@superblocksteam/sdk 1.5.2 → 1.7.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 +20 -8
- package/dist/client.js +61 -31
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +8 -1
- package/dist/sdk.d.ts +10 -7
- package/dist/sdk.js +6 -3
- package/dist/socket/handlers.d.ts +15 -0
- package/dist/types/common.d.ts +14 -0
- package/package.json +2 -2
- package/src/client.ts +117 -49
- package/src/errors.ts +7 -0
- package/src/sdk.ts +13 -1
- package/src/socket/handlers.ts +18 -0
- package/src/types/common.ts +16 -0
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
|
|
2
|
-
import { RemoteCommitDto, UserMeDto } from "./types";
|
|
2
|
+
import { ApiWithPb, Page, RemoteCommitDto, UserMeDto } from "./types";
|
|
3
3
|
export type ViewMode = "export-deployed" | "export-latest" | "export-live";
|
|
4
4
|
export interface UploadFile {
|
|
5
5
|
name: string;
|
|
@@ -8,13 +8,22 @@ export interface UploadFile {
|
|
|
8
8
|
}
|
|
9
9
|
export interface ApplicationWrapper {
|
|
10
10
|
application: Record<string, any>;
|
|
11
|
-
page:
|
|
11
|
+
page: Page;
|
|
12
|
+
apis: ApiWithPb[];
|
|
13
|
+
}
|
|
14
|
+
export interface MultiPageApplicationWrapper {
|
|
15
|
+
application: Record<string, any>;
|
|
16
|
+
pages: Page[];
|
|
12
17
|
apis: Record<string, any>[];
|
|
13
18
|
}
|
|
14
19
|
export type PushApplicationWithCommitConfig = ApplicationWrapper & {
|
|
15
20
|
commitId: string;
|
|
16
21
|
commitMessage: string;
|
|
17
22
|
};
|
|
23
|
+
export type PushMultiPageApplicationWithCommitConfig = MultiPageApplicationWrapper & {
|
|
24
|
+
commitId: string;
|
|
25
|
+
commitMessage: string;
|
|
26
|
+
};
|
|
18
27
|
export interface ApiWrapper {
|
|
19
28
|
apiPb: Record<string, any>;
|
|
20
29
|
name?: string;
|
|
@@ -31,7 +40,7 @@ export type Branch = {
|
|
|
31
40
|
name: string;
|
|
32
41
|
isDefault: boolean;
|
|
33
42
|
};
|
|
34
|
-
export declare function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
|
|
43
|
+
export declare function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, fetchSinglePageApplication, }: {
|
|
35
44
|
cliVersion: string;
|
|
36
45
|
applicationId: string;
|
|
37
46
|
branch?: string;
|
|
@@ -39,7 +48,8 @@ export declare function fetchApplication({ cliVersion, applicationId, branch, to
|
|
|
39
48
|
superblocksBaseUrl: string;
|
|
40
49
|
viewMode: ViewMode;
|
|
41
50
|
injectedHeaders: Record<string, string>;
|
|
42
|
-
|
|
51
|
+
fetchSinglePageApplication: boolean;
|
|
52
|
+
}): Promise<ApplicationWrapper | MultiPageApplicationWrapper | undefined>;
|
|
43
53
|
export declare function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders, }: {
|
|
44
54
|
cliVersion: string;
|
|
45
55
|
applicationId: string;
|
|
@@ -47,7 +57,7 @@ export declare function fetchApplicationBranches({ cliVersion, applicationId, to
|
|
|
47
57
|
superblocksBaseUrl: string;
|
|
48
58
|
injectedHeaders: Record<string, string>;
|
|
49
59
|
}): Promise<Branches | undefined>;
|
|
50
|
-
export declare function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, }: {
|
|
60
|
+
export declare function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders, fetchSinglePageApplication, }: {
|
|
51
61
|
cliVersion: string;
|
|
52
62
|
applicationId: string;
|
|
53
63
|
branch: string;
|
|
@@ -55,7 +65,8 @@ export declare function fetchApplicationWithComponents({ cliVersion, application
|
|
|
55
65
|
superblocksBaseUrl: string;
|
|
56
66
|
viewMode: ViewMode;
|
|
57
67
|
injectedHeaders: Record<string, string>;
|
|
58
|
-
|
|
68
|
+
fetchSinglePageApplication?: boolean;
|
|
69
|
+
}): Promise<((ApplicationWrapper | MultiPageApplicationWrapper) & {
|
|
59
70
|
componentFiles: any;
|
|
60
71
|
}) | undefined>;
|
|
61
72
|
export declare function fetchApplications(cliVersion: string, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
@@ -75,14 +86,15 @@ export declare function uploadComponents({ cliVersion, applicationId, componentC
|
|
|
75
86
|
branch: string | null;
|
|
76
87
|
}): Promise<void>;
|
|
77
88
|
export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<UserMeDto>;
|
|
78
|
-
export declare function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
|
|
89
|
+
export declare function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, multiPage, }: {
|
|
79
90
|
cliVersion: string;
|
|
80
91
|
applicationId: string;
|
|
81
92
|
token: string;
|
|
82
93
|
superblocksBaseUrl: string;
|
|
83
94
|
branch: string;
|
|
84
95
|
injectedHeaders: Record<string, string>;
|
|
85
|
-
applicationConfig: PushApplicationWithCommitConfig;
|
|
96
|
+
applicationConfig: PushApplicationWithCommitConfig | PushMultiPageApplicationWithCommitConfig;
|
|
97
|
+
multiPage?: boolean;
|
|
86
98
|
}): Promise<RemoteCommitDto | undefined>;
|
|
87
99
|
export declare function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
|
|
88
100
|
cliVersion: string;
|
package/dist/client.js
CHANGED
|
@@ -13,16 +13,19 @@ const socket_1 = require("./socket");
|
|
|
13
13
|
const types_1 = require("./types");
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
15
|
const BASE_BUCKETEER_URL = "api";
|
|
16
|
-
const
|
|
16
|
+
const BASE_SERVER_PUBLIC_API_URL_V1 = "api/v1/public";
|
|
17
|
+
const BASE_SERVER_PUBLIC_API_URL_v2 = "api/v2/public";
|
|
17
18
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
18
19
|
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
19
20
|
const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
|
|
20
|
-
async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
21
|
-
const serverURL = branch
|
|
22
|
-
? new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
|
|
23
|
-
: new URL(`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
|
|
24
|
-
let serverResponse;
|
|
21
|
+
async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, fetchSinglePageApplication, }) {
|
|
25
22
|
try {
|
|
23
|
+
const baseServerUrl = fetchSinglePageApplication
|
|
24
|
+
? BASE_SERVER_PUBLIC_API_URL_V1
|
|
25
|
+
: BASE_SERVER_PUBLIC_API_URL_v2;
|
|
26
|
+
const serverURL = branch
|
|
27
|
+
? new URL(`${baseServerUrl}/applications/${applicationId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
|
|
28
|
+
: new URL(`${baseServerUrl}/applications/${applicationId}?viewMode=${viewMode}`, superblocksBaseUrl);
|
|
26
29
|
const config = {
|
|
27
30
|
method: "get",
|
|
28
31
|
url: serverURL.toString(),
|
|
@@ -32,7 +35,9 @@ async function fetchApplication({ cliVersion, applicationId, branch, token, supe
|
|
|
32
35
|
...injectedHeaders,
|
|
33
36
|
},
|
|
34
37
|
};
|
|
35
|
-
serverResponse = await (0, axios_1.default)(config);
|
|
38
|
+
const serverResponse = await (0, axios_1.default)(config);
|
|
39
|
+
const data = serverResponse?.data?.data;
|
|
40
|
+
return data;
|
|
36
41
|
}
|
|
37
42
|
catch (e) {
|
|
38
43
|
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
@@ -40,7 +45,6 @@ async function fetchApplication({ cliVersion, applicationId, branch, token, supe
|
|
|
40
45
|
}
|
|
41
46
|
throw new Error("Could not fetch application");
|
|
42
47
|
}
|
|
43
|
-
return serverResponse?.data?.data;
|
|
44
48
|
}
|
|
45
49
|
exports.fetchApplication = fetchApplication;
|
|
46
50
|
async function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders = {}, }) {
|
|
@@ -67,7 +71,7 @@ async function fetchApplicationBranches({ cliVersion, applicationId, token, supe
|
|
|
67
71
|
return serverResponse?.data?.data;
|
|
68
72
|
}
|
|
69
73
|
exports.fetchApplicationBranches = fetchApplicationBranches;
|
|
70
|
-
async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, }) {
|
|
74
|
+
async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {}, fetchSinglePageApplication = false, }) {
|
|
71
75
|
const applicationWrapper = await fetchApplication({
|
|
72
76
|
cliVersion,
|
|
73
77
|
applicationId,
|
|
@@ -76,6 +80,7 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
76
80
|
superblocksBaseUrl,
|
|
77
81
|
viewMode,
|
|
78
82
|
injectedHeaders,
|
|
83
|
+
fetchSinglePageApplication,
|
|
79
84
|
});
|
|
80
85
|
if ((0, lodash_1.isEmpty)(applicationWrapper)) {
|
|
81
86
|
return;
|
|
@@ -91,9 +96,10 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
91
96
|
const commitId = "latest";
|
|
92
97
|
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
93
98
|
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
99
|
+
const multiPage = fetchSinglePageApplication ? "false" : "true";
|
|
94
100
|
// fetch files from bucketeer
|
|
95
101
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
96
|
-
const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`, bucketeerBaseUrl).toString();
|
|
102
|
+
const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}&multiPage=${multiPage}`, bucketeerBaseUrl).toString();
|
|
97
103
|
try {
|
|
98
104
|
const config = {
|
|
99
105
|
method: "get",
|
|
@@ -119,7 +125,7 @@ async function fetchApplications(cliVersion, token, superblocksBaseUrl, injected
|
|
|
119
125
|
try {
|
|
120
126
|
const config = {
|
|
121
127
|
method: "get",
|
|
122
|
-
url: new URL(`${
|
|
128
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/applications`, superblocksBaseUrl).toString(),
|
|
123
129
|
headers: {
|
|
124
130
|
Authorization: "Bearer " + token,
|
|
125
131
|
[CLI_VERSION_HEADER]: cliVersion,
|
|
@@ -149,8 +155,8 @@ exports.fetchApplications = fetchApplications;
|
|
|
149
155
|
async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch) {
|
|
150
156
|
try {
|
|
151
157
|
const serverURL = branch
|
|
152
|
-
? new URL(`${
|
|
153
|
-
: new URL(`${
|
|
158
|
+
? new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(branch)}?viewMode=${viewMode}`, superblocksBaseUrl)
|
|
159
|
+
: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}?viewMode=${viewMode}`, superblocksBaseUrl);
|
|
154
160
|
const config = {
|
|
155
161
|
method: "get",
|
|
156
162
|
url: new URL(serverURL, superblocksBaseUrl).toString(),
|
|
@@ -174,7 +180,7 @@ async function fetchApis(cliVersion, token, superblocksBaseUrl) {
|
|
|
174
180
|
try {
|
|
175
181
|
const config = {
|
|
176
182
|
method: "get",
|
|
177
|
-
url: new URL(`${
|
|
183
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis`, superblocksBaseUrl).toString(),
|
|
178
184
|
headers: {
|
|
179
185
|
Authorization: "Bearer " + token,
|
|
180
186
|
[CLI_VERSION_HEADER]: cliVersion,
|
|
@@ -210,7 +216,7 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
|
|
|
210
216
|
}
|
|
211
217
|
const config = {
|
|
212
218
|
method: "post",
|
|
213
|
-
url: new URL(`${
|
|
219
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/${path}`, superblocksBaseUrl).toString(),
|
|
214
220
|
headers: {
|
|
215
221
|
Authorization: "Bearer " + token,
|
|
216
222
|
[CLI_VERSION_HEADER]: cliVersion,
|
|
@@ -241,9 +247,17 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
|
|
|
241
247
|
`${e}`;
|
|
242
248
|
}
|
|
243
249
|
else {
|
|
244
|
-
message = `${e?.message ? e
|
|
250
|
+
message = `${e?.message ? e.message : e}`;
|
|
251
|
+
}
|
|
252
|
+
const errorMessage = `Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${resourceName ?? resourceId}${message ? "\n" + message : ""}`;
|
|
253
|
+
// TODO(@taha-au @gpoulios-sb) Replace this check with a more robust one that uses error codes once
|
|
254
|
+
// the backend starts returning them as part of the response body
|
|
255
|
+
if (message.includes("Please initialize git locally")) {
|
|
256
|
+
throw new errors_1.ValidateGitSetupError(errorMessage);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
throw new Error(errorMessage);
|
|
245
260
|
}
|
|
246
|
-
throw new Error(`Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${resourceName ?? resourceId}${message ? "\n" + message : ""}`);
|
|
247
261
|
}
|
|
248
262
|
}
|
|
249
263
|
exports.validateGitSetup = validateGitSetup;
|
|
@@ -274,7 +288,7 @@ async function registerComponents(cliVersion, applicationId, componentConfigs, t
|
|
|
274
288
|
else {
|
|
275
289
|
const config = {
|
|
276
290
|
method: "put",
|
|
277
|
-
url: new URL(`${
|
|
291
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/application/${applicationId}${branchPath}/components`, superblocksBaseUrl).toString(),
|
|
278
292
|
headers: {
|
|
279
293
|
Authorization: "Bearer " + token,
|
|
280
294
|
[CLI_VERSION_HEADER]: cliVersion,
|
|
@@ -406,7 +420,7 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
|
|
|
406
420
|
try {
|
|
407
421
|
const config = {
|
|
408
422
|
method: "get",
|
|
409
|
-
url: new URL(`${
|
|
423
|
+
url: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/users/me`, superblocksBaseUrl).toString(),
|
|
410
424
|
headers: {
|
|
411
425
|
Authorization: "Bearer " + token,
|
|
412
426
|
[CLI_VERSION_HEADER]: cliVersion,
|
|
@@ -433,7 +447,7 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
|
|
|
433
447
|
}
|
|
434
448
|
}
|
|
435
449
|
exports.fetchCurrentUser = fetchCurrentUser;
|
|
436
|
-
async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
|
|
450
|
+
async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, multiPage = false, }) {
|
|
437
451
|
const handleHttpError = (status) => {
|
|
438
452
|
if (status === 405) {
|
|
439
453
|
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
@@ -454,15 +468,25 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
454
468
|
superblocksBaseUrl,
|
|
455
469
|
token,
|
|
456
470
|
});
|
|
457
|
-
const resp =
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
471
|
+
const resp = multiPage
|
|
472
|
+
? await socket.call.v2.public.application.pushCommit({
|
|
473
|
+
applicationId,
|
|
474
|
+
apis: applicationConfig.apis,
|
|
475
|
+
application: applicationConfig.application,
|
|
476
|
+
branchName: branch,
|
|
477
|
+
commitId: applicationConfig.commitId,
|
|
478
|
+
commitMessage: applicationConfig.commitMessage,
|
|
479
|
+
pages: applicationConfig.pages,
|
|
480
|
+
})
|
|
481
|
+
: await socket.call.v1.public.application.pushCommit({
|
|
482
|
+
applicationId,
|
|
483
|
+
apis: applicationConfig.apis,
|
|
484
|
+
application: applicationConfig.application,
|
|
485
|
+
branchName: branch,
|
|
486
|
+
commitId: applicationConfig.commitId,
|
|
487
|
+
commitMessage: applicationConfig.commitMessage,
|
|
488
|
+
page: applicationConfig.page,
|
|
489
|
+
});
|
|
466
490
|
socket.close();
|
|
467
491
|
handleHttpError(resp.responseMeta.status);
|
|
468
492
|
if (resp.responseMeta.status !== 200) {
|
|
@@ -473,7 +497,11 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
473
497
|
return resp.data;
|
|
474
498
|
}
|
|
475
499
|
else {
|
|
476
|
-
|
|
500
|
+
// v1 calls can be removed once all customers move to multi page
|
|
501
|
+
const baseServerPublicApiUrl = multiPage
|
|
502
|
+
? BASE_SERVER_PUBLIC_API_URL_v2
|
|
503
|
+
: BASE_SERVER_PUBLIC_API_URL_V1;
|
|
504
|
+
const serverURL = new URL(`${baseServerPublicApiUrl}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
477
505
|
const config = {
|
|
478
506
|
method: "post",
|
|
479
507
|
url: serverURL.toString(),
|
|
@@ -503,6 +531,7 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
503
531
|
catch (e) {
|
|
504
532
|
if (e instanceof errors_1.BranchNotCheckedOutError ||
|
|
505
533
|
e instanceof errors_1.CommitAlreadyExistsError) {
|
|
534
|
+
// Rethrow these exceptions because they will be handled higher up the call stack
|
|
506
535
|
throw e;
|
|
507
536
|
}
|
|
508
537
|
throw new Error(`Could not push application ${e.message ? "\n" + e.message : ""}`);
|
|
@@ -518,7 +547,7 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
518
547
|
throw new errors_1.CommitAlreadyExistsError(`Commit ${apiConfig.commitId} already exists`);
|
|
519
548
|
}
|
|
520
549
|
};
|
|
521
|
-
const serverURL = new URL(`${
|
|
550
|
+
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
522
551
|
try {
|
|
523
552
|
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
524
553
|
const organization = userMe.organizations[0];
|
|
@@ -576,6 +605,7 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
576
605
|
catch (e) {
|
|
577
606
|
if (e instanceof errors_1.BranchNotCheckedOutError ||
|
|
578
607
|
e instanceof errors_1.CommitAlreadyExistsError) {
|
|
608
|
+
// Rethrow these exceptions because they will be handled higher up the call stack
|
|
579
609
|
throw e;
|
|
580
610
|
}
|
|
581
611
|
throw new Error(`Could not push api ${e.message ? "\n" + e.message : ""}`);
|
package/dist/errors.d.ts
CHANGED
package/dist/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommitAlreadyExistsError = exports.BranchNotCheckedOutError = void 0;
|
|
3
|
+
exports.ValidateGitSetupError = exports.CommitAlreadyExistsError = exports.BranchNotCheckedOutError = void 0;
|
|
4
4
|
class BranchNotCheckedOutError extends Error {
|
|
5
5
|
constructor(message) {
|
|
6
6
|
super(message);
|
|
@@ -15,3 +15,10 @@ class CommitAlreadyExistsError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.CommitAlreadyExistsError = CommitAlreadyExistsError;
|
|
18
|
+
class ValidateGitSetupError extends Error {
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "ValidateGitSetupError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ValidateGitSetupError = ValidateGitSetupError;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
|
|
2
|
-
import { PushApiWithCommitConfig, PushApplicationWithCommitConfig, ViewMode } from "./client";
|
|
2
|
+
import { PushApiWithCommitConfig, PushApplicationWithCommitConfig, PushMultiPageApplicationWithCommitConfig, ViewMode } from "./client";
|
|
3
3
|
export * from "./errors";
|
|
4
4
|
export declare class SuperblocksSdk {
|
|
5
5
|
token: string;
|
|
6
6
|
superblocksBaseUrl: string;
|
|
7
7
|
cliVersion: string;
|
|
8
8
|
constructor(accessToken: string, superblocksBaseUrl: string, cliVersion: string);
|
|
9
|
-
fetchApplication({ applicationId, branch, headers, viewMode, }: {
|
|
9
|
+
fetchApplication({ applicationId, branch, headers, viewMode, fetchSinglePageApplication, }: {
|
|
10
10
|
applicationId: string;
|
|
11
11
|
branch?: string;
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
13
|
viewMode?: ViewMode;
|
|
14
|
-
|
|
14
|
+
fetchSinglePageApplication?: boolean;
|
|
15
|
+
}): Promise<import("./client").ApplicationWrapper | import("./client").MultiPageApplicationWrapper | undefined>;
|
|
15
16
|
fetchApplicationBranches(applicationId: string, headers?: {}): Promise<import("./client").Branches | undefined>;
|
|
16
|
-
fetchApplicationWithComponents({ applicationId, branch, headers, viewMode, }: {
|
|
17
|
+
fetchApplicationWithComponents({ applicationId, branch, headers, viewMode, fetchSinglePageApplication, }: {
|
|
17
18
|
applicationId: string;
|
|
18
19
|
branch: string;
|
|
19
20
|
headers?: Record<string, string>;
|
|
20
21
|
viewMode?: ViewMode;
|
|
21
|
-
|
|
22
|
+
fetchSinglePageApplication?: boolean;
|
|
23
|
+
}): Promise<((import("./client").ApplicationWrapper | import("./client").MultiPageApplicationWrapper) & {
|
|
22
24
|
componentFiles: any;
|
|
23
25
|
}) | undefined>;
|
|
24
26
|
fetchApplications(headers?: Record<string, string>): Promise<any>;
|
|
@@ -30,11 +32,12 @@ export declare class SuperblocksSdk {
|
|
|
30
32
|
registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders: Record<string, string>): Promise<any>;
|
|
31
33
|
uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], branch: string | null): Promise<void>;
|
|
32
34
|
fetchCurrentUser(): Promise<import("./types").UserMeDto>;
|
|
33
|
-
pushApplication({ applicationId, applicationConfig, branch, headers, }: {
|
|
35
|
+
pushApplication({ applicationId, applicationConfig, branch, headers, multiPage, }: {
|
|
34
36
|
applicationId: string;
|
|
35
|
-
applicationConfig: PushApplicationWithCommitConfig;
|
|
37
|
+
applicationConfig: PushApplicationWithCommitConfig | PushMultiPageApplicationWithCommitConfig;
|
|
36
38
|
branch: string;
|
|
37
39
|
headers?: Record<string, string>;
|
|
40
|
+
multiPage?: boolean;
|
|
38
41
|
}): Promise<import("./types").RemoteCommitDto | undefined>;
|
|
39
42
|
pushApi({ apiId, apiConfig, branch, headers, }: {
|
|
40
43
|
apiId: string;
|
package/dist/sdk.js
CHANGED
|
@@ -14,7 +14,7 @@ class SuperblocksSdk {
|
|
|
14
14
|
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
15
15
|
this.cliVersion = cliVersion;
|
|
16
16
|
}
|
|
17
|
-
async fetchApplication({ applicationId, branch, headers = {}, viewMode = "export-live", }) {
|
|
17
|
+
async fetchApplication({ applicationId, branch, headers = {}, viewMode = "export-live", fetchSinglePageApplication = false, }) {
|
|
18
18
|
return (0, client_1.fetchApplication)({
|
|
19
19
|
cliVersion: this.cliVersion,
|
|
20
20
|
applicationId,
|
|
@@ -23,6 +23,7 @@ class SuperblocksSdk {
|
|
|
23
23
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
24
24
|
viewMode,
|
|
25
25
|
injectedHeaders: headers,
|
|
26
|
+
fetchSinglePageApplication,
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
async fetchApplicationBranches(applicationId, headers = {}) {
|
|
@@ -34,7 +35,7 @@ class SuperblocksSdk {
|
|
|
34
35
|
injectedHeaders: headers,
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
|
-
async fetchApplicationWithComponents({ applicationId, branch, headers = {}, viewMode = "export-live", }) {
|
|
38
|
+
async fetchApplicationWithComponents({ applicationId, branch, headers = {}, viewMode = "export-live", fetchSinglePageApplication = false, }) {
|
|
38
39
|
return (0, client_1.fetchApplicationWithComponents)({
|
|
39
40
|
cliVersion: this.cliVersion,
|
|
40
41
|
applicationId,
|
|
@@ -43,6 +44,7 @@ class SuperblocksSdk {
|
|
|
43
44
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
44
45
|
viewMode,
|
|
45
46
|
injectedHeaders: headers,
|
|
47
|
+
fetchSinglePageApplication,
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
async fetchApplications(headers) {
|
|
@@ -74,7 +76,7 @@ class SuperblocksSdk {
|
|
|
74
76
|
async fetchCurrentUser() {
|
|
75
77
|
return (0, client_1.fetchCurrentUser)(this.cliVersion, this.token, this.superblocksBaseUrl);
|
|
76
78
|
}
|
|
77
|
-
async pushApplication({ applicationId, applicationConfig, branch, headers = {}, }) {
|
|
79
|
+
async pushApplication({ applicationId, applicationConfig, branch, headers = {}, multiPage = false, }) {
|
|
78
80
|
return (0, client_1.pushApplication)({
|
|
79
81
|
cliVersion: this.cliVersion,
|
|
80
82
|
applicationId,
|
|
@@ -83,6 +85,7 @@ class SuperblocksSdk {
|
|
|
83
85
|
branch,
|
|
84
86
|
injectedHeaders: headers,
|
|
85
87
|
applicationConfig,
|
|
88
|
+
multiPage,
|
|
86
89
|
});
|
|
87
90
|
}
|
|
88
91
|
async pushApi({ apiId, apiConfig, branch, headers = {}, }) {
|
|
@@ -98,6 +98,21 @@ export interface ServerMethods {
|
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
|
+
v2: {
|
|
102
|
+
public: {
|
|
103
|
+
application: {
|
|
104
|
+
pushCommit: ServerMethodSchema<{
|
|
105
|
+
applicationId: string;
|
|
106
|
+
branchName: string;
|
|
107
|
+
commitId: string;
|
|
108
|
+
commitMessage: string;
|
|
109
|
+
application: Record<string, unknown>;
|
|
110
|
+
pages: Record<string, unknown>[];
|
|
111
|
+
apis: Record<string, unknown>[];
|
|
112
|
+
}, RemoteCommitDto>;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
101
116
|
}
|
|
102
117
|
export declare function createRequestHandlers({ agentUrl, token, }: {
|
|
103
118
|
token: string;
|
package/dist/types/common.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface UserMeDto {
|
|
|
6
6
|
}
|
|
7
7
|
export interface FlagBootstrap {
|
|
8
8
|
"ui.enable-resource-signing"?: boolean;
|
|
9
|
+
"server.multipage.enabled"?: boolean;
|
|
9
10
|
}
|
|
10
11
|
export type User = {
|
|
11
12
|
id: string;
|
|
@@ -95,6 +96,19 @@ export type Api = {
|
|
|
95
96
|
trigger: any;
|
|
96
97
|
signature?: Signature;
|
|
97
98
|
};
|
|
99
|
+
export type ApiWithPb = {
|
|
100
|
+
id: string;
|
|
101
|
+
pageId?: string;
|
|
102
|
+
apiPb: Api;
|
|
103
|
+
};
|
|
104
|
+
export type Page = {
|
|
105
|
+
id: string;
|
|
106
|
+
applicationId: string;
|
|
107
|
+
isHidden: boolean;
|
|
108
|
+
layouts: Record<string, unknown>[];
|
|
109
|
+
name: string;
|
|
110
|
+
apis: ApiWithPb[];
|
|
111
|
+
};
|
|
98
112
|
/** A signature, as produced by the agent. */
|
|
99
113
|
export interface Signature {
|
|
100
114
|
/** The id of the key used to sign the data. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
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.
|
|
34
|
+
"@superblocksteam/util": "1.7.0",
|
|
35
35
|
"axios": "^1.3.5",
|
|
36
36
|
"isomorphic-ws": "^5.0.0"
|
|
37
37
|
},
|
package/src/client.ts
CHANGED
|
@@ -13,14 +13,25 @@ import {
|
|
|
13
13
|
import axios, { AxiosError, AxiosRequestConfig } from "axios";
|
|
14
14
|
import FormData from "form-data";
|
|
15
15
|
import { isEmpty } from "lodash";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
BranchNotCheckedOutError,
|
|
18
|
+
CommitAlreadyExistsError,
|
|
19
|
+
ValidateGitSetupError,
|
|
20
|
+
} from "./errors";
|
|
17
21
|
import { signingEnabled } from "./flag";
|
|
18
22
|
import { connectToISocketRPCServer } from "./socket";
|
|
19
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
AgentType,
|
|
25
|
+
ApiWithPb,
|
|
26
|
+
Page,
|
|
27
|
+
RemoteCommitDto,
|
|
28
|
+
UserMeDto,
|
|
29
|
+
} from "./types";
|
|
20
30
|
import { getAgentUrl } from "./utils";
|
|
21
31
|
|
|
22
32
|
const BASE_BUCKETEER_URL = "api";
|
|
23
|
-
const
|
|
33
|
+
const BASE_SERVER_PUBLIC_API_URL_V1 = "api/v1/public";
|
|
34
|
+
const BASE_SERVER_PUBLIC_API_URL_v2 = "api/v2/public";
|
|
24
35
|
|
|
25
36
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
26
37
|
|
|
@@ -37,7 +48,13 @@ export interface UploadFile {
|
|
|
37
48
|
|
|
38
49
|
export interface ApplicationWrapper {
|
|
39
50
|
application: Record<string, any>;
|
|
40
|
-
page:
|
|
51
|
+
page: Page;
|
|
52
|
+
apis: ApiWithPb[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface MultiPageApplicationWrapper {
|
|
56
|
+
application: Record<string, any>;
|
|
57
|
+
pages: Page[];
|
|
41
58
|
apis: Record<string, any>[];
|
|
42
59
|
}
|
|
43
60
|
|
|
@@ -46,6 +63,12 @@ export type PushApplicationWithCommitConfig = ApplicationWrapper & {
|
|
|
46
63
|
commitMessage: string;
|
|
47
64
|
};
|
|
48
65
|
|
|
66
|
+
export type PushMultiPageApplicationWithCommitConfig =
|
|
67
|
+
MultiPageApplicationWrapper & {
|
|
68
|
+
commitId: string;
|
|
69
|
+
commitMessage: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
49
72
|
export interface ApiWrapper {
|
|
50
73
|
apiPb: Record<string, any>;
|
|
51
74
|
name?: string; //@deprecated this attribute is used for getting a name for backends(jobs and workflows) that were never migrated to the new API version.
|
|
@@ -76,6 +99,7 @@ export async function fetchApplication({
|
|
|
76
99
|
superblocksBaseUrl,
|
|
77
100
|
viewMode,
|
|
78
101
|
injectedHeaders = {},
|
|
102
|
+
fetchSinglePageApplication,
|
|
79
103
|
}: {
|
|
80
104
|
cliVersion: string;
|
|
81
105
|
applicationId: string;
|
|
@@ -84,22 +108,24 @@ export async function fetchApplication({
|
|
|
84
108
|
superblocksBaseUrl: string;
|
|
85
109
|
viewMode: ViewMode;
|
|
86
110
|
injectedHeaders: Record<string, string>;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
? new URL(
|
|
90
|
-
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
91
|
-
branch
|
|
92
|
-
)}?viewMode=${viewMode}`,
|
|
93
|
-
superblocksBaseUrl
|
|
94
|
-
)
|
|
95
|
-
: new URL(
|
|
96
|
-
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}?viewMode=${viewMode}`,
|
|
97
|
-
superblocksBaseUrl
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
let serverResponse;
|
|
101
|
-
|
|
111
|
+
fetchSinglePageApplication: boolean;
|
|
112
|
+
}): Promise<ApplicationWrapper | MultiPageApplicationWrapper | undefined> {
|
|
102
113
|
try {
|
|
114
|
+
const baseServerUrl = fetchSinglePageApplication
|
|
115
|
+
? BASE_SERVER_PUBLIC_API_URL_V1
|
|
116
|
+
: BASE_SERVER_PUBLIC_API_URL_v2;
|
|
117
|
+
|
|
118
|
+
const serverURL = branch
|
|
119
|
+
? new URL(
|
|
120
|
+
`${baseServerUrl}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
121
|
+
branch
|
|
122
|
+
)}?viewMode=${viewMode}`,
|
|
123
|
+
superblocksBaseUrl
|
|
124
|
+
)
|
|
125
|
+
: new URL(
|
|
126
|
+
`${baseServerUrl}/applications/${applicationId}?viewMode=${viewMode}`,
|
|
127
|
+
superblocksBaseUrl
|
|
128
|
+
);
|
|
103
129
|
const config: AxiosRequestConfig = {
|
|
104
130
|
method: "get",
|
|
105
131
|
url: serverURL.toString(),
|
|
@@ -109,15 +135,17 @@ export async function fetchApplication({
|
|
|
109
135
|
...injectedHeaders,
|
|
110
136
|
},
|
|
111
137
|
};
|
|
112
|
-
serverResponse = await axios<
|
|
138
|
+
const serverResponse = await axios<
|
|
139
|
+
ResponseWithMeta<ApplicationWrapper | MultiPageApplicationWrapper>
|
|
140
|
+
>(config);
|
|
141
|
+
const data = serverResponse?.data?.data;
|
|
142
|
+
return data;
|
|
113
143
|
} catch (e) {
|
|
114
144
|
if (axios.isAxiosError(e) && e.response?.status === 404) {
|
|
115
145
|
throw new NotFoundError(`Application ${applicationId} was not found`);
|
|
116
146
|
}
|
|
117
147
|
throw new Error("Could not fetch application");
|
|
118
148
|
}
|
|
119
|
-
|
|
120
|
-
return serverResponse?.data?.data;
|
|
121
149
|
}
|
|
122
150
|
|
|
123
151
|
export async function fetchApplicationBranches({
|
|
@@ -168,6 +196,7 @@ export async function fetchApplicationWithComponents({
|
|
|
168
196
|
superblocksBaseUrl,
|
|
169
197
|
viewMode,
|
|
170
198
|
injectedHeaders = {},
|
|
199
|
+
fetchSinglePageApplication = false,
|
|
171
200
|
}: {
|
|
172
201
|
cliVersion: string;
|
|
173
202
|
applicationId: string;
|
|
@@ -176,7 +205,13 @@ export async function fetchApplicationWithComponents({
|
|
|
176
205
|
superblocksBaseUrl: string;
|
|
177
206
|
viewMode: ViewMode;
|
|
178
207
|
injectedHeaders: Record<string, string>;
|
|
179
|
-
|
|
208
|
+
fetchSinglePageApplication?: boolean;
|
|
209
|
+
}): Promise<
|
|
210
|
+
| ((ApplicationWrapper | MultiPageApplicationWrapper) & {
|
|
211
|
+
componentFiles: any;
|
|
212
|
+
})
|
|
213
|
+
| undefined
|
|
214
|
+
> {
|
|
180
215
|
const applicationWrapper = await fetchApplication({
|
|
181
216
|
cliVersion,
|
|
182
217
|
applicationId,
|
|
@@ -185,6 +220,7 @@ export async function fetchApplicationWithComponents({
|
|
|
185
220
|
superblocksBaseUrl,
|
|
186
221
|
viewMode,
|
|
187
222
|
injectedHeaders,
|
|
223
|
+
fetchSinglePageApplication,
|
|
188
224
|
});
|
|
189
225
|
|
|
190
226
|
if (isEmpty(applicationWrapper)) {
|
|
@@ -205,10 +241,11 @@ export async function fetchApplicationWithComponents({
|
|
|
205
241
|
const bucketeerBaseUrl =
|
|
206
242
|
getBucketeerUrlFromSuperblocksUrl(superblocksBaseUrl);
|
|
207
243
|
|
|
244
|
+
const multiPage = fetchSinglePageApplication ? "false" : "true";
|
|
208
245
|
// fetch files from bucketeer
|
|
209
246
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
210
247
|
const componentFileURL = new URL(
|
|
211
|
-
`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`,
|
|
248
|
+
`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}&multiPage=${multiPage}`,
|
|
212
249
|
bucketeerBaseUrl
|
|
213
250
|
).toString();
|
|
214
251
|
|
|
@@ -242,7 +279,7 @@ export async function fetchApplications(
|
|
|
242
279
|
const config: AxiosRequestConfig = {
|
|
243
280
|
method: "get",
|
|
244
281
|
url: new URL(
|
|
245
|
-
`${
|
|
282
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/applications`,
|
|
246
283
|
superblocksBaseUrl
|
|
247
284
|
).toString(),
|
|
248
285
|
headers: {
|
|
@@ -280,13 +317,13 @@ export async function fetchApi(
|
|
|
280
317
|
try {
|
|
281
318
|
const serverURL = branch
|
|
282
319
|
? new URL(
|
|
283
|
-
`${
|
|
320
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(
|
|
284
321
|
branch
|
|
285
322
|
)}?viewMode=${viewMode}`,
|
|
286
323
|
superblocksBaseUrl
|
|
287
324
|
)
|
|
288
325
|
: new URL(
|
|
289
|
-
`${
|
|
326
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}?viewMode=${viewMode}`,
|
|
290
327
|
superblocksBaseUrl
|
|
291
328
|
);
|
|
292
329
|
|
|
@@ -317,7 +354,7 @@ export async function fetchApis(
|
|
|
317
354
|
const config: AxiosRequestConfig = {
|
|
318
355
|
method: "get",
|
|
319
356
|
url: new URL(
|
|
320
|
-
`${
|
|
357
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/apis`,
|
|
321
358
|
superblocksBaseUrl
|
|
322
359
|
).toString(),
|
|
323
360
|
headers: {
|
|
@@ -364,7 +401,7 @@ export async function validateGitSetup(
|
|
|
364
401
|
const config: AxiosRequestConfig = {
|
|
365
402
|
method: "post",
|
|
366
403
|
url: new URL(
|
|
367
|
-
`${
|
|
404
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/${path}`,
|
|
368
405
|
superblocksBaseUrl
|
|
369
406
|
).toString(),
|
|
370
407
|
headers: {
|
|
@@ -395,13 +432,20 @@ export async function validateGitSetup(
|
|
|
395
432
|
e?.message ??
|
|
396
433
|
`${e}`;
|
|
397
434
|
} else {
|
|
398
|
-
message = `${e?.message ? e
|
|
435
|
+
message = `${e?.message ? e.message : e}`;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const errorMessage = `Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${
|
|
439
|
+
resourceName ?? resourceId
|
|
440
|
+
}${message ? "\n" + message : ""}`;
|
|
441
|
+
|
|
442
|
+
// TODO(@taha-au @gpoulios-sb) Replace this check with a more robust one that uses error codes once
|
|
443
|
+
// the backend starts returning them as part of the response body
|
|
444
|
+
if (message.includes("Please initialize git locally")) {
|
|
445
|
+
throw new ValidateGitSetupError(errorMessage);
|
|
446
|
+
} else {
|
|
447
|
+
throw new Error(errorMessage);
|
|
399
448
|
}
|
|
400
|
-
throw new Error(
|
|
401
|
-
`Could not validate your git setup against Superblocks for the ${resourceType.toLowerCase()} ${
|
|
402
|
-
resourceName ?? resourceId
|
|
403
|
-
}${message ? "\n" + message : ""}`
|
|
404
|
-
);
|
|
405
449
|
}
|
|
406
450
|
}
|
|
407
451
|
|
|
@@ -450,7 +494,7 @@ export async function registerComponents(
|
|
|
450
494
|
const config: AxiosRequestConfig = {
|
|
451
495
|
method: "put",
|
|
452
496
|
url: new URL(
|
|
453
|
-
`${
|
|
497
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/application/${applicationId}${branchPath}/components`,
|
|
454
498
|
superblocksBaseUrl
|
|
455
499
|
).toString(),
|
|
456
500
|
headers: {
|
|
@@ -631,7 +675,7 @@ export async function fetchCurrentUser(
|
|
|
631
675
|
const config: AxiosRequestConfig = {
|
|
632
676
|
method: "get",
|
|
633
677
|
url: new URL(
|
|
634
|
-
`${
|
|
678
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/users/me`,
|
|
635
679
|
superblocksBaseUrl
|
|
636
680
|
).toString(),
|
|
637
681
|
headers: {
|
|
@@ -666,6 +710,7 @@ export async function pushApplication({
|
|
|
666
710
|
applicationConfig,
|
|
667
711
|
branch,
|
|
668
712
|
injectedHeaders = {},
|
|
713
|
+
multiPage = false,
|
|
669
714
|
}: {
|
|
670
715
|
cliVersion: string;
|
|
671
716
|
applicationId: string;
|
|
@@ -673,7 +718,10 @@ export async function pushApplication({
|
|
|
673
718
|
superblocksBaseUrl: string;
|
|
674
719
|
branch: string;
|
|
675
720
|
injectedHeaders: Record<string, string>;
|
|
676
|
-
applicationConfig:
|
|
721
|
+
applicationConfig:
|
|
722
|
+
| PushApplicationWithCommitConfig
|
|
723
|
+
| PushMultiPageApplicationWithCommitConfig;
|
|
724
|
+
multiPage?: boolean;
|
|
677
725
|
}): Promise<RemoteCommitDto | undefined> {
|
|
678
726
|
const handleHttpError = (status: number) => {
|
|
679
727
|
if (status === 405) {
|
|
@@ -706,15 +754,29 @@ export async function pushApplication({
|
|
|
706
754
|
superblocksBaseUrl,
|
|
707
755
|
token,
|
|
708
756
|
});
|
|
709
|
-
const resp =
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
757
|
+
const resp = multiPage
|
|
758
|
+
? await socket.call.v2.public.application.pushCommit({
|
|
759
|
+
applicationId,
|
|
760
|
+
apis: applicationConfig.apis,
|
|
761
|
+
application: applicationConfig.application,
|
|
762
|
+
branchName: branch,
|
|
763
|
+
commitId: applicationConfig.commitId,
|
|
764
|
+
commitMessage: applicationConfig.commitMessage,
|
|
765
|
+
pages: (
|
|
766
|
+
applicationConfig as unknown as PushMultiPageApplicationWithCommitConfig
|
|
767
|
+
).pages,
|
|
768
|
+
})
|
|
769
|
+
: await socket.call.v1.public.application.pushCommit({
|
|
770
|
+
applicationId,
|
|
771
|
+
apis: applicationConfig.apis,
|
|
772
|
+
application: applicationConfig.application,
|
|
773
|
+
branchName: branch,
|
|
774
|
+
commitId: applicationConfig.commitId,
|
|
775
|
+
commitMessage: applicationConfig.commitMessage,
|
|
776
|
+
page: (
|
|
777
|
+
applicationConfig as unknown as PushApplicationWithCommitConfig
|
|
778
|
+
).page,
|
|
779
|
+
});
|
|
718
780
|
socket.close();
|
|
719
781
|
handleHttpError(resp.responseMeta.status);
|
|
720
782
|
if (resp.responseMeta.status !== 200) {
|
|
@@ -725,8 +787,12 @@ export async function pushApplication({
|
|
|
725
787
|
}
|
|
726
788
|
return resp.data;
|
|
727
789
|
} else {
|
|
790
|
+
// v1 calls can be removed once all customers move to multi page
|
|
791
|
+
const baseServerPublicApiUrl = multiPage
|
|
792
|
+
? BASE_SERVER_PUBLIC_API_URL_v2
|
|
793
|
+
: BASE_SERVER_PUBLIC_API_URL_V1;
|
|
728
794
|
const serverURL = new URL(
|
|
729
|
-
`${
|
|
795
|
+
`${baseServerPublicApiUrl}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
730
796
|
branch
|
|
731
797
|
)}/push`,
|
|
732
798
|
superblocksBaseUrl
|
|
@@ -765,6 +831,7 @@ export async function pushApplication({
|
|
|
765
831
|
e instanceof BranchNotCheckedOutError ||
|
|
766
832
|
e instanceof CommitAlreadyExistsError
|
|
767
833
|
) {
|
|
834
|
+
// Rethrow these exceptions because they will be handled higher up the call stack
|
|
768
835
|
throw e;
|
|
769
836
|
}
|
|
770
837
|
throw new Error(
|
|
@@ -802,7 +869,7 @@ export async function pushApi({
|
|
|
802
869
|
}
|
|
803
870
|
};
|
|
804
871
|
const serverURL = new URL(
|
|
805
|
-
`${
|
|
872
|
+
`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(
|
|
806
873
|
branch
|
|
807
874
|
)}/push`,
|
|
808
875
|
superblocksBaseUrl
|
|
@@ -873,6 +940,7 @@ export async function pushApi({
|
|
|
873
940
|
e instanceof BranchNotCheckedOutError ||
|
|
874
941
|
e instanceof CommitAlreadyExistsError
|
|
875
942
|
) {
|
|
943
|
+
// Rethrow these exceptions because they will be handled higher up the call stack
|
|
876
944
|
throw e;
|
|
877
945
|
}
|
|
878
946
|
throw new Error(
|
package/src/errors.ts
CHANGED
|
@@ -11,3 +11,10 @@ export class CommitAlreadyExistsError extends Error {
|
|
|
11
11
|
this.name = "CommitAlreadyExistsError";
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
export class ValidateGitSetupError extends Error {
|
|
16
|
+
constructor(message: string) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "ValidateGitSetupError";
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/sdk.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
PushApiWithCommitConfig,
|
|
16
16
|
pushApplication,
|
|
17
17
|
PushApplicationWithCommitConfig,
|
|
18
|
+
PushMultiPageApplicationWithCommitConfig,
|
|
18
19
|
registerComponents,
|
|
19
20
|
uploadComponents,
|
|
20
21
|
validateGitSetup,
|
|
@@ -44,11 +45,13 @@ export class SuperblocksSdk {
|
|
|
44
45
|
branch,
|
|
45
46
|
headers = {},
|
|
46
47
|
viewMode = "export-live",
|
|
48
|
+
fetchSinglePageApplication = false,
|
|
47
49
|
}: {
|
|
48
50
|
applicationId: string;
|
|
49
51
|
branch?: string;
|
|
50
52
|
headers?: Record<string, string>;
|
|
51
53
|
viewMode?: ViewMode;
|
|
54
|
+
fetchSinglePageApplication?: boolean;
|
|
52
55
|
}) {
|
|
53
56
|
return fetchApplication({
|
|
54
57
|
cliVersion: this.cliVersion,
|
|
@@ -58,6 +61,7 @@ export class SuperblocksSdk {
|
|
|
58
61
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
59
62
|
viewMode,
|
|
60
63
|
injectedHeaders: headers,
|
|
64
|
+
fetchSinglePageApplication,
|
|
61
65
|
});
|
|
62
66
|
}
|
|
63
67
|
|
|
@@ -76,11 +80,13 @@ export class SuperblocksSdk {
|
|
|
76
80
|
branch,
|
|
77
81
|
headers = {},
|
|
78
82
|
viewMode = "export-live",
|
|
83
|
+
fetchSinglePageApplication = false,
|
|
79
84
|
}: {
|
|
80
85
|
applicationId: string;
|
|
81
86
|
branch: string;
|
|
82
87
|
headers?: Record<string, string>;
|
|
83
88
|
viewMode?: ViewMode;
|
|
89
|
+
fetchSinglePageApplication?: boolean;
|
|
84
90
|
}) {
|
|
85
91
|
return fetchApplicationWithComponents({
|
|
86
92
|
cliVersion: this.cliVersion,
|
|
@@ -90,6 +96,7 @@ export class SuperblocksSdk {
|
|
|
90
96
|
superblocksBaseUrl: this.superblocksBaseUrl,
|
|
91
97
|
viewMode,
|
|
92
98
|
injectedHeaders: headers,
|
|
99
|
+
fetchSinglePageApplication,
|
|
93
100
|
});
|
|
94
101
|
}
|
|
95
102
|
|
|
@@ -187,11 +194,15 @@ export class SuperblocksSdk {
|
|
|
187
194
|
applicationConfig,
|
|
188
195
|
branch,
|
|
189
196
|
headers = {},
|
|
197
|
+
multiPage = false,
|
|
190
198
|
}: {
|
|
191
199
|
applicationId: string;
|
|
192
|
-
applicationConfig:
|
|
200
|
+
applicationConfig:
|
|
201
|
+
| PushApplicationWithCommitConfig
|
|
202
|
+
| PushMultiPageApplicationWithCommitConfig;
|
|
193
203
|
branch: string;
|
|
194
204
|
headers?: Record<string, string>;
|
|
205
|
+
multiPage?: boolean;
|
|
195
206
|
}) {
|
|
196
207
|
return pushApplication({
|
|
197
208
|
cliVersion: this.cliVersion,
|
|
@@ -201,6 +212,7 @@ export class SuperblocksSdk {
|
|
|
201
212
|
branch,
|
|
202
213
|
injectedHeaders: headers,
|
|
203
214
|
applicationConfig,
|
|
215
|
+
multiPage,
|
|
204
216
|
});
|
|
205
217
|
}
|
|
206
218
|
async pushApi({
|
package/src/socket/handlers.ts
CHANGED
|
@@ -115,6 +115,24 @@ export interface ServerMethods {
|
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
|
+
v2: {
|
|
119
|
+
public: {
|
|
120
|
+
application: {
|
|
121
|
+
pushCommit: ServerMethodSchema<
|
|
122
|
+
{
|
|
123
|
+
applicationId: string;
|
|
124
|
+
branchName: string;
|
|
125
|
+
commitId: string;
|
|
126
|
+
commitMessage: string;
|
|
127
|
+
application: Record<string, unknown>;
|
|
128
|
+
pages: Record<string, unknown>[];
|
|
129
|
+
apis: Record<string, unknown>[];
|
|
130
|
+
},
|
|
131
|
+
RemoteCommitDto
|
|
132
|
+
>;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
118
136
|
}
|
|
119
137
|
|
|
120
138
|
export function createRequestHandlers({
|
package/src/types/common.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface UserMeDto {
|
|
|
7
7
|
|
|
8
8
|
export interface FlagBootstrap {
|
|
9
9
|
"ui.enable-resource-signing"?: boolean;
|
|
10
|
+
"server.multipage.enabled"?: boolean;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export type User = {
|
|
@@ -121,6 +122,21 @@ export type Api = {
|
|
|
121
122
|
signature?: Signature;
|
|
122
123
|
};
|
|
123
124
|
|
|
125
|
+
export type ApiWithPb = {
|
|
126
|
+
id: string;
|
|
127
|
+
pageId?: string;
|
|
128
|
+
apiPb: Api;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type Page = {
|
|
132
|
+
id: string;
|
|
133
|
+
applicationId: string;
|
|
134
|
+
isHidden: boolean;
|
|
135
|
+
layouts: Record<string, unknown>[];
|
|
136
|
+
name: string;
|
|
137
|
+
apis: ApiWithPb[];
|
|
138
|
+
};
|
|
139
|
+
|
|
124
140
|
/** A signature, as produced by the agent. */
|
|
125
141
|
export interface Signature {
|
|
126
142
|
/** The id of the key used to sign the data. */
|