perspectapi-ts-sdk 5.4.2 → 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.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;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perspectapi-ts-sdk",
3
- "version": "5.4.2",
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",
@@ -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