@livechat/developer-studio-api 3.1.27 → 3.1.28

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
@@ -76,6 +76,7 @@ __export(src_exports, {
76
76
  BigCommerceEventNames: () => BigCommerceEventNames,
77
77
  BigCommerceWebhookScopes: () => BigCommerceWebhookScopes,
78
78
  DpsApiError: () => DpsApiError,
79
+ HubSpotWebhookEventTypes: () => HubSpotWebhookEventTypes,
79
80
  HubspotApiError: () => HubspotApiError,
80
81
  HubspotEventNames: () => HubspotEventNames,
81
82
  IntegrationModes: () => IntegrationModes,
@@ -143,7 +144,6 @@ __export(src_exports, {
143
144
  getVercelClientConfig: () => getVercelClientConfig,
144
145
  githubClientInstance: () => githubClientInstance,
145
146
  hubspotClientInstance: () => hubspotClientInstance,
146
- hubspotClientUrl: () => hubspotClientUrl,
147
147
  hubspotEventsZods: () => hubspotEventsZods,
148
148
  initApi: () => initApi,
149
149
  initBigCommerceClient: () => initBigCommerceClient,
@@ -3221,9 +3221,184 @@ var shopifyApi = {
3221
3221
  }
3222
3222
  };
3223
3223
 
3224
- // src/apis/integrations/hubspot/api.ts
3224
+ // src/apis/integrations/hubspot/instance.ts
3225
3225
  var import_axios18 = __toESM(require("axios"));
3226
+ var HubspotApiError = class extends ApiErrorBase {
3227
+ constructor() {
3228
+ super(...arguments);
3229
+ this.name = "hubspot";
3230
+ }
3231
+ };
3232
+ var hubspotClientInstance = import_axios18.default.create({
3233
+ baseURL: `https://api.hubapi.com`,
3234
+ headers: {
3235
+ "Content-Type": "application/json"
3236
+ }
3237
+ });
3238
+ hubspotClientInstance.interceptors.response.use(
3239
+ (r) => r,
3240
+ (error) => {
3241
+ var _a, _b, _c, _d;
3242
+ if (import_axios18.default.isAxiosError(error)) {
3243
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
3244
+ throw new UnauthorizeApiError("hubspot");
3245
+ }
3246
+ }
3247
+ return Promise.reject(
3248
+ new HubspotApiError(
3249
+ error.message,
3250
+ (_b = error.response) == null ? void 0 : _b.data,
3251
+ (_d = (_c = error.response) == null ? void 0 : _c.status) != null ? _d : 400
3252
+ )
3253
+ );
3254
+ }
3255
+ );
3256
+ function getHubspotClientAuthorization(req) {
3257
+ if (req.headers instanceof Headers) {
3258
+ return {
3259
+ token: req.headers.get("x-adapter-hubspot-token")
3260
+ };
3261
+ }
3262
+ return {
3263
+ token: req.headers["x-adapter-hubspot-token"]
3264
+ };
3265
+ }
3266
+ function getHubspotClientConfig(options = {}) {
3267
+ var _a;
3268
+ const currentHeaders = hubspotClientInstance.defaults.headers;
3269
+ const config = {
3270
+ authorization: (_a = options.token ? `Bearer ${options.token}` : void 0) != null ? _a : currentHeaders.Authorization
3271
+ };
3272
+ if (options.ensureAuthorizationToken && !config.authorization) {
3273
+ throw new UnauthorizeApiError("hubspot");
3274
+ }
3275
+ return {
3276
+ headers: __spreadValues({}, config.authorization ? { Authorization: config.authorization } : {})
3277
+ };
3278
+ }
3279
+ function initHubspotClient(token) {
3280
+ if (token) {
3281
+ updateHubspotClient(token);
3282
+ }
3283
+ }
3284
+ function updateHubspotClient(token) {
3285
+ const defaults = hubspotClientInstance.defaults;
3286
+ const headers = defaults.headers;
3287
+ if (token) {
3288
+ headers.Authorization = `Bearer ${token}`;
3289
+ } else {
3290
+ delete headers.Authorization;
3291
+ }
3292
+ }
3293
+
3294
+ // src/apis/integrations/hubspot/webhooks/api.ts
3295
+ var hubspotWebhooksApi = {
3296
+ settings: {
3297
+ get(appId, authorization) {
3298
+ return __async(this, null, function* () {
3299
+ const params = new URLSearchParams(
3300
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3301
+ hapikey: authorization.apiKey
3302
+ } : {}
3303
+ );
3304
+ return hubspotClientInstance.get(
3305
+ `/webhooks/v1/${encodeURIComponent(
3306
+ appId
3307
+ )}/settings?${params.toString()}`
3308
+ // getHubspotClientConfig({
3309
+ // ...authorization,
3310
+ // ensureAuthorizationToken: true,
3311
+ // })
3312
+ ).catch((e) => {
3313
+ console.log(e);
3314
+ throw e;
3315
+ });
3316
+ });
3317
+ },
3318
+ update(appId, payload, authorization) {
3319
+ return __async(this, null, function* () {
3320
+ const params = new URLSearchParams(
3321
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3322
+ hapikey: authorization.apiKey
3323
+ } : {}
3324
+ );
3325
+ return hubspotClientInstance.put(
3326
+ `/webhooks/v1/${encodeURIComponent(
3327
+ appId
3328
+ )}/settings?${params.toString()}`,
3329
+ payload
3330
+ // getHubspotClientConfig({
3331
+ // ...authorization,
3332
+ // ensureAuthorizationToken: true,
3333
+ // })
3334
+ );
3335
+ });
3336
+ }
3337
+ },
3338
+ subscriptions: {
3339
+ list(appId, authorization) {
3340
+ return __async(this, null, function* () {
3341
+ const params = new URLSearchParams(
3342
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3343
+ hapikey: authorization.apiKey
3344
+ } : {}
3345
+ );
3346
+ return hubspotClientInstance.get(
3347
+ `/webhooks/v3/${encodeURIComponent(
3348
+ appId
3349
+ )}/subscriptions?${params.toString()}`
3350
+ // getHubspotClientConfig({
3351
+ // ...authorization,
3352
+ // ensureAuthorizationToken: true,
3353
+ // })
3354
+ );
3355
+ });
3356
+ },
3357
+ register(appId, payload, authorization) {
3358
+ return __async(this, null, function* () {
3359
+ const params = new URLSearchParams(
3360
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3361
+ hapikey: authorization.apiKey
3362
+ } : {}
3363
+ );
3364
+ return hubspotClientInstance.post(
3365
+ `/webhooks/v3/${encodeURIComponent(
3366
+ appId
3367
+ )}/subscriptions?${params.toString()}`,
3368
+ payload
3369
+ // getHubspotClientConfig({
3370
+ // ...authorization,
3371
+ // ensureAuthorizationToken: true,
3372
+ // })
3373
+ );
3374
+ });
3375
+ },
3376
+ unregister(appId, subscriptionId, authorization) {
3377
+ return __async(this, null, function* () {
3378
+ const params = new URLSearchParams(
3379
+ (authorization == null ? void 0 : authorization.apiKey) ? {
3380
+ hapikey: authorization.apiKey
3381
+ } : {}
3382
+ );
3383
+ return hubspotClientInstance.delete(
3384
+ `/webhooks/v3/${encodeURIComponent(
3385
+ appId
3386
+ )}/subscriptions/${encodeURIComponent(
3387
+ subscriptionId
3388
+ )}?${params.toString()}`
3389
+ // getHubspotClientConfig({
3390
+ // ...authorization,
3391
+ // ensureAuthorizationToken: true,
3392
+ // })
3393
+ );
3394
+ });
3395
+ }
3396
+ }
3397
+ };
3398
+
3399
+ // src/apis/integrations/hubspot/api.ts
3226
3400
  var hubspotApi = {
3401
+ webhooks: hubspotWebhooksApi,
3227
3402
  getToken(code, clientId, clientSecret, redirectUri) {
3228
3403
  return __async(this, null, function* () {
3229
3404
  var _a;
@@ -3234,8 +3409,8 @@ var hubspotApi = {
3234
3409
  redirect_uri: redirectUri,
3235
3410
  grant_type: "authorization_code"
3236
3411
  });
3237
- const tokenResponse = yield import_axios18.default.post(
3238
- "https://api.hubapi.com/oauth/v1/token",
3412
+ const tokenResponse = yield hubspotClientInstance.post(
3413
+ "/oauth/v1/token",
3239
3414
  data,
3240
3415
  {
3241
3416
  headers: {
@@ -3251,22 +3426,10 @@ var hubspotApi = {
3251
3426
  };
3252
3427
  });
3253
3428
  },
3254
- getMetadata(_0) {
3255
- return __async(this, arguments, function* ({ token }) {
3256
- const {
3257
- data: { dc: server }
3258
- } = yield import_axios18.default.get(
3259
- "https://login.mailchimp.com/oauth2/metadata",
3260
- {
3261
- headers: {
3262
- "Content-Type": "application/json",
3263
- Authorization: `OAuth ${token}`
3264
- }
3265
- }
3266
- );
3267
- return {
3268
- server
3269
- };
3429
+ getTokenInfo(token) {
3430
+ return __async(this, null, function* () {
3431
+ const { data: tokenInfo } = yield hubspotClientInstance.get(`/oauth/v1/access-tokens/${token}`);
3432
+ return tokenInfo;
3270
3433
  });
3271
3434
  }
3272
3435
  };
@@ -6744,75 +6907,12 @@ var WorkflowDefinitionTaskType = {
6744
6907
  trigger: "TRIGGER"
6745
6908
  };
6746
6909
 
6747
- // src/apis/integrations/hubspot/instance.ts
6748
- var import_axios24 = __toESM(require("axios"));
6749
- var HubspotApiError = class extends ApiErrorBase {
6750
- constructor() {
6751
- super(...arguments);
6752
- this.name = "hubspot";
6753
- }
6754
- };
6755
- var hubspotClientUrl = `https://api.hubapi.com`;
6756
- var hubspotClientInstance = import_axios24.default.create({
6757
- headers: {
6758
- "Content-Type": "application/json"
6759
- }
6760
- });
6761
- hubspotClientInstance.interceptors.response.use(
6762
- (r) => r,
6763
- (error) => {
6764
- var _a, _b, _c, _d;
6765
- if (import_axios24.default.isAxiosError(error)) {
6766
- if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
6767
- throw new UnauthorizeApiError("hubspot");
6768
- }
6769
- }
6770
- return Promise.reject(
6771
- new HubspotApiError(
6772
- error.message,
6773
- (_b = error.response) == null ? void 0 : _b.data,
6774
- (_d = (_c = error.response) == null ? void 0 : _c.status) != null ? _d : 400
6775
- )
6776
- );
6777
- }
6778
- );
6779
- function getHubspotClientAuthorization(req) {
6780
- if (req.headers instanceof Headers) {
6781
- return {
6782
- token: req.headers.get("x-adapter-hubspot-token")
6783
- };
6784
- }
6785
- return {
6786
- token: req.headers["x-adapter-hubspot-token"]
6787
- };
6788
- }
6789
- function getHubspotClientConfig(options = {}) {
6790
- var _a;
6791
- const currentHeaders = hubspotClientInstance.defaults.headers;
6792
- const config = {
6793
- authorization: (_a = options.token ? `Bearer ${options.token}` : void 0) != null ? _a : currentHeaders.Authorization
6794
- };
6795
- if (options.ensureAuthorizationToken && !config.authorization) {
6796
- throw new UnauthorizeApiError("hubspot");
6797
- }
6798
- return {
6799
- headers: __spreadValues({}, config.authorization ? { Authorization: config.authorization } : {})
6800
- };
6801
- }
6802
- function initHubspotClient(token) {
6803
- if (token) {
6804
- updateHubspotClient(token);
6805
- }
6806
- }
6807
- function updateHubspotClient(token) {
6808
- const defaults = hubspotClientInstance.defaults;
6809
- const headers = defaults.headers;
6810
- if (token) {
6811
- headers.Authorization = `Bearer ${token}`;
6812
- } else {
6813
- delete headers.Authorization;
6814
- }
6815
- }
6910
+ // src/apis/integrations/hubspot/webhooks/_contracts/dtos/webhooks.ts
6911
+ var HubSpotWebhookEventTypes = /* @__PURE__ */ ((HubSpotWebhookEventTypes2) => {
6912
+ HubSpotWebhookEventTypes2["ContactCreation"] = "contact.creation";
6913
+ HubSpotWebhookEventTypes2["ContactDeletion"] = "contact.deletion";
6914
+ return HubSpotWebhookEventTypes2;
6915
+ })(HubSpotWebhookEventTypes || {});
6816
6916
 
6817
6917
  // src/apis/integrations/bigcommerce/webhooks/_contracts/dtos/webhooks.ts
6818
6918
  var BigCommerceWebhookScopes = /* @__PURE__ */ ((BigCommerceWebhookScopes2) => {
@@ -6822,8 +6922,8 @@ var BigCommerceWebhookScopes = /* @__PURE__ */ ((BigCommerceWebhookScopes2) => {
6822
6922
  })(BigCommerceWebhookScopes || {});
6823
6923
 
6824
6924
  // src/apis/platform/billing/instance.ts
6825
- var import_axios25 = __toESM(require("axios"));
6826
- var platformBillingClientInstance = import_axios25.default.create({
6925
+ var import_axios24 = __toESM(require("axios"));
6926
+ var platformBillingClientInstance = import_axios24.default.create({
6827
6927
  baseURL: "https://billing.labs.livechatinc.com"
6828
6928
  });
6829
6929
  function getPlatformBillingClientAuthorization(req) {
@@ -7109,7 +7209,8 @@ var import_zod4 = require("zod");
7109
7209
 
7110
7210
  // src/apis/platform/adapter/integrations/hubspot/_contracts/dtos/events.ts
7111
7211
  var HubspotEventNames = /* @__PURE__ */ ((HubspotEventNames2) => {
7112
- HubspotEventNames2["SomeEvent"] = "some_event";
7212
+ HubspotEventNames2["ContactCreated"] = "contact_created";
7213
+ HubspotEventNames2["ContactDeleted"] = "contact_deleted";
7113
7214
  return HubspotEventNames2;
7114
7215
  })(HubspotEventNames || {});
7115
7216
 
@@ -7118,12 +7219,18 @@ var hubspotEventsZods = {
7118
7219
  provider: import_zod4.z.literal("hubspot"),
7119
7220
  eventName: import_zod4.z.nativeEnum(HubspotEventNames),
7120
7221
  events: {
7121
- someEvent: import_zod4.z.object({
7122
- name: import_zod4.z.literal("some_event" /* SomeEvent */)
7222
+ contactCreated: import_zod4.z.object({
7223
+ name: import_zod4.z.literal("contact_created" /* ContactCreated */)
7224
+ }),
7225
+ contactDeleted: import_zod4.z.object({
7226
+ name: import_zod4.z.literal("contact_deleted" /* ContactDeleted */)
7123
7227
  })
7124
7228
  },
7125
7229
  get event() {
7126
- return import_zod4.z.discriminatedUnion("name", [this.events.someEvent]);
7230
+ return import_zod4.z.discriminatedUnion("name", [
7231
+ this.events.contactCreated,
7232
+ this.events.contactDeleted
7233
+ ]);
7127
7234
  },
7128
7235
  get source() {
7129
7236
  return import_zod4.z.object({
@@ -7143,7 +7250,7 @@ var hubspotEventsZods = {
7143
7250
  return import_zod4.z.object({
7144
7251
  provider: this.provider,
7145
7252
  event: this.event,
7146
- listId: import_zod4.z.string()
7253
+ callback: import_zod4.z.string()
7147
7254
  });
7148
7255
  },
7149
7256
  get unsubscribe() {
@@ -7686,6 +7793,7 @@ function getIntegrationFlowUrl(name, flow, trigger, context, state, config) {
7686
7793
  BigCommerceEventNames,
7687
7794
  BigCommerceWebhookScopes,
7688
7795
  DpsApiError,
7796
+ HubSpotWebhookEventTypes,
7689
7797
  HubspotApiError,
7690
7798
  HubspotEventNames,
7691
7799
  IntegrationModes,
@@ -7753,7 +7861,6 @@ function getIntegrationFlowUrl(name, flow, trigger, context, state, config) {
7753
7861
  getVercelClientConfig,
7754
7862
  githubClientInstance,
7755
7863
  hubspotClientInstance,
7756
- hubspotClientUrl,
7757
7864
  hubspotEventsZods,
7758
7865
  initApi,
7759
7866
  initBigCommerceClient,