perspectapi-ts-sdk 5.0.0 → 5.0.1
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 +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +26 -20
- package/dist/index.mjs +26 -20
- package/package.json +1 -1
- package/src/v2/client/base-v2-client.ts +30 -20
package/dist/index.d.mts
CHANGED
|
@@ -3427,6 +3427,18 @@ declare abstract class BaseV2Client {
|
|
|
3427
3427
|
protected buildPath(endpoint: string): string;
|
|
3428
3428
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3429
3429
|
private toParams;
|
|
3430
|
+
/**
|
|
3431
|
+
* Extract v2 payload from HttpClient response.
|
|
3432
|
+
*
|
|
3433
|
+
* The shared HttpClient wraps responses in a v1-style { success, data } envelope.
|
|
3434
|
+
* v2 API responses don't have a `success` field — the HttpClient already throws
|
|
3435
|
+
* on HTTP errors, so if we reach this point the request succeeded.
|
|
3436
|
+
*
|
|
3437
|
+
* The HttpClient may return the v2 payload nested under `data` (when the response
|
|
3438
|
+
* JSON contains a `data` key, which v2 list responses do) or as a direct wrap.
|
|
3439
|
+
* We unwrap accordingly.
|
|
3440
|
+
*/
|
|
3441
|
+
private extractData;
|
|
3430
3442
|
/** GET a single resource. */
|
|
3431
3443
|
protected getOne<T>(path: string, params?: object): Promise<T>;
|
|
3432
3444
|
/** GET a list of resources with cursor pagination. */
|
package/dist/index.d.ts
CHANGED
|
@@ -3427,6 +3427,18 @@ declare abstract class BaseV2Client {
|
|
|
3427
3427
|
protected buildPath(endpoint: string): string;
|
|
3428
3428
|
protected sitePath(siteName: string, resource: string, suffix?: string): string;
|
|
3429
3429
|
private toParams;
|
|
3430
|
+
/**
|
|
3431
|
+
* Extract v2 payload from HttpClient response.
|
|
3432
|
+
*
|
|
3433
|
+
* The shared HttpClient wraps responses in a v1-style { success, data } envelope.
|
|
3434
|
+
* v2 API responses don't have a `success` field — the HttpClient already throws
|
|
3435
|
+
* on HTTP errors, so if we reach this point the request succeeded.
|
|
3436
|
+
*
|
|
3437
|
+
* The HttpClient may return the v2 payload nested under `data` (when the response
|
|
3438
|
+
* JSON contains a `data` key, which v2 list responses do) or as a direct wrap.
|
|
3439
|
+
* We unwrap accordingly.
|
|
3440
|
+
*/
|
|
3441
|
+
private extractData;
|
|
3430
3442
|
/** GET a single resource. */
|
|
3431
3443
|
protected getOne<T>(path: string, params?: object): Promise<T>;
|
|
3432
3444
|
/** GET a list of resources with cursor pagination. */
|
package/dist/index.js
CHANGED
|
@@ -3365,45 +3365,51 @@ var BaseV2Client = class {
|
|
|
3365
3365
|
}
|
|
3366
3366
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
3367
3367
|
}
|
|
3368
|
+
/**
|
|
3369
|
+
* Extract v2 payload from HttpClient response.
|
|
3370
|
+
*
|
|
3371
|
+
* The shared HttpClient wraps responses in a v1-style { success, data } envelope.
|
|
3372
|
+
* v2 API responses don't have a `success` field — the HttpClient already throws
|
|
3373
|
+
* on HTTP errors, so if we reach this point the request succeeded.
|
|
3374
|
+
*
|
|
3375
|
+
* The HttpClient may return the v2 payload nested under `data` (when the response
|
|
3376
|
+
* JSON contains a `data` key, which v2 list responses do) or as a direct wrap.
|
|
3377
|
+
* We unwrap accordingly.
|
|
3378
|
+
*/
|
|
3379
|
+
extractData(response) {
|
|
3380
|
+
const payload = response.data;
|
|
3381
|
+
if (payload && typeof payload === "object" && "error" in payload) {
|
|
3382
|
+
const errObj = payload.error;
|
|
3383
|
+
if (errObj && typeof errObj === "object" && "type" in errObj) {
|
|
3384
|
+
throw this.toError(response);
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
return payload;
|
|
3388
|
+
}
|
|
3368
3389
|
/** GET a single resource. */
|
|
3369
3390
|
async getOne(path, params) {
|
|
3370
3391
|
const response = await this.http.get(path, this.toParams(params));
|
|
3371
|
-
|
|
3372
|
-
throw this.toError(response);
|
|
3373
|
-
}
|
|
3374
|
-
return response.data;
|
|
3392
|
+
return this.extractData(response);
|
|
3375
3393
|
}
|
|
3376
3394
|
/** GET a list of resources with cursor pagination. */
|
|
3377
3395
|
async getList(path, params) {
|
|
3378
3396
|
const response = await this.http.get(path, this.toParams(params));
|
|
3379
|
-
|
|
3380
|
-
throw this.toError(response);
|
|
3381
|
-
}
|
|
3382
|
-
return response.data;
|
|
3397
|
+
return this.extractData(response);
|
|
3383
3398
|
}
|
|
3384
3399
|
/** POST to create a resource. */
|
|
3385
3400
|
async post(path, body) {
|
|
3386
3401
|
const response = await this.http.post(path, body);
|
|
3387
|
-
|
|
3388
|
-
throw this.toError(response);
|
|
3389
|
-
}
|
|
3390
|
-
return response.data;
|
|
3402
|
+
return this.extractData(response);
|
|
3391
3403
|
}
|
|
3392
3404
|
/** PATCH to update a resource. */
|
|
3393
3405
|
async patchOne(path, body) {
|
|
3394
3406
|
const response = await this.http.patch(path, body);
|
|
3395
|
-
|
|
3396
|
-
throw this.toError(response);
|
|
3397
|
-
}
|
|
3398
|
-
return response.data;
|
|
3407
|
+
return this.extractData(response);
|
|
3399
3408
|
}
|
|
3400
3409
|
/** DELETE a resource. */
|
|
3401
3410
|
async deleteOne(path) {
|
|
3402
3411
|
const response = await this.http.delete(path);
|
|
3403
|
-
|
|
3404
|
-
throw this.toError(response);
|
|
3405
|
-
}
|
|
3406
|
-
return response.data;
|
|
3412
|
+
return this.extractData(response);
|
|
3407
3413
|
}
|
|
3408
3414
|
/**
|
|
3409
3415
|
* Auto-paginating async generator.
|
package/dist/index.mjs
CHANGED
|
@@ -3298,45 +3298,51 @@ var BaseV2Client = class {
|
|
|
3298
3298
|
}
|
|
3299
3299
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
3300
3300
|
}
|
|
3301
|
+
/**
|
|
3302
|
+
* Extract v2 payload from HttpClient response.
|
|
3303
|
+
*
|
|
3304
|
+
* The shared HttpClient wraps responses in a v1-style { success, data } envelope.
|
|
3305
|
+
* v2 API responses don't have a `success` field — the HttpClient already throws
|
|
3306
|
+
* on HTTP errors, so if we reach this point the request succeeded.
|
|
3307
|
+
*
|
|
3308
|
+
* The HttpClient may return the v2 payload nested under `data` (when the response
|
|
3309
|
+
* JSON contains a `data` key, which v2 list responses do) or as a direct wrap.
|
|
3310
|
+
* We unwrap accordingly.
|
|
3311
|
+
*/
|
|
3312
|
+
extractData(response) {
|
|
3313
|
+
const payload = response.data;
|
|
3314
|
+
if (payload && typeof payload === "object" && "error" in payload) {
|
|
3315
|
+
const errObj = payload.error;
|
|
3316
|
+
if (errObj && typeof errObj === "object" && "type" in errObj) {
|
|
3317
|
+
throw this.toError(response);
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
return payload;
|
|
3321
|
+
}
|
|
3301
3322
|
/** GET a single resource. */
|
|
3302
3323
|
async getOne(path, params) {
|
|
3303
3324
|
const response = await this.http.get(path, this.toParams(params));
|
|
3304
|
-
|
|
3305
|
-
throw this.toError(response);
|
|
3306
|
-
}
|
|
3307
|
-
return response.data;
|
|
3325
|
+
return this.extractData(response);
|
|
3308
3326
|
}
|
|
3309
3327
|
/** GET a list of resources with cursor pagination. */
|
|
3310
3328
|
async getList(path, params) {
|
|
3311
3329
|
const response = await this.http.get(path, this.toParams(params));
|
|
3312
|
-
|
|
3313
|
-
throw this.toError(response);
|
|
3314
|
-
}
|
|
3315
|
-
return response.data;
|
|
3330
|
+
return this.extractData(response);
|
|
3316
3331
|
}
|
|
3317
3332
|
/** POST to create a resource. */
|
|
3318
3333
|
async post(path, body) {
|
|
3319
3334
|
const response = await this.http.post(path, body);
|
|
3320
|
-
|
|
3321
|
-
throw this.toError(response);
|
|
3322
|
-
}
|
|
3323
|
-
return response.data;
|
|
3335
|
+
return this.extractData(response);
|
|
3324
3336
|
}
|
|
3325
3337
|
/** PATCH to update a resource. */
|
|
3326
3338
|
async patchOne(path, body) {
|
|
3327
3339
|
const response = await this.http.patch(path, body);
|
|
3328
|
-
|
|
3329
|
-
throw this.toError(response);
|
|
3330
|
-
}
|
|
3331
|
-
return response.data;
|
|
3340
|
+
return this.extractData(response);
|
|
3332
3341
|
}
|
|
3333
3342
|
/** DELETE a resource. */
|
|
3334
3343
|
async deleteOne(path) {
|
|
3335
3344
|
const response = await this.http.delete(path);
|
|
3336
|
-
|
|
3337
|
-
throw this.toError(response);
|
|
3338
|
-
}
|
|
3339
|
-
return response.data;
|
|
3345
|
+
return this.extractData(response);
|
|
3340
3346
|
}
|
|
3341
3347
|
/**
|
|
3342
3348
|
* Auto-paginating async generator.
|
package/package.json
CHANGED
|
@@ -52,13 +52,35 @@ export abstract class BaseV2Client {
|
|
|
52
52
|
return Object.keys(out).length > 0 ? out : undefined;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Extract v2 payload from HttpClient response.
|
|
57
|
+
*
|
|
58
|
+
* The shared HttpClient wraps responses in a v1-style { success, data } envelope.
|
|
59
|
+
* v2 API responses don't have a `success` field — the HttpClient already throws
|
|
60
|
+
* on HTTP errors, so if we reach this point the request succeeded.
|
|
61
|
+
*
|
|
62
|
+
* The HttpClient may return the v2 payload nested under `data` (when the response
|
|
63
|
+
* JSON contains a `data` key, which v2 list responses do) or as a direct wrap.
|
|
64
|
+
* We unwrap accordingly.
|
|
65
|
+
*/
|
|
66
|
+
private extractData<T>(response: { data?: unknown; success?: boolean; error?: unknown; message?: string }): T {
|
|
67
|
+
const payload = response.data as any;
|
|
68
|
+
|
|
69
|
+
// Check if the API returned a v2 error body
|
|
70
|
+
if (payload && typeof payload === 'object' && 'error' in payload) {
|
|
71
|
+
const errObj = payload.error;
|
|
72
|
+
if (errObj && typeof errObj === 'object' && 'type' in errObj) {
|
|
73
|
+
throw this.toError(response);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return payload as T;
|
|
78
|
+
}
|
|
79
|
+
|
|
55
80
|
/** GET a single resource. */
|
|
56
81
|
protected async getOne<T>(path: string, params?: object): Promise<T> {
|
|
57
82
|
const response = await this.http.get<T>(path, this.toParams(params));
|
|
58
|
-
|
|
59
|
-
throw this.toError(response);
|
|
60
|
-
}
|
|
61
|
-
return response.data!;
|
|
83
|
+
return this.extractData<T>(response);
|
|
62
84
|
}
|
|
63
85
|
|
|
64
86
|
/** GET a list of resources with cursor pagination. */
|
|
@@ -67,37 +89,25 @@ export abstract class BaseV2Client {
|
|
|
67
89
|
params?: object,
|
|
68
90
|
): Promise<V2List<T>> {
|
|
69
91
|
const response = await this.http.get<V2List<T>>(path, this.toParams(params));
|
|
70
|
-
|
|
71
|
-
throw this.toError(response);
|
|
72
|
-
}
|
|
73
|
-
return response.data!;
|
|
92
|
+
return this.extractData<V2List<T>>(response);
|
|
74
93
|
}
|
|
75
94
|
|
|
76
95
|
/** POST to create a resource. */
|
|
77
96
|
protected async post<T>(path: string, body?: unknown): Promise<T> {
|
|
78
97
|
const response = await this.http.post<T>(path, body);
|
|
79
|
-
|
|
80
|
-
throw this.toError(response);
|
|
81
|
-
}
|
|
82
|
-
return response.data!;
|
|
98
|
+
return this.extractData<T>(response);
|
|
83
99
|
}
|
|
84
100
|
|
|
85
101
|
/** PATCH to update a resource. */
|
|
86
102
|
protected async patchOne<T>(path: string, body?: unknown): Promise<T> {
|
|
87
103
|
const response = await this.http.patch<T>(path, body);
|
|
88
|
-
|
|
89
|
-
throw this.toError(response);
|
|
90
|
-
}
|
|
91
|
-
return response.data!;
|
|
104
|
+
return this.extractData<T>(response);
|
|
92
105
|
}
|
|
93
106
|
|
|
94
107
|
/** DELETE a resource. */
|
|
95
108
|
protected async deleteOne(path: string): Promise<V2Deleted> {
|
|
96
109
|
const response = await this.http.delete<V2Deleted>(path);
|
|
97
|
-
|
|
98
|
-
throw this.toError(response);
|
|
99
|
-
}
|
|
100
|
-
return response.data!;
|
|
110
|
+
return this.extractData<V2Deleted>(response);
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
/**
|