@frigear-nu/account 0.3.0 → 0.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/dist/module.d.mts CHANGED
@@ -9,10 +9,11 @@ type AccountDocument = {
9
9
  path: string;
10
10
  icon?: string;
11
11
  /**
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.
12
+ * The permission (`resource:action`) a user must hold to see the document listed. Omit to show it to every
13
+ * signed-in user. Needs `@frigear-nu/authorization`; without it a document with a permission is never listed. This only
14
+ * decides what is *listed*: a file in `public/` can still be fetched by anyone who knows its URL.
14
15
  */
15
- roles?: string[];
16
+ permission?: string;
16
17
  };
17
18
  type PublicModuleOptions = {
18
19
  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.3.0",
4
+ "version": "0.5.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" }] : [],
@@ -17,7 +17,7 @@ const sessions = computed(() => data.value ?? []);
17
17
  async function signOut(session) {
18
18
  const confirmed = await confirm({
19
19
  title: t("signOutConfirm.title", "Sign out of {name}?", { name: session.application.name }),
20
- description: t("signOutConfirm.description", "The application has to ask you to sign in again. Your account and its data are not affected."),
20
+ description: t("signOutConfirm.description", "{name} is signed out on every device and has to ask you to sign in again. Your account and its data are not affected.", { name: session.application.name }),
21
21
  confirmText: t("signOut", "Sign out of app"),
22
22
  destructive: true
23
23
  });
@@ -46,6 +46,10 @@ async function signOutAll() {
46
46
  showError(e, t("signOutAllError", "Could not sign out of the applications."));
47
47
  }
48
48
  }
49
+ function activity(session) {
50
+ const params = { signedIn: format.date(session.signedInAt), lastActive: format.dateTime(session.lastActiveAt), count: session.sessions };
51
+ return session.sessions > 1 ? t("activityMany", "Signed in {signedIn} \xB7 last active {lastActive} \xB7 {count} active sign-ins", params) : t("activity", "Signed in {signedIn} \xB7 last active {lastActive}", params);
52
+ }
49
53
  const menu = (session) => [[
50
54
  { label: t("signOut", "Sign out of app"), icon: "i-lucide-log-out", color: "error", onSelect: () => signOut(session) }
51
55
  ]];
@@ -54,7 +58,7 @@ const menu = (session) => [[
54
58
  <template>
55
59
  <SectionCard
56
60
  :title="t('title', 'Signed-in apps')"
57
- :description="t('description', 'Applications that signed in with your account. Changing your password or email signs them all out.')"
61
+ :description="t('description', 'Apps you signed in to with your account. Signing out of an app ends its access on every device. Changing your password or email signs them all out.')"
58
62
  :loading="loading"
59
63
  flush
60
64
  >
@@ -88,7 +92,7 @@ const menu = (session) => [[
88
92
  {{ session.application.name }}
89
93
  </p>
90
94
  <p class="text-sm text-muted">
91
- {{ t("activity", "Signed in {signedIn} \xB7 last active {lastActive}", { signedIn: format.date(session.signedInAt), lastActive: format.dateTime(session.lastActiveAt) }) }}
95
+ {{ activity(session) }}
92
96
  </p>
93
97
  </div>
94
98
  <RowMenu
@@ -1,7 +1,9 @@
1
- declare var __VLS_29: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_29) => any;
1
+ declare const __VLS_template: () => {
2
+ __VLS_Slots: {
3
+ default?: (props: {}) => any;
4
+ };
4
5
  };
6
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
5
7
  declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
8
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
9
  declare const _default: typeof __VLS_export;
@@ -1,7 +1,9 @@
1
- declare var __VLS_29: {};
2
- type __VLS_Slots = {} & {
3
- default?: (props: typeof __VLS_29) => any;
1
+ declare const __VLS_template: () => {
2
+ __VLS_Slots: {
3
+ default?: (props: {}) => any;
4
+ };
4
5
  };
6
+ type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
5
7
  declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
8
  declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
7
9
  declare const _default: typeof __VLS_export;
@@ -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
  }
@@ -138,12 +138,13 @@
138
138
  },
139
139
  "signedInApps": {
140
140
  "title": "Apps, der er logget ind",
141
- "description": "Applikationer, der er logget ind med din konto. Når du ændrer adgangskode eller e-mail, logges de alle ud.",
141
+ "description": "Apps, du er logget ind i med din konto. Når du logger ud af en app, mister den adgangen på alle enheder. Når du ændrer adgangskode eller e-mail, logges de alle ud.",
142
142
  "activity": "Logget ind {signedIn} · sidst aktiv {lastActive}",
143
+ "activityMany": "Logget ind {signedIn} · sidst aktiv {lastActive} · {count} aktive logins",
143
144
  "signOut": "Log ud af app",
144
145
  "signOutConfirm": {
145
146
  "title": "Log ud af {name}?",
146
- "description": "Applikationen skal bede dig logge ind igen. Din konto og dens data påvirkes ikke."
147
+ "description": "{name} logges ud på alle enheder og skal bede dig logge ind igen. Din konto og dens data påvirkes ikke."
147
148
  },
148
149
  "signedOut": "Logget ud.",
149
150
  "signOutError": "Kunne ikke logge ud af applikationen.",
@@ -138,12 +138,13 @@
138
138
  },
139
139
  "signedInApps": {
140
140
  "title": "Signed-in apps",
141
- "description": "Applications that signed in with your account. Changing your password or email signs them all out.",
141
+ "description": "Apps you signed in to with your account. Signing out of an app ends its access on every device. Changing your password or email signs them all out.",
142
142
  "activity": "Signed in {signedIn} · last active {lastActive}",
143
+ "activityMany": "Signed in {signedIn} · last active {lastActive} · {count} active sign-ins",
143
144
  "signOut": "Sign out of app",
144
145
  "signOutConfirm": {
145
146
  "title": "Sign out of {name}?",
146
- "description": "The application has to ask you to sign in again. Your account and its data are not affected."
147
+ "description": "{name} is signed out on every device and has to ask you to sign in again. Your account and its data are not affected."
147
148
  },
148
149
  "signedOut": "Signed out.",
149
150
  "signOutError": "Could not sign out of the application.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/account",
3
- "version": "0.3.0",
3
+ "version": "0.5.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,23 +24,23 @@
24
24
  "playground"
25
25
  ],
26
26
  "dependencies": {
27
- "@frigear-nu/module-kit": "^1.3.4",
28
- "@frigear-nu/auth": "^0.3.4",
29
- "@frigear-nu/ui": "^0.2.5",
30
- "@frigear-nu/users": "^1.3.0",
27
+ "@frigear-nu/auth": "^0.5.0",
28
+ "@frigear-nu/module-kit": "^1.3.5",
29
+ "@frigear-nu/ui": "^0.2.6",
30
+ "@frigear-nu/users": "^3.0.0",
31
31
  "@libsql/client": "^0.18.0",
32
- "@nuxt/kit": "^4.6.1",
32
+ "@nuxt/kit": "^4.6.4",
33
33
  "@vueuse/core": "^15.0.0",
34
34
  "drizzle-kit": "^0.31.11",
35
- "drizzle-orm": "^0.45.3",
36
- "zod": "^4.6.5"
35
+ "drizzle-orm": "^0.45.4",
36
+ "zod": "^4.6.7"
37
37
  },
38
38
  "peerDependencies": {
39
- "@frigear-nu/authorization": "^0.3.2",
40
- "@frigear-nu/menu": "^0.2.4",
41
- "@frigear-nu/widget": "^0.2.4",
39
+ "@frigear-nu/authorization": "^0.5.0",
40
+ "@frigear-nu/menu": "^0.3.0",
41
+ "@frigear-nu/widget": "^0.3.0",
42
42
  "@nuxt/ui": "^4.12.0",
43
- "@nuxthub/core": "^0.10.8"
43
+ "@nuxthub/core": "^0.10.12"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "@frigear-nu/authorization": {
@@ -57,23 +57,23 @@
57
57
  }
58
58
  },
59
59
  "devDependencies": {
60
- "@frigear-nu/authorization": "^0.3.2",
61
- "@frigear-nu/menu": "^0.2.4",
62
- "@frigear-nu/widget": "^0.2.4",
63
- "@nuxt/devtools": "^3.4.2",
60
+ "@frigear-nu/authorization": "^0.5.0",
61
+ "@frigear-nu/menu": "^0.3.0",
62
+ "@frigear-nu/widget": "^0.3.0",
63
+ "@nuxt/devtools": "^4.1.0",
64
64
  "@nuxt/eslint-config": "^1.17.0",
65
65
  "@nuxt/module-builder": "^1.0.3",
66
- "@nuxt/schema": "^4.6.1",
67
- "@nuxt/test-utils": "^4.3.2",
66
+ "@nuxt/schema": "^4.6.4",
67
+ "@nuxt/test-utils": "^4.3.4",
68
68
  "@nuxt/ui": "^4.12.0",
69
- "@nuxthub/core": "^0.10.8",
70
- "@types/node": "^26.6.5",
69
+ "@nuxthub/core": "^0.10.12",
70
+ "@types/node": "^26.6.6",
71
71
  "changelogen": "^0.6.2",
72
- "eslint": "^10.12.0",
73
- "nuxt": "^4.6.1",
72
+ "eslint": "^10.14.0",
73
+ "nuxt": "^4.6.4",
74
74
  "typescript": "^6.0.3",
75
- "vitest": "^5.0.2",
76
- "vue-tsc": "^3.3.11"
75
+ "vitest": "^5.1.0",
76
+ "vue-tsc": "^3.3.14"
77
77
  },
78
78
  "scripts": {
79
79
  "dev:stub": "nuxt-module-build build --stub && nuxt prepare",