@wirecat/hubspot-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 (269) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +204 -0
  3. package/README.md +256 -2
  4. package/contracts/wirecat.json +1965 -0
  5. package/dist/bin/hubspot.d.ts +3 -0
  6. package/dist/bin/hubspot.d.ts.map +1 -0
  7. package/dist/bin/hubspot.js +40 -0
  8. package/dist/bin/hubspot.js.map +1 -0
  9. package/dist/bundle/all-profiles-64JAUYW4.js +279 -0
  10. package/dist/bundle/anthropic-VJOS4OUM.js +91 -0
  11. package/dist/bundle/app-server-422MCA7S.js +245 -0
  12. package/dist/bundle/bun-M3J2QTR3.js +169 -0
  13. package/dist/bundle/bun-sqlite-IX3XYA5F.js +76 -0
  14. package/dist/bundle/chunk-24ERVFJP.js +73 -0
  15. package/dist/bundle/chunk-2QZK5BEP.js +392 -0
  16. package/dist/bundle/chunk-2TWQIWWG.js +1328 -0
  17. package/dist/bundle/chunk-2VGD63G6.js +604 -0
  18. package/dist/bundle/chunk-2VGZRYEH.js +334 -0
  19. package/dist/bundle/chunk-36ITRDYY.js +63116 -0
  20. package/dist/bundle/chunk-43EKCUBJ.js +72 -0
  21. package/dist/bundle/chunk-4W6BMH45.js +731 -0
  22. package/dist/bundle/chunk-5A6ZYNAQ.js +2003 -0
  23. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  24. package/dist/bundle/chunk-5GBUCHRU.js +274 -0
  25. package/dist/bundle/chunk-5K7QLJMM.js +4072 -0
  26. package/dist/bundle/chunk-65TWQ7BV.js +54 -0
  27. package/dist/bundle/chunk-7ELMWE3P.js +12066 -0
  28. package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
  29. package/dist/bundle/chunk-B3MANLNK.js +602 -0
  30. package/dist/bundle/chunk-BKXDHU3G.js +1395 -0
  31. package/dist/bundle/chunk-C32AKHTY.js +2310 -0
  32. package/dist/bundle/chunk-CLAN3FES.js +1246 -0
  33. package/dist/bundle/chunk-CWXOXIWS.js +46 -0
  34. package/dist/bundle/chunk-D72URWJE.js +532 -0
  35. package/dist/bundle/chunk-DB2XKHI4.js +72 -0
  36. package/dist/bundle/chunk-DBEQI5YM.js +100 -0
  37. package/dist/bundle/chunk-DFCHHR5M.js +38 -0
  38. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  39. package/dist/bundle/chunk-DRWWJLI6.js +188 -0
  40. package/dist/bundle/chunk-DSP36YHQ.js +29 -0
  41. package/dist/bundle/chunk-E52JAS35.js +1028 -0
  42. package/dist/bundle/chunk-E5WLE7BM.js +78 -0
  43. package/dist/bundle/chunk-ECEZOLOD.js +230 -0
  44. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  45. package/dist/bundle/chunk-FBCCBCFH.js +288 -0
  46. package/dist/bundle/chunk-FKA7DOCK.js +53 -0
  47. package/dist/bundle/chunk-FOZYMDRL.js +259 -0
  48. package/dist/bundle/chunk-FPUGMDJV.js +7 -0
  49. package/dist/bundle/chunk-FTFV3HFW.js +721 -0
  50. package/dist/bundle/chunk-H3TNVEQX.js +782 -0
  51. package/dist/bundle/chunk-HC5ZWE5X.js +193 -0
  52. package/dist/bundle/chunk-HCAZV5NP.js +95 -0
  53. package/dist/bundle/chunk-HTAN663T.js +4045 -0
  54. package/dist/bundle/chunk-HZRQLAHO.js +16 -0
  55. package/dist/bundle/chunk-IMJQRPLN.js +92 -0
  56. package/dist/bundle/chunk-JLDBMEKZ.js +106 -0
  57. package/dist/bundle/chunk-JRCPCVPI.js +9393 -0
  58. package/dist/bundle/chunk-LNV33FDC.js +786 -0
  59. package/dist/bundle/chunk-LOBVOGOE.js +66 -0
  60. package/dist/bundle/chunk-MVA5HVKL.js +1392 -0
  61. package/dist/bundle/chunk-N2XADGL4.js +76 -0
  62. package/dist/bundle/chunk-NHHJHXMQ.js +58 -0
  63. package/dist/bundle/chunk-NUU4WZVL.js +52 -0
  64. package/dist/bundle/chunk-NWHEHV3K.js +133 -0
  65. package/dist/bundle/chunk-NXERIDPJ.js +319 -0
  66. package/dist/bundle/chunk-O3DYRCIT.js +23 -0
  67. package/dist/bundle/chunk-O55RWNSH.js +161 -0
  68. package/dist/bundle/chunk-P5BHKKBI.js +206 -0
  69. package/dist/bundle/chunk-PPHBRESD.js +82 -0
  70. package/dist/bundle/chunk-PVKF24ZW.js +364 -0
  71. package/dist/bundle/chunk-QGFX5MXL.js +460 -0
  72. package/dist/bundle/chunk-QJW35N5V.js +761 -0
  73. package/dist/bundle/chunk-QU25DA5N.js +360 -0
  74. package/dist/bundle/chunk-RMIYKDUL.js +1068 -0
  75. package/dist/bundle/chunk-RR5MX5TM.js +142 -0
  76. package/dist/bundle/chunk-SAKK2YRU.js +218 -0
  77. package/dist/bundle/chunk-SDQGB4KB.js +185 -0
  78. package/dist/bundle/chunk-TBJYLC5K.js +2788 -0
  79. package/dist/bundle/chunk-TI46WQXQ.js +1197 -0
  80. package/dist/bundle/chunk-TKVL2C3B.js +170 -0
  81. package/dist/bundle/chunk-TOSCB4SO.js +1227 -0
  82. package/dist/bundle/chunk-TP7GDWVF.js +6848 -0
  83. package/dist/bundle/chunk-UUMUL4L3.js +72 -0
  84. package/dist/bundle/chunk-VIEYMDBR.js +41 -0
  85. package/dist/bundle/chunk-W53EJOFQ.js +63 -0
  86. package/dist/bundle/chunk-W7HM2VGO.js +24 -0
  87. package/dist/bundle/chunk-WE4UFASG.js +88 -0
  88. package/dist/bundle/chunk-WQBX7XYP.js +26174 -0
  89. package/dist/bundle/chunk-X2M6NIQG.js +18 -0
  90. package/dist/bundle/chunk-X7XUX7A4.js +1846 -0
  91. package/dist/bundle/chunk-XRREFEIW.js +372 -0
  92. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  93. package/dist/bundle/chunk-ZBDSHFG4.js +40933 -0
  94. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  95. package/dist/bundle/command-contract-C6CBFXZF.js +40 -0
  96. package/dist/bundle/command-server-entry-DJKVVZCQ.js +169 -0
  97. package/dist/bundle/decode-FC65Y4IV.js +297 -0
  98. package/dist/bundle/definitions-MVPICAWV.js +2991 -0
  99. package/dist/bundle/dispatch-KOISQ5QJ.js +411 -0
  100. package/dist/bundle/dist-MYZZKZJ7.js +7577 -0
  101. package/dist/bundle/echarts-FVTUDXDU.js +42501 -0
  102. package/dist/bundle/embed-VNBZFPYH.js +38 -0
  103. package/dist/bundle/embedder-6U4NOFRO.js +111 -0
  104. package/dist/bundle/failure-FZ6VYKEQ.js +25 -0
  105. package/dist/bundle/first-run-RPIJZEDT.js +29 -0
  106. package/dist/bundle/first-screen-RTVMGHAE.js +40 -0
  107. package/dist/bundle/hubspot.js +198 -0
  108. package/dist/bundle/instructions-HET7BCYK.js +11 -0
  109. package/dist/bundle/mcp-RGNRW77S.js +167 -0
  110. package/dist/bundle/meeting-combined-L5AGBPYX.js +25 -0
  111. package/dist/bundle/meeting-model-NTB4RK3F.js +25 -0
  112. package/dist/bundle/meeting-semantic-JY3OGCBS.js +22 -0
  113. package/dist/bundle/node-CXZIFHZC.js +176 -0
  114. package/dist/bundle/node-P4E63KXA.js +2340 -0
  115. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  116. package/dist/bundle/node-sqlite-P3O7XN7Q.js +74 -0
  117. package/dist/bundle/oauth-HNCY4B2S.js +20 -0
  118. package/dist/bundle/open-F4P6YV54.js +23 -0
  119. package/dist/bundle/openai-4AICLIK3.js +238 -0
  120. package/dist/bundle/process-5RUXWGYS.js +91 -0
  121. package/dist/bundle/program-POG5GHUQ.js +9241 -0
  122. package/dist/bundle/prompt-NFMDVBZ4.js +17 -0
  123. package/dist/bundle/recognize-DKN3RY4V.js +26 -0
  124. package/dist/bundle/remote-6QHAGQWY.js +31 -0
  125. package/dist/bundle/rerank-M4KHEHUZ.js +52 -0
  126. package/dist/bundle/schemas-JRL3DLMP.js +952 -0
  127. package/dist/bundle/serve-DNU43ND6.js +199 -0
  128. package/dist/bundle/server-C3ZHA7AZ.js +77 -0
  129. package/dist/bundle/server-XJSNF3K5.js +207 -0
  130. package/dist/bundle/source-A3SBLHC4.js +934 -0
  131. package/dist/bundle/sqlite-runtime-EMQAC63N.js +20 -0
  132. package/dist/bundle/state-T45CX7VY.js +36 -0
  133. package/dist/bundle/store-6LCEVBAZ.js +176 -0
  134. package/dist/bundle/store-6TZ2FCVA.js +295 -0
  135. package/dist/bundle/store-CCDNUB6A.js +32 -0
  136. package/dist/bundle/store-maintenance-command-BRCG6MNA.js +68 -0
  137. package/dist/commands/account.d.ts +3 -0
  138. package/dist/commands/account.d.ts.map +1 -0
  139. package/dist/commands/account.js +87 -0
  140. package/dist/commands/account.js.map +1 -0
  141. package/dist/commands/api.d.ts +9 -0
  142. package/dist/commands/api.d.ts.map +1 -0
  143. package/dist/commands/api.js +65 -0
  144. package/dist/commands/api.js.map +1 -0
  145. package/dist/commands/comments.d.ts +3 -0
  146. package/dist/commands/comments.d.ts.map +1 -0
  147. package/dist/commands/comments.js +114 -0
  148. package/dist/commands/comments.js.map +1 -0
  149. package/dist/commands/crm-shared.d.ts +8 -0
  150. package/dist/commands/crm-shared.d.ts.map +1 -0
  151. package/dist/commands/crm-shared.js +93 -0
  152. package/dist/commands/crm-shared.js.map +1 -0
  153. package/dist/commands/schedule.d.ts +3 -0
  154. package/dist/commands/schedule.d.ts.map +1 -0
  155. package/dist/commands/schedule.js +9 -0
  156. package/dist/commands/schedule.js.map +1 -0
  157. package/dist/commands/session.d.ts +14 -0
  158. package/dist/commands/session.d.ts.map +1 -0
  159. package/dist/commands/session.js +164 -0
  160. package/dist/commands/session.js.map +1 -0
  161. package/dist/config.d.ts +22 -0
  162. package/dist/config.d.ts.map +1 -0
  163. package/dist/config.js +28 -0
  164. package/dist/config.js.map +1 -0
  165. package/dist/context.d.ts +88 -0
  166. package/dist/context.d.ts.map +1 -0
  167. package/dist/context.js +137 -0
  168. package/dist/context.js.map +1 -0
  169. package/dist/crm/activities.d.ts +24 -0
  170. package/dist/crm/activities.d.ts.map +1 -0
  171. package/dist/crm/activities.js +214 -0
  172. package/dist/crm/activities.js.map +1 -0
  173. package/dist/crm/associations.d.ts +20 -0
  174. package/dist/crm/associations.d.ts.map +1 -0
  175. package/dist/crm/associations.js +47 -0
  176. package/dist/crm/associations.js.map +1 -0
  177. package/dist/crm/records.d.ts +63 -0
  178. package/dist/crm/records.d.ts.map +1 -0
  179. package/dist/crm/records.js +333 -0
  180. package/dist/crm/records.js.map +1 -0
  181. package/dist/crm/search.d.ts +57 -0
  182. package/dist/crm/search.d.ts.map +1 -0
  183. package/dist/crm/search.js +47 -0
  184. package/dist/crm/search.js.map +1 -0
  185. package/dist/crm/source.d.ts +32 -0
  186. package/dist/crm/source.d.ts.map +1 -0
  187. package/dist/crm/source.js +369 -0
  188. package/dist/crm/source.js.map +1 -0
  189. package/dist/generated/definitions.d.ts +3 -0
  190. package/dist/generated/definitions.d.ts.map +1 -0
  191. package/dist/generated/definitions.js +2987 -0
  192. package/dist/generated/definitions.js.map +1 -0
  193. package/dist/generated/manifest.d.ts +6 -0
  194. package/dist/generated/manifest.d.ts.map +1 -0
  195. package/dist/generated/manifest.js +6499 -0
  196. package/dist/generated/manifest.js.map +1 -0
  197. package/dist/generated/schemas.d.ts +205 -0
  198. package/dist/generated/schemas.d.ts.map +1 -0
  199. package/dist/generated/schemas.js +810 -0
  200. package/dist/generated/schemas.js.map +1 -0
  201. package/dist/generated/types.d.ts +1114 -0
  202. package/dist/generated/types.d.ts.map +1 -0
  203. package/dist/generated/types.js +5 -0
  204. package/dist/generated/types.js.map +1 -0
  205. package/dist/hubspot/account.d.ts +12 -0
  206. package/dist/hubspot/account.d.ts.map +1 -0
  207. package/dist/hubspot/account.js +23 -0
  208. package/dist/hubspot/account.js.map +1 -0
  209. package/dist/hubspot/transport.d.ts +76 -0
  210. package/dist/hubspot/transport.d.ts.map +1 -0
  211. package/dist/hubspot/transport.js +346 -0
  212. package/dist/hubspot/transport.js.map +1 -0
  213. package/dist/identity.d.ts +7 -0
  214. package/dist/identity.d.ts.map +1 -0
  215. package/dist/identity.js +32 -0
  216. package/dist/identity.js.map +1 -0
  217. package/dist/index.d.ts +3 -0
  218. package/dist/index.d.ts.map +1 -0
  219. package/dist/index.js +3 -0
  220. package/dist/index.js.map +1 -0
  221. package/dist/program.d.ts +6 -0
  222. package/dist/program.d.ts.map +1 -0
  223. package/dist/program.js +77 -0
  224. package/dist/program.js.map +1 -0
  225. package/dist/reasons.d.ts +10 -0
  226. package/dist/reasons.d.ts.map +1 -0
  227. package/dist/reasons.js +33 -0
  228. package/dist/reasons.js.map +1 -0
  229. package/dist/sample/comments.d.ts +61 -0
  230. package/dist/sample/comments.d.ts.map +1 -0
  231. package/dist/sample/comments.js +39 -0
  232. package/dist/sample/comments.js.map +1 -0
  233. package/dist/sample/records.d.ts +16 -0
  234. package/dist/sample/records.d.ts.map +1 -0
  235. package/dist/sample/records.js +22 -0
  236. package/dist/sample/records.js.map +1 -0
  237. package/dist/sample/transport.d.ts +42 -0
  238. package/dist/sample/transport.d.ts.map +1 -0
  239. package/dist/sample/transport.js +153 -0
  240. package/dist/sample/transport.js.map +1 -0
  241. package/dist/setup/flow.d.ts +2 -0
  242. package/dist/setup/flow.d.ts.map +1 -0
  243. package/dist/setup/flow.js +97 -0
  244. package/dist/setup/flow.js.map +1 -0
  245. package/dist/setup/texts.en.json +19 -0
  246. package/dist/setup/texts.es.json +19 -0
  247. package/dist/setup/texts.ru.json +19 -0
  248. package/dist/store.d.ts +16 -0
  249. package/dist/store.d.ts.map +1 -0
  250. package/dist/store.js +34 -0
  251. package/dist/store.js.map +1 -0
  252. package/dist/version.d.ts +2 -0
  253. package/dist/version.d.ts.map +1 -0
  254. package/dist/version.js +2 -0
  255. package/dist/version.js.map +1 -0
  256. package/dist/wcat.d.ts +3 -0
  257. package/dist/wcat.d.ts.map +1 -0
  258. package/dist/wcat.js +4 -0
  259. package/dist/wcat.js.map +1 -0
  260. package/dist/whoami.d.ts +19 -0
  261. package/dist/whoami.d.ts.map +1 -0
  262. package/dist/whoami.js +15 -0
  263. package/dist/whoami.js.map +1 -0
  264. package/package.json +98 -4
  265. package/skills/hubspot-cli/SKILL.md +97 -0
  266. package/skills/hubspot-cli/references/api/api-basic.md +462 -0
  267. package/skills/hubspot-cli/references/api/api-batch.md +149 -0
  268. package/skills/hubspot-cli/references/api/api-search.md +147 -0
  269. package/skills/hubspot-cli/references/api.md +15 -0
@@ -0,0 +1,214 @@
1
+ import { isCliError } from "@wirecat/cli-base";
2
+ import { crmValues } from "@wirecat/cli-core/crm";
3
+ import { associationsOf } from "./associations.js";
4
+ import { msOf, nextOf, propertiesOf, resultsOf } from "./records.js";
5
+ import { modifiedSince, nextSpot, SEARCH_PAGE, search } from "./search.js";
6
+ const { id, text } = crmValues;
7
+ const OVERLAP_MS = 10 * 60_000;
8
+ /**
9
+ * A call not over yet, of the `hs_call_status` values BUSY, CALLING_CRM_USER, CANCELED, COMPLETED, CONNECTING, FAILED,
10
+ * IN_PROGRESS, NO_ANSWER, QUEUED and RINGING (https://developers.hubspot.com/docs/api-reference/latest/crm/activities/calls/guide).
11
+ */
12
+ export const CALL_OPEN = ["CALLING_CRM_USER", "CONNECTING", "IN_PROGRESS", "QUEUED", "RINGING"];
13
+ /**
14
+ * An e-mail not sent yet, of BOUNCED, FAILED, SCHEDULED, SENDING and SENT
15
+ * (https://developers.hubspot.com/docs/api-reference/latest/crm/activities/emails/guide).
16
+ */
17
+ const EMAIL_OPEN = ["SCHEDULED", "SENDING"];
18
+ const COMMON = ["hubspot_owner_id", "hs_timestamp", "hs_createdate", "hs_lastmodifieddate"];
19
+ /** HTML as plain text: notes, meetings and tasks keep rich text. */
20
+ const plain = (value) => {
21
+ const html = text(value);
22
+ if (html === null)
23
+ return null;
24
+ return text(html
25
+ .replace(/<br\s*\/?>|<\/p>|<\/div>|<\/li>/gi, "\n")
26
+ .replace(/<[^>]*>/g, "")
27
+ .replace(/&nbsp;/g, " ")
28
+ .replace(/&lt;/g, "<")
29
+ .replace(/&gt;/g, ">")
30
+ .replace(/&quot;/g, '"')
31
+ .replace(/&#39;/g, "'")
32
+ .replace(/&amp;/g, "&"));
33
+ };
34
+ // HubSpot has no notes, calls, meetings or tasks scope; a key with the contacts scope reads them (account 149800303,
35
+ // 2026-11-17). Emails ask for sales-email-read.
36
+ const CONTACTS_SCOPE = "crm.objects.contacts.read";
37
+ const ENGAGEMENTS = [
38
+ {
39
+ type: "notes",
40
+ kind: "comment",
41
+ scope: CONTACTS_SCOPE,
42
+ properties: ["hs_note_body", ...COMMON],
43
+ subject: () => "",
44
+ body: (properties) => plain(properties.hs_note_body),
45
+ dueAt: () => null,
46
+ done: () => true,
47
+ },
48
+ {
49
+ type: "calls",
50
+ kind: "call",
51
+ scope: CONTACTS_SCOPE,
52
+ properties: ["hs_call_title", "hs_call_direction", "hs_call_status", ...COMMON],
53
+ subject: (properties) => text(properties.hs_call_title) ??
54
+ (text(properties.hs_call_direction) === "INBOUND" ? "incoming call" : "outgoing call"),
55
+ body: () => null,
56
+ dueAt: () => null,
57
+ done: (properties) => !CALL_OPEN.includes(text(properties.hs_call_status) ?? ""),
58
+ },
59
+ {
60
+ type: "emails",
61
+ kind: "email",
62
+ scope: "sales-email-read",
63
+ properties: ["hs_email_subject", "hs_email_text", "hs_email_direction", "hs_email_status", ...COMMON],
64
+ subject: (properties) => text(properties.hs_email_subject),
65
+ body: (properties) => text(properties.hs_email_text),
66
+ dueAt: () => null,
67
+ done: (properties) => !EMAIL_OPEN.includes(text(properties.hs_email_status) ?? ""),
68
+ },
69
+ {
70
+ type: "meetings",
71
+ kind: "meeting",
72
+ scope: CONTACTS_SCOPE,
73
+ properties: ["hs_meeting_title", "hs_meeting_body", "hs_meeting_start_time", "hs_meeting_outcome", ...COMMON],
74
+ subject: (properties) => text(properties.hs_meeting_title),
75
+ body: (properties) => plain(properties.hs_meeting_body),
76
+ dueAt: (properties) => msOf(properties.hs_meeting_start_time),
77
+ // "scheduled, completed, rescheduled, no show, and canceled", in prose and lower case
78
+ // (https://developers.hubspot.com/docs/api-reference/latest/crm/activities/meetings/guide).
79
+ done: (properties) => text(properties.hs_meeting_outcome)?.toUpperCase() === "COMPLETED",
80
+ },
81
+ {
82
+ type: "tasks",
83
+ kind: "task",
84
+ scope: CONTACTS_SCOPE,
85
+ properties: ["hs_task_subject", "hs_task_body", "hs_task_status", ...COMMON],
86
+ subject: (properties) => text(properties.hs_task_subject),
87
+ body: (properties) => plain(properties.hs_task_body),
88
+ dueAt: (properties) => msOf(properties.hs_timestamp),
89
+ // COMPLETED or NOT_STARTED (https://developers.hubspot.com/docs/api-reference/latest/crm/activities/tasks/guide).
90
+ done: (properties) => text(properties.hs_task_status) === "COMPLETED",
91
+ },
92
+ ];
93
+ /** What an engagement is on, by the associations API's names; a list the token may not read leaves its kind out. */
94
+ const ON = [
95
+ ["deals", "deal"],
96
+ ["leads", "lead"],
97
+ ["contacts", "person"],
98
+ ["companies", "organization"],
99
+ ];
100
+ const toActivity = (engagement, raw, on) => {
101
+ const externalId = id(raw.id);
102
+ const properties = propertiesOf(raw);
103
+ const updatedAt = msOf(properties.hs_lastmodifieddate) ?? msOf(raw.updatedAt);
104
+ if (!externalId || updatedAt === null)
105
+ return null;
106
+ return {
107
+ // One id space for every kind: a note and a call may share a number.
108
+ externalId: `${engagement.type}:${externalId}`,
109
+ kind: engagement.kind,
110
+ subject: engagement.subject(properties) ?? "",
111
+ body: engagement.body(properties),
112
+ dueAt: engagement.dueAt(properties),
113
+ done: engagement.done(properties),
114
+ assignee: id(properties.hubspot_owner_id),
115
+ createdAt: msOf(properties.hs_createdate) ?? msOf(raw.createdAt) ?? updatedAt,
116
+ updatedAt,
117
+ on,
118
+ };
119
+ };
120
+ /**
121
+ * `<engagement index>.<from>.<offset>@<round start>` reads by search, keyset by modified time as the record changes
122
+ * are; `<engagement index>.<from>.L<after>@<round start>` lists the type in full, for a moment past the search cap.
123
+ * HubSpot's `after` is opaque, so the round's start is read after the last `@`.
124
+ */
125
+ const pageOf = (page, since, now) => {
126
+ const fresh = { at: 0, spot: { from: since - OVERLAP_MS, offset: 0 }, after: undefined, started: now };
127
+ const cut = (page ?? "").lastIndexOf("@");
128
+ const started = Number(page?.slice(cut + 1));
129
+ const found = /^(\d+)\.(-?\d+)\.(?:(\d+)|L(.*))$/s.exec(page?.slice(0, cut) ?? "");
130
+ if (cut < 0 || !found || !Number.isSafeInteger(started))
131
+ return fresh;
132
+ return {
133
+ at: Number(found[1]),
134
+ spot: { from: Number(found[2]), offset: Number(found[3] ?? 0) },
135
+ after: found[4] === undefined ? undefined : found[4] || "",
136
+ started,
137
+ };
138
+ };
139
+ /**
140
+ * One page of one engagement type changed since `since`, the types one after another: notes, calls, e-mails,
141
+ * meetings, tasks. A type the token's scopes refuse is a gap naming the scope, and the next type is read.
142
+ *
143
+ * More than the search cap changed at one moment (an import): the type is then listed in full, newest change or not,
144
+ * and only rows changed since the window's start are kept. Not a stop: cli-core resumes a failed activity round
145
+ * from the page it saved, which would hit the same cap on every run.
146
+ */
147
+ export const readActivities = async (caller, since, page, context, now, sizes = { search: SEARCH_PAGE, list: 100 }) => {
148
+ const { at, spot, after, started } = pageOf(page, since, now());
149
+ const engagement = ENGAGEMENTS[at];
150
+ const last = { hasMore: false, cursor: String(started) };
151
+ if (!engagement)
152
+ return { items: [], ...last };
153
+ const following = (items, next) => {
154
+ if (next)
155
+ return { items, hasMore: true, nextCursor: `${at}.${next}@${started}` };
156
+ if (at + 1 >= ENGAGEMENTS.length)
157
+ return { items, ...last };
158
+ return { items, hasMore: true, nextCursor: `${at + 1}.${since - OVERLAP_MS}.0@${started}` };
159
+ };
160
+ let rows;
161
+ let more;
162
+ let listedNext = null;
163
+ try {
164
+ if (after === undefined)
165
+ ({ rows, more } = await search(caller.post, engagement.type, modifiedSince("hs_lastmodifieddate", spot, sizes.search, engagement.properties)));
166
+ else {
167
+ const body = await caller.get(`/crm/objects/2026-03/${engagement.type}`, {
168
+ limit: sizes.list,
169
+ properties: engagement.properties.join(","),
170
+ archived: false,
171
+ ...(after ? { after } : {}),
172
+ });
173
+ listedNext = nextOf(body);
174
+ more = listedNext !== null;
175
+ rows = resultsOf(body).filter((raw) => {
176
+ const changed = msOf(propertiesOf(raw).hs_lastmodifieddate) ?? msOf(raw.updatedAt);
177
+ return changed === null || changed >= spot.from;
178
+ });
179
+ }
180
+ }
181
+ catch (error) {
182
+ if (!isCliError(error) || error.code !== "permission_error")
183
+ throw error;
184
+ context?.gap({
185
+ kind: "activities",
186
+ scope: engagement.scope,
187
+ message: `HubSpot refused the ${engagement.type} (${engagement.scope} scope missing); the other activities are read`,
188
+ });
189
+ return following([]);
190
+ }
191
+ const ids = rows.flatMap((raw) => id(raw.id) ?? []);
192
+ const on = new Map();
193
+ for (const [to, kind] of ON) {
194
+ let found;
195
+ try {
196
+ found = await associationsOf(caller.post, engagement.type, to, ids);
197
+ }
198
+ catch (error) {
199
+ if (isCliError(error) && error.code === "permission_error")
200
+ continue;
201
+ throw error;
202
+ }
203
+ for (const [owner, linked] of found)
204
+ on.set(owner, [...(on.get(owner) ?? []), ...linked.map((one) => ({ kind, externalId: one.id }))]);
205
+ }
206
+ const items = rows.flatMap((raw) => toActivity(engagement, raw, on.get(String(raw.id)) ?? []) ?? []);
207
+ if (!more)
208
+ return following(items);
209
+ if (after !== undefined)
210
+ return following(items, `${spot.from}.L${listedNext}`);
211
+ const next = nextSpot(spot, rows, "hs_lastmodifieddate", sizes.search);
212
+ return following(items, next ? `${next.from}.${next.offset}` : `${spot.from}.L`);
213
+ };
214
+ //# sourceMappingURL=activities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.js","sourceRoot":"","sources":["../../src/crm/activities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAqC,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEpF,OAAO,EAAE,cAAc,EAAE,M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AK,CAAC,CAAA;IAClC,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC,CAAA;IAC/E,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,qBAAqB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IACtE,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAA;AAClF,CAAC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import type { Raw } from "./records.js";
2
+ import type { Post } from "./search.js";
3
+ /** One associated record and how it is associated: HubSpot's type ids and labels (associations v4 guide). */
4
+ export interface Associated {
5
+ id: string;
6
+ typeIds: number[];
7
+ labels: string[];
8
+ }
9
+ /**
10
+ * Each of `ids`' associations of type `to`, by the associations v4 batch read: search answers carry none (search
11
+ * guide). An object with none is left out of the answer. More than one page of associations on one object
12
+ * (`paging.next` inside a result) is not read further.
13
+ */
14
+ export declare const associationsOf: (post: Post, from: string, to: string, ids: readonly string[]) => Promise<Map<string, Associated[]>>;
15
+ /**
16
+ * Rows with their associations of type `to` in the shape a list answers them, the type ids and labels beside, so one
17
+ * mapping reads both. A row with none gets an empty list: asked and none is not "not said".
18
+ */
19
+ export declare const withAssociations: (rows: readonly Raw[], to: string, found: ReadonlyMap<string, Associated[]>) => Raw[];
20
+ //# sourceMappingURL=associations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"associations.d.ts","sourceRoot":"","sources":["../../src/crm/associations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAIvC,6GAA6G;AAC7G,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,SAAgB,IAAI,QAAQ,MAAM,MAAM,MAAM,OAAO,SAAS,MAAM,EAAE,uCAwBhG,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,SAAU,SAAS,GAAG,EAAE,MAAM,MAAM,SAAS,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,KAAG,GAAG,EAO5G,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { crmValues } from "@wirecat/cli-core/crm";
2
+ const { fieldOf, id, number, rawsOf, text } = crmValues;
3
+ /**
4
+ * Each of `ids`' associations of type `to`, by the associations v4 batch read: search answers carry none (search
5
+ * guide). An object with none is left out of the answer. More than one page of associations on one object
6
+ * (`paging.next` inside a result) is not read further.
7
+ */
8
+ export const associationsOf = async (post, from, to, ids) => {
9
+ const found = new Map();
10
+ if (!ids.length)
11
+ return found;
12
+ const body = await post(`/crm/associations/2026-03/${from}/${to}/batch/read`, {
13
+ inputs: ids.map((one) => ({ id: one })),
14
+ });
15
+ for (const result of rawsOf(fieldOf(body, "results"))) {
16
+ const owner = id(fieldOf(result.from, "id"));
17
+ if (!owner)
18
+ continue;
19
+ const held = new Map((found.get(owner) ?? []).map((one) => [one.id, one]));
20
+ for (const one of rawsOf(result.to)) {
21
+ const linked = id(one.toObjectId);
22
+ if (!linked)
23
+ continue;
24
+ const types = rawsOf(one.associationTypes);
25
+ const kept = held.get(linked) ?? { id: linked, typeIds: [], labels: [] };
26
+ held.set(linked, {
27
+ id: linked,
28
+ typeIds: [...new Set([...kept.typeIds, ...types.flatMap((type) => number(type.typeId) ?? [])])],
29
+ labels: [...new Set([...kept.labels, ...types.flatMap((type) => text(type.label) ?? [])])],
30
+ });
31
+ }
32
+ found.set(owner, [...held.values()]);
33
+ }
34
+ return found;
35
+ };
36
+ /**
37
+ * Rows with their associations of type `to` in the shape a list answers them, the type ids and labels beside, so one
38
+ * mapping reads both. A row with none gets an empty list: asked and none is not "not said".
39
+ */
40
+ export const withAssociations = (rows, to, found) => rows.map((raw) => ({
41
+ ...raw,
42
+ associations: {
43
+ ...(typeof raw.associations === "object" && raw.associations !== null ? raw.associations : {}),
44
+ [to]: { results: (found.get(String(raw.id)) ?? []).map((one) => ({ ...one, type: to })) },
45
+ },
46
+ }));
47
+ //# sourceMappingURL=associations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"associations.js","sourceRoot":"","sources":["../../src/crm/associations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAIjD,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAA;AASvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,IAAU,EAAE,IAAY,EAAE,EAAU,EAAE,GAAsB,EAAE,EAAE;IACnG,MAAM,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAA;IAC7C,IAAI,CAAC,GAAG,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IAC7B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,6BAA6B,IAAI,IAAI,EAAE,aAAa,EAAE;QAC5E,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;KACxC,CAAC,CAAA;IACF,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;QACtD,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;QAC5C,IAAI,CAAC,KA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AM,EAAE,CAAC,CAAC,CAAA;IACtC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAoB,EAAE,EAAU,EAAE,KAAwC,EAAS,EAAE,CACpH,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACjB,GAAG,GAAG;IACN,YAAY,EAAE;QACZ,GAAG,CAAC,OAAO,GAAG,CAAC,YAAY,KAAK,QAAQ,IAAI,GAAG,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9F,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE;KAC1F;CACF,CAAC,CAAC,CAAA"}
@@ -0,0 +1,63 @@
1
+ import type { CrmField, CrmItem, CrmKind, CrmOrganization, CrmPerson, CrmPipeline, CrmUser, StageOutcome } from "@wirecat/cli-core";
2
+ export type Raw = Record<string, unknown>;
3
+ /** One kind as HubSpot's object APIs name it (https://developers.hubspot.com/docs/api-reference/latest/crm/using-object-apis). */
4
+ export interface ObjectType {
5
+ /** The path segment after `/crm/objects/2026-03/`: deals are `0-3`, the object type id. */
6
+ path: string;
7
+ /** The name the associations and pipelines APIs take. */
8
+ name: string;
9
+ /** The property the search guide names for the last change: `lastmodifieddate` on contacts only. */
10
+ modified: string;
11
+ created: string;
12
+ /** Asked for every row; what the mapping below reads. */
13
+ properties: readonly string[];
14
+ /** What a list returns the ids of, `?associations=` (contacts guide); search returns none. */
15
+ associations: readonly string[];
16
+ /**
17
+ * What is read by the associations batch read on every path, for the type ids a list does not give: the one that
18
+ * marks the primary company (associations v4 guide, association type ids).
19
+ */
20
+ linked: readonly string[];
21
+ /** The read scope its object API needs (legacy-apps/authentication/scopes). */
22
+ scope: string;
23
+ }
24
+ export declare const OBJECTS: Record<CrmKind, ObjectType>;
25
+ /** A list or search answer without `results` is refused: read as an empty page, it would end the round. */
26
+ export declare const resultsOf: (body: unknown) => Raw[];
27
+ /** `paging.next.after`, absent on the last page (contacts guide). */
28
+ export declare const nextOf: (body: unknown) => string | null;
29
+ export declare const propertiesOf: (raw: Raw) => Raw;
30
+ /** HubSpot sends a time as ISO or as epoch ms in a string, depending on the property (search guide, filtering). */
31
+ export declare const msOf: (value: unknown) => number | null;
32
+ /** Ids a list's `associations` holds of one type, each once: a pair with two labels is listed twice. */
33
+ export declare const associatedOf: (raw: Raw, type: string) => string[] | undefined;
34
+ export declare const toPerson: (raw: Raw, defined?: readonly CrmField[]) => CrmPerson;
35
+ export declare const toOrganization: (raw: Raw, defined?: readonly CrmField[]) => CrmOrganization;
36
+ export declare const toDeal: (raw: Raw, defined?: readonly CrmField[], currency?: string | null) => CrmItem;
37
+ export declare const toLead: (raw: Raw, defined?: readonly CrmField[]) => CrmItem;
38
+ /**
39
+ * A stage's outcome from its `metadata`: a deal stage is closed won at probability 1.0 and closed lost at 0.0
40
+ * (https://developers.hubspot.com/docs/api-reference/latest/crm/pipelines/guide).
41
+ *
42
+ * A lead stage is only open or closed; HubSpot documents no won or lost for it. A closed one goes by its probability
43
+ * when it has one, then by the default stages' ids, then by their English names. Any other closed lead stage is
44
+ * `unknown`: cli-core's outcomes have no "closed, outcome unknown", and counting it lost never makes a win of a
45
+ * disqualified lead.
46
+ */
47
+ export declare const outcomeOf: (metadata: unknown, kind?: "deal" | "lead", stage?: {
48
+ id?: string | null;
49
+ label?: string | null;
50
+ }) => {
51
+ outcome: StageOutcome;
52
+ unknown?: true;
53
+ };
54
+ /** A pipeline with its stages; `unknown` hears each closed stage whose outcome HubSpot does not give. */
55
+ export declare const toPipeline: (raw: Raw, kind?: "deal" | "lead", unknown?: (stage: string) => void) => CrmPipeline | null;
56
+ /** An owner is who a record is assigned to: `hubspot_owner_id` is the owner's `id`, not its `userId` (owners guide). */
57
+ export declare const toUser: (raw: Raw) => CrmUser | null;
58
+ /**
59
+ * The account's own properties of a kind (`hubspotDefined` false), what a row's `metadata` is keyed by. HubSpot's
60
+ * own properties are read by name in the mapping above and are not repeated there.
61
+ */
62
+ export declare const toField: (raw: Raw) => CrmField | null;
63
+ //# sourceMappingURL=records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../src/crm/records.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,OAAO,EACP,OAAO,EACP,eAAe,EACf,SAAS,EACT,WAAW,EACX,OAAO,EACP,YAAY,EACb,MAAM,mBAAmB,CAAA;AAM1B,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEzC,kIAAkI;AAClI,MAAM,WAAW,UAAU;IACzB,2FAA2F;IAC3F,IAAI,EAAE,MAAM,CAAA;IACZ,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAA;IACZ,oGAAoG;IACpG,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,yDAAyD;IACzD,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;IAC7B,8FAA8F;IAC9F,YAAY,EAAE,SAAS,MAAM,EAAE,CAAA;IAC/B;;;OAGG;IACH,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IACzB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CA2E/C,CAAA;AAED,2GAA2G;AAC3G,eAAO,MAAM,SAAS,SAAU,OAAO,KAAG,GAAG,EAI5C,CAAA;AAED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