zinkee 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 (61) hide show
  1. package/AGENTS.md +46 -0
  2. package/README.md +395 -0
  3. package/dist/index.d.ts +13 -0
  4. package/dist/index.js +7142 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +32 -0
  7. package/src/api/automations.ts +403 -0
  8. package/src/api/comments.ts +51 -0
  9. package/src/api/displays.ts +276 -0
  10. package/src/api/files.ts +50 -0
  11. package/src/api/navigation.ts +71 -0
  12. package/src/api/records.ts +167 -0
  13. package/src/api/schemas.ts +130 -0
  14. package/src/api/teamspace.ts +110 -0
  15. package/src/cli-examples.ts +175 -0
  16. package/src/cli-runner.ts +73 -0
  17. package/src/client.test.ts +128 -0
  18. package/src/client.ts +243 -0
  19. package/src/command-registry.ts +749 -0
  20. package/src/commands/automations.test.ts +728 -0
  21. package/src/commands/automations.ts +2013 -0
  22. package/src/commands/comments.test.ts +214 -0
  23. package/src/commands/comments.ts +303 -0
  24. package/src/commands/config.test.ts +81 -0
  25. package/src/commands/config.ts +150 -0
  26. package/src/commands/displays.test.ts +266 -0
  27. package/src/commands/displays.ts +755 -0
  28. package/src/commands/files.test.ts +284 -0
  29. package/src/commands/files.ts +280 -0
  30. package/src/commands/navigation.test.ts +214 -0
  31. package/src/commands/navigation.ts +348 -0
  32. package/src/commands/profiles.test.ts +82 -0
  33. package/src/commands/profiles.ts +281 -0
  34. package/src/commands/records.test.ts +367 -0
  35. package/src/commands/records.ts +726 -0
  36. package/src/commands/schemas.test.ts +748 -0
  37. package/src/commands/schemas.ts +746 -0
  38. package/src/commands/teamspace.test.ts +229 -0
  39. package/src/commands/teamspace.ts +540 -0
  40. package/src/config.test.ts +165 -0
  41. package/src/config.ts +248 -0
  42. package/src/index.test.ts +140 -0
  43. package/src/index.ts +8 -0
  44. package/src/parsers/expressions.test.ts +50 -0
  45. package/src/parsers/expressions.ts +111 -0
  46. package/src/parsers/kv.test.ts +35 -0
  47. package/src/parsers/kv.ts +49 -0
  48. package/src/parsers/selectors.test.ts +23 -0
  49. package/src/parsers/selectors.ts +29 -0
  50. package/src/program.ts +56 -0
  51. package/src/runtime-context.ts +18 -0
  52. package/src/types.ts +71 -0
  53. package/src/utils/errors.test.ts +48 -0
  54. package/src/utils/errors.ts +183 -0
  55. package/src/utils/examples.test.ts +67 -0
  56. package/src/utils/examples.ts +855 -0
  57. package/src/utils/output.test.ts +39 -0
  58. package/src/utils/output.ts +124 -0
  59. package/src/utils/schema-fields.ts +529 -0
  60. package/tsconfig.json +20 -0
  61. package/tsup.config.ts +13 -0
package/AGENTS.md ADDED
@@ -0,0 +1,46 @@
1
+ # Zinkee CLI Notes
2
+
3
+ This repository contains a TypeScript ESM CLI for Zinkee API v2.
4
+
5
+ ## Source Of Truth
6
+
7
+ Use this order when reasoning about behavior:
8
+
9
+ 1. live command registration in `src/index.ts`
10
+ 2. command modules in `src/commands`
11
+ 3. docs in `README.md`
12
+
13
+ ## Key Runtime Rules
14
+
15
+ - Existing config compatibility is mandatory: `~/.config/zinkee/config.toml`
16
+ - `--read-only` must block write/destructive commands before network calls
17
+ - `--example <command path>` should return concrete usage examples without running the command
18
+ - `--json` must keep stdout machine-readable
19
+ - success JSON shape is `{ data, meta }`
20
+ - error JSON shape is `{ error, meta }`
21
+
22
+ ## Current Command Groups
23
+
24
+ - `profiles`
25
+ - `config`
26
+ - `files`
27
+ - `schemas`
28
+ - `records`
29
+ - `comments`
30
+ - `navigation`
31
+ - `teamspace`
32
+ - `displays`
33
+ - `automations`
34
+
35
+ ## Implementation Shape
36
+
37
+ - REST transport lives in `src/api`
38
+ - commander commands live in `src/commands`
39
+ - shared config/runtime lives in `src/config.ts` and `src/runtime-context.ts`
40
+ - JSON/table output helpers live in `src/utils/output.ts`
41
+ - shared CLI error handling lives in `src/utils/errors.ts`
42
+ - parsers live in `src/parsers`
43
+
44
+ ## Testing
45
+
46
+ Prefer focused command tests and parser/client unit tests.
package/README.md ADDED
@@ -0,0 +1,395 @@
1
+ # Zinkee CLI
2
+
3
+ Command-line interface for Zinkee Public API v2.
4
+
5
+ ## Status
6
+
7
+ Implemented command groups:
8
+
9
+ - `profiles`
10
+ - `config`
11
+ - `files`
12
+ - `schemas`
13
+ - `records`
14
+ - `comments`
15
+ - `navigation`
16
+ - `teamspace`
17
+ - `displays`
18
+ - `automations`
19
+
20
+ ## Requirements
21
+
22
+ - Node.js 20+
23
+
24
+ ## Install Dependencies
25
+
26
+ ```bash
27
+ npm install
28
+ ```
29
+
30
+ ## Development
31
+
32
+ ```bash
33
+ npm run build
34
+ npm run typecheck
35
+ npm test
36
+ ```
37
+
38
+ ## Configuration
39
+
40
+ The CLI is compatible with the existing config file:
41
+
42
+ ```text
43
+ ~/.config/zinkee/config.toml
44
+ ```
45
+
46
+ Example:
47
+
48
+ ```toml
49
+ default_profile = "prod"
50
+
51
+ [profiles.prod]
52
+ api_key = "token"
53
+ base_url = "https://api.zinkee.com"
54
+ ```
55
+
56
+ ## Global Options
57
+
58
+ - `--profile <name>`
59
+ - `--base-url <url>`
60
+ - `--api-key <token>`
61
+ - `--read-only`
62
+ - `--example <command path>`
63
+ - `--json`
64
+
65
+ ## JSON Contract
66
+
67
+ Successful commands emit:
68
+
69
+ ```json
70
+ {
71
+ "data": {},
72
+ "meta": {}
73
+ }
74
+ ```
75
+
76
+ Failing commands emit:
77
+
78
+ ```json
79
+ {
80
+ "error": {},
81
+ "meta": {}
82
+ }
83
+ ```
84
+
85
+ ## Quick Examples
86
+
87
+ ```bash
88
+ zinkee profiles list
89
+ zinkee --json config validate
90
+ zinkee --json schemas list
91
+ zinkee --json schemas get tareas
92
+ zinkee --json records list contacts --limit 50 --offset 0
93
+ zinkee --json records query contacts --where "status eq active"
94
+ zinkee --json files storage
95
+ zinkee --json automations list
96
+ zinkee --example records query
97
+ zinkee --json --example automations create
98
+ zinkee --json --example automations trigger set
99
+ zinkee --json --example automations actions add
100
+ zinkee --json --example automations webhook set
101
+ zinkee --json --example automations connections create
102
+ ```
103
+
104
+ ## Automations
105
+
106
+ The `automations` group manages the full public automation surface:
107
+
108
+ - automation folders
109
+ - automation metadata
110
+ - triggers
111
+ - actions
112
+ - flow wiring
113
+ - webhook endpoint configuration
114
+ - plugins
115
+ - stored connections for HTTP actions
116
+
117
+ If you are scripting, prefer `--json`. If you are discovering the CLI, prefer `--example <command path>`.
118
+
119
+ ### Before You Start
120
+
121
+ - `automations create` requires `--name` and a valid trigger.
122
+ - For `record_created` and `record_changed`, `--trigger-schema` accepts a real schema UUID or schema slug from your workspace.
123
+ - For `record_changed`, every `--trigger-field` must be a real field UUID or field slug from that schema.
124
+ - `--condition` uses the format `<field:comparator:value>`.
125
+ - `--condition-json` accepts a full JSON condition object when you need structured `rawValue/source` entries.
126
+ - For record-based automation values, the CLI sends `{ rawValue, source }` objects to the API v2 contract.
127
+ - The `scheduled` trigger uses a six-field cron expression, for example `0 15 10 * * 1`.
128
+
129
+ Useful discovery commands:
130
+
131
+ ```bash
132
+ zinkee --json schemas list
133
+ zinkee --json schemas get <schema-uuid-or-slug>
134
+ zinkee --json schemas fields list <schema-uuid-or-slug>
135
+ zinkee --json automations plugins list
136
+ zinkee --json automations connections list
137
+ ```
138
+
139
+ ### Trigger Types
140
+
141
+ Valid trigger types are:
142
+
143
+ - `scheduled`
144
+ - `record_created`
145
+ - `record_changed`
146
+ - `webhook`
147
+
148
+ Minimal scheduled automation:
149
+
150
+ ```bash
151
+ zinkee --json automations create \
152
+ --name "Nightly invoice sync" \
153
+ --trigger-type scheduled \
154
+ --cron "0 15 10 * * 1"
155
+ ```
156
+
157
+ Record-created automation using a schema slug:
158
+
159
+ ```bash
160
+ zinkee --json automations create \
161
+ --name "Lead welcome" \
162
+ --trigger-type record_created \
163
+ --trigger-schema leads
164
+ ```
165
+
166
+ Record-changed automation using schema and field slugs:
167
+
168
+ ```bash
169
+ zinkee --json automations create \
170
+ --name "Order status sync" \
171
+ --trigger-type record_changed \
172
+ --trigger-schema orders \
173
+ --trigger-field status
174
+ ```
175
+
176
+ Replace the trigger on an existing automation:
177
+
178
+ ```bash
179
+ zinkee --json automations trigger set automation-1 \
180
+ --trigger-type record_changed \
181
+ --trigger-schema orders \
182
+ --trigger-field status
183
+ ```
184
+
185
+ Add trigger conditions:
186
+
187
+ ```bash
188
+ zinkee --json automations trigger set automation-1 \
189
+ --trigger-type record_changed \
190
+ --trigger-schema orders \
191
+ --trigger-field status \
192
+ --condition status:eq:approved
193
+ ```
194
+
195
+ For `record_created` and `record_changed`, trigger conditions are always sent as literal values under the new `{ rawValue, source }` shape. Trigger conditions do not support `source`.
196
+
197
+ ### Actions
198
+
199
+ Valid action types are:
200
+
201
+ - `create_record`
202
+ - `update_record`
203
+ - `search_records`
204
+ - `send_message`
205
+ - `http_request`
206
+ - `execute_plugin`
207
+
208
+ Notes:
209
+
210
+ - `schema` references inside `automations` are standardized to accept either a UUID or a slug.
211
+ - `field` references inside `automations` are standardized to accept either a UUID or a slug.
212
+ - `pluginId` for `execute_plugin` must be an active plugin id from `zinkee --json automations plugins list`.
213
+
214
+ Create-record action:
215
+
216
+ ```bash
217
+ zinkee --json automations actions add automation-1 \
218
+ --type create_record \
219
+ --name "Create follow-up" \
220
+ --target-schema followups \
221
+ --map status=pending \
222
+ --map-json owner='{"rawValue":null,"source":{"type":"TRIGGER","id":"payload_value"}}'
223
+ ```
224
+
225
+ The CLI wraps `--map field=value` literals as:
226
+
227
+ ```json
228
+ {
229
+ "rawValue": "value",
230
+ "source": null
231
+ }
232
+ ```
233
+
234
+ For source-based values, pass the full object through `--map-json`. Valid `source.type` values are `TRIGGER` and `PREVIOUS_ACTION`.
235
+
236
+ Search-records action with a trigger-based condition:
237
+
238
+ ```bash
239
+ zinkee --json automations actions add automation-1 \
240
+ --type search_records \
241
+ --name "Find duplicates" \
242
+ --target-schema followups \
243
+ --condition-json '{"field":"email","comparator":"eq","values":[{"rawValue":null,"source":{"type":"TRIGGER","id":"payload_value"}}]}'
244
+ ```
245
+
246
+ Update-record action using the trigger record:
247
+
248
+ ```bash
249
+ zinkee --json automations actions add automation-1 \
250
+ --type update_record \
251
+ --name "Update trigger record" \
252
+ --target-schema followups \
253
+ --map status=ready \
254
+ --use-trigger-record
255
+ ```
256
+
257
+ When `--use-trigger-record` is enabled, the CLI does not send `conditions`.
258
+
259
+ HTTP request action:
260
+
261
+ ```bash
262
+ zinkee --json automations actions add automation-1 \
263
+ --type http_request \
264
+ --name "Notify ERP" \
265
+ --method POST \
266
+ --url https://example.com/integrations/order-status \
267
+ --header X-Demo=cli \
268
+ --body '{"event":"order.status.changed"}' \
269
+ --content-type application/json \
270
+ --timeout-ms 5000
271
+ ```
272
+
273
+ HTTP request action with stored auth:
274
+
275
+ ```bash
276
+ zinkee --json automations actions add automation-1 \
277
+ --type http_request \
278
+ --name "Notify ERP" \
279
+ --method POST \
280
+ --url https://example.com/integrations/order-status \
281
+ --content-type application/json \
282
+ --auth-mode STORED \
283
+ --connection 550e8400-e29b-41d4-a716-446655440001
284
+ ```
285
+
286
+ Execute-plugin action:
287
+
288
+ ```bash
289
+ zinkee --json automations actions add automation-1 \
290
+ --type execute_plugin \
291
+ --name "Run plugin" \
292
+ --plugin clone-budget \
293
+ --arg mode=safe \
294
+ --arg-json payload='{"dryRun":true}'
295
+ ```
296
+
297
+ Update an existing action:
298
+
299
+ ```bash
300
+ zinkee --json automations actions update automation-1 action-1 \
301
+ --type update_record \
302
+ --name "Update trigger record" \
303
+ --target-schema followups \
304
+ --map status=ready \
305
+ --use-trigger-record
306
+ ```
307
+
308
+ ### Flow Wiring
309
+
310
+ Use `flow set` after you have action ids:
311
+
312
+ ```bash
313
+ zinkee --json automations flow set automation-1 \
314
+ --entry action-1 \
315
+ --transition action-1:action-2 \
316
+ --transition action-2:action-3
317
+ ```
318
+
319
+ The resulting payload uses:
320
+
321
+ - `entryActionIds`
322
+ - `transitions[].fromActionId`
323
+ - `transitions[].toActionId`
324
+
325
+ ### Webhook Automations
326
+
327
+ The webhook endpoint configuration is a separate resource from the trigger itself.
328
+
329
+ Configure webhook ingestion for an automation:
330
+
331
+ ```bash
332
+ zinkee --json automations webhook set automation-1 \
333
+ --active \
334
+ --idempotency-key-path "$.id" \
335
+ --event-type-path "$.type" \
336
+ --allowed-event-type frontend.demo.created \
337
+ --field-mapping '{"variable":"external_id","jsonPath":"$.data.id"}'
338
+ ```
339
+
340
+ Read the generated endpoint details:
341
+
342
+ ```bash
343
+ zinkee --json automations webhook get automation-1
344
+ ```
345
+
346
+ If you want the automation trigger itself to be webhook-based:
347
+
348
+ ```bash
349
+ zinkee --json automations trigger set automation-1 --trigger-type webhook
350
+ ```
351
+
352
+ ### Stored Connections
353
+
354
+ Create a stored connection for `http_request` actions:
355
+
356
+ ```bash
357
+ zinkee --json automations connections create \
358
+ --name "ERP API Key" \
359
+ --type api_key \
360
+ --scope workspace \
361
+ --config '{"headerName":"Authorization"}' \
362
+ --secret apiKey=super-secret \
363
+ --active
364
+ ```
365
+
366
+ Patch a stored connection:
367
+
368
+ ```bash
369
+ zinkee --json automations connections update connection-1 \
370
+ --raw '{"set":{"name":"ERP API Key Updated","config":{"headerName":"Authorization"}}}'
371
+ ```
372
+
373
+ ### Patching Automations
374
+
375
+ `automations update` uses the backend patch contract with `set` and `unset`.
376
+
377
+ ```bash
378
+ zinkee --json automations update automation-1 \
379
+ --raw '{"set":{"description":"Updated by CLI docs"},"unset":["folderId"]}'
380
+ ```
381
+
382
+ Supported metadata patch paths:
383
+
384
+ - `name`
385
+ - `description`
386
+ - `folderId`
387
+
388
+ ### Troubleshooting
389
+
390
+ - `Automation payload is invalid` during create usually means the trigger is missing or malformed.
391
+ - `scheduled` is the correct trigger type, not `schedule`.
392
+ - Use a six-field cron expression for `scheduled`.
393
+ - `record_changed` requires at least one `--trigger-field`.
394
+ - Record-based triggers only work with real schema and field UUIDs or slugs from your workspace.
395
+ - `zinkee --json --example automations <subcommand>` returns canonical command recipes without executing the command.
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+
4
+ interface CommandIo {
5
+ write(chunk: string): unknown;
6
+ }
7
+ interface BuildProgramOptions {
8
+ configPath?: string;
9
+ stdout?: CommandIo;
10
+ }
11
+ declare function buildProgram(options?: BuildProgramOptions): Command;
12
+
13
+ export { type BuildProgramOptions, buildProgram };