@zap-studio/permit 0.3.2 → 0.3.3
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 +8 -4
- package/README.md +5 -3
- package/dist/errors.d.mts +13 -3
- package/dist/errors.d.mts.map +1 -1
- package/dist/errors.mjs +10 -0
- package/dist/errors.mjs.map +1 -1
- package/dist/helpers.d.mts +27 -22
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +7 -2
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.d.mts +244 -239
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +79 -70
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +105 -106
- package/dist/types.d.mts.map +1 -1
- package/package.json +6 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## @zap-studio/permit@0.3.3
|
|
2
|
+
|
|
3
|
+
### Migrate to ultracite lint/format
|
|
4
|
+
|
|
5
|
+
Internal formatting and lint cleanup only. No public API or behavior change.
|
|
6
|
+
|
|
1
7
|
# @zap-studio/permit
|
|
2
8
|
|
|
3
9
|
## 0.3.2
|
|
@@ -29,11 +35,9 @@
|
|
|
29
35
|
|
|
30
36
|
- fe60f55: Change `policy.can()` to use a single permission string plus the resource object.
|
|
31
37
|
|
|
32
|
-
`policy.can(ctx, "read", "post", post)` is replaced by
|
|
33
|
-
`policy.can(ctx, "post:read", post)`.
|
|
38
|
+
`policy.can(ctx, "read", "post", post)` is replaced by `policy.can(ctx, "post:read", post)`.
|
|
34
39
|
|
|
35
|
-
This is a breaking API change in the `0.x` line. Docs and examples now use the
|
|
36
|
-
new permission-string format consistently.
|
|
40
|
+
This is a breaking API change in the `0.x` line. Docs and examples now use the new permission-string format consistently.
|
|
37
41
|
|
|
38
42
|
## 0.2.2
|
|
39
43
|
|
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ Returns a condition that is true only if all conditions are true.
|
|
|
126
126
|
```ts
|
|
127
127
|
const isOwnerAndPublished = and(
|
|
128
128
|
(ctx, action, resource) => ctx.user.id === resource.authorId,
|
|
129
|
-
(ctx, action, resource) => resource.status === "published"
|
|
129
|
+
(ctx, action, resource) => resource.status === "published"
|
|
130
130
|
);
|
|
131
131
|
```
|
|
132
132
|
|
|
@@ -137,7 +137,7 @@ Returns a condition that is true if any condition is true.
|
|
|
137
137
|
```ts
|
|
138
138
|
const isOwnerOrAdmin = or(
|
|
139
139
|
(ctx, action, resource) => ctx.user.id === resource.authorId,
|
|
140
|
-
(ctx, action, resource) => ctx.user.role === "admin"
|
|
140
|
+
(ctx, action, resource) => ctx.user.role === "admin"
|
|
141
141
|
);
|
|
142
142
|
```
|
|
143
143
|
|
|
@@ -146,7 +146,9 @@ const isOwnerOrAdmin = or(
|
|
|
146
146
|
Returns a condition that negates another condition.
|
|
147
147
|
|
|
148
148
|
```ts
|
|
149
|
-
const isNotOwner = not(
|
|
149
|
+
const isNotOwner = not(
|
|
150
|
+
(ctx, action, resource) => ctx.user.id === resource.authorId
|
|
151
|
+
);
|
|
150
152
|
```
|
|
151
153
|
|
|
152
154
|
### Context Helpers
|
package/dist/errors.d.mts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
//#region src/errors.d.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
|
|
3
|
+
* Error primitives for policy evaluation and configuration failures.
|
|
4
|
+
*
|
|
5
|
+
* @module @zap-studio/permit/errors
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Represents an error that occurs during policy evaluation or enforcement.
|
|
9
|
+
* Use this error to indicate issues related to policy logic, configuration, or execution.
|
|
10
|
+
*/
|
|
6
11
|
declare class PolicyError extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a policy error with a human-readable message.
|
|
14
|
+
*
|
|
15
|
+
* @param message - Error message describing the policy failure.
|
|
16
|
+
*/
|
|
7
17
|
constructor(message: string);
|
|
8
18
|
}
|
|
9
19
|
//#endregion
|
package/dist/errors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.d.mts","names":[],"sources":["../src/errors.ts"],"mappings":";;;;;;;;;;cAUa,oBAAoB;;;;;;EAM/B,YAAY"}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
//#region src/errors.ts
|
|
2
2
|
/**
|
|
3
|
+
* Error primitives for policy evaluation and configuration failures.
|
|
4
|
+
*
|
|
5
|
+
* @module @zap-studio/permit/errors
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
3
8
|
* Represents an error that occurs during policy evaluation or enforcement.
|
|
4
9
|
* Use this error to indicate issues related to policy logic, configuration, or execution.
|
|
5
10
|
*/
|
|
6
11
|
var PolicyError = class extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a policy error with a human-readable message.
|
|
14
|
+
*
|
|
15
|
+
* @param message - Error message describing the policy failure.
|
|
16
|
+
*/
|
|
7
17
|
constructor(message) {
|
|
8
18
|
super(message);
|
|
9
19
|
this.name = "PolicyError";
|
package/dist/errors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Represents an error that occurs during policy evaluation or enforcement.\n * Use this error to indicate issues related to policy logic, configuration, or execution.\n */\nexport class PolicyError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PolicyError\";\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/**\n * Error primitives for policy evaluation and configuration failures.\n *\n * @module @zap-studio/permit/errors\n */\n\n/**\n * Represents an error that occurs during policy evaluation or enforcement.\n * Use this error to indicate issues related to policy logic, configuration, or execution.\n */\nexport class PolicyError extends Error {\n /**\n * Creates a policy error with a human-readable message.\n *\n * @param message - Error message describing the policy failure.\n */\n constructor(message: string) {\n super(message);\n this.name = \"PolicyError\";\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,IAAa,cAAb,cAAiC,MAAM;;;;;;CAMrC,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF"}
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
//#region src/helpers.d.ts
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* type
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
* Helper utilities for permit consumers.
|
|
4
|
+
*
|
|
5
|
+
* @module @zap-studio/permit/helpers
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Ensures that a value of type `never` is actually never encountered at runtime.
|
|
9
|
+
* This is useful for exhaustive checks on discriminated unions.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* type Action = 'read' | 'write'
|
|
14
|
+
*
|
|
15
|
+
* function performAction(action: Action) {
|
|
16
|
+
* switch (action) {
|
|
17
|
+
* case 'read':
|
|
18
|
+
* console.log('Reading...')
|
|
19
|
+
* break
|
|
20
|
+
* case 'write':
|
|
21
|
+
* console.log('Writing...')
|
|
22
|
+
* break
|
|
23
|
+
* default:
|
|
24
|
+
* assertNever(action) // TypeScript will error if a new Action is added but not handled
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare const assertNever: (value: never) => never;
|
|
25
30
|
//#endregion
|
|
26
31
|
export { assertNever };
|
|
27
32
|
//# sourceMappingURL=helpers.d.mts.map
|
package/dist/helpers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.mts","names":[],"sources":["../src/helpers.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;cA4Ba,cAAe"}
|
package/dist/helpers.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
//#region src/helpers.ts
|
|
2
2
|
/**
|
|
3
|
+
* Helper utilities for permit consumers.
|
|
4
|
+
*
|
|
5
|
+
* @module @zap-studio/permit/helpers
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
3
8
|
* Ensures that a value of type `never` is actually never encountered at runtime.
|
|
4
9
|
* This is useful for exhaustive checks on discriminated unions.
|
|
5
10
|
*
|
|
@@ -21,9 +26,9 @@
|
|
|
21
26
|
* }
|
|
22
27
|
* ```
|
|
23
28
|
*/
|
|
24
|
-
|
|
29
|
+
const assertNever = (value) => {
|
|
25
30
|
throw new Error(`Unexpected value: ${String(value)}`);
|
|
26
|
-
}
|
|
31
|
+
};
|
|
27
32
|
//#endregion
|
|
28
33
|
export { assertNever };
|
|
29
34
|
|
package/dist/helpers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["/**\n * Ensures that a value of type `never` is actually never encountered at runtime.\n * This is useful for exhaustive checks on discriminated unions.\n *\n * @example\n * ```ts\n * type Action = 'read' | 'write'\n *\n * function performAction(action: Action) {\n * switch (action) {\n * case 'read':\n * console.log('Reading...')\n * break\n * case 'write':\n * console.log('Writing...')\n * break\n * default:\n * assertNever(action) // TypeScript will error if a new Action is added but not handled\n * }\n * }\n * ```\n */\nexport
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["/**\n * Helper utilities for permit consumers.\n *\n * @module @zap-studio/permit/helpers\n */\n\n/**\n * Ensures that a value of type `never` is actually never encountered at runtime.\n * This is useful for exhaustive checks on discriminated unions.\n *\n * @example\n * ```ts\n * type Action = 'read' | 'write'\n *\n * function performAction(action: Action) {\n * switch (action) {\n * case 'read':\n * console.log('Reading...')\n * break\n * case 'write':\n * console.log('Writing...')\n * break\n * default:\n * assertNever(action) // TypeScript will error if a new Action is added but not handled\n * }\n * }\n * ```\n */\nexport const assertNever = (value: never): never => {\n throw new Error(`Unexpected value: ${String(value)}`);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,eAAe,UAAwB;CAClD,MAAM,IAAI,MAAM,qBAAqB,OAAO,KAAK,GAAG;AACtD"}
|