@webstudio-is/http-client 0.263.0 → 0.265.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 +21 -38
- package/lib/types/index.d.ts +2 -2
- package/package.json +3 -2
package/lib/index.js
CHANGED
|
@@ -1,46 +1,29 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
const { origin, projectId, authToken } = params;
|
|
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));
|
|
15
|
-
};
|
|
2
|
+
import { createTRPCUntypedClient, httpBatchLink } from "@trpc/client";
|
|
16
3
|
var loadProjectDataByBuildId = async (params) => {
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
const headers = "seviceToken" in params ? { Authorization: params.seviceToken } : { "x-auth-token": params.authToken };
|
|
5
|
+
return await createTrpcClient(params.origin, headers).query(
|
|
6
|
+
"build.loadProjectDataByBuildId",
|
|
7
|
+
{ buildId: params.buildId }
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
var createTrpcClient = (origin, headers) => {
|
|
11
|
+
const { sourceOrigin } = parseBuilderUrl(origin);
|
|
12
|
+
const url = new URL("/trpc", sourceOrigin);
|
|
13
|
+
return createTRPCUntypedClient({
|
|
14
|
+
links: [
|
|
15
|
+
httpBatchLink({
|
|
16
|
+
url: url.href,
|
|
17
|
+
headers
|
|
18
|
+
})
|
|
19
|
+
]
|
|
28
20
|
});
|
|
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
21
|
};
|
|
35
22
|
var loadProjectDataByProjectId = async (params) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return await loadProjectDataByBuildId({
|
|
41
|
-
buildId: result.buildId,
|
|
42
|
-
origin: params.origin,
|
|
43
|
-
authToken: params.authToken
|
|
23
|
+
return await createTrpcClient(params.origin, {
|
|
24
|
+
"x-auth-token": params.authToken
|
|
25
|
+
}).query("build.loadProjectDataByProjectId", {
|
|
26
|
+
projectId: params.projectId
|
|
44
27
|
});
|
|
45
28
|
};
|
|
46
29
|
var buildProjectDomainPrefix = "p-";
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Asset, Breakpoint, DataSource, Deployment, Instance, Page,
|
|
1
|
+
import type { Asset, Breakpoint, DataSource, Deployment, Instance, Page, SerializedPages, Prop, Resource, StyleDecl, StyleDeclKey, StyleSource, StyleSourceSelection } from "@webstudio-is/sdk";
|
|
2
2
|
export type Data = {
|
|
3
3
|
page: Page;
|
|
4
4
|
pages: Array<Page>;
|
|
@@ -8,7 +8,7 @@ export type Data = {
|
|
|
8
8
|
version: number;
|
|
9
9
|
createdAt: string;
|
|
10
10
|
updatedAt: string;
|
|
11
|
-
pages:
|
|
11
|
+
pages: SerializedPages;
|
|
12
12
|
breakpoints: [Breakpoint["id"], Breakpoint][];
|
|
13
13
|
styles: [StyleDeclKey, StyleDecl][];
|
|
14
14
|
styleSources: [StyleSource["id"], StyleSource][];
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/http-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.265.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
|
-
"@
|
|
9
|
+
"@trpc/client": "^10.45.2",
|
|
10
|
+
"@webstudio-is/sdk": "0.265.0"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
13
|
"vitest": "^3.1.2",
|