glasswork 0.2.3 → 0.3.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/dist/http/route-helpers.d.ts +4 -4
- package/dist/http/route-helpers.d.ts.map +1 -1
- package/dist/http/route-helpers.js +4 -1
- package/dist/http/route-helpers.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/list-query/builder.d.ts +33 -0
- package/dist/list-query/builder.d.ts.map +1 -0
- package/dist/list-query/builder.js +104 -0
- package/dist/list-query/builder.js.map +1 -0
- package/dist/list-query/casl.d.ts +36 -0
- package/dist/list-query/casl.d.ts.map +1 -0
- package/dist/list-query/casl.js +42 -0
- package/dist/list-query/casl.js.map +1 -0
- package/dist/list-query/global-search.d.ts +20 -0
- package/dist/list-query/global-search.d.ts.map +1 -0
- package/dist/list-query/global-search.js +68 -0
- package/dist/list-query/global-search.js.map +1 -0
- package/dist/list-query/index.d.ts +6 -0
- package/dist/list-query/index.d.ts.map +1 -0
- package/dist/list-query/index.js +7 -0
- package/dist/list-query/index.js.map +1 -0
- package/dist/list-query/parser.d.ts +17 -0
- package/dist/list-query/parser.d.ts.map +1 -0
- package/dist/list-query/parser.js +162 -0
- package/dist/list-query/parser.js.map +1 -0
- package/dist/list-query/prisma-builder.d.ts +21 -0
- package/dist/list-query/prisma-builder.d.ts.map +1 -0
- package/dist/list-query/prisma-builder.js +224 -0
- package/dist/list-query/prisma-builder.js.map +1 -0
- package/dist/list-query/query-schema.d.ts +15 -0
- package/dist/list-query/query-schema.d.ts.map +1 -0
- package/dist/list-query/query-schema.js +16 -0
- package/dist/list-query/query-schema.js.map +1 -0
- package/dist/list-query/schema-helpers.d.ts +81 -0
- package/dist/list-query/schema-helpers.d.ts.map +1 -0
- package/dist/list-query/schema-helpers.js +85 -0
- package/dist/list-query/schema-helpers.js.map +1 -0
- package/dist/list-query/types.d.ts +66 -0
- package/dist/list-query/types.d.ts.map +1 -0
- package/dist/{hooks → list-query}/types.js.map +1 -1
- package/dist/list-query/validator.d.ts +35 -0
- package/dist/list-query/validator.d.ts.map +1 -0
- package/dist/list-query/validator.js +44 -0
- package/dist/list-query/validator.js.map +1 -0
- package/dist/openapi/defaults.d.ts.map +1 -1
- package/dist/openapi/defaults.js +12 -3
- package/dist/openapi/defaults.js.map +1 -1
- package/dist/openapi/hooks.d.ts.map +1 -1
- package/dist/openapi/hooks.js +7 -4
- package/dist/openapi/hooks.js.map +1 -1
- package/package.json +12 -1
- package/dist/authorization/ability-middleware.d.ts +0 -61
- package/dist/authorization/ability-middleware.d.ts.map +0 -1
- package/dist/authorization/ability-middleware.js +0 -74
- package/dist/authorization/ability-middleware.js.map +0 -1
- package/dist/authorization/index.d.ts +0 -46
- package/dist/authorization/index.d.ts.map +0 -1
- package/dist/authorization/index.js +0 -46
- package/dist/authorization/index.js.map +0 -1
- package/dist/authorization/route-helpers.d.ts +0 -106
- package/dist/authorization/route-helpers.d.ts.map +0 -1
- package/dist/authorization/route-helpers.js +0 -136
- package/dist/authorization/route-helpers.js.map +0 -1
- package/dist/authorization/service-proxy.d.ts +0 -59
- package/dist/authorization/service-proxy.d.ts.map +0 -1
- package/dist/authorization/service-proxy.js +0 -110
- package/dist/authorization/service-proxy.js.map +0 -1
- package/dist/authorization/types.d.ts +0 -58
- package/dist/authorization/types.d.ts.map +0 -1
- package/dist/authorization/types.js +0 -7
- package/dist/authorization/types.js.map +0 -1
- package/dist/hooks/authorization-hook.d.ts +0 -100
- package/dist/hooks/authorization-hook.d.ts.map +0 -1
- package/dist/hooks/authorization-hook.js +0 -93
- package/dist/hooks/authorization-hook.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -54
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -55
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/service-hooks.d.ts +0 -82
- package/dist/hooks/service-hooks.d.ts.map +0 -1
- package/dist/hooks/service-hooks.js +0 -158
- package/dist/hooks/service-hooks.js.map +0 -1
- package/dist/hooks/types.d.ts +0 -151
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/utils/pagination.d.ts +0 -48
- package/dist/utils/pagination.d.ts.map +0 -1
- package/dist/utils/pagination.js +0 -42
- package/dist/utils/pagination.js.map +0 -1
- /package/dist/{hooks → list-query}/types.js +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field path as an array of strings for nested fields
|
|
3
|
+
* Example: ['organization', 'name'] represents 'organization.name'
|
|
4
|
+
*/
|
|
5
|
+
export type FieldPath = readonly string[];
|
|
6
|
+
/**
|
|
7
|
+
* Search field input - accepts either a simple string for flat fields
|
|
8
|
+
* or an array for nested fields
|
|
9
|
+
* Example: 'name' or ['organization', 'name']
|
|
10
|
+
*/
|
|
11
|
+
export type SearchFieldInput = string | readonly string[];
|
|
12
|
+
/**
|
|
13
|
+
* Sieve filter operators
|
|
14
|
+
* Based on https://github.com/Biarity/Sieve
|
|
15
|
+
*/
|
|
16
|
+
export type FilterOperator = '==' | '!=' | '>' | '<' | '>=' | '<=' | '@=' | '_=' | '_-=' | '!@=' | '!_=' | '!_-=' | '==*' | '!=*' | '@=*' | '_=*' | '_-=*' | '!@=*' | '!_=*' | '!_-=*';
|
|
17
|
+
/**
|
|
18
|
+
* Sort direction
|
|
19
|
+
*/
|
|
20
|
+
export type SortDirection = 'asc' | 'desc';
|
|
21
|
+
/**
|
|
22
|
+
* Parsed filter condition
|
|
23
|
+
*/
|
|
24
|
+
export interface ParsedFilter {
|
|
25
|
+
readonly fieldPath: FieldPath;
|
|
26
|
+
readonly operator: FilterOperator;
|
|
27
|
+
readonly value: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Parsed sort condition
|
|
31
|
+
*/
|
|
32
|
+
export interface ParsedSort {
|
|
33
|
+
readonly fieldPath: FieldPath;
|
|
34
|
+
readonly direction: SortDirection;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Raw query parameters from HTTP request
|
|
38
|
+
*/
|
|
39
|
+
export interface RawQueryParams {
|
|
40
|
+
readonly sorts?: string;
|
|
41
|
+
readonly filters?: string;
|
|
42
|
+
readonly page?: number;
|
|
43
|
+
readonly pageSize?: number;
|
|
44
|
+
readonly search?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parsed query parameters
|
|
48
|
+
*/
|
|
49
|
+
export interface ParsedQueryParams {
|
|
50
|
+
readonly sorts: readonly ParsedSort[];
|
|
51
|
+
readonly filters: readonly ParsedFilter[];
|
|
52
|
+
readonly page: number;
|
|
53
|
+
readonly pageSize: number;
|
|
54
|
+
readonly search?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Prisma-ready query parameters for list operations
|
|
58
|
+
* Generic type parameter should be the Prisma WhereInput and OrderByInput types
|
|
59
|
+
*/
|
|
60
|
+
export interface PrismaListParams<TWhere = Record<string, unknown>, TOrderBy = Record<string, unknown>> {
|
|
61
|
+
readonly where: TWhere;
|
|
62
|
+
readonly orderBy: readonly TOrderBy[];
|
|
63
|
+
readonly skip: number;
|
|
64
|
+
readonly take: number;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/list-query/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,MAAM,EAAE,CAAC;AAE1C;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,KAAK,GACL,KA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AAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/list-query/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type BaseIssue, type BaseSchema, type InferOutput } from 'valibot';
|
|
2
|
+
/**
|
|
3
|
+
* Schema-based validation configuration
|
|
4
|
+
* Defines Valibot schemas for validating Prisma where and orderBy clauses
|
|
5
|
+
*/
|
|
6
|
+
export interface SchemaValidationConfig<TWhereSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TOrderBySchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>> {
|
|
7
|
+
readonly whereSchema: TWhereSchema;
|
|
8
|
+
readonly orderBySchema: TOrderBySchema;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validated list params with proper typing from Valibot schemas
|
|
12
|
+
* Note: orderBy is not readonly to match Prisma's expected type
|
|
13
|
+
*/
|
|
14
|
+
export interface ValidatedListParams<TWhereSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TOrderBySchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>> {
|
|
15
|
+
readonly where: InferOutput<TWhereSchema>;
|
|
16
|
+
readonly orderBy: InferOutput<TOrderBySchema>[];
|
|
17
|
+
readonly skip: number;
|
|
18
|
+
readonly take: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validate and parse Prisma where clause against schema
|
|
22
|
+
* Returns the validated and typed result
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateWhere<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(where: Record<string, unknown>, schema: TSchema): InferOutput<TSchema>;
|
|
25
|
+
/**
|
|
26
|
+
* Validate and parse Prisma orderBy clause against schema
|
|
27
|
+
* Returns the validated and typed results as a mutable array (not readonly) to match Prisma's expectations
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateOrderBy<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(orderBy: readonly Record<string, unknown>[], schema: TSchema): InferOutput<TSchema>[];
|
|
30
|
+
/**
|
|
31
|
+
* Validate Prisma list params against schemas
|
|
32
|
+
* Returns validated and properly typed params
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateListParams<TWhereSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TOrderBySchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(where: Record<string, unknown>, orderBy: readonly Record<string, unknown>[], skip: number, take: number, config: SchemaValidationConfig<TWhereSchema, TOrderBySchema>): ValidatedListParams<TWhereSchema, TOrderBySchema>;
|
|
35
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/list-query/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAS,MAAM,SAAS,CAAC;AAEnF;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CACrC,YAAY,SAAS,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,EACrE,cAAc,SAAS,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAEvE,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,cAAc,CAAC;CACxC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAClC,YAAY,SAAS,UAAU,CAAC,OAAO,EAAE,OAA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AAC,YAAY,EAAE,cAAc,CAAC,GAC3D,mBAAmB,CAAC,YAAY,EAAE,cAAc,CAAC,CAOnD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { parse } from 'valibot';
|
|
2
|
+
/**
|
|
3
|
+
* Validate and parse Prisma where clause against schema
|
|
4
|
+
* Returns the validated and typed result
|
|
5
|
+
*/
|
|
6
|
+
export function validateWhere(where, schema) {
|
|
7
|
+
try {
|
|
8
|
+
return parse(schema, where);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error instanceof Error) {
|
|
12
|
+
throw new Error(`Invalid filter: ${error.message}`);
|
|
13
|
+
}
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validate and parse Prisma orderBy clause against schema
|
|
19
|
+
* Returns the validated and typed results as a mutable array (not readonly) to match Prisma's expectations
|
|
20
|
+
*/
|
|
21
|
+
export function validateOrderBy(orderBy, schema) {
|
|
22
|
+
try {
|
|
23
|
+
return orderBy.map((order) => parse(schema, order));
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
throw new Error(`Invalid sort: ${error.message}`);
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validate Prisma list params against schemas
|
|
34
|
+
* Returns validated and properly typed params
|
|
35
|
+
*/
|
|
36
|
+
export function validateListParams(where, orderBy, skip, take, config) {
|
|
37
|
+
return {
|
|
38
|
+
where: validateWhere(where, config.whereSchema),
|
|
39
|
+
orderBy: validateOrderBy(orderBy, config.orderBySchema),
|
|
40
|
+
skip,
|
|
41
|
+
take,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/list-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names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAO/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/openapi/defaults.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAO/C;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,EAAE,SAAS,CAAC,gBA8FhD,CAAC"}
|
package/dist/openapi/defaults.js
CHANGED
|
@@ -62,7 +62,7 @@ export const defaultOpenAPIComponents = {
|
|
|
62
62
|
maximum: 3600,
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
|
-
// Pagination headers (from
|
|
65
|
+
// Pagination headers (from list-query)
|
|
66
66
|
'X-Total-Count': {
|
|
67
67
|
description: 'Total number of items available',
|
|
68
68
|
schema: {
|
|
@@ -72,7 +72,16 @@ export const defaultOpenAPIComponents = {
|
|
|
72
72
|
maximum: 2147483647, // Max int32
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
|
-
'X-
|
|
75
|
+
'X-Total-Pages': {
|
|
76
|
+
description: 'Total number of pages',
|
|
77
|
+
schema: {
|
|
78
|
+
type: 'integer',
|
|
79
|
+
format: 'int32',
|
|
80
|
+
minimum: 0,
|
|
81
|
+
maximum: 2147483647, // Max int32
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
'X-Current-Page': {
|
|
76
85
|
description: 'Current page number',
|
|
77
86
|
schema: {
|
|
78
87
|
type: 'integer',
|
|
@@ -81,7 +90,7 @@ export const defaultOpenAPIComponents = {
|
|
|
81
90
|
maximum: 2147483647, // Max int32
|
|
82
91
|
},
|
|
83
92
|
},
|
|
84
|
-
'X-
|
|
93
|
+
'X-Page-Size': {
|
|
85
94
|
description: 'Number of items per page',
|
|
86
95
|
schema: {
|
|
87
96
|
type: 'integer',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/openapi/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA+B;IAClE,OAAO,EAAE;QACP,uDAAuD;QACvD,aAAa,EAAE,YAAY,CAAC,gBAAgB,CAA2B;QACvE,uBAAuB,EAAE,YAAY,CAAC,0BAA0B,CAA2B;QAC3F,eAAe,EAAE,YAAY,CAAC,kBAAkB,CAA2B;KAC5E;IACD,OAAO,EAAE;QACP,eAAe;QACf,6BAA6B,EAAE;YAC7B,WAAW,EAAE,kCAAkC;YAC/C,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,qCAAqC;aAC/C;SACF;QAED,6CAA6C;QAC7C,iBAAiB,EAAE;YACjB,WAAW,EAAE,mDAAmD;YAChE,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,KAAK;aACf;SACF;QACD,qBAAqB,EAAE;YACrB,WAAW,EAAE,0CAA0C;YACvD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,KAAK;aACf;SACF;QACD,iBAAiB,EAAE;YACjB,WAAW,EAAE,4CAA4C;YACzD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,IAAI;aACd;SACF;QACD,aAAa,EAAE;YACb,WAAW,EAAE,4DAA4D;YACzE,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,IAAI;aACd;SACF;QAED,
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/openapi/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA+B;IAClE,OAAO,EAAE;QACP,uDAAuD;QACvD,aAAa,EAAE,YAAY,CAAC,gBAAgB,CAA2B;QACvE,uBAAuB,EAAE,YAAY,CAAC,0BAA0B,CAA2B;QAC3F,eAAe,EAAE,YAAY,CAAC,kBAAkB,CAA2B;KAC5E;IACD,OAAO,EAAE;QACP,eAAe;QACf,6BAA6B,EAAE;YAC7B,WAAW,EAAE,kCAAkC;YAC/C,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,qCAAqC;aAC/C;SACF;QAED,6CAA6C;QAC7C,iBAAiB,EAAE;YACjB,WAAW,EAAE,mDAAmD;YAChE,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,KAAK;aACf;SACF;QACD,qBAAqB,EAAE;YACrB,WAAW,EAAE,0CAA0C;YACvD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,KAAK;aACf;SACF;QACD,iBAAiB,EAAE;YACjB,WAAW,EAAE,4CAA4C;YACzD,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,IAAI;aACd;SACF;QACD,aAAa,EAAE;YACb,WAAW,EAAE,4DAA4D;YACzE,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,IAAI;aACd;SACF;QAED,uCAAuC;QACvC,eAAe,EAAE;YACf,WAAW,EAAE,iCAAiC;YAC9C,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,UAAU,EAAE,YAAY;aAClC;SACF;QACD,eAAe,EAAE;YACf,WAAW,EAAE,uBAAuB;YACpC,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,UAAU,EAAE,YAAY;aAClC;SACF;QACD,gBAAgB,EAAE;YAChB,WAAW,EAAE,qBAAqB;YAClC,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,UAAU,EAAE,YAAY;aAClC;SACF;QACD,aAAa,EAAE;YACb,WAAW,EAAE,0BAA0B;YACvC,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE,CAAC;gBACV,OAAO,EAAE,GAAG;aACb;SACF;KACF;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/openapi/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAc3E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAgChF;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,mBAAmB,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/openapi/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAc3E;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAgChF;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,mBAAmB,CA4BjE"}
|
package/dist/openapi/hooks.js
CHANGED
|
@@ -67,11 +67,14 @@ export function createPaginationHeadersHook() {
|
|
|
67
67
|
'X-Total-Count': {
|
|
68
68
|
$ref: '#/components/headers/X-Total-Count',
|
|
69
69
|
},
|
|
70
|
-
'X-
|
|
71
|
-
$ref: '#/components/headers/X-
|
|
70
|
+
'X-Total-Pages': {
|
|
71
|
+
$ref: '#/components/headers/X-Total-Pages',
|
|
72
72
|
},
|
|
73
|
-
'X-
|
|
74
|
-
$ref: '#/components/headers/X-
|
|
73
|
+
'X-Current-Page': {
|
|
74
|
+
$ref: '#/components/headers/X-Current-Page',
|
|
75
|
+
},
|
|
76
|
+
'X-Page-Size': {
|
|
77
|
+
$ref: '#/components/headers/X-Page-Size',
|
|
75
78
|
},
|
|
76
79
|
},
|
|
77
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/openapi/hooks.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE;QAC5B,IAAI,CAAC,OAAO;YAAE,OAAO,QAAQ,CAAC;QAE9B,OAAO;YACL,GAAG,QAAQ;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,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAE5C,kEAAkE;QAClE,IAAI,UAAU,KAAK,KAAK,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;YAClD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,OAAO;YACL,GAAG,QAAQ;YACX,OAAO,EAAE;gBACP,GAAG,QAAQ,CAAC,OAAO;gBACnB,eAAe,EAAE;oBACf,IAAI,EAAE,oCAAoC;iBAC3C;gBACD,eAAe,EAAE;oBACf,IAAI,EAAE,oCAAoC;iBAC3C;gBACD,gBAAgB,EAAE;oBAChB,IAAI,EAAE,qCAAqC;iBAC5C;gBACD,aAAa,EAAE;oBACb,IAAI,EAAE,kCAAkC;iBACzC;aACF;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glasswork",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A transparent, Lambda-optimized web framework for building OpenAPI-compliant REST APIs.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -60,7 +60,9 @@
|
|
|
60
60
|
"@aws-sdk/client-dynamodb": "^3.902.0",
|
|
61
61
|
"@aws-sdk/client-ssm": "^3.902.0",
|
|
62
62
|
"@aws-sdk/lib-dynamodb": "^3.902.0",
|
|
63
|
+
"@casl/prisma": "^1.4.0",
|
|
63
64
|
"@hono/swagger-ui": "^0.5.0",
|
|
65
|
+
"@prisma/client": "^6.0.0",
|
|
64
66
|
"awilix": "^12.0.0",
|
|
65
67
|
"dotenv": "^16.0.0",
|
|
66
68
|
"hono": "^4.9.0",
|
|
@@ -77,9 +79,15 @@
|
|
|
77
79
|
"@aws-sdk/lib-dynamodb": {
|
|
78
80
|
"optional": true
|
|
79
81
|
},
|
|
82
|
+
"@casl/prisma": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
80
85
|
"@hono/swagger-ui": {
|
|
81
86
|
"optional": true
|
|
82
87
|
},
|
|
88
|
+
"@prisma/client": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
83
91
|
"dotenv": {
|
|
84
92
|
"optional": true
|
|
85
93
|
}
|
|
@@ -87,6 +95,9 @@
|
|
|
87
95
|
"devDependencies": {
|
|
88
96
|
"@aws-sdk/client-ssm": "^3.901.0",
|
|
89
97
|
"@biomejs/biome": "^2.2.5",
|
|
98
|
+
"@casl/ability": "^6.7.3",
|
|
99
|
+
"@casl/prisma": "^1.5.2",
|
|
100
|
+
"@prisma/client": "^6.18.0",
|
|
90
101
|
"@types/node": "^22.18.8",
|
|
91
102
|
"@vitest/coverage-v8": "^3.2.4",
|
|
92
103
|
"dotenv": "^17.2.3",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Context, MiddlewareHandler } from 'hono';
|
|
2
|
-
import type { AbilityConfig, BaseAbility } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Creates Hono middleware that attaches a CASL ability to the request context.
|
|
5
|
-
*
|
|
6
|
-
* This middleware is transparent - it exposes the CASL ability directly in the
|
|
7
|
-
* Hono context, making it accessible to route handlers. All CASL features
|
|
8
|
-
* remain available.
|
|
9
|
-
*
|
|
10
|
-
* @param config - Ability configuration with factory function
|
|
11
|
-
* @returns Hono middleware that creates and attaches the ability
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { createPrismaAbility } from '@casl/prisma';
|
|
16
|
-
* import { AbilityBuilder } from '@casl/ability';
|
|
17
|
-
*
|
|
18
|
-
* const abilityMiddleware = withAbility({
|
|
19
|
-
* factory: (c) => {
|
|
20
|
-
* const user = c.get('user');
|
|
21
|
-
* const { can, build } = new AbilityBuilder(createPrismaAbility);
|
|
22
|
-
*
|
|
23
|
-
* if (user.role === 'admin') {
|
|
24
|
-
* can('manage', 'all');
|
|
25
|
-
* } else {
|
|
26
|
-
* can('read', 'User', { id: user.id });
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* return build();
|
|
30
|
-
* }
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* app.use('*', abilityMiddleware);
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function withAbility<T extends BaseAbility = BaseAbility>(config: AbilityConfig<T>): MiddlewareHandler;
|
|
37
|
-
/**
|
|
38
|
-
* Helper to retrieve the ability from Hono context.
|
|
39
|
-
* This provides type-safe access to the CASL ability stored by `withAbility`.
|
|
40
|
-
*
|
|
41
|
-
* @param context - Hono context
|
|
42
|
-
* @param contextKey - The key used to store the ability (default: 'ability')
|
|
43
|
-
* @returns The CASL ability instance
|
|
44
|
-
* @throws Error if ability is not found in context
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* router.get('/users', async (c) => {
|
|
49
|
-
* const ability = getAbility(c);
|
|
50
|
-
*
|
|
51
|
-
* // Use CASL ability directly
|
|
52
|
-
* if (ability.can('read', 'User')) {
|
|
53
|
-
* return c.json(users);
|
|
54
|
-
* }
|
|
55
|
-
*
|
|
56
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare function getAbility<T extends BaseAbility = BaseAbility>(context: Context, contextKey?: string): T;
|
|
61
|
-
//# sourceMappingURL=ability-middleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ability-middleware.d.ts","sourceRoot":"","sources":["../../src/authorization/ability-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC7D,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GACvB,iBAAiB,CAYnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC5D,OAAO,EAAE,OAAO,EAChB,UAAU,SAAY,GACrB,CAAC,CAUH"}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates Hono middleware that attaches a CASL ability to the request context.
|
|
3
|
-
*
|
|
4
|
-
* This middleware is transparent - it exposes the CASL ability directly in the
|
|
5
|
-
* Hono context, making it accessible to route handlers. All CASL features
|
|
6
|
-
* remain available.
|
|
7
|
-
*
|
|
8
|
-
* @param config - Ability configuration with factory function
|
|
9
|
-
* @returns Hono middleware that creates and attaches the ability
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import { createPrismaAbility } from '@casl/prisma';
|
|
14
|
-
* import { AbilityBuilder } from '@casl/ability';
|
|
15
|
-
*
|
|
16
|
-
* const abilityMiddleware = withAbility({
|
|
17
|
-
* factory: (c) => {
|
|
18
|
-
* const user = c.get('user');
|
|
19
|
-
* const { can, build } = new AbilityBuilder(createPrismaAbility);
|
|
20
|
-
*
|
|
21
|
-
* if (user.role === 'admin') {
|
|
22
|
-
* can('manage', 'all');
|
|
23
|
-
* } else {
|
|
24
|
-
* can('read', 'User', { id: user.id });
|
|
25
|
-
* }
|
|
26
|
-
*
|
|
27
|
-
* return build();
|
|
28
|
-
* }
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* app.use('*', abilityMiddleware);
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export function withAbility(config) {
|
|
35
|
-
const contextKey = config.contextKey || 'ability';
|
|
36
|
-
return async (c, next) => {
|
|
37
|
-
// Create ability using factory
|
|
38
|
-
const ability = await config.factory(c);
|
|
39
|
-
// Store in Hono context
|
|
40
|
-
c.set(contextKey, ability);
|
|
41
|
-
await next();
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Helper to retrieve the ability from Hono context.
|
|
46
|
-
* This provides type-safe access to the CASL ability stored by `withAbility`.
|
|
47
|
-
*
|
|
48
|
-
* @param context - Hono context
|
|
49
|
-
* @param contextKey - The key used to store the ability (default: 'ability')
|
|
50
|
-
* @returns The CASL ability instance
|
|
51
|
-
* @throws Error if ability is not found in context
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* router.get('/users', async (c) => {
|
|
56
|
-
* const ability = getAbility(c);
|
|
57
|
-
*
|
|
58
|
-
* // Use CASL ability directly
|
|
59
|
-
* if (ability.can('read', 'User')) {
|
|
60
|
-
* return c.json(users);
|
|
61
|
-
* }
|
|
62
|
-
*
|
|
63
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
64
|
-
* });
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export function getAbility(context, contextKey = 'ability') {
|
|
68
|
-
const ability = context.get(contextKey);
|
|
69
|
-
if (!ability) {
|
|
70
|
-
throw new Error(`Ability not found in context. Did you forget to use withAbility() middleware?`);
|
|
71
|
-
}
|
|
72
|
-
return ability;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=ability-middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ability-middleware.js","sourceRoot":"","sources":["../../src/authorization/ability-middleware.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,WAAW,CACzB,MAAwB;IAExB,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,SAAS,CAAC;IAElD,OAAO,KAAK,EAAE,CAAU,EAAE,IAAI,EAAE,EAAE;QAChC,+BAA+B;QAC/B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAExC,wBAAwB;QACxB,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3B,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,UAAU,CACxB,OAAgB,EAChB,UAAU,GAAG,SAAS;IAEtB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IAED,OAAO,OAAY,CAAC;AACtB,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorization module for integrating CASL with Glasswork.
|
|
3
|
-
*
|
|
4
|
-
* This module provides transparent integration with CASL while maintaining framework principles.
|
|
5
|
-
*
|
|
6
|
-
* ## Recommended Approach: Service Hooks
|
|
7
|
-
*
|
|
8
|
-
* Configure authorization globally using the hooks system:
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { authorizationHook, defineServiceMetadata, defineAuthorize } from 'glasswork';
|
|
12
|
-
*
|
|
13
|
-
* const authServiceMeta = defineServiceMetadata({
|
|
14
|
-
* deleteSession: { authorize: defineAuthorize('delete', 'Session') }
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* bootstrap(AppModule, {
|
|
18
|
-
* serviceHooks: [authorizationHook],
|
|
19
|
-
* serviceMetadata: { authService: authServiceMeta }
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // In routes - authorization happens automatically!
|
|
23
|
-
* await services.authService.deleteSession(token);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* ## Alternative: Explicit Authorization
|
|
27
|
-
*
|
|
28
|
-
* For fine-grained control, use explicit authorize() calls:
|
|
29
|
-
*
|
|
30
|
-
* ```typescript
|
|
31
|
-
* router.delete('/sessions/:id', async (c) => {
|
|
32
|
-
* authorize(c, 'delete', 'Session', { id: c.req.param('id') });
|
|
33
|
-
* await sessionService.delete(c.req.param('id'));
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @module authorization
|
|
38
|
-
* @see https://casl.js.org/ for CASL documentation
|
|
39
|
-
* @see HOOKS_SYSTEM.md for hooks documentation
|
|
40
|
-
*/
|
|
41
|
-
export type { PureAbility } from '@casl/ability';
|
|
42
|
-
export { ForbiddenError, subject } from '@casl/ability';
|
|
43
|
-
export { getAbility, withAbility } from './ability-middleware.js';
|
|
44
|
-
export { accessibleWhere, authorize, can, cannot } from './route-helpers.js';
|
|
45
|
-
export type { AbilityConfig, AbilityFactory, BaseAbility } from './types.js';
|
|
46
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE7E,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authorization module for integrating CASL with Glasswork.
|
|
3
|
-
*
|
|
4
|
-
* This module provides transparent integration with CASL while maintaining framework principles.
|
|
5
|
-
*
|
|
6
|
-
* ## Recommended Approach: Service Hooks
|
|
7
|
-
*
|
|
8
|
-
* Configure authorization globally using the hooks system:
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { authorizationHook, defineServiceMetadata, defineAuthorize } from 'glasswork';
|
|
12
|
-
*
|
|
13
|
-
* const authServiceMeta = defineServiceMetadata({
|
|
14
|
-
* deleteSession: { authorize: defineAuthorize('delete', 'Session') }
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* bootstrap(AppModule, {
|
|
18
|
-
* serviceHooks: [authorizationHook],
|
|
19
|
-
* serviceMetadata: { authService: authServiceMeta }
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* // In routes - authorization happens automatically!
|
|
23
|
-
* await services.authService.deleteSession(token);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* ## Alternative: Explicit Authorization
|
|
27
|
-
*
|
|
28
|
-
* For fine-grained control, use explicit authorize() calls:
|
|
29
|
-
*
|
|
30
|
-
* ```typescript
|
|
31
|
-
* router.delete('/sessions/:id', async (c) => {
|
|
32
|
-
* authorize(c, 'delete', 'Session', { id: c.req.param('id') });
|
|
33
|
-
* await sessionService.delete(c.req.param('id'));
|
|
34
|
-
* });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @module authorization
|
|
38
|
-
* @see https://casl.js.org/ for CASL documentation
|
|
39
|
-
* @see HOOKS_SYSTEM.md for hooks documentation
|
|
40
|
-
*/
|
|
41
|
-
export { ForbiddenError, subject } from '@casl/ability';
|
|
42
|
-
// Ability middleware (attaches CASL abilities to context)
|
|
43
|
-
export { getAbility, withAbility } from './ability-middleware.js';
|
|
44
|
-
// Route helpers (explicit authorization - recommended for fine-grained control)
|
|
45
|
-
export { accessibleWhere, authorize, can, cannot } from './route-helpers.js';
|
|
46
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAIH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAClE,gFAAgF;AAChF,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { Context } from 'hono';
|
|
2
|
-
import type { BaseAbility } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Authorizes an action on a subject using the CASL ability from context.
|
|
5
|
-
* Throws ForbiddenError if the action is not permitted.
|
|
6
|
-
*
|
|
7
|
-
* This is a thin wrapper around CASL's authorize functionality, exposing
|
|
8
|
-
* the native CASL API while providing convenient access to the ability
|
|
9
|
-
* stored in Hono context.
|
|
10
|
-
*
|
|
11
|
-
* @param context - Hono context containing the ability
|
|
12
|
-
* @param action - CASL action (e.g., 'create', 'read', 'update', 'delete')
|
|
13
|
-
* @param subjectType - Subject type string (e.g., 'User', 'Post')
|
|
14
|
-
* @param subjectData - Optional subject instance data
|
|
15
|
-
* @throws ForbiddenError from CASL if action is not permitted
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* router.delete('/sessions/:id', async (c) => {
|
|
20
|
-
* const sessionId = c.req.param('id');
|
|
21
|
-
* const user = c.get('user');
|
|
22
|
-
*
|
|
23
|
-
* // Explicit authorization - clear and obvious
|
|
24
|
-
* authorize(c, 'delete', 'Session', { userId: user.id, sessionId });
|
|
25
|
-
*
|
|
26
|
-
* await sessionService.delete(sessionId);
|
|
27
|
-
* return c.json({ success: true });
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare function authorize<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): void;
|
|
32
|
-
/**
|
|
33
|
-
* Checks if an action is permitted without throwing an error.
|
|
34
|
-
* Returns boolean indicating if the action is allowed.
|
|
35
|
-
*
|
|
36
|
-
* @param context - Hono context containing the ability
|
|
37
|
-
* @param action - CASL action
|
|
38
|
-
* @param subjectType - Subject type string
|
|
39
|
-
* @param subjectData - Optional subject instance data
|
|
40
|
-
* @returns True if action is permitted, false otherwise
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* router.get('/users', async (c) => {
|
|
45
|
-
* if (!can(c, 'read', 'User')) {
|
|
46
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
47
|
-
* }
|
|
48
|
-
*
|
|
49
|
-
* const users = await userService.findAll();
|
|
50
|
-
* return c.json(users);
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export declare function can<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Checks if an action is forbidden (opposite of can).
|
|
57
|
-
*
|
|
58
|
-
* @param context - Hono context containing the ability
|
|
59
|
-
* @param action - CASL action
|
|
60
|
-
* @param subjectType - Subject type string
|
|
61
|
-
* @param subjectData - Optional subject instance data
|
|
62
|
-
* @returns True if action is forbidden, false if permitted
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* router.post('/admin/users', async (c) => {
|
|
67
|
-
* if (cannot(c, 'create', 'User')) {
|
|
68
|
-
* return c.json({ error: 'Forbidden' }, 403);
|
|
69
|
-
* }
|
|
70
|
-
*
|
|
71
|
-
* // ... create user
|
|
72
|
-
* });
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export declare function cannot<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a Prisma where clause using CASL's accessibleBy helper.
|
|
78
|
-
* This is a transparent wrapper that exposes @casl/prisma functionality.
|
|
79
|
-
*
|
|
80
|
-
* Requires @casl/prisma to be installed as a peer dependency.
|
|
81
|
-
*
|
|
82
|
-
* @param context - Hono context containing the ability
|
|
83
|
-
* @param subjectType - Prisma model name (e.g., 'User', 'Post')
|
|
84
|
-
* @param additionalWhere - Optional additional where conditions to combine
|
|
85
|
-
* @returns Prisma where clause that filters by ability permissions
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* import { accessibleBy } from '@casl/prisma';
|
|
90
|
-
*
|
|
91
|
-
* router.get('/posts', async (c) => {
|
|
92
|
-
* const ability = getAbility(c);
|
|
93
|
-
*
|
|
94
|
-
* // Use CASL Prisma integration directly
|
|
95
|
-
* const posts = await prisma.post.findMany({
|
|
96
|
-
* where: accessibleBy(ability).Post
|
|
97
|
-
* });
|
|
98
|
-
*
|
|
99
|
-
* return c.json(posts);
|
|
100
|
-
* });
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* @see https://casl.js.org/v6/en/package/casl-prisma
|
|
104
|
-
*/
|
|
105
|
-
export declare function accessibleWhere<T extends BaseAbility = BaseAbility>(context: Context, subjectType: string, additionalWhere?: object): object;
|
|
106
|
-
//# sourceMappingURL=route-helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route-helpers.d.ts","sourceRoot":"","sources":["../../src/authorization/route-helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC3D,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI,CAUN;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACrD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAKT;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACxD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACjE,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAuBR"}
|