@superblocksteam/sdk 0.0.11
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 +51 -0
- package/README.md +0 -0
- package/dist/client.d.ts +8 -0
- package/dist/client.js +125 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/sdk.d.ts +13 -0
- package/dist/sdk.js +34 -0
- package/package.json +38 -0
- package/src/client.ts +173 -0
- package/src/index.ts +2 -0
- package/src/sdk.ts +74 -0
- package/tsconfig.json +12 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
3
|
+
"plugins": [
|
|
4
|
+
"@typescript-eslint",
|
|
5
|
+
"prettier",
|
|
6
|
+
"import",
|
|
7
|
+
"unicorn"
|
|
8
|
+
],
|
|
9
|
+
"extends": [
|
|
10
|
+
"eslint:recommended",
|
|
11
|
+
"plugin:@typescript-eslint/recommended",
|
|
12
|
+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
|
13
|
+
"plugin:prettier/recommended",
|
|
14
|
+
"prettier",
|
|
15
|
+
"plugin:import/typescript"
|
|
16
|
+
],
|
|
17
|
+
"parserOptions": {
|
|
18
|
+
"ecmaVersion": 2020,
|
|
19
|
+
"sourceType": "module",
|
|
20
|
+
"project": "./tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"rules": {
|
|
23
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
24
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
25
|
+
"@typescript-eslint/no-unused-vars": "error",
|
|
26
|
+
"@typescript-eslint/no-var-requires": "off",
|
|
27
|
+
"@typescript-eslint/no-unsafe-return": "off",
|
|
28
|
+
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
29
|
+
"import/order": [
|
|
30
|
+
"error",
|
|
31
|
+
{
|
|
32
|
+
"alphabetize": { "order": "asc" },
|
|
33
|
+
"groups": [
|
|
34
|
+
"builtin",
|
|
35
|
+
"external",
|
|
36
|
+
"internal",
|
|
37
|
+
"parent",
|
|
38
|
+
"sibling",
|
|
39
|
+
"index",
|
|
40
|
+
"object",
|
|
41
|
+
"type"
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"import/no-cycle": "error",
|
|
46
|
+
"no-template-curly-in-string": "off",
|
|
47
|
+
"no-useless-escape": "off",
|
|
48
|
+
"no-void": ["error", { "allowAsStatement": true }]
|
|
49
|
+
},
|
|
50
|
+
"ignorePatterns": ["public", "build", "node_modules", "dist"]
|
|
51
|
+
}
|
package/README.md
ADDED
|
File without changes
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ViewMode = "export-deployed" | "export-latest" | "export-live";
|
|
2
|
+
export declare function fetchApplication(applicationId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
|
|
3
|
+
export declare function fetchApplications(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
4
|
+
export declare function fetchApi(apiId: string, token: string, superblocksBaseUrl: string, viewMode: ViewMode): Promise<any>;
|
|
5
|
+
export declare function fetchApis(token: string, superblocksBaseUrl: string): Promise<any>;
|
|
6
|
+
export declare function registerComponents(applicationId: string, componentConfigs: Record<string, any>, token: string, superblocksBaseUrl: string): Promise<any>;
|
|
7
|
+
export declare function uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[], token: string, superblocksBaseUrl: string): Promise<any>;
|
|
8
|
+
export declare function fetchCurrentUser(token: string, superblocksBaseUrl: string): Promise<any>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchCurrentUser = exports.uploadComponents = exports.registerComponents = exports.fetchApis = exports.fetchApi = exports.fetchApplications = exports.fetchApplication = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const BASE_SERVER_URL = "api/v1";
|
|
6
|
+
async function fetchApplication(applicationId, token, superblocksBaseUrl, viewMode) {
|
|
7
|
+
const url = `/api/v2/applications/${applicationId}?viewMode=${viewMode}`;
|
|
8
|
+
const config = {
|
|
9
|
+
method: "get",
|
|
10
|
+
url: new URL(url, superblocksBaseUrl).toString(),
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: "Bearer " + token,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
const response = await (0, axios_1.default)(config);
|
|
16
|
+
if (response.status !== 200) {
|
|
17
|
+
throw new Error("Could not fetch application");
|
|
18
|
+
}
|
|
19
|
+
return response.data.data;
|
|
20
|
+
}
|
|
21
|
+
exports.fetchApplication = fetchApplication;
|
|
22
|
+
async function fetchApplications(token, superblocksBaseUrl) {
|
|
23
|
+
const config = {
|
|
24
|
+
method: "get",
|
|
25
|
+
url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: "Bearer " + token,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const response = await (0, axios_1.default)(config);
|
|
31
|
+
if (response.status !== 200) {
|
|
32
|
+
throw new Error("Could not fetch applications");
|
|
33
|
+
}
|
|
34
|
+
return response.data.data.applications;
|
|
35
|
+
}
|
|
36
|
+
exports.fetchApplications = fetchApplications;
|
|
37
|
+
async function fetchApi(apiId, token, superblocksBaseUrl, viewMode) {
|
|
38
|
+
const config = {
|
|
39
|
+
method: "get",
|
|
40
|
+
url: new URL(`/api/v3/apis/${apiId}?viewMode=${viewMode}`, superblocksBaseUrl).toString(),
|
|
41
|
+
headers: {
|
|
42
|
+
Authorization: "Bearer " + token,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const response = await (0, axios_1.default)(config);
|
|
46
|
+
if (response.status !== 200) {
|
|
47
|
+
throw new Error("Could not fetch api");
|
|
48
|
+
}
|
|
49
|
+
return response.data.data;
|
|
50
|
+
}
|
|
51
|
+
exports.fetchApi = fetchApi;
|
|
52
|
+
async function fetchApis(token, superblocksBaseUrl) {
|
|
53
|
+
const config = {
|
|
54
|
+
method: "get",
|
|
55
|
+
url: new URL(`/api/v3/apis`, superblocksBaseUrl).toString(),
|
|
56
|
+
headers: {
|
|
57
|
+
Authorization: "Bearer " + token,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const response = await (0, axios_1.default)(config);
|
|
61
|
+
if (response.status !== 200) {
|
|
62
|
+
throw new Error("Could not fetch apis");
|
|
63
|
+
}
|
|
64
|
+
return response.data.data;
|
|
65
|
+
}
|
|
66
|
+
exports.fetchApis = fetchApis;
|
|
67
|
+
async function registerComponents(applicationId, componentConfigs, token, superblocksBaseUrl) {
|
|
68
|
+
const config = {
|
|
69
|
+
method: "put",
|
|
70
|
+
url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}/components`, superblocksBaseUrl).toString(),
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: "Bearer " + token,
|
|
73
|
+
},
|
|
74
|
+
data: { components: componentConfigs },
|
|
75
|
+
};
|
|
76
|
+
try {
|
|
77
|
+
const response = await (0, axios_1.default)(config);
|
|
78
|
+
if (response.status !== 200) {
|
|
79
|
+
throw new Error("Could not register application components");
|
|
80
|
+
}
|
|
81
|
+
return response.data;
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
console.error(config.url);
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.registerComponents = registerComponents;
|
|
89
|
+
async function uploadComponents(applicationId, componentConfigs, files, token, superblocksBaseUrl) {
|
|
90
|
+
const config = {
|
|
91
|
+
method: "post",
|
|
92
|
+
url: new URL(`${BASE_SERVER_URL}/public/application/${applicationId}/publish`, superblocksBaseUrl).toString(),
|
|
93
|
+
headers: {
|
|
94
|
+
Authorization: "Bearer " + token,
|
|
95
|
+
},
|
|
96
|
+
data: { components: componentConfigs, files },
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
const response = await (0, axios_1.default)(config);
|
|
100
|
+
if (response.status !== 200) {
|
|
101
|
+
throw new Error("Could not register application components");
|
|
102
|
+
}
|
|
103
|
+
return response.data;
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
console.error(config.url);
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.uploadComponents = uploadComponents;
|
|
111
|
+
async function fetchCurrentUser(token, superblocksBaseUrl) {
|
|
112
|
+
const config = {
|
|
113
|
+
method: "get",
|
|
114
|
+
url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
|
|
115
|
+
headers: {
|
|
116
|
+
Authorization: "Bearer " + token,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
const response = await (0, axios_1.default)(config);
|
|
120
|
+
if (response.status !== 200) {
|
|
121
|
+
throw new Error("Could not fetch current user");
|
|
122
|
+
}
|
|
123
|
+
return response.data.data.user;
|
|
124
|
+
}
|
|
125
|
+
exports.fetchCurrentUser = fetchCurrentUser;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ViewMode } from "./client";
|
|
2
|
+
export declare class SuperblocksSdk {
|
|
3
|
+
token: string;
|
|
4
|
+
superblocksBaseUrl: string;
|
|
5
|
+
constructor(accessToken: string, superblocksBaseUrl: string);
|
|
6
|
+
fetchApplication(applicationId: string, viewMode?: ViewMode): Promise<any>;
|
|
7
|
+
fetchApplications(): Promise<any>;
|
|
8
|
+
fetchApi(apiId: string, viewMode?: ViewMode): Promise<any>;
|
|
9
|
+
fetchApis(): Promise<any>;
|
|
10
|
+
registerComponents(applicationId: string, componentConfigs: Record<string, any>): Promise<any>;
|
|
11
|
+
uploadComponents(applicationId: string, componentConfigs: Record<string, any>, files: string[]): Promise<any>;
|
|
12
|
+
fetchCurrentUser(): Promise<any>;
|
|
13
|
+
}
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SuperblocksSdk = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
class SuperblocksSdk {
|
|
6
|
+
constructor(accessToken, superblocksBaseUrl) {
|
|
7
|
+
this.token = "";
|
|
8
|
+
this.superblocksBaseUrl = "";
|
|
9
|
+
this.token = accessToken;
|
|
10
|
+
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
11
|
+
}
|
|
12
|
+
async fetchApplication(applicationId, viewMode = "export-live") {
|
|
13
|
+
return (0, client_1.fetchApplication)(applicationId, this.token, this.superblocksBaseUrl, viewMode);
|
|
14
|
+
}
|
|
15
|
+
async fetchApplications() {
|
|
16
|
+
return (0, client_1.fetchApplications)(this.token, this.superblocksBaseUrl);
|
|
17
|
+
}
|
|
18
|
+
async fetchApi(apiId, viewMode = "export-live") {
|
|
19
|
+
return (0, client_1.fetchApi)(apiId, this.token, this.superblocksBaseUrl, viewMode);
|
|
20
|
+
}
|
|
21
|
+
async fetchApis() {
|
|
22
|
+
return (0, client_1.fetchApis)(this.token, this.superblocksBaseUrl);
|
|
23
|
+
}
|
|
24
|
+
async registerComponents(applicationId, componentConfigs) {
|
|
25
|
+
return (0, client_1.registerComponents)(applicationId, componentConfigs, this.token, this.superblocksBaseUrl);
|
|
26
|
+
}
|
|
27
|
+
async uploadComponents(applicationId, componentConfigs, files) {
|
|
28
|
+
return (0, client_1.uploadComponents)(applicationId, componentConfigs, files, this.token, this.superblocksBaseUrl);
|
|
29
|
+
}
|
|
30
|
+
async fetchCurrentUser() {
|
|
31
|
+
return (0, client_1.fetchCurrentUser)(this.token, this.superblocksBaseUrl);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.SuperblocksSdk = SuperblocksSdk;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@superblocksteam/sdk",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "Superblocks JS SDK",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/sdk.mjs",
|
|
9
|
+
"require": "./dist/sdk.js",
|
|
10
|
+
"types": "./dist/sdk.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "tsc --watch",
|
|
16
|
+
"build": "tsc --build",
|
|
17
|
+
"clean": "npm run clean:build && rm -rf node_modules",
|
|
18
|
+
"clean:build": "tsc --build --clean && rm -rf dist tsconfig.tsbuildinfo",
|
|
19
|
+
"lint": "eslint . --ext .ts --config .eslintrc.json",
|
|
20
|
+
"lint:fix": "eslint . --ext .ts --config .eslintrc.json --fix"
|
|
21
|
+
},
|
|
22
|
+
"license": "Superblocks Community Software License",
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@typescript-eslint/eslint-plugin": "^5.60.1",
|
|
25
|
+
"@typescript-eslint/parser": "^5.60.1",
|
|
26
|
+
"eslint": "^8.45.0",
|
|
27
|
+
"eslint-plugin-unicorn": "^47.0.0",
|
|
28
|
+
"prettier": "^2.8.8",
|
|
29
|
+
"typescript": "^5.1.3"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"axios": "^1.3.5"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://www.superblocks.com",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=14.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
|
|
3
|
+
const BASE_SERVER_URL = "api/v1";
|
|
4
|
+
|
|
5
|
+
export type ViewMode = "export-deployed" | "export-latest" | "export-live";
|
|
6
|
+
|
|
7
|
+
export async function fetchApplication(
|
|
8
|
+
applicationId: string,
|
|
9
|
+
token: string,
|
|
10
|
+
superblocksBaseUrl: string,
|
|
11
|
+
viewMode: ViewMode
|
|
12
|
+
) {
|
|
13
|
+
const url = `/api/v2/applications/${applicationId}?viewMode=${viewMode}`;
|
|
14
|
+
const config = {
|
|
15
|
+
method: "get",
|
|
16
|
+
url: new URL(url, superblocksBaseUrl).toString(),
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: "Bearer " + token,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const response = await axios(config);
|
|
23
|
+
if (response.status !== 200) {
|
|
24
|
+
throw new Error("Could not fetch application");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return response.data.data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function fetchApplications(
|
|
31
|
+
token: string,
|
|
32
|
+
superblocksBaseUrl: string
|
|
33
|
+
) {
|
|
34
|
+
const config = {
|
|
35
|
+
method: "get",
|
|
36
|
+
url: new URL(`/api/v2/applications`, superblocksBaseUrl).toString(),
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: "Bearer " + token,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const response = await axios(config);
|
|
43
|
+
if (response.status !== 200) {
|
|
44
|
+
throw new Error("Could not fetch applications");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return response.data.data.applications;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function fetchApi(
|
|
51
|
+
apiId: string,
|
|
52
|
+
token: string,
|
|
53
|
+
superblocksBaseUrl: string,
|
|
54
|
+
viewMode: ViewMode
|
|
55
|
+
) {
|
|
56
|
+
const config = {
|
|
57
|
+
method: "get",
|
|
58
|
+
url: new URL(
|
|
59
|
+
`/api/v3/apis/${apiId}?viewMode=${viewMode}`,
|
|
60
|
+
superblocksBaseUrl
|
|
61
|
+
).toString(),
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: "Bearer " + token,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const response = await axios(config);
|
|
68
|
+
if (response.status !== 200) {
|
|
69
|
+
throw new Error("Could not fetch api");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return response.data.data;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function fetchApis(token: string, superblocksBaseUrl: string) {
|
|
76
|
+
const config = {
|
|
77
|
+
method: "get",
|
|
78
|
+
url: new URL(`/api/v3/apis`, superblocksBaseUrl).toString(),
|
|
79
|
+
headers: {
|
|
80
|
+
Authorization: "Bearer " + token,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const response = await axios(config);
|
|
85
|
+
if (response.status !== 200) {
|
|
86
|
+
throw new Error("Could not fetch apis");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return response.data.data;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function registerComponents(
|
|
93
|
+
applicationId: string,
|
|
94
|
+
componentConfigs: Record<string, any>,
|
|
95
|
+
token: string,
|
|
96
|
+
superblocksBaseUrl: string
|
|
97
|
+
) {
|
|
98
|
+
const config = {
|
|
99
|
+
method: "put",
|
|
100
|
+
url: new URL(
|
|
101
|
+
`${BASE_SERVER_URL}/public/application/${applicationId}/components`,
|
|
102
|
+
superblocksBaseUrl
|
|
103
|
+
).toString(),
|
|
104
|
+
headers: {
|
|
105
|
+
Authorization: "Bearer " + token,
|
|
106
|
+
},
|
|
107
|
+
data: { components: componentConfigs },
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const response = await axios(config);
|
|
112
|
+
if (response.status !== 200) {
|
|
113
|
+
throw new Error("Could not register application components");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return response.data;
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.error(config.url);
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function uploadComponents(
|
|
124
|
+
applicationId: string,
|
|
125
|
+
componentConfigs: Record<string, any>,
|
|
126
|
+
files: string[],
|
|
127
|
+
token: string,
|
|
128
|
+
superblocksBaseUrl: string
|
|
129
|
+
) {
|
|
130
|
+
const config = {
|
|
131
|
+
method: "post",
|
|
132
|
+
url: new URL(
|
|
133
|
+
`${BASE_SERVER_URL}/public/application/${applicationId}/publish`,
|
|
134
|
+
superblocksBaseUrl
|
|
135
|
+
).toString(),
|
|
136
|
+
headers: {
|
|
137
|
+
Authorization: "Bearer " + token,
|
|
138
|
+
},
|
|
139
|
+
data: { components: componentConfigs, files },
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const response = await axios(config);
|
|
144
|
+
if (response.status !== 200) {
|
|
145
|
+
throw new Error("Could not register application components");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return response.data;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
console.error(config.url);
|
|
151
|
+
throw e;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export async function fetchCurrentUser(
|
|
156
|
+
token: string,
|
|
157
|
+
superblocksBaseUrl: string
|
|
158
|
+
) {
|
|
159
|
+
const config = {
|
|
160
|
+
method: "get",
|
|
161
|
+
url: new URL(`/api/v1/users/me`, superblocksBaseUrl).toString(),
|
|
162
|
+
headers: {
|
|
163
|
+
Authorization: "Bearer " + token,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const response = await axios(config);
|
|
168
|
+
if (response.status !== 200) {
|
|
169
|
+
throw new Error("Could not fetch current user");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return response.data.data.user;
|
|
173
|
+
}
|
package/src/index.ts
ADDED
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fetchApi,
|
|
3
|
+
fetchApis,
|
|
4
|
+
fetchApplication,
|
|
5
|
+
fetchApplications,
|
|
6
|
+
registerComponents,
|
|
7
|
+
uploadComponents,
|
|
8
|
+
fetchCurrentUser,
|
|
9
|
+
ViewMode,
|
|
10
|
+
} from "./client";
|
|
11
|
+
|
|
12
|
+
export class SuperblocksSdk {
|
|
13
|
+
token = "";
|
|
14
|
+
superblocksBaseUrl = "";
|
|
15
|
+
|
|
16
|
+
constructor(accessToken: string, superblocksBaseUrl: string) {
|
|
17
|
+
this.token = accessToken;
|
|
18
|
+
this.superblocksBaseUrl = superblocksBaseUrl;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async fetchApplication(
|
|
22
|
+
applicationId: string,
|
|
23
|
+
viewMode: ViewMode = "export-live"
|
|
24
|
+
) {
|
|
25
|
+
return fetchApplication(
|
|
26
|
+
applicationId,
|
|
27
|
+
this.token,
|
|
28
|
+
this.superblocksBaseUrl,
|
|
29
|
+
viewMode
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async fetchApplications() {
|
|
34
|
+
return fetchApplications(this.token, this.superblocksBaseUrl);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async fetchApi(apiId: string, viewMode: ViewMode = "export-live") {
|
|
38
|
+
return fetchApi(apiId, this.token, this.superblocksBaseUrl, viewMode);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async fetchApis() {
|
|
42
|
+
return fetchApis(this.token, this.superblocksBaseUrl);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async registerComponents(
|
|
46
|
+
applicationId: string,
|
|
47
|
+
componentConfigs: Record<string, any>
|
|
48
|
+
) {
|
|
49
|
+
return registerComponents(
|
|
50
|
+
applicationId,
|
|
51
|
+
componentConfigs,
|
|
52
|
+
this.token,
|
|
53
|
+
this.superblocksBaseUrl
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async uploadComponents(
|
|
58
|
+
applicationId: string,
|
|
59
|
+
componentConfigs: Record<string, any>,
|
|
60
|
+
files: string[]
|
|
61
|
+
) {
|
|
62
|
+
return uploadComponents(
|
|
63
|
+
applicationId,
|
|
64
|
+
componentConfigs,
|
|
65
|
+
files,
|
|
66
|
+
this.token,
|
|
67
|
+
this.superblocksBaseUrl
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async fetchCurrentUser() {
|
|
72
|
+
return fetchCurrentUser(this.token, this.superblocksBaseUrl);
|
|
73
|
+
}
|
|
74
|
+
}
|