@seamapi/http 0.1.0 → 0.2.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/connect.cjs +773 -366
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +225 -143
- package/lib/params-serializer.d.ts +5 -0
- package/lib/params-serializer.js +42 -0
- package/lib/params-serializer.js.map +1 -0
- package/lib/seam/connect/auth.d.ts +3 -2
- package/lib/seam/connect/auth.js +55 -4
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/client.d.ts +10 -22
- package/lib/seam/connect/client.js +17 -77
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/index.d.ts +3 -1
- package/lib/seam/connect/index.js +3 -1
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/{client-options.d.ts → options.d.ts} +9 -7
- package/lib/seam/connect/{client-options.js → options.js} +5 -10
- package/lib/seam/connect/options.js.map +1 -0
- package/lib/seam/connect/parse-options.d.ts +6 -2
- package/lib/seam/connect/parse-options.js +34 -16
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +10 -9
- package/lib/seam/connect/routes/access-codes-unmanaged.js +26 -14
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/access-codes.d.ts +15 -14
- package/lib/seam/connect/routes/access-codes.js +29 -17
- package/lib/seam/connect/routes/access-codes.js.map +1 -1
- package/lib/seam/connect/routes/acs-access-groups.d.ts +13 -12
- package/lib/seam/connect/routes/acs-access-groups.js +26 -14
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
- package/lib/seam/connect/routes/acs-credentials.d.ts +9 -8
- package/lib/seam/connect/routes/acs-credentials.js +26 -14
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
- package/lib/seam/connect/routes/acs-systems.d.ts +9 -8
- package/lib/seam/connect/routes/acs-systems.js +29 -17
- package/lib/seam/connect/routes/acs-systems.js.map +1 -1
- package/lib/seam/connect/routes/acs-users.d.ts +18 -11
- package/lib/seam/connect/routes/acs-users.js +40 -14
- package/lib/seam/connect/routes/acs-users.js.map +1 -1
- package/lib/seam/connect/routes/acs.d.ts +5 -4
- package/lib/seam/connect/routes/acs.js +26 -14
- package/lib/seam/connect/routes/acs.js.map +1 -1
- package/lib/seam/connect/routes/action-attempts.d.ts +7 -6
- package/lib/seam/connect/routes/action-attempts.js +26 -14
- package/lib/seam/connect/routes/action-attempts.js.map +1 -1
- package/lib/seam/connect/routes/client-sessions.d.ts +13 -9
- package/lib/seam/connect/routes/client-sessions.js +33 -14
- package/lib/seam/connect/routes/client-sessions.js.map +1 -1
- package/lib/seam/connect/routes/connect-webviews.d.ts +11 -10
- package/lib/seam/connect/routes/connect-webviews.js +29 -17
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
- package/lib/seam/connect/routes/connected-accounts.d.ts +8 -7
- package/lib/seam/connect/routes/connected-accounts.js +26 -14
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +8 -7
- package/lib/seam/connect/routes/devices-unmanaged.js +26 -14
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/devices.d.ts +10 -9
- package/lib/seam/connect/routes/devices.js +26 -14
- package/lib/seam/connect/routes/devices.js.map +1 -1
- package/lib/seam/connect/routes/events.d.ts +7 -6
- package/lib/seam/connect/routes/events.js +26 -14
- package/lib/seam/connect/routes/events.js.map +1 -1
- package/lib/seam/connect/routes/locks.d.ts +9 -8
- package/lib/seam/connect/routes/locks.js +26 -14
- package/lib/seam/connect/routes/locks.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +10 -9
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +26 -14
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors.d.ts +5 -4
- package/lib/seam/connect/routes/noise-sensors.js +26 -14
- package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +10 -9
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +26 -14
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
- package/lib/seam/connect/routes/thermostats.d.ts +13 -12
- package/lib/seam/connect/routes/thermostats.js +26 -14
- package/lib/seam/connect/routes/thermostats.js.map +1 -1
- package/lib/seam/connect/routes/webhooks.d.ts +9 -8
- package/lib/seam/connect/routes/webhooks.js +26 -14
- package/lib/seam/connect/routes/webhooks.js.map +1 -1
- package/lib/seam/connect/routes/workspaces.d.ts +8 -7
- package/lib/seam/connect/routes/workspaces.js +26 -14
- package/lib/seam/connect/routes/workspaces.js.map +1 -1
- package/lib/seam/connect/seam-http.d.ts +24 -0
- package/lib/seam/connect/seam-http.js +82 -0
- package/lib/seam/connect/seam-http.js.map +1 -0
- package/package.json +9 -4
- package/src/lib/params-serializer.ts +55 -0
- package/src/lib/seam/connect/auth.ts +94 -6
- package/src/lib/seam/connect/client.ts +22 -127
- package/src/lib/seam/connect/env.d.ts +11 -0
- package/src/lib/seam/connect/index.ts +3 -1
- package/src/lib/seam/connect/{client-options.ts → options.ts} +14 -19
- package/src/lib/seam/connect/parse-options.ts +50 -23
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +44 -31
- package/src/lib/seam/connect/routes/access-codes.ts +48 -48
- package/src/lib/seam/connect/routes/acs-access-groups.ts +49 -40
- package/src/lib/seam/connect/routes/acs-credentials.ts +40 -28
- package/src/lib/seam/connect/routes/acs-systems.ts +40 -30
- package/src/lib/seam/connect/routes/acs-users.ts +70 -36
- package/src/lib/seam/connect/routes/acs.ts +33 -17
- package/src/lib/seam/connect/routes/action-attempts.ts +36 -22
- package/src/lib/seam/connect/routes/client-sessions.ts +58 -30
- package/src/lib/seam/connect/routes/connect-webviews.ts +45 -34
- package/src/lib/seam/connect/routes/connected-accounts.ts +40 -25
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +39 -25
- package/src/lib/seam/connect/routes/devices.ts +39 -31
- package/src/lib/seam/connect/routes/events.ts +36 -22
- package/src/lib/seam/connect/routes/locks.ts +38 -28
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +47 -31
- package/src/lib/seam/connect/routes/noise-sensors.ts +33 -17
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +47 -31
- package/src/lib/seam/connect/routes/thermostats.ts +42 -40
- package/src/lib/seam/connect/routes/webhooks.ts +38 -28
- package/src/lib/seam/connect/routes/workspaces.ts +38 -25
- package/src/lib/seam/connect/seam-http.ts +141 -0
- package/lib/seam/connect/axios.d.ts +0 -3
- package/lib/seam/connect/axios.js +0 -19
- package/lib/seam/connect/axios.js.map +0 -1
- package/lib/seam/connect/client-options.js.map +0 -1
- package/src/lib/seam/connect/axios.ts +0 -25
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const paramsSerializer = (params) => {
|
|
2
|
+
const searchParams = new URLSearchParams();
|
|
3
|
+
for (const [name, value] of Object.entries(params)) {
|
|
4
|
+
if (value == null)
|
|
5
|
+
continue;
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
if (value.length === 0)
|
|
8
|
+
searchParams.set(name, '');
|
|
9
|
+
if (value.length === 1 && value[0] === '') {
|
|
10
|
+
throw new UnserializableParamError(name, `is a single element array containing the empty string which is unsupported because it serializes to the empty array`);
|
|
11
|
+
}
|
|
12
|
+
for (const v of value) {
|
|
13
|
+
throwIfUnserializable(name, v);
|
|
14
|
+
searchParams.append(name, v);
|
|
15
|
+
}
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
throwIfUnserializable(name, value);
|
|
19
|
+
searchParams.set(name, value);
|
|
20
|
+
}
|
|
21
|
+
searchParams.sort();
|
|
22
|
+
return searchParams.toString();
|
|
23
|
+
};
|
|
24
|
+
const throwIfUnserializable = (k, v) => {
|
|
25
|
+
if (v == null) {
|
|
26
|
+
throw new UnserializableParamError(k, `is ${v} or contains ${v}`);
|
|
27
|
+
}
|
|
28
|
+
if (typeof v === 'function') {
|
|
29
|
+
throw new UnserializableParamError(k, 'is a function or contains a function');
|
|
30
|
+
}
|
|
31
|
+
if (typeof v === 'object') {
|
|
32
|
+
throw new UnserializableParamError(k, 'is an object or contains an object');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
export class UnserializableParamError extends Error {
|
|
36
|
+
constructor(name, message) {
|
|
37
|
+
super(`Could not serialize parameter: '${name}' ${message}`);
|
|
38
|
+
this.name = this.constructor.name;
|
|
39
|
+
Error.captureStackTrace(this, this.constructor);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=params-serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params-serializer.js","sourceRoot":"","sources":["../src/lib/params-serializer.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAA2B,CAAC,MAAM,EAAE,EAAE;IACjE,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAA;IAE1C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAClD,IAAI,KAAK,IAAI,IAAI;YAAE,SAAQ;QAE3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;YAClD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;gBACzC,MAAM,IAAI,wBAAwB,CAChC,IAAI,EACJ,qHAAqH,CACtH,CAAA;aACF;YACD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;gBACrB,qBAAqB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;gBAC9B,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;aAC7B;YACD,SAAQ;SACT;QAED,qBAAqB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAClC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;KAC9B;IAED,YAAY,CAAC,IAAI,EAAE,CAAA;IACnB,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAM,qBAAqB,GAAG,CAAC,CAAS,EAAE,CAAU,EAAQ,EAAE;IAC5D,IAAI,CAAC,IAAI,IAAI,EAAE;QACb,MAAM,IAAI,wBAAwB,CAAC,CAAC,EAAE,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAA;KAClE;IAED,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;QAC3B,MAAM,IAAI,wBAAwB,CAChC,CAAC,EACD,sCAAsC,CACvC,CAAA;KACF;IAED,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;QACzB,MAAM,IAAI,wBAAwB,CAAC,CAAC,EAAE,oCAAoC,CAAC,CAAA;KAC5E;AACH,CAAC,CAAA;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,mCAAmC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAA;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;QACjC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACjD,CAAC;CACF"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Options } from './parse-options.js';
|
|
2
2
|
type Headers = Record<string, string>;
|
|
3
|
-
export declare const getAuthHeaders: (options:
|
|
3
|
+
export declare const getAuthHeaders: (options: Options) => Headers;
|
|
4
4
|
export declare class SeamHttpInvalidTokenError extends Error {
|
|
5
5
|
constructor(message: string);
|
|
6
6
|
}
|
|
7
|
+
export declare const warnOnInsecureuserIdentifierKey: (userIdentifierKey: string) => void;
|
|
7
8
|
export {};
|
package/lib/seam/connect/auth.js
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
|
-
import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClientSessionToken, SeamHttpInvalidOptionsError, } from './
|
|
1
|
+
import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClientSessionToken, SeamHttpInvalidOptionsError, } from './options.js';
|
|
2
2
|
export const getAuthHeaders = (options) => {
|
|
3
|
+
if ('publishableKey' in options) {
|
|
4
|
+
return getAuthHeadersForPublishableKey(options.publishableKey);
|
|
5
|
+
}
|
|
3
6
|
if (isSeamHttpOptionsWithApiKey(options)) {
|
|
4
7
|
return getAuthHeadersForApiKey(options);
|
|
5
8
|
}
|
|
6
9
|
if (isSeamHttpOptionsWithClientSessionToken(options)) {
|
|
7
10
|
return getAuthHeadersForClientSessionToken(options);
|
|
8
11
|
}
|
|
9
|
-
throw new SeamHttpInvalidOptionsError('Must specify an apiKey or
|
|
12
|
+
throw new SeamHttpInvalidOptionsError('Must specify an apiKey, clientSessionToken, or publishableKey');
|
|
10
13
|
};
|
|
11
14
|
const getAuthHeadersForApiKey = ({ apiKey, }) => {
|
|
12
15
|
if (isClientSessionToken(apiKey)) {
|
|
13
16
|
throw new SeamHttpInvalidTokenError('A Client Session Token cannot be used as an apiKey');
|
|
14
17
|
}
|
|
18
|
+
if (isJwt(apiKey)) {
|
|
19
|
+
throw new SeamHttpInvalidTokenError('A JWT cannot be used as an apiKey');
|
|
20
|
+
}
|
|
15
21
|
if (isAccessToken(apiKey)) {
|
|
16
|
-
throw new SeamHttpInvalidTokenError('An
|
|
22
|
+
throw new SeamHttpInvalidTokenError('An Access Token cannot be used as an apiKey');
|
|
17
23
|
}
|
|
18
|
-
if (
|
|
24
|
+
if (isPublishableKey(apiKey)) {
|
|
25
|
+
throw new SeamHttpInvalidTokenError('A Publishable Key cannot be used as an apiKey');
|
|
26
|
+
}
|
|
27
|
+
if (!isSeamToken(apiKey)) {
|
|
19
28
|
throw new SeamHttpInvalidTokenError(`Unknown or invalid apiKey format, expected token to start with ${tokenPrefix}`);
|
|
20
29
|
}
|
|
21
30
|
return {
|
|
@@ -23,6 +32,15 @@ const getAuthHeadersForApiKey = ({ apiKey, }) => {
|
|
|
23
32
|
};
|
|
24
33
|
};
|
|
25
34
|
const getAuthHeadersForClientSessionToken = ({ clientSessionToken, }) => {
|
|
35
|
+
if (isJwt(clientSessionToken)) {
|
|
36
|
+
throw new SeamHttpInvalidTokenError('A JWT cannot be used as a clientSessionToken');
|
|
37
|
+
}
|
|
38
|
+
if (isAccessToken(clientSessionToken)) {
|
|
39
|
+
throw new SeamHttpInvalidTokenError('An Access Token cannot be used as a clientSessionToken');
|
|
40
|
+
}
|
|
41
|
+
if (isPublishableKey(clientSessionToken)) {
|
|
42
|
+
throw new SeamHttpInvalidTokenError('A Publishable Key cannot be used as a clientSessionToken');
|
|
43
|
+
}
|
|
26
44
|
if (!isClientSessionToken(clientSessionToken)) {
|
|
27
45
|
throw new SeamHttpInvalidTokenError(`Unknown or invalid clientSessionToken format, expected token to start with ${clientSessionTokenPrefix}`);
|
|
28
46
|
}
|
|
@@ -31,6 +49,23 @@ const getAuthHeadersForClientSessionToken = ({ clientSessionToken, }) => {
|
|
|
31
49
|
'client-session-token': clientSessionToken,
|
|
32
50
|
};
|
|
33
51
|
};
|
|
52
|
+
const getAuthHeadersForPublishableKey = (publishableKey) => {
|
|
53
|
+
if (isJwt(publishableKey)) {
|
|
54
|
+
throw new SeamHttpInvalidTokenError('A JWT cannot be used as a publishableKey');
|
|
55
|
+
}
|
|
56
|
+
if (isAccessToken(publishableKey)) {
|
|
57
|
+
throw new SeamHttpInvalidTokenError('An Access Token cannot be used as a publishableKey');
|
|
58
|
+
}
|
|
59
|
+
if (isClientSessionToken(publishableKey)) {
|
|
60
|
+
throw new SeamHttpInvalidTokenError('A Client Session Token Key cannot be used as a publishableKey');
|
|
61
|
+
}
|
|
62
|
+
if (!isPublishableKey(publishableKey)) {
|
|
63
|
+
throw new SeamHttpInvalidTokenError(`Unknown or invalid publishableKey format, expected token to start with ${publishableKeyTokenPrefix}`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
'seam-publishable-key': publishableKey,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
34
69
|
export class SeamHttpInvalidTokenError extends Error {
|
|
35
70
|
constructor(message) {
|
|
36
71
|
super(`SeamHttp received an invalid token: ${message}`);
|
|
@@ -38,10 +73,26 @@ export class SeamHttpInvalidTokenError extends Error {
|
|
|
38
73
|
Error.captureStackTrace(this, this.constructor);
|
|
39
74
|
}
|
|
40
75
|
}
|
|
76
|
+
export const warnOnInsecureuserIdentifierKey = (userIdentifierKey) => {
|
|
77
|
+
if (isEmail(userIdentifierKey)) {
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.warn(...[
|
|
80
|
+
'Using an email for the userIdentifierKey is insecure and may return an error in the future!',
|
|
81
|
+
'This is insecure because an email is common knowledge or easily guessed.',
|
|
82
|
+
'Use something with sufficient entropy known only to the owner of the client session.',
|
|
83
|
+
'For help choosing a user identifier key see',
|
|
84
|
+
'https://docs.seam.co/latest/seam-components/overview/get-started-with-client-side-components#3-select-a-user-identifier-key',
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
41
88
|
const tokenPrefix = 'seam_';
|
|
42
89
|
const clientSessionTokenPrefix = 'seam_cst';
|
|
90
|
+
const publishableKeyTokenPrefix = 'seam_pk';
|
|
43
91
|
const isClientSessionToken = (token) => token.startsWith(clientSessionTokenPrefix);
|
|
44
92
|
const isAccessToken = (token) => token.startsWith('seam_at');
|
|
45
93
|
const isJwt = (token) => token.startsWith('ey');
|
|
46
94
|
const isSeamToken = (token) => token.startsWith(tokenPrefix);
|
|
95
|
+
const isPublishableKey = (token) => token.startsWith(publishableKeyTokenPrefix);
|
|
96
|
+
// SOURCE: https://stackoverflow.com/a/46181
|
|
97
|
+
const isEmail = (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
47
98
|
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,uCAAuC,EACvC,2BAA2B,
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,uCAAuC,EACvC,2BAA2B,GAG5B,MAAM,cAAc,CAAA;AAKrB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAgB,EAAW,EAAE;IAC1D,IAAI,gBAAgB,IAAI,OAAO,EAAE;QAC/B,OAAO,+BAA+B,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;KAC/D;IAED,IAAI,2BAA2B,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAuB,CAAC,OAAO,CAAC,CAAA;KACxC;IAED,IAAI,uCAAuC,CAAC,OAAO,CAAC,EAAE;QACpD,OAAO,mCAAmC,CAAC,OAAO,CAAC,CAAA;KACpD;IAED,MAAM,IAAI,2BAA2B,CACnC,+DAA+D,CAChE,CAAA;AACH,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,CAAC,EAC/B,MAAM,GACoB,EAAW,EAAE;IACvC,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE;QAChC,MAAM,IAAI,yBAAyB,CACjC,oDAAoD,CACrD,CAAA;KACF;IAED,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE;QACjB,MAAM,IAAI,yBAAyB,CAAC,mCAAmC,CAAC,CAA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AAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAEhE,MAAM,WAAW,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AAE7E,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAW,EAAE,CAClD,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAA;AAE7C,4CAA4C;AAC5C,MAAM,OAAO,GAAG,CAAC,KAAa,EAAW,EAAE,CACzC,4BAA4B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA"}
|
|
@@ -1,23 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
static fromApiKey(apiKey: SeamHttpOptionsWithApiKey['apiKey'], options?: Omit<SeamHttpOptionsWithApiKey, 'apiKey'>): SeamHttp;
|
|
9
|
-
static fromClientSessionToken(clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options?: Omit<SeamHttpOptionsWithClientSessionToken, 'clientSessionToken'>): SeamHttp;
|
|
10
|
-
get accessCodes(): SeamHttpAccessCodes;
|
|
11
|
-
get acs(): SeamHttpAcs;
|
|
12
|
-
get actionAttempts(): SeamHttpActionAttempts;
|
|
13
|
-
get clientSessions(): SeamHttpClientSessions;
|
|
14
|
-
get connectedAccounts(): SeamHttpConnectedAccounts;
|
|
15
|
-
get connectWebviews(): SeamHttpConnectWebviews;
|
|
16
|
-
get devices(): SeamHttpDevices;
|
|
17
|
-
get events(): SeamHttpEvents;
|
|
18
|
-
get locks(): SeamHttpLocks;
|
|
19
|
-
get noiseSensors(): SeamHttpNoiseSensors;
|
|
20
|
-
get thermostats(): SeamHttpThermostats;
|
|
21
|
-
get webhooks(): SeamHttpWebhooks;
|
|
22
|
-
get workspaces(): SeamHttpWorkspaces;
|
|
1
|
+
import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { type AxiosRetry } from 'axios-retry';
|
|
3
|
+
export type Client = AxiosInstance;
|
|
4
|
+
export interface ClientOptions {
|
|
5
|
+
axiosOptions?: AxiosRequestConfig;
|
|
6
|
+
axiosRetryOptions?: AxiosRetryConfig;
|
|
7
|
+
client?: Client;
|
|
23
8
|
}
|
|
9
|
+
type AxiosRetryConfig = Parameters<AxiosRetry>[1];
|
|
10
|
+
export declare const createClient: (options: ClientOptions) => AxiosInstance;
|
|
11
|
+
export {};
|
|
@@ -1,78 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
static fromApiKey(apiKey, options = {}) {
|
|
20
|
-
const opts = { ...options, apiKey };
|
|
21
|
-
if (!isSeamHttpOptionsWithApiKey(opts)) {
|
|
22
|
-
throw new SeamHttpInvalidOptionsError('Missing apiKey');
|
|
23
|
-
}
|
|
24
|
-
return new SeamHttp(opts);
|
|
25
|
-
}
|
|
26
|
-
static fromClientSessionToken(clientSessionToken, options = {}) {
|
|
27
|
-
const opts = { ...options, clientSessionToken };
|
|
28
|
-
if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
|
|
29
|
-
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken');
|
|
30
|
-
}
|
|
31
|
-
return new SeamHttp(opts);
|
|
32
|
-
}
|
|
33
|
-
get accessCodes() {
|
|
34
|
-
return SeamHttpAccessCodes.fromClient(this.client);
|
|
35
|
-
}
|
|
36
|
-
get acs() {
|
|
37
|
-
return SeamHttpAcs.fromClient(this.client);
|
|
38
|
-
}
|
|
39
|
-
get actionAttempts() {
|
|
40
|
-
return SeamHttpActionAttempts.fromClient(this.client);
|
|
41
|
-
}
|
|
42
|
-
get clientSessions() {
|
|
43
|
-
return SeamHttpClientSessions.fromClient(this.client);
|
|
44
|
-
}
|
|
45
|
-
get connectedAccounts() {
|
|
46
|
-
return SeamHttpConnectedAccounts.fromClient(this.client);
|
|
47
|
-
}
|
|
48
|
-
get connectWebviews() {
|
|
49
|
-
return SeamHttpConnectWebviews.fromClient(this.client);
|
|
50
|
-
}
|
|
51
|
-
get devices() {
|
|
52
|
-
return SeamHttpDevices.fromClient(this.client);
|
|
53
|
-
}
|
|
54
|
-
get events() {
|
|
55
|
-
return SeamHttpEvents.fromClient(this.client);
|
|
56
|
-
}
|
|
57
|
-
get locks() {
|
|
58
|
-
return SeamHttpLocks.fromClient(this.client);
|
|
59
|
-
}
|
|
60
|
-
get noiseSensors() {
|
|
61
|
-
return SeamHttpNoiseSensors.fromClient(this.client);
|
|
62
|
-
}
|
|
63
|
-
get thermostats() {
|
|
64
|
-
return SeamHttpThermostats.fromClient(this.client);
|
|
65
|
-
}
|
|
66
|
-
get webhooks() {
|
|
67
|
-
return SeamHttpWebhooks.fromClient(this.client);
|
|
68
|
-
}
|
|
69
|
-
get workspaces() {
|
|
70
|
-
return SeamHttpWorkspaces.fromClient(this.client);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// TODO
|
|
74
|
-
// static fromPublishableKey and deprecate getClientSessionToken
|
|
75
|
-
// TODO: Should we keep makeRequest?
|
|
76
|
-
// Better to implement error handling and wrapping in an error handler.
|
|
77
|
-
// makeRequest
|
|
1
|
+
import axios, {} from 'axios';
|
|
2
|
+
import axiosRetry, { exponentialDelay } from 'axios-retry';
|
|
3
|
+
import { paramsSerializer } from '../../../lib/params-serializer.js';
|
|
4
|
+
export const createClient = (options) => {
|
|
5
|
+
if (options.client != null)
|
|
6
|
+
return options.client;
|
|
7
|
+
const client = axios.create({
|
|
8
|
+
paramsSerializer,
|
|
9
|
+
...options.axiosOptions,
|
|
10
|
+
});
|
|
11
|
+
axiosRetry(client, {
|
|
12
|
+
retries: 2,
|
|
13
|
+
retryDelay: exponentialDelay,
|
|
14
|
+
...options.axiosRetryOptions,
|
|
15
|
+
});
|
|
16
|
+
return client;
|
|
17
|
+
};
|
|
78
18
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA+C,MAAM,OAAO,CAAA;AAC1E,OAAO,UAAU,EAAE,EAAmB,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAY3D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAsB,EAAiB,EAAE;IACpE,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI;QAAE,OAAO,OAAO,CAAC,MAAM,CAAA;IAEjD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC1B,gBAAgB;QAChB,GAAG,OAAO,CAAC,YAAY;KACxB,CAAC,CAAA;IAEF,UAAU,CAAC,MAAM,EAAE;QACjB,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,gBAAgB;QAC5B,GAAG,OAAO,CAAC,iBAAiB;KAC7B,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export type SeamHttpOptions = SeamHttpOptionsWithClient | SeamHttpOptionsWithApiKey | SeamHttpOptionsWithClientSessionToken;
|
|
3
|
-
interface SeamHttpCommonOptions {
|
|
1
|
+
import type { Client, ClientOptions } from './client.js';
|
|
2
|
+
export type SeamHttpOptions = SeamHttpOptionsFromEnv | SeamHttpOptionsWithClient | SeamHttpOptionsWithApiKey | SeamHttpOptionsWithClientSessionToken;
|
|
3
|
+
interface SeamHttpCommonOptions extends ClientOptions {
|
|
4
4
|
endpoint?: string;
|
|
5
|
-
axiosOptions?: AxiosRequestConfig;
|
|
6
|
-
enableLegacyMethodBehaivor?: boolean;
|
|
7
5
|
}
|
|
8
|
-
export interface
|
|
9
|
-
|
|
6
|
+
export interface SeamHttpFromPublishableKeyOptions extends SeamHttpCommonOptions {
|
|
7
|
+
}
|
|
8
|
+
export interface SeamHttpOptionsFromEnv extends SeamHttpCommonOptions {
|
|
9
|
+
}
|
|
10
|
+
export interface SeamHttpOptionsWithClient {
|
|
11
|
+
client: Client;
|
|
10
12
|
}
|
|
11
13
|
export declare const isSeamHttpOptionsWithClient: (options: SeamHttpOptions) => options is SeamHttpOptionsWithClient;
|
|
12
14
|
export interface SeamHttpOptionsWithApiKey extends SeamHttpCommonOptions {
|
|
@@ -3,9 +3,9 @@ export const isSeamHttpOptionsWithClient = (options) => {
|
|
|
3
3
|
return false;
|
|
4
4
|
if (options.client == null)
|
|
5
5
|
return false;
|
|
6
|
-
const keys = Object.keys(options).filter((k) =>
|
|
6
|
+
const keys = Object.keys(options).filter((k) => k !== 'client');
|
|
7
7
|
if (keys.length > 0) {
|
|
8
|
-
throw new SeamHttpInvalidOptionsError(`The client option cannot be used with any other option
|
|
8
|
+
throw new SeamHttpInvalidOptionsError(`The client option cannot be used with any other option, but received: ${keys.join(', ')}`);
|
|
9
9
|
}
|
|
10
10
|
return true;
|
|
11
11
|
};
|
|
@@ -15,7 +15,7 @@ export const isSeamHttpOptionsWithApiKey = (options) => {
|
|
|
15
15
|
if (options.apiKey == null)
|
|
16
16
|
return false;
|
|
17
17
|
if ('clientSessionToken' in options && options.clientSessionToken != null) {
|
|
18
|
-
throw new SeamHttpInvalidOptionsError('The clientSessionToken option cannot be used with the apiKey option
|
|
18
|
+
throw new SeamHttpInvalidOptionsError('The clientSessionToken option cannot be used with the apiKey option');
|
|
19
19
|
}
|
|
20
20
|
return true;
|
|
21
21
|
};
|
|
@@ -25,7 +25,7 @@ export const isSeamHttpOptionsWithClientSessionToken = (options) => {
|
|
|
25
25
|
if (options.clientSessionToken == null)
|
|
26
26
|
return false;
|
|
27
27
|
if ('apiKey' in options && options.apiKey != null) {
|
|
28
|
-
throw new SeamHttpInvalidOptionsError('The clientSessionToken option cannot be used with the apiKey option
|
|
28
|
+
throw new SeamHttpInvalidOptionsError('The clientSessionToken option cannot be used with the apiKey option');
|
|
29
29
|
}
|
|
30
30
|
return true;
|
|
31
31
|
};
|
|
@@ -36,9 +36,4 @@ export class SeamHttpInvalidOptionsError extends Error {
|
|
|
36
36
|
Error.captureStackTrace(this, this.constructor);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
// export interface SeamHttpOptionsWithSessionToken extends SeamHttpCommonOptions {
|
|
41
|
-
// workspaceId: string
|
|
42
|
-
// apiKey: string
|
|
43
|
-
// }
|
|
44
|
-
//# sourceMappingURL=client-options.js.map
|
|
39
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/options.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,OAAwB,EACc,EAAE;IACxC,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAA;IACxC,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI;QAAE,OAAO,KAAK,CAAA;IAExC,MAAM,I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IAAI,CAAA;QACjC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IACjD,CAAC;CACF"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { ClientOptions } from './client.js';
|
|
2
|
+
import { type SeamHttpOptions } from './options.js';
|
|
3
|
+
export type Options = SeamHttpOptions & {
|
|
4
|
+
publishableKey?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const parseOptions: (apiKeyOrOptions: string | Options) => ClientOptions;
|
|
@@ -1,27 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { getAuthHeaders } from './auth.js';
|
|
2
|
+
import { isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, } from './options.js';
|
|
3
|
+
const defaultEndpoint = 'https://connect.getseam.com';
|
|
3
4
|
export const parseOptions = (apiKeyOrOptions) => {
|
|
5
|
+
const options = getNormalizedOptions(apiKeyOrOptions);
|
|
6
|
+
if (isSeamHttpOptionsWithClient(options))
|
|
7
|
+
return options;
|
|
8
|
+
return {
|
|
9
|
+
axiosOptions: {
|
|
10
|
+
baseURL: options.endpoint ?? getEndpointFromEnv() ?? defaultEndpoint,
|
|
11
|
+
withCredentials: isSeamHttpOptionsWithClientSessionToken(options),
|
|
12
|
+
...options.axiosOptions,
|
|
13
|
+
headers: {
|
|
14
|
+
...getAuthHeaders(options),
|
|
15
|
+
...options.axiosOptions?.headers,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
axiosRetryOptions: {
|
|
19
|
+
...options.axiosRetryOptions,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const getNormalizedOptions = (apiKeyOrOptions) => {
|
|
4
24
|
const options = typeof apiKeyOrOptions === 'string'
|
|
5
25
|
? { apiKey: apiKeyOrOptions }
|
|
6
26
|
: apiKeyOrOptions;
|
|
7
27
|
if (isSeamHttpOptionsWithClient(options))
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
enableLegacyMethodBehaivor: options.enableLegacyMethodBehaivor ?? enableLegacyMethodBehaivorDefault,
|
|
11
|
-
};
|
|
12
|
-
const endpoint = options.endpoint ??
|
|
13
|
-
globalThis.process?.env?.['SEAM_ENDPOINT'] ??
|
|
14
|
-
globalThis.process?.env?.['SEAM_API_URL'] ??
|
|
15
|
-
'https://connect.getseam.com';
|
|
16
|
-
const apiKey = 'apiKey' in options
|
|
17
|
-
? options.apiKey
|
|
18
|
-
: globalThis.process?.env?.['SEAM_API_KEY'];
|
|
28
|
+
return options;
|
|
29
|
+
const apiKey = 'apiKey' in options ? options.apiKey : getApiKeyFromEnv(options);
|
|
19
30
|
return {
|
|
20
31
|
...options,
|
|
21
32
|
...(apiKey != null ? { apiKey } : {}),
|
|
22
|
-
endpoint,
|
|
23
|
-
axiosOptions: options.axiosOptions ?? {},
|
|
24
|
-
enableLegacyMethodBehaivor: options.enableLegacyMethodBehaivor ?? enableLegacyMethodBehaivorDefault,
|
|
25
33
|
};
|
|
26
34
|
};
|
|
35
|
+
const getApiKeyFromEnv = (options) => {
|
|
36
|
+
if ('clientSessionToken' in options && options.clientSessionToken != null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return globalThis.process?.env?.SEAM_API_KEY;
|
|
40
|
+
};
|
|
41
|
+
const getEndpointFromEnv = () => {
|
|
42
|
+
return (globalThis.process?.env?.SEAM_ENDPOINT ??
|
|
43
|
+
globalThis.process?.env?.SEAM_API_URL);
|
|
44
|
+
};
|
|
27
45
|
//# sourceMappingURL=parse-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-options.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/parse-options.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,
|
|
1
|
+
{"version":3,"file":"parse-options.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/parse-options.ts"],"names":[],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AC,CAAA;AAED,MAAM,gBAAgB,GAAG,CACvB,OAAwB,EACG,EAAE;IAC7B,IAAI,oBAAoB,IAAI,OAAO,IAAI,OAAO,CAAC,kBAAkB,IAAI,IAAI,EAAE;QACzE,OAAO,IAAI,CAAA;KACZ;IACD,OAAO,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,CAAA;AAC9C,CAAC,CAAA;AAED,MAAM,kBAAkB,GAAG,GAA8B,EAAE;IACzD,OAAO,CACL,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa;QACtC,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,YAAY,CACtC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect';
|
|
2
|
-
import type { Axios } from 'axios';
|
|
3
2
|
import type { SetNonNullable } from 'type-fest';
|
|
4
|
-
import { type
|
|
3
|
+
import { type Client } from '../../../../lib/seam/connect/client.js';
|
|
4
|
+
import { type SeamHttpFromPublishableKeyOptions, type SeamHttpOptions, type SeamHttpOptionsWithApiKey, type SeamHttpOptionsWithClient, type SeamHttpOptionsWithClientSessionToken } from '../../../../lib/seam/connect/options.js';
|
|
5
5
|
export declare class SeamHttpAccessCodesUnmanaged {
|
|
6
|
-
client:
|
|
7
|
-
constructor(apiKeyOrOptions
|
|
6
|
+
client: Client;
|
|
7
|
+
constructor(apiKeyOrOptions?: string | SeamHttpOptions);
|
|
8
8
|
static fromClient(client: SeamHttpOptionsWithClient['client'], options?: Omit<SeamHttpOptionsWithClient, 'client'>): SeamHttpAccessCodesUnmanaged;
|
|
9
9
|
static fromApiKey(apiKey: SeamHttpOptionsWithApiKey['apiKey'], options?: Omit<SeamHttpOptionsWithApiKey, 'apiKey'>): SeamHttpAccessCodesUnmanaged;
|
|
10
10
|
static fromClientSessionToken(clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'], options?: Omit<SeamHttpOptionsWithClientSessionToken, 'clientSessionToken'>): SeamHttpAccessCodesUnmanaged;
|
|
11
|
+
static fromPublishableKey(publishableKey: string, userIdentifierKey: string, options?: SeamHttpFromPublishableKeyOptions): Promise<SeamHttpAccessCodesUnmanaged>;
|
|
11
12
|
convertToManaged(body: AccessCodesUnmanagedConvertToManagedBody): Promise<void>;
|
|
12
13
|
delete(body: AccessCodesUnmanagedDeleteBody): Promise<void>;
|
|
13
14
|
get(body: AccessCodesUnmanagedGetBody): Promise<AccessCodesUnmanagedGetResponse['access_code']>;
|
|
14
15
|
list(body: AccessCodesUnmanagedListBody): Promise<AccessCodesUnmanagedListResponse['access_codes']>;
|
|
15
16
|
update(body: AccessCodesUnmanagedUpdateBody): Promise<void>;
|
|
16
17
|
}
|
|
17
|
-
export type AccessCodesUnmanagedConvertToManagedBody =
|
|
18
|
+
export type AccessCodesUnmanagedConvertToManagedBody = RouteRequestBody<'/access_codes/unmanaged/convert_to_managed'>;
|
|
18
19
|
export type AccessCodesUnmanagedConvertToManagedResponse = SetNonNullable<Required<RouteResponse<'/access_codes/unmanaged/convert_to_managed'>>>;
|
|
19
|
-
export type AccessCodesUnmanagedDeleteBody =
|
|
20
|
+
export type AccessCodesUnmanagedDeleteBody = RouteRequestBody<'/access_codes/unmanaged/delete'>;
|
|
20
21
|
export type AccessCodesUnmanagedDeleteResponse = SetNonNullable<Required<RouteResponse<'/access_codes/unmanaged/delete'>>>;
|
|
21
|
-
export type AccessCodesUnmanagedGetBody =
|
|
22
|
+
export type AccessCodesUnmanagedGetBody = RouteRequestBody<'/access_codes/unmanaged/get'>;
|
|
22
23
|
export type AccessCodesUnmanagedGetResponse = SetNonNullable<Required<RouteResponse<'/access_codes/unmanaged/get'>>>;
|
|
23
|
-
export type AccessCodesUnmanagedListBody =
|
|
24
|
+
export type AccessCodesUnmanagedListBody = RouteRequestBody<'/access_codes/unmanaged/list'>;
|
|
24
25
|
export type AccessCodesUnmanagedListResponse = SetNonNullable<Required<RouteResponse<'/access_codes/unmanaged/list'>>>;
|
|
25
|
-
export type AccessCodesUnmanagedUpdateBody =
|
|
26
|
+
export type AccessCodesUnmanagedUpdateBody = RouteRequestBody<'/access_codes/unmanaged/update'>;
|
|
26
27
|
export type AccessCodesUnmanagedUpdateResponse = SetNonNullable<Required<RouteResponse<'/access_codes/unmanaged/update'>>>;
|
|
@@ -2,34 +2,46 @@
|
|
|
2
2
|
* Automatically generated by generate-routes.ts.
|
|
3
3
|
* Do not edit this file or add other files to this directory.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { warnOnInsecureuserIdentifierKey } from '../../../../lib/seam/connect/auth.js';
|
|
6
|
+
import { createClient } from '../../../../lib/seam/connect/client.js';
|
|
7
|
+
import { isSeamHttpOptionsWithApiKey, isSeamHttpOptionsWithClient, isSeamHttpOptionsWithClientSessionToken, SeamHttpInvalidOptionsError, } from '../../../../lib/seam/connect/options.js';
|
|
7
8
|
import { parseOptions } from '../../../../lib/seam/connect/parse-options.js';
|
|
9
|
+
import { SeamHttpClientSessions } from './client-sessions.js';
|
|
8
10
|
export class SeamHttpAccessCodesUnmanaged {
|
|
9
|
-
constructor(apiKeyOrOptions) {
|
|
10
|
-
const
|
|
11
|
-
this.client =
|
|
11
|
+
constructor(apiKeyOrOptions = {}) {
|
|
12
|
+
const clientOptions = parseOptions(apiKeyOrOptions);
|
|
13
|
+
this.client = createClient(clientOptions);
|
|
12
14
|
}
|
|
13
15
|
static fromClient(client, options = {}) {
|
|
14
|
-
const
|
|
15
|
-
if (!isSeamHttpOptionsWithClient(
|
|
16
|
+
const constructorOptions = { ...options, client };
|
|
17
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
16
18
|
throw new SeamHttpInvalidOptionsError('Missing client');
|
|
17
19
|
}
|
|
18
|
-
return new SeamHttpAccessCodesUnmanaged(
|
|
20
|
+
return new SeamHttpAccessCodesUnmanaged(constructorOptions);
|
|
19
21
|
}
|
|
20
22
|
static fromApiKey(apiKey, options = {}) {
|
|
21
|
-
const
|
|
22
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
23
|
+
const constructorOptions = { ...options, apiKey };
|
|
24
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
23
25
|
throw new SeamHttpInvalidOptionsError('Missing apiKey');
|
|
24
26
|
}
|
|
25
|
-
return new SeamHttpAccessCodesUnmanaged(
|
|
27
|
+
return new SeamHttpAccessCodesUnmanaged(constructorOptions);
|
|
26
28
|
}
|
|
27
29
|
static fromClientSessionToken(clientSessionToken, options = {}) {
|
|
28
|
-
const
|
|
29
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
30
|
+
const constructorOptions = { ...options, clientSessionToken };
|
|
31
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
30
32
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken');
|
|
31
33
|
}
|
|
32
|
-
return new SeamHttpAccessCodesUnmanaged(
|
|
34
|
+
return new SeamHttpAccessCodesUnmanaged(constructorOptions);
|
|
35
|
+
}
|
|
36
|
+
static async fromPublishableKey(publishableKey, userIdentifierKey, options = {}) {
|
|
37
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey);
|
|
38
|
+
const clientOptions = parseOptions({ ...options, publishableKey });
|
|
39
|
+
const client = createClient(clientOptions);
|
|
40
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client);
|
|
41
|
+
const { token } = await clientSessions.getOrCreate({
|
|
42
|
+
user_identifier_key: userIdentifierKey,
|
|
43
|
+
});
|
|
44
|
+
return SeamHttpAccessCodesUnmanaged.fromClientSessionToken(token, options);
|
|
33
45
|
}
|
|
34
46
|
async convertToManaged(body) {
|
|
35
47
|
await this.client.request({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access-codes-unmanaged.js","sourceRoot":"","sources":["../../../../src/lib/seam/connect/routes/access-codes-unmanaged.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"access-codes-unmanaged.js","sourceRoot":"","sources":["../../../../src/lib/seam/connect/routes/access-codes-unmanaged.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAe,YAAY,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,uCAAuC,EAEvC,2BAA2B,GAK5B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,MAAM,OAAO,4BAA4B;IAGvC,YAAY,kBAA4C,EAAE;QACxD,MAAM,aAAa,GAAG,YAAY,CAAC,eAAe,CAAC,CAAA;QACnD,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,aAAa,CAAC,CAAA;IAC3C,CAAC;IAED,MAAM,CAAC,UAAU,CACf,MAA2C,EAC3C,UAAqD,EAAE;QAEvD,MAAM,kBAAkB,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,CAAC,2BAA2B,CAAC,kBAAkB,CAAC,EAAE;YACpD,MAAM,IAAI,2BAA2B,CAAC,gBAAgB,CAAC,CAAA;SACxD;QACD,OAAO,IAAI,4BAA4B,CAAC,kBAAkB,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,CAAC,UAAU,CACf,MAA2C,EAC3C,UAAqD,EAAE;QAEvD,MAAM,kBAAkB,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,CAAA;QACjD,IAAI,CAAC,2BAA2B,CAAC,kBAAkB,CAAC,EAAE;YACpD,MAAM,IAAI,2BAA2B,CAAC,gBAAgB,CAAC,CAAA;SACxD;QACD,OAAO,IAAI,4BAA4B,CAAC,kBAAkB,CAAC,CAAA;IAC7D,CAAC;IAED,MAAM,CAAC,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