## Quick start ```bash aancer-pack init connector my-items ``` ```text wrote /…/my-items — next: cd /…/my-items && npm install && npm run build, then aancer-pack connector run create_item --props test/props.create_item.json --auth test/auth.json ``` The name must match `^[a-z0-9][a-z0-9-]{1,62}$`; it becomes the package `@aancer/connector-my-items`. You get: ```text my-items/ package.json @aancer/connector-my-items 0.1.0, depends on @aancer/connector-framework, TypeScript tsconfig.json node16 modules, strict, output in dist/ pack.json displayName, description, category, egressHosts .gitignore node_modules/, dist/, .aancer-run/, test/auth.json src/index.ts createConnector(...) src/auth.ts ConnectorAuth.CustomAuth: API key + optional base URL, a validate() call, a call() helper with timeout and retries src/lib/list-items.ts action list_items (follows the API's pages) src/lib/create-item.ts action create_item src/lib/new-item.ts polling trigger new_item (keeps the last seen time in the store) test/props.create_item.json test/auth.example.json README.md ``` Then: ```bash cd my-items npm install /absolute/path/to/aancer-connector-framework-.tgz npm install npm run build # → dist/src/index.js ``` ## Run and check it on your machine ### `connector run`: one step, locally ```bash cp test/auth.example.json test/auth.json # a key for a test account; auth.json stays out of git aancer-pack connector run create_item --props test/props.create_item.json --auth test/auth.json aancer-pack connector run list_items --auth test/auth.json aancer-pack connector run new_item --hook test --auth test/auth.json aancer-pack connector run new_item --hook enable --auth test/auth.json ``` For a webhook trigger, `--payload ` gives the request the trigger receives (`{ "body", "headers", "queryParams" }`). It loads the **built** connector (`dist/src/index.js`; otherwise exit 2 "build the connector first"), fills `propsValue` as the runner does (defaults for missing values; a missing required value or an unknown property is exit 2 and names the properties), and runs one action, or one hook of a trigger (`--hook run|test|enable|disable`, default `run`). The result is printed as JSON, exit 0. If the step throws, it prints ` failed: ` with the stack frames of your project and exits 1. The local stand-in: the store and written files live under `.aancer-run/` in the project; `server`, `flows` and `project` are local placeholders; agent tools and waitpoints are not available (they throw). Your step reaches the real network: point `baseUrl` at a sandbox. `--auth` takes a JSON string for a secret-text key, or the fields (`{ "apiKey": …, "baseUrl": … }`) for custom auth, `{ "username", "password" }` for basic auth, or a complete connection value with a `type`. ### `connector check`: the certification build's rules ```bash aancer-pack connector check aancer-pack connector check --json ``` ```text OK: @aancer/connector-my-items 0.1.0 meets the certification build rules ( runtime packages, files, bytes) ``` It needs `npm` and access to the npm registry (it runs `npm ci` and `npm audit` in a temporary copy). It refuses, one line per problem, exit 2: - inputs: the package name is not `@aancer/connector-`, the version is not strict `x.y.z`, a `pack.json` field breaks the pack.json rules below, no dependency on `@aancer/connector-framework`, `package-lock.json` missing (commit it); - the runtime dependencies: an `install`, `preinstall`, `postinstall` or `prepare` script (`prepare` is accepted for a package from a registry tarball), a native add-on (`*.node`, `binding.gyp`, `prebuilds/`), a symlink, a copy of the framework inside, a licence outside MIT, ISC, BSD-2-Clause, BSD-3-Clause, Apache-2.0, 0BSD, any known vulnerability, more than 2,000 packages, more than 20,000 files, a file over 32 MiB, more than 128 MiB in total; - the build: `dist/src/index.js` missing, or compiled code that names the framework other than as a plain `require("@aancer/connector-framework")` (no subpath, no ESM `import`, no `.mjs`). The framework comes from a local `.tgz`. A relative `file:` path to it (for example `npm i ../../fw.tgz`) works from any folder depth: `connector check` rebuilds the same relative layout in its temporary folder before `npm ci`. ## Reference connectors Three complete connectors show the patterns. Their full source is public: [reference-connectors](https://aancer.ai/dev/manual/examples/reference-connectors/apikey-contacts/src/index.ts). Each imports only `@aancer/connector-framework`, and each comes with tests that run the **built** connector with `fetch` replaced and an in-memory store, so nothing leaves the machine. | Folder | What it shows | Example host | |---|---|---| | [`apikey-contacts`](https://aancer.ai/dev/manual/examples/reference-connectors/apikey-contacts/src/index.ts) | an API key checked when the connection is saved, numbered pages, a list picker filled from the API, a polling trigger that never starts a flow twice for the same contact | `api.example.org` | | [`oauth2-tasks`](https://aancer.ai/dev/manual/examples/reference-connectors/oauth2-tasks/src/index.ts) | `ConnectorAuth.OAuth2` with PKCE, cursor pages, retries on 429 and 5xx | `api.example.com` | | [`webhook-events`](https://aancer.ai/dev/manual/examples/reference-connectors/webhook-events/src/index.ts) | a `TriggerStrategy.WEBHOOK` trigger that registers itself with the service, checks HMAC signatures, answers the URL check (`WebhookHandshakeStrategy.QUERY_PRESENT`) and renews daily (`WebhookRenewStrategy.CRON`) | `events.example.net` | Each folder holds `pack.json`, `package.json`, `tsconfig.json`, `src/index.ts` and a test under `test/`. ### The API key connector, step by step The key, checked when the connection is saved: ```ts export const auth = ConnectorAuth.SecretText({ displayName: 'API key', description: 'Settings → API keys in your Example Contacts account. Read access is enough for the trigger.', required: true, validate: async ({ auth }) => { try { await call(auth, '/me'); return { valid: true }; } catch (e) { return { valid: false, error: (e as Error).message }; } }, }); ``` `call()` sends the key in a header, times out after 30 s and retries up to 3 times on 429 and 5xx (honouring `Retry-After`); a 401 or 403 becomes a sentence the user understands. `allPages()` follows `page=1..total_pages`. A list picker filled with the connection the step uses: ```ts const listProp = Property.Dropdown({ displayName: 'List', required: true, auth, refreshers: [], options: async ({ auth: conn }) => { if (!conn) return { disabled: true, placeholder: 'Choose a connection first', options: [] }; const lists = await allPages<{ id: string; name: string }>(conn.secret_text, '/lists', 1000); return { options: lists.map((l) => ({ label: l.name, value: l.id })) }; }, }); ``` The action: ```ts export const listContacts = createAction({ auth, name: 'list_contacts', displayName: 'List contacts', description: 'Returns the contacts of a list, page by page up to the limit.', props: { listId: listProp, maxItems: Property.Number({ displayName: 'At most', required: false, defaultValue: 500 }) }, async run({ auth, propsValue }) { const max = Math.min(Math.max(Math.trunc(propsValue.maxItems ?? 500), 1), 10_000); return { contacts: await allPages(auth.secret_text, `/lists/${encodeURIComponent(propsValue.listId)}/contacts`, max) }; }, }); ``` The polling trigger keeps a high-water mark in the store: the newest `createdAt` seen, plus the ids seen at exactly that instant, so two contacts with the same time stamp across two polls are neither lost nor doubled. `onEnable` starts from "now" (contacts that already exist do not start the flow), `onDisable` deletes the mark, `run` returns the new contacts, `test` returns three samples. ```ts export const newContact = createTrigger({ auth, name: 'new_contact', displayName: 'New contact', description: 'Starts once for every contact added to the list.', type: TriggerStrategy.POLLING, props: { listId: listProp }, sampleData: { id: 'c_1', email: 'person@example.org', name: 'A Person', listId: 'l_1', createdAt: '2026-01-01T00:00:00.000Z' }, async onEnable({ auth, propsValue, store }) { /* store.put(MARK, { at: , ids: [] }) */ }, async onDisable({ store }) { await store.delete(MARK); }, async run({ auth, propsValue, store }) { /* fetch created_since=mark.at, keep the fresh ones, move the mark */ }, async test({ auth, propsValue }) { /* three contacts */ }, }); export const exampleContacts = createConnector({ displayName: 'Reference: API key contacts', description: 'Lists contacts page by page and starts a flow for each new contact.', logoUrl: 'https://api.example.org/logo.svg', minimumSupportedRelease: '0.0.0', authors: ['aancer'], auth, actions: [listContacts], triggers: [newContact], }); ``` Its `pack.json`: `{ "displayName": "Reference: API key contacts", …, "category": "Sales", "egressHosts": ["api.example.org"] }`. Run its tests: ```bash cd reference-connectors/apikey-contacts npm install /absolute/path/to/aancer-connector-framework-.tgz typescript npm run build && npm test aancer-pack connector check ``` The reference connectors are named `@aancer/connector-ref-`; for your own connector use `@aancer/connector-`. ## File layout What you write: ```text my-items/ package.json # name @aancer/connector-, version x.y.z, main ./dist/src/index.js package-lock.json # locked runtime dependencies pack.json # pack metadata, see below tsconfig.json src/ index.ts # createConnector(...) export auth.ts lib/*.ts # actions and triggers test/ ``` What the signed pack contains: ```text dev.my-items-0.1.0.ancpack MANIFEST.json # pack manifest with one connector item MANIFEST.sig # the signature (your developer key, or the AANCER platform key after certification) content/piece.tar # the built connector: dist/, a cleaned package.json and the runtime dependencies ``` ## Field reference JSON Schema: [connector.schema.json](https://aancer.ai/dev/schemas/connector.schema.json) (the connector item spec) ### pack.json | Field | Type | Required | Rules | |---|---|---|---| | `displayName` | string | yes | 1 to 80 characters. The name in the catalog | | `title` | string | no | pack title. Default ` connector` | | `description` | string | no | at most 300 characters. Default: the `package.json` description | | `category` | string | no | `AI`, `Comms`, `Commerce`, `Core`, `Business`, `Finance`, `Productivity`, `Content`, `Developer`, `Support`, `Forms`, `HR`, `Payments`, `Marketing`, `Sales`, `Other`. Default `Other` | | `licence` | string | no | `"required"` for a paid connector bound to one customer licence. Leave it out for a free connector. A paid connector's pack version gets the suffix `-l` | | `framework` | string | no | `major.minor` of the connector framework the connector is built against | | `egressHosts` | string[] | no | at most 64 host names the connector calls (`host`, `*.domain`, optional `:port`). A bare `*` is refused. Every other host is blocked at run time. Default `[]` | | `egressFromConnection` | object | no | `{ hostProp, portProp, defaultPort }`: take the host from the connection settings. For systems each customer hosts themselves | ### Connector item spec This is what the build writes into the pack. You do not write it by hand, but it shows exactly what the installation checks. | Field | Type | Required | Rules | |---|---|---|---| | `connectorName` | string | yes | `@aancer/connector-`, name `^[a-z0-9][a-z0-9-]{1,62}$`. Must be unique on the installation | | `connectorVersion` | string | yes | strict `x.y.z`, no pre-release | | `displayName` | string | yes | 1 to 80 characters | | `description` | string | no | at most 300 characters | | `category` | string | yes | see the category list above | | `archive` | string | yes | set by the build; do not edit | | `framework` | string | yes | `major.minor` of the connector framework, written by the build | | `egressHosts` | string[] | yes | at most 64. Hostname with optional `*.` prefix and `:port`. A bare `*` is refused | | `egressFromConnection` | object | no | `{ hostProp (1 to 64), portProp (1 to 64), defaultPort (1 to 65535) }` | | `licenceId` | string | no | lower-case UUID of the customer licence for a paid connector. Absent means free | | `deps` | array | yes | the bill of materials: up to 2000 of `{ name, version, license }` | | `build` | object | no | build facts recorded by the build | | `knowledgeSource` | object | no | for a connector that feeds knowledge sets: `{ contract: 1, label (1 to 40), actions: { list, item, download, estimate? }, siteProps? (up to 5), sharedConnectionView? }`. Action names match `^[a-z][a-z0-9_]{0,63}$` | | `metadata` | boolean | no | `true` when the archive root holds `aancer-metadata.json` | No other fields are allowed. ### Network egress There are two ways to let a connector reach the network: 1. **Fixed hosts** (`egressHosts`): for a cloud API such as `api.example.com` or `*.example.org`. When an administrator enables the connector, these hosts are added to the installation's allow-list. 2. **Host from the connection** (`egressFromConnection`): for a system each customer runs, such as an on-premises database. The administrator types host and port into the connection and switches its egress on. Only that `host:port` is allowed. Loopback, link-local and cloud metadata addresses are always blocked, and an address inside your own network is refused unless an administrator allows it. At run time a connector reaches only the hosts of a **saved connection whose outbound access is switched on** (Admin → Connections). A call without one is refused by the installation's egress gate (`connector.egress … default-deny` in the audit log) and fails inside the connector with a plain `fetch failed`: check the hosts and the connection first. Disable or uninstall removes the grant. Connections and credentials are kept. ### Authentication The connector carries its own authentication: `ConnectorAuth.SecretText(...)`, `ConnectorAuth.CustomAuth({ props: {...} })`, `ConnectorAuth.BasicAuth(...)` or `ConnectorAuth.OAuth2(...)`. Secrets are stored encrypted in the connection. Next part: https://aancer.ai/dev/parts/pages/12-sign-and-install-on-your-developer-edition.md