@webstudio-is/http-client 0.99.1-e132cba.0 → 0.100.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,10 +1,10 @@
1
1
  // src/index.ts
2
2
  var loadProjectDataById = async (params) => {
3
3
  const result = await getLatestBuildUsingProjectId(params);
4
- if (result === null) {
5
- throw new Error(``);
4
+ if (result.buildId === null) {
5
+ throw new Error(`The project is not published yet`);
6
6
  }
7
- const url = new URL(params.host);
7
+ const url = new URL(params.origin);
8
8
  url.pathname = `/rest/build/${result.buildId}`;
9
9
  if (params.authToken) {
10
10
  url.searchParams.append("authToken", params.authToken);
@@ -16,9 +16,23 @@ var loadProjectDataById = async (params) => {
16
16
  const message = await response.text();
17
17
  throw new Error(message.slice(0, 1e3));
18
18
  };
19
+ var loadProjectDataByBuildId = async (params) => {
20
+ const url = new URL(params.origin);
21
+ url.pathname = `/rest/build/${params.buildId}`;
22
+ const response = await fetch(url.href, {
23
+ headers: {
24
+ Authorization: params.authToken
25
+ }
26
+ });
27
+ if (response.ok) {
28
+ return await response.json();
29
+ }
30
+ const message = await response.text();
31
+ throw new Error(message.slice(0, 1e3));
32
+ };
19
33
  var getLatestBuildUsingProjectId = async (params) => {
20
- const { host, projectId, authToken } = params;
21
- const url = new URL(host);
34
+ const { origin, projectId, authToken } = params;
35
+ const url = new URL(origin);
22
36
  url.pathname = `/rest/buildId/${projectId}`;
23
37
  if (authToken) {
24
38
  url.searchParams.append("authToken", authToken);
@@ -32,5 +46,6 @@ var getLatestBuildUsingProjectId = async (params) => {
32
46
  };
33
47
  export {
34
48
  getLatestBuildUsingProjectId,
49
+ loadProjectDataByBuildId,
35
50
  loadProjectDataById
36
51
  };
@@ -19,17 +19,20 @@ export type Data = {
19
19
  };
20
20
  assets: Array<Asset>;
21
21
  };
22
- interface DefaultArgs {
23
- host: string;
24
- authToken?: string;
25
- }
26
- type ResourceFactory<T, K> = (params: DefaultArgs & T) => Promise<K>;
27
- export declare const loadProjectDataById: ResourceFactory<{
28
- projectId: string;
29
- }, Data>;
30
- export declare const getLatestBuildUsingProjectId: ResourceFactory<{
22
+ export declare const loadProjectDataById: (params: {
31
23
  projectId: string;
32
- }, {
24
+ origin: string;
25
+ authToken?: string;
26
+ }) => Promise<Data>;
27
+ export declare const loadProjectDataByBuildId: (params: {
33
28
  buildId: string;
29
+ origin: string;
30
+ authToken: string;
31
+ }) => Promise<Data>;
32
+ export declare const getLatestBuildUsingProjectId: (params: {
33
+ projectId: string;
34
+ origin: string;
35
+ authToken?: string;
36
+ }) => Promise<{
37
+ buildId: string | null;
34
38
  }>;
35
- export {};
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@webstudio-is/http-client",
3
- "version": "0.99.1-e132cba.0",
3
+ "version": "0.100.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.99.1-e132cba.0"
9
+ "@webstudio-is/sdk": "0.100.0"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@jest/globals": "^29.6.4",
13
13
  "jest": "^29.6.4",
14
14
  "typescript": "5.2.2",
15
- "@webstudio-is/jest-config": "^1.0.8-e132cba.0",
16
- "@webstudio-is/tsconfig": "^1.0.8-e132cba.0"
15
+ "@webstudio-is/jest-config": "1.0.7",
16
+ "@webstudio-is/tsconfig": "1.0.7"
17
17
  },
18
18
  "exports": {
19
19
  "source": "./src/index.ts",