perspectapi-ts-sdk 5.4.0 → 5.4.4

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/index.d.mts CHANGED
@@ -3804,6 +3804,8 @@ interface ImageTransformOptions {
3804
3804
  bottom?: number;
3805
3805
  left?: number;
3806
3806
  };
3807
+ /** URL prefix for image transform paths. Defaults to '/_image'. */
3808
+ imageUrlPrefix?: string;
3807
3809
  }
3808
3810
  interface ResponsiveImageSizes {
3809
3811
  thumbnail: ImageTransformOptions;
package/dist/index.d.ts CHANGED
@@ -3804,6 +3804,8 @@ interface ImageTransformOptions {
3804
3804
  bottom?: number;
3805
3805
  left?: number;
3806
3806
  };
3807
+ /** URL prefix for image transform paths. Defaults to '/_image'. */
3808
+ imageUrlPrefix?: string;
3807
3809
  }
3808
3810
  interface ResponsiveImageSizes {
3809
3811
  thumbnail: ImageTransformOptions;
package/dist/index.js CHANGED
@@ -3380,6 +3380,13 @@ var BaseV2Client = class {
3380
3380
  * We unwrap accordingly.
3381
3381
  */
3382
3382
  extractData(response) {
3383
+ if ("object" in response && typeof response.object === "string") {
3384
+ const payload2 = response;
3385
+ if (payload2.error && typeof payload2.error === "object" && "type" in payload2.error) {
3386
+ throw this.toError(response);
3387
+ }
3388
+ return response;
3389
+ }
3383
3390
  const payload = response.data;
3384
3391
  if (payload && typeof payload === "object" && "error" in payload) {
3385
3392
  const errObj = payload.error;
@@ -3911,7 +3918,8 @@ function buildImageUrl(baseUrl, mediaPath, options) {
3911
3918
  }
3912
3919
  }
3913
3920
  const queryString = params.join(",");
3914
- return `/cdn-cgi/image/${queryString}/${sourceUrl}`;
3921
+ const prefix = options?.imageUrlPrefix ?? "/_image";
3922
+ return `${prefix}/${queryString}/${sourceUrl}`;
3915
3923
  }
3916
3924
  function generateResponsiveUrls(baseUrl, mediaPath, sizes = DEFAULT_IMAGE_SIZES) {
3917
3925
  return {
package/dist/index.mjs CHANGED
@@ -3312,6 +3312,13 @@ var BaseV2Client = class {
3312
3312
  * We unwrap accordingly.
3313
3313
  */
3314
3314
  extractData(response) {
3315
+ if ("object" in response && typeof response.object === "string") {
3316
+ const payload2 = response;
3317
+ if (payload2.error && typeof payload2.error === "object" && "type" in payload2.error) {
3318
+ throw this.toError(response);
3319
+ }
3320
+ return response;
3321
+ }
3315
3322
  const payload = response.data;
3316
3323
  if (payload && typeof payload === "object" && "error" in payload) {
3317
3324
  const errObj = payload.error;
@@ -3843,7 +3850,8 @@ function buildImageUrl(baseUrl, mediaPath, options) {
3843
3850
  }
3844
3851
  }
3845
3852
  const queryString = params.join(",");
3846
- return `/cdn-cgi/image/${queryString}/${sourceUrl}`;
3853
+ const prefix = options?.imageUrlPrefix ?? "/_image";
3854
+ return `${prefix}/${queryString}/${sourceUrl}`;
3847
3855
  }
3848
3856
  function generateResponsiveUrls(baseUrl, mediaPath, sizes = DEFAULT_IMAGE_SIZES) {
3849
3857
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perspectapi-ts-sdk",
3
- "version": "5.4.0",
3
+ "version": "5.4.4",
4
4
  "description": "TypeScript SDK for PerspectAPI - Cloudflare Workers compatible",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -23,6 +23,8 @@ export interface ImageTransformOptions {
23
23
  bottom?: number;
24
24
  left?: number;
25
25
  };
26
+ /** URL prefix for image transform paths. Defaults to '/_image'. */
27
+ imageUrlPrefix?: string;
26
28
  }
27
29
 
28
30
  export interface ResponsiveImageSizes {
@@ -127,10 +129,8 @@ export function buildImageUrl(
127
129
 
128
130
  const queryString = params.join(',');
129
131
 
130
- // Cloudflare Image Resizing URL format:
131
- // /cdn-cgi/image/{options}/{source-image-url}
132
- // Note: This only works on Cloudflare zones with Image Resizing enabled
133
- return `/cdn-cgi/image/${queryString}/${sourceUrl}`;
132
+ const prefix = options?.imageUrlPrefix ?? '/_image';
133
+ return `${prefix}/${queryString}/${sourceUrl}`;
134
134
  }
135
135
 
136
136
  /**
@@ -68,6 +68,20 @@ export abstract class BaseV2Client {
68
68
  * We unwrap accordingly.
69
69
  */
70
70
  private extractData<T>(response: { data?: unknown; success?: boolean; error?: unknown; message?: string }): T {
71
+ // When the v2 API returns an object with an `object` key (e.g. list responses
72
+ // like { object: "list", data: [...], has_more: ... }), the shared HttpClient
73
+ // passes it through as-is because it detects a `data` key. In that case the
74
+ // *entire* response is the v2 payload — return it directly instead of
75
+ // double-unwrapping via `.data`.
76
+ if ('object' in response && typeof (response as any).object === 'string') {
77
+ // Still check for v2 error bodies nested inside
78
+ const payload = response as any;
79
+ if (payload.error && typeof payload.error === 'object' && 'type' in payload.error) {
80
+ throw this.toError(response);
81
+ }
82
+ return response as unknown as T;
83
+ }
84
+
71
85
  const payload = response.data as any;
72
86
 
73
87
  // Check if the API returned a v2 error body