@livechat/developer-studio-api 3.1.27 → 3.1.29

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/index.mjs CHANGED
@@ -2005,9 +2005,13 @@ var textPlatformWorkflowsApi = {
2005
2005
  return __async(this, null, function* () {
2006
2006
  yield textClientInstance.delete(
2007
2007
  `/workflow_platform/workflows/${encodeURIComponent(payload.name)}`,
2008
- getTextClientConfig(__spreadProps(__spreadValues({}, authorization), {
2008
+ __spreadProps(__spreadValues({}, getTextClientConfig(__spreadProps(__spreadValues({}, authorization), {
2009
2009
  ensureAuthorizationToken: true
2010
- }))
2010
+ }))), {
2011
+ data: {
2012
+ third_party_headers: payload.third_party_headers
2013
+ }
2014
+ })
2011
2015
  );
2012
2016
  });
2013
2017
  },
@@ -3068,9 +3072,184 @@ var shopifyApi = {
3068
3072
  }
3069
3073
  };
3070
3074
 
3071
- // src/apis/integrations/hubspot/api.ts
3075
+ // src/apis/integrations/hubspot/instance.ts
3072
3076
  import axios16 from "axios";
3077
+ var HubspotApiError = class extends ApiErrorBase {
3078
+ constructor() {
3079
+ super(...arguments);
3080
+ this.name = "hubspot";
3081
+ }
3082
+ };
3083
+ var hubspotClientInstance = axios16.create({
3084
+ baseURL: `https://api.hubapi.com`,
3085
+ headers: {
3086
+ "Content-Type": "application/json"
3087
+ }
3088
+ });
3089
+ hubspotClientInstance.interceptors.response.use(
3090
+ (r) => r,
3091
+ (error) => {
3092
+ var _a, _b, _c, _d;
3093
+ if (axios16.isAxiosError(error)) {
3094
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
3095
+ throw new UnauthorizeApiError("hubspot");
3096
+ }
3097
+ }
3098
+ return Promise.reject(
3099
+ new HubspotApiError(
3100
+ error.message,
3101
+ (_b = error.response) == null ? void 0 : _b.data,
3102
+ (_d = (_c = error.response) == null ? void 0 : _c.status) != null ? _d : 400
3103
+ )
3104
+ );
3105
+ }
3106
+ );
3107
+ function getHubspotClientAuthorization(req) {
3108
+ if (req.headers instanceof Headers) {
3109
+ return {
3110
+ token: req.headers.get("x-adapter-hubspot-token")
3111
+ };
3112
+ }
3113
+ return {
3114
+ token: req.headers["x-adapter-hubspot-token"]
3115
+ };
3116
+ }
3117
+ function getHubspotClientConfig(options = {}) {
3118
+ var _a;
3119
+ const currentHeaders = hubspotClientInstance.defaults.headers;
3120
+ const config = {
3121
+ authorization: (_a = options.token ? `Bearer ${options.token}` : void 0) != null ? _a : currentHeaders.Authorization
3122
+ };
3123
+ if (options.ensureAuthorizationToken && !config.authorization) {
3124
+ throw new UnauthorizeApiError("hubspot");
3125
+ }
3126
+ return {
3127
+ headers: __spreadValues({}, config.authorization ? { Authorization: config.authorization } : {})
3128
+ };
3129
+ }
3130
+ function initHubspotClient(token) {
3131
+ if (token) {
3132
+ updateHubspotClient(token);
3133
+ }
3134
+ }
3135
+ function updateHubspotClient(token) {
3136
+ const defaults = hubspotClientInstance.defaults;
3137
+ const headers = defaults.headers;
3138
+ if (token) {
3139
+ headers.Authorization = `Bearer ${token}`;
3140
+ } else {
3141
+ delete headers.Authorization;
3142
+ }
3143
+ }
3144
+
3145
+ // src/apis/integrations/hubspot/webhooks/api.ts
3146
+ var hubspotWebhooksApi = {
3147
+ settings: {
3148
+ get(appId, authorization) {
3149
+ return __async(this, null, function* () {
3150
+ const params = new URLSearchParams(
3151
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3152
+ hapikey: authorization.apiKey
3153
+ } : {}
3154
+ );
3155
+ return hubspotClientInstance.get(
3156
+ `/webhooks/v1/${encodeURIComponent(
3157
+ appId
3158
+ )}/settings?${params.toString()}`
3159
+ // getHubspotClientConfig({
3160
+ // ...authorization,
3161
+ // ensureAuthorizationToken: true,
3162
+ // })
3163
+ ).catch((e) => {
3164
+ console.log(e);
3165
+ throw e;
3166
+ });
3167
+ });
3168
+ },
3169
+ update(appId, payload, authorization) {
3170
+ return __async(this, null, function* () {
3171
+ const params = new URLSearchParams(
3172
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3173
+ hapikey: authorization.apiKey
3174
+ } : {}
3175
+ );
3176
+ return hubspotClientInstance.put(
3177
+ `/webhooks/v1/${encodeURIComponent(
3178
+ appId
3179
+ )}/settings?${params.toString()}`,
3180
+ payload
3181
+ // getHubspotClientConfig({
3182
+ // ...authorization,
3183
+ // ensureAuthorizationToken: true,
3184
+ // })
3185
+ );
3186
+ });
3187
+ }
3188
+ },
3189
+ subscriptions: {
3190
+ list(appId, authorization) {
3191
+ return __async(this, null, function* () {
3192
+ const params = new URLSearchParams(
3193
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3194
+ hapikey: authorization.apiKey
3195
+ } : {}
3196
+ );
3197
+ return hubspotClientInstance.get(
3198
+ `/webhooks/v3/${encodeURIComponent(
3199
+ appId
3200
+ )}/subscriptions?${params.toString()}`
3201
+ // getHubspotClientConfig({
3202
+ // ...authorization,
3203
+ // ensureAuthorizationToken: true,
3204
+ // })
3205
+ );
3206
+ });
3207
+ },
3208
+ register(appId, payload, authorization) {
3209
+ return __async(this, null, function* () {
3210
+ const params = new URLSearchParams(
3211
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3212
+ hapikey: authorization.apiKey
3213
+ } : {}
3214
+ );
3215
+ return hubspotClientInstance.post(
3216
+ `/webhooks/v3/${encodeURIComponent(
3217
+ appId
3218
+ )}/subscriptions?${params.toString()}`,
3219
+ payload
3220
+ // getHubspotClientConfig({
3221
+ // ...authorization,
3222
+ // ensureAuthorizationToken: true,
3223
+ // })
3224
+ );
3225
+ });
3226
+ },
3227
+ unregister(appId, subscriptionId, authorization) {
3228
+ return __async(this, null, function* () {
3229
+ const params = new URLSearchParams(
3230
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3231
+ hapikey: authorization.apiKey
3232
+ } : {}
3233
+ );
3234
+ return hubspotClientInstance.delete(
3235
+ `/webhooks/v3/${encodeURIComponent(
3236
+ appId
3237
+ )}/subscriptions/${encodeURIComponent(
3238
+ subscriptionId
3239
+ )}?${params.toString()}`
3240
+ // getHubspotClientConfig({
3241
+ // ...authorization,
3242
+ // ensureAuthorizationToken: true,
3243
+ // })
3244
+ );
3245
+ });
3246
+ }
3247
+ }
3248
+ };
3249
+
3250
+ // src/apis/integrations/hubspot/api.ts
3073
3251
  var hubspotApi = {
3252
+ webhooks: hubspotWebhooksApi,
3074
3253
  getToken(code, clientId, clientSecret, redirectUri) {
3075
3254
  return __async(this, null, function* () {
3076
3255
  var _a;
@@ -3081,8 +3260,8 @@ var hubspotApi = {
3081
3260
  redirect_uri: redirectUri,
3082
3261
  grant_type: "authorization_code"
3083
3262
  });
3084
- const tokenResponse = yield axios16.post(
3085
- "https://api.hubapi.com/oauth/v1/token",
3263
+ const tokenResponse = yield hubspotClientInstance.post(
3264
+ "/oauth/v1/token",
3086
3265
  data,
3087
3266
  {
3088
3267
  headers: {
@@ -3098,22 +3277,10 @@ var hubspotApi = {
3098
3277
  };
3099
3278
  });
3100
3279
  },
3101
- getMetadata(_0) {
3102
- return __async(this, arguments, function* ({ token }) {
3103
- const {
3104
- data: { dc: server }
3105
- } = yield axios16.get(
3106
- "https://login.mailchimp.com/oauth2/metadata",
3107
- {
3108
- headers: {
3109
- "Content-Type": "application/json",
3110
- Authorization: `OAuth ${token}`
3111
- }
3112
- }
3113
- );
3114
- return {
3115
- server
3116
- };
3280
+ getTokenInfo(token) {
3281
+ return __async(this, null, function* () {
3282
+ const { data: tokenInfo } = yield hubspotClientInstance.get(`/oauth/v1/access-tokens/${token}`);
3283
+ return tokenInfo;
3117
3284
  });
3118
3285
  }
3119
3286
  };
@@ -6591,75 +6758,12 @@ var WorkflowDefinitionTaskType = {
6591
6758
  trigger: "TRIGGER"
6592
6759
  };
6593
6760
 
6594
- // src/apis/integrations/hubspot/instance.ts
6595
- import axios22 from "axios";
6596
- var HubspotApiError = class extends ApiErrorBase {
6597
- constructor() {
6598
- super(...arguments);
6599
- this.name = "hubspot";
6600
- }
6601
- };
6602
- var hubspotClientUrl = `https://api.hubapi.com`;
6603
- var hubspotClientInstance = axios22.create({
6604
- headers: {
6605
- "Content-Type": "application/json"
6606
- }
6607
- });
6608
- hubspotClientInstance.interceptors.response.use(
6609
- (r) => r,
6610
- (error) => {
6611
- var _a, _b, _c, _d;
6612
- if (axios22.isAxiosError(error)) {
6613
- if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
6614
- throw new UnauthorizeApiError("hubspot");
6615
- }
6616
- }
6617
- return Promise.reject(
6618
- new HubspotApiError(
6619
- error.message,
6620
- (_b = error.response) == null ? void 0 : _b.data,
6621
- (_d = (_c = error.response) == null ? void 0 : _c.status) != null ? _d : 400
6622
- )
6623
- );
6624
- }
6625
- );
6626
- function getHubspotClientAuthorization(req) {
6627
- if (req.headers instanceof Headers) {
6628
- return {
6629
- token: req.headers.get("x-adapter-hubspot-token")
6630
- };
6631
- }
6632
- return {
6633
- token: req.headers["x-adapter-hubspot-token"]
6634
- };
6635
- }
6636
- function getHubspotClientConfig(options = {}) {
6637
- var _a;
6638
- const currentHeaders = hubspotClientInstance.defaults.headers;
6639
- const config = {
6640
- authorization: (_a = options.token ? `Bearer ${options.token}` : void 0) != null ? _a : currentHeaders.Authorization
6641
- };
6642
- if (options.ensureAuthorizationToken && !config.authorization) {
6643
- throw new UnauthorizeApiError("hubspot");
6644
- }
6645
- return {
6646
- headers: __spreadValues({}, config.authorization ? { Authorization: config.authorization } : {})
6647
- };
6648
- }
6649
- function initHubspotClient(token) {
6650
- if (token) {
6651
- updateHubspotClient(token);
6652
- }
6653
- }
6654
- function updateHubspotClient(token) {
6655
- const defaults = hubspotClientInstance.defaults;
6656
- const headers = defaults.headers;
6657
- if (token) {
6658
- headers.Authorization = `Bearer ${token}`;
6659
- } else {
6660
- delete headers.Authorization;
6661
- }
6662
- }
6761
+ // src/apis/integrations/hubspot/webhooks/_contracts/dtos/webhooks.ts
6762
+ var HubSpotWebhookEventTypes = /* @__PURE__ */ ((HubSpotWebhookEventTypes2) => {
6763
+ HubSpotWebhookEventTypes2["ContactCreation"] = "contact.creation";
6764
+ HubSpotWebhookEventTypes2["ContactDeletion"] = "contact.deletion";
6765
+ return HubSpotWebhookEventTypes2;
6766
+ })(HubSpotWebhookEventTypes || {});
6663
6767
 
6664
6768
  // src/apis/integrations/bigcommerce/webhooks/_contracts/dtos/webhooks.ts
6665
6769
  var BigCommerceWebhookScopes = /* @__PURE__ */ ((BigCommerceWebhookScopes2) => {
@@ -6669,8 +6773,8 @@ var BigCommerceWebhookScopes = /* @__PURE__ */ ((BigCommerceWebhookScopes2) => {
6669
6773
  })(BigCommerceWebhookScopes || {});
6670
6774
 
6671
6775
  // src/apis/platform/billing/instance.ts
6672
- import axios23 from "axios";
6673
- var platformBillingClientInstance = axios23.create({
6776
+ import axios22 from "axios";
6777
+ var platformBillingClientInstance = axios22.create({
6674
6778
  baseURL: "https://billing.labs.livechatinc.com"
6675
6779
  });
6676
6780
  function getPlatformBillingClientAuthorization(req) {
@@ -6956,7 +7060,8 @@ import { z as z4 } from "zod";
6956
7060
 
6957
7061
  // src/apis/platform/adapter/integrations/hubspot/_contracts/dtos/events.ts
6958
7062
  var HubspotEventNames = /* @__PURE__ */ ((HubspotEventNames2) => {
6959
- HubspotEventNames2["SomeEvent"] = "some_event";
7063
+ HubspotEventNames2["ContactCreated"] = "contact_created";
7064
+ HubspotEventNames2["ContactDeleted"] = "contact_deleted";
6960
7065
  return HubspotEventNames2;
6961
7066
  })(HubspotEventNames || {});
6962
7067
 
@@ -6965,12 +7070,18 @@ var hubspotEventsZods = {
6965
7070
  provider: z4.literal("hubspot"),
6966
7071
  eventName: z4.nativeEnum(HubspotEventNames),
6967
7072
  events: {
6968
- someEvent: z4.object({
6969
- name: z4.literal("some_event" /* SomeEvent */)
7073
+ contactCreated: z4.object({
7074
+ name: z4.literal("contact_created" /* ContactCreated */)
7075
+ }),
7076
+ contactDeleted: z4.object({
7077
+ name: z4.literal("contact_deleted" /* ContactDeleted */)
6970
7078
  })
6971
7079
  },
6972
7080
  get event() {
6973
- return z4.discriminatedUnion("name", [this.events.someEvent]);
7081
+ return z4.discriminatedUnion("name", [
7082
+ this.events.contactCreated,
7083
+ this.events.contactDeleted
7084
+ ]);
6974
7085
  },
6975
7086
  get source() {
6976
7087
  return z4.object({
@@ -6990,7 +7101,7 @@ var hubspotEventsZods = {
6990
7101
  return z4.object({
6991
7102
  provider: this.provider,
6992
7103
  event: this.event,
6993
- listId: z4.string()
7104
+ callback: z4.string()
6994
7105
  });
6995
7106
  },
6996
7107
  get unsubscribe() {
@@ -7532,6 +7643,7 @@ export {
7532
7643
  BigCommerceEventNames,
7533
7644
  BigCommerceWebhookScopes,
7534
7645
  DpsApiError,
7646
+ HubSpotWebhookEventTypes,
7535
7647
  HubspotApiError,
7536
7648
  HubspotEventNames,
7537
7649
  IntegrationModes,
@@ -7599,7 +7711,6 @@ export {
7599
7711
  getVercelClientConfig,
7600
7712
  githubClientInstance,
7601
7713
  hubspotClientInstance,
7602
- hubspotClientUrl,
7603
7714
  hubspotEventsZods,
7604
7715
  initApi,
7605
7716
  initBigCommerceClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livechat/developer-studio-api",
3
- "version": "3.1.27",
3
+ "version": "3.1.29",
4
4
  "description": "This project is API for LiveChat Developer Studio.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",