@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,333 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { crmValues } from "@wirecat/cli-core/crm";
3
+ import { SERVICE } from "../hubspot/transport.js";
4
+ const { amountOf, crmValuesOf, epoch, fieldOf, fullName, id, isRaw, rawsOf, text } = crmValues;
5
+ export const OBJECTS = {
6
+ organization: {
7
+ path: "companies",
8
+ name: "companies",
9
+ modified: "hs_lastmodifieddate",
10
+ created: "createdate",
11
+ properties: ["name", "domain", "website", "phone", "hubspot_owner_id", "createdate", "hs_lastmodifieddate"],
12
+ associations: [],
13
+ linked: [],
14
+ scope: "crm.objects.companies.read",
15
+ },
16
+ person: {
17
+ path: "contacts",
18
+ name: "contacts",
19
+ modified: "lastmodifieddate",
20
+ created: "createdate",
21
+ properties: [
22
+ "firstname",
23
+ "lastname",
24
+ "email",
25
+ "hs_additional_emails",
26
+ "phone",
27
+ "mobilephone",
28
+ "jobtitle",
29
+ "associatedcompanyid",
30
+ "hubspot_owner_id",
31
+ "createdate",
32
+ "lastmodifieddate",
33
+ ],
34
+ associations: ["companies"],
35
+ linked: [],
36
+ scope: "crm.objects.contacts.read",
37
+ },
38
+ deal: {
39
+ path: "0-3",
40
+ name: "deals",
41
+ modified: "hs_lastmodifieddate",
42
+ created: "createdate",
43
+ properties: [
44
+ "dealname",
45
+ "pipeline",
46
+ "dealstage",
47
+ "amount",
48
+ "deal_currency_code",
49
+ "closedate",
50
+ "closed_lost_reason",
51
+ "closed_won_reason",
52
+ "hubspot_owner_id",
53
+ "createdate",
54
+ "hs_lastmodifieddate",
55
+ ],
56
+ associations: ["contacts"],
57
+ linked: ["companies"],
58
+ scope: "crm.objects.deals.read",
59
+ },
60
+ lead: {
61
+ path: "leads",
62
+ name: "leads",
63
+ modified: "hs_lastmodifieddate",
64
+ // The leads guide names no created-time property (https://developers.hubspot.com/docs/api-reference/latest/crm/objects/leads/guide);
65
+ // HubSpot's other objects use `hs_createdate` or `createdate`, so both are asked and either is read.
66
+ created: "hs_createdate",
67
+ properties: [
68
+ "hs_lead_name",
69
+ "hs_pipeline",
70
+ "hs_pipeline_stage",
71
+ "hubspot_owner_id",
72
+ "hs_createdate",
73
+ "createdate",
74
+ "hs_lastmodifieddate",
75
+ ],
76
+ associations: ["contacts"],
77
+ linked: ["companies"],
78
+ scope: "crm.objects.leads.read",
79
+ },
80
+ };
81
+ /** A list or search answer without `results` is refused: read as an empty page, it would end the round. */
82
+ export const resultsOf = (body) => {
83
+ const results = fieldOf(body, "results");
84
+ if (!Array.isArray(results))
85
+ throw new CliError("invalid_response", `${SERVICE} answered a list without its results`);
86
+ return results.filter(isRaw);
87
+ };
88
+ /** `paging.next.after`, absent on the last page (contacts guide). */
89
+ export const nextOf = (body) => text(fieldOf(fieldOf(fieldOf(body, "paging"), "next"), "after"));
90
+ export const propertiesOf = (raw) => (isRaw(raw.properties) ? raw.properties : {});
91
+ /** HubSpot sends a time as ISO or as epoch ms in a string, depending on the property (search guide, filtering). */
92
+ export const msOf = (value) => {
93
+ if (typeof value === "string" && /^\d{10,16}$/.test(value))
94
+ return Number(value);
95
+ return epoch(value);
96
+ };
97
+ /**
98
+ * The primary-company association type ids by the record's type: deal 5, contact 1, lead 580
99
+ * (https://developers.hubspot.com/docs/api-reference/crm-associations-v4/guide, "Association type ID values").
100
+ */
101
+ const PRIMARY_COMPANY = { deals: 5, contacts: 1, leads: 580 };
102
+ /** The company the record's primary-company association names; the first one when none is marked. */
103
+ const primaryCompanyOf = (raw, from) => {
104
+ const results = rawsOf(fieldOf(fieldOf(raw.associations, "companies"), "results"));
105
+ const marked = results.find((one) => Array.isArray(one.typeIds) && one.typeIds.includes(PRIMARY_COMPANY[from] ?? Number.NaN));
106
+ return id(marked?.id) ?? id(results[0]?.id);
107
+ };
108
+ /** Ids a list's `associations` holds of one type, each once: a pair with two labels is listed twice. */
109
+ export const associatedOf = (raw, type) => {
110
+ const group = fieldOf(raw.associations, type);
111
+ if (group === undefined)
112
+ return undefined;
113
+ return [...new Set(rawsOf(fieldOf(group, "results")).flatMap((one) => id(one.id) ?? []))];
114
+ };
115
+ /** The link HubSpot keeps as the company's website, as its bare origin: never a path or query a token could sit in. */
116
+ const siteOf = (properties) => {
117
+ for (const value of [properties.website, properties.domain]) {
118
+ const raw = text(value);
119
+ if (!raw)
120
+ continue;
121
+ try {
122
+ const url = new URL(/^https?:\/\//i.test(raw) ? raw : `https://${raw}`);
123
+ if ((url.protocol === "https:" || url.protocol === "http:") && !url.username && !url.password)
124
+ return `${url.protocol}//${url.host}`;
125
+ }
126
+ catch { }
127
+ }
128
+ return null;
129
+ };
130
+ const DAY = /^(\d{4}-\d{2}-\d{2})/;
131
+ /** `closedate` is a time; the port keeps the day (deals guide: "the date the deal was closed"). */
132
+ const dayOf = (value) => {
133
+ const ms = msOf(value);
134
+ if (ms !== null)
135
+ return new Date(ms).toISOString().slice(0, 10);
136
+ return DAY.exec(text(value) ?? "")?.[1] ?? null;
137
+ };
138
+ const uniq = (values) => [...new Set(values.filter((one) => !!one))];
139
+ /** The custom values of a row: only properties the account defined, which `fields()` lists. */
140
+ const valuesOf = (properties, defined) => {
141
+ const values = {};
142
+ for (const field of defined) {
143
+ const value = properties[field.code];
144
+ if (value === null || value === undefined || value === "")
145
+ continue;
146
+ values[field.code] = field.multiple && typeof value === "string" ? value.split(";") : value;
147
+ }
148
+ return Object.keys(values).length ? crmValuesOf(values, defined) : undefined;
149
+ };
150
+ const timesOf = (raw, type) => {
151
+ const properties = propertiesOf(raw);
152
+ return {
153
+ createdAt: msOf(properties[type.created]) ?? msOf(properties.createdate) ?? msOf(raw.createdAt),
154
+ updatedAt: msOf(properties[type.modified]) ?? msOf(raw.updatedAt),
155
+ };
156
+ };
157
+ export const toPerson = (raw, defined = []) => {
158
+ const properties = propertiesOf(raw);
159
+ const phones = uniq([text(properties.phone), text(properties.mobilephone)]);
160
+ const emails = uniq([
161
+ text(properties.email),
162
+ ...(text(properties.hs_additional_emails) ?? "").split(";").map((one) => text(one)),
163
+ ]);
164
+ const companies = associatedOf(raw, "companies");
165
+ const primary = id(properties.associatedcompanyid) ?? (companies?.length ? primaryCompanyOf(raw, "contacts") : null);
166
+ const metadata = valuesOf(properties, defined);
167
+ return {
168
+ externalId: id(raw.id) ?? "",
169
+ name: fullName(properties.firstname, properties.lastname),
170
+ firstName: text(properties.firstname),
171
+ lastName: text(properties.lastname),
172
+ email: emails[0] ?? null,
173
+ phone: phones[0] ?? null,
174
+ phones,
175
+ emails,
176
+ position: text(properties.jobtitle),
177
+ assignee: id(properties.hubspot_owner_id),
178
+ ...timesOf(raw, OBJECTS.person),
179
+ ...(companies
180
+ ? {
181
+ organizations: uniq([primary && companies.includes(primary) ? primary : null, ...companies]).map((externalId) => ({ externalId, primary: externalId === primary })),
182
+ }
183
+ : {}),
184
+ ...(metadata ? { metadata } : {}),
185
+ };
186
+ };
187
+ export const toOrganization = (raw, defined = []) => {
188
+ const properties = propertiesOf(raw);
189
+ const metadata = valuesOf(properties, defined);
190
+ const phones = uniq([text(properties.phone)]);
191
+ return {
192
+ externalId: id(raw.id) ?? "",
193
+ name: text(properties.name) ?? text(properties.domain) ?? "",
194
+ url: siteOf(properties),
195
+ phones,
196
+ assignee: id(properties.hubspot_owner_id),
197
+ ...timesOf(raw, OBJECTS.organization),
198
+ ...(metadata ? { metadata } : {}),
199
+ };
200
+ };
201
+ /**
202
+ * A deal's or lead's contacts and its primary company; each left out when it was read without them, so the stored
203
+ * ones stay.
204
+ */
205
+ const linksOf = (raw, from) => {
206
+ const contacts = associatedOf(raw, "contacts");
207
+ const companies = associatedOf(raw, "companies");
208
+ return {
209
+ ...(contacts ? { people: contacts.map((externalId) => ({ externalId, role: "contact" })) } : {}),
210
+ ...(companies ? { organization: primaryCompanyOf(raw, from) } : {}),
211
+ };
212
+ };
213
+ export const toDeal = (raw, defined = [], currency = null) => {
214
+ const properties = propertiesOf(raw);
215
+ const money = amountOf(properties.amount, text(properties.deal_currency_code) ?? currency);
216
+ const metadata = valuesOf(properties, defined);
217
+ return {
218
+ externalId: id(raw.id) ?? "",
219
+ title: text(properties.dealname) ?? "",
220
+ pipeline: text(properties.pipeline) ?? "",
221
+ stage: text(properties.dealstage) ?? "",
222
+ ...money,
223
+ closeDate: dayOf(properties.closedate),
224
+ closedReason: text(properties.closed_won_reason) ?? text(properties.closed_lost_reason),
225
+ assignee: id(properties.hubspot_owner_id),
226
+ ...timesOf(raw, OBJECTS.deal),
227
+ ...linksOf(raw, "deals"),
228
+ ...(metadata ? { metadata } : {}),
229
+ };
230
+ };
231
+ export const toLead = (raw, defined = []) => {
232
+ const properties = propertiesOf(raw);
233
+ const metadata = valuesOf(properties, defined);
234
+ return {
235
+ externalId: id(raw.id) ?? "",
236
+ title: text(properties.hs_lead_name) ?? "",
237
+ pipeline: text(properties.hs_pipeline) ?? "",
238
+ stage: text(properties.hs_pipeline_stage) ?? "",
239
+ assignee: id(properties.hubspot_owner_id),
240
+ ...timesOf(raw, OBJECTS.lead),
241
+ ...linksOf(raw, "leads"),
242
+ ...(metadata ? { metadata } : {}),
243
+ };
244
+ };
245
+ /**
246
+ * The ids of HubSpot's default lead pipeline's closed stages. Not in HubSpot's docs: seen in that default pipeline,
247
+ * and to be checked on a live account. Matched before the label, so a renamed or translated stage keeps its outcome.
248
+ */
249
+ const LEAD_STAGE_IDS = { "qualified-stage-id": "won", "unqualified-stage-id": "lost" };
250
+ /** The default stages' English names (https://knowledge.hubspot.com/object-settings/set-up-and-customize-pipelines). */
251
+ const LEAD_STAGE_LABELS = { qualified: "won", disqualified: "lost" };
252
+ /**
253
+ * A stage's outcome from its `metadata`: a deal stage is closed won at probability 1.0 and closed lost at 0.0
254
+ * (https://developers.hubspot.com/docs/api-reference/latest/crm/pipelines/guide).
255
+ *
256
+ * A lead stage is only open or closed; HubSpot documents no won or lost for it. A closed one goes by its probability
257
+ * when it has one, then by the default stages' ids, then by their English names. Any other closed lead stage is
258
+ * `unknown`: cli-core's outcomes have no "closed, outcome unknown", and counting it lost never makes a win of a
259
+ * disqualified lead.
260
+ */
261
+ export const outcomeOf = (metadata, kind = "deal", stage = {}) => {
262
+ if (text(fieldOf(metadata, "isClosed")) !== "true")
263
+ return { outcome: "open" };
264
+ const probability = text(fieldOf(metadata, "probability"));
265
+ if (kind === "deal" || probability !== null)
266
+ return { outcome: Number(probability) === 1 ? "won" : "lost" };
267
+ const known = LEAD_STAGE_IDS[stage.id ?? ""] ?? LEAD_STAGE_LABELS[stage.label?.trim().toLowerCase() ?? ""];
268
+ return known ? { outcome: known } : { outcome: "lost", unknown: true };
269
+ };
270
+ /** A pipeline with its stages; `unknown` hears each closed stage whose outcome HubSpot does not give. */
271
+ export const toPipeline = (raw, kind = "deal", unknown = () => { }) => {
272
+ const externalId = id(raw.id);
273
+ if (!externalId)
274
+ return null;
275
+ return {
276
+ externalId,
277
+ name: text(raw.label) ?? externalId,
278
+ stages: rawsOf(raw.stages).flatMap((stage, at) => {
279
+ const stageId = id(stage.id);
280
+ if (!stageId)
281
+ return [];
282
+ const order = Number(stage.displayOrder);
283
+ const name = text(stage.label) ?? stageId;
284
+ const { outcome, unknown: guessed } = outcomeOf(stage.metadata, kind, { id: stageId, label: text(stage.label) });
285
+ if (guessed)
286
+ unknown(name);
287
+ return [{ externalId: stageId, name, position: Number.isFinite(order) ? order : at, outcome }];
288
+ }),
289
+ };
290
+ };
291
+ /** An owner is who a record is assigned to: `hubspot_owner_id` is the owner's `id`, not its `userId` (owners guide). */
292
+ export const toUser = (raw) => {
293
+ const externalId = id(raw.id);
294
+ if (!externalId)
295
+ return null;
296
+ return {
297
+ externalId,
298
+ name: fullName(raw.firstName, raw.lastName) ?? text(raw.email),
299
+ email: text(raw.email),
300
+ active: raw.archived !== true,
301
+ };
302
+ };
303
+ /**
304
+ * The account's own properties of a kind (`hubspotDefined` false), what a row's `metadata` is keyed by. HubSpot's
305
+ * own properties are read by name in the mapping above and are not repeated there.
306
+ */
307
+ export const toField = (raw) => {
308
+ const code = text(raw.name);
309
+ if (!code || raw.hubspotDefined === true || raw.archived === true)
310
+ return null;
311
+ const type = text(raw.type) ?? "string";
312
+ const fieldType = text(raw.fieldType);
313
+ const options = type === "enumeration" && fieldType !== "booleancheckbox"
314
+ ? [
315
+ ...new Map(rawsOf(raw.options)
316
+ .filter((one) => one.hidden !== true)
317
+ .flatMap((one) => {
318
+ const value = text(one.value);
319
+ return value ? [[value, { id: value, label: text(one.label) ?? value }]] : [];
320
+ })).values(),
321
+ ]
322
+ : undefined;
323
+ return {
324
+ code,
325
+ label: text(raw.label),
326
+ type,
327
+ multiple: type === "enumeration" && fieldType === "checkbox",
328
+ filterable: true,
329
+ ...(options ? { options } : {}),
330
+ ...(fieldType === "phonenumber" ? { holds: "phone" } : {}),
331
+ };
332
+ };
333
+ //# sourceMappingURL=records.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/crm/records.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAW5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AAEjD,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,SAAS,CAAA;AA0B9F,MAAM,CAAC,MAAM,OAAO,GAAgC;IAClD,YAAY,EAAE;QACZ,IAAI,EAAE,WAAW;Q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AE,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,EAAE,CAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;YACxF,CAAC,CAAC,CACL,CAAC,MAAM,EAAE;SACX;QACH,CAAC,CAAC,SAAS,CAAA;IACf,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QACtB,IAAI;QACJ,QAAQ,EAAE,IAAI,KAAK,aAAa,IAAI,SAAS,KAAK,UAAU;QAC5D,UAAU,EAAE,IAAI;QAChB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,GAAG,CAAC,SAAS,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpE,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { type Raw } from "./records.js";
2
+ /** The search guide: 200 rows a page, 10,000 results a query (400 past it), 5 groups, 6 filters each, 18 in all. */
3
+ export declare const SEARCH_PAGE = 200;
4
+ export declare const SEARCH_CAP = 10000;
5
+ export declare const MAX_FILTERS_PER_GROUP = 6;
6
+ export interface Filter {
7
+ propertyName: string;
8
+ operator: string;
9
+ value?: string;
10
+ values?: string[];
11
+ }
12
+ export interface SearchRequest {
13
+ filters: Filter[];
14
+ sort: {
15
+ propertyName: string;
16
+ direction: "ASCENDING" | "DESCENDING";
17
+ };
18
+ properties: readonly string[];
19
+ limit: number;
20
+ offset: number;
21
+ query?: string;
22
+ }
23
+ export type Post = (path: string, body: Record<string, unknown>) => Promise<unknown>;
24
+ /**
25
+ * One search page. `sorts` takes objects as the search guide shows them; the spec types it as strings. `after` is the
26
+ * offset as an integer string (search guide, paging), sent only past the first page as the guide's examples do.
27
+ */
28
+ export declare const search: (post: Post, path: string, request: SearchRequest) => Promise<{
29
+ rows: Raw[];
30
+ more: boolean;
31
+ }>;
32
+ /** Where a round of changes stands: rows modified at or after `from`, the first `offset` of them read. */
33
+ export interface Spot {
34
+ from: number;
35
+ offset: number;
36
+ }
37
+ /**
38
+ * The next spot after a page sorted by modified time. Keyset, not the search's own offset: a row changed mid-round
39
+ * moves to the end, and an offset would then skip the row after it. Rows at the boundary time are read twice. A page
40
+ * that is all one time (a mass import) moves by offset inside it; past the cap, `null`.
41
+ */
42
+ export declare const nextSpot: (spot: Spot, rows: readonly Raw[], modified: string, limit: number) => Spot | null;
43
+ export declare const modifiedSince: (modified: string, spot: Spot, limit: number, properties: readonly string[]) => {
44
+ filters: {
45
+ propertyName: string;
46
+ operator: string;
47
+ value: string;
48
+ }[];
49
+ sort: {
50
+ propertyName: string;
51
+ direction: "ASCENDING";
52
+ };
53
+ properties: readonly string[];
54
+ limit: number;
55
+ offset: number;
56
+ };
57
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/crm/search.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8B,KAAK,GAAG,EAAa,MAAM,cAAc,CAAA;AAE9E,oHAAoH;AACpH,eAAO,MAAM,WAAW,MAAM,CAAA;AAC9B,eAAO,MAAM,UAAU,QAAS,CAAA;AAChC,eAAO,MAAM,qBAAqB,IAAI,CAAA;AAEtC,MAAM,WAAW,MAAM;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,WAAW,GAAG,YAAY,CAAA;KAAE,CAAA;IACrE,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAEpF;;;GAGG;AACH,eAAO,MAAM,MAAM,SAAgB,IAAI,QAAQ,MAAM,WAAW,aAAa;;;EAsB5E,CAAA;AAED,0GAA0G;AAC1G,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SAAU,IAAI,QAAQ,SAAS,GAAG,EAAE,YAAY,MAAM,SAAS,MAAM,KAAG,IAAI,GAAG,IAMnG,CAAA;AAED,eAAO,MAAM,aAAa,aAAc,MAAM,QAAQ,IAAI,SAAS,MAAM,cAAc,SAAS,MAAM,EAAE;;;;;;;;;;;;;CAO5E,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { SERVICE } from "../hubspot/transport.js";
3
+ import { msOf, nextOf, propertiesOf, resultsOf } from "./records.js";
4
+ /** The search guide: 200 rows a page, 10,000 results a query (400 past it), 5 groups, 6 filters each, 18 in all. */
5
+ export const SEARCH_PAGE = 200;
6
+ export const SEARCH_CAP = 10_000;
7
+ export const MAX_FILTERS_PER_GROUP = 6;
8
+ /**
9
+ * One search page. `sorts` takes objects as the search guide shows them; the spec types it as strings. `after` is the
10
+ * offset as an integer string (search guide, paging), sent only past the first page as the guide's examples do.
11
+ */
12
+ export const search = async (post, path, request) => {
13
+ if (request.filters.length > MAX_FILTERS_PER_GROUP)
14
+ throw new CliError("validation_error", `${SERVICE} search takes at most ${MAX_FILTERS_PER_GROUP} conditions together; drop some`, { reason: "hubspot.too-many-filters" });
15
+ if (request.offset + request.limit > SEARCH_CAP)
16
+ throw new CliError("validation_error", `${SERVICE} search reaches only its first ${SEARCH_CAP} results; narrow the query`, { reason: "hubspot.search-cap" });
17
+ const body = await post(`/crm/objects/2026-03/${path}/search`, {
18
+ filterGroups: request.filters.length ? [{ filters: request.filters }] : [],
19
+ sorts: [request.sort],
20
+ properties: [...request.properties],
21
+ limit: request.limit,
22
+ ...(request.offset ? { after: String(request.offset) } : {}),
23
+ ...(request.query ? { query: request.query } : {}),
24
+ });
25
+ return { rows: resultsOf(body), more: nextOf(body) !== null };
26
+ };
27
+ /**
28
+ * The next spot after a page sorted by modified time. Keyset, not the search's own offset: a row changed mid-round
29
+ * moves to the end, and an offset would then skip the row after it. Rows at the boundary time are read twice. A page
30
+ * that is all one time (a mass import) moves by offset inside it; past the cap, `null`.
31
+ */
32
+ export const nextSpot = (spot, rows, modified, limit) => {
33
+ const last = rows.at(-1);
34
+ const at = last ? (msOf(propertiesOf(last)[modified]) ?? msOf(last.updatedAt)) : null;
35
+ if (at !== null && at > spot.from)
36
+ return { from: at, offset: 0 };
37
+ const offset = spot.offset + rows.length;
38
+ return offset + limit > SEARCH_CAP ? null : { from: spot.from, offset };
39
+ };
40
+ export const modifiedSince = (modified, spot, limit, properties) => ({
41
+ filters: [{ propertyName: modified, operator: "GTE", value: String(spot.from) }],
42
+ sort: { propertyName: modified, direction: "ASCENDING" },
43
+ properties,
44
+ limit,
45
+ offset: spot.offset,
46
+ });
47
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/crm/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAY,SAAS,EAAE,MAAM,cAAc,CAAA;AAE9E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AY,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE;IACxD,UAAU;IACV,KAAK;IACL,MAAM,EAAE,IAAI,CAAC,MAAM;CACpB,CAAyB,CAAA"}
@@ -0,0 +1,32 @@
1
+ import { type CrmSource } from "@wirecat/cli-core/crm";
2
+ import { type HubSpotTransport } from "../hubspot/transport.js";
3
+ /**
4
+ * Re-read before the last cursor: rows HubSpot saved while the round ran, rows its search index had not shown yet
5
+ * ("a few moments", search guide), and this computer's clock running ahead of HubSpot's. A row read twice is only
6
+ * saved twice.
7
+ */
8
+ export declare const OVERLAP_MS: number;
9
+ /**
10
+ * The longest `properties=` a GET sends. Servers commonly refuse request lines past 8 KB; HubSpot names no limit, so
11
+ * an account with hundreds of custom properties reads the ones that fit, and the call says which it left out.
12
+ */
13
+ export declare const MAX_PROPERTIES_CHARS = 6000;
14
+ /** HubSpot's own properties first, always; then the account's own while they fit. */
15
+ export declare const fitted: (own: readonly string[], custom: readonly string[]) => {
16
+ properties: string;
17
+ dropped: string[];
18
+ };
19
+ export interface HubSpotSourceOptions {
20
+ now?: () => number;
21
+ /** Rows a full list asks per page; a test pages over a small account with a smaller one. */
22
+ page?: number;
23
+ /** Rows a search asks per page. */
24
+ searchPage?: number;
25
+ }
26
+ /**
27
+ * The account's CRM for core's sync: lists in full by `after`, changes by search on the modified time, deletions by a
28
+ * pass over every id, since HubSpot gives a private app no change feed (webhooks need a public app). A service key has
29
+ * no user, so there is no `self()` and the copy is the whole account.
30
+ */
31
+ export declare const hubspotCrmSource: (hub: () => HubSpotTransport, options?: HubSpotSourceOptions) => CrmSource;
32
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/crm/source.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,SAAS,EAIf,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,KAAK,gBAAgB,EAAgC,MAAM,yBAAyB,CAAA;AAsB7F;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAAc,CAAA;AAuDrC;;;GAGG;AACH,eAAO,MAAM,oBAAoB,OAAQ,CAAA;AAEzC,qFAAqF;AACrF,eAAO,MAAM,MAAM,QAAS,SAAS,MAAM,EAAE,UAAU,SAAS,MAAM,EAAE;;;CAavE,CAAA;AAyBD,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;IAClB,4FAA4F;IAC5F,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAS,MAAM,gBAAgB,YAAW,oBAAoB,KAAQ,SAgSlG,CAAA"}