@seamapi/http 2.22.0 → 2.23.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/lib/routes/devices/devices.d.ts +1 -1
- package/lib/routes/devices/unmanaged/unmanaged.d.ts +1 -1
- package/lib/routes/locks/locks.d.ts +1 -1
- package/lib/seam-http-error.d.ts +20 -0
- package/lib/seam-http-error.js +27 -0
- package/lib/seam-http-error.js.map +1 -1
- package/lib/seam-http-request.d.ts +6 -0
- package/lib/seam-http-request.js +16 -1
- package/lib/seam-http-request.js.map +1 -1
- package/lib/seam-paginator.js +14 -13
- package/lib/seam-paginator.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/src/lib/routes/devices/devices.ts +1 -1
- package/src/lib/routes/devices/unmanaged/unmanaged.ts +1 -1
- package/src/lib/routes/locks/locks.ts +1 -1
- package/src/lib/seam-http-error.ts +35 -0
- package/src/lib/seam-http-request.ts +38 -1
- package/src/lib/seam-paginator.ts +28 -16
- package/src/lib/version.ts +1 -1
|
@@ -113,7 +113,7 @@ export type DevicesListParameters = {
|
|
|
113
113
|
/**
|
|
114
114
|
* Manufacturer for which you want to list devices.
|
|
115
115
|
*/
|
|
116
|
-
manufacturer?: 'akuvox' | 'august' | 'avigilon_alta' | 'brivo' | 'butterflymx' | 'doorking' | 'four_suites' | 'genie' | 'igloo' | 'keywe' | 'kwikset' | 'linear' | '
|
|
116
|
+
manufacturer?: 'akuvox' | 'august' | 'avigilon_alta' | 'brivo' | 'butterflymx' | 'doorking' | 'four_suites' | 'genie' | 'igloo' | 'keywe' | 'kwikset' | 'linear' | 'nuki' | 'philia' | 'salto' | 'samsung' | 'schlage' | 'seam' | 'unknown' | 'wyze' | 'yale' | 'two_n' | 'ttlock' | 'igloohome' | 'controlbyweb' | 'dormakaba_oracode' | 'tedee' | 'keyincode' | 'akiles' | 'aqara' | 'ecobee' | 'honeywell_resideo' | 'keynest' | 'korelock' | 'lockly' | 'minut' | 'nest' | 'noiseaware' | 'sensi' | 'smartthings' | 'tado' | 'ultraloq' | 'ring' | 'ical' | 'lodgify' | 'hostaway' | 'guesty' | 'acuity_scheduling' | 'omnitec' | 'kisi' | 'slack' | 'yacan' | undefined;
|
|
117
117
|
/**
|
|
118
118
|
* Identifies the specific page of results to return, obtained from the previous page's `next_page_cursor`.
|
|
119
119
|
*/
|
|
@@ -96,7 +96,7 @@ export type DevicesUnmanagedListParameters = {
|
|
|
96
96
|
/**
|
|
97
97
|
* Manufacturer for which you want to list devices.
|
|
98
98
|
*/
|
|
99
|
-
manufacturer?: 'akuvox' | 'august' | 'avigilon_alta' | 'brivo' | 'butterflymx' | 'doorking' | 'four_suites' | 'genie' | 'igloo' | 'keywe' | 'kwikset' | 'linear' | '
|
|
99
|
+
manufacturer?: 'akuvox' | 'august' | 'avigilon_alta' | 'brivo' | 'butterflymx' | 'doorking' | 'four_suites' | 'genie' | 'igloo' | 'keywe' | 'kwikset' | 'linear' | 'nuki' | 'philia' | 'salto' | 'samsung' | 'schlage' | 'seam' | 'unknown' | 'wyze' | 'yale' | 'two_n' | 'ttlock' | 'igloohome' | 'controlbyweb' | 'dormakaba_oracode' | 'tedee' | 'keyincode' | 'akiles' | 'aqara' | 'ecobee' | 'honeywell_resideo' | 'keynest' | 'korelock' | 'lockly' | 'minut' | 'nest' | 'noiseaware' | 'sensi' | 'smartthings' | 'tado' | 'ultraloq' | 'ring' | 'ical' | 'lodgify' | 'hostaway' | 'guesty' | 'acuity_scheduling' | 'omnitec' | 'kisi' | 'slack' | 'yacan' | undefined;
|
|
100
100
|
/**
|
|
101
101
|
* Identifies the specific page of results to return, obtained from the previous page's `next_page_cursor`.
|
|
102
102
|
*/
|
|
@@ -106,7 +106,7 @@ export type LocksListParameters = {
|
|
|
106
106
|
/**
|
|
107
107
|
* Manufacturer of the locks that you want to list.
|
|
108
108
|
*/
|
|
109
|
-
manufacturer?: 'akuvox' | 'august' | 'brivo' | 'butterflymx' | 'avigilon_alta' | 'doorking' | 'genie' | 'igloo' | 'linear' | '
|
|
109
|
+
manufacturer?: 'akuvox' | 'august' | 'brivo' | 'butterflymx' | 'avigilon_alta' | 'doorking' | 'genie' | 'igloo' | 'linear' | 'kwikset' | 'nuki' | 'salto' | 'schlage' | 'seam' | 'wyze' | 'yale' | 'two_n' | 'controlbyweb' | 'ttlock' | 'igloohome' | 'four_suites' | 'dormakaba_oracode' | 'tedee' | 'keyincode' | 'akiles' | 'aqara' | 'korelock' | 'lockly' | 'smartthings' | 'ultraloq' | 'omnitec' | 'kisi' | 'yacan' | undefined;
|
|
110
110
|
};
|
|
111
111
|
/**
|
|
112
112
|
* @deprecated Use LocksListRequest instead.
|
package/lib/seam-http-error.d.ts
CHANGED
|
@@ -54,3 +54,23 @@ export declare class SeamHttpInvalidInputError extends SeamHttpApiError {
|
|
|
54
54
|
* Returns true if the error is a {@link SeamHttpInvalidInputError}.
|
|
55
55
|
*/
|
|
56
56
|
export declare const isSeamHttpInvalidInputError: (error: unknown) => error is SeamHttpInvalidInputError;
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when the Seam API returns a success response
|
|
59
|
+
* with an unexpected shape,
|
|
60
|
+
* e.g., a response missing the expected response key.
|
|
61
|
+
*/
|
|
62
|
+
export declare class SeamHttpInvalidResponseError extends Error {
|
|
63
|
+
/**
|
|
64
|
+
* Path of the endpoint that returned the invalid response.
|
|
65
|
+
*/
|
|
66
|
+
path: string;
|
|
67
|
+
/**
|
|
68
|
+
* Key expected to contain the response data.
|
|
69
|
+
*/
|
|
70
|
+
responseKey: string;
|
|
71
|
+
constructor(path: string, responseKey: string, reason: string);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns true if the error is a {@link SeamHttpInvalidResponseError}.
|
|
75
|
+
*/
|
|
76
|
+
export declare const isSeamHttpInvalidResponseError: (error: unknown) => error is SeamHttpInvalidResponseError;
|
package/lib/seam-http-error.js
CHANGED
|
@@ -83,4 +83,31 @@ export class SeamHttpInvalidInputError extends SeamHttpApiError {
|
|
|
83
83
|
export const isSeamHttpInvalidInputError = (error) => {
|
|
84
84
|
return error instanceof SeamHttpInvalidInputError;
|
|
85
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Error thrown when the Seam API returns a success response
|
|
88
|
+
* with an unexpected shape,
|
|
89
|
+
* e.g., a response missing the expected response key.
|
|
90
|
+
*/
|
|
91
|
+
export class SeamHttpInvalidResponseError extends Error {
|
|
92
|
+
/**
|
|
93
|
+
* Path of the endpoint that returned the invalid response.
|
|
94
|
+
*/
|
|
95
|
+
path;
|
|
96
|
+
/**
|
|
97
|
+
* Key expected to contain the response data.
|
|
98
|
+
*/
|
|
99
|
+
responseKey;
|
|
100
|
+
constructor(path, responseKey, reason) {
|
|
101
|
+
super(`Seam returned an invalid response for ${path}: expected "${responseKey}", ${reason}`);
|
|
102
|
+
this.name = this.constructor.name;
|
|
103
|
+
this.path = path;
|
|
104
|
+
this.responseKey = responseKey;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns true if the error is a {@link SeamHttpInvalidResponseError}.
|
|
109
|
+
*/
|
|
110
|
+
export const isSeamHttpInvalidResponseError = (error) => {
|
|
111
|
+
return error instanceof SeamHttpInvalidResponseError;
|
|
112
|
+
};
|
|
86
113
|
//# sourceMappingURL=seam-http-error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seam-http-error.js","sourceRoot":"","sources":["../src/lib/seam-http-error.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;;OAEG;IACH,IAAI,CAAQ;IAEZ,UAAU,CAAQ;IAElB;;;OAGG;IACH,SAAS,CAAQ;IAEjB;;OAEG;IACH,IAAI,CAAU;IAEd,YAAY,KAAe,EAAE,UAAkB,EAAE,SAAiB;QAChE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,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AI,EAAE,CAAA;IACzD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,KAAc,EACsB,EAAE;IACtC,OAAO,KAAK,YAAY,yBAAyB,CAAA;AACnD,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IACrD;;OAEG;IACH,IAAI,CAAQ;IAEZ;;OAEG;IACH,WAAW,CAAQ;IAEnB,YAAY,IAAY,EAAE,WAAmB,EAAE,MAAc;QAC3D,KAAK,CACH,yCAAyC,IAAI,eAAe,WAAW,MAAM,MAAM,EAAE,CACtF,CAAA;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,KAAc,EACyB,EAAE;IACzC,OAAO,KAAK,YAAY,4BAA4B,CAAA;AACtD,CAAC,CAAA"}
|
|
@@ -67,4 +67,10 @@ export declare class SeamHttpRequest<const TResponse, const TResponseKey extends
|
|
|
67
67
|
catch<TResult = never>(onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null | undefined): Promise<(TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined) | TResult>;
|
|
68
68
|
finally(onfinally?: (() => void) | null | undefined): Promise<TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined>;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Reads the response data at the response key,
|
|
72
|
+
* throwing a {@link SeamHttpInvalidResponseError} for a success response
|
|
73
|
+
* that is not an object or does not contain the response key.
|
|
74
|
+
*/
|
|
75
|
+
export declare const readResponseData: <TResponse, TResponseKey extends keyof TResponse>(response: TResponse, responseKey: TResponseKey, path: string) => TResponse[TResponseKey];
|
|
70
76
|
export {};
|
package/lib/seam-http-request.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertValidRequestParameters } from './request-parameters.js';
|
|
2
2
|
import { resolveActionAttempt, } from './resolve-action-attempt.js';
|
|
3
|
+
import { SeamHttpInvalidResponseError } from './seam-http-error.js';
|
|
3
4
|
import { serializeUrlSearchParams } from './url-search-params-serializer.js';
|
|
4
5
|
/**
|
|
5
6
|
* A lazy request to the Seam API.
|
|
@@ -72,7 +73,7 @@ export class SeamHttpRequest {
|
|
|
72
73
|
if (this.responseKey === undefined) {
|
|
73
74
|
return undefined;
|
|
74
75
|
}
|
|
75
|
-
const data = response
|
|
76
|
+
const data = readResponseData(response, this.responseKey, this.pathname);
|
|
76
77
|
if (this.responseKey === 'action_attempt') {
|
|
77
78
|
const waitForActionAttempt = this.#config.options?.waitForActionAttempt ??
|
|
78
79
|
this.#parent.defaults.waitForActionAttempt;
|
|
@@ -111,6 +112,20 @@ export class SeamHttpRequest {
|
|
|
111
112
|
return await this.execute().finally(onfinally);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Reads the response data at the response key,
|
|
117
|
+
* throwing a {@link SeamHttpInvalidResponseError} for a success response
|
|
118
|
+
* that is not an object or does not contain the response key.
|
|
119
|
+
*/
|
|
120
|
+
export const readResponseData = (response, responseKey, path) => {
|
|
121
|
+
if (response == null || typeof response !== 'object') {
|
|
122
|
+
throw new SeamHttpInvalidResponseError(path, String(responseKey), `got ${response === null ? 'null' : typeof response} instead of a response object`);
|
|
123
|
+
}
|
|
124
|
+
if (!(responseKey in response)) {
|
|
125
|
+
throw new SeamHttpInvalidResponseError(path, String(responseKey), 'which the response does not contain');
|
|
126
|
+
}
|
|
127
|
+
return response[responseKey];
|
|
128
|
+
};
|
|
114
129
|
const getUrlPrefix = (input) => {
|
|
115
130
|
if (canParseUrl(input)) {
|
|
116
131
|
const url = new URL(input).toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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alidResponseError } from './seam-http-error.js';
|
|
2
|
+
import { readResponseData, SeamHttpRequest } from './seam-http-request.js';
|
|
2
3
|
/**
|
|
3
4
|
* Iterates over paginated results from Seam API list endpoints.
|
|
4
5
|
*
|
|
@@ -51,20 +52,20 @@ export class SeamPaginator {
|
|
|
51
52
|
: undefined,
|
|
52
53
|
});
|
|
53
54
|
const response = await request.fetchResponse();
|
|
54
|
-
const data = response
|
|
55
|
-
const paginationData = response != null &&
|
|
56
|
-
typeof response === 'object' &&
|
|
57
|
-
'pagination' in response
|
|
58
|
-
? response.pagination
|
|
59
|
-
: null;
|
|
60
|
-
const pagination = {
|
|
61
|
-
hasNextPage: paginationData?.has_next_page ?? false,
|
|
62
|
-
nextPageCursor: paginationData?.next_page_cursor ?? null,
|
|
63
|
-
nextPageUrl: paginationData?.next_page_url ?? null,
|
|
64
|
-
};
|
|
55
|
+
const data = readResponseData(response, responseKey, request.pathname);
|
|
65
56
|
if (!Array.isArray(data)) {
|
|
66
|
-
throw new
|
|
57
|
+
throw new SeamHttpInvalidResponseError(request.pathname, String(responseKey), `got ${data === null ? 'null' : typeof data} instead of a list`);
|
|
58
|
+
}
|
|
59
|
+
const paginationData = readResponseData(response, 'pagination', request.pathname);
|
|
60
|
+
if (paginationData === null || typeof paginationData !== 'object') {
|
|
61
|
+
throw new SeamHttpInvalidResponseError(request.pathname, 'pagination', `got ${paginationData === null ? 'null' : typeof paginationData} instead of a pagination object`);
|
|
67
62
|
}
|
|
63
|
+
const paginationResponse = paginationData;
|
|
64
|
+
const pagination = {
|
|
65
|
+
hasNextPage: paginationResponse.has_next_page ?? false,
|
|
66
|
+
nextPageCursor: paginationResponse.next_page_cursor ?? null,
|
|
67
|
+
nextPageUrl: paginationResponse.next_page_url ?? null,
|
|
68
|
+
};
|
|
68
69
|
return [
|
|
69
70
|
data,
|
|
70
71
|
pagination,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seam-paginator.js","sourceRoot":"","sources":["../src/lib/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Z,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAG3B,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAA;QAClD,MAAM,OAAO,CAAA;QACb,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC;YAC9B,CAAC;YAAA,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,CAAA;YACvE,MAAM,OAAO,CAAA;QACf,CAAC;IACH,CAAC;CACF"}
|
package/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const seamapiJavascriptHttpVersion = "2.
|
|
1
|
+
declare const seamapiJavascriptHttpVersion = "2.23.1";
|
|
2
2
|
export default seamapiJavascriptHttpVersion;
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seamapi/http",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.23.1",
|
|
4
4
|
"description": "JavaScript HTTP client for the Seam API written in TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@seamapi/blueprint": "^1.8.0",
|
|
89
89
|
"@seamapi/fake-seam-connect": "^2.0.4",
|
|
90
90
|
"@seamapi/smith": "^1.1.0",
|
|
91
|
-
"@seamapi/types": "1.
|
|
91
|
+
"@seamapi/types": "1.1037.0",
|
|
92
92
|
"@types/jsonwebtoken": "^9.0.6",
|
|
93
93
|
"@types/node": "^24.10.9",
|
|
94
94
|
"ava": "^8.0.1",
|
|
@@ -443,7 +443,6 @@ export type DevicesListParameters = {
|
|
|
443
443
|
| 'keywe'
|
|
444
444
|
| 'kwikset'
|
|
445
445
|
| 'linear'
|
|
446
|
-
| 'lockly'
|
|
447
446
|
| 'nuki'
|
|
448
447
|
| 'philia'
|
|
449
448
|
| 'salto'
|
|
@@ -466,6 +465,7 @@ export type DevicesListParameters = {
|
|
|
466
465
|
| 'honeywell_resideo'
|
|
467
466
|
| 'keynest'
|
|
468
467
|
| 'korelock'
|
|
468
|
+
| 'lockly'
|
|
469
469
|
| 'minut'
|
|
470
470
|
| 'nest'
|
|
471
471
|
| 'noiseaware'
|
|
@@ -392,7 +392,6 @@ export type DevicesUnmanagedListParameters = {
|
|
|
392
392
|
| 'keywe'
|
|
393
393
|
| 'kwikset'
|
|
394
394
|
| 'linear'
|
|
395
|
-
| 'lockly'
|
|
396
395
|
| 'nuki'
|
|
397
396
|
| 'philia'
|
|
398
397
|
| 'salto'
|
|
@@ -415,6 +414,7 @@ export type DevicesUnmanagedListParameters = {
|
|
|
415
414
|
| 'honeywell_resideo'
|
|
416
415
|
| 'keynest'
|
|
417
416
|
| 'korelock'
|
|
417
|
+
| 'lockly'
|
|
418
418
|
| 'minut'
|
|
419
419
|
| 'nest'
|
|
420
420
|
| 'noiseaware'
|
|
@@ -427,7 +427,6 @@ export type LocksListParameters = {
|
|
|
427
427
|
| 'genie'
|
|
428
428
|
| 'igloo'
|
|
429
429
|
| 'linear'
|
|
430
|
-
| 'lockly'
|
|
431
430
|
| 'kwikset'
|
|
432
431
|
| 'nuki'
|
|
433
432
|
| 'salto'
|
|
@@ -446,6 +445,7 @@ export type LocksListParameters = {
|
|
|
446
445
|
| 'akiles'
|
|
447
446
|
| 'aqara'
|
|
448
447
|
| 'korelock'
|
|
448
|
+
| 'lockly'
|
|
449
449
|
| 'smartthings'
|
|
450
450
|
| 'ultraloq'
|
|
451
451
|
| 'omnitec'
|
|
@@ -103,3 +103,38 @@ export const isSeamHttpInvalidInputError = (
|
|
|
103
103
|
): error is SeamHttpInvalidInputError => {
|
|
104
104
|
return error instanceof SeamHttpInvalidInputError
|
|
105
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Error thrown when the Seam API returns a success response
|
|
109
|
+
* with an unexpected shape,
|
|
110
|
+
* e.g., a response missing the expected response key.
|
|
111
|
+
*/
|
|
112
|
+
export class SeamHttpInvalidResponseError extends Error {
|
|
113
|
+
/**
|
|
114
|
+
* Path of the endpoint that returned the invalid response.
|
|
115
|
+
*/
|
|
116
|
+
path: string
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Key expected to contain the response data.
|
|
120
|
+
*/
|
|
121
|
+
responseKey: string
|
|
122
|
+
|
|
123
|
+
constructor(path: string, responseKey: string, reason: string) {
|
|
124
|
+
super(
|
|
125
|
+
`Seam returned an invalid response for ${path}: expected "${responseKey}", ${reason}`,
|
|
126
|
+
)
|
|
127
|
+
this.name = this.constructor.name
|
|
128
|
+
this.path = path
|
|
129
|
+
this.responseKey = responseKey
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Returns true if the error is a {@link SeamHttpInvalidResponseError}.
|
|
135
|
+
*/
|
|
136
|
+
export const isSeamHttpInvalidResponseError = (
|
|
137
|
+
error: unknown,
|
|
138
|
+
): error is SeamHttpInvalidResponseError => {
|
|
139
|
+
return error instanceof SeamHttpInvalidResponseError
|
|
140
|
+
}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
resolveActionAttempt,
|
|
9
9
|
} from './resolve-action-attempt.js'
|
|
10
10
|
import type { ActionAttempt } from './resources/action-attempt.js'
|
|
11
|
+
import { SeamHttpInvalidResponseError } from './seam-http-error.js'
|
|
11
12
|
import { serializeUrlSearchParams } from './url-search-params-serializer.js'
|
|
12
13
|
|
|
13
14
|
interface SeamHttpRequestParent {
|
|
@@ -132,7 +133,11 @@ export class SeamHttpRequest<
|
|
|
132
133
|
return undefined as Response
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
const data =
|
|
136
|
+
const data = readResponseData(
|
|
137
|
+
response,
|
|
138
|
+
this.responseKey,
|
|
139
|
+
this.pathname,
|
|
140
|
+
) as Response
|
|
136
141
|
|
|
137
142
|
if (this.responseKey === 'action_attempt') {
|
|
138
143
|
const waitForActionAttempt =
|
|
@@ -222,6 +227,38 @@ export class SeamHttpRequest<
|
|
|
222
227
|
}
|
|
223
228
|
}
|
|
224
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Reads the response data at the response key,
|
|
232
|
+
* throwing a {@link SeamHttpInvalidResponseError} for a success response
|
|
233
|
+
* that is not an object or does not contain the response key.
|
|
234
|
+
*/
|
|
235
|
+
export const readResponseData = <
|
|
236
|
+
TResponse,
|
|
237
|
+
TResponseKey extends keyof TResponse,
|
|
238
|
+
>(
|
|
239
|
+
response: TResponse,
|
|
240
|
+
responseKey: TResponseKey,
|
|
241
|
+
path: string,
|
|
242
|
+
): TResponse[TResponseKey] => {
|
|
243
|
+
if (response == null || typeof response !== 'object') {
|
|
244
|
+
throw new SeamHttpInvalidResponseError(
|
|
245
|
+
path,
|
|
246
|
+
String(responseKey),
|
|
247
|
+
`got ${response === null ? 'null' : typeof response} instead of a response object`,
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (!(responseKey in response)) {
|
|
252
|
+
throw new SeamHttpInvalidResponseError(
|
|
253
|
+
path,
|
|
254
|
+
String(responseKey),
|
|
255
|
+
'which the response does not contain',
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return response[responseKey]
|
|
260
|
+
}
|
|
261
|
+
|
|
225
262
|
const getUrlPrefix = (input: string): string => {
|
|
226
263
|
if (canParseUrl(input)) {
|
|
227
264
|
const url = new URL(input).toString()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Client } from './client.js'
|
|
2
2
|
import type { SeamHttpRequestOptions } from './options.js'
|
|
3
|
-
import {
|
|
3
|
+
import { SeamHttpInvalidResponseError } from './seam-http-error.js'
|
|
4
|
+
import { readResponseData, SeamHttpRequest } from './seam-http-request.js'
|
|
4
5
|
|
|
5
6
|
interface SeamPaginatorParent {
|
|
6
7
|
readonly client: Client
|
|
@@ -96,27 +97,38 @@ export class SeamPaginator<
|
|
|
96
97
|
})
|
|
97
98
|
|
|
98
99
|
const response = await request.fetchResponse()
|
|
99
|
-
const data = response
|
|
100
|
+
const data = readResponseData(response, responseKey, request.pathname)
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
?
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const pagination: Pagination = {
|
|
109
|
-
hasNextPage: paginationData?.has_next_page ?? false,
|
|
110
|
-
nextPageCursor: paginationData?.next_page_cursor ?? null,
|
|
111
|
-
nextPageUrl: paginationData?.next_page_url ?? null,
|
|
102
|
+
if (!Array.isArray(data)) {
|
|
103
|
+
throw new SeamHttpInvalidResponseError(
|
|
104
|
+
request.pathname,
|
|
105
|
+
String(responseKey),
|
|
106
|
+
`got ${data === null ? 'null' : typeof data} instead of a list`,
|
|
107
|
+
)
|
|
112
108
|
}
|
|
113
109
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
const paginationData = readResponseData(
|
|
111
|
+
response as { pagination: unknown },
|
|
112
|
+
'pagination',
|
|
113
|
+
request.pathname,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
if (paginationData === null || typeof paginationData !== 'object') {
|
|
117
|
+
throw new SeamHttpInvalidResponseError(
|
|
118
|
+
request.pathname,
|
|
119
|
+
'pagination',
|
|
120
|
+
`got ${paginationData === null ? 'null' : typeof paginationData} instead of a pagination object`,
|
|
117
121
|
)
|
|
118
122
|
}
|
|
119
123
|
|
|
124
|
+
const paginationResponse = paginationData as PaginationData
|
|
125
|
+
|
|
126
|
+
const pagination: Pagination = {
|
|
127
|
+
hasNextPage: paginationResponse.has_next_page ?? false,
|
|
128
|
+
nextPageCursor: paginationResponse.next_page_cursor ?? null,
|
|
129
|
+
nextPageUrl: paginationResponse.next_page_url ?? null,
|
|
130
|
+
}
|
|
131
|
+
|
|
120
132
|
return [
|
|
121
133
|
data as EnsureReadonlyArray<TResponse[TResponseKey]>,
|
|
122
134
|
pagination,
|
package/src/lib/version.ts
CHANGED