@anievo-id/rbac-evolution-react 0.7.0 → 0.7.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/checker.ts","../src/context.tsx","../src/components.tsx"],"sourcesContent":["/**\n * @anievo-id/rbac-evolution-react\n *\n * Client-side UI helpers. They only show/hide UI — always enforce authorization on the server.\n */\n\nexport { createRbacChecker } from './checker'\nexport type { RbacChecker, RbacCheckerOptions } from './checker'\n\nexport {\n RbacProvider,\n useCan,\n useCanAll,\n useCanAny,\n useCannot,\n useHasAllRoles,\n useHasAnyRole,\n useHasRole,\n useRbac,\n} from './context'\nexport type { RbacProviderProps } from './context'\n\nexport { Can, Cannot, HasRole } from './components'\nexport type { CannotProps, CanProps, HasRoleProps, PermissionCondition, RoleCondition } from './components'\n","import { wildcardImplies } from '@anievo-id/rbac-evolution'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\n\nexport interface RbacCheckerOptions {\n /** Treat granted permissions as wildcard patterns (`articles.*`). Must match the server's `wildcard` setting. */\n wildcard?: boolean\n /** Roles that pass every permission check (like spatie's `Gate::before` super-admin pattern). */\n superAdminRoles?: readonly string[]\n /** The snapshot is still being fetched: `<Can>`, `<Cannot>` and `<HasRole>` render nothing. Default: `false`. */\n loading?: boolean\n}\n\n/** Synchronous checks against a {@link RbacSnapshot}. */\nexport interface RbacChecker {\n readonly roles: readonly string[]\n readonly permissions: readonly string[]\n /** `true` if the subject has one of the configured `superAdminRoles`. */\n readonly isSuperAdmin: boolean\n /** `true` while the snapshot is still being fetched (the `loading` option). Every check, `cannot` included, returns `false` meanwhile. */\n readonly loading: boolean\n can(permission: string): boolean\n cannot(permission: string): boolean\n /** `true` if ANY of the permissions is granted. `false` for an empty list. */\n canAny(...permissions: Many<string>[]): boolean\n /** `true` if ALL of the permissions are granted. `false` for an empty list (deny by default, like the Vue package). */\n canAll(...permissions: Many<string>[]): boolean\n /** `true` if the subject has the role — or ANY of the roles when given an array. */\n hasRole(roles: Many<string>): boolean\n hasAnyRole(...roles: Many<string>[]): boolean\n hasAllRoles(...roles: Many<string>[]): boolean\n}\n\nconst EMPTY: RbacSnapshot = { roles: [], permissions: [] }\n\nfunction flatten(items: readonly Many<string>[]): string[] {\n const out: string[] = []\n for (const item of items) {\n if (typeof item === 'string') out.push(item)\n else out.push(...item)\n }\n return out\n}\n\nfunction safeImplies(granted: string, required: string): boolean {\n try {\n return wildcardImplies(granted, required)\n } catch {\n return false\n }\n}\n\n/**\n * Builds a pure, synchronous checker for a snapshot (as returned by `rbac.for(user).snapshot()`).\n * Used by `RbacProvider`, but usable on its own too.\n */\nexport function createRbacChecker(\n snapshot: RbacSnapshot | null | undefined,\n options: RbacCheckerOptions = {},\n): RbacChecker {\n const { roles, permissions } = snapshot ?? EMPTY\n const roleSet = new Set(roles)\n const permissionSet = new Set(permissions)\n const wildcard = options.wildcard ?? false\n // While loading, every check (`cannot` too) is false: neither a stale grant nor \"no access\" UI shows.\n const loading = options.loading ?? false\n const isSuperAdmin = !loading && (options.superAdminRoles ?? []).some((r) => roleSet.has(r))\n\n const can = (permission: string): boolean => {\n if (loading) return false\n if (isSuperAdmin) return true\n const name = permission.trim()\n if (name === '') return false\n if (permissionSet.has(name)) return true\n return wildcard && permissions.some((granted) => safeImplies(granted, name))\n }\n const hasOne = (role: string): boolean => !loading && roleSet.has(role.trim())\n\n return {\n roles,\n permissions,\n isSuperAdmin,\n loading,\n can,\n cannot: (permission) => !loading && !can(permission),\n canAny: (...list) => flatten(list).some(can),\n canAll: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(can)\n },\n hasRole: (list) => flatten([list]).some(hasOne),\n hasAnyRole: (...list) => flatten(list).some(hasOne),\n hasAllRoles: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(hasOne)\n },\n }\n}\n","import { createContext, useContext, useMemo } from 'react'\nimport type { ReactNode } from 'react'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\nimport { createRbacChecker } from './checker'\nimport type { RbacChecker } from './checker'\n\nconst RbacContext = createContext<RbacChecker | null>(null)\nRbacContext.displayName = 'RbacContext'\n\nexport interface RbacProviderProps {\n /** Roles & permissions of the current user, e.g. from `rbac.for(user).snapshot()` on the server. `null` = guest. */\n snapshot: RbacSnapshot | null | undefined\n /** Enable wildcard matching (`articles.*`). Must match the server's `wildcard` setting. Default: `false`. */\n wildcard?: boolean\n /** Roles that pass every `can` check (super admin). */\n superAdminRoles?: readonly string[]\n /**\n * The snapshot is still being fetched. `<Can>`, `<Cannot>` and `<HasRole>` then render nothing\n * (not even `fallback`), so nothing flashes before the real permissions arrive. Default: `false`.\n */\n loading?: boolean\n children?: ReactNode\n}\n\n/**\n * Provides a user's roles & permissions to `useCan()`, `<Can>`, ...\n *\n * UI only: this hides and shows elements. Always enforce authorization on the server.\n */\nexport function RbacProvider({ snapshot, wildcard = false, superAdminRoles, loading = false, children }: RbacProviderProps) {\n const superKey = superAdminRoles?.join('\\u0000') ?? ''\n const checker = useMemo(\n () => createRbacChecker(snapshot, superAdminRoles ? { wildcard, superAdminRoles, loading } : { wildcard, loading }),\n // `superKey` keeps inline arrays (`superAdminRoles={['admin']}`) from recomputing every render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [snapshot, wildcard, superKey, loading],\n )\n return <RbacContext.Provider value={checker}>{children}</RbacContext.Provider>\n}\n\n/** Returns the checker of the nearest `RbacProvider`. Throws when there is none. */\nexport function useRbac(): RbacChecker {\n const checker = useContext(RbacContext)\n if (!checker) {\n throw new Error('useRbac() must be used inside <RbacProvider>.')\n }\n return checker\n}\n\nexport function useCan(permission: string): boolean {\n return useRbac().can(permission)\n}\n\nexport function useCannot(permission: string): boolean {\n return useRbac().cannot(permission)\n}\n\nexport function useCanAny(...permissions: Many<string>[]): boolean {\n return useRbac().canAny(...permissions)\n}\n\nexport function useCanAll(...permissions: Many<string>[]): boolean {\n return useRbac().canAll(...permissions)\n}\n\n/** `true` if the user has the role — or ANY of the roles when given an array. */\nexport function useHasRole(role: Many<string>): boolean {\n return useRbac().hasRole(role)\n}\n\nexport function useHasAnyRole(...roles: Many<string>[]): boolean {\n return useRbac().hasAnyRole(...roles)\n}\n\nexport function useHasAllRoles(...roles: Many<string>[]): boolean {\n return useRbac().hasAllRoles(...roles)\n}\n","import type { ReactNode } from 'react'\nimport type { RbacChecker } from './checker'\nimport { useRbac } from './context'\n\n/** Exactly one of `permission`, `anyOf` or `allOf`. */\nexport type PermissionCondition =\n | { permission: string; anyOf?: never; allOf?: never }\n | { permission?: never; anyOf: readonly string[]; allOf?: never }\n | { permission?: never; anyOf?: never; allOf: readonly string[] }\n\n/** Exactly one of `role`, `anyOf` or `allOf`. */\nexport type RoleCondition =\n | { role: string; anyOf?: never; allOf?: never }\n | { role?: never; anyOf: readonly string[]; allOf?: never }\n | { role?: never; anyOf?: never; allOf: readonly string[] }\n\ninterface GateProps {\n children?: ReactNode\n /** Rendered when the check fails. Default: nothing. */\n fallback?: ReactNode\n}\n\nexport type CanProps = PermissionCondition & GateProps\nexport type CannotProps = PermissionCondition & GateProps\nexport type HasRoleProps = RoleCondition & GateProps\n\ninterface LooseCondition {\n anyOf?: readonly string[] | undefined\n allOf?: readonly string[] | undefined\n}\n\n// Conditions are ANDed; no condition at all is denied (deny by default, also for untyped JS callers).\nfunction checkPermissions(rbac: RbacChecker, p: LooseCondition & { permission?: string | undefined }): boolean {\n if (p.permission === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.permission === undefined || rbac.can(p.permission)) &&\n (p.anyOf === undefined || rbac.canAny(p.anyOf)) &&\n (p.allOf === undefined || rbac.canAll(p.allOf))\n )\n}\n\nfunction checkRoles(rbac: RbacChecker, p: LooseCondition & { role?: string | undefined }): boolean {\n if (p.role === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.role === undefined || rbac.hasRole(p.role)) &&\n (p.anyOf === undefined || rbac.hasAnyRole(p.anyOf)) &&\n (p.allOf === undefined || rbac.hasAllRoles(p.allOf))\n )\n}\n\n/** Renders `children` if the user has the permission(s) — like spatie's `@can` / `@canany`. */\nexport function Can(props: CanProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.children : props.fallback}</>\n}\n\n/** Renders `children` if the user does NOT have the permission(s) — like spatie's `@cannot`. */\nexport function Cannot(props: CannotProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.fallback : props.children}</>\n}\n\n/** Renders `children` if the user has the role(s) — like spatie's `@role` / `@hasanyrole` / `@hasallroles`. */\nexport function HasRole(props: HasRoleProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkRoles(rbac, props) ? props.children : props.fallback}</>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,4BAAgC;AAgChC,IAAM,QAAsB,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,EAAE;AAEzD,SAAS,QAAQ,OAA0C;AACzD,QAAM,MAAgB,CAAC;AACvB,aAAW,QAAQ,OAAO;AACxB,QAAI,OAAO,SAAS,SAAU,KAAI,KAAK,IAAI;AAAA,QACtC,KAAI,KAAK,GAAG,IAAI;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,YAAY,SAAiB,UAA2B;AAC/D,MAAI;AACF,eAAO,uCAAgB,SAAS,QAAQ;AAAA,EAC1C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMO,SAAS,kBACd,UACA,UAA8B,CAAC,GAClB;AACb,QAAM,EAAE,OAAO,YAAY,IAAI,YAAY;AAC3C,QAAM,UAAU,IAAI,IAAI,KAAK;AAC7B,QAAM,gBAAgB,IAAI,IAAI,WAAW;AACzC,QAAM,WAA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;AAEA,SAAS,WAAW,MAAmB,GAA4D;AACjG,MAAI,EAAE,SAAS,UAAa,EAAE,UAAU,UAAa,EAAE,UAAU,OAAW,QAAO;AACnF,UACG,EAAE,SAAS,UAAa,KAAK,QAAQ,EAAE,IAAI,OAC3C,EAAE,UAAU,UAAa,KAAK,WAAW,EAAE,KAAK,OAChD,EAAE,UAAU,UAAa,KAAK,YAAY,EAAE,KAAK;AAEtD;AAGO,SAAS,IAAI,OAAiB;AACnC,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,6EAAG,2BAAiB,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AAC5E;AAGO,SAAS,OAAO,OAAoB;AACzC,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,6EAAG,2BAAiB,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AAC5E;AAGO,SAAS,QAAQ,OAAqB;AAC3C,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,6EAAG,qBAAW,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AACtE;","names":["import_jsx_runtime"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/checker.ts","../src/context.tsx","../src/components.tsx"],"sourcesContent":["/**\n * @anievo-id/rbac-evolution-react\n *\n * Client-side UI helpers. They only show/hide UI — always enforce authorization on the server.\n */\n\nexport { createRbacChecker } from './checker'\nexport type { RbacChecker, RbacCheckerOptions } from './checker'\n\nexport {\n RbacProvider,\n useCan,\n useCanAll,\n useCanAny,\n useCannot,\n useHasAllRoles,\n useHasAnyRole,\n useHasRole,\n useRbac,\n} from './context'\nexport type { RbacProviderProps } from './context'\n\nexport { Can, Cannot, HasRole } from './components'\nexport type { CannotProps, CanProps, HasRoleProps, PermissionCondition, RoleCondition } from './components'\n","import { wildcardImplies } from '@anievo-id/rbac-evolution'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\n\nexport interface RbacCheckerOptions {\n /** Treat granted permissions as wildcard patterns (`articles.*`). Must match the server's `wildcard` setting. */\n wildcard?: boolean | undefined\n /** Roles that pass every permission check (like spatie's `Gate::before` super-admin pattern). */\n superAdminRoles?: readonly string[] | undefined\n /** The snapshot is still being fetched: `<Can>`, `<Cannot>` and `<HasRole>` render nothing. Default: `false`. */\n loading?: boolean | undefined\n}\n\n/** Synchronous checks against a {@link RbacSnapshot}. */\nexport interface RbacChecker {\n readonly roles: readonly string[]\n readonly permissions: readonly string[]\n /** `true` if the subject has one of the configured `superAdminRoles`. */\n readonly isSuperAdmin: boolean\n /** `true` while the snapshot is still being fetched (the `loading` option). Every check, `cannot` included, returns `false` meanwhile. */\n readonly loading: boolean\n can(permission: string): boolean\n cannot(permission: string): boolean\n /** `true` if ANY of the permissions is granted. `false` for an empty list. */\n canAny(...permissions: Many<string>[]): boolean\n /** `true` if ALL of the permissions are granted. `false` for an empty list (deny by default, like the Vue package). */\n canAll(...permissions: Many<string>[]): boolean\n /** `true` if the subject has the role — or ANY of the roles when given an array. */\n hasRole(roles: Many<string>): boolean\n hasAnyRole(...roles: Many<string>[]): boolean\n hasAllRoles(...roles: Many<string>[]): boolean\n}\n\nconst EMPTY: RbacSnapshot = { roles: [], permissions: [] }\n\nfunction flatten(items: readonly Many<string>[]): string[] {\n const out: string[] = []\n for (const item of items) {\n if (typeof item === 'string') out.push(item)\n else out.push(...item)\n }\n return out\n}\n\nfunction safeImplies(granted: string, required: string): boolean {\n try {\n return wildcardImplies(granted, required)\n } catch {\n return false\n }\n}\n\n/**\n * Builds a pure, synchronous checker for a snapshot (as returned by `rbac.for(user).snapshot()`).\n * Used by `RbacProvider`, but usable on its own too.\n */\nexport function createRbacChecker(\n snapshot: RbacSnapshot | null | undefined,\n options: RbacCheckerOptions = {},\n): RbacChecker {\n const { roles, permissions } = snapshot ?? EMPTY\n const roleSet = new Set(roles)\n const permissionSet = new Set(permissions)\n const wildcard = options.wildcard ?? false\n // While loading, every check (`cannot` too) is false: neither a stale grant nor \"no access\" UI shows.\n const loading = options.loading ?? false\n const isSuperAdmin = !loading && (options.superAdminRoles ?? []).some((r) => roleSet.has(r))\n\n const can = (permission: string): boolean => {\n if (loading) return false\n if (isSuperAdmin) return true\n const name = permission.trim()\n if (name === '') return false\n if (permissionSet.has(name)) return true\n return wildcard && permissions.some((granted) => safeImplies(granted, name))\n }\n const hasOne = (role: string): boolean => !loading && roleSet.has(role.trim())\n\n return {\n roles,\n permissions,\n isSuperAdmin,\n loading,\n can,\n cannot: (permission) => !loading && !can(permission),\n canAny: (...list) => flatten(list).some(can),\n canAll: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(can)\n },\n hasRole: (list) => flatten([list]).some(hasOne),\n hasAnyRole: (...list) => flatten(list).some(hasOne),\n hasAllRoles: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(hasOne)\n },\n }\n}\n","import { createContext, useContext, useMemo } from 'react'\nimport type { ReactNode } from 'react'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\nimport { createRbacChecker } from './checker'\nimport type { RbacChecker } from './checker'\n\nconst RbacContext = createContext<RbacChecker | null>(null)\nRbacContext.displayName = 'RbacContext'\n\nexport interface RbacProviderProps {\n /** Roles & permissions of the current user, e.g. from `rbac.for(user).snapshot()` on the server. `null` = guest. */\n snapshot: RbacSnapshot | null | undefined\n /** Enable wildcard matching (`articles.*`). Must match the server's `wildcard` setting. Default: `false`. */\n wildcard?: boolean | undefined\n /** Roles that pass every `can` check (super admin). */\n superAdminRoles?: readonly string[] | undefined\n /**\n * The snapshot is still being fetched. `<Can>`, `<Cannot>` and `<HasRole>` then render nothing\n * (not even `fallback`), so nothing flashes before the real permissions arrive. Default: `false`.\n */\n loading?: boolean | undefined\n children?: ReactNode | undefined\n}\n\n/**\n * Provides a user's roles & permissions to `useCan()`, `<Can>`, ...\n *\n * UI only: this hides and shows elements. Always enforce authorization on the server.\n */\nexport function RbacProvider({ snapshot, wildcard = false, superAdminRoles, loading = false, children }: RbacProviderProps) {\n const superKey = superAdminRoles?.join('\\u0000') ?? ''\n const checker = useMemo(\n () => createRbacChecker(snapshot, superAdminRoles ? { wildcard, superAdminRoles, loading } : { wildcard, loading }),\n // `superKey` keeps inline arrays (`superAdminRoles={['admin']}`) from recomputing every render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [snapshot, wildcard, superKey, loading],\n )\n return <RbacContext.Provider value={checker}>{children}</RbacContext.Provider>\n}\n\n/** Returns the checker of the nearest `RbacProvider`. Throws when there is none. */\nexport function useRbac(): RbacChecker {\n const checker = useContext(RbacContext)\n if (!checker) {\n throw new Error('useRbac() must be used inside <RbacProvider>.')\n }\n return checker\n}\n\nexport function useCan(permission: string): boolean {\n return useRbac().can(permission)\n}\n\nexport function useCannot(permission: string): boolean {\n return useRbac().cannot(permission)\n}\n\nexport function useCanAny(...permissions: Many<string>[]): boolean {\n return useRbac().canAny(...permissions)\n}\n\nexport function useCanAll(...permissions: Many<string>[]): boolean {\n return useRbac().canAll(...permissions)\n}\n\n/** `true` if the user has the role — or ANY of the roles when given an array. */\nexport function useHasRole(role: Many<string>): boolean {\n return useRbac().hasRole(role)\n}\n\nexport function useHasAnyRole(...roles: Many<string>[]): boolean {\n return useRbac().hasAnyRole(...roles)\n}\n\nexport function useHasAllRoles(...roles: Many<string>[]): boolean {\n return useRbac().hasAllRoles(...roles)\n}\n","import type { ReactNode } from 'react'\nimport type { RbacChecker } from './checker'\nimport { useRbac } from './context'\n\n/** Exactly one of `permission`, `anyOf` or `allOf`. */\nexport type PermissionCondition =\n | { permission: string; anyOf?: never; allOf?: never }\n | { permission?: never; anyOf: readonly string[]; allOf?: never }\n | { permission?: never; anyOf?: never; allOf: readonly string[] }\n\n/** Exactly one of `role`, `anyOf` or `allOf`. */\nexport type RoleCondition =\n | { role: string; anyOf?: never; allOf?: never }\n | { role?: never; anyOf: readonly string[]; allOf?: never }\n | { role?: never; anyOf?: never; allOf: readonly string[] }\n\ninterface GateProps {\n children?: ReactNode | undefined\n /** Rendered when the check fails. Default: nothing. */\n fallback?: ReactNode | undefined\n}\n\nexport type CanProps = PermissionCondition & GateProps\nexport type CannotProps = PermissionCondition & GateProps\nexport type HasRoleProps = RoleCondition & GateProps\n\ninterface LooseCondition {\n anyOf?: readonly string[] | undefined\n allOf?: readonly string[] | undefined\n}\n\n// Conditions are ANDed; no condition at all is denied (deny by default, also for untyped JS callers).\nfunction checkPermissions(rbac: RbacChecker, p: LooseCondition & { permission?: string | undefined }): boolean {\n if (p.permission === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.permission === undefined || rbac.can(p.permission)) &&\n (p.anyOf === undefined || rbac.canAny(p.anyOf)) &&\n (p.allOf === undefined || rbac.canAll(p.allOf))\n )\n}\n\nfunction checkRoles(rbac: RbacChecker, p: LooseCondition & { role?: string | undefined }): boolean {\n if (p.role === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.role === undefined || rbac.hasRole(p.role)) &&\n (p.anyOf === undefined || rbac.hasAnyRole(p.anyOf)) &&\n (p.allOf === undefined || rbac.hasAllRoles(p.allOf))\n )\n}\n\n/** Renders `children` if the user has the permission(s) — like spatie's `@can` / `@canany`. */\nexport function Can(props: CanProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.children : props.fallback}</>\n}\n\n/** Renders `children` if the user does NOT have the permission(s) — like spatie's `@cannot`. */\nexport function Cannot(props: CannotProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.fallback : props.children}</>\n}\n\n/** Renders `children` if the user has the role(s) — like spatie's `@role` / `@hasanyrole` / `@hasallroles`. */\nexport function HasRole(props: HasRoleProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkRoles(rbac, props) ? props.children : props.fallback}</>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA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M,UAAS;AAC5E;AAGO,SAAS,QAAQ,OAAqB;AAC3C,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,6EAAG,qBAAW,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AACtE;","names":["import_jsx_runtime"]}
package/dist/index.d.cts CHANGED
@@ -4,11 +4,11 @@ import { ReactNode } from 'react';
4
4
 
5
5
  interface RbacCheckerOptions {
6
6
  /** Treat granted permissions as wildcard patterns (`articles.*`). Must match the server's `wildcard` setting. */
7
- wildcard?: boolean;
7
+ wildcard?: boolean | undefined;
8
8
  /** Roles that pass every permission check (like spatie's `Gate::before` super-admin pattern). */
9
- superAdminRoles?: readonly string[];
9
+ superAdminRoles?: readonly string[] | undefined;
10
10
  /** The snapshot is still being fetched: `<Can>`, `<Cannot>` and `<HasRole>` render nothing. Default: `false`. */
11
- loading?: boolean;
11
+ loading?: boolean | undefined;
12
12
  }
13
13
  /** Synchronous checks against a {@link RbacSnapshot}. */
14
14
  interface RbacChecker {
@@ -39,15 +39,15 @@ interface RbacProviderProps {
39
39
  /** Roles & permissions of the current user, e.g. from `rbac.for(user).snapshot()` on the server. `null` = guest. */
40
40
  snapshot: RbacSnapshot | null | undefined;
41
41
  /** Enable wildcard matching (`articles.*`). Must match the server's `wildcard` setting. Default: `false`. */
42
- wildcard?: boolean;
42
+ wildcard?: boolean | undefined;
43
43
  /** Roles that pass every `can` check (super admin). */
44
- superAdminRoles?: readonly string[];
44
+ superAdminRoles?: readonly string[] | undefined;
45
45
  /**
46
46
  * The snapshot is still being fetched. `<Can>`, `<Cannot>` and `<HasRole>` then render nothing
47
47
  * (not even `fallback`), so nothing flashes before the real permissions arrive. Default: `false`.
48
48
  */
49
- loading?: boolean;
50
- children?: ReactNode;
49
+ loading?: boolean | undefined;
50
+ children?: ReactNode | undefined;
51
51
  }
52
52
  /**
53
53
  * Provides a user's roles & permissions to `useCan()`, `<Can>`, ...
@@ -95,9 +95,9 @@ type RoleCondition = {
95
95
  allOf: readonly string[];
96
96
  };
97
97
  interface GateProps {
98
- children?: ReactNode;
98
+ children?: ReactNode | undefined;
99
99
  /** Rendered when the check fails. Default: nothing. */
100
- fallback?: ReactNode;
100
+ fallback?: ReactNode | undefined;
101
101
  }
102
102
  type CanProps = PermissionCondition & GateProps;
103
103
  type CannotProps = PermissionCondition & GateProps;
package/dist/index.d.ts CHANGED
@@ -4,11 +4,11 @@ import { ReactNode } from 'react';
4
4
 
5
5
  interface RbacCheckerOptions {
6
6
  /** Treat granted permissions as wildcard patterns (`articles.*`). Must match the server's `wildcard` setting. */
7
- wildcard?: boolean;
7
+ wildcard?: boolean | undefined;
8
8
  /** Roles that pass every permission check (like spatie's `Gate::before` super-admin pattern). */
9
- superAdminRoles?: readonly string[];
9
+ superAdminRoles?: readonly string[] | undefined;
10
10
  /** The snapshot is still being fetched: `<Can>`, `<Cannot>` and `<HasRole>` render nothing. Default: `false`. */
11
- loading?: boolean;
11
+ loading?: boolean | undefined;
12
12
  }
13
13
  /** Synchronous checks against a {@link RbacSnapshot}. */
14
14
  interface RbacChecker {
@@ -39,15 +39,15 @@ interface RbacProviderProps {
39
39
  /** Roles & permissions of the current user, e.g. from `rbac.for(user).snapshot()` on the server. `null` = guest. */
40
40
  snapshot: RbacSnapshot | null | undefined;
41
41
  /** Enable wildcard matching (`articles.*`). Must match the server's `wildcard` setting. Default: `false`. */
42
- wildcard?: boolean;
42
+ wildcard?: boolean | undefined;
43
43
  /** Roles that pass every `can` check (super admin). */
44
- superAdminRoles?: readonly string[];
44
+ superAdminRoles?: readonly string[] | undefined;
45
45
  /**
46
46
  * The snapshot is still being fetched. `<Can>`, `<Cannot>` and `<HasRole>` then render nothing
47
47
  * (not even `fallback`), so nothing flashes before the real permissions arrive. Default: `false`.
48
48
  */
49
- loading?: boolean;
50
- children?: ReactNode;
49
+ loading?: boolean | undefined;
50
+ children?: ReactNode | undefined;
51
51
  }
52
52
  /**
53
53
  * Provides a user's roles & permissions to `useCan()`, `<Can>`, ...
@@ -95,9 +95,9 @@ type RoleCondition = {
95
95
  allOf: readonly string[];
96
96
  };
97
97
  interface GateProps {
98
- children?: ReactNode;
98
+ children?: ReactNode | undefined;
99
99
  /** Rendered when the check fails. Default: nothing. */
100
- fallback?: ReactNode;
100
+ fallback?: ReactNode | undefined;
101
101
  }
102
102
  type CanProps = PermissionCondition & GateProps;
103
103
  type CannotProps = PermissionCondition & GateProps;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/checker.ts","../src/context.tsx","../src/components.tsx"],"sourcesContent":["import { wildcardImplies } from '@anievo-id/rbac-evolution'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\n\nexport interface RbacCheckerOptions {\n /** Treat granted permissions as wildcard patterns (`articles.*`). Must match the server's `wildcard` setting. */\n wildcard?: boolean\n /** Roles that pass every permission check (like spatie's `Gate::before` super-admin pattern). */\n superAdminRoles?: readonly string[]\n /** The snapshot is still being fetched: `<Can>`, `<Cannot>` and `<HasRole>` render nothing. Default: `false`. */\n loading?: boolean\n}\n\n/** Synchronous checks against a {@link RbacSnapshot}. */\nexport interface RbacChecker {\n readonly roles: readonly string[]\n readonly permissions: readonly string[]\n /** `true` if the subject has one of the configured `superAdminRoles`. */\n readonly isSuperAdmin: boolean\n /** `true` while the snapshot is still being fetched (the `loading` option). Every check, `cannot` included, returns `false` meanwhile. */\n readonly loading: boolean\n can(permission: string): boolean\n cannot(permission: string): boolean\n /** `true` if ANY of the permissions is granted. `false` for an empty list. */\n canAny(...permissions: Many<string>[]): boolean\n /** `true` if ALL of the permissions are granted. `false` for an empty list (deny by default, like the Vue package). */\n canAll(...permissions: Many<string>[]): boolean\n /** `true` if the subject has the role — or ANY of the roles when given an array. */\n hasRole(roles: Many<string>): boolean\n hasAnyRole(...roles: Many<string>[]): boolean\n hasAllRoles(...roles: Many<string>[]): boolean\n}\n\nconst EMPTY: RbacSnapshot = { roles: [], permissions: [] }\n\nfunction flatten(items: readonly Many<string>[]): string[] {\n const out: string[] = []\n for (const item of items) {\n if (typeof item === 'string') out.push(item)\n else out.push(...item)\n }\n return out\n}\n\nfunction safeImplies(granted: string, required: string): boolean {\n try {\n return wildcardImplies(granted, required)\n } catch {\n return false\n }\n}\n\n/**\n * Builds a pure, synchronous checker for a snapshot (as returned by `rbac.for(user).snapshot()`).\n * Used by `RbacProvider`, but usable on its own too.\n */\nexport function createRbacChecker(\n snapshot: RbacSnapshot | null | undefined,\n options: RbacCheckerOptions = {},\n): RbacChecker {\n const { roles, permissions } = snapshot ?? EMPTY\n const roleSet = new Set(roles)\n const permissionSet = new Set(permissions)\n const wildcard = options.wildcard ?? false\n // While loading, every check (`cannot` too) is false: neither a stale grant nor \"no access\" UI shows.\n const loading = options.loading ?? false\n const isSuperAdmin = !loading && (options.superAdminRoles ?? []).some((r) => roleSet.has(r))\n\n const can = (permission: string): boolean => {\n if (loading) return false\n if (isSuperAdmin) return true\n const name = permission.trim()\n if (name === '') return false\n if (permissionSet.has(name)) return true\n return wildcard && permissions.some((granted) => safeImplies(granted, name))\n }\n const hasOne = (role: string): boolean => !loading && roleSet.has(role.trim())\n\n return {\n roles,\n permissions,\n isSuperAdmin,\n loading,\n can,\n cannot: (permission) => !loading && !can(permission),\n canAny: (...list) => flatten(list).some(can),\n canAll: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(can)\n },\n hasRole: (list) => flatten([list]).some(hasOne),\n hasAnyRole: (...list) => flatten(list).some(hasOne),\n hasAllRoles: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(hasOne)\n },\n }\n}\n","import { createContext, useContext, useMemo } from 'react'\nimport type { ReactNode } from 'react'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\nimport { createRbacChecker } from './checker'\nimport type { RbacChecker } from './checker'\n\nconst RbacContext = createContext<RbacChecker | null>(null)\nRbacContext.displayName = 'RbacContext'\n\nexport interface RbacProviderProps {\n /** Roles & permissions of the current user, e.g. from `rbac.for(user).snapshot()` on the server. `null` = guest. */\n snapshot: RbacSnapshot | null | undefined\n /** Enable wildcard matching (`articles.*`). Must match the server's `wildcard` setting. Default: `false`. */\n wildcard?: boolean\n /** Roles that pass every `can` check (super admin). */\n superAdminRoles?: readonly string[]\n /**\n * The snapshot is still being fetched. `<Can>`, `<Cannot>` and `<HasRole>` then render nothing\n * (not even `fallback`), so nothing flashes before the real permissions arrive. Default: `false`.\n */\n loading?: boolean\n children?: ReactNode\n}\n\n/**\n * Provides a user's roles & permissions to `useCan()`, `<Can>`, ...\n *\n * UI only: this hides and shows elements. Always enforce authorization on the server.\n */\nexport function RbacProvider({ snapshot, wildcard = false, superAdminRoles, loading = false, children }: RbacProviderProps) {\n const superKey = superAdminRoles?.join('\\u0000') ?? ''\n const checker = useMemo(\n () => createRbacChecker(snapshot, superAdminRoles ? { wildcard, superAdminRoles, loading } : { wildcard, loading }),\n // `superKey` keeps inline arrays (`superAdminRoles={['admin']}`) from recomputing every render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [snapshot, wildcard, superKey, loading],\n )\n return <RbacContext.Provider value={checker}>{children}</RbacContext.Provider>\n}\n\n/** Returns the checker of the nearest `RbacProvider`. Throws when there is none. */\nexport function useRbac(): RbacChecker {\n const checker = useContext(RbacContext)\n if (!checker) {\n throw new Error('useRbac() must be used inside <RbacProvider>.')\n }\n return checker\n}\n\nexport function useCan(permission: string): boolean {\n return useRbac().can(permission)\n}\n\nexport function useCannot(permission: string): boolean {\n return useRbac().cannot(permission)\n}\n\nexport function useCanAny(...permissions: Many<string>[]): boolean {\n return useRbac().canAny(...permissions)\n}\n\nexport function useCanAll(...permissions: Many<string>[]): boolean {\n return useRbac().canAll(...permissions)\n}\n\n/** `true` if the user has the role — or ANY of the roles when given an array. */\nexport function useHasRole(role: Many<string>): boolean {\n return useRbac().hasRole(role)\n}\n\nexport function useHasAnyRole(...roles: Many<string>[]): boolean {\n return useRbac().hasAnyRole(...roles)\n}\n\nexport function useHasAllRoles(...roles: Many<string>[]): boolean {\n return useRbac().hasAllRoles(...roles)\n}\n","import type { ReactNode } from 'react'\nimport type { RbacChecker } from './checker'\nimport { useRbac } from './context'\n\n/** Exactly one of `permission`, `anyOf` or `allOf`. */\nexport type PermissionCondition =\n | { permission: string; anyOf?: never; allOf?: never }\n | { permission?: never; anyOf: readonly string[]; allOf?: never }\n | { permission?: never; anyOf?: never; allOf: readonly string[] }\n\n/** Exactly one of `role`, `anyOf` or `allOf`. */\nexport type RoleCondition =\n | { role: string; anyOf?: never; allOf?: never }\n | { role?: never; anyOf: readonly string[]; allOf?: never }\n | { role?: never; anyOf?: never; allOf: readonly string[] }\n\ninterface GateProps {\n children?: ReactNode\n /** Rendered when the check fails. Default: nothing. */\n fallback?: ReactNode\n}\n\nexport type CanProps = PermissionCondition & GateProps\nexport type CannotProps = PermissionCondition & GateProps\nexport type HasRoleProps = RoleCondition & GateProps\n\ninterface LooseCondition {\n anyOf?: readonly string[] | undefined\n allOf?: readonly string[] | undefined\n}\n\n// Conditions are ANDed; no condition at all is denied (deny by default, also for untyped JS callers).\nfunction checkPermissions(rbac: RbacChecker, p: LooseCondition & { permission?: string | undefined }): boolean {\n if (p.permission === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.permission === undefined || rbac.can(p.permission)) &&\n (p.anyOf === undefined || rbac.canAny(p.anyOf)) &&\n (p.allOf === undefined || rbac.canAll(p.allOf))\n )\n}\n\nfunction checkRoles(rbac: RbacChecker, p: LooseCondition & { role?: string | undefined }): boolean {\n if (p.role === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.role === undefined || rbac.hasRole(p.role)) &&\n (p.anyOf === undefined || rbac.hasAnyRole(p.anyOf)) &&\n (p.allOf === undefined || rbac.hasAllRoles(p.allOf))\n )\n}\n\n/** Renders `children` if the user has the permission(s) — like spatie's `@can` / `@canany`. */\nexport function Can(props: CanProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.children : props.fallback}</>\n}\n\n/** Renders `children` if the user does NOT have the permission(s) — like spatie's `@cannot`. */\nexport function Cannot(props: CannotProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.fallback : props.children}</>\n}\n\n/** Renders `children` if the user has the role(s) — like spatie's `@role` / `@hasanyrole` / `@hasallroles`. */\nexport function HasRole(props: HasRoleProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkRoles(rbac, props) ? props.children : props.fallback}</>\n}\n"],"mappings":";;;AAAA,SAAS,uBAAuB;AAgChC,IAAM,QAAsB,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,EAAE;AAEzD,SAAS,QAAQ,OAA0C;AACzD,QAAM,MAAgB,CAAC;AACvB,aAAW,QAAQ,OAAO;AACxB,QAAI,OAAO,SAAS,SAAU,KAAI,KAAK,IAAI;AAAA,QACtC,KAAI,KAAK,GAAG,IAAI;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,YAAY,SAAiB,UAA2B;AAC/D,MAAI;AACF,WAAO,gBAAgB,SAAS,QAAQ;AAAA,EAC1C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMO,SAAS,kBACd,UACA,UAA8B,CAAC,GAClB;AACb,QAAM,EAAE,OAAO,YAAY,IAAI,YAAY;AAC3C,QAAM,UAAU,IAAI,IAAI,KAAK;AAC7B,QAAM,gBAAgB,IAAI,IAAI,WAAW;AACzC,QAAM,WAAW,QAAQ,YAAY;AAErC,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,eAAe,CAAC,YAAY,QAAQ,mBAAmB,CAAC,GAAG,KAAK,CAAC,MAAM,QAAQ,IAAI,CAAC,CAAC;AAE3F,QAAM,MAAM,CAAC,eAAgC;AAC3C,QAAI,QAAS,QAAO;AACpB,QAAI,aAAc,QAAO;AACzB,UAAM,OAAO,WAAW,KAAK;AAC7B,QAAI,SAAS,GAAI,QAAO;AACxB,QAAI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AACnC,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,gBAAAA,KAAA,YAAG,2BAAiB,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AAC5E;AAGO,SAAS,OAAO,OAAoB;AACzC,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,gBAAAA,KAAA,YAAG,2BAAiB,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AAC5E;AAGO,SAAS,QAAQ,OAAqB;AAC3C,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,gBAAAA,KAAA,YAAG,qBAAW,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AACtE;","names":["jsx"]}
1
+ {"version":3,"sources":["../src/checker.ts","../src/context.tsx","../src/components.tsx"],"sourcesContent":["import { wildcardImplies } from '@anievo-id/rbac-evolution'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\n\nexport interface RbacCheckerOptions {\n /** Treat granted permissions as wildcard patterns (`articles.*`). Must match the server's `wildcard` setting. */\n wildcard?: boolean | undefined\n /** Roles that pass every permission check (like spatie's `Gate::before` super-admin pattern). */\n superAdminRoles?: readonly string[] | undefined\n /** The snapshot is still being fetched: `<Can>`, `<Cannot>` and `<HasRole>` render nothing. Default: `false`. */\n loading?: boolean | undefined\n}\n\n/** Synchronous checks against a {@link RbacSnapshot}. */\nexport interface RbacChecker {\n readonly roles: readonly string[]\n readonly permissions: readonly string[]\n /** `true` if the subject has one of the configured `superAdminRoles`. */\n readonly isSuperAdmin: boolean\n /** `true` while the snapshot is still being fetched (the `loading` option). Every check, `cannot` included, returns `false` meanwhile. */\n readonly loading: boolean\n can(permission: string): boolean\n cannot(permission: string): boolean\n /** `true` if ANY of the permissions is granted. `false` for an empty list. */\n canAny(...permissions: Many<string>[]): boolean\n /** `true` if ALL of the permissions are granted. `false` for an empty list (deny by default, like the Vue package). */\n canAll(...permissions: Many<string>[]): boolean\n /** `true` if the subject has the role — or ANY of the roles when given an array. */\n hasRole(roles: Many<string>): boolean\n hasAnyRole(...roles: Many<string>[]): boolean\n hasAllRoles(...roles: Many<string>[]): boolean\n}\n\nconst EMPTY: RbacSnapshot = { roles: [], permissions: [] }\n\nfunction flatten(items: readonly Many<string>[]): string[] {\n const out: string[] = []\n for (const item of items) {\n if (typeof item === 'string') out.push(item)\n else out.push(...item)\n }\n return out\n}\n\nfunction safeImplies(granted: string, required: string): boolean {\n try {\n return wildcardImplies(granted, required)\n } catch {\n return false\n }\n}\n\n/**\n * Builds a pure, synchronous checker for a snapshot (as returned by `rbac.for(user).snapshot()`).\n * Used by `RbacProvider`, but usable on its own too.\n */\nexport function createRbacChecker(\n snapshot: RbacSnapshot | null | undefined,\n options: RbacCheckerOptions = {},\n): RbacChecker {\n const { roles, permissions } = snapshot ?? EMPTY\n const roleSet = new Set(roles)\n const permissionSet = new Set(permissions)\n const wildcard = options.wildcard ?? false\n // While loading, every check (`cannot` too) is false: neither a stale grant nor \"no access\" UI shows.\n const loading = options.loading ?? false\n const isSuperAdmin = !loading && (options.superAdminRoles ?? []).some((r) => roleSet.has(r))\n\n const can = (permission: string): boolean => {\n if (loading) return false\n if (isSuperAdmin) return true\n const name = permission.trim()\n if (name === '') return false\n if (permissionSet.has(name)) return true\n return wildcard && permissions.some((granted) => safeImplies(granted, name))\n }\n const hasOne = (role: string): boolean => !loading && roleSet.has(role.trim())\n\n return {\n roles,\n permissions,\n isSuperAdmin,\n loading,\n can,\n cannot: (permission) => !loading && !can(permission),\n canAny: (...list) => flatten(list).some(can),\n canAll: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(can)\n },\n hasRole: (list) => flatten([list]).some(hasOne),\n hasAnyRole: (...list) => flatten(list).some(hasOne),\n hasAllRoles: (...list) => {\n const wanted = flatten(list)\n return wanted.length > 0 && wanted.every(hasOne)\n },\n }\n}\n","import { createContext, useContext, useMemo } from 'react'\nimport type { ReactNode } from 'react'\nimport type { Many, RbacSnapshot } from '@anievo-id/rbac-evolution'\nimport { createRbacChecker } from './checker'\nimport type { RbacChecker } from './checker'\n\nconst RbacContext = createContext<RbacChecker | null>(null)\nRbacContext.displayName = 'RbacContext'\n\nexport interface RbacProviderProps {\n /** Roles & permissions of the current user, e.g. from `rbac.for(user).snapshot()` on the server. `null` = guest. */\n snapshot: RbacSnapshot | null | undefined\n /** Enable wildcard matching (`articles.*`). Must match the server's `wildcard` setting. Default: `false`. */\n wildcard?: boolean | undefined\n /** Roles that pass every `can` check (super admin). */\n superAdminRoles?: readonly string[] | undefined\n /**\n * The snapshot is still being fetched. `<Can>`, `<Cannot>` and `<HasRole>` then render nothing\n * (not even `fallback`), so nothing flashes before the real permissions arrive. Default: `false`.\n */\n loading?: boolean | undefined\n children?: ReactNode | undefined\n}\n\n/**\n * Provides a user's roles & permissions to `useCan()`, `<Can>`, ...\n *\n * UI only: this hides and shows elements. Always enforce authorization on the server.\n */\nexport function RbacProvider({ snapshot, wildcard = false, superAdminRoles, loading = false, children }: RbacProviderProps) {\n const superKey = superAdminRoles?.join('\\u0000') ?? ''\n const checker = useMemo(\n () => createRbacChecker(snapshot, superAdminRoles ? { wildcard, superAdminRoles, loading } : { wildcard, loading }),\n // `superKey` keeps inline arrays (`superAdminRoles={['admin']}`) from recomputing every render.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [snapshot, wildcard, superKey, loading],\n )\n return <RbacContext.Provider value={checker}>{children}</RbacContext.Provider>\n}\n\n/** Returns the checker of the nearest `RbacProvider`. Throws when there is none. */\nexport function useRbac(): RbacChecker {\n const checker = useContext(RbacContext)\n if (!checker) {\n throw new Error('useRbac() must be used inside <RbacProvider>.')\n }\n return checker\n}\n\nexport function useCan(permission: string): boolean {\n return useRbac().can(permission)\n}\n\nexport function useCannot(permission: string): boolean {\n return useRbac().cannot(permission)\n}\n\nexport function useCanAny(...permissions: Many<string>[]): boolean {\n return useRbac().canAny(...permissions)\n}\n\nexport function useCanAll(...permissions: Many<string>[]): boolean {\n return useRbac().canAll(...permissions)\n}\n\n/** `true` if the user has the role — or ANY of the roles when given an array. */\nexport function useHasRole(role: Many<string>): boolean {\n return useRbac().hasRole(role)\n}\n\nexport function useHasAnyRole(...roles: Many<string>[]): boolean {\n return useRbac().hasAnyRole(...roles)\n}\n\nexport function useHasAllRoles(...roles: Many<string>[]): boolean {\n return useRbac().hasAllRoles(...roles)\n}\n","import type { ReactNode } from 'react'\nimport type { RbacChecker } from './checker'\nimport { useRbac } from './context'\n\n/** Exactly one of `permission`, `anyOf` or `allOf`. */\nexport type PermissionCondition =\n | { permission: string; anyOf?: never; allOf?: never }\n | { permission?: never; anyOf: readonly string[]; allOf?: never }\n | { permission?: never; anyOf?: never; allOf: readonly string[] }\n\n/** Exactly one of `role`, `anyOf` or `allOf`. */\nexport type RoleCondition =\n | { role: string; anyOf?: never; allOf?: never }\n | { role?: never; anyOf: readonly string[]; allOf?: never }\n | { role?: never; anyOf?: never; allOf: readonly string[] }\n\ninterface GateProps {\n children?: ReactNode | undefined\n /** Rendered when the check fails. Default: nothing. */\n fallback?: ReactNode | undefined\n}\n\nexport type CanProps = PermissionCondition & GateProps\nexport type CannotProps = PermissionCondition & GateProps\nexport type HasRoleProps = RoleCondition & GateProps\n\ninterface LooseCondition {\n anyOf?: readonly string[] | undefined\n allOf?: readonly string[] | undefined\n}\n\n// Conditions are ANDed; no condition at all is denied (deny by default, also for untyped JS callers).\nfunction checkPermissions(rbac: RbacChecker, p: LooseCondition & { permission?: string | undefined }): boolean {\n if (p.permission === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.permission === undefined || rbac.can(p.permission)) &&\n (p.anyOf === undefined || rbac.canAny(p.anyOf)) &&\n (p.allOf === undefined || rbac.canAll(p.allOf))\n )\n}\n\nfunction checkRoles(rbac: RbacChecker, p: LooseCondition & { role?: string | undefined }): boolean {\n if (p.role === undefined && p.anyOf === undefined && p.allOf === undefined) return false\n return (\n (p.role === undefined || rbac.hasRole(p.role)) &&\n (p.anyOf === undefined || rbac.hasAnyRole(p.anyOf)) &&\n (p.allOf === undefined || rbac.hasAllRoles(p.allOf))\n )\n}\n\n/** Renders `children` if the user has the permission(s) — like spatie's `@can` / `@canany`. */\nexport function Can(props: CanProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.children : props.fallback}</>\n}\n\n/** Renders `children` if the user does NOT have the permission(s) — like spatie's `@cannot`. */\nexport function Cannot(props: CannotProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkPermissions(rbac, props) ? props.fallback : props.children}</>\n}\n\n/** Renders `children` if the user has the role(s) — like spatie's `@role` / `@hasanyrole` / `@hasallroles`. */\nexport function HasRole(props: HasRoleProps) {\n const rbac = useRbac()\n if (rbac.loading) return null\n return <>{checkRoles(rbac, props) ? props.children : props.fallback}</>\n}\n"],"mappings":";;;AAAA,SAAS,uBAAuB;AAgChC,IAAM,QAAsB,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,EAAE;AAEzD,SAAS,QAAQ,OAA0C;AACzD,QAAM,MAAgB,CAAC;AACvB,aAAW,QAAQ,OAAO;AACxB,QAAI,OAAO,SAAS,SAAU,KAAI,KAAK,IAAI;AAAA,QACtC,KAAI,KAAK,GAAG,IAAI;AAAA,EACvB;AACA,SAAO;AACT;AAEA,SAAS,YAAY,SAAiB,UAA2B;AAC/D,MAAI;AACF,WAAO,gBAAgB,SAAS,QAAQ;AAAA,EAC1C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMO,SAAS,kBACd,UACA,UAA8B,CAAC,GAClB;AACb,QAAM,EAAE,OAAO,YAAY,IAAI,YAAY;AAC3C,QAAM,UAAU,IAAI,IAAI,KAAK;AAC7B,QAAM,gBAAgB,IAAI,IAAI,WAAW;AACzC,QAAM,WAAW,QAAQ,YAAY;AAErC,QAAM,UAAU,QAAQ,WAAW;AACnC,QAAM,eAAe,C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AS,UAAa,EAAE,UAAU,UAAa,EAAE,UAAU,OAAW,QAAO;AACnF,UACG,EAAE,SAAS,UAAa,KAAK,QAAQ,EAAE,IAAI,OAC3C,EAAE,UAAU,UAAa,KAAK,WAAW,EAAE,KAAK,OAChD,EAAE,UAAU,UAAa,KAAK,YAAY,EAAE,KAAK;AAEtD;AAGO,SAAS,IAAI,OAAiB;AACnC,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,gBAAAA,KAAA,YAAG,2BAAiB,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AAC5E;AAGO,SAAS,OAAO,OAAoB;AACzC,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,gBAAAA,KAAA,YAAG,2BAAiB,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AAC5E;AAGO,SAAS,QAAQ,OAAqB;AAC3C,QAAM,OAAO,QAAQ;AACrB,MAAI,KAAK,QAAS,QAAO;AACzB,SAAO,gBAAAA,KAAA,YAAG,qBAAW,MAAM,KAAK,IAAI,MAAM,WAAW,MAAM,UAAS;AACtE;","names":["jsx"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anievo-id/rbac-evolution-react",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "React bindings for rbac-evolution: <Can>, useCan(), useHasRole().",
5
5
  "license": "MIT",
6
6
  "author": "AniEvo-ID (https://github.com/AniEvo-ID)",
@@ -46,7 +46,7 @@
46
46
  "access": "public"
47
47
  },
48
48
  "dependencies": {
49
- "@anievo-id/rbac-evolution": "^0.7.0"
49
+ "@anievo-id/rbac-evolution": "^0.7.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "react": ">=18"