@seamapi/http 0.2.1 → 0.4.0
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/connect.cjs +106 -1
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +157 -124
- package/lib/seam/connect/api-error-type.d.ts +8 -0
- package/lib/seam/connect/api-error-type.js +3 -0
- package/lib/seam/connect/api-error-type.js.map +1 -0
- package/lib/seam/connect/client.js +6 -0
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/error-interceptor.d.ts +1 -0
- package/lib/seam/connect/error-interceptor.js +43 -0
- package/lib/seam/connect/error-interceptor.js.map +1 -0
- package/lib/seam/connect/index.d.ts +4 -1
- package/lib/seam/connect/index.js +4 -1
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/parse-options.js +6 -0
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +7 -7
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/access-codes.d.ts +10 -10
- package/lib/seam/connect/routes/access-codes.js.map +1 -1
- package/lib/seam/connect/routes/acs-access-groups.d.ts +11 -11
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
- package/lib/seam/connect/routes/acs-credentials.d.ts +6 -6
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
- package/lib/seam/connect/routes/acs-systems.d.ts +4 -4
- package/lib/seam/connect/routes/acs-systems.js.map +1 -1
- package/lib/seam/connect/routes/acs-users.d.ts +11 -11
- package/lib/seam/connect/routes/acs-users.js.map +1 -1
- package/lib/seam/connect/routes/action-attempts.d.ts +4 -4
- package/lib/seam/connect/routes/action-attempts.js.map +1 -1
- package/lib/seam/connect/routes/client-sessions.d.ts +8 -8
- package/lib/seam/connect/routes/client-sessions.js.map +1 -1
- package/lib/seam/connect/routes/connect-webviews.d.ts +6 -6
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
- package/lib/seam/connect/routes/connected-accounts.d.ts +3 -3
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +5 -5
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/devices.d.ts +8 -8
- package/lib/seam/connect/routes/devices.js.map +1 -1
- package/lib/seam/connect/routes/events.d.ts +4 -4
- package/lib/seam/connect/routes/events.js.map +1 -1
- package/lib/seam/connect/routes/locks.d.ts +6 -6
- package/lib/seam/connect/routes/locks.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +7 -7
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +7 -7
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
- package/lib/seam/connect/routes/thermostats.d.ts +10 -10
- package/lib/seam/connect/routes/thermostats.js.map +1 -1
- package/lib/seam/connect/routes/webhooks.d.ts +4 -4
- package/lib/seam/connect/routes/webhooks.js.map +1 -1
- package/lib/seam/connect/routes/workspaces.d.ts +1 -1
- package/lib/seam/connect/routes/workspaces.js.map +1 -1
- package/lib/seam/connect/seam-http-error.d.ts +20 -0
- package/lib/seam/connect/seam-http-error.js +43 -0
- package/lib/seam/connect/seam-http-error.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.js +3 -0
- package/lib/version.js.map +1 -0
- package/package.json +5 -2
- package/src/lib/seam/connect/api-error-type.ts +11 -0
- package/src/lib/seam/connect/client.ts +9 -0
- package/src/lib/seam/connect/error-interceptor.ts +61 -0
- package/src/lib/seam/connect/index.ts +4 -1
- package/src/lib/seam/connect/parse-options.ts +8 -0
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +7 -7
- package/src/lib/seam/connect/routes/access-codes.ts +10 -10
- package/src/lib/seam/connect/routes/acs-access-groups.ts +12 -11
- package/src/lib/seam/connect/routes/acs-credentials.ts +6 -6
- package/src/lib/seam/connect/routes/acs-systems.ts +4 -4
- package/src/lib/seam/connect/routes/acs-users.ts +13 -11
- package/src/lib/seam/connect/routes/action-attempts.ts +4 -4
- package/src/lib/seam/connect/routes/client-sessions.ts +8 -8
- package/src/lib/seam/connect/routes/connect-webviews.ts +7 -6
- package/src/lib/seam/connect/routes/connected-accounts.ts +3 -3
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +6 -5
- package/src/lib/seam/connect/routes/devices.ts +10 -8
- package/src/lib/seam/connect/routes/events.ts +4 -4
- package/src/lib/seam/connect/routes/locks.ts +6 -6
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +7 -7
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +7 -7
- package/src/lib/seam/connect/routes/thermostats.ts +10 -10
- package/src/lib/seam/connect/routes/webhooks.ts +4 -4
- package/src/lib/seam/connect/routes/workspaces.ts +1 -1
- package/src/lib/seam/connect/seam-http-error.ts +64 -0
- package/src/lib/version.ts +3 -0
package/dist/connect.cjs
CHANGED
|
@@ -1,13 +1,98 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var axios = require('axios');
|
|
4
|
+
var axiosBetterStacktrace = require('axios-better-stacktrace');
|
|
4
5
|
var axiosRetry = require('axios-retry');
|
|
5
6
|
|
|
6
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
8
|
|
|
8
9
|
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
10
|
+
var axiosBetterStacktrace__default = /*#__PURE__*/_interopDefault(axiosBetterStacktrace);
|
|
9
11
|
var axiosRetry__default = /*#__PURE__*/_interopDefault(axiosRetry);
|
|
10
12
|
|
|
13
|
+
// src/lib/seam/connect/error-interceptor.ts
|
|
14
|
+
|
|
15
|
+
// src/lib/seam/connect/seam-http-error.ts
|
|
16
|
+
var SeamHttpApiError = class extends Error {
|
|
17
|
+
constructor(error, statusCode, requestId) {
|
|
18
|
+
const { type, message, data } = error;
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = this.constructor.name;
|
|
21
|
+
Error.captureStackTrace(this, this.constructor);
|
|
22
|
+
this.code = type;
|
|
23
|
+
this.statusCode = statusCode;
|
|
24
|
+
this.requestId = requestId;
|
|
25
|
+
if (data != null)
|
|
26
|
+
this.data = data;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var isSeamHttpApiError = (error) => {
|
|
30
|
+
return error instanceof SeamHttpApiError;
|
|
31
|
+
};
|
|
32
|
+
var SeamHttpUnauthorizedError = class extends SeamHttpApiError {
|
|
33
|
+
constructor(requestId) {
|
|
34
|
+
const type = "unauthorized";
|
|
35
|
+
const status = 401;
|
|
36
|
+
super({ type, message: "Unauthorized" }, status, requestId);
|
|
37
|
+
this.name = this.constructor.name;
|
|
38
|
+
Error.captureStackTrace(this, this.constructor);
|
|
39
|
+
this.code = type;
|
|
40
|
+
this.statusCode = status;
|
|
41
|
+
this.requestId = requestId;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var isSeamHttpUnauthorizedError = (error) => {
|
|
45
|
+
return error instanceof SeamHttpUnauthorizedError;
|
|
46
|
+
};
|
|
47
|
+
var SeamHttpInvalidInputError = class extends SeamHttpApiError {
|
|
48
|
+
constructor(error, statusCode, requestId) {
|
|
49
|
+
super(error, statusCode, requestId);
|
|
50
|
+
this.name = this.constructor.name;
|
|
51
|
+
Error.captureStackTrace(this, this.constructor);
|
|
52
|
+
this.code = "invalid_input";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var isSeamHttpInvalidInputError = (error) => {
|
|
56
|
+
return error instanceof SeamHttpInvalidInputError;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/lib/seam/connect/error-interceptor.ts
|
|
60
|
+
var errorInterceptor = async (err) => {
|
|
61
|
+
if (!axios.isAxiosError(err))
|
|
62
|
+
throw err;
|
|
63
|
+
const { response } = err;
|
|
64
|
+
const status = response?.status;
|
|
65
|
+
const headers = response?.headers;
|
|
66
|
+
const requestId = headers?.["seam-request-id"] ?? "";
|
|
67
|
+
if (status == null)
|
|
68
|
+
throw err;
|
|
69
|
+
if (status === 401) {
|
|
70
|
+
throw new SeamHttpUnauthorizedError(requestId);
|
|
71
|
+
}
|
|
72
|
+
if (!isApiErrorResponse(response))
|
|
73
|
+
throw err;
|
|
74
|
+
const { type } = response.data.error;
|
|
75
|
+
const args = [response.data.error, status, requestId];
|
|
76
|
+
if (type === "invalid_input")
|
|
77
|
+
throw new SeamHttpInvalidInputError(...args);
|
|
78
|
+
throw new SeamHttpApiError(...args);
|
|
79
|
+
};
|
|
80
|
+
var isApiErrorResponse = (response) => {
|
|
81
|
+
if (response == null)
|
|
82
|
+
return false;
|
|
83
|
+
const { headers, data } = response;
|
|
84
|
+
if (headers == null)
|
|
85
|
+
return false;
|
|
86
|
+
const contentType = headers["content-type"];
|
|
87
|
+
if (typeof contentType === "string" && !contentType.startsWith("application/json")) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (typeof data === "object" && data != null) {
|
|
91
|
+
return "error" in data && typeof data.error === "object" && data.error != null && "type" in data.error && typeof data.error.type === "string";
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
};
|
|
95
|
+
|
|
11
96
|
// src/lib/seam/connect/options.ts
|
|
12
97
|
var isSeamHttpOptionsWithClient = (options) => {
|
|
13
98
|
if (!("client" in options))
|
|
@@ -241,16 +326,26 @@ var createClient = (options) => {
|
|
|
241
326
|
paramsSerializer,
|
|
242
327
|
...options.axiosOptions
|
|
243
328
|
});
|
|
329
|
+
axiosBetterStacktrace__default.default(axios__default.default);
|
|
244
330
|
axiosRetry__default.default(client, {
|
|
245
331
|
retries: 2,
|
|
246
332
|
retryDelay: axiosRetry.exponentialDelay,
|
|
247
333
|
...options.axiosRetryOptions
|
|
248
334
|
});
|
|
335
|
+
client.interceptors.response.use(void 0, errorInterceptor);
|
|
249
336
|
return client;
|
|
250
337
|
};
|
|
251
338
|
|
|
339
|
+
// src/lib/version.ts
|
|
340
|
+
var seamapiJavascriptHttpVersion = null;
|
|
341
|
+
var version_default = seamapiJavascriptHttpVersion;
|
|
342
|
+
|
|
252
343
|
// src/lib/seam/connect/parse-options.ts
|
|
253
344
|
var defaultEndpoint = "https://connect.getseam.com";
|
|
345
|
+
var sdkHeaders = {
|
|
346
|
+
"seam-sdk-name": "seamapi/javascript-http",
|
|
347
|
+
"seam-sdk-version": version_default
|
|
348
|
+
};
|
|
254
349
|
var parseOptions = (apiKeyOrOptions) => {
|
|
255
350
|
const options = getNormalizedOptions(apiKeyOrOptions);
|
|
256
351
|
if (isSeamHttpOptionsWithClient(options))
|
|
@@ -262,7 +357,8 @@ var parseOptions = (apiKeyOrOptions) => {
|
|
|
262
357
|
...options.axiosOptions,
|
|
263
358
|
headers: {
|
|
264
359
|
...getAuthHeaders(options),
|
|
265
|
-
...options.axiosOptions?.headers
|
|
360
|
+
...options.axiosOptions?.headers,
|
|
361
|
+
...sdkHeaders
|
|
266
362
|
}
|
|
267
363
|
},
|
|
268
364
|
axiosRetryOptions: {
|
|
@@ -1930,22 +2026,31 @@ exports.SeamHttpAcsCredentials = SeamHttpAcsCredentials;
|
|
|
1930
2026
|
exports.SeamHttpAcsSystems = SeamHttpAcsSystems;
|
|
1931
2027
|
exports.SeamHttpAcsUsers = SeamHttpAcsUsers;
|
|
1932
2028
|
exports.SeamHttpActionAttempts = SeamHttpActionAttempts;
|
|
2029
|
+
exports.SeamHttpApiError = SeamHttpApiError;
|
|
1933
2030
|
exports.SeamHttpClientSessions = SeamHttpClientSessions;
|
|
1934
2031
|
exports.SeamHttpConnectWebviews = SeamHttpConnectWebviews;
|
|
1935
2032
|
exports.SeamHttpConnectedAccounts = SeamHttpConnectedAccounts;
|
|
1936
2033
|
exports.SeamHttpDevices = SeamHttpDevices;
|
|
1937
2034
|
exports.SeamHttpDevicesUnmanaged = SeamHttpDevicesUnmanaged;
|
|
1938
2035
|
exports.SeamHttpEvents = SeamHttpEvents;
|
|
2036
|
+
exports.SeamHttpInvalidInputError = SeamHttpInvalidInputError;
|
|
1939
2037
|
exports.SeamHttpInvalidOptionsError = SeamHttpInvalidOptionsError;
|
|
1940
2038
|
exports.SeamHttpLocks = SeamHttpLocks;
|
|
1941
2039
|
exports.SeamHttpNoiseSensors = SeamHttpNoiseSensors;
|
|
1942
2040
|
exports.SeamHttpNoiseSensorsNoiseThresholds = SeamHttpNoiseSensorsNoiseThresholds;
|
|
1943
2041
|
exports.SeamHttpThermostats = SeamHttpThermostats;
|
|
1944
2042
|
exports.SeamHttpThermostatsClimateSettingSchedules = SeamHttpThermostatsClimateSettingSchedules;
|
|
2043
|
+
exports.SeamHttpUnauthorizedError = SeamHttpUnauthorizedError;
|
|
1945
2044
|
exports.SeamHttpWebhooks = SeamHttpWebhooks;
|
|
1946
2045
|
exports.SeamHttpWorkspaces = SeamHttpWorkspaces;
|
|
2046
|
+
exports.UnserializableParamError = UnserializableParamError;
|
|
2047
|
+
exports.errorInterceptor = errorInterceptor;
|
|
2048
|
+
exports.isSeamHttpApiError = isSeamHttpApiError;
|
|
2049
|
+
exports.isSeamHttpInvalidInputError = isSeamHttpInvalidInputError;
|
|
1947
2050
|
exports.isSeamHttpOptionsWithApiKey = isSeamHttpOptionsWithApiKey;
|
|
1948
2051
|
exports.isSeamHttpOptionsWithClient = isSeamHttpOptionsWithClient;
|
|
1949
2052
|
exports.isSeamHttpOptionsWithClientSessionToken = isSeamHttpOptionsWithClientSessionToken;
|
|
2053
|
+
exports.isSeamHttpUnauthorizedError = isSeamHttpUnauthorizedError;
|
|
2054
|
+
exports.paramsSerializer = paramsSerializer;
|
|
1950
2055
|
//# sourceMappingURL=out.js.map
|
|
1951
2056
|
//# sourceMappingURL=connect.cjs.map
|