@webstudio-is/sdk 0.122.0 → 0.124.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
@@ -62,8 +62,8 @@ var HomePage = z2.object({
62
62
  path: HomePagePath
63
63
  });
64
64
  var PagePath = z2.string().refine((path) => path !== "", "Can't be empty").refine((path) => path !== "/", "Can't be just a /").refine((path) => path === "" || path.startsWith("/"), "Must start with a /").refine((path) => path.endsWith("/") === false, "Can't end with a /").refine((path) => path.includes("//") === false, "Can't contain repeating /").refine(
65
- (path) => /^[-_a-z0-9*:\\/]*$/.test(path),
66
- "Only a-z, 0-9, -, _, /, : and * are allowed"
65
+ (path) => /^[-_a-z0-9*:?\\/]*$/.test(path),
66
+ "Only a-z, 0-9, -, _, /, :, ? and * are allowed"
67
67
  ).refine(
68
68
  // We use /s for our system stuff like /s/css or /s/uploads
69
69
  (path) => path !== "/s" && path.startsWith("/s/") === false,
@@ -78,13 +78,19 @@ var Page = z2.object({
78
78
  ...commonPageFields,
79
79
  path: PagePath
80
80
  });
81
- var SiteMeta = z2.object({
81
+ var ProjectMeta = z2.object({
82
+ // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
82
83
  siteName: z2.string().optional(),
83
84
  faviconAssetId: z2.string().optional(),
84
85
  code: z2.string().optional()
85
86
  });
87
+ var ProjectSettings = z2.object({
88
+ // All fields are optional to ensure consistency and allow for the addition of new fields without requiring migration
89
+ atomicStyles: z2.boolean().optional()
90
+ });
86
91
  var Pages = z2.object({
87
- meta: SiteMeta.optional(),
92
+ meta: ProjectMeta.optional(),
93
+ settings: ProjectSettings.optional(),
88
94
  homePage: HomePage,
89
95
  pages: z2.array(Page).refine(
90
96
  (array) => new Set(array.map((page) => page.path)).size === array.length,
@@ -151,97 +157,130 @@ var DataSource = z4.union([
151
157
  id: DataSourceId,
152
158
  scopeInstanceId: z4.optional(z4.string()),
153
159
  name: z4.string()
160
+ }),
161
+ z4.object({
162
+ type: z4.literal("resource"),
163
+ id: DataSourceId,
164
+ scopeInstanceId: z4.optional(z4.string()),
165
+ name: z4.string(),
166
+ resourceId: z4.string()
154
167
  })
155
168
  ]);
156
169
  var DataSources = z4.map(DataSourceId, DataSource);
157
170
 
158
- // src/schema/props.ts
171
+ // src/schema/resources.ts
159
172
  import { z as z5 } from "zod";
160
- var PropId = z5.string();
173
+ var ResourceId = z5.string();
174
+ var Method = z5.union([
175
+ z5.literal("get"),
176
+ z5.literal("post"),
177
+ z5.literal("put"),
178
+ z5.literal("delete")
179
+ ]);
180
+ var Header = z5.object({
181
+ name: z5.string(),
182
+ // expression
183
+ value: z5.string()
184
+ });
185
+ var Resource = z5.object({
186
+ id: ResourceId,
187
+ name: z5.string(),
188
+ method: Method,
189
+ // expression
190
+ url: z5.string(),
191
+ headers: z5.array(Header),
192
+ // expression
193
+ body: z5.optional(z5.string())
194
+ });
195
+ var Resources = z5.map(ResourceId, Resource);
196
+
197
+ // src/schema/props.ts
198
+ import { z as z6 } from "zod";
199
+ var PropId = z6.string();
161
200
  var baseProp = {
162
201
  id: PropId,
163
- instanceId: z5.string(),
164
- name: z5.string(),
165
- required: z5.optional(z5.boolean())
202
+ instanceId: z6.string(),
203
+ name: z6.string(),
204
+ required: z6.optional(z6.boolean())
166
205
  };
167
- var Prop = z5.union([
168
- z5.object({
206
+ var Prop = z6.union([
207
+ z6.object({
169
208
  ...baseProp,
170
- type: z5.literal("number"),
171
- value: z5.number()
209
+ type: z6.literal("number"),
210
+ value: z6.number()
172
211
  }),
173
- z5.object({
212
+ z6.object({
174
213
  ...baseProp,
175
- type: z5.literal("string"),
176
- value: z5.string()
214
+ type: z6.literal("string"),
215
+ value: z6.string()
177
216
  }),
178
- z5.object({
217
+ z6.object({
179
218
  ...baseProp,
180
- type: z5.literal("boolean"),
181
- value: z5.boolean()
219
+ type: z6.literal("boolean"),
220
+ value: z6.boolean()
182
221
  }),
183
- z5.object({
222
+ z6.object({
184
223
  ...baseProp,
185
- type: z5.literal("json"),
186
- value: z5.unknown()
224
+ type: z6.literal("json"),
225
+ value: z6.unknown()
187
226
  }),
188
- z5.object({
227
+ z6.object({
189
228
  ...baseProp,
190
- type: z5.literal("asset"),
191
- value: z5.string()
229
+ type: z6.literal("asset"),
230
+ value: z6.string()
192
231
  // asset id
193
232
  }),
194
- z5.object({
233
+ z6.object({
195
234
  ...baseProp,
196
- type: z5.literal("page"),
197
- value: z5.union([
198
- z5.string(),
235
+ type: z6.literal("page"),
236
+ value: z6.union([
237
+ z6.string(),
199
238
  // page id
200
- z5.object({
201
- pageId: z5.string(),
202
- instanceId: z5.string()
239
+ z6.object({
240
+ pageId: z6.string(),
241
+ instanceId: z6.string()
203
242
  })
204
243
  ])
205
244
  }),
206
- z5.object({
245
+ z6.object({
207
246
  ...baseProp,
208
- type: z5.literal("string[]"),
209
- value: z5.array(z5.string())
247
+ type: z6.literal("string[]"),
248
+ value: z6.array(z6.string())
210
249
  }),
211
- z5.object({
250
+ z6.object({
212
251
  ...baseProp,
213
- type: z5.literal("parameter"),
252
+ type: z6.literal("parameter"),
214
253
  // data source id
215
- value: z5.string()
254
+ value: z6.string()
216
255
  }),
217
- z5.object({
256
+ z6.object({
218
257
  ...baseProp,
219
- type: z5.literal("expression"),
258
+ type: z6.literal("expression"),
220
259
  // expression code
221
- value: z5.string()
260
+ value: z6.string()
222
261
  }),
223
- z5.object({
262
+ z6.object({
224
263
  ...baseProp,
225
- type: z5.literal("action"),
226
- value: z5.array(
227
- z5.object({
228
- type: z5.literal("execute"),
229
- args: z5.array(z5.string()),
230
- code: z5.string()
264
+ type: z6.literal("action"),
265
+ value: z6.array(
266
+ z6.object({
267
+ type: z6.literal("execute"),
268
+ args: z6.array(z6.string()),
269
+ code: z6.string()
231
270
  })
232
271
  )
233
272
  })
234
273
  ]);
235
- var Props = z5.map(PropId, Prop);
274
+ var Props = z6.map(PropId, Prop);
236
275
 
237
276
  // src/schema/breakpoints.ts
238
- import { z as z6 } from "zod";
239
- var BreakpointId = z6.string();
240
- var Breakpoint = z6.object({
277
+ import { z as z7 } from "zod";
278
+ var BreakpointId = z7.string();
279
+ var Breakpoint = z7.object({
241
280
  id: BreakpointId,
242
- label: z6.string(),
243
- minWidth: z6.number().optional(),
244
- maxWidth: z6.number().optional()
281
+ label: z7.string(),
282
+ minWidth: z7.number().optional(),
283
+ maxWidth: z7.number().optional()
245
284
  }).refine(({ minWidth, maxWidth }) => {
246
285
  return (
247
286
  // Either min or max width have to be defined
@@ -249,7 +288,7 @@ var Breakpoint = z6.object({
249
288
  minWidth === void 0 && maxWidth === void 0
250
289
  );
251
290
  }, "Either minWidth or maxWidth should be defined");
252
- var Breakpoints = z6.map(BreakpointId, Breakpoint);
291
+ var Breakpoints = z7.map(BreakpointId, Breakpoint);
253
292
  var initialBreakpoints = [
254
293
  { id: "placeholder", label: "Base" },
255
294
  { id: "placeholder", label: "Tablet", maxWidth: 991 },
@@ -258,52 +297,52 @@ var initialBreakpoints = [
258
297
  ];
259
298
 
260
299
  // src/schema/style-sources.ts
261
- import { z as z7 } from "zod";
262
- var StyleSourceId = z7.string();
263
- var StyleSourceToken = z7.object({
264
- type: z7.literal("token"),
300
+ import { z as z8 } from "zod";
301
+ var StyleSourceId = z8.string();
302
+ var StyleSourceToken = z8.object({
303
+ type: z8.literal("token"),
265
304
  id: StyleSourceId,
266
- name: z7.string()
305
+ name: z8.string()
267
306
  });
268
- var StyleSourceLocal = z7.object({
269
- type: z7.literal("local"),
307
+ var StyleSourceLocal = z8.object({
308
+ type: z8.literal("local"),
270
309
  id: StyleSourceId
271
310
  });
272
- var StyleSource = z7.union([StyleSourceToken, StyleSourceLocal]);
273
- var StyleSources = z7.map(StyleSourceId, StyleSource);
311
+ var StyleSource = z8.union([StyleSourceToken, StyleSourceLocal]);
312
+ var StyleSources = z8.map(StyleSourceId, StyleSource);
274
313
 
275
314
  // src/schema/style-source-selections.ts
276
- import { z as z8 } from "zod";
277
- var InstanceId2 = z8.string();
278
- var StyleSourceId2 = z8.string();
279
- var StyleSourceSelection = z8.object({
315
+ import { z as z9 } from "zod";
316
+ var InstanceId2 = z9.string();
317
+ var StyleSourceId2 = z9.string();
318
+ var StyleSourceSelection = z9.object({
280
319
  instanceId: InstanceId2,
281
- values: z8.array(StyleSourceId2)
320
+ values: z9.array(StyleSourceId2)
282
321
  });
283
- var StyleSourceSelections = z8.map(InstanceId2, StyleSourceSelection);
322
+ var StyleSourceSelections = z9.map(InstanceId2, StyleSourceSelection);
284
323
 
285
324
  // src/schema/styles.ts
286
- import { z as z9 } from "zod";
325
+ import { z as z10 } from "zod";
287
326
  import { StyleValue } from "@webstudio-is/css-engine";
288
- var StyleDeclRaw = z9.object({
289
- styleSourceId: z9.string(),
290
- breakpointId: z9.string(),
291
- state: z9.optional(z9.string()),
327
+ var StyleDeclRaw = z10.object({
328
+ styleSourceId: z10.string(),
329
+ breakpointId: z10.string(),
330
+ state: z10.optional(z10.string()),
292
331
  // @todo can't figure out how to make property to be enum
293
- property: z9.string(),
332
+ property: z10.string(),
294
333
  value: StyleValue
295
334
  });
296
335
  var StyleDecl = StyleDeclRaw;
297
336
  var getStyleDeclKey = (styleDecl) => {
298
337
  return `${styleDecl.styleSourceId}:${styleDecl.breakpointId}:${styleDecl.property}:${styleDecl.state ?? ""}`;
299
338
  };
300
- var Styles = z9.map(z9.string(), StyleDecl);
339
+ var Styles = z10.map(z10.string(), StyleDecl);
301
340
 
302
341
  // src/schema/deployment.ts
303
- import { z as z10 } from "zod";
304
- var Deployment = z10.object({
305
- domains: z10.array(z10.string()),
306
- projectDomain: z10.string()
342
+ import { z as z11 } from "zod";
343
+ var Deployment = z11.object({
344
+ domains: z11.array(z11.string()),
345
+ projectDomain: z11.string()
307
346
  });
308
347
 
309
348
  // src/instances-utils.ts
@@ -387,6 +426,34 @@ var createScope = (occupiedIdentifiers = []) => {
387
426
  getName
388
427
  };
389
428
  };
429
+
430
+ // src/resource-loader.ts
431
+ var loadResource = async (resourceData) => {
432
+ const { url, method, headers, body } = resourceData;
433
+ const requestHeaders = new Headers(
434
+ headers.map(({ name, value }) => [name, value])
435
+ );
436
+ const requestInit = {
437
+ method,
438
+ headers: requestHeaders
439
+ };
440
+ if (method !== "get" && body !== void 0) {
441
+ requestInit.body = body;
442
+ }
443
+ const response = await fetch(url, requestInit);
444
+ let data;
445
+ if (response.ok && // accept json by default and when specified explicitly
446
+ (requestHeaders.has("accept") === false || requestHeaders.get("accept") === "application/json")) {
447
+ data = await response.json();
448
+ } else {
449
+ data = await response.text();
450
+ }
451
+ return {
452
+ data,
453
+ status: response.status,
454
+ statusText: response.statusText
455
+ };
456
+ };
390
457
  export {
391
458
  Asset,
392
459
  Assets,
@@ -409,6 +476,8 @@ export {
409
476
  Pages,
410
477
  Prop,
411
478
  Props,
479
+ Resource,
480
+ Resources,
412
481
  StyleDecl,
413
482
  StyleSource,
414
483
  StyleSourceSelection,
@@ -421,5 +490,6 @@ export {
421
490
  findTreeInstanceIdsExcludingSlotDescendants,
422
491
  getStyleDeclKey,
423
492
  initialBreakpoints,
493
+ loadResource,
424
494
  parseComponentName
425
495
  };
@@ -2,6 +2,7 @@ export * from "./schema/assets";
2
2
  export * from "./schema/pages";
3
3
  export * from "./schema/instances";
4
4
  export * from "./schema/data-sources";
5
+ export * from "./schema/resources";
5
6
  export * from "./schema/props";
6
7
  export * from "./schema/breakpoints";
7
8
  export * from "./schema/style-sources";
@@ -10,3 +11,4 @@ export * from "./schema/styles";
10
11
  export * from "./schema/deployment";
11
12
  export * from "./instances-utils";
12
13
  export * from "./scope";
14
+ export * from "./resource-loader";
@@ -0,0 +1,6 @@
1
+ import type { Resource } from "./schema/resources";
2
+ export declare const loadResource: (resourceData: Resource) => Promise<{
3
+ data: any;
4
+ status: number;
5
+ statusText: string;
6
+ }>;
@@ -153,6 +153,24 @@ export declare const DataSource: z.ZodUnion<[z.ZodObject<{
153
153
  name: string;
154
154
  id: string;
155
155
  scopeInstanceId?: string | undefined;
156
+ }>, z.ZodObject<{
157
+ type: z.ZodLiteral<"resource">;
158
+ id: z.ZodString;
159
+ scopeInstanceId: z.ZodOptional<z.ZodString>;
160
+ name: z.ZodString;
161
+ resourceId: z.ZodString;
162
+ }, "strip", z.ZodTypeAny, {
163
+ type: "resource";
164
+ name: string;
165
+ id: string;
166
+ resourceId: string;
167
+ scopeInstanceId?: string | undefined;
168
+ }, {
169
+ type: "resource";
170
+ name: string;
171
+ id: string;
172
+ resourceId: string;
173
+ scopeInstanceId?: string | undefined;
156
174
  }>]>;
157
175
  export type DataSource = z.infer<typeof DataSource>;
158
176
  export declare const DataSources: z.ZodMap<z.ZodString, z.ZodUnion<[z.ZodObject<{
@@ -263,5 +281,23 @@ export declare const DataSources: z.ZodMap<z.ZodString, z.ZodUnion<[z.ZodObject<
263
281
  name: string;
264
282
  id: string;
265
283
  scopeInstanceId?: string | undefined;
284
+ }>, z.ZodObject<{
285
+ type: z.ZodLiteral<"resource">;
286
+ id: z.ZodString;
287
+ scopeInstanceId: z.ZodOptional<z.ZodString>;
288
+ name: z.ZodString;
289
+ resourceId: z.ZodString;
290
+ }, "strip", z.ZodTypeAny, {
291
+ type: "resource";
292
+ name: string;
293
+ id: string;
294
+ resourceId: string;
295
+ scopeInstanceId?: string | undefined;
296
+ }, {
297
+ type: "resource";
298
+ name: string;
299
+ id: string;
300
+ resourceId: string;
301
+ scopeInstanceId?: string | undefined;
266
302
  }>]>>;
267
303
  export type DataSources = z.infer<typeof DataSources>;
@@ -79,7 +79,7 @@ declare const Page: z.ZodObject<{
79
79
  rootInstanceId: string;
80
80
  pathVariableId?: string | undefined;
81
81
  }>;
82
- declare const SiteMeta: z.ZodObject<{
82
+ declare const ProjectMeta: z.ZodObject<{
83
83
  siteName: z.ZodOptional<z.ZodString>;
84
84
  faviconAssetId: z.ZodOptional<z.ZodString>;
85
85
  code: z.ZodOptional<z.ZodString>;
@@ -92,7 +92,7 @@ declare const SiteMeta: z.ZodObject<{
92
92
  faviconAssetId?: string | undefined;
93
93
  code?: string | undefined;
94
94
  }>;
95
- export type SiteMeta = z.infer<typeof SiteMeta>;
95
+ export type ProjectMeta = z.infer<typeof ProjectMeta>;
96
96
  export type Page = z.infer<typeof Page>;
97
97
  export declare const Pages: z.ZodObject<{
98
98
  meta: z.ZodOptional<z.ZodObject<{
@@ -108,6 +108,13 @@ export declare const Pages: z.ZodObject<{
108
108
  faviconAssetId?: string | undefined;
109
109
  code?: string | undefined;
110
110
  }>>;
111
+ settings: z.ZodOptional<z.ZodObject<{
112
+ atomicStyles: z.ZodOptional<z.ZodBoolean>;
113
+ }, "strip", z.ZodTypeAny, {
114
+ atomicStyles?: boolean | undefined;
115
+ }, {
116
+ atomicStyles?: boolean | undefined;
117
+ }>>;
111
118
  homePage: z.ZodObject<{
112
119
  path: z.ZodEffects<z.ZodString, string, string>;
113
120
  id: z.ZodString;
@@ -336,6 +343,9 @@ export declare const Pages: z.ZodObject<{
336
343
  faviconAssetId?: string | undefined;
337
344
  code?: string | undefined;
338
345
  } | undefined;
346
+ settings?: {
347
+ atomicStyles?: boolean | undefined;
348
+ } | undefined;
339
349
  }, {
340
350
  homePage: {
341
351
  path: string;
@@ -378,6 +388,9 @@ export declare const Pages: z.ZodObject<{
378
388
  faviconAssetId?: string | undefined;
379
389
  code?: string | undefined;
380
390
  } | undefined;
391
+ settings?: {
392
+ atomicStyles?: boolean | undefined;
393
+ } | undefined;
381
394
  }>;
382
395
  export type Pages = z.infer<typeof Pages>;
383
396
  export {};
@@ -0,0 +1,77 @@
1
+ import { z } from "zod";
2
+ export declare const Resource: z.ZodObject<{
3
+ id: z.ZodString;
4
+ name: z.ZodString;
5
+ method: z.ZodUnion<[z.ZodLiteral<"get">, z.ZodLiteral<"post">, z.ZodLiteral<"put">, z.ZodLiteral<"delete">]>;
6
+ url: z.ZodString;
7
+ headers: z.ZodArray<z.ZodObject<{
8
+ name: z.ZodString;
9
+ value: z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ value: string;
12
+ name: string;
13
+ }, {
14
+ value: string;
15
+ name: string;
16
+ }>, "many">;
17
+ body: z.ZodOptional<z.ZodString>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ name: string;
20
+ id: string;
21
+ method: "get" | "post" | "put" | "delete";
22
+ url: string;
23
+ headers: {
24
+ value: string;
25
+ name: string;
26
+ }[];
27
+ body?: string | undefined;
28
+ }, {
29
+ name: string;
30
+ id: string;
31
+ method: "get" | "post" | "put" | "delete";
32
+ url: string;
33
+ headers: {
34
+ value: string;
35
+ name: string;
36
+ }[];
37
+ body?: string | undefined;
38
+ }>;
39
+ export type Resource = z.infer<typeof Resource>;
40
+ export declare const Resources: z.ZodMap<z.ZodString, z.ZodObject<{
41
+ id: z.ZodString;
42
+ name: z.ZodString;
43
+ method: z.ZodUnion<[z.ZodLiteral<"get">, z.ZodLiteral<"post">, z.ZodLiteral<"put">, z.ZodLiteral<"delete">]>;
44
+ url: z.ZodString;
45
+ headers: z.ZodArray<z.ZodObject<{
46
+ name: z.ZodString;
47
+ value: z.ZodString;
48
+ }, "strip", z.ZodTypeAny, {
49
+ value: string;
50
+ name: string;
51
+ }, {
52
+ value: string;
53
+ name: string;
54
+ }>, "many">;
55
+ body: z.ZodOptional<z.ZodString>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ name: string;
58
+ id: string;
59
+ method: "get" | "post" | "put" | "delete";
60
+ url: string;
61
+ headers: {
62
+ value: string;
63
+ name: string;
64
+ }[];
65
+ body?: string | undefined;
66
+ }, {
67
+ name: string;
68
+ id: string;
69
+ method: "get" | "post" | "put" | "delete";
70
+ url: string;
71
+ headers: {
72
+ value: string;
73
+ name: string;
74
+ }[];
75
+ body?: string | undefined;
76
+ }>>;
77
+ export type Resources = z.infer<typeof Resources>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webstudio-is/sdk",
3
- "version": "0.122.0",
4
- "description": "Webstudio site data schema",
3
+ "version": "0.124.0",
4
+ "description": "Webstudio project data schema",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
7
7
  "license": "AGPL-3.0-or-later",
@@ -19,8 +19,8 @@
19
19
  "sideEffects": false,
20
20
  "dependencies": {
21
21
  "zod": "^3.21.4",
22
- "@webstudio-is/css-engine": "0.122.0",
23
- "@webstudio-is/fonts": "0.122.0"
22
+ "@webstudio-is/css-engine": "0.124.0",
23
+ "@webstudio-is/fonts": "0.124.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@jest/globals": "^29.7.0",