digital-tools 2.0.2 → 2.1.1

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 (93) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +3 -4
  3. package/src/define.js +267 -0
  4. package/src/entities/advertising.js +999 -0
  5. package/src/entities/ai.js +756 -0
  6. package/src/entities/analytics.js +1588 -0
  7. package/src/entities/automation.js +601 -0
  8. package/src/entities/communication.js +1150 -0
  9. package/src/entities/crm.js +1386 -0
  10. package/src/entities/design.js +546 -0
  11. package/src/entities/development.js +2212 -0
  12. package/src/entities/document.js +874 -0
  13. package/src/entities/ecommerce.js +1429 -0
  14. package/src/entities/experiment.js +1039 -0
  15. package/src/entities/finance.js +3478 -0
  16. package/src/entities/forms.js +1892 -0
  17. package/src/entities/hr.js +661 -0
  18. package/src/entities/identity.js +997 -0
  19. package/src/entities/index.js +282 -0
  20. package/src/entities/infrastructure.js +1153 -0
  21. package/src/entities/knowledge.js +1438 -0
  22. package/src/entities/marketing.js +1610 -0
  23. package/src/entities/media.js +1634 -0
  24. package/src/entities/notification.js +1199 -0
  25. package/src/entities/presentation.js +1274 -0
  26. package/src/entities/productivity.js +1317 -0
  27. package/src/entities/project-management.js +1136 -0
  28. package/src/entities/recruiting.js +736 -0
  29. package/src/entities/shipping.js +509 -0
  30. package/src/entities/signature.js +1102 -0
  31. package/src/entities/site.js +222 -0
  32. package/src/entities/spreadsheet.js +1341 -0
  33. package/src/entities/storage.js +1198 -0
  34. package/src/entities/support.js +1166 -0
  35. package/src/entities/video-conferencing.js +1750 -0
  36. package/src/entities/video.js +950 -0
  37. package/src/entities.js +1663 -0
  38. package/src/index.js +74 -0
  39. package/src/providers/analytics/index.js +17 -0
  40. package/src/providers/analytics/mixpanel.js +255 -0
  41. package/src/providers/calendar/cal-com.js +303 -0
  42. package/src/providers/calendar/google-calendar.js +335 -0
  43. package/src/providers/calendar/index.js +20 -0
  44. package/src/providers/crm/hubspot.js +566 -0
  45. package/src/providers/crm/index.js +17 -0
  46. package/src/providers/development/github.js +472 -0
  47. package/src/providers/development/index.js +17 -0
  48. package/src/providers/ecommerce/index.js +17 -0
  49. package/src/providers/ecommerce/shopify.js +378 -0
  50. package/src/providers/email/index.js +20 -0
  51. package/src/providers/email/resend.js +258 -0
  52. package/src/providers/email/sendgrid.js +161 -0
  53. package/src/providers/finance/index.js +17 -0
  54. package/src/providers/finance/stripe.js +549 -0
  55. package/src/providers/forms/index.js +17 -0
  56. package/src/providers/forms/typeform.js +500 -0
  57. package/src/providers/index.js +123 -0
  58. package/src/providers/knowledge/index.js +17 -0
  59. package/src/providers/knowledge/notion.js +389 -0
  60. package/src/providers/marketing/index.js +17 -0
  61. package/src/providers/marketing/mailchimp.js +443 -0
  62. package/src/providers/media/cloudinary.js +318 -0
  63. package/src/providers/media/index.js +17 -0
  64. package/src/providers/messaging/index.js +20 -0
  65. package/src/providers/messaging/slack.js +393 -0
  66. package/src/providers/messaging/twilio-sms.js +249 -0
  67. package/src/providers/project-management/index.js +17 -0
  68. package/src/providers/project-management/linear.js +575 -0
  69. package/src/providers/registry.js +86 -0
  70. package/src/providers/spreadsheet/google-sheets.js +375 -0
  71. package/src/providers/spreadsheet/index.js +20 -0
  72. package/src/providers/spreadsheet/xlsx.js +423 -0
  73. package/src/providers/storage/index.js +24 -0
  74. package/src/providers/storage/s3.js +419 -0
  75. package/src/providers/support/index.js +17 -0
  76. package/src/providers/support/zendesk.js +373 -0
  77. package/src/providers/tasks/index.js +17 -0
  78. package/src/providers/tasks/todoist.js +286 -0
  79. package/src/providers/types.js +9 -0
  80. package/src/providers/video-conferencing/google-meet.js +286 -0
  81. package/src/providers/video-conferencing/index.js +31 -0
  82. package/src/providers/video-conferencing/jitsi.js +254 -0
  83. package/src/providers/video-conferencing/teams.js +270 -0
  84. package/src/providers/video-conferencing/zoom.js +332 -0
  85. package/src/registry.js +128 -0
  86. package/src/tools/communication.js +184 -0
  87. package/src/tools/data.js +205 -0
  88. package/src/tools/index.js +11 -0
  89. package/src/tools/web.js +137 -0
  90. package/src/types.js +10 -0
  91. package/test/define.test.js +306 -0
  92. package/test/registry.test.js +357 -0
  93. package/test/tools.test.js +363 -0
@@ -0,0 +1,566 @@
1
+ /**
2
+ * HubSpot CRM Provider
3
+ *
4
+ * Concrete implementation of CRMProvider using HubSpot CRM API v3.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import { defineProvider } from '../registry.js';
9
+ const HUBSPOT_API_URL = 'https://api.hubapi.com/crm/v3';
10
+ /**
11
+ * HubSpot provider info
12
+ */
13
+ export const hubspotInfo = {
14
+ id: 'crm.hubspot',
15
+ name: 'HubSpot',
16
+ description: 'HubSpot CRM platform for managing contacts, deals, and activities',
17
+ category: 'crm',
18
+ website: 'https://www.hubspot.com',
19
+ docsUrl: 'https://developers.hubspot.com/docs/api/overview',
20
+ requiredConfig: ['accessToken'],
21
+ optionalConfig: ['baseUrl'],
22
+ };
23
+ /**
24
+ * Map HubSpot contact properties to CRMContactData
25
+ */
26
+ function mapContactFromHubSpot(contact) {
27
+ const props = contact.properties || {};
28
+ return {
29
+ id: contact.id,
30
+ firstName: props.firstname || '',
31
+ lastName: props.lastname || '',
32
+ email: props.email,
33
+ phone: props.phone,
34
+ company: props.company,
35
+ title: props.jobtitle,
36
+ ownerId: props.hubspot_owner_id,
37
+ createdAt: new Date(props.createdate || contact.createdAt),
38
+ updatedAt: new Date(props.lastmodifieddate || contact.updatedAt),
39
+ };
40
+ }
41
+ /**
42
+ * Map HubSpot deal properties to DealData
43
+ */
44
+ function mapDealFromHubSpot(deal) {
45
+ const props = deal.properties || {};
46
+ return {
47
+ id: deal.id,
48
+ name: props.dealname || '',
49
+ value: props.amount ? parseFloat(props.amount) : undefined,
50
+ currency: props.deal_currency_code,
51
+ stage: props.dealstage || '',
52
+ probability: props.hs_deal_stage_probability ? parseFloat(props.hs_deal_stage_probability) : undefined,
53
+ contactId: props.associatedcontactid,
54
+ companyId: props.associatedcompanyid,
55
+ ownerId: props.hubspot_owner_id,
56
+ closeDate: props.closedate ? new Date(props.closedate) : undefined,
57
+ createdAt: new Date(props.createdate || deal.createdAt),
58
+ updatedAt: new Date(props.hs_lastmodifieddate || deal.updatedAt),
59
+ wonAt: props.hs_date_entered_closedwon ? new Date(props.hs_date_entered_closedwon) : undefined,
60
+ lostAt: props.hs_date_entered_closedlost ? new Date(props.hs_date_entered_closedlost) : undefined,
61
+ };
62
+ }
63
+ /**
64
+ * Map HubSpot engagement to CRMActivityData
65
+ */
66
+ function mapActivityFromHubSpot(engagement, contactId) {
67
+ const props = engagement.properties || {};
68
+ return {
69
+ id: engagement.id,
70
+ type: props.hs_engagement_type || 'note',
71
+ subject: props.hs_engagement_subject || '',
72
+ body: props.hs_note_body || props.hs_email_text || '',
73
+ contactId,
74
+ ownerId: props.hubspot_owner_id || '',
75
+ dueDate: props.hs_task_due_date ? new Date(props.hs_task_due_date) : undefined,
76
+ completedAt: props.hs_engagement_completed_at ? new Date(props.hs_engagement_completed_at) : undefined,
77
+ createdAt: new Date(props.hs_createdate || engagement.createdAt),
78
+ };
79
+ }
80
+ /**
81
+ * Create HubSpot CRM provider
82
+ */
83
+ export function createHubSpotProvider(config) {
84
+ let accessToken;
85
+ let baseUrl;
86
+ // Helper function to associate deal with contact
87
+ async function associateDealWithContact(dealId, contactId) {
88
+ try {
89
+ const response = await fetch(`${baseUrl}/objects/deals/${dealId}/associations/contacts/${contactId}/deal_to_contact`, {
90
+ method: 'PUT',
91
+ headers: {
92
+ Authorization: `Bearer ${accessToken}`,
93
+ 'Content-Type': 'application/json',
94
+ },
95
+ });
96
+ if (!response.ok) {
97
+ throw new Error(`HTTP ${response.status}`);
98
+ }
99
+ }
100
+ catch (error) {
101
+ // Log but don't throw - association is optional
102
+ console.warn('Failed to associate deal with contact:', error);
103
+ }
104
+ }
105
+ // Helper function to associate deal with company
106
+ async function associateDealWithCompany(dealId, companyId) {
107
+ try {
108
+ const response = await fetch(`${baseUrl}/objects/deals/${dealId}/associations/companies/${companyId}/deal_to_company`, {
109
+ method: 'PUT',
110
+ headers: {
111
+ Authorization: `Bearer ${accessToken}`,
112
+ 'Content-Type': 'application/json',
113
+ },
114
+ });
115
+ if (!response.ok) {
116
+ throw new Error(`HTTP ${response.status}`);
117
+ }
118
+ }
119
+ catch (error) {
120
+ // Log but don't throw - association is optional
121
+ console.warn('Failed to associate deal with company:', error);
122
+ }
123
+ }
124
+ // Helper function to associate engagement with contact
125
+ async function associateEngagementWithContact(engagementId, contactId) {
126
+ try {
127
+ const response = await fetch(`${baseUrl}/objects/engagements/${engagementId}/associations/contacts/${contactId}/engagement_to_contact`, {
128
+ method: 'PUT',
129
+ headers: {
130
+ Authorization: `Bearer ${accessToken}`,
131
+ 'Content-Type': 'application/json',
132
+ },
133
+ });
134
+ if (!response.ok) {
135
+ throw new Error(`HTTP ${response.status}`);
136
+ }
137
+ }
138
+ catch (error) {
139
+ console.warn('Failed to associate engagement with contact:', error);
140
+ }
141
+ }
142
+ return {
143
+ info: hubspotInfo,
144
+ async initialize(cfg) {
145
+ accessToken = cfg.accessToken;
146
+ baseUrl = cfg.baseUrl || HUBSPOT_API_URL;
147
+ if (!accessToken) {
148
+ throw new Error('HubSpot access token is required');
149
+ }
150
+ },
151
+ async healthCheck() {
152
+ const start = Date.now();
153
+ try {
154
+ const response = await fetch(`${baseUrl}/objects/contacts?limit=1`, {
155
+ headers: {
156
+ Authorization: `Bearer ${accessToken}`,
157
+ 'Content-Type': 'application/json',
158
+ },
159
+ });
160
+ return {
161
+ healthy: response.ok,
162
+ latencyMs: Date.now() - start,
163
+ message: response.ok ? 'Connected' : `HTTP ${response.status}`,
164
+ checkedAt: new Date(),
165
+ };
166
+ }
167
+ catch (error) {
168
+ return {
169
+ healthy: false,
170
+ latencyMs: Date.now() - start,
171
+ message: error instanceof Error ? error.message : 'Unknown error',
172
+ checkedAt: new Date(),
173
+ };
174
+ }
175
+ },
176
+ async dispose() {
177
+ // No cleanup needed
178
+ },
179
+ async createContact(contact) {
180
+ const properties = {
181
+ firstname: contact.firstName,
182
+ lastname: contact.lastName,
183
+ };
184
+ if (contact.email)
185
+ properties.email = contact.email;
186
+ if (contact.phone)
187
+ properties.phone = contact.phone;
188
+ if (contact.company)
189
+ properties.company = contact.company;
190
+ if (contact.title)
191
+ properties.jobtitle = contact.title;
192
+ // Add custom fields
193
+ if (contact.customFields) {
194
+ Object.assign(properties, contact.customFields);
195
+ }
196
+ try {
197
+ const response = await fetch(`${baseUrl}/objects/contacts`, {
198
+ method: 'POST',
199
+ headers: {
200
+ Authorization: `Bearer ${accessToken}`,
201
+ 'Content-Type': 'application/json',
202
+ },
203
+ body: JSON.stringify({ properties }),
204
+ });
205
+ if (!response.ok) {
206
+ const errorData = await response.json().catch(() => ({}));
207
+ throw new Error(errorData?.message || `HTTP ${response.status}`);
208
+ }
209
+ const data = await response.json();
210
+ return mapContactFromHubSpot(data);
211
+ }
212
+ catch (error) {
213
+ throw new Error(`Failed to create contact: ${error instanceof Error ? error.message : 'Unknown error'}`);
214
+ }
215
+ },
216
+ async getContact(contactId) {
217
+ try {
218
+ const response = await fetch(`${baseUrl}/objects/contacts/${contactId}`, {
219
+ headers: {
220
+ Authorization: `Bearer ${accessToken}`,
221
+ 'Content-Type': 'application/json',
222
+ },
223
+ });
224
+ if (response.status === 404) {
225
+ return null;
226
+ }
227
+ if (!response.ok) {
228
+ throw new Error(`HTTP ${response.status}`);
229
+ }
230
+ const data = await response.json();
231
+ return mapContactFromHubSpot(data);
232
+ }
233
+ catch (error) {
234
+ if (error instanceof Error && error.message.includes('404')) {
235
+ return null;
236
+ }
237
+ throw new Error(`Failed to get contact: ${error instanceof Error ? error.message : 'Unknown error'}`);
238
+ }
239
+ },
240
+ async updateContact(contactId, updates) {
241
+ const properties = {};
242
+ if (updates.firstName !== undefined)
243
+ properties.firstname = updates.firstName;
244
+ if (updates.lastName !== undefined)
245
+ properties.lastname = updates.lastName;
246
+ if (updates.email !== undefined)
247
+ properties.email = updates.email;
248
+ if (updates.phone !== undefined)
249
+ properties.phone = updates.phone;
250
+ if (updates.company !== undefined)
251
+ properties.company = updates.company;
252
+ if (updates.title !== undefined)
253
+ properties.jobtitle = updates.title;
254
+ // Add custom fields
255
+ if (updates.customFields) {
256
+ Object.assign(properties, updates.customFields);
257
+ }
258
+ try {
259
+ const response = await fetch(`${baseUrl}/objects/contacts/${contactId}`, {
260
+ method: 'PATCH',
261
+ headers: {
262
+ Authorization: `Bearer ${accessToken}`,
263
+ 'Content-Type': 'application/json',
264
+ },
265
+ body: JSON.stringify({ properties }),
266
+ });
267
+ if (!response.ok) {
268
+ const errorData = await response.json().catch(() => ({}));
269
+ throw new Error(errorData?.message || `HTTP ${response.status}`);
270
+ }
271
+ const data = await response.json();
272
+ return mapContactFromHubSpot(data);
273
+ }
274
+ catch (error) {
275
+ throw new Error(`Failed to update contact: ${error instanceof Error ? error.message : 'Unknown error'}`);
276
+ }
277
+ },
278
+ async listContacts(options) {
279
+ const params = new URLSearchParams({
280
+ limit: String(options?.limit || 100),
281
+ });
282
+ if (options?.cursor) {
283
+ params.set('after', options.cursor);
284
+ }
285
+ try {
286
+ const response = await fetch(`${baseUrl}/objects/contacts?${params}`, {
287
+ headers: {
288
+ Authorization: `Bearer ${accessToken}`,
289
+ 'Content-Type': 'application/json',
290
+ },
291
+ });
292
+ if (!response.ok) {
293
+ throw new Error(`HTTP ${response.status}`);
294
+ }
295
+ const data = await response.json();
296
+ return {
297
+ items: (data.results || []).map(mapContactFromHubSpot),
298
+ total: data.total,
299
+ hasMore: !!data.paging?.next,
300
+ nextCursor: data.paging?.next?.after,
301
+ };
302
+ }
303
+ catch (error) {
304
+ throw new Error(`Failed to list contacts: ${error instanceof Error ? error.message : 'Unknown error'}`);
305
+ }
306
+ },
307
+ async searchContacts(query) {
308
+ try {
309
+ const response = await fetch(`${baseUrl}/objects/contacts/search`, {
310
+ method: 'POST',
311
+ headers: {
312
+ Authorization: `Bearer ${accessToken}`,
313
+ 'Content-Type': 'application/json',
314
+ },
315
+ body: JSON.stringify({
316
+ filterGroups: [
317
+ {
318
+ filters: [
319
+ {
320
+ propertyName: 'email',
321
+ operator: 'CONTAINS_TOKEN',
322
+ value: query,
323
+ },
324
+ {
325
+ propertyName: 'firstname',
326
+ operator: 'CONTAINS_TOKEN',
327
+ value: query,
328
+ },
329
+ {
330
+ propertyName: 'lastname',
331
+ operator: 'CONTAINS_TOKEN',
332
+ value: query,
333
+ },
334
+ ],
335
+ },
336
+ ],
337
+ limit: 100,
338
+ }),
339
+ });
340
+ if (!response.ok) {
341
+ throw new Error(`HTTP ${response.status}`);
342
+ }
343
+ const data = await response.json();
344
+ return (data.results || []).map(mapContactFromHubSpot);
345
+ }
346
+ catch (error) {
347
+ throw new Error(`Failed to search contacts: ${error instanceof Error ? error.message : 'Unknown error'}`);
348
+ }
349
+ },
350
+ async createDeal(deal) {
351
+ const properties = {
352
+ dealname: deal.name,
353
+ dealstage: deal.stage,
354
+ };
355
+ if (deal.value !== undefined)
356
+ properties.amount = String(deal.value);
357
+ if (deal.currency)
358
+ properties.deal_currency_code = deal.currency;
359
+ if (deal.closeDate)
360
+ properties.closedate = deal.closeDate.toISOString();
361
+ if (deal.probability !== undefined)
362
+ properties.hs_deal_stage_probability = String(deal.probability);
363
+ try {
364
+ const response = await fetch(`${baseUrl}/objects/deals`, {
365
+ method: 'POST',
366
+ headers: {
367
+ Authorization: `Bearer ${accessToken}`,
368
+ 'Content-Type': 'application/json',
369
+ },
370
+ body: JSON.stringify({ properties }),
371
+ });
372
+ if (!response.ok) {
373
+ const errorData = await response.json().catch(() => ({}));
374
+ throw new Error(errorData?.message || `HTTP ${response.status}`);
375
+ }
376
+ const data = await response.json();
377
+ const dealData = mapDealFromHubSpot(data);
378
+ // Associate with contact if specified
379
+ if (deal.contactId) {
380
+ await associateDealWithContact(dealData.id, deal.contactId);
381
+ }
382
+ // Associate with company if specified
383
+ if (deal.companyId) {
384
+ await associateDealWithCompany(dealData.id, deal.companyId);
385
+ }
386
+ return dealData;
387
+ }
388
+ catch (error) {
389
+ throw new Error(`Failed to create deal: ${error instanceof Error ? error.message : 'Unknown error'}`);
390
+ }
391
+ },
392
+ async getDeal(dealId) {
393
+ try {
394
+ const response = await fetch(`${baseUrl}/objects/deals/${dealId}`, {
395
+ headers: {
396
+ Authorization: `Bearer ${accessToken}`,
397
+ 'Content-Type': 'application/json',
398
+ },
399
+ });
400
+ if (response.status === 404) {
401
+ return null;
402
+ }
403
+ if (!response.ok) {
404
+ throw new Error(`HTTP ${response.status}`);
405
+ }
406
+ const data = await response.json();
407
+ return mapDealFromHubSpot(data);
408
+ }
409
+ catch (error) {
410
+ if (error instanceof Error && error.message.includes('404')) {
411
+ return null;
412
+ }
413
+ throw new Error(`Failed to get deal: ${error instanceof Error ? error.message : 'Unknown error'}`);
414
+ }
415
+ },
416
+ async updateDeal(dealId, updates) {
417
+ const properties = {};
418
+ if (updates.name !== undefined)
419
+ properties.dealname = updates.name;
420
+ if (updates.stage !== undefined)
421
+ properties.dealstage = updates.stage;
422
+ if (updates.value !== undefined)
423
+ properties.amount = String(updates.value);
424
+ if (updates.currency !== undefined)
425
+ properties.deal_currency_code = updates.currency;
426
+ if (updates.closeDate !== undefined)
427
+ properties.closedate = updates.closeDate.toISOString();
428
+ if (updates.probability !== undefined)
429
+ properties.hs_deal_stage_probability = String(updates.probability);
430
+ try {
431
+ const response = await fetch(`${baseUrl}/objects/deals/${dealId}`, {
432
+ method: 'PATCH',
433
+ headers: {
434
+ Authorization: `Bearer ${accessToken}`,
435
+ 'Content-Type': 'application/json',
436
+ },
437
+ body: JSON.stringify({ properties }),
438
+ });
439
+ if (!response.ok) {
440
+ const errorData = await response.json().catch(() => ({}));
441
+ throw new Error(errorData?.message || `HTTP ${response.status}`);
442
+ }
443
+ const data = await response.json();
444
+ return mapDealFromHubSpot(data);
445
+ }
446
+ catch (error) {
447
+ throw new Error(`Failed to update deal: ${error instanceof Error ? error.message : 'Unknown error'}`);
448
+ }
449
+ },
450
+ async listDeals(options) {
451
+ const params = new URLSearchParams({
452
+ limit: String(options?.limit || 100),
453
+ });
454
+ if (options?.cursor) {
455
+ params.set('after', options.cursor);
456
+ }
457
+ try {
458
+ const response = await fetch(`${baseUrl}/objects/deals?${params}`, {
459
+ headers: {
460
+ Authorization: `Bearer ${accessToken}`,
461
+ 'Content-Type': 'application/json',
462
+ },
463
+ });
464
+ if (!response.ok) {
465
+ throw new Error(`HTTP ${response.status}`);
466
+ }
467
+ const data = await response.json();
468
+ return {
469
+ items: (data.results || []).map(mapDealFromHubSpot),
470
+ total: data.total,
471
+ hasMore: !!data.paging?.next,
472
+ nextCursor: data.paging?.next?.after,
473
+ };
474
+ }
475
+ catch (error) {
476
+ throw new Error(`Failed to list deals: ${error instanceof Error ? error.message : 'Unknown error'}`);
477
+ }
478
+ },
479
+ async logActivity(contactId, activity) {
480
+ // Map activity type to HubSpot engagement type
481
+ const engagementType = activity.type === 'email' ? 'EMAIL' :
482
+ activity.type === 'call' ? 'CALL' :
483
+ activity.type === 'meeting' ? 'MEETING' :
484
+ activity.type === 'task' ? 'TASK' :
485
+ 'NOTE';
486
+ const properties = {
487
+ hs_engagement_type: engagementType.toLowerCase(),
488
+ hs_engagement_subject: activity.subject,
489
+ };
490
+ if (activity.body) {
491
+ if (engagementType === 'NOTE') {
492
+ properties.hs_note_body = activity.body;
493
+ }
494
+ else if (engagementType === 'EMAIL') {
495
+ properties.hs_email_text = activity.body;
496
+ }
497
+ }
498
+ if (activity.dueDate) {
499
+ properties.hs_task_due_date = activity.dueDate.toISOString();
500
+ }
501
+ try {
502
+ const response = await fetch(`${baseUrl}/objects/engagements`, {
503
+ method: 'POST',
504
+ headers: {
505
+ Authorization: `Bearer ${accessToken}`,
506
+ 'Content-Type': 'application/json',
507
+ },
508
+ body: JSON.stringify({ properties }),
509
+ });
510
+ if (!response.ok) {
511
+ const errorData = await response.json().catch(() => ({}));
512
+ throw new Error(errorData?.message || `HTTP ${response.status}`);
513
+ }
514
+ const data = await response.json();
515
+ // Associate engagement with contact
516
+ await associateEngagementWithContact(data.id, contactId);
517
+ return mapActivityFromHubSpot(data, contactId);
518
+ }
519
+ catch (error) {
520
+ throw new Error(`Failed to log activity: ${error instanceof Error ? error.message : 'Unknown error'}`);
521
+ }
522
+ },
523
+ async listActivities(contactId) {
524
+ try {
525
+ // Get associated engagements for the contact
526
+ const response = await fetch(`${baseUrl}/objects/contacts/${contactId}/associations/engagements`, {
527
+ headers: {
528
+ Authorization: `Bearer ${accessToken}`,
529
+ 'Content-Type': 'application/json',
530
+ },
531
+ });
532
+ if (!response.ok) {
533
+ throw new Error(`HTTP ${response.status}`);
534
+ }
535
+ const data = await response.json();
536
+ const engagementIds = (data.results || []).map((r) => r.id);
537
+ if (engagementIds.length === 0) {
538
+ return [];
539
+ }
540
+ // Fetch engagement details in batch
541
+ const engagements = await Promise.all(engagementIds.map(async (id) => {
542
+ const engResponse = await fetch(`${baseUrl}/objects/engagements/${id}`, {
543
+ headers: {
544
+ Authorization: `Bearer ${accessToken}`,
545
+ 'Content-Type': 'application/json',
546
+ },
547
+ });
548
+ if (engResponse.ok) {
549
+ return engResponse.json();
550
+ }
551
+ return null;
552
+ }));
553
+ return engagements
554
+ .filter((eng) => eng !== null)
555
+ .map((eng) => mapActivityFromHubSpot(eng, contactId));
556
+ }
557
+ catch (error) {
558
+ throw new Error(`Failed to list activities: ${error instanceof Error ? error.message : 'Unknown error'}`);
559
+ }
560
+ },
561
+ };
562
+ }
563
+ /**
564
+ * HubSpot provider definition
565
+ */
566
+ export const hubspotProvider = defineProvider(hubspotInfo, async (config) => createHubSpotProvider(config));
@@ -0,0 +1,17 @@
1
+ /**
2
+ * CRM Providers
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export { hubspotInfo, hubspotProvider, createHubSpotProvider } from './hubspot.js';
7
+ import { hubspotProvider } from './hubspot.js';
8
+ /**
9
+ * Register all CRM providers
10
+ */
11
+ export function registerCRMProviders() {
12
+ hubspotProvider.register();
13
+ }
14
+ /**
15
+ * All CRM providers
16
+ */
17
+ export const crmProviders = [hubspotProvider];