@superblocksteam/sdk 1.5.1 → 1.5.2
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.js +63 -30
- package/dist/socket/handlers.d.ts +1 -0
- package/package.json +2 -2
- package/src/client.ts +81 -53
- package/src/socket/handlers.ts +1 -0
package/dist/client.js
CHANGED
|
@@ -434,8 +434,14 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
|
|
|
434
434
|
}
|
|
435
435
|
exports.fetchCurrentUser = fetchCurrentUser;
|
|
436
436
|
async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
|
|
437
|
-
const
|
|
438
|
-
|
|
437
|
+
const handleHttpError = (status) => {
|
|
438
|
+
if (status === 405) {
|
|
439
|
+
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
440
|
+
}
|
|
441
|
+
else if (status === 409) {
|
|
442
|
+
throw new errors_1.CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
439
445
|
try {
|
|
440
446
|
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
441
447
|
const organization = userMe.organizations[0];
|
|
@@ -458,9 +464,16 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
458
464
|
page: applicationConfig.page,
|
|
459
465
|
});
|
|
460
466
|
socket.close();
|
|
467
|
+
handleHttpError(resp.responseMeta.status);
|
|
468
|
+
if (resp.responseMeta.status !== 200) {
|
|
469
|
+
// Get the raw error message from the server and throw it. The outer try-catch block will wrap it in a nicer error message
|
|
470
|
+
const message = resp?.responseMeta?.message ?? JSON.stringify(resp?.data);
|
|
471
|
+
throw new Error(message);
|
|
472
|
+
}
|
|
461
473
|
return resp.data;
|
|
462
474
|
}
|
|
463
475
|
else {
|
|
476
|
+
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
464
477
|
const config = {
|
|
465
478
|
method: "post",
|
|
466
479
|
url: serverURL.toString(),
|
|
@@ -471,31 +484,41 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
471
484
|
},
|
|
472
485
|
data: applicationConfig,
|
|
473
486
|
};
|
|
474
|
-
|
|
487
|
+
try {
|
|
488
|
+
const serverResponse = await (0, axios_1.default)(config);
|
|
489
|
+
return serverResponse?.data?.data;
|
|
490
|
+
}
|
|
491
|
+
catch (e) {
|
|
492
|
+
if (!axios_1.default.isAxiosError(e)) {
|
|
493
|
+
throw e;
|
|
494
|
+
}
|
|
495
|
+
handleHttpError(e.response?.data?.responseMeta?.status ?? e.response?.status);
|
|
496
|
+
const message = e.response?.data?.responseMeta?.message ??
|
|
497
|
+
JSON.stringify(e.response?.data) ??
|
|
498
|
+
e.response?.statusText;
|
|
499
|
+
throw new Error(message);
|
|
500
|
+
}
|
|
475
501
|
}
|
|
476
502
|
}
|
|
477
503
|
catch (e) {
|
|
478
|
-
if (
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
482
|
-
}
|
|
483
|
-
else if (respCode === 409) {
|
|
484
|
-
throw new errors_1.CommitAlreadyExistsError(`Commit ${applicationConfig.commitId} already exists`);
|
|
485
|
-
}
|
|
486
|
-
const message = e.response?.data?.responseMeta?.message ??
|
|
487
|
-
JSON.stringify(e.response?.data) ??
|
|
488
|
-
e.response?.statusText;
|
|
489
|
-
throw new Error(`Could not push application ${message ? "\n" + message : ""}`);
|
|
504
|
+
if (e instanceof errors_1.BranchNotCheckedOutError ||
|
|
505
|
+
e instanceof errors_1.CommitAlreadyExistsError) {
|
|
506
|
+
throw e;
|
|
490
507
|
}
|
|
491
508
|
throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
|
|
492
509
|
}
|
|
493
|
-
return serverResponse?.data?.data;
|
|
494
510
|
}
|
|
495
511
|
exports.pushApplication = pushApplication;
|
|
496
512
|
async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders = {}, }) {
|
|
513
|
+
const handleHttpError = (status) => {
|
|
514
|
+
if (status === 405) {
|
|
515
|
+
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
516
|
+
}
|
|
517
|
+
else if (status === 409) {
|
|
518
|
+
throw new errors_1.CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
497
521
|
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
498
|
-
let serverResponse;
|
|
499
522
|
try {
|
|
500
523
|
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
501
524
|
const organization = userMe.organizations[0];
|
|
@@ -515,6 +538,12 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
515
538
|
commitMessage: apiConfig.commitMessage,
|
|
516
539
|
});
|
|
517
540
|
socket.close();
|
|
541
|
+
handleHttpError(resp.responseMeta.status);
|
|
542
|
+
if (resp.responseMeta.status !== 200) {
|
|
543
|
+
// Get the raw error message from the server and throw it. The outer try-catch block will wrap it in a nicer error message
|
|
544
|
+
const message = resp?.responseMeta?.message ?? JSON.stringify(resp?.data);
|
|
545
|
+
throw new Error(message);
|
|
546
|
+
}
|
|
518
547
|
return resp.data;
|
|
519
548
|
}
|
|
520
549
|
else {
|
|
@@ -528,24 +557,28 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
528
557
|
},
|
|
529
558
|
data: apiConfig,
|
|
530
559
|
};
|
|
531
|
-
|
|
560
|
+
try {
|
|
561
|
+
const serverResponse = await (0, axios_1.default)(config);
|
|
562
|
+
return serverResponse?.data?.data;
|
|
563
|
+
}
|
|
564
|
+
catch (e) {
|
|
565
|
+
if (!axios_1.default.isAxiosError(e)) {
|
|
566
|
+
throw e;
|
|
567
|
+
}
|
|
568
|
+
handleHttpError(e.response?.data?.responseMeta?.status);
|
|
569
|
+
const message = e.response?.data?.responseMeta?.message ??
|
|
570
|
+
JSON.stringify(e.response?.data) ??
|
|
571
|
+
e.response?.statusText;
|
|
572
|
+
throw new Error(message);
|
|
573
|
+
}
|
|
532
574
|
}
|
|
533
575
|
}
|
|
534
576
|
catch (e) {
|
|
535
|
-
if (
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
else if (e.response?.data?.responseMeta?.status === 409) {
|
|
540
|
-
throw new errors_1.CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
|
|
541
|
-
}
|
|
542
|
-
const message = e.response?.data?.responseMeta?.message ??
|
|
543
|
-
JSON.stringify(e.response?.data) ??
|
|
544
|
-
e.response?.statusText;
|
|
545
|
-
throw new Error(`Could not push api ${message ? "\n" + message : ""}`);
|
|
577
|
+
if (e instanceof errors_1.BranchNotCheckedOutError ||
|
|
578
|
+
e instanceof errors_1.CommitAlreadyExistsError) {
|
|
579
|
+
throw e;
|
|
546
580
|
}
|
|
547
581
|
throw new Error(`Could not push api ${e.message ? "\n" + e.message : ""}`);
|
|
548
582
|
}
|
|
549
|
-
return serverResponse?.data?.data;
|
|
550
583
|
}
|
|
551
584
|
exports.pushApi = pushApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Superblocks JS SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typescript": "^5.1.3"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@superblocksteam/util": "1.5.
|
|
34
|
+
"@superblocksteam/util": "1.5.2",
|
|
35
35
|
"axios": "^1.3.5",
|
|
36
36
|
"isomorphic-ws": "^5.0.0"
|
|
37
37
|
},
|
package/src/client.ts
CHANGED
|
@@ -675,14 +675,15 @@ export async function pushApplication({
|
|
|
675
675
|
injectedHeaders: Record<string, string>;
|
|
676
676
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
677
677
|
}): Promise<RemoteCommitDto | undefined> {
|
|
678
|
-
const
|
|
679
|
-
|
|
680
|
-
branch
|
|
681
|
-
)
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
678
|
+
const handleHttpError = (status: number) => {
|
|
679
|
+
if (status === 405) {
|
|
680
|
+
throw new BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
681
|
+
} else if (status === 409) {
|
|
682
|
+
throw new CommitAlreadyExistsError(
|
|
683
|
+
`Commit ${applicationConfig.commitId} already exists`
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
};
|
|
686
687
|
try {
|
|
687
688
|
const userMe = await fetchCurrentUser(
|
|
688
689
|
cliVersion,
|
|
@@ -715,8 +716,21 @@ export async function pushApplication({
|
|
|
715
716
|
page: applicationConfig.page,
|
|
716
717
|
});
|
|
717
718
|
socket.close();
|
|
719
|
+
handleHttpError(resp.responseMeta.status);
|
|
720
|
+
if (resp.responseMeta.status !== 200) {
|
|
721
|
+
// Get the raw error message from the server and throw it. The outer try-catch block will wrap it in a nicer error message
|
|
722
|
+
const message: string =
|
|
723
|
+
(resp?.responseMeta?.message as string) ?? JSON.stringify(resp?.data);
|
|
724
|
+
throw new Error(message);
|
|
725
|
+
}
|
|
718
726
|
return resp.data;
|
|
719
727
|
} else {
|
|
728
|
+
const serverURL = new URL(
|
|
729
|
+
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
730
|
+
branch
|
|
731
|
+
)}/push`,
|
|
732
|
+
superblocksBaseUrl
|
|
733
|
+
);
|
|
720
734
|
const config: AxiosRequestConfig = {
|
|
721
735
|
method: "post",
|
|
722
736
|
url: serverURL.toString(),
|
|
@@ -727,29 +741,31 @@ export async function pushApplication({
|
|
|
727
741
|
},
|
|
728
742
|
data: applicationConfig,
|
|
729
743
|
};
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
if (axios.isAxiosError(e)) {
|
|
734
|
-
const respCode =
|
|
735
|
-
e.response?.data?.responseMeta?.status ?? e.response?.status;
|
|
736
|
-
if (respCode === 405) {
|
|
737
|
-
throw new BranchNotCheckedOutError(
|
|
738
|
-
`Branch ${branch} is not checked out`
|
|
744
|
+
try {
|
|
745
|
+
const serverResponse = await axios<ResponseWithMeta<RemoteCommitDto>>(
|
|
746
|
+
config
|
|
739
747
|
);
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
748
|
+
return serverResponse?.data?.data;
|
|
749
|
+
} catch (e) {
|
|
750
|
+
if (!axios.isAxiosError(e)) {
|
|
751
|
+
throw e;
|
|
752
|
+
}
|
|
753
|
+
handleHttpError(
|
|
754
|
+
e.response?.data?.responseMeta?.status ?? e.response?.status
|
|
743
755
|
);
|
|
756
|
+
const message =
|
|
757
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
758
|
+
JSON.stringify(e.response?.data) ??
|
|
759
|
+
e.response?.statusText;
|
|
760
|
+
throw new Error(message);
|
|
744
761
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
);
|
|
762
|
+
}
|
|
763
|
+
} catch (e) {
|
|
764
|
+
if (
|
|
765
|
+
e instanceof BranchNotCheckedOutError ||
|
|
766
|
+
e instanceof CommitAlreadyExistsError
|
|
767
|
+
) {
|
|
768
|
+
throw e;
|
|
753
769
|
}
|
|
754
770
|
throw new Error(
|
|
755
771
|
`Could not push application ${
|
|
@@ -757,8 +773,6 @@ export async function pushApplication({
|
|
|
757
773
|
}`
|
|
758
774
|
);
|
|
759
775
|
}
|
|
760
|
-
|
|
761
|
-
return serverResponse?.data?.data;
|
|
762
776
|
}
|
|
763
777
|
|
|
764
778
|
export async function pushApi({
|
|
@@ -778,14 +792,21 @@ export async function pushApi({
|
|
|
778
792
|
branch: string;
|
|
779
793
|
injectedHeaders: Record<string, string>;
|
|
780
794
|
}): Promise<{ commitId: string } | undefined> {
|
|
795
|
+
const handleHttpError = (status: number) => {
|
|
796
|
+
if (status === 405) {
|
|
797
|
+
throw new BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
798
|
+
} else if (status === 409) {
|
|
799
|
+
throw new CommitAlreadyExistsError(
|
|
800
|
+
`Commit ${apiConfig.commitId} already exists`
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
};
|
|
781
804
|
const serverURL = new URL(
|
|
782
805
|
`${BASE_SERVER_PUBLIC_API_URL}/apis/${apiId}/branches/${encodeURIComponent(
|
|
783
806
|
branch
|
|
784
807
|
)}/push`,
|
|
785
808
|
superblocksBaseUrl
|
|
786
809
|
);
|
|
787
|
-
let serverResponse;
|
|
788
|
-
|
|
789
810
|
try {
|
|
790
811
|
const userMe = await fetchCurrentUser(
|
|
791
812
|
cliVersion,
|
|
@@ -811,6 +832,13 @@ export async function pushApi({
|
|
|
811
832
|
commitMessage: apiConfig.commitMessage,
|
|
812
833
|
});
|
|
813
834
|
socket.close();
|
|
835
|
+
handleHttpError(resp.responseMeta.status);
|
|
836
|
+
if (resp.responseMeta.status !== 200) {
|
|
837
|
+
// Get the raw error message from the server and throw it. The outer try-catch block will wrap it in a nicer error message
|
|
838
|
+
const message: string =
|
|
839
|
+
(resp?.responseMeta?.message as string) ?? JSON.stringify(resp?.data);
|
|
840
|
+
throw new Error(message);
|
|
841
|
+
}
|
|
814
842
|
return resp.data;
|
|
815
843
|
} else {
|
|
816
844
|
const config: AxiosRequestConfig = {
|
|
@@ -823,27 +851,29 @@ export async function pushApi({
|
|
|
823
851
|
},
|
|
824
852
|
data: apiConfig,
|
|
825
853
|
};
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
854
|
+
try {
|
|
855
|
+
const serverResponse = await axios<
|
|
856
|
+
ResponseWithMeta<{ commitId: string }>
|
|
857
|
+
>(config);
|
|
858
|
+
return serverResponse?.data?.data;
|
|
859
|
+
} catch (e) {
|
|
860
|
+
if (!axios.isAxiosError(e)) {
|
|
861
|
+
throw e;
|
|
862
|
+
}
|
|
863
|
+
handleHttpError(e.response?.data?.responseMeta?.status);
|
|
864
|
+
const message =
|
|
865
|
+
(e.response?.data?.responseMeta?.message as string) ??
|
|
866
|
+
JSON.stringify(e.response?.data) ??
|
|
867
|
+
e.response?.statusText;
|
|
868
|
+
throw new Error(message);
|
|
869
|
+
}
|
|
829
870
|
}
|
|
830
871
|
} catch (e) {
|
|
831
|
-
if (
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
} else if (e.response?.data?.responseMeta?.status === 409) {
|
|
837
|
-
throw new CommitAlreadyExistsError(
|
|
838
|
-
`Commit ${apiConfig.commitId} already exists`
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
const message: string =
|
|
842
|
-
(e.response?.data?.responseMeta?.message as string) ??
|
|
843
|
-
JSON.stringify(e.response?.data) ??
|
|
844
|
-
e.response?.statusText;
|
|
845
|
-
|
|
846
|
-
throw new Error(`Could not push api ${message ? "\n" + message : ""}`);
|
|
872
|
+
if (
|
|
873
|
+
e instanceof BranchNotCheckedOutError ||
|
|
874
|
+
e instanceof CommitAlreadyExistsError
|
|
875
|
+
) {
|
|
876
|
+
throw e;
|
|
847
877
|
}
|
|
848
878
|
throw new Error(
|
|
849
879
|
`Could not push api ${
|
|
@@ -851,6 +881,4 @@ export async function pushApi({
|
|
|
851
881
|
}`
|
|
852
882
|
);
|
|
853
883
|
}
|
|
854
|
-
|
|
855
|
-
return serverResponse?.data?.data;
|
|
856
884
|
}
|