@dma-sdk/hubspot 1.0.2 → 1.0.3
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/constants/api-path.d.ts +1 -1
- package/dist/constants/api-path.js +2 -2
- package/dist/constants/data-types.d.ts +1 -1
- package/dist/constants/data-types.js +2 -2
- package/dist/constants/object-types.d.ts +1 -1
- package/dist/constants/object-types.js +2 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +22 -0
- package/dist/{hubspot-service.d.ts → services/hubspot-service.d.ts} +5 -5
- package/dist/{hubspot-service.js → services/hubspot-service.js} +8 -9
- package/dist/utils/type-converter.js +3 -3
- package/package.json +1 -1
- package/src/constants/api-path.ts +1 -1
- package/src/constants/data-types.ts +1 -1
- package/src/constants/object-types.ts +1 -1
- package/src/index.ts +6 -0
- package/src/{hubspot-service.ts → services/hubspot-service.ts} +13 -13
- package/src/utils/type-converter.ts +4 -5
- package/tsconfig.json +1 -1
- package/dist/constants/types.d.ts +0 -23
- package/dist/constants/types.js +0 -26
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
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 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const HsObjectTypes: {};
|
package/dist/index.d.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';
|
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 '
|
|
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 '
|
|
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 '
|
|
10
|
-
import { CreateSubscriptionInput } from '
|
|
11
|
-
import { CreateSubscriptionOutput } from '
|
|
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("
|
|
6
|
-
const data_types_1 = require("
|
|
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("
|
|
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.
|
|
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.
|
|
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[
|
|
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.
|
|
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.
|
|
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.
|
|
6
|
+
[data_types_1.HsDataTypes.date]: (data) => {
|
|
7
7
|
return (new Date(data)).setUTCHours(0, 0, 0, 0);
|
|
8
8
|
},
|
|
9
|
-
[data_types_1.
|
|
9
|
+
[data_types_1.HsDataTypes.datetime]: (data) => {
|
|
10
10
|
return new Date(data).getTime();
|
|
11
11
|
},
|
|
12
|
-
[data_types_1.
|
|
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,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
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 +1 @@
|
|
|
1
|
-
export const
|
|
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 '
|
|
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 '
|
|
9
|
-
import { HubspotTypeConverter } from '
|
|
10
|
-
import {
|
|
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 '
|
|
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 '
|
|
14
|
+
import { HubspotSignatureData } from '../types/auth/hs-signature-data'
|
|
15
15
|
import { fetchApi } from '@dma-sdk/utils/src/fetch'
|
|
16
|
-
import {
|
|
17
|
-
import { CreateSubscriptionInput } from '
|
|
18
|
-
import { CreateSubscriptionOutput } from '
|
|
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 =
|
|
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: `${
|
|
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(
|
|
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
|
-
|
|
317
|
+
ApiMethods.subscriptions(appId),
|
|
318
318
|
options,
|
|
319
319
|
{ hapikey: devApiKey }
|
|
320
320
|
)
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
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
|
-
[
|
|
5
|
+
[HsDataTypes.date]:
|
|
7
6
|
(data: string) => {
|
|
8
7
|
return (new Date(data)).setUTCHours(0, 0, 0, 0);
|
|
9
8
|
},
|
|
10
|
-
[
|
|
9
|
+
[HsDataTypes.datetime]:
|
|
11
10
|
(data: string) => {
|
|
12
11
|
return new Date(data).getTime();
|
|
13
12
|
},
|
|
14
|
-
[
|
|
13
|
+
[HsDataTypes.number]:
|
|
15
14
|
(data: string | number) => {
|
|
16
15
|
return (typeof data === "number") ? data : parseFloat(data);
|
|
17
16
|
}
|
package/tsconfig.json
CHANGED
|
@@ -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
|
-
};
|
package/dist/constants/types.js
DELETED
|
@@ -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
|
-
};
|