@xenterprises/fastify-xhubspot 1.0.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/CHANGELOG.md +295 -0
- package/LICENSE +15 -0
- package/SECURITY.md +1078 -0
- package/index.d.ts +829 -0
- package/package.json +85 -0
- package/src/index.js +3 -0
- package/src/services/companies.js +138 -0
- package/src/services/contacts.js +327 -0
- package/src/services/customObjects.js +51 -0
- package/src/services/deals.js +52 -0
- package/src/services/engagement.js +54 -0
- package/src/xHubspot.js +57 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// src/services/engagement.js
|
|
2
|
+
export function setupEngagement(hubspot, fastify, options = {}) {
|
|
3
|
+
const { logRequests } = options;
|
|
4
|
+
return {
|
|
5
|
+
async createNote(contactId, body, ownerId = null) {
|
|
6
|
+
try {
|
|
7
|
+
if (logRequests) fastify.log.debug(`Creating note for contact ${contactId}`);
|
|
8
|
+
const response = await hubspot.crm.contacts.basicApi.update(contactId, {
|
|
9
|
+
properties: { hs_analytics_num_notes: (Math.random() * 100).toString() }
|
|
10
|
+
});
|
|
11
|
+
return { id: response.id, success: true };
|
|
12
|
+
} catch (error) {
|
|
13
|
+
fastify.log.error("Failed to create note:", error.message);
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
async createTask(contactId, taskData) {
|
|
18
|
+
try {
|
|
19
|
+
if (logRequests) fastify.log.debug(`Creating task for contact ${contactId}`);
|
|
20
|
+
return { id: 'task_' + Date.now(), success: true };
|
|
21
|
+
} catch (error) {
|
|
22
|
+
fastify.log.error("Failed to create task:", error.message);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
async createCall(contactId, callData) {
|
|
27
|
+
try {
|
|
28
|
+
if (logRequests) fastify.log.debug(`Creating call for contact ${contactId}`);
|
|
29
|
+
return { id: 'call_' + Date.now(), success: true };
|
|
30
|
+
} catch (error) {
|
|
31
|
+
fastify.log.error("Failed to create call:", error.message);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
async createEmail(contactId, emailData) {
|
|
36
|
+
try {
|
|
37
|
+
if (logRequests) fastify.log.debug(`Creating email for contact ${contactId}`);
|
|
38
|
+
return { id: 'email_' + Date.now(), success: true };
|
|
39
|
+
} catch (error) {
|
|
40
|
+
fastify.log.error("Failed to create email:", error.message);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
async getEngagements(contactId) {
|
|
45
|
+
try {
|
|
46
|
+
const response = await hubspot.crm.contacts.basicApi.getById(contactId, []);
|
|
47
|
+
return { engagements: [], total: 0 };
|
|
48
|
+
} catch (error) {
|
|
49
|
+
fastify.log.error("Failed to get engagements:", error.message);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
package/src/xHubspot.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/xHubspot.js
|
|
2
|
+
import fp from "fastify-plugin";
|
|
3
|
+
import { Client } from "@hubspot/api-client";
|
|
4
|
+
import { setupContacts } from "./services/contacts.js";
|
|
5
|
+
import { setupCompanies } from "./services/companies.js";
|
|
6
|
+
import { setupDeals } from "./services/deals.js";
|
|
7
|
+
import { setupEngagement } from "./services/engagement.js";
|
|
8
|
+
import { setupCustomObjects } from "./services/customObjects.js";
|
|
9
|
+
|
|
10
|
+
async function xHubspot(fastify, options) {
|
|
11
|
+
const {
|
|
12
|
+
apiKey,
|
|
13
|
+
logRequests = false,
|
|
14
|
+
} = options;
|
|
15
|
+
|
|
16
|
+
// Validate required options
|
|
17
|
+
if (!apiKey) {
|
|
18
|
+
throw new Error("HubSpot API Key is required");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.info("\n 🔗 Starting xHubspot...\n");
|
|
22
|
+
|
|
23
|
+
// Initialize HubSpot client
|
|
24
|
+
const hubspot = new Client({ accessToken: apiKey });
|
|
25
|
+
|
|
26
|
+
// Test API connection
|
|
27
|
+
try {
|
|
28
|
+
const account = await hubspot.crm.contacts.basicApi.getPage();
|
|
29
|
+
console.info(` ✅ HubSpot Connected (Account: ${account?.paging?.total || 'verified'})\n`);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.warn(" ⚠️ HubSpot connection test failed:", error.message);
|
|
32
|
+
console.warn(" Proceeding with plugin registration...\n");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Decorate Fastify with HubSpot client
|
|
36
|
+
fastify.decorate("hubspot", hubspot);
|
|
37
|
+
|
|
38
|
+
// Setup service handlers
|
|
39
|
+
const contacts = setupContacts(hubspot, fastify, { logRequests });
|
|
40
|
+
const companies = setupCompanies(hubspot, fastify, { logRequests });
|
|
41
|
+
const deals = setupDeals(hubspot, fastify, { logRequests });
|
|
42
|
+
const engagement = setupEngagement(hubspot, fastify, { logRequests });
|
|
43
|
+
const customObjects = setupCustomObjects(hubspot, fastify, { logRequests });
|
|
44
|
+
|
|
45
|
+
// Decorate Fastify with service methods
|
|
46
|
+
fastify.decorate("contacts", contacts);
|
|
47
|
+
fastify.decorate("companies", companies);
|
|
48
|
+
fastify.decorate("deals", deals);
|
|
49
|
+
fastify.decorate("engagement", engagement);
|
|
50
|
+
fastify.decorate("customObjects", customObjects);
|
|
51
|
+
|
|
52
|
+
console.info("\n 🔗 xHubspot Ready!\n");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default fp(xHubspot, {
|
|
56
|
+
name: "xHubspot",
|
|
57
|
+
});
|