@veloxts/auth 0.3.3 → 0.3.5
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/README.md +1157 -30
- package/dist/__integration__/fixtures.d.ts +41 -0
- package/dist/__integration__/fixtures.d.ts.map +1 -0
- package/dist/__integration__/fixtures.js +79 -0
- package/dist/__integration__/fixtures.js.map +1 -0
- package/dist/__integration__/setup.d.ts +26 -0
- package/dist/__integration__/setup.d.ts.map +1 -0
- package/dist/__integration__/setup.js +28 -0
- package/dist/__integration__/setup.js.map +1 -0
- package/dist/adapter.d.ts +710 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +581 -0
- package/dist/adapter.js.map +1 -0
- package/dist/adapters/better-auth.d.ts +271 -0
- package/dist/adapters/better-auth.d.ts.map +1 -0
- package/dist/adapters/better-auth.js +341 -0
- package/dist/adapters/better-auth.js.map +1 -0
- package/dist/adapters/index.d.ts +28 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +28 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/csrf.d.ts +300 -0
- package/dist/csrf.d.ts.map +1 -0
- package/dist/csrf.js +402 -0
- package/dist/csrf.js.map +1 -0
- package/dist/guards.d.ts +142 -0
- package/dist/guards.d.ts.map +1 -0
- package/dist/guards.js +259 -0
- package/dist/guards.js.map +1 -0
- package/dist/hash.d.ts +91 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +236 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +27 -32
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +94 -36
- package/dist/index.js.map +1 -1
- package/dist/jwt.d.ts +157 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +489 -0
- package/dist/jwt.js.map +1 -0
- package/dist/middleware.d.ts +99 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +253 -0
- package/dist/middleware.js.map +1 -0
- package/dist/plugin.d.ts +125 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +193 -0
- package/dist/plugin.js.map +1 -0
- package/dist/policies.d.ts +137 -0
- package/dist/policies.d.ts.map +1 -0
- package/dist/policies.js +240 -0
- package/dist/policies.js.map +1 -0
- package/dist/rate-limit.d.ts +231 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +352 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/session.d.ts +500 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +801 -0
- package/dist/session.js.map +1 -0
- package/dist/types.d.ts +261 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -7
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test fixtures and helpers
|
|
3
|
+
* @module __integration__/fixtures
|
|
4
|
+
*/
|
|
5
|
+
import { TEST_SECRETS } from '@veloxts/testing';
|
|
6
|
+
import type { User } from '../types.js';
|
|
7
|
+
export { TEST_SECRETS };
|
|
8
|
+
export declare const TEST_USERS: Record<string, User>;
|
|
9
|
+
/**
|
|
10
|
+
* Mock user loader for tests
|
|
11
|
+
*/
|
|
12
|
+
export declare function testUserLoader(userId: string): Promise<User | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Auth config with user loader (for tests that use TEST_USERS)
|
|
15
|
+
*/
|
|
16
|
+
export declare function createTestAuthConfig(): {
|
|
17
|
+
jwt: {
|
|
18
|
+
secret: "test-access-secret-key-for-integration-tests-must-be-64-characters-long-at-minimum-for-hmac";
|
|
19
|
+
refreshSecret: "test-refresh-secret-key-for-integration-tests-must-be-64-characters-long-at-minimum-for-hmac";
|
|
20
|
+
accessTokenExpiry: string;
|
|
21
|
+
refreshTokenExpiry: string;
|
|
22
|
+
issuer: string;
|
|
23
|
+
audience: string;
|
|
24
|
+
};
|
|
25
|
+
userLoader: typeof testUserLoader;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Auth config without user loader (for tests with ad-hoc users)
|
|
29
|
+
* User info comes directly from token claims
|
|
30
|
+
*/
|
|
31
|
+
export declare function createTestAuthConfigNoLoader(): {
|
|
32
|
+
jwt: {
|
|
33
|
+
secret: "test-access-secret-key-for-integration-tests-must-be-64-characters-long-at-minimum-for-hmac";
|
|
34
|
+
refreshSecret: "test-refresh-secret-key-for-integration-tests-must-be-64-characters-long-at-minimum-for-hmac";
|
|
35
|
+
accessTokenExpiry: string;
|
|
36
|
+
refreshTokenExpiry: string;
|
|
37
|
+
issuer: string;
|
|
38
|
+
audience: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=fixtures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../src/__integration__/fixtures.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,CAAC;AAMxB,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAqB3C,CAAC;AAMF;;GAEG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAGzE;AAMD;;GAEG;AACH,wBAAgB,oBAAoB;;;;;;;;;;EAYnC;AAED;;;GAGG;AACH,wBAAgB,4BAA4B;;;;;;;;;EAY3C"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test fixtures and helpers
|
|
3
|
+
* @module __integration__/fixtures
|
|
4
|
+
*/
|
|
5
|
+
import { TEST_SECRETS } from '@veloxts/testing';
|
|
6
|
+
// Re-export shared test secrets
|
|
7
|
+
export { TEST_SECRETS };
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Test Users
|
|
10
|
+
// ============================================================================
|
|
11
|
+
export const TEST_USERS = {
|
|
12
|
+
admin: {
|
|
13
|
+
id: 'user-admin-123',
|
|
14
|
+
email: 'admin@example.com',
|
|
15
|
+
roles: ['admin'],
|
|
16
|
+
},
|
|
17
|
+
user: {
|
|
18
|
+
id: 'user-regular-456',
|
|
19
|
+
email: 'user@example.com',
|
|
20
|
+
roles: ['user'],
|
|
21
|
+
},
|
|
22
|
+
guest: {
|
|
23
|
+
id: 'user-guest-789',
|
|
24
|
+
email: 'guest@example.com',
|
|
25
|
+
roles: [], // Empty roles - tests guard failure
|
|
26
|
+
},
|
|
27
|
+
multiRole: {
|
|
28
|
+
id: 'user-multi-101',
|
|
29
|
+
email: 'multi@example.com',
|
|
30
|
+
roles: ['user', 'editor', 'moderator'],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// User Loader
|
|
35
|
+
// ============================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Mock user loader for tests
|
|
38
|
+
*/
|
|
39
|
+
export async function testUserLoader(userId) {
|
|
40
|
+
const user = Object.values(TEST_USERS).find((u) => u.id === userId);
|
|
41
|
+
return user ?? null;
|
|
42
|
+
}
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// Auth Config Factory
|
|
45
|
+
// ============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* Auth config with user loader (for tests that use TEST_USERS)
|
|
48
|
+
*/
|
|
49
|
+
export function createTestAuthConfig() {
|
|
50
|
+
return {
|
|
51
|
+
jwt: {
|
|
52
|
+
secret: TEST_SECRETS.access,
|
|
53
|
+
refreshSecret: TEST_SECRETS.refresh,
|
|
54
|
+
accessTokenExpiry: '15m',
|
|
55
|
+
refreshTokenExpiry: '7d',
|
|
56
|
+
issuer: 'velox-test',
|
|
57
|
+
audience: 'velox-test-app',
|
|
58
|
+
},
|
|
59
|
+
userLoader: testUserLoader,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Auth config without user loader (for tests with ad-hoc users)
|
|
64
|
+
* User info comes directly from token claims
|
|
65
|
+
*/
|
|
66
|
+
export function createTestAuthConfigNoLoader() {
|
|
67
|
+
return {
|
|
68
|
+
jwt: {
|
|
69
|
+
secret: TEST_SECRETS.access,
|
|
70
|
+
refreshSecret: TEST_SECRETS.refresh,
|
|
71
|
+
accessTokenExpiry: '15m',
|
|
72
|
+
refreshTokenExpiry: '7d',
|
|
73
|
+
issuer: 'velox-test',
|
|
74
|
+
audience: 'velox-test-app',
|
|
75
|
+
},
|
|
76
|
+
// No userLoader - user info comes from token
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=fixtures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../src/__integration__/fixtures.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,gCAAgC;AAChC,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,MAAM,CAAC,MAAM,UAAU,GAAyB;IAC9C,KAAK,EAAE;QACL,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,CAAC,OAAO,CAAC;KACjB;IACD,IAAI,EAAE;QACJ,EAAE,EAAE,kBAAkB;QACtB,KAAK,EAAE,kBAAkB;QACzB,KAAK,EAAE,CAAC,MAAM,CAAC;KAChB;IACD,KAAK,EAAE;QACL,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,EAAE,EAAE,oCAAoC;KAChD;IACD,SAAS,EAAE;QACT,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC;KACvC;CACF,CAAC;AAEF,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAc;IACjD,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;IACpE,OAAO,IAAI,IAAI,IAAI,CAAC;AACtB,CAAC;AAED,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,GAAG,EAAE;YACH,MAAM,EAAE,YAAY,CAAC,MAAM;YAC3B,aAAa,EAAE,YAAY,CAAC,OAAO;YACnC,iBAAiB,EAAE,KAAK;YACxB,kBAAkB,EAAE,IAAI;YACxB,MAAM,EAAE,YAAY;YACpB,QAAQ,EAAE,gBAAgB;SAC3B;QACD,UAAU,EAAE,cAAc;KAC3B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,GAAG,EAAE;YACH,MAAM,EAAE,YAAY,CAAC,MAAM;YAC3B,aAAa,EAAE,YAAY,CAAC,OAAO;YACnC,iBAAiB,EAAE,KAAK;YACxB,kBAAkB,EAAE,IAAI;YACxB,MAAM,EAAE,YAAY;YACpB,QAAQ,EAAE,gBAAgB;SAC3B;QACD,6CAA6C;KAC9C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test setup utilities
|
|
3
|
+
* @module __integration__/setup
|
|
4
|
+
*/
|
|
5
|
+
import type { FastifyInstance } from 'fastify';
|
|
6
|
+
import { type AuthPluginOptions } from '../plugin.js';
|
|
7
|
+
export { authHeader } from '@veloxts/testing';
|
|
8
|
+
/**
|
|
9
|
+
* Options for creating a test server
|
|
10
|
+
*/
|
|
11
|
+
export interface TestServerOptions {
|
|
12
|
+
/** Auth plugin options (defaults to test config) */
|
|
13
|
+
authOptions?: AuthPluginOptions;
|
|
14
|
+
/** Skip auth plugin registration */
|
|
15
|
+
skipAuth?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates a Fastify server configured for integration testing
|
|
19
|
+
*
|
|
20
|
+
* This sets up:
|
|
21
|
+
* - Request context decoration (mimics VeloxApp behavior)
|
|
22
|
+
* - Auth plugin with test configuration
|
|
23
|
+
* - Logging disabled for cleaner test output
|
|
24
|
+
*/
|
|
25
|
+
export declare function createTestServer(options?: TestServerOptions): Promise<FastifyInstance>;
|
|
26
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__integration__/setup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,EAAE,KAAK,iBAAiB,EAAc,MAAM,cAAc,CAAC;AAIlE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAM9C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,oDAAoD;IACpD,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAYhG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test setup utilities
|
|
3
|
+
* @module __integration__/setup
|
|
4
|
+
*/
|
|
5
|
+
import { createTestServer as baseCreateTestServer, wrapVeloxPlugin } from '@veloxts/testing';
|
|
6
|
+
import { authPlugin } from '../plugin.js';
|
|
7
|
+
import { createTestAuthConfig } from './fixtures.js';
|
|
8
|
+
// Re-export utilities from @veloxts/testing
|
|
9
|
+
export { authHeader } from '@veloxts/testing';
|
|
10
|
+
/**
|
|
11
|
+
* Creates a Fastify server configured for integration testing
|
|
12
|
+
*
|
|
13
|
+
* This sets up:
|
|
14
|
+
* - Request context decoration (mimics VeloxApp behavior)
|
|
15
|
+
* - Auth plugin with test configuration
|
|
16
|
+
* - Logging disabled for cleaner test output
|
|
17
|
+
*/
|
|
18
|
+
export async function createTestServer(options = {}) {
|
|
19
|
+
const server = await baseCreateTestServer({ logger: false });
|
|
20
|
+
// Register auth plugin if not skipped
|
|
21
|
+
if (!options.skipAuth) {
|
|
22
|
+
const authOptions = options.authOptions ?? createTestAuthConfig();
|
|
23
|
+
const plugin = authPlugin(authOptions);
|
|
24
|
+
await server.register(wrapVeloxPlugin(plugin), authOptions);
|
|
25
|
+
}
|
|
26
|
+
return server;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/__integration__/setup.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,IAAI,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAG7F,OAAO,EAA0B,UAAU,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,4CAA4C;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAgB9C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,UAA6B,EAAE;IACpE,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAE7D,sCAAsC;IACtC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtB,MAAM,WAAW,GAAsB,OAAO,CAAC,WAAW,IAAI,oBAAoB,EAAE,CAAC;QACrF,MAAM,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;QAEvC,MAAM,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|