@go-labs-sg/bb 2.20.0 → 2.23.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.
@@ -1,645 +0,0 @@
1
- /**
2
- * Declarative command catalogue for the Budget Builder CLI.
3
- *
4
- * The first v2 integration step uses `legacyTarget` to dispatch through the
5
- * established command implementation. New command handlers can replace that
6
- * target incrementally by supplying `load` instead.
7
- */
8
- export const globalCommandOptions = [
9
- { name: "--help", description: "Show help for this command." },
10
- { name: "--quiet", description: "Suppress non-error diagnostics." },
11
- { name: "--debug", description: "Emit sanitized diagnostic traces." },
12
- {
13
- name: "--api-url",
14
- description: "Override the Budget Builder API base URL.",
15
- },
16
- {
17
- name: "--allow-state-change",
18
- description: "Allow a Budget Builder state change in non-interactive use.",
19
- },
20
- {
21
- name: "--allow-email",
22
- description: "Allow sending email in non-interactive use.",
23
- },
24
- {
25
- name: "--allow-external-write",
26
- description: "Allow writes to external systems in non-interactive use.",
27
- },
28
- {
29
- name: "--allow-delete",
30
- description: "Allow deleting data in non-interactive use.",
31
- },
32
- {
33
- name: "--allow-financial-write",
34
- description: "Allow financial-record changes in non-interactive use.",
35
- },
36
- ];
37
- const mutationPrefixes = [
38
- "add-",
39
- "approve-",
40
- "archive-",
41
- "attach-",
42
- "cleanup-",
43
- "complete-",
44
- "create-",
45
- "delete-",
46
- "discard-",
47
- "import-",
48
- "mark-",
49
- "patch-",
50
- "reactivate-",
51
- "reconcile-",
52
- "reject-",
53
- "remove-",
54
- "replace-",
55
- "rename-",
56
- "reorder-",
57
- "restore-",
58
- "retry-",
59
- "revoke-",
60
- "save-",
61
- "send-",
62
- "stage-",
63
- "setup-",
64
- "submit-",
65
- "sync-",
66
- "update-",
67
- "upload-",
68
- "void-",
69
- ];
70
- const emailTargets = new Set([
71
- "approve-bill",
72
- "approve-budget",
73
- "approve-customer-invoice",
74
- "approve-supplier",
75
- "create-bill",
76
- "create-bill-approval",
77
- "create-budget-approval",
78
- "create-customer-invoice",
79
- "create-supplier",
80
- "reject-bill",
81
- "reject-budget",
82
- "reject-customer-invoice",
83
- "reject-supplier",
84
- "send-estimate-email",
85
- "send-estimate-to-contact-person",
86
- "send-customer-invoice-to-contact-person",
87
- "update-bill-status",
88
- "update-supplier",
89
- ]);
90
- const externalWriteTargets = new Set([
91
- "approve-bill",
92
- "approve-customer-invoice",
93
- "approve-supplier",
94
- "complete-project",
95
- "create-bill",
96
- "create-company",
97
- "create-estimate",
98
- "create-placeholder-bill",
99
- "create-customer-invoice",
100
- "create-item",
101
- "create-item-category",
102
- "create-project",
103
- "create-supplier",
104
- "delete-bill",
105
- "delete-budget",
106
- "delete-company",
107
- "delete-customer-invoice",
108
- "delete-item",
109
- "delete-project",
110
- "delete-suppliers",
111
- "discard-customer-invoice",
112
- "import-qbo-project",
113
- "mark-budget-items-not-utilized",
114
- "mark-budget-won",
115
- "reconcile-project",
116
- "reject-customer-invoice",
117
- "reactivate-suppliers",
118
- "restore-budget-item",
119
- "restore-budget-version",
120
- "retry-integration-operation",
121
- "setup-project-hub",
122
- "sync-project-hub-commercial-documents",
123
- "sync-customer-invoice",
124
- "update-bill",
125
- "update-budget-status",
126
- "update-company",
127
- "update-item",
128
- "update-item-category",
129
- "update-project",
130
- "update-project-status",
131
- "update-supplier",
132
- "void-customer-invoice",
133
- ]);
134
- const financialWriteTargets = new Set([
135
- "approve-bill",
136
- "approve-customer-invoice",
137
- "complete-project",
138
- "create-bill",
139
- "create-customer-invoice",
140
- "create-estimate",
141
- "create-placeholder-bill",
142
- "delete-budget-commission",
143
- "delete-budget-discount",
144
- "delete-bill",
145
- "delete-budget",
146
- "delete-customer-invoice",
147
- "mark-budget-items-not-utilized",
148
- "mark-budget-won",
149
- "patch-bill-payment",
150
- "reject-customer-invoice",
151
- "restore-budget-item",
152
- "restore-budget-version",
153
- "replace-budget-item",
154
- "sync-customer-invoice",
155
- "update-bill",
156
- "update-bill-payment-evidence",
157
- "update-bill-status",
158
- "update-budget-commission",
159
- "update-budget-discount",
160
- "update-budget-status",
161
- "update-project-status",
162
- "void-customer-invoice",
163
- ]);
164
- const deleteTargets = new Set([
165
- "cleanup-staged-bill-attachments",
166
- "cleanup-staged-quotation-attachments",
167
- "discard-customer-invoice",
168
- "complete-project",
169
- "mark-budget-items-not-utilized",
170
- "remove-budget-item",
171
- "restore-budget-version",
172
- "update-project-status",
173
- ]);
174
- const effectsFor = (legacyTarget) => {
175
- const effects = new Set();
176
- if (mutationPrefixes.some((prefix) => legacyTarget.startsWith(prefix))) {
177
- effects.add("state-change");
178
- }
179
- if (legacyTarget.startsWith("delete-") || deleteTargets.has(legacyTarget)) {
180
- effects.add("delete");
181
- }
182
- if (emailTargets.has(legacyTarget))
183
- effects.add("email");
184
- if (externalWriteTargets.has(legacyTarget))
185
- effects.add("external-write");
186
- if (financialWriteTargets.has(legacyTarget))
187
- effects.add("financial-write");
188
- return [...effects];
189
- };
190
- const titleCase = (value) => value
191
- .split("-")
192
- .map((word) => `${word.slice(0, 1).toUpperCase()}${word.slice(1)}`)
193
- .join(" ");
194
- const summaryFor = (legacyTarget) => {
195
- if (legacyTarget === "whoami")
196
- return "Show the active API-key identity.";
197
- if (legacyTarget === "create-bill") {
198
- return "Create a bill or claim with an approved supplier.";
199
- }
200
- if (legacyTarget === "validate-bill-selection") {
201
- return "Validate the approved supplier and selected bill line items.";
202
- }
203
- if (legacyTarget === "create-quotation") {
204
- return "Create a quotation with an approved supplier.";
205
- }
206
- if (legacyTarget === "update-quotation") {
207
- return "Update a quotation with an approved supplier.";
208
- }
209
- if (legacyTarget === "download-customer-invoice-pdf") {
210
- return "Download a customer invoice PDF when permitted.";
211
- }
212
- if (legacyTarget === "send-customer-invoice-to-contact-person") {
213
- return "Send a customer invoice and update the project billing email.";
214
- }
215
- if (legacyTarget.startsWith("list-")) {
216
- return `List ${legacyTarget.slice("list-".length).replaceAll("-", " ")}.`;
217
- }
218
- if (legacyTarget.startsWith("get-")) {
219
- return `Get ${legacyTarget.slice("get-".length).replaceAll("-", " ")}.`;
220
- }
221
- return `${titleCase(legacyTarget)}.`;
222
- };
223
- const aliasesFor = (legacyTarget, aliases) => [
224
- ...new Set([legacyTarget, ...aliases].flatMap((alias) => [
225
- alias,
226
- alias.replaceAll("-", "_"),
227
- ])),
228
- ];
229
- const legacyCommand = (legacyTarget, path, aliases = [], commandOptions = []) => ({
230
- path,
231
- legacyAliases: aliasesFor(legacyTarget, aliases),
232
- summary: summaryFor(legacyTarget),
233
- options: [...globalCommandOptions, ...commandOptions],
234
- effects: effectsFor(legacyTarget),
235
- legacyTarget,
236
- });
237
- const registry = [
238
- legacyCommand("whoami", ["auth", "whoami"]),
239
- legacyCommand("list-budgets", ["budget", "list"]),
240
- legacyCommand("get-budget", ["budget", "get"]),
241
- legacyCommand("upload-budget-attachment", ["budget", "attachment", "upload"]),
242
- legacyCommand("mark-budget-won", ["budget", "won", "mark"]),
243
- legacyCommand("get-budget-items", ["budget", "item", "list"]),
244
- legacyCommand("get-budget-details", ["budget", "detail", "get"]),
245
- legacyCommand("get-budget-categories", ["budget", "category", "list"]),
246
- legacyCommand("get-budget-versions", ["budget", "version", "list"]),
247
- legacyCommand("rename-budget-version", ["budget", "version", "rename"]),
248
- legacyCommand("restore-budget-version", ["budget", "version", "restore"]),
249
- legacyCommand("update-budget-status", ["budget", "status", "update"]),
250
- legacyCommand("create-budget-approval", ["budget", "approval", "create"]),
251
- legacyCommand("create-estimate", ["budget", "estimate", "create"]),
252
- legacyCommand("send-estimate-to-contact-person", ["budget", "estimate", "send"], ["send-estimate-email"]),
253
- legacyCommand("create-budget", ["budget", "create"]),
254
- legacyCommand("update-budget", ["budget", "update"]),
255
- legacyCommand("delete-budget", ["budget", "delete"]),
256
- legacyCommand("add-budget-items", ["budget", "item", "add"]),
257
- legacyCommand("update-budget-item", ["budget", "item", "update"]),
258
- legacyCommand("remove-budget-item", ["budget", "item", "remove"]),
259
- legacyCommand("replace-budget-item", ["budget", "item", "replace"]),
260
- legacyCommand("approve-unavailable-item-exception", [
261
- "budget",
262
- "item",
263
- "exception",
264
- "approve",
265
- ]),
266
- legacyCommand("reorder-budget-items", ["budget", "item", "reorder"]),
267
- legacyCommand("update-budget-item-supplier", [
268
- "budget",
269
- "item",
270
- "supplier",
271
- "update",
272
- ]),
273
- legacyCommand("create-budget-category", ["budget", "category", "create"]),
274
- legacyCommand("update-budget-category", ["budget", "category", "update"]),
275
- legacyCommand("delete-budget-category", ["budget", "category", "delete"]),
276
- legacyCommand("update-budget-commission", ["budget", "commission", "update"]),
277
- legacyCommand("update-budget-discount", ["budget", "discount", "update"]),
278
- legacyCommand("delete-budget-commission", ["budget", "commission", "delete"]),
279
- legacyCommand("delete-budget-discount", ["budget", "discount", "delete"]),
280
- legacyCommand("mark-budget-items-not-utilized", [
281
- "budget",
282
- "item",
283
- "mark-not-utilized",
284
- ]),
285
- legacyCommand("restore-budget-item", ["budget", "item", "restore"]),
286
- legacyCommand("create-placeholder-bill", [
287
- "budget",
288
- "item",
289
- "placeholder-bill",
290
- "create",
291
- ]),
292
- legacyCommand("list-bills", ["bill", "list"]),
293
- legacyCommand("list-claims", ["claim", "list"]),
294
- legacyCommand("create-bill-approval", ["bill", "approval", "create"]),
295
- legacyCommand("create-bill", ["bill", "create"]),
296
- legacyCommand("validate-bill-selection", ["bill", "selection", "validate"]),
297
- legacyCommand("update-bill", ["bill", "update"]),
298
- legacyCommand("update-bill-payment-evidence", [
299
- "bill",
300
- "payment-evidence",
301
- "update",
302
- ]),
303
- legacyCommand("delete-bill", ["bill", "delete"]),
304
- legacyCommand("update-bill-status", ["bill", "status", "update"]),
305
- legacyCommand("patch-bill-payment", ["bill", "payment", "patch"]),
306
- legacyCommand("patch-bill-invoice-number", [
307
- "bill",
308
- "invoice-number",
309
- "patch",
310
- ]),
311
- legacyCommand("get-bill-attachments", ["bill", "attachment", "list"]),
312
- legacyCommand("stage-bill-attachment", ["bill", "attachment", "stage"]),
313
- legacyCommand("cleanup-staged-bill-attachments", [
314
- "bill",
315
- "attachment",
316
- "staged",
317
- "cleanup",
318
- ]),
319
- legacyCommand("upload-bill-attachment", ["bill", "attachment", "upload"], ["attach-bill-attachment"]),
320
- legacyCommand("attach-bill-payment-receipt", [
321
- "bill",
322
- "payment-receipt",
323
- "attach",
324
- ]),
325
- legacyCommand("attach-bill-documents", ["bill", "document", "attach"]),
326
- legacyCommand("get-bill-details", ["bill", "get"]),
327
- legacyCommand("list-quotations", ["quotation", "list"]),
328
- legacyCommand("get-quotation", ["quotation", "get"]),
329
- legacyCommand("upload-quotation-attachment", [
330
- "quotation",
331
- "attachment",
332
- "upload",
333
- ]),
334
- legacyCommand("cleanup-staged-quotation-attachments", [
335
- "quotation",
336
- "attachment",
337
- "staged",
338
- "cleanup",
339
- ]),
340
- legacyCommand("create-quotation", ["quotation", "create"]),
341
- legacyCommand("update-quotation", ["quotation", "update"]),
342
- legacyCommand("delete-quotation", ["quotation", "delete"]),
343
- legacyCommand("submit-quotation", ["quotation", "submit"]),
344
- legacyCommand("approve-quotation", ["quotation", "approve"]),
345
- legacyCommand("reject-quotation", ["quotation", "reject"]),
346
- legacyCommand("download-quotation-pdf", ["quotation", "pdf", "download"]),
347
- legacyCommand("check-customer-invoice-readiness", [
348
- "customer-invoice",
349
- "readiness",
350
- "check",
351
- ]),
352
- legacyCommand("list-eligible-customer-invoice-budgets", [
353
- "customer-invoice",
354
- "eligible-budget",
355
- "list",
356
- ]),
357
- legacyCommand("list-customer-invoices", ["customer-invoice", "list"]),
358
- legacyCommand("get-customer-invoice", ["customer-invoice", "get"]),
359
- legacyCommand("get-customer-invoice-email-context", [
360
- "customer-invoice",
361
- "email-context",
362
- "get",
363
- ]),
364
- legacyCommand("create-customer-invoice", ["customer-invoice", "create"]),
365
- legacyCommand("discard-customer-invoice", ["customer-invoice", "discard"]),
366
- legacyCommand("delete-customer-invoice", ["customer-invoice", "delete"]),
367
- legacyCommand("void-customer-invoice", ["customer-invoice", "void"]),
368
- legacyCommand("approve-customer-invoice", ["customer-invoice", "approve"]),
369
- legacyCommand("reject-customer-invoice", ["customer-invoice", "reject"]),
370
- legacyCommand("send-customer-invoice-to-contact-person", [
371
- "customer-invoice",
372
- "send",
373
- ]),
374
- legacyCommand("download-customer-invoice-pdf", [
375
- "customer-invoice",
376
- "pdf",
377
- "download",
378
- ]),
379
- legacyCommand("sync-customer-invoice", ["customer-invoice", "sync"]),
380
- legacyCommand("list-approvals", ["approval", "list"], ["get-pending-approvals"]),
381
- legacyCommand("approve-bill", ["bill", "approve"]),
382
- legacyCommand("reject-bill", ["bill", "reject"]),
383
- legacyCommand("approve-budget", ["budget", "approve"]),
384
- legacyCommand("reject-budget", ["budget", "reject"]),
385
- legacyCommand("approve-supplier", ["supplier", "approve"]),
386
- legacyCommand("reject-supplier", ["supplier", "reject"]),
387
- legacyCommand("get-supplier-details", ["supplier", "detail", "get"]),
388
- legacyCommand("list-companies", ["company", "list"]),
389
- legacyCommand("get-company", ["company", "get"]),
390
- legacyCommand("create-company", ["company", "create"]),
391
- legacyCommand("update-company", ["company", "update"]),
392
- legacyCommand("delete-company", ["company", "delete"]),
393
- legacyCommand("list-projects", ["project", "list"]),
394
- legacyCommand("list-project-hubs", ["project", "hub", "list"], [], [
395
- {
396
- name: "--q",
397
- description: "Search project and company names.",
398
- },
399
- {
400
- name: "--status",
401
- description: "Filter by comma-separated project statuses.",
402
- },
403
- { name: "--page", description: "Select a results page." },
404
- { name: "--perPage", description: "Set the results page size." },
405
- {
406
- name: "--sortBy",
407
- description: "Sort by startDate, name, companyName, or status.",
408
- },
409
- { name: "--sortDir", description: "Sort in asc or desc order." },
410
- ]),
411
- legacyCommand("get-project", ["project", "get"]),
412
- legacyCommand("get-project-hub-status", ["project", "hub", "status"]),
413
- legacyCommand("setup-project-hub", ["project", "hub", "setup"]),
414
- legacyCommand("sync-project-hub-commercial-documents", [
415
- "project",
416
- "hub",
417
- "sync",
418
- ]),
419
- legacyCommand("create-project", ["project", "create"]),
420
- legacyCommand("update-project", ["project", "update"]),
421
- legacyCommand("delete-project", ["project", "delete"]),
422
- legacyCommand("check-project-reconciliation", [
423
- "project",
424
- "reconciliation",
425
- "check",
426
- ]),
427
- legacyCommand("reconcile-project", ["project", "reconcile"]),
428
- legacyCommand("complete-project", ["project", "complete"]),
429
- legacyCommand("import-qbo-project", ["project", "quickbooks", "import"]),
430
- legacyCommand("update-project-status", ["project", "status", "update"]),
431
- legacyCommand("list-contacts", ["contact", "list"]),
432
- legacyCommand("create-contact-person", ["contact", "create"]),
433
- legacyCommand("update-contact-person", ["contact", "update"]),
434
- legacyCommand("list-suppliers", ["supplier", "list"]),
435
- legacyCommand("create-supplier", ["supplier", "create"]),
436
- legacyCommand("update-supplier", ["supplier", "update"]),
437
- legacyCommand("delete-suppliers", ["supplier", "delete"]),
438
- legacyCommand("reactivate-suppliers", ["supplier", "reactivate"]),
439
- legacyCommand("create-certification", [
440
- "supplier",
441
- "certification",
442
- "create",
443
- ]),
444
- legacyCommand("create-payment-method", [
445
- "supplier",
446
- "payment-method",
447
- "create",
448
- ]),
449
- legacyCommand("create-supplier-role", ["supplier", "role", "create"]),
450
- legacyCommand("create-supplier-tag", ["supplier", "tag", "create"]),
451
- legacyCommand("get-supplier-analytics", ["supplier", "analytics", "get"]),
452
- legacyCommand("list-items", ["item", "list"]),
453
- legacyCommand("get-item", ["item", "get"]),
454
- legacyCommand("create-item", ["item", "create"]),
455
- legacyCommand("update-item", ["item", "update"]),
456
- legacyCommand("archive-items", ["item", "archive"]),
457
- legacyCommand("delete-item", ["item", "delete"]),
458
- legacyCommand("list-item-categories", ["item", "category", "list"]),
459
- legacyCommand("create-item-category", ["item", "category", "create"]),
460
- legacyCommand("update-item-category", ["item", "category", "update"]),
461
- legacyCommand("delete-item-categories", ["item", "category", "delete"]),
462
- legacyCommand("list-users", ["user", "list"]),
463
- legacyCommand("create-user", ["user", "create"]),
464
- legacyCommand("create-api-key", ["user", "api-key", "create"]),
465
- legacyCommand("list-api-keys", ["user", "api-key", "list"]),
466
- legacyCommand("revoke-api-key", ["user", "api-key", "revoke"]),
467
- legacyCommand("get-user-performance", ["user", "performance", "get"]),
468
- legacyCommand("get-dashboard", ["dashboard", "get"]),
469
- legacyCommand("get-monthly-metrics", ["dashboard", "monthly-metrics", "get"]),
470
- legacyCommand("get-system-overview", ["dashboard", "system-overview", "get"]),
471
- legacyCommand("get-estimate-performance", [
472
- "dashboard",
473
- "estimate-performance",
474
- "get",
475
- ]),
476
- legacyCommand("get-financial-overview", [
477
- "dashboard",
478
- "financial-overview",
479
- "get",
480
- ]),
481
- legacyCommand("get-recent-errors", ["error", "recent", "list"]),
482
- legacyCommand("get-error-metrics", ["error", "metrics", "get"]),
483
- legacyCommand("list-integration-operations", [
484
- "integration",
485
- "operation",
486
- "list",
487
- ]),
488
- legacyCommand("retry-integration-operation", [
489
- "integration",
490
- "operation",
491
- "retry",
492
- ]),
493
- legacyCommand("list-inbound-sources", ["inbound", "source", "list"]),
494
- legacyCommand("create-inbound-source", ["inbound", "source", "create"]),
495
- legacyCommand("get-inbound-source", ["inbound", "source", "get"]),
496
- legacyCommand("update-inbound-source", ["inbound", "source", "update"]),
497
- legacyCommand("list-inbound-submissions", ["inbound", "submission", "list"]),
498
- legacyCommand("get-inbound-submission", ["inbound", "submission", "get"]),
499
- legacyCommand("save-inbound-mapping", ["inbound", "mapping", "save"]),
500
- legacyCommand("save-inbound-automation-config", [
501
- "inbound",
502
- "automation",
503
- "save",
504
- ]),
505
- legacyCommand("update-inbound-processing", [
506
- "inbound",
507
- "processing",
508
- "update",
509
- ]),
510
- legacyCommand("get-approved-budgets", ["budget", "approved", "list"]),
511
- legacyCommand("get-budget-category-benchmarks", [
512
- "budget",
513
- "category",
514
- "benchmark",
515
- "get",
516
- ]),
517
- legacyCommand("get-item-pricing-history", [
518
- "item",
519
- "pricing-history",
520
- "list",
521
- ]),
522
- legacyCommand("get-supplier-pricing-history", [
523
- "supplier",
524
- "pricing-history",
525
- "list",
526
- ]),
527
- ];
528
- const normalizeToken = (value) => value.replaceAll("_", "-");
529
- const normalizedPath = (path) => path.map(normalizeToken);
530
- const assertRegistry = (commands) => {
531
- const paths = new Set();
532
- const aliases = new Set();
533
- for (const command of commands) {
534
- const path = command.path.join(" ");
535
- if (paths.has(path))
536
- throw new Error(`Duplicate canonical command path: ${path}`);
537
- paths.add(path);
538
- const commandAliases = new Set();
539
- for (const alias of command.legacyAliases) {
540
- const normalizedAlias = normalizeToken(alias);
541
- if (commandAliases.has(normalizedAlias))
542
- continue;
543
- commandAliases.add(normalizedAlias);
544
- if (aliases.has(normalizedAlias)) {
545
- throw new Error(`Duplicate legacy command alias: ${alias}`);
546
- }
547
- aliases.add(normalizedAlias);
548
- }
549
- }
550
- };
551
- assertRegistry(registry);
552
- export const commandRegistry = registry;
553
- export const resolveCommand = (argv) => {
554
- const normalizedArgv = argv.map(normalizeToken);
555
- const canonical = [...commandRegistry]
556
- .sort((left, right) => right.path.length - left.path.length)
557
- .find((command) => {
558
- const path = normalizedPath(command.path);
559
- return path.every((segment, index) => normalizedArgv[index] === segment);
560
- });
561
- if (canonical) {
562
- return {
563
- command: canonical,
564
- argv: argv.slice(canonical.path.length),
565
- invokedAs: argv.slice(0, canonical.path.length),
566
- isLegacyAlias: false,
567
- };
568
- }
569
- const rawAlias = argv[0];
570
- if (!rawAlias)
571
- return undefined;
572
- const normalizedAlias = normalizeToken(rawAlias);
573
- const legacy = commandRegistry.find((command) => command.legacyAliases.some((alias) => normalizeToken(alias) === normalizedAlias));
574
- if (!legacy)
575
- return undefined;
576
- return {
577
- command: legacy,
578
- argv: argv.slice(1),
579
- invokedAs: [rawAlias],
580
- isLegacyAlias: true,
581
- };
582
- };
583
- export const createCommandManifest = () => commandRegistry.map((command) => ({
584
- path: command.path,
585
- legacyAliases: command.legacyAliases,
586
- summary: command.summary,
587
- globalOptions: command.options,
588
- argumentMode: "legacyTarget" in command ? "legacy-passthrough" : "typed",
589
- effects: command.effects,
590
- ...("legacyTarget" in command
591
- ? { legacyTarget: command.legacyTarget }
592
- : {}),
593
- }));
594
- export const createHumanHelp = () => {
595
- const lines = commandRegistry.map((command) => {
596
- const canonical = `bb ${command.path.join(" ")}`;
597
- const aliases = command.legacyAliases
598
- .filter((alias) => alias.includes("-"))
599
- .map((alias) => `bb ${alias}`)
600
- .join(", ");
601
- return ` ${canonical}\n ${command.summary}${aliases ? ` Legacy: ${aliases}.` : ""}`;
602
- });
603
- return [
604
- "bb — Budget Builder CLI",
605
- "",
606
- "Usage: bb <resource> <operation> [options] [args]",
607
- "",
608
- "Global options",
609
- ...globalCommandOptions.map((option) => ` ${option.name}\n ${option.description}`),
610
- "",
611
- "Canonical commands",
612
- ...lines,
613
- "",
614
- "Use `bb completion <shell>` to generate shell completion scripts.",
615
- ].join("\n");
616
- };
617
- const completionWords = () => {
618
- const words = new Set();
619
- for (const command of commandRegistry) {
620
- for (const segment of command.path)
621
- words.add(segment);
622
- for (const alias of command.legacyAliases)
623
- words.add(alias);
624
- }
625
- words.add("help");
626
- words.add("version");
627
- words.add("completion");
628
- return [...words].sort();
629
- };
630
- export const createCompletionScript = (shell) => {
631
- const words = completionWords().join(" ");
632
- switch (shell) {
633
- case "bash":
634
- return `# bash completion for bb\n_bb() {\n COMPREPLY=( $(compgen -W '${words}' -- "${"$"}{COMP_WORDS[COMP_CWORD]}") )\n}\ncomplete -F _bb bb\n`;
635
- case "zsh":
636
- return `#compdef bb\n_bb() {\n local -a commands\n commands=(${words})\n _describe 'bb command' commands\n}\ncompdef _bb bb\n`;
637
- case "fish":
638
- return completionWords()
639
- .map((word) => `complete -c bb -f -a '${word}'`)
640
- .join("\n")
641
- .concat("\n");
642
- case "powershell":
643
- return `Register-ArgumentCompleter -Native -CommandName bb -ScriptBlock {\n param($wordToComplete)\n '${words}'.Split(' ') | Where-Object { $_ -like "$wordToComplete*" }\n}\n`;
644
- }
645
- };
package/dist/rich-text.js DELETED
@@ -1,34 +0,0 @@
1
- const escapeHtml = (text) => text
2
- .replace(/&/g, "&amp;")
3
- .replace(/</g, "&lt;")
4
- .replace(/>/g, "&gt;")
5
- .replace(/"/g, "&quot;")
6
- .replace(/'/g, "&#39;");
7
- export const createRichTextFromPlainText = (text) => {
8
- const lines = text?.split(/\r?\n/) ?? [];
9
- const paragraphs = lines.length ? lines : [""];
10
- return {
11
- json: {
12
- type: "doc",
13
- content: paragraphs.map((line) => ({
14
- type: "paragraph",
15
- ...(line ? { content: [{ type: "text", text: line }] } : {}),
16
- })),
17
- },
18
- html: paragraphs.map((line) => `<p>${escapeHtml(line)}</p>`).join(""),
19
- };
20
- };
21
- export const isRichTextJson = (value) => Boolean(value &&
22
- typeof value === "object" &&
23
- "json" in value &&
24
- "html" in value &&
25
- typeof value.html === "string");
26
- export const normalizePlainTextRichTextField = ({ input, textField, richTextField, }) => {
27
- if (isRichTextJson(input[richTextField]) || input[textField] === undefined) {
28
- return input;
29
- }
30
- return {
31
- ...input,
32
- [richTextField]: createRichTextFromPlainText(String(input[textField] ?? "")),
33
- };
34
- };