@superblocksteam/sdk 1.4.1 → 1.4.2
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/client.d.ts +18 -12
- package/dist/client.js +62 -39
- package/dist/sdk.d.ts +3 -2
- package/dist/sdk.js +16 -8
- package/package.json +2 -2
- package/src/client.ts +103 -35
- package/src/sdk.ts +40 -6
package/dist/client.d.ts
CHANGED
|
@@ -30,7 +30,8 @@ export type Branch = {
|
|
|
30
30
|
name: string;
|
|
31
31
|
isDefault: boolean;
|
|
32
32
|
};
|
|
33
|
-
export declare function fetchApplication({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
|
|
33
|
+
export declare function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
|
|
34
|
+
cliVersion: string;
|
|
34
35
|
applicationId: string;
|
|
35
36
|
branch?: string;
|
|
36
37
|
token: string;
|
|
@@ -38,13 +39,15 @@ export declare function fetchApplication({ applicationId, branch, token, superbl
|
|
|
38
39
|
viewMode: ViewMode;
|
|
39
40
|
injectedHeaders: Record<string, string>;
|
|
40
41
|
}): Promise<ApplicationWrapper | undefined>;
|
|
41
|
-
export declare function fetchApplicationBranches({ applicationId, token, superblocksBaseUrl, injectedHeaders, }: {
|
|
42
|
+
export declare function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders, }: {
|
|
43
|
+
cliVersion: string;
|
|
42
44
|
applicationId: string;
|
|
43
45
|
token: string;
|
|
44
46
|
superblocksBaseUrl: string;
|
|
45
47
|
injectedHeaders: Record<string, string>;
|
|
46
48
|
}): Promise<Branches | undefined>;
|
|
47
|
-
export declare function fetchApplicationWithComponents({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
|
|
49
|
+
export declare function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
|
|
50
|
+
cliVersion: string;
|
|
48
51
|
applicationId: string;
|
|
49
52
|
branch: string;
|
|
50
53
|
token: string;
|
|
@@ -54,14 +57,15 @@ export declare function fetchApplicationWithComponents({ applicationId, branch,
|
|
|
54
57
|
}): Promise<(ApplicationWrapper & {
|
|
55
58
|
componentFiles: any;
|
|
56
59
|
}) | undefined>;
|
|
57
|
-
export declare function fetchApplications(token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
58
|
-
export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
|
|
59
|
-
export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
60
|
-
export declare function validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
|
|
60
|
+
export declare function fetchApplications(cliVersion: string, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
61
|
+
export declare function fetchApi(cliVersion: string, apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode, branch?: string): Promise<any>;
|
|
62
|
+
export declare function fetchApis(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<any>;
|
|
63
|
+
export declare function validateGitSetup(cliVersion: string, resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
|
|
61
64
|
branchName: string | null;
|
|
62
65
|
}>;
|
|
63
|
-
export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, branch: string | null, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
64
|
-
export declare function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }: {
|
|
66
|
+
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
|
+
export declare function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }: {
|
|
68
|
+
cliVersion: string;
|
|
65
69
|
applicationId: string;
|
|
66
70
|
componentConfigs: Record<string, any>;
|
|
67
71
|
files: string[];
|
|
@@ -69,8 +73,9 @@ export declare function uploadComponents({ applicationId, componentConfigs, file
|
|
|
69
73
|
superblocksBaseUrl: string;
|
|
70
74
|
branch: string | null;
|
|
71
75
|
}): Promise<any>;
|
|
72
|
-
export declare function fetchCurrentUser(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
73
|
-
export declare function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
|
|
76
|
+
export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<any>;
|
|
77
|
+
export declare function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
|
|
78
|
+
cliVersion: string;
|
|
74
79
|
applicationId: string;
|
|
75
80
|
token: string;
|
|
76
81
|
superblocksBaseUrl: string;
|
|
@@ -78,7 +83,8 @@ export declare function pushApplication({ applicationId, token, superblocksBaseU
|
|
|
78
83
|
injectedHeaders: Record<string, string>;
|
|
79
84
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
80
85
|
}): Promise<ApplicationWrapper | undefined>;
|
|
81
|
-
export declare function pushApi({ apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
|
|
86
|
+
export declare function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
|
|
87
|
+
cliVersion: string;
|
|
82
88
|
apiId: string;
|
|
83
89
|
token: string;
|
|
84
90
|
superblocksBaseUrl: string;
|
package/dist/client.js
CHANGED
|
@@ -7,16 +7,16 @@ const axios_1 = require("axios");
|
|
|
7
7
|
const FormData = require("form-data");
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
9
|
const errors_1 = require("./errors");
|
|
10
|
-
const BASE_SERVER_URL = "api/v1";
|
|
11
10
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
11
|
+
const BASE_SERVER_PUBLIC_API_URL = "api/v1/public";
|
|
12
12
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
13
13
|
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
14
14
|
const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
|
|
15
|
-
async function fetchApplication({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
15
|
+
async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
16
16
|
var _a, _b;
|
|
17
17
|
const serverURL = branch
|
|
18
|
-
? new URL(
|
|
19
|
-
: new URL(
|
|
18
|
+
? new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
|
|
19
|
+
: new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
|
|
20
20
|
let serverResponse;
|
|
21
21
|
try {
|
|
22
22
|
const config = {
|
|
@@ -24,6 +24,7 @@ async function fetchApplication({ applicationId, branch, token, superblocksBaseU
|
|
|
24
24
|
url: serverURL.toString(),
|
|
25
25
|
headers: {
|
|
26
26
|
Authorization: "Bearer " + token,
|
|
27
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
27
28
|
...injectedHeaders,
|
|
28
29
|
},
|
|
29
30
|
};
|
|
@@ -38,9 +39,9 @@ async function fetchApplication({ applicationId, branch, token, superblocksBaseU
|
|
|
38
39
|
return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
|
|
39
40
|
}
|
|
40
41
|
exports.fetchApplication = fetchApplication;
|
|
41
|
-
async function fetchApplicationBranches({ applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
|
|
42
|
+
async function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
|
|
42
43
|
var _a, _b;
|
|
43
|
-
const serverURL = new URL(`
|
|
44
|
+
const serverURL = new URL(`public/applications/${applicationId}/branches`, superblocksBaseUrl);
|
|
44
45
|
let serverResponse;
|
|
45
46
|
try {
|
|
46
47
|
const config = {
|
|
@@ -48,6 +49,7 @@ async function fetchApplicationBranches({ applicationId, token, superblocksBaseU
|
|
|
48
49
|
url: serverURL.toString(),
|
|
49
50
|
headers: {
|
|
50
51
|
Authorization: "Bearer " + token,
|
|
52
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
51
53
|
...injectedHeaders,
|
|
52
54
|
},
|
|
53
55
|
};
|
|
@@ -62,9 +64,10 @@ async function fetchApplicationBranches({ applicationId, token, superblocksBaseU
|
|
|
62
64
|
return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
|
|
63
65
|
}
|
|
64
66
|
exports.fetchApplicationBranches = fetchApplicationBranches;
|
|
65
|
-
async function fetchApplicationWithComponents({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
67
|
+
async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
66
68
|
var _a, _b, _c;
|
|
67
69
|
const applicationWrapper = await fetchApplication({
|
|
70
|
+
cliVersion,
|
|
68
71
|
applicationId,
|
|
69
72
|
branch,
|
|
70
73
|
token,
|
|
@@ -110,13 +113,15 @@ async function fetchApplicationWithComponents({ applicationId, branch, token, su
|
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
115
|
exports.fetchApplicationWithComponents = fetchApplicationWithComponents;
|
|
113
|
-
async function fetchApplications(token, superblocksBaseUrl, injectedHeaders = {}) {
|
|
116
|
+
async function fetchApplications(cliVersion, token, superblocksBaseUrl, injectedHeaders = {}) {
|
|
117
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
114
118
|
try {
|
|
115
119
|
const config = {
|
|
116
120
|
method: "get",
|
|
117
|
-
url: new URL(
|
|
121
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications`, superblocksBaseUrl).toString(),
|
|
118
122
|
headers: {
|
|
119
123
|
Authorization: "Bearer " + token,
|
|
124
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
120
125
|
...injectedHeaders,
|
|
121
126
|
},
|
|
122
127
|
};
|
|
@@ -124,18 +129,30 @@ async function fetchApplications(token, superblocksBaseUrl, injectedHeaders = {}
|
|
|
124
129
|
return response.data.data.applications;
|
|
125
130
|
}
|
|
126
131
|
catch (e) {
|
|
127
|
-
|
|
132
|
+
let message;
|
|
133
|
+
if (e instanceof axios_1.AxiosError) {
|
|
134
|
+
message =
|
|
135
|
+
(_j = (_h = (_f = (_d = (_c = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.responseMeta) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : JSON.stringify((_e = e.response) === null || _e === void 0 ? void 0 : _e.data)) !== null && _f !== void 0 ? _f : (_g = e.response) === null || _g === void 0 ? void 0 : _g.statusText) !== null && _h !== void 0 ? _h : e === null || e === void 0 ? void 0 : e.message) !== null && _j !== void 0 ? _j : `${e}`;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
message = `${(e === null || e === void 0 ? void 0 : e.message) ? e === null || e === void 0 ? void 0 : e.message : e}`;
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Could not fetch applications: ${message}`);
|
|
128
141
|
}
|
|
129
142
|
}
|
|
130
143
|
exports.fetchApplications = fetchApplications;
|
|
131
|
-
async function fetchApi(apiId, token, superblocksBaseUrl, viewMode) {
|
|
144
|
+
async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch) {
|
|
132
145
|
var _a;
|
|
133
146
|
try {
|
|
147
|
+
const serverURL = branch
|
|
148
|
+
? new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
|
|
149
|
+
: new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}?viewMode=${viewMode}`, superblocksBaseUrl);
|
|
134
150
|
const config = {
|
|
135
151
|
method: "get",
|
|
136
|
-
url: new URL(
|
|
152
|
+
url: new URL(serverURL, superblocksBaseUrl).toString(),
|
|
137
153
|
headers: {
|
|
138
154
|
Authorization: "Bearer " + token,
|
|
155
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
139
156
|
},
|
|
140
157
|
};
|
|
141
158
|
const response = await (0, axios_1.default)(config);
|
|
@@ -149,28 +166,28 @@ async function fetchApi(apiId, token, superblocksBaseUrl, viewMode) {
|
|
|
149
166
|
}
|
|
150
167
|
}
|
|
151
168
|
exports.fetchApi = fetchApi;
|
|
152
|
-
async function fetchApis(token, superblocksBaseUrl) {
|
|
169
|
+
async function fetchApis(cliVersion, token, superblocksBaseUrl) {
|
|
153
170
|
try {
|
|
154
171
|
const config = {
|
|
155
172
|
method: "get",
|
|
156
|
-
url: new URL(
|
|
173
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis`, superblocksBaseUrl).toString(),
|
|
157
174
|
headers: {
|
|
158
175
|
Authorization: "Bearer " + token,
|
|
176
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
159
177
|
},
|
|
160
178
|
};
|
|
161
179
|
const response = await (0, axios_1.default)(config);
|
|
162
|
-
return response.data.data;
|
|
180
|
+
return response.data.data.apis;
|
|
163
181
|
}
|
|
164
182
|
catch (e) {
|
|
165
183
|
throw new Error("Could not fetch apis");
|
|
166
184
|
}
|
|
167
185
|
}
|
|
168
186
|
exports.fetchApis = fetchApis;
|
|
169
|
-
async function validateGitSetup(resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
|
|
187
|
+
async function validateGitSetup(cliVersion, resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
|
|
170
188
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
171
189
|
let resourceName;
|
|
172
190
|
try {
|
|
173
|
-
const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
174
191
|
const requestBody = {
|
|
175
192
|
event,
|
|
176
193
|
gitState: localGitRepoState,
|
|
@@ -178,11 +195,11 @@ async function validateGitSetup(resourceId, resourceType, event, localGitRepoSta
|
|
|
178
195
|
let path;
|
|
179
196
|
switch (resourceType) {
|
|
180
197
|
case "APPLICATION": {
|
|
181
|
-
path = `/
|
|
198
|
+
path = `/application/${resourceId}/validate-git-setup`;
|
|
182
199
|
break;
|
|
183
200
|
}
|
|
184
201
|
case "BACKEND": {
|
|
185
|
-
path = `/
|
|
202
|
+
path = `/api/${resourceId}/validate-git-setup`;
|
|
186
203
|
break;
|
|
187
204
|
}
|
|
188
205
|
default:
|
|
@@ -190,10 +207,10 @@ async function validateGitSetup(resourceId, resourceType, event, localGitRepoSta
|
|
|
190
207
|
}
|
|
191
208
|
const config = {
|
|
192
209
|
method: "post",
|
|
193
|
-
url: new URL(`${
|
|
210
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/${path}`, superblocksBaseUrl).toString(),
|
|
194
211
|
headers: {
|
|
195
212
|
Authorization: "Bearer " + token,
|
|
196
|
-
[CLI_VERSION_HEADER]:
|
|
213
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
197
214
|
...injectedHeaders,
|
|
198
215
|
},
|
|
199
216
|
data: requestBody,
|
|
@@ -223,17 +240,16 @@ async function validateGitSetup(resourceId, resourceType, event, localGitRepoSta
|
|
|
223
240
|
}
|
|
224
241
|
}
|
|
225
242
|
exports.validateGitSetup = validateGitSetup;
|
|
226
|
-
async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
|
|
243
|
+
async function registerComponents(cliVersion, applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
|
|
227
244
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
228
245
|
try {
|
|
229
|
-
const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
230
246
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
231
247
|
const config = {
|
|
232
248
|
method: "put",
|
|
233
|
-
url: new URL(`${
|
|
249
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
|
|
234
250
|
headers: {
|
|
235
251
|
Authorization: "Bearer " + token,
|
|
236
|
-
[CLI_VERSION_HEADER]:
|
|
252
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
237
253
|
...injectedHeaders,
|
|
238
254
|
},
|
|
239
255
|
data: { components: componentConfigs },
|
|
@@ -250,7 +266,7 @@ async function registerComponents(applicationId, componentConfigs, token, superb
|
|
|
250
266
|
}
|
|
251
267
|
}
|
|
252
268
|
exports.registerComponents = registerComponents;
|
|
253
|
-
async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
|
|
269
|
+
async function uploadComponents({ cliVersion, applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
|
|
254
270
|
var _a, _b, _c, _d, _e, _f;
|
|
255
271
|
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
256
272
|
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
@@ -295,11 +311,10 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
295
311
|
}
|
|
296
312
|
const formHeaders = formData.getHeaders();
|
|
297
313
|
try {
|
|
298
|
-
const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
299
314
|
const config = {
|
|
300
315
|
headers: {
|
|
301
316
|
Authorization: "Bearer " + token,
|
|
302
|
-
[CLI_VERSION_HEADER]:
|
|
317
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
303
318
|
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.UPLOAD,
|
|
304
319
|
[SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
|
|
305
320
|
...formHeaders,
|
|
@@ -330,13 +345,15 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
330
345
|
}
|
|
331
346
|
}
|
|
332
347
|
exports.uploadComponents = uploadComponents;
|
|
333
|
-
async function fetchCurrentUser(token, superblocksBaseUrl) {
|
|
348
|
+
async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
|
|
349
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
334
350
|
try {
|
|
335
351
|
const config = {
|
|
336
352
|
method: "get",
|
|
337
|
-
url: new URL(
|
|
353
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL}/users/me`, superblocksBaseUrl).toString(),
|
|
338
354
|
headers: {
|
|
339
355
|
Authorization: "Bearer " + token,
|
|
356
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
340
357
|
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.LOGIN,
|
|
341
358
|
},
|
|
342
359
|
};
|
|
@@ -344,14 +361,21 @@ async function fetchCurrentUser(token, superblocksBaseUrl) {
|
|
|
344
361
|
return response.data.data.user;
|
|
345
362
|
}
|
|
346
363
|
catch (e) {
|
|
347
|
-
|
|
364
|
+
let message;
|
|
365
|
+
if (e instanceof axios_1.AxiosError) {
|
|
366
|
+
message =
|
|
367
|
+
(_j = (_h = (_f = (_d = (_c = (_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.responseMeta) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : JSON.stringify((_e = e.response) === null || _e === void 0 ? void 0 : _e.data)) !== null && _f !== void 0 ? _f : (_g = e.response) === null || _g === void 0 ? void 0 : _g.statusText) !== null && _h !== void 0 ? _h : e === null || e === void 0 ? void 0 : e.message) !== null && _j !== void 0 ? _j : `${e}`;
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
message = `${(e === null || e === void 0 ? void 0 : e.message) ? e === null || e === void 0 ? void 0 : e.message : e}`;
|
|
371
|
+
}
|
|
372
|
+
throw new Error(`Could not fetch current user: ${message}`);
|
|
348
373
|
}
|
|
349
374
|
}
|
|
350
375
|
exports.fetchCurrentUser = fetchCurrentUser;
|
|
351
|
-
async function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
|
|
376
|
+
async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
|
|
352
377
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
353
|
-
const
|
|
354
|
-
const serverURL = new URL(`${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
378
|
+
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
355
379
|
let serverResponse;
|
|
356
380
|
try {
|
|
357
381
|
const config = {
|
|
@@ -359,7 +383,7 @@ async function pushApplication({ applicationId, token, superblocksBaseUrl, appli
|
|
|
359
383
|
url: serverURL.toString(),
|
|
360
384
|
headers: {
|
|
361
385
|
Authorization: "Bearer " + token,
|
|
362
|
-
[CLI_VERSION_HEADER]:
|
|
386
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
363
387
|
...injectedHeaders,
|
|
364
388
|
},
|
|
365
389
|
data: applicationConfig,
|
|
@@ -383,10 +407,9 @@ async function pushApplication({ applicationId, token, superblocksBaseUrl, appli
|
|
|
383
407
|
return (_o = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _o === void 0 ? void 0 : _o.data;
|
|
384
408
|
}
|
|
385
409
|
exports.pushApplication = pushApplication;
|
|
386
|
-
async function pushApi({ apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
|
|
410
|
+
async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
|
|
387
411
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
388
|
-
const
|
|
389
|
-
const serverURL = new URL(`${BASE_SERVER_URL}/public/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
412
|
+
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
390
413
|
let serverResponse;
|
|
391
414
|
try {
|
|
392
415
|
const config = {
|
|
@@ -394,7 +417,7 @@ async function pushApi({ apiId, token, superblocksBaseUrl, apiConfig, branch, in
|
|
|
394
417
|
url: serverURL.toString(),
|
|
395
418
|
headers: {
|
|
396
419
|
Authorization: "Bearer " + token,
|
|
397
|
-
[CLI_VERSION_HEADER]:
|
|
420
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
398
421
|
...injectedHeaders,
|
|
399
422
|
},
|
|
400
423
|
data: apiConfig,
|
package/dist/sdk.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export * from "./errors";
|
|
|
4
4
|
export declare class SuperblocksSdk {
|
|
5
5
|
token: string;
|
|
6
6
|
superblocksBaseUrl: string;
|
|
7
|
-
|
|
7
|
+
cliVersion: string;
|
|
8
|
+
constructor(accessToken: string, superblocksBaseUrl: string, cliVersion: string);
|
|
8
9
|
fetchApplication({ applicationId, branch, headers, viewMode, }: {
|
|
9
10
|
applicationId: string;
|
|
10
11
|
branch?: string;
|
|
@@ -21,7 +22,7 @@ export declare class SuperblocksSdk {
|
|
|
21
22
|
componentFiles: any;
|
|
22
23
|
}) | undefined>;
|
|
23
24
|
fetchApplications(headers?: Record<string, string>): Promise<any>;
|
|
24
|
-
fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
|
|
25
|
+
fetchApi(apiId: string, viewMode?: ViewMode, branch?: string): Promise<any>;
|
|
25
26
|
fetchApis(): Promise<any>;
|
|
26
27
|
validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, injectedHeaders?: Record<string, string>): Promise<{
|
|
27
28
|
branchName: string | null;
|
package/dist/sdk.js
CHANGED
|
@@ -6,14 +6,17 @@ const client_1 = require("./client");
|
|
|
6
6
|
// Exporting here instead of index.ts because only sdk.ts is exposed outside in package.json
|
|
7
7
|
tslib_1.__exportStar(require("./errors"), exports);
|
|
8
8
|
class SuperblocksSdk {
|
|
9
|
-
constructor(accessToken, superblocksBaseUrl) {
|
|
9
|
+
constructor(accessToken, superblocksBaseUrl, cliVersion) {
|
|
10
10
|
this.token = "";
|
|
11
11
|
this.superblocksBaseUrl = "";
|
|
12
|
+
this.cliVersion = "";
|
|
12
13
|
this.token = accessToken;
|
|
13
14
|
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
15
|
+
this.cliVersion = cliVersion;
|
|
14
16
|
}
|
|
15
17
|
async fetchApplication({ applicationId, branch, headers = {}, viewMode = "export-live", }) {
|
|
16
18
|
return (0, client_1.fetchApplication)({
|
|
19
|
+
cliVersion: this.cliVersion,
|
|
17
20
|
applicationId,
|
|
18
21
|
branch,
|
|
19
22
|
token: this.token,
|
|
@@ -24,6 +27,7 @@ class SuperblocksSdk {
|
|
|
24
27
|
}
|
|
25
28
|
async fetchApplicationBranches(applicationId, headers = {}) {
|
|
26
29
|
return (0, client_1.fetchApplicationBranches)({
|
|
30
|
+
cliVersion: this.cliVersion,
|
|
27
31
|
applicationId,
|
|
28
32
|
token: this.token,
|
|
29
33
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
@@ -32,6 +36,7 @@ class SuperblocksSdk {
|
|
|
32
36
|
}
|
|
33
37
|
async fetchApplicationWithComponents({ applicationId, branch, headers = {}, viewMode = "export-live", }) {
|
|
34
38
|
return (0, client_1.fetchApplicationWithComponents)({
|
|
39
|
+
cliVersion: this.cliVersion,
|
|
35
40
|
applicationId,
|
|
36
41
|
branch,
|
|
37
42
|
token: this.token,
|
|
@@ -41,22 +46,23 @@ class SuperblocksSdk {
|
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
48
|
async fetchApplications(headers) {
|
|
44
|
-
return (0, client_1.fetchApplications)(this.token, this.superblocksBaseUrl, headers);
|
|
49
|
+
return (0, client_1.fetchApplications)(this.cliVersion, this.token, this.superblocksBaseUrl, headers);
|
|
45
50
|
}
|
|
46
|
-
async fetchApi(apiId, viewMode = "export-live") {
|
|
47
|
-
return (0, client_1.fetchApi)(apiId, this.token, this.superblocksBaseUrl, viewMode);
|
|
51
|
+
async fetchApi(apiId, viewMode = "export-live", branch) {
|
|
52
|
+
return (0, client_1.fetchApi)(this.cliVersion, apiId, this.token, this.superblocksBaseUrl, viewMode, branch);
|
|
48
53
|
}
|
|
49
54
|
async fetchApis() {
|
|
50
|
-
return (0, client_1.fetchApis)(this.token, this.superblocksBaseUrl);
|
|
55
|
+
return (0, client_1.fetchApis)(this.cliVersion, this.token, this.superblocksBaseUrl);
|
|
51
56
|
}
|
|
52
57
|
async validateGitSetup(resourceId, resourceType, event, localGitRepoState, injectedHeaders) {
|
|
53
|
-
return (0, client_1.validateGitSetup)(resourceId, resourceType, event, localGitRepoState, this.token, this.superblocksBaseUrl, injectedHeaders);
|
|
58
|
+
return (0, client_1.validateGitSetup)(this.cliVersion, resourceId, resourceType, event, localGitRepoState, this.token, this.superblocksBaseUrl, injectedHeaders);
|
|
54
59
|
}
|
|
55
60
|
async registerComponents(applicationId, componentConfigs, branch, injectedHeaders) {
|
|
56
|
-
return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl, branch, injectedHeaders);
|
|
61
|
+
return (0, client_1.registerComponents)(this.cliVersion, applicationId, componentConfigs, this.token, this.superblocksBaseUrl, branch, injectedHeaders);
|
|
57
62
|
}
|
|
58
63
|
async uploadComponents(applicationId, componentConfigs, files, branch) {
|
|
59
64
|
return (0, client_1.uploadComponents)({
|
|
65
|
+
cliVersion: this.cliVersion,
|
|
60
66
|
applicationId,
|
|
61
67
|
componentConfigs,
|
|
62
68
|
files,
|
|
@@ -66,10 +72,11 @@ class SuperblocksSdk {
|
|
|
66
72
|
});
|
|
67
73
|
}
|
|
68
74
|
async fetchCurrentUser() {
|
|
69
|
-
return (0, client_1.fetchCurrentUser)(this.token, this.superblocksBaseUrl);
|
|
75
|
+
return (0, client_1.fetchCurrentUser)(this.cliVersion, this.token, this.superblocksBaseUrl);
|
|
70
76
|
}
|
|
71
77
|
async pushApplication({ applicationId, applicationConfig, branch, headers = {}, }) {
|
|
72
78
|
return (0, client_1.pushApplication)({
|
|
79
|
+
cliVersion: this.cliVersion,
|
|
73
80
|
applicationId,
|
|
74
81
|
token: this.token,
|
|
75
82
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
@@ -80,6 +87,7 @@ class SuperblocksSdk {
|
|
|
80
87
|
}
|
|
81
88
|
async pushApi({ apiId, apiConfig, branch, headers = {}, }) {
|
|
82
89
|
return (0, client_1.pushApi)({
|
|
90
|
+
cliVersion: this.cliVersion,
|
|
83
91
|
apiId,
|
|
84
92
|
apiConfig,
|
|
85
93
|
token: this.token,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Superblocks JS SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"typescript": "^5.1.3"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@superblocksteam/util": "1.4.
|
|
33
|
+
"@superblocksteam/util": "1.4.2",
|
|
34
34
|
"axios": "^1.3.5"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://www.superblocks.com",
|
package/src/client.ts
CHANGED
|
@@ -2,7 +2,6 @@ import * as fs from "fs";
|
|
|
2
2
|
import {
|
|
3
3
|
ComponentEvent,
|
|
4
4
|
getBucketeerUrlFromSuperblocksUrl,
|
|
5
|
-
getSuperblocksMonorepoConfigJson,
|
|
6
5
|
getContentType,
|
|
7
6
|
COMPONENT_EVENT_HEADER,
|
|
8
7
|
NotFoundError,
|
|
@@ -16,8 +15,8 @@ import * as FormData from "form-data";
|
|
|
16
15
|
import { isEmpty } from "lodash";
|
|
17
16
|
import { BranchNotCheckedOutError, CommitAlreadyExistsError } from "./errors";
|
|
18
17
|
|
|
19
|
-
const BASE_SERVER_URL = "api/v1";
|
|
20
18
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
19
|
+
const BASE_SERVER_PUBLIC_API_URL = "api/v1/public";
|
|
21
20
|
|
|
22
21
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
23
22
|
|
|
@@ -66,6 +65,7 @@ export type Branch = {
|
|
|
66
65
|
type ResponseWithMeta<T> = { responseMeta: unknown; data: T };
|
|
67
66
|
|
|
68
67
|
export async function fetchApplication({
|
|
68
|
+
cliVersion,
|
|
69
69
|
applicationId,
|
|
70
70
|
branch,
|
|
71
71
|
token,
|
|
@@ -73,6 +73,7 @@ export async function fetchApplication({
|
|
|
73
73
|
viewMode,
|
|
74
74
|
injectedHeaders = {},
|
|
75
75
|
}: {
|
|
76
|
+
cliVersion: string;
|
|
76
77
|
applicationId: string;
|
|
77
78
|
branch?: string;
|
|
78
79
|
token: string;
|
|
@@ -82,11 +83,13 @@ export async function fetchApplication({
|
|
|
82
83
|
}): Promise<ApplicationWrapper | undefined> {
|
|
83
84
|
const serverURL = branch
|
|
84
85
|
? new URL(
|
|
85
|
-
|
|
86
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
87
|
+
branch
|
|
88
|
+
)}?viewMode=${viewMode}`,
|
|
86
89
|
superblocksBaseUrl
|
|
87
90
|
)
|
|
88
91
|
: new URL(
|
|
89
|
-
|
|
92
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`,
|
|
90
93
|
superblocksBaseUrl
|
|
91
94
|
);
|
|
92
95
|
|
|
@@ -98,6 +101,7 @@ export async function fetchApplication({
|
|
|
98
101
|
url: serverURL.toString(),
|
|
99
102
|
headers: {
|
|
100
103
|
Authorization: "Bearer " + token,
|
|
104
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
101
105
|
...injectedHeaders,
|
|
102
106
|
},
|
|
103
107
|
};
|
|
@@ -113,18 +117,20 @@ export async function fetchApplication({
|
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
export async function fetchApplicationBranches({
|
|
120
|
+
cliVersion,
|
|
116
121
|
applicationId,
|
|
117
122
|
token,
|
|
118
123
|
superblocksBaseUrl,
|
|
119
124
|
injectedHeaders = {},
|
|
120
125
|
}: {
|
|
126
|
+
cliVersion: string;
|
|
121
127
|
applicationId: string;
|
|
122
128
|
token: string;
|
|
123
129
|
superblocksBaseUrl: string;
|
|
124
130
|
injectedHeaders: Record<string, string>;
|
|
125
131
|
}): Promise<Branches | undefined> {
|
|
126
132
|
const serverURL = new URL(
|
|
127
|
-
`
|
|
133
|
+
`public/applications/${applicationId}/branches`,
|
|
128
134
|
superblocksBaseUrl
|
|
129
135
|
);
|
|
130
136
|
let serverResponse;
|
|
@@ -135,6 +141,7 @@ export async function fetchApplicationBranches({
|
|
|
135
141
|
url: serverURL.toString(),
|
|
136
142
|
headers: {
|
|
137
143
|
Authorization: "Bearer " + token,
|
|
144
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
138
145
|
...injectedHeaders,
|
|
139
146
|
},
|
|
140
147
|
};
|
|
@@ -150,6 +157,7 @@ export async function fetchApplicationBranches({
|
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
export async function fetchApplicationWithComponents({
|
|
160
|
+
cliVersion,
|
|
153
161
|
applicationId,
|
|
154
162
|
branch,
|
|
155
163
|
token,
|
|
@@ -157,6 +165,7 @@ export async function fetchApplicationWithComponents({
|
|
|
157
165
|
viewMode,
|
|
158
166
|
injectedHeaders = {},
|
|
159
167
|
}: {
|
|
168
|
+
cliVersion: string;
|
|
160
169
|
applicationId: string;
|
|
161
170
|
branch: string;
|
|
162
171
|
token: string;
|
|
@@ -165,6 +174,7 @@ export async function fetchApplicationWithComponents({
|
|
|
165
174
|
injectedHeaders: Record<string, string>;
|
|
166
175
|
}): Promise<(ApplicationWrapper & { componentFiles: any }) | undefined> {
|
|
167
176
|
const applicationWrapper = await fetchApplication({
|
|
177
|
+
cliVersion,
|
|
168
178
|
applicationId,
|
|
169
179
|
branch,
|
|
170
180
|
token,
|
|
@@ -219,6 +229,7 @@ export async function fetchApplicationWithComponents({
|
|
|
219
229
|
}
|
|
220
230
|
|
|
221
231
|
export async function fetchApplications(
|
|
232
|
+
cliVersion: string,
|
|
222
233
|
token: string,
|
|
223
234
|
superblocksBaseUrl: string,
|
|
224
235
|
injectedHeaders: Record<string, string> = {}
|
|
@@ -226,34 +237,61 @@ export async function fetchApplications(
|
|
|
226
237
|
try {
|
|
227
238
|
const config: AxiosRequestConfig = {
|
|
228
239
|
method: "get",
|
|
229
|
-
url: new URL(
|
|
240
|
+
url: new URL(
|
|
241
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications`,
|
|
242
|
+
superblocksBaseUrl
|
|
243
|
+
).toString(),
|
|
230
244
|
headers: {
|
|
231
245
|
Authorization: "Bearer " + token,
|
|
246
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
232
247
|
...injectedHeaders,
|
|
233
248
|
},
|
|
234
249
|
};
|
|
235
250
|
const response = await axios(config);
|
|
236
251
|
return response.data.data.applications;
|
|
237
|
-
} catch (e) {
|
|
238
|
-
|
|
252
|
+
} catch (e: any) {
|
|
253
|
+
let message: string;
|
|
254
|
+
if (e instanceof AxiosError) {
|
|
255
|
+
message =
|
|
256
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
257
|
+
JSON.stringify(e.response?.data) ??
|
|
258
|
+
e.response?.statusText ??
|
|
259
|
+
e?.message ??
|
|
260
|
+
`${e}`;
|
|
261
|
+
} else {
|
|
262
|
+
message = `${e?.message ? e?.message : e}`;
|
|
263
|
+
}
|
|
264
|
+
throw new Error(`Could not fetch applications: ${message}`);
|
|
239
265
|
}
|
|
240
266
|
}
|
|
241
267
|
|
|
242
268
|
export async function fetchApi(
|
|
269
|
+
cliVersion: string,
|
|
243
270
|
apiId: string,
|
|
244
271
|
token: string,
|
|
245
272
|
superblocksBaseUrl: string,
|
|
246
|
-
viewMode: ViewMode
|
|
273
|
+
viewMode: ViewMode,
|
|
274
|
+
branch?: string
|
|
247
275
|
) {
|
|
248
276
|
try {
|
|
277
|
+
const serverURL = branch
|
|
278
|
+
? new URL(
|
|
279
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(
|
|
280
|
+
branch
|
|
281
|
+
)}?viewMode=${viewMode}`,
|
|
282
|
+
superblocksBaseUrl
|
|
283
|
+
)
|
|
284
|
+
: new URL(
|
|
285
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}?viewMode=${viewMode}`,
|
|
286
|
+
superblocksBaseUrl
|
|
287
|
+
);
|
|
288
|
+
|
|
249
289
|
const config: AxiosRequestConfig = {
|
|
250
290
|
method: "get",
|
|
251
|
-
url: new URL(
|
|
252
|
-
`/api/v3/apis/${apiId}?viewMode=${viewMode}`,
|
|
253
|
-
superblocksBaseUrl
|
|
254
|
-
).toString(),
|
|
291
|
+
url: new URL(serverURL, superblocksBaseUrl).toString(),
|
|
255
292
|
headers: {
|
|
256
293
|
Authorization: "Bearer " + token,
|
|
294
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
257
295
|
},
|
|
258
296
|
};
|
|
259
297
|
const response = await axios(config);
|
|
@@ -266,23 +304,32 @@ export async function fetchApi(
|
|
|
266
304
|
}
|
|
267
305
|
}
|
|
268
306
|
|
|
269
|
-
export async function fetchApis(
|
|
307
|
+
export async function fetchApis(
|
|
308
|
+
cliVersion: string,
|
|
309
|
+
token: string,
|
|
310
|
+
superblocksBaseUrl: string
|
|
311
|
+
) {
|
|
270
312
|
try {
|
|
271
313
|
const config: AxiosRequestConfig = {
|
|
272
314
|
method: "get",
|
|
273
|
-
url: new URL(
|
|
315
|
+
url: new URL(
|
|
316
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis`,
|
|
317
|
+
superblocksBaseUrl
|
|
318
|
+
).toString(),
|
|
274
319
|
headers: {
|
|
275
320
|
Authorization: "Bearer " + token,
|
|
321
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
276
322
|
},
|
|
277
323
|
};
|
|
278
324
|
const response = await axios(config);
|
|
279
|
-
return response.data.data;
|
|
325
|
+
return response.data.data.apis;
|
|
280
326
|
} catch (e) {
|
|
281
327
|
throw new Error("Could not fetch apis");
|
|
282
328
|
}
|
|
283
329
|
}
|
|
284
330
|
|
|
285
331
|
export async function validateGitSetup(
|
|
332
|
+
cliVersion: string,
|
|
286
333
|
resourceId: string,
|
|
287
334
|
resourceType: SuperblocksResourceType,
|
|
288
335
|
event: ComponentEvent,
|
|
@@ -293,7 +340,6 @@ export async function validateGitSetup(
|
|
|
293
340
|
) {
|
|
294
341
|
let resourceName: string | undefined;
|
|
295
342
|
try {
|
|
296
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
297
343
|
const requestBody: ValidateGitSetupRequestBody = {
|
|
298
344
|
event,
|
|
299
345
|
gitState: localGitRepoState,
|
|
@@ -301,11 +347,11 @@ export async function validateGitSetup(
|
|
|
301
347
|
let path: string;
|
|
302
348
|
switch (resourceType) {
|
|
303
349
|
case "APPLICATION": {
|
|
304
|
-
path = `/
|
|
350
|
+
path = `/application/${resourceId}/validate-git-setup`;
|
|
305
351
|
break;
|
|
306
352
|
}
|
|
307
353
|
case "BACKEND": {
|
|
308
|
-
path = `/
|
|
354
|
+
path = `/api/${resourceId}/validate-git-setup`;
|
|
309
355
|
break;
|
|
310
356
|
}
|
|
311
357
|
default:
|
|
@@ -313,10 +359,13 @@ export async function validateGitSetup(
|
|
|
313
359
|
}
|
|
314
360
|
const config: AxiosRequestConfig = {
|
|
315
361
|
method: "post",
|
|
316
|
-
url: new URL(
|
|
362
|
+
url: new URL(
|
|
363
|
+
`${BASE_SERVER_PUBLIC_API_URL}/${path}`,
|
|
364
|
+
superblocksBaseUrl
|
|
365
|
+
).toString(),
|
|
317
366
|
headers: {
|
|
318
367
|
Authorization: "Bearer " + token,
|
|
319
|
-
[CLI_VERSION_HEADER]:
|
|
368
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
320
369
|
...injectedHeaders,
|
|
321
370
|
},
|
|
322
371
|
data: requestBody,
|
|
@@ -353,6 +402,7 @@ export async function validateGitSetup(
|
|
|
353
402
|
}
|
|
354
403
|
|
|
355
404
|
export async function registerComponents(
|
|
405
|
+
cliVersion: string,
|
|
356
406
|
applicationId: string,
|
|
357
407
|
componentConfigs: Record<string, any>,
|
|
358
408
|
token: string,
|
|
@@ -361,17 +411,16 @@ export async function registerComponents(
|
|
|
361
411
|
injectedHeaders?: Record<string, string>
|
|
362
412
|
) {
|
|
363
413
|
try {
|
|
364
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
365
414
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
366
415
|
const config: AxiosRequestConfig = {
|
|
367
416
|
method: "put",
|
|
368
417
|
url: new URL(
|
|
369
|
-
`${
|
|
418
|
+
`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`,
|
|
370
419
|
superblocksBaseUrl
|
|
371
420
|
).toString(),
|
|
372
421
|
headers: {
|
|
373
422
|
Authorization: "Bearer " + token,
|
|
374
|
-
[CLI_VERSION_HEADER]:
|
|
423
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
375
424
|
...injectedHeaders,
|
|
376
425
|
},
|
|
377
426
|
data: { components: componentConfigs },
|
|
@@ -399,6 +448,7 @@ export async function registerComponents(
|
|
|
399
448
|
}
|
|
400
449
|
|
|
401
450
|
export async function uploadComponents({
|
|
451
|
+
cliVersion,
|
|
402
452
|
applicationId,
|
|
403
453
|
componentConfigs,
|
|
404
454
|
files,
|
|
@@ -406,6 +456,7 @@ export async function uploadComponents({
|
|
|
406
456
|
superblocksBaseUrl,
|
|
407
457
|
branch,
|
|
408
458
|
}: {
|
|
459
|
+
cliVersion: string;
|
|
409
460
|
applicationId: string;
|
|
410
461
|
componentConfigs: Record<string, any>;
|
|
411
462
|
files: string[];
|
|
@@ -469,11 +520,10 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
469
520
|
const formHeaders = formData.getHeaders();
|
|
470
521
|
|
|
471
522
|
try {
|
|
472
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
473
523
|
const config: AxiosRequestConfig = {
|
|
474
524
|
headers: {
|
|
475
525
|
Authorization: "Bearer " + token,
|
|
476
|
-
[CLI_VERSION_HEADER]:
|
|
526
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
477
527
|
[COMPONENT_EVENT_HEADER]: ComponentEvent.UPLOAD,
|
|
478
528
|
[SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
|
|
479
529
|
...formHeaders,
|
|
@@ -506,26 +556,43 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
506
556
|
}
|
|
507
557
|
|
|
508
558
|
export async function fetchCurrentUser(
|
|
559
|
+
cliVersion: string,
|
|
509
560
|
token: string,
|
|
510
561
|
superblocksBaseUrl: string
|
|
511
562
|
) {
|
|
512
563
|
try {
|
|
513
564
|
const config: AxiosRequestConfig = {
|
|
514
565
|
method: "get",
|
|
515
|
-
url: new URL(
|
|
566
|
+
url: new URL(
|
|
567
|
+
`${BASE_SERVER_PUBLIC_API_URL}/users/me`,
|
|
568
|
+
superblocksBaseUrl
|
|
569
|
+
).toString(),
|
|
516
570
|
headers: {
|
|
517
571
|
Authorization: "Bearer " + token,
|
|
572
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
518
573
|
[COMPONENT_EVENT_HEADER]: ComponentEvent.LOGIN,
|
|
519
574
|
},
|
|
520
575
|
};
|
|
521
576
|
const response = await axios(config);
|
|
522
577
|
return response.data.data.user;
|
|
523
|
-
} catch (e) {
|
|
524
|
-
|
|
578
|
+
} catch (e: any) {
|
|
579
|
+
let message: string;
|
|
580
|
+
if (e instanceof AxiosError) {
|
|
581
|
+
message =
|
|
582
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
583
|
+
JSON.stringify(e.response?.data) ??
|
|
584
|
+
e.response?.statusText ??
|
|
585
|
+
e?.message ??
|
|
586
|
+
`${e}`;
|
|
587
|
+
} else {
|
|
588
|
+
message = `${e?.message ? e?.message : e}`;
|
|
589
|
+
}
|
|
590
|
+
throw new Error(`Could not fetch current user: ${message}`);
|
|
525
591
|
}
|
|
526
592
|
}
|
|
527
593
|
|
|
528
594
|
export async function pushApplication({
|
|
595
|
+
cliVersion,
|
|
529
596
|
applicationId,
|
|
530
597
|
token,
|
|
531
598
|
superblocksBaseUrl,
|
|
@@ -533,6 +600,7 @@ export async function pushApplication({
|
|
|
533
600
|
branch,
|
|
534
601
|
injectedHeaders = {},
|
|
535
602
|
}: {
|
|
603
|
+
cliVersion: string;
|
|
536
604
|
applicationId: string;
|
|
537
605
|
token: string;
|
|
538
606
|
superblocksBaseUrl: string;
|
|
@@ -540,9 +608,8 @@ export async function pushApplication({
|
|
|
540
608
|
injectedHeaders: Record<string, string>;
|
|
541
609
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
542
610
|
}): Promise<ApplicationWrapper | undefined> {
|
|
543
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
544
611
|
const serverURL = new URL(
|
|
545
|
-
`${
|
|
612
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
546
613
|
branch
|
|
547
614
|
)}/push`,
|
|
548
615
|
superblocksBaseUrl
|
|
@@ -555,7 +622,7 @@ export async function pushApplication({
|
|
|
555
622
|
url: serverURL.toString(),
|
|
556
623
|
headers: {
|
|
557
624
|
Authorization: "Bearer " + token,
|
|
558
|
-
[CLI_VERSION_HEADER]:
|
|
625
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
559
626
|
...injectedHeaders,
|
|
560
627
|
},
|
|
561
628
|
data: applicationConfig,
|
|
@@ -594,6 +661,7 @@ export async function pushApplication({
|
|
|
594
661
|
}
|
|
595
662
|
|
|
596
663
|
export async function pushApi({
|
|
664
|
+
cliVersion,
|
|
597
665
|
apiId,
|
|
598
666
|
token,
|
|
599
667
|
superblocksBaseUrl,
|
|
@@ -601,6 +669,7 @@ export async function pushApi({
|
|
|
601
669
|
branch,
|
|
602
670
|
injectedHeaders = {},
|
|
603
671
|
}: {
|
|
672
|
+
cliVersion: string;
|
|
604
673
|
apiId: string;
|
|
605
674
|
token: string;
|
|
606
675
|
superblocksBaseUrl: string;
|
|
@@ -608,9 +677,8 @@ export async function pushApi({
|
|
|
608
677
|
branch: string;
|
|
609
678
|
injectedHeaders: Record<string, string>;
|
|
610
679
|
}): Promise<{ commitId: string } | undefined> {
|
|
611
|
-
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
612
680
|
const serverURL = new URL(
|
|
613
|
-
`${
|
|
681
|
+
`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(
|
|
614
682
|
branch
|
|
615
683
|
)}/push`,
|
|
616
684
|
superblocksBaseUrl
|
|
@@ -623,7 +691,7 @@ export async function pushApi({
|
|
|
623
691
|
url: serverURL.toString(),
|
|
624
692
|
headers: {
|
|
625
693
|
Authorization: "Bearer " + token,
|
|
626
|
-
[CLI_VERSION_HEADER]:
|
|
694
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
627
695
|
...injectedHeaders,
|
|
628
696
|
},
|
|
629
697
|
data: apiConfig,
|
package/src/sdk.ts
CHANGED
|
@@ -27,10 +27,16 @@ export * from "./errors";
|
|
|
27
27
|
export class SuperblocksSdk {
|
|
28
28
|
token = "";
|
|
29
29
|
superblocksBaseUrl = "";
|
|
30
|
+
cliVersion = "";
|
|
30
31
|
|
|
31
|
-
constructor(
|
|
32
|
+
constructor(
|
|
33
|
+
accessToken: string,
|
|
34
|
+
superblocksBaseUrl: string,
|
|
35
|
+
cliVersion: string
|
|
36
|
+
) {
|
|
32
37
|
this.token = accessToken;
|
|
33
38
|
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
39
|
+
this.cliVersion = cliVersion;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
async fetchApplication({
|
|
@@ -45,6 +51,7 @@ export class SuperblocksSdk {
|
|
|
45
51
|
viewMode?: ViewMode;
|
|
46
52
|
}) {
|
|
47
53
|
return fetchApplication({
|
|
54
|
+
cliVersion: this.cliVersion,
|
|
48
55
|
applicationId,
|
|
49
56
|
branch,
|
|
50
57
|
token: this.token,
|
|
@@ -56,6 +63,7 @@ export class SuperblocksSdk {
|
|
|
56
63
|
|
|
57
64
|
async fetchApplicationBranches(applicationId: string, headers = {}) {
|
|
58
65
|
return fetchApplicationBranches({
|
|
66
|
+
cliVersion: this.cliVersion,
|
|
59
67
|
applicationId,
|
|
60
68
|
token: this.token,
|
|
61
69
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
@@ -75,6 +83,7 @@ export class SuperblocksSdk {
|
|
|
75
83
|
viewMode?: ViewMode;
|
|
76
84
|
}) {
|
|
77
85
|
return fetchApplicationWithComponents({
|
|
86
|
+
cliVersion: this.cliVersion,
|
|
78
87
|
applicationId,
|
|
79
88
|
branch,
|
|
80
89
|
token: this.token,
|
|
@@ -85,15 +94,31 @@ export class SuperblocksSdk {
|
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
async fetchApplications(headers?: Record<string, string>) {
|
|
88
|
-
return fetchApplications(
|
|
97
|
+
return fetchApplications(
|
|
98
|
+
this.cliVersion,
|
|
99
|
+
this.token,
|
|
100
|
+
this.superblocksBaseUrl,
|
|
101
|
+
headers
|
|
102
|
+
);
|
|
89
103
|
}
|
|
90
104
|
|
|
91
|
-
async fetchApi(
|
|
92
|
-
|
|
105
|
+
async fetchApi(
|
|
106
|
+
apiId: string,
|
|
107
|
+
viewMode: ViewMode = "export-live",
|
|
108
|
+
branch?: string
|
|
109
|
+
) {
|
|
110
|
+
return fetchApi(
|
|
111
|
+
this.cliVersion,
|
|
112
|
+
apiId,
|
|
113
|
+
this.token,
|
|
114
|
+
this.superblocksBaseUrl,
|
|
115
|
+
viewMode,
|
|
116
|
+
branch
|
|
117
|
+
);
|
|
93
118
|
}
|
|
94
119
|
|
|
95
120
|
async fetchApis() {
|
|
96
|
-
return fetchApis(this.token, this.superblocksBaseUrl);
|
|
121
|
+
return fetchApis(this.cliVersion, this.token, this.superblocksBaseUrl);
|
|
97
122
|
}
|
|
98
123
|
|
|
99
124
|
async validateGitSetup(
|
|
@@ -104,6 +129,7 @@ export class SuperblocksSdk {
|
|
|
104
129
|
injectedHeaders?: Record<string, string>
|
|
105
130
|
) {
|
|
106
131
|
return validateGitSetup(
|
|
132
|
+
this.cliVersion,
|
|
107
133
|
resourceId,
|
|
108
134
|
resourceType,
|
|
109
135
|
event,
|
|
@@ -121,6 +147,7 @@ export class SuperblocksSdk {
|
|
|
121
147
|
injectedHeaders?: Record<string, string>
|
|
122
148
|
) {
|
|
123
149
|
return registerComponents(
|
|
150
|
+
this.cliVersion,
|
|
124
151
|
applicationId,
|
|
125
152
|
componentConfigs,
|
|
126
153
|
this.token,
|
|
@@ -137,6 +164,7 @@ export class SuperblocksSdk {
|
|
|
137
164
|
branch: string | null
|
|
138
165
|
) {
|
|
139
166
|
return uploadComponents({
|
|
167
|
+
cliVersion: this.cliVersion,
|
|
140
168
|
applicationId,
|
|
141
169
|
componentConfigs,
|
|
142
170
|
files,
|
|
@@ -147,7 +175,11 @@ export class SuperblocksSdk {
|
|
|
147
175
|
}
|
|
148
176
|
|
|
149
177
|
async fetchCurrentUser() {
|
|
150
|
-
return fetchCurrentUser(
|
|
178
|
+
return fetchCurrentUser(
|
|
179
|
+
this.cliVersion,
|
|
180
|
+
this.token,
|
|
181
|
+
this.superblocksBaseUrl
|
|
182
|
+
);
|
|
151
183
|
}
|
|
152
184
|
|
|
153
185
|
async pushApplication({
|
|
@@ -162,6 +194,7 @@ export class SuperblocksSdk {
|
|
|
162
194
|
headers?: Record<string, string>;
|
|
163
195
|
}) {
|
|
164
196
|
return pushApplication({
|
|
197
|
+
cliVersion: this.cliVersion,
|
|
165
198
|
applicationId,
|
|
166
199
|
token: this.token,
|
|
167
200
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
@@ -182,6 +215,7 @@ export class SuperblocksSdk {
|
|
|
182
215
|
headers?: Record<string, string>;
|
|
183
216
|
}) {
|
|
184
217
|
return pushApi({
|
|
218
|
+
cliVersion: this.cliVersion,
|
|
185
219
|
apiId,
|
|
186
220
|
apiConfig,
|
|
187
221
|
token: this.token,
|