@embeddable.com/sdk-core 3.9.2 → 3.9.4
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/index.esm.js +237 -100
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +237 -100
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +9 -0
- package/lib/utils.d.ts +2 -1
- package/package.json +1 -1
- package/src/build.test.ts +6 -0
- package/src/build.ts +14 -0
- package/src/cleanup.test.ts +4 -0
- package/src/cleanup.ts +5 -19
- package/src/dev.test.ts +25 -0
- package/src/dev.ts +121 -100
- package/src/logger.test.ts +98 -0
- package/src/logger.ts +116 -0
- package/src/login.test.ts +5 -0
- package/src/login.ts +7 -1
- package/src/push.test.ts +2 -0
- package/src/push.ts +11 -6
- package/src/utils.test.ts +16 -0
- package/src/utils.ts +42 -1
package/src/login.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
import provideConfig from "./provideConfig";
|
|
4
|
+
import { initLogger, logError } from "./logger";
|
|
4
5
|
|
|
5
6
|
// @ts-ignore
|
|
6
7
|
import reportErrorToRollbar from "./rollbar.mjs";
|
|
@@ -9,14 +10,18 @@ const oraP = import("ora");
|
|
|
9
10
|
const openP = import("open");
|
|
10
11
|
|
|
11
12
|
export default async () => {
|
|
13
|
+
await initLogger("login");
|
|
14
|
+
const breadcrumbs: string[] = [];
|
|
12
15
|
const ora = (await oraP).default;
|
|
13
16
|
const authenticationSpinner = ora("Waiting for code verification...").start();
|
|
14
17
|
|
|
15
18
|
try {
|
|
16
19
|
const open = (await openP).default;
|
|
17
20
|
const config = await provideConfig();
|
|
21
|
+
breadcrumbs.push("provideConfig");
|
|
18
22
|
|
|
19
23
|
await resolveFiles();
|
|
24
|
+
breadcrumbs.push("resolveFiles");
|
|
20
25
|
|
|
21
26
|
const deviceCodePayload = {
|
|
22
27
|
client_id: config.authClientId,
|
|
@@ -70,8 +75,9 @@ export default async () => {
|
|
|
70
75
|
await sleep(deviceCodeResponse.data["interval"] * 1000);
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
|
-
} catch (error) {
|
|
78
|
+
} catch (error: unknown) {
|
|
74
79
|
authenticationSpinner.fail("Authentication failed. Please try again.");
|
|
80
|
+
await logError({ command: "login", breadcrumbs, error });
|
|
75
81
|
await reportErrorToRollbar(error);
|
|
76
82
|
console.log(error);
|
|
77
83
|
|
package/src/push.test.ts
CHANGED
|
@@ -35,6 +35,7 @@ vi.mock("./utils", () => ({
|
|
|
35
35
|
checkNodeVersion: vi.fn(),
|
|
36
36
|
checkBuildSuccess: vi.fn(),
|
|
37
37
|
getArgumentByKey: vi.fn(),
|
|
38
|
+
getSDKVersions: vi.fn(),
|
|
38
39
|
}));
|
|
39
40
|
|
|
40
41
|
vi.mock("node:fs/promises", () => ({
|
|
@@ -42,6 +43,7 @@ vi.mock("node:fs/promises", () => ({
|
|
|
42
43
|
readFile: vi.fn(),
|
|
43
44
|
access: vi.fn(),
|
|
44
45
|
rm: vi.fn(),
|
|
46
|
+
mkdir: vi.fn(),
|
|
45
47
|
}));
|
|
46
48
|
|
|
47
49
|
vi.mock("node:fs", () => ({
|
package/src/push.ts
CHANGED
|
@@ -3,6 +3,8 @@ import * as fsSync from "node:fs";
|
|
|
3
3
|
import * as archiver from "archiver";
|
|
4
4
|
import axios from "axios";
|
|
5
5
|
const oraP = import("ora");
|
|
6
|
+
import { initLogger, logError } from "./logger";
|
|
7
|
+
import * as path from "path";
|
|
6
8
|
|
|
7
9
|
import provideConfig from "./provideConfig";
|
|
8
10
|
// @ts-ignore
|
|
@@ -18,10 +20,13 @@ export const YAML_OR_JS_FILES = /^(.*)\.(cube|sc)\.(ya?ml|js)$/;
|
|
|
18
20
|
|
|
19
21
|
let ora: any;
|
|
20
22
|
export default async () => {
|
|
23
|
+
await initLogger("push");
|
|
24
|
+
const breadcrumbs: string[] = [];
|
|
21
25
|
let spinnerPushing;
|
|
22
26
|
|
|
23
27
|
try {
|
|
24
28
|
checkNodeVersion();
|
|
29
|
+
breadcrumbs.push("checkNodeVersion");
|
|
25
30
|
const isBuildSuccess = await checkBuildSuccess();
|
|
26
31
|
if (!isBuildSuccess) {
|
|
27
32
|
console.error(
|
|
@@ -36,6 +41,7 @@ export default async () => {
|
|
|
36
41
|
|
|
37
42
|
if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
|
|
38
43
|
spinnerPushing = ora("Using API key...").start();
|
|
44
|
+
breadcrumbs.push("push by api key");
|
|
39
45
|
await pushByApiKey(config, spinnerPushing);
|
|
40
46
|
|
|
41
47
|
spinnerPushing.succeed("Published using API key");
|
|
@@ -43,11 +49,13 @@ export default async () => {
|
|
|
43
49
|
return;
|
|
44
50
|
}
|
|
45
51
|
|
|
52
|
+
breadcrumbs.push("push by standard login");
|
|
46
53
|
const token = await verify(config);
|
|
47
54
|
spinnerPushing = ora()
|
|
48
55
|
.start()
|
|
49
56
|
.info("No API Key provided. Standard login will be used.");
|
|
50
57
|
|
|
58
|
+
breadcrumbs.push("select workspace");
|
|
51
59
|
const { workspaceId, name: workspaceName } = await selectWorkspace(
|
|
52
60
|
ora,
|
|
53
61
|
config,
|
|
@@ -56,23 +64,20 @@ export default async () => {
|
|
|
56
64
|
|
|
57
65
|
const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
|
|
58
66
|
|
|
67
|
+
breadcrumbs.push("build archive");
|
|
59
68
|
await buildArchive(config);
|
|
60
69
|
spinnerPushing.info(
|
|
61
70
|
`Publishing to ${workspaceName} using ${workspacePreviewUrl}...`,
|
|
62
71
|
);
|
|
63
72
|
|
|
73
|
+
breadcrumbs.push("send build");
|
|
64
74
|
await sendBuild(config, { workspaceId, token });
|
|
65
75
|
spinnerPushing.succeed(
|
|
66
76
|
`Published to ${workspaceName} using ${workspacePreviewUrl}`,
|
|
67
77
|
);
|
|
68
78
|
} catch (error: any) {
|
|
69
79
|
spinnerPushing?.fail("Publishing failed");
|
|
70
|
-
|
|
71
|
-
console.error("Unauthorized. Please check your credentials.");
|
|
72
|
-
} else {
|
|
73
|
-
console.error(error.response?.data || error?.message || error);
|
|
74
|
-
}
|
|
75
|
-
|
|
80
|
+
await logError({ command: "push", breadcrumbs, error });
|
|
76
81
|
await reportErrorToRollbar(error);
|
|
77
82
|
process.exit(1);
|
|
78
83
|
}
|
package/src/utils.test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
storeBuildSuccessFlag,
|
|
6
6
|
checkBuildSuccess,
|
|
7
7
|
SUCCESS_FLAG_FILE,
|
|
8
|
+
hrtimeToISO8601,
|
|
8
9
|
} from "./utils";
|
|
9
10
|
|
|
10
11
|
const startMock = {
|
|
@@ -114,4 +115,19 @@ describe("utils", () => {
|
|
|
114
115
|
expect(result).toBe(false);
|
|
115
116
|
});
|
|
116
117
|
});
|
|
118
|
+
|
|
119
|
+
describe("hrtimeToISO8601", () => {
|
|
120
|
+
test.each([
|
|
121
|
+
{ input: [0, 0], expected: "PT0.000S" },
|
|
122
|
+
{ input: [75, 0], expected: "PT1M15.000S" }, // 1 minute and 15 seconds
|
|
123
|
+
{ input: [2, 500000000], expected: "PT2.500S" }, // 2.5 seconds
|
|
124
|
+
{ input: [0, 123456789], expected: "PT0.123S" }, // 0.123 seconds
|
|
125
|
+
{ input: [0, 500000000], expected: "PT0.500S" }, // 0.5 seconds
|
|
126
|
+
{ input: [1, 0], expected: "PT1.000S" }, // 1 second
|
|
127
|
+
{ input: null, expected: "" },
|
|
128
|
+
{ input: undefined, expected: "" },
|
|
129
|
+
])("converts hrtime $input to $expected", ({ input, expected }) => {
|
|
130
|
+
expect(hrtimeToISO8601(input)).toBe(expected);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
117
133
|
});
|
package/src/utils.ts
CHANGED
|
@@ -88,7 +88,7 @@ export const checkBuildSuccess = async () => {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
const getPackageVersion = (packageName: string) => {
|
|
92
92
|
const packageJsonPath = path.join(
|
|
93
93
|
process.cwd(),
|
|
94
94
|
"node_modules",
|
|
@@ -102,3 +102,44 @@ export const getPackageVersion = (packageName: string) => {
|
|
|
102
102
|
return undefined;
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
|
+
|
|
106
|
+
export const getSDKVersions = () => {
|
|
107
|
+
const packageNames = [
|
|
108
|
+
"@embeddable.com/core",
|
|
109
|
+
"@embeddable.com/react",
|
|
110
|
+
"@embeddable.com/sdk-core",
|
|
111
|
+
"@embeddable.com/sdk-react",
|
|
112
|
+
"@embeddable.com/sdk-utils",
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
const sdkVersions = packageNames.reduce<Record<string, string>>(
|
|
116
|
+
(acc, packageName) => {
|
|
117
|
+
const version = getPackageVersion(packageName);
|
|
118
|
+
if (version) {
|
|
119
|
+
acc[packageName] = version;
|
|
120
|
+
}
|
|
121
|
+
return acc;
|
|
122
|
+
},
|
|
123
|
+
{},
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return sdkVersions;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const hrtimeToISO8601 = (
|
|
130
|
+
hrtime: number[] | null | undefined,
|
|
131
|
+
): String => {
|
|
132
|
+
if (hrtime === null || hrtime === undefined) {
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
const seconds = hrtime[0];
|
|
136
|
+
const nanoseconds = hrtime[1];
|
|
137
|
+
|
|
138
|
+
// Convert time components
|
|
139
|
+
const totalSeconds = seconds + nanoseconds / 1e9;
|
|
140
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
141
|
+
const remainingSeconds = totalSeconds % 60;
|
|
142
|
+
|
|
143
|
+
// Format ISO 8601 duration without hours
|
|
144
|
+
return `PT${minutes > 0 ? minutes + "M" : ""}${remainingSeconds.toFixed(3)}S`;
|
|
145
|
+
};
|