@velajs/better-auth 1.31.0 → 1.33.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.33.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1a520f9: Publish verified identity through the canonical execution-context APIs across HTTP adapters and native managed invocations. Identity snapshots are immutable, isolated to the exact invocation, and unavailable after expiry, clear, replacement, completion or container disposal. Tenant admission and authorization reject stale authentication snapshots after asynchronous checks.
|
|
8
|
+
|
|
9
|
+
Native tenant and Cedar guards now require canonical identity published by a verified transport adapter. Resolver output and service-binding caller props cannot substitute for authentication. WebSocket attachment support remains available. The integrations require the updated core peer version; explicitly order authentication, tenant and authorization guards on native hosts.
|
|
10
|
+
|
|
11
|
+
Update the Better Auth integration alongside its authorization dependency with the compatible core peer floor.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [1a520f9]
|
|
16
|
+
- @velajs/vela@1.35.0
|
|
17
|
+
- @velajs/authz@1.33.0
|
|
18
|
+
|
|
19
|
+
## 1.32.0
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- 9a00506: Align module APIs with instance ownership: shared facilities use forRoot, local and named services use register, and Queue, I18n and Seeder contribute declarations through forFeature. Remove replaced APIs. Local registrations receive independent identities; reused definitions share within an application, and explicit keys retain conflict checks.
|
|
24
|
+
|
|
25
|
+
Require applications to attach exported guards and interceptors explicitly. Remove automatic installation and guard options while preserving policy ownership, request scope, phase ordering, testing overrides and integration-route exemptions. Keep translation contributions and mutable runtime configuration isolated per application, and return runtime-only settings from async factories. Storage separates structural httpController mounting from runtime http options.
|
|
26
|
+
|
|
27
|
+
Add schema-first GraphQL resolver and parameter decorators with exact provider ownership, endpoint selection and duplicate binding validation. Add the optional Cloudflare workflow-definitions entrypoint to host portable workflows and compiled agents with validated input, per-run dependency resolution, explicit dispatch authority and native replay/error semantics.
|
|
28
|
+
|
|
29
|
+
Update CLI output, runnable examples, packed consumers and migration documentation together. Keep root Cloudflare declarations usable without installing the optional Feature Flags peer. See docs/module-api-migration.md for the new signatures and required application changes. This is a coordinated breaking change on the 1.x line; no compatibility aliases are retained.
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [9a00506]
|
|
34
|
+
- @velajs/vela@1.34.0
|
|
35
|
+
- @velajs/authz@1.32.0
|
|
36
|
+
|
|
3
37
|
## 1.31.0
|
|
4
38
|
|
|
5
39
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -8,13 +8,13 @@ pnpm add @velajs/better-auth better-auth
|
|
|
8
8
|
|
|
9
9
|
## Quick start
|
|
10
10
|
|
|
11
|
-
Construct your better-auth instance once and hand it to `BetterAuthModule.forRoot`.
|
|
11
|
+
Construct your better-auth instance once and hand it to `BetterAuthModule.forRoot`. Attach its exported `AuthGuard` in the application; use `@CurrentUser()` on authenticated routes and mark the small anonymous surface explicitly.
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
14
|
import { betterAuth } from 'better-auth';
|
|
15
|
-
import { Module, Controller, Get, VelaFactory } from '@velajs/vela';
|
|
15
|
+
import { APP_GUARD, Module, Controller, Get, VelaFactory } from '@velajs/vela';
|
|
16
16
|
import {
|
|
17
|
-
BetterAuthModule, CurrentUser, Public,
|
|
17
|
+
AuthGuard, BetterAuthModule, CurrentUser, Public,
|
|
18
18
|
} from '@velajs/better-auth';
|
|
19
19
|
|
|
20
20
|
const auth = betterAuth({
|
|
@@ -36,6 +36,7 @@ class MeController {
|
|
|
36
36
|
@Module({
|
|
37
37
|
imports: [BetterAuthModule.forRoot({ auth })],
|
|
38
38
|
controllers: [MeController],
|
|
39
|
+
providers: [{ provide: APP_GUARD, useExisting: AuthGuard }],
|
|
39
40
|
})
|
|
40
41
|
class AppModule {}
|
|
41
42
|
|
|
@@ -52,17 +53,19 @@ BetterAuthModule.forRoot({
|
|
|
52
53
|
auth, // betterAuth({ ... }) instance, or () => betterAuth({ ... })
|
|
53
54
|
issuer: 'my-app:better-auth', // stable namespace paired with user ids
|
|
54
55
|
basePath: '/api/auth', // default — must match your better-auth config
|
|
55
|
-
guard: 'global', // default — AuthGuard runs globally in the authenticate phase
|
|
56
56
|
mountHandler: true, // mount /api/auth/* catch-all controller
|
|
57
57
|
isGlobal: false, // default — true makes BetterAuthService visible to every module
|
|
58
58
|
});
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
Authentication has no allow-by-default compatibility mode. Use `@Public(true)` for routes that intentionally skip authentication, or `@OptionalAuth(true)` when the route accepts an anonymous identity.
|
|
61
|
+
Authentication has no allow-by-default compatibility mode. Use `@Public(true)` for routes that intentionally skip authentication, or `@OptionalAuth(true)` when the route accepts an anonymous identity. Importing the module alone does not install authentication; attach an application alias or `@UseGuards(AuthGuard)`.
|
|
62
62
|
|
|
63
|
-
`basePath
|
|
63
|
+
`basePath` and `mountHandler` are structural: `forRootAsync` takes them next to its factory, which returns the other options. An `auth` function runs on the first authentication, not while the application initializes.
|
|
64
64
|
|
|
65
|
-
Global guards run in deterministic phases whatever the import order: `authenticate` (AuthGuard), `tenant` (TenantGuard), `authorize` (PermissionGuard, RolesGuard, CedarGuard), then `feature` (ThrottlerGuard and any guard without a declared phase). Throttling therefore always partitions by the verified identity. The mounted auth handler is `@Public(true)` and marked `SkipGuardPhases(['tenant', 'authorize'])`, so the tenant admission and authorization guards
|
|
65
|
+
Global guards run in deterministic phases whatever the import order: `authenticate` (AuthGuard), `tenant` (TenantGuard), `authorize` (PermissionGuard, RolesGuard, CedarGuard), then `feature` (ThrottlerGuard and any guard without a declared phase). Throttling therefore always partitions by the verified identity. The mounted auth handler is `@Public(true)` and marked `SkipGuardPhases(['tenant', 'authorize'])`, so the tenant admission and authorization guards applications install globally never block sign-in, including a `TenantGuard` the application registers globally itself; throttling and the other global guards still apply.
|
|
66
|
+
|
|
67
|
+
The following imports configure authentication; retain the `APP_GUARD` alias from
|
|
68
|
+
the quick start in the application root.
|
|
66
69
|
|
|
67
70
|
## Three composition patterns
|
|
68
71
|
|
|
@@ -193,9 +196,9 @@ handle(@CurrentUser() user: User | undefined) {
|
|
|
193
196
|
- **`AuthGuard`** — singleton. Reads `Authorization` header / cookies via `auth.api.getSession`, validates the full base user/session models, and publishes Vela's trusted principal, tenant, roles, and session expiry for downstream security components. The Better Auth organization plugin's verified `activeOrganizationId` becomes the tenant partition when present. The guard honors only explicit `@Public()` / `@OptionalAuth()` metadata. The generated Better Auth catch-all controller is explicitly public; sharing its URL prefix never makes an application controller public.
|
|
194
197
|
Permission and role guards live in `@velajs/authz/vela`: import `PermissionGuard`, `RequirePermission`, `RolesGuard`, and `Roles` there. They read the same trusted identity for Better Auth and Cloudflare Access. Run authentication before authorization.
|
|
195
198
|
|
|
196
|
-
|
|
199
|
+
Install globally with `{ provide: APP_GUARD, useExisting: AuthGuard }`, or select routes with `@UseGuards(AuthGuard)`. Routes are deny-by-default; mark public ones with `@Public(true)`. The generated Better Auth controller is already marked public.
|
|
197
200
|
|
|
198
|
-
When using `ThrottlerModule`,
|
|
201
|
+
When using `ThrottlerModule`, also attach its exported `ThrottlerGuard`. Guard phases ensure Vela rate-limits by
|
|
199
202
|
the verified issuer, subject, principal type, and active organization before it
|
|
200
203
|
falls back to a platform-attested client address.
|
|
201
204
|
|
|
@@ -27,18 +27,11 @@ interface BetterAuthRuntimeOptions {
|
|
|
27
27
|
issuer?: string;
|
|
28
28
|
/** Mount path of the catch-all handler (default `/api/auth`). Structural. */
|
|
29
29
|
basePath?: string;
|
|
30
|
-
/**
|
|
31
|
-
* `'global'` (default) installs AuthGuard as a global guard in the
|
|
32
|
-
* `authenticate` phase, so it runs before tenant, authorization and feature
|
|
33
|
-
* guards whatever the import order. Use `'none'` only when the application
|
|
34
|
-
* installs an equivalent authentication guard itself. Structural.
|
|
35
|
-
*/
|
|
36
|
-
guard?: 'global' | 'none';
|
|
37
30
|
/** Mount the catch-all better-auth handler (default `true`). Structural. */
|
|
38
31
|
mountHandler?: boolean;
|
|
39
32
|
}
|
|
40
33
|
/** The fields `forRootAsync` takes alongside its factory: they shape the module graph. */
|
|
41
|
-
type BetterAuthStructuralOption = 'basePath' | '
|
|
34
|
+
type BetterAuthStructuralOption = 'basePath' | 'mountHandler';
|
|
42
35
|
type User$1 = User;
|
|
43
36
|
type Session$1 = Session;
|
|
44
37
|
//#endregion
|
|
@@ -74,4 +67,4 @@ declare class BetterAuthService<TAuth extends BetterAuthInstance = BetterAuthIns
|
|
|
74
67
|
}
|
|
75
68
|
//#endregion
|
|
76
69
|
export { BetterAuthStructuralOption as a, BetterAuthRuntimeOptions as i, BetterAuthInstance as n, Session$1 as o, BetterAuthModuleOptions as r, User$1 as s, BetterAuthService as t };
|
|
77
|
-
//# sourceMappingURL=better-auth.service-
|
|
70
|
+
//# sourceMappingURL=better-auth.service-D_G-PP8p.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as BetterAuthStructuralOption, i as BetterAuthRuntimeOptions, n as BetterAuthInstance, o as Session, r as BetterAuthModuleOptions, s as User, t as BetterAuthService } from "./better-auth.service-
|
|
1
|
+
import { a as BetterAuthStructuralOption, i as BetterAuthRuntimeOptions, n as BetterAuthInstance, o as Session, r as BetterAuthModuleOptions, s as User, t as BetterAuthService } from "./better-auth.service-D_G-PP8p.js";
|
|
2
2
|
import { CanActivate, ExecutionContext, GuardPhase, InjectionToken, Reflector, Type } from "@velajs/vela";
|
|
3
3
|
import { UpgradeAuthenticator, WebSocketUpgradeAuthenticationContext, WebSocketUpgradeIdentity } from "@velajs/vela/websocket";
|
|
4
4
|
import { Identity, PermissionResolver } from "@velajs/authz";
|
|
@@ -8,7 +8,8 @@ declare const ConfigurableModuleClass: import("@velajs/vela").ConfigurableModule
|
|
|
8
8
|
}, BetterAuthStructuralOption>;
|
|
9
9
|
/**
|
|
10
10
|
* better-auth for Vela: `BetterAuthService`, the catch-all handler under
|
|
11
|
-
* `basePath`, and `AuthGuard
|
|
11
|
+
* `basePath`, and an injectable `AuthGuard`. Applications install it through `APP_GUARD`
|
|
12
|
+
* with `useExisting: AuthGuard`, or attach it with `@UseGuards`.
|
|
12
13
|
*
|
|
13
14
|
* ```ts
|
|
14
15
|
* BetterAuthModule.forRoot({ auth: betterAuth({ ... }) });
|
|
@@ -18,7 +19,7 @@ declare const ConfigurableModuleClass: import("@velajs/vela").ConfigurableModule
|
|
|
18
19
|
* });
|
|
19
20
|
* ```
|
|
20
21
|
*
|
|
21
|
-
* `basePath
|
|
22
|
+
* `basePath` and `mountHandler` are structural: `forRootAsync`
|
|
22
23
|
* takes them alongside the factory. The factory runs when the application
|
|
23
24
|
* initializes; an `auth` function it returns runs on first authentication.
|
|
24
25
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as __decorateMetadata, i as __decorateParam, n as BetterAuthService, r as __decorate, t as BETTER_AUTH_BUILDER } from "./better-auth.service-SNg1YFTK.js";
|
|
2
|
-
import {
|
|
2
|
+
import { All, Controller, Inject, Injectable, InjectionToken, Optional, Reflector, Req, UnauthorizedException, createParamDecorator, defineModule, defineProvider } from "@velajs/vela";
|
|
3
3
|
import { SkipGuardPhases, clearTrustedRequestIdentity, createTrustedRequestIdentityStore, getTrustedContextRequest, setTrustedRequestIdentity } from "@velajs/vela/module-kit";
|
|
4
4
|
import { getContextIdentity } from "@velajs/authz/vela";
|
|
5
5
|
//#region src/decorators/public.decorator.ts
|
|
@@ -235,7 +235,6 @@ function runtimeOptions(options) {
|
|
|
235
235
|
return {
|
|
236
236
|
basePath,
|
|
237
237
|
issuer,
|
|
238
|
-
guard: options.guard ?? "global",
|
|
239
238
|
mountHandler: options.mountHandler ?? true
|
|
240
239
|
};
|
|
241
240
|
}
|
|
@@ -246,20 +245,13 @@ function buildAuth(auth) {
|
|
|
246
245
|
const { ConfigurableModuleClass } = defineModule({
|
|
247
246
|
name: "BetterAuth",
|
|
248
247
|
optionsToken: MODULE_OPTIONS,
|
|
249
|
-
structural: [
|
|
250
|
-
"basePath",
|
|
251
|
-
"guard",
|
|
252
|
-
"mountHandler"
|
|
253
|
-
],
|
|
248
|
+
structural: ["basePath", "mountHandler"],
|
|
254
249
|
defaults: {
|
|
255
250
|
basePath: DEFAULT_BETTER_AUTH_BASE_PATH,
|
|
256
|
-
guard: "global",
|
|
257
251
|
mountHandler: true
|
|
258
252
|
},
|
|
259
253
|
setup: ({ OPTIONS, options }) => {
|
|
260
254
|
const basePath = normalizeBetterAuthBasePath(options.basePath);
|
|
261
|
-
const guard = options.guard;
|
|
262
|
-
if (guard !== "global" && guard !== "none") throw new Error("@velajs/better-auth: guard must be 'global' or 'none'");
|
|
263
255
|
const controllers = options.mountHandler === false ? [] : [createBetterAuthCatchallController(basePath)];
|
|
264
256
|
return {
|
|
265
257
|
providers: [
|
|
@@ -272,8 +264,7 @@ const { ConfigurableModuleClass } = defineModule({
|
|
|
272
264
|
inject: [OPTIONS]
|
|
273
265
|
}),
|
|
274
266
|
BetterAuthService,
|
|
275
|
-
AuthGuard
|
|
276
|
-
...guard === "global" ? [defineProvider(APP_GUARD, { useExisting: AuthGuard })] : []
|
|
267
|
+
AuthGuard
|
|
277
268
|
],
|
|
278
269
|
controllers,
|
|
279
270
|
exports: [
|
|
@@ -286,7 +277,8 @@ const { ConfigurableModuleClass } = defineModule({
|
|
|
286
277
|
});
|
|
287
278
|
/**
|
|
288
279
|
* better-auth for Vela: `BetterAuthService`, the catch-all handler under
|
|
289
|
-
* `basePath`, and `AuthGuard
|
|
280
|
+
* `basePath`, and an injectable `AuthGuard`. Applications install it through `APP_GUARD`
|
|
281
|
+
* with `useExisting: AuthGuard`, or attach it with `@UseGuards`.
|
|
290
282
|
*
|
|
291
283
|
* ```ts
|
|
292
284
|
* BetterAuthModule.forRoot({ auth: betterAuth({ ... }) });
|
|
@@ -296,7 +288,7 @@ const { ConfigurableModuleClass } = defineModule({
|
|
|
296
288
|
* });
|
|
297
289
|
* ```
|
|
298
290
|
*
|
|
299
|
-
* `basePath
|
|
291
|
+
* `basePath` and `mountHandler` are structural: `forRootAsync`
|
|
300
292
|
* takes them alongside the factory. The factory runs when the application
|
|
301
293
|
* initializes; an `auth` function it returns runs on first authentication.
|
|
302
294
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/decorators/public.decorator.ts","../src/base-path.ts","../src/better-auth.controller.ts","../src/better-auth.tokens.ts","../src/auth-request-state.ts","../src/session-data.ts","../src/decorators/optional-auth.decorator.ts","../src/guards/auth.guard.ts","../src/better-auth.module.ts","../src/upgrade-authenticator.ts","../src/decorators/current-user.decorator.ts","../src/decorators/current-session.decorator.ts","../src/authz-bridge.ts"],"sourcesContent":["import { Reflector } from '@velajs/vela';\n\nexport const Public = Reflector.createDecorator<boolean>({ key: 'vela.auth.public' });\nexport const PUBLIC_KEY = Public.KEY;\n","export const DEFAULT_BETTER_AUTH_BASE_PATH = '/api/auth';\n\n/** Validate and canonicalize the route prefix used by the public auth controller. */\nexport function normalizeBetterAuthBasePath(value?: string): string {\n const basePath = value ?? DEFAULT_BETTER_AUTH_BASE_PATH;\n if (\n basePath.length === 0 ||\n basePath !== basePath.trim() ||\n !basePath.startsWith('/') ||\n basePath.startsWith('//') ||\n basePath === '/' ||\n basePath.endsWith('/') ||\n /[\\\\?#*]/u.test(basePath) ||\n /%(?:2e|2f|5c)/iu.test(basePath)\n ) {\n throw new Error(\n '@velajs/better-auth: basePath must be a canonical absolute path such as \"/api/auth\"',\n );\n }\n\n let decoded: string;\n try {\n decoded = decodeURIComponent(basePath);\n } catch {\n throw new Error('@velajs/better-auth: basePath contains invalid percent encoding');\n }\n if (decoded.split('/').some((segment) => segment === '.' || segment === '..')) {\n throw new Error('@velajs/better-auth: basePath must not contain dot segments');\n }\n return basePath;\n}\n","import { All, Controller, Inject, Req, type Type } from '@velajs/vela';\nimport { SkipGuardPhases } from '@velajs/vela/module-kit';\nimport { BetterAuthService } from './better-auth.service';\nimport { Public } from './decorators/public.decorator';\nimport { normalizeBetterAuthBasePath } from './base-path';\n\n// One decorated class per base path: every registration of a path, and every\n// call, shares it (the class reads nothing else).\nconst controllers = new Map<string, Type>();\n\n/**\n * Build a catch-all controller that mounts better-auth's handler at `basePath`\n * (default `/api/auth`). This is a factory because vela reads a controller's\n * route off the class at decoration time, so a custom base path needs its own\n * decorated class — the path can't be parametrized on a single shared class.\n * Calls with the same base path return the same class.\n *\n * Two base paths to keep consistent:\n * - this `basePath` is RELATIVE to vela's `globalPrefix` (always prepended);\n * - better-auth routes against its OWN absolute `basePath` (the one you pass to\n * `betterAuth({ basePath })`), which must equal `globalPrefix + basePath`.\n *\n * Both default to `/api/auth`, so the no-prefix / no-config case just works.\n */\nexport function createBetterAuthCatchallController(basePath: string = '/api/auth'): Type {\n const normalizedBasePath = normalizeBetterAuthBasePath(basePath);\n const existing = controllers.get(normalizedBasePath);\n if (existing) return existing;\n // Better Auth authenticates its own endpoints; application-wide tenant\n // admission and authorization do not apply to signing in.\n @Public(true)\n @SkipGuardPhases(['tenant', 'authorize'])\n @Controller(normalizedBasePath)\n class BetterAuthCatchallController {\n // Inject the service — its `.handler` getter triggers lazy construction\n // of the underlying betterAuth() instance on first access, AFTER any\n // runtime adapter middleware (Cloudflare env capture) has run.\n constructor(@Inject(BetterAuthService) private readonly auth: BetterAuthService) {}\n\n @All('/*')\n async handle(@Req() request: Request): Promise<Response> {\n return this.auth.handler(request);\n }\n }\n controllers.set(normalizedBasePath, BetterAuthCatchallController);\n return BetterAuthCatchallController;\n}\n","import { InjectionToken } from '@velajs/vela';\nimport type { BetterAuthRuntimeOptions } from './better-auth.types';\n\nexport const BETTER_AUTH_OPTIONS = new InjectionToken<BetterAuthRuntimeOptions>(\n 'vela.BetterAuthOptions',\n);\n","import type { ExecutionContext } from '@velajs/vela';\nimport {\n clearTrustedRequestIdentity,\n createTrustedRequestIdentityStore,\n getTrustedContextRequest,\n setTrustedRequestIdentity,\n} from '@velajs/vela/module-kit';\nimport type { SessionData } from './session-data';\n\n// This map stores provider payload, never a second authentication authority.\n// A clear, expiry, or identity replacement makes the payload unreachable.\nconst sessions = createTrustedRequestIdentityStore<SessionData>();\n\nexport function beginAuthRequest(context: ExecutionContext): void {\n clearTrustedRequestIdentity(context.getRequest());\n}\n\nexport function authenticateRequest(\n context: ExecutionContext,\n data: SessionData,\n issuer: string,\n): void {\n const request = context.getRequest();\n setTrustedRequestIdentity(request, {\n principal: { issuer, subject: data.user.id, principalType: 'user' },\n expiresAtMs: data.session.expiresAt.getTime(),\n roles: data.roles,\n ...(data.tenantId === undefined ? {} : { tenantId: data.tenantId }),\n });\n sessions.set(request, data);\n}\n\nexport function getAuthRequestState(context: ExecutionContext): SessionData | undefined {\n const request = getTrustedContextRequest(context);\n return request ? sessions.get(request) : undefined;\n}\n","import type { Session, User } from './better-auth.types';\n\nexport interface SessionData {\n readonly user: User;\n readonly session: Session;\n readonly roles: readonly string[];\n readonly tenantId?: string;\n}\n\nfunction own(value: unknown, key: string): unknown {\n if (typeof value !== 'object' || value === null) return undefined;\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n return descriptor && 'value' in descriptor ? descriptor.value : undefined;\n}\n\nfunction requiredString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\nfunction date(value: unknown): Date | undefined {\n return value instanceof Date && Number.isFinite(value.getTime()) ? new Date(value) : undefined;\n}\n\nfunction optionalString(value: unknown): value is string | null | undefined {\n return value === undefined || value === null || typeof value === 'string';\n}\n\n/** Keep plugin data opaque; base model fields below are validated individually. */\nfunction dataProperties(value: object): Record<string, unknown> {\n return Object.fromEntries(Object.keys(value).map((key) => [key, own(value, key)]));\n}\n\n/** Validate the full Better Auth base models, not merely ids masquerading as them. */\nexport function validateSessionData(value: unknown): SessionData | undefined {\n try {\n const user = own(value, 'user');\n const session = own(value, 'session');\n if (\n typeof user !== 'object' ||\n user === null ||\n typeof session !== 'object' ||\n session === null\n ) {\n return undefined;\n }\n const id = own(user, 'id');\n const email = own(user, 'email');\n const name = own(user, 'name');\n const emailVerified = own(user, 'emailVerified');\n const image = own(user, 'image');\n const createdAt = date(own(user, 'createdAt'));\n const updatedAt = date(own(user, 'updatedAt'));\n const sessionId = own(session, 'id');\n const userId = own(session, 'userId');\n const token = own(session, 'token');\n const sessionCreatedAt = date(own(session, 'createdAt'));\n const sessionUpdatedAt = date(own(session, 'updatedAt'));\n const expiresAt = date(own(session, 'expiresAt'));\n const ipAddress = own(session, 'ipAddress');\n const userAgent = own(session, 'userAgent');\n const organization = own(session, 'activeOrganizationId');\n const role = own(user, 'role');\n let roles: string[] = [];\n if (role !== undefined && role !== null) {\n if (typeof role === 'string')\n roles = role\n .split(',')\n .map((part) => part.trim())\n .filter(Boolean);\n else if (\n Array.isArray(role) &&\n role.every((entry: unknown): entry is string => typeof entry === 'string')\n ) {\n roles = role.map((entry: string) => entry.trim()).filter(Boolean);\n } else return undefined;\n }\n if (\n !requiredString(id) ||\n !requiredString(email) ||\n typeof name !== 'string' ||\n typeof emailVerified !== 'boolean' ||\n !optionalString(image) ||\n !createdAt ||\n !updatedAt ||\n !requiredString(sessionId) ||\n userId !== id ||\n !requiredString(token) ||\n !sessionCreatedAt ||\n !sessionUpdatedAt ||\n !expiresAt ||\n expiresAt.getTime() <= Date.now() ||\n !optionalString(ipAddress) ||\n !optionalString(userAgent) ||\n (organization !== undefined && organization !== null && !requiredString(organization))\n )\n return undefined;\n return {\n user: Object.freeze({\n ...dataProperties(user),\n id,\n email,\n name,\n emailVerified,\n createdAt,\n updatedAt,\n image,\n }),\n session: Object.freeze({\n ...dataProperties(session),\n id: sessionId,\n userId: id,\n token,\n createdAt: sessionCreatedAt,\n updatedAt: sessionUpdatedAt,\n expiresAt,\n ipAddress,\n userAgent,\n }),\n roles: Object.freeze(roles),\n ...(typeof organization === 'string' ? { tenantId: organization } : {}),\n };\n } catch {\n return undefined;\n }\n}\n","import { Reflector } from '@velajs/vela';\n\nexport const OptionalAuth = Reflector.createDecorator<boolean>({ key: 'vela.auth.optional' });\nexport const OPTIONAL_AUTH_KEY = OptionalAuth.KEY;\n","import {\n Inject,\n Injectable,\n Reflector,\n UnauthorizedException,\n type CanActivate,\n type ExecutionContext,\n type GuardPhase,\n} from '@velajs/vela';\nimport { getTrustedContextRequest } from '@velajs/vela/module-kit';\nimport { getContextIdentity } from '@velajs/authz/vela';\nimport { BETTER_AUTH_OPTIONS } from '../better-auth.tokens';\nimport { BetterAuthService } from '../better-auth.service';\nimport type { BetterAuthRuntimeOptions } from '../better-auth.types';\nimport { authenticateRequest, beginAuthRequest, getAuthRequestState } from '../auth-request-state';\nimport { validateSessionData } from '../session-data';\nimport { OptionalAuth } from '../decorators/optional-auth.decorator';\nimport { Public } from '../decorators/public.decorator';\n\n@Injectable()\nexport class AuthGuard implements CanActivate {\n /** Global guards run authentication first, then tenant, authorization and feature phases. */\n static readonly phase: GuardPhase = 'authenticate';\n\n constructor(\n @Inject(BetterAuthService) private readonly auth: BetterAuthService,\n @Inject(BETTER_AUTH_OPTIONS) private readonly opts: BetterAuthRuntimeOptions,\n @Inject(Reflector) private readonly reflector: Reflector,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n // Frames trust only the authenticated connection attachment; HTTP cookies\n // and request payload never become ambient WebSocket authentication.\n if (context.getType() === 'ws') {\n if (getContextIdentity(context)) return true;\n throw new UnauthorizedException('Authentication required');\n }\n // Custom HTTP-backed dispatchers authenticate once at the outer boundary.\n // Never re-read credentials or clear shared authority across sibling fields.\n if (context.getType() !== 'http') {\n if (\n getTrustedContextRequest(context) &&\n (getAuthRequestState(context) ||\n this.reflector.getAllAndOverride(Public, context) ||\n this.reflector.getAllAndOverride(OptionalAuth, context))\n )\n return true;\n throw new UnauthorizedException('Authentication required');\n }\n beginAuthRequest(context);\n if (this.reflector.getAllAndOverride(Public, context)) return true;\n\n const raw = await this.auth.api.getSession({ headers: context.getRequest().headers });\n const data = validateSessionData(raw);\n if (data) {\n authenticateRequest(context, data, this.opts.issuer ?? 'better-auth');\n return true;\n }\n if (this.reflector.getAllAndOverride(OptionalAuth, context)) return true;\n throw new UnauthorizedException('Authentication required');\n }\n}\n","import { APP_GUARD, defineModule, defineProvider, InjectionToken, type Type } from '@velajs/vela';\nimport { createBetterAuthCatchallController } from './better-auth.controller';\nimport { BetterAuthService, BETTER_AUTH_BUILDER } from './better-auth.service';\nimport { BETTER_AUTH_OPTIONS } from './better-auth.tokens';\nimport type {\n BetterAuthInstance,\n BetterAuthModuleOptions,\n BetterAuthRuntimeOptions,\n BetterAuthStructuralOption,\n} from './better-auth.types';\nimport { AuthGuard } from './guards/auth.guard';\nimport { DEFAULT_BETTER_AUTH_BASE_PATH, normalizeBetterAuthBasePath } from './base-path';\n\nconst MODULE_OPTIONS = new InjectionToken<BetterAuthModuleOptions>(\n 'vela.better-auth.ModuleOptions',\n);\n\n/** Runtime options with defaults applied: what AuthGuard and the upgrade authenticator read. */\nfunction runtimeOptions(options: BetterAuthModuleOptions): Required<BetterAuthRuntimeOptions> {\n const auth: unknown = options.auth;\n if (typeof auth !== 'function' && (typeof auth !== 'object' || auth === null)) {\n throw new TypeError(\n '@velajs/better-auth: options need `auth`, a better-auth instance or a function that builds one',\n );\n }\n const basePath = normalizeBetterAuthBasePath(options.basePath);\n const issuer = options.issuer ?? `better-auth:${basePath}`;\n if (issuer.length === 0 || issuer !== issuer.trim()) {\n throw new Error('@velajs/better-auth: issuer must be a non-empty stable namespace');\n }\n return {\n basePath,\n issuer,\n guard: options.guard ?? 'global',\n mountHandler: options.mountHandler ?? true,\n };\n}\n\n/** The instance itself, or the one its builder function returns. */\nfunction buildAuth(auth: BetterAuthModuleOptions['auth']): BetterAuthInstance {\n return typeof auth === 'function' ? auth() : auth;\n}\n\nconst { ConfigurableModuleClass } = defineModule<\n BetterAuthModuleOptions,\n BetterAuthStructuralOption\n>({\n name: 'BetterAuth',\n optionsToken: MODULE_OPTIONS,\n structural: ['basePath', 'guard', 'mountHandler'],\n // Spelling out a default configures what leaving it out does: one instance.\n defaults: { basePath: DEFAULT_BETTER_AUTH_BASE_PATH, guard: 'global', mountHandler: true },\n setup: ({ OPTIONS, options }) => {\n // Validates the mount path and guard when the module is declared, before bootstrap.\n const basePath = normalizeBetterAuthBasePath(options.basePath);\n const guard = options.guard;\n if (guard !== 'global' && guard !== 'none') {\n throw new Error(\"@velajs/better-auth: guard must be 'global' or 'none'\");\n }\n const controllers: Type[] =\n options.mountHandler === false ? [] : [createBetterAuthCatchallController(basePath)];\n return {\n providers: [\n defineProvider(BETTER_AUTH_OPTIONS, {\n useFactory: (resolved) => runtimeOptions(resolved),\n inject: [OPTIONS],\n }),\n // BetterAuthService calls the builder on first use and caches the\n // instance, so a builder function never runs at bootstrap.\n defineProvider(BETTER_AUTH_BUILDER, {\n useFactory: (resolved) => () => buildAuth(resolved.auth),\n inject: [OPTIONS],\n }),\n BetterAuthService,\n AuthGuard,\n // Fail closed: every route authenticates unless it opts out. AuthGuard\n // declares the `authenticate` phase, so it runs first whatever the\n // import order.\n ...(guard === 'global' ? [defineProvider(APP_GUARD, { useExisting: AuthGuard })] : []),\n ],\n controllers,\n exports: [BetterAuthService, BETTER_AUTH_OPTIONS, AuthGuard],\n };\n },\n});\n\n/**\n * better-auth for Vela: `BetterAuthService`, the catch-all handler under\n * `basePath`, and `AuthGuard`, registered application-wide by default.\n *\n * ```ts\n * BetterAuthModule.forRoot({ auth: betterAuth({ ... }) });\n * BetterAuthModule.forRootAsync({\n * inject: [ENV],\n * useFactory: (env) => ({ auth: () => betterAuth({ database: env.DB }), issuer: 'accounts' }),\n * });\n * ```\n *\n * `basePath`, `mountHandler` and `guard` are structural: `forRootAsync`\n * takes them alongside the factory. The factory runs when the application\n * initializes; an `auth` function it returns runs on first authentication.\n */\nexport class BetterAuthModule extends ConfigurableModuleClass {}\n","import { Inject, Injectable, InjectionToken, Optional } from '@velajs/vela';\nimport type {\n UpgradeAuthenticator,\n WebSocketUpgradeAuthenticationContext,\n WebSocketUpgradeIdentity,\n} from '@velajs/vela/websocket';\nimport { BetterAuthService } from './better-auth.service';\nimport { BETTER_AUTH_OPTIONS } from './better-auth.tokens';\nimport type { BetterAuthRuntimeOptions, Session, User } from './better-auth.types';\nimport { validateSessionData } from './session-data';\n\n/** The validated Better Auth session behind a WebSocket upgrade. */\nexport interface BetterAuthUpgradeSession {\n readonly user: User;\n readonly session: Session;\n}\n\n/**\n * Chooses the tenant a WebSocket connection joins. Returning no tenant (or\n * throwing) refuses the upgrade.\n */\nexport type BetterAuthUpgradeTenantResolver = (\n session: BetterAuthUpgradeSession,\n context: WebSocketUpgradeAuthenticationContext,\n request: Request,\n) => string | undefined | Promise<string | undefined>;\n\n/**\n * Optional tenant resolver for {@link BetterAuthUpgradeAuthenticator}. Provide it\n * in the module that declares the gateway; without one, the session's active\n * organization is the tenant.\n */\nexport const BETTER_AUTH_UPGRADE_TENANT = new InjectionToken<BetterAuthUpgradeTenantResolver>(\n 'vela.better-auth.UpgradeTenant',\n);\n\n/**\n * WebSocket upgrade authenticator backed by the Better Auth session cookie:\n * `@WebSocketGateway({ authenticator: BetterAuthUpgradeAuthenticator })`.\n *\n * The principal uses the `BetterAuthModule` issuer, as `AuthGuard` does for\n * HTTP. The identity expires with the session. Every WebSocket identity carries\n * a tenant, so a session without an active organization is refused unless a\n * {@link BETTER_AUTH_UPGRADE_TENANT} resolver supplies one.\n */\n@Injectable()\nexport class BetterAuthUpgradeAuthenticator implements UpgradeAuthenticator {\n constructor(\n @Inject(BetterAuthService) private readonly auth: BetterAuthService,\n @Inject(BETTER_AUTH_OPTIONS) private readonly options: BetterAuthRuntimeOptions,\n @Optional()\n @Inject(BETTER_AUTH_UPGRADE_TENANT)\n private readonly resolveTenant?: BetterAuthUpgradeTenantResolver,\n ) {}\n\n async authenticate(\n request: Request,\n context: WebSocketUpgradeAuthenticationContext,\n ): Promise<WebSocketUpgradeIdentity | false> {\n const data = validateSessionData(await this.auth.api.getSession({ headers: request.headers }));\n if (!data) return false;\n const tenantId = this.resolveTenant\n ? await this.resolveTenant({ user: data.user, session: data.session }, context, request)\n : data.tenantId;\n if (typeof tenantId !== 'string' || tenantId.length === 0) return false;\n return {\n principal: {\n issuer: this.options.issuer ?? 'better-auth',\n subject: data.user.id,\n principalType: 'user',\n },\n tenantId,\n expiresAtMs: data.session.expiresAt.getTime(),\n };\n }\n}\n","import { createParamDecorator, type ExecutionContext } from '@velajs/vela';\nimport { getAuthRequestState } from '../auth-request-state';\nimport type { User } from '../better-auth.types';\n\nexport const CurrentUser = createParamDecorator(\n (_data: unknown, ctx: ExecutionContext): User | undefined => {\n const state = getAuthRequestState(ctx);\n return state?.user;\n },\n);\n","import { createParamDecorator, type ExecutionContext } from '@velajs/vela';\nimport { getAuthRequestState } from '../auth-request-state';\nimport type { Session } from '../better-auth.types';\n\nexport const CurrentSession = createParamDecorator(\n (_data: unknown, ctx: ExecutionContext): Session | undefined => {\n const state = getAuthRequestState(ctx);\n return state?.session;\n },\n);\n","import type { Identity, PermissionResolver } from '@velajs/authz';\nimport type { User } from './better-auth.types';\n\n/**\n * A better-auth user carrying the optional `role` field contributed by the\n * admin plugin. `role` may be a single role, a comma-separated list, or an\n * array — {@link identityFromUser} normalizes all three.\n */\nexport type AuthUser = Pick<User, 'id'> & { role?: string | string[] | null };\n\n/** Stable issuer namespace used for better-auth session principals. */\nexport const BETTER_AUTH_ISSUER = 'better-auth';\n\nconst normalizeRoles = (role: string | string[] | null | undefined): string[] => {\n if (!role) return [];\n // Strip empty entries and return a fresh array (never alias the caller's\n // input), matching the comma-string path below.\n if (Array.isArray(role)) return role.filter(Boolean);\n return role\n .split(',')\n .map((r) => r.trim())\n .filter(Boolean);\n};\n\n/**\n * Pure authorization projection; this does not authenticate or publish trusted state.\n * Adapts an already verified better-auth user into a stable `@velajs/authz` {@link Identity}.\n * The issuer scopes `user.id` as the `subject`;\n * the admin-plugin `role` field supplies local roles.\n *\n * Fail-closed: a missing user (`null`/`undefined`, i.e. an unauthenticated\n * request) maps to the zero-privilege identity `{ roles: [] }`, so downstream\n * `can()` checks grant nothing.\n */\nexport const identityFromUser = (\n user: AuthUser | null | undefined,\n issuer: string = BETTER_AUTH_ISSUER,\n principalType: 'user' | 'service' = 'user',\n): Identity => {\n if (!user || typeof user.id !== 'string' || user.id.length === 0) return { roles: [] };\n if (issuer.length === 0)\n throw new Error('@velajs/better-auth: identity issuer must be non-empty');\n return {\n issuer,\n subject: user.id,\n principalType,\n roles: normalizeRoles(user.role),\n };\n};\n\n/**\n * The minimal slice of a better-auth access-control role consumed here. Both\n * `createAccessControl(...).newRole(...)` and the standalone `role(...)` return\n * `{ authorize, statements }`; `statements` is the `{ resource: actions[] }`\n * grant map for that role — the only accessor {@link betterAuthAcResolver}\n * reads.\n */\nexport interface BetterAuthAcRole {\n readonly statements: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * Flattens a better-auth AC role's `statements` into `resource:action`\n * permission strings — the granted-side format `@velajs/authz` matches\n * (wildcards included).\n */\nexport const permissionsFromAcRole = (role: BetterAuthAcRole): string[] => {\n const permissions: string[] = [];\n for (const [resource, actions] of Object.entries(role.statements ?? {})) {\n for (const action of actions ?? []) permissions.push(`${resource}:${action}`);\n }\n return permissions;\n};\n\n/**\n * Builds a fail-closed `@velajs/authz` {@link PermissionResolver} from a\n * better-auth access-control role table (`{ roleName: acRole }` — the same map\n * shape passed to better-auth's admin/organization plugins). An identity's\n * `roles` are unioned into their granted permission strings; unknown roles\n * contribute nothing.\n *\n * ```ts\n * const ac = createAccessControl({ posts: ['read', 'write'] });\n * const authz = createAuthz({\n * resolver: betterAuthAcResolver({ editor: ac.newRole({ posts: ['write'] }) }),\n * });\n * await authz.can(identityFromUser(user), 'posts:write');\n * ```\n */\nexport const betterAuthAcResolver = (\n roles: Readonly<Record<string, BetterAuthAcRole>>,\n): PermissionResolver => {\n const grantsByRole = new Map<string, string[]>();\n for (const [name, role] of Object.entries(roles)) {\n grantsByRole.set(name, permissionsFromAcRole(role));\n }\n return {\n grants(identity: Identity): Set<string> {\n const out = new Set<string>();\n for (const name of identity.roles ?? []) {\n for (const permission of grantsByRole.get(name) ?? []) out.add(permission);\n }\n return out;\n },\n };\n};\n"],"mappings":";;;;;AAEA,MAAa,SAAS,UAAU,gBAAyB,EAAE,KAAK,mBAAmB,CAAC;AACpF,MAAa,aAAa,OAAO;;;ACHjC,MAAa,gCAAgC;;AAG7C,SAAgB,4BAA4B,OAAwB;CAClE,MAAM,WAAW,SAAA;CACjB,IACE,SAAS,WAAW,KACpB,aAAa,SAAS,KAAK,KAC3B,CAAC,SAAS,WAAW,GAAG,KACxB,SAAS,WAAW,IAAI,KACxB,aAAa,OACb,SAAS,SAAS,GAAG,KACrB,WAAW,KAAK,QAAQ,KACxB,kBAAkB,KAAK,QAAQ,GAE/B,MAAM,IAAI,MACR,uFACF;CAGF,IAAI;CACJ,IAAI;EACF,UAAU,mBAAmB,QAAQ;CACvC,QAAQ;EACN,MAAM,IAAI,MAAM,iEAAiE;CACnF;CACA,IAAI,QAAQ,MAAM,GAAG,CAAC,CAAC,MAAM,YAAY,YAAY,OAAO,YAAY,IAAI,GAC1E,MAAM,IAAI,MAAM,6DAA6D;CAE/E,OAAO;AACT;;;ACtBA,MAAM,8BAAc,IAAI,IAAkB;;;;;;;;;;;;;;;AAgB1C,SAAgB,mCAAmC,WAAmB,aAAmB;CACvF,MAAM,qBAAqB,4BAA4B,QAAQ;CAC/D,MAAM,WAAW,YAAY,IAAI,kBAAkB;CACnD,IAAI,UAAU,OAAO;CAGrB,IAGM,+BAHN,MAGM,6BAA6B;EAIuB;EAAxD,YAAY,MAAqE;GAAzB,KAAA,OAAA;EAA0B;EAElF,MACM,OAAO,SAA4C;GACvD,OAAO,KAAK,KAAK,QAAQ,OA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GACpB,MAAM,IAAI,MAAM,wDAAwD;CAC1E,OAAO;EACL;EACA,SAAS,KAAK;EACd;EACA,OAAO,eAAe,KAAK,IAAI;CACjC;AACF;;;;;;AAkBA,MAAa,yBAAyB,SAAqC;CACzE,MAAM,cAAwB,CAAC;CAC/B,KAAK,MAAM,CAAC,UAAU,YAAY,OAAO,QAAQ,KAAK,cAAc,CAAC,CAAC,GACpE,KAAK,MAAM,UAAU,WAAW,CAAC,GAAG,YAAY,KAAK,GAAG,SAAS,GAAG,QAAQ;CAE9E,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,MAAa,wBACX,UACuB;CACvB,MAAM,+BAAe,IAAI,IAAsB;CAC/C,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,KAAK,GAC7C,aAAa,IAAI,MAAM,sBAAsB,IAAI,CAAC;CAEpD,OAAO,EACL,OAAO,UAAiC;EACtC,MAAM,sBAAM,IAAI,IAAY;EAC5B,KAAK,MAAM,QAAQ,SAAS,SAAS,CAAC,GACpC,KAAK,MAAM,cAAc,aAAa,IAAI,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI,UAAU;EAE3E,OAAO;CACT,EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/decorators/public.decorator.ts","../src/base-path.ts","../src/better-auth.controller.ts","../src/better-auth.tokens.ts","../src/auth-request-state.ts","../src/session-data.ts","../src/decorators/optional-auth.decorator.ts","../src/guards/auth.guard.ts","../src/better-auth.module.ts","../src/upgrade-authenticator.ts","../src/decorators/current-user.decorator.ts","../src/decorators/current-session.decorator.ts","../src/authz-bridge.ts"],"sourcesContent":["import { Reflector } from '@velajs/vela';\n\nexport const Public = Reflector.createDecorator<boolean>({ key: 'vela.auth.public' });\nexport const PUBLIC_KEY = Public.KEY;\n","export const DEFAULT_BETTER_AUTH_BASE_PATH = '/api/auth';\n\n/** Validate and canonicalize the route prefix used by the public auth controller. */\nexport function normalizeBetterAuthBasePath(value?: string): string {\n const basePath = value ?? DEFAULT_BETTER_AUTH_BASE_PATH;\n if (\n basePath.length === 0 ||\n basePath !== basePath.trim() ||\n !basePath.startsWith('/') ||\n basePath.startsWith('//') ||\n basePath === '/' ||\n basePath.endsWith('/') ||\n /[\\\\?#*]/u.test(basePath) ||\n /%(?:2e|2f|5c)/iu.test(basePath)\n ) {\n throw new Error(\n '@velajs/better-auth: basePath must be a canonical absolute path such as \"/api/auth\"',\n );\n }\n\n let decoded: string;\n try {\n decoded = decodeURIComponent(basePath);\n } catch {\n throw new Error('@velajs/better-auth: basePath contains invalid percent encoding');\n }\n if (decoded.split('/').some((segment) => segment === '.' || segment === '..')) {\n throw new Error('@velajs/better-auth: basePath must not contain dot segments');\n }\n return basePath;\n}\n","import { All, Controller, Inject, Req, type Type } from '@velajs/vela';\nimport { SkipGuardPhases } from '@velajs/vela/module-kit';\nimport { BetterAuthService } from './better-auth.service';\nimport { Public } from './decorators/public.decorator';\nimport { normalizeBetterAuthBasePath } from './base-path';\n\n// One decorated class per base path: every registration of a path, and every\n// call, shares it (the class reads nothing else).\nconst controllers = new Map<string, Type>();\n\n/**\n * Build a catch-all controller that mounts better-auth's handler at `basePath`\n * (default `/api/auth`). This is a factory because vela reads a controller's\n * route off the class at decoration time, so a custom base path needs its own\n * decorated class — the path can't be parametrized on a single shared class.\n * Calls with the same base path return the same class.\n *\n * Two base paths to keep consistent:\n * - this `basePath` is RELATIVE to vela's `globalPrefix` (always prepended);\n * - better-auth routes against its OWN absolute `basePath` (the one you pass to\n * `betterAuth({ basePath })`), which must equal `globalPrefix + basePath`.\n *\n * Both default to `/api/auth`, so the no-prefix / no-config case just works.\n */\nexport function createBetterAuthCatchallController(basePath: string = '/api/auth'): Type {\n const normalizedBasePath = normalizeBetterAuthBasePath(basePath);\n const existing = controllers.get(normalizedBasePath);\n if (existing) return existing;\n // Better Auth authenticates its own endpoints; application-wide tenant\n // admission and authorization do not apply to signing in.\n @Public(true)\n @SkipGuardPhases(['tenant', 'authorize'])\n @Controller(normalizedBasePath)\n class BetterAuthCatchallController {\n // Inject the service — its `.handler` getter triggers lazy construction\n // of the underlying betterAuth() instance on first access, AFTER any\n // runtime adapter middleware (Cloudflare env capture) has run.\n constructor(@Inject(BetterAuthService) private readonly auth: BetterAuthService) {}\n\n @All('/*')\n async handle(@Req() request: Request): Promise<Response> {\n return this.auth.handler(request);\n }\n }\n controllers.set(normalizedBasePath, BetterAuthCatchallController);\n return BetterAuthCatchallController;\n}\n","import { InjectionToken } from '@velajs/vela';\nimport type { BetterAuthRuntimeOptions } from './better-auth.types';\n\nexport const BETTER_AUTH_OPTIONS = new InjectionToken<BetterAuthRuntimeOptions>(\n 'vela.BetterAuthOptions',\n);\n","import type { ExecutionContext } from '@velajs/vela';\nimport {\n clearTrustedRequestIdentity,\n createTrustedRequestIdentityStore,\n getTrustedContextRequest,\n setTrustedRequestIdentity,\n} from '@velajs/vela/module-kit';\nimport type { SessionData } from './session-data';\n\n// This map stores provider payload, never a second authentication authority.\n// A clear, expiry, or identity replacement makes the payload unreachable.\nconst sessions = createTrustedRequestIdentityStore<SessionData>();\n\nexport function beginAuthRequest(context: ExecutionContext): void {\n clearTrustedRequestIdentity(context.getRequest());\n}\n\nexport function authenticateRequest(\n context: ExecutionContext,\n data: SessionData,\n issuer: string,\n): void {\n const request = context.getRequest();\n setTrustedRequestIdentity(request, {\n principal: { issuer, subject: data.user.id, principalType: 'user' },\n expiresAtMs: data.session.expiresAt.getTime(),\n roles: data.roles,\n ...(data.tenantId === undefined ? {} : { tenantId: data.tenantId }),\n });\n sessions.set(request, data);\n}\n\nexport function getAuthRequestState(context: ExecutionContext): SessionData | undefined {\n const request = getTrustedContextRequest(context);\n return request ? sessions.get(request) : undefined;\n}\n","import type { Session, User } from './better-auth.types';\n\nexport interface SessionData {\n readonly user: User;\n readonly session: Session;\n readonly roles: readonly string[];\n readonly tenantId?: string;\n}\n\nfunction own(value: unknown, key: string): unknown {\n if (typeof value !== 'object' || value === null) return undefined;\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n return descriptor && 'value' in descriptor ? descriptor.value : undefined;\n}\n\nfunction requiredString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0;\n}\n\nfunction date(value: unknown): Date | undefined {\n return value instanceof Date && Number.isFinite(value.getTime()) ? new Date(value) : undefined;\n}\n\nfunction optionalString(value: unknown): value is string | null | undefined {\n return value === undefined || value === null || typeof value === 'string';\n}\n\n/** Keep plugin data opaque; base model fields below are validated individually. */\nfunction dataProperties(value: object): Record<string, unknown> {\n return Object.fromEntries(Object.keys(value).map((key) => [key, own(value, key)]));\n}\n\n/** Validate the full Better Auth base models, not merely ids masquerading as them. */\nexport function validateSessionData(value: unknown): SessionData | undefined {\n try {\n const user = own(value, 'user');\n const session = own(value, 'session');\n if (\n typeof user !== 'object' ||\n user === null ||\n typeof session !== 'object' ||\n session === null\n ) {\n return undefined;\n }\n const id = own(user, 'id');\n const email = own(user, 'email');\n const name = own(user, 'name');\n const emailVerified = own(user, 'emailVerified');\n const image = own(user, 'image');\n const createdAt = date(own(user, 'createdAt'));\n const updatedAt = date(own(user, 'updatedAt'));\n const sessionId = own(session, 'id');\n const userId = own(session, 'userId');\n const token = own(session, 'token');\n const sessionCreatedAt = date(own(session, 'createdAt'));\n const sessionUpdatedAt = date(own(session, 'updatedAt'));\n const expiresAt = date(own(session, 'expiresAt'));\n const ipAddress = own(session, 'ipAddress');\n const userAgent = own(session, 'userAgent');\n const organization = own(session, 'activeOrganizationId');\n const role = own(user, 'role');\n let roles: string[] = [];\n if (role !== undefined && role !== null) {\n if (typeof role === 'string')\n roles = role\n .split(',')\n .map((part) => part.trim())\n .filter(Boolean);\n else if (\n Array.isArray(role) &&\n role.every((entry: unknown): entry is string => typeof entry === 'string')\n ) {\n roles = role.map((entry: string) => entry.trim()).filter(Boolean);\n } else return undefined;\n }\n if (\n !requiredString(id) ||\n !requiredString(email) ||\n typeof name !== 'string' ||\n typeof emailVerified !== 'boolean' ||\n !optionalString(image) ||\n !createdAt ||\n !updatedAt ||\n !requiredString(sessionId) ||\n userId !== id ||\n !requiredString(token) ||\n !sessionCreatedAt ||\n !sessionUpdatedAt ||\n !expiresAt ||\n expiresAt.getTime() <= Date.now() ||\n !optionalString(ipAddress) ||\n !optionalString(userAgent) ||\n (organization !== undefined && organization !== null && !requiredString(organization))\n )\n return undefined;\n return {\n user: Object.freeze({\n ...dataProperties(user),\n id,\n email,\n name,\n emailVerified,\n createdAt,\n updatedAt,\n image,\n }),\n session: Object.freeze({\n ...dataProperties(session),\n id: sessionId,\n userId: id,\n token,\n createdAt: sessionCreatedAt,\n updatedAt: sessionUpdatedAt,\n expiresAt,\n ipAddress,\n userAgent,\n }),\n roles: Object.freeze(roles),\n ...(typeof organization === 'string' ? { tenantId: organization } : {}),\n };\n } catch {\n return undefined;\n }\n}\n","import { Reflector } from '@velajs/vela';\n\nexport const OptionalAuth = Reflector.createDecorator<boolean>({ key: 'vela.auth.optional' });\nexport const OPTIONAL_AUTH_KEY = OptionalAuth.KEY;\n","import {\n Inject,\n Injectable,\n Reflector,\n UnauthorizedException,\n type CanActivate,\n type ExecutionContext,\n type GuardPhase,\n} from '@velajs/vela';\nimport { getTrustedContextRequest } from '@velajs/vela/module-kit';\nimport { getContextIdentity } from '@velajs/authz/vela';\nimport { BETTER_AUTH_OPTIONS } from '../better-auth.tokens';\nimport { BetterAuthService } from '../better-auth.service';\nimport type { BetterAuthRuntimeOptions } from '../better-auth.types';\nimport { authenticateRequest, beginAuthRequest, getAuthRequestState } from '../auth-request-state';\nimport { validateSessionData } from '../session-data';\nimport { OptionalAuth } from '../decorators/optional-auth.decorator';\nimport { Public } from '../decorators/public.decorator';\n\n@Injectable()\nexport class AuthGuard implements CanActivate {\n /** Global guards run authentication first, then tenant, authorization and feature phases. */\n static readonly phase: GuardPhase = 'authenticate';\n\n constructor(\n @Inject(BetterAuthService) private readonly auth: BetterAuthService,\n @Inject(BETTER_AUTH_OPTIONS) private readonly opts: BetterAuthRuntimeOptions,\n @Inject(Reflector) private readonly reflector: Reflector,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n // Frames trust only the authenticated connection attachment; HTTP cookies\n // and request payload never become ambient WebSocket authentication.\n if (context.getType() === 'ws') {\n if (getContextIdentity(context)) return true;\n throw new UnauthorizedException('Authentication required');\n }\n // Custom HTTP-backed dispatchers authenticate once at the outer boundary.\n // Never re-read credentials or clear shared authority across sibling fields.\n if (context.getType() !== 'http') {\n if (\n getTrustedContextRequest(context) &&\n (getAuthRequestState(context) ||\n this.reflector.getAllAndOverride(Public, context) ||\n this.reflector.getAllAndOverride(OptionalAuth, context))\n )\n return true;\n throw new UnauthorizedException('Authentication required');\n }\n beginAuthRequest(context);\n if (this.reflector.getAllAndOverride(Public, context)) return true;\n\n const raw = await this.auth.api.getSession({ headers: context.getRequest().headers });\n const data = validateSessionData(raw);\n if (data) {\n authenticateRequest(context, data, this.opts.issuer ?? 'better-auth');\n return true;\n }\n if (this.reflector.getAllAndOverride(OptionalAuth, context)) return true;\n throw new UnauthorizedException('Authentication required');\n }\n}\n","import { defineModule, defineProvider, InjectionToken, type Type } from '@velajs/vela';\nimport { createBetterAuthCatchallController } from './better-auth.controller';\nimport { BetterAuthService, BETTER_AUTH_BUILDER } from './better-auth.service';\nimport { BETTER_AUTH_OPTIONS } from './better-auth.tokens';\nimport type {\n BetterAuthInstance,\n BetterAuthModuleOptions,\n BetterAuthRuntimeOptions,\n BetterAuthStructuralOption,\n} from './better-auth.types';\nimport { AuthGuard } from './guards/auth.guard';\nimport { DEFAULT_BETTER_AUTH_BASE_PATH, normalizeBetterAuthBasePath } from './base-path';\n\nconst MODULE_OPTIONS = new InjectionToken<BetterAuthModuleOptions>(\n 'vela.better-auth.ModuleOptions',\n);\n\n/** Runtime options with defaults applied: what AuthGuard and the upgrade authenticator read. */\nfunction runtimeOptions(options: BetterAuthModuleOptions): Required<BetterAuthRuntimeOptions> {\n const auth: unknown = options.auth;\n if (typeof auth !== 'function' && (typeof auth !== 'object' || auth === null)) {\n throw new TypeError(\n '@velajs/better-auth: options need `auth`, a better-auth instance or a function that builds one',\n );\n }\n const basePath = normalizeBetterAuthBasePath(options.basePath);\n const issuer = options.issuer ?? `better-auth:${basePath}`;\n if (issuer.length === 0 || issuer !== issuer.trim()) {\n throw new Error('@velajs/better-auth: issuer must be a non-empty stable namespace');\n }\n return {\n basePath,\n issuer,\n mountHandler: options.mountHandler ?? true,\n };\n}\n\n/** The instance itself, or the one its builder function returns. */\nfunction buildAuth(auth: BetterAuthModuleOptions['auth']): BetterAuthInstance {\n return typeof auth === 'function' ? auth() : auth;\n}\n\nconst { ConfigurableModuleClass } = defineModule<\n BetterAuthModuleOptions,\n BetterAuthStructuralOption\n>({\n name: 'BetterAuth',\n optionsToken: MODULE_OPTIONS,\n structural: ['basePath', 'mountHandler'],\n // Spelling out a default configures what leaving it out does: one instance.\n defaults: { basePath: DEFAULT_BETTER_AUTH_BASE_PATH, mountHandler: true },\n setup: ({ OPTIONS, options }) => {\n // Validates the mount path when the module is declared, before bootstrap.\n const basePath = normalizeBetterAuthBasePath(options.basePath);\n const controllers: Type[] =\n options.mountHandler === false ? [] : [createBetterAuthCatchallController(basePath)];\n return {\n providers: [\n defineProvider(BETTER_AUTH_OPTIONS, {\n useFactory: (resolved) => runtimeOptions(resolved),\n inject: [OPTIONS],\n }),\n // BetterAuthService calls the builder on first use and caches the\n // instance, so a builder function never runs at bootstrap.\n defineProvider(BETTER_AUTH_BUILDER, {\n useFactory: (resolved) => () => buildAuth(resolved.auth),\n inject: [OPTIONS],\n }),\n BetterAuthService,\n AuthGuard,\n ],\n controllers,\n exports: [BetterAuthService, BETTER_AUTH_OPTIONS, AuthGuard],\n };\n },\n});\n\n/**\n * better-auth for Vela: `BetterAuthService`, the catch-all handler under\n * `basePath`, and an injectable `AuthGuard`. Applications install it through `APP_GUARD`\n * with `useExisting: AuthGuard`, or attach it with `@UseGuards`.\n *\n * ```ts\n * BetterAuthModule.forRoot({ auth: betterAuth({ ... }) });\n * BetterAuthModule.forRootAsync({\n * inject: [ENV],\n * useFactory: (env) => ({ auth: () => betterAuth({ database: env.DB }), issuer: 'accounts' }),\n * });\n * ```\n *\n * `basePath` and `mountHandler` are structural: `forRootAsync`\n * takes them alongside the factory. The factory runs when the application\n * initializes; an `auth` function it returns runs on first authentication.\n */\nexport class BetterAuthModule extends ConfigurableModuleClass {}\n","import { Inject, Injectable, InjectionToken, Optional } from '@velajs/vela';\nimport type {\n UpgradeAuthenticator,\n WebSocketUpgradeAuthenticationContext,\n WebSocketUpgradeIdentity,\n} from '@velajs/vela/websocket';\nimport { BetterAuthService } from './better-auth.service';\nimport { BETTER_AUTH_OPTIONS } from './better-auth.tokens';\nimport type { BetterAuthRuntimeOptions, Session, User } from './better-auth.types';\nimport { validateSessionData } from './session-data';\n\n/** The validated Better Auth session behind a WebSocket upgrade. */\nexport interface BetterAuthUpgradeSession {\n readonly user: User;\n readonly session: Session;\n}\n\n/**\n * Chooses the tenant a WebSocket connection joins. Returning no tenant (or\n * throwing) refuses the upgrade.\n */\nexport type BetterAuthUpgradeTenantResolver = (\n session: BetterAuthUpgradeSession,\n context: WebSocketUpgradeAuthenticationContext,\n request: Request,\n) => string | undefined | Promise<string | undefined>;\n\n/**\n * Optional tenant resolver for {@link BetterAuthUpgradeAuthenticator}. Provide it\n * in the module that declares the gateway; without one, the session's active\n * organization is the tenant.\n */\nexport const BETTER_AUTH_UPGRADE_TENANT = new InjectionToken<BetterAuthUpgradeTenantResolver>(\n 'vela.better-auth.UpgradeTenant',\n);\n\n/**\n * WebSocket upgrade authenticator backed by the Better Auth session cookie:\n * `@WebSocketGateway({ authenticator: BetterAuthUpgradeAuthenticator })`.\n *\n * The principal uses the `BetterAuthModule` issuer, as `AuthGuard` does for\n * HTTP. The identity expires with the session. Every WebSocket identity carries\n * a tenant, so a session without an active organization is refused unless a\n * {@link BETTER_AUTH_UPGRADE_TENANT} resolver supplies one.\n */\n@Injectable()\nexport class BetterAuthUpgradeAuthenticator implements UpgradeAuthenticator {\n constructor(\n @Inject(BetterAuthService) private readonly auth: BetterAuthService,\n @Inject(BETTER_AUTH_OPTIONS) private readonly options: BetterAuthRuntimeOptions,\n @Optional()\n @Inject(BETTER_AUTH_UPGRADE_TENANT)\n private readonly resolveTenant?: BetterAuthUpgradeTenantResolver,\n ) {}\n\n async authenticate(\n request: Request,\n context: WebSocketUpgradeAuthenticationContext,\n ): Promise<WebSocketUpgradeIdentity | false> {\n const data = validateSessionData(await this.auth.api.getSession({ headers: request.headers }));\n if (!data) return false;\n const tenantId = this.resolveTenant\n ? await this.resolveTenant({ user: data.user, session: data.session }, context, request)\n : data.tenantId;\n if (typeof tenantId !== 'string' || tenantId.length === 0) return false;\n return {\n principal: {\n issuer: this.options.issuer ?? 'better-auth',\n subject: data.user.id,\n principalType: 'user',\n },\n tenantId,\n expiresAtMs: data.session.expiresAt.getTime(),\n };\n }\n}\n","import { createParamDecorator, type ExecutionContext } from '@velajs/vela';\nimport { getAuthRequestState } from '../auth-request-state';\nimport type { User } from '../better-auth.types';\n\nexport const CurrentUser = createParamDecorator(\n (_data: unknown, ctx: ExecutionContext): User | undefined => {\n const state = getAuthRequestState(ctx);\n return state?.user;\n },\n);\n","import { createParamDecorator, type ExecutionContext } from '@velajs/vela';\nimport { getAuthRequestState } from '../auth-request-state';\nimport type { Session } from '../better-auth.types';\n\nexport const CurrentSession = createParamDecorator(\n (_data: unknown, ctx: ExecutionContext): Session | undefined => {\n const state = getAuthRequestState(ctx);\n return state?.session;\n },\n);\n","import type { Identity, PermissionResolver } from '@velajs/authz';\nimport type { User } from './better-auth.types';\n\n/**\n * A better-auth user carrying the optional `role` field contributed by the\n * admin plugin. `role` may be a single role, a comma-separated list, or an\n * array — {@link identityFromUser} normalizes all three.\n */\nexport type AuthUser = Pick<User, 'id'> & { role?: string | string[] | null };\n\n/** Stable issuer namespace used for better-auth session principals. */\nexport const BETTER_AUTH_ISSUER = 'better-auth';\n\nconst normalizeRoles = (role: string | string[] | null | undefined): string[] => {\n if (!role) return [];\n // Strip empty entries and return a fresh array (never alias the caller's\n // input), matching the comma-string path below.\n if (Array.isArray(role)) return role.filter(Boolean);\n return role\n .split(',')\n .map((r) => r.trim())\n .filter(Boolean);\n};\n\n/**\n * Pure authorization projection; this does not authenticate or publish trusted state.\n * Adapts an already verified better-auth user into a stable `@velajs/authz` {@link Identity}.\n * The issuer scopes `user.id` as the `subject`;\n * the admin-plugin `role` field supplies local roles.\n *\n * Fail-closed: a missing user (`null`/`undefined`, i.e. an unauthenticated\n * request) maps to the zero-privilege identity `{ roles: [] }`, so downstream\n * `can()` checks grant nothing.\n */\nexport const identityFromUser = (\n user: AuthUser | null | undefined,\n issuer: string = BETTER_AUTH_ISSUER,\n principalType: 'user' | 'service' = 'user',\n): Identity => {\n if (!user || typeof user.id !== 'string' || user.id.length === 0) return { roles: [] };\n if (issuer.length === 0)\n throw new Error('@velajs/better-auth: identity issuer must be non-empty');\n return {\n issuer,\n subject: user.id,\n principalType,\n roles: normalizeRoles(user.role),\n };\n};\n\n/**\n * The minimal slice of a better-auth access-control role consumed here. Both\n * `createAccessControl(...).newRole(...)` and the standalone `role(...)` return\n * `{ authorize, statements }`; `statements` is the `{ resource: actions[] }`\n * grant map for that role — the only accessor {@link betterAuthAcResolver}\n * reads.\n */\nexport interface BetterAuthAcRole {\n readonly statements: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * Flattens a better-auth AC role's `statements` into `resource:action`\n * permission strings — the granted-side format `@velajs/authz` matches\n * (wildcards included).\n */\nexport const permissionsFromAcRole = (role: BetterAuthAcRole): string[] => {\n const permissions: string[] = [];\n for (const [resource, actions] of Object.entries(role.statements ?? {})) {\n for (const action of actions ?? []) permissions.push(`${resource}:${action}`);\n }\n return permissions;\n};\n\n/**\n * Builds a fail-closed `@velajs/authz` {@link PermissionResolver} from a\n * better-auth access-control role table (`{ roleName: acRole }` — the same map\n * shape passed to better-auth's admin/organization plugins). An identity's\n * `roles` are unioned into their granted permission strings; unknown roles\n * contribute nothing.\n *\n * ```ts\n * const ac = createAccessControl({ posts: ['read', 'write'] });\n * const authz = createAuthz({\n * resolver: betterAuthAcResolver({ editor: ac.newRole({ posts: ['write'] }) }),\n * });\n * await authz.can(identityFromUser(user), 'posts:write');\n * ```\n */\nexport const betterAuthAcResolver = (\n roles: Readonly<Record<string, BetterAuthAcRole>>,\n): PermissionResolver => {\n const grantsByRole = new Map<string, string[]>();\n for (const [name, role] of Object.entries(roles)) {\n grantsByRole.set(name, permissionsFromAcRole(role));\n }\n return {\n grants(identity: Identity): Set<string> {\n const out = new Set<string>();\n for (const name of identity.roles ?? []) {\n for (const permission of grantsByRole.get(name) ?? []) out.add(permission);\n }\n return out;\n },\n };\n};\n"],"mappings":";;;;;AAEA,MAAa,SAAS,UAAU,gBAAyB,EAAE,KAAK,mBAAmB,CAAC;AACpF,MAAa,aAAa,OAAO;;;ACHjC,MAAa,gCAAgC;;AAG7C,SAAgB,4BAA4B,OAAwB;CAClE,MAAM,WAAW,SAAA;CACjB,IACE,SAAS,WAAW,KACpB,aAAa,SAAS,KAAK,KAC3B,CAAC,SAAS,WAAW,GAAG,KACxB,SAAS,WAAW,IAAI,KACxB,aAAa,OACb,SAAS,SAAS,GAAG,KACrB,WAAW,KAAK,QAAQ,KACxB,kBAAkB,KAAK,QAAQ,GAE/B,MAAM,IAAI,MACR,uFACF;CAGF,IAAI;CACJ,IAAI;EACF,UAAU,mBAAmB,QAAQ;CACvC,QAAQ;EACN,MAAM,IAAI,MAAM,iEAAiE;CACnF;CACA,IAAI,QAAQ,MAAM,GAAG,CAAC,CAAC,MAAM,YAAY,YAAY,OAAO,YAAY,IAAI,GAC1E,MAAM,IAAI,MAAM,6DAA6D;CAE/E,OAAO;AACT;;;ACtBA,MAAM,8BAAc,IAAI,IAAkB;;;;;;;;;;;;;;;AAgB1C,SAAgB,mCAAmC,WAAmB,aAAmB;CACvF,MAAM,qBAAqB,4BAA4B,QAAQ;CAC/D,MAAM,WAAW,YAAY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;CAC1E,OAAO;EACL;EACA,SAAS,KAAK;EACd;EACA,OAAO,eAAe,KAAK,IAAI;CACjC;AACF;;;;;;AAkBA,MAAa,yBAAyB,SAAqC;CACzE,MAAM,cAAwB,CAAC;CAC/B,KAAK,MAAM,CAAC,UAAU,YAAY,OAAO,QAAQ,KAAK,cAAc,CAAC,CAAC,GACpE,KAAK,MAAM,UAAU,WAAW,CAAC,GAAG,YAAY,KAAK,GAAG,SAAS,GAAG,QAAQ;CAE9E,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,MAAa,wBACX,UACuB;CACvB,MAAM,+BAAe,IAAI,IAAsB;CAC/C,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,KAAK,GAC7C,aAAa,IAAI,MAAM,sBAAsB,IAAI,CAAC;CAEpD,OAAO,EACL,OAAO,UAAiC;EACtC,MAAM,sBAAM,IAAI,IAAY;EAC5B,KAAK,MAAM,QAAQ,SAAS,SAAS,CAAC,GACpC,KAAK,MAAM,cAAc,aAAa,IAAI,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI,UAAU;EAE3E,OAAO;CACT,EACF;AACF"}
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as BetterAuthService } from "../better-auth.service-
|
|
1
|
+
import { t as BetterAuthService } from "../better-auth.service-D_G-PP8p.js";
|
|
2
2
|
//#region src/testing/acting-as.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The slice of `@velajs/testing`'s `TestingModule` this resolver depends on.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velajs/better-auth",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "better-auth integration for the Vela framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@velajs/authz": "1.
|
|
50
|
+
"@velajs/authz": "1.33.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@arethetypeswrong/cli": "0.18.5",
|
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
"unplugin-swc": "1.5.9",
|
|
64
64
|
"vite": "^8.0.16",
|
|
65
65
|
"vitest": "4.1.11",
|
|
66
|
-
"@velajs/
|
|
67
|
-
"@velajs/
|
|
68
|
-
"@velajs/
|
|
66
|
+
"@velajs/testing": "1.34.0",
|
|
67
|
+
"@velajs/vela": "1.35.0",
|
|
68
|
+
"@velajs/tenant": "1.33.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"better-auth": ">=1.2.0",
|
|
72
72
|
"hono": ">=4",
|
|
73
|
-
"@velajs/vela": "^1.
|
|
73
|
+
"@velajs/vela": "^1.35.0"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=24"
|