@superblocksteam/sdk 1.0.2 → 1.1.1

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
@@ -9,15 +9,34 @@ export interface ApplicationWrapper {
9
9
  page: Record<string, any>;
10
10
  apis: Record<string, any>[];
11
11
  }
12
- export declare function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
12
+ export type PushApplicationWithCommitConfig = ApplicationWrapper & {
13
+ commitId: string;
14
+ commitMessage: string;
15
+ };
16
+ export type Branches = {
17
+ branches: Branch[];
18
+ };
19
+ export type Branch = {
20
+ name: string;
21
+ isDefault: boolean;
22
+ };
23
+ export declare function fetchApplication({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
13
24
  applicationId: string;
25
+ branch: string;
14
26
  token: string;
15
27
  superblocksBaseUrl: string;
16
28
  viewMode: ViewMode;
17
29
  injectedHeaders: Record<string, string>;
18
30
  }): Promise<ApplicationWrapper | undefined>;
19
- export declare function fetchApplicationWithComponents({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
31
+ export declare function fetchApplicationBranches({ applicationId, token, superblocksBaseUrl, injectedHeaders, }: {
32
+ applicationId: string;
33
+ token: string;
34
+ superblocksBaseUrl: string;
35
+ injectedHeaders: Record<string, string>;
36
+ }): Promise<Branches | undefined>;
37
+ export declare function fetchApplicationWithComponents({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
20
38
  applicationId: string;
39
+ branch: string;
21
40
  token: string;
22
41
  superblocksBaseUrl: string;
23
42
  viewMode: ViewMode;
@@ -28,12 +47,21 @@ export declare function fetchApplicationWithComponents({ applicationId, token, s
28
47
  export declare function fetchApplications(token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
29
48
  export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
30
49
  export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
31
- export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
32
- export declare function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }: {
50
+ export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string, branch: string | null, injectedHeaders?: Record<string, string>): Promise<any>;
51
+ export declare function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }: {
33
52
  applicationId: string;
34
53
  componentConfigs: Record<string, any>;
35
54
  files: string[];
36
55
  token: string;
37
56
  superblocksBaseUrl: string;
57
+ branch: string | null;
38
58
  }): Promise<any>;
39
59
  export declare function fetchCurrentUser(token: string, superblocksBaseUrl: string): Promise<any>;
60
+ export declare function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
61
+ applicationId: string;
62
+ token: string;
63
+ superblocksBaseUrl: string;
64
+ branch: string;
65
+ injectedHeaders: Record<string, string>;
66
+ applicationConfig: ApplicationWrapper;
67
+ }): Promise<ApplicationWrapper | undefined>;
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplication = void 0;
3
+ exports.pushApplication = exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplicationBranches = exports.fetchApplication = void 0;
4
4
  const fs = require("fs");
5
5
  const util_1 = require("@superblocksteam/util");
6
6
  const axios_1 = require("axios");
@@ -11,9 +11,9 @@ const BASE_BUCKETEER_URL = "api/v1";
11
11
  const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
12
12
  const CLI_VERSION_HEADER = "x-superblocks-cli-version";
13
13
  const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
14
- async function fetchApplication({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
14
+ async function fetchApplication({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
15
15
  var _a, _b;
16
- const serverURL = new URL(`api/v2/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
16
+ const serverURL = new URL(`api/v2/applications/${applicationId}/branches/${branch}?viewMode=${viewMode}`, superblocksBaseUrl);
17
17
  let serverResponse;
18
18
  try {
19
19
  const config = {
@@ -35,10 +35,35 @@ async function fetchApplication({ applicationId, token, superblocksBaseUrl, view
35
35
  return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
36
36
  }
37
37
  exports.fetchApplication = fetchApplication;
38
- async function fetchApplicationWithComponents({ applicationId, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
38
+ async function fetchApplicationBranches({ applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
39
+ var _a, _b;
40
+ const serverURL = new URL(`api/v2/applications/${applicationId}/branches`, superblocksBaseUrl);
41
+ let serverResponse;
42
+ try {
43
+ const config = {
44
+ method: "get",
45
+ url: serverURL.toString(),
46
+ headers: {
47
+ Authorization: "Bearer " + token,
48
+ ...injectedHeaders,
49
+ },
50
+ };
51
+ serverResponse = await (0, axios_1.default)(config);
52
+ }
53
+ catch (e) {
54
+ if (axios_1.default.isAxiosError(e) && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
55
+ throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
56
+ }
57
+ throw new Error(`Could not fetch application branches: ${e.message}`);
58
+ }
59
+ return (_b = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _b === void 0 ? void 0 : _b.data;
60
+ }
61
+ exports.fetchApplicationBranches = fetchApplicationBranches;
62
+ async function fetchApplicationWithComponents({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
39
63
  var _a, _b, _c;
40
64
  const applicationWrapper = await fetchApplication({
41
65
  applicationId,
66
+ branch,
42
67
  token,
43
68
  superblocksBaseUrl,
44
69
  viewMode,
@@ -137,13 +162,14 @@ async function fetchApis(token, superblocksBaseUrl) {
137
162
  }
138
163
  }
139
164
  exports.fetchApis = fetchApis;
140
- async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl, injectedHeaders) {
165
+ async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
141
166
  var _a, _b, _c, _d, _e, _f, _g;
142
167
  try {
143
168
  const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
169
+ const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
144
170
  const config = {
145
171
  method: "put",
146
- url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}/components`, superblocksBaseUrl).toString(),
172
+ url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
147
173
  headers: {
148
174
  Authorization: "Bearer " + token,
149
175
  [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
@@ -163,8 +189,8 @@ async function registerComponents(applicationId, componentConfigs, token, superb
163
189
  }
164
190
  }
165
191
  exports.registerComponents = registerComponents;
166
- async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }) {
167
- var _a, _b, _c, _d, _e, _f, _g, _h;
192
+ async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
193
+ var _a, _b, _c, _d, _e, _f;
168
194
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
169
195
  const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
170
196
  // parse files to source and bundled files based on path
@@ -184,6 +210,7 @@ async function uploadComponents({ applicationId, componentConfigs, files, token,
184
210
  const srcFiles = uploadFiles.filter((uploadFile) => !uploadFile.filename.startsWith("dist/"));
185
211
  const formatJSON = JSON.stringify({
186
212
  applicationId,
213
+ branch,
187
214
  registeredComponents: componentConfigs,
188
215
  srcFiles,
189
216
  buildFiles,
@@ -227,8 +254,7 @@ You can reduce your component bundle size by uploading static assets to a separa
227
254
  else {
228
255
  let message;
229
256
  if (e instanceof axios_1.AxiosError) {
230
- message =
231
- (_g = (_e = (_d = (_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.responseMeta) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : (_f = e.response) === null || _f === void 0 ? void 0 : _f.data) !== null && _g !== void 0 ? _g : (_h = e.response) === null || _h === void 0 ? void 0 : _h.statusText;
257
+ message = ((_d = (_c = (_b = e.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.responseMeta) === null || _d === void 0 ? void 0 : _d.message) || ((_e = e.response) === null || _e === void 0 ? void 0 : _e.data) || ((_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText);
232
258
  }
233
259
  else {
234
260
  message = e.message;
@@ -259,3 +285,31 @@ async function fetchCurrentUser(token, superblocksBaseUrl) {
259
285
  }
260
286
  }
261
287
  exports.fetchCurrentUser = fetchCurrentUser;
288
+ async function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
289
+ var _a, _b, _c, _d, _e, _f, _g, _h;
290
+ const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
291
+ const serverURL = new URL(`${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
292
+ let serverResponse;
293
+ try {
294
+ const config = {
295
+ method: "post",
296
+ url: serverURL.toString(),
297
+ headers: {
298
+ Authorization: "Bearer " + token,
299
+ [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
300
+ ...injectedHeaders,
301
+ },
302
+ data: applicationConfig,
303
+ };
304
+ serverResponse = await (0, axios_1.default)(config);
305
+ }
306
+ catch (e) {
307
+ if (axios_1.default.isAxiosError(e)) {
308
+ 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;
309
+ throw new Error(`Could not push application ${message ? "\n" + message : ""}`);
310
+ }
311
+ throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
312
+ }
313
+ return (_h = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _h === void 0 ? void 0 : _h.data;
314
+ }
315
+ exports.pushApplication = pushApplication;
package/dist/sdk.d.ts CHANGED
@@ -1,15 +1,18 @@
1
- import { ViewMode } from "./client";
1
+ import { ViewMode, PushApplicationWithCommitConfig } from "./client";
2
2
  export declare class SuperblocksSdk {
3
3
  token: string;
4
4
  superblocksBaseUrl: string;
5
5
  constructor(accessToken: string, superblocksBaseUrl: string);
6
- fetchApplication({ applicationId, headers, viewMode, }: {
6
+ fetchApplication({ applicationId, branch, headers, viewMode, }: {
7
7
  applicationId: string;
8
+ branch: string;
8
9
  headers?: Record<string, string>;
9
10
  viewMode?: ViewMode;
10
11
  }): Promise<import("./client").ApplicationWrapper | undefined>;
11
- fetchApplicationWithComponents({ applicationId, headers, viewMode, }: {
12
+ fetchApplicationBranches(applicationId: string, headers?: {}): Promise<import("./client").Branches | undefined>;
13
+ fetchApplicationWithComponents({ applicationId, branch, headers, viewMode, }: {
12
14
  applicationId: string;
15
+ branch: string;
13
16
  headers?: Record<string, string>;
14
17
  viewMode?: ViewMode;
15
18
  }): Promise<(import("./client").ApplicationWrapper & {
@@ -18,7 +21,13 @@ export declare class SuperblocksSdk {
18
21
  fetchApplications(headers?: Record<string, string>): Promise<any>;
19
22
  fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
20
23
  fetchApis(): Promise<any>;
21
- registerComponents(applicationId: string, componentConfigs: Record<string, any>, injectedHeaders?: Record<string, string>): Promise<any>;
22
- uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[]): Promise<any>;
24
+ registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders?: Record<string, string>): Promise<any>;
25
+ uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], branch: string | null): Promise<any>;
23
26
  fetchCurrentUser(): Promise<any>;
27
+ pushApplication({ applicationId, applicationConfig, branch, headers, }: {
28
+ applicationId: string;
29
+ applicationConfig: PushApplicationWithCommitConfig;
30
+ branch: string;
31
+ headers?: Record<string, string>;
32
+ }): Promise<import("./client").ApplicationWrapper | undefined>;
24
33
  }
package/dist/sdk.js CHANGED
@@ -9,18 +9,28 @@ class SuperblocksSdk {
9
9
  this.token = accessToken;
10
10
  this.superblocksBaseUrl = superblocksBaseUrl;
11
11
  }
12
- async fetchApplication({ applicationId, headers = {}, viewMode = "export-live", }) {
12
+ async fetchApplication({ applicationId, branch, headers = {}, viewMode = "export-live", }) {
13
13
  return (0, client_1.fetchApplication)({
14
14
  applicationId,
15
+ branch,
15
16
  token: this.token,
16
17
  superblocksBaseUrl: this.superblocksBaseUrl,
17
18
  viewMode,
18
19
  injectedHeaders: headers,
19
20
  });
20
21
  }
21
- async fetchApplicationWithComponents({ applicationId, headers = {}, viewMode = "export-live", }) {
22
+ async fetchApplicationBranches(applicationId, headers = {}) {
23
+ return (0, client_1.fetchApplicationBranches)({
24
+ applicationId,
25
+ token: this.token,
26
+ superblocksBaseUrl: this.superblocksBaseUrl,
27
+ injectedHeaders: headers,
28
+ });
29
+ }
30
+ async fetchApplicationWithComponents({ applicationId, branch, headers = {}, viewMode = "export-live", }) {
22
31
  return (0, client_1.fetchApplicationWithComponents)({
23
32
  applicationId,
33
+ branch,
24
34
  token: this.token,
25
35
  superblocksBaseUrl: this.superblocksBaseUrl,
26
36
  viewMode,
@@ -36,20 +46,31 @@ class SuperblocksSdk {
36
46
  async fetchApis() {
37
47
  return (0, client_1.fetchApis)(this.token, this.superblocksBaseUrl);
38
48
  }
39
- async registerComponents(applicationId, componentConfigs, injectedHeaders) {
40
- return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl, injectedHeaders);
49
+ async registerComponents(applicationId, componentConfigs, branch, injectedHeaders) {
50
+ return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl, branch, injectedHeaders);
41
51
  }
42
- async uploadComponents(applicationId, componentConfigs, files) {
52
+ async uploadComponents(applicationId, componentConfigs, files, branch) {
43
53
  return (0, client_1.uploadComponents)({
44
54
  applicationId,
45
55
  componentConfigs,
46
56
  files,
47
57
  token: this.token,
48
58
  superblocksBaseUrl: this.superblocksBaseUrl,
59
+ branch,
49
60
  });
50
61
  }
51
62
  async fetchCurrentUser() {
52
63
  return (0, client_1.fetchCurrentUser)(this.token, this.superblocksBaseUrl);
53
64
  }
65
+ async pushApplication({ applicationId, applicationConfig, branch, headers = {}, }) {
66
+ return (0, client_1.pushApplication)({
67
+ applicationId,
68
+ token: this.token,
69
+ superblocksBaseUrl: this.superblocksBaseUrl,
70
+ branch,
71
+ injectedHeaders: headers,
72
+ applicationConfig,
73
+ });
74
+ }
54
75
  }
55
76
  exports.SuperblocksSdk = SuperblocksSdk;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Superblocks JS SDK",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -30,7 +30,7 @@
30
30
  "typescript": "^5.1.3"
31
31
  },
32
32
  "dependencies": {
33
- "@superblocksteam/util": "1.0.2",
33
+ "@superblocksteam/util": "1.1.1",
34
34
  "axios": "^1.3.5"
35
35
  },
36
36
  "homepage": "https://www.superblocks.com",
package/src/client.ts CHANGED
@@ -33,23 +33,39 @@ export interface ApplicationWrapper {
33
33
  apis: Record<string, any>[];
34
34
  }
35
35
 
36
+ export type PushApplicationWithCommitConfig = ApplicationWrapper & {
37
+ commitId: string;
38
+ commitMessage: string;
39
+ };
40
+
41
+ export type Branches = {
42
+ branches: Branch[];
43
+ };
44
+
45
+ export type Branch = {
46
+ name: string;
47
+ isDefault: boolean;
48
+ };
49
+
36
50
  type ResponseWithMeta<T> = { responseMeta: unknown; data: T };
37
51
 
38
52
  export async function fetchApplication({
39
53
  applicationId,
54
+ branch,
40
55
  token,
41
56
  superblocksBaseUrl,
42
57
  viewMode,
43
58
  injectedHeaders = {},
44
59
  }: {
45
60
  applicationId: string;
61
+ branch: string;
46
62
  token: string;
47
63
  superblocksBaseUrl: string;
48
64
  viewMode: ViewMode;
49
65
  injectedHeaders: Record<string, string>;
50
66
  }): Promise<ApplicationWrapper | undefined> {
51
67
  const serverURL = new URL(
52
- `api/v2/applications/${applicationId}?viewMode=${viewMode}`,
68
+ `api/v2/applications/${applicationId}/branches/${branch}?viewMode=${viewMode}`,
53
69
  superblocksBaseUrl
54
70
  );
55
71
  let serverResponse;
@@ -74,14 +90,53 @@ export async function fetchApplication({
74
90
  return serverResponse?.data?.data;
75
91
  }
76
92
 
93
+ export async function fetchApplicationBranches({
94
+ applicationId,
95
+ token,
96
+ superblocksBaseUrl,
97
+ injectedHeaders = {},
98
+ }: {
99
+ applicationId: string;
100
+ token: string;
101
+ superblocksBaseUrl: string;
102
+ injectedHeaders: Record<string, string>;
103
+ }): Promise<Branches | undefined> {
104
+ const serverURL = new URL(
105
+ `api/v2/applications/${applicationId}/branches`,
106
+ superblocksBaseUrl
107
+ );
108
+ let serverResponse;
109
+
110
+ try {
111
+ const config: AxiosRequestConfig = {
112
+ method: "get",
113
+ url: serverURL.toString(),
114
+ headers: {
115
+ Authorization: "Bearer " + token,
116
+ ...injectedHeaders,
117
+ },
118
+ };
119
+ serverResponse = await axios<ResponseWithMeta<Branches>>(config);
120
+ } catch (e: any) {
121
+ if (axios.isAxiosError(e) && e.response?.status === 404) {
122
+ throw new NotFoundError(`Application ${applicationId} was not found`);
123
+ }
124
+ throw new Error(`Could not fetch application branches: ${e.message}`);
125
+ }
126
+
127
+ return serverResponse?.data?.data;
128
+ }
129
+
77
130
  export async function fetchApplicationWithComponents({
78
131
  applicationId,
132
+ branch,
79
133
  token,
80
134
  superblocksBaseUrl,
81
135
  viewMode,
82
136
  injectedHeaders = {},
83
137
  }: {
84
138
  applicationId: string;
139
+ branch: string;
85
140
  token: string;
86
141
  superblocksBaseUrl: string;
87
142
  viewMode: ViewMode;
@@ -89,6 +144,7 @@ export async function fetchApplicationWithComponents({
89
144
  }): Promise<(ApplicationWrapper & { componentFiles: any }) | undefined> {
90
145
  const applicationWrapper = await fetchApplication({
91
146
  applicationId,
147
+ branch,
92
148
  token,
93
149
  superblocksBaseUrl,
94
150
  viewMode,
@@ -208,14 +264,16 @@ export async function registerComponents(
208
264
  componentConfigs: Record<string, any>,
209
265
  token: string,
210
266
  superblocksBaseUrl: string,
267
+ branch: string | null,
211
268
  injectedHeaders?: Record<string, string>
212
269
  ) {
213
270
  try {
214
271
  const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
272
+ const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
215
273
  const config: AxiosRequestConfig = {
216
274
  method: "put",
217
275
  url: new URL(
218
- `${BASE_SERVER_URL}/public/application/${applicationId}/components`,
276
+ `${BASE_SERVER_URL}/public/application/${applicationId}${branchPath}/components`,
219
277
  superblocksBaseUrl
220
278
  ).toString(),
221
279
  headers: {
@@ -253,12 +311,14 @@ export async function uploadComponents({
253
311
  files,
254
312
  token,
255
313
  superblocksBaseUrl,
314
+ branch,
256
315
  }: {
257
316
  applicationId: string;
258
317
  componentConfigs: Record<string, any>;
259
318
  files: string[];
260
319
  token: string;
261
320
  superblocksBaseUrl: string;
321
+ branch: string | null;
262
322
  }) {
263
323
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
264
324
  const bucketeerBaseUrl =
@@ -286,6 +346,7 @@ export async function uploadComponents({
286
346
 
287
347
  const formatJSON = JSON.stringify({
288
348
  applicationId,
349
+ branch,
289
350
  registeredComponents: componentConfigs,
290
351
  srcFiles,
291
352
  buildFiles,
@@ -335,12 +396,11 @@ You can reduce your component bundle size by uploading static assets to a separa
335
396
  `Could not upload application components, file size limit exceeded`
336
397
  );
337
398
  } else {
338
- let message: any;
399
+ let message: string;
339
400
  if (e instanceof AxiosError) {
340
- message =
341
- e.response?.data?.responseMeta?.message ?? e.response?.data ?? e.response?.statusText;
401
+ message = e.response?.data?.responseMeta?.message || e.response?.data || e.response?.statusText;
342
402
  } else {
343
- message = e.message;
403
+ message = e.message as string;
344
404
  }
345
405
  if (typeof message !== "string") {
346
406
  message = JSON.stringify(message, null, 2);
@@ -369,3 +429,60 @@ export async function fetchCurrentUser(
369
429
  throw new Error("Could not fetch current user");
370
430
  }
371
431
  }
432
+
433
+ export async function pushApplication({
434
+ applicationId,
435
+ token,
436
+ superblocksBaseUrl,
437
+ applicationConfig,
438
+ branch,
439
+ injectedHeaders = {},
440
+ }: {
441
+ applicationId: string;
442
+ token: string;
443
+ superblocksBaseUrl: string;
444
+ branch: string;
445
+ injectedHeaders: Record<string, string>;
446
+ applicationConfig: ApplicationWrapper;
447
+ }): Promise<ApplicationWrapper | undefined> {
448
+ const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
449
+ const serverURL = new URL(
450
+ `${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(
451
+ branch
452
+ )}/push`,
453
+ superblocksBaseUrl
454
+ );
455
+ let serverResponse;
456
+
457
+ try {
458
+ const config: AxiosRequestConfig = {
459
+ method: "post",
460
+ url: serverURL.toString(),
461
+ headers: {
462
+ Authorization: "Bearer " + token,
463
+ [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
464
+ ...injectedHeaders,
465
+ },
466
+ data: applicationConfig,
467
+ };
468
+ serverResponse = await axios<ResponseWithMeta<ApplicationWrapper>>(config);
469
+ } catch (e) {
470
+ if (axios.isAxiosError(e)) {
471
+ const message: string =
472
+ (e.response?.data?.responseMeta?.message as string) ??
473
+ JSON.stringify(e.response?.data) ??
474
+ e.response?.statusText;
475
+
476
+ throw new Error(
477
+ `Could not push application ${message ? "\n" + message : ""}`
478
+ );
479
+ }
480
+ throw new Error(
481
+ `Could not push application ${
482
+ (e as Error).message ? "\n" + (e as Error).message : ""
483
+ }`
484
+ );
485
+ }
486
+
487
+ return serverResponse?.data?.data;
488
+ }
package/src/sdk.ts CHANGED
@@ -8,6 +8,9 @@ import {
8
8
  uploadComponents,
9
9
  fetchCurrentUser,
10
10
  ViewMode,
11
+ pushApplication,
12
+ PushApplicationWithCommitConfig,
13
+ fetchApplicationBranches,
11
14
  } from "./client";
12
15
 
13
16
  export class SuperblocksSdk {
@@ -21,15 +24,18 @@ export class SuperblocksSdk {
21
24
 
22
25
  async fetchApplication({
23
26
  applicationId,
27
+ branch,
24
28
  headers = {},
25
29
  viewMode = "export-live",
26
30
  }: {
27
31
  applicationId: string;
32
+ branch: string;
28
33
  headers?: Record<string, string>;
29
34
  viewMode?: ViewMode;
30
35
  }) {
31
36
  return fetchApplication({
32
37
  applicationId,
38
+ branch,
33
39
  token: this.token,
34
40
  superblocksBaseUrl: this.superblocksBaseUrl,
35
41
  viewMode,
@@ -37,17 +43,29 @@ export class SuperblocksSdk {
37
43
  });
38
44
  }
39
45
 
46
+ async fetchApplicationBranches(applicationId: string, headers = {}) {
47
+ return fetchApplicationBranches({
48
+ applicationId,
49
+ token: this.token,
50
+ superblocksBaseUrl: this.superblocksBaseUrl,
51
+ injectedHeaders: headers,
52
+ });
53
+ }
54
+
40
55
  async fetchApplicationWithComponents({
41
56
  applicationId,
57
+ branch,
42
58
  headers = {},
43
59
  viewMode = "export-live",
44
60
  }: {
45
61
  applicationId: string;
62
+ branch: string;
46
63
  headers?: Record<string, string>;
47
64
  viewMode?: ViewMode;
48
65
  }) {
49
66
  return fetchApplicationWithComponents({
50
67
  applicationId,
68
+ branch,
51
69
  token: this.token,
52
70
  superblocksBaseUrl: this.superblocksBaseUrl,
53
71
  viewMode,
@@ -70,6 +88,7 @@ export class SuperblocksSdk {
70
88
  async registerComponents(
71
89
  applicationId: string,
72
90
  componentConfigs: Record<string, any>,
91
+ branch: string | null,
73
92
  injectedHeaders?: Record<string, string>
74
93
  ) {
75
94
  return registerComponents(
@@ -77,6 +96,7 @@ export class SuperblocksSdk {
77
96
  componentConfigs,
78
97
  this.token,
79
98
  this.superblocksBaseUrl,
99
+ branch,
80
100
  injectedHeaders
81
101
  );
82
102
  }
@@ -84,7 +104,8 @@ export class SuperblocksSdk {
84
104
  async uploadComponents(
85
105
  applicationId: string,
86
106
  componentConfigs: Record<string, any>,
87
- files: string[]
107
+ files: string[],
108
+ branch: string | null
88
109
  ) {
89
110
  return uploadComponents({
90
111
  applicationId,
@@ -92,10 +113,32 @@ export class SuperblocksSdk {
92
113
  files,
93
114
  token: this.token,
94
115
  superblocksBaseUrl: this.superblocksBaseUrl,
116
+ branch,
95
117
  });
96
118
  }
97
119
 
98
120
  async fetchCurrentUser() {
99
121
  return fetchCurrentUser(this.token, this.superblocksBaseUrl);
100
122
  }
123
+
124
+ async pushApplication({
125
+ applicationId,
126
+ applicationConfig,
127
+ branch,
128
+ headers = {},
129
+ }: {
130
+ applicationId: string;
131
+ applicationConfig: PushApplicationWithCommitConfig;
132
+ branch: string;
133
+ headers?: Record<string, string>;
134
+ }) {
135
+ return pushApplication({
136
+ applicationId,
137
+ token: this.token,
138
+ superblocksBaseUrl: this.superblocksBaseUrl,
139
+ branch,
140
+ injectedHeaders: headers,
141
+ applicationConfig,
142
+ });
143
+ }
101
144
  }