diff --git a/.changeset/32799-host-mail-transport-live-environment.md b/.changeset/32799-host-mail-transport-live-environment.md new file mode 100644 index 00000000000..09dac7bcba1 --- /dev/null +++ b/.changeset/32799-host-mail-transport-live-environment.md @@ -0,0 +1,18 @@ +--- +'@objectstack/spec': patch +'@objectstack/service-settings': patch +'@objectstack/plugin-email': patch +--- + +fix(plugin-email): a host's own mail transport now reads as in use on `GET /api/settings/mail` (`live.provider` is `{ value: null, source: 'environment' }`) + +Clause-②: yes (widening) — the served `live` entry of `GET /api/settings/:namespace` now also admits `{ value: null, source: 'environment' }`; every entry served before is served unchanged +Metadata-protocol: none + +A transport the host application hands to `@objectstack/plugin-email` that no `provider` option names (a plain `IEmailTransport`, such as a hosted platform's mail channel) used to leave `live.provider` unstated, so the first-run checklist read mail as not set up while mail was being delivered. The plugin now states it as `{ value: null, source: 'environment' }`: in use, supplied by the environment or host, named by no option. + +- `@objectstack/spec`: `SettingsNamespacePayloadSchema.live` documents the reading. A non-null `value` is still always one of the key's options. `value` is `null` when `source` is `'none'` (nothing in use) or `'environment'` (in use, named by no option). Read whether something is in use from `source`, never from `value === null`. `'settings'` always names an option. The schema's shape is unchanged. +- `@objectstack/service-settings`: the live-value judge serves `environment` with a `null` value. `settings` with a `null` value is still dropped, and so is any entry on a key with no option table. +- `@objectstack/plugin-email`: the stock transports (`smtp`, `resend`, `postmark`) read as before. A transport swapped in through `EmailService.setTransport` is still not stated. + +A reader that took `value === null` to mean "nothing is in use" should read `source` instead: `source: 'none'` is the only "nothing is in use". diff --git a/content/docs/references/system/settings-manifest.mdx b/content/docs/references/system/settings-manifest.mdx index 3676481d59b..820172ae073 100644 --- a/content/docs/references/system/settings-manifest.mdx +++ b/content/docs/references/system/settings-manifest.mdx @@ -177,8 +177,8 @@ const result = ResolvedSettingValueSchema.parse(data); | Property | Type | Required | Description | | :--- | :--- | :--- | :--- | -| **value** | `string \| null` | ✅ | The option in use; null exactly when source is 'none' | -| **source** | `Enum<'settings' \| 'environment' \| 'none'>` | ✅ | Where the running system took it from: these settings, its own boot environment, or nothing in use | +| **value** | `string \| null` | ✅ | The option in use; null when source is 'none', or when source is 'environment' and no option names what is in use. Read in-use from source, never from a null value | +| **source** | `Enum<'settings' \| 'environment' \| 'none'>` | ✅ | Where the running system took it from: these settings, its own boot environment or host, or nothing in use | --- diff --git a/packages/plugins/plugin-email/src/live-transport-status.pin.test.ts b/packages/plugins/plugin-email/src/live-transport-status.pin.test.ts index cf6ed853ffe..c4da68fc8ec 100644 --- a/packages/plugins/plugin-email/src/live-transport-status.pin.test.ts +++ b/packages/plugins/plugin-email/src/live-transport-status.pin.test.ts @@ -101,6 +101,15 @@ describe('describeLiveMailTransport — the reading of isConfigured()', () => { expect(s.label).toBe('Mail is delivered through SMTP (smtp.example.test:2525)'); }); + it("a transport no option names is stated only as 'environment': 'settings' always names an option", () => { + const own: IEmailTransport = { send: async () => ({ messageId: 'host-own-0' }) } as never; + const svc = { isConfigured: () => true, options: { transport: own } }; + expect(describeLiveMailTransport(svc, 'en', 'environment').values) + .toEqual({ provider: { value: null, source: 'environment' } }); + expect(describeLiveMailTransport(svc, 'en', 'settings').values).toBeUndefined(); + expect(describeLiveMailTransport(svc, 'en').values).toBeUndefined(); + }); + it('the branch is isConfigured(), not the transport class', () => { const smtp = new SmtpTransport({ host: 'smtp.example.test' }); expect(describeLiveMailTransport({ isConfigured: () => false, options: { transport: smtp } }).label) @@ -342,16 +351,27 @@ describe('GET /api/settings/mail — live.provider states the provider in use', expect(banner(data)).toEqual({ label: 'No mail leaves this machine', bannerSeverity: 'warning' }); }); - it("states nothing for a transport no option names, or one this plugin did not install: unknown is not 'none'", async () => { + it("environment: the host's own transport, which no option names, reads { value: null, source: 'environment' }", async () => { + // A hosted platform's mail channel reaches the plugin this way: a plain + // IEmailTransport handed over as the constructor default, no stock class. const own: IEmailTransport = { send: async () => ({ messageId: 'host-own-1' }) } as never; const hosted = await serve({}, { transport: own }); const data = await hosted.read(); - expect('live' in data).toBe(false); - // The banner still names the host's transport. - expect(banner(data).bannerSeverity).toBe('info'); + expect(data.live).toEqual({ provider: { value: null, source: 'environment' } }); + // In use, so it is not 'none'; the banner still names the host's transport. + expect(banner(data)).toEqual({ + label: 'Mail is delivered through a transport supplied by the host application', bannerSeverity: 'info', + }); + }); + it("states nothing for a transport this plugin did not install: unknown is not 'none'", async () => { const swapped = await serve({}, { provider: 'smtp', providerOptions: { host: 'smtp.boot.test' } }); swapped.service.setTransport(new SmtpTransport({ host: 'smtp.elsewhere.test' })); expect('live' in (await swapped.read())).toBe(false); + + const own: IEmailTransport = { send: async () => ({ messageId: 'host-own-2' }) } as never; + const hostedSwapped = await serve({}, { transport: own }); + hostedSwapped.service.setTransport({ send: async () => ({ messageId: 'other-1' }) } as never); + expect('live' in (await hostedSwapped.read())).toBe(false); }); }); diff --git a/packages/plugins/plugin-email/src/live-transport-status.ts b/packages/plugins/plugin-email/src/live-transport-status.ts index 674e5e1a62b..96ea62b03b6 100644 --- a/packages/plugins/plugin-email/src/live-transport-status.ts +++ b/packages/plugins/plugin-email/src/live-transport-status.ts @@ -26,9 +26,12 @@ export interface LiveMailTransportStatus { * The provider in use, machine-readable, for a reader that needs the answer * and not the banner's prose (the console's first-run checklist). The * settings `GET` route serves it as the page's `live.provider`, the shape the - * `ai` namespace's runtime states its provider in. Absent = not stated: the - * live transport is one the `provider` options cannot name (a host's own - * transport class), or the plugin cannot say where it came from. + * `ai` namespace's runtime states its provider in. A transport the host + * handed over that no `provider` option names (a host's own transport class, + * such as a hosted platform's mail channel) is stated as + * `{ value: null, source: 'environment' }`: in use, supplied by the host, + * named by no option. Absent = not stated: the plugin cannot say where the + * live transport came from. */ values?: { provider: LiveMailProviderValue }; } @@ -45,8 +48,9 @@ export type LiveMailTransportOrigin = 'settings' | 'environment'; /** * The `provider` key's value in the running system: one of its options, or - * `null` when nothing delivers. Typed from the spec's served `live` entry, so a - * change to that shape fails this package's type-check. + * `null` when nothing delivers (`none`) or when the host's own transport, which + * no option names, delivers (`environment`). Typed from the spec's served + * `live` entry, so a change to that shape fails this package's type-check. */ export type LiveMailProviderValue = NonNullable[string]; @@ -335,8 +339,11 @@ function transportName(transport: IEmailTransport, copy: MailDeliveryCopy): stri * * `values.provider` states the provider in use: `{ value: null, source: 'none' }` * when nothing delivers, else the option naming the transport with the `origin` - * the caller holds for it. With no `origin`, or a transport no option names, the - * provider is not stated, which a reader tells from `none`. + * the caller holds for it. A transport no option names that came from the + * environment (the host handed it over) is `{ value: null, source: 'environment' }`: + * it delivers, and the spec's `live` entry reads in-use from `source`. With no + * `origin`, or a `settings` origin no option names, the provider is not stated, + * which a reader tells from `none`. */ export function describeLiveMailTransport( source: LiveMailTransportSource, @@ -356,5 +363,6 @@ export function describeLiveMailTransport( }; const option = providerOptionOf(source.options.transport); if (option && origin) status.values = { provider: { value: option, source: origin } }; + else if (!option && origin === 'environment') status.values = { provider: { value: null, source: 'environment' } }; return status; } diff --git a/packages/services/service-settings/src/settings-routes.live-status.pin.test.ts b/packages/services/service-settings/src/settings-routes.live-status.pin.test.ts index 04f92dae998..9340799311d 100644 --- a/packages/services/service-settings/src/settings-routes.live-status.pin.test.ts +++ b/packages/services/service-settings/src/settings-routes.live-status.pin.test.ts @@ -163,6 +163,20 @@ describe('GET /api/settings/:namespace — the live values the runtime states', expect(SettingsNamespacePayloadSchema.safeParse(body.data).success).toBe(true); }); + it('serves "environment" with no value: in use, supplied by the host, named by no option', async () => { + const { svc, read, logger } = rig(); + svc.registerLiveStatus('mail', () => ({ + label: 'Mail is delivered through a transport supplied by the host application', + bannerText: 'In use.', bannerSeverity: 'info', + values: { provider: { value: null, source: 'environment' } }, + })); + const { status, body } = await read(); + expect(status).toBe(200); + expect(body.data.live).toEqual({ provider: { value: null, source: 'environment' } }); + expect(logger.warn).not.toHaveBeenCalled(); + expect(SettingsNamespacePayloadSchema.safeParse(body.data).success).toBe(true); + }); + it('⛔ serves only the value and its source: a credential the runtime attaches never leaves', async () => { const { svc, read } = rig(aiSettingsManifest); svc.registerLiveStatus('ai', () => ({ @@ -204,7 +218,8 @@ describe('GET /api/settings/:namespace — the live values the runtime states', ['a key the namespace does not declare', { api_key: { value: 'openai', source: 'environment' } }], ['a source outside the closed set', { provider: { value: 'openai', source: 'env' } }], ['a value under source "none"', { provider: { value: 'openai', source: 'none' } }], - ['no value under a source other than "none"', { provider: { value: null, source: 'settings' } }], + ['no value under source "settings"', { provider: { value: null, source: 'settings' } }], + ['a key with no option table, even as "environment" with no value', { openai_model: { value: null, source: 'environment' } }], ['an entry that is not { value, source }', { provider: 'openai' }], ])('leaves out an entry naming %s, keeping the stated banner', async (_what, values) => { const { svc, read, logger } = rig(aiSettingsManifest); diff --git a/packages/services/service-settings/src/settings-service.ts b/packages/services/service-settings/src/settings-service.ts index 2a536039cd5..d4778e068c1 100644 --- a/packages/services/service-settings/src/settings-service.ts +++ b/packages/services/service-settings/src/settings-service.ts @@ -2276,7 +2276,9 @@ export class SettingsService { * is not servable is left out and named in `dropped`, by its key and why, * never by its value: the key is not an option-bearing key of the * namespace, the value is not one its option table admits, or `value` and - * `source` disagree about "none". The value is kept out of `dropped` + * `source` disagree about "none" (only `'environment'` may also carry a null + * value: in use, supplied by the host, named by no option; `'settings'` + * always names one). The value is kept out of `dropped` * because an entry this wrong may be carrying the very credential the rule * keeps off the page. */ @@ -2319,6 +2321,10 @@ export class SettingsService { if (source === 'none') { return value === null ? { served: { value: null, source } } : { why: "states a value under source 'none'" }; } + // In use, supplied by the runtime's environment or host, and named by no + // option (a host's own mail transport). Only 'environment' may say this: + // what 'settings' resolves is always one of the options. + if (source === 'environment' && value === null) return { served: { value: null, source } }; if (typeof value !== 'string' || table.judge(value) !== null) { return { why: 'states a value that is not one of its options' }; } diff --git a/packages/services/service-settings/src/settings-service.types.ts b/packages/services/service-settings/src/settings-service.types.ts index 0cd8c68318c..fe173f5c4cc 100644 --- a/packages/services/service-settings/src/settings-service.types.ts +++ b/packages/services/service-settings/src/settings-service.types.ts @@ -503,8 +503,9 @@ export interface SettingsLiveStatus { * * Only an option-bearing key may be named, and only with a value its option * table admits (the declared `options`, or a registered option source's - * answer), so what is served is always one of the page's own options and - * never free text a runtime might fill with a credential. Each entry is + * answer), so what is served is always one of the page's own options (or + * `null`, under `'none'` or `'environment'` alone) and never free text a + * runtime might fill with a credential. Each entry is * served as `{ value, source }` and nothing else. An entry that breaks this * is left out, so its key reads as not stated, and the server logs it once * per read without the value; the banner and the other entries stand. @@ -517,13 +518,18 @@ export interface SettingsLiveStatus { /** One key's value in the running system — see {@link SettingsLiveStatus.values}. */ export interface SettingsLiveValue { - /** The value in use, one of the key's options; `null` exactly when `source` is `'none'`. */ + /** + * The value in use, one of the key's options; `null` when `source` is + * `'none'`, or when `source` is `'environment'` and no option names what is + * in use (a transport the host hands over). Whether something is in use is + * read from `source`, never from a `null` value. + */ value: string | null; /** * Where the running system took it from: `'settings'` (what this namespace - * resolves, saved or `OS_*`-locked), `'environment'` (detected by the - * runtime itself from its own boot environment, outside this namespace), or - * `'none'` (nothing is in use). + * resolves, saved or `OS_*`-locked; always names an option), `'environment'` + * (detected by the runtime itself from its own boot environment, or handed + * over by its host, outside this namespace), or `'none'` (nothing is in use). */ source: 'settings' | 'environment' | 'none'; } diff --git a/packages/spec/src/system/settings-manifest.test.ts b/packages/spec/src/system/settings-manifest.test.ts index 279d80e4490..5e9c64b2b56 100644 --- a/packages/spec/src/system/settings-manifest.test.ts +++ b/packages/spec/src/system/settings-manifest.test.ts @@ -795,6 +795,9 @@ describe('SettingsNamespacePayloadSchema', () => { expect(parsed.live?.provider).toEqual({ value: 'openai', source: 'environment' }); expect(SettingsNamespacePayloadSchema.parse({ ...aiPage, live: { provider: { value: null, source: 'none' } } }).live) .toEqual({ provider: { value: null, source: 'none' } }); + // In use, supplied by the environment or host, named by no option (a host's own mail transport). + expect(SettingsNamespacePayloadSchema.parse({ ...aiPage, live: { provider: { value: null, source: 'environment' } } }).live) + .toEqual({ provider: { value: null, source: 'environment' } }); expect(SettingsNamespacePayloadSchema.parse(aiPage).live).toBeUndefined(); }); diff --git a/packages/spec/src/system/settings-manifest.zod.ts b/packages/spec/src/system/settings-manifest.zod.ts index 8136243b04f..95350d0c798 100644 --- a/packages/spec/src/system/settings-manifest.zod.ts +++ b/packages/spec/src/system/settings-manifest.zod.ts @@ -969,17 +969,26 @@ export const SettingsNamespacePayloadSchema = lazySchema(() => z.object({ * this says what is in use, which may come from elsewhere: the AI runtime * detects a provider from its own boot environment when nothing is saved. * Absent, or a key absent from it, means not stated (unknown), which is not - * `source: 'none'`. Only `value` and `source` are served, and `value` is - * always one of the key's options, never a credential. + * `source: 'none'`. Only `value` and `source` are served, and a non-null + * `value` is always one of the key's options, never a credential. + * `value` is null in two cases: nothing is in use (`source: 'none'`), or + * something is in use that the runtime's boot environment or host supplied + * and no option names (`source: 'environment'`, e.g. a mail transport the + * host application hands over). So whether something is in use is read from + * `source` alone, never from `value === null`; `source: 'settings'` always + * names an option. */ live: z .record( z.string(), z.object({ - value: z.string().nullable().describe("The option in use; null exactly when source is 'none'"), + value: z + .string() + .nullable() + .describe("The option in use; null when source is 'none', or when source is 'environment' and no option names what is in use. Read in-use from source, never from a null value"), source: z .enum(['settings', 'environment', 'none']) - .describe("Where the running system took it from: these settings, its own boot environment, or nothing in use"), + .describe("Where the running system took it from: these settings, its own boot environment or host, or nothing in use"), }), ) .optional()