Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions configs/platform/system/connectors/imap-smtp/connector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ configFields:
label: Connection security
type: string
enum: [tls, starttls]
optionLabels:
tls: Implicit TLS
starttls: STARTTLS
default: tls
description: >-
Fallback when a port is not standard. Ports 465 and 993 always use
Expand All @@ -84,9 +87,15 @@ configFields:
de:
label: 'Verbindungssicherheit'
description: 'Fallback, wenn ein Port nicht dem Standard entspricht. Die Ports 465 und 993 verwenden immer implizites TLS, die Ports 587 und 143 immer STARTTLS.'
optionLabels:
tls: 'Implizites TLS'
starttls: 'STARTTLS'
fr:
label: 'Sécurité de la connexion'
description: 'Solution de repli quand un port n’est pas standard. Les ports 465 et 993 utilisent toujours le TLS implicite ; les ports 587 et 143 utilisent toujours STARTTLS.'
optionLabels:
tls: 'TLS implicite'
starttls: 'STARTTLS'
- key: sentMailbox
label: Sent folder
type: string
Expand All @@ -107,6 +116,13 @@ configFields:
description: >-
Mailbox address used as Conversations From / inbox source. Set
automatically from the login username.
i18n:
de:
label: 'Absenderadresse'
description: 'Die Postfachadresse, die als Absender der Konversationen und als Quelle des Posteingangs dient. Wird automatisch aus dem Benutzernamen der Anmeldung übernommen.'
fr:
label: 'Adresse d’expéditeur'
description: 'L’adresse de boîte utilisée comme expéditeur des conversations et comme source de la boîte de réception. Définie automatiquement à partir du nom d’utilisateur de connexion.'
auth:
- method: basic
actions:
Expand Down
2 changes: 1 addition & 1 deletion docs/de/develop/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Ein Connector, dessen Name aus gewöhnlichen Wörtern besteht, etwa `task` (Task
| `endpointMode: fixed` | Standard. Live-HTTP-Aufrufe verwenden feste Anbieter-URLs; `allowedHosts` enthält genaue Hostnamen |
| `endpointMode: per-credential` | Jeder Zugang enthält eine HTTPS-`endpointUrl`; Aktionen lesen den Ursprung ohne abschließenden Schrägstrich über `ctx.endpoint` |
| `allowedHosts` bei per-credential | Hostsuffixe: `atlassian.net` erlaubt seine Subdomains |
| `configFields` | Nicht geheime Angaben je Zugang, etwa Serverhost, Port, Region oder API-Version; `label` und `description` eines Felds nehmen für das Formular der Zugangsdaten Übersetzungen unter `i18n.de` und `i18n.fr`. `required` macht ein Feld für alle Zugangsdaten zur Pflicht; `requiredFor` nennt die Authentifizierungsmethoden, für die es Pflicht ist, etwa Outlooks `mailbox` für `client-credentials`; `fixed: true` legt ein Feld beim Hinzufügen der Zugangsdaten fest und lehnt eine Bearbeitung ab, die es ändert, für einen Wert, der bestimmt, wo die Zugangsdaten arbeiten, etwa Outlooks `mailbox`; `format: email` lässt ein `string`-Feld nur eine E-Mail-Adresse annehmen, geprüft vom Formular und vom Server, etwa Outlooks `mailbox` |
| `configFields` | Nicht geheime Angaben je Zugang, etwa Serverhost, Port, Region oder API-Version; `label`, `description` und `optionLabels` eines Felds (was die Auswahl im Formular für jeden `enum`-Wert zeigt, etwa `tls: Implicit TLS`) nehmen für das Formular der Zugangsdaten Übersetzungen unter `i18n.de` und `i18n.fr`. `required` macht ein Feld für alle Zugangsdaten zur Pflicht; `requiredFor` nennt die Authentifizierungsmethoden, für die es Pflicht ist, etwa Outlooks `mailbox` für `client-credentials`; `fixed: true` legt ein Feld beim Hinzufügen der Zugangsdaten fest und lehnt eine Bearbeitung ab, die es ändert, für einen Wert, der bestimmt, wo die Zugangsdaten arbeiten, etwa Outlooks `mailbox`; `format: email` lässt ein `string`-Feld nur eine E-Mail-Adresse annehmen, geprüft vom Formular und vom Server, etwa Outlooks `mailbox` |
| `livePrelude` | Optionales JavaScript, mit dem jeder `yaml-js`-Live-Body des Connectors beginnt, im Scope des Bodys: Hilfsfunktionen, die sich die Aktionen teilen, etwa Outlooks Graph-Wurzel und Fehlermeldungen |
| `git` | Optional: Die Zugangsdaten öffnen auch die Git-Remotes des Anbieters über HTTPS. `host` ist ein fester Git-Host wie `github.com` oder `endpoint` für den Host der Instanzadresse der jeweiligen Zugangsdaten (nur bei Ursprüngen je Zugang), der wie die HTTP-Aufrufe des Connectors dessen `allowedHosts` und die Regel für private Adressen erfüllen muss; `username` ist, was Git neben dem Token sendet, und `basic`-Zugangsdaten senden stattdessen ihren eigenen |

Expand Down
2 changes: 1 addition & 1 deletion docs/en/develop/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A connector named with ordinary words, such as `task` (Tasks), also declares `i1
| `endpointMode: fixed` | Default. Live HTTP calls use fixed vendor URLs; `allowedHosts` contains exact hosts |
| `endpointMode: per-credential` | Each credential supplies an HTTPS `endpointUrl`; actions read its origin as `ctx.endpoint`, without a trailing slash |
| `allowedHosts` in per-credential mode | Host suffixes: `atlassian.net` allows its subdomains |
| `configFields` | Non-secret per-credential values such as server host, port, region, or API version; a field's `label` and `description` take `i18n.de` and `i18n.fr` overrides for the credential form. `required` makes a field mandatory for every credential; `requiredFor` lists the authentication methods it is mandatory for, such as Outlook's `mailbox` for `client-credentials`; `fixed: true` sets a field when the credential is added and refuses an edit that changes it, for a value that decides where the credential acts, such as Outlook's `mailbox`; `format: email` makes a `string` field take a mail address only, checked by the form and the server, such as Outlook's `mailbox` |
| `configFields` | Non-secret per-credential values such as server host, port, region, or API version; a field's `label`, `description` and `optionLabels` (what the form's select shows for each `enum` value, such as `tls: Implicit TLS`) take `i18n.de` and `i18n.fr` overrides for the credential form. `required` makes a field mandatory for every credential; `requiredFor` lists the authentication methods it is mandatory for, such as Outlook's `mailbox` for `client-credentials`; `fixed: true` sets a field when the credential is added and refuses an edit that changes it, for a value that decides where the credential acts, such as Outlook's `mailbox`; `format: email` makes a `string` field take a mail address only, checked by the form and the server, such as Outlook's `mailbox` |
| `livePrelude` | Optional JavaScript every `yaml-js` live body of the connector starts with, in the body's scope: helpers the actions share, such as Outlook's Graph root and refusal messages |
| `git` | Optional: the credential also opens the vendor's Git remotes over HTTPS. `host` is a fixed Git host, such as `github.com`, or `endpoint` for the host of each credential's own instance address (per-credential connectors only), which must pass the connector's `allowedHosts` and the private-address policy, as its HTTP calls do; `username` is what Git sends beside the token, and a `basic` credential sends its own instead |

Expand Down
2 changes: 1 addition & 1 deletion docs/fr/develop/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Un connector dont le nom est fait de mots courants, comme `task` (Tasks), décla
| `endpointMode: fixed` | Valeur par défaut. Les appels HTTP réels utilisent des URL fixes ; `allowedHosts` contient les hôtes exacts |
| `endpointMode: per-credential` | Chaque identifiant fournit une `endpointUrl` HTTPS ; les actions lisent son origine sans barre oblique finale via `ctx.endpoint` |
| `allowedHosts` en mode per-credential | Suffixes d'hôtes : `atlassian.net` autorise ses sous-domaines |
| `configFields` | Valeurs non secrètes propres à l'identifiant : hôte, port, région ou version d'API ; le `label` et la `description` d'un champ prennent des traductions sous `i18n.de` et `i18n.fr` pour le formulaire des identifiants. `required` rend un champ obligatoire pour tous les identifiants ; `requiredFor` liste les méthodes d'authentification pour lesquelles il l'est, comme le `mailbox` d'Outlook pour `client-credentials` ; `fixed: true` fixe un champ à l'ajout des identifiants et refuse une modification qui le change, pour une valeur qui détermine où les identifiants agissent, comme le `mailbox` d'Outlook ; `format: email` limite un champ `string` à une adresse e-mail, vérifiée par le formulaire et par le serveur, comme le `mailbox` d'Outlook |
| `configFields` | Valeurs non secrètes propres à l'identifiant : hôte, port, région ou version d'API ; le `label`, la `description` et les `optionLabels` d'un champ (ce que la liste déroulante du formulaire affiche pour chaque valeur d'`enum`, comme `tls: Implicit TLS`) prennent des traductions sous `i18n.de` et `i18n.fr` pour le formulaire des identifiants. `required` rend un champ obligatoire pour tous les identifiants ; `requiredFor` liste les méthodes d'authentification pour lesquelles il l'est, comme le `mailbox` d'Outlook pour `client-credentials` ; `fixed: true` fixe un champ à l'ajout des identifiants et refuse une modification qui le change, pour une valeur qui détermine où les identifiants agissent, comme le `mailbox` d'Outlook ; `format: email` limite un champ `string` à une adresse e-mail, vérifiée par le formulaire et par le serveur, comme le `mailbox` d'Outlook |
| `livePrelude` | JavaScript facultatif par lequel commence chaque corps `yaml-js` du connector, dans la portée du corps : des fonctions que les actions partagent, comme la racine Graph et les messages d'erreur d'Outlook |
| `git` | Facultatif : l'identifiant ouvre aussi les remotes Git du fournisseur en HTTPS. `host` est un hôte Git fixe, comme `github.com`, ou `endpoint` pour l'hôte de l'adresse d'instance de chaque identifiant (connectors à origine propre à l'identifiant uniquement), qui doit, comme les appels HTTP du connector, respecter ses `allowedHosts` et la règle des adresses privées ; `username` est ce que Git envoie avec le jeton, et un identifiant `basic` envoie le sien à la place |

Expand Down
66 changes: 66 additions & 0 deletions packages/shared/src/schemas/connectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,72 @@ describe('connectorSchema', () => {
}
});

it('labels the options of a select field, in English and per locale, and only its own values', () => {
const mailbox = connectorSchema.parse(MAILBOX);
const field = {
key: 'security',
label: 'Connection security',
type: 'string',
enum: ['tls', 'starttls'],
};
const labelled = connectorSchema.parse({
...mailbox,
configFields: [
{
...field,
optionLabels: { tls: 'Implicit TLS', starttls: 'STARTTLS' },
// A translation may name some of the options; the rest fall back.
i18n: { de: { optionLabels: { tls: 'Implizites TLS' } } },
},
],
});
expect(labelled.configFields[0]?.optionLabels).toEqual({
tls: 'Implicit TLS',
starttls: 'STARTTLS',
});
expect(labelled.configFields[0]?.i18n?.de?.optionLabels).toEqual({
tls: 'Implizites TLS',
});

const refusals = (configField: object) =>
connectorSchema
.safeParse({ ...mailbox, configFields: [configField] })
.error?.issues.map(({ path, message }) => ({ path, message }));
// A label for a value the field does not take, in English or translated.
expect(refusals({ ...field, optionLabels: { ssl: 'SSL' } })).toEqual([
{
path: ['configFields', 0, 'optionLabels', 'ssl'],
message:
'optionLabels names "ssl", which is not one of the field\'s enum values',
},
]);
expect(
refusals({ ...field, i18n: { fr: { optionLabels: { ssl: 'SSL' } } } }),
).toEqual([
{
path: ['configFields', 0, 'i18n', 'fr', 'optionLabels', 'ssl'],
message:
'optionLabels names "ssl", which is not one of the field\'s enum values',
},
]);
// A field without options has none to label.
expect(
refusals({
key: 'imapHost',
label: 'IMAP server',
type: 'string',
optionLabels: { tls: 'Implicit TLS' },
}),
).toEqual([
{
path: ['configFields', 0, 'optionLabels', 'tls'],
message:
'optionLabels names "tls", which is not one of the field\'s enum values',
},
]);
expect(refusals({ ...field, optionLabels: { tls: '' } })).toHaveLength(1);
});

it('requires a mock on every action', () => {
const github = connectorSchema.parse(GITHUB);
const noMock = {
Expand Down
34 changes: 31 additions & 3 deletions packages/shared/src/schemas/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ const configKeySchema = z
* the connector's display name ("GitHub · List issues"). */
const actionTitleSchema = z.string().min(1).max(80);

/** What a select shows for each of a config field's `enum` values, keyed by
* the value ("Implicit TLS" for `tls`). */
const optionLabelsSchema = z.record(
z.string().min(1),
z.string().min(1).max(120),
);

/**
* The auth methods a connector accepts — discriminated on `method`, MULTIPLE
* per connector, decoupled from the actions. A credential row references one
Expand Down Expand Up @@ -263,22 +270,26 @@ const configFieldSchema = z
format: z.enum(['email']).optional(),
/** Closed set of accepted values, for a `string` field rendered as a select. */
enum: z.array(z.string().min(1)).min(1).optional(),
/** The select's English label for each `enum` value; a value without
* one shows as itself. The value stays what is stored and checked. */
optionLabels: optionLabelsSchema.optional(),
/** Numeric constraints for number fields. */
integer: z.boolean().optional(),
min: z.number().finite().optional(),
max: z.number().finite().optional(),
/** Applied when the field is absent; must match `type`. */
default: z.union([z.string(), z.number(), z.boolean()]).optional(),
/** Per-locale overrides of the label and description a form shows,
* same locale chain as an action's `title`: exact tag, then base
* language, then the authored English. */
/** Per-locale overrides of the label, description and option labels a
* form shows, same locale chain as an action's `title`: exact tag, then
* base language, then the authored English — each option on its own. */
i18n: z
.record(
z.string().regex(LOCALE_RE),
z
.object({
label: z.string().min(1).max(120).optional(),
description: z.string().max(2000).optional(),
optionLabels: optionLabelsSchema.optional(),
})
.strict(),
)
Expand Down Expand Up @@ -480,6 +491,23 @@ export const connectorSchema = z
path: ['configFields', index, 'requiredFor'],
message: `requiredFor names ${method}, which the connector does not accept`,
});
// A label for a value the field does not take could never be shown.
const values = new Set(field.enum ?? []);
const labelSets = [
{ at: ['optionLabels'], labels: field.optionLabels },
...Object.entries(field.i18n ?? {}).map(([locale, text]) => ({
at: ['i18n', locale, 'optionLabels'],
labels: text.optionLabels,
})),
];
for (const { at, labels } of labelSets)
for (const value of Object.keys(labels ?? {}))
if (!values.has(value))
context.addIssue({
code: 'custom',
path: ['configFields', index, ...at, value],
message: `optionLabels names "${value}", which is not one of the field's enum values`,
});
});
});
export type Connector = z.infer<typeof connectorSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,91 @@ describe('the declared fields in the reader’s language', () => {
});
expect(input).toHaveAccessibleDescription(help);
});

const securityField: ConnectorSummary['configFields'][number] = {
key: 'security',
label: 'Connection security',
type: 'string',
required: false,
// `none` is labelled in no language, so it shows as itself.
enum: ['tls', 'starttls', 'none'],
optionLabels: { tls: 'Implicit TLS', starttls: 'STARTTLS' },
default: 'tls',
i18n: {
de: {
label: 'Verbindungssicherheit',
optionLabels: { tls: 'Implizites TLS', starttls: 'STARTTLS' },
},
// French names one option; the other falls back to English.
fr: {
label: 'Sécurité de la connexion',
optionLabels: { tls: 'TLS implicite' },
},
// A regional override of one option; the other comes from German.
'de-CH': { optionLabels: { starttls: 'STARTTLS (CH)' } },
},
};

it.each([
['en', 'Connection security', ['Implicit TLS', 'STARTTLS', 'none']],
['de', 'Verbindungssicherheit', ['Implizites TLS', 'STARTTLS', 'none']],
['fr', 'Sécurité de la connexion', ['TLS implicite', 'STARTTLS', 'none']],
[
'de-CH',
'Verbindungssicherheit',
['Implizites TLS', 'STARTTLS (CH)', 'none'],
],
])(
'names the options of a select in %s, each through the locale chain',
async (locale, label, options) => {
localStorage.setItem('user-locale', locale);
await i18n.changeLanguage(locale);
const Fields = extras.Fields;
if (Fields === null) throw new Error('the config fields are missing');
const { user } = render(
<Fields
vendor={{ summary: summary([securityField]) }}
value={{}}
onChange={() => {}}
/>,
);
const select = screen.getByRole('combobox', {
name: new RegExp(`^${label}`),
});
// The default shows by its label, not as the stored `tls`.
expect(select).toHaveTextContent(options[0] ?? '');
await user.click(select);
expect(
screen.getAllByRole('option').map((option) => option.textContent),
).toEqual(options);
},
);

it('shows a German reader none of the English it translates', async () => {
localStorage.setItem('user-locale', 'de');
await i18n.changeLanguage('de');
const Fields = extras.Fields;
if (Fields === null) throw new Error('the config fields are missing');
const { user } = render(
<Fields
vendor={{ summary: summary([...httpFields, securityField]) }}
value={{}}
onChange={() => {}}
/>,
);
await user.click(
screen.getByRole('combobox', { name: /^Verbindungssicherheit/ }),
);
expect(
screen.getByRole('option', { name: 'Implizites TLS' }),
).toBeVisible();
for (const english of [
'Base URL',
'The address every call stays under.',
'Connection security',
'Implicit TLS',
]) {
expect(document.body).not.toHaveTextContent(english);
}
});
});
Loading
Loading