@dma-sdk/hubspot 1.0.18 → 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.
- package/dist/exceptions/system-error.d.ts +3 -0
- package/dist/exceptions/system-error.js +10 -0
- package/dist/services/hubspot-service.d.ts +3 -2
- package/dist/services/hubspot-service.js +7 -0
- package/lib/exceptions/system-error.ts +6 -0
- package/lib/services/hubspot-service.ts +10 -2
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -80,7 +80,7 @@ export declare class HubspotService {
|
|
|
80
80
|
props?: string[];
|
|
81
81
|
propsWithHistory?: string[];
|
|
82
82
|
accessToken: string;
|
|
83
|
-
}): Promise<
|
|
83
|
+
}): Promise<SimplePublicObjectWithAssociations>;
|
|
84
84
|
getObjectWithPropsType(objectType: string, objectId: string, accessToken: string, types?: string[]): Promise<SimplePublicObject & {
|
|
85
85
|
propertiesWithTypes: {
|
|
86
86
|
[key: string]: {
|
|
@@ -105,5 +105,6 @@ export declare class HubspotService {
|
|
|
105
105
|
commandInput: CreateSubscriptionInput;
|
|
106
106
|
devApiKey: string;
|
|
107
107
|
}): Promise<CreateSubscriptionOutput>;
|
|
108
|
+
setAccessToken(accessToken: string): void;
|
|
108
109
|
private fetchApi;
|
|
109
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.
|
|
@@ -181,6 +182,12 @@ class HubspotService {
|
|
|
181
182
|
const response = await this.fetchApi(api_1.ApiMethods.subscriptions(appId), options, { hapikey: devApiKey });
|
|
182
183
|
return await response.json();
|
|
183
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
|
+
}
|
|
184
191
|
async fetchApi(endpoint, options, queryParams) {
|
|
185
192
|
return await (0, utils_1.fetchApi)(HubspotService.HS_BASE_URL, endpoint, options, queryParams);
|
|
186
193
|
}
|
|
@@ -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
|
|
@@ -167,7 +168,7 @@ export class HubspotService {
|
|
|
167
168
|
props?: string[], // nome delle props da restituire
|
|
168
169
|
propsWithHistory?: string[], // nome delle props da restituire
|
|
169
170
|
accessToken: string
|
|
170
|
-
}): Promise<
|
|
171
|
+
}): Promise<SimplePublicObjectWithAssociations> {
|
|
171
172
|
const { objectType, objectId, associations, props, propsWithHistory, accessToken } = params
|
|
172
173
|
this.client.setAccessToken(accessToken)
|
|
173
174
|
return await this.client.crm.objects.basicApi.getById(
|
|
@@ -322,6 +323,13 @@ export class HubspotService {
|
|
|
322
323
|
|
|
323
324
|
return await response.json()
|
|
324
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
|
+
}
|
|
325
333
|
|
|
326
334
|
private async fetchApi(endpoint: string, options: {}, queryParams?: {}): Promise<any> {
|
|
327
335
|
return await fetchApi(HubspotService.HS_BASE_URL, endpoint, options, queryParams)
|