@anievo-id/rbac-evolution-sveltekit 1.4.0 → 1.5.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 AniEvo-ID
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AniEvo-ID
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,69 +1,69 @@
1
- # @anievo-id/rbac-evolution-sveltekit
2
-
3
- SvelteKit 2 and 3 (Svelte 5) integration for [RBAC Evolution](https://github.com/AniEvo-ID/rbac-evolution): a
4
- `handle` hook, guards for `load` functions, form actions and `+server.ts` endpoints, and `<Can>` / `<HasRole>`
5
- components with a runes-based context.
6
-
7
- ## Install
8
-
9
- ```bash
10
- npm i @anievo-id/rbac-evolution @anievo-id/rbac-evolution-sveltekit
11
- ```
12
-
13
- ## Usage
14
-
15
- ```ts
16
- // src/hooks.server.ts
17
- import { sequence } from '@sveltejs/kit/hooks'
18
- import { rbacHandle } from '@anievo-id/rbac-evolution-sveltekit/server'
19
- import { rbac } from '$lib/server/rbac' // createRbac({ adapter })
20
-
21
- export const handle = sequence(
22
- authHandle, // yours: sets event.locals.user
23
- rbacHandle({ rbac, getSubject: (event) => (event.locals.user ? { type: 'user', id: event.locals.user.id } : null) }),
24
- )
25
- ```
26
-
27
- ```ts
28
- // src/routes/+layout.server.ts
29
- import { getSnapshot } from '@anievo-id/rbac-evolution-sveltekit/server'
30
- export const load = async (event) => ({ rbac: await getSnapshot(event) })
31
-
32
- // src/routes/admin/+page.server.ts
33
- import { requireRole } from '@anievo-id/rbac-evolution-sveltekit/server'
34
- export const load = async (event) => {
35
- await requireRole(event, 'admin') // error(401) for guests, error(403) without the role
36
- }
37
- ```
38
-
39
- ```svelte
40
- <!-- src/routes/+layout.svelte -->
41
- <script lang="ts">
42
- import { setRbacContext } from '@anievo-id/rbac-evolution-sveltekit'
43
- let { data, children } = $props()
44
- setRbacContext(() => data.rbac, { superAdminRoles: ['super-admin'] })
45
- </script>
46
-
47
- {@render children()}
48
-
49
- <!-- any component below it -->
50
- <script lang="ts">
51
- import { Can, HasRole } from '@anievo-id/rbac-evolution-sveltekit'
52
- </script>
53
-
54
- <Can permission="articles.publish">
55
- <button>Publish</button>
56
- {#snippet fallback()}Ask an editor.{/snippet}
57
- </Can>
58
- <HasRole role="admin|editor">Staff tools</HasRole>
59
- ```
60
-
61
- > Client checks only decide what the UI shows. Enforce access on the server with the guards of `/server`.
62
-
63
- ## Documentation
64
-
65
- https://creation.anievo.id/rbac-evolution/frameworks/sveltekit
66
-
67
- ## License
68
-
69
- MIT
1
+ # @anievo-id/rbac-evolution-sveltekit
2
+
3
+ SvelteKit 2 and 3 (Svelte 5) integration for [RBAC Evolution](https://github.com/AniEvo-ID/rbac-evolution): a
4
+ `handle` hook, guards for `load` functions, form actions and `+server.ts` endpoints, and `<Can>` / `<HasRole>`
5
+ components with a runes-based context.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i @anievo-id/rbac-evolution @anievo-id/rbac-evolution-sveltekit
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ts
16
+ // src/hooks.server.ts
17
+ import { sequence } from '@sveltejs/kit/hooks'
18
+ import { rbacHandle } from '@anievo-id/rbac-evolution-sveltekit/server'
19
+ import { rbac } from '$lib/server/rbac' // createRbac({ adapter })
20
+
21
+ export const handle = sequence(
22
+ authHandle, // yours: sets event.locals.user
23
+ rbacHandle({ rbac, getSubject: (event) => (event.locals.user ? { type: 'user', id: event.locals.user.id } : null) }),
24
+ )
25
+ ```
26
+
27
+ ```ts
28
+ // src/routes/+layout.server.ts
29
+ import { getSnapshot } from '@anievo-id/rbac-evolution-sveltekit/server'
30
+ export const load = async (event) => ({ rbac: await getSnapshot(event) })
31
+
32
+ // src/routes/admin/+page.server.ts
33
+ import { requireRole } from '@anievo-id/rbac-evolution-sveltekit/server'
34
+ export const load = async (event) => {
35
+ await requireRole(event, 'admin') // error(401) for guests, error(403) without the role
36
+ }
37
+ ```
38
+
39
+ ```svelte
40
+ <!-- src/routes/+layout.svelte -->
41
+ <script lang="ts">
42
+ import { setRbacContext } from '@anievo-id/rbac-evolution-sveltekit'
43
+ let { data, children } = $props()
44
+ setRbacContext(() => data.rbac, { superAdminRoles: ['super-admin'] })
45
+ </script>
46
+
47
+ {@render children()}
48
+
49
+ <!-- any component below it -->
50
+ <script lang="ts">
51
+ import { Can, HasRole } from '@anievo-id/rbac-evolution-sveltekit'
52
+ </script>
53
+
54
+ <Can permission="articles.publish">
55
+ <button>Publish</button>
56
+ {#snippet fallback()}Ask an editor.{/snippet}
57
+ </Can>
58
+ <HasRole role="admin|editor">Staff tools</HasRole>
59
+ ```
60
+
61
+ > Client checks only decide what the UI shows. Enforce access on the server with the guards of `/server`.
62
+
63
+ ## Documentation
64
+
65
+ https://creation.anievo.id/rbac-evolution/frameworks/sveltekit
66
+
67
+ ## License
68
+
69
+ MIT
package/dist/Can.svelte CHANGED
@@ -1,17 +1,17 @@
1
- <!--
2
- @component
3
- Renders `children` when the user has the permission(s), otherwise the `fallback` snippet.
4
- Conditions are ANDed; without any condition nothing passes (deny by default). `not` inverts the result.
5
-
6
- ```svelte
7
- <Can permission="articles.edit">...</Can>
8
- <Can anyOf={['articles.edit', 'articles.delete']}>
9
- ...
10
- {#snippet fallback()}No access{/snippet}
11
- </Can>
12
- <Can allOf={['a', 'b']}>...</Can>
13
- ```
14
- -->
1
+ <!--
2
+ @component
3
+ Renders `children` when the user has the permission(s), otherwise the `fallback` snippet.
4
+ Conditions are ANDed; without any condition nothing passes (deny by default). `not` inverts the result.
5
+
6
+ ```svelte
7
+ <Can permission="articles.edit">...</Can>
8
+ <Can anyOf={['articles.edit', 'articles.delete']}>
9
+ ...
10
+ {#snippet fallback()}No access{/snippet}
11
+ </Can>
12
+ <Can allOf={['a', 'b']}>...</Can>
13
+ ```
14
+ -->
15
15
  <script lang="ts">import { getRbacContext } from "./context.svelte.js";
16
16
  let { permission, anyOf, allOf, not = false, children, fallback } = $props();
17
17
  const rbac = getRbacContext();
@@ -20,10 +20,10 @@ const allowed = $derived(
20
20
  (permission === void 0 || rbac.canAll(permission)) && (anyOf === void 0 || rbac.canAny(anyOf)) && (allOf === void 0 || rbac.canAll(allOf))
21
21
  );
22
22
  const pass = $derived(hasCondition && allowed !== not);
23
- </script>
24
-
25
- {#if pass}
26
- {@render children?.()}
27
- {:else}
28
- {@render fallback?.()}
29
- {/if}
23
+ </script>
24
+
25
+ {#if pass}
26
+ {@render children?.()}
27
+ {:else}
28
+ {@render fallback?.()}
29
+ {/if}
@@ -1,14 +1,14 @@
1
- <!--
2
- @component
3
- Renders `children` when the user has the role(s), otherwise the `fallback` snippet.
4
- Conditions are ANDed; without any condition nothing passes (deny by default). `not` inverts the result.
5
-
6
- ```svelte
7
- <HasRole role="admin">...</HasRole>
8
- <HasRole role="writer|editor">...</HasRole>
9
- <HasRole allOf={['writer', 'editor']}>...</HasRole>
10
- ```
11
- -->
1
+ <!--
2
+ @component
3
+ Renders `children` when the user has the role(s), otherwise the `fallback` snippet.
4
+ Conditions are ANDed; without any condition nothing passes (deny by default). `not` inverts the result.
5
+
6
+ ```svelte
7
+ <HasRole role="admin">...</HasRole>
8
+ <HasRole role="writer|editor">...</HasRole>
9
+ <HasRole allOf={['writer', 'editor']}>...</HasRole>
10
+ ```
11
+ -->
12
12
  <script lang="ts">import { getRbacContext } from "./context.svelte.js";
13
13
  let { role, anyOf, allOf, not = false, children, fallback } = $props();
14
14
  const rbac = getRbacContext();
@@ -17,10 +17,10 @@ const allowed = $derived(
17
17
  (role === void 0 || rbac.hasAnyRole(role)) && (anyOf === void 0 || rbac.hasAnyRole(anyOf)) && (allOf === void 0 || rbac.hasAllRoles(allOf))
18
18
  );
19
19
  const pass = $derived(hasCondition && allowed !== not);
20
- </script>
21
-
22
- {#if pass}
23
- {@render children?.()}
24
- {:else}
25
- {@render fallback?.()}
26
- {/if}
20
+ </script>
21
+
22
+ {#if pass}
23
+ {@render children?.()}
24
+ {:else}
25
+ {@render fallback?.()}
26
+ {/if}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anievo-id/rbac-evolution-sveltekit",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "SvelteKit integration for rbac-evolution: a handle hook, guards for loads, form actions & endpoints, and Svelte 5 components.",
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": "^1.4.0"
49
+ "@anievo-id/rbac-evolution": "^1.5.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@sveltejs/kit": ">=2",