@superblocksteam/sdk 0.0.18 → 0.0.20

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 CHANGED
@@ -4,7 +4,12 @@ export interface UploadFile {
4
4
  filename: string;
5
5
  ContentType: string;
6
6
  }
7
- export declare function fetchApplication(applicationId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
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 = "X-Superblocks-CLI-Version";
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
- const url = `/api/v2/applications/${applicationId}?viewMode=${viewMode}`;
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: new URL(url, superblocksBaseUrl).toString(),
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.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) {
@@ -115,6 +121,7 @@ ${e.message}`);
115
121
  exports.registerComponents = registerComponents;
116
122
  async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }) {
117
123
  var _a, _b, _c;
124
+ superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
118
125
  const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
119
126
  // parse files to source and bundled files based on path
120
127
  const uploadFiles = files.map((file, ind) => {
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)(applicationId, this.token, this.superblocksBaseUrl, viewMode);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Superblocks JS SDK",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
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 = "X-Superblocks-CLI-Version";
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: string,
25
- token: string,
26
- superblocksBaseUrl: string,
27
- viewMode: ViewMode
28
- ) {
29
- const url = `/api/v2/applications/${applicationId}?viewMode=${viewMode}`;
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: new URL(url, superblocksBaseUrl).toString(),
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.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`);
@@ -153,6 +170,7 @@ export async function uploadComponents({
153
170
  token: string;
154
171
  superblocksBaseUrl: string;
155
172
  }) {
173
+ superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
156
174
  const bucketeerBaseUrl =
157
175
  getBucketeerUrlFromSuperblocksUrl(superblocksBaseUrl);
158
176
  // parse files to source and bundled files based on path
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() {