@guren/server 2.21.0 → 2.23.0

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.
Files changed (115) hide show
  1. package/dist/Job-BxioDEcS.js +165 -0
  2. package/dist/{Logger-DFifRAtc.js → Logger-DWXdtLSJ.js} +62 -2
  3. package/dist/agent/approval-status.d.ts +1 -1
  4. package/dist/agent/approval.d.ts +2 -2
  5. package/dist/agent/audit-emitter.d.ts +11 -1
  6. package/dist/agent/gate.d.ts +10 -8
  7. package/dist/agent/meta-tools.d.ts +13 -5
  8. package/dist/agent/pipeline.d.ts +10 -9
  9. package/dist/auth/AuthManager.d.ts +29 -0
  10. package/dist/auth/AuthenticatableModel.d.ts +15 -0
  11. package/dist/auth/RequestAuthContext.d.ts +10 -1
  12. package/dist/auth/SessionGuard.d.ts +2 -0
  13. package/dist/auth/api-token.d.ts +6 -0
  14. package/dist/auth/context.d.ts +32 -0
  15. package/dist/auth/index.d.ts +7 -0
  16. package/dist/auth/index.js +2 -2
  17. package/dist/auth/model-capability.d.ts +8 -0
  18. package/dist/auth/oauth/index.d.ts +5 -0
  19. package/dist/auth/password/DefaultHasher.d.ts +17 -6
  20. package/dist/auth/password/configured-hasher.d.ts +23 -0
  21. package/dist/auth/providers/ModelUserProvider.d.ts +3 -0
  22. package/dist/auth/providers/unconfigured-user-provider.d.ts +12 -0
  23. package/dist/auth/types.d.ts +9 -0
  24. package/dist/{auth-CjE2oO50.js → auth-D_W1cJp3.js} +279 -84
  25. package/dist/authorization/Gate.d.ts +12 -0
  26. package/dist/authorization/index.js +1 -1
  27. package/dist/{authorization-CdEWZZw3.js → authorization-0mCGUFoI.js} +58 -12
  28. package/dist/broadcasting/BroadcastManager.d.ts +10 -0
  29. package/dist/broadcasting/index.js +1 -1
  30. package/dist/{broadcasting-B5RzB0A2.js → broadcasting-BdJnaq1O.js} +17 -3
  31. package/dist/cache/index.js +1 -1
  32. package/dist/{cache-thXRnaju.js → cache-DikxP7Bk.js} +1 -1
  33. package/dist/container/Container.d.ts +18 -1
  34. package/dist/container/bindings.d.ts +9 -4
  35. package/dist/container/index.d.ts +4 -2
  36. package/dist/container/resolve-optional.d.ts +10 -0
  37. package/dist/context-af2n5abO.js +91 -0
  38. package/dist/{Job-CvDwk2Gj.js → default-application-Chbrul_m.js} +126 -82
  39. package/dist/encryption/Encrypter.d.ts +10 -0
  40. package/dist/encryption/index.js +1 -1
  41. package/dist/{encryption-uwP3Di4D.js → encryption-BRjZnshr.js} +23 -5
  42. package/dist/errors/ExceptionHandler.d.ts +10 -0
  43. package/dist/events/Event.d.ts +18 -0
  44. package/dist/events/EventManager.d.ts +56 -4
  45. package/dist/events/index.d.ts +2 -1
  46. package/dist/events/index.js +2 -2
  47. package/dist/events/queued.d.ts +8 -0
  48. package/dist/events/serialize.d.ts +8 -0
  49. package/dist/events/types.d.ts +19 -2
  50. package/dist/events-C86rS63h.js +428 -0
  51. package/dist/health/checks/CacheCheck.d.ts +3 -5
  52. package/dist/health/checks/StorageCheck.d.ts +3 -5
  53. package/dist/health/index.js +1 -1
  54. package/dist/{health-DQSvUplL.js → health-CB0oS_UE.js} +2 -2
  55. package/dist/http/Application.d.ts +28 -0
  56. package/dist/http/default-application.d.ts +33 -0
  57. package/dist/http/middleware/detect-locale.d.ts +2 -1
  58. package/dist/http/request-container.d.ts +25 -0
  59. package/dist/i18n/I18nManager.d.ts +16 -3
  60. package/dist/i18n/index.d.ts +1 -1
  61. package/dist/i18n/index.js +2 -2
  62. package/dist/{i18n-BZ2VrSud.js → i18n-DRo1g0AN.js} +34 -10
  63. package/dist/index.d.ts +16 -11
  64. package/dist/index.js +248 -129
  65. package/dist/lambda/index.js +1 -1
  66. package/dist/logging/LogManager.d.ts +9 -0
  67. package/dist/logging/index.js +2 -2
  68. package/dist/{logging-DXmqqUl4.js → logging-CXotojgW.js} +17 -4
  69. package/dist/mail/Mail.d.ts +14 -1
  70. package/dist/mail/MailManager.d.ts +10 -2
  71. package/dist/mail/index.js +1 -1
  72. package/dist/{mail-9CrvJyBZ.js → mail-CmxO2Ttx.js} +42 -11
  73. package/dist/mvc/Controller.d.ts +1 -1
  74. package/dist/mvc/Router.d.ts +16 -5
  75. package/dist/mvc/inertia/InertiaEngine.d.ts +24 -3
  76. package/dist/mvc/inertia/shared.d.ts +7 -0
  77. package/dist/notifications/NotificationManager.d.ts +15 -0
  78. package/dist/notifications/index.js +1 -1
  79. package/dist/{notifications-D0VXkFLF.js → notifications-CE3U7uyg.js} +24 -5
  80. package/dist/providers/AuthServiceProvider.d.ts +5 -4
  81. package/dist/providers/AuthorizationServiceProvider.d.ts +2 -2
  82. package/dist/providers/BroadcastServiceProvider.d.ts +4 -1
  83. package/dist/providers/EncryptionServiceProvider.d.ts +7 -1
  84. package/dist/providers/EventServiceProvider.d.ts +1 -0
  85. package/dist/providers/LogServiceProvider.d.ts +6 -1
  86. package/dist/providers/MailServiceProvider.d.ts +7 -1
  87. package/dist/providers/NotificationServiceProvider.d.ts +4 -1
  88. package/dist/queue/Job.d.ts +39 -0
  89. package/dist/queue/QueueManager.d.ts +14 -5
  90. package/dist/queue/Worker.d.ts +2 -1
  91. package/dist/queue/index.d.ts +1 -1
  92. package/dist/queue/index.js +3 -3
  93. package/dist/queue/types.d.ts +7 -0
  94. package/dist/{queue-zPPYZdif.js → queue-B3x_RKnB.js} +24 -10
  95. package/dist/redis/RedisSchedulerLock.d.ts +17 -0
  96. package/dist/redis/index.d.ts +2 -0
  97. package/dist/redis/index.js +21 -1
  98. package/dist/runtime/index.js +1 -1
  99. package/dist/scheduling/MemorySchedulerLock.d.ts +16 -0
  100. package/dist/scheduling/ScheduledTask.d.ts +19 -2
  101. package/dist/scheduling/Scheduler.d.ts +25 -0
  102. package/dist/scheduling/index.d.ts +2 -1
  103. package/dist/scheduling/index.js +2 -2
  104. package/dist/scheduling/types.d.ts +26 -2
  105. package/dist/{scheduling-C6tcOtUl.js → scheduling-DudNXGnh.js} +178 -20
  106. package/dist/storage/index.js +1 -1
  107. package/dist/{storage-D_yNe54O.js → storage-6HLaUf9j.js} +2 -13
  108. package/dist/support/deprecate.d.ts +16 -0
  109. package/dist/support/keep-alive.d.ts +26 -0
  110. package/dist/support/request-deferrer.d.ts +10 -0
  111. package/dist/{vite-manifest-CdfPfQdj.js → vite-manifest-B8720V7w.js} +1 -1
  112. package/dist/warn-once-p-IlMjra.js +13 -0
  113. package/package.json +3 -2
  114. package/dist/context-CXk_umpT.js +0 -21
  115. package/dist/events-DOmAHDeP.js +0 -230
@@ -1,2 +1,2 @@
1
- import { $ as buildTokenUrl, A as verifyOAuthState, B as getApiToken, C as createGoogleOAuthProviderConfig, D as fetchOAuthUserProfile, E as exchangeOAuthCode, F as TokenGuard, G as readBearerToken, H as getUserApiTokens, I as API_TOKEN_KEY, J as tokenCan, K as revokeAllApiTokens, L as MemoryApiTokenStore, O as parseOAuthRedirectUrl, P as AuthManager, Q as SessionGuard, R as createApiToken, S as createGitHubOAuthProviderConfig, T as createOAuthState, V as getApiTokenOrFail, W as parseApiToken, X as tokenCanAny, Y as tokenCanAll, Z as verifyApiToken, _ as OAUTH_SESSION_BINDING_KEY, a as isEmailVerified, at as secureStringCompare, b as buildOAuthRedirectUrl, c as verifyEmailToken, ct as NodeHasher, d as completePasswordReset, dt as BaseUserProvider, et as generateId, f as createPasswordResetToken, g as MemoryOAuthStateStore, h as AuthenticatableModel, i as createEmailVerificationToken, it as secureCompare, k as sanitizeOAuthRedirect, l as MemoryPasswordResetStore, lt as ScryptHasher, m as verifyPasswordResetToken, n as buildVerificationUrl, nt as hashToken, o as parseVerificationUrl, ot as ModelUserProvider, p as parsePasswordResetUrl, q as revokeApiToken, r as completeEmailVerification, rt as parseTokenUrl, s as requireVerifiedEmail, t as MemoryEmailVerificationStore, tt as generateToken, u as buildPasswordResetUrl, v as OAuthManager, w as createOAuthManager, x as createDiscordOAuthProviderConfig, y as buildOAuthAuthorizeUrl, z as createBearerTokenMiddleware } from "../auth-CjE2oO50.js";
2
- export { API_TOKEN_KEY, AuthManager, AuthenticatableModel, BaseUserProvider, MemoryApiTokenStore, MemoryEmailVerificationStore, MemoryOAuthStateStore, MemoryPasswordResetStore, ModelUserProvider, NodeHasher, OAUTH_SESSION_BINDING_KEY, OAuthManager, ScryptHasher, SessionGuard, TokenGuard, buildOAuthAuthorizeUrl, buildOAuthRedirectUrl, buildPasswordResetUrl, buildTokenUrl, buildVerificationUrl, completeEmailVerification, completePasswordReset, createApiToken, createBearerTokenMiddleware, createDiscordOAuthProviderConfig, createEmailVerificationToken, createGitHubOAuthProviderConfig, createGoogleOAuthProviderConfig, createOAuthManager, createOAuthState, createPasswordResetToken, exchangeOAuthCode, fetchOAuthUserProfile, generateId, generateToken, getApiToken, getApiTokenOrFail, getUserApiTokens, hashToken, isEmailVerified, parseApiToken, parseOAuthRedirectUrl, parsePasswordResetUrl, parseTokenUrl, parseVerificationUrl, readBearerToken, requireVerifiedEmail, revokeAllApiTokens, revokeApiToken, sanitizeOAuthRedirect, secureCompare, secureStringCompare, tokenCan, tokenCanAll, tokenCanAny, verifyApiToken, verifyEmailToken, verifyOAuthState, verifyPasswordResetToken };
1
+ import { $ as SessionGuard, A as verifyOAuthState, B as createBearerTokenMiddleware, C as createGoogleOAuthProviderConfig, D as fetchOAuthUserProfile, E as exchangeOAuthCode, G as parseApiToken, H as getApiTokenOrFail, I as TokenGuard, J as revokeApiToken, K as readBearerToken, L as API_TOKEN_KEY, O as parseOAuthRedirectUrl, P as AuthManager, Q as verifyApiToken, R as MemoryApiTokenStore, S as createGitHubOAuthProviderConfig, T as createOAuthState, U as getUserApiTokens, V as getApiToken, X as tokenCanAll, Y as tokenCan, Z as tokenCanAny, _ as OAUTH_SESSION_BINDING_KEY, a as isEmailVerified, at as secureCompare, b as buildOAuthRedirectUrl, c as verifyEmailToken, d as completePasswordReset, dt as BaseUserProvider, et as buildTokenUrl, f as createPasswordResetToken, g as MemoryOAuthStateStore, h as AuthenticatableModel, i as createEmailVerificationToken, it as parseTokenUrl, k as sanitizeOAuthRedirect, l as MemoryPasswordResetStore, lt as NodeHasher, m as verifyPasswordResetToken, n as buildVerificationUrl, nt as generateToken, o as parseVerificationUrl, ot as secureStringCompare, p as parsePasswordResetUrl, q as revokeAllApiTokens, r as completeEmailVerification, rt as hashToken, s as requireVerifiedEmail, st as ModelUserProvider, t as MemoryEmailVerificationStore, tt as generateId, u as buildPasswordResetUrl, ut as ScryptHasher, v as OAuthManager, w as createOAuthManager, x as createDiscordOAuthProviderConfig, y as buildOAuthAuthorizeUrl, z as createApiToken } from "../auth-D_W1cJp3.js";
2
+ export { API_TOKEN_KEY, ScryptHasher as Argon2Hasher, ScryptHasher, AuthManager, AuthenticatableModel, BaseUserProvider, MemoryApiTokenStore, MemoryEmailVerificationStore, MemoryOAuthStateStore, MemoryPasswordResetStore, ModelUserProvider, NodeHasher, OAUTH_SESSION_BINDING_KEY, OAuthManager, SessionGuard, TokenGuard, buildOAuthAuthorizeUrl, buildOAuthRedirectUrl, buildPasswordResetUrl, buildTokenUrl, buildVerificationUrl, completeEmailVerification, completePasswordReset, createApiToken, createBearerTokenMiddleware, createDiscordOAuthProviderConfig, createEmailVerificationToken, createGitHubOAuthProviderConfig, createGoogleOAuthProviderConfig, createOAuthManager, createOAuthState, createPasswordResetToken, exchangeOAuthCode, fetchOAuthUserProfile, generateId, generateToken, getApiToken, getApiTokenOrFail, getUserApiTokens, hashToken, isEmailVerified, parseApiToken, parseOAuthRedirectUrl, parsePasswordResetUrl, parseTokenUrl, parseVerificationUrl, readBearerToken, requireVerifiedEmail, revokeAllApiTokens, revokeApiToken, sanitizeOAuthRedirect, secureCompare, secureStringCompare, tokenCan, tokenCanAll, tokenCanAny, verifyApiToken, verifyEmailToken, verifyOAuthState, verifyPasswordResetToken };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The capability `T` a model class implements, or null. A capability check
3
+ * rather than `instanceof`: two copies of @guren/server coexist through
4
+ * workspace symlinks (src and dist), and a nominal test answers "no" for the
5
+ * copy it was not built from, silently ignoring a renamed credential column or
6
+ * a hasher the app bound.
7
+ */
8
+ export declare function capabilityOf<T>(model: unknown, ...methods: Array<keyof T & string>): T | null;
@@ -107,6 +107,11 @@ export declare const OAUTH_SESSION_BINDING_KEY = "guren:oauth.bindings";
107
107
  export interface OAuthAuthorizeOptions {
108
108
  scope?: string[];
109
109
  redirectTo?: string;
110
+ /**
111
+ * Use this value rather than a minted one. A bound flow returns it carrying
112
+ * the boundness marker, so send the `state` `authorize()` returns, not the
113
+ * one passed in.
114
+ */
110
115
  state?: string;
111
116
  extraParams?: Record<string, string>;
112
117
  /**
@@ -1,16 +1,27 @@
1
1
  import type { PasswordHasher } from './PasswordHasher.js';
2
2
  /**
3
- * Runtime-detecting password hasher behind `Hash`, the default for
4
- * `AuthenticatableModel` and `ModelUserProvider`: `Bun.password` on Bun (Argon2id,
5
- * despite `ScryptHasher`'s name), `crypto.scrypt` otherwise. **Verification routes
6
- * on the stored hash, not the runtime**, or a column written elsewhere would 500 on
7
- * every login; `$scrypt$` verifies anywhere, Argon2id/bcrypt needs `Bun.password`.
3
+ * The format new hashes are written in. `scrypt` is `node:crypto`'s and verifies
4
+ * on every runtime; `argon2` is `Bun.password`'s and needs Bun to read back.
5
+ */
6
+ export type PasswordHashAlgorithm = 'scrypt' | 'argon2';
7
+ export interface DefaultHasherOptions {
8
+ /** Defaults to `scrypt`. */
9
+ algorithm?: PasswordHashAlgorithm;
10
+ }
11
+ /**
12
+ * The hasher behind `Hash`, the default for `AuthenticatableModel` and
13
+ * `ModelUserProvider`. Writes the configured algorithm, scrypt unless told
14
+ * otherwise, so a row seeded under Bun still verifies on Node or Workers.
15
+ * Verification routes on the stored hash, not the writer: `$scrypt$` verifies
16
+ * anywhere, Argon2id/bcrypt needs `Bun.password`; the other format reports `needsRehash()`.
8
17
  */
9
18
  export declare class DefaultHasher implements PasswordHasher {
19
+ readonly algorithm: PasswordHashAlgorithm;
10
20
  private readonly bun;
11
21
  private readonly node;
22
+ private readonly writer;
12
23
  private readonly testing;
13
- constructor();
24
+ constructor(options?: DefaultHasherOptions);
14
25
  hash(plain: string): Promise<string>;
15
26
  verify(hashed: string, plain: string): Promise<boolean>;
16
27
  needsRehash(hashed: string): boolean;
@@ -0,0 +1,23 @@
1
+ import { type PasswordHashAlgorithm } from './DefaultHasher.js';
2
+ import type { PasswordHasher } from './PasswordHasher.js';
3
+ /**
4
+ * What `createApp({ auth: { hasher } })` accepts: an algorithm name for the
5
+ * built-in `DefaultHasher`, or a `PasswordHasher` of the app's own.
6
+ */
7
+ export type PasswordHasherOption = PasswordHashAlgorithm | PasswordHasher;
8
+ export declare function createPasswordHasher(option: PasswordHasherOption | undefined): PasswordHasher;
9
+ /**
10
+ * Hand the app's hasher to a model class at bind time, rather than letting the
11
+ * class read a process-wide container per hash. A model that declares `static
12
+ * passwordHasher` keeps the author's choice. The slot is a static, so a model
13
+ * class shared by two Applications carries the last binding.
14
+ */
15
+ export declare function bindPasswordHasher(model: unknown, hasher: PasswordHasher): void;
16
+ /**
17
+ * The one hasher precedence, read by the model class and by its provider: the
18
+ * author's `static passwordHasher`, then the caller's override, then what
19
+ * `useModel()` bound, then scrypt. A second spelling of this order is how a
20
+ * model and its provider come to write at different parameters, and every
21
+ * login then asks for a rehash the previous one already made.
22
+ */
23
+ export declare function resolveModelHasher(model: unknown, override?: PasswordHasher): PasswordHasher;
@@ -24,6 +24,9 @@ export declare class ModelUserProvider<User extends Authenticatable = Authentica
24
24
  retrieveByCredentials(credentials: AuthCredentials): Promise<User | null>;
25
25
  validateCredentials(user: User, credentials: AuthCredentials): Promise<boolean>;
26
26
  getId(user: User): unknown;
27
+ rehashPasswordIfRequired(user: User, credentials: AuthCredentials): Promise<void>;
28
+ /** forceUpdate keyed on the id column: both credential columns are denied to mass assignment. */
29
+ private writeColumn;
27
30
  /**
28
31
  * Strip the password hash, remember token, and the model's `hidden` fields
29
32
  * before the record leaves the auth layer. Credential validation runs on the
@@ -0,0 +1,12 @@
1
+ import type { UserProvider } from '../types.js';
2
+ /** The remediation both the thrown message and the boot warning end on. */
3
+ export declare const REGISTER_USER_PROVIDER_HINT: string;
4
+ export declare const NO_USER_PROVIDER_MESSAGE: string;
5
+ /**
6
+ * The provider behind the default guard until an app registers `users`. An
7
+ * anonymous request on an app with no auth is legitimately unauthenticated, so
8
+ * `retrieveById` answers null; a credential check with nothing to check
9
+ * against is a misconfiguration, so it throws rather than answering "wrong
10
+ * password" forever. One object: the guard is built per request.
11
+ */
12
+ export declare const unconfiguredUserProvider: UserProvider;
@@ -1,5 +1,6 @@
1
1
  import type { Context } from 'hono';
2
2
  import type { Session } from '../http/middleware/index.js';
3
+ import type { PasswordHasherOption } from './password/configured-hasher.js';
3
4
  export type AuthCredentials = Record<string, unknown>;
4
5
  export interface Authenticatable {
5
6
  getAuthIdentifier(): unknown;
@@ -30,6 +31,12 @@ export interface UserProvider<User = Authenticatable> {
30
31
  * remember tokens, model `hidden` fields) before caching or exposing a user.
31
32
  */
32
33
  sanitize?(user: User): User;
34
+ /**
35
+ * Called by a guard after `validateCredentials()` succeeded, never after it
36
+ * failed: re-hash the password in the current format and cost when the stored
37
+ * hash needs it, and persist the new value.
38
+ */
39
+ rehashPasswordIfRequired?(user: User, credentials: AuthCredentials): Promise<void> | void;
33
40
  }
34
41
  /** The conventional credential column names `ModelUserProvider.sanitize()` strips. */
35
42
  export type DefaultSanitizedKeys = 'password' | 'passwordHash' | 'password_hash' | 'rememberToken' | 'remember_token';
@@ -52,6 +59,8 @@ export interface ProviderFactory<User = Authenticatable> {
52
59
  }
53
60
  export interface AuthManagerOptions {
54
61
  defaultGuard?: string;
62
+ /** See `AuthPluginOptions.hasher`. Defaults to `'scrypt'`. */
63
+ hasher?: PasswordHasherOption;
55
64
  }
56
65
  export interface AttachContextOptions {
57
66
  guard?: string;