@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,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account hosts: `<subdomain>.amocrm.ru` (amoCRM), `<subdomain>.kommo.com` and the older `<subdomain>.amocrm.com`
|
|
3
|
+
* (Kommo), never the shared `www` (amocrm.ru developers "Рекомендации", developers.kommo.com "Limitations").
|
|
4
|
+
*/
|
|
5
|
+
export declare const ACCOUNT_DOMAINS: readonly ["amocrm.ru", "amocrm.com", "kommo.com"];
|
|
6
|
+
/** One account: the address the owner gave, kept exactly (amocrm.com is never turned into kommo.com), and its token. */
|
|
7
|
+
export interface AmoSignIn {
|
|
8
|
+
origin: string;
|
|
9
|
+
token: string;
|
|
10
|
+
/** The token's user, learnt at sign-in; absent for `AMO_TOKEN`. */
|
|
11
|
+
userId?: string;
|
|
12
|
+
}
|
|
13
|
+
/** `https://example.amocrm.ru`, `example.kommo.com/`: the account's origin, or a refusal that quotes nothing back. */
|
|
14
|
+
export declare const accountOrigin: (raw: string) => string;
|
|
15
|
+
/** The keyring holds the address beside the token, so one entry is the whole sign-in, as b24's webhook address is. */
|
|
16
|
+
export declare const encodeSignIn: (signIn: AmoSignIn) => string;
|
|
17
|
+
export declare const decodeSignIn: (secret: string) => AmoSignIn;
|
|
18
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/amo/account.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,eAAe,YAAI,WAAW,EAAE,YAAY,EAAE,WAAW,CAAU,CAAA;AAMhF,wHAAwH;AACxH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,sHAAsH;AACtH,eAAO,MAAM,aAAa,QAAS,MAAM,KAAG,MAmB3C,CAAA;AAED,sHAAsH;AACtH,eAAO,MAAM,YAAY,WAAY,SAAS,KAAG,MAAgC,CAAA;AAEjF,eAAO,MAAM,YAAY,WAAY,MAAM,KAAG,SAoB7C,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { isRecord } from "./json.js";
|
|
3
|
+
/**
|
|
4
|
+
* Account hosts: `<subdomain>.amocrm.ru` (amoCRM), `<subdomain>.kommo.com` and the older `<subdomain>.amocrm.com`
|
|
5
|
+
* (Kommo), never the shared `www` (amocrm.ru developers "Рекомендации", developers.kommo.com "Limitations").
|
|
6
|
+
*/
|
|
7
|
+
export const ACCOUNT_DOMAINS = ["amocrm.ru", "amocrm.com", "kommo.com"];
|
|
8
|
+
const HOST = new RegExp(`^(?!www\\.)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.(${ACCOUNT_DOMAINS.join("|").replaceAll(".", "\\.")})$`);
|
|
9
|
+
/** `https://example.amocrm.ru`, `example.kommo.com/`: the account's origin, or a refusal that quotes nothing back. */
|
|
10
|
+
export const accountOrigin = (raw) => {
|
|
11
|
+
const refused = (why) => new CliError("validation_error", `--host takes the account's address, such as https://example.amocrm.ru or https://example.kommo.com: ${why}`, { reason: "account.malformed", param: "--host" });
|
|
12
|
+
const text = raw.trim();
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
url = new URL(/^[a-z]+:\/\//i.test(text) ? text : `https://${text}`);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw refused("it is not an address");
|
|
19
|
+
}
|
|
20
|
+
if (url.protocol !== "https:")
|
|
21
|
+
throw refused("it must be https");
|
|
22
|
+
if (url.username || url.password || url.port || url.search || url.hash || (url.pathname !== "/" && url.pathname))
|
|
23
|
+
throw refused("it carries more than the account's host");
|
|
24
|
+
if (!HOST.test(url.hostname))
|
|
25
|
+
throw refused(`the host is not <subdomain>.${ACCOUNT_DOMAINS.join(", .")}`);
|
|
26
|
+
return url.origin;
|
|
27
|
+
};
|
|
28
|
+
/** The keyring holds the address beside the token, so one entry is the whole sign-in, as b24's webhook address is. */
|
|
29
|
+
export const encodeSignIn = (signIn) => JSON.stringify(signIn);
|
|
30
|
+
export const decodeSignIn = (secret) => {
|
|
31
|
+
let value;
|
|
32
|
+
try {
|
|
33
|
+
value = JSON.parse(secret);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
value = undefined;
|
|
37
|
+
}
|
|
38
|
+
if (!isRecord(value) || typeof value.origin !== "string" || typeof value.token !== "string")
|
|
39
|
+
throw new CliError("configuration_error", "the saved sign-in is not one amo wrote; sign in again with session start", {
|
|
40
|
+
reason: "account.malformed",
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
origin: accountOrigin(value.origin),
|
|
44
|
+
token: value.token,
|
|
45
|
+
...(typeof value.userId === "string" ? { userId: value.userId } : {}),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/amo/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,WAAW,CAAU,CAAA;AAEhF,MAAM,IAAI,GAAG,IAAI,MAAM,CACrB,sDAAsD,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAC3G,CAAA;AAUD,sHAAsH;AACtH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAU,EAAE;IACnD,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE,CAC9B,IAAI,QAAQ,CACV,kBAAkB,EAClB,uGAAuG,GAAG,EAAE,EAC5G,EAAE,MAAM,EAAE,mBAAmB,EAAE,KAAK,EAAE,QAAQ,EAAE,CACjD,CAAA;IACH,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAA;IACvB,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,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AA0E,EAC1E;YACE,MAAM,EAAE,mBAAmB;SAC5B,CACF,CAAA;IACH,OAAO;QACL,MAAM,EAAE,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;QACnC,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GAAG,CAAC,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtE,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SchemaNode } from "@wirecat/cli-base/codegen";
|
|
2
|
+
import type { SpecOperation } from "./operation.js";
|
|
3
|
+
/** The record types `{entity_type}` and `{entity}` take where the spec gives no enum. */
|
|
4
|
+
export declare const ENTITY_TYPES: {
|
|
5
|
+
readonly values: readonly ["leads", "contacts", "companies", "customers"];
|
|
6
|
+
readonly sources: readonly ["https://www.amocrm.ru/developers/content/crm_platform/entity-links-api", "https://www.amocrm.ru/developers/content/crm_platform/custom-fields", "https://www.amocrm.ru/developers/content/crm_platform/tags-api", "https://www.amocrm.ru/developers/content/crm_platform/events-and-notes"];
|
|
7
|
+
};
|
|
8
|
+
/** Routes with no page in the Kommo reference. */
|
|
9
|
+
export declare const EXTRA_OPERATIONS: readonly SpecOperation[];
|
|
10
|
+
/** The `with` values each list or record takes; the spec types `with` as free text and names them only in prose. */
|
|
11
|
+
export declare const WITH_VALUES: Readonly<Record<string, {
|
|
12
|
+
values: readonly string[];
|
|
13
|
+
source: string;
|
|
14
|
+
}>>;
|
|
15
|
+
/** The largest `limit` a list takes: 250 on every list page, events 100 in the ru docs (Kommo says 250). */
|
|
16
|
+
export declare const LIMITS: {
|
|
17
|
+
readonly default: 250;
|
|
18
|
+
readonly byPath: Readonly<Record<string, number>>;
|
|
19
|
+
readonly sources: readonly ["https://www.amocrm.ru/developers/content/crm_platform/leads-api", "https://www.amocrm.ru/developers/content/crm_platform/events-and-notes"];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Body fields the merged spec types wrongly, by name at any depth of any body: right for `custom_fields_values`, which
|
|
23
|
+
* means the same everywhere. Every write page types
|
|
24
|
+
* `custom_fields_values` as a string; the custom-fields page sends an array of `field_id` or `field_code` with
|
|
25
|
+
* `values`, each a `value`, `enum_id` or `enum_code`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const BODY_FIELDS: Readonly<Record<string, {
|
|
28
|
+
schema: SchemaNode;
|
|
29
|
+
source: string;
|
|
30
|
+
}>>;
|
|
31
|
+
//# sourceMappingURL=allow-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allow-list.d.ts","sourceRoot":"","sources":["../../src/amo/allow-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AASnD,yFAAyF;AACzF,eAAO,MAAM,YAAY;aACvB,MAAM,YAAG,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW;aACtD,OAAO,sFAEL,qEAAqE,EACrE,gEAAgE,EAChE,wEAAwE;CAElE,CAAA;AAEV,kDAAkD;AAClD,eAAO,MAAM,gBAAgB,EAAE,SAAS,aAAa,EAWpD,CAAA;AAED,oHAAoH;AACpH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAmC/F,CAAA;AAED,4GAA4G;AAC5G,eAAO,MAAM,MAAM;aACjB,OAAO,EAAE,GAAG;aACZ,MAAM,EAA+B,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;aACrE,OAAO,YACL,iEAAiE,EACjE,wEAAwE;CAElE,CAAA;AAIV;;;;;GAKG;AACH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA2BxF,CAAA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* What amoCRM documents but the merged Kommo OpenAPI (contracts/kommo-openapi.json) does not carry as a concrete path
|
|
3
|
+
* or value. Each entry names its page; nothing passes the fake or `api call` without being here or in the spec.
|
|
4
|
+
*/
|
|
5
|
+
const LINKS = "https://www.amocrm.ru/developers/content/crm_platform/entity-links-api";
|
|
6
|
+
/** The record types `{entity_type}` and `{entity}` take where the spec gives no enum. */
|
|
7
|
+
export const ENTITY_TYPES = {
|
|
8
|
+
values: ["leads", "contacts", "companies", "customers"],
|
|
9
|
+
sources: [
|
|
10
|
+
LINKS,
|
|
11
|
+
"https://www.amocrm.ru/developers/content/crm_platform/custom-fields",
|
|
12
|
+
"https://www.amocrm.ru/developers/content/crm_platform/tags-api",
|
|
13
|
+
"https://www.amocrm.ru/developers/content/crm_platform/events-and-notes",
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
/** Routes with no page in the Kommo reference. */
|
|
17
|
+
export const EXTRA_OPERATIONS = [
|
|
18
|
+
{
|
|
19
|
+
// The mass form beside the spec's `/{entity}/{entity_id}/links`: the links of many records in one call.
|
|
20
|
+
name: "GET /api/v4/{entity_type}/links",
|
|
21
|
+
effect: "read",
|
|
22
|
+
summary: "Get the links of many entities",
|
|
23
|
+
source: LINKS,
|
|
24
|
+
path: { entity_type: { type: "string" } },
|
|
25
|
+
query: ["filter[entity_id][]", "filter[to_entity_id]", "filter[to_entity_type]", "filter[to_catalog_id]"],
|
|
26
|
+
body: false,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
/** The `with` values each list or record takes; the spec types `with` as free text and names them only in prose. */
|
|
30
|
+
export const WITH_VALUES = Object.fromEntries([
|
|
31
|
+
[
|
|
32
|
+
["GET /api/v4/account"],
|
|
33
|
+
"amojo_id,version,drive_url,task_types,users_groups,datetime_settings,entity_names,is_api_filter_enabled",
|
|
34
|
+
"https://www.amocrm.ru/developers/content/crm_platform/account-info",
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
["GET /api/v4/leads", "GET /api/v4/leads/{id}"],
|
|
38
|
+
"catalog_elements,is_price_modified_by_robot,loss_reason,contacts,only_deleted,source_id,source",
|
|
39
|
+
"https://www.amocrm.ru/developers/content/crm_platform/leads-api",
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
["GET /api/v4/contacts", "GET /api/v4/contacts/{id}"],
|
|
43
|
+
"catalog_elements,leads,customers",
|
|
44
|
+
"https://www.amocrm.ru/developers/content/crm_platform/contacts-api",
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
["GET /api/v4/companies", "GET /api/v4/companies/{id}"],
|
|
48
|
+
"catalog_elements,leads,customers,contacts",
|
|
49
|
+
"https://www.amocrm.ru/developers/content/crm_platform/companies-api",
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
["GET /api/v4/events"],
|
|
53
|
+
"contact_name,lead_name,company_name,catalog_element_name,customer_name,catalog_name",
|
|
54
|
+
"https://www.amocrm.ru/developers/content/crm_platform/events-and-notes",
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
["GET /api/v4/users", "GET /api/v4/users/{id}"],
|
|
58
|
+
"role,group,uuid,amojo_id,user_rank,phone_number",
|
|
59
|
+
"https://www.amocrm.ru/developers/content/crm_platform/users-api",
|
|
60
|
+
],
|
|
61
|
+
].flatMap(([names, values, source]) => names.map((name) => [name, { values: values.split(","), source }])));
|
|
62
|
+
/** The largest `limit` a list takes: 250 on every list page, events 100 in the ru docs (Kommo says 250). */
|
|
63
|
+
export const LIMITS = {
|
|
64
|
+
default: 250,
|
|
65
|
+
byPath: { "/api/v4/events": 100 },
|
|
66
|
+
sources: [
|
|
67
|
+
"https://www.amocrm.ru/developers/content/crm_platform/leads-api",
|
|
68
|
+
"https://www.amocrm.ru/developers/content/crm_platform/events-and-notes",
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
const CUSTOM_FIELDS = "https://www.amocrm.ru/developers/content/crm_platform/custom-fields";
|
|
72
|
+
/**
|
|
73
|
+
* Body fields the merged spec types wrongly, by name at any depth of any body: right for `custom_fields_values`, which
|
|
74
|
+
* means the same everywhere. Every write page types
|
|
75
|
+
* `custom_fields_values` as a string; the custom-fields page sends an array of `field_id` or `field_code` with
|
|
76
|
+
* `values`, each a `value`, `enum_id` or `enum_code`.
|
|
77
|
+
*/
|
|
78
|
+
export const BODY_FIELDS = {
|
|
79
|
+
custom_fields_values: {
|
|
80
|
+
source: CUSTOM_FIELDS,
|
|
81
|
+
schema: {
|
|
82
|
+
type: "array",
|
|
83
|
+
items: {
|
|
84
|
+
type: "object",
|
|
85
|
+
required: ["values"],
|
|
86
|
+
properties: {
|
|
87
|
+
field_id: { type: "integer" },
|
|
88
|
+
field_code: { type: "string" },
|
|
89
|
+
values: {
|
|
90
|
+
type: "array",
|
|
91
|
+
items: {
|
|
92
|
+
type: "object",
|
|
93
|
+
required: [],
|
|
94
|
+
properties: {
|
|
95
|
+
value: { type: "unknown" },
|
|
96
|
+
enum_id: { type: "integer" },
|
|
97
|
+
enum_code: { type: "string" },
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=allow-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allow-list.js","sourceRoot":"","sources":["../../src/amo/allow-list.ts"],"names":[],"mappings":"AAGA;;;GAGG;AAEH,MAAM,KAAK,GAAG,wEAAwE,CAAA;AAEtF,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EA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,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAC3G,CAAA;AAED,4GAA4G;AAC5G,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,EAAE,gBAAgB,EAAE,GAAG,EAAsC;IACrE,OAAO,EAAE;QACP,iEAAiE;QACjE,wEAAwE;KACzE;CACO,CAAA;AAEV,MAAM,aAAa,GAAG,qEAAqE,CAAA;AAE3F;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAqE;IAC3F,oBAAoB,EAAE;QACpB,MAAM,EAAE,aAAa;QACrB,MAAM,EAAE;YACN,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,QAAQ,EAAE,CAAC,QAAQ,CAAC;gBACpB,UAAU,EAAE;oBACV,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;oBAC7B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC9B,MAAM,EAAE;wBACN,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;4BACd,QAAQ,EAAE,EAAE;4BACZ,UAAU,EAAE;gCACV,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gCAC1B,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;gCAC5B,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;6BAC9B;yBACF;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
export declare const isBlock: (operation: string, body: unknown, json: boolean) => boolean;
|
|
3
|
+
export interface Refusal {
|
|
4
|
+
/** Whether the answer was JSON at all: a block's 403 is a bare page. */
|
|
5
|
+
json: boolean;
|
|
6
|
+
waitMs?: number | undefined;
|
|
7
|
+
/** An OAuth access token, which a refresh renews; a long-lived token has nothing to refresh it with. */
|
|
8
|
+
oauth?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** amoCRM's refusal as a stable code and reason a script branches on; the message never repeats amoCRM's text. */
|
|
11
|
+
export declare const amoError: (operation: string, status: number, body: unknown, { json, waitMs, oauth }: Refusal) => CliError;
|
|
12
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/amo/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwC,MAAM,mBAAmB,CAAA;AA2ClF,eAAO,MAAM,OAAO,cAAe,MAAM,QAAQ,OAAO,QAAQ,OAAO,KAAG,OACH,CAAA;AAEvE,MAAM,WAAW,OAAO;IACtB,wEAAwE;IACxE,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,wGAAwG;IACxG,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,kHAAkH;AAClH,eAAO,MAAM,QAAQ,cACR,MAAM,UACT,MAAM,QACR,OAAO,2BACoB,OAAO,KACvC,QAoDF,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { retryableStatus, statusToCode } from "@wirecat/cli-base/http";
|
|
3
|
+
import { isRecord } from "./json.js";
|
|
4
|
+
/*
|
|
5
|
+
* amoCRM answers a refusal as problem+json: `title`, `type`, `status`, `detail`, and on a validation failure
|
|
6
|
+
* `validation-errors: [{ request_id, errors: [{ code, path, detail }] }]`
|
|
7
|
+
* (https://www.amocrm.ru/developers/content/crm_platform/error-codes, https://developers.kommo.com/docs/http-codes).
|
|
8
|
+
* The limits and what 402 and 403 mean are on https://www.amocrm.ru/developers/content/api/recommendations.
|
|
9
|
+
*
|
|
10
|
+
* A block of every request is a 403 too. The ru error-codes page lists code 113 (403, "access to this account is
|
|
11
|
+
* forbidden from your IP address") and 403 ("the account is blocked for repeatedly exceeding the requests a second");
|
|
12
|
+
* Kommo's http-codes page shows the block as a bare `403 Forbidden` page. Neither names the body field, so the code is
|
|
13
|
+
* read where amoCRM's other answers put one: `error_code`, at the top or under `response`.
|
|
14
|
+
*/
|
|
15
|
+
/** Kommo's 429 example carries `retry_after` in seconds; without it, a second, the limit's own window. */
|
|
16
|
+
const RATE_WAIT_MS = 1_000;
|
|
17
|
+
const CODE = /^[A-Za-z0-9_.[\]-]{1,128}$/;
|
|
18
|
+
/** Only code-shaped paths and codes: a `detail` can quote a value somebody typed (WC-SECR-6). */
|
|
19
|
+
const validationOf = (body) => {
|
|
20
|
+
const groups = isRecord(body) ? body["validation-errors"] : undefined;
|
|
21
|
+
const errors = (Array.isArray(groups) ? groups : []).flatMap((group) => isRecord(group) && Array.isArray(group.errors) ? group.errors.filter(isRecord) : []);
|
|
22
|
+
const pick = (key) => errors.map((one) => one[key]).filter((one) => typeof one === "string" && CODE.test(one));
|
|
23
|
+
return { fields: [...new Set(pick("path"))], codes: [...new Set(pick("code"))] };
|
|
24
|
+
};
|
|
25
|
+
/** The documented codes of a block (error-codes: 113 address not allowed, 403 blocked for the rate). */
|
|
26
|
+
const BLOCK_CODES = new Set(["113", "403"]);
|
|
27
|
+
/** No user right gates the account itself, so a refusal of it is a block. */
|
|
28
|
+
const UNGATED = "GET /api/v4/account";
|
|
29
|
+
const codeOf = (body) => {
|
|
30
|
+
const holder = isRecord(body) && isRecord(body.response) ? body.response : body;
|
|
31
|
+
const code = isRecord(holder) ? holder.error_code : undefined;
|
|
32
|
+
return typeof code === "string" || typeof code === "number" ? String(code) : undefined;
|
|
33
|
+
};
|
|
34
|
+
export const isBlock = (operation, body, json) => !json || operation === UNGATED || BLOCK_CODES.has(codeOf(body) ?? "");
|
|
35
|
+
/** amoCRM's refusal as a stable code and reason a script branches on; the message never repeats amoCRM's text. */
|
|
36
|
+
export const amoError = (operation, status, body, { json, waitMs, oauth = false }) => {
|
|
37
|
+
const details = { operation, status };
|
|
38
|
+
const as = (code, message, more = {}) => new CliError(code, message, { ...details, ...more });
|
|
39
|
+
if (status === 401 && oauth)
|
|
40
|
+
return as("authentication_error", "amoCRM refused the access token; it is renewed with the refresh token", {
|
|
41
|
+
reason: "oauth.expired",
|
|
42
|
+
});
|
|
43
|
+
if (status === 401)
|
|
44
|
+
return as("authentication_error", "amoCRM refused the token: it expired, was revoked, or the account address is wrong. Make a new long-lived " +
|
|
45
|
+
"token and sign in again with `amo <profile> session start`", { reason: "session.expired" });
|
|
46
|
+
if (status === 402)
|
|
47
|
+
return as("permission_error", "the amoCRM subscription has ended: writes stop at once, and reads 30 days later. Renew it in amoCRM", { reason: "amo.subscription-ended" });
|
|
48
|
+
if (status === 403 && isBlock(operation, body, json))
|
|
49
|
+
return as("permission_error", "amoCRM blocks every request from here (too many requests, or an address not on the account's allow list). " +
|
|
50
|
+
"Stop all amo commands on this account and check it in amoCRM before trying again", { reason: "amo.blocked", retryable: false });
|
|
51
|
+
if (status === 403)
|
|
52
|
+
return as("permission_error", `the token's user may not do ${operation} in amoCRM`, { reason: "amo.access-denied" });
|
|
53
|
+
if (status === 429) {
|
|
54
|
+
const after = isRecord(body) && typeof body.retry_after === "number" ? body.retry_after * 1000 : undefined;
|
|
55
|
+
return as("rate_limited", `amoCRM asks to slow down before ${operation}`, {
|
|
56
|
+
retry_after_ms: waitMs ?? after ?? RATE_WAIT_MS,
|
|
57
|
+
retryable: true,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (status === 404)
|
|
61
|
+
return as("not_found", `${operation}: amoCRM has no such record, or this token cannot see it`);
|
|
62
|
+
if (status === 400 || status === 422) {
|
|
63
|
+
const { fields, codes } = validationOf(body);
|
|
64
|
+
return as("validation_error", `amoCRM refused ${operation}${fields.length ? `; check ${fields.join(", ")}` : ""}`, fields.length ? { fields, ...(codes.length ? { provider_error: codes.join(",") } : {}) } : {});
|
|
65
|
+
}
|
|
66
|
+
if (status >= 500)
|
|
67
|
+
return as("provider_unavailable", `amoCRM failed on ${operation} (HTTP ${status})`, {
|
|
68
|
+
retryable: retryableStatus(status),
|
|
69
|
+
});
|
|
70
|
+
return as(status >= 400 ? statusToCode(status) : "provider_error", `amoCRM refused ${operation} (HTTP ${status})`);
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/amo/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwC,MAAM,mBAAmB,CAAA;AAClF,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC;;;;;;;;;;GAUG;AAEH,0GAA0G;AAC1G,MAAM,YAAY,GAAG,KAAK,CAAA;AAE1B,MAAM,IAAI,GAAG,4BAA4B,CAAA;AAEzC,iGAAiG;AACjG,MAAM,YAAY,GAAG,CAAC,IAAa,EAAE,EAAE;IACrC,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACrE,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACrE,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CACpF,CAAA;IACD,MAAM,IAAI,GAAG,CAAC,GAAW,EAAE,EAAE,CAC3B,MAAM,CAA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CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,gBAAgB,EAAE,kBAAkB,SAAS,UAAU,MAAM,GAAG,CAAC,CAAA;AACpH,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/amo/json.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE1C,eAAO,MAAM,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,IAAsB,CAAA"}
|
package/dist/amo/json.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/amo/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAIjD,MAAM,CAAC,MAAM,QAAQ,GAAsC,SAAS,CAAC,KAAK,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type CredentialStorage, type KeyringStore } from "@wirecat/cli-base";
|
|
2
|
+
import { type OAuthClient, type OAuthProvider, type SignInOptions as SignInSteps, type TokenCodec, type TokenStorage } from "@wirecat/cli-core/oauth";
|
|
3
|
+
export declare const PROVIDER = "amocrm";
|
|
4
|
+
/**
|
|
5
|
+
* The integration's Redirect URI, which amoCRM sends the browser to with `code` and `state` (amocrm.ru developers
|
|
6
|
+
* oauth/step-by-step). The static page forwards any `code` and `state` to the waiting local port (cli-docs
|
|
7
|
+
* public/webhooks/apps/amo-callback.html).
|
|
8
|
+
*/
|
|
9
|
+
export declare const RELAY_URL = "https://wirecat.dev/webhooks/apps/amo-callback";
|
|
10
|
+
/** A sign-in through the owner's own integration: the account, the user whose rights it carries, and the token. */
|
|
11
|
+
export interface AppAuth {
|
|
12
|
+
origin: string;
|
|
13
|
+
userId: string;
|
|
14
|
+
accessToken: (refresh: boolean) => Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* cli-core's account-bound entry, plus the Redirect URI it was signed in with: every refresh sends the same one, and
|
|
18
|
+
* amoCRM refuses one that differs from the integration's setting (oauth/step-by-step).
|
|
19
|
+
*/
|
|
20
|
+
export declare const appCodec: TokenCodec;
|
|
21
|
+
/** The same service, folder and moved-run rule as the long-lived token's `ProfileTokenStore`, under `oauth:amocrm:<profile>`. */
|
|
22
|
+
export declare const appStorage: (env: NodeJS.ProcessEnv, profile: string, keyring?: KeyringStore, storage?: CredentialStorage) => TokenStorage;
|
|
23
|
+
/** Where the integration's sign-in is kept, `keyring` or `file`, and never what. */
|
|
24
|
+
export declare const appSourceOf: (env: NodeJS.ProcessEnv, profile: string, keyring?: KeyringStore) => import("@wirecat/cli-base").CredentialSource | undefined;
|
|
25
|
+
export declare const appProvider: (origin: string, client: OAuthClient, redirectUri?: string) => OAuthProvider;
|
|
26
|
+
export interface AppSignInOptions<T> {
|
|
27
|
+
env: NodeJS.ProcessEnv;
|
|
28
|
+
profile: string;
|
|
29
|
+
origin: string;
|
|
30
|
+
client: OAuthClient;
|
|
31
|
+
storage: "keyring" | "file";
|
|
32
|
+
keyring?: KeyringStore | undefined;
|
|
33
|
+
fetch?: typeof fetch | undefined;
|
|
34
|
+
signal?: AbortSignal | undefined;
|
|
35
|
+
signInCommand: string;
|
|
36
|
+
steps: Omit<SignInSteps, "scopes" | "accept">;
|
|
37
|
+
/** Whose rights the new tokens carry, asked of the account before anything is kept. */
|
|
38
|
+
check: (auth: AppAuth) => Promise<T>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The integration's sign-in: authorize in the browser, exchange the code on the account the owner named, ask that
|
|
42
|
+
* account who it is, then keep it. A code from another account fails there, before anything is saved.
|
|
43
|
+
*/
|
|
44
|
+
export declare const appSignIn: <T extends {
|
|
45
|
+
id: string;
|
|
46
|
+
}>(options: AppSignInOptions<T>) => Promise<T>;
|
|
47
|
+
/** The profile's integration sign-in, refreshed under cli-core's shared lock; none when the profile has none. */
|
|
48
|
+
export declare const appAuthOf: (options: {
|
|
49
|
+
env: NodeJS.ProcessEnv;
|
|
50
|
+
profile: string;
|
|
51
|
+
keyring?: KeyringStore | undefined;
|
|
52
|
+
fetch?: typeof fetch | undefined;
|
|
53
|
+
signal?: AbortSignal | undefined;
|
|
54
|
+
}) => AppAuth | undefined;
|
|
55
|
+
//# sourceMappingURL=oauth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/amo/oauth.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EAGtB,KAAK,YAAY,EAGlB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,aAAa,EAElB,KAAK,aAAa,IAAI,WAAW,EACjC,KAAK,UAAU,EAEf,KAAK,YAAY,EAElB,MAAM,yBAAyB,CAAA;AAKhC,eAAO,MAAM,QAAQ,WAAW,CAAA;AAChC;;;;GAIG;AACH,eAAO,MAAM,SAAS,mDAAmD,CAAA;AAIzE,mHAAmH;AACnH,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAID;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,UAStB,CAAA;AAcD,iIAAiI;AACjI,eAAO,MAAM,UAAU,QAChB,MAAM,CAAC,UAAU,WACb,MAAM,YACL,YAAY,YACb,iBAAiB,KACzB,YAKC,CAAA;AAEJ,oFAAoF;AACpF,eAAO,MAAM,WAAW,QAAS,MAAM,CAAC,UAAU,WAAW,MAAM,YAAY,YAAY,6DACS,CAAA;AA2FpG,eAAO,MAAM,WAAW,WAAY,MAAM,UAAU,WAAW,gBAAe,MAAM,KAAe,aAUjG,CAAA;AAKF,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,WAAW,CAAA;IACnB,OAAO,EAAE,SAAS,GAAG,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;IAChC,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAA;IAC7C,uFAAuF;IACvF,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CACrC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,WAAW,gBAAgB,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAsBjG,CAAA;AAED,iHAAiH;AACjH,eAAO,MAAM,SAAS,YAAa;IACjC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC,KAAG,OAAO,GAAG,SAkBb,CAAA"}
|
|
@@ -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,GAAG,gDAAgD,CAAA;AACzE,MAAM,UAAU,GAAG,MAAM,CAAA;AACzB,MAAM,IAAI,GAAG,sBAAsB,CAAA;AASnC,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAA;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAe;IAClC,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,OAAO,CAAC,MAAM;IACtB,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;QACd,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClC,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACtC,MAAM,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