@webstudio-is/http-client 0.264.0 → 0.266.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,46 +1,32 @@
1
1
  // src/index.ts
2
- var getLatestBuildUsingProjectId = async (params) => {
3
- const { origin, projectId, authToken } = params;
2
+ import { createTRPCUntypedClient, httpBatchLink } from "@trpc/client";
3
+ var createTrpcClient = (origin, headers) => {
4
4
  const { sourceOrigin } = parseBuilderUrl(origin);
5
- const url = new URL(sourceOrigin);
6
- url.pathname = `/rest/buildId/${projectId}`;
7
- const headers = new Headers();
8
- headers.set("x-auth-token", authToken);
9
- const response = await fetch(url.href, { headers });
10
- if (response.ok) {
11
- return await response.json();
12
- }
13
- const message = await response.text();
14
- throw new Error(message.slice(0, 1e3));
5
+ const url = new URL("/trpc", sourceOrigin);
6
+ return createTRPCUntypedClient({
7
+ links: [
8
+ httpBatchLink({
9
+ url: url.href,
10
+ headers
11
+ })
12
+ ]
13
+ });
15
14
  };
16
15
  var loadProjectDataByBuildId = async (params) => {
17
- const { sourceOrigin } = parseBuilderUrl(params.origin);
18
- const url = new URL(sourceOrigin);
19
- url.pathname = `/rest/build/${params.buildId}`;
20
- const headers = new Headers();
21
- if ("seviceToken" in params) {
22
- headers.set("Authorization", params.seviceToken);
23
- } else {
24
- headers.set("x-auth-token", params.authToken);
25
- }
26
- const response = await fetch(url.href, {
27
- headers
16
+ const headers = "seviceToken" in params ? { Authorization: params.seviceToken } : { "x-auth-token": params.authToken };
17
+ return await createTrpcClient(params.origin, {
18
+ ...params.headers,
19
+ ...headers
20
+ }).query("build.loadProjectDataByBuildId", {
21
+ buildId: params.buildId
28
22
  });
29
- if (response.ok) {
30
- return await response.json();
31
- }
32
- const message = await response.text();
33
- throw new Error(message.slice(0, 1e3));
34
23
  };
35
24
  var loadProjectDataByProjectId = async (params) => {
36
- const result = await getLatestBuildUsingProjectId(params);
37
- if (result.buildId === null) {
38
- throw new Error(`The project is not published yet`);
39
- }
40
- return await loadProjectDataByBuildId({
41
- buildId: result.buildId,
42
- origin: params.origin,
43
- authToken: params.authToken
25
+ return await createTrpcClient(params.origin, {
26
+ ...params.headers,
27
+ "x-auth-token": params.authToken
28
+ }).query("build.loadProjectDataByProjectId", {
29
+ projectId: params.projectId
44
30
  });
45
31
  };
46
32
  var buildProjectDomainPrefix = "p-";
@@ -1,4 +1,5 @@
1
- import type { Asset, Breakpoint, DataSource, Deployment, Instance, Page, Pages, Prop, Resource, StyleDecl, StyleDeclKey, StyleSource, StyleSourceSelection } from "@webstudio-is/sdk";
1
+ import type { Asset, Breakpoint, DataSource, Deployment, Instance, Page, Prop, Resource, StyleDecl, StyleDeclKey, StyleSource, StyleSourceSelection } from "@webstudio-is/sdk";
2
+ import type { SerializedPages } from "@webstudio-is/project-migrations/pages";
2
3
  export type Data = {
3
4
  page: Page;
4
5
  pages: Array<Page>;
@@ -8,7 +9,7 @@ export type Data = {
8
9
  version: number;
9
10
  createdAt: string;
10
11
  updatedAt: string;
11
- pages: Pages;
12
+ pages: SerializedPages;
12
13
  breakpoints: [Breakpoint["id"], Breakpoint][];
13
14
  styles: [StyleDeclKey, StyleDecl][];
14
15
  styleSources: [StyleSource["id"], StyleSource][];
@@ -25,6 +26,7 @@ export type Data = {
25
26
  export declare const loadProjectDataByBuildId: (params: {
26
27
  buildId: string;
27
28
  origin: string;
29
+ headers?: Record<string, string | undefined>;
28
30
  } & ({
29
31
  seviceToken: string;
30
32
  } | {
@@ -34,6 +36,7 @@ export declare const loadProjectDataByProjectId: (params: {
34
36
  projectId: string;
35
37
  origin: string;
36
38
  authToken: string;
39
+ headers?: Record<string, string | undefined>;
37
40
  }) => Promise<Data>;
38
41
  export declare const parseBuilderUrl: (urlStr: string) => {
39
42
  projectId: undefined;
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@webstudio-is/http-client",
3
- "version": "0.264.0",
3
+ "version": "0.266.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
8
  "dependencies": {
9
- "@webstudio-is/sdk": "0.264.0"
9
+ "@trpc/client": "^10.45.2",
10
+ "@webstudio-is/sdk": "0.266.0",
11
+ "@webstudio-is/project-migrations": "0.266.0"
10
12
  },
11
13
  "devDependencies": {
12
14
  "vitest": "^3.1.2",