@webstudio-is/http-client 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Webstudio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Webstudio HTTP Client
2
+
3
+ Enables to optimize the http calls to Webstudio API.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fetch-polyfill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-polyfill.d.ts","sourceRoot":"","sources":["../src/fetch-polyfill.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
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
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import "./fetch-polyfill";
2
+ import type { Includes, Project } from "./index.d";
3
+ export declare const loadProject: ({ projectId, host, include, }: {
4
+ projectId: string;
5
+ host?: string | undefined;
6
+ include?: Includes<boolean> | undefined;
7
+ }) => Promise<Project>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/lib/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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}`);
8
+ const treeUrl = new URL(`/rest/tree/${projectId}`, baseUrl);
9
+ const propsUrl = new URL(`/rest/props/${projectId}`, baseUrl);
10
+ const breakpointsUrl = new URL(`/rest/breakpoints/${projectId}`, baseUrl);
11
+ 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(),
15
+ ]);
16
+ return {
17
+ tree,
18
+ props,
19
+ breakpoints,
20
+ };
21
+ };
22
+ exports.loadProject = loadProject;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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";
7
+ describe("getProjectDetails", () => {
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
+ const response = await (0, index_1.loadProject)({
14
+ projectId: nonExistingProject,
15
+ });
16
+ expect(response.tree.errors).toBe("Project required");
17
+ });
18
+ test("loads not published project", async () => {
19
+ const response = await (0, index_1.loadProject)({
20
+ projectId: notPublishedProject,
21
+ });
22
+ expect(response.tree.errors).toBe("Site needs to be published, production tree ID is null.");
23
+ });
24
+ });
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@webstudio-is/http-client",
3
+ "version": "0.0.1",
4
+ "description": "Webstudio HTTP Client",
5
+ "author": "Webstudio <github@webstudio.is>",
6
+ "homepage": "https://webstudio.is",
7
+ "scripts": {
8
+ "dev": "tsup src/index.ts --format esm,cjs --watch --out-dir=lib",
9
+ "test": "jest",
10
+ "build": "rm -fr lib && tsc",
11
+ "typecheck": "tsc --noEmit",
12
+ "lint": "eslint ./src --ext .ts,.tsx --max-warnings 0",
13
+ "checks": "yarn typecheck && yarn lint"
14
+ },
15
+ "devDependencies": {
16
+ "@webstudio-is/jest-config": "*",
17
+ "@webstudio-is/react-sdk": "*",
18
+ "@webstudio-is/prisma-client": "*",
19
+ "tsup": "^6.1.3",
20
+ "typescript": "^4.6.2"
21
+ },
22
+ "peerDependencies": {},
23
+ "dependencies": {
24
+ "node-fetch": "^3.2.10"
25
+ },
26
+ "main": "lib/index.js",
27
+ "types": "lib/index.d.ts",
28
+ "files": [
29
+ "lib/*",
30
+ "README.md",
31
+ "!*.test.*"
32
+ ],
33
+ "license": "MIT",
34
+ "private": false
35
+ }