@sudobility/svgr_client 1.0.4 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/svgr_client",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -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,9 +17,11 @@ 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(
@@ -27,9 +30,20 @@ export class SvgrClient {
27
30
  quality?: number,
28
31
  transparentBg?: boolean,
29
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
+
30
44
  const response = await fetch(`${this.baseUrl}/api/v1/convert`, {
31
45
  method: "POST",
32
- headers: { "Content-Type": "application/json" },
46
+ headers,
33
47
  body: JSON.stringify({ original, filename, quality, transparentBg }),
34
48
  });
35
49