@livechat/developer-studio-api 3.1.18 → 3.1.20

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
@@ -2807,7 +2807,7 @@ function getMailchimpClientConfig(options = {}) {
2807
2807
  }
2808
2808
  function initMailchimpClient(token, server) {
2809
2809
  if (token && server) {
2810
- updateMailchimpClient(token);
2810
+ updateMailchimpClient(token, server);
2811
2811
  }
2812
2812
  }
2813
2813
  function updateMailchimpClient(token, server) {
@@ -3068,6 +3068,56 @@ var shopifyApi = {
3068
3068
  }
3069
3069
  };
3070
3070
 
3071
+ // src/apis/integrations/hubspot/api.ts
3072
+ import axios16 from "axios";
3073
+ var hubspotApi = {
3074
+ getToken(code, clientId, clientSecret, redirectUri) {
3075
+ return __async(this, null, function* () {
3076
+ var _a;
3077
+ const data = new URLSearchParams({
3078
+ code,
3079
+ client_id: clientId,
3080
+ client_secret: clientSecret,
3081
+ redirect_uri: redirectUri,
3082
+ grant_type: "authorization_code"
3083
+ });
3084
+ const tokenResponse = yield axios16.post(
3085
+ "https://api.hubapi.com/oauth/v1/token",
3086
+ data,
3087
+ {
3088
+ headers: {
3089
+ "Content-Type": "application/x-www-form-urlencoded"
3090
+ }
3091
+ }
3092
+ );
3093
+ const params = new URLSearchParams(
3094
+ tokenResponse.data
3095
+ );
3096
+ return {
3097
+ token: (_a = params.get("access_token")) != null ? _a : ""
3098
+ };
3099
+ });
3100
+ },
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
+ };
3117
+ });
3118
+ }
3119
+ };
3120
+
3071
3121
  // src/apis/integrations/api.ts
3072
3122
  var integrationsApi = {
3073
3123
  github: gitHubApi,
@@ -3077,11 +3127,12 @@ var integrationsApi = {
3077
3127
  shopify: shopifyApi,
3078
3128
  neon: neonApi,
3079
3129
  planetscale: planetscaleApi,
3130
+ hubspot: hubspotApi,
3080
3131
  text: textApi
3081
3132
  };
3082
3133
 
3083
3134
  // src/apis/products/livechat/instance.ts
3084
- import axios16 from "axios";
3135
+ import axios17 from "axios";
3085
3136
  var REGION = {
3086
3137
  FRA: "fra",
3087
3138
  DAL: "dal",
@@ -3101,7 +3152,7 @@ var LivechatApiError = class extends ApiErrorBase {
3101
3152
  this.name = "livechat";
3102
3153
  }
3103
3154
  };
3104
- var livechatClientInstance = axios16.create({
3155
+ var livechatClientInstance = axios17.create({
3105
3156
  baseURL: "https://api.labs.livechatinc.com"
3106
3157
  });
3107
3158
  livechatClientInstance.interceptors.response.use(
@@ -3996,14 +4047,14 @@ var platformAccountsApi = {
3996
4047
  };
3997
4048
 
3998
4049
  // src/apis/platform/dps/instance.ts
3999
- import axios17 from "axios";
4050
+ import axios18 from "axios";
4000
4051
  var DpsApiError = class extends ApiErrorBase {
4001
4052
  constructor() {
4002
4053
  super(...arguments);
4003
4054
  this.name = "dps";
4004
4055
  }
4005
4056
  };
4006
- var platformDpsClientInstance = axios17.create({
4057
+ var platformDpsClientInstance = axios18.create({
4007
4058
  baseURL: "https://dev-platform.labs.livechatinc.com"
4008
4059
  });
4009
4060
  platformDpsClientInstance.interceptors.response.use(
@@ -4199,7 +4250,7 @@ var appTemplates = {
4199
4250
  target: "nextjs"
4200
4251
  },
4201
4252
  deployment: {
4202
- provider: "netlify",
4253
+ provider: "vercel",
4203
4254
  url: ""
4204
4255
  },
4205
4256
  storage: {
@@ -5606,7 +5657,7 @@ var platformDpsApi = {
5606
5657
  };
5607
5658
 
5608
5659
  // src/apis/platform/adapter/instance.ts
5609
- import axios18 from "axios";
5660
+ import axios19 from "axios";
5610
5661
  var REGION2 = {
5611
5662
  FRA: "fra",
5612
5663
  DAL: "dal",
@@ -5636,7 +5687,7 @@ var AdapterApiError = class _AdapterApiError extends ApiErrorBase {
5636
5687
  );
5637
5688
  }
5638
5689
  };
5639
- var platformAdapterClientInstance = axios18.create({
5690
+ var platformAdapterClientInstance = axios19.create({
5640
5691
  baseURL: "https://platform.labs.text.com/console-adapter/api",
5641
5692
  headers: {
5642
5693
  "Content-Type": "application/json"
@@ -6356,9 +6407,79 @@ var WorkflowDefinitionTaskType = {
6356
6407
  addTrigger: "ADD_TRIGGER"
6357
6408
  };
6358
6409
 
6410
+ // src/apis/integrations/hubspot/instance.ts
6411
+ import axios20 from "axios";
6412
+ var HubspotApiError = class extends ApiErrorBase {
6413
+ constructor() {
6414
+ super(...arguments);
6415
+ this.name = "hubspot";
6416
+ }
6417
+ };
6418
+ var hubspotClientUrl = `https://api.hubapi.com`;
6419
+ var hubspotClientInstance = axios20.create({
6420
+ headers: {
6421
+ "Content-Type": "application/json"
6422
+ }
6423
+ });
6424
+ hubspotClientInstance.interceptors.response.use(
6425
+ (r) => r,
6426
+ (error) => {
6427
+ var _a, _b, _c, _d;
6428
+ if (axios20.isAxiosError(error)) {
6429
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
6430
+ throw new UnauthorizeApiError("hubspot");
6431
+ }
6432
+ }
6433
+ return Promise.reject(
6434
+ new HubspotApiError(
6435
+ error.message,
6436
+ (_b = error.response) == null ? void 0 : _b.data,
6437
+ (_d = (_c = error.response) == null ? void 0 : _c.status) != null ? _d : 400
6438
+ )
6439
+ );
6440
+ }
6441
+ );
6442
+ function getHubspotClientAuthorization(req) {
6443
+ if (req.headers instanceof Headers) {
6444
+ return {
6445
+ token: req.headers.get("x-adapter-hubspot-token")
6446
+ };
6447
+ }
6448
+ return {
6449
+ token: req.headers["x-adapter-hubspot-token"]
6450
+ };
6451
+ }
6452
+ function getHubspotClientConfig(options = {}) {
6453
+ var _a;
6454
+ const currentHeaders = hubspotClientInstance.defaults.headers;
6455
+ const config = {
6456
+ authorization: (_a = options.token ? `Bearer ${options.token}` : void 0) != null ? _a : currentHeaders.Authorization
6457
+ };
6458
+ if (options.ensureAuthorizationToken && !config.authorization) {
6459
+ throw new UnauthorizeApiError("hubspot");
6460
+ }
6461
+ return {
6462
+ headers: __spreadValues({}, config.authorization ? { Authorization: config.authorization } : {})
6463
+ };
6464
+ }
6465
+ function initHubspotClient(token) {
6466
+ if (token) {
6467
+ updateHubspotClient(token);
6468
+ }
6469
+ }
6470
+ function updateHubspotClient(token) {
6471
+ const defaults = hubspotClientInstance.defaults;
6472
+ const headers = defaults.headers;
6473
+ if (token) {
6474
+ headers.Authorization = `Bearer ${token}`;
6475
+ } else {
6476
+ delete headers.Authorization;
6477
+ }
6478
+ }
6479
+
6359
6480
  // src/apis/platform/billing/instance.ts
6360
- import axios19 from "axios";
6361
- var platformBillingClientInstance = axios19.create({
6481
+ import axios21 from "axios";
6482
+ var platformBillingClientInstance = axios21.create({
6362
6483
  baseURL: "https://billing.labs.livechatinc.com"
6363
6484
  });
6364
6485
  function getPlatformBillingClientAuthorization(req) {
@@ -6399,7 +6520,7 @@ function initPlatformBillingClient(baseUrl, token) {
6399
6520
  }
6400
6521
 
6401
6522
  // src/apis/platform/adapter/integrations/_contracts/requests/events.ts
6402
- import { z as z4 } from "zod";
6523
+ import { z as z5 } from "zod";
6403
6524
 
6404
6525
  // src/apis/platform/adapter/integrations/shopify/_contracts/dtos/events.ts
6405
6526
  var ShopifyEventNames = /* @__PURE__ */ ((ShopifyEventNames2) => {
@@ -6618,34 +6739,93 @@ var textLivechatEventsZods = {
6618
6739
  }
6619
6740
  };
6620
6741
 
6742
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/requests/events.ts
6743
+ import { z as z4 } from "zod";
6744
+
6745
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/dtos/events.ts
6746
+ var HubspotEventNames = /* @__PURE__ */ ((HubspotEventNames2) => {
6747
+ HubspotEventNames2["SomeEvent"] = "some_event";
6748
+ return HubspotEventNames2;
6749
+ })(HubspotEventNames || {});
6750
+
6751
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/requests/events.ts
6752
+ var hubspotEventsZods = {
6753
+ provider: z4.literal("hubspot"),
6754
+ eventName: z4.nativeEnum(HubspotEventNames),
6755
+ events: {
6756
+ someEvent: z4.object({
6757
+ name: z4.literal("some_event" /* SomeEvent */)
6758
+ })
6759
+ },
6760
+ get event() {
6761
+ return z4.discriminatedUnion("name", [this.events.someEvent]);
6762
+ },
6763
+ get source() {
6764
+ return z4.object({
6765
+ sourceName: z4.enum(["apps", "workflows"]),
6766
+ sourceKey: z4.string()
6767
+ });
6768
+ },
6769
+ get subscribe() {
6770
+ return this.source.and(
6771
+ z4.object({
6772
+ event: this.event,
6773
+ callback: z4.string()
6774
+ })
6775
+ );
6776
+ },
6777
+ get subscribeContent() {
6778
+ return z4.object({
6779
+ provider: this.provider,
6780
+ event: this.event,
6781
+ listId: z4.string()
6782
+ });
6783
+ },
6784
+ get unsubscribe() {
6785
+ return this.source.and(
6786
+ z4.object({
6787
+ event: this.eventName
6788
+ })
6789
+ );
6790
+ },
6791
+ get unsubscribeContent() {
6792
+ return z4.object({
6793
+ provider: this.provider,
6794
+ event: this.eventName
6795
+ });
6796
+ }
6797
+ };
6798
+
6621
6799
  // src/apis/platform/adapter/integrations/_contracts/requests/events.ts
6622
6800
  var integrationEventsZods = {
6623
- sourceName: z4.enum(["apps", "workflows"]),
6624
- providerName: z4.enum(["text-livechat", "mailchimp", "shopify"]),
6801
+ sourceName: z5.enum(["apps", "workflows"]),
6802
+ providerName: z5.enum(["text-livechat", "mailchimp", "shopify", "hubspot"]),
6625
6803
  get event() {
6626
- return textLivechatEventsZods.event.or(shopifyEventsZods.event).or(mailchimpEventsZods.event);
6804
+ return textLivechatEventsZods.event.or(shopifyEventsZods.event).or(mailchimpEventsZods.event).or(hubspotEventsZods.event);
6627
6805
  },
6628
6806
  get source() {
6629
- return z4.object({
6807
+ return z5.object({
6630
6808
  sourceName: this.sourceName,
6631
- sourceKey: z4.string()
6809
+ sourceKey: z5.string()
6632
6810
  });
6633
6811
  },
6634
6812
  get subscribe() {
6635
6813
  return this.source.and(
6636
- z4.discriminatedUnion("provider", [
6814
+ z5.discriminatedUnion("provider", [
6637
6815
  textLivechatEventsZods.subscribeContent,
6638
6816
  shopifyEventsZods.subscribeContent,
6639
- mailchimpEventsZods.subscribeContent
6817
+ mailchimpEventsZods.subscribeContent,
6818
+ hubspotEventsZods.subscribeContent
6640
6819
  ])
6641
6820
  );
6642
6821
  },
6643
6822
  get unsubscribe() {
6644
6823
  return this.source.and(
6645
- z4.discriminatedUnion("provider", [
6824
+ z5.discriminatedUnion("provider", [
6646
6825
  textLivechatEventsZods.unsubscribeContent,
6647
6826
  shopifyEventsZods.unsubscribeContent,
6648
- mailchimpEventsZods.unsubscribeContent
6827
+ mailchimpEventsZods.unsubscribeContent,
6828
+ hubspotEventsZods.unsubscribeContent
6649
6829
  ])
6650
6830
  );
6651
6831
  }
@@ -6974,6 +7154,8 @@ export {
6974
7154
  ApiClient,
6975
7155
  ApiErrorBase,
6976
7156
  DpsApiError,
7157
+ HubspotApiError,
7158
+ HubspotEventNames,
6977
7159
  LivechatApiError,
6978
7160
  MailchimpApiError,
6979
7161
  MailchimpEventNames,
@@ -6998,6 +7180,8 @@ export {
6998
7180
  getEmptyAppAutoReview,
6999
7181
  getGitHubClientAuthorization,
7000
7182
  getGithubClientConfig,
7183
+ getHubspotClientAuthorization,
7184
+ getHubspotClientConfig,
7001
7185
  getIntegrationFlowUrl,
7002
7186
  getLiveChatClientAuthorization,
7003
7187
  getLiveChatClientConfig,
@@ -7028,8 +7212,12 @@ export {
7028
7212
  getVercelClientAuthorization,
7029
7213
  getVercelClientConfig,
7030
7214
  githubClientInstance,
7215
+ hubspotClientInstance,
7216
+ hubspotClientUrl,
7217
+ hubspotEventsZods,
7031
7218
  initApi,
7032
7219
  initGithubClient,
7220
+ initHubspotClient,
7033
7221
  initLiveChatClient,
7034
7222
  initMailchimpClient,
7035
7223
  initNeonClient,
@@ -7058,6 +7246,7 @@ export {
7058
7246
  textClientInstance,
7059
7247
  textLivechatEventsZods,
7060
7248
  updateGithubClient,
7249
+ updateHubspotClient,
7061
7250
  updateMailchimpClient,
7062
7251
  updateNeonClient,
7063
7252
  updateNetlifyClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livechat/developer-studio-api",
3
- "version": "3.1.18",
3
+ "version": "3.1.20",
4
4
  "description": "This project is API for LiveChat Developer Studio.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",