@dma-sdk/hubspot 1.0.19 → 1.0.20
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/dist/constants/api.d.ts +1 -0
- package/dist/constants/api.js +3 -2
- package/dist/interfaces/input/associations.d.ts +14 -0
- package/dist/services/hubspot-service.d.ts +4 -1
- package/dist/services/hubspot-service.js +26 -0
- package/lib/constants/api.ts +4 -3
- package/lib/interfaces/input/associations.ts +17 -0
- package/lib/services/hubspot-service.ts +38 -2
- package/package.json +1 -1
package/dist/constants/api.d.ts
CHANGED
package/dist/constants/api.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.ApiMethods = void 0;
|
|
|
4
4
|
exports.ApiMethods = {
|
|
5
5
|
getUserInfoByToken: '/oauth/v1/access-tokens',
|
|
6
6
|
refreshToken: '/oauth/v1/token',
|
|
7
|
-
createObjectProperties: (objectType) =>
|
|
8
|
-
subscriptions: (appId) =>
|
|
7
|
+
createObjectProperties: (objectType) => `/crm/v3/properties/${objectType}/batch/create`,
|
|
8
|
+
subscriptions: (appId) => `/webhooks/v3/${appId}/subscriptions`,
|
|
9
|
+
associateObjectBatch: (fromObjectType, toObjectType) => `/crm/v4/associations/${fromObjectType}/${toObjectType}/batch/create`
|
|
9
10
|
};
|
|
@@ -6,3 +6,17 @@ export interface AssociateObjectInput {
|
|
|
6
6
|
objectIdSecond: string;
|
|
7
7
|
options?: AssociationSpec[];
|
|
8
8
|
}
|
|
9
|
+
export interface BatchAssociateObjectInput {
|
|
10
|
+
objectTypeFirst: string;
|
|
11
|
+
objectTypeSecond: string;
|
|
12
|
+
associations: AssociationsObject[];
|
|
13
|
+
}
|
|
14
|
+
export interface AssociationsObject {
|
|
15
|
+
from: {
|
|
16
|
+
id: string;
|
|
17
|
+
};
|
|
18
|
+
to: {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
types: Array<AssociationSpec>;
|
|
22
|
+
}
|
|
@@ -10,7 +10,7 @@ import { HubspotSignatureData } from '../types/auth/hs-signature-data';
|
|
|
10
10
|
import { CreateSubscriptionInput } from '../interfaces/input/subscriptions';
|
|
11
11
|
import { CreateSubscriptionOutput } from '../interfaces/output/subscriptions';
|
|
12
12
|
import { PublicObjectSearchRequest, SimplePublicObjectWithAssociations } from '@hubspot/api-client/lib/codegen/crm/companies';
|
|
13
|
-
import { AssociateObjectInput } from '../interfaces/input/associations';
|
|
13
|
+
import { AssociateObjectInput, BatchAssociateObjectInput } from '../interfaces/input/associations';
|
|
14
14
|
export declare class HubspotService {
|
|
15
15
|
static HS_BASE_URL: string;
|
|
16
16
|
static readonly hubspotObjectType: {
|
|
@@ -94,6 +94,9 @@ export declare class HubspotService {
|
|
|
94
94
|
[key: string]: string;
|
|
95
95
|
}, accessToken: string, options?: Configuration): Promise<SimplePublicObject>;
|
|
96
96
|
associateObjects(commandInput: AssociateObjectInput, accessToken: string): Promise<LabelsBetweenObjectPair>;
|
|
97
|
+
associateObjectsBatch(commandInput: BatchAssociateObjectInput, accessToken: string): Promise<Array<{
|
|
98
|
+
errors: string;
|
|
99
|
+
}>>;
|
|
97
100
|
createObjectProperties(objectType: string, properties: PropertyCreate[], accessToken: string): Promise<any>;
|
|
98
101
|
createPropertyGroup(objectType: string, group: PropertyGroupCreate, accessToken: string): Promise<PropertyGroup>;
|
|
99
102
|
convertPropertyValues(properties: {
|
|
@@ -133,6 +133,32 @@ class HubspotService {
|
|
|
133
133
|
const response = await this.client.crm.associations.v4.basicApi.create(objectTypeFirst, objectIdFirst, objectTypeSecond, objectIdSecond, options || []);
|
|
134
134
|
return response;
|
|
135
135
|
}
|
|
136
|
+
async associateObjectsBatch(commandInput, accessToken) {
|
|
137
|
+
const errors = [];
|
|
138
|
+
const chunkSize = 20;
|
|
139
|
+
for (let i = 0; i < commandInput.associations.length; i += chunkSize) {
|
|
140
|
+
const associationChunk = commandInput.associations.slice(i, i + chunkSize);
|
|
141
|
+
const options = {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
headers: {
|
|
144
|
+
Authorization: `Bearer ${accessToken}`,
|
|
145
|
+
'Content-Type': 'application/json'
|
|
146
|
+
},
|
|
147
|
+
body: JSON.stringify({
|
|
148
|
+
inputs: associationChunk
|
|
149
|
+
})
|
|
150
|
+
};
|
|
151
|
+
try {
|
|
152
|
+
await this.fetchApi(api_1.ApiMethods.associateObjectBatch(commandInput.objectTypeFirst, commandInput.objectTypeSecond), options);
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
errors.push({
|
|
156
|
+
errors: error instanceof Error ? error.message : String(error)
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return errors;
|
|
161
|
+
}
|
|
136
162
|
async createObjectProperties(objectType, properties, accessToken) {
|
|
137
163
|
const options = {
|
|
138
164
|
method: 'POST',
|
package/lib/constants/api.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const ApiMethods = {
|
|
2
2
|
getUserInfoByToken: '/oauth/v1/access-tokens',
|
|
3
3
|
refreshToken: '/oauth/v1/token',
|
|
4
|
-
createObjectProperties: (objectType: string) =>
|
|
5
|
-
subscriptions: (appId: string) =>
|
|
6
|
-
}
|
|
4
|
+
createObjectProperties: (objectType: string) => `/crm/v3/properties/${objectType}/batch/create`,
|
|
5
|
+
subscriptions: (appId: string) => `/webhooks/v3/${appId}/subscriptions`,
|
|
6
|
+
associateObjectBatch: (fromObjectType: string, toObjectType: string) => `/crm/v4/associations/${fromObjectType}/${toObjectType}/batch/create`
|
|
7
|
+
}
|
|
@@ -6,4 +6,21 @@ export interface AssociateObjectInput {
|
|
|
6
6
|
objectIdFirst: string,
|
|
7
7
|
objectIdSecond: string,
|
|
8
8
|
options?: AssociationSpec[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BatchAssociateObjectInput {
|
|
12
|
+
objectTypeFirst: string,
|
|
13
|
+
objectTypeSecond: string,
|
|
14
|
+
associations: AssociationsObject[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export interface AssociationsObject {
|
|
19
|
+
from: {
|
|
20
|
+
id: string
|
|
21
|
+
},
|
|
22
|
+
to: {
|
|
23
|
+
id: string
|
|
24
|
+
},
|
|
25
|
+
types: Array<AssociationSpec>
|
|
9
26
|
}
|
|
@@ -16,8 +16,8 @@ import { fetchApi } from '@dma-sdk/utils'
|
|
|
16
16
|
import { ApiMethods } from '../constants/api'
|
|
17
17
|
import { CreateSubscriptionInput } from '../interfaces/input/subscriptions'
|
|
18
18
|
import { CreateSubscriptionOutput } from '../interfaces/output/subscriptions'
|
|
19
|
-
import {
|
|
20
|
-
import { AssociateObjectInput } from '../interfaces/input/associations'
|
|
19
|
+
import { PublicObjectSearchRequest, SimplePublicObjectWithAssociations } from '@hubspot/api-client/lib/codegen/crm/companies'
|
|
20
|
+
import { AssociateObjectInput, AssociationsObject, BatchAssociateObjectInput } from '../interfaces/input/associations'
|
|
21
21
|
import { SystemError } from '../exceptions/system-error'
|
|
22
22
|
|
|
23
23
|
// Per ogni metodo che viene creato, è fondamentale che
|
|
@@ -251,6 +251,42 @@ export class HubspotService {
|
|
|
251
251
|
return response
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
+
async associateObjectsBatch(
|
|
255
|
+
commandInput: BatchAssociateObjectInput,
|
|
256
|
+
accessToken: string
|
|
257
|
+
): Promise<Array<{ errors: string }>> {
|
|
258
|
+
const errors: Array<{ errors: string }> = []
|
|
259
|
+
const chunkSize = 20
|
|
260
|
+
|
|
261
|
+
for (let i = 0; i < commandInput.associations.length; i += chunkSize) {
|
|
262
|
+
const associationChunk = commandInput.associations.slice(i, i + chunkSize)
|
|
263
|
+
|
|
264
|
+
const options = {
|
|
265
|
+
method: 'POST',
|
|
266
|
+
headers: {
|
|
267
|
+
Authorization: `Bearer ${accessToken}`,
|
|
268
|
+
'Content-Type': 'application/json'
|
|
269
|
+
},
|
|
270
|
+
body: JSON.stringify({
|
|
271
|
+
inputs: associationChunk
|
|
272
|
+
})
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
await this.fetchApi(
|
|
277
|
+
ApiMethods.associateObjectBatch(commandInput.objectTypeFirst, commandInput.objectTypeSecond),
|
|
278
|
+
options
|
|
279
|
+
)
|
|
280
|
+
} catch (error) {
|
|
281
|
+
errors.push({
|
|
282
|
+
errors: error instanceof Error ? error.message : String(error)
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return errors
|
|
288
|
+
}
|
|
289
|
+
|
|
254
290
|
async createObjectProperties(
|
|
255
291
|
objectType: string,
|
|
256
292
|
properties: PropertyCreate[],
|