@seamapi/http 0.0.2 → 0.2.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 +1807 -96
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +472 -15
- 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 +4 -3
- package/lib/seam/connect/auth.js +59 -8
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/client.d.ts +10 -10
- package/lib/seam/connect/client.js +16 -49
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/index.d.ts +2 -1
- package/lib/seam/connect/index.js +2 -1
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/options.d.ts +23 -0
- package/lib/seam/connect/options.js +39 -0
- 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 +35 -10
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +27 -0
- package/lib/seam/connect/routes/access-codes-unmanaged.js +84 -0
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -0
- package/lib/seam/connect/routes/access-codes.d.ts +38 -0
- package/lib/seam/connect/routes/access-codes.js +113 -0
- package/lib/seam/connect/routes/access-codes.js.map +1 -0
- package/lib/seam/connect/routes/acs-access-groups.d.ts +36 -0
- package/lib/seam/connect/routes/acs-access-groups.js +107 -0
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -0
- package/lib/seam/connect/routes/acs-credentials.d.ts +24 -0
- package/lib/seam/connect/routes/acs-credentials.js +78 -0
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -0
- package/lib/seam/connect/routes/acs-systems.d.ts +18 -0
- package/lib/seam/connect/routes/acs-systems.js +63 -0
- package/lib/seam/connect/routes/acs-systems.js.map +1 -0
- package/lib/seam/connect/routes/acs-users.d.ts +39 -0
- package/lib/seam/connect/routes/acs-users.js +113 -0
- package/lib/seam/connect/routes/acs-users.js.map +1 -0
- package/lib/seam/connect/routes/acs.d.ts +18 -0
- package/lib/seam/connect/routes/acs.js +63 -0
- package/lib/seam/connect/routes/acs.js.map +1 -0
- package/lib/seam/connect/routes/action-attempts.d.ts +18 -0
- package/lib/seam/connect/routes/action-attempts.js +63 -0
- package/lib/seam/connect/routes/action-attempts.js.map +1 -0
- package/lib/seam/connect/routes/client-sessions.d.ts +30 -0
- package/lib/seam/connect/routes/client-sessions.js +93 -0
- package/lib/seam/connect/routes/client-sessions.js.map +1 -0
- package/lib/seam/connect/routes/connect-webviews.d.ts +27 -0
- package/lib/seam/connect/routes/connect-webviews.js +85 -0
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -0
- package/lib/seam/connect/routes/connected-accounts.d.ts +21 -0
- package/lib/seam/connect/routes/connected-accounts.js +70 -0
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -0
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +21 -0
- package/lib/seam/connect/routes/devices-unmanaged.js +70 -0
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -0
- package/lib/seam/connect/routes/devices.d.ts +29 -0
- package/lib/seam/connect/routes/devices.js +89 -0
- package/lib/seam/connect/routes/devices.js.map +1 -0
- package/lib/seam/connect/routes/events.d.ts +18 -0
- package/lib/seam/connect/routes/events.js +63 -0
- package/lib/seam/connect/routes/events.js.map +1 -0
- package/lib/seam/connect/routes/index.d.ts +21 -0
- package/lib/seam/connect/routes/index.js +22 -0
- package/lib/seam/connect/routes/index.js.map +1 -0
- package/lib/seam/connect/routes/locks.d.ts +24 -0
- package/lib/seam/connect/routes/locks.js +79 -0
- package/lib/seam/connect/routes/locks.js.map +1 -0
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +27 -0
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +84 -0
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -0
- package/lib/seam/connect/routes/noise-sensors.d.ts +12 -0
- package/lib/seam/connect/routes/noise-sensors.js +51 -0
- package/lib/seam/connect/routes/noise-sensors.js.map +1 -0
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +27 -0
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +85 -0
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -0
- package/lib/seam/connect/routes/thermostats.d.ts +38 -0
- package/lib/seam/connect/routes/thermostats.js +109 -0
- package/lib/seam/connect/routes/thermostats.js.map +1 -0
- package/lib/seam/connect/routes/webhooks.d.ts +24 -0
- package/lib/seam/connect/routes/webhooks.js +78 -0
- package/lib/seam/connect/routes/webhooks.js.map +1 -0
- package/lib/seam/connect/routes/workspaces.d.ts +17 -7
- package/lib/seam/connect/routes/workspaces.js +61 -11
- 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 -3
- package/src/lib/params-serializer.ts +55 -0
- package/src/lib/seam/connect/auth.ts +101 -13
- package/src/lib/seam/connect/client.ts +30 -62
- package/src/lib/seam/connect/env.d.ts +11 -0
- package/src/lib/seam/connect/index.ts +2 -1
- package/src/lib/seam/connect/{client-options.ts → options.ts} +37 -15
- package/src/lib/seam/connect/parse-options.ts +55 -14
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +170 -0
- package/src/lib/seam/connect/routes/access-codes.ts +226 -0
- package/src/lib/seam/connect/routes/acs-access-groups.ts +216 -0
- package/src/lib/seam/connect/routes/acs-credentials.ts +151 -0
- package/src/lib/seam/connect/routes/acs-systems.ts +118 -0
- package/src/lib/seam/connect/routes/acs-users.ts +221 -0
- package/src/lib/seam/connect/routes/acs.ts +101 -0
- package/src/lib/seam/connect/routes/action-attempts.ts +118 -0
- package/src/lib/seam/connect/routes/client-sessions.ts +187 -0
- package/src/lib/seam/connect/routes/connect-webviews.ts +170 -0
- package/src/lib/seam/connect/routes/connected-accounts.ts +139 -0
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +134 -0
- package/src/lib/seam/connect/routes/devices.ts +166 -0
- package/src/lib/seam/connect/routes/events.ts +114 -0
- package/src/lib/seam/connect/routes/index.ts +21 -0
- package/src/lib/seam/connect/routes/locks.ts +148 -0
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +170 -0
- package/src/lib/seam/connect/routes/noise-sensors.ts +86 -0
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +192 -0
- package/src/lib/seam/connect/routes/thermostats.ts +208 -0
- package/src/lib/seam/connect/routes/webhooks.ts +151 -0
- package/src/lib/seam/connect/routes/workspaces.ts +118 -22
- 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 -17
- package/lib/seam/connect/axios.js.map +0 -1
- package/lib/seam/connect/client-options.d.ts +0 -19
- package/lib/seam/connect/client-options.js +0 -29
- package/lib/seam/connect/client-options.js.map +0 -1
- package/lib/seam/connect/legacy/workspaces.d.ts +0 -8
- package/lib/seam/connect/legacy/workspaces.js +0 -10
- package/lib/seam/connect/legacy/workspaces.js.map +0 -1
- package/src/lib/seam/connect/axios.ts +0 -23
- package/src/lib/seam/connect/legacy/workspaces.ts +0 -26
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Automatically generated by generate-routes.ts.
|
|
3
|
+
* Do not edit this file or add other files to this directory.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
RouteRequestBody,
|
|
8
|
+
RouteRequestParams,
|
|
9
|
+
RouteResponse,
|
|
10
|
+
} from '@seamapi/types/connect'
|
|
11
|
+
import type { SetNonNullable } from 'type-fest'
|
|
12
|
+
|
|
13
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
14
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
15
|
+
import {
|
|
16
|
+
isSeamHttpOptionsWithApiKey,
|
|
17
|
+
isSeamHttpOptionsWithClient,
|
|
18
|
+
isSeamHttpOptionsWithClientSessionToken,
|
|
19
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
20
|
+
SeamHttpInvalidOptionsError,
|
|
21
|
+
type SeamHttpOptions,
|
|
22
|
+
type SeamHttpOptionsWithApiKey,
|
|
23
|
+
type SeamHttpOptionsWithClient,
|
|
24
|
+
type SeamHttpOptionsWithClientSessionToken,
|
|
25
|
+
} from 'lib/seam/connect/options.js'
|
|
26
|
+
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
27
|
+
|
|
28
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
29
|
+
|
|
30
|
+
export class SeamHttpWebhooks {
|
|
31
|
+
client: Client
|
|
32
|
+
|
|
33
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
34
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
35
|
+
this.client = createClient(clientOptions)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static fromClient(
|
|
39
|
+
client: SeamHttpOptionsWithClient['client'],
|
|
40
|
+
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
41
|
+
): SeamHttpWebhooks {
|
|
42
|
+
const constructorOptions = { ...options, client }
|
|
43
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
44
|
+
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
45
|
+
}
|
|
46
|
+
return new SeamHttpWebhooks(constructorOptions)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static fromApiKey(
|
|
50
|
+
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
51
|
+
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
52
|
+
): SeamHttpWebhooks {
|
|
53
|
+
const constructorOptions = { ...options, apiKey }
|
|
54
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
55
|
+
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
56
|
+
}
|
|
57
|
+
return new SeamHttpWebhooks(constructorOptions)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static fromClientSessionToken(
|
|
61
|
+
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
|
|
62
|
+
options: Omit<
|
|
63
|
+
SeamHttpOptionsWithClientSessionToken,
|
|
64
|
+
'clientSessionToken'
|
|
65
|
+
> = {},
|
|
66
|
+
): SeamHttpWebhooks {
|
|
67
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
68
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
69
|
+
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
70
|
+
}
|
|
71
|
+
return new SeamHttpWebhooks(constructorOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async fromPublishableKey(
|
|
75
|
+
publishableKey: string,
|
|
76
|
+
userIdentifierKey: string,
|
|
77
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
78
|
+
): Promise<SeamHttpWebhooks> {
|
|
79
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
80
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
81
|
+
const client = createClient(clientOptions)
|
|
82
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
83
|
+
const { token } = await clientSessions.getOrCreate({
|
|
84
|
+
user_identifier_key: userIdentifierKey,
|
|
85
|
+
})
|
|
86
|
+
return SeamHttpWebhooks.fromClientSessionToken(token, options)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async create(
|
|
90
|
+
body: WebhooksCreateBody,
|
|
91
|
+
): Promise<WebhooksCreateResponse['webhook']> {
|
|
92
|
+
const { data } = await this.client.request<WebhooksCreateResponse>({
|
|
93
|
+
url: '/webhooks/create',
|
|
94
|
+
method: 'post',
|
|
95
|
+
data: body,
|
|
96
|
+
})
|
|
97
|
+
return data.webhook
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async delete(body: WebhooksDeleteBody): Promise<void> {
|
|
101
|
+
await this.client.request<WebhooksDeleteResponse>({
|
|
102
|
+
url: '/webhooks/delete',
|
|
103
|
+
method: 'post',
|
|
104
|
+
data: body,
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async get(body: WebhooksGetBody): Promise<WebhooksGetResponse['webhook']> {
|
|
109
|
+
const { data } = await this.client.request<WebhooksGetResponse>({
|
|
110
|
+
url: '/webhooks/get',
|
|
111
|
+
method: 'post',
|
|
112
|
+
data: body,
|
|
113
|
+
})
|
|
114
|
+
return data.webhook
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async list(
|
|
118
|
+
params?: WebhooksListParams,
|
|
119
|
+
): Promise<WebhooksListResponse['webhooks']> {
|
|
120
|
+
const { data } = await this.client.request<WebhooksListResponse>({
|
|
121
|
+
url: '/webhooks/list',
|
|
122
|
+
method: 'get',
|
|
123
|
+
params,
|
|
124
|
+
})
|
|
125
|
+
return data.webhooks
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type WebhooksCreateBody = RouteRequestBody<'/webhooks/create'>
|
|
130
|
+
|
|
131
|
+
export type WebhooksCreateResponse = SetNonNullable<
|
|
132
|
+
Required<RouteResponse<'/webhooks/create'>>
|
|
133
|
+
>
|
|
134
|
+
|
|
135
|
+
export type WebhooksDeleteBody = RouteRequestBody<'/webhooks/delete'>
|
|
136
|
+
|
|
137
|
+
export type WebhooksDeleteResponse = SetNonNullable<
|
|
138
|
+
Required<RouteResponse<'/webhooks/delete'>>
|
|
139
|
+
>
|
|
140
|
+
|
|
141
|
+
export type WebhooksGetBody = RouteRequestBody<'/webhooks/get'>
|
|
142
|
+
|
|
143
|
+
export type WebhooksGetResponse = SetNonNullable<
|
|
144
|
+
Required<RouteResponse<'/webhooks/get'>>
|
|
145
|
+
>
|
|
146
|
+
|
|
147
|
+
export type WebhooksListParams = RouteRequestParams<'/webhooks/list'>
|
|
148
|
+
|
|
149
|
+
export type WebhooksListResponse = SetNonNullable<
|
|
150
|
+
Required<RouteResponse<'/webhooks/list'>>
|
|
151
|
+
>
|
|
@@ -1,41 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Automatically generated by generate-routes.ts.
|
|
3
|
+
* Do not edit this file or add other files to this directory.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
RouteRequestBody,
|
|
8
|
+
RouteRequestParams,
|
|
9
|
+
RouteResponse,
|
|
10
|
+
} from '@seamapi/types/connect'
|
|
3
11
|
import type { SetNonNullable } from 'type-fest'
|
|
4
12
|
|
|
5
|
-
import {
|
|
6
|
-
import type
|
|
13
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
14
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
15
|
+
import {
|
|
16
|
+
isSeamHttpOptionsWithApiKey,
|
|
17
|
+
isSeamHttpOptionsWithClient,
|
|
18
|
+
isSeamHttpOptionsWithClientSessionToken,
|
|
19
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
20
|
+
SeamHttpInvalidOptionsError,
|
|
21
|
+
type SeamHttpOptions,
|
|
22
|
+
type SeamHttpOptionsWithApiKey,
|
|
23
|
+
type SeamHttpOptionsWithClient,
|
|
24
|
+
type SeamHttpOptionsWithClientSessionToken,
|
|
25
|
+
} from 'lib/seam/connect/options.js'
|
|
7
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
8
27
|
|
|
9
|
-
|
|
10
|
-
|
|
28
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
29
|
+
|
|
30
|
+
export class SeamHttpWorkspaces {
|
|
31
|
+
client: Client
|
|
32
|
+
|
|
33
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
34
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
35
|
+
this.client = createClient(clientOptions)
|
|
36
|
+
}
|
|
11
37
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
38
|
+
static fromClient(
|
|
39
|
+
client: SeamHttpOptionsWithClient['client'],
|
|
40
|
+
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
41
|
+
): SeamHttpWorkspaces {
|
|
42
|
+
const constructorOptions = { ...options, client }
|
|
43
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
44
|
+
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
16
45
|
}
|
|
46
|
+
return new SeamHttpWorkspaces(constructorOptions)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static fromApiKey(
|
|
50
|
+
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
51
|
+
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
52
|
+
): SeamHttpWorkspaces {
|
|
53
|
+
const constructorOptions = { ...options, apiKey }
|
|
54
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
55
|
+
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
56
|
+
}
|
|
57
|
+
return new SeamHttpWorkspaces(constructorOptions)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static fromClientSessionToken(
|
|
61
|
+
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
|
|
62
|
+
options: Omit<
|
|
63
|
+
SeamHttpOptionsWithClientSessionToken,
|
|
64
|
+
'clientSessionToken'
|
|
65
|
+
> = {},
|
|
66
|
+
): SeamHttpWorkspaces {
|
|
67
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
68
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
69
|
+
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
70
|
+
}
|
|
71
|
+
return new SeamHttpWorkspaces(constructorOptions)
|
|
72
|
+
}
|
|
17
73
|
|
|
18
|
-
|
|
19
|
-
|
|
74
|
+
static async fromPublishableKey(
|
|
75
|
+
publishableKey: string,
|
|
76
|
+
userIdentifierKey: string,
|
|
77
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
78
|
+
): Promise<SeamHttpWorkspaces> {
|
|
79
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
80
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
81
|
+
const client = createClient(clientOptions)
|
|
82
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
83
|
+
const { token } = await clientSessions.getOrCreate({
|
|
84
|
+
user_identifier_key: userIdentifierKey,
|
|
85
|
+
})
|
|
86
|
+
return SeamHttpWorkspaces.fromClientSessionToken(token, options)
|
|
20
87
|
}
|
|
21
88
|
|
|
22
89
|
async get(
|
|
23
|
-
params
|
|
90
|
+
params?: WorkspacesGetParams,
|
|
24
91
|
): Promise<WorkspacesGetResponse['workspace']> {
|
|
25
|
-
const { data } = await this.client.
|
|
26
|
-
'/workspaces/get',
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
92
|
+
const { data } = await this.client.request<WorkspacesGetResponse>({
|
|
93
|
+
url: '/workspaces/get',
|
|
94
|
+
method: 'get',
|
|
95
|
+
params,
|
|
96
|
+
})
|
|
31
97
|
return data.workspace
|
|
32
98
|
}
|
|
99
|
+
|
|
100
|
+
async list(
|
|
101
|
+
params?: WorkspacesListParams,
|
|
102
|
+
): Promise<WorkspacesListResponse['workspaces']> {
|
|
103
|
+
const { data } = await this.client.request<WorkspacesListResponse>({
|
|
104
|
+
url: '/workspaces/list',
|
|
105
|
+
method: 'get',
|
|
106
|
+
params,
|
|
107
|
+
})
|
|
108
|
+
return data.workspaces
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async resetSandbox(body: WorkspacesResetSandboxBody): Promise<void> {
|
|
112
|
+
await this.client.request<WorkspacesResetSandboxResponse>({
|
|
113
|
+
url: '/workspaces/reset_sandbox',
|
|
114
|
+
method: 'post',
|
|
115
|
+
data: body,
|
|
116
|
+
})
|
|
117
|
+
}
|
|
33
118
|
}
|
|
34
119
|
|
|
35
|
-
export type WorkspacesGetParams =
|
|
36
|
-
Required<RouteRequestParams<'/workspaces/get'>>
|
|
37
|
-
>
|
|
120
|
+
export type WorkspacesGetParams = RouteRequestParams<'/workspaces/get'>
|
|
38
121
|
|
|
39
122
|
export type WorkspacesGetResponse = SetNonNullable<
|
|
40
123
|
Required<RouteResponse<'/workspaces/get'>>
|
|
41
124
|
>
|
|
125
|
+
|
|
126
|
+
export type WorkspacesListParams = RouteRequestParams<'/workspaces/list'>
|
|
127
|
+
|
|
128
|
+
export type WorkspacesListResponse = SetNonNullable<
|
|
129
|
+
Required<RouteResponse<'/workspaces/list'>>
|
|
130
|
+
>
|
|
131
|
+
|
|
132
|
+
export type WorkspacesResetSandboxBody =
|
|
133
|
+
RouteRequestBody<'/workspaces/reset_sandbox'>
|
|
134
|
+
|
|
135
|
+
export type WorkspacesResetSandboxResponse = SetNonNullable<
|
|
136
|
+
Required<RouteResponse<'/workspaces/reset_sandbox'>>
|
|
137
|
+
>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { warnOnInsecureuserIdentifierKey } from './auth.js'
|
|
2
|
+
import { type Client, createClient } from './client.js'
|
|
3
|
+
import {
|
|
4
|
+
isSeamHttpOptionsWithApiKey,
|
|
5
|
+
isSeamHttpOptionsWithClient,
|
|
6
|
+
isSeamHttpOptionsWithClientSessionToken,
|
|
7
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
8
|
+
SeamHttpInvalidOptionsError,
|
|
9
|
+
type SeamHttpOptions,
|
|
10
|
+
type SeamHttpOptionsWithApiKey,
|
|
11
|
+
type SeamHttpOptionsWithClient,
|
|
12
|
+
type SeamHttpOptionsWithClientSessionToken,
|
|
13
|
+
} from './options.js'
|
|
14
|
+
import { parseOptions } from './parse-options.js'
|
|
15
|
+
import {
|
|
16
|
+
SeamHttpAccessCodes,
|
|
17
|
+
SeamHttpAcs,
|
|
18
|
+
SeamHttpActionAttempts,
|
|
19
|
+
SeamHttpClientSessions,
|
|
20
|
+
SeamHttpConnectedAccounts,
|
|
21
|
+
SeamHttpConnectWebviews,
|
|
22
|
+
SeamHttpDevices,
|
|
23
|
+
SeamHttpEvents,
|
|
24
|
+
SeamHttpLocks,
|
|
25
|
+
SeamHttpNoiseSensors,
|
|
26
|
+
SeamHttpThermostats,
|
|
27
|
+
SeamHttpWebhooks,
|
|
28
|
+
SeamHttpWorkspaces,
|
|
29
|
+
} from './routes/index.js'
|
|
30
|
+
|
|
31
|
+
export class SeamHttp {
|
|
32
|
+
client: Client
|
|
33
|
+
|
|
34
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
35
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
36
|
+
this.client = createClient(clientOptions)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static fromClient(
|
|
40
|
+
client: SeamHttpOptionsWithClient['client'],
|
|
41
|
+
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
42
|
+
): SeamHttp {
|
|
43
|
+
const constructorOptions = { ...options, client }
|
|
44
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
45
|
+
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
46
|
+
}
|
|
47
|
+
return new SeamHttp(constructorOptions)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static fromApiKey(
|
|
51
|
+
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
52
|
+
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
53
|
+
): SeamHttp {
|
|
54
|
+
const constructorOptions = { ...options, apiKey }
|
|
55
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
56
|
+
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
57
|
+
}
|
|
58
|
+
return new SeamHttp(constructorOptions)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static fromClientSessionToken(
|
|
62
|
+
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
|
|
63
|
+
options: Omit<
|
|
64
|
+
SeamHttpOptionsWithClientSessionToken,
|
|
65
|
+
'clientSessionToken'
|
|
66
|
+
> = {},
|
|
67
|
+
): SeamHttp {
|
|
68
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
69
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
70
|
+
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
71
|
+
}
|
|
72
|
+
return new SeamHttp(constructorOptions)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static async fromPublishableKey(
|
|
76
|
+
publishableKey: string,
|
|
77
|
+
userIdentifierKey: string,
|
|
78
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
79
|
+
): Promise<SeamHttp> {
|
|
80
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
81
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
82
|
+
const client = createClient(clientOptions)
|
|
83
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
84
|
+
const { token } = await clientSessions.getOrCreate({
|
|
85
|
+
user_identifier_key: userIdentifierKey,
|
|
86
|
+
})
|
|
87
|
+
return SeamHttp.fromClientSessionToken(token, options)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get accessCodes(): SeamHttpAccessCodes {
|
|
91
|
+
return SeamHttpAccessCodes.fromClient(this.client)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get acs(): SeamHttpAcs {
|
|
95
|
+
return SeamHttpAcs.fromClient(this.client)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get actionAttempts(): SeamHttpActionAttempts {
|
|
99
|
+
return SeamHttpActionAttempts.fromClient(this.client)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get clientSessions(): SeamHttpClientSessions {
|
|
103
|
+
return SeamHttpClientSessions.fromClient(this.client)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get connectedAccounts(): SeamHttpConnectedAccounts {
|
|
107
|
+
return SeamHttpConnectedAccounts.fromClient(this.client)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get connectWebviews(): SeamHttpConnectWebviews {
|
|
111
|
+
return SeamHttpConnectWebviews.fromClient(this.client)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get devices(): SeamHttpDevices {
|
|
115
|
+
return SeamHttpDevices.fromClient(this.client)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get events(): SeamHttpEvents {
|
|
119
|
+
return SeamHttpEvents.fromClient(this.client)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get locks(): SeamHttpLocks {
|
|
123
|
+
return SeamHttpLocks.fromClient(this.client)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get noiseSensors(): SeamHttpNoiseSensors {
|
|
127
|
+
return SeamHttpNoiseSensors.fromClient(this.client)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
get thermostats(): SeamHttpThermostats {
|
|
131
|
+
return SeamHttpThermostats.fromClient(this.client)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get webhooks(): SeamHttpWebhooks {
|
|
135
|
+
return SeamHttpWebhooks.fromClient(this.client)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
get workspaces(): SeamHttpWorkspaces {
|
|
139
|
+
return SeamHttpWorkspaces.fromClient(this.client)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import axios, {} from 'axios';
|
|
2
|
-
import { getAuthHeaders } from './auth.js';
|
|
3
|
-
import { isSeamHttpOptionsWithClientSessionToken, } from './client-options.js';
|
|
4
|
-
export const createAxiosClient = (options) => {
|
|
5
|
-
// TODO: axiosRetry? Allow options to configure this if so
|
|
6
|
-
return axios.create({
|
|
7
|
-
baseURL: options.endpoint,
|
|
8
|
-
withCredentials: isSeamHttpOptionsWithClientSessionToken(options),
|
|
9
|
-
...options.axiosOptions,
|
|
10
|
-
headers: {
|
|
11
|
-
...getAuthHeaders(options),
|
|
12
|
-
...options.axiosOptions.headers,
|
|
13
|
-
// TODO: User-Agent
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=axios.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/axios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAc,MAAM,OAAO,CAAA;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EACL,uCAAuC,GAExC,MAAM,qBAAqB,CAAA;AAE5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAkC,EAC3B,EAAE;IACT,0DAA0D;IAC1D,OAAO,KAAK,CAAC,MAAM,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC,QAAQ;QACzB,eAAe,EAAE,uCAAuC,CAAC,OAAO,CAAC;QACjE,GAAG,OAAO,CAAC,YAAY;QACvB,OAAO,EAAE;YACP,GAAG,cAAc,CAAC,OAAO,CAAC;YAC1B,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO;YAC/B,mBAAmB;SACpB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
-
export type SeamHttpOptions = SeamHttpOptionsWithApiKey | SeamHttpOptionsWithClientSessionToken;
|
|
3
|
-
interface SeamHttpCommonOptions {
|
|
4
|
-
endpoint?: string;
|
|
5
|
-
axiosOptions?: AxiosRequestConfig;
|
|
6
|
-
enableLegacyMethodBehaivor?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface SeamHttpOptionsWithApiKey extends SeamHttpCommonOptions {
|
|
9
|
-
apiKey: string;
|
|
10
|
-
}
|
|
11
|
-
export declare const isSeamHttpOptionsWithApiKey: (options: SeamHttpOptions) => options is SeamHttpOptionsWithApiKey;
|
|
12
|
-
export interface SeamHttpOptionsWithClientSessionToken extends SeamHttpCommonOptions {
|
|
13
|
-
clientSessionToken: string;
|
|
14
|
-
}
|
|
15
|
-
export declare const isSeamHttpOptionsWithClientSessionToken: (options: SeamHttpOptions) => options is SeamHttpOptionsWithClientSessionToken;
|
|
16
|
-
export declare class InvalidSeamHttpOptionsError extends Error {
|
|
17
|
-
constructor(message: string);
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export const isSeamHttpOptionsWithApiKey = (options) => {
|
|
2
|
-
if (!('apiKey' in options))
|
|
3
|
-
return false;
|
|
4
|
-
if ('clientSessionToken' in options && options.clientSessionToken != null) {
|
|
5
|
-
throw new InvalidSeamHttpOptionsError('The clientSessionToken option cannot be used with the apiKey option.');
|
|
6
|
-
}
|
|
7
|
-
return true;
|
|
8
|
-
};
|
|
9
|
-
export const isSeamHttpOptionsWithClientSessionToken = (options) => {
|
|
10
|
-
if (!('clientSessionToken' in options))
|
|
11
|
-
return false;
|
|
12
|
-
if ('apiKey' in options && options.apiKey != null) {
|
|
13
|
-
throw new InvalidSeamHttpOptionsError('The clientSessionToken option cannot be used with the apiKey option.');
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
};
|
|
17
|
-
export class InvalidSeamHttpOptionsError extends Error {
|
|
18
|
-
constructor(message) {
|
|
19
|
-
super(`SeamHttp received invalid options: ${message}`);
|
|
20
|
-
this.name = this.constructor.name;
|
|
21
|
-
Error.captureStackTrace(this, this.constructor);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
// TODO: withSessionToken { sessionToken } or withMultiWorkspaceApiKey { apiKey }?
|
|
25
|
-
// export interface SeamHttpOptionsWithSessionToken extends SeamHttpCommonOptions {
|
|
26
|
-
// workspaceId: string
|
|
27
|
-
// apiKey: string
|
|
28
|
-
// }
|
|
29
|
-
//# sourceMappingURL=client-options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-options.js","sourceRoot":"","sources":["../../../src/lib/seam/connect/client-options.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,OAAwB,EACc,EAAE;IACxC,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAA;IAExC,IAAI,oBAAoB,IAAI,OAAO,IAAI,OAAO,CAAC,kBAAkB,IAAI,IAAI,EAAE;QACzE,MAAM,IAAI,2BAA2B,CACnC,sEAAsE,CACvE,CAAA;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAOD,MAAM,CAAC,MAAM,uCAAuC,GAAG,CACrD,OAAwB,EAC0B,EAAE;IACpD,IAAI,CAAC,CAAC,oBAAoB,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAA;IAEpD,IAAI,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,EAAE;QACjD,MAAM,IAAI,2BAA2B,CACnC,sEAAsE,CACvE,CAAA;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD,YAAY,OAAe;QACzB,KAAK,CAAC,sCAAsC,OAAO,EAAE,CAAC,CAAA;QACtD,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;AAED,kFAAkF;AAClF,mFAAmF;AACnF,wBAAwB;AACxB,mBAAmB;AACnB,IAAI"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { RouteRequestParams, RouteResponse } from '@seamapi/types/connect';
|
|
2
|
-
import type { SetNonNullable } from 'type-fest';
|
|
3
|
-
import { WorkspacesHttp } from '../../../../lib/seam/connect/routes/workspaces.js';
|
|
4
|
-
export declare class LegacyWorkspacesHttp extends WorkspacesHttp {
|
|
5
|
-
get(params?: WorkspacesGetParams): Promise<WorkspacesGetResponse['workspace']>;
|
|
6
|
-
}
|
|
7
|
-
export type WorkspacesGetParams = SetNonNullable<Required<RouteRequestParams<'/workspaces/get'>>>;
|
|
8
|
-
export type WorkspacesGetResponse = SetNonNullable<Required<RouteResponse<'/workspaces/get'>>>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { WorkspacesHttp } from '../../../../lib/seam/connect/routes/workspaces.js';
|
|
2
|
-
export class LegacyWorkspacesHttp extends WorkspacesHttp {
|
|
3
|
-
async get(params = {}) {
|
|
4
|
-
const { data } = await this.client.get('/workspaces/get', {
|
|
5
|
-
params,
|
|
6
|
-
});
|
|
7
|
-
return data.workspace;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=workspaces.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workspaces.js","sourceRoot":"","sources":["../../../../src/lib/seam/connect/legacy/workspaces.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAEtE,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IAC7C,KAAK,CAAC,GAAG,CAChB,SAA8B,EAAE;QAEhC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CACpC,iBAAiB,EACjB;YACE,MAAM;SACP,CACF,CAAA;QACD,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;CACF"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import axios, { type Axios } from 'axios'
|
|
2
|
-
|
|
3
|
-
import { getAuthHeaders } from './auth.js'
|
|
4
|
-
import {
|
|
5
|
-
isSeamHttpOptionsWithClientSessionToken,
|
|
6
|
-
type SeamHttpOptions,
|
|
7
|
-
} from './client-options.js'
|
|
8
|
-
|
|
9
|
-
export const createAxiosClient = (
|
|
10
|
-
options: Required<SeamHttpOptions>,
|
|
11
|
-
): Axios => {
|
|
12
|
-
// TODO: axiosRetry? Allow options to configure this if so
|
|
13
|
-
return axios.create({
|
|
14
|
-
baseURL: options.endpoint,
|
|
15
|
-
withCredentials: isSeamHttpOptionsWithClientSessionToken(options),
|
|
16
|
-
...options.axiosOptions,
|
|
17
|
-
headers: {
|
|
18
|
-
...getAuthHeaders(options),
|
|
19
|
-
...options.axiosOptions.headers,
|
|
20
|
-
// TODO: User-Agent
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { RouteRequestParams, RouteResponse } from '@seamapi/types/connect'
|
|
2
|
-
import type { SetNonNullable } from 'type-fest'
|
|
3
|
-
|
|
4
|
-
import { WorkspacesHttp } from 'lib/seam/connect/routes/workspaces.js'
|
|
5
|
-
|
|
6
|
-
export class LegacyWorkspacesHttp extends WorkspacesHttp {
|
|
7
|
-
override async get(
|
|
8
|
-
params: WorkspacesGetParams = {},
|
|
9
|
-
): Promise<WorkspacesGetResponse['workspace']> {
|
|
10
|
-
const { data } = await this.client.get<WorkspacesGetResponse>(
|
|
11
|
-
'/workspaces/get',
|
|
12
|
-
{
|
|
13
|
-
params,
|
|
14
|
-
},
|
|
15
|
-
)
|
|
16
|
-
return data.workspace
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type WorkspacesGetParams = SetNonNullable<
|
|
21
|
-
Required<RouteRequestParams<'/workspaces/get'>>
|
|
22
|
-
>
|
|
23
|
-
|
|
24
|
-
export type WorkspacesGetResponse = SetNonNullable<
|
|
25
|
-
Required<RouteResponse<'/workspaces/get'>>
|
|
26
|
-
>
|