@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,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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AU9C,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=operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.js","sourceRoot":"","sources":["../../src/amo/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE5C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AA6BjD,MAAM,MAAM,GAAG,UAAU,CAAA;AAEzB,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE;IAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC/B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAa,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAA;AACtF,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,IAAyC,EAAY,EAAE;IACvF,MAAM,IAAI,GAAG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