@zerodot/hubspot 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +528 -52
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Set **Authentication** to **Service Key** or **OAuth2**.
|
|
|
24
24
|
Notes:
|
|
25
25
|
|
|
26
26
|
- Lists have **Return All** (at most 5000 items) and **Limit**. The node reads the pages for you.
|
|
27
|
-
-
|
|
27
|
+
- The editor loads choices from HubSpot: owners, companies, contacts, deals, tickets, engagements, static contact lists, pipelines and stages, property names, and the values of properties such as lifecycle stage and lead status. You can still type an ID or an internal name, or use an expression. The trigger loads the property names for each event row. For that, connect the developer credential with OAuth2 (the client ID is optional and only for this sign-in). You can also type the name.
|
|
28
28
|
- **Custom Properties** take the internal name of the property as the name.
|
|
29
29
|
- **Dates** are ISO 8601 text, such as `2025-01-31T10:00:00Z`. The node changes them to the form that HubSpot wants.
|
|
30
30
|
- **Contact > Create or Update** can link a company with **Associated Company ID**. When **Simplify Output** is off, the node gets the full profile of the contact and adds `isNew`.
|
|
@@ -54,7 +54,7 @@ The output is a list of events. HubSpot gives `objectId`. The trigger renames it
|
|
|
54
54
|
|
|
55
55
|
- **HubSpot service key** (`hubspot.appToken`): `appToken`, the token of a service key (private app) of your account. The **Test** button reads one contact (`GET /crm/v3/objects/contacts?limit=1`). The **Test** button reads one contact (`GET /crm/v3/objects/contacts?limit=1`).
|
|
56
56
|
- **HubSpot OAuth2** (`hubspot.oauth2`): `clientId` and `clientSecret` of your public app. The scopes are `crm.lists.write`, `crm.objects.contacts.read/write`, `crm.objects.companies.read/write`, `crm.objects.deals.read/write`, `crm.objects.owners.read`, `crm.schemas.contacts/companies/deals.read`, `forms`, and `tickets`.
|
|
57
|
-
- **HubSpot developer API** (`hubspot.developerApi`): `apiKey` (developer API key), `appId`, `clientSecret`, and `clientId`. Only the trigger uses it.
|
|
57
|
+
- **HubSpot developer API** (`hubspot.developerApi`): `apiKey` (developer API key), `appId`, `clientSecret`, and `clientId`. Only the trigger uses it. Sign in with OAuth2 to load property names in the editor.
|
|
58
58
|
|
|
59
59
|
The legacy HubSpot API key is not supported. HubSpot ended it.
|
|
60
60
|
|
package/dist/index.cjs
CHANGED
|
@@ -7,11 +7,11 @@ const HUBSPOT_TOKEN_CREDENTIAL = "hubspot.appToken";
|
|
|
7
7
|
const HUBSPOT_OAUTH2_CREDENTIAL = "hubspot.oauth2";
|
|
8
8
|
const HUBSPOT_DEVELOPER_CREDENTIAL = "hubspot.developerApi";
|
|
9
9
|
const HUBSPOT_API = "https://api.hubapi.com";
|
|
10
|
-
const text = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
10
|
+
const text$1 = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
11
11
|
/** The access of a service key credential or an OAuth2 credential. */
|
|
12
12
|
function hubspotAccess(credential) {
|
|
13
13
|
if (credential?.type === "hubspot.appToken") {
|
|
14
|
-
const token = text(credential.data.appToken);
|
|
14
|
+
const token = text$1(credential.data.appToken);
|
|
15
15
|
if (!token) throw new Error("The credential has no \"appToken\"");
|
|
16
16
|
return {
|
|
17
17
|
kind: "bearer",
|
|
@@ -19,7 +19,7 @@ function hubspotAccess(credential) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
if (credential?.type === "hubspot.oauth2") {
|
|
22
|
-
const token = text(credential.data.accessToken);
|
|
22
|
+
const token = text$1(credential.data.accessToken);
|
|
23
23
|
if (!token) throw new Error("The HubSpot credential is not connected to an account yet");
|
|
24
24
|
return {
|
|
25
25
|
kind: "bearer",
|
|
@@ -31,9 +31,9 @@ function hubspotAccess(credential) {
|
|
|
31
31
|
/** The developer API credential of an app. The trigger uses it. */
|
|
32
32
|
function developerAccess(credential) {
|
|
33
33
|
if (!credential || credential.type !== "hubspot.developerApi") throw new Error("The trigger needs a HubSpot developer API credential");
|
|
34
|
-
const appId = text(credential.data.appId);
|
|
35
|
-
const apiKey = text(credential.data.apiKey);
|
|
36
|
-
const clientSecret = text(credential.data.clientSecret);
|
|
34
|
+
const appId = text$1(credential.data.appId);
|
|
35
|
+
const apiKey = text$1(credential.data.apiKey);
|
|
36
|
+
const clientSecret = text$1(credential.data.clientSecret);
|
|
37
37
|
if (!appId) throw new Error("The credential has no \"appId\"");
|
|
38
38
|
if (!apiKey) throw new Error("The credential has no \"apiKey\"");
|
|
39
39
|
if (!clientSecret) throw new Error("The credential has no \"clientSecret\"");
|
|
@@ -155,7 +155,7 @@ async function callHubspotList(access, call, spec, limit, options) {
|
|
|
155
155
|
// src/icon.ts
|
|
156
156
|
const HUBSPOT_ICON = (0, _zerodot_node_sdk.fileIcon)(require("url").pathToFileURL(__filename).href, "../hubspot.svg");
|
|
157
157
|
// src/credential.ts
|
|
158
|
-
const TIMEOUT_MS$
|
|
158
|
+
const TIMEOUT_MS$2 = 1e4;
|
|
159
159
|
const HUBSPOT_OAUTH2 = {
|
|
160
160
|
authUrl: "https://app.hubspot.com/oauth/authorize",
|
|
161
161
|
tokenUrl: "https://api.hubapi.com/oauth/v1/token",
|
|
@@ -177,6 +177,21 @@ const HUBSPOT_OAUTH2 = {
|
|
|
177
177
|
authQuery: { grant_type: "authorization_code" },
|
|
178
178
|
authentication: "body"
|
|
179
179
|
};
|
|
180
|
+
/** The scopes of the trigger credential. They are to read the property names. */
|
|
181
|
+
const DEVELOPER_SCOPES = [
|
|
182
|
+
"crm.objects.contacts.read",
|
|
183
|
+
"crm.schemas.contacts.read",
|
|
184
|
+
"crm.objects.companies.read",
|
|
185
|
+
"crm.schemas.companies.read",
|
|
186
|
+
"crm.objects.deals.read",
|
|
187
|
+
"crm.schemas.deals.read",
|
|
188
|
+
"conversations.read",
|
|
189
|
+
"tickets"
|
|
190
|
+
];
|
|
191
|
+
const HUBSPOT_DEVELOPER_OAUTH2 = {
|
|
192
|
+
...HUBSPOT_OAUTH2,
|
|
193
|
+
scopes: DEVELOPER_SCOPES
|
|
194
|
+
};
|
|
180
195
|
/** Fields that only the server writes, after the user connects the account. */
|
|
181
196
|
const OAUTH2_TOKEN_FIELDS = [
|
|
182
197
|
"accessToken",
|
|
@@ -192,8 +207,8 @@ async function check(credential) {
|
|
|
192
207
|
path: "/crm/v3/objects/contacts",
|
|
193
208
|
query: { limit: 1 }
|
|
194
209
|
}, {
|
|
195
|
-
signal: AbortSignal.timeout(TIMEOUT_MS$
|
|
196
|
-
timeoutMs: TIMEOUT_MS$
|
|
210
|
+
signal: AbortSignal.timeout(TIMEOUT_MS$2),
|
|
211
|
+
timeoutMs: TIMEOUT_MS$2
|
|
197
212
|
});
|
|
198
213
|
}
|
|
199
214
|
const hubspotTokenCredential = {
|
|
@@ -242,11 +257,25 @@ const hubspotDeveloperCredential = {
|
|
|
242
257
|
/** The key of the developer account. It sets the webhook settings of the app. */
|
|
243
258
|
apiKey: zod.z.string().min(1).meta({ title: "Developer API Key" }),
|
|
244
259
|
appId: zod.z.string().min(1).meta({ title: "App ID" }),
|
|
260
|
+
/** Only for the OAuth2 sign-in that loads property names in the editor. */
|
|
245
261
|
clientId: zod.z.string().min(1).optional().meta({ title: "Client ID" }),
|
|
246
262
|
/** HubSpot signs each webhook request with the client secret of the app. */
|
|
247
|
-
clientSecret: zod.z.string().min(1).meta({ title: "Client Secret" })
|
|
263
|
+
clientSecret: zod.z.string().min(1).meta({ title: "Client Secret" }),
|
|
264
|
+
accessToken: zod.z.string().min(1).optional(),
|
|
265
|
+
refreshToken: zod.z.string().min(1).optional(),
|
|
266
|
+
/** ISO 8601 time. */
|
|
267
|
+
expiresAt: zod.z.iso.datetime().optional(),
|
|
268
|
+
tokenType: zod.z.string().min(1).optional(),
|
|
269
|
+
grantedScope: zod.z.string().optional()
|
|
248
270
|
}),
|
|
249
|
-
secretFields: [
|
|
271
|
+
secretFields: [
|
|
272
|
+
"apiKey",
|
|
273
|
+
"clientSecret",
|
|
274
|
+
"accessToken",
|
|
275
|
+
"refreshToken"
|
|
276
|
+
],
|
|
277
|
+
serverFields: [...OAUTH2_TOKEN_FIELDS],
|
|
278
|
+
oauth2: HUBSPOT_DEVELOPER_OAUTH2,
|
|
250
279
|
icon: "UserGroupIcon",
|
|
251
280
|
iconUrl: HUBSPOT_ICON,
|
|
252
281
|
async test({ data }) {
|
|
@@ -261,8 +290,8 @@ const hubspotDeveloperCredential = {
|
|
|
261
290
|
method: "GET",
|
|
262
291
|
path: `/webhooks/v3/${encodeURIComponent(appId)}/settings`
|
|
263
292
|
}, {
|
|
264
|
-
signal: AbortSignal.timeout(TIMEOUT_MS$
|
|
265
|
-
timeoutMs: TIMEOUT_MS$
|
|
293
|
+
signal: AbortSignal.timeout(TIMEOUT_MS$2),
|
|
294
|
+
timeoutMs: TIMEOUT_MS$2
|
|
266
295
|
});
|
|
267
296
|
} catch (error) {
|
|
268
297
|
if (error instanceof HubspotError && error.status === 404) return;
|
|
@@ -2392,10 +2421,59 @@ const on = (operations) => ({ showWhen: Object.entries(operations).map(([resourc
|
|
|
2392
2421
|
operation: [...ops ?? []]
|
|
2393
2422
|
})) });
|
|
2394
2423
|
const ISO_HINT = "A date and time as ISO 8601, such as 2025-01-31T10:00:00Z";
|
|
2424
|
+
const load = (name, dependsOn, searchable, urlPattern) => ({
|
|
2425
|
+
loadOptions: name,
|
|
2426
|
+
...dependsOn ? { dependsOn } : {},
|
|
2427
|
+
...searchable ? { searchable } : {},
|
|
2428
|
+
...urlPattern ? { urlPattern } : {}
|
|
2429
|
+
});
|
|
2430
|
+
const CONTACT_LOADERS = {
|
|
2431
|
+
contactOwner: load("owners"),
|
|
2432
|
+
leadStatus: load("contactLeadStatuses"),
|
|
2433
|
+
processingContactData: load("contactLegalBasis"),
|
|
2434
|
+
lifeCycleStage: load("contactLifecycleStages"),
|
|
2435
|
+
numberOfEmployees: load("contactEmployees"),
|
|
2436
|
+
originalSource: load("contactOriginalSources"),
|
|
2437
|
+
prefferedLanguage: load("contactLanguages"),
|
|
2438
|
+
status: load("contactStatuses")
|
|
2439
|
+
};
|
|
2440
|
+
const COMPANY_LOADERS = {
|
|
2441
|
+
companyOwner: load("owners"),
|
|
2442
|
+
industry: load("companyIndustries"),
|
|
2443
|
+
leadStatus: load("companyLeadStatuses"),
|
|
2444
|
+
lifecycleStatus: load("companyLifecycleStages"),
|
|
2445
|
+
originalSourceType: load("companySourceTypes"),
|
|
2446
|
+
targetAccount: load("companyTargetAccounts"),
|
|
2447
|
+
type: load("companyTypes"),
|
|
2448
|
+
webTechnologies: load("companyWebTechnologies")
|
|
2449
|
+
};
|
|
2450
|
+
const DEAL_CREATE_LOADERS = {
|
|
2451
|
+
dealOwner: load("owners"),
|
|
2452
|
+
dealType: load("dealTypes"),
|
|
2453
|
+
pipeline: load("dealPipelines")
|
|
2454
|
+
};
|
|
2455
|
+
const DEAL_UPDATE_LOADERS = {
|
|
2456
|
+
dealOwner: load("owners"),
|
|
2457
|
+
dealType: load("dealTypes"),
|
|
2458
|
+
stage: load("dealStages")
|
|
2459
|
+
};
|
|
2460
|
+
const TICKET_CREATE_LOADERS = {
|
|
2461
|
+
category: load("ticketCategories"),
|
|
2462
|
+
priority: load("ticketPriorities"),
|
|
2463
|
+
resolution: load("ticketResolutions"),
|
|
2464
|
+
source: load("ticketSources"),
|
|
2465
|
+
ticketOwnerId: load("owners")
|
|
2466
|
+
};
|
|
2467
|
+
const TICKET_UPDATE_LOADERS = {
|
|
2468
|
+
...TICKET_CREATE_LOADERS,
|
|
2469
|
+
pipelineId: load("ticketPipelines"),
|
|
2470
|
+
stageId: load("ticketStages", [".pipelineId"])
|
|
2471
|
+
};
|
|
2395
2472
|
/** The zod type of one field of an object. */
|
|
2396
|
-
function fieldSchema(spec) {
|
|
2473
|
+
function fieldSchema(spec, loader) {
|
|
2397
2474
|
let schema;
|
|
2398
2475
|
const meta = { title: spec.title };
|
|
2476
|
+
if (loader) Object.assign(meta, loader);
|
|
2399
2477
|
if (spec.description) meta.description = spec.description;
|
|
2400
2478
|
switch (spec.kind) {
|
|
2401
2479
|
case "number":
|
|
@@ -2417,8 +2495,8 @@ function fieldSchema(spec) {
|
|
|
2417
2495
|
return schema.meta(meta);
|
|
2418
2496
|
}
|
|
2419
2497
|
/** An object with one optional key for each field. */
|
|
2420
|
-
const collectionOf = (specs, extra = {}) => zod.z.object({
|
|
2421
|
-
...Object.fromEntries(specs.map((spec) => [spec.key, fieldSchema(spec)])),
|
|
2498
|
+
const collectionOf = (specs, extra = {}, loaders = {}) => zod.z.object({
|
|
2499
|
+
...Object.fromEntries(specs.map((spec) => [spec.key, fieldSchema(spec, loaders[spec.key])])),
|
|
2422
2500
|
...extra
|
|
2423
2501
|
}).partial();
|
|
2424
2502
|
const customProperties = zod.z.record(zod.z.string(), zod.z.unknown()).meta({
|
|
@@ -2426,9 +2504,10 @@ const customProperties = zod.z.record(zod.z.string(), zod.z.unknown()).meta({
|
|
|
2426
2504
|
title: "Custom Properties",
|
|
2427
2505
|
description: "The name is the internal name of the property. The value is the new value"
|
|
2428
2506
|
});
|
|
2429
|
-
const propertyList = (title, description) => zod.z.array(zod.z.string()).meta({
|
|
2507
|
+
const propertyList = (title, description, loadOptions) => zod.z.array(zod.z.string()).meta({
|
|
2430
2508
|
title,
|
|
2431
|
-
description
|
|
2509
|
+
description,
|
|
2510
|
+
...load(loadOptions)
|
|
2432
2511
|
});
|
|
2433
2512
|
const propertyMode = zod.z.enum(PROPERTY_MODES).meta({
|
|
2434
2513
|
title: "Include",
|
|
@@ -2444,6 +2523,7 @@ const sinceField = zod.z.string().meta({
|
|
|
2444
2523
|
});
|
|
2445
2524
|
const filterItem = zod.z.object({
|
|
2446
2525
|
propertyName: zod.z.string().meta({
|
|
2526
|
+
...load("searchProperties", ["resource"]),
|
|
2447
2527
|
title: "Property Name",
|
|
2448
2528
|
description: "The internal name of the property, such as email"
|
|
2449
2529
|
}),
|
|
@@ -2481,16 +2561,19 @@ const searchOptions = zod.z.object({
|
|
|
2481
2561
|
DESCENDING: "Descending"
|
|
2482
2562
|
}
|
|
2483
2563
|
}),
|
|
2484
|
-
properties: propertyList("Field Names", "The properties to include in the results, such as firstname"),
|
|
2564
|
+
properties: propertyList("Field Names", "The properties to include in the results, such as firstname", "searchProperties").meta({ dependsOn: ["resource"] }),
|
|
2485
2565
|
query: zod.z.string().meta({ description: "A text search against all property values of the object type" }),
|
|
2486
2566
|
sortBy: zod.z.string().meta({
|
|
2567
|
+
...load("searchProperties", ["resource"]),
|
|
2487
2568
|
title: "Sort By",
|
|
2488
2569
|
description: "The internal name of the property to sort by. The default is createdate"
|
|
2489
2570
|
})
|
|
2490
2571
|
}).partial();
|
|
2491
|
-
|
|
2572
|
+
/** A list of IDs. A text with commas between (the old shape) still works. */
|
|
2573
|
+
const idList = (title, description, loadOptions) => zod.z.preprocess((value) => typeof value === "string" ? value.split(",").map((item) => item.trim()).filter(Boolean) : value, zod.z.array(zod.z.string())).optional().meta({
|
|
2492
2574
|
title,
|
|
2493
|
-
description
|
|
2575
|
+
description,
|
|
2576
|
+
...load(loadOptions, void 0, true)
|
|
2494
2577
|
});
|
|
2495
2578
|
const taskMetadata = zod.z.object({
|
|
2496
2579
|
body: zod.z.string(),
|
|
@@ -2662,16 +2745,19 @@ const hubspotConfig = zod.z.object({
|
|
|
2662
2745
|
}),
|
|
2663
2746
|
contactFields: collectionOf(CONTACT_FIELDS, {
|
|
2664
2747
|
associatedCompanyId: zod.z.string().meta({
|
|
2665
|
-
|
|
2666
|
-
|
|
2748
|
+
ui: "collection",
|
|
2749
|
+
title: "Associated Company",
|
|
2750
|
+
description: "The company to link to the contact",
|
|
2751
|
+
...load("companies", void 0, true)
|
|
2667
2752
|
}),
|
|
2668
|
-
properties: propertyList("Contact Properties to Include", "The properties to include in the result. Used when Simplify Output is off"),
|
|
2753
|
+
properties: propertyList("Contact Properties to Include", "The properties to include in the result. Used when Simplify Output is off", "contactProperties"),
|
|
2669
2754
|
customProperties
|
|
2670
|
-
}).default({}).meta({
|
|
2755
|
+
}, CONTACT_LOADERS).default({}).meta({
|
|
2671
2756
|
...on({ contact: ["upsert"] }),
|
|
2672
2757
|
title: "Contact Properties"
|
|
2673
2758
|
}),
|
|
2674
2759
|
upsertOptions: zod.z.object({ resolveData: zod.z.boolean().meta({
|
|
2760
|
+
ui: "collection",
|
|
2675
2761
|
title: "Simplify Output",
|
|
2676
2762
|
description: "On: the result is the answer of the update. Off: the node gets the full profile of the contact"
|
|
2677
2763
|
}) }).partial().default({}).meta({
|
|
@@ -2680,6 +2766,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2680
2766
|
}),
|
|
2681
2767
|
contactId: zod.z.string().optional().meta({
|
|
2682
2768
|
...on({ contact: ["delete", "get"] }),
|
|
2769
|
+
...load("contacts", void 0, true, "hubspot\\.com/contacts/\\d+/(?:record|objects)/0-1/(\\d+)"),
|
|
2683
2770
|
title: "Contact ID",
|
|
2684
2771
|
description: "The ID of the contact. This is not the email, but a number such as 1485"
|
|
2685
2772
|
}),
|
|
@@ -2690,6 +2777,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2690
2777
|
"newest",
|
|
2691
2778
|
"oldest"
|
|
2692
2779
|
]).meta({
|
|
2780
|
+
ui: "collection",
|
|
2693
2781
|
title: "Form Submission Mode",
|
|
2694
2782
|
description: "Which form submissions to get",
|
|
2695
2783
|
labels: {
|
|
@@ -2703,7 +2791,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2703
2791
|
title: "Include List Memberships",
|
|
2704
2792
|
description: "Get the current list memberships of the contact"
|
|
2705
2793
|
}),
|
|
2706
|
-
properties: propertyList("Contact Properties to Include", "The properties to include in the results. By default the results have only the contact ID"),
|
|
2794
|
+
properties: propertyList("Contact Properties to Include", "The properties to include in the results. By default the results have only the contact ID", "contactProperties"),
|
|
2707
2795
|
propertyMode
|
|
2708
2796
|
}).partial().default({}).meta({
|
|
2709
2797
|
...on({ contact: [
|
|
@@ -2722,6 +2810,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2722
2810
|
description: "Groups combine with OR. HubSpot allows 3 groups at most. The filters of one group combine with AND"
|
|
2723
2811
|
}),
|
|
2724
2812
|
searchOptions: searchOptions.default({}).meta({
|
|
2813
|
+
ui: "collection",
|
|
2725
2814
|
...on({
|
|
2726
2815
|
contact: ["search"],
|
|
2727
2816
|
deal: ["search"]
|
|
@@ -2753,6 +2842,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2753
2842
|
}),
|
|
2754
2843
|
listId: zod.z.number().optional().meta({
|
|
2755
2844
|
...on({ contactList: ["add", "remove"] }),
|
|
2845
|
+
...load("contactLists", void 0, true),
|
|
2756
2846
|
title: "List ID",
|
|
2757
2847
|
description: "The ID of the list, as HubSpot shows it (the ILS list ID). HubSpot allows only static lists"
|
|
2758
2848
|
}),
|
|
@@ -2760,7 +2850,8 @@ const hubspotConfig = zod.z.object({
|
|
|
2760
2850
|
resource: ["company"],
|
|
2761
2851
|
operation: ["create"]
|
|
2762
2852
|
} }),
|
|
2763
|
-
companyFields: collectionOf(COMPANY_CREATE_FIELDS, { customProperties }).default({}).meta({
|
|
2853
|
+
companyFields: collectionOf(COMPANY_CREATE_FIELDS, { customProperties }, COMPANY_LOADERS).default({}).meta({
|
|
2854
|
+
ui: "collection",
|
|
2764
2855
|
...on({ company: ["create"] }),
|
|
2765
2856
|
title: "Company Properties"
|
|
2766
2857
|
}),
|
|
@@ -2770,13 +2861,16 @@ const hubspotConfig = zod.z.object({
|
|
|
2770
2861
|
"get",
|
|
2771
2862
|
"update"
|
|
2772
2863
|
] }),
|
|
2864
|
+
...load("companies", void 0, true, "hubspot\\.com/contacts/\\d+/(?:record|objects)/0-2/(\\d+)"),
|
|
2773
2865
|
title: "Company ID"
|
|
2774
2866
|
}),
|
|
2775
|
-
companyUpdateFields: collectionOf(COMPANY_UPDATE_FIELDS, { customProperties }).default({}).meta({
|
|
2867
|
+
companyUpdateFields: collectionOf(COMPANY_UPDATE_FIELDS, { customProperties }, COMPANY_LOADERS).default({}).meta({
|
|
2868
|
+
ui: "collection",
|
|
2776
2869
|
...on({ company: ["update"] }),
|
|
2777
2870
|
title: "Update Fields"
|
|
2778
2871
|
}),
|
|
2779
2872
|
companyGetOptions: zod.z.object({ includeMergeAudits: zod.z.boolean().meta({
|
|
2873
|
+
ui: "collection",
|
|
2780
2874
|
title: "Include Merge Audits",
|
|
2781
2875
|
description: "Get the merge history if the company merged with another company record"
|
|
2782
2876
|
}) }).partial().default({}).meta({
|
|
@@ -2785,18 +2879,22 @@ const hubspotConfig = zod.z.object({
|
|
|
2785
2879
|
}),
|
|
2786
2880
|
companyListOptions: zod.z.object({
|
|
2787
2881
|
includeMergeAudits: zod.z.boolean().meta({
|
|
2882
|
+
ui: "collection",
|
|
2788
2883
|
title: "Include Merge Audits",
|
|
2789
2884
|
description: "Get the merge history if a company merged with another company record"
|
|
2790
2885
|
}),
|
|
2791
|
-
properties: propertyList("Companies Properties to Include", "The properties to include in the results"),
|
|
2886
|
+
properties: propertyList("Companies Properties to Include", "The properties to include in the results", "companyProperties"),
|
|
2792
2887
|
propertyMode
|
|
2793
2888
|
}).partial().default({}).meta({
|
|
2794
2889
|
...on({ company: ["getAll"] }),
|
|
2795
2890
|
title: "Options"
|
|
2796
2891
|
}),
|
|
2797
2892
|
companyRecentOptions: zod.z.object({
|
|
2798
|
-
since: sinceField.meta({
|
|
2799
|
-
|
|
2893
|
+
since: sinceField.meta({
|
|
2894
|
+
ui: "collection",
|
|
2895
|
+
description: `Only companies created or updated after this time. ${ISO_HINT}`
|
|
2896
|
+
}),
|
|
2897
|
+
properties: propertyList("Companies Properties to Include", "The properties to include in the results", "companyProperties"),
|
|
2800
2898
|
propertyMode
|
|
2801
2899
|
}).partial().default({}).meta({
|
|
2802
2900
|
...on({ company: ["getRecentlyCreatedUpdated"] }),
|
|
@@ -2809,7 +2907,8 @@ const hubspotConfig = zod.z.object({
|
|
|
2809
2907
|
},
|
|
2810
2908
|
description: "The website domain of the company, such as example.com"
|
|
2811
2909
|
}),
|
|
2812
|
-
domainOptions: zod.z.object({ properties: propertyList("Company Properties to Include", "The properties to include in the results") }).partial().default({}).meta({
|
|
2910
|
+
domainOptions: zod.z.object({ properties: propertyList("Company Properties to Include", "The properties to include in the results", "companyProperties") }).partial().default({}).meta({
|
|
2911
|
+
ui: "collection",
|
|
2813
2912
|
...on({ company: ["searchByDomain"] }),
|
|
2814
2913
|
title: "Options"
|
|
2815
2914
|
}),
|
|
@@ -2818,14 +2917,16 @@ const hubspotConfig = zod.z.object({
|
|
|
2818
2917
|
resource: ["deal"],
|
|
2819
2918
|
operation: ["create"]
|
|
2820
2919
|
},
|
|
2920
|
+
...load("dealStages"),
|
|
2821
2921
|
title: "Deal Stage",
|
|
2822
2922
|
description: "The ID of the deal stage. The deal needs a stage. See the CRM Pipelines API for stages"
|
|
2823
2923
|
}),
|
|
2824
2924
|
dealFields: collectionOf(DEAL_CREATE_FIELDS, {
|
|
2825
|
-
associatedCompany: idList("Associated Company IDs", "IDs of companies to link to the deal, with commas between"),
|
|
2826
|
-
associatedVids: idList("Associated Contact IDs", "IDs of contacts to link to the deal, with commas between"),
|
|
2925
|
+
associatedCompany: idList("Associated Company IDs", "IDs of companies to link to the deal, with commas between", "companies"),
|
|
2926
|
+
associatedVids: idList("Associated Contact IDs", "IDs of contacts to link to the deal, with commas between", "contacts"),
|
|
2827
2927
|
customProperties
|
|
2828
|
-
}).default({}).meta({
|
|
2928
|
+
}, DEAL_CREATE_LOADERS).default({}).meta({
|
|
2929
|
+
ui: "collection",
|
|
2829
2930
|
...on({ deal: ["create"] }),
|
|
2830
2931
|
title: "Deal Properties"
|
|
2831
2932
|
}),
|
|
@@ -2835,18 +2936,21 @@ const hubspotConfig = zod.z.object({
|
|
|
2835
2936
|
"get",
|
|
2836
2937
|
"update"
|
|
2837
2938
|
] }),
|
|
2939
|
+
...load("deals", void 0, true, "hubspot\\.com/contacts/\\d+/(?:record|objects)/0-3/(\\d+)"),
|
|
2838
2940
|
title: "Deal ID"
|
|
2839
2941
|
}),
|
|
2840
|
-
dealUpdateFields: collectionOf(DEAL_UPDATE_FIELDS, { customProperties }).default({}).meta({
|
|
2942
|
+
dealUpdateFields: collectionOf(DEAL_UPDATE_FIELDS, { customProperties }, DEAL_UPDATE_LOADERS).default({}).meta({
|
|
2943
|
+
ui: "collection",
|
|
2841
2944
|
...on({ deal: ["update"] }),
|
|
2842
2945
|
title: "Update Fields"
|
|
2843
2946
|
}),
|
|
2844
2947
|
dealGetOptions: zod.z.object({
|
|
2845
2948
|
includePropertyVersions: zod.z.boolean().meta({
|
|
2949
|
+
ui: "collection",
|
|
2846
2950
|
title: "Include Property Versions",
|
|
2847
2951
|
description: "By default you get only the latest version of a property. On: you get all old versions too"
|
|
2848
2952
|
}),
|
|
2849
|
-
properties: propertyList("Deal Properties to Include", "The properties to include in the results. By default the results have only the deal ID"),
|
|
2953
|
+
properties: propertyList("Deal Properties to Include", "The properties to include in the results. By default the results have only the deal ID", "dealProperties"),
|
|
2850
2954
|
propertyMode
|
|
2851
2955
|
}).partial().default({}).meta({
|
|
2852
2956
|
...on({ deal: ["get"] }),
|
|
@@ -2854,17 +2958,21 @@ const hubspotConfig = zod.z.object({
|
|
|
2854
2958
|
}),
|
|
2855
2959
|
dealListOptions: zod.z.object({
|
|
2856
2960
|
includeAssociations: zod.z.boolean().meta({
|
|
2961
|
+
ui: "collection",
|
|
2857
2962
|
title: "Include Associations",
|
|
2858
2963
|
description: "Include the IDs of the associated contacts and companies in the results. This also adds the num_associated_contacts property"
|
|
2859
2964
|
}),
|
|
2860
|
-
properties: propertyList("Deal Properties to Include", "The properties to include in the results. By default the results have only the deal ID"),
|
|
2861
|
-
propertiesWithHistory: propertyList("Deal Properties with History to Include", "Works as Properties, but the results have the history of each property")
|
|
2965
|
+
properties: propertyList("Deal Properties to Include", "The properties to include in the results. By default the results have only the deal ID", "dealProperties"),
|
|
2966
|
+
propertiesWithHistory: propertyList("Deal Properties with History to Include", "Works as Properties, but the results have the history of each property", "dealProperties")
|
|
2862
2967
|
}).partial().default({}).meta({
|
|
2863
2968
|
...on({ deal: ["getAll"] }),
|
|
2864
2969
|
title: "Options"
|
|
2865
2970
|
}),
|
|
2866
2971
|
dealRecentOptions: zod.z.object({
|
|
2867
|
-
since: sinceField.meta({
|
|
2972
|
+
since: sinceField.meta({
|
|
2973
|
+
ui: "collection",
|
|
2974
|
+
description: `Only deals created after this time. ${ISO_HINT}`
|
|
2975
|
+
}),
|
|
2868
2976
|
includePropertyVersions: zod.z.boolean().meta({
|
|
2869
2977
|
title: "Include Property Versions",
|
|
2870
2978
|
description: "By default you get only the latest version of a property. On: you get all old versions too"
|
|
@@ -2897,6 +3005,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2897
3005
|
description: `The due date of the task. ${ISO_HINT}`
|
|
2898
3006
|
}),
|
|
2899
3007
|
taskMetadata: taskMetadata.default({}).meta({
|
|
3008
|
+
ui: "collection",
|
|
2900
3009
|
showWhen: {
|
|
2901
3010
|
resource: ["engagement"],
|
|
2902
3011
|
operation: ["create"],
|
|
@@ -2905,6 +3014,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2905
3014
|
title: "Metadata"
|
|
2906
3015
|
}),
|
|
2907
3016
|
emailMetadata: emailMetadata.default({}).meta({
|
|
3017
|
+
ui: "collection",
|
|
2908
3018
|
showWhen: {
|
|
2909
3019
|
resource: ["engagement"],
|
|
2910
3020
|
operation: ["create"],
|
|
@@ -2913,6 +3023,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2913
3023
|
title: "Metadata"
|
|
2914
3024
|
}),
|
|
2915
3025
|
meetingMetadata: meetingMetadata.default({}).meta({
|
|
3026
|
+
ui: "collection",
|
|
2916
3027
|
showWhen: {
|
|
2917
3028
|
resource: ["engagement"],
|
|
2918
3029
|
operation: ["create"],
|
|
@@ -2921,6 +3032,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2921
3032
|
title: "Metadata"
|
|
2922
3033
|
}),
|
|
2923
3034
|
callMetadata: callMetadata.default({}).meta({
|
|
3035
|
+
ui: "collection",
|
|
2924
3036
|
showWhen: {
|
|
2925
3037
|
resource: ["engagement"],
|
|
2926
3038
|
operation: ["create"],
|
|
@@ -2930,6 +3042,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2930
3042
|
}),
|
|
2931
3043
|
associations: zod.z.object({
|
|
2932
3044
|
companyIds: zod.z.string().meta({
|
|
3045
|
+
ui: "collection",
|
|
2933
3046
|
title: "Company IDs",
|
|
2934
3047
|
description: "IDs with commas between"
|
|
2935
3048
|
}),
|
|
@@ -2955,6 +3068,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2955
3068
|
}),
|
|
2956
3069
|
engagementId: zod.z.string().optional().meta({
|
|
2957
3070
|
...on({ engagement: ["delete", "get"] }),
|
|
3071
|
+
...load("engagements", ["type"]),
|
|
2958
3072
|
title: "Engagement ID"
|
|
2959
3073
|
}),
|
|
2960
3074
|
pipelineId: zod.z.string().optional().meta({
|
|
@@ -2962,6 +3076,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2962
3076
|
resource: ["ticket"],
|
|
2963
3077
|
operation: ["create"]
|
|
2964
3078
|
},
|
|
3079
|
+
...load("ticketPipelines"),
|
|
2965
3080
|
title: "Pipeline ID",
|
|
2966
3081
|
description: "The ID of the pipeline of the ticket"
|
|
2967
3082
|
}),
|
|
@@ -2970,6 +3085,7 @@ const hubspotConfig = zod.z.object({
|
|
|
2970
3085
|
resource: ["ticket"],
|
|
2971
3086
|
operation: ["create"]
|
|
2972
3087
|
},
|
|
3088
|
+
...load("ticketStages", [".pipelineId"]),
|
|
2973
3089
|
title: "Stage ID",
|
|
2974
3090
|
description: "The ID of the stage in the pipeline of the ticket"
|
|
2975
3091
|
}),
|
|
@@ -2978,9 +3094,10 @@ const hubspotConfig = zod.z.object({
|
|
|
2978
3094
|
operation: ["create"]
|
|
2979
3095
|
} }),
|
|
2980
3096
|
ticketFields: collectionOf(TICKET_CREATE_FIELDS, {
|
|
2981
|
-
associatedCompanyIds: idList("Company IDs", "IDs of companies to link to the ticket, with commas between"),
|
|
2982
|
-
associatedContactIds: idList("Contact IDs", "IDs of contacts to link to the ticket, with commas between")
|
|
2983
|
-
}).default({}).meta({
|
|
3097
|
+
associatedCompanyIds: idList("Company IDs", "IDs of companies to link to the ticket, with commas between", "companies"),
|
|
3098
|
+
associatedContactIds: idList("Contact IDs", "IDs of contacts to link to the ticket, with commas between", "contacts")
|
|
3099
|
+
}, TICKET_CREATE_LOADERS).default({}).meta({
|
|
3100
|
+
ui: "collection",
|
|
2984
3101
|
...on({ ticket: ["create"] }),
|
|
2985
3102
|
title: "Ticket Properties"
|
|
2986
3103
|
}),
|
|
@@ -2990,27 +3107,33 @@ const hubspotConfig = zod.z.object({
|
|
|
2990
3107
|
"get",
|
|
2991
3108
|
"update"
|
|
2992
3109
|
] }),
|
|
3110
|
+
...load("tickets", void 0, true, "hubspot\\.com/contacts/\\d+/(?:record|objects)/0-5/(\\d+)"),
|
|
2993
3111
|
title: "Ticket ID"
|
|
2994
3112
|
}),
|
|
2995
3113
|
ticketUpdateFields: collectionOf(TICKET_UPDATE_FIELDS, {
|
|
2996
|
-
associatedCompanyIds: idList("Company IDs", "IDs of companies to link to the ticket, with commas between"),
|
|
2997
|
-
associatedContactIds: idList("Contact IDs", "IDs of contacts to link to the ticket, with commas between")
|
|
2998
|
-
}).default({}).meta({
|
|
3114
|
+
associatedCompanyIds: idList("Company IDs", "IDs of companies to link to the ticket, with commas between", "companies"),
|
|
3115
|
+
associatedContactIds: idList("Contact IDs", "IDs of contacts to link to the ticket, with commas between", "contacts")
|
|
3116
|
+
}, TICKET_UPDATE_LOADERS).default({}).meta({
|
|
3117
|
+
ui: "collection",
|
|
2999
3118
|
...on({ ticket: ["update"] }),
|
|
3000
3119
|
title: "Update Fields"
|
|
3001
3120
|
}),
|
|
3002
3121
|
ticketGetOptions: zod.z.object({
|
|
3003
|
-
includeDeleted: zod.z.boolean().meta({
|
|
3004
|
-
|
|
3005
|
-
|
|
3122
|
+
includeDeleted: zod.z.boolean().meta({
|
|
3123
|
+
ui: "collection",
|
|
3124
|
+
title: "Include Deleted"
|
|
3125
|
+
}),
|
|
3126
|
+
properties: propertyList("Ticket Properties to Include", "The properties to include in the results", "ticketProperties"),
|
|
3127
|
+
propertiesWithHistory: propertyList("Properties With History", "Works as Properties, but the results have the history of each property", "ticketProperties")
|
|
3006
3128
|
}).partial().default({}).meta({
|
|
3007
3129
|
...on({ ticket: ["get"] }),
|
|
3008
3130
|
title: "Options"
|
|
3009
3131
|
}),
|
|
3010
3132
|
ticketListOptions: zod.z.object({
|
|
3011
|
-
properties: propertyList("Ticket Properties to Include", "The properties to include in the results"),
|
|
3012
|
-
propertiesWithHistory: propertyList("Properties With History", "Works as Properties, but the results have the history of each property")
|
|
3133
|
+
properties: propertyList("Ticket Properties to Include", "The properties to include in the results", "ticketProperties"),
|
|
3134
|
+
propertiesWithHistory: propertyList("Properties With History", "Works as Properties, but the results have the history of each property", "ticketProperties")
|
|
3013
3135
|
}).partial().default({}).meta({
|
|
3136
|
+
ui: "collection",
|
|
3014
3137
|
...on({ ticket: ["getAll"] }),
|
|
3015
3138
|
title: "Options"
|
|
3016
3139
|
}),
|
|
@@ -3045,6 +3168,355 @@ const hubspotConfig = zod.z.object({
|
|
|
3045
3168
|
message: `"${config.operation}" is not an operation of "${config.resource}"`
|
|
3046
3169
|
});
|
|
3047
3170
|
});
|
|
3171
|
+
// src/load.ts
|
|
3172
|
+
const TIMEOUT_MS$1 = 15e3;
|
|
3173
|
+
const PAGE = 100;
|
|
3174
|
+
const rec = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : {};
|
|
3175
|
+
const arr = (value) => Array.isArray(value) ? value : [];
|
|
3176
|
+
const text = (value) => typeof value === "string" && value !== "" ? value : typeof value === "number" ? String(value) : void 0;
|
|
3177
|
+
/** The access of the credential. The trigger credential has an OAuth2 token for these calls. */
|
|
3178
|
+
function accessOf(ctx) {
|
|
3179
|
+
if (ctx.credential?.type === "hubspot.developerApi") {
|
|
3180
|
+
const token = text(ctx.credential.data.accessToken);
|
|
3181
|
+
if (!token) throw new Error("Connect the HubSpot developer credential to an account first");
|
|
3182
|
+
return {
|
|
3183
|
+
kind: "bearer",
|
|
3184
|
+
token
|
|
3185
|
+
};
|
|
3186
|
+
}
|
|
3187
|
+
return hubspotAccess(ctx.credential);
|
|
3188
|
+
}
|
|
3189
|
+
/** One call with the credential of the node. */
|
|
3190
|
+
const send = (ctx, call) => callHubspot(accessOf(ctx), call, {
|
|
3191
|
+
signal: ctx.signal,
|
|
3192
|
+
timeoutMs: TIMEOUT_MS$1
|
|
3193
|
+
});
|
|
3194
|
+
/**
|
|
3195
|
+
* The value of a field next to the one that loads (in the same object or list item). On create
|
|
3196
|
+
* the field is at the top of the config, and its sibling too.
|
|
3197
|
+
*/
|
|
3198
|
+
function siblingOf(ctx, key) {
|
|
3199
|
+
return (0, _zerodot_node_sdk.configValue)(ctx.config, (0, _zerodot_node_sdk.dependsOnPath)(`.${key}`, ctx.path));
|
|
3200
|
+
}
|
|
3201
|
+
/** The `after` cursor of the next page, or null. */
|
|
3202
|
+
const nextOf = (answer) => text(rec(rec(rec(answer).paging).next).after) ?? null;
|
|
3203
|
+
const byLabel = (a, b) => a.label.localeCompare(b.label);
|
|
3204
|
+
/** The owners of the account. The label is the email address. */
|
|
3205
|
+
const owners = async (ctx) => {
|
|
3206
|
+
const answer = await send(ctx, {
|
|
3207
|
+
method: "GET",
|
|
3208
|
+
path: "/crm/v3/owners",
|
|
3209
|
+
query: {
|
|
3210
|
+
limit: PAGE,
|
|
3211
|
+
after: ctx.cursor
|
|
3212
|
+
}
|
|
3213
|
+
});
|
|
3214
|
+
const options = [];
|
|
3215
|
+
for (const item of arr(rec(answer).results)) {
|
|
3216
|
+
const owner = rec(item);
|
|
3217
|
+
const id = text(owner.id);
|
|
3218
|
+
if (id) options.push({
|
|
3219
|
+
label: text(owner.email) ?? id,
|
|
3220
|
+
value: id
|
|
3221
|
+
});
|
|
3222
|
+
}
|
|
3223
|
+
return {
|
|
3224
|
+
options,
|
|
3225
|
+
nextCursor: nextOf(answer)
|
|
3226
|
+
};
|
|
3227
|
+
};
|
|
3228
|
+
/**
|
|
3229
|
+
* The records of one object. With a search text, the search API looks for the text. The value
|
|
3230
|
+
* is the ID of the record.
|
|
3231
|
+
*/
|
|
3232
|
+
function objectLoader(object, properties, toOption) {
|
|
3233
|
+
return async (ctx) => {
|
|
3234
|
+
const search = ctx.search?.trim();
|
|
3235
|
+
const answer = search ? await send(ctx, {
|
|
3236
|
+
method: "POST",
|
|
3237
|
+
path: `/crm/v3/objects/${object}/search`,
|
|
3238
|
+
body: {
|
|
3239
|
+
query: search,
|
|
3240
|
+
properties,
|
|
3241
|
+
limit: PAGE,
|
|
3242
|
+
...ctx.cursor ? { after: ctx.cursor } : {}
|
|
3243
|
+
}
|
|
3244
|
+
}) : await send(ctx, {
|
|
3245
|
+
method: "GET",
|
|
3246
|
+
path: `/crm/v3/objects/${object}`,
|
|
3247
|
+
query: {
|
|
3248
|
+
properties: properties.join(","),
|
|
3249
|
+
limit: PAGE,
|
|
3250
|
+
after: ctx.cursor
|
|
3251
|
+
}
|
|
3252
|
+
});
|
|
3253
|
+
const options = [];
|
|
3254
|
+
for (const item of arr(rec(answer).results)) {
|
|
3255
|
+
const record = rec(item);
|
|
3256
|
+
const id = text(record.id);
|
|
3257
|
+
if (id) options.push(toOption(id, rec(record.properties)));
|
|
3258
|
+
}
|
|
3259
|
+
return {
|
|
3260
|
+
options,
|
|
3261
|
+
nextCursor: nextOf(answer)
|
|
3262
|
+
};
|
|
3263
|
+
};
|
|
3264
|
+
}
|
|
3265
|
+
const companies = objectLoader("companies", ["name"], (id, props) => ({
|
|
3266
|
+
label: text(props.name) ?? id,
|
|
3267
|
+
value: id
|
|
3268
|
+
}));
|
|
3269
|
+
const contacts = objectLoader("contacts", [
|
|
3270
|
+
"firstname",
|
|
3271
|
+
"lastname",
|
|
3272
|
+
"email"
|
|
3273
|
+
], (id, props) => {
|
|
3274
|
+
return {
|
|
3275
|
+
label: `${text(props.firstname) ?? ""} ${text(props.lastname) ?? ""}`.trim() || text(props.email) || id,
|
|
3276
|
+
value: id,
|
|
3277
|
+
description: `Contact ID: ${id}`
|
|
3278
|
+
};
|
|
3279
|
+
});
|
|
3280
|
+
const deals = objectLoader("deals", ["dealname"], (id, props) => ({
|
|
3281
|
+
label: text(props.dealname) ?? id,
|
|
3282
|
+
value: id
|
|
3283
|
+
}));
|
|
3284
|
+
const tickets = objectLoader("tickets", ["subject"], (id, props) => {
|
|
3285
|
+
const subject = text(props.subject);
|
|
3286
|
+
return {
|
|
3287
|
+
label: id,
|
|
3288
|
+
value: id,
|
|
3289
|
+
...subject ? { description: subject } : {}
|
|
3290
|
+
};
|
|
3291
|
+
});
|
|
3292
|
+
const ACTIVITY_OBJECTS = {
|
|
3293
|
+
call: "calls",
|
|
3294
|
+
email: "emails",
|
|
3295
|
+
meeting: "meetings",
|
|
3296
|
+
task: "tasks"
|
|
3297
|
+
};
|
|
3298
|
+
/** The engagements of the type in the config. The label has the type and the ID. */
|
|
3299
|
+
const engagements = async (ctx) => {
|
|
3300
|
+
const type = text(ctx.config.type);
|
|
3301
|
+
const object = type ? ACTIVITY_OBJECTS[type] : void 0;
|
|
3302
|
+
if (!type || !object) return [];
|
|
3303
|
+
const answer = await send(ctx, {
|
|
3304
|
+
method: "GET",
|
|
3305
|
+
path: `/crm/v3/objects/${object}`,
|
|
3306
|
+
query: {
|
|
3307
|
+
limit: PAGE,
|
|
3308
|
+
after: ctx.cursor
|
|
3309
|
+
}
|
|
3310
|
+
});
|
|
3311
|
+
const options = [];
|
|
3312
|
+
for (const item of arr(rec(answer).results)) {
|
|
3313
|
+
const id = text(rec(item).id);
|
|
3314
|
+
if (id) options.push({
|
|
3315
|
+
label: `${type}: ${id}`,
|
|
3316
|
+
value: id
|
|
3317
|
+
});
|
|
3318
|
+
}
|
|
3319
|
+
return {
|
|
3320
|
+
options,
|
|
3321
|
+
nextCursor: nextOf(answer)
|
|
3322
|
+
};
|
|
3323
|
+
};
|
|
3324
|
+
/** The static lists of contacts. Lists search of the CRM API. */
|
|
3325
|
+
const contactLists = async (ctx) => {
|
|
3326
|
+
const offset = Number(ctx.cursor);
|
|
3327
|
+
const answer = rec(await send(ctx, {
|
|
3328
|
+
method: "POST",
|
|
3329
|
+
path: "/crm/v3/lists/search",
|
|
3330
|
+
body: {
|
|
3331
|
+
query: ctx.search?.trim() ?? "",
|
|
3332
|
+
processingTypes: ["MANUAL"],
|
|
3333
|
+
objectTypeId: "0-1",
|
|
3334
|
+
count: PAGE,
|
|
3335
|
+
...ctx.cursor && Number.isFinite(offset) ? { offset } : {}
|
|
3336
|
+
}
|
|
3337
|
+
}));
|
|
3338
|
+
const options = [];
|
|
3339
|
+
for (const item of arr(answer.lists ?? answer.results)) {
|
|
3340
|
+
const list = rec(item);
|
|
3341
|
+
const id = text(list.listId);
|
|
3342
|
+
if (!id) continue;
|
|
3343
|
+
options.push({
|
|
3344
|
+
label: text(list.name) ?? id,
|
|
3345
|
+
value: /^\d+$/.test(id) ? Number(id) : id
|
|
3346
|
+
});
|
|
3347
|
+
}
|
|
3348
|
+
return {
|
|
3349
|
+
options,
|
|
3350
|
+
nextCursor: answer.hasMore === true && text(answer.offset) ? text(answer.offset) ?? null : nextOf(answer)
|
|
3351
|
+
};
|
|
3352
|
+
};
|
|
3353
|
+
/** The properties of an object. The label is the label of the property, the value its name. */
|
|
3354
|
+
function propertyLoader(object) {
|
|
3355
|
+
return (async (ctx) => {
|
|
3356
|
+
const name = typeof object === "function" ? object(ctx) : object;
|
|
3357
|
+
const answer = await send(ctx, {
|
|
3358
|
+
method: "GET",
|
|
3359
|
+
path: `/crm/v3/properties/${name}`,
|
|
3360
|
+
query: {
|
|
3361
|
+
limit: PAGE,
|
|
3362
|
+
after: ctx.cursor
|
|
3363
|
+
}
|
|
3364
|
+
});
|
|
3365
|
+
const options = [];
|
|
3366
|
+
for (const item of arr(rec(answer).results)) {
|
|
3367
|
+
const property = rec(item);
|
|
3368
|
+
const id = text(property.name);
|
|
3369
|
+
if (id) options.push({
|
|
3370
|
+
label: text(property.label) ?? id,
|
|
3371
|
+
value: id
|
|
3372
|
+
});
|
|
3373
|
+
}
|
|
3374
|
+
options.sort(byLabel);
|
|
3375
|
+
return {
|
|
3376
|
+
options,
|
|
3377
|
+
nextCursor: nextOf(answer)
|
|
3378
|
+
};
|
|
3379
|
+
});
|
|
3380
|
+
}
|
|
3381
|
+
/** The options of one property, such as the lifecycle stages of a contact. */
|
|
3382
|
+
function optionsOfProperty(object, property) {
|
|
3383
|
+
return async (ctx) => {
|
|
3384
|
+
const answer = await send(ctx, {
|
|
3385
|
+
method: "GET",
|
|
3386
|
+
path: `/crm/v3/properties/${object}/${encodeURIComponent(property)}`
|
|
3387
|
+
});
|
|
3388
|
+
const options = [];
|
|
3389
|
+
for (const item of arr(rec(answer).options)) {
|
|
3390
|
+
const option = rec(item);
|
|
3391
|
+
const value = text(option.value);
|
|
3392
|
+
if (value !== void 0) options.push({
|
|
3393
|
+
label: text(option.label) ?? value,
|
|
3394
|
+
value
|
|
3395
|
+
});
|
|
3396
|
+
}
|
|
3397
|
+
return options;
|
|
3398
|
+
};
|
|
3399
|
+
}
|
|
3400
|
+
const pipelines = (object) => async (ctx) => {
|
|
3401
|
+
const answer = await send(ctx, {
|
|
3402
|
+
method: "GET",
|
|
3403
|
+
path: `/crm/v3/pipelines/${object}`
|
|
3404
|
+
});
|
|
3405
|
+
return arr(rec(answer).results).map(rec);
|
|
3406
|
+
};
|
|
3407
|
+
/** The deal stages of all pipelines. The label is `Pipeline > Stage`. */
|
|
3408
|
+
const dealStages = async (ctx) => {
|
|
3409
|
+
const options = [];
|
|
3410
|
+
for (const pipeline of await pipelines("deals")(ctx)) for (const item of arr(pipeline.stages)) {
|
|
3411
|
+
const stage = rec(item);
|
|
3412
|
+
const id = text(stage.id);
|
|
3413
|
+
if (id) options.push({
|
|
3414
|
+
label: `${text(pipeline.label) ?? text(pipeline.id)} > ${text(stage.label) ?? id}`,
|
|
3415
|
+
value: id
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3418
|
+
return options;
|
|
3419
|
+
};
|
|
3420
|
+
const pipelineOptions = (object) => async (ctx) => {
|
|
3421
|
+
const options = [];
|
|
3422
|
+
for (const pipeline of await pipelines(object)(ctx)) {
|
|
3423
|
+
const id = text(pipeline.id);
|
|
3424
|
+
if (id) options.push({
|
|
3425
|
+
label: text(pipeline.label) ?? id,
|
|
3426
|
+
value: id
|
|
3427
|
+
});
|
|
3428
|
+
}
|
|
3429
|
+
return options;
|
|
3430
|
+
};
|
|
3431
|
+
/** The stages of the ticket pipeline that the config names (on create or on update). */
|
|
3432
|
+
const ticketStages = async (ctx) => {
|
|
3433
|
+
const pipelineId = text(siblingOf(ctx, "pipelineId"));
|
|
3434
|
+
if (!pipelineId) return [];
|
|
3435
|
+
const options = [];
|
|
3436
|
+
for (const pipeline of await pipelines("tickets")(ctx)) {
|
|
3437
|
+
if (text(pipeline.id) !== pipelineId) continue;
|
|
3438
|
+
for (const item of arr(pipeline.stages)) {
|
|
3439
|
+
const stage = rec(item);
|
|
3440
|
+
const id = text(stage.id);
|
|
3441
|
+
if (id) options.push({
|
|
3442
|
+
label: text(stage.label) ?? id,
|
|
3443
|
+
value: id
|
|
3444
|
+
});
|
|
3445
|
+
}
|
|
3446
|
+
}
|
|
3447
|
+
return options;
|
|
3448
|
+
};
|
|
3449
|
+
const CONVERSATION_PROPERTIES = [
|
|
3450
|
+
{
|
|
3451
|
+
label: "Assigned To",
|
|
3452
|
+
value: "assignedTo"
|
|
3453
|
+
},
|
|
3454
|
+
{
|
|
3455
|
+
label: "Is Archived",
|
|
3456
|
+
value: "isArchived"
|
|
3457
|
+
},
|
|
3458
|
+
{
|
|
3459
|
+
label: "Status",
|
|
3460
|
+
value: "status"
|
|
3461
|
+
}
|
|
3462
|
+
];
|
|
3463
|
+
/**
|
|
3464
|
+
* The property names for one row of the events of the trigger. The event name in the same row
|
|
3465
|
+
* says the object. A conversation has three fixed properties.
|
|
3466
|
+
*/
|
|
3467
|
+
const eventProperties = (ctx) => {
|
|
3468
|
+
const name = text(siblingOf(ctx, "name"));
|
|
3469
|
+
const object = name?.split(".")[0];
|
|
3470
|
+
if (object === "conversation") return CONVERSATION_PROPERTIES;
|
|
3471
|
+
const found = object ? {
|
|
3472
|
+
contact: "contacts",
|
|
3473
|
+
company: "companies",
|
|
3474
|
+
deal: "deals",
|
|
3475
|
+
ticket: "tickets"
|
|
3476
|
+
}[object] : void 0;
|
|
3477
|
+
if (!name?.endsWith(".propertyChange") || !found) return [];
|
|
3478
|
+
return propertyLoader(found)(ctx);
|
|
3479
|
+
};
|
|
3480
|
+
/** The loaders of the HubSpot trigger. */
|
|
3481
|
+
const hubspotTriggerLoaders = { eventProperties };
|
|
3482
|
+
/** The loaders of the HubSpot node. */
|
|
3483
|
+
const hubspotLoaders = {
|
|
3484
|
+
owners,
|
|
3485
|
+
companies,
|
|
3486
|
+
contacts,
|
|
3487
|
+
deals,
|
|
3488
|
+
tickets,
|
|
3489
|
+
engagements,
|
|
3490
|
+
contactLists,
|
|
3491
|
+
contactProperties: propertyLoader("contacts"),
|
|
3492
|
+
companyProperties: propertyLoader("companies"),
|
|
3493
|
+
dealProperties: propertyLoader("deals"),
|
|
3494
|
+
ticketProperties: propertyLoader("tickets"),
|
|
3495
|
+
searchProperties: propertyLoader((ctx) => ctx.config.resource === "deal" ? "deals" : "contacts"),
|
|
3496
|
+
contactLeadStatuses: optionsOfProperty("contacts", "hs_lead_status"),
|
|
3497
|
+
contactLegalBasis: optionsOfProperty("contacts", "hs_legal_basis"),
|
|
3498
|
+
contactLifecycleStages: optionsOfProperty("contacts", "lifecyclestage"),
|
|
3499
|
+
contactOriginalSources: optionsOfProperty("contacts", "hs_analytics_source"),
|
|
3500
|
+
contactLanguages: optionsOfProperty("contacts", "hs_language"),
|
|
3501
|
+
contactStatuses: optionsOfProperty("contacts", "hs_content_membership_status"),
|
|
3502
|
+
contactEmployees: optionsOfProperty("contacts", "numemployees"),
|
|
3503
|
+
companyIndustries: optionsOfProperty("companies", "industry"),
|
|
3504
|
+
companyLeadStatuses: optionsOfProperty("companies", "hs_lead_status"),
|
|
3505
|
+
companyLifecycleStages: optionsOfProperty("companies", "lifecyclestage"),
|
|
3506
|
+
companyTypes: optionsOfProperty("companies", "type"),
|
|
3507
|
+
companyTargetAccounts: optionsOfProperty("companies", "hs_target_account"),
|
|
3508
|
+
companySourceTypes: optionsOfProperty("companies", "hs_analytics_source"),
|
|
3509
|
+
companyWebTechnologies: optionsOfProperty("companies", "web_technologies"),
|
|
3510
|
+
dealTypes: optionsOfProperty("deals", "dealtype"),
|
|
3511
|
+
dealStages,
|
|
3512
|
+
dealPipelines: pipelineOptions("deals"),
|
|
3513
|
+
ticketCategories: optionsOfProperty("tickets", "hs_ticket_category"),
|
|
3514
|
+
ticketPriorities: optionsOfProperty("tickets", "hs_ticket_priority"),
|
|
3515
|
+
ticketResolutions: optionsOfProperty("tickets", "hs_resolution"),
|
|
3516
|
+
ticketSources: optionsOfProperty("tickets", "source_type"),
|
|
3517
|
+
ticketPipelines: pipelineOptions("tickets"),
|
|
3518
|
+
ticketStages
|
|
3519
|
+
};
|
|
3048
3520
|
// src/request.ts
|
|
3049
3521
|
/** The object type IDs of the CRM. The associations API takes them. */
|
|
3050
3522
|
const OBJECT_TYPE_ID = {
|
|
@@ -3777,6 +4249,7 @@ var node_default = (0, _zerodot_node_sdk.defineNode)({
|
|
|
3777
4249
|
icon: "UserGroupIcon",
|
|
3778
4250
|
iconUrl: HUBSPOT_ICON,
|
|
3779
4251
|
config: hubspotConfig,
|
|
4252
|
+
loadOptions: hubspotLoaders,
|
|
3780
4253
|
defaultConfig: {
|
|
3781
4254
|
authentication: "appToken",
|
|
3782
4255
|
resource: "contact",
|
|
@@ -3968,6 +4441,8 @@ const eventItem = zod.z.object({
|
|
|
3968
4441
|
}
|
|
3969
4442
|
}),
|
|
3970
4443
|
property: zod.z.string().optional().meta({
|
|
4444
|
+
loadOptions: "eventProperties",
|
|
4445
|
+
dependsOn: [".name"],
|
|
3971
4446
|
title: "Property Name",
|
|
3972
4447
|
description: "The internal name of the property. Needed for the events that end with Property Changed. For a conversation use assignedTo, isArchived, or status"
|
|
3973
4448
|
})
|
|
@@ -3977,7 +4452,7 @@ const triggerConfig = zod.z.object({
|
|
|
3977
4452
|
additionalFields: zod.z.object({ maxConcurrentRequests: zod.z.number().int().min(5).meta({
|
|
3978
4453
|
title: "Max Concurrent Requests",
|
|
3979
4454
|
description: "The most requests that HubSpot sends at the same time. At least 5"
|
|
3980
|
-
}) }).partial().default({})
|
|
4455
|
+
}) }).partial().default({}).meta({ ui: "collection" })
|
|
3981
4456
|
});
|
|
3982
4457
|
/** The value of a header. The name can be in any case. */
|
|
3983
4458
|
function headerOf(headers, name) {
|
|
@@ -4087,6 +4562,7 @@ const nodes = [(0, _zerodot_node_sdk.defineNode)({
|
|
|
4087
4562
|
icon: "UserGroupIcon",
|
|
4088
4563
|
iconUrl: HUBSPOT_ICON,
|
|
4089
4564
|
config: triggerConfig,
|
|
4565
|
+
loadOptions: hubspotTriggerLoaders,
|
|
4090
4566
|
defaultConfig: {
|
|
4091
4567
|
events: [{ name: "contact.creation" }],
|
|
4092
4568
|
additionalFields: {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodot/hubspot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Manage HubSpot contacts, companies, deals, tickets, engagements, and contact lists, and start a workflow when a HubSpot app webhook event happens. Use it for CRM sync and sales automation.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"hubspot.svg"
|
|
22
22
|
],
|
|
23
23
|
"zerodot": {
|
|
24
|
-
"sdk": "^1.
|
|
24
|
+
"sdk": "^1.7",
|
|
25
25
|
"label": "HubSpot",
|
|
26
26
|
"summary": "Contacts, companies, deals, tickets, engagements, lists, and app webhook events"
|
|
27
27
|
},
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@zerodot/node-sdk": "^1.
|
|
33
|
+
"@zerodot/node-sdk": "^1.7.0",
|
|
34
34
|
"zod": "^4.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "26.6.5",
|
|
38
|
-
"@zerodot/node-sdk": "^1.
|
|
38
|
+
"@zerodot/node-sdk": "^1.7.0",
|
|
39
39
|
"tsdown": "0.23.2",
|
|
40
40
|
"tsx": "4.23.15",
|
|
41
41
|
"typescript": "7.0.2",
|