@embeddable.com/sdk-core 3.13.5 → 3.13.6-next.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/lib/buildTypes.d.ts +2 -1
- package/lib/cleanup.d.ts +3 -2
- package/lib/defineConfig.d.ts +25 -2
- package/lib/generate.d.ts +2 -1
- package/lib/globalCleanup.d.ts +2 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +248 -68
- package/lib/index.esm.js.map +1 -1
- package/lib/prepare.d.ts +3 -2
- package/lib/provideConfig.d.ts +2 -1
- package/lib/validate.d.ts +2 -1
- package/lib/workspaceUtils.d.ts +4 -2
- package/package.json +4 -3
- package/src/build.test.ts +4 -1
- package/src/buildTypes.test.ts +6 -3
- package/src/buildTypes.ts +5 -5
- package/src/cleanup.test.ts +2 -2
- package/src/cleanup.ts +5 -4
- package/src/defineConfig.test.ts +6 -0
- package/src/defineConfig.ts +26 -2
- package/src/dev.test.ts +4 -2
- package/src/dev.ts +20 -14
- package/src/generate.test.ts +4 -3
- package/src/generate.ts +21 -9
- package/src/globalCleanup.ts +4 -2
- package/src/index.ts +1 -0
- package/src/prepare.ts +12 -7
- package/src/provideConfig.ts +2 -1
- package/src/push.test.ts +12 -6
- package/src/rollbar.test.ts +4 -1
- package/src/validate.ts +2 -2
- package/src/workspaceUtils.test.ts +24 -9
- package/src/workspaceUtils.ts +9 -3
- package/lib/index.js +0 -22627
- package/lib/index.js.map +0 -1
package/src/rollbar.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import reportErrorToRollbar from "./rollbar.mjs";
|
|
3
3
|
import provideConfig from "./provideConfig";
|
|
4
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
4
5
|
import Rollbar from "rollbar";
|
|
5
6
|
import * as path from "node:path";
|
|
6
7
|
import * as fs from "node:fs/promises";
|
|
@@ -57,7 +58,9 @@ const rollbarInstanceMock = {
|
|
|
57
58
|
|
|
58
59
|
describe("rollbar", () => {
|
|
59
60
|
beforeEach(() => {
|
|
60
|
-
vi.mocked(provideConfig).mockResolvedValue(
|
|
61
|
+
vi.mocked(provideConfig).mockResolvedValue(
|
|
62
|
+
config as ResolvedEmbeddableConfig,
|
|
63
|
+
);
|
|
61
64
|
vi.mocked(Rollbar).mockReturnValue(rollbarInstanceMock as any);
|
|
62
65
|
vi.mocked(path.resolve).mockReturnValue("resolvedPath");
|
|
63
66
|
|
package/src/validate.ts
CHANGED
|
@@ -4,12 +4,12 @@ import { errorFormatter, findFiles } from "@embeddable.com/sdk-utils";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import ora from "ora";
|
|
6
6
|
import { checkNodeVersion } from "./utils";
|
|
7
|
-
|
|
7
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
8
8
|
const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;
|
|
9
9
|
const SECURITY_CONTEXT_FILE_REGEX = /^(.*)\.sc\.ya?ml$/;
|
|
10
10
|
const CLIENT_CONTEXT_FILE_REGEX = /^(.*)\.cc\.ya?ml$/;
|
|
11
11
|
|
|
12
|
-
export default async (ctx:
|
|
12
|
+
export default async (ctx: ResolvedEmbeddableConfig) => {
|
|
13
13
|
checkNodeVersion();
|
|
14
14
|
|
|
15
15
|
const spinnerValidate = ora("Data model validation...").start();
|
|
@@ -2,7 +2,8 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import { getWorkspaces, selectWorkspace } from "./workspaceUtils";
|
|
4
4
|
import { select } from "@inquirer/prompts";
|
|
5
|
-
|
|
5
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
6
|
+
import { Ora } from "ora";
|
|
6
7
|
vi.mock("axios");
|
|
7
8
|
|
|
8
9
|
vi.mock("@inquirer/prompts", () => ({
|
|
@@ -23,7 +24,11 @@ describe("workspaceUtils", () => {
|
|
|
23
24
|
|
|
24
25
|
(axios.get as any).mockResolvedValue({ data: workspaces });
|
|
25
26
|
|
|
26
|
-
const result = await getWorkspaces(
|
|
27
|
+
const result = await getWorkspaces(
|
|
28
|
+
ctx as ResolvedEmbeddableConfig,
|
|
29
|
+
token,
|
|
30
|
+
workspaceSpinner as unknown as Ora,
|
|
31
|
+
);
|
|
27
32
|
|
|
28
33
|
expect(result).toEqual([
|
|
29
34
|
{ name: "Workspace 1", workspaceId: "1", devWorkspace: false },
|
|
@@ -33,12 +38,12 @@ describe("workspaceUtils", () => {
|
|
|
33
38
|
it("should handle unauthorized error", async () => {
|
|
34
39
|
const ctx = { pushBaseUrl: "http://example.com" };
|
|
35
40
|
const token = "test-token";
|
|
36
|
-
const workspaceSpinner = { fail: vi.fn() };
|
|
41
|
+
const workspaceSpinner = { fail: vi.fn() } as unknown as Ora;
|
|
37
42
|
|
|
38
43
|
(axios.get as any).mockRejectedValue({ response: { status: 401 } });
|
|
39
44
|
|
|
40
45
|
await expect(
|
|
41
|
-
getWorkspaces(ctx, token, workspaceSpinner),
|
|
46
|
+
getWorkspaces(ctx as ResolvedEmbeddableConfig, token, workspaceSpinner),
|
|
42
47
|
).rejects.toThrow();
|
|
43
48
|
expect(workspaceSpinner.fail).toHaveBeenCalledWith(
|
|
44
49
|
'Unauthorized. Please login using "embeddable login" command.',
|
|
@@ -48,12 +53,12 @@ describe("workspaceUtils", () => {
|
|
|
48
53
|
it("should handle other errors", async () => {
|
|
49
54
|
const ctx = { pushBaseUrl: "http://example.com" };
|
|
50
55
|
const token = "test-token";
|
|
51
|
-
const workspaceSpinner = { fail: vi.fn() };
|
|
56
|
+
const workspaceSpinner = { fail: vi.fn() } as unknown as Ora;
|
|
52
57
|
|
|
53
58
|
(axios.get as any).mockRejectedValue({ response: { status: 500 } });
|
|
54
59
|
|
|
55
60
|
await expect(
|
|
56
|
-
getWorkspaces(ctx, token, workspaceSpinner),
|
|
61
|
+
getWorkspaces(ctx as ResolvedEmbeddableConfig, token, workspaceSpinner),
|
|
57
62
|
).rejects.toThrow();
|
|
58
63
|
expect(workspaceSpinner.fail).toHaveBeenCalledWith(
|
|
59
64
|
"Failed to fetch workspaces",
|
|
@@ -87,7 +92,11 @@ describe("workspaceUtils", () => {
|
|
|
87
92
|
|
|
88
93
|
(axios.get as any).mockResolvedValue({ data: workspaces });
|
|
89
94
|
|
|
90
|
-
const selectedWorkspace = await selectWorkspace(
|
|
95
|
+
const selectedWorkspace = await selectWorkspace(
|
|
96
|
+
ora,
|
|
97
|
+
ctx as ResolvedEmbeddableConfig,
|
|
98
|
+
token,
|
|
99
|
+
);
|
|
91
100
|
|
|
92
101
|
expect(selectedWorkspace).toEqual(workspaces[0]);
|
|
93
102
|
expect(ora().succeed).toHaveBeenCalledWith(`Workspace: Workspace 1 (1)`);
|
|
@@ -110,7 +119,11 @@ describe("workspaceUtils", () => {
|
|
|
110
119
|
|
|
111
120
|
(axios.get as any).mockResolvedValue({ data: workspaces });
|
|
112
121
|
|
|
113
|
-
const selectedWorkspace = await selectWorkspace(
|
|
122
|
+
const selectedWorkspace = await selectWorkspace(
|
|
123
|
+
ora,
|
|
124
|
+
ctx as ResolvedEmbeddableConfig,
|
|
125
|
+
token,
|
|
126
|
+
);
|
|
114
127
|
|
|
115
128
|
expect(selectedWorkspace).toEqual(workspaces[1]);
|
|
116
129
|
expect(ora().succeed).toHaveBeenCalledWith(`Workspace: Workspace 2 (2)`);
|
|
@@ -128,7 +141,9 @@ describe("workspaceUtils", () => {
|
|
|
128
141
|
|
|
129
142
|
(axios.get as any).mockResolvedValue({ data: [] });
|
|
130
143
|
|
|
131
|
-
await expect(
|
|
144
|
+
await expect(
|
|
145
|
+
selectWorkspace(ora, ctx as ResolvedEmbeddableConfig, token),
|
|
146
|
+
).rejects.toThrow();
|
|
132
147
|
expect(ora().fail).toHaveBeenCalledWith("No workspaces found");
|
|
133
148
|
});
|
|
134
149
|
});
|
package/src/workspaceUtils.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { select } from "@inquirer/prompts";
|
|
2
2
|
import axios from "axios";
|
|
3
|
+
import { ResolvedEmbeddableConfig } from "./defineConfig";
|
|
4
|
+
import { Options, Ora } from "ora";
|
|
3
5
|
|
|
4
6
|
export async function getWorkspaces(
|
|
5
|
-
ctx:
|
|
7
|
+
ctx: ResolvedEmbeddableConfig,
|
|
6
8
|
token: string,
|
|
7
|
-
workspaceSpinner:
|
|
9
|
+
workspaceSpinner: Ora,
|
|
8
10
|
) {
|
|
9
11
|
try {
|
|
10
12
|
const response = await axios.get(`${ctx.pushBaseUrl}/workspace`, {
|
|
@@ -30,7 +32,11 @@ export async function getWorkspaces(
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
export async function selectWorkspace(
|
|
35
|
+
export async function selectWorkspace(
|
|
36
|
+
ora: (options?: string | Options) => Ora,
|
|
37
|
+
ctx: ResolvedEmbeddableConfig,
|
|
38
|
+
token: string,
|
|
39
|
+
) {
|
|
34
40
|
const workspaceSpinner = ora({
|
|
35
41
|
text: `Fetching workspaces using ${ctx.pushBaseUrl}...`,
|
|
36
42
|
color: "green",
|