@wirecat/amo-cli 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +15 -10
- package/contracts/wirecat.json +55 -6
- package/dist/amo/button.d.ts +53 -0
- package/dist/amo/button.d.ts.map +1 -0
- package/dist/amo/button.js +234 -0
- package/dist/amo/button.js.map +1 -0
- package/dist/amo/oauth.d.ts +12 -3
- package/dist/amo/oauth.d.ts.map +1 -1
- package/dist/amo/oauth.js +19 -6
- package/dist/amo/oauth.js.map +1 -1
- package/dist/bin/amo.js +2 -2
- package/dist/bundle/agent-FDNP27SW.js +40 -0
- package/dist/bundle/{all-profiles-3KQVWDV4.js → all-profiles-PPUN52SP.js} +63 -21
- package/dist/bundle/amo.js +28 -26
- package/dist/bundle/{anthropic-N5NOX7K7.js → anthropic-RDNDT6ZP.js} +5 -5
- package/dist/bundle/{app-server-2MST5EZ5.js → app-server-MMALJDBP.js} +79 -68
- package/dist/bundle/{bun-4NHWOFX2.js → bun-Y4FRPURU.js} +2 -2
- package/dist/bundle/{bun-sqlite-DRSXPWPR.js → bun-sqlite-7NXJGZCO.js} +6 -6
- package/dist/bundle/{chunk-GNTJMB6X.js → chunk-2YEDK2XV.js} +4 -4
- package/dist/bundle/chunk-3NDMVXGS.js +80 -0
- package/dist/bundle/{chunk-Y37A3232.js → chunk-3RP57VDS.js} +114 -7
- package/dist/bundle/{chunk-ODNQU7DH.js → chunk-3YOZTGZ6.js} +43 -64
- package/dist/bundle/{chunk-ESZSMZKT.js → chunk-4EYPFFTN.js} +2 -2
- package/dist/bundle/{chunk-TZSUZGWM.js → chunk-4MVTSMWP.js} +2 -2
- package/dist/bundle/{chunk-LJQUYECN.js → chunk-5DPMNYQT.js} +1 -1
- package/dist/bundle/{chunk-7PKFYX7V.js → chunk-5POLHHDZ.js} +8 -8
- package/dist/bundle/{chunk-A33TIM5D.js → chunk-5RXH35ZA.js} +225 -225
- package/dist/bundle/{chunk-BVMNXI53.js → chunk-77FP6AWC.js} +25 -25
- package/dist/bundle/{chunk-L6AFE73L.js → chunk-7E6QSIRQ.js} +1 -1
- package/dist/bundle/chunk-7SBAHYZW.js +734 -0
- package/dist/bundle/{chunk-GQ7VFIYM.js → chunk-7USADF2W.js} +23 -7
- package/dist/bundle/{chunk-AHJ4W2IL.js → chunk-7VSYOMEH.js} +2 -2
- package/dist/bundle/chunk-7Z6NYSAN.js +52 -0
- package/dist/bundle/chunk-AYR6FIXN.js +30 -0
- package/dist/bundle/{chunk-ADEWU4P4.js → chunk-B4ITT55D.js} +1 -1
- package/dist/bundle/{chunk-AUBB72VF.js → chunk-BKTLAXUK.js} +41 -10
- package/dist/bundle/{chunk-63F65DHU.js → chunk-BYVDMPLX.js} +2 -2
- package/dist/bundle/{chunk-V77XNPXG.js → chunk-CQ472K6W.js} +11 -11
- package/dist/bundle/{chunk-FKR3M62D.js → chunk-CUZISGWH.js} +13 -13
- package/dist/bundle/{chunk-LDEBZ3IX.js → chunk-D6UPCAPD.js} +1 -1
- package/dist/bundle/{chunk-P3WQRTYZ.js → chunk-E2DLRLJ5.js} +1 -1
- package/dist/bundle/{chunk-NJYAL3UW.js → chunk-EHULZEXQ.js} +1 -1
- package/dist/bundle/chunk-EKNP326Q.js +108 -0
- package/dist/bundle/{chunk-DJD7TBYG.js → chunk-ELJGALVX.js} +76 -74
- package/dist/bundle/{chunk-RPWAJYI6.js → chunk-FI2TP6TY.js} +3 -3
- package/dist/bundle/{chunk-CDY2NJFE.js → chunk-FPDTIQOK.js} +2 -2
- package/dist/bundle/{chunk-NC76INB2.js → chunk-FPIUFSWK.js} +3099 -2266
- package/dist/bundle/{chunk-SZ2V62HB.js → chunk-GCUFGDKE.js} +2 -2
- package/dist/bundle/{chunk-LRBPT7LQ.js → chunk-GKP7CKW2.js} +6 -6
- package/dist/bundle/chunk-H34RBRS3.js +209 -0
- package/dist/bundle/{chunk-O2UCU52O.js → chunk-HQH4YPO5.js} +134 -569
- package/dist/bundle/{chunk-TNUFLULO.js → chunk-I4QCJZW7.js} +8 -8
- package/dist/bundle/{chunk-DXGGCGRP.js → chunk-IDQ7BNCZ.js} +14 -14
- package/dist/bundle/{chunk-JMDLPBXK.js → chunk-IEAPNTHT.js} +17 -17
- package/dist/bundle/{chunk-XQL7FEF4.js → chunk-ILUREFWJ.js} +9 -9
- package/dist/bundle/{chunk-QRQYUHCZ.js → chunk-IYUWVMGP.js} +12 -12
- package/dist/bundle/chunk-JTFAG3BX.js +338 -0
- package/dist/bundle/{chunk-CHUKWON6.js → chunk-JZ2AITOE.js} +3 -3
- package/dist/bundle/{chunk-JR6TSMFX.js → chunk-KEOKH2OZ.js} +103 -70
- package/dist/bundle/{chunk-UMVRT7VQ.js → chunk-KKXF6TSS.js} +1 -1
- package/dist/bundle/{chunk-5E5R65CA.js → chunk-KTLCQ7GC.js} +2 -2
- package/dist/bundle/{chunk-QDMXZZG4.js → chunk-KZDBO2FT.js} +18 -8
- package/dist/bundle/{chunk-VX37MPTJ.js → chunk-L2ZQDTDU.js} +1 -1
- package/dist/bundle/{chunk-CUZRHF34.js → chunk-L3JDQNBC.js} +4 -4
- package/dist/bundle/{chunk-3IRJDH2U.js → chunk-L72UALL5.js} +2 -100
- package/dist/bundle/{chunk-XRTD2GCU.js → chunk-LOSOWTAZ.js} +19 -258
- package/dist/bundle/{chunk-LGQXGOPJ.js → chunk-LYRICHEK.js} +2 -2
- package/dist/bundle/{chunk-UBRREVLJ.js → chunk-MMOEAH5G.js} +2 -2
- package/dist/bundle/{chunk-EQ7A6NA6.js → chunk-MPXKBF37.js} +1 -1
- package/dist/bundle/{chunk-SMSTGO2G.js → chunk-MYMBPQPQ.js} +4 -4
- package/dist/bundle/chunk-N4A6E2LL.js +559 -0
- package/dist/bundle/{chunk-5HGGG3QO.js → chunk-NJ2LJKNH.js} +16 -3
- package/dist/bundle/{chunk-TGEQNS6G.js → chunk-OMH3WP7F.js} +1 -1
- package/dist/bundle/{chunk-ULXQ5MJM.js → chunk-ORFLQGWH.js} +4 -4
- package/dist/bundle/{chunk-DQV2IKCF.js → chunk-PFZ7WG2B.js} +10 -3
- package/dist/bundle/{chunk-5D4AEUVA.js → chunk-PL5P7UKW.js} +434 -1
- package/dist/bundle/{chunk-6RS7OYTD.js → chunk-Q2YVY7IR.js} +3 -3
- package/dist/bundle/{chunk-DOSJONCX.js → chunk-QHA33ZS6.js} +7 -7
- package/dist/bundle/{chunk-JH3UOHRE.js → chunk-QQT7WUR4.js} +4 -4
- package/dist/bundle/{chunk-EROSAUNP.js → chunk-R23DRW2T.js} +5 -5
- package/dist/bundle/{chunk-WCYCUTSK.js → chunk-SBQ5MFHM.js} +7 -7
- package/dist/bundle/{chunk-DAY6TSPF.js → chunk-SJYVKR54.js} +62 -50
- package/dist/bundle/{chunk-T2UDLX76.js → chunk-SJZ52MZE.js} +6 -6
- package/dist/bundle/{chunk-ZM7I52EP.js → chunk-T6D34X5S.js} +3 -4
- package/dist/bundle/{chunk-P5LYZRKW.js → chunk-TCDER3G7.js} +1586 -749
- package/dist/bundle/{chunk-2I5UVMLW.js → chunk-TWZF7VO6.js} +1726 -1159
- package/dist/bundle/{chunk-VVHRQ46X.js → chunk-UA7C57IB.js} +2 -2
- package/dist/bundle/{chunk-5SBLU7D7.js → chunk-UM6SDFB6.js} +1 -1
- package/dist/bundle/{chunk-7U5HJEPZ.js → chunk-UOPP6ORQ.js} +21 -19
- package/dist/bundle/{chunk-U7RLVJ34.js → chunk-UT3ODJMI.js} +4 -4
- package/dist/bundle/{chunk-7GTUZY7M.js → chunk-UZLT6VSP.js} +3 -3
- package/dist/bundle/{chunk-5RLUHTK6.js → chunk-V3ZWYMXT.js} +1 -1
- package/dist/bundle/{chunk-LSND5QYI.js → chunk-VD7HD25M.js} +9 -9
- package/dist/bundle/{chunk-PFO76YFP.js → chunk-VEGNZPQU.js} +18 -18
- package/dist/bundle/{chunk-5Z5PEEKP.js → chunk-VFU25P57.js} +4 -4
- package/dist/bundle/{chunk-4ZAK773N.js → chunk-VJHOBOJR.js} +3 -3
- package/dist/bundle/{chunk-PM77PRB6.js → chunk-VPBSZ4HQ.js} +185 -162
- package/dist/bundle/{chunk-Q2VNBY4Y.js → chunk-VY27K2SH.js} +746 -1205
- package/dist/bundle/{chunk-XEFAMLSD.js → chunk-W4KY5JF5.js} +3 -3
- package/dist/bundle/{chunk-73CXFE36.js → chunk-WBWVBEHH.js} +29 -1
- package/dist/bundle/{chunk-NHXJYS4R.js → chunk-XDT74W5P.js} +32 -28
- package/dist/bundle/{chunk-EPOV5UIO.js → chunk-XI75EKLG.js} +11 -11
- package/dist/bundle/{chunk-2B24PDH7.js → chunk-XM2G62YF.js} +8 -6
- package/dist/bundle/{chunk-5D4Z2B5B.js → chunk-YSOGGUK3.js} +9 -9
- package/dist/bundle/chunk-YVO2YGML.js +353 -0
- package/dist/bundle/{chunk-EQUKVVHX.js → chunk-ZIFEIJRK.js} +7 -7
- package/dist/bundle/{cli-QVWTXADI.js → cli-GAO7LDDA.js} +150 -103
- package/dist/bundle/command-contract-RLIBGIDT.js +39 -0
- package/dist/bundle/{command-server-entry-5VL5U5EE.js → command-server-entry-BCDJP7XE.js} +28 -28
- package/dist/bundle/{decode-SQ5WGNDX.js → decode-OY2GR442.js} +5 -5
- package/dist/bundle/{dispatch-LA4DFXJD.js → dispatch-JWEJCBTF.js} +8 -8
- package/dist/bundle/dist-PAKDDIBT.js +191 -0
- package/dist/bundle/{echarts-25Z3RINX.js → echarts-AHEPEA5P.js} +2 -2
- package/dist/bundle/{embed-BNOTNXMA.js → embed-RVSUV54Z.js} +6 -6
- package/dist/bundle/{embedder-BCUT7KKV.js → embedder-GRZXZUXR.js} +9 -9
- package/dist/bundle/{failure-PKAC6XCT.js → failure-DDCSR54L.js} +2 -2
- package/dist/bundle/{first-run-EO5K5GME.js → first-run-G3WI4DH4.js} +12 -12
- package/dist/bundle/first-screen-6MLCMW2U.js +39 -0
- package/dist/bundle/{instructions-VLM3QAYB.js → instructions-NWQC5IP4.js} +1 -1
- package/dist/bundle/{mcp-7ILNMJH5.js → mcp-KGWT6TGO.js} +2 -2
- package/dist/bundle/meeting-combined-SVTFVZNJ.js +24 -0
- package/dist/bundle/{meeting-model-GHMMUQ34.js → meeting-model-I6T5HIZ5.js} +11 -11
- package/dist/bundle/{meeting-semantic-BMP6323L.js → meeting-semantic-47UA5JBF.js} +6 -6
- package/dist/bundle/{node-CT3N3TNL.js → node-7VXN7F4B.js} +2 -2
- package/dist/bundle/{node-sqlite-MELD2SBX.js → node-sqlite-BSEON57L.js} +7 -7
- package/dist/bundle/{oauth-YBH5OKC2.js → oauth-V6UAT4YD.js} +8 -8
- package/dist/bundle/{open-WNSBWTAG.js → open-7LVAY7ZU.js} +5 -5
- package/dist/bundle/{openai-XSNMNLW6.js → openai-OIEH342H.js} +15 -15
- package/dist/bundle/{process-I2QKOMM7.js → process-PTUCNLZ7.js} +1 -1
- package/dist/bundle/{program-DV73CIGP.js → program-S5WY5IZP.js} +643 -852
- package/dist/bundle/{prompt-SOG4AKPM.js → prompt-7XWTEQ62.js} +5 -5
- package/dist/bundle/{recognize-WMQLWMXH.js → recognize-HGIAJXDR.js} +4 -4
- package/dist/bundle/{remote-4BTFOLFY.js → remote-X4SVEMHS.js} +9 -9
- package/dist/bundle/{rerank-LJ3TWRNV.js → rerank-QWM3DQMU.js} +7 -7
- package/dist/bundle/{serve-B6UANKXN.js → serve-VVG3TXYT.js} +10 -10
- package/dist/bundle/{server-YRH6GJ5Z.js → server-EHYK62BJ.js} +73 -61
- package/dist/bundle/server-WRPTBVNW.js +86 -0
- package/dist/bundle/source-YISMYLBQ.js +44 -0
- package/dist/bundle/{sqlite-runtime-R7QFWFE7.js → sqlite-runtime-MCKXDNYC.js} +6 -6
- package/dist/bundle/{state-DIJ5YUOE.js → state-MYNYQJCT.js} +6 -6
- package/dist/bundle/store-A7R2SZVD.js +34 -0
- package/dist/bundle/{store-MYTYDV6A.js → store-B7O3F3QB.js} +28 -21
- package/dist/bundle/{store-6WFWW7EC.js → store-FPIU2546.js} +24 -23
- package/dist/bundle/store-maintenance-command-D55FRTIK.js +73 -0
- package/dist/bundle/surface-3EX6IGHW.js +72 -0
- package/dist/bundle/writer-XDHZ54JD.js +46 -0
- package/dist/commands/session.d.ts +23 -0
- package/dist/commands/session.d.ts.map +1 -1
- package/dist/commands/session.js +115 -45
- package/dist/commands/session.js.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/identity.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +3 -1
- package/dist/program.js.map +1 -1
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +2 -0
- package/dist/reasons.js.map +1 -1
- package/dist/setup/flow.d.ts.map +1 -1
- package/dist/setup/flow.js +74 -4
- package/dist/setup/flow.js.map +1 -1
- package/dist/setup/texts.en.json +22 -1
- package/dist/setup/texts.es.json +22 -1
- package/dist/setup/texts.ru.json +22 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -3
- package/scenarios/first-sync.md +23 -0
- package/scenarios/keep-in-sync.md +18 -0
- package/scenarios/safe-agent-writes.md +21 -0
- package/skills/amo-cli/SKILL.md +1 -1
- package/skills/amo-cli/references/mcp.md +1 -1
- package/skills/amo-cli/references/setup.md +9 -3
- package/dist/bundle/command-contract-QBUQBXH7.js +0 -39
- package/dist/bundle/first-screen-GMN3T6RW.js +0 -39
- package/dist/bundle/meeting-combined-LAMF7S2B.js +0 -24
- package/dist/bundle/server-S6XD6V6E.js +0 -77
- package/dist/bundle/source-DGFTA2TN.js +0 -42
- package/dist/bundle/store-FJCNZULV.js +0 -32
- package/dist/bundle/store-maintenance-command-B5TMKFMG.js +0 -68
- package/dist/bundle/writer-GP7VIMAU.js +0 -44
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
Notable changes to `@wirecat/amo-cli`. One section per version, newest first.
|
|
4
4
|
|
|
5
|
+
## 0.3.0 — 23.11.2026
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **Sign in with one click: `amo <profile> session start --host https://<subdomain>.amocrm.ru --one-click`.** The
|
|
10
|
+
browser opens a page on connect.wirecat.dev, a WireCat server in Russia that amoCRM can reach. The person
|
|
11
|
+
chooses the account and clicks «Разрешить», and amoCRM creates a WireCat integration in it. Nobody copies an
|
|
12
|
+
integration ID, a secret key or a token. amoCRM sends the integration's secret key to connect.wirecat.dev, and `amo`
|
|
13
|
+
collects it once. `amo` exchanges the code only with the account `--host` names, and refuses one allowed in another
|
|
14
|
+
account. It keeps and renews the sign-in like `--client-id`. amoCRM lets only an account administrator allow it
|
|
15
|
+
([amoCRM: the button](https://www.amocrm.ru/developers/content/oauth/button)). amoCRM accounts only for now; Kommo
|
|
16
|
+
signs in with a token.
|
|
17
|
+
- **`amo setup` offers «Войти через amoCRM» first to an administrator,** with the token second. WireCat Desktop shows
|
|
18
|
+
the link to open, and waits until access is allowed.
|
|
19
|
+
- **`amo setup` asks whether you are an account administrator.** An administrator creates the integration as before.
|
|
20
|
+
A user who is not one gets the request to send an administrator for a long-lived token, a warning that the token
|
|
21
|
+
carries the administrator's rights, and, once connected, how to sync their own deals rather than the administrator's.
|
|
22
|
+
WireCat Desktop shows the same steps. The installation page has the same path under "If you are not an
|
|
23
|
+
administrator".
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **The shared CRM help no longer mentions leads or Bitrix24's fields.** amoCRM has no separate leads: `changes list`,
|
|
28
|
+
`search all` and the other shared commands now describe deals only.
|
|
29
|
+
- The setup and the installation page no longer say that anyone can sign in through the integration in the browser:
|
|
30
|
+
amoCRM's guide says it offers that sign-in only on accounts where the person is an administrator
|
|
31
|
+
([amoCRM: step by step](https://www.amocrm.ru/developers/content/oauth/step-by-step)).
|
|
32
|
+
|
|
33
|
+
## 0.2.0 — 19.11.2026
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- **`amo guide` lists scenarios for common tasks**, each as commands in order and why: the first sync and the pipeline
|
|
38
|
+
board, keeping the copy up to date, and letting an agent change the CRM without surprises.
|
|
39
|
+
- The README opens with the WireCat banner, and the installation page says how WireCat Desktop connects `amo`.
|
|
40
|
+
|
|
5
41
|
## 0.1.1 — 18.11.2026
|
|
6
42
|
|
|
7
43
|
### Fixed
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/WireCatLabs/amo-cli/main/docs/images/social-preview.png" alt="amoCRM and Kommo CLI for AI agents" width="100%">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# amo: amoCRM and Kommo CLI for AI agents
|
|
2
6
|
|
|
3
7
|
<p align="center">
|
|
@@ -73,23 +77,23 @@ and write notes by itself. In `amo` that takes `api call`, which you run yoursel
|
|
|
73
77
|
```sh
|
|
74
78
|
npm install -g @wirecat/amo-cli
|
|
75
79
|
amo skill install # the agent skill, for Claude Code, Codex, Gemini CLI and OpenClaw
|
|
76
|
-
amo work setup #
|
|
80
|
+
amo work setup # sign in with amoCRM in the browser, or paste a token
|
|
77
81
|
amo work sync # copy your deals and their clients
|
|
78
82
|
amo work deals list status:open
|
|
79
83
|
```
|
|
80
84
|
|
|
81
85
|
`work` is a profile, a name you choose for one account. It is the first word of every command that uses the account,
|
|
82
|
-
and none is ever assumed. `amo work setup`
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
a colleague's too, see
|
|
86
|
+
and none is ever assumed. `amo work setup` asks for the account's address. An administrator of an amoCRM account then
|
|
87
|
+
clicks **Sign in with amoCRM** and allows access in the browser. Otherwise it shows each click to make a private
|
|
88
|
+
integration and its long-lived token, checks them against the account and keeps the token in the system keyring. A
|
|
89
|
+
sync copies the deals assigned to the user the token belongs to. To copy a colleague's too, see
|
|
86
90
|
[which deals sync copies](https://github.com/WireCatLabs/amo-cli/blob/main/docs/configuration.md#which-deals-sync-copies).
|
|
87
91
|
|
|
88
92
|
You need Node.js 22.16 or a later 22.x, or Node.js 24 or later. `amo doctor` needs no network and shows what is set
|
|
89
93
|
up.
|
|
90
94
|
|
|
91
|
-
More: [install and connect](https://github.com/WireCatLabs/amo-cli/blob/main/docs/installation.md), with
|
|
92
|
-
sign
|
|
95
|
+
More: [install and connect](https://github.com/WireCatLabs/amo-cli/blob/main/docs/installation.md), with every way
|
|
96
|
+
to sign in.
|
|
93
97
|
|
|
94
98
|
## Use it with your agent
|
|
95
99
|
|
|
@@ -175,9 +179,10 @@ More: [WireCat](https://wirecat.dev)
|
|
|
175
179
|
|
|
176
180
|
## How it works
|
|
177
181
|
|
|
178
|
-
- **
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
- **Sign in with one click, or with a token.** An amoCRM administrator clicks amoCRM's button in the browser and
|
|
183
|
+
copies nothing: amoCRM creates WireCat's integration, `amo` acts with that person's rights and renews the sign-in
|
|
184
|
+
itself. A long-lived token works for Kommo and for users, with the rights of the administrator who made it. Either
|
|
185
|
+
is kept in your system keyring.
|
|
181
186
|
- **A copy of your share of the CRM.** `sync` copies the pipelines, the deals assigned to you and only the contacts and
|
|
182
187
|
companies on them. An administrator can choose colleagues too. No sync copies the whole CRM.
|
|
183
188
|
- **Staying current.** `amo work schedule command crm --every 1h -- sync` keeps the copy fresh with a timer.
|
package/contracts/wirecat.json
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"session",
|
|
33
33
|
"start"
|
|
34
34
|
],
|
|
35
|
-
"summary": "sign in
|
|
35
|
+
"summary": "sign in with one click, a long-lived token or your own integration",
|
|
36
36
|
"effects": {
|
|
37
37
|
"remote": "read",
|
|
38
38
|
"local": "write"
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"store",
|
|
115
115
|
"apply"
|
|
116
116
|
],
|
|
117
|
-
"summary": "apply scope mine to the contacts already stored: remove those no deal
|
|
117
|
+
"summary": "apply scope mine to the contacts already stored: remove those no deal of the…",
|
|
118
118
|
"effects": {
|
|
119
119
|
"remote": "none",
|
|
120
120
|
"local": "write"
|
|
@@ -557,7 +557,7 @@
|
|
|
557
557
|
"changes",
|
|
558
558
|
"list"
|
|
559
559
|
],
|
|
560
|
-
"summary": "deals
|
|
560
|
+
"summary": "deals made, moved, won, lost and given another owner, activities added and…",
|
|
561
561
|
"effects": {
|
|
562
562
|
"remote": "none",
|
|
563
563
|
"local": "read"
|
|
@@ -583,7 +583,7 @@
|
|
|
583
583
|
"search",
|
|
584
584
|
"all"
|
|
585
585
|
],
|
|
586
|
-
"summary": "search stored deals
|
|
586
|
+
"summary": "search stored deals, messages, notes, calendar events and meetings",
|
|
587
587
|
"effects": {
|
|
588
588
|
"remote": "none",
|
|
589
589
|
"local": "read"
|
|
@@ -630,7 +630,7 @@
|
|
|
630
630
|
"schedule",
|
|
631
631
|
"command"
|
|
632
632
|
],
|
|
633
|
-
"summary": "run amo <args…> on a timer — reads save what they read, so this is how
|
|
633
|
+
"summary": "run amo <args…> on a timer — reads save what they read, so this is how the…",
|
|
634
634
|
"effects": {
|
|
635
635
|
"remote": "none",
|
|
636
636
|
"local": "write"
|
|
@@ -804,6 +804,16 @@
|
|
|
804
804
|
"local": "read"
|
|
805
805
|
}
|
|
806
806
|
},
|
|
807
|
+
{
|
|
808
|
+
"path": [
|
|
809
|
+
"guide"
|
|
810
|
+
],
|
|
811
|
+
"summary": "scenarios: the commands for a common task, in order, and why each",
|
|
812
|
+
"effects": {
|
|
813
|
+
"remote": "none",
|
|
814
|
+
"local": "none"
|
|
815
|
+
}
|
|
816
|
+
},
|
|
807
817
|
{
|
|
808
818
|
"path": [
|
|
809
819
|
"mcp",
|
|
@@ -1195,6 +1205,7 @@
|
|
|
1195
1205
|
"*.amocrm.com",
|
|
1196
1206
|
"*.kommo.com",
|
|
1197
1207
|
"wirecat.dev",
|
|
1208
|
+
"connect.wirecat.dev",
|
|
1198
1209
|
"registry.npmjs.org",
|
|
1199
1210
|
"huggingface.co",
|
|
1200
1211
|
"*.huggingface.co",
|
|
@@ -1351,6 +1362,44 @@
|
|
|
1351
1362
|
"app": "amo-cli",
|
|
1352
1363
|
"env": "AMO"
|
|
1353
1364
|
},
|
|
1354
|
-
"settings": null
|
|
1365
|
+
"settings": null,
|
|
1366
|
+
"accountRemove": {
|
|
1367
|
+
"signOut": [
|
|
1368
|
+
"{profile}",
|
|
1369
|
+
"session",
|
|
1370
|
+
"end",
|
|
1371
|
+
"--record",
|
|
1372
|
+
"--json"
|
|
1373
|
+
],
|
|
1374
|
+
"remove": {
|
|
1375
|
+
"minVersion": "0.0.0",
|
|
1376
|
+
"keepData": [
|
|
1377
|
+
"{profile}",
|
|
1378
|
+
"account",
|
|
1379
|
+
"remove",
|
|
1380
|
+
"--keep-data",
|
|
1381
|
+
"--record",
|
|
1382
|
+
"--json"
|
|
1383
|
+
],
|
|
1384
|
+
"deleteData": [
|
|
1385
|
+
"{profile}",
|
|
1386
|
+
"account",
|
|
1387
|
+
"remove",
|
|
1388
|
+
"--delete-data",
|
|
1389
|
+
"--record",
|
|
1390
|
+
"--json"
|
|
1391
|
+
],
|
|
1392
|
+
"dryRun": "--dry-run",
|
|
1393
|
+
"confirm": "--yes"
|
|
1394
|
+
},
|
|
1395
|
+
"removes": [
|
|
1396
|
+
"signIn"
|
|
1397
|
+
],
|
|
1398
|
+
"keeps": [
|
|
1399
|
+
"settings",
|
|
1400
|
+
"data",
|
|
1401
|
+
"listed"
|
|
1402
|
+
]
|
|
1403
|
+
}
|
|
1355
1404
|
}
|
|
1356
1405
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type KeyringStore, type SleepLike } from "@wirecat/cli-base";
|
|
2
|
+
import { type OAuthClient } from "@wirecat/cli-core/oauth";
|
|
3
|
+
import { type AppAuth } from "./oauth.js";
|
|
4
|
+
export declare const CONNECT_VARIABLE: string;
|
|
5
|
+
/** The button page and the claim endpoint; a test moves both to one fake origin, keeping their paths. */
|
|
6
|
+
export declare const connectUrls: (env: NodeJS.ProcessEnv) => {
|
|
7
|
+
page: string;
|
|
8
|
+
claim: string;
|
|
9
|
+
};
|
|
10
|
+
/** Kommo's button is not checked yet, so a guess could create an integration amo then cannot finish. */
|
|
11
|
+
export declare const refuseKommo: (origin: string) => void;
|
|
12
|
+
export interface BrowserSteps {
|
|
13
|
+
openBrowser: (url: string) => Promise<void>;
|
|
14
|
+
showUrl: (url: string) => void;
|
|
15
|
+
readPaste?: (signal: AbortSignal) => Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
interface ClaimOptions {
|
|
18
|
+
claim: string;
|
|
19
|
+
state: string;
|
|
20
|
+
fetch?: typeof fetch | undefined;
|
|
21
|
+
sleep: SleepLike;
|
|
22
|
+
now: () => number;
|
|
23
|
+
signal?: AbortSignal | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The keys amoCRM posted to the claim server for this `state`, read once. A 404 `not_ready` means the webhook has not come
|
|
27
|
+
* yet. No failure quotes the answer: a body may hold the secret.
|
|
28
|
+
*/
|
|
29
|
+
export declare const claimKeys: (options: ClaimOptions) => Promise<OAuthClient>;
|
|
30
|
+
export interface BrowserSignInOptions<T> {
|
|
31
|
+
env: NodeJS.ProcessEnv;
|
|
32
|
+
profile: string;
|
|
33
|
+
origin: string;
|
|
34
|
+
storage: "keyring" | "file";
|
|
35
|
+
keyring?: KeyringStore | undefined;
|
|
36
|
+
fetch?: typeof fetch | undefined;
|
|
37
|
+
sleep: SleepLike;
|
|
38
|
+
now: () => number;
|
|
39
|
+
signal?: AbortSignal | undefined;
|
|
40
|
+
steps: BrowserSteps;
|
|
41
|
+
/** Whose rights the new tokens carry, asked of the account before anything is kept. */
|
|
42
|
+
check: (auth: AppAuth) => Promise<T>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* amoCRM's button on the connect page creates an integration in the account the person picks and posts its keys to
|
|
46
|
+
* the claim server; amo claims them once, exchanges the code on the account `--host` names and keeps it all as a
|
|
47
|
+
* `--client-id` sign-in, marked so a failed renewal names this command.
|
|
48
|
+
*/
|
|
49
|
+
export declare const browserSignIn: <T extends {
|
|
50
|
+
id: string;
|
|
51
|
+
}>(options: BrowserSignInOptions<T>) => Promise<T>;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../src/amo/button.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE3F,OAAO,EAAE,KAAK,WAAW,EAAe,MAAM,yBAAyB,CAAA;AAGvE,OAAO,EACL,KAAK,OAAO,EAQb,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,gBAAgB,QAAsC,CAAA;AASnE,yGAAyG;AACzG,eAAO,MAAM,WAAW,QAAS,MAAM,CAAC,UAAU,KAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAoBjF,CAAA;AAED,wGAAwG;AACxG,eAAO,MAAM,WAAW,WAAY,MAAM,SAQzC,CAAA;AAQD,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3C,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACrD;AAoGD,UAAU,YAAY;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,CAAA;IAChC,KAAK,EAAE,SAAS,CAAA;IAChB,GAAG,EAAE,MAAM,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;CACjC;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,YAAmB,YAAY,KAAG,OAAO,CAAC,WAAW,CAkD1E,CAAA;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,SAAS,GAAG,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,CAAA;IAChC,KAAK,EAAE,SAAS,CAAA;IAChB,GAAG,EAAE,MAAM,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;IAChC,KAAK,EAAE,YAAY,CAAA;IACnB,uFAAuF;IACvF,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CACrC;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAU,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,WAAW,oBAAoB,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CA0CzG,CAAA"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { createServer } from "node:http";
|
|
3
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
4
|
+
import { hostFetch } from "@wirecat/cli-base/http";
|
|
5
|
+
import { tokenKeeper } from "@wirecat/cli-core/oauth";
|
|
6
|
+
import { IDENTITY } from "../identity.js";
|
|
7
|
+
import { isRecord } from "./json.js";
|
|
8
|
+
import { appProvider, appStorage, BUTTON_RELAY_URL, CLAIM_URL, CONNECT_PAGE_URL, fetchFor, lockDirOf, } from "./oauth.js";
|
|
9
|
+
export const CONNECT_VARIABLE = `${IDENTITY.envPrefix}_CONNECT_URL`;
|
|
10
|
+
/** The claim server keeps the integration's keys 10 minutes; a wait longer than that could never be claimed. */
|
|
11
|
+
const CALLBACK_MS = 600_000;
|
|
12
|
+
/** amoCRM posts the keys before it redirects (oauth/button), so a minute covers a slow webhook. */
|
|
13
|
+
const CLAIM_MS = 60_000;
|
|
14
|
+
const CLAIM_PAUSES_MS = [500, 1000, 2000, 4000];
|
|
15
|
+
const REQUEST_MS = 30_000;
|
|
16
|
+
const AMOCRM_HOST = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.amocrm\.ru$/;
|
|
17
|
+
/** The button page and the claim endpoint; a test moves both to one fake origin, keeping their paths. */
|
|
18
|
+
export const connectUrls = (env) => {
|
|
19
|
+
const given = env[CONNECT_VARIABLE]?.trim();
|
|
20
|
+
if (!given)
|
|
21
|
+
return { page: CONNECT_PAGE_URL, claim: CLAIM_URL };
|
|
22
|
+
let url;
|
|
23
|
+
try {
|
|
24
|
+
url = new URL(given);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
url = undefined;
|
|
28
|
+
}
|
|
29
|
+
if (url?.protocol !== "https:" || url.username || url.password)
|
|
30
|
+
throw new CliError("configuration_error", `${CONNECT_VARIABLE} must be an https address, such as https://connect.wirecat.dev`, {
|
|
31
|
+
reason: "connect.url-invalid",
|
|
32
|
+
});
|
|
33
|
+
const { origin } = url;
|
|
34
|
+
const moved = (address) => `${origin}${new URL(address).pathname}`;
|
|
35
|
+
return { page: moved(CONNECT_PAGE_URL), claim: moved(CLAIM_URL) };
|
|
36
|
+
};
|
|
37
|
+
/** Kommo's button is not checked yet, so a guess could create an integration amo then cannot finish. */
|
|
38
|
+
export const refuseKommo = (origin) => {
|
|
39
|
+
if (AMOCRM_HOST.test(new URL(origin).hostname))
|
|
40
|
+
return;
|
|
41
|
+
throw new CliError("validation_error", "the browser sign-in works only for amoCRM accounts at amocrm.ru for now; sign in to Kommo with a long-lived " +
|
|
42
|
+
"token or --client-id", { reason: "oauth.browser-amocrm-only", param: "--host" });
|
|
43
|
+
};
|
|
44
|
+
const queryOf = (text) => {
|
|
45
|
+
const trimmed = text.trim();
|
|
46
|
+
const start = trimmed.indexOf("?");
|
|
47
|
+
return new URLSearchParams(start >= 0 ? trimmed.slice(start + 1).split("#")[0] : trimmed);
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* The local port the relay page sends amoCRM's redirect to. cli-core's `authorize` cannot serve here: it needs the
|
|
51
|
+
* integration before the browser opens, puts `state` in the query and answers only the code, not amoCRM's `referer`.
|
|
52
|
+
*/
|
|
53
|
+
const awaitRedirect = async (open, steps, signal) => {
|
|
54
|
+
if (signal?.aborted)
|
|
55
|
+
throw new CliError("cancelled", "the amoCRM sign-in was cancelled");
|
|
56
|
+
const paste = new AbortController();
|
|
57
|
+
let state = "";
|
|
58
|
+
let settled = false;
|
|
59
|
+
let accept = () => { };
|
|
60
|
+
let fail = () => { };
|
|
61
|
+
const redirect = new Promise((resolve, reject) => {
|
|
62
|
+
accept = (query) => {
|
|
63
|
+
settled = true;
|
|
64
|
+
resolve(query);
|
|
65
|
+
};
|
|
66
|
+
fail = (error) => {
|
|
67
|
+
settled = true;
|
|
68
|
+
reject(error);
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
void redirect.catch(() => { });
|
|
72
|
+
const handler = (request, response) => {
|
|
73
|
+
const url = new URL(request.url ?? "/", "http://localhost");
|
|
74
|
+
if (request.method !== "GET" || url.pathname !== "/callback")
|
|
75
|
+
return void response.writeHead(404).end();
|
|
76
|
+
if (settled || !state || url.searchParams.get("state") !== state)
|
|
77
|
+
return void response.writeHead(400).end("This sign-in link does not belong to the waiting sign-in");
|
|
78
|
+
response.end("Sign-in received; you can close this tab");
|
|
79
|
+
accept(url.searchParams);
|
|
80
|
+
};
|
|
81
|
+
const server = createServer(handler);
|
|
82
|
+
const onAbort = () => fail(new CliError("cancelled", "the amoCRM sign-in was cancelled"));
|
|
83
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
84
|
+
const timer = setTimeout(() => fail(new CliError("timeout", "the amoCRM sign-in timed out", { reason: "oauth.timeout" })), CALLBACK_MS);
|
|
85
|
+
timer.unref();
|
|
86
|
+
try {
|
|
87
|
+
await new Promise((resolve, reject) => {
|
|
88
|
+
server.once("error", reject);
|
|
89
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
90
|
+
});
|
|
91
|
+
const address = server.address();
|
|
92
|
+
if (!address || typeof address === "string")
|
|
93
|
+
throw new CliError("configuration_error", "could not start the local sign-in listener");
|
|
94
|
+
// The relay page reads the port from the front of `state` (cli-docs amo-callback.html).
|
|
95
|
+
state = `${address.port}.${randomBytes(32).toString("base64url")}`;
|
|
96
|
+
const url = open(state);
|
|
97
|
+
steps.showUrl(url);
|
|
98
|
+
steps
|
|
99
|
+
.readPaste?.(paste.signal)
|
|
100
|
+
.then((text) => {
|
|
101
|
+
if (settled)
|
|
102
|
+
return;
|
|
103
|
+
const query = queryOf(text);
|
|
104
|
+
if (query.get("state") !== state)
|
|
105
|
+
fail(new CliError("authentication_error", "the pasted sign-in result does not match this sign-in", {
|
|
106
|
+
reason: "oauth.mismatch",
|
|
107
|
+
}));
|
|
108
|
+
else
|
|
109
|
+
accept(query);
|
|
110
|
+
})
|
|
111
|
+
.catch(() => { });
|
|
112
|
+
void Promise.resolve()
|
|
113
|
+
.then(() => steps.openBrowser(url))
|
|
114
|
+
.catch(() => { });
|
|
115
|
+
return { state, query: await redirect };
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
signal?.removeEventListener("abort", onAbort);
|
|
120
|
+
paste.abort();
|
|
121
|
+
server.closeAllConnections();
|
|
122
|
+
if (server.listening)
|
|
123
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/** amoCRM names the account the person allowed access in; the code and the keys belong to that one. */
|
|
127
|
+
const refuseOtherAccount = (origin, query) => {
|
|
128
|
+
const given = (query.get("referer") ?? "").trim().toLowerCase();
|
|
129
|
+
const host = given.replace(/^https?:\/\//, "").replace(/\/.*$/, "");
|
|
130
|
+
const expected = new URL(origin).hostname;
|
|
131
|
+
if (host === expected)
|
|
132
|
+
return;
|
|
133
|
+
const named = AMOCRM_HOST.test(host) ? host : undefined;
|
|
134
|
+
throw new CliError("authentication_error", named
|
|
135
|
+
? `access was allowed in ${named}, not in ${expected}; run this again with --host https://${named}, or choose ` +
|
|
136
|
+
`${expected} in amoCRM's window`
|
|
137
|
+
: `amoCRM did not say which account access was allowed in, so nothing was sent to ${expected}; run this again`, { reason: "oauth.mismatch", ...(named ? { account: named } : {}) });
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The keys amoCRM posted to the claim server for this `state`, read once. A 404 `not_ready` means the webhook has not come
|
|
141
|
+
* yet. No failure quotes the answer: a body may hold the secret.
|
|
142
|
+
*/
|
|
143
|
+
export const claimKeys = async (options) => {
|
|
144
|
+
const host = new URL(options.claim).hostname;
|
|
145
|
+
const request = hostFetch({
|
|
146
|
+
hosts: [host],
|
|
147
|
+
timeoutMs: REQUEST_MS,
|
|
148
|
+
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
149
|
+
});
|
|
150
|
+
const again = "start the browser sign-in again";
|
|
151
|
+
const deadline = options.now() + CLAIM_MS;
|
|
152
|
+
for (let attempt = 0;; attempt += 1) {
|
|
153
|
+
let response;
|
|
154
|
+
try {
|
|
155
|
+
response = await request(options.claim, {
|
|
156
|
+
method: "POST",
|
|
157
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
158
|
+
body: JSON.stringify({ state: options.state }),
|
|
159
|
+
redirect: "error",
|
|
160
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (options.signal?.aborted)
|
|
165
|
+
throw new CliError("cancelled", "the amoCRM sign-in was cancelled");
|
|
166
|
+
if (isCliError(error))
|
|
167
|
+
throw error;
|
|
168
|
+
throw new CliError("provider_unavailable", `could not reach ${host} for the integration's keys; ${again}`, {
|
|
169
|
+
retryable: true,
|
|
170
|
+
reason: "oauth.unavailable",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const answer = await response.json().catch(() => undefined);
|
|
174
|
+
if (response.ok) {
|
|
175
|
+
const id = isRecord(answer) ? answer.client_id : undefined;
|
|
176
|
+
const secret = isRecord(answer) ? answer.client_secret : undefined;
|
|
177
|
+
if (typeof id !== "string" || !id || typeof secret !== "string" || !secret)
|
|
178
|
+
throw new CliError("invalid_response", `${host} returned keys amo cannot use; ${again}`, {
|
|
179
|
+
reason: "oauth.invalid-response",
|
|
180
|
+
});
|
|
181
|
+
return { clientId: id, clientSecret: secret };
|
|
182
|
+
}
|
|
183
|
+
const notReady = response.status === 404 && isRecord(answer) && answer.error === "not_ready";
|
|
184
|
+
if (!notReady)
|
|
185
|
+
throw new CliError("provider_unavailable", `${host} did not hand over the integration's keys (HTTP ${response.status}); ${again}`, { status: response.status, reason: "oauth.unavailable" });
|
|
186
|
+
if (options.now() >= deadline)
|
|
187
|
+
throw new CliError("timeout", `amoCRM did not send the integration's keys to ${host} within a minute; ${again}`, {
|
|
188
|
+
reason: "oauth.timeout",
|
|
189
|
+
});
|
|
190
|
+
await options.sleep(CLAIM_PAUSES_MS[Math.min(attempt, CLAIM_PAUSES_MS.length - 1)] ?? 4000, options.signal, "retry");
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* amoCRM's button on the connect page creates an integration in the account the person picks and posts its keys to
|
|
195
|
+
* the claim server; amo claims them once, exchanges the code on the account `--host` names and keeps it all as a
|
|
196
|
+
* `--client-id` sign-in, marked so a failed renewal names this command.
|
|
197
|
+
*/
|
|
198
|
+
export const browserSignIn = async (options) => {
|
|
199
|
+
const { origin } = options;
|
|
200
|
+
refuseKommo(origin);
|
|
201
|
+
const connect = connectUrls(options.env);
|
|
202
|
+
const storage = appStorage(options.env, options.profile, options.keyring, options.storage === "file" ? "file" : "auto");
|
|
203
|
+
storage.probe();
|
|
204
|
+
const { state, query } = await awaitRedirect((made) => `${connect.page}#state=${made}`, options.steps, options.signal);
|
|
205
|
+
if (!query.get("code"))
|
|
206
|
+
throw new CliError("authentication_error", "amoCRM sign-in was declined", { reason: "oauth.declined" });
|
|
207
|
+
refuseOtherAccount(origin, query);
|
|
208
|
+
const client = await claimKeys({
|
|
209
|
+
claim: connect.claim,
|
|
210
|
+
state,
|
|
211
|
+
fetch: options.fetch,
|
|
212
|
+
sleep: options.sleep,
|
|
213
|
+
now: options.now,
|
|
214
|
+
signal: options.signal,
|
|
215
|
+
});
|
|
216
|
+
const signInCommand = `${IDENTITY.command} ${options.profile} session start --host ${origin} --one-click`;
|
|
217
|
+
const provider = appProvider(origin, client, BUTTON_RELAY_URL);
|
|
218
|
+
const fetch = fetchFor(origin, options.fetch);
|
|
219
|
+
const tokens = await provider.exchange?.({ grant_type: "authorization_code", code: query.get("code") ?? "" }, { fetch, client, now: Date.now, signInCommand, ...(options.signal ? { signal: options.signal } : {}) });
|
|
220
|
+
if (!tokens)
|
|
221
|
+
throw new CliError("authentication_error", "amoCRM did not answer the sign-in");
|
|
222
|
+
const access = tokens.accessToken ?? "";
|
|
223
|
+
const user = await options.check({ origin, userId: "", accessToken: async () => access });
|
|
224
|
+
// The keeper keeps a saved entry's own client over a new one, and this sign-in brings a new integration.
|
|
225
|
+
storage.remove();
|
|
226
|
+
await tokenKeeper({ provider, storage, lockDir: lockDirOf(options.env), fetch, signInCommand }).save(tokens, {
|
|
227
|
+
host: origin,
|
|
228
|
+
userId: user.id,
|
|
229
|
+
redirectUri: BUTTON_RELAY_URL,
|
|
230
|
+
browser: true,
|
|
231
|
+
});
|
|
232
|
+
return user;
|
|
233
|
+
};
|
|
234
|
+
//# sourceMappingURL=button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.js","sourceRoot":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,MAAM,EAAE;QAC3G,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,WAAW,EAAE,gBAAgB;QAC7B,OAAO,EAAE,IAAI;KACd,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
package/dist/amo/oauth.d.ts
CHANGED
|
@@ -2,11 +2,17 @@ import { type CredentialStorage, type KeyringStore } from "@wirecat/cli-base";
|
|
|
2
2
|
import { type OAuthClient, type OAuthProvider, type SignInOptions as SignInSteps, type TokenCodec, type TokenStorage } from "@wirecat/cli-core/oauth";
|
|
3
3
|
export declare const PROVIDER = "amocrm";
|
|
4
4
|
/**
|
|
5
|
-
* The
|
|
6
|
-
* oauth/step-by-step). The static page forwards any `code` and `state` to the
|
|
7
|
-
* public/webhooks/apps/amo-callback.html).
|
|
5
|
+
* The Redirect URI of an integration the owner creates for `--client-id`, which amoCRM sends the browser to with
|
|
6
|
+
* `code` and `state` (amocrm.ru developers oauth/step-by-step). The static page forwards any `code` and `state` to the
|
|
7
|
+
* waiting local port (cli-docs public/webhooks/apps/amo-callback.html).
|
|
8
8
|
*/
|
|
9
9
|
export declare const RELAY_URL = "https://wirecat.dev/webhooks/apps/amo-callback";
|
|
10
|
+
/** The Redirect URI amoCRM's button gives the integration it creates; the same page as RELAY_URL, on that server. */
|
|
11
|
+
export declare const BUTTON_RELAY_URL = "https://connect.wirecat.dev/webhooks/apps/amo-callback";
|
|
12
|
+
/** The page with amoCRM's button, which reads `state` from the fragment (cli-docs services/amo-connect). */
|
|
13
|
+
export declare const CONNECT_PAGE_URL = "https://connect.wirecat.dev/connect/amo.html";
|
|
14
|
+
/** Hands over once the keys amoCRM posted for a `state`. */
|
|
15
|
+
export declare const CLAIM_URL = "https://connect.wirecat.dev/api/amo/claim";
|
|
10
16
|
/** A sign-in through the owner's own integration: the account, the user whose rights it carries, and the token. */
|
|
11
17
|
export interface AppAuth {
|
|
12
18
|
origin: string;
|
|
@@ -18,11 +24,14 @@ export interface AppAuth {
|
|
|
18
24
|
* amoCRM refuses one that differs from the integration's setting (oauth/step-by-step).
|
|
19
25
|
*/
|
|
20
26
|
export declare const appCodec: TokenCodec;
|
|
27
|
+
/** The folder cli-core's sign-in lock lives in, beside the config. */
|
|
28
|
+
export declare const lockDirOf: (env: NodeJS.ProcessEnv) => string;
|
|
21
29
|
/** The same service, folder and moved-run rule as the long-lived token's `ProfileTokenStore`, under `oauth:amocrm:<profile>`. */
|
|
22
30
|
export declare const appStorage: (env: NodeJS.ProcessEnv, profile: string, keyring?: KeyringStore, storage?: CredentialStorage) => TokenStorage;
|
|
23
31
|
/** Where the integration's sign-in is kept, `keyring` or `file`, and never what. */
|
|
24
32
|
export declare const appSourceOf: (env: NodeJS.ProcessEnv, profile: string, keyring?: KeyringStore) => import("@wirecat/cli-base").CredentialSource | undefined;
|
|
25
33
|
export declare const appProvider: (origin: string, client: OAuthClient, redirectUri?: string) => OAuthProvider;
|
|
34
|
+
export declare const fetchFor: (origin: string, given?: typeof fetch) => import("@wirecat/cli-base/http").FetchLike;
|
|
26
35
|
export interface AppSignInOptions<T> {
|
|
27
36
|
env: NodeJS.ProcessEnv;
|
|
28
37
|
profile: string;
|
package/dist/amo/oauth.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sour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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,SAsBb,CAAA"}
|
package/dist/amo/oauth.js
CHANGED
|
@@ -6,11 +6,22 @@ import { accountOrigin } from "./account.js";
|
|
|
6
6
|
import { isRecord } from "./json.js";
|
|
7
7
|
export const PROVIDER = "amocrm";
|
|
8
8
|
/**
|
|
9
|
-
* The
|
|
10
|
-
* oauth/step-by-step). The static page forwards any `code` and `state` to the
|
|
11
|
-
* public/webhooks/apps/amo-callback.html).
|
|
9
|
+
* The Redirect URI of an integration the owner creates for `--client-id`, which amoCRM sends the browser to with
|
|
10
|
+
* `code` and `state` (amocrm.ru developers oauth/step-by-step). The static page forwards any `code` and `state` to the
|
|
11
|
+
* waiting local port (cli-docs public/webhooks/apps/amo-callback.html).
|
|
12
12
|
*/
|
|
13
13
|
export const RELAY_URL = "https://wirecat.dev/webhooks/apps/amo-callback";
|
|
14
|
+
/**
|
|
15
|
+
* The one-click sign-in runs on connect.wirecat.dev, a server in Russia (cli-docs services/amo-connect): amoCRM's
|
|
16
|
+
* servers post the new integration's keys from Russia, where Cloudflare, which serves wirecat.dev, is blocked.
|
|
17
|
+
*/
|
|
18
|
+
const CONNECT_ORIGIN = "https://connect.wirecat.dev";
|
|
19
|
+
/** The Redirect URI amoCRM's button gives the integration it creates; the same page as RELAY_URL, on that server. */
|
|
20
|
+
export const BUTTON_RELAY_URL = `${CONNECT_ORIGIN}/webhooks/apps/amo-callback`;
|
|
21
|
+
/** The page with amoCRM's button, which reads `state` from the fragment (cli-docs services/amo-connect). */
|
|
22
|
+
export const CONNECT_PAGE_URL = `${CONNECT_ORIGIN}/connect/amo.html`;
|
|
23
|
+
/** Hands over once the keys amoCRM posted for a `state`. */
|
|
24
|
+
export const CLAIM_URL = `${CONNECT_ORIGIN}/api/amo/claim`;
|
|
14
25
|
const REQUEST_MS = 30_000;
|
|
15
26
|
const HINT = /^[\w .,:'`-]{1,200}$/;
|
|
16
27
|
const account = accountTokenCodec(PROVIDER);
|
|
@@ -25,10 +36,12 @@ export const appCodec = {
|
|
|
25
36
|
const stored = account.decode(raw);
|
|
26
37
|
const entry = JSON.parse(raw);
|
|
27
38
|
const redirectUri = isRecord(entry) && typeof entry.redirectUri === "string" ? entry.redirectUri : RELAY_URL;
|
|
28
|
-
return Object.assign(stored, { redirectUri });
|
|
39
|
+
return Object.assign(stored, { redirectUri, browser: isRecord(entry) && entry.browser === true });
|
|
29
40
|
},
|
|
30
41
|
};
|
|
31
42
|
const paths = (env) => resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env });
|
|
43
|
+
/** The folder cli-core's sign-in lock lives in, beside the config. */
|
|
44
|
+
export const lockDirOf = (env) => paths(env).config;
|
|
32
45
|
const credentialsOf = (env, keyring, storage) => ({
|
|
33
46
|
configDir: paths(env).config,
|
|
34
47
|
service: IDENTITY.appName,
|
|
@@ -136,7 +149,7 @@ export const appProvider = (origin, client, redirectUri = RELAY_URL) => ({
|
|
|
136
149
|
authorizeParams: { mode: "post_message" },
|
|
137
150
|
exchange: (params, context) => exchange(origin, redirectUri, params, context),
|
|
138
151
|
});
|
|
139
|
-
const fetchFor = (origin, given) => given ?? hostFetch({ hosts: [new URL(origin).hostname], timeoutMs: REQUEST_MS });
|
|
152
|
+
export const fetchFor = (origin, given) => given ?? hostFetch({ hosts: [new URL(origin).hostname], timeoutMs: REQUEST_MS });
|
|
140
153
|
/**
|
|
141
154
|
* The integration's sign-in: authorize in the browser, exchange the code on the account the owner named, ask that
|
|
142
155
|
* account who it is, then keep it. A code from another account fails there, before anything is saved.
|
|
@@ -181,7 +194,7 @@ export const appAuthOf = (options) => {
|
|
|
181
194
|
storage,
|
|
182
195
|
lockDir: paths(options.env).config,
|
|
183
196
|
fetch: fetchFor(origin, options.fetch),
|
|
184
|
-
signInCommand: `${IDENTITY.command} ${options.profile} session start --host ${origin} --client-id ${stored.client.clientId}`,
|
|
197
|
+
signInCommand: `${IDENTITY.command} ${options.profile} session start --host ${origin} ${stored.browser ? "--one-click" : `--client-id ${stored.client.clientId}`}`,
|
|
185
198
|
...(options.signal ? { signal: options.signal } : {}),
|
|
186
199
|
});
|
|
187
200
|
return { origin, userId: stored.account.userId, accessToken: (refresh) => keeper.accessToken({ refresh }) };
|