@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.59.3",
3
+ "version": "0.59.4",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -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
- type ParsedFigmaFileURL = {
6
- fileId: string;
7
- fileName: string | null;
8
- nodeId: string | null;
9
- nodeType: string | null;
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 | null {
14
- if (!URL.canParse(urlString)) return null;
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")) return null;
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") return null;
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)) return null;
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