@animaapp/anima-sdk-react 0.1.3 → 0.2.0
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 +14 -6
- package/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.js +593 -577
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/useAnimaCodegen.ts +36 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animaapp/anima-sdk-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Anima's JavaScript utilities library",
|
|
6
6
|
"author": "Anima App, Inc.",
|
|
@@ -40,4 +40,4 @@
|
|
|
40
40
|
"vite-tsconfig-paths": "^5.1.4",
|
|
41
41
|
"vitest": "^3.0.5"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
package/src/useAnimaCodegen.ts
CHANGED
|
@@ -8,10 +8,12 @@ import { convertCodegenFilesToAnimaFiles } from "@animaapp/anima-sdk";
|
|
|
8
8
|
import { EventSource } from "eventsource";
|
|
9
9
|
import { useImmer } from "use-immer";
|
|
10
10
|
|
|
11
|
+
type LocalAssetsStorage =
|
|
12
|
+
| { strategy: "local"; path: string }
|
|
13
|
+
| { strategy: "local"; filePath: string; referencePath: string };
|
|
14
|
+
|
|
11
15
|
export type UseAnimaParams = Omit<GetCodeParams, "assetsStorage"> & {
|
|
12
|
-
assetsStorage?:
|
|
13
|
-
| GetCodeParams["assetsStorage"]
|
|
14
|
-
| { strategy: "local"; path: string };
|
|
16
|
+
assetsStorage?: GetCodeParams["assetsStorage"] | LocalAssetsStorage;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
type Status = "idle" | "pending" | "success" | "aborted" | "error";
|
|
@@ -45,6 +47,26 @@ type StreamMessageByType<T extends StreamCodgenMessage["type"]> = Extract<
|
|
|
45
47
|
{ type: T }
|
|
46
48
|
>;
|
|
47
49
|
|
|
50
|
+
const getAssetsLocalStrategyParams = (
|
|
51
|
+
localAssetsStorage: LocalAssetsStorage
|
|
52
|
+
) => {
|
|
53
|
+
if ("path" in localAssetsStorage) {
|
|
54
|
+
return {
|
|
55
|
+
filePath: localAssetsStorage.path.replace(/^\//, ""),
|
|
56
|
+
referencePath:
|
|
57
|
+
localAssetsStorage.path === "/" ? "" : localAssetsStorage.path, // Workaround to avoid duplicated slashes in the URL. Ideally, the fix should be done in Codegen.
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
filePath: localAssetsStorage.filePath.replace(/^\//, ""),
|
|
63
|
+
referencePath:
|
|
64
|
+
localAssetsStorage.referencePath === "/"
|
|
65
|
+
? ""
|
|
66
|
+
: localAssetsStorage.referencePath,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
48
70
|
export const useAnimaCodegen = ({
|
|
49
71
|
url,
|
|
50
72
|
method = "POST",
|
|
@@ -67,9 +89,13 @@ export const useAnimaCodegen = ({
|
|
|
67
89
|
const initialParams = structuredClone(params);
|
|
68
90
|
|
|
69
91
|
if (params.assetsStorage?.strategy === "local") {
|
|
92
|
+
const { referencePath } = getAssetsLocalStrategyParams(
|
|
93
|
+
params.assetsStorage
|
|
94
|
+
);
|
|
95
|
+
|
|
70
96
|
params.assetsStorage = {
|
|
71
97
|
strategy: "external",
|
|
72
|
-
url:
|
|
98
|
+
url: referencePath,
|
|
73
99
|
};
|
|
74
100
|
}
|
|
75
101
|
|
|
@@ -220,6 +246,10 @@ export const useAnimaCodegen = ({
|
|
|
220
246
|
initialParams.assetsStorage?.strategy === "local" &&
|
|
221
247
|
result?.assets?.length
|
|
222
248
|
) {
|
|
249
|
+
const { filePath } = getAssetsLocalStrategyParams(
|
|
250
|
+
initialParams.assetsStorage
|
|
251
|
+
);
|
|
252
|
+
|
|
223
253
|
const downloadAssetsPromises = result.assets.map(async (asset) => {
|
|
224
254
|
const response = await fetch(asset.url);
|
|
225
255
|
const buffer = await response.arrayBuffer();
|
|
@@ -237,7 +267,8 @@ export const useAnimaCodegen = ({
|
|
|
237
267
|
|
|
238
268
|
assetsList[assetName] = base64;
|
|
239
269
|
|
|
240
|
-
|
|
270
|
+
const assetPath = filePath ? `${filePath}/${assetName}` : assetName;
|
|
271
|
+
result.files[assetPath] = {
|
|
241
272
|
content: base64,
|
|
242
273
|
isBinary: true,
|
|
243
274
|
};
|