@webstudio-is/http-client 0.0.1 → 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,8 +1,7 @@
1
- import "./fetch-polyfill";
2
1
  import type { Includes, Project } from "./index.d";
3
- export declare const loadProject: ({ projectId, host, include, }: {
2
+ export declare const loadProject: ({ apiUrl, projectId, include, }: {
3
+ apiUrl: string;
4
4
  projectId: string;
5
- host?: string | undefined;
6
5
  include?: Includes<boolean> | undefined;
7
6
  }) => Promise<Project>;
8
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,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
@@ -1,17 +1,22 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.loadProject = void 0;
4
- require("./fetch-polyfill");
5
- const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
6
- const loadProject = async ({ projectId, host = process.env.DESIGNER_HOST || "localhost:3000", include = { tree: true, props: true, breakpoints: true }, }) => {
7
- const baseUrl = new URL("/", `${protocol}://${host}`);
7
+ const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
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}`);
8
13
  const treeUrl = new URL(`/rest/tree/${projectId}`, baseUrl);
9
14
  const propsUrl = new URL(`/rest/props/${projectId}`, baseUrl);
10
15
  const breakpointsUrl = new URL(`/rest/breakpoints/${projectId}`, baseUrl);
11
16
  const [tree, props, breakpoints] = await Promise.all([
12
- include.tree && (await fetch(treeUrl)).json(),
13
- include.props && (await fetch(propsUrl)).json(),
14
- include.breakpoints && (await fetch(breakpointsUrl)).json(),
17
+ include.tree && (await (0, isomorphic_fetch_1.default)(treeUrl)).json(),
18
+ include.props && (await (0, isomorphic_fetch_1.default)(propsUrl)).json(),
19
+ include.breakpoints && (await (0, isomorphic_fetch_1.default)(breakpointsUrl)).json(),
15
20
  ]);
16
21
  return {
17
22
  tree,
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.0.1",
3
+ "version": "0.1.1",
4
4
  "description": "Webstudio HTTP Client",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -13,15 +13,16 @@
13
13
  "checks": "yarn typecheck && yarn lint"
14
14
  },
15
15
  "devDependencies": {
16
+ "@types/isomorphic-fetch": "^0.0.36",
16
17
  "@webstudio-is/jest-config": "*",
17
- "@webstudio-is/react-sdk": "*",
18
18
  "@webstudio-is/prisma-client": "*",
19
+ "@webstudio-is/react-sdk": "*",
19
20
  "tsup": "^6.1.3",
20
- "typescript": "^4.6.2"
21
+ "typescript": "4.7.4"
21
22
  },
22
23
  "peerDependencies": {},
23
24
  "dependencies": {
24
- "node-fetch": "^3.2.10"
25
+ "isomorphic-fetch": "^3.0.0"
25
26
  },
26
27
  "main": "lib/index.js",
27
28
  "types": "lib/index.d.ts",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=fetch-polyfill.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-polyfill.d.ts","sourceRoot":"","sources":["../src/fetch-polyfill.ts"],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_fetch_1 = __importDefault(require("node-fetch"));
7
- if (globalThis.fetch === undefined) {
8
- // @ts-expect-error node-fetch doesn't implement a complete spec
9
- globalThis.fetch = node_fetch_1.default;
10
- }