@d1g1tal/transportr 1.2.1 → 1.2.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.
- package/dist/transportr.js +66 -58
- package/dist/transportr.min.js +2 -2
- package/dist/transportr.min.js.map +3 -3
- package/package.json +1 -1
- package/src/transportr.js +69 -58
package/dist/transportr.js
CHANGED
|
@@ -2187,8 +2187,8 @@ var Transportr = (() => {
|
|
|
2187
2187
|
* the specified options, where the method is GET.
|
|
2188
2188
|
*
|
|
2189
2189
|
* @async
|
|
2190
|
-
* @param {string} path
|
|
2191
|
-
* @param {RequestOptions} [options]
|
|
2190
|
+
* @param {string} [path] The path to the resource you want to get.
|
|
2191
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2192
2192
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
|
|
2193
2193
|
*/
|
|
2194
2194
|
async get(path, options) {
|
|
@@ -2198,9 +2198,9 @@ var Transportr = (() => {
|
|
|
2198
2198
|
* This function makes a POST request to the given path with the given body and options.
|
|
2199
2199
|
*
|
|
2200
2200
|
* @async
|
|
2201
|
-
* @param {string} path
|
|
2202
|
-
* @param {RequestBody} body
|
|
2203
|
-
* @param {RequestOptions} [options]
|
|
2201
|
+
* @param {string} [path] The path to the endpoint you want to call.
|
|
2202
|
+
* @param {RequestBody} body The body of the request.
|
|
2203
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2204
2204
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response body.
|
|
2205
2205
|
*/
|
|
2206
2206
|
async post(path, body, options) {
|
|
@@ -2211,8 +2211,8 @@ var Transportr = (() => {
|
|
|
2211
2211
|
* the specified options, where the method is PUT.
|
|
2212
2212
|
*
|
|
2213
2213
|
* @async
|
|
2214
|
-
* @param {string} path
|
|
2215
|
-
* @param {RequestOptions} [options]
|
|
2214
|
+
* @param {string} [path] The path to the endpoint you want to call.
|
|
2215
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2216
2216
|
* @returns {Promise<ResponseBody>} The return value of the #request method.
|
|
2217
2217
|
*/
|
|
2218
2218
|
async put(path, options) {
|
|
@@ -2222,8 +2222,8 @@ var Transportr = (() => {
|
|
|
2222
2222
|
* It takes a path and options, and returns a request with the method set to PATCH.
|
|
2223
2223
|
*
|
|
2224
2224
|
* @async
|
|
2225
|
-
* @param {string} path
|
|
2226
|
-
* @param {RequestOptions} [options]
|
|
2225
|
+
* @param {string} [path] The path to the endpoint you want to hit.
|
|
2226
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2227
2227
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response of the request.
|
|
2228
2228
|
*/
|
|
2229
2229
|
async patch(path, options) {
|
|
@@ -2233,8 +2233,8 @@ var Transportr = (() => {
|
|
|
2233
2233
|
* It takes a path and options, and returns a request with the method set to DELETE.
|
|
2234
2234
|
*
|
|
2235
2235
|
* @async
|
|
2236
|
-
* @param {string} path
|
|
2237
|
-
* @param {RequestOptions} [options]
|
|
2236
|
+
* @param {string} [path] The path to the resource you want to access.
|
|
2237
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2238
2238
|
* @returns {Promise<ResponseBody>} The result of the request.
|
|
2239
2239
|
*/
|
|
2240
2240
|
async delete(path, options) {
|
|
@@ -2244,8 +2244,8 @@ var Transportr = (() => {
|
|
|
2244
2244
|
* Returns the response headers of a request to the given path.
|
|
2245
2245
|
*
|
|
2246
2246
|
* @async
|
|
2247
|
-
* @param {string} path
|
|
2248
|
-
* @param {RequestOptions} [options]
|
|
2247
|
+
* @param {string} [path] The path to the resource you want to access.
|
|
2248
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2249
2249
|
* @returns {Promise<ResponseBody>} A promise that resolves to the response object.
|
|
2250
2250
|
*/
|
|
2251
2251
|
async head(path, options) {
|
|
@@ -2255,8 +2255,8 @@ var Transportr = (() => {
|
|
|
2255
2255
|
* It takes a path and options, and returns a request with the method set to OPTIONS.
|
|
2256
2256
|
*
|
|
2257
2257
|
* @async
|
|
2258
|
-
* @param {string} path
|
|
2259
|
-
* @param {RequestOptions} [options]
|
|
2258
|
+
* @param {string} [path] The path to the resource.
|
|
2259
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2260
2260
|
* @returns {Promise<ResponseBody>} The return value of the #request method.
|
|
2261
2261
|
*/
|
|
2262
2262
|
async options(path, options) {
|
|
@@ -2266,8 +2266,8 @@ var Transportr = (() => {
|
|
|
2266
2266
|
* It takes a path and options, and makes a request to the server.
|
|
2267
2267
|
*
|
|
2268
2268
|
* @async
|
|
2269
|
-
* @param {string} path
|
|
2270
|
-
* @param {RequestOptions} [options]
|
|
2269
|
+
* @param {string} [path] The path to the endpoint you want to hit.
|
|
2270
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2271
2271
|
* @returns {Promise<ResponseBody>} The return value of the function is the return value of the function that is passed to the `then` method of the promise returned by the `fetch` method.
|
|
2272
2272
|
*/
|
|
2273
2273
|
async request(path, options) {
|
|
@@ -2277,8 +2277,8 @@ var Transportr = (() => {
|
|
|
2277
2277
|
* It gets a JSON resource from the server.
|
|
2278
2278
|
*
|
|
2279
2279
|
* @async
|
|
2280
|
-
* @param {string} path
|
|
2281
|
-
* @param {RequestOptions} [options]
|
|
2280
|
+
* @param {string} [path] The path to the resource.
|
|
2281
|
+
* @param {RequestOptions} [options] The options object to pass to the request.
|
|
2282
2282
|
* @returns {Promise<JsonObject>} A promise that resolves to the response body as a JSON object.
|
|
2283
2283
|
*/
|
|
2284
2284
|
async getJson(path, options) {
|
|
@@ -2288,8 +2288,8 @@ var Transportr = (() => {
|
|
|
2288
2288
|
* It gets the XML representation of the resource at the given path.
|
|
2289
2289
|
*
|
|
2290
2290
|
* @async
|
|
2291
|
-
* @param {string} path
|
|
2292
|
-
* @param {RequestOptions} [options]
|
|
2291
|
+
* @param {string} [path] The path to the resource you want to get.
|
|
2292
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2293
2293
|
* @returns {Promise<Document>} The result of the function call to #get.
|
|
2294
2294
|
*/
|
|
2295
2295
|
async getXml(path, options) {
|
|
@@ -2300,8 +2300,8 @@ var Transportr = (() => {
|
|
|
2300
2300
|
*
|
|
2301
2301
|
* @todo Add way to return portion of the retrieved HTML using a selector. Like jQuery.
|
|
2302
2302
|
* @async
|
|
2303
|
-
* @param {string} path
|
|
2304
|
-
* @param {RequestOptions} [options]
|
|
2303
|
+
* @param {string} [path] The path to the resource.
|
|
2304
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2305
2305
|
* @returns {Promise<Document>} The return value of the function is the return value of the function passed to the `then`
|
|
2306
2306
|
* method of the promise returned by the `#get` method.
|
|
2307
2307
|
*/
|
|
@@ -2311,10 +2311,10 @@ var Transportr = (() => {
|
|
|
2311
2311
|
/**
|
|
2312
2312
|
* It returns a promise that resolves to the HTML fragment at the given path.
|
|
2313
2313
|
*
|
|
2314
|
-
* @todo
|
|
2314
|
+
* @todo Add way to return portion of the retrieved HTML using a selector. Like jQuery.
|
|
2315
2315
|
* @async
|
|
2316
|
-
* @param {string} path
|
|
2317
|
-
* @param {RequestOptions} [options]
|
|
2316
|
+
* @param {string} [path] The path to the resource.
|
|
2317
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2318
2318
|
* @returns {Promise<DocumentFragment>} A promise that resolves to an HTML fragment.
|
|
2319
2319
|
*/
|
|
2320
2320
|
async getHtmlFragment(path, options) {
|
|
@@ -2325,8 +2325,8 @@ var Transportr = (() => {
|
|
|
2325
2325
|
* CORS is enabled by default.
|
|
2326
2326
|
*
|
|
2327
2327
|
* @async
|
|
2328
|
-
* @param {string} path
|
|
2329
|
-
* @param {RequestOptions} [options]
|
|
2328
|
+
* @param {string} [path] The path to the script.
|
|
2329
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2330
2330
|
* @returns {Promise<void>} A promise that has been resolved.
|
|
2331
2331
|
*/
|
|
2332
2332
|
async getScript(path, options) {
|
|
@@ -2336,8 +2336,8 @@ var Transportr = (() => {
|
|
|
2336
2336
|
* Gets a stylesheet from the server, and adds it as a {@link Blob} {@link URL}.
|
|
2337
2337
|
*
|
|
2338
2338
|
* @async
|
|
2339
|
-
* @param {string} path
|
|
2340
|
-
* @param {RequestOptions} [options]
|
|
2339
|
+
* @param {string} [path] The path to the stylesheet.
|
|
2340
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2341
2341
|
* @returns {Promise<void>} A promise that has been resolved.
|
|
2342
2342
|
*/
|
|
2343
2343
|
async getStylesheet(path, options) {
|
|
@@ -2347,8 +2347,8 @@ var Transportr = (() => {
|
|
|
2347
2347
|
* It returns a blob from the specified path.
|
|
2348
2348
|
*
|
|
2349
2349
|
* @async
|
|
2350
|
-
* @param {string} path
|
|
2351
|
-
* @param {RequestOptions} [options]
|
|
2350
|
+
* @param {string} [path] The path to the resource.
|
|
2351
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2352
2352
|
* @returns {Promise<Blob>} A promise that resolves to a blob.
|
|
2353
2353
|
*/
|
|
2354
2354
|
async getBlob(path, options) {
|
|
@@ -2358,8 +2358,8 @@ var Transportr = (() => {
|
|
|
2358
2358
|
* It returns a promise that resolves to an object URL.
|
|
2359
2359
|
*
|
|
2360
2360
|
* @async
|
|
2361
|
-
* @param {string} path
|
|
2362
|
-
* @param {RequestOptions} [options]
|
|
2361
|
+
* @param {string|RequestOptions} [path] The path to the resource.
|
|
2362
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2363
2363
|
* @returns {Promise<string>} A promise that resolves to an object URL.
|
|
2364
2364
|
*/
|
|
2365
2365
|
async getImage(path, options) {
|
|
@@ -2369,8 +2369,8 @@ var Transportr = (() => {
|
|
|
2369
2369
|
* It gets a buffer from the specified path
|
|
2370
2370
|
*
|
|
2371
2371
|
* @async
|
|
2372
|
-
* @param {string} path
|
|
2373
|
-
* @param {RequestOptions} [options]
|
|
2372
|
+
* @param {string} [path] The path to the resource.
|
|
2373
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2374
2374
|
* @returns {Promise<ArrayBuffer>} A promise that resolves to a buffer.
|
|
2375
2375
|
*/
|
|
2376
2376
|
async getBuffer(path, options) {
|
|
@@ -2380,8 +2380,8 @@ var Transportr = (() => {
|
|
|
2380
2380
|
* It returns a readable stream of the response body from the specified path.
|
|
2381
2381
|
*
|
|
2382
2382
|
* @async
|
|
2383
|
-
* @param {string} path
|
|
2384
|
-
* @param {RequestOptions} [options]
|
|
2383
|
+
* @param {string} [path] The path to the resource.
|
|
2384
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2385
2385
|
* @returns {Promise<ReadableStream<Uint8Array>>} A readable stream.
|
|
2386
2386
|
*/
|
|
2387
2387
|
async getStream(path, options) {
|
|
@@ -2393,13 +2393,14 @@ var Transportr = (() => {
|
|
|
2393
2393
|
*
|
|
2394
2394
|
* @private
|
|
2395
2395
|
* @async
|
|
2396
|
-
* @param {string} path
|
|
2397
|
-
* @param {RequestOptions} [userOptions]
|
|
2398
|
-
* @param {RequestOptions} [options]
|
|
2399
|
-
* @param {ResponseHandler<ResponseBody>} [responseHandler]
|
|
2396
|
+
* @param {string} [path] The path to the endpoint you want to call.
|
|
2397
|
+
* @param {RequestOptions} [userOptions] The options passed to the public function to use for the request.
|
|
2398
|
+
* @param {RequestOptions} [options] The options for the request.
|
|
2399
|
+
* @param {ResponseHandler<ResponseBody>} [responseHandler] A function that will be called with the response object.
|
|
2400
2400
|
* @returns {Promise<ResponseBody>} The result of the #request method.
|
|
2401
2401
|
*/
|
|
2402
2402
|
async #get(path, userOptions, options, responseHandler) {
|
|
2403
|
+
delete userOptions?.method;
|
|
2403
2404
|
return this.#request(path, userOptions, options, responseHandler);
|
|
2404
2405
|
}
|
|
2405
2406
|
/**
|
|
@@ -2408,14 +2409,18 @@ var Transportr = (() => {
|
|
|
2408
2409
|
*
|
|
2409
2410
|
* @private
|
|
2410
2411
|
* @async
|
|
2411
|
-
* @param {string} path
|
|
2412
|
-
* @param {RequestOptions} [userOptions={}]
|
|
2413
|
-
* @param {RequestOptions} [options={}]
|
|
2414
|
-
* @param {ResponseHandler<ResponseBody>} [responseHandler]
|
|
2412
|
+
* @param {string} [path] The path to the resource you want to access.
|
|
2413
|
+
* @param {RequestOptions} [userOptions={}] The options passed to the public function to use for the request.
|
|
2414
|
+
* @param {RequestOptions} [options={}] The options to use for the request.
|
|
2415
|
+
* @param {ResponseHandler<ResponseBody>} [responseHandler] A function that will be called with the response body as a parameter. This
|
|
2415
2416
|
* is useful if you want to do something with the response body before returning it.
|
|
2416
2417
|
* @returns {Promise<ResponseBody>} The response from the API call.
|
|
2417
2418
|
*/
|
|
2418
2419
|
async #request(path, userOptions = {}, options = {}, responseHandler) {
|
|
2420
|
+
if (object_type_default(path) == Object) {
|
|
2421
|
+
userOptions = path;
|
|
2422
|
+
path = void 0;
|
|
2423
|
+
}
|
|
2419
2424
|
const requestOptions = object_merge_default(this.#options, _Transportr.#convertRequestOptions(userOptions), options);
|
|
2420
2425
|
const url = _Transportr.#createUrl(this.#baseUrl, path, requestOptions.searchParams);
|
|
2421
2426
|
const signalController = new SignalController(requestOptions.signal);
|
|
@@ -2519,9 +2524,9 @@ var Transportr = (() => {
|
|
|
2519
2524
|
* @private
|
|
2520
2525
|
* @static
|
|
2521
2526
|
* @async
|
|
2522
|
-
* @param {Response} response
|
|
2523
|
-
* @param {URL} url
|
|
2524
|
-
* @param {ResponseHandler<ResponseBody>} [handler]
|
|
2527
|
+
* @param {Response} response The response object returned by the fetch API.
|
|
2528
|
+
* @param {URL} url The path to the resource you want to access. Used for error handling.
|
|
2529
|
+
* @param {ResponseHandler<ResponseBody>} [handler] The handler to use for processing the response.
|
|
2525
2530
|
* @returns {Promise<ResponseBody>} The response is being returned.
|
|
2526
2531
|
*/
|
|
2527
2532
|
async #processResponse(response, url, handler) {
|
|
@@ -2550,18 +2555,21 @@ var Transportr = (() => {
|
|
|
2550
2555
|
*
|
|
2551
2556
|
* @private
|
|
2552
2557
|
* @static
|
|
2553
|
-
* @param {URL} url
|
|
2554
|
-
* @param {string} path
|
|
2555
|
-
* @param {Object<string, string>} [searchParams={}]
|
|
2558
|
+
* @param {URL} url The URL to use as a base.
|
|
2559
|
+
* @param {string} [path] The path to the resource. This can be a relative path or a full URL.
|
|
2560
|
+
* @param {Object<string, string>} [searchParams={}] An object containing the query parameters to be added to the URL.
|
|
2556
2561
|
* @returns {URL} A new URL object with the pathname and origin of the url parameter, and the path parameter
|
|
2557
2562
|
* appended to the end of the pathname.
|
|
2558
2563
|
*/
|
|
2559
2564
|
static #createUrl(url, path, searchParams = {}) {
|
|
2565
|
+
let _url;
|
|
2560
2566
|
if (path) {
|
|
2561
|
-
|
|
2567
|
+
_url = path.startsWith("/") ? new URL(`${url.pathname.replace(endsWithSlashRegEx, "")}${path}`, url.origin) : new URL(path);
|
|
2568
|
+
} else {
|
|
2569
|
+
_url = new URL(url);
|
|
2562
2570
|
}
|
|
2563
|
-
Object.entries(searchParams).forEach(([key, value]) =>
|
|
2564
|
-
return
|
|
2571
|
+
Object.entries(searchParams).forEach(([key, value]) => _url.searchParams.append(key, value));
|
|
2572
|
+
return _url;
|
|
2565
2573
|
}
|
|
2566
2574
|
/**
|
|
2567
2575
|
* If the request method is POST, PUT, or PATCH, and the content type is JSON, then the request body
|
|
@@ -2569,8 +2577,8 @@ var Transportr = (() => {
|
|
|
2569
2577
|
*
|
|
2570
2578
|
* @private
|
|
2571
2579
|
* @static
|
|
2572
|
-
* @param {RequestMethod} method
|
|
2573
|
-
* @param {HttpMediaType} contentType
|
|
2580
|
+
* @param {RequestMethod} method The HTTP request method.
|
|
2581
|
+
* @param {HttpMediaType} contentType The headers of the request.
|
|
2574
2582
|
* @returns {boolean} `true` if the request body needs to be serialized, `false` otherwise.
|
|
2575
2583
|
*/
|
|
2576
2584
|
static #needsSerialization(method, contentType) {
|
|
@@ -2578,7 +2586,7 @@ var Transportr = (() => {
|
|
|
2578
2586
|
}
|
|
2579
2587
|
/**
|
|
2580
2588
|
*
|
|
2581
|
-
* @param {RequestOptions} options
|
|
2589
|
+
* @param {RequestOptions} options The options passed to the public function to use for the request.
|
|
2582
2590
|
* @returns {RequestOptions} The options to use for the request.
|
|
2583
2591
|
*/
|
|
2584
2592
|
static #convertRequestOptions(options) {
|
package/dist/transportr.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Transportr=(()=>{var v=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var oe=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},ne=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let
|
|
2
|
-
`,"\r"],Se=/^[ \t\n\r]+/u,X=/[ \t\n\r]+$/u,Re=/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u,xe=/^[\t\u0020-\u007E\u0080-\u00FF]*$/u,k=r=>r.replace(Se,"").replace(X,""),L=r=>r.replace(X,""),z=r=>Ce.includes(r),m=r=>Re.test(r),A=r=>xe.test(r),u=r=>{let e="";for(let[t,s=t.charCodeAt(0)]of r)e+=s>=65&&s<=90?String.fromCharCode(s+32):t;return e},B=(r,e)=>{let t="";for(let s=r.length,n;++e<s;)if(n=r[e],n=="\\")t+=++e<s?r[e]:n;else{if(n=='"')break;t+=n}return[t,e]};var y=class{#e;constructor(e){this.#e=new Map(e)}get size(){return this.#e.size}get(e){return this.#e.get(u(String(e)))}has(e){return this.#e.has(u(String(e)))}set(e,t){if(e=u(String(e)),t=String(t),!m(e))throw new Error(`Invalid media type parameter name "${e}": only HTTP token code points are valid.`);if(!A(t))throw new Error(`Invalid media type parameter value "${t}": only HTTP quoted-string token code points are valid.`);return this.#e.set(e,t),this}clear(){this.#e.clear()}delete(e){return e=u(String(e)),this.#e.delete(e)}forEach(e,t){this.#e.forEach(e,t)}keys(){return this.#e.keys()}values(){return this.#e.values()}entries(){return this.#e.entries()}[Symbol.iterator](){return this.#e[Symbol.iterator]()}[Symbol.toStringTag](){return"MediaTypeParameters"}};var _e=r=>{r=k(r);let e=0,t="";for(;e<r.length&&r[e]!="/";)t+=r[e],++e;if(t.length===0||!m(t)||e>=r.length)return null;++e;let s="";for(;e<r.length&&r[e]!=";";)s+=r[e],++e;if(s=L(s),s.length===0||!m(s))return null;let n={type:u(t),subtype:u(s),parameters:new Map};for(;e<r.length;){for(++e;z(r[e]);)++e;let o="";for(;e<r.length&&r[e]!=";"&&r[e]!="=";)o+=r[e],++e;if(o=u(o),e<r.length){if(r[e]==";")continue;++e}let i=null;if(r[e]=='"')for([i,e]=B(r,e);e<r.length&&r[e]!=";";)++e;else{for(i="";e<r.length&&r[e]!=";";)i+=r[e],++e;if(i=L(i),i==="")continue}o.length>0&&m(o)&&A(i)&&!n.parameters.has(o)&&n.parameters.set(o,i)}return n},M=_e;var Pe=r=>{let e=`${r.type}/${r.subtype}`;if(r.parameters.size===0)return e;for(let[t,s]of r.parameters)e+=`;${t}=`,(!m(s)||s.length===0)&&(s=`"${s.replace(/(["\\])/ug,"\\$1")}"`),e+=s;return e},j=Pe;var p=class r{#e;#t;#s;constructor(e,t={}){let{type:s,subtype:n,parameters:o}=M(e);this.#e=s,this.#t=n,this.#s=new y([...o,...Object.entries(t).map(([i,E])=>[u(i),u(E)])])}static parse(e){try{return new r(e)}catch{throw new Error(`Could not parse media type string '${e}'`)}}get essence(){return`${this.#e}/${this.#t}`}get type(){return this.#e}set type(e){if(e=u(String(e)),e.length===0)throw new Error("Invalid type: must be a non-empty string");if(!m(e))throw new Error(`Invalid type ${e}: must contain only HTTP token code points`);this.#e=e}get subtype(){return this.#t}set subtype(e){if(e=u(String(e)),e.length===0)throw new Error("Invalid subtype: must be a non-empty string");if(!m(e))throw new Error(`Invalid subtype ${e}: must contain only HTTP token code points`);this.#t=e}get parameters(){return this.#s}toString(){return j(this)}isJavaScript({prohibitParameters:e=!1}={}){switch(this.#e){case"text":switch(this.#t){case"ecmascript":case"javascript":case"javascript1.0":case"javascript1.1":case"javascript1.2":case"javascript1.3":case"javascript1.4":case"javascript1.5":case"jscript":case"livescript":case"x-ecmascript":case"x-javascript":return!e||this.#s.size===0;default:return!1}case"application":switch(this.#t){case"ecmascript":case"javascript":case"x-ecmascript":case"x-javascript":return!e||this.#s.size===0;default:return!1}default:return!1}}isXML(){return this.#t==="xml"&&(this.#e==="text"||this.#e==="application")||this.#t.endsWith("+xml")}isHTML(){return this.#t==="html"&&this.#e==="text"}get[Symbol.toStringTag](){return"MediaType"}};var _=class extends Map{set(e,t){return super.set(e,(super.get(e)??new Set).add(t)),this}[Symbol.toStringTag](){return"SetMultiMap"}};var P=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}handle(e,t){this.#t.call(this.#e,e,t)}get[Symbol.toStringTag](){return"ContextEventHandler"}};var b=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get eventName(){return this.#e}get contextEventHandler(){return this.#t}get[Symbol.toStringTag](){return"Subscription"}};var O=class{#e;constructor(){this.#e=new _}subscribe(e,t,s=t){let n=new P(s,t);return this.#e.set(e,n),new b(e,n)}unsubscribe({eventName:e,contextEventHandler:t}){let s=this.#e.get(e),n=s?.delete(t);return n&&s.size==0&&this.#e.delete(e),n}publish(e,t=new CustomEvent(e),s){s==null&&!(t instanceof Event)&&([s,t]=[t,new CustomEvent(e)]),this.#e.get(e)?.forEach(n=>n.handle(t,s))}isSubscribed({eventName:e,contextEventHandler:t}){return this.#e.get(e)?.has(t)}get[Symbol.toStringTag](){return"Subscribr"}};var C=class extends Error{#e;#t;constructor(e,{cause:t,status:s,entity:n}){super(e,{cause:t}),this.#e=n,this.#t=s}get entity(){return this.#e}get statusCode(){return this.#t?.code}get statusText(){return this.#t?.text}get name(){return"HttpError"}get[Symbol.toStringTag](){return"HttpError"}};var be={AAC:"audio/aac",ABW:"application/x-abiword",ARC:"application/x-freearc",AVIF:"image/avif",AVI:"video/x-msvideo",AZW:"application/vnd.amazon.ebook",BIN:"application/octet-stream",BMP:"image/bmp",BZIP:"application/x-bzip",BZIP2:"application/x-bzip2",CDA:"application/x-cdf",CSH:"application/x-csh",CSS:"text/css",CSV:"text/csv",DOC:"application/msword",DOCX:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",EOT:"application/vnd.ms-fontobject",EPUB:"application/epub+zip",GZIP:"application/gzip",GIF:"image/gif",HTML:"text/html",ICO:"image/vnd.microsoft.icon",ICS:"text/calendar",JAR:"application/java-archive",JPEG:"image/jpeg",JAVA_SCRIPT:"text/javascript",JSON:"application/json",JSON_LD:"application/ld+json",MID:"audio/midi",X_MID:"audio/x-midi",MP3:"audio/mpeg",MP4A:"audio/mp4",MP4:"video/mp4",MPEG:"video/mpeg",MPKG:"application/vnd.apple.installer+xml",ODP:"application/vnd.oasis.opendocument.presentation",ODS:"application/vnd.oasis.opendocument.spreadsheet",ODT:"application/vnd.oasis.opendocument.text",OGA:"audio/ogg",OGV:"video/ogg",OGX:"application/ogg",OPUS:"audio/opus",OTF:"font/otf",PNG:"image/png",PDF:"application/pdf",PHP:"application/x-httpd-php",PPT:"application/vnd.ms-powerpoint",PPTX:"application/vnd.openxmlformats-officedocument.presentationml.presentation",RAR:"application/vnd.rar",RTF:"application/rtf",SH:"application/x-sh",SVG:"image/svg+xml",TAR:"application/x-tar",TIFF:"image/tiff",TRANSPORT_STREAM:"video/mp2t",TTF:"font/ttf",TEXT:"text/plain",VSD:"application/vnd.visio",WAV:"audio/wav",WEBA:"audio/webm",WEBM:"video/webm",WEBP:"image/webp",WOFF:"font/woff",WOFF2:"font/woff2",FORM:"application/x-www-form-urlencoded",MULTIPART_FORM_DATA:"multipart/form-data",XHTML:"application/xhtml+xml",XLS:"application/vnd.ms-excel",XLSX:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",XML:"application/xml",XUL:"application/vnd.mozilla.xul+xml",ZIP:"application/zip","3GP":"video/3gpp","3G2":"video/3gpp2","7Z":"application/x-7z-compressed"},a=be;var Ie={ACCEPT:"accept",ACCEPT_CHARSET:"accept-charset",ACCEPT_ENCODING:"accept-encoding",ACCEPT_LANGUAGE:"accept-language",AUTHORIZATION:"authorization",CACHE_CONTROL:"cache-control",CONNECTION:"connection",COOKIE:"cookie",CONTENT_LENGTH:"content-length",CONTENT_MD5:"content-md5",CONTENT_TYPE:"content-type",DATE:"date",EXPECT:"expect",FROM:"from",HOST:"host",IF_MATCH:"if-match",IF_MODIFIED_SINCE:"if-modified-since",IF_NONE_MATCH:"if-none-match",IF_RANGE:"if-range",IF_UNMODIFIED_SINCE:"if-unmodified-since",MAX_FORWARDS:"max-forwards",ORIGIN:"origin",PRAGMA:"pragma",PROXY_AUTHORIZATION:"proxy-authorization",RANGE:"range",REFERER:"referer",TE:"te",USER_AGENT:"user-agent",UPGRADE:"upgrade",VIA:"via",WARNING:"warning",X_REQUESTED_WITH:"x-requested-with",DNT:"dnt",X_FORWARDED_FOR:"x-forwarded-for",X_FORWARDED_HOST:"x-forwarded-host",X_FORWARDED_PROTO:"x-forwarded-proto",FRONT_END_HTTPS:"front-end-https",X_HTTP_METHOD_OVERRIDE:"x-http-method-override",X_ATT_DEVICE_ID:"x-att-deviceid",X_WAP_PROFILE:"x-wap-profile"},c=Ie;var Ae={OPTIONS:"OPTIONS",GET:"GET",HEAD:"HEAD",POST:"POST",PUT:"PUT",DELETE:"DELETE",TRACE:"TRACE",CONNECT:"CONNECT",PATCH:"PATCH"},f=Ae;var Ne={PROXY_CONNECTION:"proxy-connection",X_UIDH:"x-uidh",X_CSRF_TOKEN:"x-csrf-token",ACCESS_CONTROL_ALLOW_ORIGIN:"access-control-allow-origin",ACCEPT_PATCH:"accept-patch",ACCEPT_RANGES:"accept-ranges",AGE:"age",ALLOW:"allow",CACHE_CONTROL:"cache-control",CONNECTION:"connection",CONTENT_DISPOSITION:"content-disposition",CONTENT_ENCODING:"content-encoding",CONTENT_LANGUAGE:"content-language",CONTENT_LENGTH:"content-length",CONTENT_LOCATION:"content-location",CONTENT_RANGE:"content-range",CONTENT_TYPE:"content-type",DATE:"date",ETAG:"etag",EXPIRES:"expires",LAST_MODIFIED:"last-modified",LINK:"link",LOCATION:"location",P3P:"p3p",PRAGMA:"pragma",PROXY_AUTHENTICATION:"proxy-authenticate",PUBLIC_KEY_PINS:"public-key-pins",RETRY_AFTER:"retry-after",SERVER:"server",SET_COOKIE:"set-cookie",STATUS:"status",STRICT_TRANSPORT_SECURITY:"strict-transport-security",TRAILER:"trailer",TRANSFER_ENCODING:"transfer-encoding",UPGRADE:"upgrade",VARY:"vary",VIA:"via",WARNING:"warning",WWW_AUTHENTICATE:"www-authenticate",X_XSS_PROTECTION:"x-xss-protection",CONTENT_SECURITY_POLICY:"content-security-policy",X_CONTENT_TYPE_OPTIONS:"x-content-type-options",X_POWERED_BY:"x-powered-by"},D=Ne;var g=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get code(){return this.#e}get text(){return this.#t}get[Symbol.toStringTag](){return"ResponseStatus"}toString(){return`${this.#e} ${this.#t}`}};var S=class{#e;constructor(e){this.#e=new AbortController,e?.addEventListener("abort",()=>this.#e.abort())}get signal(){return this.#e.signal}abort(e){this.#e.abort(e)}get[Symbol.toStringTag](){return"SignalController"}};var we=/\/$/,R="utf-8",l=new Map([[a.PNG,new p(a.PNG)],[a.TEXT,new p(a.TEXT,{charset:R})],[a.JSON,new p(a.JSON,{charset:R})],[a.HTML,new p(a.HTML,{charset:R})],[a.JAVA_SCRIPT,new p(a.JAVA_SCRIPT,{charset:R})],[a.CSS,new p(a.CSS,{charset:R})],[a.XML,new p(a.XML,{charset:R})],[a.BIN,new p(a.BIN)]]),$=async r=>await r.text(),V=async r=>{let e=URL.createObjectURL(await r.blob());return document.head.removeChild(document.head.appendChild(Object.assign(document.createElement("script"),{src:e,type:a.JAVA_SCRIPT,async:!0}))),URL.revokeObjectURL(e),Promise.resolve()},J=async r=>{let e=URL.createObjectURL(await r.blob());return document.head.appendChild(Object.assign(document.createElement("link"),{href:e,type:a.CSS,rel:"stylesheet"})),URL.revokeObjectURL(e),Promise.resolve()},Y=async r=>await r.json(),ve=async r=>await r.blob(),q=async r=>URL.createObjectURL(await r.blob()),He=async r=>await r.arrayBuffer(),Z=async r=>r.body,Q=async r=>new DOMParser().parseFromString(await r.text(),a.XML),K=async r=>new DOMParser().parseFromString(await r.text(),a.HTML),Le=async r=>document.createRange().createContextualFragment(await r.text()),ee=r=>Object.fromEntries(Array.from(r.keys()).map((e,t,s,n=r.getAll(e))=>[e,n.length>1?n:n[0]])),N=class r{#e;#t;#s;static#i=new O;static#a=[];static#f=new W([[q,l.get(a.PNG).type],[$,l.get(a.TEXT).type],[Y,l.get(a.JSON).subtype],[K,l.get(a.HTML).subtype],[V,l.get(a.JAVA_SCRIPT).subtype],[J,l.get(a.CSS).subtype],[Q,l.get(a.XML).subtype],[Z,l.get(a.BIN).subtype]]);static#m=new Set([[{property:"body",type:FormData,converter:ee}],[{property:"searchParams",type:URLSearchParams,converter:ee}],[{property:"headers",type:Headers,converter:Object.fromEntries}]]);constructor(e=location.origin,t={}){let s=h(e);s==Object?(t=e,e=location.origin):s!=URL&&(e=e.startsWith("/")?new URL(e,location.origin):new URL(e)),this.#e=e,this.#t=x(r.#h,r.#u(t)),this.#s=new O}static signalController(e){return new S(e)}static register(e,t,s){return r.#i.subscribe(e,t,s)}static unregister(e){return r.#i.unsubscribe(e)}static abortAll(){for(let e of this.#a)e.abort();this.#a=[]}static Method=Object.freeze(f);static MediaType=Object.freeze(a);static RequestHeader=Object.freeze(c);static ResponseHeader=Object.freeze(D);static CachingPolicy=Object.freeze({DEFAULT:"default",FORCE_CACHE:"force-cache",NO_CACHE:"no-cache",NO_STORE:"no-store",ONLY_IF_CACHED:"only-if-cached",RELOAD:"reload"});static CredentialsPolicy=Object.freeze({INCLUDE:"include",OMIT:"omit",SAME_ORIGIN:"same-origin"});static RequestMode=Object.freeze({CORS:"cors",NAVIGATE:"navigate",NO_CORS:"no-cors",SAME_ORIGIN:"same-origin"});static RedirectPolicy=Object.freeze({ERROR:"error",FOLLOW:"follow",MANUAL:"manual"});static ReferrerPolicy=Object.freeze({NO_REFERRER:"no-referrer",NO_REFERRER_WHEN_DOWNGRADE:"no-referrer-when-downgrade",ORIGIN:"origin",ORIGIN_WHEN_CROSS_ORIGIN:"origin-when-cross-origin",SAME_ORIGIN:"same-origin",STRICT_ORIGIN:"strict-origin",STRICT_ORIGIN_WHEN_CROSS_ORIGIN:"strict-origin-when-cross-origin",UNSAFE_URL:"unsafe-url"});static Events=Object.freeze({CONFIGURED:"configured",SUCCESS:"success",ERROR:"error",ABORTED:"aborted",TIMEOUT:"timeout",COMPLETE:"complete",ALL_COMPLETE:"all-complete"});static#h=Object.freeze({body:null,cache:r.CachingPolicy.NO_STORE,credentials:r.CredentialsPolicy.SAME_ORIGIN,headers:{[c.CONTENT_TYPE]:l.get(a.JSON).toString(),[c.ACCEPT]:l.get(a.JSON).toString()},searchParams:{},integrity:void 0,keepalive:void 0,method:f.GET,mode:r.RequestMode.CORS,redirect:r.RedirectPolicy.FOLLOW,referrer:"about:client",referrerPolicy:r.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,signal:void 0,timeout:3e4,global:!0,window:null});static#l=new Map([[r.Events.ABORTED,new g(499,"Aborted")],[r.Events.TIMEOUT,new g(504,"Gateway Timeout")]]);get baseUrl(){return this.#e}register(e,t,s){return this.#s.subscribe(e,t,s)}unregister(e){this.#s.unsubscribe(e)}async get(e,t){return this.#r(e,t)}async post(e,t,s){return this.#o(e,{...s,body:t},{method:f.POST})}async put(e,t){return this.#o(e,t,{method:f.PUT})}async patch(e,t){return this.#o(e,t,{method:f.PATCH})}async delete(e,t){return this.#o(e,t,{method:f.DELETE})}async head(e,t){return this.#o(e,t,{method:f.HEAD})}async options(e,t){return this.#o(e,t,{method:f.OPTIONS})}async request(e,t){return this.#o(e,t)}async getJson(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.JSON).toString()}},Y)}async getXml(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.XML).toString()}},Q)}async getHtml(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.HTML).toString()}},K)}async getHtmlFragment(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.HTML).toString()}},Le)}async getScript(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.JAVA_SCRIPT).toString()}},V)}async getStylesheet(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.CSS).toString()}},J)}async getBlob(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:a.BIN}},ve)}async getImage(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:"image/*"}},q)}async getBuffer(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:a.BIN}},He)}async getStream(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:a.BIN}},Z)}async#r(e,t,s,n){return this.#o(e,t,s,n)}async#o(e,t={},s={},n){let o=x(this.#t,r.#u(t),s),i=r.#T(this.#e,e,o.searchParams),E=new S(o.signal);if(r.#a.push(E),o.signal=E.signal,r.#g(o.method,o.headers[c.CONTENT_TYPE]))try{o.body=JSON.stringify(o.body)}catch(d){return Promise.reject(new C(i,{cause:d}))}else o.method==f.GET&&o.headers[c.CONTENT_TYPE]!=""&&(delete o.headers[c.CONTENT_TYPE],delete o.body);o.signal.addEventListener("abort",d=>this.#n(r.Events.ABORTED,o.global,d)),o.signal.addEventListener("timeout",d=>this.#n(r.Events.TIMEOUT,o.global,d)),this.#n(r.Events.CONFIGURED,o.global,o);let w,G,T;try{if(G=setTimeout(()=>{let d=new DOMException(`The call to '${i}' timed-out after ${o.timeout/1e3} seconds`,"TimeoutError");E.abort(d),o.signal.dispatchEvent(new CustomEvent(r.Events.TIMEOUT,{detail:{url:i,options:o,cause:d}}))},o.timeout),T=await fetch(i,o),!T.ok)return Promise.reject(this.#c(i,{status:r.#p("ResponseError",T),entity:await this.#d(T,i)}));w=await this.#d(T,i,n),this.#n(r.Events.SUCCESS,o.global,w)}catch(d){return Promise.reject(this.#c(i,{cause:d,status:r.#p(d.name,T)}))}finally{if(clearTimeout(G),!o.signal.aborted){this.#n(r.Events.COMPLETE,o.global,T);let d=r.#a.indexOf(E);d>-1&&r.#a.splice(d,1),r.#a.length===0&&this.#n(r.Events.ALL_COMPLETE,o.global,T)}}return w}#c(e,t){let s=new C(`An error has occurred with your request to: '${e}'`,t);return this.#n(r.Events.ERROR,!0,s),s}#n(e,t,s,n){t&&r.#i.publish(e,s,n),this.#s.publish(e,s,n)}static#p(e,t){switch(e){case"AbortError":return r.#l.get(r.Events.ABORTED);case"TimeoutError":return r.#l.get(r.Events.TIMEOUT);default:return t?new g(t.status,t.statusText):new g(500,"Internal Server Error")}}async#d(e,t,s){try{let n;if(!s&&(n=p.parse(e.headers.get(D.CONTENT_TYPE)),n)){for(let[o,i]of r.#f)if(i.has(n.type)||i.has(n.subtype)){s=o;break}}return(s??$)(e)}catch(n){return console.error("Unable to process response.",n,e),Promise.reject(this.#c(t,{cause:n}))}}static#T(e,t,s={}){return t&&(e=t.startsWith("/")?new URL(`${e.pathname.replace(we,"")}${t}`,e.origin):new URL(t)),Object.entries(s).forEach(([n,o])=>e.searchParams.append(n,o)),e}static#g(e,t){return(l.get(t)??new p(t)).essence==a.JSON&&[f.POST,f.PUT,f.PATCH].includes(e)}static#u(e){if(!I(e))for(let[{property:t,type:s,converter:n},o=e[t]]of r.#m)o instanceof s&&(e[t]=n(o));return e}get[Symbol.toStringTag](){return"Transportr"}};return ae(Me);})();
|
|
1
|
+
var Transportr=(()=>{var v=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var oe=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},ne=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of re(e))!se.call(r,o)&&o!==t&&v(r,o,{get:()=>e[o],enumerable:!(s=te(e,o))||s.enumerable});return r};var ae=r=>ne(v({},"__esModule",{value:!0}),r);var Me={};oe(Me,{default:()=>N});var de=r=>r?.constructor??r?.prototype?.constructor??globalThis[Object.prototype.toString.call(r).slice(8,-1)]??r,h=de;var me=r=>!!r&&Object.keys(r).length===0&&r.constructor===Object,I=me;var F=(...r)=>{let e={};for(let t of r){if(h(t)!=Object)return;let s,o;for(let n of Object.getOwnPropertyNames(t))s=Object.getOwnPropertyDescriptor(t,n),s.enumerable&&(o=h(t[n]),o==Object?s.value=h(e[n])==Object?F(e[n],t[n]):{...t[n]}:o==Array&&(s.value=Array.isArray(e[n])?[...new Set([...t[n],...e[n]])]:[...t[n]]),e[n]=s.value)}return e},x=F;var L=class extends Map{set(e,t){return super.set(e,(super.get(e)??new Set).add(t)),this}hasValue(e,t){let s=super.get(e);return s?s.has(t):!1}deleteValue(e,t){let s=super.get(e);return s?s.delete(t):!1}get[Symbol.toStringTag](){return"SetMultiMap"}},W=L;var Ce=[" "," ",`
|
|
2
|
+
`,"\r"],Se=/^[ \t\n\r]+/u,X=/[ \t\n\r]+$/u,Re=/^[-!#$%&'*+.^_`|~A-Za-z0-9]*$/u,xe=/^[\t\u0020-\u007E\u0080-\u00FF]*$/u,k=r=>r.replace(Se,"").replace(X,""),H=r=>r.replace(X,""),z=r=>Ce.includes(r),m=r=>Re.test(r),A=r=>xe.test(r),u=r=>{let e="";for(let[t,s=t.charCodeAt(0)]of r)e+=s>=65&&s<=90?String.fromCharCode(s+32):t;return e},B=(r,e)=>{let t="";for(let s=r.length,o;++e<s;)if(o=r[e],o=="\\")t+=++e<s?r[e]:o;else{if(o=='"')break;t+=o}return[t,e]};var y=class{#e;constructor(e){this.#e=new Map(e)}get size(){return this.#e.size}get(e){return this.#e.get(u(String(e)))}has(e){return this.#e.has(u(String(e)))}set(e,t){if(e=u(String(e)),t=String(t),!m(e))throw new Error(`Invalid media type parameter name "${e}": only HTTP token code points are valid.`);if(!A(t))throw new Error(`Invalid media type parameter value "${t}": only HTTP quoted-string token code points are valid.`);return this.#e.set(e,t),this}clear(){this.#e.clear()}delete(e){return e=u(String(e)),this.#e.delete(e)}forEach(e,t){this.#e.forEach(e,t)}keys(){return this.#e.keys()}values(){return this.#e.values()}entries(){return this.#e.entries()}[Symbol.iterator](){return this.#e[Symbol.iterator]()}[Symbol.toStringTag](){return"MediaTypeParameters"}};var _e=r=>{r=k(r);let e=0,t="";for(;e<r.length&&r[e]!="/";)t+=r[e],++e;if(t.length===0||!m(t)||e>=r.length)return null;++e;let s="";for(;e<r.length&&r[e]!=";";)s+=r[e],++e;if(s=H(s),s.length===0||!m(s))return null;let o={type:u(t),subtype:u(s),parameters:new Map};for(;e<r.length;){for(++e;z(r[e]);)++e;let n="";for(;e<r.length&&r[e]!=";"&&r[e]!="=";)n+=r[e],++e;if(n=u(n),e<r.length){if(r[e]==";")continue;++e}let i=null;if(r[e]=='"')for([i,e]=B(r,e);e<r.length&&r[e]!=";";)++e;else{for(i="";e<r.length&&r[e]!=";";)i+=r[e],++e;if(i=H(i),i==="")continue}n.length>0&&m(n)&&A(i)&&!o.parameters.has(n)&&o.parameters.set(n,i)}return o},M=_e;var Pe=r=>{let e=`${r.type}/${r.subtype}`;if(r.parameters.size===0)return e;for(let[t,s]of r.parameters)e+=`;${t}=`,(!m(s)||s.length===0)&&(s=`"${s.replace(/(["\\])/ug,"\\$1")}"`),e+=s;return e},j=Pe;var p=class r{#e;#t;#s;constructor(e,t={}){let{type:s,subtype:o,parameters:n}=M(e);this.#e=s,this.#t=o,this.#s=new y([...n,...Object.entries(t).map(([i,E])=>[u(i),u(E)])])}static parse(e){try{return new r(e)}catch{throw new Error(`Could not parse media type string '${e}'`)}}get essence(){return`${this.#e}/${this.#t}`}get type(){return this.#e}set type(e){if(e=u(String(e)),e.length===0)throw new Error("Invalid type: must be a non-empty string");if(!m(e))throw new Error(`Invalid type ${e}: must contain only HTTP token code points`);this.#e=e}get subtype(){return this.#t}set subtype(e){if(e=u(String(e)),e.length===0)throw new Error("Invalid subtype: must be a non-empty string");if(!m(e))throw new Error(`Invalid subtype ${e}: must contain only HTTP token code points`);this.#t=e}get parameters(){return this.#s}toString(){return j(this)}isJavaScript({prohibitParameters:e=!1}={}){switch(this.#e){case"text":switch(this.#t){case"ecmascript":case"javascript":case"javascript1.0":case"javascript1.1":case"javascript1.2":case"javascript1.3":case"javascript1.4":case"javascript1.5":case"jscript":case"livescript":case"x-ecmascript":case"x-javascript":return!e||this.#s.size===0;default:return!1}case"application":switch(this.#t){case"ecmascript":case"javascript":case"x-ecmascript":case"x-javascript":return!e||this.#s.size===0;default:return!1}default:return!1}}isXML(){return this.#t==="xml"&&(this.#e==="text"||this.#e==="application")||this.#t.endsWith("+xml")}isHTML(){return this.#t==="html"&&this.#e==="text"}get[Symbol.toStringTag](){return"MediaType"}};var _=class extends Map{set(e,t){return super.set(e,(super.get(e)??new Set).add(t)),this}[Symbol.toStringTag](){return"SetMultiMap"}};var P=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}handle(e,t){this.#t.call(this.#e,e,t)}get[Symbol.toStringTag](){return"ContextEventHandler"}};var b=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get eventName(){return this.#e}get contextEventHandler(){return this.#t}get[Symbol.toStringTag](){return"Subscription"}};var O=class{#e;constructor(){this.#e=new _}subscribe(e,t,s=t){let o=new P(s,t);return this.#e.set(e,o),new b(e,o)}unsubscribe({eventName:e,contextEventHandler:t}){let s=this.#e.get(e),o=s?.delete(t);return o&&s.size==0&&this.#e.delete(e),o}publish(e,t=new CustomEvent(e),s){s==null&&!(t instanceof Event)&&([s,t]=[t,new CustomEvent(e)]),this.#e.get(e)?.forEach(o=>o.handle(t,s))}isSubscribed({eventName:e,contextEventHandler:t}){return this.#e.get(e)?.has(t)}get[Symbol.toStringTag](){return"Subscribr"}};var C=class extends Error{#e;#t;constructor(e,{cause:t,status:s,entity:o}){super(e,{cause:t}),this.#e=o,this.#t=s}get entity(){return this.#e}get statusCode(){return this.#t?.code}get statusText(){return this.#t?.text}get name(){return"HttpError"}get[Symbol.toStringTag](){return"HttpError"}};var be={AAC:"audio/aac",ABW:"application/x-abiword",ARC:"application/x-freearc",AVIF:"image/avif",AVI:"video/x-msvideo",AZW:"application/vnd.amazon.ebook",BIN:"application/octet-stream",BMP:"image/bmp",BZIP:"application/x-bzip",BZIP2:"application/x-bzip2",CDA:"application/x-cdf",CSH:"application/x-csh",CSS:"text/css",CSV:"text/csv",DOC:"application/msword",DOCX:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",EOT:"application/vnd.ms-fontobject",EPUB:"application/epub+zip",GZIP:"application/gzip",GIF:"image/gif",HTML:"text/html",ICO:"image/vnd.microsoft.icon",ICS:"text/calendar",JAR:"application/java-archive",JPEG:"image/jpeg",JAVA_SCRIPT:"text/javascript",JSON:"application/json",JSON_LD:"application/ld+json",MID:"audio/midi",X_MID:"audio/x-midi",MP3:"audio/mpeg",MP4A:"audio/mp4",MP4:"video/mp4",MPEG:"video/mpeg",MPKG:"application/vnd.apple.installer+xml",ODP:"application/vnd.oasis.opendocument.presentation",ODS:"application/vnd.oasis.opendocument.spreadsheet",ODT:"application/vnd.oasis.opendocument.text",OGA:"audio/ogg",OGV:"video/ogg",OGX:"application/ogg",OPUS:"audio/opus",OTF:"font/otf",PNG:"image/png",PDF:"application/pdf",PHP:"application/x-httpd-php",PPT:"application/vnd.ms-powerpoint",PPTX:"application/vnd.openxmlformats-officedocument.presentationml.presentation",RAR:"application/vnd.rar",RTF:"application/rtf",SH:"application/x-sh",SVG:"image/svg+xml",TAR:"application/x-tar",TIFF:"image/tiff",TRANSPORT_STREAM:"video/mp2t",TTF:"font/ttf",TEXT:"text/plain",VSD:"application/vnd.visio",WAV:"audio/wav",WEBA:"audio/webm",WEBM:"video/webm",WEBP:"image/webp",WOFF:"font/woff",WOFF2:"font/woff2",FORM:"application/x-www-form-urlencoded",MULTIPART_FORM_DATA:"multipart/form-data",XHTML:"application/xhtml+xml",XLS:"application/vnd.ms-excel",XLSX:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",XML:"application/xml",XUL:"application/vnd.mozilla.xul+xml",ZIP:"application/zip","3GP":"video/3gpp","3G2":"video/3gpp2","7Z":"application/x-7z-compressed"},a=be;var Ie={ACCEPT:"accept",ACCEPT_CHARSET:"accept-charset",ACCEPT_ENCODING:"accept-encoding",ACCEPT_LANGUAGE:"accept-language",AUTHORIZATION:"authorization",CACHE_CONTROL:"cache-control",CONNECTION:"connection",COOKIE:"cookie",CONTENT_LENGTH:"content-length",CONTENT_MD5:"content-md5",CONTENT_TYPE:"content-type",DATE:"date",EXPECT:"expect",FROM:"from",HOST:"host",IF_MATCH:"if-match",IF_MODIFIED_SINCE:"if-modified-since",IF_NONE_MATCH:"if-none-match",IF_RANGE:"if-range",IF_UNMODIFIED_SINCE:"if-unmodified-since",MAX_FORWARDS:"max-forwards",ORIGIN:"origin",PRAGMA:"pragma",PROXY_AUTHORIZATION:"proxy-authorization",RANGE:"range",REFERER:"referer",TE:"te",USER_AGENT:"user-agent",UPGRADE:"upgrade",VIA:"via",WARNING:"warning",X_REQUESTED_WITH:"x-requested-with",DNT:"dnt",X_FORWARDED_FOR:"x-forwarded-for",X_FORWARDED_HOST:"x-forwarded-host",X_FORWARDED_PROTO:"x-forwarded-proto",FRONT_END_HTTPS:"front-end-https",X_HTTP_METHOD_OVERRIDE:"x-http-method-override",X_ATT_DEVICE_ID:"x-att-deviceid",X_WAP_PROFILE:"x-wap-profile"},c=Ie;var Ae={OPTIONS:"OPTIONS",GET:"GET",HEAD:"HEAD",POST:"POST",PUT:"PUT",DELETE:"DELETE",TRACE:"TRACE",CONNECT:"CONNECT",PATCH:"PATCH"},f=Ae;var Ne={PROXY_CONNECTION:"proxy-connection",X_UIDH:"x-uidh",X_CSRF_TOKEN:"x-csrf-token",ACCESS_CONTROL_ALLOW_ORIGIN:"access-control-allow-origin",ACCEPT_PATCH:"accept-patch",ACCEPT_RANGES:"accept-ranges",AGE:"age",ALLOW:"allow",CACHE_CONTROL:"cache-control",CONNECTION:"connection",CONTENT_DISPOSITION:"content-disposition",CONTENT_ENCODING:"content-encoding",CONTENT_LANGUAGE:"content-language",CONTENT_LENGTH:"content-length",CONTENT_LOCATION:"content-location",CONTENT_RANGE:"content-range",CONTENT_TYPE:"content-type",DATE:"date",ETAG:"etag",EXPIRES:"expires",LAST_MODIFIED:"last-modified",LINK:"link",LOCATION:"location",P3P:"p3p",PRAGMA:"pragma",PROXY_AUTHENTICATION:"proxy-authenticate",PUBLIC_KEY_PINS:"public-key-pins",RETRY_AFTER:"retry-after",SERVER:"server",SET_COOKIE:"set-cookie",STATUS:"status",STRICT_TRANSPORT_SECURITY:"strict-transport-security",TRAILER:"trailer",TRANSFER_ENCODING:"transfer-encoding",UPGRADE:"upgrade",VARY:"vary",VIA:"via",WARNING:"warning",WWW_AUTHENTICATE:"www-authenticate",X_XSS_PROTECTION:"x-xss-protection",CONTENT_SECURITY_POLICY:"content-security-policy",X_CONTENT_TYPE_OPTIONS:"x-content-type-options",X_POWERED_BY:"x-powered-by"},D=Ne;var g=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get code(){return this.#e}get text(){return this.#t}get[Symbol.toStringTag](){return"ResponseStatus"}toString(){return`${this.#e} ${this.#t}`}};var S=class{#e;constructor(e){this.#e=new AbortController,e?.addEventListener("abort",()=>this.#e.abort())}get signal(){return this.#e.signal}abort(e){this.#e.abort(e)}get[Symbol.toStringTag](){return"SignalController"}};var we=/\/$/,R="utf-8",l=new Map([[a.PNG,new p(a.PNG)],[a.TEXT,new p(a.TEXT,{charset:R})],[a.JSON,new p(a.JSON,{charset:R})],[a.HTML,new p(a.HTML,{charset:R})],[a.JAVA_SCRIPT,new p(a.JAVA_SCRIPT,{charset:R})],[a.CSS,new p(a.CSS,{charset:R})],[a.XML,new p(a.XML,{charset:R})],[a.BIN,new p(a.BIN)]]),$=async r=>await r.text(),V=async r=>{let e=URL.createObjectURL(await r.blob());return document.head.removeChild(document.head.appendChild(Object.assign(document.createElement("script"),{src:e,type:a.JAVA_SCRIPT,async:!0}))),URL.revokeObjectURL(e),Promise.resolve()},J=async r=>{let e=URL.createObjectURL(await r.blob());return document.head.appendChild(Object.assign(document.createElement("link"),{href:e,type:a.CSS,rel:"stylesheet"})),URL.revokeObjectURL(e),Promise.resolve()},Y=async r=>await r.json(),ve=async r=>await r.blob(),q=async r=>URL.createObjectURL(await r.blob()),Le=async r=>await r.arrayBuffer(),Z=async r=>r.body,Q=async r=>new DOMParser().parseFromString(await r.text(),a.XML),K=async r=>new DOMParser().parseFromString(await r.text(),a.HTML),He=async r=>document.createRange().createContextualFragment(await r.text()),ee=r=>Object.fromEntries(Array.from(r.keys()).map((e,t,s,o=r.getAll(e))=>[e,o.length>1?o:o[0]])),N=class r{#e;#t;#s;static#i=new O;static#a=[];static#f=new W([[q,l.get(a.PNG).type],[$,l.get(a.TEXT).type],[Y,l.get(a.JSON).subtype],[K,l.get(a.HTML).subtype],[V,l.get(a.JAVA_SCRIPT).subtype],[J,l.get(a.CSS).subtype],[Q,l.get(a.XML).subtype],[Z,l.get(a.BIN).subtype]]);static#m=new Set([[{property:"body",type:FormData,converter:ee}],[{property:"searchParams",type:URLSearchParams,converter:ee}],[{property:"headers",type:Headers,converter:Object.fromEntries}]]);constructor(e=location.origin,t={}){let s=h(e);s==Object?(t=e,e=location.origin):s!=URL&&(e=e.startsWith("/")?new URL(e,location.origin):new URL(e)),this.#e=e,this.#t=x(r.#h,r.#u(t)),this.#s=new O}static signalController(e){return new S(e)}static register(e,t,s){return r.#i.subscribe(e,t,s)}static unregister(e){return r.#i.unsubscribe(e)}static abortAll(){for(let e of this.#a)e.abort();this.#a=[]}static Method=Object.freeze(f);static MediaType=Object.freeze(a);static RequestHeader=Object.freeze(c);static ResponseHeader=Object.freeze(D);static CachingPolicy=Object.freeze({DEFAULT:"default",FORCE_CACHE:"force-cache",NO_CACHE:"no-cache",NO_STORE:"no-store",ONLY_IF_CACHED:"only-if-cached",RELOAD:"reload"});static CredentialsPolicy=Object.freeze({INCLUDE:"include",OMIT:"omit",SAME_ORIGIN:"same-origin"});static RequestMode=Object.freeze({CORS:"cors",NAVIGATE:"navigate",NO_CORS:"no-cors",SAME_ORIGIN:"same-origin"});static RedirectPolicy=Object.freeze({ERROR:"error",FOLLOW:"follow",MANUAL:"manual"});static ReferrerPolicy=Object.freeze({NO_REFERRER:"no-referrer",NO_REFERRER_WHEN_DOWNGRADE:"no-referrer-when-downgrade",ORIGIN:"origin",ORIGIN_WHEN_CROSS_ORIGIN:"origin-when-cross-origin",SAME_ORIGIN:"same-origin",STRICT_ORIGIN:"strict-origin",STRICT_ORIGIN_WHEN_CROSS_ORIGIN:"strict-origin-when-cross-origin",UNSAFE_URL:"unsafe-url"});static Events=Object.freeze({CONFIGURED:"configured",SUCCESS:"success",ERROR:"error",ABORTED:"aborted",TIMEOUT:"timeout",COMPLETE:"complete",ALL_COMPLETE:"all-complete"});static#h=Object.freeze({body:null,cache:r.CachingPolicy.NO_STORE,credentials:r.CredentialsPolicy.SAME_ORIGIN,headers:{[c.CONTENT_TYPE]:l.get(a.JSON).toString(),[c.ACCEPT]:l.get(a.JSON).toString()},searchParams:{},integrity:void 0,keepalive:void 0,method:f.GET,mode:r.RequestMode.CORS,redirect:r.RedirectPolicy.FOLLOW,referrer:"about:client",referrerPolicy:r.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN,signal:void 0,timeout:3e4,global:!0,window:null});static#l=new Map([[r.Events.ABORTED,new g(499,"Aborted")],[r.Events.TIMEOUT,new g(504,"Gateway Timeout")]]);get baseUrl(){return this.#e}register(e,t,s){return this.#s.subscribe(e,t,s)}unregister(e){this.#s.unsubscribe(e)}async get(e,t){return this.#r(e,t)}async post(e,t,s){return this.#o(e,{...s,body:t},{method:f.POST})}async put(e,t){return this.#o(e,t,{method:f.PUT})}async patch(e,t){return this.#o(e,t,{method:f.PATCH})}async delete(e,t){return this.#o(e,t,{method:f.DELETE})}async head(e,t){return this.#o(e,t,{method:f.HEAD})}async options(e,t){return this.#o(e,t,{method:f.OPTIONS})}async request(e,t){return this.#o(e,t)}async getJson(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.JSON).toString()}},Y)}async getXml(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.XML).toString()}},Q)}async getHtml(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.HTML).toString()}},K)}async getHtmlFragment(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.HTML).toString()}},He)}async getScript(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.JAVA_SCRIPT).toString()}},V)}async getStylesheet(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:l.get(a.CSS).toString()}},J)}async getBlob(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:a.BIN}},ve)}async getImage(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:"image/*"}},q)}async getBuffer(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:a.BIN}},Le)}async getStream(e,t){return this.#r(e,t,{headers:{[c.ACCEPT]:a.BIN}},Z)}async#r(e,t,s,o){return delete t?.method,this.#o(e,t,s,o)}async#o(e,t={},s={},o){h(e)==Object&&(t=e,e=void 0);let n=x(this.#t,r.#u(t),s),i=r.#T(this.#e,e,n.searchParams),E=new S(n.signal);if(r.#a.push(E),n.signal=E.signal,r.#g(n.method,n.headers[c.CONTENT_TYPE]))try{n.body=JSON.stringify(n.body)}catch(d){return Promise.reject(new C(i,{cause:d}))}else n.method==f.GET&&n.headers[c.CONTENT_TYPE]!=""&&(delete n.headers[c.CONTENT_TYPE],delete n.body);n.signal.addEventListener("abort",d=>this.#n(r.Events.ABORTED,n.global,d)),n.signal.addEventListener("timeout",d=>this.#n(r.Events.TIMEOUT,n.global,d)),this.#n(r.Events.CONFIGURED,n.global,n);let w,U,T;try{if(U=setTimeout(()=>{let d=new DOMException(`The call to '${i}' timed-out after ${n.timeout/1e3} seconds`,"TimeoutError");E.abort(d),n.signal.dispatchEvent(new CustomEvent(r.Events.TIMEOUT,{detail:{url:i,options:n,cause:d}}))},n.timeout),T=await fetch(i,n),!T.ok)return Promise.reject(this.#c(i,{status:r.#p("ResponseError",T),entity:await this.#d(T,i)}));w=await this.#d(T,i,o),this.#n(r.Events.SUCCESS,n.global,w)}catch(d){return Promise.reject(this.#c(i,{cause:d,status:r.#p(d.name,T)}))}finally{if(clearTimeout(U),!n.signal.aborted){this.#n(r.Events.COMPLETE,n.global,T);let d=r.#a.indexOf(E);d>-1&&r.#a.splice(d,1),r.#a.length===0&&this.#n(r.Events.ALL_COMPLETE,n.global,T)}}return w}#c(e,t){let s=new C(`An error has occurred with your request to: '${e}'`,t);return this.#n(r.Events.ERROR,!0,s),s}#n(e,t,s,o){t&&r.#i.publish(e,s,o),this.#s.publish(e,s,o)}static#p(e,t){switch(e){case"AbortError":return r.#l.get(r.Events.ABORTED);case"TimeoutError":return r.#l.get(r.Events.TIMEOUT);default:return t?new g(t.status,t.statusText):new g(500,"Internal Server Error")}}async#d(e,t,s){try{let o;if(!s&&(o=p.parse(e.headers.get(D.CONTENT_TYPE)),o)){for(let[n,i]of r.#f)if(i.has(o.type)||i.has(o.subtype)){s=n;break}}return(s??$)(e)}catch(o){return console.error("Unable to process response.",o,e),Promise.reject(this.#c(t,{cause:o}))}}static#T(e,t,s={}){let o;return t?o=t.startsWith("/")?new URL(`${e.pathname.replace(we,"")}${t}`,e.origin):new URL(t):o=new URL(e),Object.entries(s).forEach(([n,i])=>o.searchParams.append(n,i)),o}static#g(e,t){return(l.get(t)??new p(t)).essence==a.JSON&&[f.POST,f.PUT,f.PATCH].includes(e)}static#u(e){if(!I(e))for(let[{property:t,type:s,converter:o},n=e[t]]of r.#m)n instanceof s&&(e[t]=o(n));return e}get[Symbol.toStringTag](){return"Transportr"}};return ae(Me);})();
|
|
3
3
|
window.Transportr = Transportr.default;
|
|
4
4
|
//# sourceMappingURL=transportr.min.js.map
|