@frigear-nu/authorization 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -8,4 +8,4 @@ current user is injected by a client/server resolver, and check with `authorize`
8
8
  - Route rules as keys on Nuxt's native `routeRules` (`roles`, `ability`, `guest`, `authenticated`) and per page (`definePageMeta({ authorize })`).
9
9
  - Overridable user resolvers (`authorization.resolvers.server` / `.client`).
10
10
 
11
- See the [documentation](../../apps/docs/content/4.modules/11.authorization.md) for usage.
11
+ See the [documentation](../../apps/docs/content/4.modules/04.authorization.md) for usage.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/authorization",
3
3
  "configKey": "authorization",
4
- "version": "0.0.5",
4
+ "version": "0.0.7",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { defineNuxtModule, createResolver, addServerTemplate, addTemplate, addTypeTemplate, addImports, addServerImports, addComponentsDir, addServerImportsDir, addRouteMiddleware, addServerHandler } from '@nuxt/kit';
4
- import { registerModule, extendDatabaseTable } from '@frigear-nu/module-kit/utils';
4
+ import { registerModule, extendDatabaseTable, inlineModuleRuntime } from '@frigear-nu/module-kit/utils';
5
5
  import { ROUTE_RULE_KEYS } from '../dist/runtime/utils/types.js';
6
6
 
7
7
  const module$1 = defineNuxtModule({
@@ -16,6 +16,9 @@ const module$1 = defineNuxtModule({
16
16
  "@frigear-nu/module-kit": {
17
17
  version: ">=0.0.1"
18
18
  },
19
+ "@frigear-nu/auth": {
20
+ version: ">=0.0.1"
21
+ },
19
22
  "@frigear-nu/users": {
20
23
  version: ">=0.0.1"
21
24
  }
@@ -106,6 +109,7 @@ export {}
106
109
  })));
107
110
  addComponentsDir({ path: resolver.resolve("./runtime/app/components") });
108
111
  addServerImportsDir(resolver.resolve("./runtime/server/utils"));
112
+ inlineModuleRuntime(nuxt, resolver);
109
113
  addRouteMiddleware({
110
114
  name: "authorization",
111
115
  path: resolver.resolve("./runtime/app/middleware/authorization.global"),
@@ -1,4 +1,4 @@
1
1
  export default async function resolveServerUser(event) {
2
- const session = await getUserSession(event);
3
- return session.user ?? null;
2
+ const auth = await getAuth(event);
3
+ return auth?.user ?? null;
4
4
  }
@@ -3,3 +3,4 @@ export * from './error.js';
3
3
  export * from './ability.js';
4
4
  export * from './bouncer.js';
5
5
  export * from './rules.js';
6
+ export * from './roles.js';
@@ -3,3 +3,4 @@ export * from "./error.js";
3
3
  export * from "./ability.js";
4
4
  export * from "./bouncer.js";
5
5
  export * from "./rules.js";
6
+ export * from "./roles.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Role hierarchy helpers. A hierarchy is an array of role names **from highest to lowest** rank, e.g.
3
+ * `['admin', 'manager', 'member', 'user']`. Unknown roles never outrank (or equal) anything.
4
+ */
5
+ export type RoleHierarchy = readonly string[];
6
+ /** Whether `source` ranks strictly above `target`. */
7
+ export declare function roleIsHigher(roles: RoleHierarchy, source: string | null | undefined, target: string | null | undefined): boolean;
8
+ /** Whether `source` ranks above or equal to `target`. */
9
+ export declare function roleIsHigherOrEqual(roles: RoleHierarchy, source: string | null | undefined, target: string | null | undefined): boolean;
10
+ /**
11
+ * Whether `actor` may assign (or change) the role `target`: only roles strictly below their own, unless the actor's
12
+ * own role is listed in `equalAllowedFor` (e.g. `['admin']`, so admins can create other admins).
13
+ */
14
+ export declare function canManageRole(roles: RoleHierarchy, actor: string | null | undefined, target: string | null | undefined, { equalAllowedFor }?: {
15
+ equalAllowedFor?: readonly string[];
16
+ }): boolean;
@@ -0,0 +1,12 @@
1
+ export function roleIsHigher(roles, source, target) {
2
+ if (!source || !target || !roles.includes(source) || !roles.includes(target)) return false;
3
+ return roles.indexOf(source) < roles.indexOf(target);
4
+ }
5
+ export function roleIsHigherOrEqual(roles, source, target) {
6
+ if (!source || !target || !roles.includes(source) || !roles.includes(target)) return false;
7
+ return roles.indexOf(source) <= roles.indexOf(target);
8
+ }
9
+ export function canManageRole(roles, actor, target, { equalAllowedFor = [] } = {}) {
10
+ if (roleIsHigher(roles, actor, target)) return true;
11
+ return !!actor && actor === target && equalAllowedFor.includes(actor) && roles.includes(actor);
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/authorization",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Policy-based authorization (abilities, resolvers, route rules, <Can>) for the frigear ecosystem, built on @frigear-nu/users.",
5
5
  "homepage": "https://docs.frigear.dev/modules/authorization",
6
6
  "repository": {
@@ -30,8 +30,9 @@
30
30
  "playground"
31
31
  ],
32
32
  "dependencies": {
33
- "@frigear-nu/module-kit": "0.1.6",
34
- "@frigear-nu/users": "1.0.8",
33
+ "@frigear-nu/module-kit": "1.0.0",
34
+ "@frigear-nu/auth": "0.0.4",
35
+ "@frigear-nu/users": "1.0.10",
35
36
  "@libsql/client": "^0.18.0",
36
37
  "@nuxt/kit": "^4.6.0",
37
38
  "drizzle-kit": "^0.31.11",