najm-auth 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var __export = (target, all) => {
6
6
  };
7
7
 
8
8
  // src/AuthPlugin.ts
9
- import { Err as Err9, plugin } from "najm-core";
9
+ import { Err as Err10, plugin } from "najm-core";
10
10
  import { cache } from "najm-cache";
11
11
 
12
12
  // src/auth.tokens.ts
@@ -18,7 +18,7 @@ var AUTH_PERMISSIONS = /* @__PURE__ */ Symbol.for("najm:auth:permissions");
18
18
  var AUTH_ENCRYPTION_KEY = /* @__PURE__ */ Symbol.for("najm:auth:encryption-key");
19
19
 
20
20
  // src/schema/pg.ts
21
- import { pgTable, text, boolean, timestamp, pgEnum, primaryKey, integer, index } from "drizzle-orm/pg-core";
21
+ import { pgTable, text, boolean, timestamp, pgEnum, primaryKey, integer, index, uniqueIndex } from "drizzle-orm/pg-core";
22
22
  import { sql } from "drizzle-orm";
23
23
  import { nanoid } from "nanoid";
24
24
 
@@ -58,6 +58,16 @@ var usersTable = pgTable("users", {
58
58
  }, (table) => ({
59
59
  roleIdx: index("users_role_id_idx").on(table.roleId)
60
60
  }));
61
+ var oauthAccountsTable = pgTable("oauth_accounts", {
62
+ ...baseFields(10),
63
+ userId: text("user_id").notNull().references(() => usersTable.id, { onDelete: "cascade" }),
64
+ provider: text("provider").notNull(),
65
+ providerAccountId: text("provider_account_id").notNull()
66
+ }, (table) => ({
67
+ providerAccountUnique: uniqueIndex("oauth_accounts_provider_account_unique").on(table.provider, table.providerAccountId),
68
+ userProviderUnique: uniqueIndex("oauth_accounts_user_provider_unique").on(table.userId, table.provider),
69
+ userIdIdx: index("oauth_accounts_user_id_idx").on(table.userId)
70
+ }));
61
71
  var permissionsTable = pgTable("permissions", {
62
72
  ...baseFields(5),
63
73
  name: text("name").notNull().unique(),
@@ -89,6 +99,7 @@ var rolePermissionsTable = pgTable("role_permissions", {
89
99
  }));
90
100
  var authSchema = {
91
101
  users: usersTable,
102
+ oauthAccounts: oauthAccountsTable,
92
103
  tokens: tokensTable,
93
104
  roles: rolesTable,
94
105
  permissions: permissionsTable,
@@ -96,7 +107,7 @@ var authSchema = {
96
107
  };
97
108
 
98
109
  // src/schema/sqlite.ts
99
- import { sqliteTable, text as text2, integer as integer2, uniqueIndex, index as index2 } from "drizzle-orm/sqlite-core";
110
+ import { sqliteTable, text as text2, integer as integer2, uniqueIndex as uniqueIndex2, index as index2 } from "drizzle-orm/sqlite-core";
100
111
  import { sql as sql2 } from "drizzle-orm";
101
112
  import { nanoid as nanoid2 } from "nanoid";
102
113
  var baseFields2 = /* @__PURE__ */ __name((idLength = 5) => ({
@@ -126,6 +137,16 @@ var usersTable2 = sqliteTable("users", {
126
137
  }, (table) => ({
127
138
  roleIdx: index2("users_role_id_idx").on(table.roleId)
128
139
  }));
140
+ var oauthAccountsTable2 = sqliteTable("oauth_accounts", {
141
+ ...baseFields2(10),
142
+ userId: text2("user_id").notNull().references(() => usersTable2.id, { onDelete: "cascade" }),
143
+ provider: text2("provider").notNull(),
144
+ providerAccountId: text2("provider_account_id").notNull()
145
+ }, (table) => ({
146
+ providerAccountUnique: uniqueIndex2("oauth_accounts_provider_account_unique").on(table.provider, table.providerAccountId),
147
+ userProviderUnique: uniqueIndex2("oauth_accounts_user_provider_unique").on(table.userId, table.provider),
148
+ userIdIdx: index2("oauth_accounts_user_id_idx").on(table.userId)
149
+ }));
129
150
  var permissionsTable2 = sqliteTable("permissions", {
130
151
  ...baseFields2(5),
131
152
  name: text2("name").notNull().unique(),
@@ -153,10 +174,11 @@ var rolePermissionsTable2 = sqliteTable("role_permissions", {
153
174
  roleId: text2("role_id").notNull().references(() => rolesTable2.id, { onDelete: "cascade" }),
154
175
  permissionId: text2("permission_id").notNull().references(() => permissionsTable2.id, { onDelete: "cascade" })
155
176
  }, (table) => ({
156
- uniq: uniqueIndex("role_permission_unique").on(table.roleId, table.permissionId)
177
+ uniq: uniqueIndex2("role_permission_unique").on(table.roleId, table.permissionId)
157
178
  }));
158
179
  var authSchema2 = {
159
180
  users: usersTable2,
181
+ oauthAccounts: oauthAccountsTable2,
160
182
  tokens: tokensTable2,
161
183
  roles: rolesTable2,
162
184
  permissions: permissionsTable2,
@@ -381,8 +403,8 @@ import { Get, Post, ResMsg } from "najm-core";
381
403
  import { Body, User as User3, Headers } from "najm-core";
382
404
 
383
405
  // src/auth/AuthService.ts
384
- import { Injectable as Injectable7, Inject as Inject8 } from "najm-core";
385
- import { Err as Err7, Log } from "najm-core";
406
+ import { Injectable as Injectable8, Inject as Inject8 } from "najm-core";
407
+ import { Err as Err8, Log } from "najm-core";
386
408
  import { I18n as I18n6, I18nService as I18nService2 } from "najm-i18n";
387
409
  import { EmailService, passwordResetTemplate, accountInviteTemplate } from "najm-email";
388
410
  import { nanoid as nanoid5 } from "nanoid";
@@ -551,6 +573,15 @@ var UserRepository = class UserRepository2 {
551
573
  }).from(this.users).leftJoin(this.roles, eq2(this.users.roleId, this.roles.id)).where(eq2(this.users.email, email2));
552
574
  return existingUser;
553
575
  }
576
+ async getByEmailInsensitive(email2) {
577
+ const [existingUser] = await this.db.select({
578
+ ...this.q.userSelection(),
579
+ password: this.users.password,
580
+ failedLoginAttempts: this.users.failedLoginAttempts,
581
+ lockoutUntil: this.users.lockoutUntil
582
+ }).from(this.users).leftJoin(this.roles, eq2(this.users.roleId, this.roles.id)).where(sql3`lower(${this.users.email}) = ${email2.trim().toLowerCase()}`).limit(1);
583
+ return existingUser;
584
+ }
554
585
  async create(data) {
555
586
  const [newUser] = await this.db.insert(this.users).values(data).returning();
556
587
  return newUser;
@@ -1193,6 +1224,9 @@ var UserService = class UserService2 {
1193
1224
  async findByEmail(email2) {
1194
1225
  return await this.userRepository.getByEmail(email2);
1195
1226
  }
1227
+ async findByEmailInsensitive(email2) {
1228
+ return await this.userRepository.getByEmailInsensitive(email2);
1229
+ }
1196
1230
  async getAuthRecordById(id) {
1197
1231
  return await this.userRepository.getRawById(id);
1198
1232
  }
@@ -1971,6 +2005,10 @@ TokenService = TokenService_1 = __decorate10([
1971
2005
 
1972
2006
  // src/auth/AuthService.ts
1973
2007
  import timestring3 from "timestring";
2008
+
2009
+ // src/auth/AuthSessionService.ts
2010
+ import { Injectable as Injectable7 } from "najm-core";
2011
+ import { Err as Err7 } from "najm-core";
1974
2012
  var __decorate11 = function(decorators, target, key, desc) {
1975
2013
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1976
2014
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1983,10 +2021,66 @@ var __metadata11 = function(k, v) {
1983
2021
  var _a7;
1984
2022
  var _b5;
1985
2023
  var _c3;
2024
+ var AuthSessionService = class AuthSessionService2 {
2025
+ static {
2026
+ __name(this, "AuthSessionService");
2027
+ }
2028
+ tokenService;
2029
+ userService;
2030
+ cookieManager;
2031
+ constructor(tokenService, userService, cookieManager) {
2032
+ this.tokenService = tokenService;
2033
+ this.userService = userService;
2034
+ this.cookieManager = cookieManager;
2035
+ }
2036
+ async establish(user) {
2037
+ if (user.status !== "active") {
2038
+ Err7("oauth_account_inactive", 403);
2039
+ }
2040
+ await this.tokenService.deleteExpiredSessions();
2041
+ const generated = await this.tokenService.generateTokens(user.id);
2042
+ this.cookieManager.setRefreshToken(generated.refreshToken);
2043
+ await this.userService.updateLastLogin(user.id);
2044
+ const { roles, permissions, sessionVersion } = generated;
2045
+ this.cookieManager.setSessionCookie({
2046
+ user: {
2047
+ id: user.id,
2048
+ email: user.email,
2049
+ name: user.name,
2050
+ role: user.role ?? void 0,
2051
+ status: user.status ?? void 0
2052
+ },
2053
+ roles,
2054
+ permissions,
2055
+ sessionVersion
2056
+ });
2057
+ const { userId: _userId, tokenFamily: _tokenFamily, roles: _roles, permissions: _permissions, sessionVersion: _sessionVersion, ...tokens } = generated;
2058
+ return { ...tokens, user };
2059
+ }
2060
+ };
2061
+ AuthSessionService = __decorate11([
2062
+ Injectable7(),
2063
+ __metadata11("design:paramtypes", [typeof (_a7 = typeof TokenService !== "undefined" && TokenService) === "function" ? _a7 : Object, typeof (_b5 = typeof UserService !== "undefined" && UserService) === "function" ? _b5 : Object, typeof (_c3 = typeof CookieManager !== "undefined" && CookieManager) === "function" ? _c3 : Object])
2064
+ ], AuthSessionService);
2065
+
2066
+ // src/auth/AuthService.ts
2067
+ var __decorate12 = function(decorators, target, key, desc) {
2068
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2069
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2070
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2071
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2072
+ };
2073
+ var __metadata12 = function(k, v) {
2074
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2075
+ };
2076
+ var _a8;
2077
+ var _b6;
2078
+ var _c4;
1986
2079
  var _d2;
1987
2080
  var _e2;
1988
2081
  var _f2;
1989
2082
  var _g2;
2083
+ var _h2;
1990
2084
  var AuthService = class AuthService2 {
1991
2085
  static {
1992
2086
  __name(this, "AuthService");
@@ -1998,11 +2092,12 @@ var AuthService = class AuthService2 {
1998
2092
  cookieManager;
1999
2093
  i18nService;
2000
2094
  emailService;
2095
+ authSessionService;
2001
2096
  config;
2002
2097
  t;
2003
2098
  logger;
2004
2099
  dummyHash;
2005
- constructor(tokenService, userService, userValidator, encryptionService, cookieManager, i18nService, emailService) {
2100
+ constructor(tokenService, userService, userValidator, encryptionService, cookieManager, i18nService, emailService, authSessionService) {
2006
2101
  this.tokenService = tokenService;
2007
2102
  this.userService = userService;
2008
2103
  this.userValidator = userValidator;
@@ -2010,6 +2105,7 @@ var AuthService = class AuthService2 {
2010
2105
  this.cookieManager = cookieManager;
2011
2106
  this.i18nService = i18nService;
2012
2107
  this.emailService = emailService;
2108
+ this.authSessionService = authSessionService;
2013
2109
  }
2014
2110
  isLockoutActive(lockoutUntil) {
2015
2111
  if (!lockoutUntil)
@@ -2105,7 +2201,7 @@ var AuthService = class AuthService2 {
2105
2201
  user.lockoutUntil = null;
2106
2202
  }
2107
2203
  if (user && this.isLockoutActive(user.lockoutUntil)) {
2108
- Err7(this.t("errors.accountLocked"), 423);
2204
+ Err8(this.t("errors.accountLocked"), 423);
2109
2205
  }
2110
2206
  const storedHash = user?.password ?? await this.getDummyHash();
2111
2207
  const isValid = await this.userValidator.comparePassword(password, storedHash);
@@ -2114,34 +2210,23 @@ var AuthService = class AuthService2 {
2114
2210
  const attempts = await this.userService.incrementFailedAttempts(user.id);
2115
2211
  if (attempts >= this.config.lockout.maxAttempts) {
2116
2212
  await this.userService.setLockout(user.id, this.nextLockoutUntil());
2117
- Err7(this.t("errors.accountLocked"), 423);
2213
+ Err8(this.t("errors.accountLocked"), 423);
2118
2214
  }
2119
2215
  }
2120
- Err7(this.t("errors.invalidCredentials"));
2216
+ Err8(this.t("errors.invalidCredentials"));
2121
2217
  }
2122
2218
  if (user.status !== "active") {
2123
- Err7(this.t("errors.accountInactive"));
2219
+ Err8(this.t("errors.accountInactive"));
2124
2220
  }
2125
2221
  if (this.config.requireVerifiedEmail && !user.emailVerified) {
2126
- Err7(this.t("errors.emailNotVerified"), 403);
2222
+ Err8(this.t("errors.emailNotVerified"), 403);
2127
2223
  }
2128
2224
  if ((user.failedLoginAttempts ?? 0) > 0 || user.lockoutUntil) {
2129
2225
  await this.userService.resetFailedAttempts(user.id);
2130
2226
  }
2131
- await this.tokenService.deleteExpiredSessions();
2132
- const generated = await this.tokenService.generateTokens(user.id);
2133
- this.cookieManager.setRefreshToken(generated.refreshToken);
2134
- await this.userService.updateLastLogin(user.id);
2135
2227
  const { password: _, failedLoginAttempts: __, lockoutUntil: ___, ...sanitized } = user;
2136
- const { roles, permissions, sessionVersion } = generated;
2137
- this.cookieManager.setSessionCookie({
2138
- user: { id: sanitized.id, email: sanitized.email, name: sanitized.name, role: sanitized.role, status: sanitized.status ?? void 0 },
2139
- roles,
2140
- permissions,
2141
- sessionVersion
2142
- });
2143
- const { userId: _userId, tokenFamily: _tokenFamily, roles: _roles, permissions: _permissions, sessionVersion: _sv, ...tokens } = generated;
2144
- return { ...tokens, user: sanitized };
2228
+ this.authSessionService ??= new AuthSessionService(this.tokenService, this.userService, this.cookieManager);
2229
+ return this.authSessionService.establish(sanitized);
2145
2230
  }
2146
2231
  async refreshTokens() {
2147
2232
  const generated = await this.tokenService.refreshTokens();
@@ -2237,11 +2322,11 @@ var AuthService = class AuthService2 {
2237
2322
  async changePassword(userId, currentPassword, newPassword) {
2238
2323
  const user = await this.userService.getAuthRecordById(userId);
2239
2324
  if (!user?.password) {
2240
- Err7(this.t("errors.invalidCredentials"));
2325
+ Err8(this.t("errors.invalidCredentials"));
2241
2326
  }
2242
2327
  const isValid = await this.userValidator.comparePassword(currentPassword, user.password);
2243
2328
  if (!isValid) {
2244
- Err7(this.t("errors.invalidCredentials"));
2329
+ Err8(this.t("errors.invalidCredentials"));
2245
2330
  }
2246
2331
  this.userValidator.validatePasswordStrength(newPassword);
2247
2332
  await this.userService.update(userId, { password: newPassword });
@@ -2262,33 +2347,33 @@ var AuthService = class AuthService2 {
2262
2347
  return { message: this.t("success.passwordReset") };
2263
2348
  }
2264
2349
  };
2265
- __decorate11([
2350
+ __decorate12([
2266
2351
  Inject8(AUTH_CONFIG),
2267
- __metadata11("design:type", Object)
2352
+ __metadata12("design:type", Object)
2268
2353
  ], AuthService.prototype, "config", void 0);
2269
- __decorate11([
2354
+ __decorate12([
2270
2355
  I18n6("auth"),
2271
- __metadata11("design:type", Object)
2356
+ __metadata12("design:type", Object)
2272
2357
  ], AuthService.prototype, "t", void 0);
2273
- __decorate11([
2358
+ __decorate12([
2274
2359
  Log(),
2275
- __metadata11("design:type", Object)
2360
+ __metadata12("design:type", Object)
2276
2361
  ], AuthService.prototype, "logger", void 0);
2277
- AuthService = __decorate11([
2278
- Injectable7(),
2279
- __metadata11("design:paramtypes", [typeof (_a7 = typeof TokenService !== "undefined" && TokenService) === "function" ? _a7 : Object, typeof (_b5 = typeof UserService !== "undefined" && UserService) === "function" ? _b5 : Object, typeof (_c3 = typeof UserValidator !== "undefined" && UserValidator) === "function" ? _c3 : Object, typeof (_d2 = typeof EncryptionService !== "undefined" && EncryptionService) === "function" ? _d2 : Object, typeof (_e2 = typeof CookieManager !== "undefined" && CookieManager) === "function" ? _e2 : Object, typeof (_f2 = typeof I18nService2 !== "undefined" && I18nService2) === "function" ? _f2 : Object, typeof (_g2 = typeof EmailService !== "undefined" && EmailService) === "function" ? _g2 : Object])
2362
+ AuthService = __decorate12([
2363
+ Injectable8(),
2364
+ __metadata12("design:paramtypes", [typeof (_a8 = typeof TokenService !== "undefined" && TokenService) === "function" ? _a8 : Object, typeof (_b6 = typeof UserService !== "undefined" && UserService) === "function" ? _b6 : Object, typeof (_c4 = typeof UserValidator !== "undefined" && UserValidator) === "function" ? _c4 : Object, typeof (_d2 = typeof EncryptionService !== "undefined" && EncryptionService) === "function" ? _d2 : Object, typeof (_e2 = typeof CookieManager !== "undefined" && CookieManager) === "function" ? _e2 : Object, typeof (_f2 = typeof I18nService2 !== "undefined" && I18nService2) === "function" ? _f2 : Object, typeof (_g2 = typeof EmailService !== "undefined" && EmailService) === "function" ? _g2 : Object, typeof (_h2 = typeof AuthSessionService !== "undefined" && AuthSessionService) === "function" ? _h2 : Object])
2280
2365
  ], AuthService);
2281
2366
 
2282
2367
  // src/auth/AuthGuard.ts
2283
2368
  import { Service as Service2, User } from "najm-core";
2284
2369
  import { createGuard } from "najm-guard";
2285
- var __decorate12 = function(decorators, target, key, desc) {
2370
+ var __decorate13 = function(decorators, target, key, desc) {
2286
2371
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2287
2372
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2288
2373
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2289
2374
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2290
2375
  };
2291
- var __metadata12 = function(k, v) {
2376
+ var __metadata13 = function(k, v) {
2292
2377
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2293
2378
  };
2294
2379
  var __param3 = function(paramIndex, decorator) {
@@ -2304,13 +2389,13 @@ var AuthGuard = class AuthGuard2 {
2304
2389
  return !!user;
2305
2390
  }
2306
2391
  };
2307
- __decorate12([
2392
+ __decorate13([
2308
2393
  __param3(0, User()),
2309
- __metadata12("design:type", Function),
2310
- __metadata12("design:paramtypes", [Object]),
2311
- __metadata12("design:returntype", Boolean)
2394
+ __metadata13("design:type", Function),
2395
+ __metadata13("design:paramtypes", [Object]),
2396
+ __metadata13("design:returntype", Boolean)
2312
2397
  ], AuthGuard.prototype, "canActivate", null);
2313
- AuthGuard = __decorate12([
2398
+ AuthGuard = __decorate13([
2314
2399
  Service2()
2315
2400
  ], AuthGuard);
2316
2401
  var isAuth = createGuard(AuthGuard);
@@ -2319,13 +2404,13 @@ var isAuth = createGuard(AuthGuard);
2319
2404
  import { Service as Service3 } from "najm-core";
2320
2405
  import { GuardParams, User as User2 } from "najm-core";
2321
2406
  import { composeGuards, createGuard as createGuard2 } from "najm-guard";
2322
- var __decorate13 = function(decorators, target, key, desc) {
2407
+ var __decorate14 = function(decorators, target, key, desc) {
2323
2408
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2324
2409
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2325
2410
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2326
2411
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2327
2412
  };
2328
- var __metadata13 = function(k, v) {
2413
+ var __metadata14 = function(k, v) {
2329
2414
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2330
2415
  };
2331
2416
  var __param4 = function(paramIndex, decorator) {
@@ -2348,14 +2433,14 @@ var RoleGuard = class RoleGuard2 {
2348
2433
  return false;
2349
2434
  }
2350
2435
  };
2351
- __decorate13([
2436
+ __decorate14([
2352
2437
  __param4(0, GuardParams()),
2353
2438
  __param4(1, User2("role")),
2354
- __metadata13("design:type", Function),
2355
- __metadata13("design:paramtypes", [Object, String]),
2356
- __metadata13("design:returntype", void 0)
2439
+ __metadata14("design:type", Function),
2440
+ __metadata14("design:paramtypes", [Object, String]),
2441
+ __metadata14("design:returntype", void 0)
2357
2442
  ], RoleGuard.prototype, "canActivate", null);
2358
- RoleGuard = __decorate13([
2443
+ RoleGuard = __decorate14([
2359
2444
  Service3()
2360
2445
  ], RoleGuard);
2361
2446
  var Role = createGuard2(RoleGuard);
@@ -2431,13 +2516,13 @@ var userListQuery = z.object({
2431
2516
  });
2432
2517
 
2433
2518
  // src/auth/AuthController.ts
2434
- var __decorate14 = function(decorators, target, key, desc) {
2519
+ var __decorate15 = function(decorators, target, key, desc) {
2435
2520
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2436
2521
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2437
2522
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2438
2523
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2439
2524
  };
2440
- var __metadata14 = function(k, v) {
2525
+ var __metadata15 = function(k, v) {
2441
2526
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2442
2527
  };
2443
2528
  var __param5 = function(paramIndex, decorator) {
@@ -2445,7 +2530,7 @@ var __param5 = function(paramIndex, decorator) {
2445
2530
  decorator(target, key, paramIndex);
2446
2531
  };
2447
2532
  };
2448
- var _a8;
2533
+ var _a9;
2449
2534
  var hashKeyPart = /* @__PURE__ */ __name((value) => createHash2("sha256").update(value).digest("base64url").slice(0, 32), "hashKeyPart");
2450
2535
  var cookieFingerprint = /* @__PURE__ */ __name(() => (ctx) => {
2451
2536
  const ip = ctx.req.header("x-forwarded-for")?.split(",")[0]?.trim() ?? ctx.req.header("x-real-ip") ?? "unknown";
@@ -2502,113 +2587,113 @@ var AuthController = class AuthController2 {
2502
2587
  return this.authService.resetPassword(body.token, body.newPassword);
2503
2588
  }
2504
2589
  };
2505
- __decorate14([
2590
+ __decorate15([
2506
2591
  Post("/register"),
2507
2592
  RateLimit({ limit: 5, window: "15m", key: ipAndEmail }),
2508
2593
  Validate(registerDto),
2509
2594
  ResMsg("auth.success.register"),
2510
2595
  __param5(0, Body()),
2511
- __metadata14("design:type", Function),
2512
- __metadata14("design:paramtypes", [Object]),
2513
- __metadata14("design:returntype", Promise)
2596
+ __metadata15("design:type", Function),
2597
+ __metadata15("design:paramtypes", [Object]),
2598
+ __metadata15("design:returntype", Promise)
2514
2599
  ], AuthController.prototype, "registerUser", null);
2515
- __decorate14([
2600
+ __decorate15([
2516
2601
  Post("/login"),
2517
2602
  RateLimit({ limit: 5, window: "15m", key: ipAndEmail, message: "Too many login attempts. Please try again later." }),
2518
2603
  Validate(loginDto),
2519
2604
  ResMsg("auth.success.login"),
2520
2605
  __param5(0, Body()),
2521
- __metadata14("design:type", Function),
2522
- __metadata14("design:paramtypes", [Object]),
2523
- __metadata14("design:returntype", Promise)
2606
+ __metadata15("design:type", Function),
2607
+ __metadata15("design:paramtypes", [Object]),
2608
+ __metadata15("design:returntype", Promise)
2524
2609
  ], AuthController.prototype, "loginUser", null);
2525
- __decorate14([
2610
+ __decorate15([
2526
2611
  Post("/invite"),
2527
2612
  isAdmin(),
2528
2613
  RateLimit({ limit: 20, window: "15m", key: "user" }),
2529
2614
  Validate(inviteUserDto),
2530
2615
  ResMsg("auth.success.accountInviteSent"),
2531
2616
  __param5(0, Body()),
2532
- __metadata14("design:type", Function),
2533
- __metadata14("design:paramtypes", [Object]),
2534
- __metadata14("design:returntype", Promise)
2617
+ __metadata15("design:type", Function),
2618
+ __metadata15("design:paramtypes", [Object]),
2619
+ __metadata15("design:returntype", Promise)
2535
2620
  ], AuthController.prototype, "inviteUser", null);
2536
- __decorate14([
2621
+ __decorate15([
2537
2622
  Post("/refresh"),
2538
2623
  RateLimit({ limit: 15, window: "15m", key: cookieFingerprint() }),
2539
2624
  ResMsg("auth.success.tokenRefreshed"),
2540
- __metadata14("design:type", Function),
2541
- __metadata14("design:paramtypes", []),
2542
- __metadata14("design:returntype", Promise)
2625
+ __metadata15("design:type", Function),
2626
+ __metadata15("design:paramtypes", []),
2627
+ __metadata15("design:returntype", Promise)
2543
2628
  ], AuthController.prototype, "refreshTokens", null);
2544
- __decorate14([
2629
+ __decorate15([
2545
2630
  Post("/logout"),
2546
2631
  isAuth(),
2547
2632
  RateLimit({ limit: 10, window: "15m", key: "user" }),
2548
2633
  __param5(0, User3("id")),
2549
2634
  __param5(1, Headers("authorization")),
2550
- __metadata14("design:type", Function),
2551
- __metadata14("design:paramtypes", [String, String]),
2552
- __metadata14("design:returntype", Promise)
2635
+ __metadata15("design:type", Function),
2636
+ __metadata15("design:paramtypes", [String, String]),
2637
+ __metadata15("design:returntype", Promise)
2553
2638
  ], AuthController.prototype, "logoutUser", null);
2554
- __decorate14([
2639
+ __decorate15([
2555
2640
  Post("/change-password"),
2556
2641
  isAuth(),
2557
2642
  Validate(changePasswordDto),
2558
2643
  ResMsg("auth.success.passwordChanged"),
2559
2644
  __param5(0, User3("id")),
2560
2645
  __param5(1, Body()),
2561
- __metadata14("design:type", Function),
2562
- __metadata14("design:paramtypes", [String, Object]),
2563
- __metadata14("design:returntype", Promise)
2646
+ __metadata15("design:type", Function),
2647
+ __metadata15("design:paramtypes", [String, Object]),
2648
+ __metadata15("design:returntype", Promise)
2564
2649
  ], AuthController.prototype, "changePassword", null);
2565
- __decorate14([
2650
+ __decorate15([
2566
2651
  Get("/me"),
2567
2652
  RateLimit({ limit: 30, window: "1m", key: cookieFingerprint() }),
2568
2653
  ResMsg("auth.users.success.retrieved"),
2569
2654
  __param5(0, Headers("authorization")),
2570
- __metadata14("design:type", Function),
2571
- __metadata14("design:paramtypes", [String]),
2572
- __metadata14("design:returntype", Promise)
2655
+ __metadata15("design:type", Function),
2656
+ __metadata15("design:paramtypes", [String]),
2657
+ __metadata15("design:returntype", Promise)
2573
2658
  ], AuthController.prototype, "userProfile", null);
2574
- __decorate14([
2659
+ __decorate15([
2575
2660
  Post("/forgot-password"),
2576
2661
  RateLimit({ limit: 3, window: "15m", key: ipAndEmail, message: "Too many password reset requests. Please try again later." }),
2577
2662
  Validate(resetPasswordDto),
2578
2663
  ResMsg("auth.success.passwordResetSent"),
2579
2664
  __param5(0, Body()),
2580
- __metadata14("design:type", Function),
2581
- __metadata14("design:paramtypes", [Object]),
2582
- __metadata14("design:returntype", Promise)
2665
+ __metadata15("design:type", Function),
2666
+ __metadata15("design:paramtypes", [Object]),
2667
+ __metadata15("design:returntype", Promise)
2583
2668
  ], AuthController.prototype, "forgotPassword", null);
2584
- __decorate14([
2669
+ __decorate15([
2585
2670
  Post("/reset-password"),
2586
2671
  RateLimit({ limit: 5, window: "15m", key: "ip", message: "Too many password reset attempts. Please try again later." }),
2587
2672
  Validate(confirmResetPasswordDto),
2588
2673
  ResMsg("auth.success.passwordReset"),
2589
2674
  __param5(0, Body()),
2590
- __metadata14("design:type", Function),
2591
- __metadata14("design:paramtypes", [Object]),
2592
- __metadata14("design:returntype", Promise)
2675
+ __metadata15("design:type", Function),
2676
+ __metadata15("design:paramtypes", [Object]),
2677
+ __metadata15("design:returntype", Promise)
2593
2678
  ], AuthController.prototype, "resetPassword", null);
2594
- AuthController = __decorate14([
2679
+ AuthController = __decorate15([
2595
2680
  Controller("/auth"),
2596
- __metadata14("design:paramtypes", [typeof (_a8 = typeof AuthService !== "undefined" && AuthService) === "function" ? _a8 : Object])
2681
+ __metadata15("design:paramtypes", [typeof (_a9 = typeof AuthService !== "undefined" && AuthService) === "function" ? _a9 : Object])
2597
2682
  ], AuthController);
2598
2683
 
2599
2684
  // src/auth/AuthResolver.ts
2600
2685
  import { APP, Container, DI, Inject as Inject9, LOGGER, Meta, Service as Service4 } from "najm-core";
2601
2686
  import { USER, ROLE, PERMISSIONS } from "najm-guard";
2602
- var __decorate15 = function(decorators, target, key, desc) {
2687
+ var __decorate16 = function(decorators, target, key, desc) {
2603
2688
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2604
2689
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2605
2690
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2606
2691
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2607
2692
  };
2608
- var __metadata15 = function(k, v) {
2693
+ var __metadata16 = function(k, v) {
2609
2694
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2610
2695
  };
2611
- var _a9;
2696
+ var _a10;
2612
2697
  var AuthResolver = class AuthResolver2 {
2613
2698
  static {
2614
2699
  __name(this, "AuthResolver");
@@ -2724,19 +2809,19 @@ var AuthResolver = class AuthResolver2 {
2724
2809
  await authService.warmupPasswordHash();
2725
2810
  }
2726
2811
  };
2727
- __decorate15([
2812
+ __decorate16([
2728
2813
  DI(),
2729
- __metadata15("design:type", typeof (_a9 = typeof Container !== "undefined" && Container) === "function" ? _a9 : Object)
2814
+ __metadata16("design:type", typeof (_a10 = typeof Container !== "undefined" && Container) === "function" ? _a10 : Object)
2730
2815
  ], AuthResolver.prototype, "container", void 0);
2731
- __decorate15([
2816
+ __decorate16([
2732
2817
  Inject9(APP),
2733
- __metadata15("design:type", Object)
2818
+ __metadata16("design:type", Object)
2734
2819
  ], AuthResolver.prototype, "app", void 0);
2735
- __decorate15([
2820
+ __decorate16([
2736
2821
  Inject9(LOGGER),
2737
- __metadata15("design:type", Object)
2822
+ __metadata16("design:type", Object)
2738
2823
  ], AuthResolver.prototype, "log", void 0);
2739
- AuthResolver = __decorate15([
2824
+ AuthResolver = __decorate16([
2740
2825
  Service4(),
2741
2826
  Meta({ layer: "plugin", order: 30 })
2742
2827
  ], AuthResolver);
@@ -2767,6 +2852,7 @@ __name(runAsUser, "runAsUser");
2767
2852
  // src/auth/index.ts
2768
2853
  var AUTH_MODULE = [
2769
2854
  AuthService,
2855
+ AuthSessionService,
2770
2856
  CookieManager,
2771
2857
  EncryptionService,
2772
2858
  AuthGuard,
@@ -2882,13 +2968,13 @@ var assignRoleDto = z2.object({
2882
2968
  });
2883
2969
 
2884
2970
  // src/roles/RoleController.ts
2885
- var __decorate16 = function(decorators, target, key, desc) {
2971
+ var __decorate17 = function(decorators, target, key, desc) {
2886
2972
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2887
2973
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2888
2974
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2889
2975
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2890
2976
  };
2891
- var __metadata16 = function(k, v) {
2977
+ var __metadata17 = function(k, v) {
2892
2978
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2893
2979
  };
2894
2980
  var __param6 = function(paramIndex, decorator) {
@@ -2896,7 +2982,7 @@ var __param6 = function(paramIndex, decorator) {
2896
2982
  decorator(target, key, paramIndex);
2897
2983
  };
2898
2984
  };
2899
- var _a10;
2985
+ var _a11;
2900
2986
  var RoleController = class RoleController2 {
2901
2987
  static {
2902
2988
  __name(this, "RoleController");
@@ -2921,35 +3007,35 @@ var RoleController = class RoleController2 {
2921
3007
  return this.roleService.delete(params.id);
2922
3008
  }
2923
3009
  };
2924
- __decorate16([
3010
+ __decorate17([
2925
3011
  Get2(),
2926
3012
  isAdmin(),
2927
3013
  ResMsg2("roles.success.retrieved"),
2928
- __metadata16("design:type", Function),
2929
- __metadata16("design:paramtypes", []),
2930
- __metadata16("design:returntype", Promise)
3014
+ __metadata17("design:type", Function),
3015
+ __metadata17("design:paramtypes", []),
3016
+ __metadata17("design:returntype", Promise)
2931
3017
  ], RoleController.prototype, "getRoles", null);
2932
- __decorate16([
3018
+ __decorate17([
2933
3019
  Get2("/:id"),
2934
3020
  isAdmin(),
2935
3021
  Validate2({ params: roleIdParam }),
2936
3022
  ResMsg2("roles.success.retrieved"),
2937
3023
  __param6(0, Params()),
2938
- __metadata16("design:type", Function),
2939
- __metadata16("design:paramtypes", [Object]),
2940
- __metadata16("design:returntype", Promise)
3024
+ __metadata17("design:type", Function),
3025
+ __metadata17("design:paramtypes", [Object]),
3026
+ __metadata17("design:returntype", Promise)
2941
3027
  ], RoleController.prototype, "getRole", null);
2942
- __decorate16([
3028
+ __decorate17([
2943
3029
  Post2(),
2944
3030
  isAdmin(),
2945
3031
  Validate2(createRoleDto),
2946
3032
  ResMsg2("roles.success.created"),
2947
3033
  __param6(0, Body2()),
2948
- __metadata16("design:type", Function),
2949
- __metadata16("design:paramtypes", [Object]),
2950
- __metadata16("design:returntype", Promise)
3034
+ __metadata17("design:type", Function),
3035
+ __metadata17("design:paramtypes", [Object]),
3036
+ __metadata17("design:returntype", Promise)
2951
3037
  ], RoleController.prototype, "createRole", null);
2952
- __decorate16([
3038
+ __decorate17([
2953
3039
  Put("/:id"),
2954
3040
  isAdmin(),
2955
3041
  Validate2({
@@ -2959,34 +3045,34 @@ __decorate16([
2959
3045
  ResMsg2("roles.success.updated"),
2960
3046
  __param6(0, Params()),
2961
3047
  __param6(1, Body2()),
2962
- __metadata16("design:type", Function),
2963
- __metadata16("design:paramtypes", [Object, Object]),
2964
- __metadata16("design:returntype", Promise)
3048
+ __metadata17("design:type", Function),
3049
+ __metadata17("design:paramtypes", [Object, Object]),
3050
+ __metadata17("design:returntype", Promise)
2965
3051
  ], RoleController.prototype, "updateRole", null);
2966
- __decorate16([
3052
+ __decorate17([
2967
3053
  Delete("/:id"),
2968
3054
  isAdmin(),
2969
3055
  Validate2({ params: roleIdParam }),
2970
3056
  ResMsg2("roles.success.deleted"),
2971
3057
  __param6(0, Params()),
2972
- __metadata16("design:type", Function),
2973
- __metadata16("design:paramtypes", [Object]),
2974
- __metadata16("design:returntype", Promise)
3058
+ __metadata17("design:type", Function),
3059
+ __metadata17("design:paramtypes", [Object]),
3060
+ __metadata17("design:returntype", Promise)
2975
3061
  ], RoleController.prototype, "deleteRole", null);
2976
- RoleController = __decorate16([
3062
+ RoleController = __decorate17([
2977
3063
  Controller2("/roles"),
2978
- __metadata16("design:paramtypes", [typeof (_a10 = typeof RoleService !== "undefined" && RoleService) === "function" ? _a10 : Object])
3064
+ __metadata17("design:paramtypes", [typeof (_a11 = typeof RoleService !== "undefined" && RoleService) === "function" ? _a11 : Object])
2979
3065
  ], RoleController);
2980
3066
 
2981
3067
  // src/users/UserController.ts
2982
3068
  import { Validate as Validate3 } from "najm-validation";
2983
- var __decorate17 = function(decorators, target, key, desc) {
3069
+ var __decorate18 = function(decorators, target, key, desc) {
2984
3070
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2985
3071
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2986
3072
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2987
3073
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2988
3074
  };
2989
- var __metadata17 = function(k, v) {
3075
+ var __metadata18 = function(k, v) {
2990
3076
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
2991
3077
  };
2992
3078
  var __param7 = function(paramIndex, decorator) {
@@ -2994,7 +3080,7 @@ var __param7 = function(paramIndex, decorator) {
2994
3080
  decorator(target, key, paramIndex);
2995
3081
  };
2996
3082
  };
2997
- var _a11;
3083
+ var _a12;
2998
3084
  var UserController = class UserController2 {
2999
3085
  static {
3000
3086
  __name(this, "UserController");
@@ -3041,75 +3127,75 @@ var UserController = class UserController2 {
3041
3127
  return this.userService.removeRole(params.userId);
3042
3128
  }
3043
3129
  };
3044
- __decorate17([
3130
+ __decorate18([
3045
3131
  Get3(),
3046
3132
  isAdmin(),
3047
3133
  Validate3({ query: userListQuery }),
3048
3134
  ResMsg3("users.success.retrieved"),
3049
3135
  __param7(0, Query()),
3050
- __metadata17("design:type", Function),
3051
- __metadata17("design:paramtypes", [Object]),
3052
- __metadata17("design:returntype", Promise)
3136
+ __metadata18("design:type", Function),
3137
+ __metadata18("design:paramtypes", [Object]),
3138
+ __metadata18("design:returntype", Promise)
3053
3139
  ], UserController.prototype, "getUsers", null);
3054
- __decorate17([
3140
+ __decorate18([
3055
3141
  Get3("/lang"),
3056
3142
  isAuth(),
3057
3143
  ResMsg3("users.success.retrieved"),
3058
- __metadata17("design:type", Function),
3059
- __metadata17("design:paramtypes", []),
3060
- __metadata17("design:returntype", Promise)
3144
+ __metadata18("design:type", Function),
3145
+ __metadata18("design:paramtypes", []),
3146
+ __metadata18("design:returntype", Promise)
3061
3147
  ], UserController.prototype, "getLang", null);
3062
- __decorate17([
3148
+ __decorate18([
3063
3149
  Post3("/lang/:language"),
3064
3150
  isAuth(),
3065
3151
  Validate3({ params: languageParam }),
3066
3152
  ResMsg3("users.success.updated"),
3067
3153
  __param7(0, Params2()),
3068
- __metadata17("design:type", Function),
3069
- __metadata17("design:paramtypes", [Object]),
3070
- __metadata17("design:returntype", Promise)
3154
+ __metadata18("design:type", Function),
3155
+ __metadata18("design:paramtypes", [Object]),
3156
+ __metadata18("design:returntype", Promise)
3071
3157
  ], UserController.prototype, "updateLang", null);
3072
- __decorate17([
3158
+ __decorate18([
3073
3159
  Get3("/:id"),
3074
3160
  isAdmin(),
3075
3161
  Validate3({ params: userIdParam }),
3076
3162
  ResMsg3("users.success.retrieved"),
3077
3163
  __param7(0, Params2()),
3078
- __metadata17("design:type", Function),
3079
- __metadata17("design:paramtypes", [Object]),
3080
- __metadata17("design:returntype", Promise)
3164
+ __metadata18("design:type", Function),
3165
+ __metadata18("design:paramtypes", [Object]),
3166
+ __metadata18("design:returntype", Promise)
3081
3167
  ], UserController.prototype, "getUser", null);
3082
- __decorate17([
3168
+ __decorate18([
3083
3169
  Get3("/email/:email"),
3084
3170
  isAdmin(),
3085
3171
  Validate3({ params: emailParam }),
3086
3172
  ResMsg3("users.success.retrieved"),
3087
3173
  __param7(0, Params2()),
3088
- __metadata17("design:type", Function),
3089
- __metadata17("design:paramtypes", [Object]),
3090
- __metadata17("design:returntype", Promise)
3174
+ __metadata18("design:type", Function),
3175
+ __metadata18("design:paramtypes", [Object]),
3176
+ __metadata18("design:returntype", Promise)
3091
3177
  ], UserController.prototype, "getByEmail", null);
3092
- __decorate17([
3178
+ __decorate18([
3093
3179
  Get3("/role/:userId"),
3094
3180
  isAdmin(),
3095
3181
  Validate3({ params: userIdInParam }),
3096
3182
  ResMsg3("users.success.retrieved"),
3097
3183
  __param7(0, Params2()),
3098
- __metadata17("design:type", Function),
3099
- __metadata17("design:paramtypes", [Object]),
3100
- __metadata17("design:returntype", Promise)
3184
+ __metadata18("design:type", Function),
3185
+ __metadata18("design:paramtypes", [Object]),
3186
+ __metadata18("design:returntype", Promise)
3101
3187
  ], UserController.prototype, "getRole", null);
3102
- __decorate17([
3188
+ __decorate18([
3103
3189
  Post3(),
3104
3190
  isAdmin(),
3105
3191
  Validate3(createUserDto),
3106
3192
  ResMsg3("users.success.created"),
3107
3193
  __param7(0, Body3()),
3108
- __metadata17("design:type", Function),
3109
- __metadata17("design:paramtypes", [Object]),
3110
- __metadata17("design:returntype", Promise)
3194
+ __metadata18("design:type", Function),
3195
+ __metadata18("design:paramtypes", [Object]),
3196
+ __metadata18("design:returntype", Promise)
3111
3197
  ], UserController.prototype, "create", null);
3112
- __decorate17([
3198
+ __decorate18([
3113
3199
  Put2("/:id"),
3114
3200
  isAdmin(),
3115
3201
  Validate3({
@@ -3119,51 +3205,51 @@ __decorate17([
3119
3205
  ResMsg3("users.success.updated"),
3120
3206
  __param7(0, Params2()),
3121
3207
  __param7(1, Body3()),
3122
- __metadata17("design:type", Function),
3123
- __metadata17("design:paramtypes", [Object, Object]),
3124
- __metadata17("design:returntype", Promise)
3208
+ __metadata18("design:type", Function),
3209
+ __metadata18("design:paramtypes", [Object, Object]),
3210
+ __metadata18("design:returntype", Promise)
3125
3211
  ], UserController.prototype, "update", null);
3126
- __decorate17([
3212
+ __decorate18([
3127
3213
  Delete2("/:id"),
3128
3214
  isAdmin(),
3129
3215
  Validate3({ params: userIdParam }),
3130
3216
  ResMsg3("users.success.deleted"),
3131
3217
  __param7(0, Params2()),
3132
- __metadata17("design:type", Function),
3133
- __metadata17("design:paramtypes", [Object]),
3134
- __metadata17("design:returntype", Promise)
3218
+ __metadata18("design:type", Function),
3219
+ __metadata18("design:paramtypes", [Object]),
3220
+ __metadata18("design:returntype", Promise)
3135
3221
  ], UserController.prototype, "delete", null);
3136
- __decorate17([
3222
+ __decorate18([
3137
3223
  Delete2(),
3138
3224
  isAdmin(),
3139
3225
  ResMsg3("users.success.allDeleted"),
3140
- __metadata17("design:type", Function),
3141
- __metadata17("design:paramtypes", []),
3142
- __metadata17("design:returntype", Promise)
3226
+ __metadata18("design:type", Function),
3227
+ __metadata18("design:paramtypes", []),
3228
+ __metadata18("design:returntype", Promise)
3143
3229
  ], UserController.prototype, "deleteAll", null);
3144
- __decorate17([
3230
+ __decorate18([
3145
3231
  Post3("/assign/:userId/:roleId"),
3146
3232
  isAdmin(),
3147
3233
  Validate3({ params: assignRoleParams }),
3148
3234
  ResMsg3("users.success.updated"),
3149
3235
  __param7(0, Params2()),
3150
- __metadata17("design:type", Function),
3151
- __metadata17("design:paramtypes", [Object]),
3152
- __metadata17("design:returntype", Promise)
3236
+ __metadata18("design:type", Function),
3237
+ __metadata18("design:paramtypes", [Object]),
3238
+ __metadata18("design:returntype", Promise)
3153
3239
  ], UserController.prototype, "assignRole", null);
3154
- __decorate17([
3240
+ __decorate18([
3155
3241
  Delete2("/remove/:userId"),
3156
3242
  isAdmin(),
3157
3243
  Validate3({ params: userIdInParam }),
3158
3244
  ResMsg3("users.success.updated"),
3159
3245
  __param7(0, Params2()),
3160
- __metadata17("design:type", Function),
3161
- __metadata17("design:paramtypes", [Object]),
3162
- __metadata17("design:returntype", Promise)
3246
+ __metadata18("design:type", Function),
3247
+ __metadata18("design:paramtypes", [Object]),
3248
+ __metadata18("design:returntype", Promise)
3163
3249
  ], UserController.prototype, "removeRole", null);
3164
- UserController = __decorate17([
3250
+ UserController = __decorate18([
3165
3251
  Controller3("/users"),
3166
- __metadata17("design:paramtypes", [typeof (_a11 = typeof UserService !== "undefined" && UserService) === "function" ? _a11 : Object])
3252
+ __metadata18("design:paramtypes", [typeof (_a12 = typeof UserService !== "undefined" && UserService) === "function" ? _a12 : Object])
3167
3253
  ], UserController);
3168
3254
 
3169
3255
  // src/permissions/index.ts
@@ -3186,13 +3272,13 @@ __export(permissions_exports, {
3186
3272
  import { eq as eq5, and as and2 } from "drizzle-orm";
3187
3273
  import { Repository as Repository4, Inject as Inject10 } from "najm-core";
3188
3274
  import { DB as DB4 } from "najm-database";
3189
- var __decorate18 = function(decorators, target, key, desc) {
3275
+ var __decorate19 = function(decorators, target, key, desc) {
3190
3276
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3191
3277
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3192
3278
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3193
3279
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3194
3280
  };
3195
- var __metadata18 = function(k, v) {
3281
+ var __metadata19 = function(k, v) {
3196
3282
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3197
3283
  };
3198
3284
  var PermissionRepository = class PermissionRepository2 {
@@ -3270,29 +3356,29 @@ var PermissionRepository = class PermissionRepository2 {
3270
3356
  return deletedPermissions;
3271
3357
  }
3272
3358
  };
3273
- __decorate18([
3359
+ __decorate19([
3274
3360
  DB4(),
3275
- __metadata18("design:type", Object)
3361
+ __metadata19("design:type", Object)
3276
3362
  ], PermissionRepository.prototype, "db", void 0);
3277
- __decorate18([
3363
+ __decorate19([
3278
3364
  Inject10(AUTH_SCHEMA),
3279
- __metadata18("design:type", Object)
3365
+ __metadata19("design:type", Object)
3280
3366
  ], PermissionRepository.prototype, "schema", void 0);
3281
- PermissionRepository = __decorate18([
3367
+ PermissionRepository = __decorate19([
3282
3368
  Repository4()
3283
3369
  ], PermissionRepository);
3284
3370
 
3285
3371
  // src/permissions/PermissionGuards.ts
3286
- import { Injectable as Injectable8 } from "najm-core";
3372
+ import { Injectable as Injectable9 } from "najm-core";
3287
3373
  import { GuardParams as GuardParams2, User as User4 } from "najm-core";
3288
3374
  import { createGuard as createGuard4, composeGuards as composeGuards3 } from "najm-guard";
3289
- var __decorate19 = function(decorators, target, key, desc) {
3375
+ var __decorate20 = function(decorators, target, key, desc) {
3290
3376
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3291
3377
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3292
3378
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3293
3379
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3294
3380
  };
3295
- var __metadata19 = function(k, v) {
3381
+ var __metadata20 = function(k, v) {
3296
3382
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3297
3383
  };
3298
3384
  var __param8 = function(paramIndex, decorator) {
@@ -3328,15 +3414,15 @@ var PermissionGuard = class PermissionGuard2 {
3328
3414
  return false;
3329
3415
  }
3330
3416
  };
3331
- __decorate19([
3417
+ __decorate20([
3332
3418
  __param8(0, GuardParams2()),
3333
3419
  __param8(1, User4("permissions")),
3334
- __metadata19("design:type", Function),
3335
- __metadata19("design:paramtypes", [String, Array]),
3336
- __metadata19("design:returntype", Object)
3420
+ __metadata20("design:type", Function),
3421
+ __metadata20("design:paramtypes", [String, Array]),
3422
+ __metadata20("design:returntype", Object)
3337
3423
  ], PermissionGuard.prototype, "canActivate", null);
3338
- PermissionGuard = __decorate19([
3339
- Injectable8()
3424
+ PermissionGuard = __decorate20([
3425
+ Injectable9()
3340
3426
  ], PermissionGuard);
3341
3427
  var Permission = createGuard4(PermissionGuard);
3342
3428
  var Can = /* @__PURE__ */ __name((permission) => composeGuards3(isAuth(), Permission(permission))(), "Can");
@@ -3347,23 +3433,23 @@ import { Get as Get4, Post as Post4, Put as Put3, Delete as Delete3, ResMsg as R
3347
3433
  import { Params as Params3, Body as Body4 } from "najm-core";
3348
3434
 
3349
3435
  // src/permissions/PermissionService.ts
3350
- import { Injectable as Injectable10 } from "najm-core";
3436
+ import { Injectable as Injectable11 } from "najm-core";
3351
3437
 
3352
3438
  // src/permissions/PermissionValidator.ts
3353
- import { Injectable as Injectable9 } from "najm-core";
3439
+ import { Injectable as Injectable10 } from "najm-core";
3354
3440
  import { I18n as I18n7 } from "najm-i18n";
3355
- import { Err as Err8 } from "najm-core";
3356
- var __decorate20 = function(decorators, target, key, desc) {
3441
+ import { Err as Err9 } from "najm-core";
3442
+ var __decorate21 = function(decorators, target, key, desc) {
3357
3443
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3358
3444
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3359
3445
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3360
3446
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3361
3447
  };
3362
- var __metadata20 = function(k, v) {
3448
+ var __metadata21 = function(k, v) {
3363
3449
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3364
3450
  };
3365
- var _a12;
3366
- var _b6;
3451
+ var _a13;
3452
+ var _b7;
3367
3453
  var PermissionValidator = class PermissionValidator2 {
3368
3454
  static {
3369
3455
  __name(this, "PermissionValidator");
@@ -3381,7 +3467,7 @@ var PermissionValidator = class PermissionValidator2 {
3381
3467
  async checkPermissionExists(id) {
3382
3468
  const permission = await this.permissionRepository.getById(id);
3383
3469
  if (!permission) {
3384
- Err8(this.t("errors.notFound"), 404);
3470
+ Err9(this.t("errors.notFound"), 404);
3385
3471
  }
3386
3472
  return permission;
3387
3473
  }
@@ -3391,7 +3477,7 @@ var PermissionValidator = class PermissionValidator2 {
3391
3477
  async checkPermissionExistsByName(name) {
3392
3478
  const permission = await this.permissionRepository.getByName(name);
3393
3479
  if (!permission) {
3394
- Err8(this.t("errors.notFound"), 404);
3480
+ Err9(this.t("errors.notFound"), 404);
3395
3481
  }
3396
3482
  return permission;
3397
3483
  }
@@ -3403,7 +3489,7 @@ var PermissionValidator = class PermissionValidator2 {
3403
3489
  return;
3404
3490
  const existingPermission = await this.permissionRepository.getByName(name);
3405
3491
  if (existingPermission && existingPermission.id !== excludeId) {
3406
- Err8(this.t("errors.nameExists"), 409);
3492
+ Err9(this.t("errors.nameExists"), 409);
3407
3493
  }
3408
3494
  }
3409
3495
  /**
@@ -3426,32 +3512,32 @@ var PermissionValidator = class PermissionValidator2 {
3426
3512
  await this.checkPermissionExists(permissionId);
3427
3513
  const hasPermission = await this.permissionRepository.checkRoleHasPermission(roleId, permissionId);
3428
3514
  if (hasPermission) {
3429
- Err8(this.t("errors.roleAlreadyHasPermission"), 409);
3515
+ Err9(this.t("errors.roleAlreadyHasPermission"), 409);
3430
3516
  }
3431
3517
  }
3432
3518
  };
3433
- __decorate20([
3519
+ __decorate21([
3434
3520
  I18n7("permissions"),
3435
- __metadata20("design:type", Object)
3521
+ __metadata21("design:type", Object)
3436
3522
  ], PermissionValidator.prototype, "t", void 0);
3437
- PermissionValidator = __decorate20([
3438
- Injectable9(),
3439
- __metadata20("design:paramtypes", [typeof (_a12 = typeof PermissionRepository !== "undefined" && PermissionRepository) === "function" ? _a12 : Object, typeof (_b6 = typeof RoleValidator !== "undefined" && RoleValidator) === "function" ? _b6 : Object])
3523
+ PermissionValidator = __decorate21([
3524
+ Injectable10(),
3525
+ __metadata21("design:paramtypes", [typeof (_a13 = typeof PermissionRepository !== "undefined" && PermissionRepository) === "function" ? _a13 : Object, typeof (_b7 = typeof RoleValidator !== "undefined" && RoleValidator) === "function" ? _b7 : Object])
3440
3526
  ], PermissionValidator);
3441
3527
 
3442
3528
  // src/permissions/PermissionService.ts
3443
- var __decorate21 = function(decorators, target, key, desc) {
3529
+ var __decorate22 = function(decorators, target, key, desc) {
3444
3530
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3445
3531
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3446
3532
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3447
3533
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3448
3534
  };
3449
- var __metadata21 = function(k, v) {
3535
+ var __metadata22 = function(k, v) {
3450
3536
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3451
3537
  };
3452
- var _a13;
3453
- var _b7;
3454
- var _c4;
3538
+ var _a14;
3539
+ var _b8;
3540
+ var _c5;
3455
3541
  var PermissionService = class PermissionService2 {
3456
3542
  static {
3457
3543
  __name(this, "PermissionService");
@@ -3556,9 +3642,9 @@ var PermissionService = class PermissionService2 {
3556
3642
  return await this.permissionRepository.deleteAll();
3557
3643
  }
3558
3644
  };
3559
- PermissionService = __decorate21([
3560
- Injectable10(),
3561
- __metadata21("design:paramtypes", [typeof (_a13 = typeof PermissionRepository !== "undefined" && PermissionRepository) === "function" ? _a13 : Object, typeof (_b7 = typeof PermissionValidator !== "undefined" && PermissionValidator) === "function" ? _b7 : Object, typeof (_c4 = typeof RoleService !== "undefined" && RoleService) === "function" ? _c4 : Object])
3645
+ PermissionService = __decorate22([
3646
+ Injectable11(),
3647
+ __metadata22("design:paramtypes", [typeof (_a14 = typeof PermissionRepository !== "undefined" && PermissionRepository) === "function" ? _a14 : Object, typeof (_b8 = typeof PermissionValidator !== "undefined" && PermissionValidator) === "function" ? _b8 : Object, typeof (_c5 = typeof RoleService !== "undefined" && RoleService) === "function" ? _c5 : Object])
3562
3648
  ], PermissionService);
3563
3649
 
3564
3650
  // src/permissions/PermissionController.ts
@@ -3591,13 +3677,13 @@ var checkPermissionDto = z3.object({
3591
3677
  });
3592
3678
 
3593
3679
  // src/permissions/PermissionController.ts
3594
- var __decorate22 = function(decorators, target, key, desc) {
3680
+ var __decorate23 = function(decorators, target, key, desc) {
3595
3681
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3596
3682
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3597
3683
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3598
3684
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3599
3685
  };
3600
- var __metadata22 = function(k, v) {
3686
+ var __metadata23 = function(k, v) {
3601
3687
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3602
3688
  };
3603
3689
  var __param9 = function(paramIndex, decorator) {
@@ -3605,7 +3691,7 @@ var __param9 = function(paramIndex, decorator) {
3605
3691
  decorator(target, key, paramIndex);
3606
3692
  };
3607
3693
  };
3608
- var _a14;
3694
+ var _a15;
3609
3695
  var PermissionController = class PermissionController2 {
3610
3696
  static {
3611
3697
  __name(this, "PermissionController");
@@ -3651,32 +3737,32 @@ var PermissionController = class PermissionController2 {
3651
3737
  return this.permissionService.deleteAll();
3652
3738
  }
3653
3739
  };
3654
- __decorate22([
3740
+ __decorate23([
3655
3741
  Get4(),
3656
3742
  ResMsg4("permissions.success.retrieved"),
3657
- __metadata22("design:type", Function),
3658
- __metadata22("design:paramtypes", []),
3659
- __metadata22("design:returntype", Promise)
3743
+ __metadata23("design:type", Function),
3744
+ __metadata23("design:paramtypes", []),
3745
+ __metadata23("design:returntype", Promise)
3660
3746
  ], PermissionController.prototype, "getPermissions", null);
3661
- __decorate22([
3747
+ __decorate23([
3662
3748
  Get4("/:id"),
3663
3749
  Validate4({ params: permissionIdParam }),
3664
3750
  ResMsg4("permissions.success.retrieved"),
3665
3751
  __param9(0, Params3()),
3666
- __metadata22("design:type", Function),
3667
- __metadata22("design:paramtypes", [Object]),
3668
- __metadata22("design:returntype", Promise)
3752
+ __metadata23("design:type", Function),
3753
+ __metadata23("design:paramtypes", [Object]),
3754
+ __metadata23("design:returntype", Promise)
3669
3755
  ], PermissionController.prototype, "getPermission", null);
3670
- __decorate22([
3756
+ __decorate23([
3671
3757
  Post4(),
3672
3758
  Validate4(createPermissionDto),
3673
3759
  ResMsg4({ message: "Permission created successfully", status: 201 }),
3674
3760
  __param9(0, Body4()),
3675
- __metadata22("design:type", Function),
3676
- __metadata22("design:paramtypes", [Object]),
3677
- __metadata22("design:returntype", Promise)
3761
+ __metadata23("design:type", Function),
3762
+ __metadata23("design:paramtypes", [Object]),
3763
+ __metadata23("design:returntype", Promise)
3678
3764
  ], PermissionController.prototype, "create", null);
3679
- __decorate22([
3765
+ __decorate23([
3680
3766
  Put3("/:id"),
3681
3767
  Validate4({
3682
3768
  params: permissionIdParam,
@@ -3685,67 +3771,67 @@ __decorate22([
3685
3771
  ResMsg4("permissions.success.updated"),
3686
3772
  __param9(0, Params3()),
3687
3773
  __param9(1, Body4()),
3688
- __metadata22("design:type", Function),
3689
- __metadata22("design:paramtypes", [Object, Object]),
3690
- __metadata22("design:returntype", Promise)
3774
+ __metadata23("design:type", Function),
3775
+ __metadata23("design:paramtypes", [Object, Object]),
3776
+ __metadata23("design:returntype", Promise)
3691
3777
  ], PermissionController.prototype, "update", null);
3692
- __decorate22([
3778
+ __decorate23([
3693
3779
  Delete3("/:id"),
3694
3780
  Validate4({ params: permissionIdParam }),
3695
3781
  ResMsg4("permissions.success.deleted"),
3696
3782
  __param9(0, Params3()),
3697
- __metadata22("design:type", Function),
3698
- __metadata22("design:paramtypes", [Object]),
3699
- __metadata22("design:returntype", Promise)
3783
+ __metadata23("design:type", Function),
3784
+ __metadata23("design:paramtypes", [Object]),
3785
+ __metadata23("design:returntype", Promise)
3700
3786
  ], PermissionController.prototype, "delete", null);
3701
- __decorate22([
3787
+ __decorate23([
3702
3788
  Get4("/role/:id"),
3703
3789
  Validate4({ params: roleIdParam }),
3704
3790
  ResMsg4("permissions.success.retrieved"),
3705
3791
  __param9(0, Params3()),
3706
- __metadata22("design:type", Function),
3707
- __metadata22("design:paramtypes", [Object]),
3708
- __metadata22("design:returntype", Promise)
3792
+ __metadata23("design:type", Function),
3793
+ __metadata23("design:paramtypes", [Object]),
3794
+ __metadata23("design:returntype", Promise)
3709
3795
  ], PermissionController.prototype, "getByRole", null);
3710
- __decorate22([
3796
+ __decorate23([
3711
3797
  Get4("/roles/:id"),
3712
3798
  Validate4({ params: permissionIdParam }),
3713
3799
  ResMsg4("permissions.success.retrieved"),
3714
3800
  __param9(0, Params3()),
3715
- __metadata22("design:type", Function),
3716
- __metadata22("design:paramtypes", [Object]),
3717
- __metadata22("design:returntype", Promise)
3801
+ __metadata23("design:type", Function),
3802
+ __metadata23("design:paramtypes", [Object]),
3803
+ __metadata23("design:returntype", Promise)
3718
3804
  ], PermissionController.prototype, "getRolesByPermission", null);
3719
- __decorate22([
3805
+ __decorate23([
3720
3806
  Post4("/assign/:roleId/:permissionId"),
3721
3807
  Validate4({ params: assignPermissionDto }),
3722
3808
  ResMsg4("permissions.success.assigned"),
3723
3809
  __param9(0, Params3()),
3724
- __metadata22("design:type", Function),
3725
- __metadata22("design:paramtypes", [Object]),
3726
- __metadata22("design:returntype", Promise)
3810
+ __metadata23("design:type", Function),
3811
+ __metadata23("design:paramtypes", [Object]),
3812
+ __metadata23("design:returntype", Promise)
3727
3813
  ], PermissionController.prototype, "assignToRole", null);
3728
- __decorate22([
3814
+ __decorate23([
3729
3815
  Delete3("/remove/:roleId/:permissionId"),
3730
3816
  Validate4({ params: assignPermissionDto }),
3731
3817
  ResMsg4("permissions.success.removed"),
3732
3818
  __param9(0, Params3()),
3733
- __metadata22("design:type", Function),
3734
- __metadata22("design:paramtypes", [Object]),
3735
- __metadata22("design:returntype", Promise)
3819
+ __metadata23("design:type", Function),
3820
+ __metadata23("design:paramtypes", [Object]),
3821
+ __metadata23("design:returntype", Promise)
3736
3822
  ], PermissionController.prototype, "removeFromRole", null);
3737
- __decorate22([
3823
+ __decorate23([
3738
3824
  Delete3(),
3739
3825
  isAdmin(),
3740
3826
  ResMsg4("permissions.success.allDeleted"),
3741
- __metadata22("design:type", Function),
3742
- __metadata22("design:paramtypes", []),
3743
- __metadata22("design:returntype", Promise)
3827
+ __metadata23("design:type", Function),
3828
+ __metadata23("design:paramtypes", []),
3829
+ __metadata23("design:returntype", Promise)
3744
3830
  ], PermissionController.prototype, "deleteAll", null);
3745
- PermissionController = __decorate22([
3831
+ PermissionController = __decorate23([
3746
3832
  Controller4("/permissions"),
3747
3833
  isAdmin(),
3748
- __metadata22("design:paramtypes", [typeof (_a14 = typeof PermissionService !== "undefined" && PermissionService) === "function" ? _a14 : Object])
3834
+ __metadata23("design:paramtypes", [typeof (_a15 = typeof PermissionService !== "undefined" && PermissionService) === "function" ? _a15 : Object])
3749
3835
  ], PermissionController);
3750
3836
 
3751
3837
  // src/tokens/index.ts
@@ -3952,15 +4038,15 @@ function own(table, opts) {
3952
4038
  __name(own, "own");
3953
4039
 
3954
4040
  // src/ownership/configureOwnership.ts
3955
- import { Injectable as Injectable11, Inject as Inject11, User as User5, Body as Body5, Params as Params4 } from "najm-core";
4041
+ import { Injectable as Injectable12, Inject as Inject11, User as User5, Body as Body5, Params as Params4 } from "najm-core";
3956
4042
  import { createGuard as createGuard5, composeGuards as composeGuards4 } from "najm-guard";
3957
- var __decorate23 = function(decorators, target, key, desc) {
4043
+ var __decorate24 = function(decorators, target, key, desc) {
3958
4044
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3959
4045
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3960
4046
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3961
4047
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3962
4048
  };
3963
- var __metadata23 = function(k, v) {
4049
+ var __metadata24 = function(k, v) {
3964
4050
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
3965
4051
  };
3966
4052
  var __param10 = function(paramIndex, decorator) {
@@ -3980,7 +4066,7 @@ function toSingular(plural) {
3980
4066
  }
3981
4067
  __name(toSingular, "toSingular");
3982
4068
  function createResourceGuards(ownershipClass, resourceType, resource, options) {
3983
- var _a16, _b8;
4069
+ var _a22, _b12;
3984
4070
  const writeGuard = options?.adminGuard ?? isAdmin;
3985
4071
  let AccessGuard = class AccessGuard {
3986
4072
  static {
@@ -3992,19 +4078,19 @@ function createResourceGuards(ownershipClass, resourceType, resource, options) {
3992
4078
  return allowed ? { owner: user } : false;
3993
4079
  }
3994
4080
  };
3995
- __decorate23([
4081
+ __decorate24([
3996
4082
  Inject11(ownershipClass),
3997
- __metadata23("design:type", Object)
4083
+ __metadata24("design:type", Object)
3998
4084
  ], AccessGuard.prototype, "ownership", void 0);
3999
- __decorate23([
4085
+ __decorate24([
4000
4086
  __param10(0, User5()),
4001
4087
  __param10(1, Params4("id")),
4002
- __metadata23("design:type", Function),
4003
- __metadata23("design:paramtypes", [Object, String]),
4004
- __metadata23("design:returntype", typeof (_a16 = typeof Promise !== "undefined" && Promise) === "function" ? _a16 : Object)
4088
+ __metadata24("design:type", Function),
4089
+ __metadata24("design:paramtypes", [Object, String]),
4090
+ __metadata24("design:returntype", typeof (_a22 = typeof Promise !== "undefined" && Promise) === "function" ? _a22 : Object)
4005
4091
  ], AccessGuard.prototype, "canActivate", null);
4006
- AccessGuard = __decorate23([
4007
- Injectable11()
4092
+ AccessGuard = __decorate24([
4093
+ Injectable12()
4008
4094
  ], AccessGuard);
4009
4095
  let ListGuard = class ListGuard {
4010
4096
  static {
@@ -4016,18 +4102,18 @@ function createResourceGuards(ownershipClass, resourceType, resource, options) {
4016
4102
  return { filter: ids };
4017
4103
  }
4018
4104
  };
4019
- __decorate23([
4105
+ __decorate24([
4020
4106
  Inject11(ownershipClass),
4021
- __metadata23("design:type", Object)
4107
+ __metadata24("design:type", Object)
4022
4108
  ], ListGuard.prototype, "ownership", void 0);
4023
- __decorate23([
4109
+ __decorate24([
4024
4110
  __param10(0, User5()),
4025
- __metadata23("design:type", Function),
4026
- __metadata23("design:paramtypes", [Object]),
4027
- __metadata23("design:returntype", typeof (_b8 = typeof Promise !== "undefined" && Promise) === "function" ? _b8 : Object)
4111
+ __metadata24("design:type", Function),
4112
+ __metadata24("design:paramtypes", [Object]),
4113
+ __metadata24("design:returntype", typeof (_b12 = typeof Promise !== "undefined" && Promise) === "function" ? _b12 : Object)
4028
4114
  ], ListGuard.prototype, "canActivate", null);
4029
- ListGuard = __decorate23([
4030
- Injectable11()
4115
+ ListGuard = __decorate24([
4116
+ Injectable12()
4031
4117
  ], ListGuard);
4032
4118
  const access = createGuard5(AccessGuard);
4033
4119
  const list = createGuard5(ListGuard);
@@ -4158,11 +4244,11 @@ function configureOwnership(config) {
4158
4244
  }
4159
4245
  }
4160
4246
  };
4161
- GeneratedOwnershipService = __decorate23([
4162
- Injectable11()
4247
+ GeneratedOwnershipService = __decorate24([
4248
+ Injectable12()
4163
4249
  ], GeneratedOwnershipService);
4164
4250
  function bodyGuard(resourceType, bodyField, optional = false) {
4165
- var _a16;
4251
+ var _a22;
4166
4252
  let BodyAccessGuard = class BodyAccessGuard {
4167
4253
  static {
4168
4254
  __name(this, "BodyAccessGuard");
@@ -4175,19 +4261,19 @@ function configureOwnership(config) {
4175
4261
  return this.ownership.canAccess(user, resourceType, id);
4176
4262
  }
4177
4263
  };
4178
- __decorate23([
4264
+ __decorate24([
4179
4265
  Inject11(GeneratedOwnershipService),
4180
- __metadata23("design:type", GeneratedOwnershipService)
4266
+ __metadata24("design:type", GeneratedOwnershipService)
4181
4267
  ], BodyAccessGuard.prototype, "ownership", void 0);
4182
- __decorate23([
4268
+ __decorate24([
4183
4269
  __param10(0, User5()),
4184
4270
  __param10(1, Body5()),
4185
- __metadata23("design:type", Function),
4186
- __metadata23("design:paramtypes", [Object, Object]),
4187
- __metadata23("design:returntype", typeof (_a16 = typeof Promise !== "undefined" && Promise) === "function" ? _a16 : Object)
4271
+ __metadata24("design:type", Function),
4272
+ __metadata24("design:paramtypes", [Object, Object]),
4273
+ __metadata24("design:returntype", typeof (_a22 = typeof Promise !== "undefined" && Promise) === "function" ? _a22 : Object)
4188
4274
  ], BodyAccessGuard.prototype, "canActivate", null);
4189
- BodyAccessGuard = __decorate23([
4190
- Injectable11()
4275
+ BodyAccessGuard = __decorate24([
4276
+ Injectable12()
4191
4277
  ], BodyAccessGuard);
4192
4278
  return createGuard5(BodyAccessGuard);
4193
4279
  }
@@ -4302,18 +4388,18 @@ __name(Policy, "Policy");
4302
4388
  // src/ownership/OwnedDecorator.ts
4303
4389
  import "reflect-metadata";
4304
4390
  import { sql as sql5, and as and3 } from "drizzle-orm";
4305
- import { Injectable as Injectable12, Inject as Inject12, DI as DI2, Container as Container2, REQUEST_ID } from "najm-core";
4391
+ import { Injectable as Injectable13, Inject as Inject12, DI as DI2, Container as Container2, REQUEST_ID } from "najm-core";
4306
4392
  import { USER as USER2 } from "najm-guard";
4307
- var __decorate24 = function(decorators, target, key, desc) {
4393
+ var __decorate25 = function(decorators, target, key, desc) {
4308
4394
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4309
4395
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4310
4396
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4311
4397
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4312
4398
  };
4313
- var __metadata24 = function(k, v) {
4399
+ var __metadata25 = function(k, v) {
4314
4400
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4315
4401
  };
4316
- var _a15;
4402
+ var _a16;
4317
4403
  var OWNED_META = /* @__PURE__ */ Symbol.for("najm:owned");
4318
4404
  var ScopeContext = class ScopeContext2 {
4319
4405
  static {
@@ -4345,12 +4431,12 @@ var ScopeContext = class ScopeContext2 {
4345
4431
  }
4346
4432
  }
4347
4433
  };
4348
- __decorate24([
4434
+ __decorate25([
4349
4435
  DI2(),
4350
- __metadata24("design:type", typeof (_a15 = typeof Container2 !== "undefined" && Container2) === "function" ? _a15 : Object)
4436
+ __metadata25("design:type", typeof (_a16 = typeof Container2 !== "undefined" && Container2) === "function" ? _a16 : Object)
4351
4437
  ], ScopeContext.prototype, "container", void 0);
4352
- ScopeContext = __decorate24([
4353
- Injectable12()
4438
+ ScopeContext = __decorate25([
4439
+ Injectable13()
4354
4440
  ], ScopeContext);
4355
4441
  function Owned(token) {
4356
4442
  return function(target) {
@@ -4454,7 +4540,17 @@ var en_default = {
4454
4540
  sessionExpired: "Session has expired",
4455
4541
  accountLocked: "Account is temporarily locked. Please try again later.",
4456
4542
  accountInactive: "Account is inactive. Please contact support.",
4457
- emailNotVerified: "Please verify your email address before signing in."
4543
+ emailNotVerified: "Please verify your email address before signing in.",
4544
+ oauthProviderDisabled: "Google sign-in is not configured.",
4545
+ oauthStateInvalid: "The Google sign-in attempt is invalid or expired.",
4546
+ oauthAccessDenied: "Google sign-in was cancelled.",
4547
+ oauthProviderError: "Google sign-in could not be completed.",
4548
+ oauthVerifiedEmailRequired: "Google must provide a verified email address.",
4549
+ oauthAccountLinkRequired: "Sign in with your password and link Google from your account.",
4550
+ oauthProviderAccountLinked: "This Google account is already linked.",
4551
+ oauthSignupDisabled: "Registration with Google is disabled.",
4552
+ oauthHostedDomainDenied: "This Google Workspace domain is not allowed.",
4553
+ oauthLinkSessionExpired: "Your session changed before Google could be linked. Please try again."
4458
4554
  },
4459
4555
  success: {
4460
4556
  login: "Login successful",
@@ -4464,7 +4560,9 @@ var en_default = {
4464
4560
  passwordResetSent: "If that email exists, a reset link has been sent",
4465
4561
  passwordReset: "Password has been reset successfully",
4466
4562
  accountInviteSent: "Invitation sent successfully",
4467
- tokenRefreshed: "Token refreshed successfully"
4563
+ tokenRefreshed: "Token refreshed successfully",
4564
+ oauthLogin: "Google sign-in successful",
4565
+ oauthLinked: "Google account linked successfully"
4468
4566
  },
4469
4567
  emails: {
4470
4568
  passwordReset: {
@@ -4540,6 +4638,674 @@ function getAuthLocale(lang) {
4540
4638
  __name(getAuthLocale, "getAuthLocale");
4541
4639
  var AUTH_SUPPORTED_LANGUAGES = Object.keys(AUTH_LOCALES);
4542
4640
 
4641
+ // src/oauth/google/GoogleOAuthProvider.ts
4642
+ import { Inject as Inject14, Injectable as Injectable15 } from "najm-core";
4643
+
4644
+ // src/oauth/types.ts
4645
+ var OAuthFlowError = class extends Error {
4646
+ static {
4647
+ __name(this, "OAuthFlowError");
4648
+ }
4649
+ oauthCode;
4650
+ status;
4651
+ constructor(oauthCode, status = 400) {
4652
+ super(oauthCode);
4653
+ this.oauthCode = oauthCode;
4654
+ this.status = status;
4655
+ this.name = "OAuthFlowError";
4656
+ }
4657
+ };
4658
+
4659
+ // src/oauth/google/GoogleTokenVerifier.ts
4660
+ import { Inject as Inject13, Injectable as Injectable14 } from "najm-core";
4661
+ import { createRemoteJWKSet, jwtVerify } from "jose";
4662
+ var __decorate26 = function(decorators, target, key, desc) {
4663
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4664
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4665
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4666
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4667
+ };
4668
+ var __metadata26 = function(k, v) {
4669
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4670
+ };
4671
+ var GOOGLE_JWKS = createRemoteJWKSet(new URL("https://www.googleapis.com/oauth2/v3/certs"));
4672
+ var GoogleTokenVerifier = class GoogleTokenVerifier2 {
4673
+ static {
4674
+ __name(this, "GoogleTokenVerifier");
4675
+ }
4676
+ config;
4677
+ jwks = GOOGLE_JWKS;
4678
+ async verify(idToken, nonce) {
4679
+ const google = this.googleConfig();
4680
+ try {
4681
+ const { payload } = await jwtVerify(idToken, this.jwks, {
4682
+ issuer: ["https://accounts.google.com", "accounts.google.com"],
4683
+ audience: google.clientId,
4684
+ algorithms: ["RS256"]
4685
+ });
4686
+ if (payload.nonce !== nonce)
4687
+ throw new OAuthFlowError("oauth_token_invalid");
4688
+ if (typeof payload.sub !== "string" || !payload.sub) {
4689
+ throw new OAuthFlowError("oauth_token_invalid");
4690
+ }
4691
+ if (typeof payload.email !== "string" || !payload.email || payload.email_verified !== true) {
4692
+ throw new OAuthFlowError("oauth_verified_email_required");
4693
+ }
4694
+ const hostedDomain = typeof payload.hd === "string" ? payload.hd.toLowerCase() : void 0;
4695
+ if (google.allowedHostedDomains.length > 0 && (!hostedDomain || !google.allowedHostedDomains.includes(hostedDomain))) {
4696
+ throw new OAuthFlowError("oauth_hosted_domain_denied", 403);
4697
+ }
4698
+ return {
4699
+ provider: "google",
4700
+ providerAccountId: payload.sub,
4701
+ email: payload.email.trim().toLowerCase(),
4702
+ emailVerified: true,
4703
+ name: typeof payload.name === "string" ? payload.name : void 0,
4704
+ picture: typeof payload.picture === "string" ? payload.picture : void 0,
4705
+ hostedDomain
4706
+ };
4707
+ } catch (error) {
4708
+ if (error instanceof OAuthFlowError)
4709
+ throw error;
4710
+ throw new OAuthFlowError("oauth_token_invalid");
4711
+ }
4712
+ }
4713
+ googleConfig() {
4714
+ const google = this.config.oauth?.google;
4715
+ if (!google)
4716
+ throw new OAuthFlowError("oauth_provider_disabled", 404);
4717
+ return google;
4718
+ }
4719
+ };
4720
+ __decorate26([
4721
+ Inject13(AUTH_CONFIG),
4722
+ __metadata26("design:type", Object)
4723
+ ], GoogleTokenVerifier.prototype, "config", void 0);
4724
+ GoogleTokenVerifier = __decorate26([
4725
+ Injectable14()
4726
+ ], GoogleTokenVerifier);
4727
+
4728
+ // src/oauth/google/GoogleOAuthProvider.ts
4729
+ var __decorate27 = function(decorators, target, key, desc) {
4730
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4731
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4732
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4733
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4734
+ };
4735
+ var __metadata27 = function(k, v) {
4736
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4737
+ };
4738
+ var _a17;
4739
+ var AUTHORIZATION_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth";
4740
+ var TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
4741
+ var GoogleOAuthProvider = class GoogleOAuthProvider2 {
4742
+ static {
4743
+ __name(this, "GoogleOAuthProvider");
4744
+ }
4745
+ verifier;
4746
+ config;
4747
+ constructor(verifier) {
4748
+ this.verifier = verifier;
4749
+ }
4750
+ authorizationUrl(attempt, codeChallenge) {
4751
+ const google = this.googleConfig();
4752
+ const url = new URL(AUTHORIZATION_ENDPOINT);
4753
+ url.search = new URLSearchParams({
4754
+ client_id: google.clientId,
4755
+ redirect_uri: google.callbackUrl,
4756
+ response_type: "code",
4757
+ scope: "openid email profile",
4758
+ state: attempt.state,
4759
+ nonce: attempt.nonce,
4760
+ code_challenge: codeChallenge,
4761
+ code_challenge_method: "S256"
4762
+ }).toString();
4763
+ return url.toString();
4764
+ }
4765
+ async exchange(code, attempt) {
4766
+ const google = this.googleConfig();
4767
+ let response;
4768
+ try {
4769
+ response = await fetch(TOKEN_ENDPOINT, {
4770
+ method: "POST",
4771
+ headers: { "content-type": "application/x-www-form-urlencoded" },
4772
+ body: new URLSearchParams({
4773
+ code,
4774
+ client_id: google.clientId,
4775
+ client_secret: google.clientSecret,
4776
+ redirect_uri: google.callbackUrl,
4777
+ grant_type: "authorization_code",
4778
+ code_verifier: attempt.codeVerifier
4779
+ }),
4780
+ signal: AbortSignal.timeout(15e3)
4781
+ });
4782
+ } catch {
4783
+ throw new OAuthFlowError("oauth_provider_error", 502);
4784
+ }
4785
+ if (!response.ok)
4786
+ throw new OAuthFlowError("oauth_provider_error", 502);
4787
+ let body;
4788
+ try {
4789
+ body = await response.json();
4790
+ } catch {
4791
+ throw new OAuthFlowError("oauth_provider_error", 502);
4792
+ }
4793
+ const idToken = body.id_token;
4794
+ if (typeof idToken !== "string" || !idToken) {
4795
+ throw new OAuthFlowError("oauth_provider_error", 502);
4796
+ }
4797
+ return this.verifier.verify(idToken, attempt.nonce);
4798
+ }
4799
+ googleConfig() {
4800
+ const google = this.config.oauth?.google;
4801
+ if (!google)
4802
+ throw new OAuthFlowError("oauth_provider_disabled", 404);
4803
+ return google;
4804
+ }
4805
+ };
4806
+ __decorate27([
4807
+ Inject14(AUTH_CONFIG),
4808
+ __metadata27("design:type", Object)
4809
+ ], GoogleOAuthProvider.prototype, "config", void 0);
4810
+ GoogleOAuthProvider = __decorate27([
4811
+ Injectable15(),
4812
+ __metadata27("design:paramtypes", [typeof (_a17 = typeof GoogleTokenVerifier !== "undefined" && GoogleTokenVerifier) === "function" ? _a17 : Object])
4813
+ ], GoogleOAuthProvider);
4814
+
4815
+ // src/oauth/OAuthAccountRepository.ts
4816
+ import { and as and4, eq as eq7 } from "drizzle-orm";
4817
+ import { Inject as Inject15, Repository as Repository5 } from "najm-core";
4818
+ import { DB as DB5 } from "najm-database";
4819
+ var __decorate28 = function(decorators, target, key, desc) {
4820
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4821
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4822
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4823
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4824
+ };
4825
+ var __metadata28 = function(k, v) {
4826
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4827
+ };
4828
+ var OAuthAccountRepository = class OAuthAccountRepository2 {
4829
+ static {
4830
+ __name(this, "OAuthAccountRepository");
4831
+ }
4832
+ db;
4833
+ schema;
4834
+ get accounts() {
4835
+ if (!this.schema.oauthAccounts) {
4836
+ throw new OAuthFlowError("oauth_schema_missing", 500);
4837
+ }
4838
+ return this.schema.oauthAccounts;
4839
+ }
4840
+ async getByProviderAccount(provider, providerAccountId) {
4841
+ const [account] = await this.db.select().from(this.accounts).where(and4(eq7(this.accounts.provider, provider), eq7(this.accounts.providerAccountId, providerAccountId))).limit(1);
4842
+ return account;
4843
+ }
4844
+ async getByUserProvider(userId, provider) {
4845
+ const [account] = await this.db.select().from(this.accounts).where(and4(eq7(this.accounts.userId, userId), eq7(this.accounts.provider, provider))).limit(1);
4846
+ return account;
4847
+ }
4848
+ async create(data) {
4849
+ const [account] = await this.db.insert(this.accounts).values(data).onConflictDoNothing().returning();
4850
+ return account;
4851
+ }
4852
+ };
4853
+ __decorate28([
4854
+ DB5(),
4855
+ __metadata28("design:type", Object)
4856
+ ], OAuthAccountRepository.prototype, "db", void 0);
4857
+ __decorate28([
4858
+ Inject15(AUTH_SCHEMA),
4859
+ __metadata28("design:type", Object)
4860
+ ], OAuthAccountRepository.prototype, "schema", void 0);
4861
+ OAuthAccountRepository = __decorate28([
4862
+ Repository5()
4863
+ ], OAuthAccountRepository);
4864
+
4865
+ // src/oauth/OAuthAccountService.ts
4866
+ import { randomBytes as randomBytes2 } from "crypto";
4867
+ import { Inject as Inject16, Injectable as Injectable16 } from "najm-core";
4868
+ import { Transaction as Transaction2 } from "najm-database";
4869
+ var __decorate29 = function(decorators, target, key, desc) {
4870
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4871
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4872
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4873
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4874
+ };
4875
+ var __metadata29 = function(k, v) {
4876
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4877
+ };
4878
+ var _a18;
4879
+ var _b9;
4880
+ var _c6;
4881
+ var _d3;
4882
+ var OAuthAccountService = class OAuthAccountService2 {
4883
+ static {
4884
+ __name(this, "OAuthAccountService");
4885
+ }
4886
+ accounts;
4887
+ users;
4888
+ config;
4889
+ constructor(accounts, users) {
4890
+ this.accounts = accounts;
4891
+ this.users = users;
4892
+ }
4893
+ async resolveForLogin(identity) {
4894
+ const linked = await this.accounts.getByProviderAccount("google", identity.providerAccountId);
4895
+ if (linked)
4896
+ return this.users.getById(linked.userId);
4897
+ const existingUser = await this.users.findByEmailInsensitive(identity.email);
4898
+ if (existingUser) {
4899
+ if (!this.googleConfig().autoLinkVerifiedEmail) {
4900
+ throw new OAuthFlowError("oauth_account_link_required", 409);
4901
+ }
4902
+ await this.createLink(existingUser.id, identity);
4903
+ return this.users.getById(existingUser.id);
4904
+ }
4905
+ if (!this.googleConfig().allowSignup) {
4906
+ throw new OAuthFlowError("oauth_signup_disabled", 403);
4907
+ }
4908
+ const password = `${randomBytes2(32).toString("base64url")}Aa1`;
4909
+ const user = await this.users.create({
4910
+ name: identity.name,
4911
+ email: identity.email,
4912
+ password,
4913
+ image: identity.picture,
4914
+ emailVerified: true
4915
+ });
4916
+ await this.createLink(user.id, identity);
4917
+ return this.users.getById(user.id);
4918
+ }
4919
+ async linkUser(userId, identity) {
4920
+ const user = await this.users.getById(userId);
4921
+ if (user.status !== "active")
4922
+ throw new OAuthFlowError("oauth_account_inactive", 403);
4923
+ const providerAccount = await this.accounts.getByProviderAccount("google", identity.providerAccountId);
4924
+ if (providerAccount && providerAccount.userId !== userId) {
4925
+ throw new OAuthFlowError("oauth_provider_account_linked", 409);
4926
+ }
4927
+ if (providerAccount)
4928
+ return user;
4929
+ const userProvider = await this.accounts.getByUserProvider(userId, "google");
4930
+ if (userProvider && userProvider.providerAccountId !== identity.providerAccountId) {
4931
+ throw new OAuthFlowError("oauth_user_provider_linked", 409);
4932
+ }
4933
+ if (!userProvider)
4934
+ await this.createLink(userId, identity);
4935
+ return user;
4936
+ }
4937
+ async createLink(userId, identity) {
4938
+ const created = await this.accounts.create({
4939
+ userId,
4940
+ provider: "google",
4941
+ providerAccountId: identity.providerAccountId
4942
+ });
4943
+ if (created)
4944
+ return;
4945
+ const linked = await this.accounts.getByProviderAccount("google", identity.providerAccountId);
4946
+ if (!linked || linked.userId !== userId) {
4947
+ throw new OAuthFlowError("oauth_provider_account_linked", 409);
4948
+ }
4949
+ }
4950
+ googleConfig() {
4951
+ const google = this.config.oauth?.google;
4952
+ if (!google)
4953
+ throw new OAuthFlowError("oauth_provider_disabled", 404);
4954
+ return google;
4955
+ }
4956
+ };
4957
+ __decorate29([
4958
+ Inject16(AUTH_CONFIG),
4959
+ __metadata29("design:type", Object)
4960
+ ], OAuthAccountService.prototype, "config", void 0);
4961
+ __decorate29([
4962
+ Transaction2(),
4963
+ __metadata29("design:type", Function),
4964
+ __metadata29("design:paramtypes", [Object]),
4965
+ __metadata29("design:returntype", typeof (_c6 = typeof Promise !== "undefined" && Promise) === "function" ? _c6 : Object)
4966
+ ], OAuthAccountService.prototype, "resolveForLogin", null);
4967
+ __decorate29([
4968
+ Transaction2(),
4969
+ __metadata29("design:type", Function),
4970
+ __metadata29("design:paramtypes", [String, Object]),
4971
+ __metadata29("design:returntype", typeof (_d3 = typeof Promise !== "undefined" && Promise) === "function" ? _d3 : Object)
4972
+ ], OAuthAccountService.prototype, "linkUser", null);
4973
+ OAuthAccountService = __decorate29([
4974
+ Injectable16(),
4975
+ __metadata29("design:paramtypes", [typeof (_a18 = typeof OAuthAccountRepository !== "undefined" && OAuthAccountRepository) === "function" ? _a18 : Object, typeof (_b9 = typeof UserService !== "undefined" && UserService) === "function" ? _b9 : Object])
4976
+ ], OAuthAccountService);
4977
+
4978
+ // src/oauth/OAuthController.ts
4979
+ import { createHash as createHash4 } from "crypto";
4980
+ import { Controller as Controller5, Ctx, Get as Get5, Post as Post5, Query as Query2, User as User6 } from "najm-core";
4981
+ import { RateLimit as RateLimit2 } from "najm-rate";
4982
+
4983
+ // src/oauth/OAuthService.ts
4984
+ import { Inject as Inject17, Injectable as Injectable18, Log as Log2 } from "najm-core";
4985
+
4986
+ // src/oauth/OAuthStateService.ts
4987
+ import { createHash as createHash3, randomBytes as randomBytes3, timingSafeEqual } from "crypto";
4988
+ import { Injectable as Injectable17 } from "najm-core";
4989
+ import { CookieService as CookieService2 } from "najm-cookies";
4990
+ var __decorate30 = function(decorators, target, key, desc) {
4991
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4992
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4993
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4994
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4995
+ };
4996
+ var __metadata30 = function(k, v) {
4997
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
4998
+ };
4999
+ var _a19;
5000
+ var _b10;
5001
+ var ATTEMPT_TTL_MS = 10 * 60 * 1e3;
5002
+ var COOKIE_PREFIX = "najm.oauth.google.";
5003
+ var OAuthStateService = class OAuthStateService2 {
5004
+ static {
5005
+ __name(this, "OAuthStateService");
5006
+ }
5007
+ cookies;
5008
+ encryption;
5009
+ constructor(cookies2, encryption) {
5010
+ this.cookies = cookies2;
5011
+ this.encryption = encryption;
5012
+ }
5013
+ create(input) {
5014
+ const state = randomBytes3(32).toString("base64url");
5015
+ const codeVerifier = randomBytes3(48).toString("base64url");
5016
+ const attempt = {
5017
+ provider: "google",
5018
+ intent: input.intent,
5019
+ state,
5020
+ nonce: randomBytes3(32).toString("base64url"),
5021
+ codeVerifier,
5022
+ returnTo: this.validateReturnTo(input.returnTo),
5023
+ userId: input.userId,
5024
+ sessionVersion: input.sessionVersion,
5025
+ createdAt: Date.now()
5026
+ };
5027
+ this.cookies.set(this.cookieName(state), this.encryption.encrypt(JSON.stringify(attempt)), {
5028
+ httpOnly: true,
5029
+ sameSite: "Lax",
5030
+ path: "/",
5031
+ maxAge: Math.floor(ATTEMPT_TTL_MS / 1e3)
5032
+ });
5033
+ return {
5034
+ attempt,
5035
+ codeChallenge: createHash3("sha256").update(codeVerifier).digest("base64url")
5036
+ };
5037
+ }
5038
+ consume(state) {
5039
+ if (!this.isSafeState(state))
5040
+ throw new OAuthFlowError("oauth_state_invalid");
5041
+ const name = this.cookieName(state);
5042
+ const encrypted = this.cookies.get(name);
5043
+ this.cookies.delete(name, { path: "/" });
5044
+ if (!encrypted)
5045
+ throw new OAuthFlowError("oauth_state_invalid");
5046
+ try {
5047
+ const attempt = JSON.parse(this.encryption.decrypt(encrypted));
5048
+ const expected = Buffer.from(attempt.state);
5049
+ const actual = Buffer.from(state);
5050
+ if (expected.length !== actual.length || !timingSafeEqual(expected, actual)) {
5051
+ throw new OAuthFlowError("oauth_state_invalid");
5052
+ }
5053
+ if (attempt.provider !== "google" || Date.now() - attempt.createdAt > ATTEMPT_TTL_MS) {
5054
+ throw new OAuthFlowError("oauth_state_invalid");
5055
+ }
5056
+ attempt.returnTo = this.validateReturnTo(attempt.returnTo);
5057
+ return attempt;
5058
+ } catch (error) {
5059
+ if (error instanceof OAuthFlowError)
5060
+ throw error;
5061
+ throw new OAuthFlowError("oauth_state_invalid");
5062
+ }
5063
+ }
5064
+ validateReturnTo(value) {
5065
+ const candidate = value?.trim() || "/";
5066
+ if (!candidate.startsWith("/") || candidate.startsWith("//") || candidate.includes("\\")) {
5067
+ throw new OAuthFlowError("oauth_redirect_invalid");
5068
+ }
5069
+ try {
5070
+ const base = new URL("https://najm.invalid");
5071
+ const parsed = new URL(candidate, base);
5072
+ if (parsed.origin !== base.origin || parsed.username || parsed.password) {
5073
+ throw new OAuthFlowError("oauth_redirect_invalid");
5074
+ }
5075
+ return `${parsed.pathname}${parsed.search}${parsed.hash}`;
5076
+ } catch (error) {
5077
+ if (error instanceof OAuthFlowError)
5078
+ throw error;
5079
+ throw new OAuthFlowError("oauth_redirect_invalid");
5080
+ }
5081
+ }
5082
+ cookieName(state) {
5083
+ return `${COOKIE_PREFIX}${state}`;
5084
+ }
5085
+ isSafeState(state) {
5086
+ return /^[A-Za-z0-9_-]{40,128}$/.test(state);
5087
+ }
5088
+ };
5089
+ OAuthStateService = __decorate30([
5090
+ Injectable17(),
5091
+ __metadata30("design:paramtypes", [typeof (_a19 = typeof CookieService2 !== "undefined" && CookieService2) === "function" ? _a19 : Object, typeof (_b10 = typeof EncryptionService !== "undefined" && EncryptionService) === "function" ? _b10 : Object])
5092
+ ], OAuthStateService);
5093
+
5094
+ // src/oauth/OAuthService.ts
5095
+ var __decorate31 = function(decorators, target, key, desc) {
5096
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5097
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5098
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5099
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5100
+ };
5101
+ var __metadata31 = function(k, v) {
5102
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5103
+ };
5104
+ var _a20;
5105
+ var _b11;
5106
+ var _c7;
5107
+ var _d4;
5108
+ var _e3;
5109
+ var _f3;
5110
+ var OAuthService = class OAuthService2 {
5111
+ static {
5112
+ __name(this, "OAuthService");
5113
+ }
5114
+ state;
5115
+ google;
5116
+ accounts;
5117
+ sessions;
5118
+ tokens;
5119
+ users;
5120
+ config;
5121
+ logger;
5122
+ constructor(state, google, accounts, sessions, tokens, users) {
5123
+ this.state = state;
5124
+ this.google = google;
5125
+ this.accounts = accounts;
5126
+ this.sessions = sessions;
5127
+ this.tokens = tokens;
5128
+ this.users = users;
5129
+ }
5130
+ startGoogleLogin(returnTo) {
5131
+ this.googleConfig();
5132
+ const { attempt, codeChallenge } = this.state.create({ intent: "login", returnTo });
5133
+ return this.google.authorizationUrl(attempt, codeChallenge);
5134
+ }
5135
+ async startGoogleLink(userId, returnTo) {
5136
+ this.googleConfig();
5137
+ const user = await this.users.getById(userId);
5138
+ if (user.status !== "active")
5139
+ throw new OAuthFlowError("oauth_account_inactive", 403);
5140
+ const sessionVersion = await this.tokens.getSessionVersion(userId);
5141
+ const { attempt, codeChallenge } = this.state.create({
5142
+ intent: "link",
5143
+ returnTo,
5144
+ userId,
5145
+ sessionVersion
5146
+ });
5147
+ return { authorizationUrl: this.google.authorizationUrl(attempt, codeChallenge) };
5148
+ }
5149
+ async finishGoogleCallback(params) {
5150
+ try {
5151
+ this.googleConfig();
5152
+ if (!params.state)
5153
+ throw new OAuthFlowError("oauth_state_invalid");
5154
+ const attempt = this.state.consume(params.state);
5155
+ if (params.error) {
5156
+ throw new OAuthFlowError(params.error === "access_denied" ? "oauth_access_denied" : "oauth_provider_error");
5157
+ }
5158
+ if (!params.code)
5159
+ throw new OAuthFlowError("oauth_provider_error");
5160
+ const identity = await this.google.exchange(params.code, attempt);
5161
+ if (attempt.intent === "link") {
5162
+ if (!attempt.userId || attempt.sessionVersion === void 0) {
5163
+ throw new OAuthFlowError("oauth_state_invalid");
5164
+ }
5165
+ const currentVersion = await this.tokens.getSessionVersion(attempt.userId);
5166
+ if (currentVersion !== attempt.sessionVersion) {
5167
+ throw new OAuthFlowError("oauth_link_session_expired", 401);
5168
+ }
5169
+ await this.accounts.linkUser(attempt.userId, identity);
5170
+ } else {
5171
+ const user = await this.accounts.resolveForLogin(identity);
5172
+ await this.sessions.establish(user);
5173
+ }
5174
+ return this.frontendSuccessUrl(attempt.returnTo, attempt.intent);
5175
+ } catch (error) {
5176
+ const code = this.publicErrorCode(error);
5177
+ this.logger.warn("Google OAuth callback failed", { provider: "google", code });
5178
+ return this.frontendErrorUrl(code);
5179
+ }
5180
+ }
5181
+ frontendSuccessUrl(returnTo, mode) {
5182
+ const google = this.googleConfig();
5183
+ const url = new URL(google.frontendCallbackPath, this.config.frontendUrl);
5184
+ url.searchParams.set("provider", "google");
5185
+ url.searchParams.set("mode", mode);
5186
+ url.searchParams.set("returnTo", this.state.validateReturnTo(returnTo));
5187
+ return url.toString();
5188
+ }
5189
+ frontendErrorUrl(code) {
5190
+ const path2 = this.config.oauth?.google?.errorRedirectPath ?? "/login";
5191
+ const url = new URL(path2, this.config.frontendUrl);
5192
+ url.searchParams.set("oauthError", code);
5193
+ return url.toString();
5194
+ }
5195
+ publicErrorCode(error) {
5196
+ if (error instanceof OAuthFlowError)
5197
+ return error.oauthCode;
5198
+ if (error instanceof Error && /^oauth_[a-z0-9_]+$/.test(error.message))
5199
+ return error.message;
5200
+ return "oauth_provider_error";
5201
+ }
5202
+ googleConfig() {
5203
+ const google = this.config.oauth?.google;
5204
+ if (!google)
5205
+ throw new OAuthFlowError("oauth_provider_disabled", 404);
5206
+ return google;
5207
+ }
5208
+ };
5209
+ __decorate31([
5210
+ Inject17(AUTH_CONFIG),
5211
+ __metadata31("design:type", Object)
5212
+ ], OAuthService.prototype, "config", void 0);
5213
+ __decorate31([
5214
+ Log2(),
5215
+ __metadata31("design:type", Object)
5216
+ ], OAuthService.prototype, "logger", void 0);
5217
+ OAuthService = __decorate31([
5218
+ Injectable18(),
5219
+ __metadata31("design:paramtypes", [typeof (_a20 = typeof OAuthStateService !== "undefined" && OAuthStateService) === "function" ? _a20 : Object, typeof (_b11 = typeof GoogleOAuthProvider !== "undefined" && GoogleOAuthProvider) === "function" ? _b11 : Object, typeof (_c7 = typeof OAuthAccountService !== "undefined" && OAuthAccountService) === "function" ? _c7 : Object, typeof (_d4 = typeof AuthSessionService !== "undefined" && AuthSessionService) === "function" ? _d4 : Object, typeof (_e3 = typeof TokenService !== "undefined" && TokenService) === "function" ? _e3 : Object, typeof (_f3 = typeof UserService !== "undefined" && UserService) === "function" ? _f3 : Object])
5220
+ ], OAuthService);
5221
+
5222
+ // src/oauth/OAuthController.ts
5223
+ var __decorate32 = function(decorators, target, key, desc) {
5224
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5225
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5226
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5227
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5228
+ };
5229
+ var __metadata32 = function(k, v) {
5230
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5231
+ };
5232
+ var __param11 = function(paramIndex, decorator) {
5233
+ return function(target, key) {
5234
+ decorator(target, key, paramIndex);
5235
+ };
5236
+ };
5237
+ var _a21;
5238
+ var callbackKey = /* @__PURE__ */ __name((ctx) => {
5239
+ const ip = ctx.req.header("x-forwarded-for")?.split(",")[0]?.trim() ?? ctx.req.header("x-real-ip") ?? "unknown";
5240
+ const state = ctx.req.query("state") ?? "none";
5241
+ const fingerprint = createHash4("sha256").update(state).digest("base64url").slice(0, 24);
5242
+ return `${ip}:${fingerprint}`;
5243
+ }, "callbackKey");
5244
+ var OAuthController = class OAuthController2 {
5245
+ static {
5246
+ __name(this, "OAuthController");
5247
+ }
5248
+ oauth;
5249
+ constructor(oauth) {
5250
+ this.oauth = oauth;
5251
+ }
5252
+ start(ctx, returnTo) {
5253
+ return ctx.redirect(this.oauth.startGoogleLogin(returnTo), 302);
5254
+ }
5255
+ async callback(ctx, code, state, error) {
5256
+ const redirect = await this.oauth.finishGoogleCallback({ code, state, error });
5257
+ return ctx.redirect(redirect, 302);
5258
+ }
5259
+ link(userId, returnTo) {
5260
+ return this.oauth.startGoogleLink(userId, returnTo);
5261
+ }
5262
+ };
5263
+ __decorate32([
5264
+ Get5("/start"),
5265
+ RateLimit2({ limit: 20, window: "15m", key: "ip" }),
5266
+ __param11(0, Ctx()),
5267
+ __param11(1, Query2("returnTo")),
5268
+ __metadata32("design:type", Function),
5269
+ __metadata32("design:paramtypes", [Object, String]),
5270
+ __metadata32("design:returntype", void 0)
5271
+ ], OAuthController.prototype, "start", null);
5272
+ __decorate32([
5273
+ Get5("/callback"),
5274
+ RateLimit2({ limit: 20, window: "15m", key: callbackKey }),
5275
+ __param11(0, Ctx()),
5276
+ __param11(1, Query2("code")),
5277
+ __param11(2, Query2("state")),
5278
+ __param11(3, Query2("error")),
5279
+ __metadata32("design:type", Function),
5280
+ __metadata32("design:paramtypes", [Object, String, String, String]),
5281
+ __metadata32("design:returntype", Promise)
5282
+ ], OAuthController.prototype, "callback", null);
5283
+ __decorate32([
5284
+ Post5("/link"),
5285
+ isAuth(),
5286
+ RateLimit2({ limit: 10, window: "15m", key: "user" }),
5287
+ __param11(0, User6("id")),
5288
+ __param11(1, Query2("returnTo")),
5289
+ __metadata32("design:type", Function),
5290
+ __metadata32("design:paramtypes", [String, String]),
5291
+ __metadata32("design:returntype", void 0)
5292
+ ], OAuthController.prototype, "link", null);
5293
+ OAuthController = __decorate32([
5294
+ Controller5("/auth/oauth/google"),
5295
+ __metadata32("design:paramtypes", [typeof (_a21 = typeof OAuthService !== "undefined" && OAuthService) === "function" ? _a21 : Object])
5296
+ ], OAuthController);
5297
+
5298
+ // src/oauth/index.ts
5299
+ var OAUTH_MODULE = [
5300
+ OAuthAccountRepository,
5301
+ OAuthAccountService,
5302
+ OAuthStateService,
5303
+ GoogleTokenVerifier,
5304
+ GoogleOAuthProvider,
5305
+ OAuthService,
5306
+ OAuthController
5307
+ ];
5308
+
4543
5309
  // src/AuthPlugin.ts
4544
5310
  var DEFAULT_JWT = {
4545
5311
  accessSecret: process.env.JWT_ACCESS_SECRET || "",
@@ -4547,7 +5313,47 @@ var DEFAULT_JWT = {
4547
5313
  refreshSecret: process.env.JWT_REFRESH_SECRET || "",
4548
5314
  refreshExpiresIn: process.env.REFRESH_EXPIRES_IN || "7d"
4549
5315
  };
4550
- var mergeConfig = /* @__PURE__ */ __name((config) => {
5316
+ var validateFrontendPath = /* @__PURE__ */ __name((value, name) => {
5317
+ if (!value.startsWith("/") || value.startsWith("//") || value.includes("\\")) {
5318
+ throw new Error(`${name} must be a same-origin path starting with a single '/'`);
5319
+ }
5320
+ return value;
5321
+ }, "validateFrontendPath");
5322
+ var resolveGoogleConfig = /* @__PURE__ */ __name((config) => {
5323
+ const configuredGoogle = config?.oauth?.google;
5324
+ if (!configuredGoogle)
5325
+ return void 0;
5326
+ const google = configuredGoogle === true ? {} : configuredGoogle;
5327
+ const clientId = google.clientId ?? process.env.GOOGLE_CLIENT_ID ?? "";
5328
+ const clientSecret = google.clientSecret ?? process.env.GOOGLE_CLIENT_SECRET ?? "";
5329
+ if (!clientId)
5330
+ throw Err10.configRequired("auth.oauth.google", "GOOGLE_CLIENT_ID");
5331
+ if (!clientSecret)
5332
+ throw Err10.configRequired("auth.oauth.google", "GOOGLE_CLIENT_SECRET");
5333
+ const frontendUrl = config?.frontendUrl ?? process.env.FRONTEND_URL ?? "http://localhost:3000";
5334
+ const callbackUrl = google.callbackUrl ?? process.env.GOOGLE_CALLBACK_URL ?? `${frontendUrl.replace(/\/$/, "")}/api/auth/oauth/google/callback`;
5335
+ let callback;
5336
+ try {
5337
+ callback = new URL(callbackUrl);
5338
+ } catch {
5339
+ throw new Error("auth.oauth.google.callbackUrl must be an absolute URL");
5340
+ }
5341
+ const local = callback.hostname === "localhost" || callback.hostname === "127.0.0.1" || callback.hostname === "[::1]" || callback.hostname === "::1";
5342
+ if (callback.protocol !== "https:" && !(local && callback.protocol === "http:")) {
5343
+ throw new Error("auth.oauth.google.callbackUrl must use HTTPS (HTTP is allowed only for localhost)");
5344
+ }
5345
+ return {
5346
+ clientId,
5347
+ clientSecret,
5348
+ callbackUrl: callback.toString(),
5349
+ frontendCallbackPath: validateFrontendPath(google.frontendCallbackPath ?? "/auth/oauth/callback", "auth.oauth.google.frontendCallbackPath"),
5350
+ errorRedirectPath: validateFrontendPath(google.errorRedirectPath ?? "/login", "auth.oauth.google.errorRedirectPath"),
5351
+ allowSignup: google.allowSignup ?? true,
5352
+ autoLinkVerifiedEmail: google.autoLinkVerifiedEmail ?? false,
5353
+ allowedHostedDomains: [...new Set((google.allowedHostedDomains ?? []).map((domain) => domain.trim().toLowerCase()).filter(Boolean))]
5354
+ };
5355
+ }, "resolveGoogleConfig");
5356
+ var resolveAuthConfig = /* @__PURE__ */ __name((config) => {
4551
5357
  const bcryptRounds = config?.bcryptRounds ?? 10;
4552
5358
  if (!Number.isInteger(bcryptRounds) || bcryptRounds < 4 || bcryptRounds > 31) {
4553
5359
  throw new Error("auth.bcryptRounds must be an integer between 4 and 31");
@@ -4575,19 +5381,26 @@ var mergeConfig = /* @__PURE__ */ __name((config) => {
4575
5381
  maxAge: config?.session?.maxAge ?? 300,
4576
5382
  secret: config?.session?.secret
4577
5383
  // fallback to jwt.accessSecret at use site
5384
+ },
5385
+ oauth: {
5386
+ google: resolveGoogleConfig(config)
4578
5387
  }
4579
5388
  };
4580
5389
  if (!finalConfig.jwt.accessSecret) {
4581
- throw Err9.configRequired("auth", "JWT_ACCESS_SECRET");
5390
+ throw Err10.configRequired("auth", "JWT_ACCESS_SECRET");
4582
5391
  }
4583
5392
  if (!finalConfig.jwt.refreshSecret) {
4584
- throw Err9.configRequired("auth", "JWT_REFRESH_SECRET");
5393
+ throw Err10.configRequired("auth", "JWT_REFRESH_SECRET");
4585
5394
  }
4586
5395
  return finalConfig;
4587
- }, "mergeConfig");
4588
- var selectSchema = /* @__PURE__ */ __name((config) => {
4589
- if (config?.schema)
5396
+ }, "resolveAuthConfig");
5397
+ var selectAuthSchema = /* @__PURE__ */ __name((config) => {
5398
+ if (config?.schema) {
5399
+ if (config.oauth?.google && !config.schema.oauthAccounts) {
5400
+ throw new Error("auth.schema.oauthAccounts is required when Google OAuth is enabled");
5401
+ }
4590
5402
  return config.schema;
5403
+ }
4591
5404
  const dialect = config?.dialect ?? "pg";
4592
5405
  switch (dialect) {
4593
5406
  case "sqlite":
@@ -4596,8 +5409,8 @@ var selectSchema = /* @__PURE__ */ __name((config) => {
4596
5409
  default:
4597
5410
  return authSchema;
4598
5411
  }
4599
- }, "selectSchema");
4600
- var auth = /* @__PURE__ */ __name((config) => plugin("auth").version("1.0.0").depends(cache(), cookies(), i18n(), guards(), validation(config?.validation), rateLimit(config?.rateLimit), email()).requires("database").contributes(I18N_CONTRIBUTIONS, AUTH_LOCALES).services(AUTH_MODULE, users_exports, roles_exports, permissions_exports, tokens_exports, ScopeContext).config(AUTH_CONFIG, mergeConfig(config)).set(AUTH_SCHEMA, selectSchema(config)).set(AUTH_ENCRYPTION_KEY, config?.encryptionKey ?? null).build(), "auth");
5412
+ }, "selectAuthSchema");
5413
+ var auth = /* @__PURE__ */ __name((config) => plugin("auth").version("1.0.0").depends(cache(), cookies(), i18n(), guards(), validation(config?.validation), rateLimit(config?.rateLimit), email(config?.email)).requires("database").contributes(I18N_CONTRIBUTIONS, AUTH_LOCALES).services(AUTH_MODULE, OAUTH_MODULE, users_exports, roles_exports, permissions_exports, tokens_exports, ScopeContext).config(AUTH_CONFIG, resolveAuthConfig(config)).set(AUTH_SCHEMA, selectAuthSchema(config)).set(AUTH_ENCRYPTION_KEY, config?.encryptionKey ?? null).build(), "auth");
4601
5414
 
4602
5415
  // src/seed.ts
4603
5416
  var toSeedId = /* @__PURE__ */ __name((prefix, value) => {
@@ -4743,6 +5556,7 @@ export {
4743
5556
  AuthQueries,
4744
5557
  AuthResolver,
4745
5558
  AuthService,
5559
+ AuthSessionService,
4746
5560
  Can,
4747
5561
  CanCreate,
4748
5562
  CanDelete,
@@ -4811,6 +5625,7 @@ export {
4811
5625
  join2 as join,
4812
5626
  languageParam,
4813
5627
  loginDto,
5628
+ oauthAccountsTable,
4814
5629
  own,
4815
5630
  parseSchema,
4816
5631
  permissionIdParam,