@stacksjs/auth 0.75.617 → 0.75.621

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.
@@ -1,6 +1,5 @@
1
1
  import { any, can, cannot } from './gate';
2
- import type { AuthorizationResponse } from './gate';
3
- import type { UserModel as OrmUserModel } from '@stacksjs/orm';
2
+ import type { AuthorizationResponse, GateUser } from './gate';
4
3
  /**
5
4
  * Check if a user can perform an ability
6
5
  *
@@ -67,10 +66,8 @@ export declare interface AuthorizableMethods {
67
66
  canAll(abilities: string[], ...args: any[]): Promise<boolean>
68
67
  authorize(ability: string, ...args: any[]): Promise<AuthorizationResponse>
69
68
  }
70
- // Alias the ORM-derived UserModel under the name the rest of this module
71
- // expects. Using the row/instance shape (rather than `typeof User`) lets
72
- // callers pass plain authenticated user objects to the gate helpers.
73
- declare type UserModel = OrmUserModel;
69
+ // The signed-in user, as `Gate` receives it.
70
+ declare type UserModel = GateUser;
74
71
  /**
75
72
  * Type for a user with authorization methods
76
73
  */
package/dist/gate.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { UserModel as OrmUserModel } from '@stacksjs/orm';
1
+ import type { AuthenticatedUser } from '@stacksjs/types';
2
+ import type { AuthUser } from './user';
2
3
  /**
3
4
  * Define the application's gates, policy mappings and before/after callbacks.
4
5
  *
@@ -263,10 +264,18 @@ export declare interface Policy<T = any> {
263
264
  forceDelete?(user: UserModel | null, model: T): boolean | Promise<boolean> | AuthorizationResponse
264
265
  [key: string]: PolicyMethod | undefined
265
266
  }
266
- // Alias the ORM-derived UserModel under the name this module uses internally.
267
- // The gate API receives authenticated user objects (rows / instances),
268
- // not the User class constructor.
269
- declare type UserModel = OrmUserModel;
267
+ /**
268
+ * The user a gate, a policy or an RBAC helper is handed (stacksjs/stacks#3314).
269
+ *
270
+ * The same object arrives under two types. The router's request carries the
271
+ * User row (`AuthUser`, what `User.find` returns), so `request.can()` and an
272
+ * action typed with the router's request pass that. An action typed with
273
+ * `RequestInstance` from `@stacksjs/types` gets `request.user()` as
274
+ * `AuthenticatedUser`, the app's User columns without the model's methods,
275
+ * since that package cannot depend on the ORM. Both have `id` and `email`.
276
+ */
277
+ export type GateUser = AuthUser | AuthenticatedUser;
278
+ declare type UserModel = GateUser;
270
279
  /**
271
280
  * Gate callback function type
272
281
  */
package/dist/policy.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AuthorizationResponse } from './gate';
2
- import type { UserModel as OrmUserModel } from '@stacksjs/orm';
2
+ import type { GateUser } from './gate';
3
3
  /** For tests, and for a dev server that regenerated the registry. */
4
4
  export declare function resetPolicyRegistry(): void;
5
5
  /**
@@ -29,9 +29,8 @@ export declare function registerGates(): Promise<void>;
29
29
  * error level, not swallowed at debug.
30
30
  */
31
31
  export declare function initializeAuthorization(): Promise<void>;
32
- // Use the row/instance shape from orm so policies operate on the
33
- // authenticated user object, not the User class constructor.
34
- declare type UserModel = OrmUserModel;
32
+ // The signed-in user, as `Gate` receives it.
33
+ declare type UserModel = GateUser;
35
34
  export declare abstract class BasePolicy<T = any> {
36
35
  before?(user: UserModel | null, ability: string): boolean | null | Promise<boolean | null>;
37
36
  viewAny?(user: UserModel | null): boolean | Promise<boolean> | AuthorizationResponse;
package/dist/rbac.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { UserModel as OrmUserModel } from '@stacksjs/orm';
1
+ import type { GateUser } from './gate';
2
2
  /**
3
3
  * Set the RBAC store implementation
4
4
  */
@@ -250,9 +250,8 @@ export declare interface RbacMethods {
250
250
  revokePermission(permissionName: string, guardName?: string): Promise<void>
251
251
  syncPermissions(permissionNames: string[], guardName?: string): Promise<void>
252
252
  }
253
- // Use the row/instance shape from orm so role helpers operate on the
254
- // authenticated user object, not the User class constructor.
255
- declare type UserModel = OrmUserModel;
253
+ // The signed-in user, as `Gate` receives it.
254
+ declare type UserModel = GateUser;
256
255
  export type RbacEntity = 'permission' | 'role';
257
256
  export declare class RbacEntityNotFoundError extends Error {
258
257
  public readonly entity: RbacEntity;
package/dist/user.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { UserModel as OrmUserModel } from '@stacksjs/orm';
1
+ import type { User } from '@stacksjs/orm';
2
2
  /**
3
3
  * Get the currently authenticated user
4
4
  *
@@ -14,7 +14,7 @@ import type { UserModel as OrmUserModel } from '@stacksjs/orm';
14
14
  * console.log('Logged in as:', user.email)
15
15
  * }
16
16
  */
17
- export declare function authUser(): Promise<UserModel | undefined>;
17
+ export declare function authUser(): Promise<AuthUser | undefined>;
18
18
  export declare function check(): Promise<boolean>;
19
19
  export declare function id(): Promise<number | undefined>;
20
20
  export declare function email(): Promise<string | undefined>;
@@ -22,9 +22,10 @@ export declare function name(): Promise<string | undefined>;
22
22
  export declare function isAuthenticated(): Promise<boolean>;
23
23
  export declare function logout(): Promise<void>;
24
24
  export declare function refresh(): Promise<void>;
25
- // Local aliases — keep the existing `UserModel` / `UserJsonResponse` symbols
26
- // in this module while sourcing the underlying type from the ORM.
27
- declare type UserModel = OrmUserModel;
28
- declare type UserJsonResponse = OrmUserModel;
29
- export type AuthUser = UserJsonResponse;
30
- export {};
25
+ /**
26
+ * The signed-in user: the row `User.find` returns, so an app's own User model
27
+ * and its columns come through. It is what `Auth.user()` resolves, what the
28
+ * Auth middleware stamps on `request._authenticatedUser`, and what `Gate`,
29
+ * policies and the RBAC helpers receive (stacksjs/stacks#3314).
30
+ */
31
+ export type AuthUser = NonNullable<Awaited<ReturnType<typeof User.find>>>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/auth",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.617",
5
+ "version": "0.75.621",
6
6
  "description": "A more simplistic way to authenticate.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -59,19 +59,19 @@
59
59
  },
60
60
  "dependencies": {
61
61
  "@stacksjs/bun-router": "^0.1.24",
62
- "@stacksjs/cache": "0.75.617",
63
- "@stacksjs/config": "0.75.617",
64
- "@stacksjs/database": "0.75.617",
65
- "@stacksjs/email": "0.75.617",
66
- "@stacksjs/env": "0.75.617",
67
- "@stacksjs/error-handling": "0.75.617",
68
- "@stacksjs/logging": "0.75.617",
69
- "@stacksjs/orm": "0.75.617",
70
- "@stacksjs/path": "0.75.617",
71
- "@stacksjs/router": "0.75.617",
72
- "@stacksjs/security": "0.75.617",
73
- "@stacksjs/socials": "0.75.617",
74
- "@stacksjs/storage": "0.75.617",
62
+ "@stacksjs/cache": "0.75.621",
63
+ "@stacksjs/config": "0.75.621",
64
+ "@stacksjs/database": "0.75.621",
65
+ "@stacksjs/email": "0.75.621",
66
+ "@stacksjs/env": "0.75.621",
67
+ "@stacksjs/error-handling": "0.75.621",
68
+ "@stacksjs/logging": "0.75.621",
69
+ "@stacksjs/orm": "0.75.621",
70
+ "@stacksjs/path": "0.75.621",
71
+ "@stacksjs/router": "0.75.621",
72
+ "@stacksjs/security": "0.75.621",
73
+ "@stacksjs/socials": "0.75.621",
74
+ "@stacksjs/storage": "0.75.621",
75
75
  "@stacksjs/ts-auth": "^0.4.7",
76
76
  "ts-qr-codes": "^0.1.8",
77
77
  "oauth4webapi": "^3.8.8",