@webstudio-is/http-client 0.1.0 → 0.1.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/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -3
- package/lib/index.test.js +9 -11
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Includes, Project } from "./index.d";
|
|
2
|
-
export declare const loadProject: ({
|
|
2
|
+
export declare const loadProject: ({ apiUrl, projectId, include, }: {
|
|
3
|
+
apiUrl: string;
|
|
3
4
|
projectId: string;
|
|
4
|
-
host?: string | undefined;
|
|
5
5
|
include?: Includes<boolean> | undefined;
|
|
6
6
|
}) => Promise<Project>;
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,eAAO,MAAM,WAAW;YAKd,MAAM;eACH,MAAM;;MAEf,QAAQ,OAAO,CAmBlB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -5,9 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.loadProject = void 0;
|
|
7
7
|
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const loadProject = async ({ apiUrl, projectId, include = { tree: true, props: true, breakpoints: true }, }) => {
|
|
9
|
+
if (apiUrl === undefined) {
|
|
10
|
+
throw new Error("Webstudio API URL is required.");
|
|
11
|
+
}
|
|
12
|
+
const baseUrl = new URL(`${apiUrl}`);
|
|
11
13
|
const treeUrl = new URL(`/rest/tree/${projectId}`, baseUrl);
|
|
12
14
|
const propsUrl = new URL(`/rest/props/${projectId}`, baseUrl);
|
|
13
15
|
const breakpointsUrl = new URL(`/rest/breakpoints/${projectId}`, baseUrl);
|
package/lib/index.test.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const index_1 = require("./index");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const existingProjectId = "ab3619d3-831f-46f8-abb6-609558cffd99";
|
|
5
|
+
const notPublishedProjectId = "7ec397c6-b3d0-4967-9073-9d83623fcf8e";
|
|
6
|
+
const apiUrl = "http://localhost:3000";
|
|
7
7
|
describe("getProjectDetails", () => {
|
|
8
8
|
test("loads existing project", async () => {
|
|
9
|
-
const response = await (0, index_1.loadProject)({ projectId: existingProject });
|
|
10
|
-
expect(response.tree.id).toBeTruthy();
|
|
11
|
-
});
|
|
12
|
-
test("loads non-existing project", async () => {
|
|
13
9
|
const response = await (0, index_1.loadProject)({
|
|
14
|
-
|
|
10
|
+
apiUrl,
|
|
11
|
+
projectId: existingProjectId,
|
|
15
12
|
});
|
|
16
|
-
expect(response.tree.
|
|
13
|
+
expect(response.tree.id).toBeTruthy();
|
|
17
14
|
});
|
|
18
15
|
test("loads not published project", async () => {
|
|
19
16
|
const response = await (0, index_1.loadProject)({
|
|
20
|
-
|
|
17
|
+
apiUrl,
|
|
18
|
+
projectId: notPublishedProjectId,
|
|
21
19
|
});
|
|
22
|
-
expect(response.tree.errors).toBe("
|
|
20
|
+
expect(response.tree.errors).toBe("Project 7ec397c6-b3d0-4967-9073-9d83623fcf8e needs to be published first");
|
|
23
21
|
});
|
|
24
22
|
});
|