UNPKG

pubnub

Version:

Publish & Subscribe Real-time Messaging with PubNub

1,489 lines (1,434 loc) 720 kB
(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()); })(this, (function () { 'use strict'; 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 <paroga@paroga.com> * * 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 encode(value) { var data = new ArrayBuffer(256); var dataView = new DataView(data); var lastLength; var offset = 0; 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)); } 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 === 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); 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; utf8data.push(0xf0 | charCode >> 18); utf8data.push(0x80 | (charCode >> 12) & 0x3f); utf8data.push(0x80 | (charCode >> 6) & 0x3f); utf8data.push(0x80 | charCode & 0x3f); } } writeTypeAndLength(3, utf8data.length); return writeUint8Array(utf8data); 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); 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 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 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(); 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 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; } } 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; if (majorType === 7) { switch (additionalInformation) { case 25: return readFloat16(); case 26: return readFloat32(); case 27: return readFloat64(); } } 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 (module.exports) module.exports = obj; else if (!global.CBOR) global.CBOR = obj; })(commonjsGlobal); } (cbor)); var cborExports = cbor.exports; var CborReader = /*@__PURE__*/getDefaultExportFromCjs(cborExports); /****************************************************************************** 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, Iterator */ 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; } 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; }; /** * 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 : []; } /** * Assign registered loggers' manager. * * @param _logger - Registered loggers' manager. * * @internal */ set logger(_logger) { throw new Error('Method not implemented.'); } // endregion // -------------------------------------------------------- // ----------------------- Helpers ------------------------ // -------------------------------------------------------- // region Helpers /** * Retrieve list of module's cryptors. * * @internal */ getAllCryptors() { return [this.defaultCryptor, ...this.cryptors]; } // endregion /** * Serialize crypto module information to string. * * @returns Serialized crypto module information. */ toString() { return `AbstractCryptoModule { default: ${this.defaultCryptor.toString()}, cryptors: [${this.cryptors.map((c) => c.toString()).join(', ')}]}`; } } /** * `String` to {@link ArrayBuffer} response decoder. * * @internal */ AbstractCryptoModule.encoder = new TextEncoder(); /** * {@link ArrayBuffer} to {@link string} decoder. * * @internal */ 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; /** * Base64 support module. * * @internal */ 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); 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; } /** * 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"; /** * 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"; /** * Server can't process request. * * There can be few sources of unexpected return with success code: * - potentially an ongoing incident; * - proxy server / VPN. */ StatusCategory["PNServerErrorCategory"] = "PNServerErrorCategory"; /** * 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"; /** * Set of active channels and groups has been changed. */ StatusCategory["PNSubscriptionChangedCategory"] = "PNSubscriptionChangedCategory"; /** * 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; /** * 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; this.name = 'PubNubError'; this.message = message; Object.setPrototypeOf(this, new.target.prototype); } } /** * 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, category) { var _a; (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category, 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 }, ({})), 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); } /** * CryptoJS implementation. * * @internal */ /*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] = (