@embeddable.com/sdk-core 3.13.2 → 3.13.3-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-core",
3
- "version": "3.13.2",
3
+ "version": "3.13.3-next.1",
4
4
  "description": "Core Embeddable SDK module responsible for web-components bundling and publishing.",
5
5
  "keywords": [
6
6
  "embeddable",
@@ -14,6 +14,7 @@ const ctx = {
14
14
 
15
15
  vi.mock("node:fs/promises", () => ({
16
16
  writeFile: vi.fn(),
17
+ readFile: vi.fn(),
17
18
  rename: vi.fn(),
18
19
  }));
19
20
 
package/src/push.ts CHANGED
@@ -229,10 +229,17 @@ export async function sendBuildByApiKey(
229
229
  form.set("file", file, "embeddable-build.zip");
230
230
 
231
231
  const metadataBlob = new Blob(
232
- [JSON.stringify({ authorEmail: email, description: message })],
232
+ [
233
+ JSON.stringify({
234
+ pushModels: ctx.pushModels,
235
+ pushComponents: ctx.pushComponents,
236
+ authorEmail: email,
237
+ description: message,
238
+ }),
239
+ ],
233
240
  { type: "application/json" },
234
241
  );
235
- form.set("metadata", metadataBlob, "metadata.json");
242
+ form.set("request", metadataBlob, "request.json");
236
243
 
237
244
  const response = await uploadFile(
238
245
  form,
package/src/utils.test.ts CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  checkBuildSuccess,
7
7
  SUCCESS_FLAG_FILE,
8
8
  hrtimeToISO8601,
9
+ getSDKVersions,
9
10
  } from "./utils";
10
11
 
11
12
  const startMock = {
@@ -16,6 +17,11 @@ const startMock = {
16
17
 
17
18
  const failMock = vi.fn();
18
19
 
20
+ // Mock for testing resolveLocalFileVersion
21
+ const mockPackageJson = {
22
+ version: "1.2.3",
23
+ };
24
+
19
25
  vi.mock("ora", () => ({
20
26
  default: () => ({
21
27
  start: vi.fn().mockImplementation(() => startMock),
@@ -35,6 +41,7 @@ vi.mock("fs/promises", () => ({
35
41
  writeFile: vi.fn(),
36
42
  access: vi.fn(),
37
43
  mkdir: vi.fn(),
44
+ unlink: vi.fn(),
38
45
  }));
39
46
 
40
47
  describe("utils", () => {
@@ -135,6 +142,109 @@ describe("utils", () => {
135
142
  });
136
143
  });
137
144
 
145
+ describe("getSDKVersions", () => {
146
+ beforeEach(() => {
147
+ process.env.NODE_ENV = "local";
148
+ vi.resetAllMocks();
149
+ process.cwd = vi.fn().mockReturnValue("/test/path");
150
+ });
151
+
152
+ afterEach(() => {
153
+ process.env.NODE_ENV = "test";
154
+ });
155
+
156
+ it("should get versions from node_modules", async () => {
157
+ // Mock the readFile to return a version for the first package
158
+ vi.mocked(fs.readFile).mockResolvedValueOnce(
159
+ JSON.stringify(mockPackageJson),
160
+ );
161
+
162
+ const result = await getSDKVersions();
163
+
164
+ expect(result).toHaveProperty("@embeddable.com/core", "1.2.3");
165
+ });
166
+
167
+ it("should handle local file references", async () => {
168
+ // Mock package.json with local file references
169
+ const mockProjectPackageJson = {
170
+ dependencies: {
171
+ "@embeddable.com/core": "file:../packages/core",
172
+ },
173
+ };
174
+
175
+ // First readFile calls for node_modules fail
176
+ vi.mocked(fs.readFile)
177
+ .mockRejectedValueOnce(new Error("Not found")) // core
178
+ .mockRejectedValueOnce(new Error("Not found")) // react
179
+ .mockRejectedValueOnce(new Error("Not found")) // sdk-core
180
+ .mockRejectedValueOnce(new Error("Not found")) // sdk-react
181
+ .mockRejectedValueOnce(new Error("Not found")) // sdk-utils
182
+ // Then project package.json succeeds
183
+ .mockResolvedValueOnce(JSON.stringify(mockProjectPackageJson))
184
+ // Then the referenced package.json succeeds
185
+ .mockResolvedValueOnce(JSON.stringify({ version: "2.0.0" }));
186
+
187
+ const result = await getSDKVersions();
188
+
189
+ expect(result).toHaveProperty("@embeddable.com/core", "2.0.0");
190
+ });
191
+
192
+ it("should handle errors when resolving local file references", async () => {
193
+ // Mock console.warn to avoid test output noise
194
+ const consoleWarnSpy = vi
195
+ .spyOn(console, "warn")
196
+ .mockImplementation(() => {});
197
+
198
+ // Mock package.json with local file references
199
+ const mockProjectPackageJson = {
200
+ dependencies: {
201
+ "@embeddable.com/core": "file:../packages/core",
202
+ },
203
+ };
204
+
205
+ // First readFile calls for node_modules fail
206
+ vi.mocked(fs.readFile)
207
+ .mockRejectedValueOnce(new Error("Not found")) // core
208
+ .mockRejectedValueOnce(new Error("Not found")) // react
209
+ .mockRejectedValueOnce(new Error("Not found")) // sdk-core
210
+ .mockRejectedValueOnce(new Error("Not found")) // sdk-react
211
+ .mockRejectedValueOnce(new Error("Not found")) // sdk-utils
212
+ // Then project package.json succeeds
213
+ .mockResolvedValueOnce(JSON.stringify(mockProjectPackageJson))
214
+ // Then the referenced package.json fails
215
+ .mockRejectedValueOnce(new Error("Cannot read file"));
216
+
217
+ const result = await getSDKVersions();
218
+
219
+ expect(consoleWarnSpy).toHaveBeenCalled();
220
+ expect(result).toHaveProperty("@embeddable.com/core", "local-dev");
221
+
222
+ consoleWarnSpy.mockRestore();
223
+ });
224
+
225
+ it("should use fallback values in test environment when no versions found", async () => {
226
+ // Mock console.warn to avoid test output noise
227
+ const consoleWarnSpy = vi
228
+ .spyOn(console, "warn")
229
+ .mockImplementation(() => {});
230
+
231
+ // Mock all readFile calls to fail
232
+ vi.mocked(fs.readFile).mockRejectedValue(new Error("Not found"));
233
+
234
+ // Mock process.cwd to return a test-sdk path
235
+ process.cwd = vi.fn().mockReturnValue("/test/path/test-sdk");
236
+
237
+ const result = await getSDKVersions();
238
+
239
+ // Should have fallback values for all packages
240
+ expect(Object.keys(result).length).toBeGreaterThan(0);
241
+ expect(result["@embeddable.com/core"]).toBe("local-dev");
242
+ expect(result["@embeddable.com/sdk-core"]).toBe("local-dev");
243
+
244
+ consoleWarnSpy.mockRestore();
245
+ });
246
+ });
247
+
138
248
  describe("hrtimeToISO8601", () => {
139
249
  test.each([
140
250
  { input: [0, 0], expected: "PT0.000S" },
package/src/utils.ts CHANGED
@@ -115,6 +115,30 @@ const getPackageVersion = async (packageName: string) => {
115
115
  }
116
116
  };
117
117
 
118
+ /**
119
+ * Attempts to resolve a local file reference to get the actual package version
120
+ * @param packageName The name of the package
121
+ * @param filePath The file path reference (e.g. "file:../packages/core")
122
+ * @returns The resolved version or "local-dev" if not found
123
+ */
124
+ const resolveLocalFileVersion = async (
125
+ packageName: string,
126
+ filePath: string,
127
+ ) => {
128
+ try {
129
+ // Remove the file: prefix and resolve the path
130
+ const refPath = filePath.replace(/^file:/, "");
131
+ const absPath = path.resolve(process.cwd(), refPath, "package.json");
132
+
133
+ // Read the package.json from the referenced path
134
+ const refPackageJson = JSON.parse(await fs.readFile(absPath, "utf-8"));
135
+ return refPackageJson.version || "local-dev";
136
+ } catch (e) {
137
+ console.warn(`Failed to resolve local version for ${packageName}`, e);
138
+ return "local-dev";
139
+ }
140
+ };
141
+
118
142
  export const getSDKVersions = async () => {
119
143
  const packageNames = [
120
144
  "@embeddable.com/core",
@@ -124,6 +148,7 @@ export const getSDKVersions = async () => {
124
148
  "@embeddable.com/sdk-utils",
125
149
  ];
126
150
 
151
+ // First try to get versions from node_modules
127
152
  const sdkVersions = await packageNames.reduce<
128
153
  Promise<Record<string, string>>
129
154
  >(
@@ -138,6 +163,49 @@ export const getSDKVersions = async () => {
138
163
  Promise.resolve({}), // Start with a resolved promise containing an empty object
139
164
  );
140
165
 
166
+ // If no versions were found, try to get them from package.json dependencies/devDependencies
167
+ if (
168
+ Object.keys(sdkVersions).length === 0 &&
169
+ process.env.NODE_ENV !== "test"
170
+ ) {
171
+ try {
172
+ const packageJsonPath = path.join(process.cwd(), "package.json");
173
+ const packageJson = JSON.parse(
174
+ await fs.readFile(packageJsonPath, "utf-8"),
175
+ );
176
+
177
+ const { dependencies = {}, devDependencies = {} } = packageJson;
178
+ const allDeps = { ...dependencies, ...devDependencies };
179
+
180
+ for (const packageName of packageNames) {
181
+ if (allDeps[packageName]) {
182
+ // For file: references, try to get the actual version from the referenced package
183
+ if (allDeps[packageName].startsWith("file:")) {
184
+ sdkVersions[packageName] = await resolveLocalFileVersion(
185
+ packageName,
186
+ allDeps[packageName],
187
+ );
188
+ } else {
189
+ sdkVersions[packageName] = allDeps[packageName];
190
+ }
191
+ }
192
+ }
193
+ } catch (e) {
194
+ console.warn("Failed to read package.json for SDK versions", e);
195
+ }
196
+ }
197
+
198
+ // If we're in a test environment and still have no versions, add fallback values
199
+ if (Object.keys(sdkVersions).length === 0) {
200
+ const isTestEnv = process.cwd().includes("test-sdk");
201
+ if (isTestEnv) {
202
+ console.warn("Test environment detected, using fallback SDK versions");
203
+ packageNames.forEach((pkg) => {
204
+ sdkVersions[pkg] = "local-dev";
205
+ });
206
+ }
207
+ }
208
+
141
209
  return sdkVersions;
142
210
  };
143
211