@enegalan/request-manager 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-manager.min.cjs","sources":["../main.js"],"sourcesContent":["/**\n * RequestManager - A library for managing and regulating HTTP requests efficiently.\n * @license MIT\n * @author Eneko Galan <enekogalanelorza@gmail.com>\n * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)\n * by accepting Promises as parameters. When a request is repeated with the same identifier,\n * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.\n */\nclass RequestManager {\n constructor(options = {}) {\n /**\n * @type {Map<string, import('./index.d.ts').ActiveRequest>}\n */\n this.activeRequests = new Map();\n /**\n * @type {import('./index.d.ts').Options}\n */\n this.options = options;\n /**\n * One-shot AbortController for getSignal()/getAbortController() handoff.\n * Consumed by the next request that does not pass options.abortController.\n * @type {AbortController|null}\n */\n this.abortController = null;\n }\n\n /**\n * Gets the manager options\n * @returns {import('./index.d.ts').Options} Manager options\n */\n getOptions() {\n return this.options;\n }\n\n /**\n * Sets the manager options\n * @param {import('./index.d.ts').Options} options - The options to set\n */\n setOptions(options) {\n this.options = options;\n }\n\n /**\n * Creates a new AbortController and returns its signal for the next request()\n * (one getSignal → one request). Do not use for parallel requests; use fetch(),\n * axios(), or request(url, ({ options }) => ...) instead — they create their own signal.\n * @returns {AbortSignal} The signal from a new AbortController\n * @example\n * const signal = requestManager.getSignal();\n * requestManager.request('/api/users', fetch('/api/users', { signal }));\n */\n getSignal() {\n return this.getAbortController().signal;\n }\n\n /**\n * Creates a new AbortController for the next request handoff.\n * Always returns a fresh controller (never reuses one from another in-flight request).\n * @returns {AbortController} A new AbortController instance\n */\n getAbortController() {\n this.abortController = new AbortController();\n return this.abortController;\n }\n\n /**\n * Checks if a request with the given identifier is currently active.\n * @param {string} requestId - The unique identifier to check\n * @returns {boolean} True if the request is active, false otherwise\n */\n isActive(requestId) {\n return this.activeRequests.has(requestId);\n }\n\n /**\n * Gets the number of active requests.\n * @returns {number} The number of currently active requests\n */\n getActiveCount() {\n return this.activeRequests.size;\n }\n\n /**\n * Clears all active requests without cancelling them.\n * Use with caution - this will not cancel the underlying HTTP requests.\n */\n clear() {\n this.activeRequests.clear();\n }\n\n /**\n * Executes an HTTP request, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise or function that returns a promise\n * @param {import('./index.d.ts').RequestOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Request with Promise\n * requestManager.request('/api/users', axios.get('/api/users'));\n * @example\n * // Request with Function\n * requestManager.request('/api/users', ({ options }) => fetch('/api/users', { signal: options.signal, ...options }));\n * @example\n * // Request with Promise and custom cancellation grouping with requestKey\n * const options = {\n * requestKey: 'get-users'\n * }\n * requestManager.request('/api/users', axios.get('/api/users', options), options);\n */\n request(url, requestPromise, options = {}) {\n return this.#_request(this.getRequestId(url, options), requestPromise, options);\n }\n\n /**\n * Executes an HTTP request using fetch, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to fetch\n * @param {import('./index.d.ts').FetchOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.fetch('/api/users');\n * @example\n * // POST request with options\n * requestManager.fetch('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.fetch('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n fetch(url, options = {}) {\n return this.#_request(this.getRequestId(url, options), url, options);\n }\n\n /**\n * Executes an HTTP request using axios, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').AxiosRequestOptions} options - Optional configuration\n * @param {import('./index.d.ts').AxiosInstance|import('./index.d.ts').AxiosStatic|null} axiosInstance - Optional axios instance to use. If not provided, uses global axios.\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request (uses global axios)\n * requestManager.axios('/api/users');\n * @example\n * // With custom axios instance\n * const myAxios = axios.create({ baseURL: 'https://api.example.com' });\n * requestManager.axios('/users', {}, myAxios);\n * @example\n * // POST request with options\n * requestManager.axios('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.axios('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n axios(url, options = {}, axiosInstance = null) {\n const axiosLib = axiosInstance || (typeof axios !== 'undefined' ? axios : null);\n if (!axiosLib) {\n throw new Error(\n 'axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally'\n );\n }\n this.#_checkAxiosVersion(axiosLib);\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => axiosLib({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using jQuery.ajax, cancelling any previous request with the same identifier.\n * @param {import('./index.d.ts').AjaxFunction} ajaxFunction - A function that receives { url, ...options } and returns a Promise\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').BaseRequestOptions & Record<string, any>} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.ajax(ajaxFunction, '/api/users');\n * @example\n * // POST request with options\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * requestKey: 'get-users'\n * });\n */\n ajax(ajaxFunction, url, options = {}) {\n if (typeof ajaxFunction !== 'function') throw new Error('ajaxFunction parameter must be a function');\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => ajaxFunction({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using XMLHttpRequest, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').XhrOptions} options - Optional configuration\n * @returns {Promise<import('./index.d.ts').XhrResponse>} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.xhr('/api/users');\n * @example\n * // POST request with options\n * requestManager.xhr('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping\n * requestManager.xhr('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n xhr(url, options = {}) {\n /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */\n const xhrFunction = ({ options: fetchOptions }) => {\n // Create XMLHttpRequest\n const xhr = new XMLHttpRequest();\n const method = (options.method || 'GET').toUpperCase();\n // Create a promise that wraps the XHR request\n const xhrPromise = new Promise((resolve, reject) => {\n xhr.onload = function () {\n detachAbortListener();\n if (xhr.status >= 200 && xhr.status < 300) {\n let response = xhr.response;\n if (\n options.responseType === 'json' ||\n ((!options.responseType || options.responseType === 'text') &&\n xhr.getResponseHeader('Content-Type')?.includes('application/json') &&\n typeof response === 'string')\n ) {\n try {\n response = JSON.parse(response);\n } catch {}\n }\n resolve({\n data: response,\n status: xhr.status,\n statusText: xhr.statusText,\n headers: xhr.getAllResponseHeaders(),\n xhr: xhr,\n });\n } else {\n reject({\n message: `Request failed with status ${xhr.status}`,\n status: xhr.status,\n statusText: xhr.statusText,\n xhr: xhr,\n });\n }\n };\n xhr.onerror = function () {\n detachAbortListener();\n reject({\n message: 'Network error',\n xhr: xhr,\n });\n };\n xhr.ontimeout = function () {\n detachAbortListener();\n reject({\n message: 'Request timeout',\n xhr: xhr,\n });\n };\n\n // Open the request\n xhr.open(method, url, true);\n\n // Set response type\n if (options.responseType) xhr.responseType = options.responseType;\n // Set withCredentials\n if (options.withCredentials !== undefined) xhr.withCredentials = options.withCredentials;\n // Set timeout\n if (options.timeout !== undefined) xhr.timeout = options.timeout;\n // Set headers\n if (options.headers)\n Object.keys(options.headers).forEach((key) => {\n xhr.setRequestHeader(key, options.headers[key]);\n });\n\n // Connect abort signal to xhr.abort()\n const abortListener = () => xhr.abort();\n if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', abortListener);\n // Detach the listener once the request settles so completed requests do not keep it alive\n const detachAbortListener = () => {\n if (fetchOptions.signal) fetchOptions.signal.removeEventListener('abort', abortListener);\n };\n\n xhr.onabort = function () {\n reject({\n message: 'Request was cancelled',\n xhr: xhr,\n });\n };\n\n // Send the request\n xhr.send(options.body || null);\n });\n return xhrPromise;\n };\n return this.#_request(this.getRequestId(url, options), xhrFunction, options);\n }\n\n /**\n * Returns the request identifier for a URL and options.\n * @param {string} url - The URL used when starting the request\n * @param {import('./index.d.ts').BaseRequestOptions} options - Same options used for the request\n * @returns {string} The request identifier\n * @example\n * requestManager.fetch('/api/users');\n * const id = requestManager.getRequestId('/api/users');\n * requestManager.cancel(id);\n */\n getRequestId(url, options = {}) {\n let requestKey = options.requestKey;\n\n const prefix = 'request_';\n\n // Generate a unique identifier to prevent cancellation for non cancelable requests\n if (options.noCancel) {\n return `${prefix}${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n // Handle function requestKey\n if (typeof requestKey === 'function') {\n try {\n requestKey = requestKey();\n } catch {\n requestKey = null;\n }\n }\n if (requestKey !== null && requestKey !== undefined) return `${prefix}${String(requestKey)}`;\n\n // Use cleaned URL as key as fallback\n let cleanedUrl = url || '';\n if (cleanedUrl.includes('://')) cleanedUrl = cleanedUrl.split('://')[1];\n if (cleanedUrl.includes('#')) cleanedUrl = cleanedUrl.split('#')[0];\n if (!options.includeQuery && cleanedUrl.includes('?')) cleanedUrl = cleanedUrl.split('?')[0];\n\n const methodPrefix =\n options.includeMethod === false ? '' : `${(options.method || options.type || 'GET').toUpperCase()}_`;\n\n return `${prefix}${methodPrefix}${cleanedUrl}`;\n }\n\n /**\n * Cancels a specific request by its identifier.\n * @param {string} requestId - The unique identifier of the request to cancel\n * @returns {boolean} True if the request was found and cancelled, false otherwise\n */\n cancel(requestId) {\n /** @type {import('./index.d.ts').ActiveRequest|undefined} */\n const requestInfo = this.activeRequests.get(requestId);\n if (!requestInfo) return false;\n\n requestInfo.isCancelled = true; // Mark as cancelled\n\n // Try to abort using AbortController (for fetch)\n if (requestInfo.abortController && !requestInfo.abortController.signal.aborted) {\n try {\n requestInfo.abortController.abort('Request was cancelled');\n } catch (error) {}\n }\n\n // Try to cancel using cancel token/function (for axios and others)\n if (requestInfo.cancelToken) {\n try {\n if (typeof requestInfo.cancelToken === 'function') requestInfo.cancelToken();\n else if (requestInfo.cancelToken.cancel) requestInfo.cancelToken.cancel();\n } catch (error) {}\n }\n\n // Reject the wrapper promise\n this.#_deleteRequest(\n requestId,\n requestInfo.rejectWrapper,\n this.getOptions().verbose ? new Error(`Request ${requestId} was cancelled`) : null\n );\n return true;\n }\n\n /**\n * Link abort signal with HTTP client abort method.\n * Useful for custom HTTP clients that only support the abort method to cancel requests.\n * @param {Function} abortMethod - The abort method to call when the signal is aborted\n * @param {AbortSignal} signal - The signal to listen to\n */\n addAbortListener(abortMethod, signal) {\n if (!abortMethod || !signal) return;\n signal.addEventListener('abort', () => {\n if (typeof abortMethod === 'function') {\n try {\n abortMethod();\n } catch (error) {}\n }\n });\n }\n\n /**\n * Cancels all active requests.\n * @returns {number} The number of requests that were cancelled\n */\n cancelAll() {\n const requestIds = Array.from(this.activeRequests.keys());\n let cancelledCount = 0;\n requestIds.forEach((requestId) => {\n if (this.cancel(requestId)) cancelledCount++;\n });\n return cancelledCount;\n }\n\n /**\n * Resolves the AbortController for a request: explicit option, pending handoff, or new.\n * Clears the pending handoff so concurrent requests do not share it.\n * @param {AbortController|undefined} provided - Optional AbortController from options\n * @returns {AbortController}\n * @private\n */\n #_resolveAbortController(provided) {\n const abortController = provided || this.abortController || new AbortController();\n this.abortController = null;\n return abortController;\n }\n\n /**\n * Picks the best abort callback for a client request object.\n * @param {Object} req - The request object\n * @returns {Function|null}\n * @private\n */\n #_resolveAbortMethod(req) {\n if (!req) return null;\n if (typeof req.abort === 'function') return () => req.abort();\n const ExtAjax =\n typeof globalThis !== 'undefined' && globalThis.Ext && globalThis.Ext.Ajax ? globalThis.Ext.Ajax : null;\n if (req.xhr && ExtAjax && typeof ExtAjax.abort === 'function') {\n return () => ExtAjax.abort(req);\n }\n if (req.xhr && typeof req.xhr.abort === 'function') return () => req.xhr.abort();\n return null;\n }\n\n /**\n * Prepares request options by merging options and removing custom properties\n * @param {import('./index.d.ts').RequestOptions} options - Configuration options\n * @param {AbortSignal} signal - Abort signal to add to request options\n * @returns {Object} Prepared request options\n * @private\n */\n #_prepareRequestOptions(options, signal) {\n const requestOptions = {};\n const customOptions = [\n 'abortController',\n 'cancelToken',\n 'requestKey',\n 'noCancel',\n 'includeQuery',\n 'includeMethod',\n 'verbose',\n ];\n Object.keys(options).forEach((key) => {\n if (customOptions.includes(key)) return;\n requestOptions[key] = options[key];\n });\n requestOptions.signal = signal;\n return requestOptions;\n }\n\n /**\n * Warns when the provided axios instance predates 0.22.0, the first version\n * supporting AbortSignal cancellation. Older instances silently ignore\n * options.signal, so duplicate requests would not be cancelled.\n * @param {object} axiosLib - The axios instance about to be used\n * @private\n */\n #_checkAxiosVersion(axiosLib) {\n const version = typeof axiosLib?.VERSION === 'string' ? axiosLib.VERSION : null;\n if (!version) return;\n const [major, minor] = version.split('.').map(Number);\n if (major === 0 && minor < 22) {\n console.warn(\n `[request-manager] axios >= 0.22.0 is required: axios ${version} ignores the AbortSignal used for automatic cancellation. Please upgrade axios.`\n );\n }\n }\n\n /**\n * Deletes a request from the active requests map and rejects the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} rejectWrapper - The function to reject the wrapper promise\n * @param {*} error - The error to reject the wrapper promise with; the wrapper is not rejected if null/undefined\n * @private\n */\n #_deleteRequest(requestId, rejectWrapper, error) {\n this.activeRequests.delete(requestId);\n if (error !== null && error !== undefined) {\n rejectWrapper(error);\n }\n }\n\n /**\n * Completes a request by deleting it from the active requests map and resolving the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} resolveWrapper - The function to resolve the wrapper promise\n * @param {Promise} requestPromise - The request promise\n * @param {boolean} isCancelled - Whether the request was cancelled\n * @private\n */\n #_completeRequest(requestId, resolveWrapper, requestPromise, isCancelled) {\n this.activeRequests.delete(requestId);\n if (!isCancelled) {\n resolveWrapper(requestPromise);\n }\n }\n\n /**\n * Internal method that handles the core request logic.\n * @param {string} requestId - Unique identifier for the request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise, function, or URL string\n * @param {import('./index.d.ts').BaseRequestOptions} options - Configuration options\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @private\n */\n #_request(requestId, requestPromise, options = {}) {\n const abortController = this.#_resolveAbortController(options.abortController);\n\n // Handle different types of requestPromise inputs\n // Priority: Function (Custom logic) > String (URL) > Promise (axios, fetch, etc.)\n if (typeof requestPromise === 'function') {\n // Function: custom logic for any library (axios, ajax, etc.)\n try {\n requestPromise = requestPromise({\n options: this.#_prepareRequestOptions(options, abortController.signal),\n });\n } catch (error) {\n return Promise.reject(error);\n }\n } else if (typeof requestPromise === 'string') {\n // String (URL): make fetch internally\n try {\n requestPromise = fetch(requestPromise, this.#_prepareRequestOptions(options, abortController.signal));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n // Link the request object's abort method (Ext.Ajax, XHR, etc.) to the cancellation signal\n this.addAbortListener(this.#_resolveAbortMethod(requestPromise), abortController.signal);\n\n // Cancel previous request with the same identifier if it exists\n if (!options.noCancel) this.cancel(requestId);\n\n // Create a wrapper promise that will be resolved/rejected based on the request\n let resolveWrapper, rejectWrapper;\n const wrapperPromise = new Promise((resolve, reject) => {\n resolveWrapper = resolve;\n rejectWrapper = reject;\n });\n\n /**\n * @type {import('./index.d.ts').ActiveRequest}\n */\n const requestInfo = {\n promise: requestPromise,\n abortController: abortController,\n cancelToken: options.cancelToken || null,\n resolveWrapper: resolveWrapper,\n rejectWrapper: rejectWrapper,\n isCancelled: false,\n };\n\n this.activeRequests.set(requestId, requestInfo);\n\n // Handle request promise completion\n if (requestPromise && typeof requestPromise.then === 'function') {\n try {\n let req = requestPromise.then((result) => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, result, requestInfo.isCancelled);\n });\n if (req.catch)\n req.catch((error) => {\n onError(this, error);\n });\n } catch (error) {\n onError(this, error);\n }\n function onError(scope, error) {\n // Check if this requestInfo is still the active one, or if it was cancelled\n if (scope.activeRequests.get(requestId) !== requestInfo) return;\n if (requestInfo.isCancelled) {\n // Already cancelled: let cancel() handle cleanup and reject the wrapper promise\n scope.cancel(requestId);\n return;\n }\n // Only delete if this is still the active request\n scope.#_deleteRequest(requestId, rejectWrapper, error);\n }\n } else {\n // Non-promise (Ext.Ajax request object, raw XHR, etc.). Keep tracked until the\n // underlying XHR finishes so a later duplicate can still cancel it.\n const xhr =\n requestPromise &&\n (requestPromise.xhr ||\n (typeof XMLHttpRequest !== 'undefined' && requestPromise instanceof XMLHttpRequest\n ? requestPromise\n : null));\n const finish = () => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, requestPromise, requestInfo.isCancelled);\n };\n if (xhr && typeof xhr.addEventListener === 'function') {\n xhr.addEventListener('loadend', finish);\n } else {\n setTimeout(finish, 0);\n }\n }\n return wrapperPromise;\n }\n}\n\nexport default RequestManager;\n\nexport { RequestManager };\n"],"names":["RequestManager","constructor","options","arguments","length","undefined","_classPrivateMethodInitSpec","_RequestManager_brand","this","activeRequests","Map","abortController","getOptions","setOptions","getSignal","getAbortController","signal","AbortController","isActive","requestId","has","getActiveCount","size","clear","request","url","requestPromise","_assertClassBrand","_request","call","getRequestId","fetch","axios","axiosLib","Error","_checkAxiosVersion","_ref","requestOptions","_objectSpread","ajax","ajaxFunction","_ref2","xhr","_ref3","fetchOptions","XMLHttpRequest","method","toUpperCase","Promise","resolve","reject","onload","detachAbortListener","status","_xhr$getResponseHeade","response","responseType","getResponseHeader","includes","JSON","parse","_unused","data","statusText","headers","getAllResponseHeaders","message","concat","onerror","ontimeout","open","withCredentials","timeout","Object","keys","forEach","key","setRequestHeader","abortListener","abort","addEventListener","removeEventListener","onabort","send","body","requestKey","prefix","noCancel","Date","now","Math","random","toString","slice","_unused2","String","cleanedUrl","split","includeQuery","methodPrefix","includeMethod","type","cancel","requestInfo","get","isCancelled","aborted","error","cancelToken","_deleteRequest","rejectWrapper","verbose","addAbortListener","abortMethod","cancelAll","requestIds","Array","from","cancelledCount","_resolveAbortController","provided","_resolveAbortMethod","req","ExtAjax","globalThis","Ext","Ajax","_prepareRequestOptions","customOptions","version","VERSION","_version$split$map2","_slicedToArray","map","Number","major","minor","console","warn","delete","_completeRequest","resolveWrapper","wrapperPromise","promise","set","then","result","catch","onError","scope","finish","setTimeout"],"mappings":";;;;;;;;GAQA,MAAMA,EACFC,WAAAA,GAA0B,IAAdC,EAAOC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAA,EAqatBG,OAAAC,GAjaIC,KAAKC,eAAiB,IAAIC,IAI1BF,KAAKN,QAAUA,EAMfM,KAAKG,gBAAkB,IAC3B,CAMAC,UAAAA,GACI,OAAOJ,KAAKN,OAChB,CAMAW,UAAAA,CAAWX,GACPM,KAAKN,QAAUA,CACnB,CAWAY,SAAAA,GACI,OAAON,KAAKO,qBAAqBC,MACrC,CAOAD,kBAAAA,GAEI,OADAP,KAAKG,gBAAkB,IAAIM,gBACpBT,KAAKG,eAChB,CAOAO,QAAAA,CAASC,GACL,OAAOX,KAAKC,eAAeW,IAAID,EACnC,CAMAE,cAAAA,GACI,OAAOb,KAAKC,e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EAAW2F,EAAeH,GACpD,CACJ,KAAO,CAGH,IAAMjE,EACFhB,IACCA,EAAegB,MACe,oBAAnBG,gBAAkCnB,aAA0BmB,eAC9DnB,EACA,OACR4H,EAASA,KACP9I,KAAKC,eAAe+F,IAAIrF,KAAeoF,GAC3C5E,EAAApB,EAAAC,KAAKoI,GAAiB/G,KAAtBrB,KAAuBW,EAAW0H,EAAgBnH,EAAgB6E,EAAYE,cAE9E/D,GAAuC,mBAAzBA,EAAIsC,iBAClBtC,EAAIsC,iBAAiB,UAAWsE,GAEhCC,WAAWD,EAAQ,EAE3B,CACA,OAAOR,CACX"}
@@ -1,4 +1,4 @@
1
- var RequestManager=function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:r;throw new TypeError("Private element is not present on this object")}function r(t,e){(function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")})(t,e),e.add(t)}function n(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach(function(e){n(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(e,r){return function(t){if(Array.isArray(t))return t}(e)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,s,a=[],l=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e);else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==e);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw o}}return a}}(e,r)||function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var a=new WeakSet;
1
+ var RequestManager=function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:r;throw new TypeError("Private element is not present on this object")}function r(t,e){(function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")})(t,e),e.add(t)}function n(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach(function(e){n(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function a(e,r){return function(t){if(Array.isArray(t))return t}(e)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,s=[],l=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e);else for(;!(l=(n=i.call(r)).done)&&(s.push(n.value),s.length!==e);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return s}}(e,r)||function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var s=new WeakSet;
2
2
  /**
3
3
  * RequestManager - A library for managing and regulating HTTP requests efficiently.
4
4
  * @license MIT
@@ -6,5 +6,5 @@ var RequestManager=function(){"use strict";function t(t,e){(null==e||e>t.length)
6
6
  * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)
7
7
  * by accepting Promises as parameters. When a request is repeated with the same identifier,
8
8
  * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.
9
- */function l(t){var e=t||this.abortController||new AbortController;return this.abortController=null,e}function c(t){if(!t)return null;if("function"==typeof t.abort)return()=>t.abort();var e="undefined"!=typeof globalThis&&globalThis.Ext&&globalThis.Ext.Ajax?globalThis.Ext.Ajax:null;return t.xhr&&e&&"function"==typeof e.abort?()=>e.abort(t):t.xhr&&"function"==typeof t.xhr.abort?()=>t.xhr.abort():null}function u(t,e){var r={},n=["abortController","cancelToken","requestKey","noCancel","includeQuery"];return Object.keys(t).forEach(e=>{n.includes(e)||(r[e]=t[e])}),r.signal=e,r}function h(t){var e="string"==typeof(null==t?void 0:t.VERSION)?t.VERSION:null;if(e){var r=s(e.split(".").map(Number),2),n=r[0],o=r[1];0===n&&o<22&&console.warn("[request-manager] axios >= 0.22.0 is required: axios ".concat(e," ignores the AbortSignal used for automatic cancellation. Please upgrade axios."))}}function f(t,e,r){this.activeRequests.delete(t),null!=r&&e(r)}function p(t,e,r,n){this.activeRequests.delete(t),n||e(r)}function d(t,r){var n,o,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=e(a,this,l).call(this,i.abortController);if("function"==typeof r)try{r=r({options:e(a,this,u).call(this,i,s.signal)})}catch(g){return Promise.reject(g)}else if("string"==typeof r)try{r=fetch(r,e(a,this,u).call(this,i,s.signal))}catch(m){return Promise.reject(m)}this.addAbortListener(e(a,this,c).call(this,r),s.signal),i.noCancel||this.cancel(t);var h=new Promise((t,e)=>{n=t,o=e}),d={promise:r,abortController:s,cancelToken:i.cancelToken||null,resolveWrapper:n,rejectWrapper:o,isCancelled:!1};if(this.activeRequests.set(t,d),r&&"function"==typeof r.then){try{var v=r.then(r=>{this.activeRequests.get(t)===d&&e(a,this,p).call(this,t,n,r,d.isCancelled)});v.catch&&v.catch(t=>{w(this,t)})}catch(q){w(this,q)}function w(r,n){r.activeRequests.get(t)===d&&(d.isCancelled?r.cancel(t):e(a,r,f).call(r,t,o,n))}}else{var y=r&&(r.xhr||("undefined"!=typeof XMLHttpRequest&&r instanceof XMLHttpRequest?r:null)),b=()=>{this.activeRequests.get(t)===d&&e(a,this,p).call(this,t,n,r,d.isCancelled)};y&&"function"==typeof y.addEventListener?y.addEventListener("loadend",b):setTimeout(b,0)}return h}return class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,a),this.activeRequests=new Map,this.options=t,this.abortController=null}getOptions(){return this.options}setOptions(t){this.options=t}getSignal(){return this.getAbortController().signal}getAbortController(){return this.abortController=new AbortController,this.abortController}isActive(t){return this.activeRequests.has(t)}getActiveCount(){return this.activeRequests.size}clear(){this.activeRequests.clear()}request(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(a,this,d).call(this,this.getRequestId(t,n),r,n)}fetch(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e(a,this,d).call(this,this.getRequestId(t,r),t,r)}axios(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:null)||axios;return e(a,this,h).call(this,n),e(a,this,d).call(this,this.getRequestId(t,r),e=>{var r=e.options;return n(i({url:t},r))},r)}ajax(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("function"!=typeof t)throw new Error("ajaxFunction parameter must be a function");return e(a,this,d).call(this,this.getRequestId(r,n),e=>{var n=e.options;return t(i({url:r},n))},n)}xhr(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.getRequestId(t,r);return e(a,this,d).call(this,n,e=>{var n=e.options,o=new XMLHttpRequest,i=(r.method||"GET").toUpperCase();return new Promise((e,s)=>{o.onload=function(){if(o.status>=200&&o.status<300){var t,n=o.response;if("json"===r.responseType||(!r.responseType||"text"===r.responseType)&&null!==(t=o.getResponseHeader("Content-Type"))&&void 0!==t&&t.includes("application/json")&&"string"==typeof n)try{n=JSON.parse(n)}catch(t){}e({data:n,status:o.status,statusText:o.statusText,headers:o.getAllResponseHeaders(),xhr:o})}else s({message:"Request failed with status ".concat(o.status),status:o.status,statusText:o.statusText,xhr:o})},o.onerror=function(){s({message:"Network error",xhr:o})},o.ontimeout=function(){s({message:"Request timeout",xhr:o})},o.open(i,t,!0),r.responseType&&(o.responseType=r.responseType),void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),void 0!==r.timeout&&(o.timeout=r.timeout),r.headers&&Object.keys(r.headers).forEach(t=>{o.setRequestHeader(t,r.headers[t])}),n.signal&&n.signal.addEventListener("abort",()=>o.abort()),o.send(r.body||null)})},r)}getRequestId(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.requestKey,n="request_";if(e.noCancel)return"".concat(n).concat(Date.now(),"_").concat(Math.random().toString(36).slice(2,11));if("function"==typeof r)try{r=r()}catch(t){r=null}if(null!=r)return"".concat(n).concat(String(r));var o=t||"";o.includes("://")&&(o=o.split("://")[1]),o.includes("#")&&(o=o.split("#")[0]),!e.includeQuery&&o.includes("?")&&(o=o.split("?")[0]);var i=!1===e.includeMethod?"":"".concat((e.method||e.type||"GET").toUpperCase(),"_");return"".concat(n).concat(i).concat(o)}cancel(t){var r=this.activeRequests.get(t);if(!r)return!1;if(r.isCancelled=!0,r.abortController&&!r.abortController.signal.aborted)try{r.abortController.abort("Request was cancelled")}catch(t){}if(r.cancelToken)try{"function"==typeof r.cancelToken?r.cancelToken():r.cancelToken.cancel&&r.cancelToken.cancel()}catch(t){}return e(a,this,f).call(this,t,r.rejectWrapper,this.getOptions().verbose?new Error("Request ".concat(t," was cancelled")):null),!0}addAbortListener(t,e){t&&e&&e.addEventListener("abort",()=>{if("function"==typeof t)try{t()}catch(t){}})}cancelAll(){var t=Array.from(this.activeRequests.keys()),e=0;return t.forEach(t=>{this.cancel(t)&&e++}),e}}}();
9
+ */function l(t){var e=t||this.abortController||new AbortController;return this.abortController=null,e}function c(t){if(!t)return null;if("function"==typeof t.abort)return()=>t.abort();var e="undefined"!=typeof globalThis&&globalThis.Ext&&globalThis.Ext.Ajax?globalThis.Ext.Ajax:null;return t.xhr&&e&&"function"==typeof e.abort?()=>e.abort(t):t.xhr&&"function"==typeof t.xhr.abort?()=>t.xhr.abort():null}function u(t,e){var r={},n=["abortController","cancelToken","requestKey","noCancel","includeQuery","includeMethod","verbose"];return Object.keys(t).forEach(e=>{n.includes(e)||(r[e]=t[e])}),r.signal=e,r}function h(t){var e="string"==typeof(null==t?void 0:t.VERSION)?t.VERSION:null;if(e){var r=a(e.split(".").map(Number),2),n=r[0],o=r[1];0===n&&o<22&&console.warn("[request-manager] axios >= 0.22.0 is required: axios ".concat(e," ignores the AbortSignal used for automatic cancellation. Please upgrade axios."))}}function f(t,e,r){this.activeRequests.delete(t),null!=r&&e(r)}function p(t,e,r,n){this.activeRequests.delete(t),n||e(r)}function d(t,r){var n,o,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=e(s,this,l).call(this,i.abortController);if("function"==typeof r)try{r=r({options:e(s,this,u).call(this,i,a.signal)})}catch(g){return Promise.reject(g)}else if("string"==typeof r)try{r=fetch(r,e(s,this,u).call(this,i,a.signal))}catch(m){return Promise.reject(m)}this.addAbortListener(e(s,this,c).call(this,r),a.signal),i.noCancel||this.cancel(t);var h=new Promise((t,e)=>{n=t,o=e}),d={promise:r,abortController:a,cancelToken:i.cancelToken||null,resolveWrapper:n,rejectWrapper:o,isCancelled:!1};if(this.activeRequests.set(t,d),r&&"function"==typeof r.then){try{var v=r.then(r=>{this.activeRequests.get(t)===d&&e(s,this,p).call(this,t,n,r,d.isCancelled)});v.catch&&v.catch(t=>{w(this,t)})}catch(q){w(this,q)}function w(r,n){r.activeRequests.get(t)===d&&(d.isCancelled?r.cancel(t):e(s,r,f).call(r,t,o,n))}}else{var y=r&&(r.xhr||("undefined"!=typeof XMLHttpRequest&&r instanceof XMLHttpRequest?r:null)),b=()=>{this.activeRequests.get(t)===d&&e(s,this,p).call(this,t,n,r,d.isCancelled)};y&&"function"==typeof y.addEventListener?y.addEventListener("loadend",b):setTimeout(b,0)}return h}return class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,s),this.activeRequests=new Map,this.options=t,this.abortController=null}getOptions(){return this.options}setOptions(t){this.options=t}getSignal(){return this.getAbortController().signal}getAbortController(){return this.abortController=new AbortController,this.abortController}isActive(t){return this.activeRequests.has(t)}getActiveCount(){return this.activeRequests.size}clear(){this.activeRequests.clear()}request(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(s,this,d).call(this,this.getRequestId(t,n),r,n)}fetch(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e(s,this,d).call(this,this.getRequestId(t,r),t,r)}axios(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:null)||("undefined"!=typeof axios?axios:null);if(!n)throw new Error("axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally");return e(s,this,h).call(this,n),e(s,this,d).call(this,this.getRequestId(t,r),e=>{var r=e.options;return n(i({url:t},r))},r)}ajax(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("function"!=typeof t)throw new Error("ajaxFunction parameter must be a function");return e(s,this,d).call(this,this.getRequestId(r,n),e=>{var n=e.options;return t(i({url:r},n))},n)}xhr(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e(s,this,d).call(this,this.getRequestId(t,r),e=>{var n=e.options,o=new XMLHttpRequest,i=(r.method||"GET").toUpperCase();return new Promise((e,a)=>{o.onload=function(){if(l(),o.status>=200&&o.status<300){var t,n=o.response;if("json"===r.responseType||(!r.responseType||"text"===r.responseType)&&null!==(t=o.getResponseHeader("Content-Type"))&&void 0!==t&&t.includes("application/json")&&"string"==typeof n)try{n=JSON.parse(n)}catch(t){}e({data:n,status:o.status,statusText:o.statusText,headers:o.getAllResponseHeaders(),xhr:o})}else a({message:"Request failed with status ".concat(o.status),status:o.status,statusText:o.statusText,xhr:o})},o.onerror=function(){l(),a({message:"Network error",xhr:o})},o.ontimeout=function(){l(),a({message:"Request timeout",xhr:o})},o.open(i,t,!0),r.responseType&&(o.responseType=r.responseType),void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),void 0!==r.timeout&&(o.timeout=r.timeout),r.headers&&Object.keys(r.headers).forEach(t=>{o.setRequestHeader(t,r.headers[t])});var s=()=>o.abort();n.signal&&n.signal.addEventListener("abort",s);var l=()=>{n.signal&&n.signal.removeEventListener("abort",s)};o.onabort=function(){a({message:"Request was cancelled",xhr:o})},o.send(r.body||null)})},r)}getRequestId(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.requestKey,n="request_";if(e.noCancel)return"".concat(n).concat(Date.now(),"_").concat(Math.random().toString(36).slice(2,11));if("function"==typeof r)try{r=r()}catch(t){r=null}if(null!=r)return"".concat(n).concat(String(r));var o=t||"";o.includes("://")&&(o=o.split("://")[1]),o.includes("#")&&(o=o.split("#")[0]),!e.includeQuery&&o.includes("?")&&(o=o.split("?")[0]);var i=!1===e.includeMethod?"":"".concat((e.method||e.type||"GET").toUpperCase(),"_");return"".concat(n).concat(i).concat(o)}cancel(t){var r=this.activeRequests.get(t);if(!r)return!1;if(r.isCancelled=!0,r.abortController&&!r.abortController.signal.aborted)try{r.abortController.abort("Request was cancelled")}catch(t){}if(r.cancelToken)try{"function"==typeof r.cancelToken?r.cancelToken():r.cancelToken.cancel&&r.cancelToken.cancel()}catch(t){}return e(s,this,f).call(this,t,r.rejectWrapper,this.getOptions().verbose?new Error("Request ".concat(t," was cancelled")):null),!0}addAbortListener(t,e){t&&e&&e.addEventListener("abort",()=>{if("function"==typeof t)try{t()}catch(t){}})}cancelAll(){var t=Array.from(this.activeRequests.keys()),e=0;return t.forEach(t=>{this.cancel(t)&&e++}),e}}}();
10
10
  //# sourceMappingURL=request-manager.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"request-manager.min.js","sources":["../main.js"],"sourcesContent":["/**\n * RequestManager - A library for managing and regulating HTTP requests efficiently.\n * @license MIT\n * @author Eneko Galan <enekogalanelorza@gmail.com>\n * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)\n * by accepting Promises as parameters. When a request is repeated with the same identifier,\n * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.\n */\nclass RequestManager {\n constructor(options = {}) {\n /**\n * @type {Map<string, import('./index.d.ts').ActiveRequest>}\n */\n this.activeRequests = new Map();\n /**\n * @type {import('./index.d.ts').Options}\n */\n this.options = options;\n /**\n * One-shot AbortController for getSignal()/getAbortController() handoff.\n * Consumed by the next request that does not pass options.abortController.\n * @type {AbortController|null}\n */\n this.abortController = null;\n }\n\n /**\n * Gets the manager options\n * @returns {import('./index.d.ts').Options} Manager options\n */\n getOptions() {\n return this.options;\n }\n\n /**\n * Sets the manager options\n * @param {import('./index.d.ts').Options} options - The options to set\n */\n setOptions(options) {\n this.options = options;\n }\n\n /**\n * Creates a new AbortController and returns its signal for the next request()\n * (one getSignal → one request). Do not use for parallel requests; use fetch(),\n * axios(), or request(url, ({ options }) => ...) instead — they create their own signal.\n * @returns {AbortSignal} The signal from a new AbortController\n * @example\n * const signal = requestManager.getSignal();\n * requestManager.request('/api/users', fetch('/api/users', { signal }));\n */\n getSignal() {\n return this.getAbortController().signal;\n }\n\n /**\n * Creates a new AbortController for the next request handoff.\n * Always returns a fresh controller (never reuses one from another in-flight request).\n * @returns {AbortController} A new AbortController instance\n */\n getAbortController() {\n this.abortController = new AbortController();\n return this.abortController;\n }\n\n /**\n * Checks if a request with the given identifier is currently active.\n * @param {string} requestId - The unique identifier to check\n * @returns {boolean} True if the request is active, false otherwise\n */\n isActive(requestId) {\n return this.activeRequests.has(requestId);\n }\n\n /**\n * Gets the number of active requests.\n * @returns {number} The number of currently active requests\n */\n getActiveCount() {\n return this.activeRequests.size;\n }\n\n /**\n * Clears all active requests without cancelling them.\n * Use with caution - this will not cancel the underlying HTTP requests.\n */\n clear() {\n this.activeRequests.clear();\n }\n\n /**\n * Executes an HTTP request, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise or function that returns a promise\n * @param {import('./index.d.ts').RequestOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Request with Promise\n * requestManager.request('/api/users', axios.get('/api/users'));\n * @example\n * // Request with Function\n * requestManager.request('/api/users', ({ options }) => fetch('/api/users', { signal: options.signal, ...options }));\n * @example\n * // Request with Promise and custom cancellation grouping with requestKey\n * const options = {\n * requestKey: 'get-users'\n * }\n * requestManager.request('/api/users', axios.get('/api/users', options), options);\n */\n request(url, requestPromise, options = {}) {\n return this.#_request(this.getRequestId(url, options), requestPromise, options);\n }\n\n /**\n * Executes an HTTP request using fetch, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to fetch\n * @param {import('./index.d.ts').FetchOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.fetch('/api/users');\n * @example\n * // POST request with options\n * requestManager.fetch('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.fetch('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n fetch(url, options = {}) {\n return this.#_request(this.getRequestId(url, options), url, options);\n }\n\n /**\n * Executes an HTTP request using axios, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').AxiosRequestOptions} options - Optional configuration\n * @param {import('./index.d.ts').AxiosInstance|import('./index.d.ts').AxiosStatic|null} axiosInstance - Optional axios instance to use. If not provided, uses global axios.\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request (uses global axios)\n * requestManager.axios('/api/users');\n * @example\n * // With custom axios instance\n * const myAxios = axios.create({ baseURL: 'https://api.example.com' });\n * requestManager.axios('/users', {}, myAxios);\n * @example\n * // POST request with options\n * requestManager.axios('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.axios('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n axios(url, options = {}, axiosInstance = null) {\n const axiosLib = axiosInstance || axios;\n this.#_checkAxiosVersion(axiosLib);\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => axiosLib({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using jQuery.ajax, cancelling any previous request with the same identifier.\n * @param {import('./index.d.ts').AjaxFunction} ajaxFunction - A function that receives { url, ...options } and returns a Promise\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').BaseRequestOptions & Record<string, any>} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.ajax(ajaxFunction, '/api/users');\n * @example\n * // POST request with options\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * requestKey: 'get-users'\n * });\n */\n ajax(ajaxFunction, url, options = {}) {\n if (typeof ajaxFunction !== 'function') throw new Error('ajaxFunction parameter must be a function');\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => ajaxFunction({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using XMLHttpRequest, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').XhrOptions} options - Optional configuration\n * @returns {Promise<import('./index.d.ts').XhrResponse>} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.xhr('/api/users');\n * @example\n * // POST request with options\n * requestManager.xhr('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping\n * requestManager.xhr('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n xhr(url, options = {}) {\n const requestId = this.getRequestId(url, options);\n /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */\n const xhrFunction = ({ options: fetchOptions }) => {\n // Create XMLHttpRequest\n const xhr = new XMLHttpRequest();\n const method = (options.method || 'GET').toUpperCase();\n // Create a promise that wraps the XHR request\n const xhrPromise = new Promise((resolve, reject) => {\n xhr.onload = function () {\n if (xhr.status >= 200 && xhr.status < 300) {\n let response = xhr.response;\n if (\n options.responseType === 'json' ||\n ((!options.responseType || options.responseType === 'text') &&\n xhr.getResponseHeader('Content-Type')?.includes('application/json') &&\n typeof response === 'string')\n ) {\n try {\n response = JSON.parse(response);\n } catch {}\n }\n resolve({\n data: response,\n status: xhr.status,\n statusText: xhr.statusText,\n headers: xhr.getAllResponseHeaders(),\n xhr: xhr,\n });\n } else {\n reject({\n message: `Request failed with status ${xhr.status}`,\n status: xhr.status,\n statusText: xhr.statusText,\n xhr: xhr,\n });\n }\n };\n xhr.onerror = function () {\n reject({\n message: 'Network error',\n xhr: xhr,\n });\n };\n xhr.ontimeout = function () {\n reject({\n message: 'Request timeout',\n xhr: xhr,\n });\n };\n\n // Open the request\n xhr.open(method, url, true);\n\n // Set response type\n if (options.responseType) xhr.responseType = options.responseType;\n // Set withCredentials\n if (options.withCredentials !== undefined) xhr.withCredentials = options.withCredentials;\n // Set timeout\n if (options.timeout !== undefined) xhr.timeout = options.timeout;\n // Set headers\n if (options.headers)\n Object.keys(options.headers).forEach((key) => {\n xhr.setRequestHeader(key, options.headers[key]);\n });\n\n // Connect abort signal to xhr.abort()\n if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', () => xhr.abort());\n\n // Send the request\n xhr.send(options.body || null);\n });\n return xhrPromise;\n };\n return this.#_request(requestId, xhrFunction, options);\n }\n\n /**\n * Returns the request identifier for a URL and options.\n * @param {string} url - The URL used when starting the request\n * @param {import('./index.d.ts').BaseRequestOptions} options - Same options used for the request\n * @returns {string} The request identifier\n * @example\n * requestManager.fetch('/api/users');\n * const id = requestManager.getRequestId('/api/users');\n * requestManager.cancel(id);\n */\n getRequestId(url, options = {}) {\n let requestKey = options.requestKey;\n\n const prefix = 'request_';\n\n // Generate a unique identifier to prevent cancellation for non cancelable requests\n if (options.noCancel) {\n return `${prefix}${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n // Handle function requestKey\n if (typeof requestKey === 'function') {\n try {\n requestKey = requestKey();\n } catch {\n requestKey = null;\n }\n }\n if (requestKey !== null && requestKey !== undefined) return `${prefix}${String(requestKey)}`;\n\n // Use cleaned URL as key as fallback\n let cleanedUrl = url || '';\n if (cleanedUrl.includes('://')) cleanedUrl = cleanedUrl.split('://')[1];\n if (cleanedUrl.includes('#')) cleanedUrl = cleanedUrl.split('#')[0];\n if (!options.includeQuery && cleanedUrl.includes('?')) cleanedUrl = cleanedUrl.split('?')[0];\n\n const methodPrefix =\n options.includeMethod === false ? '' : `${(options.method || options.type || 'GET').toUpperCase()}_`;\n\n return `${prefix}${methodPrefix}${cleanedUrl}`;\n }\n\n /**\n * Cancels a specific request by its identifier.\n * @param {string} requestId - The unique identifier of the request to cancel\n * @returns {boolean} True if the request was found and cancelled, false otherwise\n */\n cancel(requestId) {\n /** @type {import('./index.d.ts').ActiveRequest|undefined} */\n const requestInfo = this.activeRequests.get(requestId);\n if (!requestInfo) return false;\n\n requestInfo.isCancelled = true; // Mark as cancelled\n\n // Try to abort using AbortController (for fetch)\n if (requestInfo.abortController && !requestInfo.abortController.signal.aborted) {\n try {\n requestInfo.abortController.abort('Request was cancelled');\n } catch (error) {}\n }\n\n // Try to cancel using cancel token/function (for axios and others)\n if (requestInfo.cancelToken) {\n try {\n if (typeof requestInfo.cancelToken === 'function') requestInfo.cancelToken();\n else if (requestInfo.cancelToken.cancel) requestInfo.cancelToken.cancel();\n } catch (error) {}\n }\n\n // Reject the wrapper promise\n this.#_deleteRequest(\n requestId,\n requestInfo.rejectWrapper,\n this.getOptions().verbose ? new Error(`Request ${requestId} was cancelled`) : null\n );\n return true;\n }\n\n /**\n * Link abort signal with HTTP client abort method.\n * Useful for custom HTTP clients that only support the abort method to cancel requests.\n * @param {Function} abortMethod - The abort method to call when the signal is aborted\n * @param {AbortSignal} signal - The signal to listen to\n */\n addAbortListener(abortMethod, signal) {\n if (!abortMethod || !signal) return;\n signal.addEventListener('abort', () => {\n if (typeof abortMethod === 'function') {\n try {\n abortMethod();\n } catch (error) {}\n }\n });\n }\n\n /**\n * Cancels all active requests.\n * @returns {number} The number of requests that were cancelled\n */\n cancelAll() {\n const requestIds = Array.from(this.activeRequests.keys());\n let cancelledCount = 0;\n requestIds.forEach((requestId) => {\n if (this.cancel(requestId)) cancelledCount++;\n });\n return cancelledCount;\n }\n\n /**\n * Resolves the AbortController for a request: explicit option, pending handoff, or new.\n * Clears the pending handoff so concurrent requests do not share it.\n * @param {AbortController|undefined} provided - Optional AbortController from options\n * @returns {AbortController}\n * @private\n */\n #_resolveAbortController(provided) {\n const abortController = provided || this.abortController || new AbortController();\n this.abortController = null;\n return abortController;\n }\n\n /**\n * Picks the best abort callback for a client request object.\n * @param {Object} req - The request object\n * @returns {Function|null}\n * @private\n */\n #_resolveAbortMethod(req) {\n if (!req) return null;\n if (typeof req.abort === 'function') return () => req.abort();\n const ExtAjax =\n typeof globalThis !== 'undefined' && globalThis.Ext && globalThis.Ext.Ajax ? globalThis.Ext.Ajax : null;\n if (req.xhr && ExtAjax && typeof ExtAjax.abort === 'function') {\n return () => ExtAjax.abort(req);\n }\n if (req.xhr && typeof req.xhr.abort === 'function') return () => req.xhr.abort();\n return null;\n }\n\n /**\n * Prepares request options by merging options and removing custom properties\n * @param {import('./index.d.ts').RequestOptions} options - Configuration options\n * @param {AbortSignal} signal - Abort signal to add to request options\n * @returns {Object} Prepared request options\n * @private\n */\n #_prepareRequestOptions(options, signal) {\n const requestOptions = {};\n const customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery'];\n Object.keys(options).forEach((key) => {\n if (customOptions.includes(key)) return;\n requestOptions[key] = options[key];\n });\n requestOptions.signal = signal;\n return requestOptions;\n }\n\n /**\n * Warns when the provided axios instance predates 0.22.0, the first version\n * supporting AbortSignal cancellation. Older instances silently ignore\n * options.signal, so duplicate requests would not be cancelled.\n * @param {object} axiosLib - The axios instance about to be used\n * @private\n */\n #_checkAxiosVersion(axiosLib) {\n const version = typeof axiosLib?.VERSION === 'string' ? axiosLib.VERSION : null;\n if (!version) return;\n const [major, minor] = version.split('.').map(Number);\n if (major === 0 && minor < 22) {\n console.warn(\n `[request-manager] axios >= 0.22.0 is required: axios ${version} ignores the AbortSignal used for automatic cancellation. Please upgrade axios.`\n );\n }\n }\n\n /**\n * Deletes a request from the active requests map and rejects the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} rejectWrapper - The function to reject the wrapper promise\n * @param {*} error - The error to reject the wrapper promise with; the wrapper is not rejected if null/undefined\n * @private\n */\n #_deleteRequest(requestId, rejectWrapper, error) {\n this.activeRequests.delete(requestId);\n if (error !== null && error !== undefined) {\n rejectWrapper(error);\n }\n }\n\n /**\n * Completes a request by deleting it from the active requests map and resolving the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} resolveWrapper - The function to resolve the wrapper promise\n * @param {Promise} requestPromise - The request promise\n * @param {boolean} isCancelled - Whether the request was cancelled\n * @private\n */\n #_completeRequest(requestId, resolveWrapper, requestPromise, isCancelled) {\n this.activeRequests.delete(requestId);\n if (!isCancelled) {\n resolveWrapper(requestPromise);\n }\n }\n\n /**\n * Internal method that handles the core request logic.\n * @param {string} requestId - Unique identifier for the request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise, function, or URL string\n * @param {import('./index.d.ts').BaseRequestOptions} options - Configuration options\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @private\n */\n #_request(requestId, requestPromise, options = {}) {\n const abortController = this.#_resolveAbortController(options.abortController);\n\n // Handle different types of requestPromise inputs\n // Priority: Function (Custom logic) > String (URL) > Promise (axios, fetch, etc.)\n if (typeof requestPromise === 'function') {\n // Function: custom logic for any library (axios, ajax, etc.)\n try {\n requestPromise = requestPromise({\n options: this.#_prepareRequestOptions(options, abortController.signal),\n });\n } catch (error) {\n return Promise.reject(error);\n }\n } else if (typeof requestPromise === 'string') {\n // String (URL): make fetch internally\n try {\n requestPromise = fetch(requestPromise, this.#_prepareRequestOptions(options, abortController.signal));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n // Link the request object's abort method (Ext.Ajax, XHR, etc.) to the cancellation signal\n this.addAbortListener(this.#_resolveAbortMethod(requestPromise), abortController.signal);\n\n // Cancel previous request with the same identifier if it exists\n if (!options.noCancel) this.cancel(requestId);\n\n // Create a wrapper promise that will be resolved/rejected based on the request\n let resolveWrapper, rejectWrapper;\n const wrapperPromise = new Promise((resolve, reject) => {\n resolveWrapper = resolve;\n rejectWrapper = reject;\n });\n\n /**\n * @type {import('./index.d.ts').ActiveRequest}\n */\n const requestInfo = {\n promise: requestPromise,\n abortController: abortController,\n cancelToken: options.cancelToken || null,\n resolveWrapper: resolveWrapper,\n rejectWrapper: rejectWrapper,\n isCancelled: false,\n };\n\n this.activeRequests.set(requestId, requestInfo);\n\n // Handle request promise completion\n if (requestPromise && typeof requestPromise.then === 'function') {\n try {\n let req = requestPromise.then((result) => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, result, requestInfo.isCancelled);\n });\n if (req.catch)\n req.catch((error) => {\n onError(this, error);\n });\n } catch (error) {\n onError(this, error);\n }\n function onError(scope, error) {\n // Check if this requestInfo is still the active one, or if it was cancelled\n if (scope.activeRequests.get(requestId) !== requestInfo) return;\n if (requestInfo.isCancelled) {\n // Already cancelled: let cancel() handle cleanup and reject the wrapper promise\n scope.cancel(requestId);\n return;\n }\n // Only delete if this is still the active request\n scope.#_deleteRequest(requestId, rejectWrapper, error);\n }\n } else {\n // Non-promise (Ext.Ajax request object, raw XHR, etc.). Keep tracked until the\n // underlying XHR finishes so a later duplicate can still cancel it.\n const xhr =\n requestPromise &&\n (requestPromise.xhr ||\n (typeof XMLHttpRequest !== 'undefined' && requestPromise instanceof XMLHttpRequest\n ? requestPromise\n : null));\n const finish = () => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, requestPromise, requestInfo.isCancelled);\n };\n if (xhr && typeof xhr.addEventListener === 'function') {\n xhr.addEventListener('loadend', finish);\n } else {\n setTimeout(finish, 0);\n }\n }\n return wrapperPromise;\n }\n}\n\nexport default RequestManager;\n\nexport { RequestManager };\n"],"names":["_resolveAbortController","provided","abortController","this","AbortController","_resolveAbortMethod","req","abort","ExtAjax","globalThis","Ext","Ajax","xhr","_prepareRequestOptions","options","signal","requestOptions","customOptions","Object","keys","forEach","key","includes","_checkAxiosVersion","axiosLib","version","VERSION","_version$split$map2","_slicedToArray","split","map","Number","major","minor","console","warn","concat","_deleteRequest","requestId","rejectWrapper","error","activeRequests","delete","_completeRequest","resolveWrapper","requestPromise","isCancelled","_request","arguments","length","undefined","_assertClassBrand","_RequestManager_brand","call","Promise","reject","fetch","addAbortListener","noCancel","cancel","wrapperPromise","resolve","requestInfo","promise","cancelToken","set","then","result","get","catch","onError","scope","XMLHttpRequest","finish","addEventListener","setTimeout","constructor","_classPrivateMethodInitSpec","Map","getOptions","setOptions","getSignal","getAbortController","isActive","has","getActiveCount","size","clear","request","url","getRequestId","axios","_ref","_objectSpread","ajax","ajaxFunction","Error","_ref2","_ref3","fetchOptions","method","toUpperCase","onload","status","_xhr$getResponseHeade","response","responseType","getResponseHeader","JSON","parse","_unused","data","statusText","headers","getAllResponseHeaders","message","onerror","ontimeout","open","withCredentials","timeout","setRequestHeader","send","body","requestKey","prefix","Date","now","Math","random","toString","slice","_unused2","String","cleanedUrl","includeQuery","methodPrefix","includeMethod","type","aborted","verbose","abortMethod","cancelAll","requestIds","Array","from","cancelledCount"],"mappings":";;;;;;;;K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EAAY5D,gBAAgBa,OAAO4H,QACnE,IACI7E,EAAY5D,gBAAgBK,MAAM,wBACtC,CAAE,MAAOiC,GAAQ,CAIrB,GAAIsB,EAAYE,YACZ,IAC2C,mBAA5BF,EAAYE,YAA4BF,EAAYE,cACtDF,EAAYE,YAAYL,QAAQG,EAAYE,YAAYL,QACrE,CAAE,MAAOnB,GAAQ,CASrB,OALAW,EAAAC,EAAAjD,KAAKkC,GAAegB,KAApBlD,KACImC,EACAwB,EAAYvB,cACZpC,KAAK4E,aAAa6D,QAAU,IAAI5C,MAAK,WAAA5D,OAAYE,EAAS,mBAAoB,OAE3E,CACX,CAQAmB,gBAAAA,CAAiBoF,EAAa9H,GACrB8H,GAAgB9H,GACrBA,EAAO2D,iBAAiB,QAAS,KAC7B,GAA2B,mBAAhBmE,EACP,IACIA,GACJ,CAAE,MAAOrG,GAAQ,GAG7B,CAMAsG,SAAAA,GACI,IAAMC,EAAaC,MAAMC,KAAK9I,KAAKsC,eAAetB,QAC9C+H,EAAiB,EAIrB,OAHAH,EAAW3H,QAASkB,IACZnC,KAAKwD,OAAOrB,IAAY4G,MAEzBA,CACX"}
1
+ {"version":3,"file":"request-manager.min.js","sources":["../main.js"],"sourcesContent":["/**\n * RequestManager - A library for managing and regulating HTTP requests efficiently.\n * @license MIT\n * @author Eneko Galan <enekogalanelorza@gmail.com>\n * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)\n * by accepting Promises as parameters. When a request is repeated with the same identifier,\n * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.\n */\nclass RequestManager {\n constructor(options = {}) {\n /**\n * @type {Map<string, import('./index.d.ts').ActiveRequest>}\n */\n this.activeRequests = new Map();\n /**\n * @type {import('./index.d.ts').Options}\n */\n this.options = options;\n /**\n * One-shot AbortController for getSignal()/getAbortController() handoff.\n * Consumed by the next request that does not pass options.abortController.\n * @type {AbortController|null}\n */\n this.abortController = null;\n }\n\n /**\n * Gets the manager options\n * @returns {import('./index.d.ts').Options} Manager options\n */\n getOptions() {\n return this.options;\n }\n\n /**\n * Sets the manager options\n * @param {import('./index.d.ts').Options} options - The options to set\n */\n setOptions(options) {\n this.options = options;\n }\n\n /**\n * Creates a new AbortController and returns its signal for the next request()\n * (one getSignal → one request). Do not use for parallel requests; use fetch(),\n * axios(), or request(url, ({ options }) => ...) instead — they create their own signal.\n * @returns {AbortSignal} The signal from a new AbortController\n * @example\n * const signal = requestManager.getSignal();\n * requestManager.request('/api/users', fetch('/api/users', { signal }));\n */\n getSignal() {\n return this.getAbortController().signal;\n }\n\n /**\n * Creates a new AbortController for the next request handoff.\n * Always returns a fresh controller (never reuses one from another in-flight request).\n * @returns {AbortController} A new AbortController instance\n */\n getAbortController() {\n this.abortController = new AbortController();\n return this.abortController;\n }\n\n /**\n * Checks if a request with the given identifier is currently active.\n * @param {string} requestId - The unique identifier to check\n * @returns {boolean} True if the request is active, false otherwise\n */\n isActive(requestId) {\n return this.activeRequests.has(requestId);\n }\n\n /**\n * Gets the number of active requests.\n * @returns {number} The number of currently active requests\n */\n getActiveCount() {\n return this.activeRequests.size;\n }\n\n /**\n * Clears all active requests without cancelling them.\n * Use with caution - this will not cancel the underlying HTTP requests.\n */\n clear() {\n this.activeRequests.clear();\n }\n\n /**\n * Executes an HTTP request, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise or function that returns a promise\n * @param {import('./index.d.ts').RequestOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Request with Promise\n * requestManager.request('/api/users', axios.get('/api/users'));\n * @example\n * // Request with Function\n * requestManager.request('/api/users', ({ options }) => fetch('/api/users', { signal: options.signal, ...options }));\n * @example\n * // Request with Promise and custom cancellation grouping with requestKey\n * const options = {\n * requestKey: 'get-users'\n * }\n * requestManager.request('/api/users', axios.get('/api/users', options), options);\n */\n request(url, requestPromise, options = {}) {\n return this.#_request(this.getRequestId(url, options), requestPromise, options);\n }\n\n /**\n * Executes an HTTP request using fetch, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to fetch\n * @param {import('./index.d.ts').FetchOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.fetch('/api/users');\n * @example\n * // POST request with options\n * requestManager.fetch('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.fetch('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n fetch(url, options = {}) {\n return this.#_request(this.getRequestId(url, options), url, options);\n }\n\n /**\n * Executes an HTTP request using axios, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').AxiosRequestOptions} options - Optional configuration\n * @param {import('./index.d.ts').AxiosInstance|import('./index.d.ts').AxiosStatic|null} axiosInstance - Optional axios instance to use. If not provided, uses global axios.\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request (uses global axios)\n * requestManager.axios('/api/users');\n * @example\n * // With custom axios instance\n * const myAxios = axios.create({ baseURL: 'https://api.example.com' });\n * requestManager.axios('/users', {}, myAxios);\n * @example\n * // POST request with options\n * requestManager.axios('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.axios('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n axios(url, options = {}, axiosInstance = null) {\n const axiosLib = axiosInstance || (typeof axios !== 'undefined' ? axios : null);\n if (!axiosLib) {\n throw new Error(\n 'axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally'\n );\n }\n this.#_checkAxiosVersion(axiosLib);\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => axiosLib({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using jQuery.ajax, cancelling any previous request with the same identifier.\n * @param {import('./index.d.ts').AjaxFunction} ajaxFunction - A function that receives { url, ...options } and returns a Promise\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').BaseRequestOptions & Record<string, any>} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.ajax(ajaxFunction, '/api/users');\n * @example\n * // POST request with options\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * requestKey: 'get-users'\n * });\n */\n ajax(ajaxFunction, url, options = {}) {\n if (typeof ajaxFunction !== 'function') throw new Error('ajaxFunction parameter must be a function');\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => ajaxFunction({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using XMLHttpRequest, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').XhrOptions} options - Optional configuration\n * @returns {Promise<import('./index.d.ts').XhrResponse>} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.xhr('/api/users');\n * @example\n * // POST request with options\n * requestManager.xhr('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping\n * requestManager.xhr('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n xhr(url, options = {}) {\n /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */\n const xhrFunction = ({ options: fetchOptions }) => {\n // Create XMLHttpRequest\n const xhr = new XMLHttpRequest();\n const method = (options.method || 'GET').toUpperCase();\n // Create a promise that wraps the XHR request\n const xhrPromise = new Promise((resolve, reject) => {\n xhr.onload = function () {\n detachAbortListener();\n if (xhr.status >= 200 && xhr.status < 300) {\n let response = xhr.response;\n if (\n options.responseType === 'json' ||\n ((!options.responseType || options.responseType === 'text') &&\n xhr.getResponseHeader('Content-Type')?.includes('application/json') &&\n typeof response === 'string')\n ) {\n try {\n response = JSON.parse(response);\n } catch {}\n }\n resolve({\n data: response,\n status: xhr.status,\n statusText: xhr.statusText,\n headers: xhr.getAllResponseHeaders(),\n xhr: xhr,\n });\n } else {\n reject({\n message: `Request failed with status ${xhr.status}`,\n status: xhr.status,\n statusText: xhr.statusText,\n xhr: xhr,\n });\n }\n };\n xhr.onerror = function () {\n detachAbortListener();\n reject({\n message: 'Network error',\n xhr: xhr,\n });\n };\n xhr.ontimeout = function () {\n detachAbortListener();\n reject({\n message: 'Request timeout',\n xhr: xhr,\n });\n };\n\n // Open the request\n xhr.open(method, url, true);\n\n // Set response type\n if (options.responseType) xhr.responseType = options.responseType;\n // Set withCredentials\n if (options.withCredentials !== undefined) xhr.withCredentials = options.withCredentials;\n // Set timeout\n if (options.timeout !== undefined) xhr.timeout = options.timeout;\n // Set headers\n if (options.headers)\n Object.keys(options.headers).forEach((key) => {\n xhr.setRequestHeader(key, options.headers[key]);\n });\n\n // Connect abort signal to xhr.abort()\n const abortListener = () => xhr.abort();\n if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', abortListener);\n // Detach the listener once the request settles so completed requests do not keep it alive\n const detachAbortListener = () => {\n if (fetchOptions.signal) fetchOptions.signal.removeEventListener('abort', abortListener);\n };\n\n xhr.onabort = function () {\n reject({\n message: 'Request was cancelled',\n xhr: xhr,\n });\n };\n\n // Send the request\n xhr.send(options.body || null);\n });\n return xhrPromise;\n };\n return this.#_request(this.getRequestId(url, options), xhrFunction, options);\n }\n\n /**\n * Returns the request identifier for a URL and options.\n * @param {string} url - The URL used when starting the request\n * @param {import('./index.d.ts').BaseRequestOptions} options - Same options used for the request\n * @returns {string} The request identifier\n * @example\n * requestManager.fetch('/api/users');\n * const id = requestManager.getRequestId('/api/users');\n * requestManager.cancel(id);\n */\n getRequestId(url, options = {}) {\n let requestKey = options.requestKey;\n\n const prefix = 'request_';\n\n // Generate a unique identifier to prevent cancellation for non cancelable requests\n if (options.noCancel) {\n return `${prefix}${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n // Handle function requestKey\n if (typeof requestKey === 'function') {\n try {\n requestKey = requestKey();\n } catch {\n requestKey = null;\n }\n }\n if (requestKey !== null && requestKey !== undefined) return `${prefix}${String(requestKey)}`;\n\n // Use cleaned URL as key as fallback\n let cleanedUrl = url || '';\n if (cleanedUrl.includes('://')) cleanedUrl = cleanedUrl.split('://')[1];\n if (cleanedUrl.includes('#')) cleanedUrl = cleanedUrl.split('#')[0];\n if (!options.includeQuery && cleanedUrl.includes('?')) cleanedUrl = cleanedUrl.split('?')[0];\n\n const methodPrefix =\n options.includeMethod === false ? '' : `${(options.method || options.type || 'GET').toUpperCase()}_`;\n\n return `${prefix}${methodPrefix}${cleanedUrl}`;\n }\n\n /**\n * Cancels a specific request by its identifier.\n * @param {string} requestId - The unique identifier of the request to cancel\n * @returns {boolean} True if the request was found and cancelled, false otherwise\n */\n cancel(requestId) {\n /** @type {import('./index.d.ts').ActiveRequest|undefined} */\n const requestInfo = this.activeRequests.get(requestId);\n if (!requestInfo) return false;\n\n requestInfo.isCancelled = true; // Mark as cancelled\n\n // Try to abort using AbortController (for fetch)\n if (requestInfo.abortController && !requestInfo.abortController.signal.aborted) {\n try {\n requestInfo.abortController.abort('Request was cancelled');\n } catch (error) {}\n }\n\n // Try to cancel using cancel token/function (for axios and others)\n if (requestInfo.cancelToken) {\n try {\n if (typeof requestInfo.cancelToken === 'function') requestInfo.cancelToken();\n else if (requestInfo.cancelToken.cancel) requestInfo.cancelToken.cancel();\n } catch (error) {}\n }\n\n // Reject the wrapper promise\n this.#_deleteRequest(\n requestId,\n requestInfo.rejectWrapper,\n this.getOptions().verbose ? new Error(`Request ${requestId} was cancelled`) : null\n );\n return true;\n }\n\n /**\n * Link abort signal with HTTP client abort method.\n * Useful for custom HTTP clients that only support the abort method to cancel requests.\n * @param {Function} abortMethod - The abort method to call when the signal is aborted\n * @param {AbortSignal} signal - The signal to listen to\n */\n addAbortListener(abortMethod, signal) {\n if (!abortMethod || !signal) return;\n signal.addEventListener('abort', () => {\n if (typeof abortMethod === 'function') {\n try {\n abortMethod();\n } catch (error) {}\n }\n });\n }\n\n /**\n * Cancels all active requests.\n * @returns {number} The number of requests that were cancelled\n */\n cancelAll() {\n const requestIds = Array.from(this.activeRequests.keys());\n let cancelledCount = 0;\n requestIds.forEach((requestId) => {\n if (this.cancel(requestId)) cancelledCount++;\n });\n return cancelledCount;\n }\n\n /**\n * Resolves the AbortController for a request: explicit option, pending handoff, or new.\n * Clears the pending handoff so concurrent requests do not share it.\n * @param {AbortController|undefined} provided - Optional AbortController from options\n * @returns {AbortController}\n * @private\n */\n #_resolveAbortController(provided) {\n const abortController = provided || this.abortController || new AbortController();\n this.abortController = null;\n return abortController;\n }\n\n /**\n * Picks the best abort callback for a client request object.\n * @param {Object} req - The request object\n * @returns {Function|null}\n * @private\n */\n #_resolveAbortMethod(req) {\n if (!req) return null;\n if (typeof req.abort === 'function') return () => req.abort();\n const ExtAjax =\n typeof globalThis !== 'undefined' && globalThis.Ext && globalThis.Ext.Ajax ? globalThis.Ext.Ajax : null;\n if (req.xhr && ExtAjax && typeof ExtAjax.abort === 'function') {\n return () => ExtAjax.abort(req);\n }\n if (req.xhr && typeof req.xhr.abort === 'function') return () => req.xhr.abort();\n return null;\n }\n\n /**\n * Prepares request options by merging options and removing custom properties\n * @param {import('./index.d.ts').RequestOptions} options - Configuration options\n * @param {AbortSignal} signal - Abort signal to add to request options\n * @returns {Object} Prepared request options\n * @private\n */\n #_prepareRequestOptions(options, signal) {\n const requestOptions = {};\n const customOptions = [\n 'abortController',\n 'cancelToken',\n 'requestKey',\n 'noCancel',\n 'includeQuery',\n 'includeMethod',\n 'verbose',\n ];\n Object.keys(options).forEach((key) => {\n if (customOptions.includes(key)) return;\n requestOptions[key] = options[key];\n });\n requestOptions.signal = signal;\n return requestOptions;\n }\n\n /**\n * Warns when the provided axios instance predates 0.22.0, the first version\n * supporting AbortSignal cancellation. Older instances silently ignore\n * options.signal, so duplicate requests would not be cancelled.\n * @param {object} axiosLib - The axios instance about to be used\n * @private\n */\n #_checkAxiosVersion(axiosLib) {\n const version = typeof axiosLib?.VERSION === 'string' ? axiosLib.VERSION : null;\n if (!version) return;\n const [major, minor] = version.split('.').map(Number);\n if (major === 0 && minor < 22) {\n console.warn(\n `[request-manager] axios >= 0.22.0 is required: axios ${version} ignores the AbortSignal used for automatic cancellation. Please upgrade axios.`\n );\n }\n }\n\n /**\n * Deletes a request from the active requests map and rejects the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} rejectWrapper - The function to reject the wrapper promise\n * @param {*} error - The error to reject the wrapper promise with; the wrapper is not rejected if null/undefined\n * @private\n */\n #_deleteRequest(requestId, rejectWrapper, error) {\n this.activeRequests.delete(requestId);\n if (error !== null && error !== undefined) {\n rejectWrapper(error);\n }\n }\n\n /**\n * Completes a request by deleting it from the active requests map and resolving the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} resolveWrapper - The function to resolve the wrapper promise\n * @param {Promise} requestPromise - The request promise\n * @param {boolean} isCancelled - Whether the request was cancelled\n * @private\n */\n #_completeRequest(requestId, resolveWrapper, requestPromise, isCancelled) {\n this.activeRequests.delete(requestId);\n if (!isCancelled) {\n resolveWrapper(requestPromise);\n }\n }\n\n /**\n * Internal method that handles the core request logic.\n * @param {string} requestId - Unique identifier for the request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise, function, or URL string\n * @param {import('./index.d.ts').BaseRequestOptions} options - Configuration options\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @private\n */\n #_request(requestId, requestPromise, options = {}) {\n const abortController = this.#_resolveAbortController(options.abortController);\n\n // Handle different types of requestPromise inputs\n // Priority: Function (Custom logic) > String (URL) > Promise (axios, fetch, etc.)\n if (typeof requestPromise === 'function') {\n // Function: custom logic for any library (axios, ajax, etc.)\n try {\n requestPromise = requestPromise({\n options: this.#_prepareRequestOptions(options, abortController.signal),\n });\n } catch (error) {\n return Promise.reject(error);\n }\n } else if (typeof requestPromise === 'string') {\n // String (URL): make fetch internally\n try {\n requestPromise = fetch(requestPromise, this.#_prepareRequestOptions(options, abortController.signal));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n // Link the request object's abort method (Ext.Ajax, XHR, etc.) to the cancellation signal\n this.addAbortListener(this.#_resolveAbortMethod(requestPromise), abortController.signal);\n\n // Cancel previous request with the same identifier if it exists\n if (!options.noCancel) this.cancel(requestId);\n\n // Create a wrapper promise that will be resolved/rejected based on the request\n let resolveWrapper, rejectWrapper;\n const wrapperPromise = new Promise((resolve, reject) => {\n resolveWrapper = resolve;\n rejectWrapper = reject;\n });\n\n /**\n * @type {import('./index.d.ts').ActiveRequest}\n */\n const requestInfo = {\n promise: requestPromise,\n abortController: abortController,\n cancelToken: options.cancelToken || null,\n resolveWrapper: resolveWrapper,\n rejectWrapper: rejectWrapper,\n isCancelled: false,\n };\n\n this.activeRequests.set(requestId, requestInfo);\n\n // Handle request promise completion\n if (requestPromise && typeof requestPromise.then === 'function') {\n try {\n let req = requestPromise.then((result) => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, result, requestInfo.isCancelled);\n });\n if (req.catch)\n req.catch((error) => {\n onError(this, error);\n });\n } catch (error) {\n onError(this, error);\n }\n function onError(scope, error) {\n // Check if this requestInfo is still the active one, or if it was cancelled\n if (scope.activeRequests.get(requestId) !== requestInfo) return;\n if (requestInfo.isCancelled) {\n // Already cancelled: let cancel() handle cleanup and reject the wrapper promise\n scope.cancel(requestId);\n return;\n }\n // Only delete if this is still the active request\n scope.#_deleteRequest(requestId, rejectWrapper, error);\n }\n } else {\n // Non-promise (Ext.Ajax request object, raw XHR, etc.). Keep tracked until the\n // underlying XHR finishes so a later duplicate can still cancel it.\n const xhr =\n requestPromise &&\n (requestPromise.xhr ||\n (typeof XMLHttpRequest !== 'undefined' && requestPromise instanceof XMLHttpRequest\n ? requestPromise\n : null));\n const finish = () => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, requestPromise, requestInfo.isCancelled);\n };\n if (xhr && typeof xhr.addEventListener === 'function') {\n xhr.addEventListener('loadend', finish);\n } else {\n setTimeout(finish, 0);\n }\n }\n return wrapperPromise;\n }\n}\n\nexport default RequestManager;\n\nexport { RequestManager };\n"],"names":["_resolveAbortController","provided","abortController","this","AbortController","_resolveAbortMethod","req","abort","ExtAjax","globalThis","Ext","Ajax","xhr","_prepareRequestOptions","options","signal","requestOptions","customOptions","Object","keys","forEach","key","includes","_checkAxiosVersion","axiosLib","version","VERSION","_version$split$map2","_slicedToArray","split","map","Number","major","minor","console","warn","concat","_deleteRequest","requestId","rejectWrapper","error","activeRequests","delete","_completeRequest","resolveWrapper","requestPromise","isCancelled","_request","arguments","length","undefined","_assertClassBrand","_RequestManager_brand","call","Promise","reject","fetch","addAbortListener","noCancel","cancel","wrapperPromise","resolve","requestInfo","promise","cancelToken","set","then","result","get","catch","onError","scope","XMLHttpRequest","finish","addEventListener","setTimeout","constructor","_classPrivateMethodInitSpec","Map","getOptions","setOptions","getSignal","getAbortController","isActive","has","getActiveCount","size","clear","request","url","getRequestId","axios","Error","_ref","_objectSpread","ajax","ajaxFunction","_ref2","_ref3","fetchOptions","method","toUpperCase","onload","detachAbortListener","status","_xhr$getResponseHeade","response","responseType","getResponseHeader","JSON","parse","_unused","data","statusText","headers","getAllResponseHeaders","message","onerror","ontimeout","open","withCredentials","timeout","setRequestHeader","abortListener","removeEventListener","onabort","send","body","requestKey","prefix","Date","now","Math","random","toString","slice","_unused2","String","cleanedUrl","includeQuery","methodPrefix","includeMethod","type","abor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AAE,GAAAzG,QAAOtB,EAAQsF,QAAUtF,EAAQgI,MAAQ,OAAOzC,cAAa,KAErG,MAAA,GAAAjE,OAAU6F,GAAM7F,OAAGwG,GAAYxG,OAAGsG,EACtC,CAOA/E,MAAAA,CAAOrB,GAEH,IAAMwB,EAAc3D,KAAKsC,eAAe2B,IAAI9B,GAC5C,IAAKwB,EAAa,OAAO,EAKzB,GAHAA,EAAYhB,aAAc,EAGtBgB,EAAY5D,kBAAoB4D,EAAY5D,gBAAgBa,OAAOgI,QACnE,IACIjF,EAAY5D,gBAAgBK,MAAM,wBACtC,CAAE,MAAOiC,GAAQ,CAIrB,GAAIsB,EAAYE,YACZ,IAC2C,mBAA5BF,EAAYE,YAA4BF,EAAYE,cACtDF,EAAYE,YAAYL,QAAQG,EAAYE,YAAYL,QACrE,CAAE,MAAOnB,GAAQ,CASrB,OALAW,EAAAC,EAAAjD,KAAKkC,GAAegB,KAApBlD,KACImC,EACAwB,EAAYvB,cACZpC,KAAK4E,aAAaiE,QAAU,IAAIpD,MAAK,WAAAxD,OAAYE,EAAS,mBAAoB,OAE3E,CACX,CAQAmB,gBAAAA,CAAiBwF,EAAalI,GACrBkI,GAAgBlI,GACrBA,EAAO2D,iBAAiB,QAAS,KAC7B,GAA2B,mBAAhBuE,EACP,IACIA,GACJ,CAAE,MAAOzG,GAAQ,GAG7B,CAMA0G,SAAAA,GACI,IAAMC,EAAaC,MAAMC,KAAKlJ,KAAKsC,eAAetB,QAC9CmI,EAAiB,EAIrB,OAHAH,EAAW/H,QAASkB,IACZnC,KAAKwD,OAAOrB,IAAYgH,MAEzBA,CACX"}
@@ -282,7 +282,10 @@
282
282
  axios(url) {
283
283
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
284
284
  var axiosInstance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
285
- var axiosLib = axiosInstance || axios;
285
+ var axiosLib = axiosInstance || (typeof axios !== 'undefined' ? axios : null);
286
+ if (!axiosLib) {
287
+ throw new Error('axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally');
288
+ }
286
289
  _assertClassBrand(_RequestManager_brand, this, _checkAxiosVersion).call(this, axiosLib);
287
290
  return _assertClassBrand(_RequestManager_brand, this, _request).call(this, this.getRequestId(url, options), _ref => {
288
291
  var requestOptions = _ref.options;
@@ -348,7 +351,6 @@
348
351
  */
349
352
  xhr(url) {
350
353
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
351
- var requestId = this.getRequestId(url, options);
352
354
  /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */
353
355
  var xhrFunction = _ref3 => {
354
356
  var fetchOptions = _ref3.options;
@@ -358,6 +360,7 @@
358
360
  // Create a promise that wraps the XHR request
359
361
  var xhrPromise = new Promise((resolve, reject) => {
360
362
  xhr.onload = function () {
363
+ detachAbortListener();
361
364
  if (xhr.status >= 200 && xhr.status < 300) {
362
365
  var _xhr$getResponseHeade;
363
366
  var response = xhr.response;
@@ -383,12 +386,14 @@
383
386
  }
384
387
  };
385
388
  xhr.onerror = function () {
389
+ detachAbortListener();
386
390
  reject({
387
391
  message: 'Network error',
388
392
  xhr: xhr
389
393
  });
390
394
  };
391
395
  xhr.ontimeout = function () {
396
+ detachAbortListener();
392
397
  reject({
393
398
  message: 'Request timeout',
394
399
  xhr: xhr
@@ -410,14 +415,25 @@
410
415
  });
411
416
 
412
417
  // Connect abort signal to xhr.abort()
413
- if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', () => xhr.abort());
418
+ var abortListener = () => xhr.abort();
419
+ if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', abortListener);
420
+ // Detach the listener once the request settles so completed requests do not keep it alive
421
+ var detachAbortListener = () => {
422
+ if (fetchOptions.signal) fetchOptions.signal.removeEventListener('abort', abortListener);
423
+ };
424
+ xhr.onabort = function () {
425
+ reject({
426
+ message: 'Request was cancelled',
427
+ xhr: xhr
428
+ });
429
+ };
414
430
 
415
431
  // Send the request
416
432
  xhr.send(options.body || null);
417
433
  });
418
434
  return xhrPromise;
419
435
  };
420
- return _assertClassBrand(_RequestManager_brand, this, _request).call(this, requestId, xhrFunction, options);
436
+ return _assertClassBrand(_RequestManager_brand, this, _request).call(this, this.getRequestId(url, options), xhrFunction, options);
421
437
  }
422
438
 
423
439
  /**
@@ -549,7 +565,7 @@
549
565
  */
550
566
  function _prepareRequestOptions(options, signal) {
551
567
  var requestOptions = {};
552
- var customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery'];
568
+ var customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery', 'includeMethod', 'verbose'];
553
569
  Object.keys(options).forEach(key => {
554
570
  if (customOptions.includes(key)) return;
555
571
  requestOptions[key] = options[key];