@zeyos/cli 0.1.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.
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Resource registry — maps CLI resource names to ZeyOS API operation IDs
3
+ * and defines sensible defaults for display fields.
4
+ *
5
+ * Naming rules
6
+ * - Singular OR plural accepted (ticket / tickets)
7
+ * - Case-insensitive
8
+ * - Common aliases supported
9
+ */
10
+
11
+ // ── Registry ─────────────────────────────────────────────────────────────────
12
+
13
+ /** @typedef {import('./types.mjs').ResourceDef} ResourceDef */
14
+
15
+ /** @type {Record<string, ResourceDef>} */
16
+ const REGISTRY = {
17
+ ticket: {
18
+ list: 'listTickets',
19
+ get: 'getTicket',
20
+ create: 'createTicket',
21
+ update: 'updateTicket',
22
+ delete: 'deleteTicket',
23
+ fields: ['ID', 'ticketnum', 'name', 'status', 'priority', 'duedate', 'lastmodified'],
24
+ },
25
+ task: {
26
+ list: 'listTasks',
27
+ get: 'getTask',
28
+ create: 'createTask',
29
+ update: 'updateTask',
30
+ delete: 'deleteTask',
31
+ fields: ['ID', 'tasknum', 'name', 'status', 'priority', 'duedate', 'ticket'],
32
+ },
33
+ account: {
34
+ list: 'listAccounts',
35
+ get: 'getAccount',
36
+ create: 'createAccount',
37
+ update: 'updateAccount',
38
+ delete: 'deleteAccount',
39
+ fields: ['ID', 'customernum', 'lastname', 'firstname', 'type', 'assigneduser', 'lastmodified'],
40
+ },
41
+ contact: {
42
+ list: 'listContacts',
43
+ get: 'getContact',
44
+ create: 'createContact',
45
+ update: 'updateContact',
46
+ delete: 'deleteContact',
47
+ fields: ['ID', 'firstname', 'lastname', 'email', 'phone', 'account'],
48
+ },
49
+ project: {
50
+ list: 'listProjects',
51
+ get: 'getProject',
52
+ create: 'createProject',
53
+ update: 'updateProject',
54
+ delete: 'deleteProject',
55
+ fields: ['ID', 'projectnum', 'name', 'status', 'assigneduser', 'lastmodified'],
56
+ },
57
+ appointment: {
58
+ list: 'listAppointments',
59
+ get: 'getAppointment',
60
+ create: 'createAppointment',
61
+ update: 'updateAppointment',
62
+ delete: 'deleteAppointment',
63
+ fields: ['ID', 'name', 'startdate', 'enddate', 'location'],
64
+ },
65
+ document: {
66
+ list: 'listDocuments',
67
+ get: 'getDocument',
68
+ create: 'createDocument',
69
+ update: 'updateDocument',
70
+ delete: 'deleteDocument',
71
+ fields: ['ID', 'name', 'doctype', 'docnum', 'account', 'date', 'nettotal'],
72
+ },
73
+ note: {
74
+ list: 'listNotes',
75
+ get: 'getNote',
76
+ create: 'createNote',
77
+ update: 'updateNote',
78
+ delete: 'deleteNote',
79
+ fields: ['ID', 'name', 'text', 'created'],
80
+ },
81
+ message: {
82
+ list: 'listMessages',
83
+ get: 'getMessage',
84
+ create: 'createMessage',
85
+ update: 'updateMessage',
86
+ delete: 'deleteMessage',
87
+ fields: ['ID', 'subject', 'sender', 'created', 'read'],
88
+ },
89
+ item: {
90
+ list: 'listItems',
91
+ get: 'getItem',
92
+ create: 'createItem',
93
+ update: 'updateItem',
94
+ delete: 'deleteItem',
95
+ fields: ['ID', 'itemnum', 'name', 'manufacturer', 'type', 'sellingprice', 'purchaseprice'],
96
+ },
97
+ user: {
98
+ list: 'listUsers',
99
+ get: 'getUser',
100
+ fields: ['ID', 'name', 'email', 'role', 'active'],
101
+ },
102
+ group: {
103
+ list: 'listGroups',
104
+ get: 'getGroup',
105
+ fields: ['ID', 'name', 'description'],
106
+ },
107
+ event: {
108
+ list: 'listEvents',
109
+ get: 'getEvent',
110
+ create: 'createEvent',
111
+ update: 'updateEvent',
112
+ delete: 'deleteEvent',
113
+ fields: ['ID', 'name', 'type', 'created', 'account'],
114
+ },
115
+ transaction: {
116
+ list: 'listTransactions',
117
+ get: 'getTransaction',
118
+ create: 'createTransaction',
119
+ update: 'updateTransaction',
120
+ delete: 'deleteTransaction',
121
+ fields: ['ID', 'name', 'amount', 'date', 'account'],
122
+ },
123
+ payment: {
124
+ list: 'listPayments',
125
+ get: 'getPayment',
126
+ create: 'createPayment',
127
+ update: 'updatePayment',
128
+ delete: 'deletePayment',
129
+ fields: ['ID', 'amount', 'date', 'method', 'transaction'],
130
+ },
131
+ opportunity: {
132
+ list: 'listOpportunities',
133
+ get: 'getOpportunity',
134
+ create: 'createOpportunity',
135
+ update: 'updateOpportunity',
136
+ delete: 'deleteOpportunity',
137
+ fields: ['ID', 'name', 'status', 'probability', 'amount', 'account'],
138
+ },
139
+ campaign: {
140
+ list: 'listCampaigns',
141
+ get: 'getCampaign',
142
+ create: 'createCampaign',
143
+ update: 'updateCampaign',
144
+ delete: 'deleteCampaign',
145
+ fields: ['ID', 'name', 'status', 'startdate', 'enddate'],
146
+ },
147
+ file: {
148
+ list: 'listFiles',
149
+ get: 'getFile',
150
+ create: 'createFile',
151
+ update: 'updateFile',
152
+ delete: 'deleteFile',
153
+ fields: ['ID', 'name', 'mimetype', 'filesize', 'created'],
154
+ },
155
+ invitation: {
156
+ list: 'listInvitations',
157
+ get: 'getInvitation',
158
+ create: 'createInvitation',
159
+ update: 'updateInvitation',
160
+ delete: 'deleteInvitation',
161
+ fields: ['ID', 'email', 'status', 'created'],
162
+ },
163
+ storage: {
164
+ list: 'listStorages',
165
+ get: 'getStorage',
166
+ create: 'createStorage',
167
+ update: 'updateStorage',
168
+ delete: 'deleteStorage',
169
+ fields: ['ID', 'name', 'type', 'capacity'],
170
+ },
171
+ };
172
+
173
+ // ── Aliases ───────────────────────────────────────────────────────────────────
174
+
175
+ const ALIASES = {
176
+ // Plurals
177
+ tickets: 'ticket',
178
+ tasks: 'task',
179
+ accounts: 'account',
180
+ contacts: 'contact',
181
+ projects: 'project',
182
+ appointments: 'appointment',
183
+ documents: 'document',
184
+ doc: 'document',
185
+ docs: 'document',
186
+ notes: 'note',
187
+ messages: 'message',
188
+ items: 'item',
189
+ users: 'user',
190
+ groups: 'group',
191
+ events: 'event',
192
+ transactions: 'transaction',
193
+ payments: 'payment',
194
+ opportunities:'opportunity',
195
+ campaigns: 'campaign',
196
+ files: 'file',
197
+ invitations: 'invitation',
198
+ storages: 'storage',
199
+ // Colloquials
200
+ invoice: 'document',
201
+ invoices: 'document',
202
+ crm: 'account',
203
+ lead: 'opportunity',
204
+ leads: 'opportunity',
205
+ };
206
+
207
+ // ── Lookup ────────────────────────────────────────────────────────────────────
208
+
209
+ /**
210
+ * Resolve a CLI resource name to a ResourceDef.
211
+ * Returns undefined if not found.
212
+ *
213
+ * @param {string} name - e.g. "ticket", "tickets", "TICKET"
214
+ * @returns {ResourceDef|undefined}
215
+ */
216
+ export function resolveResource(name) {
217
+ const lower = name.toLowerCase();
218
+ const canonical = ALIASES[lower] ?? lower;
219
+ return REGISTRY[canonical];
220
+ }
221
+
222
+ /**
223
+ * Return the canonical resource name for a given input.
224
+ * Returns undefined if not found.
225
+ */
226
+ export function canonicalName(name) {
227
+ const lower = name.toLowerCase();
228
+ return ALIASES[lower] ?? (REGISTRY[lower] ? lower : undefined);
229
+ }
230
+
231
+ /** Return a sorted list of all canonical resource names. */
232
+ export function listResources() {
233
+ return Object.keys(REGISTRY).sort();
234
+ }
package/lib/types.mjs ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Shared JSDoc-only shapes for the CLI resource registry and field config.
3
+ * This file intentionally has no runtime exports beyond being an ESM module.
4
+ */
5
+
6
+ /**
7
+ * @typedef {null|boolean|number|string|JsonValue[]|Record<string, JsonValue>} JsonValue
8
+ * @typedef {Record<string, JsonValue>} JsonObject
9
+ * @typedef {JsonObject} CliConfig
10
+ * @typedef {(value: JsonValue, row: JsonObject) => string|number|boolean|null|undefined} ValueFormatter
11
+ */
12
+
13
+ /**
14
+ * @typedef {{
15
+ * list: string,
16
+ * get: string,
17
+ * create?: string,
18
+ * update?: string,
19
+ * delete?: string,
20
+ * fields: string[],
21
+ * idField?: string
22
+ * }} ResourceDef
23
+ */
24
+
25
+ /**
26
+ * @typedef {{
27
+ * apiFields: Record<string,string>|undefined,
28
+ * displayColumns: string[]
29
+ * }} ListFieldSelection
30
+ */
31
+
32
+ /**
33
+ * @typedef {{
34
+ * keys: string[],
35
+ * labels: Record<string,string>
36
+ * }} GetFieldSelection
37
+ */
38
+
39
+ /**
40
+ * @typedef {{
41
+ * list?: { fields?: Record<string,string> },
42
+ * get?: { fields?: string[], params?: Record<string, number|string|boolean> }
43
+ * }} ResourceFieldConfig
44
+ */
45
+
46
+ export {};
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@zeyos/cli",
3
+ "version": "0.1.1",
4
+ "description": "Command-line interface for the ZeyOS API",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Peter Haider <peter.haider@zeyos.com>",
8
+ "homepage": "https://github.com/zeyos/client/tree/main/cli#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/zeyos/client.git",
12
+ "directory": "cli"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/zeyos/client/issues"
16
+ },
17
+ "keywords": [
18
+ "zeyos",
19
+ "cli",
20
+ "erp",
21
+ "crm",
22
+ "api"
23
+ ],
24
+ "bin": {
25
+ "zeyos": "bin/zeyos.mjs"
26
+ },
27
+ "exports": {
28
+ ".": "./bin/zeyos.mjs"
29
+ },
30
+ "files": [
31
+ "bin",
32
+ "commands",
33
+ "config",
34
+ "lib",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "engines": {
39
+ "node": ">=18.3"
40
+ },
41
+ "dependencies": {
42
+ "@zeyos/client": "^0.1.0"
43
+ },
44
+ "scripts": {
45
+ "test": "node --test test/offline.mjs"
46
+ }
47
+ }