@sudobility/svgr_client 1.0.33 → 1.0.36
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/hooks/index.d.ts +5 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/query-keys.d.ts +3 -0
- package/dist/hooks/query-keys.d.ts.map +1 -1
- package/dist/hooks/query-keys.js +3 -0
- package/dist/hooks/query-keys.js.map +1 -1
- package/dist/hooks/useCreateJob.d.ts +4 -0
- package/dist/hooks/useCreateJob.d.ts.map +1 -0
- package/dist/hooks/useCreateJob.js +7 -0
- package/dist/hooks/useCreateJob.js.map +1 -0
- package/dist/hooks/useImageJobs.d.ts +3 -0
- package/dist/hooks/useImageJobs.d.ts.map +1 -0
- package/dist/hooks/useImageJobs.js +10 -0
- package/dist/hooks/useImageJobs.js.map +1 -0
- package/dist/hooks/useJobStatus.d.ts +3 -0
- package/dist/hooks/useJobStatus.d.ts.map +1 -0
- package/dist/hooks/useJobStatus.js +16 -0
- package/dist/hooks/useJobStatus.js.map +1 -0
- package/dist/hooks/useUploadImage.d.ts +7 -0
- package/dist/hooks/useUploadImage.d.ts.map +1 -0
- package/dist/hooks/useUploadImage.js +7 -0
- package/dist/hooks/useUploadImage.js.map +1 -0
- package/dist/hooks/useUserImages.d.ts +3 -0
- package/dist/hooks/useUserImages.d.ts.map +1 -0
- package/dist/hooks/useUserImages.js +10 -0
- package/dist/hooks/useUserImages.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/network/SvgrClient.d.ts +11 -1
- package/dist/network/SvgrClient.d.ts.map +1 -1
- package/dist/network/SvgrClient.js +57 -0
- package/dist/network/SvgrClient.js.map +1 -1
- package/package.json +2 -2
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export { useConvert } from "./useConvert";
|
|
2
|
+
export { useUploadImage } from "./useUploadImage";
|
|
3
|
+
export { useCreateJob } from "./useCreateJob";
|
|
4
|
+
export { useJobStatus } from "./useJobStatus";
|
|
5
|
+
export { useImageJobs } from "./useImageJobs";
|
|
6
|
+
export { useUserImages } from "./useUserImages";
|
|
2
7
|
export { svgrKeys } from "./query-keys";
|
|
3
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export { useConvert } from "./useConvert";
|
|
2
|
+
export { useUploadImage } from "./useUploadImage";
|
|
3
|
+
export { useCreateJob } from "./useCreateJob";
|
|
4
|
+
export { useJobStatus } from "./useJobStatus";
|
|
5
|
+
export { useImageJobs } from "./useImageJobs";
|
|
6
|
+
export { useUserImages } from "./useUserImages";
|
|
2
7
|
export { svgrKeys } from "./query-keys";
|
|
3
8
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { useConvert } from \"./useConvert\";\nexport { svgrKeys } from \"./query-keys\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { useConvert } from \"./useConvert\";\nexport { useUploadImage } from \"./useUploadImage\";\nexport { useCreateJob } from \"./useCreateJob\";\nexport { useJobStatus } from \"./useJobStatus\";\nexport { useImageJobs } from \"./useImageJobs\";\nexport { useUserImages } from \"./useUserImages\";\nexport { svgrKeys } from \"./query-keys\";\n"]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare const svgrKeys: {
|
|
2
2
|
all: readonly ["svgr"];
|
|
3
3
|
convert: () => readonly ["svgr", "convert"];
|
|
4
|
+
jobs: () => readonly ["svgr", "jobs"];
|
|
5
|
+
job: (jobId: string) => readonly ["svgr", "jobs", string];
|
|
6
|
+
imageJobs: (imageId: string) => readonly ["svgr", "jobs", "image", string];
|
|
4
7
|
};
|
|
5
8
|
//# sourceMappingURL=query-keys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-keys.d.ts","sourceRoot":"","sources":["../../src/hooks/query-keys.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"query-keys.d.ts","sourceRoot":"","sources":["../../src/hooks/query-keys.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,QAAQ;;;;iBAQN,MAAM;yBAEE,MAAM;CAE5B,CAAC"}
|
package/dist/hooks/query-keys.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export const svgrKeys = {
|
|
2
2
|
all: ["svgr"],
|
|
3
3
|
convert: () => [...svgrKeys.all, "convert"],
|
|
4
|
+
jobs: () => [...svgrKeys.all, "jobs"],
|
|
5
|
+
job: (jobId) => [...svgrKeys.jobs(), jobId],
|
|
6
|
+
imageJobs: (imageId) => [...svgrKeys.jobs(), "image", imageId],
|
|
4
7
|
};
|
|
5
8
|
//# sourceMappingURL=query-keys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-keys.js","sourceRoot":"","sources":["../../src/hooks/query-keys.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,MAAM,QAAQ,GAAG;IAEtB,GAAG,EAAE,CAAC,MAAM,CAAU;IAEtB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAU;
|
|
1
|
+
{"version":3,"file":"query-keys.js","sourceRoot":"","sources":["../../src/hooks/query-keys.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,MAAM,QAAQ,GAAG;IAEtB,GAAG,EAAE,CAAC,MAAM,CAAU;IAEtB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAU;IAEpD,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAU;IAE9C,GAAG,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,CAAU;IAE5D,SAAS,EAAE,CAAC,OAAe,EAAE,EAAE,CAC7B,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,CAAU;CAClD,CAAC","sourcesContent":["/**\n * Query key factory for SVGR-related TanStack Query cache keys.\n *\n * Provides a hierarchical key structure for consistent cache invalidation.\n * All keys are `as const` tuples for type-safe query key matching.\n *\n * @example\n * ```typescript\n * import { svgrKeys } from '@sudobility/svgr_client';\n * import { useQueryClient } from '@tanstack/react-query';\n *\n * const queryClient = useQueryClient();\n *\n * // Invalidate all SVGR-related queries\n * queryClient.invalidateQueries({ queryKey: svgrKeys.all });\n *\n * // Invalidate only convert-related queries\n * queryClient.invalidateQueries({ queryKey: svgrKeys.convert() });\n * ```\n */\nexport const svgrKeys = {\n /** Base key for all SVGR queries: `[\"svgr\"]` */\n all: [\"svgr\"] as const,\n /** Key for conversion queries: `[\"svgr\", \"convert\"]` */\n convert: () => [...svgrKeys.all, \"convert\"] as const,\n /** Base key for all job queries: `[\"svgr\", \"jobs\"]` */\n jobs: () => [...svgrKeys.all, \"jobs\"] as const,\n /** Key for a specific job: `[\"svgr\", \"jobs\", jobId]` */\n job: (jobId: string) => [...svgrKeys.jobs(), jobId] as const,\n /** Key for all jobs of an image: `[\"svgr\", \"jobs\", \"image\", imageId]` */\n imageJobs: (imageId: string) =>\n [...svgrKeys.jobs(), \"image\", imageId] as const,\n};\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CreateJobRequest } from "@sudobility/svgr_types";
|
|
2
|
+
import type { SvgrClient } from "../network/SvgrClient";
|
|
3
|
+
export declare function useCreateJob(client: SvgrClient): import("@tanstack/react-query").UseMutationResult<import("@sudobility/types").BaseResponse<import("@sudobility/svgr_types").JobResult>, Error, CreateJobRequest, unknown>;
|
|
4
|
+
//# sourceMappingURL=useCreateJob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateJob.d.ts","sourceRoot":"","sources":["../../src/hooks/useCreateJob.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,6KAI9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCreateJob.js","sourceRoot":"","sources":["../../src/hooks/useCreateJob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC7C,OAAO,WAAW,CAAC;QACjB,UAAU,EAAE,CAAC,OAAyB,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC;KACrE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { useMutation } from \"@tanstack/react-query\";\nimport type { CreateJobRequest } from \"@sudobility/svgr_types\";\nimport type { SvgrClient } from \"../network/SvgrClient\";\n\nexport function useCreateJob(client: SvgrClient) {\n return useMutation({\n mutationFn: (request: CreateJobRequest) => client.createJob(request),\n });\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SvgrClient } from "../network/SvgrClient";
|
|
2
|
+
export declare function useImageJobs(client: SvgrClient, imageId: string | null): import("@tanstack/react-query").UseQueryResult<import("@sudobility/types").BaseResponse<import("@sudobility/svgr_types").JobResult[]>, Error>;
|
|
3
|
+
//# sourceMappingURL=useImageJobs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useImageJobs.d.ts","sourceRoot":"","sources":["../../src/hooks/useImageJobs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,iJAMtE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { svgrKeys } from "./query-keys";
|
|
3
|
+
export function useImageJobs(client, imageId) {
|
|
4
|
+
return useQuery({
|
|
5
|
+
queryKey: svgrKeys.imageJobs(imageId ?? ""),
|
|
6
|
+
queryFn: () => client.getJobsForImage(imageId),
|
|
7
|
+
enabled: !!imageId,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=useImageJobs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useImageJobs.js","sourceRoot":"","sources":["../../src/hooks/useImageJobs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,UAAU,YAAY,CAAC,MAAkB,EAAE,OAAsB;IACrE,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC;QAC3C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,OAAQ,CAAC;QAC/C,OAAO,EAAE,CAAC,CAAC,OAAO;KACnB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { useQuery } from \"@tanstack/react-query\";\nimport type { SvgrClient } from \"../network/SvgrClient\";\nimport { svgrKeys } from \"./query-keys\";\n\nexport function useImageJobs(client: SvgrClient, imageId: string | null) {\n return useQuery({\n queryKey: svgrKeys.imageJobs(imageId ?? \"\"),\n queryFn: () => client.getJobsForImage(imageId!),\n enabled: !!imageId,\n });\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SvgrClient } from "../network/SvgrClient";
|
|
2
|
+
export declare function useJobStatus(client: SvgrClient, jobId: string | null): import("@tanstack/react-query").UseQueryResult<import("@sudobility/types").BaseResponse<import("@sudobility/svgr_types").JobResult>, Error>;
|
|
3
|
+
//# sourceMappingURL=useJobStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useJobStatus.d.ts","sourceRoot":"","sources":["../../src/hooks/useJobStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,+IAWpE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { svgrKeys } from "./query-keys";
|
|
3
|
+
export function useJobStatus(client, jobId) {
|
|
4
|
+
return useQuery({
|
|
5
|
+
queryKey: svgrKeys.job(jobId ?? ""),
|
|
6
|
+
queryFn: () => client.getJobStatus(jobId),
|
|
7
|
+
enabled: !!jobId,
|
|
8
|
+
refetchInterval: (query) => {
|
|
9
|
+
const status = query.state.data?.data?.status;
|
|
10
|
+
if (status === "done" || status === "error")
|
|
11
|
+
return false;
|
|
12
|
+
return 2500;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=useJobStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useJobStatus.js","sourceRoot":"","sources":["../../src/hooks/useJobStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,UAAU,YAAY,CAAC,MAAkB,EAAE,KAAoB;IACnE,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;QACnC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,KAAM,CAAC;QAC1C,OAAO,EAAE,CAAC,CAAC,KAAK;QAChB,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;YACzB,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;YAC9C,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,OAAO;gBAAE,OAAO,KAAK,CAAC;YAC1D,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { useQuery } from \"@tanstack/react-query\";\nimport type { SvgrClient } from \"../network/SvgrClient\";\nimport { svgrKeys } from \"./query-keys\";\n\nexport function useJobStatus(client: SvgrClient, jobId: string | null) {\n return useQuery({\n queryKey: svgrKeys.job(jobId ?? \"\"),\n queryFn: () => client.getJobStatus(jobId!),\n enabled: !!jobId,\n refetchInterval: (query) => {\n const status = query.state.data?.data?.status;\n if (status === \"done\" || status === \"error\") return false;\n return 2500;\n },\n });\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SvgrClient } from "../network/SvgrClient";
|
|
2
|
+
export declare function useUploadImage(client: SvgrClient): import("@tanstack/react-query").UseMutationResult<import("@sudobility/types").BaseResponse<import("@sudobility/svgr_types").ImageUploadResult>, Error, File | {
|
|
3
|
+
buffer: ArrayBuffer;
|
|
4
|
+
filename: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
}, unknown>;
|
|
7
|
+
//# sourceMappingURL=useUploadImage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUploadImage.d.ts","sourceRoot":"","sources":["../../src/hooks/useUploadImage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU;YAGpB,WAAW;cAAY,MAAM;cAAY,MAAM;YAG3E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUploadImage.js","sourceRoot":"","sources":["../../src/hooks/useUploadImage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,MAAM,UAAU,cAAc,CAAC,MAAkB;IAC/C,OAAO,WAAW,CAAC;QACjB,UAAU,EAAE,CACV,IAAwE,EACxE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC;KAC9B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { useMutation } from \"@tanstack/react-query\";\nimport type { SvgrClient } from \"../network/SvgrClient\";\n\nexport function useUploadImage(client: SvgrClient) {\n return useMutation({\n mutationFn: (\n file: File | { buffer: ArrayBuffer; filename: string; mimeType: string },\n ) => client.uploadImage(file),\n });\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SvgrClient } from "../network/SvgrClient";
|
|
2
|
+
export declare function useUserImages(client: SvgrClient, enabled?: boolean): import("@tanstack/react-query").UseQueryResult<import("@sudobility/types").BaseResponse<import("@sudobility/svgr_types").ImageWithJobs[]>, Error>;
|
|
3
|
+
//# sourceMappingURL=useUserImages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUserImages.d.ts","sourceRoot":"","sources":["../../src/hooks/useUserImages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,UAAO,qJAM/D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { svgrKeys } from "./query-keys";
|
|
3
|
+
export function useUserImages(client, enabled = true) {
|
|
4
|
+
return useQuery({
|
|
5
|
+
queryKey: [...svgrKeys.all, "images"],
|
|
6
|
+
queryFn: () => client.getUserImages(),
|
|
7
|
+
enabled,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=useUserImages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUserImages.js","sourceRoot":"","sources":["../../src/hooks/useUserImages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,UAAU,aAAa,CAAC,MAAkB,EAAE,OAAO,GAAG,IAAI;IAC9D,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAU;QAC9C,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE;QACrC,OAAO;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { useQuery } from \"@tanstack/react-query\";\nimport type { SvgrClient } from \"../network/SvgrClient\";\nimport { svgrKeys } from \"./query-keys\";\n\nexport function useUserImages(client: SvgrClient, enabled = true) {\n return useQuery({\n queryKey: [...svgrKeys.all, \"images\"] as const,\n queryFn: () => client.getUserImages(),\n enabled,\n });\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { SvgrClient, SvgrApiError, type SvgrClientConfig, type RetryConfig, } from "./network/SvgrClient";
|
|
2
|
-
export { useConvert, svgrKeys } from "./hooks";
|
|
2
|
+
export { useConvert, useUploadImage, useCreateJob, useJobStatus, useImageJobs, useUserImages, svgrKeys, } from "./hooks";
|
|
3
3
|
export type { ConvertMutationParams } from "./hooks/useConvert";
|
|
4
|
-
export type { ConvertRequest, ConvertResult, ConvertResponse, BaseResponse, ImageType, } from "@sudobility/svgr_types";
|
|
4
|
+
export type { ConvertRequest, ConvertResult, ConvertResponse, BaseResponse, CreateJobRequest, CreateJobResponse, ImageType, ImageUploadResult, ImageUploadResponse, ImageWithJobs, ImageListResponse, JobListResponse, JobResult, JobStatus, JobStatusResponse, } from "@sudobility/svgr_types";
|
|
5
5
|
export { IMAGE_TYPES } from "@sudobility/svgr_types";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,KAAK,gBAAgB,EACrB,KAAK,WAAW,GACjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAGhE,YAAY,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,SAAS,EACT,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { SvgrClient, SvgrApiError, } from "./network/SvgrClient";
|
|
2
|
-
export { useConvert, svgrKeys } from "./hooks";
|
|
2
|
+
export { useConvert, useUploadImage, useCreateJob, useJobStatus, useImageJobs, useUserImages, svgrKeys, } from "./hooks";
|
|
3
3
|
export { IMAGE_TYPES } from "@sudobility/svgr_types";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,UAAU,EACV,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAG9B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,UAAU,EACV,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,MAAM,SAAS,CAAC;AAqBjB,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * @module @sudobility/svgr_client\n *\n * API client SDK for SVGR with React Query hooks.\n *\n * Provides a typed HTTP client ({@link SvgrClient}) for calling the SVGR\n * image-to-SVG conversion API, along with TanStack Query hooks ({@link useConvert})\n * for seamless React integration.\n *\n * @example\n * ```typescript\n * import { SvgrClient, useConvert, svgrKeys } from '@sudobility/svgr_client';\n * ```\n */\n\n// Network\nexport {\n SvgrClient,\n SvgrApiError,\n type SvgrClientConfig,\n type RetryConfig,\n} from \"./network/SvgrClient\";\n\n// Hooks\nexport {\n useConvert,\n useUploadImage,\n useCreateJob,\n useJobStatus,\n useImageJobs,\n useUserImages,\n svgrKeys,\n} from \"./hooks\";\nexport type { ConvertMutationParams } from \"./hooks/useConvert\";\n\n// Re-export types for convenience\nexport type {\n ConvertRequest,\n ConvertResult,\n ConvertResponse,\n BaseResponse,\n CreateJobRequest,\n CreateJobResponse,\n ImageType,\n ImageUploadResult,\n ImageUploadResponse,\n ImageWithJobs,\n ImageListResponse,\n JobListResponse,\n JobResult,\n JobStatus,\n JobStatusResponse,\n} from \"@sudobility/svgr_types\";\nexport { IMAGE_TYPES } from \"@sudobility/svgr_types\";\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NetworkClient } from "@sudobility/types";
|
|
2
|
-
import type { BaseResponse, ConvertResult, ImageType } from "@sudobility/svgr_types";
|
|
2
|
+
import type { BaseResponse, ConvertResult, CreateJobRequest, ImageType, ImageUploadResult, ImageWithJobs, JobResult } from "@sudobility/svgr_types";
|
|
3
3
|
export interface SvgrClientConfig {
|
|
4
4
|
baseUrl: string;
|
|
5
5
|
networkClient: NetworkClient;
|
|
@@ -21,6 +21,16 @@ export declare class SvgrClient {
|
|
|
21
21
|
constructor(config: SvgrClientConfig);
|
|
22
22
|
convert(original: string, filename?: string, quality?: number, transparentBg?: boolean, ocr?: boolean, mergePaths?: boolean, smooth?: number, imageType?: ImageType): Promise<BaseResponse<ConvertResult>>;
|
|
23
23
|
fetchSvg(cacheId: string): Promise<string>;
|
|
24
|
+
uploadImage(file: File | {
|
|
25
|
+
buffer: ArrayBuffer;
|
|
26
|
+
filename: string;
|
|
27
|
+
mimeType: string;
|
|
28
|
+
}): Promise<BaseResponse<ImageUploadResult>>;
|
|
29
|
+
createJob(request: CreateJobRequest): Promise<BaseResponse<JobResult>>;
|
|
30
|
+
getJobStatus(jobId: string): Promise<BaseResponse<JobResult>>;
|
|
31
|
+
getJobsForImage(imageId: string): Promise<BaseResponse<JobResult[]>>;
|
|
32
|
+
fetchFile(filename: string): Promise<Blob>;
|
|
33
|
+
getUserImages(): Promise<BaseResponse<ImageWithJobs[]>>;
|
|
24
34
|
private withRetry;
|
|
25
35
|
}
|
|
26
36
|
//# sourceMappingURL=SvgrClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SvgrClient.d.ts","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACv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OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAkBtE,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IAgB7D,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;IAgBpE,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1C,aAAa,IAAI,OAAO,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC,CAAC;YAuB/C,SAAS;CAsBxB"}
|
|
@@ -40,6 +40,63 @@ export class SvgrClient {
|
|
|
40
40
|
}
|
|
41
41
|
return response.text();
|
|
42
42
|
}
|
|
43
|
+
async uploadImage(file) {
|
|
44
|
+
const formData = new FormData();
|
|
45
|
+
if (file instanceof File) {
|
|
46
|
+
formData.append("image", file);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const blob = new Blob([file.buffer], { type: file.mimeType });
|
|
50
|
+
formData.append("image", blob, file.filename);
|
|
51
|
+
}
|
|
52
|
+
const url = `${this.baseUrl}/api/v1/images/upload`;
|
|
53
|
+
const response = await this.networkClient.post(url, formData, { timeout: 60000 });
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new SvgrApiError(response.status, response.data?.error ?? "Upload failed");
|
|
56
|
+
}
|
|
57
|
+
return response.data;
|
|
58
|
+
}
|
|
59
|
+
async createJob(request) {
|
|
60
|
+
const url = `${this.baseUrl}/api/v1/jobs`;
|
|
61
|
+
const response = await this.networkClient.post(url, request);
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new SvgrApiError(response.status, response.data?.error ?? "Job creation failed");
|
|
64
|
+
}
|
|
65
|
+
return response.data;
|
|
66
|
+
}
|
|
67
|
+
async getJobStatus(jobId) {
|
|
68
|
+
const url = `${this.baseUrl}/api/v1/jobs/${jobId}`;
|
|
69
|
+
const response = await this.networkClient.get(url);
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new SvgrApiError(response.status, response.data?.error ??
|
|
72
|
+
"Failed to get job status");
|
|
73
|
+
}
|
|
74
|
+
return response.data;
|
|
75
|
+
}
|
|
76
|
+
async getJobsForImage(imageId) {
|
|
77
|
+
const url = `${this.baseUrl}/api/v1/jobs?imageId=${encodeURIComponent(imageId)}`;
|
|
78
|
+
const response = await this.networkClient.get(url);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new SvgrApiError(response.status, response.data?.error ?? "Failed to list jobs");
|
|
81
|
+
}
|
|
82
|
+
return response.data;
|
|
83
|
+
}
|
|
84
|
+
async fetchFile(filename) {
|
|
85
|
+
const url = `${this.baseUrl}/api/v1/files/${encodeURIComponent(filename)}`;
|
|
86
|
+
const response = await this.networkClient.get(url);
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new SvgrApiError(response.status, "File not found");
|
|
89
|
+
}
|
|
90
|
+
return response.data;
|
|
91
|
+
}
|
|
92
|
+
async getUserImages() {
|
|
93
|
+
const url = `${this.baseUrl}/api/v1/images`;
|
|
94
|
+
const response = await this.networkClient.get(url);
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
throw new SvgrApiError(response.status, response.data?.error ?? "Failed to list images");
|
|
97
|
+
}
|
|
98
|
+
return response.data;
|
|
99
|
+
}
|
|
43
100
|
async withRetry(fn, config) {
|
|
44
101
|
const retryableStatuses = config.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES;
|
|
45
102
|
let response = await fn();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SvgrClient.js","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"AAkEA,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AA2BlE,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAES,MAAc,EACrB,OAA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AAe;QAC5B,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,eAAe,OAAO,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,YAAY,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;QACjE,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAUO,KAAK,CAAC,SAAS,CACrB,EAAsD,EACtD,MAAmB;QAEnB,MAAM,iBAAiB,GACrB,MAAM,CAAC,iBAAiB,IAAI,0BAA0B,CAAC;QAEzD,IAAI,QAAQ,GAAG,MAAM,EAAE,EAAE,CAAC;QAE1B,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;YAC7D,IAAI,QAAQ,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBAChE,OAAO,QAAQ,CAAC;YAClB,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YACxD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;YAE3D,QAAQ,GAAG,MAAM,EAAE,EAAE,CAAC;QACxB,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["import type { NetworkClient } from \"@sudobility/types\";\nimport type {\n BaseResponse,\n ConvertResult,\n ImageType,\n} from \"@sudobility/svgr_types\";\n\n/**\n * Configuration for creating an {@link SvgrClient} instance.\n *\n * @interface SvgrClientConfig\n * @property {string} baseUrl - The base URL of the SVGR API server (e.g., `https://api.svgr.app`)\n * @property {NetworkClient} networkClient - A platform-agnostic HTTP client from `@sudobility/types`\n * that handles authentication headers and request serialization\n *\n * @example\n * ```typescript\n * const config: SvgrClientConfig = {\n * baseUrl: 'https://api.svgr.app',\n * networkClient: myNetworkClient,\n * };\n * const client = new SvgrClient(config);\n * ```\n */\nexport interface SvgrClientConfig {\n /** The base URL of the SVGR API server (e.g., `https://api.svgr.app`) */\n baseUrl: string;\n /** Platform-agnostic HTTP client that handles auth and serialization */\n networkClient: NetworkClient;\n /**\n * Optional retry configuration for failed requests.\n * When provided, the client will retry failed network requests\n * using exponential backoff.\n */\n retry?: RetryConfig;\n}\n\n/**\n * Configuration for automatic retry of failed network requests.\n *\n * @interface RetryConfig\n * @property {number} maxRetries - Maximum number of retry attempts (default: 3)\n * @property {number} baseDelayMs - Base delay in milliseconds before first retry (default: 1000).\n * Subsequent retries use exponential backoff: `baseDelayMs * 2^attempt`.\n * @property {number[]} [retryableStatuses] - HTTP status codes that should trigger a retry.\n * Defaults to [408, 429, 500, 502, 503, 504].\n *\n * @example\n * ```typescript\n * const retryConfig: RetryConfig = {\n * maxRetries: 3,\n * baseDelayMs: 1000,\n * retryableStatuses: [429, 500, 502, 503, 504],\n * };\n * ```\n */\nexport interface RetryConfig {\n /** Maximum number of retry attempts (default: 3) */\n maxRetries: number;\n /** Base delay in milliseconds before first retry (default: 1000) */\n baseDelayMs: number;\n /** HTTP status codes that should trigger a retry. Defaults to [408, 429, 500, 502, 503, 504] */\n retryableStatuses?: number[];\n}\n\n/** Default HTTP status codes considered retryable */\nconst DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];\n\n/**\n * Error thrown when the SVGR API returns a non-successful HTTP response.\n *\n * Extends the built-in `Error` class with an HTTP `status` code property,\n * allowing consumers to differentiate between different error types.\n *\n * @extends Error\n * @property {number} status - The HTTP status code from the API response\n * @property {string} message - Human-readable error description\n * @property {string} name - Always `\"SvgrApiError\"` for type identification\n *\n * @example\n * ```typescript\n * try {\n * await client.convert(imageData);\n * } catch (error) {\n * if (error instanceof SvgrApiError) {\n * console.error(`API error ${error.status}: ${error.message}`);\n * if (error.status === 429) {\n * // Handle rate limiting\n * }\n * }\n * }\n * ```\n */\nexport class SvgrApiError extends Error {\n constructor(\n /** The HTTP status code from the API response */\n public status: number,\n message: string,\n ) {\n super(message);\n this.name = \"SvgrApiError\";\n }\n}\n\n/**\n * HTTP client for the SVGR image-to-SVG conversion API.\n *\n * Provides a typed interface for calling the SVGR conversion endpoint.\n * Uses a platform-agnostic `NetworkClient` for HTTP communication,\n * making it usable in both web and React Native environments.\n *\n * @example\n * ```typescript\n * import { SvgrClient } from '@sudobility/svgr_client';\n *\n * const client = new SvgrClient({\n * baseUrl: 'https://api.svgr.app',\n * networkClient: myNetworkClient,\n * });\n *\n * const response = await client.convert(base64Image, 'logo.png', 7, true);\n * const svg = await client.fetchSvg(response.data!.cacheId);\n * ```\n *\n * @example\n * ```typescript\n * // With retry configuration\n * const client = new SvgrClient({\n * baseUrl: 'https://api.svgr.app',\n * networkClient: myNetworkClient,\n * retry: { maxRetries: 3, baseDelayMs: 1000 },\n * });\n * ```\n */\nexport class SvgrClient {\n private readonly baseUrl: string;\n private readonly networkClient: NetworkClient;\n private readonly retryConfig: RetryConfig | undefined;\n\n constructor(config: SvgrClientConfig) {\n this.baseUrl = config.baseUrl;\n this.networkClient = config.networkClient;\n this.retryConfig = config.retry;\n }\n\n /**\n * Convert a raster image to SVG format.\n *\n * Sends a POST request to `/api/v1/convert` with the image data and\n * optional conversion parameters. Returns a `BaseResponse<ConvertResult>`\n * containing a cache ID and original image dimensions on success.\n * Use {@link fetchSvg} with the cache ID to retrieve the SVG content.\n *\n * @param original - Base64-encoded raster image data (PNG, JPG, WEBP, BMP, or GIF)\n * @param filename - Optional filename for metadata or audit purposes\n * @param quality - Conversion quality level from 1 to 10 (1 = smallest, 10 = highest fidelity). Default: 5\n * @param transparentBg - If true, removes the background from the SVG. Default: false\n * @param imageType - Optional shared preprocessing profile such as `photo`, `gray_scale`, or `design`\n * @returns A promise resolving to a `BaseResponse<ConvertResult>` with the SVG output\n * @throws {SvgrApiError} When the API returns a non-successful response (includes HTTP status code)\n *\n * @example\n * ```typescript\n * const response = await client.convert(\n * 'data:image/png;base64,...',\n * 'logo.png',\n * 7,\n * true,\n * );\n * if (response.success && response.data) {\n * const svg = await client.fetchSvg(response.data.cacheId);\n * console.log(svg); // SVG string\n * console.log(response.data.width); // Original width in px\n * console.log(response.data.height); // Original height in px\n * }\n * ```\n */\n async convert(\n original: string,\n filename?: string,\n quality?: number,\n transparentBg?: boolean,\n ocr?: boolean,\n mergePaths?: boolean,\n smooth?: number,\n imageType?: ImageType,\n ): Promise<BaseResponse<ConvertResult>> {\n const makeRequest = () =>\n this.networkClient.post<BaseResponse<ConvertResult>>(\n `${this.baseUrl}/api/v1/convert`,\n {\n original,\n filename,\n quality,\n transparentBg,\n ocr,\n mergePaths,\n smooth,\n imageType,\n },\n { timeout: 120000 },\n );\n\n const response = this.retryConfig\n ? await this.withRetry(makeRequest, this.retryConfig)\n : await makeRequest();\n\n if (!response.ok || !response.data) {\n const errorData = response.data as { error?: string } | null | undefined;\n throw new SvgrApiError(\n response.status,\n errorData?.error || \"Conversion failed\",\n );\n }\n\n return response.data;\n }\n\n /**\n * Fetch a cached SVG by its cache ID.\n *\n * Sends a GET request to `/api/v1/svg/:cacheId` which returns the raw SVG\n * content with `Content-Type: image/svg+xml`. Uses native `fetch` instead\n * of the `NetworkClient` because the response is raw SVG text, not JSON.\n *\n * @param cacheId - The cache ID returned from a successful {@link convert} call\n * @returns The SVG content as a string\n * @throws {SvgrApiError} When the fetch fails or returns a non-OK status\n *\n * @example\n * ```typescript\n * const response = await client.convert(imageData, 'logo.png');\n * if (response.success && response.data) {\n * const svg = await client.fetchSvg(response.data.cacheId);\n * console.log(svg); // '<svg xmlns=\"http://www.w3.org/2000/svg\">...</svg>'\n * }\n * ```\n */\n async fetchSvg(cacheId: string): Promise<string> {\n const url = `${this.baseUrl}/api/v1/svg/${cacheId}`;\n const response = await fetch(url);\n if (!response.ok) {\n throw new SvgrApiError(response.status, \"Failed to fetch SVG\");\n }\n return response.text();\n }\n\n /**\n * Execute a request function with exponential backoff retry.\n *\n * @param fn - The async function to retry\n * @param config - Retry configuration\n * @returns The result of the successful request\n * @throws The last error encountered after all retries are exhausted\n */\n private async withRetry<T>(\n fn: () => Promise<{ ok: boolean; status: number } & T>,\n config: RetryConfig,\n ): Promise<{ ok: boolean; status: number } & T> {\n const retryableStatuses =\n config.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES;\n\n let response = await fn();\n\n for (let attempt = 0; attempt < config.maxRetries; attempt++) {\n if (response.ok || !retryableStatuses.includes(response.status)) {\n return response;\n }\n\n const delay = config.baseDelayMs * Math.pow(2, attempt);\n await new Promise((resolve) => setTimeout(resolve, delay));\n\n response = await fn();\n }\n\n return response;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SvgrClient.js","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"AAsEA,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AA2BlE,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAES,MAAc,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,WAAM,GAAN,MAAM,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAgCD,MAAM,OAAO,UAAU;IAKrB,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC;IAClC,CAAC;IAkCD,KAAK,CAAC,OA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seResponse,\n ConvertResult,\n CreateJobRequest,\n ImageType,\n ImageUploadResult,\n ImageWithJobs,\n JobResult,\n} from \"@sudobility/svgr_types\";\n\n/**\n * Configuration for creating an {@link SvgrClient} instance.\n *\n * @interface SvgrClientConfig\n * @property {string} baseUrl - The base URL of the SVGR API server (e.g., `https://api.svgr.app`)\n * @property {NetworkClient} networkClient - A platform-agnostic HTTP client from `@sudobility/types`\n * that handles authentication headers and request serialization\n *\n * @example\n * ```typescript\n * const config: SvgrClientConfig = {\n * baseUrl: 'https://api.svgr.app',\n * networkClient: myNetworkClient,\n * };\n * const client = new SvgrClient(config);\n * ```\n */\nexport interface SvgrClientConfig {\n /** The base URL of the SVGR API server (e.g., `https://api.svgr.app`) */\n baseUrl: string;\n /** Platform-agnostic HTTP client that handles auth and serialization */\n networkClient: NetworkClient;\n /**\n * Optional retry configuration for failed requests.\n * When provided, the client will retry failed network requests\n * using exponential backoff.\n */\n retry?: RetryConfig;\n}\n\n/**\n * Configuration for automatic retry of failed network requests.\n *\n * @interface RetryConfig\n * @property {number} maxRetries - Maximum number of retry attempts (default: 3)\n * @property {number} baseDelayMs - Base delay in milliseconds before first retry (default: 1000).\n * Subsequent retries use exponential backoff: `baseDelayMs * 2^attempt`.\n * @property {number[]} [retryableStatuses] - HTTP status codes that should trigger a retry.\n * Defaults to [408, 429, 500, 502, 503, 504].\n *\n * @example\n * ```typescript\n * const retryConfig: RetryConfig = {\n * maxRetries: 3,\n * baseDelayMs: 1000,\n * retryableStatuses: [429, 500, 502, 503, 504],\n * };\n * ```\n */\nexport interface RetryConfig {\n /** Maximum number of retry attempts (default: 3) */\n maxRetries: number;\n /** Base delay in milliseconds before first retry (default: 1000) */\n baseDelayMs: number;\n /** HTTP status codes that should trigger a retry. Defaults to [408, 429, 500, 502, 503, 504] */\n retryableStatuses?: number[];\n}\n\n/** Default HTTP status codes considered retryable */\nconst DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];\n\n/**\n * Error thrown when the SVGR API returns a non-successful HTTP response.\n *\n * Extends the built-in `Error` class with an HTTP `status` code property,\n * allowing consumers to differentiate between different error types.\n *\n * @extends Error\n * @property {number} status - The HTTP status code from the API response\n * @property {string} message - Human-readable error description\n * @property {string} name - Always `\"SvgrApiError\"` for type identification\n *\n * @example\n * ```typescript\n * try {\n * await client.convert(imageData);\n * } catch (error) {\n * if (error instanceof SvgrApiError) {\n * console.error(`API error ${error.status}: ${error.message}`);\n * if (error.status === 429) {\n * // Handle rate limiting\n * }\n * }\n * }\n * ```\n */\nexport class SvgrApiError extends Error {\n constructor(\n /** The HTTP status code from the API response */\n public status: number,\n message: string,\n ) {\n super(message);\n this.name = \"SvgrApiError\";\n }\n}\n\n/**\n * HTTP client for the SVGR image-to-SVG conversion API.\n *\n * Provides a typed interface for calling the SVGR conversion endpoint.\n * Uses a platform-agnostic `NetworkClient` for HTTP communication,\n * making it usable in both web and React Native environments.\n *\n * @example\n * ```typescript\n * import { SvgrClient } from '@sudobility/svgr_client';\n *\n * const client = new SvgrClient({\n * baseUrl: 'https://api.svgr.app',\n * networkClient: myNetworkClient,\n * });\n *\n * const response = await client.convert(base64Image, 'logo.png', 7, true);\n * const svg = await client.fetchSvg(response.data!.cacheId);\n * ```\n *\n * @example\n * ```typescript\n * // With retry configuration\n * const client = new SvgrClient({\n * baseUrl: 'https://api.svgr.app',\n * networkClient: myNetworkClient,\n * retry: { maxRetries: 3, baseDelayMs: 1000 },\n * });\n * ```\n */\nexport class SvgrClient {\n private readonly baseUrl: string;\n private readonly networkClient: NetworkClient;\n private readonly retryConfig: RetryConfig | undefined;\n\n constructor(config: SvgrClientConfig) {\n this.baseUrl = config.baseUrl;\n this.networkClient = config.networkClient;\n this.retryConfig = config.retry;\n }\n\n /**\n * Convert a raster image to SVG format.\n *\n * Sends a POST request to `/api/v1/convert` with the image data and\n * optional conversion parameters. Returns a `BaseResponse<ConvertResult>`\n * containing a cache ID and original image dimensions on success.\n * Use {@link fetchSvg} with the cache ID to retrieve the SVG content.\n *\n * @param original - Base64-encoded raster image data (PNG, JPG, WEBP, BMP, or GIF)\n * @param filename - Optional filename for metadata or audit purposes\n * @param quality - Conversion quality level from 1 to 10 (1 = smallest, 10 = highest fidelity). Default: 5\n * @param transparentBg - If true, removes the background from the SVG. Default: false\n * @param imageType - Optional shared preprocessing profile such as `photo`, `gray_scale`, or `design`\n * @returns A promise resolving to a `BaseResponse<ConvertResult>` with the SVG output\n * @throws {SvgrApiError} When the API returns a non-successful response (includes HTTP status code)\n *\n * @example\n * ```typescript\n * const response = await client.convert(\n * 'data:image/png;base64,...',\n * 'logo.png',\n * 7,\n * true,\n * );\n * if (response.success && response.data) {\n * const svg = await client.fetchSvg(response.data.cacheId);\n * console.log(svg); // SVG string\n * console.log(response.data.width); // Original width in px\n * console.log(response.data.height); // Original height in px\n * }\n * ```\n */\n async convert(\n original: string,\n filename?: string,\n quality?: number,\n transparentBg?: boolean,\n ocr?: boolean,\n mergePaths?: boolean,\n smooth?: number,\n imageType?: ImageType,\n ): Promise<BaseResponse<ConvertResult>> {\n const makeRequest = () =>\n this.networkClient.post<BaseResponse<ConvertResult>>(\n `${this.baseUrl}/api/v1/convert`,\n {\n original,\n filename,\n quality,\n transparentBg,\n ocr,\n mergePaths,\n smooth,\n imageType,\n },\n { timeout: 120000 },\n );\n\n const response = this.retryConfig\n ? await this.withRetry(makeRequest, this.retryConfig)\n : await makeRequest();\n\n if (!response.ok || !response.data) {\n const errorData = response.data as { error?: string } | null | undefined;\n throw new SvgrApiError(\n response.status,\n errorData?.error || \"Conversion failed\",\n );\n }\n\n return response.data;\n }\n\n /**\n * Fetch a cached SVG by its cache ID.\n *\n * Sends a GET request to `/api/v1/svg/:cacheId` which returns the raw SVG\n * content with `Content-Type: image/svg+xml`. Uses native `fetch` instead\n * of the `NetworkClient` because the response is raw SVG text, not JSON.\n *\n * @param cacheId - The cache ID returned from a successful {@link convert} call\n * @returns The SVG content as a string\n * @throws {SvgrApiError} When the fetch fails or returns a non-OK status\n *\n * @example\n * ```typescript\n * const response = await client.convert(imageData, 'logo.png');\n * if (response.success && response.data) {\n * const svg = await client.fetchSvg(response.data.cacheId);\n * console.log(svg); // '<svg xmlns=\"http://www.w3.org/2000/svg\">...</svg>'\n * }\n * ```\n */\n async fetchSvg(cacheId: string): Promise<string> {\n const url = `${this.baseUrl}/api/v1/svg/${cacheId}`;\n const response = await fetch(url);\n if (!response.ok) {\n throw new SvgrApiError(response.status, \"Failed to fetch SVG\");\n }\n return response.text();\n }\n\n /**\n * Upload an image file for persistent storage.\n * Uses networkClient.post with FormData (handles auth automatically).\n */\n async uploadImage(\n file: File | { buffer: ArrayBuffer; filename: string; mimeType: string },\n ): Promise<BaseResponse<ImageUploadResult>> {\n const formData = new FormData();\n if (file instanceof File) {\n formData.append(\"image\", file);\n } else {\n const blob = new Blob([file.buffer], { type: file.mimeType });\n formData.append(\"image\", blob, file.filename);\n }\n\n const url = `${this.baseUrl}/api/v1/images/upload`;\n const response = await this.networkClient.post<\n BaseResponse<ImageUploadResult>\n >(url, formData, { timeout: 60000 });\n\n if (!response.ok) {\n throw new SvgrApiError(\n response.status,\n (response.data as { error?: string })?.error ?? \"Upload failed\",\n );\n }\n\n return response.data as BaseResponse<ImageUploadResult>;\n }\n\n /** Create a conversion job for an uploaded image. */\n async createJob(request: CreateJobRequest): Promise<BaseResponse<JobResult>> {\n const url = `${this.baseUrl}/api/v1/jobs`;\n const response = await this.networkClient.post<BaseResponse<JobResult>>(\n url,\n request,\n );\n\n if (!response.ok) {\n throw new SvgrApiError(\n response.status,\n (response.data as { error?: string })?.error ?? \"Job creation failed\",\n );\n }\n\n return response.data as BaseResponse<JobResult>;\n }\n\n /** Get the current status of a conversion job. */\n async getJobStatus(jobId: string): Promise<BaseResponse<JobResult>> {\n const url = `${this.baseUrl}/api/v1/jobs/${jobId}`;\n const response = await this.networkClient.get<BaseResponse<JobResult>>(url);\n\n if (!response.ok) {\n throw new SvgrApiError(\n response.status,\n (response.data as { error?: string })?.error ??\n \"Failed to get job status\",\n );\n }\n\n return response.data as BaseResponse<JobResult>;\n }\n\n /** List all conversion jobs for a given image. */\n async getJobsForImage(imageId: string): Promise<BaseResponse<JobResult[]>> {\n const url = `${this.baseUrl}/api/v1/jobs?imageId=${encodeURIComponent(imageId)}`;\n const response =\n await this.networkClient.get<BaseResponse<JobResult[]>>(url);\n\n if (!response.ok) {\n throw new SvgrApiError(\n response.status,\n (response.data as { error?: string })?.error ?? \"Failed to list jobs\",\n );\n }\n\n return response.data as BaseResponse<JobResult[]>;\n }\n\n /** Fetch a file by name (SVG, JPEG preview, or uploaded image). Returns Blob. */\n async fetchFile(filename: string): Promise<Blob> {\n const url = `${this.baseUrl}/api/v1/files/${encodeURIComponent(filename)}`;\n const response = await this.networkClient.get<Blob>(url);\n\n if (!response.ok) {\n throw new SvgrApiError(response.status, \"File not found\");\n }\n\n return response.data as Blob;\n }\n\n /** List all images with their jobs for the authenticated user. */\n async getUserImages(): Promise<BaseResponse<ImageWithJobs[]>> {\n const url = `${this.baseUrl}/api/v1/images`;\n const response =\n await this.networkClient.get<BaseResponse<ImageWithJobs[]>>(url);\n\n if (!response.ok) {\n throw new SvgrApiError(\n response.status,\n (response.data as { error?: string })?.error ?? \"Failed to list images\",\n );\n }\n\n return response.data as BaseResponse<ImageWithJobs[]>;\n }\n\n /**\n * Execute a request function with exponential backoff retry.\n *\n * @param fn - The async function to retry\n * @param config - Retry configuration\n * @returns The result of the successful request\n * @throws The last error encountered after all retries are exhausted\n */\n private async withRetry<T>(\n fn: () => Promise<{ ok: boolean; status: number } & T>,\n config: RetryConfig,\n ): Promise<{ ok: boolean; status: number } & T> {\n const retryableStatuses =\n config.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES;\n\n let response = await fn();\n\n for (let attempt = 0; attempt < config.maxRetries; attempt++) {\n if (response.ok || !retryableStatuses.includes(response.status)) {\n return response;\n }\n\n const delay = config.baseDelayMs * Math.pow(2, attempt);\n await new Promise((resolve) => setTimeout(resolve, delay));\n\n response = await fn();\n }\n\n return response;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/svgr_client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"verify": "bun run typecheck && bun run lint && bun run test && bun run build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@sudobility/svgr_types": "^1.0.
|
|
32
|
+
"@sudobility/svgr_types": "^1.0.24"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@sudobility/types": "^1.9.62",
|