@helm-ai/cli 0.15.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.
- package/README.md +158 -0
- package/dist/cli.js +3990 -0
- package/package.json +50 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,3990 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import kleur8 from "kleur";
|
|
6
|
+
|
|
7
|
+
// src/lib/branding.ts
|
|
8
|
+
import kleur from "kleur";
|
|
9
|
+
var SPLASH = ` \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557
|
|
10
|
+
\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551
|
|
11
|
+
\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551
|
|
12
|
+
\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551
|
|
13
|
+
\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551
|
|
14
|
+
\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D`;
|
|
15
|
+
function renderSplash(ctx) {
|
|
16
|
+
if (!process.stdout.isTTY) return "";
|
|
17
|
+
const tagline = ` AI operations platform \xB7 v${ctx.version}`;
|
|
18
|
+
const ident = ctx.user || ctx.workspace ? ` ${[ctx.user, ctx.workspace].filter(Boolean).join(" \xB7 ")}` : "";
|
|
19
|
+
return [
|
|
20
|
+
kleur.cyan(SPLASH),
|
|
21
|
+
kleur.gray(tagline),
|
|
22
|
+
ident && kleur.gray(ident),
|
|
23
|
+
""
|
|
24
|
+
].filter(Boolean).join("\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/version.ts
|
|
28
|
+
var version = "0.15.0";
|
|
29
|
+
|
|
30
|
+
// src/commands/auth.ts
|
|
31
|
+
import prompts from "prompts";
|
|
32
|
+
import kleur3 from "kleur";
|
|
33
|
+
|
|
34
|
+
// src/lib/errors.ts
|
|
35
|
+
import kleur2 from "kleur";
|
|
36
|
+
var HelmError = class extends Error {
|
|
37
|
+
constructor(message, cause) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.cause = cause;
|
|
40
|
+
this.name = "HelmError";
|
|
41
|
+
}
|
|
42
|
+
cause;
|
|
43
|
+
};
|
|
44
|
+
var HelmAuthError = class extends HelmError {
|
|
45
|
+
constructor(message = "Authentication failed. Run `helm-ai login` to set your API key.") {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "HelmAuthError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var HelmPlanLimitError = class extends HelmError {
|
|
51
|
+
constructor(resource, current, max) {
|
|
52
|
+
super(`Plan limit reached for ${resource}: ${current}/${max}. Upgrade at https://gethelm.ai/pricing`);
|
|
53
|
+
this.resource = resource;
|
|
54
|
+
this.current = current;
|
|
55
|
+
this.max = max;
|
|
56
|
+
this.name = "HelmPlanLimitError";
|
|
57
|
+
}
|
|
58
|
+
resource;
|
|
59
|
+
current;
|
|
60
|
+
max;
|
|
61
|
+
};
|
|
62
|
+
var HelmModuleDisabledError = class extends HelmError {
|
|
63
|
+
constructor(module) {
|
|
64
|
+
super(`The ${module.replace("_", " ")} module is disabled for this workspace.`);
|
|
65
|
+
this.module = module;
|
|
66
|
+
this.name = "HelmModuleDisabledError";
|
|
67
|
+
}
|
|
68
|
+
module;
|
|
69
|
+
};
|
|
70
|
+
var HelmValidationError = class extends HelmError {
|
|
71
|
+
constructor(message) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = "HelmValidationError";
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var HelmNetworkError = class extends HelmError {
|
|
77
|
+
constructor(message, cause) {
|
|
78
|
+
super(message, cause);
|
|
79
|
+
this.name = "HelmNetworkError";
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
function parseApiError(status, body) {
|
|
83
|
+
const errMsg = body?.error || body?.message || `Request failed with status ${status}`;
|
|
84
|
+
if (status === 401 || status === 403) {
|
|
85
|
+
return new HelmAuthError(errMsg);
|
|
86
|
+
}
|
|
87
|
+
const planLimitMatch = errMsg.match(/^PLAN_LIMIT:(\w+):(\d+):(\d+)/);
|
|
88
|
+
if (planLimitMatch) {
|
|
89
|
+
return new HelmPlanLimitError(
|
|
90
|
+
planLimitMatch[1],
|
|
91
|
+
parseInt(planLimitMatch[2], 10),
|
|
92
|
+
parseInt(planLimitMatch[3], 10)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const moduleMatch = errMsg.match(/^The (\w+) module is disabled/i);
|
|
96
|
+
if (moduleMatch) {
|
|
97
|
+
return new HelmModuleDisabledError(moduleMatch[1]);
|
|
98
|
+
}
|
|
99
|
+
if (status >= 400 && status < 500) {
|
|
100
|
+
return new HelmValidationError(errMsg);
|
|
101
|
+
}
|
|
102
|
+
return new HelmError(errMsg);
|
|
103
|
+
}
|
|
104
|
+
function formatErrorForCli(err) {
|
|
105
|
+
if (err instanceof HelmError) {
|
|
106
|
+
return kleur2.red(`\u2717 ${err.message}`);
|
|
107
|
+
}
|
|
108
|
+
if (err instanceof Error) {
|
|
109
|
+
return kleur2.red(`\u2717 ${err.message}`);
|
|
110
|
+
}
|
|
111
|
+
return kleur2.red(`\u2717 ${String(err)}`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/lib/client.ts
|
|
115
|
+
function sleep(ms) {
|
|
116
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
117
|
+
}
|
|
118
|
+
function parseRetryAfter(header) {
|
|
119
|
+
if (!header) return 5e3;
|
|
120
|
+
const seconds = parseInt(header, 10);
|
|
121
|
+
if (!isNaN(seconds) && seconds > 0) return Math.min(seconds * 1e3, 6e4);
|
|
122
|
+
const date = Date.parse(header);
|
|
123
|
+
if (!isNaN(date)) return Math.min(Math.max(0, date - Date.now()), 6e4);
|
|
124
|
+
return 5e3;
|
|
125
|
+
}
|
|
126
|
+
var HelmClient = class _HelmClient {
|
|
127
|
+
constructor(opts) {
|
|
128
|
+
this.opts = opts;
|
|
129
|
+
}
|
|
130
|
+
opts;
|
|
131
|
+
static fromProfile(profile) {
|
|
132
|
+
return new _HelmClient({
|
|
133
|
+
apiUrl: profile.apiUrl,
|
|
134
|
+
apiKey: profile.apiKey,
|
|
135
|
+
supabaseAnonKey: profile.supabaseAnonKey
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async request(action, method, payload, options = {}) {
|
|
139
|
+
const url = new URL(`${this.opts.apiUrl}/mcp`);
|
|
140
|
+
url.searchParams.set("action", action);
|
|
141
|
+
if (method === "GET" && payload) {
|
|
142
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
143
|
+
if (value !== void 0 && value !== null) {
|
|
144
|
+
url.searchParams.set(key, String(value));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const headers = {
|
|
149
|
+
Authorization: `Bearer ${this.opts.supabaseAnonKey}`,
|
|
150
|
+
apikey: this.opts.supabaseAnonKey,
|
|
151
|
+
"X-Helm-API-Key": this.opts.apiKey,
|
|
152
|
+
"Content-Type": "application/json"
|
|
153
|
+
};
|
|
154
|
+
const maxAttempts = options.retries ?? 5;
|
|
155
|
+
let delay = 500;
|
|
156
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
157
|
+
let response;
|
|
158
|
+
try {
|
|
159
|
+
response = await fetch(url.toString(), {
|
|
160
|
+
method,
|
|
161
|
+
headers,
|
|
162
|
+
body: method === "POST" && payload ? JSON.stringify(payload) : void 0
|
|
163
|
+
});
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (err instanceof TypeError && attempt < maxAttempts) {
|
|
166
|
+
await sleep(delay);
|
|
167
|
+
delay = Math.min(delay * 2, 3e4);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
throw new HelmNetworkError(
|
|
171
|
+
`Network error reaching ${this.opts.apiUrl}: ${err.message}`,
|
|
172
|
+
err
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
const isRetryable = response.status === 429 || response.status >= 500 && response.status < 600;
|
|
176
|
+
if (isRetryable && attempt < maxAttempts) {
|
|
177
|
+
const wait = response.status === 429 ? parseRetryAfter(response.headers.get("Retry-After")) : delay;
|
|
178
|
+
await sleep(wait);
|
|
179
|
+
delay = Math.min(delay * 2, 3e4);
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const data = await response.json().catch(() => ({}));
|
|
183
|
+
if (!response.ok || data.success === false) {
|
|
184
|
+
throw parseApiError(response.status, data);
|
|
185
|
+
}
|
|
186
|
+
return data;
|
|
187
|
+
}
|
|
188
|
+
throw new HelmNetworkError(`Request failed after ${maxAttempts} attempts (action=${action})`);
|
|
189
|
+
}
|
|
190
|
+
modules = {
|
|
191
|
+
get: async () => {
|
|
192
|
+
const data = await this.request("get_module_settings", "GET");
|
|
193
|
+
return data.modules ?? {};
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
projects = {
|
|
197
|
+
list: async () => {
|
|
198
|
+
const data = await this.request("get_projects", "GET");
|
|
199
|
+
return data.projects ?? [];
|
|
200
|
+
},
|
|
201
|
+
create: async (input) => {
|
|
202
|
+
const data = await this.request("create_project", "POST", input);
|
|
203
|
+
return data.project;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
tasks = {
|
|
207
|
+
list: async (filters = {}) => {
|
|
208
|
+
const data = await this.request("get_tasks", "GET", filters);
|
|
209
|
+
return data.tasks ?? [];
|
|
210
|
+
},
|
|
211
|
+
get: async (taskId) => {
|
|
212
|
+
const data = await this.request("get_task", "GET", { task_id: taskId });
|
|
213
|
+
return data.task;
|
|
214
|
+
},
|
|
215
|
+
create: async (input) => {
|
|
216
|
+
const data = await this.request("add_task", "POST", input);
|
|
217
|
+
if (data.task) return data.task;
|
|
218
|
+
const { task_id, task_display_id, message: _msg, ...rest } = data;
|
|
219
|
+
return { id: task_id, visible_id: task_display_id, ...rest };
|
|
220
|
+
},
|
|
221
|
+
update: async (taskId, input) => {
|
|
222
|
+
const data = await this.request("update_task", "POST", { task_id: taskId, ...input });
|
|
223
|
+
return data.task;
|
|
224
|
+
},
|
|
225
|
+
addComment: async (taskId, content, attachments) => {
|
|
226
|
+
const data = await this.request("add_task_comment", "POST", { task_id: taskId, content, attachments });
|
|
227
|
+
return data.comment;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
attachments = {
|
|
231
|
+
/** Upload a file (base64) to the task-attachments bucket; returns metadata to attach. */
|
|
232
|
+
upload: async (input) => {
|
|
233
|
+
const data = await this.request("upload_attachment", "POST", input);
|
|
234
|
+
return data.attachment;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
accounts = {
|
|
238
|
+
list: async (filters = {}) => {
|
|
239
|
+
const data = await this.request("get_accounts", "GET", filters);
|
|
240
|
+
return data.accounts ?? [];
|
|
241
|
+
},
|
|
242
|
+
get: async (accountId) => {
|
|
243
|
+
const data = await this.request("get_account", "GET", { account_id: accountId });
|
|
244
|
+
return data.account;
|
|
245
|
+
},
|
|
246
|
+
create: async (input) => {
|
|
247
|
+
const data = await this.request("add_account", "POST", input);
|
|
248
|
+
return data.account;
|
|
249
|
+
},
|
|
250
|
+
update: async (accountId, input) => {
|
|
251
|
+
const data = await this.request("update_account", "POST", { account_id: accountId, ...input });
|
|
252
|
+
return data.account;
|
|
253
|
+
},
|
|
254
|
+
// Page through every account (the server caps a single response at ~1000 rows).
|
|
255
|
+
listAll: async (filters = {}) => {
|
|
256
|
+
const pageSize = 1e3;
|
|
257
|
+
const all = [];
|
|
258
|
+
for (let offset = 0; ; offset += pageSize) {
|
|
259
|
+
const page = await this.accounts.list({ ...filters, limit: pageSize, offset });
|
|
260
|
+
all.push(...page);
|
|
261
|
+
if (page.length < pageSize) break;
|
|
262
|
+
}
|
|
263
|
+
return all;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
contacts = {
|
|
267
|
+
list: async (filters = {}) => {
|
|
268
|
+
const data = await this.request("get_contacts", "GET", filters);
|
|
269
|
+
return data.contacts ?? [];
|
|
270
|
+
},
|
|
271
|
+
get: async (contactId) => {
|
|
272
|
+
const data = await this.request("get_contact", "GET", { contact_id: contactId });
|
|
273
|
+
return data.contact;
|
|
274
|
+
},
|
|
275
|
+
create: async (input) => {
|
|
276
|
+
const data = await this.request("add_contact", "POST", input);
|
|
277
|
+
return data.contact;
|
|
278
|
+
},
|
|
279
|
+
update: async (contactId, input) => {
|
|
280
|
+
const data = await this.request("update_contact", "POST", { contact_id: contactId, ...input });
|
|
281
|
+
return data.contact;
|
|
282
|
+
},
|
|
283
|
+
delete: async (contactId) => {
|
|
284
|
+
await this.request("delete_contact", "POST", { contact_id: contactId });
|
|
285
|
+
},
|
|
286
|
+
// Page through every contact (the server caps a single response at ~1000 rows).
|
|
287
|
+
listAll: async (filters = {}) => {
|
|
288
|
+
const pageSize = 1e3;
|
|
289
|
+
const all = [];
|
|
290
|
+
for (let offset = 0; ; offset += pageSize) {
|
|
291
|
+
const page = await this.contacts.list({ ...filters, limit: pageSize, offset });
|
|
292
|
+
all.push(...page);
|
|
293
|
+
if (page.length < pageSize) break;
|
|
294
|
+
}
|
|
295
|
+
return all;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
deals = {
|
|
299
|
+
list: async (filters = {}) => {
|
|
300
|
+
const data = await this.request("get_deals", "GET", filters);
|
|
301
|
+
return data.deals ?? [];
|
|
302
|
+
},
|
|
303
|
+
get: async (dealId) => {
|
|
304
|
+
const data = await this.request("get_deal", "GET", { deal_id: dealId });
|
|
305
|
+
return data.deal;
|
|
306
|
+
},
|
|
307
|
+
create: async (input) => {
|
|
308
|
+
const data = await this.request("add_deal", "POST", input);
|
|
309
|
+
return data.deal;
|
|
310
|
+
},
|
|
311
|
+
update: async (dealId, input) => {
|
|
312
|
+
const data = await this.request("update_deal", "POST", { deal_id: dealId, ...input });
|
|
313
|
+
return data.deal;
|
|
314
|
+
},
|
|
315
|
+
delete: async (dealId) => {
|
|
316
|
+
await this.request("delete_deal", "POST", { deal_id: dealId });
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
pipelines = {
|
|
320
|
+
list: async () => {
|
|
321
|
+
const data = await this.request("get_pipelines", "GET");
|
|
322
|
+
return data.pipelines ?? [];
|
|
323
|
+
},
|
|
324
|
+
create: async (input) => {
|
|
325
|
+
const data = await this.request("add_pipeline", "POST", input);
|
|
326
|
+
return data.pipeline;
|
|
327
|
+
},
|
|
328
|
+
update: async (pipelineId, input) => {
|
|
329
|
+
const data = await this.request("update_pipeline", "POST", { pipeline_id: pipelineId, ...input });
|
|
330
|
+
return data.pipeline;
|
|
331
|
+
},
|
|
332
|
+
delete: async (pipelineId, reassignToPipelineId) => {
|
|
333
|
+
await this.request("delete_pipeline", "POST", {
|
|
334
|
+
pipeline_id: pipelineId,
|
|
335
|
+
reassign_to_pipeline_id: reassignToPipelineId
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
addStage: async (input) => {
|
|
339
|
+
const data = await this.request("add_pipeline_stage", "POST", input);
|
|
340
|
+
return data.stage;
|
|
341
|
+
},
|
|
342
|
+
updateStage: async (stageId, input) => {
|
|
343
|
+
const data = await this.request("update_pipeline_stage", "POST", { stage_id: stageId, ...input });
|
|
344
|
+
return data.stage;
|
|
345
|
+
},
|
|
346
|
+
deleteStage: async (stageId) => {
|
|
347
|
+
await this.request("delete_pipeline_stage", "POST", { stage_id: stageId });
|
|
348
|
+
},
|
|
349
|
+
reorderStages: async (pipelineId, stageIds) => {
|
|
350
|
+
const data = await this.request("reorder_pipeline_stages", "POST", {
|
|
351
|
+
pipeline_id: pipelineId,
|
|
352
|
+
stage_ids: stageIds
|
|
353
|
+
});
|
|
354
|
+
return data.pipeline;
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
timeEntries = {
|
|
358
|
+
list: async (filters = {}) => {
|
|
359
|
+
const data = await this.request("get_time_entries", "GET", filters);
|
|
360
|
+
return data.time_entries ?? [];
|
|
361
|
+
},
|
|
362
|
+
create: async (input) => {
|
|
363
|
+
const data = await this.request("create_time_entry", "POST", input);
|
|
364
|
+
return data.time_entry;
|
|
365
|
+
},
|
|
366
|
+
update: async (timeEntryId, input) => {
|
|
367
|
+
const data = await this.request("update_time_entry", "POST", {
|
|
368
|
+
time_entry_id: timeEntryId,
|
|
369
|
+
...input
|
|
370
|
+
});
|
|
371
|
+
return data.time_entry;
|
|
372
|
+
},
|
|
373
|
+
delete: async (timeEntryId) => {
|
|
374
|
+
await this.request("delete_time_entry", "POST", { time_entry_id: timeEntryId });
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
invoices = {
|
|
378
|
+
list: async (filters = {}) => {
|
|
379
|
+
const data = await this.request("get_invoices", "GET", filters);
|
|
380
|
+
return data.invoices ?? [];
|
|
381
|
+
},
|
|
382
|
+
get: async (invoiceId) => {
|
|
383
|
+
const data = await this.request("get_invoice", "GET", { invoice_id: invoiceId });
|
|
384
|
+
return data.invoice;
|
|
385
|
+
},
|
|
386
|
+
create: async (input) => {
|
|
387
|
+
const data = await this.request("create_invoice", "POST", input);
|
|
388
|
+
return data.invoice;
|
|
389
|
+
},
|
|
390
|
+
update: async (invoiceId, input) => {
|
|
391
|
+
const data = await this.request("update_invoice", "POST", { invoice_id: invoiceId, ...input });
|
|
392
|
+
return data.invoice;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
estimates = {
|
|
396
|
+
list: async (filters = {}) => {
|
|
397
|
+
const data = await this.request("get_estimates", "GET", filters);
|
|
398
|
+
return data.estimates ?? [];
|
|
399
|
+
},
|
|
400
|
+
create: async (input) => {
|
|
401
|
+
const data = await this.request("create_estimate", "POST", input);
|
|
402
|
+
return data.estimate;
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
products = {
|
|
406
|
+
list: async (filters = {}) => {
|
|
407
|
+
const data = await this.request("list_products", "GET", filters);
|
|
408
|
+
return data.products ?? [];
|
|
409
|
+
},
|
|
410
|
+
get: async (idOrName) => {
|
|
411
|
+
const data = await this.request("get_product", "GET", idOrName);
|
|
412
|
+
return data;
|
|
413
|
+
},
|
|
414
|
+
create: async (input) => {
|
|
415
|
+
const data = await this.request("create_product", "POST", input);
|
|
416
|
+
return data.product;
|
|
417
|
+
},
|
|
418
|
+
update: async (input) => {
|
|
419
|
+
const data = await this.request("update_product", "POST", input);
|
|
420
|
+
return data.product;
|
|
421
|
+
},
|
|
422
|
+
archive: async (input) => {
|
|
423
|
+
const data = await this.request("archive_product", "POST", input);
|
|
424
|
+
return data;
|
|
425
|
+
},
|
|
426
|
+
attachToDeal: async (input) => {
|
|
427
|
+
return await this.request("attach_product_to_deal", "POST", input);
|
|
428
|
+
},
|
|
429
|
+
addLineItem: async (input) => {
|
|
430
|
+
return await this.request("add_line_item_from_product", "POST", input);
|
|
431
|
+
},
|
|
432
|
+
// Price tiers (e.g. Single Site / 5 Sites / Unlimited)
|
|
433
|
+
prices: {
|
|
434
|
+
list: async (productId) => {
|
|
435
|
+
const data = await this.request("list_product_prices", "GET", { product_id: productId });
|
|
436
|
+
return data.prices ?? [];
|
|
437
|
+
},
|
|
438
|
+
create: async (input) => {
|
|
439
|
+
const data = await this.request("create_product_price", "POST", input);
|
|
440
|
+
return data.price;
|
|
441
|
+
},
|
|
442
|
+
update: async (input) => {
|
|
443
|
+
const data = await this.request("update_product_price", "POST", input);
|
|
444
|
+
return data.price;
|
|
445
|
+
},
|
|
446
|
+
delete: async (priceId) => {
|
|
447
|
+
return await this.request("delete_product_price", "POST", { price_id: priceId });
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
accountProducts = {
|
|
452
|
+
list: async (accountId) => {
|
|
453
|
+
const data = await this.request("list_account_products", "GET", { account_id: accountId });
|
|
454
|
+
return {
|
|
455
|
+
rows: data.rows ?? [],
|
|
456
|
+
summary: data.summary
|
|
457
|
+
};
|
|
458
|
+
},
|
|
459
|
+
attach: async (input) => {
|
|
460
|
+
const data = await this.request("attach_product_to_account", "POST", input);
|
|
461
|
+
return data;
|
|
462
|
+
},
|
|
463
|
+
update: async (input) => {
|
|
464
|
+
return await this.request("update_account_product", "POST", input);
|
|
465
|
+
},
|
|
466
|
+
detach: async (accountProductId) => {
|
|
467
|
+
return await this.request("detach_product_from_account", "POST", { account_product_id: accountProductId });
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
calendar = {
|
|
471
|
+
list: async (filters = {}) => {
|
|
472
|
+
const data = await this.request("get_calendar_events", "GET", filters);
|
|
473
|
+
return data.calendar_events ?? [];
|
|
474
|
+
},
|
|
475
|
+
get: async (eventId) => {
|
|
476
|
+
const data = await this.request("get_calendar_event", "GET", { event_id: eventId });
|
|
477
|
+
return data.calendar_event;
|
|
478
|
+
},
|
|
479
|
+
create: async (input) => {
|
|
480
|
+
const data = await this.request("create_calendar_event", "POST", input);
|
|
481
|
+
return data.calendar_event;
|
|
482
|
+
},
|
|
483
|
+
delete: async (eventId) => {
|
|
484
|
+
await this.request("delete_calendar_event", "POST", { event_id: eventId });
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
templates = {
|
|
488
|
+
list: async () => {
|
|
489
|
+
const data = await this.request("list_program_templates", "GET");
|
|
490
|
+
return data.templates ?? [];
|
|
491
|
+
},
|
|
492
|
+
apply: async (input) => {
|
|
493
|
+
const data = await this.request("apply_program_template", "POST", input);
|
|
494
|
+
return data;
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
documents = {
|
|
498
|
+
list: async (filters = {}) => {
|
|
499
|
+
const data = await this.request("get_documents", "GET", filters);
|
|
500
|
+
return data.documents ?? [];
|
|
501
|
+
},
|
|
502
|
+
get: async (documentId) => {
|
|
503
|
+
const data = await this.request("get_document", "GET", { document_id: documentId });
|
|
504
|
+
return data.document;
|
|
505
|
+
},
|
|
506
|
+
create: async (input) => {
|
|
507
|
+
const data = await this.request("create_document", "POST", input);
|
|
508
|
+
if (data.document) return data.document;
|
|
509
|
+
const { document_id, message: _msg, ...rest } = data;
|
|
510
|
+
return { id: document_id, ...rest };
|
|
511
|
+
},
|
|
512
|
+
update: async (documentId, input) => {
|
|
513
|
+
const data = await this.request("update_document", "POST", { document_id: documentId, ...input });
|
|
514
|
+
if (data.document) return data.document;
|
|
515
|
+
const { document_id: id, message: _msg, ...rest } = data;
|
|
516
|
+
return { id, ...rest };
|
|
517
|
+
},
|
|
518
|
+
listPages: async (documentId) => {
|
|
519
|
+
const data = await this.request("get_document_pages", "GET", { document_id: documentId });
|
|
520
|
+
return data.pages ?? [];
|
|
521
|
+
},
|
|
522
|
+
createPage: async (documentId, input = {}) => {
|
|
523
|
+
const data = await this.request("create_document_page", "POST", { document_id: documentId, ...input });
|
|
524
|
+
if (data.page) return data.page;
|
|
525
|
+
const { page_id, message: _msg, ...rest } = data;
|
|
526
|
+
return { id: page_id, ...rest };
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
agentSchedules = {
|
|
530
|
+
list: async (agentId) => {
|
|
531
|
+
const data = await this.request("get_agent_schedules", "GET", agentId ? { agent_id: agentId } : void 0);
|
|
532
|
+
return data.schedules ?? [];
|
|
533
|
+
},
|
|
534
|
+
create: async (input) => {
|
|
535
|
+
const data = await this.request("create_agent_schedule", "POST", input);
|
|
536
|
+
return data.schedule;
|
|
537
|
+
},
|
|
538
|
+
update: async (scheduleId, input) => {
|
|
539
|
+
const data = await this.request("update_agent_schedule", "POST", { schedule_id: scheduleId, ...input });
|
|
540
|
+
return data.schedule;
|
|
541
|
+
},
|
|
542
|
+
delete: async (scheduleId) => {
|
|
543
|
+
await this.request("delete_agent_schedule", "POST", { schedule_id: scheduleId });
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
agentEmail = {
|
|
547
|
+
send: async (input) => {
|
|
548
|
+
const data = await this.request("agent_send_email", "POST", input);
|
|
549
|
+
if (data.error) {
|
|
550
|
+
const extra = Array.isArray(data.available_agents) && data.available_agents.length ? ` (available agents: ${data.available_agents.join(", ")})` : "";
|
|
551
|
+
throw new Error(`${data.message ?? data.error}${extra}`);
|
|
552
|
+
}
|
|
553
|
+
return data;
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
/** Mail from YOU, drafted by an assistant. Draft-only — there is no send here
|
|
557
|
+
* on purpose; approving the draft in the app is what sends it. */
|
|
558
|
+
email = {
|
|
559
|
+
listIdentities: async () => {
|
|
560
|
+
const data = await this.request("list_sender_identities", "GET");
|
|
561
|
+
return data.identities ?? [];
|
|
562
|
+
},
|
|
563
|
+
draft: async (input) => {
|
|
564
|
+
const data = await this.request("draft_email", "POST", input);
|
|
565
|
+
if (data.error) {
|
|
566
|
+
const extra = Array.isArray(data.available_identities) && data.available_identities.length ? ` (you can send from: ${data.available_identities.join(", ")})` : "";
|
|
567
|
+
throw new Error(`${data.message ?? data.error}${extra}`);
|
|
568
|
+
}
|
|
569
|
+
return data;
|
|
570
|
+
},
|
|
571
|
+
listDrafts: async (filters = {}) => {
|
|
572
|
+
const data = await this.request("list_drafts", "GET", filters);
|
|
573
|
+
if (data.error) throw new Error(data.message ?? data.error);
|
|
574
|
+
return data.drafts ?? [];
|
|
575
|
+
},
|
|
576
|
+
updateDraft: async (input) => {
|
|
577
|
+
const data = await this.request("update_draft", "POST", input);
|
|
578
|
+
if (data.error) {
|
|
579
|
+
const extra = Array.isArray(data.available_identities) && data.available_identities.length ? ` (you can send from: ${data.available_identities.join(", ")})` : "";
|
|
580
|
+
throw new Error(`${data.message ?? data.error}${extra}`);
|
|
581
|
+
}
|
|
582
|
+
return data.draft;
|
|
583
|
+
},
|
|
584
|
+
deleteDraft: async (draftId) => {
|
|
585
|
+
const data = await this.request("delete_draft", "POST", { draft_id: draftId });
|
|
586
|
+
if (data.error) throw new Error(data.message ?? data.error);
|
|
587
|
+
return data;
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
workflows = {
|
|
591
|
+
list: async (filters = {}) => {
|
|
592
|
+
const data = await this.request("get_workflows", "GET", filters);
|
|
593
|
+
return data.workflows ?? [];
|
|
594
|
+
},
|
|
595
|
+
get: async (workflowId) => {
|
|
596
|
+
const data = await this.request("get_workflow", "GET", { workflow_id: workflowId });
|
|
597
|
+
return data.workflow;
|
|
598
|
+
},
|
|
599
|
+
executions: async (workflowId, filters = {}) => {
|
|
600
|
+
const data = await this.request("get_workflow_executions", "GET", { workflow_id: workflowId, ...filters });
|
|
601
|
+
return data.executions ?? [];
|
|
602
|
+
},
|
|
603
|
+
setStatus: async (workflowId, status) => {
|
|
604
|
+
const data = await this.request("set_workflow_status", "POST", { workflow_id: workflowId, status });
|
|
605
|
+
return data.workflow;
|
|
606
|
+
},
|
|
607
|
+
run: async (workflowId, triggerData) => {
|
|
608
|
+
const data = await this.request("execute_workflow", "POST", { workflow_id: workflowId, trigger_data: triggerData });
|
|
609
|
+
return data;
|
|
610
|
+
},
|
|
611
|
+
schema: async () => {
|
|
612
|
+
const data = await this.request("get_workflow_schema", "GET");
|
|
613
|
+
return data.schema ?? data;
|
|
614
|
+
},
|
|
615
|
+
create: async (input) => {
|
|
616
|
+
const data = await this.request("create_workflow", "POST", input);
|
|
617
|
+
return data;
|
|
618
|
+
},
|
|
619
|
+
update: async (workflowId, input) => {
|
|
620
|
+
const data = await this.request("update_workflow", "POST", { workflow_id: workflowId, ...input });
|
|
621
|
+
return data;
|
|
622
|
+
},
|
|
623
|
+
delete: async (workflowId) => {
|
|
624
|
+
const data = await this.request("delete_workflow", "POST", { workflow_id: workflowId });
|
|
625
|
+
return data;
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
forms = {
|
|
629
|
+
list: async (filters = {}) => {
|
|
630
|
+
const data = await this.request("list_forms", "GET", filters);
|
|
631
|
+
return data.forms ?? [];
|
|
632
|
+
},
|
|
633
|
+
get: async (formId) => {
|
|
634
|
+
const data = await this.request("get_form", "GET", { form_id: formId });
|
|
635
|
+
return data.form;
|
|
636
|
+
},
|
|
637
|
+
submissions: async (formId, limit) => {
|
|
638
|
+
const data = await this.request("get_form_submissions", "GET", { form_id: formId, limit });
|
|
639
|
+
return data.submissions ?? [];
|
|
640
|
+
},
|
|
641
|
+
stats: async (formId) => {
|
|
642
|
+
const data = await this.request("get_form_stats", "GET", { form_id: formId });
|
|
643
|
+
return data.stats;
|
|
644
|
+
},
|
|
645
|
+
create: async (input) => {
|
|
646
|
+
const data = await this.request("create_form", "POST", input);
|
|
647
|
+
return data.form;
|
|
648
|
+
},
|
|
649
|
+
addStep: async (input) => {
|
|
650
|
+
const data = await this.request("add_form_step", "POST", input);
|
|
651
|
+
return data.step;
|
|
652
|
+
},
|
|
653
|
+
addField: async (input) => {
|
|
654
|
+
const data = await this.request("add_form_field", "POST", input);
|
|
655
|
+
return data.field;
|
|
656
|
+
},
|
|
657
|
+
setStatus: async (formId, status) => {
|
|
658
|
+
const data = await this.request("set_form_status", "POST", { form_id: formId, status });
|
|
659
|
+
return data.form;
|
|
660
|
+
},
|
|
661
|
+
updateField: async (fieldId, updates) => {
|
|
662
|
+
const data = await this.request("update_form_field", "POST", { field_id: fieldId, ...updates });
|
|
663
|
+
return data.field;
|
|
664
|
+
},
|
|
665
|
+
removeField: async (fieldId) => {
|
|
666
|
+
const data = await this.request("delete_form_field", "POST", { field_id: fieldId });
|
|
667
|
+
return data;
|
|
668
|
+
},
|
|
669
|
+
updateStep: async (stepId, updates) => {
|
|
670
|
+
const data = await this.request("update_form_step", "POST", { step_id: stepId, ...updates });
|
|
671
|
+
return data.step;
|
|
672
|
+
},
|
|
673
|
+
removeStep: async (stepId) => {
|
|
674
|
+
const data = await this.request("delete_form_step", "POST", { step_id: stepId });
|
|
675
|
+
return data;
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
sequences = {
|
|
679
|
+
list: async (filters = {}) => {
|
|
680
|
+
const data = await this.request("list_email_sequences", "GET", filters);
|
|
681
|
+
return data.sequences ?? [];
|
|
682
|
+
},
|
|
683
|
+
get: async (sequenceId) => {
|
|
684
|
+
const data = await this.request("get_sequence", "GET", { sequence_id: sequenceId });
|
|
685
|
+
const { success: _success, ...rest } = data;
|
|
686
|
+
return rest;
|
|
687
|
+
},
|
|
688
|
+
enroll: async (sequenceId, opts) => {
|
|
689
|
+
const data = await this.request("enroll_in_sequence", "POST", { sequence_id: sequenceId, ...opts });
|
|
690
|
+
return data;
|
|
691
|
+
},
|
|
692
|
+
create: async (input) => {
|
|
693
|
+
const data = await this.request("create_email_sequence", "POST", input);
|
|
694
|
+
return data.sequence;
|
|
695
|
+
},
|
|
696
|
+
addEmail: async (sequenceId, input) => {
|
|
697
|
+
const data = await this.request("create_sequence_email", "POST", { sequence_id: sequenceId, ...input });
|
|
698
|
+
return data.step;
|
|
699
|
+
},
|
|
700
|
+
enrollments: async (sequenceId, filters = {}) => {
|
|
701
|
+
const data = await this.request("list_sequence_enrollments", "GET", { sequence_id: sequenceId, ...filters });
|
|
702
|
+
return data.enrollments ?? [];
|
|
703
|
+
},
|
|
704
|
+
setStatus: async (sequenceId, status) => {
|
|
705
|
+
const data = await this.request("set_sequence_status", "POST", { sequence_id: sequenceId, status });
|
|
706
|
+
return data.sequence;
|
|
707
|
+
},
|
|
708
|
+
pauseEnrollment: async (enrollmentId) => {
|
|
709
|
+
const data = await this.request("pause_sequence_enrollment", "POST", { enrollment_id: enrollmentId });
|
|
710
|
+
return data.enrollment;
|
|
711
|
+
},
|
|
712
|
+
resumeEnrollment: async (enrollmentId) => {
|
|
713
|
+
const data = await this.request("resume_sequence_enrollment", "POST", { enrollment_id: enrollmentId });
|
|
714
|
+
return data.enrollment;
|
|
715
|
+
},
|
|
716
|
+
exitEnrollment: async (enrollmentId, reason) => {
|
|
717
|
+
const data = await this.request("exit_sequence_enrollment", "POST", { enrollment_id: enrollmentId, reason });
|
|
718
|
+
return data.enrollment;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
// src/lib/config.ts
|
|
724
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, chmodSync, statSync } from "fs";
|
|
725
|
+
import { homedir } from "os";
|
|
726
|
+
import { join, dirname, resolve } from "path";
|
|
727
|
+
import { parse, stringify } from "yaml";
|
|
728
|
+
import { z } from "zod";
|
|
729
|
+
var DEFAULT_API_URL = "https://api.gethelm.ai/functions/v1";
|
|
730
|
+
var DEFAULT_SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InJldmhucXd4b3ZvZmRnd292bG9xIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mzk4Mjg1ODEsImV4cCI6MjA1NTQwNDU4MX0.xePlF-hXLpS3I7jKDm5zLDxnff2-rN23lL5hfXiWmtw";
|
|
731
|
+
var ProfileSchema = z.object({
|
|
732
|
+
apiUrl: z.string().url().default(DEFAULT_API_URL),
|
|
733
|
+
apiKey: z.string().min(1),
|
|
734
|
+
supabaseAnonKey: z.string().default(DEFAULT_SUPABASE_ANON_KEY),
|
|
735
|
+
workspaceId: z.string().nullable().default(null),
|
|
736
|
+
defaultProjectId: z.string().nullable().default(null)
|
|
737
|
+
});
|
|
738
|
+
var ConfigSchema = z.object({
|
|
739
|
+
defaultProfile: z.string().default("default"),
|
|
740
|
+
profiles: z.record(z.string(), ProfileSchema).default({}),
|
|
741
|
+
splash: z.boolean().default(true)
|
|
742
|
+
});
|
|
743
|
+
var CONFIG_DIR = join(homedir(), ".helm");
|
|
744
|
+
var CONFIG_PATH = join(CONFIG_DIR, "config.yaml");
|
|
745
|
+
function readConfig() {
|
|
746
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
747
|
+
return ConfigSchema.parse({});
|
|
748
|
+
}
|
|
749
|
+
const raw = readFileSync(CONFIG_PATH, "utf8");
|
|
750
|
+
const parsed = parse(raw) ?? {};
|
|
751
|
+
return ConfigSchema.parse(parsed);
|
|
752
|
+
}
|
|
753
|
+
function writeConfig(config) {
|
|
754
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
755
|
+
mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
|
|
756
|
+
}
|
|
757
|
+
const yaml = stringify(config);
|
|
758
|
+
writeFileSync(CONFIG_PATH, yaml, { mode: 384 });
|
|
759
|
+
chmodSync(CONFIG_PATH, 384);
|
|
760
|
+
}
|
|
761
|
+
function resolveProfile(profileName) {
|
|
762
|
+
const config = readConfig();
|
|
763
|
+
let name;
|
|
764
|
+
let source;
|
|
765
|
+
let cwdFilePath;
|
|
766
|
+
if (profileName) {
|
|
767
|
+
name = profileName;
|
|
768
|
+
source = "flag";
|
|
769
|
+
} else if (process.env.HELM_PROFILE) {
|
|
770
|
+
name = process.env.HELM_PROFILE;
|
|
771
|
+
source = "env";
|
|
772
|
+
} else {
|
|
773
|
+
const found = findCwdProfile();
|
|
774
|
+
if (found) {
|
|
775
|
+
name = found.name;
|
|
776
|
+
source = "cwd-file";
|
|
777
|
+
cwdFilePath = found.path;
|
|
778
|
+
} else {
|
|
779
|
+
name = config.defaultProfile;
|
|
780
|
+
source = "default";
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const stored = config.profiles[name];
|
|
784
|
+
const apiKey = process.env.HELM_API_KEY ?? stored?.apiKey;
|
|
785
|
+
if (!apiKey) {
|
|
786
|
+
throw new Error(
|
|
787
|
+
`No API key found for profile "${name}". Run \`helm-ai login --profile ${name}\` or set HELM_API_KEY.`
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
return {
|
|
791
|
+
name,
|
|
792
|
+
source,
|
|
793
|
+
cwdFilePath,
|
|
794
|
+
apiUrl: process.env.HELM_API_URL ?? stored?.apiUrl ?? DEFAULT_API_URL,
|
|
795
|
+
apiKey,
|
|
796
|
+
supabaseAnonKey: stored?.supabaseAnonKey ?? DEFAULT_SUPABASE_ANON_KEY,
|
|
797
|
+
workspaceId: process.env.HELM_WORKSPACE_ID ?? stored?.workspaceId ?? null,
|
|
798
|
+
defaultProjectId: stored?.defaultProjectId ?? null
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
var CWD_CONFIG_FILENAME = ".helm";
|
|
802
|
+
function findCwdProfile(startDir = process.cwd()) {
|
|
803
|
+
const home = resolve(homedir());
|
|
804
|
+
let dir = resolve(startDir);
|
|
805
|
+
while (true) {
|
|
806
|
+
if (dir === home) break;
|
|
807
|
+
const candidate = join(dir, CWD_CONFIG_FILENAME);
|
|
808
|
+
if (existsSync(candidate)) {
|
|
809
|
+
try {
|
|
810
|
+
const s = statSync(candidate);
|
|
811
|
+
if (s.isFile()) {
|
|
812
|
+
const contents = readFileSync(candidate, "utf8");
|
|
813
|
+
const profile = parseCwdProfileFile(contents);
|
|
814
|
+
if (profile) return { name: profile, path: candidate };
|
|
815
|
+
}
|
|
816
|
+
} catch {
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
const parent = dirname(dir);
|
|
820
|
+
if (parent === dir) break;
|
|
821
|
+
dir = parent;
|
|
822
|
+
}
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
function parseCwdProfileFile(contents) {
|
|
826
|
+
for (const rawLine of contents.split(/\r?\n/)) {
|
|
827
|
+
const line = rawLine.trim();
|
|
828
|
+
if (!line || line.startsWith("#")) continue;
|
|
829
|
+
const eq = line.indexOf("=");
|
|
830
|
+
if (eq !== -1) {
|
|
831
|
+
const key = line.slice(0, eq).trim().toLowerCase();
|
|
832
|
+
if (key !== "profile") continue;
|
|
833
|
+
const value = line.slice(eq + 1).trim();
|
|
834
|
+
if (value) return value;
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
return line;
|
|
838
|
+
}
|
|
839
|
+
return null;
|
|
840
|
+
}
|
|
841
|
+
function setProfile(name, profile) {
|
|
842
|
+
const config = readConfig();
|
|
843
|
+
const existing = config.profiles[name];
|
|
844
|
+
config.profiles[name] = ProfileSchema.parse({
|
|
845
|
+
apiUrl: profile.apiUrl ?? existing?.apiUrl ?? DEFAULT_API_URL,
|
|
846
|
+
apiKey: profile.apiKey,
|
|
847
|
+
supabaseAnonKey: profile.supabaseAnonKey ?? existing?.supabaseAnonKey ?? DEFAULT_SUPABASE_ANON_KEY,
|
|
848
|
+
workspaceId: profile.workspaceId ?? existing?.workspaceId ?? null,
|
|
849
|
+
defaultProjectId: profile.defaultProjectId ?? existing?.defaultProjectId ?? null
|
|
850
|
+
});
|
|
851
|
+
if (!config.defaultProfile || config.defaultProfile === "default") {
|
|
852
|
+
config.defaultProfile = name;
|
|
853
|
+
}
|
|
854
|
+
writeConfig(config);
|
|
855
|
+
}
|
|
856
|
+
function deleteProfile(name) {
|
|
857
|
+
const config = readConfig();
|
|
858
|
+
delete config.profiles[name];
|
|
859
|
+
if (config.defaultProfile === name) {
|
|
860
|
+
config.defaultProfile = Object.keys(config.profiles)[0] || "default";
|
|
861
|
+
}
|
|
862
|
+
writeConfig(config);
|
|
863
|
+
}
|
|
864
|
+
function updateProfileField(name, field, value) {
|
|
865
|
+
const config = readConfig();
|
|
866
|
+
const existing = config.profiles[name];
|
|
867
|
+
if (!existing) {
|
|
868
|
+
throw new Error(`Profile "${name}" not found. Run \`helm-ai login\` first.`);
|
|
869
|
+
}
|
|
870
|
+
config.profiles[name] = { ...existing, [field]: value };
|
|
871
|
+
writeConfig(config);
|
|
872
|
+
}
|
|
873
|
+
function listProfiles() {
|
|
874
|
+
const config = readConfig();
|
|
875
|
+
return Object.entries(config.profiles).map(([name, profile]) => ({
|
|
876
|
+
name,
|
|
877
|
+
isDefault: name === config.defaultProfile,
|
|
878
|
+
apiUrl: profile.apiUrl,
|
|
879
|
+
apiKeyMasked: maskKey(profile.apiKey),
|
|
880
|
+
workspaceId: profile.workspaceId
|
|
881
|
+
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
882
|
+
}
|
|
883
|
+
function setDefaultProfile(name) {
|
|
884
|
+
const config = readConfig();
|
|
885
|
+
if (!config.profiles[name]) {
|
|
886
|
+
const available = Object.keys(config.profiles);
|
|
887
|
+
const hint = available.length ? `Available: ${available.join(", ")}.` : "No profiles saved yet \u2014 run `helm-ai login --profile <name>`.";
|
|
888
|
+
throw new Error(`Profile "${name}" not found. ${hint}`);
|
|
889
|
+
}
|
|
890
|
+
config.defaultProfile = name;
|
|
891
|
+
writeConfig(config);
|
|
892
|
+
}
|
|
893
|
+
function maskKey(key) {
|
|
894
|
+
if (key.length <= 12) return "***";
|
|
895
|
+
return `${key.slice(0, 8)}\u2026${key.slice(-4)}`;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// src/commands/auth.ts
|
|
899
|
+
function registerAuthCommands(parent) {
|
|
900
|
+
parent.command("login").description("Authenticate with Helm by saving an API key").option("-p, --profile <name>", "profile name to save under", "default").option("-k, --api-key <key>", "API key (skips interactive prompt)").option("--api-url <url>", "override API URL").action(async (opts) => {
|
|
901
|
+
try {
|
|
902
|
+
if (process.stdout.isTTY) {
|
|
903
|
+
process.stdout.write(renderSplash({ version }));
|
|
904
|
+
}
|
|
905
|
+
let apiKey = opts.apiKey;
|
|
906
|
+
if (!apiKey) {
|
|
907
|
+
const answers = await prompts({
|
|
908
|
+
type: "password",
|
|
909
|
+
name: "apiKey",
|
|
910
|
+
message: "Paste your Helm API key (Settings \u2192 Workspace \u2192 API Keys \u2192 Private Keys):",
|
|
911
|
+
validate: (v) => v && v.length > 8 ? true : "API key looks too short"
|
|
912
|
+
});
|
|
913
|
+
apiKey = answers.apiKey;
|
|
914
|
+
}
|
|
915
|
+
if (!apiKey) {
|
|
916
|
+
console.error(kleur3.red("\u2717 No API key provided."));
|
|
917
|
+
process.exitCode = 1;
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
setProfile(opts.profile, { apiKey, apiUrl: opts.apiUrl });
|
|
921
|
+
const profile = resolveProfile(opts.profile);
|
|
922
|
+
const client = HelmClient.fromProfile(profile);
|
|
923
|
+
const projects = await client.projects.list();
|
|
924
|
+
console.log(kleur3.green(`\u2713 Logged in to profile "${opts.profile}".`));
|
|
925
|
+
console.log(kleur3.gray(` ${projects.length} project(s) accessible.`));
|
|
926
|
+
console.log(kleur3.gray(` Config: ~/.helm/config.yaml`));
|
|
927
|
+
} catch (err) {
|
|
928
|
+
console.error(formatErrorForCli(err));
|
|
929
|
+
process.exitCode = 1;
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
parent.command("logout").description("Remove a stored profile").option("-p, --profile <name>", "profile to remove", "default").action((opts) => {
|
|
934
|
+
try {
|
|
935
|
+
deleteProfile(opts.profile);
|
|
936
|
+
console.log(kleur3.green(`\u2713 Removed profile "${opts.profile}".`));
|
|
937
|
+
} catch (err) {
|
|
938
|
+
console.error(formatErrorForCli(err));
|
|
939
|
+
process.exitCode = 1;
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
});
|
|
943
|
+
parent.command("whoami").description("Show the current profile and connection status").option("-p, --profile <name>", "profile to check").action(async (opts) => {
|
|
944
|
+
try {
|
|
945
|
+
const profile = resolveProfile(opts.profile);
|
|
946
|
+
const client = HelmClient.fromProfile(profile);
|
|
947
|
+
const projects = await client.projects.list();
|
|
948
|
+
const config = readConfig();
|
|
949
|
+
console.log(kleur3.cyan("Profile: ") + profile.name + (profile.name === config.defaultProfile ? kleur3.gray(" (default)") : ""));
|
|
950
|
+
console.log(kleur3.cyan("Source: ") + describeProfileSource(profile));
|
|
951
|
+
console.log(kleur3.cyan("API URL: ") + profile.apiUrl);
|
|
952
|
+
console.log(kleur3.cyan("API key: ") + maskKey(profile.apiKey));
|
|
953
|
+
console.log(kleur3.cyan("Workspace: ") + (profile.workspaceId ?? kleur3.gray("(not set)")));
|
|
954
|
+
console.log(kleur3.cyan("Projects: ") + `${projects.length} accessible`);
|
|
955
|
+
} catch (err) {
|
|
956
|
+
console.error(formatErrorForCli(err));
|
|
957
|
+
process.exitCode = 1;
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
function describeProfileSource(p) {
|
|
963
|
+
switch (p.source) {
|
|
964
|
+
case "flag":
|
|
965
|
+
return "--profile flag";
|
|
966
|
+
case "env":
|
|
967
|
+
return "HELM_PROFILE env var";
|
|
968
|
+
case "cwd-file":
|
|
969
|
+
return `.helm file (${p.cwdFilePath ?? "cwd"})`;
|
|
970
|
+
case "default":
|
|
971
|
+
return "default profile";
|
|
972
|
+
default:
|
|
973
|
+
return p.source;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
// src/commands/profile.ts
|
|
978
|
+
import kleur4 from "kleur";
|
|
979
|
+
|
|
980
|
+
// src/lib/output.ts
|
|
981
|
+
import Table from "cli-table3";
|
|
982
|
+
import { stringify as csvStringify } from "csv-stringify/sync";
|
|
983
|
+
import { stringify as yamlStringify } from "yaml";
|
|
984
|
+
function defaultFormat() {
|
|
985
|
+
return process.stdout.isTTY ? "table" : "json";
|
|
986
|
+
}
|
|
987
|
+
function render(data, columns, format = defaultFormat()) {
|
|
988
|
+
const rows = Array.isArray(data) ? data : [data];
|
|
989
|
+
switch (format) {
|
|
990
|
+
case "json":
|
|
991
|
+
return JSON.stringify(rows, null, 2);
|
|
992
|
+
case "ndjson":
|
|
993
|
+
return rows.map((r) => JSON.stringify(r)).join("\n");
|
|
994
|
+
case "yaml":
|
|
995
|
+
return yamlStringify(rows);
|
|
996
|
+
case "csv":
|
|
997
|
+
return csvStringify(rows.map((r) => columns.map((c) => formatValue(c.get(r)))), {
|
|
998
|
+
header: true,
|
|
999
|
+
columns: columns.map((c) => c.header)
|
|
1000
|
+
});
|
|
1001
|
+
case "table":
|
|
1002
|
+
return renderTable(rows, columns);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function renderTable(rows, columns) {
|
|
1006
|
+
if (rows.length === 0) {
|
|
1007
|
+
return "(no rows)";
|
|
1008
|
+
}
|
|
1009
|
+
const table = new Table({
|
|
1010
|
+
head: columns.map((c) => c.header),
|
|
1011
|
+
style: { head: ["cyan"], border: ["gray"] },
|
|
1012
|
+
wordWrap: true
|
|
1013
|
+
});
|
|
1014
|
+
for (const row of rows) {
|
|
1015
|
+
table.push(columns.map((c) => {
|
|
1016
|
+
const v = formatValue(c.get(row));
|
|
1017
|
+
return c.truncate && v.length > c.truncate ? v.slice(0, c.truncate - 1) + "\u2026" : v;
|
|
1018
|
+
}));
|
|
1019
|
+
}
|
|
1020
|
+
return table.toString();
|
|
1021
|
+
}
|
|
1022
|
+
function formatValue(v) {
|
|
1023
|
+
if (v === null || v === void 0) return "";
|
|
1024
|
+
if (typeof v === "string") return v;
|
|
1025
|
+
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
1026
|
+
if (v instanceof Date) return v.toISOString();
|
|
1027
|
+
return JSON.stringify(v);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// src/commands/profile.ts
|
|
1031
|
+
function registerProfileCommands(parent) {
|
|
1032
|
+
const profile = parent.command("profile").description("Manage CLI profiles (one per workspace)");
|
|
1033
|
+
profile.command("list").description("List saved profiles").option("-o, --output <format>", "output format: table | json | ndjson | csv | yaml").action((opts) => {
|
|
1034
|
+
try {
|
|
1035
|
+
const rows = listProfiles();
|
|
1036
|
+
if (rows.length === 0) {
|
|
1037
|
+
console.log(kleur4.gray("No profiles saved. Run `helm-ai login --profile <name>` to add one."));
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
const format = opts.output ?? defaultFormat();
|
|
1041
|
+
const text = render(rows, [
|
|
1042
|
+
{ header: "Default", get: (r) => r.isDefault ? "*" : "" },
|
|
1043
|
+
{ header: "Name", get: (r) => r.name },
|
|
1044
|
+
{ header: "Workspace", get: (r) => r.workspaceId ?? "" },
|
|
1045
|
+
{ header: "API key", get: (r) => r.apiKeyMasked },
|
|
1046
|
+
{ header: "API URL", get: (r) => r.apiUrl }
|
|
1047
|
+
], format);
|
|
1048
|
+
console.log(text);
|
|
1049
|
+
} catch (err) {
|
|
1050
|
+
console.error(formatErrorForCli(err));
|
|
1051
|
+
process.exitCode = 1;
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
profile.command("use <name>").description("Set the default profile").action((name) => {
|
|
1056
|
+
try {
|
|
1057
|
+
setDefaultProfile(name);
|
|
1058
|
+
console.log(kleur4.green(`\u2713 Default profile set to "${name}".`));
|
|
1059
|
+
} catch (err) {
|
|
1060
|
+
console.error(formatErrorForCli(err));
|
|
1061
|
+
process.exitCode = 1;
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
});
|
|
1065
|
+
profile.command("current").description("Show which profile would be used right now and why").action(() => {
|
|
1066
|
+
try {
|
|
1067
|
+
const resolved = resolveProfile();
|
|
1068
|
+
const reason = describeSource(resolved);
|
|
1069
|
+
console.log(kleur4.cyan("Profile: ") + resolved.name);
|
|
1070
|
+
console.log(kleur4.cyan("Source: ") + reason);
|
|
1071
|
+
if (resolved.cwdFilePath) {
|
|
1072
|
+
console.log(kleur4.cyan("From: ") + resolved.cwdFilePath);
|
|
1073
|
+
}
|
|
1074
|
+
} catch (err) {
|
|
1075
|
+
const found = findCwdProfile();
|
|
1076
|
+
if (found) {
|
|
1077
|
+
console.log(kleur4.yellow(`Found .helm at ${found.path} pointing to "${found.name}", but the profile isn't saved.`));
|
|
1078
|
+
console.log(kleur4.gray(`Run \`helm-ai login --profile ${found.name}\` to add it.`));
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
console.error(formatErrorForCli(err));
|
|
1082
|
+
process.exitCode = 1;
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
function describeSource(p) {
|
|
1088
|
+
switch (p.source) {
|
|
1089
|
+
case "flag":
|
|
1090
|
+
return "--profile flag";
|
|
1091
|
+
case "env":
|
|
1092
|
+
return "HELM_PROFILE env var";
|
|
1093
|
+
case "cwd-file":
|
|
1094
|
+
return `.helm file in cwd (${p.cwdFilePath ?? ""})`;
|
|
1095
|
+
case "default":
|
|
1096
|
+
return "default profile in ~/.helm/config.yaml";
|
|
1097
|
+
default:
|
|
1098
|
+
return p.source;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/commands/config.ts
|
|
1103
|
+
import kleur5 from "kleur";
|
|
1104
|
+
import { spawn } from "child_process";
|
|
1105
|
+
function registerConfigCommands(parent) {
|
|
1106
|
+
const cfg = parent.command("config").description("Manage CLI configuration");
|
|
1107
|
+
cfg.command("path").description("Print the config file path").action(() => console.log(CONFIG_PATH));
|
|
1108
|
+
cfg.command("show").description("Print the current config (API keys masked)").action(() => {
|
|
1109
|
+
const config = readConfig();
|
|
1110
|
+
const masked = {
|
|
1111
|
+
...config,
|
|
1112
|
+
profiles: Object.fromEntries(
|
|
1113
|
+
Object.entries(config.profiles).map(([n, p]) => [n, { ...p, apiKey: "***" }])
|
|
1114
|
+
)
|
|
1115
|
+
};
|
|
1116
|
+
console.log(JSON.stringify(masked, null, 2));
|
|
1117
|
+
});
|
|
1118
|
+
cfg.command("edit").description("Open the config file in $EDITOR").action(() => {
|
|
1119
|
+
const editor = process.env.EDITOR || "vi";
|
|
1120
|
+
spawn(editor, [CONFIG_PATH], { stdio: "inherit" });
|
|
1121
|
+
});
|
|
1122
|
+
cfg.command("set <key> <value>").description("Set a profile field (workspaceId, defaultProjectId, apiUrl)").option("-p, --profile <name>", "profile to update").action((key, value, opts) => {
|
|
1123
|
+
try {
|
|
1124
|
+
const profile = resolveProfile(opts.profile);
|
|
1125
|
+
const allowed = /* @__PURE__ */ new Set(["workspaceId", "defaultProjectId", "apiUrl"]);
|
|
1126
|
+
if (!allowed.has(key)) {
|
|
1127
|
+
throw new Error(`Cannot set "${key}". Allowed: ${Array.from(allowed).join(", ")}.`);
|
|
1128
|
+
}
|
|
1129
|
+
updateProfileField(profile.name, key, value);
|
|
1130
|
+
console.log(kleur5.green(`\u2713 Set ${key}=${value} on profile "${profile.name}".`));
|
|
1131
|
+
} catch (err) {
|
|
1132
|
+
console.error(formatErrorForCli(err));
|
|
1133
|
+
process.exitCode = 1;
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// src/lib/field-parsers.ts
|
|
1140
|
+
function parseTags(input) {
|
|
1141
|
+
if (input === void 0) return void 0;
|
|
1142
|
+
return input.split(",").map((t) => t.trim()).filter(Boolean);
|
|
1143
|
+
}
|
|
1144
|
+
function parseCustomFields(input) {
|
|
1145
|
+
if (input === void 0) return void 0;
|
|
1146
|
+
let parsed;
|
|
1147
|
+
try {
|
|
1148
|
+
parsed = JSON.parse(input);
|
|
1149
|
+
} catch {
|
|
1150
|
+
throw new Error(`Invalid --custom-fields JSON: ${input}`);
|
|
1151
|
+
}
|
|
1152
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
1153
|
+
throw new Error(`--custom-fields must be a JSON object, e.g. '{"region":"EU","tier":"gold"}'`);
|
|
1154
|
+
}
|
|
1155
|
+
return parsed;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
// src/commands/contact.ts
|
|
1159
|
+
var PROFILE_FIELD_MAP = {
|
|
1160
|
+
secondaryEmail: "secondary_email",
|
|
1161
|
+
mobilePhone: "mobile_phone",
|
|
1162
|
+
linkedin: "linkedin_url",
|
|
1163
|
+
twitter: "twitter_url",
|
|
1164
|
+
facebook: "facebook_url",
|
|
1165
|
+
instagram: "instagram_url",
|
|
1166
|
+
tiktok: "tiktok_url",
|
|
1167
|
+
youtube: "youtube_url",
|
|
1168
|
+
street: "address_street",
|
|
1169
|
+
city: "address_city",
|
|
1170
|
+
state: "address_state",
|
|
1171
|
+
zip: "address_zip",
|
|
1172
|
+
country: "address_country",
|
|
1173
|
+
timezone: "timezone",
|
|
1174
|
+
leadSource: "lead_source",
|
|
1175
|
+
lastContacted: "last_contacted_at",
|
|
1176
|
+
nextFollowUp: "next_follow_up_at"
|
|
1177
|
+
};
|
|
1178
|
+
function profileFieldsFrom(opts) {
|
|
1179
|
+
const out = {};
|
|
1180
|
+
for (const [optName, column] of Object.entries(PROFILE_FIELD_MAP)) {
|
|
1181
|
+
const value = opts[optName];
|
|
1182
|
+
if (value !== void 0) out[column] = value;
|
|
1183
|
+
}
|
|
1184
|
+
return out;
|
|
1185
|
+
}
|
|
1186
|
+
function registerContactCommands(parent) {
|
|
1187
|
+
const cmd = parent.command("contact").alias("contacts").description("Manage contacts (people)");
|
|
1188
|
+
cmd.command("list").description("List contacts with optional filters").option("-q, --query <text>", "search by name (first or last) or email (case-insensitive partial match)").option("-a, --account <id>", "filter by account ID").option("-t, --type <type>", "filter by contact type (lead|prospect|customer|partner|vendor)").option("--priority <level>", "filter by priority (low|medium|high|urgent)").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("--offset <n>", "skip n rows (paginate)", (v) => parseInt(v, 10)).option("--all", "fetch every matching contact (auto-paginate, ignores --limit/--offset)").option("-o, --output <format>", "output: table|json|ndjson|csv|yaml").option("-p, --profile <name>", "profile name").action(async (opts) => {
|
|
1189
|
+
try {
|
|
1190
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1191
|
+
const filters = {
|
|
1192
|
+
query: opts.query,
|
|
1193
|
+
account_id: opts.account,
|
|
1194
|
+
contact_type: opts.type,
|
|
1195
|
+
priority: opts.priority
|
|
1196
|
+
};
|
|
1197
|
+
const rows = opts.all ? await client.contacts.listAll(filters) : await client.contacts.list({ ...filters, limit: opts.limit, offset: opts.offset });
|
|
1198
|
+
console.log(render(rows, [
|
|
1199
|
+
{ header: "Name", get: (r) => `${r.first_name} ${r.last_name ?? ""}`.trim() },
|
|
1200
|
+
{ header: "Email", get: (r) => r.email },
|
|
1201
|
+
{ header: "Account", get: (r) => r.account?.name },
|
|
1202
|
+
{ header: "Type", get: (r) => r.contact_type },
|
|
1203
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
1204
|
+
], opts.output ?? defaultFormat()));
|
|
1205
|
+
} catch (err) {
|
|
1206
|
+
console.error(formatErrorForCli(err));
|
|
1207
|
+
process.exitCode = 1;
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
cmd.command("get <id>").description("Get a contact by ID").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1212
|
+
try {
|
|
1213
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1214
|
+
const contact = await client.contacts.get(id);
|
|
1215
|
+
console.log(JSON.stringify(contact, null, 2));
|
|
1216
|
+
} catch (err) {
|
|
1217
|
+
console.error(formatErrorForCli(err));
|
|
1218
|
+
process.exitCode = 1;
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
cmd.command("create").description("Create a contact").requiredOption("-f, --first-name <name>", "first name (required)").option("-l, --last-name <name>").option("-e, --email <email>").option("--phone <phone>").option("-a, --account <id>", "account ID").option("--title <title>").option("-t, --type <type>", "lead|prospect|customer|partner|vendor").option("--priority <level>").option("--notes <notes>").option("--tags <list>", 'comma-separated tags, e.g. "vip,lead"').option("--custom-fields <json>", `custom fields as a JSON object, e.g. '{"region":"EU"}'`).option("--secondary-email <email>").option("--mobile-phone <phone>").option("--linkedin <url>", "LinkedIn profile URL").option("--twitter <url>", "X/Twitter profile URL").option("--facebook <url>").option("--instagram <url>").option("--tiktok <url>").option("--youtube <url>").option("--street <street>", "street address").option("--city <city>").option("--state <state>").option("--zip <zip>").option("--country <country>").option("--timezone <tz>", 'IANA timezone, e.g. "America/New_York"').option("--lead-source <source>").option("--last-contacted <iso>", "ISO 8601 timestamp of the last contact").option("--next-follow-up <iso>", "ISO 8601 timestamp for the next planned follow-up").option("-p, --profile <name>").action(async (opts) => {
|
|
1223
|
+
try {
|
|
1224
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1225
|
+
const contact = await client.contacts.create({
|
|
1226
|
+
first_name: opts.firstName,
|
|
1227
|
+
last_name: opts.lastName,
|
|
1228
|
+
email: opts.email,
|
|
1229
|
+
phone: opts.phone,
|
|
1230
|
+
account_id: opts.account,
|
|
1231
|
+
title: opts.title,
|
|
1232
|
+
contact_type: opts.type,
|
|
1233
|
+
priority: opts.priority,
|
|
1234
|
+
notes: opts.notes,
|
|
1235
|
+
tags: parseTags(opts.tags),
|
|
1236
|
+
custom_fields: parseCustomFields(opts.customFields),
|
|
1237
|
+
...profileFieldsFrom(opts)
|
|
1238
|
+
});
|
|
1239
|
+
console.log(JSON.stringify(contact, null, 2));
|
|
1240
|
+
} catch (err) {
|
|
1241
|
+
console.error(formatErrorForCli(err));
|
|
1242
|
+
process.exitCode = 1;
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
cmd.command("update <id>").description("Update a contact").option("-f, --first-name <name>").option("-l, --last-name <name>").option("-e, --email <email>").option("--phone <phone>").option("-a, --account <id>", "account ID").option("--title <title>").option("-t, --type <type>", "lead|prospect|customer|partner|vendor").option("--priority <level>").option("--notes <notes>").option("--tags <list>", "comma-separated tags (replaces the existing set)").option("--custom-fields <json>", "custom fields as a JSON object (replaces the existing object)").option("--secondary-email <email>").option("--mobile-phone <phone>").option("--linkedin <url>", "LinkedIn profile URL").option("--twitter <url>", "X/Twitter profile URL").option("--facebook <url>").option("--instagram <url>").option("--tiktok <url>").option("--youtube <url>").option("--street <street>", "street address").option("--city <city>").option("--state <state>").option("--zip <zip>").option("--country <country>").option("--timezone <tz>", 'IANA timezone, e.g. "America/New_York"').option("--lead-source <source>").option("--last-contacted <iso>", "ISO 8601 timestamp of the last contact").option("--next-follow-up <iso>", "ISO 8601 timestamp for the next planned follow-up").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1247
|
+
try {
|
|
1248
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1249
|
+
const updates = {};
|
|
1250
|
+
if (opts.firstName !== void 0) updates.first_name = opts.firstName;
|
|
1251
|
+
if (opts.lastName !== void 0) updates.last_name = opts.lastName;
|
|
1252
|
+
if (opts.email !== void 0) updates.email = opts.email;
|
|
1253
|
+
if (opts.phone !== void 0) updates.phone = opts.phone;
|
|
1254
|
+
if (opts.account !== void 0) updates.account_id = opts.account;
|
|
1255
|
+
if (opts.title !== void 0) updates.title = opts.title;
|
|
1256
|
+
if (opts.type !== void 0) updates.contact_type = opts.type;
|
|
1257
|
+
if (opts.priority !== void 0) updates.priority = opts.priority;
|
|
1258
|
+
if (opts.notes !== void 0) updates.notes = opts.notes;
|
|
1259
|
+
if (opts.tags !== void 0) updates.tags = parseTags(opts.tags);
|
|
1260
|
+
if (opts.customFields !== void 0) updates.custom_fields = parseCustomFields(opts.customFields);
|
|
1261
|
+
Object.assign(updates, profileFieldsFrom(opts));
|
|
1262
|
+
const contact = await client.contacts.update(id, updates);
|
|
1263
|
+
console.log(JSON.stringify(contact, null, 2));
|
|
1264
|
+
} catch (err) {
|
|
1265
|
+
console.error(formatErrorForCli(err));
|
|
1266
|
+
process.exitCode = 1;
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
cmd.command("delete [ids...]").description("Delete contacts by ID, or all matching --email (bulk cleanup)").option("--email <email>", "delete every contact with this email (case-insensitive)").option("--dry-run", "list what would be deleted without deleting").option("-p, --profile <name>").action(async (ids, opts) => {
|
|
1271
|
+
try {
|
|
1272
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1273
|
+
const targets = /* @__PURE__ */ new Map();
|
|
1274
|
+
for (const id of ids ?? []) targets.set(id, { id, label: id });
|
|
1275
|
+
if (opts.email) {
|
|
1276
|
+
const needle = String(opts.email).toLowerCase();
|
|
1277
|
+
const matches = (await client.contacts.listAll()).filter((c) => c.email?.toLowerCase() === needle);
|
|
1278
|
+
for (const c of matches) {
|
|
1279
|
+
targets.set(c.id, { id: c.id, label: `${c.first_name} ${c.last_name ?? ""}`.trim() + ` <${c.email}>` });
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (targets.size === 0) {
|
|
1283
|
+
console.error("No contacts matched. Pass IDs and/or --email.");
|
|
1284
|
+
process.exitCode = 1;
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
const list = [...targets.values()];
|
|
1288
|
+
if (opts.dryRun) {
|
|
1289
|
+
console.log(`Would delete ${list.length} contact(s):`);
|
|
1290
|
+
for (const t of list) console.log(` ${t.id} ${t.label}`);
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
let deleted = 0;
|
|
1294
|
+
const failures = [];
|
|
1295
|
+
for (const t of list) {
|
|
1296
|
+
try {
|
|
1297
|
+
await client.contacts.delete(t.id);
|
|
1298
|
+
deleted++;
|
|
1299
|
+
} catch (err) {
|
|
1300
|
+
failures.push(`${t.id}: ${err.message}`);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
console.log(`Deleted ${deleted}/${list.length} contact(s).`);
|
|
1304
|
+
if (failures.length) {
|
|
1305
|
+
console.error(`Failed:
|
|
1306
|
+
${failures.join("\n ")}`);
|
|
1307
|
+
process.exitCode = 1;
|
|
1308
|
+
return;
|
|
1309
|
+
}
|
|
1310
|
+
} catch (err) {
|
|
1311
|
+
console.error(formatErrorForCli(err));
|
|
1312
|
+
process.exitCode = 1;
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
// src/commands/account.ts
|
|
1319
|
+
function registerAccountCommands(parent) {
|
|
1320
|
+
const cmd = parent.command("account").alias("accounts").description("Manage client accounts");
|
|
1321
|
+
cmd.command("list").description("List accounts").option("-q, --query <text>", "search by account name or email (case-insensitive partial match)").option("--status <status>", "active|inactive|paused").option("--health <health>", "good|at_risk|critical|not_set").option("--owner <id>", "filter by owner user ID").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("--offset <n>", "skip n rows (paginate)", (v) => parseInt(v, 10)).option("--all", "fetch every matching account (auto-paginate, ignores --limit/--offset)").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
1322
|
+
try {
|
|
1323
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1324
|
+
const filters = {
|
|
1325
|
+
query: opts.query,
|
|
1326
|
+
status: opts.status,
|
|
1327
|
+
health: opts.health,
|
|
1328
|
+
owner_id: opts.owner
|
|
1329
|
+
};
|
|
1330
|
+
const rows = opts.all ? await client.accounts.listAll(filters) : await client.accounts.list({ ...filters, limit: opts.limit, offset: opts.offset });
|
|
1331
|
+
console.log(render(rows, [
|
|
1332
|
+
{ header: "Name", get: (r) => r.name },
|
|
1333
|
+
{ header: "Email", get: (r) => r.email },
|
|
1334
|
+
{ header: "Status", get: (r) => r.status },
|
|
1335
|
+
{ header: "Health", get: (r) => r.health },
|
|
1336
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
1337
|
+
], opts.output ?? defaultFormat()));
|
|
1338
|
+
} catch (err) {
|
|
1339
|
+
console.error(formatErrorForCli(err));
|
|
1340
|
+
process.exitCode = 1;
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1344
|
+
cmd.command("get <id>").description("Get an account by ID").option("-o, --output <format>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1345
|
+
try {
|
|
1346
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1347
|
+
const account = await client.accounts.get(id);
|
|
1348
|
+
console.log(JSON.stringify(account, null, 2));
|
|
1349
|
+
} catch (err) {
|
|
1350
|
+
console.error(formatErrorForCli(err));
|
|
1351
|
+
process.exitCode = 1;
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
cmd.command("create").description("Create an account").requiredOption("-n, --name <name>", "account name (required)").option("-e, --email <email>").option("-w, --website <url>").option("--phone <phone>").option("--status <status>", "active|inactive|paused").option("--health <health>", "good|at_risk|critical|not_set").option("--description <text>").option("--tags <list>", 'comma-separated tags, e.g. "agency,priority"').option("--custom-fields <json>", `custom fields as a JSON object, e.g. '{"region":"EU"}'`).option("-p, --profile <name>").action(async (opts) => {
|
|
1356
|
+
try {
|
|
1357
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1358
|
+
const account = await client.accounts.create({
|
|
1359
|
+
name: opts.name,
|
|
1360
|
+
email: opts.email,
|
|
1361
|
+
website: opts.website,
|
|
1362
|
+
phone: opts.phone,
|
|
1363
|
+
status: opts.status,
|
|
1364
|
+
health: opts.health,
|
|
1365
|
+
description: opts.description,
|
|
1366
|
+
tags: parseTags(opts.tags),
|
|
1367
|
+
custom_fields: parseCustomFields(opts.customFields)
|
|
1368
|
+
});
|
|
1369
|
+
console.log(JSON.stringify(account, null, 2));
|
|
1370
|
+
} catch (err) {
|
|
1371
|
+
console.error(formatErrorForCli(err));
|
|
1372
|
+
process.exitCode = 1;
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
cmd.command("update <id>").description("Update an account").option("-n, --name <name>").option("-e, --email <email>").option("-w, --website <url>").option("--phone <phone>").option("--status <status>", "active|inactive|paused").option("--health <health>", "good|at_risk|critical|not_set").option("--description <text>").option("--tags <list>", "comma-separated tags (replaces the existing set)").option("--custom-fields <json>", "custom fields as a JSON object (replaces the existing object)").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1377
|
+
try {
|
|
1378
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1379
|
+
const updates = {};
|
|
1380
|
+
if (opts.name !== void 0) updates.name = opts.name;
|
|
1381
|
+
if (opts.email !== void 0) updates.email = opts.email;
|
|
1382
|
+
if (opts.website !== void 0) updates.website = opts.website;
|
|
1383
|
+
if (opts.phone !== void 0) updates.phone = opts.phone;
|
|
1384
|
+
if (opts.status !== void 0) updates.status = opts.status;
|
|
1385
|
+
if (opts.health !== void 0) updates.health = opts.health;
|
|
1386
|
+
if (opts.description !== void 0) updates.description = opts.description;
|
|
1387
|
+
if (opts.tags !== void 0) updates.tags = parseTags(opts.tags);
|
|
1388
|
+
if (opts.customFields !== void 0) updates.custom_fields = parseCustomFields(opts.customFields);
|
|
1389
|
+
const account = await client.accounts.update(id, updates);
|
|
1390
|
+
console.log(JSON.stringify(account, null, 2));
|
|
1391
|
+
} catch (err) {
|
|
1392
|
+
console.error(formatErrorForCli(err));
|
|
1393
|
+
process.exitCode = 1;
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
const products = cmd.command("products").description("Manage account \u2194 product attribution");
|
|
1398
|
+
products.command("list <accountId>").description("Customer-360 list: what's attributed, paid, won, and in pipeline").option("-o, --output <format>").option("-p, --profile <name>").action(async (accountId, opts) => {
|
|
1399
|
+
try {
|
|
1400
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1401
|
+
const { rows } = await client.accountProducts.list(accountId);
|
|
1402
|
+
console.log(render(rows, [
|
|
1403
|
+
{ header: "Product", get: (r) => r.product_name, truncate: 24 },
|
|
1404
|
+
{ header: "Source", get: (r) => r.source },
|
|
1405
|
+
{ header: "Active", get: (r) => r.is_active ? "yes" : "no" },
|
|
1406
|
+
{ header: "Qty", get: (r) => String(r.quantity) },
|
|
1407
|
+
{ header: "Rate", get: (r) => r.rate != null ? `$${Number(r.rate).toFixed(2)}` : "\u2014" },
|
|
1408
|
+
{ header: "Amount", get: (r) => `$${Number(r.amount).toFixed(2)}` },
|
|
1409
|
+
{ header: "When", get: (r) => r.occurred_at ?? "" }
|
|
1410
|
+
], opts.output ?? defaultFormat()));
|
|
1411
|
+
} catch (err) {
|
|
1412
|
+
console.error(formatErrorForCli(err));
|
|
1413
|
+
process.exitCode = 1;
|
|
1414
|
+
return;
|
|
1415
|
+
}
|
|
1416
|
+
});
|
|
1417
|
+
products.command("attach <accountId>").description("Attach a product to an account (no invoice created \u2014 pure attribution)").requiredOption("--product <id>", "product id (required)").option("--tier <id>", "price tier id (omit for the default tier)").option("-q, --quantity <n>", "", parseFloat).option("-r, --rate <amount>", "snapshot rate", parseFloat).option("--purchased <date>", "ISO date the relationship began").option("--ended <date>", "ISO date the relationship ended (mark as historical)").option("--notes <text>").option("--source <source>", "manual|import|onboarding", "manual").option("-p, --profile <name>").action(async (accountId, opts) => {
|
|
1418
|
+
try {
|
|
1419
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1420
|
+
const result = await client.accountProducts.attach({
|
|
1421
|
+
account_id: accountId,
|
|
1422
|
+
product_id: opts.product,
|
|
1423
|
+
product_price_id: opts.tier,
|
|
1424
|
+
quantity: opts.quantity,
|
|
1425
|
+
rate: opts.rate,
|
|
1426
|
+
purchased_at: opts.purchased,
|
|
1427
|
+
ended_at: opts.ended,
|
|
1428
|
+
notes: opts.notes,
|
|
1429
|
+
source: opts.source
|
|
1430
|
+
});
|
|
1431
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1432
|
+
} catch (err) {
|
|
1433
|
+
console.error(formatErrorForCli(err));
|
|
1434
|
+
process.exitCode = 1;
|
|
1435
|
+
return;
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
products.command("update <accountProductId>").description("Update an account_products attribution row").option("--tier <id>", "switch to a different price tier of the same product (rate follows the tier)").option("-q, --quantity <n>", "", parseFloat).option("-r, --rate <amount>", "", parseFloat).option("--purchased <date>", "ISO date started").option("--ended <date>", "ISO date ended").option("--notes <text>").option("-p, --profile <name>").action(async (accountProductId, opts) => {
|
|
1439
|
+
try {
|
|
1440
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1441
|
+
const result = await client.accountProducts.update({
|
|
1442
|
+
account_product_id: accountProductId,
|
|
1443
|
+
product_price_id: opts.tier,
|
|
1444
|
+
quantity: opts.quantity,
|
|
1445
|
+
rate: opts.rate,
|
|
1446
|
+
purchased_at: opts.purchased,
|
|
1447
|
+
ended_at: opts.ended,
|
|
1448
|
+
notes: opts.notes
|
|
1449
|
+
});
|
|
1450
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1451
|
+
} catch (err) {
|
|
1452
|
+
console.error(formatErrorForCli(err));
|
|
1453
|
+
process.exitCode = 1;
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
products.command("detach <accountProductId>").description('Delete an attribution row (prefer "update --ended" for natural endings)').option("-p, --profile <name>").action(async (accountProductId, opts) => {
|
|
1458
|
+
try {
|
|
1459
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1460
|
+
const result = await client.accountProducts.detach(accountProductId);
|
|
1461
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1462
|
+
} catch (err) {
|
|
1463
|
+
console.error(formatErrorForCli(err));
|
|
1464
|
+
process.exitCode = 1;
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// src/commands/deal.ts
|
|
1471
|
+
import prompts2 from "prompts";
|
|
1472
|
+
function registerDealCommands(parent) {
|
|
1473
|
+
const cmd = parent.command("deal").alias("deals").description("Manage sales deals");
|
|
1474
|
+
cmd.command("list").description("List deals").option("--stage <stage>", "stage key (defined per pipeline; see `pipeline list`)").option("--priority <level>").option("-a, --account <id>").option("--pipeline <id>", "filter by pipeline ID (see `pipeline list`)").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
1475
|
+
try {
|
|
1476
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1477
|
+
const rows = await client.deals.list({
|
|
1478
|
+
stage: opts.stage,
|
|
1479
|
+
priority: opts.priority,
|
|
1480
|
+
account_id: opts.account,
|
|
1481
|
+
pipeline_id: opts.pipeline,
|
|
1482
|
+
limit: opts.limit
|
|
1483
|
+
});
|
|
1484
|
+
console.log(render(rows, [
|
|
1485
|
+
{ header: "Title", get: (r) => r.title },
|
|
1486
|
+
{ header: "Stage", get: (r) => r.stage },
|
|
1487
|
+
{ header: "Value", get: (r) => r.value != null ? `$${r.value.toLocaleString()}` : "" },
|
|
1488
|
+
{ header: "Prob.", get: (r) => r.probability != null ? `${r.probability}%` : "" },
|
|
1489
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
1490
|
+
], opts.output ?? defaultFormat()));
|
|
1491
|
+
} catch (err) {
|
|
1492
|
+
console.error(formatErrorForCli(err));
|
|
1493
|
+
process.exitCode = 1;
|
|
1494
|
+
return;
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
cmd.command("get <id>").description("Get a deal by ID").option("-o, --output <format>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1498
|
+
try {
|
|
1499
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1500
|
+
const deal = await client.deals.get(id);
|
|
1501
|
+
console.log(JSON.stringify(deal, null, 2));
|
|
1502
|
+
} catch (err) {
|
|
1503
|
+
console.error(formatErrorForCli(err));
|
|
1504
|
+
process.exitCode = 1;
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
cmd.command("create").description("Create a deal").requiredOption("-t, --title <title>", "deal title (required)").option("--pipeline <id>", "pipeline ID (defaults to the workspace default; see `pipeline list`)").option("--stage <stage>", "stage key (defaults to the pipeline first stage)").option("--priority <level>", "low|medium|high|urgent").option("--value <amount>", "deal value in dollars", parseFloat).option("--probability <pct>", "0-100", parseFloat).option("-a, --account <id>").option("--contact <id>", "link the deal to a contact/person (see `contact list`)").option("--close-date <date>", "expected close (ISO 8601)").option("-p, --profile <name>").action(async (opts) => {
|
|
1509
|
+
try {
|
|
1510
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1511
|
+
const deal = await client.deals.create({
|
|
1512
|
+
title: opts.title,
|
|
1513
|
+
pipeline_id: opts.pipeline,
|
|
1514
|
+
stage: opts.stage,
|
|
1515
|
+
priority: opts.priority,
|
|
1516
|
+
value: opts.value,
|
|
1517
|
+
probability: opts.probability,
|
|
1518
|
+
account_id: opts.account,
|
|
1519
|
+
contact_id: opts.contact,
|
|
1520
|
+
expected_close_date: opts.closeDate
|
|
1521
|
+
});
|
|
1522
|
+
console.log(JSON.stringify(deal, null, 2));
|
|
1523
|
+
} catch (err) {
|
|
1524
|
+
console.error(formatErrorForCli(err));
|
|
1525
|
+
process.exitCode = 1;
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
cmd.command("update <id>").description("Update a deal").option("-t, --title <title>").option("--pipeline <id>", "move the deal to another pipeline (see `pipeline list`)").option("--stage <stage>", "stage key within the deal pipeline").option("--priority <level>", "low|medium|high|urgent").option("--value <amount>", "deal value in dollars", parseFloat).option("--probability <pct>", "0-100", parseFloat).option("-a, --account <id>").option("--contact <id>", "link the deal to a contact/person (see `contact list`)").option("--close-date <date>", "expected close (ISO 8601)").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1530
|
+
try {
|
|
1531
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1532
|
+
const deal = await client.deals.update(id, {
|
|
1533
|
+
title: opts.title,
|
|
1534
|
+
pipeline_id: opts.pipeline,
|
|
1535
|
+
stage: opts.stage,
|
|
1536
|
+
priority: opts.priority,
|
|
1537
|
+
value: opts.value,
|
|
1538
|
+
probability: opts.probability,
|
|
1539
|
+
account_id: opts.account,
|
|
1540
|
+
contact_id: opts.contact,
|
|
1541
|
+
expected_close_date: opts.closeDate
|
|
1542
|
+
});
|
|
1543
|
+
console.log(JSON.stringify(deal, null, 2));
|
|
1544
|
+
} catch (err) {
|
|
1545
|
+
console.error(formatErrorForCli(err));
|
|
1546
|
+
process.exitCode = 1;
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
cmd.command("delete <id>").description("Delete a deal").option("-y, --yes", "skip confirmation").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1551
|
+
try {
|
|
1552
|
+
if (!opts.yes) {
|
|
1553
|
+
if (!process.stdin.isTTY) {
|
|
1554
|
+
console.error("Refusing to delete without confirmation in a non-interactive shell. Re-run with -y/--yes.");
|
|
1555
|
+
process.exitCode = 1;
|
|
1556
|
+
return;
|
|
1557
|
+
}
|
|
1558
|
+
const { confirmed } = await prompts2({
|
|
1559
|
+
type: "confirm",
|
|
1560
|
+
name: "confirmed",
|
|
1561
|
+
message: `Delete deal ${id}? This cannot be undone.`,
|
|
1562
|
+
initial: false
|
|
1563
|
+
});
|
|
1564
|
+
if (!confirmed) {
|
|
1565
|
+
console.log("Aborted.");
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1570
|
+
await client.deals.delete(id);
|
|
1571
|
+
console.log(`\u2713 Deleted deal ${id}`);
|
|
1572
|
+
} catch (err) {
|
|
1573
|
+
console.error(formatErrorForCli(err));
|
|
1574
|
+
process.exitCode = 1;
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// src/commands/pipeline.ts
|
|
1581
|
+
import prompts3 from "prompts";
|
|
1582
|
+
function registerPipelineCommands(parent) {
|
|
1583
|
+
const cmd = parent.command("pipeline").alias("pipelines").description("Manage sales pipelines and their stages");
|
|
1584
|
+
cmd.command("list").description("List pipelines with their stages").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
1585
|
+
try {
|
|
1586
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1587
|
+
const rows = await client.pipelines.list();
|
|
1588
|
+
const format = opts.output ?? defaultFormat();
|
|
1589
|
+
if (format === "table") {
|
|
1590
|
+
console.log(render(rows, [
|
|
1591
|
+
{ header: "Name", get: (r) => r.name },
|
|
1592
|
+
{ header: "Default", get: (r) => r.is_default ? "\u2713" : "" },
|
|
1593
|
+
{ header: "Stages", get: (r) => (r.stages ?? []).map((s) => s.key).join(" \u2192 ") },
|
|
1594
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
1595
|
+
], format));
|
|
1596
|
+
} else {
|
|
1597
|
+
console.log(render(rows, [
|
|
1598
|
+
{ header: "id", get: (r) => r.id },
|
|
1599
|
+
{ header: "name", get: (r) => r.name },
|
|
1600
|
+
{ header: "is_default", get: (r) => r.is_default },
|
|
1601
|
+
{ header: "stages", get: (r) => r.stages }
|
|
1602
|
+
], format));
|
|
1603
|
+
}
|
|
1604
|
+
} catch (err) {
|
|
1605
|
+
console.error(formatErrorForCli(err));
|
|
1606
|
+
process.exitCode = 1;
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
cmd.command("create").description("Create a pipeline (seeds default stages unless --stage given)").requiredOption("-n, --name <name>", "pipeline name (required)").option("-d, --description <text>").option("--color <name>", "accent color name").option("--default", "make this the default pipeline").option("--stage <key:label>", "seed stage (repeatable), e.g. --stage trial:Trial", collectStage, []).option("-p, --profile <name>").action(async (opts) => {
|
|
1611
|
+
try {
|
|
1612
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1613
|
+
const pipeline = await client.pipelines.create({
|
|
1614
|
+
name: opts.name,
|
|
1615
|
+
description: opts.description,
|
|
1616
|
+
color: opts.color,
|
|
1617
|
+
is_default: opts.default,
|
|
1618
|
+
stages: opts.stage.length ? opts.stage : void 0
|
|
1619
|
+
});
|
|
1620
|
+
console.log(JSON.stringify(pipeline, null, 2));
|
|
1621
|
+
} catch (err) {
|
|
1622
|
+
console.error(formatErrorForCli(err));
|
|
1623
|
+
process.exitCode = 1;
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
cmd.command("update <id>").description("Update a pipeline").option("-n, --name <name>").option("-d, --description <text>").option("--color <name>").option("--default", "make this the default pipeline").option("--position <n>", "order position", (v) => parseInt(v, 10)).option("-p, --profile <name>").action(async (id, opts) => {
|
|
1628
|
+
try {
|
|
1629
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1630
|
+
const pipeline = await client.pipelines.update(id, {
|
|
1631
|
+
name: opts.name,
|
|
1632
|
+
description: opts.description,
|
|
1633
|
+
color: opts.color,
|
|
1634
|
+
is_default: opts.default,
|
|
1635
|
+
position: opts.position
|
|
1636
|
+
});
|
|
1637
|
+
console.log(JSON.stringify(pipeline, null, 2));
|
|
1638
|
+
} catch (err) {
|
|
1639
|
+
console.error(formatErrorForCli(err));
|
|
1640
|
+
process.exitCode = 1;
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
cmd.command("delete <id>").description("Delete a pipeline (reassign deals first with --reassign-to)").option("--reassign-to <pipelineId>", "move existing deals to this pipeline before deleting").option("-y, --yes", "skip confirmation").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1645
|
+
try {
|
|
1646
|
+
if (!opts.yes) {
|
|
1647
|
+
if (!process.stdin.isTTY) {
|
|
1648
|
+
console.error("Refusing to delete without confirmation in a non-interactive shell. Re-run with -y/--yes.");
|
|
1649
|
+
process.exitCode = 1;
|
|
1650
|
+
return;
|
|
1651
|
+
}
|
|
1652
|
+
const { confirmed } = await prompts3({
|
|
1653
|
+
type: "confirm",
|
|
1654
|
+
name: "confirmed",
|
|
1655
|
+
message: `Delete pipeline ${id}? This cannot be undone.`,
|
|
1656
|
+
initial: false
|
|
1657
|
+
});
|
|
1658
|
+
if (!confirmed) {
|
|
1659
|
+
console.log("Aborted.");
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1664
|
+
await client.pipelines.delete(id, opts.reassignTo);
|
|
1665
|
+
console.log(`\u2713 Deleted pipeline ${id}`);
|
|
1666
|
+
} catch (err) {
|
|
1667
|
+
console.error(formatErrorForCli(err));
|
|
1668
|
+
process.exitCode = 1;
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
});
|
|
1672
|
+
cmd.command("add-stage").description("Add a stage to a pipeline").requiredOption("--pipeline <id>", "pipeline ID (required)").requiredOption("--key <key>", "stage key/slug (required)").requiredOption("--label <label>", "display label (required)").option("--color <name>", "color name (gray, blue, purple, yellow, green, red)").option("--position <n>", "order position (defaults to end)", (v) => parseInt(v, 10)).option("--won", "mark as a won stage").option("--lost", "mark as a lost stage").option("--archived", "mark as a parked stage (excluded from funnels)").option("-p, --profile <name>").action(async (opts) => {
|
|
1673
|
+
try {
|
|
1674
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1675
|
+
const stage = await client.pipelines.addStage({
|
|
1676
|
+
pipeline_id: opts.pipeline,
|
|
1677
|
+
key: opts.key,
|
|
1678
|
+
label: opts.label,
|
|
1679
|
+
color: opts.color,
|
|
1680
|
+
position: opts.position,
|
|
1681
|
+
is_won: opts.won,
|
|
1682
|
+
is_lost: opts.lost,
|
|
1683
|
+
is_archived: opts.archived
|
|
1684
|
+
});
|
|
1685
|
+
console.log(JSON.stringify(stage, null, 2));
|
|
1686
|
+
} catch (err) {
|
|
1687
|
+
console.error(formatErrorForCli(err));
|
|
1688
|
+
process.exitCode = 1;
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
});
|
|
1692
|
+
cmd.command("update-stage <stageId>").description("Update a pipeline stage").option("--key <key>").option("--label <label>").option("--color <name>").option("--position <n>", "order position", (v) => parseInt(v, 10)).option("--won", "mark as a won stage").option("--lost", "mark as a lost stage").option("--archived", "mark as a parked stage (excluded from funnels)").option("-p, --profile <name>").action(async (stageId, opts) => {
|
|
1693
|
+
try {
|
|
1694
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1695
|
+
const stage = await client.pipelines.updateStage(stageId, {
|
|
1696
|
+
key: opts.key,
|
|
1697
|
+
label: opts.label,
|
|
1698
|
+
color: opts.color,
|
|
1699
|
+
position: opts.position,
|
|
1700
|
+
is_won: opts.won,
|
|
1701
|
+
is_lost: opts.lost,
|
|
1702
|
+
is_archived: opts.archived
|
|
1703
|
+
});
|
|
1704
|
+
console.log(JSON.stringify(stage, null, 2));
|
|
1705
|
+
} catch (err) {
|
|
1706
|
+
console.error(formatErrorForCli(err));
|
|
1707
|
+
process.exitCode = 1;
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
cmd.command("delete-stage <stageId>").description("Delete a pipeline stage (deals move to the first remaining stage)").option("-y, --yes", "skip confirmation").option("-p, --profile <name>").action(async (stageId, opts) => {
|
|
1712
|
+
try {
|
|
1713
|
+
if (!opts.yes) {
|
|
1714
|
+
if (!process.stdin.isTTY) {
|
|
1715
|
+
console.error("Refusing to delete without confirmation in a non-interactive shell. Re-run with -y/--yes.");
|
|
1716
|
+
process.exitCode = 1;
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
const { confirmed } = await prompts3({
|
|
1720
|
+
type: "confirm",
|
|
1721
|
+
name: "confirmed",
|
|
1722
|
+
message: `Delete stage ${stageId}?`,
|
|
1723
|
+
initial: false
|
|
1724
|
+
});
|
|
1725
|
+
if (!confirmed) {
|
|
1726
|
+
console.log("Aborted.");
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1731
|
+
await client.pipelines.deleteStage(stageId);
|
|
1732
|
+
console.log(`\u2713 Deleted stage ${stageId}`);
|
|
1733
|
+
} catch (err) {
|
|
1734
|
+
console.error(formatErrorForCli(err));
|
|
1735
|
+
process.exitCode = 1;
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
function collectStage(value, previous) {
|
|
1741
|
+
const idx = value.indexOf(":");
|
|
1742
|
+
const key = idx === -1 ? value : value.slice(0, idx);
|
|
1743
|
+
const label = idx === -1 ? value : value.slice(idx + 1);
|
|
1744
|
+
return [...previous, { key: key.trim(), label: label.trim() }];
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
// src/commands/project.ts
|
|
1748
|
+
function registerProjectCommands(parent) {
|
|
1749
|
+
const cmd = parent.command("project").alias("projects").description("Manage projects");
|
|
1750
|
+
cmd.command("list").description("List projects").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
1751
|
+
try {
|
|
1752
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1753
|
+
const rows = await client.projects.list();
|
|
1754
|
+
console.log(render(rows, [
|
|
1755
|
+
{ header: "Name", get: (r) => r.name },
|
|
1756
|
+
{ header: "Stage", get: (r) => r.stage },
|
|
1757
|
+
{ header: "Slug", get: (r) => r.slug },
|
|
1758
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
1759
|
+
], opts.output ?? defaultFormat()));
|
|
1760
|
+
} catch (err) {
|
|
1761
|
+
console.error(formatErrorForCli(err));
|
|
1762
|
+
process.exitCode = 1;
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
});
|
|
1766
|
+
cmd.command("create").description("Create a project").requiredOption("-n, --name <name>", "project name (required)").option("-d, --description <text>").option("-a, --account <id>", "link to account ID or name").option("--stage <stage>", "active|archived|completed", "active").option("--visibility <vis>", "public|private", "private").option("-p, --profile <name>").action(async (opts) => {
|
|
1767
|
+
try {
|
|
1768
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1769
|
+
const project = await client.projects.create({
|
|
1770
|
+
name: opts.name,
|
|
1771
|
+
description: opts.description,
|
|
1772
|
+
account_id: opts.account,
|
|
1773
|
+
stage: opts.stage,
|
|
1774
|
+
visibility: opts.visibility
|
|
1775
|
+
});
|
|
1776
|
+
console.log(JSON.stringify(project, null, 2));
|
|
1777
|
+
} catch (err) {
|
|
1778
|
+
console.error(formatErrorForCli(err));
|
|
1779
|
+
process.exitCode = 1;
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
// src/commands/task.ts
|
|
1786
|
+
import { readFile } from "fs/promises";
|
|
1787
|
+
import { basename, extname } from "path";
|
|
1788
|
+
var MIME_BY_EXT = {
|
|
1789
|
+
".png": "image/png",
|
|
1790
|
+
".jpg": "image/jpeg",
|
|
1791
|
+
".jpeg": "image/jpeg",
|
|
1792
|
+
".gif": "image/gif",
|
|
1793
|
+
".webp": "image/webp",
|
|
1794
|
+
".svg": "image/svg+xml",
|
|
1795
|
+
".bmp": "image/bmp",
|
|
1796
|
+
".heic": "image/heic",
|
|
1797
|
+
".pdf": "application/pdf",
|
|
1798
|
+
".txt": "text/plain",
|
|
1799
|
+
".md": "text/markdown",
|
|
1800
|
+
".csv": "text/csv",
|
|
1801
|
+
".json": "application/json",
|
|
1802
|
+
".zip": "application/zip",
|
|
1803
|
+
".doc": "application/msword",
|
|
1804
|
+
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
1805
|
+
".xls": "application/vnd.ms-excel",
|
|
1806
|
+
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
1807
|
+
".ppt": "application/vnd.ms-powerpoint",
|
|
1808
|
+
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
1809
|
+
".mp4": "video/mp4",
|
|
1810
|
+
".mov": "video/quicktime",
|
|
1811
|
+
".mp3": "audio/mpeg",
|
|
1812
|
+
".wav": "audio/wav"
|
|
1813
|
+
};
|
|
1814
|
+
async function uploadAttachments(client, paths) {
|
|
1815
|
+
const out = [];
|
|
1816
|
+
for (const path of paths) {
|
|
1817
|
+
const buf = await readFile(path);
|
|
1818
|
+
const filename = basename(path);
|
|
1819
|
+
const content_type = MIME_BY_EXT[extname(path).toLowerCase()] || "application/octet-stream";
|
|
1820
|
+
const attachment = await client.attachments.upload({
|
|
1821
|
+
filename,
|
|
1822
|
+
content_type,
|
|
1823
|
+
data_base64: buf.toString("base64")
|
|
1824
|
+
});
|
|
1825
|
+
out.push(attachment);
|
|
1826
|
+
}
|
|
1827
|
+
return out;
|
|
1828
|
+
}
|
|
1829
|
+
function registerTaskCommands(parent) {
|
|
1830
|
+
const cmd = parent.command("task").alias("tasks").description("Manage tasks");
|
|
1831
|
+
cmd.command("list").description("List tasks (archived excluded by default)").option("-q, --query <text>", "search by task title or description (case-insensitive partial match)").option("-s, --status <status>", "backlog|todo|in_progress|for_review|for_approval|approved|on_hold|completed|archived").option("--priority <level>", "low|medium|high|urgent").option("--project <id>", "filter by project ID").option("--active-only", "exclude completed and archived").option("--include-archived", "include archived").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
1832
|
+
try {
|
|
1833
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1834
|
+
const rows = await client.tasks.list({
|
|
1835
|
+
query: opts.query,
|
|
1836
|
+
status: opts.status,
|
|
1837
|
+
priority: opts.priority,
|
|
1838
|
+
project_id: opts.project,
|
|
1839
|
+
active_only: opts.activeOnly,
|
|
1840
|
+
include_archived: opts.includeArchived,
|
|
1841
|
+
limit: opts.limit
|
|
1842
|
+
});
|
|
1843
|
+
console.log(render(rows, [
|
|
1844
|
+
{ header: "ID", get: (r) => r.visible_id ?? r.id, truncate: 12 },
|
|
1845
|
+
{ header: "Title", get: (r) => r.title, truncate: 50 },
|
|
1846
|
+
{ header: "Status", get: (r) => r.status },
|
|
1847
|
+
{ header: "Priority", get: (r) => r.priority },
|
|
1848
|
+
{ header: "Due", get: (r) => r.due_date }
|
|
1849
|
+
], opts.output ?? defaultFormat()));
|
|
1850
|
+
} catch (err) {
|
|
1851
|
+
console.error(formatErrorForCli(err));
|
|
1852
|
+
process.exitCode = 1;
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
cmd.command("get <id>").description("Get a task by ID or visible_id (e.g., TRI-49)").option("-o, --output <format>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1857
|
+
try {
|
|
1858
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1859
|
+
const task = await client.tasks.get(id);
|
|
1860
|
+
console.log(JSON.stringify(task, null, 2));
|
|
1861
|
+
} catch (err) {
|
|
1862
|
+
console.error(formatErrorForCli(err));
|
|
1863
|
+
process.exitCode = 1;
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
cmd.command("create").description("Create a task (requires project unless defaultProjectId is set)").requiredOption("-t, --title <title>", "task title (required)").option("-d, --description <text>").option("--project <id>", "project ID (falls back to defaultProjectId)").option("--parent <id>", "parent task ID or visible_id (e.g., HDEV-037)").option("--priority <level>", "low|medium|high|urgent").option("-s, --status <status>").option("-a, --assignee <id...>", "assignee user ID (repeatable, max 5)").option("--attach <path...>", "file(s) to attach (repeatable, any type, max 25MB each)").option("--force", "create even if a similar task already exists (bypasses duplicate detection)").option("-p, --profile <name>").action(async (opts) => {
|
|
1868
|
+
try {
|
|
1869
|
+
const profile = resolveProfile(opts.profile);
|
|
1870
|
+
const client = HelmClient.fromProfile(profile);
|
|
1871
|
+
const projectId = opts.project ?? profile.defaultProjectId;
|
|
1872
|
+
if (!projectId) {
|
|
1873
|
+
throw new Error("No project specified. Pass --project or set defaultProjectId in your profile.");
|
|
1874
|
+
}
|
|
1875
|
+
const attachments = opts.attach ? await uploadAttachments(client, opts.attach) : void 0;
|
|
1876
|
+
const task = await client.tasks.create({
|
|
1877
|
+
title: opts.title,
|
|
1878
|
+
description: opts.description,
|
|
1879
|
+
project_id: projectId,
|
|
1880
|
+
priority: opts.priority,
|
|
1881
|
+
status: opts.status,
|
|
1882
|
+
assignee_ids: opts.assignee,
|
|
1883
|
+
parent_task_id: opts.parent,
|
|
1884
|
+
skip_duplicate_check: opts.force,
|
|
1885
|
+
attachments
|
|
1886
|
+
});
|
|
1887
|
+
const dupWarning = task;
|
|
1888
|
+
if (dupWarning?.duplicate_warning) {
|
|
1889
|
+
const matches = dupWarning.similar_tasks ?? [];
|
|
1890
|
+
console.error(`Found ${matches.length} similar task(s) in this project:`);
|
|
1891
|
+
for (const t of matches) {
|
|
1892
|
+
console.error(` ${t.visible_id ?? "(no id)"} \u2014 ${t.title} (${t.status})`);
|
|
1893
|
+
}
|
|
1894
|
+
console.error("\nRe-run with --force to create anyway.");
|
|
1895
|
+
process.exitCode = 1;
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
console.log(JSON.stringify(task, null, 2));
|
|
1899
|
+
} catch (err) {
|
|
1900
|
+
console.error(formatErrorForCli(err));
|
|
1901
|
+
process.exitCode = 1;
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
cmd.command("update <id>").description("Update a task").option("-t, --title <title>").option("-d, --description <text>").option("-s, --status <status>").option("--priority <level>").option("--due <date>", "ISO 8601 date").option("--parent <id>", 'parent task ID or visible_id (use "none" to detach)').option("-a, --assignee <id...>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1906
|
+
try {
|
|
1907
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1908
|
+
const task = await client.tasks.update(id, {
|
|
1909
|
+
title: opts.title,
|
|
1910
|
+
description: opts.description,
|
|
1911
|
+
status: opts.status,
|
|
1912
|
+
priority: opts.priority,
|
|
1913
|
+
assignee_ids: opts.assignee,
|
|
1914
|
+
parent_task_id: opts.parent === "none" ? null : opts.parent
|
|
1915
|
+
});
|
|
1916
|
+
console.log(JSON.stringify(task, null, 2));
|
|
1917
|
+
} catch (err) {
|
|
1918
|
+
console.error(formatErrorForCli(err));
|
|
1919
|
+
process.exitCode = 1;
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
});
|
|
1923
|
+
cmd.command("complete <id>").description("Mark a task as completed").option("-p, --profile <name>").action(async (id, opts) => {
|
|
1924
|
+
try {
|
|
1925
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1926
|
+
await client.tasks.update(id, { status: "completed" });
|
|
1927
|
+
console.log(`\u2713 Completed ${id}`);
|
|
1928
|
+
} catch (err) {
|
|
1929
|
+
console.error(formatErrorForCli(err));
|
|
1930
|
+
process.exitCode = 1;
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
cmd.command("comment <id> <content>").description("Add a comment to a task").option("--attach <path...>", "file(s) to attach (repeatable, any type, max 25MB each)").option("-p, --profile <name>").action(async (id, content, opts) => {
|
|
1935
|
+
try {
|
|
1936
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1937
|
+
const attachments = opts.attach ? await uploadAttachments(client, opts.attach) : void 0;
|
|
1938
|
+
await client.tasks.addComment(id, content, attachments);
|
|
1939
|
+
console.log(`\u2713 Comment added to ${id}`);
|
|
1940
|
+
} catch (err) {
|
|
1941
|
+
console.error(formatErrorForCli(err));
|
|
1942
|
+
process.exitCode = 1;
|
|
1943
|
+
return;
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
// src/commands/time.ts
|
|
1949
|
+
function parseDuration(input) {
|
|
1950
|
+
const match = input.match(/^(\d+(?:\.\d+)?)\s*(m|min|mins|minutes|h|hr|hrs|hours)?$/i);
|
|
1951
|
+
if (!match) throw new Error(`Bad duration "${input}". Try 90m or 1.5h.`);
|
|
1952
|
+
const n = parseFloat(match[1]);
|
|
1953
|
+
const unit = (match[2] ?? "m").toLowerCase();
|
|
1954
|
+
const minutes = Math.round(unit.startsWith("h") ? n * 60 : n);
|
|
1955
|
+
if (minutes <= 0) throw new Error(`Duration must be greater than zero (got "${input}").`);
|
|
1956
|
+
return minutes;
|
|
1957
|
+
}
|
|
1958
|
+
function resolveStartTime(date, at) {
|
|
1959
|
+
if (!date && !at) return void 0;
|
|
1960
|
+
const now = /* @__PURE__ */ new Date();
|
|
1961
|
+
const localToday = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
|
1962
|
+
const day = date ?? localToday;
|
|
1963
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(day)) {
|
|
1964
|
+
throw new Error(`Bad date "${day}". Use YYYY-MM-DD.`);
|
|
1965
|
+
}
|
|
1966
|
+
const clock = at ?? "09:00";
|
|
1967
|
+
const clockMatch = clock.match(/^(\d{1,2}):(\d{2})$/);
|
|
1968
|
+
if (!clockMatch) throw new Error(`Bad time "${clock}". Use HH:MM (24-hour).`);
|
|
1969
|
+
const hours = parseInt(clockMatch[1], 10);
|
|
1970
|
+
const minutes = parseInt(clockMatch[2], 10);
|
|
1971
|
+
if (hours > 23 || minutes > 59) throw new Error(`Bad time "${clock}". Use HH:MM (24-hour).`);
|
|
1972
|
+
const local = /* @__PURE__ */ new Date(`${day}T${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}:00`);
|
|
1973
|
+
if (Number.isNaN(local.getTime())) throw new Error(`Bad date/time "${day} ${clock}".`);
|
|
1974
|
+
return local.toISOString();
|
|
1975
|
+
}
|
|
1976
|
+
function registerTimeCommands(parent) {
|
|
1977
|
+
const cmd = parent.command("time").description("Manage time entries");
|
|
1978
|
+
cmd.command("list").description("List time entries").option("--project <id>").option("--task <id>").option("--user <id>").option("--running", "only running entries").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
1979
|
+
try {
|
|
1980
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
1981
|
+
const rows = await client.timeEntries.list({
|
|
1982
|
+
project_id: opts.project,
|
|
1983
|
+
task_id: opts.task,
|
|
1984
|
+
user_id: opts.user,
|
|
1985
|
+
is_running: opts.running ? "true" : void 0,
|
|
1986
|
+
limit: opts.limit
|
|
1987
|
+
});
|
|
1988
|
+
console.log(render(rows, [
|
|
1989
|
+
{ header: "Description", get: (r) => r.description, truncate: 40 },
|
|
1990
|
+
{ header: "Duration", get: (r) => r.duration_minutes != null ? `${r.duration_minutes}m` : "" },
|
|
1991
|
+
{ header: "Type", get: (r) => r.task_type },
|
|
1992
|
+
{ header: "Start", get: (r) => r.start_time?.slice(0, 16) },
|
|
1993
|
+
{ header: "Running", get: (r) => r.is_running ? "yes" : "" },
|
|
1994
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
1995
|
+
], opts.output ?? defaultFormat()));
|
|
1996
|
+
} catch (err) {
|
|
1997
|
+
console.error(formatErrorForCli(err));
|
|
1998
|
+
process.exitCode = 1;
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
});
|
|
2002
|
+
cmd.command("log").description("Log a manual time entry (e.g., 90m, 1.5h). Defaults to today unless --date is given.").requiredOption("-d, --duration <amount>", "duration like 90m or 1.5h").option("--task <id>", "task ID").option("--project <id>", "project ID").option("--type <type>", "work type (e.g., development, meeting)").option("--description <text>").option("--date <YYYY-MM-DD>", "date the work happened (default: today)").option("--at <HH:MM>", "start time on that date, 24-hour (default: 09:00)").option("-p, --profile <name>").action(async (opts) => {
|
|
2003
|
+
try {
|
|
2004
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2005
|
+
const minutes = parseDuration(opts.duration);
|
|
2006
|
+
const startTime = resolveStartTime(opts.date, opts.at);
|
|
2007
|
+
const entry = await client.timeEntries.create({
|
|
2008
|
+
duration_minutes: minutes,
|
|
2009
|
+
task_id: opts.task,
|
|
2010
|
+
project_id: opts.project,
|
|
2011
|
+
task_type: opts.type,
|
|
2012
|
+
description: opts.description,
|
|
2013
|
+
start_time: startTime,
|
|
2014
|
+
end_time: startTime ? new Date(new Date(startTime).getTime() + minutes * 6e4).toISOString() : void 0
|
|
2015
|
+
});
|
|
2016
|
+
console.log(JSON.stringify(entry, null, 2));
|
|
2017
|
+
} catch (err) {
|
|
2018
|
+
console.error(formatErrorForCli(err));
|
|
2019
|
+
process.exitCode = 1;
|
|
2020
|
+
return;
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
2023
|
+
cmd.command("update <id>").description("Update a time entry (re-date it, change its length, or edit its details)").option("-d, --duration <amount>", "new duration like 90m or 1.5h").option("--date <YYYY-MM-DD>", "move the entry to this date (duration is preserved)").option("--at <HH:MM>", "start time on that date, 24-hour (default: 09:00)").option("--task <id>", "task ID").option("--project <id>", "project ID").option("--type <type>", "work type (e.g., development, meeting)").option("--description <text>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2024
|
+
try {
|
|
2025
|
+
if (opts.at && !opts.date) {
|
|
2026
|
+
throw new Error("--at needs --date, so the entry does not silently move to today.");
|
|
2027
|
+
}
|
|
2028
|
+
const updates = {
|
|
2029
|
+
duration_minutes: opts.duration ? parseDuration(opts.duration) : void 0,
|
|
2030
|
+
start_time: resolveStartTime(opts.date, opts.at),
|
|
2031
|
+
task_id: opts.task,
|
|
2032
|
+
project_id: opts.project,
|
|
2033
|
+
task_type: opts.type,
|
|
2034
|
+
description: opts.description
|
|
2035
|
+
};
|
|
2036
|
+
if (Object.values(updates).every((v) => v === void 0)) {
|
|
2037
|
+
throw new Error("Nothing to update. Pass at least one of --duration, --date, --task, --project, --type, --description.");
|
|
2038
|
+
}
|
|
2039
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2040
|
+
const entry = await client.timeEntries.update(id, updates);
|
|
2041
|
+
console.log(JSON.stringify(entry, null, 2));
|
|
2042
|
+
} catch (err) {
|
|
2043
|
+
console.error(formatErrorForCli(err));
|
|
2044
|
+
process.exitCode = 1;
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
});
|
|
2048
|
+
cmd.command("delete <id>").description("Delete a time entry").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2049
|
+
try {
|
|
2050
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2051
|
+
await client.timeEntries.delete(id);
|
|
2052
|
+
console.log("\u2713 Deleted");
|
|
2053
|
+
} catch (err) {
|
|
2054
|
+
console.error(formatErrorForCli(err));
|
|
2055
|
+
process.exitCode = 1;
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
});
|
|
2059
|
+
cmd.command("start").description("Start a running time entry").option("--task <id>").option("--project <id>").option("--type <type>").option("--description <text>").option("-p, --profile <name>").action(async (opts) => {
|
|
2060
|
+
try {
|
|
2061
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2062
|
+
const entry = await client.timeEntries.create({
|
|
2063
|
+
start_time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2064
|
+
task_id: opts.task,
|
|
2065
|
+
project_id: opts.project,
|
|
2066
|
+
task_type: opts.type,
|
|
2067
|
+
description: opts.description
|
|
2068
|
+
});
|
|
2069
|
+
console.log(JSON.stringify(entry, null, 2));
|
|
2070
|
+
} catch (err) {
|
|
2071
|
+
console.error(formatErrorForCli(err));
|
|
2072
|
+
process.exitCode = 1;
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
// src/commands/invoice.ts
|
|
2079
|
+
function registerInvoiceCommands(parent) {
|
|
2080
|
+
const cmd = parent.command("invoice").alias("invoices").description("Manage invoices");
|
|
2081
|
+
cmd.command("list").description("List invoices").option("-s, --status <status>", "draft|sent|paid|overdue|cancelled").option("-a, --account <id>").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2082
|
+
try {
|
|
2083
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2084
|
+
const rows = await client.invoices.list({
|
|
2085
|
+
status: opts.status,
|
|
2086
|
+
account_id: opts.account,
|
|
2087
|
+
limit: opts.limit
|
|
2088
|
+
});
|
|
2089
|
+
console.log(render(rows, [
|
|
2090
|
+
{ header: "Number", get: (r) => r.invoice_number },
|
|
2091
|
+
{ header: "Title", get: (r) => r.title, truncate: 30 },
|
|
2092
|
+
{ header: "Status", get: (r) => r.status },
|
|
2093
|
+
{ header: "Total", get: (r) => r.total != null ? `$${r.total.toLocaleString()}` : "" },
|
|
2094
|
+
{ header: "Due", get: (r) => r.due_date },
|
|
2095
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2096
|
+
], opts.output ?? defaultFormat()));
|
|
2097
|
+
} catch (err) {
|
|
2098
|
+
console.error(formatErrorForCli(err));
|
|
2099
|
+
process.exitCode = 1;
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
cmd.command("get <id>").description("Get an invoice by ID").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2104
|
+
try {
|
|
2105
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2106
|
+
const invoice = await client.invoices.get(id);
|
|
2107
|
+
console.log(JSON.stringify(invoice, null, 2));
|
|
2108
|
+
} catch (err) {
|
|
2109
|
+
console.error(formatErrorForCli(err));
|
|
2110
|
+
process.exitCode = 1;
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
});
|
|
2114
|
+
cmd.command("create").description("Create an invoice").requiredOption("-t, --title <title>", "invoice title (required)").option("-d, --description <text>").option("-a, --account <id>").option("--tax-rate <pct>", "tax rate %", parseFloat).option("--issue-date <date>", "ISO 8601").option("--due-date <date>", "ISO 8601").option("--notes <text>", "client-visible notes").option("--internal-notes <text>").option("-p, --profile <name>").action(async (opts) => {
|
|
2115
|
+
try {
|
|
2116
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2117
|
+
const invoice = await client.invoices.create({
|
|
2118
|
+
title: opts.title,
|
|
2119
|
+
description: opts.description,
|
|
2120
|
+
account_id: opts.account,
|
|
2121
|
+
tax_rate: opts.taxRate,
|
|
2122
|
+
issue_date: opts.issueDate,
|
|
2123
|
+
due_date: opts.dueDate,
|
|
2124
|
+
notes: opts.notes,
|
|
2125
|
+
internal_notes: opts.internalNotes
|
|
2126
|
+
});
|
|
2127
|
+
console.log(JSON.stringify(invoice, null, 2));
|
|
2128
|
+
} catch (err) {
|
|
2129
|
+
console.error(formatErrorForCli(err));
|
|
2130
|
+
process.exitCode = 1;
|
|
2131
|
+
return;
|
|
2132
|
+
}
|
|
2133
|
+
});
|
|
2134
|
+
cmd.command("update <id>").description("Update an invoice").option("-t, --title <title>").option("-s, --status <status>", "draft|sent|paid|overdue|cancelled").option("--tax-rate <pct>", "", parseFloat).option("--due-date <date>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2135
|
+
try {
|
|
2136
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2137
|
+
const invoice = await client.invoices.update(id, {
|
|
2138
|
+
title: opts.title,
|
|
2139
|
+
status: opts.status,
|
|
2140
|
+
tax_rate: opts.taxRate,
|
|
2141
|
+
due_date: opts.dueDate
|
|
2142
|
+
});
|
|
2143
|
+
console.log(JSON.stringify(invoice, null, 2));
|
|
2144
|
+
} catch (err) {
|
|
2145
|
+
console.error(formatErrorForCli(err));
|
|
2146
|
+
process.exitCode = 1;
|
|
2147
|
+
return;
|
|
2148
|
+
}
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
// src/commands/estimate.ts
|
|
2153
|
+
function registerEstimateCommands(parent) {
|
|
2154
|
+
const cmd = parent.command("estimate").alias("estimates").description("Manage estimates");
|
|
2155
|
+
cmd.command("list").description("List estimates").option("-s, --status <status>").option("-a, --account <id>").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2156
|
+
try {
|
|
2157
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2158
|
+
const rows = await client.estimates.list({
|
|
2159
|
+
status: opts.status,
|
|
2160
|
+
account_id: opts.account,
|
|
2161
|
+
limit: opts.limit
|
|
2162
|
+
});
|
|
2163
|
+
console.log(render(rows, [
|
|
2164
|
+
{ header: "Number", get: (r) => r.estimate_number },
|
|
2165
|
+
{ header: "Title", get: (r) => r.title, truncate: 30 },
|
|
2166
|
+
{ header: "Status", get: (r) => r.status },
|
|
2167
|
+
{ header: "Total", get: (r) => r.total != null ? `$${r.total.toLocaleString()}` : "" },
|
|
2168
|
+
{ header: "Expires", get: (r) => r.expiry_date },
|
|
2169
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2170
|
+
], opts.output ?? defaultFormat()));
|
|
2171
|
+
} catch (err) {
|
|
2172
|
+
console.error(formatErrorForCli(err));
|
|
2173
|
+
process.exitCode = 1;
|
|
2174
|
+
return;
|
|
2175
|
+
}
|
|
2176
|
+
});
|
|
2177
|
+
cmd.command("create").description("Create an estimate").requiredOption("-t, --title <title>", "estimate title (required)").option("-d, --description <text>").option("-a, --account <id>").option("--tax-rate <pct>", "", parseFloat).option("--issue-date <date>").option("--expiry-date <date>").option("--notes <text>").option("-p, --profile <name>").action(async (opts) => {
|
|
2178
|
+
try {
|
|
2179
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2180
|
+
const estimate = await client.estimates.create({
|
|
2181
|
+
title: opts.title,
|
|
2182
|
+
description: opts.description,
|
|
2183
|
+
account_id: opts.account,
|
|
2184
|
+
tax_rate: opts.taxRate,
|
|
2185
|
+
issue_date: opts.issueDate,
|
|
2186
|
+
expiry_date: opts.expiryDate,
|
|
2187
|
+
notes: opts.notes
|
|
2188
|
+
});
|
|
2189
|
+
console.log(JSON.stringify(estimate, null, 2));
|
|
2190
|
+
} catch (err) {
|
|
2191
|
+
console.error(formatErrorForCli(err));
|
|
2192
|
+
process.exitCode = 1;
|
|
2193
|
+
return;
|
|
2194
|
+
}
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
// src/commands/product.ts
|
|
2199
|
+
function formatRate(p) {
|
|
2200
|
+
if (p.default_rate == null) return "\u2014";
|
|
2201
|
+
const formatted = new Intl.NumberFormat(void 0, {
|
|
2202
|
+
style: "currency",
|
|
2203
|
+
currency: p.currency || "USD",
|
|
2204
|
+
maximumFractionDigits: 2
|
|
2205
|
+
}).format(Number(p.default_rate));
|
|
2206
|
+
const suffix = p.billing_interval ? `/ ${p.billing_interval}` : `/ ${p.unit}`;
|
|
2207
|
+
return `${formatted} ${suffix}`;
|
|
2208
|
+
}
|
|
2209
|
+
function formatTier(t) {
|
|
2210
|
+
const price = t.effective_price ?? t.amount;
|
|
2211
|
+
if (price == null) return "on request";
|
|
2212
|
+
const fmt = (n) => new Intl.NumberFormat(void 0, {
|
|
2213
|
+
style: "currency",
|
|
2214
|
+
currency: t.currency || "USD",
|
|
2215
|
+
maximumFractionDigits: 2
|
|
2216
|
+
}).format(Number(n));
|
|
2217
|
+
if (t.sale_amount != null && t.amount != null && Number(t.sale_amount) < Number(t.amount)) {
|
|
2218
|
+
return `${fmt(Number(t.sale_amount))} (was ${fmt(Number(t.amount))})`;
|
|
2219
|
+
}
|
|
2220
|
+
return fmt(Number(price));
|
|
2221
|
+
}
|
|
2222
|
+
function registerProductCommands(parent) {
|
|
2223
|
+
const cmd = parent.command("product").alias("products").description("Manage the workspace product catalog");
|
|
2224
|
+
cmd.command("list").description("List products in the catalog").option("-c, --category <name>").option("-b, --billing <interval>", "day | week | month | year | one_time").option("--include-archived", "include archived products").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 100).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2225
|
+
try {
|
|
2226
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2227
|
+
const rows = await client.products.list({
|
|
2228
|
+
category: opts.category,
|
|
2229
|
+
billing_interval: opts.billing,
|
|
2230
|
+
active_only: !opts.includeArchived,
|
|
2231
|
+
limit: opts.limit
|
|
2232
|
+
});
|
|
2233
|
+
console.log(render(rows, [
|
|
2234
|
+
{ header: "Name", get: (r) => r.name, truncate: 30 },
|
|
2235
|
+
{ header: "Billing", get: (r) => r.billing_interval ? `Recurring (${r.billing_interval})` : "One-time" },
|
|
2236
|
+
{ header: "Rate", get: (r) => formatRate(r) },
|
|
2237
|
+
{ header: "Category", get: (r) => r.category ?? "" },
|
|
2238
|
+
{ header: "Active", get: (r) => r.is_active === false ? "no" : "yes" },
|
|
2239
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2240
|
+
], opts.output ?? defaultFormat()));
|
|
2241
|
+
} catch (err) {
|
|
2242
|
+
console.error(formatErrorForCli(err));
|
|
2243
|
+
process.exitCode = 1;
|
|
2244
|
+
return;
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
cmd.command("get <idOrName>").description("Get a product by id or fuzzy name match").option("-p, --profile <name>").action(async (idOrName, opts) => {
|
|
2248
|
+
try {
|
|
2249
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2250
|
+
const isUuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(idOrName);
|
|
2251
|
+
const result = await client.products.get(isUuid ? { product_id: idOrName } : { name: idOrName });
|
|
2252
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2253
|
+
if (!result.found) {
|
|
2254
|
+
process.exitCode = 1;
|
|
2255
|
+
return;
|
|
2256
|
+
}
|
|
2257
|
+
} catch (err) {
|
|
2258
|
+
console.error(formatErrorForCli(err));
|
|
2259
|
+
process.exitCode = 1;
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
});
|
|
2263
|
+
cmd.command("create").description("Create a new product").requiredOption("-n, --name <name>", "product name (required)").option("-d, --description <text>").option("-c, --category <name>").option("-b, --billing <interval>", "day | week | month | year (omit for one-time)").option("-r, --rate <amount>", "default rate", parseFloat).option("-u, --unit <unit>", "hour | day | week | month | project | unit | license | seat | word | page").option("--currency <iso>", "3-letter ISO code", "USD").option("--tax-rate <pct>", "", parseFloat).option("--positioning <text>").option("--deliverable <text...>", "repeatable; one per deliverable").option("-p, --profile <name>").action(async (opts) => {
|
|
2264
|
+
try {
|
|
2265
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2266
|
+
const product = await client.products.create({
|
|
2267
|
+
name: opts.name,
|
|
2268
|
+
description: opts.description,
|
|
2269
|
+
category: opts.category,
|
|
2270
|
+
billing_interval: opts.billing,
|
|
2271
|
+
default_rate: opts.rate,
|
|
2272
|
+
unit: opts.unit,
|
|
2273
|
+
currency: opts.currency,
|
|
2274
|
+
tax_rate: opts.taxRate,
|
|
2275
|
+
positioning: opts.positioning,
|
|
2276
|
+
deliverables: opts.deliverable
|
|
2277
|
+
});
|
|
2278
|
+
console.log(JSON.stringify(product, null, 2));
|
|
2279
|
+
} catch (err) {
|
|
2280
|
+
console.error(formatErrorForCli(err));
|
|
2281
|
+
process.exitCode = 1;
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
cmd.command("update <productId>").description("Update a product (only the flags you pass are changed)").option("-n, --name <name>").option("-d, --description <text>").option("-c, --category <name>").option("-b, --billing <interval>", "day | week | month | year").option("-r, --rate <amount>", "default rate", parseFloat).option("-u, --unit <unit>", "hour | day | week | month | project | unit | license | seat | word | page").option("--currency <iso>", "3-letter ISO code").option("--tax-rate <pct>", "", parseFloat).option("--positioning <text>").option("--deliverable <text...>", "repeatable; replaces the full deliverables list").option("--active <bool>", "true to reactivate, false to archive", (v) => v === "true").option("-p, --profile <name>").action(async (productId, opts) => {
|
|
2286
|
+
try {
|
|
2287
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2288
|
+
const product = await client.products.update({
|
|
2289
|
+
product_id: productId,
|
|
2290
|
+
name: opts.name,
|
|
2291
|
+
description: opts.description,
|
|
2292
|
+
category: opts.category,
|
|
2293
|
+
billing_interval: opts.billing,
|
|
2294
|
+
default_rate: opts.rate,
|
|
2295
|
+
unit: opts.unit,
|
|
2296
|
+
currency: opts.currency,
|
|
2297
|
+
tax_rate: opts.taxRate,
|
|
2298
|
+
positioning: opts.positioning,
|
|
2299
|
+
deliverables: opts.deliverable,
|
|
2300
|
+
is_active: opts.active
|
|
2301
|
+
});
|
|
2302
|
+
console.log(JSON.stringify(product, null, 2));
|
|
2303
|
+
} catch (err) {
|
|
2304
|
+
console.error(formatErrorForCli(err));
|
|
2305
|
+
process.exitCode = 1;
|
|
2306
|
+
return;
|
|
2307
|
+
}
|
|
2308
|
+
});
|
|
2309
|
+
cmd.command("archive <productId>").description("Archive a product (hides it from active lists; keeps history)").option("--unarchive", "reactivate a previously archived product instead").option("-p, --profile <name>").action(async (productId, opts) => {
|
|
2310
|
+
try {
|
|
2311
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2312
|
+
const result = await client.products.archive({ product_id: productId, unarchive: opts.unarchive });
|
|
2313
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2314
|
+
} catch (err) {
|
|
2315
|
+
console.error(formatErrorForCli(err));
|
|
2316
|
+
process.exitCode = 1;
|
|
2317
|
+
return;
|
|
2318
|
+
}
|
|
2319
|
+
});
|
|
2320
|
+
cmd.command("attach <productId>").description("Attach a product to a deal").requiredOption("--deal <id>", "deal id (required)").option("--tier <id>", "price tier id (omit for the default tier)").option("-q, --quantity <n>", "", parseFloat).option("-r, --rate <amount>", "override product/tier rate", parseFloat).option("--notes <text>").option("-p, --profile <name>").action(async (productId, opts) => {
|
|
2321
|
+
try {
|
|
2322
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2323
|
+
const result = await client.products.attachToDeal({
|
|
2324
|
+
deal_id: opts.deal,
|
|
2325
|
+
product_id: productId,
|
|
2326
|
+
product_price_id: opts.tier,
|
|
2327
|
+
quantity: opts.quantity,
|
|
2328
|
+
rate: opts.rate,
|
|
2329
|
+
notes: opts.notes
|
|
2330
|
+
});
|
|
2331
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2332
|
+
} catch (err) {
|
|
2333
|
+
console.error(formatErrorForCli(err));
|
|
2334
|
+
process.exitCode = 1;
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
});
|
|
2338
|
+
cmd.command("add-line <productId>").description("Add a line item to an invoice or estimate from a product").requiredOption("--type <kind>", "invoice | estimate").requiredOption("--doc <id>", "invoice or estimate id").option("--tier <id>", "price tier id (omit for the default tier)").option("-q, --quantity <n>", "", parseFloat).option("-r, --rate <amount>", "override product/tier rate", parseFloat).option("--description <text>", "override default description").option("-p, --profile <name>").action(async (productId, opts) => {
|
|
2339
|
+
try {
|
|
2340
|
+
if (opts.type !== "invoice" && opts.type !== "estimate") {
|
|
2341
|
+
throw new Error("--type must be 'invoice' or 'estimate'");
|
|
2342
|
+
}
|
|
2343
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2344
|
+
const result = await client.products.addLineItem({
|
|
2345
|
+
document_type: opts.type,
|
|
2346
|
+
document_id: opts.doc,
|
|
2347
|
+
product_id: productId,
|
|
2348
|
+
product_price_id: opts.tier,
|
|
2349
|
+
quantity: opts.quantity,
|
|
2350
|
+
rate_override: opts.rate,
|
|
2351
|
+
description_override: opts.description
|
|
2352
|
+
});
|
|
2353
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2354
|
+
} catch (err) {
|
|
2355
|
+
console.error(formatErrorForCli(err));
|
|
2356
|
+
process.exitCode = 1;
|
|
2357
|
+
return;
|
|
2358
|
+
}
|
|
2359
|
+
});
|
|
2360
|
+
const tier = cmd.command("tier").description("Manage a product's price tiers");
|
|
2361
|
+
tier.command("list <productId>").description("List a product's price tiers").option("-o, --output <format>").option("-p, --profile <name>").action(async (productId, opts) => {
|
|
2362
|
+
try {
|
|
2363
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2364
|
+
const rows = await client.products.prices.list(productId);
|
|
2365
|
+
console.log(render(rows, [
|
|
2366
|
+
{ header: "Label", get: (r) => r.label, truncate: 24 },
|
|
2367
|
+
{ header: "Price", get: (r) => formatTier(r) },
|
|
2368
|
+
{ header: "Billing", get: (r) => r.billing_interval ?? "one-time" },
|
|
2369
|
+
{ header: "Default", get: (r) => r.is_default ? "yes" : "" },
|
|
2370
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2371
|
+
], opts.output ?? defaultFormat()));
|
|
2372
|
+
} catch (err) {
|
|
2373
|
+
console.error(formatErrorForCli(err));
|
|
2374
|
+
process.exitCode = 1;
|
|
2375
|
+
return;
|
|
2376
|
+
}
|
|
2377
|
+
});
|
|
2378
|
+
tier.command("add <productId>").description("Add a price tier to a product (first tier becomes the default)").requiredOption("-l, --label <text>", 'tier name, e.g. "5 Sites" (required)').option("-a, --amount <amount>", "regular price", parseFloat).option("--sale <amount>", "sale price (charged when below amount)", parseFloat).option("--currency <iso>", "3-letter ISO code (defaults to product currency)").option("-b, --billing <interval>", "day | week | month | year (omit for one-time)").option("-u, --unit <unit>", "hour | day | week | month | project | unit | license | seat | word | page").option("--default", "make this the default tier").option("-p, --profile <name>").action(async (productId, opts) => {
|
|
2379
|
+
try {
|
|
2380
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2381
|
+
const price = await client.products.prices.create({
|
|
2382
|
+
product_id: productId,
|
|
2383
|
+
label: opts.label,
|
|
2384
|
+
amount: opts.amount,
|
|
2385
|
+
sale_amount: opts.sale,
|
|
2386
|
+
currency: opts.currency,
|
|
2387
|
+
billing_interval: opts.billing,
|
|
2388
|
+
unit: opts.unit,
|
|
2389
|
+
is_default: opts.default
|
|
2390
|
+
});
|
|
2391
|
+
console.log(JSON.stringify(price, null, 2));
|
|
2392
|
+
} catch (err) {
|
|
2393
|
+
console.error(formatErrorForCli(err));
|
|
2394
|
+
process.exitCode = 1;
|
|
2395
|
+
return;
|
|
2396
|
+
}
|
|
2397
|
+
});
|
|
2398
|
+
tier.command("update <priceId>").description("Update a price tier (only the flags you pass are changed)").option("-l, --label <text>").option("-a, --amount <amount>", "regular price", parseFloat).option("--sale <amount>", "sale price", parseFloat).option("--currency <iso>", "3-letter ISO code").option("-b, --billing <interval>", "day | week | month | year").option("-u, --unit <unit>", "hour | day | week | month | project | unit | license | seat | word | page").option("--default", "make this the default tier").option("-p, --profile <name>").action(async (priceId, opts) => {
|
|
2399
|
+
try {
|
|
2400
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2401
|
+
const price = await client.products.prices.update({
|
|
2402
|
+
price_id: priceId,
|
|
2403
|
+
label: opts.label,
|
|
2404
|
+
amount: opts.amount,
|
|
2405
|
+
sale_amount: opts.sale,
|
|
2406
|
+
currency: opts.currency,
|
|
2407
|
+
billing_interval: opts.billing,
|
|
2408
|
+
unit: opts.unit,
|
|
2409
|
+
is_default: opts.default ? true : void 0
|
|
2410
|
+
});
|
|
2411
|
+
console.log(JSON.stringify(price, null, 2));
|
|
2412
|
+
} catch (err) {
|
|
2413
|
+
console.error(formatErrorForCli(err));
|
|
2414
|
+
process.exitCode = 1;
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
});
|
|
2418
|
+
tier.command("rm <priceId>").description("Delete a price tier (past line items keep their snapshot)").option("-p, --profile <name>").action(async (priceId, opts) => {
|
|
2419
|
+
try {
|
|
2420
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2421
|
+
const result = await client.products.prices.delete(priceId);
|
|
2422
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2423
|
+
} catch (err) {
|
|
2424
|
+
console.error(formatErrorForCli(err));
|
|
2425
|
+
process.exitCode = 1;
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
});
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
// src/commands/form.ts
|
|
2432
|
+
function registerFormCommands(parent) {
|
|
2433
|
+
const cmd = parent.command("form").alias("forms").description("Manage lead-capture / intake forms");
|
|
2434
|
+
cmd.command("list").description("List forms in the workspace").option("-s, --status <status>", "draft | live | archived").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 100).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2435
|
+
try {
|
|
2436
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2437
|
+
const rows = await client.forms.list({ status: opts.status, limit: opts.limit });
|
|
2438
|
+
console.log(render(rows, [
|
|
2439
|
+
{ header: "Name", get: (r) => r.name, truncate: 32 },
|
|
2440
|
+
{ header: "Status", get: (r) => r.status },
|
|
2441
|
+
{ header: "Fields", get: (r) => r.field_count },
|
|
2442
|
+
{ header: "Subs", get: (r) => r.submission_count },
|
|
2443
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2444
|
+
], opts.output ?? defaultFormat()));
|
|
2445
|
+
} catch (err) {
|
|
2446
|
+
console.error(formatErrorForCli(err));
|
|
2447
|
+
process.exitCode = 1;
|
|
2448
|
+
}
|
|
2449
|
+
});
|
|
2450
|
+
cmd.command("get <formId>").description("Get a form's full structure (steps, fields, embed snippet)").option("-p, --profile <name>").action(async (formId, opts) => {
|
|
2451
|
+
try {
|
|
2452
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2453
|
+
console.log(JSON.stringify(await client.forms.get(formId), null, 2));
|
|
2454
|
+
} catch (err) {
|
|
2455
|
+
console.error(formatErrorForCli(err));
|
|
2456
|
+
process.exitCode = 1;
|
|
2457
|
+
}
|
|
2458
|
+
});
|
|
2459
|
+
cmd.command("submissions <formId>").description("Read recent submissions for a form").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 20).option("-o, --output <format>").option("-p, --profile <name>").action(async (formId, opts) => {
|
|
2460
|
+
try {
|
|
2461
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2462
|
+
const rows = await client.forms.submissions(formId, opts.limit);
|
|
2463
|
+
const fmt = opts.output ?? defaultFormat();
|
|
2464
|
+
if (fmt === "table") {
|
|
2465
|
+
console.log(render(rows, [
|
|
2466
|
+
{ header: "Submitted", get: (r) => r.submitted_at },
|
|
2467
|
+
{ header: "Data", get: (r) => JSON.stringify(r.data), truncate: 60 },
|
|
2468
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2469
|
+
], fmt));
|
|
2470
|
+
} else {
|
|
2471
|
+
console.log(render(rows, [], fmt));
|
|
2472
|
+
}
|
|
2473
|
+
} catch (err) {
|
|
2474
|
+
console.error(formatErrorForCli(err));
|
|
2475
|
+
process.exitCode = 1;
|
|
2476
|
+
}
|
|
2477
|
+
});
|
|
2478
|
+
cmd.command("stats <formId>").description("Submission counts (total / last 7d / last 30d)").option("-p, --profile <name>").action(async (formId, opts) => {
|
|
2479
|
+
try {
|
|
2480
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2481
|
+
console.log(JSON.stringify(await client.forms.stats(formId), null, 2));
|
|
2482
|
+
} catch (err) {
|
|
2483
|
+
console.error(formatErrorForCli(err));
|
|
2484
|
+
process.exitCode = 1;
|
|
2485
|
+
}
|
|
2486
|
+
});
|
|
2487
|
+
cmd.command("create").description("Create a new form (draft by default)").requiredOption("-n, --name <name>", "form name").option("-d, --description <text>").option("-s, --status <status>", "draft | live | archived", "draft").option("-p, --profile <name>").action(async (opts) => {
|
|
2488
|
+
try {
|
|
2489
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2490
|
+
const form = await client.forms.create({ name: opts.name, description: opts.description, status: opts.status });
|
|
2491
|
+
console.log(JSON.stringify(form, null, 2));
|
|
2492
|
+
} catch (err) {
|
|
2493
|
+
console.error(formatErrorForCli(err));
|
|
2494
|
+
process.exitCode = 1;
|
|
2495
|
+
}
|
|
2496
|
+
});
|
|
2497
|
+
cmd.command("add-step <formId>").description("Add a step (page) to a form").option("-t, --title <text>", "step heading").option("--subtitle <text>").option("-p, --profile <name>").action(async (formId, opts) => {
|
|
2498
|
+
try {
|
|
2499
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2500
|
+
const step = await client.forms.addStep({ form_id: formId, title: opts.title, subtitle: opts.subtitle });
|
|
2501
|
+
console.log(JSON.stringify(step, null, 2));
|
|
2502
|
+
} catch (err) {
|
|
2503
|
+
console.error(formatErrorForCli(err));
|
|
2504
|
+
process.exitCode = 1;
|
|
2505
|
+
}
|
|
2506
|
+
});
|
|
2507
|
+
cmd.command("add-field <formId>").description("Add a field to a form").requiredOption("-t, --type <type>", "text|textarea|email|phone|number|date|time|select|radio|checkbox|consent|file|choice_cards (consent = email opt-in gate for broadcasts; label is the consent statement)").requiredOption("-l, --label <label>", "field label").option("--required", "mark the field required").option("--placeholder <text>").option("--options <list>", "comma-separated choices (for select/radio/checkbox/choice_cards)", (v) => v.split(",").map((s) => s.trim()).filter(Boolean)).option("--step <stepId>", "step UUID to place the field in").option("-p, --profile <name>").action(async (formId, opts) => {
|
|
2508
|
+
try {
|
|
2509
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2510
|
+
const field = await client.forms.addField({
|
|
2511
|
+
form_id: formId,
|
|
2512
|
+
type: opts.type,
|
|
2513
|
+
label: opts.label,
|
|
2514
|
+
required: !!opts.required,
|
|
2515
|
+
placeholder: opts.placeholder,
|
|
2516
|
+
options: opts.options,
|
|
2517
|
+
step_id: opts.step
|
|
2518
|
+
});
|
|
2519
|
+
console.log(JSON.stringify(field, null, 2));
|
|
2520
|
+
} catch (err) {
|
|
2521
|
+
console.error(formatErrorForCli(err));
|
|
2522
|
+
process.exitCode = 1;
|
|
2523
|
+
}
|
|
2524
|
+
});
|
|
2525
|
+
cmd.command("status <formId> <status>").description("Set a form status: draft | live | archived").option("-p, --profile <name>").action(async (formId, status, opts) => {
|
|
2526
|
+
try {
|
|
2527
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2528
|
+
console.log(JSON.stringify(await client.forms.setStatus(formId, status), null, 2));
|
|
2529
|
+
} catch (err) {
|
|
2530
|
+
console.error(formatErrorForCli(err));
|
|
2531
|
+
process.exitCode = 1;
|
|
2532
|
+
}
|
|
2533
|
+
});
|
|
2534
|
+
cmd.command("update-field <fieldId>").description("Edit an existing form field (get field IDs from `form get`). Pass only what changes.").option("-t, --type <type>", "text|textarea|email|phone|number|date|time|select|radio|checkbox|consent|file|choice_cards").option("-l, --label <label>", "field label").option("--required", "mark the field required").option("--not-required", "mark the field optional").option("--placeholder <text>").option("--options <list>", "replacement comma-separated choices (for select/radio/checkbox/choice_cards)", (v) => v.split(",").map((s) => s.trim()).filter(Boolean)).option("--step <stepId>", "move the field into this step UUID").option("--unset-step", "move the field out of any step").option("--position <n>", "ordering position within the form", (v) => parseInt(v, 10)).option("-p, --profile <name>").action(async (fieldId, opts) => {
|
|
2535
|
+
try {
|
|
2536
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2537
|
+
const updates = {};
|
|
2538
|
+
if (opts.type !== void 0) updates.type = opts.type;
|
|
2539
|
+
if (opts.label !== void 0) updates.label = opts.label;
|
|
2540
|
+
if (opts.required) updates.required = true;
|
|
2541
|
+
if (opts.notRequired) updates.required = false;
|
|
2542
|
+
if (opts.placeholder !== void 0) updates.placeholder = opts.placeholder;
|
|
2543
|
+
if (opts.options !== void 0) updates.options = opts.options;
|
|
2544
|
+
if (opts.unsetStep) updates.step_id = null;
|
|
2545
|
+
else if (typeof opts.step === "string") updates.step_id = opts.step;
|
|
2546
|
+
if (opts.position !== void 0) updates.position = opts.position;
|
|
2547
|
+
const field = await client.forms.updateField(fieldId, updates);
|
|
2548
|
+
console.log(JSON.stringify(field, null, 2));
|
|
2549
|
+
} catch (err) {
|
|
2550
|
+
console.error(formatErrorForCli(err));
|
|
2551
|
+
process.exitCode = 1;
|
|
2552
|
+
}
|
|
2553
|
+
});
|
|
2554
|
+
cmd.command("remove-field <fieldId>").alias("delete-field").description("Remove a field from a form (get field IDs from `form get`). Existing submissions are kept.").option("-p, --profile <name>").action(async (fieldId, opts) => {
|
|
2555
|
+
try {
|
|
2556
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2557
|
+
console.log(JSON.stringify(await client.forms.removeField(fieldId), null, 2));
|
|
2558
|
+
} catch (err) {
|
|
2559
|
+
console.error(formatErrorForCli(err));
|
|
2560
|
+
process.exitCode = 1;
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
cmd.command("update-step <stepId>").description("Edit a form step / page (get step IDs from `form get`). Pass only what changes.").option("-t, --title <text>", "step heading").option("--subtitle <text>").option("--position <n>", "ordering position among steps", (v) => parseInt(v, 10)).option("-p, --profile <name>").action(async (stepId, opts) => {
|
|
2564
|
+
try {
|
|
2565
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2566
|
+
const updates = {};
|
|
2567
|
+
if (opts.title !== void 0) updates.title = opts.title;
|
|
2568
|
+
if (opts.subtitle !== void 0) updates.subtitle = opts.subtitle;
|
|
2569
|
+
if (opts.position !== void 0) updates.position = opts.position;
|
|
2570
|
+
const step = await client.forms.updateStep(stepId, updates);
|
|
2571
|
+
console.log(JSON.stringify(step, null, 2));
|
|
2572
|
+
} catch (err) {
|
|
2573
|
+
console.error(formatErrorForCli(err));
|
|
2574
|
+
process.exitCode = 1;
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
cmd.command("remove-step <stepId>").alias("delete-step").description("Remove a step / page from a form (get step IDs from `form get`). Its fields are kept on the form.").option("-p, --profile <name>").action(async (stepId, opts) => {
|
|
2578
|
+
try {
|
|
2579
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2580
|
+
console.log(JSON.stringify(await client.forms.removeStep(stepId), null, 2));
|
|
2581
|
+
} catch (err) {
|
|
2582
|
+
console.error(formatErrorForCli(err));
|
|
2583
|
+
process.exitCode = 1;
|
|
2584
|
+
}
|
|
2585
|
+
});
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
// src/commands/calendar.ts
|
|
2589
|
+
function registerCalendarCommands(parent) {
|
|
2590
|
+
const cmd = parent.command("calendar").alias("cal").description("Manage calendar events");
|
|
2591
|
+
cmd.command("list").description("List calendar events (defaults to next 7 days)").option("--start <date>", "ISO 8601 start").option("--end <date>", "ISO 8601 end").option("--all-users", "deprecated and ignored; a calendar is personal").option("--project <id>").option("--account <id>").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2592
|
+
try {
|
|
2593
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2594
|
+
const rows = await client.calendar.list({
|
|
2595
|
+
start: opts.start,
|
|
2596
|
+
end: opts.end,
|
|
2597
|
+
include_all_users: opts.allUsers,
|
|
2598
|
+
project_id: opts.project,
|
|
2599
|
+
account_id: opts.account,
|
|
2600
|
+
limit: opts.limit
|
|
2601
|
+
});
|
|
2602
|
+
console.log(render(rows, [
|
|
2603
|
+
{ header: "Title", get: (r) => r.title, truncate: 40 },
|
|
2604
|
+
{ header: "Start", get: (r) => r.start_time?.slice(0, 16) },
|
|
2605
|
+
{ header: "End", get: (r) => r.end_time?.slice(0, 16) },
|
|
2606
|
+
{ header: "Status", get: (r) => r.status },
|
|
2607
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2608
|
+
], opts.output ?? defaultFormat()));
|
|
2609
|
+
} catch (err) {
|
|
2610
|
+
console.error(formatErrorForCli(err));
|
|
2611
|
+
process.exitCode = 1;
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
});
|
|
2615
|
+
cmd.command("create").description("Create a calendar event").requiredOption("-t, --title <title>").requiredOption("--start <date>", "ISO 8601 start time").requiredOption("--end <date>", "ISO 8601 end time").option("-d, --description <text>").option("--location <text>").option("--all-day").option("--meet", "auto-create Google Meet link").option("--zoom <url>", "attach a Zoom URL").option("--project <id>").option("--account <id>").option("-p, --profile <name>").action(async (opts) => {
|
|
2616
|
+
try {
|
|
2617
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2618
|
+
const event = await client.calendar.create({
|
|
2619
|
+
title: opts.title,
|
|
2620
|
+
start_time: opts.start,
|
|
2621
|
+
end_time: opts.end,
|
|
2622
|
+
description: opts.description,
|
|
2623
|
+
location: opts.location,
|
|
2624
|
+
all_day: opts.allDay,
|
|
2625
|
+
conference_provider: opts.meet ? "google_meet" : opts.zoom ? "zoom" : void 0,
|
|
2626
|
+
conference_url: opts.zoom,
|
|
2627
|
+
project_id: opts.project,
|
|
2628
|
+
account_id: opts.account
|
|
2629
|
+
});
|
|
2630
|
+
console.log(JSON.stringify(event, null, 2));
|
|
2631
|
+
} catch (err) {
|
|
2632
|
+
console.error(formatErrorForCli(err));
|
|
2633
|
+
process.exitCode = 1;
|
|
2634
|
+
return;
|
|
2635
|
+
}
|
|
2636
|
+
});
|
|
2637
|
+
cmd.command("delete <id>").description("Delete a calendar event").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2638
|
+
try {
|
|
2639
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2640
|
+
await client.calendar.delete(id);
|
|
2641
|
+
console.log(`\u2713 Deleted ${id}`);
|
|
2642
|
+
} catch (err) {
|
|
2643
|
+
console.error(formatErrorForCli(err));
|
|
2644
|
+
process.exitCode = 1;
|
|
2645
|
+
return;
|
|
2646
|
+
}
|
|
2647
|
+
});
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// src/commands/doc.ts
|
|
2651
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
2652
|
+
function readContent(opts) {
|
|
2653
|
+
if (opts.contentFile) return readFileSync2(opts.contentFile, "utf8");
|
|
2654
|
+
if (opts.content === "-") return readFileSync2(0, "utf8");
|
|
2655
|
+
return opts.content;
|
|
2656
|
+
}
|
|
2657
|
+
function registerDocCommands(parent) {
|
|
2658
|
+
const cmd = parent.command("doc").alias("docs").description("Manage documents");
|
|
2659
|
+
cmd.command("list").description("List documents").option("-s, --status <status>", "draft|published|archived").option("--visibility <vis>", "private|workspace|shared|public").option("--category <cat>").option("--project <id>").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 50).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2660
|
+
try {
|
|
2661
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2662
|
+
const rows = await client.documents.list({
|
|
2663
|
+
status: opts.status,
|
|
2664
|
+
visibility: opts.visibility,
|
|
2665
|
+
category: opts.category,
|
|
2666
|
+
project_id: opts.project,
|
|
2667
|
+
limit: opts.limit
|
|
2668
|
+
});
|
|
2669
|
+
console.log(render(rows, [
|
|
2670
|
+
{ header: "Title", get: (r) => r.title, truncate: 40 },
|
|
2671
|
+
{ header: "Status", get: (r) => r.status },
|
|
2672
|
+
{ header: "Visibility", get: (r) => r.visibility },
|
|
2673
|
+
{ header: "Updated", get: (r) => r.updated_at?.slice(0, 10) },
|
|
2674
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2675
|
+
], opts.output ?? defaultFormat()));
|
|
2676
|
+
} catch (err) {
|
|
2677
|
+
console.error(formatErrorForCli(err));
|
|
2678
|
+
process.exitCode = 1;
|
|
2679
|
+
return;
|
|
2680
|
+
}
|
|
2681
|
+
});
|
|
2682
|
+
cmd.command("get <id>").description("Get a document by ID").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2683
|
+
try {
|
|
2684
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2685
|
+
const doc = await client.documents.get(id);
|
|
2686
|
+
console.log(JSON.stringify(doc, null, 2));
|
|
2687
|
+
} catch (err) {
|
|
2688
|
+
console.error(formatErrorForCli(err));
|
|
2689
|
+
process.exitCode = 1;
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
});
|
|
2693
|
+
cmd.command("create").description("Create a document (content from --content, --content-file, or stdin with -c -)").requiredOption("-t, --title <title>").option("-c, --content <text>", 'content as markdown (use "-" for stdin)').option("--content-file <path>", "read content from a file").option("-d, --description <text>").option("--project <id>").option("-s, --status <status>", "draft|published|archived", "draft").option("--visibility <vis>", "private|workspace|shared|public", "private").option("--category <cat>").option("--tag <tag...>").option("-p, --profile <name>").action(async (opts) => {
|
|
2694
|
+
try {
|
|
2695
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2696
|
+
const doc = await client.documents.create({
|
|
2697
|
+
title: opts.title,
|
|
2698
|
+
description: opts.description,
|
|
2699
|
+
content: readContent(opts),
|
|
2700
|
+
project_id: opts.project,
|
|
2701
|
+
status: opts.status,
|
|
2702
|
+
visibility: opts.visibility,
|
|
2703
|
+
category: opts.category,
|
|
2704
|
+
tags: opts.tag
|
|
2705
|
+
});
|
|
2706
|
+
console.log(JSON.stringify(doc, null, 2));
|
|
2707
|
+
} catch (err) {
|
|
2708
|
+
console.error(formatErrorForCli(err));
|
|
2709
|
+
process.exitCode = 1;
|
|
2710
|
+
return;
|
|
2711
|
+
}
|
|
2712
|
+
});
|
|
2713
|
+
cmd.command("update <id>").description("Update a document").option("-t, --title <title>").option("-c, --content <text>", 'use "-" for stdin').option("--content-file <path>").option("-s, --status <status>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2714
|
+
try {
|
|
2715
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2716
|
+
const doc = await client.documents.update(id, {
|
|
2717
|
+
title: opts.title,
|
|
2718
|
+
content: readContent(opts),
|
|
2719
|
+
status: opts.status
|
|
2720
|
+
});
|
|
2721
|
+
console.log(JSON.stringify(doc, null, 2));
|
|
2722
|
+
} catch (err) {
|
|
2723
|
+
console.error(formatErrorForCli(err));
|
|
2724
|
+
process.exitCode = 1;
|
|
2725
|
+
return;
|
|
2726
|
+
}
|
|
2727
|
+
});
|
|
2728
|
+
const page = cmd.command("page").description("Manage pages within a document");
|
|
2729
|
+
page.command("list <documentId>").description("List the pages in a document").option("-o, --output <format>").option("-p, --profile <name>").action(async (documentId, opts) => {
|
|
2730
|
+
try {
|
|
2731
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2732
|
+
const rows = await client.documents.listPages(documentId);
|
|
2733
|
+
console.log(render(rows, [
|
|
2734
|
+
{ header: "Order", get: (r) => String(r.page_order) },
|
|
2735
|
+
{ header: "Title", get: (r) => r.title, truncate: 40 },
|
|
2736
|
+
{ header: "Updated", get: (r) => r.updated_at?.slice(0, 10) },
|
|
2737
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2738
|
+
], opts.output ?? defaultFormat()));
|
|
2739
|
+
} catch (err) {
|
|
2740
|
+
console.error(formatErrorForCli(err));
|
|
2741
|
+
process.exitCode = 1;
|
|
2742
|
+
return;
|
|
2743
|
+
}
|
|
2744
|
+
});
|
|
2745
|
+
page.command("create <documentId>").description("Add a page to a document (content from --content, --content-file, or stdin with -c -)").option("-t, --title <title>", "page title", "Untitled Page").option("-c, --content <text>", 'content as markdown (use "-" for stdin)').option("--content-file <path>", "read content from a file").option("--icon <name>", "icon name (e.g. FileText)").option("--order <n>", "zero-based position; omit to append at end", (v) => parseInt(v, 10)).option("-p, --profile <name>").action(async (documentId, opts) => {
|
|
2746
|
+
try {
|
|
2747
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2748
|
+
const newPage = await client.documents.createPage(documentId, {
|
|
2749
|
+
title: opts.title,
|
|
2750
|
+
content: readContent(opts),
|
|
2751
|
+
icon: opts.icon,
|
|
2752
|
+
page_order: opts.order
|
|
2753
|
+
});
|
|
2754
|
+
console.log(JSON.stringify(newPage, null, 2));
|
|
2755
|
+
} catch (err) {
|
|
2756
|
+
console.error(formatErrorForCli(err));
|
|
2757
|
+
process.exitCode = 1;
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
});
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
// src/commands/agent.ts
|
|
2764
|
+
var DAY_MAP = {
|
|
2765
|
+
sun: 0,
|
|
2766
|
+
mon: 1,
|
|
2767
|
+
tue: 2,
|
|
2768
|
+
wed: 3,
|
|
2769
|
+
thu: 4,
|
|
2770
|
+
fri: 5,
|
|
2771
|
+
sat: 6,
|
|
2772
|
+
sunday: 0,
|
|
2773
|
+
monday: 1,
|
|
2774
|
+
tuesday: 2,
|
|
2775
|
+
wednesday: 3,
|
|
2776
|
+
thursday: 4,
|
|
2777
|
+
friday: 5,
|
|
2778
|
+
saturday: 6
|
|
2779
|
+
};
|
|
2780
|
+
function parseDayOfWeek(input) {
|
|
2781
|
+
if (!input) return void 0;
|
|
2782
|
+
const lc = input.toLowerCase();
|
|
2783
|
+
if (lc in DAY_MAP) return DAY_MAP[lc];
|
|
2784
|
+
const n = parseInt(input, 10);
|
|
2785
|
+
if (n >= 0 && n <= 6) return n;
|
|
2786
|
+
throw new Error(`Bad --day "${input}". Use mon|tue|... or 0-6.`);
|
|
2787
|
+
}
|
|
2788
|
+
function registerAgentCommands(parent) {
|
|
2789
|
+
const cmd = parent.command("agent").alias("agents").description("Manage AI agents");
|
|
2790
|
+
const sched = cmd.command("schedule").description("Manage agent schedules");
|
|
2791
|
+
sched.command("list").description("List recurring agent schedules").option("-a, --agent <id>", "filter by agent ID").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2792
|
+
try {
|
|
2793
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2794
|
+
const rows = await client.agentSchedules.list(opts.agent);
|
|
2795
|
+
console.log(render(rows, [
|
|
2796
|
+
{ header: "Name", get: (r) => r.name, truncate: 35 },
|
|
2797
|
+
{ header: "Frequency", get: (r) => r.frequency },
|
|
2798
|
+
{ header: "Time", get: (r) => r.time_of_day },
|
|
2799
|
+
{ header: "Output", get: (r) => r.output_channel },
|
|
2800
|
+
{ header: "Enabled", get: (r) => r.enabled ? "yes" : "no" },
|
|
2801
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
2802
|
+
], opts.output ?? defaultFormat()));
|
|
2803
|
+
} catch (err) {
|
|
2804
|
+
console.error(formatErrorForCli(err));
|
|
2805
|
+
process.exitCode = 1;
|
|
2806
|
+
return;
|
|
2807
|
+
}
|
|
2808
|
+
});
|
|
2809
|
+
sched.command("create").description("Create a recurring agent schedule").requiredOption("-a, --agent <id>", "agent ID").requiredOption("-n, --name <name>").requiredOption("--prompt <text>", "prompt the agent runs each time").requiredOption("-f, --frequency <freq>", "daily|weekly|monthly").option("--day <day>", "day-of-week (mon|tue|... or 0-6) for weekly").option("--day-of-month <n>", "day-of-month (1-28) for monthly", (v) => parseInt(v, 10)).option("--time <hhmm>", "HH:MM (default 09:00)", "09:00").option("--timezone <tz>", "", "America/New_York").option("--output-channel <ch>", "notification|slack|task_comment", "notification").option("-p, --profile <name>").action(async (opts) => {
|
|
2810
|
+
try {
|
|
2811
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2812
|
+
const schedule = await client.agentSchedules.create({
|
|
2813
|
+
agent_id: opts.agent,
|
|
2814
|
+
name: opts.name,
|
|
2815
|
+
prompt: opts.prompt,
|
|
2816
|
+
frequency: opts.frequency,
|
|
2817
|
+
day_of_week: parseDayOfWeek(opts.day),
|
|
2818
|
+
day_of_month: opts.dayOfMonth,
|
|
2819
|
+
time_of_day: opts.time,
|
|
2820
|
+
timezone: opts.timezone,
|
|
2821
|
+
output_channel: opts.outputChannel
|
|
2822
|
+
});
|
|
2823
|
+
console.log(JSON.stringify(schedule, null, 2));
|
|
2824
|
+
} catch (err) {
|
|
2825
|
+
console.error(formatErrorForCli(err));
|
|
2826
|
+
process.exitCode = 1;
|
|
2827
|
+
return;
|
|
2828
|
+
}
|
|
2829
|
+
});
|
|
2830
|
+
sched.command("disable <id>").description("Disable a schedule (without deleting it)").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2831
|
+
try {
|
|
2832
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2833
|
+
await client.agentSchedules.update(id, { enabled: false });
|
|
2834
|
+
console.log(`\u2713 Disabled ${id}`);
|
|
2835
|
+
} catch (err) {
|
|
2836
|
+
console.error(formatErrorForCli(err));
|
|
2837
|
+
process.exitCode = 1;
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
});
|
|
2841
|
+
sched.command("enable <id>").description("Enable a schedule").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2842
|
+
try {
|
|
2843
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2844
|
+
await client.agentSchedules.update(id, { enabled: true });
|
|
2845
|
+
console.log(`\u2713 Enabled ${id}`);
|
|
2846
|
+
} catch (err) {
|
|
2847
|
+
console.error(formatErrorForCli(err));
|
|
2848
|
+
process.exitCode = 1;
|
|
2849
|
+
return;
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
sched.command("delete <id>").description("Delete a schedule").option("-p, --profile <name>").action(async (id, opts) => {
|
|
2853
|
+
try {
|
|
2854
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2855
|
+
await client.agentSchedules.delete(id);
|
|
2856
|
+
console.log(`\u2713 Deleted ${id}`);
|
|
2857
|
+
} catch (err) {
|
|
2858
|
+
console.error(formatErrorForCli(err));
|
|
2859
|
+
process.exitCode = 1;
|
|
2860
|
+
return;
|
|
2861
|
+
}
|
|
2862
|
+
});
|
|
2863
|
+
cmd.command("send-email").description("Send an email AS one of your agents, from its verified sender identity").requiredOption("--as <agent>", 'agent name, slug, or id (e.g. "Ava")').requiredOption("--to <addresses>", "recipient email(s), comma-separated").option("--cc <addresses>", "Cc email(s), comma-separated").option("--subject <text>", "subject line (required unless --delegate)").option("--body <text>", "plain-text body (required unless --delegate)").option("--html <html>", "HTML body (alternative/addition to --body)").option("--delegate", "let the agent write the email itself from --intent").option("--intent <text>", "what the email should accomplish (required with --delegate)").option("--context <text>", "extra context for the agent in --delegate mode").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
2864
|
+
try {
|
|
2865
|
+
const splitAddrs = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
2866
|
+
if (opts.delegate) {
|
|
2867
|
+
if (!opts.intent) throw new Error("--intent is required with --delegate");
|
|
2868
|
+
} else {
|
|
2869
|
+
if (!opts.subject) throw new Error("--subject is required (or use --delegate with --intent)");
|
|
2870
|
+
if (!opts.body && !opts.html) throw new Error("--body or --html is required (or use --delegate with --intent)");
|
|
2871
|
+
}
|
|
2872
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
2873
|
+
const result = await client.agentEmail.send({
|
|
2874
|
+
agent: opts.as,
|
|
2875
|
+
to: splitAddrs(opts.to),
|
|
2876
|
+
cc: opts.cc ? splitAddrs(opts.cc) : void 0,
|
|
2877
|
+
subject: opts.subject,
|
|
2878
|
+
text_body: opts.body,
|
|
2879
|
+
html_body: opts.html,
|
|
2880
|
+
delegate: Boolean(opts.delegate),
|
|
2881
|
+
intent: opts.intent,
|
|
2882
|
+
context: opts.context
|
|
2883
|
+
});
|
|
2884
|
+
const fmt = opts.output ?? defaultFormat();
|
|
2885
|
+
if (fmt === "json") {
|
|
2886
|
+
console.log(JSON.stringify(result, null, 2));
|
|
2887
|
+
} else {
|
|
2888
|
+
const verb = result.mode === "delegated" ? "composed and sent" : "sent";
|
|
2889
|
+
console.log(`\u2713 ${result.agent.name} ${verb} email from ${result.from_address}`);
|
|
2890
|
+
if (result.summary) console.log(` ${result.summary}`);
|
|
2891
|
+
if (result.message_id) console.log(` message: ${result.message_id}`);
|
|
2892
|
+
if (result.suppressed_dropped && result.suppressed_dropped.length) {
|
|
2893
|
+
console.log(` suppressed (not sent): ${result.suppressed_dropped.join(", ")}`);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
} catch (err) {
|
|
2897
|
+
console.error(formatErrorForCli(err));
|
|
2898
|
+
process.exitCode = 1;
|
|
2899
|
+
return;
|
|
2900
|
+
}
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
// src/commands/import.ts
|
|
2905
|
+
import kleur6 from "kleur";
|
|
2906
|
+
import ora from "ora";
|
|
2907
|
+
import { writeFileSync as writeFileSync2 } from "fs";
|
|
2908
|
+
|
|
2909
|
+
// src/lib/csv.ts
|
|
2910
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
2911
|
+
import { parse as parse2 } from "csv-parse/sync";
|
|
2912
|
+
function readDataFile(path) {
|
|
2913
|
+
const ext = path.toLowerCase().split(".").pop();
|
|
2914
|
+
const raw = readFileSync3(path, "utf8");
|
|
2915
|
+
if (ext === "json") {
|
|
2916
|
+
const data = JSON.parse(raw);
|
|
2917
|
+
if (!Array.isArray(data)) throw new Error("JSON file must contain an array of objects");
|
|
2918
|
+
const columns2 = Array.from(new Set(data.flatMap((r) => Object.keys(r))));
|
|
2919
|
+
return {
|
|
2920
|
+
rows: data.map((r) => stringifyRow(r)),
|
|
2921
|
+
columns: columns2
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2924
|
+
if (ext === "ndjson") {
|
|
2925
|
+
const data = raw.split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l));
|
|
2926
|
+
const columns2 = Array.from(new Set(data.flatMap((r) => Object.keys(r))));
|
|
2927
|
+
return { rows: data.map(stringifyRow), columns: columns2 };
|
|
2928
|
+
}
|
|
2929
|
+
const delimiter = ext === "tsv" ? " " : ",";
|
|
2930
|
+
const records = parse2(raw, {
|
|
2931
|
+
columns: true,
|
|
2932
|
+
skip_empty_lines: true,
|
|
2933
|
+
trim: true,
|
|
2934
|
+
delimiter
|
|
2935
|
+
});
|
|
2936
|
+
const columns = records.length > 0 ? Object.keys(records[0]) : [];
|
|
2937
|
+
return { rows: records, columns };
|
|
2938
|
+
}
|
|
2939
|
+
function stringifyRow(r) {
|
|
2940
|
+
const out = {};
|
|
2941
|
+
for (const [k, v] of Object.entries(r)) {
|
|
2942
|
+
if (v === null || v === void 0) {
|
|
2943
|
+
out[k] = "";
|
|
2944
|
+
} else if (typeof v === "object" && !Array.isArray(v)) {
|
|
2945
|
+
out[k] = JSON.stringify(v);
|
|
2946
|
+
} else {
|
|
2947
|
+
out[k] = String(v);
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
return out;
|
|
2951
|
+
}
|
|
2952
|
+
function autoMap(csvColumns, schemaFields) {
|
|
2953
|
+
const mapping = {};
|
|
2954
|
+
const used = /* @__PURE__ */ new Set();
|
|
2955
|
+
for (const field of schemaFields) {
|
|
2956
|
+
const candidates = [field.name, ...field.aliases ?? []];
|
|
2957
|
+
let match;
|
|
2958
|
+
for (const candidate of candidates) {
|
|
2959
|
+
match = csvColumns.find(
|
|
2960
|
+
(c) => !used.has(c) && normalize(c) === normalize(candidate)
|
|
2961
|
+
);
|
|
2962
|
+
if (match) break;
|
|
2963
|
+
}
|
|
2964
|
+
if (!match) {
|
|
2965
|
+
for (const candidate of candidates) {
|
|
2966
|
+
match = csvColumns.find(
|
|
2967
|
+
(c) => !used.has(c) && normalize(c).includes(normalize(candidate))
|
|
2968
|
+
);
|
|
2969
|
+
if (match) break;
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
if (match) {
|
|
2973
|
+
mapping[field.name] = match;
|
|
2974
|
+
used.add(match);
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
const unmapped = csvColumns.filter((c) => !used.has(c));
|
|
2978
|
+
const missingRequired = schemaFields.filter((f) => f.required && !mapping[f.name]).map((f) => f.name);
|
|
2979
|
+
return { mapping, unmapped, missingRequired };
|
|
2980
|
+
}
|
|
2981
|
+
function normalize(s) {
|
|
2982
|
+
return s.toLowerCase().replace(/[\s_\-./]+/g, "");
|
|
2983
|
+
}
|
|
2984
|
+
function applyMapping(row, mapping) {
|
|
2985
|
+
const out = {};
|
|
2986
|
+
for (const [field, column] of Object.entries(mapping)) {
|
|
2987
|
+
const v = row[column];
|
|
2988
|
+
if (v !== void 0 && v !== "") out[field] = v;
|
|
2989
|
+
}
|
|
2990
|
+
return out;
|
|
2991
|
+
}
|
|
2992
|
+
function parseExplicitMapping(maps) {
|
|
2993
|
+
const out = {};
|
|
2994
|
+
for (const m of maps) {
|
|
2995
|
+
const eq = m.indexOf("=");
|
|
2996
|
+
if (eq < 0) throw new Error(`Invalid --map "${m}". Expected field=ColumnName.`);
|
|
2997
|
+
const field = m.slice(0, eq).trim();
|
|
2998
|
+
const col = m.slice(eq + 1).trim();
|
|
2999
|
+
if (!field || !col) throw new Error(`Invalid --map "${m}". Both sides must be non-empty.`);
|
|
3000
|
+
out[field] = col;
|
|
3001
|
+
}
|
|
3002
|
+
return out;
|
|
3003
|
+
}
|
|
3004
|
+
|
|
3005
|
+
// src/commands/import.ts
|
|
3006
|
+
var PEOPLE_SCHEMA = [
|
|
3007
|
+
{ name: "first_name", required: true, aliases: ["firstname", "fname", "given_name", "first"] },
|
|
3008
|
+
{ name: "last_name", aliases: ["lastname", "lname", "surname", "family_name", "last"] },
|
|
3009
|
+
{ name: "secondary_email", aliases: ["alternate_email", "alt_email", "email2", "other_email"] },
|
|
3010
|
+
{ name: "email", aliases: ["email_address", "e-mail", "mail"] },
|
|
3011
|
+
{ name: "mobile_phone", aliases: ["cell_phone", "mobile_number", "cellphone", "mobile", "cell"] },
|
|
3012
|
+
{ name: "phone", aliases: ["phone_number", "tel", "mobile", "cell"] },
|
|
3013
|
+
{ name: "title", aliases: ["job_title", "role", "position"] },
|
|
3014
|
+
{ name: "account_id", aliases: ["account", "company", "organization", "org", "client"] },
|
|
3015
|
+
{ name: "contact_type", aliases: ["type", "category"] },
|
|
3016
|
+
{ name: "priority" },
|
|
3017
|
+
{ name: "notes", aliases: ["note", "description", "comments"] },
|
|
3018
|
+
{ name: "linkedin_url", aliases: ["linkedin", "linkedin_profile"] },
|
|
3019
|
+
{ name: "twitter_url", aliases: ["twitter", "x_url", "twitter_handle"] },
|
|
3020
|
+
{ name: "facebook_url", aliases: ["facebook", "fb_url"] },
|
|
3021
|
+
{ name: "instagram_url", aliases: ["instagram", "ig_url"] },
|
|
3022
|
+
{ name: "tiktok_url", aliases: ["tiktok"] },
|
|
3023
|
+
{ name: "youtube_url", aliases: ["youtube", "yt_url"] },
|
|
3024
|
+
// The specific address_* parts precede address_street, whose bare 'address'
|
|
3025
|
+
// alias would otherwise substring-claim "address_city" and friends.
|
|
3026
|
+
{ name: "address_city", aliases: ["city", "town"] },
|
|
3027
|
+
{ name: "address_state", aliases: ["state", "region", "province"] },
|
|
3028
|
+
{ name: "address_zip", aliases: ["zip", "postal_code", "postcode", "zipcode"] },
|
|
3029
|
+
{ name: "address_country", aliases: ["country"] },
|
|
3030
|
+
{ name: "address_street", aliases: ["street", "street_address", "address", "address_line1"] },
|
|
3031
|
+
{ name: "timezone", aliases: ["tz", "time_zone"] },
|
|
3032
|
+
{ name: "lead_source", aliases: ["source", "lead_src"] },
|
|
3033
|
+
{ name: "last_contacted_at", aliases: ["last_contacted", "last_contact_date"] },
|
|
3034
|
+
{ name: "next_follow_up_at", aliases: ["next_follow_up", "next_followup", "follow_up_date"] },
|
|
3035
|
+
{ name: "tags", aliases: ["tag", "labels", "label"] },
|
|
3036
|
+
{ name: "custom_fields", aliases: ["custom", "metadata", "meta"] }
|
|
3037
|
+
];
|
|
3038
|
+
var ACCOUNTS_SCHEMA = [
|
|
3039
|
+
{ name: "name", required: true, aliases: ["company", "organization", "account_name", "business"] },
|
|
3040
|
+
{ name: "email", aliases: ["email_address", "mail"] },
|
|
3041
|
+
{ name: "website", aliases: ["url", "web", "site"] },
|
|
3042
|
+
{ name: "phone", aliases: ["phone_number", "tel"] },
|
|
3043
|
+
{ name: "status" },
|
|
3044
|
+
{ name: "health" },
|
|
3045
|
+
{ name: "description", aliases: ["notes", "about"] },
|
|
3046
|
+
{ name: "address", aliases: ["street", "street_address"] },
|
|
3047
|
+
{ name: "city" },
|
|
3048
|
+
{ name: "state", aliases: ["region", "province"] },
|
|
3049
|
+
{ name: "zip", aliases: ["postal_code", "postcode", "zipcode"] },
|
|
3050
|
+
{ name: "country" },
|
|
3051
|
+
{ name: "tags", aliases: ["tag", "labels", "label"] },
|
|
3052
|
+
{ name: "custom_fields", aliases: ["custom", "metadata", "meta"] }
|
|
3053
|
+
];
|
|
3054
|
+
var DEALS_SCHEMA = [
|
|
3055
|
+
{ name: "title", required: true, aliases: ["name", "deal_name", "opportunity"] },
|
|
3056
|
+
{ name: "description", aliases: ["notes", "about"] },
|
|
3057
|
+
{ name: "stage", aliases: ["status"] },
|
|
3058
|
+
{ name: "priority" },
|
|
3059
|
+
{ name: "value", aliases: ["amount", "price", "deal_value"] },
|
|
3060
|
+
{ name: "probability", aliases: ["prob", "win_rate", "win_probability"] },
|
|
3061
|
+
{ name: "account_id", aliases: ["account", "company", "client"] },
|
|
3062
|
+
{ name: "expected_close_date", aliases: ["close_date", "expected_close", "closing_date"] }
|
|
3063
|
+
];
|
|
3064
|
+
var TASKS_SCHEMA = [
|
|
3065
|
+
{ name: "title", required: true, aliases: ["name", "task_name", "task"] },
|
|
3066
|
+
{ name: "description", aliases: ["notes", "details"] },
|
|
3067
|
+
{ name: "project_id", aliases: ["project"] },
|
|
3068
|
+
{ name: "status" },
|
|
3069
|
+
{ name: "priority" },
|
|
3070
|
+
{ name: "due_date", aliases: ["due", "deadline"] }
|
|
3071
|
+
];
|
|
3072
|
+
var SCHEMAS = {
|
|
3073
|
+
people: PEOPLE_SCHEMA,
|
|
3074
|
+
accounts: ACCOUNTS_SCHEMA,
|
|
3075
|
+
deals: DEALS_SCHEMA,
|
|
3076
|
+
tasks: TASKS_SCHEMA
|
|
3077
|
+
};
|
|
3078
|
+
function registerImportCommands(parent) {
|
|
3079
|
+
const cmd = parent.command("import").description("Bulk-import CSV/JSON data into Helm");
|
|
3080
|
+
for (const entity of ["people", "accounts", "deals", "tasks"]) {
|
|
3081
|
+
cmd.command(`${entity} <file>`).description(`Import ${entity} from a CSV/TSV/JSON/NDJSON file`).option("-m, --map <field=column...>", "explicit field mapping (repeatable)").option("--apply", "actually write (default is dry-run)").option("--on-duplicate <mode>", "skip|update|create", "skip").option("-c, --concurrency <n>", "parallel writes", "5").option("--report <file>", "write per-row outcomes to NDJSON file").option("--strict", "abort on first error").option("-p, --profile <name>").action(async (file, opts) => {
|
|
3082
|
+
try {
|
|
3083
|
+
await runImport(entity, file, opts);
|
|
3084
|
+
} catch (err) {
|
|
3085
|
+
console.error(formatErrorForCli(err));
|
|
3086
|
+
process.exitCode = 1;
|
|
3087
|
+
return;
|
|
3088
|
+
}
|
|
3089
|
+
});
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
async function runImport(entity, file, opts) {
|
|
3093
|
+
const schema = SCHEMAS[entity];
|
|
3094
|
+
const { rows, columns } = readDataFile(file);
|
|
3095
|
+
const explicit = opts.map ? parseExplicitMapping(opts.map) : {};
|
|
3096
|
+
const auto = autoMap(columns, schema);
|
|
3097
|
+
const mapping = { ...auto.mapping, ...explicit };
|
|
3098
|
+
const missingRequired = schema.filter((f) => f.required && !mapping[f.name]).map((f) => f.name);
|
|
3099
|
+
console.log(kleur6.cyan(`
|
|
3100
|
+
Detected mapping (${entity}):`));
|
|
3101
|
+
for (const field of schema) {
|
|
3102
|
+
const col = mapping[field.name];
|
|
3103
|
+
const req = field.required ? kleur6.yellow(" (required)") : "";
|
|
3104
|
+
if (col) {
|
|
3105
|
+
console.log(` ${kleur6.green(field.name.padEnd(22))} \u2190 "${col}"${req}`);
|
|
3106
|
+
} else if (field.required) {
|
|
3107
|
+
console.log(` ${kleur6.red(field.name.padEnd(22))} \u2190 (no match)${req}`);
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
const dottedCustomFields = Object.keys(mapping).filter((k) => k.startsWith(CUSTOM_FIELD_PREFIX)).sort();
|
|
3111
|
+
for (const k of dottedCustomFields) {
|
|
3112
|
+
console.log(` ${kleur6.green(k.padEnd(22))} \u2190 "${mapping[k]}"`);
|
|
3113
|
+
}
|
|
3114
|
+
const unmapped = columns.filter((c) => !Object.values(mapping).includes(c));
|
|
3115
|
+
if (unmapped.length) {
|
|
3116
|
+
console.log(kleur6.gray(` Unmapped columns: ${unmapped.join(", ")}`));
|
|
3117
|
+
}
|
|
3118
|
+
if (missingRequired.length) {
|
|
3119
|
+
console.error(kleur6.red(`
|
|
3120
|
+
\u2717 Missing required field(s): ${missingRequired.join(", ")}`));
|
|
3121
|
+
console.error(kleur6.gray(' Use --map to set them manually, e.g. --map first_name="Full Name"'));
|
|
3122
|
+
process.exitCode = 1;
|
|
3123
|
+
return;
|
|
3124
|
+
}
|
|
3125
|
+
console.log(kleur6.cyan(`
|
|
3126
|
+
Rows to import: ${rows.length}`));
|
|
3127
|
+
const concurrency = parseInt(opts.concurrency || "5", 10);
|
|
3128
|
+
const eta = Math.round(rows.length / concurrency / 10);
|
|
3129
|
+
console.log(kleur6.gray(`Concurrency: ${concurrency} \xB7 ETA: ~${eta}s`));
|
|
3130
|
+
const previewN = Math.min(3, rows.length);
|
|
3131
|
+
if (previewN > 0) {
|
|
3132
|
+
console.log(kleur6.cyan(`
|
|
3133
|
+
Preview (first ${previewN}):`));
|
|
3134
|
+
for (let i = 0; i < previewN; i++) {
|
|
3135
|
+
const mapped = applyMapping(rows[i], mapping);
|
|
3136
|
+
const display = entity === "people" ? `${mapped.first_name ?? ""} ${mapped.last_name ?? ""} <${mapped.email ?? ""}>`.trim() : entity === "accounts" ? `${mapped.name ?? ""} <${mapped.email ?? ""}>`.trim() : entity === "tasks" ? `${mapped.title ?? ""} (${mapped.priority ?? "medium"}, ${mapped.status ?? "backlog"})`.trim() : `${mapped.title ?? ""} ($${mapped.value ?? "0"})`.trim();
|
|
3137
|
+
console.log(` ${i + 1}. ${display}`);
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
if (!opts.apply) {
|
|
3141
|
+
console.log(kleur6.yellow("\nDry-run only. Add --apply to write."));
|
|
3142
|
+
return;
|
|
3143
|
+
}
|
|
3144
|
+
const profile = resolveProfile(opts.profile);
|
|
3145
|
+
const client = HelmClient.fromProfile(profile);
|
|
3146
|
+
const prep = ora({ text: "Loading existing records for dedup...", color: "cyan" }).start();
|
|
3147
|
+
const dedupIndex = await buildDedupIndex(client, entity);
|
|
3148
|
+
const accountResolver = await buildAccountResolver(entity, mapping, client);
|
|
3149
|
+
prep.stop();
|
|
3150
|
+
const spinner = ora({ text: "Importing...", color: "cyan" }).start();
|
|
3151
|
+
const results = [];
|
|
3152
|
+
const stats = { created: 0, updated: 0, skipped: 0, failed: 0, planLimit: false };
|
|
3153
|
+
let cursor = 0;
|
|
3154
|
+
const workers = Array.from({ length: concurrency }, () => worker());
|
|
3155
|
+
async function worker() {
|
|
3156
|
+
while (cursor < rows.length) {
|
|
3157
|
+
const idx = cursor++;
|
|
3158
|
+
const row = rows[idx];
|
|
3159
|
+
const mapped = applyMapping(row, mapping);
|
|
3160
|
+
try {
|
|
3161
|
+
const accountInput = mapped.account_id;
|
|
3162
|
+
if (accountInput && accountResolver) {
|
|
3163
|
+
const resolved = await accountResolver(accountInput);
|
|
3164
|
+
if (resolved) mapped.account_id = resolved;
|
|
3165
|
+
else delete mapped.account_id;
|
|
3166
|
+
}
|
|
3167
|
+
const outcome = await createOne(client, entity, mapped, opts, dedupIndex);
|
|
3168
|
+
if (outcome === "skipped") {
|
|
3169
|
+
stats.skipped++;
|
|
3170
|
+
results.push({ row: idx + 1, status: "skipped" });
|
|
3171
|
+
} else if (outcome.action === "updated") {
|
|
3172
|
+
stats.updated++;
|
|
3173
|
+
results.push({ row: idx + 1, status: "updated", id: outcome.id });
|
|
3174
|
+
} else {
|
|
3175
|
+
stats.created++;
|
|
3176
|
+
dedupIndex.add(mapped, outcome.id);
|
|
3177
|
+
results.push({ row: idx + 1, status: "created", id: outcome.id });
|
|
3178
|
+
}
|
|
3179
|
+
} catch (err) {
|
|
3180
|
+
stats.failed++;
|
|
3181
|
+
results.push({ row: idx + 1, status: "failed", error: err.message });
|
|
3182
|
+
if (err instanceof HelmPlanLimitError) {
|
|
3183
|
+
stats.planLimit = true;
|
|
3184
|
+
cursor = rows.length;
|
|
3185
|
+
break;
|
|
3186
|
+
}
|
|
3187
|
+
if (opts.strict) {
|
|
3188
|
+
cursor = rows.length;
|
|
3189
|
+
throw err;
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
const done = stats.created + stats.updated + stats.skipped + stats.failed;
|
|
3193
|
+
spinner.text = `Importing... ${done}/${rows.length} ${kleur6.green(`\u2713${stats.created}`)} ${kleur6.cyan(`\u27F3${stats.updated}`)} ${kleur6.gray(`\u21BA${stats.skipped}`)} ${kleur6.red(`\u2717${stats.failed}`)}`;
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
await Promise.all(workers);
|
|
3197
|
+
spinner.stop();
|
|
3198
|
+
console.log();
|
|
3199
|
+
console.log(kleur6.green(`\u2713 ${stats.created} created`));
|
|
3200
|
+
if (stats.updated) console.log(kleur6.cyan(`\u27F3 ${stats.updated} updated (duplicate)`));
|
|
3201
|
+
if (stats.skipped) console.log(kleur6.gray(`\u21BA ${stats.skipped} skipped (duplicate)`));
|
|
3202
|
+
if (stats.failed) console.log(kleur6.red(`\u2717 ${stats.failed} failed`));
|
|
3203
|
+
if (stats.planLimit) {
|
|
3204
|
+
console.log(kleur6.yellow("\nPlan limit reached. Upgrade at https://gethelm.ai/pricing"));
|
|
3205
|
+
}
|
|
3206
|
+
if (opts.report) {
|
|
3207
|
+
writeFileSync2(opts.report, results.map((r) => JSON.stringify(r)).join("\n"));
|
|
3208
|
+
console.log(kleur6.gray(`Report written to ${opts.report}`));
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
var CUSTOM_FIELD_PREFIX = "custom_fields.";
|
|
3212
|
+
function coerceScalar(v) {
|
|
3213
|
+
try {
|
|
3214
|
+
return JSON.parse(v);
|
|
3215
|
+
} catch {
|
|
3216
|
+
return v;
|
|
3217
|
+
}
|
|
3218
|
+
}
|
|
3219
|
+
function buildCustomFields(data) {
|
|
3220
|
+
let base;
|
|
3221
|
+
if (data.custom_fields !== void 0) {
|
|
3222
|
+
base = parseCustomFields(data.custom_fields);
|
|
3223
|
+
}
|
|
3224
|
+
let dotted;
|
|
3225
|
+
for (const [k, v] of Object.entries(data)) {
|
|
3226
|
+
if (k.startsWith(CUSTOM_FIELD_PREFIX)) {
|
|
3227
|
+
const key = k.slice(CUSTOM_FIELD_PREFIX.length);
|
|
3228
|
+
if (key) {
|
|
3229
|
+
dotted ??= {};
|
|
3230
|
+
dotted[key] = coerceScalar(v);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
if (dotted) base = { ...base ?? {}, ...dotted };
|
|
3235
|
+
return base;
|
|
3236
|
+
}
|
|
3237
|
+
async function createOne(client, entity, data, opts, dedupIndex) {
|
|
3238
|
+
const existingId = dedupIndex.findId(data);
|
|
3239
|
+
if (existingId && opts.onDuplicate === "skip") return "skipped";
|
|
3240
|
+
const doUpdate = !!existingId && opts.onDuplicate === "update";
|
|
3241
|
+
if (entity === "people") {
|
|
3242
|
+
const payload2 = {
|
|
3243
|
+
first_name: data.first_name,
|
|
3244
|
+
last_name: data.last_name,
|
|
3245
|
+
email: data.email,
|
|
3246
|
+
phone: data.phone,
|
|
3247
|
+
title: data.title,
|
|
3248
|
+
account_id: data.account_id,
|
|
3249
|
+
contact_type: data.contact_type,
|
|
3250
|
+
priority: data.priority,
|
|
3251
|
+
notes: data.notes,
|
|
3252
|
+
tags: parseTags(data.tags),
|
|
3253
|
+
custom_fields: buildCustomFields(data),
|
|
3254
|
+
// Profile fields. Must stay in sync with PEOPLE_SCHEMA — a field present
|
|
3255
|
+
// in the schema but missing here maps cleanly and is then silently
|
|
3256
|
+
// dropped before the API call.
|
|
3257
|
+
secondary_email: data.secondary_email,
|
|
3258
|
+
mobile_phone: data.mobile_phone,
|
|
3259
|
+
linkedin_url: data.linkedin_url,
|
|
3260
|
+
twitter_url: data.twitter_url,
|
|
3261
|
+
facebook_url: data.facebook_url,
|
|
3262
|
+
instagram_url: data.instagram_url,
|
|
3263
|
+
tiktok_url: data.tiktok_url,
|
|
3264
|
+
youtube_url: data.youtube_url,
|
|
3265
|
+
address_street: data.address_street,
|
|
3266
|
+
address_city: data.address_city,
|
|
3267
|
+
address_state: data.address_state,
|
|
3268
|
+
address_zip: data.address_zip,
|
|
3269
|
+
address_country: data.address_country,
|
|
3270
|
+
timezone: data.timezone,
|
|
3271
|
+
lead_source: data.lead_source,
|
|
3272
|
+
last_contacted_at: data.last_contacted_at,
|
|
3273
|
+
next_follow_up_at: data.next_follow_up_at
|
|
3274
|
+
};
|
|
3275
|
+
const rec2 = doUpdate ? await client.contacts.update(existingId, payload2) : await client.contacts.create(payload2);
|
|
3276
|
+
return { id: rec2.id, action: doUpdate ? "updated" : "created" };
|
|
3277
|
+
}
|
|
3278
|
+
if (entity === "accounts") {
|
|
3279
|
+
const payload2 = {
|
|
3280
|
+
name: data.name,
|
|
3281
|
+
email: data.email,
|
|
3282
|
+
website: data.website,
|
|
3283
|
+
phone: data.phone,
|
|
3284
|
+
status: data.status,
|
|
3285
|
+
health: data.health,
|
|
3286
|
+
description: data.description,
|
|
3287
|
+
address: data.address,
|
|
3288
|
+
city: data.city,
|
|
3289
|
+
state: data.state,
|
|
3290
|
+
zip: data.zip,
|
|
3291
|
+
country: data.country,
|
|
3292
|
+
tags: parseTags(data.tags),
|
|
3293
|
+
custom_fields: buildCustomFields(data)
|
|
3294
|
+
};
|
|
3295
|
+
const rec2 = doUpdate ? await client.accounts.update(existingId, payload2) : await client.accounts.create(payload2);
|
|
3296
|
+
return { id: rec2.id, action: doUpdate ? "updated" : "created" };
|
|
3297
|
+
}
|
|
3298
|
+
if (entity === "tasks") {
|
|
3299
|
+
const payload2 = {
|
|
3300
|
+
title: data.title,
|
|
3301
|
+
description: data.description,
|
|
3302
|
+
project_id: data.project_id,
|
|
3303
|
+
status: data.status,
|
|
3304
|
+
priority: data.priority
|
|
3305
|
+
};
|
|
3306
|
+
const rec2 = doUpdate ? await client.tasks.update(existingId, payload2) : await client.tasks.create(payload2);
|
|
3307
|
+
return { id: rec2.id, action: doUpdate ? "updated" : "created" };
|
|
3308
|
+
}
|
|
3309
|
+
const payload = {
|
|
3310
|
+
title: data.title,
|
|
3311
|
+
description: data.description,
|
|
3312
|
+
stage: data.stage,
|
|
3313
|
+
priority: data.priority,
|
|
3314
|
+
value: data.value ? parseFloat(data.value) : void 0,
|
|
3315
|
+
probability: data.probability ? parseFloat(data.probability) : void 0,
|
|
3316
|
+
account_id: data.account_id,
|
|
3317
|
+
expected_close_date: data.expected_close_date
|
|
3318
|
+
};
|
|
3319
|
+
const rec = doUpdate ? await client.deals.update(existingId, payload) : await client.deals.create(payload);
|
|
3320
|
+
return { id: rec.id, action: doUpdate ? "updated" : "created" };
|
|
3321
|
+
}
|
|
3322
|
+
async function buildDedupIndex(client, entity) {
|
|
3323
|
+
if (entity === "people") {
|
|
3324
|
+
const existing2 = await client.contacts.listAll();
|
|
3325
|
+
const byEmail = /* @__PURE__ */ new Map();
|
|
3326
|
+
for (const c of existing2) {
|
|
3327
|
+
if (c.email) byEmail.set(c.email.toLowerCase(), c.id);
|
|
3328
|
+
}
|
|
3329
|
+
const keyOf = (d) => d.email?.toLowerCase();
|
|
3330
|
+
return {
|
|
3331
|
+
findId: (d) => {
|
|
3332
|
+
const k = keyOf(d);
|
|
3333
|
+
return k ? byEmail.get(k) : void 0;
|
|
3334
|
+
},
|
|
3335
|
+
add: (d, id) => {
|
|
3336
|
+
const k = keyOf(d);
|
|
3337
|
+
if (k) byEmail.set(k, id);
|
|
3338
|
+
}
|
|
3339
|
+
};
|
|
3340
|
+
}
|
|
3341
|
+
if (entity === "accounts") {
|
|
3342
|
+
const existing2 = await client.accounts.listAll();
|
|
3343
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3344
|
+
for (const a of existing2) byName.set(a.name.toLowerCase(), a.id);
|
|
3345
|
+
const keyOf = (d) => d.name?.toLowerCase();
|
|
3346
|
+
return {
|
|
3347
|
+
findId: (d) => {
|
|
3348
|
+
const k = keyOf(d);
|
|
3349
|
+
return k ? byName.get(k) : void 0;
|
|
3350
|
+
},
|
|
3351
|
+
add: (d, id) => {
|
|
3352
|
+
const k = keyOf(d);
|
|
3353
|
+
if (k) byName.set(k, id);
|
|
3354
|
+
}
|
|
3355
|
+
};
|
|
3356
|
+
}
|
|
3357
|
+
if (entity === "tasks") {
|
|
3358
|
+
const existing2 = await client.tasks.list({ limit: 1e4, include_archived: true });
|
|
3359
|
+
const taskKey = (title, projectId) => `${(title ?? "").toLowerCase()}::${projectId ?? ""}`;
|
|
3360
|
+
const byKey2 = /* @__PURE__ */ new Map();
|
|
3361
|
+
for (const t of existing2) byKey2.set(taskKey(t.title, t.project_id), t.id);
|
|
3362
|
+
return {
|
|
3363
|
+
findId: (d) => byKey2.get(taskKey(d.title, d.project_id)),
|
|
3364
|
+
add: (d, id) => byKey2.set(taskKey(d.title, d.project_id), id)
|
|
3365
|
+
};
|
|
3366
|
+
}
|
|
3367
|
+
const existing = await client.deals.list({ limit: 1e4 });
|
|
3368
|
+
const dealKey = (title, accountId) => `${(title ?? "").toLowerCase()}::${accountId ?? ""}`;
|
|
3369
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
3370
|
+
for (const d of existing) byKey.set(dealKey(d.title, d.account_id), d.id);
|
|
3371
|
+
return {
|
|
3372
|
+
findId: (d) => byKey.get(dealKey(d.title, d.account_id)),
|
|
3373
|
+
add: (d, id) => byKey.set(dealKey(d.title, d.account_id), id)
|
|
3374
|
+
};
|
|
3375
|
+
}
|
|
3376
|
+
async function buildAccountResolver(entity, mapping, client) {
|
|
3377
|
+
if (!mapping.account_id) return null;
|
|
3378
|
+
if (entity === "accounts") return null;
|
|
3379
|
+
const accounts = await client.accounts.listAll();
|
|
3380
|
+
const byName = new Map(accounts.map((a) => [a.name.toLowerCase(), a.id]));
|
|
3381
|
+
const ids = new Set(accounts.map((a) => a.id));
|
|
3382
|
+
return async (input) => {
|
|
3383
|
+
if (ids.has(input)) return input;
|
|
3384
|
+
return byName.get(input.toLowerCase()) ?? null;
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
// src/commands/template.ts
|
|
3389
|
+
function registerTemplateCommands(parent) {
|
|
3390
|
+
const cmd = parent.command("template").alias("templates").description("Install and manage Program Templates");
|
|
3391
|
+
cmd.command("list").description("List available built-in templates").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
3392
|
+
try {
|
|
3393
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3394
|
+
const rows = await client.templates.list();
|
|
3395
|
+
console.log(render(rows, [
|
|
3396
|
+
{ header: "Slug", get: (r) => r.slug },
|
|
3397
|
+
{ header: "Name", get: (r) => r.name },
|
|
3398
|
+
{ header: "Version", get: (r) => r.version },
|
|
3399
|
+
{ header: "Description", get: (r) => r.description, truncate: 60 }
|
|
3400
|
+
], opts.output ?? defaultFormat()));
|
|
3401
|
+
} catch (err) {
|
|
3402
|
+
console.error(formatErrorForCli(err));
|
|
3403
|
+
process.exitCode = 1;
|
|
3404
|
+
return;
|
|
3405
|
+
}
|
|
3406
|
+
});
|
|
3407
|
+
cmd.command("apply <slug>").description("Install a built-in Program Template into the active workspace").option("--input <key=value...>", 'scalar input (repeatable, e.g. --input campaign_name="Q2 Beta")', collect, []).option("--csv <key=path>", "CSV input (repeatable, e.g. --csv list_file=./beta-list.csv)", collect, []).option("--base-date <YYYY-MM-DD>", "base date for due_offset_days math (defaults to today UTC)").option("--dry-run", "plan and report without applying (NOT YET IMPLEMENTED)").option("-p, --profile <name>").action(async (slug, opts) => {
|
|
3408
|
+
try {
|
|
3409
|
+
if (opts.dryRun) {
|
|
3410
|
+
console.error("--dry-run not yet implemented; planner runs server-side");
|
|
3411
|
+
process.exitCode = 2;
|
|
3412
|
+
return;
|
|
3413
|
+
}
|
|
3414
|
+
const inputs = parseInputs(opts.input);
|
|
3415
|
+
const csvData = parseCsvInputs(opts.csv);
|
|
3416
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3417
|
+
process.stdout.write(`Installing template "${slug}"...
|
|
3418
|
+
`);
|
|
3419
|
+
const result = await client.templates.apply({ slug, inputs, csv_data: csvData, base_date: opts.baseDate });
|
|
3420
|
+
if (result.status === "applied") {
|
|
3421
|
+
console.log(`\u2713 applied: ${result.entity_count} entities created (application=${result.application_id})`);
|
|
3422
|
+
if (result.ops) {
|
|
3423
|
+
const created = result.ops.filter((o) => o.status === "created");
|
|
3424
|
+
const byType = created.reduce((acc, o) => {
|
|
3425
|
+
acc[o.entityType] = (acc[o.entityType] ?? 0) + 1;
|
|
3426
|
+
return acc;
|
|
3427
|
+
}, {});
|
|
3428
|
+
for (const [type, count] of Object.entries(byType)) {
|
|
3429
|
+
console.log(` ${count} ${type}`);
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
} else if (result.status === "skipped") {
|
|
3433
|
+
console.log(`\u2713 already installed (application=${result.application_id}) \u2014 re-apply is a no-op in skip mode`);
|
|
3434
|
+
} else {
|
|
3435
|
+
console.error(`\u2717 ${result.status}: ${result.error}`);
|
|
3436
|
+
if (result.ops) {
|
|
3437
|
+
for (const op of result.ops) {
|
|
3438
|
+
if (op.status === "failed") console.error(` ${op.entityType}/${op.ref}: ${op.error}`);
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
process.exitCode = 1;
|
|
3442
|
+
return;
|
|
3443
|
+
}
|
|
3444
|
+
} catch (err) {
|
|
3445
|
+
console.error(formatErrorForCli(err));
|
|
3446
|
+
process.exitCode = 1;
|
|
3447
|
+
return;
|
|
3448
|
+
}
|
|
3449
|
+
});
|
|
3450
|
+
}
|
|
3451
|
+
function collect(value, prev) {
|
|
3452
|
+
return [...prev, value];
|
|
3453
|
+
}
|
|
3454
|
+
function parseInputs(raw) {
|
|
3455
|
+
const out = {};
|
|
3456
|
+
for (const entry of raw) {
|
|
3457
|
+
const eq = entry.indexOf("=");
|
|
3458
|
+
if (eq < 0) throw new Error(`invalid --input "${entry}" (expected key=value)`);
|
|
3459
|
+
const key = entry.slice(0, eq);
|
|
3460
|
+
let value = entry.slice(eq + 1);
|
|
3461
|
+
if (typeof value === "string") {
|
|
3462
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
3463
|
+
value = value.slice(1, -1);
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
out[key] = value;
|
|
3467
|
+
}
|
|
3468
|
+
return out;
|
|
3469
|
+
}
|
|
3470
|
+
function parseCsvInputs(raw) {
|
|
3471
|
+
const out = {};
|
|
3472
|
+
for (const entry of raw) {
|
|
3473
|
+
const eq = entry.indexOf("=");
|
|
3474
|
+
if (eq < 0) throw new Error(`invalid --csv "${entry}" (expected key=path)`);
|
|
3475
|
+
const key = entry.slice(0, eq);
|
|
3476
|
+
const path = entry.slice(eq + 1);
|
|
3477
|
+
const parsed = readDataFile(path);
|
|
3478
|
+
out[key] = parsed.rows;
|
|
3479
|
+
}
|
|
3480
|
+
return out;
|
|
3481
|
+
}
|
|
3482
|
+
|
|
3483
|
+
// src/commands/workflow.ts
|
|
3484
|
+
import kleur7 from "kleur";
|
|
3485
|
+
async function readJsonSource(path) {
|
|
3486
|
+
let raw;
|
|
3487
|
+
if (path === "-") {
|
|
3488
|
+
const chunks = [];
|
|
3489
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
3490
|
+
raw = Buffer.concat(chunks).toString("utf8");
|
|
3491
|
+
} else {
|
|
3492
|
+
const { readFileSync: readFileSync5 } = await import("fs");
|
|
3493
|
+
raw = readFileSync5(path, "utf8");
|
|
3494
|
+
}
|
|
3495
|
+
try {
|
|
3496
|
+
return JSON.parse(raw);
|
|
3497
|
+
} catch (e) {
|
|
3498
|
+
throw new Error(`Invalid JSON in ${path === "-" ? "stdin" : path}: ${e.message}`);
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
async function buildDefinition(opts) {
|
|
3502
|
+
let def = {};
|
|
3503
|
+
if (opts.file) def = await readJsonSource(String(opts.file));
|
|
3504
|
+
if (opts.name !== void 0) def.name = String(opts.name);
|
|
3505
|
+
if (opts.description !== void 0) def.description = String(opts.description);
|
|
3506
|
+
if (opts.trigger !== void 0) def.trigger_config = JSON.parse(String(opts.trigger));
|
|
3507
|
+
if (opts.steps !== void 0) def.steps_config = JSON.parse(String(opts.steps));
|
|
3508
|
+
if (opts.settings !== void 0) def.settings = JSON.parse(String(opts.settings));
|
|
3509
|
+
if (opts.status !== void 0) def.status = String(opts.status);
|
|
3510
|
+
return def;
|
|
3511
|
+
}
|
|
3512
|
+
function printIssues(label, issues) {
|
|
3513
|
+
if (!issues || issues.length === 0) return;
|
|
3514
|
+
console.error(kleur7.yellow(`
|
|
3515
|
+
${label}:`));
|
|
3516
|
+
for (const i of issues) {
|
|
3517
|
+
console.error(kleur7.yellow(` \u2022 ${i.path}: ${i.message}`));
|
|
3518
|
+
if (i.hint) console.error(kleur7.gray(` hint: ${i.hint}`));
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
function registerWorkflowCommands(parent) {
|
|
3522
|
+
const cmd = parent.command("workflow").alias("workflows").description("Build and operate automation workflows");
|
|
3523
|
+
cmd.command("list").description("List workflows").option("--status <status>", "draft|live|archived").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 100).option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
3524
|
+
try {
|
|
3525
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3526
|
+
const rows = await client.workflows.list({ status: opts.status, limit: opts.limit });
|
|
3527
|
+
console.log(render(rows, [
|
|
3528
|
+
{ header: "Name", get: (r) => r.name },
|
|
3529
|
+
{ header: "Status", get: (r) => r.status ?? "" },
|
|
3530
|
+
{ header: "Trigger", get: (r) => r.trigger_entity_type ?? "" },
|
|
3531
|
+
{ header: "Steps", get: (r) => String(r.step_count ?? 0) },
|
|
3532
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
3533
|
+
], opts.output ?? defaultFormat()));
|
|
3534
|
+
} catch (err) {
|
|
3535
|
+
console.error(formatErrorForCli(err));
|
|
3536
|
+
process.exitCode = 1;
|
|
3537
|
+
return;
|
|
3538
|
+
}
|
|
3539
|
+
});
|
|
3540
|
+
cmd.command("get <id>").description("Get a workflow by ID (includes trigger + steps config)").option("-o, --output <format>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3541
|
+
try {
|
|
3542
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3543
|
+
const workflow = await client.workflows.get(id);
|
|
3544
|
+
console.log(JSON.stringify(workflow, null, 2));
|
|
3545
|
+
} catch (err) {
|
|
3546
|
+
console.error(formatErrorForCli(err));
|
|
3547
|
+
process.exitCode = 1;
|
|
3548
|
+
return;
|
|
3549
|
+
}
|
|
3550
|
+
});
|
|
3551
|
+
cmd.command("runs <id>").description("List recent execution runs for a workflow").option("--status <status>", "running|completed|failed|cancelled").option("-l, --limit <n>", "max rows", (v) => parseInt(v, 10), 25).option("-o, --output <format>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3552
|
+
try {
|
|
3553
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3554
|
+
const rows = await client.workflows.executions(id, { status: opts.status, limit: opts.limit });
|
|
3555
|
+
console.log(render(rows, [
|
|
3556
|
+
{ header: "Status", get: (r) => r.status ?? "" },
|
|
3557
|
+
{ header: "Started", get: (r) => r.created_at ?? "" },
|
|
3558
|
+
{ header: "Completed", get: (r) => r.completed_at ?? "" },
|
|
3559
|
+
{ header: "Error", get: (r) => r.error_message ?? "" },
|
|
3560
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
3561
|
+
], opts.output ?? defaultFormat()));
|
|
3562
|
+
} catch (err) {
|
|
3563
|
+
console.error(formatErrorForCli(err));
|
|
3564
|
+
process.exitCode = 1;
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
});
|
|
3568
|
+
const setStatus = (verb, status, desc) => {
|
|
3569
|
+
cmd.command(`${verb} <id>`).description(desc).option("-p, --profile <name>").action(async (id, opts) => {
|
|
3570
|
+
try {
|
|
3571
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3572
|
+
const wf = await client.workflows.setStatus(id, status);
|
|
3573
|
+
console.log(`\u2713 ${wf.name ?? id} \u2192 ${wf.status ?? status}`);
|
|
3574
|
+
} catch (err) {
|
|
3575
|
+
console.error(formatErrorForCli(err));
|
|
3576
|
+
process.exitCode = 1;
|
|
3577
|
+
return;
|
|
3578
|
+
}
|
|
3579
|
+
});
|
|
3580
|
+
};
|
|
3581
|
+
setStatus("enable", "live", "Set a workflow live");
|
|
3582
|
+
setStatus("disable", "draft", "Pause a workflow (back to draft)");
|
|
3583
|
+
setStatus("archive", "archived", "Archive a workflow");
|
|
3584
|
+
cmd.command("run <id>").description("Manually execute a workflow (bypasses trigger conditions)").option("--data <json>", "trigger data as a JSON string").option("--data-file <path>", "read trigger data from a JSON file").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3585
|
+
try {
|
|
3586
|
+
let triggerData;
|
|
3587
|
+
if (opts.dataFile) {
|
|
3588
|
+
const { readFileSync: readFileSync5 } = await import("fs");
|
|
3589
|
+
triggerData = JSON.parse(readFileSync5(opts.dataFile, "utf8"));
|
|
3590
|
+
} else if (opts.data) {
|
|
3591
|
+
triggerData = JSON.parse(opts.data);
|
|
3592
|
+
}
|
|
3593
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3594
|
+
const res = await client.workflows.run(id, triggerData);
|
|
3595
|
+
console.log(`\u2713 ${res.message ?? "Executed"}${res.execution_id ? ` (execution ${res.execution_id})` : ""}`);
|
|
3596
|
+
} catch (err) {
|
|
3597
|
+
console.error(formatErrorForCli(err));
|
|
3598
|
+
process.exitCode = 1;
|
|
3599
|
+
return;
|
|
3600
|
+
}
|
|
3601
|
+
});
|
|
3602
|
+
cmd.command("schema").description("Print the workflow authoring grammar (triggers, step types, entities, operators, rules)").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
3603
|
+
try {
|
|
3604
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3605
|
+
const schema = await client.workflows.schema();
|
|
3606
|
+
console.log(JSON.stringify(schema, null, 2));
|
|
3607
|
+
} catch (err) {
|
|
3608
|
+
console.error(formatErrorForCli(err));
|
|
3609
|
+
process.exitCode = 1;
|
|
3610
|
+
return;
|
|
3611
|
+
}
|
|
3612
|
+
});
|
|
3613
|
+
cmd.command("create").description("Create a workflow from a JSON definition (--file/-) and/or flags. Saved as draft unless --status live.").option("-f, --file <path>", 'JSON definition file (use "-" for stdin)').option("-n, --name <name>", "workflow name").option("-d, --description <text>").option("--trigger <json>", "trigger_config as a JSON string").option("--steps <json>", "steps_config as a JSON string").option("--settings <json>", "settings as a JSON string").option("--status <status>", "draft|live (default: draft)").option("-p, --profile <name>").action(async (opts) => {
|
|
3614
|
+
try {
|
|
3615
|
+
const def = await buildDefinition(opts);
|
|
3616
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3617
|
+
const res = await client.workflows.create(def);
|
|
3618
|
+
console.log(JSON.stringify(res.workflow, null, 2));
|
|
3619
|
+
printIssues("Incomplete (resolve before going live)", res.incomplete);
|
|
3620
|
+
printIssues("Warnings", res.warnings);
|
|
3621
|
+
} catch (err) {
|
|
3622
|
+
console.error(formatErrorForCli(err));
|
|
3623
|
+
process.exitCode = 1;
|
|
3624
|
+
return;
|
|
3625
|
+
}
|
|
3626
|
+
});
|
|
3627
|
+
cmd.command("update <id>").description("Update a workflow from a JSON definition (--file/-) and/or flags").option("-f, --file <path>", 'JSON definition file (use "-" for stdin)').option("-n, --name <name>").option("-d, --description <text>").option("--trigger <json>", "trigger_config as a JSON string").option("--steps <json>", "steps_config as a JSON string").option("--settings <json>", "settings as a JSON string").option("--status <status>", "draft|live|archived").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3628
|
+
try {
|
|
3629
|
+
const def = await buildDefinition(opts);
|
|
3630
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3631
|
+
const res = await client.workflows.update(id, def);
|
|
3632
|
+
console.log(JSON.stringify(res.workflow, null, 2));
|
|
3633
|
+
printIssues("Incomplete (resolve before going live)", res.incomplete);
|
|
3634
|
+
printIssues("Warnings", res.warnings);
|
|
3635
|
+
} catch (err) {
|
|
3636
|
+
console.error(formatErrorForCli(err));
|
|
3637
|
+
process.exitCode = 1;
|
|
3638
|
+
return;
|
|
3639
|
+
}
|
|
3640
|
+
});
|
|
3641
|
+
cmd.command("delete <id>").description("Delete a workflow").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3642
|
+
try {
|
|
3643
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3644
|
+
await client.workflows.delete(id);
|
|
3645
|
+
console.log(`\u2713 Deleted workflow ${id}`);
|
|
3646
|
+
} catch (err) {
|
|
3647
|
+
console.error(formatErrorForCli(err));
|
|
3648
|
+
process.exitCode = 1;
|
|
3649
|
+
return;
|
|
3650
|
+
}
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3654
|
+
// src/commands/sequence.ts
|
|
3655
|
+
import { stringify as yamlStringify2 } from "yaml";
|
|
3656
|
+
var collect2 = (value, prev) => prev.concat([value]);
|
|
3657
|
+
function registerSequenceCommands(parent) {
|
|
3658
|
+
const cmd = parent.command("sequence").alias("sequences").description("Operate email sequences (read, enroll, lifecycle)");
|
|
3659
|
+
cmd.command("list").description("List email sequences").option("--status <status>", "draft|live|paused|archived").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
3660
|
+
try {
|
|
3661
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3662
|
+
const rows = await client.sequences.list({ status: opts.status });
|
|
3663
|
+
console.log(render(rows, [
|
|
3664
|
+
{ header: "Name", get: (r) => r.name },
|
|
3665
|
+
{ header: "Status", get: (r) => r.status ?? "" },
|
|
3666
|
+
{ header: "Steps", get: (r) => String(r.step_count ?? 0) },
|
|
3667
|
+
{ header: "Active", get: (r) => String(r.stats?.active_count ?? 0) },
|
|
3668
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
3669
|
+
], opts.output ?? defaultFormat()));
|
|
3670
|
+
} catch (err) {
|
|
3671
|
+
console.error(formatErrorForCli(err));
|
|
3672
|
+
process.exitCode = 1;
|
|
3673
|
+
return;
|
|
3674
|
+
}
|
|
3675
|
+
});
|
|
3676
|
+
cmd.command("get <id>").description("Get a sequence by ID (includes steps + stats)").option("-o, --output <format>", "json|yaml (default json)").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3677
|
+
try {
|
|
3678
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3679
|
+
const detail = await client.sequences.get(id);
|
|
3680
|
+
console.log(opts.output === "yaml" ? yamlStringify2(detail) : JSON.stringify(detail, null, 2));
|
|
3681
|
+
} catch (err) {
|
|
3682
|
+
console.error(formatErrorForCli(err));
|
|
3683
|
+
process.exitCode = 1;
|
|
3684
|
+
return;
|
|
3685
|
+
}
|
|
3686
|
+
});
|
|
3687
|
+
cmd.command("enrollments <id>").description("List enrollments for a sequence").option("--status <status>", "active|paused|completed|exited_reply|...").option("-o, --output <format>").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3688
|
+
try {
|
|
3689
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3690
|
+
const rows = await client.sequences.enrollments(id, { status: opts.status });
|
|
3691
|
+
console.log(render(rows, [
|
|
3692
|
+
{ header: "Contact", get: (r) => r.person ? `${r.person.first_name ?? ""} ${r.person.last_name ?? ""}`.trim() || (r.person.email ?? "") : r.person_id ?? "" },
|
|
3693
|
+
{ header: "Status", get: (r) => r.status ?? "" },
|
|
3694
|
+
{ header: "Step", get: (r) => r.current_step_position != null ? String(r.current_step_position) : "\u2014" },
|
|
3695
|
+
{ header: "Next send", get: (r) => r.next_send_at ?? "" },
|
|
3696
|
+
{ header: "ID", get: (r) => r.id, truncate: 8 }
|
|
3697
|
+
], opts.output ?? defaultFormat()));
|
|
3698
|
+
} catch (err) {
|
|
3699
|
+
console.error(formatErrorForCli(err));
|
|
3700
|
+
process.exitCode = 1;
|
|
3701
|
+
return;
|
|
3702
|
+
}
|
|
3703
|
+
});
|
|
3704
|
+
cmd.command("enroll <id>").description("Enroll one or more contacts into a sequence").option("--person <id>", "contact UUID (repeatable)", collect2, []).option("--email <email>", "contact email (repeatable)", collect2, []).option("-p, --profile <name>").action(async (id, opts) => {
|
|
3705
|
+
try {
|
|
3706
|
+
const targets = [
|
|
3707
|
+
...opts.person.map((person_id) => ({ person_id })),
|
|
3708
|
+
...opts.email.map((email) => ({ email }))
|
|
3709
|
+
];
|
|
3710
|
+
if (targets.length === 0) {
|
|
3711
|
+
console.error("Provide at least one --person <id> or --email <email>.");
|
|
3712
|
+
process.exitCode = 1;
|
|
3713
|
+
return;
|
|
3714
|
+
}
|
|
3715
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3716
|
+
let enrolled = 0;
|
|
3717
|
+
let skipped = 0;
|
|
3718
|
+
for (const target of targets) {
|
|
3719
|
+
const res = await client.sequences.enroll(id, target);
|
|
3720
|
+
const label = target.person_id ?? target.email ?? "";
|
|
3721
|
+
if (res.error) {
|
|
3722
|
+
skipped++;
|
|
3723
|
+
console.log(`\u2717 ${label}: ${res.message ?? res.error}`);
|
|
3724
|
+
} else if (res.enrolled) {
|
|
3725
|
+
enrolled++;
|
|
3726
|
+
console.log(`\u2713 ${label} enrolled (${res.enrollment_id ?? ""})`);
|
|
3727
|
+
} else {
|
|
3728
|
+
skipped++;
|
|
3729
|
+
console.log(`\u2013 ${label} skipped: ${res.skipped_reason ?? "unknown"}`);
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
console.log(`
|
|
3733
|
+
${enrolled} enrolled, ${skipped} skipped.`);
|
|
3734
|
+
} catch (err) {
|
|
3735
|
+
console.error(formatErrorForCli(err));
|
|
3736
|
+
process.exitCode = 1;
|
|
3737
|
+
return;
|
|
3738
|
+
}
|
|
3739
|
+
});
|
|
3740
|
+
cmd.command("create").description("Create a new email sequence (starts as draft)").requiredOption("-n, --name <name>", "sequence name").option("--description <text>", "what the sequence is for").option("--sender <id>", "sender identity UUID (required before publishing)").option("--no-exit-on-reply", "keep sending after a contact replies").option("--no-exit-on-bounce", "keep sending after a bounce").option("--transactional", "billing/account mail: still sends to marketing unsubscribes, no unsubscribe footer").option("-p, --profile <name>").action(async (opts) => {
|
|
3741
|
+
try {
|
|
3742
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3743
|
+
const seq = await client.sequences.create({
|
|
3744
|
+
name: opts.name,
|
|
3745
|
+
description: opts.description,
|
|
3746
|
+
sender_identity_id: opts.sender,
|
|
3747
|
+
// commander sets opts.exitOnReply=false only when --no-exit-on-reply is passed
|
|
3748
|
+
exit_on_reply: opts.exitOnReply,
|
|
3749
|
+
exit_on_bounce: opts.exitOnBounce,
|
|
3750
|
+
is_transactional: opts.transactional
|
|
3751
|
+
});
|
|
3752
|
+
console.log(`\u2713 Created sequence "${seq.name}" (${seq.status ?? "draft"})`);
|
|
3753
|
+
console.log(` id: ${seq.id}`);
|
|
3754
|
+
console.log(`
|
|
3755
|
+
Next: add emails with
|
|
3756
|
+
helm-ai sequence add-email ${seq.id} --subject "..." --text "..." --delay 0 --unit days`);
|
|
3757
|
+
} catch (err) {
|
|
3758
|
+
console.error(formatErrorForCli(err));
|
|
3759
|
+
process.exitCode = 1;
|
|
3760
|
+
return;
|
|
3761
|
+
}
|
|
3762
|
+
});
|
|
3763
|
+
cmd.command("add-email <id>").description("Add an email to a sequence (appends to the end)").requiredOption("--subject <subject>", "email subject line").option("--text <body>", "plain-text body (provide --text and/or --html)").option("--html <body>", "HTML body (provide --text and/or --html)").requiredOption("--delay <n>", "wait before this email, with --unit (0 = on enrollment)").option("--unit <unit>", "minutes|hours|days", "days").option("--position <n>", "1-based insert position (omit to append)").option("-p, --profile <name>").action(async (id, opts) => {
|
|
3764
|
+
try {
|
|
3765
|
+
if (!opts.text && !opts.html) {
|
|
3766
|
+
console.error("Provide --text and/or --html for the email body.");
|
|
3767
|
+
process.exitCode = 1;
|
|
3768
|
+
return;
|
|
3769
|
+
}
|
|
3770
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3771
|
+
const step = await client.sequences.addEmail(id, {
|
|
3772
|
+
subject: opts.subject,
|
|
3773
|
+
text_body: opts.text,
|
|
3774
|
+
html_body: opts.html,
|
|
3775
|
+
delay_value: Number(opts.delay),
|
|
3776
|
+
delay_unit: opts.unit,
|
|
3777
|
+
position: opts.position != null ? Number(opts.position) : void 0
|
|
3778
|
+
});
|
|
3779
|
+
console.log(`\u2713 Added email #${step.position}: "${step.subject}" (after ${step.delay_value ?? 0} ${step.delay_unit ?? opts.unit})`);
|
|
3780
|
+
} catch (err) {
|
|
3781
|
+
console.error(formatErrorForCli(err));
|
|
3782
|
+
process.exitCode = 1;
|
|
3783
|
+
return;
|
|
3784
|
+
}
|
|
3785
|
+
});
|
|
3786
|
+
const setStatus = (verb, status, desc) => {
|
|
3787
|
+
cmd.command(`${verb} <id>`).description(desc).option("-p, --profile <name>").action(async (id, opts) => {
|
|
3788
|
+
try {
|
|
3789
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3790
|
+
const seq = await client.sequences.setStatus(id, status);
|
|
3791
|
+
console.log(`\u2713 ${seq.name ?? id} \u2192 ${seq.status ?? status}`);
|
|
3792
|
+
} catch (err) {
|
|
3793
|
+
console.error(formatErrorForCli(err));
|
|
3794
|
+
process.exitCode = 1;
|
|
3795
|
+
return;
|
|
3796
|
+
}
|
|
3797
|
+
});
|
|
3798
|
+
};
|
|
3799
|
+
setStatus("publish", "live", "Publish a sequence (set live)");
|
|
3800
|
+
setStatus("pause", "paused", "Pause a live sequence (halts sending; enrollments preserved)");
|
|
3801
|
+
setStatus("resume", "live", "Resume a paused sequence (sending picks back up)");
|
|
3802
|
+
setStatus("archive", "archived", "Archive a sequence (exits active enrollments)");
|
|
3803
|
+
const enrollmentAction = (verb, desc, fn, withReason = false) => {
|
|
3804
|
+
const sub = cmd.command(`${verb} <enrollmentId>`).description(desc).option("-p, --profile <name>");
|
|
3805
|
+
if (withReason) sub.option("--reason <reason>", "exit reason");
|
|
3806
|
+
sub.action(async (enrollmentId, opts) => {
|
|
3807
|
+
try {
|
|
3808
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3809
|
+
await fn(client, enrollmentId, opts);
|
|
3810
|
+
console.log(`\u2713 ${verb} enrollment ${enrollmentId}`);
|
|
3811
|
+
} catch (err) {
|
|
3812
|
+
console.error(formatErrorForCli(err));
|
|
3813
|
+
process.exitCode = 1;
|
|
3814
|
+
return;
|
|
3815
|
+
}
|
|
3816
|
+
});
|
|
3817
|
+
};
|
|
3818
|
+
enrollmentAction("pause-enrollment", "Pause an active enrollment", (c, eid) => c.sequences.pauseEnrollment(eid));
|
|
3819
|
+
enrollmentAction("resume-enrollment", "Resume a paused enrollment", (c, eid) => c.sequences.resumeEnrollment(eid));
|
|
3820
|
+
enrollmentAction("exit-enrollment", "Manually exit an enrollment", (c, eid, o) => c.sequences.exitEnrollment(eid, o.reason), true);
|
|
3821
|
+
}
|
|
3822
|
+
|
|
3823
|
+
// src/commands/email.ts
|
|
3824
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
3825
|
+
function registerEmailCommands(parent) {
|
|
3826
|
+
const cmd = parent.command("email").description("Draft and revise email from your own address");
|
|
3827
|
+
cmd.command("identities").alias("addresses").description("List the addresses you can send from").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
3828
|
+
try {
|
|
3829
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3830
|
+
const identities = await client.email.listIdentities();
|
|
3831
|
+
const fmt = opts.output ?? defaultFormat();
|
|
3832
|
+
if (fmt === "json") {
|
|
3833
|
+
console.log(JSON.stringify(identities, null, 2));
|
|
3834
|
+
return;
|
|
3835
|
+
}
|
|
3836
|
+
if (identities.length === 0) {
|
|
3837
|
+
console.log("No verified sender identities. Add one in Settings \u2192 Email Domains.");
|
|
3838
|
+
return;
|
|
3839
|
+
}
|
|
3840
|
+
console.log(render(identities, [
|
|
3841
|
+
{ header: "Address", get: (i) => i.address },
|
|
3842
|
+
{ header: "Name", get: (i) => i.display_name ?? "" },
|
|
3843
|
+
{ header: "Scope", get: (i) => i.scope },
|
|
3844
|
+
{ header: "ID", get: (i) => i.id, truncate: 8 }
|
|
3845
|
+
], fmt));
|
|
3846
|
+
} catch (err) {
|
|
3847
|
+
console.error(formatErrorForCli(err));
|
|
3848
|
+
process.exitCode = 1;
|
|
3849
|
+
}
|
|
3850
|
+
});
|
|
3851
|
+
cmd.command("draft").description("Draft an email from your address, saved to Drafts for you to review and send").requiredOption("--to <addresses>", "recipient email(s), comma-separated").requiredOption("--subject <text>", "subject line").option("--cc <addresses>", "Cc email(s), comma-separated").option("--body <text>", "plain-text body").option("--body-file <path>", "read the plain-text body from a file (use - for stdin)").option("--html <html>", "HTML body (alternative/addition to --body)").option("--from <address>", "which of your addresses to send as (required if you have several)").option("--thread <id>", "draft a reply into an existing thread").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
3852
|
+
try {
|
|
3853
|
+
const splitAddrs = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
3854
|
+
let body = opts.body;
|
|
3855
|
+
if (opts.bodyFile) {
|
|
3856
|
+
body = readFileSync4(opts.bodyFile === "-" ? 0 : opts.bodyFile, "utf8");
|
|
3857
|
+
}
|
|
3858
|
+
if (!body && !opts.html) {
|
|
3859
|
+
throw new Error("--body, --body-file, or --html is required");
|
|
3860
|
+
}
|
|
3861
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3862
|
+
const result = await client.email.draft({
|
|
3863
|
+
to: splitAddrs(opts.to),
|
|
3864
|
+
cc: opts.cc ? splitAddrs(opts.cc) : void 0,
|
|
3865
|
+
subject: opts.subject,
|
|
3866
|
+
text_body: body,
|
|
3867
|
+
html_body: opts.html,
|
|
3868
|
+
from_identity: opts.from,
|
|
3869
|
+
thread_id: opts.thread
|
|
3870
|
+
});
|
|
3871
|
+
const fmt = opts.output ?? defaultFormat();
|
|
3872
|
+
if (fmt === "json") {
|
|
3873
|
+
console.log(JSON.stringify(result, null, 2));
|
|
3874
|
+
} else {
|
|
3875
|
+
console.log(`\u2713 Draft saved from ${result.from_address}`);
|
|
3876
|
+
console.log(` Draft id: ${result.draft_id}`);
|
|
3877
|
+
console.log(" Review and send it from your Drafts folder \u2014 nothing has gone out.");
|
|
3878
|
+
}
|
|
3879
|
+
} catch (err) {
|
|
3880
|
+
console.error(formatErrorForCli(err));
|
|
3881
|
+
process.exitCode = 1;
|
|
3882
|
+
}
|
|
3883
|
+
});
|
|
3884
|
+
cmd.command("drafts").description("List your unsent drafts").option("--id <draftId>", "show one draft in full instead of the list").option("--limit <n>", "how many to list (default 25)").option("-o, --output <format>").option("-p, --profile <name>").action(async (opts) => {
|
|
3885
|
+
try {
|
|
3886
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3887
|
+
const drafts = await client.email.listDrafts({
|
|
3888
|
+
draft_id: opts.id,
|
|
3889
|
+
limit: opts.limit ? Number(opts.limit) : void 0
|
|
3890
|
+
});
|
|
3891
|
+
const fmt = opts.output ?? (opts.id ? "json" : defaultFormat());
|
|
3892
|
+
if (fmt === "json") {
|
|
3893
|
+
console.log(JSON.stringify(opts.id ? drafts[0] ?? null : drafts, null, 2));
|
|
3894
|
+
return;
|
|
3895
|
+
}
|
|
3896
|
+
if (drafts.length === 0) {
|
|
3897
|
+
console.log("No unsent drafts.");
|
|
3898
|
+
return;
|
|
3899
|
+
}
|
|
3900
|
+
console.log(render(drafts, [
|
|
3901
|
+
{ header: "ID", get: (d) => d.draft_id, truncate: 8 },
|
|
3902
|
+
{ header: "To", get: (d) => d.to.join(", ") },
|
|
3903
|
+
{ header: "Subject", get: (d) => d.subject ?? "" },
|
|
3904
|
+
{ header: "From", get: (d) => d.from_address ?? "" },
|
|
3905
|
+
{ header: "Updated", get: (d) => d.updated_at.slice(0, 16).replace("T", " ") }
|
|
3906
|
+
], fmt));
|
|
3907
|
+
} catch (err) {
|
|
3908
|
+
console.error(formatErrorForCli(err));
|
|
3909
|
+
process.exitCode = 1;
|
|
3910
|
+
}
|
|
3911
|
+
});
|
|
3912
|
+
cmd.command("update <draftId>").alias("revise").description("Revise an unsent draft in place \u2014 only the fields you pass change").option("--to <addresses>", "replace the recipient list, comma-separated").option("--cc <addresses>", "replace the Cc list, comma-separated (empty string clears it)").option("--subject <text>", "new subject line").option("--body <text>", "replace the plain-text body").option("--body-file <path>", "replace the plain-text body from a file (use - for stdin)").option("--html <html>", "replace the HTML body").option("--from <address>", "change which of your addresses it sends from").option("-o, --output <format>").option("-p, --profile <name>").action(async (draftId, opts) => {
|
|
3913
|
+
try {
|
|
3914
|
+
const splitAddrs = (v) => v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
3915
|
+
let body = opts.body;
|
|
3916
|
+
if (opts.bodyFile) {
|
|
3917
|
+
body = readFileSync4(opts.bodyFile === "-" ? 0 : opts.bodyFile, "utf8");
|
|
3918
|
+
}
|
|
3919
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3920
|
+
const draft = await client.email.updateDraft({
|
|
3921
|
+
draft_id: draftId,
|
|
3922
|
+
// Left undefined when the flag is absent, which is what keeps this a
|
|
3923
|
+
// patch: only what you named is touched.
|
|
3924
|
+
to: opts.to !== void 0 ? splitAddrs(opts.to) : void 0,
|
|
3925
|
+
cc: opts.cc !== void 0 ? splitAddrs(opts.cc) : void 0,
|
|
3926
|
+
subject: opts.subject,
|
|
3927
|
+
text_body: body,
|
|
3928
|
+
html_body: opts.html,
|
|
3929
|
+
from_identity: opts.from
|
|
3930
|
+
});
|
|
3931
|
+
const fmt = opts.output ?? defaultFormat();
|
|
3932
|
+
if (fmt === "json") {
|
|
3933
|
+
console.log(JSON.stringify(draft, null, 2));
|
|
3934
|
+
} else {
|
|
3935
|
+
console.log(`\u2713 Draft updated \u2014 "${draft.subject ?? "(no subject)"}" to ${draft.to.join(", ")}`);
|
|
3936
|
+
console.log(" Still unsent. Approve it in your Drafts folder when it reads right.");
|
|
3937
|
+
}
|
|
3938
|
+
} catch (err) {
|
|
3939
|
+
console.error(formatErrorForCli(err));
|
|
3940
|
+
process.exitCode = 1;
|
|
3941
|
+
}
|
|
3942
|
+
});
|
|
3943
|
+
cmd.command("delete <draftId>").alias("discard").description("Delete an unsent draft").option("-p, --profile <name>").action(async (draftId, opts) => {
|
|
3944
|
+
try {
|
|
3945
|
+
const client = HelmClient.fromProfile(resolveProfile(opts.profile));
|
|
3946
|
+
const result = await client.email.deleteDraft(draftId);
|
|
3947
|
+
console.log(`\u2713 Deleted draft "${result.subject ?? "(no subject)"}"`);
|
|
3948
|
+
} catch (err) {
|
|
3949
|
+
console.error(formatErrorForCli(err));
|
|
3950
|
+
process.exitCode = 1;
|
|
3951
|
+
}
|
|
3952
|
+
});
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
// src/cli.ts
|
|
3956
|
+
var program = new Command();
|
|
3957
|
+
program.name("helm-ai").description("Helm CLI \u2014 run your business operations (projects, CRM, billing, automations, AI agents) from the terminal").version(version, "-v, --version").addHelpText("beforeAll", () => process.stdout.isTTY ? renderSplash({ version }) : "");
|
|
3958
|
+
registerAuthCommands(program);
|
|
3959
|
+
registerProfileCommands(program);
|
|
3960
|
+
registerConfigCommands(program);
|
|
3961
|
+
registerProjectCommands(program);
|
|
3962
|
+
registerAccountCommands(program);
|
|
3963
|
+
registerContactCommands(program);
|
|
3964
|
+
registerDealCommands(program);
|
|
3965
|
+
registerPipelineCommands(program);
|
|
3966
|
+
registerTaskCommands(program);
|
|
3967
|
+
registerTimeCommands(program);
|
|
3968
|
+
registerInvoiceCommands(program);
|
|
3969
|
+
registerEstimateCommands(program);
|
|
3970
|
+
registerProductCommands(program);
|
|
3971
|
+
registerFormCommands(program);
|
|
3972
|
+
registerCalendarCommands(program);
|
|
3973
|
+
registerDocCommands(program);
|
|
3974
|
+
registerAgentCommands(program);
|
|
3975
|
+
registerImportCommands(program);
|
|
3976
|
+
registerTemplateCommands(program);
|
|
3977
|
+
registerWorkflowCommands(program);
|
|
3978
|
+
registerSequenceCommands(program);
|
|
3979
|
+
registerEmailCommands(program);
|
|
3980
|
+
program.action(() => {
|
|
3981
|
+
if (process.stdout.isTTY) {
|
|
3982
|
+
process.stdout.write(renderSplash({ version }));
|
|
3983
|
+
}
|
|
3984
|
+
console.log(kleur8.gray(" Run `helm-ai --help` to see available commands."));
|
|
3985
|
+
console.log();
|
|
3986
|
+
});
|
|
3987
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
3988
|
+
console.error(kleur8.red(`\u2717 ${err instanceof Error ? err.message : String(err)}`));
|
|
3989
|
+
process.exit(1);
|
|
3990
|
+
});
|