-
-
Notifications
You must be signed in to change notification settings - Fork 10
refactor(deps): clean deprecated dependencies — acl→casl, joi→zod, body-parser, swig #3134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7b0dbe5
chore(vscode): enable Copilot for json files to match Vue stack
PierreBrisorgueil d787533
refactor(auth): replace acl with @casl/ability, add auth rate limiting
PierreBrisorgueil 20418fc
refactor(deps): replace @hapi/joi, body-parser, swig with zod + expre…
PierreBrisorgueil 7b07767
fix(review): address Copilot comments and improve coverage
PierreBrisorgueil 2da068c
test(auth): cover AppError catch path in checkOAuthUserProfile
PierreBrisorgueil d431d16
fix(tasks): remove dead model.isValid on DELETE route
PierreBrisorgueil fb82bf1
test(auth): cover oauthCallback tokenCookieOptions branches
PierreBrisorgueil a26052f
fix(test): drop unused arrow-fn params to satisfy no-unused-vars lint
PierreBrisorgueil ca1f850
fix(validation): address Copilot review comments
PierreBrisorgueil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Migrations | ||
|
|
||
| Breaking changes and upgrade notes for downstream projects. | ||
|
|
||
| --- | ||
|
|
||
| ## `acl` → `@casl/ability` (2026-02-20) | ||
|
|
||
| `acl@0.4.11` (unmaintained since 2018) has been replaced by `@casl/ability`. | ||
|
|
||
| ### What changed | ||
|
|
||
| - `lib/middlewares/policy.js` no longer exports `Acl`. | ||
| - Policy files now call `policy.registerRules([...])` instead of `policy.Acl.allow([...])`. | ||
| - `isAllowed` and `isOwner` middleware signatures are **unchanged** — routes do not need to be updated. | ||
|
|
||
| ### HTTP method → CASL action mapping | ||
|
|
||
| | HTTP method | CASL action | | ||
| |-----------------|-------------| | ||
| | `GET` | `read` | | ||
| | `POST` | `create` | | ||
| | `PUT` / `PATCH` | `update` | | ||
| | `DELETE` | `delete` | | ||
| | `*` (all) | `manage` | | ||
|
|
||
| ### Migration example | ||
|
|
||
| **Before (`acl`):** | ||
|
|
||
| ```js | ||
| import policy from '../../../lib/middlewares/policy.js'; | ||
|
|
||
| const invokeRolesPolicies = () => { | ||
| policy.Acl.allow([ | ||
| { | ||
| roles: ['user'], | ||
| allows: [ | ||
| { resources: '/api/tasks', permissions: '*' }, | ||
| { resources: '/api/tasks/:taskId', permissions: '*' }, | ||
| ], | ||
| }, | ||
| { | ||
| roles: ['guest'], | ||
| allows: [ | ||
| { resources: '/api/tasks/stats', permissions: ['get'] }, | ||
| { resources: '/api/tasks', permissions: ['get'] }, | ||
| { resources: '/api/tasks/:taskId', permissions: ['get'] }, | ||
| ], | ||
| }, | ||
| ]); | ||
| }; | ||
|
|
||
| export default { invokeRolesPolicies }; | ||
| ``` | ||
|
|
||
| **After (`@casl/ability`):** | ||
|
|
||
| ```js | ||
| import policy from '../../../lib/middlewares/policy.js'; | ||
|
|
||
| const invokeRolesPolicies = () => { | ||
| policy.registerRules([ | ||
| { roles: ['user'], actions: 'manage', subject: '/api/tasks' }, | ||
| { roles: ['user'], actions: 'manage', subject: '/api/tasks/:taskId' }, | ||
| { roles: ['guest'], actions: ['read'], subject: '/api/tasks/stats' }, | ||
| { roles: ['guest'], actions: ['read'], subject: '/api/tasks' }, | ||
| { roles: ['guest'], actions: ['read'], subject: '/api/tasks/:taskId' }, | ||
| ]); | ||
| }; | ||
|
|
||
| export default { invokeRolesPolicies }; | ||
| ``` | ||
|
|
||
| ### `defineAbilityFor` is now async | ||
|
|
||
| `policy.defineAbilityFor(user)` returns a `Promise<Ability>` (lazy-loads `@casl/ability` on first call). Express `isAllowed` middleware is `async` and works unchanged. If you test `defineAbilityFor` directly, `await` it: | ||
|
|
||
| ```js | ||
| // Unit test | ||
| const ability = await policy.defineAbilityFor(null); | ||
| expect(ability.can('read', '/api/tasks')).toBe(true); | ||
| ``` | ||
|
|
||
| > **Jest note**: `policy.js` must be a static top-level import in the test file (not only reached via dynamic `import()`). This pre-loads the module in Jest's VM registry before policy files are dynamically imported in `beforeAll`. | ||
| > ```js | ||
| > import policy from '../../../lib/middlewares/policy.js'; // required at top level | ||
| > ``` | ||
|
|
||
| ### Steps for downstream projects | ||
|
|
||
| 1. `npm remove acl && npm install @casl/ability` | ||
| 2. Update every `modules/*/policies/*.policy.js` following the pattern above. | ||
| 3. Remove any direct use of `policy.Acl` (it is no longer exported). | ||
| 4. If you have unit tests that call `defineAbilityFor`, add `import policy from '...policy.js'` as a top-level static import and `await` the call. | ||
| 5. Run `npm run lint && npm test` — all existing 403/200 assertions should pass unchanged. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** | ||
| * Module dependencies | ||
| */ | ||
| import zxcvbn from 'zxcvbn'; | ||
| import config from '../../config/index.js'; | ||
| import { z } from 'zod'; | ||
|
|
||
| /** | ||
| * @desc Zod superRefine for zxcvbn password strength | ||
| */ | ||
| const passwordRefinement = (val, ctx) => { | ||
| if (config.zxcvbn.forbiddenPasswords.includes(val)) { | ||
| ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'password is too common' }); | ||
| } else if (zxcvbn(val).score < config.zxcvbn.minimumScore) { | ||
| ctx.addIssue({ code: z.ZodIssueCode.custom, message: `password must have a strength of at least ${config.zxcvbn.minimumScore}` }); | ||
| } | ||
| }; | ||
|
|
||
| export default { passwordRefinement }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.