@react-protected/core 0.2.0-beta.2 → 0.2.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 +30 -0
- package/dist/createGuard.d.ts +9 -0
- package/dist/types.d.ts +46 -0
- package/package.json +3 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @react-protected/core
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 05cda4d: Update roadmap and docs
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 4b835f6: Docs added
|
|
12
|
+
- 11a6537: Configure Changesets-based release automation and public package publish metadata.
|
|
13
|
+
|
|
14
|
+
## 0.2.0-beta.2
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 05cda4d: Update roadmap and docs
|
|
19
|
+
|
|
20
|
+
## 0.1.1-beta.1
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 4b835f6: Docs added
|
|
25
|
+
|
|
26
|
+
## 0.1.1-beta.0
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- 11a6537: Configure Changesets-based release automation and public package publish metadata.
|
package/dist/createGuard.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { Guard, GuardOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a guard that evaluates access against the current user.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam TUser - User shape returned by `getUser`.
|
|
6
|
+
* @param options - Access callbacks and user accessors used by the guard.
|
|
7
|
+
* @returns A reusable guard with resolved defaults for authentication, role, and permission checks.
|
|
8
|
+
* @remarks When `roles` or `permissions` are provided without `access`, the guard treats the config
|
|
9
|
+
* as authenticated-only.
|
|
10
|
+
*/
|
|
2
11
|
export declare function createGuard<TUser = unknown>(options: GuardOptions<TUser>): Guard<TUser>;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Access level handled by the framework-agnostic guard.
|
|
3
|
+
*/
|
|
1
4
|
export type AccessLevel = 'public' | 'authenticated';
|
|
5
|
+
/**
|
|
6
|
+
* Access requirements consumed by `guard.check()` and adapter components.
|
|
7
|
+
*/
|
|
2
8
|
export type AccessConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* Declares whether access is public or requires an authenticated user.
|
|
11
|
+
* Defaults to `'public'` when omitted.
|
|
12
|
+
*/
|
|
3
13
|
access?: AccessLevel;
|
|
14
|
+
/**
|
|
15
|
+
* Roles that must be satisfied by your `hasRole` callback.
|
|
16
|
+
*/
|
|
4
17
|
roles?: Array<string>;
|
|
18
|
+
/**
|
|
19
|
+
* Permissions that must be satisfied by your `hasPermission` callback.
|
|
20
|
+
*/
|
|
5
21
|
permissions?: Array<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Optional metadata for application-specific access logic.
|
|
24
|
+
*/
|
|
6
25
|
meta?: Record<string, unknown>;
|
|
7
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Result returned by `guard.check()`.
|
|
29
|
+
*/
|
|
8
30
|
export type AccessResult = {
|
|
9
31
|
allowed: true;
|
|
10
32
|
} | {
|
|
@@ -14,13 +36,37 @@ export type AccessResult = {
|
|
|
14
36
|
allowed: false;
|
|
15
37
|
reason: 'forbidden';
|
|
16
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* Callbacks and accessors used to create a guard instance.
|
|
41
|
+
*/
|
|
17
42
|
export type GuardOptions<TUser = unknown> = {
|
|
43
|
+
/**
|
|
44
|
+
* Returns the current user or `null` when no user is available.
|
|
45
|
+
*/
|
|
18
46
|
getUser: () => TUser | null;
|
|
47
|
+
/**
|
|
48
|
+
* Overrides the default authenticated check of `user !== null`.
|
|
49
|
+
*/
|
|
19
50
|
isAuthenticated?: (user: TUser | null) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Determines whether the current user satisfies the requested roles.
|
|
53
|
+
*/
|
|
20
54
|
hasRole?: (user: TUser, roles: Array<string>) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Determines whether the current user satisfies the requested permissions.
|
|
57
|
+
*/
|
|
21
58
|
hasPermission?: (user: TUser, permissions: Array<string>) => boolean;
|
|
22
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Guard instance returned by `createGuard()`.
|
|
62
|
+
*/
|
|
23
63
|
export type Guard<TUser = unknown> = {
|
|
64
|
+
/**
|
|
65
|
+
* Evaluates whether the current user satisfies the provided access config.
|
|
66
|
+
*/
|
|
24
67
|
check: (config: AccessConfig) => AccessResult;
|
|
68
|
+
/**
|
|
69
|
+
* Resolved guard callbacks with built-in defaults applied.
|
|
70
|
+
*/
|
|
25
71
|
options: Required<GuardOptions<TUser>>;
|
|
26
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-protected/core",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Framework-agnostic route protection logic",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"CHANGELOG.md"
|
|
26
27
|
],
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"vite": "^5.0.0",
|