@superblocksteam/sdk 1.1.2 → 1.2.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 +1 -1
- package/dist/client.js +15 -4
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +17 -0
- package/dist/sdk.d.ts +1 -0
- package/dist/sdk.js +3 -0
- package/package.json +2 -2
- package/src/client.ts +17 -2
- package/src/errors.ts +13 -0
- package/src/sdk.ts +3 -0
package/dist/client.d.ts
CHANGED
|
@@ -63,5 +63,5 @@ export declare function pushApplication({ applicationId, token, superblocksBaseU
|
|
|
63
63
|
superblocksBaseUrl: string;
|
|
64
64
|
branch: string;
|
|
65
65
|
injectedHeaders: Record<string, string>;
|
|
66
|
-
applicationConfig:
|
|
66
|
+
applicationConfig: PushApplicationWithCommitConfig;
|
|
67
67
|
}): Promise<ApplicationWrapper | undefined>;
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,7 @@ const util_1 = require("@superblocksteam/util");
|
|
|
6
6
|
const axios_1 = require("axios");
|
|
7
7
|
const FormData = require("form-data");
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
|
+
const errors_1 = require("./errors");
|
|
9
10
|
const BASE_SERVER_URL = "api/v1";
|
|
10
11
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
11
12
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
@@ -254,7 +255,10 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
254
255
|
else {
|
|
255
256
|
let message;
|
|
256
257
|
if (e instanceof axios_1.AxiosError) {
|
|
257
|
-
message =
|
|
258
|
+
message =
|
|
259
|
+
((_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) ||
|
|
260
|
+
((_e = e.response) === null || _e === void 0 ? void 0 : _e.data) ||
|
|
261
|
+
((_f = e.response) === null || _f === void 0 ? void 0 : _f.statusText);
|
|
258
262
|
}
|
|
259
263
|
else {
|
|
260
264
|
message = e.message;
|
|
@@ -286,7 +290,7 @@ async function fetchCurrentUser(token, superblocksBaseUrl) {
|
|
|
286
290
|
}
|
|
287
291
|
exports.fetchCurrentUser = fetchCurrentUser;
|
|
288
292
|
async function pushApplication({ applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
|
|
289
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
293
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
290
294
|
const [rootSettings] = await (0, util_1.getSuperblocksMonorepoConfigJson)(true);
|
|
291
295
|
const serverURL = new URL(`${BASE_SERVER_URL}/public/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
292
296
|
let serverResponse;
|
|
@@ -305,11 +309,18 @@ async function pushApplication({ applicationId, token, superblocksBaseUrl, appli
|
|
|
305
309
|
}
|
|
306
310
|
catch (e) {
|
|
307
311
|
if (axios_1.default.isAxiosError(e)) {
|
|
308
|
-
const
|
|
312
|
+
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;
|
|
313
|
+
if (respCode === 405) {
|
|
314
|
+
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
315
|
+
}
|
|
316
|
+
else if (respCode === 409) {
|
|
317
|
+
throw new errors_1.CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
|
|
318
|
+
}
|
|
319
|
+
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
320
|
throw new Error(`Could not push application ${message ? "\n" + message : ""}`);
|
|
310
321
|
}
|
|
311
322
|
throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
|
|
312
323
|
}
|
|
313
|
-
return (
|
|
324
|
+
return (_o = serverResponse === null || serverResponse === void 0 ? void 0 : serverResponse.data) === null || _o === void 0 ? void 0 : _o.data;
|
|
314
325
|
}
|
|
315
326
|
exports.pushApplication = pushApplication;
|
package/dist/errors.d.ts
ADDED
package/dist/errors.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommitAlreadyExistsError = exports.BranchNotCheckedOutError = void 0;
|
|
4
|
+
class BranchNotCheckedOutError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "BranchNotCheckedOutError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.BranchNotCheckedOutError = BranchNotCheckedOutError;
|
|
11
|
+
class CommitAlreadyExistsError extends Error {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "CommitAlreadyExistsError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.CommitAlreadyExistsError = CommitAlreadyExistsError;
|
package/dist/sdk.d.ts
CHANGED
package/dist/sdk.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SuperblocksSdk = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const client_1 = require("./client");
|
|
6
|
+
// Exporting here instead of index.ts because only sdk.ts is exposed outside in package.json
|
|
7
|
+
tslib_1.__exportStar(require("./errors"), exports);
|
|
5
8
|
class SuperblocksSdk {
|
|
6
9
|
constructor(accessToken, superblocksBaseUrl) {
|
|
7
10
|
this.token = "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.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.1
|
|
33
|
+
"@superblocksteam/util": "1.2.1",
|
|
34
34
|
"axios": "^1.3.5"
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://www.superblocks.com",
|
package/src/client.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import axios, { AxiosError, AxiosRequestConfig } from "axios";
|
|
11
11
|
import * as FormData from "form-data";
|
|
12
12
|
import { isEmpty } from "lodash";
|
|
13
|
+
import { BranchNotCheckedOutError, CommitAlreadyExistsError } from "./errors";
|
|
13
14
|
|
|
14
15
|
const BASE_SERVER_URL = "api/v1";
|
|
15
16
|
const BASE_BUCKETEER_URL = "api/v1";
|
|
@@ -398,7 +399,10 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
398
399
|
} else {
|
|
399
400
|
let message: string;
|
|
400
401
|
if (e instanceof AxiosError) {
|
|
401
|
-
message =
|
|
402
|
+
message =
|
|
403
|
+
e.response?.data?.responseMeta?.message ||
|
|
404
|
+
e.response?.data ||
|
|
405
|
+
e.response?.statusText;
|
|
402
406
|
} else {
|
|
403
407
|
message = e.message as string;
|
|
404
408
|
}
|
|
@@ -443,7 +447,7 @@ export async function pushApplication({
|
|
|
443
447
|
superblocksBaseUrl: string;
|
|
444
448
|
branch: string;
|
|
445
449
|
injectedHeaders: Record<string, string>;
|
|
446
|
-
applicationConfig:
|
|
450
|
+
applicationConfig: PushApplicationWithCommitConfig;
|
|
447
451
|
}): Promise<ApplicationWrapper | undefined> {
|
|
448
452
|
const [rootSettings] = await getSuperblocksMonorepoConfigJson(true);
|
|
449
453
|
const serverURL = new URL(
|
|
@@ -468,6 +472,17 @@ export async function pushApplication({
|
|
|
468
472
|
serverResponse = await axios<ResponseWithMeta<ApplicationWrapper>>(config);
|
|
469
473
|
} catch (e) {
|
|
470
474
|
if (axios.isAxiosError(e)) {
|
|
475
|
+
const respCode =
|
|
476
|
+
e.response?.data?.responseMeta?.status ?? e.response?.status;
|
|
477
|
+
if (respCode === 405) {
|
|
478
|
+
throw new BranchNotCheckedOutError(
|
|
479
|
+
`Branch ${branch} is not checked out`
|
|
480
|
+
);
|
|
481
|
+
} else if (respCode === 409) {
|
|
482
|
+
throw new CommitAlreadyExistsError(
|
|
483
|
+
`Commit ${applicationConfig.commitId} already exists`
|
|
484
|
+
);
|
|
485
|
+
}
|
|
471
486
|
const message: string =
|
|
472
487
|
(e.response?.data?.responseMeta?.message as string) ??
|
|
473
488
|
JSON.stringify(e.response?.data) ??
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class BranchNotCheckedOutError extends Error {
|
|
2
|
+
constructor(message: string) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = "BranchNotCheckedOutError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class CommitAlreadyExistsError extends Error {
|
|
9
|
+
constructor(message: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "CommitAlreadyExistsError";
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/sdk.ts
CHANGED
|
@@ -13,6 +13,9 @@ import {
|
|
|
13
13
|
fetchApplicationBranches,
|
|
14
14
|
} from "./client";
|
|
15
15
|
|
|
16
|
+
// Exporting here instead of index.ts because only sdk.ts is exposed outside in package.json
|
|
17
|
+
export * from "./errors";
|
|
18
|
+
|
|
16
19
|
export class SuperblocksSdk {
|
|
17
20
|
token = "";
|
|
18
21
|
superblocksBaseUrl = "";
|