@dma-sdk/hubspot 1.0.9 → 1.0.11

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.
@@ -0,0 +1,3 @@
1
+ export declare const HsSubscriptionTypes: {
2
+ ticketPropChange: string;
3
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HsSubscriptionTypes = void 0;
4
+ const events_1 = require("./events");
5
+ const objects_1 = require("./objects");
6
+ exports.HsSubscriptionTypes = {
7
+ ticketPropChange: `${objects_1.HsObjectTypes.ticket}.${events_1.HsEventTypes.propertyChange}`,
8
+ };
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './services/hubspot-service';
2
2
  export * from './constants/data';
3
3
  export * from './constants/objects';
4
4
  export * from './constants/events';
5
+ export * from './constants/subscriptions';
5
6
  export * from './interfaces/input/subscriptions';
6
7
  export * from './interfaces/output/subscriptions';
7
8
  export * from './types/auth/hs-signature-data';
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ __exportStar(require("./services/hubspot-service"), exports);
18
18
  __exportStar(require("./constants/data"), exports);
19
19
  __exportStar(require("./constants/objects"), exports);
20
20
  __exportStar(require("./constants/events"), exports);
21
+ __exportStar(require("./constants/subscriptions"), exports);
21
22
  __exportStar(require("./interfaces/input/subscriptions"), exports);
22
23
  __exportStar(require("./interfaces/output/subscriptions"), exports);
23
24
  __exportStar(require("./types/auth/hs-signature-data"), exports);
@@ -1,5 +1,5 @@
1
1
  import { HubspotUser } from '../interfaces/user';
2
- import { Configuration, Filter } from '@hubspot/api-client/lib/codegen/crm/objects';
2
+ import { Configuration } from '@hubspot/api-client/lib/codegen/crm/objects';
3
3
  import { SimplePublicObjectInputForCreate } from '@hubspot/api-client/lib/codegen/crm/objects/taxes/models/all';
4
4
  import { SimplePublicObject } from '@hubspot/api-client/lib/codegen/crm/objects/tasks/models/all';
5
5
  import { LabelsBetweenObjectPair } from '@hubspot/api-client/lib/codegen/crm/associations/v4';
@@ -9,6 +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
13
  export declare class HubspotService {
13
14
  static HS_BASE_URL: string;
14
15
  static readonly hubspotObjectType: {
@@ -39,26 +40,30 @@ export declare class HubspotService {
39
40
  video: string;
40
41
  };
41
42
  private client;
42
- private hsRedirectUriOauth;
43
- private hsClientId;
44
43
  private hsClientSecret;
45
44
  private typeConvert;
46
- constructor(hsRedirectUriOauth: string, hsClientId: string, hsClientSecret: string);
45
+ constructor(hsClientSecret: string);
47
46
  exchangeCodeForTokens(params: {
48
47
  code: string;
48
+ redirectUriOauth: string;
49
+ clientId: string;
49
50
  }): Promise<TokenResponseIF>;
50
51
  getUserInfoByToken(accessToken: string): Promise<HubspotUser>;
51
52
  verifyFetchReqSignature(params: {
52
53
  version: string;
53
54
  data: HubspotSignatureData;
54
55
  }): Promise<boolean>;
55
- refreshAccessToken(refreshToken: string): Promise<TokenResponse>;
56
+ refreshAccessToken(params: {
57
+ refreshToken: string;
58
+ redirectUriOauth: string;
59
+ clientId: string;
60
+ }): Promise<TokenResponse>;
56
61
  listObjectProperties(params: {
57
62
  objectType: string;
58
63
  types?: string[];
59
64
  accessToken?: string;
60
65
  }): Promise<CollectionResponsePropertyNoPaging>;
61
- listObjects(objectType: string, filters: Filter[], accessToken: string): Promise<SimplePublicObject[] | null>;
66
+ listObjects(objectType: string, searchRequest: PublicObjectSearchRequest, accessToken: string): Promise<SimplePublicObject[] | null>;
62
67
  createObject(objectType: string, properties: SimplePublicObjectInputForCreate, accessToken: string): Promise<SimplePublicObject | {
63
68
  id: string;
64
69
  }>;
@@ -11,16 +11,14 @@ const api_1 = require("../constants/api");
11
11
  // il client venga inizializzato con il token di accesso o l'api key
12
12
  // altrimenti non funzionerà correttamente.
13
13
  class HubspotService {
14
- constructor(hsRedirectUriOauth, hsClientId, hsClientSecret) {
15
- ;
16
- (this.hsRedirectUriOauth = hsRedirectUriOauth),
17
- (this.hsClientId = hsClientId),
18
- (this.hsClientSecret = hsClientSecret);
14
+ constructor(hsClientSecret) {
15
+ this.hsClientSecret = hsClientSecret;
19
16
  this.typeConvert = type_converter_1.typeConverter;
20
17
  this.client = new api_client_1.Client();
21
18
  }
22
19
  async exchangeCodeForTokens(params) {
23
- return await this.client.oauth.tokensApi.create('authorization_code', params.code, this.hsRedirectUriOauth, this.hsClientId, this.hsClientSecret);
20
+ const { code, redirectUriOauth, clientId } = params;
21
+ return await this.client.oauth.tokensApi.create('authorization_code', code, redirectUriOauth, clientId, this.hsClientSecret);
24
22
  }
25
23
  async getUserInfoByToken(accessToken) {
26
24
  const response = await this.client.apiRequest({
@@ -55,8 +53,9 @@ class HubspotService {
55
53
  clientSecret: this.hsClientSecret,
56
54
  });
57
55
  }
58
- async refreshAccessToken(refreshToken) {
59
- const token = await this.client.oauth.tokensApi.create('refresh_token', undefined, this.hsRedirectUriOauth, this.hsClientId, this.hsClientSecret, refreshToken);
56
+ async refreshAccessToken(params) {
57
+ const { refreshToken, redirectUriOauth, clientId } = params;
58
+ const token = await this.client.oauth.tokensApi.create('refresh_token', undefined, redirectUriOauth, clientId, this.hsClientSecret, refreshToken);
60
59
  return {
61
60
  accessToken: token.accessToken,
62
61
  expiresIn: token.expiresIn,
@@ -73,15 +72,9 @@ class HubspotService {
73
72
  return props;
74
73
  return { results: props.results.filter((prop) => types.includes(prop.fieldType) || types.includes(prop.type)) };
75
74
  }
76
- async listObjects(objectType, filters, accessToken) {
75
+ async listObjects(objectType, searchRequest, accessToken) {
77
76
  this.client.setAccessToken(accessToken);
78
- const response = await this.client.crm.objects.searchApi.doSearch(objectType, {
79
- filterGroups: [
80
- {
81
- filters: filters,
82
- },
83
- ],
84
- });
77
+ const response = await this.client.crm.objects.searchApi.doSearch(objectType, searchRequest);
85
78
  return response.results || null;
86
79
  }
87
80
  async createObject(objectType, properties, accessToken) {
@@ -0,0 +1,6 @@
1
+ import { HsEventTypes } from "./events";
2
+ import { HsObjectTypes } from "./objects";
3
+
4
+ export const HsSubscriptionTypes = {
5
+ ticketPropChange: `${HsObjectTypes.ticket}.${HsEventTypes.propertyChange}`,
6
+ };
package/lib/index.ts CHANGED
@@ -2,6 +2,7 @@ export * from './services/hubspot-service';
2
2
  export * from './constants/data';
3
3
  export * from './constants/objects';
4
4
  export * from './constants/events';
5
+ export * from './constants/subscriptions';
5
6
  export * from './interfaces/input/subscriptions';
6
7
  export * from './interfaces/output/subscriptions';
7
8
  export * from './types/auth/hs-signature-data';
@@ -4,7 +4,7 @@ import { Configuration, Filter } from '@hubspot/api-client/lib/codegen/crm/objec
4
4
  import { SimplePublicObjectInputForCreate } from '@hubspot/api-client/lib/codegen/crm/objects/taxes/models/all'
5
5
  import { SimplePublicObject } from '@hubspot/api-client/lib/codegen/crm/objects/tasks/models/all'
6
6
  import { LabelsBetweenObjectPair } from '@hubspot/api-client/lib/codegen/crm/associations/v4'
7
- import { TokenResponseIF } from '@hubspot/api-client/lib/codegen/oauth'
7
+ import { PromiseConfigurationOptions, TokenResponseIF } from '@hubspot/api-client/lib/codegen/oauth'
8
8
  import { typeConverter } from '../utils/type-converter'
9
9
  import { HubspotTypeConverter } from '../interfaces/hubspot-type-converter'
10
10
  import { HsDataTypes } from '../constants/data'
@@ -16,6 +16,7 @@ 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 { FilterGroup, PublicObjectSearchRequest } from '@hubspot/api-client/lib/codegen/crm/companies'
19
20
 
20
21
  // Per ogni metodo che viene creato, è fondamentale che
21
22
  // il client venga inizializzato con il token di accesso o l'api key
@@ -30,27 +31,23 @@ export class HubspotService {
30
31
  public static readonly hubspotPropertyTypes = HsDataTypes
31
32
 
32
33
  private client: HubspotClient
33
- private hsRedirectUriOauth: string
34
- private hsClientId: string
35
34
  private hsClientSecret: string
36
35
  private typeConvert: HubspotTypeConverter
37
36
 
38
37
 
39
- constructor(hsRedirectUriOauth: string, hsClientId: string, hsClientSecret: string) {
40
- ;(this.hsRedirectUriOauth = hsRedirectUriOauth),
41
- (this.hsClientId = hsClientId),
42
- (this.hsClientSecret = hsClientSecret)
38
+ constructor(hsClientSecret: string) {
39
+ this.hsClientSecret = hsClientSecret
43
40
  this.typeConvert = typeConverter
44
-
45
41
  this.client = new HubspotClient()
46
42
  }
47
43
 
48
- async exchangeCodeForTokens(params: { code: string }): Promise<TokenResponseIF> {
44
+ async exchangeCodeForTokens(params: { code: string, redirectUriOauth: string, clientId: string }): Promise<TokenResponseIF> {
45
+ const { code, redirectUriOauth, clientId } = params
49
46
  return await this.client.oauth.tokensApi.create(
50
47
  'authorization_code',
51
- params.code,
52
- this.hsRedirectUriOauth,
53
- this.hsClientId,
48
+ code,
49
+ redirectUriOauth,
50
+ clientId,
54
51
  this.hsClientSecret
55
52
  )
56
53
  }
@@ -93,12 +90,14 @@ export class HubspotService {
93
90
  })
94
91
  }
95
92
 
96
- async refreshAccessToken(refreshToken: string): Promise<TokenResponse> {
93
+ async refreshAccessToken(params: { refreshToken: string, redirectUriOauth: string, clientId: string }): Promise<TokenResponse> {
94
+ const { refreshToken, redirectUriOauth, clientId } = params
95
+
97
96
  const token = await this.client.oauth.tokensApi.create(
98
97
  'refresh_token',
99
98
  undefined,
100
- this.hsRedirectUriOauth,
101
- this.hsClientId,
99
+ redirectUriOauth,
100
+ clientId,
102
101
  this.hsClientSecret,
103
102
  refreshToken
104
103
  )
@@ -128,18 +127,11 @@ export class HubspotService {
128
127
 
129
128
  async listObjects(
130
129
  objectType: string,
131
- filters: Filter[],
130
+ searchRequest: PublicObjectSearchRequest,
132
131
  accessToken: string
133
132
  ): Promise<SimplePublicObject[] | null> {
134
133
  this.client.setAccessToken(accessToken)
135
- const response = await this.client.crm.objects.searchApi.doSearch(objectType, {
136
- filterGroups: [
137
- {
138
- filters: filters,
139
- },
140
- ],
141
- })
142
-
134
+ const response = await this.client.crm.objects.searchApi.doSearch(objectType, searchRequest)
143
135
  return response.results || null
144
136
  }
145
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dma-sdk/hubspot",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "DMA SDK – Hubspot service",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,14 +10,14 @@
10
10
  "test": "node_modules/jest/bin/jest.js --runInBand --forceExit --coverage --detectOpenHandles --coverageProvider v8 --collectCoverageFrom=src/**/*.{ts,js} --config='./jest.config.js' __tests__"
11
11
  },
12
12
  "dependencies": {
13
- "@dma-sdk/utils": "^1.0.4",
13
+ "@dma-sdk/utils": "^1.0.6",
14
14
  "@hubspot/api-client": "^13.4.0",
15
15
  "zod": "^4.3.5"
16
16
  },
17
17
  "devDependencies": {
18
- "typescript": "^5.2.0",
19
- "ts-jest": "^29.2.5",
18
+ "@types/jest": "^29.5.13",
20
19
  "jest": "^29.7.0",
21
- "@types/jest": "^29.5.13"
20
+ "ts-jest": "^29.2.5",
21
+ "typescript": "^5.2.0"
22
22
  }
23
23
  }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApiMethods = void 0;
4
- exports.ApiMethods = {
5
- getUserInfoByToken: '/oauth/v1/access-tokens',
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),
9
- };
10
- //# sourceMappingURL=api-path.js.map
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HsDataTypes = void 0;
4
- exports.HsDataTypes = {
5
- string: "string",
6
- number: "number",
7
- boolean: "bool",
8
- date: "date",
9
- datetime: "datetime",
10
- single_select: "enumeration",
11
- multiple_select: "enumeration",
12
- checkbox: "bool",
13
- calculation: "calculation_equation",
14
- phone_number: "phone_number",
15
- user: "hubspot_user",
16
- file: "file",
17
- score: "score",
18
- currency: "currency",
19
- rich_text: "rich_text",
20
- owner: "owner",
21
- location: "location",
22
- json: "json",
23
- percentage: "number",
24
- ip_address: "ip_address",
25
- video: "video"
26
- };
27
- //# sourceMappingURL=data-types.js.map
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HsObjectTypes = void 0;
4
- exports.HsObjectTypes = {};
5
- //# sourceMappingURL=object-types.js.map