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