@superblocksteam/sdk 1.4.1 → 1.5.0
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/.eslintrc.json +3 -0
- package/dist/client.d.ts +21 -14
- package/dist/client.js +198 -79
- package/dist/flag.d.ts +2 -0
- package/dist/flag.js +8 -0
- package/dist/sdk.d.ts +8 -7
- package/dist/sdk.js +16 -8
- package/dist/socket/handlers.d.ts +105 -0
- package/dist/socket/handlers.js +85 -0
- package/dist/socket/index.d.ts +27 -0
- package/dist/socket/index.js +69 -0
- package/dist/socket/signing.d.ts +13 -0
- package/dist/socket/signing.js +81 -0
- package/dist/socket/socket.d.ts +16 -0
- package/dist/socket/socket.js +157 -0
- package/dist/types/common.d.ts +111 -0
- package/dist/types/common.js +33 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +7 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/plugin.js +9 -0
- package/dist/types/signing.d.ts +51 -0
- package/dist/types/signing.js +2 -0
- package/dist/types/socket.d.ts +17 -0
- package/dist/types/socket.js +2 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +36 -0
- package/package.json +5 -3
- package/src/client.ts +258 -83
- package/src/flag.ts +5 -0
- package/src/sdk.ts +48 -14
- package/src/socket/handlers.ts +228 -0
- package/src/socket/index.ts +164 -0
- package/src/socket/signing.ts +113 -0
- package/src/socket/socket.ts +253 -0
- package/src/types/common.ts +138 -0
- package/src/types/index.ts +4 -0
- package/src/types/plugin.ts +7 -0
- package/src/types/signing.ts +61 -0
- package/src/types/socket.ts +48 -0
- package/src/utils.ts +45 -0
- package/tsconfig.json +3 -1
package/src/client.ts
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import {
|
|
3
|
+
COMPONENT_EVENT_HEADER,
|
|
3
4
|
ComponentEvent,
|
|
4
5
|
getBucketeerUrlFromSuperblocksUrl,
|
|
5
|
-
getSuperblocksMonorepoConfigJson,
|
|
6
6
|
getContentType,
|
|
7
|
-
COMPONENT_EVENT_HEADER,
|
|
8
|
-
NotFoundError,
|
|
9
7
|
LocalGitRepoState,
|
|
10
|
-
|
|
8
|
+
NotFoundError,
|
|
11
9
|
SuperblocksResourceType,
|
|
12
10
|
unreachable,
|
|
11
|
+
ValidateGitSetupRequestBody,
|
|
13
12
|
} from "@superblocksteam/util";
|
|
14
13
|
import axios, { AxiosError, AxiosRequestConfig } from "axios";
|
|
15
|
-
import
|
|
14
|
+
import FormData from "form-data";
|
|
16
15
|
import { isEmpty } from "lodash";
|
|
17
16
|
import { BranchNotCheckedOutError, CommitAlreadyExistsError } from "./errors";
|
|
17
|
+
import { signingEnabled } from "./flag";
|
|
18
|
+
import { connectToISocketRPCServer } from "./socket";
|
|
19
|
+
import { AgentType, RemoteCommitDto, UserMeDto } from "./types";
|
|
20
|
+
import { getAgentUrls } from "./utils";
|
|
18
21
|
|
|
19
|
-
const
|
|
20
|
-
const
|
|
22
|
+
const BASE_BUCKETEER_URL = "api";
|
|
23
|
+
const BASE_SERVER_PUBLIC_API_URL = "api/v1/public";
|
|
21
24
|
|
|
22
25
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
23
26
|
|
|
@@ -66,6 +69,7 @@ export type Branch = {
|
|
|
66
69
|
type ResponseWithMeta<T> = { responseMeta: unknown; data: T };
|
|
67
70
|
|
|
68
71
|
export async function fetchApplication({
|
|
72
|
+
cliVersion,
|
|
69
73
|
applicationId,
|
|
70
74
|
branch,
|
|
71
75
|
token,
|
|
@@ -73,6 +77,7 @@ export async function fetchApplication({
|
|
|
73
77
|
viewMode,
|
|
74
78
|
injectedHeaders = {},
|
|
75
79
|
}: {
|
|
80
|
+
cliVersion: string;
|
|
76
81
|
applicationId: string;
|
|
77
82
|
branch?: string;
|
|
78
83
|
token: string;
|
|
@@ -82,11 +87,13 @@ export async function fetchApplication({
|
|
|
82
87
|
}): Promise<ApplicationWrapper | undefined> {
|
|
83
88
|
const serverURL = branch
|
|
84
89
|
? new URL(
|
|
85
|
-
|
|
90
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
91
|
+
branch
|
|
92
|
+
)}?viewMode=${viewMode}`,
|
|
86
93
|
superblocksBaseUrl
|
|
87
94
|
)
|
|
88
95
|
: new URL(
|
|
89
|
-
|
|
96
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`,
|
|
90
97
|
superblocksBaseUrl
|
|
91
98
|
);
|
|
92
99
|
|
|
@@ -98,6 +105,7 @@ export async function fetchApplication({
|
|
|
98
105
|
url: serverURL.toString(),
|
|
99
106
|
headers: {
|
|
100
107
|
Authorization: "Bearer " + token,
|
|
108
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
101
109
|
...injectedHeaders,
|
|
102
110
|
},
|
|
103
111
|
};
|
|
@@ -113,18 +121,20 @@ export async function fetchApplication({
|
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
export async function fetchApplicationBranches({
|
|
124
|
+
cliVersion,
|
|
116
125
|
applicationId,
|
|
117
126
|
token,
|
|
118
127
|
superblocksBaseUrl,
|
|
119
128
|
injectedHeaders = {},
|
|
120
129
|
}: {
|
|
130
|
+
cliVersion: string;
|
|
121
131
|
applicationId: string;
|
|
122
132
|
token: string;
|
|
123
133
|
superblocksBaseUrl: string;
|
|
124
134
|
injectedHeaders: Record<string, string>;
|
|
125
135
|
}): Promise<Branches | undefined> {
|
|
126
136
|
const serverURL = new URL(
|
|
127
|
-
`
|
|
137
|
+
`public/applications/${applicationId}/branches`,
|
|
128
138
|
superblocksBaseUrl
|
|
129
139
|
);
|
|
130
140
|
let serverResponse;
|
|
@@ -135,6 +145,7 @@ export async function fetchApplicationBranches({
|
|
|
135
145
|
url: serverURL.toString(),
|
|
136
146
|
headers: {
|
|
137
147
|
Authorization: "Bearer " + token,
|
|
148
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
138
149
|
...injectedHeaders,
|
|
139
150
|
},
|
|
140
151
|
};
|
|
@@ -150,6 +161,7 @@ export async function fetchApplicationBranches({
|
|
|
150
161
|
}
|
|
151
162
|
|
|
152
163
|
export async function fetchApplicationWithComponents({
|
|
164
|
+
cliVersion,
|
|
153
165
|
applicationId,
|
|
154
166
|
branch,
|
|
155
167
|
token,
|
|
@@ -157,6 +169,7 @@ export async function fetchApplicationWithComponents({
|
|
|
157
169
|
viewMode,
|
|
158
170
|
injectedHeaders = {},
|
|
159
171
|
}: {
|
|
172
|
+
cliVersion: string;
|
|
160
173
|
applicationId: string;
|
|
161
174
|
branch: string;
|
|
162
175
|
token: string;
|
|
@@ -165,6 +178,7 @@ export async function fetchApplicationWithComponents({
|
|
|
165
178
|
injectedHeaders: Record<string, string>;
|
|
166
179
|
}): Promise<(ApplicationWrapper & { componentFiles: any }) | undefined> {
|
|
167
180
|
const applicationWrapper = await fetchApplication({
|
|
181
|
+
cliVersion,
|
|
168
182
|
applicationId,
|
|
169
183
|
branch,
|
|
170
184
|
token,
|
|
@@ -194,7 +208,7 @@ export async function fetchApplicationWithComponents({
|
|
|
194
208
|
// fetch files from bucketeer
|
|
195
209
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
196
210
|
const componentFileURL = new URL(
|
|
197
|
-
`${BASE_BUCKETEER_URL}/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`,
|
|
211
|
+
`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`,
|
|
198
212
|
bucketeerBaseUrl
|
|
199
213
|
).toString();
|
|
200
214
|
|
|
@@ -219,6 +233,7 @@ export async function fetchApplicationWithComponents({
|
|
|
219
233
|
}
|
|
220
234
|
|
|
221
235
|
export async function fetchApplications(
|
|
236
|
+
cliVersion: string,
|
|
222
237
|
token: string,
|
|
223
238
|
superblocksBaseUrl: string,
|
|
224
239
|
injectedHeaders: Record<string, string> = {}
|
|
@@ -226,34 +241,61 @@ export async function fetchApplications(
|
|
|
226
241
|
try {
|
|
227
242
|
const config: AxiosRequestConfig = {
|
|
228
243
|
method: "get",
|
|
229
|
-
url: new URL(
|
|
244
|
+
url: new URL(
|
|
245
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications`,
|
|
246
|
+
superblocksBaseUrl
|
|
247
|
+
).toString(),
|
|
230
248
|
headers: {
|
|
231
249
|
Authorization: "Bearer " + token,
|
|
250
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
232
251
|
...injectedHeaders,
|
|
233
252
|
},
|
|
234
253
|
};
|
|
235
254
|
const response = await axios(config);
|
|
236
255
|
return response.data.data.applications;
|
|
237
|
-
} catch (e) {
|
|
238
|
-
|
|
256
|
+
} catch (e: any) {
|
|
257
|
+
let message: string;
|
|
258
|
+
if (e instanceof AxiosError) {
|
|
259
|
+
message =
|
|
260
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
261
|
+
JSON.stringify(e.response?.data) ??
|
|
262
|
+
e.response?.statusText ??
|
|
263
|
+
e?.message ??
|
|
264
|
+
`${e}`;
|
|
265
|
+
} else {
|
|
266
|
+
message = `${e?.message ? e?.message : e}`;
|
|
267
|
+
}
|
|
268
|
+
throw new Error(`Could not fetch applications: ${message}`);
|
|
239
269
|
}
|
|
240
270
|
}
|
|
241
271
|
|
|
242
272
|
export async function fetchApi(
|
|
273
|
+
cliVersion: string,
|
|
243
274
|
apiId: string,
|
|
244
275
|
token: string,
|
|
245
276
|
superblocksBaseUrl: string,
|
|
246
|
-
viewMode: ViewMode
|
|
277
|
+
viewMode: ViewMode,
|
|
278
|
+
branch?: string
|
|
247
279
|
) {
|
|
248
280
|
try {
|
|
281
|
+
const serverURL = branch
|
|
282
|
+
? new URL(
|
|
283
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(
|
|
284
|
+
branch
|
|
285
|
+
)}?viewMode=${viewMode}`,
|
|
286
|
+
superblocksBaseUrl
|
|
287
|
+
)
|
|
288
|
+
: new URL(
|
|
289
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}?viewMode=${viewMode}`,
|
|
290
|
+
superblocksBaseUrl
|
|
291
|
+
);
|
|
292
|
+
|
|
249
293
|
const config: AxiosRequestConfig = {
|
|
250
294
|
method: "get",
|
|
251
|
-
url: new URL(
|
|
252
|
-
`/api/v3/apis/${apiId}?viewMode=${viewMode}`,
|
|
253
|
-
superblocksBaseUrl
|
|
254
|
-
).toString(),
|
|
295
|
+
url: new URL(serverURL, superblocksBaseUrl).toString(),
|
|
255
296
|
headers: {
|
|
256
297
|
Authorization: "Bearer " + token,
|
|
298
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
257
299
|
},
|
|
258
300
|
};
|
|
259
301
|
const response = await axios(config);
|
|
@@ -266,23 +308,32 @@ export async function fetchApi(
|
|
|
266
308
|
}
|
|
267
309
|
}
|
|
268
310
|
|
|
269
|
-
export async function fetchApis(
|
|
311
|
+
export async function fetchApis(
|
|
312
|
+
cliVersion: string,
|
|
313
|
+
token: string,
|
|
314
|
+
superblocksBaseUrl: string
|
|
315
|
+
) {
|
|
270
316
|
try {
|
|
271
317
|
const config: AxiosRequestConfig = {
|
|
272
318
|
method: "get",
|
|
273
|
-
url: new URL(
|
|
319
|
+
url: new URL(
|
|
320
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis`,
|
|
321
|
+
superblocksBaseUrl
|
|
322
|
+
).toString(),
|
|
274
323
|
headers: {
|
|
275
324
|
Authorization: "Bearer " + token,
|
|
325
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
276
326
|
},
|
|
277
327
|
};
|
|
278
328
|
const response = await axios(config);
|
|
279
|
-
return response.data.data;
|
|
329
|
+
return response.data.data.apis;
|
|
280
330
|
} catch (e) {
|
|
281
331
|
throw new Error("Could not fetch apis");
|
|
282
332
|
}
|
|
283
333
|
}
|
|
284
334
|
|
|
285
335
|
export async function validateGitSetup(
|
|
336
|
+
cliVersion: string,
|
|
286
337
|
resourceId: string,
|
|
287
338
|
resourceType: SuperblocksResourceType,
|
|
288
339
|
event: ComponentEvent,
|
|
@@ -293,7 +344,6 @@ export async function validateGitSetup(
|
|
|
293
344
|
) {
|
|
294
345
|
let resourceName: string | undefined;
|
|
295
346
|
try {
|
|
296
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
297
347
|
const requestBody: ValidateGitSetupRequestBody = {
|
|
298
348
|
event,
|
|
299
349
|
gitState: localGitRepoState,
|
|
@@ -301,11 +351,11 @@ export async function validateGitSetup(
|
|
|
301
351
|
let path: string;
|
|
302
352
|
switch (resourceType) {
|
|
303
353
|
case "APPLICATION": {
|
|
304
|
-
path = `/
|
|
354
|
+
path = `/application/${resourceId}/validate-git-setup`;
|
|
305
355
|
break;
|
|
306
356
|
}
|
|
307
357
|
case "BACKEND": {
|
|
308
|
-
path = `/
|
|
358
|
+
path = `/api/${resourceId}/validate-git-setup`;
|
|
309
359
|
break;
|
|
310
360
|
}
|
|
311
361
|
default:
|
|
@@ -313,10 +363,13 @@ export async function validateGitSetup(
|
|
|
313
363
|
}
|
|
314
364
|
const config: AxiosRequestConfig = {
|
|
315
365
|
method: "post",
|
|
316
|
-
url: new URL(
|
|
366
|
+
url: new URL(
|
|
367
|
+
`${BASE_SERVER_PUBLIC_API_URL}/${path}`,
|
|
368
|
+
superblocksBaseUrl
|
|
369
|
+
).toString(),
|
|
317
370
|
headers: {
|
|
318
371
|
Authorization: "Bearer " + token,
|
|
319
|
-
[CLI_VERSION_HEADER]:
|
|
372
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
320
373
|
...injectedHeaders,
|
|
321
374
|
},
|
|
322
375
|
data: requestBody,
|
|
@@ -353,31 +406,55 @@ export async function validateGitSetup(
|
|
|
353
406
|
}
|
|
354
407
|
|
|
355
408
|
export async function registerComponents(
|
|
409
|
+
cliVersion: string,
|
|
356
410
|
applicationId: string,
|
|
357
411
|
componentConfigs: Record<string, any>,
|
|
358
412
|
token: string,
|
|
359
413
|
superblocksBaseUrl: string,
|
|
360
414
|
branch: string | null,
|
|
361
|
-
injectedHeaders
|
|
415
|
+
injectedHeaders: Record<string, string>
|
|
362
416
|
) {
|
|
363
417
|
try {
|
|
364
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
365
418
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
419
|
+
const userMe = await fetchCurrentUser(
|
|
420
|
+
cliVersion,
|
|
421
|
+
token,
|
|
422
|
+
superblocksBaseUrl
|
|
423
|
+
);
|
|
424
|
+
const organization = userMe.organizations[0];
|
|
425
|
+
if (organization.agentType == AgentType.ONPREMISE && signingEnabled(userMe.flagBootstrap)) {
|
|
426
|
+
const agentUrls = getAgentUrls(userMe.agents, organization.agentType);
|
|
427
|
+
const socket = await connectToISocketRPCServer({
|
|
428
|
+
agentUrls,
|
|
429
|
+
superblocksBaseUrl,
|
|
430
|
+
token,
|
|
431
|
+
});
|
|
432
|
+
const resp = await socket.call.v1.public.application.component.register({
|
|
433
|
+
applicationId,
|
|
434
|
+
branchName: branch || "",
|
|
435
|
+
cliVersion: cliVersion,
|
|
436
|
+
componentEvent: injectedHeaders[COMPONENT_EVENT_HEADER],
|
|
437
|
+
components: componentConfigs,
|
|
438
|
+
});
|
|
439
|
+
socket.close();
|
|
440
|
+
return resp.data;
|
|
441
|
+
} else {
|
|
442
|
+
const config: AxiosRequestConfig = {
|
|
443
|
+
method: "put",
|
|
444
|
+
url: new URL(
|
|
445
|
+
`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`,
|
|
446
|
+
superblocksBaseUrl
|
|
447
|
+
).toString(),
|
|
448
|
+
headers: {
|
|
449
|
+
Authorization: "Bearer " + token,
|
|
450
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
451
|
+
...injectedHeaders,
|
|
452
|
+
},
|
|
453
|
+
data: { components: componentConfigs },
|
|
454
|
+
};
|
|
455
|
+
const response = await axios(config);
|
|
456
|
+
return response.data;
|
|
457
|
+
}
|
|
381
458
|
} catch (e: any) {
|
|
382
459
|
if (e instanceof AxiosError) {
|
|
383
460
|
const message: string =
|
|
@@ -399,6 +476,7 @@ export async function registerComponents(
|
|
|
399
476
|
}
|
|
400
477
|
|
|
401
478
|
export async function uploadComponents({
|
|
479
|
+
cliVersion,
|
|
402
480
|
applicationId,
|
|
403
481
|
componentConfigs,
|
|
404
482
|
files,
|
|
@@ -406,6 +484,7 @@ export async function uploadComponents({
|
|
|
406
484
|
superblocksBaseUrl,
|
|
407
485
|
branch,
|
|
408
486
|
}: {
|
|
487
|
+
cliVersion: string;
|
|
409
488
|
applicationId: string;
|
|
410
489
|
componentConfigs: Record<string, any>;
|
|
411
490
|
files: string[];
|
|
@@ -445,7 +524,7 @@ export async function uploadComponents({
|
|
|
445
524
|
buildFiles,
|
|
446
525
|
});
|
|
447
526
|
const postURL = new URL(
|
|
448
|
-
`${BASE_BUCKETEER_URL}/components/upload`,
|
|
527
|
+
`${BASE_BUCKETEER_URL}/v2/components/upload`,
|
|
449
528
|
bucketeerBaseUrl
|
|
450
529
|
).toString();
|
|
451
530
|
|
|
@@ -469,20 +548,48 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
469
548
|
const formHeaders = formData.getHeaders();
|
|
470
549
|
|
|
471
550
|
try {
|
|
472
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
473
551
|
const config: AxiosRequestConfig = {
|
|
474
552
|
headers: {
|
|
475
553
|
Authorization: "Bearer " + token,
|
|
476
|
-
[CLI_VERSION_HEADER]:
|
|
554
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
477
555
|
[COMPONENT_EVENT_HEADER]: ComponentEvent.UPLOAD,
|
|
478
556
|
[SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
|
|
479
|
-
|
|
557
|
+
...formHeaders,
|
|
480
558
|
},
|
|
481
559
|
};
|
|
482
560
|
|
|
483
|
-
const
|
|
561
|
+
const uploadResponse = await axios.post(postURL, formData, config);
|
|
484
562
|
|
|
485
|
-
|
|
563
|
+
const userMe = await fetchCurrentUser(
|
|
564
|
+
cliVersion,
|
|
565
|
+
token,
|
|
566
|
+
superblocksBaseUrl
|
|
567
|
+
);
|
|
568
|
+
const organization = userMe.organizations[0];
|
|
569
|
+
const signingRequired = organization.agentType == AgentType.ONPREMISE && signingEnabled(userMe.flagBootstrap);
|
|
570
|
+
let agentUrls: string[] = [];
|
|
571
|
+
if (signingRequired) {
|
|
572
|
+
agentUrls = getAgentUrls(userMe.agents, organization.agentType);
|
|
573
|
+
}
|
|
574
|
+
const socket = await connectToISocketRPCServer({
|
|
575
|
+
agentUrls,
|
|
576
|
+
superblocksBaseUrl,
|
|
577
|
+
token,
|
|
578
|
+
});
|
|
579
|
+
try {
|
|
580
|
+
await socket.call.v1.public.application.component.update({
|
|
581
|
+
applicationId,
|
|
582
|
+
branchName: branch ?? undefined,
|
|
583
|
+
srcFiles: srcFiles.map((file) => file.filename),
|
|
584
|
+
buildFiles: buildFiles.map((file) => file.filename),
|
|
585
|
+
registeredComponents: componentConfigs,
|
|
586
|
+
cliVersion,
|
|
587
|
+
componentBaseUrl: uploadResponse.data.componentBaseUrl,
|
|
588
|
+
signingRequired,
|
|
589
|
+
});
|
|
590
|
+
} finally {
|
|
591
|
+
socket.close();
|
|
592
|
+
}
|
|
486
593
|
} catch (e: any) {
|
|
487
594
|
if (e instanceof AxiosError && e.response?.status === 413) {
|
|
488
595
|
throw new Error(
|
|
@@ -506,26 +613,43 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
506
613
|
}
|
|
507
614
|
|
|
508
615
|
export async function fetchCurrentUser(
|
|
616
|
+
cliVersion: string,
|
|
509
617
|
token: string,
|
|
510
618
|
superblocksBaseUrl: string
|
|
511
|
-
) {
|
|
619
|
+
): Promise<UserMeDto> {
|
|
512
620
|
try {
|
|
513
621
|
const config: AxiosRequestConfig = {
|
|
514
622
|
method: "get",
|
|
515
|
-
url: new URL(
|
|
623
|
+
url: new URL(
|
|
624
|
+
`${BASE_SERVER_PUBLIC_API_URL}/users/me`,
|
|
625
|
+
superblocksBaseUrl
|
|
626
|
+
).toString(),
|
|
516
627
|
headers: {
|
|
517
628
|
Authorization: "Bearer " + token,
|
|
629
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
518
630
|
[COMPONENT_EVENT_HEADER]: ComponentEvent.LOGIN,
|
|
519
631
|
},
|
|
520
632
|
};
|
|
521
633
|
const response = await axios(config);
|
|
522
|
-
return response.data.data
|
|
523
|
-
} catch (e) {
|
|
524
|
-
|
|
634
|
+
return response.data.data as UserMeDto;
|
|
635
|
+
} catch (e: any) {
|
|
636
|
+
let message: string;
|
|
637
|
+
if (e instanceof AxiosError) {
|
|
638
|
+
message =
|
|
639
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
640
|
+
JSON.stringify(e.response?.data) ??
|
|
641
|
+
e.response?.statusText ??
|
|
642
|
+
e?.message ??
|
|
643
|
+
`${e}`;
|
|
644
|
+
} else {
|
|
645
|
+
message = `${e?.message ? e?.message : e}`;
|
|
646
|
+
}
|
|
647
|
+
throw new Error(`Could not fetch current user: ${message}`);
|
|
525
648
|
}
|
|
526
649
|
}
|
|
527
650
|
|
|
528
651
|
export async function pushApplication({
|
|
652
|
+
cliVersion,
|
|
529
653
|
applicationId,
|
|
530
654
|
token,
|
|
531
655
|
superblocksBaseUrl,
|
|
@@ -533,16 +657,16 @@ export async function pushApplication({
|
|
|
533
657
|
branch,
|
|
534
658
|
injectedHeaders = {},
|
|
535
659
|
}: {
|
|
660
|
+
cliVersion: string;
|
|
536
661
|
applicationId: string;
|
|
537
662
|
token: string;
|
|
538
663
|
superblocksBaseUrl: string;
|
|
539
664
|
branch: string;
|
|
540
665
|
injectedHeaders: Record<string, string>;
|
|
541
666
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
542
|
-
}): Promise<
|
|
543
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
667
|
+
}): Promise<RemoteCommitDto | undefined> {
|
|
544
668
|
const serverURL = new URL(
|
|
545
|
-
`${
|
|
669
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
546
670
|
branch
|
|
547
671
|
)}/push`,
|
|
548
672
|
superblocksBaseUrl
|
|
@@ -550,17 +674,43 @@ export async function pushApplication({
|
|
|
550
674
|
let serverResponse;
|
|
551
675
|
|
|
552
676
|
try {
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
677
|
+
const userMe = await fetchCurrentUser(
|
|
678
|
+
cliVersion,
|
|
679
|
+
token,
|
|
680
|
+
superblocksBaseUrl
|
|
681
|
+
);
|
|
682
|
+
const organization = userMe.organizations[0];
|
|
683
|
+
if (organization.agentType == AgentType.ONPREMISE && signingEnabled(userMe.flagBootstrap)) {
|
|
684
|
+
const agentUrls = getAgentUrls(userMe.agents, organization.agentType);
|
|
685
|
+
const socket = await connectToISocketRPCServer({
|
|
686
|
+
agentUrls,
|
|
687
|
+
superblocksBaseUrl,
|
|
688
|
+
token,
|
|
689
|
+
});
|
|
690
|
+
const resp = await socket.call.v1.public.application.pushCommit({
|
|
691
|
+
applicationId,
|
|
692
|
+
apis: applicationConfig.apis,
|
|
693
|
+
application: applicationConfig.application,
|
|
694
|
+
branchName: branch,
|
|
695
|
+
commitId: applicationConfig.commitId,
|
|
696
|
+
commitMessage: applicationConfig.commitMessage,
|
|
697
|
+
page: applicationConfig.page,
|
|
698
|
+
});
|
|
699
|
+
socket.close();
|
|
700
|
+
return resp.data;
|
|
701
|
+
} else {
|
|
702
|
+
const config: AxiosRequestConfig = {
|
|
703
|
+
method: "post",
|
|
704
|
+
url: serverURL.toString(),
|
|
705
|
+
headers: {
|
|
706
|
+
Authorization: "Bearer " + token,
|
|
707
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
708
|
+
...injectedHeaders,
|
|
709
|
+
},
|
|
710
|
+
data: applicationConfig,
|
|
711
|
+
};
|
|
712
|
+
serverResponse = await axios<ResponseWithMeta<RemoteCommitDto>>(config);
|
|
713
|
+
}
|
|
564
714
|
} catch (e) {
|
|
565
715
|
if (axios.isAxiosError(e)) {
|
|
566
716
|
const respCode =
|
|
@@ -594,6 +744,7 @@ export async function pushApplication({
|
|
|
594
744
|
}
|
|
595
745
|
|
|
596
746
|
export async function pushApi({
|
|
747
|
+
cliVersion,
|
|
597
748
|
apiId,
|
|
598
749
|
token,
|
|
599
750
|
superblocksBaseUrl,
|
|
@@ -601,6 +752,7 @@ export async function pushApi({
|
|
|
601
752
|
branch,
|
|
602
753
|
injectedHeaders = {},
|
|
603
754
|
}: {
|
|
755
|
+
cliVersion: string;
|
|
604
756
|
apiId: string;
|
|
605
757
|
token: string;
|
|
606
758
|
superblocksBaseUrl: string;
|
|
@@ -608,9 +760,8 @@ export async function pushApi({
|
|
|
608
760
|
branch: string;
|
|
609
761
|
injectedHeaders: Record<string, string>;
|
|
610
762
|
}): Promise<{ commitId: string } | undefined> {
|
|
611
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
612
763
|
const serverURL = new URL(
|
|
613
|
-
`${
|
|
764
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(
|
|
614
765
|
branch
|
|
615
766
|
)}/push`,
|
|
616
767
|
superblocksBaseUrl
|
|
@@ -618,19 +769,43 @@ export async function pushApi({
|
|
|
618
769
|
let serverResponse;
|
|
619
770
|
|
|
620
771
|
try {
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
Authorization: "Bearer " + token,
|
|
626
|
-
[CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
|
|
627
|
-
...injectedHeaders,
|
|
628
|
-
},
|
|
629
|
-
data: apiConfig,
|
|
630
|
-
};
|
|
631
|
-
serverResponse = await axios<ResponseWithMeta<{ commitId: string }>>(
|
|
632
|
-
config
|
|
772
|
+
const userMe = await fetchCurrentUser(
|
|
773
|
+
cliVersion,
|
|
774
|
+
token,
|
|
775
|
+
superblocksBaseUrl
|
|
633
776
|
);
|
|
777
|
+
const organization = userMe.organizations[0];
|
|
778
|
+
if (organization.agentType == AgentType.ONPREMISE && signingEnabled(userMe.flagBootstrap)) {
|
|
779
|
+
const agentUrls = getAgentUrls(userMe.agents, organization.agentType);
|
|
780
|
+
const socket = await connectToISocketRPCServer({
|
|
781
|
+
agentUrls,
|
|
782
|
+
superblocksBaseUrl,
|
|
783
|
+
token,
|
|
784
|
+
});
|
|
785
|
+
const resp = await socket.call.v1.public.api.pushCommit({
|
|
786
|
+
apiId,
|
|
787
|
+
apiPb: apiConfig.apiPb,
|
|
788
|
+
branchName: branch,
|
|
789
|
+
commitId: apiConfig.commitId,
|
|
790
|
+
commitMessage: apiConfig.commitMessage,
|
|
791
|
+
});
|
|
792
|
+
socket.close();
|
|
793
|
+
return resp.data;
|
|
794
|
+
} else {
|
|
795
|
+
const config: AxiosRequestConfig = {
|
|
796
|
+
method: "post",
|
|
797
|
+
url: serverURL.toString(),
|
|
798
|
+
headers: {
|
|
799
|
+
Authorization: "Bearer " + token,
|
|
800
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
801
|
+
...injectedHeaders,
|
|
802
|
+
},
|
|
803
|
+
data: apiConfig,
|
|
804
|
+
};
|
|
805
|
+
serverResponse = await axios<ResponseWithMeta<{ commitId: string }>>(
|
|
806
|
+
config
|
|
807
|
+
);
|
|
808
|
+
}
|
|
634
809
|
} catch (e) {
|
|
635
810
|
if (axios.isAxiosError(e)) {
|
|
636
811
|
if (e.response?.data?.responseMeta?.status === 405) {
|