@sudobility/svgr_client 1.0.10 → 1.0.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.
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import type { NetworkClient } from "@sudobility/types";
|
|
1
2
|
import type { BaseResponse, ConvertResult } from "@sudobility/svgr_types";
|
|
2
3
|
export interface SvgrClientConfig {
|
|
3
4
|
baseUrl: string;
|
|
4
|
-
|
|
5
|
+
networkClient: NetworkClient;
|
|
5
6
|
}
|
|
6
7
|
export declare class SvgrApiError extends Error {
|
|
7
8
|
status: number;
|
|
8
9
|
constructor(status: number, message: string);
|
|
9
10
|
}
|
|
10
11
|
export declare class SvgrClient {
|
|
11
|
-
private baseUrl;
|
|
12
|
-
private
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly networkClient;
|
|
13
14
|
constructor(config: SvgrClientConfig);
|
|
14
15
|
convert(original: string, filename?: string, quality?: number, transparentBg?: boolean): Promise<BaseResponse<ConvertResult>>;
|
|
15
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SvgrClient.d.ts","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,
|
|
1
|
+
{"version":3,"file":"SvgrClient.d.ts","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED,qBAAa,YAAa,SAAQ,KAAK;IAE5B,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKlB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gBAElC,MAAM,EAAE,gBAAgB;IAK9B,OAAO,CACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;CAqBxC"}
|
|
@@ -8,30 +8,20 @@ export class SvgrApiError extends Error {
|
|
|
8
8
|
export class SvgrClient {
|
|
9
9
|
constructor(config) {
|
|
10
10
|
this.baseUrl = config.baseUrl;
|
|
11
|
-
this.
|
|
11
|
+
this.networkClient = config.networkClient;
|
|
12
12
|
}
|
|
13
13
|
async convert(original, filename, quality, transparentBg) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (token) {
|
|
20
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const response = await fetch(`${this.baseUrl}/api/v1/convert`, {
|
|
24
|
-
method: "POST",
|
|
25
|
-
headers,
|
|
26
|
-
body: JSON.stringify({ original, filename, quality, transparentBg }),
|
|
14
|
+
const response = await this.networkClient.post(`${this.baseUrl}/api/v1/convert`, {
|
|
15
|
+
original,
|
|
16
|
+
filename,
|
|
17
|
+
quality,
|
|
18
|
+
transparentBg,
|
|
27
19
|
});
|
|
28
|
-
if (!response.ok) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
.catch(() => ({ error: "Unknown error" }));
|
|
32
|
-
throw new SvgrApiError(response.status, error.error || "Conversion failed");
|
|
20
|
+
if (!response.ok || !response.data) {
|
|
21
|
+
const errorData = response.data;
|
|
22
|
+
throw new SvgrApiError(response.status, errorData?.error || "Conversion failed");
|
|
33
23
|
}
|
|
34
|
-
return response.
|
|
24
|
+
return response.data;
|
|
35
25
|
}
|
|
36
26
|
}
|
|
37
27
|
//# sourceMappingURL=SvgrClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SvgrClient.js","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SvgrClient.js","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YACS,MAAc,EACrB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,WAAM,GAAN,MAAM,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,UAAU;IAIrB,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,OAAO,CACX,QAAgB,EAChB,QAAiB,EACjB,OAAgB,EAChB,aAAuB;QAEvB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,IAAI,CAC5C,GAAG,IAAI,CAAC,OAAO,iBAAiB,EAChC;YACE,QAAQ;YACR,QAAQ;YACR,OAAO;YACP,aAAa;SACd,CACF,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,MAAM,SAAS,GAAG,QAAQ,CAAC,IAA6C,CAAC;YACzE,MAAM,IAAI,YAAY,CACpB,QAAQ,CAAC,MAAM,EACf,SAAS,EAAE,KAAK,IAAI,mBAAmB,CACxC,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF","sourcesContent":["import type { NetworkClient } from \"@sudobility/types\";\nimport type { BaseResponse, ConvertResult } from \"@sudobility/svgr_types\";\n\nexport interface SvgrClientConfig {\n baseUrl: string;\n networkClient: NetworkClient;\n}\n\nexport class SvgrApiError extends Error {\n constructor(\n public status: number,\n message: string,\n ) {\n super(message);\n this.name = \"SvgrApiError\";\n }\n}\n\nexport class SvgrClient {\n private readonly baseUrl: string;\n private readonly networkClient: NetworkClient;\n\n constructor(config: SvgrClientConfig) {\n this.baseUrl = config.baseUrl;\n this.networkClient = config.networkClient;\n }\n\n async convert(\n original: string,\n filename?: string,\n quality?: number,\n transparentBg?: boolean,\n ): Promise<BaseResponse<ConvertResult>> {\n const response = await this.networkClient.post<BaseResponse<ConvertResult>>(\n `${this.baseUrl}/api/v1/convert`,\n {\n original,\n filename,\n quality,\n transparentBg,\n },\n );\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/svgr_client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,13 +29,16 @@
|
|
|
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.7"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
+
"@sudobility/types": "^1.9.54",
|
|
35
36
|
"react": "^18.0.0 || ^19.0.0",
|
|
36
37
|
"@tanstack/react-query": "^5.0.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
40
|
+
"@sudobility/di": "^1.5.40",
|
|
41
|
+
"@sudobility/types": "^1.9.54",
|
|
39
42
|
"@eslint/js": "^9.38.0",
|
|
40
43
|
"@tanstack/react-query": "^5.0.0",
|
|
41
44
|
"@types/react": "^19.0.0",
|