@wirecat/bitrix24-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/LICENSE +204 -0
- package/README.md +17 -2
- package/dist/api-keys.d.ts +21 -0
- package/dist/api-keys.d.ts.map +1 -0
- package/dist/api-keys.js +58 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/bin/b24.d.ts +3 -0
- package/dist/bin/b24.d.ts.map +1 -0
- package/dist/bin/b24.js +40 -0
- package/dist/bin/b24.js.map +1 -0
- package/dist/bitrix/errors.d.ts +22 -0
- package/dist/bitrix/errors.d.ts.map +1 -0
- package/dist/bitrix/errors.js +76 -0
- package/dist/bitrix/errors.js.map +1 -0
- package/dist/bitrix/methods.d.ts +13 -0
- package/dist/bitrix/methods.d.ts.map +1 -0
- package/dist/bitrix/methods.js +33 -0
- package/dist/bitrix/methods.js.map +1 -0
- package/dist/bitrix/transport.d.ts +50 -0
- package/dist/bitrix/transport.d.ts.map +1 -0
- package/dist/bitrix/transport.js +189 -0
- package/dist/bitrix/transport.js.map +1 -0
- package/dist/bitrix/webhook.d.ts +14 -0
- package/dist/bitrix/webhook.d.ts.map +1 -0
- package/dist/bitrix/webhook.js +29 -0
- package/dist/bitrix/webhook.js.map +1 -0
- package/dist/bundle/all-profiles-QJ444GSX.js +24 -0
- package/dist/bundle/anthropic-RHRAVHC2.js +70 -0
- package/dist/bundle/app-server-QIT6S7AZ.js +224 -0
- package/dist/bundle/b24.js +32 -0
- package/dist/bundle/bun-H6RSODZ3.js +169 -0
- package/dist/bundle/bun-sqlite-BO4LTQHX.js +69 -0
- package/dist/bundle/chunk-2KCZ7BKW.js +215 -0
- package/dist/bundle/chunk-2SNUMZ7S.js +1028 -0
- package/dist/bundle/chunk-45AKJVKV.js +24 -0
- package/dist/bundle/chunk-4PDYYS5K.js +2 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-6WY72XVQ.js +216 -0
- package/dist/bundle/chunk-7GRZAKBB.js +639 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-BCF7P4FZ.js +558 -0
- package/dist/bundle/chunk-CNNEA2M4.js +54 -0
- package/dist/bundle/chunk-CXL33BFL.js +570 -0
- package/dist/bundle/chunk-CZ23EVP4.js +1691 -0
- package/dist/bundle/chunk-D5S6QV6R.js +95 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DTXERR44.js +35 -0
- package/dist/bundle/chunk-EVYSBZ3I.js +153 -0
- package/dist/bundle/chunk-EXOOKUEA.js +82 -0
- package/dist/bundle/chunk-FLUEXJ4X.js +53 -0
- package/dist/bundle/chunk-FOTREPNS.js +366 -0
- package/dist/bundle/chunk-FZL7F5NR.js +2022 -0
- package/dist/bundle/chunk-H2ADPPSH.js +50910 -0
- package/dist/bundle/chunk-HAXNUIGQ.js +1245 -0
- package/dist/bundle/chunk-HGL63O5V.js +288 -0
- package/dist/bundle/chunk-INFYLWUA.js +929 -0
- package/dist/bundle/chunk-IRV2PCQ2.js +5213 -0
- package/dist/bundle/chunk-K3UIB6ZF.js +45 -0
- package/dist/bundle/chunk-LRGYKOCP.js +91 -0
- package/dist/bundle/chunk-LSPIOT6Z.js +459 -0
- package/dist/bundle/chunk-MBDK4YXG.js +34 -0
- package/dist/bundle/chunk-N6FLBXZS.js +73 -0
- package/dist/bundle/chunk-OTD2ZRXD.js +161 -0
- package/dist/bundle/chunk-P33NDCDI.js +78 -0
- package/dist/bundle/chunk-P364PLIK.js +257 -0
- package/dist/bundle/chunk-PH5FZX6E.js +193 -0
- package/dist/bundle/chunk-POC3V3AO.js +36616 -0
- package/dist/bundle/chunk-QC53QBNC.js +143 -0
- package/dist/bundle/chunk-QGMDQ2PM.js +122 -0
- package/dist/bundle/chunk-QIPTIUMJ.js +281 -0
- package/dist/bundle/chunk-QMPN6WKD.js +3512 -0
- package/dist/bundle/chunk-QQXH2OPB.js +594 -0
- package/dist/bundle/chunk-QSNROIJL.js +413 -0
- package/dist/bundle/chunk-RRJNNPR4.js +76 -0
- package/dist/bundle/chunk-SFRNX2TI.js +6848 -0
- package/dist/bundle/chunk-SGRYYE4X.js +266 -0
- package/dist/bundle/chunk-TE3FR6MI.js +884 -0
- package/dist/bundle/chunk-U5ACMCAQ.js +12049 -0
- package/dist/bundle/chunk-VEWWAGTD.js +2315 -0
- package/dist/bundle/chunk-VL6SPMZV.js +194 -0
- package/dist/bundle/chunk-WII44RXN.js +58 -0
- package/dist/bundle/chunk-WKRQ44EH.js +528 -0
- package/dist/bundle/chunk-WTPMJYMD.js +8308 -0
- package/dist/bundle/chunk-XD4FRDSL.js +565 -0
- package/dist/bundle/chunk-XJXONOB5.js +63 -0
- package/dist/bundle/chunk-XNHSPHUN.js +48 -0
- package/dist/bundle/chunk-XRFJWHY5.js +131 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YYO7D2MO.js +783 -0
- package/dist/bundle/chunk-YZ5LHE5Q.js +31 -0
- package/dist/bundle/chunk-ZDQQCXFG.js +392 -0
- package/dist/bundle/chunk-ZEW4P6AH.js +158 -0
- package/dist/bundle/chunk-ZGZT5S6B.js +3480 -0
- package/dist/bundle/chunk-ZIAQPTUS.js +82 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-OKQOE6G4.js +30 -0
- package/dist/bundle/decode-5ZPLTYV6.js +160 -0
- package/dist/bundle/dist-PII6Z6X3.js +7577 -0
- package/dist/bundle/echarts-J6LAPIX7.js +42501 -0
- package/dist/bundle/embed-YG5LDHME.js +35 -0
- package/dist/bundle/embedder-7FNUA5OZ.js +108 -0
- package/dist/bundle/first-run-JPZNWIJN.js +23 -0
- package/dist/bundle/first-screen-VQM4MTS7.js +28 -0
- package/dist/bundle/instructions-AXWTQHMR.js +11 -0
- package/dist/bundle/mcp-7F46P6AM.js +165 -0
- package/dist/bundle/mcp-J5R5A65I.js +87 -0
- package/dist/bundle/mcp-WALJM6QX.js +160 -0
- package/dist/bundle/node-CWKAIOEM.js +176 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-LSEKVRDA.js +67 -0
- package/dist/bundle/oauth-THYNLRLD.js +17 -0
- package/dist/bundle/open-E47QYKFC.js +20 -0
- package/dist/bundle/openai-EWSGC3BC.js +227 -0
- package/dist/bundle/process-WKTEA3WE.js +91 -0
- package/dist/bundle/program-GO3RVP2H.js +20847 -0
- package/dist/bundle/prompt-CAQ7QR3U.js +12 -0
- package/dist/bundle/recognize-6KGHNZC3.js +23 -0
- package/dist/bundle/remote-3UO2WDC3.js +26 -0
- package/dist/bundle/rerank-2JVDPZBX.js +49 -0
- package/dist/bundle/serve-ES7AG5IK.js +19 -0
- package/dist/bundle/server-5LE5LNUQ.js +45 -0
- package/dist/bundle/server-BU4VBM6S.js +58 -0
- package/dist/bundle/state-7NH5G4XJ.js +33 -0
- package/dist/bundle/store-7O4JQD2Z.js +127 -0
- package/dist/bundle/store-maintenance-command-UDVGEY2D.js +47 -0
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +130 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/crm-writes.d.ts +4 -0
- package/dist/commands/crm-writes.d.ts.map +1 -0
- package/dist/commands/crm-writes.js +182 -0
- package/dist/commands/crm-writes.js.map +1 -0
- package/dist/commands/crm.d.ts +3 -0
- package/dist/commands/crm.d.ts.map +1 -0
- package/dist/commands/crm.js +142 -0
- package/dist/commands/crm.js.map +1 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +74 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +97 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +101 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/write.d.ts +21 -0
- package/dist/commands/write.d.ts.map +1 -0
- package/dist/commands/write.js +47 -0
- package/dist/commands/write.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +17 -0
- package/dist/config.js.map +1 -0
- package/dist/crm/conditions.d.ts +25 -0
- package/dist/crm/conditions.d.ts.map +1 -0
- package/dist/crm/conditions.js +78 -0
- package/dist/crm/conditions.js.map +1 -0
- package/dist/crm/deal.d.ts +27 -0
- package/dist/crm/deal.d.ts.map +1 -0
- package/dist/crm/deal.js +76 -0
- package/dist/crm/deal.js.map +1 -0
- package/dist/crm/items.d.ts +30 -0
- package/dist/crm/items.d.ts.map +1 -0
- package/dist/crm/items.js +76 -0
- package/dist/crm/items.js.map +1 -0
- package/dist/crm/lead.d.ts +36 -0
- package/dist/crm/lead.d.ts.map +1 -0
- package/dist/crm/lead.js +86 -0
- package/dist/crm/lead.js.map +1 -0
- package/dist/crm/organization.d.ts +32 -0
- package/dist/crm/organization.d.ts.map +1 -0
- package/dist/crm/organization.js +68 -0
- package/dist/crm/organization.js.map +1 -0
- package/dist/crm/person.d.ts +31 -0
- package/dist/crm/person.d.ts.map +1 -0
- package/dist/crm/person.js +68 -0
- package/dist/crm/person.js.map +1 -0
- package/dist/crm/pipeline.d.ts +17 -0
- package/dist/crm/pipeline.d.ts.map +1 -0
- package/dist/crm/pipeline.js +42 -0
- package/dist/crm/pipeline.js.map +1 -0
- package/dist/crm/product.d.ts +43 -0
- package/dist/crm/product.d.ts.map +1 -0
- package/dist/crm/product.js +42 -0
- package/dist/crm/product.js.map +1 -0
- package/dist/crm/stage.d.ts +20 -0
- package/dist/crm/stage.d.ts.map +1 -0
- package/dist/crm/stage.js +65 -0
- package/dist/crm/stage.js.map +1 -0
- package/dist/crm/user.d.ts +39 -0
- package/dist/crm/user.d.ts.map +1 -0
- package/dist/crm/user.js +54 -0
- package/dist/crm/user.js.map +1 -0
- package/dist/crm/values.d.ts +30 -0
- package/dist/crm/values.d.ts.map +1 -0
- package/dist/crm/values.js +50 -0
- package/dist/crm/values.js.map +1 -0
- package/dist/crm/walk.d.ts +19 -0
- package/dist/crm/walk.d.ts.map +1 -0
- package/dist/crm/walk.js +22 -0
- package/dist/crm/walk.js.map +1 -0
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +18 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +29 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +99 -0
- package/dist/mcp.js.map +1 -0
- package/dist/portal.d.ts +33 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +46 -0
- package/dist/portal.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +45 -0
- package/dist/program.js.map +1 -0
- package/dist/reasons.d.ts +10 -0
- package/dist/reasons.d.ts.map +1 -0
- package/dist/reasons.js +28 -0
- package/dist/reasons.js.map +1 -0
- package/dist/token.d.ts +12 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +41 -0
- package/dist/token.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/whoami.d.ts +8 -0
- package/dist/whoami.d.ts.map +1 -0
- package/dist/whoami.js +9 -0
- package/dist/whoami.js.map +1 -0
- package/package.json +83 -4
- package/skills/bitrix24-cli/SKILL.md +41 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { REMOTE_WRITE } from "@wirecat/cli-core/cli";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { DEAL } from "../crm/deal.js";
|
|
6
|
+
import { LEAD } from "../crm/lead.js";
|
|
7
|
+
import { ORGANIZATION } from "../crm/organization.js";
|
|
8
|
+
import { PERSON } from "../crm/person.js";
|
|
9
|
+
import { directoryOf, findStage, listStages } from "../crm/stage.js";
|
|
10
|
+
import { IDENTITY } from "../identity.js";
|
|
11
|
+
import { write } from "./write.js";
|
|
12
|
+
const B24 = IDENTITY.command;
|
|
13
|
+
const OPTIONS = {
|
|
14
|
+
title: (c) => c.option("--title <title>", "the title"),
|
|
15
|
+
name: (c) => c.option("--name <name>", "the name"),
|
|
16
|
+
firstName: (c) => c.option("--first-name <name>", "the person's first name"),
|
|
17
|
+
lastName: (c) => c.option("--last-name <name>", "the person's last name"),
|
|
18
|
+
};
|
|
19
|
+
const BODY = "the other fields to set, as a JSON object in Bitrix24's REST 3.0 names: " +
|
|
20
|
+
'{"opportunity":15000,"currencyId":"EUR","assignedById":7,"stageId":"C1:NEW","phone":[{"valueTypeId":"WORK","value":"+1…"}]}; ' +
|
|
21
|
+
"`api show crm.<type>.add` names them; assignedById other than the webhook's own user checks crm.assign-others";
|
|
22
|
+
const bodyOf = (raw) => {
|
|
23
|
+
if (raw === undefined)
|
|
24
|
+
return {};
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = JSON.parse(raw);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
throw new CliError("validation_error", "--body is not JSON", { param: "--body" });
|
|
31
|
+
}
|
|
32
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
33
|
+
throw new CliError("validation_error", "--body takes a JSON object of fields", { param: "--body" });
|
|
34
|
+
return parsed;
|
|
35
|
+
};
|
|
36
|
+
/** The fields to send: the named options over what `--body` gives. */
|
|
37
|
+
const fieldsOf = (options) => {
|
|
38
|
+
const fields = bodyOf(options.body);
|
|
39
|
+
const set = (key, value) => {
|
|
40
|
+
if (value !== undefined)
|
|
41
|
+
fields[key] = value;
|
|
42
|
+
};
|
|
43
|
+
set("title", options.title ?? options.name);
|
|
44
|
+
set("name", options.firstName);
|
|
45
|
+
set("lastName", options.lastName);
|
|
46
|
+
return fields;
|
|
47
|
+
};
|
|
48
|
+
/** Who the write assigns the record to, when it does: the guard compares it with the webhook's own user. */
|
|
49
|
+
const assigneeOf = (fields) => fields.assignedById === undefined || fields.assignedById === null ? undefined : String(fields.assignedById);
|
|
50
|
+
/** The pipeline a deal is in, so `--stage` is read among that pipeline's stages. */
|
|
51
|
+
const dealPipeline = async (portal, id) => {
|
|
52
|
+
const answer = await portal.call("crm.deal.get", { id: Number(id), select: ["id", "categoryId"] });
|
|
53
|
+
const item = answer.result?.item;
|
|
54
|
+
if (!item)
|
|
55
|
+
throw new CliError("not_found", `there is no deal ${id}`);
|
|
56
|
+
return String(item.categoryId ?? "0");
|
|
57
|
+
};
|
|
58
|
+
const KINDS = [
|
|
59
|
+
{
|
|
60
|
+
noun: "deals",
|
|
61
|
+
type: DEAL,
|
|
62
|
+
create: ["title"],
|
|
63
|
+
needs: ["title"],
|
|
64
|
+
moves: true,
|
|
65
|
+
examples: {
|
|
66
|
+
create: `${B24} work deals create --title "Kitchen for Acme" --body '{"opportunity":15000,"currencyId":"EUR"}'`,
|
|
67
|
+
update: `${B24} work deals update 42 --body '{"opportunity":18000}'`,
|
|
68
|
+
move: `${B24} work deals move 42 --stage "Contract signed"`,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
noun: "leads",
|
|
73
|
+
type: LEAD,
|
|
74
|
+
create: ["title", "firstName", "lastName"],
|
|
75
|
+
needs: ["title", "firstName", "lastName"],
|
|
76
|
+
moves: true,
|
|
77
|
+
examples: {
|
|
78
|
+
create: `${B24} work leads create --title "Website form" --first-name Ivan`,
|
|
79
|
+
update: `${B24} work leads update 7 --body '{"opportunity":5000}'`,
|
|
80
|
+
move: `${B24} work leads move 7 --stage IN_PROCESS`,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
noun: "people",
|
|
85
|
+
type: PERSON,
|
|
86
|
+
create: ["firstName", "lastName"],
|
|
87
|
+
needs: ["firstName", "lastName"],
|
|
88
|
+
moves: false,
|
|
89
|
+
examples: {
|
|
90
|
+
create: `${B24} work people create --first-name Anna --last-name Ivanova`,
|
|
91
|
+
update: `${B24} work people update 4 --body '{"post":"Buyer"}'`,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
noun: "organizations",
|
|
96
|
+
type: ORGANIZATION,
|
|
97
|
+
create: ["name"],
|
|
98
|
+
needs: ["name"],
|
|
99
|
+
moves: false,
|
|
100
|
+
examples: {
|
|
101
|
+
create: `${B24} work organizations create --name "Acme"`,
|
|
102
|
+
update: `${B24} work organizations update 9 --name "Acme Ltd"`,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
const flagOf = (option) => `--${option.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}`;
|
|
107
|
+
const withOptions = (command, options) => {
|
|
108
|
+
for (const option of options)
|
|
109
|
+
OPTIONS[option](command);
|
|
110
|
+
return command
|
|
111
|
+
.option("--body <json>", BODY)
|
|
112
|
+
.option("--operation-id <id>", "the operation_id an outcome_unknown named: a retry Bitrix24 will not run twice");
|
|
113
|
+
};
|
|
114
|
+
/** A deal's stages are its pipeline's; a lead's are the lead directory. */
|
|
115
|
+
const stageDirectory = async (kind, portal, id) => kind.noun === "leads" ? directoryOf("leads") : directoryOf("deals", await dealPipeline(portal, id));
|
|
116
|
+
const createCommand = (kind) => withOptions(annotate(new Command("create"), { effects: REMOTE_WRITE, offline: false, examples: [kind.examples.create] }), kind.create)
|
|
117
|
+
.description(`create one ${kind.type.word} on the portal`)
|
|
118
|
+
.action(async function (options) {
|
|
119
|
+
if (!kind.needs.some((one) => options[one] !== undefined))
|
|
120
|
+
throw new CliError("validation_error", `a new ${kind.type.word} needs ${kind.needs.map(flagOf).join(" or ")}`);
|
|
121
|
+
const fields = fieldsOf(options);
|
|
122
|
+
await write(this, {
|
|
123
|
+
key: `${kind.noun}.create`,
|
|
124
|
+
assignee: assigneeOf(fields),
|
|
125
|
+
operationId: options.operationId,
|
|
126
|
+
act: async (portal, operationId) => {
|
|
127
|
+
const answer = await portal.call(`crm.${kind.type.type}.add`, { fields }, { idempotencyKey: operationId });
|
|
128
|
+
const id = String(answer.result?.id ?? "");
|
|
129
|
+
if (!id)
|
|
130
|
+
throw new CliError("invalid_response", `Bitrix24 answered the new ${kind.type.word} without its id`);
|
|
131
|
+
return { id, created: true };
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
const updateCommand = (kind) => withOptions(annotate(new Command("update"), { effects: REMOTE_WRITE, offline: false, examples: [kind.examples.update] }), kind.create)
|
|
136
|
+
.description(`change one ${kind.type.word} on the portal; options left out keep their values`)
|
|
137
|
+
.argument("<id>", `the ${kind.type.word}'s id`)
|
|
138
|
+
.action(async function (id, options) {
|
|
139
|
+
if (!/^[1-9]\d*$/.test(id))
|
|
140
|
+
throw new CliError("validation_error", `${kind.noun} update takes the ${kind.type.word}'s id`);
|
|
141
|
+
const fields = fieldsOf(options);
|
|
142
|
+
if (Object.keys(fields).length === 0)
|
|
143
|
+
throw new CliError("validation_error", "nothing to change: name a field");
|
|
144
|
+
await write(this, {
|
|
145
|
+
key: `${kind.noun}.update`,
|
|
146
|
+
assignee: assigneeOf(fields),
|
|
147
|
+
operationId: options.operationId,
|
|
148
|
+
act: async (portal, operationId) => {
|
|
149
|
+
await portal.call(`crm.${kind.type.type}.update`, { id: Number(id), fields }, { idempotencyKey: operationId });
|
|
150
|
+
return { id, updated: Object.keys(fields) };
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
const moveCommand = (kind) => annotate(new Command("move"), { effects: REMOTE_WRITE, offline: false, examples: [kind.examples.move ?? ""] })
|
|
155
|
+
.description(`move one ${kind.type.word} to another stage`)
|
|
156
|
+
.argument("<id>", `the ${kind.type.word}'s id`)
|
|
157
|
+
.requiredOption("--stage <stage>", "the stage, by id or name, as `stages list` prints it")
|
|
158
|
+
.option("--operation-id <id>", "the operation_id an outcome_unknown named: a retry Bitrix24 will not run twice")
|
|
159
|
+
.action(async function (id, options) {
|
|
160
|
+
if (!/^[1-9]\d*$/.test(id))
|
|
161
|
+
throw new CliError("validation_error", `${kind.noun} move takes the ${kind.type.word}'s id`);
|
|
162
|
+
await write(this, {
|
|
163
|
+
key: `${kind.noun}.move`,
|
|
164
|
+
operationId: options.operationId,
|
|
165
|
+
act: async (portal, operationId) => {
|
|
166
|
+
const stage = findStage(await listStages(portal, await stageDirectory(kind, portal, id)), options.stage ?? "");
|
|
167
|
+
await portal.call(`crm.${kind.type.type}.update`, { id: Number(id), fields: { stageId: stage.id } }, { idempotencyKey: operationId });
|
|
168
|
+
return { id, stage_id: stage.id, outcome: stage.outcome };
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
/** The writes of each CRM noun, added to the noun's read commands. */
|
|
173
|
+
export const addWrites = (noun) => {
|
|
174
|
+
const kind = KINDS.find((one) => one.noun === noun.name());
|
|
175
|
+
if (!kind)
|
|
176
|
+
return noun;
|
|
177
|
+
noun.addCommand(createCommand(kind)).addCommand(updateCommand(kind));
|
|
178
|
+
if (kind.moves)
|
|
179
|
+
noun.addCommand(moveCommand(kind));
|
|
180
|
+
return noun;
|
|
181
|
+
};
|
|
182
|
+
//# sourceMappingURL=crm-writes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crm-writes.js","sourceRoot":"","sources":["../../src/commands/crm-writes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,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.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AA+InC,eAAO,MAAM,WAAW,QAAO,OAAO,EAoGrC,CAAA"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { defineQuery, queryFieldsOf } from "@wirecat/cli-base/query";
|
|
3
|
+
import { answerEntity, commandPath, itemOf, listQuery, nativeTerms, outputFor, pagedList, REMOTE_READ, renderAnswer, typedQuery, unfilteredQuery, withPaging, withQuery, } from "@wirecat/cli-core/cli";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { conditionsOf } from "../crm/conditions.js";
|
|
6
|
+
import { DEAL, DEAL_FIELDS, dealSchema } from "../crm/deal.js";
|
|
7
|
+
import { getItem, listItems, resolveItem } from "../crm/items.js";
|
|
8
|
+
import { LEAD, LEAD_FIELDS, leadSchema } from "../crm/lead.js";
|
|
9
|
+
import { ORGANIZATION, ORGANIZATION_FIELDS, organizationSchema } from "../crm/organization.js";
|
|
10
|
+
import { PERSON, PERSON_FIELDS, personSchema } from "../crm/person.js";
|
|
11
|
+
import { findPipeline, listPipelines, pipelineSchema } from "../crm/pipeline.js";
|
|
12
|
+
import { getProduct, listProducts, PRODUCT_FIELDS, productSchema } from "../crm/product.js";
|
|
13
|
+
import { directoryOf, findStage, listStages, stageSchema } from "../crm/stage.js";
|
|
14
|
+
import { getUser, listUsers, USER_FIELDS, userSchema } from "../crm/user.js";
|
|
15
|
+
import { IDENTITY } from "../identity.js";
|
|
16
|
+
import { contextOf, portalOf } from "../portal.js";
|
|
17
|
+
const B24 = IDENTITY.command;
|
|
18
|
+
const nativeQuery = (entity, schema, fields, examples = {}) => defineQuery({
|
|
19
|
+
entity,
|
|
20
|
+
backend: "native",
|
|
21
|
+
fields: queryFieldsOf(schema, {
|
|
22
|
+
exclude: ["provider_metadata", "url"],
|
|
23
|
+
native: Object.keys(fields),
|
|
24
|
+
text: Object.entries(fields)
|
|
25
|
+
.filter(([, map]) => map.kind === "word")
|
|
26
|
+
.map(([name]) => name),
|
|
27
|
+
examples,
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
const windowOf = (command) => {
|
|
31
|
+
const { settings } = contextOf(command);
|
|
32
|
+
return settings.all ? { offset: 0 } : { offset: (settings.page - 1) * settings.limit, limit: settings.limit };
|
|
33
|
+
};
|
|
34
|
+
const listCommand = (noun) => withPaging(withQuery(answerEntity(annotate(new Command("list"), { effects: REMOTE_READ, offline: false, examples: noun.examples }), noun.entity, noun.schema), noun.query))
|
|
35
|
+
.description(`list ${noun.what} on the portal, newest first`)
|
|
36
|
+
.action(async function (words) {
|
|
37
|
+
const path = commandPath(this);
|
|
38
|
+
const terms = nativeTerms(listQuery(typedQuery(words), noun.query, path, noun.word ? { defaultField: noun.word } : {}), path);
|
|
39
|
+
const { settings } = contextOf(this);
|
|
40
|
+
const found = await noun.list(portalOf(this), terms, windowOf(this));
|
|
41
|
+
renderAnswer(this, outputFor(this), pagedList(path, settings, found));
|
|
42
|
+
});
|
|
43
|
+
const showCommand = (noun) => answerEntity(annotate(new Command("show"), {
|
|
44
|
+
effects: REMOTE_READ,
|
|
45
|
+
offline: false,
|
|
46
|
+
examples: [`${B24} work ${noun.noun} show 42`, `${B24} work ${noun.noun} show 42 --json`],
|
|
47
|
+
}), noun.entity, noun.schema)
|
|
48
|
+
.description(`show one of the ${noun.what} on the portal`)
|
|
49
|
+
.argument(`<${noun.reference}>`, `the ${noun.reference} as list prints it`)
|
|
50
|
+
.action(async function (reference) {
|
|
51
|
+
renderAnswer(this, outputFor(this), itemOf(await noun.show(portalOf(this), reference)));
|
|
52
|
+
});
|
|
53
|
+
const nounCommand = (noun, description) => annotate(new Command(noun.noun), { effects: REMOTE_READ })
|
|
54
|
+
.description(description)
|
|
55
|
+
.addCommand(listCommand(noun))
|
|
56
|
+
.addCommand(showCommand(noun));
|
|
57
|
+
const itemNoun = (type, shape, examples, listExamples) => {
|
|
58
|
+
const word = Object.entries(shape.fields).find(([, map]) => map.kind === "word")?.[0];
|
|
59
|
+
return {
|
|
60
|
+
...shape,
|
|
61
|
+
query: nativeQuery(shape.entity, shape.schema, shape.fields, examples),
|
|
62
|
+
...(word ? { word } : {}),
|
|
63
|
+
examples: listExamples,
|
|
64
|
+
reference: "id-or-name",
|
|
65
|
+
list: (portal, terms, window) => listItems(portal, type, conditionsOf(terms, shape.fields), window),
|
|
66
|
+
show: async (portal, reference) => getItem(portal, type, await resolveItem(portal, type, reference)),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const whole = (items) => ({ items, has_more: false });
|
|
70
|
+
const STAGE_FIELDS = {
|
|
71
|
+
entity: { field: "ENTITY_ID", kind: "text" },
|
|
72
|
+
pipeline_id: { field: "ENTITY_ID", kind: "id" },
|
|
73
|
+
};
|
|
74
|
+
/** The stage directories a query names: one for leads or one pipeline, or all of them. */
|
|
75
|
+
const stagesFor = async (portal, conditions) => {
|
|
76
|
+
const entity = conditions.find((one) => one.field === "ENTITY_ID" && typeof one.value === "string")?.value;
|
|
77
|
+
const pipeline = conditions.find((one) => typeof one.value === "number")?.value;
|
|
78
|
+
if (entity === "leads")
|
|
79
|
+
return listStages(portal, directoryOf("leads"));
|
|
80
|
+
if (pipeline !== undefined)
|
|
81
|
+
return listStages(portal, directoryOf("deals", String(pipeline)));
|
|
82
|
+
const all = await listStages(portal);
|
|
83
|
+
return entity === "deals" ? all.filter((stage) => stage.entity === "deals") : all;
|
|
84
|
+
};
|
|
85
|
+
export const crmCommands = () => [
|
|
86
|
+
nounCommand(itemNoun(DEAL, { noun: "deals", entity: "deal", schema: dealSchema, what: "deals", fields: DEAL_FIELDS }, { title: "title:kitchen*", stage_id: 'stage_id:"C1:WON"' }, [`${B24} work deals list`, `${B24} work deals list outcome:open pipeline_id:1 amount>=10000`]), "read the portal's deals"),
|
|
87
|
+
nounCommand(itemNoun(LEAD, { noun: "leads", entity: "lead", schema: leadSchema, what: "leads", fields: LEAD_FIELDS }, { title: "title:kitchen*", stage_id: "stage_id:NEW" }, [`${B24} work leads list`, `${B24} work leads list outcome:open updated_at>=7d`]), "read the portal's leads"),
|
|
88
|
+
nounCommand(itemNoun(PERSON, { noun: "people", entity: "crm_person", schema: personSchema, what: "contacts", fields: PERSON_FIELDS }, { name: "name:ivan*" }, [`${B24} work people list`, `${B24} work people list name:ivan*`]), "read the portal's contacts"),
|
|
89
|
+
nounCommand(itemNoun(ORGANIZATION, {
|
|
90
|
+
noun: "organizations",
|
|
91
|
+
entity: "crm_organization",
|
|
92
|
+
schema: organizationSchema,
|
|
93
|
+
what: "companies",
|
|
94
|
+
fields: ORGANIZATION_FIELDS,
|
|
95
|
+
}, { name: "name:acme*" }, [`${B24} work organizations list`, `${B24} work organizations list name:acme*`]), "read the portal's companies"),
|
|
96
|
+
nounCommand({
|
|
97
|
+
noun: "pipelines",
|
|
98
|
+
entity: "pipeline",
|
|
99
|
+
schema: pipelineSchema,
|
|
100
|
+
what: "deal pipelines",
|
|
101
|
+
query: unfilteredQuery("pipeline", pipelineSchema),
|
|
102
|
+
examples: [`${B24} work pipelines list`, `${B24} work pipelines list --json`],
|
|
103
|
+
reference: "id-or-name",
|
|
104
|
+
list: async (portal) => whole(await listPipelines(portal)),
|
|
105
|
+
show: async (portal, reference) => findPipeline(await listPipelines(portal), reference),
|
|
106
|
+
}, "read the portal's deal pipelines"),
|
|
107
|
+
nounCommand({
|
|
108
|
+
noun: "stages",
|
|
109
|
+
entity: "stage",
|
|
110
|
+
schema: stageSchema,
|
|
111
|
+
what: "deal and lead stages, each with its outcome",
|
|
112
|
+
query: nativeQuery("stage", stageSchema, STAGE_FIELDS),
|
|
113
|
+
examples: [`${B24} work stages list`, `${B24} work stages list entity:leads`],
|
|
114
|
+
reference: "id-or-name",
|
|
115
|
+
list: async (portal, terms) => whole(await stagesFor(portal, conditionsOf(terms, STAGE_FIELDS))),
|
|
116
|
+
show: async (portal, reference) => findStage(await listStages(portal), reference),
|
|
117
|
+
}, "read the stages of the portal's deal pipelines and leads"),
|
|
118
|
+
nounCommand({
|
|
119
|
+
noun: "products",
|
|
120
|
+
entity: "product",
|
|
121
|
+
schema: productSchema,
|
|
122
|
+
what: "catalog products",
|
|
123
|
+
query: nativeQuery("product", productSchema, PRODUCT_FIELDS),
|
|
124
|
+
word: "name",
|
|
125
|
+
examples: [`${B24} work products list`, `${B24} work products list active:true name:chair*`],
|
|
126
|
+
reference: "id",
|
|
127
|
+
list: (portal, terms, window) => listProducts(portal, conditionsOf(terms, PRODUCT_FIELDS), window),
|
|
128
|
+
show: getProduct,
|
|
129
|
+
}, "read the portal's product catalog"),
|
|
130
|
+
nounCommand({
|
|
131
|
+
noun: "users",
|
|
132
|
+
entity: "user",
|
|
133
|
+
schema: userSchema,
|
|
134
|
+
what: "employees",
|
|
135
|
+
query: nativeQuery("user", userSchema, USER_FIELDS),
|
|
136
|
+
examples: [`${B24} work users list`, `${B24} work users list active:true`],
|
|
137
|
+
reference: "id",
|
|
138
|
+
list: (portal, terms, window) => listUsers(portal, conditionsOf(terms, USER_FIELDS), window),
|
|
139
|
+
show: getUser,
|
|
140
|
+
}, "read the portal's employees"),
|
|
141
|
+
];
|
|
142
|
+
//# sourceMappingURL=crm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crm.js","sourceRoot":"","sources":["../../src/commands/crm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,WAAW,EAAsC,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACxG,OAAO,EACL,YAAY,EACZ,WAAW,EACX,MAAM,EACN,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACV,eAAe,EACf,UAAU,EACV,SAAS,GACV,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGn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QACxB,KAAK,EAAE,WAAW,CAAC,SAAS,EAAE,aAAa,EAAE,cAAc,CAAC;QAC5D,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,CAAC,GAAG,GAAG,qBAAqB,EAAE,GAAG,GAAG,6CAA6C,CAAC;QAC5F,SAAS,EAAE,IAAI;QACf,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC;QAClG,IAAI,EAAE,UAAU;KACjB,EACD,mCAAmC,CACpC;IACD,WAAW,CACT;QACE,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC;QACnD,QAAQ,EAAE,CAAC,GAAG,GAAG,kBAAkB,EAAE,GAAG,GAAG,8BAA8B,CAAC;QAC1E,SAAS,EAAE,IAAI;QACf,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC;QAC5F,IAAI,EAAE,OAAO;KACd,EACD,6BAA6B,CAC9B;CACF,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* It is run when everything else is broken, so a problem in the config file is a field in the answer, never a throw.
|
|
4
|
+
* `fixes` are the `chmod` commands that make the config private; they go to stderr, not into the answer.
|
|
5
|
+
*/
|
|
6
|
+
export declare const doctorReport: (env: NodeJS.ProcessEnv) => {
|
|
7
|
+
report: {
|
|
8
|
+
version: string;
|
|
9
|
+
runtime: {
|
|
10
|
+
node: string;
|
|
11
|
+
platform: NodeJS.Platform;
|
|
12
|
+
};
|
|
13
|
+
paths: {
|
|
14
|
+
config: string;
|
|
15
|
+
state: string;
|
|
16
|
+
cache: string;
|
|
17
|
+
};
|
|
18
|
+
config: {
|
|
19
|
+
path: string;
|
|
20
|
+
found: boolean;
|
|
21
|
+
issues: import("@wirecat/cli-core/cli").ConfigIssue[];
|
|
22
|
+
};
|
|
23
|
+
profiles: string[];
|
|
24
|
+
read_only: string | null;
|
|
25
|
+
files: {
|
|
26
|
+
checked: false;
|
|
27
|
+
reason: string;
|
|
28
|
+
} | {
|
|
29
|
+
checked: true;
|
|
30
|
+
ok: boolean;
|
|
31
|
+
problems: {
|
|
32
|
+
path: string;
|
|
33
|
+
mode: string;
|
|
34
|
+
want: string;
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
fixes: string[] | never[];
|
|
39
|
+
} | {
|
|
40
|
+
report: {
|
|
41
|
+
version: string;
|
|
42
|
+
runtime: {
|
|
43
|
+
node: string;
|
|
44
|
+
platform: NodeJS.Platform;
|
|
45
|
+
};
|
|
46
|
+
paths: {
|
|
47
|
+
config: string;
|
|
48
|
+
state: string;
|
|
49
|
+
cache: string;
|
|
50
|
+
};
|
|
51
|
+
config: {
|
|
52
|
+
path: string;
|
|
53
|
+
found: boolean;
|
|
54
|
+
issues: never[];
|
|
55
|
+
};
|
|
56
|
+
settings: {
|
|
57
|
+
error: string;
|
|
58
|
+
};
|
|
59
|
+
profiles: null;
|
|
60
|
+
read_only: string | null;
|
|
61
|
+
files: {
|
|
62
|
+
checked: false;
|
|
63
|
+
reason: string;
|
|
64
|
+
} | {
|
|
65
|
+
checked: true;
|
|
66
|
+
ok: boolean;
|
|
67
|
+
problems: {
|
|
68
|
+
path: string;
|
|
69
|
+
mode: string;
|
|
70
|
+
want: string;
|
|
71
|
+
}[];
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
fixes: string[] | never[];
|
|
75
|
+
};
|
|
76
|
+
export declare const doctorCommand: () => Command;
|
|
77
|
+
//# sourceMappingURL=doctor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAenC;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAS,MAAM,CAAC,UAAU;;;;YAIpC,IAAI;YAAyB,QAAQ;;;YACvC,MAAM;YAAgB,KAAK;YAAe,KAAK;;;YAS1C,IAAI;YAAuB,KAAK;YAAwB,MAAM;;;;;;;;;;;;;;;;;;;;;;YAVjE,IAAI;YAAyB,QAAQ;;;YACvC,MAAM;YAAgB,KAAK;YAAe,KAAK;;;YAsB1C,IAAI;YAAQ,KAAK;YAAoB,MAAM;;;YACzC,KAAK;;;;;;;;;;;;;;;;;;CAQxB,CAAA;AAED,eAAO,MAAM,aAAa,QAAO,OAc3B,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { configFilePath, resolvePaths } from "@wirecat/cli-base";
|
|
4
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
|
+
import { environmentOf, itemOf, LOCAL_READ, outputFor, privateFiles, profileFree, readOnlyLockOf, renderAnswer, } from "@wirecat/cli-core/cli";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import { configuration } from "../config.js";
|
|
8
|
+
import { IDENTITY } from "../identity.js";
|
|
9
|
+
const failure = (error) => (error instanceof Error ? error.message : String(error));
|
|
10
|
+
const configFiles = (path) => {
|
|
11
|
+
const files = privateFiles({ files: [path], dirs: [dirname(path)] });
|
|
12
|
+
if (!files.checked)
|
|
13
|
+
return { files, fixes: [] };
|
|
14
|
+
return {
|
|
15
|
+
files: { ...files, problems: files.problems.map(({ path, mode, want }) => ({ path, mode, want })) },
|
|
16
|
+
fixes: files.problems.map((problem) => problem.fix),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* It is run when everything else is broken, so a problem in the config file is a field in the answer, never a throw.
|
|
21
|
+
* `fixes` are the `chmod` commands that make the config private; they go to stderr, not into the answer.
|
|
22
|
+
*/
|
|
23
|
+
export const doctorReport = (env) => {
|
|
24
|
+
const paths = resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env });
|
|
25
|
+
const common = {
|
|
26
|
+
version: IDENTITY.version,
|
|
27
|
+
runtime: { node: process.versions.node, platform: process.platform },
|
|
28
|
+
paths: { config: paths.config, state: paths.state, cache: paths.cache },
|
|
29
|
+
};
|
|
30
|
+
const readOnly = readOnlyLockOf(IDENTITY, env) ?? null;
|
|
31
|
+
try {
|
|
32
|
+
const settings = configuration.resolveSettings({}, { env, readOnly: true, needsProfile: false, withIssues: true });
|
|
33
|
+
const { files, fixes } = configFiles(settings.configPath);
|
|
34
|
+
return {
|
|
35
|
+
report: {
|
|
36
|
+
...common,
|
|
37
|
+
config: { path: settings.configPath, found: settings.configFound, issues: settings.configIssues ?? [] },
|
|
38
|
+
profiles: settings.configuredProfiles,
|
|
39
|
+
read_only: readOnly,
|
|
40
|
+
files,
|
|
41
|
+
},
|
|
42
|
+
fixes,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const file = configFilePath(paths.config);
|
|
47
|
+
const { files, fixes } = configFiles(file);
|
|
48
|
+
return {
|
|
49
|
+
report: {
|
|
50
|
+
...common,
|
|
51
|
+
config: { path: file, found: existsSync(file), issues: [] },
|
|
52
|
+
settings: { error: failure(error) },
|
|
53
|
+
profiles: null,
|
|
54
|
+
read_only: readOnly,
|
|
55
|
+
files,
|
|
56
|
+
},
|
|
57
|
+
fixes,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export const doctorCommand = () => profileFree(annotate(new Command("doctor"), {
|
|
62
|
+
effects: LOCAL_READ,
|
|
63
|
+
examples: [`${IDENTITY.command} doctor`, `${IDENTITY.command} doctor --json`],
|
|
64
|
+
}))
|
|
65
|
+
.description("check this installation: version, paths, config, profiles; no keyring or network")
|
|
66
|
+
.action(function () {
|
|
67
|
+
const env = environmentOf(this).env ?? process.env;
|
|
68
|
+
const { report, fixes } = doctorReport(env);
|
|
69
|
+
const output = outputFor(this);
|
|
70
|
+
renderAnswer(this, output, itemOf(report));
|
|
71
|
+
for (const fix of fixes)
|
|
72
|
+
output.renderer.note(`to make it private: ${fix}`);
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=doctor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EACL,aAAa,EACb,MAAM,EACN,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,cAAc,EACd,YAAY,GACb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,OAAO,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;AAE5F,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE;IACnC,MAAM,KAAK,GAAG,YAAY,CAAC,EAAE,KAAK,EAA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,CAAC,OAAO,SAAS,EAAE,GAAG,QAAQ,CAAC,OAAO,gBAAgB,CAAC;CAC9E,CAAC,CACH;KACE,WAAW,CAAC,kFAAkF,CAAC;KAC/F,MAAM,CAAC;IACN,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAA;IAClD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;IAC3C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAC9B,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;IAC1C,KAAK,MAAM,GAAG,IAAI,KAAK;QAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC,CAAA;AAC7E,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAwFnC,eAAO,MAAM,UAAU,QAAO,OAuBzB,CAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate, describeProgram } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { changesAuthorityAt, environmentOf, httpTokenFile, itemOf, LOCAL_READ, LOCAL_WRITE, MCP_HTTP_DEFAULT_PORT, mcpServerCommand, outputFor, REMOTE_WRITE, refuseUnderReadOnly, renderAnswer, rootOf, } from "@wirecat/cli-core/cli";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { configuration } from "../config.js";
|
|
6
|
+
import { IDENTITY } from "../identity.js";
|
|
7
|
+
const SETUP = `claude mcp add ${IDENTITY.command} -- ${IDENTITY.command} personal mcp serve`;
|
|
8
|
+
const settingsOf = (command) => {
|
|
9
|
+
const flags = command.optsWithGlobals();
|
|
10
|
+
const env = environmentOf(command).env ?? process.env;
|
|
11
|
+
const { profile } = configuration.resolveSettings(flags, { env });
|
|
12
|
+
return { flags, env, profile, tokenFile: httpTokenFile(IDENTITY, profile, env) };
|
|
13
|
+
};
|
|
14
|
+
const serveCommand = () => annotate(new Command("serve"), {
|
|
15
|
+
effects: REMOTE_WRITE,
|
|
16
|
+
lifetime: "persistent",
|
|
17
|
+
mcp: false,
|
|
18
|
+
examples: [
|
|
19
|
+
`${IDENTITY.command} personal mcp serve`,
|
|
20
|
+
`${IDENTITY.command} personal mcp serve --http --public-url https://laptop.example.ts.net`,
|
|
21
|
+
],
|
|
22
|
+
})
|
|
23
|
+
.summary("serve this profile's commands to an AI agent")
|
|
24
|
+
.description(`serve this profile's commands to an agent over MCP, on stdin and stdout, writes included; the profile's permissions decide — \`${SETUP}\``)
|
|
25
|
+
.option("--http", "serve over HTTP on 127.0.0.1 for ChatGPT and Claude in the browser, behind your tunnel; the profile's permissions decide")
|
|
26
|
+
.option("--port <port>", `the local port for --http (default ${MCP_HTTP_DEFAULT_PORT})`)
|
|
27
|
+
.option("--public-url <url>", "the tunnel's https address the browser apps use, e.g. https://<name>.ts.net")
|
|
28
|
+
.action(async function () {
|
|
29
|
+
const { flags, env, profile, tokenFile } = settingsOf(this);
|
|
30
|
+
if (!flags.http && (flags.json || flags.jsonl))
|
|
31
|
+
throw new CliError("validation_error", "MCP over stdio controls its own output; leave out --json and --jsonl");
|
|
32
|
+
const environment = environmentOf(this);
|
|
33
|
+
const run = environment.runCommand;
|
|
34
|
+
if (!run)
|
|
35
|
+
throw new Error("mcp serve runs inside the program's run(), which provides runCommand");
|
|
36
|
+
const program = rootOf(this);
|
|
37
|
+
const options = {
|
|
38
|
+
profile,
|
|
39
|
+
commands: describeProgram(program),
|
|
40
|
+
levels: () => configuration.resolveSettings(flags, { env }).permissions,
|
|
41
|
+
authority: changesAuthorityAt(program),
|
|
42
|
+
run,
|
|
43
|
+
...(environment.signal ? { signal: environment.signal } : {}),
|
|
44
|
+
};
|
|
45
|
+
// Loaded here, not at the top: every other command would otherwise pay for the MCP SDK.
|
|
46
|
+
const { serveMcp, serveMcpOverHttp } = await import("../mcp.js");
|
|
47
|
+
if (!flags.http)
|
|
48
|
+
return serveMcp(options);
|
|
49
|
+
const { portOf, publicUrlOf } = await import("@wirecat/cli-core/mcp");
|
|
50
|
+
const { renderer } = outputFor(this);
|
|
51
|
+
await serveMcpOverHttp(options, {
|
|
52
|
+
publicUrl: publicUrlOf(flags.publicUrl, {
|
|
53
|
+
missing: "--http",
|
|
54
|
+
reaches: `the browser apps reach ${IDENTITY.command}`,
|
|
55
|
+
}),
|
|
56
|
+
port: portOf(flags.port, MCP_HTTP_DEFAULT_PORT),
|
|
57
|
+
tokenFile,
|
|
58
|
+
background: env[`${IDENTITY.envPrefix}_MCP_HTTP`] !== undefined,
|
|
59
|
+
note: (line) => renderer.note(line),
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
const revokeCommand = () => annotate(new Command("revoke"), {
|
|
63
|
+
effects: LOCAL_WRITE,
|
|
64
|
+
mcp: false,
|
|
65
|
+
examples: [`${IDENTITY.command} personal mcp revoke`],
|
|
66
|
+
})
|
|
67
|
+
.summary("forget every login given to a browser app")
|
|
68
|
+
.description("forget every login `mcp serve --http` gave a browser app; each must log in again")
|
|
69
|
+
.action(async function () {
|
|
70
|
+
refuseUnderReadOnly(this, "mcp revoke");
|
|
71
|
+
const { profile, tokenFile } = settingsOf(this);
|
|
72
|
+
const { revokeAll } = await import("@wirecat/cli-core/mcp");
|
|
73
|
+
revokeAll(tokenFile);
|
|
74
|
+
renderAnswer(this, outputFor(this), itemOf({ revoked: true, profile }));
|
|
75
|
+
});
|
|
76
|
+
export const mcpCommand = () => annotate(new Command("mcp"), { effects: LOCAL_READ, mcp: false })
|
|
77
|
+
.summary("serve this profile's commands to an AI agent")
|
|
78
|
+
.description(`serve this profile's commands to an agent over MCP — \`${SETUP}\``)
|
|
79
|
+
.addCommand(serveCommand())
|
|
80
|
+
.addCommand(revokeCommand())
|
|
81
|
+
.addCommand(mcpServerCommand({
|
|
82
|
+
example: `${IDENTITY.command} personal`,
|
|
83
|
+
target: (self) => {
|
|
84
|
+
const { env, profile, tokenFile } = settingsOf(self);
|
|
85
|
+
return {
|
|
86
|
+
invocation: `${IDENTITY.command} ${profile}`,
|
|
87
|
+
profile,
|
|
88
|
+
envPrefix: IDENTITY.envPrefix,
|
|
89
|
+
env,
|
|
90
|
+
tokenFile,
|
|
91
|
+
argv: [profile, "mcp", "serve", "--http"],
|
|
92
|
+
version: IDENTITY.version,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
answer: (self, item, lines) => renderAnswer(self, outputFor(self), itemOf(item), () => lines.join("\n")),
|
|
96
|
+
}));
|
|
97
|
+
//# sourceMappingURL=mcp.js.map
|