@webstudio-is/http-client 0.91.0 → 0.93.0

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.js CHANGED
@@ -1,4 +1,5 @@
1
- const loadProjectDataById = async (params) => {
1
+ "use strict";
2
+ export const loadProjectDataById = async (params) => {
2
3
  const result = await getLatestBuildUsingProjectId(params);
3
4
  if (result === null) {
4
5
  throw new Error(``);
@@ -15,7 +16,7 @@ const loadProjectDataById = async (params) => {
15
16
  const message = await response.text();
16
17
  throw new Error(message.slice(0, 1e3));
17
18
  };
18
- const getLatestBuildUsingProjectId = async (params) => {
19
+ export const getLatestBuildUsingProjectId = async (params) => {
19
20
  const { host, projectId, authToken } = params;
20
21
  const url = new URL(host);
21
22
  url.pathname = `/rest/buildId/${projectId}`;
@@ -29,7 +30,3 @@ const getLatestBuildUsingProjectId = async (params) => {
29
30
  const message = await response.text();
30
31
  throw new Error(message.slice(0, 1e3));
31
32
  };
32
- export {
33
- getLatestBuildUsingProjectId,
34
- loadProjectDataById
35
- };
@@ -1,20 +1,17 @@
1
+ "use strict";
1
2
  import { describe, test, expect } from "@jest/globals";
2
3
  import { loadProjectDataById } from "./index";
3
-
4
4
  const existingProjectId = "675e8af3-48fa-4b18-9ebf-fd2b128865e2";
5
5
  const notPublishedProjectId = "7ec397c6-b3d0-4967-9073-9d83623fcf8e";
6
6
  const onlyHomeProjectId = "36d6c16f-04a0-45d4-ab1d-aa0ab61eb5b6";
7
7
  const morePagesProjectId = existingProjectId;
8
-
9
8
  const host = "http://localhost:3000";
10
-
11
9
  describe("getProjectDetails", () => {
12
10
  test("include pages", async () => {
13
11
  const response = await loadProjectDataById({
14
12
  host,
15
- projectId: morePagesProjectId,
13
+ projectId: morePagesProjectId
16
14
  });
17
-
18
15
  if (typeof response === "object") {
19
16
  return expect(response.pages.length).toBeTruthy();
20
17
  }
@@ -23,7 +20,7 @@ describe("getProjectDetails", () => {
23
20
  test("does not include pages", async () => {
24
21
  const response = await loadProjectDataById({
25
22
  host,
26
- projectId: onlyHomeProjectId,
23
+ projectId: onlyHomeProjectId
27
24
  });
28
25
  if (typeof response === "object") {
29
26
  return expect(response.pages.length === 1).toBeTruthy();
@@ -33,14 +30,14 @@ describe("getProjectDetails", () => {
33
30
  test("loads existing project", async () => {
34
31
  const response = await loadProjectDataById({
35
32
  host,
36
- projectId: existingProjectId,
33
+ projectId: existingProjectId
37
34
  });
38
35
  expect(response).toBeTruthy();
39
36
  });
40
37
  test("loads not published project", async () => {
41
38
  const response = await loadProjectDataById({
42
39
  host,
43
- projectId: notPublishedProjectId,
40
+ projectId: notPublishedProjectId
44
41
  });
45
42
  if (response instanceof Error) {
46
43
  throw response;
@@ -1,4 +1,24 @@
1
- import type { Data } from "@webstudio-is/react-sdk";
1
+ import type { Asset, Breakpoint, DataSource, Deployment, Instance, Page, Pages, Prop, StyleDecl, StyleDeclKey, StyleSource, StyleSourceSelection } from "@webstudio-is/sdk";
2
+ export type Data = {
3
+ page: Page;
4
+ pages: Array<Page>;
5
+ build: {
6
+ id: string;
7
+ projectId: string;
8
+ version: number;
9
+ createdAt: string;
10
+ pages: Pages;
11
+ breakpoints: [Breakpoint["id"], Breakpoint][];
12
+ styles: [StyleDeclKey, StyleDecl][];
13
+ styleSources: [StyleSource["id"], StyleSource][];
14
+ styleSourceSelections: [Instance["id"], StyleSourceSelection][];
15
+ props: [Prop["id"], Prop][];
16
+ instances: [Instance["id"], Instance][];
17
+ dataSources: [DataSource["id"], DataSource][];
18
+ deployment?: Deployment | undefined;
19
+ };
20
+ assets: Array<Asset>;
21
+ };
2
22
  interface DefaultArgs {
3
23
  host: string;
4
24
  authToken?: string;
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@webstudio-is/http-client",
3
- "version": "0.91.0",
3
+ "version": "0.93.0",
4
4
  "description": "Webstudio HTTP Client",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
7
7
  "type": "module",
8
+ "dependencies": {
9
+ "@webstudio-is/sdk": "^0.93.0"
10
+ },
8
11
  "devDependencies": {
9
- "@jest/globals": "^29.6.2",
10
- "jest": "^29.6.2",
11
- "typescript": "5.1.6",
12
+ "@jest/globals": "^29.6.4",
13
+ "jest": "^29.6.4",
14
+ "typescript": "5.2.2",
12
15
  "@webstudio-is/jest-config": "^1.0.7",
13
- "@webstudio-is/prisma-client": "^0.91.0",
14
- "@webstudio-is/react-sdk": "^0.91.0",
15
- "@webstudio-is/scripts": "^0.0.0",
16
16
  "@webstudio-is/tsconfig": "^1.0.7"
17
17
  },
18
18
  "exports": {
@@ -22,15 +22,14 @@
22
22
  },
23
23
  "files": [
24
24
  "lib/*",
25
- "src/*",
26
- "!*.test.*"
25
+ "!*.{test,stories}.*"
27
26
  ],
28
27
  "license": "AGPL-3.0-or-later",
29
28
  "private": false,
30
29
  "sideEffects": false,
31
30
  "scripts": {
32
- "dev": "build-package --watch",
33
- "build": "build-package",
31
+ "dev": "pnpm build --watch",
32
+ "build": "rm -rf lib && esbuild 'src/**/*.ts' 'src/**/*.tsx' --outdir=lib",
34
33
  "dts": "tsc --project tsconfig.dts.json",
35
34
  "test": "NODE_OPTIONS=--experimental-vm-modules jest",
36
35
  "typecheck": "tsc",
package/lib/cjs/index.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var src_exports = {};
20
- __export(src_exports, {
21
- getLatestBuildUsingProjectId: () => getLatestBuildUsingProjectId,
22
- loadProjectDataById: () => loadProjectDataById
23
- });
24
- module.exports = __toCommonJS(src_exports);
25
- const loadProjectDataById = async (params) => {
26
- const result = await getLatestBuildUsingProjectId(params);
27
- if (result === null) {
28
- throw new Error(``);
29
- }
30
- const url = new URL(params.host);
31
- url.pathname = `/rest/build/${result.buildId}`;
32
- if (params.authToken) {
33
- url.searchParams.append("authToken", params.authToken);
34
- }
35
- const response = await fetch(url.href);
36
- if (response.ok) {
37
- return await response.json();
38
- }
39
- const message = await response.text();
40
- throw new Error(message.slice(0, 1e3));
41
- };
42
- const getLatestBuildUsingProjectId = async (params) => {
43
- const { host, projectId, authToken } = params;
44
- const url = new URL(host);
45
- url.pathname = `/rest/buildId/${projectId}`;
46
- if (authToken) {
47
- url.searchParams.append("authToken", authToken);
48
- }
49
- const response = await fetch(url.href);
50
- if (response.ok) {
51
- return await response.json();
52
- }
53
- const message = await response.text();
54
- throw new Error(message.slice(0, 1e3));
55
- };
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
package/src/index.ts DELETED
@@ -1,53 +0,0 @@
1
- import type { Data } from "@webstudio-is/react-sdk";
2
-
3
- interface DefaultArgs {
4
- host: string;
5
- authToken?: string;
6
- }
7
-
8
- type ResourceFactory<T, K> = (params: DefaultArgs & T) => Promise<K>;
9
-
10
- export const loadProjectDataById: ResourceFactory<
11
- { projectId: string },
12
- Data
13
- > = async (params) => {
14
- const result = await getLatestBuildUsingProjectId(params);
15
- if (result === null) {
16
- throw new Error(``);
17
- }
18
-
19
- const url = new URL(params.host);
20
- url.pathname = `/rest/build/${result.buildId}`;
21
- if (params.authToken) {
22
- url.searchParams.append("authToken", params.authToken);
23
- }
24
-
25
- const response = await fetch(url.href);
26
-
27
- if (response.ok) {
28
- return await response.json();
29
- }
30
-
31
- const message = await response.text();
32
- throw new Error(message.slice(0, 1000));
33
- };
34
-
35
- export const getLatestBuildUsingProjectId: ResourceFactory<
36
- { projectId: string },
37
- { buildId: string }
38
- > = async (params) => {
39
- const { host, projectId, authToken } = params;
40
- const url = new URL(host);
41
- url.pathname = `/rest/buildId/${projectId}`;
42
- if (authToken) {
43
- url.searchParams.append("authToken", authToken);
44
- }
45
- const response = await fetch(url.href);
46
-
47
- if (response.ok) {
48
- return await response.json();
49
- }
50
-
51
- const message = await response.text();
52
- throw new Error(message.slice(0, 1000));
53
- };