@supernova-studio/client 0.59.1 → 0.59.3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.59.1",
3
+ "version": "0.59.3",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -32,13 +32,12 @@
32
32
  "license": "ISC",
33
33
  "dependencies": {
34
34
  "prosemirror-model": "1.22.3",
35
- "typescript": "5.0.4",
36
35
  "y-prosemirror": "1.2.2",
37
36
  "yjs": "13.6.19",
38
37
  "zod": "3.23.6"
39
38
  },
40
39
  "devDependencies": {
41
40
  "tsup": "8.0.2",
42
- "typescript": "5.0.4"
41
+ "typescript": "5.7.3"
43
42
  }
44
43
  }
@@ -33,7 +33,12 @@ import {
33
33
  DTODocumentationPageUpdateActionInputV2,
34
34
  DTODocumentationPageUpdateActionOutputV2,
35
35
  } from "./documentation/page-actions-v2";
36
- import { DTOFigmaNodeRenderActionInput, DTOFigmaNodeRenderActionOutput } from "./figma-nodes/node-actions-v2";
36
+ import {
37
+ DTOFigmaNodeRenderActionInput,
38
+ DTOFigmaNodeRenderActionOutput,
39
+ DTOFigmaNodeRenderAsyncActionInput,
40
+ DTOFigmaNodeRenderAsyncActionOutput,
41
+ } from "./figma-nodes/node-actions-v2";
37
42
 
38
43
  //
39
44
  // Read
@@ -58,6 +63,7 @@ export const DTOElementActionOutput = z.discriminatedUnion("type", [
58
63
 
59
64
  // Figma frames
60
65
  DTOFigmaNodeRenderActionOutput,
66
+ DTOFigmaNodeRenderAsyncActionOutput,
61
67
 
62
68
  // Restore
63
69
  DTODocumentationPageRestoreActionOutput,
@@ -92,6 +98,7 @@ export const DTOElementActionInput = z.discriminatedUnion("type", [
92
98
 
93
99
  // Figma frames
94
100
  DTOFigmaNodeRenderActionInput,
101
+ DTOFigmaNodeRenderAsyncActionInput,
95
102
 
96
103
  // Restore
97
104
  DTODocumentationPageRestoreActionInput,
@@ -0,0 +1,32 @@
1
+ import { FigmaNodeReference } from "@supernova-studio/model";
2
+ import { z } from "zod";
3
+ import { DTOFigmaNodeOrigin, DTOFigmaNodeRenderFormat } from "./figma-node";
4
+
5
+ export const DTOFigmaNodeData = z.object({
6
+ // Id of the node in the Figma file
7
+ figmaNodeId: z.string(),
8
+
9
+ // Validity
10
+ isValid: z.boolean(),
11
+
12
+ // Asset data
13
+ assetId: z.string(),
14
+ assetUrl: z.string(),
15
+ assetFormat: DTOFigmaNodeRenderFormat,
16
+
17
+ // Asset metadata
18
+ assetScale: z.number(),
19
+ assetWidth: z.number().optional(),
20
+ assetHeight: z.number().optional(),
21
+ });
22
+
23
+ export const DTOFigmaNode = FigmaNodeReference.omit({
24
+ data: true,
25
+ origin: true,
26
+ }).extend({
27
+ data: DTOFigmaNodeData,
28
+ origin: DTOFigmaNodeOrigin,
29
+ });
30
+
31
+ export type DTOFigmaNodeData = z.infer<typeof DTOFigmaNodeData>;
32
+ export type DTOFigmaNode = z.infer<typeof DTOFigmaNode>;
@@ -0,0 +1,32 @@
1
+ import {
2
+ FigmaNodeReference,
3
+ FigmaNodeRenderedImage,
4
+ FigmaNodeRenderError,
5
+ FigmaNodeRenderFormat,
6
+ FigmaNodeRenderState,
7
+ } from "@supernova-studio/model";
8
+ import { z } from "zod";
9
+ import { DTOFigmaNodeOrigin } from "./figma-node";
10
+
11
+ export const DTOFigmaNodeDataV2 = z.object({
12
+ sceneNodeId: z.string(),
13
+ format: FigmaNodeRenderFormat,
14
+ scale: z.number().optional(),
15
+
16
+ renderState: FigmaNodeRenderState,
17
+ renderedImage: FigmaNodeRenderedImage.optional(),
18
+ renderError: FigmaNodeRenderError.optional(),
19
+
20
+ hasSource: z.boolean(),
21
+ });
22
+
23
+ export const DTOFigmaNodeV2 = FigmaNodeReference.omit({
24
+ data: true,
25
+ origin: true,
26
+ }).extend({
27
+ data: DTOFigmaNodeDataV2,
28
+ origin: DTOFigmaNodeOrigin,
29
+ });
30
+
31
+ export type DTOFigmaNodeDataV2 = z.infer<typeof DTOFigmaNodeDataV2>;
32
+ export type DTOFigmaNodeV2 = z.infer<typeof DTOFigmaNodeV2>;
@@ -1,4 +1,4 @@
1
- import { FigmaNodeReference, FigmaNodeRenderFormat } from "@supernova-studio/model";
1
+ import { FigmaNodeRenderFormat } from "@supernova-studio/model";
2
2
  import { z } from "zod";
3
3
 
4
4
  //
@@ -18,35 +18,7 @@ export const DTOFigmaNodeOrigin = z.object({
18
18
  parentName: z.string().optional(),
19
19
  });
20
20
 
21
- export const DTOFigmaNodeData = z.object({
22
- // Id of the node in the Figma file
23
- figmaNodeId: z.string(),
24
-
25
- // Validity
26
- isValid: z.boolean(),
27
-
28
- // Asset data
29
- assetId: z.string(),
30
- assetUrl: z.string(),
31
- assetFormat: DTOFigmaNodeRenderFormat,
32
-
33
- // Asset metadata
34
- assetScale: z.number(),
35
- assetWidth: z.number().optional(),
36
- assetHeight: z.number().optional(),
37
- });
38
-
39
- export const DTOFigmaNode = FigmaNodeReference.omit({
40
- data: true,
41
- origin: true,
42
- }).extend({
43
- data: DTOFigmaNodeData,
44
- origin: DTOFigmaNodeOrigin,
45
- });
46
-
47
21
  export type DTOFigmaNodeOrigin = z.infer<typeof DTOFigmaNodeOrigin>;
48
- export type DTOFigmaNodeData = z.infer<typeof DTOFigmaNodeData>;
49
- export type DTOFigmaNode = z.infer<typeof DTOFigmaNode>;
50
22
 
51
23
  //
52
24
  // Write
@@ -60,6 +32,11 @@ const DTOFigmaNodeRenderInputBase = z.object({
60
32
  * Format in which the node must be rendered, png by default.
61
33
  */
62
34
  format: FigmaNodeRenderFormat.default("Png"),
35
+
36
+ /**
37
+ * Scale to apply to PNG images, can be between 1 and 4. Scale is ignored for other image formats.
38
+ */
39
+ scale: z.number().optional(),
63
40
  });
64
41
 
65
42
  /**
@@ -1,2 +1,4 @@
1
+ export * from "./figma-node-v1";
2
+ export * from "./figma-node-v2";
1
3
  export * from "./figma-node";
2
4
  export * from "./node-actions-v2";
@@ -1,24 +1,44 @@
1
1
  import { z } from "zod";
2
- import { DTOFigmaNode, DTOFigmaNodeRenderInput } from "./figma-node";
2
+ import { DTOFigmaNodeRenderInput } from "./figma-node";
3
+ import { DTOFigmaNode } from "./figma-node-v1";
4
+ import { DTOFigmaNodeV2 } from "./figma-node-v2";
3
5
 
4
6
  //
5
7
  // Read
6
8
  //
7
9
 
10
+ /**
11
+ * @deprecated Please use FigmaNodeRenderAsync (DTOFigmaNodeRenderAsyncActionOutput)
12
+ */
8
13
  export const DTOFigmaNodeRenderActionOutput = z.object({
9
14
  type: z.literal("FigmaNodeRender"),
10
15
  figmaNodes: z.array(DTOFigmaNode),
11
16
  });
12
17
 
18
+ export const DTOFigmaNodeRenderAsyncActionOutput = z.object({
19
+ type: z.literal("FigmaNodeRenderAsync"),
20
+ figmaNodes: z.array(DTOFigmaNodeV2),
21
+ });
22
+
13
23
  export type DTOFigmaNodeRenderActionOutput = z.infer<typeof DTOFigmaNodeRenderActionOutput>;
24
+ export type DTOFigmaNodeRenderAsyncActionOutput = z.infer<typeof DTOFigmaNodeRenderAsyncActionOutput>;
14
25
 
15
26
  //
16
27
  // Read
17
28
  //
18
29
 
30
+ /**
31
+ * @deprecated Please use FigmaNodeRenderAsync (DTOFigmaNodeRenderAsyncActionInput)
32
+ */
19
33
  export const DTOFigmaNodeRenderActionInput = z.object({
20
34
  type: z.literal("FigmaNodeRender"),
21
35
  input: DTOFigmaNodeRenderInput.array(),
22
36
  });
23
37
 
38
+ export const DTOFigmaNodeRenderAsyncActionInput = z.object({
39
+ type: z.literal("FigmaNodeRenderAsync"),
40
+ nodes: DTOFigmaNodeRenderInput.array(),
41
+ });
42
+
24
43
  export type DTOFigmaNodeRenderActionInput = z.infer<typeof DTOFigmaNodeRenderActionInput>;
44
+ export type DTOFigmaNodeRenderAsyncActionInput = z.infer<typeof DTOFigmaNodeRenderAsyncActionInput>;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { DTOFigmaNode } from "./figma-nodes";
2
+ import { DTOFigmaNode, DTOFigmaNodeV2 } from "./figma-nodes";
3
3
 
4
4
  //
5
5
  // Read
@@ -9,13 +9,19 @@ export const DTOElementsGetTypeFilter = z.enum(["FigmaNode"]);
9
9
 
10
10
  export const DTOElementsGetQuerySchema = z.object({
11
11
  types: z.string().transform(val => val.split(",").map(v => DTOElementsGetTypeFilter.parse(v))),
12
+ responseVersion: z.coerce.number().default(1),
12
13
  });
13
14
 
14
15
  export const DTOElementsGetOutput = z.object({
15
16
  figmaNodes: z.array(DTOFigmaNode).optional(),
16
17
  });
17
18
 
19
+ export const DTOElementsGetOutputV2 = z.object({
20
+ figmaNodes: z.array(DTOFigmaNodeV2).optional(),
21
+ });
22
+
18
23
  export type DTOElementsGetOutput = z.infer<typeof DTOElementsGetOutput>;
24
+ export type DTOElementsGetOutputV2 = z.infer<typeof DTOElementsGetOutputV2>;
19
25
  export type DTOElementsGetQueryRaw = z.input<typeof DTOElementsGetQuerySchema>;
20
26
  export type DTOElementsGetQueryParsed = z.output<typeof DTOElementsGetQuerySchema>;
21
27
  export type DTOElementsGetTypeFilter = z.infer<typeof DTOElementsGetTypeFilter>;
@@ -42,6 +42,10 @@ export class ElementsActionEndpoint {
42
42
  return this.action(dsId, vId, { type: "FigmaNodeRender", input });
43
43
  }
44
44
 
45
+ async renderNodesAsync(dsId: string, vId: string, nodes: DTOFigmaNodeRenderInput[]) {
46
+ return this.action(dsId, vId, { type: "FigmaNodeRenderAsync", nodes });
47
+ }
48
+
45
49
  private async action(dsId: string, vId: string, input: DTOElementActionInput) {
46
50
  return this.requestExecutor.json(
47
51
  `/design-systems/${dsId}/versions/${vId}/elements-action`,
@@ -1,13 +1,27 @@
1
+ import { OmitStrict } from "@supernova-studio/model";
1
2
  import { serializeQuery } from "../../../../utils";
2
- import { DTOElementsGetOutput, DTOElementsGetQueryParsed } from "../../../dto";
3
+ import { DTOElementsGetOutput, DTOElementsGetOutputV2, DTOElementsGetQueryParsed } from "../../../dto";
3
4
  import { RequestExecutor } from "../../../transport/request-executor";
4
5
 
6
+ type GetElementsQuery = OmitStrict<DTOElementsGetQueryParsed, "responseVersion">;
7
+
5
8
  export class ElementsEndpoint {
6
9
  constructor(private readonly requestExecutor: RequestExecutor) {}
7
10
 
8
- getElements(dsId: string, vId: string, query: DTOElementsGetQueryParsed) {
11
+ getElementsV1(dsId: string, vId: string, query: GetElementsQuery) {
9
12
  return this.requestExecutor.json(`/design-systems/${dsId}/versions/${vId}/elements`, DTOElementsGetOutput, {
10
13
  query: serializeQuery(query),
11
14
  });
12
15
  }
16
+
17
+ getElementsV2(dsId: string, vId: string, query: GetElementsQuery) {
18
+ const fullQuery: DTOElementsGetQueryParsed = {
19
+ ...query,
20
+ responseVersion: 2,
21
+ };
22
+
23
+ return this.requestExecutor.json(`/design-systems/${dsId}/versions/${vId}/elements`, DTOElementsGetOutputV2, {
24
+ query: serializeQuery(fullQuery),
25
+ });
26
+ }
13
27
  }
@@ -0,0 +1,21 @@
1
+ import { DataSourceRemoteType } from "@supernova-studio/model";
2
+ import { z } from "zod";
3
+
4
+ export const DTOEventFigmaNodesRendered = z.object({
5
+ type: z.literal("DesignSystem.FigmaNodesRendered"),
6
+ designSystemId: z.string(),
7
+ versionId: z.string(),
8
+ figmaNodePersistentIds: z.string().array(),
9
+ });
10
+
11
+ export const DTOEventDataSourcesImported = z.object({
12
+ type: z.literal("DesignSystem.ImportJobFinished"),
13
+ designSystemId: z.string(),
14
+ versionId: z.string(),
15
+ importJobId: z.string(),
16
+ dataSourceType: DataSourceRemoteType,
17
+ dataSourceIds: z.string().array(),
18
+ });
19
+
20
+ export type DTOEventFigmaNodesRendered = z.infer<typeof DTOEventFigmaNodesRendered>;
21
+ export type DTOEventDataSourcesImported = z.infer<typeof DTOEventDataSourcesImported>;
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ import { DTOEventDataSourcesImported, DTOEventFigmaNodesRendered } from "./design-system";
3
+
4
+ export const DTOEvent = z.discriminatedUnion("type", [DTOEventDataSourcesImported, DTOEventFigmaNodesRendered]);
5
+
6
+ export type DTOEvent = z.infer<typeof DTOEvent>;
@@ -0,0 +1,2 @@
1
+ export * from "./design-system";
2
+ export * from "./event";
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./api";
2
+ export * from "./events";
2
3
  export * from "./utils";
3
4
  export * from "./yjs";