diff --git a/.github/workflows/contracts.yml b/.github/workflows/contracts.yml new file mode 100644 index 0000000..3b7c2ca --- /dev/null +++ b/.github/workflows/contracts.yml @@ -0,0 +1,39 @@ +name: contracts + +on: + push: + paths: + - 'contracts/**' + - 'conformance/**' + - '.github/workflows/contracts.yml' + pull_request: + paths: + - 'contracts/**' + - 'conformance/**' + - '.github/workflows/contracts.yml' + +permissions: + contents: read + +jobs: + openapi-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - name: Lint OpenAPI description + working-directory: contracts + run: npx --yes @redocly/cli@1 lint staff-api-v1.openapi.yaml + + conformance-typecheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - name: Typecheck conformance suite + working-directory: conformance + run: npm ci && npm run typecheck diff --git a/README.md b/README.md index dff6508..077d470 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ This repo holds the glossary, domain model, architecture decisions, conventions - **"How do I do X?"** → [`guides/`](guides/) - **"What's in a specific repo?"** → [`repos/`](repos/) - **"How should I style / structure / test this?"** → [`CONVENTIONS.md`](CONVENTIONS.md), [`TESTING.md`](TESTING.md) +- **"What does the staff REST API look like?"** → [`contracts/`](contracts/) ## Learn more diff --git a/conformance/.gitignore b/conformance/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/conformance/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/conformance/README.md b/conformance/README.md new file mode 100644 index 0000000..d565348 --- /dev/null +++ b/conformance/README.md @@ -0,0 +1,107 @@ +# Staff API conformance suite + +A black-box test suite for the staff REST API defined in `contracts/staff-api-v1.md`. Each backend runs it in CI against a live install. The suite knows nothing about the backend's language or framework; it only speaks HTTP. + +## Run it + +Node 22 or newer. + +```bash +cd conformance +npm ci +ESCALATED_CONFORMANCE_URL=http://localhost:8000/support/api/v1 \ +ESCALATED_CONFORMANCE_TOKEN= \ +ESCALATED_CONFORMANCE_ADMIN_TOKEN= \ +npm test +``` + +| Variable | Required | Meaning | +|---|---|---| +| `ESCALATED_CONFORMANCE_URL` | yes | Full API base, including the prefix and `/v1` | +| `ESCALATED_CONFORMANCE_TOKEN` | yes | Token with the `agent` ability | +| `ESCALATED_CONFORMANCE_ADMIN_TOKEN` | no | Token with the `admin` ability, for the report routes | +| `ESCALATED_CONFORMANCE_REVOCABLE_TOKEN` | no | A spare agent token. The `POST /auth/revoke` test spends it and checks it is 401 afterwards. Without it that test is skipped | +| `ESCALATED_CONFORMANCE_CONNECT_CODE` | no | A fresh connect code. See [Connect fixture](#connect-fixture) | +| `ESCALATED_CONFORMANCE_CONNECT_CODE_2` | no | A second fresh code for the same verifier and `redirect_uri`, spent by the failure cases | +| `ESCALATED_CONFORMANCE_CONNECT_VERIFIER` | no | The `code_verifier` both codes were issued for | +| `ESCALATED_CONFORMANCE_CONNECT_REDIRECT_URI` | no | The `redirect_uri` both codes were issued for | +| `ESCALATED_CONFORMANCE_FORBIDDEN_TRANSITION` | no | A status change this backend refuses, as `from:to`, for example `open:live`. The suite checks it answers 422 with `errors.status`. Unset on a backend that allows every change; that test is then skipped | + +## Seed the install must have + +Each backend's CI provides this before `npm test`: + +- Two staff users: the token's owner and one other agent. +- At least three open tickets, at least one unassigned, and at least one open ticket assigned to someone. The action tests change that ticket and put its status, priority and assignee back; the API cannot unassign, so an assigned ticket is needed for the assign test. The replies and notes they add stay on the ticket. +- At least one department. +- Canned responses and macros are optional. The macro test runs only when a macro exists whose actions are all `priority` or `note`; otherwise it is skipped with the reason. Status actions are left out because the suite cannot know whether the backend lets it put the status back. + +Run it against a throwaway seed. The suite sends `DELETE /tickets/{reference}` with an agent token and expects 403; a backend that gets that wrong would delete the ticket. + +Request counts per run, measured against a mock that serves every feature: + +| Bucket | Requests | Limit | +|---|---|---| +| Agent token | 44 to 46 (45 with every fixture set; more only when a restore step has to retry) | 60 per minute per token | +| Revocable token | 2 | 60 per minute per token | +| Token minted by the connect test | 2 | 60 per minute per token | +| `POST /auth/exchange`, per IP | 11 (1 + 4 + 6 until the 429), at most 16 | 10 per minute per IP | +| Other unauthenticated or invalid-token requests, per IP | 7 (5 with no token, 2 with a garbage token) | the install's per-IP limit | + +The exchange limit is per IP, not per token, so its requests are counted on their own. The rate limit test in `70-connect` exists to use that bucket up, which is why it runs last. Wait a minute before running the suite again from the same IP, or the first exchange tests see 429. + +### Connect fixture + +The connect tests in `70-connect` need two codes that a staff member would get by clicking Approve on the connect page. A suite that only speaks HTTP cannot click, so each backend's CI seeds them before `npm test`: + +- Pick one `code_verifier` (43 to 128 characters from `[A-Za-z0-9-._~]`) and one valid `redirect_uri`, for example `https://bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.chromiumapp.org/`. +- Issue two codes for the token owner through the backend's own code-issuing path, with the challenge computed from that verifier and that `redirect_uri`. Pass them in as `ESCALATED_CONFORMANCE_CONNECT_CODE` and `ESCALATED_CONFORMANCE_CONNECT_CODE_2`. +- Give them a long TTL, for example an hour, so a slow CI job does not see them expire. Do this in CI only: production keeps the contract's 60-second TTL, and a command or route that issues codes without the connect page must not be reachable outside the test environment. + +The tests check that the first code gives a token with abilities `["agent"]` and `Cache-Control: no-store`, that a second use of it is 400, and that the second code is 400 with a wrong verifier and then also 400 with the right one, because a failed exchange still consumes the code. Without the fixture these three tests are skipped with the reason. The rate limit test needs only `auth.exchange` in `GET /meta`. + +`npm run typecheck` checks the TypeScript without calling anything. + +## What a failure looks like + +- URL unreachable: one failure in `00-meta` that names the URL, for example `Could not connect to http://127.0.0.1:9/meta: ...`. +- `GET /meta` answers 404: one failure, `Backend does not serve staff API contract v1 (GET /meta is 404)`. Every other file is skipped. +- `GET /meta` answers anything else that is not a 200 JSON object with a string `api_version`: one failure that says what came back, for example `GET /meta answered 302 (Location: http://127.0.0.1:8787/login); contract v1 says /meta is public and answers 200` or `GET /meta returned non-JSON (text/html): ...`. Every other file is skipped. + +## Writing tests + +Test files import only from `../src`: + +```ts +import { api, env, describeContract } from '../src'; + +describeContract('GET /tickets', () => { + it('requires a token', async () => { + const res = await api('GET', '/tickets', { token: null }); + expect(res.status).toBe(401); + }); +}); +``` + +`env()` returns `{ baseUrl, agentToken, adminToken? }` and throws a clear message when a variable is missing. + +`api(method, path, { token?, query?, body?, retry? })` returns `{ status, headers, json, text }`. + +- `token` defaults to the agent token. Pass `null` to send no Authorization header, or another string to use that token. +- `json` is `null` when the body is empty or not JSON. +- `text` is the raw body. +- A 429 is retried once after waiting `Retry-After` seconds. Pass `retry: false` to get the 429 itself. +- A connection failure throws an error that names the URL. + +### Skipping when the contract is absent + +`vitest.config.ts` registers `src/global-setup.ts` as a Vitest `globalSetup`. It calls `GET /meta` once per run and shares the result with every test file through `provide('contractState', ...)`. The state is `ok` (a 200 JSON object with a string `api_version`), `missing` (anything else, with a message naming what came back), `unreachable` or `misconfigured`. + +- `tests/00-meta.test.ts` reads the state with `inject('contractState')` and reports the failure once, with the right message. +- Every other test file wraps its tests in `describeContract(name, fn)` instead of `describe`. When the state is not `ok`, the block is skipped, so a backend without the API gets one clear failure and not a wall of red. + +Files run one at a time, in name order, because they share one live install. `vitest.config.ts` sets `fileParallelism: false` and an alphabetical sequencer (`src/sequencer.ts`), since Vitest's default sequencer does not promise an order. Name new files `NN-topic.test.ts`. + +`expectSchema(name, value)` (from `../src`) validates a value against a component of `contracts/staff-api-v1.openapi.yaml` with Ajv and fails with the full error list. `hasFeature(name)` tells whether `GET /meta` lists a feature, for `it.skipIf(!hasFeature('x'))`; it makes no request. `connectFixture()` returns the connect fixture or the names of the variables that are missing. `forbiddenTransition()` reads `ESCALATED_CONFORMANCE_FORBIDDEN_TRANSITION`. The contract lets each backend choose which status changes it allows, so the status round-trip test tries `waiting_on_customer`, `in_progress`, `waiting_on_agent` and `open` in turn, treats a 422 with `errors.status` (`isRefusedTransition`) as "not allowed from here", and skips when every candidate is refused. + +Assertions in a `finally` block use `expect.soft`, so a failure in the clean-up does not hide the first failure in the test. diff --git a/conformance/package-lock.json b/conformance/package-lock.json new file mode 100644 index 0000000..9885010 --- /dev/null +++ b/conformance/package-lock.json @@ -0,0 +1,1679 @@ +{ + "name": "escalated-staff-api-conformance", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "escalated-staff-api-conformance", + "devDependencies": { + "@types/node": "^22.20.7", + "ajv": "^8.20.0", + "ajv-formats": "^3.0.1", + "typescript": "^7.0.2", + "vitest": "^5.1.2", + "yaml": "^2.9.1" + }, + "engines": { + "node": ">=22" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.3.tgz", + "integrity": "sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@oxc-project/types": { + "version": "0.160.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.160.0.tgz", + "integrity": "sha512-gw4k9syEmnckbOgw2A2FU1TBDdX9hfwV9jEn/uio65pguPzwWiXQS3OIJDMEhv9m06tj9XiEe6RoD0YA+LgreA==", + "dev": true, + "license": "MIT", + "peer": true, + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.3.4.tgz", + "integrity": "sha512-xCW8CkL/ualx/SbYqeG9iK87lJCZGDQ0soE+kaORJ0Bd+pHALyE4qK7BStmEAyYWLEzZ3/biSIpA6/7GDFvzIg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.3.4.tgz", + "integrity": "sha512-5lifIO+b/prcM9sx/bkPN4w6UEToEfQ3gjhx0+0neuL+dkYskI792CfAq03T51jc8JFcaYXs2hi3l8RjiH/VWQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.3.4.tgz", + "integrity": "sha512-RCgxTI4AJQxhVF//BI3ImQOsXTHrF4Eg+f99jBy8WoETA2kSEGFxpnrVmW0leQq/2aBR4R5AC6csmy3rc66e3Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.3.4.tgz", + "integrity": "sha512-zNPJVVPUaDEj+L0lImoK3rFv2b+Z5gNijI6DWu/fcD3/1TfmRXKb9ZyxbSN+2AhlctqjbNzUvCsMa+EBhnEM4Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.3.4.tgz", + "integrity": "sha512-upP6g7ZIRy5by1RDQ/EphHIdJ5xK0eUD7sUgfZFWJ49s4XdbYsIvIlAPtrFpayR70Hhf9J22lb4Pm8/9FhrZmg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.3.4.tgz", + "integrity": "sha512-SAX5C5+poMLCxu8dkPF6h5yst40rkzs+9Y3cbPn2OFSydmHjAEprrGi64zGgnYyPIVZfdGUFqJ2fJbfbnHI+mA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.3.4.tgz", + "integrity": "sha512-nwHqdlRZS6GWBef3dG5/pMY6RNTBBUjj7s0Da+m6xsFpe7jx6IC46SLZcCu8f46JOfCovZmwnrz51EzGE+7Fyw==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.3.4.tgz", + "integrity": "sha512-Gr78X2ur/AgLCkmZgHffk/FerIX8S5zb/eII4bCcvJo0ANzeXhTShahdNbpnY6bpiszIAgIfiuKS9ziziWsamw==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.3.4.tgz", + "integrity": "sha512-o9Wcn8nWrsQasaBRYM4d//FwhlBsTJYWkPVlhlt6FwzpwEoovY4IopRZjk5Fq3+ntRuSDORJjF/nA8sFeF2q6w==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.3.4.tgz", + "integrity": "sha512-UDWu4jkVcx2kiBKm3Ec//4lVCbeTWj8gmJ9SyLWCdLWtTlyq7fQVeVV/14nXvRtSLErvJ2+yA/Ux5taS31Y17Q==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.3.4.tgz", + "integrity": "sha512-W9mGtTa0w4fWh8RLMNPyaEhhcuqUfO07Q4I1bBc4PDMNg7gQSw0yPQNQ3D0qwbkXwxbyL4YrIzc8n6k1vuFExQ==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.3.4.tgz", + "integrity": "sha512-8B+ofyQZ7/aCmkqnyMonPr5zKLqMVNczhRGFNtdIuItiwNn8iQWJawMq2E58r7bxD1XEbtRRsULY/eCWwZQ01Q==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.3.4.tgz", + "integrity": "sha512-TlD0FSZaC7o2B4NCe9V5N11ugTnhzTM9ksj4sgRLvrKosDzjEkvlsTX3ehkw4ZlPv8AADimZZTvJGEa16pfXug==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.3.4.tgz", + "integrity": "sha512-jwO8P3o53ygo7b5061B7BeaJ1BGv3BKZ6jroFdw/01qWry7Z+qNBlDvulzbTle5s/A0Fc1FRgsTxrke9DvsSbA==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@oxc-project/types": "0.160.0" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.3.4.tgz", + "integrity": "sha512-8adGMrNtrdzi2WD1ozhYapER59gD8Q/DV6SCKJlyG2HqULPdeQUBvMa33lTsiEYwIqTZUaIU2MmvPp5f1wbtXA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.3.4.tgz", + "integrity": "sha512-rIMjtESdXJCIoOiUTroQ1Y1rjVDZkuUVRUxs3APX2vNv175D7TDWvzdELiIhzGq9cUNUFat+co+PTmPHPqSREg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz", + "integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.11.tgz", + "integrity": "sha512-YBdNe5JcjYR0sPhJW1QIeRCmI11YhYvaRuGCs9+WCeTTb+Yhb2BE2XMe5/wAqF10FK5g3+q1PDhQABfT7aX0gg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "22.20.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.7.tgz", + "integrity": "sha512-F/Mcc4pD3YwXQCG50hb8BjB5RmrOere6hge7n2XHf0V8tpkZOVEjwYv9Ql7n0MpMn8Bv7+q12P9w6UHsBm0Sfw==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/@typescript/typescript-aix-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-aix-ppc64/-/typescript-aix-ppc64-7.0.2.tgz", + "integrity": "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-arm64/-/typescript-darwin-arm64-7.0.2.tgz", + "integrity": "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-darwin-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-darwin-x64/-/typescript-darwin-x64-7.0.2.tgz", + "integrity": "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-arm64/-/typescript-freebsd-arm64-7.0.2.tgz", + "integrity": "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-freebsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-freebsd-x64/-/typescript-freebsd-x64-7.0.2.tgz", + "integrity": "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm/-/typescript-linux-arm-7.0.2.tgz", + "integrity": "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-arm64/-/typescript-linux-arm64-7.0.2.tgz", + "integrity": "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-loong64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-loong64/-/typescript-linux-loong64-7.0.2.tgz", + "integrity": "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-mips64el": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-mips64el/-/typescript-linux-mips64el-7.0.2.tgz", + "integrity": "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-ppc64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-ppc64/-/typescript-linux-ppc64-7.0.2.tgz", + "integrity": "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-riscv64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-riscv64/-/typescript-linux-riscv64-7.0.2.tgz", + "integrity": "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-s390x": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-s390x/-/typescript-linux-s390x-7.0.2.tgz", + "integrity": "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-linux-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-linux-x64/-/typescript-linux-x64-7.0.2.tgz", + "integrity": "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-arm64/-/typescript-netbsd-arm64-7.0.2.tgz", + "integrity": "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-netbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-netbsd-x64/-/typescript-netbsd-x64-7.0.2.tgz", + "integrity": "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-arm64/-/typescript-openbsd-arm64-7.0.2.tgz", + "integrity": "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-openbsd-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-openbsd-x64/-/typescript-openbsd-x64-7.0.2.tgz", + "integrity": "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-sunos-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-sunos-x64/-/typescript-sunos-x64-7.0.2.tgz", + "integrity": "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-arm64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-arm64/-/typescript-win32-arm64-7.0.2.tgz", + "integrity": "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@typescript/typescript-win32-x64": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@typescript/typescript-win32-x64/-/typescript-win32-x64-7.0.2.tgz", + "integrity": "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "Apache-2.0", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/@vitest/mocker": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.2.tgz", + "integrity": "sha512-UGc97wUIy0Ji2+9GxzHEJiOhiwkaukgE7VYcUNnjpX3sWnwQ8XogmNXX4WyOukxYgKb8Nh2XFa7KId0ZjpmVhQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.31", + "@vitest/spy": "5.1.2", + "estree-walker": "^3.0.3", + "magic-string": "^1.4.5" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9 || ^3.0.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/spy": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.2.tgz", + "integrity": "sha512-PQl0/3+p9GaY71+MHywN6oyHfLhVDD5kcbm7oNRldA2F0ExMU3S8RQdnpteJ9gFAdK5P6KCgE6LqCpUgy57KzA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/chai": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", + "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz", + "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "dev": true, + "license": "MIT" + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "peer": true, + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "peer": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/napi-windows-process-start-time": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/napi-windows-process-start-time/-/napi-windows-process-start-time-0.1.0.tgz", + "integrity": "sha512-zHxhzKsIFu3elch3eFw69WEUGc79DFhbc3nD/WEOzWL/pFFLZRW13EHnuO0c+0YjncE5uCaS9ICHxOBXkb6vPw==", + "cpu": [ + "x64", + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/obug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", + "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC", + "peer": true + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.33", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz", + "integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "peer": true, + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/rolldown": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.3.4.tgz", + "integrity": "sha512-p2rq4bfBmF0M6yaR8+A89fbkBQynZI2fxUW4G07eq9kpctAkpo7q5BZ4X4Mo4XZ7HHROu33cX9PeopUFN6u+2Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@oxc-project/types": "=0.160.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.3.4", + "@rolldown/binding-android-arm64": "1.3.4", + "@rolldown/binding-darwin-arm64": "1.3.4", + "@rolldown/binding-darwin-x64": "1.3.4", + "@rolldown/binding-freebsd-x64": "1.3.4", + "@rolldown/binding-linux-arm-gnueabihf": "1.3.4", + "@rolldown/binding-linux-arm64-gnu": "1.3.4", + "@rolldown/binding-linux-arm64-musl": "1.3.4", + "@rolldown/binding-linux-ppc64-gnu": "1.3.4", + "@rolldown/binding-linux-s390x-gnu": "1.3.4", + "@rolldown/binding-linux-x64-gnu": "1.3.4", + "@rolldown/binding-linux-x64-musl": "1.3.4", + "@rolldown/binding-openharmony-arm64": "1.3.4", + "@rolldown/binding-wasm32-wasi": "1.3.4", + "@rolldown/binding-win32-arm64-msvc": "1.3.4", + "@rolldown/binding-win32-x64-msvc": "1.3.4" + } + }, + "node_modules/source-map-js": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz", + "integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==", + "dev": true, + "license": "BSD-3-Clause", + "peer": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinybench": { + "version": "6.2.5", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.5.tgz", + "integrity": "sha512-b/8GRMdnY4cqkfCLyaFpTGIv1qwfi3oT0mWaepwT++6Z/ZrYehNfZZ2JDKVLKGhNoEkS3IIB1ELtCT0XS5DtOA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/tinyexec": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.4.0.tgz", + "integrity": "sha512-PV6lIcJQh57aFeJDwx16JNHmgFRh5xguzallrDW1qe8nAghYgr5MKz2K5k7wEyV/ygZhdnIAP8+HZSarHPBCsg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/typescript": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-7.0.2.tgz", + "integrity": "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc" + }, + "engines": { + "node": ">=16.20.0" + }, + "optionalDependencies": { + "@typescript/typescript-aix-ppc64": "7.0.2", + "@typescript/typescript-darwin-arm64": "7.0.2", + "@typescript/typescript-darwin-x64": "7.0.2", + "@typescript/typescript-freebsd-arm64": "7.0.2", + "@typescript/typescript-freebsd-x64": "7.0.2", + "@typescript/typescript-linux-arm": "7.0.2", + "@typescript/typescript-linux-arm64": "7.0.2", + "@typescript/typescript-linux-loong64": "7.0.2", + "@typescript/typescript-linux-mips64el": "7.0.2", + "@typescript/typescript-linux-ppc64": "7.0.2", + "@typescript/typescript-linux-riscv64": "7.0.2", + "@typescript/typescript-linux-s390x": "7.0.2", + "@typescript/typescript-linux-x64": "7.0.2", + "@typescript/typescript-netbsd-arm64": "7.0.2", + "@typescript/typescript-netbsd-x64": "7.0.2", + "@typescript/typescript-openbsd-arm64": "7.0.2", + "@typescript/typescript-openbsd-x64": "7.0.2", + "@typescript/typescript-sunos-x64": "7.0.2", + "@typescript/typescript-win32-arm64": "7.0.2", + "@typescript/typescript-win32-x64": "7.0.2" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/vite": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.4.0.tgz", + "integrity": "sha512-X2nUJg+9cutlz3hzqyO6p+WTwk9H257DjwAEf9EQYUFrQbDItmetadi9gYmb+l7VDy4r3VXLUnmLTwuPmzejDw==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.33", + "rolldown": "~1.3.2", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3", + "napi-windows-process-start-time": "^0.1.0" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1 || ^0.8.0", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitest": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.2.tgz", + "integrity": "sha512-VIa2wXV208WraXUbzH+dQUrGcFpPuaiRA8HlhXS8R6/sy9cynw6OMqGj8fmAlH1hot7huTCtWUE14+FdXU3eLw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/chai": "^5.2.2", + "@vitest/mocker": "5.1.2", + "chai": "^6.3.0", + "es-module-lexer": "^2.3.2", + "expect-type": "^1.4.0", + "magic-string": "^1.4.5", + "obug": "^3.0.0", + "picomatch": "^4.0.7", + "std-env": "^4.3.0", + "tinybench": "^6.2.3", + "tinyexec": "^1.3.1", + "tinyglobby": "^0.2.17", + "why-is-node-running": "3.2.1" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^22.12.0 || ^24.0.0 || >=26.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "5.1.2", + "@vitest/browser-preview": "5.1.2", + "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", + "@vitest/coverage-istanbul": "5.1.2", + "@vitest/coverage-v8": "5.1.2", + "@vitest/ui": "5.1.2", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, + "node_modules/why-is-node-running": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-3.2.1.tgz", + "integrity": "sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==", + "dev": true, + "license": "MIT", + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=20.11" + } + }, + "node_modules/yaml": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz", + "integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==", + "dev": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + } + } +} diff --git a/conformance/package.json b/conformance/package.json new file mode 100644 index 0000000..ced9aea --- /dev/null +++ b/conformance/package.json @@ -0,0 +1,21 @@ +{ + "name": "escalated-staff-api-conformance", + "private": true, + "description": "Black-box conformance suite for the Escalated staff API contract v1", + "type": "module", + "engines": { + "node": ">=22" + }, + "scripts": { + "test": "vitest run", + "typecheck": "tsc --noEmit" + }, + "devDependencies": { + "@types/node": "^22.20.7", + "ajv": "^8.20.0", + "ajv-formats": "^3.0.1", + "typescript": "^7.0.2", + "vitest": "^5.1.2", + "yaml": "^2.9.1" + } +} diff --git a/conformance/src/client.ts b/conformance/src/client.ts new file mode 100644 index 0000000..7646860 --- /dev/null +++ b/conformance/src/client.ts @@ -0,0 +1,78 @@ +import { baseUrl as readBaseUrl, env } from './env'; + +export interface ApiOptions { + /** Bearer token. Pass `null` to send no Authorization header. Defaults to the agent token. */ + token?: string | null; + query?: Record; + body?: unknown; + /** Retry once after `Retry-After` on a 429. Defaults to true. Pass false to see the 429 itself. */ + retry?: boolean; +} + +export interface ApiResponse { + status: number; + headers: Headers; + /** Parsed JSON body, or null when the body is empty or not JSON. */ + json: any; + /** The raw body text. */ + text: string; +} + +const MAX_RETRY_WAIT_MS = 65_000; + +export class ConnectionError extends Error { + constructor(url: string, cause: unknown) { + const inner = cause instanceof Error ? ((cause.cause as Error | undefined)?.message ?? cause.message) : String(cause); + super(`Could not connect to ${url}: ${inner}`); + this.name = 'ConnectionError'; + } +} + +export function buildUrl(baseUrl: string, path: string, query?: ApiOptions['query']): string { + const url = new URL(baseUrl + (path.startsWith('/') ? path : `/${path}`)); + for (const [k, v] of Object.entries(query ?? {})) { + if (v !== undefined) url.searchParams.set(k, String(v)); + } + return url.toString(); +} + +async function once(method: string, url: string, token: string | null, body: unknown): Promise { + const headers: Record = { Accept: 'application/json' }; + if (token) headers.Authorization = `Bearer ${token}`; + if (body !== undefined) headers['Content-Type'] = 'application/json'; + let res: Response; + try { + res = await fetch(url, { + method, + headers, + body: body === undefined ? undefined : JSON.stringify(body), + redirect: 'manual', + }); + } catch (e) { + throw new ConnectionError(url, e); + } + const text = await res.text(); + let json: any = null; + if (text) { + try { + json = JSON.parse(text); + } catch { + json = null; + } + } + return { status: res.status, headers: res.headers, json, text }; +} + +/** Call the API under test. Retries once after `Retry-After` on 429, unless `retry` is false. */ +export async function api(method: string, path: string, opts: ApiOptions = {}): Promise { + // The token is only required when the call actually uses the default one. + const token = opts.token === undefined ? env().agentToken : opts.token; + const url = buildUrl(readBaseUrl(), path, opts.query); + const m = method.toUpperCase(); + const res = await once(m, url, token, opts.body); + if (res.status !== 429 || opts.retry === false) return res; + const seconds = Number(res.headers.get('retry-after') ?? res.json?.retry_after ?? 1); + const waitMs = Math.min(Math.max(Number.isFinite(seconds) ? seconds : 1, 0) * 1000, MAX_RETRY_WAIT_MS); + await new Promise((r) => setTimeout(r, waitMs)); + return once(m, url, token, opts.body); +} diff --git a/conformance/src/contract.ts b/conformance/src/contract.ts new file mode 100644 index 0000000..782e8c2 --- /dev/null +++ b/conformance/src/contract.ts @@ -0,0 +1,20 @@ +import { describe, inject } from 'vitest'; +import './global-setup'; + +/** + * Use instead of `describe` in every test file except 00-meta. The block is + * skipped when the backend does not serve contract v1, so a missing API shows + * up as one failure in 00-meta rather than a wall of failures. + */ +export function describeContract(name: string, fn: () => void): void { + describe.skipIf(inject('contractState').kind !== 'ok')(name, fn); +} + +/** + * True when GET /meta lists the feature. Read at collection time, so it works + * in `it.skipIf(!hasFeature('x'))`. No request is made: /meta is fetched once per run. + */ +export function hasFeature(name: string): boolean { + const state = inject('contractState'); + return state.kind === 'ok' && state.features.includes(name); +} diff --git a/conformance/src/env.ts b/conformance/src/env.ts new file mode 100644 index 0000000..e6a38f6 --- /dev/null +++ b/conformance/src/env.ts @@ -0,0 +1,68 @@ +export interface ConformanceEnv { + /** Full API base, e.g. http://localhost:8000/support/api/v1 (no trailing slash). */ + baseUrl: string; + agentToken: string; + adminToken?: string; +} + +/** The API base URL alone, for calls that need no token (GET /meta). */ +export function baseUrl(): string { + const url = process.env.ESCALATED_CONFORMANCE_URL?.trim(); + if (!url) { + throw new Error( + 'ESCALATED_CONFORMANCE_URL is not set. Set it to the API base, e.g. http://localhost:8000/support/api/v1', + ); + } + return url.replace(/\/+$/, ''); +} + +export function env(): ConformanceEnv { + const base = baseUrl(); + const agentToken = process.env.ESCALATED_CONFORMANCE_TOKEN?.trim(); + const adminToken = process.env.ESCALATED_CONFORMANCE_ADMIN_TOKEN?.trim(); + if (!agentToken) { + throw new Error('ESCALATED_CONFORMANCE_TOKEN is not set. Set it to an agent token for the install under test.'); + } + return { baseUrl: base, agentToken, adminToken: adminToken || undefined }; +} + +export interface ConnectFixture { + /** A fresh code from the connect page, issued for `verifier` and `redirectUri`. */ + code: string; + /** A second fresh code for the same verifier and redirect_uri, spent by the failure cases. */ + code2: string; + verifier: string; + redirectUri: string; +} + +const CONNECT_VARS = [ + 'ESCALATED_CONFORMANCE_CONNECT_CODE', + 'ESCALATED_CONFORMANCE_CONNECT_CODE_2', + 'ESCALATED_CONFORMANCE_CONNECT_VERIFIER', + 'ESCALATED_CONFORMANCE_CONNECT_REDIRECT_URI', +] as const; + +/** The optional connect fixture, or the names of the variables that are not set. */ +export function connectFixture(): { fixture: ConnectFixture } | { missing: string[] } { + const values = CONNECT_VARS.map((name) => process.env[name]?.trim() ?? ''); + const missing = CONNECT_VARS.filter((_, i) => !values[i]); + if (missing.length) return { missing }; + const [code, code2, verifier, redirectUri] = values; + return { fixture: { code, code2, verifier, redirectUri } }; +} + +/** + * The optional forbidden-transition fixture, ESCALATED_CONFORMANCE_FORBIDDEN_TRANSITION=from:to, + * naming a status change this backend refuses. Undefined when unset; throws on a malformed value. + */ +export function forbiddenTransition(statuses: readonly string[]): { from: string; to: string } | undefined { + const raw = process.env.ESCALATED_CONFORMANCE_FORBIDDEN_TRANSITION?.trim(); + if (!raw) return undefined; + const [from, to, ...rest] = raw.split(':').map((p) => p.trim()); + if (rest.length || !from || !to || from === to || !statuses.includes(from) || !statuses.includes(to)) { + throw new Error( + `ESCALATED_CONFORMANCE_FORBIDDEN_TRANSITION must be "from:to" with two different statuses from ${statuses.join(', ')}; got "${raw}"`, + ); + } + return { from, to }; +} diff --git a/conformance/src/global-setup.ts b/conformance/src/global-setup.ts new file mode 100644 index 0000000..c1d9c6d --- /dev/null +++ b/conformance/src/global-setup.ts @@ -0,0 +1,70 @@ +import type { TestProject } from 'vitest/node'; +import { api } from './client'; +import type { ApiResponse } from './client'; + +export type ContractState = + | { kind: 'ok'; features: string[] } + | { kind: 'missing'; message: string } + | { kind: 'unreachable'; message: string } + | { kind: 'misconfigured'; message: string }; + +declare module 'vitest' { + export interface ProvidedContext { + contractState: ContractState; + } +} + +export const MISSING_MESSAGE = 'Backend does not serve staff API contract v1 (GET /meta is 404)'; + +/** + * Classifies a GET /meta response. Only a 200 whose body is a JSON object with a + * string api_version counts as the contract being served; anything else is + * `missing`, with a message that says what came back instead. + */ +export function classifyMeta(res: Pick): ContractState { + if (res.status === 404) return { kind: 'missing', message: MISSING_MESSAGE }; + if (res.status !== 200) { + const location = res.headers.get('location'); + const where = location ? ` (Location: ${location})` : ''; + return { + kind: 'missing', + message: `GET /meta answered ${res.status}${where}; contract v1 says /meta is public and answers 200`, + }; + } + const body: unknown = res.json; + if (body === null && res.text.trim() !== 'null') { + const type = res.headers.get('content-type') ?? 'no content type'; + const sample = res.text.trim().slice(0, 80).replace(/\s+/g, ' '); + return { + kind: 'missing', + message: `GET /meta returned non-JSON (${type})${sample ? `: ${sample}` : ', empty body'}`, + }; + } + if (typeof body !== 'object' || body === null || Array.isArray(body)) { + return { kind: 'missing', message: `GET /meta returned JSON that is not an object: ${res.text.trim().slice(0, 80)}` }; + } + const meta = body as Record; + if (typeof meta.api_version !== 'string') { + return { kind: 'missing', message: 'GET /meta returned a JSON object without a string api_version' }; + } + const features = Array.isArray(meta.features) ? meta.features.filter((f): f is string => typeof f === 'string') : []; + return { kind: 'ok', features }; +} + +async function probe(): Promise { + // GET /meta is public, so only the URL is needed here. A missing token is + // reported by the first test in 00-meta. + if (!process.env.ESCALATED_CONFORMANCE_URL?.trim()) { + return { kind: 'misconfigured', message: 'ESCALATED_CONFORMANCE_URL is not set. Set it to the API base, e.g. http://localhost:8000/support/api/v1' }; + } + try { + return classifyMeta(await api('GET', '/meta', { token: null })); + } catch (e) { + return { kind: 'unreachable', message: (e as Error).message }; + } +} + +/** Probes GET /meta once per run and shares the result with every test file. */ +export default async function setup(project: TestProject) { + project.provide('contractState', await probe()); +} diff --git a/conformance/src/index.ts b/conformance/src/index.ts new file mode 100644 index 0000000..9a0a2ad --- /dev/null +++ b/conformance/src/index.ts @@ -0,0 +1,7 @@ +export { api } from './client'; +export type { ApiOptions, ApiResponse } from './client'; +export { connectFixture, env, forbiddenTransition } from './env'; +export type { ConformanceEnv, ConnectFixture } from './env'; +export { describeContract, hasFeature } from './contract'; +export { expectSchema } from './schema'; +export { isRefusedTransition, ROUND_TRIP_CANDIDATES, STATUSES } from './transitions'; diff --git a/conformance/src/schema.ts b/conformance/src/schema.ts new file mode 100644 index 0000000..0a439fc --- /dev/null +++ b/conformance/src/schema.ts @@ -0,0 +1,33 @@ +import Ajv2020 from 'ajv/dist/2020'; +import addFormats from 'ajv-formats'; +import { readFileSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { parse } from 'yaml'; + +const SPEC_PATH = fileURLToPath(new URL('../../contracts/staff-api-v1.openapi.yaml', import.meta.url)); +const ROOT_ID = 'urn:escalated:staff-api-v1'; + +let ajv: Ajv2020 | undefined; + +function load(): Ajv2020 { + if (ajv) return ajv; + const spec = parse(readFileSync(SPEC_PATH, 'utf8')); + const instance = new Ajv2020({ allErrors: true, strict: false, allowUnionTypes: true }); + addFormats(instance); + // Register the components under one root so '#/components/schemas/X' refs resolve. + instance.addSchema({ $id: ROOT_ID, components: { schemas: spec.components.schemas } }); + ajv = instance; + return instance; +} + +/** Fails the test, with every Ajv error in the message, unless `value` matches the named OpenAPI component. */ +export function expectSchema(name: string, value: unknown): void { + const validate = load().getSchema(`${ROOT_ID}#/components/schemas/${name}`); + if (!validate) throw new Error(`No schema named ${name} in staff-api-v1.openapi.yaml`); + if (validate(value)) return; + const lines = (validate.errors ?? []).map((e) => { + const extra = e.params && Object.keys(e.params).length ? ` ${JSON.stringify(e.params)}` : ''; + return ` ${e.instancePath || '/'} ${e.message}${extra}`; + }); + throw new Error(`Response does not match schema ${name}:\n${lines.join('\n')}\nValue: ${JSON.stringify(value).slice(0, 600)}`); +} diff --git a/conformance/src/sequencer.ts b/conformance/src/sequencer.ts new file mode 100644 index 0000000..d50c094 --- /dev/null +++ b/conformance/src/sequencer.ts @@ -0,0 +1,12 @@ +import { BaseSequencer } from 'vitest/node'; +import type { TestSpecification } from 'vitest/node'; + +/** + * Runs test files in path order. The files share one live install and the + * action tests mutate a ticket, so the order must not depend on cache or size. + */ +export default class AlphabeticalSequencer extends BaseSequencer { + async sort(files: TestSpecification[]): Promise { + return [...files].sort((a, b) => a.moduleId.localeCompare(b.moduleId, 'en')); + } +} diff --git a/conformance/src/transitions.ts b/conformance/src/transitions.ts new file mode 100644 index 0000000..7a33fb4 --- /dev/null +++ b/conformance/src/transitions.ts @@ -0,0 +1,27 @@ +/** + * Backends MAY restrict status changes, and their tables differ, so the suite + * never assumes one. It tries candidates and treats a 422 with errors.status as + * "not allowed from here". See contracts/staff-api-v1.md, Status transitions. + */ +export const STATUSES = [ + 'open', + 'in_progress', + 'waiting_on_customer', + 'waiting_on_agent', + 'escalated', + 'resolved', + 'closed', + 'reopened', + 'live', +] as const; + +/** + * Statuses tried for a round trip, in order. Statuses with side effects beyond + * the status itself (resolved_at, closed_at, escalation events) are left out. + */ +export const ROUND_TRIP_CANDIDATES = ['waiting_on_customer', 'in_progress', 'waiting_on_agent', 'open'] as const; + +/** True when a response is the contract's refusal of a status change: 422 with errors.status. */ +export function isRefusedTransition(res: { status: number; json: any }): boolean { + return res.status === 422 && res.json?.errors != null && typeof res.json.errors === 'object' && 'status' in res.json.errors; +} diff --git a/conformance/tests/00-meta.test.ts b/conformance/tests/00-meta.test.ts new file mode 100644 index 0000000..24c1de8 --- /dev/null +++ b/conformance/tests/00-meta.test.ts @@ -0,0 +1,59 @@ +import { describe, expect, inject, it } from 'vitest'; +import { api, env, expectSchema } from '../src'; + +const state = inject('contractState'); + +describe('GET /meta', () => { + it('is reachable and served by contract v1', () => { + if (state.kind !== 'ok') throw new Error(state.message); + env(); // fails with a clear message when the token variable is missing + }); + + // Everything below needs a live /meta; the first test already reported why it is not. + // Each test checks the body against the Meta schema first, so a bad body fails + // with the schema errors and never with a TypeError. + describe.skipIf(state.kind !== 'ok')('response', () => { + it('is public, matches Meta, and omits backend_version without a token', async () => { + const res = await api('GET', '/meta', { token: null }); + expect(res.status).toBe(200); + expectSchema('Meta', res.json); + expect(res.json).not.toHaveProperty('backend_version'); + }); + + it('matches Meta and includes backend_version with a token', async () => { + const res = await api('GET', '/meta', { token: env().agentToken }); + expect(res.status).toBe(200); + expectSchema('Meta', res.json); + expect(res.json).toHaveProperty('backend_version'); + }); + + it('ignores an invalid token: 200 in the public shape, with Vary and Cache-Control', async () => { + const res = await api('GET', '/meta', { token: 'not-a-real-token-0000000000' }); + expect(res.status).toBe(200); + expectSchema('Meta', res.json); + expect(res.json).not.toHaveProperty('backend_version'); + expect(res.headers.get('vary') ?? '', 'Vary header').toMatch(/(^|[\s,])authorization([\s,]|$)|^\*$/i); + expect(res.headers.get('cache-control') ?? '', 'Cache-Control header').toMatch(/no-store/i); + }); + + it('describes the backend', async () => { + const res = await api('GET', '/meta', { token: null }); + expectSchema('Meta', res.json); + const meta = res.json; + expect(meta.api_version).toMatch(/^1\./); + expect(meta.backend.length).toBeGreaterThan(0); + expect(meta.web_url_template).toContain('{reference}'); + }); + + it('advertises connect_url exactly when auth.exchange is listed', async () => { + const res = await api('GET', '/meta', { token: null }); + expectSchema('Meta', res.json); + const meta = res.json; + if (meta.features.includes('auth.exchange')) { + expect(typeof meta.connect_url).toBe('string'); + } else { + expect(meta.connect_url).toBeNull(); + } + }); + }); +}); diff --git a/conformance/tests/10-auth.test.ts b/conformance/tests/10-auth.test.ts new file mode 100644 index 0000000..4c5e311 --- /dev/null +++ b/conformance/tests/10-auth.test.ts @@ -0,0 +1,45 @@ +import { expect, it } from 'vitest'; +import { api, describeContract, expectSchema, hasFeature } from '../src'; + +const revocable = process.env.ESCALATED_CONFORMANCE_REVOCABLE_TOKEN?.trim(); + +describeContract('auth', () => { + it('POST /auth/validate returns the caller', async () => { + const res = await api('POST', '/auth/validate'); + expect(res.status).toBe(200); + expectSchema('AuthValidateResponse', res.json); + expect(res.json.is_agent).toBe(true); + }); + + it('rejects a request with no token: 401 with a message', async () => { + const res = await api('POST', '/auth/validate', { token: null }); + expect(res.status).toBe(401); + expectSchema('Error', res.json); + }); + + it('rejects a garbage token: 401 with a message', async () => { + const res = await api('POST', '/auth/validate', { token: 'not-a-real-token-0000000000' }); + expect(res.status).toBe(401); + expectSchema('Error', res.json); + }); + + it.skipIf(!hasFeature('auth.exchange'))('POST /auth/exchange with a random code is 400 with a message', async () => { + const res = await api('POST', '/auth/exchange', { + token: null, + body: { + code: `conformance-${Math.random().toString(36).slice(2)}`, + code_verifier: 'v'.repeat(64), + redirect_uri: `https://${'a'.repeat(32)}.chromiumapp.org/`, + }, + }); + expect(res.status).toBe(400); + expectSchema('Error', res.json); + }); + + it.skipIf(!revocable)('POST /auth/revoke is 204 and the token is 401 afterwards', async () => { + const revoke = await api('POST', '/auth/revoke', { token: revocable }); + expect(revoke.status).toBe(204); + const after = await api('POST', '/auth/validate', { token: revocable }); + expect(after.status).toBe(401); + }); +}); diff --git a/conformance/tests/20-tickets-list.test.ts b/conformance/tests/20-tickets-list.test.ts new file mode 100644 index 0000000..0534c71 --- /dev/null +++ b/conformance/tests/20-tickets-list.test.ts @@ -0,0 +1,89 @@ +import { beforeAll, describe, expect, it } from 'vitest'; +import { api, describeContract, expectSchema, hasFeature } from '../src'; + +describeContract('GET /tickets', () => { + let base: Awaited>; + + beforeAll(async () => { + base = await api('GET', '/tickets'); + }); + + it('is 200 with {data: TicketListItem[], meta: PaginationMeta}', () => { + expect(base.status).toBe(200); + expect(Array.isArray(base.json.data)).toBe(true); + expect(base.json.data.length).toBeGreaterThanOrEqual(3); + for (const item of base.json.data) expectSchema('TicketListItem', item); + expectSchema('PaginationMeta', base.json.meta); + }); + + it('per_page=1&page=2 returns a different reference than page 1', async () => { + const one = await api('GET', '/tickets', { query: { per_page: 1, page: 1 } }); + const two = await api('GET', '/tickets', { query: { per_page: 1, page: 2 } }); + expect(one.status).toBe(200); + expect(two.status).toBe(200); + expect(one.json.data).toHaveLength(1); + expect(two.json.data).toHaveLength(1); + expect(two.json.data[0].reference).not.toBe(one.json.data[0].reference); + expect(two.json.meta.current_page).toBe(2); + expect(two.json.meta.per_page).toBe(1); + }); + + // The contract says "A per_page above 100 is a 422". The task brief said + // "caps at 100"; the contract is the source of truth. + it('per_page=500 is rejected with 422 and field errors', async () => { + const res = await api('GET', '/tickets', { query: { per_page: 500 } }); + expect(res.status).toBe(422); + expectSchema('ValidationError', res.json); + }); + + it('status=open returns only open tickets', async () => { + const res = await api('GET', '/tickets', { query: { status: 'open' } }); + expect(res.status).toBe(200); + expect(res.json.data.length).toBeGreaterThan(0); + for (const t of res.json.data) expect(t.status).toBe('open'); + }); + + it('unassigned=1 returns only tickets with a null assignee', async () => { + const res = await api('GET', '/tickets', { query: { unassigned: 1 } }); + expect(res.status).toBe(200); + expect(res.json.data.length).toBeGreaterThan(0); + for (const t of res.json.data) expect(t.assignee).toBeNull(); + }); + + it.skipIf(!hasFeature('tickets.open_filter'))('open=1 returns only tickets that are neither resolved nor closed', async () => { + const res = await api('GET', '/tickets', { query: { open: 1 } }); + expect(res.status).toBe(200); + expect(res.json.data.length).toBeGreaterThan(0); + for (const t of res.json.data) expect(['resolved', 'closed']).not.toContain(t.status); + }); + + describe.skipIf(!hasFeature('tickets.updated_since'))('updated_since', () => { + it('a far-future value returns no tickets', async () => { + const res = await api('GET', '/tickets', { query: { updated_since: '2999-01-01T00:00:00Z' } }); + expect(res.status).toBe(200); + expect(res.json.data).toEqual([]); + }); + + it('a far-past value returns the seeded tickets', async () => { + const res = await api('GET', '/tickets', { query: { updated_since: '2000-01-01T00:00:00Z' } }); + expect(res.status).toBe(200); + expect(res.json.data.length).toBeGreaterThanOrEqual(3); + }); + + it('accepts a +02:00 offset', async () => { + const res = await api('GET', '/tickets', { query: { updated_since: '2000-01-01T00:00:00+02:00' } }); + expect(res.status).toBe(200); + }); + + it('rejects a malformed value with 422', async () => { + const res = await api('GET', '/tickets', { query: { updated_since: 'not-a-date' } }); + expect(res.status).toBe(422); + expectSchema('ValidationError', res.json); + }); + }); + + it.skipIf(!hasFeature('tickets.last_customer_reply_at'))('every item has a last_customer_reply_at key', () => { + expect(base.json.data.length).toBeGreaterThan(0); + for (const t of base.json.data) expect(t).toHaveProperty('last_customer_reply_at'); + }); +}); diff --git a/conformance/tests/30-ticket-show.test.ts b/conformance/tests/30-ticket-show.test.ts new file mode 100644 index 0000000..708c994 --- /dev/null +++ b/conformance/tests/30-ticket-show.test.ts @@ -0,0 +1,25 @@ +import { beforeAll, expect, it } from 'vitest'; +import { api, describeContract, expectSchema } from '../src'; + +describeContract('GET /tickets/{reference}', () => { + let reference: string; + + beforeAll(async () => { + const list = await api('GET', '/tickets', { query: { per_page: 1 } }); + reference = list.json?.data?.[0]?.reference; + if (!reference) throw new Error('Seed needs at least one ticket, but GET /tickets returned none'); + }); + + it('returns a Ticket by reference', async () => { + const res = await api('GET', `/tickets/${reference}`); + expect(res.status).toBe(200); + expectSchema('Ticket', res.json.data); + expect(res.json.data.reference).toBe(reference); + }); + + it('an unknown reference is 404 with a message', async () => { + const res = await api('GET', '/tickets/ESC-NOPE-999999'); + expect(res.status).toBe(404); + expectSchema('Error', res.json); + }); +}); diff --git a/conformance/tests/40-ticket-actions.test.ts b/conformance/tests/40-ticket-actions.test.ts new file mode 100644 index 0000000..b1f66da --- /dev/null +++ b/conformance/tests/40-ticket-actions.test.ts @@ -0,0 +1,206 @@ +import { afterAll, beforeAll, expect, it } from 'vitest'; +import { + api, + describeContract, + expectSchema, + forbiddenTransition, + hasFeature, + isRefusedTransition, + ROUND_TRIP_CANDIDATES, + STATUSES, +} from '../src'; + +/** + * Mutates one seeded ticket and puts status, priority and assignee back, even + * when an assertion fails. Replies and notes cannot be deleted through the API, + * so they stay on the ticket. Backends may restrict status changes in different + * ways, so status targets are tried in turn and a 422 with errors.status means + * "not allowed from here". About 22 requests per run on a backend that allows + * the first candidate. + */ +describeContract('ticket actions', () => { + let reference: string; + let snap: any; // Ticket as it was before any change + let agents: any[] = []; + let macros: any[] = []; + const tag = `conformance-${Date.now().toString(36)}`; + let replyId: unknown; + let noteId: unknown; + + const originalAssignee = () => snap?.assignee?.id ?? null; + + async function current(): Promise { + return (await api('GET', `/tickets/${reference}`)).json?.data; + } + + const setStatus = (ref: string, status: string) => api('PATCH', `/tickets/${ref}/status`, { body: { status } }); + + /** Puts a ticket's status back to `want`, directly or through one candidate status. True on success. */ + async function putStatusBack(ref: string, have: string, want: string): Promise { + if (have === want) return true; + if ((await setStatus(ref, want)).status === 200) return true; + for (const hop of ROUND_TRIP_CANDIDATES) { + if (hop === have || hop === want) continue; + if ((await setStatus(ref, hop)).status !== 200) continue; + have = hop; + if ((await setStatus(ref, want)).status === 200) return true; + } + return false; + } + + async function restore(): Promise { + const now = await current(); + if (!now) return; + if (now.status !== snap.status) await putStatusBack(reference, now.status, snap.status); + if (now.priority !== snap.priority) await api('PATCH', `/tickets/${reference}/priority`, { body: { priority: snap.priority } }); + if (originalAssignee() !== null && String(now.assignee?.id) !== String(originalAssignee())) { + await api('POST', `/tickets/${reference}/assign`, { body: { agent_id: originalAssignee() } }); + } + } + + beforeAll(async () => { + // Prefer an open ticket that already has an assignee: the API has no way + // to unassign, so only an assigned ticket can be put back as it was. + const list = await api('GET', '/tickets', { query: { status: 'open', per_page: 50 } }); + const open: any[] = list.json?.data ?? []; + const pick = open.find((t) => t.assignee) ?? open[0]; + if (!pick) throw new Error('Seed needs at least one open ticket'); + reference = pick.reference; + snap = await current(); + if (!snap) throw new Error(`GET /tickets/${reference} returned no ticket`); + agents = (await api('GET', '/agents')).json?.data ?? []; + if (hasFeature('macros')) macros = (await api('GET', '/macros')).json?.data ?? []; + }); + + afterAll(async () => { + if (reference && snap) await restore(); + }); + + it('reply: 201 with ReplyCreated', async () => { + const res = await api('POST', `/tickets/${reference}/reply`, { body: { body: `Reply ${tag}` } }); + expect(res.status).toBe(201); + expectSchema('ReplyCreated', res.json.data); + expect(res.json.data.is_internal_note).toBe(false); + replyId = res.json.data.id; + }); + + it('internal note: 201 and is_internal_note is true', async () => { + const res = await api('POST', `/tickets/${reference}/reply`, { + body: { body: `Note ${tag}`, is_internal_note: true }, + }); + expect(res.status).toBe(201); + expectSchema('ReplyCreated', res.json.data); + expect(res.json.data.is_internal_note).toBe(true); + noteId = res.json.data.id; + }); + + it('the reply and the note show in the ticket thread', async () => { + const res = await api('GET', `/tickets/${reference}`); + expect(res.status).toBe(200); + const replies: any[] = res.json.data.replies; + const reply = replies.find((r) => String(r.id) === String(replyId)); + const note = replies.find((r) => String(r.id) === String(noteId)); + expect(reply, 'reply missing from thread').toBeDefined(); + expect(note, 'note missing from thread').toBeDefined(); + expect(reply.is_internal_note).toBe(false); + expect(note.is_internal_note).toBe(true); + }); + + it('status changes, then back', async (ctx) => { + const from: string = (await current())?.status ?? snap.status; + const refused: string[] = []; + for (const target of ROUND_TRIP_CANDIDATES) { + if (target === from) continue; + const res = await setStatus(reference, target); + if (isRefusedTransition(res)) { + refused.push(target); // not allowed from here; try the next one + continue; + } + try { + expect(res.status).toBe(200); + expect(res.json).toMatchObject({ message: 'Status updated.', status: target }); + } finally { + if (res.status === 200) { + expect.soft(await putStatusBack(reference, target, from), `putting the status back to "${from}"`).toBe(true); + } + } + return; + } + ctx.skip(`the backend refused every candidate status from "${from}" with 422: ${refused.join(', ')}`); + }); + + it('setting the current status is 200 and a no-op', async () => { + const res = await setStatus(reference, snap.status); + expect(res.status).toBe(200); + expect(res.json).toMatchObject({ message: 'Status updated.', status: snap.status }); + }); + + it('a transition the backend refuses is 422 with errors.status', async (ctx) => { + const forbidden = forbiddenTransition(STATUSES); + if (!forbidden) return ctx.skip('ESCALATED_CONFORMANCE_FORBIDDEN_TRANSITION is not set (for example open:live)'); + let ref = reference; + if (snap.status !== forbidden.from) { + const t = (await api('GET', '/tickets', { query: { status: forbidden.from, per_page: 1 } })).json?.data?.[0]; + if (!t) return ctx.skip(`no ticket in status "${forbidden.from}" to try ${forbidden.from} -> ${forbidden.to} on`); + ref = t.reference; + } + const res = await setStatus(ref, forbidden.to); + try { + expect(res.status, `PATCH status ${forbidden.from} -> ${forbidden.to}`).toBe(422); + expectSchema('ValidationError', res.json); + expect(res.json.errors).toHaveProperty('status'); + } finally { + if (res.status === 200) await putStatusBack(ref, forbidden.to, forbidden.from); + } + }); + + it('priority changes, then back', async () => { + const target = snap.priority === 'high' ? 'low' : 'high'; + try { + const res = await api('PATCH', `/tickets/${reference}/priority`, { body: { priority: target } }); + expect(res.status).toBe(200); + expect(res.json).toMatchObject({ message: 'Priority updated.', priority: target }); + } finally { + const back = await api('PATCH', `/tickets/${reference}/priority`, { body: { priority: snap.priority } }); + expect.soft(back.status, 'putting the priority back').toBe(200); + expect.soft(back.json?.priority, 'putting the priority back').toBe(snap.priority); + } + }); + + it('assign to the other agent, then back', async (ctx) => { + if (originalAssignee() === null) ctx.skip('no assigned open ticket in the seed, and the API cannot unassign'); + const other = agents.find((a) => String(a.id) !== String(originalAssignee())); + if (!other) ctx.skip('the seed has only one agent'); + try { + const res = await api('POST', `/tickets/${reference}/assign`, { body: { agent_id: other.id } }); + expect(res.status).toBe(200); + expect(res.json).toMatchObject({ message: 'Ticket assigned.' }); + } finally { + const back = await api('POST', `/tickets/${reference}/assign`, { body: { agent_id: originalAssignee() } }); + expect.soft(back.status, 'putting the assignee back').toBe(200); + } + }); + + it('assign to a non-agent is 422', async () => { + const res = await api('POST', `/tickets/${reference}/assign`, { body: { agent_id: 2147483000 } }); + expect(res.status).toBe(422); + expectSchema('ValidationError', res.json); + }); + + it('applies a macro', async (ctx) => { + if (!hasFeature('tickets.macro')) ctx.skip('backend does not list tickets.macro'); + // Only a macro this suite can undo whatever the backend's transition rules: + // priority actions it puts back, and notes, which leave no trace beyond the note. + const safe = macros.find( + (m) => m.actions.length > 0 && m.actions.every((a: any) => ['priority', 'note'].includes(a.type)), + ); + if (!safe) ctx.skip('no macro in the seed with only priority or note actions'); + try { + const res = await api('POST', `/tickets/${reference}/macro`, { body: { macro_id: safe.id } }); + expect(res.status).toBe(200); + expect(res.json.message).toContain(safe.name); + } finally { + await restore(); + } + }); +}); diff --git a/conformance/tests/50-resources.test.ts b/conformance/tests/50-resources.test.ts new file mode 100644 index 0000000..8abd3cd --- /dev/null +++ b/conformance/tests/50-resources.test.ts @@ -0,0 +1,22 @@ +import { expect, it } from 'vitest'; +import { api, describeContract, expectSchema, hasFeature } from '../src'; + +async function expectList(path: string, schema: string): Promise { + const res = await api('GET', path); + expect(res.status).toBe(200); + expect(Array.isArray(res.json.data)).toBe(true); + expect(res.json).not.toHaveProperty('meta'); + for (const item of res.json.data) expectSchema(schema, item); +} + +describeContract('resources', () => { + it('GET /agents returns {data: Agent[]}', () => expectList('/agents', 'Agent')); + + it('GET /departments returns {data: Department[]}', () => expectList('/departments', 'Department')); + + it.skipIf(!hasFeature('canned_responses'))('GET /canned-responses returns {data: CannedResponse[]}', () => + expectList('/canned-responses', 'CannedResponse'), + ); + + it.skipIf(!hasFeature('macros'))('GET /macros returns {data: Macro[]}', () => expectList('/macros', 'Macro')); +}); diff --git a/conformance/tests/60-errors.test.ts b/conformance/tests/60-errors.test.ts new file mode 100644 index 0000000..ba9cef0 --- /dev/null +++ b/conformance/tests/60-errors.test.ts @@ -0,0 +1,35 @@ +import { beforeAll, expect, it } from 'vitest'; +import { api, describeContract, expectSchema } from '../src'; + +describeContract('errors and limits', () => { + let reference: string; + + beforeAll(async () => { + const list = await api('GET', '/tickets', { query: { per_page: 1 } }); + reference = list.json?.data?.[0]?.reference; + if (!reference) throw new Error('Seed needs at least one ticket, but GET /tickets returned none'); + }); + + // Expects the agent token to lack the admin ability. A conforming backend + // refuses before deleting; a broken one deletes the ticket, so run this + // suite against a throwaway seed only. + it('an agent token on DELETE /tickets/{reference} is 403, not 401', async () => { + const res = await api('DELETE', `/tickets/${reference}`); + expect(res.status).toBe(403); + expectSchema('Error', res.json); + }); + + it('a validation failure is 422 with an errors map', async () => { + const res = await api('PATCH', `/tickets/${reference}/status`, { body: {} }); + expect(res.status).toBe(422); + expectSchema('ValidationError', res.json); + expect(Object.keys(res.json.errors).length).toBeGreaterThan(0); + }); + + it('a 200 carries X-RateLimit-Limit and X-RateLimit-Remaining', async () => { + const res = await api('POST', '/auth/validate'); + expect(res.status).toBe(200); + expect(res.headers.get('x-ratelimit-limit')).toMatch(/^\d+$/); + expect(res.headers.get('x-ratelimit-remaining')).toMatch(/^\d+$/); + }); +}); diff --git a/conformance/tests/70-connect.test.ts b/conformance/tests/70-connect.test.ts new file mode 100644 index 0000000..3014296 --- /dev/null +++ b/conformance/tests/70-connect.test.ts @@ -0,0 +1,94 @@ +import { afterAll, expect, it } from 'vitest'; +import { api, connectFixture, describeContract, expectSchema, hasFeature } from '../src'; + +/** + * POST /auth/exchange with codes the backend's CI seeded through the connect + * flow (see README, "Connect fixture"). The exchange endpoint is limited per IP, + * not per token, so these requests are counted separately: 4 with the fixture, + * then up to 11 in the rate limit test, which runs last because it burns the + * per-IP bucket. This file runs last for the same reason. + */ +describeContract('connect: POST /auth/exchange', () => { + const found = connectFixture(); + const fixture = 'fixture' in found ? found.fixture : undefined; + const skipReason = !hasFeature('auth.exchange') + ? 'backend does not list auth.exchange' + : fixture + ? undefined + : `connect fixture not set (${'missing' in found ? found.missing.join(', ') : ''})`; + + let minted: string | undefined; + let codeSpent = false; + + const exchange = (code: string, verifier: string, redirectUri: string) => + api('POST', '/auth/exchange', { + token: null, + retry: false, + body: { code, code_verifier: verifier, redirect_uri: redirectUri }, + }); + + afterAll(async () => { + // Leave no live token behind. A backend that revoked it on replay answers 401 here. + if (minted && hasFeature('auth.revoke')) await api('POST', '/auth/revoke', { token: minted }); + }); + + it('a fresh code gives an agent token, with Cache-Control: no-store', async (ctx) => { + if (skipReason || !fixture) return ctx.skip(skipReason); + const res = await exchange(fixture.code, fixture.verifier, fixture.redirectUri); + codeSpent = true; + expect(res.status).toBe(200); + expectSchema('ExchangeResponse', res.json); + minted = res.json.token; + expect(res.headers.get('cache-control') ?? '', 'Cache-Control header').toMatch(/no-store/i); + + const validate = await api('POST', '/auth/validate', { token: minted }); + expect(validate.status).toBe(200); + expectSchema('AuthValidateResponse', validate.json); + expect(validate.json.abilities).toEqual(['agent']); + }); + + it('the same code a second time is 400', async (ctx) => { + if (skipReason || !fixture) return ctx.skip(skipReason); + if (!codeSpent) await exchange(fixture.code, fixture.verifier, fixture.redirectUri); + const res = await exchange(fixture.code, fixture.verifier, fixture.redirectUri); + expect(res.status).toBe(400); + expectSchema('Error', res.json); + }); + + it('a wrong verifier is 400 and consumes the code', async (ctx) => { + if (skipReason || !fixture) return ctx.skip(skipReason); + // Well formed (43 unreserved characters) but not the verifier the code was issued for. + const wrong = fixture.verifier.startsWith('A') ? 'B'.repeat(43) : 'A'.repeat(43); + const bad = await exchange(fixture.code2, wrong, fixture.redirectUri); + const after = await exchange(fixture.code2, fixture.verifier, fixture.redirectUri); + + // Revoke anything a broken backend minted before asserting, so no live token is left behind. + if (hasFeature('auth.revoke')) { + for (const res of [bad, after]) { + if (res.status === 200 && typeof res.json?.token === 'string') { + await api('POST', '/auth/revoke', { token: res.json.token }); + } + } + } + + expect.soft(bad.status, 'a wrong verifier must be refused').toBe(400); + if (bad.status === 400) expectSchema('Error', bad.json); + expect.soft(after.status, 'CODE_2 still worked after a failed exchange; any presentation must consume it').toBe(400); + }); + + // Keep this last: it uses up the per-IP exchange limit for the next minute. + it.skipIf(!hasFeature('auth.exchange'))('11 exchanges within a minute from one client produce a 429', async () => { + let limited: Awaited> | undefined; + for (let i = 0; i < 11 && !limited; i++) { + const res = await exchange( + `conformance-limit-${i}-${Math.random().toString(36).slice(2)}`, + 'v'.repeat(64), + `https://${'a'.repeat(32)}.chromiumapp.org/`, + ); + if (res.status === 429) limited = res; + else expect(res.status, `exchange ${i + 1} of 11`).toBe(400); + } + expect(limited, 'no 429 after 11 exchanges; the contract limits POST /auth/exchange to 10 per minute per IP').toBeDefined(); + expect(limited!.headers.get('retry-after') ?? '', 'Retry-After header').toMatch(/^\d+$/); + }); +}); diff --git a/conformance/tsconfig.json b/conformance/tsconfig.json new file mode 100644 index 0000000..4106de2 --- /dev/null +++ b/conformance/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ES2023", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "noEmit": true, + "allowImportingTsExtensions": true, + "skipLibCheck": true, + "esModuleInterop": true, + "isolatedModules": true, + "lib": ["ES2023"], + "types": ["node"] + }, + "include": ["src", "tests", "vitest.config.ts"] +} diff --git a/conformance/vitest.config.ts b/conformance/vitest.config.ts new file mode 100644 index 0000000..0d292cc --- /dev/null +++ b/conformance/vitest.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'vitest/config'; +import AlphabeticalSequencer from './src/sequencer.ts'; + +export default defineConfig({ + test: { + include: ['tests/**/*.test.ts'], + globalSetup: ['./src/global-setup.ts'], + testTimeout: 30_000, + // Tests run in file name order against one live install; keep them sequential. + fileParallelism: false, + sequence: { sequencer: AlphabeticalSequencer }, + }, +}); diff --git a/contracts/package.json b/contracts/package.json new file mode 100644 index 0000000..c76c4b2 --- /dev/null +++ b/contracts/package.json @@ -0,0 +1,8 @@ +{ + "name": "escalated-staff-api-contract", + "private": true, + "description": "Tooling for the staff API contract v1 OpenAPI description", + "scripts": { + "lint": "npx --yes @redocly/cli@1 lint staff-api-v1.openapi.yaml" + } +} diff --git a/contracts/staff-api-v1.md b/contracts/staff-api-v1.md new file mode 100644 index 0000000..cc93a55 --- /dev/null +++ b/contracts/staff-api-v1.md @@ -0,0 +1,541 @@ +# Staff API contract v1 + +The REST API that every Escalated backend serves to staff clients, such as the browser extension. It is derived from `escalated-laravel` 1.9.20 (`routes/api.php`) with the new endpoints and fixes listed in the [change log](#change-log). If a backend disagrees with this file, this file is right. + +Contract version: `1.0`. + +The words MUST, MUST NOT, SHOULD, SHOULD NOT and MAY are used as in [RFC 2119](https://www.rfc-editor.org/rfc/rfc2119). + +A conformance suite runs against a live backend over HTTP. This document is its source, together with the OpenAPI file that sits beside it. + +## Scope + +In scope: the staff API. That means agent and admin calls made with a Bearer token. + +Out of scope: + +- The customer mobile API (`support/api/v1/mobile`). It is a different surface with different tokens. +- Inertia pages and session routes. The one exception is the connect page in [Connecting an extension](#connecting-an-extension), which is a browser page. +- Webhooks and host callbacks. + +Backends add to this API without removing their existing routes. Old paths stay as aliases, so current clients keep working. + +## Base path and discovery + +Every path in this document is relative to the API prefix. + +| Backend | Default prefix | +|---|---| +| All except WordPress | `support/api/v1` | +| WordPress | `/wp-json/escalated/v1` | + +An install may change the prefix in config. Clients find the API with `GET {prefix}/meta`. It needs no token. A client tries the default prefix first, then each backend's known prefix, and lets the user type a custom one. + +The API is off by default on most backends. When it is off, every route in this document answers 404. + +## Authentication + +Send `Authorization: Bearer ` on every request except `GET /meta` and `POST /auth/exchange`. Tokens are opaque strings. The server stores only a hash. + +A token has a list of abilities: `agent`, `admin`, or `*`. They are not hierarchical. `*` passes every check. A call to an `admin` route needs the `admin` ability, and the token's owner must be an admin. A call to an `agent` route needs the `agent` ability, and the owner must still be an agent when the call is made. + +| Status | Body `message` | When | +|---|---|---| +| 401 | `Unauthenticated.` | No Bearer header | +| 401 | `Invalid token.` | Unknown token | +| 401 | `Token has expired.` | Past `expires_at` | +| 401 | `Token owner not found.` | The user was deleted | +| 403 | `Insufficient permissions.` | Token lacks the ability, or owner is not an admin | +| 403 | `User no longer has agent access.` | Owner lost staff access | + +Clients match on the status, not on the message text. + +Tokens come from two places. An admin can create one in the admin UI. A browser extension gets one through the connect flow below. + +### Connecting an extension + +The connect flow uses a browser redirect with PKCE (S256, [RFC 7636](https://www.rfc-editor.org/rfc/rfc7636)). The extension never sees the staff member's password. + +1. The extension generates a random `code_verifier`, derives `code_challenge` from it as described in [PKCE encoding](#pkce-encoding), and generates a random `state`. +2. The extension opens this page in the browser, where the staff member is signed in: + + `GET {web_prefix}/agent/connect-extension?redirect_uri=&state=&code_challenge=&code_challenge_method=S256&client_name=` + + `{web_prefix}` is the install's web route prefix, `support` by default. The page URL is advertised as `connect_url` in `GET /meta`. +3. The page checks the parameters as described in [Connect page requirements](#connect-page-requirements). The Chrome extension redirect is `https://.chromiumapp.org/`. +4. The page shows who is asking (the extension ID and `client_name`) and two buttons. + - Approve creates a one-time code and redirects to `redirect_uri?code=&state=`. + - Deny redirects to `redirect_uri?error=access_denied&state=`. +5. The code lives 60 seconds and works once. The server stores a hash of it, with the challenge, the `redirect_uri`, the extension ID and the staff member who approved it. +6. The extension calls `POST /auth/exchange` with the code, the verifier and the same `redirect_uri`, and gets a token. The server follows the [Exchange rules](#exchange-rules). + +The token minted by the exchange has: + +- abilities `["agent"]` +- name `Browser extension ()`, using the truncated `client_name`, or `Browser extension` when `client_name` was empty or missing +- kind `browser_extension` +- the extension ID from the code +- no expiry, unless the install sets one + +Each staff member sees and revokes their own extension tokens at `{web_prefix}/agent/browser-extensions`, which shows each token's name, extension ID and creation time. Extension tokens also appear on the admin API tokens page, with their kind shown, so an admin can revoke them. A client can also revoke its own token with `POST /auth/revoke`. + +#### Connect page requirements + +Checking `redirect_uri`: + +- The page MUST check `redirect_uri` before anything else. When it is missing or invalid, the page MUST show an error page and MUST NOT redirect anywhere, not even with an error. +- A valid Chrome `redirect_uri` matches `^https://[a-p]{32}\.chromiumapp\.org/$` as a whole string. The check MUST be a full-string match. Common anchoring mistakes let `https://<32 letters>.chromiumapp.org/\n` or a longer string through: + - In Ruby, `^` and `$` are line anchors. Use `\A` and `\z`. + - In PHP (PCRE without the `D` modifier), Python `re.match`, and Elixir, `$` also matches before a trailing newline. Use `\z` (or the `D` modifier in PHP), Python `re.fullmatch`, or `\z` in Elixir. + - In Java, use `Pattern.matcher(...).matches()`, not `find()`. +- A parse-based check is an accepted equivalent. It MUST require all of: scheme `https`; a host that matches the pattern exactly (32 letters `a` to `p`, then `.chromiumapp.org`); no port; no userinfo; path exactly `/`; no query; no fragment. The check MUST run on the raw string as well as the parsed parts, so a value that parsers normalise (trailing whitespace, a newline, upper-case letters) is refused. +- An install MAY add its own patterns, for example for another browser. Every added pattern MUST be held to the same full-string rule. + +Checking the other parameters, once `redirect_uri` is valid: + +- When `state` is missing, `code_challenge` is missing or is not exactly 43 characters from `[A-Za-z0-9_-]`, or `code_challenge_method` is missing or anything other than `S256`, the page MUST redirect to `redirect_uri?error=invalid_request&state=`. It leaves out `state` when none was sent. It MUST NOT issue a code. +- `client_name` is optional display text. The page MUST truncate it to 64 characters and MUST HTML-escape it on output. The token name uses the truncated value. + +Who can approve: + +- Only a signed-in staff member with agent access can approve. A signed-in user without agent access MUST get a 403 page, with no redirect. +- A signed-out user MUST be sent to sign in and then returned to the connect page with every query parameter intact. + +How the page behaves: + +- `GET` MUST NOT have side effects. It only shows the page. +- Approve and Deny MUST be `POST` requests that carry the session's CSRF token. A `POST` without a valid CSRF token MUST be refused without a redirect. +- The page MUST NOT auto-approve, even for an extension the staff member approved before. Every code needs a fresh click on Approve, so a non-interactive `chrome.identity.launchWebAuthFlow` call never gets a code. +- Every response from the page, including the error page, MUST carry `Content-Security-Policy: frame-ancestors 'none'` and `X-Frame-Options: DENY`. +- The page MUST show the extension ID, taken from the `redirect_uri` host (the 32 letters before `.chromiumapp.org`), and not only `client_name`. The caller chooses `client_name`, so it proves nothing. The ID is stored with the code and then with the token, so the browser extensions page can show it. + +#### PKCE encoding + +- `code_verifier` is 43 to 128 characters from `[A-Za-z0-9-._~]`. +- `code_challenge = BASE64URL(SHA-256(ASCII(code_verifier)))` with the `=` padding removed. It is always 43 characters. +- The default URL-safe Base64 encoders in Ruby (`Base64.urlsafe_encode64`), Python (`base64.urlsafe_b64encode`) and Java (`Base64.getUrlEncoder()`) add `=` padding. Strip it, or use `padding: false` in Ruby and `.withoutPadding()` in Java. A padded challenge never matches. +- Test vector from RFC 7636 Appendix B: the verifier `dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk` gives the challenge `E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM`. Each backend SHOULD have a unit test with it. + +#### Exchange rules + +- The server MUST compare the `redirect_uri` sent to `POST /auth/exchange` with the one stored for the code by exact string equality, with no normalisation. +- The server MUST compute the challenge from `code_verifier` as in [PKCE encoding](#pkce-encoding) and compare it with the stored challenge. It SHOULD use a constant-time comparison. +- Consuming a code MUST be atomic: two concurrent exchanges of one code MUST NOT both succeed. A conditional update that marks the code used only when it is still unused, followed by a check of the affected row count, is enough. A read followed by a separate write is not. +- Any presentation of a known code MUST consume it, even when the exchange then fails because the verifier or the `redirect_uri` is wrong. A wrong guess burns the code. +- Codes MUST carry at least 128 bits of entropy, for example 32 random bytes encoded as base64url, and MUST be stored hashed. +- A code expires 60 seconds after it is issued. +- The 200 response MUST carry `Cache-Control: no-store`. +- When an already used code is presented again, the server SHOULD revoke the token that code issued, since a replay means the code leaked. The server keeps the used code's record, with the id of the token it issued, at least until the code would have expired. +- A body that is missing `code`, `code_verifier` or `redirect_uri`, or where one of them is not a string, is a 422 validation error. That check runs before any code lookup, so it does not consume a code. +- Every failure that involves a code (unknown, used, expired, wrong verifier, mismatched `redirect_uri`) answers the single generic 400 described in [POST /auth/exchange](#post-authexchange). The response never says which. + +## Conventions + +### Format + +- Bodies are JSON. Send `Content-Type: application/json` and `Accept: application/json`. +- Every timestamp is ISO 8601 in UTC, for example `2026-11-26T14:03:09Z`. A `+00:00` suffix is accepted in place of `Z`. Clients must parse both. +- Enums are lower-case strings. Never integers. +- Tickets in paths are addressed by `reference` (for example `ESC-00042`), not by numeric id. +- Ids in bodies and responses may be integers or strings, because host apps use either. Clients treat them as opaque. + +### Enums + +| Field | Values | +|---|---| +| `status` | `open`, `in_progress`, `waiting_on_customer`, `waiting_on_agent`, `escalated`, `resolved`, `closed`, `reopened`, `live` | +| `priority` | `low`, `medium`, `high`, `urgent`, `critical` | +| `ticket_type` | `question`, `problem`, `incident`, `task` | + +A backend emits `ticket_type` as `question` when the stored value is null. + +### Empty objects + +Some backends serialize an empty JSON object as `[]`. Clients must accept `[]` as empty for free-form object fields such as ticket `metadata` and report `filters`. + +### Pagination + +`GET /tickets` takes `page` (default 1) and `per_page` (default 15, maximum 100). A `per_page` above 100 is a 422. It answers: + +```json +{ + "data": [], + "meta": { "current_page": 1, "last_page": 1, "per_page": 15, "total": 0 } +} +``` + +The other list endpoints (`/agents`, `/departments`, `/tags`, `/canned-responses`, `/macros`) return `{ "data": [] }` with no `meta`. + +### Errors + +Every error body has a `message`. A validation error also has `errors`, a map from field name to a list of strings. + +```json +{ "message": "The status field is required.", "errors": { "status": ["The status field is required."] } } +``` + +| Status | Meaning | +|---|---| +| 400 | Bad request. Used by `POST /auth/exchange` | +| 401 | Missing, unknown or expired token | +| 403 | Token or user lacks permission. Also a policy refusal (`This action is unauthorized.`) | +| 404 | Unknown ticket, action, report type or route | +| 422 | Validation failed | +| 429 | Rate limited | + +### Rate limits + +The default is 60 requests per minute per token. Install config may change it. Unauthenticated routes are limited per IP. Requests that fail authentication (401) SHOULD also be limited per IP, so that guessing tokens is no faster than the per-IP limit allows. + +Every response from a limited route carries: + +- `X-RateLimit-Limit` +- `X-RateLimit-Remaining` + +When the limit is hit the answer is 429 with `Retry-After` (seconds), `X-RateLimit-Remaining: 0` and this body: + +```json +{ "message": "Too many requests.", "retry_after": 30 } +``` + +### CORS + +The API sends no CORS headers. Browser extensions call it from a service worker or an extension page with host permission, never from a content script. + +## Shared shapes + +### Ticket list item + +Returned by `GET /tickets`. + +| Field | Type | Notes | +|---|---|---| +| `id` | id | | +| `reference` | string | | +| `ticket_type` | string | | +| `account` | `{type, id}` or null | Present only when accounts are enabled | +| `subject` | string | | +| `status`, `status_label` | string | | +| `priority`, `priority_label` | string | | +| `requester` | `{name, email}` | | +| `assignee` | `{id, name}` or null | | +| `department` | `{id, name}` or null | | +| `sla_breached` | boolean | | +| `last_reply_at` | timestamp or null | Last reply of any kind | +| `last_customer_reply_at` | timestamp or null | Last public activity from the customer side. New in v1 | +| `created_at`, `updated_at` | timestamp | | + +### Ticket + +Returned by `GET /tickets/{reference}` and `POST /tickets`. It has every list item field except `requester`, plus: + +| Field | Type | Notes | +|---|---|---| +| `description` | string | | +| `channel` | string | | +| `metadata` | object or null | | +| `external_reference` | string or null | | +| `requester` | `{kind, id, name, email}` | `kind` is `user`, `contact` or `guest` | +| `assignee` | `{id, name, email}` or null | | +| `tags` | `[{id, name, color}]` | | +| `subjects` | `[Subject]` | Only where subjects are supported | +| `replies` | `[Reply]` | Latest first | +| `activities` | `[{id, type, description, causer, created_at}]` | The latest 20. `causer` is `{id, name}` or null | +| `sla` | object | `first_response_due_at` (timestamp or null), `first_response_at` (timestamp or null), `first_response_breached` (boolean), `resolution_due_at` (timestamp or null), `resolution_breached` (boolean) | +| `is_following` | boolean | True when the caller follows the ticket | +| `followers_count` | integer | | +| `custom_actions` | array | `{key, label, url, method, ...}`, for the caller | +| `resolved_at`, `closed_at` | timestamp or null | | + +`POST /tickets` returns the ticket without `replies` and `activities`. + +### Reply + +`{id, body, is_internal_note, is_pinned, author, attachments, created_at}`. `author` is `{id, name, email}` or null. `attachments` is `[{id, filename, mime_type, size, url}]`. + +### Subject + +`{link_id, type, id, role, position, title, subtitle, url, color, icon, missing}`. `missing` is true when the linked record is gone or the caller may not see it. + +## Endpoints + +Ability `none` means no token. The last column says whether the browser extension needs the endpoint on every backend. + +| Method | Path | Ability | Request | Response | Extension | +|---|---|---|---|---|---| +| GET | `/meta` | none | | `{api_version, backend, features, connect_url, web_url_template}`, plus `backend_version` with a valid token | yes | +| POST | `/auth/exchange` | none | `{code, code_verifier, redirect_uri}` | `{token, token_type, expires_at, user}` | yes | +| POST | `/auth/revoke` | any valid token | | 204, no body | yes | +| POST | `/auth/validate` | agent | | `{user, abilities, is_agent, is_admin, token_name, expires_at}` | yes | +| GET | `/dashboard` | agent | | `{stats, recent_tickets, needs_attention, my_performance}` | yes | +| GET | `/tickets` | agent | query filters below | `{data: [Ticket list item], meta}` | yes | +| POST | `/tickets` | agent | create fields below | 201 `{data: Ticket, message}` | yes | +| GET | `/tickets/{reference}` | agent | | `{data: Ticket}` | yes | +| DELETE | `/tickets/{reference}` | admin | | `{message}` | no | +| GET | `/tickets/{reference}/subjects` | agent | | `{data: [Subject]}` | no | +| PUT | `/tickets/{reference}/subjects` | agent | `{subjects: [{type, id, role?}]}` | `{data: [Subject]}` | no | +| POST | `/tickets/{reference}/reply` | agent | `{body, is_internal_note?}` | 201 `{data: Reply created, message}` | yes | +| PATCH | `/tickets/{reference}/status` | agent | `{status}` | `{message, status}` | yes | +| PATCH | `/tickets/{reference}/priority` | agent | `{priority}` | `{message, priority}` | yes | +| POST | `/tickets/{reference}/assign` | agent | `{agent_id}` | `{message}` | yes | +| POST | `/tickets/{reference}/follow` | agent | | `{message, following}` | no | +| POST | `/tickets/{reference}/macro` | agent | `{macro_id}` | `{message}` | yes | +| POST | `/tickets/{reference}/actions/{action}` | agent | `{payload?}` | `{message, action}` | no | +| POST | `/tickets/{reference}/tags` | agent | `{tag_ids}` | `{message}` | no | +| GET | `/agents` | agent | | `{data: [{id, name, email}]}` | yes | +| GET | `/departments` | agent | | `{data: [{id, name, description, is_active}]}` | yes | +| GET | `/tags` | agent | | `{data: [{id, name, color}]}` | no | +| GET | `/canned-responses` | agent | | `{data: [{id, title, body}]}` | yes | +| GET | `/macros` | agent | | `{data: [{id, name, actions, order}]}` | yes | +| GET | `/realtime/config` | agent | | config object, or `null` | no | +| GET | `/reports/summary` | admin | `period` | summary object | no | +| GET | `/reports/export/{type}` | admin | `format`, `period` | JSON or CSV | no | + +### GET /meta + +No token needed. Rate limited per IP. This is how a client finds the API before sign-in. + +An unknown or expired token is ignored: the answer is the public 200 response, never 401. Every response MUST carry `Vary: Authorization` and `Cache-Control: no-store`, because the body depends on the token. + +```json +{ + "api_version": "1.0", + "backend": "laravel", + "features": ["tickets.create", "tickets.macro", "tickets.updated_since", "tickets.last_customer_reply_at", "tickets.open_filter", "canned_responses", "macros", "auth.exchange", "auth.revoke", "realtime"], + "connect_url": "https://help.example.com/support/agent/connect-extension", + "web_url_template": "https://help.example.com/support/agent/tickets/{reference}" +} +``` + +The `connect_url` and `web_url_template` values are illustrative examples. Real values follow the install's host and web prefix. + +- `backend` is one of `laravel`, `rails`, `django`, `adonis`, `symfony`, `wordpress`, `phoenix`, `go`, `dotnet`, `spring`, `nestjs`. +- `connect_url` is the absolute URL of the connect page. It is `null` when `auth.exchange` is off. +- `web_url_template` is the absolute agent ticket URL with `{reference}` where the reference goes. +- `connect_url` and `web_url_template` MUST be on the same origin (scheme, host and port) as the API base. A client SHOULD refuse a `/meta` response that points elsewhere, since following it would send the staff member to another site. +- With a valid token the response also has `backend_version`, for example `"1.9.21"`. It is left out of the public response so installs do not advertise their version. + +### POST /auth/exchange + +No token. Rate limited to 10 per minute per IP. The server follows the [Exchange rules](#exchange-rules). + +Request: `{code, code_verifier, redirect_uri}`, all strings. + +Success, 200, with `Cache-Control: no-store`: + +```json +{ + "token": "", + "token_type": "Bearer", + "expires_at": null, + "user": { "id": 7, "name": "Sam Agent", "email": "sam@example.com" } +} +``` + +`expires_at` is a timestamp, or `null` when the token never expires. + +Failure, 400 `{ "message": "Invalid or expired code." }`. The same message covers an unknown code, a used code, an expired code, a wrong verifier and a `redirect_uri` that does not match. The response never says which. A body with a missing or non-string field is a 422, checked before any code lookup. + +### POST /auth/revoke + +Any valid token, whatever its abilities. Deletes the token that made the call. Answers 204 with no body. The token is dead on the next request. + +### POST /auth/validate + +Returns the caller: + +```json +{ + "user": { "id": 7, "name": "Sam Agent", "email": "sam@example.com" }, + "abilities": ["agent"], + "is_agent": true, + "is_admin": false, + "token_name": "Browser extension (Chrome)", + "expires_at": null +} +``` + +### GET /dashboard + +```json +{ + "stats": { "open": 0, "my_assigned": 0, "unassigned": 0, "sla_breached": 0, "resolved_today": 0 }, + "recent_tickets": [ + { "id": 1, "reference": "ESC-00001", "subject": "", "status": "open", "priority": "medium", + "requester_name": "", "assignee_name": null, "created_at": "" } + ], + "needs_attention": { + "sla_breaching": [{ "reference": "", "subject": "", "priority": "", "requester_name": "" }], + "unassigned_urgent": [{ "reference": "", "subject": "", "priority": "", "requester_name": "" }] + }, + "my_performance": { "resolved_this_week": 0 } +} +``` + +`recent_tickets` has the 10 newest tickets. Each `needs_attention` list has at most 5 items. `unassigned_urgent` holds open, unassigned tickets with priority `urgent` or `critical`. + +### GET /tickets + +Query parameters. All are optional. + +| Parameter | Meaning | +|---|---| +| `status` | One status value | +| `priority` | One priority value | +| `ticket_type` | One ticket type | +| `assigned_to` | Assignee id | +| `unassigned` | `1` for tickets with no assignee | +| `open` | `1` for tickets in any open-family status: every status except `resolved` and `closed`. `0` is the same as leaving it out. Combines with the other filters, so `open=1&status=resolved` returns nothing. Listed as `tickets.open_filter` in `/meta` features | +| `department_id` | Department id | +| `account_type`, `account_id` | Account filter. Must be sent together | +| `search` | Matches subject, reference, description, and the requester's name and email | +| `sla_breached` | `1` for tickets with a breached SLA | +| `tag_ids[]` | Tag ids | +| `following` | `1` for tickets the caller follows. `0` is the same as leaving it out | +| `updated_since` | ISO 8601 timestamp. Tickets with `updated_at >= updated_since`. A malformed value is a 422 | +| `sort_by` | One of `created_at` (default), `updated_at`, `status`, `priority`, `subject`, `reference`, `assigned_to`, `department_id`, `resolved_at`, `closed_at`. Anything else falls back to `created_at` | +| `sort_dir` | `asc` or `desc` (default) | +| `page`, `per_page` | See [Pagination](#pagination) | + +Ties in the sort column are broken by `id`, in the same direction as `sort_dir`, so pages do not overlap or skip tickets. + +### POST /tickets + +| Field | Type | Rules | +|---|---|---| +| `subject` | string | Required, 255 characters at most | +| `description` | string | Required, 65535 characters at most | +| `priority` | string | A priority value. Default is the install's default priority, `medium` unless changed | +| `ticket_type` | string | A ticket type. Default `question` | +| `department_id` | id or null | Must exist | +| `tags` | array of tag ids | Each must exist | +| `external_reference` | string or null | 255 characters at most | +| `metadata` | object or null | JSON, 16384 bytes at most by default | +| `requester` | object | Either `{id}` for an existing user, or `{name, email}`. Default is the caller | +| `subjects` | array | `[{type, id, role?}]` | + +Answers 201 `{data: Ticket, message: "Ticket created."}`. The ticket starts as `open`, with channel `web`. + +### POST /tickets/{reference}/reply + +`body` is required (65535 characters at most). `is_internal_note` is optional and defaults to false. A note is private to staff. + +Answers 201 with a reduced reply, not the full [Reply](#reply) shape. It has no `is_pinned`, `attachments` or author `email`: + +```json +{ + "data": { "id": 1, "body": "", "is_internal_note": false, "author": { "id": 7, "name": "Sam Agent" }, "created_at": "" }, + "message": "Reply sent." +} +``` + +The message is `Note added.` for a note. + +### Status, priority, assign + +- `PATCH /tickets/{reference}/status` takes `{status}` and answers `{message: "Status updated.", status}`. See [Status transitions](#status-transitions). +- `PATCH /tickets/{reference}/priority` takes `{priority}` and answers `{message: "Priority updated.", priority}`. +- `POST /tickets/{reference}/assign` takes `{agent_id}` and answers `{message: "Ticket assigned."}`. An unknown agent is a 422. + +### Status transitions + +A backend MAY restrict which status changes it allows. Backends differ here: some allow any change, some hard-code a table, and Laravel reads its table from install config. + +- A change the backend refuses MUST be a 422 with `errors.status`, never a 500. For example `{"message": "Cannot change status from closed to waiting_on_customer.", "errors": {"status": ["Cannot change status from closed to waiting_on_customer."]}}`. +- Setting the status a ticket already has MUST be a 200 and a no-op. + +Clients cannot know the table in advance, so they treat a 422 with `errors.status` as "not allowed from here" and show the message. + +Recommended default table. This is informative, not normative; it is Laravel's default config: + +| From | Allowed to | +|---|---| +| `open` | `in_progress`, `waiting_on_customer`, `waiting_on_agent`, `escalated`, `resolved`, `closed` | +| `in_progress` | `waiting_on_customer`, `waiting_on_agent`, `escalated`, `resolved`, `closed` | +| `waiting_on_customer` | `open`, `in_progress`, `resolved`, `closed` | +| `waiting_on_agent` | `open`, `in_progress`, `escalated`, `resolved`, `closed` | +| `escalated` | `in_progress`, `resolved`, `closed` | +| `resolved` | `reopened`, `closed` | +| `closed` | `reopened` | +| `reopened` | `in_progress`, `waiting_on_customer`, `waiting_on_agent`, `escalated`, `resolved`, `closed` | +| `live` | `open`, `resolved`, `closed` | + +### POST /tickets/{reference}/follow + +Toggles. Answers `{message, following}` where `following` is the new state. The message is `Following ticket.` when the caller now follows, and `Unfollowed ticket.` when they stopped. + +### POST /tickets/{reference}/macro + +Takes `{macro_id}`, the macro `id` as returned by `GET /macros`, as an integer. The macro must be shared or created by the caller, or the answer is 404. Applies the macro's actions in order. Answers `{message: "Macro \"\" applied."}`. + +### POST /tickets/{reference}/actions/{action} + +Triggers a custom action by key. `payload` is an optional object. An unknown or hidden action is 404. A disabled action is 403. Answers `{message, action}`. + +### POST /tickets/{reference}/tags + +`tag_ids` is required: an array of integer tag ids. Each must exist. A backend casts them to integers. It replaces the full tag set: tags not in the list are removed. Answers `{message: "Tags updated."}`. + +### GET /macros + +```json +{ "data": [{ "id": 1, "name": "Close as solved", "actions": [{ "type": "status", "value": "resolved" }], "order": 0 }] } +``` + +`actions` is an ordered list of `{type, value}`. `type` is one of `status`, `priority`, `assign`, `tags`, `department`, `reply`, `note`. Only shared macros and the caller's own are listed, sorted by `order`. + +### GET /realtime/config + +When the install broadcasts over Reverb or Pusher: + +```json +{ "driver": "reverb", "channel_prefix": "", "key": "", "host": "", "port": 8080, "scheme": "https", "cluster": null } +``` + +Otherwise the body is `null`. + +### Subjects + +`PUT /tickets/{reference}/subjects` replaces the full set. The `subjects` key must be present, and can be an empty list. Where subjects are not supported the answer is 404. + +### Reports + +- `GET /reports/summary` takes `period` in days (default 30) and answers `{period_days, avg_first_response_hours, avg_resolution_hours, sla_compliance_rate, csat_average, volume, by_status, by_priority, comparison}`. `by_status` and `by_priority` are lists of `{label, value}` rows, for example `[{"label": "open", "value": 12}]`, not maps. A backend casts each `value` to an integer, since some database drivers return counts as strings. +- `GET /reports/export/{type}` takes `format` (`json` default, or `csv`) and `period`. `type` is one of `tickets`, `agent_performance`, `sla_compliance`, `csat`, `resolution_times`, `first_response_times`. Any other type is 404. JSON answers `{report_type, generated_at, filters, record_count, data}`. An empty `filters` may arrive as `[]`. + +## Features + +`GET /meta` lists the features a backend serves. A client hides what is missing. + +| Feature | Means | +|---|---| +| `tickets.create` | `POST /tickets` works | +| `tickets.macro` | `POST /tickets/{reference}/macro` works | +| `tickets.updated_since` | `GET /tickets` honours `updated_since` | +| `tickets.last_customer_reply_at` | List and show items carry `last_customer_reply_at` | +| `tickets.open_filter` | `GET /tickets` honours `open` | +| `canned_responses` | `GET /canned-responses` works | +| `macros` | `GET /macros` works | +| `auth.exchange` | The connect page and `POST /auth/exchange` work | +| `auth.revoke` | `POST /auth/revoke` works | +| `realtime` | `GET /realtime/config` can return a config | + +A backend that passes the conformance suite lists all of them. The list exists so a backend that is partway there can say so honestly. + +## Change log + +### 1.0 + +First version. Taken from `escalated-laravel` 1.9.20 with these changes to Laravel's behaviour: + +- Added `GET /meta`, `POST /auth/exchange`, `POST /auth/revoke` and the connect flow. +- Added `updated_since` on `GET /tickets`. +- Added `last_customer_reply_at` on ticket list and show items. +- Added the optional `open` filter on `GET /tickets` (`open=1` returns every status except `resolved` and `closed`), listed as the `tickets.open_filter` feature. +- `GET /macros` returns `actions`. Laravel returned `steps`, which was always null. +- `GET /reports/export/{type}` answers 404 for an unknown type. Laravel answered 500. +- `following` returns the tickets the caller follows. Laravel returned the tickets the caller requested. +- `GET /tickets/{reference}` always returns `is_following` and `followers_count`. Laravel left them out. +- `GET /tickets/{reference}` returns `sla_breached`, like the list item. Laravel's `TicketResource` leaves it out. +- A status change the backend refuses is a 422 with `errors.status`, and setting the current status is a 200 no-op. Laravel throws `InvalidArgumentException` from `Ticket::transitionTo` (`src/Models/Ticket.php`, line 932), which answers 500. Setting the current status hits the same exception, except for `resolved`, `closed`, `reopened` and `escalated`, which Laravel routes to their own methods without checking the table. +- `GET /tickets` breaks ties in the sort column by `id`. Laravel orders by the sort column alone (`src/Drivers/LocalDriver.php`, line 139), so tickets created in the same second can repeat or go missing across pages. diff --git a/contracts/staff-api-v1.openapi.yaml b/contracts/staff-api-v1.openapi.yaml new file mode 100644 index 0000000..45f7499 --- /dev/null +++ b/contracts/staff-api-v1.openapi.yaml @@ -0,0 +1,1305 @@ +openapi: 3.1.0 +info: + title: Escalated staff API + version: '1.0' + summary: The REST API every Escalated backend serves to staff clients. + description: | + Contract v1. The prose source is `staff-api-v1.md` beside this file. If the two disagree, + fix both in the same change. A backend that disagrees with them is wrong. + license: + name: MIT + identifier: MIT +servers: + - url: '{base}' + variables: + base: + default: https://helpdesk.example.com/support/api/v1 + description: The install's API prefix. WordPress uses `/wp-json/escalated/v1`. Find it with `GET /meta`. +security: + - bearerAuth: [] +tags: + - { name: Discovery, description: Find the API before sign-in. } + - { name: Auth, description: 'Token exchange, revoke and validate.' } + - { name: Dashboard, description: Agent dashboard. } + - { name: Tickets, description: 'Ticket list, detail and actions.' } + - { name: Lookups, description: Reference data for forms and pickers. } + - { name: Reports, description: Admin reports. } + +paths: + /meta: + get: + tags: [Discovery] + operationId: getMeta + summary: Discover the API + description: | + No token needed. Rate limited per IP. `backend_version` is present only with a valid token. + An unknown or expired token is ignored and the answer is the public 200 response, never 401. + `connect_url` and `web_url_template` MUST be on the same origin as the API base. + security: [] + responses: + '200': + description: API metadata + headers: + Vary: { $ref: '#/components/headers/VaryAuthorization' } + Cache-Control: { $ref: '#/components/headers/CacheControlNoStore' } + content: + application/json: + schema: { $ref: '#/components/schemas/Meta' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + + /auth/exchange: + post: + tags: [Auth] + operationId: exchangeAuthCode + summary: Exchange a connect code for a token + description: | + No token. Rate limited to 10 per minute per IP. See *Exchange rules* in `staff-api-v1.md`: + `redirect_uri` is compared by exact string equality, consuming a code is atomic, any + presentation of a known code consumes it (even a failed one), and a replayed code SHOULD + revoke the token it issued. + security: [] + requestBody: + required: true + content: + application/json: + schema: { $ref: '#/components/schemas/ExchangeRequest' } + responses: + '200': + description: Token minted + headers: + Cache-Control: { $ref: '#/components/headers/CacheControlNoStore' } + content: + application/json: + schema: { $ref: '#/components/schemas/ExchangeResponse' } + '400': + description: Invalid or expired code. The same message covers every failure that involves a code. + content: + application/json: + schema: { $ref: '#/components/schemas/Error' } + '404': { $ref: '#/components/responses/NotFound' } + '422': + description: A required field is missing or not a string. Checked before any code lookup, so no code is consumed. + content: + application/json: + schema: { $ref: '#/components/schemas/ValidationError' } + '429': { $ref: '#/components/responses/RateLimited' } + + /auth/revoke: + post: + tags: [Auth] + operationId: revokeToken + summary: Revoke the calling token + description: Any valid token, whatever its abilities. + responses: + '204': { description: 'Token revoked. No body.' } + '401': { $ref: '#/components/responses/Unauthorized' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + + /auth/validate: + post: + tags: [Auth] + operationId: validateToken + summary: Describe the caller + responses: + '200': + description: The caller + content: + application/json: + schema: { $ref: '#/components/schemas/AuthValidateResponse' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '429': { $ref: '#/components/responses/RateLimited' } + + /dashboard: + get: + tags: [Dashboard] + operationId: getDashboard + summary: Dashboard summary + responses: + '200': + description: Dashboard + content: + application/json: + schema: { $ref: '#/components/schemas/Dashboard' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets: + get: + tags: [Tickets] + operationId: listTickets + summary: List tickets + parameters: + - { name: status, in: query, schema: { $ref: '#/components/schemas/TicketStatus' } } + - { name: priority, in: query, schema: { $ref: '#/components/schemas/TicketPriority' } } + - { name: ticket_type, in: query, schema: { $ref: '#/components/schemas/TicketType' } } + - { name: assigned_to, in: query, description: Assignee id., schema: { $ref: '#/components/schemas/Id' } } + - { name: unassigned, in: query, description: '`1` for tickets with no assignee.', schema: { type: string, enum: ['1'] } } + - { name: open, in: query, description: '`1` for tickets in any open-family status, which is every status except `resolved` and `closed`. `0` is the same as omitting it. Combines with the other filters. Listed as `tickets.open_filter` in `/meta` features.', schema: { type: string, enum: ['0', '1'] } } + - { name: department_id, in: query, schema: { $ref: '#/components/schemas/Id' } } + - { name: account_type, in: query, description: Send together with `account_id`., schema: { type: string } } + - { name: account_id, in: query, description: Send together with `account_type`., schema: { type: string } } + - { name: search, in: query, description: 'Matches subject, reference, description, and the requester name and email.', schema: { type: string } } + - { name: sla_breached, in: query, description: '`1` for tickets with a breached SLA.', schema: { type: string, enum: ['1'] } } + - name: tag_ids[] + in: query + description: Tag ids. + style: form + explode: true + schema: + type: array + items: { type: integer } + - { name: following, in: query, description: '`1` for tickets the caller follows. `0` is the same as omitting it.', schema: { type: string, enum: ['0', '1'] } } + - name: updated_since + in: query + description: Tickets with `updated_at >= updated_since`. A malformed value is a 422. + schema: { type: string, format: date-time } + - name: sort_by + in: query + description: Anything else falls back to `created_at`. Ties are broken by `id` in the same direction as `sort_dir`. + schema: + type: string + default: created_at + enum: [created_at, updated_at, status, priority, subject, reference, assigned_to, department_id, resolved_at, closed_at] + - { name: sort_dir, in: query, schema: { type: string, default: desc, enum: [asc, desc] } } + - { name: page, in: query, schema: { type: integer, minimum: 1, default: 1 } } + - { name: per_page, in: query, description: Above 100 is a 422., schema: { type: integer, minimum: 1, maximum: 100, default: 15 } } + responses: + '200': + description: A page of tickets + content: + application/json: + schema: + type: object + required: [data, meta] + properties: + data: + type: array + items: { $ref: '#/components/schemas/TicketListItem' } + meta: { $ref: '#/components/schemas/PaginationMeta' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + post: + tags: [Tickets] + operationId: createTicket + summary: Create a ticket + requestBody: + required: true + content: + application/json: + schema: { $ref: '#/components/schemas/CreateTicketRequest' } + responses: + '201': + description: Ticket created. The ticket has no `replies` or `activities`. + content: + application/json: + schema: + type: object + required: [data, message] + properties: + data: { $ref: '#/components/schemas/Ticket' } + message: { type: string, examples: ['Ticket created.'] } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}: + parameters: + - { $ref: '#/components/parameters/Reference' } + get: + tags: [Tickets] + operationId: getTicket + summary: Show a ticket + responses: + '200': + description: The ticket + content: + application/json: + schema: + type: object + required: [data] + properties: + data: { $ref: '#/components/schemas/Ticket' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + delete: + tags: [Tickets] + operationId: deleteTicket + summary: Delete a ticket + description: Needs the `admin` ability. + responses: + '200': { $ref: '#/components/responses/Message' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/subjects: + parameters: + - { $ref: '#/components/parameters/Reference' } + get: + tags: [Tickets] + operationId: listTicketSubjects + summary: List a ticket's subjects + responses: + '200': { $ref: '#/components/responses/SubjectList' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + put: + tags: [Tickets] + operationId: replaceTicketSubjects + summary: Replace a ticket's subjects + description: Replaces the full set. The `subjects` key must be present and can be an empty list. Where subjects are not supported the answer is 404. + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [subjects] + properties: + subjects: + type: array + items: + type: object + required: [type, id] + properties: + type: { type: string } + id: { $ref: '#/components/schemas/Id' } + role: { type: string } + responses: + '200': { $ref: '#/components/responses/SubjectList' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/reply: + parameters: + - { $ref: '#/components/parameters/Reference' } + post: + tags: [Tickets] + operationId: replyToTicket + summary: Reply to a ticket or add an internal note + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [body] + properties: + body: { type: string, maxLength: 65535 } + is_internal_note: { type: boolean, default: false } + responses: + '201': + description: Reply or note created. The message is `Reply sent.` or `Note added.`. + content: + application/json: + schema: + type: object + required: [data, message] + properties: + data: { $ref: '#/components/schemas/ReplyCreated' } + message: { type: string } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/status: + parameters: + - { $ref: '#/components/parameters/Reference' } + patch: + tags: [Tickets] + operationId: updateTicketStatus + summary: Change a ticket's status + description: | + A backend MAY restrict which changes it allows (a recommended default table is in + `staff-api-v1.md`). A refused change MUST be a 422 with `errors.status`, never a 500. + Setting the current status MUST be a 200 and a no-op. + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [status] + properties: + status: { $ref: '#/components/schemas/TicketStatus' } + responses: + '200': + description: Status updated + content: + application/json: + schema: + type: object + required: [message, status] + properties: + message: { type: string, examples: ['Status updated.'] } + status: { $ref: '#/components/schemas/TicketStatus' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/priority: + parameters: + - { $ref: '#/components/parameters/Reference' } + patch: + tags: [Tickets] + operationId: updateTicketPriority + summary: Change a ticket's priority + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [priority] + properties: + priority: { $ref: '#/components/schemas/TicketPriority' } + responses: + '200': + description: Priority updated + content: + application/json: + schema: + type: object + required: [message, priority] + properties: + message: { type: string, examples: ['Priority updated.'] } + priority: { $ref: '#/components/schemas/TicketPriority' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/assign: + parameters: + - { $ref: '#/components/parameters/Reference' } + post: + tags: [Tickets] + operationId: assignTicket + summary: Assign a ticket to an agent + description: An unknown agent is a 422. + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [agent_id] + properties: + agent_id: { $ref: '#/components/schemas/Id' } + responses: + '200': { $ref: '#/components/responses/Message' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/follow: + parameters: + - { $ref: '#/components/parameters/Reference' } + post: + tags: [Tickets] + operationId: toggleTicketFollow + summary: Toggle following a ticket + description: The message is `Following ticket.` or `Unfollowed ticket.`. `following` is the new state. + responses: + '200': + description: New follow state + content: + application/json: + schema: + type: object + required: [message, following] + properties: + message: { type: string } + following: { type: boolean } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/macro: + parameters: + - { $ref: '#/components/parameters/Reference' } + post: + tags: [Tickets] + operationId: applyMacro + summary: Apply a macro to a ticket + description: The macro must be shared or created by the caller, or the answer is 404. + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [macro_id] + properties: + macro_id: + type: integer + description: The macro `id` as returned by `GET /macros`. + responses: + '200': { $ref: '#/components/responses/Message' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/actions/{action}: + parameters: + - { $ref: '#/components/parameters/Reference' } + - { name: action, in: path, required: true, description: Custom action key., schema: { type: string } } + post: + tags: [Tickets] + operationId: runTicketAction + summary: Trigger a custom action + description: An unknown or hidden action is 404. A disabled action is 403. + requestBody: + required: false + content: + application/json: + schema: + type: object + properties: + payload: { type: object, additionalProperties: true } + responses: + '200': + description: Action triggered + content: + application/json: + schema: + type: object + required: [message, action] + properties: + message: { type: string } + action: { type: string } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tickets/{reference}/tags: + parameters: + - { $ref: '#/components/parameters/Reference' } + post: + tags: [Tickets] + operationId: setTicketTags + summary: Replace a ticket's tags + description: Replaces the full tag set. Tags not in the list are removed. + requestBody: + required: true + content: + application/json: + schema: + type: object + required: [tag_ids] + properties: + tag_ids: + type: array + description: Integer ids of existing tags. + items: { type: integer } + responses: + '200': { $ref: '#/components/responses/Message' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '422': { $ref: '#/components/responses/ValidationFailed' } + '429': { $ref: '#/components/responses/RateLimited' } + + /agents: + get: + tags: [Lookups] + operationId: listAgents + summary: List agents + responses: + '200': + description: Agents + content: + application/json: + schema: + type: object + required: [data] + properties: + data: + type: array + items: { $ref: '#/components/schemas/Agent' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '429': { $ref: '#/components/responses/RateLimited' } + + /departments: + get: + tags: [Lookups] + operationId: listDepartments + summary: List departments + responses: + '200': + description: Departments + content: + application/json: + schema: + type: object + required: [data] + properties: + data: + type: array + items: { $ref: '#/components/schemas/Department' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '429': { $ref: '#/components/responses/RateLimited' } + + /tags: + get: + tags: [Lookups] + operationId: listTags + summary: List tags + responses: + '200': + description: Tags + content: + application/json: + schema: + type: object + required: [data] + properties: + data: + type: array + items: { $ref: '#/components/schemas/Tag' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '429': { $ref: '#/components/responses/RateLimited' } + + /canned-responses: + get: + tags: [Lookups] + operationId: listCannedResponses + summary: List canned responses + responses: + '200': + description: Canned responses + content: + application/json: + schema: + type: object + required: [data] + properties: + data: + type: array + items: { $ref: '#/components/schemas/CannedResponse' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + + /macros: + get: + tags: [Lookups] + operationId: listMacros + summary: List macros + description: Only shared macros and the caller's own, sorted by `order`. + responses: + '200': + description: Macros + content: + application/json: + schema: + type: object + required: [data] + properties: + data: + type: array + items: { $ref: '#/components/schemas/Macro' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + + /realtime/config: + get: + tags: [Lookups] + operationId: getRealtimeConfig + summary: Realtime broadcast config + description: The body is `null` when the install does not broadcast over Reverb or Pusher. + responses: + '200': + description: Config object, or null + content: + application/json: + schema: + oneOf: + - $ref: '#/components/schemas/RealtimeConfig' + - type: 'null' + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '429': { $ref: '#/components/responses/RateLimited' } + + /reports/summary: + get: + tags: [Reports] + operationId: getReportSummary + summary: Report summary + description: Needs the `admin` ability. + parameters: + - { name: period, in: query, description: Days., schema: { type: integer, minimum: 1, default: 30 } } + responses: + '200': + description: Summary + content: + application/json: + schema: { $ref: '#/components/schemas/ReportSummary' } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '429': { $ref: '#/components/responses/RateLimited' } + + /reports/export/{type}: + get: + tags: [Reports] + operationId: exportReport + summary: Export a report + description: Needs the `admin` ability. Any other type is 404. + parameters: + - name: type + in: path + required: true + schema: + type: string + enum: [tickets, agent_performance, sla_compliance, csat, resolution_times, first_response_times] + - { name: format, in: query, schema: { type: string, default: json, enum: [json, csv] } } + - { name: period, in: query, description: Days., schema: { type: integer, minimum: 1, default: 30 } } + responses: + '200': + description: The report + content: + application/json: + schema: + type: object + required: [report_type, generated_at, filters, record_count, data] + properties: + report_type: { type: string } + generated_at: { $ref: '#/components/schemas/Timestamp' } + filters: + description: Applied filters. An empty set may serialize as `[]`. + oneOf: + - { type: object, additionalProperties: true } + - { type: array, maxItems: 0 } + record_count: { type: integer } + data: { type: array, items: { type: object, additionalProperties: true } } + text/csv: + schema: { type: string } + '401': { $ref: '#/components/responses/Unauthorized' } + '403': { $ref: '#/components/responses/Forbidden' } + '404': { $ref: '#/components/responses/NotFound' } + '429': { $ref: '#/components/responses/RateLimited' } + +components: + securitySchemes: + bearerAuth: + type: http + scheme: bearer + description: Opaque token. Abilities are `agent`, `admin` or `*`. + + parameters: + Reference: + name: reference + in: path + required: true + description: Ticket reference, for example `ESC-00042`. Never the numeric id. + schema: { type: string } + + headers: + RetryAfter: + description: Seconds until the limit resets. + schema: { type: integer } + CacheControlNoStore: + description: Must include `no-store`. + schema: { type: string, examples: [no-store] } + VaryAuthorization: + description: Must include `Authorization`, because the body depends on the token. + schema: { type: string, examples: [Authorization] } + + responses: + Message: + description: Done + content: + application/json: + schema: + type: object + required: [message] + properties: + message: { type: string } + SubjectList: + description: Subjects + content: + application/json: + schema: + type: object + required: [data] + properties: + data: + type: array + items: { $ref: '#/components/schemas/Subject' } + Unauthorized: + description: Missing, unknown or expired token. Match on the status, not the message. + content: + application/json: + schema: { $ref: '#/components/schemas/Error' } + Forbidden: + description: Token or user lacks permission, or a policy refused the action. + content: + application/json: + schema: { $ref: '#/components/schemas/Error' } + NotFound: + description: Unknown ticket, action, report type or route. Also every route when the API is off. + content: + application/json: + schema: { $ref: '#/components/schemas/Error' } + ValidationFailed: + description: Validation failed. + content: + application/json: + schema: { $ref: '#/components/schemas/ValidationError' } + RateLimited: + description: Rate limited. + headers: + Retry-After: { $ref: '#/components/headers/RetryAfter' } + X-RateLimit-Limit: { schema: { type: integer } } + X-RateLimit-Remaining: { schema: { type: integer } } + content: + application/json: + schema: + type: object + required: [message] + properties: + message: { type: string, examples: ['Too many requests.'] } + retry_after: { type: integer } + + schemas: + Id: + description: Opaque id. Host apps use integers or strings. + type: [integer, string] + Timestamp: + description: ISO 8601 in UTC. Both `Z` and `+00:00` suffixes occur. + type: string + format: date-time + NullableTimestamp: + description: ISO 8601 in UTC, or null. + type: [string, 'null'] + format: date-time + TicketStatus: + type: string + enum: [open, in_progress, waiting_on_customer, waiting_on_agent, escalated, resolved, closed, reopened, live] + TicketPriority: + type: string + enum: [low, medium, high, urgent, critical] + TicketType: + type: string + enum: [question, problem, incident, task] + + Meta: + type: object + required: [api_version, backend, features, connect_url, web_url_template] + properties: + api_version: { type: string, examples: ['1.0'] } + backend: + type: string + enum: [laravel, rails, django, adonis, symfony, wordpress, phoenix, go, dotnet, spring, nestjs] + backend_version: + type: string + description: Only with a valid token. + examples: ['1.9.21'] + features: + type: array + items: + type: string + description: 'Known values: tickets.create, tickets.macro, tickets.updated_since, tickets.last_customer_reply_at, tickets.open_filter, canned_responses, macros, auth.exchange, auth.revoke, realtime.' + connect_url: + type: [string, 'null'] + description: Absolute URL of the connect page. Null when `auth.exchange` is off. The example value is illustrative. + examples: ['https://help.example.com/support/agent/connect-extension'] + web_url_template: + type: string + description: Absolute agent ticket URL with `{reference}` where the reference goes. The example value is illustrative. + examples: ['https://help.example.com/support/agent/tickets/{reference}'] + + PaginationMeta: + type: object + required: [current_page, last_page, per_page, total] + properties: + current_page: { type: integer } + last_page: { type: integer } + per_page: { type: integer } + total: { type: integer } + + Error: + type: object + required: [message] + properties: + message: { type: string } + + ValidationError: + type: object + required: [message, errors] + properties: + message: { type: string } + errors: + type: object + additionalProperties: + type: array + items: { type: string } + + AccountRef: + type: object + required: [type, id] + properties: + type: { type: string } + id: { type: string } + + NamedRef: + type: object + required: [id, name] + properties: + id: { $ref: '#/components/schemas/Id' } + name: { type: string } + + TicketListItem: + type: object + required: [id, reference, ticket_type, subject, status, status_label, priority, priority_label, requester, assignee, department, sla_breached, last_reply_at, last_customer_reply_at, created_at, updated_at] + properties: + id: { $ref: '#/components/schemas/Id' } + reference: { type: string } + ticket_type: + type: string + description: '`question` when the stored value is null.' + account: + description: Present only when accounts are enabled. + oneOf: + - $ref: '#/components/schemas/AccountRef' + - type: 'null' + subject: { type: string } + status: { $ref: '#/components/schemas/TicketStatus' } + status_label: { type: string } + priority: { $ref: '#/components/schemas/TicketPriority' } + priority_label: { type: string } + requester: + type: object + required: [name, email] + properties: + name: { type: [string, 'null'] } + email: { type: [string, 'null'] } + assignee: + oneOf: + - $ref: '#/components/schemas/NamedRef' + - type: 'null' + department: + oneOf: + - $ref: '#/components/schemas/NamedRef' + - type: 'null' + sla_breached: { type: boolean } + last_reply_at: + description: Last reply of any kind. + $ref: '#/components/schemas/NullableTimestamp' + last_customer_reply_at: + description: Last public activity from the customer side. + $ref: '#/components/schemas/NullableTimestamp' + created_at: { $ref: '#/components/schemas/Timestamp' } + updated_at: { $ref: '#/components/schemas/Timestamp' } + + Ticket: + type: object + description: Full ticket. It has every list item field except the list item's `requester`. `POST /tickets` omits `replies` and `activities`. + required: [id, reference, ticket_type, subject, description, status, status_label, priority, priority_label, channel, metadata, external_reference, requester, assignee, department, sla_breached, tags, sla, is_following, followers_count, custom_actions, resolved_at, closed_at, last_reply_at, last_customer_reply_at, created_at, updated_at] + properties: + id: { $ref: '#/components/schemas/Id' } + reference: { type: string } + ticket_type: + type: string + description: '`question` when the stored value is null.' + account: + oneOf: + - $ref: '#/components/schemas/AccountRef' + - type: 'null' + subject: { type: string } + description: { type: string } + status: { $ref: '#/components/schemas/TicketStatus' } + status_label: { type: string } + priority: { $ref: '#/components/schemas/TicketPriority' } + priority_label: { type: string } + channel: { type: string } + metadata: + description: Free-form JSON. An empty value may serialize as `[]`, so accept an empty array as empty. + oneOf: + - { type: object, additionalProperties: true } + - { type: array, maxItems: 0 } + - { type: 'null' } + external_reference: { type: [string, 'null'] } + requester: + type: object + required: [kind, id, name, email] + properties: + kind: { type: string, enum: [user, contact, guest] } + id: + oneOf: + - $ref: '#/components/schemas/Id' + - type: 'null' + name: { type: [string, 'null'] } + email: { type: [string, 'null'] } + assignee: + oneOf: + - type: 'null' + - type: object + required: [id, name, email] + properties: + id: { $ref: '#/components/schemas/Id' } + name: { type: string } + email: { type: [string, 'null'] } + department: + oneOf: + - $ref: '#/components/schemas/NamedRef' + - type: 'null' + sla_breached: { type: boolean } + tags: + type: array + items: { $ref: '#/components/schemas/Tag' } + subjects: + description: Only where subjects are supported. + type: array + items: { $ref: '#/components/schemas/Subject' } + replies: + description: Latest first. Absent on `POST /tickets`. + type: array + items: { $ref: '#/components/schemas/Reply' } + activities: + description: The latest 20. Absent on `POST /tickets`. + type: array + items: + type: object + required: [id, type, description, causer, created_at] + properties: + id: { $ref: '#/components/schemas/Id' } + type: { type: string } + description: { type: [string, 'null'] } + causer: + oneOf: + - $ref: '#/components/schemas/NamedRef' + - type: 'null' + created_at: { $ref: '#/components/schemas/Timestamp' } + sla: + type: object + required: [first_response_due_at, first_response_at, first_response_breached, resolution_due_at, resolution_breached] + properties: + first_response_due_at: { $ref: '#/components/schemas/NullableTimestamp' } + first_response_at: { $ref: '#/components/schemas/NullableTimestamp' } + first_response_breached: { type: boolean } + resolution_due_at: { $ref: '#/components/schemas/NullableTimestamp' } + resolution_breached: { type: boolean } + is_following: { type: boolean } + followers_count: { type: integer } + custom_actions: + type: array + items: + type: object + required: [key, label] + properties: + key: { type: string } + label: { type: string } + url: { type: [string, 'null'] } + method: { type: string } + additionalProperties: true + resolved_at: { $ref: '#/components/schemas/NullableTimestamp' } + closed_at: { $ref: '#/components/schemas/NullableTimestamp' } + last_reply_at: { $ref: '#/components/schemas/NullableTimestamp' } + last_customer_reply_at: { $ref: '#/components/schemas/NullableTimestamp' } + created_at: { $ref: '#/components/schemas/Timestamp' } + updated_at: { $ref: '#/components/schemas/Timestamp' } + + CreateTicketRequest: + type: object + required: [subject, description] + properties: + subject: { type: string, maxLength: 255 } + description: { type: string, maxLength: 65535 } + priority: { $ref: '#/components/schemas/TicketPriority' } + ticket_type: { $ref: '#/components/schemas/TicketType' } + department_id: + oneOf: + - $ref: '#/components/schemas/Id' + - type: 'null' + tags: + type: array + description: Ids of existing tags. + items: { type: integer } + external_reference: { type: [string, 'null'], maxLength: 255 } + metadata: { type: [object, 'null'], additionalProperties: true } + requester: + description: Either `{id}` for an existing user, or `{name, email}`. Default is the caller. + type: object + properties: + id: { $ref: '#/components/schemas/Id' } + name: { type: string } + email: { type: string } + subjects: + type: array + items: + type: object + required: [type, id] + properties: + type: { type: string } + id: { $ref: '#/components/schemas/Id' } + role: { type: string } + + Reply: + type: object + required: [id, body, is_internal_note, is_pinned, author, created_at] + properties: + id: { $ref: '#/components/schemas/Id' } + body: { type: string } + is_internal_note: { type: boolean } + is_pinned: { type: boolean } + author: + oneOf: + - type: 'null' + - type: object + required: [id, name] + properties: + id: { $ref: '#/components/schemas/Id' } + name: { type: string } + email: { type: [string, 'null'] } + attachments: + type: array + items: + type: object + required: [id, filename, mime_type, size, url] + properties: + id: { $ref: '#/components/schemas/Id' } + filename: { type: string } + mime_type: { type: [string, 'null'] } + size: { type: [integer, 'null'] } + url: { type: [string, 'null'] } + created_at: { $ref: '#/components/schemas/Timestamp' } + + ReplyCreated: + description: The reduced reply returned by `POST /tickets/{reference}/reply`. + type: object + required: [id, body, is_internal_note, author, created_at] + properties: + id: { $ref: '#/components/schemas/Id' } + body: { type: string } + is_internal_note: { type: boolean } + author: + oneOf: + - $ref: '#/components/schemas/NamedRef' + - type: 'null' + created_at: { $ref: '#/components/schemas/Timestamp' } + + Subject: + type: object + required: [link_id, type, id, role, title, missing] + properties: + link_id: { $ref: '#/components/schemas/Id' } + type: { type: string } + id: { $ref: '#/components/schemas/Id' } + role: { type: [string, 'null'] } + position: { type: [integer, 'null'] } + title: { type: [string, 'null'] } + subtitle: { type: [string, 'null'] } + url: { type: [string, 'null'] } + color: { type: [string, 'null'] } + icon: { type: [string, 'null'] } + missing: + type: boolean + description: True when the linked record is gone or the caller may not see it. + + Tag: + type: object + required: [id, name, color] + properties: + id: { $ref: '#/components/schemas/Id' } + name: { type: string } + color: { type: [string, 'null'] } + + Agent: + type: object + required: [id, name, email] + properties: + id: { $ref: '#/components/schemas/Id' } + name: { type: string } + email: { type: [string, 'null'] } + + Department: + type: object + required: [id, name, description, is_active] + properties: + id: { $ref: '#/components/schemas/Id' } + name: { type: string } + description: { type: [string, 'null'] } + is_active: { type: boolean } + + CannedResponse: + type: object + required: [id, title, body] + properties: + id: { $ref: '#/components/schemas/Id' } + title: { type: string } + body: { type: string } + + Macro: + type: object + required: [id, name, actions, order] + properties: + id: { type: integer } + name: { type: string } + actions: + type: array + description: Ordered list applied in sequence. + items: + type: object + required: [type, value] + properties: + type: { type: string, enum: [status, priority, assign, tags, department, reply, note] } + value: {} + order: { type: integer } + + Dashboard: + type: object + required: [stats, recent_tickets, needs_attention, my_performance] + properties: + stats: + type: object + required: [open, my_assigned, unassigned, sla_breached, resolved_today] + properties: + open: { type: integer } + my_assigned: { type: integer } + unassigned: { type: integer } + sla_breached: { type: integer } + resolved_today: { type: integer } + recent_tickets: + description: The 10 newest tickets. + type: array + items: + type: object + required: [id, reference, subject, status, priority, requester_name, assignee_name, created_at] + properties: + id: { $ref: '#/components/schemas/Id' } + reference: { type: string } + subject: { type: string } + status: { $ref: '#/components/schemas/TicketStatus' } + priority: { $ref: '#/components/schemas/TicketPriority' } + requester_name: { type: [string, 'null'] } + assignee_name: { type: [string, 'null'] } + created_at: { $ref: '#/components/schemas/Timestamp' } + needs_attention: + type: object + required: [sla_breaching, unassigned_urgent] + properties: + sla_breaching: { $ref: '#/components/schemas/AttentionList' } + unassigned_urgent: { $ref: '#/components/schemas/AttentionList' } + my_performance: + type: object + required: [resolved_this_week] + properties: + resolved_this_week: { type: integer } + + AttentionList: + description: At most 5 items. + type: array + items: + type: object + required: [reference, subject, priority, requester_name] + properties: + reference: { type: string } + subject: { type: string } + priority: { type: string } + requester_name: { type: [string, 'null'] } + + ExchangeRequest: + type: object + required: [code, code_verifier, redirect_uri] + properties: + code: { type: string } + code_verifier: + type: string + description: 43 to 128 characters from `[A-Za-z0-9-._~]`. A well-formed but wrong verifier is a 400 and consumes the code. + redirect_uri: + type: string + description: Compared with the value stored for the code by exact string equality. + + ExchangeResponse: + type: object + required: [token, token_type, expires_at, user] + properties: + token: { type: string } + token_type: { type: string, enum: [Bearer] } + expires_at: { $ref: '#/components/schemas/NullableTimestamp' } + user: { $ref: '#/components/schemas/Agent' } + + AuthValidateResponse: + type: object + required: [user, abilities, is_agent, is_admin, token_name, expires_at] + properties: + user: { $ref: '#/components/schemas/Agent' } + abilities: + type: array + items: { type: string } + is_agent: { type: boolean } + is_admin: { type: boolean } + token_name: { type: [string, 'null'] } + expires_at: { $ref: '#/components/schemas/NullableTimestamp' } + + RealtimeConfig: + type: object + required: [driver, key] + properties: + driver: { type: string, examples: [reverb] } + channel_prefix: { type: string } + key: { type: string } + host: { type: [string, 'null'] } + port: { type: [integer, 'null'] } + scheme: { type: [string, 'null'] } + cluster: { type: [string, 'null'] } + + ReportSummary: + type: object + required: [period_days, avg_first_response_hours, avg_resolution_hours, sla_compliance_rate, csat_average, volume, by_status, by_priority, comparison] + properties: + period_days: { type: integer } + avg_first_response_hours: { type: [number, 'null'] } + avg_resolution_hours: { type: [number, 'null'] } + sla_compliance_rate: { type: [number, 'null'] } + csat_average: { type: [number, 'null'] } + volume: {} + by_status: { $ref: '#/components/schemas/LabelValueRows' } + by_priority: { $ref: '#/components/schemas/LabelValueRows' } + comparison: {} + + LabelValueRows: + description: 'Counts as a list of rows, for example [{"label": "open", "value": 12}].' + type: array + items: + type: object + required: [label, value] + properties: + label: { type: string } + value: + type: integer + description: A backend casts counts to integers; some database drivers return them as strings.