@dma-sdk/hubspot 1.0.19 → 1.0.21

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.
@@ -3,4 +3,5 @@ export declare const ApiMethods: {
3
3
  refreshToken: string;
4
4
  createObjectProperties: (objectType: string) => string;
5
5
  subscriptions: (appId: string) => string;
6
+ associateObjectBatch: (fromObjectType: string, toObjectType: string) => string;
6
7
  };
@@ -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) => '/crm/v3/properties/{objectType}/batch/create'.replace('{objectType}', objectType),
8
- subscriptions: (appId) => '/webhooks/v3/{appId}/subscriptions'.replace('{appId}', 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<{
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,30 @@ 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(error instanceof Error ? error.message : String(error));
156
+ }
157
+ }
158
+ return { errors };
159
+ }
136
160
  async createObjectProperties(objectType, properties, accessToken) {
137
161
  const options = {
138
162
  method: 'POST',
@@ -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) => '/crm/v3/properties/{objectType}/batch/create'.replace('{objectType}', objectType),
5
- subscriptions: (appId: string) => '/webhooks/v3/{appId}/subscriptions'.replace('{appId}', appId),
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 { AssociationSpec, FilterGroup, PublicObjectSearchRequest, SimplePublicObjectWithAssociations } from '@hubspot/api-client/lib/codegen/crm/companies'
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,40 @@ export class HubspotService {
251
251
  return response
252
252
  }
253
253
 
254
+ async associateObjectsBatch(
255
+ commandInput: BatchAssociateObjectInput,
256
+ accessToken: string
257
+ ): Promise<{ errors: string[] }> {
258
+ const errors = []
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(error instanceof Error ? error.message : String(error))
282
+ }
283
+ }
284
+
285
+ return { errors }
286
+ }
287
+
254
288
  async createObjectProperties(
255
289
  objectType: string,
256
290
  properties: PropertyCreate[],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dma-sdk/hubspot",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "DMA SDK – Hubspot service",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",