From 55b3100b230a68c327f30a5cff3a98f4a7a061b9 Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Thu, 19 Nov 2026 13:42:54 +0000 Subject: [PATCH 1/6] fix(ENG-902): send a cleared optional field as null on account edit The relink PATCH dropped every empty field, so the API's merge kept the stored value and the field came back on the next edit. An edit now sends a cleared field as null, which the API removes. Creating an account and the OAuth popup still omit empty fields, and an unopened secret placeholder is still left out so the stored secret is kept. Co-Authored-By: Claude Opus 5.5 --- .../hooks/useIntegrationPicker.ts | 32 +++---- .../utils/credentialsPayload.test.ts | 95 +++++++++++++++++++ .../utils/credentialsPayload.ts | 50 ++++++++++ 3 files changed, 156 insertions(+), 21 deletions(-) create mode 100644 src/modules/integration-picker/utils/credentialsPayload.test.ts create mode 100644 src/modules/integration-picker/utils/credentialsPayload.ts diff --git a/src/modules/integration-picker/hooks/useIntegrationPicker.ts b/src/modules/integration-picker/hooks/useIntegrationPicker.ts index 39acc7f..9f33951 100644 --- a/src/modules/integration-picker/hooks/useIntegrationPicker.ts +++ b/src/modules/integration-picker/hooks/useIntegrationPicker.ts @@ -18,8 +18,8 @@ import { isFalconConnectorConfig, isLegacyConnectorConfig, } from '../types'; +import { buildCredentialsPayload, withoutClearedFields } from '../utils/credentialsPayload'; import { describeConnectError, errorStatus } from '../utils/requestErrors'; -import { isSecretPlaceholder } from '../utils/secretPlaceholder'; // Shared retry configuration for queries const RETRY_CONFIG = { @@ -561,23 +561,13 @@ export const useIntegrationPicker = ({ setConnectionState({ loading: true, success: false }); try { - const cleanedFormData = { ...formData }; - if (accountData) { - fields.forEach((field) => { - if (field.secret !== false || field.type === 'password') { - const fieldValue = cleanedFormData[field.key]; - if (isSecretPlaceholder(fieldValue) && !editingSecrets.has(field.key)) { - delete cleanedFormData[field.key]; - } - } - }); - } - - Object.keys(cleanedFormData).forEach((key) => { - if (cleanedFormData[key] === '') { - delete cleanedFormData[key]; - } + const credentials = buildCredentialsPayload({ + formData, + fields, + editingSecrets, + editing: !!accountData, }); + const filledCredentials = withoutClearedFields(credentials); const shouldRedirectForOAuth = authConfig?.type === 'oauth2' && @@ -624,8 +614,8 @@ export const useIntegrationPicker = ({ `${dashboardUrl}/embedded/accounts/callback`, ); let windowUrl = `${baseUrl}/connect/oauth2/${selectedIntegration.integration_id}?redirect_uri=${callbackEmbeddedAccountsUrl}&token=${token}&connection_attempt_id=${attemptId}`; - Object.keys(cleanedFormData).forEach((key) => { - windowUrl += `&${key}=${encodeURIComponent(cleanedFormData[key])}`; + Object.keys(filledCredentials).forEach((key) => { + windowUrl += `&${key}=${encodeURIComponent(filledCredentials[key])}`; }); const width = 1024; @@ -691,14 +681,14 @@ export const useIntegrationPicker = ({ accountId, token, integrationId: selectedIntegration.integration_id, - credentials: cleanedFormData, + credentials, }); successData = { id: accountId, provider: selectedIntegration.provider }; } else { const response = await connectAccount({ baseUrl, token, - credentials: cleanedFormData, + credentials: filledCredentials, integrationId: selectedIntegration.integration_id, }); if (!response) { diff --git a/src/modules/integration-picker/utils/credentialsPayload.test.ts b/src/modules/integration-picker/utils/credentialsPayload.test.ts new file mode 100644 index 0000000..8a55958 --- /dev/null +++ b/src/modules/integration-picker/utils/credentialsPayload.test.ts @@ -0,0 +1,95 @@ +import { describe, expect, it } from 'vitest'; +import type { ConnectorConfigField } from '../types'; +import { buildCredentialsPayload, withoutClearedFields } from './credentialsPayload'; + +const field = (overrides: Partial): ConnectorConfigField => ({ + label: overrides.key ?? 'field', + key: 'field', + required: false, + readOnly: false, + secret: false, + placeholder: '', + ...overrides, +}); + +const placeholder = '__secretvalue:**redacted**1234'; + +const fields = [ + field({ key: 'apiUrl', required: true }), + field({ key: 'region' }), + field({ key: 'apiKey', secret: true, required: true }), + field({ key: 'apiToken', type: 'password' }), +]; + +describe('buildCredentialsPayload', () => { + describe('when editing an account', () => { + it('sends a cleared field as null', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', region: '' }, + fields, + editingSecrets: new Set(), + editing: true, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com', region: null }); + }); + + it('leaves out a secret the user did not open, so the stored one is kept', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', apiKey: placeholder }, + fields, + editingSecrets: new Set(), + editing: true, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); + }); + + it('sends a secret the user opened and emptied as null', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', apiToken: '' }, + fields, + editingSecrets: new Set(['apiToken']), + editing: true, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com', apiToken: null }); + }); + + it('sends a value the user entered', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', apiKey: 'new-key', region: 'eu' }, + fields, + editingSecrets: new Set(['apiKey']), + editing: true, + }); + + expect(actual).toEqual({ + apiUrl: 'https://api.example.com', + apiKey: 'new-key', + region: 'eu', + }); + }); + }); + + describe('when creating an account', () => { + it('leaves out an empty field', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', region: '', apiToken: '' }, + fields, + editingSecrets: new Set(), + editing: false, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); + }); + }); +}); + +describe('withoutClearedFields', () => { + it('drops the cleared fields and keeps the rest', () => { + const actual = withoutClearedFields({ apiUrl: 'https://api.example.com', region: null }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); + }); +}); diff --git a/src/modules/integration-picker/utils/credentialsPayload.ts b/src/modules/integration-picker/utils/credentialsPayload.ts new file mode 100644 index 0000000..42e5e36 --- /dev/null +++ b/src/modules/integration-picker/utils/credentialsPayload.ts @@ -0,0 +1,50 @@ +import type { ConnectorConfigField } from '../types'; +import { isSecretPlaceholder } from './secretPlaceholder'; + +export type CredentialsPayload = Record; + +const isSecretField = (field: ConnectorConfigField) => + field.secret !== false || field.type === 'password'; + +const untouchedSecretKeys = ( + formData: Record, + fields: ConnectorConfigField[], + editingSecrets: Set, +) => + fields + .filter( + (field) => + isSecretField(field) && + isSecretPlaceholder(formData[field.key]) && + !editingSecrets.has(field.key), + ) + .map((field) => field.key); + +/** + * An edit sends a cleared field as `null` so the API removes the stored value; a new account + * has nothing stored, so it simply omits the field. + */ +export const buildCredentialsPayload = ({ + formData, + fields, + editingSecrets, + editing, +}: { + formData: Record; + fields: ConnectorConfigField[]; + editingSecrets: Set; + editing: boolean; +}): CredentialsPayload => { + const keptSecrets = editing ? untouchedSecretKeys(formData, fields, editingSecrets) : []; + + return Object.fromEntries( + Object.entries(formData) + .filter(([key, value]) => !keptSecrets.includes(key) && (editing || value !== '')) + .map(([key, value]) => [key, value === '' ? null : value]), + ); +}; + +export const withoutClearedFields = (credentials: CredentialsPayload): Record => + Object.fromEntries( + Object.entries(credentials).filter((entry): entry is [string, string] => entry[1] !== null), + ); From c42c453219ae3f74a4478c7a4b820562dffdad8e Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Thu, 19 Nov 2026 13:48:20 +0000 Subject: [PATCH 2/6] fix(ENG-902): only clear a field the form showed with a stored value Sending null for every empty field deleted values the user never saw: a secret emptied by its Edit button, a stored value the prefill hides, and everything after switching to another profile. Now only a non-secret field whose stored value was shown and then emptied is sent as null. Co-Authored-By: Claude Opus 5.5 --- .../hooks/useIntegrationPicker.ts | 8 ++- .../utils/credentialsPayload.test.ts | 57 +++++++++++++++---- .../utils/credentialsPayload.ts | 51 ++++++++++++----- 3 files changed, 87 insertions(+), 29 deletions(-) diff --git a/src/modules/integration-picker/hooks/useIntegrationPicker.ts b/src/modules/integration-picker/hooks/useIntegrationPicker.ts index 9f33951..7651a8f 100644 --- a/src/modules/integration-picker/hooks/useIntegrationPicker.ts +++ b/src/modules/integration-picker/hooks/useIntegrationPicker.ts @@ -565,7 +565,9 @@ export const useIntegrationPicker = ({ formData, fields, editingSecrets, - editing: !!accountData, + storedSetupInformation: prefillAccount + ? (prefillAccount.setupInformation ?? {}) + : undefined, }); const filledCredentials = withoutClearedFields(credentials); @@ -688,7 +690,7 @@ export const useIntegrationPicker = ({ const response = await connectAccount({ baseUrl, token, - credentials: filledCredentials, + credentials, integrationId: selectedIntegration.integration_id, }); if (!response) { @@ -713,7 +715,7 @@ export const useIntegrationPicker = ({ formData, editingSecrets, handleSuccess, - accountData, + prefillAccount, fields, accountId, authConfig, diff --git a/src/modules/integration-picker/utils/credentialsPayload.test.ts b/src/modules/integration-picker/utils/credentialsPayload.test.ts index 8a55958..75f07c6 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.test.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.test.ts @@ -17,68 +17,103 @@ const placeholder = '__secretvalue:**redacted**1234'; const fields = [ field({ key: 'apiUrl', required: true }), field({ key: 'region' }), + field({ key: 'retries' }), field({ key: 'apiKey', secret: true, required: true }), field({ key: 'apiToken', type: 'password' }), ]; +const stored = { apiUrl: 'https://api.example.com', region: 'eu' }; + describe('buildCredentialsPayload', () => { describe('when editing an account', () => { - it('sends a cleared field as null', () => { + it('sends a field the user emptied as null', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', region: '' }, fields, editingSecrets: new Set(), - editing: true, + storedSetupInformation: stored, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com', region: null }); }); + it('leaves out an empty field that had no stored value to show', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', region: 'eu', retries: '' }, + fields, + editingSecrets: new Set(), + storedSetupInformation: stored, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com', region: 'eu' }); + }); + it('leaves out a secret the user did not open, so the stored one is kept', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', apiKey: placeholder }, fields, editingSecrets: new Set(), - editing: true, + storedSetupInformation: stored, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); + }); + + it('leaves out a secret the user opened and left empty, so the stored one is kept', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', apiToken: '' }, + fields, + editingSecrets: new Set(['apiToken']), + storedSetupInformation: stored, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); }); - it('sends a secret the user opened and emptied as null', () => { + it('never clears a secret field, even one with a stored setup value', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', apiToken: '' }, fields, editingSecrets: new Set(['apiToken']), - editing: true, + storedSetupInformation: { ...stored, apiToken: 'legacy-token' }, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); + }); + + it('sends a placeholder the user opened as it stands', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', apiKey: placeholder }, + fields, + editingSecrets: new Set(['apiKey']), + storedSetupInformation: stored, }); - expect(actual).toEqual({ apiUrl: 'https://api.example.com', apiToken: null }); + expect(actual).toEqual({ apiUrl: 'https://api.example.com', apiKey: placeholder }); }); it('sends a value the user entered', () => { const actual = buildCredentialsPayload({ - formData: { apiUrl: 'https://api.example.com', apiKey: 'new-key', region: 'eu' }, + formData: { apiUrl: 'https://api.example.com', apiKey: 'new-key', region: 'us' }, fields, editingSecrets: new Set(['apiKey']), - editing: true, + storedSetupInformation: stored, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com', apiKey: 'new-key', - region: 'eu', + region: 'us', }); }); }); - describe('when creating an account', () => { + describe('when nothing stored was shown, as on a new account or another profile', () => { it('leaves out an empty field', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', region: '', apiToken: '' }, fields, editingSecrets: new Set(), - editing: false, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); diff --git a/src/modules/integration-picker/utils/credentialsPayload.ts b/src/modules/integration-picker/utils/credentialsPayload.ts index 42e5e36..932a634 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.ts @@ -11,36 +11,57 @@ const untouchedSecretKeys = ( fields: ConnectorConfigField[], editingSecrets: Set, ) => - fields - .filter( - (field) => - isSecretField(field) && - isSecretPlaceholder(formData[field.key]) && - !editingSecrets.has(field.key), - ) - .map((field) => field.key); + new Set( + fields + .filter( + (field) => + isSecretField(field) && + isSecretPlaceholder(formData[field.key]) && + !editingSecrets.has(field.key), + ) + .map((field) => field.key), + ); + +const clearedKeys = ( + formData: Record, + fields: ConnectorConfigField[], + storedSetupInformation: Record, +) => + new Set( + fields + .filter( + (field) => + !isSecretField(field) && + formData[field.key] === '' && + !!storedSetupInformation[field.key], + ) + .map((field) => field.key), + ); /** - * An edit sends a cleared field as `null` so the API removes the stored value; a new account - * has nothing stored, so it simply omits the field. + * A field the form showed with its stored value and the user emptied is sent as `null`, so the + * API removes it. Secrets are never cleared this way: opening one empties it before any typing. */ export const buildCredentialsPayload = ({ formData, fields, editingSecrets, - editing, + storedSetupInformation, }: { formData: Record; fields: ConnectorConfigField[]; editingSecrets: Set; - editing: boolean; + storedSetupInformation?: Record; }): CredentialsPayload => { - const keptSecrets = editing ? untouchedSecretKeys(formData, fields, editingSecrets) : []; + const keptSecrets = storedSetupInformation + ? untouchedSecretKeys(formData, fields, editingSecrets) + : new Set(); + const cleared = clearedKeys(formData, fields, storedSetupInformation ?? {}); return Object.fromEntries( Object.entries(formData) - .filter(([key, value]) => !keptSecrets.includes(key) && (editing || value !== '')) - .map(([key, value]) => [key, value === '' ? null : value]), + .filter(([key, value]) => !keptSecrets.has(key) && (value !== '' || cleared.has(key))) + .map(([key, value]) => [key, cleared.has(key) ? null : value]), ); }; From df8b48a3da637eca60ac07d7594c58a39c58d3b7 Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Thu, 19 Nov 2026 13:55:42 +0000 Subject: [PATCH 3/6] refactor(ENG-902): decide a clear from the value the form showed Re-deriving "was it shown" from setupInformation copied the prefill rule and missed a stored 0 shown as the connector default. The prefilled field already carries what the form showed, so the payload reads that. Create goes back to the null-free payload. Co-Authored-By: Claude Opus 5.5 --- .../hooks/useIntegrationPicker.ts | 6 +- .../utils/credentialsPayload.test.ts | 71 +++++++++---------- .../utils/credentialsPayload.ts | 27 +++---- 3 files changed, 42 insertions(+), 62 deletions(-) diff --git a/src/modules/integration-picker/hooks/useIntegrationPicker.ts b/src/modules/integration-picker/hooks/useIntegrationPicker.ts index 7651a8f..79bf5e0 100644 --- a/src/modules/integration-picker/hooks/useIntegrationPicker.ts +++ b/src/modules/integration-picker/hooks/useIntegrationPicker.ts @@ -565,9 +565,7 @@ export const useIntegrationPicker = ({ formData, fields, editingSecrets, - storedSetupInformation: prefillAccount - ? (prefillAccount.setupInformation ?? {}) - : undefined, + editing: !!prefillAccount, }); const filledCredentials = withoutClearedFields(credentials); @@ -690,7 +688,7 @@ export const useIntegrationPicker = ({ const response = await connectAccount({ baseUrl, token, - credentials, + credentials: filledCredentials, integrationId: selectedIntegration.integration_id, }); if (!response) { diff --git a/src/modules/integration-picker/utils/credentialsPayload.test.ts b/src/modules/integration-picker/utils/credentialsPayload.test.ts index 75f07c6..ab8bbd2 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.test.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.test.ts @@ -14,46 +14,49 @@ const field = (overrides: Partial): ConnectorConfigField = const placeholder = '__secretvalue:**redacted**1234'; -const fields = [ - field({ key: 'apiUrl', required: true }), - field({ key: 'region' }), - field({ key: 'retries' }), - field({ key: 'apiKey', secret: true, required: true }), - field({ key: 'apiToken', type: 'password' }), +const shownFields = [ + field({ key: 'apiUrl', required: true, value: 'https://api.example.com' }), + field({ key: 'region', value: 'eu' }), + field({ key: 'retries', value: '3' }), + field({ key: 'subdomain' }), + field({ key: 'apiKey', secret: true, required: true, value: placeholder }), + field({ key: 'apiToken', type: 'password', value: placeholder }), ]; -const stored = { apiUrl: 'https://api.example.com', region: 'eu' }; - describe('buildCredentialsPayload', () => { describe('when editing an account', () => { - it('sends a field the user emptied as null', () => { + it('sends a field the form showed with a value and the user emptied as null', () => { const actual = buildCredentialsPayload({ - formData: { apiUrl: 'https://api.example.com', region: '' }, - fields, + formData: { apiUrl: 'https://api.example.com', region: '', retries: '' }, + fields: shownFields, editingSecrets: new Set(), - storedSetupInformation: stored, + editing: true, }); - expect(actual).toEqual({ apiUrl: 'https://api.example.com', region: null }); + expect(actual).toEqual({ + apiUrl: 'https://api.example.com', + region: null, + retries: null, + }); }); - it('leaves out an empty field that had no stored value to show', () => { + it('leaves out an empty field the form showed without a value', () => { const actual = buildCredentialsPayload({ - formData: { apiUrl: 'https://api.example.com', region: 'eu', retries: '' }, - fields, + formData: { apiUrl: 'https://api.example.com', subdomain: '' }, + fields: shownFields, editingSecrets: new Set(), - storedSetupInformation: stored, + editing: true, }); - expect(actual).toEqual({ apiUrl: 'https://api.example.com', region: 'eu' }); + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); }); it('leaves out a secret the user did not open, so the stored one is kept', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', apiKey: placeholder }, - fields, + fields: shownFields, editingSecrets: new Set(), - storedSetupInformation: stored, + editing: true, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); @@ -62,20 +65,9 @@ describe('buildCredentialsPayload', () => { it('leaves out a secret the user opened and left empty, so the stored one is kept', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', apiToken: '' }, - fields, - editingSecrets: new Set(['apiToken']), - storedSetupInformation: stored, - }); - - expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); - }); - - it('never clears a secret field, even one with a stored setup value', () => { - const actual = buildCredentialsPayload({ - formData: { apiUrl: 'https://api.example.com', apiToken: '' }, - fields, + fields: shownFields, editingSecrets: new Set(['apiToken']), - storedSetupInformation: { ...stored, apiToken: 'legacy-token' }, + editing: true, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); @@ -84,9 +76,9 @@ describe('buildCredentialsPayload', () => { it('sends a placeholder the user opened as it stands', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', apiKey: placeholder }, - fields, + fields: shownFields, editingSecrets: new Set(['apiKey']), - storedSetupInformation: stored, + editing: true, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com', apiKey: placeholder }); @@ -95,9 +87,9 @@ describe('buildCredentialsPayload', () => { it('sends a value the user entered', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', apiKey: 'new-key', region: 'us' }, - fields, + fields: shownFields, editingSecrets: new Set(['apiKey']), - storedSetupInformation: stored, + editing: true, }); expect(actual).toEqual({ @@ -108,12 +100,13 @@ describe('buildCredentialsPayload', () => { }); }); - describe('when nothing stored was shown, as on a new account or another profile', () => { + describe('when nothing stored is shown, as on a new account or another profile', () => { it('leaves out an empty field', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', region: '', apiToken: '' }, - fields, + fields: shownFields, editingSecrets: new Set(), + editing: false, }); expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); diff --git a/src/modules/integration-picker/utils/credentialsPayload.ts b/src/modules/integration-picker/utils/credentialsPayload.ts index 932a634..f7be384 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.ts @@ -22,41 +22,30 @@ const untouchedSecretKeys = ( .map((field) => field.key), ); -const clearedKeys = ( - formData: Record, - fields: ConnectorConfigField[], - storedSetupInformation: Record, -) => +const emptiedKeys = (formData: Record, fields: ConnectorConfigField[]) => new Set( fields - .filter( - (field) => - !isSecretField(field) && - formData[field.key] === '' && - !!storedSetupInformation[field.key], - ) + .filter((field) => !isSecretField(field) && !!field.value && formData[field.key] === '') .map((field) => field.key), ); /** - * A field the form showed with its stored value and the user emptied is sent as `null`, so the - * API removes it. Secrets are never cleared this way: opening one empties it before any typing. + * On an edit, a field the form showed with a value and the user emptied is sent as `null`, so + * the API removes it. Secrets are never cleared this way: opening one empties it before any typing. */ export const buildCredentialsPayload = ({ formData, fields, editingSecrets, - storedSetupInformation, + editing, }: { formData: Record; fields: ConnectorConfigField[]; editingSecrets: Set; - storedSetupInformation?: Record; + editing: boolean; }): CredentialsPayload => { - const keptSecrets = storedSetupInformation - ? untouchedSecretKeys(formData, fields, editingSecrets) - : new Set(); - const cleared = clearedKeys(formData, fields, storedSetupInformation ?? {}); + const keptSecrets = editing ? untouchedSecretKeys(formData, fields, editingSecrets) : new Set(); + const cleared = editing ? emptiedKeys(formData, fields) : new Set(); return Object.fromEntries( Object.entries(formData) From d6ec9ca6e160d80398d149ad3d2a5a452c497096 Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Thu, 19 Nov 2026 14:04:03 +0000 Subject: [PATCH 4/6] refactor(ENG-902): share the form's shown value with the clear rule The form's default values and the payload's "was it shown" check now come from one shownFieldValue, so a numeric 0 the form displays as "0" can be cleared too. Secret placeholders are stripped whenever present, since they only ever arrive through the prefill. Co-Authored-By: Claude Opus 5.5 --- .../components/IntegrationFields.tsx | 11 ++------ .../utils/credentialsPayload.test.ts | 25 +++++++++++++++++++ .../utils/credentialsPayload.ts | 14 ++++++++--- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/modules/integration-picker/components/IntegrationFields.tsx b/src/modules/integration-picker/components/IntegrationFields.tsx index 9bd9dcb..20f58c4 100644 --- a/src/modules/integration-picker/components/IntegrationFields.tsx +++ b/src/modules/integration-picker/components/IntegrationFields.tsx @@ -20,6 +20,7 @@ import { FieldErrors, UseFormSetValue } from 'react-hook-form'; import { useForm } from 'react-hook-form'; import useDeepCompareEffect from 'use-deep-compare-effect'; import { AuthenticationNotice, ConnectorConfigField } from '../types'; +import { shownFieldValue } from '../utils/credentialsPayload'; import { partitionNotices } from '../utils/partitionNotices'; import { formatSecretPlaceholder, isSecretPlaceholder } from '../utils/secretPlaceholder'; import { @@ -309,15 +310,7 @@ export const IntegrationForm: React.FC = ({ const schema = useMemo(() => createFormSchema(fields, rules), [fields, rules]); const defaultValues = useMemo(() => { - const initialData: Record = {}; - fields.forEach((field) => { - if (field.value !== undefined) { - initialData[field.key] = field.value.toString(); - } else { - initialData[field.key] = ''; - } - }); - return initialData; + return Object.fromEntries(fields.map((field) => [field.key, shownFieldValue(field)])); }, [fields]); const { formState, watch, reset, setValue, getValues } = useForm({ diff --git a/src/modules/integration-picker/utils/credentialsPayload.test.ts b/src/modules/integration-picker/utils/credentialsPayload.test.ts index ab8bbd2..99e6c58 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.test.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.test.ts @@ -40,6 +40,31 @@ describe('buildCredentialsPayload', () => { }); }); + it('sends a field showing a connector default the user emptied as null', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', timeout: '' }, + fields: [...shownFields, field({ key: 'timeout', type: 'number', value: 0 })], + editingSecrets: new Set(), + editing: true, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com', timeout: null }); + }); + + it('never clears a secret field, even one showing a real value', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', apiToken: '' }, + fields: [ + ...shownFields.filter((f) => f.key !== 'apiToken'), + field({ key: 'apiToken', type: 'password', value: 'legacy-token' }), + ], + editingSecrets: new Set(['apiToken']), + editing: true, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); + }); + it('leaves out an empty field the form showed without a value', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', subdomain: '' }, diff --git a/src/modules/integration-picker/utils/credentialsPayload.ts b/src/modules/integration-picker/utils/credentialsPayload.ts index f7be384..6869628 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.ts @@ -3,6 +3,9 @@ import { isSecretPlaceholder } from './secretPlaceholder'; export type CredentialsPayload = Record; +export const shownFieldValue = (field: ConnectorConfigField): string => + field.value === undefined ? '' : field.value.toString(); + const isSecretField = (field: ConnectorConfigField) => field.secret !== false || field.type === 'password'; @@ -25,7 +28,12 @@ const untouchedSecretKeys = ( const emptiedKeys = (formData: Record, fields: ConnectorConfigField[]) => new Set( fields - .filter((field) => !isSecretField(field) && !!field.value && formData[field.key] === '') + .filter( + (field) => + !isSecretField(field) && + shownFieldValue(field) !== '' && + formData[field.key] === '', + ) .map((field) => field.key), ); @@ -44,8 +52,8 @@ export const buildCredentialsPayload = ({ editingSecrets: Set; editing: boolean; }): CredentialsPayload => { - const keptSecrets = editing ? untouchedSecretKeys(formData, fields, editingSecrets) : new Set(); - const cleared = editing ? emptiedKeys(formData, fields) : new Set(); + const keptSecrets = untouchedSecretKeys(formData, fields, editingSecrets); + const cleared = editing ? emptiedKeys(formData, fields) : new Set(); return Object.fromEntries( Object.entries(formData) From 9745845079f6fd520a7e269bc6051c9fb0949b19 Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Thu, 19 Nov 2026 15:59:09 +0000 Subject: [PATCH 5/6] fix(ENG-902): never clear a required field from the hub The API only clears optional fields; the hub now applies the same rule instead of relying on form validation to keep a required field from going out empty. Co-Authored-By: Claude Opus 5.5 --- .../utils/credentialsPayload.test.ts | 11 +++++++++++ .../integration-picker/utils/credentialsPayload.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/modules/integration-picker/utils/credentialsPayload.test.ts b/src/modules/integration-picker/utils/credentialsPayload.test.ts index 99e6c58..b44bf1c 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.test.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.test.ts @@ -65,6 +65,17 @@ describe('buildCredentialsPayload', () => { expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); }); + it('never clears a required field, leaving the stored value to the API', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: '', region: 'eu' }, + fields: shownFields, + editingSecrets: new Set(), + editing: true, + }); + + expect(actual).toEqual({ region: 'eu' }); + }); + it('leaves out an empty field the form showed without a value', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: 'https://api.example.com', subdomain: '' }, diff --git a/src/modules/integration-picker/utils/credentialsPayload.ts b/src/modules/integration-picker/utils/credentialsPayload.ts index 6869628..07c8faa 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.ts @@ -31,6 +31,7 @@ const emptiedKeys = (formData: Record, fields: ConnectorConfigFi .filter( (field) => !isSecretField(field) && + field.required !== true && shownFieldValue(field) !== '' && formData[field.key] === '', ) From 940713361269a2733f298b1552b1f512997c5756 Mon Sep 17 00:00:00 2001 From: Joao Miguel Date: Thu, 19 Nov 2026 17:03:03 +0000 Subject: [PATCH 6/6] test(ENG-902): pin a field without a secret flag as a secret The API stores a field with no `secret` flag in the secret bundle, and the hub prefills it from secrets, so the clear rule treats it as a secret too. A fixture without the flag now pins that. Co-Authored-By: Claude Opus 5.5 --- .../utils/credentialsPayload.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/modules/integration-picker/utils/credentialsPayload.test.ts b/src/modules/integration-picker/utils/credentialsPayload.test.ts index b44bf1c..543d8e1 100644 --- a/src/modules/integration-picker/utils/credentialsPayload.test.ts +++ b/src/modules/integration-picker/utils/credentialsPayload.test.ts @@ -65,6 +65,20 @@ describe('buildCredentialsPayload', () => { expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); }); + it('treats a field without a secret flag as a secret, as the API stores it', () => { + const actual = buildCredentialsPayload({ + formData: { apiUrl: 'https://api.example.com', webhookKey: '' }, + fields: [ + ...shownFields, + field({ key: 'webhookKey', secret: undefined, value: placeholder }), + ], + editingSecrets: new Set(['webhookKey']), + editing: true, + }); + + expect(actual).toEqual({ apiUrl: 'https://api.example.com' }); + }); + it('never clears a required field, leaving the stored value to the API', () => { const actual = buildCredentialsPayload({ formData: { apiUrl: '', region: 'eu' },