@embeddable.com/sdk-core 1.0.0 → 2.0.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/bin/embeddable +1 -1
- package/dist/build.d.ts +2 -0
- package/dist/buildTypes.d.ts +2 -0
- package/dist/cleanup.d.ts +2 -0
- package/dist/createContext.d.ts +20 -0
- package/dist/generate.d.ts +2 -0
- package/dist/globalCleanup.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +416 -0
- package/dist/login.d.ts +3 -0
- package/dist/prepare.d.ts +2 -0
- package/dist/push.d.ts +2 -0
- package/dist/validate.d.ts +2 -0
- package/lib/defineConfig.d.ts +22 -0
- package/lib/embedType.d.ts +4 -1
- package/lib/index.cjs.js +41 -15
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +41 -16
- package/lib/index.umd.js +43 -19
- package/lib/loadData.d.ts +8 -4
- package/package.json +6 -2
- package/templates/component.tsx.template +4 -0
- package/scripts/build.js +0 -20
- package/scripts/buildTypes.js +0 -61
- package/scripts/cleanup.js +0 -27
- package/scripts/createContext.js +0 -27
- package/scripts/findEmbFiles.js +0 -32
- package/scripts/generate.js +0 -72
- package/scripts/globalCleanup.js +0 -13
- package/scripts/index.js +0 -17
- package/scripts/login.js +0 -93
- package/scripts/prepare.js +0 -27
- package/scripts/push.js +0 -153
- package/scripts/validate.js +0 -66
package/scripts/push.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
const fs = require("fs/promises");
|
|
2
|
-
const fsSync = require("fs");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const archiver = require("archiver");
|
|
5
|
-
const axios = require("axios");
|
|
6
|
-
const oraP = import("ora");
|
|
7
|
-
const inquirerSelect = import("@inquirer/select");
|
|
8
|
-
|
|
9
|
-
const { findEmbFiles } = require("./findEmbFiles");
|
|
10
|
-
const { createContext } = require("./createContext");
|
|
11
|
-
const { getToken } = require("./login");
|
|
12
|
-
|
|
13
|
-
const EMB_YAML_FILE_REGEX = /^(.*)\.emb\.ya?ml$/;
|
|
14
|
-
|
|
15
|
-
let ora;
|
|
16
|
-
async function push() {
|
|
17
|
-
ora = (await oraP).default;
|
|
18
|
-
|
|
19
|
-
const ctx = createContext(path.resolve(__dirname, ".."), process.cwd());
|
|
20
|
-
|
|
21
|
-
const token = await verify(ctx);
|
|
22
|
-
|
|
23
|
-
const { workspaceId, workspaceName } = await selectWorkspace(token);
|
|
24
|
-
|
|
25
|
-
const spinnerArchive = ora("archivation...").start();
|
|
26
|
-
|
|
27
|
-
const filesList = await findEmbFiles(ctx.client.srcDir, EMB_YAML_FILE_REGEX);
|
|
28
|
-
|
|
29
|
-
await archive(ctx, filesList);
|
|
30
|
-
spinnerArchive.succeed("archivation competed");
|
|
31
|
-
|
|
32
|
-
const spinnerPushing = ora("publishing...").start();
|
|
33
|
-
|
|
34
|
-
await sendBuild(ctx, { workspaceId, token });
|
|
35
|
-
spinnerPushing.succeed(`published to ${workspaceName}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = { push };
|
|
39
|
-
|
|
40
|
-
async function selectWorkspace(token) {
|
|
41
|
-
const workspaceSpinner = ora({
|
|
42
|
-
text: "Fetching workspaces...",
|
|
43
|
-
color: "green",
|
|
44
|
-
discardStdin: false,
|
|
45
|
-
}).start();
|
|
46
|
-
|
|
47
|
-
const availableWorkspaces = await getWorkspaces(token);
|
|
48
|
-
|
|
49
|
-
let selectedWorkspace;
|
|
50
|
-
|
|
51
|
-
if (availableWorkspaces.length === 0) {
|
|
52
|
-
workspaceSpinner.fail("No workspaces found");
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
workspaceSpinner.info(`Found ${availableWorkspaces.length} workspace(s)`);
|
|
57
|
-
|
|
58
|
-
if (availableWorkspaces.length === 1) {
|
|
59
|
-
selectedWorkspace = availableWorkspaces[0];
|
|
60
|
-
} else {
|
|
61
|
-
const select = (await inquirerSelect).default;
|
|
62
|
-
selectedWorkspace = await select({
|
|
63
|
-
message: "Select workspace to push changes",
|
|
64
|
-
choices: availableWorkspaces.map((workspace) => ({
|
|
65
|
-
name: `${workspace.name} (${workspace.workspaceId})`,
|
|
66
|
-
value: workspace,
|
|
67
|
-
})),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
workspaceSpinner.succeed(`Workspace: ${selectedWorkspace.name} (${selectedWorkspace.workspaceId})`);
|
|
72
|
-
|
|
73
|
-
return selectedWorkspace;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function verify(ctx) {
|
|
77
|
-
try {
|
|
78
|
-
await fs.access(ctx.client.buildDir);
|
|
79
|
-
} catch (_e) {
|
|
80
|
-
console.error("No embeddable build was produced.");
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// TODO: initiate login if no/invalid token.
|
|
85
|
-
const token = await getToken();
|
|
86
|
-
|
|
87
|
-
if (!token) {
|
|
88
|
-
console.error("Expired token. Please login again.");
|
|
89
|
-
process.exit(1);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return token;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function archive(ctx, yamlFiles) {
|
|
96
|
-
const output = fsSync.createWriteStream(ctx.client.archiveFile);
|
|
97
|
-
const _archiver = archiver("zip", {
|
|
98
|
-
zlib: { level: 9 },
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
_archiver.pipe(output);
|
|
102
|
-
_archiver.directory(ctx.client.buildDir, false);
|
|
103
|
-
|
|
104
|
-
for (const fileData of yamlFiles) {
|
|
105
|
-
_archiver.file(fileData[1], { name: `${fileData[0]}.emb.yaml` });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
_archiver.finalize();
|
|
109
|
-
|
|
110
|
-
return new Promise((resolve, _reject) => {
|
|
111
|
-
output.on("close", resolve);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async function sendBuild(ctx, { workspaceId, token }) {
|
|
116
|
-
const { FormData } = await import("formdata-node");
|
|
117
|
-
const { fileFromPath } = await import("formdata-node/file-from-path");
|
|
118
|
-
|
|
119
|
-
const file = await fileFromPath(
|
|
120
|
-
ctx.client.archiveFile,
|
|
121
|
-
"embeddable-build.zip",
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const form = new FormData();
|
|
125
|
-
form.set("file", file, "embeddable-build.zip");
|
|
126
|
-
form.set("workspaceId", workspaceId);
|
|
127
|
-
|
|
128
|
-
await axios.post("https://metadata.embeddable.com/sdk/upload-files", form, {
|
|
129
|
-
headers: {
|
|
130
|
-
"Content-Type": "multipart/form-data",
|
|
131
|
-
Authorization: `Bearer ${token}`,
|
|
132
|
-
},
|
|
133
|
-
maxContentLength: Infinity,
|
|
134
|
-
maxBodyLength: Infinity,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
await fs.rm(ctx.client.archiveFile);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function getWorkspaces(token) {
|
|
141
|
-
try {
|
|
142
|
-
return axios
|
|
143
|
-
.get("https://api.embeddable.com/workspace", {
|
|
144
|
-
headers: {
|
|
145
|
-
Authorization: `Bearer ${token}`,
|
|
146
|
-
},
|
|
147
|
-
})
|
|
148
|
-
.then((res) => res.data);
|
|
149
|
-
} catch (e) {
|
|
150
|
-
console.error(e);
|
|
151
|
-
return [];
|
|
152
|
-
}
|
|
153
|
-
}
|
package/scripts/validate.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const fs = require("node:fs/promises");
|
|
2
|
-
const oraP = import("ora");
|
|
3
|
-
const YAML = require("yaml");
|
|
4
|
-
const { findEmbFiles } = require("./findEmbFiles");
|
|
5
|
-
|
|
6
|
-
const EMB_YAML_FILE_REGEX = /^(.*)\.emb\.ya?ml$/;
|
|
7
|
-
|
|
8
|
-
async function validate(ctx) {
|
|
9
|
-
const ora = (await oraP).default;
|
|
10
|
-
|
|
11
|
-
const spinnerValidate = ora("validation...").start();
|
|
12
|
-
|
|
13
|
-
const filesList = await findEmbFiles(ctx.client.srcDir, EMB_YAML_FILE_REGEX);
|
|
14
|
-
|
|
15
|
-
const componentConfigErrors = await componentConfigValidation(filesList);
|
|
16
|
-
|
|
17
|
-
if (componentConfigErrors.length) {
|
|
18
|
-
spinnerValidate.fail("One or more component.emb.yaml files are invalid:");
|
|
19
|
-
|
|
20
|
-
componentConfigErrors.forEach((errorMessage) =>
|
|
21
|
-
spinnerValidate.info(errorMessage),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
spinnerValidate.succeed("validation completed");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = { validate };
|
|
31
|
-
|
|
32
|
-
async function componentConfigValidation(filesList) {
|
|
33
|
-
const ARRAY_ALLOWED_TYPES = ["Dimension", "Measure"];
|
|
34
|
-
const errors = [];
|
|
35
|
-
|
|
36
|
-
for (const [fileName, filePath] of filesList) {
|
|
37
|
-
if (!fileName.endsWith(".component")) continue;
|
|
38
|
-
|
|
39
|
-
const fileContentRaw = await fs.readFile(filePath, "utf8");
|
|
40
|
-
|
|
41
|
-
const config = YAML.parse(fileContentRaw);
|
|
42
|
-
|
|
43
|
-
if (!("inputs" in config) || config.inputs.length === 0) continue;
|
|
44
|
-
|
|
45
|
-
config.inputs
|
|
46
|
-
.filter((inputConfig) => inputConfig?.array)
|
|
47
|
-
.forEach((inputConfig) => {
|
|
48
|
-
if (!ARRAY_ALLOWED_TYPES.includes(inputConfig?.type)) {
|
|
49
|
-
const errorMessage = `${fileName} contains invalid type value for \x1b[33m${
|
|
50
|
-
inputConfig.name
|
|
51
|
-
}\x1b[0m input.
|
|
52
|
-
\x1b[33m${
|
|
53
|
-
inputConfig.name
|
|
54
|
-
}\x1b[0m is marked as \x1b[33marray\x1b[0m. Inputs marked as array support the following types: ${ARRAY_ALLOWED_TYPES.join(
|
|
55
|
-
", ",
|
|
56
|
-
)}.
|
|
57
|
-
Specified \x1b[33m${inputConfig?.type}\x1b[0m type is not supported.
|
|
58
|
-
Please check the following file: \x1b[33m${filePath}\x1b[0m\n`;
|
|
59
|
-
|
|
60
|
-
errors.push(errorMessage);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return errors;
|
|
66
|
-
}
|