@grantjs/server 1.0.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/LICENSE +21 -0
- package/README.md +443 -0
- package/dist/debug-C8ibbrE5.js +9 -0
- package/dist/debug-C8ibbrE5.js.map +1 -0
- package/dist/debug-Crb5gNDM.cjs +8 -0
- package/dist/debug-Crb5gNDM.cjs.map +1 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/express/index.d.ts +6 -0
- package/dist/express/index.d.ts.map +1 -0
- package/dist/express/middleware.d.ts +38 -0
- package/dist/express/middleware.d.ts.map +1 -0
- package/dist/express.cjs +99 -0
- package/dist/express.cjs.map +1 -0
- package/dist/express.mjs +101 -0
- package/dist/express.mjs.map +1 -0
- package/dist/fastify/index.d.ts +6 -0
- package/dist/fastify/index.d.ts.map +1 -0
- package/dist/fastify/plugin.d.ts +74 -0
- package/dist/fastify/plugin.d.ts.map +1 -0
- package/dist/fastify.cjs +103 -0
- package/dist/fastify.cjs.map +1 -0
- package/dist/fastify.mjs +104 -0
- package/dist/fastify.mjs.map +1 -0
- package/dist/grant-client-D1LZI2f4.js +180 -0
- package/dist/grant-client-D1LZI2f4.js.map +1 -0
- package/dist/grant-client-DywfJN5P.cjs +179 -0
- package/dist/grant-client-DywfJN5P.cjs.map +1 -0
- package/dist/grant-client.d.ts +50 -0
- package/dist/grant-client.d.ts.map +1 -0
- package/dist/index.cjs +50 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +50 -0
- package/dist/index.mjs.map +1 -0
- package/dist/nest/grant.decorator.d.ts +38 -0
- package/dist/nest/grant.decorator.d.ts.map +1 -0
- package/dist/nest/grant.guard.d.ts +29 -0
- package/dist/nest/grant.guard.d.ts.map +1 -0
- package/dist/nest/grant.module.d.ts +28 -0
- package/dist/nest/grant.module.d.ts.map +1 -0
- package/dist/nest/index.d.ts +8 -0
- package/dist/nest/index.d.ts.map +1 -0
- package/dist/nest.cjs +154 -0
- package/dist/nest.cjs.map +1 -0
- package/dist/nest.mjs +156 -0
- package/dist/nest.mjs.map +1 -0
- package/dist/next/index.d.ts +6 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/with-grant.d.ts +57 -0
- package/dist/next/with-grant.d.ts.map +1 -0
- package/dist/next.cjs +62 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.mjs +63 -0
- package/dist/next.mjs.map +1 -0
- package/dist/types.d.ts +92 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/debug.d.ts +9 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/token-extractor.d.ts +14 -0
- package/dist/utils/token-extractor.d.ts.map +1 -0
- package/package.json +109 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export type { Scope, Tenant } from '../../schema/src/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for the Grant server client
|
|
4
|
+
*/
|
|
5
|
+
export interface GrantServerConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Grant API URL (e.g., "https://api.grant.com")
|
|
8
|
+
*/
|
|
9
|
+
apiUrl: string;
|
|
10
|
+
/**
|
|
11
|
+
* Cookie name for access token (if using cookie-based auth)
|
|
12
|
+
* Default: 'grant-access-token'
|
|
13
|
+
*/
|
|
14
|
+
cookieName?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Custom function to extract token from request
|
|
17
|
+
* If provided, this takes precedence over default extraction (header/cookie)
|
|
18
|
+
*/
|
|
19
|
+
getToken?: (request: unknown) => string | null | Promise<string | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Custom fetch implementation
|
|
22
|
+
* Defaults to globalThis.fetch (Node.js 18+) or node-fetch
|
|
23
|
+
*/
|
|
24
|
+
fetch?: typeof fetch;
|
|
25
|
+
/**
|
|
26
|
+
* Credentials mode for fetch requests
|
|
27
|
+
* Defaults to 'include' for cookie support
|
|
28
|
+
*/
|
|
29
|
+
credentials?: RequestCredentials;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Result of an authorization check
|
|
33
|
+
*/
|
|
34
|
+
export interface AuthorizationResult {
|
|
35
|
+
/** Whether the action is authorized */
|
|
36
|
+
authorized: boolean;
|
|
37
|
+
/** Human-readable reason for the decision */
|
|
38
|
+
reason?: string;
|
|
39
|
+
/** The permission that matched (if authorized) */
|
|
40
|
+
matchedPermission?: Permission;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for permission checks
|
|
44
|
+
*/
|
|
45
|
+
export interface PermissionCheckOptions {
|
|
46
|
+
/** Resource context for condition evaluation */
|
|
47
|
+
context?: {
|
|
48
|
+
resource?: Record<string, unknown> | null;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Permission entity
|
|
53
|
+
*/
|
|
54
|
+
export interface Permission {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
description?: string | null;
|
|
58
|
+
action: string;
|
|
59
|
+
resourceId?: string | null;
|
|
60
|
+
resource?: Resource | null;
|
|
61
|
+
condition?: unknown;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resource entity
|
|
65
|
+
*/
|
|
66
|
+
export interface Resource {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
slug: string;
|
|
70
|
+
description?: string | null;
|
|
71
|
+
actions: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Error response from the API
|
|
75
|
+
*/
|
|
76
|
+
export interface ApiError {
|
|
77
|
+
error: string;
|
|
78
|
+
message?: string;
|
|
79
|
+
statusCode?: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resource resolver function type
|
|
83
|
+
* Used to resolve resource data for condition evaluation
|
|
84
|
+
*/
|
|
85
|
+
export interface ResourceResolverParams {
|
|
86
|
+
resourceSlug: string;
|
|
87
|
+
request: unknown;
|
|
88
|
+
[key: string]: unknown;
|
|
89
|
+
}
|
|
90
|
+
export type ResourceResolverResult<T = Record<string, unknown>> = T | null;
|
|
91
|
+
export type ResourceResolver<TResult = Record<string, unknown>> = (params: ResourceResolverParams) => Promise<ResourceResolverResult<TResult>>;
|
|
92
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAExE;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAErB;;;OAGG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,uCAAuC;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,iBAAiB,CAAC,EAAE,UAAU,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;KAC3C,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAE3E,MAAM,MAAM,gBAAgB,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAChE,MAAM,EAAE,sBAAsB,KAC3B,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Whether Grant debug logging is enabled (set DEBUG_GRANT=1 in development). */
|
|
2
|
+
export declare function isDebugGrant(): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Log Grant integration debug info when DEBUG_GRANT=1.
|
|
5
|
+
* Used by Express middleware, Fastify grant hook, Next withGrant, and Nest GrantGuard.
|
|
6
|
+
* Set DEBUG_GRANT=1 in .env or the environment to see resource, action, and outcome in development.
|
|
7
|
+
*/
|
|
8
|
+
export declare function debugGrant(integration: string, data: Record<string, unknown>): void;
|
|
9
|
+
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AAEA,iFAAiF;AACjF,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAGnF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GrantServerConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extract Bearer token from Authorization header
|
|
4
|
+
*/
|
|
5
|
+
export declare function extractBearerToken(authHeader: string | undefined): string | null;
|
|
6
|
+
/**
|
|
7
|
+
* Extract token from cookies
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractTokenFromCookies(cookieHeader: string | undefined, cookieName: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Extract token from Express request
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractTokenFromRequest(request: unknown, config: GrantServerConfig): Promise<string | null>;
|
|
14
|
+
//# sourceMappingURL=token-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-extractor.d.ts","sourceRoot":"","sources":["../../src/utils/token-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAShF;AAkBD;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,IAAI,CAKf;AAED;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmDxB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grantjs/server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Server SDK for Grant authorization - Middleware and guards for Express, Fastify, NestJS, and Next.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./express": {
|
|
16
|
+
"types": "./dist/express/index.d.ts",
|
|
17
|
+
"import": "./dist/express.mjs",
|
|
18
|
+
"require": "./dist/express.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./fastify": {
|
|
21
|
+
"types": "./dist/fastify/index.d.ts",
|
|
22
|
+
"import": "./dist/fastify.mjs",
|
|
23
|
+
"require": "./dist/fastify.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./next": {
|
|
26
|
+
"types": "./dist/next/index.d.ts",
|
|
27
|
+
"import": "./dist/next.mjs",
|
|
28
|
+
"require": "./dist/next.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./nest": {
|
|
31
|
+
"types": "./dist/nest/index.d.ts",
|
|
32
|
+
"import": "./dist/nest.mjs",
|
|
33
|
+
"require": "./dist/nest.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"keywords": [
|
|
43
|
+
"grant",
|
|
44
|
+
"authorization",
|
|
45
|
+
"permissions",
|
|
46
|
+
"rbac",
|
|
47
|
+
"role-based-access-control",
|
|
48
|
+
"express",
|
|
49
|
+
"fastify",
|
|
50
|
+
"nestjs",
|
|
51
|
+
"nextjs",
|
|
52
|
+
"middleware",
|
|
53
|
+
"access-control",
|
|
54
|
+
"typescript",
|
|
55
|
+
"multi-tenant",
|
|
56
|
+
"sdk",
|
|
57
|
+
"server"
|
|
58
|
+
],
|
|
59
|
+
"author": {
|
|
60
|
+
"name": "Alejandro Heredia",
|
|
61
|
+
"email": "ale@logus.graphics",
|
|
62
|
+
"url": "https://logus.graphics"
|
|
63
|
+
},
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "https://github.com/logusgraphics/grant.git",
|
|
67
|
+
"directory": "packages/@grantjs/server"
|
|
68
|
+
},
|
|
69
|
+
"license": "MIT",
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public",
|
|
72
|
+
"registry": "https://registry.npmjs.org/"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@grantjs/schema": "1.0.0"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@types/express": "^5.0.0",
|
|
79
|
+
"@types/node": "^24.7.2",
|
|
80
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
81
|
+
"eslint": "^9.37.0",
|
|
82
|
+
"express": "^5.1.0",
|
|
83
|
+
"fastify": "^5.7.2",
|
|
84
|
+
"next": "^16.0.0",
|
|
85
|
+
"@nestjs/common": "^11.0.0",
|
|
86
|
+
"@nestjs/core": "^11.0.0",
|
|
87
|
+
"typescript": "^5",
|
|
88
|
+
"vite": "^6.0.0",
|
|
89
|
+
"vite-plugin-dts": "^4.3.0",
|
|
90
|
+
"vitest": "^3.2.4"
|
|
91
|
+
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"express": "^4 || ^5",
|
|
94
|
+
"fastify": "^4 || ^5",
|
|
95
|
+
"next": ">=13.0.0 <17.0.0",
|
|
96
|
+
"@nestjs/common": ">=10.0.0",
|
|
97
|
+
"@nestjs/core": ">=10.0.0"
|
|
98
|
+
},
|
|
99
|
+
"scripts": {
|
|
100
|
+
"build": "vite build",
|
|
101
|
+
"build:watch": "vite build --watch",
|
|
102
|
+
"type-check": "tsc --noEmit",
|
|
103
|
+
"lint": "eslint src --ext .ts",
|
|
104
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
105
|
+
"test": "vitest",
|
|
106
|
+
"test:run": "vitest run",
|
|
107
|
+
"test:coverage": "vitest run --coverage"
|
|
108
|
+
}
|
|
109
|
+
}
|