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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +2 -0
- package/dist/client.d.ts +109 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/define.d.ts +2 -2
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +21 -11
- package/dist/define.js.map +1 -1
- package/dist/function-ref.d.ts +229 -0
- package/dist/function-ref.d.ts.map +1 -0
- package/dist/function-ref.js +28 -0
- package/dist/function-ref.js.map +1 -0
- package/dist/function-sugar.d.ts +57 -0
- package/dist/function-sugar.d.ts.map +1 -0
- package/dist/function-sugar.js +79 -0
- package/dist/function-sugar.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -4
- package/dist/index.js.map +1 -1
- package/dist/providers/analytics/mixpanel.d.ts.map +1 -1
- package/dist/providers/analytics/mixpanel.js +21 -18
- package/dist/providers/analytics/mixpanel.js.map +1 -1
- package/dist/providers/calendar/cal-com.d.ts.map +1 -1
- package/dist/providers/calendar/cal-com.js +10 -10
- package/dist/providers/calendar/cal-com.js.map +1 -1
- package/dist/providers/calendar/google-calendar.d.ts.map +1 -1
- package/dist/providers/calendar/google-calendar.js +4 -4
- package/dist/providers/calendar/google-calendar.js.map +1 -1
- package/dist/providers/crm/hubspot.d.ts.map +1 -1
- package/dist/providers/crm/hubspot.js +107 -85
- package/dist/providers/crm/hubspot.js.map +1 -1
- package/dist/providers/development/github.d.ts.map +1 -1
- package/dist/providers/development/github.js +40 -43
- package/dist/providers/development/github.js.map +1 -1
- package/dist/providers/ecommerce/shopify.d.ts.map +1 -1
- package/dist/providers/ecommerce/shopify.js +79 -62
- package/dist/providers/ecommerce/shopify.js.map +1 -1
- package/dist/providers/email/resend.d.ts.map +1 -1
- package/dist/providers/email/resend.js +20 -16
- package/dist/providers/email/resend.js.map +1 -1
- package/dist/providers/email/sendgrid.d.ts.map +1 -1
- package/dist/providers/email/sendgrid.js +12 -9
- package/dist/providers/email/sendgrid.js.map +1 -1
- package/dist/providers/finance/stripe.d.ts.map +1 -1
- package/dist/providers/finance/stripe.js +44 -42
- package/dist/providers/finance/stripe.js.map +1 -1
- package/dist/providers/forms/typeform.d.ts.map +1 -1
- package/dist/providers/forms/typeform.js +68 -58
- package/dist/providers/forms/typeform.js.map +1 -1
- package/dist/providers/knowledge/notion.d.ts.map +1 -1
- package/dist/providers/knowledge/notion.js +75 -41
- package/dist/providers/knowledge/notion.js.map +1 -1
- package/dist/providers/marketing/mailchimp.d.ts.map +1 -1
- package/dist/providers/marketing/mailchimp.js +74 -61
- package/dist/providers/marketing/mailchimp.js.map +1 -1
- package/dist/providers/media/cloudinary.d.ts.map +1 -1
- package/dist/providers/media/cloudinary.js +30 -28
- package/dist/providers/media/cloudinary.js.map +1 -1
- package/dist/providers/messaging/slack.d.ts.map +1 -1
- package/dist/providers/messaging/slack.js +75 -58
- package/dist/providers/messaging/slack.js.map +1 -1
- package/dist/providers/messaging/twilio-sms.d.ts.map +1 -1
- package/dist/providers/messaging/twilio-sms.js +33 -15
- package/dist/providers/messaging/twilio-sms.js.map +1 -1
- package/dist/providers/project-management/linear.d.ts.map +1 -1
- package/dist/providers/project-management/linear.js +31 -27
- package/dist/providers/project-management/linear.js.map +1 -1
- package/dist/providers/spreadsheet/google-sheets.d.ts.map +1 -1
- package/dist/providers/spreadsheet/google-sheets.js +21 -18
- package/dist/providers/spreadsheet/google-sheets.js.map +1 -1
- package/dist/providers/spreadsheet/xlsx.d.ts.map +1 -1
- package/dist/providers/spreadsheet/xlsx.js +4 -4
- package/dist/providers/spreadsheet/xlsx.js.map +1 -1
- package/dist/providers/storage/index.js +1 -0
- package/dist/providers/storage/index.js.map +1 -1
- package/dist/providers/storage/s3.d.ts.map +1 -1
- package/dist/providers/storage/s3.js +36 -27
- package/dist/providers/storage/s3.js.map +1 -1
- package/dist/providers/support/zendesk.d.ts.map +1 -1
- package/dist/providers/support/zendesk.js +24 -25
- package/dist/providers/support/zendesk.js.map +1 -1
- package/dist/providers/tasks/todoist.d.ts.map +1 -1
- package/dist/providers/tasks/todoist.js +18 -18
- package/dist/providers/tasks/todoist.js.map +1 -1
- package/dist/providers/video-conferencing/google-meet.d.ts.map +1 -1
- package/dist/providers/video-conferencing/google-meet.js +11 -11
- package/dist/providers/video-conferencing/google-meet.js.map +1 -1
- package/dist/providers/video-conferencing/jitsi.js +14 -14
- package/dist/providers/video-conferencing/jitsi.js.map +1 -1
- package/dist/providers/video-conferencing/teams.d.ts.map +1 -1
- package/dist/providers/video-conferencing/teams.js +9 -7
- package/dist/providers/video-conferencing/teams.js.map +1 -1
- package/dist/providers/video-conferencing/zoom.d.ts.map +1 -1
- package/dist/providers/video-conferencing/zoom.js +26 -24
- package/dist/providers/video-conferencing/zoom.js.map +1 -1
- package/dist/tools/data.d.ts.map +1 -1
- package/dist/tools/data.js +5 -12
- package/dist/tools/data.js.map +1 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/system.d.ts +289 -0
- package/dist/tools/system.d.ts.map +1 -0
- package/dist/tools/system.js +752 -0
- package/dist/tools/system.js.map +1 -0
- package/dist/tools/web.d.ts.map +1 -1
- package/dist/tools/web.js +22 -10
- package/dist/tools/web.js.map +1 -1
- package/dist/track-record.d.ts +101 -0
- package/dist/track-record.d.ts.map +1 -0
- package/dist/track-record.js +17 -0
- package/dist/track-record.js.map +1 -0
- package/dist/types.d.ts +210 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/verb-registration.d.ts +122 -0
- package/dist/verb-registration.d.ts.map +1 -0
- package/dist/verb-registration.js +176 -0
- package/dist/verb-registration.js.map +1 -0
- package/dist/worker.d.ts +93 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +315 -0
- package/dist/worker.js.map +1 -0
- package/dist/wrap.d.ts +89 -0
- package/dist/wrap.d.ts.map +1 -0
- package/dist/wrap.js +225 -0
- package/dist/wrap.js.map +1 -0
- package/package.json +31 -14
- package/src/client.ts +136 -0
- package/src/define.ts +30 -24
- package/src/function-ref.ts +264 -0
- package/src/function-sugar.ts +134 -0
- package/src/index.ts +132 -10
- package/src/providers/analytics/mixpanel.ts +19 -18
- package/src/providers/calendar/cal-com.ts +29 -18
- package/src/providers/calendar/google-calendar.ts +20 -14
- package/src/providers/crm/hubspot.ts +225 -99
- package/src/providers/development/github.ts +206 -135
- package/src/providers/ecommerce/shopify.ts +250 -89
- package/src/providers/email/resend.ts +101 -28
- package/src/providers/email/sendgrid.ts +12 -9
- package/src/providers/finance/stripe.ts +128 -49
- package/src/providers/forms/typeform.ts +74 -58
- package/src/providers/knowledge/notion.ts +340 -88
- package/src/providers/marketing/mailchimp.ts +86 -70
- package/src/providers/media/cloudinary.ts +99 -41
- package/src/providers/messaging/slack.ts +283 -85
- package/src/providers/messaging/twilio-sms.ts +35 -15
- package/src/providers/project-management/linear.ts +143 -55
- package/src/providers/spreadsheet/google-sheets.ts +222 -56
- package/src/providers/spreadsheet/xlsx.ts +47 -16
- package/src/providers/storage/s3.ts +119 -47
- package/src/providers/support/zendesk.ts +196 -46
- package/src/providers/tasks/todoist.ts +20 -26
- package/src/providers/video-conferencing/google-meet.ts +17 -20
- package/src/providers/video-conferencing/jitsi.ts +14 -14
- package/src/providers/video-conferencing/teams.ts +14 -13
- package/src/providers/video-conferencing/zoom.ts +54 -49
- package/src/tools/data.ts +6 -16
- package/src/tools/index.ts +1 -0
- package/src/tools/system.ts +887 -0
- package/src/tools/web.ts +22 -10
- package/src/track-record.ts +106 -0
- package/src/types.ts +241 -13
- package/src/verb-registration.ts +197 -0
- package/src/worker.ts +370 -0
- package/src/wrap.ts +260 -0
- package/test/client.test.ts +146 -0
- package/test/communication-tools-extended.test.ts +734 -0
- package/test/data-tools-extended.test.ts +743 -0
- package/test/define-extended.test.ts +819 -0
- package/test/define.test.ts +150 -41
- package/test/entities.test.ts +623 -0
- package/test/extended-entities.test.ts +1228 -0
- package/test/provider-implementations.test.ts +725 -0
- package/test/provider-registry-extended.test.ts +583 -0
- package/test/providers/google-sheets.test.ts +851 -0
- package/test/providers/helpers.ts +554 -0
- package/test/providers/hubspot.test.ts +576 -0
- package/test/providers/slack.test.ts +932 -0
- package/test/providers/stripe.test.ts +701 -0
- package/test/providers.test.ts +578 -0
- package/test/system-tools-extended.test.ts +632 -0
- package/test/system.test.ts +673 -0
- package/test/tools.test.ts +15 -11
- package/test/types.test.ts +402 -0
- package/test/verb-registration.test.ts +395 -0
- package/test/web-tools.test.ts +553 -0
- package/test/worker-extended.test.ts +699 -0
- package/test/worker.test.ts +576 -0
- package/test/wrap.test.ts +366 -0
- package/tsconfig.json +3 -13
- package/vitest.config.ts +37 -0
- package/wrangler.jsonc +9 -0
- package/LICENSE +0 -21
- package/dist/providers/voice/vapi.d.ts +0 -27
- package/dist/providers/voice/vapi.d.ts.map +0 -1
- package/dist/providers/voice/vapi.js +0 -440
- package/dist/providers/voice/vapi.js.map +0 -1
- package/src/define.js +0 -259
- package/src/entities/advertising.js +0 -999
- package/src/entities/ai.js +0 -756
- package/src/entities/analytics.js +0 -1588
- package/src/entities/automation.js +0 -601
- package/src/entities/communication.js +0 -1150
- package/src/entities/crm.js +0 -1386
- package/src/entities/design.js +0 -546
- package/src/entities/development.js +0 -2212
- package/src/entities/document.js +0 -874
- package/src/entities/ecommerce.js +0 -1429
- package/src/entities/experiment.js +0 -1039
- package/src/entities/finance.js +0 -3478
- package/src/entities/forms.js +0 -1892
- package/src/entities/hr.js +0 -661
- package/src/entities/identity.js +0 -997
- package/src/entities/index.js +0 -282
- package/src/entities/infrastructure.js +0 -1153
- package/src/entities/knowledge.js +0 -1438
- package/src/entities/marketing.js +0 -1610
- package/src/entities/media.js +0 -1634
- package/src/entities/notification.js +0 -1199
- package/src/entities/presentation.js +0 -1274
- package/src/entities/productivity.js +0 -1317
- package/src/entities/project-management.js +0 -1136
- package/src/entities/recruiting.js +0 -736
- package/src/entities/shipping.js +0 -509
- package/src/entities/signature.js +0 -1102
- package/src/entities/site.js +0 -222
- package/src/entities/spreadsheet.js +0 -1341
- package/src/entities/storage.js +0 -1198
- package/src/entities/support.js +0 -1166
- package/src/entities/video-conferencing.js +0 -1750
- package/src/entities/video.js +0 -950
- package/src/entities.js +0 -1663
- package/src/index.js +0 -74
- package/src/providers/analytics/index.js +0 -17
- package/src/providers/analytics/mixpanel.js +0 -255
- package/src/providers/calendar/cal-com.js +0 -303
- package/src/providers/calendar/google-calendar.js +0 -335
- package/src/providers/calendar/index.js +0 -20
- package/src/providers/crm/hubspot.js +0 -566
- package/src/providers/crm/index.js +0 -17
- package/src/providers/development/github.js +0 -472
- package/src/providers/development/index.js +0 -17
- package/src/providers/ecommerce/index.js +0 -17
- package/src/providers/ecommerce/shopify.js +0 -378
- package/src/providers/email/index.js +0 -20
- package/src/providers/email/resend.js +0 -258
- package/src/providers/email/sendgrid.js +0 -161
- package/src/providers/finance/index.js +0 -17
- package/src/providers/finance/stripe.js +0 -549
- package/src/providers/forms/index.js +0 -17
- package/src/providers/forms/typeform.js +0 -500
- package/src/providers/index.js +0 -123
- package/src/providers/knowledge/index.js +0 -17
- package/src/providers/knowledge/notion.js +0 -389
- package/src/providers/marketing/index.js +0 -17
- package/src/providers/marketing/mailchimp.js +0 -443
- package/src/providers/media/cloudinary.js +0 -318
- package/src/providers/media/index.js +0 -17
- package/src/providers/messaging/index.js +0 -20
- package/src/providers/messaging/slack.js +0 -393
- package/src/providers/messaging/twilio-sms.js +0 -249
- package/src/providers/project-management/index.js +0 -17
- package/src/providers/project-management/linear.js +0 -575
- package/src/providers/registry.js +0 -86
- package/src/providers/spreadsheet/google-sheets.js +0 -375
- package/src/providers/spreadsheet/index.js +0 -20
- package/src/providers/spreadsheet/xlsx.js +0 -423
- package/src/providers/storage/index.js +0 -24
- package/src/providers/storage/s3.js +0 -419
- package/src/providers/support/index.js +0 -17
- package/src/providers/support/zendesk.js +0 -373
- package/src/providers/tasks/index.js +0 -17
- package/src/providers/tasks/todoist.js +0 -286
- package/src/providers/types.js +0 -9
- package/src/providers/video-conferencing/google-meet.js +0 -286
- package/src/providers/video-conferencing/index.js +0 -31
- package/src/providers/video-conferencing/jitsi.js +0 -254
- package/src/providers/video-conferencing/teams.js +0 -270
- package/src/providers/video-conferencing/zoom.js +0 -332
- package/src/registry.js +0 -128
- package/src/tools/communication.js +0 -184
- package/src/tools/data.js +0 -205
- package/src/tools/index.js +0 -11
- package/src/tools/web.js +0 -137
- package/src/types.js +0 -10
- package/test/define.test.js +0 -306
- package/test/registry.test.js +0 -357
- 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:
|
|
140
|
+
function mapContactFromHubSpot(contact: HubSpotContact): CRMContactData {
|
|
46
141
|
const props = contact.properties || {}
|
|
47
142
|
return {
|
|
48
143
|
id: contact.id,
|
|
49
|
-
firstName: props
|
|
50
|
-
lastName: props
|
|
51
|
-
email: props
|
|
52
|
-
phone: props
|
|
53
|
-
company: props
|
|
54
|
-
title: props
|
|
55
|
-
ownerId: props
|
|
56
|
-
createdAt: new Date(props
|
|
57
|
-
updatedAt: new Date(props
|
|
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:
|
|
159
|
+
function mapDealFromHubSpot(deal: HubSpotDeal): DealData {
|
|
65
160
|
const props = deal.properties || {}
|
|
66
161
|
return {
|
|
67
162
|
id: deal.id,
|
|
68
|
-
name: props
|
|
69
|
-
|
|
70
|
-
currency: props
|
|
71
|
-
stage: props
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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:
|
|
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
|
|
92
|
-
subject: props
|
|
93
|
-
body: props
|
|
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
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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(
|
|
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,
|
|
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
|
|
226
|
-
if (contact.phone) properties
|
|
227
|
-
if (contact.company) properties
|
|
228
|
-
if (contact.title) properties
|
|
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.
|
|
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(
|
|
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
|
|
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
|
|
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,
|
|
404
|
+
const properties: Record<string, string> = {}
|
|
293
405
|
|
|
294
|
-
if (updates.firstName !== undefined) properties
|
|
295
|
-
if (updates.lastName !== undefined) properties
|
|
296
|
-
if (updates.email !== undefined) properties
|
|
297
|
-
if (updates.phone !== undefined) properties
|
|
298
|
-
if (updates.company !== undefined) properties
|
|
299
|
-
if (updates.title !== undefined) properties
|
|
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.
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
419
|
-
if (deal.currency) properties
|
|
420
|
-
if (deal.closeDate) properties
|
|
421
|
-
if (deal.probability !== undefined)
|
|
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(
|
|
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
|
|
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
|
|
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,
|
|
606
|
+
const properties: Record<string, string> = {}
|
|
490
607
|
|
|
491
|
-
if (updates.name !== undefined) properties
|
|
492
|
-
if (updates.stage !== undefined) properties
|
|
493
|
-
if (updates.value !== undefined) properties
|
|
494
|
-
if (updates.currency !== undefined) properties
|
|
495
|
-
if (updates.closeDate !== undefined) properties
|
|
496
|
-
if (updates.probability !== undefined)
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
675
|
+
async logActivity(
|
|
676
|
+
contactId: string,
|
|
677
|
+
activity: CreateActivityOptions
|
|
678
|
+
): Promise<CRMActivityData> {
|
|
558
679
|
// Map activity type to HubSpot engagement type
|
|
559
|
-
const engagementType =
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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
|
|
698
|
+
properties['hs_note_body'] = activity.body
|
|
573
699
|
} else if (engagementType === 'EMAIL') {
|
|
574
|
-
properties
|
|
700
|
+
properties['hs_email_text'] = activity.body
|
|
575
701
|
}
|
|
576
702
|
}
|
|
577
703
|
|
|
578
704
|
if (activity.dueDate) {
|
|
579
|
-
properties
|
|
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(
|
|
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
|
|
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
|
|
628
|
-
const engagementIds = (data.results || []).map((r
|
|
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:
|
|
652
|
-
.map((eng
|
|
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'}`
|