@sudobility/svgr_client 1.0.13 → 1.0.15

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 +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;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAmB1E,MAAM,WAAW,gBAAgB;IAE/B,OAAO,EAAE,MAAM,CAAC;IAEhB,aAAa,EAAE,aAAa,CAAC;IAM7B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAqBD,MAAM,WAAW,WAAW;IAE1B,UAAU,EAAE,MAAM,CAAC;IAEnB,WAAW,EAAE,MAAM,CAAC;IAEpB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AA8BD,qBAAa,YAAa,SAAQ,KAAK;IAG5B,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKlB;AAgCD,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;gBAE1C,MAAM,EAAE,gBAAgB;IAmC9B,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;YAmCzB,SAAS;CAsBxB"}
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;AAmB1E,MAAM,WAAW,gBAAgB;IAE/B,OAAO,EAAE,MAAM,CAAC;IAEhB,aAAa,EAAE,aAAa,CAAC;IAM7B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAqBD,MAAM,WAAW,WAAW;IAE1B,UAAU,EAAE,MAAM,CAAC;IAEnB,WAAW,EAAE,MAAM,CAAC;IAEpB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B;AA8BD,qBAAa,YAAa,SAAQ,KAAK;IAG5B,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKlB;AAgCD,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0B;gBAE1C,MAAM,EAAE,gBAAgB;IAmC9B,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;YAoCzB,SAAS;CAsBxB"}
@@ -18,7 +18,7 @@ export class SvgrClient {
18
18
  filename,
19
19
  quality,
20
20
  transparentBg,
21
- });
21
+ }, { timeout: 30000 });
22
22
  const response = this.retryConfig
23
23
  ? await this.withRetry(makeRequest, this.retryConfig)
24
24
  : await makeRequest();
@@ -1 +1 @@
1
- {"version":3,"file":"SvgrClient.js","sourceRoot":"","sources":["../../src/network/SvgrClient.ts"],"names":[],"mappings":"AA8DA,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AA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B,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 { BaseResponse, ConvertResult } 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 * console.log(response.data?.svg);\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 the SVG string and original image dimensions on success.\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 * @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 * console.log(response.data.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 ): 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 },\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 * 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":"AA8DA,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;IA+BD,KAAK,CAAC,OA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AAE,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 { BaseResponse, ConvertResult } 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 * console.log(response.data?.svg);\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 the SVG string and original image dimensions on success.\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 * @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 * console.log(response.data.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 ): 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 },\n { timeout: 30000 },\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 * 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.13",
3
+ "version": "1.0.15",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "@tanstack/react-query": "^5.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@sudobility/di": "^1.5.40",
40
+ "@sudobility/di": "^1.5.42",
41
41
  "@sudobility/types": "^1.9.54",
42
42
  "@eslint/js": "^9.38.0",
43
43
  "@tanstack/react-query": "^5.0.0",