@superblocksteam/sdk 1.1.1 → 1.2.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
@@ -1,4 +1,10 @@
1
1
  export type ViewMode = "export-deployed" | "export-latest" | "export-live";
2
+ export declare class BranchNotCheckedOutError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export declare class CommitAlreadyExistsError extends Error {
6
+ constructor(message: string);
7
+ }
2
8
  export interface UploadFile {
3
9
  name: string;
4
10
  filename: string;
@@ -63,5 +69,5 @@ export declare function pushApplication({ applicationId, token, superblocksBaseU
63
69
  superblocksBaseUrl: string;
64
70
  branch: string;
65
71
  injectedHeaders: Record<string, string>;
66
- applicationConfig: ApplicationWrapper;
72
+ applicationConfig: PushApplicationWithCommitConfig;
67
73
  }): 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.pushApplication = exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplicationBranches = 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 = exports.CommitAlreadyExistsError = exports.BranchNotCheckedOutError = void 0;
4
4
  const fs = require("fs");
5
5
  const util_1 = require("@superblocksteam/util");
6
6
  const axios_1 = require("axios");
@@ -11,6 +11,20 @@ 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
+ class BranchNotCheckedOutError extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = "BranchNotCheckedOutError";
18
+ }
19
+ }
20
+ exports.BranchNotCheckedOutError = BranchNotCheckedOutError;
21
+ class CommitAlreadyExistsError extends Error {
22
+ constructor(message) {
23
+ super(message);
24
+ this.name = "CommitAlreadyExistsError";
25
+ }
26
+ }
27
+ exports.CommitAlreadyExistsError = CommitAlreadyExistsError;
14
28
  async function fetchApplication({ applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
15
29
  var _a, _b;
16
30
  const serverURL = new URL(`api/v2/applications/${applicationId}/branches/${branch}?viewMode=${viewMode}`, superblocksBaseUrl);
@@ -254,7 +268,10 @@ You can reduce your component bundle size by uploading static assets to a separa
254
268
  else {
255
269
  let message;
256
270
  if (e instanceof axios_1.AxiosError) {
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);
271
+ message =
272
+ ((_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) ||
273
+ ((_e = e.response) === null || _e === void 0 ? void 0 : _e.data) ||
274
+ ((_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText);
258
275
  }
259
276
  else {
260
277
  message = e.message;
@@ -286,7 +303,7 @@ async function fetchCurrentUser(token, superblocksBaseUrl) {
286
303
  }
287
304
  exports.fetchCurrentUser = fetchCurrentUser;
288
305
  async function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
289
- var _a, _b, _c, _d, _e, _f, _g, _h;
306
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
290
307
  const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
291
308
  const serverURL = new URL(`${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
292
309
  let serverResponse;
@@ -305,11 +322,18 @@ async function pushApplication({ applicationId, token, superblocksBaseUrl, appli
305
322
  }
306
323
  catch (e) {
307
324
  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;
325
+ const respCode = (_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.status) !== null && _d !== void 0 ? _d : (_e = e.response) === null || _e === void 0 ? void 0 : _e.status;
326
+ if (respCode === 405) {
327
+ throw new BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
328
+ }
329
+ else if (respCode === 409) {
330
+ throw new CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
331
+ }
332
+ const message = (_l = (_j = (_h = (_g = (_f = e.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.responseMeta) === null || _h === void 0 ? void 0 : _h.message) !== null && _j !== void 0 ? _j : JSON.stringify((_k = e.response) === null || _k === void 0 ? void 0 : _k.data)) !== null && _l !== void 0 ? _l : (_m = e.response) === null || _m === void 0 ? void 0 : _m.statusText;
309
333
  throw new Error(`Could not push application ${message ? "\n" + message : ""}`);
310
334
  }
311
335
  throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
312
336
  }
313
- return (_h = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _h === void 0 ? void 0 : _h.data;
337
+ return (_o = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _o === void 0 ? void 0 : _o.data;
314
338
  }
315
339
  exports.pushApplication = pushApplication;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/sdk",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
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.1.1",
33
+ "@superblocksteam/util": "1.2.0",
34
34
  "axios": "^1.3.5"
35
35
  },
36
36
  "homepage": "https://www.superblocks.com",
package/src/client.ts CHANGED
@@ -21,6 +21,20 @@ const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
21
21
 
22
22
  export type ViewMode = "export-deployed" | "export-latest" | "export-live";
23
23
 
24
+ export class BranchNotCheckedOutError extends Error {
25
+ constructor(message: string) {
26
+ super(message);
27
+ this.name = "BranchNotCheckedOutError";
28
+ }
29
+ }
30
+
31
+ export class CommitAlreadyExistsError extends Error {
32
+ constructor(message: string) {
33
+ super(message);
34
+ this.name = "CommitAlreadyExistsError";
35
+ }
36
+ }
37
+
24
38
  export interface UploadFile {
25
39
  name: string;
26
40
  filename: string;
@@ -398,7 +412,10 @@ You can reduce your component bundle size by uploading static assets to a separa
398
412
  } else {
399
413
  let message: string;
400
414
  if (e instanceof AxiosError) {
401
- message = e.response?.data?.responseMeta?.message || e.response?.data || e.response?.statusText;
415
+ message =
416
+ e.response?.data?.responseMeta?.message ||
417
+ e.response?.data ||
418
+ e.response?.statusText;
402
419
  } else {
403
420
  message = e.message as string;
404
421
  }
@@ -443,7 +460,7 @@ export async function pushApplication({
443
460
  superblocksBaseUrl: string;
444
461
  branch: string;
445
462
  injectedHeaders: Record<string, string>;
446
- applicationConfig: ApplicationWrapper;
463
+ applicationConfig: PushApplicationWithCommitConfig;
447
464
  }): Promise<ApplicationWrapper | undefined> {
448
465
  const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
449
466
  const serverURL = new URL(
@@ -468,6 +485,17 @@ export async function pushApplication({
468
485
  serverResponse = await axios<ResponseWithMeta<ApplicationWrapper>>(config);
469
486
  } catch (e) {
470
487
  if (axios.isAxiosError(e)) {
488
+ const respCode =
489
+ e.response?.data?.responseMeta?.status ?? e.response?.status;
490
+ if (respCode === 405) {
491
+ throw new BranchNotCheckedOutError(
492
+ `Branch ${branch} is not checked out`
493
+ );
494
+ } else if (respCode === 409) {
495
+ throw new CommitAlreadyExistsError(
496
+ `Commit ${applicationConfig.commitId} already exists`
497
+ );
498
+ }
471
499
  const message: string =
472
500
  (e.response?.data?.responseMeta?.message as string) ??
473
501
  JSON.stringify(e.response?.data) ??