@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.js CHANGED
@@ -73,6 +73,10 @@ __export(src_exports, {
73
73
  ApiClient: () => ApiClient,
74
74
  ApiErrorBase: () => ApiErrorBase,
75
75
  DpsApiError: () => DpsApiError,
76
+ HubspotApiError: () => HubspotApiError,
77
+ HubspotEventNames: () => HubspotEventNames,
78
+ IntegrationModes: () => IntegrationModes,
79
+ IntegrationNames: () => IntegrationNames,
76
80
  LivechatApiError: () => LivechatApiError,
77
81
  MailchimpApiError: () => MailchimpApiError,
78
82
  MailchimpEventNames: () => MailchimpEventNames,
@@ -97,7 +101,10 @@ __export(src_exports, {
97
101
  getEmptyAppAutoReview: () => getEmptyAppAutoReview,
98
102
  getGitHubClientAuthorization: () => getGitHubClientAuthorization,
99
103
  getGithubClientConfig: () => getGithubClientConfig,
104
+ getHubspotClientAuthorization: () => getHubspotClientAuthorization,
105
+ getHubspotClientConfig: () => getHubspotClientConfig,
100
106
  getIntegrationFlowUrl: () => getIntegrationFlowUrl,
107
+ getIntegrationFlowUrlOld: () => getIntegrationFlowUrlOld,
101
108
  getLiveChatClientAuthorization: () => getLiveChatClientAuthorization,
102
109
  getLiveChatClientConfig: () => getLiveChatClientConfig,
103
110
  getMailchimpClientAuthorization: () => getMailchimpClientAuthorization,
@@ -127,8 +134,12 @@ __export(src_exports, {
127
134
  getVercelClientAuthorization: () => getVercelClientAuthorization,
128
135
  getVercelClientConfig: () => getVercelClientConfig,
129
136
  githubClientInstance: () => githubClientInstance,
137
+ hubspotClientInstance: () => hubspotClientInstance,
138
+ hubspotClientUrl: () => hubspotClientUrl,
139
+ hubspotEventsZods: () => hubspotEventsZods,
130
140
  initApi: () => initApi,
131
141
  initGithubClient: () => initGithubClient,
142
+ initHubspotClient: () => initHubspotClient,
132
143
  initLiveChatClient: () => initLiveChatClient,
133
144
  initMailchimpClient: () => initMailchimpClient,
134
145
  initNeonClient: () => initNeonClient,
@@ -157,6 +168,7 @@ __export(src_exports, {
157
168
  textClientInstance: () => textClientInstance,
158
169
  textLivechatEventsZods: () => textLivechatEventsZods,
159
170
  updateGithubClient: () => updateGithubClient,
171
+ updateHubspotClient: () => updateHubspotClient,
160
172
  updateMailchimpClient: () => updateMailchimpClient,
161
173
  updateNeonClient: () => updateNeonClient,
162
174
  updateNetlifyClient: () => updateNetlifyClient,
@@ -2938,7 +2950,7 @@ function getMailchimpClientConfig(options = {}) {
2938
2950
  }
2939
2951
  function initMailchimpClient(token, server) {
2940
2952
  if (token && server) {
2941
- updateMailchimpClient(token);
2953
+ updateMailchimpClient(token, server);
2942
2954
  }
2943
2955
  }
2944
2956
  function updateMailchimpClient(token, server) {
@@ -3199,6 +3211,56 @@ var shopifyApi = {
3199
3211
  }
3200
3212
  };
3201
3213
 
3214
+ // src/apis/integrations/hubspot/api.ts
3215
+ var import_axios18 = __toESM(require("axios"));
3216
+ var hubspotApi = {
3217
+ getToken(code, clientId, clientSecret, redirectUri) {
3218
+ return __async(this, null, function* () {
3219
+ var _a;
3220
+ const data = new URLSearchParams({
3221
+ code,
3222
+ client_id: clientId,
3223
+ client_secret: clientSecret,
3224
+ redirect_uri: redirectUri,
3225
+ grant_type: "authorization_code"
3226
+ });
3227
+ const tokenResponse = yield import_axios18.default.post(
3228
+ "https://api.hubapi.com/oauth/v1/token",
3229
+ data,
3230
+ {
3231
+ headers: {
3232
+ "Content-Type": "application/x-www-form-urlencoded"
3233
+ }
3234
+ }
3235
+ );
3236
+ const params = new URLSearchParams(
3237
+ tokenResponse.data
3238
+ );
3239
+ return {
3240
+ token: (_a = params.get("access_token")) != null ? _a : ""
3241
+ };
3242
+ });
3243
+ },
3244
+ getMetadata(_0) {
3245
+ return __async(this, arguments, function* ({ token }) {
3246
+ const {
3247
+ data: { dc: server }
3248
+ } = yield import_axios18.default.get(
3249
+ "https://login.mailchimp.com/oauth2/metadata",
3250
+ {
3251
+ headers: {
3252
+ "Content-Type": "application/json",
3253
+ Authorization: `OAuth ${token}`
3254
+ }
3255
+ }
3256
+ );
3257
+ return {
3258
+ server
3259
+ };
3260
+ });
3261
+ }
3262
+ };
3263
+
3202
3264
  // src/apis/integrations/api.ts
3203
3265
  var integrationsApi = {
3204
3266
  github: gitHubApi,
@@ -3208,11 +3270,12 @@ var integrationsApi = {
3208
3270
  shopify: shopifyApi,
3209
3271
  neon: neonApi,
3210
3272
  planetscale: planetscaleApi,
3273
+ hubspot: hubspotApi,
3211
3274
  text: textApi
3212
3275
  };
3213
3276
 
3214
3277
  // src/apis/products/livechat/instance.ts
3215
- var import_axios18 = __toESM(require("axios"));
3278
+ var import_axios19 = __toESM(require("axios"));
3216
3279
  var REGION = {
3217
3280
  FRA: "fra",
3218
3281
  DAL: "dal",
@@ -3232,7 +3295,7 @@ var LivechatApiError = class extends ApiErrorBase {
3232
3295
  this.name = "livechat";
3233
3296
  }
3234
3297
  };
3235
- var livechatClientInstance = import_axios18.default.create({
3298
+ var livechatClientInstance = import_axios19.default.create({
3236
3299
  baseURL: "https://api.labs.livechatinc.com"
3237
3300
  });
3238
3301
  livechatClientInstance.interceptors.response.use(
@@ -4127,14 +4190,14 @@ var platformAccountsApi = {
4127
4190
  };
4128
4191
 
4129
4192
  // src/apis/platform/dps/instance.ts
4130
- var import_axios19 = __toESM(require("axios"));
4193
+ var import_axios20 = __toESM(require("axios"));
4131
4194
  var DpsApiError = class extends ApiErrorBase {
4132
4195
  constructor() {
4133
4196
  super(...arguments);
4134
4197
  this.name = "dps";
4135
4198
  }
4136
4199
  };
4137
- var platformDpsClientInstance = import_axios19.default.create({
4200
+ var platformDpsClientInstance = import_axios20.default.create({
4138
4201
  baseURL: "https://dev-platform.labs.livechatinc.com"
4139
4202
  });
4140
4203
  platformDpsClientInstance.interceptors.response.use(
@@ -5737,7 +5800,7 @@ var platformDpsApi = {
5737
5800
  };
5738
5801
 
5739
5802
  // src/apis/platform/adapter/instance.ts
5740
- var import_axios20 = __toESM(require("axios"));
5803
+ var import_axios21 = __toESM(require("axios"));
5741
5804
  var REGION2 = {
5742
5805
  FRA: "fra",
5743
5806
  DAL: "dal",
@@ -5767,7 +5830,7 @@ var AdapterApiError = class _AdapterApiError extends ApiErrorBase {
5767
5830
  );
5768
5831
  }
5769
5832
  };
5770
- var platformAdapterClientInstance = import_axios20.default.create({
5833
+ var platformAdapterClientInstance = import_axios21.default.create({
5771
5834
  baseURL: "https://platform.labs.text.com/console-adapter/api",
5772
5835
  headers: {
5773
5836
  "Content-Type": "application/json"
@@ -6487,9 +6550,79 @@ var WorkflowDefinitionTaskType = {
6487
6550
  addTrigger: "ADD_TRIGGER"
6488
6551
  };
6489
6552
 
6553
+ // src/apis/integrations/hubspot/instance.ts
6554
+ var import_axios22 = __toESM(require("axios"));
6555
+ var HubspotApiError = class extends ApiErrorBase {
6556
+ constructor() {
6557
+ super(...arguments);
6558
+ this.name = "hubspot";
6559
+ }
6560
+ };
6561
+ var hubspotClientUrl = `https://api.hubapi.com`;
6562
+ var hubspotClientInstance = import_axios22.default.create({
6563
+ headers: {
6564
+ "Content-Type": "application/json"
6565
+ }
6566
+ });
6567
+ hubspotClientInstance.interceptors.response.use(
6568
+ (r) => r,
6569
+ (error) => {
6570
+ var _a, _b, _c, _d;
6571
+ if (import_axios22.default.isAxiosError(error)) {
6572
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
6573
+ throw new UnauthorizeApiError("hubspot");
6574
+ }
6575
+ }
6576
+ return Promise.reject(
6577
+ new HubspotApiError(
6578
+ error.message,
6579
+ (_b = error.response) == null ? void 0 : _b.data,
6580
+ (_d = (_c = error.response) == null ? void 0 : _c.status) != null ? _d : 400
6581
+ )
6582
+ );
6583
+ }
6584
+ );
6585
+ function getHubspotClientAuthorization(req) {
6586
+ if (req.headers instanceof Headers) {
6587
+ return {
6588
+ token: req.headers.get("x-adapter-hubspot-token")
6589
+ };
6590
+ }
6591
+ return {
6592
+ token: req.headers["x-adapter-hubspot-token"]
6593
+ };
6594
+ }
6595
+ function getHubspotClientConfig(options = {}) {
6596
+ var _a;
6597
+ const currentHeaders = hubspotClientInstance.defaults.headers;
6598
+ const config = {
6599
+ authorization: (_a = options.token ? `Bearer ${options.token}` : void 0) != null ? _a : currentHeaders.Authorization
6600
+ };
6601
+ if (options.ensureAuthorizationToken && !config.authorization) {
6602
+ throw new UnauthorizeApiError("hubspot");
6603
+ }
6604
+ return {
6605
+ headers: __spreadValues({}, config.authorization ? { Authorization: config.authorization } : {})
6606
+ };
6607
+ }
6608
+ function initHubspotClient(token) {
6609
+ if (token) {
6610
+ updateHubspotClient(token);
6611
+ }
6612
+ }
6613
+ function updateHubspotClient(token) {
6614
+ const defaults = hubspotClientInstance.defaults;
6615
+ const headers = defaults.headers;
6616
+ if (token) {
6617
+ headers.Authorization = `Bearer ${token}`;
6618
+ } else {
6619
+ delete headers.Authorization;
6620
+ }
6621
+ }
6622
+
6490
6623
  // src/apis/platform/billing/instance.ts
6491
- var import_axios21 = __toESM(require("axios"));
6492
- var platformBillingClientInstance = import_axios21.default.create({
6624
+ var import_axios23 = __toESM(require("axios"));
6625
+ var platformBillingClientInstance = import_axios23.default.create({
6493
6626
  baseURL: "https://billing.labs.livechatinc.com"
6494
6627
  });
6495
6628
  function getPlatformBillingClientAuthorization(req) {
@@ -6529,8 +6662,29 @@ function initPlatformBillingClient(baseUrl, token) {
6529
6662
  }
6530
6663
  }
6531
6664
 
6665
+ // src/apis/platform/adapter/integrations/_contracts/dtos/flow.ts
6666
+ var IntegrationNames = /* @__PURE__ */ ((IntegrationNames2) => {
6667
+ IntegrationNames2["Accounts"] = "accounts";
6668
+ IntegrationNames2["GitHub"] = "github";
6669
+ IntegrationNames2["Netlify"] = "netlify";
6670
+ IntegrationNames2["Vercel"] = "vercel";
6671
+ IntegrationNames2["PlanetScale"] = "planetscale";
6672
+ IntegrationNames2["Neon"] = "neon";
6673
+ IntegrationNames2["Mailchimp"] = "mailchimp";
6674
+ IntegrationNames2["Shopify"] = "shopify";
6675
+ IntegrationNames2["BigCommerce"] = "bigcommerce";
6676
+ IntegrationNames2["HubSpot"] = "hubspot";
6677
+ IntegrationNames2["Text"] = "text";
6678
+ return IntegrationNames2;
6679
+ })(IntegrationNames || {});
6680
+ var IntegrationModes = /* @__PURE__ */ ((IntegrationModes2) => {
6681
+ IntegrationModes2["Redirect"] = "redirect";
6682
+ IntegrationModes2["Modal"] = "modal";
6683
+ return IntegrationModes2;
6684
+ })(IntegrationModes || {});
6685
+
6532
6686
  // src/apis/platform/adapter/integrations/_contracts/requests/events.ts
6533
- var import_zod4 = require("zod");
6687
+ var import_zod5 = require("zod");
6534
6688
 
6535
6689
  // src/apis/platform/adapter/integrations/shopify/_contracts/dtos/events.ts
6536
6690
  var ShopifyEventNames = /* @__PURE__ */ ((ShopifyEventNames2) => {
@@ -6749,34 +6903,93 @@ var textLivechatEventsZods = {
6749
6903
  }
6750
6904
  };
6751
6905
 
6906
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/requests/events.ts
6907
+ var import_zod4 = require("zod");
6908
+
6909
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/dtos/events.ts
6910
+ var HubspotEventNames = /* @__PURE__ */ ((HubspotEventNames2) => {
6911
+ HubspotEventNames2["SomeEvent"] = "some_event";
6912
+ return HubspotEventNames2;
6913
+ })(HubspotEventNames || {});
6914
+
6915
+ // src/apis/platform/adapter/integrations/hubspot/_contracts/requests/events.ts
6916
+ var hubspotEventsZods = {
6917
+ provider: import_zod4.z.literal("hubspot"),
6918
+ eventName: import_zod4.z.nativeEnum(HubspotEventNames),
6919
+ events: {
6920
+ someEvent: import_zod4.z.object({
6921
+ name: import_zod4.z.literal("some_event" /* SomeEvent */)
6922
+ })
6923
+ },
6924
+ get event() {
6925
+ return import_zod4.z.discriminatedUnion("name", [this.events.someEvent]);
6926
+ },
6927
+ get source() {
6928
+ return import_zod4.z.object({
6929
+ sourceName: import_zod4.z.enum(["apps", "workflows"]),
6930
+ sourceKey: import_zod4.z.string()
6931
+ });
6932
+ },
6933
+ get subscribe() {
6934
+ return this.source.and(
6935
+ import_zod4.z.object({
6936
+ event: this.event,
6937
+ callback: import_zod4.z.string()
6938
+ })
6939
+ );
6940
+ },
6941
+ get subscribeContent() {
6942
+ return import_zod4.z.object({
6943
+ provider: this.provider,
6944
+ event: this.event,
6945
+ listId: import_zod4.z.string()
6946
+ });
6947
+ },
6948
+ get unsubscribe() {
6949
+ return this.source.and(
6950
+ import_zod4.z.object({
6951
+ event: this.eventName
6952
+ })
6953
+ );
6954
+ },
6955
+ get unsubscribeContent() {
6956
+ return import_zod4.z.object({
6957
+ provider: this.provider,
6958
+ event: this.eventName
6959
+ });
6960
+ }
6961
+ };
6962
+
6752
6963
  // src/apis/platform/adapter/integrations/_contracts/requests/events.ts
6753
6964
  var integrationEventsZods = {
6754
- sourceName: import_zod4.z.enum(["apps", "workflows"]),
6755
- providerName: import_zod4.z.enum(["text-livechat", "mailchimp", "shopify"]),
6965
+ sourceName: import_zod5.z.enum(["apps", "workflows"]),
6966
+ providerName: import_zod5.z.enum(["text-livechat", "mailchimp", "shopify", "hubspot"]),
6756
6967
  get event() {
6757
- return textLivechatEventsZods.event.or(shopifyEventsZods.event).or(mailchimpEventsZods.event);
6968
+ return textLivechatEventsZods.event.or(shopifyEventsZods.event).or(mailchimpEventsZods.event).or(hubspotEventsZods.event);
6758
6969
  },
6759
6970
  get source() {
6760
- return import_zod4.z.object({
6971
+ return import_zod5.z.object({
6761
6972
  sourceName: this.sourceName,
6762
- sourceKey: import_zod4.z.string()
6973
+ sourceKey: import_zod5.z.string()
6763
6974
  });
6764
6975
  },
6765
6976
  get subscribe() {
6766
6977
  return this.source.and(
6767
- import_zod4.z.discriminatedUnion("provider", [
6978
+ import_zod5.z.discriminatedUnion("provider", [
6768
6979
  textLivechatEventsZods.subscribeContent,
6769
6980
  shopifyEventsZods.subscribeContent,
6770
- mailchimpEventsZods.subscribeContent
6981
+ mailchimpEventsZods.subscribeContent,
6982
+ hubspotEventsZods.subscribeContent
6771
6983
  ])
6772
6984
  );
6773
6985
  },
6774
6986
  get unsubscribe() {
6775
6987
  return this.source.and(
6776
- import_zod4.z.discriminatedUnion("provider", [
6988
+ import_zod5.z.discriminatedUnion("provider", [
6777
6989
  textLivechatEventsZods.unsubscribeContent,
6778
6990
  shopifyEventsZods.unsubscribeContent,
6779
- mailchimpEventsZods.unsubscribeContent
6991
+ mailchimpEventsZods.unsubscribeContent,
6992
+ hubspotEventsZods.unsubscribeContent
6780
6993
  ])
6781
6994
  );
6782
6995
  }
@@ -7091,13 +7304,54 @@ var serializerBase64 = {
7091
7304
  };
7092
7305
 
7093
7306
  // src/utils/integrations/getIntegrationFlowUrl.ts
7094
- function getIntegrationFlowUrl(provider, flow, data, context, config) {
7307
+ function getIntegrationFlowUrlOld(provider, flow, data, context, config) {
7095
7308
  const serializedFlowState = typeof data === "string" ? data : serializerBase64.serialize(data);
7096
7309
  const serializedContext = serializerBase64.serialize(__spreadProps(__spreadValues({}, context), {
7310
+ mode: "redirect" /* Redirect */,
7097
7311
  state: serializedFlowState
7098
7312
  }));
7099
7313
  return `${config.adapterUrl}/integrations/${provider}/flow?flow=${flow}&context=${serializedContext}`;
7100
7314
  }
7315
+ function getIntegrationFlowUrl(name, flow, trigger, context, state, config) {
7316
+ return __async(this, null, function* () {
7317
+ const serializedState = typeof state === "string" ? state : serializerBase64.serialize(state);
7318
+ const serializedContext = serializerBase64.serialize(__spreadValues(__spreadValues({
7319
+ state: serializedState,
7320
+ userId: config.user.id,
7321
+ userToken: config.user.token
7322
+ }, trigger), context));
7323
+ const url = `${config.urls.adapterUrl}/integrations/${name}/flow?flow=${flow}&context=${serializedContext}`;
7324
+ if (trigger.mode === "modal" /* Modal */) {
7325
+ const newWindow = window.open(
7326
+ url,
7327
+ "_blank",
7328
+ "location=no,height=800,width=800,scrollbars=no,status=no"
7329
+ );
7330
+ return new Promise((resolve) => {
7331
+ const observer = setInterval(() => {
7332
+ if (newWindow == null ? void 0 : newWindow.closed) {
7333
+ clearInterval(observer);
7334
+ resolve({
7335
+ status: "cancel"
7336
+ });
7337
+ }
7338
+ }, 1e3);
7339
+ window.addEventListener(
7340
+ "message",
7341
+ (event) => {
7342
+ var _a;
7343
+ if (((_a = event.data) == null ? void 0 : _a.type) === "adapter" && event.data.output) {
7344
+ newWindow == null ? void 0 : newWindow.close();
7345
+ clearInterval(observer);
7346
+ resolve(event.data.output);
7347
+ }
7348
+ }
7349
+ );
7350
+ });
7351
+ }
7352
+ window.location.href = url;
7353
+ });
7354
+ }
7101
7355
  // Annotate the CommonJS export names for ESM import in node:
7102
7356
  0 && (module.exports = {
7103
7357
  API_NOTIFICATIONS,
@@ -7106,6 +7360,10 @@ function getIntegrationFlowUrl(provider, flow, data, context, config) {
7106
7360
  ApiClient,
7107
7361
  ApiErrorBase,
7108
7362
  DpsApiError,
7363
+ HubspotApiError,
7364
+ HubspotEventNames,
7365
+ IntegrationModes,
7366
+ IntegrationNames,
7109
7367
  LivechatApiError,
7110
7368
  MailchimpApiError,
7111
7369
  MailchimpEventNames,
@@ -7130,7 +7388,10 @@ function getIntegrationFlowUrl(provider, flow, data, context, config) {
7130
7388
  getEmptyAppAutoReview,
7131
7389
  getGitHubClientAuthorization,
7132
7390
  getGithubClientConfig,
7391
+ getHubspotClientAuthorization,
7392
+ getHubspotClientConfig,
7133
7393
  getIntegrationFlowUrl,
7394
+ getIntegrationFlowUrlOld,
7134
7395
  getLiveChatClientAuthorization,
7135
7396
  getLiveChatClientConfig,
7136
7397
  getMailchimpClientAuthorization,
@@ -7160,8 +7421,12 @@ function getIntegrationFlowUrl(provider, flow, data, context, config) {
7160
7421
  getVercelClientAuthorization,
7161
7422
  getVercelClientConfig,
7162
7423
  githubClientInstance,
7424
+ hubspotClientInstance,
7425
+ hubspotClientUrl,
7426
+ hubspotEventsZods,
7163
7427
  initApi,
7164
7428
  initGithubClient,
7429
+ initHubspotClient,
7165
7430
  initLiveChatClient,
7166
7431
  initMailchimpClient,
7167
7432
  initNeonClient,
@@ -7190,6 +7455,7 @@ function getIntegrationFlowUrl(provider, flow, data, context, config) {
7190
7455
  textClientInstance,
7191
7456
  textLivechatEventsZods,
7192
7457
  updateGithubClient,
7458
+ updateHubspotClient,
7193
7459
  updateMailchimpClient,
7194
7460
  updateNeonClient,
7195
7461
  updateNetlifyClient,