@livechat/developer-studio-api 3.1.19 → 3.1.21

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(
@@ -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) {
@@ -6398,8 +6519,29 @@ function initPlatformBillingClient(baseUrl, token) {
6398
6519
  }
6399
6520
  }
6400
6521
 
6522
+ // src/apis/platform/adapter/integrations/_contracts/dtos/flow.ts
6523
+ var IntegrationNames = /* @__PURE__ */ ((IntegrationNames2) => {
6524
+ IntegrationNames2["Accounts"] = "accounts";
6525
+ IntegrationNames2["GitHub"] = "github";
6526
+ IntegrationNames2["Netlify"] = "netlify";
6527
+ IntegrationNames2["Vercel"] = "vercel";
6528
+ IntegrationNames2["PlanetScale"] = "planetscale";
6529
+ IntegrationNames2["Neon"] = "neon";
6530
+ IntegrationNames2["Mailchimp"] = "mailchimp";
6531
+ IntegrationNames2["Shopify"] = "shopify";
6532
+ IntegrationNames2["BigCommerce"] = "bigcommerce";
6533
+ IntegrationNames2["HubSpot"] = "hubspot";
6534
+ IntegrationNames2["Text"] = "text";
6535
+ return IntegrationNames2;
6536
+ })(IntegrationNames || {});
6537
+ var IntegrationModes = /* @__PURE__ */ ((IntegrationModes2) => {
6538
+ IntegrationModes2["Redirect"] = "redirect";
6539
+ IntegrationModes2["Modal"] = "modal";
6540
+ return IntegrationModes2;
6541
+ })(IntegrationModes || {});
6542
+
6401
6543
  // src/apis/platform/adapter/integrations/_contracts/requests/events.ts
6402
- import { z as z4 } from "zod";
6544
+ import { z as z5 } from "zod";
6403
6545
 
6404
6546
  // src/apis/platform/adapter/integrations/shopify/_contracts/dtos/events.ts
6405
6547
  var ShopifyEventNames = /* @__PURE__ */ ((ShopifyEventNames2) => {
@@ -6618,34 +6760,93 @@ var textLivechatEventsZods = {
6618
6760
  }
6619
6761
  };
6620
6762
 
6763
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/requests/events.ts
6764
+ import { z as z4 } from "zod";
6765
+
6766
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/dtos/events.ts
6767
+ var HubspotEventNames = /* @__PURE__ */ ((HubspotEventNames2) => {
6768
+ HubspotEventNames2["SomeEvent"] = "some_event";
6769
+ return HubspotEventNames2;
6770
+ })(HubspotEventNames || {});
6771
+
6772
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/requests/events.ts
6773
+ var hubspotEventsZods = {
6774
+ provider: z4.literal("hubspot"),
6775
+ eventName: z4.nativeEnum(HubspotEventNames),
6776
+ events: {
6777
+ someEvent: z4.object({
6778
+ name: z4.literal("some_event" /* SomeEvent */)
6779
+ })
6780
+ },
6781
+ get event() {
6782
+ return z4.discriminatedUnion("name", [this.events.someEvent]);
6783
+ },
6784
+ get source() {
6785
+ return z4.object({
6786
+ sourceName: z4.enum(["apps", "workflows"]),
6787
+ sourceKey: z4.string()
6788
+ });
6789
+ },
6790
+ get subscribe() {
6791
+ return this.source.and(
6792
+ z4.object({
6793
+ event: this.event,
6794
+ callback: z4.string()
6795
+ })
6796
+ );
6797
+ },
6798
+ get subscribeContent() {
6799
+ return z4.object({
6800
+ provider: this.provider,
6801
+ event: this.event,
6802
+ listId: z4.string()
6803
+ });
6804
+ },
6805
+ get unsubscribe() {
6806
+ return this.source.and(
6807
+ z4.object({
6808
+ event: this.eventName
6809
+ })
6810
+ );
6811
+ },
6812
+ get unsubscribeContent() {
6813
+ return z4.object({
6814
+ provider: this.provider,
6815
+ event: this.eventName
6816
+ });
6817
+ }
6818
+ };
6819
+
6621
6820
  // src/apis/platform/adapter/integrations/_contracts/requests/events.ts
6622
6821
  var integrationEventsZods = {
6623
- sourceName: z4.enum(["apps", "workflows"]),
6624
- providerName: z4.enum(["text-livechat", "mailchimp", "shopify"]),
6822
+ sourceName: z5.enum(["apps", "workflows"]),
6823
+ providerName: z5.enum(["text-livechat", "mailchimp", "shopify", "hubspot"]),
6625
6824
  get event() {
6626
- return textLivechatEventsZods.event.or(shopifyEventsZods.event).or(mailchimpEventsZods.event);
6825
+ return textLivechatEventsZods.event.or(shopifyEventsZods.event).or(mailchimpEventsZods.event).or(hubspotEventsZods.event);
6627
6826
  },
6628
6827
  get source() {
6629
- return z4.object({
6828
+ return z5.object({
6630
6829
  sourceName: this.sourceName,
6631
- sourceKey: z4.string()
6830
+ sourceKey: z5.string()
6632
6831
  });
6633
6832
  },
6634
6833
  get subscribe() {
6635
6834
  return this.source.and(
6636
- z4.discriminatedUnion("provider", [
6835
+ z5.discriminatedUnion("provider", [
6637
6836
  textLivechatEventsZods.subscribeContent,
6638
6837
  shopifyEventsZods.subscribeContent,
6639
- mailchimpEventsZods.subscribeContent
6838
+ mailchimpEventsZods.subscribeContent,
6839
+ hubspotEventsZods.subscribeContent
6640
6840
  ])
6641
6841
  );
6642
6842
  },
6643
6843
  get unsubscribe() {
6644
6844
  return this.source.and(
6645
- z4.discriminatedUnion("provider", [
6845
+ z5.discriminatedUnion("provider", [
6646
6846
  textLivechatEventsZods.unsubscribeContent,
6647
6847
  shopifyEventsZods.unsubscribeContent,
6648
- mailchimpEventsZods.unsubscribeContent
6848
+ mailchimpEventsZods.unsubscribeContent,
6849
+ hubspotEventsZods.unsubscribeContent
6649
6850
  ])
6650
6851
  );
6651
6852
  }
@@ -6960,13 +7161,54 @@ var serializerBase64 = {
6960
7161
  };
6961
7162
 
6962
7163
  // src/utils/integrations/getIntegrationFlowUrl.ts
6963
- function getIntegrationFlowUrl(provider, flow, data, context, config) {
7164
+ function getIntegrationFlowUrlOld(provider, flow, data, context, config) {
6964
7165
  const serializedFlowState = typeof data === "string" ? data : serializerBase64.serialize(data);
6965
7166
  const serializedContext = serializerBase64.serialize(__spreadProps(__spreadValues({}, context), {
7167
+ mode: "redirect" /* Redirect */,
6966
7168
  state: serializedFlowState
6967
7169
  }));
6968
7170
  return `${config.adapterUrl}/integrations/${provider}/flow?flow=${flow}&context=${serializedContext}`;
6969
7171
  }
7172
+ function getIntegrationFlowUrl(name, flow, trigger, context, state, config) {
7173
+ return __async(this, null, function* () {
7174
+ const serializedState = typeof state === "string" ? state : serializerBase64.serialize(state);
7175
+ const serializedContext = serializerBase64.serialize(__spreadValues(__spreadValues({
7176
+ state: serializedState,
7177
+ userId: config.user.id,
7178
+ userToken: config.user.token
7179
+ }, trigger), context));
7180
+ const url = `${config.urls.adapterUrl}/integrations/${name}/flow?flow=${flow}&context=${serializedContext}`;
7181
+ if (trigger.mode === "modal" /* Modal */) {
7182
+ const newWindow = window.open(
7183
+ url,
7184
+ "_blank",
7185
+ "location=no,height=800,width=800,scrollbars=no,status=no"
7186
+ );
7187
+ return new Promise((resolve) => {
7188
+ const observer = setInterval(() => {
7189
+ if (newWindow == null ? void 0 : newWindow.closed) {
7190
+ clearInterval(observer);
7191
+ resolve({
7192
+ status: "cancel"
7193
+ });
7194
+ }
7195
+ }, 1e3);
7196
+ window.addEventListener(
7197
+ "message",
7198
+ (event) => {
7199
+ var _a;
7200
+ if (((_a = event.data) == null ? void 0 : _a.type) === "adapter" && event.data.output) {
7201
+ newWindow == null ? void 0 : newWindow.close();
7202
+ clearInterval(observer);
7203
+ resolve(event.data.output);
7204
+ }
7205
+ }
7206
+ );
7207
+ });
7208
+ }
7209
+ window.location.href = url;
7210
+ });
7211
+ }
6970
7212
  export {
6971
7213
  API_NOTIFICATIONS,
6972
7214
  AccountsApiError,
@@ -6974,6 +7216,10 @@ export {
6974
7216
  ApiClient,
6975
7217
  ApiErrorBase,
6976
7218
  DpsApiError,
7219
+ HubspotApiError,
7220
+ HubspotEventNames,
7221
+ IntegrationModes,
7222
+ IntegrationNames,
6977
7223
  LivechatApiError,
6978
7224
  MailchimpApiError,
6979
7225
  MailchimpEventNames,
@@ -6998,7 +7244,10 @@ export {
6998
7244
  getEmptyAppAutoReview,
6999
7245
  getGitHubClientAuthorization,
7000
7246
  getGithubClientConfig,
7247
+ getHubspotClientAuthorization,
7248
+ getHubspotClientConfig,
7001
7249
  getIntegrationFlowUrl,
7250
+ getIntegrationFlowUrlOld,
7002
7251
  getLiveChatClientAuthorization,
7003
7252
  getLiveChatClientConfig,
7004
7253
  getMailchimpClientAuthorization,
@@ -7028,8 +7277,12 @@ export {
7028
7277
  getVercelClientAuthorization,
7029
7278
  getVercelClientConfig,
7030
7279
  githubClientInstance,
7280
+ hubspotClientInstance,
7281
+ hubspotClientUrl,
7282
+ hubspotEventsZods,
7031
7283
  initApi,
7032
7284
  initGithubClient,
7285
+ initHubspotClient,
7033
7286
  initLiveChatClient,
7034
7287
  initMailchimpClient,
7035
7288
  initNeonClient,
@@ -7058,6 +7311,7 @@ export {
7058
7311
  textClientInstance,
7059
7312
  textLivechatEventsZods,
7060
7313
  updateGithubClient,
7314
+ updateHubspotClient,
7061
7315
  updateMailchimpClient,
7062
7316
  updateNeonClient,
7063
7317
  updateNetlifyClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livechat/developer-studio-api",
3
- "version": "3.1.19",
3
+ "version": "3.1.21",
4
4
  "description": "This project is API for LiveChat Developer Studio.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "@types/node": "^17.0.12",
21
21
  "tsup": "^7.1.0",
22
22
  "typescript": "^5.1.6",
23
+ "utils": "0.0.4",
23
24
  "eslint-config-custom": "0.0.8",
24
- "tsconfig": "0.0.1",
25
- "utils": "0.0.4"
25
+ "tsconfig": "0.0.1"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsup",