@livechat/developer-studio-api 1.0.1

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 ADDED
@@ -0,0 +1,4758 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __async = (__this, __arguments, generator) => {
47
+ return new Promise((resolve, reject) => {
48
+ var fulfilled = (value) => {
49
+ try {
50
+ step(generator.next(value));
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ };
55
+ var rejected = (value) => {
56
+ try {
57
+ step(generator.throw(value));
58
+ } catch (e) {
59
+ reject(e);
60
+ }
61
+ };
62
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
+ step((generator = generator.apply(__this, __arguments)).next());
64
+ });
65
+ };
66
+
67
+ // src/index.ts
68
+ var src_exports = {};
69
+ __export(src_exports, {
70
+ API_NOTIFICATIONS: () => API_NOTIFICATIONS,
71
+ ErrorType: () => ErrorType,
72
+ UnauthorizeApiError: () => UnauthorizeApiError,
73
+ api: () => api,
74
+ getAppAutoReviewPayload: () => getAppAutoReviewPayload,
75
+ getEmptyAppAutoReview: () => getEmptyAppAutoReview,
76
+ getGitHubClientAuthorization: () => getGitHubClientAuthorization,
77
+ getGithubClientRequestConfig: () => getGithubClientRequestConfig,
78
+ getLiveChatClientAuthorization: () => getLiveChatClientAuthorization,
79
+ getLiveChatClientConfig: () => getLiveChatClientConfig,
80
+ getNetlifyClientAuthorization: () => getNetlifyClientAuthorization,
81
+ getNetlifyClientConfig: () => getNetlifyClientConfig,
82
+ getPlanetScaleClientAuthorization: () => getPlanetScaleClientAuthorization,
83
+ getPlanetScaleClientConfig: () => getPlanetScaleClientConfig,
84
+ getPlatformAccountsClientAuthorization: () => getPlatformAccountsClientAuthorization,
85
+ getPlatformAccountsClientConfig: () => getPlatformAccountsClientConfig,
86
+ getPlatformAdapterClientAuthorization: () => getPlatformAdapterClientAuthorization,
87
+ getPlatformAdapterClientConfig: () => getPlatformAdapterClientConfig,
88
+ getPlatformDpsAdminClientAuthorization: () => getPlatformDpsAdminClientAuthorization,
89
+ getPlatformDpsClientAuthorization: () => getPlatformDpsClientAuthorization,
90
+ getPlatformDpsClientConfig: () => getPlatformDpsClientConfig,
91
+ getRegion: () => getRegion,
92
+ getSentryClientAuthorization: () => getSentryClientAuthorization,
93
+ getSentryClientConfig: () => getSentryClientConfig,
94
+ getVercelClientAuthorization: () => getVercelClientAuthorization,
95
+ getVercelClientConfig: () => getVercelClientConfig,
96
+ githubClientInstance: () => githubClientInstance,
97
+ initApi: () => initApi,
98
+ initGithubClientInstance: () => initGithubClientInstance,
99
+ initLiveChatClientInstance: () => initLiveChatClientInstance,
100
+ initNetlifyClientInstance: () => initNetlifyClientInstance,
101
+ initPlanetScaleClientInstance: () => initPlanetScaleClientInstance,
102
+ initPlatformAccountsClientInstance: () => initPlatformAccountsClientInstance,
103
+ initPlatformAdapterClientInstance: () => initPlatformAdapterClientInstance,
104
+ initPlatformDpsClientInstance: () => initPlatformDpsClientInstance,
105
+ initSentryClientInstance: () => initSentryClientInstance,
106
+ initVercelClientInstance: () => initVercelClientInstance,
107
+ livechatClientInstance: () => livechatClientInstance,
108
+ netlifyClientInstance: () => netlifyClientInstance,
109
+ planetScaleClientInstance: () => planetScaleClientInstance,
110
+ platformAccountsClientInstance: () => platformAccountsClientInstance,
111
+ platformAdapterClientInstance: () => platformAdapterClientInstance,
112
+ platformDpsClientInstance: () => platformDpsClientInstance,
113
+ sentryClientInstance: () => sentryClientInstance,
114
+ serializerBase64: () => serializerBase64,
115
+ updateGithubClientInstance: () => updateGithubClientInstance,
116
+ updateNetlifyClientInstance: () => updateNetlifyClientInstance,
117
+ updatePlanetScaleClientInstance: () => updatePlanetScaleClientInstance,
118
+ updatePlatformAdapterClientInstance: () => updatePlatformAdapterClientInstance,
119
+ updateSentryClientInstance: () => updateSentryClientInstance,
120
+ updateVercelClientInstance: () => updateVercelClientInstance,
121
+ vercelClientInstance: () => vercelClientInstance
122
+ });
123
+ module.exports = __toCommonJS(src_exports);
124
+
125
+ // src/apis/integrations/github/api.ts
126
+ var import_axios2 = __toESM(require("axios"));
127
+
128
+ // src/apis/integrations/github/instance.ts
129
+ var import_axios = __toESM(require("axios"));
130
+
131
+ // src/types/errors/api.ts
132
+ var UnauthorizeApiError = class extends Error {
133
+ constructor(source) {
134
+ super("Unauthorized API call");
135
+ this.source = source;
136
+ }
137
+ };
138
+
139
+ // src/apis/integrations/github/instance.ts
140
+ var githubClientInstance = import_axios.default.create({
141
+ baseURL: "https://api.github.com",
142
+ headers: {
143
+ ["Accept"]: "application/vnd.github+json",
144
+ ["Content-Type"]: "application/json"
145
+ }
146
+ });
147
+ githubClientInstance.interceptors.response.use(
148
+ (r) => r,
149
+ (error) => {
150
+ var _a;
151
+ if (import_axios.default.isAxiosError(error)) {
152
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
153
+ error = new UnauthorizeApiError("github");
154
+ }
155
+ }
156
+ throw error;
157
+ }
158
+ );
159
+ function getGitHubClientAuthorization(req) {
160
+ return {
161
+ tokens: {
162
+ app: req.headers["github-app-token"],
163
+ oauth: req.headers["github-oauth-token"]
164
+ }
165
+ };
166
+ }
167
+ function getGithubClientRequestConfig(options = {}) {
168
+ const defaultAuthorization = githubClientInstance.defaults.headers["Authorization"];
169
+ const headers = {
170
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
171
+ };
172
+ return {
173
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
174
+ };
175
+ }
176
+ function initGithubClientInstance(token) {
177
+ if (token) {
178
+ updateGithubClientInstance(token);
179
+ }
180
+ }
181
+ function updateGithubClientInstance(token) {
182
+ if (token) {
183
+ githubClientInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
184
+ } else {
185
+ delete githubClientInstance.defaults.headers["Authorization"];
186
+ }
187
+ }
188
+
189
+ // ../../private/config/src/integrations/github.ts
190
+ var GITHUB_CONFIG = {
191
+ url: "https://github.com/login/oauth/authorize",
192
+ app: process.env.NEXT_PUBLIC_PLATFORM_ENV === "prod" ? {
193
+ id: 265597,
194
+ client_name: "text-platform-developer-console",
195
+ client_id: "Iv1.c582ec1de0bf8428",
196
+ client_secret: process.env.GITHUB_APP_CLIENT_SECRET,
197
+ redirect_uri: "https://platform.text.com/console-adapter/integrations/github/callbacks/app"
198
+ } : {
199
+ id: 319969,
200
+ client_name: "text-platform-labs",
201
+ client_id: "Iv1.e631130cf8ac91d7",
202
+ client_secret: process.env.GITHUB_APP_CLIENT_SECRET_LABS,
203
+ redirect_uri: "https://platform.labs.text.com/console-adapter/integrations/github/callbacks/app"
204
+ },
205
+ oauth: process.env.NEXT_PUBLIC_PLATFORM_ENV === "prod" ? {
206
+ client_id: "ebbb08fa2c26d3e7911d",
207
+ client_secret: process.env.GITHUB_OAUTH_CLIENT_SECRET,
208
+ redirect_uri: "https://platform.text.com/console-adapter/integrations/github/callbacks/oauth"
209
+ } : {
210
+ client_id: "bcffd61bd0edd23bca45",
211
+ client_secret: process.env.GITHUB_OAUTH_CLIENT_SECRET_LABS,
212
+ redirect_uri: "https://platform.labs.text.com/console-adapter/integrations/github/callbacks/oauth"
213
+ }
214
+ };
215
+
216
+ // ../../private/config/src/integrations/netlify.ts
217
+ var NETLIFY_CONFIG = {
218
+ url: "https://app.netlify.com/authorize",
219
+ github_app_client_name: "netlify",
220
+ app: process.env.NEXT_PUBLIC_PLATFORM_ENV === "prod" ? {
221
+ client_id: "qUoHYb2DdVwKxot9Gc7URTdsZQYHYaumykjkv5K3_Mw",
222
+ redirect_uri: "https://platform.text.com/console-adapter/integrations/netlify/callbacks/oauth",
223
+ client_secret: process.env.NETLIFY_CLIENT_SECRET
224
+ } : {
225
+ client_id: "vDmNXNN9rTkZJtCwOHot2IKOherrm8t7gGA5kStotlo",
226
+ redirect_uri: "https://platform.labs.text.com/console-adapter/integrations/netlify/callbacks/oauth",
227
+ client_secret: process.env.NETLIFY_CLIENT_SECRET_LABS
228
+ }
229
+ };
230
+
231
+ // ../../private/config/src/integrations/planetscale.ts
232
+ var PLANETSCALE_CONFIG = {
233
+ url: "http://app.planetscale.com/oauth/authorize",
234
+ github_app_client_name: "planetscale",
235
+ app: process.env.NEXT_PUBLIC_PLATFORM_ENV === "prod" ? {
236
+ organization: "livechat",
237
+ appId: "bw2hi8knpzbl",
238
+ client_id: "pscale_app_b0aa82ae3d32f32010d7352d88f22fb2",
239
+ service_token_id: "be5l1vy34g6h",
240
+ redirect_uri: "https://platform.text.com/console-adapter/integrations/planetscale/callbacks/oauth",
241
+ client_secret: process.env.PLANETSCALE_CLIENT_SECRET,
242
+ service_token: process.env.PLANETSCALE_SERVICE_TOKEN
243
+ } : {
244
+ organization: "livechat",
245
+ appId: "oz4pafhcyshn",
246
+ client_id: "pscale_app_54606de46e127f664df359639baf6b66",
247
+ service_token_id: "qdpgtmrqpdsm",
248
+ redirect_uri: "https://platform.labs.text.com/console-adapter/integrations/planetscale/callbacks/oauth",
249
+ client_secret: process.env.PLANETSCALE_CLIENT_SECRET_LABS,
250
+ service_token: process.env.PLANETSCALE_SERVICE_TOKEN_LABS
251
+ }
252
+ };
253
+
254
+ // ../../private/config/src/integrations/sentry.ts
255
+ var SENTRY_CONFIG = {
256
+ github_app_client_name: "sentry-io",
257
+ app: process.env.NEXT_PUBLIC_PLATFORM_ENV === "prod" ? {
258
+ client_id: "8c8296fe87cb446e9ded22f8b6f4b078363500062155476490d4583b5406d30a",
259
+ client_secret: process.env.SENTRY_CLIENT_SECRET,
260
+ redirect_uri: "https://platform.text.com/console-adapter/integrations/sentry/callbacks/oauth"
261
+ } : {
262
+ client_id: "d35803a39bab43b3b6dbe0b89cb99dc54689c35a74dd442baaef0f5b9b0d70bc",
263
+ client_secret: process.env.SENTRY_CLIENT_SECRET_LABS,
264
+ redirect_uri: "https://platform.labs.text.com/console-adapter/integrations/sentry/callbacks/oauth"
265
+ }
266
+ };
267
+
268
+ // ../../private/config/src/integrations/vercel.ts
269
+ var VERCEL_CONFIG = {
270
+ github_app_client_name: "vercel",
271
+ app: process.env.NEXT_PUBLIC_PLATFORM_ENV === "prod" ? {
272
+ client_name: "text-platform-developer-console",
273
+ client_id: "oac_0nV7q5jDmCQKqpwEdGljaaLp",
274
+ client_secret: process.env.VERCEL_CLIENT_SECRET,
275
+ redirect_uri: "https://platform.text.com/console-adapter/integrations/vercel/callbacks/oauth"
276
+ } : {
277
+ client_name: "text-platform-labs",
278
+ client_id: "oac_bgwv72AO8fJWj8I9qIROY7wI",
279
+ client_secret: process.env.VERCEL_CLIENT_SECRET_LABS,
280
+ redirect_uri: "https://platform.labs.text.com/console-adapter/integrations/vercel/callbacks/oauth"
281
+ }
282
+ };
283
+
284
+ // src/apis/integrations/github/installation/api.ts
285
+ var gitHubInstallationApi = {
286
+ getInstallation(account, authorization) {
287
+ return __async(this, null, function* () {
288
+ const installations = yield this.getInstallations(authorization);
289
+ return installations.find(
290
+ (installation) => installation.app_id === GITHUB_CONFIG.app.id && account ? installation.account.login === account : installation.target_type === "User"
291
+ );
292
+ });
293
+ },
294
+ getInstallations(authorization) {
295
+ return __async(this, null, function* () {
296
+ var _a;
297
+ const response = yield githubClientInstance.get(
298
+ `/user/installations?timestamp=${(/* @__PURE__ */ new Date()).getTime()}`,
299
+ getGithubClientRequestConfig({
300
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
301
+ })
302
+ );
303
+ return response.data.installations;
304
+ });
305
+ },
306
+ getInstallationRepositories(installationId) {
307
+ return __async(this, null, function* () {
308
+ const response = yield githubClientInstance.get(
309
+ `/user/installations/${installationId}/repositories?timestamp=${(/* @__PURE__ */ new Date()).getTime()}&per_page=100`
310
+ );
311
+ return response.data.repositories;
312
+ });
313
+ }
314
+ };
315
+
316
+ // src/apis/integrations/github/repository/api.ts
317
+ var gitHubRepositoryApi = {
318
+ getRepository(repositoryName, authorization) {
319
+ return __async(this, null, function* () {
320
+ var _a;
321
+ const response = yield githubClientInstance.get(
322
+ `/repos/${repositoryName}`,
323
+ getGithubClientRequestConfig({
324
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
325
+ })
326
+ );
327
+ return response.data;
328
+ });
329
+ },
330
+ getRepositoryBranches(repositoryName, authorization) {
331
+ return __async(this, null, function* () {
332
+ var _a;
333
+ const response = yield githubClientInstance.get(
334
+ `/repos/${repositoryName}/branches`,
335
+ getGithubClientRequestConfig({
336
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
337
+ })
338
+ );
339
+ return response.data;
340
+ });
341
+ },
342
+ getRepositoryBranch(repositoryName, repositoryBranch, authorization) {
343
+ return __async(this, null, function* () {
344
+ var _a;
345
+ const response = yield githubClientInstance.get(
346
+ `/repos/${repositoryName}/branches`,
347
+ getGithubClientRequestConfig({
348
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
349
+ })
350
+ );
351
+ const branch = response.data.find(
352
+ (branch2) => branch2.name === repositoryBranch
353
+ );
354
+ if (!branch) {
355
+ throw new Error("Branch not found");
356
+ }
357
+ return branch;
358
+ });
359
+ },
360
+ getRepositorySeed(repositoryName, authorization) {
361
+ return __async(this, null, function* () {
362
+ var _a;
363
+ const { data } = yield githubClientInstance.get(
364
+ `/repos/${repositoryName}/contents/livechat.config.json`,
365
+ getGithubClientRequestConfig({
366
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
367
+ })
368
+ );
369
+ return data;
370
+ });
371
+ },
372
+ createRepository(name, hasInstallation, templateName, authorization) {
373
+ return __async(this, null, function* () {
374
+ var _a, _b, _c, _d;
375
+ const fullTemplateName = templateName === "nextjs" ? "livechat/developer-app-template-nextjs" : void 0;
376
+ if (fullTemplateName || !hasInstallation) {
377
+ let repository;
378
+ if (fullTemplateName) {
379
+ const response2 = yield githubClientInstance.post(
380
+ `/repos/${fullTemplateName}/generate`,
381
+ {
382
+ name,
383
+ description: name,
384
+ private: false,
385
+ include_all_branches: false
386
+ },
387
+ getGithubClientRequestConfig({
388
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.oauth
389
+ })
390
+ );
391
+ repository = response2.data;
392
+ } else {
393
+ const response2 = yield githubClientInstance.post(
394
+ `/user/repos`,
395
+ {
396
+ name,
397
+ description: name,
398
+ private: false,
399
+ auto_init: true,
400
+ is_template: false
401
+ },
402
+ getGithubClientRequestConfig({
403
+ token: (_b = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _b.oauth
404
+ })
405
+ );
406
+ repository = response2.data;
407
+ }
408
+ yield githubClientInstance.patch(
409
+ `/repos/${repository.full_name}`,
410
+ {
411
+ private: true
412
+ },
413
+ getGithubClientRequestConfig({
414
+ token: (_c = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _c.oauth
415
+ })
416
+ );
417
+ return repository;
418
+ }
419
+ const response = yield githubClientInstance.post(
420
+ `/user/repos`,
421
+ {
422
+ name,
423
+ description: name,
424
+ private: true,
425
+ auto_init: true,
426
+ is_template: false
427
+ },
428
+ getGithubClientRequestConfig({
429
+ token: (_d = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _d.app
430
+ })
431
+ );
432
+ return response.data;
433
+ });
434
+ },
435
+ seedRepository(repositoryName, appId, clientId, authorization) {
436
+ return __async(this, null, function* () {
437
+ const upsert = (sha) => __async(this, null, function* () {
438
+ var _a;
439
+ const response = yield githubClientInstance.put(
440
+ `/repos/${repositoryName}/contents/livechat.config.json`,
441
+ {
442
+ message: "Added LiveChat Developer App configuration",
443
+ sha,
444
+ content: btoa(
445
+ JSON.stringify(
446
+ {
447
+ appId,
448
+ auth: {
449
+ clientId
450
+ }
451
+ },
452
+ null,
453
+ 4
454
+ )
455
+ )
456
+ },
457
+ getGithubClientRequestConfig({ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app })
458
+ );
459
+ return response.data.content;
460
+ });
461
+ let seed = void 0;
462
+ try {
463
+ seed = yield this.getRepositorySeed(repositoryName, authorization);
464
+ } catch (e) {
465
+ }
466
+ return yield upsert(seed == null ? void 0 : seed.sha);
467
+ });
468
+ },
469
+ deleteRepository(repositoryName, authorization) {
470
+ return __async(this, null, function* () {
471
+ var _a;
472
+ return yield githubClientInstance.delete(
473
+ `/repos/${repositoryName}`,
474
+ getGithubClientRequestConfig({
475
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
476
+ })
477
+ );
478
+ });
479
+ },
480
+ createRepositoryDeployKey(repositoryName, deployKey, authorization) {
481
+ return __async(this, null, function* () {
482
+ var _a;
483
+ const response = yield githubClientInstance.post(
484
+ `/repos/${repositoryName}/keys`,
485
+ {
486
+ title: "developer-console-to-netlify",
487
+ key: deployKey
488
+ },
489
+ getGithubClientRequestConfig({
490
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
491
+ })
492
+ );
493
+ return response.data;
494
+ });
495
+ },
496
+ createRepositoryBuildHook(repositoryName, authorization) {
497
+ return __async(this, null, function* () {
498
+ var _a;
499
+ try {
500
+ const response = yield githubClientInstance.post(
501
+ `/repos/${repositoryName}/hooks`,
502
+ {
503
+ name: "web",
504
+ active: true,
505
+ events: [
506
+ "delete",
507
+ "push",
508
+ "pull_request",
509
+ "create",
510
+ "issue_comment",
511
+ "pull_request_review",
512
+ "pull_request_review_comment"
513
+ ],
514
+ config: {
515
+ url: "https://api.netlify.com/hooks/github",
516
+ content_type: "json"
517
+ }
518
+ },
519
+ getGithubClientRequestConfig({
520
+ token: (_a = authorization == null ? void 0 : authorization.tokens) == null ? void 0 : _a.app
521
+ })
522
+ );
523
+ return response.data;
524
+ } catch (e) {
525
+ }
526
+ });
527
+ }
528
+ };
529
+
530
+ // src/apis/integrations/github/api.ts
531
+ var gitHubApi = {
532
+ installation: gitHubInstallationApi,
533
+ repository: gitHubRepositoryApi,
534
+ getToken(code, clientId, clientSecret, redirectUrl) {
535
+ return __async(this, null, function* () {
536
+ var _a;
537
+ const data = new URLSearchParams({
538
+ code,
539
+ client_id: clientId,
540
+ client_secret: clientSecret,
541
+ redirect_uri: redirectUrl
542
+ });
543
+ const response = yield import_axios2.default.post(
544
+ "https://github.com/login/oauth/access_token",
545
+ data,
546
+ {
547
+ headers: {
548
+ "Content-Type": "application/x-www-form-urlencoded"
549
+ }
550
+ }
551
+ );
552
+ let params = new URLSearchParams(response.data);
553
+ return (_a = params.get("access_token")) != null ? _a : "";
554
+ });
555
+ }
556
+ };
557
+
558
+ // src/apis/integrations/netlify/instance.ts
559
+ var import_axios3 = __toESM(require("axios"));
560
+ var netlifyClientInstance = import_axios3.default.create({
561
+ baseURL: "https://api.netlify.com/api/v1",
562
+ headers: {
563
+ ["Content-Type"]: "application/json"
564
+ }
565
+ });
566
+ netlifyClientInstance.interceptors.response.use(
567
+ (r) => r,
568
+ (error) => {
569
+ var _a;
570
+ if (import_axios3.default.isAxiosError(error)) {
571
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
572
+ error = new UnauthorizeApiError("netlify");
573
+ }
574
+ }
575
+ throw error;
576
+ }
577
+ );
578
+ function getNetlifyClientAuthorization(req) {
579
+ return {
580
+ token: req.headers["netlify-token"]
581
+ };
582
+ }
583
+ function getNetlifyClientConfig(options = {}) {
584
+ const defaultAuthorization = netlifyClientInstance.defaults.headers["Authorization"];
585
+ const headers = {
586
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
587
+ };
588
+ return {
589
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
590
+ };
591
+ }
592
+ function initNetlifyClientInstance(token) {
593
+ if (token) {
594
+ updateNetlifyClientInstance(token);
595
+ }
596
+ }
597
+ function updateNetlifyClientInstance(token) {
598
+ if (token) {
599
+ netlifyClientInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
600
+ } else {
601
+ delete netlifyClientInstance.defaults.headers["Authorization"];
602
+ }
603
+ }
604
+
605
+ // src/apis/integrations/netlify/account/api.ts
606
+ var netlifyAccountApi = {
607
+ getAccount(authorization) {
608
+ return __async(this, null, function* () {
609
+ const { data: accounts } = yield netlifyClientInstance.get(`/accounts`, getNetlifyClientConfig(authorization));
610
+ return accounts[0].id;
611
+ });
612
+ },
613
+ getAccountEnvs(accountId, siteId, authorization) {
614
+ return __async(this, null, function* () {
615
+ if (!accountId) {
616
+ accountId = yield this.getAccount(authorization);
617
+ }
618
+ if (!accountId) {
619
+ throw new Error("No account");
620
+ }
621
+ const { data: envs } = yield netlifyClientInstance.get(
622
+ `/accounts/${accountId}/env?site_id=${siteId}&scope=all&context=all&level=all`,
623
+ getNetlifyClientConfig(authorization)
624
+ );
625
+ return envs;
626
+ });
627
+ },
628
+ getAccountEnv(accountId, siteId, envKey, authorization) {
629
+ return __async(this, null, function* () {
630
+ if (!accountId) {
631
+ accountId = yield this.getAccount(authorization);
632
+ }
633
+ if (!accountId) {
634
+ throw new Error("No account");
635
+ }
636
+ const { data: envs } = yield netlifyClientInstance.get(
637
+ `/accounts/${accountId}/env/${envKey}?site_id=${siteId}`,
638
+ getNetlifyClientConfig(authorization)
639
+ );
640
+ return envs;
641
+ });
642
+ },
643
+ createAccountEnv(accountId, siteId, envName, envValue, envs, authorization) {
644
+ return __async(this, null, function* () {
645
+ if (!accountId) {
646
+ accountId = yield this.getAccount(authorization);
647
+ }
648
+ if (!accountId) {
649
+ throw new Error("No account");
650
+ }
651
+ if (!envs) {
652
+ const response = yield netlifyClientInstance.get(
653
+ `/accounts/${accountId}/env?site_id=${siteId}&scope=all&context=all&level=all`,
654
+ getNetlifyClientConfig(authorization)
655
+ );
656
+ envs = response.data;
657
+ }
658
+ const existingEnv = envs.find((env) => env.key === envName);
659
+ if (existingEnv) {
660
+ yield netlifyClientInstance.put(
661
+ `/accounts/${accountId}/env/${existingEnv.key}?site_id=${siteId}`,
662
+ {
663
+ key: existingEnv.key,
664
+ scopes: ["builds", "functions", "runtime", "post_processing"],
665
+ values: [{ context: "all", value: envValue }]
666
+ },
667
+ getNetlifyClientConfig(authorization)
668
+ );
669
+ } else {
670
+ yield netlifyClientInstance.post(
671
+ `/accounts/${accountId}/env?site_id=${siteId}`,
672
+ [
673
+ {
674
+ key: envName,
675
+ scopes: ["builds", "functions", "runtime", "post_processing"],
676
+ values: [{ context: "all", value: envValue }]
677
+ }
678
+ ],
679
+ getNetlifyClientConfig(authorization)
680
+ );
681
+ }
682
+ });
683
+ },
684
+ addAccountSentryTokenEnv(siteId, token, authorization) {
685
+ return __async(this, null, function* () {
686
+ const accounts = yield netlifyClientInstance.get(
687
+ `/accounts`,
688
+ getNetlifyClientConfig(authorization)
689
+ );
690
+ const accountId = accounts.data[0].id;
691
+ yield this.createAccountEnv(
692
+ accountId,
693
+ siteId,
694
+ "SENTRY_AUTH_TOKEN",
695
+ token,
696
+ void 0,
697
+ authorization
698
+ );
699
+ });
700
+ }
701
+ };
702
+
703
+ // src/apis/integrations/netlify/hook/api.ts
704
+ var netlifyHookApi = {
705
+ addBuildHooks(siteId, authorization) {
706
+ return __async(this, null, function* () {
707
+ try {
708
+ netlifyClientInstance.post(
709
+ "/hooks",
710
+ {
711
+ site_id: siteId,
712
+ event: "deploy_created",
713
+ type: "url",
714
+ data: {
715
+ url: `${process.env.NEXT_PUBLIC_PLATFORM_DEVELOPER_CONSOLE_ADAPTER_APP_URL}${process.env.NEXT_PUBLIC_PLATFORM_DEVELOPER_CONSOLE_ADAPTER_BASE_PATH}/api/integrations/netlify/webhook`
716
+ }
717
+ },
718
+ getNetlifyClientConfig(authorization)
719
+ );
720
+ } catch (e) {
721
+ }
722
+ try {
723
+ netlifyClientInstance.post(
724
+ "/hooks",
725
+ {
726
+ site_id: siteId,
727
+ event: "deploy_failed",
728
+ type: "url",
729
+ data: {
730
+ url: `${process.env.NEXT_PUBLIC_PLATFORM_DEVELOPER_CONSOLE_ADAPTER_APP_URL}${process.env.NEXT_PUBLIC_PLATFORM_DEVELOPER_CONSOLE_ADAPTER_BASE_PATH}/api/integrations/netlify/webhook`
731
+ }
732
+ },
733
+ getNetlifyClientConfig(authorization)
734
+ );
735
+ } catch (e) {
736
+ }
737
+ try {
738
+ netlifyClientInstance.post(
739
+ "/hooks",
740
+ {
741
+ site_id: siteId,
742
+ event: "deploy_building",
743
+ type: "url",
744
+ data: {
745
+ url: `${process.env.NEXT_PUBLIC_PLATFORM_DEVELOPER_CONSOLE_ADAPTER_APP_URL}${process.env.NEXT_PUBLIC_PLATFORM_DEVELOPER_CONSOLE_ADAPTER_BASE_PATH}/api/integrations/netlify/webhook`
746
+ }
747
+ },
748
+ getNetlifyClientConfig(authorization)
749
+ );
750
+ } catch (e) {
751
+ }
752
+ });
753
+ }
754
+ };
755
+
756
+ // src/apis/integrations/netlify/key/api.ts
757
+ var netlifyKeyApi = {
758
+ createDeployKey(authorization) {
759
+ return __async(this, null, function* () {
760
+ const response = yield netlifyClientInstance.post(
761
+ "/deploy_keys",
762
+ void 0,
763
+ getNetlifyClientConfig(authorization)
764
+ );
765
+ return response.data;
766
+ });
767
+ }
768
+ };
769
+
770
+ // src/apis/integrations/netlify/site/api.ts
771
+ var netlifySiteApi = {
772
+ getSites(authorization) {
773
+ return __async(this, null, function* () {
774
+ const response = yield netlifyClientInstance.get(
775
+ "/sites",
776
+ getNetlifyClientConfig(authorization)
777
+ );
778
+ return response.data;
779
+ });
780
+ },
781
+ getSite(siteId, authorization) {
782
+ return __async(this, null, function* () {
783
+ const response = yield netlifyClientInstance.get(
784
+ `/sites/${siteId}`,
785
+ getNetlifyClientConfig(authorization)
786
+ );
787
+ return response.data;
788
+ });
789
+ },
790
+ getSiteDeploy(siteId, authorization) {
791
+ return __async(this, null, function* () {
792
+ const { data: deploys } = yield netlifyClientInstance.get(
793
+ `/sites/${siteId}/deploys/`,
794
+ getNetlifyClientConfig(authorization)
795
+ );
796
+ const deploy = deploys.filter(
797
+ (deploy2) => deploy2.context === "production"
798
+ )[0];
799
+ const { data: pluginRuns } = yield netlifyClientInstance.get(
800
+ `/deploys/${deploy.id}/plugin_runs`,
801
+ getNetlifyClientConfig(authorization)
802
+ );
803
+ deploy.plugin_runs = pluginRuns;
804
+ return deploy;
805
+ });
806
+ },
807
+ getSiteDeploys(siteId, authorization) {
808
+ return __async(this, null, function* () {
809
+ const { data: deploys } = yield netlifyClientInstance.get(
810
+ `/sites/${siteId}/deploys`,
811
+ getNetlifyClientConfig(authorization)
812
+ );
813
+ return deploys;
814
+ });
815
+ },
816
+ getSiteSnippets(siteId, authorization) {
817
+ return __async(this, null, function* () {
818
+ const { data: snippets } = yield netlifyClientInstance.get(`sites/${siteId}/snippets`, getNetlifyClientConfig(authorization));
819
+ return snippets;
820
+ });
821
+ },
822
+ createSiteByInstallationId(name, repositoryFullName, installationId, branch, authorization) {
823
+ return __async(this, null, function* () {
824
+ const response = yield netlifyClientInstance.post(
825
+ `/sites`,
826
+ {
827
+ name,
828
+ repo: {
829
+ provider: "github",
830
+ repo: repositoryFullName,
831
+ branch,
832
+ private: true,
833
+ installation_id: installationId,
834
+ owner_type: "User",
835
+ plugins: ["@netlify/plugin-nextjs"],
836
+ env: {},
837
+ dir: ".next",
838
+ cmd: "npm run build"
839
+ },
840
+ default_hooks_data: {},
841
+ plugins: [{ package: "@netlify/plugin-nextjs" }],
842
+ created_via: ""
843
+ },
844
+ getNetlifyClientConfig(authorization)
845
+ );
846
+ yield netlifyHookApi.addBuildHooks(response.data.id, authorization);
847
+ return response.data;
848
+ });
849
+ },
850
+ createSiteByDeployKey(name, repositoryFullName, deployKeyId, branch, authorization) {
851
+ return __async(this, null, function* () {
852
+ const response = yield netlifyClientInstance.post(
853
+ `/sites`,
854
+ {
855
+ name,
856
+ repo: {
857
+ provider: "github",
858
+ branch,
859
+ repo: repositoryFullName,
860
+ deploy_key_id: deployKeyId,
861
+ plugins: [
862
+ {
863
+ package: "@netlify/plugin-nextjs"
864
+ }
865
+ ],
866
+ dir: ".next",
867
+ env: {},
868
+ cmd: "npm run build",
869
+ private: true
870
+ },
871
+ plugins: [
872
+ {
873
+ package: "@netlify/plugin-nextjs"
874
+ }
875
+ ],
876
+ created_via: ""
877
+ },
878
+ getNetlifyClientConfig(authorization)
879
+ );
880
+ yield netlifyHookApi.addBuildHooks(response.data.id, authorization);
881
+ return response.data;
882
+ });
883
+ },
884
+ removeSite(siteId, authorization) {
885
+ return __async(this, null, function* () {
886
+ const response = yield netlifyClientInstance.delete(
887
+ `/sites/${siteId}`,
888
+ getNetlifyClientConfig(authorization)
889
+ );
890
+ return response.data;
891
+ });
892
+ },
893
+ triggerSiteBuild(siteId, authorization) {
894
+ return __async(this, null, function* () {
895
+ yield netlifyClientInstance.post(
896
+ `/sites/${siteId}/builds`,
897
+ {},
898
+ getNetlifyClientConfig(authorization)
899
+ );
900
+ });
901
+ },
902
+ addGitHubInstallationToSite(siteId, installationId, authorization) {
903
+ return __async(this, null, function* () {
904
+ const site = yield netlifyClientInstance.get(
905
+ `/sites/${siteId}`,
906
+ getNetlifyClientConfig(authorization)
907
+ );
908
+ yield netlifyClientInstance.put(
909
+ `/sites/${siteId}`,
910
+ {
911
+ repo: {
912
+ provider: site.data.build_settings.provider,
913
+ repo: site.data.build_settings.repo_path,
914
+ branch: site.data.build_settings.allowed_branches[0],
915
+ private: !site.data.build_settings.public_repo,
916
+ installation_id: installationId,
917
+ plugins: site.data.plugins,
918
+ env: site.data.build_settings.env,
919
+ dir: site.data.build_settings.dir,
920
+ cmd: site.data.build_settings.cmd
921
+ }
922
+ },
923
+ getNetlifyClientConfig(authorization)
924
+ );
925
+ });
926
+ },
927
+ addSentryPluginToSite(siteId, projectOrg, projectName, projectKey, token, authorization) {
928
+ return __async(this, null, function* () {
929
+ yield netlifyClientInstance.put(
930
+ `/sites/${siteId}`,
931
+ {
932
+ plugins: [
933
+ {
934
+ package: "@netlify/plugin-nextjs"
935
+ },
936
+ {
937
+ package: "@sentry/netlify-build-plugin"
938
+ }
939
+ ]
940
+ },
941
+ getNetlifyClientConfig(authorization)
942
+ );
943
+ const accountId = yield netlifyAccountApi.getAccount(authorization);
944
+ if (!accountId) {
945
+ throw new Error("Account is missing");
946
+ }
947
+ const snippets = yield this.getSiteSnippets(siteId, authorization);
948
+ const envs = yield netlifyAccountApi.getAccountEnvs(
949
+ accountId,
950
+ siteId,
951
+ authorization
952
+ );
953
+ if (token) {
954
+ yield netlifyAccountApi.createAccountEnv(
955
+ accountId,
956
+ siteId,
957
+ "SENTRY_AUTH_TOKEN",
958
+ token,
959
+ envs,
960
+ authorization
961
+ );
962
+ }
963
+ yield netlifyAccountApi.createAccountEnv(
964
+ accountId,
965
+ siteId,
966
+ "SENTRY_ORG",
967
+ projectOrg,
968
+ envs,
969
+ authorization
970
+ );
971
+ yield netlifyAccountApi.createAccountEnv(
972
+ accountId,
973
+ siteId,
974
+ "SENTRY_PROJECT",
975
+ projectName,
976
+ envs,
977
+ authorization
978
+ );
979
+ const currentSnippet = snippets.find(
980
+ (snippet) => snippet.title === "sentry"
981
+ );
982
+ if (currentSnippet) {
983
+ yield netlifyClientInstance.delete(
984
+ `sites/${siteId}/snippets/${currentSnippet.id}`,
985
+ getNetlifyClientConfig(authorization)
986
+ );
987
+ }
988
+ yield netlifyClientInstance.post(
989
+ `sites/${siteId}/snippets`,
990
+ {
991
+ general_position: "footer",
992
+ title: "sentry",
993
+ // eslint-disable-next-line no-useless-escape
994
+ general: `<script src='https://js.sentry-cdn.com/${projectKey}.min.js' crossorigin="anonymous"></script>`
995
+ },
996
+ getNetlifyClientConfig(authorization)
997
+ );
998
+ return;
999
+ });
1000
+ }
1001
+ };
1002
+
1003
+ // src/apis/integrations/netlify/api.ts
1004
+ var netlifyApi = {
1005
+ account: netlifyAccountApi,
1006
+ site: netlifySiteApi,
1007
+ key: netlifyKeyApi,
1008
+ hook: netlifyHookApi
1009
+ };
1010
+
1011
+ // src/apis/integrations/planetscale/api.ts
1012
+ var import_axios5 = __toESM(require("axios"));
1013
+
1014
+ // src/apis/integrations/planetscale/instance.ts
1015
+ var import_axios4 = __toESM(require("axios"));
1016
+ var planetScaleClientInstance = import_axios4.default.create({
1017
+ baseURL: "https://api.planetscale.com"
1018
+ });
1019
+ planetScaleClientInstance.interceptors.response.use(
1020
+ (r) => r,
1021
+ (error) => {
1022
+ var _a;
1023
+ if (import_axios4.default.isAxiosError(error)) {
1024
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
1025
+ error = new UnauthorizeApiError("planetscale");
1026
+ }
1027
+ }
1028
+ throw error;
1029
+ }
1030
+ );
1031
+ function getPlanetScaleClientAuthorization(req) {
1032
+ return {
1033
+ token: req.headers["planetscale-token"]
1034
+ };
1035
+ }
1036
+ function getPlanetScaleClientConfig(options = {}) {
1037
+ const defaultAuthorization = planetScaleClientInstance.defaults.headers["Authorization"];
1038
+ const headers = {
1039
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `${options.token}` : void 0
1040
+ };
1041
+ if (options.ensureAuthorizationToken && !headers.authorization) {
1042
+ throw new UnauthorizeApiError("planetscale");
1043
+ }
1044
+ return {
1045
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
1046
+ };
1047
+ }
1048
+ function initPlanetScaleClientInstance(token) {
1049
+ if (token) {
1050
+ updatePlanetScaleClientInstance(token);
1051
+ }
1052
+ }
1053
+ function updatePlanetScaleClientInstance(token) {
1054
+ if (token) {
1055
+ planetScaleClientInstance.defaults.headers["Authorization"] = `${token}`;
1056
+ } else {
1057
+ delete planetScaleClientInstance.defaults.headers["Authorization"];
1058
+ }
1059
+ }
1060
+
1061
+ // src/apis/integrations/planetscale/database/password/api.ts
1062
+ var planescaleDatabasePasswordApi = {
1063
+ getDatabasePasswords(organization, databaseName, branchName, authorization) {
1064
+ return __async(this, null, function* () {
1065
+ const response = yield planetScaleClientInstance.get(
1066
+ `/v1/organizations/${organization}/databases/${databaseName}/branches/${branchName}/passwords`,
1067
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1068
+ ensureAuthorizationToken: true
1069
+ }))
1070
+ );
1071
+ return response.data;
1072
+ });
1073
+ },
1074
+ getDatabasePassword(organization, databaseName, branchName, passwordId, authorization) {
1075
+ return __async(this, null, function* () {
1076
+ const response = yield planetScaleClientInstance.get(
1077
+ `/v1/organizations/${organization}/databases/${databaseName}/branches/${branchName}/passwords/${passwordId}`,
1078
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1079
+ ensureAuthorizationToken: true
1080
+ }))
1081
+ );
1082
+ return response.data;
1083
+ });
1084
+ },
1085
+ createDatabasePassword(organization, databaseName, branchName, passwordName, authorization) {
1086
+ return __async(this, null, function* () {
1087
+ const response = yield planetScaleClientInstance.post(
1088
+ `/v1/organizations/${organization}/databases/${databaseName}/branches/${branchName}/passwords`,
1089
+ {
1090
+ name: passwordName
1091
+ },
1092
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1093
+ ensureAuthorizationToken: true
1094
+ }))
1095
+ );
1096
+ return response.data;
1097
+ });
1098
+ },
1099
+ deleteDatabasePassword(organization, databaseName, branchName, passwordId, authorization) {
1100
+ return __async(this, null, function* () {
1101
+ yield planetScaleClientInstance.delete(
1102
+ `/v1/organizations/${organization}/databases/${databaseName}/branches/${branchName}/passwords/${passwordId}`,
1103
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1104
+ ensureAuthorizationToken: true
1105
+ }))
1106
+ );
1107
+ });
1108
+ }
1109
+ };
1110
+
1111
+ // src/apis/integrations/planetscale/database/api.ts
1112
+ var planescaleDatabaseApi = {
1113
+ password: planescaleDatabasePasswordApi,
1114
+ getDatabases(organization, authorization) {
1115
+ return __async(this, null, function* () {
1116
+ const response = yield planetScaleClientInstance.get(
1117
+ `/v1/organizations/${organization}/databases`,
1118
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1119
+ ensureAuthorizationToken: true
1120
+ }))
1121
+ );
1122
+ return response.data;
1123
+ });
1124
+ },
1125
+ getDatabase(organization, databaseName, authorization) {
1126
+ return __async(this, null, function* () {
1127
+ const response = yield planetScaleClientInstance.get(
1128
+ `/v1/organizations/${organization}/databases/${databaseName}`,
1129
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1130
+ ensureAuthorizationToken: true
1131
+ }))
1132
+ );
1133
+ return response.data;
1134
+ });
1135
+ },
1136
+ createDatabase(organization, name, authorization) {
1137
+ return __async(this, null, function* () {
1138
+ const response = yield planetScaleClientInstance.post(
1139
+ `/v1/organizations/${organization}/databases`,
1140
+ {
1141
+ name
1142
+ },
1143
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1144
+ ensureAuthorizationToken: true
1145
+ }))
1146
+ );
1147
+ return response.data;
1148
+ });
1149
+ },
1150
+ removeDatabase(organization, databaseName, authorization) {
1151
+ return __async(this, null, function* () {
1152
+ yield planetScaleClientInstance.delete(
1153
+ `/v1/organizations/${organization}/databases/${databaseName}`,
1154
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1155
+ ensureAuthorizationToken: true
1156
+ }))
1157
+ );
1158
+ });
1159
+ }
1160
+ };
1161
+
1162
+ // src/apis/integrations/planetscale/organization/api.ts
1163
+ var planescaleOrganizationApi = {
1164
+ getOrganizations(authorization) {
1165
+ return __async(this, null, function* () {
1166
+ const response = yield planetScaleClientInstance.get(
1167
+ `/v1/organizations`,
1168
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1169
+ ensureAuthorizationToken: true
1170
+ }))
1171
+ );
1172
+ return response.data;
1173
+ });
1174
+ },
1175
+ getOrganization(organization, authorization) {
1176
+ return __async(this, null, function* () {
1177
+ const response = yield planetScaleClientInstance.get(
1178
+ `/v1/organizations/${organization}`,
1179
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1180
+ ensureAuthorizationToken: true
1181
+ }))
1182
+ );
1183
+ return response.data;
1184
+ });
1185
+ }
1186
+ };
1187
+
1188
+ // src/apis/integrations/planetscale/user/api.ts
1189
+ var planescaleUserApi = {
1190
+ getUser(authorization) {
1191
+ return __async(this, null, function* () {
1192
+ const response = yield planetScaleClientInstance.get(
1193
+ `/v1/user`,
1194
+ getPlanetScaleClientConfig(__spreadProps(__spreadValues({}, authorization), {
1195
+ ensureAuthorizationToken: true
1196
+ }))
1197
+ );
1198
+ return response.data;
1199
+ });
1200
+ }
1201
+ };
1202
+
1203
+ // src/apis/integrations/planetscale/api.ts
1204
+ var planetscaleApi = {
1205
+ database: planescaleDatabaseApi,
1206
+ organization: planescaleOrganizationApi,
1207
+ user: planescaleUserApi,
1208
+ getToken(applicationId, organization, code, clientId, clientSecret, serviceTokenId, serviceToken, redirectUrl) {
1209
+ return __async(this, null, function* () {
1210
+ const data = new URLSearchParams({
1211
+ code,
1212
+ client_id: clientId,
1213
+ client_secret: clientSecret,
1214
+ redirect_uri: redirectUrl,
1215
+ grant_type: "authorization_code"
1216
+ });
1217
+ const response = yield import_axios5.default.post(
1218
+ `https://api.planetscale.com/v1/organizations/${organization}/oauth-applications/${applicationId}/token`,
1219
+ data,
1220
+ {
1221
+ headers: {
1222
+ "Content-Type": "application/x-www-form-urlencoded",
1223
+ Authorization: `${serviceTokenId}:${serviceToken}`
1224
+ }
1225
+ }
1226
+ );
1227
+ return {
1228
+ tokenId: response.data.id,
1229
+ token: response.data.token,
1230
+ refreshToken: response.data.plain_text_refresh_token
1231
+ };
1232
+ });
1233
+ }
1234
+ };
1235
+
1236
+ // src/apis/integrations/sentry/instance.ts
1237
+ var import_axios6 = __toESM(require("axios"));
1238
+ var sentryClientInstance = import_axios6.default.create({
1239
+ baseURL: "https://sentry.io/api/0/",
1240
+ headers: {
1241
+ ["Content-Type"]: "application/json"
1242
+ }
1243
+ });
1244
+ sentryClientInstance.interceptors.response.use(
1245
+ (r) => r,
1246
+ (error) => {
1247
+ var _a;
1248
+ if (import_axios6.default.isAxiosError(error)) {
1249
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
1250
+ error = new UnauthorizeApiError("sentry");
1251
+ }
1252
+ }
1253
+ throw error;
1254
+ }
1255
+ );
1256
+ function getSentryClientAuthorization(req) {
1257
+ return {
1258
+ token: req.headers["sentry-token"]
1259
+ };
1260
+ }
1261
+ function getSentryClientConfig(options = {}) {
1262
+ const defaultAuthorization = sentryClientInstance.defaults.headers["Authorization"];
1263
+ const headers = {
1264
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
1265
+ };
1266
+ return {
1267
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
1268
+ };
1269
+ }
1270
+ function initSentryClientInstance(token) {
1271
+ updateSentryClientInstance(token);
1272
+ if (token) {
1273
+ updateSentryClientInstance(token);
1274
+ }
1275
+ }
1276
+ function updateSentryClientInstance(token) {
1277
+ if (token) {
1278
+ sentryClientInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
1279
+ } else {
1280
+ delete sentryClientInstance.defaults.headers["Authorization"];
1281
+ }
1282
+ }
1283
+
1284
+ // src/apis/integrations/sentry/api.ts
1285
+ var sentryApi = {
1286
+ getTeam(teamSlug, authorization) {
1287
+ return __async(this, null, function* () {
1288
+ const response = yield sentryClientInstance.get(
1289
+ `/teams/${teamSlug}/`,
1290
+ getSentryClientConfig(authorization)
1291
+ );
1292
+ return response.data;
1293
+ });
1294
+ },
1295
+ getOrganizations(authorization) {
1296
+ return __async(this, null, function* () {
1297
+ const response = yield sentryClientInstance.get(
1298
+ "/organizations/",
1299
+ getSentryClientConfig(authorization)
1300
+ );
1301
+ return response.data;
1302
+ });
1303
+ },
1304
+ getOrganization(organizationSlug, authorization) {
1305
+ return __async(this, null, function* () {
1306
+ const response = yield sentryClientInstance.get(
1307
+ `/organizations/${organizationSlug}/`,
1308
+ getSentryClientConfig(authorization)
1309
+ );
1310
+ return response.data;
1311
+ });
1312
+ },
1313
+ getOrganizationRepos(organizationSlug, authorization) {
1314
+ return __async(this, null, function* () {
1315
+ const response = yield sentryClientInstance.get(
1316
+ `/organizations/${organizationSlug}/repos/`,
1317
+ getSentryClientConfig(authorization)
1318
+ );
1319
+ return response.data;
1320
+ });
1321
+ },
1322
+ getOrganizationIntegrations(organizationSlug, authorization) {
1323
+ return __async(this, null, function* () {
1324
+ const response = yield sentryClientInstance.get(
1325
+ `/organizations/${organizationSlug}/integrations/`,
1326
+ getSentryClientConfig(authorization)
1327
+ );
1328
+ return response.data;
1329
+ });
1330
+ },
1331
+ getProjects(authorization) {
1332
+ return __async(this, null, function* () {
1333
+ const response = yield sentryClientInstance.get(
1334
+ "/projects/",
1335
+ getSentryClientConfig(authorization)
1336
+ );
1337
+ return response.data;
1338
+ });
1339
+ },
1340
+ getProject(projectFullName, authorization) {
1341
+ return __async(this, null, function* () {
1342
+ const response = yield sentryClientInstance.get(
1343
+ `/projects/${projectFullName}/`,
1344
+ getSentryClientConfig(authorization)
1345
+ );
1346
+ return response.data;
1347
+ });
1348
+ },
1349
+ getProjectIssues(projectFullName, authorization) {
1350
+ return __async(this, null, function* () {
1351
+ const response = yield sentryClientInstance.get(
1352
+ `/projects/${projectFullName}/issues/`,
1353
+ getSentryClientConfig(authorization)
1354
+ );
1355
+ return response.data;
1356
+ });
1357
+ },
1358
+ getProjectIssueLatestEvent(issueId, authorization) {
1359
+ return __async(this, null, function* () {
1360
+ const response = yield sentryClientInstance.get(
1361
+ `/issues/${issueId}/events/latest/`,
1362
+ getSentryClientConfig(authorization)
1363
+ );
1364
+ return response.data;
1365
+ });
1366
+ },
1367
+ getProjectKeys(projectFullName, authorization) {
1368
+ return __async(this, null, function* () {
1369
+ const response = yield sentryClientInstance.get(
1370
+ `/projects/${projectFullName}/keys/`,
1371
+ getSentryClientConfig(authorization)
1372
+ );
1373
+ return response.data;
1374
+ });
1375
+ },
1376
+ createTeam(organizationSlug, teamName, authorization) {
1377
+ return __async(this, null, function* () {
1378
+ const { data: team } = yield sentryClientInstance.post(
1379
+ `/organizations/${organizationSlug}/teams/`,
1380
+ {
1381
+ name: teamName,
1382
+ slug: teamName
1383
+ },
1384
+ getSentryClientConfig(authorization)
1385
+ );
1386
+ return team;
1387
+ });
1388
+ },
1389
+ createRepo(organizationSlug, projectId, repositoryFullName, repositoryBranch, githubIntegrationId, authorization) {
1390
+ return __async(this, null, function* () {
1391
+ var _a, _b, _c, _d;
1392
+ let repository;
1393
+ try {
1394
+ const response = yield sentryClientInstance.post(
1395
+ `/organizations/${organizationSlug}/repos/`,
1396
+ {
1397
+ installation: githubIntegrationId,
1398
+ identifier: repositoryFullName,
1399
+ provider: "integrations:github"
1400
+ },
1401
+ getSentryClientConfig(authorization)
1402
+ );
1403
+ repository = response.data;
1404
+ } catch (err) {
1405
+ const error = err;
1406
+ if (((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.error_type) === "validation" || ((_d = (_c = error == null ? void 0 : error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.error_type) === "unknown") {
1407
+ throw error;
1408
+ }
1409
+ const response = yield sentryClientInstance.get(
1410
+ `/organizations/${organizationSlug}/repos/`,
1411
+ getSentryClientConfig(authorization)
1412
+ );
1413
+ repository = response.data.find(
1414
+ (repo) => repo.externalSlug === repositoryFullName
1415
+ );
1416
+ }
1417
+ if (!repository) {
1418
+ throw new Error("Couldn't get repository");
1419
+ }
1420
+ try {
1421
+ yield sentryClientInstance.post(
1422
+ `/organizations/${organizationSlug}/code-mappings/`,
1423
+ {
1424
+ defaultBranch: repositoryBranch,
1425
+ stackRoot: "",
1426
+ sourceRoot: "",
1427
+ repositoryId: repository.id,
1428
+ integrationId: githubIntegrationId,
1429
+ projectId
1430
+ },
1431
+ getSentryClientConfig(authorization)
1432
+ );
1433
+ } catch (e) {
1434
+ }
1435
+ });
1436
+ },
1437
+ createProject(organizationSlug, appName, authorization) {
1438
+ return __async(this, null, function* () {
1439
+ var _a;
1440
+ const name = appName.toLowerCase();
1441
+ try {
1442
+ yield this.createTeam(organizationSlug, name, authorization);
1443
+ } catch (e) {
1444
+ }
1445
+ try {
1446
+ const response = yield sentryClientInstance.post(
1447
+ `/teams/${organizationSlug}/${name}/projects/`,
1448
+ {
1449
+ name,
1450
+ slug: name
1451
+ },
1452
+ getSentryClientConfig(authorization)
1453
+ );
1454
+ return yield this.getProject(
1455
+ `${organizationSlug}/${response.data.slug}`,
1456
+ authorization
1457
+ );
1458
+ } catch (error) {
1459
+ if (((_a = error.response) == null ? void 0 : _a.status) === 409) {
1460
+ return yield this.getProject(
1461
+ `${organizationSlug}/${name}`,
1462
+ authorization
1463
+ );
1464
+ }
1465
+ throw error;
1466
+ }
1467
+ });
1468
+ },
1469
+ deleteProject(projectFullName, authorization) {
1470
+ return __async(this, null, function* () {
1471
+ const response = yield sentryClientInstance.delete(
1472
+ `/projects/${projectFullName}/`,
1473
+ getSentryClientConfig(authorization)
1474
+ );
1475
+ return response.data;
1476
+ });
1477
+ }
1478
+ };
1479
+
1480
+ // src/apis/integrations/vercel/api.ts
1481
+ var import_axios8 = __toESM(require("axios"));
1482
+
1483
+ // src/apis/integrations/vercel/instance.ts
1484
+ var import_axios7 = __toESM(require("axios"));
1485
+ var vercelClientInstance = import_axios7.default.create({
1486
+ baseURL: "https://api.vercel.com"
1487
+ });
1488
+ vercelClientInstance.interceptors.response.use(
1489
+ (r) => r,
1490
+ (error) => {
1491
+ var _a;
1492
+ if (import_axios7.default.isAxiosError(error)) {
1493
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401) {
1494
+ error = new UnauthorizeApiError("vercel");
1495
+ }
1496
+ }
1497
+ throw error;
1498
+ }
1499
+ );
1500
+ function getVercelClientAuthorization(req) {
1501
+ return {
1502
+ token: req.headers["vercel-token"]
1503
+ };
1504
+ }
1505
+ function getVercelClientConfig(options = {}) {
1506
+ const defaultAuthorization = vercelClientInstance.defaults.headers["Authorization"];
1507
+ const headers = {
1508
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
1509
+ };
1510
+ return {
1511
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
1512
+ };
1513
+ }
1514
+ function initVercelClientInstance(token) {
1515
+ if (token) {
1516
+ updateVercelClientInstance(token);
1517
+ }
1518
+ }
1519
+ function updateVercelClientInstance(token) {
1520
+ if (token) {
1521
+ vercelClientInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
1522
+ } else {
1523
+ delete vercelClientInstance.defaults.headers["Authorization"];
1524
+ }
1525
+ }
1526
+
1527
+ // src/apis/integrations/vercel/deploy/api.ts
1528
+ var vercelDeployApi = {
1529
+ createDeploy(project, repoId, branch, authorization) {
1530
+ return __async(this, null, function* () {
1531
+ const response = yield vercelClientInstance.post(
1532
+ `/v13/deployments`,
1533
+ {
1534
+ gitSource: { type: "github", ref: branch, repoId },
1535
+ name: project,
1536
+ target: "production",
1537
+ source: "import"
1538
+ },
1539
+ getVercelClientConfig(authorization)
1540
+ );
1541
+ return response.data;
1542
+ });
1543
+ }
1544
+ };
1545
+
1546
+ // src/apis/integrations/vercel/integrations/api.ts
1547
+ var vercelIntegrationApi = {
1548
+ getGitNamespaces(authorization) {
1549
+ return __async(this, null, function* () {
1550
+ const response = yield vercelClientInstance.get(
1551
+ `/v1/integrations/git-namespaces?provider=github`,
1552
+ getVercelClientConfig(authorization)
1553
+ );
1554
+ return response.data;
1555
+ });
1556
+ },
1557
+ getGitRepos(repositoryName, namespaceId, authorization) {
1558
+ return __async(this, null, function* () {
1559
+ var _a;
1560
+ try {
1561
+ const response = yield vercelClientInstance.get(
1562
+ `/v1/integrations/search-repo?provider=github${repositoryName ? "&query=" + repositoryName : ""}${namespaceId ? "&namespaceId=" + namespaceId : ""}`,
1563
+ getVercelClientConfig(authorization)
1564
+ );
1565
+ return {
1566
+ provider: response.data.gitAccount.provider,
1567
+ namespaceId: response.data.gitAccount.namespaceId,
1568
+ repos: response.data.repos
1569
+ };
1570
+ } catch (err) {
1571
+ const error = err;
1572
+ if (error.isAxiosError && ((_a = error.response) == null ? void 0 : _a.data.error.code) === "installation_not_found") {
1573
+ return {
1574
+ repos: []
1575
+ };
1576
+ }
1577
+ throw error;
1578
+ }
1579
+ });
1580
+ },
1581
+ isRepositoryAccessible(repositoryName, authorization) {
1582
+ return __async(this, null, function* () {
1583
+ var _a;
1584
+ try {
1585
+ const namespaces = yield this.getGitNamespaces(authorization);
1586
+ const accessibleNamespaceId = namespaces.length > 0 ? (yield Promise.all(
1587
+ namespaces.map(
1588
+ (namespace) => this.getGitRepos(repositoryName, namespace.id, authorization)
1589
+ )
1590
+ )).map(
1591
+ (repositories) => repositories.repos.length > 0 ? repositories.namespaceId : void 0
1592
+ )[0] : (_a = yield this.getGitRepos(repositoryName, void 0, authorization)) == null ? void 0 : _a.namespaceId;
1593
+ return {
1594
+ isAccessible: !!accessibleNamespaceId,
1595
+ installationId: accessibleNamespaceId
1596
+ };
1597
+ } catch (err) {
1598
+ return {
1599
+ isAccessible: false
1600
+ };
1601
+ }
1602
+ });
1603
+ },
1604
+ isUserConnectedToGitHub(authorization) {
1605
+ return __async(this, null, function* () {
1606
+ try {
1607
+ const { provider } = yield this.getGitRepos(
1608
+ void 0,
1609
+ void 0,
1610
+ authorization
1611
+ );
1612
+ return provider === "github";
1613
+ } catch (e) {
1614
+ return false;
1615
+ }
1616
+ });
1617
+ }
1618
+ };
1619
+
1620
+ // src/apis/integrations/vercel/project/api.ts
1621
+ var vercelProjectApi = {
1622
+ getProjects(authorization) {
1623
+ return __async(this, null, function* () {
1624
+ const response = yield vercelClientInstance.get(
1625
+ "/v9/projects",
1626
+ getVercelClientConfig(authorization)
1627
+ );
1628
+ return response.data;
1629
+ });
1630
+ },
1631
+ getProject(projectId, authorization) {
1632
+ return __async(this, null, function* () {
1633
+ const response = yield vercelClientInstance.get(
1634
+ `/v9/projects/${projectId}`,
1635
+ getVercelClientConfig(authorization)
1636
+ );
1637
+ return response.data;
1638
+ });
1639
+ },
1640
+ createProject(name, repositoryFullName, branch, authorization) {
1641
+ return __async(this, null, function* () {
1642
+ const response = yield vercelClientInstance.post(
1643
+ `/v9/projects`,
1644
+ {
1645
+ name,
1646
+ gitRepository: {
1647
+ type: "github",
1648
+ repo: repositoryFullName,
1649
+ sourceless: true
1650
+ },
1651
+ framework: "nextjs"
1652
+ },
1653
+ getVercelClientConfig(authorization)
1654
+ );
1655
+ return response.data;
1656
+ });
1657
+ },
1658
+ removeProject(projectId, authorization) {
1659
+ return __async(this, null, function* () {
1660
+ yield vercelClientInstance.delete(
1661
+ `/projects/${projectId}`,
1662
+ getVercelClientConfig(authorization)
1663
+ );
1664
+ });
1665
+ },
1666
+ getProjectEnvs(projectId, authorization) {
1667
+ return __async(this, null, function* () {
1668
+ const {
1669
+ data: { envs }
1670
+ } = yield vercelClientInstance.get(`/v9/projects/${projectId}/env`, getVercelClientConfig(authorization));
1671
+ return envs;
1672
+ });
1673
+ },
1674
+ getProjectEnv(projectId, envId, authorization) {
1675
+ return __async(this, null, function* () {
1676
+ const { data } = yield vercelClientInstance.get(
1677
+ `/v9/projects/${projectId}/env/${envId}`,
1678
+ getVercelClientConfig(authorization)
1679
+ );
1680
+ return data;
1681
+ });
1682
+ },
1683
+ getProjectEnvByKey(projectId, envKey, authorization) {
1684
+ return __async(this, null, function* () {
1685
+ const envs = yield this.getProjectEnvs(projectId, authorization);
1686
+ const env = envs.find((env2) => envKey === env2.key);
1687
+ if (!env) {
1688
+ return;
1689
+ }
1690
+ return yield this.getProjectEnv(projectId, env.id, authorization);
1691
+ });
1692
+ },
1693
+ createProjectEnv(projectId, key, value, envs, authorization) {
1694
+ return __async(this, null, function* () {
1695
+ if (!envs) {
1696
+ const response = yield vercelClientInstance.get(`/v9/projects/${projectId}/env`, getVercelClientConfig(authorization));
1697
+ envs = response.data.envs;
1698
+ }
1699
+ const existingEnv = envs.find((env) => env.key === key);
1700
+ if (existingEnv) {
1701
+ const { data: editedEnv } = yield vercelClientInstance.patch(
1702
+ `/v9/projects/${projectId}/env/${existingEnv == null ? void 0 : existingEnv.id}`,
1703
+ {
1704
+ key,
1705
+ value,
1706
+ type: "encrypted",
1707
+ target: ["production", "preview", "development"]
1708
+ },
1709
+ getVercelClientConfig(authorization)
1710
+ );
1711
+ return editedEnv;
1712
+ } else {
1713
+ const { data: createdEnv } = yield vercelClientInstance.post(
1714
+ `/v9/projects/${projectId}/env`,
1715
+ {
1716
+ key,
1717
+ value,
1718
+ type: "encrypted",
1719
+ target: ["production", "preview", "development"]
1720
+ },
1721
+ getVercelClientConfig(authorization)
1722
+ );
1723
+ return createdEnv;
1724
+ }
1725
+ });
1726
+ }
1727
+ };
1728
+
1729
+ // src/apis/integrations/vercel/api.ts
1730
+ var vercelApi = {
1731
+ project: vercelProjectApi,
1732
+ deploy: vercelDeployApi,
1733
+ integrations: vercelIntegrationApi,
1734
+ getToken(code, clientId, clientSecret, redirectUrl) {
1735
+ return __async(this, null, function* () {
1736
+ const data = new URLSearchParams({
1737
+ code,
1738
+ client_id: clientId,
1739
+ client_secret: clientSecret,
1740
+ redirect_uri: redirectUrl
1741
+ });
1742
+ const response = yield import_axios8.default.post(
1743
+ "https://api.vercel.com/v2/oauth/access_token",
1744
+ data,
1745
+ {
1746
+ headers: {
1747
+ "Content-Type": "application/x-www-form-urlencoded"
1748
+ }
1749
+ }
1750
+ );
1751
+ return {
1752
+ token: response.data.access_token,
1753
+ installationId: response.data.installation_id,
1754
+ userId: response.data.user_id,
1755
+ teamId: response.data.team_id
1756
+ };
1757
+ });
1758
+ }
1759
+ };
1760
+
1761
+ // src/apis/integrations/api.ts
1762
+ var integrationsApi = {
1763
+ github: gitHubApi,
1764
+ netlify: netlifyApi,
1765
+ vercel: vercelApi,
1766
+ planetscale: planetscaleApi,
1767
+ sentry: sentryApi
1768
+ };
1769
+
1770
+ // src/apis/products/livechat/instance.ts
1771
+ var import_axios9 = __toESM(require("axios"));
1772
+ var REGION = {
1773
+ FRA: "fra",
1774
+ DAL: "dal",
1775
+ FRA_A: "fra-a",
1776
+ FRA_B: "fra-b"
1777
+ };
1778
+ var supportedRegions = Object.values(REGION);
1779
+ var getRegion = (token) => {
1780
+ const region = token.split(":")[0];
1781
+ if (supportedRegions.includes(region)) {
1782
+ return region;
1783
+ }
1784
+ return void 0;
1785
+ };
1786
+ var livechatClientInstance = import_axios9.default.create({
1787
+ baseURL: "https://api.labs.livechatinc.com"
1788
+ });
1789
+ function getLiveChatClientAuthorization(req) {
1790
+ return {
1791
+ token: req.headers["livechat-token"]
1792
+ };
1793
+ }
1794
+ function getLiveChatClientConfig(options = {}) {
1795
+ const defaultAuthorization = livechatClientInstance.defaults.headers["Authorization"];
1796
+ const headers = {
1797
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
1798
+ };
1799
+ return {
1800
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
1801
+ };
1802
+ }
1803
+ function initLiveChatClientInstance(baseUrl, token) {
1804
+ const region = token ? getRegion(token) : void 0;
1805
+ if (baseUrl) {
1806
+ livechatClientInstance.interceptors.request.use(
1807
+ (config) => __async(this, null, function* () {
1808
+ config.baseURL = baseUrl;
1809
+ return config;
1810
+ }),
1811
+ (error) => Promise.reject(error)
1812
+ );
1813
+ }
1814
+ if (region) {
1815
+ livechatClientInstance.defaults.headers["X-Region"] = region;
1816
+ }
1817
+ if (token) {
1818
+ livechatClientInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
1819
+ } else {
1820
+ delete livechatClientInstance.defaults.headers["Authorization"];
1821
+ }
1822
+ }
1823
+
1824
+ // src/apis/products/livechat/agents/api.ts
1825
+ var livechatAgentApi = {
1826
+ getUser() {
1827
+ return __async(this, null, function* () {
1828
+ try {
1829
+ const response = yield livechatClientInstance.get(
1830
+ `/agents/me`,
1831
+ {
1832
+ headers: {
1833
+ "X-API-Version": 2
1834
+ }
1835
+ }
1836
+ );
1837
+ return response.data;
1838
+ } catch (error) {
1839
+ if (error instanceof Error) {
1840
+ throw new Error(`User couldn't be fetched. [${error.message}]`);
1841
+ }
1842
+ throw error;
1843
+ }
1844
+ });
1845
+ }
1846
+ };
1847
+
1848
+ // src/constants/notifications.ts
1849
+ var API_NOTIFICATIONS = {
1850
+ BUILDING_BLOCKS: {
1851
+ SUCCESS: {
1852
+ CREATED: "Building block created successfully.",
1853
+ UPDATED: "Building block updated successfully.",
1854
+ DELETED: "Building block deleted successfully."
1855
+ },
1856
+ FAILURE: {
1857
+ CREATED: "Building block couldn't be created.",
1858
+ UPDATED: "Building block couldn't be updated.",
1859
+ DELETED: "Building block couldn't be deleted."
1860
+ }
1861
+ }
1862
+ };
1863
+
1864
+ // src/apis/products/livechat/configuration/properties/api.ts
1865
+ var livechatPropertyApi = {
1866
+ getProperties(clientId, isAgent) {
1867
+ return __async(this, null, function* () {
1868
+ if (isAgent) {
1869
+ return {
1870
+ data: {}
1871
+ };
1872
+ }
1873
+ try {
1874
+ const response = yield livechatClientInstance.post(
1875
+ `/v3.3/configuration/action/list_properties`,
1876
+ {
1877
+ owner_client_id: clientId
1878
+ }
1879
+ );
1880
+ return response;
1881
+ } catch (error) {
1882
+ if (error instanceof Error) {
1883
+ throw new Error(`Properties couldn't be fetched. [${error.message}]`);
1884
+ } else {
1885
+ throw error;
1886
+ }
1887
+ }
1888
+ });
1889
+ },
1890
+ registerProperty(property) {
1891
+ return __async(this, null, function* () {
1892
+ try {
1893
+ const response = yield livechatClientInstance.post(
1894
+ `/v3.3/configuration/action/register_property`,
1895
+ {
1896
+ name: property.name,
1897
+ owner_client_id: property.owner_client_id,
1898
+ type: property.type,
1899
+ access: property.access,
1900
+ description: property.description,
1901
+ domain: property.domain,
1902
+ range: property.range,
1903
+ default_value: property.default_value
1904
+ }
1905
+ );
1906
+ return response;
1907
+ } catch (error) {
1908
+ if (error instanceof Error) {
1909
+ throw new Error(`Property couldn't be created. [${error.message}]`);
1910
+ } else {
1911
+ throw error;
1912
+ }
1913
+ }
1914
+ });
1915
+ },
1916
+ unregisterProperty(propertyId, clientId, properties) {
1917
+ return __async(this, null, function* () {
1918
+ try {
1919
+ const response = yield livechatClientInstance.post(
1920
+ `/v3.3/configuration/action/unregister_property`,
1921
+ {
1922
+ name: propertyId,
1923
+ owner_client_id: clientId
1924
+ }
1925
+ );
1926
+ return response;
1927
+ } catch (error) {
1928
+ if (error instanceof Error) {
1929
+ if (properties) {
1930
+ throw new Error(
1931
+ `${properties.length > 1 ? "Property couldn't be deleted." : API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
1932
+ );
1933
+ } else {
1934
+ throw new Error(`Property couldn't be deleted. [${error.message}]`);
1935
+ }
1936
+ } else {
1937
+ throw error;
1938
+ }
1939
+ }
1940
+ });
1941
+ },
1942
+ publishProperty(propertyId, clientId, accessType) {
1943
+ return __async(this, null, function* () {
1944
+ try {
1945
+ const response = yield livechatClientInstance.post(
1946
+ `/v3.3/configuration/action/publish_property`,
1947
+ {
1948
+ name: propertyId,
1949
+ owner_client_id: clientId,
1950
+ access_type: accessType
1951
+ }
1952
+ );
1953
+ return response;
1954
+ } catch (error) {
1955
+ if (error instanceof Error) {
1956
+ throw new Error(`Property couldn't be published. [${error.message}]`);
1957
+ } else {
1958
+ throw error;
1959
+ }
1960
+ }
1961
+ });
1962
+ },
1963
+ publishProperties(properties) {
1964
+ return __async(this, null, function* () {
1965
+ try {
1966
+ const response = yield Promise.all(
1967
+ properties.filter((property) => property.public_access).map((property) => __async(this, null, function* () {
1968
+ return yield livechatClientInstance.post(
1969
+ `/v3.3/configuration/action/publish_property`,
1970
+ {
1971
+ name: property.name,
1972
+ owner_client_id: property.owner_client_id,
1973
+ access_type: property.public_access
1974
+ }
1975
+ );
1976
+ }))
1977
+ );
1978
+ return response;
1979
+ } catch (error) {
1980
+ if (error instanceof Error) {
1981
+ throw new Error(`Properties couldn't be published. [${error.message}]`);
1982
+ } else {
1983
+ throw error;
1984
+ }
1985
+ }
1986
+ });
1987
+ },
1988
+ registerProperties(properties) {
1989
+ return __async(this, null, function* () {
1990
+ try {
1991
+ const response = yield Promise.all(
1992
+ properties.map((property) => __async(this, null, function* () {
1993
+ return yield livechatClientInstance.post(
1994
+ `/v3.3/configuration/action/register_property`,
1995
+ {
1996
+ name: property.name,
1997
+ type: property.type,
1998
+ owner_client_id: property.owner_client_id,
1999
+ domain: property.domain,
2000
+ range: property.range,
2001
+ access: property.access,
2002
+ default_value: property.default_value
2003
+ }
2004
+ );
2005
+ }))
2006
+ );
2007
+ return response;
2008
+ } catch (error) {
2009
+ if (error instanceof Error) {
2010
+ throw new Error(`Properties couldn't be created. [${error.message}]`);
2011
+ } else {
2012
+ throw error;
2013
+ }
2014
+ }
2015
+ });
2016
+ },
2017
+ unregisterProperties(clientId) {
2018
+ return __async(this, null, function* () {
2019
+ const { data: properties } = yield this.getProperties(clientId);
2020
+ try {
2021
+ yield Promise.all(
2022
+ Object.keys(properties).map((property) => __async(this, null, function* () {
2023
+ if (Object.keys(properties[property]).indexOf("public_access") <= 0) {
2024
+ return yield livechatClientInstance.post(
2025
+ `/v3.3/configuration/action/unregister_property`,
2026
+ {
2027
+ name: property,
2028
+ owner_client_id: clientId
2029
+ }
2030
+ );
2031
+ }
2032
+ }))
2033
+ );
2034
+ } catch (error) {
2035
+ if (error instanceof Error) {
2036
+ throw new Error(`Properties couldn't be removed. [${error.message}]`);
2037
+ } else {
2038
+ throw error;
2039
+ }
2040
+ }
2041
+ });
2042
+ }
2043
+ };
2044
+
2045
+ // src/apis/products/livechat/configuration/webhooks/api.ts
2046
+ var livechatWebhookApi = {
2047
+ getWebhooks(clientId, isAgent) {
2048
+ return __async(this, null, function* () {
2049
+ if (isAgent) {
2050
+ return {
2051
+ data: []
2052
+ };
2053
+ }
2054
+ try {
2055
+ const response = yield livechatClientInstance.post(
2056
+ `/v3.5/configuration/action/list_webhooks`,
2057
+ {
2058
+ owner_client_id: clientId
2059
+ }
2060
+ );
2061
+ return response;
2062
+ } catch (error) {
2063
+ if (error instanceof Error) {
2064
+ throw new Error(
2065
+ `Registered Webhooks couldn't be fetched. [${error.message}]`
2066
+ );
2067
+ } else {
2068
+ throw error;
2069
+ }
2070
+ }
2071
+ });
2072
+ },
2073
+ unregisterWebhook(clientId, webhookId) {
2074
+ return __async(this, null, function* () {
2075
+ try {
2076
+ const response = yield livechatClientInstance.post(
2077
+ `/v3.5/configuration/action/unregister_webhook`,
2078
+ {
2079
+ id: webhookId,
2080
+ owner_client_id: clientId
2081
+ }
2082
+ );
2083
+ return response;
2084
+ } catch (error) {
2085
+ if (error instanceof Error) {
2086
+ throw new Error(
2087
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
2088
+ );
2089
+ } else {
2090
+ throw error;
2091
+ }
2092
+ }
2093
+ });
2094
+ },
2095
+ unregisterWebhooks(clientId) {
2096
+ return __async(this, null, function* () {
2097
+ try {
2098
+ const { data: webhooks } = yield this.getWebhooks(clientId);
2099
+ yield Promise.all(
2100
+ webhooks.map((webhook) => __async(this, null, function* () {
2101
+ return yield livechatClientInstance.post(
2102
+ `/v3.5/configuration/action/unregister_webhook`,
2103
+ {
2104
+ id: webhook.id,
2105
+ owner_client_id: clientId
2106
+ }
2107
+ );
2108
+ }))
2109
+ );
2110
+ } catch (error) {
2111
+ if (error instanceof Error) {
2112
+ throw new Error(
2113
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
2114
+ );
2115
+ } else {
2116
+ throw error;
2117
+ }
2118
+ }
2119
+ });
2120
+ },
2121
+ registerWebhooks(webhooks) {
2122
+ return __async(this, null, function* () {
2123
+ try {
2124
+ yield this.unregisterWebhooks(webhooks[0]["owner_client_id"]);
2125
+ yield Promise.all(
2126
+ webhooks.map((webhook) => __async(this, null, function* () {
2127
+ return yield livechatClientInstance.post(
2128
+ `/v${webhook.api_version || "3.5"}/configuration/action/register_webhook`,
2129
+ {
2130
+ url: webhook.url,
2131
+ action: webhook.action,
2132
+ secret_key: webhook.secret_key,
2133
+ owner_client_id: webhook.owner_client_id,
2134
+ type: webhook.type,
2135
+ description: webhook.description,
2136
+ filters: webhook.filters
2137
+ }
2138
+ );
2139
+ }))
2140
+ );
2141
+ } catch (error) {
2142
+ if (error instanceof Error) {
2143
+ throw new Error(
2144
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.CREATED} [${error.message}]`
2145
+ );
2146
+ } else {
2147
+ throw error;
2148
+ }
2149
+ }
2150
+ });
2151
+ },
2152
+ migrateWebhooks(webhooks, clientId) {
2153
+ return __async(this, null, function* () {
2154
+ try {
2155
+ const webhooksToCheck = webhooks.map((webhook) => {
2156
+ return {
2157
+ api_version: "3.2",
2158
+ action: webhook.action,
2159
+ filters: webhook.filters
2160
+ };
2161
+ });
2162
+ const { data: verifiedWebhooks } = yield livechatClientInstance.post(
2163
+ `/v3.3/configuration/action/check_webhooks_migration`,
2164
+ [...webhooksToCheck]
2165
+ );
2166
+ const updatedWebhooks = webhooks.map((webhook, index) => {
2167
+ return __spreadProps(__spreadValues({}, webhook), {
2168
+ action: verifiedWebhooks[index].action
2169
+ });
2170
+ });
2171
+ yield livechatClientInstance.post(
2172
+ `/v3.3/configuration/action/migrate_webhooks`,
2173
+ {
2174
+ owner_client_id: clientId,
2175
+ webhooks: updatedWebhooks
2176
+ }
2177
+ );
2178
+ } catch (error) {
2179
+ if (error instanceof Error) {
2180
+ throw new Error(
2181
+ `Migration failed. It looks like one of the webhooks you're trying to migrate doesn't exist in the new version or exists under a different name. Migrate the webhook manually via the Configuration API. `
2182
+ );
2183
+ } else {
2184
+ throw error;
2185
+ }
2186
+ }
2187
+ });
2188
+ },
2189
+ getLicenseWebhooksList(isAgent) {
2190
+ return __async(this, null, function* () {
2191
+ if (isAgent) {
2192
+ return {
2193
+ data: []
2194
+ };
2195
+ }
2196
+ try {
2197
+ const response = yield livechatClientInstance.post(
2198
+ `/v3.2/configuration/action/list_registered_webhooks`,
2199
+ {}
2200
+ );
2201
+ return response;
2202
+ } catch (error) {
2203
+ if (error instanceof Error) {
2204
+ throw new Error(
2205
+ `Registered Webhooks couldn't be fetched. [${error.message}]`
2206
+ );
2207
+ } else {
2208
+ throw error;
2209
+ }
2210
+ }
2211
+ });
2212
+ },
2213
+ deleteLicenseWebhook(id) {
2214
+ return __async(this, null, function* () {
2215
+ try {
2216
+ const response = yield livechatClientInstance.post(
2217
+ `/v3.2/configuration/action/unregister_webhook`,
2218
+ { webhook_id: id }
2219
+ );
2220
+ return response;
2221
+ } catch (error) {
2222
+ if (error instanceof Error) {
2223
+ throw new Error(
2224
+ `Registered Webhooks couldn't be deleted. [${error.message}]`
2225
+ );
2226
+ } else {
2227
+ throw error;
2228
+ }
2229
+ }
2230
+ });
2231
+ }
2232
+ };
2233
+
2234
+ // src/apis/products/livechat/configuration/api.ts
2235
+ var livechatConfigurationApi = {
2236
+ property: livechatPropertyApi,
2237
+ webhook: livechatWebhookApi
2238
+ };
2239
+
2240
+ // src/apis/products/livechat/api.ts
2241
+ var livechatApi = {
2242
+ agent: livechatAgentApi,
2243
+ configuration: livechatConfigurationApi
2244
+ };
2245
+
2246
+ // src/apis/products/api.ts
2247
+ var productsApi = {
2248
+ livechat: livechatApi
2249
+ };
2250
+
2251
+ // src/apis/platform/accounts/instance.ts
2252
+ var import_axios10 = __toESM(require("axios"));
2253
+ var platformAccountsClientInstance = import_axios10.default.create({
2254
+ baseURL: "https://accounts.labs.livechatinc.com"
2255
+ });
2256
+ function getPlatformAccountsClientAuthorization(req) {
2257
+ return {
2258
+ token: req.headers["platform-accounts-token"]
2259
+ };
2260
+ }
2261
+ function getPlatformAccountsClientConfig(options = {}) {
2262
+ const defaultAuthorization = platformAccountsClientInstance.defaults.headers["Authorization"];
2263
+ const headers = {
2264
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
2265
+ };
2266
+ return {
2267
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
2268
+ };
2269
+ }
2270
+ function initPlatformAccountsClientInstance(baseUrl, token) {
2271
+ if (baseUrl) {
2272
+ platformAccountsClientInstance.interceptors.request.use(
2273
+ (config) => __async(this, null, function* () {
2274
+ config.baseURL = baseUrl;
2275
+ return config;
2276
+ }),
2277
+ (error) => Promise.reject(error)
2278
+ );
2279
+ }
2280
+ if (token) {
2281
+ platformAccountsClientInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
2282
+ } else {
2283
+ delete platformAccountsClientInstance.defaults.headers["Authorization"];
2284
+ }
2285
+ }
2286
+
2287
+ // src/apis/platform/accounts/client/api.ts
2288
+ var platformAccountsClientApi = {
2289
+ getClients(authorization) {
2290
+ return __async(this, null, function* () {
2291
+ try {
2292
+ return yield platformAccountsClientInstance.get(
2293
+ `/v2/clients`,
2294
+ getPlatformAccountsClientConfig(authorization)
2295
+ );
2296
+ } catch (error) {
2297
+ if (error instanceof Error) {
2298
+ throw new Error(`Clients couldn't be fetched. [${error.message}]`);
2299
+ } else {
2300
+ throw error;
2301
+ }
2302
+ }
2303
+ });
2304
+ },
2305
+ getClient(clientId, authorization) {
2306
+ return __async(this, null, function* () {
2307
+ try {
2308
+ return yield platformAccountsClientInstance.get(
2309
+ `/v2/clients/${clientId}`,
2310
+ getPlatformAccountsClientConfig(authorization)
2311
+ );
2312
+ } catch (error) {
2313
+ if (error instanceof Error) {
2314
+ throw new Error(`Client couldn't be fetched. [${error.message}]`);
2315
+ } else {
2316
+ throw error;
2317
+ }
2318
+ }
2319
+ });
2320
+ },
2321
+ createClient(payload, authorization) {
2322
+ return __async(this, null, function* () {
2323
+ try {
2324
+ return yield platformAccountsClientInstance.post(
2325
+ `/v2/clients`,
2326
+ payload,
2327
+ getPlatformAccountsClientConfig(authorization)
2328
+ );
2329
+ } catch (error) {
2330
+ if (error instanceof Error) {
2331
+ throw new Error(`Client couldn't be created. [${error.message}]`);
2332
+ } else {
2333
+ throw error;
2334
+ }
2335
+ }
2336
+ });
2337
+ },
2338
+ updateClient(clientId, payload, authorization) {
2339
+ return __async(this, null, function* () {
2340
+ try {
2341
+ return yield platformAccountsClientInstance.patch(
2342
+ `/v2/clients/${clientId}`,
2343
+ payload,
2344
+ getPlatformAccountsClientConfig(authorization)
2345
+ );
2346
+ } catch (error) {
2347
+ if (error instanceof Error) {
2348
+ throw new Error(`Client couldn't be updated. [${error.message}]`);
2349
+ } else {
2350
+ throw error;
2351
+ }
2352
+ }
2353
+ });
2354
+ },
2355
+ deleteClient(clientId, authorization) {
2356
+ return __async(this, null, function* () {
2357
+ try {
2358
+ return yield platformAccountsClientInstance.delete(
2359
+ `/v2/clients/${clientId}`,
2360
+ getPlatformAccountsClientConfig(authorization)
2361
+ );
2362
+ } catch (error) {
2363
+ if (error instanceof Error) {
2364
+ throw new Error(`Client couldn't be deleted. [${error.message}]`);
2365
+ } else {
2366
+ throw error;
2367
+ }
2368
+ }
2369
+ });
2370
+ },
2371
+ updateClientScopes(clientId, scopes, authorization) {
2372
+ return __async(this, null, function* () {
2373
+ try {
2374
+ return yield platformAccountsClientInstance.put(
2375
+ `/v2/clients/${clientId}/scopes`,
2376
+ scopes.map((scope) => ({
2377
+ scope: scope.scope,
2378
+ required: scope.required
2379
+ })),
2380
+ getPlatformAccountsClientConfig(authorization)
2381
+ );
2382
+ } catch (error) {
2383
+ if (error instanceof Error) {
2384
+ throw new Error(`Scopes couldn't be updated. [${error.message}]`);
2385
+ } else {
2386
+ throw error;
2387
+ }
2388
+ }
2389
+ });
2390
+ },
2391
+ deleteClientScopes(clientId, scopes, authorization) {
2392
+ return __async(this, null, function* () {
2393
+ try {
2394
+ return yield platformAccountsClientInstance.delete(
2395
+ `/v2/clients/${clientId}/scopes`,
2396
+ __spreadValues({
2397
+ data: scopes.map((scope) => ({
2398
+ scope: scope.scope,
2399
+ required: scope.required
2400
+ }))
2401
+ }, getPlatformAccountsClientConfig(authorization))
2402
+ );
2403
+ } catch (error) {
2404
+ if (error instanceof Error) {
2405
+ throw new Error(`Scopes couldn't be updated. [${error.message}]`);
2406
+ } else {
2407
+ throw error;
2408
+ }
2409
+ }
2410
+ });
2411
+ },
2412
+ getInfo(authorization) {
2413
+ return __async(this, null, function* () {
2414
+ try {
2415
+ return yield platformAccountsClientInstance.get(
2416
+ `/v2/info`,
2417
+ getPlatformAccountsClientConfig(authorization)
2418
+ );
2419
+ } catch (error) {
2420
+ if (error instanceof Error) {
2421
+ throw new Error(`Info couldn't be fetched. [${error.message}]`);
2422
+ } else {
2423
+ throw error;
2424
+ }
2425
+ }
2426
+ });
2427
+ }
2428
+ };
2429
+
2430
+ // src/apis/platform/accounts/pat/api.ts
2431
+ var platformAccountsPersonalAccessTokenApi = {
2432
+ getPersonalAccessTokens(authorization) {
2433
+ return __async(this, null, function* () {
2434
+ try {
2435
+ const response = yield platformAccountsClientInstance.get(
2436
+ `/v2/personal_token`
2437
+ );
2438
+ return response.data;
2439
+ } catch (error) {
2440
+ if (error instanceof Error) {
2441
+ throw new Error(
2442
+ `Personal Access Token couldn't be fetched. [${error.message}]`
2443
+ );
2444
+ } else {
2445
+ throw error;
2446
+ }
2447
+ }
2448
+ });
2449
+ },
2450
+ createPersonalAccessToken(name, scopes, authorization) {
2451
+ return __async(this, null, function* () {
2452
+ try {
2453
+ const response = yield platformAccountsClientInstance.post(
2454
+ `/v2/personal_token`,
2455
+ {
2456
+ name,
2457
+ scope: scopes && scopes.map((item) => item.name).filter((el) => el).join(",")
2458
+ }
2459
+ );
2460
+ return response.data;
2461
+ } catch (error) {
2462
+ if (error instanceof Error) {
2463
+ throw new Error(
2464
+ `Personal Access Token couldn't be created. [${error.message}]`
2465
+ );
2466
+ } else {
2467
+ throw error;
2468
+ }
2469
+ }
2470
+ });
2471
+ },
2472
+ deletePersonalAccessToken(id, authorization) {
2473
+ return __async(this, null, function* () {
2474
+ try {
2475
+ const response = yield platformAccountsClientInstance.delete(
2476
+ `/v2/personal_token/${id}`,
2477
+ getPlatformAccountsClientConfig(authorization)
2478
+ );
2479
+ return response.data;
2480
+ } catch (error) {
2481
+ if (error instanceof Error) {
2482
+ throw new Error(
2483
+ `Personal Access Token couldn't be deleted. [${error.message}]`
2484
+ );
2485
+ } else {
2486
+ throw error;
2487
+ }
2488
+ }
2489
+ });
2490
+ }
2491
+ };
2492
+
2493
+ // src/apis/platform/accounts/products/api.ts
2494
+ var platformAccountsProductsApi = {
2495
+ getOrganizationProducts(authorization) {
2496
+ return __async(this, null, function* () {
2497
+ try {
2498
+ const response = yield platformAccountsClientInstance.get(
2499
+ `/v2/organizations/my/products`,
2500
+ getPlatformAccountsClientConfig(authorization)
2501
+ );
2502
+ return response.data;
2503
+ } catch (error) {
2504
+ if (error instanceof Error) {
2505
+ throw new Error(`Products couldn't be fetched. [${error.message}]`);
2506
+ } else {
2507
+ throw error;
2508
+ }
2509
+ }
2510
+ });
2511
+ },
2512
+ updateOrganizationProducts(payload, authorization) {
2513
+ return __async(this, null, function* () {
2514
+ try {
2515
+ const response = yield platformAccountsClientInstance.post(
2516
+ `/v2/organizations/my/products`,
2517
+ payload,
2518
+ getPlatformAccountsClientConfig(authorization)
2519
+ );
2520
+ return response.data;
2521
+ } catch (error) {
2522
+ if (error instanceof Error) {
2523
+ throw new Error(`Products couldn't be updated. [${error.message}]`);
2524
+ } else {
2525
+ throw error;
2526
+ }
2527
+ }
2528
+ });
2529
+ }
2530
+ };
2531
+
2532
+ // src/apis/platform/accounts/scopes/api.ts
2533
+ var platformAccountsScopesApi = {
2534
+ getScopes(authorization) {
2535
+ return __async(this, null, function* () {
2536
+ try {
2537
+ const response = yield platformAccountsClientInstance.get(
2538
+ `/v2/scopes`,
2539
+ getPlatformAccountsClientConfig(authorization)
2540
+ );
2541
+ return response.data || [];
2542
+ } catch (error) {
2543
+ if (error instanceof Error) {
2544
+ throw new Error(`Scopes couldn't be fetched. [${error.message}]`);
2545
+ } else {
2546
+ throw error;
2547
+ }
2548
+ }
2549
+ });
2550
+ }
2551
+ };
2552
+
2553
+ // src/apis/platform/accounts/sessions/api.ts
2554
+ var platformAccountsSessionsApi = {
2555
+ deleteSessions(authorization) {
2556
+ return __async(this, null, function* () {
2557
+ try {
2558
+ return yield platformAccountsClientInstance.delete(
2559
+ `/v2/sessions`,
2560
+ getPlatformAccountsClientConfig(authorization)
2561
+ );
2562
+ } catch (error) {
2563
+ if (error instanceof Error) {
2564
+ throw new Error(`Sessions couldn't be deleted. [${error.message}]`);
2565
+ } else {
2566
+ throw error;
2567
+ }
2568
+ }
2569
+ });
2570
+ }
2571
+ };
2572
+
2573
+ // src/apis/platform/accounts/api.ts
2574
+ var platformAccountsApi = {
2575
+ client: platformAccountsClientApi,
2576
+ pat: platformAccountsPersonalAccessTokenApi,
2577
+ products: platformAccountsProductsApi,
2578
+ scopes: platformAccountsScopesApi,
2579
+ sessions: platformAccountsSessionsApi
2580
+ };
2581
+
2582
+ // src/apis/platform/dps/instance.ts
2583
+ var import_axios11 = __toESM(require("axios"));
2584
+ var platformDpsClientInstance = import_axios11.default.create({
2585
+ baseURL: "https://dev-platform.labs.livechatinc.com"
2586
+ });
2587
+ function getPlatformDpsClientAuthorization(req) {
2588
+ var _a;
2589
+ return {
2590
+ token: (_a = req.headers["platform-dps-token"]) != null ? _a : req.headers["platform-token"],
2591
+ tokenType: "Bearer"
2592
+ };
2593
+ }
2594
+ function getPlatformDpsAdminClientAuthorization() {
2595
+ const token = process.env.NEXT_PUBLIC_PLATFORM_ENV === "prod" ? process.env.PLATFORM_DPS_TOKEN_FOR_GITHUB : process.env.PLATFORM_DPS_TOKEN_FOR_GITHUB_LABS;
2596
+ return {
2597
+ token: btoa("apps@livechatinc.com:" + token),
2598
+ tokenType: "Basic"
2599
+ };
2600
+ }
2601
+ function getPlatformDpsClientConfig(options = {}) {
2602
+ const defaultAuthorization = platformDpsClientInstance.defaults.headers["Authorization"];
2603
+ const headers = {
2604
+ authorization: defaultAuthorization != null ? defaultAuthorization : options.token ? `Bearer ${options.token}` : void 0
2605
+ };
2606
+ return {
2607
+ headers: __spreadValues({}, headers.authorization ? { Authorization: headers.authorization } : {})
2608
+ };
2609
+ }
2610
+ function initPlatformDpsClientInstance(baseUrl, token) {
2611
+ if (baseUrl) {
2612
+ platformDpsClientInstance.interceptors.request.use(
2613
+ (config) => __async(this, null, function* () {
2614
+ config.baseURL = baseUrl;
2615
+ return config;
2616
+ }),
2617
+ (error) => Promise.reject(error)
2618
+ );
2619
+ }
2620
+ if (token) {
2621
+ platformDpsClientInstance.defaults.headers["Authorization"] = `Bearer ${token}`;
2622
+ } else {
2623
+ delete platformDpsClientInstance.defaults.headers["Authorization"];
2624
+ }
2625
+ }
2626
+
2627
+ // src/apis/platform/dps/applications/application/authorization/api.ts
2628
+ var platformDpsApplicationAuthorizationApi = {
2629
+ createAuth(appId, payload, authorization) {
2630
+ return __async(this, null, function* () {
2631
+ try {
2632
+ yield platformDpsClientInstance.post(
2633
+ `/v2/applications/${appId}/authorization`,
2634
+ payload,
2635
+ getPlatformDpsClientConfig(authorization)
2636
+ );
2637
+ } catch (error) {
2638
+ if (error instanceof Error) {
2639
+ throw new Error(
2640
+ `Authorization couldn't be created. [${error.message}]`
2641
+ );
2642
+ }
2643
+ throw error;
2644
+ }
2645
+ });
2646
+ }
2647
+ };
2648
+
2649
+ // src/apis/platform/dps/applications/application/autoReview/_contracts/dtos/autoReview.ts
2650
+ var getEmptyAppAutoReview = () => ({
2651
+ isReviewed: false,
2652
+ recommendations: {
2653
+ listingDetails: {
2654
+ appName: "",
2655
+ shortDescription: "",
2656
+ longDescription: "",
2657
+ features: "",
2658
+ benefits: ""
2659
+ },
2660
+ auth: {
2661
+ hasZeroScopes: false
2662
+ }
2663
+ },
2664
+ errors: {
2665
+ listingDetails: {
2666
+ appName: "",
2667
+ shortDescription: "",
2668
+ longDescription: "",
2669
+ features: "",
2670
+ benefits: ""
2671
+ },
2672
+ auth: {
2673
+ hasAllScopes: false,
2674
+ isRedirectUriSafe: false
2675
+ },
2676
+ links: {
2677
+ tutorial: {
2678
+ returns200: false,
2679
+ isValid: false
2680
+ },
2681
+ privacyPolicy: {
2682
+ returns200: false,
2683
+ isValid: false
2684
+ }
2685
+ },
2686
+ images: {
2687
+ icon: {
2688
+ isNsfw: false,
2689
+ isRatioValid: false
2690
+ },
2691
+ screenshots: {
2692
+ areNsfw: false,
2693
+ areRatiosValid: false
2694
+ }
2695
+ }
2696
+ }
2697
+ });
2698
+
2699
+ // src/apis/platform/dps/applications/application/autoReview/_contracts/payloads/autoReview.ts
2700
+ var getAppAutoReviewPayload = (value) => {
2701
+ return {
2702
+ appName: value,
2703
+ shortDescription: value,
2704
+ longDescription: value,
2705
+ features: value,
2706
+ benefits: value,
2707
+ scopes: value,
2708
+ redirect: value,
2709
+ tutorial: value,
2710
+ privacyPolicy: value,
2711
+ icons: value,
2712
+ screenshots: value
2713
+ };
2714
+ };
2715
+
2716
+ // src/apis/platform/dps/applications/application/autoReview/api.ts
2717
+ var platformDpsApplicationAutoReviewApi = {
2718
+ getAutoReview(appId, authorization) {
2719
+ return __async(this, null, function* () {
2720
+ try {
2721
+ const response = yield platformDpsClientInstance.get(
2722
+ `/v2/applications/${appId}/auto-review`,
2723
+ getPlatformDpsClientConfig(authorization)
2724
+ );
2725
+ if (response.status === 204) {
2726
+ return getEmptyAppAutoReview();
2727
+ }
2728
+ return response.data;
2729
+ } catch (error) {
2730
+ if (error instanceof Error) {
2731
+ throw new Error(`The review couldn\u2019t be completed. [${error.message}]`);
2732
+ }
2733
+ throw error;
2734
+ }
2735
+ });
2736
+ },
2737
+ submitAutoReview(appId, payload, authorization) {
2738
+ return __async(this, null, function* () {
2739
+ try {
2740
+ yield platformDpsClientInstance.post(
2741
+ `/v2/applications/${appId}/auto-review`,
2742
+ payload,
2743
+ getPlatformDpsClientConfig(authorization)
2744
+ );
2745
+ } catch (error) {
2746
+ if (error instanceof Error) {
2747
+ throw new Error(`The review couldn\u2019t be requested. [${error.message}]`);
2748
+ }
2749
+ throw error;
2750
+ }
2751
+ });
2752
+ }
2753
+ };
2754
+
2755
+ // src/apis/platform/dps/applications/application/chatActions/api.ts
2756
+ var platformDpsApplicationChatActionsApi = {
2757
+ createChatAction(appId, payload, authorization) {
2758
+ return __async(this, null, function* () {
2759
+ try {
2760
+ yield platformDpsClientInstance.put(
2761
+ `/v2/applications/${appId}/chat-actions/${payload.id}`,
2762
+ payload,
2763
+ getPlatformDpsClientConfig(authorization)
2764
+ );
2765
+ } catch (error) {
2766
+ if (error instanceof Error) {
2767
+ throw new Error(
2768
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.CREATED} [${error.message}]`
2769
+ );
2770
+ }
2771
+ throw error;
2772
+ }
2773
+ });
2774
+ },
2775
+ updateChatAction(appId, payload, authorization) {
2776
+ return __async(this, null, function* () {
2777
+ try {
2778
+ yield platformDpsClientInstance.patch(
2779
+ `/v2/applications/${appId}/chat-actions/${payload.id}`,
2780
+ payload,
2781
+ getPlatformDpsClientConfig(authorization)
2782
+ );
2783
+ } catch (error) {
2784
+ if (error instanceof Error) {
2785
+ throw new Error(
2786
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.UPDATED} [${error.message}]`
2787
+ );
2788
+ }
2789
+ throw error;
2790
+ }
2791
+ });
2792
+ },
2793
+ deleteChatAction(appId, chatActionId, authorization) {
2794
+ return __async(this, null, function* () {
2795
+ try {
2796
+ yield platformDpsClientInstance.delete(
2797
+ `/v2/applications/${appId}/chat-actions/${chatActionId}`,
2798
+ __spreadValues({}, getPlatformDpsClientConfig(authorization))
2799
+ );
2800
+ } catch (error) {
2801
+ if (error instanceof Error) {
2802
+ throw new Error(
2803
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
2804
+ );
2805
+ }
2806
+ throw error;
2807
+ }
2808
+ });
2809
+ }
2810
+ };
2811
+
2812
+ // src/apis/platform/dps/applications/application/chatBoosters/api.ts
2813
+ var platformDpsApplicationChatBoostersApi = {
2814
+ createChatBooster(appId, chatBoosterId, payload, authorization) {
2815
+ try {
2816
+ return platformDpsClientInstance.put(
2817
+ `/v2/applications/${appId}/chat-boosters/${chatBoosterId}`,
2818
+ payload,
2819
+ getPlatformDpsClientConfig(authorization)
2820
+ );
2821
+ } catch (error) {
2822
+ if (error instanceof Error) {
2823
+ throw new Error(`Chat Booster couldn't be created. [${error.message}]`);
2824
+ }
2825
+ throw error;
2826
+ }
2827
+ },
2828
+ updateChatBooster(appId, chatBoosterId, payload, authorization) {
2829
+ return __async(this, null, function* () {
2830
+ try {
2831
+ return yield platformDpsClientInstance.put(
2832
+ `/v2/applications/${appId}/chat-boosters/${chatBoosterId}`,
2833
+ payload,
2834
+ getPlatformDpsClientConfig(authorization)
2835
+ );
2836
+ } catch (error) {
2837
+ if (error instanceof Error) {
2838
+ throw new Error(`Chat Booster couldn't be updated. [${error.message}]`);
2839
+ }
2840
+ throw error;
2841
+ }
2842
+ });
2843
+ }
2844
+ };
2845
+
2846
+ // src/apis/platform/dps/applications/application/display/api.ts
2847
+ var platformDpsApplicationDisplayApi = {
2848
+ updateVersionHistory(appId, payload, authorization) {
2849
+ return __async(this, null, function* () {
2850
+ try {
2851
+ const response = yield platformDpsClientInstance.put(
2852
+ `/v2/applications/${appId}/display/changelog`,
2853
+ payload,
2854
+ getPlatformDpsClientConfig(authorization)
2855
+ );
2856
+ return response.data;
2857
+ } catch (error) {
2858
+ if (error instanceof Error) {
2859
+ throw new Error(
2860
+ `Listing details couldn't be updated. [${error.message}]`
2861
+ );
2862
+ }
2863
+ throw error;
2864
+ }
2865
+ });
2866
+ },
2867
+ updateBasicDetails(appId, basicDetails, authorization) {
2868
+ return __async(this, null, function* () {
2869
+ try {
2870
+ yield platformDpsClientInstance.put(
2871
+ `/v2/applications/${appId}/display`,
2872
+ basicDetails,
2873
+ getPlatformDpsClientConfig(authorization)
2874
+ );
2875
+ } catch (error) {
2876
+ if (error instanceof Error) {
2877
+ throw new Error(
2878
+ `Listing details couldn't be updated. [${error.message}]`
2879
+ );
2880
+ }
2881
+ throw error;
2882
+ }
2883
+ });
2884
+ },
2885
+ updateOverview(appId, data, authorization) {
2886
+ return __async(this, null, function* () {
2887
+ try {
2888
+ yield platformDpsClientInstance.put(
2889
+ `/v2/applications/${appId}/listing/overview`,
2890
+ data,
2891
+ getPlatformDpsClientConfig(authorization)
2892
+ );
2893
+ } catch (error) {
2894
+ if (error instanceof Error) {
2895
+ throw new Error(
2896
+ `Listing details couldn't be updated. [${error.message}]`
2897
+ );
2898
+ }
2899
+ throw error;
2900
+ }
2901
+ });
2902
+ },
2903
+ updateTutorialAndSupport(appId, data, authorization) {
2904
+ return __async(this, null, function* () {
2905
+ try {
2906
+ yield platformDpsClientInstance.put(
2907
+ `/v2/applications/${appId}/listing/support`,
2908
+ data,
2909
+ getPlatformDpsClientConfig(authorization)
2910
+ );
2911
+ } catch (error) {
2912
+ if (error instanceof Error) {
2913
+ throw new Error(
2914
+ `Listing details couldn't be updated. [${error.message}]`
2915
+ );
2916
+ }
2917
+ throw error;
2918
+ }
2919
+ });
2920
+ },
2921
+ updateAppIcon(appId, payload, authorization) {
2922
+ return __async(this, null, function* () {
2923
+ try {
2924
+ yield platformDpsClientInstance.put(
2925
+ `/v2/applications/${appId}/display/icons`,
2926
+ payload,
2927
+ getPlatformDpsClientConfig(authorization)
2928
+ );
2929
+ } catch (error) {
2930
+ if (error instanceof Error) {
2931
+ throw new Error(
2932
+ `Listing details couldn't be updated. [${error.message}]`
2933
+ );
2934
+ }
2935
+ throw error;
2936
+ }
2937
+ });
2938
+ },
2939
+ updateDisplayImages(appId, screenshots, authorization) {
2940
+ return __async(this, null, function* () {
2941
+ try {
2942
+ yield platformDpsClientInstance.put(
2943
+ `/v2/applications/${appId}/screenshots/commit`,
2944
+ screenshots,
2945
+ getPlatformDpsClientConfig(authorization)
2946
+ );
2947
+ } catch (error) {
2948
+ if (error instanceof Error) {
2949
+ throw new Error(
2950
+ `Listing details couldn't be updated. [${error.message}]`
2951
+ );
2952
+ }
2953
+ throw error;
2954
+ }
2955
+ });
2956
+ },
2957
+ updateDisplayFeatures(appId, features, authorization) {
2958
+ return __async(this, null, function* () {
2959
+ try {
2960
+ yield platformDpsClientInstance.put(
2961
+ `/v2/applications/${appId}/features`,
2962
+ features,
2963
+ getPlatformDpsClientConfig(authorization)
2964
+ );
2965
+ } catch (error) {
2966
+ if (error instanceof Error) {
2967
+ throw new Error(
2968
+ `Listing details couldn't be updated. [${error.message}]`
2969
+ );
2970
+ }
2971
+ throw error;
2972
+ }
2973
+ });
2974
+ },
2975
+ updateDisplayBenefits(appId, benefits, authorization) {
2976
+ return __async(this, null, function* () {
2977
+ try {
2978
+ yield platformDpsClientInstance.put(
2979
+ `/v2/applications/${appId}/benefits`,
2980
+ benefits,
2981
+ getPlatformDpsClientConfig(authorization)
2982
+ );
2983
+ } catch (error) {
2984
+ if (error instanceof Error) {
2985
+ throw new Error(
2986
+ `Listing details couldn't be updated. [${error.message}]`
2987
+ );
2988
+ }
2989
+ throw error;
2990
+ }
2991
+ });
2992
+ }
2993
+ };
2994
+
2995
+ // src/apis/platform/dps/applications/application/events/api.ts
2996
+ var platformDpsApplicationEventApi = {
2997
+ getEvents(appId, authorization) {
2998
+ return __async(this, null, function* () {
2999
+ try {
3000
+ const response = yield platformDpsClientInstance.get(
3001
+ `/v2/applications/${appId}/events?limit=300`,
3002
+ getPlatformDpsClientConfig(authorization)
3003
+ );
3004
+ return response.data;
3005
+ } catch (error) {
3006
+ if (error instanceof Error) {
3007
+ throw new Error(`App Events couldn't be fetched. [${error.message}]`);
3008
+ }
3009
+ throw error;
3010
+ }
3011
+ });
3012
+ }
3013
+ };
3014
+
3015
+ // src/apis/platform/dps/applications/application/infrastructure/blocks/api.ts
3016
+ var platformDpsApplicationInfrastructureBlocksApi = {
3017
+ getBlocks(appId, authorization) {
3018
+ return __async(this, null, function* () {
3019
+ const response = yield platformDpsClientInstance.get(
3020
+ `/v2/applications/${appId}/infrastructure/blocks`,
3021
+ getPlatformDpsClientConfig(authorization)
3022
+ );
3023
+ return response.data;
3024
+ });
3025
+ },
3026
+ updateBlocks(appId, payload, authorization) {
3027
+ return __async(this, null, function* () {
3028
+ const response = yield platformDpsClientInstance.patch(
3029
+ `/v2/applications/${appId}/infrastructure/blocks`,
3030
+ payload,
3031
+ getPlatformDpsClientConfig(authorization)
3032
+ );
3033
+ return response.data;
3034
+ });
3035
+ },
3036
+ updateRepository(appId, payload, authorization) {
3037
+ return __async(this, null, function* () {
3038
+ const response = yield platformDpsClientInstance.patch(
3039
+ `/v2/applications/${appId}/infrastructure/blocks`,
3040
+ {
3041
+ appId,
3042
+ repository: {
3043
+ provider: payload.provider
3044
+ }
3045
+ },
3046
+ getPlatformDpsClientConfig(authorization)
3047
+ );
3048
+ return response.data;
3049
+ });
3050
+ },
3051
+ updateDeployment(appId, payload, authorization) {
3052
+ return __async(this, null, function* () {
3053
+ const config = payload.customUrl ? { custom: { url: payload.customUrl } } : { custom: null };
3054
+ const response = yield platformDpsClientInstance.patch(
3055
+ `/v2/applications/${appId}/infrastructure/blocks`,
3056
+ {
3057
+ appId,
3058
+ deployment: {
3059
+ mode: payload.mode,
3060
+ provider: payload.provider,
3061
+ config
3062
+ }
3063
+ },
3064
+ getPlatformDpsClientConfig(authorization)
3065
+ );
3066
+ return response.data;
3067
+ });
3068
+ },
3069
+ updateStorage(appId, payload, authorization) {
3070
+ return __async(this, null, function* () {
3071
+ const response = yield platformDpsClientInstance.patch(
3072
+ `/v2/applications/${appId}/infrastructure/blocks`,
3073
+ {
3074
+ appId,
3075
+ storage: {
3076
+ provider: payload.provider
3077
+ }
3078
+ },
3079
+ getPlatformDpsClientConfig(authorization)
3080
+ );
3081
+ return response.data;
3082
+ });
3083
+ },
3084
+ updateLogger(appId, payload, authorization) {
3085
+ return __async(this, null, function* () {
3086
+ const response = yield platformDpsClientInstance.post(
3087
+ `/v2/applications/${appId}/infrastructure/blocks`,
3088
+ {
3089
+ appId,
3090
+ logger: {
3091
+ provider: payload.provider
3092
+ }
3093
+ },
3094
+ getPlatformDpsClientConfig(authorization)
3095
+ );
3096
+ return response.data;
3097
+ });
3098
+ }
3099
+ };
3100
+
3101
+ // src/apis/platform/dps/applications/application/infrastructure/api.ts
3102
+ var platformDpsApplicationInfrastructureApi = {
3103
+ blocks: platformDpsApplicationInfrastructureBlocksApi
3104
+ };
3105
+
3106
+ // src/apis/platform/dps/applications/application/install/api.ts
3107
+ var platformDpsApplicationInstallApi = {
3108
+ updateDirectInstallationUrl(appId, payload, authorization) {
3109
+ return __async(this, null, function* () {
3110
+ try {
3111
+ yield platformDpsClientInstance.put(
3112
+ `/v2/applications/${appId}/install/direct`,
3113
+ payload,
3114
+ getPlatformDpsClientConfig(authorization)
3115
+ );
3116
+ } catch (error) {
3117
+ if (error instanceof Error) {
3118
+ throw new Error(
3119
+ `Direct installation URL couldn't be updated. [${error.message}]`
3120
+ );
3121
+ }
3122
+ throw error;
3123
+ }
3124
+ });
3125
+ }
3126
+ };
3127
+
3128
+ // src/apis/platform/dps/applications/application/onboarding/api.ts
3129
+ var platformDpsApplicationOnboardingApi = {
3130
+ updateOnboarding(appId, payload, authorization) {
3131
+ return __async(this, null, function* () {
3132
+ try {
3133
+ yield platformDpsClientInstance.put(
3134
+ `/v2/applications/${appId}/onboarding`,
3135
+ payload,
3136
+ getPlatformDpsClientConfig(authorization)
3137
+ );
3138
+ } catch (error) {
3139
+ if (error instanceof Error) {
3140
+ throw new Error(
3141
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.UPDATED} [${error.message}]`
3142
+ );
3143
+ }
3144
+ throw error;
3145
+ }
3146
+ });
3147
+ },
3148
+ deleteOnboarding(appId, authorization) {
3149
+ return __async(this, null, function* () {
3150
+ try {
3151
+ yield platformDpsClientInstance.delete(
3152
+ `/v2/applications/${appId}/onboarding`,
3153
+ __spreadValues({}, getPlatformDpsClientConfig(authorization))
3154
+ );
3155
+ } catch (error) {
3156
+ if (error instanceof Error) {
3157
+ throw new Error(
3158
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
3159
+ );
3160
+ }
3161
+ throw error;
3162
+ }
3163
+ });
3164
+ }
3165
+ };
3166
+
3167
+ // src/apis/platform/dps/applications/application/payment/api.ts
3168
+ var platformDpsApplicationPaymentApi = {
3169
+ updatePaymentBlock(appId, payment, authorization) {
3170
+ return __async(this, null, function* () {
3171
+ try {
3172
+ yield platformDpsClientInstance.put(
3173
+ `/v2/applications/${appId}/payment`,
3174
+ payment,
3175
+ getPlatformDpsClientConfig(authorization)
3176
+ );
3177
+ } catch (error) {
3178
+ if (error instanceof Error) {
3179
+ throw new Error(
3180
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.UPDATED} [${error.message}]`
3181
+ );
3182
+ }
3183
+ throw error;
3184
+ }
3185
+ });
3186
+ },
3187
+ deletePaymentBlock(appId, authorization) {
3188
+ return __async(this, null, function* () {
3189
+ try {
3190
+ yield platformDpsClientInstance.delete(
3191
+ `/v2/applications/${appId}/payment`,
3192
+ getPlatformDpsClientConfig(authorization)
3193
+ );
3194
+ } catch (error) {
3195
+ if (error instanceof Error) {
3196
+ throw new Error(
3197
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
3198
+ );
3199
+ }
3200
+ throw error;
3201
+ }
3202
+ });
3203
+ }
3204
+ };
3205
+
3206
+ // src/apis/platform/dps/applications/application/product/api.ts
3207
+ var platformDpsApplicationProductApi = {
3208
+ updateProduct(appId, payload, authorization) {
3209
+ return __async(this, null, function* () {
3210
+ try {
3211
+ yield platformDpsClientInstance.put(
3212
+ `/v2/applications/${appId}/product`,
3213
+ payload,
3214
+ getPlatformDpsClientConfig(authorization)
3215
+ );
3216
+ } catch (error) {
3217
+ if (error instanceof Error) {
3218
+ throw new Error(
3219
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.UPDATED} [${error.message}]`
3220
+ );
3221
+ }
3222
+ throw error;
3223
+ }
3224
+ });
3225
+ }
3226
+ };
3227
+
3228
+ // src/apis/platform/dps/applications/application/properties/api.ts
3229
+ var platformDpsApplicationCustomPropsApi = {
3230
+ createCustomProps(appId, property, authorization) {
3231
+ return __async(this, null, function* () {
3232
+ try {
3233
+ const response = yield platformDpsClientInstance.post(
3234
+ `/v2/applications/${appId}/property`,
3235
+ property,
3236
+ getPlatformDpsClientConfig(authorization)
3237
+ );
3238
+ return response.data;
3239
+ } catch (error) {
3240
+ if (error instanceof Error) {
3241
+ throw new Error(
3242
+ `Listing details couldn't be created. [${error.message}]`
3243
+ );
3244
+ }
3245
+ throw error;
3246
+ }
3247
+ });
3248
+ },
3249
+ updateCustomProps(appId, property, authorization) {
3250
+ return __async(this, null, function* () {
3251
+ try {
3252
+ const response = yield platformDpsClientInstance.put(
3253
+ `/v2/applications/${appId}/property`,
3254
+ property,
3255
+ getPlatformDpsClientConfig(authorization)
3256
+ );
3257
+ return response.data;
3258
+ } catch (error) {
3259
+ if (error instanceof Error) {
3260
+ throw new Error(
3261
+ `Listing details couldn't be updated. [${error.message}]`
3262
+ );
3263
+ }
3264
+ throw error;
3265
+ }
3266
+ });
3267
+ },
3268
+ deleteCustomProps(appId, property, authorization) {
3269
+ return __async(this, null, function* () {
3270
+ try {
3271
+ const response = yield platformDpsClientInstance.delete(
3272
+ `/v2/applications/${appId}/property`,
3273
+ __spreadValues({ data: property }, getPlatformDpsClientConfig(authorization))
3274
+ );
3275
+ return response.data;
3276
+ } catch (error) {
3277
+ if (error instanceof Error) {
3278
+ throw new Error(
3279
+ `Listing details couldn't be deleted. [${error.message}]`
3280
+ );
3281
+ }
3282
+ throw error;
3283
+ }
3284
+ });
3285
+ }
3286
+ };
3287
+
3288
+ // src/apis/platform/dps/applications/application/reporting/api.ts
3289
+ var platformDpsApplicationReportingApi = {
3290
+ sendEvent(appId, event, authorization) {
3291
+ return __async(this, null, function* () {
3292
+ yield platformDpsClientInstance.post(
3293
+ `/apps/${appId}/events`,
3294
+ event,
3295
+ getPlatformDpsClientConfig(authorization)
3296
+ );
3297
+ });
3298
+ }
3299
+ };
3300
+
3301
+ // src/apis/platform/dps/applications/application/resources/api.ts
3302
+ var platformDpsApplicationResourcesApi = {
3303
+ getAppUpgrades(appId, authorization) {
3304
+ return __async(this, null, function* () {
3305
+ try {
3306
+ return yield platformDpsClientInstance.get(
3307
+ `/v2/applications/${appId}/resources`,
3308
+ getPlatformDpsClientConfig(authorization)
3309
+ );
3310
+ } catch (error) {
3311
+ if (error instanceof Error) {
3312
+ throw new Error(`App Resources couldn't be loaded. [${error.message}]`);
3313
+ }
3314
+ throw error;
3315
+ }
3316
+ });
3317
+ },
3318
+ createAppUpgrade(appId, body, authorization) {
3319
+ return __async(this, null, function* () {
3320
+ try {
3321
+ return yield platformDpsClientInstance.put(
3322
+ `/v2/applications/${appId}/resources`,
3323
+ body,
3324
+ getPlatformDpsClientConfig(authorization)
3325
+ );
3326
+ } catch (error) {
3327
+ if (error instanceof Error) {
3328
+ throw new Error(
3329
+ `App Resources couldn't be created. [${error.message}]`
3330
+ );
3331
+ }
3332
+ throw error;
3333
+ }
3334
+ });
3335
+ },
3336
+ updateAppUpgrade(appId, body, authorization) {
3337
+ return __async(this, null, function* () {
3338
+ try {
3339
+ return yield platformDpsClientInstance.put(
3340
+ `/v2/applications/${appId}/resources`,
3341
+ body,
3342
+ getPlatformDpsClientConfig(authorization)
3343
+ );
3344
+ } catch (error) {
3345
+ if (error instanceof Error) {
3346
+ throw new Error(
3347
+ `App Resources couldn't be updated. [${error.message}]`
3348
+ );
3349
+ }
3350
+ throw error;
3351
+ }
3352
+ });
3353
+ },
3354
+ deleteAppUpgrade(appId, resourceId, authorization) {
3355
+ return __async(this, null, function* () {
3356
+ try {
3357
+ return yield platformDpsClientInstance.delete(
3358
+ `/v2/applications/${appId}/resources/${resourceId}`,
3359
+ getPlatformDpsClientConfig(authorization)
3360
+ );
3361
+ } catch (error) {
3362
+ if (error instanceof Error) {
3363
+ throw new Error(`App Resource couldn't be delete. [${error.message}]`);
3364
+ }
3365
+ throw error;
3366
+ }
3367
+ });
3368
+ },
3369
+ copyUpgrade(sourceAppId, destinationAppId, authorization) {
3370
+ return __async(this, null, function* () {
3371
+ try {
3372
+ return yield platformDpsClientInstance.put(
3373
+ `/v2/applications/${sourceAppId}/resources/copy?application=${destinationAppId}`,
3374
+ getPlatformDpsClientConfig(authorization)
3375
+ );
3376
+ } catch (error) {
3377
+ if (error instanceof Error) {
3378
+ throw new Error(`App Resources couldn't be copied. [${error.message}]`);
3379
+ }
3380
+ throw error;
3381
+ }
3382
+ });
3383
+ }
3384
+ };
3385
+
3386
+ // src/apis/platform/dps/applications/application/review/api.ts
3387
+ var platformDpsApplicationReviewApi = {
3388
+ createSubmission(appId, payload, authorization) {
3389
+ return __async(this, null, function* () {
3390
+ try {
3391
+ const response = yield platformDpsClientInstance.put(
3392
+ `/v2/applications/${appId}/review/submit`,
3393
+ payload,
3394
+ getPlatformDpsClientConfig(authorization)
3395
+ );
3396
+ return response.data;
3397
+ } catch (error) {
3398
+ if (error instanceof Error) {
3399
+ throw new Error(
3400
+ `App couldn't be submitted for review. [${error.message}]`
3401
+ );
3402
+ }
3403
+ throw error;
3404
+ }
3405
+ });
3406
+ },
3407
+ cancelSubmission(appId, authorization) {
3408
+ return __async(this, null, function* () {
3409
+ try {
3410
+ const response = yield platformDpsClientInstance.put(
3411
+ `/v2/applications/${appId}/review/cancel`,
3412
+ getPlatformDpsClientConfig(authorization)
3413
+ );
3414
+ return response.data;
3415
+ } catch (error) {
3416
+ if (error instanceof Error) {
3417
+ throw new Error(`App review couldn't be cancelled. [${error.message}]`);
3418
+ }
3419
+ throw error;
3420
+ }
3421
+ });
3422
+ }
3423
+ };
3424
+
3425
+ // src/apis/platform/dps/applications/application/webhooks/api.ts
3426
+ var platformDpsApplicationWebhooksApi = {
3427
+ updateAppWebhooks(appId, payload, authorization) {
3428
+ return __async(this, null, function* () {
3429
+ try {
3430
+ yield platformDpsClientInstance.put(
3431
+ `/v2/applications/${appId}/webhook`,
3432
+ payload,
3433
+ getPlatformDpsClientConfig(authorization)
3434
+ );
3435
+ } catch (error) {
3436
+ if (error instanceof Error) {
3437
+ throw new Error(
3438
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.UPDATED} [${error.message}]`
3439
+ );
3440
+ }
3441
+ throw error;
3442
+ }
3443
+ });
3444
+ },
3445
+ getChatWebhook(appId, authorization) {
3446
+ return __async(this, null, function* () {
3447
+ try {
3448
+ yield platformDpsClientInstance.get(
3449
+ `/v2/applications/${appId}/chat-webhooks`,
3450
+ getPlatformDpsClientConfig(authorization)
3451
+ );
3452
+ } catch (error) {
3453
+ if (error instanceof Error) {
3454
+ throw new Error(`Couldn't get the chat webhook. [${error.message}]`);
3455
+ }
3456
+ throw error;
3457
+ }
3458
+ });
3459
+ },
3460
+ updateChatWebhook(appId, payload, authorization) {
3461
+ return __async(this, null, function* () {
3462
+ try {
3463
+ yield platformDpsClientInstance.post(
3464
+ `/v2/applications/${appId}/chat-webhooks`,
3465
+ payload,
3466
+ getPlatformDpsClientConfig(authorization)
3467
+ );
3468
+ } catch (error) {
3469
+ if (error instanceof Error) {
3470
+ throw new Error(
3471
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.UPDATED} [${error.message}]`
3472
+ );
3473
+ }
3474
+ throw error;
3475
+ }
3476
+ });
3477
+ },
3478
+ deleteChatWebhook(appId, authorization) {
3479
+ return __async(this, null, function* () {
3480
+ try {
3481
+ yield platformDpsClientInstance.delete(
3482
+ `/v2/applications/${appId}/chat-webhooks`,
3483
+ __spreadValues({}, getPlatformDpsClientConfig(authorization))
3484
+ );
3485
+ } catch (error) {
3486
+ if (error instanceof Error) {
3487
+ throw new Error(
3488
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
3489
+ );
3490
+ }
3491
+ throw error;
3492
+ }
3493
+ });
3494
+ }
3495
+ };
3496
+
3497
+ // src/apis/platform/dps/applications/application/widgets/api.ts
3498
+ var platformDpsApplicationWidgetsApi = {
3499
+ createWidget(appId, widgetId, widget, authorization) {
3500
+ return __async(this, null, function* () {
3501
+ try {
3502
+ yield platformDpsClientInstance.put(
3503
+ `/v2/applications/${appId}/widgets/${widgetId}`,
3504
+ widget,
3505
+ getPlatformDpsClientConfig(authorization)
3506
+ );
3507
+ } catch (error) {
3508
+ if (error instanceof Error) {
3509
+ throw new Error(
3510
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.CREATED} [${error.message}]`
3511
+ );
3512
+ }
3513
+ throw error;
3514
+ }
3515
+ });
3516
+ },
3517
+ updateWidget(appId, widgetId, widget, authorization) {
3518
+ return __async(this, null, function* () {
3519
+ try {
3520
+ yield platformDpsClientInstance.patch(
3521
+ `/v2/applications/${appId}/widgets/${widgetId}`,
3522
+ widget,
3523
+ getPlatformDpsClientConfig(authorization)
3524
+ );
3525
+ } catch (error) {
3526
+ if (error instanceof Error) {
3527
+ throw new Error(
3528
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.UPDATED} [${error.message}]`
3529
+ );
3530
+ }
3531
+ throw error;
3532
+ }
3533
+ });
3534
+ },
3535
+ deleteWidget(appId, widgetId, authorization) {
3536
+ return __async(this, null, function* () {
3537
+ try {
3538
+ yield platformDpsClientInstance.delete(
3539
+ `/v2/applications/${appId}/widgets/${widgetId}`,
3540
+ __spreadValues({}, getPlatformDpsClientConfig(authorization))
3541
+ );
3542
+ } catch (error) {
3543
+ if (error instanceof Error) {
3544
+ throw new Error(
3545
+ `${API_NOTIFICATIONS.BUILDING_BLOCKS.FAILURE.DELETED} [${error.message}]`
3546
+ );
3547
+ }
3548
+ throw error;
3549
+ }
3550
+ });
3551
+ }
3552
+ };
3553
+
3554
+ // src/apis/platform/dps/applications/application/api.ts
3555
+ var platformDpsApplicationApi = {
3556
+ authorization: platformDpsApplicationAuthorizationApi,
3557
+ autoReview: platformDpsApplicationAutoReviewApi,
3558
+ chatActions: platformDpsApplicationChatActionsApi,
3559
+ chatBoosters: platformDpsApplicationChatBoostersApi,
3560
+ customProps: platformDpsApplicationCustomPropsApi,
3561
+ display: platformDpsApplicationDisplayApi,
3562
+ events: platformDpsApplicationEventApi,
3563
+ install: platformDpsApplicationInstallApi,
3564
+ infrastructure: platformDpsApplicationInfrastructureApi,
3565
+ onboarding: platformDpsApplicationOnboardingApi,
3566
+ payment: platformDpsApplicationPaymentApi,
3567
+ product: platformDpsApplicationProductApi,
3568
+ reporting: platformDpsApplicationReportingApi,
3569
+ resource: platformDpsApplicationResourcesApi,
3570
+ review: platformDpsApplicationReviewApi,
3571
+ webhooks: platformDpsApplicationWebhooksApi,
3572
+ widgets: platformDpsApplicationWidgetsApi,
3573
+ getApp(appId, authorization) {
3574
+ return __async(this, null, function* () {
3575
+ try {
3576
+ const response = yield platformDpsClientInstance.get(
3577
+ `/v2/applications/${appId}`,
3578
+ getPlatformDpsClientConfig(authorization)
3579
+ );
3580
+ return response.data;
3581
+ } catch (error) {
3582
+ if (error instanceof Error) {
3583
+ throw new Error(`App couldn't be fetched. [${error.message}]`);
3584
+ }
3585
+ throw error;
3586
+ }
3587
+ });
3588
+ },
3589
+ createApp(payload, authorization) {
3590
+ return __async(this, null, function* () {
3591
+ try {
3592
+ const response = yield platformDpsClientInstance.post(
3593
+ `/v2/applications`,
3594
+ payload,
3595
+ getPlatformDpsClientConfig(authorization)
3596
+ );
3597
+ return response.data;
3598
+ } catch (error) {
3599
+ if (error instanceof Error) {
3600
+ throw new Error(`App couldn't be created. [${error.message}]`);
3601
+ }
3602
+ throw error;
3603
+ }
3604
+ });
3605
+ },
3606
+ fork(appId, authorization) {
3607
+ return __async(this, null, function* () {
3608
+ try {
3609
+ return yield platformDpsClientInstance.post(
3610
+ `/v2/applications/${appId}/fork`,
3611
+ getPlatformDpsClientConfig(authorization)
3612
+ );
3613
+ } catch (error) {
3614
+ if (error instanceof Error) {
3615
+ throw new Error(`App couldn't be forked. [${error.message}]`);
3616
+ }
3617
+ throw error;
3618
+ }
3619
+ });
3620
+ },
3621
+ updateQL(appId) {
3622
+ return __async(this, null, function* () {
3623
+ try {
3624
+ yield platformDpsClientInstance.patch(
3625
+ `/v2/applications/${appId}/qualified-lead`
3626
+ );
3627
+ } catch (error) {
3628
+ if (error instanceof Error) {
3629
+ throw new Error(`QL couldn't be updated. [${error.message}]`);
3630
+ }
3631
+ throw error;
3632
+ }
3633
+ });
3634
+ },
3635
+ deleteApp(appId, authorization) {
3636
+ return __async(this, null, function* () {
3637
+ try {
3638
+ yield platformDpsClientInstance.delete(
3639
+ `/v2/applications/${appId}`,
3640
+ getPlatformDpsClientConfig(authorization)
3641
+ );
3642
+ } catch (error) {
3643
+ if (error instanceof Error) {
3644
+ throw new Error(`App couldn't be created. [${error.message}]`);
3645
+ }
3646
+ throw error;
3647
+ }
3648
+ });
3649
+ },
3650
+ createAiContent(appId, appName, appSummary) {
3651
+ return __async(this, null, function* () {
3652
+ try {
3653
+ const response = yield platformDpsClientInstance.post(
3654
+ `/v2/ai/application/${appId}/content`,
3655
+ {
3656
+ name: appName,
3657
+ summary: appSummary
3658
+ }
3659
+ );
3660
+ return response;
3661
+ } catch (error) {
3662
+ if (error instanceof Error) {
3663
+ throw new Error(`AI content couldn't be created. [${error.message}]`);
3664
+ }
3665
+ throw error;
3666
+ }
3667
+ });
3668
+ }
3669
+ };
3670
+
3671
+ // src/apis/platform/dps/applications/purchases/api.ts
3672
+ var platformDpsApplicationsPurchasesApi = {
3673
+ getPurchases(apps, options, authorization) {
3674
+ return __async(this, null, function* () {
3675
+ try {
3676
+ const { from, to, duration } = options;
3677
+ const response = apps.map((app) => __async(this, null, function* () {
3678
+ const params = `applications=${app.clientId}${from ? `&from=${from}` : ""}${to ? `&to=${to}` : ""}&duration=${duration}&by=supplier`;
3679
+ const singleResponse = yield platformDpsClientInstance.get(
3680
+ `/v2/applications/purchases?${params}`,
3681
+ getPlatformDpsClientConfig(authorization)
3682
+ );
3683
+ return {
3684
+ appId: app.appId,
3685
+ data: singleResponse.data
3686
+ };
3687
+ }));
3688
+ return Promise.all(response);
3689
+ } catch (error) {
3690
+ if (error instanceof Error) {
3691
+ throw new Error(
3692
+ `App purchases couldn't be fetched. [${error.message}]`
3693
+ );
3694
+ }
3695
+ throw error;
3696
+ }
3697
+ });
3698
+ },
3699
+ getSummaryPurchases(apps, options, authorization) {
3700
+ return __async(this, null, function* () {
3701
+ try {
3702
+ const { from, to, duration } = options;
3703
+ const clientIds = apps.map((app) => app.clientId);
3704
+ const params = `applications=${clientIds.join(",")}${from ? `&from=${from}` : ""}${to ? `&to=${to}` : ""}&duration=${duration}&by=supplier`;
3705
+ const response = yield platformDpsClientInstance.get(
3706
+ `/v2/applications/purchases?${params}`,
3707
+ getPlatformDpsClientConfig(authorization)
3708
+ );
3709
+ return [{ data: response.data, appId: "All apps" }];
3710
+ } catch (error) {
3711
+ if (error instanceof Error) {
3712
+ throw new Error(
3713
+ `App summary purchases couldn't be fetched. [${error.message}]`
3714
+ );
3715
+ }
3716
+ throw error;
3717
+ }
3718
+ });
3719
+ },
3720
+ getSummaryPurchasesHistory(apps, options, authorization) {
3721
+ return __async(this, null, function* () {
3722
+ try {
3723
+ const { from, to, duration } = options;
3724
+ const params = `applications=${apps.join(",")}${from ? `&from=${from}` : ""}${to ? `&to=${to}` : ""}&duration=${duration}`;
3725
+ const response = yield platformDpsClientInstance.get(
3726
+ `/v2/applications/purchases/history?${params}`,
3727
+ getPlatformDpsClientConfig(authorization)
3728
+ );
3729
+ return [{ data: response.data, appId: "All apps" }];
3730
+ } catch (error) {
3731
+ if (error instanceof Error) {
3732
+ throw new Error(
3733
+ `App summary purchases history couldn't be fetched. [${error.message}]`
3734
+ );
3735
+ }
3736
+ throw error;
3737
+ }
3738
+ });
3739
+ }
3740
+ };
3741
+
3742
+ // src/apis/platform/dps/applications/usage/api.ts
3743
+ var platformDpsApplicationsUsageApi = {
3744
+ getUsage(appId, options, authorization) {
3745
+ return __async(this, null, function* () {
3746
+ try {
3747
+ const { events = [], from, apps, to, duration } = options;
3748
+ const response = events.map((event) => __async(this, null, function* () {
3749
+ const applications = appId ? `applications=${appId}` : `applications=${apps.map((app) => app.id).join(",")}`;
3750
+ let params = `${applications}&event=${event}`;
3751
+ params += duration ? `&duration=${duration}` : "";
3752
+ params += from ? `&from=${from}` : "";
3753
+ params += to ? `&to=${to}` : "";
3754
+ const singleResponse = yield platformDpsClientInstance.get(
3755
+ `/v2/applications/usage/developer?${params}`,
3756
+ getPlatformDpsClientConfig(authorization)
3757
+ );
3758
+ return singleResponse.data;
3759
+ }));
3760
+ return Promise.all(response);
3761
+ } catch (error) {
3762
+ if (error instanceof Error) {
3763
+ throw new Error(`App usage couldn't be fetched. [${error.message}]`);
3764
+ }
3765
+ throw error;
3766
+ }
3767
+ });
3768
+ }
3769
+ };
3770
+
3771
+ // src/apis/platform/dps/applications/api.ts
3772
+ var platformDpsApplicationsApi = {
3773
+ application: platformDpsApplicationApi,
3774
+ usage: platformDpsApplicationsUsageApi,
3775
+ purchases: platformDpsApplicationsPurchasesApi,
3776
+ getApps() {
3777
+ return __async(this, arguments, function* ({ filter = "licensed" } = {}) {
3778
+ try {
3779
+ const params = `filter=${filter}`;
3780
+ const response = yield platformDpsClientInstance.get(`/v2/applications?${params}`);
3781
+ return response.data;
3782
+ } catch (error) {
3783
+ if (error instanceof Error) {
3784
+ throw new Error(`Apps couldn't be fetched. [${error.message}]`);
3785
+ }
3786
+ throw error;
3787
+ }
3788
+ });
3789
+ }
3790
+ };
3791
+
3792
+ // src/apis/platform/dps/categories/api.ts
3793
+ var platformDpsCategoriesApi = {
3794
+ getCategories(authorization) {
3795
+ return __async(this, null, function* () {
3796
+ try {
3797
+ const response = yield platformDpsClientInstance.get(
3798
+ `/v2/categories`,
3799
+ getPlatformDpsClientConfig(authorization)
3800
+ );
3801
+ return response.data;
3802
+ } catch (error) {
3803
+ if (error instanceof Error) {
3804
+ throw new Error(`Categories couldn't be fetched. [${error.message}]`);
3805
+ }
3806
+ throw error;
3807
+ }
3808
+ });
3809
+ }
3810
+ };
3811
+
3812
+ // src/apis/platform/dps/developers/developer/api.ts
3813
+ var platformDpsDeveloperApi = {
3814
+ getLedger(userId, options, authorization) {
3815
+ return __async(this, null, function* () {
3816
+ try {
3817
+ const { startAt, endAt, size, page } = options;
3818
+ const withRange = !!(startAt && endAt);
3819
+ const withPagination = !!(size && typeof page === "number");
3820
+ let params = withRange || withPagination ? `?` : "";
3821
+ if (withRange) {
3822
+ params += `from=${startAt}&to=${endAt}`;
3823
+ }
3824
+ if (withPagination) {
3825
+ if (withRange) {
3826
+ params += `&size=${size}&page=${page}`;
3827
+ } else {
3828
+ params += `size=${size}&page=${page}`;
3829
+ }
3830
+ }
3831
+ const response = yield platformDpsClientInstance.get(
3832
+ `/v2/developers/${userId}/account/ledger${params}`,
3833
+ getPlatformDpsClientConfig(authorization)
3834
+ );
3835
+ return response.data;
3836
+ } catch (error) {
3837
+ if (error instanceof Error) {
3838
+ throw new Error(`Ledger couldn't be fetched. [${error.message}]`);
3839
+ }
3840
+ throw error;
3841
+ }
3842
+ });
3843
+ },
3844
+ requestWithdrawal(_0, _1) {
3845
+ return __async(this, arguments, function* ({
3846
+ amount,
3847
+ note,
3848
+ userId
3849
+ }, authorization) {
3850
+ try {
3851
+ const response = yield platformDpsClientInstance.patch(
3852
+ `/v2/developers/${userId}/account/withdrawal/request`,
3853
+ { amount, note },
3854
+ getPlatformDpsClientConfig(authorization)
3855
+ );
3856
+ return response.data;
3857
+ } catch (error) {
3858
+ if (error instanceof Error) {
3859
+ throw new Error(`Withdrawal couldn't be requested. [${error.message}]`);
3860
+ }
3861
+ throw error;
3862
+ }
3863
+ });
3864
+ }
3865
+ };
3866
+
3867
+ // src/apis/platform/dps/developers/api.ts
3868
+ var platformDpsDevelopersApi = {
3869
+ developer: platformDpsDeveloperApi
3870
+ };
3871
+
3872
+ // src/apis/platform/dps/links/api.ts
3873
+ var platformDpsLinksApi = {
3874
+ updateShortcuts(links, authorization) {
3875
+ return __async(this, null, function* () {
3876
+ try {
3877
+ yield platformDpsClientInstance.put(
3878
+ `/v2/links`,
3879
+ links,
3880
+ getPlatformDpsClientConfig(authorization)
3881
+ );
3882
+ } catch (error) {
3883
+ if (error instanceof Error) {
3884
+ throw new Error(`Shortcuts couldn't be updated. [${error.message}]`);
3885
+ }
3886
+ throw error;
3887
+ }
3888
+ });
3889
+ }
3890
+ };
3891
+
3892
+ // src/apis/platform/dps/messaging/developer/api.ts
3893
+ var platformDpsMessagingDeveloperApi = {
3894
+ getMessages(authorization) {
3895
+ return __async(this, null, function* () {
3896
+ try {
3897
+ const response = yield platformDpsClientInstance.get(
3898
+ `/v2/messaging/developer/fetch`,
3899
+ getPlatformDpsClientConfig(authorization)
3900
+ );
3901
+ return response.data;
3902
+ } catch (error) {
3903
+ if (error instanceof Error) {
3904
+ throw new Error(`Messages couldn't be fetched. [${error.message}]`);
3905
+ }
3906
+ throw error;
3907
+ }
3908
+ });
3909
+ },
3910
+ createMessage(message, authorization) {
3911
+ return __async(this, null, function* () {
3912
+ try {
3913
+ const response = yield platformDpsClientInstance.post(
3914
+ `/v2/messaging/developer/create`,
3915
+ message,
3916
+ getPlatformDpsClientConfig(authorization)
3917
+ );
3918
+ return response;
3919
+ } catch (error) {
3920
+ if (error instanceof Error) {
3921
+ throw new Error(`Message couldn't be sent. [${error.message}]`);
3922
+ }
3923
+ throw error;
3924
+ }
3925
+ });
3926
+ }
3927
+ };
3928
+
3929
+ // src/apis/platform/dps/messaging/api.ts
3930
+ var platformDpsMessagingApi = {
3931
+ developer: platformDpsMessagingDeveloperApi
3932
+ };
3933
+
3934
+ // src/apis/platform/dps/research/customer/api.ts
3935
+ var dpsResearchCustomerApi = {
3936
+ getResearchCustomersLicenses(authorization) {
3937
+ return __async(this, null, function* () {
3938
+ try {
3939
+ const response = yield platformDpsClientInstance.get(
3940
+ `/v2/research/customers/licenses`,
3941
+ getPlatformDpsClientConfig(authorization)
3942
+ );
3943
+ return response.data;
3944
+ } catch (error) {
3945
+ if (error instanceof Error) {
3946
+ throw new Error(
3947
+ `We couldn't fetch the research toolkit data. [${error.message}]`
3948
+ );
3949
+ }
3950
+ throw error;
3951
+ }
3952
+ });
3953
+ },
3954
+ getResearchCustomersBusiness(authorization) {
3955
+ return __async(this, null, function* () {
3956
+ try {
3957
+ const response = yield platformDpsClientInstance.get(
3958
+ `/v2/research/customers/business`,
3959
+ getPlatformDpsClientConfig(authorization)
3960
+ );
3961
+ return response.data;
3962
+ } catch (error) {
3963
+ if (error instanceof Error) {
3964
+ throw new Error(
3965
+ `We couldn't fetch the research toolkit data. [${error.message}]`
3966
+ );
3967
+ }
3968
+ throw error;
3969
+ }
3970
+ });
3971
+ },
3972
+ getResearchCustomersLocation(authorization) {
3973
+ return __async(this, null, function* () {
3974
+ try {
3975
+ const response = yield platformDpsClientInstance.get(
3976
+ `/v2/research/customers/location`,
3977
+ getPlatformDpsClientConfig(authorization)
3978
+ );
3979
+ return response.data;
3980
+ } catch (error) {
3981
+ if (error instanceof Error) {
3982
+ throw new Error(
3983
+ `We couldn't fetch the research toolkit data. [${error.message}]`
3984
+ );
3985
+ }
3986
+ throw error;
3987
+ }
3988
+ });
3989
+ }
3990
+ };
3991
+
3992
+ // src/apis/platform/dps/research/dictionary/api.ts
3993
+ var dpsResearchDictionaryApi = {
3994
+ getResearchDictionary() {
3995
+ return __async(this, arguments, function* (options = {}, authorization) {
3996
+ try {
3997
+ const params = new URLSearchParams(options);
3998
+ const response = yield platformDpsClientInstance.get(
3999
+ `/v2/research/dictionary?${params}`,
4000
+ getPlatformDpsClientConfig(authorization)
4001
+ );
4002
+ return response.data;
4003
+ } catch (error) {
4004
+ if (error instanceof Error) {
4005
+ throw new Error(
4006
+ `We couldn't fetch the research toolkit data. [${error.message}]`
4007
+ );
4008
+ }
4009
+ throw error;
4010
+ }
4011
+ });
4012
+ }
4013
+ };
4014
+
4015
+ // src/apis/platform/dps/research/marketplace/api.ts
4016
+ var dpsResearchMarketplaceApi = {
4017
+ getResearchMarketplaceApps() {
4018
+ return __async(this, arguments, function* (options = {}, authorization) {
4019
+ try {
4020
+ const params = new URLSearchParams(options);
4021
+ const response = yield platformDpsClientInstance.get(
4022
+ `/v2/research/marketplace/apps?${params}`,
4023
+ getPlatformDpsClientConfig(authorization)
4024
+ );
4025
+ return response.data;
4026
+ } catch (error) {
4027
+ if (error instanceof Error) {
4028
+ throw new Error(
4029
+ `We couldn't fetch the research toolkit data. [${error.message}]`
4030
+ );
4031
+ }
4032
+ throw error;
4033
+ }
4034
+ });
4035
+ },
4036
+ getResearchMarketplaceViews() {
4037
+ return __async(this, arguments, function* (options = {}, authorization) {
4038
+ try {
4039
+ const params = new URLSearchParams(options);
4040
+ const response = yield platformDpsClientInstance.get(
4041
+ `/v2/research/marketplace/views?${params}`,
4042
+ getPlatformDpsClientConfig(authorization)
4043
+ );
4044
+ return response.data;
4045
+ } catch (error) {
4046
+ if (error instanceof Error) {
4047
+ throw new Error(
4048
+ `We couldn't fetch the research toolkit data. [${error.message}]`
4049
+ );
4050
+ }
4051
+ throw error;
4052
+ }
4053
+ });
4054
+ }
4055
+ };
4056
+
4057
+ // src/apis/platform/dps/research/traffic/api.ts
4058
+ var dpsResearchTrafficApi = {
4059
+ getResearchTrafficAgents() {
4060
+ return __async(this, arguments, function* (options = {}, authorization) {
4061
+ try {
4062
+ const params = new URLSearchParams(options);
4063
+ const response = yield platformDpsClientInstance.get(
4064
+ `/v2/research/traffic/agents?${params}`,
4065
+ getPlatformDpsClientConfig(authorization)
4066
+ );
4067
+ return response.data;
4068
+ } catch (error) {
4069
+ if (error instanceof Error) {
4070
+ throw new Error(
4071
+ `We couldn't fetch the research toolkit data. [${error.message}]`
4072
+ );
4073
+ }
4074
+ throw error;
4075
+ }
4076
+ });
4077
+ },
4078
+ getResearchTrafficChats() {
4079
+ return __async(this, arguments, function* (options = {}, authorization) {
4080
+ try {
4081
+ const params = new URLSearchParams(options);
4082
+ const response = yield platformDpsClientInstance.get(
4083
+ `/v2/research/traffic/chats?${params}`,
4084
+ getPlatformDpsClientConfig(authorization)
4085
+ );
4086
+ return response.data;
4087
+ } catch (error) {
4088
+ if (error instanceof Error) {
4089
+ throw new Error(
4090
+ `We couldn't fetch the research toolkit data. [${error.message}]`
4091
+ );
4092
+ }
4093
+ throw error;
4094
+ }
4095
+ });
4096
+ }
4097
+ };
4098
+
4099
+ // src/apis/platform/dps/research/api.ts
4100
+ var platformDpsResearchApi = {
4101
+ customer: dpsResearchCustomerApi,
4102
+ traffic: dpsResearchTrafficApi,
4103
+ marketplace: dpsResearchMarketplaceApi,
4104
+ dictionary: dpsResearchDictionaryApi
4105
+ };
4106
+
4107
+ // src/apis/platform/dps/user/api.ts
4108
+ var platformDpsUserApi = {
4109
+ getUser(authorization) {
4110
+ return __async(this, null, function* () {
4111
+ const response = yield platformDpsClientInstance.get(
4112
+ `/v2/me`,
4113
+ getPlatformDpsClientConfig(authorization)
4114
+ );
4115
+ return response.data;
4116
+ });
4117
+ },
4118
+ getUserIntegrations(authorization) {
4119
+ return __async(this, null, function* () {
4120
+ const response = yield platformDpsClientInstance.get(
4121
+ `/v2/me/integrations`,
4122
+ getPlatformDpsClientConfig(authorization)
4123
+ );
4124
+ return response.data;
4125
+ });
4126
+ },
4127
+ updateUser(user, authorization) {
4128
+ return __async(this, null, function* () {
4129
+ const { status } = yield platformDpsClientInstance.put(
4130
+ `/v2/me`,
4131
+ user,
4132
+ getPlatformDpsClientConfig(authorization)
4133
+ );
4134
+ return status;
4135
+ });
4136
+ },
4137
+ updateUserIntegrations(payload, authorization) {
4138
+ return __async(this, null, function* () {
4139
+ const response = yield platformDpsClientInstance.patch(
4140
+ `/v2/me/integrations`,
4141
+ payload,
4142
+ getPlatformDpsClientConfig(authorization)
4143
+ );
4144
+ return response.data;
4145
+ });
4146
+ },
4147
+ updateUserFeatures(payload, authorization) {
4148
+ return __async(this, null, function* () {
4149
+ const response = yield platformDpsClientInstance.put(
4150
+ "/v2/features",
4151
+ payload,
4152
+ getPlatformDpsClientConfig(authorization)
4153
+ );
4154
+ return response.data;
4155
+ });
4156
+ },
4157
+ removeUserGitHubIntegrationByInstallationId(installationId, authorization) {
4158
+ return __async(this, null, function* () {
4159
+ const response = yield platformDpsClientInstance.delete(
4160
+ `/v2/me/integrations/github`,
4161
+ __spreadProps(__spreadValues({}, getPlatformDpsClientConfig(authorization)), {
4162
+ data: {
4163
+ githubInstallationId: installationId
4164
+ }
4165
+ })
4166
+ );
4167
+ return response.data;
4168
+ });
4169
+ },
4170
+ updateUserNetlifyIntegration(userNetlifyIntegration, authorization) {
4171
+ return __async(this, null, function* () {
4172
+ const { status } = yield platformDpsClientInstance.patch(
4173
+ `/v2/me/integrations`,
4174
+ { netlify: userNetlifyIntegration },
4175
+ getPlatformDpsClientConfig(authorization)
4176
+ );
4177
+ return status;
4178
+ });
4179
+ }
4180
+ };
4181
+
4182
+ // src/apis/platform/dps/api.ts
4183
+ var platformDpsApi = {
4184
+ applications: platformDpsApplicationsApi,
4185
+ user: platformDpsUserApi,
4186
+ categories: platformDpsCategoriesApi,
4187
+ developers: platformDpsDevelopersApi,
4188
+ links: platformDpsLinksApi,
4189
+ messaging: platformDpsMessagingApi,
4190
+ research: platformDpsResearchApi
4191
+ };
4192
+
4193
+ // src/apis/platform/adapter/instance.ts
4194
+ var import_axios12 = __toESM(require("axios"));
4195
+ function getPlatformAdapterClientAuthorization(req) {
4196
+ return {
4197
+ platform: {
4198
+ dps: req.headers["platform-dps-token"]
4199
+ },
4200
+ github: {
4201
+ app: req.headers["github-app-token"],
4202
+ oauth: req.headers["github-oauth-token"]
4203
+ },
4204
+ netlify: req.headers["netlify-token"],
4205
+ vercel: req.headers["vercel-token"],
4206
+ planetscale: req.headers["planetscale-token"],
4207
+ sentry: req.headers["sentry-token"]
4208
+ };
4209
+ }
4210
+ var platformAdapterClientInstance = import_axios12.default.create({
4211
+ baseURL: "https://platform.labs.text.com/console-adapter/api",
4212
+ headers: {
4213
+ "Content-Type": "application/json"
4214
+ }
4215
+ });
4216
+ platformAdapterClientInstance.interceptors.response.use(
4217
+ (r) => r,
4218
+ (error) => {
4219
+ var _a;
4220
+ if (import_axios12.default.isAxiosError(error)) {
4221
+ if (((_a = error.response) == null ? void 0 : _a.status) === 401 && error.response.data.error.source) {
4222
+ error = new UnauthorizeApiError(error.response.data.error.source);
4223
+ }
4224
+ }
4225
+ throw error;
4226
+ }
4227
+ );
4228
+ function getPlatformAdapterClientConfig(options = {}) {
4229
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
4230
+ const headers = {
4231
+ platform: {
4232
+ dps: (_b = platformAdapterClientInstance.defaults.headers["platform-dps-token"]) != null ? _b : (_a = options.platform) == null ? void 0 : _a.dps
4233
+ },
4234
+ integrations: {
4235
+ github: {
4236
+ app: (_d = platformAdapterClientInstance.defaults.headers["github-app-token"]) != null ? _d : (_c = options.github) == null ? void 0 : _c.app,
4237
+ oauth: (_f = platformAdapterClientInstance.defaults.headers["github-oauth-token"]) != null ? _f : (_e = options.github) == null ? void 0 : _e.oauth
4238
+ },
4239
+ netlify: (_g = platformAdapterClientInstance.defaults.headers["netlify-token"]) != null ? _g : options.netlify,
4240
+ vercel: (_h = platformAdapterClientInstance.defaults.headers["vercel-token"]) != null ? _h : options.vercel,
4241
+ planetscale: (_i = platformAdapterClientInstance.defaults.headers["planetscale-token"]) != null ? _i : options.planetscale,
4242
+ sentry: (_j = platformAdapterClientInstance.defaults.headers["sentry-token"]) != null ? _j : options.sentry
4243
+ }
4244
+ };
4245
+ if (((_l = (_k = options.ensureAuthorizationToken) == null ? void 0 : _k.platform) == null ? void 0 : _l.dps) && !headers.platform.dps) {
4246
+ throw new UnauthorizeApiError("dps");
4247
+ }
4248
+ if (((_m = options.ensureAuthorizationToken) == null ? void 0 : _m.github) && (!headers.integrations.github.app || !headers.integrations.github.oauth)) {
4249
+ throw new UnauthorizeApiError("github");
4250
+ }
4251
+ if (((_n = options.ensureAuthorizationToken) == null ? void 0 : _n.vercel) && !headers.integrations.vercel) {
4252
+ throw new UnauthorizeApiError("vercel");
4253
+ }
4254
+ if (((_o = options.ensureAuthorizationToken) == null ? void 0 : _o.netlify) && !headers.integrations.netlify) {
4255
+ throw new UnauthorizeApiError("netlify");
4256
+ }
4257
+ if (((_p = options.ensureAuthorizationToken) == null ? void 0 : _p.planetscale) && !headers.integrations.planetscale) {
4258
+ throw new UnauthorizeApiError("planetscale");
4259
+ }
4260
+ if (((_q = options.ensureAuthorizationToken) == null ? void 0 : _q.sentry) && !headers.integrations.sentry) {
4261
+ throw new UnauthorizeApiError("sentry");
4262
+ }
4263
+ return {
4264
+ headers: __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, headers.platform.dps ? { "platform-dps-token": headers.platform.dps } : {}), headers.integrations.github.app ? { "github-app-token": headers.integrations.github.app } : {}), headers.integrations.github.oauth ? { "github-oauth-token": headers.integrations.github.oauth } : {}), headers.integrations.netlify ? { "netlify-token": headers.integrations.netlify } : {}), headers.integrations.vercel ? { "vercel-token": headers.integrations.vercel } : {}), headers.integrations.planetscale ? { "planetscale-token": headers.integrations.planetscale } : {}), headers.integrations.sentry ? { "sentry-token": headers.integrations.sentry } : {})
4265
+ };
4266
+ }
4267
+ function initPlatformAdapterClientInstance(baseUrl, tokens) {
4268
+ if (baseUrl) {
4269
+ platformAdapterClientInstance.interceptors.request.use(
4270
+ (config) => __async(this, null, function* () {
4271
+ config.baseURL = baseUrl;
4272
+ return config;
4273
+ }),
4274
+ (error) => Promise.reject(error)
4275
+ );
4276
+ }
4277
+ if (tokens) {
4278
+ updatePlatformAdapterClientInstance(tokens);
4279
+ }
4280
+ }
4281
+ function updatePlatformAdapterClientInstance(tokens) {
4282
+ var _a;
4283
+ if ((_a = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _a.dps) {
4284
+ platformAdapterClientInstance.defaults.headers["platform-dps-token"] = tokens.platform.dps;
4285
+ }
4286
+ if (tokens == null ? void 0 : tokens.github.app) {
4287
+ platformAdapterClientInstance.defaults.headers["github-app-token"] = tokens.github.app;
4288
+ }
4289
+ if (tokens == null ? void 0 : tokens.github.oauth) {
4290
+ platformAdapterClientInstance.defaults.headers["github-oauth-token"] = tokens.github.oauth;
4291
+ }
4292
+ if (tokens == null ? void 0 : tokens.netlify) {
4293
+ platformAdapterClientInstance.defaults.headers["netlify-token"] = tokens.netlify;
4294
+ }
4295
+ if (tokens == null ? void 0 : tokens.vercel) {
4296
+ platformAdapterClientInstance.defaults.headers["vercel-token"] = tokens.vercel;
4297
+ }
4298
+ if (tokens == null ? void 0 : tokens.planetscale) {
4299
+ platformAdapterClientInstance.defaults.headers["planetscale-token"] = tokens.planetscale;
4300
+ }
4301
+ if (tokens == null ? void 0 : tokens.sentry) {
4302
+ platformAdapterClientInstance.defaults.headers["sentry-token"] = tokens.sentry;
4303
+ }
4304
+ }
4305
+
4306
+ // src/apis/platform/adapter/app/blocks/deployment/api.ts
4307
+ var platformAdapterAppDeploymentApi = {
4308
+ get(appId, authorization) {
4309
+ return __async(this, null, function* () {
4310
+ const response = yield platformAdapterClientInstance.get(
4311
+ `/console/app/${appId}/blocks/deployment`,
4312
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4313
+ ensureAuthorizationToken: {
4314
+ platform: {
4315
+ dps: true
4316
+ }
4317
+ }
4318
+ }))
4319
+ );
4320
+ return response.data;
4321
+ });
4322
+ },
4323
+ link(payload, authorization) {
4324
+ return __async(this, null, function* () {
4325
+ yield platformAdapterClientInstance.post(
4326
+ `/console/app/${payload.appId}/blocks/deployment/link`,
4327
+ payload,
4328
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4329
+ ensureAuthorizationToken: {
4330
+ platform: {
4331
+ dps: true
4332
+ }
4333
+ }
4334
+ }))
4335
+ );
4336
+ });
4337
+ },
4338
+ unlink(payload, authorization) {
4339
+ return __async(this, null, function* () {
4340
+ const response = yield platformAdapterClientInstance.post(
4341
+ `/console/app/${payload.appId}/blocks/deployment/unlink`,
4342
+ payload,
4343
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4344
+ ensureAuthorizationToken: {
4345
+ platform: {
4346
+ dps: true
4347
+ }
4348
+ }
4349
+ }))
4350
+ );
4351
+ return response.data;
4352
+ });
4353
+ },
4354
+ installSentry(appId, authorization) {
4355
+ return __async(this, null, function* () {
4356
+ const response = yield platformAdapterClientInstance.post(
4357
+ `/console/app/${appId}/blocks/deployment/install/sentry`,
4358
+ {},
4359
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4360
+ ensureAuthorizationToken: {
4361
+ platform: {
4362
+ dps: true
4363
+ }
4364
+ }
4365
+ }))
4366
+ );
4367
+ return response.data;
4368
+ });
4369
+ }
4370
+ };
4371
+
4372
+ // src/apis/platform/adapter/app/blocks/logger/providers/sentry/api.ts
4373
+ var platformAdapterAppSentryLoggerApi = {
4374
+ get(projectSlug, authorization) {
4375
+ return __async(this, null, function* () {
4376
+ const response = yield platformAdapterClientInstance.get(
4377
+ `/console/app/blocks/logger/providers/sentry/get?projectSlug=${projectSlug}`,
4378
+ getPlatformAdapterClientConfig(authorization)
4379
+ );
4380
+ return response.data;
4381
+ });
4382
+ },
4383
+ link(payload, authorization) {
4384
+ return __async(this, null, function* () {
4385
+ const response = yield platformAdapterClientInstance.post(
4386
+ "/console/app/blocks/logger/providers/sentry/link",
4387
+ payload,
4388
+ getPlatformAdapterClientConfig(authorization)
4389
+ );
4390
+ return response.data;
4391
+ });
4392
+ },
4393
+ unlink(payload, authorization) {
4394
+ return __async(this, null, function* () {
4395
+ const response = yield platformAdapterClientInstance.post(
4396
+ "/console/app/blocks/logger/providers/sentry/unlink",
4397
+ payload,
4398
+ getPlatformAdapterClientConfig(authorization)
4399
+ );
4400
+ return response.data;
4401
+ });
4402
+ },
4403
+ reauthorizeSentryApp(userId, sentryInstallationId, sentryRefreshToken, authorization) {
4404
+ return __async(this, null, function* () {
4405
+ const response = yield platformAdapterClientInstance.post(
4406
+ "/integrations/sentry/refresh",
4407
+ {
4408
+ userId,
4409
+ sentryInstallationId,
4410
+ sentryRefreshToken
4411
+ },
4412
+ getPlatformAdapterClientConfig(authorization)
4413
+ );
4414
+ return response.data;
4415
+ });
4416
+ },
4417
+ requestSentryIssueSolution(stacktrace, authorization) {
4418
+ return __async(this, null, function* () {
4419
+ const response = yield platformAdapterClientInstance.post(
4420
+ "/integrations/openai/issues/solution",
4421
+ {
4422
+ stacktrace
4423
+ },
4424
+ getPlatformAdapterClientConfig(authorization)
4425
+ );
4426
+ return response.data;
4427
+ });
4428
+ }
4429
+ };
4430
+
4431
+ // src/apis/platform/adapter/app/blocks/logger/api.ts
4432
+ var platformAdapterAppLoggerApi = {
4433
+ providers: {
4434
+ sentry: platformAdapterAppSentryLoggerApi
4435
+ }
4436
+ };
4437
+
4438
+ // src/apis/platform/adapter/app/blocks/repository/api.ts
4439
+ var platformAdapterAppRepositoryApi = {
4440
+ get(appId, authorization) {
4441
+ return __async(this, null, function* () {
4442
+ const response = yield platformAdapterClientInstance.get(
4443
+ `/console/app/${appId}/blocks/repository`,
4444
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4445
+ ensureAuthorizationToken: {
4446
+ platform: {
4447
+ dps: true
4448
+ }
4449
+ }
4450
+ }))
4451
+ );
4452
+ return response.data;
4453
+ });
4454
+ },
4455
+ link(payload, authorization) {
4456
+ return __async(this, null, function* () {
4457
+ const response = yield platformAdapterClientInstance.post(
4458
+ `/console/app/${payload.appId}/blocks/repository/link`,
4459
+ payload,
4460
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4461
+ ensureAuthorizationToken: {
4462
+ platform: {
4463
+ dps: true
4464
+ }
4465
+ }
4466
+ }))
4467
+ );
4468
+ return response.data;
4469
+ });
4470
+ },
4471
+ unlink(payload, authorization) {
4472
+ return __async(this, null, function* () {
4473
+ const response = yield platformAdapterClientInstance.post(
4474
+ `/console/app/${payload.appId}/blocks/repository/unlink`,
4475
+ payload,
4476
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4477
+ ensureAuthorizationToken: {
4478
+ platform: {
4479
+ dps: true
4480
+ }
4481
+ }
4482
+ }))
4483
+ );
4484
+ return response.data;
4485
+ });
4486
+ },
4487
+ seed(payload, authorization) {
4488
+ return __async(this, null, function* () {
4489
+ const response = yield platformAdapterClientInstance.post(
4490
+ `/console/app/${payload.appId}/blocks/repository/seed`,
4491
+ payload,
4492
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4493
+ ensureAuthorizationToken: {
4494
+ platform: {
4495
+ dps: true
4496
+ }
4497
+ }
4498
+ }))
4499
+ );
4500
+ return response.data;
4501
+ });
4502
+ }
4503
+ };
4504
+
4505
+ // src/apis/platform/adapter/app/blocks/storage/api.ts
4506
+ var platformAdapterAppStorageApi = {
4507
+ get(appId, authorization) {
4508
+ return __async(this, null, function* () {
4509
+ const response = yield platformAdapterClientInstance.get(
4510
+ `/console/app/${appId}/blocks/storage`,
4511
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4512
+ ensureAuthorizationToken: {
4513
+ platform: {
4514
+ dps: true
4515
+ }
4516
+ }
4517
+ }))
4518
+ );
4519
+ return response.data;
4520
+ });
4521
+ },
4522
+ link(payload, authorization) {
4523
+ return __async(this, null, function* () {
4524
+ yield platformAdapterClientInstance.post(
4525
+ `/console/app/${payload.appId}/blocks/storage/link`,
4526
+ payload,
4527
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4528
+ ensureAuthorizationToken: {
4529
+ platform: {
4530
+ dps: true
4531
+ }
4532
+ }
4533
+ }))
4534
+ );
4535
+ });
4536
+ },
4537
+ unlink(payload, authorization) {
4538
+ return __async(this, null, function* () {
4539
+ const response = yield platformAdapterClientInstance.post(
4540
+ `/console/app/${payload.appId}/blocks/storage/unlink`,
4541
+ payload,
4542
+ getPlatformAdapterClientConfig(__spreadProps(__spreadValues({}, authorization), {
4543
+ ensureAuthorizationToken: {
4544
+ platform: {
4545
+ dps: true
4546
+ }
4547
+ }
4548
+ }))
4549
+ );
4550
+ return response.data;
4551
+ });
4552
+ }
4553
+ };
4554
+
4555
+ // src/apis/platform/adapter/app/blocks/api.ts
4556
+ var platformAdapterAppBlocksApi = {
4557
+ repository: platformAdapterAppRepositoryApi,
4558
+ deployment: platformAdapterAppDeploymentApi,
4559
+ storage: platformAdapterAppStorageApi,
4560
+ logger: platformAdapterAppLoggerApi
4561
+ };
4562
+
4563
+ // src/apis/platform/adapter/app/variables/api.ts
4564
+ var platformAdapterAppVariablesApi = {
4565
+ getVariables(appId, decrypted, authorization) {
4566
+ return __async(this, null, function* () {
4567
+ const response = yield platformAdapterClientInstance.get(
4568
+ `/console/app/${appId}/variables`,
4569
+ __spreadValues({
4570
+ params: {
4571
+ decrypted
4572
+ }
4573
+ }, getPlatformAdapterClientConfig(authorization))
4574
+ );
4575
+ return response.data;
4576
+ });
4577
+ },
4578
+ getVariable(appId, key, authorization) {
4579
+ return __async(this, null, function* () {
4580
+ const response = yield platformAdapterClientInstance.get(
4581
+ `/console/app/${appId}/variables/${key}`,
4582
+ getPlatformAdapterClientConfig(authorization)
4583
+ );
4584
+ return response.data;
4585
+ });
4586
+ },
4587
+ syncVariable(appId, key, payload, authorization) {
4588
+ return __async(this, null, function* () {
4589
+ const response = yield platformAdapterClientInstance.post(
4590
+ `/console/app/${appId}/variables/${key}/sync`,
4591
+ payload,
4592
+ getPlatformAdapterClientConfig(authorization)
4593
+ );
4594
+ return response.data;
4595
+ });
4596
+ }
4597
+ };
4598
+
4599
+ // src/apis/platform/adapter/app/api.ts
4600
+ var platformAdapterAppApi = {
4601
+ blocks: platformAdapterAppBlocksApi,
4602
+ variables: platformAdapterAppVariablesApi,
4603
+ create(payload, authorization) {
4604
+ return __async(this, null, function* () {
4605
+ const response = yield platformAdapterClientInstance.post(
4606
+ `/console/app/new`,
4607
+ payload,
4608
+ getPlatformAdapterClientConfig(authorization)
4609
+ );
4610
+ return response.data;
4611
+ });
4612
+ },
4613
+ createStatus(sagaId, authorization) {
4614
+ return __async(this, null, function* () {
4615
+ const response = yield platformAdapterClientInstance.get(
4616
+ `/console/app/new/status`,
4617
+ __spreadValues({
4618
+ params: {
4619
+ sagaId
4620
+ }
4621
+ }, getPlatformAdapterClientConfig(authorization))
4622
+ );
4623
+ return response.data;
4624
+ });
4625
+ }
4626
+ };
4627
+
4628
+ // src/apis/platform/adapter/api.ts
4629
+ var platformAdapterApi = {
4630
+ app: platformAdapterAppApi
4631
+ };
4632
+
4633
+ // src/apis/platform/api.ts
4634
+ var platformApi = {
4635
+ accounts: platformAccountsApi,
4636
+ adapter: platformAdapterApi,
4637
+ dps: platformDpsApi
4638
+ };
4639
+
4640
+ // src/apis/platform/dps/applications/application/reporting/_contracts/dtos/events/error.ts
4641
+ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
4642
+ ErrorType2["4xx"] = "4xx";
4643
+ ErrorType2["5xx"] = "5xx";
4644
+ return ErrorType2;
4645
+ })(ErrorType || {});
4646
+
4647
+ // src/apis/api.ts
4648
+ var api = {
4649
+ platform: platformApi,
4650
+ products: productsApi,
4651
+ integrations: integrationsApi,
4652
+ isInitialized: false
4653
+ };
4654
+ function initApi(config, tokens) {
4655
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s;
4656
+ initPlatformAccountsClientInstance(
4657
+ (_a = config.urls.platform) == null ? void 0 : _a.accounts,
4658
+ (_b = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _b.dps
4659
+ );
4660
+ initPlatformDpsClientInstance(
4661
+ (_c = config.urls.platform) == null ? void 0 : _c.dps,
4662
+ (_d = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _d.dps
4663
+ );
4664
+ initPlatformAdapterClientInstance(
4665
+ (_e = config.urls.platform) == null ? void 0 : _e.adapter,
4666
+ tokens ? {
4667
+ platform: {
4668
+ dps: (_f = tokens.platform) == null ? void 0 : _f.dps
4669
+ },
4670
+ github: {
4671
+ app: (_g = tokens.github) == null ? void 0 : _g.apps,
4672
+ oauth: (_h = tokens.github) == null ? void 0 : _h.oauth
4673
+ },
4674
+ netlify: (_i = tokens.netlify) == null ? void 0 : _i.token,
4675
+ vercel: (_j = tokens.vercel) == null ? void 0 : _j.token,
4676
+ planetscale: (_k = tokens.planetscale) == null ? void 0 : _k.token,
4677
+ sentry: (_l = tokens.sentry) == null ? void 0 : _l.token
4678
+ } : void 0
4679
+ );
4680
+ initLiveChatClientInstance(
4681
+ (_m = config.urls.products) == null ? void 0 : _m.livechat,
4682
+ (_n = tokens == null ? void 0 : tokens.platform) == null ? void 0 : _n.dps
4683
+ );
4684
+ initGithubClientInstance((_o = tokens == null ? void 0 : tokens.github) == null ? void 0 : _o.apps);
4685
+ initNetlifyClientInstance((_p = tokens == null ? void 0 : tokens.netlify) == null ? void 0 : _p.token);
4686
+ initVercelClientInstance((_q = tokens == null ? void 0 : tokens.vercel) == null ? void 0 : _q.token);
4687
+ initPlanetScaleClientInstance((_r = tokens == null ? void 0 : tokens.planetscale) == null ? void 0 : _r.token);
4688
+ initSentryClientInstance((_s = tokens == null ? void 0 : tokens.sentry) == null ? void 0 : _s.token);
4689
+ api.isInitialized = true;
4690
+ }
4691
+
4692
+ // src/utils/serializer.ts
4693
+ var serializerBase64 = {
4694
+ serialize(state) {
4695
+ return btoa(escape(JSON.stringify(state)));
4696
+ },
4697
+ deserialize(message) {
4698
+ try {
4699
+ return message ? JSON.parse(unescape(atob(unescape(message)))) : void 0;
4700
+ } catch (e) {
4701
+ }
4702
+ }
4703
+ };
4704
+ // Annotate the CommonJS export names for ESM import in node:
4705
+ 0 && (module.exports = {
4706
+ API_NOTIFICATIONS,
4707
+ ErrorType,
4708
+ UnauthorizeApiError,
4709
+ api,
4710
+ getAppAutoReviewPayload,
4711
+ getEmptyAppAutoReview,
4712
+ getGitHubClientAuthorization,
4713
+ getGithubClientRequestConfig,
4714
+ getLiveChatClientAuthorization,
4715
+ getLiveChatClientConfig,
4716
+ getNetlifyClientAuthorization,
4717
+ getNetlifyClientConfig,
4718
+ getPlanetScaleClientAuthorization,
4719
+ getPlanetScaleClientConfig,
4720
+ getPlatformAccountsClientAuthorization,
4721
+ getPlatformAccountsClientConfig,
4722
+ getPlatformAdapterClientAuthorization,
4723
+ getPlatformAdapterClientConfig,
4724
+ getPlatformDpsAdminClientAuthorization,
4725
+ getPlatformDpsClientAuthorization,
4726
+ getPlatformDpsClientConfig,
4727
+ getRegion,
4728
+ getSentryClientAuthorization,
4729
+ getSentryClientConfig,
4730
+ getVercelClientAuthorization,
4731
+ getVercelClientConfig,
4732
+ githubClientInstance,
4733
+ initApi,
4734
+ initGithubClientInstance,
4735
+ initLiveChatClientInstance,
4736
+ initNetlifyClientInstance,
4737
+ initPlanetScaleClientInstance,
4738
+ initPlatformAccountsClientInstance,
4739
+ initPlatformAdapterClientInstance,
4740
+ initPlatformDpsClientInstance,
4741
+ initSentryClientInstance,
4742
+ initVercelClientInstance,
4743
+ livechatClientInstance,
4744
+ netlifyClientInstance,
4745
+ planetScaleClientInstance,
4746
+ platformAccountsClientInstance,
4747
+ platformAdapterClientInstance,
4748
+ platformDpsClientInstance,
4749
+ sentryClientInstance,
4750
+ serializerBase64,
4751
+ updateGithubClientInstance,
4752
+ updateNetlifyClientInstance,
4753
+ updatePlanetScaleClientInstance,
4754
+ updatePlatformAdapterClientInstance,
4755
+ updateSentryClientInstance,
4756
+ updateVercelClientInstance,
4757
+ vercelClientInstance
4758
+ });