@innertia-solutions/innertia-nuxt 0.1.89 → 0.1.91

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 (33) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/app.config.ts +8 -0
  3. package/components/App/NotificationBell.vue +4 -1
  4. package/components/App/NotificationHistory.vue +4 -2
  5. package/components/Integrations/ApiKeys.vue +297 -0
  6. package/components/Integrations/Developers.vue +60 -0
  7. package/components/Integrations/Webhooks.vue +458 -0
  8. package/components/Integrations/__tests__/sfc-compile.test.ts +31 -0
  9. package/components/Mail/BrandingPreview.vue +60 -0
  10. package/components/Mail/BrandingSettings.vue +141 -0
  11. package/components/Notifications/Preferences.vue +98 -0
  12. package/components/Notifications/__tests__/sfc-compile.test.ts +34 -0
  13. package/components/Platform/Emails.vue +133 -0
  14. package/components/Platform/MailSettings.vue +213 -0
  15. package/composables/__tests__/useNotifications.test.ts +32 -0
  16. package/composables/internal/__tests__/forcePassword.test.ts +37 -0
  17. package/composables/internal/__tests__/mailBranding.test.ts +35 -0
  18. package/composables/internal/forcePassword.ts +39 -0
  19. package/composables/internal/mailBranding.ts +62 -0
  20. package/composables/useIntegrations/index.ts +136 -0
  21. package/composables/useIntegrations/internal/__tests__/integrations.test.ts +112 -0
  22. package/composables/useIntegrations/internal/integrations.ts +276 -0
  23. package/composables/useNotificationHistory/index.ts +8 -7
  24. package/composables/useNotificationPreferences/index.ts +28 -0
  25. package/composables/useNotificationPreferences/internal/__tests__/preferences.test.ts +39 -0
  26. package/composables/useNotificationPreferences/internal/preferences.ts +66 -0
  27. package/composables/useNotifications.js +10 -5
  28. package/docs/correos-notificaciones.md +101 -0
  29. package/docs/webhooks-api.md +88 -0
  30. package/middleware/06.force-password.global.ts +14 -0
  31. package/middleware/platform-owner.ts +12 -0
  32. package/nuxt.config.ts +1 -1
  33. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { resolveForcePasswordRedirect } from '../forcePassword'
3
+
4
+ const pending = { force_password_change: true }
5
+ const on = { enabled: true }
6
+
7
+ describe('force-password', () => {
8
+ it('apagado por defecto: nunca redirige', () => {
9
+ expect(resolveForcePasswordRedirect('/backoffice', pending, undefined)).toBeNull()
10
+ expect(resolveForcePasswordRedirect('/backoffice', pending, { enabled: false })).toBeNull()
11
+ })
12
+
13
+ it('con cambio pendiente lleva a la página de cambio del área', () => {
14
+ expect(resolveForcePasswordRedirect('/backoffice/users', pending, on)).toBe('/backoffice/auth/change-password')
15
+ })
16
+
17
+ it('deja pasar las rutas de auth y la propia página de cambio', () => {
18
+ expect(resolveForcePasswordRedirect('/backoffice/auth/change-password', pending, on)).toBeNull()
19
+ expect(resolveForcePasswordRedirect('/backoffice/auth/login', pending, on)).toBeNull()
20
+ })
21
+
22
+ it('sin cambio pendiente o fuera del área no hace nada', () => {
23
+ expect(resolveForcePasswordRedirect('/backoffice', { force_password_change: false }, on)).toBeNull()
24
+ expect(resolveForcePasswordRedirect('/portal', pending, on)).toBeNull()
25
+ expect(resolveForcePasswordRedirect('/backoffice-x', pending, on)).toBeNull()
26
+ })
27
+
28
+ it('rutas configurables por área, el prefijo más largo gana', () => {
29
+ const cfg = { enabled: true, routes: { '/backoffice': '/backoffice/auth/change-password', '/technician': '/technician/password' }, allow: ['/technician/password', '/backoffice/auth/'] }
30
+ expect(resolveForcePasswordRedirect('/technician/agenda', pending, cfg)).toBe('/technician/password')
31
+ expect(resolveForcePasswordRedirect('/technician/password', pending, cfg)).toBeNull()
32
+ })
33
+
34
+ it('/platform lo maneja su propio middleware', () => {
35
+ expect(resolveForcePasswordRedirect('/platform/users', { ...pending, is_platform_admin: true }, { enabled: true, routes: { '/platform': '/x' } })).toBeNull()
36
+ })
37
+ })
@@ -0,0 +1,35 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { resolveBrandingPreview, validateBranding } from '../mailBranding'
3
+
4
+ const platform = { name: 'pomely', logo_url: 'https://cdn.test/pomely.png', color: '#112233' }
5
+
6
+ describe('vista previa de marca', () => {
7
+ it('sin marca del espacio usa la de plataforma (sin "vía")', () => {
8
+ expect(resolveBrandingPreview({}, platform)).toEqual({
9
+ name: 'pomely', logo_url: 'https://cdn.test/pomely.png', color: '#112233', footer_address: null, footer_phone: null, via: null,
10
+ })
11
+ })
12
+
13
+ it('marca propia con respaldo campo a campo y pie "vía"', () => {
14
+ const r = resolveBrandingPreview({ display_name: 'CESFAM Rancagua', footer_phone: '+56 72 123' }, platform)
15
+ expect(r.name).toBe('CESFAM Rancagua')
16
+ expect(r.logo_url).toBeNull() // marca propia sin logo: el nombre en texto, no el logo de plataforma
17
+ expect(r.color).toBe('#112233')
18
+ expect(r.footer_phone).toBe('+56 72 123')
19
+ expect(r.via).toBe('pomely')
20
+ })
21
+
22
+ it('ignora color o URL inválidos', () => {
23
+ const r = resolveBrandingPreview({ color: 'rojo', logo_url: 'ftp://x' }, platform)
24
+ expect(r.color).toBe('#112233')
25
+ expect(r.logo_url).toBe('https://cdn.test/pomely.png')
26
+ })
27
+
28
+ it('valida los campos', () => {
29
+ expect(validateBranding({ color: '#zzz', logo_url: 'logo.png' })).toMatchObject({
30
+ color: 'El color debe ser un hexadecimal como #6366f1 o #fff.',
31
+ logo_url: 'La URL del logo debe comenzar con http:// o https://.',
32
+ })
33
+ expect(validateBranding({ color: '#fff', logo_url: 'https://x.cl/l.png' })).toMatchObject({ color: null, logo_url: null })
34
+ })
35
+ })
@@ -0,0 +1,39 @@
1
+ // Cambio de contraseña forzado (force_password_change) para backoffice y otras áreas.
2
+ // Lógica pura del middleware 06.force-password.global (la usan también los tests).
3
+ //
4
+ // appConfig.innertia.forcePassword = {
5
+ // enabled: true,
6
+ // routes: { '/backoffice': '/backoffice/auth/change-password' }, // prefijo → página de cambio
7
+ // allow: ['/backoffice/auth/'], // prefijos que siempre pasan
8
+ // }
9
+ // /platform ya lo cubre 05.platform-password.global (identidad de plataforma).
10
+
11
+ export interface ForcePasswordConfig {
12
+ enabled?: boolean
13
+ routes?: Record<string, string>
14
+ allow?: string[]
15
+ }
16
+
17
+ export const FORCE_PASSWORD_DEFAULT_ROUTES: Record<string, string> = {
18
+ '/backoffice': '/backoffice/auth/change-password',
19
+ }
20
+
21
+ /** Ruta a la que hay que redirigir, o null si se deja pasar. */
22
+ export function resolveForcePasswordRedirect(path: string, user: any, config?: ForcePasswordConfig | null): string | null {
23
+ if (!config?.enabled || user?.force_password_change !== true) return null
24
+ if (user?.is_platform_admin && path.startsWith('/platform')) return null
25
+
26
+ const routes = config.routes && Object.keys(config.routes).length ? config.routes : FORCE_PASSWORD_DEFAULT_ROUTES
27
+ const allow = config.allow ?? Object.keys(routes).map(prefix => `${prefix.replace(/\/+$/, '')}/auth/`)
28
+
29
+ if (allow.some(prefix => path.startsWith(prefix))) return null
30
+
31
+ // El prefijo más largo gana (p. ej. /backoffice/admin antes que /backoffice).
32
+ const match = Object.keys(routes)
33
+ .sort((a, b) => b.length - a.length)
34
+ .find(prefix => path === prefix || path.startsWith(prefix.endsWith('/') ? prefix : `${prefix}/`))
35
+
36
+ if (!match) return null
37
+ const target = routes[match]
38
+ return path === target ? null : target
39
+ }
@@ -0,0 +1,62 @@
1
+ // Vista previa de la marca de correos (espejo de \Innertia\Mail\Branding::for()):
2
+ // marca del espacio con respaldo campo a campo en la de plataforma y "vía" cuando hay marca propia.
3
+
4
+ export interface BrandingFields {
5
+ display_name?: string | null
6
+ logo_url?: string | null
7
+ color?: string | null
8
+ footer_address?: string | null
9
+ footer_phone?: string | null
10
+ }
11
+
12
+ export interface ResolvedBranding {
13
+ name: string
14
+ logo_url: string | null
15
+ color: string
16
+ footer_address: string | null
17
+ footer_phone: string | null
18
+ via: string | null
19
+ }
20
+
21
+ export const DEFAULT_BRAND_COLOR = '#6366f1'
22
+ export const HEX_COLOR = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/
23
+ const HTTP_URL = /^https?:\/\//i
24
+
25
+ const clean = (v?: string | null) => (typeof v === 'string' && v.trim() !== '' ? v.trim() : null)
26
+
27
+ export function resolveBrandingPreview(tenant: BrandingFields | null | undefined, platform: Partial<ResolvedBranding> | null | undefined): ResolvedBranding {
28
+ const p: ResolvedBranding = {
29
+ name: clean(platform?.name) ?? 'App',
30
+ logo_url: clean(platform?.logo_url),
31
+ color: clean(platform?.color) ?? DEFAULT_BRAND_COLOR,
32
+ footer_address: null,
33
+ footer_phone: null,
34
+ via: null,
35
+ }
36
+
37
+ const name = clean(tenant?.display_name)
38
+ const logoRaw = clean(tenant?.logo_url)
39
+ const logo = logoRaw && HTTP_URL.test(logoRaw) ? logoRaw : null
40
+ const color = clean(tenant?.color)
41
+ const own = name !== null || logo !== null
42
+
43
+ return {
44
+ name: name ?? p.name,
45
+ logo_url: logo ?? (own ? null : p.logo_url),
46
+ color: color && HEX_COLOR.test(color) ? color : p.color,
47
+ footer_address: clean(tenant?.footer_address),
48
+ footer_phone: clean(tenant?.footer_phone),
49
+ via: own && name !== p.name ? p.name : null,
50
+ }
51
+ }
52
+
53
+ /** Errores de validación local de los campos de marca (null = válido). */
54
+ export function validateBranding(fields: BrandingFields): Record<string, string | null> {
55
+ const logo = clean(fields.logo_url)
56
+ const color = clean(fields.color)
57
+ return {
58
+ logo_url: logo && !HTTP_URL.test(logo) ? 'La URL del logo debe comenzar con http:// o https://.' : null,
59
+ color: color && !HEX_COLOR.test(color) ? 'El color debe ser un hexadecimal como #6366f1 o #fff.' : null,
60
+ display_name: (fields.display_name ?? '').length > 120 ? 'Máximo 120 caracteres.' : null,
61
+ }
62
+ }
@@ -0,0 +1,136 @@
1
+ import { computed } from 'vue'
2
+ import type { ApiKey, ApiScope, Webhook, WebhookEvent, WebhookLog } from './internal/integrations'
3
+
4
+ // Only the composables are exported: ./internal helpers are not auto-imported globally
5
+ // (avoids name clashes in products).
6
+
7
+ const clean = (base?: string) => String(base || 'integrations').replace(/^\/+|\/+$/g, '')
8
+
9
+ export interface CursorPage<T> { data: T[]; meta?: { next_cursor?: string | null; limit?: number } }
10
+
11
+ /**
12
+ * API keys of the active space (innertia-laravel \Innertia\PublicApi\Routes::manage()):
13
+ * GET api-keys · GET api-keys/scopes · POST api-keys → {data, secret} (shown once)
14
+ * POST api-keys/{id}/rotate → {data, secret, previous} · DELETE api-keys/{id}
15
+ * GET api-keys/{id}/requests?cursor&limit → {data, meta.next_cursor}
16
+ *
17
+ * `base`: API prefix where the product mounted the routes (default 'integrations').
18
+ */
19
+ export function useApiKeys(options: { base?: string } = {}) {
20
+ const base = clean(options.base)
21
+ const api = useApi()
22
+ const queryClient = useQueryClient()
23
+ const listKey = computed(() => ['integrations', base, 'api-keys'])
24
+ const invalidate = () => queryClient.invalidateQueries({ queryKey: listKey.value })
25
+
26
+ const list = useQuery({
27
+ queryKey: listKey,
28
+ queryFn: () => api.get(`${base}/api-keys`),
29
+ select: (res: any) => (res?.data ?? []) as ApiKey[],
30
+ })
31
+
32
+ const scopes = useQuery({
33
+ queryKey: computed(() => ['integrations', base, 'api-key-scopes']),
34
+ queryFn: () => api.get(`${base}/api-keys/scopes`),
35
+ select: (res: any) => (res?.data ?? []) as ApiScope[],
36
+ staleTime: 5 * 60_000,
37
+ })
38
+
39
+ const create = useMutation({
40
+ mutationFn: (body: { name: string; scopes: string[]; organization_id?: string | number | null; expires_at?: string | null }) =>
41
+ api.post(`${base}/api-keys`, body) as Promise<{ data: ApiKey; secret: string }>,
42
+ onSuccess: invalidate,
43
+ })
44
+
45
+ const rotate = useMutation({
46
+ mutationFn: (id: string) =>
47
+ api.post(`${base}/api-keys/${id}/rotate`, {}) as Promise<{ data: ApiKey; secret: string; previous?: { id: string; expires_at: string | null } }>,
48
+ onSuccess: invalidate,
49
+ })
50
+
51
+ const revoke = useMutation({
52
+ mutationFn: (id: string) => api.delete(`${base}/api-keys/${id}`) as Promise<{ data: ApiKey }>,
53
+ onSuccess: invalidate,
54
+ })
55
+
56
+ /** Request log page of a key (cursor pagination). */
57
+ function requests(id: string, cursor?: string | null, limit = 25): Promise<CursorPage<any>> {
58
+ return api.get(`${base}/api-keys/${id}/requests`, { params: { limit, ...(cursor ? { cursor } : {}) } })
59
+ }
60
+
61
+ return { list, scopes, create, rotate, revoke, requests }
62
+ }
63
+
64
+ /**
65
+ * Outbound webhooks of the active space (innertia-laravel \Innertia\PublicApi\Routes::manage()):
66
+ * GET webhooks · GET webhooks/events · POST webhooks → {data, secret} · GET|PATCH|DELETE webhooks/{id}
67
+ * POST webhooks/{id}/rotate-secret → {data, secret} · POST webhooks/{id}/test
68
+ * GET webhooks/{id}/logs?cursor&limit&status · GET webhooks/{id}/logs/{log} · POST …/logs/{log}/resend
69
+ */
70
+ export function useWebhooks(options: { base?: string } = {}) {
71
+ const base = clean(options.base)
72
+ const api = useApi()
73
+ const queryClient = useQueryClient()
74
+ const listKey = computed(() => ['integrations', base, 'webhooks'])
75
+ const invalidate = () => queryClient.invalidateQueries({ queryKey: listKey.value })
76
+
77
+ const list = useQuery({
78
+ queryKey: listKey,
79
+ queryFn: () => api.get(`${base}/webhooks`),
80
+ select: (res: any) => (res?.data ?? []) as Webhook[],
81
+ })
82
+
83
+ const events = useQuery({
84
+ queryKey: computed(() => ['integrations', base, 'webhook-events']),
85
+ queryFn: () => api.get(`${base}/webhooks/events`),
86
+ select: (res: any) => (res?.data ?? []) as WebhookEvent[],
87
+ staleTime: 5 * 60_000,
88
+ })
89
+
90
+ type WebhookInput = { url?: string; events?: string[]; description?: string | null; organization_id?: string | number | null; scopes?: string[]; active?: boolean }
91
+
92
+ const create = useMutation({
93
+ mutationFn: (body: WebhookInput) => api.post(`${base}/webhooks`, body) as Promise<{ data: Webhook; secret: string }>,
94
+ onSuccess: invalidate,
95
+ })
96
+
97
+ const update = useMutation({
98
+ mutationFn: ({ id, ...body }: WebhookInput & { id: string | number }) =>
99
+ api.patch(`${base}/webhooks/${id}`, body) as Promise<{ data: Webhook }>,
100
+ onSuccess: invalidate,
101
+ })
102
+
103
+ const remove = useMutation({
104
+ mutationFn: (id: string | number) => api.delete(`${base}/webhooks/${id}`),
105
+ onSuccess: invalidate,
106
+ })
107
+
108
+ const rotateSecret = useMutation({
109
+ mutationFn: (id: string | number) => api.post(`${base}/webhooks/${id}/rotate-secret`, {}) as Promise<{ data: Webhook; secret: string }>,
110
+ onSuccess: invalidate,
111
+ })
112
+
113
+ const test = useMutation({
114
+ mutationFn: (id: string | number) => api.post(`${base}/webhooks/${id}/test`, {}) as Promise<{ data: WebhookLog }>,
115
+ })
116
+
117
+ const resend = useMutation({
118
+ mutationFn: ({ id, logId }: { id: string | number; logId: string | number }) =>
119
+ api.post(`${base}/webhooks/${id}/logs/${logId}/resend`, {}) as Promise<{ data: WebhookLog }>,
120
+ })
121
+
122
+ /** Delivery log page (cursor pagination, optional status filter). */
123
+ function logs(id: string | number, params: { cursor?: string | null; status?: string; limit?: number } = {}): Promise<CursorPage<WebhookLog>> {
124
+ const q: Record<string, any> = { limit: params.limit ?? 25 }
125
+ if (params.cursor) q.cursor = params.cursor
126
+ if (params.status) q.status = params.status
127
+ return api.get(`${base}/webhooks/${id}/logs`, { params: q })
128
+ }
129
+
130
+ /** One delivery with payload, request headers and (truncated) response body. */
131
+ function log(id: string | number, logId: string | number): Promise<{ data: WebhookLog }> {
132
+ return api.get(`${base}/webhooks/${id}/logs/${logId}`)
133
+ }
134
+
135
+ return { list, events, create, update, remove, rotateSecret, test, resend, logs, log }
136
+ }
@@ -0,0 +1,112 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import {
3
+ apiKeyStatus, deliveryStatus, webhookState, httpSeverity, scopeResource, groupScopes, toggleValue,
4
+ eventMatches, isEventSelected, groupEvents, toggleFamily, toggleEvent, familyState,
5
+ validateWebhookUrl, relativeTime, expiryLabel, expiryFromPreset, appendPage, prettyJson,
6
+ } from '../integrations'
7
+
8
+ const catalog = [
9
+ { key: 'call.ringing' }, { key: 'call.answered' }, { key: 'call.ended' },
10
+ { key: 'person.created' }, { key: 'person.updated' },
11
+ ]
12
+
13
+ describe('status labels', () => {
14
+ it('maps key and delivery statuses with fallback', () => {
15
+ expect(apiKeyStatus('active')).toEqual({ label: 'Activa', severity: 'success' })
16
+ expect(apiKeyStatus('revoked').severity).toBe('danger')
17
+ expect(apiKeyStatus('weird').label).toBe('weird')
18
+ expect(deliveryStatus('retrying').label).toBe('Reintentando')
19
+ expect(deliveryStatus(null).label).toBe('—')
20
+ })
21
+
22
+ it('derives the webhook state', () => {
23
+ expect(webhookState({ active: false, disabled_at: '2026-11-19T00:00:00Z' }).label).toBe('Desactivado por fallas')
24
+ expect(webhookState({ active: false }).label).toBe('Pausado')
25
+ expect(webhookState({ active: true, failing_since: 'x' }).severity).toBe('warning')
26
+ expect(webhookState({ active: true }).label).toBe('Activo')
27
+ })
28
+
29
+ it('colors http statuses', () => {
30
+ expect(httpSeverity(200)).toBe('success')
31
+ expect(httpSeverity(404)).toBe('warning')
32
+ expect(httpSeverity(503)).toBe('danger')
33
+ expect(httpSeverity(null)).toBe('secondary')
34
+ })
35
+ })
36
+
37
+ describe('scopes', () => {
38
+ it('groups by explicit group or resource', () => {
39
+ expect(scopeResource('calls:read')).toBe('calls')
40
+ const g = groupScopes([{ key: 'calls:read' }, { key: 'people:read' }, { key: 'calls:write' }, { key: 'people:pii', group: 'people' }])
41
+ expect(g.map(x => x.group)).toEqual(['calls', 'people'])
42
+ expect(g[0].items.map(i => i.key)).toEqual(['calls:read', 'calls:write'])
43
+ expect(g[1].items).toHaveLength(2)
44
+ })
45
+
46
+ it('toggles values without duplicates', () => {
47
+ expect(toggleValue(['a'], 'a', true)).toEqual(['a'])
48
+ expect(toggleValue(['a', 'b'], 'a', false)).toEqual(['b'])
49
+ })
50
+ })
51
+
52
+ describe('event selection with wildcards', () => {
53
+ it('matches patterns', () => {
54
+ expect(eventMatches('*', 'call.ended')).toBe(true)
55
+ expect(eventMatches('call.*', 'call.ended')).toBe(true)
56
+ expect(eventMatches('call.*', 'callback.x')).toBe(false)
57
+ expect(isEventSelected(['person.created'], 'person.updated')).toBe(false)
58
+ })
59
+
60
+ it('groups events by family', () => {
61
+ expect(groupEvents(catalog).map(g => [g.family, g.items.length])).toEqual([['call', 3], ['person', 2]])
62
+ })
63
+
64
+ it('toggles a family as wildcard', () => {
65
+ expect(toggleFamily(['call.ended', 'person.created'], 'call', true)).toEqual(['person.created', 'call.*'])
66
+ expect(toggleFamily(['call.*', 'person.created'], 'call', false)).toEqual(['person.created'])
67
+ })
68
+
69
+ it('expands a wildcard when one event is turned off', () => {
70
+ expect(toggleEvent(['call.*'], 'call.ringing', false, catalog)).toEqual(['call.answered', 'call.ended'])
71
+ expect(toggleEvent(['*'], 'person.updated', false, catalog).sort()).toEqual(['call.*', 'person.created'].sort())
72
+ expect(toggleEvent(['call.*'], 'call.ended', true, catalog)).toEqual(['call.*'])
73
+ expect(toggleEvent([], 'call.ended', true, catalog)).toEqual(['call.ended'])
74
+ })
75
+
76
+ it('reports family state', () => {
77
+ expect(familyState(['call.*'], 'call', catalog)).toBe('all')
78
+ expect(familyState(['call.ended'], 'call', catalog)).toBe('some')
79
+ expect(familyState(['person.created', 'person.updated'], 'person', catalog)).toBe('all')
80
+ expect(familyState([], 'person', catalog)).toBe('none')
81
+ })
82
+ })
83
+
84
+ describe('validation and dates', () => {
85
+ it('validates https webhook URLs', () => {
86
+ expect(validateWebhookUrl('')).toMatch(/Ingresa/)
87
+ expect(validateWebhookUrl('http://x.cl/hook')).toMatch(/https/)
88
+ expect(validateWebhookUrl('nope')).toMatch(/no es válida/)
89
+ expect(validateWebhookUrl('https://u:p@x.cl')).toMatch(/credenciales/)
90
+ expect(validateWebhookUrl('https://hooks.example.com/in')).toBeNull()
91
+ })
92
+
93
+ it('formats relative times and expiry', () => {
94
+ const now = new Date('2026-11-19T12:00:00Z')
95
+ expect(relativeTime('2026-11-19T11:55:00Z', now)).toBe('hace 5 min')
96
+ expect(relativeTime('2026-11-22T12:00:00Z', now)).toBe('en 3 días')
97
+ expect(relativeTime(null, now)).toBe('—')
98
+ expect(expiryLabel(null, now)).toBe('Sin vencimiento')
99
+ expect(expiryLabel('2026-11-20T12:00:00Z', now)).toBe('Vence en 1 día')
100
+ expect(expiryLabel('2026-11-18T12:00:00Z', now)).toBe('Venció hace 1 día')
101
+ expect(expiryFromPreset('30', now)).toBe('2026-12-19T12:00:00.000Z')
102
+ expect(expiryFromPreset('', now)).toBeNull()
103
+ })
104
+
105
+ it('appends cursor pages without duplicates and pretty-prints json', () => {
106
+ expect(appendPage([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }]).map(i => i.id)).toEqual([1, 2, 3])
107
+ expect(prettyJson('{"a":1}')).toBe('{\n "a": 1\n}')
108
+ expect(prettyJson({ a: 1 })).toBe('{\n "a": 1\n}')
109
+ expect(prettyJson('plain')).toBe('plain')
110
+ expect(prettyJson(null)).toBe('')
111
+ })
112
+ })