@fonderie/auth 7.17.0 → 7.17.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.
package/dist/index.cjs CHANGED
@@ -357,8 +357,8 @@ function issueMfaPendingToken(userId, config, loginMethod) {
357
357
  );
358
358
  }
359
359
  function issueTokenPair(userId, config, options) {
360
- const duration = config.sessionDuration ?? DEFAULT_SESSION_DURATION;
361
- const accessDuration = config.accessTokenDuration ?? DEFAULT_ACCESS_TOKEN_DURATION;
360
+ const duration = validDuration(config.sessionDuration, DEFAULT_SESSION_DURATION, "sessionDuration");
361
+ const accessDuration = validDuration(config.accessTokenDuration, DEFAULT_ACCESS_TOKEN_DURATION, "accessTokenDuration");
362
362
  const authTime = options.authTime ?? Math.floor(Date.now() / 1e3);
363
363
  const loginMethod = options.loginMethod;
364
364
  const phoneVerified = options.phoneVerified ?? false;
@@ -401,6 +401,17 @@ function durationMs(value) {
401
401
  const scale = { ms: 1, s: 1e3, m: 6e4, h: 36e5, d: 864e5, w: 6048e5, y: 315576e5 };
402
402
  return Number(m[1]) * (scale[unit] ?? 1e3);
403
403
  }
404
+ var warnedDurations = /* @__PURE__ */ new Set();
405
+ function validDuration(value, fallback, name) {
406
+ if (value === void 0 || value === null || value === "") return fallback;
407
+ if (durationMs(String(value)) !== null) return String(value);
408
+ const key = `${name}=${String(value)}`;
409
+ if (!warnedDurations.has(key)) {
410
+ warnedDurations.add(key);
411
+ console.warn(`[auth] ${name} ${JSON.stringify(value)} is not a duration (e.g. '90d', '1h') \u2014 using ${fallback}`);
412
+ }
413
+ return fallback;
414
+ }
404
415
 
405
416
  // src/services/mfa.ts
406
417
  var import_node_crypto2 = require("crypto");
@@ -2015,7 +2026,7 @@ function authController(store, config, bus, locales = (0, import_core6.defineLoc
2015
2026
  return (0, import_core6.setApiResponse)(import_core6.HTTP.UNAUTHORIZED, "TOKEN_REFRESH_FAILED", "Invalid refresh token");
2016
2027
  }
2017
2028
  const resolvedRefresh = { ...config, ...config.resolve?.(ctx) };
2018
- const maxAgeMs = durationMs(resolvedRefresh.sessionMaxAge);
2029
+ const maxAgeMs = resolvedRefresh.sessionMaxAge ? durationMs(String(resolvedRefresh.sessionMaxAge)) : null;
2019
2030
  let issued = null;
2020
2031
  for (let attempt = 0; attempt < 3 && !issued; attempt++) {
2021
2032
  const found = await sessions.match(token);
@@ -3674,7 +3685,7 @@ var AuthModule = class {
3674
3685
  name = "@fonderie/auth";
3675
3686
  // Baked in at build time by tsup.base, so the operator's Modules page can
3676
3687
  // say what is actually deployed rather than 'not reported'.
3677
- version = "7.17.0";
3688
+ version = "7.17.1";
3678
3689
  // Users, sessions, login history, suspend — only through @fonderie/admin.
3679
3690
  describeAdmin() {
3680
3691
  return { routes: describeAuthAdminRoutes(this.store) };