@shivaedev/access 0.6.5 → 0.7.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/CHANGELOG.md +20 -0
- package/README.md +1 -1
- package/dist/refusal.d.ts +9 -0
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +8 -1
- package/dist/refusal.js.map +1 -1
- package/package.json +4 -4
- package/src/refusal.ts +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 - 2026-11-20
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- `MissingPermission` in `refusal.ts` is the `cause` of every `Forbidden` that `forbidden(permission)` builds; its `permission` names the grant that was missing, for logs and for code.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- `forbidden(permission)` says "You do not have permission to do this." instead of naming the permission, because the client shows a shared rejection's message to the person as it arrives.
|
|
12
|
+
|
|
13
|
+
### Breaking
|
|
14
|
+
|
|
15
|
+
- code that read the permission out of a `Forbidden` message reads `error.cause.permission` after checking `error.cause instanceof MissingPermission`; branch on the `Forbidden` tag, never on its message.
|
|
16
|
+
|
|
17
|
+
## 0.6.6 - 2026-11-20
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Update `@shivaedev/errors` from 0.13.1 to 0.14.0.
|
|
22
|
+
|
|
3
23
|
## 0.6.5 - 2026-11-20
|
|
4
24
|
|
|
5
25
|
### Changed
|
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ const decodeRole = Schema.decodeUnknownEffect(Access.Role);
|
|
|
57
57
|
|
|
58
58
|
### Check grants and enforce actions
|
|
59
59
|
|
|
60
|
-
`Access.hasPermission(role, permission)` evaluates the role's grants. The standalone `hasPermission(grants, permission)` from `@shivaedev/access/permission.ts` evaluates resolved grants with the same rule. `requirePermission(user, permission)` from `@shivaedev/access/requirePermission.ts` enforces it for a signed-in user carrying `permissions`; missing grants fail with `Forbidden`. The session boundary authenticates the user before this check. `forbidden(permission)` and `unauthorized()` from `@shivaedev/access/refusal.ts` construct these shared failures from `@shivaedev/errors/taxonomy.ts`.
|
|
60
|
+
`Access.hasPermission(role, permission)` evaluates the role's grants. The standalone `hasPermission(grants, permission)` from `@shivaedev/access/permission.ts` evaluates resolved grants with the same rule. `requirePermission(user, permission)` from `@shivaedev/access/requirePermission.ts` enforces it for a signed-in user carrying `permissions`; missing grants fail with `Forbidden`. The session boundary authenticates the user before this check. `forbidden(permission)` and `unauthorized()` from `@shivaedev/access/refusal.ts` construct these shared failures from `@shivaedev/errors/taxonomy.ts`. Their messages are written for the person using the application, `You do not have permission to do this.` and `Sign in to continue`, because the client shows them as they arrive. A `Forbidden` from `forbidden(permission)` carries a `MissingPermission` as its `cause`, whose `permission` names the grant that was missing, for logs and for code.
|
|
61
61
|
|
|
62
62
|
```ts
|
|
63
63
|
import { requirePermission } from "@shivaedev/access/requirePermission.ts";
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
2
2
|
import type { Permission } from "#permission.ts";
|
|
3
|
+
declare const MissingPermission_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
4
|
+
readonly _tag: "MissingPermission";
|
|
5
|
+
} & Readonly<A>;
|
|
6
|
+
export declare class MissingPermission extends MissingPermission_base<{
|
|
7
|
+
readonly message: string;
|
|
8
|
+
readonly permission: Permission;
|
|
9
|
+
}> {
|
|
10
|
+
}
|
|
3
11
|
export declare function forbidden(permission: Permission): Forbidden;
|
|
4
12
|
export declare function unauthorized(): Unauthorized;
|
|
13
|
+
export {};
|
|
5
14
|
//# sourceMappingURL=refusal.d.ts.map
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;;;;AAEjD,qBAAa,iBAAkB,SAAQ,uBAAsC;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC;CAAG;AAG9I,wBAAgB,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,CAK3D;AAED,wBAAgB,YAAY,IAAI,YAAY,CAE3C"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
1
2
|
import { Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
3
|
+
export class MissingPermission extends Data.TaggedError("MissingPermission") {
|
|
4
|
+
}
|
|
5
|
+
// The message reaches the person verbatim, so the permission they lack travels as the cause, which logs print and the wire leaves out.
|
|
2
6
|
export function forbidden(permission) {
|
|
3
|
-
|
|
7
|
+
const rejection = new Forbidden({ message: "You do not have permission to do this." });
|
|
8
|
+
const missing = new MissingPermission({ message: `Permission required: ${permission.name} (${permission.strength})`, permission });
|
|
9
|
+
Object.defineProperty(rejection, "cause", { configurable: true, value: missing, writable: true });
|
|
10
|
+
return rejection;
|
|
4
11
|
}
|
|
5
12
|
export function unauthorized() {
|
|
6
13
|
return new Unauthorized({ message: "Sign in to continue" });
|
package/dist/refusal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.js","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAGxE,MAAM,UAAU,SAAS,CAAC,UAAsB;IAC/C,
|
|
1
|
+
{"version":3,"file":"refusal.js","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAGxE,MAAM,OAAO,iBAAkB,SAAQ,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAgE;CAAG;AAE9I,uIAAuI;AACvI,MAAM,UAAU,SAAS,CAAC,UAAsB;IAC/C,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,wCAAwC,EAAE,CAAC,CAAC;IACvF,MAAM,OAAO,GAAG,IAAI,iBAAiB,CAAC,EAAE,OAAO,EAAE,wBAAwB,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,QAAQ,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;IACnI,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAClG,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,YAAY;IAC3B,OAAO,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAC,CAAC;AAC7D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/access",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Browser-safe role declarations and permission checks for Effect applications",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/access#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"README.md"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@shivaedev/errors": "0.
|
|
45
|
+
"@shivaedev/errors": "0.14.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@shivaedev/quality": "0.
|
|
49
|
-
"@shivaedev/test-story": "0.
|
|
48
|
+
"@shivaedev/quality": "0.81.1",
|
|
49
|
+
"@shivaedev/test-story": "0.50.2",
|
|
50
50
|
"@types/node": "24.19.2",
|
|
51
51
|
"effect": "4.1.4",
|
|
52
52
|
"typescript": "7.0.2",
|
package/src/refusal.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
1
2
|
import { Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
2
3
|
import type { Permission } from "#permission.ts";
|
|
3
4
|
|
|
5
|
+
export class MissingPermission extends Data.TaggedError("MissingPermission")<{ readonly message: string; readonly permission: Permission }> {}
|
|
6
|
+
|
|
7
|
+
// The message reaches the person verbatim, so the permission they lack travels as the cause, which logs print and the wire leaves out.
|
|
4
8
|
export function forbidden(permission: Permission): Forbidden {
|
|
5
|
-
|
|
9
|
+
const rejection = new Forbidden({ message: "You do not have permission to do this." });
|
|
10
|
+
const missing = new MissingPermission({ message: `Permission required: ${permission.name} (${permission.strength})`, permission });
|
|
11
|
+
Object.defineProperty(rejection, "cause", { configurable: true, value: missing, writable: true });
|
|
12
|
+
return rejection;
|
|
6
13
|
}
|
|
7
14
|
|
|
8
15
|
export function unauthorized(): Unauthorized {
|