## 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. ## Sign and install on your developer edition `aancer-pack connector pack` makes the connector pack on your machine: Node.js 20+ and `npm`, no repository, no container. **Step 1: trust your developer key as a developer key (once per installation).** ```bash aancer-pack trust-key --print ``` In the product: **Admin → Extensions** → **Add trust key**. Key id: the `pub-…` id printed. Label: anything. Public key: the PEM block. Tick **Developer key: may sign my own connectors on this development install** (the box shows on a developer edition only). Save. The list tags it "developer key". (`aancer-pack dev` against your developer edition does this for you the first time.) **Step 2: build, pack and sign.** ```bash npm run build aancer-pack connector pack ``` ```text wrote …/dist-pack/dev.my-items-0.1.0.ancpack (dev.my-items 0.1.0, signed by pub-<12 hex>, bytes archive, runtime packages) next: on a developer edition, trust this key as a developer key (aancer-pack trust-key --print), then import … ``` It applies the rules of `connector check` to a fresh `npm ci` of your lock, points the compiled `require("@aancer/connector-framework")` at the runner's framework, drops source files and maps, makes the archive, and writes `dist-pack/manifest.json`, `dist-pack/content/piece.tar` and the signed `dist-pack/-.ancpack`. `publisher.keyId` is always the id of the key it signs with. Options: `--key ` (default `~/.aancer/dev-signing.key`, made on first use), `--out `, `--id ` (default `dev.`), `--publisher `. Exit `0` written, `2` a rule refused or the input is wrong (nothing written). It makes free packs only: a `pack.json` with `"licence": "required"` is refused (licence binding is done by certification). Unlike certification, it does not load the built connector in a locked-down container; the installation loads it when you activate it. **Step 3: verify (and optionally validate).** ```bash aancer-pack verify dist-pack/dev.my-items-0.1.0.ancpack --pubkey ~/.aancer/dev-signing.pub aancer-pack validate dist-pack/dev.my-items-0.1.0.ancpack --remote http://localhost # the installation's checks, nothing stored ``` **Step 4: import and activate.** **Admin → Extensions → Import pack** → choose the file → Import. The summary and the pack card say "Developer key: this development install only" (never "Certified" or "Platform"). Activate. The connector row turns Ready once the automation runner has loaded it (it needs the developer licence). At import the installation runs the build rules again over the archive: the build must record 0 known vulnerabilities and 0 install scripts, no install script in any package of the archive, no `prepare` in the connector's own `package.json`, no native add-on files, permissive licences only. **Before step 5: point it at a real API.** The scaffold's example host `api.example.com` does not exist on the internet. Put your API's host into `pack.json` `egressHosts` (and its address into the connection's Base URL), raise the version and pack again. **Step 5: use it.** **Admin → Connectors → Catalog**: the connector is listed. Enable it (this opens its egress hosts), add a connection with a test account, and call an action from a workflow step, or start a workflow with its trigger. To ship a fix, raise the version in `package.json` and repeat steps 2 to 4: a pack id plus version never changes (`PACK_VERSION_CONFLICT` for different content under a known version). For a faster loop, `aancer-pack dev [dir] --target http://localhost --trust-key-on-target --watch` signs with your developer key, imports and activates on your developer edition, and does it again on every save. ### The same file on any other edition Imported on an installation that is not a developer edition (or a developer edition without the developer licence, or with the key not ticked), the pack is refused with `PACK_SIGNER_NOT_ALLOWED` ("must be signed by the platform publisher"). Nothing is listed. To reach customers, a connector goes through certification. Next part: https://aancer.ai/dev/parts/reference/16-submit-for-certification.md