@frigear-nu/users 3.1.5 → 3.1.6

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.
Files changed (87) hide show
  1. package/dist/module.d.mts +103 -3
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +132 -16
  4. package/dist/runtime/access.js +3 -3
  5. package/dist/runtime/app/components/UserCreateSlideover.vue +8 -6
  6. package/dist/runtime/app/components/UserPicker.d.vue.ts +2 -2
  7. package/dist/runtime/app/components/UserPicker.vue.d.ts +2 -2
  8. package/dist/runtime/app/components/UsersAdminTerms.d.vue.ts +7 -0
  9. package/dist/runtime/app/components/UsersAdminTerms.vue +55 -0
  10. package/dist/runtime/app/components/UsersAdminTerms.vue.d.ts +7 -0
  11. package/dist/runtime/app/components/UsersTermsGate.d.vue.ts +11 -0
  12. package/dist/runtime/app/components/UsersTermsGate.vue +82 -0
  13. package/dist/runtime/app/components/UsersTermsGate.vue.d.ts +11 -0
  14. package/dist/runtime/app/components/UsersTermsText.d.vue.ts +7 -0
  15. package/dist/runtime/app/components/UsersTermsText.vue +34 -0
  16. package/dist/runtime/app/components/UsersTermsText.vue.d.ts +7 -0
  17. package/dist/runtime/app/composables/useUserActions.d.ts +6 -2
  18. package/dist/runtime/app/composables/useUserActions.js +32 -3
  19. package/dist/runtime/app/pages/admin-user.vue +3 -0
  20. package/dist/runtime/app/pages/admin.vue +2 -1
  21. package/dist/runtime/app/pages/revert-email-change.vue +2 -1
  22. package/dist/runtime/app/plugins/terms-gate.client.d.ts +2 -0
  23. package/dist/runtime/app/plugins/terms-gate.client.js +55 -0
  24. package/dist/runtime/app/tabs/Overview.vue +22 -12
  25. package/dist/runtime/app/utils/admin-user.d.ts +4 -2
  26. package/dist/runtime/app/utils/terms.d.ts +10 -0
  27. package/dist/runtime/app/utils/terms.js +7 -0
  28. package/dist/runtime/app/widgets/NewUsers.d.vue.ts +4 -1
  29. package/dist/runtime/app/widgets/NewUsers.vue +7 -4
  30. package/dist/runtime/app/widgets/NewUsers.vue.d.ts +4 -1
  31. package/dist/runtime/app/widgets/NewUsersStat.d.vue.ts +4 -1
  32. package/dist/runtime/app/widgets/NewUsersStat.vue +4 -1
  33. package/dist/runtime/app/widgets/NewUsersStat.vue.d.ts +4 -1
  34. package/dist/runtime/app/widgets/UsersAccountTerms.d.vue.ts +6 -0
  35. package/dist/runtime/app/widgets/UsersAccountTerms.vue +63 -0
  36. package/dist/runtime/app/widgets/UsersAccountTerms.vue.d.ts +6 -0
  37. package/dist/runtime/app/widgets/UsersRegisterTerms.d.vue.ts +9 -0
  38. package/dist/runtime/app/widgets/UsersRegisterTerms.vue +37 -0
  39. package/dist/runtime/app/widgets/UsersRegisterTerms.vue.d.ts +9 -0
  40. package/dist/runtime/db/terms-users.postgresql.d.ts +24 -0
  41. package/dist/runtime/db/terms-users.postgresql.js +4 -0
  42. package/dist/runtime/db/terms-users.sqlite.d.ts +26 -0
  43. package/dist/runtime/db/terms-users.sqlite.js +4 -0
  44. package/dist/runtime/db/terms.postgresql.d.ts +162 -0
  45. package/dist/runtime/db/terms.postgresql.js +21 -0
  46. package/dist/runtime/db/terms.sqlite.d.ts +173 -0
  47. package/dist/runtime/db/terms.sqlite.js +21 -0
  48. package/dist/runtime/i18n/lang/da.json +62 -3
  49. package/dist/runtime/i18n/lang/en.json +62 -3
  50. package/dist/runtime/server/plugins/terms-claims.d.ts +13 -0
  51. package/dist/runtime/server/plugins/terms-claims.js +19 -0
  52. package/dist/runtime/server/plugins/terms.d.ts +15 -0
  53. package/dist/runtime/server/plugins/terms.js +43 -0
  54. package/dist/runtime/server/routes/admin/user-avatar.delete.d.ts +2 -0
  55. package/dist/runtime/server/routes/admin/user-avatar.delete.js +11 -0
  56. package/dist/runtime/server/routes/admin/user-terms.get.d.ts +2 -0
  57. package/dist/runtime/server/routes/admin/user-terms.get.js +12 -0
  58. package/dist/runtime/server/routes/admin/user.delete.js +2 -0
  59. package/dist/runtime/server/routes/admin/user.patch.js +2 -2
  60. package/dist/runtime/server/routes/admin/users.get.js +1 -2
  61. package/dist/runtime/server/routes/avatar.get.d.ts +2 -0
  62. package/dist/runtime/server/routes/avatar.get.js +12 -0
  63. package/dist/runtime/server/routes/me/avatar.delete.d.ts +2 -0
  64. package/dist/runtime/server/routes/me/avatar.delete.js +13 -0
  65. package/dist/runtime/server/routes/me/avatar.put.d.ts +2 -0
  66. package/dist/runtime/server/routes/me/avatar.put.js +20 -0
  67. package/dist/runtime/server/routes/me/profile.patch.js +7 -2
  68. package/dist/runtime/server/routes/me/terms.get.d.ts +2 -0
  69. package/dist/runtime/server/routes/me/terms.get.js +4 -0
  70. package/dist/runtime/server/routes/me/terms.post.d.ts +2 -0
  71. package/dist/runtime/server/routes/me/terms.post.js +18 -0
  72. package/dist/runtime/server/schemas.d.ts +5 -1
  73. package/dist/runtime/server/schemas.js +2 -1
  74. package/dist/runtime/server/utils/dto.d.ts +1 -1
  75. package/dist/runtime/server/utils/dto.js +2 -1
  76. package/dist/runtime/server/utils/users-avatar.d.ts +29 -0
  77. package/dist/runtime/server/utils/users-avatar.js +69 -0
  78. package/dist/runtime/server/utils/users-terms.d.ts +35 -0
  79. package/dist/runtime/server/utils/users-terms.js +90 -0
  80. package/dist/runtime/utils/api.d.ts +21 -2
  81. package/dist/runtime/utils/api.js +20 -1
  82. package/dist/runtime/utils/avatar.d.ts +25 -0
  83. package/dist/runtime/utils/avatar.js +23 -0
  84. package/dist/runtime/utils/terms-claim.d.ts +27 -0
  85. package/dist/runtime/utils/terms-claim.js +15 -0
  86. package/dist/types.d.mts +1 -1
  87. package/package.json +18 -13
package/dist/module.d.mts CHANGED
@@ -1,5 +1,14 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { H3Event } from 'h3';
2
3
 
4
+ /**
5
+ * Context of `users:deleted`: a staff member deleted the user (`DELETE /api/admin/users/:id`). Modules that keep rows
6
+ * about a user without a foreign key (wristbands, ...) remove them here. `event` is the request.
7
+ */
8
+ type UserDeletedContext = {
9
+ event: H3Event;
10
+ userId: number;
11
+ };
3
12
  type PublicModuleOptions = {
4
13
  /** Where the page of the signed-in user's profile lives; the email change confirmation link lands there. */
5
14
  profilePath?: string;
@@ -8,8 +17,49 @@ type PublicModuleOptions = {
8
17
  pages: {
9
18
  admin?: string;
10
19
  };
20
+ /** The terms people accept (`users.terms`), or `undefined` when the host does not track them. */
21
+ terms?: UsersPublicTerms;
22
+ /** Whether users may upload a photo as their avatar (`avatarUpload`): the account page then offers it. */
23
+ avatarUpload: boolean;
24
+ /** The largest avatar upload in bytes (`maxAvatarBytes`). */
25
+ maxAvatarBytes: number;
26
+ };
27
+ /** The current terms, as the app sees them (`runtimeConfig.public.users.terms`). */
28
+ type UsersPublicTerms = {
29
+ /** The front matter `version` of the terms files. */
30
+ version: string;
31
+ /** Where the terms are read (a path of the site, localised by the app). */
32
+ url: string;
33
+ /** Where the privacy policy is read: linked next to the terms, not accepted. */
34
+ privacyUrl?: string;
35
+ };
36
+ /**
37
+ * Where an acceptance was given: the registration form, the prompt a signed-in user gets for new terms, or another app
38
+ * with the same terms, handed over at a frigear.nu login (the `terms` claim).
39
+ */
40
+ type UsersTermsSource = 'sign-up' | 'prompt' | 'oauth';
41
+ /** The server's terms config (`runtimeConfig.users.terms`): the public part plus the hash of every locale's file. */
42
+ type UsersTermsRuntimeConfig = UsersPublicTerms & {
43
+ /** SHA-256 (hex) of each locale's terms file, in the order of `users.terms.files` (the first is the fallback). */
44
+ hashes: Record<string, string>;
45
+ };
46
+ /** Context of `users:terms:accepted`: a user accepted the current terms (a history row was written). */
47
+ type UsersTermsAcceptedContext = {
48
+ userId: number;
49
+ version: string;
50
+ /** Epoch milliseconds. */
51
+ acceptedAt: number;
52
+ source: UsersTermsSource;
11
53
  };
12
54
  type ModuleOptions = {
55
+ /**
56
+ * Users may upload a photo as their avatar (`PUT /api/users/me/avatar`). It is stored in NuxtHub Blob (the module
57
+ * turns `hub.blob` on) and served by the public `GET /api/users/avatars/:userId/:file`; `users.avatar` holds its
58
+ * absolute URL. Needs a blob binding (R2 on Cloudflare). Defaults to `false`: avatars are URLs only.
59
+ */
60
+ avatarUpload?: boolean;
61
+ /** The largest avatar upload in bytes. Defaults to 2 MB. */
62
+ maxAvatarBytes?: number;
13
63
  settings?: {
14
64
  /**
15
65
  * User administration for staff: list/create/edit users (`/api/admin/users`), a "new users" widget and an
@@ -32,6 +82,21 @@ type ModuleOptions = {
32
82
  /** Expose the MCP tools of this module (`get-my-profile`) on the MCP endpoint. Needs `@frigear-nu/mcp`. Defaults to `false`. */
33
83
  mcp?: boolean;
34
84
  };
85
+ /**
86
+ * Terms people accept, with an append-only history of who accepted which version when (`user_terms_acceptances`) and
87
+ * the latest acceptance on the user (`acceptedTermsAt`, `acceptedTermsVersion`). Off unless set: no table, no
88
+ * registration checkbox, no prompt. The version is the front matter `version` of the files, read at build time with
89
+ * the SHA-256 of each file, so a stored hash proves which text was accepted. Signed-in users who have not accepted
90
+ * the current version are asked to before they go on.
91
+ */
92
+ terms?: {
93
+ /** The page of the terms (a path of the site, localised by the app). */
94
+ url: string;
95
+ /** The page of the privacy policy, linked next to the terms (read, not accepted). */
96
+ privacyUrl?: string;
97
+ /** The terms file of each locale, relative to the app's root (`{ en: 'content/en/legal/terms.md' }`). The first is the fallback. */
98
+ files: Record<string, string>;
99
+ };
35
100
  };
36
101
  /** A user as the users admin API returns it (`GET /api/admin/users/:id`, create and edit): an allowlist, never the row. */
37
102
  type AdminUserDto = {
@@ -43,8 +108,8 @@ type AdminUserDto = {
43
108
  avatar: string | null;
44
109
  /** Only in the detail and edit responses, and only for a caller with `users:pii`. */
45
110
  phone?: string | null;
46
- /** The person's id in an external system. Only in the detail and edit responses, and only with `users:pii`. */
47
- peopleNumber?: string | null;
111
+ /** The person's id in an external system (not personal data: every staff member who sees the user sees it). */
112
+ peopleNumber: string | null;
48
113
  /** The user asked not to be photographed as the main subject (crowd shots can still include them). */
49
114
  photoOptOut: boolean;
50
115
  /** The user asked not to be tagged in posts and photos online. */
@@ -72,7 +137,40 @@ type ProfileDto = {
72
137
  locale: string | null;
73
138
  emailVerifiedAt: string | null;
74
139
  };
140
+ /** The signed-in user's terms (`GET /api/users/me/terms`): the current version and what they accepted last. */
141
+ type UserTermsStatusDto = {
142
+ current: UsersPublicTerms;
143
+ /** The latest acceptance, or `null` when the user never accepted any terms. */
144
+ accepted: {
145
+ version: string;
146
+ acceptedAt: string;
147
+ } | null;
148
+ /** Whether the latest acceptance is of the current version. */
149
+ upToDate: boolean;
150
+ };
151
+ /** One acceptance of a user's history (`GET /api/admin/users/:id/terms`, `users:pii`), newest first. */
152
+ type UserTermsAcceptanceDto = {
153
+ id: number;
154
+ version: string;
155
+ /** The locale of the text accepted. */
156
+ locale: string;
157
+ /** SHA-256 (hex) of the terms file accepted. */
158
+ contentHash: string;
159
+ acceptedAt: string;
160
+ source: UsersTermsSource;
161
+ /** A keyed hash (HMAC-SHA-256, hex) of the request's IP address, never the address; `null` without an address or key. */
162
+ ipHash: string | null;
163
+ userAgent: string | null;
164
+ };
75
165
 
166
+ declare module 'nitropack' {
167
+ interface NitroRuntimeHooks {
168
+ /** A user was deleted (after their row is gone): remove what you keep about them. */
169
+ 'users:deleted': (ctx: UserDeletedContext) => void | Promise<void>;
170
+ /** A user accepted the current terms (`users.terms`), on the registration form or at the prompt; the history row is written. */
171
+ 'users:terms:accepted': (ctx: UsersTermsAcceptedContext) => void | Promise<void>;
172
+ }
173
+ }
76
174
  declare module 'nuxt/schema' {
77
175
  interface NuxtConfig {
78
176
  users?: ModuleOptions;
@@ -82,6 +180,8 @@ declare module 'nuxt/schema' {
82
180
  verifyEmailChange: boolean;
83
181
  /** The app's i18n locale codes (filled at `modules:done`): the languages `users.locale` accepts. Empty: any short BCP-47 tag. */
84
182
  locales: string[];
183
+ /** The terms (`users.terms`) with the hash of each locale's file, read at build time; `null` when off. */
184
+ terms: UsersTermsRuntimeConfig | null;
85
185
  };
86
186
  }
87
187
  interface PublicRuntimeConfig {
@@ -91,4 +191,4 @@ declare module 'nuxt/schema' {
91
191
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
92
192
 
93
193
  export { _default as default };
94
- export type { AdminUserDto, ModuleOptions, ProfileDto, PublicModuleOptions };
194
+ export type { AdminUserDto, ModuleOptions, ProfileDto, PublicModuleOptions, UserDeletedContext, UserTermsAcceptanceDto, UserTermsStatusDto, UsersPublicTerms, UsersTermsAcceptedContext, UsersTermsSource };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@frigear-nu/users",
3
3
  "configKey": "users",
4
- "version": "3.1.5",
4
+ "version": "3.1.6",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.4",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,9 +1,49 @@
1
- import { defineNuxtModule, createResolver, addComponent, addServerImportsDir, hasNuxtModule, addPlugin, addNitroPlugin } from '@nuxt/kit';
2
- import { registerTailwindSource, registerLocales, isClientOnlyApp, registerDatabaseTable, registerSearchIndex, inlineModuleRuntime, addModulePages, addModuleRoutes, resolvePagePath, addOptionalMenuSource, serverModuleDependencies } from '@frigear-nu/module-kit/utils';
3
- import { setAuthUserStore, registerAccess } from '@frigear-nu/auth/utils';
1
+ import { defineNuxtModule, createResolver, addComponent, addServerImportsDir, hasNuxtModule, addTypeTemplate, addNitroPlugin, addPlugin } from '@nuxt/kit';
2
+ import { registerTailwindSource, registerLocales, isClientOnlyApp, registerDatabaseTable, registerSearchIndex, inlineModuleRuntime, addModulePages, defineVirtualRegistry, extendDatabaseTable, addModuleRoutes, resolvePagePath, addOptionalMenuSource, serverModuleDependencies } from '@frigear-nu/module-kit/utils';
3
+ import { setAuthUserStore, AUTH_WIDGET_AREAS, registerAccess } from '@frigear-nu/auth/utils';
4
4
  import { resolveAuthMode } from '@frigear-nu/auth/mode';
5
5
  import { setNotifyRecipientStore } from '@frigear-nu/notify/utils';
6
6
  import { usersAccess, USERS_SELF_SERVICE } from '../dist/runtime/access.js';
7
+ import { USERS_MAX_AVATAR_BYTES } from '../dist/runtime/utils/avatar.js';
8
+ import { isAbsolute, resolve } from 'node:path';
9
+ import { createHash } from 'node:crypto';
10
+ import { readFileSync } from 'node:fs';
11
+
12
+ function readTermsFrontMatterVersion(source) {
13
+ const match = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(source);
14
+ if (!match) return null;
15
+ for (const line of match[1].split(/\r?\n/)) {
16
+ const field = /^version\s*:(.*)$/.exec(line);
17
+ if (!field) continue;
18
+ const value = field[1].trim().replace(/^(['"])(.*)\1$/, "$2").trim();
19
+ return value || null;
20
+ }
21
+ return null;
22
+ }
23
+ function hashTermsSource(bytes) {
24
+ return createHash("sha256").update(bytes).digest("hex");
25
+ }
26
+ function readTermsFiles(rootDir, files) {
27
+ const entries = Object.entries(files);
28
+ if (!entries.length) throw new Error("[@frigear-nu/users] `users.terms.files` names no file: add one per locale (`{ en: 'content/en/terms.md' }`).");
29
+ const locales = {};
30
+ for (const [locale, file] of entries) {
31
+ const path = isAbsolute(file) ? file : resolve(rootDir, file);
32
+ let bytes;
33
+ try {
34
+ bytes = readFileSync(path);
35
+ } catch {
36
+ throw new Error(`[@frigear-nu/users] The terms file of \`${locale}\` (\`${file}\`) could not be read.`);
37
+ }
38
+ const version2 = readTermsFrontMatterVersion(bytes.toString("utf8"));
39
+ if (!version2) throw new Error(`[@frigear-nu/users] The terms file of \`${locale}\` (\`${file}\`) has no \`version\` in its front matter.`);
40
+ locales[locale] = { version: version2, hash: hashTermsSource(bytes) };
41
+ }
42
+ const [first] = entries;
43
+ const version = locales[first[0]].version;
44
+ const warnings = Object.entries(locales).filter(([, value]) => value.version !== version).map(([locale, value]) => `[@frigear-nu/users] The terms of \`${locale}\` are version \`${value.version}\`, the terms of \`${first[0]}\` \`${version}\`: \`${version}\` is the current version.`);
45
+ return { version, locales, warnings };
46
+ }
7
47
 
8
48
  const module$1 = defineNuxtModule({
9
49
  meta: { name: "@frigear-nu/users", configKey: "users" },
@@ -12,7 +52,8 @@ const module$1 = defineNuxtModule({
12
52
  },
13
53
  // `@frigear-nu/mcp` is only installed when `settings.mcp` is on.
14
54
  moduleDependencies: (nuxt) => ({
15
- ...serverModuleDependencies(nuxt, { "@nuxthub/core": { version: ">=0.0.1" } }),
55
+ // Uploaded avatars are stored in NuxtHub Blob: it is turned on only with `avatarUpload`.
56
+ ...serverModuleDependencies(nuxt, { "@nuxthub/core": nuxt.options.users?.avatarUpload === true ? { version: ">=0.10", defaults: { blob: true } } : { version: ">=0.0.1" } }),
16
57
  "@frigear-nu/module-kit": {
17
58
  version: ">=0.0.1"
18
59
  },
@@ -94,12 +135,75 @@ const module$1 = defineNuxtModule({
94
135
  schema: (dialect) => `./runtime/db/email-changes.${dialect}`
95
136
  });
96
137
  }
97
- addModuleRoutes(resolver, selfRoutes, { base: "/api/users" });
138
+ const avatarUpload = options.avatarUpload === true;
139
+ if (avatarUpload) {
140
+ selfRoutes.push(
141
+ { method: "put", path: "me/avatar", file: "me/avatar.put" },
142
+ { method: "delete", path: "me/avatar", file: "me/avatar.delete" },
143
+ { method: "get", path: "avatars/:userId/:file", file: "avatar.get" }
144
+ );
145
+ }
146
+ defineVirtualRegistry(nuxt, {
147
+ filename: "#users/avatar-blob",
148
+ target: "server",
149
+ collect: () => avatarUpload && server,
150
+ contents: (enabled) => enabled ? `export { blob } from '@nuxthub/blob'
151
+ ` : "export const blob = null\n"
152
+ });
153
+ addTypeTemplate({
154
+ filename: "types/users-avatar-blob.d.ts",
155
+ getContents: () => `declare module '#users/avatar-blob' {
156
+ export const blob: {
157
+ put(pathname: string, body: Uint8Array, options?: { contentType?: string, prefix?: string, addRandomSuffix?: boolean }): Promise<{ pathname: string }>
158
+ get(pathname: string): Promise<Blob | null>
159
+ del(pathnames: string | string[]): Promise<void>
160
+ list(options?: { prefix?: string, cursor?: string }): Promise<{ blobs: { pathname: string }[], hasMore: boolean, cursor?: string }>
161
+ } | null
162
+ }
163
+ `
164
+ }, { nitro: true, nuxt: true });
98
165
  if (settings.mcp === true && server) {
99
166
  const { addMcpDefinitions } = await import('@frigear-nu/mcp/utils');
100
167
  addMcpDefinitions(nuxt, resolver.resolve("./runtime/server/mcp"));
101
168
  }
102
- nuxt.options.runtimeConfig.users = { verifyEmailChange: settings.verifyEmailChange === true, locales: [] };
169
+ let terms = null;
170
+ if (options.terms && (!server || !signInHere)) {
171
+ console.warn("[@frigear-nu/users] `users.terms` needs sessions on this server: it does nothing in a client-only app or with `authentication.mode: 'resource'`.");
172
+ } else if (options.terms) {
173
+ const files = readTermsFiles(nuxt.options.rootDir, options.terms.files);
174
+ for (const warning of files.warnings) console.warn(warning);
175
+ terms = {
176
+ version: files.version,
177
+ url: options.terms.url,
178
+ ...options.terms.privacyUrl ? { privacyUrl: options.terms.privacyUrl } : {},
179
+ hashes: Object.fromEntries(Object.entries(files.locales).map(([locale, file]) => [locale, file.hash]))
180
+ };
181
+ nuxt.options.watch.push(...Object.values(options.terms.files).map((file) => resolve(nuxt.options.rootDir, file)));
182
+ registerDatabaseTable(nuxt, { resolver, schema: (dialect) => `./runtime/db/terms.${dialect}` });
183
+ extendDatabaseTable(nuxt, { resolver, file: (dialect) => `./runtime/db/terms-users.${dialect}` });
184
+ selfRoutes.push(
185
+ { method: "get", path: "me/terms", file: "me/terms.get" },
186
+ { method: "post", path: "me/terms", file: "me/terms.post" }
187
+ );
188
+ addNitroPlugin(resolver.resolve("./runtime/server/plugins/terms"));
189
+ if (hasNuxtModule("@frigear-nu/oauth-server", nuxt)) {
190
+ addNitroPlugin(resolver.resolve("./runtime/server/plugins/terms-claims"));
191
+ }
192
+ nuxt.hook("modules:done", () => {
193
+ if (hasNuxtModule("@nuxt/ui", nuxt) && hasNuxtModule("@frigear-nu/ui", nuxt)) {
194
+ addPlugin({ src: resolver.resolve("./runtime/app/plugins/terms-gate.client"), mode: "client" });
195
+ } else {
196
+ console.warn("[@frigear-nu/users] `users.terms` is on, but `@nuxt/ui` or `@frigear-nu/ui` is not installed: there is no prompt for new terms, check `GET /api/users/me/terms` yourself.");
197
+ }
198
+ });
199
+ if (hasNuxtModule("@frigear-nu/widget")) {
200
+ const { extendWidgets } = await import('@frigear-nu/widget/utils');
201
+ extendWidgets(nuxt, AUTH_WIDGET_AREAS.register, { id: "users-register-terms", component: resolver.resolve("./runtime/app/widgets/UsersRegisterTerms.vue"), order: 90 });
202
+ extendWidgets(nuxt, "account.profile", { id: "users-account-terms", component: resolver.resolve("./runtime/app/widgets/UsersAccountTerms.vue"), order: 50 });
203
+ }
204
+ }
205
+ addModuleRoutes(resolver, selfRoutes, { base: "/api/users" });
206
+ nuxt.options.runtimeConfig.users = { verifyEmailChange: settings.verifyEmailChange === true, locales: [], terms };
103
207
  nuxt.hook("modules:done", () => {
104
208
  const locales = nuxt.options.i18n?.locales ?? [];
105
209
  nuxt.options.runtimeConfig.users.locales = locales.map((locale) => typeof locale === "string" ? locale : locale.code);
@@ -131,7 +235,10 @@ const module$1 = defineNuxtModule({
131
235
  { method: "get", path: ":id", file: "admin/user.get" },
132
236
  { method: "patch", path: ":id", file: "admin/user.patch" },
133
237
  { method: "delete", path: ":id", file: "admin/user.delete" },
134
- ...signInHere ? [{ method: "post", path: ":id/resend", file: "admin/user-resend.post" }] : []
238
+ { method: "delete", path: ":id/avatar", file: "admin/user-avatar.delete" },
239
+ ...signInHere ? [{ method: "post", path: ":id/resend", file: "admin/user-resend.post" }] : [],
240
+ // The terms history (`users:pii`), with `users.terms`.
241
+ ...terms ? [{ method: "get", path: ":id/terms", file: "admin/user-terms.get" }] : []
135
242
  ], { base: "/api/admin/users" });
136
243
  if (adminPagePath) {
137
244
  addModulePages("@frigear-nu/users", resolver, [
@@ -140,7 +247,7 @@ const module$1 = defineNuxtModule({
140
247
  ]);
141
248
  }
142
249
  if (withAdminShell && hasNuxtModule("@frigear-nu/widget")) {
143
- const { extendWidgets, extendTabs } = await import('@frigear-nu/widget/utils');
250
+ const { extendTabs } = await import('@frigear-nu/widget/utils');
144
251
  extendTabs(nuxt, "admin.users", {
145
252
  id: "overview",
146
253
  component: resolver.resolve("./runtime/app/tabs/Overview.vue"),
@@ -149,16 +256,22 @@ const module$1 = defineNuxtModule({
149
256
  labelKey: "users.admin.tabs.overview",
150
257
  icon: "i-lucide-user"
151
258
  });
152
- extendWidgets(nuxt, "admin.dashboard", {
259
+ const { extendAdminDashboard } = await import('@frigear-nu/admin/utils');
260
+ extendAdminDashboard(nuxt, {
261
+ id: "users-new-users-stat",
262
+ component: resolver.resolve("./runtime/app/widgets/NewUsersStat.vue"),
263
+ title: "New users",
264
+ titleKey: "users.admin.dashboard.newUsersStat",
265
+ order: 10,
266
+ size: { cols: 1, maxCols: 2 }
267
+ }, "top");
268
+ extendAdminDashboard(nuxt, {
153
269
  id: "users-new-users",
154
270
  component: resolver.resolve("./runtime/app/widgets/NewUsers.vue"),
271
+ title: "Latest sign-ups",
272
+ titleKey: "users.admin.dashboard.newUsers",
155
273
  order: 20,
156
- span: 2
157
- });
158
- extendWidgets(nuxt, "admin.dashboard.top", {
159
- id: "users-new-users-stat",
160
- component: resolver.resolve("./runtime/app/widgets/NewUsersStat.vue"),
161
- order: 10
274
+ size: { cols: 2, minCols: 1, maxCols: 4, rows: 2 }
162
275
  });
163
276
  }
164
277
  }
@@ -168,7 +281,10 @@ const module$1 = defineNuxtModule({
168
281
  nuxt.options.runtimeConfig.public.users = {
169
282
  profilePath: settings.profilePath,
170
283
  mcp: settings.mcp === true,
171
- pages: { admin: adminPagePath }
284
+ pages: { admin: adminPagePath },
285
+ ...terms ? { terms: { version: terms.version, url: terms.url, ...terms.privacyUrl ? { privacyUrl: terms.privacyUrl } : {} } } : {},
286
+ avatarUpload,
287
+ maxAvatarBytes: options.maxAvatarBytes ?? USERS_MAX_AVATAR_BYTES
172
288
  };
173
289
  }
174
290
  });
@@ -16,12 +16,12 @@ export const usersAccess = defineAccess("users", {
16
16
  // Granted to `admin` by name; give it to other staff roles in the host's `authorization.roles`. It covers an optional
17
17
  // phone number on the new user (changing it later is `users:pii`).
18
18
  "create": { label: "Add users", description: "Create users and email them an invite link.", grantTo: ["admin"] },
19
- "update": { label: "Edit users", description: "Change a user's name and nickname." },
19
+ "update": { label: "Edit users", description: "Change a user's name, nickname and people number." },
20
20
  "delete": { label: "Delete users", description: "Delete users and their sign-in methods.", sessionOnly: true },
21
21
  "manage": { label: "Manage sign-in of users", description: "Change or verify a user's email address and email them a sign-in link.", sessionOnly: true },
22
22
  // Sensitive (`:pii`): never covered by `users:*` or `*`, only granted by name. Other modules show the phone number
23
- // under their own `:pii` permission (`crew:pii`, `shifts:pii`). The people number (an id in an external system) too.
24
- "pii": { label: "See users' phone and people numbers", description: "See and change the phone number and people number of other users.", grantTo: ["admin"] }
23
+ // under their own `:pii` permission (`crew:pii`, `shifts:pii`).
24
+ "pii": { label: "See users' phone numbers", description: "See and change the phone number of other users.", grantTo: ["admin"] }
25
25
  }
26
26
  });
27
27
  export const USERS_SELF_SERVICE = ["profile:read", "profile:write"];
@@ -1,6 +1,7 @@
1
1
  <script setup>
2
2
  import { usersApi } from "../../utils/api";
3
3
  import { USER_PHONE_MAX_LENGTH, USER_PHONE_PATTERN } from "../../utils/phone";
4
+ import { phoneIssue } from "@frigear-nu/ui/phone";
4
5
  import { z } from "zod";
5
6
  import { $fetch, reactive, ref, useErrorToast, useModuleT, useNuxtApp, useToast } from "#imports";
6
7
  defineOptions({ name: "UsersUserCreateSlideover" });
@@ -18,7 +19,9 @@ const locale = useNuxtApp().$i18n?.locale?.value || void 0;
18
19
  const schema = z.object({
19
20
  name: z.string().trim().min(1, t("admin.nameRequired", "Enter a name.")).max(120),
20
21
  email: z.string().trim().email(t("admin.emailInvalid", "Enter a valid email address.")),
21
- phone: z.string().trim().max(USER_PHONE_MAX_LENGTH).regex(USER_PHONE_PATTERN, t("admin.phoneInvalid", "Enter a phone number of digits, spaces and + - ( ).")).or(z.literal("")),
22
+ // The server's rule and a full international number (`PhoneInput` writes `+4512345678`); a prefilled number passes
23
+ // as given, since the server accepts it.
24
+ phone: z.string().trim().max(USER_PHONE_MAX_LENGTH).regex(USER_PHONE_PATTERN, t("admin.phoneInvalid", "Enter a valid phone number.")).refine((value) => !value || value === (props.initial?.phone ?? "") || !phoneIssue(value), t("admin.phoneInvalid", "Enter a valid phone number.")),
22
25
  emailVerified: z.boolean(),
23
26
  sendWelcomeEmail: z.boolean()
24
27
  });
@@ -103,11 +106,10 @@ const chooseExisting = () => {
103
106
  :label="t('admin.phone', 'Phone')"
104
107
  :description="t('admin.createPhoneHelp', 'Optional. Used for text messages.')"
105
108
  >
106
- <UInput
107
- v-model="state.phone"
108
- type="tel"
109
- autocomplete="off"
110
- class="w-full"
109
+ <PhoneInput
110
+ :model-value="state.phone"
111
+ :country-label="t('admin.phoneCountry', 'Country')"
112
+ @update:model-value="state.phone = $event ?? ''"
111
113
  />
112
114
  </UFormField>
113
115
  <UCheckbox
@@ -32,12 +32,12 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {
32
32
  canCreate: import("vue").ComputedRef<boolean>;
33
33
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
34
34
  created: (user: UserPickerOption) => any;
35
- picked: (user: UserPickerOption) => any;
36
35
  "update:modelValue": (value: number | number[] | null | undefined) => any;
36
+ picked: (user: UserPickerOption) => any;
37
37
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
38
38
  onCreated?: ((user: UserPickerOption) => any) | undefined;
39
- onPicked?: ((user: UserPickerOption) => any) | undefined;
40
39
  "onUpdate:modelValue"?: ((value: number | number[] | null | undefined) => any) | undefined;
40
+ onPicked?: ((user: UserPickerOption) => any) | undefined;
41
41
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
42
42
  declare const _default: typeof __VLS_export;
43
43
  export default _default;
@@ -32,12 +32,12 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {
32
32
  canCreate: import("vue").ComputedRef<boolean>;
33
33
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
34
34
  created: (user: UserPickerOption) => any;
35
- picked: (user: UserPickerOption) => any;
36
35
  "update:modelValue": (value: number | number[] | null | undefined) => any;
36
+ picked: (user: UserPickerOption) => any;
37
37
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
38
38
  onCreated?: ((user: UserPickerOption) => any) | undefined;
39
- onPicked?: ((user: UserPickerOption) => any) | undefined;
40
39
  "onUpdate:modelValue"?: ((value: number | number[] | null | undefined) => any) | undefined;
40
+ onPicked?: ((user: UserPickerOption) => any) | undefined;
41
41
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
42
42
  declare const _default: typeof __VLS_export;
43
43
  export default _default;
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ userId: number;
3
+ currentVersion: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
@@ -0,0 +1,55 @@
1
+ <script setup>
2
+ import { computed } from "vue";
3
+ import { usersApi } from "../../utils/api";
4
+ import { tableUi, useFormat, useLazyFetch, useModuleT } from "#imports";
5
+ defineOptions({ name: "UsersAdminTerms" });
6
+ const props = defineProps({
7
+ userId: { type: Number, required: true },
8
+ currentVersion: { type: String, required: true }
9
+ });
10
+ const t = useModuleT("users");
11
+ const format = useFormat();
12
+ const { data, status, error } = useLazyFetch(() => usersApi.admin.terms(props.userId), {
13
+ key: `users:admin:terms:${props.userId}`,
14
+ default: () => []
15
+ });
16
+ const loading = computed(() => status.value === "pending" && !data.value?.length);
17
+ const latest = computed(() => data.value?.[0]);
18
+ const summary = computed(() => {
19
+ if (error.value) return t("admin.terms.loadFailed", "The terms history could not be loaded.");
20
+ if (!latest.value) return t("admin.terms.none", "Has not accepted any terms.");
21
+ const text = t("admin.terms.latest", "Version {version}, accepted {date}.", { version: latest.value.version, date: format.dateTime(latest.value.acceptedAt) });
22
+ return latest.value.version === props.currentVersion ? text : `${text} ${t("admin.terms.outdated", "Not the current version ({version}).", { version: props.currentVersion })}`;
23
+ });
24
+ const sourceLabel = (source) => source === "sign-up" ? t("admin.terms.sources.signUp", "Sign-up") : source === "oauth" ? t("admin.terms.sources.oauth", "Another app (login)") : t("admin.terms.sources.prompt", "Signed in");
25
+ const columns = computed(() => [
26
+ { accessorKey: "version", header: t("admin.terms.version", "Version") },
27
+ { accessorKey: "acceptedAt", header: t("admin.terms.acceptedAt", "Accepted"), cell: ({ row }) => format.dateTime(row.original.acceptedAt) },
28
+ { accessorKey: "source", header: t("admin.terms.source", "Where"), cell: ({ row }) => sourceLabel(row.original.source) },
29
+ { accessorKey: "locale", header: t("admin.terms.locale", "Language") },
30
+ { accessorKey: "contentHash", header: t("admin.terms.hash", "Text hash"), cell: ({ row }) => row.original.contentHash.slice(0, 12) }
31
+ ]);
32
+ </script>
33
+
34
+ <template>
35
+ <TableCard
36
+ :title="t('admin.terms.title', 'Terms')"
37
+ :description="summary"
38
+ :loading="loading"
39
+ >
40
+ <UTable
41
+ :data="data ?? []"
42
+ :columns="columns"
43
+ :ui="tableUi({ tr: '' })"
44
+ >
45
+ <template #empty>
46
+ <UEmpty
47
+ icon="i-lucide-scroll-text"
48
+ variant="naked"
49
+ :title="t('admin.terms.empty', 'No acceptances yet')"
50
+ :description="t('admin.terms.emptyHint', 'The user is asked to accept the terms when they next sign in.')"
51
+ />
52
+ </template>
53
+ </UTable>
54
+ </TableCard>
55
+ </template>
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ userId: number;
3
+ currentVersion: string;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import type { UserTermsStatusDto } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ status: UserTermsStatusDto;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ close: (args_0: UserTermsStatusDto | null) => any;
7
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
8
+ onClose?: ((args_0: UserTermsStatusDto | null) => any) | undefined;
9
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;
@@ -0,0 +1,82 @@
1
+ <script setup>
2
+ import { usersApi } from "../../utils/api";
3
+ import UsersTermsText from "./UsersTermsText.vue";
4
+ import { $fetch, reloadNuxtApp, useAction, useAuth, useFormat, useLocaleLink, useModuleT, useNuxtApp } from "#imports";
5
+ defineOptions({ name: "UsersTermsGate" });
6
+ const props = defineProps({
7
+ status: { type: Object, required: true }
8
+ });
9
+ const emit = defineEmits(["close"]);
10
+ const t = useModuleT("users");
11
+ const format = useFormat();
12
+ const { localize } = useLocaleLink();
13
+ const { busy, run } = useAction();
14
+ const signingOut = useAction();
15
+ const i18n = useNuxtApp().$i18n;
16
+ async function accept() {
17
+ const status = await run(async () => {
18
+ try {
19
+ return await $fetch(usersApi.me.terms, {
20
+ method: "POST",
21
+ body: { version: props.status.current.version, ...i18n?.locale?.value ? { locale: i18n.locale.value } : {} }
22
+ });
23
+ } catch (error) {
24
+ if (error.data?.data?.code === "outdated_version") reloadNuxtApp();
25
+ throw error;
26
+ }
27
+ }, { success: t("terms.gate.accepted", "Terms accepted"), error: t("terms.gate.acceptFailed", "The terms could not be accepted.") });
28
+ if (status) emit("close", status);
29
+ }
30
+ function signOut() {
31
+ return signingOut.run(() => useAuth().logout(), { error: t("terms.gate.signOutFailed", "You could not be signed out.") });
32
+ }
33
+ </script>
34
+
35
+ <template>
36
+ <UModal
37
+ :title="status.accepted ? t('terms.gate.changedTitle', 'Our terms have changed') : t('terms.gate.title', 'Accept our terms')"
38
+ :description="status.accepted ? t('terms.gate.changedDescription', 'You accepted version {version} on {date}. Read and accept the new terms to go on.', { version: status.accepted.version, date: format.date(status.accepted.acceptedAt) }) : t('terms.gate.description', 'Read and accept the terms to go on using your account.')"
39
+ :dismissible="false"
40
+ :close="false"
41
+ >
42
+ <template #body>
43
+ <div
44
+ class="flex flex-col gap-3 text-sm"
45
+ data-users-terms-gate
46
+ >
47
+ <p class="text-highlighted">
48
+ <UsersTermsText :terms="status.current" />
49
+ </p>
50
+ <p class="text-muted">
51
+ {{ t("terms.gate.version", "Version {version}", { version: status.current.version }) }}
52
+ </p>
53
+ </div>
54
+ </template>
55
+ <template #footer>
56
+ <div class="flex w-full flex-wrap justify-end gap-2">
57
+ <UButton
58
+ color="neutral"
59
+ variant="outline"
60
+ icon="i-lucide-scroll-text"
61
+ :to="localize(status.current.url)"
62
+ target="_blank"
63
+ :label="t('terms.gate.read', 'Read the terms')"
64
+ />
65
+ <UButton
66
+ color="neutral"
67
+ variant="ghost"
68
+ icon="i-lucide-log-out"
69
+ :loading="signingOut.busy.value"
70
+ :label="t('terms.gate.signOut', 'Sign out')"
71
+ @click="signOut"
72
+ />
73
+ <UButton
74
+ icon="i-lucide-check"
75
+ :loading="busy"
76
+ :label="t('terms.gate.accept', 'Accept terms')"
77
+ @click="accept"
78
+ />
79
+ </div>
80
+ </template>
81
+ </UModal>
82
+ </template>
@@ -0,0 +1,11 @@
1
+ import type { UserTermsStatusDto } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ status: UserTermsStatusDto;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
6
+ close: (args_0: UserTermsStatusDto | null) => any;
7
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
8
+ onClose?: ((args_0: UserTermsStatusDto | null) => any) | undefined;
9
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;
@@ -0,0 +1,7 @@
1
+ import type { UsersPublicTerms } from '../../../types.js';
2
+ type __VLS_Props = {
3
+ terms: UsersPublicTerms;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;