@superblocksteam/sdk 0.0.20 → 0.0.22
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 +4 -3
- package/dist/client.js +18 -14
- package/dist/sdk.d.ts +7 -3
- package/dist/sdk.js +6 -5
- package/package.json +1 -1
- package/src/client.ts +33 -11
- package/src/sdk.ts +18 -10
package/dist/client.d.ts
CHANGED
|
@@ -4,16 +4,17 @@ export interface UploadFile {
|
|
|
4
4
|
filename: string;
|
|
5
5
|
ContentType: string;
|
|
6
6
|
}
|
|
7
|
-
export declare function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, }: {
|
|
7
|
+
export declare function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
|
|
8
8
|
applicationId: string;
|
|
9
9
|
token: string;
|
|
10
10
|
superblocksBaseUrl: string;
|
|
11
11
|
viewMode: ViewMode;
|
|
12
|
+
injectedHeaders: Record<string, string>;
|
|
12
13
|
}): Promise<any>;
|
|
13
|
-
export declare function fetchApplications(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
14
|
+
export declare function fetchApplications(token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
14
15
|
export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
|
|
15
16
|
export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
16
|
-
export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string): Promise<any>;
|
|
17
|
+
export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
17
18
|
export declare function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }: {
|
|
18
19
|
applicationId: string;
|
|
19
20
|
componentConfigs: Record<string, any>;
|
package/dist/client.js
CHANGED
|
@@ -9,7 +9,8 @@ const FormData = require("form-data");
|
|
|
9
9
|
const BASE_SERVER_URL = "api/v1";
|
|
10
10
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
11
11
|
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
12
|
-
|
|
12
|
+
const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
|
|
13
|
+
async function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
13
14
|
var _a;
|
|
14
15
|
// TODO(jason) update this with commit ID once we enable fetching by commit
|
|
15
16
|
const commitId = "latest";
|
|
@@ -23,7 +24,8 @@ async function fetchApplication({ applicationId, token, superblocksBaseUrl, view
|
|
|
23
24
|
url: componentFileURL,
|
|
24
25
|
headers: {
|
|
25
26
|
Authorization: "Bearer " + token,
|
|
26
|
-
|
|
27
|
+
[SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
|
|
28
|
+
...injectedHeaders,
|
|
27
29
|
},
|
|
28
30
|
};
|
|
29
31
|
const response = await (0, axios_1.default)(config);
|
|
@@ -37,13 +39,14 @@ async function fetchApplication({ applicationId, token, superblocksBaseUrl, view
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
exports.fetchApplication = fetchApplication;
|
|
40
|
-
async function fetchApplications(token, superblocksBaseUrl) {
|
|
42
|
+
async function fetchApplications(token, superblocksBaseUrl, injectedHeaders = {}) {
|
|
41
43
|
try {
|
|
42
44
|
const config = {
|
|
43
45
|
method: "get",
|
|
44
46
|
url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
|
|
45
47
|
headers: {
|
|
46
48
|
Authorization: "Bearer " + token,
|
|
49
|
+
...injectedHeaders,
|
|
47
50
|
},
|
|
48
51
|
};
|
|
49
52
|
const response = await (0, axios_1.default)(config);
|
|
@@ -92,8 +95,8 @@ async function fetchApis(token, superblocksBaseUrl) {
|
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
exports.fetchApis = fetchApis;
|
|
95
|
-
async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl) {
|
|
96
|
-
var _a, _b, _c;
|
|
98
|
+
async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl, injectedHeaders) {
|
|
99
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
97
100
|
try {
|
|
98
101
|
const [rootSettings] = await (0, util_2.getSuperblocksMonorepoConfigJson)(true);
|
|
99
102
|
const config = {
|
|
@@ -102,6 +105,7 @@ async function registerComponents(applicationId, componentConfigs, token, superb
|
|
|
102
105
|
headers: {
|
|
103
106
|
Authorization: "Bearer " + token,
|
|
104
107
|
[CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
|
|
108
|
+
...injectedHeaders,
|
|
105
109
|
},
|
|
106
110
|
data: { components: componentConfigs },
|
|
107
111
|
};
|
|
@@ -110,17 +114,15 @@ async function registerComponents(applicationId, componentConfigs, token, superb
|
|
|
110
114
|
}
|
|
111
115
|
catch (e) {
|
|
112
116
|
if (e instanceof axios_1.AxiosError) {
|
|
113
|
-
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;
|
|
114
|
-
throw new Error(`Could not register application components
|
|
115
|
-
${message !== null && message !== void 0 ? message : ""}`);
|
|
117
|
+
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;
|
|
118
|
+
throw new Error(`Could not register application components ${message ? "\n" + message : ""}`);
|
|
116
119
|
}
|
|
117
|
-
throw new Error(`Could not register application components
|
|
118
|
-
${e.message}`);
|
|
120
|
+
throw new Error(`Could not register application components ${e.message ? "\n" + e.message : ""}`);
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
exports.registerComponents = registerComponents;
|
|
122
124
|
async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }) {
|
|
123
|
-
var _a, _b, _c;
|
|
125
|
+
var _a, _b, _c, _d, _e, _f;
|
|
124
126
|
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
125
127
|
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
126
128
|
// parse files to source and bundled files based on path
|
|
@@ -156,7 +158,8 @@ async function uploadComponents({ applicationId, componentConfigs, files, token,
|
|
|
156
158
|
headers: {
|
|
157
159
|
Authorization: "Bearer " + token,
|
|
158
160
|
[CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
|
|
159
|
-
|
|
161
|
+
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.UPLOAD,
|
|
162
|
+
[SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
|
|
160
163
|
...formHeaders,
|
|
161
164
|
},
|
|
162
165
|
};
|
|
@@ -165,9 +168,9 @@ async function uploadComponents({ applicationId, componentConfigs, files, token,
|
|
|
165
168
|
}
|
|
166
169
|
catch (e) {
|
|
167
170
|
if (e instanceof axios_1.AxiosError) {
|
|
168
|
-
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;
|
|
171
|
+
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;
|
|
169
172
|
throw new Error(`Could not upload application components
|
|
170
|
-
${message}`);
|
|
173
|
+
${message !== null && message !== void 0 ? message : (_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText}`);
|
|
171
174
|
}
|
|
172
175
|
throw new Error(`Could not upload application components
|
|
173
176
|
${e.message}`);
|
|
@@ -181,6 +184,7 @@ async function fetchCurrentUser(token, superblocksBaseUrl) {
|
|
|
181
184
|
url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
|
|
182
185
|
headers: {
|
|
183
186
|
Authorization: "Bearer " + token,
|
|
187
|
+
[util_1.COMPONENT_EVENT_HEADER]: util_1.ComponentEvent.LOGIN,
|
|
184
188
|
},
|
|
185
189
|
};
|
|
186
190
|
const response = await (0, axios_1.default)(config);
|
package/dist/sdk.d.ts
CHANGED
|
@@ -3,11 +3,15 @@ export declare class SuperblocksSdk {
|
|
|
3
3
|
token: string;
|
|
4
4
|
superblocksBaseUrl: string;
|
|
5
5
|
constructor(accessToken: string, superblocksBaseUrl: string);
|
|
6
|
-
fetchApplication(applicationId
|
|
7
|
-
|
|
6
|
+
fetchApplication({ applicationId, headers, viewMode, }: {
|
|
7
|
+
applicationId: string;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
viewMode?: ViewMode;
|
|
10
|
+
}): Promise<any>;
|
|
11
|
+
fetchApplications(headers?: Record<string, string>): Promise<any>;
|
|
8
12
|
fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
|
|
9
13
|
fetchApis(): Promise<any>;
|
|
10
|
-
registerComponents(applicationId: string, componentConfigs: Record<string, any>): Promise<any>;
|
|
14
|
+
registerComponents(applicationId: string, componentConfigs: Record<string, any>, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
11
15
|
uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[]): Promise<any>;
|
|
12
16
|
fetchCurrentUser(): Promise<any>;
|
|
13
17
|
}
|
package/dist/sdk.js
CHANGED
|
@@ -9,16 +9,17 @@ class SuperblocksSdk {
|
|
|
9
9
|
this.token = accessToken;
|
|
10
10
|
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
11
11
|
}
|
|
12
|
-
async fetchApplication(applicationId, viewMode = "export-live") {
|
|
12
|
+
async fetchApplication({ applicationId, headers = {}, viewMode = "export-live", }) {
|
|
13
13
|
return (0, client_1.fetchApplication)({
|
|
14
14
|
applicationId,
|
|
15
15
|
token: this.token,
|
|
16
16
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
17
17
|
viewMode,
|
|
18
|
+
injectedHeaders: headers,
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
async fetchApplications() {
|
|
21
|
-
return (0, client_1.fetchApplications)(this.token, this.superblocksBaseUrl);
|
|
21
|
+
async fetchApplications(headers) {
|
|
22
|
+
return (0, client_1.fetchApplications)(this.token, this.superblocksBaseUrl, headers);
|
|
22
23
|
}
|
|
23
24
|
async fetchApi(apiId, viewMode = "export-live") {
|
|
24
25
|
return (0, client_1.fetchApi)(apiId, this.token, this.superblocksBaseUrl, viewMode);
|
|
@@ -26,8 +27,8 @@ class SuperblocksSdk {
|
|
|
26
27
|
async fetchApis() {
|
|
27
28
|
return (0, client_1.fetchApis)(this.token, this.superblocksBaseUrl);
|
|
28
29
|
}
|
|
29
|
-
async registerComponents(applicationId, componentConfigs) {
|
|
30
|
-
return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl);
|
|
30
|
+
async registerComponents(applicationId, componentConfigs, injectedHeaders) {
|
|
31
|
+
return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl, injectedHeaders);
|
|
31
32
|
}
|
|
32
33
|
async uploadComponents(applicationId, componentConfigs, files) {
|
|
33
34
|
return (0, client_1.uploadComponents)({
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import {
|
|
3
|
+
ComponentEvent,
|
|
3
4
|
getBucketeerUrlFromSuperblocksUrl,
|
|
4
5
|
getContentType,
|
|
6
|
+
COMPONENT_EVENT_HEADER,
|
|
5
7
|
} from "@superblocksteam/util";
|
|
6
8
|
import { getSuperblocksMonorepoConfigJson } from "@superblocksteam/util";
|
|
7
9
|
import axios, { AxiosError } from "axios";
|
|
@@ -11,6 +13,7 @@ const BASE_SERVER_URL = "api/v1";
|
|
|
11
13
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
12
14
|
|
|
13
15
|
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
16
|
+
const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
|
|
14
17
|
|
|
15
18
|
export type ViewMode = "export-deployed" | "export-latest" | "export-live";
|
|
16
19
|
|
|
@@ -25,11 +28,13 @@ export async function fetchApplication({
|
|
|
25
28
|
token,
|
|
26
29
|
superblocksBaseUrl,
|
|
27
30
|
viewMode,
|
|
31
|
+
injectedHeaders = {},
|
|
28
32
|
}: {
|
|
29
33
|
applicationId: string;
|
|
30
34
|
token: string;
|
|
31
35
|
superblocksBaseUrl: string;
|
|
32
36
|
viewMode: ViewMode;
|
|
37
|
+
injectedHeaders: Record<string, string>;
|
|
33
38
|
}) {
|
|
34
39
|
// TODO(jason) update this with commit ID once we enable fetching by commit
|
|
35
40
|
const commitId = "latest";
|
|
@@ -49,7 +54,8 @@ export async function fetchApplication({
|
|
|
49
54
|
url: componentFileURL,
|
|
50
55
|
headers: {
|
|
51
56
|
Authorization: "Bearer " + token,
|
|
52
|
-
|
|
57
|
+
[SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
|
|
58
|
+
...injectedHeaders,
|
|
53
59
|
},
|
|
54
60
|
};
|
|
55
61
|
const response = await axios(config);
|
|
@@ -64,7 +70,8 @@ export async function fetchApplication({
|
|
|
64
70
|
|
|
65
71
|
export async function fetchApplications(
|
|
66
72
|
token: string,
|
|
67
|
-
superblocksBaseUrl: string
|
|
73
|
+
superblocksBaseUrl: string,
|
|
74
|
+
injectedHeaders: Record<string, string> = {}
|
|
68
75
|
) {
|
|
69
76
|
try {
|
|
70
77
|
const config = {
|
|
@@ -72,6 +79,7 @@ export async function fetchApplications(
|
|
|
72
79
|
url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
|
|
73
80
|
headers: {
|
|
74
81
|
Authorization: "Bearer " + token,
|
|
82
|
+
...injectedHeaders,
|
|
75
83
|
},
|
|
76
84
|
};
|
|
77
85
|
const response = await axios(config);
|
|
@@ -128,7 +136,8 @@ export async function registerComponents(
|
|
|
128
136
|
applicationId: string,
|
|
129
137
|
componentConfigs: Record<string, any>,
|
|
130
138
|
token: string,
|
|
131
|
-
superblocksBaseUrl: string
|
|
139
|
+
superblocksBaseUrl: string,
|
|
140
|
+
injectedHeaders?: Record<string, string>
|
|
132
141
|
) {
|
|
133
142
|
try {
|
|
134
143
|
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
@@ -141,6 +150,7 @@ export async function registerComponents(
|
|
|
141
150
|
headers: {
|
|
142
151
|
Authorization: "Bearer " + token,
|
|
143
152
|
[CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
|
|
153
|
+
...injectedHeaders,
|
|
144
154
|
},
|
|
145
155
|
data: { components: componentConfigs },
|
|
146
156
|
};
|
|
@@ -148,12 +158,21 @@ export async function registerComponents(
|
|
|
148
158
|
return response.data;
|
|
149
159
|
} catch (e: any) {
|
|
150
160
|
if (e instanceof AxiosError) {
|
|
151
|
-
const message =
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
const message: string =
|
|
162
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
163
|
+
JSON.stringify(e.response?.data) ??
|
|
164
|
+
e.response?.statusText;
|
|
165
|
+
throw new Error(
|
|
166
|
+
`Could not register application components ${
|
|
167
|
+
message ? "\n" + message : ""
|
|
168
|
+
}`
|
|
169
|
+
);
|
|
154
170
|
}
|
|
155
|
-
throw new Error(
|
|
156
|
-
${
|
|
171
|
+
throw new Error(
|
|
172
|
+
`Could not register application components ${
|
|
173
|
+
e.message ? "\n" + (e as Error).message : ""
|
|
174
|
+
}`
|
|
175
|
+
);
|
|
157
176
|
}
|
|
158
177
|
}
|
|
159
178
|
|
|
@@ -217,7 +236,8 @@ export async function uploadComponents({
|
|
|
217
236
|
headers: {
|
|
218
237
|
Authorization: "Bearer " + token,
|
|
219
238
|
[CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
|
|
220
|
-
|
|
239
|
+
[COMPONENT_EVENT_HEADER]: ComponentEvent.UPLOAD,
|
|
240
|
+
[SUPERBLOCKS_URL_HEADER]: superblocksBaseUrl,
|
|
221
241
|
...formHeaders,
|
|
222
242
|
},
|
|
223
243
|
};
|
|
@@ -227,9 +247,10 @@ export async function uploadComponents({
|
|
|
227
247
|
return response.data;
|
|
228
248
|
} catch (e: any) {
|
|
229
249
|
if (e instanceof AxiosError) {
|
|
230
|
-
const message =
|
|
250
|
+
const message =
|
|
251
|
+
(e.response?.data?.responseMeta?.message as string) ?? e.response?.data;
|
|
231
252
|
throw new Error(`Could not upload application components
|
|
232
|
-
${message}`);
|
|
253
|
+
${message ?? e.response?.statusText}`);
|
|
233
254
|
}
|
|
234
255
|
throw new Error(`Could not upload application components
|
|
235
256
|
${e.message as string}`);
|
|
@@ -246,6 +267,7 @@ export async function fetchCurrentUser(
|
|
|
246
267
|
url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
|
|
247
268
|
headers: {
|
|
248
269
|
Authorization: "Bearer " + token,
|
|
270
|
+
[COMPONENT_EVENT_HEADER]: ComponentEvent.LOGIN,
|
|
249
271
|
},
|
|
250
272
|
};
|
|
251
273
|
const response = await axios(config);
|
package/src/sdk.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fetchApi,
|
|
3
3
|
fetchApis,
|
|
4
|
-
fetchApplication,
|
|
4
|
+
fetchApplication as fetchApplicationClient,
|
|
5
5
|
fetchApplications,
|
|
6
6
|
registerComponents,
|
|
7
7
|
uploadComponents,
|
|
@@ -18,20 +18,26 @@ export class SuperblocksSdk {
|
|
|
18
18
|
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
async fetchApplication(
|
|
22
|
-
applicationId
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
async fetchApplication({
|
|
22
|
+
applicationId,
|
|
23
|
+
headers = {},
|
|
24
|
+
viewMode = "export-live",
|
|
25
|
+
}: {
|
|
26
|
+
applicationId: string;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
viewMode?: ViewMode;
|
|
29
|
+
}) {
|
|
30
|
+
return fetchApplicationClient({
|
|
26
31
|
applicationId,
|
|
27
32
|
token: this.token,
|
|
28
33
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
29
34
|
viewMode,
|
|
35
|
+
injectedHeaders: headers,
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
async fetchApplications() {
|
|
34
|
-
return fetchApplications(this.token, this.superblocksBaseUrl);
|
|
39
|
+
async fetchApplications(headers?: Record<string, string>) {
|
|
40
|
+
return fetchApplications(this.token, this.superblocksBaseUrl, headers);
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
async fetchApi(apiId: string, viewMode: ViewMode = "export-live") {
|
|
@@ -44,13 +50,15 @@ export class SuperblocksSdk {
|
|
|
44
50
|
|
|
45
51
|
async registerComponents(
|
|
46
52
|
applicationId: string,
|
|
47
|
-
componentConfigs: Record<string, any
|
|
53
|
+
componentConfigs: Record<string, any>,
|
|
54
|
+
injectedHeaders?: Record<string, string>
|
|
48
55
|
) {
|
|
49
56
|
return registerComponents(
|
|
50
57
|
applicationId,
|
|
51
58
|
componentConfigs,
|
|
52
59
|
this.token,
|
|
53
|
-
this.superblocksBaseUrl
|
|
60
|
+
this.superblocksBaseUrl,
|
|
61
|
+
injectedHeaders
|
|
54
62
|
);
|
|
55
63
|
}
|
|
56
64
|
|