@asteby/metacore-runtime-react 53.10.1 → 53.10.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @asteby/metacore-runtime-react
2
2
 
3
+ ## 53.10.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 8836f74: `AddonConfigSurface`: un campo de credencial oculto por `visible_when` (propio o de su sección de `form_layout`) ya nunca es obligatorio, no se valida, no cuenta en el estado de error del paso y no se envía. Antes se validaban TODOS los campos declarados: un conector con proveedores condicionales (connector_email con Resend/SendGrid/Mailgun) pedía la API key de SendGrid al guardar con Resend. Las secciones con `visible_when` también desaparecen como pasos del asistente, y el mensaje de error nombra solo campos aplicables. Helpers puros nuevos: `applicableFields`, `visibleSections`, `predicateHolds`.
8
+
3
9
  ## 53.10.1
4
10
 
5
11
  ### Patch Changes
@@ -42,9 +42,15 @@ export interface ConnectorCredentialField {
42
42
  }[];
43
43
  options_source?: string;
44
44
  section?: string;
45
+ /** Shown only while a sibling credential has this value (kernel Setting.visible_when). */
46
+ visible_when?: VisibleWhen;
47
+ visibleWhen?: VisibleWhen;
45
48
  }
46
49
  export interface ConnectorFormLayoutSection {
47
50
  key: string;
51
+ /** Hides the whole section (and its fields) while false. */
52
+ visible_when?: VisibleWhen;
53
+ visibleWhen?: VisibleWhen;
48
54
  title?: string;
49
55
  description?: string;
50
56
  /** Setup blocks (webhook_url / instructions / action), host-filled. */
@@ -1 +1 @@
1
- {"version":3,"file":"addon-config-surface.d.ts","sourceRoot":"","sources":["../../src/setup/addon-config-surface.tsx"],"names":[],"mappings":"AAsCA,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAI3C,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAA;AASjC,MAAM,WAAW,eAAe;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AA;IACvB,SAAS,EAAE,cAAc,GAAG,IAAI,CAAA;IAChC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,oFAAoF;IACpF,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IACnD,4EAA4E;IAC5E,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAChF,+BAA+B;IAC/B,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,uCAAuC;IACvC,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5C,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,KAAK,IAAI,CAAA;CACrD;AAmQD,6EAA6E;AAC7E,wBAAgB,yBAAyB,SAExC;AA0JD,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,SAAS,EACT,IAAI,EACJ,YAAY,EACZ,OAAO,EACP,eAAsB,EACtB,gBAAwB,EACxB,YAAmB,EACnB,iBAAiB,EACjB,MAAc,EACd,MAAM,EACN,mBAAqC,EACrC,WAAW,EACX,cAAc,GACf,EAAE,uBAAuB,+BAulCzB"}
@@ -26,7 +26,7 @@ import { useSetupT } from './messages';
26
26
  import { StepStatusBadge } from './step-status-badge';
27
27
  import { ConnectorBlocks, HelpText } from './connector-blocks';
28
28
  import { buildWizardSteps, errorMessage, hasExplicitTest, normalizeBlockResult, stepStatus, } from './connector-blocks-model';
29
- import { isSecretCredential, missingRequired, parseSaveError, shapeMismatch, textOrFallback, } from './connector-form-model';
29
+ import { isSecretCredential, missingRequired, applicableFields, visibleSections, parseSaveError, shapeMismatch, textOrFallback, } from './connector-form-model';
30
30
  // Empty write_only value (typed then erased) must not overwrite the stored secret.
31
31
  const isBlank = (v) => v == null || (typeof v === 'string' && v.trim() === '');
32
32
  const NO_OPTION_KINDS = {};
@@ -236,8 +236,6 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
236
236
  clearConnectorLookupCache();
237
237
  }, [open]);
238
238
  const credFields = connector?.credentials ?? [];
239
- const requiredFields = credFields.filter((f) => f.required);
240
- const advancedFields = credFields.filter((f) => !f.required);
241
239
  // A connector with a form_layout groups its credentials into titled sections
242
240
  // (a light wizard). Fall back to the required/advanced split when absent.
243
241
  const layoutSections = connector?.form_layout?.sections ?? [];
@@ -270,6 +268,18 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
270
268
  const loadedEnv = useRef(null);
271
269
  const envField = credFields.find((f) => f.type === 'select' && ['environment', 'mode', 'env'].includes(f.key));
272
270
  const envValue = envField ? (credValues[envField.key] ?? '') : '';
271
+ // What the form SHOWS for the live values: a credential whose own visible_when
272
+ // (or whose section's) is false is not applicable — never required, never
273
+ // validated, never counted in a step's error, never sent (connector_email:
274
+ // choosing Resend must not demand the SendGrid key).
275
+ const credDefaults = {};
276
+ for (const f of credFields)
277
+ if (f.default != null && f.default !== '')
278
+ credDefaults[f.key] = String(f.default);
279
+ const activeSections = visibleSections(layoutSections, credValues, credDefaults);
280
+ const activeFields = applicableFields(credFields, layoutSections, credValues, credDefaults);
281
+ // Only what applies is sent: a hidden provider's field is left out.
282
+ const isSendable = (key) => !credFields.some((f) => f.key === key) || activeFields.some((f) => f.key === key);
273
283
  const stepHeadingRef = useRef(null);
274
284
  const stepMoved = useRef(false);
275
285
  const setCred = (key, val) => {
@@ -507,7 +517,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
507
517
  // secret leaves it untouched (server merges).
508
518
  const payload = {};
509
519
  for (const [k, v] of Object.entries(credValues)) {
510
- if (v != null && v !== '')
520
+ if (v != null && v !== '' && isSendable(k))
511
521
  payload[k] = v;
512
522
  }
513
523
  await api.post(`/integrations/${connector.provider}`, payload);
@@ -590,7 +600,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
590
600
  const handleSave = () => {
591
601
  setFormError(null);
592
602
  if (connector && canManageIssuer) {
593
- const miss = missingRequired(credFields, credValues, !!connector.connected);
603
+ const miss = missingRequired(activeFields, credValues, !!connector.connected);
594
604
  if (miss.length > 0) {
595
605
  const errs = {};
596
606
  for (const k of miss) {
@@ -614,7 +624,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
614
624
  const persistCredsIfDirty = async () => {
615
625
  if (!credDirty || !connector || !canManageIssuer)
616
626
  return null;
617
- const miss = missingRequired(credFields, credValues, !!connector.connected);
627
+ const miss = missingRequired(activeFields, credValues, !!connector.connected);
618
628
  if (miss.length > 0) {
619
629
  const errs = {};
620
630
  for (const k of miss)
@@ -626,7 +636,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
626
636
  }
627
637
  const payload = {};
628
638
  for (const [k, v] of Object.entries(credValues)) {
629
- if (v != null && v !== '')
639
+ if (v != null && v !== '' && isSendable(k))
630
640
  payload[k] = v;
631
641
  }
632
642
  await api.post(`/integrations/${connector.provider}`, payload);
@@ -737,7 +747,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
737
747
  // Wizard steps: form_layout sections with fields OR blocks, + a final
738
748
  // "Ajustes" step when the addon also ships settings.
739
749
  const wizardSteps = stepMode
740
- ? buildWizardSteps(layoutSections, credFields.map((f) => f.section), hasSettings)
750
+ ? buildWizardSteps(activeSections, activeFields.map((f) => f.section), hasSettings)
741
751
  : [];
742
752
  const totalSteps = wizardSteps.length;
743
753
  const useStepper = stepMode && totalSteps > 1;
@@ -778,7 +788,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
778
788
  return stepStatus({
779
789
  index: i,
780
790
  current: stepIdx,
781
- fieldKeys: s.kind === 'creds' ? credFields.filter((f) => f.section === s.key).map((f) => f.key) : [],
791
+ fieldKeys: s.kind === 'creds' ? activeFields.filter((f) => f.section === s.key).map((f) => f.key) : [],
782
792
  fieldErrors,
783
793
  blockKeys: blocksFor(s.key, s.blocks).map((b) => b.key),
784
794
  results: blockResults,
@@ -798,7 +808,7 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
798
808
  // operator learns what is missing where it is, not at the end.
799
809
  const handleNext = () => {
800
810
  if (activeStep?.kind === 'creds' && connector && canManageIssuer) {
801
- const stepFields = credFields.filter((f) => f.section === activeStep.key);
811
+ const stepFields = activeFields.filter((f) => f.section === activeStep.key);
802
812
  const miss = missingRequired(stepFields, credValues, !!connector.connected);
803
813
  if (miss.length > 0) {
804
814
  const errs = {};
@@ -852,12 +862,12 @@ export function AddonConfigSurface({ addon, connector, open, onOpenChange, onSav
852
862
  : 'border-border text-muted-foreground'), children: !active && status === 'error' ? (_jsx(AlertCircle, { className: 'h-4 w-4' })) : !active && status === 'ok' ? (_jsx(Check, { className: 'h-4 w-4' })) : (i + 1) }) }), i < wizardSteps.length - 1 && (_jsx("span", { "aria-hidden": 'true', className: cn('mx-1 h-0.5 flex-1 rounded-full transition-colors', i < stepIdx ? 'bg-primary' : 'bg-border') }))] }, s.key));
853
863
  }) }), _jsxs("div", { className: 'flex items-start justify-between gap-3', children: [_jsx("h3", { ref: stepHeadingRef, tabIndex: -1, className: 'min-w-0 text-base leading-snug font-semibold break-words outline-none', children: t(activeStep?.title ?? '', {
854
864
  defaultValue: humanizeKey(activeStep?.title),
855
- }) }), _jsx("span", { className: 'mt-0.5 shrink-0 text-xs font-medium tabular-nums text-muted-foreground', children: st('flow.step_of', { n: stepIdx + 1, total: totalSteps }) })] })] }), _jsxs("div", { className: 'flex flex-col gap-4', children: [activeStep?.description && (_jsx(HelpText, { text: addonText(activeStep.description) })), activeStep?.kind === 'settings' ? (settingsBody) : !canManageIssuer ? (_jsxs(_Fragment, { children: [issuerAdminNote, renderBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))] })) : (_jsxs(_Fragment, { children: [renderBlocks(leadBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))), credFields.filter((f) => f.section === activeStep?.key).map(renderCred), renderBlocks(trailBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))] }))] })] })) : (_jsxs(_Fragment, { children: [oauthPanel, hasCredentials && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Cable, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_credentials') })] }), !canManageIssuer ? (issuerAdminNote) : useLayout ? (
865
+ }) }), _jsx("span", { className: 'mt-0.5 shrink-0 text-xs font-medium tabular-nums text-muted-foreground', children: st('flow.step_of', { n: stepIdx + 1, total: totalSteps }) })] })] }), _jsxs("div", { className: 'flex flex-col gap-4', children: [activeStep?.description && (_jsx(HelpText, { text: addonText(activeStep.description) })), activeStep?.kind === 'settings' ? (settingsBody) : !canManageIssuer ? (_jsxs(_Fragment, { children: [issuerAdminNote, renderBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))] })) : (_jsxs(_Fragment, { children: [renderBlocks(leadBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks))), activeFields.filter((f) => f.section === activeStep?.key).map(renderCred), renderBlocks(trailBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))] }))] })] })) : (_jsxs(_Fragment, { children: [oauthPanel, hasCredentials && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Cable, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_credentials') })] }), !canManageIssuer ? (issuerAdminNote) : useLayout ? (
856
866
  // form_layout: one titled group per section, in declared order.
857
- layoutSections.map((sec) => {
858
- const fields = credFields.filter((f) => f.section === sec.key);
867
+ activeSections.map((sec) => {
868
+ const fields = activeFields.filter((f) => f.section === sec.key);
859
869
  if (fields.length === 0 && (sec.blocks?.length ?? 0) === 0)
860
870
  return null;
861
871
  return (_jsxs("div", { className: 'flex flex-col gap-3 rounded-md border border-border/60 px-3 py-3', children: [sec.title && (_jsxs("div", { className: 'flex flex-col gap-1', children: [_jsx("h4", { className: 'text-sm font-medium', children: t(sec.title, { defaultValue: sec.title }) }), sec.description && (_jsx(HelpText, { text: addonText(sec.description) }))] })), renderBlocks(leadBlocks(sec.blocks)), fields.map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))), renderBlocks(trailBlocks(sec.blocks))] }, sec.key));
862
- })) : (_jsxs(_Fragment, { children: [requiredFields.map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))), advancedFields.length > 0 && (_jsxs("details", { className: 'rounded-md border border-border/60 px-3 py-2', open: advancedFields.some((f) => !!fieldErrors[f.key]) || undefined, children: [_jsx("summary", { className: 'flex min-h-11 cursor-pointer items-center text-sm font-medium text-muted-foreground select-none sm:min-h-8', children: st('installed_addons.advanced') }), _jsx("div", { className: 'flex flex-col gap-3 pt-3', children: advancedFields.map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))) })] }))] }))] })), extraBlocks.length > 0 && renderBlocks(extraBlocks), hasSettings && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Settings, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_settings') })] }), targetPicker, shownDefs.map(renderSetting)] })), nothingToConfigure && (_jsxs("div", { className: 'flex flex-col items-start gap-1 rounded-lg border border-dashed p-4', children: [_jsx("p", { className: 'text-sm font-medium', children: st('empty.title') }), _jsx(HelpText, { text: st('empty.help') })] }))] })) }), formError ? (_jsx("div", { ref: errorRef, role: 'alert', className: 'max-h-40 shrink-0 overflow-y-auto whitespace-pre-wrap break-words rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive', children: formError })) : null, _jsx(DialogFooter, { "data-wizard-footer": '', 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', children: nothingToSave ? (_jsx(Button, { className: 'h-11 w-full sm:ml-auto sm:h-9 sm:w-auto', onClick: () => onOpenChange(false), children: st('common.close') })) : (_jsxs(_Fragment, { children: [_jsxs("p", { role: 'status', "aria-live": 'polite', "data-save-status": saveStatus, className: cn('flex shrink-0 items-center gap-1.5 whitespace-nowrap text-xs', saveStatus === 'dirty' ? 'font-medium text-amber-600 dark:text-amber-400' : 'text-muted-foreground', saveStatus === 'saved' && 'text-emerald-600 dark:text-emerald-400'), children: [saveStatus === 'saving' ? (_jsx(Loader2, { className: 'h-3.5 w-3.5 animate-spin' })) : saveStatus === 'saved' ? (_jsx(Check, { className: 'h-3.5 w-3.5' })) : (_jsx("span", { "aria-hidden": true, className: cn('h-2 w-2 rounded-full', saveStatus === 'dirty' ? 'bg-amber-500' : 'bg-muted-foreground/40') })), st(`form.status_${saveStatus}`)] }), _jsxs("div", { className: 'flex flex-wrap items-center gap-2 sm:ml-auto sm:flex-nowrap sm:justify-end', children: [_jsx(Button, { variant: 'ghost', className: 'h-11 px-3 sm:h-9', onClick: () => onOpenChange(false), children: dirty ? st('common.cancel') : st('common.close') }), useStepper && stepIdx > 0 && (_jsx(Button, { variant: 'outline', className: 'h-11 sm:h-9', onClick: () => goToStep(Math.max(0, stepIdx - 1)), children: st('common.back') })), useStepper && !isLastStep && (_jsx(Button, { variant: 'outline', className: 'h-11 sm:h-9', onClick: handleNext, children: st('common.next') })), _jsxs(Button, { className: 'h-11 flex-1 sm:h-9 sm:flex-none', onClick: handleSave, disabled: saveMutation.isPending || loading, "data-testid": 'config-save', children: [saveMutation.isPending && _jsx(Loader2, { className: 'mr-2 h-4 w-4 animate-spin' }), st('common.save')] })] })] })) })] }) }) }));
872
+ })) : (_jsxs(_Fragment, { children: [activeFields.filter((f) => f.required).map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))), activeFields.some((f) => !f.required) && (_jsxs("details", { className: 'rounded-md border border-border/60 px-3 py-2', open: activeFields.filter((f) => !f.required).some((f) => !!fieldErrors[f.key]) || undefined, children: [_jsx("summary", { className: 'flex min-h-11 cursor-pointer items-center text-sm font-medium text-muted-foreground select-none sm:min-h-8', children: st('installed_addons.advanced') }), _jsx("div", { className: 'flex flex-col gap-3 pt-3', children: activeFields.filter((f) => !f.required).map((f) => (_jsx(ConnectorCredentialFieldControl, { field: f, connected: !!connector?.connected, provider: connector?.provider ?? '', ...storedProps(f.key), value: credValues[f.key] ?? '', onChange: (val) => setCred(f.key, val) }, f.key))) })] }))] }))] })), extraBlocks.length > 0 && renderBlocks(extraBlocks), hasSettings && (_jsxs("section", { className: 'flex flex-col gap-3', children: [_jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Settings, { className: 'h-4 w-4 text-muted-foreground' }), _jsx("h3", { className: 'text-sm font-semibold', children: st('installed_addons.section_settings') })] }), targetPicker, shownDefs.map(renderSetting)] })), nothingToConfigure && (_jsxs("div", { className: 'flex flex-col items-start gap-1 rounded-lg border border-dashed p-4', children: [_jsx("p", { className: 'text-sm font-medium', children: st('empty.title') }), _jsx(HelpText, { text: st('empty.help') })] }))] })) }), formError ? (_jsx("div", { ref: errorRef, role: 'alert', className: 'max-h-40 shrink-0 overflow-y-auto whitespace-pre-wrap break-words rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive', children: formError })) : null, _jsx(DialogFooter, { "data-wizard-footer": '', 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', children: nothingToSave ? (_jsx(Button, { className: 'h-11 w-full sm:ml-auto sm:h-9 sm:w-auto', onClick: () => onOpenChange(false), children: st('common.close') })) : (_jsxs(_Fragment, { children: [_jsxs("p", { role: 'status', "aria-live": 'polite', "data-save-status": saveStatus, className: cn('flex shrink-0 items-center gap-1.5 whitespace-nowrap text-xs', saveStatus === 'dirty' ? 'font-medium text-amber-600 dark:text-amber-400' : 'text-muted-foreground', saveStatus === 'saved' && 'text-emerald-600 dark:text-emerald-400'), children: [saveStatus === 'saving' ? (_jsx(Loader2, { className: 'h-3.5 w-3.5 animate-spin' })) : saveStatus === 'saved' ? (_jsx(Check, { className: 'h-3.5 w-3.5' })) : (_jsx("span", { "aria-hidden": true, className: cn('h-2 w-2 rounded-full', saveStatus === 'dirty' ? 'bg-amber-500' : 'bg-muted-foreground/40') })), st(`form.status_${saveStatus}`)] }), _jsxs("div", { className: 'flex flex-wrap items-center gap-2 sm:ml-auto sm:flex-nowrap sm:justify-end', children: [_jsx(Button, { variant: 'ghost', className: 'h-11 px-3 sm:h-9', onClick: () => onOpenChange(false), children: dirty ? st('common.cancel') : st('common.close') }), useStepper && stepIdx > 0 && (_jsx(Button, { variant: 'outline', className: 'h-11 sm:h-9', onClick: () => goToStep(Math.max(0, stepIdx - 1)), children: st('common.back') })), useStepper && !isLastStep && (_jsx(Button, { variant: 'outline', className: 'h-11 sm:h-9', onClick: handleNext, children: st('common.next') })), _jsxs(Button, { className: 'h-11 flex-1 sm:h-9 sm:flex-none', onClick: handleSave, disabled: saveMutation.isPending || loading, "data-testid": 'config-save', children: [saveMutation.isPending && _jsx(Loader2, { className: 'mr-2 h-4 w-4 animate-spin' }), st('common.save')] })] })] })) })] }) }) }));
863
873
  }
@@ -37,4 +37,32 @@ export declare function parseSaveError(err: unknown, fallback: string): SaveErro
37
37
  export declare function textOrFallback(text: string | undefined, key: string, fallback: string): string;
38
38
  /** Cheap content hash so a re-published bundle with the same key count re-merges. */
39
39
  export declare function bundleSignature(labels: Record<string, unknown>): string;
40
+ export interface VisibilityPredicate {
41
+ field?: string;
42
+ equals?: unknown;
43
+ in?: unknown[];
44
+ class?: string;
45
+ }
46
+ interface ConditionalField {
47
+ key: string;
48
+ section?: string;
49
+ visible_when?: VisibilityPredicate;
50
+ visibleWhen?: VisibilityPredicate;
51
+ }
52
+ interface ConditionalSection {
53
+ key: string;
54
+ visible_when?: VisibilityPredicate;
55
+ visibleWhen?: VisibilityPredicate;
56
+ }
57
+ /** Same semantics as `evaluateVisibleWhen` (no field / no comparison => visible). */
58
+ export declare function predicateHolds(cond: VisibilityPredicate | undefined, values: Record<string, string>, defaults?: Record<string, string>): boolean;
59
+ /** Sections the form shows for these values. */
60
+ export declare function visibleSections<S extends ConditionalSection>(sections: S[], values: Record<string, string>, defaults?: Record<string, string>): S[];
61
+ /**
62
+ * Fields the form shows for these values: the field's own `visible_when` holds
63
+ * AND its section's does. Hidden fields are not validated, not counted in a
64
+ * step's error state and not sent.
65
+ */
66
+ export declare function applicableFields<F extends ConditionalField>(fields: F[], sections: ConditionalSection[], values: Record<string, string>, defaults?: Record<string, string>): F[];
67
+ export {};
40
68
  //# sourceMappingURL=connector-form-model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connector-form-model.d.ts","sourceRoot":"","sources":["../../src/setup/connector-form-model.ts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,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG9F;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAKvE"}
1
+ {"version":3,"file":"connector-form-model.d.ts","sourceRoot":"","sources":["../../src/setup/connector-form-model.ts"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG,YAAY,CAAA;AASzD,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAMnE;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,cAAc,YAAsC,CAAA;AAI1F,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,KAAK,EAAE,eAAe,CAAA;IACtB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,cAAc,EAAE,GACvB,aAAa,GAAG,IAAI,CAatB;AAED,iFAAiF;AACjF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EAAE,EACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,SAAS,EAAE,OAAO,GACjB,MAAM,EAAE,CAOV;AAED,MAAM,WAAW,SAAS;IACxB,oDAAoD;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,mEAAmE;IACnE,SAAS,EAAE,MAAM,EA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MAAM,CAAM,GACpC,CAAC,EAAE,CAEL;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,gBAAgB,EACzD,MAAM,EAAE,CAAC,EAAE,EACX,QAAQ,EAAE,kBAAkB,EAAE,EAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,CAAC,EAAE,CAOL"}
@@ -74,3 +74,29 @@ export function bundleSignature(labels) {
74
74
  h = ((h << 5) + h + s.charCodeAt(i)) | 0;
75
75
  return `${Object.keys(labels).length}:${(h >>> 0).toString(36)}`;
76
76
  }
77
+ /** Same semantics as `evaluateVisibleWhen` (no field / no comparison => visible). */
78
+ export function predicateHolds(cond, values, defaults = {}) {
79
+ if (!cond || typeof cond.field !== 'string' || cond.field.trim() === '')
80
+ return true;
81
+ const key = cond.field.trim();
82
+ const raw = values[key];
83
+ const current = raw == null || raw === '' ? (defaults[key] ?? '') : String(raw);
84
+ if (Array.isArray(cond.in) && cond.in.length > 0)
85
+ return cond.in.some((v) => String(v) === current);
86
+ if (cond.equals != null)
87
+ return String(cond.equals) === current;
88
+ return true;
89
+ }
90
+ /** Sections the form shows for these values. */
91
+ export function visibleSections(sections, values, defaults = {}) {
92
+ return sections.filter((s) => predicateHolds(s.visible_when ?? s.visibleWhen, values, defaults));
93
+ }
94
+ /**
95
+ * Fields the form shows for these values: the field's own `visible_when` holds
96
+ * AND its section's does. Hidden fields are not validated, not counted in a
97
+ * step's error state and not sent.
98
+ */
99
+ export function applicableFields(fields, sections, values, defaults = {}) {
100
+ const hidden = new Set(sections.filter((s) => !predicateHolds(s.visible_when ?? s.visibleWhen, values, defaults)).map((s) => s.key));
101
+ return fields.filter((f) => predicateHolds(f.visible_when ?? f.visibleWhen, values, defaults) && !(f.section && hidden.has(f.section)));
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-runtime-react",
3
- "version": "53.10.1",
3
+ "version": "53.10.2",
4
4
  "description": "React runtime for metacore hosts — renders addon contributions dynamically",
5
5
  "repository": {
6
6
  "type": "git",
@@ -54,6 +54,8 @@ import {
54
54
  import {
55
55
  isSecretCredential,
56
56
  missingRequired,
57
+ applicableFields,
58
+ visibleSections,
57
59
  parseSaveError,
58
60
  shapeMismatch,
59
61
  textOrFallback,
@@ -96,10 +98,16 @@ export interface ConnectorCredentialField {
96
98
  options?: { value: string; label: string }[]
97
99
  options_source?: string // dynamic_select: export the host runs to list options
98
100
  section?: string // binds to a form_layout section
101
+ /** Shown only while a sibling credential has this value (kernel Setting.visible_when). */
102
+ visible_when?: VisibleWhen
103
+ visibleWhen?: VisibleWhen
99
104
  }
100
105
 
101
106
  export interface ConnectorFormLayoutSection {
102
107
  key: string
108
+ /** Hides the whole section (and its fields) while false. */
109
+ visible_when?: VisibleWhen
110
+ visibleWhen?: VisibleWhen
103
111
  title?: string // i18n key
104
112
  description?: string // i18n key
105
113
  /** Setup blocks (webhook_url / instructions / action), host-filled. */
@@ -622,8 +630,6 @@ export function AddonConfigSurface({
622
630
  }, [open])
623
631
 
624
632
  const credFields = connector?.credentials ?? []
625
- const requiredFields = credFields.filter((f) => f.required)
626
- const advancedFields = credFields.filter((f) => !f.required)
627
633
  // A connector with a form_layout groups its credentials into titled sections
628
634
  // (a light wizard). Fall back to the required/advanced split when absent.
629
635
  const layoutSections = connector?.form_layout?.sections ?? []
@@ -660,6 +666,16 @@ export function AddonConfigSurface({
660
666
  (f) => f.type === 'select' && ['environment', 'mode', 'env'].includes(f.key),
661
667
  )
662
668
  const envValue = envField ? (credValues[envField.key] ?? '') : ''
669
+ // What the form SHOWS for the live values: a credential whose own visible_when
670
+ // (or whose section's) is false is not applicable — never required, never
671
+ // validated, never counted in a step's error, never sent (connector_email:
672
+ // choosing Resend must not demand the SendGrid key).
673
+ const credDefaults: Record<string, string> = {}
674
+ for (const f of credFields) if (f.default != null && f.default !== '') credDefaults[f.key] = String(f.default)
675
+ const activeSections = visibleSections(layoutSections, credValues, credDefaults)
676
+ const activeFields = applicableFields(credFields, layoutSections, credValues, credDefaults)
677
+ // Only what applies is sent: a hidden provider's field is left out.
678
+ const isSendable = (key: string) => !credFields.some((f) => f.key === key) || activeFields.some((f) => f.key === key)
663
679
  const stepHeadingRef = useRef<HTMLHeadingElement>(null)
664
680
  const stepMoved = useRef(false)
665
681
  const setCred = (key: string, val: string) => {
@@ -891,7 +907,7 @@ export function AddonConfigSurface({
891
907
  // secret leaves it untouched (server merges).
892
908
  const payload: Record<string, string> = {}
893
909
  for (const [k, v] of Object.entries(credValues)) {
894
- if (v != null && v !== '') payload[k] = v
910
+ if (v != null && v !== '' && isSendable(k)) payload[k] = v
895
911
  }
896
912
  await api.post(`/integrations/${connector.provider}`, payload)
897
913
  }
@@ -973,7 +989,7 @@ export function AddonConfigSurface({
973
989
  const handleSave = () => {
974
990
  setFormError(null)
975
991
  if (connector && canManageIssuer) {
976
- const miss = missingRequired(credFields, credValues, !!connector.connected)
992
+ const miss = missingRequired(activeFields, credValues, !!connector.connected)
977
993
  if (miss.length > 0) {
978
994
  const errs: Record<string, string> = {}
979
995
  for (const k of miss) {
@@ -999,7 +1015,7 @@ export function AddonConfigSurface({
999
1015
  // screen requires persisting it first. Returns an error message, or null.
1000
1016
  const persistCredsIfDirty = async (): Promise<string | null> => {
1001
1017
  if (!credDirty || !connector || !canManageIssuer) return null
1002
- const miss = missingRequired(credFields, credValues, !!connector.connected)
1018
+ const miss = missingRequired(activeFields, credValues, !!connector.connected)
1003
1019
  if (miss.length > 0) {
1004
1020
  const errs: Record<string, string> = {}
1005
1021
  for (const k of miss) errs[k] = st('installed_addons.field_required')
@@ -1010,7 +1026,7 @@ export function AddonConfigSurface({
1010
1026
  }
1011
1027
  const payload: Record<string, string> = {}
1012
1028
  for (const [k, v] of Object.entries(credValues)) {
1013
- if (v != null && v !== '') payload[k] = v
1029
+ if (v != null && v !== '' && isSendable(k)) payload[k] = v
1014
1030
  }
1015
1031
  await api.post(`/integrations/${connector.provider}`, payload)
1016
1032
  setCredDirty(false)
@@ -1282,8 +1298,8 @@ export function AddonConfigSurface({
1282
1298
  // "Ajustes" step when the addon also ships settings.
1283
1299
  const wizardSteps = stepMode
1284
1300
  ? buildWizardSteps(
1285
- layoutSections,
1286
- credFields.map((f) => f.section),
1301
+ activeSections,
1302
+ activeFields.map((f) => f.section),
1287
1303
  hasSettings,
1288
1304
  )
1289
1305
  : []
@@ -1339,7 +1355,7 @@ export function AddonConfigSurface({
1339
1355
  return stepStatus({
1340
1356
  index: i,
1341
1357
  current: stepIdx,
1342
- fieldKeys: s.kind === 'creds' ? credFields.filter((f) => f.section === s.key).map((f) => f.key) : [],
1358
+ fieldKeys: s.kind === 'creds' ? activeFields.filter((f) => f.section === s.key).map((f) => f.key) : [],
1343
1359
  fieldErrors,
1344
1360
  blockKeys: blocksFor(s.key, s.blocks).map((b) => b.key),
1345
1361
  results: blockResults,
@@ -1360,7 +1376,7 @@ export function AddonConfigSurface({
1360
1376
  // operator learns what is missing where it is, not at the end.
1361
1377
  const handleNext = () => {
1362
1378
  if (activeStep?.kind === 'creds' && connector && canManageIssuer) {
1363
- const stepFields = credFields.filter((f) => f.section === activeStep.key)
1379
+ const stepFields = activeFields.filter((f) => f.section === activeStep.key)
1364
1380
  const miss = missingRequired(stepFields, credValues, !!connector.connected)
1365
1381
  if (miss.length > 0) {
1366
1382
  const errs: Record<string, string> = {}
@@ -1512,7 +1528,7 @@ export function AddonConfigSurface({
1512
1528
  ) : (
1513
1529
  <>
1514
1530
  {renderBlocks(leadBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))}
1515
- {credFields.filter((f) => f.section === activeStep?.key).map(renderCred)}
1531
+ {activeFields.filter((f) => f.section === activeStep?.key).map(renderCred)}
1516
1532
  {renderBlocks(trailBlocks(blocksFor(activeStep?.key ?? '', activeStep?.blocks)))}
1517
1533
  </>
1518
1534
  )}
@@ -1534,8 +1550,8 @@ export function AddonConfigSurface({
1534
1550
  issuerAdminNote
1535
1551
  ) : useLayout ? (
1536
1552
  // form_layout: one titled group per section, in declared order.
1537
- layoutSections.map((sec) => {
1538
- const fields = credFields.filter((f) => f.section === sec.key)
1553
+ activeSections.map((sec) => {
1554
+ const fields = activeFields.filter((f) => f.section === sec.key)
1539
1555
  if (fields.length === 0 && (sec.blocks?.length ?? 0) === 0) return null
1540
1556
  return (
1541
1557
  <div
@@ -1570,7 +1586,7 @@ export function AddonConfigSurface({
1570
1586
  })
1571
1587
  ) : (
1572
1588
  <>
1573
- {requiredFields.map((f) => (
1589
+ {activeFields.filter((f) => f.required).map((f) => (
1574
1590
  <ConnectorCredentialFieldControl
1575
1591
  key={f.key}
1576
1592
  field={f}
@@ -1581,16 +1597,16 @@ export function AddonConfigSurface({
1581
1597
  onChange={(val) => setCred(f.key, val)}
1582
1598
  />
1583
1599
  ))}
1584
- {advancedFields.length > 0 && (
1600
+ {activeFields.some((f) => !f.required) && (
1585
1601
  <details
1586
1602
  className='rounded-md border border-border/60 px-3 py-2'
1587
- open={advancedFields.some((f) => !!fieldErrors[f.key]) || undefined}
1603
+ open={activeFields.filter((f) => !f.required).some((f) => !!fieldErrors[f.key]) || undefined}
1588
1604
  >
1589
1605
  <summary className='flex min-h-11 cursor-pointer items-center text-sm font-medium text-muted-foreground select-none sm:min-h-8'>
1590
1606
  {st('installed_addons.advanced')}
1591
1607
  </summary>
1592
1608
  <div className='flex flex-col gap-3 pt-3'>
1593
- {advancedFields.map((f) => (
1609
+ {activeFields.filter((f) => !f.required).map((f) => (
1594
1610
  <ConnectorCredentialFieldControl
1595
1611
  key={f.key}
1596
1612
  field={f}
@@ -0,0 +1,58 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { applicableFields, missingRequired, visibleSections } from './connector-form-model'
3
+
4
+ // connector_email: provider picks which API key applies; each provider lives in
5
+ // its own section gated by visible_when.
6
+ const sections = [
7
+ { key: 'provider' },
8
+ { key: 'connection_resend', visible_when: { field: 'provider', equals: 'resend' } },
9
+ { key: 'connection_sendgrid', visible_when: { field: 'provider', equals: 'sendgrid' } },
10
+ { key: 'identity' },
11
+ ]
12
+ const fields = [
13
+ { key: 'provider', type: 'select', required: true, default: 'resend', section: 'provider' },
14
+ { key: 'api_key', type: 'secret', required: true, section: 'connection_resend' },
15
+ { key: 'sendgrid_api_key', type: 'secret', required: true, section: 'connection_sendgrid' },
16
+ { key: 'from_address', type: 'string', required: true, section: 'identity' },
17
+ ]
18
+ const defaults = { provider: 'resend' }
19
+
20
+ describe('conditional credential fields', () => {
21
+ it('provider=resend with sendgrid_api_key empty saves (hidden field is not required)', () => {
22
+ const values = { provider: 'resend', api_key: 're_123', from_address: 'a@b.mx' }
23
+ const active = applicableFields(fields, sections, values, defaults)
24
+ expect(active.map((f) => f.key)).toEqual(['provider', 'api_key', 'from_address'])
25
+ expect(missingRequired(active, values, false)).toEqual([])
26
+ // The old behaviour (every declared field) is what produced the bug.
27
+ expect(missingRequired(fields, values, false)).toContain('sendgrid_api_key')
28
+ })
29
+
30
+ it('the default provider applies when the value is blank', () => {
31
+ const active = applicableFields(fields, sections, { from_address: 'a@b.mx' }, defaults)
32
+ expect(active.map((f) => f.key)).toContain('api_key')
33
+ expect(active.map((f) => f.key)).not.toContain('sendgrid_api_key')
34
+ })
35
+
36
+ it('switching to sendgrid requires ITS key and not the Resend one', () => {
37
+ const values = { provider: 'sendgrid', from_address: 'a@b.mx' }
38
+ const active = applicableFields(fields, sections, values, defaults)
39
+ expect(missingRequired(active, values, false)).toEqual(['sendgrid_api_key'])
40
+ })
41
+
42
+ it('hides sections (wizard steps) of the other providers', () => {
43
+ expect(visibleSections(sections, { provider: 'resend' }, defaults).map((s) => s.key)).toEqual([
44
+ 'provider',
45
+ 'connection_resend',
46
+ 'identity',
47
+ ])
48
+ })
49
+
50
+ it('honours a field-level visible_when (in)', () => {
51
+ const f = [
52
+ { key: 'mode', required: true, default: 'a' },
53
+ { key: 'extra', required: true, visible_when: { field: 'mode', in: ['b', 'c'] } },
54
+ ]
55
+ expect(applicableFields(f, [], { mode: 'a' }, { mode: 'a' }).map((x) => x.key)).toEqual(['mode'])
56
+ expect(applicableFields(f, [], { mode: 'b' }).map((x) => x.key)).toEqual(['mode', 'extra'])
57
+ })
58
+ })
@@ -113,3 +113,72 @@ export function bundleSignature(labels: Record<string, unknown>): string {
113
113
  for (let i = 0; i < s.length; i++) h = ((h << 5) + h + s.charCodeAt(i)) | 0
114
114
  return `${Object.keys(labels).length}:${(h >>> 0).toString(36)}`
115
115
  }
116
+
117
+ // ─── Conditional fields (visible_when) ──────────────────────────────────────
118
+ // Kernel contract (Setting.visible_when / FormSection.visible_when): a hidden
119
+ // credential counts for required checks only while visible. A connector with
120
+ // conditional providers (email: Resend / SendGrid / Mailgun, each with its own
121
+ // key in its own section) must never demand the keys of the providers that were
122
+ // not chosen. These pure helpers decide what is APPLICABLE for the live values.
123
+
124
+ export interface VisibilityPredicate {
125
+ field?: string
126
+ equals?: unknown
127
+ in?: unknown[]
128
+ class?: string
129
+ }
130
+
131
+ interface ConditionalField {
132
+ key: string
133
+ section?: string
134
+ visible_when?: VisibilityPredicate
135
+ visibleWhen?: VisibilityPredicate
136
+ }
137
+ interface ConditionalSection {
138
+ key: string
139
+ visible_when?: VisibilityPredicate
140
+ visibleWhen?: VisibilityPredicate
141
+ }
142
+
143
+ /** Same semantics as `evaluateVisibleWhen` (no field / no comparison => visible). */
144
+ export function predicateHolds(
145
+ cond: VisibilityPredicate | undefined,
146
+ values: Record<string, string>,
147
+ defaults: Record<string, string> = {},
148
+ ): boolean {
149
+ if (!cond || typeof cond.field !== 'string' || cond.field.trim() === '') return true
150
+ const key = cond.field.trim()
151
+ const raw = values[key]
152
+ const current = raw == null || raw === '' ? (defaults[key] ?? '') : String(raw)
153
+ if (Array.isArray(cond.in) && cond.in.length > 0) return cond.in.some((v) => String(v) === current)
154
+ if (cond.equals != null) return String(cond.equals) === current
155
+ return true
156
+ }
157
+
158
+ /** Sections the form shows for these values. */
159
+ export function visibleSections<S extends ConditionalSection>(
160
+ sections: S[],
161
+ values: Record<string, string>,
162
+ defaults: Record<string, string> = {},
163
+ ): S[] {
164
+ return sections.filter((s) => predicateHolds(s.visible_when ?? s.visibleWhen, values, defaults))
165
+ }
166
+
167
+ /**
168
+ * Fields the form shows for these values: the field's own `visible_when` holds
169
+ * AND its section's does. Hidden fields are not validated, not counted in a
170
+ * step's error state and not sent.
171
+ */
172
+ export function applicableFields<F extends ConditionalField>(
173
+ fields: F[],
174
+ sections: ConditionalSection[],
175
+ values: Record<string, string>,
176
+ defaults: Record<string, string> = {},
177
+ ): F[] {
178
+ const hidden = new Set(
179
+ sections.filter((s) => !predicateHolds(s.visible_when ?? s.visibleWhen, values, defaults)).map((s) => s.key),
180
+ )
181
+ return fields.filter(
182
+ (f) => predicateHolds(f.visible_when ?? f.visibleWhen, values, defaults) && !(f.section && hidden.has(f.section)),
183
+ )
184
+ }