@asteby/metacore-runtime-react 53.20.0 → 53.21.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 (89) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/attention/apply-nav-badges.d.ts +10 -0
  3. package/dist/attention/apply-nav-badges.d.ts.map +1 -0
  4. package/dist/attention/apply-nav-badges.js +35 -0
  5. package/dist/attention/index.d.ts +4 -0
  6. package/dist/attention/index.d.ts.map +1 -0
  7. package/dist/attention/index.js +3 -0
  8. package/dist/attention/use-document-attention.d.ts +10 -0
  9. package/dist/attention/use-document-attention.d.ts.map +1 -0
  10. package/dist/attention/use-document-attention.js +66 -0
  11. package/dist/attention/use-nav-badges.d.ts +42 -0
  12. package/dist/attention/use-nav-badges.d.ts.map +1 -0
  13. package/dist/attention/use-nav-badges.js +54 -0
  14. package/dist/dynamic-columns.js +1 -1
  15. package/dist/dynamic-table.js +3 -3
  16. package/dist/genui/index.d.ts +2 -0
  17. package/dist/genui/index.d.ts.map +1 -0
  18. package/dist/genui/index.js +1 -0
  19. package/dist/genui/settings-block.d.ts +31 -0
  20. package/dist/genui/settings-block.d.ts.map +1 -0
  21. package/dist/genui/settings-block.js +100 -0
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -0
  25. package/dist/setup/addon-config-surface.d.ts +14 -1
  26. package/dist/setup/addon-config-surface.d.ts.map +1 -1
  27. package/dist/setup/addon-config-surface.js +109 -6
  28. package/dist/setup/messages.d.ts.map +1 -1
  29. package/dist/setup/messages.js +50 -0
  30. package/dist/setup/secret-field-model.d.ts +47 -0
  31. package/dist/setup/secret-field-model.d.ts.map +1 -0
  32. package/dist/setup/secret-field-model.js +95 -0
  33. package/dist/view-system/card-spec.d.ts +24 -0
  34. package/dist/view-system/card-spec.d.ts.map +1 -0
  35. package/dist/view-system/card-spec.js +40 -0
  36. package/dist/view-system/cards-view.d.ts +17 -0
  37. package/dist/view-system/cards-view.d.ts.map +1 -0
  38. package/dist/view-system/cards-view.js +37 -0
  39. package/dist/view-system/index.d.ts +10 -0
  40. package/dist/view-system/index.d.ts.map +1 -0
  41. package/dist/view-system/index.js +9 -0
  42. package/dist/view-system/model-view.d.ts +31 -0
  43. package/dist/view-system/model-view.d.ts.map +1 -0
  44. package/dist/view-system/model-view.js +50 -0
  45. package/dist/view-system/saved-views.d.ts +22 -0
  46. package/dist/view-system/saved-views.d.ts.map +1 -0
  47. package/dist/view-system/saved-views.js +53 -0
  48. package/dist/view-system/types.d.ts +63 -0
  49. package/dist/view-system/types.d.ts.map +1 -0
  50. package/dist/view-system/types.js +1 -0
  51. package/dist/view-system/use-view-mode.d.ts +26 -0
  52. package/dist/view-system/use-view-mode.d.ts.map +1 -0
  53. package/dist/view-system/use-view-mode.js +60 -0
  54. package/dist/view-system/view-state.d.ts +19 -0
  55. package/dist/view-system/view-state.d.ts.map +1 -0
  56. package/dist/view-system/view-state.js +66 -0
  57. package/dist/view-system/view-switcher.d.ts +14 -0
  58. package/dist/view-system/view-switcher.d.ts.map +1 -0
  59. package/dist/view-system/view-switcher.js +26 -0
  60. package/dist/view-system/view-toolbar.d.ts +19 -0
  61. package/dist/view-system/view-toolbar.d.ts.map +1 -0
  62. package/dist/view-system/view-toolbar.js +33 -0
  63. package/package.json +14 -5
  64. package/src/__tests__/addon-config-surface.test.tsx +67 -1
  65. package/src/__tests__/attention-view-system.test.tsx +128 -0
  66. package/src/__tests__/genui-settings-block.test.tsx +73 -0
  67. package/src/attention/apply-nav-badges.ts +42 -0
  68. package/src/attention/index.ts +11 -0
  69. package/src/attention/use-document-attention.ts +62 -0
  70. package/src/attention/use-nav-badges.ts +94 -0
  71. package/src/dynamic-columns.tsx +1 -1
  72. package/src/dynamic-table.tsx +3 -3
  73. package/src/genui/index.ts +1 -0
  74. package/src/genui/settings-block.tsx +123 -0
  75. package/src/index.ts +2 -0
  76. package/src/setup/addon-config-surface.tsx +297 -16
  77. package/src/setup/messages.ts +50 -0
  78. package/src/setup/secret-field-model.test.ts +67 -0
  79. package/src/setup/secret-field-model.ts +104 -0
  80. package/src/view-system/card-spec.tsx +78 -0
  81. package/src/view-system/cards-view.tsx +61 -0
  82. package/src/view-system/index.ts +9 -0
  83. package/src/view-system/model-view.tsx +105 -0
  84. package/src/view-system/saved-views.ts +66 -0
  85. package/src/view-system/types.ts +63 -0
  86. package/src/view-system/use-view-mode.ts +79 -0
  87. package/src/view-system/view-state.ts +61 -0
  88. package/src/view-system/view-switcher.tsx +53 -0
  89. package/src/view-system/view-toolbar.tsx +119 -0
package/src/index.ts CHANGED
@@ -899,3 +899,5 @@ export {
899
899
  } from './bulk-image-dialog'
900
900
  export type { BulkImageTarget } from './bulk-image-target'
901
901
  export type { BatchLog as BulkImageBatchLog } from './bulk-image-import'
902
+ export * from './attention'
903
+ export * from './view-system'
@@ -12,11 +12,11 @@
12
12
  // fields). Everything host-specific is injected: the API client (ApiProvider
13
13
  // or `client`), the admin gate (`canManageIssuer`), the active branch, the
14
14
  // addon i18n bundle loader and the notifier.
15
- import { createContext, useContext, useEffect, useId, useRef, useState } from 'react'
15
+ import { createContext, useContext, useEffect, useId, useRef, useState, type ReactNode } from 'react'
16
16
  import { useMutation } from '@tanstack/react-query'
17
17
  import { useTranslation } from 'react-i18next'
18
18
  import { toast } from 'sonner'
19
- import { AlertCircle, Cable, Check, Eye, EyeOff, Link2, Loader2, Pencil, RefreshCw, Settings, X } from 'lucide-react'
19
+ import { AlertCircle, Cable, Check, Copy, Eye, EyeOff, Link2, Loader2, Pencil, RefreshCw, Settings, Sparkles, X } from 'lucide-react'
20
20
  import {
21
21
  Badge,
22
22
  Button,
@@ -42,6 +42,15 @@ import type { VisibleWhen } from '../types'
42
42
  import { useSetupT } from './messages'
43
43
  import { StepStatusBadge } from './step-status-badge'
44
44
  import { ConnectorBlocks, CopyValue, HelpText } from './connector-blocks'
45
+ import { copyText } from './records-table'
46
+ import {
47
+ generateSecret,
48
+ generatedLength,
49
+ secretMinLength,
50
+ secretStrength,
51
+ splitHelp,
52
+ tooShortSecrets,
53
+ } from './secret-field-model'
45
54
  import {
46
55
  buildWizardSteps,
47
56
  errorMessage,
@@ -83,6 +92,7 @@ export interface AddonConfigAddon {
83
92
  manifest: {
84
93
  name: string
85
94
  display_name?: string
95
+ version?: string
86
96
  settings_defs?: AddonSettingDef[]
87
97
  }
88
98
  }
@@ -98,6 +108,12 @@ export interface ConnectorCredentialField {
98
108
  options?: { value: string; label: string }[]
99
109
  options_source?: string // dynamic_select: export the host runs to list options
100
110
  section?: string // binds to a form_layout section
111
+ /**
112
+ * Constraint hint from the manifest. For secrets the surface reads a minimum
113
+ * length from `min_length:N` (or the regex `^.{N,}$`): it sizes "Generar",
114
+ * validates live and blocks Guardar while shorter.
115
+ */
116
+ validation?: string
101
117
  /** Shown only while a sibling credential has this value (kernel Setting.visible_when). */
102
118
  visible_when?: VisibleWhen
103
119
  visibleWhen?: VisibleWhen
@@ -188,12 +204,17 @@ export interface AddonConfigSurfaceProps {
188
204
  expectedOptionKinds?: Record<string, string>
189
205
  /** Title name; default `manifest.display_name ?? manifest.name`. */
190
206
  displayName?: string
207
+ /** Logo drawn before the title (use `<AddonLogo size='modal' />` from
208
+ * `@asteby/metacore-ui/primitives` so it is never cropped). */
209
+ logo?: ReactNode
191
210
  /**
192
211
  * OAuth connectors (auth != "token") have no credential form: the surface
193
212
  * shows the connection state and a "Conectar cuenta" button that calls this
194
213
  * (the host starts its OAuth flow). Absent → no button.
195
214
  */
196
215
  onConnectOAuth?: (connector: ConnectorEntry) => void
216
+ /** Addon version shown next to the name; default `manifest.version`. */
217
+ version?: string
197
218
  }
198
219
 
199
220
  /** Key of the implicit "Probar conexión" block (connector.test_export). */
@@ -227,6 +248,8 @@ interface ConnectorFormState {
227
248
  expectedOptionKinds: Record<string, string>
228
249
  /** Bumped after a save: dependent selects re-list their options in place. */
229
250
  reloadNonce?: number
251
+ /** The user may write credentials (org admin): gates Generar / Rotar. */
252
+ canManage?: boolean
230
253
  }
231
254
  const ConnectorFormStateContext = createContext<ConnectorFormState>({
232
255
  fields: [],
@@ -235,6 +258,26 @@ const ConnectorFormStateContext = createContext<ConnectorFormState>({
235
258
  expectedOptionKinds: {},
236
259
  })
237
260
 
261
+ // Field help: a short lead sentence, with the technical remainder (endpoints,
262
+ // header names…) behind a collapsible «Cómo se usa» so the form stays calm.
263
+ function FieldHelp({ text }: { text: string }) {
264
+ const st = useSetupT()
265
+ const { lead, detail } = splitHelp(text)
266
+ return (
267
+ <div className='flex flex-col gap-1'>
268
+ <HelpText text={lead} />
269
+ {detail ? (
270
+ <details className='group text-xs text-muted-foreground'>
271
+ <summary className='flex min-h-11 w-fit cursor-pointer items-center gap-1 font-medium text-primary select-none focus-visible:outline-2 focus-visible:outline-ring sm:min-h-6'>
272
+ {st('secret.how_to_use')}
273
+ </summary>
274
+ <p className='pb-1 leading-relaxed break-words whitespace-pre-line'>{detail}</p>
275
+ </details>
276
+ ) : null}
277
+ </div>
278
+ )
279
+ }
280
+
238
281
  function ConnectorCredentialFieldControl({
239
282
  field,
240
283
  value,
@@ -260,6 +303,7 @@ function ConnectorCredentialFieldControl({
260
303
  const { t } = useTranslation()
261
304
  const st = useSetupT()
262
305
  const form = useContext(ConnectorFormStateContext)
306
+ const canManage = form.canManage !== false
263
307
  // label/description are i18n keys (addon locales are loaded into i18next);
264
308
  // never surface a raw dotted key: fall back to the humanized field key.
265
309
  const humanize = (k: string) =>
@@ -279,12 +323,20 @@ function ConnectorCredentialFieldControl({
279
323
  const [revealed, setRevealed] = useState<string | null>(null)
280
324
  const [revealing, setRevealing] = useState(false)
281
325
  const [armed, setArmed] = useState(false)
326
+ const [confirmRotate, setConfirmRotate] = useState(false)
327
+ const [generated, setGenerated] = useState(false)
328
+ const [genError, setGenError] = useState(false)
329
+ const [copyState, setCopyState] = useState<'idle' | 'copied' | 'failed'>('idle')
330
+ const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
331
+ useEffect(() => () => clearTimeout(copyTimer.current), [])
282
332
  const initial = useRef('')
283
333
  const locked = stored && !editing
284
334
  useEffect(() => {
285
335
  setEditing(false)
286
336
  setVisible(false)
287
337
  setRevealed(null)
338
+ setConfirmRotate(false)
339
+ setGenerated(false)
288
340
  }, [resetKey])
289
341
  const canEye = isSecret ? (locked ? !!onReveal : true) : false
290
342
  const toggleEye = async () => {
@@ -320,8 +372,39 @@ function ConnectorCredentialFieldControl({
320
372
  onChange(initial.current)
321
373
  setVisible(false)
322
374
  setEditing(false)
375
+ setGenerated(false)
376
+ }
377
+ // Generate: a CSPRNG value at least as long as the manifest's minimum, shown
378
+ // so it can be copied before saving. Rotating a STORED secret goes through
379
+ // an explicit confirmation first (confirmRotate).
380
+ const minLen = isSecret ? secretMinLength(field) : 0
381
+ const generate = () => {
382
+ try {
383
+ const next = generateSecret(generatedLength(field))
384
+ if (stored && !editing) {
385
+ initial.current = value
386
+ setEditing(true)
387
+ }
388
+ setArmed(true)
389
+ setVisible(true)
390
+ setRevealed(null)
391
+ setGenerated(true)
392
+ setGenError(false)
393
+ setConfirmRotate(false)
394
+ onChange(next)
395
+ } catch {
396
+ setGenError(true)
397
+ }
398
+ }
399
+ const copyValue = async () => {
400
+ const ok = await copyText(value)
401
+ setCopyState(ok ? 'copied' : 'failed')
402
+ clearTimeout(copyTimer.current)
403
+ copyTimer.current = setTimeout(() => setCopyState('idle'), 2500)
323
404
  }
324
- const error = form.errors[field.key]
405
+ const strength = isSecret ? secretStrength(value, minLen) : 'empty'
406
+ const shortBy = isSecret && minLen > 0 && value !== '' && value.length < minLen
407
+ const error = form.errors[field.key] ?? (shortBy ? st('secret.too_short', { min: minLen, n: value.length }) : undefined)
325
408
  const mismatch = shapeMismatch(field, value, form.fields)
326
409
  const target = mismatch?.suggestedKey
327
410
  ? form.fields.find((f) => f.key === mismatch.suggestedKey)
@@ -387,7 +470,10 @@ function ConnectorCredentialFieldControl({
387
470
  )}
388
471
  placeholder={(connected || stored) && isSecret ? '••••••••' : ''}
389
472
  value={locked && isSecret ? (revealed ?? '') : value}
390
- onChange={(e) => onChange(e.target.value)}
473
+ onChange={(e) => {
474
+ setGenerated(false)
475
+ onChange(e.target.value)
476
+ }}
391
477
  />
392
478
  {canEye && (
393
479
  <Button
@@ -427,8 +513,125 @@ function ConnectorCredentialFieldControl({
427
513
  ) : null}
428
514
  </div>
429
515
  )}
516
+ {isSecret && !isDynamic && field.type !== 'select' ? (
517
+ <div className='flex flex-col gap-2'>
518
+ <div className='flex flex-wrap items-center gap-2'>
519
+ {locked ? (
520
+ canManage ? (
521
+ <Button
522
+ type='button'
523
+ variant='outline'
524
+ size='sm'
525
+ className='h-11 gap-1.5 sm:h-8'
526
+ aria-expanded={confirmRotate}
527
+ onClick={() => setConfirmRotate(true)}
528
+ >
529
+ <RefreshCw aria-hidden='true' className='size-3.5' />
530
+ {st('secret.rotate')}
531
+ </Button>
532
+ ) : null
533
+ ) : (
534
+ <>
535
+ {canManage ? (
536
+ <Button
537
+ type='button'
538
+ variant='outline'
539
+ size='sm'
540
+ className='h-11 gap-1.5 sm:h-8'
541
+ onClick={generate}
542
+ >
543
+ <Sparkles aria-hidden='true' className='size-3.5' />
544
+ {generated ? st('secret.regenerate') : st('secret.generate')}
545
+ </Button>
546
+ ) : null}
547
+ {value !== '' ? (
548
+ <Button
549
+ type='button'
550
+ variant='outline'
551
+ size='sm'
552
+ className='h-11 gap-1.5 sm:h-8'
553
+ aria-label={st('blocks.copy_label', { what: st('secret.copy_what') })}
554
+ onClick={() => void copyValue()}
555
+ >
556
+ {copyState === 'copied' ? (
557
+ <Check aria-hidden='true' className='size-3.5' />
558
+ ) : (
559
+ <Copy aria-hidden='true' className='size-3.5' />
560
+ )}
561
+ {copyState === 'copied' ? st('records.copied') : st('secret.copy')}
562
+ </Button>
563
+ ) : null}
564
+ </>
565
+ )}
566
+ <span className='sr-only' role='status' aria-live='polite'>
567
+ {copyState === 'copied' ? st('records.copied') : copyState === 'failed' ? st('records.copy_failed') : ''}
568
+ </span>
569
+ </div>
570
+ {confirmRotate ? (
571
+ <div
572
+ role='group'
573
+ aria-labelledby={`${form.idPrefix}-rot-${field.key}`}
574
+ className='flex flex-col gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3'
575
+ >
576
+ <p id={`${form.idPrefix}-rot-${field.key}`} className='text-sm font-medium'>
577
+ {st('secret.rotate_title')}
578
+ </p>
579
+ <p className='text-xs text-muted-foreground'>{st('secret.rotate_body')}</p>
580
+ <div className='flex flex-wrap gap-2'>
581
+ <Button type='button' size='sm' className='h-11 sm:h-8' onClick={generate}>
582
+ {st('secret.rotate_confirm')}
583
+ </Button>
584
+ <Button
585
+ type='button'
586
+ size='sm'
587
+ variant='ghost'
588
+ className='h-11 sm:h-8'
589
+ autoFocus
590
+ onClick={() => setConfirmRotate(false)}
591
+ >
592
+ {st('secret.rotate_cancel')}
593
+ </Button>
594
+ </div>
595
+ </div>
596
+ ) : null}
597
+ {value !== '' && !locked ? (
598
+ <div className='flex items-center gap-2' data-strength={strength}>
599
+ <span aria-hidden='true' className='flex flex-1 gap-1'>
600
+ {[0, 1, 2].map((i) => (
601
+ <span
602
+ key={i}
603
+ className={cn(
604
+ 'h-1.5 flex-1 rounded-full transition-colors',
605
+ i <= (strength === 'strong' ? 2 : strength === 'fair' ? 1 : 0)
606
+ ? strength === 'strong'
607
+ ? 'bg-emerald-500'
608
+ : strength === 'fair'
609
+ ? 'bg-amber-500'
610
+ : 'bg-destructive'
611
+ : 'bg-muted',
612
+ )}
613
+ />
614
+ ))}
615
+ </span>
616
+ <span className='shrink-0 text-xs text-muted-foreground'>
617
+ {st('secret.strength')}: {st(`secret.strength_${strength === 'empty' ? 'weak' : strength}`)}
618
+ </span>
619
+ </div>
620
+ ) : null}
621
+ {generated && value !== '' ? (
622
+ <p role='status' className='text-xs text-emerald-700 dark:text-emerald-400'>
623
+ {st('secret.generated_hint')}
624
+ </p>
625
+ ) : null}
626
+ {genError ? (
627
+ <p role='alert' className='text-xs text-destructive'>
628
+ {st('secret.generate_unavailable')}
629
+ </p>
630
+ ) : null}
631
+ </div>
632
+ ) : null}
430
633
  {error ? (
431
- <p id={`${form.idPrefix}-cred-${field.key}-error`} role='alert' className='text-xs text-destructive'>
634
+ <p id={`${form.idPrefix}-cred-${field.key}-error`} role={form.errors[field.key] ? 'alert' : undefined} className='text-xs text-destructive'>
432
635
  {error}
433
636
  </p>
434
637
  ) : null}
@@ -437,7 +640,7 @@ function ConnectorCredentialFieldControl({
437
640
  {warning}
438
641
  </p>
439
642
  ) : null}
440
- {help ? <HelpText text={help} /> : null}
643
+ {help ? <FieldHelp text={help} /> : null}
441
644
  </div>
442
645
  )
443
646
  }
@@ -624,7 +827,9 @@ export function AddonConfigSurface({
624
827
  client,
625
828
  expectedOptionKinds = NO_OPTION_KINDS,
626
829
  displayName,
830
+ logo,
627
831
  onConnectOAuth,
832
+ version,
628
833
  }: AddonConfigSurfaceProps) {
629
834
  const idPrefix = useId()
630
835
  const { t, i18n } = useTranslation()
@@ -1038,6 +1243,21 @@ export function AddonConfigSurface({
1038
1243
  return
1039
1244
  }
1040
1245
  }
1246
+ const short = connector && canManageIssuer ? tooShortSecrets(activeFields, credValues) : []
1247
+ if (short.length > 0) {
1248
+ const errs: Record<string, string> = {}
1249
+ for (const x of short) {
1250
+ errs[x.key] = st('secret.too_short', { min: x.min, n: (credValues[x.key] ?? '').length })
1251
+ }
1252
+ setFieldErrors(errs)
1253
+ setFormError(
1254
+ st('secret.fix_fields', {
1255
+ fields: short.map((x) => credLabel(credFields.find((f) => f.key === x.key)!)).join(', '),
1256
+ }),
1257
+ )
1258
+ focusFirstInvalid(short.map((x) => x.key))
1259
+ return
1260
+ }
1041
1261
  setFieldErrors({})
1042
1262
  saveMutation.mutate()
1043
1263
  }
@@ -1056,6 +1276,13 @@ export function AddonConfigSurface({
1056
1276
  fields: miss.map((k) => credLabel(credFields.find((f) => f.key === k)!)).join(', '),
1057
1277
  })
1058
1278
  }
1279
+ const short = tooShortSecrets(activeFields, credValues)
1280
+ if (short.length > 0) {
1281
+ const errs: Record<string, string> = {}
1282
+ for (const x of short) errs[x.key] = st('secret.too_short', { min: x.min, n: (credValues[x.key] ?? '').length })
1283
+ setFieldErrors(errs)
1284
+ return st('secret.too_short', { min: short[0].min, n: (credValues[short[0].key] ?? '').length })
1285
+ }
1059
1286
  const payload: Record<string, string> = {}
1060
1287
  for (const [k, v] of Object.entries(credValues)) {
1061
1288
  if (v != null && v !== '' && isSendable(k)) payload[k] = v
@@ -1488,24 +1715,60 @@ export function AddonConfigSurface({
1488
1715
  ? 'saved'
1489
1716
  : 'clean'
1490
1717
 
1718
+ // Closing with unsaved edits asks first (Esc, overlay click, X and Cancelar
1719
+ // all land here); a save in flight never closes the dialog under it.
1720
+ const [confirmDiscard, setConfirmDiscard] = useState(false)
1721
+ const keepEditingRef = useRef<HTMLButtonElement>(null)
1722
+ useEffect(() => {
1723
+ if (!open) setConfirmDiscard(false)
1724
+ }, [open])
1725
+ useEffect(() => {
1726
+ if (confirmDiscard) keepEditingRef.current?.focus()
1727
+ }, [confirmDiscard])
1728
+ const requestClose = (next: boolean) => {
1729
+ if (next) return onOpenChange(true)
1730
+ if (saveMutation.isPending) return
1731
+ if (dirty) return setConfirmDiscard(true)
1732
+ onOpenChange(false)
1733
+ }
1734
+
1735
+ const headerVersion = version ?? addon.manifest.version
1736
+ const configured = connector ? !!connector.connected : null
1737
+
1491
1738
  const hasAnyBlocks = layoutSections.some((s) => (s.blocks?.length ?? 0) > 0) || extraBlocks.length > 0
1492
1739
  const nothingToConfigure =
1493
1740
  !hasCredentials && !hasSettings && !isOAuth && !hasAnyBlocks && autoFields.length === 0
1494
1741
  const nothingToSave = !hasCredentials && !hasSettings
1495
1742
 
1496
1743
  return (
1497
- <Dialog open={open} onOpenChange={onOpenChange}>
1744
+ <Dialog open={open} onOpenChange={requestClose}>
1498
1745
  <DialogContent className='flex max-h-[85vh] flex-col max-sm:max-h-[calc(100dvh-1rem)] max-sm:gap-3 max-sm:p-4'>
1499
1746
  <ConnectorFormStateContext.Provider
1500
- value={{ fields: credFields, errors: fieldErrors, idPrefix, client: api, expectedOptionKinds, reloadNonce }}
1747
+ value={{ fields: credFields, errors: fieldErrors, idPrefix, client: api, expectedOptionKinds, reloadNonce, canManage: canManageIssuer }}
1501
1748
  >
1502
1749
  <DialogHeader className='shrink-0 pe-8 text-start'>
1503
- <DialogTitle className='leading-snug'>
1504
- {st('installed_addons.configure_title', { name: displayName ?? addon.manifest.display_name ?? addon.manifest.name })}
1505
- </DialogTitle>
1506
- <DialogDescription>
1507
- {st('installed_addons.configure_description')}
1508
- </DialogDescription>
1750
+ <div className='flex items-center gap-3'>
1751
+ {logo}
1752
+ <div className='flex min-w-0 flex-1 flex-col gap-1'>
1753
+ <DialogTitle className='leading-snug break-words'>
1754
+ {st('installed_addons.configure_title', { name: displayName ?? addon.manifest.display_name ?? addon.manifest.name })}
1755
+ </DialogTitle>
1756
+ <div className='flex flex-wrap items-center gap-2'>
1757
+ {headerVersion ? (
1758
+ <Badge variant='outline' className='text-[10px] tabular-nums'>
1759
+ {st('header.version', { version: String(headerVersion).replace(/^v/i, '') })}
1760
+ </Badge>
1761
+ ) : null}
1762
+ {configured !== null ? (
1763
+ <StepStatusBadge
1764
+ status={configured ? 'ok' : 'pending'}
1765
+ label={configured ? st('header.configured') : st('header.pending')}
1766
+ />
1767
+ ) : null}
1768
+ </div>
1769
+ </div>
1770
+ </div>
1771
+ <DialogDescription className='sr-only'>{st('header.description')}</DialogDescription>
1509
1772
  </DialogHeader>
1510
1773
 
1511
1774
  <div className='-mr-2 flex min-h-0 flex-col gap-6 overflow-y-auto py-2 pr-2'>
@@ -1756,7 +2019,25 @@ export function AddonConfigSurface({
1756
2019
  data-wizard-footer=''
1757
2020
  className='flex shrink-0 flex-col gap-2 border-t pt-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between sm:space-x-0'
1758
2021
  >
1759
- {nothingToSave && !useStepper ? (
2022
+ {confirmDiscard ? (
2023
+ <div
2024
+ role='alertdialog'
2025
+ aria-labelledby={`${idPrefix}-discard`}
2026
+ className='flex w-full flex-col gap-2 sm:flex-row sm:items-center sm:justify-between'
2027
+ >
2028
+ <p id={`${idPrefix}-discard`} className='text-sm font-medium'>
2029
+ {st('discard.title')}
2030
+ </p>
2031
+ <div className='flex flex-wrap gap-2 sm:justify-end'>
2032
+ <Button ref={keepEditingRef} className='h-11 sm:h-9' onClick={() => setConfirmDiscard(false)}>
2033
+ {st('discard.keep')}
2034
+ </Button>
2035
+ <Button variant='outline' className='h-11 sm:h-9' onClick={() => onOpenChange(false)}>
2036
+ {st('discard.confirm')}
2037
+ </Button>
2038
+ </div>
2039
+ </div>
2040
+ ) : nothingToSave && !useStepper ? (
1760
2041
  <Button className='h-11 w-full sm:ml-auto sm:h-9 sm:w-auto' onClick={() => onOpenChange(false)}>
1761
2042
  {st('common.close')}
1762
2043
  </Button>
@@ -1785,7 +2066,7 @@ export function AddonConfigSurface({
1785
2066
  {st(`form.status_${saveStatus}`)}
1786
2067
  </p>
1787
2068
  <div className='flex flex-wrap items-center gap-2 sm:ml-auto sm:flex-nowrap sm:justify-end'>
1788
- <Button variant='ghost' className='h-11 px-3 sm:h-9' onClick={() => onOpenChange(false)}>
2069
+ <Button variant='ghost' className='h-11 px-3 sm:h-9' onClick={() => requestClose(false)}>
1789
2070
  {dirty ? st('common.cancel') : st('common.close')}
1790
2071
  </Button>
1791
2072
  {useStepper && stepIdx > 0 && (
@@ -170,6 +170,31 @@ export const SETUP_MESSAGES_ES: Dict = {
170
170
  'form.status_dirty': 'Cambios sin guardar',
171
171
  'form.status_saved': 'Guardado',
172
172
  'form.status_saving': 'Guardando…',
173
+ 'header.description': 'Credenciales y ajustes de este addon.',
174
+ 'header.version': 'v{{version}}',
175
+ 'header.configured': 'Configurado',
176
+ 'header.pending': 'Por configurar',
177
+ 'secret.fix_fields': 'Revisa estos campos: {{fields}}.',
178
+ 'secret.generate': 'Generar',
179
+ 'secret.regenerate': 'Generar otra',
180
+ 'secret.rotate': 'Rotar',
181
+ 'secret.rotate_title': '¿Rotar esta clave?',
182
+ 'secret.rotate_body': 'Se reemplaza la clave actual. Lo que la use dejará de funcionar hasta que le pongas la nueva.',
183
+ 'secret.rotate_confirm': 'Sí, rotar',
184
+ 'secret.rotate_cancel': 'Cancelar',
185
+ 'secret.copy': 'Copiar',
186
+ 'secret.copy_what': 'la clave',
187
+ 'secret.generated_hint': 'Clave generada. Cópiala y guarda para activarla.',
188
+ 'secret.generate_unavailable': 'Tu navegador no permite generar claves seguras.',
189
+ 'secret.strength': 'Fuerza',
190
+ 'secret.strength_weak': 'Débil',
191
+ 'secret.strength_fair': 'Aceptable',
192
+ 'secret.strength_strong': 'Fuerte',
193
+ 'secret.too_short': 'Mínimo {{min}} caracteres (llevas {{n}}).',
194
+ 'secret.how_to_use': 'Cómo se usa',
195
+ 'discard.title': '¿Descartar los cambios sin guardar?',
196
+ 'discard.keep': 'Seguir editando',
197
+ 'discard.confirm': 'Descartar',
173
198
  }
174
199
 
175
200
  export const SETUP_MESSAGES_EN: Dict = {
@@ -333,6 +358,31 @@ export const SETUP_MESSAGES_EN: Dict = {
333
358
  'form.status_dirty': 'Unsaved changes',
334
359
  'form.status_saved': 'Saved',
335
360
  'form.status_saving': 'Saving…',
361
+ 'header.description': 'Credentials and settings for this addon.',
362
+ 'header.version': 'v{{version}}',
363
+ 'header.configured': 'Configured',
364
+ 'header.pending': 'Not configured',
365
+ 'secret.fix_fields': 'Check these fields: {{fields}}.',
366
+ 'secret.generate': 'Generate',
367
+ 'secret.regenerate': 'Generate another',
368
+ 'secret.rotate': 'Rotate',
369
+ 'secret.rotate_title': 'Rotate this key?',
370
+ 'secret.rotate_body': 'The current key is replaced. Anything using it stops working until you give it the new one.',
371
+ 'secret.rotate_confirm': 'Yes, rotate',
372
+ 'secret.rotate_cancel': 'Cancel',
373
+ 'secret.copy': 'Copy',
374
+ 'secret.copy_what': 'the key',
375
+ 'secret.generated_hint': 'Key generated. Copy it and save to activate it.',
376
+ 'secret.generate_unavailable': 'Your browser cannot generate secure keys.',
377
+ 'secret.strength': 'Strength',
378
+ 'secret.strength_weak': 'Weak',
379
+ 'secret.strength_fair': 'Fair',
380
+ 'secret.strength_strong': 'Strong',
381
+ 'secret.too_short': 'At least {{min}} characters ({{n}} so far).',
382
+ 'secret.how_to_use': 'How it is used',
383
+ 'discard.title': 'Discard unsaved changes?',
384
+ 'discard.keep': 'Keep editing',
385
+ 'discard.confirm': 'Discard',
336
386
  }
337
387
 
338
388
  export type TFn = (key: string, vars?: Record<string, unknown>) => string
@@ -0,0 +1,67 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ generateSecret,
4
+ generatedLength,
5
+ secretMinLength,
6
+ secretStrength,
7
+ splitHelp,
8
+ tooShortSecrets,
9
+ } from './secret-field-model'
10
+
11
+ describe('secretMinLength', () => {
12
+ it('reads named hints and the .{N,} regex', () => {
13
+ expect(secretMinLength({ key: 'k', validation: 'min_length:48' })).toBe(48)
14
+ expect(secretMinLength({ key: 'k', validation: 'minlength=32' })).toBe(32)
15
+ expect(secretMinLength({ key: 'k', validation: '^.{40,}$' })).toBe(40)
16
+ expect(secretMinLength({ key: 'k', validation: 'email' })).toBe(0)
17
+ expect(secretMinLength({ key: 'k' })).toBe(0)
18
+ })
19
+ it('generates at least the declared minimum, default 32, capped', () => {
20
+ expect(generatedLength({ key: 'k' })).toBe(32)
21
+ expect(generatedLength({ key: 'k', validation: 'min_length:64' })).toBe(64)
22
+ expect(generatedLength({ key: 'k', validation: 'min_length:9999' })).toBe(128)
23
+ })
24
+ })
25
+
26
+ describe('generateSecret', () => {
27
+ it('uses crypto.getRandomValues and yields the requested length over the alphabet', () => {
28
+ const s = generateSecret(48)
29
+ expect(s).toHaveLength(48)
30
+ expect(s).toMatch(/^[A-Za-z0-9]+$/)
31
+ expect(generateSecret(48)).not.toBe(s)
32
+ })
33
+ it('rejects biased bytes (>= 248) instead of wrapping them', () => {
34
+ let calls = 0
35
+ const src = {
36
+ getRandomValues: <T extends ArrayBufferView | null>(a: T): T => {
37
+ const u = a as unknown as Uint8Array
38
+ u.fill(calls++ === 0 ? 255 : 1)
39
+ return a
40
+ },
41
+ }
42
+ expect(generateSecret(4, src as Crypto)).toBe('BBBB')
43
+ })
44
+ it('throws without a CSPRNG', () => {
45
+ expect(() => generateSecret(8, {} as Crypto)).toThrow()
46
+ })
47
+ })
48
+
49
+ describe('secretStrength / tooShortSecrets / splitHelp', () => {
50
+ it('grades by length against the minimum', () => {
51
+ expect(secretStrength('')).toBe('empty')
52
+ expect(secretStrength('abc123')).toBe('weak')
53
+ expect(secretStrength(generateSecret(32), 32)).toBe('strong')
54
+ expect(secretStrength('aB3dE6gH9jK2mN5pQ8', 32)).toBe('weak')
55
+ })
56
+ it('flags only non-empty secrets under the minimum', () => {
57
+ const f = [{ key: 'a', type: 'secret', validation: 'min_length:32' }, { key: 'b', validation: 'min_length:8' }]
58
+ expect(tooShortSecrets(f, { a: 'short', b: 'x' })).toEqual([{ key: 'a', min: 32 }])
59
+ expect(tooShortSecrets(f, { a: '' })).toEqual([])
60
+ })
61
+ it('splits a long help into lead + technical detail', () => {
62
+ const r = splitHelp('Secreto de al menos 32 caracteres aleatorios; la tienda lo manda como Bearer a /submit_review y /list_reviews')
63
+ expect(r.lead).toBe('Secreto de al menos 32 caracteres aleatorios')
64
+ expect(r.detail).toMatch(/^la tienda/)
65
+ expect(splitHelp('Corto.')).toEqual({ lead: 'Corto.', detail: '' })
66
+ })
67
+ })