@cas-system/react-cas-client 1.0.0 → 1.0.1
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/dist/CasProvider.d.ts +63 -0
- package/dist/CasProvider.d.ts.map +1 -0
- package/dist/CasProvider.js +133 -0
- package/dist/CasProvider.js.map +1 -0
- package/dist/cas-client.d.ts +161 -0
- package/dist/cas-client.d.ts.map +1 -0
- package/dist/cas-client.js +309 -0
- package/dist/cas-client.js.map +1 -0
- package/dist/components/CasLoginButton.d.ts +40 -0
- package/dist/components/CasLoginButton.d.ts.map +1 -0
- package/dist/components/CasLoginButton.js +26 -0
- package/dist/components/CasLoginButton.js.map +1 -0
- package/dist/components/CasProtectedRoute.d.ts +53 -0
- package/dist/components/CasProtectedRoute.d.ts.map +1 -0
- package/dist/components/CasProtectedRoute.js +54 -0
- package/dist/components/CasProtectedRoute.js.map +1 -0
- package/dist/hooks/useCasAuth.d.ts +34 -0
- package/dist/hooks/useCasAuth.d.ts.map +1 -0
- package/dist/hooks/useCasAuth.js +42 -0
- package/dist/hooks/useCasAuth.js.map +1 -0
- package/dist/hooks/useCasUser.d.ts +58 -0
- package/dist/hooks/useCasUser.d.ts.map +1 -0
- package/dist/hooks/useCasUser.js +50 -0
- package/dist/hooks/useCasUser.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +10 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cas-client.js","sourceRoot":"","sources":["../src/cas-client.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,MAAM,WAAW,GAAG,UAAU,CAAC;AAE/B,2DAA2D;AAC3D,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAEtC;;;;;;;;;;;;;;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AAE,CAAC;QAC5B,IAAI,CAAC,IAAI,EAAE,KAAK;YAAE,OAAO,KAAK,CAAC;QAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,8EAA8E;IAC9E,mBAAmB;IACnB,8EAA8E;IAE9E;;;OAGG;IACK,QAAQ;QACd,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAE1C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEjC,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC;QAChE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the {@link CasLoginButton} component.
|
|
4
|
+
*/
|
|
5
|
+
export interface CasLoginButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
|
|
6
|
+
/**
|
|
7
|
+
* URL to return to after CAS authentication.
|
|
8
|
+
* If omitted, the current page URL is used.
|
|
9
|
+
*/
|
|
10
|
+
returnUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Custom CSS class name(s) for the button element.
|
|
13
|
+
*/
|
|
14
|
+
className?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Custom button content. Defaults to `"Sign in"`.
|
|
17
|
+
*/
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Pre-wired button that triggers CAS SSO login on click.
|
|
22
|
+
*
|
|
23
|
+
* Accepts all standard `<button>` HTML attributes (except `onClick`, which
|
|
24
|
+
* is handled internally).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* import { CasLoginButton } from '@cas-system/react-cas-client';
|
|
29
|
+
*
|
|
30
|
+
* // Default label
|
|
31
|
+
* <CasLoginButton className="btn btn-primary" />
|
|
32
|
+
*
|
|
33
|
+
* // Custom label and return URL
|
|
34
|
+
* <CasLoginButton returnUrl="/dashboard">
|
|
35
|
+
* 🔑 Log in with SSO
|
|
36
|
+
* </CasLoginButton>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function CasLoginButton({ returnUrl, className, children, ...rest }: CasLoginButtonProps): import("react").JSX.Element;
|
|
40
|
+
//# sourceMappingURL=CasLoginButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CasLoginButton.d.ts","sourceRoot":"","sources":["../../src/components/CasLoginButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG7D;;GAEG;AACH,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAChE;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,SAAS,EACT,SAAS,EACT,QAAoB,EACpB,GAAG,IAAI,EACR,EAAE,mBAAmB,+BAarB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCasAuth } from '../hooks/useCasAuth';
|
|
3
|
+
/**
|
|
4
|
+
* Pre-wired button that triggers CAS SSO login on click.
|
|
5
|
+
*
|
|
6
|
+
* Accepts all standard `<button>` HTML attributes (except `onClick`, which
|
|
7
|
+
* is handled internally).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { CasLoginButton } from '@cas-system/react-cas-client';
|
|
12
|
+
*
|
|
13
|
+
* // Default label
|
|
14
|
+
* <CasLoginButton className="btn btn-primary" />
|
|
15
|
+
*
|
|
16
|
+
* // Custom label and return URL
|
|
17
|
+
* <CasLoginButton returnUrl="/dashboard">
|
|
18
|
+
* 🔑 Log in with SSO
|
|
19
|
+
* </CasLoginButton>
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function CasLoginButton({ returnUrl, className, children = 'Sign in', ...rest }) {
|
|
23
|
+
const { login } = useCasAuth();
|
|
24
|
+
return (_jsx("button", { type: "button", className: className, onClick: () => login(returnUrl), ...rest, children: children }));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=CasLoginButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CasLoginButton.js","sourceRoot":"","sources":["../../src/components/CasLoginButton.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAwBjD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,SAAS,EACT,SAAS,EACT,QAAQ,GAAG,SAAS,EACpB,GAAG,IAAI,EACa;IACpB,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,EAAE,CAAC;IAE/B,OAAO,CACL,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,KAC3B,IAAI,YAEP,QAAQ,GACF,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the {@link CasProtectedRoute} component.
|
|
4
|
+
*/
|
|
5
|
+
export interface CasProtectedRouteProps {
|
|
6
|
+
/** The content to render when the user is authenticated (and authorised). */
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Component to render while the auth state is loading (e.g. during token
|
|
10
|
+
* validation). Defaults to `null` (renders nothing).
|
|
11
|
+
*/
|
|
12
|
+
fallback?: ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Roles required to access this route. If specified, the user must have
|
|
15
|
+
* **at least one** of these roles to see the children.
|
|
16
|
+
*/
|
|
17
|
+
roles?: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Component to render when the user is authenticated but lacks the
|
|
20
|
+
* required roles. If omitted, the user is redirected to the CAS login page.
|
|
21
|
+
*/
|
|
22
|
+
unauthorizedComponent?: ReactNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Protects a route (or any component subtree) behind CAS authentication.
|
|
26
|
+
*
|
|
27
|
+
* - If the user is **not authenticated**, they are automatically redirected
|
|
28
|
+
* to the CAS SSO login page.
|
|
29
|
+
* - If **roles** are specified and the user does not have any of them,
|
|
30
|
+
* either `unauthorizedComponent` is rendered or the user is redirected.
|
|
31
|
+
* - While auth state is loading, `fallback` is rendered (default: nothing).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { CasProtectedRoute } from '@cas-system/react-cas-client';
|
|
36
|
+
*
|
|
37
|
+
* // Basic protection
|
|
38
|
+
* <CasProtectedRoute fallback={<Spinner />}>
|
|
39
|
+
* <Dashboard />
|
|
40
|
+
* </CasProtectedRoute>
|
|
41
|
+
*
|
|
42
|
+
* // Role-based protection
|
|
43
|
+
* <CasProtectedRoute
|
|
44
|
+
* roles={['admin', 'manager']}
|
|
45
|
+
* unauthorizedComponent={<ForbiddenPage />}
|
|
46
|
+
* fallback={<Spinner />}
|
|
47
|
+
* >
|
|
48
|
+
* <AdminPanel />
|
|
49
|
+
* </CasProtectedRoute>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function CasProtectedRoute({ children, fallback, roles, unauthorizedComponent, }: CasProtectedRouteProps): import("react").JSX.Element;
|
|
53
|
+
//# sourceMappingURL=CasProtectedRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CasProtectedRoute.d.ts","sourceRoot":"","sources":["../../src/components/CasProtectedRoute.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,6EAA6E;IAC7E,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,SAAS,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,QAAe,EACf,KAAK,EACL,qBAAqB,GACtB,EAAE,sBAAsB,+BA0BxB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCasAuth } from '../hooks/useCasAuth';
|
|
3
|
+
/**
|
|
4
|
+
* Protects a route (or any component subtree) behind CAS authentication.
|
|
5
|
+
*
|
|
6
|
+
* - If the user is **not authenticated**, they are automatically redirected
|
|
7
|
+
* to the CAS SSO login page.
|
|
8
|
+
* - If **roles** are specified and the user does not have any of them,
|
|
9
|
+
* either `unauthorizedComponent` is rendered or the user is redirected.
|
|
10
|
+
* - While auth state is loading, `fallback` is rendered (default: nothing).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { CasProtectedRoute } from '@cas-system/react-cas-client';
|
|
15
|
+
*
|
|
16
|
+
* // Basic protection
|
|
17
|
+
* <CasProtectedRoute fallback={<Spinner />}>
|
|
18
|
+
* <Dashboard />
|
|
19
|
+
* </CasProtectedRoute>
|
|
20
|
+
*
|
|
21
|
+
* // Role-based protection
|
|
22
|
+
* <CasProtectedRoute
|
|
23
|
+
* roles={['admin', 'manager']}
|
|
24
|
+
* unauthorizedComponent={<ForbiddenPage />}
|
|
25
|
+
* fallback={<Spinner />}
|
|
26
|
+
* >
|
|
27
|
+
* <AdminPanel />
|
|
28
|
+
* </CasProtectedRoute>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function CasProtectedRoute({ children, fallback = null, roles, unauthorizedComponent, }) {
|
|
32
|
+
const { isAuthenticated, isLoading, login, hasAnyRole } = useCasAuth();
|
|
33
|
+
// Still resolving auth state — show fallback
|
|
34
|
+
if (isLoading) {
|
|
35
|
+
return _jsx(_Fragment, { children: fallback });
|
|
36
|
+
}
|
|
37
|
+
// Not authenticated — redirect to CAS login
|
|
38
|
+
if (!isAuthenticated) {
|
|
39
|
+
login();
|
|
40
|
+
return _jsx(_Fragment, { children: fallback });
|
|
41
|
+
}
|
|
42
|
+
// Authenticated but missing required roles
|
|
43
|
+
if (roles && roles.length > 0 && !hasAnyRole(roles)) {
|
|
44
|
+
if (unauthorizedComponent) {
|
|
45
|
+
return _jsx(_Fragment, { children: unauthorizedComponent });
|
|
46
|
+
}
|
|
47
|
+
// No custom unauthorized view — redirect to login as a fallback
|
|
48
|
+
login();
|
|
49
|
+
return _jsx(_Fragment, { children: fallback });
|
|
50
|
+
}
|
|
51
|
+
// Authenticated and authorised
|
|
52
|
+
return _jsx(_Fragment, { children: children });
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=CasProtectedRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CasProtectedRoute.js","sourceRoot":"","sources":["../../src/components/CasProtectedRoute.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA4BjD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,QAAQ,EACR,QAAQ,GAAG,IAAI,EACf,KAAK,EACL,qBAAqB,GACE;IACvB,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC;IAEvE,6CAA6C;IAC7C,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,4BAAG,QAAQ,GAAI,CAAC;IACzB,CAAC;IAED,4CAA4C;IAC5C,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,KAAK,EAAE,CAAC;QACR,OAAO,4BAAG,QAAQ,GAAI,CAAC;IACzB,CAAC;IAED,2CAA2C;IAC3C,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,IAAI,qBAAqB,EAAE,CAAC;YAC1B,OAAO,4BAAG,qBAAqB,GAAI,CAAC;QACtC,CAAC;QACD,gEAAgE;QAChE,KAAK,EAAE,CAAC;QACR,OAAO,4BAAG,QAAQ,GAAI,CAAC;IACzB,CAAC;IAED,+BAA+B;IAC/B,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CasContextValue } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that provides the full CAS authentication state and actions.
|
|
4
|
+
*
|
|
5
|
+
* Must be used within a `<CasProvider>`.
|
|
6
|
+
*
|
|
7
|
+
* @returns The current {@link CasContextValue} containing `user`,
|
|
8
|
+
* `isAuthenticated`, `isLoading`, `error`, `login`, `logout`,
|
|
9
|
+
* `hasRole`, and `hasAnyRole`.
|
|
10
|
+
*
|
|
11
|
+
* @throws {Error} If called outside of a `<CasProvider>`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* import { useCasAuth } from '@cas-system/react-cas-client';
|
|
16
|
+
*
|
|
17
|
+
* function Header() {
|
|
18
|
+
* const { user, isAuthenticated, login, logout } = useCasAuth();
|
|
19
|
+
*
|
|
20
|
+
* if (!isAuthenticated) {
|
|
21
|
+
* return <button onClick={() => login()}>Sign in</button>;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <div>
|
|
26
|
+
* Welcome, {user?.username}
|
|
27
|
+
* <button onClick={() => logout()}>Sign out</button>
|
|
28
|
+
* </div>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function useCasAuth(): CasContextValue;
|
|
34
|
+
//# sourceMappingURL=useCasAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCasAuth.d.ts","sourceRoot":"","sources":["../../src/hooks/useCasAuth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,UAAU,IAAI,eAAe,CAW5C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { CasContext } from '../CasProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Hook that provides the full CAS authentication state and actions.
|
|
5
|
+
*
|
|
6
|
+
* Must be used within a `<CasProvider>`.
|
|
7
|
+
*
|
|
8
|
+
* @returns The current {@link CasContextValue} containing `user`,
|
|
9
|
+
* `isAuthenticated`, `isLoading`, `error`, `login`, `logout`,
|
|
10
|
+
* `hasRole`, and `hasAnyRole`.
|
|
11
|
+
*
|
|
12
|
+
* @throws {Error} If called outside of a `<CasProvider>`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { useCasAuth } from '@cas-system/react-cas-client';
|
|
17
|
+
*
|
|
18
|
+
* function Header() {
|
|
19
|
+
* const { user, isAuthenticated, login, logout } = useCasAuth();
|
|
20
|
+
*
|
|
21
|
+
* if (!isAuthenticated) {
|
|
22
|
+
* return <button onClick={() => login()}>Sign in</button>;
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <div>
|
|
27
|
+
* Welcome, {user?.username}
|
|
28
|
+
* <button onClick={() => logout()}>Sign out</button>
|
|
29
|
+
* </div>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function useCasAuth() {
|
|
35
|
+
const context = useContext(CasContext);
|
|
36
|
+
if (!context) {
|
|
37
|
+
throw new Error('useCasAuth() must be used within a <CasProvider>. ' +
|
|
38
|
+
'Wrap your component tree with <CasProvider config={...}>.');
|
|
39
|
+
}
|
|
40
|
+
return context;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=useCasAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCasAuth.js","sourceRoot":"","sources":["../../src/hooks/useCasAuth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,OAAO,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IAEvC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,oDAAoD;YAClD,2DAA2D,CAC9D,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CasUser } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Return type for the {@link useCasUser} hook.
|
|
4
|
+
*/
|
|
5
|
+
export interface UseCasUserReturn {
|
|
6
|
+
/** The currently authenticated user, or `null`. */
|
|
7
|
+
user: CasUser | null;
|
|
8
|
+
/** Whether a user session exists. */
|
|
9
|
+
isAuthenticated: boolean;
|
|
10
|
+
/** Whether the SDK is currently loading (e.g. validating a callback token). */
|
|
11
|
+
isLoading: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Check if the user has a specific role.
|
|
14
|
+
* @param role - The role name to check.
|
|
15
|
+
*/
|
|
16
|
+
hasRole: (role: string) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Check if the user has at least one of the given roles.
|
|
19
|
+
* @param roles - The role names to check.
|
|
20
|
+
*/
|
|
21
|
+
hasAnyRole: (roles: string[]) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if the user has all of the given roles.
|
|
24
|
+
* @param roles - The role names to check.
|
|
25
|
+
*/
|
|
26
|
+
hasAllRoles: (roles: string[]) => boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook that returns just the user data and role-checking helpers.
|
|
30
|
+
*
|
|
31
|
+
* This is a convenience wrapper around {@link useCasAuth} for components
|
|
32
|
+
* that only need to read user information without triggering login/logout.
|
|
33
|
+
*
|
|
34
|
+
* Must be used within a `<CasProvider>`.
|
|
35
|
+
*
|
|
36
|
+
* @returns An object with `user`, `isAuthenticated`, `isLoading`, and
|
|
37
|
+
* role-checking functions.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* import { useCasUser } from '@cas-system/react-cas-client';
|
|
42
|
+
*
|
|
43
|
+
* function ProfileBadge() {
|
|
44
|
+
* const { user, hasRole } = useCasUser();
|
|
45
|
+
*
|
|
46
|
+
* if (!user) return null;
|
|
47
|
+
*
|
|
48
|
+
* return (
|
|
49
|
+
* <span>
|
|
50
|
+
* {user.username}
|
|
51
|
+
* {hasRole('admin') && ' 👑'}
|
|
52
|
+
* </span>
|
|
53
|
+
* );
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function useCasUser(): UseCasUserReturn;
|
|
58
|
+
//# sourceMappingURL=useCasUser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCasUser.d.ts","sourceRoot":"","sources":["../../src/hooks/useCasUser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAErB,qCAAqC;IACrC,eAAe,EAAE,OAAO,CAAC;IAEzB,+EAA+E;IAC/E,SAAS,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnC;;;OAGG;IACH,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IAEzC;;;OAGG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CAsB7C"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useCasAuth } from './useCasAuth';
|
|
3
|
+
/**
|
|
4
|
+
* Hook that returns just the user data and role-checking helpers.
|
|
5
|
+
*
|
|
6
|
+
* This is a convenience wrapper around {@link useCasAuth} for components
|
|
7
|
+
* that only need to read user information without triggering login/logout.
|
|
8
|
+
*
|
|
9
|
+
* Must be used within a `<CasProvider>`.
|
|
10
|
+
*
|
|
11
|
+
* @returns An object with `user`, `isAuthenticated`, `isLoading`, and
|
|
12
|
+
* role-checking functions.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { useCasUser } from '@cas-system/react-cas-client';
|
|
17
|
+
*
|
|
18
|
+
* function ProfileBadge() {
|
|
19
|
+
* const { user, hasRole } = useCasUser();
|
|
20
|
+
*
|
|
21
|
+
* if (!user) return null;
|
|
22
|
+
*
|
|
23
|
+
* return (
|
|
24
|
+
* <span>
|
|
25
|
+
* {user.username}
|
|
26
|
+
* {hasRole('admin') && ' 👑'}
|
|
27
|
+
* </span>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function useCasUser() {
|
|
33
|
+
const { user, isAuthenticated, isLoading, hasRole, hasAnyRole } = useCasAuth();
|
|
34
|
+
const hasAllRoles = useMemo(() => {
|
|
35
|
+
return (roles) => {
|
|
36
|
+
if (!user?.roles)
|
|
37
|
+
return false;
|
|
38
|
+
return roles.every((role) => user.roles.includes(role));
|
|
39
|
+
};
|
|
40
|
+
}, [user]);
|
|
41
|
+
return useMemo(() => ({
|
|
42
|
+
user,
|
|
43
|
+
isAuthenticated,
|
|
44
|
+
isLoading,
|
|
45
|
+
hasRole,
|
|
46
|
+
hasAnyRole,
|
|
47
|
+
hasAllRoles,
|
|
48
|
+
}), [user, isAuthenticated, isLoading, hasRole, hasAnyRole, hasAllRoles]);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=useCasUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCasUser.js","sourceRoot":"","sources":["../../src/hooks/useCasUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAmC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,GAC7D,UAAU,EAAE,CAAC;IAEf,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE;QAC/B,OAAO,CAAC,KAAe,EAAW,EAAE;YAClC,IAAI,CAAC,IAAI,EAAE,KAAK;gBAAE,OAAO,KAAK,CAAC;YAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,IAAI;QACJ,eAAe;QACf,SAAS;QACT,OAAO;QACP,UAAU;QACV,WAAW;KACZ,CAAC,EACF,CAAC,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,CACrE,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @cas-system/react-cas-client
|
|
3
|
+
* @description React SDK for CAS (Central Authentication System) integration.
|
|
4
|
+
*
|
|
5
|
+
* Provides hooks, components, and a context provider for seamless SSO
|
|
6
|
+
* authentication with a CAS server.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import {
|
|
11
|
+
* CasProvider,
|
|
12
|
+
* useCasAuth,
|
|
13
|
+
* CasProtectedRoute,
|
|
14
|
+
* } from '@cas-system/react-cas-client';
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export type { CasConfig, CasUser, CasAuthState, CasAuthActions, CasContextValue, } from './types';
|
|
18
|
+
export { CasClient } from './cas-client';
|
|
19
|
+
export { CasProvider, CasContext } from './CasProvider';
|
|
20
|
+
export type { CasProviderProps } from './CasProvider';
|
|
21
|
+
export { useCasAuth } from './hooks/useCasAuth';
|
|
22
|
+
export { useCasUser } from './hooks/useCasUser';
|
|
23
|
+
export type { UseCasUserReturn } from './hooks/useCasUser';
|
|
24
|
+
export { CasProtectedRoute } from './components/CasProtectedRoute';
|
|
25
|
+
export type { CasProtectedRouteProps } from './components/CasProtectedRoute';
|
|
26
|
+
export { CasLoginButton } from './components/CasLoginButton';
|
|
27
|
+
export type { CasLoginButtonProps } from './components/CasLoginButton';
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,YAAY,EACV,SAAS,EACT,OAAO,EACP,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,SAAS,CAAC;AAKjB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAKzC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACxD,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAKtD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAK3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAE7E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @cas-system/react-cas-client
|
|
3
|
+
* @description React SDK for CAS (Central Authentication System) integration.
|
|
4
|
+
*
|
|
5
|
+
* Provides hooks, components, and a context provider for seamless SSO
|
|
6
|
+
* authentication with a CAS server.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import {
|
|
11
|
+
* CasProvider,
|
|
12
|
+
* useCasAuth,
|
|
13
|
+
* CasProtectedRoute,
|
|
14
|
+
* } from '@cas-system/react-cas-client';
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Core client
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
export { CasClient } from './cas-client';
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// React Context & Provider
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
export { CasProvider, CasContext } from './CasProvider';
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Hooks
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
export { useCasAuth } from './hooks/useCasAuth';
|
|
29
|
+
export { useCasUser } from './hooks/useCasUser';
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Components
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
export { CasProtectedRoute } from './components/CasProtectedRoute';
|
|
34
|
+
export { CasLoginButton } from './components/CasLoginButton';
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAaH,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAC9E,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGxD,8EAA8E;AAC9E,QAAQ;AACR,8EAA8E;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module types
|
|
3
|
+
* @description Core TypeScript interfaces for the CAS Client SDK.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the CAS client.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const config: CasConfig = {
|
|
11
|
+
* serverUrl: 'https://cas.example.com',
|
|
12
|
+
* clientId: 'my-app',
|
|
13
|
+
* callbackUrl: 'https://myapp.com/auth/callback',
|
|
14
|
+
* backendValidateUrl: '/api/auth/validate',
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface CasConfig {
|
|
19
|
+
/**
|
|
20
|
+
* The base URL of the CAS server (no trailing slash).
|
|
21
|
+
* @example 'https://cas.example.com'
|
|
22
|
+
*/
|
|
23
|
+
serverUrl: string;
|
|
24
|
+
/**
|
|
25
|
+
* The OAuth client ID registered with the CAS server.
|
|
26
|
+
*/
|
|
27
|
+
clientId: string;
|
|
28
|
+
/**
|
|
29
|
+
* The URL the CAS server should redirect to after authentication.
|
|
30
|
+
* Defaults to the current page URL (`window.location.href`) if omitted.
|
|
31
|
+
*/
|
|
32
|
+
callbackUrl?: string;
|
|
33
|
+
/**
|
|
34
|
+
* URL of your backend endpoint that proxies token validation to the CAS server.
|
|
35
|
+
* Tokens are NEVER validated in the browser — they must be sent to your backend,
|
|
36
|
+
* which calls `POST {serverUrl}/api/validate-token` with the `client_secret`.
|
|
37
|
+
*
|
|
38
|
+
* @example '/api/auth/validate'
|
|
39
|
+
*/
|
|
40
|
+
backendValidateUrl?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Represents an authenticated CAS user.
|
|
44
|
+
*/
|
|
45
|
+
export interface CasUser {
|
|
46
|
+
/** Unique user identifier from the CAS server. */
|
|
47
|
+
id: string;
|
|
48
|
+
/** The user's login name. */
|
|
49
|
+
username: string;
|
|
50
|
+
/** The user's email address. */
|
|
51
|
+
email: string;
|
|
52
|
+
/**
|
|
53
|
+
* Roles assigned to this user (e.g. `['admin', 'editor']`).
|
|
54
|
+
* May be `undefined` if the CAS server does not return roles.
|
|
55
|
+
*/
|
|
56
|
+
roles?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The authentication state exposed by the CAS context and hooks.
|
|
60
|
+
*/
|
|
61
|
+
export interface CasAuthState {
|
|
62
|
+
/** The currently authenticated user, or `null` if not authenticated. */
|
|
63
|
+
user: CasUser | null;
|
|
64
|
+
/** Whether the user is currently authenticated. */
|
|
65
|
+
isAuthenticated: boolean;
|
|
66
|
+
/** Whether the SDK is performing an authentication operation (e.g. validating a callback token). */
|
|
67
|
+
isLoading: boolean;
|
|
68
|
+
/** The last authentication error, or `null` if no error occurred. */
|
|
69
|
+
error: string | null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Actions available through the CAS context.
|
|
73
|
+
*/
|
|
74
|
+
export interface CasAuthActions {
|
|
75
|
+
/**
|
|
76
|
+
* Redirect the user to the CAS SSO login page.
|
|
77
|
+
* @param returnUrl - Optional URL to return to after login (defaults to current page).
|
|
78
|
+
*/
|
|
79
|
+
login: (returnUrl?: string) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Log the user out: clears the session, calls the CAS logout endpoint, and optionally redirects.
|
|
82
|
+
* @param redirectUrl - Optional URL to redirect to after logout.
|
|
83
|
+
*/
|
|
84
|
+
logout: (redirectUrl?: string) => Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Check whether the current user has a specific role.
|
|
87
|
+
* @param role - The role to check.
|
|
88
|
+
* @returns `true` if the user has the given role.
|
|
89
|
+
*/
|
|
90
|
+
hasRole: (role: string) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Check whether the current user has at least one of the given roles.
|
|
93
|
+
* @param roles - The roles to check.
|
|
94
|
+
* @returns `true` if the user has any of the given roles.
|
|
95
|
+
*/
|
|
96
|
+
hasAnyRole: (roles: string[]) => boolean;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The full context value provided by {@link CasProvider}.
|
|
100
|
+
*/
|
|
101
|
+
export interface CasContextValue extends CasAuthState, CasAuthActions {
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,kDAAkD;IAClD,EAAE,EAAE,MAAM,CAAC;IAEX,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IAEjB,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;IAErB,mDAAmD;IACnD,eAAe,EAAE,OAAO,CAAC;IAEzB,oGAAoG;IACpG,SAAS,EAAE,OAAO,CAAC;IAEnB,qEAAqE;IACrE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEpC;;;OAGG;IACH,MAAM,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD;;;;OAIG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnC;;;;OAIG;IACH,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,eAAgB,SAAQ,YAAY,EAAE,cAAc;CAAG"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cas-system/react-cas-client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "React SDK for CAS (Central Authentication System) integration \u2014 provides hooks, components, and context for seamless SSO authentication.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.
|
|
6
|
+
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
@@ -19,14 +19,15 @@
|
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsc",
|
|
22
|
-
"typecheck": "tsc --noEmit"
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
23
24
|
},
|
|
24
25
|
"peerDependencies": {
|
|
25
26
|
"react": ">=18.2"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/react": "^18.3.0",
|
|
29
|
-
"typescript": "^6.
|
|
30
|
+
"typescript": "^5.6.3"
|
|
30
31
|
},
|
|
31
32
|
"keywords": [
|
|
32
33
|
"react",
|
|
@@ -44,5 +45,6 @@
|
|
|
44
45
|
},
|
|
45
46
|
"publishConfig": {
|
|
46
47
|
"access": "public"
|
|
47
|
-
}
|
|
48
|
+
},
|
|
49
|
+
"type": "module"
|
|
48
50
|
}
|