@superblocksteam/sdk 1.4.2 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +3 -0
- package/dist/client.d.ts +5 -4
- package/dist/client.js +191 -82
- package/dist/flag.d.ts +2 -0
- package/dist/flag.js +7 -0
- package/dist/sdk.d.ts +5 -5
- package/dist/socket/handlers.d.ts +105 -0
- package/dist/socket/handlers.js +97 -0
- package/dist/socket/index.d.ts +27 -0
- package/dist/socket/index.js +69 -0
- package/dist/socket/signing.d.ts +13 -0
- package/dist/socket/signing.js +70 -0
- package/dist/socket/socket.d.ts +16 -0
- package/dist/socket/socket.js +157 -0
- package/dist/types/common.d.ts +111 -0
- package/dist/types/common.js +33 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +7 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/plugin.js +9 -0
- package/dist/types/signing.d.ts +51 -0
- package/dist/types/signing.js +2 -0
- package/dist/types/socket.d.ts +17 -0
- package/dist/types/socket.js +2 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +66 -0
- package/package.json +5 -3
- package/src/client.ts +179 -51
- package/src/flag.ts +5 -0
- package/src/sdk.ts +8 -8
- package/src/socket/handlers.ts +248 -0
- package/src/socket/index.ts +164 -0
- package/src/socket/signing.ts +104 -0
- package/src/socket/socket.ts +253 -0
- package/src/types/common.ts +138 -0
- package/src/types/index.ts +4 -0
- package/src/types/plugin.ts +7 -0
- package/src/types/signing.ts +61 -0
- package/src/types/socket.ts +48 -0
- package/src/utils.ts +81 -0
- package/tsconfig.json +3 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProfileType = exports.Profile = exports.AgentType = exports.AgentStatus = void 0;
|
|
4
|
+
var AgentStatus;
|
|
5
|
+
(function (AgentStatus) {
|
|
6
|
+
AgentStatus["ACTIVE"] = "Active";
|
|
7
|
+
AgentStatus["DISCONNECTED"] = "Disconnected";
|
|
8
|
+
AgentStatus["BROWSER_UNREACHABLE"] = "Browser Unreachable";
|
|
9
|
+
// TODO: remove PENDING_REGISTRATION after the DB migration
|
|
10
|
+
AgentStatus["PENDING_REGISTRATION"] = "Pending Registration";
|
|
11
|
+
AgentStatus["STALE"] = "Stale";
|
|
12
|
+
})(AgentStatus || (exports.AgentStatus = AgentStatus = {}));
|
|
13
|
+
var AgentType;
|
|
14
|
+
(function (AgentType) {
|
|
15
|
+
AgentType[AgentType["MULTITENANT"] = 0] = "MULTITENANT";
|
|
16
|
+
AgentType[AgentType["DEDICATED"] = 1] = "DEDICATED";
|
|
17
|
+
AgentType[AgentType["ONPREMISE"] = 2] = "ONPREMISE";
|
|
18
|
+
})(AgentType || (exports.AgentType = AgentType = {}));
|
|
19
|
+
class Profile {
|
|
20
|
+
constructor({ id, key, displayName, description, type, }) {
|
|
21
|
+
this.id = id;
|
|
22
|
+
this.key = key;
|
|
23
|
+
this.displayName = displayName;
|
|
24
|
+
this.description = description;
|
|
25
|
+
this.type = type;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Profile = Profile;
|
|
29
|
+
var ProfileType;
|
|
30
|
+
(function (ProfileType) {
|
|
31
|
+
ProfileType["RESERVED"] = "RESERVED";
|
|
32
|
+
ProfileType["CUSTOM"] = "CUSTOM";
|
|
33
|
+
})(ProfileType || (exports.ProfileType = ProfileType = {}));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./common"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./socket"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./plugin"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./signing"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenAiPluginId = exports.transcribeAudioToTextTranslateToEnglishTruthyValues = void 0;
|
|
4
|
+
exports.transcribeAudioToTextTranslateToEnglishTruthyValues = [
|
|
5
|
+
"checked",
|
|
6
|
+
"true",
|
|
7
|
+
true,
|
|
8
|
+
];
|
|
9
|
+
exports.OpenAiPluginId = "openai";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Api as ApiPb, Signature } from "./common";
|
|
2
|
+
export type SignatureResponse = {
|
|
3
|
+
signature: Signature;
|
|
4
|
+
};
|
|
5
|
+
export type ApiResource = {
|
|
6
|
+
api: ApiPb;
|
|
7
|
+
};
|
|
8
|
+
export type GenericResource = {
|
|
9
|
+
literal: {
|
|
10
|
+
data: any;
|
|
11
|
+
signature?: Signature;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
interface PageHash {
|
|
15
|
+
/** The version of the page DSL. */
|
|
16
|
+
version: number;
|
|
17
|
+
/** The SHA-256 hash of the page DSL (i.e. `page.layouts[0].dsl`), in base64. */
|
|
18
|
+
hash: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ApplicationSettingsHashes {
|
|
21
|
+
/** The SHA-256 hash of all custom components related properties from settings, in base64. */
|
|
22
|
+
components: string;
|
|
23
|
+
/** The SHA-256 hash of settings without the custom components related properties, in base64. */
|
|
24
|
+
rest: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ApplicationSignatureTree {
|
|
27
|
+
/** The version of the signature tree. */
|
|
28
|
+
v: 1;
|
|
29
|
+
settings: ApplicationSettingsHashes;
|
|
30
|
+
page: PageHash;
|
|
31
|
+
}
|
|
32
|
+
export interface ApplicationSignatureTreeSigned {
|
|
33
|
+
/** The SHA-256 hash of `root`, in base64. */
|
|
34
|
+
signature: Signature;
|
|
35
|
+
root: ApplicationSignatureTree;
|
|
36
|
+
}
|
|
37
|
+
export type AppToSign = {
|
|
38
|
+
rootHash: string;
|
|
39
|
+
};
|
|
40
|
+
export type AppToVerify = {
|
|
41
|
+
rootHash: string;
|
|
42
|
+
signature?: Signature;
|
|
43
|
+
};
|
|
44
|
+
export type ApiToSign = {
|
|
45
|
+
apiPb: ApiPb;
|
|
46
|
+
};
|
|
47
|
+
export type ApiToVerify = {
|
|
48
|
+
apiPb: ApiPb;
|
|
49
|
+
signature?: Signature;
|
|
50
|
+
};
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type MethodHandler<Params, Result, PeerMethods, RequestContext> = (params: Params, peer: ISocketClient<PeerMethods>, ctx: RequestContext) => Promise<Result>;
|
|
2
|
+
export type MiddlewareHandler<Params, PeerMethods, RequestContext> = (params: Params, peerAuthorization: string | undefined, peer: ISocketClient<PeerMethods>, ctx: RequestContext) => Promise<void>;
|
|
3
|
+
export type MethodHandlers<Methods, PeerMethods, RequestContext> = {
|
|
4
|
+
[Key in keyof Methods]: Methods[Key] extends (params: infer Params) => Promise<infer Result> ? [
|
|
5
|
+
...middlewareHandlers: MiddlewareHandler<Params, PeerMethods, RequestContext>[],
|
|
6
|
+
handler: MethodHandler<Params, Result, PeerMethods, RequestContext>
|
|
7
|
+
] : Methods[Key] extends Record<string, unknown> ? MethodHandlers<Methods[Key], PeerMethods, RequestContext> : never;
|
|
8
|
+
};
|
|
9
|
+
type ISocketClientMethodCall<Methods> = {
|
|
10
|
+
[Key in keyof Methods]: Methods[Key] extends (params: infer P) => Promise<infer R> ? (params: P) => Promise<R> : Methods[Key] extends Record<string, unknown> ? ISocketClientMethodCall<Methods[Key]> : never;
|
|
11
|
+
};
|
|
12
|
+
export type ISocketClient<Methods> = {
|
|
13
|
+
close: () => void;
|
|
14
|
+
call: ISocketClientMethodCall<Methods>;
|
|
15
|
+
};
|
|
16
|
+
export type MethodSchema<Params, Response> = (params: Params) => Promise<Response>;
|
|
17
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Agent, AgentType, Api } from "./types";
|
|
2
|
+
export declare function getAgentUrl(agents: Agent[], agentType: AgentType, profile?: string, healthCheck?: boolean): Promise<string>;
|
|
3
|
+
export declare const sanitizeV2RequestBody: (apiBody: Record<string, unknown>) => Record<string, unknown>;
|
|
4
|
+
export declare const getSanitizedApi: (api: Api) => any;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSanitizedApi = exports.sanitizeV2RequestBody = exports.getAgentUrl = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
async function getAgentUrl(agents, agentType, profile, healthCheck = true) {
|
|
8
|
+
let filtered = agents.filter((a) => a.type === agentType && a.status === types_1.AgentStatus.ACTIVE);
|
|
9
|
+
if (profile) {
|
|
10
|
+
filtered = agents.filter((a) => a.tags.profile &&
|
|
11
|
+
(a.tags.profile.includes("*") || a.tags.profile.includes(profile)));
|
|
12
|
+
}
|
|
13
|
+
if (healthCheck) {
|
|
14
|
+
const coroutines = [];
|
|
15
|
+
for (const agent of filtered) {
|
|
16
|
+
const p = (async () => {
|
|
17
|
+
const url = new URL("health", agent.url);
|
|
18
|
+
const config = {
|
|
19
|
+
url: url.toString(),
|
|
20
|
+
method: "get",
|
|
21
|
+
headers: {},
|
|
22
|
+
};
|
|
23
|
+
await (0, axios_1.default)(config);
|
|
24
|
+
return agent.url;
|
|
25
|
+
})();
|
|
26
|
+
coroutines.push(p);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
return await Promise.any(coroutines);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new Error("No available agents");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const randomIndex = Math.floor(Math.random() * filtered.length);
|
|
37
|
+
return filtered[randomIndex].url;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.getAgentUrl = getAgentUrl;
|
|
41
|
+
const sanitizeV2RequestBody = (apiBody) => {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
const traverseJSON = (obj) => {
|
|
44
|
+
for (const key in obj) {
|
|
45
|
+
if (key === "step" && obj.step[types_1.OpenAiPluginId]) {
|
|
46
|
+
const value = obj.step[types_1.OpenAiPluginId].transcribeAudioToTextTranslateToEnglish;
|
|
47
|
+
obj.step[types_1.OpenAiPluginId].transcribeAudioToTextTranslateToEnglish =
|
|
48
|
+
types_1.transcribeAudioToTextTranslateToEnglishTruthyValues.includes(value);
|
|
49
|
+
}
|
|
50
|
+
else if (typeof obj[key] === "object") {
|
|
51
|
+
(0, exports.sanitizeV2RequestBody)(obj[key]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
traverseJSON(apiBody);
|
|
56
|
+
return apiBody;
|
|
57
|
+
};
|
|
58
|
+
exports.sanitizeV2RequestBody = sanitizeV2RequestBody;
|
|
59
|
+
const getSanitizedApi = (api) => {
|
|
60
|
+
const sanitizedBlocks = (api.blocks ?? [])?.map((block) => (0, exports.sanitizeV2RequestBody)(block));
|
|
61
|
+
return {
|
|
62
|
+
...api,
|
|
63
|
+
blocks: sanitizedBlocks,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
exports.getSanitizedApi = getSanitizedApi;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superblocksteam/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Superblocks JS SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Superblocks Community Software License",
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/ws": "^8.5.10",
|
|
25
26
|
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
|
26
27
|
"@typescript-eslint/parser": "^5.60.1",
|
|
27
28
|
"eslint": "^8.48.0",
|
|
@@ -30,8 +31,9 @@
|
|
|
30
31
|
"typescript": "^5.1.3"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@superblocksteam/util": "1.
|
|
34
|
-
"axios": "^1.3.5"
|
|
34
|
+
"@superblocksteam/util": "1.5.1",
|
|
35
|
+
"axios": "^1.3.5",
|
|
36
|
+
"isomorphic-ws": "^5.0.0"
|
|
35
37
|
},
|
|
36
38
|
"homepage": "https://www.superblocks.com",
|
|
37
39
|
"engines": {
|
package/src/client.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import {
|
|
3
|
+
COMPONENT_EVENT_HEADER,
|
|
3
4
|
ComponentEvent,
|
|
4
5
|
getBucketeerUrlFromSuperblocksUrl,
|
|
5
6
|
getContentType,
|
|
6
|
-
COMPONENT_EVENT_HEADER,
|
|
7
|
-
NotFoundError,
|
|
8
7
|
LocalGitRepoState,
|
|
9
|
-
|
|
8
|
+
NotFoundError,
|
|
10
9
|
SuperblocksResourceType,
|
|
11
10
|
unreachable,
|
|
11
|
+
ValidateGitSetupRequestBody,
|
|
12
12
|
} from "@superblocksteam/util";
|
|
13
13
|
import axios, { AxiosError, AxiosRequestConfig } from "axios";
|
|
14
|
-
import
|
|
14
|
+
import FormData from "form-data";
|
|
15
15
|
import { isEmpty } from "lodash";
|
|
16
16
|
import { BranchNotCheckedOutError, CommitAlreadyExistsError } from "./errors";
|
|
17
|
+
import { signingEnabled } from "./flag";
|
|
18
|
+
import { connectToISocketRPCServer } from "./socket";
|
|
19
|
+
import { AgentType, RemoteCommitDto, UserMeDto } from "./types";
|
|
20
|
+
import { getAgentUrl } from "./utils";
|
|
17
21
|
|
|
18
|
-
const BASE_BUCKETEER_URL = "api
|
|
22
|
+
const BASE_BUCKETEER_URL = "api";
|
|
19
23
|
const BASE_SERVER_PUBLIC_API_URL = "api/v1/public";
|
|
20
24
|
|
|
21
25
|
const SUPERBLOCKS_MAX_FILE_SIZE_MB = 10;
|
|
@@ -204,7 +208,7 @@ export async function fetchApplicationWithComponents({
|
|
|
204
208
|
// fetch files from bucketeer
|
|
205
209
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
206
210
|
const componentFileURL = new URL(
|
|
207
|
-
`${BASE_BUCKETEER_URL}/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`,
|
|
211
|
+
`${BASE_BUCKETEER_URL}/v1/components/${applicationId}${branchPath}?commit=${commitId}&viewMode=${viewMode}`,
|
|
208
212
|
bucketeerBaseUrl
|
|
209
213
|
).toString();
|
|
210
214
|
|
|
@@ -408,25 +412,57 @@ export async function registerComponents(
|
|
|
408
412
|
token: string,
|
|
409
413
|
superblocksBaseUrl: string,
|
|
410
414
|
branch: string | null,
|
|
411
|
-
injectedHeaders
|
|
415
|
+
injectedHeaders: Record<string, string>
|
|
412
416
|
) {
|
|
413
417
|
try {
|
|
414
418
|
const branchPath = branch ? `/branches/${encodeURIComponent(branch)}` : "";
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
419
|
+
const userMe = await fetchCurrentUser(
|
|
420
|
+
cliVersion,
|
|
421
|
+
token,
|
|
422
|
+
superblocksBaseUrl
|
|
423
|
+
);
|
|
424
|
+
const organization = userMe.organizations[0];
|
|
425
|
+
if (
|
|
426
|
+
organization.agentType == AgentType.ONPREMISE &&
|
|
427
|
+
signingEnabled(userMe.flagBootstrap)
|
|
428
|
+
) {
|
|
429
|
+
const profile = process.env.SUPERBLOCKS_PROFILE;
|
|
430
|
+
const agentUrl = await getAgentUrl(
|
|
431
|
+
userMe.agents,
|
|
432
|
+
organization.agentType,
|
|
433
|
+
profile
|
|
434
|
+
);
|
|
435
|
+
const socket = await connectToISocketRPCServer({
|
|
436
|
+
agentUrl,
|
|
437
|
+
superblocksBaseUrl,
|
|
438
|
+
token,
|
|
439
|
+
});
|
|
440
|
+
const resp = await socket.call.v1.public.application.component.register({
|
|
441
|
+
applicationId,
|
|
442
|
+
branchName: branch || "",
|
|
443
|
+
cliVersion: cliVersion,
|
|
444
|
+
componentEvent: injectedHeaders[COMPONENT_EVENT_HEADER],
|
|
445
|
+
components: componentConfigs,
|
|
446
|
+
});
|
|
447
|
+
socket.close();
|
|
448
|
+
return resp.data;
|
|
449
|
+
} else {
|
|
450
|
+
const config: AxiosRequestConfig = {
|
|
451
|
+
method: "put",
|
|
452
|
+
url: new URL(
|
|
453
|
+
`${BASE_SERVER_PUBLIC_API_URL}/application/${applicationId}${branchPath}/components`,
|
|
454
|
+
superblocksBaseUrl
|
|
455
|
+
).toString(),
|
|
456
|
+
headers: {
|
|
457
|
+
Authorization: "Bearer " + token,
|
|
458
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
459
|
+
...injectedHeaders,
|
|
460
|
+
},
|
|
461
|
+
data: { components: componentConfigs },
|
|
462
|
+
};
|
|
463
|
+
const response = await axios(config);
|
|
464
|
+
return response.data;
|
|
465
|
+
}
|
|
430
466
|
} catch (e: any) {
|
|
431
467
|
if (e instanceof AxiosError) {
|
|
432
468
|
const message: string =
|
|
@@ -496,7 +532,7 @@ export async function uploadComponents({
|
|
|
496
532
|
buildFiles,
|
|
497
533
|
});
|
|
498
534
|
const postURL = new URL(
|
|
499
|
-
`${BASE_BUCKETEER_URL}/components/upload`,
|
|
535
|
+
`${BASE_BUCKETEER_URL}/v2/components/upload`,
|
|
500
536
|
bucketeerBaseUrl
|
|
501
537
|
).toString();
|
|
502
538
|
|
|
@@ -530,9 +566,40 @@ You can reduce your component bundle size by uploading static assets to a separa
|
|
|
530
566
|
},
|
|
531
567
|
};
|
|
532
568
|
|
|
533
|
-
const
|
|
569
|
+
const uploadResponse = await axios.post(postURL, formData, config);
|
|
534
570
|
|
|
535
|
-
|
|
571
|
+
const userMe = await fetchCurrentUser(
|
|
572
|
+
cliVersion,
|
|
573
|
+
token,
|
|
574
|
+
superblocksBaseUrl
|
|
575
|
+
);
|
|
576
|
+
const organization = userMe.organizations[0];
|
|
577
|
+
let agentUrl: string | undefined;
|
|
578
|
+
const signingRequired =
|
|
579
|
+
organization.agentType == AgentType.ONPREMISE &&
|
|
580
|
+
signingEnabled(userMe.flagBootstrap);
|
|
581
|
+
if (signingRequired) {
|
|
582
|
+
agentUrl = await getAgentUrl(userMe.agents, organization.agentType);
|
|
583
|
+
}
|
|
584
|
+
const socket = await connectToISocketRPCServer({
|
|
585
|
+
agentUrl,
|
|
586
|
+
superblocksBaseUrl,
|
|
587
|
+
token,
|
|
588
|
+
});
|
|
589
|
+
try {
|
|
590
|
+
await socket.call.v1.public.application.component.update({
|
|
591
|
+
applicationId,
|
|
592
|
+
branchName: branch ?? undefined,
|
|
593
|
+
srcFiles: srcFiles.map((file) => file.filename),
|
|
594
|
+
buildFiles: buildFiles.map((file) => file.filename),
|
|
595
|
+
registeredComponents: componentConfigs,
|
|
596
|
+
cliVersion,
|
|
597
|
+
componentBaseUrl: uploadResponse.data.componentBaseUrl,
|
|
598
|
+
signingRequired,
|
|
599
|
+
});
|
|
600
|
+
} finally {
|
|
601
|
+
socket.close();
|
|
602
|
+
}
|
|
536
603
|
} catch (e: any) {
|
|
537
604
|
if (e instanceof AxiosError && e.response?.status === 413) {
|
|
538
605
|
throw new Error(
|
|
@@ -559,7 +626,7 @@ export async function fetchCurrentUser(
|
|
|
559
626
|
cliVersion: string,
|
|
560
627
|
token: string,
|
|
561
628
|
superblocksBaseUrl: string
|
|
562
|
-
) {
|
|
629
|
+
): Promise<UserMeDto> {
|
|
563
630
|
try {
|
|
564
631
|
const config: AxiosRequestConfig = {
|
|
565
632
|
method: "get",
|
|
@@ -574,7 +641,7 @@ export async function fetchCurrentUser(
|
|
|
574
641
|
},
|
|
575
642
|
};
|
|
576
643
|
const response = await axios(config);
|
|
577
|
-
return response.data.data
|
|
644
|
+
return response.data.data as UserMeDto;
|
|
578
645
|
} catch (e: any) {
|
|
579
646
|
let message: string;
|
|
580
647
|
if (e instanceof AxiosError) {
|
|
@@ -607,7 +674,7 @@ export async function pushApplication({
|
|
|
607
674
|
branch: string;
|
|
608
675
|
injectedHeaders: Record<string, string>;
|
|
609
676
|
applicationConfig: PushApplicationWithCommitConfig;
|
|
610
|
-
}): Promise<
|
|
677
|
+
}): Promise<RemoteCommitDto | undefined> {
|
|
611
678
|
const serverURL = new URL(
|
|
612
679
|
`${BASE_SERVER_PUBLIC_API_URL}/applications/${applicationId}/branches/${encodeURIComponent(
|
|
613
680
|
branch
|
|
@@ -617,17 +684,51 @@ export async function pushApplication({
|
|
|
617
684
|
let serverResponse;
|
|
618
685
|
|
|
619
686
|
try {
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
687
|
+
const userMe = await fetchCurrentUser(
|
|
688
|
+
cliVersion,
|
|
689
|
+
token,
|
|
690
|
+
superblocksBaseUrl
|
|
691
|
+
);
|
|
692
|
+
const organization = userMe.organizations[0];
|
|
693
|
+
if (
|
|
694
|
+
organization.agentType == AgentType.ONPREMISE &&
|
|
695
|
+
signingEnabled(userMe.flagBootstrap)
|
|
696
|
+
) {
|
|
697
|
+
const profile = process.env.SUPERBLOCKS_PROFILE;
|
|
698
|
+
const agentUrl = await getAgentUrl(
|
|
699
|
+
userMe.agents,
|
|
700
|
+
organization.agentType,
|
|
701
|
+
profile
|
|
702
|
+
);
|
|
703
|
+
const socket = await connectToISocketRPCServer({
|
|
704
|
+
agentUrl,
|
|
705
|
+
superblocksBaseUrl,
|
|
706
|
+
token,
|
|
707
|
+
});
|
|
708
|
+
const resp = await socket.call.v1.public.application.pushCommit({
|
|
709
|
+
applicationId,
|
|
710
|
+
apis: applicationConfig.apis,
|
|
711
|
+
application: applicationConfig.application,
|
|
712
|
+
branchName: branch,
|
|
713
|
+
commitId: applicationConfig.commitId,
|
|
714
|
+
commitMessage: applicationConfig.commitMessage,
|
|
715
|
+
page: applicationConfig.page,
|
|
716
|
+
});
|
|
717
|
+
socket.close();
|
|
718
|
+
return resp.data;
|
|
719
|
+
} else {
|
|
720
|
+
const config: AxiosRequestConfig = {
|
|
721
|
+
method: "post",
|
|
722
|
+
url: serverURL.toString(),
|
|
723
|
+
headers: {
|
|
724
|
+
Authorization: "Bearer " + token,
|
|
725
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
726
|
+
...injectedHeaders,
|
|
727
|
+
},
|
|
728
|
+
data: applicationConfig,
|
|
729
|
+
};
|
|
730
|
+
serverResponse = await axios<ResponseWithMeta<RemoteCommitDto>>(config);
|
|
731
|
+
}
|
|
631
732
|
} catch (e) {
|
|
632
733
|
if (axios.isAxiosError(e)) {
|
|
633
734
|
const respCode =
|
|
@@ -686,19 +787,46 @@ export async function pushApi({
|
|
|
686
787
|
let serverResponse;
|
|
687
788
|
|
|
688
789
|
try {
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
Authorization: "Bearer " + token,
|
|
694
|
-
[CLI_VERSION_HEADER]: cliVersion,
|
|
695
|
-
...injectedHeaders,
|
|
696
|
-
},
|
|
697
|
-
data: apiConfig,
|
|
698
|
-
};
|
|
699
|
-
serverResponse = await axios<ResponseWithMeta<{ commitId: string }>>(
|
|
700
|
-
config
|
|
790
|
+
const userMe = await fetchCurrentUser(
|
|
791
|
+
cliVersion,
|
|
792
|
+
token,
|
|
793
|
+
superblocksBaseUrl
|
|
701
794
|
);
|
|
795
|
+
const organization = userMe.organizations[0];
|
|
796
|
+
if (
|
|
797
|
+
organization.agentType == AgentType.ONPREMISE &&
|
|
798
|
+
signingEnabled(userMe.flagBootstrap)
|
|
799
|
+
) {
|
|
800
|
+
const agentUrl = await getAgentUrl(userMe.agents, organization.agentType);
|
|
801
|
+
const socket = await connectToISocketRPCServer({
|
|
802
|
+
agentUrl,
|
|
803
|
+
superblocksBaseUrl,
|
|
804
|
+
token,
|
|
805
|
+
});
|
|
806
|
+
const resp = await socket.call.v1.public.api.pushCommit({
|
|
807
|
+
apiId,
|
|
808
|
+
apiPb: apiConfig.apiPb,
|
|
809
|
+
branchName: branch,
|
|
810
|
+
commitId: apiConfig.commitId,
|
|
811
|
+
commitMessage: apiConfig.commitMessage,
|
|
812
|
+
});
|
|
813
|
+
socket.close();
|
|
814
|
+
return resp.data;
|
|
815
|
+
} else {
|
|
816
|
+
const config: AxiosRequestConfig = {
|
|
817
|
+
method: "post",
|
|
818
|
+
url: serverURL.toString(),
|
|
819
|
+
headers: {
|
|
820
|
+
Authorization: "Bearer " + token,
|
|
821
|
+
[CLI_VERSION_HEADER]: cliVersion,
|
|
822
|
+
...injectedHeaders,
|
|
823
|
+
},
|
|
824
|
+
data: apiConfig,
|
|
825
|
+
};
|
|
826
|
+
serverResponse = await axios<ResponseWithMeta<{ commitId: string }>>(
|
|
827
|
+
config
|
|
828
|
+
);
|
|
829
|
+
}
|
|
702
830
|
} catch (e) {
|
|
703
831
|
if (axios.isAxiosError(e)) {
|
|
704
832
|
if (e.response?.data?.responseMeta?.status === 405) {
|
package/src/flag.ts
ADDED
package/src/sdk.ts
CHANGED
|
@@ -7,18 +7,18 @@ import {
|
|
|
7
7
|
fetchApi,
|
|
8
8
|
fetchApis,
|
|
9
9
|
fetchApplication,
|
|
10
|
-
|
|
10
|
+
fetchApplicationBranches,
|
|
11
11
|
fetchApplications,
|
|
12
|
-
|
|
13
|
-
uploadComponents,
|
|
12
|
+
fetchApplicationWithComponents,
|
|
14
13
|
fetchCurrentUser,
|
|
15
|
-
|
|
14
|
+
pushApi,
|
|
15
|
+
PushApiWithCommitConfig,
|
|
16
16
|
pushApplication,
|
|
17
17
|
PushApplicationWithCommitConfig,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
pushApi,
|
|
18
|
+
registerComponents,
|
|
19
|
+
uploadComponents,
|
|
21
20
|
validateGitSetup,
|
|
21
|
+
ViewMode,
|
|
22
22
|
} from "./client";
|
|
23
23
|
|
|
24
24
|
// Exporting here instead of index.ts because only sdk.ts is exposed outside in package.json
|
|
@@ -144,7 +144,7 @@ export class SuperblocksSdk {
|
|
|
144
144
|
applicationId: string,
|
|
145
145
|
componentConfigs: Record<string, any>,
|
|
146
146
|
branch: string | null,
|
|
147
|
-
injectedHeaders
|
|
147
|
+
injectedHeaders: Record<string, string>
|
|
148
148
|
) {
|
|
149
149
|
return registerComponents(
|
|
150
150
|
this.cliVersion,
|