@supernova-studio/client 0.59.3 → 0.59.5
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/dist/index.d.mts +83 -77
- package/dist/index.d.ts +83 -77
- package/dist/index.js +33 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/dto/elements/figma-nodes/figma-node.ts +17 -2
- package/src/api/dto/elements/figma-nodes/node-actions-v2.ts +2 -2
- package/src/api/endpoints/design-system/versions/elements-action.ts +2 -1
- package/src/utils/figma.ts +31 -12
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ const DTOFigmaNodeRenderInputBase = z.object({
|
|
|
43
43
|
* Figma node render request that uses source ID + node ID to identify the requested
|
|
44
44
|
* node to render. The node ID can be obtained from the source's Figma node structure.
|
|
45
45
|
*/
|
|
46
|
-
const DTOFigmaNodeRenderIdInput = DTOFigmaNodeRenderInputBase.extend({
|
|
46
|
+
export const DTOFigmaNodeRenderIdInput = DTOFigmaNodeRenderInputBase.extend({
|
|
47
47
|
inputType: z
|
|
48
48
|
.literal("NodeId")
|
|
49
49
|
.optional()
|
|
@@ -64,7 +64,7 @@ const DTOFigmaNodeRenderIdInput = DTOFigmaNodeRenderInputBase.extend({
|
|
|
64
64
|
* Figma node render request that uses Figma URL to identify the requested
|
|
65
65
|
* node to render. The URL can be obtained by the user directly from the Figma app.
|
|
66
66
|
*/
|
|
67
|
-
const DTOFigmaNodeRenderUrlInput = DTOFigmaNodeRenderInputBase.extend({
|
|
67
|
+
export const DTOFigmaNodeRenderUrlInput = DTOFigmaNodeRenderInputBase.extend({
|
|
68
68
|
inputType: z.literal("URL"),
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -78,11 +78,26 @@ const DTOFigmaNodeRenderUrlInput = DTOFigmaNodeRenderInputBase.extend({
|
|
|
78
78
|
brandPersistentId: z.string(),
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Figma node render request that uses Figma URL to identify the requested
|
|
83
|
+
* node to render. The URL can be obtained by the user directly from the Figma app.
|
|
84
|
+
*/
|
|
85
|
+
export const DTOFigmaNodeRerenderInput = z.object({
|
|
86
|
+
inputType: z.literal("Rerender"),
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Persistent ID of an existing Figma node
|
|
90
|
+
*/
|
|
91
|
+
figmaNodePersistentId: z.string(),
|
|
92
|
+
});
|
|
93
|
+
|
|
81
94
|
export const DTOFigmaNodeRenderInput = z.discriminatedUnion("inputType", [
|
|
82
95
|
DTOFigmaNodeRenderIdInput,
|
|
83
96
|
DTOFigmaNodeRenderUrlInput,
|
|
97
|
+
DTOFigmaNodeRerenderInput,
|
|
84
98
|
]);
|
|
85
99
|
|
|
86
100
|
export type DTOFigmaNodeRenderIdInput = z.infer<typeof DTOFigmaNodeRenderIdInput>;
|
|
87
101
|
export type DTOFigmaNodeRenderUrlInput = z.infer<typeof DTOFigmaNodeRenderUrlInput>;
|
|
102
|
+
export type DTOFigmaNodeRerenderInput = z.infer<typeof DTOFigmaNodeRerenderInput>;
|
|
88
103
|
export type DTOFigmaNodeRenderInput = z.infer<typeof DTOFigmaNodeRenderInput>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { DTOFigmaNodeRenderInput } from "./figma-node";
|
|
2
|
+
import { DTOFigmaNodeRenderIdInput, DTOFigmaNodeRenderInput } from "./figma-node";
|
|
3
3
|
import { DTOFigmaNode } from "./figma-node-v1";
|
|
4
4
|
import { DTOFigmaNodeV2 } from "./figma-node-v2";
|
|
5
5
|
|
|
@@ -32,7 +32,7 @@ export type DTOFigmaNodeRenderAsyncActionOutput = z.infer<typeof DTOFigmaNodeRen
|
|
|
32
32
|
*/
|
|
33
33
|
export const DTOFigmaNodeRenderActionInput = z.object({
|
|
34
34
|
type: z.literal("FigmaNodeRender"),
|
|
35
|
-
input:
|
|
35
|
+
input: DTOFigmaNodeRenderIdInput.array(),
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
export const DTOFigmaNodeRenderAsyncActionInput = z.object({
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
DTOCreateDocumentationTabInput,
|
|
5
5
|
DTOElementActionInput,
|
|
6
6
|
DTOElementActionOutput,
|
|
7
|
+
DTOFigmaNodeRenderIdInput,
|
|
7
8
|
DTOFigmaNodeRenderInput,
|
|
8
9
|
DTOMoveDocumentationGroupInput,
|
|
9
10
|
DTOUpdateDocumentationGroupInput,
|
|
@@ -38,7 +39,7 @@ export class ElementsActionEndpoint {
|
|
|
38
39
|
return this.action(dsId, vId, { type: "DocumentationTabCreate", input });
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
async renderNodes(dsId: string, vId: string, input:
|
|
42
|
+
async renderNodes(dsId: string, vId: string, input: DTOFigmaNodeRenderIdInput[]) {
|
|
42
43
|
return this.action(dsId, vId, { type: "FigmaNodeRender", input });
|
|
43
44
|
}
|
|
44
45
|
|
package/src/utils/figma.ts
CHANGED
|
@@ -2,28 +2,47 @@ const figmaFileIdRegex = /^[0-9a-zA-Z]{22,128}$/;
|
|
|
2
2
|
const nodeIdRegex = /^\d+-\d+$/;
|
|
3
3
|
const nodeTypeRegex = /^[0-9a-zA-Z]^/;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
export enum ParsedFigmaFileURLError {
|
|
6
|
+
InvalidUrl = "InvalidUrl",
|
|
7
|
+
InvalidFigmaFileId = "InvalidFigmaFileId",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type ParsedFigmaFileURL =
|
|
11
|
+
| {
|
|
12
|
+
status: "Success";
|
|
13
|
+
fileId: string;
|
|
14
|
+
fileName: string | null;
|
|
15
|
+
nodeId: string | null;
|
|
16
|
+
nodeType: string | null;
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
status: "Error";
|
|
20
|
+
error: ParsedFigmaFileURLError;
|
|
21
|
+
};
|
|
11
22
|
|
|
12
23
|
export const FigmaUtils = {
|
|
13
|
-
tryParseFigmaFileURL(urlString: string): ParsedFigmaFileURL
|
|
14
|
-
if (!URL.canParse(urlString))
|
|
24
|
+
tryParseFigmaFileURL(urlString: string): ParsedFigmaFileURL {
|
|
25
|
+
if (!URL.canParse(urlString)) {
|
|
26
|
+
return { status: "Error", error: ParsedFigmaFileURLError.InvalidUrl };
|
|
27
|
+
}
|
|
15
28
|
|
|
16
29
|
// Validate that this is a Figma URL
|
|
17
30
|
const url = new URL(urlString);
|
|
18
|
-
if (!url.hostname.endsWith("figma.com"))
|
|
31
|
+
if (!url.hostname.endsWith("figma.com")) {
|
|
32
|
+
return { status: "Error", error: ParsedFigmaFileURLError.InvalidUrl };
|
|
33
|
+
}
|
|
19
34
|
|
|
20
35
|
// Validate that the URL type is the correct one (pointing to a design file)
|
|
21
36
|
const pathSegments = url.pathname.split("/");
|
|
22
|
-
if (pathSegments[1] !== "design" && pathSegments[1] !== "file")
|
|
37
|
+
if (pathSegments[1] !== "design" && pathSegments[1] !== "file") {
|
|
38
|
+
return { status: "Error", error: ParsedFigmaFileURLError.InvalidUrl };
|
|
39
|
+
}
|
|
23
40
|
|
|
24
41
|
// Validate Figma file ID
|
|
25
42
|
const fileId = pathSegments[2];
|
|
26
|
-
if (!fileId || !fileId.match(figmaFileIdRegex))
|
|
43
|
+
if (!fileId || !fileId.match(figmaFileIdRegex)) {
|
|
44
|
+
return { status: "Error", error: ParsedFigmaFileURLError.InvalidFigmaFileId };
|
|
45
|
+
}
|
|
27
46
|
|
|
28
47
|
// Parse Figma file name
|
|
29
48
|
let fileName: string | null = null;
|
|
@@ -46,7 +65,7 @@ export const FigmaUtils = {
|
|
|
46
65
|
nodeType = nodeTypeRaw;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
return { fileId, fileName, nodeId, nodeType };
|
|
68
|
+
return { status: "Success", fileId, fileName, nodeId, nodeType };
|
|
50
69
|
},
|
|
51
70
|
};
|
|
52
71
|
|