@zeyos/client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/LICENSE +21 -0
  3. package/README.md +458 -0
  4. package/agents/README.md +66 -0
  5. package/agents/shared/business-app-benchmarks.md +111 -0
  6. package/agents/shared/zeyos-entity-map.md +142 -0
  7. package/agents/shared/zeyos-entity-reference.md +570 -0
  8. package/agents/shared/zeyos-query-patterns.md +89 -0
  9. package/agents/zeyos-account-intelligence/SKILL.md +34 -0
  10. package/agents/zeyos-account-intelligence/agents/openai.yaml +4 -0
  11. package/agents/zeyos-account-intelligence/references/workflows.md +84 -0
  12. package/agents/zeyos-billing-insights/SKILL.md +41 -0
  13. package/agents/zeyos-billing-insights/agents/openai.yaml +4 -0
  14. package/agents/zeyos-billing-insights/references/workflows.md +106 -0
  15. package/agents/zeyos-campaign-and-outreach/SKILL.md +44 -0
  16. package/agents/zeyos-campaign-and-outreach/agents/openai.yaml +4 -0
  17. package/agents/zeyos-campaign-and-outreach/references/workflows.md +100 -0
  18. package/agents/zeyos-collaboration-and-activity/SKILL.md +37 -0
  19. package/agents/zeyos-collaboration-and-activity/agents/openai.yaml +4 -0
  20. package/agents/zeyos-collaboration-and-activity/references/workflows.md +104 -0
  21. package/agents/zeyos-collections-and-dunning/SKILL.md +46 -0
  22. package/agents/zeyos-collections-and-dunning/agents/openai.yaml +4 -0
  23. package/agents/zeyos-collections-and-dunning/references/workflows.md +132 -0
  24. package/agents/zeyos-commerce-and-inventory/SKILL.md +38 -0
  25. package/agents/zeyos-commerce-and-inventory/agents/openai.yaml +4 -0
  26. package/agents/zeyos-commerce-and-inventory/references/workflows.md +101 -0
  27. package/agents/zeyos-mail-operations/SKILL.md +35 -0
  28. package/agents/zeyos-mail-operations/agents/openai.yaml +4 -0
  29. package/agents/zeyos-mail-operations/references/workflows.md +110 -0
  30. package/agents/zeyos-notes-and-sops/SKILL.md +31 -0
  31. package/agents/zeyos-notes-and-sops/agents/openai.yaml +4 -0
  32. package/agents/zeyos-notes-and-sops/references/workflows.md +85 -0
  33. package/agents/zeyos-platform-and-schema/SKILL.md +37 -0
  34. package/agents/zeyos-platform-and-schema/agents/openai.yaml +4 -0
  35. package/agents/zeyos-platform-and-schema/references/workflows.md +97 -0
  36. package/agents/zeyos-work-management/SKILL.md +45 -0
  37. package/agents/zeyos-work-management/agents/openai.yaml +4 -0
  38. package/agents/zeyos-work-management/references/workflows.md +148 -0
  39. package/docs/01-api-reference/01-data-retrieval.md +601 -0
  40. package/docs/01-api-reference/02-authentication.md +288 -0
  41. package/docs/01-api-reference/03-resources.md +270 -0
  42. package/docs/01-api-reference/04-schema.md +539 -0
  43. package/docs/01-api-reference/_category_.json +9 -0
  44. package/docs/02-javascript-client/01-getting-started.md +146 -0
  45. package/docs/02-javascript-client/02-authentication.md +287 -0
  46. package/docs/02-javascript-client/03-making-requests.md +572 -0
  47. package/docs/02-javascript-client/04-practical-guide.md +348 -0
  48. package/docs/02-javascript-client/_category_.json +9 -0
  49. package/docs/03-cli/01-getting-started.md +219 -0
  50. package/docs/03-cli/02-commands.md +407 -0
  51. package/docs/03-cli/03-configuration.md +220 -0
  52. package/docs/03-cli/_category_.json +9 -0
  53. package/docs/04-agent-workflows/00-coding-agents.md +35 -0
  54. package/docs/04-agent-workflows/01-agent-quickstart.md +147 -0
  55. package/docs/04-agent-workflows/02-agent-recipes.md +109 -0
  56. package/docs/04-agent-workflows/03-cli-coverage-and-escalation.md +65 -0
  57. package/docs/04-agent-workflows/_category_.json +9 -0
  58. package/docs/04-sample-apps/01-kanban.md +89 -0
  59. package/docs/04-sample-apps/02-crm.md +81 -0
  60. package/docs/04-sample-apps/03-dashboard.md +80 -0
  61. package/docs/04-sample-apps/_category_.json +9 -0
  62. package/docs/05-tutorials/00-application-developers.md +43 -0
  63. package/docs/05-tutorials/01-integration-architecture.md +60 -0
  64. package/docs/05-tutorials/02-build-your-own-zeyos-frontend.md +517 -0
  65. package/docs/05-tutorials/03-server-side-integrations.md +185 -0
  66. package/docs/05-tutorials/_category_.json +9 -0
  67. package/docs/intro.md +197 -0
  68. package/openapi/api.json +24308 -0
  69. package/openapi/auth.json +415 -0
  70. package/openapi/dbref.json +56223 -0
  71. package/openapi/oauth2.json +781 -0
  72. package/openapi/sdk.json +949 -0
  73. package/openapi/views.txt +642 -0
  74. package/package.json +49 -0
  75. package/samples/crm/README.md +28 -0
  76. package/samples/crm/index.html +327 -0
  77. package/samples/crm/js/api.js +208 -0
  78. package/samples/crm/js/auth.js +61 -0
  79. package/samples/crm/js/main.js +545 -0
  80. package/samples/crm/js/state.js +90 -0
  81. package/samples/crm/js/ui.js +51 -0
  82. package/samples/dashboard/README.md +28 -0
  83. package/samples/dashboard/index.html +280 -0
  84. package/samples/dashboard/js/api.js +197 -0
  85. package/samples/dashboard/js/auth.js +59 -0
  86. package/samples/dashboard/js/main.js +382 -0
  87. package/samples/dashboard/js/state.js +81 -0
  88. package/samples/dashboard/js/ui.js +48 -0
  89. package/samples/kanban/README.md +28 -0
  90. package/samples/kanban/index.html +263 -0
  91. package/samples/kanban/js/api.js +152 -0
  92. package/samples/kanban/js/auth.js +59 -0
  93. package/samples/kanban/js/constants.js +40 -0
  94. package/samples/kanban/js/kanban.js +246 -0
  95. package/samples/kanban/js/main.js +362 -0
  96. package/samples/kanban/js/modals.js +474 -0
  97. package/samples/kanban/js/settings.js +82 -0
  98. package/samples/kanban/js/state.js +118 -0
  99. package/samples/kanban/js/ui.js +49 -0
  100. package/scripts/generate-client.mjs +344 -0
  101. package/src/generated/operations.js +9772 -0
  102. package/src/generated/schema.js +8982 -0
  103. package/src/index.js +85 -0
  104. package/src/runtime/client.js +1208 -0
  105. package/src/runtime/error.js +29 -0
  106. package/src/runtime/http.js +174 -0
  107. package/src/runtime/request-shape.js +35 -0
  108. package/src/runtime/schema.js +206 -0
  109. package/src/runtime/suggest.js +74 -0
  110. package/src/runtime/token-store.js +105 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ Notable changes to `@zeyos/client` and `@zeyos/cli`. This project follows
4
+ [Semantic Versioning](https://semver.org/).
5
+
6
+ ## 0.1.0 — Initial release
7
+
8
+ ### `@zeyos/client`
9
+ - Zero-dependency JavaScript client (browser + Node 18+) for the ZeyOS OpenAPI
10
+ services (`api`, `oauth2`, `legacyAuth`), with methods generated from the specs.
11
+ - Authentication modes: `auto`, `oauth` (bearer + refresh; authorization-code and
12
+ password grants), `session` (ZEYOSID cookie), and `none`; pluggable token store
13
+ (`MemoryTokenStore`) and token-set helpers.
14
+ - Schema introspection (`client.schema`): describe resources, fields, enums, and
15
+ foreign keys; pre-flight `validate()` flags unknown fields, bad enums, the
16
+ `filter`-vs-`filters` footgun, and required-on-create fields.
17
+ - Resilience: automatic 429 retry honoring `Retry-After`, structured
18
+ `ZeyosApiError` / `ZeyosValidationError`, CRUD body inference, and
19
+ `normalizeListResult`.
20
+
21
+ ### `@zeyos/cli` (`zeyos`)
22
+ - CRUD against common resources with `--json`/`--yaml`, field selection and
23
+ aliasing, dot-notation joins, pagination, and config-driven field display.
24
+ - OAuth login flow, credential cascade (env → `.zeyos` → global config),
25
+ `describe` / `resources` / `skills` / `whoami`, and safe delete confirmation.
26
+ - Accepts a JSON body passed positionally to `create` / `update`.
27
+
28
+ ### Docs, samples & agent skills
29
+ - Docusaurus documentation (API reference, JavaScript client, CLI, agent
30
+ workflows, tutorials), three sample apps (Kanban, CRM, Dashboard), and a
31
+ repo-local agent skill pack under `agents/`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ZeyOS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,458 @@
1
+ # ZeyOS Client & CLI
2
+
3
+ A dependency-light JavaScript client, a command-line tool, and agent guidance for integrating external tools with [ZeyOS](https://www.zeyos.com) — the ERP/CRM platform. Read and write business data (tickets, accounts, tasks, projects, billing, and 50+ more resources) over the ZeyOS OpenAPI surface.
4
+
5
+ This repository ships two npm packages plus the docs, OpenAPI specs, sample apps, and coding-agent skills:
6
+
7
+ | Package | What it is | Install |
8
+ |---------|-----------|---------|
9
+ | [`@zeyos/client`](#javascript-client) | Zero-runtime-dependency JS client (browser + Node 18+). Auto-generated methods for the full API. | `npm install @zeyos/client` |
10
+ | [`@zeyos/cli`](#cli) | The `zeyos` command — login, CRUD, schema introspection, agent-skill installer. | `npm install -g @zeyos/cli` |
11
+
12
+ The authoritative, in-depth documentation lives in [`docs/`](./docs/). This README is the quick tour.
13
+
14
+ ---
15
+
16
+ ## Table of contents
17
+
18
+ - [Quick start](#quick-start)
19
+ - [Authentication & login](#authentication--login)
20
+ - [CLI](#cli)
21
+ - [JavaScript client](#javascript-client)
22
+ - [Using ZeyOS with a coding agent](#using-zeyos-with-a-coding-agent)
23
+ - [Sample apps](#sample-apps)
24
+ - [Repository layout](#repository-layout)
25
+ - [Documentation](#documentation)
26
+ - [Testing](#testing)
27
+ - [Conventions & gotchas](#conventions--gotchas)
28
+ - [License](#license)
29
+
30
+ ---
31
+
32
+ ## Quick start
33
+
34
+ ### From the command line
35
+
36
+ ```bash
37
+ npm install -g @zeyos/cli
38
+
39
+ # Authenticate once (opens a browser for the OAuth flow)
40
+ zeyos login --base-url https://cloud.zeyos.com/demo --client-id myapp --secret "$ZEYOS_CLIENT_SECRET"
41
+
42
+ # Read and write
43
+ zeyos list tickets --filter '{"status":4}' --sort -lastmodified --limit 10
44
+ zeyos count tickets --filter '{"status":4}'
45
+ zeyos get ticket 42 --all
46
+ zeyos create ticket --name "Fix login bug" --status 0 --priority 3
47
+ zeyos update ticket 42 --status 9
48
+ ```
49
+
50
+ ### From JavaScript
51
+
52
+ ```js
53
+ import { createZeyosClient, MemoryTokenStore } from '@zeyos/client';
54
+
55
+ const client = createZeyosClient({
56
+ platform: 'https://cloud.zeyos.com/demo/',
57
+ auth: {
58
+ mode: 'oauth',
59
+ oauth: {
60
+ tokenStore: new MemoryTokenStore({ accessToken: process.env.ZEYOS_TOKEN }),
61
+ },
62
+ },
63
+ });
64
+
65
+ const tickets = await client.api.listTickets({
66
+ fields: ['ID', 'name', 'status', 'priority'],
67
+ filters: { visibility: 0 },
68
+ limit: 10,
69
+ });
70
+ ```
71
+
72
+ > **`platform`** is your instance URL: `https://<host>/<instance>/`. For `https://cloud.zeyos.com/demo/`, the instance is `demo`. The string `'live'` is a shorthand preset for `https://cloud.zeyos.com`.
73
+
74
+ ---
75
+
76
+ ## Authentication & login
77
+
78
+ ZeyOS uses OAuth 2.0. You register an application in your ZeyOS instance to get a **client ID** and **client secret**, then obtain tokens via one of the flows below. The client also supports legacy session-cookie auth.
79
+
80
+ The client supports four auth **modes**:
81
+
82
+ | Mode | Behavior |
83
+ |------|----------|
84
+ | `auto` (default) | Bearer token → auto-refresh on expiry/401 → session-cookie fallback |
85
+ | `oauth` | Bearer token only |
86
+ | `session` | Session cookies only |
87
+ | `none` | No authentication (public endpoints) |
88
+
89
+ ### Option 1 — Log in with the CLI
90
+
91
+ The easiest path. `zeyos login` runs the OAuth authorization-code flow: it prints the URLs, opens your browser, starts a local callback server to capture the redirect, and stores the resulting tokens.
92
+
93
+ ```bash
94
+ zeyos login \
95
+ --base-url https://cloud.zeyos.com/demo \
96
+ --client-id myapp \
97
+ --secret "$ZEYOS_CLIENT_SECRET"
98
+
99
+ zeyos whoami # confirm you're authenticated
100
+ ```
101
+
102
+ - Omit any of `--base-url` / `--client-id` / `--secret` to be prompted interactively (the secret prompt is masked).
103
+ - `--global` stores credentials in `~/.config/zeyos/credentials.json` instead of a local `.zeyos/auth.json`.
104
+ - `--manual` skips the browser and prompts you to paste the authorization code (useful over SSH).
105
+ - `--force` re-authenticates even if a token is already stored; `--clean` discards the saved config and re-prompts for everything.
106
+
107
+ Tokens auto-refresh on use, and the refreshed token is written back to whichever config file you logged into. **Add `.zeyos/auth.json` to your `.gitignore`** — it holds credentials and tokens.
108
+
109
+ ### Option 2 — Programmatic OAuth (authorization-code flow)
110
+
111
+ For server-side apps that run their own OAuth flow:
112
+
113
+ ```js
114
+ import { createZeyosClient } from '@zeyos/client';
115
+
116
+ const client = createZeyosClient({
117
+ platform: 'https://cloud.zeyos.com/demo/',
118
+ auth: { mode: 'oauth', oauth: { clientId: 'myapp', clientSecret: process.env.ZEYOS_CLIENT_SECRET } },
119
+ });
120
+
121
+ // 1. Send the user to the authorization URL
122
+ const authUrl = client.oauth2.buildAuthorizationUrl({
123
+ redirectUri: 'https://myapp.example.com/callback',
124
+ scope: 'all',
125
+ state: 'csrf-token-here',
126
+ });
127
+
128
+ // 2. On your callback route, exchange the code for tokens (stored in the token store)
129
+ const { code } = client.oauth2.parseAuthorizationCallback(req.url);
130
+ await client.oauth2.exchangeAuthorizationCode({
131
+ code,
132
+ redirectUri: 'https://myapp.example.com/callback',
133
+ });
134
+
135
+ // 3. Make authenticated calls — tokens refresh automatically when they expire
136
+ const me = await client.oauth2.getUserInfo();
137
+ ```
138
+
139
+ PKCE is supported by passing `codeChallenge` / `codeChallengeMethod` to `buildAuthorizationUrl` and `codeVerifier` to `exchangeAuthorizationCode`.
140
+
141
+ ### Option 3 — Use an access token directly
142
+
143
+ If you already have an access token (and optionally a refresh token), seed a `MemoryTokenStore`:
144
+
145
+ ```js
146
+ import { createZeyosClient, MemoryTokenStore } from '@zeyos/client';
147
+
148
+ const client = createZeyosClient({
149
+ platform: 'https://cloud.zeyos.com/demo/',
150
+ auth: {
151
+ mode: 'oauth',
152
+ oauth: {
153
+ clientId: 'myapp',
154
+ clientSecret: process.env.ZEYOS_CLIENT_SECRET, // required for auto-refresh
155
+ tokenStore: new MemoryTokenStore({
156
+ accessToken: process.env.ZEYOS_TOKEN,
157
+ refreshToken: process.env.ZEYOS_REFRESH_TOKEN,
158
+ }),
159
+ },
160
+ },
161
+ });
162
+ ```
163
+
164
+ Implement your own persistent token store by providing an object with `async get()` and `async set(tokenSet)` — see [server-side integrations](./docs/05-tutorials/03-server-side-integrations.md).
165
+
166
+ ### CLI credential resolution
167
+
168
+ The CLI resolves credentials in this order (first match wins, field by field):
169
+
170
+ 1. **Environment variables** — `ZEYOS_BASE_URL`, `ZEYOS_INSTANCE`, `ZEYOS_CLIENT_ID`, `ZEYOS_CLIENT_SECRET`, `ZEYOS_TOKEN`, `ZEYOS_REFRESH_TOKEN`
171
+ 2. **Local** `.zeyos/auth.json` (found by walking up from the current directory, like `.git`)
172
+ 3. **Global** `~/.config/zeyos/credentials.json`
173
+
174
+ Environment variables make CI and ephemeral agent environments easy:
175
+
176
+ ```bash
177
+ export ZEYOS_BASE_URL=https://cloud.zeyos.com/demo
178
+ export ZEYOS_TOKEN=your-access-token
179
+ zeyos list accounts --limit 5
180
+ ```
181
+
182
+ ---
183
+
184
+ ## CLI
185
+
186
+ Install globally (`npm install -g @zeyos/cli`) or run from this repo with `node cli/bin/zeyos.mjs <command>`.
187
+
188
+ ```
189
+ zeyos <command> [options] [args…]
190
+ ```
191
+
192
+ | Command | What it does | Example |
193
+ |---------|--------------|---------|
194
+ | `login` | OAuth login, stores tokens | `zeyos login --base-url https://cloud.zeyos.com/demo --client-id myapp --secret $S` |
195
+ | `logout` | Revoke session and clear stored tokens | `zeyos logout` |
196
+ | `whoami` | Show the authenticated user | `zeyos whoami --json` |
197
+ | `list <resource>` | List / query records | `zeyos list tickets --filter '{"status":4}' --sort -lastmodified` |
198
+ | `count <resource>` | Count records (true total) | `zeyos count tickets --filter '{"status":4}'` |
199
+ | `get <resource> <id>` | Fetch one record (`show` is an alias) | `zeyos get ticket 42 --all` |
200
+ | `create <resource>` | Create a record | `zeyos create ticket --name "Bug" --status 0 --priority 3` |
201
+ | `update <resource> <id>` | Update a record (`edit` is an alias) | `zeyos update ticket 42 --status 9` |
202
+ | `delete <resource> <id>` | Delete a record (`rm`/`remove` aliases) | `zeyos delete ticket 42 --force` |
203
+ | `resources` | List resource types the CLI exposes | `zeyos resources --json` |
204
+ | `describe <resource>` | Show a resource's fields, types and enums | `zeyos describe ticket` |
205
+ | `skills <list\|show\|install>` | Manage bundled coding-agent skills | `zeyos skills install --target claude` |
206
+
207
+ **Global options** (work on every command): `--json`, `--yaml`, `--no-color`, `-h/--help`, `-v/--version`.
208
+
209
+ ### Querying
210
+
211
+ ```bash
212
+ # Field selection: comma list, JSON array, or JSON object (with aliasing + dot-notation joins)
213
+ zeyos list tickets --fields ID,name,status --limit 10
214
+ zeyos list accounts --fields '{"Name": "lastname", "City": "contact.city"}'
215
+
216
+ # Filtering (JSON object) and sorting (prefix - for descending)
217
+ zeyos list tickets --filter '{"status":4,"priority":4}' --sort -lastmodified
218
+
219
+ # Pagination
220
+ zeyos list tickets --limit 100 --offset 100
221
+ ```
222
+
223
+ > `zeyos list` defaults to `--limit 50` and prints a `Showing X–Y of TOTAL` hint to **stderr** when the result is truncated. To count records, use `zeyos count <resource>` — counting the rows of a `list` only counts the current page.
224
+
225
+ ### Creating & updating
226
+
227
+ Pass fields as individual flags or as a JSON blob:
228
+
229
+ ```bash
230
+ zeyos create ticket --name "Fix login bug" --status 0 --priority 3
231
+ zeyos create account --lastname "Acme Corp" --currency EUR --type 1
232
+ zeyos update ticket 42 --status 9 --data '{"priority":4}'
233
+ ```
234
+
235
+ `--json` / `--yaml` switch any command to machine-readable output, which is what you want for scripting and agents:
236
+
237
+ ```bash
238
+ zeyos list tickets --filter '{"status":4}' --json | jq '.[].name'
239
+ ```
240
+
241
+ Full CLI reference: [docs/03-cli](./docs/03-cli/01-getting-started.md).
242
+
243
+ ---
244
+
245
+ ## JavaScript client
246
+
247
+ `createZeyosClient(config)` returns a frozen client. Every API operation is available as a method under `client.api.*` (and `client.oauth2.*`, `client.legacyAuth.*`).
248
+
249
+ ```js
250
+ import {
251
+ createZeyosClient,
252
+ MemoryTokenStore,
253
+ ZeyosApiError,
254
+ normalizeListResult,
255
+ normalizeCountResult,
256
+ } from '@zeyos/client';
257
+
258
+ const client = createZeyosClient({
259
+ platform: 'https://cloud.zeyos.com/demo/',
260
+ auth: { mode: 'oauth', oauth: { tokenStore: new MemoryTokenStore({ accessToken: TOKEN }) } },
261
+ });
262
+ ```
263
+
264
+ ### CRUD
265
+
266
+ ```js
267
+ // List with field selection, filters, and sorting
268
+ const tickets = await client.api.listTickets({
269
+ fields: ['ID', 'name', 'status', 'priority', 'lastmodified'],
270
+ filters: { visibility: 0, status: 4 },
271
+ sort: ['-lastmodified'],
272
+ limit: 25,
273
+ });
274
+
275
+ // Count (count is a boolean flag)
276
+ const open = await client.api.listTickets({ filters: { visibility: 0, status: 4 }, count: true });
277
+ const total = normalizeCountResult(open);
278
+
279
+ // Fetch one
280
+ const ticket = await client.api.getTicket({ ID: 42 });
281
+
282
+ // Create (returns the new record)
283
+ const created = await client.api.createTicket({ name: 'Fix login bug', status: 0, priority: 3 });
284
+
285
+ // Update — flat spread or an explicit body both work
286
+ await client.api.updateTicket({ ID: 42, status: 9 });
287
+
288
+ // Delete
289
+ await client.api.deleteTicket({ ID: 42 });
290
+ ```
291
+
292
+ ### Normalizing responses
293
+
294
+ List endpoints return either a plain array or a `{ data, count }` wrapper depending on the call. `normalizeListResult` smooths that over:
295
+
296
+ ```js
297
+ const raw = await client.api.listAccounts({ filters: { visibility: 0 } });
298
+ const { data, count } = normalizeListResult(raw); // data is always an array
299
+ ```
300
+
301
+ ### Schema introspection
302
+
303
+ `client.schema` is a read-only view of resources, fields, enums, and operations — handy for building UIs and for agents that need to self-correct:
304
+
305
+ ```js
306
+ client.schema.resources(); // ['accounts', 'tickets', ...]
307
+ client.schema.fields('tickets'); // ['ID', 'name', 'status', ...]
308
+ client.schema.describe('accounts'); // { name, type, fields }
309
+ client.schema.operationIds(); // every callable operationId
310
+
311
+ // Opt-in pre-flight validation: catches unknown fields, filter/filters
312
+ // spelling, bad enum values, and required-create fields before the request.
313
+ const result = client.schema.validate('createAccount', { lastname: 'Acme' });
314
+ // → { valid: false, errors: [{ field: 'currency', message: 'Missing required field "currency" …' }] }
315
+ ```
316
+
317
+ Enable validation on every call with `createZeyosClient({ validate: true })`, or per call with `client.api.createAccount(input, { validate: true })` (throws `ZeyosValidationError`).
318
+
319
+ ### Error handling
320
+
321
+ Non-2xx responses throw a `ZeyosApiError` carrying the full response context:
322
+
323
+ ```js
324
+ try {
325
+ await client.api.getTicket({ ID: 999999 });
326
+ } catch (err) {
327
+ if (err instanceof ZeyosApiError) {
328
+ console.error(err.status, err.statusText); // 404 'Not Found'
329
+ console.error(err.body); // parsed server response
330
+ console.error(err.operationId, err.url); // 'getTicket', full URL
331
+ }
332
+ }
333
+ ```
334
+
335
+ Calling an operation that doesn't exist throws a helpful `ZeyosApiError` with a "did you mean …?" suggestion instead of an opaque `TypeError`.
336
+
337
+ ### Retries & low-level access
338
+
339
+ - **Retries**: 429/503 are retried automatically with exponential backoff that honors `Retry-After`. Configure with `retry: { maxRetries, retryOn, baseDelayMs, maxDelayMs }`, or disable with `retry: false`.
340
+ - **Escape hatch**: `client.request({ service, operationId, ... })` or `client.request({ service, method, path, ... })` for anything the generated methods don't cover. Pass `{ raw: true }` to get the full `{ status, headers, data }` response.
341
+
342
+ Full client reference: [docs/02-javascript-client](./docs/02-javascript-client/01-getting-started.md). For battle-tested patterns and gotchas, see the [Practical Guide](./docs/02-javascript-client/04-practical-guide.md).
343
+
344
+ ---
345
+
346
+ ## Using ZeyOS with a coding agent
347
+
348
+ ZeyOS ships **agent skills** — curated instructions and query playbooks that teach a coding agent (Claude Code, Codex, etc.) how to operate against ZeyOS with the right conventions out of the box. This is the fastest way to let an agent read and write your business data correctly.
349
+
350
+ ### 1. Install the skills into your project
351
+
352
+ ```bash
353
+ zeyos skills list # see what's available
354
+ zeyos skills install --target claude # copies skills into .claude/skills/
355
+ zeyos skills install zeyos-work-management # or install just one
356
+ ```
357
+
358
+ `--target claude` writes to `.claude/skills/`, `--target codex` writes to `.codex/skills/`; with no `--target`, it auto-detects an existing `.claude`/`.codex` directory (defaulting to Claude). Shared reference docs are installed alongside so the skills' cross-links resolve. Point your agent at the install directory.
359
+
360
+ Bundled skills:
361
+
362
+ | Skill | Focus |
363
+ |-------|-------|
364
+ | `zeyos-work-management` | Tickets, tasks, projects, action steps, assignees, workload |
365
+ | `zeyos-account-intelligence` | Accounts, contacts, addresses, opportunities |
366
+ | `zeyos-billing-insights` | Transactions, invoices, credits, payments, revenue |
367
+ | `zeyos-collections-and-dunning` | Overdue receivables, dunning notices, collection workflows |
368
+ | `zeyos-commerce-and-inventory` | Items, pricing, price lists, stock, suppliers |
369
+ | `zeyos-campaign-and-outreach` | Campaigns, mailing lists, outbound mailings |
370
+ | `zeyos-collaboration-and-activity` | Timelines, comments, followers, channels, files, events |
371
+ | `zeyos-mail-operations` | Querying, summarizing, and drafting email/message records |
372
+ | `zeyos-notes-and-sops` | Notes, SOPs, documents, file-backed knowledge |
373
+ | `zeyos-platform-and-schema` | Platform/admin entities, schema, custom fields |
374
+
375
+ ### 2. Give the agent the CLI as its tool
376
+
377
+ For most agent workflows, the CLI with `--json` is the right interface: stable machine-readable output, built-in auth, and a safe delete confirmation. The agent runs `zeyos` commands and pipes JSON through `jq` or parses it directly.
378
+
379
+ ```bash
380
+ zeyos describe ticket --json # discover fields & enums
381
+ zeyos list tickets --filter '{"status":4}' --json
382
+ zeyos count accounts --filter '{"type":1}'
383
+ ```
384
+
385
+ When a task needs a resource or request shape the CLI doesn't expose, the agent escalates to `@zeyos/client`, which covers the full generated API surface.
386
+
387
+ See [Agent Workflows](./docs/04-agent-workflows/00-coding-agents.md): [quickstart](./docs/04-agent-workflows/01-agent-quickstart.md), [recipes](./docs/04-agent-workflows/02-agent-recipes.md), and [CLI coverage & escalation](./docs/04-agent-workflows/03-cli-coverage-and-escalation.md).
388
+
389
+ ---
390
+
391
+ ## Sample apps
392
+
393
+ Three runnable, dependency-free browser demos live in [`samples/`](./samples/):
394
+
395
+ - [**Kanban**](./docs/04-sample-apps/01-kanban.md) — drag-and-drop ticket board (status updates, detail view).
396
+ - [**CRM**](./docs/04-sample-apps/02-crm.md) — contact list with dot-notation joins, full-text search, sortable columns, pagination, inline editing.
397
+ - [**Dashboard**](./docs/04-sample-apps/03-dashboard.md) — KPI cards and charts built from parallel `count` queries.
398
+
399
+ Each can be served as static files from the repository root; see the linked docs for run and configuration instructions.
400
+
401
+ ---
402
+
403
+ ## Repository layout
404
+
405
+ - [`src/`](./src/) — the `@zeyos/client` JavaScript client (`src/runtime/` is hand-written; `src/generated/` is generated from the OpenAPI specs).
406
+ - [`cli/`](./cli/) — the `@zeyos/cli` command-line tool.
407
+ - [`docs/`](./docs/) — the authoritative documentation (Docusaurus).
408
+ - [`agents/`](./agents/) — repo-local ZeyOS agent skills and query playbooks.
409
+ - [`openapi/`](./openapi/) — the OpenAPI specifications and DB schema reference.
410
+ - [`samples/`](./samples/) — the sample browser applications.
411
+ - [`scripts/`](./scripts/) — client generation (`generate-client.mjs`) and the test runner.
412
+
413
+ ---
414
+
415
+ ## Documentation
416
+
417
+ | Section | Covers | Entry point |
418
+ |---------|--------|-------------|
419
+ | **API Reference** | Query language, OAuth2, every resource endpoint, field schema | [docs/01-api-reference](./docs/01-api-reference/01-data-retrieval.md) |
420
+ | **JavaScript Client** | Install, auth modes, CRUD, filtering, schema, retries, errors, patterns | [docs/02-javascript-client](./docs/02-javascript-client/01-getting-started.md) |
421
+ | **CLI** | Install, login, all commands, config & field display | [docs/03-cli](./docs/03-cli/01-getting-started.md) |
422
+ | **Agent Workflows** | CLI-first agent orientation, JSON recipes, escalation | [docs/04-agent-workflows](./docs/04-agent-workflows/00-coding-agents.md) |
423
+ | **Sample Apps** | Kanban, CRM, Dashboard walkthroughs | [docs/04-sample-apps](./docs/04-sample-apps/01-kanban.md) |
424
+ | **Tutorials** | Architecture guide, build-your-own frontend, server-side integration | [docs/05-tutorials](./docs/05-tutorials/00-application-developers.md) |
425
+ | **Agent Skills** | What the bundled skills do and how they're organized | [agents/README.md](./agents/README.md) |
426
+
427
+ ---
428
+
429
+ ## Testing
430
+
431
+ ```bash
432
+ npm test # offline unit + schema tests (mocked fetch)
433
+ npm test -- --live # adds a live OAuth smoke test (needs config.test.json)
434
+ npm run test:cli-integration # live CLI CRUD lifecycle (requires `zeyos login`)
435
+ npm run test:agent-protocol # agent-driven live protocol; --dry-run to verify wiring first
436
+ ```
437
+
438
+ The CLI has its own offline suite: `node --test cli/test/offline.mjs`.
439
+
440
+ The **agent test protocol** drives a coding agent against a live instance and uses a model-rotation rule to separate real client defects from model flakiness. See [`test/agent-protocol/PROTOCOL.md`](./test/agent-protocol/PROTOCOL.md).
441
+
442
+ ---
443
+
444
+ ## Conventions & gotchas
445
+
446
+ A few platform facts that save debugging time (full list in the [Practical Guide](./docs/02-javascript-client/04-practical-guide.md)):
447
+
448
+ - **Use `filters` (plural)**, not `filter`, in client/CLI code. `filters` also matches GIN-indexed foreign-key fields (`account`, `project`, `ticket`); `filter` silently ignores them.
449
+ - **Always include `visibility: 0`** in filters unless you want archived (`1`) or deleted (`2`) records.
450
+ - **Dates are Unix timestamps in seconds**, not milliseconds (`new Date(value * 1000)`).
451
+ - **`createAccount` requires `currency`** (e.g. `"EUR"`) — it's `NOT NULL` with no default and otherwise fails with an opaque HTTP 500. Accounts use `lastname`/`firstname` (there is no `name` field) and `type` (not `accounttype`).
452
+ - **`operationId`s are CamelCase compounds** that don't always match DB table names (e.g. `dunning` → `listDunningNotices`). Use `client.schema.operationIds()` or `zeyos resources` to discover them.
453
+
454
+ ---
455
+
456
+ ## License
457
+
458
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,66 @@
1
+ # ZeyOS Agent Skills
2
+
3
+ This folder contains a repo-local skill pack for coding agents that use ZeyOS as a business operating system. The focus is not generic chat behavior. The focus is repeatable business queries and actions that depend on the ZeyOS entity model, its query rules, and safe escalation from the CLI to the JavaScript client.
4
+
5
+ The source-backed model reference lives in [`shared/zeyos-entity-reference.md`](./shared/zeyos-entity-reference.md) and is derived from [`openapi/dbref.json`](../openapi/dbref.json) and [`openapi/api.json`](../openapi/api.json).
6
+ Cross-platform modeling guidance lives in [`shared/business-app-benchmarks.md`](./shared/business-app-benchmarks.md).
7
+
8
+ ## Structure
9
+
10
+ - `shared/` contains cross-domain query rules and entity relationships.
11
+ - `zeyos-work-management/` handles tasks, projects, tickets, and assignee workload questions.
12
+ - `zeyos-mail-operations/` handles message lookup, email summaries, threads, and safe draft workflows.
13
+ - `zeyos-billing-insights/` handles transactions, payments, invoices, credits, and revenue questions.
14
+ - `zeyos-notes-and-sops/` handles notes, SOP discovery, documents, and file-backed knowledge lookup.
15
+ - `zeyos-account-intelligence/` handles customer 360 questions across accounts, contacts, addresses, opportunities, and contracts.
16
+ - `zeyos-commerce-and-inventory/` handles catalog, pricing, stock, supplier, and price-list questions.
17
+ - `zeyos-collections-and-dunning/` handles overdue receivables, reminders, notices, and payment-gap analysis.
18
+ - `zeyos-campaign-and-outreach/` handles campaigns, mailing lists, participants, mailing activity, and recipient coverage.
19
+ - `zeyos-collaboration-and-activity/` handles record timelines, comments, followers, channels, files, and recent-activity reconstruction.
20
+ - `zeyos-platform-and-schema/` handles applications, services, custom fields, objects, groups, and permissions.
21
+
22
+ ## Shared Design Rules
23
+
24
+ - Resolve business names to IDs before answering cross-record questions.
25
+ - Start with the smallest primary query, then follow relationships with a second query when needed.
26
+ - Use `visibility: 0` for resources that expose a `visibility` field.
27
+ - Check `zeyos resources --json` before assuming CLI coverage. If a required resource is missing from the curated CLI registry, switch to `@zeyos/client`.
28
+ - Treat `filter` vs `filters` as a source inconsistency; follow the interface-native convention and verify raw REST behavior against the target instance.
29
+ - Treat list responses and count-enabled responses defensively.
30
+ - Treat "worked on", "revenue", and "latest SOP" as potentially ambiguous business concepts and state the chosen interpretation.
31
+ - Keep destructive actions and outbound email sends behind explicit confirmation.
32
+
33
+ ## Skill Catalog
34
+
35
+ | Skill | Best for | Example prompts |
36
+ |------|----------|-----------------|
37
+ | `zeyos-work-management` | Operational work queues, user workload, ticket-task-project tracing, follow-up work creation | "On which projects did Max Power work in the last two weeks?"; "Show overdue high-priority tickets for account ACME."; "What open tasks are blocking Project Atlas?" |
38
+ | `zeyos-mail-operations` | Customer mail summaries, thread reconstruction, draft preparation, mailbox analysis | "Give me a summary of all recent mails from customer XYZ."; "Which open tickets have unanswered customer emails?"; "Draft a reply to the latest complaint from ACME." |
39
+ | `zeyos-billing-insights` | Revenue, invoices, credits, payment tracking, transaction-level finance questions | "What is our net invoiced revenue this year?"; "How much cash did we collect this quarter?"; "Show all billing activity for customer XYZ." |
40
+ | `zeyos-notes-and-sops` | SOP retrieval, note summaries, final-document lookup, attachment discovery | "Find the current escalation SOP for billing disputes."; "Summarize our notes on failed invoice syncs."; "Which finalized onboarding SOP changed last month?" |
41
+ | `zeyos-account-intelligence` | Customer 360, contacts, contracts, opportunities, CRM hygiene | "Give me a 360 summary for customer XYZ."; "What open opportunities and active contracts do we have with ACME?"; "Which accounts are missing billing addresses?" |
42
+ | `zeyos-commerce-and-inventory` | Customer-specific pricing, stock, suppliers, catalog structure | "What price does customer XYZ get for item ABC?"; "Which items are low on stock?"; "Who are the suppliers for item ABC?" |
43
+ | `zeyos-collections-and-dunning` | Overdue invoices, dunning notices, payment gaps, receivables follow-up | "Which invoices are overdue for customer XYZ?"; "What dunning notices are still open?"; "Which receivables need follow-up this week?" |
44
+ | `zeyos-campaign-and-outreach` | Campaign setup, mailing-list membership, participant coverage, outreach execution | "How many participants are in campaign Spring Renewal?"; "Which mailing lists belong to campaign XYZ?"; "Who received the latest mailing?" |
45
+ | `zeyos-collaboration-and-activity` | Activity timelines, comments, channels, followers, attachments, recent changes | "What happened on account ACME this week?"; "Who follows Project Atlas?"; "Which channel is linked to ticket 812?" |
46
+ | `zeyos-platform-and-schema` | App inventory, service hooks, custom schema, group permissions | "Which custom fields exist on tickets?"; "Which services run after ticket modification?"; "Which groups grant access to application XYZ?" |
47
+
48
+ ## Interface Boundary
49
+
50
+ The CLI covers common operational resources such as accounts, contacts, documents, items, projects, tasks, tickets, users, and groups. Skills that depend on platform, pricing, campaign-recipient, permission, channel, follower, or other specialist resources should start with `zeyos resources --json`; if the resource is absent, use `@zeyos/client` and the generated operation names from the API reference.
51
+
52
+ ## Recommended Loading Order
53
+
54
+ 1. Read `shared/zeyos-query-patterns.md`.
55
+ 2. Read `shared/business-app-benchmarks.md` when the semantics are unclear.
56
+ 3. Read `shared/zeyos-entity-reference.md` when the entity itself is unclear.
57
+ 4. Read `shared/zeyos-entity-map.md` if the question crosses domains.
58
+ 5. Load the matching skill folder and its `references/workflows.md`.
59
+
60
+ ## Good Next Skills
61
+
62
+ Potential next additions that would fit this folder well are:
63
+
64
+ - calendar and appointment coordination
65
+ - document generation and approval flows
66
+ - purchasing and supplier performance analysis