@dma-sdk/hubspot 1.0.17 → 1.0.19

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.
@@ -1,3 +1,4 @@
1
1
  export declare const HsSubscriptionTypes: {
2
2
  ticketPropChange: string;
3
+ dealCreation: string;
3
4
  };
@@ -5,4 +5,5 @@ const events_1 = require("./events");
5
5
  const objects_1 = require("./objects");
6
6
  exports.HsSubscriptionTypes = {
7
7
  ticketPropChange: `${objects_1.HsObjectTypes.ticket}.${events_1.HsEventTypes.propertyChange}`,
8
+ dealCreation: `${objects_1.HsObjectTypes.deal}.${events_1.HsEventTypes.creation}`,
8
9
  };
@@ -0,0 +1,3 @@
1
+ export declare class SystemError extends Error {
2
+ constructor(message: string);
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SystemError = void 0;
4
+ class SystemError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "SystemError";
8
+ }
9
+ }
10
+ exports.SystemError = SystemError;
@@ -9,7 +9,7 @@ import { CollectionResponsePropertyNoPaging, PropertyCreate, PropertyGroup, Prop
9
9
  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
- import { PublicObjectSearchRequest } from '@hubspot/api-client/lib/codegen/crm/companies';
12
+ import { PublicObjectSearchRequest, SimplePublicObjectWithAssociations } from '@hubspot/api-client/lib/codegen/crm/companies';
13
13
  import { AssociateObjectInput } from '../interfaces/input/associations';
14
14
  export declare class HubspotService {
15
15
  static HS_BASE_URL: string;
@@ -68,9 +68,19 @@ export declare class HubspotService {
68
68
  createObject(objectType: string, properties: SimplePublicObjectInputForCreate, accessToken: string): Promise<SimplePublicObject | {
69
69
  id: string;
70
70
  }>;
71
- getObject(objectType: string, objectId: string, accessToken: string): Promise<SimplePublicObject>;
72
- getObjectProps(objectType: string, objectId: string, props: string[], // nome delle props da restituire
73
- accessToken: string): Promise<SimplePublicObject>;
71
+ getObjectById(params: {
72
+ objectType: string;
73
+ objectId: string;
74
+ accessToken: string;
75
+ }): Promise<SimplePublicObject>;
76
+ getObject(params: {
77
+ objectType: string;
78
+ objectId: string;
79
+ associations?: string[];
80
+ props?: string[];
81
+ propsWithHistory?: string[];
82
+ accessToken: string;
83
+ }): Promise<SimplePublicObjectWithAssociations>;
74
84
  getObjectWithPropsType(objectType: string, objectId: string, accessToken: string, types?: string[]): Promise<SimplePublicObject & {
75
85
  propertiesWithTypes: {
76
86
  [key: string]: {
@@ -95,5 +105,6 @@ export declare class HubspotService {
95
105
  commandInput: CreateSubscriptionInput;
96
106
  devApiKey: string;
97
107
  }): Promise<CreateSubscriptionOutput>;
108
+ setAccessToken(accessToken: string): void;
98
109
  private fetchApi;
99
110
  }
@@ -7,6 +7,7 @@ const data_1 = require("../constants/data");
7
7
  const api_client_2 = require("@hubspot/api-client");
8
8
  const utils_1 = require("@dma-sdk/utils");
9
9
  const api_1 = require("../constants/api");
10
+ const system_error_1 = require("../exceptions/system-error");
10
11
  // Per ogni metodo che viene creato, è fondamentale che
11
12
  // il client venga inizializzato con il token di accesso o l'api key
12
13
  // altrimenti non funzionerà correttamente.
@@ -82,19 +83,25 @@ class HubspotService {
82
83
  const response = await this.client.crm.objects.basicApi.create(objectType, properties);
83
84
  return response;
84
85
  }
85
- async getObject(objectType, objectId, accessToken) {
86
+ async getObjectById(params) {
87
+ const { objectType, objectId, accessToken } = params;
86
88
  this.client.setAccessToken(accessToken);
87
89
  return await this.client.crm.objects.basicApi.getById(objectType, objectId);
88
90
  }
89
- async getObjectProps(objectType, objectId, props, // nome delle props da restituire
90
- accessToken) {
91
+ async getObject(params) {
92
+ const { objectType, objectId, associations, props, propsWithHistory, accessToken } = params;
91
93
  this.client.setAccessToken(accessToken);
92
- return await this.client.crm.objects.basicApi.getById(objectType, objectId, props);
94
+ return await this.client.crm.objects.basicApi.getById(objectType, objectId, props, propsWithHistory, associations);
93
95
  }
94
96
  async getObjectWithPropsType(objectType, objectId, accessToken, types) {
95
97
  this.client.setAccessToken(accessToken);
96
98
  const props = await this.listObjectProperties({ objectType, types });
97
- const data = await this.getObjectProps(objectType, objectId, props.results.map((prop) => prop.name), accessToken);
99
+ const data = await this.getObject({
100
+ objectType,
101
+ objectId,
102
+ props: props.results.map((prop) => prop.name),
103
+ accessToken
104
+ });
98
105
  let formattedProp = {};
99
106
  props.results.forEach((property) => {
100
107
  if (!data.properties[property.name]) {
@@ -175,6 +182,12 @@ class HubspotService {
175
182
  const response = await this.fetchApi(api_1.ApiMethods.subscriptions(appId), options, { hapikey: devApiKey });
176
183
  return await response.json();
177
184
  }
185
+ setAccessToken(accessToken) {
186
+ if (this.client === undefined) {
187
+ throw new system_error_1.SystemError('Hubspot client not initialized');
188
+ }
189
+ this.client.setAccessToken(accessToken);
190
+ }
178
191
  async fetchApi(endpoint, options, queryParams) {
179
192
  return await (0, utils_1.fetchApi)(HubspotService.HS_BASE_URL, endpoint, options, queryParams);
180
193
  }
@@ -3,4 +3,5 @@ import { HsObjectTypes } from "./objects";
3
3
 
4
4
  export const HsSubscriptionTypes = {
5
5
  ticketPropChange: `${HsObjectTypes.ticket}.${HsEventTypes.propertyChange}`,
6
+ dealCreation: `${HsObjectTypes.deal}.${HsEventTypes.creation}`,
6
7
  };
@@ -0,0 +1,6 @@
1
+ export class SystemError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = "SystemError";
5
+ }
6
+ }
@@ -16,8 +16,9 @@ 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 } from '@hubspot/api-client/lib/codegen/crm/companies'
19
+ import { AssociationSpec, FilterGroup, PublicObjectSearchRequest, SimplePublicObjectWithAssociations } from '@hubspot/api-client/lib/codegen/crm/companies'
20
20
  import { AssociateObjectInput } from '../interfaces/input/associations'
21
+ import { SystemError } from '../exceptions/system-error'
21
22
 
22
23
  // Per ogni metodo che viene creato, è fondamentale che
23
24
  // il client venga inizializzato con il token di accesso o l'api key
@@ -147,11 +148,12 @@ export class HubspotService {
147
148
  return response
148
149
  }
149
150
 
150
- async getObject(
151
+ async getObjectById(params: {
151
152
  objectType: string,
152
- objectId: string,
153
+ objectId: string,
153
154
  accessToken: string
154
- ): Promise<SimplePublicObject> {
155
+ }): Promise<SimplePublicObject> {
156
+ const { objectType, objectId, accessToken } = params
155
157
  this.client.setAccessToken(accessToken)
156
158
  return await this.client.crm.objects.basicApi.getById(
157
159
  objectType,
@@ -159,17 +161,22 @@ export class HubspotService {
159
161
  );
160
162
  }
161
163
 
162
- async getObjectProps(
164
+ async getObject(params: {
163
165
  objectType: string,
164
166
  objectId: string,
165
- props: string[], // nome delle props da restituire
167
+ associations?: string[],
168
+ props?: string[], // nome delle props da restituire
169
+ propsWithHistory?: string[], // nome delle props da restituire
166
170
  accessToken: string
167
- ): Promise<SimplePublicObject> {
171
+ }): Promise<SimplePublicObjectWithAssociations> {
172
+ const { objectType, objectId, associations, props, propsWithHistory, accessToken } = params
168
173
  this.client.setAccessToken(accessToken)
169
174
  return await this.client.crm.objects.basicApi.getById(
170
175
  objectType,
171
176
  objectId,
172
- props
177
+ props,
178
+ propsWithHistory,
179
+ associations
173
180
  );
174
181
  }
175
182
 
@@ -181,12 +188,12 @@ export class HubspotService {
181
188
  ): Promise<SimplePublicObject & { propertiesWithTypes: { [key: string]: { type: string, label: string, value: string | null } }}> {
182
189
  this.client.setAccessToken(accessToken)
183
190
  const props = await this.listObjectProperties({ objectType, types })
184
- const data = await this.getObjectProps(
191
+ const data = await this.getObject({
185
192
  objectType,
186
193
  objectId,
187
- props.results.map((prop) => prop.name),
194
+ props: props.results.map((prop) => prop.name),
188
195
  accessToken
189
- );
196
+ });
190
197
 
191
198
 
192
199
  let formattedProp: { [key: string]: { type: string, label: string, value: string | null } } = {}
@@ -316,6 +323,13 @@ export class HubspotService {
316
323
 
317
324
  return await response.json()
318
325
  }
326
+
327
+ setAccessToken(accessToken: string) {
328
+ if(this.client === undefined) {
329
+ throw new SystemError('Hubspot client not initialized')
330
+ }
331
+ this.client.setAccessToken(accessToken)
332
+ }
319
333
 
320
334
  private async fetchApi(endpoint: string, options: {}, queryParams?: {}): Promise<any> {
321
335
  return await fetchApi(HubspotService.HS_BASE_URL, endpoint, options, queryParams)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dma-sdk/hubspot",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "DMA SDK – Hubspot service",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",