@sudobility/svgr_client 1.0.3 → 1.0.6

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/bun.lock CHANGED
@@ -5,7 +5,7 @@
5
5
  "": {
6
6
  "name": "@sudobility/svgr_client",
7
7
  "dependencies": {
8
- "@sudobility/svgr_types": "^1.0.2",
8
+ "@sudobility/svgr_types": "^1.0.3",
9
9
  },
10
10
  "devDependencies": {
11
11
  "@eslint/js": "^9.38.0",
@@ -154,7 +154,7 @@
154
154
 
155
155
  "@rollup/rollup-win32-x64-msvc": ["@rollup/rollup-win32-x64-msvc@4.57.1", "", { "os": "win32", "cpu": "x64" }, "sha512-mxRFDdHIWRxg3UfIIAwCm6NzvxG0jDX/wBN6KsQFTvKFqqg9vTrWUE68qEjHt19A5wwx5X5aUi2zuZT7YR0jrA=="],
156
156
 
157
- "@sudobility/svgr_types": ["@sudobility/svgr_types@1.0.2", "", { "peerDependencies": { "@sudobility/types": "^1.9.50" } }, "sha512-qWge84qsZmxCMBZkuqOExb7sHqrJ9rmntifQ4E2xY6W1k1dpQHYpH+zyc8527KYpY5B6A8f4A+i7x+sklN9qyg=="],
157
+ "@sudobility/svgr_types": ["@sudobility/svgr_types@1.0.3", "", { "peerDependencies": { "@sudobility/types": "^1.9.50" } }, "sha512-JJsfoZkNhgs6MGHx3CHUJPMZDAtfJUE8ymUzbM3EDcSOOLYpVLnPsCYahR6RIVccXe/JvtmF3S24/NH4kwMmjQ=="],
158
158
 
159
159
  "@sudobility/types": ["@sudobility/types@1.9.50", "", {}, "sha512-SKopIMJqgNVopcz/MNukrm936yKuBJMFcz4uUbQz9XB7cDjyuExoVeyMnvidMKtOLkmJSRdYYV4+M7eG7KN2aw=="],
160
160
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/svgr_client",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "verify": "bun run typecheck && bun run lint && bun run test && bun run build"
27
27
  },
28
28
  "dependencies": {
29
- "@sudobility/svgr_types": "^1.0.2"
29
+ "@sudobility/svgr_types": "^1.0.3"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": "^18.0.0 || ^19.0.0",
@@ -7,10 +7,12 @@ export function useConvert(client: SvgrClient) {
7
7
  original,
8
8
  filename,
9
9
  quality,
10
+ transparentBg,
10
11
  }: {
11
12
  original: string;
12
13
  filename?: string;
13
14
  quality?: number;
14
- }) => client.convert(original, filename, quality),
15
+ transparentBg?: boolean;
16
+ }) => client.convert(original, filename, quality, transparentBg),
15
17
  });
16
18
  }
@@ -2,6 +2,7 @@ import type { BaseResponse, ConvertResult } from "@sudobility/svgr_types";
2
2
 
3
3
  export interface SvgrClientConfig {
4
4
  baseUrl: string;
5
+ getToken?: () => Promise<string | null>;
5
6
  }
6
7
 
7
8
  export class SvgrApiError extends Error {
@@ -16,20 +17,34 @@ export class SvgrApiError extends Error {
16
17
 
17
18
  export class SvgrClient {
18
19
  private baseUrl: string;
20
+ private getToken: (() => Promise<string | null>) | undefined;
19
21
 
20
22
  constructor(config: SvgrClientConfig) {
21
23
  this.baseUrl = config.baseUrl;
24
+ this.getToken = config.getToken;
22
25
  }
23
26
 
24
27
  async convert(
25
28
  original: string,
26
29
  filename?: string,
27
30
  quality?: number,
31
+ transparentBg?: boolean,
28
32
  ): Promise<BaseResponse<ConvertResult>> {
33
+ const headers: Record<string, string> = {
34
+ "Content-Type": "application/json",
35
+ };
36
+
37
+ if (this.getToken) {
38
+ const token = await this.getToken();
39
+ if (token) {
40
+ headers["Authorization"] = `Bearer ${token}`;
41
+ }
42
+ }
43
+
29
44
  const response = await fetch(`${this.baseUrl}/api/v1/convert`, {
30
45
  method: "POST",
31
- headers: { "Content-Type": "application/json" },
32
- body: JSON.stringify({ original, filename, quality }),
46
+ headers,
47
+ body: JSON.stringify({ original, filename, quality, transparentBg }),
33
48
  });
34
49
 
35
50
  if (!response.ok) {