@asteby/metacore-runtime-react 53.20.1 → 53.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) 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/genui/index.d.ts +2 -0
  15. package/dist/genui/index.d.ts.map +1 -0
  16. package/dist/genui/index.js +1 -0
  17. package/dist/genui/settings-block.d.ts +31 -0
  18. package/dist/genui/settings-block.d.ts.map +1 -0
  19. package/dist/genui/settings-block.js +100 -0
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +2 -0
  23. package/dist/setup/addon-config-surface.d.ts +14 -1
  24. package/dist/setup/addon-config-surface.d.ts.map +1 -1
  25. package/dist/setup/addon-config-surface.js +116 -6
  26. package/dist/setup/messages.d.ts.map +1 -1
  27. package/dist/setup/messages.js +50 -0
  28. package/dist/setup/secret-field-model.d.ts +47 -0
  29. package/dist/setup/secret-field-model.d.ts.map +1 -0
  30. package/dist/setup/secret-field-model.js +95 -0
  31. package/dist/view-system/card-spec.d.ts +24 -0
  32. package/dist/view-system/card-spec.d.ts.map +1 -0
  33. package/dist/view-system/card-spec.js +40 -0
  34. package/dist/view-system/cards-view.d.ts +17 -0
  35. package/dist/view-system/cards-view.d.ts.map +1 -0
  36. package/dist/view-system/cards-view.js +37 -0
  37. package/dist/view-system/index.d.ts +10 -0
  38. package/dist/view-system/index.d.ts.map +1 -0
  39. package/dist/view-system/index.js +9 -0
  40. package/dist/view-system/model-view.d.ts +31 -0
  41. package/dist/view-system/model-view.d.ts.map +1 -0
  42. package/dist/view-system/model-view.js +50 -0
  43. package/dist/view-system/saved-views.d.ts +22 -0
  44. package/dist/view-system/saved-views.d.ts.map +1 -0
  45. package/dist/view-system/saved-views.js +53 -0
  46. package/dist/view-system/types.d.ts +63 -0
  47. package/dist/view-system/types.d.ts.map +1 -0
  48. package/dist/view-system/types.js +1 -0
  49. package/dist/view-system/use-view-mode.d.ts +26 -0
  50. package/dist/view-system/use-view-mode.d.ts.map +1 -0
  51. package/dist/view-system/use-view-mode.js +60 -0
  52. package/dist/view-system/view-state.d.ts +19 -0
  53. package/dist/view-system/view-state.d.ts.map +1 -0
  54. package/dist/view-system/view-state.js +66 -0
  55. package/dist/view-system/view-switcher.d.ts +14 -0
  56. package/dist/view-system/view-switcher.d.ts.map +1 -0
  57. package/dist/view-system/view-switcher.js +26 -0
  58. package/dist/view-system/view-toolbar.d.ts +19 -0
  59. package/dist/view-system/view-toolbar.d.ts.map +1 -0
  60. package/dist/view-system/view-toolbar.js +33 -0
  61. package/package.json +14 -5
  62. package/src/__tests__/addon-config-surface.test.tsx +67 -1
  63. package/src/__tests__/attention-view-system.test.tsx +128 -0
  64. package/src/__tests__/dynamic-table-bulk-delete-reasons.test.tsx +6 -1
  65. package/src/__tests__/genui-settings-block.test.tsx +73 -0
  66. package/src/attention/apply-nav-badges.ts +42 -0
  67. package/src/attention/index.ts +11 -0
  68. package/src/attention/use-document-attention.ts +62 -0
  69. package/src/attention/use-nav-badges.ts +94 -0
  70. package/src/genui/index.ts +1 -0
  71. package/src/genui/settings-block.tsx +123 -0
  72. package/src/index.ts +2 -0
  73. package/src/setup/addon-config-surface.tsx +303 -16
  74. package/src/setup/messages.ts +50 -0
  75. package/src/setup/secret-field-model.test.ts +67 -0
  76. package/src/setup/secret-field-model.ts +104 -0
  77. package/src/view-system/card-spec.tsx +78 -0
  78. package/src/view-system/cards-view.tsx +61 -0
  79. package/src/view-system/index.ts +9 -0
  80. package/src/view-system/model-view.tsx +105 -0
  81. package/src/view-system/saved-views.ts +66 -0
  82. package/src/view-system/types.ts +63 -0
  83. package/src/view-system/use-view-mode.ts +79 -0
  84. package/src/view-system/view-state.ts +61 -0
  85. package/src/view-system/view-switcher.tsx +53 -0
  86. package/src/view-system/view-toolbar.tsx +119 -0
@@ -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,26 @@ 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
334
+ // Reset only when the environment actually CHANGES. Running on mount too would queue
335
+ // setConfirmRotate(false)/setGenerated(false) behind a click that lands before the mount
336
+ // effects flush, silently discarding the user's action (flaky under load).
337
+ const lastResetKey = useRef(resetKey)
284
338
  useEffect(() => {
339
+ if (lastResetKey.current === resetKey) return
340
+ lastResetKey.current = resetKey
285
341
  setEditing(false)
286
342
  setVisible(false)
287
343
  setRevealed(null)
344
+ setConfirmRotate(false)
345
+ setGenerated(false)
288
346
  }, [resetKey])
289
347
  const canEye = isSecret ? (locked ? !!onReveal : true) : false
290
348
  const toggleEye = async () => {
@@ -320,8 +378,39 @@ function ConnectorCredentialFieldControl({
320
378
  onChange(initial.current)
321
379
  setVisible(false)
322
380
  setEditing(false)
381
+ setGenerated(false)
382
+ }
383
+ // Generate: a CSPRNG value at least as long as the manifest's minimum, shown
384
+ // so it can be copied before saving. Rotating a STORED secret goes through
385
+ // an explicit confirmation first (confirmRotate).
386
+ const minLen = isSecret ? secretMinLength(field) : 0
387
+ const generate = () => {
388
+ try {
389
+ const next = generateSecret(generatedLength(field))
390
+ if (stored && !editing) {
391
+ initial.current = value
392
+ setEditing(true)
393
+ }
394
+ setArmed(true)
395
+ setVisible(true)
396
+ setRevealed(null)
397
+ setGenerated(true)
398
+ setGenError(false)
399
+ setConfirmRotate(false)
400
+ onChange(next)
401
+ } catch {
402
+ setGenError(true)
403
+ }
404
+ }
405
+ const copyValue = async () => {
406
+ const ok = await copyText(value)
407
+ setCopyState(ok ? 'copied' : 'failed')
408
+ clearTimeout(copyTimer.current)
409
+ copyTimer.current = setTimeout(() => setCopyState('idle'), 2500)
323
410
  }
324
- const error = form.errors[field.key]
411
+ const strength = isSecret ? secretStrength(value, minLen) : 'empty'
412
+ const shortBy = isSecret && minLen > 0 && value !== '' && value.length < minLen
413
+ const error = form.errors[field.key] ?? (shortBy ? st('secret.too_short', { min: minLen, n: value.length }) : undefined)
325
414
  const mismatch = shapeMismatch(field, value, form.fields)
326
415
  const target = mismatch?.suggestedKey
327
416
  ? form.fields.find((f) => f.key === mismatch.suggestedKey)
@@ -387,7 +476,10 @@ function ConnectorCredentialFieldControl({
387
476
  )}
388
477
  placeholder={(connected || stored) && isSecret ? '••••••••' : ''}
389
478
  value={locked && isSecret ? (revealed ?? '') : value}
390
- onChange={(e) => onChange(e.target.value)}
479
+ onChange={(e) => {
480
+ setGenerated(false)
481
+ onChange(e.target.value)
482
+ }}
391
483
  />
392
484
  {canEye && (
393
485
  <Button
@@ -427,8 +519,125 @@ function ConnectorCredentialFieldControl({
427
519
  ) : null}
428
520
  </div>
429
521
  )}
522
+ {isSecret && !isDynamic && field.type !== 'select' ? (
523
+ <div className='flex flex-col gap-2'>
524
+ <div className='flex flex-wrap items-center gap-2'>
525
+ {locked ? (
526
+ canManage ? (
527
+ <Button
528
+ type='button'
529
+ variant='outline'
530
+ size='sm'
531
+ className='h-11 gap-1.5 sm:h-8'
532
+ aria-expanded={confirmRotate}
533
+ onClick={() => setConfirmRotate(true)}
534
+ >
535
+ <RefreshCw aria-hidden='true' className='size-3.5' />
536
+ {st('secret.rotate')}
537
+ </Button>
538
+ ) : null
539
+ ) : (
540
+ <>
541
+ {canManage ? (
542
+ <Button
543
+ type='button'
544
+ variant='outline'
545
+ size='sm'
546
+ className='h-11 gap-1.5 sm:h-8'
547
+ onClick={generate}
548
+ >
549
+ <Sparkles aria-hidden='true' className='size-3.5' />
550
+ {generated ? st('secret.regenerate') : st('secret.generate')}
551
+ </Button>
552
+ ) : null}
553
+ {value !== '' ? (
554
+ <Button
555
+ type='button'
556
+ variant='outline'
557
+ size='sm'
558
+ className='h-11 gap-1.5 sm:h-8'
559
+ aria-label={st('blocks.copy_label', { what: st('secret.copy_what') })}
560
+ onClick={() => void copyValue()}
561
+ >
562
+ {copyState === 'copied' ? (
563
+ <Check aria-hidden='true' className='size-3.5' />
564
+ ) : (
565
+ <Copy aria-hidden='true' className='size-3.5' />
566
+ )}
567
+ {copyState === 'copied' ? st('records.copied') : st('secret.copy')}
568
+ </Button>
569
+ ) : null}
570
+ </>
571
+ )}
572
+ <span className='sr-only' role='status' aria-live='polite'>
573
+ {copyState === 'copied' ? st('records.copied') : copyState === 'failed' ? st('records.copy_failed') : ''}
574
+ </span>
575
+ </div>
576
+ {confirmRotate ? (
577
+ <div
578
+ role='group'
579
+ aria-labelledby={`${form.idPrefix}-rot-${field.key}`}
580
+ className='flex flex-col gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 p-3'
581
+ >
582
+ <p id={`${form.idPrefix}-rot-${field.key}`} className='text-sm font-medium'>
583
+ {st('secret.rotate_title')}
584
+ </p>
585
+ <p className='text-xs text-muted-foreground'>{st('secret.rotate_body')}</p>
586
+ <div className='flex flex-wrap gap-2'>
587
+ <Button type='button' size='sm' className='h-11 sm:h-8' onClick={generate}>
588
+ {st('secret.rotate_confirm')}
589
+ </Button>
590
+ <Button
591
+ type='button'
592
+ size='sm'
593
+ variant='ghost'
594
+ className='h-11 sm:h-8'
595
+ autoFocus
596
+ onClick={() => setConfirmRotate(false)}
597
+ >
598
+ {st('secret.rotate_cancel')}
599
+ </Button>
600
+ </div>
601
+ </div>
602
+ ) : null}
603
+ {value !== '' && !locked ? (
604
+ <div className='flex items-center gap-2' data-strength={strength}>
605
+ <span aria-hidden='true' className='flex flex-1 gap-1'>
606
+ {[0, 1, 2].map((i) => (
607
+ <span
608
+ key={i}
609
+ className={cn(
610
+ 'h-1.5 flex-1 rounded-full transition-colors',
611
+ i <= (strength === 'strong' ? 2 : strength === 'fair' ? 1 : 0)
612
+ ? strength === 'strong'
613
+ ? 'bg-emerald-500'
614
+ : strength === 'fair'
615
+ ? 'bg-amber-500'
616
+ : 'bg-destructive'
617
+ : 'bg-muted',
618
+ )}
619
+ />
620
+ ))}
621
+ </span>
622
+ <span className='shrink-0 text-xs text-muted-foreground'>
623
+ {st('secret.strength')}: {st(`secret.strength_${strength === 'empty' ? 'weak' : strength}`)}
624
+ </span>
625
+ </div>
626
+ ) : null}
627
+ {generated && value !== '' ? (
628
+ <p role='status' className='text-xs text-emerald-700 dark:text-emerald-400'>
629
+ {st('secret.generated_hint')}
630
+ </p>
631
+ ) : null}
632
+ {genError ? (
633
+ <p role='alert' className='text-xs text-destructive'>
634
+ {st('secret.generate_unavailable')}
635
+ </p>
636
+ ) : null}
637
+ </div>
638
+ ) : null}
430
639
  {error ? (
431
- <p id={`${form.idPrefix}-cred-${field.key}-error`} role='alert' className='text-xs text-destructive'>
640
+ <p id={`${form.idPrefix}-cred-${field.key}-error`} role={form.errors[field.key] ? 'alert' : undefined} className='text-xs text-destructive'>
432
641
  {error}
433
642
  </p>
434
643
  ) : null}
@@ -437,7 +646,7 @@ function ConnectorCredentialFieldControl({
437
646
  {warning}
438
647
  </p>
439
648
  ) : null}
440
- {help ? <HelpText text={help} /> : null}
649
+ {help ? <FieldHelp text={help} /> : null}
441
650
  </div>
442
651
  )
443
652
  }
@@ -624,7 +833,9 @@ export function AddonConfigSurface({
624
833
  client,
625
834
  expectedOptionKinds = NO_OPTION_KINDS,
626
835
  displayName,
836
+ logo,
627
837
  onConnectOAuth,
838
+ version,
628
839
  }: AddonConfigSurfaceProps) {
629
840
  const idPrefix = useId()
630
841
  const { t, i18n } = useTranslation()
@@ -1038,6 +1249,21 @@ export function AddonConfigSurface({
1038
1249
  return
1039
1250
  }
1040
1251
  }
1252
+ const short = connector && canManageIssuer ? tooShortSecrets(activeFields, credValues) : []
1253
+ if (short.length > 0) {
1254
+ const errs: Record<string, string> = {}
1255
+ for (const x of short) {
1256
+ errs[x.key] = st('secret.too_short', { min: x.min, n: (credValues[x.key] ?? '').length })
1257
+ }
1258
+ setFieldErrors(errs)
1259
+ setFormError(
1260
+ st('secret.fix_fields', {
1261
+ fields: short.map((x) => credLabel(credFields.find((f) => f.key === x.key)!)).join(', '),
1262
+ }),
1263
+ )
1264
+ focusFirstInvalid(short.map((x) => x.key))
1265
+ return
1266
+ }
1041
1267
  setFieldErrors({})
1042
1268
  saveMutation.mutate()
1043
1269
  }
@@ -1056,6 +1282,13 @@ export function AddonConfigSurface({
1056
1282
  fields: miss.map((k) => credLabel(credFields.find((f) => f.key === k)!)).join(', '),
1057
1283
  })
1058
1284
  }
1285
+ const short = tooShortSecrets(activeFields, credValues)
1286
+ if (short.length > 0) {
1287
+ const errs: Record<string, string> = {}
1288
+ for (const x of short) errs[x.key] = st('secret.too_short', { min: x.min, n: (credValues[x.key] ?? '').length })
1289
+ setFieldErrors(errs)
1290
+ return st('secret.too_short', { min: short[0].min, n: (credValues[short[0].key] ?? '').length })
1291
+ }
1059
1292
  const payload: Record<string, string> = {}
1060
1293
  for (const [k, v] of Object.entries(credValues)) {
1061
1294
  if (v != null && v !== '' && isSendable(k)) payload[k] = v
@@ -1488,24 +1721,60 @@ export function AddonConfigSurface({
1488
1721
  ? 'saved'
1489
1722
  : 'clean'
1490
1723
 
1724
+ // Closing with unsaved edits asks first (Esc, overlay click, X and Cancelar
1725
+ // all land here); a save in flight never closes the dialog under it.
1726
+ const [confirmDiscard, setConfirmDiscard] = useState(false)
1727
+ const keepEditingRef = useRef<HTMLButtonElement>(null)
1728
+ useEffect(() => {
1729
+ if (!open) setConfirmDiscard(false)
1730
+ }, [open])
1731
+ useEffect(() => {
1732
+ if (confirmDiscard) keepEditingRef.current?.focus()
1733
+ }, [confirmDiscard])
1734
+ const requestClose = (next: boolean) => {
1735
+ if (next) return onOpenChange(true)
1736
+ if (saveMutation.isPending) return
1737
+ if (dirty) return setConfirmDiscard(true)
1738
+ onOpenChange(false)
1739
+ }
1740
+
1741
+ const headerVersion = version ?? addon.manifest.version
1742
+ const configured = connector ? !!connector.connected : null
1743
+
1491
1744
  const hasAnyBlocks = layoutSections.some((s) => (s.blocks?.length ?? 0) > 0) || extraBlocks.length > 0
1492
1745
  const nothingToConfigure =
1493
1746
  !hasCredentials && !hasSettings && !isOAuth && !hasAnyBlocks && autoFields.length === 0
1494
1747
  const nothingToSave = !hasCredentials && !hasSettings
1495
1748
 
1496
1749
  return (
1497
- <Dialog open={open} onOpenChange={onOpenChange}>
1750
+ <Dialog open={open} onOpenChange={requestClose}>
1498
1751
  <DialogContent className='flex max-h-[85vh] flex-col max-sm:max-h-[calc(100dvh-1rem)] max-sm:gap-3 max-sm:p-4'>
1499
1752
  <ConnectorFormStateContext.Provider
1500
- value={{ fields: credFields, errors: fieldErrors, idPrefix, client: api, expectedOptionKinds, reloadNonce }}
1753
+ value={{ fields: credFields, errors: fieldErrors, idPrefix, client: api, expectedOptionKinds, reloadNonce, canManage: canManageIssuer }}
1501
1754
  >
1502
1755
  <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>
1756
+ <div className='flex items-center gap-3'>
1757
+ {logo}
1758
+ <div className='flex min-w-0 flex-1 flex-col gap-1'>
1759
+ <DialogTitle className='leading-snug break-words'>
1760
+ {st('installed_addons.configure_title', { name: displayName ?? addon.manifest.display_name ?? addon.manifest.name })}
1761
+ </DialogTitle>
1762
+ <div className='flex flex-wrap items-center gap-2'>
1763
+ {headerVersion ? (
1764
+ <Badge variant='outline' className='text-[10px] tabular-nums'>
1765
+ {st('header.version', { version: String(headerVersion).replace(/^v/i, '') })}
1766
+ </Badge>
1767
+ ) : null}
1768
+ {configured !== null ? (
1769
+ <StepStatusBadge
1770
+ status={configured ? 'ok' : 'pending'}
1771
+ label={configured ? st('header.configured') : st('header.pending')}
1772
+ />
1773
+ ) : null}
1774
+ </div>
1775
+ </div>
1776
+ </div>
1777
+ <DialogDescription className='sr-only'>{st('header.description')}</DialogDescription>
1509
1778
  </DialogHeader>
1510
1779
 
1511
1780
  <div className='-mr-2 flex min-h-0 flex-col gap-6 overflow-y-auto py-2 pr-2'>
@@ -1756,7 +2025,25 @@ export function AddonConfigSurface({
1756
2025
  data-wizard-footer=''
1757
2026
  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
2027
  >
1759
- {nothingToSave && !useStepper ? (
2028
+ {confirmDiscard ? (
2029
+ <div
2030
+ role='alertdialog'
2031
+ aria-labelledby={`${idPrefix}-discard`}
2032
+ className='flex w-full flex-col gap-2 sm:flex-row sm:items-center sm:justify-between'
2033
+ >
2034
+ <p id={`${idPrefix}-discard`} className='text-sm font-medium'>
2035
+ {st('discard.title')}
2036
+ </p>
2037
+ <div className='flex flex-wrap gap-2 sm:justify-end'>
2038
+ <Button ref={keepEditingRef} className='h-11 sm:h-9' onClick={() => setConfirmDiscard(false)}>
2039
+ {st('discard.keep')}
2040
+ </Button>
2041
+ <Button variant='outline' className='h-11 sm:h-9' onClick={() => onOpenChange(false)}>
2042
+ {st('discard.confirm')}
2043
+ </Button>
2044
+ </div>
2045
+ </div>
2046
+ ) : nothingToSave && !useStepper ? (
1760
2047
  <Button className='h-11 w-full sm:ml-auto sm:h-9 sm:w-auto' onClick={() => onOpenChange(false)}>
1761
2048
  {st('common.close')}
1762
2049
  </Button>
@@ -1785,7 +2072,7 @@ export function AddonConfigSurface({
1785
2072
  {st(`form.status_${saveStatus}`)}
1786
2073
  </p>
1787
2074
  <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)}>
2075
+ <Button variant='ghost' className='h-11 px-3 sm:h-9' onClick={() => requestClose(false)}>
1789
2076
  {dirty ? st('common.cancel') : st('common.close')}
1790
2077
  </Button>
1791
2078
  {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
+ })