@livechat/developer-studio-api 2.3.1 → 2.3.3

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
@@ -84,6 +84,8 @@ __export(src_exports, {
84
84
  getPlatformAccountsClientConfig: () => getPlatformAccountsClientConfig,
85
85
  getPlatformAdapterClientAuthorization: () => getPlatformAdapterClientAuthorization,
86
86
  getPlatformAdapterClientConfig: () => getPlatformAdapterClientConfig,
87
+ getPlatformBillingClientAuthorization: () => getPlatformBillingClientAuthorization,
88
+ getPlatformBillingClientConfig: () => getPlatformBillingClientConfig,
87
89
  getPlatformDpsAdminClientAuthorization: () => getPlatformDpsAdminClientAuthorization,
88
90
  getPlatformDpsClientAuthorization: () => getPlatformDpsClientAuthorization,
89
91
  getPlatformDpsClientConfig: () => getPlatformDpsClientConfig,
@@ -102,6 +104,7 @@ __export(src_exports, {
102
104
  initPlanetScaleClientInstance: () => initPlanetScaleClientInstance,
103
105
  initPlatformAccountsClientInstance: () => initPlatformAccountsClientInstance,
104
106
  initPlatformAdapterClientInstance: () => initPlatformAdapterClientInstance,
107
+ initPlatformBillingClientInstance: () => initPlatformBillingClientInstance,
105
108
  initPlatformDpsClientInstance: () => initPlatformDpsClientInstance,
106
109
  initSentryClientInstance: () => initSentryClientInstance,
107
110
  initTextClientInstance: () => initTextClientInstance,
@@ -111,6 +114,7 @@ __export(src_exports, {
111
114
  planetScaleClientInstance: () => planetScaleClientInstance,
112
115
  platformAccountsClientInstance: () => platformAccountsClientInstance,
113
116
  platformAdapterClientInstance: () => platformAdapterClientInstance,
117
+ platformBillingClientInstance: () => platformBillingClientInstance,
114
118
  platformDpsClientInstance: () => platformDpsClientInstance,
115
119
  sentryClientInstance: () => sentryClientInstance,
116
120
  serializerBase64: () => serializerBase64,
@@ -2038,9 +2042,56 @@ var textAppApi = {
2038
2042
  monitoring: textAppMonitoringApi
2039
2043
  };
2040
2044
 
2045
+ // src/apis/integrations/text/platform/dashboard/api.ts
2046
+ var textPlatformDashboardApi = {
2047
+ getReport(params, authorization) {
2048
+ return __async(this, null, function* () {
2049
+ try {
2050
+ const searchParams = new URLSearchParams(
2051
+ Object.fromEntries(
2052
+ Object.entries(params).filter(([, value]) => value !== void 0)
2053
+ )
2054
+ );
2055
+ const response = yield textClientInstance.get(
2056
+ `/platform_dashboard/report?${searchParams.toString()}`,
2057
+ getTextClientConfig(authorization)
2058
+ );
2059
+ return response.data;
2060
+ } catch (error) {
2061
+ if (error instanceof Error) {
2062
+ throw new Error(`Couldn't load report. [${error.message}]`);
2063
+ }
2064
+ throw error;
2065
+ }
2066
+ });
2067
+ },
2068
+ getCredits(authorization) {
2069
+ return __async(this, null, function* () {
2070
+ try {
2071
+ const response = yield textClientInstance.get(
2072
+ `/platform_dashboard/credits`,
2073
+ getTextClientConfig(authorization)
2074
+ );
2075
+ return response.data;
2076
+ } catch (error) {
2077
+ if (error instanceof Error) {
2078
+ throw new Error(`Couldn't load credits. [${error.message}]`);
2079
+ }
2080
+ throw error;
2081
+ }
2082
+ });
2083
+ }
2084
+ };
2085
+
2086
+ // src/apis/integrations/text/platform/api.ts
2087
+ var textPlatformApi = {
2088
+ dashboard: textPlatformDashboardApi
2089
+ };
2090
+
2041
2091
  // src/apis/integrations/text/api.ts
2042
2092
  var textApi = {
2043
- app: textAppApi
2093
+ app: textAppApi,
2094
+ platform: textPlatformApi
2044
2095
  };
2045
2096
 
2046
2097
  // src/apis/integrations/vercel/api.ts
@@ -2853,7 +2904,7 @@ var productsApi = {
2853
2904
  // src/apis/platform/accounts/instance.ts
2854
2905
  var import_axios11 = __toESM(require("axios"));
2855
2906
  var platformAccountsClientInstance = import_axios11.default.create({
2856
- baseURL: "https://accounts.labs.livechatinc.com"
2907
+ baseURL: "https://accounts.labs.livechat.com"
2857
2908
  });
2858
2909
  function getPlatformAccountsClientAuthorization(req) {
2859
2910
  return {
@@ -2886,6 +2937,58 @@ function initPlatformAccountsClientInstance(baseUrl, token) {
2886
2937
  }
2887
2938
  }
2888
2939
 
2940
+ // src/apis/platform/accounts/accounts/api.ts
2941
+ var platformAccountsAccountApi = {
2942
+ getAccounts(authorization) {
2943
+ return __async(this, null, function* () {
2944
+ try {
2945
+ return yield platformAccountsClientInstance.get(
2946
+ `/v2/accounts`,
2947
+ getPlatformAccountsClientConfig(authorization)
2948
+ );
2949
+ } catch (error) {
2950
+ if (error instanceof Error) {
2951
+ throw new Error(`Accounts couldn't be fetched. [${error.message}]`);
2952
+ } else {
2953
+ throw error;
2954
+ }
2955
+ }
2956
+ });
2957
+ },
2958
+ getAccount(accountId, authorization) {
2959
+ return __async(this, null, function* () {
2960
+ try {
2961
+ return yield platformAccountsClientInstance.get(
2962
+ `/v2/accounts/${accountId}`,
2963
+ getPlatformAccountsClientConfig(authorization)
2964
+ );
2965
+ } catch (error) {
2966
+ if (error instanceof Error) {
2967
+ throw new Error(`Account couldn't be fetched. [${error.message}]`);
2968
+ } else {
2969
+ throw error;
2970
+ }
2971
+ }
2972
+ });
2973
+ },
2974
+ getMeAccount(authorization) {
2975
+ return __async(this, null, function* () {
2976
+ try {
2977
+ return yield platformAccountsClientInstance.get(
2978
+ `/v2/accounts/me`,
2979
+ getPlatformAccountsClientConfig(authorization)
2980
+ );
2981
+ } catch (error) {
2982
+ if (error instanceof Error) {
2983
+ throw new Error(`Account couldn't be fetched. [${error.message}]`);
2984
+ } else {
2985
+ throw error;
2986
+ }
2987
+ }
2988
+ });
2989
+ }
2990
+ };
2991
+
2889
2992
  // src/apis/platform/accounts/client/api.ts
2890
2993
  var platformAccountsClientApi = {
2891
2994
  getClients(authorization) {
@@ -3029,13 +3132,50 @@ var platformAccountsClientApi = {
3029
3132
  }
3030
3133
  };
3031
3134
 
3135
+ // src/apis/platform/accounts/organization/api.ts
3136
+ var platformAccountsOrganizationApi = {
3137
+ getOrganizations(authorization) {
3138
+ return __async(this, null, function* () {
3139
+ try {
3140
+ const response = yield platformAccountsClientInstance.get(`/v2/organizations`, getPlatformAccountsClientConfig(authorization));
3141
+ return response.data || [];
3142
+ } catch (error) {
3143
+ if (error instanceof Error) {
3144
+ throw new Error(
3145
+ `Organizations couldn't be fetched. [${error.message}]`
3146
+ );
3147
+ } else {
3148
+ throw error;
3149
+ }
3150
+ }
3151
+ });
3152
+ },
3153
+ getMyOrganization(authorization) {
3154
+ return __async(this, null, function* () {
3155
+ try {
3156
+ return yield platformAccountsClientInstance.get(
3157
+ `/v2/organizations/my`,
3158
+ getPlatformAccountsClientConfig(authorization)
3159
+ );
3160
+ } catch (error) {
3161
+ if (error instanceof Error) {
3162
+ throw new Error(`Organization couldn't be fetched. [${error.message}]`);
3163
+ } else {
3164
+ throw error;
3165
+ }
3166
+ }
3167
+ });
3168
+ }
3169
+ };
3170
+
3032
3171
  // src/apis/platform/accounts/pat/api.ts
3033
3172
  var platformAccountsPersonalAccessTokenApi = {
3034
3173
  getPersonalAccessTokens(authorization) {
3035
3174
  return __async(this, null, function* () {
3036
3175
  try {
3037
3176
  const response = yield platformAccountsClientInstance.get(
3038
- `/v2/personal_token`
3177
+ `/v2/personal_token`,
3178
+ __spreadValues({}, getPlatformAccountsClientConfig(authorization))
3039
3179
  );
3040
3180
  return response.data;
3041
3181
  } catch (error) {
@@ -3057,7 +3197,8 @@ var platformAccountsPersonalAccessTokenApi = {
3057
3197
  {
3058
3198
  name,
3059
3199
  scope: scopes && scopes.map((item) => item.name).filter((el) => el).join(",")
3060
- }
3200
+ },
3201
+ getPlatformAccountsClientConfig(authorization)
3061
3202
  );
3062
3203
  return response.data;
3063
3204
  } catch (error) {
@@ -3074,11 +3215,10 @@ var platformAccountsPersonalAccessTokenApi = {
3074
3215
  deletePersonalAccessToken(id, authorization) {
3075
3216
  return __async(this, null, function* () {
3076
3217
  try {
3077
- const response = yield platformAccountsClientInstance.delete(
3218
+ yield platformAccountsClientInstance.delete(
3078
3219
  `/v2/personal_token/${id}`,
3079
3220
  getPlatformAccountsClientConfig(authorization)
3080
3221
  );
3081
- return response.data;
3082
3222
  } catch (error) {
3083
3223
  if (error instanceof Error) {
3084
3224
  throw new Error(
@@ -3174,8 +3314,10 @@ var platformAccountsSessionsApi = {
3174
3314
 
3175
3315
  // src/apis/platform/accounts/api.ts
3176
3316
  var platformAccountsApi = {
3317
+ account: platformAccountsAccountApi,
3177
3318
  client: platformAccountsClientApi,
3178
3319
  pat: platformAccountsPersonalAccessTokenApi,
3320
+ organization: platformAccountsOrganizationApi,
3179
3321
  products: platformAccountsProductsApi,
3180
3322
  scopes: platformAccountsScopesApi,
3181
3323
  sessions: platformAccountsSessionsApi
@@ -5234,9 +5376,135 @@ var platformAdapterApi = {
5234
5376
  app: platformAdapterAppApi
5235
5377
  };
5236
5378
 
5379
+ // src/apis/platform/billing/instance.ts
5380
+ var import_axios14 = __toESM(require("axios"));
5381
+ var platformBillingClientInstance = import_axios14.default.create({
5382
+ baseURL: "https://billing.labs.livechatinc.com"
5383
+ });
5384
+ function getPlatformBillingClientAuthorization(req) {
5385
+ return {
5386
+ token: req.headers["platform-token"]
5387
+ };
5388
+ }
5389
+ function getPlatformBillingClientConfig(options = {}) {
5390
+ const defaultAuthorization = platformBillingClientInstance.defaults.headers.Authorization;
5391
+ const headers = {
5392
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
5393
+ };
5394
+ return {
5395
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
5396
+ };
5397
+ }
5398
+ function initPlatformBillingClientInstance(baseUrl, token) {
5399
+ if (baseUrl) {
5400
+ platformBillingClientInstance.interceptors.request.use(
5401
+ (config) => __async(this, null, function* () {
5402
+ config.baseURL = baseUrl;
5403
+ return config;
5404
+ }),
5405
+ (error) => Promise.reject(error)
5406
+ );
5407
+ }
5408
+ if (token) {
5409
+ platformBillingClientInstance.defaults.headers.Authorization = `Bearer ${token}`;
5410
+ } else {
5411
+ delete platformBillingClientInstance.defaults.headers.Authorization;
5412
+ }
5413
+ }
5414
+
5415
+ // src/apis/platform/billing/account/api.ts
5416
+ var platformBillingAccountApi = {
5417
+ getAccount(authorization) {
5418
+ return __async(this, null, function* () {
5419
+ try {
5420
+ return yield platformBillingClientInstance.get(
5421
+ `/v1/account`,
5422
+ getPlatformBillingClientConfig(authorization)
5423
+ );
5424
+ } catch (error) {
5425
+ if (error instanceof Error) {
5426
+ throw new Error(`Account couldn't be fetched. [${error.message}]`);
5427
+ } else {
5428
+ throw error;
5429
+ }
5430
+ }
5431
+ });
5432
+ },
5433
+ getAccountInfo(authorization) {
5434
+ return __async(this, null, function* () {
5435
+ try {
5436
+ return yield platformBillingClientInstance.get(
5437
+ `/v1/account/billing_info`,
5438
+ getPlatformBillingClientConfig(authorization)
5439
+ );
5440
+ } catch (error) {
5441
+ if (error instanceof Error) {
5442
+ throw new Error(
5443
+ `Account billing info couldn't be fetched. [${error.message}]`
5444
+ );
5445
+ } else {
5446
+ throw error;
5447
+ }
5448
+ }
5449
+ });
5450
+ }
5451
+ };
5452
+
5453
+ // src/apis/platform/billing/invoices/api.ts
5454
+ var platformBillingInvoicesApi = {
5455
+ getInvoices(authorization) {
5456
+ return __async(this, null, function* () {
5457
+ try {
5458
+ return yield platformBillingClientInstance.get(`/v1/invoices`, getPlatformBillingClientConfig(authorization));
5459
+ } catch (error) {
5460
+ if (error instanceof Error) {
5461
+ throw new Error(`Invoices couldn't be fetched. [${error.message}]`);
5462
+ } else {
5463
+ throw error;
5464
+ }
5465
+ }
5466
+ });
5467
+ },
5468
+ downloadInvoices(number, authorization) {
5469
+ return __async(this, null, function* () {
5470
+ try {
5471
+ const response = yield platformBillingClientInstance.request(__spreadValues({
5472
+ url: `https://api.labs.livechatinc.com/v2/invoices/${number}`,
5473
+ data: new URLSearchParams({
5474
+ _method: "GET"
5475
+ //gave the values directly for testing
5476
+ }),
5477
+ responseType: "blob"
5478
+ }, getPlatformBillingClientConfig(authorization)));
5479
+ const href = URL.createObjectURL(response.data);
5480
+ const link = document.createElement("a");
5481
+ link.href = href;
5482
+ link.setAttribute("download", `invoice-${number}.pdf`);
5483
+ document.body.appendChild(link);
5484
+ link.click();
5485
+ document.body.removeChild(link);
5486
+ URL.revokeObjectURL(href);
5487
+ } catch (error) {
5488
+ if (error instanceof Error) {
5489
+ throw new Error(`Invoice couldn't be downloaded. [${error.message}]`);
5490
+ } else {
5491
+ throw error;
5492
+ }
5493
+ }
5494
+ });
5495
+ }
5496
+ };
5497
+
5498
+ // src/apis/platform/billing/api.ts
5499
+ var platformBillingApi = {
5500
+ account: platformBillingAccountApi,
5501
+ invoices: platformBillingInvoicesApi
5502
+ };
5503
+
5237
5504
  // src/apis/platform/api.ts
5238
5505
  var platformApi = {
5239
5506
  accounts: platformAccountsApi,
5507
+ billing: platformBillingApi,
5240
5508
  adapter: platformAdapterApi,
5241
5509
  dps: platformDpsApi
5242
5510
  };
@@ -5249,41 +5517,45 @@ var api = {
5249
5517
  isInitialized: false
5250
5518
  };
5251
5519
  function initApi(config, tokens) {
5252
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
5520
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
5253
5521
  initPlatformAccountsClientInstance(
5254
5522
  (_a = config.urls.platform) == null ? void 0 : _a.accounts,
5255
5523
  (_b = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _b.dps
5256
5524
  );
5257
- initPlatformDpsClientInstance(
5258
- (_c = config.urls.platform) == null ? void 0 : _c.dps,
5525
+ initPlatformBillingClientInstance(
5526
+ (_c = config.urls.platform) == null ? void 0 : _c.billing,
5259
5527
  (_d = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _d.dps
5260
5528
  );
5529
+ initPlatformDpsClientInstance(
5530
+ (_e = config.urls.platform) == null ? void 0 : _e.dps,
5531
+ (_f = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _f.dps
5532
+ );
5261
5533
  initPlatformAdapterClientInstance(
5262
- (_e = config.urls.platform) == null ? void 0 : _e.adapter,
5534
+ (_g = config.urls.platform) == null ? void 0 : _g.adapter,
5263
5535
  tokens ? {
5264
5536
  platform: {
5265
- dps: (_f = tokens.platform) == null ? void 0 : _f.dps
5537
+ dps: (_h = tokens.platform) == null ? void 0 : _h.dps
5266
5538
  },
5267
5539
  github: {
5268
- app: (_g = tokens.github) == null ? void 0 : _g.apps,
5269
- oauth: (_h = tokens.github) == null ? void 0 : _h.oauth
5540
+ app: (_i = tokens.github) == null ? void 0 : _i.apps,
5541
+ oauth: (_j = tokens.github) == null ? void 0 : _j.oauth
5270
5542
  },
5271
- netlify: (_i = tokens.netlify) == null ? void 0 : _i.token,
5272
- vercel: (_j = tokens.vercel) == null ? void 0 : _j.token,
5273
- planetscale: (_k = tokens.planetscale) == null ? void 0 : _k.token,
5274
- sentry: (_l = tokens.sentry) == null ? void 0 : _l.token
5543
+ netlify: (_k = tokens.netlify) == null ? void 0 : _k.token,
5544
+ vercel: (_l = tokens.vercel) == null ? void 0 : _l.token,
5545
+ planetscale: (_m = tokens.planetscale) == null ? void 0 : _m.token,
5546
+ sentry: (_n = tokens.sentry) == null ? void 0 : _n.token
5275
5547
  } : void 0
5276
5548
  );
5277
5549
  initLiveChatClientInstance(
5278
- (_m = config.urls.products) == null ? void 0 : _m.livechat,
5279
- (_n = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _n.dps
5550
+ (_o = config.urls.products) == null ? void 0 : _o.livechat,
5551
+ (_p = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _p.dps
5280
5552
  );
5281
- initTextClientInstance((_o = config.urls.integrations) == null ? void 0 : _o.text, (_p = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _p.dps);
5282
- initGithubClientInstance((_q = tokens == null ? void 0 : tokens.github) == null ? void 0 : _q.apps);
5283
- initNetlifyClientInstance((_r = tokens == null ? void 0 : tokens.netlify) == null ? void 0 : _r.token);
5284
- initVercelClientInstance((_s = tokens == null ? void 0 : tokens.vercel) == null ? void 0 : _s.token);
5285
- initPlanetScaleClientInstance((_t = tokens == null ? void 0 : tokens.planetscale) == null ? void 0 : _t.token);
5286
- initSentryClientInstance((_u = tokens == null ? void 0 : tokens.sentry) == null ? void 0 : _u.token);
5553
+ initTextClientInstance((_q = config.urls.integrations) == null ? void 0 : _q.text, (_r = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _r.dps);
5554
+ initGithubClientInstance((_s = tokens == null ? void 0 : tokens.github) == null ? void 0 : _s.apps);
5555
+ initNetlifyClientInstance((_t = tokens == null ? void 0 : tokens.netlify) == null ? void 0 : _t.token);
5556
+ initVercelClientInstance((_u = tokens == null ? void 0 : tokens.vercel) == null ? void 0 : _u.token);
5557
+ initPlanetScaleClientInstance((_v = tokens == null ? void 0 : tokens.planetscale) == null ? void 0 : _v.token);
5558
+ initSentryClientInstance((_w = tokens == null ? void 0 : tokens.sentry) == null ? void 0 : _w.token);
5287
5559
  api.isInitialized = true;
5288
5560
  }
5289
5561
 
@@ -5318,6 +5590,8 @@ var serializerBase64 = {
5318
5590
  getPlatformAccountsClientConfig,
5319
5591
  getPlatformAdapterClientAuthorization,
5320
5592
  getPlatformAdapterClientConfig,
5593
+ getPlatformBillingClientAuthorization,
5594
+ getPlatformBillingClientConfig,
5321
5595
  getPlatformDpsAdminClientAuthorization,
5322
5596
  getPlatformDpsClientAuthorization,
5323
5597
  getPlatformDpsClientConfig,
@@ -5336,6 +5610,7 @@ var serializerBase64 = {
5336
5610
  initPlanetScaleClientInstance,
5337
5611
  initPlatformAccountsClientInstance,
5338
5612
  initPlatformAdapterClientInstance,
5613
+ initPlatformBillingClientInstance,
5339
5614
  initPlatformDpsClientInstance,
5340
5615
  initSentryClientInstance,
5341
5616
  initTextClientInstance,
@@ -5345,6 +5620,7 @@ var serializerBase64 = {
5345
5620
  planetScaleClientInstance,
5346
5621
  platformAccountsClientInstance,
5347
5622
  platformAdapterClientInstance,
5623
+ platformBillingClientInstance,
5348
5624
  platformDpsClientInstance,
5349
5625
  sentryClientInstance,
5350
5626
  serializerBase64,