@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.mjs CHANGED
@@ -1951,9 +1951,56 @@ var textAppApi = {
1951
1951
  monitoring: textAppMonitoringApi
1952
1952
  };
1953
1953
 
1954
+ // src/apis/integrations/text/platform/dashboard/api.ts
1955
+ var textPlatformDashboardApi = {
1956
+ getReport(params, authorization) {
1957
+ return __async(this, null, function* () {
1958
+ try {
1959
+ const searchParams = new URLSearchParams(
1960
+ Object.fromEntries(
1961
+ Object.entries(params).filter(([, value]) => value !== void 0)
1962
+ )
1963
+ );
1964
+ const response = yield textClientInstance.get(
1965
+ `/platform_dashboard/report?${searchParams.toString()}`,
1966
+ getTextClientConfig(authorization)
1967
+ );
1968
+ return response.data;
1969
+ } catch (error) {
1970
+ if (error instanceof Error) {
1971
+ throw new Error(`Couldn't load report. [${error.message}]`);
1972
+ }
1973
+ throw error;
1974
+ }
1975
+ });
1976
+ },
1977
+ getCredits(authorization) {
1978
+ return __async(this, null, function* () {
1979
+ try {
1980
+ const response = yield textClientInstance.get(
1981
+ `/platform_dashboard/credits`,
1982
+ getTextClientConfig(authorization)
1983
+ );
1984
+ return response.data;
1985
+ } catch (error) {
1986
+ if (error instanceof Error) {
1987
+ throw new Error(`Couldn't load credits. [${error.message}]`);
1988
+ }
1989
+ throw error;
1990
+ }
1991
+ });
1992
+ }
1993
+ };
1994
+
1995
+ // src/apis/integrations/text/platform/api.ts
1996
+ var textPlatformApi = {
1997
+ dashboard: textPlatformDashboardApi
1998
+ };
1999
+
1954
2000
  // src/apis/integrations/text/api.ts
1955
2001
  var textApi = {
1956
- app: textAppApi
2002
+ app: textAppApi,
2003
+ platform: textPlatformApi
1957
2004
  };
1958
2005
 
1959
2006
  // src/apis/integrations/vercel/api.ts
@@ -2766,7 +2813,7 @@ var productsApi = {
2766
2813
  // src/apis/platform/accounts/instance.ts
2767
2814
  import axios11 from "axios";
2768
2815
  var platformAccountsClientInstance = axios11.create({
2769
- baseURL: "https://accounts.labs.livechatinc.com"
2816
+ baseURL: "https://accounts.labs.livechat.com"
2770
2817
  });
2771
2818
  function getPlatformAccountsClientAuthorization(req) {
2772
2819
  return {
@@ -2799,6 +2846,58 @@ function initPlatformAccountsClientInstance(baseUrl, token) {
2799
2846
  }
2800
2847
  }
2801
2848
 
2849
+ // src/apis/platform/accounts/accounts/api.ts
2850
+ var platformAccountsAccountApi = {
2851
+ getAccounts(authorization) {
2852
+ return __async(this, null, function* () {
2853
+ try {
2854
+ return yield platformAccountsClientInstance.get(
2855
+ `/v2/accounts`,
2856
+ getPlatformAccountsClientConfig(authorization)
2857
+ );
2858
+ } catch (error) {
2859
+ if (error instanceof Error) {
2860
+ throw new Error(`Accounts couldn't be fetched. [${error.message}]`);
2861
+ } else {
2862
+ throw error;
2863
+ }
2864
+ }
2865
+ });
2866
+ },
2867
+ getAccount(accountId, authorization) {
2868
+ return __async(this, null, function* () {
2869
+ try {
2870
+ return yield platformAccountsClientInstance.get(
2871
+ `/v2/accounts/${accountId}`,
2872
+ getPlatformAccountsClientConfig(authorization)
2873
+ );
2874
+ } catch (error) {
2875
+ if (error instanceof Error) {
2876
+ throw new Error(`Account couldn't be fetched. [${error.message}]`);
2877
+ } else {
2878
+ throw error;
2879
+ }
2880
+ }
2881
+ });
2882
+ },
2883
+ getMeAccount(authorization) {
2884
+ return __async(this, null, function* () {
2885
+ try {
2886
+ return yield platformAccountsClientInstance.get(
2887
+ `/v2/accounts/me`,
2888
+ getPlatformAccountsClientConfig(authorization)
2889
+ );
2890
+ } catch (error) {
2891
+ if (error instanceof Error) {
2892
+ throw new Error(`Account couldn't be fetched. [${error.message}]`);
2893
+ } else {
2894
+ throw error;
2895
+ }
2896
+ }
2897
+ });
2898
+ }
2899
+ };
2900
+
2802
2901
  // src/apis/platform/accounts/client/api.ts
2803
2902
  var platformAccountsClientApi = {
2804
2903
  getClients(authorization) {
@@ -2942,13 +3041,50 @@ var platformAccountsClientApi = {
2942
3041
  }
2943
3042
  };
2944
3043
 
3044
+ // src/apis/platform/accounts/organization/api.ts
3045
+ var platformAccountsOrganizationApi = {
3046
+ getOrganizations(authorization) {
3047
+ return __async(this, null, function* () {
3048
+ try {
3049
+ const response = yield platformAccountsClientInstance.get(`/v2/organizations`, getPlatformAccountsClientConfig(authorization));
3050
+ return response.data || [];
3051
+ } catch (error) {
3052
+ if (error instanceof Error) {
3053
+ throw new Error(
3054
+ `Organizations couldn't be fetched. [${error.message}]`
3055
+ );
3056
+ } else {
3057
+ throw error;
3058
+ }
3059
+ }
3060
+ });
3061
+ },
3062
+ getMyOrganization(authorization) {
3063
+ return __async(this, null, function* () {
3064
+ try {
3065
+ return yield platformAccountsClientInstance.get(
3066
+ `/v2/organizations/my`,
3067
+ getPlatformAccountsClientConfig(authorization)
3068
+ );
3069
+ } catch (error) {
3070
+ if (error instanceof Error) {
3071
+ throw new Error(`Organization couldn't be fetched. [${error.message}]`);
3072
+ } else {
3073
+ throw error;
3074
+ }
3075
+ }
3076
+ });
3077
+ }
3078
+ };
3079
+
2945
3080
  // src/apis/platform/accounts/pat/api.ts
2946
3081
  var platformAccountsPersonalAccessTokenApi = {
2947
3082
  getPersonalAccessTokens(authorization) {
2948
3083
  return __async(this, null, function* () {
2949
3084
  try {
2950
3085
  const response = yield platformAccountsClientInstance.get(
2951
- `/v2/personal_token`
3086
+ `/v2/personal_token`,
3087
+ __spreadValues({}, getPlatformAccountsClientConfig(authorization))
2952
3088
  );
2953
3089
  return response.data;
2954
3090
  } catch (error) {
@@ -2970,7 +3106,8 @@ var platformAccountsPersonalAccessTokenApi = {
2970
3106
  {
2971
3107
  name,
2972
3108
  scope: scopes && scopes.map((item) => item.name).filter((el) => el).join(",")
2973
- }
3109
+ },
3110
+ getPlatformAccountsClientConfig(authorization)
2974
3111
  );
2975
3112
  return response.data;
2976
3113
  } catch (error) {
@@ -2987,11 +3124,10 @@ var platformAccountsPersonalAccessTokenApi = {
2987
3124
  deletePersonalAccessToken(id, authorization) {
2988
3125
  return __async(this, null, function* () {
2989
3126
  try {
2990
- const response = yield platformAccountsClientInstance.delete(
3127
+ yield platformAccountsClientInstance.delete(
2991
3128
  `/v2/personal_token/${id}`,
2992
3129
  getPlatformAccountsClientConfig(authorization)
2993
3130
  );
2994
- return response.data;
2995
3131
  } catch (error) {
2996
3132
  if (error instanceof Error) {
2997
3133
  throw new Error(
@@ -3087,8 +3223,10 @@ var platformAccountsSessionsApi = {
3087
3223
 
3088
3224
  // src/apis/platform/accounts/api.ts
3089
3225
  var platformAccountsApi = {
3226
+ account: platformAccountsAccountApi,
3090
3227
  client: platformAccountsClientApi,
3091
3228
  pat: platformAccountsPersonalAccessTokenApi,
3229
+ organization: platformAccountsOrganizationApi,
3092
3230
  products: platformAccountsProductsApi,
3093
3231
  scopes: platformAccountsScopesApi,
3094
3232
  sessions: platformAccountsSessionsApi
@@ -5147,9 +5285,135 @@ var platformAdapterApi = {
5147
5285
  app: platformAdapterAppApi
5148
5286
  };
5149
5287
 
5288
+ // src/apis/platform/billing/instance.ts
5289
+ import axios14 from "axios";
5290
+ var platformBillingClientInstance = axios14.create({
5291
+ baseURL: "https://billing.labs.livechatinc.com"
5292
+ });
5293
+ function getPlatformBillingClientAuthorization(req) {
5294
+ return {
5295
+ token: req.headers["platform-token"]
5296
+ };
5297
+ }
5298
+ function getPlatformBillingClientConfig(options = {}) {
5299
+ const defaultAuthorization = platformBillingClientInstance.defaults.headers.Authorization;
5300
+ const headers = {
5301
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
5302
+ };
5303
+ return {
5304
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
5305
+ };
5306
+ }
5307
+ function initPlatformBillingClientInstance(baseUrl, token) {
5308
+ if (baseUrl) {
5309
+ platformBillingClientInstance.interceptors.request.use(
5310
+ (config) => __async(this, null, function* () {
5311
+ config.baseURL = baseUrl;
5312
+ return config;
5313
+ }),
5314
+ (error) => Promise.reject(error)
5315
+ );
5316
+ }
5317
+ if (token) {
5318
+ platformBillingClientInstance.defaults.headers.Authorization = `Bearer ${token}`;
5319
+ } else {
5320
+ delete platformBillingClientInstance.defaults.headers.Authorization;
5321
+ }
5322
+ }
5323
+
5324
+ // src/apis/platform/billing/account/api.ts
5325
+ var platformBillingAccountApi = {
5326
+ getAccount(authorization) {
5327
+ return __async(this, null, function* () {
5328
+ try {
5329
+ return yield platformBillingClientInstance.get(
5330
+ `/v1/account`,
5331
+ getPlatformBillingClientConfig(authorization)
5332
+ );
5333
+ } catch (error) {
5334
+ if (error instanceof Error) {
5335
+ throw new Error(`Account couldn't be fetched. [${error.message}]`);
5336
+ } else {
5337
+ throw error;
5338
+ }
5339
+ }
5340
+ });
5341
+ },
5342
+ getAccountInfo(authorization) {
5343
+ return __async(this, null, function* () {
5344
+ try {
5345
+ return yield platformBillingClientInstance.get(
5346
+ `/v1/account/billing_info`,
5347
+ getPlatformBillingClientConfig(authorization)
5348
+ );
5349
+ } catch (error) {
5350
+ if (error instanceof Error) {
5351
+ throw new Error(
5352
+ `Account billing info couldn't be fetched. [${error.message}]`
5353
+ );
5354
+ } else {
5355
+ throw error;
5356
+ }
5357
+ }
5358
+ });
5359
+ }
5360
+ };
5361
+
5362
+ // src/apis/platform/billing/invoices/api.ts
5363
+ var platformBillingInvoicesApi = {
5364
+ getInvoices(authorization) {
5365
+ return __async(this, null, function* () {
5366
+ try {
5367
+ return yield platformBillingClientInstance.get(`/v1/invoices`, getPlatformBillingClientConfig(authorization));
5368
+ } catch (error) {
5369
+ if (error instanceof Error) {
5370
+ throw new Error(`Invoices couldn't be fetched. [${error.message}]`);
5371
+ } else {
5372
+ throw error;
5373
+ }
5374
+ }
5375
+ });
5376
+ },
5377
+ downloadInvoices(number, authorization) {
5378
+ return __async(this, null, function* () {
5379
+ try {
5380
+ const response = yield platformBillingClientInstance.request(__spreadValues({
5381
+ url: `https://api.labs.livechatinc.com/v2/invoices/${number}`,
5382
+ data: new URLSearchParams({
5383
+ _method: "GET"
5384
+ //gave the values directly for testing
5385
+ }),
5386
+ responseType: "blob"
5387
+ }, getPlatformBillingClientConfig(authorization)));
5388
+ const href = URL.createObjectURL(response.data);
5389
+ const link = document.createElement("a");
5390
+ link.href = href;
5391
+ link.setAttribute("download", `invoice-${number}.pdf`);
5392
+ document.body.appendChild(link);
5393
+ link.click();
5394
+ document.body.removeChild(link);
5395
+ URL.revokeObjectURL(href);
5396
+ } catch (error) {
5397
+ if (error instanceof Error) {
5398
+ throw new Error(`Invoice couldn't be downloaded. [${error.message}]`);
5399
+ } else {
5400
+ throw error;
5401
+ }
5402
+ }
5403
+ });
5404
+ }
5405
+ };
5406
+
5407
+ // src/apis/platform/billing/api.ts
5408
+ var platformBillingApi = {
5409
+ account: platformBillingAccountApi,
5410
+ invoices: platformBillingInvoicesApi
5411
+ };
5412
+
5150
5413
  // src/apis/platform/api.ts
5151
5414
  var platformApi = {
5152
5415
  accounts: platformAccountsApi,
5416
+ billing: platformBillingApi,
5153
5417
  adapter: platformAdapterApi,
5154
5418
  dps: platformDpsApi
5155
5419
  };
@@ -5162,41 +5426,45 @@ var api = {
5162
5426
  isInitialized: false
5163
5427
  };
5164
5428
  function initApi(config, tokens) {
5165
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
5429
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
5166
5430
  initPlatformAccountsClientInstance(
5167
5431
  (_a = config.urls.platform) == null ? void 0 : _a.accounts,
5168
5432
  (_b = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _b.dps
5169
5433
  );
5170
- initPlatformDpsClientInstance(
5171
- (_c = config.urls.platform) == null ? void 0 : _c.dps,
5434
+ initPlatformBillingClientInstance(
5435
+ (_c = config.urls.platform) == null ? void 0 : _c.billing,
5172
5436
  (_d = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _d.dps
5173
5437
  );
5438
+ initPlatformDpsClientInstance(
5439
+ (_e = config.urls.platform) == null ? void 0 : _e.dps,
5440
+ (_f = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _f.dps
5441
+ );
5174
5442
  initPlatformAdapterClientInstance(
5175
- (_e = config.urls.platform) == null ? void 0 : _e.adapter,
5443
+ (_g = config.urls.platform) == null ? void 0 : _g.adapter,
5176
5444
  tokens ? {
5177
5445
  platform: {
5178
- dps: (_f = tokens.platform) == null ? void 0 : _f.dps
5446
+ dps: (_h = tokens.platform) == null ? void 0 : _h.dps
5179
5447
  },
5180
5448
  github: {
5181
- app: (_g = tokens.github) == null ? void 0 : _g.apps,
5182
- oauth: (_h = tokens.github) == null ? void 0 : _h.oauth
5449
+ app: (_i = tokens.github) == null ? void 0 : _i.apps,
5450
+ oauth: (_j = tokens.github) == null ? void 0 : _j.oauth
5183
5451
  },
5184
- netlify: (_i = tokens.netlify) == null ? void 0 : _i.token,
5185
- vercel: (_j = tokens.vercel) == null ? void 0 : _j.token,
5186
- planetscale: (_k = tokens.planetscale) == null ? void 0 : _k.token,
5187
- sentry: (_l = tokens.sentry) == null ? void 0 : _l.token
5452
+ netlify: (_k = tokens.netlify) == null ? void 0 : _k.token,
5453
+ vercel: (_l = tokens.vercel) == null ? void 0 : _l.token,
5454
+ planetscale: (_m = tokens.planetscale) == null ? void 0 : _m.token,
5455
+ sentry: (_n = tokens.sentry) == null ? void 0 : _n.token
5188
5456
  } : void 0
5189
5457
  );
5190
5458
  initLiveChatClientInstance(
5191
- (_m = config.urls.products) == null ? void 0 : _m.livechat,
5192
- (_n = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _n.dps
5459
+ (_o = config.urls.products) == null ? void 0 : _o.livechat,
5460
+ (_p = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _p.dps
5193
5461
  );
5194
- initTextClientInstance((_o = config.urls.integrations) == null ? void 0 : _o.text, (_p = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _p.dps);
5195
- initGithubClientInstance((_q = tokens == null ? void 0 : tokens.github) == null ? void 0 : _q.apps);
5196
- initNetlifyClientInstance((_r = tokens == null ? void 0 : tokens.netlify) == null ? void 0 : _r.token);
5197
- initVercelClientInstance((_s = tokens == null ? void 0 : tokens.vercel) == null ? void 0 : _s.token);
5198
- initPlanetScaleClientInstance((_t = tokens == null ? void 0 : tokens.planetscale) == null ? void 0 : _t.token);
5199
- initSentryClientInstance((_u = tokens == null ? void 0 : tokens.sentry) == null ? void 0 : _u.token);
5462
+ initTextClientInstance((_q = config.urls.integrations) == null ? void 0 : _q.text, (_r = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _r.dps);
5463
+ initGithubClientInstance((_s = tokens == null ? void 0 : tokens.github) == null ? void 0 : _s.apps);
5464
+ initNetlifyClientInstance((_t = tokens == null ? void 0 : tokens.netlify) == null ? void 0 : _t.token);
5465
+ initVercelClientInstance((_u = tokens == null ? void 0 : tokens.vercel) == null ? void 0 : _u.token);
5466
+ initPlanetScaleClientInstance((_v = tokens == null ? void 0 : tokens.planetscale) == null ? void 0 : _v.token);
5467
+ initSentryClientInstance((_w = tokens == null ? void 0 : tokens.sentry) == null ? void 0 : _w.token);
5200
5468
  api.isInitialized = true;
5201
5469
  }
5202
5470
 
@@ -5230,6 +5498,8 @@ export {
5230
5498
  getPlatformAccountsClientConfig,
5231
5499
  getPlatformAdapterClientAuthorization,
5232
5500
  getPlatformAdapterClientConfig,
5501
+ getPlatformBillingClientAuthorization,
5502
+ getPlatformBillingClientConfig,
5233
5503
  getPlatformDpsAdminClientAuthorization,
5234
5504
  getPlatformDpsClientAuthorization,
5235
5505
  getPlatformDpsClientConfig,
@@ -5248,6 +5518,7 @@ export {
5248
5518
  initPlanetScaleClientInstance,
5249
5519
  initPlatformAccountsClientInstance,
5250
5520
  initPlatformAdapterClientInstance,
5521
+ initPlatformBillingClientInstance,
5251
5522
  initPlatformDpsClientInstance,
5252
5523
  initSentryClientInstance,
5253
5524
  initTextClientInstance,
@@ -5257,6 +5528,7 @@ export {
5257
5528
  planetScaleClientInstance,
5258
5529
  platformAccountsClientInstance,
5259
5530
  platformAdapterClientInstance,
5531
+ platformBillingClientInstance,
5260
5532
  platformDpsClientInstance,
5261
5533
  sentryClientInstance,
5262
5534
  serializerBase64,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livechat/developer-studio-api",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "This project is API for LiveChat Developer Studio.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",