@auth0/auth0-server-js 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  AbstractStateStore: () => AbstractStateStore,
24
24
  AbstractTransactionStore: () => AbstractTransactionStore,
25
25
  BackchannelLogoutError: () => BackchannelLogoutError,
26
+ ChangePasswordError: () => import_auth0_auth_js4.ChangePasswordError,
26
27
  CookieTransactionStore: () => CookieTransactionStore,
27
28
  InvalidConfigurationError: () => InvalidConfigurationError,
28
29
  IssuerValidationError: () => IssuerValidationError,
@@ -30,22 +31,25 @@ __export(index_exports, {
30
31
  MfaEnrollmentError: () => import_auth0_auth_js2.MfaEnrollmentError,
31
32
  MfaListAuthenticatorsError: () => import_auth0_auth_js2.MfaListAuthenticatorsError,
32
33
  MfaVerifyError: () => import_auth0_auth_js2.MfaVerifyError,
33
- MissingClientAuthError: () => import_auth0_auth_js4.MissingClientAuthError,
34
+ MissingClientAuthError: () => import_auth0_auth_js5.MissingClientAuthError,
34
35
  MissingRequiredArgumentError: () => MissingRequiredArgumentError,
35
36
  MissingSessionError: () => MissingSessionError,
36
37
  MissingTransactionError: () => MissingTransactionError,
37
- OrganizationValidationError: () => import_auth0_auth_js4.OrganizationValidationError,
38
+ OrganizationValidationError: () => import_auth0_auth_js5.OrganizationValidationError,
38
39
  PasskeyChallengeError: () => import_auth0_auth_js3.PasskeyChallengeError,
39
40
  PasskeyGetTokenError: () => import_auth0_auth_js3.PasskeyGetTokenError,
40
41
  PasskeyRegisterError: () => import_auth0_auth_js3.PasskeyRegisterError,
41
42
  ServerClient: () => ServerClient,
43
+ ServerDatabaseClient: () => ServerDatabaseClient,
42
44
  ServerMfaClient: () => ServerMfaClient,
43
45
  ServerPasskeyClient: () => ServerPasskeyClient,
44
46
  SessionExpiredError: () => SessionExpiredError,
47
+ SignUpError: () => import_auth0_auth_js4.SignUpError,
45
48
  StartLinkUserError: () => StartLinkUserError,
46
49
  StatefulStateStore: () => StatefulStateStore,
47
50
  StatelessStateStore: () => StatelessStateStore,
48
- TokenExchangeError: () => import_auth0_auth_js4.TokenExchangeError,
51
+ TokenExchangeError: () => import_auth0_auth_js5.TokenExchangeError,
52
+ TokenRevocationError: () => import_auth0_auth_js5.TokenRevocationError,
49
53
  isMfaRequiredError: () => import_auth0_auth_js2.isMfaRequiredError
50
54
  });
51
55
  module.exports = __toCommonJS(index_exports);
@@ -250,7 +254,7 @@ function getTelemetryConfig(config) {
250
254
  return {
251
255
  enabled: true,
252
256
  name: config?.name ?? "@auth0/auth0-server-js",
253
- version: config?.version ?? "1.9.0"
257
+ version: config?.version ?? "1.10.0"
254
258
  };
255
259
  }
256
260
 
@@ -429,6 +433,53 @@ var ServerPasskeyClient = class {
429
433
  }
430
434
  };
431
435
 
436
+ // src/database/server-database-client.ts
437
+ var ServerDatabaseClient = class {
438
+ #options;
439
+ /**
440
+ * @internal
441
+ */
442
+ constructor(options) {
443
+ this.#options = options;
444
+ }
445
+ /**
446
+ * Registers a new user in a database connection.
447
+ *
448
+ * Delegates to the underlying `AuthClient.database.signUp` without any session
449
+ * state modification. The caller is responsible for handling the returned user
450
+ * data as needed.
451
+ *
452
+ * @param options The signup options (email, password, connection, etc.).
453
+ * @param storeOptions Optional options used to resolve the domain (resolver mode).
454
+ *
455
+ * @throws {SignUpError} If there was an issue signing the user up.
456
+ *
457
+ * @returns A promise resolving to the created user result with a normalized `id` field.
458
+ */
459
+ async signUp(options, storeOptions) {
460
+ const domain = await this.#options.resolveDomain(storeOptions);
461
+ return this.#options.getAuthClient(domain).database.signUp(options);
462
+ }
463
+ /**
464
+ * Requests a password-change email for a database connection user.
465
+ *
466
+ * Delegates to the underlying `AuthClient.database.changePassword` without any
467
+ * session state modification. The caller is responsible for informing the user
468
+ * of the sent email as needed.
469
+ *
470
+ * @param options The password change options (email, connection, organization, etc.).
471
+ * @param storeOptions Optional options used to resolve the domain (resolver mode).
472
+ *
473
+ * @throws {ChangePasswordError} If there was an issue requesting the password change.
474
+ *
475
+ * @returns A promise resolving to the server's plain-text confirmation message.
476
+ */
477
+ async changePassword(options, storeOptions) {
478
+ const domain = await this.#options.resolveDomain(storeOptions);
479
+ return this.#options.getAuthClient(domain).database.changePassword(options);
480
+ }
481
+ };
482
+
432
483
  // src/server-client.ts
433
484
  var normalizeDomain = (value) => {
434
485
  const trimmed = value.trim();
@@ -454,6 +505,7 @@ var ServerClient = class {
454
505
  #authClient;
455
506
  #mfaClient;
456
507
  #passkeyClient;
508
+ #databaseClient;
457
509
  /**
458
510
  * The underlying `authClient` instance that can be used to interact with the Auth0 Authentication API.
459
511
  * Generally, you should prefer to use the higher-level methods exposed on the `ServerClient` instance.
@@ -501,6 +553,21 @@ var ServerClient = class {
501
553
  get passkey() {
502
554
  return this.#passkeyClient;
503
555
  }
556
+ /**
557
+ * The database client for self-service sign-up and password-change requests
558
+ * against an Auth0 database connection.
559
+ *
560
+ * Provides `signUp()` to register a user and `changePassword()` to request a
561
+ * password-reset email. Both are pure passthrough operations to the Auth0
562
+ * Authentication API — they never read or write the session/state store.
563
+ *
564
+ * Like `passkey`, this property is available in both static and resolver
565
+ * (multi-tenant) domain modes. In resolver mode, pass `storeOptions` so the
566
+ * request resolves the intended tenant.
567
+ */
568
+ get database() {
569
+ return this.#databaseClient;
570
+ }
504
571
  constructor(options) {
505
572
  this.#options = options;
506
573
  this.#stateStoreIdentifier = this.#options.stateIdentifier || "__a0_session";
@@ -550,6 +617,10 @@ var ServerClient = class {
550
617
  defaultScope: this.#options.authorizationParams?.scope,
551
618
  defaultAudience: this.#options.authorizationParams?.audience
552
619
  });
620
+ this.#databaseClient = new ServerDatabaseClient({
621
+ resolveDomain: (storeOptions) => this.#resolveDomain(storeOptions),
622
+ getAuthClient: (domain) => this.#getAuthClient(domain)
623
+ });
553
624
  }
554
625
  async #resolveDomain(storeOptions) {
555
626
  if (typeof this.#options.domain === "function") {
@@ -1215,6 +1286,47 @@ var ServerClient = class {
1215
1286
  loginHint: options.loginHint
1216
1287
  };
1217
1288
  }
1289
+ /**
1290
+ * Revokes the refresh token stored in the current session, or an explicitly supplied token.
1291
+ *
1292
+ * In resolver mode, revocation only occurs when the session domain matches the domain resolved
1293
+ * for the current request. If the domains differ (or the session has no stored domain), the call
1294
+ * returns without revoking to avoid sending a token to the wrong tenant. This guard applies even
1295
+ * when a token is passed explicitly via `options.token`.
1296
+ *
1297
+ * @param options Optionally supply a token to revoke instead of reading from the session.
1298
+ * @param storeOptions Optional options passed to the StateStore.
1299
+ *
1300
+ * @throws {MissingRequiredArgumentError} If `options.token` is an empty string.
1301
+ * @throws {MissingSessionError} If no refresh token is found in the session and none was provided.
1302
+ * @throws {TokenRevocationError} If the revocation request fails.
1303
+ */
1304
+ async revokeRefreshToken(options = {}, storeOptions) {
1305
+ if (options.token !== void 0 && options.token.length === 0) {
1306
+ throw new MissingRequiredArgumentError("options.token must not be an empty string.");
1307
+ }
1308
+ let refreshToken = options.token;
1309
+ const needsStateData = !refreshToken || this.#isResolverMode();
1310
+ const stateData = needsStateData ? await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions) : void 0;
1311
+ if (!refreshToken) {
1312
+ refreshToken = stateData?.refreshToken;
1313
+ }
1314
+ if (!refreshToken) {
1315
+ throw new MissingSessionError("Unable to revoke refresh token: no refresh token found in session.");
1316
+ }
1317
+ let authClient;
1318
+ if (this.#isResolverMode()) {
1319
+ const resolvedDomain = await this.#resolveDomain(storeOptions);
1320
+ const sessionDomain = stateData ? this.#getSessionDomain(stateData) : void 0;
1321
+ if (stateData && sessionDomain !== resolvedDomain) {
1322
+ return;
1323
+ }
1324
+ authClient = this.#getAuthClient(sessionDomain ?? resolvedDomain);
1325
+ } else {
1326
+ authClient = this.authClient;
1327
+ }
1328
+ await authClient.revokeToken({ token: refreshToken, tokenTypeHint: "refresh_token" });
1329
+ }
1218
1330
  /**
1219
1331
  * Logs the user out and returns a URL to redirect the user-agent to after they log out.
1220
1332
  * @param options Options used to configure the logout process.
@@ -1223,17 +1335,26 @@ var ServerClient = class {
1223
1335
  */
1224
1336
  async logout(options, storeOptions) {
1225
1337
  if (!this.#isResolverMode()) {
1338
+ try {
1339
+ await this.revokeRefreshToken({}, storeOptions);
1340
+ } catch {
1341
+ }
1226
1342
  await this.#stateStore.delete(this.#stateStoreIdentifier, storeOptions);
1227
1343
  return this.authClient.buildLogoutUrl(options);
1228
1344
  }
1229
1345
  const resolvedDomain = await this.#resolveDomain(storeOptions);
1230
1346
  const authClient = this.#getAuthClient(resolvedDomain);
1231
1347
  const stateData = await this.#stateStore.get(this.#stateStoreIdentifier, storeOptions);
1232
- const sessionDomain = stateData ? this.#getSessionDomain(stateData) : void 0;
1233
1348
  if (!stateData) {
1234
1349
  return authClient.buildLogoutUrl(options);
1235
1350
  }
1236
- if (sessionDomain && sessionDomain === resolvedDomain) {
1351
+ const sessionDomain = this.#getSessionDomain(stateData);
1352
+ const domainMatches = sessionDomain === resolvedDomain;
1353
+ if (domainMatches) {
1354
+ try {
1355
+ await this.revokeRefreshToken({}, storeOptions);
1356
+ } catch {
1357
+ }
1237
1358
  await this.#stateStore.delete(this.#stateStoreIdentifier, storeOptions);
1238
1359
  }
1239
1360
  return authClient.buildLogoutUrl(options);
@@ -1451,7 +1572,7 @@ var AbstractTransactionStore = class extends AbstractStore {
1451
1572
  };
1452
1573
 
1453
1574
  // src/index.ts
1454
- var import_auth0_auth_js4 = require("@auth0/auth0-auth-js");
1575
+ var import_auth0_auth_js5 = require("@auth0/auth0-auth-js");
1455
1576
 
1456
1577
  // src/store/cookie-transaction-store.ts
1457
1578
  var CookieTransactionStore = class extends AbstractTransactionStore {
@@ -1652,11 +1773,15 @@ var import_auth0_auth_js2 = require("@auth0/auth0-auth-js");
1652
1773
 
1653
1774
  // src/passkey/index.ts
1654
1775
  var import_auth0_auth_js3 = require("@auth0/auth0-auth-js");
1776
+
1777
+ // src/database/index.ts
1778
+ var import_auth0_auth_js4 = require("@auth0/auth0-auth-js");
1655
1779
  // Annotate the CommonJS export names for ESM import in node:
1656
1780
  0 && (module.exports = {
1657
1781
  AbstractStateStore,
1658
1782
  AbstractTransactionStore,
1659
1783
  BackchannelLogoutError,
1784
+ ChangePasswordError,
1660
1785
  CookieTransactionStore,
1661
1786
  InvalidConfigurationError,
1662
1787
  IssuerValidationError,
@@ -1673,13 +1798,16 @@ var import_auth0_auth_js3 = require("@auth0/auth0-auth-js");
1673
1798
  PasskeyGetTokenError,
1674
1799
  PasskeyRegisterError,
1675
1800
  ServerClient,
1801
+ ServerDatabaseClient,
1676
1802
  ServerMfaClient,
1677
1803
  ServerPasskeyClient,
1678
1804
  SessionExpiredError,
1805
+ SignUpError,
1679
1806
  StartLinkUserError,
1680
1807
  StatefulStateStore,
1681
1808
  StatelessStateStore,
1682
1809
  TokenExchangeError,
1810
+ TokenRevocationError,
1683
1811
  isMfaRequiredError
1684
1812
  });
1685
1813
  //# sourceMappingURL=index.cjs.map