UNPKG

@simplepay-ai/widget

Version:

SimplePay Payment Widget

1,383 lines (1,382 loc) 5.41 MB
var __defProp2 = Object.defineProperty; var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp2 = (obj, key2, value) => key2 in obj ? __defProp2(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value; var __publicField = (obj, key2, value) => __defNormalProp2(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); var __privateWrapper = (obj, member, setter, getter) => ({ set _(value) { __privateSet(obj, member, value, setter); }, get _() { return __privateGet(obj, member, getter); } }); var _names, _data, _dataLength, _Writer_instances, writeData_fn, _data2, _offset, _bytesRead, _parent, _maxInflation, _Reader_instances, incrementBytesRead_fn, peekBytes_fn, _r2, _s2, _v, _networkV, _privateKey, _options, _type, _to, _data3, _nonce, _gasLimit, _gasPrice, _maxPriorityFeePerGas, _maxFeePerGas, _value, _chainId, _sig, _accessList, _maxFeePerBlobGas, _blobVersionedHashes, _kzg, _blobs, _Transaction_instances, getSerialized_fn, _a2, _types, _fullTypes, _encoderCache, _TypedDataEncoder_instances, getEncoder_fn, _b, _offset2, _tokens, _TokenString_instances, subTokenString_fn, _c, _ParamType_instances, walkAsync_fn, _d, _AbiCoder_instances, getCoder_fn, _VoidSigner_instances, throwUnsupported_fn, _signingKey, _data4, _checksum, _words, _WordlistOwl_instances, loadWords_fn, _HDNodeWallet_instances, account_fn, _HDNodeWallet_static, fromSeed_fn, _offset3, _tokens2, _TokenString_instances2, subTokenString_fn2, _ParamType_instances2, walkAsync_fn2, _errors, _events, _functions, _abiCoder, _Interface_instances, getFunction_fn, getEvent_fn, _e2, _types2, _fullTypes2, _encoderCache2, _TypedDataEncoder_instances2, getEncoder_fn2; var statusCodeToReasonPhrase = { "202": "Accepted", "502": "Bad Gateway", "400": "Bad Request", "409": "Conflict", "100": "Continue", "201": "Created", "417": "Expectation Failed", "424": "Failed Dependency", "403": "Forbidden", "504": "Gateway Timeout", "410": "Gone", "505": "HTTP Version Not Supported", "418": "I'm a teapot", "419": "Insufficient Space on Resource", "507": "Insufficient Storage", "500": "Internal Server Error", "411": "Length Required", "423": "Locked", "420": "Method Failure", "405": "Method Not Allowed", "301": "Moved Permanently", "302": "Moved Temporarily", "207": "Multi-Status", "300": "Multiple Choices", "511": "Network Authentication Required", "204": "No Content", "203": "Non Authoritative Information", "406": "Not Acceptable", "404": "Not Found", "501": "Not Implemented", "304": "Not Modified", "200": "OK", "206": "Partial Content", "402": "Payment Required", "308": "Permanent Redirect", "412": "Precondition Failed", "428": "Precondition Required", "102": "Processing", "103": "Early Hints", "426": "Upgrade Required", "407": "Proxy Authentication Required", "431": "Request Header Fields Too Large", "408": "Request Timeout", "413": "Request Entity Too Large", "414": "Request-URI Too Long", "416": "Requested Range Not Satisfiable", "205": "Reset Content", "303": "See Other", "503": "Service Unavailable", "101": "Switching Protocols", "307": "Temporary Redirect", "429": "Too Many Requests", "401": "Unauthorized", "451": "Unavailable For Legal Reasons", "422": "Unprocessable Entity", "415": "Unsupported Media Type", "305": "Use Proxy", "421": "Misdirected Request" }; function getReasonPhrase(statusCode) { var result = statusCodeToReasonPhrase[statusCode.toString()]; if (!result) { throw new Error("Status code does not exist: " + statusCode); } return result; } var StatusCodes; (function(StatusCodes2) { StatusCodes2[StatusCodes2["CONTINUE"] = 100] = "CONTINUE"; StatusCodes2[StatusCodes2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS"; StatusCodes2[StatusCodes2["PROCESSING"] = 102] = "PROCESSING"; StatusCodes2[StatusCodes2["EARLY_HINTS"] = 103] = "EARLY_HINTS"; StatusCodes2[StatusCodes2["OK"] = 200] = "OK"; StatusCodes2[StatusCodes2["CREATED"] = 201] = "CREATED"; StatusCodes2[StatusCodes2["ACCEPTED"] = 202] = "ACCEPTED"; StatusCodes2[StatusCodes2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION"; StatusCodes2[StatusCodes2["NO_CONTENT"] = 204] = "NO_CONTENT"; StatusCodes2[StatusCodes2["RESET_CONTENT"] = 205] = "RESET_CONTENT"; StatusCodes2[StatusCodes2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT"; StatusCodes2[StatusCodes2["MULTI_STATUS"] = 207] = "MULTI_STATUS"; StatusCodes2[StatusCodes2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES"; StatusCodes2[StatusCodes2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY"; StatusCodes2[StatusCodes2["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY"; StatusCodes2[StatusCodes2["SEE_OTHER"] = 303] = "SEE_OTHER"; StatusCodes2[StatusCodes2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED"; StatusCodes2[StatusCodes2["USE_PROXY"] = 305] = "USE_PROXY"; StatusCodes2[StatusCodes2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT"; StatusCodes2[StatusCodes2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT"; StatusCodes2[StatusCodes2["BAD_REQUEST"] = 400] = "BAD_REQUEST"; StatusCodes2[StatusCodes2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED"; StatusCodes2[StatusCodes2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED"; StatusCodes2[StatusCodes2["FORBIDDEN"] = 403] = "FORBIDDEN"; StatusCodes2[StatusCodes2["NOT_FOUND"] = 404] = "NOT_FOUND"; StatusCodes2[StatusCodes2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED"; StatusCodes2[StatusCodes2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE"; StatusCodes2[StatusCodes2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED"; StatusCodes2[StatusCodes2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT"; StatusCodes2[StatusCodes2["CONFLICT"] = 409] = "CONFLICT"; StatusCodes2[StatusCodes2["GONE"] = 410] = "GONE"; StatusCodes2[StatusCodes2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED"; StatusCodes2[StatusCodes2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED"; StatusCodes2[StatusCodes2["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG"; StatusCodes2[StatusCodes2["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG"; StatusCodes2[StatusCodes2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE"; StatusCodes2[StatusCodes2["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE"; StatusCodes2[StatusCodes2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED"; StatusCodes2[StatusCodes2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT"; StatusCodes2[StatusCodes2["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE"; StatusCodes2[StatusCodes2["METHOD_FAILURE"] = 420] = "METHOD_FAILURE"; StatusCodes2[StatusCodes2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST"; StatusCodes2[StatusCodes2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY"; StatusCodes2[StatusCodes2["LOCKED"] = 423] = "LOCKED"; StatusCodes2[StatusCodes2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY"; StatusCodes2[StatusCodes2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED"; StatusCodes2[StatusCodes2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED"; StatusCodes2[StatusCodes2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS"; StatusCodes2[StatusCodes2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE"; StatusCodes2[StatusCodes2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS"; StatusCodes2[StatusCodes2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR"; StatusCodes2[StatusCodes2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED"; StatusCodes2[StatusCodes2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY"; StatusCodes2[StatusCodes2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE"; StatusCodes2[StatusCodes2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT"; StatusCodes2[StatusCodes2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED"; StatusCodes2[StatusCodes2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE"; StatusCodes2[StatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED"; })(StatusCodes || (StatusCodes = {})); class HttpError extends Error { constructor(code2) { super(getReasonPhrase(code2)); __publicField(this, "code"); this.code = code2; this.name = this.constructor.name; } } class ValidationError extends Error { constructor(errors2) { super("Validation error"); __publicField(this, "errors"); this.errors = errors2; this.name = this.constructor.name; } } var AppEnvironment; (function(AppEnvironment2) { AppEnvironment2["Development"] = "development"; AppEnvironment2["Production"] = "production"; })(AppEnvironment || (AppEnvironment = {})); var InvoiceEventType; (function(InvoiceEventType2) { InvoiceEventType2["Created"] = "created"; InvoiceEventType2["Success"] = "success"; InvoiceEventType2["Canceled"] = "canceled"; })(InvoiceEventType || (InvoiceEventType = {})); var InvoiceStatus; (function(InvoiceStatus2) { InvoiceStatus2["Active"] = "active"; InvoiceStatus2["Closed"] = "closed"; InvoiceStatus2["Success"] = "success"; InvoiceStatus2["Canceled"] = "canceled"; })(InvoiceStatus || (InvoiceStatus = {})); var PATScope; (function(PATScope2) { PATScope2["AppRead"] = "app:read"; PATScope2["AppWrite"] = "app:write"; PATScope2["AppAddressRead"] = "app.address:read"; PATScope2["AppAddressWrite"] = "app.address:write"; PATScope2["AppCryptocurrencyWrite"] = "app.cryptocurrency:write"; PATScope2["InvoiceRead"] = "invoice:read"; PATScope2["ProductWrite"] = "product:write"; PATScope2["UserBillingRead"] = "user.billing:read"; PATScope2["UserInvoiceRead"] = "user.invoice:read"; PATScope2["UserPATRead"] = "user.pat:read"; PATScope2["UserPATWrite"] = "user.pat:write"; })(PATScope || (PATScope = {})); var TransactionEventType; (function(TransactionEventType2) { TransactionEventType2["Created"] = "created"; TransactionEventType2["Processing"] = "processing"; TransactionEventType2["Confirming"] = "confirming"; TransactionEventType2["Success"] = "success"; TransactionEventType2["Rejected"] = "rejected"; TransactionEventType2["Canceled"] = "canceled"; TransactionEventType2["Expired"] = "expired"; })(TransactionEventType || (TransactionEventType = {})); var TransactionStatus; (function(TransactionStatus2) { TransactionStatus2["Created"] = "created"; TransactionStatus2["Processing"] = "processing"; TransactionStatus2["Confirming"] = "confirming"; TransactionStatus2["Success"] = "success"; TransactionStatus2["Rejected"] = "rejected"; TransactionStatus2["Canceled"] = "canceled"; TransactionStatus2["Expired"] = "expired"; })(TransactionStatus || (TransactionStatus = {})); var UserAddressType; (function(UserAddressType2) { UserAddressType2["BTC"] = "BTC"; UserAddressType2["EVM"] = "EVM"; UserAddressType2["LTC"] = "LTC"; UserAddressType2["TRX"] = "TRX"; })(UserAddressType || (UserAddressType = {})); var WebhookEventType; (function(WebhookEventType2) { WebhookEventType2["InvoiceCreated"] = "invoice.created"; WebhookEventType2["InvoiceSuccess"] = "invoice.success"; WebhookEventType2["InvoiceCanceled"] = "invoice.canceled"; WebhookEventType2["TransactionCreated"] = "transaction.created"; WebhookEventType2["TransactionProcessing"] = "transaction.processing"; WebhookEventType2["TransactionConfirming"] = "transaction.confirming"; WebhookEventType2["TransactionSuccess"] = "transaction.success"; WebhookEventType2["TransactionRejected"] = "transaction.rejected"; WebhookEventType2["TransactionCanceled"] = "transaction.canceled"; WebhookEventType2["TransactionExpired"] = "transaction.expired"; })(WebhookEventType || (WebhookEventType = {})); var UserInvoiceListOrderBy; (function(UserInvoiceListOrderBy2) { UserInvoiceListOrderBy2["Status"] = "status"; UserInvoiceListOrderBy2["CreatedAt"] = "created_at"; })(UserInvoiceListOrderBy || (UserInvoiceListOrderBy = {})); const isObject$h = (value) => typeof value === "object" && value !== null; const isObjectCustom$1 = (value) => isObject$h(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date); const mapObjectSkip$1 = Symbol("mapObjectSkip"); const _mapObject = (object, mapper, options, isSeen = /* @__PURE__ */ new WeakMap()) => { options = { deep: false, target: {}, ...options }; if (isSeen.has(object)) { return isSeen.get(object); } isSeen.set(object, options.target); const { target } = options; delete options.target; const mapArray = (array) => array.map((element) => isObjectCustom$1(element) ? _mapObject(element, mapper, options, isSeen) : element); if (Array.isArray(object)) { return mapArray(object); } for (const [key2, value] of Object.entries(object)) { const mapResult = mapper(key2, value, object); if (mapResult === mapObjectSkip$1) { continue; } let [newKey, newValue, { shouldRecurse = true } = {}] = mapResult; if (newKey === "__proto__") { continue; } if (options.deep && shouldRecurse && isObjectCustom$1(newValue)) { newValue = Array.isArray(newValue) ? mapArray(newValue) : _mapObject(newValue, mapper, options, isSeen); } target[newKey] = newValue; } return target; }; function mapObject$2(object, mapper, options) { if (!isObject$h(object)) { throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`); } return _mapObject(object, mapper, options); } const UPPERCASE = /[\p{Lu}]/u; const LOWERCASE = /[\p{Ll}]/u; const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu; const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u; const SEPARATORS = /[_.\- ]+/; const LEADING_SEPARATORS = new RegExp("^" + SEPARATORS.source); const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, "gu"); const NUMBERS_AND_IDENTIFIER = new RegExp("\\d+" + IDENTIFIER.source, "gu"); const preserveCamelCase = (string2, toLowerCase, toUpperCase, preserveConsecutiveUppercase2) => { let isLastCharLower = false; let isLastCharUpper = false; let isLastLastCharUpper = false; let isLastLastCharPreserved = false; for (let index2 = 0; index2 < string2.length; index2++) { const character = string2[index2]; isLastLastCharPreserved = index2 > 2 ? string2[index2 - 3] === "-" : true; if (isLastCharLower && UPPERCASE.test(character)) { string2 = string2.slice(0, index2) + "-" + string2.slice(index2); isLastCharLower = false; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = true; index2++; } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase2)) { string2 = string2.slice(0, index2 - 1) + "-" + string2.slice(index2 - 1); isLastLastCharUpper = isLastCharUpper; isLastCharUpper = false; isLastCharLower = true; } else { isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character; isLastLastCharUpper = isLastCharUpper; isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character; } } return string2; }; const preserveConsecutiveUppercase = (input, toLowerCase) => { LEADING_CAPITAL.lastIndex = 0; return input.replaceAll(LEADING_CAPITAL, (match) => toLowerCase(match)); }; const postProcess = (input, toUpperCase) => { SEPARATORS_AND_IDENTIFIER.lastIndex = 0; NUMBERS_AND_IDENTIFIER.lastIndex = 0; return input.replaceAll(NUMBERS_AND_IDENTIFIER, (match, pattern, offset) => ["_", "-"].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match)).replaceAll(SEPARATORS_AND_IDENTIFIER, (_3, identifier) => toUpperCase(identifier)); }; function camelCase$2(input, options) { if (!(typeof input === "string" || Array.isArray(input))) { throw new TypeError("Expected the input to be `string | string[]`"); } options = { pascalCase: false, preserveConsecutiveUppercase: false, ...options }; if (Array.isArray(input)) { input = input.map((x2) => x2.trim()).filter((x2) => x2.length).join("-"); } else { input = input.trim(); } if (input.length === 0) { return ""; } const toLowerCase = options.locale === false ? (string2) => string2.toLowerCase() : (string2) => string2.toLocaleLowerCase(options.locale); const toUpperCase = options.locale === false ? (string2) => string2.toUpperCase() : (string2) => string2.toLocaleUpperCase(options.locale); if (input.length === 1) { if (SEPARATORS.test(input)) { return ""; } return options.pascalCase ? toUpperCase(input) : toLowerCase(input); } const hasUpperCase = input !== toLowerCase(input); if (hasUpperCase) { input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase); } input = input.replace(LEADING_SEPARATORS, ""); input = options.preserveConsecutiveUppercase ? preserveConsecutiveUppercase(input, toLowerCase) : toLowerCase(input); if (options.pascalCase) { input = toUpperCase(input.charAt(0)) + input.slice(1); } return postProcess(input, toUpperCase); } class QuickLRU extends Map { constructor(options = {}) { super(); if (!(options.maxSize && options.maxSize > 0)) { throw new TypeError("`maxSize` must be a number greater than 0"); } if (typeof options.maxAge === "number" && options.maxAge === 0) { throw new TypeError("`maxAge` must be a number greater than 0"); } this.maxSize = options.maxSize; this.maxAge = options.maxAge || Number.POSITIVE_INFINITY; this.onEviction = options.onEviction; this.cache = /* @__PURE__ */ new Map(); this.oldCache = /* @__PURE__ */ new Map(); this._size = 0; } // TODO: Use private class methods when targeting Node.js 16. _emitEvictions(cache2) { if (typeof this.onEviction !== "function") { return; } for (const [key2, item] of cache2) { this.onEviction(key2, item.value); } } _deleteIfExpired(key2, item) { if (typeof item.expiry === "number" && item.expiry <= Date.now()) { if (typeof this.onEviction === "function") { this.onEviction(key2, item.value); } return this.delete(key2); } return false; } _getOrDeleteIfExpired(key2, item) { const deleted = this._deleteIfExpired(key2, item); if (deleted === false) { return item.value; } } _getItemValue(key2, item) { return item.expiry ? this._getOrDeleteIfExpired(key2, item) : item.value; } _peek(key2, cache2) { const item = cache2.get(key2); return this._getItemValue(key2, item); } _set(key2, value) { this.cache.set(key2, value); this._size++; if (this._size >= this.maxSize) { this._size = 0; this._emitEvictions(this.oldCache); this.oldCache = this.cache; this.cache = /* @__PURE__ */ new Map(); } } _moveToRecent(key2, item) { this.oldCache.delete(key2); this._set(key2, item); } *_entriesAscending() { for (const item of this.oldCache) { const [key2, value] = item; if (!this.cache.has(key2)) { const deleted = this._deleteIfExpired(key2, value); if (deleted === false) { yield item; } } } for (const item of this.cache) { const [key2, value] = item; const deleted = this._deleteIfExpired(key2, value); if (deleted === false) { yield item; } } } get(key2) { if (this.cache.has(key2)) { const item = this.cache.get(key2); return this._getItemValue(key2, item); } if (this.oldCache.has(key2)) { const item = this.oldCache.get(key2); if (this._deleteIfExpired(key2, item) === false) { this._moveToRecent(key2, item); return item.value; } } } set(key2, value, { maxAge = this.maxAge } = {}) { const expiry = typeof maxAge === "number" && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : void 0; if (this.cache.has(key2)) { this.cache.set(key2, { value, expiry }); } else { this._set(key2, { value, expiry }); } return this; } has(key2) { if (this.cache.has(key2)) { return !this._deleteIfExpired(key2, this.cache.get(key2)); } if (this.oldCache.has(key2)) { return !this._deleteIfExpired(key2, this.oldCache.get(key2)); } return false; } peek(key2) { if (this.cache.has(key2)) { return this._peek(key2, this.cache); } if (this.oldCache.has(key2)) { return this._peek(key2, this.oldCache); } } delete(key2) { const deleted = this.cache.delete(key2); if (deleted) { this._size--; } return this.oldCache.delete(key2) || deleted; } clear() { this.cache.clear(); this.oldCache.clear(); this._size = 0; } resize(newSize) { if (!(newSize && newSize > 0)) { throw new TypeError("`maxSize` must be a number greater than 0"); } const items = [...this._entriesAscending()]; const removeCount = items.length - newSize; if (removeCount < 0) { this.cache = new Map(items); this.oldCache = /* @__PURE__ */ new Map(); this._size = items.length; } else { if (removeCount > 0) { this._emitEvictions(items.slice(0, removeCount)); } this.oldCache = new Map(items.slice(removeCount)); this.cache = /* @__PURE__ */ new Map(); this._size = 0; } this.maxSize = newSize; } *keys() { for (const [key2] of this) { yield key2; } } *values() { for (const [, value] of this) { yield value; } } *[Symbol.iterator]() { for (const item of this.cache) { const [key2, value] = item; const deleted = this._deleteIfExpired(key2, value); if (deleted === false) { yield [key2, value.value]; } } for (const item of this.oldCache) { const [key2, value] = item; if (!this.cache.has(key2)) { const deleted = this._deleteIfExpired(key2, value); if (deleted === false) { yield [key2, value.value]; } } } } *entriesDescending() { let items = [...this.cache]; for (let i3 = items.length - 1; i3 >= 0; --i3) { const item = items[i3]; const [key2, value] = item; const deleted = this._deleteIfExpired(key2, value); if (deleted === false) { yield [key2, value.value]; } } items = [...this.oldCache]; for (let i3 = items.length - 1; i3 >= 0; --i3) { const item = items[i3]; const [key2, value] = item; if (!this.cache.has(key2)) { const deleted = this._deleteIfExpired(key2, value); if (deleted === false) { yield [key2, value.value]; } } } } *entriesAscending() { for (const [key2, value] of this._entriesAscending()) { yield [key2, value.value]; } } get size() { if (!this._size) { return this.oldCache.size; } let oldCacheSize = 0; for (const key2 of this.oldCache.keys()) { if (!this.cache.has(key2)) { oldCacheSize++; } } return Math.min(this._size + oldCacheSize, this.maxSize); } entries() { return this.entriesAscending(); } forEach(callbackFunction, thisArgument = this) { for (const [key2, value] of this.entriesAscending()) { callbackFunction.call(thisArgument, value, key2, this); } } get [Symbol.toStringTag]() { return JSON.stringify([...this.entriesAscending()]); } } const has$3 = (array, key2) => array.some((element) => { if (typeof element === "string") { return element === key2; } element.lastIndex = 0; return element.test(key2); }); const cache$2 = new QuickLRU({ maxSize: 1e5 }); const isObject$g = (value) => typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date); const transform$1 = (input, options = {}) => { if (!isObject$g(input)) { return input; } const { exclude, pascalCase = false, stopPaths, deep = false, preserveConsecutiveUppercase: preserveConsecutiveUppercase2 = false } = options; const stopPathsSet = new Set(stopPaths); const makeMapper = (parentPath) => (key2, value) => { if (deep && isObject$g(value)) { const path2 = parentPath === void 0 ? key2 : `${parentPath}.${key2}`; if (!stopPathsSet.has(path2)) { value = mapObject$2(value, makeMapper(path2)); } } if (!(exclude && has$3(exclude, key2))) { const cacheKey = pascalCase ? `${key2}_` : key2; if (cache$2.has(cacheKey)) { key2 = cache$2.get(cacheKey); } else { const returnValue = camelCase$2(key2, { pascalCase, locale: false, preserveConsecutiveUppercase: preserveConsecutiveUppercase2 }); if (key2.length < 100) { cache$2.set(cacheKey, returnValue); } key2 = returnValue; } } return [key2, value]; }; return mapObject$2(input, makeMapper(void 0)); }; function camelcaseKeys(input, options) { if (Array.isArray(input)) { return Object.keys(input).map((key2) => transform$1(input[key2], options)); } return transform$1(input, options); } var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; function getDefaultExportFromCjs$1(x2) { return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2; } function getAugmentedNamespace(n4) { if (n4.__esModule) return n4; var f4 = n4.default; if (typeof f4 == "function") { var a2 = function a3() { if (this instanceof a3) { return Reflect.construct(f4, arguments, this.constructor); } return f4.apply(this, arguments); }; a2.prototype = f4.prototype; } else a2 = {}; Object.defineProperty(a2, "__esModule", { value: true }); Object.keys(n4).forEach(function(k2) { var d4 = Object.getOwnPropertyDescriptor(n4, k2); Object.defineProperty(a2, k2, d4.get ? d4 : { enumerable: true, get: function() { return n4[k2]; } }); }); return a2; } var mapObj = { exports: {} }; const isObject$f = (value) => typeof value === "object" && value !== null; const mapObjectSkip = Symbol("skip"); const isObjectCustom = (value) => isObject$f(value) && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date); const mapObject = (object, mapper, options, isSeen = /* @__PURE__ */ new WeakMap()) => { options = { deep: false, target: {}, ...options }; if (isSeen.has(object)) { return isSeen.get(object); } isSeen.set(object, options.target); const { target } = options; delete options.target; const mapArray = (array) => array.map((element) => isObjectCustom(element) ? mapObject(element, mapper, options, isSeen) : element); if (Array.isArray(object)) { return mapArray(object); } for (const [key2, value] of Object.entries(object)) { const mapResult = mapper(key2, value, object); if (mapResult === mapObjectSkip) { continue; } let [newKey, newValue, { shouldRecurse = true } = {}] = mapResult; if (newKey === "__proto__") { continue; } if (options.deep && shouldRecurse && isObjectCustom(newValue)) { newValue = Array.isArray(newValue) ? mapArray(newValue) : mapObject(newValue, mapper, options, isSeen); } target[newKey] = newValue; } return target; }; mapObj.exports = (object, mapper, options) => { if (!isObject$f(object)) { throw new TypeError(`Expected an object, got \`${object}\` (${typeof object})`); } return mapObject(object, mapper, options); }; mapObj.exports.mapObjectSkip = mapObjectSkip; var mapObjExports = mapObj.exports; const mapObject$1 = /* @__PURE__ */ getDefaultExportFromCjs$1(mapObjExports); const handlePreserveConsecutiveUppercase = (decamelized, separator) => { decamelized = decamelized.replace( new RegExp("((?<![\\p{Uppercase_Letter}\\d])[\\p{Uppercase_Letter}\\d](?![\\p{Uppercase_Letter}\\d]))", "gu"), ($0) => $0.toLowerCase() ); return decamelized.replace( new RegExp("(\\p{Uppercase_Letter}+)(\\p{Uppercase_Letter}\\p{Lowercase_Letter}+)", "gu"), (_3, $1, $2) => $1 + separator + $2.toLowerCase() ); }; function decamelize(text, { separator = "_", preserveConsecutiveUppercase: preserveConsecutiveUppercase2 = false } = {}) { if (!(typeof text === "string" && typeof separator === "string")) { throw new TypeError( "The `text` and `separator` arguments should be of type `string`" ); } if (text.length < 2) { return preserveConsecutiveUppercase2 ? text : text.toLowerCase(); } const replacement = `$1${separator}$2`; const decamelized = text.replace( new RegExp("([\\p{Lowercase_Letter}\\d])(\\p{Uppercase_Letter})", "gu"), replacement ); if (preserveConsecutiveUppercase2) { return handlePreserveConsecutiveUppercase(decamelized, separator); } return decamelized.replace( new RegExp("(\\p{Uppercase_Letter})(\\p{Uppercase_Letter}\\p{Lowercase_Letter}+)", "gu"), replacement ).toLowerCase(); } const has$2 = (array, key2) => array.some((element) => { if (typeof element === "string") { return element === key2; } element.lastIndex = 0; return element.test(key2); }); const cache$1 = new QuickLRU({ maxSize: 1e5 }); const isObject$e = (value) => typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Error) && !(value instanceof Date); const transform = (input, options = {}) => { if (!isObject$e(input)) { return input; } const { separator = "_", exclude, deep = false } = options; const makeMapper = (parentPath) => (key2, value) => { if (deep && isObject$e(value)) { value = mapObject$1(value, makeMapper()); } if (!(exclude && has$2(exclude, key2))) { const cacheKey = `${separator}${key2}`; if (cache$1.has(cacheKey)) { key2 = cache$1.get(cacheKey); } else { const returnValue = decamelize(key2, { separator }); if (key2.length < 100) { cache$1.set(cacheKey, returnValue); } key2 = returnValue; } } return [key2, value]; }; return mapObject$1(input, makeMapper()); }; function decamelizeKeys(input, options) { if (Array.isArray(input)) { return Object.keys(input).map((key2) => transform(input[key2], options)); } return transform(input, options); } class BaseService { constructor(state2, fetch2, apiBase, apiKey = null) { __publicField(this, "state"); __publicField(this, "fetch"); __publicField(this, "apiBase"); __publicField(this, "apiKey"); __publicField(this, "CSRF_TOKEN_HEADER", "X-Csrf-Token"); this.state = state2; this.fetch = fetch2; this.apiBase = apiBase; this.apiKey = apiKey; } async request(method, path2 = null, body = null) { const headers = {}; if (this.state.csrfToken != null) { headers[this.CSRF_TOKEN_HEADER] = this.state.csrfToken; } let bodyInit = null; if (body !== null) { bodyInit = JSON.stringify(body); headers["Content-Type"] = "application/json"; } if (this.apiKey !== null) { headers["Authorization"] = `Bearer ${this.apiKey}`; } let fetch2 = this.fetch; if (typeof window !== "undefined") { fetch2 = this.fetch.bind(window); } const response = await fetch2(`${this.apiBase}${path2 || ""}`, { credentials: "include", method, headers, body: bodyInit }); if (response.headers.has(this.CSRF_TOKEN_HEADER)) { this.state.csrfToken = response.headers.get(this.CSRF_TOKEN_HEADER); } return response; } toSnakeCase(obj) { return decamelizeKeys(obj, { deep: true }); } toCamelCase(obj) { return camelcaseKeys(obj, { deep: true }); } } class AppService extends BaseService { constructor(state2, fetch2, apiBase) { super(state2, fetch2, apiBase); __publicField(this, "state"); __publicField(this, "fetch"); __publicField(this, "apiBase"); __publicField(this, "cryptocurrency"); this.state = state2; this.fetch = fetch2; this.apiBase = apiBase; this.cryptocurrency = new AppCryptocurrencyService(state2, fetch2, this.apiBase); } async list() { const response = await this.request("GET", "?v=1"); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } async create(request) { const response = await this.request("POST", "?v=1", this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } async get(id2) { const response = await this.request("GET", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } async update(id2, request) { const response = await this.request("PUT", `/${id2}?v=1`, this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } async delete(id2) { const response = await this.request("DELETE", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } return true; } } class AppCryptocurrencyService extends BaseService { async update(appId, request) { const response = await this.request("PUT", `/${appId}/cryptocurrency?v=1`, this.toSnakeCase(request)); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } } class CurrencyService extends BaseService { /** * Get fiat currency list */ async list() { const response = await this.request("GET", "?v=1"); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } } class CryptocurrencyService extends BaseService { /** * Get cryptocurrency list */ async list(request = {}) { const query2 = new URLSearchParams(); for (const [key2, value] of Object.entries(this.toSnakeCase(request))) { query2.append(key2, value.toString()); } const response = await this.request("GET", `?v=1&${query2.toString()}`); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } } class InvoiceService extends BaseService { /** * Create invoice */ async create(request) { const response = await this.request("POST", "?v=2", this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } /** * Get invoice by ID */ async get(id2, app = false) { const response = await this.request("GET", `/${id2}?v=2&app=${app}`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } /** * Cancel invoice by ID */ async cancel(id2) { const response = await this.request("DELETE", `/${id2}?v=2`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } /** * List invoices */ async list(request = {}) { const query2 = new URLSearchParams(); for (const [key2, value] of Object.entries(this.toSnakeCase(request))) { query2.append(key2, value.toString()); } const response = await this.request("GET", `?v=2&${query2.toString()}`); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } } class ProductService extends BaseService { async list(appId) { const response = await this.request("GET", `?v=1&app_id=${appId}`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } async get(id2) { const response = await this.request("GET", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } } class TransactionService extends BaseService { /** * Create transaction */ async create(request) { const response = await this.request("POST", "?v=1", this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } /** * Get transaction by ID */ async get(id2) { const response = await this.request("GET", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } /** * Cancel transaction by ID */ async cancel(id2) { const response = await this.request("DELETE", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } /** * List transactions */ async list(request) { const query2 = new URLSearchParams(); for (const [key2, value] of Object.entries(this.toSnakeCase(request))) { query2.append(key2, value.toString()); } const response = await this.request("GET", `?v=1&${query2.toString()}`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return this.toCamelCase(data); } } class UserService extends BaseService { constructor(state2, fetch2, apiBase) { super(state2, fetch2, apiBase); __publicField(this, "state"); __publicField(this, "fetch"); __publicField(this, "apiBase"); __publicField(this, "address"); __publicField(this, "billing"); __publicField(this, "invoice"); __publicField(this, "pat"); __publicField(this, "profile"); this.state = state2; this.fetch = fetch2; this.apiBase = apiBase; this.address = new UserAddressService(state2, fetch2, `${this.apiBase}/address`); this.billing = new UserBillingService(state2, fetch2, `${this.apiBase}/billing`); this.invoice = new UserInvoiceService(state2, fetch2, `${this.apiBase}/invoice`); this.pat = new UserPATService(state2, fetch2, `${this.apiBase}/pat`); this.profile = new UserProfileService(state2, fetch2, `${this.apiBase}/profile`); } } class UserAddressService extends BaseService { async list() { const response = await this.request("GET", "?v=1"); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } async create(request) { const response = await this.request("POST", "?v=1", this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } async get(id2) { const response = await this.request("GET", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } async update(id2, request) { const response = await this.request("PUT", `/${id2}?v=1`, this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } async delete(id2) { const response = await this.request("DELETE", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } return true; } } class UserProfileService extends BaseService { async get() { const response = await this.request("GET", "?v=1"); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } async update(request) { const response = await this.request("PUT", "?v=1", this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } } class UserBillingService extends BaseService { /** * List billing invoices */ async list() { const response = await this.request("GET", `?v=1`); if (!response.ok) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); return data; } } class UserInvoiceService extends BaseService { /** * List invoices */ async list(request = {}) { const query2 = new URLSearchParams(); for (const [key2, value] of Object.entries(this.toSnakeCase(request))) { query2.append(key2, value.toString()); } const response = await this.request("GET", `?v=1&${query2.toString()}`); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } async link(request) { const response = await this.request("POST", "?v=1", this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } } class UserPATService extends BaseService { async list() { const response = await this.request("GET", "?v=1"); if (!response.ok) { throw new HttpError(response.status); } const data = await response.json(); return this.toCamelCase(data); } async create(request) { const response = await this.request("POST", "?v=1", this.toSnakeCase(request)); if (!response.ok && response.status !== StatusCodes.BAD_REQUEST) { throw new HttpError(response.status); } const data = this.toCamelCase(await response.json()); if (response.status === StatusCodes.BAD_REQUEST) { throw new ValidationError(data); } return data; } async delete(id2) { const response = await this.request("DELETE", `/${id2}?v=1`); if (!response.ok) { throw new HttpError(response.status); } return true; } } class BaseChannel { constructor(channel) { __publicField(this, "channel"); this.channel = channel; } toCamelCase(obj) { return camelcaseKeys(obj, { deep: true }); } } class AppClientInvoiceChannel extends BaseChannel { on(eventType, callback) { this.channel.bind(eventType, (i3) => callback(this.toCamelCase(i3))); } } class InvoiceChannel extends BaseChannel { on(eventType, callback) { this.channel.bind(eventType, (i3) => callback(this.toCamelCase(i3))); } } class InvoiceTransactionChannel extends BaseChannel { on(eventType, callback) { this.channel.bind(eventType, (i3) => callback(this.toCamelCase(i3))); } } class Client { constructor(options = {}) { /** * App API */ __publicField(this, "app"); /** * Fiat currency API */ __publicField(this, "currency"); /** * Cryptocurrency API */ __publicField(this, "cryptocurrency"); /** * Invoice API */ __publicField(this, "invoice"); /** * Product API */ __publicField(this, "product"); /** * Transaction API */ __publicField(this, "transaction"); /** * User API */ __publicField(this, "user"); __publicField(this, "state"); const apiBase = options.apiBase || "https://api.simplepay.ai"; const fetchApi = options.fetch || fetch; this.state = { csrfToken: null }; this.app = new AppService(this.state, fetchApi, `${apiBase}/app`); this.currency = new CurrencyService(this.state, fetchApi, `${apiBase}/currency`); this.cryptocurrency = new CryptocurrencyService(this.state, fetchApi, `${apiBase}/cryptocurrency`); this.invoice = new InvoiceService(this.state, fetchApi, `${apiBase}/invoice`, options.apiKey); this.product = new ProductService(this.state, fetchApi, `${apiBase}/product`); this.transaction = new TransactionService(this.state, fetchApi, `${apiBase}/transaction`); this.user = new UserService(this.state, fetchApi, `${apiBase}/user`); } } var pusher = { exports: {} }; /*! * Pusher JavaScript Library v8.4.0 * https://pusher.com/ * * Copyright 2020, Pusher * Released under the MIT licence. */ (function(module, exports2) { (function webpackUniversalModuleDefinition(root2, factory) { module.exports = factory(); })(window, function() { return ( /******/ function(modules) { var installedModules = {}; function __webpack_require__(moduleId) { if (installedModules[moduleId]) { return installedModules[moduleId].exports; } var module2 = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; modules[moduleId].call(module2.exports, module2, module2.exports, __webpack_require__); module2.l = true; return module2.exports; } __webpack_require__.m = modules; __webpack_require__.c = installedModules; __webpack_require__.d = function(exports3, name, getter) { if (!__webpack_require__.o(exports3, name)) { Object.defineProperty(exports3, name, { enumerable: true, get: getter }); } }; __webpack_require__.r = function(exports3) { if (typeof Symbol !== "undefined" && Symbol.toStringTag) { Object.defineProperty(exports3, Symbol.toStringTag, { value: "Module" }); } Object.defineProperty(exports3, "__esModule", { value: true }); }; __webpack_require__.t = function(value, mode) { if (mode & 1) value = __webpack_require__(value); if (mode & 8) return value; if (mode & 4 && typeof value === "object" && value && value.__esModule) return value; var ns2 = /* @__PURE__ */ Object.create(null); __webpack_require__.r(ns2); Object.defineProperty(ns2, "default", { enumerable: true, value }); if (mode & 2 && typeof value != "string") for (var key2 in value) __webpack_require__.d(ns2, key2, (function(key3) { return value[key3]; }).bind(null, key2)); return ns2; }; __webpack_require__.n = function(module2) { var getter = module2 && module2.__esModule ? ( /******/ function getDefault() { return module2["default"]; } ) : ( /******/ function getModuleExports() { return module2; } ); __webpack_require__.d(getter, "a", getter); return getter;