@superblocksteam/sdk 0.0.13 → 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 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
- const config = {
9
- method: "get",
10
- url: new URL(url, superblocksBaseUrl).toString(),
11
- headers: {
12
- Authorization: "Bearer " + token,
13
- },
14
- };
15
- const response = await (0, axios_1.default)(config);
16
- if (response.status !== 200) {
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
- const config = {
24
- method: "get",
25
- url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
26
- headers: {
27
- Authorization: "Bearer " + token,
28
- },
29
- };
30
- const response = await (0, axios_1.default)(config);
31
- if (response.status !== 200) {
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
- const config = {
39
- method: "get",
40
- url: new URL(`/api/v3/apis/${apiId}?viewMode=${viewMode}`, superblocksBaseUrl).toString(),
41
- headers: {
42
- Authorization: "Bearer " + token,
43
- },
44
- };
45
- const response = await (0, axios_1.default)(config);
46
- if (response.status !== 200) {
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
- const config = {
54
- method: "get",
55
- url: new URL(`/api/v3/apis`, superblocksBaseUrl).toString(),
56
- headers: {
57
- Authorization: "Bearer " + token,
58
- },
59
- };
60
- const response = await (0, axios_1.default)(config);
61
- if (response.status !== 200) {
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
- console.error(config.url);
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
- console.error(config.url);
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
- const config = {
113
- method: "get",
114
- url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
115
- headers: {
116
- Authorization: "Bearer " + token,
117
- },
118
- };
119
- const response = await (0, axios_1.default)(config);
120
- if (response.status !== 200) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Superblocks JS SDK",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
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
- const config = {
15
- method: "get",
16
- url: new URL(url, superblocksBaseUrl).toString(),
17
- headers: {
18
- Authorization: "Bearer " + token,
19
- },
20
- };
21
-
22
- const response = await axios(config);
23
- if (response.status !== 200) {
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
- const config = {
35
- method: "get",
36
- url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
37
- headers: {
38
- Authorization: "Bearer " + token,
39
- },
40
- };
41
-
42
- const response = await axios(config);
43
- if (response.status !== 200) {
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
- const config = {
57
- method: "get",
58
- url: new URL(
59
- `/api/v3/apis/${apiId}?viewMode=${viewMode}`,
60
- superblocksBaseUrl
61
- ).toString(),
62
- headers: {
63
- Authorization: "Bearer " + token,
64
- },
65
- };
66
-
67
- const response = await axios(config);
68
- if (response.status !== 200) {
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
- const config = {
77
- method: "get",
78
- url: new URL(`/api/v3/apis`, superblocksBaseUrl).toString(),
79
- headers: {
80
- Authorization: "Bearer " + token,
81
- },
82
- };
83
-
84
- const response = await axios(config);
85
- if (response.status !== 200) {
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
- console.error(config.url);
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
- console.error(config.url);
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
- const config = {
160
- method: "get",
161
- url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
162
- headers: {
163
- Authorization: "Bearer " + token,
164
- },
165
- };
166
-
167
- const response = await axios(config);
168
- if (response.status !== 200) {
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
  }