digital-tools 2.1.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +19 -0
  3. package/README.md +2 -0
  4. package/dist/client.d.ts +109 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +69 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/define.d.ts +2 -2
  9. package/dist/define.d.ts.map +1 -1
  10. package/dist/define.js +21 -11
  11. package/dist/define.js.map +1 -1
  12. package/dist/function-ref.d.ts +229 -0
  13. package/dist/function-ref.d.ts.map +1 -0
  14. package/dist/function-ref.js +28 -0
  15. package/dist/function-ref.js.map +1 -0
  16. package/dist/function-sugar.d.ts +57 -0
  17. package/dist/function-sugar.d.ts.map +1 -0
  18. package/dist/function-sugar.js +79 -0
  19. package/dist/function-sugar.js.map +1 -0
  20. package/dist/index.d.ts +10 -3
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +24 -4
  23. package/dist/index.js.map +1 -1
  24. package/dist/providers/analytics/mixpanel.d.ts.map +1 -1
  25. package/dist/providers/analytics/mixpanel.js +21 -18
  26. package/dist/providers/analytics/mixpanel.js.map +1 -1
  27. package/dist/providers/calendar/cal-com.d.ts.map +1 -1
  28. package/dist/providers/calendar/cal-com.js +10 -10
  29. package/dist/providers/calendar/cal-com.js.map +1 -1
  30. package/dist/providers/calendar/google-calendar.d.ts.map +1 -1
  31. package/dist/providers/calendar/google-calendar.js +4 -4
  32. package/dist/providers/calendar/google-calendar.js.map +1 -1
  33. package/dist/providers/crm/hubspot.d.ts.map +1 -1
  34. package/dist/providers/crm/hubspot.js +107 -85
  35. package/dist/providers/crm/hubspot.js.map +1 -1
  36. package/dist/providers/development/github.d.ts.map +1 -1
  37. package/dist/providers/development/github.js +40 -43
  38. package/dist/providers/development/github.js.map +1 -1
  39. package/dist/providers/ecommerce/shopify.d.ts.map +1 -1
  40. package/dist/providers/ecommerce/shopify.js +79 -62
  41. package/dist/providers/ecommerce/shopify.js.map +1 -1
  42. package/dist/providers/email/resend.d.ts.map +1 -1
  43. package/dist/providers/email/resend.js +20 -16
  44. package/dist/providers/email/resend.js.map +1 -1
  45. package/dist/providers/email/sendgrid.d.ts.map +1 -1
  46. package/dist/providers/email/sendgrid.js +12 -9
  47. package/dist/providers/email/sendgrid.js.map +1 -1
  48. package/dist/providers/finance/stripe.d.ts.map +1 -1
  49. package/dist/providers/finance/stripe.js +44 -42
  50. package/dist/providers/finance/stripe.js.map +1 -1
  51. package/dist/providers/forms/typeform.d.ts.map +1 -1
  52. package/dist/providers/forms/typeform.js +68 -58
  53. package/dist/providers/forms/typeform.js.map +1 -1
  54. package/dist/providers/knowledge/notion.d.ts.map +1 -1
  55. package/dist/providers/knowledge/notion.js +75 -41
  56. package/dist/providers/knowledge/notion.js.map +1 -1
  57. package/dist/providers/marketing/mailchimp.d.ts.map +1 -1
  58. package/dist/providers/marketing/mailchimp.js +74 -61
  59. package/dist/providers/marketing/mailchimp.js.map +1 -1
  60. package/dist/providers/media/cloudinary.d.ts.map +1 -1
  61. package/dist/providers/media/cloudinary.js +30 -28
  62. package/dist/providers/media/cloudinary.js.map +1 -1
  63. package/dist/providers/messaging/slack.d.ts.map +1 -1
  64. package/dist/providers/messaging/slack.js +75 -58
  65. package/dist/providers/messaging/slack.js.map +1 -1
  66. package/dist/providers/messaging/twilio-sms.d.ts.map +1 -1
  67. package/dist/providers/messaging/twilio-sms.js +33 -15
  68. package/dist/providers/messaging/twilio-sms.js.map +1 -1
  69. package/dist/providers/project-management/linear.d.ts.map +1 -1
  70. package/dist/providers/project-management/linear.js +31 -27
  71. package/dist/providers/project-management/linear.js.map +1 -1
  72. package/dist/providers/spreadsheet/google-sheets.d.ts.map +1 -1
  73. package/dist/providers/spreadsheet/google-sheets.js +21 -18
  74. package/dist/providers/spreadsheet/google-sheets.js.map +1 -1
  75. package/dist/providers/spreadsheet/xlsx.d.ts.map +1 -1
  76. package/dist/providers/spreadsheet/xlsx.js +4 -4
  77. package/dist/providers/spreadsheet/xlsx.js.map +1 -1
  78. package/dist/providers/storage/index.js +1 -0
  79. package/dist/providers/storage/index.js.map +1 -1
  80. package/dist/providers/storage/s3.d.ts.map +1 -1
  81. package/dist/providers/storage/s3.js +36 -27
  82. package/dist/providers/storage/s3.js.map +1 -1
  83. package/dist/providers/support/zendesk.d.ts.map +1 -1
  84. package/dist/providers/support/zendesk.js +24 -25
  85. package/dist/providers/support/zendesk.js.map +1 -1
  86. package/dist/providers/tasks/todoist.d.ts.map +1 -1
  87. package/dist/providers/tasks/todoist.js +18 -18
  88. package/dist/providers/tasks/todoist.js.map +1 -1
  89. package/dist/providers/video-conferencing/google-meet.d.ts.map +1 -1
  90. package/dist/providers/video-conferencing/google-meet.js +11 -11
  91. package/dist/providers/video-conferencing/google-meet.js.map +1 -1
  92. package/dist/providers/video-conferencing/jitsi.js +14 -14
  93. package/dist/providers/video-conferencing/jitsi.js.map +1 -1
  94. package/dist/providers/video-conferencing/teams.d.ts.map +1 -1
  95. package/dist/providers/video-conferencing/teams.js +9 -7
  96. package/dist/providers/video-conferencing/teams.js.map +1 -1
  97. package/dist/providers/video-conferencing/zoom.d.ts.map +1 -1
  98. package/dist/providers/video-conferencing/zoom.js +26 -24
  99. package/dist/providers/video-conferencing/zoom.js.map +1 -1
  100. package/dist/tools/data.d.ts.map +1 -1
  101. package/dist/tools/data.js +5 -12
  102. package/dist/tools/data.js.map +1 -1
  103. package/dist/tools/index.d.ts +1 -0
  104. package/dist/tools/index.d.ts.map +1 -1
  105. package/dist/tools/index.js +1 -0
  106. package/dist/tools/index.js.map +1 -1
  107. package/dist/tools/system.d.ts +289 -0
  108. package/dist/tools/system.d.ts.map +1 -0
  109. package/dist/tools/system.js +752 -0
  110. package/dist/tools/system.js.map +1 -0
  111. package/dist/tools/web.d.ts.map +1 -1
  112. package/dist/tools/web.js +22 -10
  113. package/dist/tools/web.js.map +1 -1
  114. package/dist/track-record.d.ts +101 -0
  115. package/dist/track-record.d.ts.map +1 -0
  116. package/dist/track-record.js +17 -0
  117. package/dist/track-record.js.map +1 -0
  118. package/dist/types.d.ts +210 -9
  119. package/dist/types.d.ts.map +1 -1
  120. package/dist/verb-registration.d.ts +122 -0
  121. package/dist/verb-registration.d.ts.map +1 -0
  122. package/dist/verb-registration.js +176 -0
  123. package/dist/verb-registration.js.map +1 -0
  124. package/dist/worker.d.ts +93 -0
  125. package/dist/worker.d.ts.map +1 -0
  126. package/dist/worker.js +315 -0
  127. package/dist/worker.js.map +1 -0
  128. package/dist/wrap.d.ts +89 -0
  129. package/dist/wrap.d.ts.map +1 -0
  130. package/dist/wrap.js +225 -0
  131. package/dist/wrap.js.map +1 -0
  132. package/package.json +31 -14
  133. package/src/client.ts +136 -0
  134. package/src/define.ts +30 -24
  135. package/src/function-ref.ts +264 -0
  136. package/src/function-sugar.ts +134 -0
  137. package/src/index.ts +132 -10
  138. package/src/providers/analytics/mixpanel.ts +19 -18
  139. package/src/providers/calendar/cal-com.ts +29 -18
  140. package/src/providers/calendar/google-calendar.ts +20 -14
  141. package/src/providers/crm/hubspot.ts +225 -99
  142. package/src/providers/development/github.ts +206 -135
  143. package/src/providers/ecommerce/shopify.ts +250 -89
  144. package/src/providers/email/resend.ts +101 -28
  145. package/src/providers/email/sendgrid.ts +12 -9
  146. package/src/providers/finance/stripe.ts +128 -49
  147. package/src/providers/forms/typeform.ts +74 -58
  148. package/src/providers/knowledge/notion.ts +340 -88
  149. package/src/providers/marketing/mailchimp.ts +86 -70
  150. package/src/providers/media/cloudinary.ts +99 -41
  151. package/src/providers/messaging/slack.ts +283 -85
  152. package/src/providers/messaging/twilio-sms.ts +35 -15
  153. package/src/providers/project-management/linear.ts +143 -55
  154. package/src/providers/spreadsheet/google-sheets.ts +222 -56
  155. package/src/providers/spreadsheet/xlsx.ts +47 -16
  156. package/src/providers/storage/s3.ts +119 -47
  157. package/src/providers/support/zendesk.ts +196 -46
  158. package/src/providers/tasks/todoist.ts +20 -26
  159. package/src/providers/video-conferencing/google-meet.ts +17 -20
  160. package/src/providers/video-conferencing/jitsi.ts +14 -14
  161. package/src/providers/video-conferencing/teams.ts +14 -13
  162. package/src/providers/video-conferencing/zoom.ts +54 -49
  163. package/src/tools/data.ts +6 -16
  164. package/src/tools/index.ts +1 -0
  165. package/src/tools/system.ts +887 -0
  166. package/src/tools/web.ts +22 -10
  167. package/src/track-record.ts +106 -0
  168. package/src/types.ts +241 -13
  169. package/src/verb-registration.ts +197 -0
  170. package/src/worker.ts +370 -0
  171. package/src/wrap.ts +260 -0
  172. package/test/client.test.ts +146 -0
  173. package/test/communication-tools-extended.test.ts +734 -0
  174. package/test/data-tools-extended.test.ts +743 -0
  175. package/test/define-extended.test.ts +819 -0
  176. package/test/define.test.ts +150 -41
  177. package/test/entities.test.ts +623 -0
  178. package/test/extended-entities.test.ts +1228 -0
  179. package/test/provider-implementations.test.ts +725 -0
  180. package/test/provider-registry-extended.test.ts +583 -0
  181. package/test/providers/google-sheets.test.ts +851 -0
  182. package/test/providers/helpers.ts +554 -0
  183. package/test/providers/hubspot.test.ts +576 -0
  184. package/test/providers/slack.test.ts +932 -0
  185. package/test/providers/stripe.test.ts +701 -0
  186. package/test/providers.test.ts +578 -0
  187. package/test/system-tools-extended.test.ts +632 -0
  188. package/test/system.test.ts +673 -0
  189. package/test/tools.test.ts +15 -11
  190. package/test/types.test.ts +402 -0
  191. package/test/verb-registration.test.ts +395 -0
  192. package/test/web-tools.test.ts +553 -0
  193. package/test/worker-extended.test.ts +699 -0
  194. package/test/worker.test.ts +576 -0
  195. package/test/wrap.test.ts +366 -0
  196. package/tsconfig.json +3 -13
  197. package/vitest.config.ts +37 -0
  198. package/wrangler.jsonc +9 -0
  199. package/LICENSE +0 -21
  200. package/dist/providers/voice/vapi.d.ts +0 -27
  201. package/dist/providers/voice/vapi.d.ts.map +0 -1
  202. package/dist/providers/voice/vapi.js +0 -440
  203. package/dist/providers/voice/vapi.js.map +0 -1
  204. package/src/define.js +0 -259
  205. package/src/entities/advertising.js +0 -999
  206. package/src/entities/ai.js +0 -756
  207. package/src/entities/analytics.js +0 -1588
  208. package/src/entities/automation.js +0 -601
  209. package/src/entities/communication.js +0 -1150
  210. package/src/entities/crm.js +0 -1386
  211. package/src/entities/design.js +0 -546
  212. package/src/entities/development.js +0 -2212
  213. package/src/entities/document.js +0 -874
  214. package/src/entities/ecommerce.js +0 -1429
  215. package/src/entities/experiment.js +0 -1039
  216. package/src/entities/finance.js +0 -3478
  217. package/src/entities/forms.js +0 -1892
  218. package/src/entities/hr.js +0 -661
  219. package/src/entities/identity.js +0 -997
  220. package/src/entities/index.js +0 -282
  221. package/src/entities/infrastructure.js +0 -1153
  222. package/src/entities/knowledge.js +0 -1438
  223. package/src/entities/marketing.js +0 -1610
  224. package/src/entities/media.js +0 -1634
  225. package/src/entities/notification.js +0 -1199
  226. package/src/entities/presentation.js +0 -1274
  227. package/src/entities/productivity.js +0 -1317
  228. package/src/entities/project-management.js +0 -1136
  229. package/src/entities/recruiting.js +0 -736
  230. package/src/entities/shipping.js +0 -509
  231. package/src/entities/signature.js +0 -1102
  232. package/src/entities/site.js +0 -222
  233. package/src/entities/spreadsheet.js +0 -1341
  234. package/src/entities/storage.js +0 -1198
  235. package/src/entities/support.js +0 -1166
  236. package/src/entities/video-conferencing.js +0 -1750
  237. package/src/entities/video.js +0 -950
  238. package/src/entities.js +0 -1663
  239. package/src/index.js +0 -74
  240. package/src/providers/analytics/index.js +0 -17
  241. package/src/providers/analytics/mixpanel.js +0 -255
  242. package/src/providers/calendar/cal-com.js +0 -303
  243. package/src/providers/calendar/google-calendar.js +0 -335
  244. package/src/providers/calendar/index.js +0 -20
  245. package/src/providers/crm/hubspot.js +0 -566
  246. package/src/providers/crm/index.js +0 -17
  247. package/src/providers/development/github.js +0 -472
  248. package/src/providers/development/index.js +0 -17
  249. package/src/providers/ecommerce/index.js +0 -17
  250. package/src/providers/ecommerce/shopify.js +0 -378
  251. package/src/providers/email/index.js +0 -20
  252. package/src/providers/email/resend.js +0 -258
  253. package/src/providers/email/sendgrid.js +0 -161
  254. package/src/providers/finance/index.js +0 -17
  255. package/src/providers/finance/stripe.js +0 -549
  256. package/src/providers/forms/index.js +0 -17
  257. package/src/providers/forms/typeform.js +0 -500
  258. package/src/providers/index.js +0 -123
  259. package/src/providers/knowledge/index.js +0 -17
  260. package/src/providers/knowledge/notion.js +0 -389
  261. package/src/providers/marketing/index.js +0 -17
  262. package/src/providers/marketing/mailchimp.js +0 -443
  263. package/src/providers/media/cloudinary.js +0 -318
  264. package/src/providers/media/index.js +0 -17
  265. package/src/providers/messaging/index.js +0 -20
  266. package/src/providers/messaging/slack.js +0 -393
  267. package/src/providers/messaging/twilio-sms.js +0 -249
  268. package/src/providers/project-management/index.js +0 -17
  269. package/src/providers/project-management/linear.js +0 -575
  270. package/src/providers/registry.js +0 -86
  271. package/src/providers/spreadsheet/google-sheets.js +0 -375
  272. package/src/providers/spreadsheet/index.js +0 -20
  273. package/src/providers/spreadsheet/xlsx.js +0 -423
  274. package/src/providers/storage/index.js +0 -24
  275. package/src/providers/storage/s3.js +0 -419
  276. package/src/providers/support/index.js +0 -17
  277. package/src/providers/support/zendesk.js +0 -373
  278. package/src/providers/tasks/index.js +0 -17
  279. package/src/providers/tasks/todoist.js +0 -286
  280. package/src/providers/types.js +0 -9
  281. package/src/providers/video-conferencing/google-meet.js +0 -286
  282. package/src/providers/video-conferencing/index.js +0 -31
  283. package/src/providers/video-conferencing/jitsi.js +0 -254
  284. package/src/providers/video-conferencing/teams.js +0 -270
  285. package/src/providers/video-conferencing/zoom.js +0 -332
  286. package/src/registry.js +0 -128
  287. package/src/tools/communication.js +0 -184
  288. package/src/tools/data.js +0 -205
  289. package/src/tools/index.js +0 -11
  290. package/src/tools/web.js +0 -137
  291. package/src/types.js +0 -10
  292. package/test/define.test.js +0 -306
  293. package/test/registry.test.js +0 -357
  294. package/test/tools.test.js +0 -363
@@ -25,6 +25,101 @@ import { defineProvider } from '../registry.js'
25
25
 
26
26
  const HUBSPOT_API_URL = 'https://api.hubapi.com/crm/v3'
27
27
 
28
+ // =============================================================================
29
+ // HubSpot API Response Types
30
+ // =============================================================================
31
+
32
+ /** HubSpot contact properties from API */
33
+ interface HubSpotContactProperties {
34
+ firstname?: string
35
+ lastname?: string
36
+ email?: string
37
+ phone?: string
38
+ company?: string
39
+ jobtitle?: string
40
+ hubspot_owner_id?: string
41
+ createdate?: string
42
+ lastmodifieddate?: string
43
+ [key: string]: string | undefined
44
+ }
45
+
46
+ /** HubSpot contact response from API */
47
+ interface HubSpotContact {
48
+ id: string
49
+ properties: HubSpotContactProperties
50
+ createdAt?: string
51
+ updatedAt?: string
52
+ }
53
+
54
+ /** HubSpot deal properties from API */
55
+ interface HubSpotDealProperties {
56
+ dealname?: string
57
+ amount?: string
58
+ deal_currency_code?: string
59
+ dealstage?: string
60
+ hs_deal_stage_probability?: string
61
+ associatedcontactid?: string
62
+ associatedcompanyid?: string
63
+ hubspot_owner_id?: string
64
+ closedate?: string
65
+ createdate?: string
66
+ hs_lastmodifieddate?: string
67
+ hs_date_entered_closedwon?: string
68
+ hs_date_entered_closedlost?: string
69
+ [key: string]: string | undefined
70
+ }
71
+
72
+ /** HubSpot deal response from API */
73
+ interface HubSpotDeal {
74
+ id: string
75
+ properties: HubSpotDealProperties
76
+ createdAt?: string
77
+ updatedAt?: string
78
+ }
79
+
80
+ /** HubSpot engagement properties from API */
81
+ interface HubSpotEngagementProperties {
82
+ hs_engagement_type?: string
83
+ hs_engagement_subject?: string
84
+ hs_note_body?: string
85
+ hs_email_text?: string
86
+ hubspot_owner_id?: string
87
+ hs_task_due_date?: string
88
+ hs_engagement_completed_at?: string
89
+ hs_createdate?: string
90
+ [key: string]: string | undefined
91
+ }
92
+
93
+ /** HubSpot engagement response from API */
94
+ interface HubSpotEngagement {
95
+ id: string
96
+ properties: HubSpotEngagementProperties
97
+ createdAt?: string
98
+ }
99
+
100
+ /** HubSpot paginated list response */
101
+ interface HubSpotListResponse<T> {
102
+ results: T[]
103
+ total?: number
104
+ paging?: {
105
+ next?: {
106
+ after: string
107
+ }
108
+ }
109
+ }
110
+
111
+ /** HubSpot association result */
112
+ interface HubSpotAssociationResult {
113
+ id: string
114
+ }
115
+
116
+ /** HubSpot error response */
117
+ interface HubSpotErrorResponse {
118
+ message?: string
119
+ status?: string
120
+ category?: string
121
+ }
122
+
28
123
  /**
29
124
  * HubSpot provider info
30
125
  */
@@ -42,60 +137,70 @@ export const hubspotInfo: ProviderInfo = {
42
137
  /**
43
138
  * Map HubSpot contact properties to CRMContactData
44
139
  */
45
- function mapContactFromHubSpot(contact: any): CRMContactData {
140
+ function mapContactFromHubSpot(contact: HubSpotContact): CRMContactData {
46
141
  const props = contact.properties || {}
47
142
  return {
48
143
  id: contact.id,
49
- firstName: props.firstname || '',
50
- lastName: props.lastname || '',
51
- email: props.email,
52
- phone: props.phone,
53
- company: props.company,
54
- title: props.jobtitle,
55
- ownerId: props.hubspot_owner_id,
56
- createdAt: new Date(props.createdate || contact.createdAt),
57
- updatedAt: new Date(props.lastmodifieddate || contact.updatedAt),
144
+ firstName: props['firstname'] || '',
145
+ lastName: props['lastname'] || '',
146
+ ...(props['email'] !== undefined && { email: props['email'] }),
147
+ ...(props['phone'] !== undefined && { phone: props['phone'] }),
148
+ ...(props['company'] !== undefined && { company: props['company'] }),
149
+ ...(props['jobtitle'] !== undefined && { title: props['jobtitle'] }),
150
+ ...(props['hubspot_owner_id'] !== undefined && { ownerId: props['hubspot_owner_id'] }),
151
+ createdAt: new Date(props['createdate'] || contact.createdAt || Date.now()),
152
+ updatedAt: new Date(props['lastmodifieddate'] || contact.updatedAt || Date.now()),
58
153
  }
59
154
  }
60
155
 
61
156
  /**
62
157
  * Map HubSpot deal properties to DealData
63
158
  */
64
- function mapDealFromHubSpot(deal: any): DealData {
159
+ function mapDealFromHubSpot(deal: HubSpotDeal): DealData {
65
160
  const props = deal.properties || {}
66
161
  return {
67
162
  id: deal.id,
68
- name: props.dealname || '',
69
- value: props.amount ? parseFloat(props.amount) : undefined,
70
- currency: props.deal_currency_code,
71
- stage: props.dealstage || '',
72
- probability: props.hs_deal_stage_probability ? parseFloat(props.hs_deal_stage_probability) : undefined,
73
- contactId: props.associatedcontactid,
74
- companyId: props.associatedcompanyid,
75
- ownerId: props.hubspot_owner_id,
76
- closeDate: props.closedate ? new Date(props.closedate) : undefined,
77
- createdAt: new Date(props.createdate || deal.createdAt),
78
- updatedAt: new Date(props.hs_lastmodifieddate || deal.updatedAt),
79
- wonAt: props.hs_date_entered_closedwon ? new Date(props.hs_date_entered_closedwon) : undefined,
80
- lostAt: props.hs_date_entered_closedlost ? new Date(props.hs_date_entered_closedlost) : undefined,
163
+ name: props['dealname'] || '',
164
+ ...(props['amount'] !== undefined && { value: parseFloat(props['amount']) }),
165
+ ...(props['deal_currency_code'] !== undefined && { currency: props['deal_currency_code'] }),
166
+ stage: props['dealstage'] || '',
167
+ ...(props['hs_deal_stage_probability'] !== undefined && {
168
+ probability: parseFloat(props['hs_deal_stage_probability']),
169
+ }),
170
+ ...(props['associatedcontactid'] !== undefined && { contactId: props['associatedcontactid'] }),
171
+ ...(props['associatedcompanyid'] !== undefined && { companyId: props['associatedcompanyid'] }),
172
+ ...(props['hubspot_owner_id'] !== undefined && { ownerId: props['hubspot_owner_id'] }),
173
+ ...(props['closedate'] !== undefined && { closeDate: new Date(props['closedate']) }),
174
+ createdAt: new Date(props['createdate'] || deal.createdAt || Date.now()),
175
+ updatedAt: new Date(props['hs_lastmodifieddate'] || deal.updatedAt || Date.now()),
176
+ ...(props['hs_date_entered_closedwon'] !== undefined && {
177
+ wonAt: new Date(props['hs_date_entered_closedwon']),
178
+ }),
179
+ ...(props['hs_date_entered_closedlost'] !== undefined && {
180
+ lostAt: new Date(props['hs_date_entered_closedlost']),
181
+ }),
81
182
  }
82
183
  }
83
184
 
84
185
  /**
85
186
  * Map HubSpot engagement to CRMActivityData
86
187
  */
87
- function mapActivityFromHubSpot(engagement: any, contactId: string): CRMActivityData {
188
+ function mapActivityFromHubSpot(engagement: HubSpotEngagement, contactId: string): CRMActivityData {
88
189
  const props = engagement.properties || {}
89
190
  return {
90
191
  id: engagement.id,
91
- type: props.hs_engagement_type || 'note',
92
- subject: props.hs_engagement_subject || '',
93
- body: props.hs_note_body || props.hs_email_text || '',
192
+ type: props['hs_engagement_type'] || 'note',
193
+ subject: props['hs_engagement_subject'] || '',
194
+ body: props['hs_note_body'] || props['hs_email_text'] || '',
94
195
  contactId,
95
- ownerId: props.hubspot_owner_id || '',
96
- dueDate: props.hs_task_due_date ? new Date(props.hs_task_due_date) : undefined,
97
- completedAt: props.hs_engagement_completed_at ? new Date(props.hs_engagement_completed_at) : undefined,
98
- createdAt: new Date(props.hs_createdate || engagement.createdAt),
196
+ ownerId: props['hubspot_owner_id'] || '',
197
+ ...(props['hs_task_due_date'] !== undefined && {
198
+ dueDate: new Date(props['hs_task_due_date']),
199
+ }),
200
+ ...(props['hs_engagement_completed_at'] !== undefined && {
201
+ completedAt: new Date(props['hs_engagement_completed_at']),
202
+ }),
203
+ createdAt: new Date(props['hs_createdate'] || engagement.createdAt || Date.now()),
99
204
  }
100
205
  }
101
206
 
@@ -153,7 +258,10 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
153
258
  }
154
259
 
155
260
  // Helper function to associate engagement with contact
156
- async function associateEngagementWithContact(engagementId: string, contactId: string): Promise<void> {
261
+ async function associateEngagementWithContact(
262
+ engagementId: string,
263
+ contactId: string
264
+ ): Promise<void> {
157
265
  try {
158
266
  const response = await fetch(
159
267
  `${baseUrl}/objects/engagements/${engagementId}/associations/contacts/${contactId}/engagement_to_contact`,
@@ -217,19 +325,23 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
217
325
  },
218
326
 
219
327
  async createContact(contact: CreateContactOptions): Promise<CRMContactData> {
220
- const properties: Record<string, any> = {
328
+ const properties: Record<string, string> = {
221
329
  firstname: contact.firstName,
222
330
  lastname: contact.lastName,
223
331
  }
224
332
 
225
- if (contact.email) properties.email = contact.email
226
- if (contact.phone) properties.phone = contact.phone
227
- if (contact.company) properties.company = contact.company
228
- if (contact.title) properties.jobtitle = contact.title
333
+ if (contact.email) properties['email'] = contact.email
334
+ if (contact.phone) properties['phone'] = contact.phone
335
+ if (contact.company) properties['company'] = contact.company
336
+ if (contact.title) properties['jobtitle'] = contact.title
229
337
 
230
338
  // Add custom fields
231
339
  if (contact.customFields) {
232
- Object.assign(properties, contact.customFields)
340
+ for (const [key, value] of Object.entries(contact.customFields)) {
341
+ if (value !== undefined && value !== null) {
342
+ properties[key] = String(value)
343
+ }
344
+ }
233
345
  }
234
346
 
235
347
  try {
@@ -243,11 +355,11 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
243
355
  })
244
356
 
245
357
  if (!response.ok) {
246
- const errorData = await response.json().catch(() => ({}))
247
- throw new Error((errorData as any)?.message || `HTTP ${response.status}`)
358
+ const errorData = (await response.json().catch(() => ({}))) as HubSpotErrorResponse
359
+ throw new Error(errorData.message || `HTTP ${response.status}`)
248
360
  }
249
361
 
250
- const data: any = await response.json()
362
+ const data = (await response.json()) as HubSpotContact
251
363
  return mapContactFromHubSpot(data)
252
364
  } catch (error) {
253
365
  throw new Error(
@@ -273,7 +385,7 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
273
385
  throw new Error(`HTTP ${response.status}`)
274
386
  }
275
387
 
276
- const data: any = await response.json()
388
+ const data = (await response.json()) as HubSpotContact
277
389
  return mapContactFromHubSpot(data)
278
390
  } catch (error) {
279
391
  if (error instanceof Error && error.message.includes('404')) {
@@ -289,18 +401,22 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
289
401
  contactId: string,
290
402
  updates: Partial<CreateContactOptions>
291
403
  ): Promise<CRMContactData> {
292
- const properties: Record<string, any> = {}
404
+ const properties: Record<string, string> = {}
293
405
 
294
- if (updates.firstName !== undefined) properties.firstname = updates.firstName
295
- if (updates.lastName !== undefined) properties.lastname = updates.lastName
296
- if (updates.email !== undefined) properties.email = updates.email
297
- if (updates.phone !== undefined) properties.phone = updates.phone
298
- if (updates.company !== undefined) properties.company = updates.company
299
- if (updates.title !== undefined) properties.jobtitle = updates.title
406
+ if (updates.firstName !== undefined) properties['firstname'] = updates.firstName
407
+ if (updates.lastName !== undefined) properties['lastname'] = updates.lastName
408
+ if (updates.email !== undefined) properties['email'] = updates.email
409
+ if (updates.phone !== undefined) properties['phone'] = updates.phone
410
+ if (updates.company !== undefined) properties['company'] = updates.company
411
+ if (updates.title !== undefined) properties['jobtitle'] = updates.title
300
412
 
301
413
  // Add custom fields
302
414
  if (updates.customFields) {
303
- Object.assign(properties, updates.customFields)
415
+ for (const [key, value] of Object.entries(updates.customFields)) {
416
+ if (value !== undefined && value !== null) {
417
+ properties[key] = String(value)
418
+ }
419
+ }
304
420
  }
305
421
 
306
422
  try {
@@ -314,11 +430,11 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
314
430
  })
315
431
 
316
432
  if (!response.ok) {
317
- const errorData = await response.json().catch(() => ({}))
318
- throw new Error((errorData as any)?.message || `HTTP ${response.status}`)
433
+ const errorData = (await response.json().catch(() => ({}))) as HubSpotErrorResponse
434
+ throw new Error(errorData.message || `HTTP ${response.status}`)
319
435
  }
320
436
 
321
- const data: any = await response.json()
437
+ const data = (await response.json()) as HubSpotContact
322
438
  return mapContactFromHubSpot(data)
323
439
  } catch (error) {
324
440
  throw new Error(
@@ -348,12 +464,12 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
348
464
  throw new Error(`HTTP ${response.status}`)
349
465
  }
350
466
 
351
- const data: any = await response.json()
467
+ const data = (await response.json()) as HubSpotListResponse<HubSpotContact>
352
468
  return {
353
469
  items: (data.results || []).map(mapContactFromHubSpot),
354
- total: data.total,
470
+ ...(data.total !== undefined && { total: data.total }),
355
471
  hasMore: !!data.paging?.next,
356
- nextCursor: data.paging?.next?.after,
472
+ ...(data.paging?.next?.after !== undefined && { nextCursor: data.paging.next.after }),
357
473
  }
358
474
  } catch (error) {
359
475
  throw new Error(
@@ -400,7 +516,7 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
400
516
  throw new Error(`HTTP ${response.status}`)
401
517
  }
402
518
 
403
- const data: any = await response.json()
519
+ const data = (await response.json()) as HubSpotListResponse<HubSpotContact>
404
520
  return (data.results || []).map(mapContactFromHubSpot)
405
521
  } catch (error) {
406
522
  throw new Error(
@@ -410,15 +526,16 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
410
526
  },
411
527
 
412
528
  async createDeal(deal: CreateDealOptions): Promise<DealData> {
413
- const properties: Record<string, any> = {
529
+ const properties: Record<string, string> = {
414
530
  dealname: deal.name,
415
531
  dealstage: deal.stage,
416
532
  }
417
533
 
418
- if (deal.value !== undefined) properties.amount = String(deal.value)
419
- if (deal.currency) properties.deal_currency_code = deal.currency
420
- if (deal.closeDate) properties.closedate = deal.closeDate.toISOString()
421
- if (deal.probability !== undefined) properties.hs_deal_stage_probability = String(deal.probability)
534
+ if (deal.value !== undefined) properties['amount'] = String(deal.value)
535
+ if (deal.currency) properties['deal_currency_code'] = deal.currency
536
+ if (deal.closeDate) properties['closedate'] = deal.closeDate.toISOString()
537
+ if (deal.probability !== undefined)
538
+ properties['hs_deal_stage_probability'] = String(deal.probability)
422
539
 
423
540
  try {
424
541
  const response = await fetch(`${baseUrl}/objects/deals`, {
@@ -431,11 +548,11 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
431
548
  })
432
549
 
433
550
  if (!response.ok) {
434
- const errorData = await response.json().catch(() => ({}))
435
- throw new Error((errorData as any)?.message || `HTTP ${response.status}`)
551
+ const errorData = (await response.json().catch(() => ({}))) as HubSpotErrorResponse
552
+ throw new Error(errorData.message || `HTTP ${response.status}`)
436
553
  }
437
554
 
438
- const data: any = await response.json()
555
+ const data = (await response.json()) as HubSpotDeal
439
556
  const dealData = mapDealFromHubSpot(data)
440
557
 
441
558
  // Associate with contact if specified
@@ -473,7 +590,7 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
473
590
  throw new Error(`HTTP ${response.status}`)
474
591
  }
475
592
 
476
- const data: any = await response.json()
593
+ const data = (await response.json()) as HubSpotDeal
477
594
  return mapDealFromHubSpot(data)
478
595
  } catch (error) {
479
596
  if (error instanceof Error && error.message.includes('404')) {
@@ -486,14 +603,15 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
486
603
  },
487
604
 
488
605
  async updateDeal(dealId: string, updates: Partial<CreateDealOptions>): Promise<DealData> {
489
- const properties: Record<string, any> = {}
606
+ const properties: Record<string, string> = {}
490
607
 
491
- if (updates.name !== undefined) properties.dealname = updates.name
492
- if (updates.stage !== undefined) properties.dealstage = updates.stage
493
- if (updates.value !== undefined) properties.amount = String(updates.value)
494
- if (updates.currency !== undefined) properties.deal_currency_code = updates.currency
495
- if (updates.closeDate !== undefined) properties.closedate = updates.closeDate.toISOString()
496
- if (updates.probability !== undefined) properties.hs_deal_stage_probability = String(updates.probability)
608
+ if (updates.name !== undefined) properties['dealname'] = updates.name
609
+ if (updates.stage !== undefined) properties['dealstage'] = updates.stage
610
+ if (updates.value !== undefined) properties['amount'] = String(updates.value)
611
+ if (updates.currency !== undefined) properties['deal_currency_code'] = updates.currency
612
+ if (updates.closeDate !== undefined) properties['closedate'] = updates.closeDate.toISOString()
613
+ if (updates.probability !== undefined)
614
+ properties['hs_deal_stage_probability'] = String(updates.probability)
497
615
 
498
616
  try {
499
617
  const response = await fetch(`${baseUrl}/objects/deals/${dealId}`, {
@@ -506,11 +624,11 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
506
624
  })
507
625
 
508
626
  if (!response.ok) {
509
- const errorData = await response.json().catch(() => ({}))
510
- throw new Error((errorData as any)?.message || `HTTP ${response.status}`)
627
+ const errorData = (await response.json().catch(() => ({}))) as HubSpotErrorResponse
628
+ throw new Error(errorData.message || `HTTP ${response.status}`)
511
629
  }
512
630
 
513
- const data: any = await response.json()
631
+ const data = (await response.json()) as HubSpotDeal
514
632
  return mapDealFromHubSpot(data)
515
633
  } catch (error) {
516
634
  throw new Error(
@@ -540,12 +658,12 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
540
658
  throw new Error(`HTTP ${response.status}`)
541
659
  }
542
660
 
543
- const data: any = await response.json()
661
+ const data = (await response.json()) as HubSpotListResponse<HubSpotDeal>
544
662
  return {
545
663
  items: (data.results || []).map(mapDealFromHubSpot),
546
- total: data.total,
664
+ ...(data.total !== undefined && { total: data.total }),
547
665
  hasMore: !!data.paging?.next,
548
- nextCursor: data.paging?.next?.after,
666
+ ...(data.paging?.next?.after !== undefined && { nextCursor: data.paging.next.after }),
549
667
  }
550
668
  } catch (error) {
551
669
  throw new Error(
@@ -554,29 +672,37 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
554
672
  }
555
673
  },
556
674
 
557
- async logActivity(contactId: string, activity: CreateActivityOptions): Promise<CRMActivityData> {
675
+ async logActivity(
676
+ contactId: string,
677
+ activity: CreateActivityOptions
678
+ ): Promise<CRMActivityData> {
558
679
  // Map activity type to HubSpot engagement type
559
- const engagementType = activity.type === 'email' ? 'EMAIL' :
560
- activity.type === 'call' ? 'CALL' :
561
- activity.type === 'meeting' ? 'MEETING' :
562
- activity.type === 'task' ? 'TASK' :
563
- 'NOTE'
564
-
565
- const properties: Record<string, any> = {
680
+ const engagementType =
681
+ activity.type === 'email'
682
+ ? 'EMAIL'
683
+ : activity.type === 'call'
684
+ ? 'CALL'
685
+ : activity.type === 'meeting'
686
+ ? 'MEETING'
687
+ : activity.type === 'task'
688
+ ? 'TASK'
689
+ : 'NOTE'
690
+
691
+ const properties: Record<string, string> = {
566
692
  hs_engagement_type: engagementType.toLowerCase(),
567
693
  hs_engagement_subject: activity.subject,
568
694
  }
569
695
 
570
696
  if (activity.body) {
571
697
  if (engagementType === 'NOTE') {
572
- properties.hs_note_body = activity.body
698
+ properties['hs_note_body'] = activity.body
573
699
  } else if (engagementType === 'EMAIL') {
574
- properties.hs_email_text = activity.body
700
+ properties['hs_email_text'] = activity.body
575
701
  }
576
702
  }
577
703
 
578
704
  if (activity.dueDate) {
579
- properties.hs_task_due_date = activity.dueDate.toISOString()
705
+ properties['hs_task_due_date'] = activity.dueDate.toISOString()
580
706
  }
581
707
 
582
708
  try {
@@ -590,11 +716,11 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
590
716
  })
591
717
 
592
718
  if (!response.ok) {
593
- const errorData = await response.json().catch(() => ({}))
594
- throw new Error((errorData as any)?.message || `HTTP ${response.status}`)
719
+ const errorData = (await response.json().catch(() => ({}))) as HubSpotErrorResponse
720
+ throw new Error(errorData.message || `HTTP ${response.status}`)
595
721
  }
596
722
 
597
- const data: any = await response.json()
723
+ const data = (await response.json()) as HubSpotEngagement
598
724
 
599
725
  // Associate engagement with contact
600
726
  await associateEngagementWithContact(data.id, contactId)
@@ -624,8 +750,8 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
624
750
  throw new Error(`HTTP ${response.status}`)
625
751
  }
626
752
 
627
- const data: any = await response.json()
628
- const engagementIds = (data.results || []).map((r: any) => r.id)
753
+ const data = (await response.json()) as HubSpotListResponse<HubSpotAssociationResult>
754
+ const engagementIds = (data.results || []).map((r) => r.id)
629
755
 
630
756
  if (engagementIds.length === 0) {
631
757
  return []
@@ -641,15 +767,15 @@ export function createHubSpotProvider(config: ProviderConfig): CRMProvider {
641
767
  },
642
768
  })
643
769
  if (engResponse.ok) {
644
- return engResponse.json()
770
+ return (await engResponse.json()) as HubSpotEngagement
645
771
  }
646
772
  return null
647
773
  })
648
774
  )
649
775
 
650
776
  return engagements
651
- .filter((eng: any) => eng !== null)
652
- .map((eng: any) => mapActivityFromHubSpot(eng, contactId))
777
+ .filter((eng): eng is HubSpotEngagement => eng !== null)
778
+ .map((eng) => mapActivityFromHubSpot(eng, contactId))
653
779
  } catch (error) {
654
780
  throw new Error(
655
781
  `Failed to list activities: ${error instanceof Error ? error.message : 'Unknown error'}`