@supernova-studio/client 0.59.3 → 0.59.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/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/utils/figma.ts +31 -12
package/package.json
CHANGED
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
|
|