@bymax-one/nest-auth 1.5.11 → 1.5.12

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) {
@@ -5933,10 +5938,10 @@ var AccountStatusService = class _AccountStatusService {
5933
5938
  AccountStatusService = _ts_decorate12([
5934
5939
  Injectable(),
5935
5940
  _ts_param7(0, Inject(AuthRedisService)),
5936
- _ts_param7(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
5941
+ _ts_param7(1, Inject(GUARDED_USER_REPOSITORY)),
5937
5942
  _ts_param7(2, Inject(BYMAX_AUTH_OPTIONS)),
5938
5943
  _ts_param7(3, Optional()),
5939
- _ts_param7(3, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
5944
+ _ts_param7(3, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
5940
5945
  _ts_metadata12("design:type", Function),
5941
5946
  _ts_metadata12("design:paramtypes", [
5942
5947
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService,
@@ -7148,6 +7153,532 @@ PasswordService = _ts_decorate20([
7148
7153
  ])
7149
7154
  ], PasswordService);
7150
7155
 
7156
+ // src/server/utils/repository-contracts.ts
7157
+ var RECORD_CONTRACTS = {
7158
+ workspace: {
7159
+ fields: {
7160
+ id: "~id",
7161
+ tenantId: "id",
7162
+ name: "~string",
7163
+ status: "string",
7164
+ createdAt: "~date",
7165
+ deletionScheduledAt: "date|null"
7166
+ },
7167
+ nested: {}
7168
+ },
7169
+ membership: {
7170
+ fields: {
7171
+ tenantId: "id",
7172
+ workspaceId: "~id",
7173
+ userId: "~id",
7174
+ role: "string",
7175
+ status: "string",
7176
+ invitedByUserId: "~id",
7177
+ createdAt: "~date",
7178
+ updatedAt: "~date"
7179
+ },
7180
+ nested: {}
7181
+ },
7182
+ user: {
7183
+ fields: {
7184
+ id: "~id",
7185
+ email: "~string",
7186
+ name: "~string",
7187
+ passwordHash: "string|null",
7188
+ role: "string",
7189
+ status: "string",
7190
+ tenantId: "id",
7191
+ emailVerified: "boolean",
7192
+ mfaEnabled: "boolean",
7193
+ mfaSecret: "string?",
7194
+ mfaRecoveryCodes: "strings?",
7195
+ oauthProvider: "~string",
7196
+ oauthProviderId: "~string",
7197
+ lastLoginAt: "~date",
7198
+ createdAt: "~date"
7199
+ },
7200
+ nested: {}
7201
+ },
7202
+ platformUser: {
7203
+ fields: {
7204
+ id: "~id",
7205
+ email: "~string",
7206
+ name: "~string",
7207
+ passwordHash: "string",
7208
+ role: "string",
7209
+ status: "string",
7210
+ mfaEnabled: "boolean",
7211
+ mfaSecret: "string?",
7212
+ mfaRecoveryCodes: "strings?",
7213
+ platformId: "~id",
7214
+ lastLoginAt: "~date",
7215
+ updatedAt: "~date",
7216
+ createdAt: "~date"
7217
+ },
7218
+ nested: {}
7219
+ },
7220
+ apiKey: {
7221
+ fields: {
7222
+ id: "~id",
7223
+ label: "~string",
7224
+ digest: "string",
7225
+ scopes: "strings",
7226
+ createdAt: "~date",
7227
+ expiresAt: "date|null",
7228
+ revokedAt: "date|null",
7229
+ lastUsedAt: "~date"
7230
+ },
7231
+ nested: {}
7232
+ },
7233
+ removedMembership: {
7234
+ fields: {
7235
+ workspaceId: "~id",
7236
+ role: "string"
7237
+ },
7238
+ nested: {}
7239
+ }
7240
+ };
7241
+ var WORKSPACE = RECORD_CONTRACTS.workspace;
7242
+ var MEMBERSHIP = RECORD_CONTRACTS.membership;
7243
+ var USER = RECORD_CONTRACTS.user;
7244
+ var PLATFORM_USER = RECORD_CONTRACTS.platformUser;
7245
+ var API_KEY = RECORD_CONTRACTS.apiKey;
7246
+ var REMOVED_MEMBERSHIP = RECORD_CONTRACTS.removedMembership;
7247
+ var MEMBERSHIP_WITH_WORKSPACE = {
7248
+ fields: {
7249
+ ...MEMBERSHIP.fields,
7250
+ workspace: "nested"
7251
+ },
7252
+ nested: {
7253
+ workspace: WORKSPACE
7254
+ }
7255
+ };
7256
+ var PAGE_OF_MEMBERSHIPS_WITH_WORKSPACE = {
7257
+ fields: {
7258
+ items: "nested",
7259
+ nextCursor: "~string"
7260
+ },
7261
+ nested: {
7262
+ items: {
7263
+ list: MEMBERSHIP_WITH_WORKSPACE
7264
+ }
7265
+ }
7266
+ };
7267
+ var PAGE_OF_MEMBERSHIPS = {
7268
+ fields: {
7269
+ items: "nested",
7270
+ nextCursor: "~string"
7271
+ },
7272
+ nested: {
7273
+ items: {
7274
+ list: MEMBERSHIP
7275
+ }
7276
+ }
7277
+ };
7278
+ var PAGE_OF_WORKSPACES = {
7279
+ fields: {
7280
+ items: "nested",
7281
+ nextCursor: "~string"
7282
+ },
7283
+ nested: {
7284
+ items: {
7285
+ list: WORKSPACE
7286
+ }
7287
+ }
7288
+ };
7289
+ var orNothing = /* @__PURE__ */ __name((contract) => ({
7290
+ ...contract,
7291
+ nullable: true
7292
+ }), "orNothing");
7293
+ var USER_REPOSITORY_CONTRACT = {
7294
+ findById: orNothing(USER),
7295
+ findByEmail: orNothing(USER),
7296
+ create: USER,
7297
+ updatePassword: "void",
7298
+ updateMfa: "void",
7299
+ updateLastLogin: "void",
7300
+ updateStatus: "void",
7301
+ updateEmailVerified: "void",
7302
+ updateEmail: "void",
7303
+ findByOAuthId: orNothing(USER),
7304
+ linkOAuth: "void",
7305
+ createWithOAuth: USER
7306
+ };
7307
+ var PLATFORM_USER_REPOSITORY_CONTRACT = {
7308
+ findById: orNothing(PLATFORM_USER),
7309
+ findByEmail: orNothing(PLATFORM_USER),
7310
+ updateLastLogin: "void",
7311
+ updateMfa: "void",
7312
+ updatePassword: "void",
7313
+ updateStatus: "void"
7314
+ };
7315
+ var API_KEY_REPOSITORY_CONTRACT = {
7316
+ findById: orNothing(API_KEY),
7317
+ create: API_KEY,
7318
+ markRevoked: "boolean",
7319
+ setExpiry: "boolean",
7320
+ limitExpiry: "boolean",
7321
+ touchLastUsed: "void",
7322
+ listByLabel: {
7323
+ list: API_KEY
7324
+ }
7325
+ };
7326
+ var WORKSPACE_REPOSITORY_CONTRACT = {
7327
+ createWithOwner: {
7328
+ fields: {
7329
+ status: "string",
7330
+ workspace: "nested?"
7331
+ },
7332
+ nested: {
7333
+ workspace: WORKSPACE
7334
+ }
7335
+ },
7336
+ findById: orNothing(WORKSPACE),
7337
+ rename: "string",
7338
+ updateStatus: "string"
7339
+ };
7340
+ var MEMBERSHIP_REPOSITORY_CONTRACT = {
7341
+ find: orNothing(MEMBERSHIP),
7342
+ listForUser: PAGE_OF_MEMBERSHIPS_WITH_WORKSPACE,
7343
+ listForWorkspace: PAGE_OF_MEMBERSHIPS,
7344
+ create: "string",
7345
+ changeRole: "string",
7346
+ remove: "string",
7347
+ removeAllForUser: {
7348
+ fields: {
7349
+ result: "string",
7350
+ removed: "nested?",
7351
+ workspaceIds: "strings?"
7352
+ },
7353
+ nested: {
7354
+ removed: {
7355
+ list: REMOVED_MEMBERSHIP
7356
+ }
7357
+ }
7358
+ },
7359
+ transferOwnership: "string",
7360
+ countOwned: "number",
7361
+ listSoleOwned: PAGE_OF_WORKSPACES,
7362
+ getLastActiveWorkspaceId: "string|null",
7363
+ setLastActiveWorkspaceId: "void"
7364
+ };
7365
+ var CREDENTIAL_FIELDS = /* @__PURE__ */ new Set([
7366
+ "passwordHash",
7367
+ "mfaSecret",
7368
+ "mfaRecoveryCodes",
7369
+ "digest"
7370
+ ]);
7371
+
7372
+ // src/server/utils/host-read.ts
7373
+ var MAX_BREADTH = 1e5;
7374
+ function copiedUnder(seen, value, contract) {
7375
+ return seen.get(value)?.get(contract);
7376
+ }
7377
+ __name(copiedUnder, "copiedUnder");
7378
+ function rememberUnder(seen, value, contract, copy) {
7379
+ const copies = seen.get(value) ?? /* @__PURE__ */ new Map();
7380
+ copies.set(contract, copy);
7381
+ seen.set(value, copies);
7382
+ }
7383
+ __name(rememberUnder, "rememberUnder");
7384
+ function readHostOptions(read) {
7385
+ try {
7386
+ return read();
7387
+ } catch (error) {
7388
+ throw configurationError(error);
7389
+ }
7390
+ }
7391
+ __name(readHostOptions, "readHostOptions");
7392
+ async function readHostOptionsAsync(read) {
7393
+ try {
7394
+ return {
7395
+ value: await read()
7396
+ };
7397
+ } catch (error) {
7398
+ throw configurationError(error);
7399
+ }
7400
+ }
7401
+ __name(readHostOptionsAsync, "readHostOptionsAsync");
7402
+ function callFactory(factory, args) {
7403
+ return readHostOptionsAsync(async () => factory(...args));
7404
+ }
7405
+ __name(callFactory, "callFactory");
7406
+ function hostHasKey(host, key) {
7407
+ return readHostOptions(() => key in host);
7408
+ }
7409
+ __name(hostHasKey, "hostHasKey");
7410
+ function configurationError(error) {
7411
+ if (error instanceof Error && error.message.startsWith("[BymaxAuthModule]")) return error;
7412
+ return new Error("[BymaxAuthModule] the options could not be read: the factory, a getter or a Proxy of the host threw", {
7413
+ cause: error
7414
+ });
7415
+ }
7416
+ __name(configurationError, "configurationError");
7417
+ function define(copy, key, value, enumerable) {
7418
+ Object.defineProperty(copy, key, {
7419
+ value,
7420
+ enumerable,
7421
+ writable: true,
7422
+ configurable: true
7423
+ });
7424
+ }
7425
+ __name(define, "define");
7426
+ var ENTITIES = /* @__PURE__ */ new WeakMap();
7427
+ function refuseBreadth(size) {
7428
+ if (size > MAX_BREADTH) throw new Error("the answer holds more than the library follows");
7429
+ }
7430
+ __name(refuseBreadth, "refuseBreadth");
7431
+ function isDateLike(value) {
7432
+ return types.isDate(value) || types.isProxy(value) && value instanceof Date;
7433
+ }
7434
+ __name(isDateLike, "isDateLike");
7435
+ function isPlainObject(value) {
7436
+ const prototype = Object.getPrototypeOf(value);
7437
+ return prototype === null || Object.getPrototypeOf(prototype) === null;
7438
+ }
7439
+ __name(isPlainObject, "isPlainObject");
7440
+ var WRONG_KIND = "the answer holds a value that is not the kind its method promises";
7441
+ var ABSENT = "the answer lacks a field its method promises";
7442
+ var NOT_A_TIME = "the answer holds a date that is not a time";
7443
+ function accept(ok, value) {
7444
+ if (!ok) throw new Error(WRONG_KIND);
7445
+ return value;
7446
+ }
7447
+ __name(accept, "accept");
7448
+ function isHostInstance(value) {
7449
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !types.isBoxedPrimitive(value) && !isPlainObject(value);
7450
+ }
7451
+ __name(isHostInstance, "isHostInstance");
7452
+ function copyDate(value) {
7453
+ if (typeof value !== "object" || value === null || !isDateLike(value)) throw new Error(WRONG_KIND);
7454
+ const time = value.getTime();
7455
+ const copy = new Date(typeof time === "number" ? time : Number.NaN);
7456
+ if (Number.isNaN(copy.getTime())) throw new Error(NOT_A_TIME);
7457
+ return copy;
7458
+ }
7459
+ __name(copyDate, "copyDate");
7460
+ function copyStrings(value) {
7461
+ if (!Array.isArray(value)) throw new Error(WRONG_KIND);
7462
+ refuseBreadth(value.length);
7463
+ const copy = [];
7464
+ for (let index = 0; index < value.length; index += 1) {
7465
+ const element = value[index];
7466
+ copy.push(accept(typeof element === "string", element));
7467
+ }
7468
+ return copy;
7469
+ }
7470
+ __name(copyStrings, "copyStrings");
7471
+ function readInforming(value) {
7472
+ return accept(typeof value === "string" || Number.isFinite(value) || isHostInstance(value), value);
7473
+ }
7474
+ __name(readInforming, "readInforming");
7475
+ function readInformingDate(value) {
7476
+ if (typeof value === "string" || Number.isFinite(value)) return value;
7477
+ if (!isHostInstance(value)) throw new Error(WRONG_KIND);
7478
+ if (!isDateLike(value)) return value;
7479
+ const time = value.getTime();
7480
+ const copy = new Date(typeof time === "number" ? time : Number.NaN);
7481
+ return Number.isNaN(copy.getTime()) ? value : copy;
7482
+ }
7483
+ __name(readInformingDate, "readInformingDate");
7484
+ var READERS = {
7485
+ boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
7486
+ string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
7487
+ number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
7488
+ id: /* @__PURE__ */ __name((value) => accept(typeof value === "string" || isHostInstance(value), value), "id"),
7489
+ date: copyDate,
7490
+ strings: copyStrings,
7491
+ "~id": readInforming,
7492
+ "~string": readInforming,
7493
+ "~date": readInformingDate
7494
+ };
7495
+ function parseSpec(spec) {
7496
+ const lenient = spec.startsWith("~");
7497
+ const optional = lenient || spec.endsWith("?");
7498
+ const rest = spec.endsWith("?") ? spec.slice(0, -1) : spec;
7499
+ const nullable = lenient || rest.endsWith("|null");
7500
+ return {
7501
+ base: rest.endsWith("|null") ? rest.slice(0, -"|null".length) : rest,
7502
+ nullable,
7503
+ optional
7504
+ };
7505
+ }
7506
+ __name(parseSpec, "parseSpec");
7507
+ function readNull(nullable) {
7508
+ if (!nullable) throw new Error(WRONG_KIND);
7509
+ return null;
7510
+ }
7511
+ __name(readNull, "readNull");
7512
+ function readScalar(value, spec) {
7513
+ const { base, nullable } = parseSpec(spec);
7514
+ if (base === "void") return void 0;
7515
+ return value === null ? readNull(nullable) : READERS[base](value);
7516
+ }
7517
+ __name(readScalar, "readScalar");
7518
+ function copyRecord(value, contract, seen) {
7519
+ const copy = {};
7520
+ rememberUnder(seen, value, contract, copy);
7521
+ ENTITIES.set(copy, value);
7522
+ const source = value;
7523
+ const keys = Object.keys(value);
7524
+ refuseBreadth(keys.length);
7525
+ for (const key of keys) {
7526
+ if (Object.hasOwn(contract.fields, key)) continue;
7527
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
7528
+ if (descriptor !== void 0 && "value" in descriptor) define(copy, key, descriptor.value, true);
7529
+ }
7530
+ const own = new Set(keys);
7531
+ for (const [field, spec] of Object.entries(contract.fields)) {
7532
+ const { base, nullable, optional } = parseSpec(spec);
7533
+ const read = source[field];
7534
+ if (read === void 0) {
7535
+ if (optional) continue;
7536
+ throw new Error(ABSENT);
7537
+ }
7538
+ const copied = read === null ? readNull(nullable || optional) : base === "nested" ? applyContract(read, contract.nested[field], seen) : READERS[base](read);
7539
+ define(copy, field, copied, own.has(field) || !CREDENTIAL_FIELDS.has(field));
7540
+ }
7541
+ return copy;
7542
+ }
7543
+ __name(copyRecord, "copyRecord");
7544
+ function applyContract(value, contract, seen) {
7545
+ if (typeof value !== "object" || value === null) throw new Error(WRONG_KIND);
7546
+ const known = copiedUnder(seen, value, contract);
7547
+ if (known !== void 0) return known;
7548
+ if ("list" in contract) {
7549
+ if (!Array.isArray(value)) throw new Error("the answer is not the list its method promises");
7550
+ refuseBreadth(value.length);
7551
+ const copy = [];
7552
+ rememberUnder(seen, value, contract, copy);
7553
+ for (let index = 0; index < value.length; index += 1) copy.push(applyContract(value[index], contract.list, seen));
7554
+ return copy;
7555
+ }
7556
+ if (Array.isArray(value)) throw new Error("the answer is not the record its method promises");
7557
+ return copyRecord(value, contract, seen);
7558
+ }
7559
+ __name(applyContract, "applyContract");
7560
+ function copyHostRecord(record, contract) {
7561
+ try {
7562
+ if (typeof contract === "string") return readScalar(record, contract);
7563
+ if ((record === null || record === void 0) && contract.nullable === true) return record;
7564
+ return applyContract(record, contract, /* @__PURE__ */ new WeakMap());
7565
+ } catch (error) {
7566
+ throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
7567
+ cause: error
7568
+ });
7569
+ }
7570
+ }
7571
+ __name(copyHostRecord, "copyHostRecord");
7572
+ function isTypedError(error) {
7573
+ try {
7574
+ return error instanceof HttpException;
7575
+ } catch {
7576
+ return false;
7577
+ }
7578
+ }
7579
+ __name(isTypedError, "isTypedError");
7580
+ var LIFECYCLE_HOOKS = /* @__PURE__ */ new Set([
7581
+ "onModuleInit",
7582
+ "onApplicationBootstrap",
7583
+ "onModuleDestroy",
7584
+ "beforeApplicationShutdown",
7585
+ "onApplicationShutdown"
7586
+ ]);
7587
+ function hostEntityOf(record) {
7588
+ return typeof record === "object" && record !== null ? ENTITIES.get(record) ?? record : record;
7589
+ }
7590
+ __name(hostEntityOf, "hostEntityOf");
7591
+ function guardRepository(host, contract) {
7592
+ return new Proxy({}, {
7593
+ get(_target, key) {
7594
+ if (LIFECYCLE_HOOKS.has(key)) return void 0;
7595
+ let member;
7596
+ try {
7597
+ member = Reflect.get(host, key, host);
7598
+ } catch (error) {
7599
+ if (key === "then" || typeof key === "symbol") return void 0;
7600
+ return async () => {
7601
+ throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
7602
+ cause: error
7603
+ });
7604
+ };
7605
+ }
7606
+ if (typeof member !== "function") return member;
7607
+ return async (...args) => {
7608
+ let answer;
7609
+ try {
7610
+ answer = await member.apply(host, args);
7611
+ } catch (error) {
7612
+ if (isTypedError(error)) throw error;
7613
+ throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
7614
+ cause: error
7615
+ });
7616
+ }
7617
+ const promised = typeof key === "string" && Object.hasOwn(contract, key) ? contract[key] : void 0;
7618
+ return promised === void 0 ? answer : copyHostRecord(answer, promised);
7619
+ };
7620
+ }
7621
+ });
7622
+ }
7623
+ __name(guardRepository, "guardRepository");
7624
+ var GUARDED_BY_HOST = /* @__PURE__ */ new Map([
7625
+ [
7626
+ BYMAX_AUTH_USER_REPOSITORY,
7627
+ [
7628
+ GUARDED_USER_REPOSITORY,
7629
+ USER_REPOSITORY_CONTRACT
7630
+ ]
7631
+ ],
7632
+ [
7633
+ BYMAX_AUTH_PLATFORM_USER_REPOSITORY,
7634
+ [
7635
+ GUARDED_PLATFORM_USER_REPOSITORY,
7636
+ PLATFORM_USER_REPOSITORY_CONTRACT
7637
+ ]
7638
+ ],
7639
+ [
7640
+ BYMAX_AUTH_API_KEY_REPOSITORY,
7641
+ [
7642
+ GUARDED_API_KEY_REPOSITORY,
7643
+ API_KEY_REPOSITORY_CONTRACT
7644
+ ]
7645
+ ],
7646
+ [
7647
+ BYMAX_AUTH_WORKSPACE_REPOSITORY,
7648
+ [
7649
+ GUARDED_WORKSPACE_REPOSITORY,
7650
+ WORKSPACE_REPOSITORY_CONTRACT
7651
+ ]
7652
+ ],
7653
+ [
7654
+ BYMAX_AUTH_MEMBERSHIP_REPOSITORY,
7655
+ [
7656
+ GUARDED_MEMBERSHIP_REPOSITORY,
7657
+ MEMBERSHIP_REPOSITORY_CONTRACT
7658
+ ]
7659
+ ]
7660
+ ]);
7661
+ function guardedViewProvider(host, guarded, contract) {
7662
+ return {
7663
+ provide: guarded,
7664
+ useFactory: /* @__PURE__ */ __name((repository) => guardRepository(repository, contract), "useFactory"),
7665
+ inject: [
7666
+ host
7667
+ ]
7668
+ };
7669
+ }
7670
+ __name(guardedViewProvider, "guardedViewProvider");
7671
+ function withGuardedViews(providers) {
7672
+ const views = [
7673
+ ...GUARDED_BY_HOST
7674
+ ].filter(([host]) => providers.some((provider) => typeof provider !== "function" && "provide" in provider && provider.provide === host)).map(([host, [guarded, contract]]) => guardedViewProvider(host, guarded, contract));
7675
+ return [
7676
+ ...providers,
7677
+ ...views
7678
+ ];
7679
+ }
7680
+ __name(withGuardedViews, "withGuardedViews");
7681
+
7151
7682
  // src/server/utils/run-detached.ts
7152
7683
  function runDetached(logger, run, hook) {
7153
7684
  try {
@@ -7882,10 +8413,9 @@ var SessionService = class _SessionService {
7882
8413
  /**
7883
8414
  * Resolves the maximum number of concurrent sessions allowed for a user.
7884
8415
  *
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.
8416
+ * When `options.sessions.maxSessionsResolver` is configured, it is called with the entity the user
8417
+ * repository returned. Falls back to `options.sessions.defaultMaxSessions` if the resolver is absent,
8418
+ * the user cannot be found, the resolver throws, or it answers with an unusable limit.
7889
8419
  *
7890
8420
  * That last case is the one that mattered. The resolver is the host's code and its return
7891
8421
  * value went straight into the eviction arithmetic, where `NaN` — the result of, say,
@@ -7910,7 +8440,7 @@ var SessionService = class _SessionService {
7910
8440
  tenantId
7911
8441
  });
7912
8442
  if (!user) return defaultMaxSessions;
7913
- const resolved = await maxSessionsResolver(user);
8443
+ const resolved = await maxSessionsResolver(hostEntityOf(user));
7914
8444
  if (!Number.isInteger(resolved) || resolved < 1) {
7915
8445
  logEvent(this.logger, "AUTH_SESSION_LIMIT_RESOLVER_INVALID");
7916
8446
  return defaultMaxSessions;
@@ -7925,7 +8455,7 @@ var SessionService = class _SessionService {
7925
8455
  SessionService = _ts_decorate21([
7926
8456
  Injectable(),
7927
8457
  _ts_param13(0, Inject(BYMAX_AUTH_OPTIONS)),
7928
- _ts_param13(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
8458
+ _ts_param13(1, Inject(GUARDED_USER_REPOSITORY)),
7929
8459
  _ts_param13(2, Inject(BYMAX_AUTH_HOOKS)),
7930
8460
  _ts_param13(2, Optional()),
7931
8461
  _ts_param13(3, Inject(AuthRedisService)),
@@ -10134,7 +10664,7 @@ var AuthService = class _AuthService {
10134
10664
  AuthService = _ts_decorate23([
10135
10665
  Injectable(),
10136
10666
  _ts_param15(0, Inject(BYMAX_AUTH_OPTIONS)),
10137
- _ts_param15(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
10667
+ _ts_param15(1, Inject(GUARDED_USER_REPOSITORY)),
10138
10668
  _ts_param15(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
10139
10669
  _ts_param15(2, Optional()),
10140
10670
  _ts_param15(3, Inject(BYMAX_AUTH_HOOKS)),
@@ -10345,7 +10875,7 @@ WsTicketService = _ts_decorate24([
10345
10875
  Injectable(),
10346
10876
  _ts_param16(0, Inject(AuthRedisService)),
10347
10877
  _ts_param16(1, Inject(BYMAX_AUTH_OPTIONS)),
10348
- _ts_param16(2, Inject(BYMAX_AUTH_USER_REPOSITORY)),
10878
+ _ts_param16(2, Inject(GUARDED_USER_REPOSITORY)),
10349
10879
  _ts_param16(3, Inject(AuthRevocationService)),
10350
10880
  _ts_metadata21("design:type", Function),
10351
10881
  _ts_metadata21("design:paramtypes", [
@@ -11045,7 +11575,7 @@ var EmailChangeService = class _EmailChangeService {
11045
11575
  EmailChangeService = _ts_decorate28([
11046
11576
  Injectable(),
11047
11577
  _ts_param18(0, Inject(BYMAX_AUTH_OPTIONS)),
11048
- _ts_param18(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
11578
+ _ts_param18(1, Inject(GUARDED_USER_REPOSITORY)),
11049
11579
  _ts_param18(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
11050
11580
  _ts_param18(3, Inject(PasswordService)),
11051
11581
  _ts_param18(4, Inject(AuthRedisService)),
@@ -11875,7 +12405,7 @@ var InvitationService = class _InvitationService {
11875
12405
  };
11876
12406
  InvitationService = _ts_decorate33([
11877
12407
  Injectable(),
11878
- _ts_param20(0, Inject(BYMAX_AUTH_USER_REPOSITORY)),
12408
+ _ts_param20(0, Inject(GUARDED_USER_REPOSITORY)),
11879
12409
  _ts_param20(1, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
11880
12410
  _ts_param20(2, Inject(BYMAX_AUTH_HOOKS)),
11881
12411
  _ts_param20(3, Inject(AuthRedisService)),
@@ -12773,9 +13303,9 @@ var MfaRecordService = class {
12773
13303
  MfaRecordService = _ts_decorate41([
12774
13304
  Injectable(),
12775
13305
  _ts_param23(0, Inject(BYMAX_AUTH_OPTIONS)),
12776
- _ts_param23(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
13306
+ _ts_param23(1, Inject(GUARDED_USER_REPOSITORY)),
12777
13307
  _ts_param23(2, Optional()),
12778
- _ts_param23(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
13308
+ _ts_param23(2, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
12779
13309
  _ts_param23(3, Inject(AuthRedisService)),
12780
13310
  _ts_metadata38("design:type", Function),
12781
13311
  _ts_metadata38("design:paramtypes", [
@@ -13171,9 +13701,9 @@ var MfaChallengeService = class {
13171
13701
  MfaChallengeService = _ts_decorate42([
13172
13702
  Injectable(),
13173
13703
  _ts_param24(0, Inject(BYMAX_AUTH_OPTIONS)),
13174
- _ts_param24(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
13704
+ _ts_param24(1, Inject(GUARDED_USER_REPOSITORY)),
13175
13705
  _ts_param24(2, Optional()),
13176
- _ts_param24(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
13706
+ _ts_param24(2, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
13177
13707
  _ts_param24(3, Inject(TokenManagerService)),
13178
13708
  _ts_param24(4, Inject(MfaFlowLockoutService)),
13179
13709
  _ts_param24(5, Inject(MfaRecordService)),
@@ -13565,7 +14095,7 @@ MfaManagementService = _ts_decorate43([
13565
14095
  Injectable(),
13566
14096
  _ts_param25(0, Inject(BYMAX_AUTH_OPTIONS)),
13567
14097
  _ts_param25(1, Optional()),
13568
- _ts_param25(1, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
14098
+ _ts_param25(1, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
13569
14099
  _ts_param25(2, Inject(AuthRedisService)),
13570
14100
  _ts_param25(3, Inject(MfaFlowLockoutService)),
13571
14101
  _ts_param25(4, Inject(MfaRecordService)),
@@ -14087,9 +14617,9 @@ var MfaService = class _MfaService {
14087
14617
  MfaService = _ts_decorate45([
14088
14618
  Injectable(),
14089
14619
  _ts_param27(0, Inject(BYMAX_AUTH_OPTIONS)),
14090
- _ts_param27(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
14620
+ _ts_param27(1, Inject(GUARDED_USER_REPOSITORY)),
14091
14621
  _ts_param27(2, Optional()),
14092
- _ts_param27(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
14622
+ _ts_param27(2, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
14093
14623
  _ts_param27(3, Inject(AuthRedisService)),
14094
14624
  _ts_param27(4, Inject(TokenManagerService)),
14095
14625
  _ts_param27(5, Inject(MfaRecordService)),
@@ -15480,7 +16010,7 @@ var PasswordResetService = class _PasswordResetService {
15480
16010
  PasswordResetService = _ts_decorate52([
15481
16011
  Injectable(),
15482
16012
  _ts_param29(0, Inject(BYMAX_AUTH_OPTIONS)),
15483
- _ts_param29(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
16013
+ _ts_param29(1, Inject(GUARDED_USER_REPOSITORY)),
15484
16014
  _ts_param29(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
15485
16015
  _ts_param29(2, Optional()),
15486
16016
  _ts_param29(3, Inject(BYMAX_AUTH_HOOKS)),
@@ -16236,7 +16766,7 @@ var PlatformAuthService = class _PlatformAuthService {
16236
16766
  };
16237
16767
  PlatformAuthService = _ts_decorate56([
16238
16768
  Injectable(),
16239
- _ts_param32(0, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
16769
+ _ts_param32(0, Inject(GUARDED_PLATFORM_USER_REPOSITORY)),
16240
16770
  _ts_param32(1, Inject(PasswordService)),
16241
16771
  _ts_param32(2, Inject(TokenManagerService)),
16242
16772
  _ts_param32(3, Inject(BruteForceService)),
@@ -17520,8 +18050,8 @@ var WorkspaceAccessService = class _WorkspaceAccessService {
17520
18050
  WorkspaceAccessService = _ts_decorate66([
17521
18051
  Injectable(),
17522
18052
  _ts_param36(0, Inject(AuthRedisService)),
17523
- _ts_param36(1, Inject(BYMAX_AUTH_WORKSPACE_REPOSITORY)),
17524
- _ts_param36(2, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
18053
+ _ts_param36(1, Inject(GUARDED_WORKSPACE_REPOSITORY)),
18054
+ _ts_param36(2, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
17525
18055
  _ts_param36(3, Inject(BYMAX_AUTH_OPTIONS)),
17526
18056
  _ts_param36(4, Inject(AccountStatusService)),
17527
18057
  _ts_param36(4, Optional()),
@@ -18400,7 +18930,7 @@ var MembershipService = class {
18400
18930
  };
18401
18931
  MembershipService = _ts_decorate70([
18402
18932
  Injectable(),
18403
- _ts_param40(0, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
18933
+ _ts_param40(0, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
18404
18934
  _ts_param40(1, Inject(WorkspaceAccessService)),
18405
18935
  _ts_param40(2, Inject(WorkspaceEventsService)),
18406
18936
  _ts_param40(3, Inject(BYMAX_AUTH_OPTIONS)),
@@ -19105,9 +19635,9 @@ WorkspaceInvitationAcceptService = _ts_decorate72([
19105
19635
  _ts_param42(4, Inject(PasswordService)),
19106
19636
  _ts_param42(5, Inject(TokenManagerService)),
19107
19637
  _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)),
19638
+ _ts_param42(7, Inject(GUARDED_USER_REPOSITORY)),
19639
+ _ts_param42(8, Inject(GUARDED_WORKSPACE_REPOSITORY)),
19640
+ _ts_param42(9, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
19111
19641
  _ts_param42(10, Inject(BYMAX_AUTH_HOOKS)),
19112
19642
  _ts_param42(11, Inject(BYMAX_AUTH_OPTIONS)),
19113
19643
  _ts_metadata69("design:type", Function),
@@ -19589,9 +20119,9 @@ WorkspaceInvitationService = _ts_decorate73([
19589
20119
  _ts_param43(1, Inject(AuthRedisService)),
19590
20120
  _ts_param43(2, Inject(MembershipService)),
19591
20121
  _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)),
20122
+ _ts_param43(4, Inject(GUARDED_USER_REPOSITORY)),
20123
+ _ts_param43(5, Inject(GUARDED_WORKSPACE_REPOSITORY)),
20124
+ _ts_param43(6, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
19595
20125
  _ts_param43(7, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
19596
20126
  _ts_param43(8, Inject(BYMAX_AUTH_OPTIONS)),
19597
20127
  _ts_metadata70("design:type", Function),
@@ -20272,7 +20802,7 @@ var WorkspaceCallerService = class {
20272
20802
  };
20273
20803
  WorkspaceCallerService = _ts_decorate81([
20274
20804
  Injectable(),
20275
- _ts_param45(0, Inject(BYMAX_AUTH_USER_REPOSITORY)),
20805
+ _ts_param45(0, Inject(GUARDED_USER_REPOSITORY)),
20276
20806
  _ts_param45(1, Inject(ReauthenticationService)),
20277
20807
  _ts_metadata78("design:type", Function),
20278
20808
  _ts_metadata78("design:paramtypes", [
@@ -20609,8 +21139,8 @@ var WorkspaceService = class {
20609
21139
  };
20610
21140
  WorkspaceService = _ts_decorate82([
20611
21141
  Injectable(),
20612
- _ts_param46(0, Inject(BYMAX_AUTH_WORKSPACE_REPOSITORY)),
20613
- _ts_param46(1, Inject(BYMAX_AUTH_MEMBERSHIP_REPOSITORY)),
21142
+ _ts_param46(0, Inject(GUARDED_WORKSPACE_REPOSITORY)),
21143
+ _ts_param46(1, Inject(GUARDED_MEMBERSHIP_REPOSITORY)),
20614
21144
  _ts_param46(2, Inject(WorkspaceAccessService)),
20615
21145
  _ts_param46(3, Inject(WorkspaceEventsService)),
20616
21146
  _ts_param46(4, Inject(BYMAX_AUTH_HOOKS)),
@@ -21412,7 +21942,7 @@ var ApiKeyLastUsedService = class _ApiKeyLastUsedService {
21412
21942
  };
21413
21943
  ApiKeyLastUsedService = _ts_decorate85([
21414
21944
  Injectable(),
21415
- _ts_param49(0, Inject(BYMAX_AUTH_API_KEY_REPOSITORY)),
21945
+ _ts_param49(0, Inject(GUARDED_API_KEY_REPOSITORY)),
21416
21946
  _ts_param49(1, Inject(BYMAX_AUTH_OPTIONS)),
21417
21947
  _ts_metadata82("design:type", Function),
21418
21948
  _ts_metadata82("design:paramtypes", [
@@ -21551,7 +22081,7 @@ var ApiKeyVerifierService = class {
21551
22081
  };
21552
22082
  ApiKeyVerifierService = _ts_decorate86([
21553
22083
  Injectable(),
21554
- _ts_param50(0, Inject(BYMAX_AUTH_API_KEY_REPOSITORY)),
22084
+ _ts_param50(0, Inject(GUARDED_API_KEY_REPOSITORY)),
21555
22085
  _ts_param50(1, Inject(BYMAX_AUTH_API_KEY_CLOCK)),
21556
22086
  _ts_param50(2, Inject(BYMAX_AUTH_OPTIONS)),
21557
22087
  _ts_param50(3, Inject(ApiKeyLastUsedService)),
@@ -22706,7 +23236,7 @@ var OAuthService = class _OAuthService {
22706
23236
  OAuthService = _ts_decorate93([
22707
23237
  Injectable(),
22708
23238
  _ts_param56(0, Inject(OAUTH_PLUGINS)),
22709
- _ts_param56(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
23239
+ _ts_param56(1, Inject(GUARDED_USER_REPOSITORY)),
22710
23240
  _ts_param56(2, Inject(BYMAX_AUTH_HOOKS)),
22711
23241
  _ts_param56(2, Optional()),
22712
23242
  _ts_param56(3, Inject(AuthRedisService)),
@@ -23459,9 +23989,10 @@ var OAuthModule = class _OAuthModule {
23459
23989
  /**
23460
23990
  * Returns the provider array for inline inclusion in `BymaxAuthModule`.
23461
23991
  *
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.
23992
+ * Includes `OAUTH_PLUGINS` (value provider), `OAuthService` and the guarded view of the host's user repository
23993
+ * that `OAuthService` reads, built from the repository the host provides under `BYMAX_AUTH_USER_REPOSITORY`.
23994
+ * All other dependencies (`AuthRedisService`, etc.) are expected to be present in the parent module's own
23995
+ * providers array.
23465
23996
  *
23466
23997
  * @param options - Fully resolved options from `resolveOptions()`.
23467
23998
  * @returns Provider array ready to be spread into a parent module's `providers`.
@@ -23472,7 +24003,8 @@ var OAuthModule = class _OAuthModule {
23472
24003
  provide: OAUTH_PLUGINS,
23473
24004
  useValue: buildOAuthPlugins(options)
23474
24005
  },
23475
- OAuthService
24006
+ OAuthService,
24007
+ guardedViewProvider(BYMAX_AUTH_USER_REPOSITORY, GUARDED_USER_REPOSITORY, USER_REPOSITORY_CONTRACT)
23476
24008
  ];
23477
24009
  }
23478
24010
  /**
@@ -25669,7 +26201,7 @@ var ApiKeyService = class {
25669
26201
  };
25670
26202
  ApiKeyService = _ts_decorate104([
25671
26203
  Injectable(),
25672
- _ts_param63(0, Inject(BYMAX_AUTH_API_KEY_REPOSITORY)),
26204
+ _ts_param63(0, Inject(GUARDED_API_KEY_REPOSITORY)),
25673
26205
  _ts_param63(1, Inject(BYMAX_AUTH_API_KEY_CLOCK)),
25674
26206
  _ts_param63(2, Inject(BYMAX_AUTH_OPTIONS)),
25675
26207
  _ts_metadata98("design:type", Function),
@@ -26088,11 +26620,11 @@ var BymaxAuthModule = class _BymaxAuthModule {
26088
26620
  const resolvedOptionsProvider = {
26089
26621
  provide: BYMAX_AUTH_OPTIONS,
26090
26622
  useFactory: /* @__PURE__ */ __name(async (...args) => {
26091
- const userOptions = await options.useFactory(...args);
26092
- if ("controllers" in userOptions) {
26623
+ const { value: userOptions } = await callFactory(options.useFactory, args);
26624
+ if (hostHasKey(userOptions, "controllers")) {
26093
26625
  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
26626
  }
26095
- const resolved = resolveOptions(userOptions);
26627
+ const resolved = readHostOptions(() => resolveOptions(userOptions));
26096
26628
  if (includeMfa && resolved.mfa === void 0) {
26097
26629
  throw new Error("[BymaxAuthModule] controllers.mfa: true requires the mfa group (encryptionKey and issuer) to be configured in the useFactory return value.");
26098
26630
  }
@@ -26250,9 +26782,9 @@ var BymaxAuthModule = class _BymaxAuthModule {
26250
26782
  // The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
26251
26783
  imports: options.imports ?? [],
26252
26784
  useFactory: /* @__PURE__ */ __name(async (...args) => {
26253
- const userOptions = await options.useFactory(...args);
26785
+ const { value: userOptions } = await callFactory(options.useFactory, args);
26254
26786
  return {
26255
- secret: userOptions.jwt.secret,
26787
+ secret: readHostOptions(() => userOptions.jwt.secret),
26256
26788
  // Stryker disable next-line ObjectLiteral: jsonwebtoken defaults to HS256 and TokenManagerService overrides signOptions per call, so the emptied `signOptions` produces identical signing
26257
26789
  signOptions: {
26258
26790
  algorithm: "HS256"
@@ -26264,7 +26796,7 @@ var BymaxAuthModule = class _BymaxAuthModule {
26264
26796
  ],
26265
26797
  providers: [
26266
26798
  // Consumer-supplied providers first so they can override internal ones.
26267
- ...extraProviders,
26799
+ ...withGuardedViews(extraProviders),
26268
26800
  // Resolved options (depends on consumer's inject tokens).
26269
26801
  resolvedOptionsProvider,
26270
26802
  // Which controllers this registration mounted, and the contributor that reads it.