@superblocksteam/sdk 0.0.19 → 0.0.21
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 +6 -1
- package/dist/client.js +18 -14
- package/dist/sdk.js +6 -1
- package/package.json +1 -1
- package/src/client.ts +44 -17
- package/src/sdk.ts +5 -5
package/dist/client.d.ts
CHANGED
|
@@ -4,7 +4,12 @@ export interface UploadFile {
|
|
|
4
4
|
filename: string;
|
|
5
5
|
ContentType: string;
|
|
6
6
|
}
|
|
7
|
-
export declare function fetchApplication(applicationId
|
|
7
|
+
export declare function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, }: {
|
|
8
|
+
applicationId: string;
|
|
9
|
+
token: string;
|
|
10
|
+
superblocksBaseUrl: string;
|
|
11
|
+
viewMode: ViewMode;
|
|
12
|
+
}): Promise<any>;
|
|
8
13
|
export declare function fetchApplications(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
9
14
|
export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
|
|
10
15
|
export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
|
package/dist/client.js
CHANGED
|
@@ -8,20 +8,26 @@ const axios_1 = require("axios");
|
|
|
8
8
|
const FormData = require("form-data");
|
|
9
9
|
const BASE_SERVER_URL = "api/v1";
|
|
10
10
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
11
|
-
const CLI_VERSION_HEADER = "
|
|
12
|
-
async function fetchApplication(applicationId, token, superblocksBaseUrl, viewMode) {
|
|
11
|
+
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
12
|
+
async function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, }) {
|
|
13
13
|
var _a;
|
|
14
|
-
|
|
14
|
+
// TODO(jason) update this with commit ID once we enable fetching by commit
|
|
15
|
+
const commitId = "latest";
|
|
16
|
+
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
17
|
+
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
18
|
+
// fetch files from bucketeer
|
|
19
|
+
const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/components/${applicationId}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
|
|
15
20
|
try {
|
|
16
21
|
const config = {
|
|
17
22
|
method: "get",
|
|
18
|
-
url:
|
|
23
|
+
url: componentFileURL,
|
|
19
24
|
headers: {
|
|
20
25
|
Authorization: "Bearer " + token,
|
|
26
|
+
"x-superblocks-url": superblocksBaseUrl,
|
|
21
27
|
},
|
|
22
28
|
};
|
|
23
29
|
const response = await (0, axios_1.default)(config);
|
|
24
|
-
return response.data
|
|
30
|
+
return response.data;
|
|
25
31
|
}
|
|
26
32
|
catch (e) {
|
|
27
33
|
if (axios_1.default.isAxiosError(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
@@ -87,7 +93,7 @@ async function fetchApis(token, superblocksBaseUrl) {
|
|
|
87
93
|
}
|
|
88
94
|
exports.fetchApis = fetchApis;
|
|
89
95
|
async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl) {
|
|
90
|
-
var _a, _b, _c;
|
|
96
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
91
97
|
try {
|
|
92
98
|
const [rootSettings] = await (0, util_2.getSuperblocksMonorepoConfigJson)(true);
|
|
93
99
|
const config = {
|
|
@@ -104,17 +110,15 @@ async function registerComponents(applicationId, componentConfigs, token, superb
|
|
|
104
110
|
}
|
|
105
111
|
catch (e) {
|
|
106
112
|
if (e instanceof axios_1.AxiosError) {
|
|
107
|
-
const message = (_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;
|
|
108
|
-
throw new Error(`Could not register application components
|
|
109
|
-
${message !== null && message !== void 0 ? message : ""}`);
|
|
113
|
+
const message = (_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;
|
|
114
|
+
throw new Error(`Could not register application components ${message ? "\n" + message : ""}`);
|
|
110
115
|
}
|
|
111
|
-
throw new Error(`Could not register application components
|
|
112
|
-
${e.message}`);
|
|
116
|
+
throw new Error(`Could not register application components ${e.message ? "\n" + e.message : ""}`);
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
exports.registerComponents = registerComponents;
|
|
116
120
|
async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }) {
|
|
117
|
-
var _a, _b, _c;
|
|
121
|
+
var _a, _b, _c, _d, _e, _f;
|
|
118
122
|
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
119
123
|
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
120
124
|
// parse files to source and bundled files based on path
|
|
@@ -159,9 +163,9 @@ async function uploadComponents({ applicationId, componentConfigs, files, token,
|
|
|
159
163
|
}
|
|
160
164
|
catch (e) {
|
|
161
165
|
if (e instanceof axios_1.AxiosError) {
|
|
162
|
-
const message = (_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;
|
|
166
|
+
const message = (_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 : (_e = e.response) === null || _e === void 0 ? void 0 : _e.data;
|
|
163
167
|
throw new Error(`Could not upload application components
|
|
164
|
-
${message}`);
|
|
168
|
+
${message !== null && message !== void 0 ? message : (_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText}`);
|
|
165
169
|
}
|
|
166
170
|
throw new Error(`Could not upload application components
|
|
167
171
|
${e.message}`);
|
package/dist/sdk.js
CHANGED
|
@@ -10,7 +10,12 @@ class SuperblocksSdk {
|
|
|
10
10
|
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
11
11
|
}
|
|
12
12
|
async fetchApplication(applicationId, viewMode = "export-live") {
|
|
13
|
-
return (0, client_1.fetchApplication)(
|
|
13
|
+
return (0, client_1.fetchApplication)({
|
|
14
|
+
applicationId,
|
|
15
|
+
token: this.token,
|
|
16
|
+
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
17
|
+
viewMode,
|
|
18
|
+
});
|
|
14
19
|
}
|
|
15
20
|
async fetchApplications() {
|
|
16
21
|
return (0, client_1.fetchApplications)(this.token, this.superblocksBaseUrl);
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -10,7 +10,7 @@ import * as FormData from "form-data";
|
|
|
10
10
|
const BASE_SERVER_URL = "api/v1";
|
|
11
11
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
12
12
|
|
|
13
|
-
const CLI_VERSION_HEADER = "
|
|
13
|
+
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
14
14
|
|
|
15
15
|
export type ViewMode = "export-deployed" | "export-latest" | "export-live";
|
|
16
16
|
|
|
@@ -20,23 +20,40 @@ export interface UploadFile {
|
|
|
20
20
|
ContentType: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export async function fetchApplication(
|
|
24
|
-
applicationId
|
|
25
|
-
token
|
|
26
|
-
superblocksBaseUrl
|
|
27
|
-
viewMode
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
export async function fetchApplication({
|
|
24
|
+
applicationId,
|
|
25
|
+
token,
|
|
26
|
+
superblocksBaseUrl,
|
|
27
|
+
viewMode,
|
|
28
|
+
}: {
|
|
29
|
+
applicationId: string;
|
|
30
|
+
token: string;
|
|
31
|
+
superblocksBaseUrl: string;
|
|
32
|
+
viewMode: ViewMode;
|
|
33
|
+
}) {
|
|
34
|
+
// TODO(jason) update this with commit ID once we enable fetching by commit
|
|
35
|
+
const commitId = "latest";
|
|
36
|
+
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
37
|
+
const bucketeerBaseUrl =
|
|
38
|
+
getBucketeerUrlFromSuperblocksUrl(superblocksBaseUrl);
|
|
39
|
+
|
|
40
|
+
// fetch files from bucketeer
|
|
41
|
+
const componentFileURL = new URL(
|
|
42
|
+
`${BASE_BUCKETEER_URL}/components/${applicationId}?commit=${commitId}&viewMode=${viewMode}`,
|
|
43
|
+
bucketeerBaseUrl
|
|
44
|
+
).toString();
|
|
45
|
+
|
|
30
46
|
try {
|
|
31
47
|
const config = {
|
|
32
48
|
method: "get",
|
|
33
|
-
url:
|
|
49
|
+
url: componentFileURL,
|
|
34
50
|
headers: {
|
|
35
51
|
Authorization: "Bearer " + token,
|
|
52
|
+
"x-superblocks-url": superblocksBaseUrl,
|
|
36
53
|
},
|
|
37
54
|
};
|
|
38
55
|
const response = await axios(config);
|
|
39
|
-
return response.data
|
|
56
|
+
return response.data;
|
|
40
57
|
} catch (e) {
|
|
41
58
|
if (axios.isAxiosError(e) && e.response?.status === 404) {
|
|
42
59
|
throw new Error(`Application ${applicationId} was not found`);
|
|
@@ -131,12 +148,21 @@ export async function registerComponents(
|
|
|
131
148
|
return response.data;
|
|
132
149
|
} catch (e: any) {
|
|
133
150
|
if (e instanceof AxiosError) {
|
|
134
|
-
const message =
|
|
135
|
-
|
|
136
|
-
|
|
151
|
+
const message: string =
|
|
152
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
153
|
+
JSON.stringify(e.response?.data) ??
|
|
154
|
+
e.response?.statusText;
|
|
155
|
+
throw new Error(
|
|
156
|
+
`Could not register application components ${
|
|
157
|
+
message ? "\n" + message : ""
|
|
158
|
+
}`
|
|
159
|
+
);
|
|
137
160
|
}
|
|
138
|
-
throw new Error(
|
|
139
|
-
${
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Could not register application components ${
|
|
163
|
+
e.message ? "\n" + (e as Error).message : ""
|
|
164
|
+
}`
|
|
165
|
+
);
|
|
140
166
|
}
|
|
141
167
|
}
|
|
142
168
|
|
|
@@ -210,9 +236,10 @@ export async function uploadComponents({
|
|
|
210
236
|
return response.data;
|
|
211
237
|
} catch (e: any) {
|
|
212
238
|
if (e instanceof AxiosError) {
|
|
213
|
-
const message =
|
|
239
|
+
const message =
|
|
240
|
+
(e.response?.data?.responseMeta?.message as string) ?? e.response?.data;
|
|
214
241
|
throw new Error(`Could not upload application components
|
|
215
|
-
${message}`);
|
|
242
|
+
${message ?? e.response?.statusText}`);
|
|
216
243
|
}
|
|
217
244
|
throw new Error(`Could not upload application components
|
|
218
245
|
${e.message as string}`);
|
package/src/sdk.ts
CHANGED
|
@@ -22,12 +22,12 @@ export class SuperblocksSdk {
|
|
|
22
22
|
applicationId: string,
|
|
23
23
|
viewMode: ViewMode = "export-live"
|
|
24
24
|
) {
|
|
25
|
-
return fetchApplication(
|
|
25
|
+
return fetchApplication({
|
|
26
26
|
applicationId,
|
|
27
|
-
this.token,
|
|
28
|
-
this.superblocksBaseUrl,
|
|
29
|
-
viewMode
|
|
30
|
-
);
|
|
27
|
+
token: this.token,
|
|
28
|
+
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
29
|
+
viewMode,
|
|
30
|
+
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async fetchApplications() {
|