@thunderid/browser 0.1.0 → 0.2.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/index.js CHANGED
@@ -32,6 +32,43 @@ 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/SPAConstants.ts
37
+ /**
38
+ * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
39
+ *
40
+ * WSO2 LLC. licenses this file to you under the Apache License,
41
+ * Version 2.0 (the "License"); you may not use this file except
42
+ * in compliance with the License.
43
+ * You may obtain a copy of the License at
44
+ *
45
+ * http://www.apache.org/licenses/LICENSE-2.0
46
+ *
47
+ * Unless required by applicable law or agreed to in writing,
48
+ * software distributed under the License is distributed on an
49
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
50
+ * KIND, either express or implied. See the License for the
51
+ * specific language governing permissions and limitations
52
+ * under the License.
53
+ */
54
+ const ERROR = "error";
55
+ const ERROR_DESCRIPTION = "error_description";
56
+ const CUSTOM_GRANT_CONFIG = "custom_grant_config";
57
+ const STATE_QUERY = "state";
58
+ const OP_IFRAME = "opIFrame";
59
+ const RP_IFRAME = "rpIFrame";
60
+ const PROMPT_NONE_IFRAME = "promptNoneIFrame";
61
+ const STATE = "Y2hlY2tTZXNzaW9u";
62
+ const SILENT_SIGN_IN_STATE = "sign-in-silently";
63
+ const INITIALIZED_SILENT_SIGN_IN = "initialized-silent-sign-in";
64
+ const PROMPT_NONE_REQUEST_SENT = "promptNoneRequestSent";
65
+ const ACCESS_TOKEN_INVALID = "Access token is invalid";
66
+ const REFRESH_ACCESS_TOKEN_ERR0R = "refresh-access-token-error";
67
+ const TOKEN_REQUEST_CONFIG_KEY = "token_request_config";
68
+ const CHECK_SESSION_SIGNED_IN = "check_session_signed_in";
69
+ const CHECK_SESSION_SIGNED_OUT = "check_session_signed_out";
70
+ const SET_SESSION_STATE_FROM_IFRAME = "set_session_state_from_iframe";
71
+
35
72
  //#endregion
36
73
  //#region src/FetchHttpClient.ts
37
74
  /**
@@ -105,98 +142,6 @@ var FetchHttpClient = class FetchHttpClient extends HttpClient {
105
142
  };
106
143
  var FetchHttpClient_default = FetchHttpClient;
107
144
 
108
- //#endregion
109
- //#region src/constants/SPAConstants.ts
110
- /**
111
- * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
112
- *
113
- * WSO2 LLC. licenses this file to you under the Apache License,
114
- * Version 2.0 (the "License"); you may not use this file except
115
- * in compliance with the License.
116
- * You may obtain a copy of the License at
117
- *
118
- * http://www.apache.org/licenses/LICENSE-2.0
119
- *
120
- * Unless required by applicable law or agreed to in writing,
121
- * software distributed under the License is distributed on an
122
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
123
- * KIND, either express or implied. See the License for the
124
- * specific language governing permissions and limitations
125
- * under the License.
126
- */
127
- const ERROR = "error";
128
- const ERROR_DESCRIPTION = "error_description";
129
- const CUSTOM_GRANT_CONFIG = "custom_grant_config";
130
- const STATE_QUERY = "state";
131
- const OP_IFRAME = "opIFrame";
132
- const RP_IFRAME = "rpIFrame";
133
- const PROMPT_NONE_IFRAME = "promptNoneIFrame";
134
- const STATE = "Y2hlY2tTZXNzaW9u";
135
- const SILENT_SIGN_IN_STATE = "sign-in-silently";
136
- const INITIALIZED_SILENT_SIGN_IN = "initialized-silent-sign-in";
137
- const PROMPT_NONE_REQUEST_SENT = "promptNoneRequestSent";
138
- const ACCESS_TOKEN_INVALID = "Access token is invalid";
139
- const REFRESH_ACCESS_TOKEN_ERR0R = "refresh-access-token-error";
140
- const TOKEN_REQUEST_CONFIG_KEY = "token_request_config";
141
- const CHECK_SESSION_SIGNED_IN = "check_session_signed_in";
142
- const CHECK_SESSION_SIGNED_OUT = "check_session_signed_out";
143
- const SET_SESSION_STATE_FROM_IFRAME = "set_session_state_from_iframe";
144
-
145
- //#endregion
146
- //#region src/utils/navigate.ts
147
- /**
148
- * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
149
- *
150
- * WSO2 LLC. licenses this file to you under the Apache License,
151
- * Version 2.0 (the "License"); you may not use this file except
152
- * in compliance with the License.
153
- * You may obtain a copy of the License at
154
- *
155
- * http://www.apache.org/licenses/LICENSE-2.0
156
- *
157
- * Unless required by applicable law or agreed to in writing,
158
- * software distributed under the License is distributed on an
159
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160
- * KIND, either express or implied. See the License for the
161
- * specific language governing permissions and limitations
162
- * under the License.
163
- */
164
- /**
165
- * Navigates to a new URL within the browser.
166
- *
167
- * - For same-origin URLs (relative paths or absolute URLs with the same origin),
168
- * uses the History API and dispatches a `popstate` event (SPA navigation).
169
- * - For cross-origin URLs, performs a full page load using `window.location.assign`.
170
- *
171
- * This allows seamless navigation for both SPA routes and external links.
172
- *
173
- * @param url - The target URL to navigate to. Can be a path, query, or absolute URL.
174
- *
175
- * @example
176
- * ```typescript
177
- * // SPA navigation (same origin)
178
- * navigate('/dashboard');
179
- *
180
- * // SPA navigation with query
181
- * navigate('/search?q=thunderid');
182
- *
183
- * // Cross-origin navigation (full page load)
184
- * navigate('https://accounts.asgardeo.io/t/dxlab/accountrecoveryendpoint/register.do');
185
- * ```
186
- */
187
- const navigate = (url) => {
188
- try {
189
- const targetUrl = new URL(url, window.location.origin);
190
- if (targetUrl.origin === window.location.origin) {
191
- window.history.pushState(null, "", targetUrl.pathname + targetUrl.search + targetUrl.hash);
192
- window.dispatchEvent(new PopStateEvent("popstate", { state: null }));
193
- } else window.location.assign(targetUrl.href);
194
- } catch {
195
- window.location.assign(url);
196
- }
197
- };
198
- var navigate_default = navigate;
199
-
200
145
  //#endregion
201
146
  //#region src/models/BrowserStorage.ts
202
147
  /**
@@ -304,22 +249,22 @@ var SPAUtils = class SPAUtils {
304
249
  history.pushState({}, document.title, url.replace(/\?code=.*$/, ""));
305
250
  }
306
251
  /**
307
- * Retrieves a PKCE verifier from sessionStorage.
252
+ * Retrieves a PKCE verifier from storage.
308
253
  *
309
254
  * @param pkceKey - The storage key for the PKCE verifier.
310
255
  * @returns The stored verifier string, or an empty string if not found.
311
256
  */
312
257
  static getPKCE(pkceKey) {
313
- return sessionStorage.getItem(pkceKey) ?? "";
258
+ return localStorage.getItem(pkceKey) ?? "";
314
259
  }
315
260
  /**
316
- * Persists a PKCE verifier in sessionStorage.
261
+ * Persists a PKCE verifier in storage.
317
262
  *
318
263
  * @param pkceKey - The storage key.
319
264
  * @param pkce - The PKCE verifier value.
320
265
  */
321
266
  static setPKCE(pkceKey, pkce) {
322
- sessionStorage.setItem(pkceKey, pkce);
267
+ localStorage.setItem(pkceKey, pkce);
323
268
  }
324
269
  /**
325
270
  * Persists the post-sign-out redirect URL for the given client and instance.
@@ -342,12 +287,12 @@ var SPAUtils = class SPAUtils {
342
287
  return sessionStorage.getItem(`${OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceId}-${clientId}`) ?? "";
343
288
  }
344
289
  /**
345
- * Removes a PKCE verifier from sessionStorage.
290
+ * Removes a PKCE verifier from storage.
346
291
  *
347
292
  * @param pkceKey - The storage key to remove.
348
293
  */
349
294
  static removePKCE(pkceKey) {
350
- sessionStorage.removeItem(pkceKey);
295
+ localStorage.removeItem(pkceKey);
351
296
  }
352
297
  /**
353
298
  * Determines whether the `signIn` method should continue based on the `callOnlyOnRedirect` flag.
@@ -887,6 +832,61 @@ var AuthenticationHelper = class {
887
832
  };
888
833
  var AuthenticationHelper_default = AuthenticationHelper;
889
834
 
835
+ //#endregion
836
+ //#region src/utils/navigate.ts
837
+ /**
838
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
839
+ *
840
+ * WSO2 LLC. licenses this file to you under the Apache License,
841
+ * Version 2.0 (the "License"); you may not use this file except
842
+ * in compliance with the License.
843
+ * You may obtain a copy of the License at
844
+ *
845
+ * http://www.apache.org/licenses/LICENSE-2.0
846
+ *
847
+ * Unless required by applicable law or agreed to in writing,
848
+ * software distributed under the License is distributed on an
849
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
850
+ * KIND, either express or implied. See the License for the
851
+ * specific language governing permissions and limitations
852
+ * under the License.
853
+ */
854
+ /**
855
+ * Navigates to a new URL within the browser.
856
+ *
857
+ * - For same-origin URLs (relative paths or absolute URLs with the same origin),
858
+ * uses the History API and dispatches a `popstate` event (SPA navigation).
859
+ * - For cross-origin URLs, performs a full page load using `window.location.assign`.
860
+ *
861
+ * This allows seamless navigation for both SPA routes and external links.
862
+ *
863
+ * @param url - The target URL to navigate to. Can be a path, query, or absolute URL.
864
+ *
865
+ * @example
866
+ * ```typescript
867
+ * // SPA navigation (same origin)
868
+ * navigate('/dashboard');
869
+ *
870
+ * // SPA navigation with query
871
+ * navigate('/search?q=thunderid');
872
+ *
873
+ * // Cross-origin navigation (full page load)
874
+ * navigate('https://localhost:8090/accountrecoveryendpoint/register.do');
875
+ * ```
876
+ */
877
+ const navigate = (url) => {
878
+ try {
879
+ const targetUrl = new URL(url, window.location.origin);
880
+ if (targetUrl.origin === window.location.origin) {
881
+ window.history.pushState(null, "", targetUrl.pathname + targetUrl.search + targetUrl.hash);
882
+ window.dispatchEvent(new PopStateEvent("popstate", { state: null }));
883
+ } else window.location.assign(targetUrl.href);
884
+ } catch {
885
+ window.location.assign(url);
886
+ }
887
+ };
888
+ var navigate_default = navigate;
889
+
890
890
  //#endregion
891
891
  //#region src/utils/SessionManagementHelper.ts
892
892
  /**
@@ -2847,7 +2847,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
2847
2847
  SPAUtils_default.setPKCE(pkceKey, await this.getPKCECode(resolvedState));
2848
2848
  }
2849
2849
  if (tokenRequestConfig) sm.setTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY, JSON.stringify(tokenRequestConfig));
2850
- if (signInConfig?.["response_mode"] === "direct") {
2850
+ if (signInConfig?.response_mode === "direct") {
2851
2851
  const authorizeUrl = new URL(url);
2852
2852
  return initializeEmbeddedSignInFlow({
2853
2853
  url: `${authorizeUrl.origin}${authorizeUrl.pathname}`,
@@ -2969,8 +2969,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
2969
2969
  if (config.signInRequired) await this._validateMethod();
2970
2970
  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."));
2971
2971
  const response = await this._authHelper.exchangeToken(config, (cfg) => this._enableRetrievingSignOutURLFromSession(cfg));
2972
- const cb = this._onCustomGrant.get(config.id);
2973
- cb && cb(response);
2972
+ this._onCustomGrant.get(config.id)?.(response);
2974
2973
  return response;
2975
2974
  }
2976
2975
  async reInitialize(config) {
@@ -3005,8 +3004,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
3005
3004
  return true;
3006
3005
  }
3007
3006
  async decodeJwtToken(token) {
3008
- if (!token) return void 0;
3009
- return this.getCryptoHelper()?.decodeJwtToken(token);
3007
+ return this.getCryptoHelper().decodeJwtToken(token);
3010
3008
  }
3011
3009
  async on(hook, callback, id) {
3012
3010
  await this.isInitialized();
@@ -3032,10 +3030,10 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
3032
3030
  this._httpFinishCallback = callback;
3033
3031
  break;
3034
3032
  case "http-request-start":
3035
- this._httpClient?.setHttpRequestStartCallback && this._httpClient.setHttpRequestStartCallback(callback);
3033
+ this._httpClient?.setHttpRequestStartCallback?.(callback);
3036
3034
  break;
3037
3035
  case "http-request-success":
3038
- this._httpClient?.setHttpRequestSuccessCallback && this._httpClient.setHttpRequestSuccessCallback(callback);
3036
+ this._httpClient?.setHttpRequestSuccessCallback?.(callback);
3039
3037
  break;
3040
3038
  case "custom-grant":
3041
3039
  id && this._onCustomGrant.set(id, callback);