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
24 changes: 24 additions & 0 deletions .changeset/33894-connector-pull-undeclared-input-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/service-automation': minor
'@objectstack/spec': minor
---

fix(service-automation)!: the connector pull door refuses an input key its read action does not declare, as the `connector_action` node does

Clause-②: no (narrowing) — a mapping whose `connectorSource.input`, or the watermark parameter the pull adds to its `query`, carries a key the read action's `inputSchema` does not declare used to pull and send that key to the provider; the pull now fails before the call. Nothing published widens: no export, no key, no option is added. First-party mappings affected: 0 (no `connectorSource` under `examples/` or `packages/apps/`).
Metadata-protocol: narrowed

<!-- adr-0087: registered connector-pull-undeclared-input-key-refused -->

**BREAKING** for a mapping pulled through `connectorSource` whose input holds a key the read action does not declare. Every door that dispatches a connector action now judges its input alike: the pull judges the input it is about to send, the watermark parameter included, by the rule the `connector_action` node has applied since 18.5.0, and refuses with `code: 'VALIDATION_ERROR'` (status 400) before the action is called, naming each undeclared key by its dotted path and the keys the action declares at that level. Nothing is pulled and nothing is written.

A scheduled pull has no `fault` edge: a job whose `pull` names such a mapping fails every run (its `sys_sync_run` row ends `failed`, and the job's `retryPolicy` applies) until the mapping or the action's document is fixed.

The key the pull adds itself is judged too. With `connectorSource.watermark`, the pull sends the highest stored value of the target field as `query[watermark.param]` — but only once the target holds a value, so a mapping whose first pull wrote rows fails from its second pull on. An `openapi` connector declares only the query parameters its OpenAPI document names, so an operation that does not name the watermark parameter (or names none in `query` while declaring a parameter elsewhere or a body) refuses it; the refusal names the parameter. An operation with no parameter and no body has no `inputSchema`, so nothing is judged and the watermark is sent; it starts refusing the watermark the day the document gives it its first parameter or a body, unless the watermark parameter is declared with it. A `rest` connector's `request` action declares `query` with no `properties`, which reads as open, so its query keys, the watermark included, are not refused.

Migration, FROM → TO:

- A stray key the author wrote: `connectorSource: { connector: 'crm_api', action: 'list_contacts', input: { query: { limit: 50, stale: 'x' } } }` → drop `stale` from `input`, or declare it in the action.
- The watermark parameter on an `openapi` connector: `watermark: { field: 'updated_at', param: 'since' }` over an operation whose document lists only `limit` → add `{ name: 'since', in: 'query', schema: { type: 'string' } }` to that operation's `parameters` in the OpenAPI document (its declared type must be the target field's), then let the connector re-materialize.

`GET /api/v1/automation/connectors` lists each action's `inputSchema`, which is what the pull judges against. Which schemas declare their keys is the `connector_action` node's rule, unchanged: an object schema that lists `properties`, or says `additionalProperties: false`; one that admits more keys (`additionalProperties` true or a schema, `patternProperties`, a composition keyword, `$ref`) or lists no `properties` still sends every key, and so does an action with no `inputSchema`.
12 changes: 11 additions & 1 deletion content/docs/automation/jobs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,17 @@ export const OrdersPullJob = defineJob({
- A **`connectorSource`** run calls the connector's read action once and reads
one response — see
[Data sync is defined on the target](https://github.com/objectstack-ai/objectstack/blob/main/packages/spec/docs/SYNC_ARCHITECTURE.md#data-sync-is-defined-on-the-target)
for the watermark and the one-response limit.
for the watermark and the one-response limit. The input it sends is judged
against the action's `inputSchema` first, as a `connector_action` step's is:
a key the action does not declare is refused, never sent. That includes the
watermark parameter the run adds to `query` (`since`, say) once the target
holds a value, so an `openapi` connector's read operation that declares any
parameter or a body must declare it as an `in: query` parameter in the
OpenAPI document. An operation that declares neither has no `inputSchema`
and is not judged, until the day it gains its first parameter or a body;
from then on an undeclared watermark is refused. A scheduled run has no
`fault` edge: such a refusal fails every run until the mapping or the
document is fixed.
- A **`datasourceSource`** run reads the federated object in windows cut on
`watermark.field`. A built-in driver's windows are read whole, paged by the key
the object's `external.columnMap` maps onto `id`. A plugin driver's windows go
Expand Down
2 changes: 1 addition & 1 deletion content/docs/references/data/mapping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const result = ImportFieldMappingSchema.parse(data);
| :--- | :--- | :--- | :--- |
| **connector** | `string` | ✅ | Name of the connector instance the rows are pulled from — a `connectors[]` entry whose `provider` is `rest` or `openapi` (version 1) |
| **action** | `string` | ✅ | Key of the connector action that reads the records: `request` on a `rest` connector, an operation key on an `openapi` connector |
| **input** | `Record<string, any>` | optional | Fixed input passed to the action on every pull (e.g. `{ method: 'GET', path: '/contacts' }` for `rest`) |
| **input** | `Record<string, any>` | optional | Fixed input passed to the action on every pull (e.g. `{ method: 'GET', path: '/contacts' }` for `rest`). Judged against the action's `inputSchema` before the call, as a `connector_action` node's input is: a key the action does not declare is refused, never sent — the watermark parameter the pull adds to `query` included, so an `openapi` operation that declares any parameter or a body must declare it in its OpenAPI document. An operation that declares neither has no `inputSchema` and is not judged, until the day it gains its first parameter or a body |
| **recordsPath** | `string` | optional | Dot path, within the action's result, to the array of records (e.g. `body.results`); omitted ⇒ the result's `body` is the array |
| **watermark** | `{ field: string; param: string }` | optional | Timestamp-incremental pull; omitted ⇒ every pull reads the full set. Either way a pull makes ONE action call and reads ONE response: the connector's paging is not followed, so a paged endpoint yields its first page only — and an incremental pull over a newest-first paged endpoint moves its starting point past the pages it never read |
| **paging** | `{ style: Enum<'page' \| 'cursor' \| 'offset' \| 'none'>; param?: string; nextPath?: string }` | optional | The connector's paging convention: page, cursor or offset, or `none` for a source whose one response is the whole set. Omitted ⇒ a pull reads one response and does not treat it as complete |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* [#33894] The connector pull door refuses an input key the read action does
* not declare, as the `connector_action` node does: every door that
* dispatches a connector action judges its input alike. The undeclared key
* the author wrote is pinned beside the door's other input refusals in
* `connector-pull.test.ts`; this file pins the key the door ADDS itself —
* the watermark parameter, sent as `query[watermark.param]` once the target
* holds a value — which only the action can declare (for an `openapi`
* connector, its OpenAPI document).
*
* The schemas below are the shapes the shipped producers emit: the `openapi`
* generator's `{ path, query, header, body }` sections, where a location the
* operation declares no parameter in is left out, and the `rest` connector's
* `request`, whose `query` lists no `properties` and so declares open input.
*
* Every refusal asserts the ADR-0112 pair (`code` + `status`), the executor's
* `reason`, the named key, and that neither the action nor a write ran.
*/

import { describe, it, expect, vi } from 'vitest';
import {
pullConnectorSource,
ConnectorPullError,
type ConnectorPullDeps,
} from './connector-pull.js';

const silent = { debug() {}, info() {}, warn() {}, error() {} } as unknown as ConnectorPullDeps['logger'];

const contactObject = {
name: 'contact',
fields: {
external_id: { name: 'external_id', type: 'text' },
name: { name: 'name', type: 'text' },
synced_at: { name: 'synced_at', type: 'text' },
},
};

/** An incremental mapping: `updated_at` is copied onto `synced_at`, and sent back as `query.since`. */
function incrementalMapping(input: Record<string, unknown>) {
return {
name: 'crm_contacts',
targetObject: 'contact',
fieldMapping: [
{ source: 'id', target: 'external_id' },
{ source: 'name', target: 'name' },
{ source: 'updated_at', target: 'synced_at' },
],
mode: 'upsert',
upsertKey: ['external_id'],
connectorSource: {
connector: 'crm_api', action: 'list_contacts', input,
watermark: { field: 'updated_at', param: 'since' },
},
};
}

/** An `openapi` operation declaring `query.limit` only — the document never names `since`. */
const OPENAPI_LIMIT_ONLY = {
type: 'object',
properties: { query: { type: 'object', properties: { limit: { type: 'integer' } } } },
};

/** An `openapi` operation declaring only a header parameter: the generator emits no `query` section at all. */
const OPENAPI_NO_QUERY = {
type: 'object',
properties: { header: { type: 'object', properties: { 'X-Tenant': { type: 'string' } } } },
};

/** The same operation once the document declares `since` as an `in: query` parameter. */
const OPENAPI_SINCE_DECLARED = {
type: 'object',
properties: {
query: { type: 'object', properties: { limit: { type: 'integer' }, since: { type: 'string' } } },
},
};

/** The `rest` connector's `request` action: `query` lists no `properties`, so every query key is open. */
const REST_REQUEST = {
type: 'object',
properties: {
method: { type: 'string' },
path: { type: 'string' },
headers: { type: 'object' },
query: { type: 'object' },
body: {},
},
};

const STORED = [{ synced_at: '2026-01-02T00:00:00.000Z' }];

function harness(opts: {
/** Absent ⇒ the action declares no `inputSchema`. */
inputSchema: Record<string, unknown> | undefined;
input: Record<string, unknown>;
stored?: Array<Record<string, unknown>>;
}) {
const writes: unknown[] = [];
const handler = vi.fn(async (_input: Record<string, unknown>) => ({ status: 200, ok: true, body: [] }) as Record<string, unknown>);
const mapping = incrementalMapping(opts.input);
const deps: ConnectorPullDeps = {
protocol: {
async getMetaItem({ type, name }) {
if (type === 'mapping' && name === mapping.name) return { type, name, item: mapping };
if (type === 'object' && name === 'contact') return { type, name, item: contactObject };
return undefined;
},
async findData() { return { records: opts.stored ?? [] }; },
async createData(args) { writes.push(args); return { id: 'new' }; },
async updateData(args) { writes.push(args); return { id: 'upd' }; },
},
registry: {
resolveConnectorAction: (connector, action) =>
connector === 'crm_api' && action === 'list_contacts' ? handler : undefined,
getConnectorOrigin: (name) => (name === 'crm_api' ? 'declarative' : undefined),
getConnectorDegradedReason: () => undefined,
getConnectorDescriptors: () => [{
name: 'crm_api', label: 'CRM', type: 'api', origin: 'declarative', state: 'ready',
actions: [{ key: 'list_contacts', label: 'List contacts', inputSchema: opts.inputSchema }],
}],
},
providerOf: (name) => (name === 'crm_api' ? 'openapi' : undefined),
logger: silent,
};
return { deps, handler, writes };
}

async function refusal(h: ReturnType<typeof harness>): Promise<ConnectorPullError> {
const err = await pullConnectorSource(h.deps, { mapping: 'crm_contacts' }).then(
() => undefined,
(e: unknown) => e,
);
expect(err, 'the pull must refuse, not resolve').toBeInstanceOf(ConnectorPullError);
const e = err as ConnectorPullError;
expect({ code: e.code, status: e.status, reason: e.reason, mapping: e.mapping }).toEqual({
code: 'VALIDATION_ERROR', status: 400, reason: 'input_schema_mismatch', mapping: 'crm_contacts',
});
expect(h.handler).toHaveBeenCalledTimes(0);
expect(h.writes).toEqual([]);
return e;
}

describe('[#33894] connector pull — the watermark parameter the door adds is judged like any other input key', () => {
it('a watermark parameter the operation does not declare is refused, naming it and the OpenAPI fix', async () => {
const h = harness({ inputSchema: OPENAPI_LIMIT_ONLY, input: { query: { limit: 50 } }, stored: STORED });
const err = await refusal(h);
expect(err.message).toContain("'query.since' is not an input the action declares");
expect(err.message).toContain("watermark parameter 'since'");
expect(err.message).toContain('OpenAPI document');
});

it('an operation that declares no query parameter at all refuses the watermark the same way', async () => {
const h = harness({ inputSchema: OPENAPI_NO_QUERY, input: {}, stored: STORED });
const err = await refusal(h);
expect(err.message).toContain("'query' is not an input the action declares");
expect(err.message).toContain("watermark parameter 'since'");
});

it('an undeclared key the author wrote does not blame the watermark when the watermark is declared', async () => {
const h = harness({
inputSchema: OPENAPI_SINCE_DECLARED,
input: { query: { limit: 50, stale: 'x' } },
stored: STORED,
});
const err = await refusal(h);
expect(err.message).toContain("'query.stale' is not an input the action declares");
expect(err.message).not.toContain('watermark parameter');
});

it('CONTROL: once the document declares the watermark parameter, the pull sends it', async () => {
const h = harness({ inputSchema: OPENAPI_SINCE_DECLARED, input: { query: { limit: 50 } }, stored: STORED });
await pullConnectorSource(h.deps, { mapping: 'crm_contacts' });
expect(h.handler).toHaveBeenCalledTimes(1);
expect(h.handler.mock.calls[0][0]).toEqual({ query: { limit: 50, since: '2026-01-02T00:00:00.000Z' } });
});

it('CONTROL: the first pull, with nothing stored yet, sends no watermark and so is not refused for it', async () => {
const h = harness({ inputSchema: OPENAPI_LIMIT_ONLY, input: { query: { limit: 50 } } });
await pullConnectorSource(h.deps, { mapping: 'crm_contacts' });
expect(h.handler).toHaveBeenCalledTimes(1);
expect(h.handler.mock.calls[0][0]).toEqual({ query: { limit: 50 } });
});

it('CONTROL: an openapi operation with no parameter and no body declares no inputSchema, so nothing is judged and the watermark is sent', async () => {
const h = harness({ inputSchema: undefined, input: {}, stored: STORED });
await pullConnectorSource(h.deps, { mapping: 'crm_contacts' });
expect(h.handler).toHaveBeenCalledTimes(1);
expect(h.handler.mock.calls[0][0]).toEqual({ query: { since: '2026-01-02T00:00:00.000Z' } });
});

it('CONTROL: a rest connector\'s open query section takes the watermark parameter as before', async () => {
const h = harness({ inputSchema: REST_REQUEST, input: { method: 'GET', path: '/contacts' }, stored: STORED });
await pullConnectorSource(h.deps, { mapping: 'crm_contacts' });
expect(h.handler).toHaveBeenCalledTimes(1);
expect(h.handler.mock.calls[0][0]).toEqual({
method: 'GET', path: '/contacts', query: { since: '2026-01-02T00:00:00.000Z' },
});
});
});
13 changes: 7 additions & 6 deletions packages/services/service-automation/src/connector-pull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ describe('[#28040] connector pull — the input is checked against the action\'s
expect(res.pulled).toBe(0);
});

it('[#33553] an undeclared key is not refused here: the pull door does not opt in to that judgment', async () => {
it('[#33894] an undeclared key is VALIDATION_ERROR 400 naming it, as at the connector_action node, and the action is never called', async () => {
const h = harness({
inputSchema: SINCE_REQUIRED,
mapping: baseMapping({
Expand All @@ -392,11 +392,12 @@ describe('[#28040] connector pull — the input is checked against the action\'s
},
}),
});
await pullConnectorSource(h.deps, { mapping: 'crm_contacts' });
expect(h.handler).toHaveBeenCalledTimes(1);
expect(h.handler.mock.calls[0][0]).toEqual({
path: '/contacts', query: { since: '2026-01-01', stale: 'x' }, extra: 'kept',
});
const err = await refusal(h);
expectRefused(err, { code: 'VALIDATION_ERROR', status: 400, reason: 'input_schema_mismatch' });
expect(err.message).toContain("'query.stale' is not an input the action declares");
expect(err.message).toContain("'extra' is not an input the action declares");
expect(h.handler).toHaveBeenCalledTimes(0);
expect(h.writes).toEqual([]);
});

it('a valid input still pulls and writes', async () => {
Expand Down
Loading
Loading