@superblocksteam/sdk 1.8.0 → 1.9.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 +63 -22
- package/dist/client.js +180 -103
- package/dist/sdk.d.ts +37 -12
- package/dist/sdk.js +32 -8
- package/dist/socket/handlers.d.ts +25 -7
- package/dist/socket/index.d.ts +10 -19
- package/dist/socket/index.js +12 -8
- package/dist/socket/socket.d.ts +53 -10
- package/dist/socket/socket.js +128 -37
- package/dist/types/common.d.ts +1 -1
- package/dist/types/socket.d.ts +19 -6
- package/dist/types/socket.js +10 -0
- package/package.json +3 -3
- package/src/client.ts +320 -152
- package/src/sdk.ts +79 -20
- package/src/socket/handlers.ts +27 -6
- package/src/socket/index.ts +33 -55
- package/src/socket/socket.ts +218 -70
- package/src/types/common.ts +6 -1
- package/src/types/socket.ts +36 -15
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { StdISocketRPCClient } from "./socket";
|
|
3
|
+
import { ApiWithPb, Page, RemoteCommitDto, UserMeDto, ViewMode } from "./types";
|
|
4
4
|
export interface UploadFile {
|
|
5
5
|
name: string;
|
|
6
6
|
filename: string;
|
|
@@ -16,15 +16,11 @@ export interface MultiPageApplicationWrapper {
|
|
|
16
16
|
pages: Page[];
|
|
17
17
|
apis: Record<string, any>[];
|
|
18
18
|
}
|
|
19
|
-
export type PushApplicationWithCommitConfig = ApplicationWrapper & {
|
|
20
|
-
commitId: string;
|
|
21
|
-
commitMessage: string;
|
|
22
|
-
gitState: LocalGitRepoState;
|
|
23
|
-
};
|
|
24
19
|
export type PushMultiPageApplicationWithCommitConfig = MultiPageApplicationWrapper & {
|
|
25
|
-
commitId
|
|
26
|
-
commitMessage
|
|
20
|
+
commitId?: string;
|
|
21
|
+
commitMessage?: string;
|
|
27
22
|
gitState: LocalGitRepoState;
|
|
23
|
+
skipCommit: boolean;
|
|
28
24
|
};
|
|
29
25
|
export interface ApiWrapper {
|
|
30
26
|
apiPb: Record<string, any>;
|
|
@@ -32,9 +28,10 @@ export interface ApiWrapper {
|
|
|
32
28
|
}
|
|
33
29
|
export type PushApiWithCommitConfig = {
|
|
34
30
|
apiPb: Record<string, any>;
|
|
35
|
-
commitId
|
|
36
|
-
commitMessage
|
|
31
|
+
commitId?: string;
|
|
32
|
+
commitMessage?: string;
|
|
37
33
|
gitState: LocalGitRepoState;
|
|
34
|
+
skipCommit: boolean;
|
|
38
35
|
};
|
|
39
36
|
export type Branches = {
|
|
40
37
|
branches: Branch[];
|
|
@@ -43,16 +40,35 @@ export type Branch = {
|
|
|
43
40
|
name: string;
|
|
44
41
|
isDefault: boolean;
|
|
45
42
|
};
|
|
46
|
-
export
|
|
43
|
+
export interface CommitDto {
|
|
44
|
+
commitMessage: string;
|
|
45
|
+
committer: {
|
|
46
|
+
name?: string;
|
|
47
|
+
email: string;
|
|
48
|
+
};
|
|
49
|
+
commitId: string;
|
|
50
|
+
commitDate: number;
|
|
51
|
+
branch?: string;
|
|
52
|
+
autosave?: boolean;
|
|
53
|
+
tag: string;
|
|
54
|
+
externalCommitId?: string | null;
|
|
55
|
+
externalCommitDate?: number | null;
|
|
56
|
+
}
|
|
57
|
+
export interface GetCommitsResponseBody {
|
|
58
|
+
autosaves: CommitDto[];
|
|
59
|
+
commits: CommitDto[];
|
|
60
|
+
}
|
|
61
|
+
export declare function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification, injectedHeaders, }: {
|
|
47
62
|
cliVersion: string;
|
|
48
63
|
applicationId: string;
|
|
49
64
|
branch?: string;
|
|
50
65
|
token: string;
|
|
51
66
|
superblocksBaseUrl: string;
|
|
52
67
|
viewMode: ViewMode;
|
|
68
|
+
commitId?: string;
|
|
69
|
+
skipSigningVerification?: boolean;
|
|
53
70
|
injectedHeaders: Record<string, string>;
|
|
54
|
-
|
|
55
|
-
}): Promise<ApplicationWrapper | MultiPageApplicationWrapper | undefined>;
|
|
71
|
+
}): Promise<MultiPageApplicationWrapper | undefined>;
|
|
56
72
|
export declare function fetchApplicationBranches({ cliVersion, applicationId, token, superblocksBaseUrl, injectedHeaders, }: {
|
|
57
73
|
cliVersion: string;
|
|
58
74
|
applicationId: string;
|
|
@@ -60,20 +76,21 @@ export declare function fetchApplicationBranches({ cliVersion, applicationId, to
|
|
|
60
76
|
superblocksBaseUrl: string;
|
|
61
77
|
injectedHeaders: Record<string, string>;
|
|
62
78
|
}): Promise<Branches | undefined>;
|
|
63
|
-
export declare function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode,
|
|
79
|
+
export declare function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification, injectedHeaders, }: {
|
|
64
80
|
cliVersion: string;
|
|
65
81
|
applicationId: string;
|
|
66
82
|
branch: string;
|
|
67
83
|
token: string;
|
|
68
84
|
superblocksBaseUrl: string;
|
|
69
85
|
viewMode: ViewMode;
|
|
86
|
+
commitId?: string;
|
|
87
|
+
skipSigningVerification?: boolean;
|
|
70
88
|
injectedHeaders: Record<string, string>;
|
|
71
|
-
|
|
72
|
-
}): Promise<((ApplicationWrapper | MultiPageApplicationWrapper) & {
|
|
89
|
+
}): Promise<(MultiPageApplicationWrapper & {
|
|
73
90
|
componentFiles: any;
|
|
74
91
|
}) | undefined>;
|
|
75
92
|
export declare function fetchApplications(cliVersion: string, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<any>;
|
|
76
|
-
export declare function fetchApi(cliVersion: string, apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode, branch?: string): Promise<any>;
|
|
93
|
+
export declare function fetchApi(cliVersion: string, apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode, branch?: string, commitId?: string, skipSigningVerification?: boolean): Promise<any>;
|
|
77
94
|
export declare function fetchApis(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<any>;
|
|
78
95
|
export declare function validateGitSetup(cliVersion: string, resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, token: string, superblocksBaseUrl: string, injectedHeaders?: Record<string, string>): Promise<{
|
|
79
96
|
branchName: string | null;
|
|
@@ -89,16 +106,18 @@ export declare function uploadComponents({ cliVersion, applicationId, componentC
|
|
|
89
106
|
branch: string | null;
|
|
90
107
|
}): Promise<void>;
|
|
91
108
|
export declare function fetchCurrentUser(cliVersion: string, token: string, superblocksBaseUrl: string): Promise<UserMeDto>;
|
|
92
|
-
export declare
|
|
109
|
+
export declare const createSocketConnectionIfNeeded: (cliVersion: string, token: string, superblocksBaseUrl: string) => Promise<StdISocketRPCClient | undefined>;
|
|
110
|
+
export declare function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders, }: {
|
|
93
111
|
cliVersion: string;
|
|
94
112
|
applicationId: string;
|
|
95
113
|
token: string;
|
|
96
114
|
superblocksBaseUrl: string;
|
|
97
115
|
branch: string;
|
|
98
116
|
injectedHeaders: Record<string, string>;
|
|
99
|
-
applicationConfig:
|
|
100
|
-
|
|
101
|
-
|
|
117
|
+
applicationConfig: PushMultiPageApplicationWithCommitConfig;
|
|
118
|
+
}): Promise<RemoteCommitDto | {
|
|
119
|
+
updated: Date;
|
|
120
|
+
} | undefined>;
|
|
102
121
|
export declare function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig, branch, injectedHeaders, }: {
|
|
103
122
|
cliVersion: string;
|
|
104
123
|
apiId: string;
|
|
@@ -109,4 +128,26 @@ export declare function pushApi({ cliVersion, apiId, token, superblocksBaseUrl,
|
|
|
109
128
|
injectedHeaders: Record<string, string>;
|
|
110
129
|
}): Promise<{
|
|
111
130
|
commitId: string;
|
|
131
|
+
} | {
|
|
132
|
+
updated: Date;
|
|
112
133
|
} | undefined>;
|
|
134
|
+
export declare function fetchApplicationCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders, limit, offset, }: {
|
|
135
|
+
cliVersion: string;
|
|
136
|
+
applicationId: string;
|
|
137
|
+
branch?: string;
|
|
138
|
+
token: string;
|
|
139
|
+
superblocksBaseUrl: string;
|
|
140
|
+
injectedHeaders: Record<string, string>;
|
|
141
|
+
limit?: number;
|
|
142
|
+
offset?: number;
|
|
143
|
+
}): Promise<GetCommitsResponseBody>;
|
|
144
|
+
export declare function fetchApiCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders, limit, offset, }: {
|
|
145
|
+
cliVersion: string;
|
|
146
|
+
applicationId: string;
|
|
147
|
+
branch?: string;
|
|
148
|
+
token: string;
|
|
149
|
+
superblocksBaseUrl: string;
|
|
150
|
+
injectedHeaders: Record<string, string>;
|
|
151
|
+
limit?: number;
|
|
152
|
+
offset?: number;
|
|
153
|
+
}): Promise<GetCommitsResponseBody>;
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pushApi = exports.pushApplication = exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.validateGitSetup = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplicationBranches = exports.fetchApplication = void 0;
|
|
3
|
+
exports.fetchApiCommits = exports.fetchApplicationCommits = exports.pushApi = exports.pushApplication = exports.createSocketConnectionIfNeeded = exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.validateGitSetup = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplicationWithComponents = exports.fetchApplicationBranches = exports.fetchApplication = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
6
6
|
const util_1 = require("@superblocksteam/util");
|
|
@@ -15,17 +15,40 @@ const utils_1 = require("./utils");
|
|
|
15
15
|
const BASE_BUCKETEER_URL = "api";
|
|
16
16
|
const BASE_SERVER_PUBLIC_API_URL_V1 = "api/v1/public";
|
|
17
17
|
const BASE_SERVER_PUBLIC_API_URL_v2 = "api/v2/public";
|
|
18
|
+
const BASE_SERVER_API_URL_V2 = "api/v2";
|
|
19
|
+
const BASE_SERVER_API_URL_V3 = "api/v3";
|
|
18
20
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
19
21
|
const CLI_VERSION_HEADER = "x-superblocks-cli-version";
|
|
20
22
|
const SUPERBLOCKS_URL_HEADER = "x-superblocks-url";
|
|
21
|
-
async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, injectedHeaders = {},
|
|
23
|
+
async function fetchApplication({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification = false, injectedHeaders = {}, }) {
|
|
24
|
+
if (commitId && viewMode !== "export-commit") {
|
|
25
|
+
throw new Error(`If commitId ${commitId} is provided, viewMode cannot be ${viewMode}`);
|
|
26
|
+
}
|
|
22
27
|
try {
|
|
23
|
-
const baseServerUrl = fetchSinglePageApplication
|
|
24
|
-
? BASE_SERVER_PUBLIC_API_URL_V1
|
|
25
|
-
: BASE_SERVER_PUBLIC_API_URL_v2;
|
|
26
28
|
const serverURL = branch
|
|
27
|
-
? new URL(`${
|
|
28
|
-
: new URL(`${
|
|
29
|
+
? new URL(`${BASE_SERVER_PUBLIC_API_URL_v2}/applications/${applicationId}/branches/${encodeURIComponent(branch)}`, superblocksBaseUrl)
|
|
30
|
+
: new URL(`${BASE_SERVER_PUBLIC_API_URL_v2}/applications/${applicationId}`, superblocksBaseUrl);
|
|
31
|
+
serverURL.search = new URLSearchParams({
|
|
32
|
+
viewMode,
|
|
33
|
+
...(commitId ? { commitId } : {}),
|
|
34
|
+
}).toString();
|
|
35
|
+
const socket = !skipSigningVerification
|
|
36
|
+
? await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl)
|
|
37
|
+
: undefined;
|
|
38
|
+
if (socket) {
|
|
39
|
+
try {
|
|
40
|
+
const resp = await socket.call.v2.public.application.get({
|
|
41
|
+
applicationId,
|
|
42
|
+
viewMode,
|
|
43
|
+
branchName: branch,
|
|
44
|
+
commitId,
|
|
45
|
+
});
|
|
46
|
+
return resp.data;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
socket.close();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
29
52
|
const config = {
|
|
30
53
|
method: "get",
|
|
31
54
|
url: serverURL.toString(),
|
|
@@ -43,7 +66,7 @@ async function fetchApplication({ cliVersion, applicationId, branch, token, supe
|
|
|
43
66
|
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
44
67
|
throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
|
|
45
68
|
}
|
|
46
|
-
throw new Error(
|
|
69
|
+
throw new Error(`Could not fetch application: ${typeof e === "object" && e && "message" in e ? e.message : e}`);
|
|
47
70
|
}
|
|
48
71
|
}
|
|
49
72
|
exports.fetchApplication = fetchApplication;
|
|
@@ -71,7 +94,7 @@ async function fetchApplicationBranches({ cliVersion, applicationId, token, supe
|
|
|
71
94
|
return serverResponse?.data?.data;
|
|
72
95
|
}
|
|
73
96
|
exports.fetchApplicationBranches = fetchApplicationBranches;
|
|
74
|
-
async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode,
|
|
97
|
+
async function fetchApplicationWithComponents({ cliVersion, applicationId, branch, token, superblocksBaseUrl, viewMode, commitId, skipSigningVerification = false, injectedHeaders = {}, }) {
|
|
75
98
|
const applicationWrapper = await fetchApplication({
|
|
76
99
|
cliVersion,
|
|
77
100
|
applicationId,
|
|
@@ -79,8 +102,9 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
79
102
|
token,
|
|
80
103
|
superblocksBaseUrl,
|
|
81
104
|
viewMode,
|
|
105
|
+
commitId,
|
|
106
|
+
skipSigningVerification,
|
|
82
107
|
injectedHeaders,
|
|
83
|
-
fetchSinglePageApplication,
|
|
84
108
|
});
|
|
85
109
|
if ((0, lodash_1.isEmpty)(applicationWrapper)) {
|
|
86
110
|
return;
|
|
@@ -92,14 +116,11 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
92
116
|
componentFiles: null,
|
|
93
117
|
};
|
|
94
118
|
}
|
|
95
|
-
// TODO(jason) update this with commit ID once we enable fetching by commit
|
|
96
|
-
const commitId = "latest";
|
|
97
119
|
superblocksBaseUrl = superblocksBaseUrl.replace(/\/$/, "");
|
|
98
120
|
const bucketeerBaseUrl = (0, util_1.getBucketeerUrlFromSuperblocksUrl)(superblocksBaseUrl);
|
|
99
|
-
const multiPage = fetchSinglePageApplication ? "false" : "true";
|
|
100
121
|
// fetch files from bucketeer
|
|
101
122
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
102
|
-
const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}&multiPage
|
|
123
|
+
const componentFileURL = new URL(`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}&multiPage=true`, bucketeerBaseUrl).toString();
|
|
103
124
|
try {
|
|
104
125
|
const config = {
|
|
105
126
|
method: "get",
|
|
@@ -110,8 +131,12 @@ async function fetchApplicationWithComponents({ cliVersion, applicationId, branc
|
|
|
110
131
|
...injectedHeaders,
|
|
111
132
|
},
|
|
112
133
|
};
|
|
113
|
-
const
|
|
114
|
-
|
|
134
|
+
const bucketeerApp = (await (0, axios_1.default)(config))
|
|
135
|
+
.data;
|
|
136
|
+
if (!(0, lodash_1.isEqual)(applicationWrapper.application.settings, bucketeerApp.application.settings)) {
|
|
137
|
+
throw new Error("Application settings fetched from bucketeer do not match the settings fetched from the server");
|
|
138
|
+
}
|
|
139
|
+
return bucketeerApp;
|
|
115
140
|
}
|
|
116
141
|
catch (e) {
|
|
117
142
|
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
@@ -152,27 +177,49 @@ async function fetchApplications(cliVersion, token, superblocksBaseUrl, injected
|
|
|
152
177
|
}
|
|
153
178
|
}
|
|
154
179
|
exports.fetchApplications = fetchApplications;
|
|
155
|
-
async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch) {
|
|
180
|
+
async function fetchApi(cliVersion, apiId, token, superblocksBaseUrl, viewMode, branch, commitId, skipSigningVerification = false) {
|
|
156
181
|
try {
|
|
157
182
|
const serverURL = branch
|
|
158
|
-
? new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(branch)}
|
|
159
|
-
: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
183
|
+
? new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(branch)}`, superblocksBaseUrl)
|
|
184
|
+
: new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}`, superblocksBaseUrl);
|
|
185
|
+
serverURL.search = new URLSearchParams({
|
|
186
|
+
viewMode,
|
|
187
|
+
...(commitId ? { commitId } : {}),
|
|
188
|
+
}).toString();
|
|
189
|
+
const socket = !skipSigningVerification
|
|
190
|
+
? await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl)
|
|
191
|
+
: undefined;
|
|
192
|
+
if (socket) {
|
|
193
|
+
try {
|
|
194
|
+
const resp = await socket.call.v1.public.api.get({
|
|
195
|
+
apiId,
|
|
196
|
+
viewMode,
|
|
197
|
+
branchName: branch,
|
|
198
|
+
});
|
|
199
|
+
return resp.data;
|
|
200
|
+
}
|
|
201
|
+
finally {
|
|
202
|
+
socket.close();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const config = {
|
|
207
|
+
method: "get",
|
|
208
|
+
url: new URL(serverURL, superblocksBaseUrl).toString(),
|
|
209
|
+
headers: {
|
|
210
|
+
Authorization: "Bearer " + token,
|
|
211
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
const response = await (0, axios_1.default)(config);
|
|
215
|
+
return response.data.data;
|
|
216
|
+
}
|
|
170
217
|
}
|
|
171
218
|
catch (e) {
|
|
172
219
|
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
173
220
|
throw new util_1.NotFoundError(`Api ${apiId} was not found`);
|
|
174
221
|
}
|
|
175
|
-
throw new Error(
|
|
222
|
+
throw new Error(`Could not fetch api: ${typeof e === "object" && e && "message" in e ? e.message : e}`);
|
|
176
223
|
}
|
|
177
224
|
}
|
|
178
225
|
exports.fetchApi = fetchApi;
|
|
@@ -249,7 +296,7 @@ async function validateGitSetup(cliVersion, resourceId, resourceType, event, loc
|
|
|
249
296
|
else {
|
|
250
297
|
message = `${e?.message ? e.message : e}`;
|
|
251
298
|
}
|
|
252
|
-
const errorMessage = `Could not validate your git setup against Superblocks for
|
|
299
|
+
const errorMessage = `Could not validate your git setup against Superblocks for ${resourceType.toLowerCase()} ${resourceName ?? resourceId}${message ? "\n" + message : ""}`;
|
|
253
300
|
// TODO(@taha-au @gpoulios-sb) Replace this check with a more robust one that uses error codes once
|
|
254
301
|
// the backend starts returning them as part of the response body
|
|
255
302
|
if (message.includes("Please initialize git locally")) {
|
|
@@ -264,17 +311,8 @@ exports.validateGitSetup = validateGitSetup;
|
|
|
264
311
|
async function registerComponents(cliVersion, applicationId, componentConfigs, token, superblocksBaseUrl, branch, injectedHeaders) {
|
|
265
312
|
try {
|
|
266
313
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
if (organization.agentType == types_1.AgentType.ONPREMISE &&
|
|
270
|
-
(0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
|
|
271
|
-
const profile = process.env.SUPERBLOCKS_PROFILE;
|
|
272
|
-
const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType, profile);
|
|
273
|
-
const socket = await (0, socket_1.connectToISocketRPCServer)({
|
|
274
|
-
agentUrl,
|
|
275
|
-
superblocksBaseUrl,
|
|
276
|
-
token,
|
|
277
|
-
});
|
|
314
|
+
const socket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
|
|
315
|
+
if (socket) {
|
|
278
316
|
const resp = await socket.call.v1.public.application.component.register({
|
|
279
317
|
applicationId,
|
|
280
318
|
branchName: branch || "",
|
|
@@ -365,19 +403,13 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
365
403
|
},
|
|
366
404
|
};
|
|
367
405
|
const uploadResponse = await axios_1.default.post(postURL, formData, config);
|
|
368
|
-
const
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
const socket = await (0, socket_1.connectToISocketRPCServer)({
|
|
377
|
-
agentUrl,
|
|
378
|
-
superblocksBaseUrl,
|
|
379
|
-
token,
|
|
380
|
-
});
|
|
406
|
+
const initialSocket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
|
|
407
|
+
const socket = initialSocket ??
|
|
408
|
+
(await (0, socket_1.connectToISocketRPCServer)({
|
|
409
|
+
agentUrl: undefined,
|
|
410
|
+
superblocksBaseUrl,
|
|
411
|
+
token,
|
|
412
|
+
}));
|
|
381
413
|
try {
|
|
382
414
|
await socket.call.v1.public.application.component.update({
|
|
383
415
|
applicationId,
|
|
@@ -387,7 +419,7 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
387
419
|
registeredComponents: componentConfigs,
|
|
388
420
|
cliVersion,
|
|
389
421
|
componentBaseUrl: uploadResponse.data.componentBaseUrl,
|
|
390
|
-
signingRequired,
|
|
422
|
+
signingRequired: !(0, lodash_1.isEmpty)(initialSocket),
|
|
391
423
|
});
|
|
392
424
|
}
|
|
393
425
|
finally {
|
|
@@ -447,7 +479,22 @@ async function fetchCurrentUser(cliVersion, token, superblocksBaseUrl) {
|
|
|
447
479
|
}
|
|
448
480
|
}
|
|
449
481
|
exports.fetchCurrentUser = fetchCurrentUser;
|
|
450
|
-
async
|
|
482
|
+
const createSocketConnectionIfNeeded = async (cliVersion, token, superblocksBaseUrl) => {
|
|
483
|
+
const userMe = await fetchCurrentUser(cliVersion, token, superblocksBaseUrl);
|
|
484
|
+
const organization = userMe.organizations[0];
|
|
485
|
+
if (organization.agentType == types_1.AgentType.ONPREMISE &&
|
|
486
|
+
(0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
|
|
487
|
+
const profile = process.env.SUPERBLOCKS_PROFILE;
|
|
488
|
+
const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType, profile);
|
|
489
|
+
return await (0, socket_1.connectToISocketRPCServer)({
|
|
490
|
+
agentUrl,
|
|
491
|
+
superblocksBaseUrl,
|
|
492
|
+
token,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
exports.createSocketConnectionIfNeeded = createSocketConnectionIfNeeded;
|
|
497
|
+
async function pushApplication({ cliVersion, applicationId, token, superblocksBaseUrl, applicationConfig, branch, injectedHeaders = {}, }) {
|
|
451
498
|
const handleHttpError = (status) => {
|
|
452
499
|
if (status === 405) {
|
|
453
500
|
throw new errors_1.BranchNotCheckedOutError(`Branch ${branch} is not checked out`);
|
|
@@ -457,38 +504,19 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
457
504
|
}
|
|
458
505
|
};
|
|
459
506
|
try {
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
507
|
+
const socket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
|
|
508
|
+
if (socket) {
|
|
509
|
+
const resp = await socket.call.v2.public.application.pushCommit({
|
|
510
|
+
applicationId,
|
|
511
|
+
apis: applicationConfig.apis,
|
|
512
|
+
application: applicationConfig.application,
|
|
513
|
+
branchName: branch,
|
|
514
|
+
commitId: applicationConfig.commitId,
|
|
515
|
+
commitMessage: applicationConfig.commitMessage,
|
|
516
|
+
pages: applicationConfig.pages,
|
|
517
|
+
gitState: applicationConfig.gitState,
|
|
518
|
+
skipCommit: applicationConfig.skipCommit,
|
|
470
519
|
});
|
|
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
|
-
gitState: applicationConfig.gitState,
|
|
481
|
-
})
|
|
482
|
-
: await socket.call.v1.public.application.pushCommit({
|
|
483
|
-
applicationId,
|
|
484
|
-
apis: applicationConfig.apis,
|
|
485
|
-
application: applicationConfig.application,
|
|
486
|
-
branchName: branch,
|
|
487
|
-
commitId: applicationConfig.commitId,
|
|
488
|
-
commitMessage: applicationConfig.commitMessage,
|
|
489
|
-
page: applicationConfig.page,
|
|
490
|
-
gitState: applicationConfig.gitState,
|
|
491
|
-
});
|
|
492
520
|
socket.close();
|
|
493
521
|
handleHttpError(resp.responseMeta.status);
|
|
494
522
|
if (resp.responseMeta.status !== 200) {
|
|
@@ -499,11 +527,7 @@ async function pushApplication({ cliVersion, applicationId, token, superblocksBa
|
|
|
499
527
|
return resp.data;
|
|
500
528
|
}
|
|
501
529
|
else {
|
|
502
|
-
|
|
503
|
-
const baseServerPublicApiUrl = multiPage
|
|
504
|
-
? BASE_SERVER_PUBLIC_API_URL_v2
|
|
505
|
-
: BASE_SERVER_PUBLIC_API_URL_V1;
|
|
506
|
-
const serverURL = new URL(`${baseServerPublicApiUrl}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
530
|
+
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL_v2}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
507
531
|
const config = {
|
|
508
532
|
method: "post",
|
|
509
533
|
url: serverURL.toString(),
|
|
@@ -551,16 +575,8 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
551
575
|
};
|
|
552
576
|
const serverURL = new URL(`${BASE_SERVER_PUBLIC_API_URL_V1}/apis/${apiId}/branches/${encodeURIComponent(branch)}/push`, superblocksBaseUrl);
|
|
553
577
|
try {
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
if (organization.agentType == types_1.AgentType.ONPREMISE &&
|
|
557
|
-
(0, flag_1.signingEnabled)(userMe.flagBootstrap)) {
|
|
558
|
-
const agentUrl = await (0, utils_1.getAgentUrl)(userMe.agents, organization.agentType);
|
|
559
|
-
const socket = await (0, socket_1.connectToISocketRPCServer)({
|
|
560
|
-
agentUrl,
|
|
561
|
-
superblocksBaseUrl,
|
|
562
|
-
token,
|
|
563
|
-
});
|
|
578
|
+
const socket = await (0, exports.createSocketConnectionIfNeeded)(cliVersion, token, superblocksBaseUrl);
|
|
579
|
+
if (socket) {
|
|
564
580
|
const resp = await socket.call.v1.public.api.pushCommit({
|
|
565
581
|
apiId,
|
|
566
582
|
apiPb: apiConfig.apiPb,
|
|
@@ -568,6 +584,7 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
568
584
|
commitId: apiConfig.commitId,
|
|
569
585
|
commitMessage: apiConfig.commitMessage,
|
|
570
586
|
gitState: apiConfig.gitState,
|
|
587
|
+
skipCommit: apiConfig.skipCommit,
|
|
571
588
|
});
|
|
572
589
|
socket.close();
|
|
573
590
|
handleHttpError(resp.responseMeta.status);
|
|
@@ -615,3 +632,63 @@ async function pushApi({ cliVersion, apiId, token, superblocksBaseUrl, apiConfig
|
|
|
615
632
|
}
|
|
616
633
|
}
|
|
617
634
|
exports.pushApi = pushApi;
|
|
635
|
+
async function fetchApplicationCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders = {}, limit, offset, }) {
|
|
636
|
+
try {
|
|
637
|
+
const serverURL = branch
|
|
638
|
+
? new URL(`${BASE_SERVER_API_URL_V2}/applications/${applicationId}/branches/${encodeURIComponent(branch)}/commits`, superblocksBaseUrl)
|
|
639
|
+
: new URL(`${BASE_SERVER_API_URL_V2}/applications/${applicationId}/commits`, superblocksBaseUrl);
|
|
640
|
+
serverURL.search = new URLSearchParams({
|
|
641
|
+
commitType: "commit",
|
|
642
|
+
...(limit ? { limit: limit.toString() } : {}),
|
|
643
|
+
...(offset ? { offset: offset.toString() } : {}),
|
|
644
|
+
}).toString();
|
|
645
|
+
const config = {
|
|
646
|
+
method: "get",
|
|
647
|
+
url: serverURL.toString(),
|
|
648
|
+
headers: {
|
|
649
|
+
Authorization: "Bearer " + token,
|
|
650
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
651
|
+
...injectedHeaders,
|
|
652
|
+
},
|
|
653
|
+
};
|
|
654
|
+
const serverResponse = await (0, axios_1.default)(config);
|
|
655
|
+
return serverResponse?.data?.data;
|
|
656
|
+
}
|
|
657
|
+
catch (e) {
|
|
658
|
+
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
659
|
+
throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
|
|
660
|
+
}
|
|
661
|
+
throw new Error("Could not fetch application");
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
exports.fetchApplicationCommits = fetchApplicationCommits;
|
|
665
|
+
async function fetchApiCommits({ cliVersion, applicationId, branch, token, superblocksBaseUrl, injectedHeaders = {}, limit, offset, }) {
|
|
666
|
+
try {
|
|
667
|
+
const serverURL = branch
|
|
668
|
+
? new URL(`${BASE_SERVER_API_URL_V3}/apis/${applicationId}/branches/${encodeURIComponent(branch)}/commits`, superblocksBaseUrl)
|
|
669
|
+
: new URL(`${BASE_SERVER_API_URL_V3}/apis/${applicationId}/commits`, superblocksBaseUrl);
|
|
670
|
+
serverURL.search = new URLSearchParams({
|
|
671
|
+
commitType: "commit",
|
|
672
|
+
...(limit ? { limit: limit.toString() } : {}),
|
|
673
|
+
...(offset ? { offset: offset.toString() } : {}),
|
|
674
|
+
}).toString();
|
|
675
|
+
const config = {
|
|
676
|
+
method: "get",
|
|
677
|
+
url: serverURL.toString(),
|
|
678
|
+
headers: {
|
|
679
|
+
Authorization: "Bearer " + token,
|
|
680
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
681
|
+
...injectedHeaders,
|
|
682
|
+
},
|
|
683
|
+
};
|
|
684
|
+
const serverResponse = await (0, axios_1.default)(config);
|
|
685
|
+
return serverResponse?.data?.data;
|
|
686
|
+
}
|
|
687
|
+
catch (e) {
|
|
688
|
+
if (axios_1.default.isAxiosError(e) && e.response?.status === 404) {
|
|
689
|
+
throw new util_1.NotFoundError(`Application ${applicationId} was not found`);
|
|
690
|
+
}
|
|
691
|
+
throw new Error("Could not fetch application");
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
exports.fetchApiCommits = fetchApiCommits;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,30 +1,52 @@
|
|
|
1
1
|
import { ComponentEvent, LocalGitRepoState, SuperblocksResourceType } from "@superblocksteam/util";
|
|
2
|
-
import { PushApiWithCommitConfig,
|
|
2
|
+
import { PushApiWithCommitConfig, PushMultiPageApplicationWithCommitConfig } from "./client";
|
|
3
|
+
import { ViewMode } from "./types";
|
|
3
4
|
export * from "./errors";
|
|
4
5
|
export declare class SuperblocksSdk {
|
|
5
6
|
token: string;
|
|
6
7
|
superblocksBaseUrl: string;
|
|
7
8
|
cliVersion: string;
|
|
8
9
|
constructor(accessToken: string, superblocksBaseUrl: string, cliVersion: string);
|
|
9
|
-
fetchApplication({ applicationId, branch, headers, viewMode,
|
|
10
|
+
fetchApplication({ applicationId, branch, headers, viewMode, skipSigningVerification, }: {
|
|
10
11
|
applicationId: string;
|
|
11
12
|
branch?: string;
|
|
12
13
|
headers?: Record<string, string>;
|
|
13
14
|
viewMode?: ViewMode;
|
|
14
|
-
|
|
15
|
-
}): Promise<import("./client").
|
|
15
|
+
skipSigningVerification?: boolean;
|
|
16
|
+
}): Promise<import("./client").MultiPageApplicationWrapper | undefined>;
|
|
16
17
|
fetchApplicationBranches(applicationId: string, headers?: {}): Promise<import("./client").Branches | undefined>;
|
|
17
|
-
fetchApplicationWithComponents({ applicationId, branch, headers, viewMode,
|
|
18
|
+
fetchApplicationWithComponents({ applicationId, branch, headers, viewMode, commitId, skipSigningVerification, }: {
|
|
18
19
|
applicationId: string;
|
|
19
20
|
branch: string;
|
|
20
21
|
headers?: Record<string, string>;
|
|
21
22
|
viewMode?: ViewMode;
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
commitId?: string;
|
|
24
|
+
skipSigningVerification?: boolean;
|
|
25
|
+
}): Promise<(import("./client").MultiPageApplicationWrapper & {
|
|
24
26
|
componentFiles: any;
|
|
25
27
|
}) | undefined>;
|
|
28
|
+
fetchApplicationCommits({ applicationId, branch, headers, limit, offset, }: {
|
|
29
|
+
applicationId: string;
|
|
30
|
+
branch: string;
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
limit?: number;
|
|
33
|
+
offset?: number;
|
|
34
|
+
}): Promise<import("./client").GetCommitsResponseBody>;
|
|
35
|
+
fetchApiCommits({ apiId, branch, headers, limit, offset, }: {
|
|
36
|
+
apiId: string;
|
|
37
|
+
branch: string;
|
|
38
|
+
headers?: Record<string, string>;
|
|
39
|
+
limit?: number;
|
|
40
|
+
offset?: number;
|
|
41
|
+
}): Promise<import("./client").GetCommitsResponseBody>;
|
|
26
42
|
fetchApplications(headers?: Record<string, string>): Promise<any>;
|
|
27
|
-
fetchApi(apiId
|
|
43
|
+
fetchApi({ apiId, branch, viewMode, commitId, skipSigningVerification, }: {
|
|
44
|
+
apiId: string;
|
|
45
|
+
viewMode?: ViewMode;
|
|
46
|
+
branch?: string;
|
|
47
|
+
commitId?: string;
|
|
48
|
+
skipSigningVerification?: boolean;
|
|
49
|
+
}): Promise<any>;
|
|
28
50
|
fetchApis(): Promise<any>;
|
|
29
51
|
validateGitSetup(resourceId: string, resourceType: SuperblocksResourceType, event: ComponentEvent, localGitRepoState: LocalGitRepoState, injectedHeaders?: Record<string, string>): Promise<{
|
|
30
52
|
branchName: string | null;
|
|
@@ -32,13 +54,14 @@ export declare class SuperblocksSdk {
|
|
|
32
54
|
registerComponents(applicationId: string, componentConfigs: Record<string, any>, branch: string | null, injectedHeaders: Record<string, string>): Promise<any>;
|
|
33
55
|
uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], branch: string | null): Promise<void>;
|
|
34
56
|
fetchCurrentUser(): Promise<import("./types").UserMeDto>;
|
|
35
|
-
pushApplication({ applicationId, applicationConfig, branch, headers,
|
|
57
|
+
pushApplication({ applicationId, applicationConfig, branch, headers, }: {
|
|
36
58
|
applicationId: string;
|
|
37
|
-
applicationConfig:
|
|
59
|
+
applicationConfig: PushMultiPageApplicationWithCommitConfig;
|
|
38
60
|
branch: string;
|
|
39
61
|
headers?: Record<string, string>;
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
}): Promise<import("./types").RemoteCommitDto | {
|
|
63
|
+
updated: Date;
|
|
64
|
+
} | undefined>;
|
|
42
65
|
pushApi({ apiId, apiConfig, branch, headers, }: {
|
|
43
66
|
apiId: string;
|
|
44
67
|
apiConfig: PushApiWithCommitConfig;
|
|
@@ -46,5 +69,7 @@ export declare class SuperblocksSdk {
|
|
|
46
69
|
headers?: Record<string, string>;
|
|
47
70
|
}): Promise<{
|
|
48
71
|
commitId: string;
|
|
72
|
+
} | {
|
|
73
|
+
updated: Date;
|
|
49
74
|
} | undefined>;
|
|
50
75
|
}
|