Skip to content
Merged
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
14 changes: 14 additions & 0 deletions .changeset/37662-approvals-act-inbound-hooks-501-locale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/spec': patch
'@objectstack/runtime': patch
---

fix(runtime): the approval action-page door and the inbound automation hooks answer their 501 in the request's language

Clause-②: yes (widening)
Metadata-protocol: none
Skills-docs: none (no page under `skills/**` names these doors' `501` sentences)

The approval action-page door (`/approvals/act`) and the inbound automation hook route (`/automation/hooks/:flow/:hook`) now answer their `501 NOT_IMPLEMENTED` in the request's language, as the comment, webhook redelivery, print, personal-view and attachment doors do. On a kernel with no `approvals` or `trigger-api` service, or with one that lacks `handleActionPage` / `handleInboundHook`, a `zh-CN`, `ja-JP` or `es-ES` request read the sentence in English. The operation-message catalog (`BUILTIN_OPERATION_MESSAGES`, `@objectstack/spec/system`) gains `approvals_act_service_unregistered`, `approvals_act_member_missing`, `automation_hooks_service_unregistered` and `automation_hooks_member_missing` in `en`, `zh-CN`, `ja-JP` and `es-ES`. Their English is the sentence each door answered before, byte for byte. Code and status do not change, and no `userMessage` is added.

The catalog's notes on these whole-sentence `501` keys now say how they are read: by the request's top `Accept-Language` tag, with no `errors.` override consulted.
51 changes: 51 additions & 0 deletions packages/runtime/src/domains/approvals-act.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
*/

import { describe, it, expect, vi } from 'vitest';
// Paid during collection, not inside a case's clock: the dispatcher reaches
// `standalone-stack.ts`, whose dynamic `@objectstack/metadata` import would
// otherwise load inside the first case that gets that far (check:test-source-alias).
import '@objectstack/metadata';
import { HttpDispatcher } from '../http-dispatcher.js';
import type { HttpProtocolContext, KernelResolver } from '../http-dispatcher.js';

Expand Down Expand Up @@ -326,3 +330,50 @@ describe('[#22576] the token is the only credential — the membership gate skip
}
});
});

// [#37662] The action-page door's two `501` sentences are the operation-message
// catalog's, in the request's top `Accept-Language` tag, as the own-door
// bridge answers its doors' own. The English is byte for byte the sentence the
// door answered before, the code and status are unchanged, and no
// `userMessage` is added.
describe('[#37662] the action-page door\'s 501 follows the request\'s language', () => {
const SENTENCES = {
unregistered: {
en: 'Approval action pages are not available: no approvals service is registered. Register @objectstack/plugin-approvals to serve them.',
'zh-CN': '审批操作页不可用:未注册 approvals 服务。请注册 @objectstack/plugin-approvals 来提供这些页面。',
'ja-JP': '承認アクションページは利用できません。approvals サービスが登録されていません。これらのページを提供するには @objectstack/plugin-approvals を登録してください。',
'es-ES': 'Las páginas de acción de aprobación no están disponibles: no hay ningún servicio approvals registrado. Registre @objectstack/plugin-approvals para servirlas.',
},
memberMissing: {
en: 'Approval action pages are not available: the registered approvals service does not implement handleActionPage.',
'zh-CN': '审批操作页不可用:已注册的 approvals 服务未实现 handleActionPage。',
'ja-JP': '承認アクションページは利用できません。登録されている approvals サービスは handleActionPage を実装していません。',
'es-ES': 'Las páginas de acción de aprobación no están disponibles: el servicio approvals registrado no implementa handleActionPage.',
},
};
const HEADERS: Record<'en' | 'zh-CN' | 'ja-JP' | 'es-ES', Array<Record<string, string>>> = {
en: [{ 'accept-language': 'en-US,en;q=0.9' }, {}],
'zh-CN': [{ 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8' }],
'ja-JP': [{ 'accept-language': 'ja-JP,ja;q=0.9' }],
'es-ES': [{ 'accept-language': 'es-ES,es;q=0.9' }],
};

for (const site of [
{ name: 'no approvals slot on the kernel', services: {} as Record<string, unknown>, sentences: SENTENCES.unregistered },
{ name: 'an approvals service without handleActionPage', services: { approvals: { getRequest: vi.fn() } }, sentences: SENTENCES.memberMissing },
]) {
it(`${site.name}: 501 NOT_IMPLEMENTED in en (and with no header), zh-CN, ja-JP and es-ES`, async () => {
for (const [locale, list] of Object.entries(HEADERS) as Array<[keyof typeof HEADERS, Array<Record<string, string>>]>) {
for (const headers of list) {
const { dispatcher } = makeDispatcher(site.services);
const request = new Request(`${ORIGIN}/api/v1${ACT}?token=t`, { headers });
const label = JSON.stringify(headers);
const result = await dispatcher.dispatch('GET', ACT, undefined, {}, ctx(request));
expect(envelope(result), label).toEqual({ status: 501, code: 'NOT_IMPLEMENTED' });
expect(result.response?.body?.error?.message, label).toBe(site.sentences[locale]);
expect(result.response?.body?.error?.userMessage, label).toBeUndefined();
}
}
});
}
});
10 changes: 6 additions & 4 deletions packages/runtime/src/domains/approvals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
*/

import { INTERNAL_ERROR_MESSAGE } from '@objectstack/types';
import { operationUserMessage } from '@objectstack/core';
import type { IApprovalService } from '@objectstack/spec/contracts';
import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js';
import type { DomainHandlerDeps, DomainRoute } from '../domain-handler-registry.js';
import { requestLocaleOf } from './own-door-bridge.js';

/**
* The one path this domain claims — exactly, with no sub-paths: the action
Expand Down Expand Up @@ -109,12 +111,13 @@ export async function handleApprovalsActRequest(
): Promise<HttpDispatcherResult> {
const service = await deps.resolveService(context, APPROVALS_SLOT, context.environmentId) as
Pick<IApprovalService, 'handleActionPage'> | undefined;
// [#37662] The `501` is the operation-message catalog's, in the request's
// top `Accept-Language` tag, as the own-door bridge answers its own.
if (!service) {
return {
handled: true,
response: deps.error(
'Approval action pages are not available: no approvals service is registered. '
+ 'Register @objectstack/plugin-approvals to serve them.',
operationUserMessage('approvals_act_service_unregistered', { locale: requestLocaleOf(context) }),
501,
),
};
Expand All @@ -123,8 +126,7 @@ export async function handleApprovalsActRequest(
return {
handled: true,
response: deps.error(
'Approval action pages are not available: the registered approvals service '
+ 'does not implement handleActionPage.',
operationUserMessage('approvals_act_member_missing', { locale: requestLocaleOf(context) }),
501,
),
};
Expand Down
51 changes: 51 additions & 0 deletions packages/runtime/src/domains/automation-hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,3 +925,54 @@ describe('[#31696] a name two packages hold, on a kernel with no http.server', (
}
});
});

// [#37662] The inbound hook route's two `501` sentences are the
// operation-message catalog's, in the request's top `Accept-Language` tag, as
// the own-door bridge answers its doors' own. The English is byte for byte the
// sentence the route answered before, the code and status are unchanged, and
// no `userMessage` is added.
describe('[#37662] the inbound hook route\'s 501 follows the request\'s language', () => {
const SENTENCES = {
unregistered: {
en: 'Inbound automation hooks are not available: no trigger-api service is registered. The inbound-hook trigger (@objectstack/trigger-api) serves this route through that service; compose it on the environment that owns the flow.',
'zh-CN': '入站自动化钩子不可用:未注册 trigger-api 服务。入站钩子触发器(@objectstack/trigger-api)通过该服务提供此路由;请在拥有该流程的环境上组合它。',
'ja-JP': '受信オートメーションフックは利用できません。trigger-api サービスが登録されていません。受信フックトリガー(@objectstack/trigger-api)がこのサービスを通じてこのルートを提供します。フローを所有する環境に組み込んでください。',
'es-ES': 'Los ganchos de automatización entrantes no están disponibles: no hay ningún servicio trigger-api registrado. El disparador de ganchos entrantes (@objectstack/trigger-api) sirve esta ruta a través de ese servicio; compóngalo en el entorno al que pertenece el flujo.',
},
memberMissing: {
en: 'Inbound automation hooks are not available: the registered trigger-api service does not implement handleInboundHook.',
'zh-CN': '入站自动化钩子不可用:已注册的 trigger-api 服务未实现 handleInboundHook。',
'ja-JP': '受信オートメーションフックは利用できません。登録されている trigger-api サービスは handleInboundHook を実装していません。',
'es-ES': 'Los ganchos de automatización entrantes no están disponibles: el servicio trigger-api registrado no implementa handleInboundHook.',
},
};
const HEADERS: Record<'en' | 'zh-CN' | 'ja-JP' | 'es-ES', Array<Record<string, string>>> = {
en: [{ 'accept-language': 'en-US,en;q=0.9' }, {}],
'zh-CN': [{ 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8' }],
'ja-JP': [{ 'accept-language': 'ja-JP,ja;q=0.9' }],
'es-ES': [{ 'accept-language': 'es-ES,es;q=0.9' }],
};

for (const site of [
{ name: 'no trigger-api slot on the kernel', services: {} as Record<string, unknown>, sentences: SENTENCES.unregistered },
{ name: 'a trigger-api service without handleInboundHook', services: { 'trigger-api': { somethingElse: vi.fn() } }, sentences: SENTENCES.memberMissing },
]) {
it(`${site.name}: 501 NOT_IMPLEMENTED in en (and with no header), zh-CN, ja-JP and es-ES`, async () => {
for (const [locale, list] of Object.entries(HEADERS) as Array<[keyof typeof HEADERS, Array<Record<string, string>>]>) {
for (const headers of list) {
const { dispatcher } = makeDispatcher(site.services);
const request = new Request(`${ORIGIN}/api/v1${ROUTE}`, {
method: 'POST',
headers: { ...JSON_HEADERS, 'x-objectstack-signature': sign(BODY, SECRET), ...headers },
body: BODY,
});
const label = JSON.stringify(headers);
const result = await dispatcher.dispatch('POST', ROUTE, {}, {}, ctx(request));
expect(envelope(result), label).toEqual({ status: 501, code: 'NOT_IMPLEMENTED' });
expect(result.response?.body?.error?.message, label).toBe(site.sentences[locale]);
expect(result.response?.body?.error?.userMessage, label).toBeUndefined();
}
}
});
}
});
11 changes: 6 additions & 5 deletions packages/runtime/src/domains/automation-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ import { INTERNAL_ERROR_MESSAGE } from '@objectstack/types';
import {
admitInboundHookAddress,
inboundHookRefusalResponse,
operationUserMessage,
type InboundHookRouteMatch,
} from '@objectstack/core';
import { automationAddressRegistryOf } from './automation-address.js';
import type { ITriggerApiService } from '@objectstack/spec/contracts';
import type { HttpProtocolContext, HttpDispatcherResult } from '../http-dispatcher.js';
import type { DomainHandlerDeps } from '../domain-handler-registry.js';
import { requestLocaleOf } from './own-door-bridge.js';

/** The slot the member lives on — the trigger package's own name (ADR-0041 §2). */
const TRIGGER_API_SLOT = 'trigger-api';
Expand Down Expand Up @@ -182,13 +184,13 @@ export async function handleInboundHookRequest(
): Promise<HttpDispatcherResult> {
const service = await deps.resolveService(context, TRIGGER_API_SLOT, context.environmentId) as
Pick<ITriggerApiService, 'handleInboundHook'> | undefined;
// [#37662] The `501` is the operation-message catalog's, in the request's
// top `Accept-Language` tag, as the own-door bridge answers its own.
if (!service) {
return {
handled: true,
response: deps.error(
'Inbound automation hooks are not available: no trigger-api service is registered. '
+ 'The inbound-hook trigger (@objectstack/trigger-api) serves this route through that '
+ 'service; compose it on the environment that owns the flow.',
operationUserMessage('automation_hooks_service_unregistered', { locale: requestLocaleOf(context) }),
501,
),
};
Expand All @@ -197,8 +199,7 @@ export async function handleInboundHookRequest(
return {
handled: true,
response: deps.error(
'Inbound automation hooks are not available: the registered trigger-api service '
+ 'does not implement handleInboundHook.',
operationUserMessage('automation_hooks_member_missing', { locale: requestLocaleOf(context) }),
501,
),
};
Expand Down
52 changes: 52 additions & 0 deletions packages/runtime/src/domains/own-door-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import { BUILTIN_OPERATION_MESSAGES } from '@objectstack/spec/system';
import { PERSONAL_VIEWS_BRIDGE } from './personal-views.js';
import { ATTACHMENTS_BRIDGE } from './attachments.js';
import { PRINT_BRIDGE } from './print.js';
import type { OwnDoorBridge } from './own-door-bridge.js';
import { readdirSync, readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

const ORIGIN = 'http://tenant.example';
const JSON_HEADERS = { 'Content-Type': 'application/json' };
Expand Down Expand Up @@ -506,3 +510,51 @@ describe('[#37352] the personal-view and attachment doors\' 501s follow the requ
expect(BUILTIN_OPERATION_MESSAGES.en[PRINT_BRIDGE.nounKey]).toBe(PRINT_BRIDGE.noun);
});
});

/**
* [#37662] Every bridge's flags against the catalog, found rather than listed:
* each module of this directory that builds a bridge domain
* (`createOwnDoorBridgeDomain(`) is imported and its exported bridges walked,
* so a fourth bridge is held to the same rules the day it lands.
*/
describe('[#37662] every own-door bridge is tied to the catalog', () => {
const isBridge = (value: unknown): value is OwnDoorBridge =>
!!value && typeof value === 'object'
&& typeof (value as OwnDoorBridge).nounKey === 'string'
&& typeof (value as OwnDoorBridge).slot === 'string'
&& Array.isArray((value as OwnDoorBridge).doors);
const here = dirname(fileURLToPath(import.meta.url));
const builders = readdirSync(here)
.filter((name) => name.endsWith('.ts') && !name.endsWith('.test.ts') && name !== 'own-door-bridge.ts')
.filter((name) => readFileSync(join(here, name), 'utf8').includes('createOwnDoorBridgeDomain('));

it('finds the shipped bridges, each module exporting the bridge it builds', async () => {
const found: Array<[string, OwnDoorBridge]> = [];
for (const name of builders) {
const mod = await import(/* @vite-ignore */ `./${name.replace(/\.ts$/, '.js')}`) as Record<string, unknown>;
const bridges = Object.entries(mod).filter(([, value]) => isBridge(value)) as Array<[string, OwnDoorBridge]>;
expect(bridges.length, `${name} builds a bridge domain but exports no bridge`).toBeGreaterThan(0);
found.push(...bridges);
}
expect(found.map(([exported]) => exported).sort())
.toEqual(expect.arrayContaining(['ATTACHMENTS_BRIDGE', 'PERSONAL_VIEWS_BRIDGE', 'PRINT_BRIDGE']));

const locales = Object.keys(BUILTIN_OPERATION_MESSAGES);
for (const [exported, bridge] of found) {
// The noun key is in every locale, and its English is the noun.
for (const locale of locales) {
expect(BUILTIN_OPERATION_MESSAGES[locale][bridge.nounKey], `${exported} ${locale}`).toBeTruthy();
}
expect(BUILTIN_OPERATION_MESSAGES.en[bridge.nounKey], exported).toBe(bridge.noun);
// `nounPlural` is set exactly when the English noun is plural (`the … doors`).
expect(bridge.nounPlural === true, `${exported}: '${bridge.noun}'`).toBe(/\bdoors\b/.test(bridge.noun));
// The pair of sentences the bridge reads is in every locale.
const suffix = bridge.nounPlural ? '_plural' : '';
for (const key of ['own_door_service_unregistered', 'own_door_member_missing']) {
for (const locale of locales) {
expect(BUILTIN_OPERATION_MESSAGES[locale][key + suffix], `${exported} ${locale} ${key}${suffix}`).toBeTruthy();
}
}
}
});
});
2 changes: 1 addition & 1 deletion packages/runtime/src/domains/own-door-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
* dispatcher's `404 ROUTE_NOT_FOUND`: the route IS mounted, and what is
* missing is the implementation behind it.
*
* ## The `501` is in the request's language when the bridge names its noun
* ## The `501` is in the request's language
*
* [#37273] The two `501` sentences are the operation-message catalog's
* (`own_door_service_unregistered`, `own_door_member_missing`), rendered in
Expand Down
Loading
Loading