@animaapp/anima-sdk 0.3.7 → 0.3.12
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.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +165 -9
- package/dist/index.js +1520 -1457
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,12 @@ export declare class Anima {
|
|
|
16
16
|
set auth(auth: Auth);
|
|
17
17
|
protected get headers(): Record<string, string>;
|
|
18
18
|
generateCode(params: GetCodeParams, handler?: GetCodeHandler): Promise<AnimaSDKResult>;
|
|
19
|
+
/**
|
|
20
|
+
* @experimental
|
|
21
|
+
* This API is experimental and may change or be removed in future releases.
|
|
22
|
+
* Link2Code (l2c) flow.
|
|
23
|
+
*/
|
|
24
|
+
generateLink2Code(params: GetLink2CodeParams, handler?: GetLink2CodeHandler): Promise<AnimaSDKResult>;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
export declare type AnimaFiles = Record<string, {
|
|
@@ -67,7 +73,7 @@ export declare class CodegenError extends Error {
|
|
|
67
73
|
/**
|
|
68
74
|
* Codegen errors from the worker
|
|
69
75
|
*/
|
|
70
|
-
export declare type CodegenErrorReason = "Selected node type is not supported" | "Invisible group nodes are unsupported" | "Selected node is a page with multiple children" | "There is no node with the given id" | "Invalid Figma token" | "Anima API connection error" | "Figma token expired" | "Invalid user token" | "Figma file not found" | "Figma rate limit exceeded" | "Unknown";
|
|
76
|
+
export declare type CodegenErrorReason = "Selected node type is not supported" | "Invisible group nodes are unsupported" | "Selected node is a page with multiple children" | "There is no node with the given id" | "Invalid Figma token" | "Anima API connection error" | "Figma token expired" | "Invalid user token" | "Figma file not found" | "Figma rate limit exceeded" | "Figma selection too large" | "Unknown";
|
|
71
77
|
|
|
72
78
|
export declare type CodegenResult = BaseResult & {
|
|
73
79
|
files: Record<string, {
|
|
@@ -93,6 +99,8 @@ export declare type CodegenSettings = {
|
|
|
93
99
|
enableAutoSplit?: boolean;
|
|
94
100
|
autoSplitThreshold?: number;
|
|
95
101
|
disableMarkedForExport?: boolean;
|
|
102
|
+
enableDisplayScreenModelId?: boolean;
|
|
103
|
+
enableGeneratePackageLock?: boolean;
|
|
96
104
|
};
|
|
97
105
|
|
|
98
106
|
/**
|
|
@@ -117,6 +125,32 @@ export declare const createCodegenResponseEventStream: (anima: Anima, params: Ge
|
|
|
117
125
|
*/
|
|
118
126
|
export declare const createCodegenStream: (anima: Anima, params: GetCodeParams) => ReadableStream<StreamCodgenMessage>;
|
|
119
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Creates a Server-Sent Events (SSE) `Response` that forwards all messages from the URL to code generation stream.
|
|
130
|
+
*
|
|
131
|
+
* But, if the first message indicates an error (e.g., connection failed), the function returns a 500 response with the error message.
|
|
132
|
+
*
|
|
133
|
+
* @param {Anima} anima - The Anima instance to use for creating the data stream.
|
|
134
|
+
* @param {GetLink2CodeParams} params - The parameters for the URL to code generation request.
|
|
135
|
+
* @returns {Promise<Response>} - A promise that resolves to an HTTP response.
|
|
136
|
+
*/
|
|
137
|
+
export declare const createLink2CodeResponseEventStream: (anima: Anima, params: GetLink2CodeParams) => Promise<Response>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @experimental
|
|
141
|
+
* This API is experimental and may change or be removed in future releases.
|
|
142
|
+
* Link2Code (l2c) stream flow.
|
|
143
|
+
*
|
|
144
|
+
* Start the URL to code generation and creates a ReadableStream to output its result.
|
|
145
|
+
*
|
|
146
|
+
* The stream is closed when the URL to code generation ends.
|
|
147
|
+
*
|
|
148
|
+
* @param {Anima} anima - An Anima service instance to generate the code from.
|
|
149
|
+
* @param {GetLink2CodeParams} params - Parameters required for the URL to code generation process.
|
|
150
|
+
* @returns {ReadableStream<StreamL2CMessage>} - A ReadableStream that emits messages related to the URL to code generation process.
|
|
151
|
+
*/
|
|
152
|
+
export declare const createLink2CodeStream: (anima: Anima, params: GetLink2CodeParams) => ReadableStream<StreamL2CMessage>;
|
|
153
|
+
|
|
120
154
|
export declare type FigmaApiError = {
|
|
121
155
|
cause: {
|
|
122
156
|
message?: string;
|
|
@@ -127,7 +161,7 @@ export declare type FigmaApiError = {
|
|
|
127
161
|
};
|
|
128
162
|
};
|
|
129
163
|
|
|
130
|
-
export declare type FigmaApiErrorType = "FigmaTokenIssue" | "RateLimitExceeded" | "NotFound" | "UnknownFigmaApiException";
|
|
164
|
+
export declare type FigmaApiErrorType = "FigmaTokenIssue" | "RateLimitExceeded" | "NotFound" | "UnknownFigmaApiException" | "RequestTooLarge";
|
|
131
165
|
|
|
132
166
|
export declare type FigmaNode = Node_2;
|
|
133
167
|
|
|
@@ -239,6 +273,32 @@ export declare type GetFileParams = {
|
|
|
239
273
|
figmaRestApi?: FigmaRestApi;
|
|
240
274
|
};
|
|
241
275
|
|
|
276
|
+
export declare type GetLink2CodeHandler = ((message: SSEL2CMessage) => void) | {
|
|
277
|
+
onQueueing?: () => void;
|
|
278
|
+
onStart?: ({ sessionId }: {
|
|
279
|
+
sessionId: string;
|
|
280
|
+
}) => void;
|
|
281
|
+
onAssetsUploaded?: () => void;
|
|
282
|
+
onAssetsList?: ({ assets, }: {
|
|
283
|
+
assets: Array<{
|
|
284
|
+
name: string;
|
|
285
|
+
url: string;
|
|
286
|
+
}>;
|
|
287
|
+
}) => void;
|
|
288
|
+
onGeneratingCode?: ({ status, progress, files, }: {
|
|
289
|
+
status: "success" | "running" | "failure";
|
|
290
|
+
progress: number;
|
|
291
|
+
files: AnimaFiles;
|
|
292
|
+
}) => void;
|
|
293
|
+
onCodegenCompleted?: () => void;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export declare type GetLink2CodeParams = {
|
|
297
|
+
params: L2CParams;
|
|
298
|
+
assetsStorage?: AssetsStorage;
|
|
299
|
+
tracking?: TrackingInfos;
|
|
300
|
+
};
|
|
301
|
+
|
|
242
302
|
export declare const getRelatedScreenFiles: ({ files, screenPath, }: {
|
|
243
303
|
files: AnimaFiles;
|
|
244
304
|
screenPath?: string;
|
|
@@ -257,10 +317,51 @@ export declare const isNotFound: (error: Error) => boolean;
|
|
|
257
317
|
|
|
258
318
|
export declare const isRateLimitExceeded: (error: Error) => boolean;
|
|
259
319
|
|
|
320
|
+
export declare const isRequestTooLarge: (error: Error) => boolean;
|
|
321
|
+
|
|
260
322
|
export declare const isUnknownFigmaApiException: (error: Error) => boolean;
|
|
261
323
|
|
|
262
324
|
export declare const isValidFigmaUrl: (figmaLink: string) => [hasCorrectPrefix: boolean, fileKey: string, nodeId: string];
|
|
263
325
|
|
|
326
|
+
export declare type L2CParams = {
|
|
327
|
+
input: L2CParamsInput;
|
|
328
|
+
conventions: L2CParamsConvention;
|
|
329
|
+
assetsStorage: L2CParamsAssetsStorage;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export declare type L2CParamsAssetsStorage = L2CParamsBundledAssetsStorage;
|
|
333
|
+
|
|
334
|
+
export declare type L2CParamsBundledAssetsStorage = {
|
|
335
|
+
type: 'bundled';
|
|
336
|
+
referencePath?: string;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
export declare type L2CParamsConvention = L2CParamsHtmlConvention | L2CParamsReactConvention;
|
|
340
|
+
|
|
341
|
+
export declare type L2CParamsFramework = 'html' | 'react';
|
|
342
|
+
|
|
343
|
+
export declare type L2CParamsHtmlConvention = {
|
|
344
|
+
framework: 'html';
|
|
345
|
+
styling: L2CParamsStyling;
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export declare type L2CParamsInput = L2CParamsUrlInput;
|
|
349
|
+
|
|
350
|
+
export declare type L2CParamsLanguage = 'typescript';
|
|
351
|
+
|
|
352
|
+
export declare type L2CParamsReactConvention = {
|
|
353
|
+
framework: 'react';
|
|
354
|
+
language: L2CParamsLanguage;
|
|
355
|
+
styling: L2CParamsStyling;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
export declare type L2CParamsStyling = 'tailwind' | 'inline-styles';
|
|
359
|
+
|
|
360
|
+
export declare type L2CParamsUrlInput = {
|
|
361
|
+
type: 'url';
|
|
362
|
+
url: string;
|
|
363
|
+
};
|
|
364
|
+
|
|
264
365
|
export declare class NotFound extends Error {
|
|
265
366
|
fileKey: string;
|
|
266
367
|
constructor({ fileKey, cause }: {
|
|
@@ -277,6 +378,14 @@ export declare class RateLimitExceeded extends Error {
|
|
|
277
378
|
});
|
|
278
379
|
}
|
|
279
380
|
|
|
381
|
+
export declare class RequestTooLarge extends Error {
|
|
382
|
+
fileKey: string;
|
|
383
|
+
constructor({ fileKey, cause }: {
|
|
384
|
+
fileKey: string;
|
|
385
|
+
cause?: unknown;
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
280
389
|
export declare class ResponseError extends Error {
|
|
281
390
|
response: Response;
|
|
282
391
|
constructor(message: string, res: Response);
|
|
@@ -287,6 +396,13 @@ export declare class ResponseError extends Error {
|
|
|
287
396
|
*/
|
|
288
397
|
export declare type SDKErrorReason = "Invalid body payload" | "No code generated" | "Connection closed before the 'done' message" | "Response body is null";
|
|
289
398
|
|
|
399
|
+
export declare type SSECodegenMessageErrorPayload = {
|
|
400
|
+
errorName: string;
|
|
401
|
+
task?: string;
|
|
402
|
+
reason: CodegenErrorReason;
|
|
403
|
+
sentryTraceId?: string;
|
|
404
|
+
};
|
|
405
|
+
|
|
290
406
|
export declare type SSECodgenMessage = {
|
|
291
407
|
type: "queueing";
|
|
292
408
|
} | {
|
|
@@ -333,16 +449,56 @@ export declare type SSECodgenMessageErrorPayload = {
|
|
|
333
449
|
reason: CodegenErrorReason;
|
|
334
450
|
};
|
|
335
451
|
|
|
336
|
-
export declare type
|
|
452
|
+
export declare type SSEL2CMessage = {
|
|
453
|
+
type: 'queueing';
|
|
454
|
+
} | {
|
|
455
|
+
type: 'start';
|
|
456
|
+
sessionId: string;
|
|
457
|
+
} | {
|
|
458
|
+
type: 'generating_code';
|
|
459
|
+
payload: GeneratingCodePayload;
|
|
460
|
+
} | {
|
|
461
|
+
type: 'generation_completed';
|
|
462
|
+
} | {
|
|
463
|
+
type: 'assets_uploaded';
|
|
464
|
+
} | {
|
|
465
|
+
type: 'assets_list';
|
|
466
|
+
payload: {
|
|
467
|
+
assets: Array<{
|
|
468
|
+
name: string;
|
|
469
|
+
url: string;
|
|
470
|
+
}>;
|
|
471
|
+
};
|
|
472
|
+
} | {
|
|
473
|
+
type: 'aborted';
|
|
474
|
+
} | {
|
|
475
|
+
type: 'error';
|
|
476
|
+
payload: SSECodegenMessageErrorPayload;
|
|
477
|
+
} | {
|
|
478
|
+
type: 'done';
|
|
479
|
+
payload: {
|
|
480
|
+
sessionId: string;
|
|
481
|
+
tokenUsage: number;
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
export declare type StreamCodgenMessage = StreamMessage<SSECodgenMessage>;
|
|
486
|
+
|
|
487
|
+
declare type StreamErrorPayload = {
|
|
488
|
+
name: string;
|
|
489
|
+
message: CodegenErrorReason;
|
|
490
|
+
status?: number;
|
|
491
|
+
detail?: unknown;
|
|
492
|
+
errorPayload?: SSECodegenMessageErrorPayload;
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
export declare type StreamL2CMessage = StreamMessage<SSEL2CMessage>;
|
|
496
|
+
|
|
497
|
+
export declare type StreamMessage<T> = Exclude<T, {
|
|
337
498
|
type: "error";
|
|
338
499
|
}> | {
|
|
339
500
|
type: "error";
|
|
340
|
-
payload:
|
|
341
|
-
name: string;
|
|
342
|
-
message: CodegenErrorReason;
|
|
343
|
-
status?: number;
|
|
344
|
-
detail?: unknown;
|
|
345
|
-
};
|
|
501
|
+
payload: StreamErrorPayload;
|
|
346
502
|
};
|
|
347
503
|
|
|
348
504
|
export declare type TrackingInfos = {
|