@superblocksteam/sdk 1.4.2 → 1.5.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/.eslintrc.json +3 -0
- package/dist/client.d.ts +5 -4
- package/dist/client.js +191 -82
- package/dist/flag.d.ts +2 -0
- package/dist/flag.js +7 -0
- package/dist/sdk.d.ts +5 -5
- package/dist/socket/handlers.d.ts +105 -0
- package/dist/socket/handlers.js +97 -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 +70 -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 +66 -0
- package/package.json +5 -3
- package/src/client.ts +179 -51
- package/src/flag.ts +5 -0
- package/src/sdk.ts +8 -8
- package/src/socket/handlers.ts +248 -0
- package/src/socket/index.ts +164 -0
- package/src/socket/signing.ts +104 -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 +81 -0
- package/tsconfig.json +3 -1
package/.eslintrc.json
CHANGED
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"@typescript-eslint/no-unsafe-return": "off",
|
|
28
28
|
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
29
29
|
"@typescript-eslint/restrict-template-expressions": "off",
|
|
30
|
+
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
31
|
+
"@typescript-eslint/no-unsafe-argument": "off",
|
|
32
|
+
"@typescript-eslint/no-unsafe-call": "off",
|
|
30
33
|
"import/order": [
|
|
31
34
|
"error",
|
|
32
35
|
{
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
|
|
2
|
+
import { RemoteCommitDto, UserMeDto } from "./types";
|
|
2
3
|
export type ViewMode = "export-deployed" | "export-latest" | "export-live";
|
|
3
4
|
export interface UploadFile {
|
|
4
5
|
name: string;
|
|
@@ -63,7 +64,7 @@ export declare function fetchApis(cliVersion: string, token: string, superblocks
|
|
|
63
64
|
export declare function validateGitSetup(cliVersion: string, resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
|
|
64
65
|
branchName: string | null;
|
|
65
66
|
}>;
|
|
66
|
-
export declare function registerComponents(cliVersion: string, applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, branch: string | null, injectedHeaders
|
|
67
|
+
export declare function registerComponents(cliVersion: string, applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, branch: string | null, injectedHeaders: Record<string, string>): Promise<any>;
|
|
67
68
|
export declare function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }: {
|
|
68
69
|
cliVersion: string;
|
|
69
70
|
applicationId: string;
|
|
@@ -72,8 +73,8 @@ export declare function uploadComponents({ cliVersion, applicationId, componentC
|
|
|
72
73
|
token: string;
|
|
73
74
|
superblocksBaseUrl: string;
|
|
74
75
|
branch: string | null;
|
|
75
|
-
}): Promise<
|
|
76
|
-
export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<UserMeDto>;
|
|
77
78
|
export declare function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
|
|
78
79
|
cliVersion: string;
|
|
79
80
|
applicationId: string;
|
|
@@ -82,7 +83,7 @@ export declare function pushApplication({ cliVersion, applicationId, token, supe
|
|
|
82
83
|
branch: string;
|
|
83
84
|
injectedHeaders: Record<string, string>;
|
|
84
85
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
85
|
-
}): Promise<
|
|
86
|
+
}): Promise<RemoteCommitDto | undefined>;
|
|
86
87
|
export declare function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
|
|
87
88
|
cliVersion: string;
|
|
88
89
|
apiId: string;
|
package/dist/client.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pushApi = exports.pushApplication = exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.validateGitSetup = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplicationBranches = exports.fetchApplication = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
5
6
|
const util_1 = require("@superblocksteam/util");
|
|
6
|
-
const axios_1 = require("axios");
|
|
7
|
-
const
|
|
7
|
+
const axios_1 = tslib_1.__importStar(require("axios"));
|
|
8
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
8
9
|
const lodash_1 = require("lodash");
|
|
9
10
|
const errors_1 = require("./errors");
|
|
10
|
-
const
|
|
11
|
+
const flag_1 = require("./flag");
|
|
12
|
+
const socket_1 = require("./socket");
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
const BASE_BUCKETEER_URL = "api";
|
|
11
16
|
const BASE_SERVER_PUBLIC_API_URL = "api/v1/public";
|
|
12
17
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
13
18
|
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
14
19
|
const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
|
|
15
20
|
async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
16
|
-
var _a, _b;
|
|
17
21
|
const serverURL = branch
|
|
18
22
|
? new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
|
|
19
23
|
: new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
|
|
@@ -31,16 +35,15 @@ async function fetchApplication({ cliVersion, applicationId, branch, token, supe
|
|
|
31
35
|
serverResponse = await (0, axios_1.default)(config);
|
|
32
36
|
}
|
|
33
37
|
catch (e) {
|
|
34
|
-
if (axios_1.default.isAxiosError(e) &&
|
|
38
|
+
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
35
39
|
throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
|
|
36
40
|
}
|
|
37
41
|
throw new Error("Could not fetch application");
|
|
38
42
|
}
|
|
39
|
-
return
|
|
43
|
+
return serverResponse?.data?.data;
|
|
40
44
|
}
|
|
41
45
|
exports.fetchApplication = fetchApplication;
|
|
42
46
|
async function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
|
|
43
|
-
var _a, _b;
|
|
44
47
|
const serverURL = new URL(`public/applications/${applicationId}/branches`, superblocksBaseUrl);
|
|
45
48
|
let serverResponse;
|
|
46
49
|
try {
|
|
@@ -56,16 +59,15 @@ async function fetchApplicationBranches({ cliVersion, applicationId, token, supe
|
|
|
56
59
|
serverResponse = await (0, axios_1.default)(config);
|
|
57
60
|
}
|
|
58
61
|
catch (e) {
|
|
59
|
-
if (axios_1.default.isAxiosError(e) &&
|
|
62
|
+
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
60
63
|
throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
|
|
61
64
|
}
|
|
62
65
|
throw new Error(`Could not fetch application branches: ${e.message}`);
|
|
63
66
|
}
|
|
64
|
-
return
|
|
67
|
+
return serverResponse?.data?.data;
|
|
65
68
|
}
|
|
66
69
|
exports.fetchApplicationBranches = fetchApplicationBranches;
|
|
67
70
|
async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
68
|
-
var _a, _b, _c;
|
|
69
71
|
const applicationWrapper = await fetchApplication({
|
|
70
72
|
cliVersion,
|
|
71
73
|
applicationId,
|
|
@@ -79,7 +81,7 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
79
81
|
return;
|
|
80
82
|
}
|
|
81
83
|
// if there are no custom components, just return here without trying to initialize them using bucketeer
|
|
82
|
-
if ((0, lodash_1.isEmpty)(
|
|
84
|
+
if ((0, lodash_1.isEmpty)(applicationWrapper.application?.settings?.registeredComponents)) {
|
|
83
85
|
return {
|
|
84
86
|
...applicationWrapper,
|
|
85
87
|
componentFiles: null,
|
|
@@ -91,7 +93,7 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
91
93
|
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
92
94
|
// fetch files from bucketeer
|
|
93
95
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
94
|
-
const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
|
|
96
|
+
const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
|
|
95
97
|
try {
|
|
96
98
|
const config = {
|
|
97
99
|
method: "get",
|
|
@@ -106,7 +108,7 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
106
108
|
return response.data;
|
|
107
109
|
}
|
|
108
110
|
catch (e) {
|
|
109
|
-
if (axios_1.default.isAxiosError(e) &&
|
|
111
|
+
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
110
112
|
throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
|
|
111
113
|
}
|
|
112
114
|
throw new Error("Could not fetch application");
|
|
@@ -114,7 +116,6 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
114
116
|
}
|
|
115
117
|
exports.fetchApplicationWithComponents = fetchApplicationWithComponents;
|
|
116
118
|
async function fetchApplications(cliVersion, token, superblocksBaseUrl, injectedHeaders = {}) {
|
|
117
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
118
119
|
try {
|
|
119
120
|
const config = {
|
|
120
121
|
method: "get",
|
|
@@ -132,17 +133,20 @@ async function fetchApplications(cliVersion, token, superblocksBaseUrl, injected
|
|
|
132
133
|
let message;
|
|
133
134
|
if (e instanceof axios_1.AxiosError) {
|
|
134
135
|
message =
|
|
135
|
-
|
|
136
|
+
e.response?.data?.responseMeta?.message ??
|
|
137
|
+
JSON.stringify(e.response?.data) ??
|
|
138
|
+
e.response?.statusText ??
|
|
139
|
+
e?.message ??
|
|
140
|
+
`${e}`;
|
|
136
141
|
}
|
|
137
142
|
else {
|
|
138
|
-
message = `${
|
|
143
|
+
message = `${e?.message ? e?.message : e}`;
|
|
139
144
|
}
|
|
140
145
|
throw new Error(`Could not fetch applications: ${message}`);
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
exports.fetchApplications = fetchApplications;
|
|
144
149
|
async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch) {
|
|
145
|
-
var _a;
|
|
146
150
|
try {
|
|
147
151
|
const serverURL = branch
|
|
148
152
|
? new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
|
|
@@ -159,7 +163,7 @@ async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode,
|
|
|
159
163
|
return response.data.data;
|
|
160
164
|
}
|
|
161
165
|
catch (e) {
|
|
162
|
-
if (axios_1.default.isAxiosError(e) &&
|
|
166
|
+
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
163
167
|
throw new util_1.NotFoundError(`Api ${apiId} was not found`);
|
|
164
168
|
}
|
|
165
169
|
throw new Error("Could not fetch api");
|
|
@@ -185,7 +189,6 @@ async function fetchApis(cliVersion, token, superblocksBaseUrl) {
|
|
|
185
189
|
}
|
|
186
190
|
exports.fetchApis = fetchApis;
|
|
187
191
|
async function validateGitSetup(cliVersion, resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
|
|
188
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
189
192
|
let resourceName;
|
|
190
193
|
try {
|
|
191
194
|
const requestBody = {
|
|
@@ -224,42 +227,70 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
|
|
|
224
227
|
throw new Error(validationResult.errors.join("\n"));
|
|
225
228
|
}
|
|
226
229
|
return {
|
|
227
|
-
branchName: (
|
|
230
|
+
branchName: (validationResult.branchName ?? null),
|
|
228
231
|
};
|
|
229
232
|
}
|
|
230
233
|
catch (e) {
|
|
231
234
|
let message;
|
|
232
235
|
if (e instanceof axios_1.AxiosError) {
|
|
233
236
|
message =
|
|
234
|
-
|
|
237
|
+
e.response?.data?.responseMeta?.message ??
|
|
238
|
+
JSON.stringify(e.response?.data) ??
|
|
239
|
+
e.response?.statusText ??
|
|
240
|
+
e?.message ??
|
|
241
|
+
`${e}`;
|
|
235
242
|
}
|
|
236
243
|
else {
|
|
237
|
-
message = `${
|
|
244
|
+
message = `${e?.message ? e?.message : e}`;
|
|
238
245
|
}
|
|
239
|
-
throw new Error(`Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${resourceName
|
|
246
|
+
throw new Error(`Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${resourceName ?? resourceId}${message ? "\n" + message : ""}`);
|
|
240
247
|
}
|
|
241
248
|
}
|
|
242
249
|
exports.validateGitSetup = validateGitSetup;
|
|
243
250
|
async function registerComponents(cliVersion, applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
|
|
244
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
245
251
|
try {
|
|
246
252
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
253
|
+
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
254
|
+
const organization = userMe.organizations[0];
|
|
255
|
+
if (organization.agentType == types_1.AgentType.ONPREMISE &&
|
|
256
|
+
(0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
|
|
257
|
+
const profile = process.env.SUPERBLOCKS_PROFILE;
|
|
258
|
+
const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType, profile);
|
|
259
|
+
const socket = await (0, socket_1.connectToISocketRPCServer)({
|
|
260
|
+
agentUrl,
|
|
261
|
+
superblocksBaseUrl,
|
|
262
|
+
token,
|
|
263
|
+
});
|
|
264
|
+
const resp = await socket.call.v1.public.application.component.register({
|
|
265
|
+
applicationId,
|
|
266
|
+
branchName: branch || "",
|
|
267
|
+
cliVersion: cliVersion,
|
|
268
|
+
componentEvent: injectedHeaders[util_1.COMPONENT_EVENT_HEADER],
|
|
269
|
+
components: componentConfigs,
|
|
270
|
+
});
|
|
271
|
+
socket.close();
|
|
272
|
+
return resp.data;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
const config = {
|
|
276
|
+
method: "put",
|
|
277
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
|
|
278
|
+
headers: {
|
|
279
|
+
Authorization: "Bearer " + token,
|
|
280
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
281
|
+
...injectedHeaders,
|
|
282
|
+
},
|
|
283
|
+
data: { components: componentConfigs },
|
|
284
|
+
};
|
|
285
|
+
const response = await (0, axios_1.default)(config);
|
|
286
|
+
return response.data;
|
|
287
|
+
}
|
|
259
288
|
}
|
|
260
289
|
catch (e) {
|
|
261
290
|
if (e instanceof axios_1.AxiosError) {
|
|
262
|
-
const message =
|
|
291
|
+
const message = e.response?.data?.responseMeta?.message ??
|
|
292
|
+
JSON.stringify(e.response?.data) ??
|
|
293
|
+
e.response?.statusText;
|
|
263
294
|
throw new Error(`Could not register application components ${message ? "\n" + message : ""}`);
|
|
264
295
|
}
|
|
265
296
|
throw new Error(`Could not register application components ${e.message ? "\n" + e.message : ""}`);
|
|
@@ -267,7 +298,6 @@ async function registerComponents(cliVersion, applicationId, componentConfigs, t
|
|
|
267
298
|
}
|
|
268
299
|
exports.registerComponents = registerComponents;
|
|
269
300
|
async function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
|
|
270
|
-
var _a, _b, _c, _d, _e, _f;
|
|
271
301
|
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
272
302
|
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
273
303
|
// parse files to source and bundled files based on path
|
|
@@ -292,9 +322,9 @@ async function uploadComponents({ cliVersion, applicationId, componentConfigs, f
|
|
|
292
322
|
srcFiles,
|
|
293
323
|
buildFiles,
|
|
294
324
|
});
|
|
295
|
-
const postURL = new URL(`${BASE_BUCKETEER_URL}/components/upload`, bucketeerBaseUrl).toString();
|
|
325
|
+
const postURL = new URL(`${BASE_BUCKETEER_URL}/v2/components/upload`, bucketeerBaseUrl).toString();
|
|
296
326
|
let totalFileSizeMB = 0;
|
|
297
|
-
const formData = new
|
|
327
|
+
const formData = new form_data_1.default();
|
|
298
328
|
formData.append("format", formatJSON);
|
|
299
329
|
uploadFiles.forEach((uploadFile) => {
|
|
300
330
|
const uploadFileStats = fs.statSync(uploadFile.filename);
|
|
@@ -320,19 +350,46 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
320
350
|
...formHeaders,
|
|
321
351
|
},
|
|
322
352
|
};
|
|
323
|
-
const
|
|
324
|
-
|
|
353
|
+
const uploadResponse = await axios_1.default.post(postURL, formData, config);
|
|
354
|
+
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
355
|
+
const organization = userMe.organizations[0];
|
|
356
|
+
let agentUrl;
|
|
357
|
+
const signingRequired = organization.agentType == types_1.AgentType.ONPREMISE &&
|
|
358
|
+
(0, flag_1.signingEnabled)(userMe.flagBootstrap);
|
|
359
|
+
if (signingRequired) {
|
|
360
|
+
agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType);
|
|
361
|
+
}
|
|
362
|
+
const socket = await (0, socket_1.connectToISocketRPCServer)({
|
|
363
|
+
agentUrl,
|
|
364
|
+
superblocksBaseUrl,
|
|
365
|
+
token,
|
|
366
|
+
});
|
|
367
|
+
try {
|
|
368
|
+
await socket.call.v1.public.application.component.update({
|
|
369
|
+
applicationId,
|
|
370
|
+
branchName: branch ?? undefined,
|
|
371
|
+
srcFiles: srcFiles.map((file) => file.filename),
|
|
372
|
+
buildFiles: buildFiles.map((file) => file.filename),
|
|
373
|
+
registeredComponents: componentConfigs,
|
|
374
|
+
cliVersion,
|
|
375
|
+
componentBaseUrl: uploadResponse.data.componentBaseUrl,
|
|
376
|
+
signingRequired,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
finally {
|
|
380
|
+
socket.close();
|
|
381
|
+
}
|
|
325
382
|
}
|
|
326
383
|
catch (e) {
|
|
327
|
-
if (e instanceof axios_1.AxiosError &&
|
|
384
|
+
if (e instanceof axios_1.AxiosError && e.response?.status === 413) {
|
|
328
385
|
throw new Error(`Could not upload application components, file size limit exceeded`);
|
|
329
386
|
}
|
|
330
387
|
else {
|
|
331
388
|
let message;
|
|
332
389
|
if (e instanceof axios_1.AxiosError) {
|
|
333
|
-
message = (
|
|
334
|
-
|
|
335
|
-
|
|
390
|
+
message = (e.response?.data?.responseMeta?.message ||
|
|
391
|
+
e.response?.data ||
|
|
392
|
+
e.response?.statusText);
|
|
336
393
|
}
|
|
337
394
|
else {
|
|
338
395
|
message = e.message;
|
|
@@ -346,7 +403,6 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
346
403
|
}
|
|
347
404
|
exports.uploadComponents = uploadComponents;
|
|
348
405
|
async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
|
|
349
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
350
406
|
try {
|
|
351
407
|
const config = {
|
|
352
408
|
method: "get",
|
|
@@ -358,85 +414,138 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
|
|
|
358
414
|
},
|
|
359
415
|
};
|
|
360
416
|
const response = await (0, axios_1.default)(config);
|
|
361
|
-
return response.data.data
|
|
417
|
+
return response.data.data;
|
|
362
418
|
}
|
|
363
419
|
catch (e) {
|
|
364
420
|
let message;
|
|
365
421
|
if (e instanceof axios_1.AxiosError) {
|
|
366
422
|
message =
|
|
367
|
-
|
|
423
|
+
e.response?.data?.responseMeta?.message ??
|
|
424
|
+
JSON.stringify(e.response?.data) ??
|
|
425
|
+
e.response?.statusText ??
|
|
426
|
+
e?.message ??
|
|
427
|
+
`${e}`;
|
|
368
428
|
}
|
|
369
429
|
else {
|
|
370
|
-
message = `${
|
|
430
|
+
message = `${e?.message ? e?.message : e}`;
|
|
371
431
|
}
|
|
372
432
|
throw new Error(`Could not fetch current user: ${message}`);
|
|
373
433
|
}
|
|
374
434
|
}
|
|
375
435
|
exports.fetchCurrentUser = fetchCurrentUser;
|
|
376
436
|
async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
|
|
377
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
378
437
|
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
379
438
|
let serverResponse;
|
|
380
439
|
try {
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
440
|
+
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
441
|
+
const organization = userMe.organizations[0];
|
|
442
|
+
if (organization.agentType == types_1.AgentType.ONPREMISE &&
|
|
443
|
+
(0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
|
|
444
|
+
const profile = process.env.SUPERBLOCKS_PROFILE;
|
|
445
|
+
const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType, profile);
|
|
446
|
+
const socket = await (0, socket_1.connectToISocketRPCServer)({
|
|
447
|
+
agentUrl,
|
|
448
|
+
superblocksBaseUrl,
|
|
449
|
+
token,
|
|
450
|
+
});
|
|
451
|
+
const resp = await socket.call.v1.public.application.pushCommit({
|
|
452
|
+
applicationId,
|
|
453
|
+
apis: applicationConfig.apis,
|
|
454
|
+
application: applicationConfig.application,
|
|
455
|
+
branchName: branch,
|
|
456
|
+
commitId: applicationConfig.commitId,
|
|
457
|
+
commitMessage: applicationConfig.commitMessage,
|
|
458
|
+
page: applicationConfig.page,
|
|
459
|
+
});
|
|
460
|
+
socket.close();
|
|
461
|
+
return resp.data;
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
const config = {
|
|
465
|
+
method: "post",
|
|
466
|
+
url: serverURL.toString(),
|
|
467
|
+
headers: {
|
|
468
|
+
Authorization: "Bearer " + token,
|
|
469
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
470
|
+
...injectedHeaders,
|
|
471
|
+
},
|
|
472
|
+
data: applicationConfig,
|
|
473
|
+
};
|
|
474
|
+
serverResponse = await (0, axios_1.default)(config);
|
|
475
|
+
}
|
|
392
476
|
}
|
|
393
477
|
catch (e) {
|
|
394
478
|
if (axios_1.default.isAxiosError(e)) {
|
|
395
|
-
const respCode =
|
|
479
|
+
const respCode = e.response?.data?.responseMeta?.status ?? e.response?.status;
|
|
396
480
|
if (respCode === 405) {
|
|
397
481
|
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
398
482
|
}
|
|
399
483
|
else if (respCode === 409) {
|
|
400
484
|
throw new errors_1.CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
|
|
401
485
|
}
|
|
402
|
-
const message =
|
|
486
|
+
const message = e.response?.data?.responseMeta?.message ??
|
|
487
|
+
JSON.stringify(e.response?.data) ??
|
|
488
|
+
e.response?.statusText;
|
|
403
489
|
throw new Error(`Could not push application ${message ? "\n" + message : ""}`);
|
|
404
490
|
}
|
|
405
491
|
throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
|
|
406
492
|
}
|
|
407
|
-
return
|
|
493
|
+
return serverResponse?.data?.data;
|
|
408
494
|
}
|
|
409
495
|
exports.pushApplication = pushApplication;
|
|
410
496
|
async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
|
|
411
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
412
497
|
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
413
498
|
let serverResponse;
|
|
414
499
|
try {
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
500
|
+
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
501
|
+
const organization = userMe.organizations[0];
|
|
502
|
+
if (organization.agentType == types_1.AgentType.ONPREMISE &&
|
|
503
|
+
(0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
|
|
504
|
+
const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType);
|
|
505
|
+
const socket = await (0, socket_1.connectToISocketRPCServer)({
|
|
506
|
+
agentUrl,
|
|
507
|
+
superblocksBaseUrl,
|
|
508
|
+
token,
|
|
509
|
+
});
|
|
510
|
+
const resp = await socket.call.v1.public.api.pushCommit({
|
|
511
|
+
apiId,
|
|
512
|
+
apiPb: apiConfig.apiPb,
|
|
513
|
+
branchName: branch,
|
|
514
|
+
commitId: apiConfig.commitId,
|
|
515
|
+
commitMessage: apiConfig.commitMessage,
|
|
516
|
+
});
|
|
517
|
+
socket.close();
|
|
518
|
+
return resp.data;
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
const config = {
|
|
522
|
+
method: "post",
|
|
523
|
+
url: serverURL.toString(),
|
|
524
|
+
headers: {
|
|
525
|
+
Authorization: "Bearer " + token,
|
|
526
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
527
|
+
...injectedHeaders,
|
|
528
|
+
},
|
|
529
|
+
data: apiConfig,
|
|
530
|
+
};
|
|
531
|
+
serverResponse = await (0, axios_1.default)(config);
|
|
532
|
+
}
|
|
426
533
|
}
|
|
427
534
|
catch (e) {
|
|
428
535
|
if (axios_1.default.isAxiosError(e)) {
|
|
429
|
-
if (
|
|
536
|
+
if (e.response?.data?.responseMeta?.status === 405) {
|
|
430
537
|
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
431
538
|
}
|
|
432
|
-
else if (
|
|
539
|
+
else if (e.response?.data?.responseMeta?.status === 409) {
|
|
433
540
|
throw new errors_1.CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
|
|
434
541
|
}
|
|
435
|
-
const message =
|
|
542
|
+
const message = e.response?.data?.responseMeta?.message ??
|
|
543
|
+
JSON.stringify(e.response?.data) ??
|
|
544
|
+
e.response?.statusText;
|
|
436
545
|
throw new Error(`Could not push api ${message ? "\n" + message : ""}`);
|
|
437
546
|
}
|
|
438
547
|
throw new Error(`Could not push api ${e.message ? "\n" + e.message : ""}`);
|
|
439
548
|
}
|
|
440
|
-
return
|
|
549
|
+
return serverResponse?.data?.data;
|
|
441
550
|
}
|
|
442
551
|
exports.pushApi = pushApi;
|
package/dist/flag.d.ts
ADDED
package/dist/flag.js
ADDED
package/dist/sdk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
|
|
2
|
-
import {
|
|
2
|
+
import { PushApiWithCommitConfig, PushApplicationWithCommitConfig, ViewMode } from "./client";
|
|
3
3
|
export * from "./errors";
|
|
4
4
|
export declare class SuperblocksSdk {
|
|
5
5
|
token: string;
|
|
@@ -27,15 +27,15 @@ export declare class SuperblocksSdk {
|
|
|
27
27
|
validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, injectedHeaders?: Record<string, string>): Promise<{
|
|
28
28
|
branchName: string | null;
|
|
29
29
|
}>;
|
|
30
|
-
registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders
|
|
31
|
-
uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], branch: string | null): Promise<
|
|
32
|
-
fetchCurrentUser(): Promise<
|
|
30
|
+
registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders: Record<string, string>): Promise<any>;
|
|
31
|
+
uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], branch: string | null): Promise<void>;
|
|
32
|
+
fetchCurrentUser(): Promise<import("./types").UserMeDto>;
|
|
33
33
|
pushApplication({ applicationId, applicationConfig, branch, headers, }: {
|
|
34
34
|
applicationId: string;
|
|
35
35
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
36
36
|
branch: string;
|
|
37
37
|
headers?: Record<string, string>;
|
|
38
|
-
}): Promise<import("./
|
|
38
|
+
}): Promise<import("./types").RemoteCommitDto | undefined>;
|
|
39
39
|
pushApi({ apiId, apiConfig, branch, headers, }: {
|
|
40
40
|
apiId: string;
|
|
41
41
|
apiConfig: PushApiWithCommitConfig;
|