@webstudio-is/http-client 0.269.0 → 0.271.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 +53 -13
- package/lib/types/index.d.ts +23 -31
- package/package.json +2 -3
package/lib/index.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { createTRPCUntypedClient, httpBatchLink } from "@trpc/client";
|
|
3
|
+
import {
|
|
4
|
+
importProjectBundleResultSchema,
|
|
5
|
+
publishedProjectBundleSchema
|
|
6
|
+
} from "@webstudio-is/protocol";
|
|
7
|
+
import {
|
|
8
|
+
getBundleVersion,
|
|
9
|
+
isAssetFileDataString,
|
|
10
|
+
bundleVersion
|
|
11
|
+
} from "@webstudio-is/protocol";
|
|
3
12
|
var createTrpcClient = (origin, headers) => {
|
|
4
13
|
const { sourceOrigin } = parseBuilderUrl(origin);
|
|
5
14
|
const url = new URL("/trpc", sourceOrigin);
|
|
@@ -12,22 +21,48 @@ var createTrpcClient = (origin, headers) => {
|
|
|
12
21
|
]
|
|
13
22
|
});
|
|
14
23
|
};
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
24
|
+
var createAuthTrpcClient = (params) => createTrpcClient(params.origin, {
|
|
25
|
+
...params.headers,
|
|
26
|
+
"x-auth-token": params.authToken
|
|
27
|
+
});
|
|
28
|
+
var loadProjectBundleByBuildId = async (params) => {
|
|
29
|
+
const headers = "serviceToken" in params ? { Authorization: params.serviceToken } : { "x-auth-token": params.authToken };
|
|
30
|
+
const data = await createTrpcClient(params.origin, {
|
|
18
31
|
...params.headers,
|
|
19
32
|
...headers
|
|
20
|
-
}).query("build.
|
|
33
|
+
}).query("build.loadProjectBundleByBuildId", {
|
|
21
34
|
buildId: params.buildId
|
|
22
35
|
});
|
|
36
|
+
return publishedProjectBundleSchema.parse(data);
|
|
23
37
|
};
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
var loadProjectBundleByProjectId = async (params) => {
|
|
39
|
+
const data = await createAuthTrpcClient(params).query(
|
|
40
|
+
"build.loadProjectBundleByProjectId",
|
|
41
|
+
{
|
|
42
|
+
projectId: params.projectId
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
return publishedProjectBundleSchema.parse(data);
|
|
46
|
+
};
|
|
47
|
+
var checkProjectBuildPermission = async (params) => {
|
|
48
|
+
await createAuthTrpcClient(params).query(
|
|
49
|
+
"build.checkProjectBuildPermission",
|
|
50
|
+
{
|
|
51
|
+
projectId: params.projectId
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
var importProjectBundle = async (params) => {
|
|
56
|
+
const result = await createAuthTrpcClient(params).mutation(
|
|
57
|
+
"build.importProjectBundle",
|
|
58
|
+
{
|
|
59
|
+
projectId: params.projectId,
|
|
60
|
+
data: params.data,
|
|
61
|
+
assetFiles: params.assetFiles,
|
|
62
|
+
ignoreVersionCheck: params.ignoreVersionCheck
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
return importProjectBundleResultSchema.parse(result);
|
|
31
66
|
};
|
|
32
67
|
var buildProjectDomainPrefix = "p-";
|
|
33
68
|
var parseBuilderUrl = (urlStr) => {
|
|
@@ -60,7 +95,12 @@ var parseBuilderUrl = (urlStr) => {
|
|
|
60
95
|
};
|
|
61
96
|
};
|
|
62
97
|
export {
|
|
63
|
-
|
|
64
|
-
|
|
98
|
+
bundleVersion,
|
|
99
|
+
checkProjectBuildPermission,
|
|
100
|
+
getBundleVersion,
|
|
101
|
+
importProjectBundle,
|
|
102
|
+
isAssetFileDataString,
|
|
103
|
+
loadProjectBundleByBuildId,
|
|
104
|
+
loadProjectBundleByProjectId,
|
|
65
105
|
parseBuilderUrl
|
|
66
106
|
};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,44 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
pages: Array<Page>;
|
|
6
|
-
build: {
|
|
7
|
-
id: string;
|
|
8
|
-
projectId: string;
|
|
9
|
-
version: number;
|
|
10
|
-
createdAt: string;
|
|
11
|
-
updatedAt: string;
|
|
12
|
-
pages: SerializedPages;
|
|
13
|
-
breakpoints: [Breakpoint["id"], Breakpoint][];
|
|
14
|
-
styles: [StyleDeclKey, StyleDecl][];
|
|
15
|
-
styleSources: [StyleSource["id"], StyleSource][];
|
|
16
|
-
styleSourceSelections: [Instance["id"], StyleSourceSelection][];
|
|
17
|
-
props: [Prop["id"], Prop][];
|
|
18
|
-
instances: [Instance["id"], Instance][];
|
|
19
|
-
dataSources: [DataSource["id"], DataSource][];
|
|
20
|
-
resources: [Resource["id"], Resource][];
|
|
21
|
-
deployment?: Deployment | undefined;
|
|
22
|
-
};
|
|
23
|
-
assets: Array<Asset>;
|
|
24
|
-
projectDomain?: string;
|
|
25
|
-
origin?: string;
|
|
26
|
-
};
|
|
27
|
-
export declare const loadProjectDataByBuildId: (params: {
|
|
1
|
+
import { type AssetFileData, type ImportProjectBundleResult, type PublishedProjectBundle } from "@webstudio-is/protocol";
|
|
2
|
+
export { getBundleVersion, isAssetFileDataString, bundleVersion, } from "@webstudio-is/protocol";
|
|
3
|
+
export type { AssetFileData, PublishedProjectBundle, ProjectBundle, } from "@webstudio-is/protocol";
|
|
4
|
+
export declare const loadProjectBundleByBuildId: (params: {
|
|
28
5
|
buildId: string;
|
|
29
6
|
origin: string;
|
|
30
7
|
headers?: Record<string, string | undefined>;
|
|
31
8
|
} & ({
|
|
32
|
-
|
|
9
|
+
serviceToken: string;
|
|
33
10
|
} | {
|
|
34
11
|
authToken: string;
|
|
35
|
-
})) => Promise<
|
|
36
|
-
export declare const
|
|
12
|
+
})) => Promise<PublishedProjectBundle>;
|
|
13
|
+
export declare const loadProjectBundleByProjectId: (params: {
|
|
14
|
+
projectId: string;
|
|
15
|
+
origin: string;
|
|
16
|
+
authToken: string;
|
|
17
|
+
headers?: Record<string, string | undefined>;
|
|
18
|
+
}) => Promise<PublishedProjectBundle>;
|
|
19
|
+
export declare const checkProjectBuildPermission: (params: {
|
|
20
|
+
projectId: string;
|
|
21
|
+
origin: string;
|
|
22
|
+
authToken: string;
|
|
23
|
+
headers?: Record<string, string | undefined>;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
export declare const importProjectBundle: (params: {
|
|
37
26
|
projectId: string;
|
|
38
27
|
origin: string;
|
|
39
28
|
authToken: string;
|
|
29
|
+
data: PublishedProjectBundle;
|
|
30
|
+
assetFiles?: AssetFileData[];
|
|
31
|
+
ignoreVersionCheck?: boolean;
|
|
40
32
|
headers?: Record<string, string | undefined>;
|
|
41
|
-
}) => Promise<
|
|
33
|
+
}) => Promise<ImportProjectBundleResult>;
|
|
42
34
|
export declare const parseBuilderUrl: (urlStr: string) => {
|
|
43
35
|
projectId: undefined;
|
|
44
36
|
sourceOrigin: string;
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/http-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.271.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/
|
|
11
|
-
"@webstudio-is/sdk": "0.269.0"
|
|
10
|
+
"@webstudio-is/protocol": "0.271.0"
|
|
12
11
|
},
|
|
13
12
|
"devDependencies": {
|
|
14
13
|
"vitest": "^3.1.2",
|