@webstudio-is/http-client 0.175.0 → 0.181.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 +22 -28
- package/lib/types/index.d.ts +3 -10
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
var
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
url.searchParams.append("authToken", params.authToken);
|
|
11
|
-
}
|
|
12
|
-
const response = await fetch(url.href);
|
|
2
|
+
var getLatestBuildUsingProjectId = async (params) => {
|
|
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 });
|
|
13
10
|
if (response.ok) {
|
|
14
11
|
return await response.json();
|
|
15
12
|
}
|
|
@@ -17,13 +14,14 @@ var loadProjectDataByProjectId = async (params) => {
|
|
|
17
14
|
throw new Error(message.slice(0, 1e3));
|
|
18
15
|
};
|
|
19
16
|
var loadProjectDataByBuildId = async (params) => {
|
|
20
|
-
const
|
|
17
|
+
const { sourceOrigin } = parseBuilderUrl(params.origin);
|
|
18
|
+
const url = new URL(sourceOrigin);
|
|
21
19
|
url.pathname = `/rest/build/${params.buildId}`;
|
|
22
|
-
const headers =
|
|
20
|
+
const headers = new Headers();
|
|
23
21
|
if ("seviceToken" in params) {
|
|
24
|
-
headers.Authorization
|
|
22
|
+
headers.set("Authorization", params.seviceToken);
|
|
25
23
|
} else {
|
|
26
|
-
headers
|
|
24
|
+
headers.set("x-auth-token", params.authToken);
|
|
27
25
|
}
|
|
28
26
|
const response = await fetch(url.href, {
|
|
29
27
|
headers
|
|
@@ -34,19 +32,16 @@ var loadProjectDataByBuildId = async (params) => {
|
|
|
34
32
|
const message = await response.text();
|
|
35
33
|
throw new Error(message.slice(0, 1e3));
|
|
36
34
|
};
|
|
37
|
-
var
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (authToken) {
|
|
42
|
-
url.searchParams.append("authToken", authToken);
|
|
43
|
-
}
|
|
44
|
-
const response = await fetch(url.href);
|
|
45
|
-
if (response.ok) {
|
|
46
|
-
return await response.json();
|
|
35
|
+
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`);
|
|
47
39
|
}
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
return await loadProjectDataByBuildId({
|
|
41
|
+
buildId: result.buildId,
|
|
42
|
+
origin: params.origin,
|
|
43
|
+
authToken: params.authToken
|
|
44
|
+
});
|
|
50
45
|
};
|
|
51
46
|
var buildProjectDomainPrefix = "p-";
|
|
52
47
|
var parseBuilderUrl = (urlStr) => {
|
|
@@ -79,7 +74,6 @@ var parseBuilderUrl = (urlStr) => {
|
|
|
79
74
|
};
|
|
80
75
|
};
|
|
81
76
|
export {
|
|
82
|
-
getLatestBuildUsingProjectId,
|
|
83
77
|
loadProjectDataByBuildId,
|
|
84
78
|
loadProjectDataByProjectId,
|
|
85
79
|
parseBuilderUrl
|
package/lib/types/index.d.ts
CHANGED
|
@@ -21,11 +21,6 @@ export type Data = {
|
|
|
21
21
|
};
|
|
22
22
|
assets: Array<Asset>;
|
|
23
23
|
};
|
|
24
|
-
export declare const loadProjectDataByProjectId: (params: {
|
|
25
|
-
projectId: string;
|
|
26
|
-
origin: string;
|
|
27
|
-
authToken?: string;
|
|
28
|
-
}) => Promise<Data>;
|
|
29
24
|
export declare const loadProjectDataByBuildId: (params: {
|
|
30
25
|
buildId: string;
|
|
31
26
|
origin: string;
|
|
@@ -34,13 +29,11 @@ export declare const loadProjectDataByBuildId: (params: {
|
|
|
34
29
|
} | {
|
|
35
30
|
authToken: string;
|
|
36
31
|
})) => Promise<Data>;
|
|
37
|
-
export declare const
|
|
32
|
+
export declare const loadProjectDataByProjectId: (params: {
|
|
38
33
|
projectId: string;
|
|
39
34
|
origin: string;
|
|
40
|
-
authToken
|
|
41
|
-
}) => Promise<
|
|
42
|
-
buildId: string | null;
|
|
43
|
-
}>;
|
|
35
|
+
authToken: string;
|
|
36
|
+
}) => Promise<Data>;
|
|
44
37
|
export declare const parseBuilderUrl: (urlStr: string) => {
|
|
45
38
|
projectId: undefined;
|
|
46
39
|
sourceOrigin: string;
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/http-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.181.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.
|
|
9
|
+
"@webstudio-is/sdk": "0.181.0"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@jest/globals": "^29.7.0",
|
|
13
13
|
"typescript": "5.5.2",
|
|
14
|
-
"@webstudio-is/
|
|
15
|
-
"@webstudio-is/
|
|
14
|
+
"@webstudio-is/jest-config": "1.0.7",
|
|
15
|
+
"@webstudio-is/tsconfig": "1.0.7"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
18
|
"webstudio": "./src/index.ts",
|