@wirecat/amo-cli 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/LICENSE +204 -0
- package/README.md +265 -2
- package/contracts/wirecat.json +1356 -0
- package/dist/amo/account.d.ts +18 -0
- package/dist/amo/account.d.ts.map +1 -0
- package/dist/amo/account.js +48 -0
- package/dist/amo/account.js.map +1 -0
- package/dist/amo/allow-list.d.ts +31 -0
- package/dist/amo/allow-list.d.ts.map +1 -0
- package/dist/amo/allow-list.js +106 -0
- package/dist/amo/allow-list.js.map +1 -0
- package/dist/amo/errors.d.ts +12 -0
- package/dist/amo/errors.d.ts.map +1 -0
- package/dist/amo/errors.js +72 -0
- package/dist/amo/errors.js.map +1 -0
- package/dist/amo/json.d.ts +3 -0
- package/dist/amo/json.d.ts.map +1 -0
- package/dist/amo/json.js +3 -0
- package/dist/amo/json.js.map +1 -0
- package/dist/amo/oauth.d.ts +55 -0
- package/dist/amo/oauth.d.ts.map +1 -0
- package/dist/amo/oauth.js +189 -0
- package/dist/amo/oauth.js.map +1 -0
- package/dist/amo/operation.d.ts +45 -0
- package/dist/amo/operation.d.ts.map +1 -0
- package/dist/amo/operation.js +119 -0
- package/dist/amo/operation.js.map +1 -0
- package/dist/amo/operations.d.ts +3 -0
- package/dist/amo/operations.d.ts.map +1 -0
- package/dist/amo/operations.js +1407 -0
- package/dist/amo/operations.js.map +1 -0
- package/dist/amo/routes.d.ts +67 -0
- package/dist/amo/routes.d.ts.map +1 -0
- package/dist/amo/routes.js +65 -0
- package/dist/amo/routes.js.map +1 -0
- package/dist/amo/transport.d.ts +62 -0
- package/dist/amo/transport.d.ts.map +1 -0
- package/dist/amo/transport.js +282 -0
- package/dist/amo/transport.js.map +1 -0
- package/dist/api-keys.d.ts +47 -0
- package/dist/api-keys.d.ts.map +1 -0
- package/dist/api-keys.js +224 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/bin/amo.d.ts +3 -0
- package/dist/bin/amo.d.ts.map +1 -0
- package/dist/bin/amo.js +40 -0
- package/dist/bin/amo.js.map +1 -0
- package/dist/bundle/all-profiles-3KQVWDV4.js +278 -0
- package/dist/bundle/amo.js +198 -0
- package/dist/bundle/anthropic-N5NOX7K7.js +90 -0
- package/dist/bundle/app-server-2MST5EZ5.js +245 -0
- package/dist/bundle/bun-4NHWOFX2.js +169 -0
- package/dist/bundle/bun-sqlite-DRSXPWPR.js +75 -0
- package/dist/bundle/chunk-2B24PDH7.js +1718 -0
- package/dist/bundle/chunk-2I5UVMLW.js +3232 -0
- package/dist/bundle/chunk-3IRJDH2U.js +731 -0
- package/dist/bundle/chunk-4ZAK773N.js +100 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5D4Z2B5B.js +334 -0
- package/dist/bundle/chunk-5E5R65CA.js +54 -0
- package/dist/bundle/chunk-5HGGG3QO.js +73 -0
- package/dist/bundle/chunk-5RLUHTK6.js +23 -0
- package/dist/bundle/chunk-5SBLU7D7.js +63 -0
- package/dist/bundle/chunk-5Z5PEEKP.js +206 -0
- package/dist/bundle/chunk-63F65DHU.js +29 -0
- package/dist/bundle/chunk-6RS7OYTD.js +64 -0
- package/dist/bundle/chunk-73CXFE36.js +88 -0
- package/dist/bundle/chunk-7GTUZY7M.js +170 -0
- package/dist/bundle/chunk-7PKFYX7V.js +189 -0
- package/dist/bundle/chunk-7U5HJEPZ.js +1400 -0
- package/dist/bundle/chunk-A33TIM5D.js +4172 -0
- package/dist/bundle/chunk-ADEWU4P4.js +38 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-AHJ4W2IL.js +106 -0
- package/dist/bundle/chunk-AUBB72VF.js +2572 -0
- package/dist/bundle/chunk-BVMNXI53.js +1266 -0
- package/dist/bundle/chunk-CDY2NJFE.js +136 -0
- package/dist/bundle/chunk-CHUKWON6.js +244 -0
- package/dist/bundle/chunk-CUZRHF34.js +230 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DAY6TSPF.js +786 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DJD7TBYG.js +2791 -0
- package/dist/bundle/chunk-DOSJONCX.js +1197 -0
- package/dist/bundle/chunk-DQV2IKCF.js +72 -0
- package/dist/bundle/chunk-DXGGCGRP.js +218 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EPOV5UIO.js +185 -0
- package/dist/bundle/chunk-EQ7A6NA6.js +53 -0
- package/dist/bundle/chunk-EQUKVVHX.js +353 -0
- package/dist/bundle/chunk-EROSAUNP.js +133 -0
- package/dist/bundle/chunk-ESZSMZKT.js +82 -0
- package/dist/bundle/chunk-FKR3M62D.js +407 -0
- package/dist/bundle/chunk-GNTJMB6X.js +142 -0
- package/dist/bundle/chunk-GQ7VFIYM.js +316 -0
- package/dist/bundle/chunk-JH3UOHRE.js +161 -0
- package/dist/bundle/chunk-JMDLPBXK.js +1068 -0
- package/dist/bundle/chunk-JR6TSMFX.js +9435 -0
- package/dist/bundle/chunk-L6AFE73L.js +18 -0
- package/dist/bundle/chunk-LDEBZ3IX.js +238 -0
- package/dist/bundle/chunk-LGQXGOPJ.js +58 -0
- package/dist/bundle/chunk-LJQUYECN.js +6848 -0
- package/dist/bundle/chunk-LRBPT7LQ.js +95 -0
- package/dist/bundle/chunk-LSND5QYI.js +460 -0
- package/dist/bundle/chunk-NC76INB2.js +27955 -0
- package/dist/bundle/chunk-NHXJYS4R.js +1334 -0
- package/dist/bundle/chunk-NJYAL3UW.js +92 -0
- package/dist/bundle/chunk-O2UCU52O.js +4065 -0
- package/dist/bundle/chunk-ODNQU7DH.js +1028 -0
- package/dist/bundle/chunk-P3WQRTYZ.js +24 -0
- package/dist/bundle/chunk-P5LYZRKW.js +63373 -0
- package/dist/bundle/chunk-PFO76YFP.js +2003 -0
- package/dist/bundle/chunk-PM77PRB6.js +12269 -0
- package/dist/bundle/chunk-Q2VNBY4Y.js +38109 -0
- package/dist/bundle/chunk-QDMXZZG4.js +604 -0
- package/dist/bundle/chunk-QRQYUHCZ.js +761 -0
- package/dist/bundle/chunk-RPWAJYI6.js +2336 -0
- package/dist/bundle/chunk-SMSTGO2G.js +58 -0
- package/dist/bundle/chunk-SZ2V62HB.js +72 -0
- package/dist/bundle/chunk-T2UDLX76.js +259 -0
- package/dist/bundle/chunk-TGEQNS6G.js +16 -0
- package/dist/bundle/chunk-TNUFLULO.js +2333 -0
- package/dist/bundle/chunk-TZSUZGWM.js +25 -0
- package/dist/bundle/chunk-U7RLVJ34.js +274 -0
- package/dist/bundle/chunk-UBRREVLJ.js +72 -0
- package/dist/bundle/chunk-ULXQ5MJM.js +76 -0
- package/dist/bundle/chunk-UMVRT7VQ.js +46 -0
- package/dist/bundle/chunk-V77XNPXG.js +360 -0
- package/dist/bundle/chunk-VVHRQ46X.js +193 -0
- package/dist/bundle/chunk-VX37MPTJ.js +7 -0
- package/dist/bundle/chunk-WCYCUTSK.js +362 -0
- package/dist/bundle/chunk-XEFAMLSD.js +288 -0
- package/dist/bundle/chunk-XQL7FEF4.js +721 -0
- package/dist/bundle/chunk-XRTD2GCU.js +627 -0
- package/dist/bundle/chunk-Y37A3232.js +804 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-ZM7I52EP.js +78 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/cli-QVWTXADI.js +1193 -0
- package/dist/bundle/command-contract-QBUQBXH7.js +39 -0
- package/dist/bundle/command-server-entry-5VL5U5EE.js +168 -0
- package/dist/bundle/decode-SQ5WGNDX.js +296 -0
- package/dist/bundle/dispatch-LA4DFXJD.js +411 -0
- package/dist/bundle/dist-T54K3FJV.js +7577 -0
- package/dist/bundle/echarts-25Z3RINX.js +42501 -0
- package/dist/bundle/embed-BNOTNXMA.js +37 -0
- package/dist/bundle/embedder-BCUT7KKV.js +110 -0
- package/dist/bundle/failure-PKAC6XCT.js +24 -0
- package/dist/bundle/first-run-EO5K5GME.js +28 -0
- package/dist/bundle/first-screen-GMN3T6RW.js +39 -0
- package/dist/bundle/instructions-VLM3QAYB.js +11 -0
- package/dist/bundle/mcp-7ILNMJH5.js +167 -0
- package/dist/bundle/meeting-combined-LAMF7S2B.js +24 -0
- package/dist/bundle/meeting-model-GHMMUQ34.js +24 -0
- package/dist/bundle/meeting-semantic-BMP6323L.js +21 -0
- package/dist/bundle/node-CT3N3TNL.js +176 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-MELD2SBX.js +73 -0
- package/dist/bundle/oauth-YBH5OKC2.js +19 -0
- package/dist/bundle/open-WNSBWTAG.js +22 -0
- package/dist/bundle/openai-XSNMNLW6.js +237 -0
- package/dist/bundle/process-I2QKOMM7.js +91 -0
- package/dist/bundle/program-DV73CIGP.js +4940 -0
- package/dist/bundle/prompt-SOG4AKPM.js +16 -0
- package/dist/bundle/recognize-WMQLWMXH.js +25 -0
- package/dist/bundle/remote-4BTFOLFY.js +30 -0
- package/dist/bundle/rerank-LJ3TWRNV.js +51 -0
- package/dist/bundle/serve-B6UANKXN.js +198 -0
- package/dist/bundle/server-S6XD6V6E.js +77 -0
- package/dist/bundle/server-YRH6GJ5Z.js +206 -0
- package/dist/bundle/source-DGFTA2TN.js +42 -0
- package/dist/bundle/sqlite-runtime-R7QFWFE7.js +19 -0
- package/dist/bundle/state-DIJ5YUOE.js +35 -0
- package/dist/bundle/store-6WFWW7EC.js +294 -0
- package/dist/bundle/store-FJCNZULV.js +32 -0
- package/dist/bundle/store-MYTYDV6A.js +177 -0
- package/dist/bundle/store-maintenance-command-B5TMKFMG.js +68 -0
- package/dist/bundle/writer-GP7VIMAU.js +44 -0
- package/dist/commands/account.d.ts +3 -0
- package/dist/commands/account.d.ts.map +1 -0
- package/dist/commands/account.js +86 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +224 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/crm-shared.d.ts +8 -0
- package/dist/commands/crm-shared.d.ts.map +1 -0
- package/dist/commands/crm-shared.js +111 -0
- package/dist/commands/crm-shared.js.map +1 -0
- package/dist/commands/schedule.d.ts +3 -0
- package/dist/commands/schedule.d.ts.map +1 -0
- package/dist/commands/schedule.js +9 -0
- package/dist/commands/schedule.js.map +1 -0
- package/dist/commands/session.d.ts +18 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +265 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/write.d.ts +14 -0
- package/dist/commands/write.d.ts.map +1 -0
- package/dist/commands/write.js +36 -0
- package/dist/commands/write.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +29 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +62 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +97 -0
- package/dist/context.js.map +1 -0
- package/dist/crm/activities.d.ts +32 -0
- package/dist/crm/activities.d.ts.map +1 -0
- package/dist/crm/activities.js +196 -0
- package/dist/crm/activities.js.map +1 -0
- package/dist/crm/records.d.ts +20 -0
- package/dist/crm/records.d.ts.map +1 -0
- package/dist/crm/records.js +175 -0
- package/dist/crm/records.js.map +1 -0
- package/dist/crm/source.d.ts +41 -0
- package/dist/crm/source.d.ts.map +1 -0
- package/dist/crm/source.js +673 -0
- package/dist/crm/source.js.map +1 -0
- package/dist/crm/writer.d.ts +14 -0
- package/dist/crm/writer.d.ts.map +1 -0
- package/dist/crm/writer.js +247 -0
- package/dist/crm/writer.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +33 -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/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +91 -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 +35 -0
- package/dist/reasons.js.map +1 -0
- package/dist/setup/flow.d.ts +2 -0
- package/dist/setup/flow.d.ts.map +1 -0
- package/dist/setup/flow.js +127 -0
- package/dist/setup/flow.js.map +1 -0
- package/dist/setup/texts.en.json +25 -0
- package/dist/setup/texts.es.json +25 -0
- package/dist/setup/texts.ru.json +25 -0
- package/dist/store.d.ts +15 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +16 -0
- package/dist/store.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/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/dist/whoami.d.ts +24 -0
- package/dist/whoami.d.ts.map +1 -0
- package/dist/whoami.js +33 -0
- package/dist/whoami.js.map +1 -0
- package/package.json +85 -4
- package/skills/amo-cli/SKILL.md +116 -0
- package/skills/amo-cli/references/mcp.md +38 -0
- package/skills/amo-cli/references/output.md +42 -0
- package/skills/amo-cli/references/reading.md +77 -0
- package/skills/amo-cli/references/setup.md +59 -0
- package/skills/amo-cli/references/writing.md +86 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { readSecret } from "@wirecat/cli-core";
|
|
4
|
+
import { commandWords, environmentOf, FETCH, itemOf, LOCAL_READ, LOCAL_WRITE, listOf, logsInOrOut, openBrowser, outputFor, ProfileTokenStore, profileFree, profilesHere, REMOTE_READ, refuseCommandName, refuseOffline, refuseUnderReadOnly, rememberAccount, renderAnswer, rootOf, secretInputOf, signInSteps, } from "@wirecat/cli-core/cli";
|
|
5
|
+
import { Command } from "commander";
|
|
6
|
+
import { accountOrigin, decodeSignIn, encodeSignIn } from "../amo/account.js";
|
|
7
|
+
import { appSignIn, appSourceOf, appStorage, RELAY_URL } from "../amo/oauth.js";
|
|
8
|
+
import { configuration } from "../config.js";
|
|
9
|
+
import { appAuthFor, contextOf, storedSignIn, transportFor, withAccount, withoutKeyring, } from "../context.js";
|
|
10
|
+
import { IDENTITY } from "../identity.js";
|
|
11
|
+
import { accountUser } from "../whoami.js";
|
|
12
|
+
const AMO = IDENTITY.command;
|
|
13
|
+
const answer = (command, item) => renderAnswer(command, outputFor(command), itemOf(item));
|
|
14
|
+
const storageOf = (raw) => {
|
|
15
|
+
if (raw === "keyring" || raw === "file")
|
|
16
|
+
return raw;
|
|
17
|
+
throw new CliError("validation_error", `--credential-storage takes keyring or file; got ${raw}`);
|
|
18
|
+
};
|
|
19
|
+
const tokensHere = (env, keyring) => new ProfileTokenStore({ app: IDENTITY, env, ...(keyring ? { keyring } : {}) });
|
|
20
|
+
/** The account host and user a profile's saved sign-in reaches, either kind; one from `AMO_TOKEN` is no profile's. */
|
|
21
|
+
export const signedInAs = (env, keyring, profile) => {
|
|
22
|
+
const app = withoutKeyring(() => appStorage(env, profile, keyring).read()?.account, () => tokensHere(env, keyring).read(profile));
|
|
23
|
+
if (app)
|
|
24
|
+
return { host: new URL(app.host).host, userId: app.userId };
|
|
25
|
+
const saved = tokensHere(env, keyring).read(profile);
|
|
26
|
+
if (!saved || saved.source === "environment")
|
|
27
|
+
return undefined;
|
|
28
|
+
const signIn = decodeSignIn(saved.secret);
|
|
29
|
+
return { host: new URL(signIn.origin).host, userId: signIn.userId };
|
|
30
|
+
};
|
|
31
|
+
/** A second profile on the same account and user would sync the same copy twice and split its permissions. */
|
|
32
|
+
const refuseDuplicate = (env, keyring, profile, at) => {
|
|
33
|
+
// biome-ignore lint/plugin/no-own-settings: this check reads every profile, and baseContext names one
|
|
34
|
+
const { configuredProfiles } = configuration.resolveSettings({}, { env, needsProfile: false });
|
|
35
|
+
const other = profilesHere(IDENTITY, configuredProfiles, env).find((one) => {
|
|
36
|
+
if (one === profile)
|
|
37
|
+
return false;
|
|
38
|
+
try {
|
|
39
|
+
const found = signedInAs(env, keyring, one);
|
|
40
|
+
return found?.host === at.host && found.userId === at.userId;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (!other)
|
|
47
|
+
return;
|
|
48
|
+
throw new CliError("conflict", `profile ${other} already signs in to ${at.host} as user ${at.userId}. Use \`${AMO} ${other}\`, sign it in ` +
|
|
49
|
+
`again with \`${AMO} ${other} session start\`, or end it with \`${AMO} ${other} session end\` first`, { reason: "session.duplicate", profile: other, account: at.host });
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A long-lived token proven against its account, and what a profile keeps for it: the sign-in with the address and
|
|
53
|
+
* the token's user, and the account as `session start` remembers it. `setup apply` runs the same check.
|
|
54
|
+
*/
|
|
55
|
+
export const checkedToken = async (command, origin, token) => {
|
|
56
|
+
const { env, profile, keyring, run } = contextOf(command);
|
|
57
|
+
const who = await run((events) => accountUser(transportFor(command, { origin, token }, events)));
|
|
58
|
+
refuseDuplicate(env, keyring, profile, { host: who.account, userId: who.user.id });
|
|
59
|
+
return {
|
|
60
|
+
who,
|
|
61
|
+
signIn: encodeSignIn({ origin, token, userId: who.user.id }),
|
|
62
|
+
account: `${who.account}:${who.user.id}`,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/** The setup flow shows and checks the address from this setting, so both ways of signing in keep it. */
|
|
66
|
+
const keepHost = (command, origin) => {
|
|
67
|
+
const { profile, settings } = contextOf(command);
|
|
68
|
+
configuration.changeSetting(settings.configPath, { profile, setting: "host", value: JSON.stringify(origin) });
|
|
69
|
+
};
|
|
70
|
+
const PASTE = "If the browser did not come back here, paste the address it ended on: ";
|
|
71
|
+
/** The owner's own integration in the browser; its secret is never a flag (WC-SECR-5). */
|
|
72
|
+
const startWithApp = async (command, args, origin) => {
|
|
73
|
+
const { env, profile, tokens, keyring, run, environment } = contextOf(command);
|
|
74
|
+
const clientId = (args.clientId ?? env[CLIENT_ID] ?? "").trim();
|
|
75
|
+
const clientSecret = env[CLIENT_SECRET]?.trim() || (await readSecret("amoCRM integration secret key: ", secretInputOf(command))).trim();
|
|
76
|
+
if (!clientSecret)
|
|
77
|
+
throw new CliError("validation_error", "no secret key was given");
|
|
78
|
+
const flags = command.optsWithGlobals();
|
|
79
|
+
const machine = flags.json === true || flags.jsonl === true;
|
|
80
|
+
const person = !machine && flags.input !== false && !env.CI && (environment.tty ?? process.stdout.isTTY) === true;
|
|
81
|
+
const { streams } = outputFor(command);
|
|
82
|
+
const steps = signInSteps({
|
|
83
|
+
diagnostic: (line) => streams.diagnostic(`${line}\n`),
|
|
84
|
+
json: machine || environment.tty === false,
|
|
85
|
+
answers: false,
|
|
86
|
+
});
|
|
87
|
+
const input = secretInputOf(command).input ?? process.stdin;
|
|
88
|
+
const given = environment.answer;
|
|
89
|
+
const signInCommand = `${AMO} ${profile} session start --host ${origin} --client-id ${clientId}`;
|
|
90
|
+
const who = await run((events) => appSignIn({
|
|
91
|
+
env,
|
|
92
|
+
profile,
|
|
93
|
+
origin,
|
|
94
|
+
client: { clientId, clientSecret },
|
|
95
|
+
storage: args.credentialStorage,
|
|
96
|
+
keyring,
|
|
97
|
+
fetch: environment.fetch,
|
|
98
|
+
signal: environment.signal,
|
|
99
|
+
signInCommand,
|
|
100
|
+
steps: {
|
|
101
|
+
openBrowser: async (url) => {
|
|
102
|
+
if (environment.openBrowser)
|
|
103
|
+
return environment.openBrowser(url);
|
|
104
|
+
if (person)
|
|
105
|
+
await openBrowser(url);
|
|
106
|
+
},
|
|
107
|
+
showUrl: (url) => {
|
|
108
|
+
steps.openUrl(url, "Sign in to amoCRM and allow the integration");
|
|
109
|
+
streams.diagnostic(`Open the amoCRM sign-in: ${url}\n`);
|
|
110
|
+
},
|
|
111
|
+
// A pipe was the secret, and an empty answer would end the sign-in before the browser came back.
|
|
112
|
+
...(given
|
|
113
|
+
? {
|
|
114
|
+
readPaste: async () => {
|
|
115
|
+
const text = await given(PASTE);
|
|
116
|
+
if (text === null)
|
|
117
|
+
throw new CliError("cancelled", "nobody is at a terminal to paste");
|
|
118
|
+
return text;
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
: input.isTTY && !machine
|
|
122
|
+
? {
|
|
123
|
+
readPaste: (signal) => readSecret(PASTE, { ...secretInputOf(command), echo: true, signal }),
|
|
124
|
+
}
|
|
125
|
+
: {}),
|
|
126
|
+
},
|
|
127
|
+
check: async (auth) => {
|
|
128
|
+
const found = await accountUser(transportFor(command, auth, events));
|
|
129
|
+
refuseDuplicate(env, keyring, profile, { host: found.account, userId: found.user.id });
|
|
130
|
+
return { ...found, id: found.user.id };
|
|
131
|
+
},
|
|
132
|
+
}));
|
|
133
|
+
tokens.remove(profile);
|
|
134
|
+
keepHost(command, origin);
|
|
135
|
+
rememberAccount(IDENTITY, profile, `${who.account}:${who.user.id}`, env);
|
|
136
|
+
const { id: _id, ...found } = who;
|
|
137
|
+
return {
|
|
138
|
+
profile,
|
|
139
|
+
state: "saved",
|
|
140
|
+
kind: "app",
|
|
141
|
+
stored_in: appSourceOf(env, profile, keyring) ?? args.credentialStorage,
|
|
142
|
+
verified: true,
|
|
143
|
+
...found,
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
const CLIENT_ID = `${IDENTITY.envPrefix}_AMOCRM_CLIENT_ID`;
|
|
147
|
+
const CLIENT_SECRET = `${IDENTITY.envPrefix}_AMOCRM_CLIENT_SECRET`;
|
|
148
|
+
const startCommand = () => logsInOrOut(annotate(new Command("start"), {
|
|
149
|
+
effects: FETCH,
|
|
150
|
+
lifetime: "interactive",
|
|
151
|
+
mcp: false,
|
|
152
|
+
examples: [
|
|
153
|
+
`${AMO} work session start --host https://example.amocrm.ru`,
|
|
154
|
+
`${AMO} work session start --host https://example.kommo.com --json`,
|
|
155
|
+
`${AMO} work session start --host https://example.amocrm.ru --client-id 0123abcd-4567-89ef-0123-456789abcdef`,
|
|
156
|
+
],
|
|
157
|
+
}))
|
|
158
|
+
.summary("sign in to amoCRM or Kommo with a long-lived token or your own integration")
|
|
159
|
+
.description("sign this profile in: --host names the account, and its long-lived token (a private integration → Keys and " +
|
|
160
|
+
"scopes → Generate a long-lived token) is asked hidden or read from stdin, never taken as an argument, " +
|
|
161
|
+
"checked against the account, and only then kept in the keyring with the address, or in a private file. " +
|
|
162
|
+
"The token acts with the rights of the administrator who made it. With --client-id it signs in through " +
|
|
163
|
+
"that integration in the browser instead: its secret key is asked hidden or read from stdin, and the tokens " +
|
|
164
|
+
`act with the rights of the user who signs in; the integration's Redirect URI must be ${RELAY_URL}. ` +
|
|
165
|
+
"Each sign-in forgets the profile's other kind")
|
|
166
|
+
.requiredOption("--host <address>", "the account's address, such as https://example.amocrm.ru, kept as given")
|
|
167
|
+
.option("--client-id <id>", `the integration's ID (client_id), or ${CLIENT_ID}; its secret key comes from ${CLIENT_SECRET}, a hidden ` +
|
|
168
|
+
"prompt or stdin")
|
|
169
|
+
.option("--credential-storage <storage>", "where the sign-in is kept: keyring, which falls back to a private file by itself, or file", storageOf, "keyring")
|
|
170
|
+
.action(async function (args) {
|
|
171
|
+
const { env, profile, tokens, keyring } = contextOf(this);
|
|
172
|
+
refuseCommandName(profile, commandWords(rootOf(this)), AMO);
|
|
173
|
+
refuseOffline(this, "the amoCRM account");
|
|
174
|
+
const origin = accountOrigin(args.host);
|
|
175
|
+
if (args.clientId !== undefined || env[CLIENT_ID])
|
|
176
|
+
return answer(this, await startWithApp(this, args, origin));
|
|
177
|
+
// A secret is never an argument: it would land in shell history and in the run record (WC-SECR-5).
|
|
178
|
+
const token = (await readSecret("amoCRM long-lived token: ", secretInputOf(this))).trim();
|
|
179
|
+
if (!token)
|
|
180
|
+
throw new CliError("validation_error", "no token was given");
|
|
181
|
+
const { who, signIn, account } = await checkedToken(this, origin, token);
|
|
182
|
+
const storedIn = tokens.write(profile, signIn, args.credentialStorage);
|
|
183
|
+
keepHost(this, origin);
|
|
184
|
+
appStorage(env, profile, keyring).remove();
|
|
185
|
+
rememberAccount(IDENTITY, profile, account, env);
|
|
186
|
+
answer(this, { profile, state: "saved", kind: "token", stored_in: storedIn, verified: true, ...who });
|
|
187
|
+
});
|
|
188
|
+
const statusCommand = () => annotate(new Command("status"), {
|
|
189
|
+
effects: REMOTE_READ,
|
|
190
|
+
examples: [`${AMO} work session status`, `${AMO} work session status --check --json`],
|
|
191
|
+
})
|
|
192
|
+
.summary("show how this profile signs in, and with --check as whom it acts")
|
|
193
|
+
.description("show which account this profile signs in to, with a long-lived token or an integration, and where that " +
|
|
194
|
+
`comes from: ${IDENTITY.envPrefix}_TOKEN, the keyring or a file; never a token or the secret key`)
|
|
195
|
+
.option("--check", "ask the account whether the sign-in still works and whose it is: the account, the user and admin")
|
|
196
|
+
.action(async function (args) {
|
|
197
|
+
const { env, profile, tokens, keyring } = contextOf(this);
|
|
198
|
+
const saved = tokens.read(profile);
|
|
199
|
+
const app = saved?.source === "environment" ? undefined : appAuthFor(this);
|
|
200
|
+
const signIn = storedSignIn(this);
|
|
201
|
+
const status = {
|
|
202
|
+
profile,
|
|
203
|
+
state: signIn ? "saved" : "missing",
|
|
204
|
+
kind: app ? "app" : signIn ? "token" : null,
|
|
205
|
+
token_from: app ? (appSourceOf(env, profile, keyring) ?? null) : (saved?.source ?? null),
|
|
206
|
+
account: signIn ? new URL(signIn.origin).host : null,
|
|
207
|
+
};
|
|
208
|
+
if (!args.check || !signIn)
|
|
209
|
+
return answer(this, { ...status, verified: false });
|
|
210
|
+
answer(this, { ...status, verified: true, ...(await withAccount(this, accountUser)) });
|
|
211
|
+
});
|
|
212
|
+
const endCommand = () => logsInOrOut(annotate(new Command("end"), {
|
|
213
|
+
effects: LOCAL_WRITE,
|
|
214
|
+
mcp: false,
|
|
215
|
+
examples: [`${AMO} work session end`],
|
|
216
|
+
}))
|
|
217
|
+
.summary("forget this profile's sign-in on this computer")
|
|
218
|
+
.description("forget this profile's long-lived token, or its integration's secret key and tokens, and the account address " +
|
|
219
|
+
"on this computer; amoCRM has no call that revokes a token: revoke it on the integration's Keys and scopes " +
|
|
220
|
+
"tab, or switch the integration off")
|
|
221
|
+
.action(function () {
|
|
222
|
+
refuseUnderReadOnly(this, "session end");
|
|
223
|
+
const { env, profile, tokens, keyring } = contextOf(this);
|
|
224
|
+
const ended = [...tokens.remove(profile), ...appStorage(env, profile, keyring).remove()];
|
|
225
|
+
answer(this, { profile, ended: [...new Set(ended)] });
|
|
226
|
+
});
|
|
227
|
+
const listCommand = () => profileFree(annotate(new Command("list"), {
|
|
228
|
+
effects: LOCAL_READ,
|
|
229
|
+
examples: [`${AMO} session list`, `${AMO} session list --json`],
|
|
230
|
+
}))
|
|
231
|
+
.summary("list the profiles here and whether each is signed in")
|
|
232
|
+
.description("list the profiles on this computer, whether each has a token and for which account; picks none")
|
|
233
|
+
.action(function () {
|
|
234
|
+
const environment = environmentOf(this);
|
|
235
|
+
const env = environment.env ?? process.env;
|
|
236
|
+
// biome-ignore lint/plugin/no-own-settings: baseContext needs a profile, and this local read names none
|
|
237
|
+
const { configuredProfiles } = configuration.resolveSettings({}, { env, needsProfile: false });
|
|
238
|
+
const tokens = tokensHere(env, environment.keyring);
|
|
239
|
+
const items = profilesHere(IDENTITY, configuredProfiles, env).map((profile) => {
|
|
240
|
+
try {
|
|
241
|
+
const saved = tokens.read(profile);
|
|
242
|
+
const app = saved ? undefined : appStorage(env, profile, environment.keyring).read()?.account;
|
|
243
|
+
const host = app
|
|
244
|
+
? new URL(app.host).host
|
|
245
|
+
: saved && saved.source !== "environment"
|
|
246
|
+
? new URL(decodeSignIn(saved.secret).origin).host
|
|
247
|
+
: null;
|
|
248
|
+
const from = saved?.source ?? (app ? appSourceOf(env, profile, environment.keyring) : undefined);
|
|
249
|
+
return { profile, signed_in: from !== undefined, token_from: from ?? null, account: host };
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (!(error instanceof CliError))
|
|
253
|
+
throw error;
|
|
254
|
+
return { profile, signed_in: null, token_from: null, account: null, error: error.message };
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
renderAnswer(this, outputFor(this), listOf("session list", { items, limit: Math.max(1, items.length), has_more: false }));
|
|
258
|
+
});
|
|
259
|
+
export const sessionCommand = () => annotate(new Command("session"), { effects: LOCAL_READ })
|
|
260
|
+
.description("keep this profile's amoCRM sign-in and account address in the OS keyring")
|
|
261
|
+
.addCommand(startCommand())
|
|
262
|
+
.addCommand(statusCommand())
|
|
263
|
+
.addCommand(endCommand())
|
|
264
|
+
.addCommand(listCommand());
|
|
265
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/commands/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,KAAK,EAEL,MAAM,EACN,UAAU,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,MAAM,EACN,aAAa,EACb,WAAW,GAEZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,YAAY,EA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AAE,CAAC;KACtD,WAAW,CAAC,0EAA0E,CAAC;KACvF,UAAU,CAAC,YAAY,EAAE,CAAC;KAC1B,UAAU,CAAC,aAAa,EAAE,CAAC;KAC3B,UAAU,CAAC,UAAU,EAAE,CAAC;KACxB,UAAU,CAAC,WAAW,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { AmoTransport } from "../amo/transport.js";
|
|
3
|
+
export interface Write {
|
|
4
|
+
key: string;
|
|
5
|
+
/** Keys checked beside `key`, such as the command key a raw `api call` does the same as. */
|
|
6
|
+
extra?: readonly string[];
|
|
7
|
+
act: (account: AmoTransport, operationId: string) => Promise<Record<string, unknown>>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Every write's one path, as b24's and gcal-cli's: the read-only lock, the profile's levels, one question for every
|
|
11
|
+
* key at `ask`, the send journal, and an `operation_id` in the answer (WC-PERM-13, WC-OUT-10).
|
|
12
|
+
*/
|
|
13
|
+
export declare const write: (command: Command, { key, extra, act }: Write) => Promise<void>;
|
|
14
|
+
//# sourceMappingURL=write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/commands/write.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAKvD,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,4FAA4F;IAC5F,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACzB,GAAG,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACtF;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAmB,OAAO,uBAA4B,KAAK,kBAuC5E,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { environmentOf, itemOf, outputFor, readOnlyLockOf, readOnlyRefusal, renderAnswer, terminalAsker, } from "@wirecat/cli-core/cli";
|
|
3
|
+
import { guardedWrite, guardFor, keyedGuard, levelFor, newOperationId } from "@wirecat/cli-core/sends";
|
|
4
|
+
import { permissions } from "../config.js";
|
|
5
|
+
import { contextOf, signInOf, transportFor } from "../context.js";
|
|
6
|
+
import { IDENTITY } from "../identity.js";
|
|
7
|
+
/**
|
|
8
|
+
* Every write's one path, as b24's and gcal-cli's: the read-only lock, the profile's levels, one question for every
|
|
9
|
+
* key at `ask`, the send journal, and an `operation_id` in the answer (WC-PERM-13, WC-OUT-10).
|
|
10
|
+
*/
|
|
11
|
+
export const write = async (command, { key, extra = [], act }) => {
|
|
12
|
+
const defaults = permissions.defaults;
|
|
13
|
+
const { env, settings, run } = contextOf(command);
|
|
14
|
+
const lock = readOnlyLockOf(IDENTITY, env);
|
|
15
|
+
if (lock)
|
|
16
|
+
throw readOnlyRefusal(lock, "change the amoCRM account");
|
|
17
|
+
const operationId = newOperationId();
|
|
18
|
+
const levelOf = (one) => levelFor(settings.permissions, one, defaults).level;
|
|
19
|
+
const guard = keyedGuard((ask) => guardFor(IDENTITY,
|
|
20
|
+
// amoCRM limits its own rate; the guard is here for the levels and the journal, not a send limit.
|
|
21
|
+
{ ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, outputFor(command).renderer.warn, environmentOf(command).env ?? process.env, ask), terminalAsker(command), levelOf, extra);
|
|
22
|
+
const request = { chatId: null, kind: "edit", key, operationId };
|
|
23
|
+
guard.refuse(request);
|
|
24
|
+
const signIn = signInOf(command);
|
|
25
|
+
let done;
|
|
26
|
+
try {
|
|
27
|
+
done = await guardedWrite(guard, request, () => run((events) => act(transportFor(command, signIn, events), operationId)));
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof CliError && error.code === "outcome_unknown")
|
|
31
|
+
throw new CliError("outcome_unknown", `${error.message} — check the account before you write it again: amoCRM has no idempotency key and would make it a second time`, { ...error.details, operation_id: operationId });
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
renderAnswer(command, outputFor(command), itemOf({ operation_id: operationId, ...done }));
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../src/commands/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EACL,aAAa,EACb,MAAM,EACN,SAAS,EACT,cAAc,EACd,eAAe,EACf,YAAY,EACZ,aAAa,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGtG,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AASzC;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAAE,OAAgB,EAAE,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,GAAG,EAAS,EAAE,EAAE;IAC/E,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAA;IACrC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IACjD,MAAM,IAAI,GAAG,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;IAC1C,IAAI,IAAI;QAAE,MAAM,eAAe,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B,EACjB,GAAG,KAAK,CAAC,OAAO,+GAA+G,EAC/H,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,CAChD,CAAA;QACH,MAAM,KAAK,CAAA;IACb,CAAC;IACD,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;AAC3F,CAAC,CAAA"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAA0D,MAAM,uBAAuB,CAAA;AAWlH,eAAO,MAAM,WAAW,oDAKtB,CAAA;AAsBF,eAAO,MAAM,aAAa,EAAE,aAAgF,CAAA"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { commandPathKey, commandPermissions, plain, settingsFor } from "@wirecat/cli-core/cli";
|
|
2
|
+
import { CRM_WRITE_DEFAULTS, CRM_WRITE_KEYS, crmAlsoChecks } from "@wirecat/cli-core/crm";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
import { accountOrigin } from "./amo/account.js";
|
|
5
|
+
import { API_DEFAULTS, API_KEYS, crmApiKeys } from "./api-keys.js";
|
|
6
|
+
import { IDENTITY } from "./identity.js";
|
|
7
|
+
/** `api list` and `show` never reach the account; `api call` names its operation only in its arguments and checks it. */
|
|
8
|
+
const keyOf = (path) => path[0] === "api" && ["call", "list", "show"].includes(path[1] ?? "") ? null : commandPathKey(path);
|
|
9
|
+
export const permissions = commandPermissions({
|
|
10
|
+
keyOf,
|
|
11
|
+
alsoChecks: crmAlsoChecks(crmApiKeys),
|
|
12
|
+
extra: [...new Set([...CRM_WRITE_KEYS, ...API_KEYS])],
|
|
13
|
+
defaults: { ...CRM_WRITE_DEFAULTS, ...API_DEFAULTS },
|
|
14
|
+
});
|
|
15
|
+
const isAccount = (text) => {
|
|
16
|
+
try {
|
|
17
|
+
accountOrigin(text);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** The account the setup flow asks for; a sign-in keeps its own copy of the address, which requests use. */
|
|
25
|
+
const PROFILE_ENTRIES = {
|
|
26
|
+
host: v.optional(v.pipe(v.string(plain("has to be the account's address, in quotes")), v.trim(), v.check(isAccount, "has to be https://<subdomain>.amocrm.ru or https://<subdomain>.kommo.com"))),
|
|
27
|
+
};
|
|
28
|
+
export const configuration = settingsFor(IDENTITY, { permissions, profile: PROFILE_ENTRIES });
|
|
29
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,cAAc,EAAE,kBAAkB,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAClH,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACzF,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,yHAAyH;AACzH,MAAM,KAAK,GAAG,CAAC,IAAuB,EAAE,EAAE,CACxC,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;AAErG,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;IAC5C,KAAK;IACL,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC;IACrC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;IACrD,QAAQ,EAAE,EAAE,GAAG,kBAAkB,EAAE,GAAG,YAAY,EAAE;CACrD,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,EAAE;IACjC,IAAI,CAAC;QACH,aAAa,CAAC,IAAI,CAAC,CAAA;QACnB,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC,CAAA;AAED,4GAA4G;AAC5G,MAAM,eAAe,GAAG;IACtB,IAAI,EAAE,CAAC,CAAC,QAAQ,CACd,CAAC,CAAC,IAAI,CACJ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC,EAC7D,CAAC,CAAC,IAAI,EAAE,EACR,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,0EAA0E,CAAC,CAC/F,CACF;CACF,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAkB,WAAW,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type SleepLike } from "@wirecat/cli-base";
|
|
2
|
+
import type { FetchLike } from "@wirecat/cli-base/http";
|
|
3
|
+
import { type BaseEnvironment, type EventSink, type GlobalFlags, ProfileTokenStore } from "@wirecat/cli-core/cli";
|
|
4
|
+
import type { Command } from "commander";
|
|
5
|
+
import { type AppAuth } from "./amo/oauth.js";
|
|
6
|
+
import { type AmoAuth, AmoTransport } from "./amo/transport.js";
|
|
7
|
+
/** What a test hands `run()` in place of the account and real waiting (WC-ARCH-10). */
|
|
8
|
+
export interface AmoEnvironment extends BaseEnvironment {
|
|
9
|
+
fetch?: FetchLike;
|
|
10
|
+
sleep?: SleepLike;
|
|
11
|
+
/** The clock the pace waits on; a test moves it with its `sleep`, so no wait is real. */
|
|
12
|
+
now?: () => number;
|
|
13
|
+
/** In place of the system browser; a test plays the browser and the relay page. */
|
|
14
|
+
openBrowser?: (url: string) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* amoCRM allows 7 requests a second per integration and 50 per account (amocrm.ru developers "Рекомендации"; Kommo
|
|
18
|
+
* "Limitations" says 7): 5 a second with no burst stays under it in any one-second window.
|
|
19
|
+
*/
|
|
20
|
+
export declare const ACCOUNT_PACE: {
|
|
21
|
+
perMinute: number;
|
|
22
|
+
burst: number;
|
|
23
|
+
};
|
|
24
|
+
export declare const contextOf: (command: Command) => {
|
|
25
|
+
settings: import("@wirecat/cli-core/cli").Settings;
|
|
26
|
+
renderer: import("@wirecat/cli-base").Renderer;
|
|
27
|
+
format: import("@wirecat/cli-base").RenderFormat;
|
|
28
|
+
color: boolean;
|
|
29
|
+
streams: import("@wirecat/cli-base").Streams;
|
|
30
|
+
compact?: boolean;
|
|
31
|
+
full?: boolean;
|
|
32
|
+
env: NodeJS.ProcessEnv;
|
|
33
|
+
keyring?: import("@wirecat/cli-base").KeyringStore;
|
|
34
|
+
run: <T>(body: (events: EventSink) => Promise<T>, options?: {
|
|
35
|
+
unbounded?: boolean;
|
|
36
|
+
name?: string;
|
|
37
|
+
}) => Promise<T>;
|
|
38
|
+
track: (closeable: import("@wirecat/cli-core/cli").Closeable) => void;
|
|
39
|
+
environment: AmoEnvironment;
|
|
40
|
+
flags: GlobalFlags;
|
|
41
|
+
profile: string;
|
|
42
|
+
tokens: ProfileTokenStore;
|
|
43
|
+
};
|
|
44
|
+
export declare const HOST_VARIABLE: string;
|
|
45
|
+
/** The profile's integration sign-in, read with no network. */
|
|
46
|
+
export declare const appAuthFor: (command: Command) => AppAuth | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* The integration's sign-in when the keyring does not answer: none, if the profile's long-lived token is found
|
|
49
|
+
* elsewhere (a file), since each `session start` forgets the other kind; else cli-base's `keyring.unreachable`.
|
|
50
|
+
*/
|
|
51
|
+
export declare const withoutKeyring: <T>(read: () => T | undefined, token: () => unknown) => T | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* `AMO_TOKEN` first, as for every token CLI, with `AMO_HOST` naming its account; then the integration's sign-in, then
|
|
54
|
+
* the saved long-lived token, which keeps the address beside it. One `session start` forgets the other kind.
|
|
55
|
+
*/
|
|
56
|
+
export declare const storedSignIn: (command: Command) => AmoAuth | undefined;
|
|
57
|
+
/** The sign-in a request uses, or the "not signed in" refusal that names the command to sign in. */
|
|
58
|
+
export declare const signInOf: (command: Command) => AmoAuth;
|
|
59
|
+
export declare const transportFor: (command: Command, signIn: AmoAuth, events?: EventSink) => AmoTransport;
|
|
60
|
+
/** The body inside core's run: recorded, under `--timeout`, its requests in the run's events (WC-LIFE-17). */
|
|
61
|
+
export declare const withAccount: <T>(command: Command, body: (account: AmoTransport) => Promise<T>) => Promise<T>;
|
|
62
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,SAAS,EAEd,KAAK,WAAW,EAChB,iBAAiB,EAElB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE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ProfileTokenStore, refuseOffline, } from "@wirecat/cli-core/cli";
|
|
3
|
+
import { Pacer, pacePathFor } from "@wirecat/cli-core/sends";
|
|
4
|
+
import { accountOrigin, decodeSignIn } from "./amo/account.js";
|
|
5
|
+
import { appAuthOf } from "./amo/oauth.js";
|
|
6
|
+
import { AmoTransport } from "./amo/transport.js";
|
|
7
|
+
import { configuration } from "./config.js";
|
|
8
|
+
import { IDENTITY } from "./identity.js";
|
|
9
|
+
/**
|
|
10
|
+
* amoCRM allows 7 requests a second per integration and 50 per account (amocrm.ru developers "Рекомендации"; Kommo
|
|
11
|
+
* "Limitations" says 7): 5 a second with no burst stays under it in any one-second window.
|
|
12
|
+
*/
|
|
13
|
+
export const ACCOUNT_PACE = { perMinute: 300, burst: 1 };
|
|
14
|
+
export const contextOf = (command) => {
|
|
15
|
+
const base = baseContext(command, configuration.resolveSettings);
|
|
16
|
+
return {
|
|
17
|
+
...base,
|
|
18
|
+
environment: environmentOf(command),
|
|
19
|
+
flags: command.optsWithGlobals(),
|
|
20
|
+
profile: base.settings.profile,
|
|
21
|
+
tokens: new ProfileTokenStore({
|
|
22
|
+
app: IDENTITY,
|
|
23
|
+
env: base.env,
|
|
24
|
+
...(base.keyring ? { keyring: base.keyring } : {}),
|
|
25
|
+
warn: base.renderer.warn,
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export const HOST_VARIABLE = `${IDENTITY.envPrefix}_HOST`;
|
|
30
|
+
/** The profile's integration sign-in, read with no network. */
|
|
31
|
+
export const appAuthFor = (command) => {
|
|
32
|
+
const { env, profile, keyring, environment, tokens } = contextOf(command);
|
|
33
|
+
return withoutKeyring(() => appAuthOf({
|
|
34
|
+
env,
|
|
35
|
+
profile,
|
|
36
|
+
keyring,
|
|
37
|
+
...(environment.fetch ? { fetch: environment.fetch } : {}),
|
|
38
|
+
signal: environment.signal,
|
|
39
|
+
}), () => tokens.read(profile));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The integration's sign-in when the keyring does not answer: none, if the profile's long-lived token is found
|
|
43
|
+
* elsewhere (a file), since each `session start` forgets the other kind; else cli-base's `keyring.unreachable`.
|
|
44
|
+
*/
|
|
45
|
+
export const withoutKeyring = (read, token) => {
|
|
46
|
+
try {
|
|
47
|
+
return read();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (isCliError(error) && error.details.reason === "keyring.unreachable" && token() !== undefined)
|
|
51
|
+
return undefined;
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* `AMO_TOKEN` first, as for every token CLI, with `AMO_HOST` naming its account; then the integration's sign-in, then
|
|
57
|
+
* the saved long-lived token, which keeps the address beside it. One `session start` forgets the other kind.
|
|
58
|
+
*/
|
|
59
|
+
export const storedSignIn = (command) => {
|
|
60
|
+
const { env, profile, tokens } = contextOf(command);
|
|
61
|
+
const stored = tokens.read(profile);
|
|
62
|
+
if (stored?.source === "environment") {
|
|
63
|
+
const host = env[HOST_VARIABLE];
|
|
64
|
+
if (!host)
|
|
65
|
+
throw new CliError("configuration_error", `${tokens.variable} needs ${HOST_VARIABLE}, the account's address, such as https://example.amocrm.ru`, { reason: "account.host-missing" });
|
|
66
|
+
return { origin: accountOrigin(host), token: stored.secret };
|
|
67
|
+
}
|
|
68
|
+
return appAuthFor(command) ?? (stored ? decodeSignIn(stored.secret) : undefined);
|
|
69
|
+
};
|
|
70
|
+
/** The sign-in a request uses, or the "not signed in" refusal that names the command to sign in. */
|
|
71
|
+
export const signInOf = (command) => {
|
|
72
|
+
refuseOffline(command, "the amoCRM account");
|
|
73
|
+
const found = storedSignIn(command);
|
|
74
|
+
if (found)
|
|
75
|
+
return found;
|
|
76
|
+
const { profile, tokens } = contextOf(command);
|
|
77
|
+
tokens.need(profile);
|
|
78
|
+
throw new CliError("authentication_error", `profile ${profile} is not signed in`);
|
|
79
|
+
};
|
|
80
|
+
export const transportFor = (command, signIn, events) => {
|
|
81
|
+
const { environment, env, renderer } = contextOf(command);
|
|
82
|
+
return new AmoTransport({
|
|
83
|
+
signIn,
|
|
84
|
+
warn: renderer.warn,
|
|
85
|
+
...(events ? { events } : {}),
|
|
86
|
+
...(environment.fetch ? { fetch: environment.fetch } : {}),
|
|
87
|
+
...(environment.signal ? { signal: environment.signal } : {}),
|
|
88
|
+
...(environment.sleep ? { sleep: environment.sleep } : {}),
|
|
89
|
+
...(environment.deadline ? { deadline: environment.deadline } : {}),
|
|
90
|
+
...(environment.now ? { now: environment.now } : {}),
|
|
91
|
+
// amoCRM counts per integration and account: two profiles on one account share one pace.
|
|
92
|
+
pacer: new Pacer(pacePathFor(IDENTITY, `account-${new URL(signIn.origin).hostname}`, env), ACCOUNT_PACE, environment.now),
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
/** The body inside core's run: recorded, under `--timeout`, its requests in the run's events (WC-LIFE-17). */
|
|
96
|
+
export const withAccount = (command, body) => contextOf(command).run((events) => body(transportFor(command, signInOf(command), events)));
|
|
97
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAkB,MAAM,mBAAmB,CAAA;AAExE,OAAO,EAEL,WAAW,EAEX,aAAa,EAEb,iBAAiB,EACjB,aAAa,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC9D,OAAO,EAAgB,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAgB,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,QAAQ,EAA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C1D,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,yFAAyF;QACzF,KAAK,EAAE,IAAI,KAAK,CACd,WAAW,CAAC,QAAQ,EAAE,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,EACxE,YAAY,EACZ,WAAW,CAAC,GAAG,CAChB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,8GAA8G;AAC9G,MAAM,CAAC,MAAM,WAAW,GAAG,CAAI,OAAgB,EAAE,IAA2C,EAAc,EAAE,CAC1G,SAAS,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CrmActivity } from "@wirecat/cli-core";
|
|
2
|
+
import { type CrmCallContext, type CrmPage } from "@wirecat/cli-core/crm";
|
|
3
|
+
import { type Route } from "../amo/routes.js";
|
|
4
|
+
import type { QueryValue } from "../amo/transport.js";
|
|
5
|
+
import type { Raw } from "./records.js";
|
|
6
|
+
export type ListPage = (route: Route, name: string, query: Record<string, QueryValue>) => Promise<{
|
|
7
|
+
rows: Raw[];
|
|
8
|
+
more: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
export interface ActivityRead {
|
|
11
|
+
since: number;
|
|
12
|
+
page?: string;
|
|
13
|
+
now: number;
|
|
14
|
+
/** Rows a request asks while windows are searched. */
|
|
15
|
+
size: number;
|
|
16
|
+
/** The events filter for these types, in the form the account's host takes. */
|
|
17
|
+
types: (types: readonly string[]) => Record<string, QueryValue>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One call of a round over tasks and notes changed since `since`, then the round's task deletions, at
|
|
21
|
+
* `<phase><from>.<width>.<page>@<round start>`. Each call reads one window of `updated_at` seconds, `[from, from +
|
|
22
|
+
* width]`, sent one second wider at both ends since amoCRM does not say whether a bound takes its own second.
|
|
23
|
+
* - A window that holds more than a page is halved and read again; one that fits moves on, sized by the rows it held.
|
|
24
|
+
* A window is read on one page, so a row deleted or changed between two calls cannot move an unread row past the
|
|
25
|
+
* cursor, as page numbers would.
|
|
26
|
+
* - A single second that holds more than a page is read whole in the one call, page after page at the largest size.
|
|
27
|
+
* A budget stop inside it keeps the cursor at its start: the next run repeats it.
|
|
28
|
+
* - Deletions come from `task_deleted` events created in the round's window, which never change once written, so their
|
|
29
|
+
* pages keep their place.
|
|
30
|
+
*/
|
|
31
|
+
export declare const readActivities: (list: ListPage, { since, page, now, size, types }: ActivityRead, context?: CrmCallContext) => Promise<CrmPage<CrmActivity>>;
|
|
32
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/crm/activities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAA4B,MAAM,mBAAmB,CAAA;AAC9E,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,EAAa,MAAM,uBAAuB,CAAA;AACpF,OAAO,EAAU,KAAK,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAsGvC,MAAM,MAAM,QAAQ,GAAG,CACrB,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,KAC9B,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,KAAK,EAAE,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CAChE;AAoBD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,SACnB,QAAQ,qCACqB,YAAY,YACrC,cAAc,KACvB,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAyE9B,CAAA"}
|