@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animaapp/anima-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Anima's JavaScript utilities library",
6
6
  "author": "Anima App, Inc.",
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
@@ -37,7 +37,7 @@ export const createCodegenStream = (
37
37
  controller.close();
38
38
  }
39
39
  })
40
- .then((result) => {
40
+ .then((_result) => {
41
41
  controller.enqueue({ type: "done" });
42
42
  controller.close();
43
43
  })
@@ -71,13 +71,18 @@ export const isFigmaTokenIssue = (error: Error) => {
71
71
  );
72
72
  };
73
73
 
74
- export const handleFigmaApiError = (error: any, fileKey: string) => {
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
 
@@ -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, any>;
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, any>;
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
@@ -5,4 +5,3 @@ export * from "./utils";
5
5
  export * from "./figma";
6
6
  export * from "./settings";
7
7
  export * from "./dataStream";
8
- export * from "./codegenToAnimaFiles";
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: string;
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: any }
84
+ | { type: "generating_code"; payload: GeneratingCodePayload }
79
85
  | { type: "codegen_completed" }
80
86
  | { type: "assets_uploaded" }
81
87
  | {
package/src/utils.ts CHANGED
@@ -43,7 +43,7 @@ export const formatToFigmaLink = ({
43
43
  return url;
44
44
  };
45
45
 
46
- class ResponseError extends Error {
46
+ export class ResponseError extends Error {
47
47
  response: Response;
48
48
 
49
49
  constructor(message: string, res: Response) {
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "../tsconfig.json",
4
+ "exclude": ["../sdk-react"]
5
+ }
@@ -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
- };