@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { Includes, Project } from "./index.d";
2
- export declare const loadProject: ({ projectId, host, include, }: {
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
@@ -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;AAInD,eAAO,MAAM,WAAW;eAKX,MAAM;;;MAGf,QAAQ,OAAO,CAgBlB,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 protocol = process.env.NODE_ENV === "production" ? "https" : "http";
9
- const loadProject = async ({ projectId, host = process.env.DESIGNER_HOST || "localhost:3000", include = { tree: true, props: true, breakpoints: true }, }) => {
10
- const baseUrl = new URL("/", `${protocol}://${host}`);
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 existingProject = "ab3619d3-831f-46f8-abb6-609558cffd99";
5
- const notPublishedProject = "7ec397c6-b3d0-4967-9073-9d83623fcf8e";
6
- const nonExistingProject = "1";
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
- projectId: nonExistingProject,
10
+ apiUrl,
11
+ projectId: existingProjectId,
15
12
  });
16
- expect(response.tree.errors).toBe("Project required");
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
- projectId: notPublishedProject,
17
+ apiUrl,
18
+ projectId: notPublishedProjectId,
21
19
  });
22
- expect(response.tree.errors).toBe("Site needs to be published, production tree ID is null.");
20
+ expect(response.tree.errors).toBe("Project 7ec397c6-b3d0-4967-9073-9d83623fcf8e needs to be published first");
23
21
  });
24
22
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/http-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Webstudio HTTP Client",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",