@thunderid/browser 1.3.0 → 1.3.1
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/ThunderIDBrowserClient.d.ts +26 -9
- package/dist/ThunderIDBrowserClient.d.ts.map +1 -1
- package/dist/cjs/index.cjs +174 -124
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +175 -125
- package/dist/index.js.map +1 -1
- package/dist/models/BrowserConfig.d.ts +1 -1
- package/dist/models/BrowserConfig.d.ts.map +1 -1
- package/dist/theme/themeDetection.d.ts +11 -2
- package/dist/theme/themeDetection.d.ts.map +1 -1
- package/dist/utils/generateAvatarDataUri.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export type { AnonymousEntityIcon } from './utils/anonymousEntityIcons.generated
|
|
|
40
40
|
export { default as resolveLogoUri } from './utils/resolveLogoUri';
|
|
41
41
|
export type { ResolvedLogo, ResolvedLogoKind } from './utils/resolveLogoUri';
|
|
42
42
|
export { detectThemeMode, createClassObserver, createMediaQueryListener } from './theme/themeDetection';
|
|
43
|
-
export type { BrowserThemeDetection } from './theme/themeDetection';
|
|
43
|
+
export type { BrowserThemeDetection, MediaQueryListener } from './theme/themeDetection';
|
|
44
44
|
export { default as getActiveTheme } from './theme/getActiveTheme';
|
|
45
45
|
export { default as normalizeBorderRadius } from './theme/normalizeBorderRadius';
|
|
46
46
|
export * from '@thunderid/javascript';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AAGH,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,mBAAmB,CAAC;A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3E,OAAO,EAAC,eAAe,EAAE,mBAAmB,EAAE,wBAAwB,EAAC,MAAM,wBAAwB,CAAC;AACtG,YAAY,EAAC,qBAAqB,EAAE,kBAAkB,EAAC,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAC,OAAO,IAAI,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAC,OAAO,IAAI,qBAAqB,EAAC,MAAM,+BAA+B,CAAC;AAG/E,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'buffer/index.js';
|
|
2
2
|
if (typeof window !== 'undefined' && !window.Buffer) { window.Buffer = Buffer; }
|
|
3
|
-
import { DEFAULT_THEME, HttpClient, OIDCRequestConstants, ThunderIDAuthException, ThunderIDJavaScriptClient, ThunderIDRuntimeError, TokenConstants, arrayBufferToBase64url, base64urlToArrayBuffer, createPackageComponentLogger, extractEmojiFromUri, extractPkceStorageKeyFromState, isEmojiUri } from "@thunderid/javascript";
|
|
3
|
+
import { DEFAULT_THEME, HttpClient, OIDCRequestConstants, ThunderIDAuthException, ThunderIDJavaScriptClient, ThunderIDRuntimeError, TokenConstants, arrayBufferToBase64url, base64urlToArrayBuffer, createPackageComponentLogger, extractEmojiFromUri, extractPkceStorageKeyFromState, generateFlattenedUserProfile, getUsersMe, isEmojiUri, resolveResourceEndpoint } from "@thunderid/javascript";
|
|
4
4
|
import base64url from "base64url";
|
|
5
5
|
import sha256 from "fast-sha256";
|
|
6
6
|
import { createLocalJWKSet, jwtVerify } from "jose";
|
|
@@ -32,6 +32,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
enumerable: true
|
|
33
33
|
}) : target, mod));
|
|
34
34
|
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/constants/Hooks.ts
|
|
37
|
+
/**
|
|
38
|
+
* Event hook names for attaching callbacks via `ThunderIDBrowserClient.on()`.
|
|
39
|
+
*/
|
|
40
|
+
let Hooks = /* @__PURE__ */ function(Hooks$1) {
|
|
41
|
+
Hooks$1["SignIn"] = "sign-in";
|
|
42
|
+
Hooks$1["SignOut"] = "sign-out";
|
|
43
|
+
Hooks$1["Initialize"] = "initialize";
|
|
44
|
+
Hooks$1["HttpRequestStart"] = "http-request-start";
|
|
45
|
+
Hooks$1["HttpRequestFinish"] = "http-request-finish";
|
|
46
|
+
Hooks$1["HttpRequestError"] = "http-request-error";
|
|
47
|
+
Hooks$1["HttpRequestSuccess"] = "http-request-success";
|
|
48
|
+
Hooks$1["RevokeAccessToken"] = "revoke-access-token";
|
|
49
|
+
Hooks$1["CustomGrant"] = "custom-grant";
|
|
50
|
+
Hooks$1["SignOutFailed"] = "sign-out-failed";
|
|
51
|
+
return Hooks$1;
|
|
52
|
+
}({});
|
|
53
|
+
var Hooks_default = Hooks;
|
|
54
|
+
|
|
35
55
|
//#endregion
|
|
36
56
|
//#region src/constants/SPAConstants.ts
|
|
37
57
|
const ERROR = "error";
|
|
@@ -780,6 +800,57 @@ var AuthenticationHelper = class {
|
|
|
780
800
|
};
|
|
781
801
|
var AuthenticationHelper_default = AuthenticationHelper;
|
|
782
802
|
|
|
803
|
+
//#endregion
|
|
804
|
+
//#region src/utils/createHttpClientFetcher.ts
|
|
805
|
+
/**
|
|
806
|
+
* Builds a `fetch`-shaped function backed by the shared `FetchHttpClient` singleton, for
|
|
807
|
+
* framework wrappers (`@thunderid/react`, `@thunderid/vue`) that need to hand a core
|
|
808
|
+
* `@thunderid/javascript` API function a `fetcher` carrying the access token automatically.
|
|
809
|
+
*
|
|
810
|
+
* Unlike a plain `fetch` call, `FetchHttpClient.request` throws on a non-2xx response instead
|
|
811
|
+
* of resolving it. This adapter catches that and reconstructs a `Response`-shaped object from
|
|
812
|
+
* the thrown error's `response`, so the core API function sees the real status and body instead
|
|
813
|
+
* of treating every non-2xx result as a network failure. A genuine network error (no response
|
|
814
|
+
* attached) still propagates.
|
|
815
|
+
*
|
|
816
|
+
* @param instanceId - Which `FetchHttpClient` instance to use, for multi-instance apps. Defaults to `0`.
|
|
817
|
+
* @returns A function matching the `(url, config) => Promise<Response>` shape core API functions expect.
|
|
818
|
+
* @example
|
|
819
|
+
* ```typescript
|
|
820
|
+
* await updateMeCredentials({
|
|
821
|
+
* ...config,
|
|
822
|
+
* fetcher: fetcher ?? createHttpClientFetcher(instanceId),
|
|
823
|
+
* });
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
const createHttpClientFetcher = (instanceId = 0) => {
|
|
827
|
+
return async (url, config) => {
|
|
828
|
+
const httpClient = FetchHttpClient_default.getInstance(instanceId);
|
|
829
|
+
const toResponse = (data, status, statusText) => ({
|
|
830
|
+
json: () => Promise.resolve(data),
|
|
831
|
+
ok: status >= 200 && status < 300,
|
|
832
|
+
status,
|
|
833
|
+
statusText,
|
|
834
|
+
text: () => Promise.resolve(typeof data === "string" ? data : JSON.stringify(data))
|
|
835
|
+
});
|
|
836
|
+
try {
|
|
837
|
+
const response = await httpClient.request({
|
|
838
|
+
data: config.body ? JSON.parse(config.body) : void 0,
|
|
839
|
+
headers: config.headers,
|
|
840
|
+
method: config.method || "POST",
|
|
841
|
+
signal: config.signal,
|
|
842
|
+
url
|
|
843
|
+
});
|
|
844
|
+
return toResponse(response.data, response.status, response.statusText || "");
|
|
845
|
+
} catch (error) {
|
|
846
|
+
const httpError = error;
|
|
847
|
+
if (httpError?.response) return toResponse(httpError.response.data, httpError.response.status, httpError.response.statusText ?? "");
|
|
848
|
+
throw error;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
};
|
|
852
|
+
var createHttpClientFetcher_default = createHttpClientFetcher;
|
|
853
|
+
|
|
783
854
|
//#endregion
|
|
784
855
|
//#region src/utils/navigate.ts
|
|
785
856
|
/**
|
|
@@ -2439,14 +2510,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2439
2510
|
_storage = BrowserStorage_default.SessionStorage;
|
|
2440
2511
|
_getSignOutURLFromSessionStorage = false;
|
|
2441
2512
|
_isHttpHandlerEnabled = true;
|
|
2442
|
-
|
|
2443
|
-
_httpFinishCallback;
|
|
2444
|
-
_onSignInCallback = () => null;
|
|
2445
|
-
_onSignOutCallback = () => null;
|
|
2446
|
-
_onSignOutFailedCallback = () => null;
|
|
2447
|
-
_onEndUserSession = () => null;
|
|
2448
|
-
_onInitialize = () => null;
|
|
2449
|
-
_onCustomGrant = /* @__PURE__ */ new Map();
|
|
2513
|
+
_hookCallbacks = /* @__PURE__ */ new Map();
|
|
2450
2514
|
_initialized = false;
|
|
2451
2515
|
_startedInitialize = false;
|
|
2452
2516
|
constructor(instanceId = 0) {
|
|
@@ -2473,6 +2537,12 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2473
2537
|
await this._authHelper?.attachTokenToRequestConfig(request);
|
|
2474
2538
|
};
|
|
2475
2539
|
this._httpClient = FetchHttpClient_default.getInstance(this._browserInstanceId, true, attachToken);
|
|
2540
|
+
this._httpClient.setHttpRequestStartCallback((request) => {
|
|
2541
|
+
this._emitHook(Hooks_default.HttpRequestStart, request);
|
|
2542
|
+
});
|
|
2543
|
+
this._httpClient.setHttpRequestSuccessCallback((response) => {
|
|
2544
|
+
this._emitHook(Hooks_default.HttpRequestSuccess, response);
|
|
2545
|
+
});
|
|
2476
2546
|
this._authHelper = new AuthenticationHelper_default(sm, this._spaHelper, this._browserInstanceId, {
|
|
2477
2547
|
exchangeToken: (cfg) => super.exchangeToken(cfg),
|
|
2478
2548
|
getAccessToken: (sessionId) => this.getAccessToken(sessionId),
|
|
@@ -2487,7 +2557,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2487
2557
|
setPKCECode: (pkceKey, state) => this.setPKCECode(pkceKey, state)
|
|
2488
2558
|
});
|
|
2489
2559
|
this._initialized = true;
|
|
2490
|
-
|
|
2560
|
+
this._emitHook(Hooks_default.Initialize, true);
|
|
2491
2561
|
if (!merged.autoLogoutOnTokenRefreshError) return true;
|
|
2492
2562
|
window.addEventListener("message", (event) => {
|
|
2493
2563
|
if (event?.data?.type === REFRESH_ACCESS_TOKEN_ERR0R) this.signOut();
|
|
@@ -2518,7 +2588,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2518
2588
|
if (!SPAUtils_default.canContinueSignIn(Boolean(config?.callOnlyOnRedirect), authorizationCode)) return;
|
|
2519
2589
|
delete config?.callOnlyOnRedirect;
|
|
2520
2590
|
const user = await this._signInInternal(config, authorizationCode, state, tokenRequestConfig);
|
|
2521
|
-
if (user
|
|
2591
|
+
if (user) this._emitHook(Hooks_default.SignIn, user);
|
|
2522
2592
|
return user;
|
|
2523
2593
|
}
|
|
2524
2594
|
async _signInInternal(signInConfig, authorizationCode, state, tokenRequestConfig) {
|
|
@@ -2587,7 +2657,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2587
2657
|
await this.isInitialized();
|
|
2588
2658
|
if (SPAUtils_default.wasSignInCalled()) return;
|
|
2589
2659
|
const response = await this._signInSilentlyInternal(additionalParams, tokenRequestConfig);
|
|
2590
|
-
if (
|
|
2660
|
+
if (response) this._emitHook(Hooks_default.SignIn, response);
|
|
2591
2661
|
return response;
|
|
2592
2662
|
}
|
|
2593
2663
|
async _signInSilentlyInternal(additionalParams, tokenRequestConfig) {
|
|
@@ -2633,16 +2703,40 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2633
2703
|
}
|
|
2634
2704
|
async httpRequest(requestConfig) {
|
|
2635
2705
|
await this._validateMethod(false);
|
|
2636
|
-
|
|
2706
|
+
const response = await this._authHelper.httpRequest(this._httpClient, requestConfig, this._isHttpHandlerEnabled, this._emitHttpError, this._emitHttpFinish);
|
|
2707
|
+
if (this._isHttpHandlerEnabled) this._emitHttpFinish();
|
|
2708
|
+
return response;
|
|
2637
2709
|
}
|
|
2638
2710
|
async httpRequestAll(configs) {
|
|
2639
2711
|
await this._validateMethod(false);
|
|
2640
|
-
|
|
2712
|
+
const responses = await this._authHelper.httpRequestAll(configs, this._httpClient, this._isHttpHandlerEnabled, this._emitHttpError, this._emitHttpFinish);
|
|
2713
|
+
if (this._isHttpHandlerEnabled) this._emitHttpFinish();
|
|
2714
|
+
return responses;
|
|
2641
2715
|
}
|
|
2642
2716
|
async getUser(userId) {
|
|
2643
2717
|
await this._validateMethod();
|
|
2644
2718
|
return super.getUser(userId);
|
|
2645
2719
|
}
|
|
2720
|
+
/**
|
|
2721
|
+
* Fetches the signed-in user's profile from the `/users/me` endpoint (or `endpoints.usersMe` when
|
|
2722
|
+
* configured), sending the request through the client's HTTP client so the access token is attached.
|
|
2723
|
+
*
|
|
2724
|
+
* @param options - Optional `baseUrl` or full `url` overrides for the profile endpoint.
|
|
2725
|
+
* @returns The user's profile.
|
|
2726
|
+
*/
|
|
2727
|
+
async getUserProfile(options) {
|
|
2728
|
+
await this._validateMethod();
|
|
2729
|
+
const configData = await this.getStorageManager().getConfigData();
|
|
2730
|
+
const profile = await getUsersMe({
|
|
2731
|
+
baseUrl: options?.baseUrl ?? configData?.baseUrl,
|
|
2732
|
+
fetcher: createHttpClientFetcher_default(this._browserInstanceId),
|
|
2733
|
+
url: resolveResourceEndpoint("usersMe", configData, options?.url)
|
|
2734
|
+
});
|
|
2735
|
+
return {
|
|
2736
|
+
flattenedProfile: generateFlattenedUserProfile(profile),
|
|
2737
|
+
profile
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2646
2740
|
async getAccessToken(sessionId) {
|
|
2647
2741
|
return super.getAccessToken(sessionId);
|
|
2648
2742
|
}
|
|
@@ -2671,7 +2765,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2671
2765
|
return super.isSignedIn(userId);
|
|
2672
2766
|
}
|
|
2673
2767
|
notifySignIn(user) {
|
|
2674
|
-
this.
|
|
2768
|
+
this._emitHook(Hooks_default.SignIn, user);
|
|
2675
2769
|
}
|
|
2676
2770
|
async isSessionActive() {
|
|
2677
2771
|
await this.isInitialized();
|
|
@@ -2690,14 +2784,14 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2690
2784
|
const timer = await this._spaHelper.getRefreshTimeoutTimer();
|
|
2691
2785
|
await super.revokeAccessToken(userId);
|
|
2692
2786
|
await this._spaHelper.clearRefreshTokenTimeout(timer);
|
|
2693
|
-
|
|
2787
|
+
await this._emitHook(Hooks_default.RevokeAccessToken, true);
|
|
2694
2788
|
return true;
|
|
2695
2789
|
}
|
|
2696
2790
|
async exchangeToken(config) {
|
|
2697
2791
|
if (config.signInRequired) await this._validateMethod();
|
|
2698
2792
|
if (!config.id) return Promise.reject(new ThunderIDAuthException("SPA-AUTH_CLIENT-RCG-NF01", "The custom grant request id not found.", "Set the `id` attribute on the token exchange config."));
|
|
2699
2793
|
const response = await this._authHelper.exchangeToken(config, (cfg) => this._enableRetrievingSignOutURLFromSession(cfg));
|
|
2700
|
-
this.
|
|
2794
|
+
this._emitHook(`${Hooks_default.CustomGrant}:${config.id}`, response);
|
|
2701
2795
|
return response;
|
|
2702
2796
|
}
|
|
2703
2797
|
async reInitialize(config) {
|
|
@@ -2724,47 +2818,56 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2724
2818
|
async decodeJwtToken(token) {
|
|
2725
2819
|
return this.getCryptoHelper().decodeJwtToken(token);
|
|
2726
2820
|
}
|
|
2821
|
+
/**
|
|
2822
|
+
* Subscribes a callback to a lifecycle hook. Every callback registered for a hook is called when it
|
|
2823
|
+
* fires; registering the same callback again for the same hook has no further effect. Hooks can be
|
|
2824
|
+
* registered before or after `initialize()`.
|
|
2825
|
+
*
|
|
2826
|
+
* @param hook - The hook to subscribe to (see `Hooks`).
|
|
2827
|
+
* @param callback - Called when the hook fires.
|
|
2828
|
+
* @param id - The custom grant id. Required for `custom-grant`.
|
|
2829
|
+
*/
|
|
2727
2830
|
async on(hook, callback, id) {
|
|
2728
2831
|
await this.isInitialized();
|
|
2729
2832
|
if (!callback || typeof callback !== "function") throw new ThunderIDAuthException("SPA-AUTH_CLIENT-ON-IV02", "Invalid callback function.", "The provided callback must be a function.");
|
|
2730
2833
|
switch (hook) {
|
|
2731
|
-
case
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
case
|
|
2735
|
-
|
|
2736
|
-
|
|
2834
|
+
case Hooks_default.SignIn:
|
|
2835
|
+
case Hooks_default.RevokeAccessToken:
|
|
2836
|
+
case Hooks_default.Initialize:
|
|
2837
|
+
case Hooks_default.HttpRequestError:
|
|
2838
|
+
case Hooks_default.HttpRequestFinish:
|
|
2839
|
+
case Hooks_default.HttpRequestStart:
|
|
2840
|
+
case Hooks_default.HttpRequestSuccess:
|
|
2841
|
+
this._addHookCallback(hook, callback);
|
|
2737
2842
|
break;
|
|
2738
|
-
case
|
|
2739
|
-
|
|
2843
|
+
case Hooks_default.SignOut:
|
|
2844
|
+
if (await SPAUtils_default.isSignOutSuccessful(ThunderIDBrowserClient.isSignOutSuccessful.bind(ThunderIDBrowserClient), () => ThunderIDBrowserClient.clearSession())) callback();
|
|
2740
2845
|
break;
|
|
2741
|
-
case
|
|
2742
|
-
this.
|
|
2846
|
+
case Hooks_default.CustomGrant:
|
|
2847
|
+
id && this._addHookCallback(`${Hooks_default.CustomGrant}:${id}`, callback);
|
|
2743
2848
|
break;
|
|
2744
|
-
case
|
|
2745
|
-
this._httpErrorCallback = callback;
|
|
2746
|
-
break;
|
|
2747
|
-
case "http-request-finish":
|
|
2748
|
-
this._httpFinishCallback = callback;
|
|
2749
|
-
break;
|
|
2750
|
-
case "http-request-start":
|
|
2751
|
-
this._httpClient?.setHttpRequestStartCallback?.(callback);
|
|
2752
|
-
break;
|
|
2753
|
-
case "http-request-success":
|
|
2754
|
-
this._httpClient?.setHttpRequestSuccessCallback?.(callback);
|
|
2755
|
-
break;
|
|
2756
|
-
case "custom-grant":
|
|
2757
|
-
id && this._onCustomGrant.set(id, callback);
|
|
2758
|
-
break;
|
|
2759
|
-
case "sign-out-failed": {
|
|
2760
|
-
this._onSignOutFailedCallback = callback;
|
|
2849
|
+
case Hooks_default.SignOutFailed: {
|
|
2761
2850
|
const signOutFail = SPAUtils_default.didSignOutFail(ThunderIDBrowserClient.didSignOutFail.bind(ThunderIDBrowserClient));
|
|
2762
|
-
if (signOutFail)
|
|
2851
|
+
if (signOutFail) callback(signOutFail);
|
|
2763
2852
|
break;
|
|
2764
2853
|
}
|
|
2765
2854
|
default: throw new ThunderIDAuthException("SPA-AUTH_CLIENT-ON-IV01", "Invalid hook.", `Unknown hook: "${hook}"`);
|
|
2766
2855
|
}
|
|
2767
2856
|
}
|
|
2857
|
+
_addHookCallback(hook, callback) {
|
|
2858
|
+
const callbacks = this._hookCallbacks.get(hook) ?? /* @__PURE__ */ new Set();
|
|
2859
|
+
callbacks.add(callback);
|
|
2860
|
+
this._hookCallbacks.set(hook, callbacks);
|
|
2861
|
+
}
|
|
2862
|
+
_emitHook(hook, response) {
|
|
2863
|
+
return Promise.all([...this._hookCallbacks.get(hook) ?? []].map((callback) => Promise.resolve(callback(response))));
|
|
2864
|
+
}
|
|
2865
|
+
_emitHttpError = async (error) => {
|
|
2866
|
+
await this._emitHook(Hooks_default.HttpRequestError, error);
|
|
2867
|
+
};
|
|
2868
|
+
_emitHttpFinish = () => {
|
|
2869
|
+
this._emitHook(Hooks_default.HttpRequestFinish);
|
|
2870
|
+
};
|
|
2768
2871
|
_enableRetrievingSignOutURLFromSession(config) {
|
|
2769
2872
|
if (config.preventSignOutURLUpdate) this._getSignOutURLFromSessionStorage = true;
|
|
2770
2873
|
}
|
|
@@ -2790,26 +2893,6 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
2790
2893
|
};
|
|
2791
2894
|
var ThunderIDBrowserClient_default = ThunderIDBrowserClient;
|
|
2792
2895
|
|
|
2793
|
-
//#endregion
|
|
2794
|
-
//#region src/constants/Hooks.ts
|
|
2795
|
-
/**
|
|
2796
|
-
* Event hook names for attaching callbacks via `ThunderIDBrowserClient.on()`.
|
|
2797
|
-
*/
|
|
2798
|
-
let Hooks = /* @__PURE__ */ function(Hooks$1) {
|
|
2799
|
-
Hooks$1["SignIn"] = "sign-in";
|
|
2800
|
-
Hooks$1["SignOut"] = "sign-out";
|
|
2801
|
-
Hooks$1["Initialize"] = "initialize";
|
|
2802
|
-
Hooks$1["HttpRequestStart"] = "http-request-start";
|
|
2803
|
-
Hooks$1["HttpRequestFinish"] = "http-request-finish";
|
|
2804
|
-
Hooks$1["HttpRequestError"] = "http-request-error";
|
|
2805
|
-
Hooks$1["HttpRequestSuccess"] = "http-request-success";
|
|
2806
|
-
Hooks$1["RevokeAccessToken"] = "revoke-access-token";
|
|
2807
|
-
Hooks$1["CustomGrant"] = "custom-grant";
|
|
2808
|
-
Hooks$1["SignOutFailed"] = "sign-out-failed";
|
|
2809
|
-
return Hooks$1;
|
|
2810
|
-
}({});
|
|
2811
|
-
var Hooks_default = Hooks;
|
|
2812
|
-
|
|
2813
2896
|
//#endregion
|
|
2814
2897
|
//#region src/utils/hasAuthParamsInUrl.ts
|
|
2815
2898
|
/**
|
|
@@ -2861,57 +2944,6 @@ const http = (client) => {
|
|
|
2861
2944
|
};
|
|
2862
2945
|
var http_default = http;
|
|
2863
2946
|
|
|
2864
|
-
//#endregion
|
|
2865
|
-
//#region src/utils/createHttpClientFetcher.ts
|
|
2866
|
-
/**
|
|
2867
|
-
* Builds a `fetch`-shaped function backed by the shared `FetchHttpClient` singleton, for
|
|
2868
|
-
* framework wrappers (`@thunderid/react`, `@thunderid/vue`) that need to hand a core
|
|
2869
|
-
* `@thunderid/javascript` API function a `fetcher` carrying the access token automatically.
|
|
2870
|
-
*
|
|
2871
|
-
* Unlike a plain `fetch` call, `FetchHttpClient.request` throws on a non-2xx response instead
|
|
2872
|
-
* of resolving it. This adapter catches that and reconstructs a `Response`-shaped object from
|
|
2873
|
-
* the thrown error's `response`, so the core API function sees the real status and body instead
|
|
2874
|
-
* of treating every non-2xx result as a network failure. A genuine network error (no response
|
|
2875
|
-
* attached) still propagates.
|
|
2876
|
-
*
|
|
2877
|
-
* @param instanceId - Which `FetchHttpClient` instance to use, for multi-instance apps. Defaults to `0`.
|
|
2878
|
-
* @returns A function matching the `(url, config) => Promise<Response>` shape core API functions expect.
|
|
2879
|
-
* @example
|
|
2880
|
-
* ```typescript
|
|
2881
|
-
* await updateMeCredentials({
|
|
2882
|
-
* ...config,
|
|
2883
|
-
* fetcher: fetcher ?? createHttpClientFetcher(instanceId),
|
|
2884
|
-
* });
|
|
2885
|
-
* ```
|
|
2886
|
-
*/
|
|
2887
|
-
const createHttpClientFetcher = (instanceId = 0) => {
|
|
2888
|
-
return async (url, config) => {
|
|
2889
|
-
const httpClient = FetchHttpClient_default.getInstance(instanceId);
|
|
2890
|
-
const toResponse = (data, status, statusText) => ({
|
|
2891
|
-
json: () => Promise.resolve(data),
|
|
2892
|
-
ok: status >= 200 && status < 300,
|
|
2893
|
-
status,
|
|
2894
|
-
statusText,
|
|
2895
|
-
text: () => Promise.resolve(typeof data === "string" ? data : JSON.stringify(data))
|
|
2896
|
-
});
|
|
2897
|
-
try {
|
|
2898
|
-
const response = await httpClient.request({
|
|
2899
|
-
data: config.body ? JSON.parse(config.body) : void 0,
|
|
2900
|
-
headers: config.headers,
|
|
2901
|
-
method: config.method || "POST",
|
|
2902
|
-
signal: config.signal,
|
|
2903
|
-
url
|
|
2904
|
-
});
|
|
2905
|
-
return toResponse(response.data, response.status, response.statusText || "");
|
|
2906
|
-
} catch (error) {
|
|
2907
|
-
const httpError = error;
|
|
2908
|
-
if (httpError?.response) return toResponse(httpError.response.data, httpError.response.status, httpError.response.statusText ?? "");
|
|
2909
|
-
throw error;
|
|
2910
|
-
}
|
|
2911
|
-
};
|
|
2912
|
-
};
|
|
2913
|
-
var createHttpClientFetcher_default = createHttpClientFetcher;
|
|
2914
|
-
|
|
2915
2947
|
//#endregion
|
|
2916
2948
|
//#region src/utils/copyTextToClipboard.ts
|
|
2917
2949
|
/**
|
|
@@ -3505,6 +3537,23 @@ const AVATAR_PALETTES = [
|
|
|
3505
3537
|
* without needing the actual palette values.
|
|
3506
3538
|
*/
|
|
3507
3539
|
const AVATAR_GRADIENT_COUNT = AVATAR_PALETTES.length;
|
|
3540
|
+
const XML_ESCAPES = {
|
|
3541
|
+
"\"": """,
|
|
3542
|
+
"&": "&",
|
|
3543
|
+
"'": "'",
|
|
3544
|
+
"<": "<",
|
|
3545
|
+
">": ">"
|
|
3546
|
+
};
|
|
3547
|
+
/**
|
|
3548
|
+
* Escapes a caller-supplied value for interpolation into SVG text.
|
|
3549
|
+
*/
|
|
3550
|
+
const escapeXml = (value) => value.replace(/["&'<>]/g, (ch) => XML_ESCAPES[ch]);
|
|
3551
|
+
/**
|
|
3552
|
+
* Encodes an SVG document as a data URI. Lone UTF-16 surrogates are replaced with U+FFFD
|
|
3553
|
+
* first, since `encodeURIComponent` throws a `URIError` on them. `Array.from` iterates by
|
|
3554
|
+
* code point, so a surrogate it yields on its own is unpaired.
|
|
3555
|
+
*/
|
|
3556
|
+
const toSvgDataUri = (svg) => `data:image/svg+xml,${encodeURIComponent(Array.from(svg, (ch) => ch.length === 1 && ch >= "\ud800" && ch <= "\udfff" ? "�" : ch).join(""))}`;
|
|
3508
3557
|
/**
|
|
3509
3558
|
* Fills in `params.content` when the spec itself didn't carry one, deriving it from a raw
|
|
3510
3559
|
* seed name (e.g. an app or user display name) — extracting initials for letter variants,
|
|
@@ -3555,11 +3604,10 @@ const generateGradientAvatar = ({ shape, variant, content, colors, bg }) => {
|
|
|
3555
3604
|
let text = "";
|
|
3556
3605
|
if (variant !== "blank") {
|
|
3557
3606
|
const letterCount = variant === "one_letter" ? 1 : 2;
|
|
3558
|
-
const initials = (content || "A").toUpperCase().slice(0, letterCount);
|
|
3607
|
+
const initials = escapeXml(Array.from((content || "A").toUpperCase()).slice(0, letterCount).join(""));
|
|
3559
3608
|
text = `<text x="50" y="64" font-family="Helvetica,Arial,sans-serif" font-weight="700" font-size="${letterCount === 1 ? 46 : 34}" text-anchor="middle" fill="#fff">${initials}</text>`;
|
|
3560
3609
|
}
|
|
3561
|
-
|
|
3562
|
-
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
3610
|
+
return toSvgDataUri(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${defs}${shapeMarkup(shape, background)}${text}</svg>`);
|
|
3563
3611
|
};
|
|
3564
3612
|
/**
|
|
3565
3613
|
* Renders one of the curated anonymous-animal icons, applying the requested background
|
|
@@ -3571,8 +3619,7 @@ const generateAnonymousAnimalAvatar = ({ shape, content, bg }) => {
|
|
|
3571
3619
|
const icon = ANONYMOUS_ANIMAL_ICONS[Object.prototype.hasOwnProperty.call(ANONYMOUS_ANIMAL_ICONS, content) ? content : pickAnonymousAvatarName_default()];
|
|
3572
3620
|
const color = bg ?? icon.color;
|
|
3573
3621
|
const markup = icon.markup.replaceAll("%COLOR%", color);
|
|
3574
|
-
|
|
3575
|
-
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
3622
|
+
return toSvgDataUri(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${shapeMarkup(shape, color)}${markup}</svg>`);
|
|
3576
3623
|
};
|
|
3577
3624
|
/**
|
|
3578
3625
|
* Renders one of the curated anonymous-entity icons (application/organization/resource-server
|
|
@@ -3584,8 +3631,7 @@ const generateAnonymousEntityAvatar = ({ shape, content, bg }) => {
|
|
|
3584
3631
|
const icon = ANONYMOUS_ENTITY_ICONS[Object.prototype.hasOwnProperty.call(ANONYMOUS_ENTITY_ICONS, content) ? content : pickAnonymousEntityName_default()];
|
|
3585
3632
|
const color = bg ?? icon.color;
|
|
3586
3633
|
const markup = icon.markup.replaceAll("%COLOR%", color);
|
|
3587
|
-
|
|
3588
|
-
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
3634
|
+
return toSvgDataUri(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${shapeMarkup(shape, color)}${markup}</svg>`);
|
|
3589
3635
|
};
|
|
3590
3636
|
/**
|
|
3591
3637
|
* Generates an avatar image as an `svg+xml` data URI from a fully-resolved {@link AvatarParams}.
|
|
@@ -3702,7 +3748,8 @@ const createClassObserver = (targetElement, callback, config = {}) => {
|
|
|
3702
3748
|
return observer;
|
|
3703
3749
|
};
|
|
3704
3750
|
/**
|
|
3705
|
-
* Creates a media query listener for system theme changes
|
|
3751
|
+
* Creates a media query listener for system theme changes. Call `disconnect()` on the returned
|
|
3752
|
+
* object to remove the listener.
|
|
3706
3753
|
*/
|
|
3707
3754
|
const createMediaQueryListener = (callback) => {
|
|
3708
3755
|
if (typeof window === "undefined" || !window.matchMedia) return null;
|
|
@@ -3712,7 +3759,10 @@ const createMediaQueryListener = (callback) => {
|
|
|
3712
3759
|
};
|
|
3713
3760
|
if (mediaQuery.addEventListener) mediaQuery.addEventListener("change", handleChange);
|
|
3714
3761
|
else mediaQuery.addListener(handleChange);
|
|
3715
|
-
return mediaQuery
|
|
3762
|
+
return Object.assign(mediaQuery, { disconnect: () => {
|
|
3763
|
+
if (mediaQuery.removeEventListener) mediaQuery.removeEventListener("change", handleChange);
|
|
3764
|
+
else mediaQuery.removeListener(handleChange);
|
|
3765
|
+
} });
|
|
3716
3766
|
};
|
|
3717
3767
|
|
|
3718
3768
|
//#endregion
|