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