@wirecat/amo-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 +61 -0
- package/LICENSE +204 -0
- package/README.md +257 -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/call.d.ts +24 -0
- package/dist/amo/call.d.ts.map +1 -0
- package/dist/amo/call.js +54 -0
- package/dist/amo/call.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-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-DTA5YV5O.js +25 -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-K5UU3IOR.js +27955 -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-NHXJYS4R.js +1334 -0
- package/dist/bundle/chunk-NJYAL3UW.js +92 -0
- package/dist/bundle/chunk-NTLSWCJ5.js +1718 -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-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-KEGIR67U.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-XJGFOXYI.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-VQQTSSAF.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-BPNIM4BF.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/comments.d.ts +3 -0
- package/dist/commands/comments.d.ts.map +1 -0
- package/dist/commands/comments.js +114 -0
- package/dist/commands/comments.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/sample/comments.d.ts +61 -0
- package/dist/sample/comments.d.ts.map +1 -0
- package/dist/sample/comments.js +39 -0
- package/dist/sample/comments.js.map +1 -0
- package/dist/sample/records.d.ts +16 -0
- package/dist/sample/records.d.ts.map +1 -0
- package/dist/sample/records.js +22 -0
- package/dist/sample/records.js.map +1 -0
- package/dist/sample/transport.d.ts +42 -0
- package/dist/sample/transport.d.ts.map +1 -0
- package/dist/sample/transport.js +153 -0
- package/dist/sample/transport.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 +85 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { CliError, Credentials, isMovedRun, resolvePaths, systemKeyring, } from "@wirecat/cli-base";
|
|
2
|
+
import { hostFetch } from "@wirecat/cli-base/http";
|
|
3
|
+
import { accountTokenCodec, credentialStorage, oauthAccount, tokenKeeper, } from "@wirecat/cli-core/oauth";
|
|
4
|
+
import { IDENTITY } from "../identity.js";
|
|
5
|
+
import { accountOrigin } from "./account.js";
|
|
6
|
+
import { isRecord } from "./json.js";
|
|
7
|
+
export const PROVIDER = "amocrm";
|
|
8
|
+
/**
|
|
9
|
+
* The integration's Redirect URI, which amoCRM sends the browser to with `code` and `state` (amocrm.ru developers
|
|
10
|
+
* oauth/step-by-step). The static page forwards any `code` and `state` to the waiting local port (cli-docs
|
|
11
|
+
* public/webhooks/apps/amo-callback.html).
|
|
12
|
+
*/
|
|
13
|
+
export const RELAY_URL = "https://wirecat.dev/webhooks/apps/amo-callback";
|
|
14
|
+
const REQUEST_MS = 30_000;
|
|
15
|
+
const HINT = /^[\w .,:'`-]{1,200}$/;
|
|
16
|
+
const account = accountTokenCodec(PROVIDER);
|
|
17
|
+
/**
|
|
18
|
+
* cli-core's account-bound entry, plus the Redirect URI it was signed in with: every refresh sends the same one, and
|
|
19
|
+
* amoCRM refuses one that differs from the integration's setting (oauth/step-by-step).
|
|
20
|
+
*/
|
|
21
|
+
export const appCodec = {
|
|
22
|
+
rotating: true,
|
|
23
|
+
encode: account.encode,
|
|
24
|
+
decode: (raw) => {
|
|
25
|
+
const stored = account.decode(raw);
|
|
26
|
+
const entry = JSON.parse(raw);
|
|
27
|
+
const redirectUri = isRecord(entry) && typeof entry.redirectUri === "string" ? entry.redirectUri : RELAY_URL;
|
|
28
|
+
return Object.assign(stored, { redirectUri });
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const paths = (env) => resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env });
|
|
32
|
+
const credentialsOf = (env, keyring, storage) => ({
|
|
33
|
+
configDir: paths(env).config,
|
|
34
|
+
service: IDENTITY.appName,
|
|
35
|
+
storage,
|
|
36
|
+
env,
|
|
37
|
+
isolated: isMovedRun({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env }),
|
|
38
|
+
// cli-core's sign-in store takes no default keyring; a test hands its memory keyring here instead.
|
|
39
|
+
keyring: keyring ?? systemKeyring,
|
|
40
|
+
});
|
|
41
|
+
/** The same service, folder and moved-run rule as the long-lived token's `ProfileTokenStore`, under `oauth:amocrm:<profile>`. */
|
|
42
|
+
export const appStorage = (env, profile, keyring, storage = "auto") => credentialStorage({
|
|
43
|
+
credentials: credentialsOf(env, keyring, storage),
|
|
44
|
+
account: oauthAccount(PROVIDER, profile),
|
|
45
|
+
codec: appCodec,
|
|
46
|
+
});
|
|
47
|
+
/** Where the integration's sign-in is kept, `keyring` or `file`, and never what. */
|
|
48
|
+
export const appSourceOf = (env, profile, keyring) => new Credentials(credentialsOf(env, keyring, "auto")).read(oauthAccount(PROVIDER, profile))?.source;
|
|
49
|
+
/** ru accounts sign in at amocrm.ru, Kommo and the older amocrm.com accounts at kommo.com (oauth/step-by-step; Kommo oauth-20). */
|
|
50
|
+
const authorizeUrlOf = (origin) => new URL(origin).hostname.endsWith(".amocrm.ru") ? "https://www.amocrm.ru/oauth" : "https://www.kommo.com/oauth";
|
|
51
|
+
const refusal = (status, body, again) => {
|
|
52
|
+
if (status === 429 || status >= 500)
|
|
53
|
+
return new CliError("provider_unavailable", `amoCRM's sign-in failed (HTTP ${status})`, {
|
|
54
|
+
status,
|
|
55
|
+
retryable: true,
|
|
56
|
+
reason: "oauth.unavailable",
|
|
57
|
+
});
|
|
58
|
+
// Kommo get-token: a 400 names the cause in `hint` (code expired, wrong client_id, Redirect URI mismatch).
|
|
59
|
+
const hint = isRecord(body) && typeof body.hint === "string" && HINT.test(body.hint) ? ` (${body.hint})` : "";
|
|
60
|
+
return new CliError("authentication_error", `amoCRM refused the sign-in${hint}; ${again}`, {
|
|
61
|
+
status,
|
|
62
|
+
reason: "oauth.expired",
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* `POST /oauth2/access_token` on the account's own host with a JSON body (oauth/step-by-step; Kommo get-token), which
|
|
67
|
+
* cli-core's form POST is not. Only the spec's fields go: amoCRM takes no PKCE `code_verifier`. No failure quotes
|
|
68
|
+
* the request or the answer, which hold the code, the secret or a token.
|
|
69
|
+
*/
|
|
70
|
+
const exchange = async (origin, redirectUri, params, context) => {
|
|
71
|
+
const refresh = params.grant_type === "refresh_token";
|
|
72
|
+
const again = `run ${context.signInCommand} again`;
|
|
73
|
+
const body = {
|
|
74
|
+
client_id: context.client.clientId,
|
|
75
|
+
client_secret: context.client.clientSecret ?? "",
|
|
76
|
+
grant_type: refresh ? "refresh_token" : "authorization_code",
|
|
77
|
+
...(refresh ? { refresh_token: params.refresh_token ?? "" } : { code: params.code ?? "" }),
|
|
78
|
+
redirect_uri: redirectUri,
|
|
79
|
+
};
|
|
80
|
+
const deadline = new AbortController();
|
|
81
|
+
const timer = setTimeout(() => deadline.abort(), REQUEST_MS);
|
|
82
|
+
timer.unref();
|
|
83
|
+
const signal = context.signal ? AbortSignal.any([context.signal, deadline.signal]) : deadline.signal;
|
|
84
|
+
try {
|
|
85
|
+
let response;
|
|
86
|
+
try {
|
|
87
|
+
response = await hostFetch({ hosts: [new URL(origin).hostname], fetch: context.fetch, timeoutMs: REQUEST_MS })(`${origin}/oauth2/access_token`, {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
90
|
+
body: JSON.stringify(body),
|
|
91
|
+
redirect: "error",
|
|
92
|
+
signal,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
if (context.signal?.aborted)
|
|
97
|
+
throw new CliError("cancelled", "the amoCRM sign-in was cancelled");
|
|
98
|
+
throw new CliError("outcome_unknown", `amoCRM's token request did not finish; ${again} if it keeps failing`, {
|
|
99
|
+
reason: "oauth.no-response",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
const answer = await response.json().catch(() => undefined);
|
|
103
|
+
if (!response.ok)
|
|
104
|
+
throw refusal(response.status, answer, again);
|
|
105
|
+
const fields = isRecord(answer) ? answer : {};
|
|
106
|
+
const { access_token: access, refresh_token: next, expires_in: expiresIn, token_type: tokenType } = fields;
|
|
107
|
+
if (typeof access !== "string" ||
|
|
108
|
+
!access ||
|
|
109
|
+
typeof next !== "string" ||
|
|
110
|
+
!next ||
|
|
111
|
+
typeof expiresIn !== "number" ||
|
|
112
|
+
!(expiresIn > 0))
|
|
113
|
+
throw new CliError("invalid_response", `amoCRM returned a token answer amo cannot use; ${again}`, {
|
|
114
|
+
reason: "oauth.invalid-response",
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
accessToken: access,
|
|
118
|
+
refreshToken: next,
|
|
119
|
+
expiresAt: context.now() + expiresIn * 1000,
|
|
120
|
+
scopes: [],
|
|
121
|
+
...(typeof tokenType === "string" ? { tokenType } : {}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export const appProvider = (origin, client, redirectUri = RELAY_URL) => ({
|
|
129
|
+
id: PROVIDER,
|
|
130
|
+
name: "amoCRM",
|
|
131
|
+
authorizeUrl: authorizeUrlOf(origin),
|
|
132
|
+
tokenUrl: `${origin}/oauth2/access_token`,
|
|
133
|
+
client,
|
|
134
|
+
redirect: { kind: "relay", url: redirectUri },
|
|
135
|
+
// `post_message` sends the redirect to the window the sign-in was opened in, here the browser's tab (oauth/step-by-step).
|
|
136
|
+
authorizeParams: { mode: "post_message" },
|
|
137
|
+
exchange: (params, context) => exchange(origin, redirectUri, params, context),
|
|
138
|
+
});
|
|
139
|
+
const fetchFor = (origin, given) => given ?? hostFetch({ hosts: [new URL(origin).hostname], timeoutMs: REQUEST_MS });
|
|
140
|
+
/**
|
|
141
|
+
* The integration's sign-in: authorize in the browser, exchange the code on the account the owner named, ask that
|
|
142
|
+
* account who it is, then keep it. A code from another account fails there, before anything is saved.
|
|
143
|
+
*/
|
|
144
|
+
export const appSignIn = async (options) => {
|
|
145
|
+
let user;
|
|
146
|
+
const keeper = tokenKeeper({
|
|
147
|
+
provider: appProvider(options.origin, options.client),
|
|
148
|
+
storage: appStorage(options.env, options.profile, options.keyring, options.storage === "file" ? "file" : "auto"),
|
|
149
|
+
lockDir: paths(options.env).config,
|
|
150
|
+
fetch: fetchFor(options.origin, options.fetch),
|
|
151
|
+
signInCommand: options.signInCommand,
|
|
152
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
153
|
+
});
|
|
154
|
+
await keeper.signIn({
|
|
155
|
+
...options.steps,
|
|
156
|
+
// The integration's card holds the scopes; amoCRM takes no `scope` in the request.
|
|
157
|
+
scopes: [],
|
|
158
|
+
accept: async (tokens) => {
|
|
159
|
+
const token = tokens.accessToken ?? "";
|
|
160
|
+
user = await options.check({ origin: options.origin, userId: "", accessToken: async () => token });
|
|
161
|
+
return { host: options.origin, userId: user.id, redirectUri: RELAY_URL };
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
if (!user)
|
|
165
|
+
throw new CliError("authentication_error", "amoCRM did not say whose sign-in this is");
|
|
166
|
+
return user;
|
|
167
|
+
};
|
|
168
|
+
/** The profile's integration sign-in, refreshed under cli-core's shared lock; none when the profile has none. */
|
|
169
|
+
export const appAuthOf = (options) => {
|
|
170
|
+
const storage = appStorage(options.env, options.profile, options.keyring);
|
|
171
|
+
const stored = storage.read();
|
|
172
|
+
if (!stored)
|
|
173
|
+
return undefined;
|
|
174
|
+
if (!stored.account || !stored.client)
|
|
175
|
+
throw new CliError("authentication_error", "the saved amoCRM sign-in cannot be read; sign in again", {
|
|
176
|
+
reason: "oauth.invalid",
|
|
177
|
+
});
|
|
178
|
+
const origin = accountOrigin(stored.account.host);
|
|
179
|
+
const keeper = tokenKeeper({
|
|
180
|
+
provider: appProvider(origin, stored.client, stored.redirectUri),
|
|
181
|
+
storage,
|
|
182
|
+
lockDir: paths(options.env).config,
|
|
183
|
+
fetch: fetchFor(origin, options.fetch),
|
|
184
|
+
signInCommand: `${IDENTITY.command} ${options.profile} session start --host ${origin} --client-id ${stored.client.clientId}`,
|
|
185
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
186
|
+
});
|
|
187
|
+
return { origin, userId: stored.account.userId, accessToken: (refresh) => keeper.accessToken({ refresh }) };
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=oauth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../src/amo/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,WAAW,EACX,UAAU,EAEV,YAAY,EACZ,aAAa,GACd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAIjB,YAAY,EAKZ,WAAW,GACZ,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAA;AAChC;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAA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O,IAAI,OAAO,CAAC,OAAO,yBAAyB,MAAM,gBAAgB,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;QAC5H,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtD,CAAC,CAAA;IACF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAA;AAC7G,CAAC,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Effect } from "@wirecat/cli-base/codegen";
|
|
2
|
+
export type HttpVerb = "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
|
3
|
+
export type PathParam = {
|
|
4
|
+
type: "integer";
|
|
5
|
+
} | {
|
|
6
|
+
type: "string";
|
|
7
|
+
enum?: readonly string[];
|
|
8
|
+
};
|
|
9
|
+
/** One operation as `pnpm kommo:operations` writes it from the spec, or as the allow-list adds it. */
|
|
10
|
+
export interface SpecOperation {
|
|
11
|
+
/** `<HTTP verb> <path template>`, the name `api list` prints and `api call` takes. */
|
|
12
|
+
name: string;
|
|
13
|
+
effect: Effect;
|
|
14
|
+
summary: string;
|
|
15
|
+
/** The reference page it comes from. */
|
|
16
|
+
source: string;
|
|
17
|
+
path: Readonly<Record<string, PathParam>>;
|
|
18
|
+
query: readonly string[];
|
|
19
|
+
body: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface Operation extends SpecOperation {
|
|
22
|
+
/** The spec's own name for it, placeholders kept: the key of its schemas. */
|
|
23
|
+
spec: string;
|
|
24
|
+
method: HttpVerb;
|
|
25
|
+
/** The path template, with a record type named where the spec leaves it a placeholder. */
|
|
26
|
+
template: string;
|
|
27
|
+
/** The first word after `/api/v4/`: `leads`, `contacts`, `talks`. */
|
|
28
|
+
family: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const OPERATIONS: readonly Operation[];
|
|
31
|
+
export interface Matched {
|
|
32
|
+
operation: Operation;
|
|
33
|
+
/** The path's ids by placeholder name; the URL is built from the template and these, never from the raw text. */
|
|
34
|
+
ids: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* `GET /api/v4/leads/42` or the template `GET /api/v4/leads/{id}` to its operation. A path with `.`, `..`, an escape,
|
|
38
|
+
* a query or a fragment is refused before matching, so no text reaches the account other than what a template allows.
|
|
39
|
+
*/
|
|
40
|
+
export declare const matchOperation: (raw: string) => Matched;
|
|
41
|
+
/** Refuses a template with a placeholder left empty: it would send another operation's path, never checked for. */
|
|
42
|
+
export declare const withEveryId: (matched: Matched) => Matched;
|
|
43
|
+
/** The path to send: the template with each id put in its place. */
|
|
44
|
+
export declare const pathOf: ({ operation, ids }: Matched) => string;
|
|
45
|
+
//# sourceMappingURL=operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/amo/operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAIvD,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAA;AAElE,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAAA;AAE1F,sGAAsG;AACtG,MAAM,WAAW,aAAa;IAC5B,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;IACzC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,IAAI,EAAE,OAAO,CAAA;CACd;AAED,MAAM,WAAW,SAAU,SAAQ,aAAa;IAC9C,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,QAAQ,CAAA;IAChB,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,CAAA;IAChB,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAA;CACf;AAoDD,eAAO,MAAM,UAAU,EAAE,SAAS,SAAS,EAAY,CAAA;AAyBvD,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,SAAS,CAAA;IACpB,iHAAiH;IACjH,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC5B;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,OAoC5C,CAAA;AAED,mHAAmH;AACnH,eAAO,MAAM,WAAW,YAAa,OAAO,KAAG,OAU9C,CAAA;AAED,oEAAoE;AACpE,eAAO,MAAM,MAAM,uBAAwB,OAAO,KAAG,MAC+C,CAAA"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { ENTITY_TYPES, EXTRA_OPERATIONS } from "./allow-list.js";
|
|
3
|
+
import { SPEC_OPERATIONS } from "./operations.js";
|
|
4
|
+
const PREFIX = "/api/v4/";
|
|
5
|
+
const split = (name) => {
|
|
6
|
+
const space = name.indexOf(" ");
|
|
7
|
+
return { method: name.slice(0, space), template: name.slice(space + 1) };
|
|
8
|
+
};
|
|
9
|
+
const expansions = (name, path) => {
|
|
10
|
+
const free = Object.entries(path).find(([key, param]) => param.type === "string" && (param.enum !== undefined || key === "entity_type" || key === "entity"));
|
|
11
|
+
if (!free)
|
|
12
|
+
return [name];
|
|
13
|
+
const [key, param] = free;
|
|
14
|
+
const values = param.type === "string" && param.enum ? param.enum : ENTITY_TYPES.values;
|
|
15
|
+
return values.flatMap((value) => expansions(name.replace(`{${key}}`, value), Object.fromEntries(Object.entries(path).filter(([one]) => one !== key))));
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Every operation with its record type spelled out: `GET /api/v4/{entity_type}/notes` is four operations, one per type,
|
|
19
|
+
* so `api.contacts: deny` covers a contact's notes too. A spec path that already names the type (`PATCH
|
|
20
|
+
* /api/v4/leads`, leads update) wins over the same name made from a placeholder (`PATCH /api/v4/{entity_type}`, tags).
|
|
21
|
+
*/
|
|
22
|
+
const build = () => {
|
|
23
|
+
const byName = new Map();
|
|
24
|
+
const literal = (one) => !/\{(entity_type|entity|bot)\}/.test(one.name);
|
|
25
|
+
const ordered = [...SPEC_OPERATIONS, ...EXTRA_OPERATIONS].sort((a, b) => Number(literal(b)) - Number(literal(a)));
|
|
26
|
+
for (const one of ordered)
|
|
27
|
+
for (const name of expansions(one.name, one.path)) {
|
|
28
|
+
if (byName.has(name))
|
|
29
|
+
continue;
|
|
30
|
+
const { method, template } = split(name);
|
|
31
|
+
const path = Object.fromEntries(Object.entries(one.path).filter(([key]) => template.includes(`{${key}}`)));
|
|
32
|
+
byName.set(name, {
|
|
33
|
+
...one,
|
|
34
|
+
name,
|
|
35
|
+
spec: one.name,
|
|
36
|
+
path,
|
|
37
|
+
method,
|
|
38
|
+
template,
|
|
39
|
+
family: template.slice(PREFIX.length).split("/")[0] ?? "",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
43
|
+
};
|
|
44
|
+
export const OPERATIONS = build();
|
|
45
|
+
const BY_NAME = new Map(OPERATIONS.map((one) => [one.name, one]));
|
|
46
|
+
const SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
47
|
+
const VERBS = new Set(["GET", "POST", "PATCH", "PUT", "DELETE"]);
|
|
48
|
+
const unknownMethod = (message) => new CliError("validation_error", message, { reason: "api.unknown-method", param: "<method>" });
|
|
49
|
+
const fits = (value, param) => param?.type === "integer" ? /^[0-9]+$/.test(value) : param?.enum ? param.enum.includes(value) : SEGMENT.test(value);
|
|
50
|
+
/** A literal segment beats a placeholder at the first place two templates differ (OpenAPI 3.1, "Path Templating"). */
|
|
51
|
+
const moreLiteral = (a, b) => {
|
|
52
|
+
const left = a.template.split("/");
|
|
53
|
+
const right = b.template.split("/");
|
|
54
|
+
for (let at = 0; at < left.length; at++) {
|
|
55
|
+
const x = left[at]?.startsWith("{") ?? false;
|
|
56
|
+
const y = right[at]?.startsWith("{") ?? false;
|
|
57
|
+
if (x !== y)
|
|
58
|
+
return x ? 1 : -1;
|
|
59
|
+
}
|
|
60
|
+
return 0;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* `GET /api/v4/leads/42` or the template `GET /api/v4/leads/{id}` to its operation. A path with `.`, `..`, an escape,
|
|
64
|
+
* a query or a fragment is refused before matching, so no text reaches the account other than what a template allows.
|
|
65
|
+
*/
|
|
66
|
+
export const matchOperation = (raw) => {
|
|
67
|
+
const text = raw.trim().replace(/\s+/g, " ");
|
|
68
|
+
const space = text.indexOf(" ");
|
|
69
|
+
const method = text.slice(0, space).toUpperCase();
|
|
70
|
+
const path = text.slice(space + 1).replace(/\/$/, "");
|
|
71
|
+
if (space < 0 || !VERBS.has(method) || !path.startsWith(PREFIX))
|
|
72
|
+
throw unknownMethod('a method is an HTTP verb and an /api/v4/ path, such as "GET /api/v4/leads", as api list prints it');
|
|
73
|
+
const exact = BY_NAME.get(`${method} ${path}`);
|
|
74
|
+
if (exact)
|
|
75
|
+
return { operation: exact, ids: {} };
|
|
76
|
+
const segments = path.split("/").slice(1);
|
|
77
|
+
if (segments.some((one) => !SEGMENT.test(one)))
|
|
78
|
+
throw unknownMethod(`${method} ${PREFIX}…: each part of the path is letters, digits, _ or -`);
|
|
79
|
+
const found = OPERATIONS.flatMap((operation) => {
|
|
80
|
+
if (operation.method !== method)
|
|
81
|
+
return [];
|
|
82
|
+
const parts = operation.template.split("/").slice(1);
|
|
83
|
+
if (parts.length !== segments.length)
|
|
84
|
+
return [];
|
|
85
|
+
const ids = {};
|
|
86
|
+
for (const [at, part] of parts.entries()) {
|
|
87
|
+
const value = segments[at] ?? "";
|
|
88
|
+
const name = /^\{(\w+)\}$/.exec(part)?.[1];
|
|
89
|
+
if (name === undefined) {
|
|
90
|
+
if (part !== value)
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
else if (fits(value, operation.path[name]))
|
|
94
|
+
ids[name] = value;
|
|
95
|
+
else
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
return [{ operation, ids }];
|
|
99
|
+
}).sort((a, b) => moreLiteral(a.operation, b.operation));
|
|
100
|
+
const first = found[0];
|
|
101
|
+
if (!first)
|
|
102
|
+
throw new CliError("validation_error", `${method} ${path} is not in the Kommo API reference; see api list`, {
|
|
103
|
+
reason: "api.unknown-method",
|
|
104
|
+
param: "<method>",
|
|
105
|
+
});
|
|
106
|
+
return first;
|
|
107
|
+
};
|
|
108
|
+
/** Refuses a template with a placeholder left empty: it would send another operation's path, never checked for. */
|
|
109
|
+
export const withEveryId = (matched) => {
|
|
110
|
+
const missing = Object.keys(matched.operation.path).filter((name) => !matched.ids[name]);
|
|
111
|
+
if (missing.length === 0)
|
|
112
|
+
return matched;
|
|
113
|
+
const { method, template, name } = matched.operation;
|
|
114
|
+
throw new CliError("validation_error", `${name} needs ${missing.map((one) => `{${one}}`).join(", ")} in the path, such as ` +
|
|
115
|
+
`${method} ${template.replace(/\{\w+\}/g, "42")}`, { reason: "api.path-id-missing", param: "<method>" });
|
|
116
|
+
};
|
|
117
|
+
/** The path to send: the template with each id put in its place. */
|
|
118
|
+
export const pathOf = ({ operation, ids }) => operation.template.replace(/\{(\w+)\}/g, (_, name) => encodeURIComponent(ids[name] ?? ""));
|
|
119
|
+
//# sourceMappingURL=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