@thunderid/browser 1.0.6 → 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/cjs/index.cjs +51 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/createHttpClientFetcher.d.ts +24 -0
- package/dist/utils/createHttpClientFetcher.d.ts.map +1 -0
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -3062,6 +3062,56 @@ const http = (client) => {
|
|
|
3062
3062
|
};
|
|
3063
3063
|
var http_default = http;
|
|
3064
3064
|
|
|
3065
|
+
//#endregion
|
|
3066
|
+
//#region src/utils/createHttpClientFetcher.ts
|
|
3067
|
+
/**
|
|
3068
|
+
* Builds a `fetch`-shaped function backed by the shared `FetchHttpClient` singleton, for
|
|
3069
|
+
* framework wrappers (`@thunderid/react`, `@thunderid/vue`) that need to hand a core
|
|
3070
|
+
* `@thunderid/javascript` API function a `fetcher` carrying the access token automatically.
|
|
3071
|
+
*
|
|
3072
|
+
* Unlike a plain `fetch` call, `FetchHttpClient.request` throws on a non-2xx response instead
|
|
3073
|
+
* of resolving it. This adapter catches that and reconstructs a `Response`-shaped object from
|
|
3074
|
+
* the thrown error's `response`, so the core API function sees the real status and body instead
|
|
3075
|
+
* of treating every non-2xx result as a network failure. A genuine network error (no response
|
|
3076
|
+
* attached) still propagates.
|
|
3077
|
+
*
|
|
3078
|
+
* @param instanceId - Which `FetchHttpClient` instance to use, for multi-instance apps. Defaults to `0`.
|
|
3079
|
+
* @returns A function matching the `(url, config) => Promise<Response>` shape core API functions expect.
|
|
3080
|
+
* @example
|
|
3081
|
+
* ```typescript
|
|
3082
|
+
* await updateMeCredentials({
|
|
3083
|
+
* ...config,
|
|
3084
|
+
* fetcher: fetcher ?? createHttpClientFetcher(instanceId),
|
|
3085
|
+
* });
|
|
3086
|
+
* ```
|
|
3087
|
+
*/
|
|
3088
|
+
const createHttpClientFetcher = (instanceId = 0) => {
|
|
3089
|
+
return async (url, config) => {
|
|
3090
|
+
const httpClient = FetchHttpClient_default.getInstance(instanceId);
|
|
3091
|
+
const toResponse = (data, status, statusText) => ({
|
|
3092
|
+
json: () => Promise.resolve(data),
|
|
3093
|
+
ok: status >= 200 && status < 300,
|
|
3094
|
+
status,
|
|
3095
|
+
statusText,
|
|
3096
|
+
text: () => Promise.resolve(typeof data === "string" ? data : JSON.stringify(data))
|
|
3097
|
+
});
|
|
3098
|
+
try {
|
|
3099
|
+
const response = await httpClient.request({
|
|
3100
|
+
data: config.body ? JSON.parse(config.body) : void 0,
|
|
3101
|
+
headers: config.headers,
|
|
3102
|
+
method: config.method || "POST",
|
|
3103
|
+
url
|
|
3104
|
+
});
|
|
3105
|
+
return toResponse(response.data, response.status, response.statusText || "");
|
|
3106
|
+
} catch (error) {
|
|
3107
|
+
const httpError = error;
|
|
3108
|
+
if (httpError?.response) return toResponse(httpError.response.data, httpError.response.status, httpError.response.statusText ?? "");
|
|
3109
|
+
throw error;
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
};
|
|
3113
|
+
var createHttpClientFetcher_default = createHttpClientFetcher;
|
|
3114
|
+
|
|
3065
3115
|
//#endregion
|
|
3066
3116
|
//#region src/utils/handleWebAuthnAuthentication.ts
|
|
3067
3117
|
const logger$1 = (0, __thunderid_javascript.createPackageComponentLogger)("@thunderid/browser", "WebAuthn");
|
|
@@ -3930,6 +3980,7 @@ exports.TOKEN_REQUEST_CONFIG_KEY = TOKEN_REQUEST_CONFIG_KEY;
|
|
|
3930
3980
|
exports.ThunderIDBrowserClient = ThunderIDBrowserClient_default;
|
|
3931
3981
|
exports.buildAvatarSpec = buildAvatarSpec_default;
|
|
3932
3982
|
exports.createClassObserver = createClassObserver;
|
|
3983
|
+
exports.createHttpClientFetcher = createHttpClientFetcher_default;
|
|
3933
3984
|
exports.createMediaQueryListener = createMediaQueryListener;
|
|
3934
3985
|
exports.createSessionManagementHelper = SessionManagementHelper_default;
|
|
3935
3986
|
exports.deriveAvatarContent = deriveAvatarContent;
|