@frigear-nu/account 0.6.0 → 0.6.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.
package/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@frigear-nu/account",
3
3
  "configKey": "account",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "builder": {
6
- "@nuxt/module-builder": "1.0.3",
6
+ "@nuxt/module-builder": "1.0.4",
7
7
  "unbuild": "unknown"
8
8
  }
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineNuxtModule, createResolver, hasNuxtModule, addImports, addTypeTemplate, addRouteMiddleware, addPlugin, addComponentsDir } from '@nuxt/kit';
2
2
  import { registerModule, inlineModuleRuntime, registerTailwindSource, registerLocales, addOptionalImports, resolvePagePath, addModulePages, defineVirtualRegistry, getBootstrapProviders, addOptionalMenuSource } from '@frigear-nu/module-kit/utils';
3
+ import { localizedRoutePatterns, guardPages } from '@frigear-nu/auth/utils';
3
4
 
4
5
  function withAppMiddleware(existing, name) {
5
6
  const entries = typeof existing === "string" ? { [existing]: true } : Array.isArray(existing) ? Object.fromEntries(existing.map((middleware) => [middleware, true])) : existing;
@@ -91,9 +92,9 @@ const module$1 = defineNuxtModule({
91
92
  { name: "account-security", path: securityPath, file: "./runtime/app/pages/security.vue" },
92
93
  { name: "account-api-tokens", path: apiTokensPath, file: "./runtime/app/pages/api-tokens.vue" }
93
94
  ]);
94
- const prefixes = ["", ...(nuxt.options.i18n?.locales ?? []).map((locale) => typeof locale === "string" ? locale : locale.code).map((code) => `/${code}`)];
95
95
  const outside = [indexPath, profilePath, securityPath, documentsPath, apiTokensPath].filter((path) => !!path && path !== "/account" && !path.startsWith("/account/"));
96
- const areaPatterns = prefixes.flatMap((prefix) => [`${prefix}/account`, `${prefix}/account/**`, ...outside.map((path) => `${prefix}${path}`)]);
96
+ const areaBase = ["/account", "/account/**", ...outside];
97
+ const areaPatterns = localizedRoutePatterns(nuxt, areaBase);
97
98
  if (settings.layout !== false) {
98
99
  nuxt.hook("app:resolve", (app) => {
99
100
  app.layouts.account ||= { name: "account", file: resolver.resolve("./runtime/app/layouts/account.vue") };
@@ -104,10 +105,7 @@ const module$1 = defineNuxtModule({
104
105
  }
105
106
  }
106
107
  if (hasNuxtModule("@frigear-nu/authorization")) {
107
- const rules = nuxt.options.routeRules ||= {};
108
- for (const pattern of areaPatterns) {
109
- rules[pattern] = { authenticated: true, ...rules[pattern] };
110
- }
108
+ guardPages(nuxt, areaBase);
111
109
  } else {
112
110
  console.warn("[@frigear-nu/account] @frigear-nu/authorization is not installed: the account pages are not guarded. Install it and guard `/account/**` yourself.");
113
111
  }
@@ -3,6 +3,8 @@ export declare const useAccount: () => {
3
3
  updateProfileDetails: (payload: {
4
4
  name?: string;
5
5
  avatar?: string | null;
6
+ phone?: string | null;
7
+ locale?: string | null;
6
8
  }) => Promise<ProfileDto>;
7
9
  changeEmailAddress: (payload: {
8
10
  email: string;
@@ -19,39 +19,12 @@ useHead({ title: () => current.value?.label ?? t("title", "Account") }, { tagPri
19
19
 
20
20
  <template>
21
21
  <NuxtLayout :name="siteLayout">
22
- <UContainer>
23
- <div class="mx-auto w-full max-w-5xl py-8 lg:grid lg:grid-cols-[14rem_minmax(0,1fr)] lg:gap-10 lg:py-10">
24
- <aside class="hidden lg:block">
25
- <div class="sticky top-[calc(var(--ui-header-height,4rem)+2.5rem)] flex flex-col gap-4">
26
- <UUser
27
- v-if="user"
28
- :name="profile.name"
29
- :description="profile.email"
30
- :avatar="profile.avatar"
31
- size="sm"
32
- class="px-2.5"
33
- :ui="{ name: 'truncate', description: 'truncate' }"
34
- />
35
- <UNavigationMenu
36
- :items="links"
37
- orientation="vertical"
38
- highlight
39
- :aria-label="t('nav.label', 'Account navigation')"
40
- />
41
- </div>
42
- </aside>
43
-
44
- <!-- `self-start`: a stretched grid item has a definite height, which `h-full` cards inside a page would fill. -->
45
- <div class="flex min-w-0 flex-col gap-4 lg:self-start">
46
- <PageSectionSwitcher
47
- v-if="links.length"
48
- class="mb-2 lg:hidden"
49
- :items="links"
50
- :label="t('nav.label', 'Account navigation')"
51
- />
52
- <slot />
53
- </div>
54
- </div>
55
- </UContainer>
22
+ <AreaNavLayout
23
+ :links="links"
24
+ :user="user ? profile : void 0"
25
+ :label="t('nav.label', 'Account navigation')"
26
+ >
27
+ <slot />
28
+ </AreaNavLayout>
56
29
  </NuxtLayout>
57
30
  </template>
@@ -1,2 +1,2 @@
1
- declare const _default: import("#app").RouteMiddleware;
1
+ declare const _default: import("nuxt/app").RouteMiddleware;
2
2
  export default _default;
@@ -1,40 +1,58 @@
1
1
  <script setup>
2
2
  import { z } from "zod";
3
+ import { USER_PHONE_MAX_LENGTH, USER_PHONE_PATTERN } from "@frigear-nu/users/api";
3
4
  import AccountChangeEmailSlideover from "../components/Account/AccountChangeEmailSlideover.vue";
4
- import { computed, reactive, ref, useAccount, useAction, useModuleT, useOverlay, useRoute, useToast, useUserSession, watch } from "#imports";
5
+ import { PROFILE_NO_LOCALE as NO_LOCALE, profileChanges } from "../utils/profile";
6
+ import { computed, reactive, ref, useAccount, useAction, useModuleT, useNuxtApp, useOverlay, useRoute, useToast, useUserSession, watch } from "#imports";
5
7
  defineOptions({ name: "AccountProfilePage" });
6
8
  const t = useModuleT("account.profile");
7
9
  const toast = useToast();
8
10
  const route = useRoute();
9
11
  const { user } = useUserSession();
10
12
  const { updateProfileDetails } = useAccount();
13
+ const { $i18n } = useNuxtApp();
14
+ const localeItems = computed(() => {
15
+ const locales = ($i18n?.locales.value ?? []).map((locale) => typeof locale === "string" ? { value: locale, label: locale } : { value: locale.code, label: locale.name || locale.code });
16
+ return locales.length ? [{ value: NO_LOCALE, label: t("locale.none", "Not set") }, ...locales] : [];
17
+ });
11
18
  const schema = z.object({
12
19
  name: z.string().trim().min(1, t("name.required", "Please enter your name.")),
13
20
  // The server's rule: an http(s) URL of at most 2048 characters (empty clears the avatar).
14
21
  avatar: z.union([
15
22
  z.literal(""),
16
23
  z.url({ protocol: /^https?$/, message: t("avatar.invalid", "Enter a valid URL.") }).max(2048, t("avatar.invalid", "Enter a valid URL."))
17
- ]).optional()
24
+ ]).optional(),
25
+ // The server's rule, imported from `@frigear-nu/users`: digits, spaces and `+-().`; empty clears it.
26
+ phone: z.string().trim().max(USER_PHONE_MAX_LENGTH).regex(USER_PHONE_PATTERN, t("phone.invalid", "Enter a phone number of digits, spaces and + - ( ).")).optional()
18
27
  });
28
+ const sessionText = (key) => {
29
+ const value = user.value?.[key];
30
+ return typeof value === "string" ? value : "";
31
+ };
19
32
  const state = reactive({
20
33
  name: user.value?.name ?? "",
21
- avatar: user.value?.avatar ?? ""
34
+ avatar: user.value?.avatar ?? "",
35
+ phone: sessionText("phone"),
36
+ locale: sessionText("locale") || NO_LOCALE
22
37
  });
23
- const saved = computed(() => ({ name: user.value?.name ?? "", avatar: user.value?.avatar ?? "" }));
38
+ const saved = computed(() => ({ name: user.value?.name ?? "", avatar: user.value?.avatar ?? "", phone: sessionText("phone"), locale: sessionText("locale") || NO_LOCALE }));
24
39
  let lastSynced = { ...saved.value };
25
40
  watch(saved, (next) => {
26
- const pristine = state.name === lastSynced.name && state.avatar === lastSynced.avatar;
41
+ const pristine = state.name === lastSynced.name && state.avatar === lastSynced.avatar && state.phone === lastSynced.phone && state.locale === lastSynced.locale;
27
42
  lastSynced = { ...next };
28
43
  if (pristine) {
29
44
  state.name = next.name;
30
45
  state.avatar = next.avatar;
46
+ state.phone = next.phone;
47
+ state.locale = next.locale;
31
48
  }
32
49
  });
33
- const dirty = computed(() => state.name !== saved.value.name || state.avatar !== saved.value.avatar);
50
+ const dirty = computed(() => state.name !== saved.value.name || state.avatar !== saved.value.avatar || state.phone.trim() !== saved.value.phone || state.locale !== saved.value.locale);
34
51
  const profileAction = useAction();
35
52
  function onSubmitProfile(event) {
53
+ const body = profileChanges({ ...event.data, avatar: event.data.avatar ?? "", phone: event.data.phone ?? "", locale: state.locale }, saved.value, { localeChoice: localeItems.value.length > 0 });
36
54
  return profileAction.run(
37
- () => updateProfileDetails({ name: event.data.name, avatar: event.data.avatar || null }),
55
+ () => updateProfileDetails(body),
38
56
  { success: t("saved", "Profile updated"), error: t("saveFailed", "Could not update your profile.") }
39
57
  );
40
58
  }
@@ -80,8 +98,8 @@ async function onChangeEmail() {
80
98
  />
81
99
 
82
100
  <SectionCard
83
- :title="t('details.title', 'Name and avatar')"
84
- :description="t('details.description', 'How you appear to others.')"
101
+ :title="t('details.title', 'Your details')"
102
+ :description="t('details.description', 'How you appear to others and how we reach you.')"
85
103
  >
86
104
  <UForm
87
105
  id="account-profile"
@@ -123,6 +141,30 @@ async function onChangeEmail() {
123
141
  </template>
124
142
  </UInput>
125
143
  </FormRow>
144
+ <FormRow
145
+ name="phone"
146
+ :label="t('phone.label', 'Phone')"
147
+ :description="t('phone.description', 'For text messages. Only staff who need it can see it.')"
148
+ >
149
+ <UInput
150
+ v-model="state.phone"
151
+ type="tel"
152
+ autocomplete="tel"
153
+ class="w-full"
154
+ />
155
+ </FormRow>
156
+ <FormRow
157
+ v-if="localeItems.length"
158
+ name="locale"
159
+ :label="t('locale.label', 'Language')"
160
+ :description="t('locale.description', 'The language we write to you in: emails, texts and notifications.')"
161
+ >
162
+ <USelect
163
+ v-model="state.locale"
164
+ :items="localeItems"
165
+ class="w-full"
166
+ />
167
+ </FormRow>
126
168
  </UForm>
127
169
  <template #footer>
128
170
  <div class="flex justify-end gap-2">
@@ -1,2 +1,2 @@
1
- declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
@@ -0,0 +1,22 @@
1
+ /** The select value for "no language": Nuxt UI's select does not allow an empty value. */
2
+ export declare const PROFILE_NO_LOCALE = "-";
3
+ export interface ProfileFormValues {
4
+ name: string;
5
+ avatar: string;
6
+ phone: string;
7
+ /** A locale code, or {@link PROFILE_NO_LOCALE}. */
8
+ locale: string;
9
+ }
10
+ /**
11
+ * The body of `PATCH /api/users/me` for the profile form. The language is sent only when the app offers a choice
12
+ * (`localeChoice`, with i18n) and the user changed it: a stored language the app no longer offers (or one saved while it
13
+ * had no i18n) is refused by the server, so resending it untouched would block every other change.
14
+ */
15
+ export declare function profileChanges(values: ProfileFormValues, saved: Pick<ProfileFormValues, 'locale'>, options: {
16
+ localeChoice: boolean;
17
+ }): {
18
+ locale?: string | null | undefined;
19
+ name: string;
20
+ avatar: string | null;
21
+ phone: string | null;
22
+ };
@@ -0,0 +1,10 @@
1
+ export const PROFILE_NO_LOCALE = "-";
2
+ export function profileChanges(values, saved, options) {
3
+ const localeChanged = options.localeChoice && values.locale !== saved.locale;
4
+ return {
5
+ name: values.name,
6
+ avatar: values.avatar || null,
7
+ phone: values.phone || null,
8
+ ...localeChanged ? { locale: values.locale === PROFILE_NO_LOCALE ? null : values.locale } : {}
9
+ };
10
+ }
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "profile": {
46
46
  "details": {
47
- "title": "Navn og avatar",
48
- "description": "Sådan ser andre dig."
47
+ "title": "Dine oplysninger",
48
+ "description": "Sådan ser andre dig, og sådan når vi dig."
49
49
  },
50
50
  "name": {
51
51
  "label": "Navn",
@@ -78,7 +78,17 @@
78
78
  },
79
79
  "save": "Gem profil",
80
80
  "saved": "Profil opdateret",
81
- "saveFailed": "Kunne ikke opdatere din profil."
81
+ "saveFailed": "Kunne ikke opdatere din profil.",
82
+ "phone": {
83
+ "label": "Telefon",
84
+ "description": "Til sms'er. Kun personale, der har brug for det, kan se det.",
85
+ "invalid": "Angiv et telefonnummer med cifre, mellemrum og + - ( )."
86
+ },
87
+ "locale": {
88
+ "label": "Sprog",
89
+ "description": "Det sprog, vi skriver til dig på: e-mails, sms'er og notifikationer.",
90
+ "none": "Ikke valgt"
91
+ }
82
92
  },
83
93
  "documents": {
84
94
  "title": "Dokumenter",
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "profile": {
46
46
  "details": {
47
- "title": "Name and avatar",
48
- "description": "How you appear to others."
47
+ "title": "Your details",
48
+ "description": "How you appear to others and how we reach you."
49
49
  },
50
50
  "name": {
51
51
  "label": "Name",
@@ -78,7 +78,17 @@
78
78
  },
79
79
  "save": "Save profile",
80
80
  "saved": "Profile updated",
81
- "saveFailed": "Could not update your profile."
81
+ "saveFailed": "Could not update your profile.",
82
+ "phone": {
83
+ "label": "Phone",
84
+ "description": "For text messages. Only staff who need it can see it.",
85
+ "invalid": "Enter a phone number of digits, spaces and + - ( )."
86
+ },
87
+ "locale": {
88
+ "label": "Language",
89
+ "description": "The language we write to you in: emails, texts and notifications.",
90
+ "none": "Not set"
91
+ }
82
92
  },
83
93
  "documents": {
84
94
  "title": "Documents",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/account",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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.6.0",
28
- "@frigear-nu/module-kit": "^1.3.5",
29
- "@frigear-nu/ui": "^0.2.6",
30
- "@frigear-nu/users": "^3.1.0",
27
+ "@frigear-nu/auth": "^0.6.4",
28
+ "@frigear-nu/module-kit": "^1.3.8",
29
+ "@frigear-nu/ui": "^0.2.8",
30
+ "@frigear-nu/users": "^3.1.2",
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.6.0",
39
+ "@frigear-nu/authorization": "^0.6.2",
40
40
  "@frigear-nu/menu": "^0.4.0",
41
- "@frigear-nu/widget": "^0.4.0",
41
+ "@frigear-nu/widget": "^0.4.1",
42
42
  "@nuxt/ui": "^4.12.0",
43
43
  "@nuxthub/core": "^0.10.12"
44
44
  },
@@ -57,19 +57,19 @@
57
57
  }
58
58
  },
59
59
  "devDependencies": {
60
- "@frigear-nu/authorization": "^0.6.0",
60
+ "@frigear-nu/authorization": "^0.6.2",
61
61
  "@frigear-nu/menu": "^0.4.0",
62
- "@frigear-nu/widget": "^0.4.0",
63
- "@nuxt/devtools": "^4.1.0",
62
+ "@frigear-nu/widget": "^0.4.1",
63
+ "@nuxt/devtools": "^4.2.0",
64
64
  "@nuxt/eslint-config": "^1.17.0",
65
- "@nuxt/module-builder": "^1.0.3",
65
+ "@nuxt/module-builder": "^1.0.4",
66
66
  "@nuxt/schema": "^4.6.4",
67
- "@nuxt/test-utils": "^4.3.4",
67
+ "@nuxt/test-utils": "^4.4.0",
68
68
  "@nuxt/ui": "^4.12.0",
69
69
  "@nuxthub/core": "^0.10.12",
70
70
  "@types/node": "^26.6.6",
71
71
  "changelogen": "^0.6.2",
72
- "eslint": "^10.14.0",
72
+ "eslint": "^10.15.0",
73
73
  "nuxt": "^4.6.4",
74
74
  "typescript": "^6.0.3",
75
75
  "vitest": "^5.1.0",