@optionfactory/ful 1.0.16 → 1.1.0
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/ful-client-errors.iife.js.map +1 -1
- package/dist/ful-client-errors.iife.min.js.map +1 -1
- package/dist/ful.iife.js +15 -13
- package/dist/ful.iife.js.map +1 -1
- package/dist/ful.iife.min.js +1 -1
- package/dist/ful.iife.min.js.map +1 -1
- package/dist/ful.min.mjs +1 -1
- package/dist/ful.min.mjs.map +1 -1
- package/dist/ful.mjs +15 -13
- package/dist/ful.mjs.map +1 -1
- package/package.json +2 -2
package/dist/ful.mjs
CHANGED
|
@@ -135,7 +135,7 @@ class MediaType {
|
|
|
135
135
|
*/
|
|
136
136
|
/**
|
|
137
137
|
* @typedef HttpInterceptor
|
|
138
|
-
* @property {function(
|
|
138
|
+
* @property {function(URL,RequestInit|undefined,HttpInterceptorChain):Promise<Response>} intercept
|
|
139
139
|
*/
|
|
140
140
|
|
|
141
141
|
class HttpClientError extends Failure {
|
|
@@ -212,11 +212,11 @@ class CsrfTokenInterceptor {
|
|
|
212
212
|
this.#k = document.querySelector("meta[name='_csrf_header']")?.getAttribute("content");
|
|
213
213
|
this.#v = document.querySelector("meta[name='_csrf']")?.getAttribute("content");
|
|
214
214
|
}
|
|
215
|
-
async intercept(request, chain) {
|
|
215
|
+
async intercept(url, request, chain) {
|
|
216
216
|
if (this.#k && this.#v) {
|
|
217
217
|
request.headers.set(this.#k, this.#v);
|
|
218
218
|
}
|
|
219
|
-
return await chain.proceed(request);
|
|
219
|
+
return await chain.proceed(url, request);
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
/**
|
|
@@ -230,8 +230,8 @@ class RedirectOnUnauthorizedInterceptor {
|
|
|
230
230
|
constructor(redirectUri) {
|
|
231
231
|
this.#redirectUri = redirectUri;
|
|
232
232
|
}
|
|
233
|
-
async intercept(request, chain) {
|
|
234
|
-
const response = await chain.proceed(request);
|
|
233
|
+
async intercept(url, request, chain) {
|
|
234
|
+
const response = await chain.proceed(url, request);
|
|
235
235
|
if (response.status === 401) {
|
|
236
236
|
window.location.href = this.#redirectUri;
|
|
237
237
|
}
|
|
@@ -271,8 +271,8 @@ class HttpClientBuilder {
|
|
|
271
271
|
* @implements {HttpInterceptor}
|
|
272
272
|
*/
|
|
273
273
|
class HttpCall {
|
|
274
|
-
async intercept(request, chain) {
|
|
275
|
-
return await fetch(request);
|
|
274
|
+
async intercept(url, request, chain) {
|
|
275
|
+
return await fetch(new Request(url, request));
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
|
|
@@ -290,12 +290,13 @@ class HttpInterceptorChain {
|
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
292
|
*
|
|
293
|
-
* @param {
|
|
293
|
+
* @param {URL} url
|
|
294
|
+
* @param {RequestInit} request
|
|
294
295
|
* @returns {Promise<Response>} the response
|
|
295
296
|
*/
|
|
296
|
-
async proceed(request) {
|
|
297
|
+
async proceed(url, request) {
|
|
297
298
|
const interceptor = this.#interceptors[this.#current];
|
|
298
|
-
return await interceptor.intercept(request, new HttpInterceptorChain(this.#interceptors, this.#current + 1));
|
|
299
|
+
return await interceptor.intercept(url, request, new HttpInterceptorChain(this.#interceptors, this.#current + 1));
|
|
299
300
|
}
|
|
300
301
|
}
|
|
301
302
|
|
|
@@ -326,7 +327,8 @@ class HttpClient {
|
|
|
326
327
|
async exchange(uri, options, interceptors) {
|
|
327
328
|
const is = [...this.#interceptors, ...interceptors || [], new HttpCall()];
|
|
328
329
|
const chain = new HttpInterceptorChain(is, 0);
|
|
329
|
-
|
|
330
|
+
const url = new URL(new Request(uri).url);
|
|
331
|
+
return await chain.proceed(url, options ?? {});
|
|
330
332
|
}
|
|
331
333
|
/**
|
|
332
334
|
* Creates a request builder.
|
|
@@ -953,10 +955,10 @@ class AuthorizationCodeFlowInterceptor {
|
|
|
953
955
|
this.#gracePeriodBefore = gracePeriodBefore || 2000;
|
|
954
956
|
this.#gracePeriodAfter = gracePeriodAfter || 30000;
|
|
955
957
|
}
|
|
956
|
-
async intercept(request, chain) {
|
|
958
|
+
async intercept(url, request, chain) {
|
|
957
959
|
await this.#session.refreshIf(this.#gracePeriodBefore);
|
|
958
960
|
request.headers.set("Authorization", this.#session.bearerToken());
|
|
959
|
-
const response = await chain.proceed(request);
|
|
961
|
+
const response = await chain.proceed(url, request);
|
|
960
962
|
await this.#session.refreshIf(this.#gracePeriodAfter);
|
|
961
963
|
return response;
|
|
962
964
|
}
|