@superblocksteam/sdk 1.0.0 → 1.1.0

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;
@@ -29,11 +48,20 @@ export declare function fetchApplications(token: string, superblocksBaseUrl: str
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
50
  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, }: {
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,
@@ -163,8 +188,8 @@ async function registerComponents(applicationId, componentConfigs, token, superb
163
188
  }
164
189
  }
165
190
  exports.registerComponents = registerComponents;
166
- async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, }) {
167
- var _a, _b, _c, _d, _e, _f, _g;
191
+ async function uploadComponents({ applicationId, componentConfigs, files, token, superblocksBaseUrl, branch, }) {
192
+ var _a, _b, _c, _d, _e, _f;
168
193
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
169
194
  const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
170
195
  // parse files to source and bundled files based on path
@@ -184,6 +209,7 @@ async function uploadComponents({ applicationId, componentConfigs, files, token,
184
209
  const srcFiles = uploadFiles.filter((uploadFile) => !uploadFile.filename.startsWith("dist/"));
185
210
  const formatJSON = JSON.stringify({
186
211
  applicationId,
212
+ branch,
187
213
  registeredComponents: componentConfigs,
188
214
  srcFiles,
189
215
  buildFiles,
@@ -224,13 +250,19 @@ You can reduce your component bundle size by uploading static assets to a separa
224
250
  if (e instanceof axios_1.AxiosError && ((_a = e.response) === null || _a === void 0 ? void 0 : _a.status) === 413) {
225
251
  throw new Error(`Could not upload application components, file size limit exceeded`);
226
252
  }
227
- else if (e instanceof axios_1.AxiosError) {
228
- const message = (_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;
229
- throw new Error(`Could not upload application components
230
- ${message !== null && message !== void 0 ? message : (_g = e.response) === null || _g === void 0 ? void 0 : _g.statusText}`);
253
+ else {
254
+ let message;
255
+ if (e instanceof axios_1.AxiosError) {
256
+ 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);
257
+ }
258
+ else {
259
+ message = e.message;
260
+ }
261
+ if (typeof message !== "string") {
262
+ message = JSON.stringify(message, null, 2);
263
+ }
264
+ throw new Error(`Could not upload application components\n${message}`);
231
265
  }
232
- throw new Error(`Could not upload application components
233
- ${e.message}`);
234
266
  }
235
267
  }
236
268
  exports.uploadComponents = uploadComponents;
@@ -252,3 +284,31 @@ async function fetchCurrentUser(token, superblocksBaseUrl) {
252
284
  }
253
285
  }
254
286
  exports.fetchCurrentUser = fetchCurrentUser;
287
+ async function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
288
+ var _a, _b, _c, _d, _e, _f, _g, _h;
289
+ const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
290
+ const serverURL = new URL(`${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
291
+ let serverResponse;
292
+ try {
293
+ const config = {
294
+ method: "post",
295
+ url: serverURL.toString(),
296
+ headers: {
297
+ Authorization: "Bearer " + token,
298
+ [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
299
+ ...injectedHeaders,
300
+ },
301
+ data: applicationConfig,
302
+ };
303
+ serverResponse = await (0, axios_1.default)(config);
304
+ }
305
+ catch (e) {
306
+ if (axios_1.default.isAxiosError(e)) {
307
+ 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;
308
+ throw new Error(`Could not push application ${message ? "\n" + message : ""}`);
309
+ }
310
+ throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
311
+ }
312
+ return (_h = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _h === void 0 ? void 0 : _h.data;
313
+ }
314
+ 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 & {
@@ -19,6 +22,12 @@ export declare class SuperblocksSdk {
19
22
  fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
20
23
  fetchApis(): Promise<any>;
21
24
  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>;
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,
@@ -39,17 +49,28 @@ class SuperblocksSdk {
39
49
  async registerComponents(applicationId, componentConfigs, injectedHeaders) {
40
50
  return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl, 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.0",
3
+ "version": "1.1.0",
4
4
  "description": "Superblocks JS SDK",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -24,13 +24,13 @@
24
24
  "devDependencies": {
25
25
  "@typescript-eslint/eslint-plugin": "^5.60.1",
26
26
  "@typescript-eslint/parser": "^5.60.1",
27
- "eslint": "^8.45.0",
27
+ "eslint": "^8.48.0",
28
28
  "eslint-plugin-unicorn": "^47.0.0",
29
29
  "prettier": "^2.8.8",
30
30
  "typescript": "^5.1.3"
31
31
  },
32
32
  "dependencies": {
33
- "@superblocksteam/util": "1.0.0",
33
+ "@superblocksteam/util": "1.1.0",
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,
@@ -253,12 +309,14 @@ export async function uploadComponents({
253
309
  files,
254
310
  token,
255
311
  superblocksBaseUrl,
312
+ branch,
256
313
  }: {
257
314
  applicationId: string;
258
315
  componentConfigs: Record<string, any>;
259
316
  files: string[];
260
317
  token: string;
261
318
  superblocksBaseUrl: string;
319
+ branch: string | null;
262
320
  }) {
263
321
  superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
264
322
  const bucketeerBaseUrl =
@@ -286,6 +344,7 @@ export async function uploadComponents({
286
344
 
287
345
  const formatJSON = JSON.stringify({
288
346
  applicationId,
347
+ branch,
289
348
  registeredComponents: componentConfigs,
290
349
  srcFiles,
291
350
  buildFiles,
@@ -334,14 +393,18 @@ You can reduce your component bundle size by uploading static assets to a separa
334
393
  throw new Error(
335
394
  `Could not upload application components, file size limit exceeded`
336
395
  );
337
- } else if (e instanceof AxiosError) {
338
- const message =
339
- (e.response?.data?.responseMeta?.message as string) ?? e.response?.data;
340
- throw new Error(`Could not upload application components
341
- ${message ?? e.response?.statusText}`);
396
+ } else {
397
+ let message: string;
398
+ if (e instanceof AxiosError) {
399
+ message = e.response?.data?.responseMeta?.message || e.response?.data || e.response?.statusText;
400
+ } else {
401
+ message = e.message as string;
402
+ }
403
+ if (typeof message !== "string") {
404
+ message = JSON.stringify(message, null, 2);
405
+ }
406
+ throw new Error(`Could not upload application components\n${message}`);
342
407
  }
343
- throw new Error(`Could not upload application components
344
- ${e.message as string}`);
345
408
  }
346
409
  }
347
410
 
@@ -364,3 +427,60 @@ export async function fetchCurrentUser(
364
427
  throw new Error("Could not fetch current user");
365
428
  }
366
429
  }
430
+
431
+ export async function pushApplication({
432
+ applicationId,
433
+ token,
434
+ superblocksBaseUrl,
435
+ applicationConfig,
436
+ branch,
437
+ injectedHeaders = {},
438
+ }: {
439
+ applicationId: string;
440
+ token: string;
441
+ superblocksBaseUrl: string;
442
+ branch: string;
443
+ injectedHeaders: Record<string, string>;
444
+ applicationConfig: ApplicationWrapper;
445
+ }): Promise<ApplicationWrapper | undefined> {
446
+ const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
447
+ const serverURL = new URL(
448
+ `${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(
449
+ branch
450
+ )}/push`,
451
+ superblocksBaseUrl
452
+ );
453
+ let serverResponse;
454
+
455
+ try {
456
+ const config: AxiosRequestConfig = {
457
+ method: "post",
458
+ url: serverURL.toString(),
459
+ headers: {
460
+ Authorization: "Bearer " + token,
461
+ [CLI_VERSION_HEADER]: rootSettings.metadata.cliVersion,
462
+ ...injectedHeaders,
463
+ },
464
+ data: applicationConfig,
465
+ };
466
+ serverResponse = await axios<ResponseWithMeta<ApplicationWrapper>>(config);
467
+ } catch (e) {
468
+ if (axios.isAxiosError(e)) {
469
+ const message: string =
470
+ (e.response?.data?.responseMeta?.message as string) ??
471
+ JSON.stringify(e.response?.data) ??
472
+ e.response?.statusText;
473
+
474
+ throw new Error(
475
+ `Could not push application ${message ? "\n" + message : ""}`
476
+ );
477
+ }
478
+ throw new Error(
479
+ `Could not push application ${
480
+ (e as Error).message ? "\n" + (e as Error).message : ""
481
+ }`
482
+ );
483
+ }
484
+
485
+ return serverResponse?.data?.data;
486
+ }
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,
@@ -84,7 +102,8 @@ export class SuperblocksSdk {
84
102
  async uploadComponents(
85
103
  applicationId: string,
86
104
  componentConfigs: Record<string, any>,
87
- files: string[]
105
+ files: string[],
106
+ branch: string | null
88
107
  ) {
89
108
  return uploadComponents({
90
109
  applicationId,
@@ -92,10 +111,32 @@ export class SuperblocksSdk {
92
111
  files,
93
112
  token: this.token,
94
113
  superblocksBaseUrl: this.superblocksBaseUrl,
114
+ branch,
95
115
  });
96
116
  }
97
117
 
98
118
  async fetchCurrentUser() {
99
119
  return fetchCurrentUser(this.token, this.superblocksBaseUrl);
100
120
  }
121
+
122
+ async pushApplication({
123
+ applicationId,
124
+ applicationConfig,
125
+ branch,
126
+ headers = {},
127
+ }: {
128
+ applicationId: string;
129
+ applicationConfig: PushApplicationWithCommitConfig;
130
+ branch: string;
131
+ headers?: Record<string, string>;
132
+ }) {
133
+ return pushApplication({
134
+ applicationId,
135
+ token: this.token,
136
+ superblocksBaseUrl: this.superblocksBaseUrl,
137
+ branch,
138
+ injectedHeaders: headers,
139
+ applicationConfig,
140
+ });
141
+ }
101
142
  }