@superblocksteam/sdk 0.0.14 → 0.0.15
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.js +84 -76
- package/package.json +1 -1
- package/src/client.ts +88 -99
package/dist/client.js
CHANGED
|
@@ -5,121 +5,129 @@ const axios_1 = require("axios");
|
|
|
5
5
|
const BASE_SERVER_URL = "api/v1";
|
|
6
6
|
async function fetchApplication(applicationId, token, superblocksBaseUrl, viewMode) {
|
|
7
7
|
const url = `/api/v2/applications/${applicationId}?viewMode=${viewMode}`;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
try {
|
|
9
|
+
const config = {
|
|
10
|
+
method: "get",
|
|
11
|
+
url: new URL(url, superblocksBaseUrl).toString(),
|
|
12
|
+
headers: {
|
|
13
|
+
Authorization: "Bearer " + token,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const response = await (0, axios_1.default)(config);
|
|
17
|
+
return response.data.data;
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
if (e.status === 404) {
|
|
21
|
+
throw new Error(`Application ${applicationId} was not found`);
|
|
22
|
+
}
|
|
17
23
|
throw new Error("Could not fetch application");
|
|
18
24
|
}
|
|
19
|
-
return response.data.data;
|
|
20
25
|
}
|
|
21
26
|
exports.fetchApplication = fetchApplication;
|
|
22
27
|
async function fetchApplications(token, superblocksBaseUrl) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
try {
|
|
29
|
+
const config = {
|
|
30
|
+
method: "get",
|
|
31
|
+
url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: "Bearer " + token,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const response = await (0, axios_1.default)(config);
|
|
37
|
+
return response.data.data.applications;
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
32
40
|
throw new Error("Could not fetch applications");
|
|
33
41
|
}
|
|
34
|
-
return response.data.data.applications;
|
|
35
42
|
}
|
|
36
43
|
exports.fetchApplications = fetchApplications;
|
|
37
44
|
async function fetchApi(apiId, token, superblocksBaseUrl, viewMode) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
try {
|
|
46
|
+
const config = {
|
|
47
|
+
method: "get",
|
|
48
|
+
url: new URL(`/api/v3/apis/${apiId}?viewMode=${viewMode}`, superblocksBaseUrl).toString(),
|
|
49
|
+
headers: {
|
|
50
|
+
Authorization: "Bearer " + token,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
const response = await (0, axios_1.default)(config);
|
|
54
|
+
return response.data.data;
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (e.status === 404) {
|
|
58
|
+
throw new Error(`Api ${apiId} was not found`);
|
|
59
|
+
}
|
|
47
60
|
throw new Error("Could not fetch api");
|
|
48
61
|
}
|
|
49
|
-
return response.data.data;
|
|
50
62
|
}
|
|
51
63
|
exports.fetchApi = fetchApi;
|
|
52
64
|
async function fetchApis(token, superblocksBaseUrl) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
try {
|
|
66
|
+
const config = {
|
|
67
|
+
method: "get",
|
|
68
|
+
url: new URL(`/api/v3/apis`, superblocksBaseUrl).toString(),
|
|
69
|
+
headers: {
|
|
70
|
+
Authorization: "Bearer " + token,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const response = await (0, axios_1.default)(config);
|
|
74
|
+
return response.data.data;
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
62
77
|
throw new Error("Could not fetch apis");
|
|
63
78
|
}
|
|
64
|
-
return response.data.data;
|
|
65
79
|
}
|
|
66
80
|
exports.fetchApis = fetchApis;
|
|
67
81
|
async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl) {
|
|
68
|
-
const config = {
|
|
69
|
-
method: "put",
|
|
70
|
-
url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}/components`, superblocksBaseUrl).toString(),
|
|
71
|
-
headers: {
|
|
72
|
-
Authorization: "Bearer " + token,
|
|
73
|
-
},
|
|
74
|
-
data: { components: componentConfigs },
|
|
75
|
-
};
|
|
76
82
|
try {
|
|
83
|
+
const config = {
|
|
84
|
+
method: "put",
|
|
85
|
+
url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}/components`, superblocksBaseUrl).toString(),
|
|
86
|
+
headers: {
|
|
87
|
+
Authorization: "Bearer " + token,
|
|
88
|
+
},
|
|
89
|
+
data: { components: componentConfigs },
|
|
90
|
+
};
|
|
77
91
|
const response = await (0, axios_1.default)(config);
|
|
78
|
-
if (response.status !== 200) {
|
|
79
|
-
throw new Error("Could not register application components");
|
|
80
|
-
}
|
|
81
92
|
return response.data;
|
|
82
93
|
}
|
|
83
94
|
catch (e) {
|
|
84
|
-
|
|
85
|
-
throw e;
|
|
95
|
+
throw new Error("Could not register application components");
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
exports.registerComponents = registerComponents;
|
|
89
99
|
async function uploadComponents(applicationId, componentConfigs, files, token, superblocksBaseUrl) {
|
|
90
|
-
const config = {
|
|
91
|
-
method: "post",
|
|
92
|
-
url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}/publish`, superblocksBaseUrl).toString(),
|
|
93
|
-
headers: {
|
|
94
|
-
Authorization: "Bearer " + token,
|
|
95
|
-
},
|
|
96
|
-
data: { components: componentConfigs, files },
|
|
97
|
-
};
|
|
98
100
|
try {
|
|
101
|
+
const config = {
|
|
102
|
+
method: "post",
|
|
103
|
+
url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}/publish`, superblocksBaseUrl).toString(),
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: "Bearer " + token,
|
|
106
|
+
},
|
|
107
|
+
data: { components: componentConfigs, files },
|
|
108
|
+
};
|
|
99
109
|
const response = await (0, axios_1.default)(config);
|
|
100
|
-
if (response.status !== 200) {
|
|
101
|
-
throw new Error("Could not register application components");
|
|
102
|
-
}
|
|
103
110
|
return response.data;
|
|
104
111
|
}
|
|
105
112
|
catch (e) {
|
|
106
|
-
|
|
107
|
-
throw e;
|
|
113
|
+
throw new Error("Could not upload application components");
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
exports.uploadComponents = uploadComponents;
|
|
111
117
|
async function fetchCurrentUser(token, superblocksBaseUrl) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
try {
|
|
119
|
+
const config = {
|
|
120
|
+
method: "get",
|
|
121
|
+
url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
|
|
122
|
+
headers: {
|
|
123
|
+
Authorization: "Bearer " + token,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
const response = await (0, axios_1.default)(config);
|
|
127
|
+
return response.data.data.user;
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
121
130
|
throw new Error("Could not fetch current user");
|
|
122
131
|
}
|
|
123
|
-
return response.data.data.user;
|
|
124
132
|
}
|
|
125
133
|
exports.fetchCurrentUser = fetchCurrentUser;
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -11,40 +11,41 @@ export async function fetchApplication(
|
|
|
11
11
|
viewMode: ViewMode
|
|
12
12
|
) {
|
|
13
13
|
const url = `/api/v2/applications/${applicationId}?viewMode=${viewMode}`;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
try {
|
|
15
|
+
const config = {
|
|
16
|
+
method: "get",
|
|
17
|
+
url: new URL(url, superblocksBaseUrl).toString(),
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: "Bearer " + token,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
const response = await axios(config);
|
|
23
|
+
return response.data.data;
|
|
24
|
+
} catch (e: any) {
|
|
25
|
+
if (e.status === 404) {
|
|
26
|
+
throw new Error(`Application ${applicationId} was not found`);
|
|
27
|
+
}
|
|
24
28
|
throw new Error("Could not fetch application");
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
return response.data.data;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export async function fetchApplications(
|
|
31
33
|
token: string,
|
|
32
34
|
superblocksBaseUrl: string
|
|
33
35
|
) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
try {
|
|
37
|
+
const config = {
|
|
38
|
+
method: "get",
|
|
39
|
+
url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: "Bearer " + token,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const response = await axios(config);
|
|
45
|
+
return response.data.data.applications;
|
|
46
|
+
} catch (e) {
|
|
44
47
|
throw new Error("Could not fetch applications");
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
return response.data.data.applications;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export async function fetchApi(
|
|
@@ -53,40 +54,41 @@ export async function fetchApi(
|
|
|
53
54
|
superblocksBaseUrl: string,
|
|
54
55
|
viewMode: ViewMode
|
|
55
56
|
) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
try {
|
|
58
|
+
const config = {
|
|
59
|
+
method: "get",
|
|
60
|
+
url: new URL(
|
|
61
|
+
`/api/v3/apis/${apiId}?viewMode=${viewMode}`,
|
|
62
|
+
superblocksBaseUrl
|
|
63
|
+
).toString(),
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: "Bearer " + token,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
const response = await axios(config);
|
|
69
|
+
return response.data.data;
|
|
70
|
+
} catch (e: any) {
|
|
71
|
+
if (e.status === 404) {
|
|
72
|
+
throw new Error(`Api ${apiId} was not found`);
|
|
73
|
+
}
|
|
69
74
|
throw new Error("Could not fetch api");
|
|
70
75
|
}
|
|
71
|
-
|
|
72
|
-
return response.data.data;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
export async function fetchApis(token: string, superblocksBaseUrl: string) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
try {
|
|
80
|
+
const config = {
|
|
81
|
+
method: "get",
|
|
82
|
+
url: new URL(`/api/v3/apis`, superblocksBaseUrl).toString(),
|
|
83
|
+
headers: {
|
|
84
|
+
Authorization: "Bearer " + token,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
const response = await axios(config);
|
|
88
|
+
return response.data.data;
|
|
89
|
+
} catch (e) {
|
|
86
90
|
throw new Error("Could not fetch apis");
|
|
87
91
|
}
|
|
88
|
-
|
|
89
|
-
return response.data.data;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
export async function registerComponents(
|
|
@@ -95,28 +97,22 @@ export async function registerComponents(
|
|
|
95
97
|
token: string,
|
|
96
98
|
superblocksBaseUrl: string
|
|
97
99
|
) {
|
|
98
|
-
const config = {
|
|
99
|
-
method: "put",
|
|
100
|
-
url: new URL(
|
|
101
|
-
`${BASE_SERVER_URL}/public/application/${applicationId}/components`,
|
|
102
|
-
superblocksBaseUrl
|
|
103
|
-
).toString(),
|
|
104
|
-
headers: {
|
|
105
|
-
Authorization: "Bearer " + token,
|
|
106
|
-
},
|
|
107
|
-
data: { components: componentConfigs },
|
|
108
|
-
};
|
|
109
|
-
|
|
110
100
|
try {
|
|
101
|
+
const config = {
|
|
102
|
+
method: "put",
|
|
103
|
+
url: new URL(
|
|
104
|
+
`${BASE_SERVER_URL}/public/application/${applicationId}/components`,
|
|
105
|
+
superblocksBaseUrl
|
|
106
|
+
).toString(),
|
|
107
|
+
headers: {
|
|
108
|
+
Authorization: "Bearer " + token,
|
|
109
|
+
},
|
|
110
|
+
data: { components: componentConfigs },
|
|
111
|
+
};
|
|
111
112
|
const response = await axios(config);
|
|
112
|
-
if (response.status !== 200) {
|
|
113
|
-
throw new Error("Could not register application components");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
113
|
return response.data;
|
|
117
114
|
} catch (e) {
|
|
118
|
-
|
|
119
|
-
throw e;
|
|
115
|
+
throw new Error("Could not register application components");
|
|
120
116
|
}
|
|
121
117
|
}
|
|
122
118
|
|
|
@@ -127,28 +123,22 @@ export async function uploadComponents(
|
|
|
127
123
|
token: string,
|
|
128
124
|
superblocksBaseUrl: string
|
|
129
125
|
) {
|
|
130
|
-
const config = {
|
|
131
|
-
method: "post",
|
|
132
|
-
url: new URL(
|
|
133
|
-
`${BASE_SERVER_URL}/public/application/${applicationId}/publish`,
|
|
134
|
-
superblocksBaseUrl
|
|
135
|
-
).toString(),
|
|
136
|
-
headers: {
|
|
137
|
-
Authorization: "Bearer " + token,
|
|
138
|
-
},
|
|
139
|
-
data: { components: componentConfigs, files },
|
|
140
|
-
};
|
|
141
|
-
|
|
142
126
|
try {
|
|
127
|
+
const config = {
|
|
128
|
+
method: "post",
|
|
129
|
+
url: new URL(
|
|
130
|
+
`${BASE_SERVER_URL}/public/application/${applicationId}/publish`,
|
|
131
|
+
superblocksBaseUrl
|
|
132
|
+
).toString(),
|
|
133
|
+
headers: {
|
|
134
|
+
Authorization: "Bearer " + token,
|
|
135
|
+
},
|
|
136
|
+
data: { components: componentConfigs, files },
|
|
137
|
+
};
|
|
143
138
|
const response = await axios(config);
|
|
144
|
-
if (response.status !== 200) {
|
|
145
|
-
throw new Error("Could not register application components");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
139
|
return response.data;
|
|
149
140
|
} catch (e) {
|
|
150
|
-
|
|
151
|
-
throw e;
|
|
141
|
+
throw new Error("Could not upload application components");
|
|
152
142
|
}
|
|
153
143
|
}
|
|
154
144
|
|
|
@@ -156,18 +146,17 @@ export async function fetchCurrentUser(
|
|
|
156
146
|
token: string,
|
|
157
147
|
superblocksBaseUrl: string
|
|
158
148
|
) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
149
|
+
try {
|
|
150
|
+
const config = {
|
|
151
|
+
method: "get",
|
|
152
|
+
url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
|
|
153
|
+
headers: {
|
|
154
|
+
Authorization: "Bearer " + token,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
const response = await axios(config);
|
|
158
|
+
return response.data.data.user;
|
|
159
|
+
} catch (e) {
|
|
169
160
|
throw new Error("Could not fetch current user");
|
|
170
161
|
}
|
|
171
|
-
|
|
172
|
-
return response.data.data.user;
|
|
173
162
|
}
|