@webstudio-is/http-client 0.191.0 → 0.191.4

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@webstudio-is/http-client",
3
- "version": "0.191.0",
3
+ "version": "0.191.4",
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.191.0"
9
+ "@webstudio-is/sdk": "0.191.4"
10
10
  },
11
11
  "devDependencies": {
12
12
  "vitest": "^2.1.8",
package/lib/index.js DELETED
@@ -1,80 +0,0 @@
1
- // src/index.ts
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 });
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
- };
16
- 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
28
- });
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
- };
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`);
39
- }
40
- return await loadProjectDataByBuildId({
41
- buildId: result.buildId,
42
- origin: params.origin,
43
- authToken: params.authToken
44
- });
45
- };
46
- var buildProjectDomainPrefix = "p-";
47
- var parseBuilderUrl = (urlStr) => {
48
- const url = new URL(urlStr);
49
- const fragments = url.host.split(".");
50
- const re = /^(?<prefix>[a-z-]+)(?<uuid>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})(-dot-(?<branch>.*))?/;
51
- const match = fragments[0].match(re);
52
- const prefix = match?.groups?.prefix;
53
- const projectId = match?.groups?.uuid;
54
- const branch = match?.groups?.branch;
55
- if (prefix !== buildProjectDomainPrefix) {
56
- return {
57
- projectId: void 0,
58
- sourceOrigin: url.origin
59
- };
60
- }
61
- if (projectId === void 0) {
62
- return {
63
- projectId: void 0,
64
- sourceOrigin: url.origin
65
- };
66
- }
67
- fragments[0] = fragments[0].replace(re, branch ?? "");
68
- const sourceUrl = new URL(url.origin);
69
- sourceUrl.protocol = "https";
70
- sourceUrl.host = fragments.filter(Boolean).join(".");
71
- return {
72
- projectId,
73
- sourceOrigin: sourceUrl.origin
74
- };
75
- };
76
- export {
77
- loadProjectDataByBuildId,
78
- loadProjectDataByProjectId,
79
- parseBuilderUrl
80
- };
@@ -1,43 +0,0 @@
1
- import type { Asset, Breakpoint, DataSource, Deployment, Instance, Page, Pages, Prop, Resource, StyleDecl, StyleDeclKey, StyleSource, StyleSourceSelection } from "@webstudio-is/sdk";
2
- export type Data = {
3
- page: Page;
4
- pages: Array<Page>;
5
- build: {
6
- id: string;
7
- projectId: string;
8
- version: number;
9
- createdAt: string;
10
- updatedAt: string;
11
- pages: Pages;
12
- breakpoints: [Breakpoint["id"], Breakpoint][];
13
- styles: [StyleDeclKey, StyleDecl][];
14
- styleSources: [StyleSource["id"], StyleSource][];
15
- styleSourceSelections: [Instance["id"], StyleSourceSelection][];
16
- props: [Prop["id"], Prop][];
17
- instances: [Instance["id"], Instance][];
18
- dataSources: [DataSource["id"], DataSource][];
19
- resources: [Resource["id"], Resource][];
20
- deployment?: Deployment | undefined;
21
- };
22
- assets: Array<Asset>;
23
- };
24
- export declare const loadProjectDataByBuildId: (params: {
25
- buildId: string;
26
- origin: string;
27
- } & ({
28
- seviceToken: string;
29
- } | {
30
- authToken: string;
31
- })) => Promise<Data>;
32
- export declare const loadProjectDataByProjectId: (params: {
33
- projectId: string;
34
- origin: string;
35
- authToken: string;
36
- }) => Promise<Data>;
37
- export declare const parseBuilderUrl: (urlStr: string) => {
38
- projectId: undefined;
39
- sourceOrigin: string;
40
- } | {
41
- projectId: string;
42
- sourceOrigin: string;
43
- };
@@ -1 +0,0 @@
1
- export {};