@dma-sdk/hubspot 1.0.2 → 1.0.4

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,4 +1,4 @@
1
- export declare const apiMethods: {
1
+ export declare const ApiMethods: {
2
2
  getUserInfoByToken: string;
3
3
  refreshToken: string;
4
4
  createObjectProperties: (objectType: string) => string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.apiMethods = void 0;
4
- exports.apiMethods = {
3
+ exports.ApiMethods = void 0;
4
+ exports.ApiMethods = {
5
5
  getUserInfoByToken: '/oauth/v1/access-tokens',
6
6
  refreshToken: '/oauth/v1/token',
7
7
  createObjectProperties: (objectType) => '/crm/v3/properties/{objectType}/batch/create'.replace('{objectType}', objectType),
@@ -1,4 +1,4 @@
1
- export declare const hsDataTypes: {
1
+ export declare const HsDataTypes: {
2
2
  string: string;
3
3
  number: string;
4
4
  boolean: string;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hsDataTypes = void 0;
4
- exports.hsDataTypes = {
3
+ exports.HsDataTypes = void 0;
4
+ exports.HsDataTypes = {
5
5
  string: "string",
6
6
  number: "number",
7
7
  boolean: "bool",
@@ -1 +1 @@
1
- export declare const hsDataTypes: {};
1
+ export declare const HsObjectTypes: {};
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hsDataTypes = void 0;
4
- exports.hsDataTypes = {};
3
+ exports.HsObjectTypes = void 0;
4
+ exports.HsObjectTypes = {};
@@ -0,0 +1,6 @@
1
+ export * from './services/hubspot-service';
2
+ export * from './constants/data-types';
3
+ export * from './constants/object-types';
4
+ export * from './interfaces/input/subscriptions';
5
+ export * from './interfaces/output/subscriptions';
6
+ export * from './types/auth/hs-signature-data';
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./services/hubspot-service"), exports);
18
+ __exportStar(require("./constants/data-types"), exports);
19
+ __exportStar(require("./constants/object-types"), exports);
20
+ __exportStar(require("./interfaces/input/subscriptions"), exports);
21
+ __exportStar(require("./interfaces/output/subscriptions"), exports);
22
+ __exportStar(require("./types/auth/hs-signature-data"), exports);
@@ -1,14 +1,14 @@
1
- import { HubspotUser } from './interfaces/user';
1
+ import { HubspotUser } from '../interfaces/user';
2
2
  import { Configuration, Filter } 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';
6
6
  import { TokenResponseIF } from '@hubspot/api-client/lib/codegen/oauth';
7
- import { TokenResponse } from './interfaces/token';
7
+ import { TokenResponse } from '../interfaces/token';
8
8
  import { CollectionResponsePropertyNoPaging, PropertyCreate, PropertyGroup, PropertyGroupCreate } from '@hubspot/api-client/lib/codegen/crm/properties';
9
- import { HubspotSignatureData } from './types/auth/hs-signature-data';
10
- import { CreateSubscriptionInput } from './interfaces/input/subscriptions';
11
- import { CreateSubscriptionOutput } from './interfaces/output/subscriptions';
9
+ import { HubspotSignatureData } from '../types/auth/hs-signature-data';
10
+ import { CreateSubscriptionInput } from '../interfaces/input/subscriptions';
11
+ import { CreateSubscriptionOutput } from '../interfaces/output/subscriptions';
12
12
  export declare class HubspotService {
13
13
  static HS_BASE_URL: string;
14
14
  static readonly hubspotObjectType: {
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HubspotService = void 0;
4
4
  const api_client_1 = require("@hubspot/api-client");
5
- const type_converter_1 = require("./utils/type-converter");
6
- const data_types_1 = require("./constants/data-types");
5
+ const type_converter_1 = require("../utils/type-converter");
6
+ const data_types_1 = require("../constants/data-types");
7
7
  const api_client_2 = require("@hubspot/api-client");
8
8
  const fetch_1 = require("@dma-sdk/utils/src/fetch");
9
- const api_path_1 = require("./constants/api-path");
9
+ const api_path_1 = require("../constants/api-path");
10
10
  // Per ogni metodo che viene creato, è fondamentale che
11
11
  // il client venga inizializzato con il token di accesso o l'api key
12
12
  // altrimenti non funzionerà correttamente.
@@ -25,7 +25,7 @@ class HubspotService {
25
25
  async getUserInfoByToken(accessToken) {
26
26
  const response = await this.client.apiRequest({
27
27
  method: 'GET',
28
- path: `${api_path_1.apiMethods.getUserInfoByToken}/${accessToken}`,
28
+ path: `${api_path_1.ApiMethods.getUserInfoByToken}/${accessToken}`,
29
29
  });
30
30
  const jsonBody = await response.json();
31
31
  const userAttributes = {
@@ -143,7 +143,7 @@ class HubspotService {
143
143
  inputs: properties
144
144
  })
145
145
  };
146
- const response = await this.fetchApi(api_path_1.apiMethods.createObjectProperties(objectType), options);
146
+ const response = await this.fetchApi(api_path_1.ApiMethods.createObjectProperties(objectType), options);
147
147
  return await response.json();
148
148
  }
149
149
  async createPropertyGroup(objectType, group, accessToken) {
@@ -153,10 +153,9 @@ class HubspotService {
153
153
  convertPropertyValues(properties, convertionMap) {
154
154
  let convertedProps = {};
155
155
  Object.entries(properties).forEach(([key, value]) => {
156
- var _a;
157
156
  if (value === undefined)
158
157
  return;
159
- const convertionFunc = this.typeConvert[(_a = convertionMap[key]) === null || _a === void 0 ? void 0 : _a.type];
158
+ const convertionFunc = this.typeConvert[convertionMap[key]?.type];
160
159
  if (convertionFunc === undefined) {
161
160
  convertedProps[key] = value;
162
161
  return;
@@ -175,7 +174,7 @@ class HubspotService {
175
174
  },
176
175
  body: JSON.stringify(event)
177
176
  };
178
- const response = await this.fetchApi(api_path_1.apiMethods.subscriptions(appId), options, { hapikey: devApiKey });
177
+ const response = await this.fetchApi(api_path_1.ApiMethods.subscriptions(appId), options, { hapikey: devApiKey });
179
178
  return await response.json();
180
179
  }
181
180
  async fetchApi(endpoint, options, queryParams) {
@@ -188,4 +187,4 @@ HubspotService.hubspotObjectType = {
188
187
  contacts: 'contacts',
189
188
  notes: 'notes',
190
189
  };
191
- HubspotService.hubspotPropertyTypes = data_types_1.hsDataTypes;
190
+ HubspotService.hubspotPropertyTypes = data_types_1.HsDataTypes;
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typeConverter = void 0;
4
4
  const data_types_1 = require("../constants/data-types");
5
5
  exports.typeConverter = {
6
- [data_types_1.hsDataTypes.date]: (data) => {
6
+ [data_types_1.HsDataTypes.date]: (data) => {
7
7
  return (new Date(data)).setUTCHours(0, 0, 0, 0);
8
8
  },
9
- [data_types_1.hsDataTypes.datetime]: (data) => {
9
+ [data_types_1.HsDataTypes.datetime]: (data) => {
10
10
  return new Date(data).getTime();
11
11
  },
12
- [data_types_1.hsDataTypes.number]: (data) => {
12
+ [data_types_1.HsDataTypes.number]: (data) => {
13
13
  return (typeof data === "number") ? data : parseFloat(data);
14
14
  }
15
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dma-sdk/hubspot",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "DMA SDK – Hubspot service",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,11 +9,11 @@
9
9
  "prepare": "npm run build"
10
10
  },
11
11
  "dependencies": {
12
- "@dma-sdk/utils": "^1.0.0",
12
+ "@dma-sdk/utils": "^1.0.3",
13
13
  "@hubspot/api-client": "^13.4.0",
14
14
  "zod": "^4.3.5"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "^5.2.0"
18
18
  }
19
- }
19
+ }
@@ -1,4 +1,4 @@
1
- export const apiMethods = {
1
+ export const ApiMethods = {
2
2
  getUserInfoByToken: '/oauth/v1/access-tokens',
3
3
  refreshToken: '/oauth/v1/token',
4
4
  createObjectProperties: (objectType: string) => '/crm/v3/properties/{objectType}/batch/create'.replace('{objectType}', objectType),
@@ -1,4 +1,4 @@
1
- export const hsDataTypes = {
1
+ export const HsDataTypes = {
2
2
  string: "string",
3
3
  number: "number",
4
4
  boolean: "bool",
@@ -1 +1 @@
1
- export const hsDataTypes = {}
1
+ export const HsObjectTypes = {}
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './services/hubspot-service';
2
+ export * from './constants/data-types';
3
+ export * from './constants/object-types';
4
+ export * from './interfaces/input/subscriptions';
5
+ export * from './interfaces/output/subscriptions';
6
+ export * from './types/auth/hs-signature-data';
@@ -1,21 +1,21 @@
1
1
  import { Client as HubspotClient } from '@hubspot/api-client'
2
- import { HubspotUser } from './interfaces/user'
2
+ import { HubspotUser } from '../interfaces/user'
3
3
  import { Configuration, Filter } from '@hubspot/api-client/lib/codegen/crm/objects'
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
7
  import { TokenResponseIF } from '@hubspot/api-client/lib/codegen/oauth'
8
- import { typeConverter } from './utils/type-converter'
9
- import { HubspotTypeConverter } from './interfaces/hubspot-type-converter'
10
- import { hsDataTypes } from './constants/data-types'
8
+ import { typeConverter } from '../utils/type-converter'
9
+ import { HubspotTypeConverter } from '../interfaces/hubspot-type-converter'
10
+ import { HsDataTypes } from '../constants/data-types'
11
11
  import { Signature } from '@hubspot/api-client'
12
- import { TokenResponse } from './interfaces/token'
12
+ import { TokenResponse } from '../interfaces/token'
13
13
  import { CollectionResponsePropertyNoPaging, PropertyCreate, PropertyGroup, PropertyGroupCreate } from '@hubspot/api-client/lib/codegen/crm/properties'
14
- import { HubspotSignatureData } from './types/auth/hs-signature-data'
14
+ import { HubspotSignatureData } from '../types/auth/hs-signature-data'
15
15
  import { fetchApi } from '@dma-sdk/utils/src/fetch'
16
- import { apiMethods } from './constants/api-path'
17
- import { CreateSubscriptionInput } from './interfaces/input/subscriptions'
18
- import { CreateSubscriptionOutput } from './interfaces/output/subscriptions'
16
+ import { ApiMethods } from '../constants/api-path'
17
+ import { CreateSubscriptionInput } from '../interfaces/input/subscriptions'
18
+ import { CreateSubscriptionOutput } from '../interfaces/output/subscriptions'
19
19
 
20
20
  // Per ogni metodo che viene creato, è fondamentale che
21
21
  // il client venga inizializzato con il token di accesso o l'api key
@@ -27,7 +27,7 @@ export class HubspotService {
27
27
  contacts: 'contacts',
28
28
  notes: 'notes',
29
29
  }
30
- public static readonly hubspotPropertyTypes = hsDataTypes
30
+ public static readonly hubspotPropertyTypes = HsDataTypes
31
31
 
32
32
  private client: HubspotClient
33
33
  private hsRedirectUriOauth: string
@@ -58,7 +58,7 @@ export class HubspotService {
58
58
  async getUserInfoByToken(accessToken: string): Promise<HubspotUser> {
59
59
  const response = await this.client.apiRequest({
60
60
  method: 'GET',
61
- path: `${apiMethods.getUserInfoByToken}/${accessToken}`,
61
+ path: `${ApiMethods.getUserInfoByToken}/${accessToken}`,
62
62
  })
63
63
 
64
64
  const jsonBody = await response.json()
@@ -269,7 +269,7 @@ export class HubspotService {
269
269
  })
270
270
  };
271
271
 
272
- const response = await this.fetchApi(apiMethods.createObjectProperties(objectType), options)
272
+ const response = await this.fetchApi(ApiMethods.createObjectProperties(objectType), options)
273
273
  return await response.json()
274
274
  }
275
275
 
@@ -314,7 +314,7 @@ export class HubspotService {
314
314
  };
315
315
 
316
316
  const response = await this.fetchApi(
317
- apiMethods.subscriptions(appId),
317
+ ApiMethods.subscriptions(appId),
318
318
  options,
319
319
  { hapikey: devApiKey }
320
320
  )
@@ -1,17 +1,16 @@
1
- import { hsDataTypes } from "../constants/data-types";
1
+ import { HsDataTypes } from "../constants/data-types";
2
2
  import { HubspotTypeConverter } from "../interfaces/hubspot-type-converter";
3
- import { string } from "zod";
4
3
 
5
4
  export const typeConverter: HubspotTypeConverter = {
6
- [hsDataTypes.date]:
5
+ [HsDataTypes.date]:
7
6
  (data: string) => {
8
7
  return (new Date(data)).setUTCHours(0, 0, 0, 0);
9
8
  },
10
- [hsDataTypes.datetime]:
9
+ [HsDataTypes.datetime]:
11
10
  (data: string) => {
12
11
  return new Date(data).getTime();
13
12
  },
14
- [hsDataTypes.number]:
13
+ [HsDataTypes.number]:
15
14
  (data: string | number) => {
16
15
  return (typeof data === "number") ? data : parseFloat(data);
17
16
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES2019",
3
+ "target": "ES2020",
4
4
  "module": "CommonJS",
5
5
  "declaration": true,
6
6
  "outDir": "dist",
@@ -1,23 +0,0 @@
1
- export declare const hsDataTypes: {
2
- string: string;
3
- number: string;
4
- boolean: string;
5
- date: string;
6
- datetime: string;
7
- single_select: string;
8
- multiple_select: string;
9
- checkbox: string;
10
- calculation: string;
11
- phone_number: string;
12
- user: string;
13
- file: string;
14
- score: string;
15
- currency: string;
16
- rich_text: string;
17
- owner: string;
18
- location: string;
19
- json: string;
20
- percentage: string;
21
- ip_address: string;
22
- video: string;
23
- };
@@ -1,26 +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
- };