@xapp/stentor-service-hubspot 1.81.0 → 1.82.0
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/lib/HubspotService.d.ts +3 -17
- package/lib/HubspotService.js +16 -15
- package/lib/HubspotService.js.map +1 -1
- package/package.json +3 -3
package/lib/HubspotService.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
/*! Copyright (c) 2022, XAPPmedia */
|
|
2
1
|
import { FetchService } from "stentor-service-fetch";
|
|
3
2
|
import { BaseService, CrmResponse, CrmService, CrmServiceAvailability, CrmServiceAvailabilityOptions, CrmServiceJobType, DateTimeRange, ExternalLead } from "stentor-models";
|
|
4
|
-
import { Client } from "@hubspot/api-client";
|
|
5
3
|
export interface HubspotServiceProps extends BaseService {
|
|
6
4
|
appId: string;
|
|
7
5
|
/**
|
|
@@ -64,9 +62,7 @@ export interface HubspotResponse {
|
|
|
64
62
|
Reason?: string;
|
|
65
63
|
}
|
|
66
64
|
/**
|
|
67
|
-
* The contact body
|
|
68
|
-
* (`hubspotClient.crm.contacts.basicApi.create`) and at the REST endpoint
|
|
69
|
-
* (`POST /crm/v3/objects/contacts`). The shape is identical.
|
|
65
|
+
* The contact body accepted by Hubspot's REST endpoint (`POST /crm/v3/objects/contacts`).
|
|
70
66
|
*/
|
|
71
67
|
export interface HubspotContactPayload {
|
|
72
68
|
properties: {
|
|
@@ -79,14 +75,8 @@ export interface HubspotContactPayload {
|
|
|
79
75
|
}
|
|
80
76
|
/**
|
|
81
77
|
* Describes the HTTP request that should be POSTed to Hubspot's contact
|
|
82
|
-
* REST endpoint.
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* Note: `HubspotService.send()` itself does NOT use this descriptor's
|
|
86
|
-
* `url` or `headers` — the class routes through `@hubspot/api-client`,
|
|
87
|
-
* which manages its own auth headers and endpoint. `url` and `headers`
|
|
88
|
-
* are populated for REST callers (chain runners) that bypass the SDK.
|
|
89
|
-
* `body` is shared between both transports.
|
|
78
|
+
* REST endpoint. Both `HubspotService.send()` and stateless callers
|
|
79
|
+
* (e.g. stentor-api's chain runner) use this descriptor.
|
|
90
80
|
*
|
|
91
81
|
* SECURITY: `headers.Authorization` carries the Bearer access token.
|
|
92
82
|
* Callers that audit-log this descriptor must redact the `Authorization`
|
|
@@ -99,7 +89,6 @@ export interface HubspotRequestDescriptor {
|
|
|
99
89
|
body: HubspotContactPayload;
|
|
100
90
|
}
|
|
101
91
|
export declare class HubspotService extends FetchService implements CrmService {
|
|
102
|
-
hubspotClient: Client;
|
|
103
92
|
private props;
|
|
104
93
|
constructor(props: HubspotServiceProps);
|
|
105
94
|
getAvailability(range: DateTimeRange, options?: CrmServiceAvailabilityOptions): Promise<CrmServiceAvailability>;
|
|
@@ -108,9 +97,6 @@ export declare class HubspotService extends FetchService implements CrmService {
|
|
|
108
97
|
}
|
|
109
98
|
/**
|
|
110
99
|
* Builds the Hubspot contact request descriptor without performing any I/O.
|
|
111
|
-
*
|
|
112
|
-
* The body matches both the SDK input (`hubspotClient.crm.contacts.basicApi.create`)
|
|
113
|
-
* and the REST endpoint payload, so callers can execute via either transport.
|
|
114
100
|
*/
|
|
115
101
|
export declare function buildHubspotContactRequest(props: HubspotServiceProps, externalLead: ExternalLead, extras?: HubspotExternalLeadExtras): HubspotRequestDescriptor;
|
|
116
102
|
/**
|
package/lib/HubspotService.js
CHANGED
|
@@ -8,22 +8,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.HubspotService = void 0;
|
|
13
16
|
exports.buildHubspotContactRequest = buildHubspotContactRequest;
|
|
14
17
|
exports.parseHubspotContactResponse = parseHubspotContactResponse;
|
|
15
18
|
/*! Copyright (c) 2022, XAPPmedia */
|
|
19
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
20
|
const stentor_service_fetch_1 = require("stentor-service-fetch");
|
|
17
21
|
const stentor_logger_1 = require("stentor-logger");
|
|
18
22
|
const util_1 = require("./util");
|
|
19
|
-
// Hubspot API Client
|
|
20
|
-
const api_client_1 = require("@hubspot/api-client");
|
|
21
23
|
const HUBSPOT_CONTACTS_ENDPOINT = "https://api.hubapi.com/crm/v3/objects/contacts";
|
|
22
24
|
class HubspotService extends stentor_service_fetch_1.FetchService {
|
|
23
25
|
constructor(props) {
|
|
24
26
|
super(props);
|
|
25
27
|
this.props = Object.assign(Object.assign({}, props), { accessToken: props.accessToken || process.env.HUBSPOT_TOKEN });
|
|
26
|
-
this.hubspotClient = new api_client_1.Client({ accessToken: this.props.accessToken });
|
|
27
28
|
(0, stentor_logger_1.log)().info(`app id: ${this.props.appId}`);
|
|
28
29
|
}
|
|
29
30
|
getAvailability(range, options) {
|
|
@@ -44,33 +45,33 @@ class HubspotService extends stentor_service_fetch_1.FetchService {
|
|
|
44
45
|
}
|
|
45
46
|
send(externalLead, extras) {
|
|
46
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const crmResponse = {
|
|
48
|
-
status: "Failure",
|
|
49
|
-
message: ""
|
|
50
|
-
};
|
|
51
48
|
try {
|
|
52
49
|
const descriptor = buildHubspotContactRequest(this.props, externalLead, extras);
|
|
53
|
-
const
|
|
54
|
-
|
|
50
|
+
const axiosResponse = yield axios_1.default.post(descriptor.url, descriptor.body, {
|
|
51
|
+
headers: descriptor.headers
|
|
52
|
+
});
|
|
53
|
+
const parsed = parseHubspotContactResponse(axiosResponse.data);
|
|
55
54
|
if (parsed.status === "Success") {
|
|
56
55
|
(0, stentor_logger_1.log)().info(`Contact sent to Hubspot: ${parsed.refId}`);
|
|
57
56
|
}
|
|
58
57
|
return parsed;
|
|
59
58
|
}
|
|
60
59
|
catch (e) {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const responseDetail = axios_1.default.isAxiosError(e) && e.response
|
|
61
|
+
? ` (status ${e.response.status}; body ${JSON.stringify(e.response.data)})`
|
|
62
|
+
: "";
|
|
63
|
+
(0, stentor_logger_1.log)().error(`Error sending lead to Hubspot ${e}${responseDetail}`);
|
|
64
|
+
return {
|
|
65
|
+
status: "Failure",
|
|
66
|
+
message: e instanceof Error ? e.message : String(e)
|
|
67
|
+
};
|
|
63
68
|
}
|
|
64
|
-
return crmResponse;
|
|
65
69
|
});
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
exports.HubspotService = HubspotService;
|
|
69
73
|
/**
|
|
70
74
|
* Builds the Hubspot contact request descriptor without performing any I/O.
|
|
71
|
-
*
|
|
72
|
-
* The body matches both the SDK input (`hubspotClient.crm.contacts.basicApi.create`)
|
|
73
|
-
* and the REST endpoint payload, so callers can execute via either transport.
|
|
74
75
|
*/
|
|
75
76
|
function buildHubspotContactRequest(props, externalLead, extras) {
|
|
76
77
|
var _a, _b, _c, _d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HubspotService.js","sourceRoot":"","sources":["../src/HubspotService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HubspotService.js","sourceRoot":"","sources":["../src/HubspotService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AA2JA,gEAgCC;AAMD,kEAaC;AA9MD,oCAAoC;AACpC,kDAA0B;AAC1B,iEAAqD;AAErD,mDAAqC;AAErC,iCAA6C;AA8F7C,MAAM,yBAAyB,GAAG,gDAAgD,CAAC;AAEnF,MAAa,cAAe,SAAQ,oCAAY;IAG5C,YAAY,KAA0B;QAClC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,mCACH,KAAK,KACR,WAAW,EAAE,KAAK,CAAC,WAAW,IAAI,OAAO,CAAC,GAA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CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,0CAAE,KAAK;QACxE,KAAK,EAAE,MAAA,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,0CAAE,KAAK;QACjE,KAAK,EAAE,MAAA,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,0CAAE,KAAK;QACjE,OAAO,EAAE,QAAQ;KACpB,CAAC;IAEF,OAAO;QACH,GAAG,EAAE,yBAAyB;QAC9B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACL,eAAe,EAAE,UAAU,KAAK,CAAC,WAAW,EAAE;YAC9C,cAAc,EAAE,kBAAkB;SACrC;QACD,IAAI,EAAE,EAAE,UAAU,EAAE;KACvB,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAgB,2BAA2B,CAAC,IAAa;IACrD,MAAM,QAAQ,GAAG,IAAuB,CAAC;IACzC,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,EAAE,CAAC;QACf,OAAO;YACH,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,eAAe,QAAQ,CAAC,EAAE,EAAE;YACrC,KAAK,EAAE,QAAQ,CAAC,EAAE;SACrB,CAAC;IACN,CAAC;IACD,OAAO;QACH,MAAM,EAAE,SAAS;QACjB,OAAO,EAAE,qCAAqC;KACjD,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.82.0",
|
|
8
8
|
"description": "Service to interface the Hubspot CRM service",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"typescript": "5.9.3"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"
|
|
30
|
+
"axios": "1.16.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"stentor-logger": "1.x",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"clean": "rm -rf ./lib/*",
|
|
40
40
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "d4ad419e6b72c016edeb41c56210b2a70c1e94a9"
|
|
43
43
|
}
|