@superblocksteam/sdk 1.3.0 → 1.4.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 +1 -0
- package/dist/client.d.ts +20 -1
- package/dist/client.js +43 -8
- package/dist/sdk.d.ts +10 -2
- package/dist/sdk.js +11 -3
- package/package.json +2 -2
- package/src/client.ts +84 -5
- package/src/sdk.ts +23 -2
package/.eslintrc.json
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,15 @@ export type PushApplicationWithCommitConfig = ApplicationWrapper & {
|
|
|
14
14
|
commitId: string;
|
|
15
15
|
commitMessage: string;
|
|
16
16
|
};
|
|
17
|
+
export interface ApiWrapper {
|
|
18
|
+
apiPb: Record<string, any>;
|
|
19
|
+
name?: string;
|
|
20
|
+
}
|
|
21
|
+
export type PushApiWithCommitConfig = {
|
|
22
|
+
apiPb: Record<string, any>;
|
|
23
|
+
commitId: string;
|
|
24
|
+
commitMessage: string;
|
|
25
|
+
};
|
|
17
26
|
export type Branches = {
|
|
18
27
|
branches: Branch[];
|
|
19
28
|
};
|
|
@@ -48,7 +57,7 @@ export declare function fetchApplicationWithComponents({ applicationId, branch,
|
|
|
48
57
|
export declare function fetchApplications(token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
49
58
|
export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
|
|
50
59
|
export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
51
|
-
export declare function validateGitSetup(resourceId: string, resourceType:
|
|
60
|
+
export declare function validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
|
|
52
61
|
branchName: string | null;
|
|
53
62
|
}>;
|
|
54
63
|
export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, branch: string | null, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
@@ -69,3 +78,13 @@ export declare function pushApplication({ applicationId, token, superblocksBaseU
|
|
|
69
78
|
injectedHeaders: Record<string, string>;
|
|
70
79
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
71
80
|
}): Promise<ApplicationWrapper | undefined>;
|
|
81
|
+
export declare function pushApi({ apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
|
|
82
|
+
apiId: string;
|
|
83
|
+
token: string;
|
|
84
|
+
superblocksBaseUrl: string;
|
|
85
|
+
apiConfig: PushApiWithCommitConfig;
|
|
86
|
+
branch: string;
|
|
87
|
+
injectedHeaders: Record<string, string>;
|
|
88
|
+
}): Promise<{
|
|
89
|
+
commitId: string;
|
|
90
|
+
} | undefined>;
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pushApplication = exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.validateGitSetup = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplicationBranches = exports.fetchApplication = void 0;
|
|
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
4
|
const fs = require("fs");
|
|
5
5
|
const util_1 = require("@superblocksteam/util");
|
|
6
6
|
const axios_1 = require("axios");
|
|
@@ -166,9 +166,7 @@ async function fetchApis(token, superblocksBaseUrl) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
exports.fetchApis = fetchApis;
|
|
169
|
-
async function validateGitSetup(resourceId,
|
|
170
|
-
// TODO: change the type to `SuperblocksResourceType` once we support other resource types
|
|
171
|
-
resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
|
|
169
|
+
async function validateGitSetup(resourceId, resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeaders) {
|
|
172
170
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
173
171
|
let resourceName;
|
|
174
172
|
try {
|
|
@@ -183,6 +181,10 @@ resourceType, event, localGitRepoState, token, superblocksBaseUrl, injectedHeade
|
|
|
183
181
|
path = `/public/application/${resourceId}/validate-git-setup`;
|
|
184
182
|
break;
|
|
185
183
|
}
|
|
184
|
+
case "BACKEND": {
|
|
185
|
+
path = `/public/api/${resourceId}/validate-git-setup`;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
186
188
|
default:
|
|
187
189
|
(0, util_1.unreachable)(resourceType);
|
|
188
190
|
}
|
|
@@ -313,10 +315,9 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
313
315
|
else {
|
|
314
316
|
let message;
|
|
315
317
|
if (e instanceof axios_1.AxiosError) {
|
|
316
|
-
message =
|
|
317
|
-
((
|
|
318
|
-
|
|
319
|
-
((_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText);
|
|
318
|
+
message = (((_d = (_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.responseMeta) === null || _d === void 0 ? void 0 : _d.message) ||
|
|
319
|
+
((_e = e.response) === null || _e === void 0 ? void 0 : _e.data) ||
|
|
320
|
+
((_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText));
|
|
320
321
|
}
|
|
321
322
|
else {
|
|
322
323
|
message = e.message;
|
|
@@ -382,3 +383,37 @@ async function pushApplication({ applicationId, token, superblocksBaseUrl, appli
|
|
|
382
383
|
return (_o = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _o === void 0 ? void 0 : _o.data;
|
|
383
384
|
}
|
|
384
385
|
exports.pushApplication = pushApplication;
|
|
386
|
+
async function pushApi({ apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
|
|
387
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
388
|
+
const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
389
|
+
const serverURL = new URL(`${BASE_SERVER_URL}/public/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
390
|
+
let serverResponse;
|
|
391
|
+
try {
|
|
392
|
+
const config = {
|
|
393
|
+
method: "post",
|
|
394
|
+
url: serverURL.toString(),
|
|
395
|
+
headers: {
|
|
396
|
+
Authorization: "Bearer " + token,
|
|
397
|
+
[CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
|
|
398
|
+
...injectedHeaders,
|
|
399
|
+
},
|
|
400
|
+
data: apiConfig,
|
|
401
|
+
};
|
|
402
|
+
serverResponse = await (0, axios_1.default)(config);
|
|
403
|
+
}
|
|
404
|
+
catch (e) {
|
|
405
|
+
if (axios_1.default.isAxiosError(e)) {
|
|
406
|
+
if (((_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.status) === 405) {
|
|
407
|
+
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
408
|
+
}
|
|
409
|
+
else if (((_f = (_e = (_d = e.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.responseMeta) === null || _f === void 0 ? void 0 : _f.status) === 409) {
|
|
410
|
+
throw new errors_1.CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
|
|
411
|
+
}
|
|
412
|
+
const message = (_m = (_k = (_j = (_h = (_g = e.response) === null || _g === void 0 ? void 0 : _g.data) === null || _h === void 0 ? void 0 : _h.responseMeta) === null || _j === void 0 ? void 0 : _j.message) !== null && _k !== void 0 ? _k : JSON.stringify((_l = e.response) === null || _l === void 0 ? void 0 : _l.data)) !== null && _m !== void 0 ? _m : (_o = e.response) === null || _o === void 0 ? void 0 : _o.statusText;
|
|
413
|
+
throw new Error(`Could not push api ${message ? "\n" + message : ""}`);
|
|
414
|
+
}
|
|
415
|
+
throw new Error(`Could not push api ${e.message ? "\n" + e.message : ""}`);
|
|
416
|
+
}
|
|
417
|
+
return (_p = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _p === void 0 ? void 0 : _p.data;
|
|
418
|
+
}
|
|
419
|
+
exports.pushApi = pushApi;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
|
|
2
|
-
import { ViewMode, PushApplicationWithCommitConfig } from "./client";
|
|
2
|
+
import { ViewMode, PushApplicationWithCommitConfig, PushApiWithCommitConfig } from "./client";
|
|
3
3
|
export * from "./errors";
|
|
4
4
|
export declare class SuperblocksSdk {
|
|
5
5
|
token: string;
|
|
@@ -23,7 +23,7 @@ export declare class SuperblocksSdk {
|
|
|
23
23
|
fetchApplications(headers?: Record<string, string>): Promise<any>;
|
|
24
24
|
fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
|
|
25
25
|
fetchApis(): Promise<any>;
|
|
26
|
-
validateGitSetup(resourceId: string, resourceType:
|
|
26
|
+
validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, injectedHeaders?: Record<string, string>): Promise<{
|
|
27
27
|
branchName: string | null;
|
|
28
28
|
}>;
|
|
29
29
|
registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
@@ -35,4 +35,12 @@ export declare class SuperblocksSdk {
|
|
|
35
35
|
branch: string;
|
|
36
36
|
headers?: Record<string, string>;
|
|
37
37
|
}): Promise<import("./client").ApplicationWrapper | undefined>;
|
|
38
|
+
pushApi({ apiId, apiConfig, branch, headers, }: {
|
|
39
|
+
apiId: string;
|
|
40
|
+
apiConfig: PushApiWithCommitConfig;
|
|
41
|
+
branch: string;
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
commitId: string;
|
|
45
|
+
} | undefined>;
|
|
38
46
|
}
|
package/dist/sdk.js
CHANGED
|
@@ -49,9 +49,7 @@ class SuperblocksSdk {
|
|
|
49
49
|
async fetchApis() {
|
|
50
50
|
return (0, client_1.fetchApis)(this.token, this.superblocksBaseUrl);
|
|
51
51
|
}
|
|
52
|
-
async validateGitSetup(resourceId,
|
|
53
|
-
// TODO: change the type to `SuperblocksResourceType` once we support other resource types
|
|
54
|
-
resourceType, event, localGitRepoState, injectedHeaders) {
|
|
52
|
+
async validateGitSetup(resourceId, resourceType, event, localGitRepoState, injectedHeaders) {
|
|
55
53
|
return (0, client_1.validateGitSetup)(resourceId, resourceType, event, localGitRepoState, this.token, this.superblocksBaseUrl, injectedHeaders);
|
|
56
54
|
}
|
|
57
55
|
async registerComponents(applicationId, componentConfigs, branch, injectedHeaders) {
|
|
@@ -80,5 +78,15 @@ class SuperblocksSdk {
|
|
|
80
78
|
applicationConfig,
|
|
81
79
|
});
|
|
82
80
|
}
|
|
81
|
+
async pushApi({ apiId, apiConfig, branch, headers = {}, }) {
|
|
82
|
+
return (0, client_1.pushApi)({
|
|
83
|
+
apiId,
|
|
84
|
+
apiConfig,
|
|
85
|
+
token: this.token,
|
|
86
|
+
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
87
|
+
branch,
|
|
88
|
+
injectedHeaders: headers,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
83
91
|
}
|
|
84
92
|
exports.SuperblocksSdk = SuperblocksSdk;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
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.
|
|
33
|
+
"@superblocksteam/util": "1.4.1",
|
|
34
34
|
"axios": "^1.3.5"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://www.superblocks.com",
|
package/src/client.ts
CHANGED
|
@@ -43,6 +43,17 @@ export type PushApplicationWithCommitConfig = ApplicationWrapper & {
|
|
|
43
43
|
commitMessage: string;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
export interface ApiWrapper {
|
|
47
|
+
apiPb: Record<string, any>;
|
|
48
|
+
name?: string; //@deprecated this attribute is used for getting a name for backends(jobs and workflows) that were never migrated to the new API version.
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type PushApiWithCommitConfig = {
|
|
52
|
+
apiPb: Record<string, any>;
|
|
53
|
+
commitId: string;
|
|
54
|
+
commitMessage: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
46
57
|
export type Branches = {
|
|
47
58
|
branches: Branch[];
|
|
48
59
|
};
|
|
@@ -273,8 +284,7 @@ export async function fetchApis(token: string, superblocksBaseUrl: string) {
|
|
|
273
284
|
|
|
274
285
|
export async function validateGitSetup(
|
|
275
286
|
resourceId: string,
|
|
276
|
-
|
|
277
|
-
resourceType: Exclude<SuperblocksResourceType, "BACKEND">,
|
|
287
|
+
resourceType: SuperblocksResourceType,
|
|
278
288
|
event: ComponentEvent,
|
|
279
289
|
localGitRepoState: LocalGitRepoState,
|
|
280
290
|
token: string,
|
|
@@ -294,6 +304,10 @@ export async function validateGitSetup(
|
|
|
294
304
|
path = `/public/application/${resourceId}/validate-git-setup`;
|
|
295
305
|
break;
|
|
296
306
|
}
|
|
307
|
+
case "BACKEND": {
|
|
308
|
+
path = `/public/api/${resourceId}/validate-git-setup`;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
297
311
|
default:
|
|
298
312
|
unreachable(resourceType);
|
|
299
313
|
}
|
|
@@ -477,10 +491,9 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
477
491
|
} else {
|
|
478
492
|
let message: string;
|
|
479
493
|
if (e instanceof AxiosError) {
|
|
480
|
-
message =
|
|
481
|
-
e.response?.data?.responseMeta?.message ||
|
|
494
|
+
message = (e.response?.data?.responseMeta?.message ||
|
|
482
495
|
e.response?.data ||
|
|
483
|
-
e.response?.statusText;
|
|
496
|
+
e.response?.statusText) as string;
|
|
484
497
|
} else {
|
|
485
498
|
message = e.message as string;
|
|
486
499
|
}
|
|
@@ -579,3 +592,69 @@ export async function pushApplication({
|
|
|
579
592
|
|
|
580
593
|
return serverResponse?.data?.data;
|
|
581
594
|
}
|
|
595
|
+
|
|
596
|
+
export async function pushApi({
|
|
597
|
+
apiId,
|
|
598
|
+
token,
|
|
599
|
+
superblocksBaseUrl,
|
|
600
|
+
apiConfig,
|
|
601
|
+
branch,
|
|
602
|
+
injectedHeaders = {},
|
|
603
|
+
}: {
|
|
604
|
+
apiId: string;
|
|
605
|
+
token: string;
|
|
606
|
+
superblocksBaseUrl: string;
|
|
607
|
+
apiConfig: PushApiWithCommitConfig;
|
|
608
|
+
branch: string;
|
|
609
|
+
injectedHeaders: Record<string, string>;
|
|
610
|
+
}): Promise<{ commitId: string } | undefined> {
|
|
611
|
+
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
612
|
+
const serverURL = new URL(
|
|
613
|
+
`${BASE_SERVER_URL}/public/apis/${apiId}/branches/${encodeURIComponent(
|
|
614
|
+
branch
|
|
615
|
+
)}/push`,
|
|
616
|
+
superblocksBaseUrl
|
|
617
|
+
);
|
|
618
|
+
let serverResponse;
|
|
619
|
+
|
|
620
|
+
try {
|
|
621
|
+
const config: AxiosRequestConfig = {
|
|
622
|
+
method: "post",
|
|
623
|
+
url: serverURL.toString(),
|
|
624
|
+
headers: {
|
|
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
|
|
633
|
+
);
|
|
634
|
+
} catch (e) {
|
|
635
|
+
if (axios.isAxiosError(e)) {
|
|
636
|
+
if (e.response?.data?.responseMeta?.status === 405) {
|
|
637
|
+
throw new BranchNotCheckedOutError(
|
|
638
|
+
`Branch ${branch} is not checked out`
|
|
639
|
+
);
|
|
640
|
+
} else if (e.response?.data?.responseMeta?.status === 409) {
|
|
641
|
+
throw new CommitAlreadyExistsError(
|
|
642
|
+
`Commit ${apiConfig.commitId} already exists`
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
const message: string =
|
|
646
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
647
|
+
JSON.stringify(e.response?.data) ??
|
|
648
|
+
e.response?.statusText;
|
|
649
|
+
|
|
650
|
+
throw new Error(`Could not push api ${message ? "\n" + message : ""}`);
|
|
651
|
+
}
|
|
652
|
+
throw new Error(
|
|
653
|
+
`Could not push api ${
|
|
654
|
+
(e as Error).message ? "\n" + (e as Error).message : ""
|
|
655
|
+
}`
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
return serverResponse?.data?.data;
|
|
660
|
+
}
|
package/src/sdk.ts
CHANGED
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
pushApplication,
|
|
17
17
|
PushApplicationWithCommitConfig,
|
|
18
18
|
fetchApplicationBranches,
|
|
19
|
+
PushApiWithCommitConfig,
|
|
20
|
+
pushApi,
|
|
19
21
|
validateGitSetup,
|
|
20
22
|
} from "./client";
|
|
21
23
|
|
|
@@ -96,8 +98,7 @@ export class SuperblocksSdk {
|
|
|
96
98
|
|
|
97
99
|
async validateGitSetup(
|
|
98
100
|
resourceId: string,
|
|
99
|
-
|
|
100
|
-
resourceType: Exclude<SuperblocksResourceType, "BACKEND">,
|
|
101
|
+
resourceType: SuperblocksResourceType,
|
|
101
102
|
event: ComponentEvent,
|
|
102
103
|
localGitRepoState: LocalGitRepoState,
|
|
103
104
|
injectedHeaders?: Record<string, string>
|
|
@@ -169,4 +170,24 @@ export class SuperblocksSdk {
|
|
|
169
170
|
applicationConfig,
|
|
170
171
|
});
|
|
171
172
|
}
|
|
173
|
+
async pushApi({
|
|
174
|
+
apiId,
|
|
175
|
+
apiConfig,
|
|
176
|
+
branch,
|
|
177
|
+
headers = {},
|
|
178
|
+
}: {
|
|
179
|
+
apiId: string;
|
|
180
|
+
apiConfig: PushApiWithCommitConfig;
|
|
181
|
+
branch: string;
|
|
182
|
+
headers?: Record<string, string>;
|
|
183
|
+
}) {
|
|
184
|
+
return pushApi({
|
|
185
|
+
apiId,
|
|
186
|
+
apiConfig,
|
|
187
|
+
token: this.token,
|
|
188
|
+
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
189
|
+
branch,
|
|
190
|
+
injectedHeaders: headers,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
172
193
|
}
|