@thunderid/node 0.0.3 → 0.0.6

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 (47) hide show
  1. package/dist/ThunderIDNodeClient.d.ts +18 -8
  2. package/dist/ThunderIDNodeClient.d.ts.map +1 -1
  3. package/dist/cjs/index.cjs +125 -592
  4. package/dist/index.d.ts +9 -6
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +123 -579
  7. package/dist/{__legacy__/constants/logger-config.d.ts → models/AuthURLCallback.d.ts} +9 -15
  8. package/dist/models/AuthURLCallback.d.ts.map +1 -0
  9. package/dist/models/config.d.ts +27 -14
  10. package/dist/models/config.d.ts.map +1 -1
  11. package/dist/{__legacy__/stores/memory-cache-store.d.ts → stores/MemoryCacheStore.d.ts} +7 -2
  12. package/dist/stores/MemoryCacheStore.d.ts.map +1 -0
  13. package/dist/{__legacy__/utils/crypto-utils.d.ts → utils/NodeCryptoUtils.d.ts} +7 -8
  14. package/dist/utils/NodeCryptoUtils.d.ts.map +1 -0
  15. package/dist/{__legacy__/utils/session-utils.d.ts → utils/SessionUtils.d.ts} +21 -2
  16. package/dist/utils/SessionUtils.d.ts.map +1 -0
  17. package/dist/utils/getSessionCookieOptions.d.ts +2 -22
  18. package/dist/utils/getSessionCookieOptions.d.ts.map +1 -1
  19. package/package.json +5 -5
  20. package/dist/__legacy__/client.d.ts +0 -355
  21. package/dist/__legacy__/client.d.ts.map +0 -1
  22. package/dist/__legacy__/constants/index.d.ts +0 -20
  23. package/dist/__legacy__/constants/index.d.ts.map +0 -1
  24. package/dist/__legacy__/constants/logger-config.d.ts.map +0 -1
  25. package/dist/__legacy__/constants/uuid-config.d.ts +0 -19
  26. package/dist/__legacy__/constants/uuid-config.d.ts.map +0 -1
  27. package/dist/__legacy__/core/authentication.d.ts +0 -46
  28. package/dist/__legacy__/core/authentication.d.ts.map +0 -1
  29. package/dist/__legacy__/core/index.d.ts +0 -19
  30. package/dist/__legacy__/core/index.d.ts.map +0 -1
  31. package/dist/__legacy__/models/index.d.ts +0 -20
  32. package/dist/__legacy__/models/index.d.ts.map +0 -1
  33. package/dist/__legacy__/models/session-data.d.ts +0 -23
  34. package/dist/__legacy__/models/session-data.d.ts.map +0 -1
  35. package/dist/__legacy__/models/url-callback.d.ts +0 -19
  36. package/dist/__legacy__/models/url-callback.d.ts.map +0 -1
  37. package/dist/__legacy__/stores/index.d.ts +0 -19
  38. package/dist/__legacy__/stores/index.d.ts.map +0 -1
  39. package/dist/__legacy__/stores/memory-cache-store.d.ts.map +0 -1
  40. package/dist/__legacy__/utils/crypto-utils.d.ts.map +0 -1
  41. package/dist/__legacy__/utils/index.d.ts +0 -20
  42. package/dist/__legacy__/utils/index.d.ts.map +0 -1
  43. package/dist/__legacy__/utils/logger-utils.d.ts +0 -26
  44. package/dist/__legacy__/utils/logger-utils.d.ts.map +0 -1
  45. package/dist/__legacy__/utils/session-utils.d.ts.map +0 -1
  46. package/dist/models/cookies.d.ts +0 -59
  47. package/dist/models/cookies.d.ts.map +0 -1
@@ -27,8 +27,6 @@ let __thunderid_javascript = require("@thunderid/javascript");
27
27
  __thunderid_javascript = __toESM(__thunderid_javascript);
28
28
  let memory_cache = require("memory-cache");
29
29
  memory_cache = __toESM(memory_cache);
30
- let uuid = require("uuid");
31
- uuid = __toESM(uuid);
32
30
  let base64url = require("base64url");
33
31
  base64url = __toESM(base64url);
34
32
  let fast_sha256 = require("fast-sha256");
@@ -37,8 +35,14 @@ let jose = require("jose");
37
35
  jose = __toESM(jose);
38
36
  let secure_random_bytes = require("secure-random-bytes");
39
37
  secure_random_bytes = __toESM(secure_random_bytes);
38
+ let uuid = require("uuid");
39
+ uuid = __toESM(uuid);
40
40
 
41
- //#region src/__legacy__/stores/memory-cache-store.ts
41
+ //#region src/stores/MemoryCacheStore.ts
42
+ /**
43
+ * In-memory key-value store backed by `memory-cache`.
44
+ * Used as the default storage when no custom store is provided to `ThunderIDNodeClient`.
45
+ */
42
46
  var MemoryCacheStore = class {
43
47
  async setData(key, value) {
44
48
  memory_cache.default.put(key, value);
@@ -50,97 +54,15 @@ var MemoryCacheStore = class {
50
54
  memory_cache.default.del(key);
51
55
  }
52
56
  };
57
+ var MemoryCacheStore_default = MemoryCacheStore;
53
58
 
54
59
  //#endregion
55
- //#region src/__legacy__/constants/uuid-config.ts
60
+ //#region src/utils/NodeCryptoUtils.ts
56
61
  /**
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.
62
+ * Node.js crypto utilities implementing the `Crypto` interface.
63
+ * Uses `jose`, `base64url`, `fast-sha256`, and `secure-random-bytes`.
72
64
  */
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
65
  var NodeCryptoUtils = class {
138
- constructor() {}
139
- /**
140
- * Get URL encoded string.
141
- *
142
- * @returns {string} base 64 url encoded value.
143
- */
144
66
  base64URLEncode(value) {
145
67
  return base64url.default.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
146
68
  }
@@ -164,40 +86,83 @@ var NodeCryptoUtils = class {
164
86
  }).then(() => Promise.resolve(true));
165
87
  }
166
88
  };
89
+ var NodeCryptoUtils_default = NodeCryptoUtils;
167
90
 
168
91
  //#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");
92
+ //#region src/utils/SessionUtils.ts
93
+ const UUID_VERSION = 4;
94
+ /**
95
+ * Utility class for session validation and UUID management.
96
+ */
97
+ var SessionUtils = class {
98
+ constructor() {}
99
+ /**
100
+ * Generates a new UUID v4 string.
101
+ *
102
+ * @returns A new UUID string.
103
+ */
104
+ static createUUID() {
105
+ return (0, uuid.v4)();
106
+ }
107
+ /**
108
+ * Returns `true` if the given string is a valid UUID v4.
109
+ *
110
+ * @param uuid - The UUID string to validate.
111
+ */
112
+ static validateUUID(uuid$1) {
113
+ if ((0, uuid.validate)(uuid$1) && (0, uuid.version)(uuid$1) === UUID_VERSION) return Promise.resolve(true);
114
+ return Promise.resolve(false);
183
115
  }
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."));
116
+ /**
117
+ * Returns `true` if the session token is still within its validity window.
118
+ *
119
+ * @param sessionData - The session data to check.
120
+ */
121
+ static validateSession(sessionData) {
122
+ const currentTime = Date.now();
123
+ const expiryTimeStamp = sessionData.created_at + parseInt(sessionData.expires_in, 10) * 60 * 1e3;
124
+ return Promise.resolve(currentTime < expiryTimeStamp);
125
+ }
126
+ };
127
+ var SessionUtils_default = SessionUtils;
128
+
129
+ //#endregion
130
+ //#region src/ThunderIDNodeClient.ts
131
+ var ThunderIDNodeClient = class extends __thunderid_javascript.ThunderIDJavaScriptClient {
132
+ _nodeInstanceId = 0;
133
+ constructor(instanceId = 0) {
134
+ super(void 0, new NodeCryptoUtils_default());
135
+ this._nodeInstanceId = instanceId;
136
+ }
137
+ async initialize(config, storage) {
138
+ const merged = {
139
+ ...config,
140
+ instanceId: this._nodeInstanceId
141
+ };
142
+ const store = storage ?? new MemoryCacheStore_default();
143
+ return super.initialize(merged, store);
144
+ }
145
+ getInstanceId() {
146
+ return this._nodeInstanceId;
147
+ }
148
+ async signIn(...args) {
149
+ const [authURLCallback, userId, authorizationCode, sessionState, state, signInConfig] = args;
150
+ if (!userId) return Promise.reject(new __thunderid_javascript.ThunderIDAuthException("NODE-AUTH_CLIENT-SI-NF01", "No user ID was provided.", "Unable to sign in the user as no user ID was provided."));
186
151
  if (await this.isSignedIn(userId)) {
187
- const sessionData = await this.storageManager.getSessionData(userId);
152
+ const sessionData$1 = await this.getStorageManager().getSessionData(userId);
188
153
  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
154
+ accessToken: sessionData$1.access_token,
155
+ createdAt: sessionData$1.created_at,
156
+ expiresIn: sessionData$1.expires_in,
157
+ idToken: sessionData$1.id_token,
158
+ refreshToken: sessionData$1.refresh_token ?? "",
159
+ scope: sessionData$1.scope,
160
+ tokenType: sessionData$1.token_type
196
161
  });
197
162
  }
198
163
  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));
164
+ if (!authURLCallback || typeof authURLCallback !== "function") return Promise.reject(new __thunderid_javascript.ThunderIDAuthException("NODE-AUTH_CLIENT-SI-NF02", "Invalid AuthURLCallback function.", "The AuthURLCallback is not defined or is not a function."));
165
+ authURLCallback(await this.getSignInUrl(signInConfig, userId));
201
166
  return Promise.resolve({
202
167
  accessToken: "",
203
168
  createdAt: 0,
@@ -205,460 +170,72 @@ var ThunderIDNodeCore = class ThunderIDNodeCore {
205
170
  idToken: "",
206
171
  refreshToken: "",
207
172
  scope: "",
208
- session: "",
209
173
  tokenType: ""
210
174
  });
211
175
  }
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);
176
+ await this.requestAccessToken(authorizationCode, sessionState ?? "", state, userId);
177
+ const sessionData = await this.getStorageManager().getSessionData(userId);
178
+ return Promise.resolve({
179
+ accessToken: sessionData.access_token,
180
+ createdAt: sessionData.created_at,
181
+ expiresIn: sessionData.expires_in,
182
+ idToken: sessionData.id_token,
183
+ refreshToken: sessionData.refresh_token ?? "",
184
+ scope: sessionData.scope,
185
+ tokenType: sessionData.token_type
186
+ });
221
187
  }
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."));
188
+ async getSignInUrl(requestConfig, userId) {
189
+ const url = await super.getSignInUrl(requestConfig, userId);
190
+ if (!url) return Promise.reject(new __thunderid_javascript.ThunderIDAuthException("NODE-AUTH_CLIENT-GSIU-NF01", "Getting authorization URL failed.", "No authorization URL was returned."));
191
+ return url;
227
192
  }
228
- async refreshAccessToken(userId) {
229
- return this.auth.refreshAccessToken(userId);
193
+ async signOut(...args) {
194
+ const userId = typeof args[0] === "string" ? args[0] : void 0;
195
+ const signOutUrl = await this.getSignOutUrl(userId);
196
+ if (!signOutUrl) return Promise.reject(new __thunderid_javascript.ThunderIDAuthException("NODE-AUTH_CLIENT-SO-NF01", "Signing out the user failed.", "Could not obtain the sign-out URL from the server."));
197
+ return signOutUrl;
230
198
  }
231
199
  async isSignedIn(userId) {
232
200
  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);
201
+ if (!await super.isSignedIn(userId)) return false;
202
+ const sm = this.getStorageManager();
203
+ const sessionData = await sm.getSessionData(userId);
204
+ if (await SessionUtils_default.validateSession(sessionData)) return true;
205
+ if (await this.refreshAccessToken(userId)) return true;
206
+ await sm.removeSessionData(userId);
207
+ return false;
208
+ } catch {
209
+ return false;
241
210
  }
242
211
  }
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);
212
+ async getIdToken(userId) {
213
+ if (!await this.isSignedIn(userId)) return Promise.reject(new __thunderid_javascript.ThunderIDAuthException("NODE-AUTH_CLIENT-GIT-NF01", "The user is not logged in.", "No session was found for the requested user."));
214
+ return super.getIdToken(userId);
250
215
  }
251
- async getConfigData() {
252
- return this.storageManager.getConfigData();
216
+ async refreshAccessToken(userId) {
217
+ return super.refreshAccessToken(userId);
253
218
  }
254
- async getOpenIDProviderEndpoints() {
255
- return this.auth.getOpenIDProviderEndpoints();
219
+ async revokeAccessToken(userId) {
220
+ return super.revokeAccessToken(userId);
256
221
  }
257
222
  async getDecodedIdToken(userId, idToken) {
258
- return this.auth.getDecodedIdToken(userId, idToken);
223
+ return super.getDecodedIdToken(userId, idToken);
259
224
  }
260
225
  async getAccessToken(userId) {
261
- return this.auth.getAccessToken(userId);
262
- }
263
- async exchangeToken(config, userId) {
264
- return this.auth.exchangeToken(config, userId);
226
+ return super.getAccessToken(userId);
265
227
  }
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
228
  async getUser(userId) {
444
- return this.authCore.getUser(userId);
229
+ return super.getUser(userId);
445
230
  }
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
231
  async getOpenIDProviderEndpoints() {
462
- return this.authCore.getOpenIDProviderEndpoints();
232
+ return super.getOpenIDProviderEndpoints();
463
233
  }
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
234
  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);
235
+ return super.exchangeToken(config, userId);
660
236
  }
661
237
  };
238
+ var ThunderIDNodeClient_default = ThunderIDNodeClient;
662
239
 
663
240
  //#endregion
664
241
  //#region src/constants/CookieConfig.ts
@@ -697,46 +274,13 @@ var generateSessionId_default = generateSessionId;
697
274
 
698
275
  //#endregion
699
276
  //#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
277
  const getSessionCookieOptions = (options) => ({
721
- ...options,
722
278
  httpOnly: options.httpOnly ?? CookieConfig_default.DEFAULT_HTTP_ONLY,
723
- maxAge: options.maxAge ?? CookieConfig_default.DEFAULT_MAX_AGE,
724
279
  sameSite: options.sameSite ?? CookieConfig_default.DEFAULT_SAME_SITE,
725
280
  secure: options.secure ?? CookieConfig_default.DEFAULT_SECURE
726
281
  });
727
282
  var getSessionCookieOptions_default = getSessionCookieOptions;
728
283
 
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
284
  //#endregion
741
285
  //#region src/index.ts
742
286
  if (!globalThis.fetch) {
@@ -748,21 +292,10 @@ if (!globalThis.fetch) {
748
292
 
749
293
  //#endregion
750
294
  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;
295
+ exports.MemoryCacheStore = MemoryCacheStore_default;
296
+ exports.NodeCryptoUtils = NodeCryptoUtils_default;
297
+ exports.SessionUtils = SessionUtils_default;
759
298
  exports.ThunderIDNodeClient = ThunderIDNodeClient_default;
760
- Object.defineProperty(exports, 'ThunderIDNodeConfig', {
761
- enumerable: true,
762
- get: function () {
763
- return ThunderIDNodeConfig;
764
- }
765
- });
766
299
  exports.generateSessionId = generateSessionId_default;
767
300
  exports.getSessionCookieOptions = getSessionCookieOptions_default;
768
301
  Object.keys(__thunderid_javascript).forEach(function (k) {