@auth-gate/rbac 0.10.0 → 0.12.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/README.md +1 -1
- package/dist/index.d.cts +8 -10
- package/dist/index.d.ts +8 -10
- package/package.json +3 -2
package/README.md
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -94,30 +94,28 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
94
94
|
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
95
95
|
/**
|
|
96
96
|
* Compile-time constraint: if more than one role has `isDefault: true`,
|
|
97
|
-
*
|
|
98
|
-
* produces a descriptive message.
|
|
97
|
+
* produce a descriptive error at the `roles` level naming the conflicting roles.
|
|
99
98
|
*
|
|
100
|
-
*
|
|
99
|
+
* The error string includes the names of all roles that have `isDefault: true`
|
|
100
|
+
* so the developer knows exactly which roles to fix.
|
|
101
101
|
*/
|
|
102
102
|
type ValidateSingleDefault<T> = T extends {
|
|
103
103
|
roles: infer Roles;
|
|
104
104
|
} ? IsUnion<DefaultRoleKeys<Roles>> extends true ? {
|
|
105
|
-
roles: {
|
|
106
|
-
[K in DefaultRoleKeys<Roles> & keyof Roles]: {
|
|
107
|
-
isDefault: "ERROR: Only one role may have isDefault: true";
|
|
108
|
-
};
|
|
109
|
-
};
|
|
105
|
+
roles: `ERROR: multiple roles have isDefault: true ("${DefaultRoleKeys<Roles> & string}"). Only one role may be the default`;
|
|
110
106
|
} : {} : {};
|
|
111
107
|
/** Extract valid action string literals from a resource config. */
|
|
112
108
|
type ValidActions<R> = R extends {
|
|
113
109
|
actions: readonly (infer U)[];
|
|
114
110
|
} ? U & string : never;
|
|
111
|
+
/** Extract action keys that are NOT declared in the resource config. */
|
|
112
|
+
type InvalidActions<Actions, Res extends ResourceConfig> = Exclude<keyof Actions & string, ValidActions<Res>>;
|
|
115
113
|
/**
|
|
116
114
|
* Compile-time constraint: validates grant resource/action keys against
|
|
117
115
|
* declared resources at the type level.
|
|
118
116
|
*
|
|
119
117
|
* - **Invalid resource key** → descriptive error naming the resource.
|
|
120
|
-
* - **Invalid action key** → descriptive error
|
|
118
|
+
* - **Invalid action key** → descriptive error naming the specific invalid key(s).
|
|
121
119
|
* - **Valid grants** → passes through original types transparently.
|
|
122
120
|
*
|
|
123
121
|
* Used as `T & ValidateConfig<T>` in the `defineRbac()` parameter type.
|
|
@@ -136,7 +134,7 @@ type ValidateConfig<T> = T extends {
|
|
|
136
134
|
grants: {
|
|
137
135
|
[ResK in keyof G]: ResK extends keyof R ? keyof G[ResK] extends ValidActions<R[ResK & keyof R]> ? {
|
|
138
136
|
[ActK in keyof G[ResK]]: G[ResK][ActK];
|
|
139
|
-
} : `ERROR:
|
|
137
|
+
} : `ERROR: unknown action(s) "${InvalidActions<G[ResK], R[ResK & keyof R]>}" in "${ResK & string}" grants. Valid actions: ${ValidActions<R[ResK & keyof R]>}` : `ERROR: resource "${ResK & string}" is not declared in resources`;
|
|
140
138
|
};
|
|
141
139
|
} : Roles[RK];
|
|
142
140
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -94,30 +94,28 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
94
94
|
type IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;
|
|
95
95
|
/**
|
|
96
96
|
* Compile-time constraint: if more than one role has `isDefault: true`,
|
|
97
|
-
*
|
|
98
|
-
* produces a descriptive message.
|
|
97
|
+
* produce a descriptive error at the `roles` level naming the conflicting roles.
|
|
99
98
|
*
|
|
100
|
-
*
|
|
99
|
+
* The error string includes the names of all roles that have `isDefault: true`
|
|
100
|
+
* so the developer knows exactly which roles to fix.
|
|
101
101
|
*/
|
|
102
102
|
type ValidateSingleDefault<T> = T extends {
|
|
103
103
|
roles: infer Roles;
|
|
104
104
|
} ? IsUnion<DefaultRoleKeys<Roles>> extends true ? {
|
|
105
|
-
roles: {
|
|
106
|
-
[K in DefaultRoleKeys<Roles> & keyof Roles]: {
|
|
107
|
-
isDefault: "ERROR: Only one role may have isDefault: true";
|
|
108
|
-
};
|
|
109
|
-
};
|
|
105
|
+
roles: `ERROR: multiple roles have isDefault: true ("${DefaultRoleKeys<Roles> & string}"). Only one role may be the default`;
|
|
110
106
|
} : {} : {};
|
|
111
107
|
/** Extract valid action string literals from a resource config. */
|
|
112
108
|
type ValidActions<R> = R extends {
|
|
113
109
|
actions: readonly (infer U)[];
|
|
114
110
|
} ? U & string : never;
|
|
111
|
+
/** Extract action keys that are NOT declared in the resource config. */
|
|
112
|
+
type InvalidActions<Actions, Res extends ResourceConfig> = Exclude<keyof Actions & string, ValidActions<Res>>;
|
|
115
113
|
/**
|
|
116
114
|
* Compile-time constraint: validates grant resource/action keys against
|
|
117
115
|
* declared resources at the type level.
|
|
118
116
|
*
|
|
119
117
|
* - **Invalid resource key** → descriptive error naming the resource.
|
|
120
|
-
* - **Invalid action key** → descriptive error
|
|
118
|
+
* - **Invalid action key** → descriptive error naming the specific invalid key(s).
|
|
121
119
|
* - **Valid grants** → passes through original types transparently.
|
|
122
120
|
*
|
|
123
121
|
* Used as `T & ValidateConfig<T>` in the `defineRbac()` parameter type.
|
|
@@ -136,7 +134,7 @@ type ValidateConfig<T> = T extends {
|
|
|
136
134
|
grants: {
|
|
137
135
|
[ResK in keyof G]: ResK extends keyof R ? keyof G[ResK] extends ValidActions<R[ResK & keyof R]> ? {
|
|
138
136
|
[ActK in keyof G[ResK]]: G[ResK][ActK];
|
|
139
|
-
} : `ERROR:
|
|
137
|
+
} : `ERROR: unknown action(s) "${InvalidActions<G[ResK], R[ResK & keyof R]>}" in "${ResK & string}" grants. Valid actions: ${ValidActions<R[ResK & keyof R]>}` : `ERROR: resource "${ResK & string}" is not declared in resources`;
|
|
140
138
|
};
|
|
141
139
|
} : Roles[RK];
|
|
142
140
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth-gate/rbac",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"description": "RBAC as code for AuthGate — define resources, roles, and permissions in TypeScript and sync them with a single CLI command.",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"exports": {
|
|
6
7
|
".": {
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
"chalk": "^5.4.0",
|
|
24
25
|
"dotenv": "^17.2.4",
|
|
25
26
|
"jiti": "^2.4.0",
|
|
26
|
-
"@auth-gate/core": "0.
|
|
27
|
+
"@auth-gate/core": "0.12.0"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"tsup": "^8.0.0",
|