@animaapp/anima-sdk 0.1.3 → 0.2.1
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/.turbo/turbo-build.log +5 -5
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -10
- package/dist/index.js +451 -450
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/anima.ts +2 -10
- package/src/dataStream.ts +1 -1
- package/src/figma/figmaError.ts +7 -2
- package/src/figma/utils.ts +4 -4
- package/src/index.ts +0 -1
- package/src/types.ts +8 -2
- package/src/utils.ts +1 -1
- package/tsconfig.json +5 -0
- package/src/codegenToAnimaFiles.ts +0 -13
package/package.json
CHANGED
package/src/anima.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { convertCodegenFilesToAnimaFiles } from "./codegenToAnimaFiles";
|
|
2
1
|
import { CodegenError } from "./errors";
|
|
3
2
|
import { validateSettings } from "./settings";
|
|
4
3
|
import {
|
|
@@ -188,15 +187,8 @@ export class Anima {
|
|
|
188
187
|
}
|
|
189
188
|
|
|
190
189
|
case "generating_code": {
|
|
191
|
-
const codegenFiles = data.payload.files as Record<
|
|
192
|
-
string,
|
|
193
|
-
{ code: string; type: "code" }
|
|
194
|
-
>;
|
|
195
|
-
|
|
196
|
-
const files = convertCodegenFilesToAnimaFiles(codegenFiles);
|
|
197
|
-
|
|
198
190
|
if (data.payload.status === "success") {
|
|
199
|
-
result.files = files;
|
|
191
|
+
result.files = data.payload.files;
|
|
200
192
|
}
|
|
201
193
|
|
|
202
194
|
typeof handler === "function"
|
|
@@ -204,7 +196,7 @@ export class Anima {
|
|
|
204
196
|
: handler.onGeneratingCode?.({
|
|
205
197
|
status: data.payload.status,
|
|
206
198
|
progress: data.payload.progress,
|
|
207
|
-
files,
|
|
199
|
+
files: data.payload.files,
|
|
208
200
|
});
|
|
209
201
|
break;
|
|
210
202
|
}
|
package/src/dataStream.ts
CHANGED
package/src/figma/figmaError.ts
CHANGED
|
@@ -71,13 +71,18 @@ export const isFigmaTokenIssue = (error: Error) => {
|
|
|
71
71
|
);
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
export
|
|
74
|
+
export type FigmaApiError = {
|
|
75
|
+
cause?: { body?: { status?: number; reason?: string } };
|
|
76
|
+
body?: { status?: number; reason?: string };
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const handleFigmaApiError = (error: FigmaApiError, fileKey: string) => {
|
|
75
80
|
const err = error?.cause?.body || error.body;
|
|
76
81
|
|
|
77
82
|
if (err?.status === 403) {
|
|
78
83
|
throw new FigmaTokenIssue({
|
|
79
84
|
fileKey,
|
|
80
|
-
reason: error?.cause?.body || error.body,
|
|
85
|
+
reason: (error?.cause?.body?.reason || error.body?.reason || "Access denied").toString(),
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
88
|
|
package/src/figma/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GetFileResponse, Node } from '@figma/rest-api-spec';
|
|
2
2
|
import { FigmaRestApi } from '@animaapp/http-client-figma';
|
|
3
|
-
import { handleFigmaApiError } from './figmaError';
|
|
3
|
+
import { handleFigmaApiError, type FigmaApiError } from './figmaError';
|
|
4
4
|
|
|
5
5
|
export type FigmaNode = Node;
|
|
6
6
|
export type GetFileParams = { fileKey: string; authToken?: string; figmaRestApi?: FigmaRestApi };
|
|
@@ -10,7 +10,7 @@ export type GetFilePagesParams = {
|
|
|
10
10
|
fileKey: string;
|
|
11
11
|
authToken?: string;
|
|
12
12
|
figmaRestApi?: FigmaRestApi;
|
|
13
|
-
params?: Record<string,
|
|
13
|
+
params?: Record<string, string | number | undefined>;
|
|
14
14
|
};
|
|
15
15
|
export type GetFilePagesResult = FigmaPage[] | undefined;
|
|
16
16
|
export type GetFileNodesParams = {
|
|
@@ -18,7 +18,7 @@ export type GetFileNodesParams = {
|
|
|
18
18
|
authToken?: string;
|
|
19
19
|
nodeIds: string[];
|
|
20
20
|
figmaRestApi?: FigmaRestApi;
|
|
21
|
-
params?: Record<string,
|
|
21
|
+
params?: Record<string, string | number>;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export type GetFigmaFileResult = GetFileResponse | undefined;
|
|
@@ -68,6 +68,6 @@ export const getFileNodes = async ({
|
|
|
68
68
|
|
|
69
69
|
return data.nodes;
|
|
70
70
|
} catch (error) {
|
|
71
|
-
return handleFigmaApiError(error, fileKey);
|
|
71
|
+
return handleFigmaApiError(error as FigmaApiError, fileKey);
|
|
72
72
|
}
|
|
73
73
|
};
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -30,7 +30,7 @@ export type AssetsStorage =
|
|
|
30
30
|
|
|
31
31
|
export type GetCodeParams = {
|
|
32
32
|
fileKey: string;
|
|
33
|
-
figmaToken
|
|
33
|
+
figmaToken?: string;
|
|
34
34
|
nodesId: string[];
|
|
35
35
|
assetsStorage?: AssetsStorage;
|
|
36
36
|
settings: CodegenSettings;
|
|
@@ -66,6 +66,12 @@ export type GetCodeHandler =
|
|
|
66
66
|
onCodegenCompleted?: () => void;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
export type GeneratingCodePayload = {
|
|
70
|
+
status: "success" | "running" | "failure";
|
|
71
|
+
progress: number;
|
|
72
|
+
files: AnimaFiles;
|
|
73
|
+
};
|
|
74
|
+
|
|
69
75
|
// TODO: `SSECodgenMessage` and `SSECodgenMessageErrorPayload` should be imported from `anima-public-api`
|
|
70
76
|
export type SSECodgenMessage =
|
|
71
77
|
| { type: "start"; sessionId: string }
|
|
@@ -75,7 +81,7 @@ export type SSECodgenMessage =
|
|
|
75
81
|
figmaFileName: string;
|
|
76
82
|
figmaSelectedFrameName: string;
|
|
77
83
|
}
|
|
78
|
-
| { type: "generating_code"; payload:
|
|
84
|
+
| { type: "generating_code"; payload: GeneratingCodePayload }
|
|
79
85
|
| { type: "codegen_completed" }
|
|
80
86
|
| { type: "assets_uploaded" }
|
|
81
87
|
| {
|
package/src/utils.ts
CHANGED
package/tsconfig.json
ADDED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AnimaFiles } from "./types";
|
|
2
|
-
|
|
3
|
-
export const convertCodegenFilesToAnimaFiles = (
|
|
4
|
-
codegenFiles: Record<string, { code: string; type: "code" }>
|
|
5
|
-
): AnimaFiles => {
|
|
6
|
-
return Object.entries(codegenFiles).reduce(
|
|
7
|
-
(acc, [fileName, file]) => {
|
|
8
|
-
acc[fileName] = { content: file.code, isBinary: false };
|
|
9
|
-
return acc;
|
|
10
|
-
},
|
|
11
|
-
{} as AnimaFiles
|
|
12
|
-
);
|
|
13
|
-
};
|