@tolinax/ayoune-cli 2026.2.0 → 2026.2.1

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 (3) hide show
  1. package/index.js +11 -0
  2. package/package.json +1 -1
  3. package/README.md +0 -505
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ #! /usr/bin/env node
2
+ import { Command } from "commander";
3
+ import { createSpinner } from "nanospinner";
4
+ import { initializeSettings } from "./lib/helpers/initializeSettings.js";
5
+ import { createProgram } from "./lib/commands/createProgram.js";
6
+ //Create new command instance
7
+ const program = new Command();
8
+ initializeSettings();
9
+ //Setup spinner - output to stderr so stdout stays clean for piping
10
+ export const spinner = createSpinner("Getting data...", { stream: process.stderr });
11
+ createProgram(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolinax/ayoune-cli",
3
- "version": "2026.2.0",
3
+ "version": "2026.2.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/README.md DELETED
@@ -1,505 +0,0 @@
1
- # @tolinax/ayoune-cli
2
-
3
- ```
4
- __ ______ _ _
5
- \ \ / / __ \| | | |
6
- __ \ \_/ / | | | | | |_ __ ___
7
- / _` \ /| | | | | | | '_ \ / _ \
8
- | (_| || | | |__| | |__| | | | | __/
9
- \__,_||_| \____/ \____/|_| |_|\___|
10
- ```
11
-
12
- The official CLI for the **aYOUne Business-as-a-Service** platform. Manage your business modules, collections, and entries directly from the terminal.
13
-
14
- ## Installation
15
-
16
- ```bash
17
- npm install -g @tolinax/ayoune-cli
18
- ```
19
-
20
- After installation, the `ay` command is available globally. On first run, the CLI will guide you through authentication automatically.
21
-
22
- ## Quick Start
23
-
24
- ```bash
25
- # Browse modules interactively
26
- ay modules
27
-
28
- # Jump straight to a module and collection
29
- ay m crm consumers
30
-
31
- # List entries in a collection
32
- ay list contacts
33
-
34
- # Fetch all pages at once
35
- ay list contacts --all
36
-
37
- # Filter output with JMESPath
38
- ay list products --jq '[].{name: name, price: price}'
39
-
40
- # Show who you're logged in as
41
- ay whoami
42
- ```
43
-
44
- ## Commands
45
-
46
- ### Data Commands
47
-
48
- | Command | Alias | Description |
49
- |---------|-------|-------------|
50
- | `ay list [collection]` | `l` | List entries in a collection with pagination |
51
- | `ay get [collection]` | `g` | Retrieve entries with field selection |
52
- | `ay create [collection] [name]` | `c` | Create a new entry |
53
- | `ay edit [collection] [id]` | `e` | Edit an entry by ID |
54
- | `ay copy [collection] [id]` | `cp` | Duplicate an entry |
55
- | `ay describe [collection] [id]` | `d` | Show a detailed YAML description of an entry |
56
- | `ay audit [collection] [id]` | `history` | View the change history of an entry |
57
-
58
- ### Real-Time Commands
59
-
60
- | Command | Alias | Description |
61
- |---------|-------|-------------|
62
- | `ay stream` | `listen` | Subscribe to real-time data changes via WebSocket |
63
- | `ay events` | `sub` | Subscribe to filtered events via WebSocket |
64
-
65
- ### Auth & Session Commands
66
-
67
- | Command | Alias | Description |
68
- |---------|-------|-------------|
69
- | `ay login` | `auth` | Authenticate via browser-based login |
70
- | `ay logout` | `signout` | Clear stored credentials |
71
- | `ay whoami` | `who` | Display the currently authenticated user |
72
- | `ay storage` | `s` | Display stored session data and preferences |
73
-
74
- ### Utility Commands
75
-
76
- | Command | Alias | Description |
77
- |---------|-------|-------------|
78
- | `ay modules [module] [collection]` | `m` | Browse modules interactively, or jump to a specific module/collection |
79
- | `ay completions <shell>` | `completion` | Generate shell completion script |
80
- | `ay alias` | | Manage custom command aliases |
81
-
82
- ## Global Options
83
-
84
- These options are available on all commands:
85
-
86
- | Option | Description | Default |
87
- |--------|-------------|---------|
88
- | `-r, --responseFormat <format>` | Output format: `json`, `csv`, `yaml`, `table` | `json` |
89
- | `-v, --verbosity <level>` | Meta info level: `default`, `extended`, `minimal` | `default` |
90
- | `-m, --hideMeta` | Return only payload, no meta information | `false` |
91
- | `-s, --save` | Save the response to a file | |
92
- | `-d, --debug` | Show detailed request/response information | |
93
- | `-o, --outPath [filePath]` | Output directory for saved files | `~/aYOUne` |
94
- | `-n, --name [fileName]` | Custom filename for saved output | |
95
- | `-q, --quiet` | Suppress all output except errors and results | |
96
- | `--force` | Skip confirmation prompts for destructive actions | |
97
- | `--dry-run` | Preview what a mutating command would do without executing | |
98
- | `--jq <expression>` | Filter JSON output using a JMESPath expression | |
99
- | `--columns <fields>` | Comma-separated list of columns to display | |
100
- | `--no-color` | Disable colored output | |
101
-
102
- ## Usage Examples
103
-
104
- ### Listing and Querying
105
-
106
- ```bash
107
- # List contacts, page 2, 50 per page
108
- ay list contacts -p 2 -l 50
109
-
110
- # Fetch all pages automatically
111
- ay list contacts --all
112
-
113
- # Get products as YAML and save to file
114
- ay get products -r yaml -s
115
-
116
- # Get only specific fields from orders
117
- ay get orders -i status total customerName
118
-
119
- # List invoices as CSV
120
- ay list invoices -r csv
121
- ```
122
-
123
- ### Filtering Output
124
-
125
- ```bash
126
- # Extract just names using JMESPath
127
- ay list contacts --jq '[].name'
128
-
129
- # Filter to entries matching a condition
130
- ay list products --jq "[?price > \`100\`]"
131
-
132
- # Show only specific columns
133
- ay list contacts --columns name,email,phone
134
-
135
- # Combine columns and JMESPath
136
- ay list orders --columns status,total --jq '[?status == `open`]'
137
- ```
138
-
139
- ### Entry Operations
140
-
141
- ```bash
142
- # Create a new contact
143
- ay create contacts "John Doe"
144
-
145
- # Edit a contact by ID
146
- ay edit contacts 64a1b2c3d4e5
147
-
148
- # Copy (duplicate) an entry
149
- ay copy contacts 64a1b2c3d4e5
150
-
151
- # Describe an entry in YAML format
152
- ay describe contacts 64a1b2c3d4e5
153
-
154
- # View audit history
155
- ay audit contacts 64a1b2c3d4e5
156
- ```
157
-
158
- ### Interactive Module Browser
159
-
160
- ```bash
161
- # Start the interactive module browser
162
- ay modules
163
-
164
- # Jump directly to a module
165
- ay m crm
166
-
167
- # Jump directly to a module and collection
168
- ay m crm consumers
169
- ```
170
-
171
- Module and collection arguments accept both slugs and labels (e.g., `crm` or `customer relationship management`).
172
-
173
- When browsing interactively, entries are displayed with searchable names. The following actions are available on any entry:
174
-
175
- - **describe** - View full YAML representation
176
- - **edit** - Edit fields interactively
177
- - **edit raw** - Edit the raw response
178
- - **download** - Save the entry to a file
179
- - **copy** - Duplicate the entry
180
- - **delete** - Delete the entry (with confirmation, or skip with `--force`)
181
-
182
- ### Real-Time Streams
183
-
184
- ```bash
185
- # Stream all data changes as JSON
186
- ay stream
187
-
188
- # Stream changes in YAML format
189
- ay stream -f yaml
190
-
191
- # Listen to all events
192
- ay events
193
-
194
- # Filter events by category and action
195
- ay events -c sales -a create
196
-
197
- # Subscribe to CRM events as YAML
198
- ay events -f yaml -c crm
199
- ```
200
-
201
- ### Debug Mode
202
-
203
- ```bash
204
- # Show full request/response details
205
- ay list contacts --debug
206
-
207
- # Combine with other options
208
- ay m crm consumers --debug
209
- ```
210
-
211
- Debug mode displays the HTTP method, URL, query params, auth token (truncated), response status, timing, and response body for every API call.
212
-
213
- ### Dry Run
214
-
215
- ```bash
216
- # Preview what a delete would do without executing
217
- ay modules --dry-run
218
- # Navigate to an entry, select "delete" → shows the request that would be sent
219
-
220
- # Works with any mutating operation (create, edit, copy, delete)
221
- ```
222
-
223
- ### Quiet Mode and Piping
224
-
225
- The spinner outputs to `stderr`, so `stdout` stays clean for piping even without `--quiet`:
226
-
227
- ```bash
228
- # Pipe JSON output to jq
229
- ay list contacts | jq '.[].name'
230
-
231
- # Suppress spinner entirely for scripting
232
- ay list contacts -q | jq '.[].name'
233
-
234
- # Pipe CSV output to a file
235
- ay get products -r csv -q > products.csv
236
-
237
- # Use in shell scripts with proper exit codes
238
- ay get orders -q || echo "Failed with exit code $?"
239
- ```
240
-
241
- ### Force Mode
242
-
243
- ```bash
244
- # Delete without confirmation prompt
245
- ay modules --force
246
- # Navigate to entry, select delete → no confirmation asked
247
- ```
248
-
249
- ## Authentication
250
-
251
- aYOUne CLI uses browser-based authentication:
252
-
253
- 1. Run `ay login` (or just run any command — first-run onboarding will trigger login automatically)
254
- 2. A clickable URL is displayed in the terminal, and a browser window opens with the aYOUne login page
255
- 3. After successful login, the CLI receives a token via WebSocket
256
- 4. Tokens are stored locally at `~/.aYOUne/storage/`
257
-
258
- Sessions persist across CLI invocations. When a session expires (HTTP 401), the CLI automatically re-authenticates and retries the request.
259
-
260
- ## Configuration
261
-
262
- ### Environment Variables
263
-
264
- | Variable | Description | Default |
265
- |----------|-------------|---------|
266
- | `AYOUNE_AUDIT_URL` | Audit service URL | `https://audit.ayoune.app` |
267
- | `AYOUNE_NOTIFIER_URL` | Notifier/WebSocket URL | `https://notifier.ayoune.app` |
268
- | `AYOUNE_LOGIN_URL` | Browser login URL | `https://login.ayoune.app` |
269
- | `AYOUNE_VERSION` | CLI version sent as `ref` param | Auto-detected |
270
- | `NO_COLOR` | Disable colored output (see [no-color.org](https://no-color.org)) | |
271
-
272
- ### API Routing
273
-
274
- Each module has its own API endpoint following the pattern `https://{module}-api.ayoune.app`. For example:
275
- - CRM → `https://crm-api.ayoune.app`
276
- - Accounting → `https://accounting-api.ayoune.app`
277
-
278
- Services (audit, notifier, login) use their own dedicated domains.
279
-
280
- ### Config File
281
-
282
- Create a config file at one of these locations (checked in order):
283
-
284
- - `~/.config/ayoune/config.json`
285
- - `~/.ayounerc`
286
-
287
- ```json
288
- {
289
- "profile": "production",
290
- "profiles": {
291
- "production": {
292
- "auditUrl": "https://audit.ayoune.app",
293
- "notifierUrl": "https://notifier.ayoune.app",
294
- "loginUrl": "https://login.ayoune.app"
295
- },
296
- "staging": {
297
- "auditUrl": "https://staging-audit.ayoune.app",
298
- "notifierUrl": "https://staging-notifier.ayoune.app",
299
- "loginUrl": "https://staging-login.ayoune.app"
300
- }
301
- },
302
- "defaults": {
303
- "responseFormat": "json",
304
- "verbosity": "default",
305
- "outPath": "~/my-exports"
306
- }
307
- }
308
- ```
309
-
310
- ### Rate Limiting
311
-
312
- The CLI automatically handles rate limits (HTTP 429). When rate-limited:
313
- 1. If the server sends a `Retry-After` header, the CLI waits the specified duration
314
- 2. Otherwise, it uses exponential backoff (1s, 2s, 4s)
315
- 3. Up to 3 retries are attempted before failing
316
-
317
- Network errors and server errors (5xx) are also retried automatically.
318
-
319
- ## Shell Completions
320
-
321
- Enable tab-completion for commands and options:
322
-
323
- ```bash
324
- # Bash
325
- ay completions bash >> ~/.bashrc
326
-
327
- # Zsh
328
- ay completions zsh >> ~/.zshrc
329
-
330
- # Fish
331
- ay completions fish > ~/.config/fish/completions/ay.fish
332
-
333
- # PowerShell
334
- ay completions powershell >> $PROFILE
335
- ```
336
-
337
- Restart your shell after adding completions.
338
-
339
- ## Custom Aliases
340
-
341
- Create shortcuts for frequently used commands:
342
-
343
- ```bash
344
- # Create an alias
345
- ay alias set ll "list leads"
346
- ay alias set gp "get products -r yaml"
347
-
348
- # Use it
349
- ay ll # Runs: ay list leads
350
- ay gp # Runs: ay get products -r yaml
351
-
352
- # List all aliases
353
- ay alias list
354
-
355
- # Remove an alias
356
- ay alias remove ll
357
- ```
358
-
359
- Aliases are stored in `~/.config/ayoune/aliases.json`.
360
-
361
- ## Supported Modules
362
-
363
- The aYOUne platform provides the following business modules:
364
-
365
- | Module | Slug | API Endpoint |
366
- |--------|------|--------------|
367
- | Artificial Intelligence | `ai` | `ai-api.ayoune.app` |
368
- | Asset Store | `assetstore` | `assetstore-api.ayoune.app` |
369
- | Customer Relationship Management | `crm` | `crm-api.ayoune.app` |
370
- | Project Management | `pm` | `pm-api.ayoune.app` |
371
- | Content Management System | `cms` | `cms-api.ayoune.app` |
372
- | Marketing | `marketing` | `marketing-api.ayoune.app` |
373
- | Automation | `automation` | `automation-api.ayoune.app` |
374
- | Sale | `sale` | `sale-api.ayoune.app` |
375
- | Product Information Management | `pim` | `pim-api.ayoune.app` |
376
- | Hub | `hub` | `hub-api.ayoune.app` |
377
- | Human Resources | `hr` | `hr-api.ayoune.app` |
378
- | Service Desk | `service` | `service-api.ayoune.app` |
379
- | Purchase | `purchase` | `purchase-api.ayoune.app` |
380
- | Accounting | `accounting` | `accounting-api.ayoune.app` |
381
- | E-Commerce | `ecommerce` | `ecommerce-api.ayoune.app` |
382
- | Monitoring | `monitoring` | `monitoring-api.ayoune.app` |
383
- | Research | `research` | `research-api.ayoune.app` |
384
- | Production | `production` | `production-api.ayoune.app` |
385
- | Affiliate | `affiliate` | `affiliate-api.ayoune.app` |
386
- | Reporting | `reporting` | `reporting-api.ayoune.app` |
387
- | Export | `export` | `export-api.ayoune.app` |
388
- | Configuration | `config` | `config-api.ayoune.app` |
389
- | Audit | `audit` | `audit-api.ayoune.app` |
390
-
391
- ## Exit Codes
392
-
393
- The CLI uses standard exit codes for scripting compatibility:
394
-
395
- | Code | Meaning |
396
- |------|---------|
397
- | `0` | Success |
398
- | `1` | General error |
399
- | `2` | Misuse (missing arguments, non-interactive terminal) |
400
- | `4` | Authentication required (session expired) |
401
- | `5` | Permission denied (insufficient rights) |
402
- | `6` | Configuration error |
403
-
404
- ## Local Storage
405
-
406
- The CLI persists session data and context at `~/.aYOUne/storage/`:
407
-
408
- | Key | Description |
409
- |-----|-------------|
410
- | `token` | JWT access token |
411
- | `refreshToken` | Refresh token for re-authentication |
412
- | `lastModule` | Last used module slug |
413
- | `lastCollection` | Last used collection name |
414
- | `lastId` | Last used entry ID |
415
-
416
- Commands like `edit`, `copy`, `describe`, and `audit` default to the last used collection and ID when arguments are omitted.
417
-
418
- ## Development
419
-
420
- ### Prerequisites
421
-
422
- - Node.js >= 18
423
- - npm >= 9
424
-
425
- ### Setup
426
-
427
- ```bash
428
- git clone git@bitbucket.org:ayoune/ayoune-cli.git
429
- cd ayoune-cli
430
- npm install
431
- ```
432
-
433
- ### Scripts
434
-
435
- ```bash
436
- npm run build # Clean dist/, compile TypeScript, copy package.json
437
- npm run test # Run tests with Vitest
438
- npm run test:watch # Run tests in watch mode
439
- npm run lint # Lint source with ESLint
440
- npm run format # Format source with Prettier
441
- npm run format:check # Check formatting without writing
442
- npm run release # Bump version, generate changelog, tag, push, publish
443
- ```
444
-
445
- ### Project Structure
446
-
447
- ```
448
- src/
449
- index.ts # Entry point, spinner (stderr), program init
450
- data/
451
- modules.ts # Business module definitions
452
- services.ts # External service definitions
453
- operations.ts # Available operations (list, get)
454
- defaultActions.ts # Entry actions (edit, delete, copy, ...)
455
- modelsAndRights.ts # Collection-to-rights mapping
456
- lib/
457
- types.ts # Shared TypeScript interfaces
458
- exitCodes.ts # Exit code constants
459
- commands/
460
- createProgram.ts # Root program, global options, command wiring
461
- create{Name}Command.ts # Command factory per subcommand
462
- operations/
463
- handle{Name}Operation.ts # Business logic per operation
464
- prompts/
465
- prompt{Name}.ts # Interactive prompt helpers
466
- api/
467
- apiClient.ts # Axios instance with retry & rate limit handling
468
- apiCallHandler.ts # API call wrapper with auth & dry-run
469
- auditCallHandler.ts # Audit API call wrapper
470
- handleAPIError.ts # Centralized error handler
471
- login.ts # WebSocket-based auth flow
472
- helpers/
473
- config.ts # Environment-based configuration
474
- handleResponseFormatOptions.ts # Output formatter with JMESPath & column filtering
475
- localStorage.ts # File-based persistent storage
476
- saveFile.ts # File output handler
477
- initializeSettings.ts # Inquirer plugin registration
478
- models/
479
- getModuleFromCollection.ts # Collection-to-module resolver
480
- getModelsInModules.ts # Models-per-module lookup
481
- getCollections.ts # All collection names
482
- socket/
483
- customerSocketClient.ts # Socket.IO client for real-time
484
- ```
485
-
486
- ### Architecture
487
-
488
- - **Command Factory Pattern**: Each command is defined in `create{Name}Command.ts` and registered in `createProgram.ts`
489
- - **Operation Handlers**: Business logic lives in `handle{Name}Operation.ts`, keeping commands thin
490
- - **Prompt Helpers**: Interactive prompts are encapsulated in `prompt{Name}.ts` using Inquirer with searchable entry selection
491
- - **API Layer**: Per-module routing (`{module}-api.ayoune.app`), Axios with 3 retries, automatic Bearer token attachment, 401 auto-re-login, rate limit handling, centralized error handling
492
- - **Output Formatting**: All API responses pass through `handleResponseFormatOptions` for consistent JSON/YAML/CSV/table output with optional JMESPath and column filtering
493
- - **Non-Interactive Support**: TTY detection skips prompts and requires explicit arguments when piped
494
- - **Piping-Safe**: Spinner outputs to `stderr`, data to `stdout`
495
-
496
- ### Conventions
497
-
498
- - **Imports**: Use `.js` extensions in import paths (required for ESM output)
499
- - **Commit Messages**: Follow [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `chore:`, etc.)
500
- - **TypeScript**: `strict: false`, target ES2018, ESNext modules
501
- - **Interfaces**: Use `I` prefix (e.g., `ICommandOptions`, `IApiResponse`)
502
-
503
- ## License
504
-
505
- ISC