@plutocms/supabase 0.9.0 → 0.10.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.
Files changed (35) hide show
  1. package/.prettierignore +2 -0
  2. package/CHANGELOG.md +15 -0
  3. package/FEATURES.md +6 -0
  4. package/app/components/EnvPersistWarning.vue +30 -13
  5. package/app/components/SupabaseMessageParts.vue +29 -0
  6. package/app/components/migrations/MigrationsBanner.vue +3 -4
  7. package/app/components/navbar/NavbarAdmin.vue +15 -9
  8. package/app/components/settings/SettingsGeneralPanel.vue +21 -6
  9. package/app/composables/auth.ts +17 -14
  10. package/app/pages/admin/(auth)/confirm.vue +6 -5
  11. package/app/pages/admin/(auth)/forgot-password.vue +15 -11
  12. package/app/pages/admin/(auth)/login.vue +10 -8
  13. package/app/pages/admin/(auth)/signup.vue +30 -22
  14. package/app/pages/admin/(auth)/update-password.vue +15 -12
  15. package/app/pages/admin/migrations.vue +87 -51
  16. package/app/pages/admin/setup.vue +88 -74
  17. package/app/pages/admin.vue +3 -2
  18. package/app/plugins/pluto-extension.ts +24 -3
  19. package/app/plugins/pluto-locale-sync.client.ts +30 -0
  20. package/app/utils/auth-error.ts +53 -0
  21. package/db/migrations/005_profile_locale.sql +44 -0
  22. package/i18n/locales/en.json +209 -0
  23. package/i18n/locales/pt-BR.json +209 -0
  24. package/package.json +3 -3
  25. package/server/api/profile/locale.get.ts +39 -0
  26. package/server/api/profile/locale.post.ts +71 -0
  27. package/server/api/setup/create.post.ts +6 -4
  28. package/server/api/users/[id].get.ts +4 -2
  29. package/server/api/users/index.get.ts +4 -2
  30. package/server/utils/admin-guard.ts +10 -2
  31. package/server/utils/capability-guard.ts +18 -4
  32. package/server/utils/content-adapter.ts +6 -4
  33. package/server/utils/pending-migrations.ts +0 -0
  34. package/server/utils/validate.ts +6 -1
  35. package/shared/types/supabase.ts +7 -0
@@ -5,8 +5,10 @@ import { serverSupabaseClient, serverSupabaseUser } from '#supabase/server'
5
5
  export const ALL_CAPABILITIES = '*'
6
6
 
7
7
  interface RequireCapabilityOptions {
8
- /** Overrides the 403 message. */
8
+ /** Overrides the 403 message. English text. */
9
9
  message?: string
10
+ /** Translation key of the `message` override, for the admin UI. */
11
+ messageKey?: string
10
12
  }
11
13
 
12
14
  /**
@@ -34,17 +36,29 @@ export async function requireCapability(
34
36
  const user = await serverSupabaseUser(event)
35
37
 
36
38
  if (!user) {
37
- throw createError({ statusCode: 401, statusMessage: 'You must be logged in.' })
39
+ throw createPlutoError({
40
+ statusCode: 401,
41
+ message: 'You must be logged in.',
42
+ key: 'supabase.errors.notLoggedIn',
43
+ })
38
44
  }
39
45
 
40
46
  const client = await serverSupabaseClient<Database>(event)
41
47
  const { data, error } = await client.rpc('has_capability', { cap: capability })
42
48
 
43
49
  if (error || data !== true) {
44
- throw createError({
50
+ // A custom `message` without a `messageKey` has no translation, so it
51
+ // keeps the plain English error.
52
+ if (options?.message && !options.messageKey) {
53
+ throw createError({ statusCode: 403, statusMessage: options.message })
54
+ }
55
+
56
+ throw createPlutoError({
45
57
  statusCode: 403,
46
- statusMessage:
58
+ message:
47
59
  options?.message ?? `Your account is missing the "${capability}" permission.`,
60
+ key: options?.messageKey ?? 'supabase.errors.missingPermission',
61
+ params: { capability },
48
62
  })
49
63
  }
50
64
 
@@ -82,17 +82,19 @@ export function toContentError(error: PostgrestError) {
82
82
 
83
83
  // 23505: unique_violation.
84
84
  if (error.code === '23505') {
85
- return createError({
85
+ return createPlutoError({
86
86
  statusCode: 409,
87
- statusMessage: 'A record with this value already exists.',
87
+ message: 'A record with this value already exists.',
88
+ key: 'supabase.errors.duplicateRecord',
88
89
  })
89
90
  }
90
91
 
91
92
  // 23503: foreign_key_violation.
92
93
  if (error.code === '23503') {
93
- return createError({
94
+ return createPlutoError({
94
95
  statusCode: 400,
95
- statusMessage: 'This references a record that does not exist.',
96
+ message: 'This references a record that does not exist.',
97
+ key: 'supabase.errors.missingReference',
96
98
  })
97
99
  }
98
100
 
Binary file
@@ -37,7 +37,12 @@ export async function parseBody<T>(event: H3Event, schema: ZodSchema<T>): Promis
37
37
  message: issue.message,
38
38
  }))
39
39
 
40
- throw createError({ statusCode: 400, statusMessage: 'Validation failed.', data: { errors } })
40
+ throw createPlutoError({
41
+ statusCode: 400,
42
+ message: 'Validation failed.',
43
+ key: 'pluto.errors.validationFailed',
44
+ data: { errors },
45
+ })
41
46
  }
42
47
 
43
48
  return result.data
@@ -232,6 +232,7 @@ export type Database = {
232
232
  email: string | null
233
233
  id: string
234
234
  is_admin: boolean
235
+ locale: string | null
235
236
  updated_at: string | null
236
237
  username: string | null
237
238
  }
@@ -240,6 +241,7 @@ export type Database = {
240
241
  email?: string | null
241
242
  id: string
242
243
  is_admin?: boolean
244
+ locale?: string | null
243
245
  updated_at?: string | null
244
246
  username?: string | null
245
247
  }
@@ -248,6 +250,7 @@ export type Database = {
248
250
  email?: string | null
249
251
  id?: string
250
252
  is_admin?: boolean
253
+ locale?: string | null
251
254
  updated_at?: string | null
252
255
  username?: string | null
253
256
  }
@@ -364,6 +367,10 @@ export type Database = {
364
367
  Args: Record<PropertyKey, never>
365
368
  Returns: boolean
366
369
  }
370
+ set_my_locale: {
371
+ Args: { new_locale: string }
372
+ Returns: undefined
373
+ }
367
374
  }
368
375
  Enums: {
369
376
  thealthcheck: "first_setup"