@stratal/framework 0.0.18 → 0.0.19

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 (52) hide show
  1. package/dist/access-control/index.d.mts +180 -0
  2. package/dist/access-control/index.d.mts.map +1 -0
  3. package/dist/access-control/index.mjs +71 -0
  4. package/dist/access-control/index.mjs.map +1 -0
  5. package/dist/access.service-BjYVtUJw.mjs +145 -0
  6. package/dist/access.service-BjYVtUJw.mjs.map +1 -0
  7. package/dist/auth/index.d.mts +122 -4
  8. package/dist/auth/index.d.mts.map +1 -1
  9. package/dist/auth/index.mjs +237 -65
  10. package/dist/auth/index.mjs.map +1 -1
  11. package/dist/{auth-context-BD2ApWg1.d.mts → auth-context-BXSkiJ56.d.mts} +14 -1
  12. package/dist/auth-context-BXSkiJ56.d.mts.map +1 -0
  13. package/dist/{auth-context-BfekHvM9.mjs → auth-context-BberoPal.mjs} +25 -4
  14. package/dist/auth-context-BberoPal.mjs.map +1 -0
  15. package/dist/context/index.d.mts +1 -1
  16. package/dist/context/index.mjs +2 -2
  17. package/dist/database/index.d.mts +3 -3
  18. package/dist/database/index.mjs +49 -43
  19. package/dist/database/index.mjs.map +1 -1
  20. package/dist/{decorate-C12QolJF.mjs → decorate-CdfCRvAc.mjs} +1 -1
  21. package/dist/{decorateMetadata-rWbWGUuO.mjs → decorateMetadata-CqtSx3_1.mjs} +1 -1
  22. package/dist/decorateParam-Dc5DGEpb.mjs +18 -0
  23. package/dist/decorateParam-Dc5DGEpb.mjs.map +1 -0
  24. package/dist/{errors-C_KIIU1v.mjs → errors-B1vVXc1T.mjs} +1 -1
  25. package/dist/{errors-C_KIIU1v.mjs.map → errors-B1vVXc1T.mjs.map} +1 -1
  26. package/dist/factory/index.d.mts +1 -1
  27. package/dist/guards/index.d.mts +7 -6
  28. package/dist/guards/index.d.mts.map +1 -1
  29. package/dist/guards/index.mjs +38 -29
  30. package/dist/guards/index.mjs.map +1 -1
  31. package/dist/{index-B1iGBJcO.d.mts → index-CpFBG0Ws.d.mts} +23 -41
  32. package/dist/index-CpFBG0Ws.d.mts.map +1 -0
  33. package/dist/index.d.mts +2 -2
  34. package/dist/insufficient-permissions.error-CRnOHYvq.mjs +23 -0
  35. package/dist/insufficient-permissions.error-CRnOHYvq.mjs.map +1 -0
  36. package/dist/types-BLyu9dAd.d.mts +11 -0
  37. package/dist/types-BLyu9dAd.d.mts.map +1 -0
  38. package/dist/types-BZlcRR2M.d.mts +92 -0
  39. package/dist/types-BZlcRR2M.d.mts.map +1 -0
  40. package/package.json +22 -22
  41. package/dist/auth-context-BD2ApWg1.d.mts.map +0 -1
  42. package/dist/auth-context-BfekHvM9.mjs.map +0 -1
  43. package/dist/decorateParam-WGqsyT5s.mjs +0 -8
  44. package/dist/index-B1iGBJcO.d.mts.map +0 -1
  45. package/dist/rbac/index.d.mts +0 -206
  46. package/dist/rbac/index.d.mts.map +0 -1
  47. package/dist/rbac/index.mjs +0 -346
  48. package/dist/rbac/index.mjs.map +0 -1
  49. package/dist/tokens-Di1ofovy.mjs +0 -32
  50. package/dist/tokens-Di1ofovy.mjs.map +0 -1
  51. package/dist/types-Gjk0d2qB.d.mts +0 -47
  52. package/dist/types-Gjk0d2qB.d.mts.map +0 -1
@@ -0,0 +1,180 @@
1
+ import { n as RolePermissions, t as AccessControlOptions } from "../types-BLyu9dAd.mjs";
2
+ import { M as DatabaseService } from "../index-CpFBG0Ws.mjs";
3
+ import { t as AuthContext } from "../auth-context-BXSkiJ56.mjs";
4
+ import { ApplicationError } from "stratal/errors";
5
+ import { BetterAuthPlugin } from "better-auth";
6
+ import { AccessControl, Role, Statements } from "better-auth/plugins/access";
7
+
8
+ //#region src/access-control/tokens.d.ts
9
+ declare const AC_TOKENS: {
10
+ /** Request-scoped access service */readonly AccessService: symbol; /** Access control module options (ac, roles) */
11
+ readonly Options: symbol;
12
+ };
13
+ //#endregion
14
+ //#region src/access-control/create-access-control.d.ts
15
+ /**
16
+ * Define access control resources and roles in one place.
17
+ *
18
+ * Returns `{ ac, roles }` — spread this directly into `accessControl`,
19
+ * `admin({ ...permissions })`, or `organization({ ...permissions })`.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * export const permissions = createAccessControl({
24
+ * resources: {
25
+ * posts: ['create', 'read', 'update', 'delete'],
26
+ * admin: ['access'],
27
+ * } as const,
28
+ * roles: {
29
+ * admin: { posts: ['create', 'read', 'update', 'delete'], admin: ['access'] },
30
+ * user: { posts: ['create', 'read'] },
31
+ * },
32
+ * })
33
+ *
34
+ * // In AuthModule:
35
+ * accessControl: permissions
36
+ *
37
+ * // With Better Auth admin plugin (same object):
38
+ * plugins: [admin({ ...permissions })]
39
+ * ```
40
+ */
41
+ declare function createAccessControl<TResources extends Statements, TRoles extends Record<string, RolePermissions<TResources>>>(config: {
42
+ resources: TResources;
43
+ roles: TRoles;
44
+ }): AccessControlOptions<TResources, TRoles>;
45
+ //#endregion
46
+ //#region src/access-control/extend-role.d.ts
47
+ /**
48
+ * Merges two Statements types, unioning the action arrays for overlapping resource keys.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * type A = { posts: readonly ['create', 'read'] }
53
+ * type B = { posts: readonly ['update']; admin: readonly ['access'] }
54
+ * type M = MergeStatements<A, B>
55
+ * // → { posts: readonly ('create' | 'read' | 'update')[]; admin: readonly ['access'] }
56
+ * ```
57
+ */
58
+ type MergeStatements<A extends Statements, B extends Partial<Record<string, readonly string[]>>> = { [K in keyof A | keyof B]: K extends keyof A ? K extends keyof B ? readonly (A[K][number] | NonNullable<B[K]>[number])[] : A[K] : K extends keyof B ? NonNullable<B[K]> : never } & {};
59
+ /**
60
+ * Extend an existing role with additional permissions.
61
+ *
62
+ * Duplicate resource keys are merged (actions are unioned), not overwritten.
63
+ * Better Auth has no built-in role inheritance — use this to compose roles.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const adminRole = ac.newRole({ posts: ['create', 'read', 'update', 'delete'] })
68
+ * const superAdminRole = extendRole(ac, adminRole, { users: ['ban', 'delete'] })
69
+ * // superAdminRole has both posts and users permissions
70
+ *
71
+ * // Duplicate keys are merged, not overwritten:
72
+ * const editorRole = extendRole(ac, userRole, { posts: ['update'] })
73
+ * // if userRole had posts: ['create', 'read'], editorRole has posts: ['create', 'read', 'update']
74
+ * ```
75
+ */
76
+ declare function extendRole<TParent extends Statements, TExtra extends Partial<Record<string, readonly string[]>>>(ac: AccessControl<TParent>, parent: Role<TParent>, extra: TExtra): Role<MergeStatements<TParent, TExtra>>;
77
+ //#endregion
78
+ //#region src/access-control/plugin.d.ts
79
+ /**
80
+ * Creates the Stratal access control Better Auth plugin.
81
+ *
82
+ * Ensures the `user.role` schema field exists.
83
+ * No endpoints are added — all permission logic lives in AccessService.
84
+ *
85
+ * Auto-added to Better Auth options when `accessControl` is provided to
86
+ * `AuthModule.forRootAsync()`. Users never call this directly.
87
+ */
88
+ declare function createStratalAcPlugin(_options: AccessControlOptions): BetterAuthPlugin;
89
+ //#endregion
90
+ //#region src/access-control/services/access.service.d.ts
91
+ /**
92
+ * AccessService
93
+ *
94
+ * Request-scoped service for role and permission management.
95
+ *
96
+ * Roles for the current user are read from AuthContext (populated by
97
+ * SessionVerificationMiddleware — no DB hit). Other users are resolved
98
+ * from the database.
99
+ *
100
+ * Permission checks use Better Auth's `role.authorize()` locally with
101
+ * OR logic — access is granted if any of the user's roles allows it.
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // Check current user
106
+ * await accessService.currentUserHasPermission({ posts: ['update'] })
107
+ *
108
+ * // Check arbitrary user (e.g. from an admin action)
109
+ * await accessService.hasPermission(userId, { admin: ['access'] })
110
+ *
111
+ * // Assign a role
112
+ * await accessService.setUserRole(userId, 'admin')
113
+ *
114
+ * // Assign multiple roles
115
+ * await accessService.setUserRole(userId, ['editor', 'reviewer'])
116
+ * ```
117
+ */
118
+ declare class AccessService {
119
+ private readonly authContext;
120
+ private readonly db;
121
+ private readonly options;
122
+ constructor(authContext: AuthContext, db: DatabaseService, options: AccessControlOptions);
123
+ /**
124
+ * Get all roles for a user.
125
+ *
126
+ * Uses AuthContext for the current user (no DB hit).
127
+ * Falls back to DB for other users.
128
+ */
129
+ getUserRoles(userId: string): Promise<string[]>;
130
+ /**
131
+ * Assign one or more roles to a user.
132
+ *
133
+ * Multiple roles are stored as a comma-separated string in `user.role`.
134
+ */
135
+ setUserRole(userId: string, role: string | string[]): Promise<void>;
136
+ /**
137
+ * Check if a user has the required permissions.
138
+ *
139
+ * Returns true if any of the user's roles grants all of the requested permissions.
140
+ */
141
+ hasPermission(userId: string, permissions: Record<string, string[]>): Promise<boolean>;
142
+ /**
143
+ * Get the merged permission set for a user across all their roles.
144
+ * Useful for sending to the frontend.
145
+ */
146
+ getPermissionsForUser(userId: string): Promise<Record<string, string[]>>;
147
+ /**
148
+ * Get all roles for the currently authenticated user.
149
+ * Reads from AuthContext — no DB hit.
150
+ */
151
+ getCurrentUserRoles(): string[];
152
+ /**
153
+ * Check if the currently authenticated user has the required permissions.
154
+ * Reads roles from AuthContext — no DB hit.
155
+ */
156
+ currentUserHasPermission(permissions: Record<string, string[]>): boolean;
157
+ /**
158
+ * Get merged permissions for the currently authenticated user.
159
+ * Reads roles from AuthContext — no DB hit.
160
+ */
161
+ getCurrentUserPermissions(): Record<string, string[]>;
162
+ private checkPermissions;
163
+ private mergePermissions;
164
+ }
165
+ //#endregion
166
+ //#region src/access-control/errors/insufficient-permissions.error.d.ts
167
+ /**
168
+ * InsufficientPermissionsError
169
+ *
170
+ * Thrown when a user attempts to perform an action without the required permissions.
171
+ * Used by AuthGuard after an authorization check fails.
172
+ *
173
+ * HTTP Status: 403 Forbidden
174
+ */
175
+ declare class InsufficientPermissionsError extends ApplicationError {
176
+ constructor(requiredPermissions: string | string[], userId?: string);
177
+ }
178
+ //#endregion
179
+ export { AC_TOKENS, type AccessControlOptions, AccessService, InsufficientPermissionsError, createAccessControl, createStratalAcPlugin, extendRole };
180
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/access-control/tokens.ts","../../src/access-control/create-access-control.ts","../../src/access-control/extend-role.ts","../../src/access-control/plugin.ts","../../src/access-control/services/access.service.ts","../../src/access-control/errors/insufficient-permissions.error.ts"],"mappings":";;;;;;;;cAAa,SAAA;+CAKH,aAAA;WAAA,OAAA;AAAA;;;;;;;;;AALV;;;;;;;;AC8BA;;;;;;;;;;;;iBAAgB,mBAAA,oBACK,UAAA,iBACJ,MAAA,SAAe,eAAA,CAAgB,UAAA,GAAA,CAC9C,MAAA;EACA,SAAA,EAAW,UAAA;EACX,KAAA,EAAO,MAAA;AAAA,IACL,oBAAA,CAAqB,UAAA,EAAY,MAAA;;;;;;;;;;ADpCrC;;;;KEaK,eAAA,WACO,UAAA,YACA,OAAA,CAAQ,MAAA,8CAEN,CAAA,SAAU,CAAA,GAAI,CAAA,eAAgB,CAAA,GACxC,CAAA,eAAgB,CAAA,aACN,CAAA,CAAE,CAAA,YAAa,WAAA,CAAY,CAAA,CAAE,CAAA,gBACvC,CAAA,CAAE,CAAA,IACF,CAAA,eAAgB,CAAA,GAChB,WAAA,CAAY,CAAA,CAAE,CAAA;;ADQlB;;;;;;;;;;;;;;;;iBCagB,UAAA,iBACE,UAAA,iBACD,OAAA,CAAQ,MAAA,6BAAA,CAEvB,EAAA,EAAI,aAAA,CAAc,OAAA,GAClB,MAAA,EAAQ,IAAA,CAAK,OAAA,GACb,KAAA,EAAO,MAAA,GACN,IAAA,CAAK,eAAA,CAAgB,OAAA,EAAS,MAAA;;;;;;;;;AFlDjC;;;iBGYgB,qBAAA,CAAsB,QAAA,EAAU,oBAAA,GAAuB,gBAAA;;;;;;;;AHZvE;;;;;;;;AC8BA;;;;;;;;;;;;;;cGSa,aAAA;EAAA,iBAGQ,WAAA;EAAA,iBAEA,EAAA;EAAA,iBAEA,OAAA;cAJA,WAAA,EAAa,WAAA,EAEb,EAAA,EAAI,eAAA,EAEJ,OAAA,EAAS,oBAAA;EHdkB;;;;;;EGuBxC,YAAA,CAAa,MAAA,WAAiB,OAAA;EHnBb;;;;;EGoCjB,WAAA,CAAY,MAAA,UAAgB,IAAA,sBAA0B,OAAA;;AFxEmB;;;;EEqFzE,aAAA,CAAc,MAAA,UAAgB,WAAA,EAAa,MAAA,qBAA2B,OAAA;EFtElE;;;;EE+EJ,qBAAA,CAAsB,MAAA,WAAiB,OAAA,CAAQ,MAAA;EF5EnD;;;;EEqFF,mBAAA,CAAA;EFpFyC;;;;EE4FzC,wBAAA,CAAyB,WAAA,EAAa,MAAA;EF1FpB;;;;EEoGlB,yBAAA,CAAA,GAA6B,MAAA;EAAA,QAKrB,gBAAA;EAAA,QAqBA,gBAAA;AAAA;;;;;;;;;;AJnJV;cKUa,4BAAA,SAAqC,gBAAA;cACpC,mBAAA,qBAAwC,MAAA;AAAA"}
@@ -0,0 +1,71 @@
1
+ import { n as createStratalAcPlugin, t as AccessService } from "../access.service-BjYVtUJw.mjs";
2
+ import { n as AC_TOKENS } from "../decorateParam-Dc5DGEpb.mjs";
3
+ import { t as InsufficientPermissionsError } from "../insufficient-permissions.error-CRnOHYvq.mjs";
4
+ import { createAccessControl as createAccessControl$1 } from "better-auth/plugins/access";
5
+ //#region src/access-control/create-access-control.ts
6
+ /**
7
+ * Define access control resources and roles in one place.
8
+ *
9
+ * Returns `{ ac, roles }` — spread this directly into `accessControl`,
10
+ * `admin({ ...permissions })`, or `organization({ ...permissions })`.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * export const permissions = createAccessControl({
15
+ * resources: {
16
+ * posts: ['create', 'read', 'update', 'delete'],
17
+ * admin: ['access'],
18
+ * } as const,
19
+ * roles: {
20
+ * admin: { posts: ['create', 'read', 'update', 'delete'], admin: ['access'] },
21
+ * user: { posts: ['create', 'read'] },
22
+ * },
23
+ * })
24
+ *
25
+ * // In AuthModule:
26
+ * accessControl: permissions
27
+ *
28
+ * // With Better Auth admin plugin (same object):
29
+ * plugins: [admin({ ...permissions })]
30
+ * ```
31
+ */
32
+ function createAccessControl(config) {
33
+ const ac = createAccessControl$1(config.resources);
34
+ return {
35
+ ac,
36
+ roles: Object.fromEntries(Object.entries(config.roles).map(([name, perms]) => [name, ac.newRole(perms)]))
37
+ };
38
+ }
39
+ //#endregion
40
+ //#region src/access-control/extend-role.ts
41
+ /**
42
+ * Extend an existing role with additional permissions.
43
+ *
44
+ * Duplicate resource keys are merged (actions are unioned), not overwritten.
45
+ * Better Auth has no built-in role inheritance — use this to compose roles.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const adminRole = ac.newRole({ posts: ['create', 'read', 'update', 'delete'] })
50
+ * const superAdminRole = extendRole(ac, adminRole, { users: ['ban', 'delete'] })
51
+ * // superAdminRole has both posts and users permissions
52
+ *
53
+ * // Duplicate keys are merged, not overwritten:
54
+ * const editorRole = extendRole(ac, userRole, { posts: ['update'] })
55
+ * // if userRole had posts: ['create', 'read'], editorRole has posts: ['create', 'read', 'update']
56
+ * ```
57
+ */
58
+ function extendRole(ac, parent, extra) {
59
+ const merged = {};
60
+ for (const [key, actions] of Object.entries(parent.statements)) merged[key] = [...actions];
61
+ for (const [key, actions] of Object.entries(extra)) {
62
+ if (!actions) continue;
63
+ if (key in merged) merged[key] = [...new Set([...merged[key], ...actions])];
64
+ else merged[key] = [...actions];
65
+ }
66
+ return ac.newRole(merged);
67
+ }
68
+ //#endregion
69
+ export { AC_TOKENS, AccessService, InsufficientPermissionsError, createAccessControl, createStratalAcPlugin, extendRole };
70
+
71
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["baCreateAC"],"sources":["../../src/access-control/create-access-control.ts","../../src/access-control/extend-role.ts"],"sourcesContent":["import type { Role, Statements } from 'better-auth/plugins/access'\nimport { createAccessControl as baCreateAC } from 'better-auth/plugins/access'\nimport type { AccessControlOptions, RolePermissions } from './types'\n\n/**\n * Define access control resources and roles in one place.\n *\n * Returns `{ ac, roles }` — spread this directly into `accessControl`,\n * `admin({ ...permissions })`, or `organization({ ...permissions })`.\n *\n * @example\n * ```typescript\n * export const permissions = createAccessControl({\n * resources: {\n * posts: ['create', 'read', 'update', 'delete'],\n * admin: ['access'],\n * } as const,\n * roles: {\n * admin: { posts: ['create', 'read', 'update', 'delete'], admin: ['access'] },\n * user: { posts: ['create', 'read'] },\n * },\n * })\n *\n * // In AuthModule:\n * accessControl: permissions\n *\n * // With Better Auth admin plugin (same object):\n * plugins: [admin({ ...permissions })]\n * ```\n */\nexport function createAccessControl<\n TResources extends Statements,\n TRoles extends Record<string, RolePermissions<TResources>>,\n>(config: {\n resources: TResources\n roles: TRoles\n}): AccessControlOptions<TResources, TRoles> {\n const ac = baCreateAC(config.resources)\n const roles = Object.fromEntries(\n Object.entries(config.roles).map(([name, perms]) => [name, ac.newRole(perms as unknown as Statements)])\n ) as { [K in keyof TRoles]: Role<TResources> }\n return { ac, roles }\n}\n","import type { AccessControl, Role, Statements } from 'better-auth/plugins/access'\n\n/**\n * Merges two Statements types, unioning the action arrays for overlapping resource keys.\n *\n * @example\n * ```typescript\n * type A = { posts: readonly ['create', 'read'] }\n * type B = { posts: readonly ['update']; admin: readonly ['access'] }\n * type M = MergeStatements<A, B>\n * // → { posts: readonly ('create' | 'read' | 'update')[]; admin: readonly ['access'] }\n * ```\n */\ntype MergeStatements<\n A extends Statements,\n B extends Partial<Record<string, readonly string[]>>\n> = {\n [K in keyof A | keyof B]: K extends keyof A\n ? K extends keyof B\n ? readonly (A[K][number] | NonNullable<B[K]>[number])[]\n : A[K]\n : K extends keyof B\n ? NonNullable<B[K]>\n : never\n} & {}\n\n/**\n * Extend an existing role with additional permissions.\n *\n * Duplicate resource keys are merged (actions are unioned), not overwritten.\n * Better Auth has no built-in role inheritance — use this to compose roles.\n *\n * @example\n * ```typescript\n * const adminRole = ac.newRole({ posts: ['create', 'read', 'update', 'delete'] })\n * const superAdminRole = extendRole(ac, adminRole, { users: ['ban', 'delete'] })\n * // superAdminRole has both posts and users permissions\n *\n * // Duplicate keys are merged, not overwritten:\n * const editorRole = extendRole(ac, userRole, { posts: ['update'] })\n * // if userRole had posts: ['create', 'read'], editorRole has posts: ['create', 'read', 'update']\n * ```\n */\nexport function extendRole<\n TParent extends Statements,\n TExtra extends Partial<Record<string, readonly string[]>>\n>(\n ac: AccessControl<TParent>,\n parent: Role<TParent>,\n extra: TExtra\n): Role<MergeStatements<TParent, TExtra>> {\n const merged: Record<string, string[]> = {}\n\n for (const [key, actions] of Object.entries(parent.statements)) {\n merged[key] = [...(actions as string[])]\n }\n\n for (const [key, actions] of Object.entries(extra)) {\n if (!actions) continue\n if (key in merged) {\n merged[key] = [...new Set([...merged[key], ...actions])]\n } else {\n merged[key] = [...actions]\n }\n }\n\n return ac.newRole(merged) as Role<MergeStatements<TParent, TExtra>>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,oBAGd,QAG2C;CAC3C,MAAM,KAAKA,sBAAW,OAAO,UAAU;AAIvC,QAAO;EAAE;EAAI,OAHC,OAAO,YACnB,OAAO,QAAQ,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,GAAG,QAAQ,MAA+B,CAAC,CAAC,CAEvF;EAAE;;;;;;;;;;;;;;;;;;;;;ACEtB,SAAgB,WAId,IACA,QACA,OACwC;CACxC,MAAM,SAAmC,EAAE;AAE3C,MAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,OAAO,WAAW,CAC5D,QAAO,OAAO,CAAC,GAAI,QAAqB;AAG1C,MAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,MAAM,EAAE;AAClD,MAAI,CAAC,QAAS;AACd,MAAI,OAAO,OACT,QAAO,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,OAAO,MAAM,GAAG,QAAQ,CAAC,CAAC;MAExD,QAAO,OAAO,CAAC,GAAG,QAAQ;;AAI9B,QAAO,GAAG,QAAQ,OAAO"}
@@ -0,0 +1,145 @@
1
+ import { n as AC_TOKENS, t as __decorateParam } from "./decorateParam-Dc5DGEpb.mjs";
2
+ import { t as __decorateMetadata } from "./decorateMetadata-CqtSx3_1.mjs";
3
+ import { t as __decorate } from "./decorate-CdfCRvAc.mjs";
4
+ import { DI_TOKENS, Transient, inject } from "stratal/di";
5
+ //#region src/access-control/plugin.ts
6
+ /**
7
+ * Creates the Stratal access control Better Auth plugin.
8
+ *
9
+ * Ensures the `user.role` schema field exists.
10
+ * No endpoints are added — all permission logic lives in AccessService.
11
+ *
12
+ * Auto-added to Better Auth options when `accessControl` is provided to
13
+ * `AuthModule.forRootAsync()`. Users never call this directly.
14
+ */
15
+ function createStratalAcPlugin(_options) {
16
+ return {
17
+ id: "stratal-ac",
18
+ schema: { user: { fields: { role: {
19
+ type: "string",
20
+ required: false,
21
+ input: false,
22
+ defaultValue: "user"
23
+ } } } }
24
+ };
25
+ }
26
+ //#endregion
27
+ //#region src/access-control/services/access.service.ts
28
+ function parseRoles(role) {
29
+ if (!role) return [];
30
+ return role.split(",").map((r) => r.trim()).filter(Boolean);
31
+ }
32
+ let AccessService = class AccessService {
33
+ constructor(authContext, db, options) {
34
+ this.authContext = authContext;
35
+ this.db = db;
36
+ this.options = options;
37
+ }
38
+ /**
39
+ * Get all roles for a user.
40
+ *
41
+ * Uses AuthContext for the current user (no DB hit).
42
+ * Falls back to DB for other users.
43
+ */
44
+ async getUserRoles(userId) {
45
+ if (userId === this.authContext.getUserId()) {
46
+ const roles = this.authContext.getRoles();
47
+ if (roles.length > 0) return roles;
48
+ }
49
+ return parseRoles((await this.db.user.findUnique({
50
+ where: { id: userId },
51
+ select: { role: true }
52
+ }))?.role);
53
+ }
54
+ /**
55
+ * Assign one or more roles to a user.
56
+ *
57
+ * Multiple roles are stored as a comma-separated string in `user.role`.
58
+ */
59
+ async setUserRole(userId, role) {
60
+ const roleStr = Array.isArray(role) ? role.join(",") : role;
61
+ await this.db.user.update({
62
+ where: { id: userId },
63
+ data: { role: roleStr }
64
+ });
65
+ }
66
+ /**
67
+ * Check if a user has the required permissions.
68
+ *
69
+ * Returns true if any of the user's roles grants all of the requested permissions.
70
+ */
71
+ async hasPermission(userId, permissions) {
72
+ const roles = await this.getUserRoles(userId);
73
+ return this.checkPermissions(roles, permissions);
74
+ }
75
+ /**
76
+ * Get the merged permission set for a user across all their roles.
77
+ * Useful for sending to the frontend.
78
+ */
79
+ async getPermissionsForUser(userId) {
80
+ const roles = await this.getUserRoles(userId);
81
+ return this.mergePermissions(roles);
82
+ }
83
+ /**
84
+ * Get all roles for the currently authenticated user.
85
+ * Reads from AuthContext — no DB hit.
86
+ */
87
+ getCurrentUserRoles() {
88
+ return this.authContext.getRoles();
89
+ }
90
+ /**
91
+ * Check if the currently authenticated user has the required permissions.
92
+ * Reads roles from AuthContext — no DB hit.
93
+ */
94
+ currentUserHasPermission(permissions) {
95
+ const roles = this.authContext.getRoles();
96
+ if (roles.length === 0) return false;
97
+ return this.checkPermissions(roles, permissions);
98
+ }
99
+ /**
100
+ * Get merged permissions for the currently authenticated user.
101
+ * Reads roles from AuthContext — no DB hit.
102
+ */
103
+ getCurrentUserPermissions() {
104
+ const roles = this.authContext.getRoles();
105
+ return this.mergePermissions(roles);
106
+ }
107
+ checkPermissions(roles, permissions) {
108
+ return roles.some((roleName) => {
109
+ const roleObj = this.options.roles[roleName];
110
+ if (!roleObj) return false;
111
+ const specific = {};
112
+ for (const [resource, actions] of Object.entries(permissions)) if (actions.includes("*")) {
113
+ if (!roleObj.statements[resource]?.length) return false;
114
+ } else specific[resource] = actions;
115
+ return Object.keys(specific).length === 0 || roleObj.authorize(specific).success;
116
+ });
117
+ }
118
+ mergePermissions(roles) {
119
+ const result = {};
120
+ for (const roleName of roles) {
121
+ const roleObj = this.options.roles[roleName];
122
+ if (!roleObj) continue;
123
+ for (const [resource, actions] of Object.entries(roleObj.statements)) {
124
+ result[resource] ??= [];
125
+ for (const action of actions) if (!result[resource].includes(action)) result[resource].push(action);
126
+ }
127
+ }
128
+ return result;
129
+ }
130
+ };
131
+ AccessService = __decorate([
132
+ Transient(AC_TOKENS.AccessService),
133
+ __decorateParam(0, inject(DI_TOKENS.AuthContext)),
134
+ __decorateParam(1, inject(DI_TOKENS.Database)),
135
+ __decorateParam(2, inject(AC_TOKENS.Options)),
136
+ __decorateMetadata("design:paramtypes", [
137
+ Object,
138
+ Object,
139
+ Object
140
+ ])
141
+ ], AccessService);
142
+ //#endregion
143
+ export { createStratalAcPlugin as n, AccessService as t };
144
+
145
+ //# sourceMappingURL=access.service-BjYVtUJw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.service-BjYVtUJw.mjs","names":[],"sources":["../src/access-control/plugin.ts","../src/access-control/services/access.service.ts"],"sourcesContent":["import type { BetterAuthPlugin } from 'better-auth'\nimport type { AccessControlOptions } from './types'\n\n/**\n * Creates the Stratal access control Better Auth plugin.\n *\n * Ensures the `user.role` schema field exists.\n * No endpoints are added — all permission logic lives in AccessService.\n *\n * Auto-added to Better Auth options when `accessControl` is provided to\n * `AuthModule.forRootAsync()`. Users never call this directly.\n */\nexport function createStratalAcPlugin(_options: AccessControlOptions): BetterAuthPlugin {\n return {\n id: 'stratal-ac',\n schema: {\n user: {\n fields: {\n role: {\n type: 'string',\n required: false,\n input: false,\n defaultValue: 'user',\n },\n },\n },\n },\n }\n}\n","import type { DatabaseService } from '@stratal/framework/database'\nimport { DI_TOKENS, inject, Transient } from 'stratal/di'\nimport type { AuthContext } from '../../context/auth-context'\nimport { AC_TOKENS } from '../tokens'\nimport type { AccessControlOptions } from '../types'\n\nfunction parseRoles(role: string | null | undefined): string[] {\n if (!role) return []\n return role.split(',').map(r => r.trim()).filter(Boolean)\n}\n\n/**\n * AccessService\n *\n * Request-scoped service for role and permission management.\n *\n * Roles for the current user are read from AuthContext (populated by\n * SessionVerificationMiddleware — no DB hit). Other users are resolved\n * from the database.\n *\n * Permission checks use Better Auth's `role.authorize()` locally with\n * OR logic — access is granted if any of the user's roles allows it.\n *\n * @example\n * ```typescript\n * // Check current user\n * await accessService.currentUserHasPermission({ posts: ['update'] })\n *\n * // Check arbitrary user (e.g. from an admin action)\n * await accessService.hasPermission(userId, { admin: ['access'] })\n *\n * // Assign a role\n * await accessService.setUserRole(userId, 'admin')\n *\n * // Assign multiple roles\n * await accessService.setUserRole(userId, ['editor', 'reviewer'])\n * ```\n */\n@Transient(AC_TOKENS.AccessService)\nexport class AccessService {\n constructor(\n @inject(DI_TOKENS.AuthContext)\n private readonly authContext: AuthContext,\n @inject(DI_TOKENS.Database)\n private readonly db: DatabaseService,\n @inject(AC_TOKENS.Options)\n private readonly options: AccessControlOptions\n ) { }\n\n /**\n * Get all roles for a user.\n *\n * Uses AuthContext for the current user (no DB hit).\n * Falls back to DB for other users.\n */\n async getUserRoles(userId: string): Promise<string[]> {\n if (userId === this.authContext.getUserId()) {\n const roles = this.authContext.getRoles()\n if (roles.length > 0) return roles\n }\n const user = await (this.db).user.findUnique({\n where: { id: userId },\n select: { role: true },\n })\n return parseRoles(user?.role)\n }\n\n /**\n * Assign one or more roles to a user.\n *\n * Multiple roles are stored as a comma-separated string in `user.role`.\n */\n async setUserRole(userId: string, role: string | string[]): Promise<void> {\n const roleStr = Array.isArray(role) ? role.join(',') : role\n await this.db.user.update({\n where: { id: userId },\n data: { role: roleStr },\n })\n }\n\n /**\n * Check if a user has the required permissions.\n *\n * Returns true if any of the user's roles grants all of the requested permissions.\n */\n async hasPermission(userId: string, permissions: Record<string, string[]>): Promise<boolean> {\n const roles = await this.getUserRoles(userId)\n return this.checkPermissions(roles, permissions)\n }\n\n /**\n * Get the merged permission set for a user across all their roles.\n * Useful for sending to the frontend.\n */\n async getPermissionsForUser(userId: string): Promise<Record<string, string[]>> {\n const roles = await this.getUserRoles(userId)\n return this.mergePermissions(roles)\n }\n\n /**\n * Get all roles for the currently authenticated user.\n * Reads from AuthContext — no DB hit.\n */\n getCurrentUserRoles(): string[] {\n return this.authContext.getRoles()\n }\n\n /**\n * Check if the currently authenticated user has the required permissions.\n * Reads roles from AuthContext — no DB hit.\n */\n currentUserHasPermission(permissions: Record<string, string[]>): boolean {\n const roles = this.authContext.getRoles()\n if (roles.length === 0) return false\n return this.checkPermissions(roles, permissions)\n }\n\n /**\n * Get merged permissions for the currently authenticated user.\n * Reads roles from AuthContext — no DB hit.\n */\n getCurrentUserPermissions(): Record<string, string[]> {\n const roles = this.authContext.getRoles()\n return this.mergePermissions(roles)\n }\n\n private checkPermissions(roles: string[], permissions: Record<string, string[]>): boolean {\n return roles.some(roleName => {\n const roleObj = this.options.roles[roleName]\n if (!roleObj) return false\n\n const specific: Record<string, string[]> = {}\n\n for (const [resource, actions] of Object.entries(permissions)) {\n if (actions.includes('*')) {\n // Wildcard: role must have at least one action defined for this resource\n const roleActions = (roleObj.statements as Record<string, readonly string[]>)[resource]\n if (!roleActions?.length) return false\n } else {\n specific[resource] = actions\n }\n }\n\n return Object.keys(specific).length === 0 || roleObj.authorize(specific).success\n })\n }\n\n private mergePermissions(roles: string[]): Record<string, string[]> {\n const result: Record<string, string[]> = {}\n for (const roleName of roles) {\n const roleObj = this.options.roles[roleName]\n if (!roleObj) continue\n for (const [resource, actions] of Object.entries(roleObj.statements)) {\n result[resource] ??= []\n for (const action of actions as string[]) {\n if (!result[resource].includes(action)) {\n result[resource].push(action)\n }\n }\n }\n }\n return result\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAYA,SAAgB,sBAAsB,UAAkD;AACtF,QAAO;EACL,IAAI;EACJ,QAAQ,EACN,MAAM,EACJ,QAAQ,EACN,MAAM;GACJ,MAAM;GACN,UAAU;GACV,OAAO;GACP,cAAc;GACf,EACF,EACF,EACF;EACF;;;;ACrBH,SAAS,WAAW,MAA2C;AAC7D,KAAI,CAAC,KAAM,QAAO,EAAE;AACpB,QAAO,KAAK,MAAM,IAAI,CAAC,KAAI,MAAK,EAAE,MAAM,CAAC,CAAC,OAAO,QAAQ;;AA+BpD,IAAA,gBAAA,MAAM,cAAc;CAC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AAS,QAAO;GAErB,MAAM,WAAqC,EAAE;AAE7C,QAAK,MAAM,CAAC,UAAU,YAAY,OAAO,QAAQ,YAAY,CAC3D,KAAI,QAAQ,SAAS,IAAI;QAGnB,CADiB,QAAQ,WAAiD,WAC5D,OAAQ,QAAO;SAEjC,UAAS,YAAY;AAIzB,UAAO,OAAO,KAAK,SAAS,CAAC,WAAW,KAAK,QAAQ,UAAU,SAAS,CAAC;IACzE;;CAGJ,iBAAyB,OAA2C;EAClE,MAAM,SAAmC,EAAE;AAC3C,OAAK,MAAM,YAAY,OAAO;GAC5B,MAAM,UAAU,KAAK,QAAQ,MAAM;AACnC,OAAI,CAAC,QAAS;AACd,QAAK,MAAM,CAAC,UAAU,YAAY,OAAO,QAAQ,QAAQ,WAAW,EAAE;AACpE,WAAO,cAAc,EAAE;AACvB,SAAK,MAAM,UAAU,QACnB,KAAI,CAAC,OAAO,UAAU,SAAS,OAAO,CACpC,QAAO,UAAU,KAAK,OAAO;;;AAKrC,SAAO;;;;CA3HV,UAAU,UAAU,cAAc;oBAG9B,OAAO,UAAU,YAAY,CAAA;oBAE7B,OAAO,UAAU,SAAS,CAAA;oBAE1B,OAAO,UAAU,QAAQ,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { t as AccessControlOptions } from "../types-BLyu9dAd.mjs";
1
2
  import { AsyncModuleOptions, DynamicModule } from "stratal/module";
2
3
  import { ApplicationError } from "stratal/errors";
3
4
  import { LoggerService } from "stratal/logger";
@@ -6,19 +7,27 @@ import { APIError } from "better-auth/api";
6
7
  import { Middleware, Next, RouteConfigurable, Router, RouterContext } from "stratal/router";
7
8
 
8
9
  //#region src/auth/auth.module.d.ts
10
+ interface AuthModuleAsyncOptions<TOptions extends BetterAuthOptions = BetterAuthOptions> extends AsyncModuleOptions<TOptions> {
11
+ /**
12
+ * Optional access control configuration.
13
+ * When provided, registers AccessService and auto-adds the Stratal AC plugin to Better Auth.
14
+ */
15
+ accessControl?: AccessControlOptions;
16
+ }
9
17
  declare class AuthModule implements RouteConfigurable {
10
18
  /**
11
19
  * Configure auth middleware globally.
12
20
  *
13
21
  * Registers middlewares in order:
14
22
  * 1. AuthContextMiddleware - Creates and registers AuthContext in request container
15
- * 2. SessionVerificationMiddleware - Verifies session and populates AuthContext with userId
23
+ * 2. SessionVerificationMiddleware - Verifies session and populates AuthContext with userId + role
16
24
  */
17
25
  configureRoutes(router: Router): void;
18
26
  /**
19
- * Configure AuthModule with async options factory
27
+ * Configure AuthModule with async options factory.
28
+ * Optionally provide `accessControl` to enable permission-based authorization.
20
29
  */
21
- static forRootAsync<TOptions extends BetterAuthOptions>(options: AsyncModuleOptions<TOptions>): DynamicModule;
30
+ static forRootAsync<TOptions extends BetterAuthOptions>(options: AuthModuleAsyncOptions<TOptions>): DynamicModule;
22
31
  }
23
32
  //#endregion
24
33
  //#region src/auth/auth.tokens.d.ts
@@ -100,12 +109,62 @@ declare class IdTokenNotSupportedError extends ApplicationError {
100
109
  declare class TokenExpiredError extends ApplicationError {
101
110
  constructor();
102
111
  }
112
+ declare class InvalidCallbackUrlError extends ApplicationError {
113
+ constructor();
114
+ }
115
+ declare class InvalidOriginError extends ApplicationError {
116
+ constructor();
117
+ }
118
+ declare class AuthValidationFailedError extends ApplicationError {
119
+ constructor();
120
+ }
121
+ declare class EmailAlreadyVerifiedError extends ApplicationError {
122
+ constructor();
123
+ }
124
+ declare class EmailMismatchError extends ApplicationError {
125
+ constructor();
126
+ }
127
+ declare class BetterAuthUnknownError extends ApplicationError {
128
+ constructor(errorCode?: string);
129
+ }
103
130
  //#endregion
104
131
  //#region src/auth/errors/invalid-token.error.d.ts
105
132
  declare class InvalidTokenError extends ApplicationError {
106
133
  constructor();
107
134
  }
108
135
  //#endregion
136
+ //#region src/auth/errors/organization-errors.d.ts
137
+ declare class OrganizationNotFoundError extends ApplicationError {
138
+ constructor();
139
+ }
140
+ declare class OrganizationMemberNotFoundError extends ApplicationError {
141
+ constructor();
142
+ }
143
+ declare class OrganizationInvitationNotFoundError extends ApplicationError {
144
+ constructor();
145
+ }
146
+ declare class OrganizationPermissionDeniedError extends ApplicationError {
147
+ constructor();
148
+ }
149
+ declare class OrganizationInvitationRecipientMismatchError extends ApplicationError {
150
+ constructor();
151
+ }
152
+ declare class OrganizationConflictError extends ApplicationError {
153
+ constructor();
154
+ }
155
+ declare class OrganizationLimitReachedError extends ApplicationError {
156
+ constructor();
157
+ }
158
+ declare class OrganizationMembershipError extends ApplicationError {
159
+ constructor();
160
+ }
161
+ declare class OrganizationTeamNotFoundError extends ApplicationError {
162
+ constructor();
163
+ }
164
+ declare class OrganizationRoleNotFoundError extends ApplicationError {
165
+ constructor();
166
+ }
167
+ //#endregion
109
168
  //#region src/auth/errors/token-required.error.d.ts
110
169
  declare class TokenRequiredError extends ApplicationError {
111
170
  constructor();
@@ -116,6 +175,65 @@ declare class VerificationFailedError extends ApplicationError {
116
175
  constructor();
117
176
  }
118
177
  //#endregion
178
+ //#region src/auth/i18n/en.d.ts
179
+ declare const authMessages: {
180
+ readonly en: {
181
+ readonly auth: {
182
+ readonly errors: {
183
+ readonly tokenRequired: "Verification token is required";
184
+ readonly invalidToken: "Invalid or expired verification token";
185
+ readonly verificationFailed: "Verification failed. Please try again.";
186
+ readonly userNotFound: "User not found. Please check your credentials.";
187
+ readonly invalidCredentials: "Invalid email or password";
188
+ readonly invalidPassword: "Invalid password";
189
+ readonly invalidEmail: "Invalid email address";
190
+ readonly sessionExpired: "Your session has expired. Please sign in again.";
191
+ readonly emailNotVerified: "Please verify your email address before signing in";
192
+ readonly passwordTooShort: "Password must be at least {minLength} characters";
193
+ readonly passwordTooLong: "Password must be at most {maxLength} characters";
194
+ readonly accountAlreadyExists: "An account with this email already exists";
195
+ readonly failedToCreateUser: "Failed to create user account. Please try again.";
196
+ readonly failedToCreateSession: "Failed to create session. Please try again.";
197
+ readonly failedToGetSession: "Failed to retrieve session. Please try again.";
198
+ readonly failedToUpdateUser: "Failed to update user information. Please try again.";
199
+ readonly failedToGetUserInfo: "Failed to retrieve user information. Please try again.";
200
+ readonly socialAccountLinked: "This social account is already linked to another user";
201
+ readonly providerNotFound: "Authentication provider not found";
202
+ readonly userEmailNotFound: "User email address not found";
203
+ readonly accountNotFound: "Account not found";
204
+ readonly credentialAccountNotFound: "Credential account not found";
205
+ readonly cannotUnlinkLastAccount: "Cannot unlink your last account";
206
+ readonly userAlreadyHasPassword: "User already has a password set";
207
+ readonly emailCannotBeUpdated: "Email address cannot be updated at this time";
208
+ readonly tokenExpired: "The verification token has expired. Please request a new verification email.";
209
+ readonly invalidCallbackUrl: "Invalid callback URL";
210
+ readonly invalidOrigin: "Request origin is not allowed";
211
+ readonly validationFailed: "Authentication validation failed";
212
+ readonly emailAlreadyVerified: "Email address is already verified";
213
+ readonly emailMismatch: "Email address does not match";
214
+ readonly unknownError: "An authentication error occurred";
215
+ };
216
+ readonly org: {
217
+ readonly organizationNotFound: "Organization not found";
218
+ readonly memberNotFound: "Member not found";
219
+ readonly invitationNotFound: "Invitation not found";
220
+ readonly permissionDenied: "You do not have permission to perform this action";
221
+ readonly invitationRecipientMismatch: "You are not the recipient of this invitation";
222
+ readonly conflict: "A resource with this identifier already exists";
223
+ readonly limitReached: "The maximum limit has been reached";
224
+ readonly membershipError: "This action cannot be performed due to membership constraints";
225
+ readonly teamNotFound: "Team not found";
226
+ readonly roleNotFound: "Role not found";
227
+ };
228
+ };
229
+ };
230
+ };
231
+ declare module 'stratal/i18n' {
232
+ interface AppMessageNamespaces {
233
+ auth: typeof authMessages['en']['auth'];
234
+ }
235
+ } //# sourceMappingURL=en.d.ts.map
236
+ //#endregion
119
237
  //#region src/auth/middleware/auth-context.middleware.d.ts
120
238
  /**
121
239
  * Auth Context Middleware
@@ -201,5 +319,5 @@ declare function mapBetterAuthError(error: APIError): ApplicationError;
201
319
  */
202
320
  declare function isAPIError(error: unknown): error is APIError;
203
321
  //#endregion
204
- export { AUTH_OPTIONS, AUTH_SERVICE, AccountAlreadyExistsError, AccountNotFoundError, AuthContextMiddleware, AuthModule, AuthService, CannotUnlinkLastAccountError, CredentialAccountNotFoundError, EmailCannotBeUpdatedError, EmailNotVerifiedError, FailedToCreateSessionError, FailedToCreateUserError, FailedToGetSessionError, FailedToGetUserInfoError, FailedToUpdateUserError, IdTokenNotSupportedError, InvalidCredentialsError, InvalidEmailError, InvalidPasswordError, InvalidTokenError, PasswordTooLongError, PasswordTooShortError, ProviderNotFoundError, SessionExpiredError, SessionVerificationMiddleware, SocialAccountLinkedError, TokenExpiredError, TokenRequiredError, UserAlreadyHasPasswordError, UserEmailNotFoundError, UserNotFoundError, VerificationFailedError, getErrorHandlerConfig, isAPIError, mapBetterAuthError, wrapBetterAuth };
322
+ export { AUTH_OPTIONS, AUTH_SERVICE, AccountAlreadyExistsError, AccountNotFoundError, AuthContextMiddleware, AuthModule, AuthModuleAsyncOptions, AuthService, AuthValidationFailedError, BetterAuthUnknownError, CannotUnlinkLastAccountError, CredentialAccountNotFoundError, EmailAlreadyVerifiedError, EmailCannotBeUpdatedError, EmailMismatchError, EmailNotVerifiedError, FailedToCreateSessionError, FailedToCreateUserError, FailedToGetSessionError, FailedToGetUserInfoError, FailedToUpdateUserError, IdTokenNotSupportedError, InvalidCallbackUrlError, InvalidCredentialsError, InvalidEmailError, InvalidOriginError, InvalidPasswordError, InvalidTokenError, OrganizationConflictError, OrganizationInvitationNotFoundError, OrganizationInvitationRecipientMismatchError, OrganizationLimitReachedError, OrganizationMemberNotFoundError, OrganizationMembershipError, OrganizationNotFoundError, OrganizationPermissionDeniedError, OrganizationRoleNotFoundError, OrganizationTeamNotFoundError, PasswordTooLongError, PasswordTooShortError, ProviderNotFoundError, SessionExpiredError, SessionVerificationMiddleware, SocialAccountLinkedError, TokenExpiredError, TokenRequiredError, UserAlreadyHasPasswordError, UserEmailNotFoundError, UserNotFoundError, VerificationFailedError, authMessages, getErrorHandlerConfig, isAPIError, mapBetterAuthError, wrapBetterAuth };
205
323
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/auth/auth.module.ts","../../src/auth/auth.tokens.ts","../../src/auth/errors/auth-errors.ts","../../src/auth/errors/invalid-token.error.ts","../../src/auth/errors/token-required.error.ts","../../src/auth/errors/verification-failed.error.ts","../../src/auth/middleware/auth-context.middleware.ts","../../src/auth/services/auth.service.ts","../../src/auth/middleware/session-verification.middleware.ts","../../src/auth/utils/auth-helpers.ts","../../src/auth/utils/better-auth-error-handler.ts"],"mappings":";;;;;;;;cAgCa,UAAA,YAAsB,iBAAA;EAe1B;;;;;;;EAPP,eAAA,CAAgB,MAAA,EAAQ,MAAA;EASR;;;EAAA,OAFT,YAAA,kBAA8B,iBAAA,CAAA,CACnC,OAAA,EAAS,kBAAA,CAAmB,QAAA,IAC3B,aAAA;AAAA;;;;cChDQ,YAAA;;cAGA,YAAA;;;cCFA,iBAAA,SAA0B,gBAAA;cACzB,KAAA;AAAA;AAAA,cAKD,uBAAA,SAAgC,gBAAA;EAAA,WAAA,CAAA;AAAA;AAAA,cAMhC,oBAAA,SAA6B,gBAAA;EAAA,WAAA,CAAA;AAAA;AAAA,cAM7B,iBAAA,SAA0B,gBAAA;cACzB,KAAA;AAAA;AAAA,cAKD,mBAAA,SAA4B,gBAAA;EAAA,WAAA,CAAA;AAAA;AAAA,cAM5B,qBAAA,SAA8B,gBAAA;cAC7B,KAAA;AAAA;AAAA,cAKD,qBAAA,SAA8B,gBAAA;cAC7B,SAAA;AAAA;AAAA,cAKD,oBAAA,SAA6B,gBAAA;cAC5B,SAAA;AAAA;AAAA,cAKD,yBAAA,SAAkC,gBAAA;cACjC,KAAA;AAAA;AAAA,cAKD,uBAAA,SAAgC,gBAAA;cAC/B,MAAA;AAAA;AAAA,cAKD,0BAAA,SAAmC,gBAAA;cAClC,MAAA;AAAA;AAAA,cAKD,uBAAA,SAAgC,gBAAA;cAC/B,MAAA;AAAA;AAAA,cAKD,wBAAA,SAAiC,gBAAA;cAChC,QAAA;AAAA;AAAA,c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AAA,EAAQ,aAAA;EAGjD,MAAA,CAAO,GAAA,EAAK,aAAA,EAAe,IAAA,EAAM,IAAA,GAAO,OAAA;AAAA;;;;;;;iBCnBhC,qBAAA,CAAA,GAAyB,iBAAA;;;ATsBzC;cSPa,cAAA,MAA2B,EAAA,QAAU,OAAA,CAAQ,CAAA,MAAK,OAAA,CAAQ,CAAA;;;;;;iBCavD,kBAAA,CAAmB,KAAA,EAAO,QAAA,GAAW,gBAAA;;;AVNrD;;;iBUuFgB,UAAA,CAAW,KAAA,YAAiB,KAAA,IAAS,QAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/auth/auth.module.ts","../../src/auth/auth.tokens.ts","../../src/auth/errors/auth-errors.ts","../../src/auth/errors/invalid-token.error.ts","../../src/auth/errors/organization-errors.ts","../../src/auth/errors/token-required.error.ts","../../src/auth/errors/verification-failed.error.ts","../../src/auth/i18n/en.ts","../../src/auth/middleware/auth-context.middleware.ts","../../src/auth/services/auth.service.ts","../../src/auth/middleware/session-verification.middleware.ts","../../src/auth/utils/auth-helpers.ts","../../src/auth/utils/better-auth-error-handler.ts"],"mappings":";;;;;;;;;UA8DiB,sBAAA,kBAAwC,iBAAA,GAAoB,iBAAA,UACnE,kBAAA,CAAmB,QAAA;EAgCX;;;;EA3BhB,aAAA,GAAgB,oBAAA;AAAA;AAAA,cASL,UAAA,YAAsB,iBAAA;EC5E2B;;AAG9D;;;;;EDiFE,eAAA,CAAgB,MAAA,EAAQ,MAAA;;;AEnF1B;;SF2FS,YAAA,kBAA8B,iBAAA,CAAA,CACnC,OAAA,EAAS,sBAAA,CAAuB,QAAA,IAC/B,aAAA;AAAA;;;;cC9FQ,YAAA;;cAGA,YAAA;;;cCFA,iBAAA,SAA0B,gBAAA;cACzB,KAAA;AAAA;AAAA,cAKD,uBAAA,SAAgC,gBAAA;EAAA,WAAA,CAAA;AAAA;AAAA,cAMhC,oBAAA,SAA6B,gBAAA;EAAA,WAAA,CAAA;AAAA;AAAA,c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