@bymax-one/nest-auth 1.5.11 → 1.5.13

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.
@@ -7,7 +7,7 @@ import { Transform, plainToInstance } from 'class-transformer';
7
7
  import { IsEmail, MaxLength, IsString, MinLength, IsOptional, IsNotEmpty, Matches, Length, ValidateIf } from 'class-validator';
8
8
  import { isIPv6, isIP } from 'net';
9
9
  import { from } from 'rxjs';
10
- import { promisify } from 'util';
10
+ import { promisify, types } from 'util';
11
11
 
12
12
  var __defProp = Object.defineProperty;
13
13
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -25,6 +25,11 @@ var BYMAX_AUTH_API_KEY_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_API_KEY_R
25
25
  var BYMAX_AUTH_API_KEY_CLOCK = /* @__PURE__ */ Symbol("BYMAX_AUTH_API_KEY_CLOCK");
26
26
  var BYMAX_AUTH_WORKSPACE_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_WORKSPACE_REPOSITORY");
27
27
  var BYMAX_AUTH_MEMBERSHIP_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_MEMBERSHIP_REPOSITORY");
28
+ var GUARDED_USER_REPOSITORY = /* @__PURE__ */ Symbol("GUARDED_USER_REPOSITORY");
29
+ var GUARDED_PLATFORM_USER_REPOSITORY = /* @__PURE__ */ Symbol("GUARDED_PLATFORM_USER_REPOSITORY");
30
+ var GUARDED_API_KEY_REPOSITORY = /* @__PURE__ */ Symbol("GUARDED_API_KEY_REPOSITORY");
31
+ var GUARDED_WORKSPACE_REPOSITORY = /* @__PURE__ */ Symbol("GUARDED_WORKSPACE_REPOSITORY");
32
+ var GUARDED_MEMBERSHIP_REPOSITORY = /* @__PURE__ */ Symbol("GUARDED_MEMBERSHIP_REPOSITORY");
28
33
 
29
34
  // src/server/config/describe-received.ts
30
35
  function describeReceived(value) {
@@ -823,7 +828,10 @@ var OBJECT_GROUPS = [
823
828
  "platform",
824
829
  "invitations",
825
830
  "emailChange",
826
- "oauth"
831
+ "oauth",
832
+ "roles",
833
+ "workspaces",
834
+ "workspaces.roles"
827
835
  ];
828
836
  function readPath2(root, path) {
829
837
  let node = root;
@@ -1020,6 +1028,10 @@ var WORKSPACE_SUBGROUP_KEYS = {
1020
1028
  accessDeniedEvents: [
1021
1029
  "max",
1022
1030
  "windowSeconds"
1031
+ ],
1032
+ roles: [
1033
+ "hierarchy",
1034
+ "ownerRole"
1023
1035
  ]
1024
1036
  };
1025
1037
  function isObjectGroup(value) {
@@ -1069,7 +1081,7 @@ function dropUnset(options) {
1069
1081
  if (name === "workspaces") {
1070
1082
  for (const [sub, subKeys] of Object.entries(WORKSPACE_SUBGROUP_KEYS)) {
1071
1083
  const inner = group[sub];
1072
- if (isObjectGroup(inner)) group[sub] = readSetKeys(inner, subKeys);
1084
+ if (isObjectGroup(inner)) group[sub] = (sub === "roles" ? readKeptKeys : readSetKeys)(inner, subKeys);
1073
1085
  }
1074
1086
  }
1075
1087
  copy[name] = group;
@@ -1093,9 +1105,46 @@ __name(dropUnset, "dropUnset");
1093
1105
  function readOptions(given) {
1094
1106
  const options = dropUnset(given);
1095
1107
  validateTextOptions(options);
1096
- return options;
1108
+ return pinHierarchies(options);
1097
1109
  }
1098
1110
  __name(readOptions, "readOptions");
1111
+ function copyHierarchy(held) {
1112
+ if (Object(held) !== held) return held;
1113
+ return Object.fromEntries(Object.entries(held).map(([role, children]) => [
1114
+ role,
1115
+ Array.isArray(children) ? [
1116
+ ...children
1117
+ ] : children
1118
+ ]));
1119
+ }
1120
+ __name(copyHierarchy, "copyHierarchy");
1121
+ function pinIn(group, keys) {
1122
+ if (Object(group) !== group) return group;
1123
+ const plain = group;
1124
+ for (const key of keys) if (plain[key] !== void 0) plain[key] = copyHierarchy(plain[key]);
1125
+ return group;
1126
+ }
1127
+ __name(pinIn, "pinIn");
1128
+ function pinHierarchies(options) {
1129
+ const { roles, workspaces } = options;
1130
+ const { roles: workspaceRoles, ...workspaceRest } = workspaces ?? {};
1131
+ return {
1132
+ ...options,
1133
+ roles: pinIn(roles, [
1134
+ "hierarchy",
1135
+ "platformHierarchy"
1136
+ ]),
1137
+ ...workspaceRoles === void 0 ? {} : {
1138
+ workspaces: {
1139
+ ...workspaceRest,
1140
+ roles: pinIn(workspaceRoles, [
1141
+ "hierarchy"
1142
+ ])
1143
+ }
1144
+ }
1145
+ };
1146
+ }
1147
+ __name(pinHierarchies, "pinHierarchies");
1099
1148
  function validateOptionValues(userOptions) {
1100
1149
  validateNumericOptions(userOptions);
1101
1150
  validateEnumAndBooleanOptions(userOptions);
@@ -5428,26 +5477,34 @@ function malformedRefreshToken() {
5428
5477
  __name(malformedRefreshToken, "malformedRefreshToken");
5429
5478
 
5430
5479
  // src/server/utils/verify-with-rotation.ts
5480
+ function signerOf(options) {
5481
+ return {
5482
+ secret: options.jwt.secret,
5483
+ algorithm: options.jwt.algorithm
5484
+ };
5485
+ }
5486
+ __name(signerOf, "signerOf");
5431
5487
  function verifyWithRotation(jwtService, options, token, { ignoreExpiration = false } = {}) {
5432
5488
  const algorithms = [
5433
5489
  options.jwt.algorithm
5434
5490
  ];
5435
- const { issuer, audience } = options.jwt;
5491
+ const { issuer, audience, secret } = options.jwt;
5436
5492
  const base = {
5437
5493
  algorithms,
5438
5494
  ignoreExpiration,
5439
5495
  issuer,
5440
- audience
5496
+ audience,
5497
+ secret
5441
5498
  };
5442
5499
  try {
5443
5500
  return jwtService.verify(token, base);
5444
5501
  } catch (currentFailure) {
5445
5502
  const previous = options.jwt.previousSecrets ?? [];
5446
- for (const secret of previous) {
5503
+ for (const secret2 of previous) {
5447
5504
  try {
5448
5505
  return jwtService.verify(token, {
5449
5506
  ...base,
5450
- secret
5507
+ secret: secret2
5451
5508
  });
5452
5509
  } catch {
5453
5510
  }
@@ -5933,10 +5990,10 @@ var AccountStatusService = class _AccountStatusService {
5933
5990
  AccountStatusService = _ts_decorate12([
5934
5991
  Injectable(),
5935
5992
  _ts_param7(0, Inject(AuthRedisService)),
5936
- _ts_param7(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
5993
+ _ts_param7(1, Inject(GUARDED_USER_REPOSITORY)),
5937
5994
  _ts_param7(2, Inject(BYMAX_AUTH_OPTIONS)),
5938
5995
  _ts_param7(3, Optional()),
5939
- _ts_param7(3, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
5996
+ _ts_param7(3, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
5940
5997
  _ts_metadata12("design:type", Function),
5941
5998
  _ts_metadata12("design:paramtypes", [
5942
5999
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService,
@@ -6642,6 +6699,17 @@ function _ts_param11(paramIndex, decorator) {
6642
6699
  };
6643
6700
  }
6644
6701
  __name(_ts_param11, "_ts_param");
6702
+ async function releasingCooldownOnFailure(redis, logger, cooldownKey, work) {
6703
+ try {
6704
+ return await work();
6705
+ } catch (error) {
6706
+ await redis.del(cooldownKey).catch((err) => {
6707
+ logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
6708
+ });
6709
+ throw error;
6710
+ }
6711
+ }
6712
+ __name(releasingCooldownOnFailure, "releasingCooldownOnFailure");
6645
6713
  var MAX_ATTEMPTS = 5;
6646
6714
  var MIN_VERIFY_MS = 100;
6647
6715
  var OTP_STORE_LUA = `
@@ -7148,6 +7216,550 @@ PasswordService = _ts_decorate20([
7148
7216
  ])
7149
7217
  ], PasswordService);
7150
7218
 
7219
+ // src/server/utils/repository-contracts.ts
7220
+ var RECORD_CONTRACTS = {
7221
+ workspace: {
7222
+ fields: {
7223
+ id: "~id",
7224
+ tenantId: "string",
7225
+ name: "~string",
7226
+ status: "string",
7227
+ createdAt: "~date",
7228
+ deletionScheduledAt: "date|null"
7229
+ },
7230
+ nested: {}
7231
+ },
7232
+ membership: {
7233
+ fields: {
7234
+ tenantId: "string",
7235
+ workspaceId: "~id",
7236
+ userId: "~id",
7237
+ role: "string",
7238
+ status: "string",
7239
+ invitedByUserId: "~id",
7240
+ createdAt: "~date",
7241
+ updatedAt: "~date"
7242
+ },
7243
+ nested: {}
7244
+ },
7245
+ user: {
7246
+ fields: {
7247
+ id: "~id",
7248
+ email: "~string",
7249
+ name: "~string",
7250
+ passwordHash: "string|null",
7251
+ role: "string",
7252
+ status: "string",
7253
+ tenantId: "string",
7254
+ emailVerified: "boolean",
7255
+ mfaEnabled: "boolean",
7256
+ mfaSecret: "string?",
7257
+ mfaRecoveryCodes: "strings?",
7258
+ oauthProvider: "~string",
7259
+ oauthProviderId: "~string",
7260
+ lastLoginAt: "~date",
7261
+ createdAt: "~date"
7262
+ },
7263
+ nested: {}
7264
+ },
7265
+ platformUser: {
7266
+ fields: {
7267
+ id: "~id",
7268
+ email: "~string",
7269
+ name: "~string",
7270
+ passwordHash: "string",
7271
+ role: "string",
7272
+ status: "string",
7273
+ mfaEnabled: "boolean",
7274
+ mfaSecret: "string?",
7275
+ mfaRecoveryCodes: "strings?",
7276
+ platformId: "~id",
7277
+ lastLoginAt: "~date",
7278
+ updatedAt: "~date",
7279
+ createdAt: "~date"
7280
+ },
7281
+ nested: {}
7282
+ },
7283
+ apiKey: {
7284
+ fields: {
7285
+ id: "~id",
7286
+ label: "~string",
7287
+ digest: "string",
7288
+ scopes: "strings",
7289
+ createdAt: "~date",
7290
+ expiresAt: "date|null",
7291
+ revokedAt: "date|null",
7292
+ lastUsedAt: "~date"
7293
+ },
7294
+ nested: {}
7295
+ },
7296
+ removedMembership: {
7297
+ fields: {
7298
+ workspaceId: "~id",
7299
+ role: "string"
7300
+ },
7301
+ nested: {}
7302
+ }
7303
+ };
7304
+ var WORKSPACE = RECORD_CONTRACTS.workspace;
7305
+ var MEMBERSHIP = RECORD_CONTRACTS.membership;
7306
+ var USER = RECORD_CONTRACTS.user;
7307
+ var PLATFORM_USER = RECORD_CONTRACTS.platformUser;
7308
+ var API_KEY = RECORD_CONTRACTS.apiKey;
7309
+ var REMOVED_MEMBERSHIP = RECORD_CONTRACTS.removedMembership;
7310
+ var MEMBERSHIP_WITH_WORKSPACE = {
7311
+ fields: {
7312
+ ...MEMBERSHIP.fields,
7313
+ workspace: "nested"
7314
+ },
7315
+ nested: {
7316
+ workspace: WORKSPACE
7317
+ }
7318
+ };
7319
+ var PAGE_OF_MEMBERSHIPS_WITH_WORKSPACE = {
7320
+ fields: {
7321
+ items: "nested",
7322
+ nextCursor: "~string"
7323
+ },
7324
+ nested: {
7325
+ items: {
7326
+ list: MEMBERSHIP_WITH_WORKSPACE
7327
+ }
7328
+ }
7329
+ };
7330
+ var PAGE_OF_MEMBERSHIPS = {
7331
+ fields: {
7332
+ items: "nested",
7333
+ nextCursor: "~string"
7334
+ },
7335
+ nested: {
7336
+ items: {
7337
+ list: MEMBERSHIP
7338
+ }
7339
+ }
7340
+ };
7341
+ var PAGE_OF_WORKSPACES = {
7342
+ fields: {
7343
+ items: "nested",
7344
+ nextCursor: "~string"
7345
+ },
7346
+ nested: {
7347
+ items: {
7348
+ list: WORKSPACE
7349
+ }
7350
+ }
7351
+ };
7352
+ var orNothing = /* @__PURE__ */ __name((contract) => ({
7353
+ ...contract,
7354
+ nullable: true
7355
+ }), "orNothing");
7356
+ var USER_REPOSITORY_CONTRACT = {
7357
+ findById: orNothing(USER),
7358
+ findByEmail: orNothing(USER),
7359
+ create: USER,
7360
+ updatePassword: "void",
7361
+ updateMfa: "void",
7362
+ updateLastLogin: "void",
7363
+ updateStatus: "void",
7364
+ updateEmailVerified: "void",
7365
+ updateEmail: "void",
7366
+ findByOAuthId: orNothing(USER),
7367
+ linkOAuth: "void",
7368
+ createWithOAuth: USER
7369
+ };
7370
+ var PLATFORM_USER_REPOSITORY_CONTRACT = {
7371
+ findById: orNothing(PLATFORM_USER),
7372
+ findByEmail: orNothing(PLATFORM_USER),
7373
+ updateLastLogin: "void",
7374
+ updateMfa: "void",
7375
+ updatePassword: "void",
7376
+ updateStatus: "void"
7377
+ };
7378
+ var API_KEY_REPOSITORY_CONTRACT = {
7379
+ findById: orNothing(API_KEY),
7380
+ create: API_KEY,
7381
+ markRevoked: "boolean",
7382
+ setExpiry: "boolean",
7383
+ limitExpiry: "boolean",
7384
+ touchLastUsed: "void",
7385
+ listByLabel: {
7386
+ list: API_KEY
7387
+ }
7388
+ };
7389
+ var WORKSPACE_REPOSITORY_CONTRACT = {
7390
+ createWithOwner: {
7391
+ fields: {
7392
+ status: "string",
7393
+ workspace: "nested?"
7394
+ },
7395
+ nested: {
7396
+ workspace: WORKSPACE
7397
+ }
7398
+ },
7399
+ findById: orNothing(WORKSPACE),
7400
+ rename: "string",
7401
+ updateStatus: "string"
7402
+ };
7403
+ var MEMBERSHIP_REPOSITORY_CONTRACT = {
7404
+ find: orNothing(MEMBERSHIP),
7405
+ listForUser: PAGE_OF_MEMBERSHIPS_WITH_WORKSPACE,
7406
+ listForWorkspace: PAGE_OF_MEMBERSHIPS,
7407
+ create: "string",
7408
+ changeRole: "string",
7409
+ remove: "string",
7410
+ removeAllForUser: {
7411
+ fields: {
7412
+ result: "string",
7413
+ removed: "nested?",
7414
+ workspaceIds: "strings?"
7415
+ },
7416
+ nested: {
7417
+ removed: {
7418
+ list: REMOVED_MEMBERSHIP
7419
+ }
7420
+ }
7421
+ },
7422
+ transferOwnership: "string",
7423
+ countOwned: "number",
7424
+ listSoleOwned: PAGE_OF_WORKSPACES,
7425
+ getLastActiveWorkspaceId: "string|null",
7426
+ setLastActiveWorkspaceId: "void"
7427
+ };
7428
+ var CREDENTIAL_FIELDS = /* @__PURE__ */ new Set([
7429
+ "passwordHash",
7430
+ "mfaSecret",
7431
+ "mfaRecoveryCodes",
7432
+ "digest"
7433
+ ]);
7434
+
7435
+ // src/server/utils/host-read.ts
7436
+ var MAX_BREADTH = 1e5;
7437
+ var MAX_NODES = 1e6;
7438
+ function copiedUnder(read, value, contract) {
7439
+ return read.copies.get(value)?.get(contract);
7440
+ }
7441
+ __name(copiedUnder, "copiedUnder");
7442
+ function rememberUnder(read, value, contract, copy) {
7443
+ const copies = read.copies.get(value) ?? /* @__PURE__ */ new Map();
7444
+ copies.set(contract, copy);
7445
+ read.copies.set(value, copies);
7446
+ }
7447
+ __name(rememberUnder, "rememberUnder");
7448
+ function readHostOptions(read) {
7449
+ try {
7450
+ return read();
7451
+ } catch (error) {
7452
+ throw configurationError(error);
7453
+ }
7454
+ }
7455
+ __name(readHostOptions, "readHostOptions");
7456
+ async function readHostOptionsAsync(read) {
7457
+ try {
7458
+ return {
7459
+ value: await read()
7460
+ };
7461
+ } catch (error) {
7462
+ throw configurationError(error);
7463
+ }
7464
+ }
7465
+ __name(readHostOptionsAsync, "readHostOptionsAsync");
7466
+ function callFactory(factory, args) {
7467
+ return readHostOptionsAsync(async () => factory(...args));
7468
+ }
7469
+ __name(callFactory, "callFactory");
7470
+ function hostHasKey(host, key) {
7471
+ return readHostOptions(() => key in host);
7472
+ }
7473
+ __name(hostHasKey, "hostHasKey");
7474
+ function configurationError(error) {
7475
+ if (error instanceof Error && error.message.startsWith("[BymaxAuthModule]")) return error;
7476
+ return new Error("[BymaxAuthModule] the options could not be read: the factory, a getter or a Proxy of the host threw", {
7477
+ cause: error
7478
+ });
7479
+ }
7480
+ __name(configurationError, "configurationError");
7481
+ function define(copy, key, value, enumerable) {
7482
+ Object.defineProperty(copy, key, {
7483
+ value,
7484
+ enumerable,
7485
+ writable: true,
7486
+ configurable: true
7487
+ });
7488
+ }
7489
+ __name(define, "define");
7490
+ var ENTITIES = /* @__PURE__ */ new WeakMap();
7491
+ function follow(read, size) {
7492
+ read.nodes -= size;
7493
+ if (size > MAX_BREADTH || read.nodes < 0) throw new Error("the answer holds more than the library follows");
7494
+ }
7495
+ __name(follow, "follow");
7496
+ function isDateLike(value) {
7497
+ return types.isDate(value) || types.isProxy(value) && value instanceof Date;
7498
+ }
7499
+ __name(isDateLike, "isDateLike");
7500
+ function isPlainObject(value) {
7501
+ const prototype = Object.getPrototypeOf(value);
7502
+ return prototype === null || Object.getPrototypeOf(prototype) === null;
7503
+ }
7504
+ __name(isPlainObject, "isPlainObject");
7505
+ var WRONG_KIND = "the answer holds a value that is not the kind its method promises";
7506
+ var ABSENT = "the answer lacks a field its method promises";
7507
+ var NOT_A_TIME = "the answer holds a date that is not a time";
7508
+ function accept(ok, value) {
7509
+ if (!ok) throw new Error(WRONG_KIND);
7510
+ return value;
7511
+ }
7512
+ __name(accept, "accept");
7513
+ function isHostInstance(value) {
7514
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !types.isBoxedPrimitive(value) && !isPlainObject(value);
7515
+ }
7516
+ __name(isHostInstance, "isHostInstance");
7517
+ function timeOf(date) {
7518
+ const real = types.isDate(date);
7519
+ return real ? Date.prototype.getTime.call(date) : date.getTime();
7520
+ }
7521
+ __name(timeOf, "timeOf");
7522
+ function copyDate(value) {
7523
+ if (typeof value !== "object" || value === null || !isDateLike(value)) throw new Error(WRONG_KIND);
7524
+ const time = timeOf(value);
7525
+ const copy = new Date(typeof time === "number" ? time : Number.NaN);
7526
+ if (Number.isNaN(copy.getTime())) throw new Error(NOT_A_TIME);
7527
+ return copy;
7528
+ }
7529
+ __name(copyDate, "copyDate");
7530
+ function copyStrings(value, read) {
7531
+ if (!Array.isArray(value)) throw new Error(WRONG_KIND);
7532
+ follow(read, value.length);
7533
+ const copy = [];
7534
+ for (let index = 0; index < value.length; index += 1) {
7535
+ const element = value[index];
7536
+ copy.push(accept(typeof element === "string", element));
7537
+ }
7538
+ return copy;
7539
+ }
7540
+ __name(copyStrings, "copyStrings");
7541
+ function readId(value) {
7542
+ if (typeof value === "string") return accept(value !== "", value);
7543
+ if (typeof value === "number") return accept(Number.isSafeInteger(value), String(value));
7544
+ if (!isHostInstance(value) || types.isDate(value) || types.isRegExp(value)) throw new Error(WRONG_KIND);
7545
+ const printed = String(value);
7546
+ return accept(printed !== "" && !printed.startsWith("[object "), printed);
7547
+ }
7548
+ __name(readId, "readId");
7549
+ function readInforming(value) {
7550
+ return accept(typeof value === "string" || Number.isFinite(value) || isHostInstance(value), value);
7551
+ }
7552
+ __name(readInforming, "readInforming");
7553
+ function readInformingDate(value) {
7554
+ if (typeof value === "string" || Number.isFinite(value)) return value;
7555
+ if (!isHostInstance(value)) throw new Error(WRONG_KIND);
7556
+ if (!isDateLike(value)) return value;
7557
+ const time = timeOf(value);
7558
+ const copy = new Date(typeof time === "number" ? time : Number.NaN);
7559
+ return Number.isNaN(copy.getTime()) ? value : copy;
7560
+ }
7561
+ __name(readInformingDate, "readInformingDate");
7562
+ var READERS = {
7563
+ boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
7564
+ string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
7565
+ number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
7566
+ date: copyDate,
7567
+ strings: copyStrings,
7568
+ "~id": readId,
7569
+ "~string": readInforming,
7570
+ "~date": readInformingDate
7571
+ };
7572
+ function parseSpec(spec) {
7573
+ const lenient = spec.startsWith("~");
7574
+ const optional = lenient || spec.endsWith("?");
7575
+ const rest = spec.endsWith("?") ? spec.slice(0, -1) : spec;
7576
+ const nullable = lenient || rest.endsWith("|null");
7577
+ return {
7578
+ base: rest.endsWith("|null") ? rest.slice(0, -"|null".length) : rest,
7579
+ nullable,
7580
+ optional
7581
+ };
7582
+ }
7583
+ __name(parseSpec, "parseSpec");
7584
+ function readNull(nullable) {
7585
+ if (!nullable) throw new Error(WRONG_KIND);
7586
+ return null;
7587
+ }
7588
+ __name(readNull, "readNull");
7589
+ function readScalar(value, spec, run) {
7590
+ const { base, nullable } = parseSpec(spec);
7591
+ if (base === "void") return void 0;
7592
+ return value === null ? readNull(nullable) : READERS[base](value, run);
7593
+ }
7594
+ __name(readScalar, "readScalar");
7595
+ function copyRecord(value, contract, run) {
7596
+ const copy = {};
7597
+ rememberUnder(run, value, contract, copy);
7598
+ ENTITIES.set(copy, value);
7599
+ const source = value;
7600
+ const keys = Object.keys(value);
7601
+ follow(run, keys.length);
7602
+ for (const key of keys) {
7603
+ if (Object.hasOwn(contract.fields, key)) continue;
7604
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
7605
+ if (descriptor !== void 0 && "value" in descriptor) define(copy, key, descriptor.value, true);
7606
+ }
7607
+ const own = new Set(keys);
7608
+ for (const [field, spec] of Object.entries(contract.fields)) {
7609
+ const { base, nullable, optional } = parseSpec(spec);
7610
+ const held = source[field];
7611
+ if (held === void 0) {
7612
+ if (optional) continue;
7613
+ throw new Error(ABSENT);
7614
+ }
7615
+ const copied = held === null ? readNull(nullable || optional) : base === "nested" ? applyContract(held, contract.nested[field], run) : READERS[base](held, run);
7616
+ define(copy, field, copied, own.has(field) || !CREDENTIAL_FIELDS.has(field));
7617
+ }
7618
+ return copy;
7619
+ }
7620
+ __name(copyRecord, "copyRecord");
7621
+ function applyContract(value, contract, run) {
7622
+ if (typeof value !== "object" || value === null) throw new Error(WRONG_KIND);
7623
+ const known = copiedUnder(run, value, contract);
7624
+ if (known !== void 0) return known;
7625
+ if ("list" in contract) {
7626
+ if (!Array.isArray(value)) throw new Error("the answer is not the list its method promises");
7627
+ follow(run, value.length);
7628
+ const copy = [];
7629
+ rememberUnder(run, value, contract, copy);
7630
+ for (let index = 0; index < value.length; index += 1) copy.push(applyContract(value[index], contract.list, run));
7631
+ return copy;
7632
+ }
7633
+ if (Array.isArray(value)) throw new Error("the answer is not the record its method promises");
7634
+ return copyRecord(value, contract, run);
7635
+ }
7636
+ __name(applyContract, "applyContract");
7637
+ function copyHostRecord(record, contract) {
7638
+ try {
7639
+ const run = {
7640
+ copies: /* @__PURE__ */ new WeakMap(),
7641
+ nodes: MAX_NODES
7642
+ };
7643
+ if (typeof contract === "string") return readScalar(record, contract, run);
7644
+ if ((record === null || record === void 0) && contract.nullable === true) return record;
7645
+ return applyContract(record, contract, run);
7646
+ } catch (error) {
7647
+ throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
7648
+ cause: error
7649
+ });
7650
+ }
7651
+ }
7652
+ __name(copyHostRecord, "copyHostRecord");
7653
+ function isTypedError(error) {
7654
+ try {
7655
+ return error instanceof HttpException;
7656
+ } catch {
7657
+ return false;
7658
+ }
7659
+ }
7660
+ __name(isTypedError, "isTypedError");
7661
+ var LIFECYCLE_HOOKS = /* @__PURE__ */ new Set([
7662
+ "onModuleInit",
7663
+ "onApplicationBootstrap",
7664
+ "onModuleDestroy",
7665
+ "beforeApplicationShutdown",
7666
+ "onApplicationShutdown"
7667
+ ]);
7668
+ function hostEntityOf(record) {
7669
+ return typeof record === "object" && record !== null ? ENTITIES.get(record) ?? record : record;
7670
+ }
7671
+ __name(hostEntityOf, "hostEntityOf");
7672
+ function guardRepository(host, contract) {
7673
+ return new Proxy({}, {
7674
+ get(_target, key) {
7675
+ if (LIFECYCLE_HOOKS.has(key)) return void 0;
7676
+ let member;
7677
+ try {
7678
+ member = Reflect.get(host, key, host);
7679
+ } catch (error) {
7680
+ if (key === "then" || typeof key === "symbol") return void 0;
7681
+ return async () => {
7682
+ throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
7683
+ cause: error
7684
+ });
7685
+ };
7686
+ }
7687
+ if (typeof member !== "function") return member;
7688
+ return async (...args) => {
7689
+ let answer;
7690
+ try {
7691
+ answer = await member.apply(host, args);
7692
+ } catch (error) {
7693
+ if (isTypedError(error)) throw error;
7694
+ throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
7695
+ cause: error
7696
+ });
7697
+ }
7698
+ const promised = typeof key === "string" && Object.hasOwn(contract, key) ? contract[key] : void 0;
7699
+ return promised === void 0 ? answer : copyHostRecord(answer, promised);
7700
+ };
7701
+ }
7702
+ });
7703
+ }
7704
+ __name(guardRepository, "guardRepository");
7705
+ var GUARDED_BY_HOST = /* @__PURE__ */ new Map([
7706
+ [
7707
+ BYMAX_AUTH_USER_REPOSITORY,
7708
+ [
7709
+ GUARDED_USER_REPOSITORY,
7710
+ USER_REPOSITORY_CONTRACT
7711
+ ]
7712
+ ],
7713
+ [
7714
+ BYMAX_AUTH_PLATFORM_USER_REPOSITORY,
7715
+ [
7716
+ GUARDED_PLATFORM_USER_REPOSITORY,
7717
+ PLATFORM_USER_REPOSITORY_CONTRACT
7718
+ ]
7719
+ ],
7720
+ [
7721
+ BYMAX_AUTH_API_KEY_REPOSITORY,
7722
+ [
7723
+ GUARDED_API_KEY_REPOSITORY,
7724
+ API_KEY_REPOSITORY_CONTRACT
7725
+ ]
7726
+ ],
7727
+ [
7728
+ BYMAX_AUTH_WORKSPACE_REPOSITORY,
7729
+ [
7730
+ GUARDED_WORKSPACE_REPOSITORY,
7731
+ WORKSPACE_REPOSITORY_CONTRACT
7732
+ ]
7733
+ ],
7734
+ [
7735
+ BYMAX_AUTH_MEMBERSHIP_REPOSITORY,
7736
+ [
7737
+ GUARDED_MEMBERSHIP_REPOSITORY,
7738
+ MEMBERSHIP_REPOSITORY_CONTRACT
7739
+ ]
7740
+ ]
7741
+ ]);
7742
+ function guardedViewProvider(host, guarded, contract) {
7743
+ return {
7744
+ provide: guarded,
7745
+ useFactory: /* @__PURE__ */ __name((repository) => guardRepository(repository, contract), "useFactory"),
7746
+ inject: [
7747
+ host
7748
+ ]
7749
+ };
7750
+ }
7751
+ __name(guardedViewProvider, "guardedViewProvider");
7752
+ function withGuardedViews(providers) {
7753
+ const views = [
7754
+ ...GUARDED_BY_HOST
7755
+ ].filter(([host]) => providers.some((provider) => typeof provider !== "function" && "provide" in provider && provider.provide === host)).map(([host, [guarded, contract]]) => guardedViewProvider(host, guarded, contract));
7756
+ return [
7757
+ ...providers,
7758
+ ...views
7759
+ ];
7760
+ }
7761
+ __name(withGuardedViews, "withGuardedViews");
7762
+
7151
7763
  // src/server/utils/run-detached.ts
7152
7764
  function runDetached(logger, run, hook) {
7153
7765
  try {
@@ -7882,10 +8494,9 @@ var SessionService = class _SessionService {
7882
8494
  /**
7883
8495
  * Resolves the maximum number of concurrent sessions allowed for a user.
7884
8496
  *
7885
- * When `options.sessions.maxSessionsResolver` is configured, it is called with
7886
- * the full user record. Falls back to `options.sessions.defaultMaxSessions` if
7887
- * the resolver is absent, the user cannot be found, the resolver throws, or it answers
7888
- * with something that is not a usable limit.
8497
+ * When `options.sessions.maxSessionsResolver` is configured, it is called with the entity the user
8498
+ * repository returned. Falls back to `options.sessions.defaultMaxSessions` if the resolver is absent,
8499
+ * the user cannot be found, the resolver throws, or it answers with an unusable limit.
7889
8500
  *
7890
8501
  * That last case is the one that mattered. The resolver is the host's code and its return
7891
8502
  * value went straight into the eviction arithmetic, where `NaN` — the result of, say,
@@ -7910,7 +8521,7 @@ var SessionService = class _SessionService {
7910
8521
  tenantId
7911
8522
  });
7912
8523
  if (!user) return defaultMaxSessions;
7913
- const resolved = await maxSessionsResolver(user);
8524
+ const resolved = await maxSessionsResolver(hostEntityOf(user));
7914
8525
  if (!Number.isInteger(resolved) || resolved < 1) {
7915
8526
  logEvent(this.logger, "AUTH_SESSION_LIMIT_RESOLVER_INVALID");
7916
8527
  return defaultMaxSessions;
@@ -7925,7 +8536,7 @@ var SessionService = class _SessionService {
7925
8536
  SessionService = _ts_decorate21([
7926
8537
  Injectable(),
7927
8538
  _ts_param13(0, Inject(BYMAX_AUTH_OPTIONS)),
7928
- _ts_param13(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
8539
+ _ts_param13(1, Inject(GUARDED_USER_REPOSITORY)),
7929
8540
  _ts_param13(2, Inject(BYMAX_AUTH_HOOKS)),
7930
8541
  _ts_param13(2, Optional()),
7931
8542
  _ts_param13(3, Inject(AuthRedisService)),
@@ -8048,7 +8659,7 @@ var TokenManagerService = class _TokenManagerService {
8048
8659
  accessSignOptions() {
8049
8660
  return {
8050
8661
  expiresIn: this.options.jwt.accessExpiresIn,
8051
- algorithm: this.options.jwt.algorithm,
8662
+ ...signerOf(this.options),
8052
8663
  ...this.issuerAudience()
8053
8664
  };
8054
8665
  }
@@ -8834,7 +9445,7 @@ var TokenManagerService = class _TokenManagerService {
8834
9445
  };
8835
9446
  const token = this.jwtService.sign(payload, {
8836
9447
  expiresIn: `${MFA_TEMP_TOKEN_TTL_SECONDS}s`,
8837
- algorithm: this.options.jwt.algorithm,
9448
+ ...signerOf(this.options),
8838
9449
  // The challenge token is stamped and checked like every other: it grants no resource
8839
9450
  // access on its own, but it is still a token this backend minted, and a verifier that
8840
9451
  // exempted one shape would be a verifier an attacker aims at.
@@ -9859,13 +10470,13 @@ var AuthService = class _AuthService {
9859
10470
  await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
9860
10471
  return;
9861
10472
  }
9862
- const user = tenantScoped(await this.userRepo.findByEmail({
9863
- email,
9864
- tenantId
9865
- }), tenantId);
9866
- if (user && !user.emailVerified) {
9867
- await this.sendVerificationOtp(tenantId, email);
9868
- }
10473
+ await releasingCooldownOnFailure(this.redis, this.logger, cooldownKey, async () => {
10474
+ const user = tenantScoped(await this.userRepo.findByEmail({
10475
+ email,
10476
+ tenantId
10477
+ }), tenantId);
10478
+ if (user && !user.emailVerified) await this.sendVerificationOtp(tenantId, email);
10479
+ });
9869
10480
  await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
9870
10481
  }
9871
10482
  // ---------------------------------------------------------------------------
@@ -10134,7 +10745,7 @@ var AuthService = class _AuthService {
10134
10745
  AuthService = _ts_decorate23([
10135
10746
  Injectable(),
10136
10747
  _ts_param15(0, Inject(BYMAX_AUTH_OPTIONS)),
10137
- _ts_param15(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
10748
+ _ts_param15(1, Inject(GUARDED_USER_REPOSITORY)),
10138
10749
  _ts_param15(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
10139
10750
  _ts_param15(2, Optional()),
10140
10751
  _ts_param15(3, Inject(BYMAX_AUTH_HOOKS)),
@@ -10345,7 +10956,7 @@ WsTicketService = _ts_decorate24([
10345
10956
  Injectable(),
10346
10957
  _ts_param16(0, Inject(AuthRedisService)),
10347
10958
  _ts_param16(1, Inject(BYMAX_AUTH_OPTIONS)),
10348
- _ts_param16(2, Inject(BYMAX_AUTH_USER_REPOSITORY)),
10959
+ _ts_param16(2, Inject(GUARDED_USER_REPOSITORY)),
10349
10960
  _ts_param16(3, Inject(AuthRevocationService)),
10350
10961
  _ts_metadata21("design:type", Function),
10351
10962
  _ts_metadata21("design:paramtypes", [
@@ -11045,7 +11656,7 @@ var EmailChangeService = class _EmailChangeService {
11045
11656
  EmailChangeService = _ts_decorate28([
11046
11657
  Injectable(),
11047
11658
  _ts_param18(0, Inject(BYMAX_AUTH_OPTIONS)),
11048
- _ts_param18(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
11659
+ _ts_param18(1, Inject(GUARDED_USER_REPOSITORY)),
11049
11660
  _ts_param18(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
11050
11661
  _ts_param18(3, Inject(PasswordService)),
11051
11662
  _ts_param18(4, Inject(AuthRedisService)),
@@ -11875,7 +12486,7 @@ var InvitationService = class _InvitationService {
11875
12486
  };
11876
12487
  InvitationService = _ts_decorate33([
11877
12488
  Injectable(),
11878
- _ts_param20(0, Inject(BYMAX_AUTH_USER_REPOSITORY)),
12489
+ _ts_param20(0, Inject(GUARDED_USER_REPOSITORY)),
11879
12490
  _ts_param20(1, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
11880
12491
  _ts_param20(2, Inject(BYMAX_AUTH_HOOKS)),
11881
12492
  _ts_param20(3, Inject(AuthRedisService)),
@@ -12773,9 +13384,9 @@ var MfaRecordService = class {
12773
13384
  MfaRecordService = _ts_decorate41([
12774
13385
  Injectable(),
12775
13386
  _ts_param23(0, Inject(BYMAX_AUTH_OPTIONS)),
12776
- _ts_param23(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
13387
+ _ts_param23(1, Inject(GUARDED_USER_REPOSITORY)),
12777
13388
  _ts_param23(2, Optional()),
12778
- _ts_param23(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
13389
+ _ts_param23(2, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
12779
13390
  _ts_param23(3, Inject(AuthRedisService)),
12780
13391
  _ts_metadata38("design:type", Function),
12781
13392
  _ts_metadata38("design:paramtypes", [
@@ -13171,9 +13782,9 @@ var MfaChallengeService = class {
13171
13782
  MfaChallengeService = _ts_decorate42([
13172
13783
  Injectable(),
13173
13784
  _ts_param24(0, Inject(BYMAX_AUTH_OPTIONS)),
13174
- _ts_param24(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
13785
+ _ts_param24(1, Inject(GUARDED_USER_REPOSITORY)),
13175
13786
  _ts_param24(2, Optional()),
13176
- _ts_param24(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
13787
+ _ts_param24(2, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
13177
13788
  _ts_param24(3, Inject(TokenManagerService)),
13178
13789
  _ts_param24(4, Inject(MfaFlowLockoutService)),
13179
13790
  _ts_param24(5, Inject(MfaRecordService)),
@@ -13565,7 +14176,7 @@ MfaManagementService = _ts_decorate43([
13565
14176
  Injectable(),
13566
14177
  _ts_param25(0, Inject(BYMAX_AUTH_OPTIONS)),
13567
14178
  _ts_param25(1, Optional()),
13568
- _ts_param25(1, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
14179
+ _ts_param25(1, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
13569
14180
  _ts_param25(2, Inject(AuthRedisService)),
13570
14181
  _ts_param25(3, Inject(MfaFlowLockoutService)),
13571
14182
  _ts_param25(4, Inject(MfaRecordService)),
@@ -14087,9 +14698,9 @@ var MfaService = class _MfaService {
14087
14698
  MfaService = _ts_decorate45([
14088
14699
  Injectable(),
14089
14700
  _ts_param27(0, Inject(BYMAX_AUTH_OPTIONS)),
14090
- _ts_param27(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
14701
+ _ts_param27(1, Inject(GUARDED_USER_REPOSITORY)),
14091
14702
  _ts_param27(2, Optional()),
14092
- _ts_param27(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
14703
+ _ts_param27(2, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
14093
14704
  _ts_param27(3, Inject(AuthRedisService)),
14094
14705
  _ts_param27(4, Inject(TokenManagerService)),
14095
14706
  _ts_param27(5, Inject(MfaRecordService)),
@@ -15480,7 +16091,7 @@ var PasswordResetService = class _PasswordResetService {
15480
16091
  PasswordResetService = _ts_decorate52([
15481
16092
  Injectable(),
15482
16093
  _ts_param29(0, Inject(BYMAX_AUTH_OPTIONS)),
15483
- _ts_param29(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
16094
+ _ts_param29(1, Inject(GUARDED_USER_REPOSITORY)),
15484
16095
  _ts_param29(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
15485
16096
  _ts_param29(2, Optional()),
15486
16097
  _ts_param29(3, Inject(BYMAX_AUTH_HOOKS)),
@@ -16236,7 +16847,7 @@ var PlatformAuthService = class _PlatformAuthService {
16236
16847
  };
16237
16848
  PlatformAuthService = _ts_decorate56([
16238
16849
  Injectable(),
16239
- _ts_param32(0, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
16850
+ _ts_param32(0, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
16240
16851
  _ts_param32(1, Inject(PasswordService)),
16241
16852
  _ts_param32(2, Inject(TokenManagerService)),
16242
16853
  _ts_param32(3, Inject(BruteForceService)),
@@ -17496,6 +18107,9 @@ var WorkspaceAccessService = class _WorkspaceAccessService {
17496
18107
  if (membership?.status !== "active" || workspace === null) return {
17497
18108
  kind: "denied"
17498
18109
  };
18110
+ if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId) return {
18111
+ kind: "denied"
18112
+ };
17499
18113
  const member = {
17500
18114
  ...ref,
17501
18115
  role: membership.role
@@ -17520,8 +18134,8 @@ var WorkspaceAccessService = class _WorkspaceAccessService {
17520
18134
  WorkspaceAccessService = _ts_decorate66([
17521
18135
  Injectable(),
17522
18136
  _ts_param36(0, Inject(AuthRedisService)),
17523
- _ts_param36(1, Inject(BYMAX_AUTH_WORKSPACE_REPOSITORY)),
17524
- _ts_param36(2, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
18137
+ _ts_param36(1, Inject(GUARDED_WORKSPACE_REPOSITORY)),
18138
+ _ts_param36(2, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
17525
18139
  _ts_param36(3, Inject(BYMAX_AUTH_OPTIONS)),
17526
18140
  _ts_param36(4, Inject(AccountStatusService)),
17527
18141
  _ts_param36(4, Optional()),
@@ -18400,7 +19014,7 @@ var MembershipService = class {
18400
19014
  };
18401
19015
  MembershipService = _ts_decorate70([
18402
19016
  Injectable(),
18403
- _ts_param40(0, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
19017
+ _ts_param40(0, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
18404
19018
  _ts_param40(1, Inject(WorkspaceAccessService)),
18405
19019
  _ts_param40(2, Inject(WorkspaceEventsService)),
18406
19020
  _ts_param40(3, Inject(BYMAX_AUTH_OPTIONS)),
@@ -19105,9 +19719,9 @@ WorkspaceInvitationAcceptService = _ts_decorate72([
19105
19719
  _ts_param42(4, Inject(PasswordService)),
19106
19720
  _ts_param42(5, Inject(TokenManagerService)),
19107
19721
  _ts_param42(6, Inject(SessionService)),
19108
- _ts_param42(7, Inject(BYMAX_AUTH_USER_REPOSITORY)),
19109
- _ts_param42(8, Inject(BYMAX_AUTH_WORKSPACE_REPOSITORY)),
19110
- _ts_param42(9, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
19722
+ _ts_param42(7, Inject(GUARDED_USER_REPOSITORY)),
19723
+ _ts_param42(8, Inject(GUARDED_WORKSPACE_REPOSITORY)),
19724
+ _ts_param42(9, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
19111
19725
  _ts_param42(10, Inject(BYMAX_AUTH_HOOKS)),
19112
19726
  _ts_param42(11, Inject(BYMAX_AUTH_OPTIONS)),
19113
19727
  _ts_metadata69("design:type", Function),
@@ -19589,9 +20203,9 @@ WorkspaceInvitationService = _ts_decorate73([
19589
20203
  _ts_param43(1, Inject(AuthRedisService)),
19590
20204
  _ts_param43(2, Inject(MembershipService)),
19591
20205
  _ts_param43(3, Inject(WorkspaceEventsService)),
19592
- _ts_param43(4, Inject(BYMAX_AUTH_USER_REPOSITORY)),
19593
- _ts_param43(5, Inject(BYMAX_AUTH_WORKSPACE_REPOSITORY)),
19594
- _ts_param43(6, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
20206
+ _ts_param43(4, Inject(GUARDED_USER_REPOSITORY)),
20207
+ _ts_param43(5, Inject(GUARDED_WORKSPACE_REPOSITORY)),
20208
+ _ts_param43(6, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
19595
20209
  _ts_param43(7, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
19596
20210
  _ts_param43(8, Inject(BYMAX_AUTH_OPTIONS)),
19597
20211
  _ts_metadata70("design:type", Function),
@@ -20272,7 +20886,7 @@ var WorkspaceCallerService = class {
20272
20886
  };
20273
20887
  WorkspaceCallerService = _ts_decorate81([
20274
20888
  Injectable(),
20275
- _ts_param45(0, Inject(BYMAX_AUTH_USER_REPOSITORY)),
20889
+ _ts_param45(0, Inject(GUARDED_USER_REPOSITORY)),
20276
20890
  _ts_param45(1, Inject(ReauthenticationService)),
20277
20891
  _ts_metadata78("design:type", Function),
20278
20892
  _ts_metadata78("design:paramtypes", [
@@ -20609,8 +21223,8 @@ var WorkspaceService = class {
20609
21223
  };
20610
21224
  WorkspaceService = _ts_decorate82([
20611
21225
  Injectable(),
20612
- _ts_param46(0, Inject(BYMAX_AUTH_WORKSPACE_REPOSITORY)),
20613
- _ts_param46(1, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
21226
+ _ts_param46(0, Inject(GUARDED_WORKSPACE_REPOSITORY)),
21227
+ _ts_param46(1, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
20614
21228
  _ts_param46(2, Inject(WorkspaceAccessService)),
20615
21229
  _ts_param46(3, Inject(WorkspaceEventsService)),
20616
21230
  _ts_param46(4, Inject(BYMAX_AUTH_HOOKS)),
@@ -21412,7 +22026,7 @@ var ApiKeyLastUsedService = class _ApiKeyLastUsedService {
21412
22026
  };
21413
22027
  ApiKeyLastUsedService = _ts_decorate85([
21414
22028
  Injectable(),
21415
- _ts_param49(0, Inject(BYMAX_AUTH_API_KEY_REPOSITORY)),
22029
+ _ts_param49(0, Inject(GUARDED_API_KEY_REPOSITORY)),
21416
22030
  _ts_param49(1, Inject(BYMAX_AUTH_OPTIONS)),
21417
22031
  _ts_metadata82("design:type", Function),
21418
22032
  _ts_metadata82("design:paramtypes", [
@@ -21551,7 +22165,7 @@ var ApiKeyVerifierService = class {
21551
22165
  };
21552
22166
  ApiKeyVerifierService = _ts_decorate86([
21553
22167
  Injectable(),
21554
- _ts_param50(0, Inject(BYMAX_AUTH_API_KEY_REPOSITORY)),
22168
+ _ts_param50(0, Inject(GUARDED_API_KEY_REPOSITORY)),
21555
22169
  _ts_param50(1, Inject(BYMAX_AUTH_API_KEY_CLOCK)),
21556
22170
  _ts_param50(2, Inject(BYMAX_AUTH_OPTIONS)),
21557
22171
  _ts_param50(3, Inject(ApiKeyLastUsedService)),
@@ -22706,7 +23320,7 @@ var OAuthService = class _OAuthService {
22706
23320
  OAuthService = _ts_decorate93([
22707
23321
  Injectable(),
22708
23322
  _ts_param56(0, Inject(OAUTH_PLUGINS)),
22709
- _ts_param56(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
23323
+ _ts_param56(1, Inject(GUARDED_USER_REPOSITORY)),
22710
23324
  _ts_param56(2, Inject(BYMAX_AUTH_HOOKS)),
22711
23325
  _ts_param56(2, Optional()),
22712
23326
  _ts_param56(3, Inject(AuthRedisService)),
@@ -23459,9 +24073,10 @@ var OAuthModule = class _OAuthModule {
23459
24073
  /**
23460
24074
  * Returns the provider array for inline inclusion in `BymaxAuthModule`.
23461
24075
  *
23462
- * Includes `OAUTH_PLUGINS` (value provider) and `OAuthService`. All other
23463
- * dependencies (`AuthRedisService`, etc.) are expected to be present in
23464
- * `BymaxAuthModule`'s own providers array.
24076
+ * Includes `OAUTH_PLUGINS` (value provider), `OAuthService` and the guarded view of the host's user repository
24077
+ * that `OAuthService` reads, built from the repository the host provides under `BYMAX_AUTH_USER_REPOSITORY`.
24078
+ * All other dependencies (`AuthRedisService`, etc.) are expected to be present in the parent module's own
24079
+ * providers array.
23465
24080
  *
23466
24081
  * @param options - Fully resolved options from `resolveOptions()`.
23467
24082
  * @returns Provider array ready to be spread into a parent module's `providers`.
@@ -23472,7 +24087,8 @@ var OAuthModule = class _OAuthModule {
23472
24087
  provide: OAUTH_PLUGINS,
23473
24088
  useValue: buildOAuthPlugins(options)
23474
24089
  },
23475
- OAuthService
24090
+ OAuthService,
24091
+ guardedViewProvider(BYMAX_AUTH_USER_REPOSITORY, GUARDED_USER_REPOSITORY, USER_REPOSITORY_CONTRACT)
23476
24092
  ];
23477
24093
  }
23478
24094
  /**
@@ -25669,7 +26285,7 @@ var ApiKeyService = class {
25669
26285
  };
25670
26286
  ApiKeyService = _ts_decorate104([
25671
26287
  Injectable(),
25672
- _ts_param63(0, Inject(BYMAX_AUTH_API_KEY_REPOSITORY)),
26288
+ _ts_param63(0, Inject(GUARDED_API_KEY_REPOSITORY)),
25673
26289
  _ts_param63(1, Inject(BYMAX_AUTH_API_KEY_CLOCK)),
25674
26290
  _ts_param63(2, Inject(BYMAX_AUTH_OPTIONS)),
25675
26291
  _ts_metadata98("design:type", Function),
@@ -26088,11 +26704,11 @@ var BymaxAuthModule = class _BymaxAuthModule {
26088
26704
  const resolvedOptionsProvider = {
26089
26705
  provide: BYMAX_AUTH_OPTIONS,
26090
26706
  useFactory: /* @__PURE__ */ __name(async (...args) => {
26091
- const userOptions = await options.useFactory(...args);
26092
- if ("controllers" in userOptions) {
26707
+ const { value: userOptions } = await callFactory(options.useFactory, args);
26708
+ if (hostHasKey(userOptions, "controllers")) {
26093
26709
  throw new Error("[BymaxAuthModule] `controllers` must be passed to registerAsync() itself, not returned from useFactory \u2014 the module is assembled before the factory runs, so flags returned here are ignored and the endpoints are never registered.");
26094
26710
  }
26095
- const resolved = resolveOptions(userOptions);
26711
+ const resolved = readHostOptions(() => resolveOptions(userOptions));
26096
26712
  if (includeMfa && resolved.mfa === void 0) {
26097
26713
  throw new Error("[BymaxAuthModule] controllers.mfa: true requires the mfa group (encryptionKey and issuer) to be configured in the useFactory return value.");
26098
26714
  }
@@ -26242,17 +26858,16 @@ var BymaxAuthModule = class _BymaxAuthModule {
26242
26858
  ...includeApiKeys ? [
26243
26859
  DiscoveryModule
26244
26860
  ] : [],
26245
- // JwtModule reads the secret directly from the consumer factory (without re-running
26246
- // resolveOptions) to avoid double-validation on startup. Full validation happens once
26247
- // in the BYMAX_AUTH_OPTIONS provider above.
26861
+ // A second call of the consumer factory, not resolveOptions: what it answers is not what the
26862
+ // BYMAX_AUTH_OPTIONS provider validated, so every sign and verify names the resolved secret.
26248
26863
  // expiresIn is omitted — TokenManagerService sets it per-call via accessSignOptions().
26249
26864
  JwtModule.registerAsync({
26250
26865
  // The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
26251
26866
  imports: options.imports ?? [],
26252
26867
  useFactory: /* @__PURE__ */ __name(async (...args) => {
26253
- const userOptions = await options.useFactory(...args);
26868
+ const { value: userOptions } = await callFactory(options.useFactory, args);
26254
26869
  return {
26255
- secret: userOptions.jwt.secret,
26870
+ secret: readHostOptions(() => userOptions.jwt.secret),
26256
26871
  // Stryker disable next-line ObjectLiteral: jsonwebtoken defaults to HS256 and TokenManagerService overrides signOptions per call, so the emptied `signOptions` produces identical signing
26257
26872
  signOptions: {
26258
26873
  algorithm: "HS256"
@@ -26264,7 +26879,7 @@ var BymaxAuthModule = class _BymaxAuthModule {
26264
26879
  ],
26265
26880
  providers: [
26266
26881
  // Consumer-supplied providers first so they can override internal ones.
26267
- ...extraProviders,
26882
+ ...withGuardedViews(extraProviders),
26268
26883
  // Resolved options (depends on consumer's inject tokens).
26269
26884
  resolvedOptionsProvider,
26270
26885
  // Which controllers this registration mounted, and the contributor that reads it.