<!-- AANCER Developer Reference (English): every field, limit and error code, part 14 of 16. All parts: https://aancer.ai/dev/llms.txt -->

## Common errors

Import and manifest errors (path `/items/<itemId>/spec/...`):

| Message | Fix |
|---|---|
| https only (`APP_URL_INVALID`) | Use https |
| origin must equal the URL origin (`APP_URL_INVALID`) | Set `origin` to scheme, host and port of `url`, no trailing slash |
| the app origin must differ from this platform's own address (`APP_URL_INVALID`) | Host the app on its own host name |
| the host is hard-blocked (loopback, link-local or metadata) (`APP_URL_INVALID`) | Use a real DNS name |
| placeholder {{x}} is not allowed (only {{workspace}}) (`APP_URL_INVALID`) | Only `{{workspace}}` |
| credentials in the URL are not allowed / fragments are not allowed | Remove `user:pass@` and `#...` |
| unknown capability '...' (`APP_CAPABILITY_UNKNOWN`) | Use the capability list. Dataset ids have no dashes |
| a bare wildcard is not allowed (`APP_EGRESS_WILDCARD`) | `api.example.com` or `*.example.com` |
| sandbox token '...' is not allowed | Only the five tokens listed |
| must have required property 'sso' | Add `sso` |
| warning `APP_WORKSPACE_PLACEHOLDER_EMPTY` | Add `"workspace"` to `sso.scopes`, or drop `{{workspace}}` from the URL |
| `APP_ID_TAKEN`: The app id '...' is already used by the active pack '...' | Retire that pack, or use another app id |

Runtime errors:

| Code | Message | Fix |
|---|---|---|
| `FEATURE_NOT_LICENSED` | Embedded apps are not included in the licence of this installation. | The installation needs the Embedded apps licence feature |
| `APP_NOT_FOUND` | App '...' is not active in this workspace. | Activate the pack for this workspace |
| `APP_ORIGIN_UNAPPROVED`, `APP_CAPABILITIES_CHANGED` | App '...' has changes an administrator must approve first. | Approve under Manage app |
| `APP_SECRET_MISSING` | App '...' has no app secret yet. | Create the app secret |
| `APP_EMBED_REFUSED` | The app has not allowed this platform to embed it (frame-ancestors). Reason `no_csp`, `not_allowed`, `xfo`, `unreachable` or `egress` | Fix the header, remove `X-Frame-Options`, or allow the origin in the network rules |
| `APP_INTROSPECT_UNAUTHORIZED` (401) | Introspection is not authorised. | Send HTTP Basic with the app id and the current app secret |
| `SSO_NOT_ENABLED` (409) | This app does not use sign-in by one-time code. | Set `sso.mode: "code"` |
| `APP_SESSION_INVALID` | The app session is not valid. | Reopen the app |
| `APP_PKCE_REQUIRED` | A PKCE challenge is required: a codeChallenge of 43 base64url characters. | Send an S256 challenge |
| `APP_AUTHORIZE_RATE_LIMITED` | Too many sign-in codes were requested for this app session. | Renew only when introspection says inactive |
| `CAPABILITY_NOT_DECLARED` | The app did not declare '...'. | Declare it and ship a new version |
| `CAPABILITY_FORBIDDEN` | '...' is not approved for this app session. / Your seat lacks ... in this workspace. | Approve it, or give the user the permission |
| `APP_WRITE_MODE_INVALID` | Apps may only append or upsert. | Use `append` or `upsert` |
| `APP_WRITE_ROWS_INVALID` | rows must be a non-empty array. | |
| `NAVIGATE_REFUSED` | | Use an AANCER path such as `/dashboards/...` |
| `BRIDGE_UNAVAILABLE` | | AANCER could not be reached; retry |
| token `invalid_client` (401) | Client authentication failed: send HTTP Basic with the app id and the app secret. | Check `APP_ID` and `APP_SECRET` |
| token `invalid_grant` (400) | The code is not valid (unknown, expired, already used, or not issued for this app and verifier). | Get a new code through `authorize` |
| token `invalid_request` (400) | code and code_verifier are required; the verifier is 43 to 128 unreserved characters. | |
| token `unsupported_grant_type` (400) | Only grant_type=authorization_code is supported. | |
| token `429` | Too many failed attempts from this address. | Wait a minute, then retry with the correct app secret |
| token `503` | The sign-in service is briefly unavailable. | Retry |

## Limits and editions

- Up to 20 capabilities and 20 extra hosts per app. The sign-in code lives 60 seconds; tokens live 5 minutes by default.
- Embedded apps need the Embedded apps licence feature. Without it, apps do not show and their calls are refused.
- Users need `apps.view_own`. Approving needs `apps.manage_own`, or `extensions.manage` for install-scoped apps.
- Check your edition on [aancer.ai/pricing](https://aancer.ai/pricing).



## Connectors

A connector is an integration with one external system: a set of actions and triggers that workflows, agents, chat tools and knowledge sources call. AANCER offers 750+ connectors. Most of them come from the connector library that ships with each release, and an administrator installs them from the catalog with one click and no restart.

You can build your own connector for a system that is not covered, such as an in-house ERP or a regional service. A connector is written in TypeScript with the AANCER connector framework (`@aancer/connector-framework`). The framework comes with the developer kit, with full TypeScript declarations (node10 and node16 module resolution) and a scaffold. A connector written against it builds against the runner's own copy of the framework during certification, so the pack ships without a bundled copy. A connector reaches an installation as a signed **connector pack**: a pack with exactly one `connector` item, which `aancer-pack` builds from your code.

Connector code runs inside AANCER, so the rules are stricter than for other packs. **Connector packs for production are signed by AANCER through certification.** Partners build and test the connector, then submit it. AANCER reviews it, builds the archive and signs the pack. On every edition except the developer edition, a connector pack signed with any other key is refused.

**On the developer edition you sign your own connectors.** Sign the pack with your developer key and it installs on your installation only: the pack is bound to that installation's install id, and both the gateway and the connector runner check it. Remove the key and the connector stops. To ship the connector to customers, submit it for certification.

Outbound network access is denied by default. A connector can reach only the hosts it declares, and only after an administrator clicks **Enable**.

## Quick start

Start from the scaffold, `aancer-pack init connector <name>`, or write it by hand. A connector with one action that echoes its input.

`package.json`:

```json
{
  "name": "@aancer/piece-example-echo",
  "version": "0.1.0",
  "main": "./dist/src/index.js",
  "dependencies": {
    "@aancer/connector-framework": "^0.33"
  }
}
```

`src/index.ts`:

```ts
import { createConnector, createAction, Property, ConnectorAuth } from '@aancer/connector-framework';

const echo = createAction({
  name: 'echo',
  displayName: 'Echo',
  description: 'Returns the text you send.',
  props: {
    text: Property.ShortText({ displayName: 'Text', required: true }),
  },
  async run({ propsValue }) {
    return { text: propsValue.text };
  },
});

export const connector = createConnector({
  displayName: 'Example echo',
  auth: ConnectorAuth.None(),
  minimumSupportedRelease: '0.82.0',
  logoUrl: 'https://cdn.example.com/echo.png',
  authors: ['acme'],
  actions: [echo],
  triggers: [],
});
```

`pack.json`:

```json
{
  "displayName": "Example echo",
  "description": "Echoes its input back. Useful to test connector install.",
  "category": "Developer",
  "egressHosts": []
}
```

Submit these files for certification. The result is a signed connector pack that any AANCER installation accepts.

## File layout

What you write:

```text
example-echo/
  package.json         # name @aancer/piece-<name>, 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
    lib/*.ts           # actions and triggers
  test/*.ts
```

What the certified pack contains:

```text
conn.example-echo-0.1.0.ancpack
  MANIFEST.json        # pack manifest with one connector item
  MANIFEST.sig         # AANCER platform signature
  content/<archive>    # the built connector, written by the build
```

## 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 `<displayName> 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<first 8 hex of the licence id>` |
| `framework` | string | no | `major.minor` of the connector framework the connector is built against |
| `egressHosts` | string[] | no | at most 64 fixed hosts the connector calls. 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 certification writes into the pack. You do not write it by hand, but it shows exactly what the installation checks.

| Field | Type | Required | Rules |
|---|---|---|---|
| `pieceName` | string | yes | `@aancer/piece-<name>`, name `^[a-z0-9][a-z0-9-]{1,62}$`. Must be unique on the installation |
| `pieceVersion` | 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 certification |
| `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 certification |
| `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 clicks **Enable**, 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.

Disable or uninstall removes the grant. Connections and credentials are kept.

### Authentication

The connector carries its own authentication: `ConnectorAuth.None()`, `ConnectorAuth.SecretText(...)`, `ConnectorAuth.CustomAuth({ props: {...} })` or the framework's OAuth2 properties. Secrets are stored encrypted in the connection.

### Build rules

Certification refuses a connector that breaks any of these rules. Check them before you submit:

- No `install`, `preinstall`, `postinstall` or `prepare` scripts in any dependency.
- No native add-ons (`*.node`, `binding.gyp`, `prebuilds/`), no symlinks.
- Do not bundle the connector framework itself.
- `npm audit --omit=dev` reports 0 vulnerabilities.
- Dependency licences: MIT, ISC, BSD-2-Clause, BSD-3-Clause, Apache-2.0 or 0BSD.
- The built connector loads without network access.
- At most 2000 packages, 20,000 files and 32 MiB per file.
- `package-lock.json` is committed.

## Full examples

### A paid connector for a customer-hosted database

`pack.json`:

```json
{
  "title": "Example ERP connector",
  "displayName": "Example ERP",
  "description": "Read-only orders, invoices, production status and customers from the ERP database.",
  "category": "Business",
  "licence": "required",
  "egressHosts": [],
  "egressFromConnection": { "hostProp": "server", "portProp": "port", "defaultPort": 1433 }
}
```

The connection properties in the connector must include `server` and `port`:

```ts
import { ConnectorAuth, Property } from '@aancer/connector-framework';

export const erpAuth = ConnectorAuth.CustomAuth({
  displayName: 'ERP connection',
  required: true,
  props: {
    server: Property.ShortText({ displayName: 'Server', required: true }),
    port: Property.Number({ displayName: 'Port', defaultValue: 1433, required: true }),
    database: Property.ShortText({ displayName: 'Database', required: true }),
    username: Property.ShortText({ displayName: 'User name', required: true }),
    password: ConnectorAuth.SecretText({ displayName: 'Password', required: true }),
  },
  validate: async () => ({ valid: true }),
});
```

### The signed manifest of a free connector

```json
{
  "v": 2,
  "kind": "bundle",
  "id": "conn.example-echo",
  "version": "0.1.0",
  "title": "Example echo connector",
  "publisher": { "name": "Evntx FZCO", "keyId": "platform-<12 hex>" },
  "parameters": [],
  "assets": [
    { "path": "<set by the build>", "sha256": "<64 hex characters>", "contentType": "application/x-tar" }
  ],
  "items": [
    {
      "kind": "connector",
      "schemaVersion": 1,
      "id": "example-echo",
      "scope": "install",
      "spec": {
        "pieceName": "@aancer/piece-example-echo",
        "pieceVersion": "0.1.0",
        "displayName": "Example echo",
        "description": "Echoes its input back. Useful to test connector install.",
        "category": "Developer",
        "archive": "<set by the build>",
        "framework": "<major.minor>",
        "egressHosts": ["api.example.com"],
        "deps": [{ "name": "ms", "version": "2.1.3", "license": "MIT" }]
      }
    }
  ]
}
```

Next part: https://aancer.ai/dev/parts/reference/15-install-and-test.md
