@thunderid/node 0.0.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.
Files changed (48) hide show
  1. package/LICENSE +201 -0
  2. package/dist/ThunderIDNodeClient.d.ts +29 -0
  3. package/dist/ThunderIDNodeClient.d.ts.map +1 -0
  4. package/dist/__legacy__/client.d.ts +355 -0
  5. package/dist/__legacy__/client.d.ts.map +1 -0
  6. package/dist/__legacy__/constants/index.d.ts +20 -0
  7. package/dist/__legacy__/constants/index.d.ts.map +1 -0
  8. package/dist/__legacy__/constants/logger-config.d.ts +32 -0
  9. package/dist/__legacy__/constants/logger-config.d.ts.map +1 -0
  10. package/dist/__legacy__/constants/uuid-config.d.ts +19 -0
  11. package/dist/__legacy__/constants/uuid-config.d.ts.map +1 -0
  12. package/dist/__legacy__/core/authentication.d.ts +46 -0
  13. package/dist/__legacy__/core/authentication.d.ts.map +1 -0
  14. package/dist/__legacy__/core/index.d.ts +19 -0
  15. package/dist/__legacy__/core/index.d.ts.map +1 -0
  16. package/dist/__legacy__/models/index.d.ts +20 -0
  17. package/dist/__legacy__/models/index.d.ts.map +1 -0
  18. package/dist/__legacy__/models/session-data.d.ts +23 -0
  19. package/dist/__legacy__/models/session-data.d.ts.map +1 -0
  20. package/dist/__legacy__/models/url-callback.d.ts +19 -0
  21. package/dist/__legacy__/models/url-callback.d.ts.map +1 -0
  22. package/dist/__legacy__/stores/index.d.ts +19 -0
  23. package/dist/__legacy__/stores/index.d.ts.map +1 -0
  24. package/dist/__legacy__/stores/memory-cache-store.d.ts +24 -0
  25. package/dist/__legacy__/stores/memory-cache-store.d.ts.map +1 -0
  26. package/dist/__legacy__/utils/crypto-utils.d.ts +32 -0
  27. package/dist/__legacy__/utils/crypto-utils.d.ts.map +1 -0
  28. package/dist/__legacy__/utils/index.d.ts +20 -0
  29. package/dist/__legacy__/utils/index.d.ts.map +1 -0
  30. package/dist/__legacy__/utils/logger-utils.d.ts +26 -0
  31. package/dist/__legacy__/utils/logger-utils.d.ts.map +1 -0
  32. package/dist/__legacy__/utils/session-utils.d.ts +25 -0
  33. package/dist/__legacy__/utils/session-utils.d.ts.map +1 -0
  34. package/dist/cjs/index.cjs +773 -0
  35. package/dist/constants/CookieConfig.d.ts +28 -0
  36. package/dist/constants/CookieConfig.d.ts.map +1 -0
  37. package/dist/index.d.ts +28 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +721 -0
  40. package/dist/models/config.d.ts +45 -0
  41. package/dist/models/config.d.ts.map +1 -0
  42. package/dist/models/cookies.d.ts +59 -0
  43. package/dist/models/cookies.d.ts.map +1 -0
  44. package/dist/utils/generateSessionId.d.ts +20 -0
  45. package/dist/utils/generateSessionId.d.ts.map +1 -0
  46. package/dist/utils/getSessionCookieOptions.d.ts +41 -0
  47. package/dist/utils/getSessionCookieOptions.d.ts.map +1 -0
  48. package/package.json +70 -0
package/dist/index.js ADDED
@@ -0,0 +1,721 @@
1
+ import fetch, { Headers, Request, Response } from "cross-fetch";
2
+ import { ThunderIDAuthClient, ThunderIDAuthException, ThunderIDJavaScriptClient, VendorConstants } from "@thunderid/javascript";
3
+ import cache from "memory-cache";
4
+ import { v4, validate, version } from "uuid";
5
+ import base64url from "base64url";
6
+ import sha256 from "fast-sha256";
7
+ import * as jose from "jose";
8
+ import randombytes from "secure-random-bytes";
9
+
10
+ export * from "@thunderid/javascript"
11
+
12
+ //#region src/__legacy__/stores/memory-cache-store.ts
13
+ var MemoryCacheStore = class {
14
+ async setData(key, value) {
15
+ cache.put(key, value);
16
+ }
17
+ async getData(key) {
18
+ return cache.get(key) ?? "{}";
19
+ }
20
+ async removeData(key) {
21
+ cache.del(key);
22
+ }
23
+ };
24
+
25
+ //#endregion
26
+ //#region src/__legacy__/constants/uuid-config.ts
27
+ /**
28
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
29
+ *
30
+ * WSO2 LLC. licenses this file to you under the Apache License,
31
+ * Version 2.0 (the "License"); you may not use this file except
32
+ * in compliance with the License.
33
+ * You may obtain a copy of the License at
34
+ *
35
+ * http://www.apache.org/licenses/LICENSE-2.0
36
+ *
37
+ * Unless required by applicable law or agreed to in writing,
38
+ * software distributed under the License is distributed on an
39
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
40
+ * KIND, either express or implied. See the License for the
41
+ * specific language governing permissions and limitations
42
+ * under the License.
43
+ */
44
+ const UUID_VERSION = 4;
45
+
46
+ //#endregion
47
+ //#region src/__legacy__/constants/logger-config.ts
48
+ const LOGGER_CONFIG = {
49
+ bgGreen: "\x1B[42m",
50
+ bgRed: "\x1B[41m",
51
+ bgWhite: "\x1B[47m",
52
+ bgYellow: "\x1B[43m",
53
+ fgBlack: "\x1B[30m",
54
+ fgGreen: "\x1B[32m",
55
+ fgRed: "\x1B[31m",
56
+ fgWhite: "\x1B[37m",
57
+ fgYellow: "\x1B[33m",
58
+ reset: "\x1B[0m"
59
+ };
60
+
61
+ //#endregion
62
+ //#region src/__legacy__/utils/session-utils.ts
63
+ var SessionUtils = class {
64
+ constructor() {}
65
+ static createUUID() {
66
+ return v4();
67
+ }
68
+ static validateUUID(uuid) {
69
+ if (validate(uuid) && version(uuid) === UUID_VERSION) return Promise.resolve(true);
70
+ return Promise.resolve(false);
71
+ }
72
+ static validateSession(sessionData) {
73
+ if (Date.now() < sessionData.created_at + parseInt(sessionData.expires_in, 10) * 60 * 1e3) return Promise.resolve(true);
74
+ Logger.warn("Expired Session");
75
+ return Promise.resolve(false);
76
+ }
77
+ };
78
+
79
+ //#endregion
80
+ //#region src/__legacy__/utils/logger-utils.ts
81
+ var LogLevel = /* @__PURE__ */ function(LogLevel$1) {
82
+ LogLevel$1[LogLevel$1["DEBUG"] = 0] = "DEBUG";
83
+ LogLevel$1[LogLevel$1["INFO"] = 1] = "INFO";
84
+ LogLevel$1[LogLevel$1["WARN"] = 2] = "WARN";
85
+ LogLevel$1[LogLevel$1["ERROR"] = 3] = "ERROR";
86
+ LogLevel$1[LogLevel$1["OFF"] = 4] = "OFF";
87
+ return LogLevel$1;
88
+ }(LogLevel || {});
89
+ var Logger = class {
90
+ static LOG_LEVEL = process.env["LOG_LEVEL"] ?? LogLevel[LogLevel.OFF];
91
+ constructor() {}
92
+ static debug(message) {
93
+ if (LogLevel[this.LOG_LEVEL] <= LogLevel.DEBUG) console.log(LOGGER_CONFIG.bgGreen, LOGGER_CONFIG.fgBlack, "DEBUG", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgGreen, message, LOGGER_CONFIG.reset);
94
+ }
95
+ static info(message) {
96
+ if (LogLevel[this.LOG_LEVEL] <= LogLevel.INFO) console.log(LOGGER_CONFIG.bgWhite, LOGGER_CONFIG.fgBlack, "INFO", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgWhite, message, LOGGER_CONFIG.reset);
97
+ }
98
+ static warn(message) {
99
+ if (LogLevel[this.LOG_LEVEL] <= LogLevel.WARN) console.log(LOGGER_CONFIG.bgYellow, LOGGER_CONFIG.fgBlack, "WARNING", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgYellow, message, LOGGER_CONFIG.reset);
100
+ }
101
+ static error(message) {
102
+ if (LogLevel[this.LOG_LEVEL] <= LogLevel.ERROR) console.log(LOGGER_CONFIG.bgRed, LOGGER_CONFIG.fgBlack, "ERROR", LOGGER_CONFIG.reset, LOGGER_CONFIG.fgRed, message, LOGGER_CONFIG.reset);
103
+ }
104
+ };
105
+
106
+ //#endregion
107
+ //#region src/__legacy__/utils/crypto-utils.ts
108
+ var NodeCryptoUtils = class {
109
+ constructor() {}
110
+ /**
111
+ * Get URL encoded string.
112
+ *
113
+ * @returns {string} base 64 url encoded value.
114
+ */
115
+ base64URLEncode(value) {
116
+ return base64url.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
117
+ }
118
+ base64URLDecode(value) {
119
+ return base64url.decode(value).toString();
120
+ }
121
+ hashSha256(data) {
122
+ return Buffer.from(sha256(new TextEncoder().encode(data)));
123
+ }
124
+ generateRandomBytes(length) {
125
+ return randombytes(length);
126
+ }
127
+ async verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance) {
128
+ const key = await jose.importJWK(jwk);
129
+ return jose.jwtVerify(idToken, key, {
130
+ algorithms,
131
+ audience: [clientId],
132
+ clockTolerance,
133
+ issuer,
134
+ subject
135
+ }).then(() => Promise.resolve(true));
136
+ }
137
+ };
138
+
139
+ //#endregion
140
+ //#region src/__legacy__/core/authentication.ts
141
+ var ThunderIDNodeCore = class ThunderIDNodeCore {
142
+ auth;
143
+ cryptoUtils;
144
+ store;
145
+ storageManager;
146
+ constructor(config, store) {
147
+ if (!store) this.store = new MemoryCacheStore();
148
+ else this.store = store;
149
+ this.cryptoUtils = new NodeCryptoUtils();
150
+ this.auth = new ThunderIDAuthClient();
151
+ this.auth.initialize(config, this.store, this.cryptoUtils);
152
+ this.storageManager = this.auth.getStorageManager();
153
+ Logger.debug("Initialized ThunderIDAuthClient successfully");
154
+ }
155
+ async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
156
+ if (!userId) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-SI-NF01", "No user ID was provided.", "Unable to sign in the user as no user ID was provided."));
157
+ if (await this.isSignedIn(userId)) {
158
+ const sessionData = await this.storageManager.getSessionData(userId);
159
+ return Promise.resolve({
160
+ accessToken: sessionData.access_token,
161
+ createdAt: sessionData.created_at,
162
+ expiresIn: sessionData.expires_in,
163
+ idToken: sessionData.id_token,
164
+ refreshToken: sessionData.refresh_token ?? "",
165
+ scope: sessionData.scope,
166
+ tokenType: sessionData.token_type
167
+ });
168
+ }
169
+ if (!authorizationCode || !state) {
170
+ if (!authURLCallback || typeof authURLCallback !== "function") return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-SI-NF02", "Invalid AuthURLCallback function.", "The AuthURLCallback is not defined or is not a function."));
171
+ authURLCallback(await this.getAuthURL(userId, signInConfig));
172
+ return Promise.resolve({
173
+ accessToken: "",
174
+ createdAt: 0,
175
+ expiresIn: "",
176
+ idToken: "",
177
+ refreshToken: "",
178
+ scope: "",
179
+ session: "",
180
+ tokenType: ""
181
+ });
182
+ }
183
+ return this.requestAccessToken(authorizationCode, sessionState ?? "", userId, state);
184
+ }
185
+ async getAuthURL(userId, signInConfig) {
186
+ const authURL = await this.auth.getSignInUrl(signInConfig, userId);
187
+ if (authURL) return Promise.resolve(authURL.toString());
188
+ return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-GAU-NF01", "Getting Authorization URL failed.", "No authorization URL was returned by the ThunderID Auth JS SDK."));
189
+ }
190
+ async requestAccessToken(authorizationCode, sessionState, userId, state) {
191
+ return this.auth.requestAccessToken(authorizationCode, sessionState, state, userId);
192
+ }
193
+ async getIdToken(userId) {
194
+ if (!await this.isSignedIn(userId)) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-GIT-NF01", "The user is not logged in.", "No session ID was found for the requested user. User is not logged in."));
195
+ const idToken = await this.auth.getIdToken(userId);
196
+ if (idToken) return Promise.resolve(idToken);
197
+ return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-GIT-NF02", "Requesting ID Token Failed", "No ID Token was returned by the ThunderID Auth JS SDK."));
198
+ }
199
+ async refreshAccessToken(userId) {
200
+ return this.auth.refreshAccessToken(userId);
201
+ }
202
+ async isSignedIn(userId) {
203
+ try {
204
+ if (!await this.auth.isSignedIn(userId)) return await Promise.resolve(false);
205
+ if (await SessionUtils.validateSession(await this.storageManager.getSessionData(userId))) return await Promise.resolve(true);
206
+ if (await this.refreshAccessToken(userId)) return await Promise.resolve(true);
207
+ this.storageManager.removeSessionData(userId);
208
+ this.storageManager.getTemporaryData(userId);
209
+ return await Promise.resolve(false);
210
+ } catch (error) {
211
+ return Promise.reject(error);
212
+ }
213
+ }
214
+ async signOut(userId) {
215
+ const signOutURL = await this.auth.getSignOutUrl(userId);
216
+ if (!signOutURL) return Promise.reject(new ThunderIDAuthException("NODE-AUTH_CORE-SO-NF01", "Signing out the user failed.", "Could not obtain the sign-out URL from the server."));
217
+ return Promise.resolve(signOutURL);
218
+ }
219
+ async getUser(userId) {
220
+ return this.auth.getUser(userId);
221
+ }
222
+ async getConfigData() {
223
+ return this.storageManager.getConfigData();
224
+ }
225
+ async getOpenIDProviderEndpoints() {
226
+ return this.auth.getOpenIDProviderEndpoints();
227
+ }
228
+ async getDecodedIdToken(userId, idToken) {
229
+ return this.auth.getDecodedIdToken(userId, idToken);
230
+ }
231
+ async getAccessToken(userId) {
232
+ return this.auth.getAccessToken(userId);
233
+ }
234
+ async exchangeToken(config, userId) {
235
+ return this.auth.exchangeToken(config, userId);
236
+ }
237
+ async reInitialize(config) {
238
+ return this.auth.reInitialize(config);
239
+ }
240
+ async revokeAccessToken(userId) {
241
+ return this.auth.revokeAccessToken(userId);
242
+ }
243
+ static didSignOutFail(afterSignOutUrl) {
244
+ return ThunderIDNodeCore.didSignOutFail(afterSignOutUrl);
245
+ }
246
+ static isSignOutSuccessful(afterSignOutUrl) {
247
+ return ThunderIDNodeCore.isSignOutSuccessful(afterSignOutUrl);
248
+ }
249
+ getStorageManager() {
250
+ return this.storageManager;
251
+ }
252
+ async decodeJwtToken(token) {
253
+ return this.auth.decodeJwtToken(token);
254
+ }
255
+ };
256
+
257
+ //#endregion
258
+ //#region src/__legacy__/client.ts
259
+ /**
260
+ * This class provides the necessary methods needed to implement authentication.
261
+ *
262
+ * @export
263
+ * @class ThunderIDNodeClient
264
+ */
265
+ var ThunderIDNodeClient = class ThunderIDNodeClient {
266
+ authCore;
267
+ /**
268
+ * This is the constructor method that returns an instance of the `ThunderIDNodeClient` class.
269
+ *
270
+ * @param {AuthClientConfig<T>} config - The configuration object.
271
+ * @param {Storage} store - The store object.
272
+ *
273
+ * @example
274
+ * ```
275
+ * const _store: Storage = new DataStore();
276
+ * const _config = {
277
+ afterSignInUrl: "http://localhost:3000/sign-in",
278
+ afterSignOutUrl: "http://localhost:3000/dashboard",
279
+ clientId: "client ID",
280
+ serverOrigin: "https://api.asgardeo.io/t/<org_name>"
281
+ };
282
+ * const auth = new ThunderIDNodeClient(_config,_store);
283
+ * ```
284
+ *
285
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#constructor
286
+ * @preserve
287
+ */
288
+ constructor() {}
289
+ async initialize(config, store) {
290
+ this.authCore = new ThunderIDNodeCore(config, store);
291
+ return Promise.resolve(true);
292
+ }
293
+ /**
294
+ * This method logs in a user. If the authorization code is not available it will resolve with the
295
+ * authorization URL to authorize the user.
296
+ * @param {string} authorizationCode - The authorization code obtained from ThunderID after a user signs in.
297
+ * @param {String} sessionState - The session state obtained from ThunderID after a user signs in.
298
+ * @param {string} userId - (Optional) A unique ID of the user to be authenticated. This is useful in multi-user
299
+ * scenarios where each user should be uniquely identified.
300
+ * @param {string} state - The state parameter in the redirect URL.
301
+ *
302
+ * @return {Promise<URLResponse | NodeTokenResponse>} - A Promise that resolves with the
303
+ * [`URLResponse`](#URLResponse) object or a Promise that resolves with
304
+ * the [`NodeTokenResponse`](#NodeTokenResponse) object.
305
+ *
306
+ * @example
307
+ * ```
308
+ * authClient.signIn(req.query.code, req.query.session_state).then(response => {
309
+ * //URL property will available if the user has not been authenticated already
310
+ * if (response.hasOwnProperty('url')) {
311
+ * res.redirect(response.url)
312
+ * } else {
313
+ * //Set the cookie
314
+ * res.cookie('ASGARDEO_SESSION_ID', response.session, { maxAge: 900000, httpOnly: true, SameSite: true });
315
+ * res.status(200).send(response)
316
+ * }
317
+ *});
318
+ * ```
319
+ *
320
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signIn
321
+ *
322
+ * @memberof ThunderIDNodeClient
323
+ *
324
+ */
325
+ async signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig) {
326
+ return this.authCore.signIn(authURLCallback, userId, authorizationCode, sessionState, state, signInConfig);
327
+ }
328
+ /**
329
+ * Method to get the configuration data.
330
+ *
331
+ * @returns {Promise<AuthClientConfig<Config>>} - A promise that resolves with the configuration data.
332
+ */
333
+ async getConfigData() {
334
+ return this.authCore.getConfigData();
335
+ }
336
+ /**
337
+ * This method clears all session data and returns the sign-out URL.
338
+ * @param {string} userId - The userId of the user. (If you are using ExpressJS,
339
+ * you may get this from the request cookies)
340
+ *
341
+ * @return {Promise<string>} - A Promise that resolves with the sign-out URL.
342
+ *
343
+ * @example
344
+ * ```
345
+ * const signOutUrl = await auth.signOut(userId);
346
+ * ```
347
+ *
348
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#signOut
349
+ *
350
+ * @memberof ThunderIDNodeClient
351
+ *
352
+ */
353
+ async signOut(userId) {
354
+ return this.authCore.signOut(userId);
355
+ }
356
+ /**
357
+ * This method returns a boolean value indicating if the user is authenticated or not.
358
+ * @param {string} userId - The userId of the user.
359
+ * (If you are using ExpressJS, you may get this from the request cookies)
360
+ *
361
+ * @return { Promise<boolean>} -A boolean value that indicates of the user is authenticated or not.
362
+ *
363
+ * @example
364
+ * ```
365
+ * const isAuth = await authClient.isSignedIn("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
366
+ * ```
367
+ *
368
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignedIn
369
+ *
370
+ * @memberof ThunderIDNodeClient
371
+ *
372
+ */
373
+ async isSignedIn(userId) {
374
+ return this.authCore.isSignedIn(userId);
375
+ }
376
+ /**
377
+ * This method returns the id token.
378
+ * @param {string} userId - The userId of the user.
379
+ * (If you are using ExpressJS, you may get this from the request cookies)
380
+ *
381
+ * @return {Promise<string>} -A Promise that resolves with the ID Token.
382
+ *
383
+ * @example
384
+ * ```
385
+ * const isAuth = await authClient.getIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
386
+ * ```
387
+ *
388
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
389
+ *
390
+ * @memberof ThunderIDNodeClient
391
+ *
392
+ */
393
+ async getIdToken(userId) {
394
+ return this.authCore.getIdToken(userId);
395
+ }
396
+ /**
397
+ * This method returns an object containing basic user information obtained from the id token.
398
+ * @param {string} userId - The userId of the user.
399
+ * (If you are using ExpressJS, you may get this from the request cookies)
400
+ *
401
+ * @return {Promise<string>} -A Promise that resolves with the
402
+ * An object containing basic user information obtained from the id token.
403
+ *
404
+ * @example
405
+ * ```
406
+ * const basicInfo = await authClient.getUser("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
407
+ * ```
408
+ *
409
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getUser
410
+ *
411
+ * @memberof ThunderIDNodeClient
412
+ *
413
+ */
414
+ async getUser(userId) {
415
+ return this.authCore.getUser(userId);
416
+ }
417
+ /**
418
+ * This method returns an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
419
+ * @return {Promise<OIDCEndpoints>} -A Promise that resolves with
420
+ * an object containing the OIDC service endpoints returned by the `.well-known` endpoint.
421
+ *
422
+ * @example
423
+ * ```
424
+ * const oidcEndpoints = await auth.getOpenIDProviderEndpoints();
425
+ * ```
426
+ *
427
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getOpenIDProviderEndpoints
428
+ *
429
+ * @memberof ThunderIDNodeClient
430
+ *
431
+ */
432
+ async getOpenIDProviderEndpoints() {
433
+ return this.authCore.getOpenIDProviderEndpoints();
434
+ }
435
+ /**
436
+ * This method returns the decoded ID token payload.
437
+ * @param {string} userId - The userId of the user.
438
+ * (If you are using ExpressJS, you may get this from the request cookies)
439
+ *
440
+ * @return {Promise<IdToken>} -A Promise that resolves with
441
+ * an object containing the decoded ID token payload.
442
+ *
443
+ * @example
444
+ * ```
445
+ * const decodedIDTokenPayload = await auth.getDecodedIdToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
446
+ * ```
447
+ *
448
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getDecodedIdToken
449
+ *
450
+ * @memberof ThunderIDNodeClient
451
+ *
452
+ */
453
+ async getDecodedIdToken(userId, idToken) {
454
+ return this.authCore.getDecodedIdToken(userId, idToken);
455
+ }
456
+ /**
457
+ * This method returns the access token.
458
+ * @param {string} userId - The userId of the user.
459
+ * (If you are using ExpressJS, you may get this from the request cookies)
460
+ *
461
+ * @return {Promise<string>} -A Promise that resolves with
462
+ * the access token stored in the store
463
+ *
464
+ * @example
465
+ * ```
466
+ *const accessToken = await auth.getAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
467
+ * ```
468
+ *
469
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getAccessToken
470
+ *
471
+ * @memberof ThunderIDNodeClient
472
+ *
473
+ */
474
+ async getAccessToken(userId) {
475
+ return this.authCore.getAccessToken(userId);
476
+ }
477
+ /**
478
+ * This method returns Promise that resolves with the token information
479
+ * or the response returned by the server depending on the configuration passed.
480
+ * @param {TokenExchangeRequestConfig} config - The config object contains attributes that would be used
481
+ * to configure the custom grant request.
482
+ *
483
+ * @param {string} userId - The userId of the user.
484
+ * (If you are using ExpressJS, you may get this from the request cookies)
485
+ *
486
+ * @return {Promise<TokenResponse | Response>} -A Promise that resolves with the token information
487
+ * or the response returned by the server depending on the configuration passed.
488
+ *
489
+ * @example
490
+ * ```
491
+ * const config = {
492
+ * attachToken: false,
493
+ * data: {
494
+ * client_id: "{{clientId}}",
495
+ * grant_type: "account_switch",
496
+ * scope: "{{scope}}",
497
+ * token: "{{token}}",
498
+ * },
499
+ * id: "account-switch",
500
+ * returnResponse: true,
501
+ * returnsSession: true,
502
+ * signInRequired: true
503
+ * }
504
+
505
+ * auth.exchangeToken(config).then((response)=>{
506
+ * console.log(response);
507
+ * }).catch((error)=>{
508
+ * console.error(error);
509
+ * });
510
+ * ```
511
+ *
512
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#exchangeToken
513
+ *
514
+ * @memberof ThunderIDNodeClient
515
+ *
516
+ */
517
+ async exchangeToken(config, userId) {
518
+ return this.authCore.exchangeToken(config, userId);
519
+ }
520
+ /**
521
+ * This method can be used to update the configurations passed into the constructor of the ThunderIDAuthClient.
522
+ * @param {AuthClientConfig<T>} config - The config object containing the attributes
523
+ * that can be used to configure the SDK
524
+ *
525
+ * @return {Promise<void>} -A Promise that resolves with a void.
526
+ *
527
+ * @example
528
+ * ```
529
+ * const reInitialize = await auth.reInitialize({
530
+ * afterSignOutUrl: "http://localhost:3000/sign-out"
531
+ * });
532
+ * ```
533
+ *
534
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#reInitialize
535
+ *
536
+ * @memberof ThunderIDNodeClient
537
+ *
538
+ */
539
+ async reInitialize(config) {
540
+ return this.authCore.reInitialize(config);
541
+ }
542
+ async getSignInUrl(requestConfig, userId) {
543
+ return this.authCore.getAuthURL(userId, requestConfig);
544
+ }
545
+ /**
546
+ * This method returns a Promise that resolves with the response returned by the server.
547
+ * @param {string} userId - The userId of the user.
548
+ * (If you are using ExpressJS, you may get this from the request cookies)
549
+ *
550
+ * @return {Promise<Response>} -A Promise that resolves with the response returned by the server.
551
+ *
552
+ * @example
553
+ * ```
554
+ * const revokeToken = await auth.revokeAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927");
555
+ * ```
556
+ *
557
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#revokeAccessToken
558
+ *
559
+ * @memberof ThunderIDNodeClient
560
+ *
561
+ */
562
+ async revokeAccessToken(userId) {
563
+ return this.authCore.revokeAccessToken(userId);
564
+ }
565
+ /**
566
+ * This method refreshes the access token and returns a Promise that resolves with the new access
567
+ * token and other relevant data.
568
+ *
569
+ * @param {string} userId - A unique ID of the user to be authenticated. This is useful in multi-user
570
+ * scenarios where each user should be uniquely identified.
571
+ *
572
+ * @returns {Promise<TokenResponse>} - A Promise that resolves with the token response.
573
+ *
574
+ * @example
575
+ * ```
576
+ * const tokenResponse = await auth.refreshAccessToken("a2a2972c-51cd-5e9d-a9ae-058fae9f7927")
577
+ * ```
578
+ *
579
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#refreshAccessToken
580
+ *
581
+ * @memberof ThunderIDNodeClient
582
+ */
583
+ refreshAccessToken(userId) {
584
+ return this.authCore.refreshAccessToken(userId);
585
+ }
586
+ /**
587
+ * This method returns if the user has been successfully signed out or not.
588
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
589
+ * after signing out from the server.
590
+ *
591
+ * @return {boolean} - A boolean value indicating if the user has been signed out or not.
592
+ *
593
+ * @example
594
+ * ```
595
+ * const isSignedOut = auth.isSignOutSuccessful(<signout_url>);;
596
+ * ```
597
+ *
598
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#isSignOutSuccessful
599
+ *
600
+ * @memberof ThunderIDNodeClient
601
+ *
602
+ */
603
+ static isSignOutSuccessful(afterSignOutUrl) {
604
+ return ThunderIDNodeClient.isSignOutSuccessful(afterSignOutUrl);
605
+ }
606
+ /**
607
+ * This method returns if sign-out failed or not
608
+ * @param {string} afterSignOutUrl - The URL to which the user is redirected to
609
+ * after signing out from the server.
610
+ *
611
+ * @return {boolean} - A boolean value indicating if sign-out failed or not.
612
+ *
613
+ * @example
614
+ * ```
615
+ * const isSignedOut = auth.isSignOutSuccessful(<signout_url>);
616
+ * ```
617
+ *
618
+ * @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#didSignOutFail
619
+ *
620
+ * @memberof ThunderIDNodeClient
621
+ *
622
+ */
623
+ static didSignOutFail(afterSignOutUrl) {
624
+ return ThunderIDNodeClient.didSignOutFail(afterSignOutUrl);
625
+ }
626
+ async getStorageManager() {
627
+ return this.authCore.getStorageManager();
628
+ }
629
+ async decodeJwtToken(token) {
630
+ return this.authCore.decodeJwtToken(token);
631
+ }
632
+ };
633
+
634
+ //#endregion
635
+ //#region src/constants/CookieConfig.ts
636
+ var CookieConfig = class {
637
+ static SESSION_COOKIE_NAME = `__${VendorConstants.VENDOR_PREFIX}__session`;
638
+ static TEMP_SESSION_COOKIE_NAME = `__${VendorConstants.VENDOR_PREFIX}__temp.session`;
639
+ static DEFAULT_MAX_AGE = 3600;
640
+ static DEFAULT_HTTP_ONLY = true;
641
+ static DEFAULT_SAME_SITE = "lax";
642
+ static DEFAULT_SECURE = true;
643
+ constructor() {}
644
+ };
645
+ var CookieConfig_default = CookieConfig;
646
+
647
+ //#endregion
648
+ //#region src/utils/generateSessionId.ts
649
+ /**
650
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
651
+ *
652
+ * WSO2 LLC. licenses this file to you under the Apache License,
653
+ * Version 2.0 (the "License"); you may not use this file except
654
+ * in compliance with the License.
655
+ * You may obtain a copy of the License at
656
+ *
657
+ * http://www.apache.org/licenses/LICENSE-2.0
658
+ *
659
+ * Unless required by applicable law or agreed to in writing,
660
+ * software distributed under the License is distributed on an
661
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
662
+ * KIND, either express or implied. See the License for the
663
+ * specific language governing permissions and limitations
664
+ * under the License.
665
+ */
666
+ const generateSessionId = () => (/* @__PURE__ */ new Date()).getTime().toString(36) + Math.random().toString(36).substring(2);
667
+ var generateSessionId_default = generateSessionId;
668
+
669
+ //#endregion
670
+ //#region src/utils/getSessionCookieOptions.ts
671
+ /**
672
+ * Creates a complete set of cookie options by merging provided options with defaults
673
+ *
674
+ * @param options - Partial cookie options to override defaults
675
+ *
676
+ * @returns Complete cookie options with all required fields
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * // Use defaults with only maxAge override
681
+ * const options = getSessionCookieOptions({ maxAge: 3600 });
682
+ *
683
+ * // Override multiple defaults
684
+ * const options = getSessionCookieOptions({
685
+ * maxAge: 3600,
686
+ * secure: true,
687
+ * sameSite: 'strict'
688
+ * });
689
+ * ```
690
+ */
691
+ const getSessionCookieOptions = (options) => ({
692
+ ...options,
693
+ httpOnly: options.httpOnly ?? CookieConfig_default.DEFAULT_HTTP_ONLY,
694
+ maxAge: options.maxAge ?? CookieConfig_default.DEFAULT_MAX_AGE,
695
+ sameSite: options.sameSite ?? CookieConfig_default.DEFAULT_SAME_SITE,
696
+ secure: options.secure ?? CookieConfig_default.DEFAULT_SECURE
697
+ });
698
+ var getSessionCookieOptions_default = getSessionCookieOptions;
699
+
700
+ //#endregion
701
+ //#region src/ThunderIDNodeClient.ts
702
+ /**
703
+ * Base class for implementing ThunderID in Node.js based applications.
704
+ * This class provides the core functionality for managing user authentication and sessions.
705
+ *getConfigData
706
+ * @typeParam T - Configuration type that extends ThunderIDNodeConfig.
707
+ */
708
+ var ThunderIDNodeClient$1 = class extends ThunderIDJavaScriptClient {};
709
+ var ThunderIDNodeClient_default = ThunderIDNodeClient$1;
710
+
711
+ //#endregion
712
+ //#region src/index.ts
713
+ if (!globalThis.fetch) {
714
+ globalThis.fetch = fetch;
715
+ globalThis.Headers = Headers;
716
+ globalThis.Request = Request;
717
+ globalThis.Response = Response;
718
+ }
719
+
720
+ //#endregion
721
+ export { CookieConfig_default as CookieConfig, CookieOptions, ThunderIDNodeClient as LegacyThunderIDNodeClient, Logger, ThunderIDNodeClient_default as ThunderIDNodeClient, ThunderIDNodeConfig, generateSessionId_default as generateSessionId, getSessionCookieOptions_default as getSessionCookieOptions };