@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.
Files changed (294) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/LICENSE +204 -0
  3. package/README.md +257 -2
  4. package/contracts/wirecat.json +1356 -0
  5. package/dist/amo/account.d.ts +18 -0
  6. package/dist/amo/account.d.ts.map +1 -0
  7. package/dist/amo/account.js +48 -0
  8. package/dist/amo/account.js.map +1 -0
  9. package/dist/amo/allow-list.d.ts +31 -0
  10. package/dist/amo/allow-list.d.ts.map +1 -0
  11. package/dist/amo/allow-list.js +106 -0
  12. package/dist/amo/allow-list.js.map +1 -0
  13. package/dist/amo/call.d.ts +24 -0
  14. package/dist/amo/call.d.ts.map +1 -0
  15. package/dist/amo/call.js +54 -0
  16. package/dist/amo/call.js.map +1 -0
  17. package/dist/amo/errors.d.ts +12 -0
  18. package/dist/amo/errors.d.ts.map +1 -0
  19. package/dist/amo/errors.js +72 -0
  20. package/dist/amo/errors.js.map +1 -0
  21. package/dist/amo/json.d.ts +3 -0
  22. package/dist/amo/json.d.ts.map +1 -0
  23. package/dist/amo/json.js +3 -0
  24. package/dist/amo/json.js.map +1 -0
  25. package/dist/amo/oauth.d.ts +55 -0
  26. package/dist/amo/oauth.d.ts.map +1 -0
  27. package/dist/amo/oauth.js +189 -0
  28. package/dist/amo/oauth.js.map +1 -0
  29. package/dist/amo/operation.d.ts +45 -0
  30. package/dist/amo/operation.d.ts.map +1 -0
  31. package/dist/amo/operation.js +119 -0
  32. package/dist/amo/operation.js.map +1 -0
  33. package/dist/amo/operations.d.ts +3 -0
  34. package/dist/amo/operations.d.ts.map +1 -0
  35. package/dist/amo/operations.js +1407 -0
  36. package/dist/amo/operations.js.map +1 -0
  37. package/dist/amo/routes.d.ts +67 -0
  38. package/dist/amo/routes.d.ts.map +1 -0
  39. package/dist/amo/routes.js +65 -0
  40. package/dist/amo/routes.js.map +1 -0
  41. package/dist/amo/transport.d.ts +62 -0
  42. package/dist/amo/transport.d.ts.map +1 -0
  43. package/dist/amo/transport.js +282 -0
  44. package/dist/amo/transport.js.map +1 -0
  45. package/dist/api-keys.d.ts +47 -0
  46. package/dist/api-keys.d.ts.map +1 -0
  47. package/dist/api-keys.js +224 -0
  48. package/dist/api-keys.js.map +1 -0
  49. package/dist/bin/amo.d.ts +3 -0
  50. package/dist/bin/amo.d.ts.map +1 -0
  51. package/dist/bin/amo.js +40 -0
  52. package/dist/bin/amo.js.map +1 -0
  53. package/dist/bundle/all-profiles-3KQVWDV4.js +278 -0
  54. package/dist/bundle/amo.js +198 -0
  55. package/dist/bundle/anthropic-N5NOX7K7.js +90 -0
  56. package/dist/bundle/app-server-2MST5EZ5.js +245 -0
  57. package/dist/bundle/bun-4NHWOFX2.js +169 -0
  58. package/dist/bundle/bun-sqlite-DRSXPWPR.js +75 -0
  59. package/dist/bundle/chunk-2I5UVMLW.js +3232 -0
  60. package/dist/bundle/chunk-3IRJDH2U.js +731 -0
  61. package/dist/bundle/chunk-4ZAK773N.js +100 -0
  62. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  63. package/dist/bundle/chunk-5D4Z2B5B.js +334 -0
  64. package/dist/bundle/chunk-5E5R65CA.js +54 -0
  65. package/dist/bundle/chunk-5HGGG3QO.js +73 -0
  66. package/dist/bundle/chunk-5RLUHTK6.js +23 -0
  67. package/dist/bundle/chunk-5SBLU7D7.js +63 -0
  68. package/dist/bundle/chunk-5Z5PEEKP.js +206 -0
  69. package/dist/bundle/chunk-63F65DHU.js +29 -0
  70. package/dist/bundle/chunk-6RS7OYTD.js +64 -0
  71. package/dist/bundle/chunk-73CXFE36.js +88 -0
  72. package/dist/bundle/chunk-7GTUZY7M.js +170 -0
  73. package/dist/bundle/chunk-7PKFYX7V.js +189 -0
  74. package/dist/bundle/chunk-7U5HJEPZ.js +1400 -0
  75. package/dist/bundle/chunk-A33TIM5D.js +4172 -0
  76. package/dist/bundle/chunk-ADEWU4P4.js +38 -0
  77. package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
  78. package/dist/bundle/chunk-AHJ4W2IL.js +106 -0
  79. package/dist/bundle/chunk-AUBB72VF.js +2572 -0
  80. package/dist/bundle/chunk-BVMNXI53.js +1266 -0
  81. package/dist/bundle/chunk-CDY2NJFE.js +136 -0
  82. package/dist/bundle/chunk-CHUKWON6.js +244 -0
  83. package/dist/bundle/chunk-CUZRHF34.js +230 -0
  84. package/dist/bundle/chunk-D72URWJE.js +532 -0
  85. package/dist/bundle/chunk-DAY6TSPF.js +786 -0
  86. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  87. package/dist/bundle/chunk-DJD7TBYG.js +2791 -0
  88. package/dist/bundle/chunk-DOSJONCX.js +1197 -0
  89. package/dist/bundle/chunk-DQV2IKCF.js +72 -0
  90. package/dist/bundle/chunk-DTA5YV5O.js +25 -0
  91. package/dist/bundle/chunk-DXGGCGRP.js +218 -0
  92. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  93. package/dist/bundle/chunk-EPOV5UIO.js +185 -0
  94. package/dist/bundle/chunk-EQ7A6NA6.js +53 -0
  95. package/dist/bundle/chunk-EQUKVVHX.js +353 -0
  96. package/dist/bundle/chunk-EROSAUNP.js +133 -0
  97. package/dist/bundle/chunk-ESZSMZKT.js +82 -0
  98. package/dist/bundle/chunk-FKR3M62D.js +407 -0
  99. package/dist/bundle/chunk-GNTJMB6X.js +142 -0
  100. package/dist/bundle/chunk-GQ7VFIYM.js +316 -0
  101. package/dist/bundle/chunk-JH3UOHRE.js +161 -0
  102. package/dist/bundle/chunk-JMDLPBXK.js +1068 -0
  103. package/dist/bundle/chunk-JR6TSMFX.js +9435 -0
  104. package/dist/bundle/chunk-K5UU3IOR.js +27955 -0
  105. package/dist/bundle/chunk-L6AFE73L.js +18 -0
  106. package/dist/bundle/chunk-LDEBZ3IX.js +238 -0
  107. package/dist/bundle/chunk-LGQXGOPJ.js +58 -0
  108. package/dist/bundle/chunk-LJQUYECN.js +6848 -0
  109. package/dist/bundle/chunk-LRBPT7LQ.js +95 -0
  110. package/dist/bundle/chunk-LSND5QYI.js +460 -0
  111. package/dist/bundle/chunk-NHXJYS4R.js +1334 -0
  112. package/dist/bundle/chunk-NJYAL3UW.js +92 -0
  113. package/dist/bundle/chunk-NTLSWCJ5.js +1718 -0
  114. package/dist/bundle/chunk-O2UCU52O.js +4065 -0
  115. package/dist/bundle/chunk-ODNQU7DH.js +1028 -0
  116. package/dist/bundle/chunk-P3WQRTYZ.js +24 -0
  117. package/dist/bundle/chunk-P5LYZRKW.js +63373 -0
  118. package/dist/bundle/chunk-PFO76YFP.js +2003 -0
  119. package/dist/bundle/chunk-PM77PRB6.js +12269 -0
  120. package/dist/bundle/chunk-Q2VNBY4Y.js +38109 -0
  121. package/dist/bundle/chunk-QDMXZZG4.js +604 -0
  122. package/dist/bundle/chunk-QRQYUHCZ.js +761 -0
  123. package/dist/bundle/chunk-RPWAJYI6.js +2336 -0
  124. package/dist/bundle/chunk-SMSTGO2G.js +58 -0
  125. package/dist/bundle/chunk-SZ2V62HB.js +72 -0
  126. package/dist/bundle/chunk-T2UDLX76.js +259 -0
  127. package/dist/bundle/chunk-TGEQNS6G.js +16 -0
  128. package/dist/bundle/chunk-TNUFLULO.js +2333 -0
  129. package/dist/bundle/chunk-U7RLVJ34.js +274 -0
  130. package/dist/bundle/chunk-UBRREVLJ.js +72 -0
  131. package/dist/bundle/chunk-ULXQ5MJM.js +76 -0
  132. package/dist/bundle/chunk-UMVRT7VQ.js +46 -0
  133. package/dist/bundle/chunk-V77XNPXG.js +360 -0
  134. package/dist/bundle/chunk-VVHRQ46X.js +193 -0
  135. package/dist/bundle/chunk-VX37MPTJ.js +7 -0
  136. package/dist/bundle/chunk-WCYCUTSK.js +362 -0
  137. package/dist/bundle/chunk-XEFAMLSD.js +288 -0
  138. package/dist/bundle/chunk-XQL7FEF4.js +721 -0
  139. package/dist/bundle/chunk-XRTD2GCU.js +627 -0
  140. package/dist/bundle/chunk-Y37A3232.js +804 -0
  141. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  142. package/dist/bundle/chunk-ZM7I52EP.js +78 -0
  143. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  144. package/dist/bundle/cli-KEGIR67U.js +1193 -0
  145. package/dist/bundle/command-contract-QBUQBXH7.js +39 -0
  146. package/dist/bundle/command-server-entry-5VL5U5EE.js +168 -0
  147. package/dist/bundle/decode-SQ5WGNDX.js +296 -0
  148. package/dist/bundle/dispatch-LA4DFXJD.js +411 -0
  149. package/dist/bundle/dist-XJGFOXYI.js +7577 -0
  150. package/dist/bundle/echarts-25Z3RINX.js +42501 -0
  151. package/dist/bundle/embed-BNOTNXMA.js +37 -0
  152. package/dist/bundle/embedder-BCUT7KKV.js +110 -0
  153. package/dist/bundle/failure-PKAC6XCT.js +24 -0
  154. package/dist/bundle/first-run-EO5K5GME.js +28 -0
  155. package/dist/bundle/first-screen-GMN3T6RW.js +39 -0
  156. package/dist/bundle/instructions-VLM3QAYB.js +11 -0
  157. package/dist/bundle/mcp-7ILNMJH5.js +167 -0
  158. package/dist/bundle/meeting-combined-LAMF7S2B.js +24 -0
  159. package/dist/bundle/meeting-model-GHMMUQ34.js +24 -0
  160. package/dist/bundle/meeting-semantic-BMP6323L.js +21 -0
  161. package/dist/bundle/node-CT3N3TNL.js +176 -0
  162. package/dist/bundle/node-P4E63KXA.js +2340 -0
  163. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  164. package/dist/bundle/node-sqlite-MELD2SBX.js +73 -0
  165. package/dist/bundle/oauth-YBH5OKC2.js +19 -0
  166. package/dist/bundle/open-WNSBWTAG.js +22 -0
  167. package/dist/bundle/openai-XSNMNLW6.js +237 -0
  168. package/dist/bundle/process-I2QKOMM7.js +91 -0
  169. package/dist/bundle/program-VQQTSSAF.js +4940 -0
  170. package/dist/bundle/prompt-SOG4AKPM.js +16 -0
  171. package/dist/bundle/recognize-WMQLWMXH.js +25 -0
  172. package/dist/bundle/remote-4BTFOLFY.js +30 -0
  173. package/dist/bundle/rerank-LJ3TWRNV.js +51 -0
  174. package/dist/bundle/serve-B6UANKXN.js +198 -0
  175. package/dist/bundle/server-S6XD6V6E.js +77 -0
  176. package/dist/bundle/server-YRH6GJ5Z.js +206 -0
  177. package/dist/bundle/source-DGFTA2TN.js +42 -0
  178. package/dist/bundle/sqlite-runtime-R7QFWFE7.js +19 -0
  179. package/dist/bundle/state-DIJ5YUOE.js +35 -0
  180. package/dist/bundle/store-6WFWW7EC.js +294 -0
  181. package/dist/bundle/store-BPNIM4BF.js +32 -0
  182. package/dist/bundle/store-MYTYDV6A.js +177 -0
  183. package/dist/bundle/store-maintenance-command-B5TMKFMG.js +68 -0
  184. package/dist/bundle/writer-GP7VIMAU.js +44 -0
  185. package/dist/commands/account.d.ts +3 -0
  186. package/dist/commands/account.d.ts.map +1 -0
  187. package/dist/commands/account.js +86 -0
  188. package/dist/commands/account.js.map +1 -0
  189. package/dist/commands/api.d.ts +3 -0
  190. package/dist/commands/api.d.ts.map +1 -0
  191. package/dist/commands/api.js +224 -0
  192. package/dist/commands/api.js.map +1 -0
  193. package/dist/commands/comments.d.ts +3 -0
  194. package/dist/commands/comments.d.ts.map +1 -0
  195. package/dist/commands/comments.js +114 -0
  196. package/dist/commands/comments.js.map +1 -0
  197. package/dist/commands/crm-shared.d.ts +8 -0
  198. package/dist/commands/crm-shared.d.ts.map +1 -0
  199. package/dist/commands/crm-shared.js +111 -0
  200. package/dist/commands/crm-shared.js.map +1 -0
  201. package/dist/commands/schedule.d.ts +3 -0
  202. package/dist/commands/schedule.d.ts.map +1 -0
  203. package/dist/commands/schedule.js +9 -0
  204. package/dist/commands/schedule.js.map +1 -0
  205. package/dist/commands/session.d.ts +18 -0
  206. package/dist/commands/session.d.ts.map +1 -0
  207. package/dist/commands/session.js +265 -0
  208. package/dist/commands/session.js.map +1 -0
  209. package/dist/commands/write.d.ts +14 -0
  210. package/dist/commands/write.d.ts.map +1 -0
  211. package/dist/commands/write.js +36 -0
  212. package/dist/commands/write.js.map +1 -0
  213. package/dist/config.d.ts +4 -0
  214. package/dist/config.d.ts.map +1 -0
  215. package/dist/config.js +29 -0
  216. package/dist/config.js.map +1 -0
  217. package/dist/context.d.ts +62 -0
  218. package/dist/context.d.ts.map +1 -0
  219. package/dist/context.js +97 -0
  220. package/dist/context.js.map +1 -0
  221. package/dist/crm/activities.d.ts +32 -0
  222. package/dist/crm/activities.d.ts.map +1 -0
  223. package/dist/crm/activities.js +196 -0
  224. package/dist/crm/activities.js.map +1 -0
  225. package/dist/crm/records.d.ts +20 -0
  226. package/dist/crm/records.d.ts.map +1 -0
  227. package/dist/crm/records.js +175 -0
  228. package/dist/crm/records.js.map +1 -0
  229. package/dist/crm/source.d.ts +41 -0
  230. package/dist/crm/source.d.ts.map +1 -0
  231. package/dist/crm/source.js +673 -0
  232. package/dist/crm/source.js.map +1 -0
  233. package/dist/crm/writer.d.ts +14 -0
  234. package/dist/crm/writer.d.ts.map +1 -0
  235. package/dist/crm/writer.js +247 -0
  236. package/dist/crm/writer.js.map +1 -0
  237. package/dist/identity.d.ts +7 -0
  238. package/dist/identity.d.ts.map +1 -0
  239. package/dist/identity.js +33 -0
  240. package/dist/identity.js.map +1 -0
  241. package/dist/index.d.ts +3 -0
  242. package/dist/index.d.ts.map +1 -0
  243. package/dist/index.js +3 -0
  244. package/dist/index.js.map +1 -0
  245. package/dist/program.d.ts +6 -0
  246. package/dist/program.d.ts.map +1 -0
  247. package/dist/program.js +91 -0
  248. package/dist/program.js.map +1 -0
  249. package/dist/reasons.d.ts +10 -0
  250. package/dist/reasons.d.ts.map +1 -0
  251. package/dist/reasons.js +35 -0
  252. package/dist/reasons.js.map +1 -0
  253. package/dist/sample/comments.d.ts +61 -0
  254. package/dist/sample/comments.d.ts.map +1 -0
  255. package/dist/sample/comments.js +39 -0
  256. package/dist/sample/comments.js.map +1 -0
  257. package/dist/sample/records.d.ts +16 -0
  258. package/dist/sample/records.d.ts.map +1 -0
  259. package/dist/sample/records.js +22 -0
  260. package/dist/sample/records.js.map +1 -0
  261. package/dist/sample/transport.d.ts +42 -0
  262. package/dist/sample/transport.d.ts.map +1 -0
  263. package/dist/sample/transport.js +153 -0
  264. package/dist/sample/transport.js.map +1 -0
  265. package/dist/setup/flow.d.ts +2 -0
  266. package/dist/setup/flow.d.ts.map +1 -0
  267. package/dist/setup/flow.js +127 -0
  268. package/dist/setup/flow.js.map +1 -0
  269. package/dist/setup/texts.en.json +25 -0
  270. package/dist/setup/texts.es.json +25 -0
  271. package/dist/setup/texts.ru.json +25 -0
  272. package/dist/store.d.ts +15 -0
  273. package/dist/store.d.ts.map +1 -0
  274. package/dist/store.js +16 -0
  275. package/dist/store.js.map +1 -0
  276. package/dist/version.d.ts +2 -0
  277. package/dist/version.d.ts.map +1 -0
  278. package/dist/version.js +2 -0
  279. package/dist/version.js.map +1 -0
  280. package/dist/wcat.d.ts +3 -0
  281. package/dist/wcat.d.ts.map +1 -0
  282. package/dist/wcat.js +4 -0
  283. package/dist/wcat.js.map +1 -0
  284. package/dist/whoami.d.ts +24 -0
  285. package/dist/whoami.d.ts.map +1 -0
  286. package/dist/whoami.js +33 -0
  287. package/dist/whoami.js.map +1 -0
  288. package/package.json +85 -4
  289. package/skills/amo-cli/SKILL.md +116 -0
  290. package/skills/amo-cli/references/mcp.md +38 -0
  291. package/skills/amo-cli/references/output.md +42 -0
  292. package/skills/amo-cli/references/reading.md +77 -0
  293. package/skills/amo-cli/references/setup.md +59 -0
  294. package/skills/amo-cli/references/writing.md +85 -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,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CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,MAAM,OAAO,CAAC,+BAA+B,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACzG,OAAO,GAAG,CAAC,MAAM,CAAA;AACnB,CAAC,CAAA;AAED,sHAAsH;AACtH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAiB,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AAEjF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAa,EAAE;IACxD,IAAI,KAAc,CAAA;IAClB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,KAAK,GAAG,SAAS,CAAA;IACnB,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QACzF,MAAM,IAAI,QAAQ,CAChB,qBAAqB,EACrB,0EAA0E,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,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC;IACvD,OAAO,EAAE;QACP,KAAK;QACL,qEAAqE;QACrE,gEAAgE;QAChE,wEAAwE;KACzE;CACO,CAAA;AAEV,kDAAkD;AAClD,MAAM,CAAC,MAAM,gBAAgB,GAA6B;IACxD;QACE,wGAAwG;QACxG,IAAI,EAAE,iCAAiC;QACvC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,gCAAgC;QACz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AA;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,24 @@
1
+ import { type Pacer, type TurnOptions } from "@wirecat/cli-core/sends";
2
+ export interface ProviderCallOptions<T> {
3
+ /** A write is tried again only on `rate_limited`, which a CRM answers before doing anything. */
4
+ write: boolean;
5
+ /** One HTTP exchange; it throws a cli-base `CliError` with a reason. */
6
+ send: () => Promise<T>;
7
+ /** The account's shared pace: each attempt waits its turn, and a refused rate holds it. */
8
+ pace?: {
9
+ pacer: Pacer;
10
+ } & TurnOptions;
11
+ /** One token refresh on `oauth.expired`; false gives up. A refused token did nothing, so a write goes again too. */
12
+ refresh?: () => Promise<boolean>;
13
+ /** Attempts after the first; 3 when absent. */
14
+ retries?: number;
15
+ /** Waits between attempts; a test or a cancellable run passes its own. */
16
+ sleep?: (ms: number) => Promise<void>;
17
+ random?: () => number;
18
+ }
19
+ /**
20
+ * One call to a CRM: paced, reads tried again on a retryable failure or a refused rate, a write only on a refused
21
+ * rate. A write that got no answer is `outcome_unknown` and is never sent again: a CRM may have carried it out.
22
+ */
23
+ export declare const providerCall: <T>(options: ProviderCallOptions<T>) => Promise<T>;
24
+ //# sourceMappingURL=call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.d.ts","sourceRoot":"","sources":["../../src/amo/call.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAe,MAAM,yBAAyB,CAAA;AAcnF,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,gGAAgG;IAChG,KAAK,EAAE,OAAO,CAAA;IACd,wEAAwE;IACxE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAA;IACtB,2FAA2F;IAC3F,IAAI,CAAC,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,GAAG,WAAW,CAAA;IACrC,oHAAoH;IACpH,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAChC,+CAA+C;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACrC,MAAM,CAAC,EAAE,MAAM,MAAM,CAAA;CACtB;AAKD;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,WAAW,mBAAmB,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAmChF,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { backoffMs, CliError, isCliError, realSleep } from "@wirecat/cli-base";
2
+ import { waitForTurn } from "@wirecat/cli-core/sends";
3
+ /*
4
+ * cli-core's `providerCall` as its phase-1 branch has it (cli-core feat/crm-shared-records, src/crm/provider-call.ts,
5
+ * not released yet): the same options, retries and refresh reason, so phase 4 swaps the import and nothing else.
6
+ */
7
+ const RETRY = { retries: 3, baseDelayMs: 1_000, maxDelayMs: 10_000, maxRetryAfterMs: 30_000 };
8
+ /**
9
+ * A write cut off by these, or answered with a body nobody can read, may have reached the CRM: only a refusal says it
10
+ * did not. A cancel while waiting for the turn is thrown before the try and stays `cancelled`.
11
+ */
12
+ const UNANSWERED = new Set(["timeout", "network_error", "provider_unavailable", "cancelled", "invalid_response"]);
13
+ const unanswered = (error) => !isCliError(error) || (UNANSWERED.has(error.code) && error.details.sent !== false);
14
+ /**
15
+ * One call to a CRM: paced, reads tried again on a retryable failure or a refused rate, a write only on a refused
16
+ * rate. A write that got no answer is `outcome_unknown` and is never sent again: a CRM may have carried it out.
17
+ */
18
+ export const providerCall = async (options) => {
19
+ const retries = options.retries ?? RETRY.retries;
20
+ const sleep = options.sleep ?? ((ms) => realSleep(ms));
21
+ let refreshed = false;
22
+ for (let attempt = 1;; attempt++) {
23
+ if (options.pace)
24
+ await waitForTurn(options.pace.pacer, options.pace);
25
+ try {
26
+ return await options.send();
27
+ }
28
+ catch (error) {
29
+ if (!refreshed &&
30
+ options.refresh &&
31
+ isCliError(error) &&
32
+ error.code === "authentication_error" &&
33
+ error.details.reason === "oauth.expired") {
34
+ refreshed = true;
35
+ if (await options.refresh())
36
+ continue;
37
+ throw error;
38
+ }
39
+ if (options.write && unanswered(error))
40
+ throw new CliError("outcome_unknown", `${error instanceof Error ? error.message : String(error)}; the CRM may or may not have carried it out`, { ...(isCliError(error) ? error.details : {}), retryable: false });
41
+ if (!isCliError(error))
42
+ throw error;
43
+ const asked = error.details.retry_after_ms;
44
+ const wait = typeof asked === "number" ? asked : backoffMs(attempt, RETRY, options.random ?? Math.random);
45
+ const again = error.code === "rate_limited" || (!options.write && error.details.retryable === true);
46
+ if (!again || wait > RETRY.maxRetryAfterMs || attempt > retries)
47
+ throw error;
48
+ if (error.code === "rate_limited")
49
+ await options.pace?.pacer.holdFor(wait);
50
+ await sleep(wait);
51
+ }
52
+ }
53
+ };
54
+ //# sourceMappingURL=call.js.map
@@ -0,0 +1 @@
1
+ {"version":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IAAI,GAAG,KAAK,CAAC,eAAe,IAAI,OAAO,GAAG,OAAO;gBAAE,MAAM,KAAK,CAAA;YAC5E,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc;gBAAE,MAAM,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YAC1E,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;AACH,CAAC,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,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAiB,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;AACpH,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export type Json = Record<string, unknown>;
2
+ export declare const isRecord: (value: unknown) => value is Json;
3
+ //# sourceMappingURL=json.d.ts.map
@@ -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"}
@@ -0,0 +1,3 @@
1
+ import { crmValues } from "@wirecat/cli-core/crm";
2
+ export const isRecord = crmValues.isRaw;
3
+ //# sourceMappingURL=json.js.map
@@ -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/oau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