@react-protected/react 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 +43 -0
- package/dist/AccessProvider.d.ts +14 -0
- package/dist/HasAccess.d.ts +12 -0
- package/dist/testing.d.ts +21 -0
- package/dist/types.d.ts +57 -3
- package/package.json +4 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @react-protected/react
|
|
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
|
+
- Updated dependencies [4b835f6]
|
|
14
|
+
- Updated dependencies [11a6537]
|
|
15
|
+
- Updated dependencies [05cda4d]
|
|
16
|
+
- @react-protected/core@0.2.0
|
|
17
|
+
|
|
18
|
+
## 0.2.0-beta.2
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 05cda4d: Update roadmap and docs
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [05cda4d]
|
|
27
|
+
- @react-protected/core@0.2.0-beta.2
|
|
28
|
+
|
|
29
|
+
## 0.1.1-beta.1
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- 4b835f6: Docs added
|
|
34
|
+
- Updated dependencies [4b835f6]
|
|
35
|
+
- @react-protected/core@0.1.1-beta.1
|
|
36
|
+
|
|
37
|
+
## 0.1.1-beta.0
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- 11a6537: Configure Changesets-based release automation and public package publish metadata.
|
|
42
|
+
- Updated dependencies [11a6537]
|
|
43
|
+
- @react-protected/core@0.1.1-beta.0
|
package/dist/AccessProvider.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import { AccessContextValue, AccessProviderProps } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Provides access control configuration to the React subtree.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam TUser - User shape returned by `getUser`.
|
|
6
|
+
* @param props - Guard callbacks, navigation settings, and descendant elements.
|
|
7
|
+
* @returns A context provider that enables access-aware hooks and components.
|
|
8
|
+
*/
|
|
2
9
|
export declare function AccessProvider<TUser = unknown>({ children, loginPath, forbiddenPath, defaultPath, callbackUrlParam, shouldAddCallbackUrl, getUser, isAuthenticated, hasRole, hasPermission, }: AccessProviderProps<TUser>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the active access context from `AccessProvider`.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam TUser - User shape stored in the access context.
|
|
14
|
+
* @returns The guard instance and navigation settings for the current subtree.
|
|
15
|
+
* @throws {Error} When called outside an `AccessProvider`.
|
|
16
|
+
*/
|
|
3
17
|
export declare function useAccess<TUser = unknown>(): AccessContextValue<TUser>;
|
package/dist/HasAccess.d.ts
CHANGED
|
@@ -3,6 +3,18 @@ import { RouteProtection } from './types';
|
|
|
3
3
|
type HasAccessProps = RouteProtection & {
|
|
4
4
|
children?: ReactNode;
|
|
5
5
|
};
|
|
6
|
+
/**
|
|
7
|
+
* Returns `true` when the current user satisfies the provided access config.
|
|
8
|
+
*
|
|
9
|
+
* @param config - Access requirements to evaluate with the active guard.
|
|
10
|
+
* @returns `true` when access is allowed, otherwise `false`.
|
|
11
|
+
*/
|
|
6
12
|
export declare function useHasAccess(config: RouteProtection): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Renders its children only when the current user satisfies the access config.
|
|
15
|
+
*
|
|
16
|
+
* @param props - Access requirements and the children to render when allowed.
|
|
17
|
+
* @returns The provided children when access is allowed, otherwise `null`.
|
|
18
|
+
*/
|
|
7
19
|
export declare function HasAccess({ access, roles, permissions, meta, children }: HasAccessProps): string | number | boolean | import('react').ReactElement<any, string | import('react').JSXElementConstructor<any>> | Iterable<ReactNode> | null;
|
|
8
20
|
export {};
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
import { GuardOptions } from '@react-protected/core';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { NavigationConfig } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Props accepted by `MockAccessProvider`.
|
|
6
|
+
*/
|
|
4
7
|
export type MockAccessProviderProps<TUser = unknown> = Partial<GuardOptions<TUser>> & NavigationConfig & {
|
|
8
|
+
/**
|
|
9
|
+
* User returned by the default `getUser` implementation.
|
|
10
|
+
*/
|
|
5
11
|
user?: TUser | null;
|
|
12
|
+
/**
|
|
13
|
+
* Default outcome used by generated access callbacks when explicit callbacks are not provided.
|
|
14
|
+
*/
|
|
6
15
|
allowed?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* React subtree that consumes the mocked access context.
|
|
18
|
+
*/
|
|
7
19
|
children?: ReactNode;
|
|
8
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Test helper that provides a predictable access context.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam TUser - User shape returned by the mocked `getUser`.
|
|
25
|
+
* @param props - Mocked user, optional callback overrides, navigation settings, and children.
|
|
26
|
+
* @returns An `AccessProvider` configured for deterministic tests.
|
|
27
|
+
* @remarks When explicit callbacks are omitted, authentication, role, and permission checks all
|
|
28
|
+
* resolve to the `allowed` flag.
|
|
29
|
+
*/
|
|
9
30
|
export declare function MockAccessProvider<TUser = unknown>({ user, allowed, children, getUser, isAuthenticated, hasRole, hasPermission, loginPath, forbiddenPath, defaultPath, callbackUrlParam, shouldAddCallbackUrl, }: MockAccessProviderProps<TUser>): import("react/jsx-runtime").JSX.Element;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,24 +1,78 @@
|
|
|
1
|
-
import { AccessConfig, Guard, GuardOptions } from '@react-protected/core';
|
|
1
|
+
import { AccessConfig as CoreAccessConfig, Guard, GuardOptions } from '@react-protected/core';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Access requirements consumed by React hooks and components in this package.
|
|
5
|
+
*/
|
|
6
|
+
export type RouteProtection = CoreAccessConfig;
|
|
7
|
+
/**
|
|
8
|
+
* Navigation paths used when access-aware components need to redirect.
|
|
9
|
+
*/
|
|
4
10
|
export type NavigationConfig = {
|
|
11
|
+
/**
|
|
12
|
+
* Redirect target for unauthenticated users.
|
|
13
|
+
*/
|
|
5
14
|
loginPath?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Redirect target when the user is authenticated but lacks access.
|
|
17
|
+
*/
|
|
6
18
|
forbiddenPath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Redirect target for authenticated users visiting guest-only screens.
|
|
21
|
+
*/
|
|
7
22
|
defaultPath?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Query parameter name used to preserve the current location during login redirects.
|
|
25
|
+
*/
|
|
8
26
|
callbackUrlParam?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Decides whether the callback URL should be attached to an unauthenticated redirect.
|
|
29
|
+
*/
|
|
9
30
|
shouldAddCallbackUrl?: () => boolean;
|
|
10
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Access context exposed by `useAccess()`.
|
|
34
|
+
*/
|
|
11
35
|
export type AccessContextValue<TUser = unknown> = {
|
|
36
|
+
/**
|
|
37
|
+
* Guard instance used to evaluate access rules.
|
|
38
|
+
*/
|
|
12
39
|
guard: Guard<TUser>;
|
|
40
|
+
/**
|
|
41
|
+
* Redirect target for unauthenticated users.
|
|
42
|
+
*/
|
|
13
43
|
loginPath: string;
|
|
44
|
+
/**
|
|
45
|
+
* Redirect target when the user is authenticated but forbidden.
|
|
46
|
+
*/
|
|
14
47
|
forbiddenPath: string;
|
|
48
|
+
/**
|
|
49
|
+
* Redirect target for authenticated users on guest-only screens.
|
|
50
|
+
*/
|
|
15
51
|
defaultPath: string;
|
|
52
|
+
/**
|
|
53
|
+
* Query parameter name used to preserve the current location during login redirects.
|
|
54
|
+
*/
|
|
16
55
|
callbackUrlParam?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Decides whether the callback URL should be attached to an unauthenticated redirect.
|
|
58
|
+
*/
|
|
17
59
|
shouldAddCallbackUrl?: () => boolean;
|
|
18
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Props accepted by `AccessProvider`.
|
|
63
|
+
*/
|
|
19
64
|
export type AccessProviderProps<TUser = unknown> = GuardOptions<TUser> & NavigationConfig & {
|
|
65
|
+
/**
|
|
66
|
+
* React subtree that consumes the access context.
|
|
67
|
+
*/
|
|
20
68
|
children?: ReactNode;
|
|
21
69
|
};
|
|
22
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Access requirements accepted by `useHasAccess()` and `HasAccess`.
|
|
72
|
+
*/
|
|
73
|
+
export type AccessRouteProps = RouteProtection & {
|
|
74
|
+
/**
|
|
75
|
+
* React subtree rendered when the access check passes.
|
|
76
|
+
*/
|
|
23
77
|
children?: ReactNode;
|
|
24
78
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-protected/react",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React context and hooks for react-protected",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
|
-
"dist"
|
|
30
|
+
"dist",
|
|
31
|
+
"CHANGELOG.md"
|
|
31
32
|
],
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@react-protected/core": "0.2.0
|
|
34
|
+
"@react-protected/core": "0.2.0"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
37
|
"react": ">=18.0.0",
|