@hazeljs/casl 0.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +192 -0
  2. package/README.md +363 -0
  3. package/package.json +56 -0
package/LICENSE ADDED
@@ -0,0 +1,192 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2024 HazelJS Team
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ ---
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
package/README.md ADDED
@@ -0,0 +1,363 @@
1
+ # @hazeljs/casl
2
+
3
+ **Attribute-level (record-level) authorization for HazelJS, powered by [CASL](https://casl.js.org).**
4
+
5
+ Where `RoleGuard` asks "is your role high enough?", `@hazeljs/casl` asks:
6
+ > **Can _this_ user perform _this action_ on _this specific record_?**
7
+
8
+ [![npm version](https://img.shields.io/npm/v/@hazeljs/casl.svg)](https://www.npmjs.com/package/@hazeljs/casl)
9
+ [![npm downloads](https://img.shields.io/npm/dm/@hazeljs/casl)](https://www.npmjs.com/package/@hazeljs/casl)
10
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
11
+
12
+ ## Features
13
+
14
+ - **`AbilityFactory`** — abstract base class; extend it to define what each role can do, including **conditional permissions** (`can('update', 'Post', { authorId: user.id })`)
15
+ - **`CaslService`** — injectable service; call `createForUser(user)` anywhere to build an ability for record-level checks in services
16
+ - **`@Ability()`** — parameter decorator that injects the current user's pre-built ability directly into a controller method, so services never need `CaslService` injected
17
+ - **`PoliciesGuard`** — factory guard (`@UseGuards(PoliciesGuard(...handlers))`) that runs policy handlers before the route executes
18
+ - **`@CheckPolicies()`** — method decorator shorthand, equivalent to `@UseGuards(PoliciesGuard(...handlers))`
19
+ - **Function and class handlers** — use inline lambdas or `IPolicyHandler` class instances with injected dependencies
20
+ - **Composes with the full guard stack** — designed to sit after `JwtAuthGuard`, `TenantGuard`, and `RoleGuard`
21
+ - **No direct `@casl/ability` dependency needed** — `MongoAbility`, `AbilityBuilder`, `createMongoAbility`, `subject` are all re-exported from `@hazeljs/casl`
22
+
23
+ ---
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install @hazeljs/casl
29
+ ```
30
+
31
+ `@casl/ability` is a dependency of `@hazeljs/casl` and is installed automatically. You do not need to add it to your own `package.json` — import everything you need directly from `@hazeljs/casl`.
32
+
33
+ ---
34
+
35
+ ## Setup
36
+
37
+ ### 1. Define your ability factory
38
+
39
+ Extend `AbilityFactory` and implement `createForUser` to describe what each user can do. Decorate it with `@Injectable()` so the DI container can resolve it.
40
+
41
+ ```typescript
42
+ import { Injectable } from '@hazeljs/core';
43
+ // All @casl/ability symbols are re-exported — no separate @casl/ability dep needed.
44
+ import { AbilityFactory, MongoAbility, AbilityBuilder, createMongoAbility } from '@hazeljs/casl';
45
+
46
+ type Action = 'create' | 'read' | 'update' | 'delete' | 'manage';
47
+ type Subject = Post | 'Post' | 'all';
48
+ export type AppAbility = MongoAbility<[Action, Subject]>;
49
+
50
+ @Injectable()
51
+ export class AppAbilityFactory extends AbilityFactory<AppAbility> {
52
+ createForUser(user: AuthUser): AppAbility {
53
+ const { can, cannot, build } = new AbilityBuilder<AppAbility>(createMongoAbility);
54
+
55
+ if (user.role === 'admin') {
56
+ can('manage', 'all'); // admin: everything
57
+ } else {
58
+ can('read', 'Post');
59
+ can('update', 'Post', { authorId: user.id }); // own posts only
60
+ cannot('delete', 'Post');
61
+ }
62
+
63
+ return build();
64
+ }
65
+ }
66
+ ```
67
+
68
+ ### 2. Register `CaslModule`
69
+
70
+ Call `CaslModule.forRoot()` once in your root module.
71
+
72
+ ```typescript
73
+ import { HazelModule } from '@hazeljs/core';
74
+ import { CaslModule } from '@hazeljs/casl';
75
+ import { AppAbilityFactory } from './casl/app-ability.factory';
76
+
77
+ @HazelModule({
78
+ imports: [
79
+ CaslModule.forRoot({ abilityFactory: AppAbilityFactory }),
80
+ ],
81
+ })
82
+ export class AppModule {}
83
+ ```
84
+
85
+ ---
86
+
87
+ ## Guards
88
+
89
+ ### `PoliciesGuard`
90
+
91
+ Factory guard — pass one or more policy handlers inline. The guard builds the ability for the current user and runs every handler; if any returns `false` it throws 403.
92
+
93
+ **Requires `JwtAuthGuard` (or any guard that sets `req.user`) to run first.**
94
+
95
+ ```typescript
96
+ import { Controller, Get, Post, UseGuards } from '@hazeljs/core';
97
+ import { JwtAuthGuard } from '@hazeljs/auth';
98
+ import { PoliciesGuard } from '@hazeljs/casl';
99
+ import type { AppAbility } from './casl/app-ability.factory';
100
+
101
+ @UseGuards(JwtAuthGuard)
102
+ @Controller('/posts')
103
+ export class PostsController {
104
+
105
+ @UseGuards(PoliciesGuard<AppAbility>((ability) => ability.can('read', 'Post')))
106
+ @Get('/')
107
+ list() { ... }
108
+
109
+ @UseGuards(PoliciesGuard<AppAbility>((ability) => ability.can('create', 'Post')))
110
+ @Post('/')
111
+ create(@Body() dto: CreatePostDto) { ... }
112
+ }
113
+ ```
114
+
115
+ Errors thrown:
116
+
117
+ | Condition | Status |
118
+ |---|---|
119
+ | No `req.user` (guard order wrong) | 401 |
120
+ | Any handler returns `false` | 403 |
121
+
122
+ ---
123
+
124
+ ### `@CheckPolicies()` (shorthand)
125
+
126
+ Method decorator equivalent to `@UseGuards(PoliciesGuard(...handlers))`. Cleaner syntax, same behaviour.
127
+
128
+ ```typescript
129
+ import { JwtAuthGuard } from '@hazeljs/auth';
130
+ import { CheckPolicies } from '@hazeljs/casl';
131
+ import type { AppAbility } from './casl/app-ability.factory';
132
+
133
+ @UseGuards(JwtAuthGuard)
134
+ @Controller('/posts')
135
+ export class PostsController {
136
+
137
+ @CheckPolicies((ability: AppAbility) => ability.can('read', 'Post'))
138
+ @Get('/')
139
+ list() { ... }
140
+
141
+ @CheckPolicies((ability: AppAbility) => ability.can('create', 'Post'))
142
+ @Post('/')
143
+ create(@Body() dto: CreatePostDto) { ... }
144
+
145
+ // Multiple handlers — all must pass
146
+ @CheckPolicies(
147
+ (ability: AppAbility) => ability.can('read', 'Post'),
148
+ (ability: AppAbility) => ability.can('update', 'Post'),
149
+ )
150
+ @Get('/:id/edit')
151
+ editForm(@Param('id') id: string) { ... }
152
+ }
153
+ ```
154
+
155
+ ---
156
+
157
+ ### Class-instance handlers (`IPolicyHandler`)
158
+
159
+ For handlers that need constructor-injected dependencies, implement the `IPolicyHandler` interface and pass an instance:
160
+
161
+ ```typescript
162
+ import { Injectable } from '@hazeljs/core';
163
+ import { IPolicyHandler } from '@hazeljs/casl';
164
+ import type { AppAbility } from './casl/app-ability.factory';
165
+
166
+ @Injectable()
167
+ export class CanManagePost implements IPolicyHandler<AppAbility> {
168
+ constructor(private readonly config: SomeService) {}
169
+
170
+ handle(ability: AppAbility): boolean {
171
+ return ability.can('manage', 'Post');
172
+ }
173
+ }
174
+
175
+ // Usage
176
+ @CheckPolicies(new CanManagePost())
177
+ @Delete('/:id')
178
+ remove(@Param('id') id: string) { ... }
179
+ ```
180
+
181
+ ---
182
+
183
+ ### Combining with other guards
184
+
185
+ Guards run left-to-right. The recommended order:
186
+
187
+ ```typescript
188
+ @UseGuards(
189
+ JwtAuthGuard, // 1. verify token, attach req.user
190
+ TenantGuard({ source: 'param', key: 'orgId' }), // 2. enforce tenant isolation
191
+ RoleGuard('user'), // 3. coarse role check
192
+ )
193
+ @Controller('/orgs/:orgId/posts')
194
+ export class PostsController {
195
+
196
+ @CheckPolicies((ability: AppAbility) => ability.can('read', 'Post'))
197
+ @Get('/')
198
+ list() { ... }
199
+
200
+ @CheckPolicies((ability: AppAbility) => ability.can('create', 'Post'))
201
+ @Post('/')
202
+ create(@Body() dto: CreatePostDto) { ... }
203
+ }
204
+ ```
205
+
206
+ ```
207
+ Request
208
+ → JwtAuthGuard — who are you?
209
+ → TenantGuard — does this belong to your org?
210
+ → RoleGuard — is your role high enough?
211
+ → @CheckPolicies — can you act on THIS record?
212
+ → Controller method
213
+ ```
214
+
215
+ ---
216
+
217
+ ## `@Ability()` — inject the ability directly
218
+
219
+ `@Ability()` is a **parameter decorator** that resolves `CaslService.createForUser(req.user)` once per request and injects the result straight into your controller method. Services receive the pre-built ability instead of the raw user, keeping business logic clean.
220
+
221
+ ```typescript
222
+ // posts.controller.ts
223
+ import { Controller, Patch, Delete, Param, Body, UseGuards } from '@hazeljs/core';
224
+ import { JwtAuthGuard, RoleGuard } from '@hazeljs/auth';
225
+ import { Ability } from '@hazeljs/casl';
226
+ import type { AppAbility } from './casl/app-ability.factory';
227
+
228
+ @UseGuards(JwtAuthGuard, RoleGuard('user'))
229
+ @Controller('/posts')
230
+ export class PostsController {
231
+ constructor(private readonly postsService: PostsService) {}
232
+
233
+ @Patch('/:id')
234
+ update(
235
+ @Ability() ability: AppAbility, // ← resolved from req.user automatically
236
+ @Param('id') id: string,
237
+ @Body() dto: UpdatePostDto,
238
+ ) {
239
+ return this.postsService.update(ability, id, dto);
240
+ }
241
+
242
+ @Delete('/:id')
243
+ remove(
244
+ @Ability() ability: AppAbility,
245
+ @Param('id') id: string,
246
+ ) {
247
+ return this.postsService.remove(ability, id);
248
+ }
249
+ }
250
+ ```
251
+
252
+ The service just receives an `AppAbility` — no `CaslService` injection needed:
253
+
254
+ ```typescript
255
+ // posts.service.ts
256
+ import { Injectable } from '@hazeljs/core';
257
+ import { subject } from '@hazeljs/casl'; // re-exported — no @casl/ability dep needed
258
+ import type { AppAbility } from './casl/app-ability.factory';
259
+
260
+ @Injectable()
261
+ export class PostsService {
262
+ constructor(private readonly postsRepo: PostsRepository) {}
263
+
264
+ async update(ability: AppAbility, postId: string, dto: UpdatePostDto) {
265
+ const post = await this.postsRepo.findById(postId);
266
+
267
+ // subject() tags the plain object so CASL evaluates conditional rules correctly.
268
+ if (!ability.can('update', subject('Post', post))) {
269
+ throw Object.assign(new Error('You can only edit your own posts'), { status: 403 });
270
+ }
271
+ return this.postsRepo.update(postId, dto);
272
+ }
273
+
274
+ async remove(ability: AppAbility, postId: string) {
275
+ const post = await this.postsRepo.findById(postId);
276
+
277
+ if (!ability.can('delete', subject('Post', post))) {
278
+ throw Object.assign(new Error('Forbidden'), { status: 403 });
279
+ }
280
+ return this.postsRepo.delete(postId);
281
+ }
282
+ }
283
+ ```
284
+
285
+ > **When to use `@Ability()` vs `CaslService`**
286
+ > Use `@Ability()` when the controller passes the ability to a single service. Use `CaslService` directly when a service is called from multiple places (background jobs, other services) and the caller may not hold an ability object.
287
+
288
+ ---
289
+
290
+ ## Record-level checks in services (manual approach)
291
+
292
+ If you prefer to inject `CaslService` directly — for example, when a service is called from multiple sources — the pattern is the same as above but the ability is built inside the service.
293
+
294
+ ```typescript
295
+ import { Injectable } from '@hazeljs/core';
296
+ import { CaslService, subject } from '@hazeljs/casl';
297
+ import type { AppAbility } from './casl/app-ability.factory';
298
+
299
+ @Injectable()
300
+ export class PostsService {
301
+ constructor(
302
+ private readonly postsRepo: PostsRepository,
303
+ private readonly casl: CaslService<AppAbility>,
304
+ ) {}
305
+
306
+ async update(user: Record<string, unknown>, postId: string, dto: UpdatePostDto) {
307
+ const post = await this.postsRepo.findById(postId);
308
+ const ability = this.casl.createForUser(user);
309
+
310
+ if (!ability.can('update', subject('Post', post))) {
311
+ throw Object.assign(new Error('You can only edit your own posts'), { status: 403 });
312
+ }
313
+ return this.postsRepo.update(postId, dto);
314
+ }
315
+ }
316
+ ```
317
+
318
+ > **Why use `subject()`?** When you define conditions like `can('update', 'Post', { authorId: user.id })`, CASL needs to know the subject type of the plain object you pass to `ability.can()`. `subject('Post', post)` tags the object without mutating it.
319
+
320
+ ---
321
+
322
+ ## `CaslService` API
323
+
324
+ ```typescript
325
+ import { CaslService } from '@hazeljs/casl';
326
+
327
+ // Inject and call createForUser to get an ability for the current user
328
+ const ability = this.casl.createForUser(user);
329
+
330
+ ability.can('read', 'Post') // true / false
331
+ ability.can('update', subject('Post', post)) // checks conditions
332
+ ability.cannot('delete', 'Post') // negation check
333
+ ```
334
+
335
+ ---
336
+
337
+ ## `AbilityFactory` API
338
+
339
+ ```typescript
340
+ import { AbilityFactory } from '@hazeljs/casl';
341
+
342
+ // Extend this abstract class
343
+ abstract class AbilityFactory<A extends AnyAbility> {
344
+ abstract createForUser(user: Record<string, unknown>): A;
345
+ }
346
+ ```
347
+
348
+ ---
349
+
350
+ ## `CaslModule.forRoot()` options
351
+
352
+ | Option | Type | Required | Description |
353
+ |---|---|---|---|
354
+ | `abilityFactory` | `new (...args: any[]) => AbilityFactory<A>` | ✓ | Your factory class (must be `@Injectable()`) |
355
+
356
+ ---
357
+
358
+ ## Links
359
+
360
+ - [Documentation](https://hazeljs.com/docs/packages/casl)
361
+ - [GitHub](https://github.com/hazel-js/hazeljs)
362
+ - [Issues](https://github.com/hazel-js/hazeljs/issues)
363
+ - [Discord](https://discord.com/channels/1448263814238965833/1448263814859456575)
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@hazeljs/casl",
3
+ "version": "0.2.0-alpha.1",
4
+ "description": "Attribute-level (resource-level) authorization for HazelJS via CASL",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "test": "jest --coverage --passWithNoTests",
13
+ "lint": "eslint \"src/**/*.ts\"",
14
+ "lint:fix": "eslint \"src/**/*.ts\" --fix",
15
+ "clean": "rm -rf dist"
16
+ },
17
+ "dependencies": {
18
+ "@casl/ability": "^6.7.3"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^20.17.50",
22
+ "@typescript-eslint/eslint-plugin": "^8.18.2",
23
+ "@typescript-eslint/parser": "^8.18.2",
24
+ "eslint": "^8.56.0",
25
+ "jest": "^29.7.0",
26
+ "ts-jest": "^29.1.2",
27
+ "typescript": "^5.3.3"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/hazel-js/hazeljs.git",
35
+ "directory": "packages/casl"
36
+ },
37
+ "keywords": [
38
+ "hazeljs",
39
+ "casl",
40
+ "authorization",
41
+ "permissions",
42
+ "rbac",
43
+ "abac",
44
+ "policy"
45
+ ],
46
+ "author": "Muhammad Arslan <muhammad.arslan@hazeljs.com>",
47
+ "license": "Apache-2.0",
48
+ "bugs": {
49
+ "url": "https://github.com/hazeljs/hazel-js/issues"
50
+ },
51
+ "homepage": "https://hazeljs.com",
52
+ "peerDependencies": {
53
+ "@hazeljs/core": ">=0.2.0-beta.0"
54
+ },
55
+ "gitHead": "cbc5ee2c12ced28fd0576faf13c5f078c1e8421e"
56
+ }