@frigear-nu/account 0.4.0 → 0.6.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/dist/module.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Permission } from '@frigear-nu/auth/access';
2
3
 
3
4
  /** A downloadable file listed on the documents page. */
4
5
  type AccountDocument = {
@@ -9,10 +10,11 @@ type AccountDocument = {
9
10
  path: string;
10
11
  icon?: string;
11
12
  /**
12
- * Only shown to users with one of these roles (the `role` of the session user). Omit to show to every signed-in
13
- * user. This only decides what is *listed*: a file in `public/` can still be fetched by anyone who knows its URL.
13
+ * The permission (`resource:action`) a user must hold to see the document listed. Omit to show it to every
14
+ * signed-in user. Needs `@frigear-nu/authorization`; without it a document with a permission is never listed. This only
15
+ * decides what is *listed*: a file in `public/` can still be fetched by anyone who knows its URL.
14
16
  */
15
- roles?: string[];
17
+ permission?: Permission;
16
18
  };
17
19
  type PublicModuleOptions = {
18
20
  pages: {
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/account",
3
3
  "configKey": "account",
4
- "version": "0.4.0",
4
+ "version": "0.6.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -48,7 +48,18 @@ const module$1 = defineNuxtModule({
48
48
  available: () => hasNuxtModule("@frigear-nu/menu", nuxt),
49
49
  fallback: "undefined",
50
50
  fallbackType: "undefined"
51
+ }, {
52
+ // `@frigear-nu/authorization` is optional: without it nothing can be checked, so permission-gated documents are hidden.
53
+ name: "useAuthorization",
54
+ available: () => hasNuxtModule("@frigear-nu/authorization", nuxt),
55
+ fallback: "undefined",
56
+ fallbackType: "undefined"
51
57
  }]);
58
+ for (const document of settings.documents ?? []) {
59
+ if (document.roles !== void 0) {
60
+ throw new Error(`[@frigear-nu/account] \`account.settings.documents[].roles\` was removed (document "${document.id}"): use \`permission\` (a \`resource:action\` string) instead.`);
61
+ }
62
+ }
52
63
  addImports([
53
64
  { name: "useAccount", from: resolver.resolve("./runtime/app/composables/useAccount") },
54
65
  { name: "useAccountNav", from: resolver.resolve("./runtime/app/composables/useAccountNav") }
@@ -48,11 +48,7 @@ const appearance = (label, value, icon) => ({
48
48
  }
49
49
  });
50
50
  const items = computed(() => {
51
- const visible = (dropdown.value ?? []).filter((item) => {
52
- const roles = item.meta?.roles;
53
- if (roles?.length && !(role.value && roles.includes(role.value))) return false;
54
- return !item.to || item.external || item.method || !isHere(item.to);
55
- });
51
+ const visible = (dropdown.value ?? []).filter((item) => !item.to || item.external || item.method || !isHere(item.to));
56
52
  const last = (item) => (item.order ?? 0) >= 99;
57
53
  return [
58
54
  sessionUser.value ? [{ type: "label", label: displayName.value, slot: "account" }] : [],
@@ -1,12 +1,13 @@
1
1
  <script setup>
2
2
  import { documentLabel, visibleDocuments } from "../utils/documents";
3
- import { computed, useModuleT, useNuxtApp, useRuntimeConfig, useUserSession } from "#imports";
3
+ import { computed, useModuleT, useNuxtApp, useRuntimeConfig } from "#imports";
4
+ import { useAuthorization } from "#account/optional";
4
5
  defineOptions({ name: "AccountDocumentsPage" });
5
6
  const t = useModuleT("account.documents");
6
- const { user } = useUserSession();
7
+ const authorization = typeof useAuthorization === "function" ? useAuthorization() : void 0;
7
8
  const nuxtApp = useNuxtApp();
8
9
  const locale = computed(() => nuxtApp.$i18n?.locale?.value ?? "en");
9
- const documents = computed(() => visibleDocuments(useRuntimeConfig().public.account?.documents ?? [], user.value?.role));
10
+ const documents = computed(() => visibleDocuments(useRuntimeConfig().public.account?.documents ?? [], authorization ? (permission) => authorization.can(permission) : void 0));
10
11
  </script>
11
12
 
12
13
  <template>
@@ -1,5 +1,8 @@
1
1
  import type { AccountDocument } from '../../../types.js';
2
2
  /** Label in `locale`, falling back to `en`, then the first available value. */
3
3
  export declare function documentLabel(document: AccountDocument, locale: string): string;
4
- /** The documents a user with `role` may see: everything without `roles`, otherwise only matching roles. */
5
- export declare function visibleDocuments(documents: AccountDocument[], role: string | undefined): AccountDocument[];
4
+ /**
5
+ * The documents the viewer may see: everything without a `permission`, otherwise only those `can` allows. Without a `can`
6
+ * (no access layer installed) a document with a permission is hidden.
7
+ */
8
+ export declare function visibleDocuments(documents: AccountDocument[], can?: (permission: string) => boolean): AccountDocument[];
@@ -2,6 +2,6 @@ export function documentLabel(document, locale) {
2
2
  if (typeof document.label === "string") return document.label;
3
3
  return document.label[locale] ?? document.label.en ?? Object.values(document.label)[0] ?? document.id;
4
4
  }
5
- export function visibleDocuments(documents, role) {
6
- return documents.filter((document) => !document.roles?.length || !!role && document.roles.includes(role));
5
+ export function visibleDocuments(documents, can) {
6
+ return documents.filter((document) => !document.permission || !!can?.(document.permission));
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/account",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "A module for managing the account area (profile, email, password, security) in the main frigear app.",
5
5
  "homepage": "https://docs.frigear.dev/modules/identity/account",
6
6
  "repository": {
@@ -24,10 +24,10 @@
24
24
  "playground"
25
25
  ],
26
26
  "dependencies": {
27
- "@frigear-nu/auth": "^0.4.0",
28
- "@frigear-nu/module-kit": "^1.3.4",
29
- "@frigear-nu/ui": "^0.2.5",
30
- "@frigear-nu/users": "^2.0.0",
27
+ "@frigear-nu/auth": "^0.6.0",
28
+ "@frigear-nu/module-kit": "^1.3.5",
29
+ "@frigear-nu/ui": "^0.2.6",
30
+ "@frigear-nu/users": "^3.1.0",
31
31
  "@libsql/client": "^0.18.0",
32
32
  "@nuxt/kit": "^4.6.4",
33
33
  "@vueuse/core": "^15.0.0",
@@ -36,9 +36,9 @@
36
36
  "zod": "^4.6.7"
37
37
  },
38
38
  "peerDependencies": {
39
- "@frigear-nu/authorization": "^0.4.0",
40
- "@frigear-nu/menu": "^0.2.4",
41
- "@frigear-nu/widget": "^0.2.4",
39
+ "@frigear-nu/authorization": "^0.6.0",
40
+ "@frigear-nu/menu": "^0.4.0",
41
+ "@frigear-nu/widget": "^0.4.0",
42
42
  "@nuxt/ui": "^4.12.0",
43
43
  "@nuxthub/core": "^0.10.12"
44
44
  },
@@ -57,9 +57,9 @@
57
57
  }
58
58
  },
59
59
  "devDependencies": {
60
- "@frigear-nu/authorization": "^0.4.0",
61
- "@frigear-nu/menu": "^0.2.4",
62
- "@frigear-nu/widget": "^0.2.4",
60
+ "@frigear-nu/authorization": "^0.6.0",
61
+ "@frigear-nu/menu": "^0.4.0",
62
+ "@frigear-nu/widget": "^0.4.0",
63
63
  "@nuxt/devtools": "^4.1.0",
64
64
  "@nuxt/eslint-config": "^1.17.0",
65
65
  "@nuxt/module-builder": "^1.0.3",