@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.
Files changed (132) hide show
  1. package/dist/connect.cjs +1807 -96
  2. package/dist/connect.cjs.map +1 -1
  3. package/dist/connect.d.cts +472 -15
  4. package/lib/params-serializer.d.ts +5 -0
  5. package/lib/params-serializer.js +42 -0
  6. package/lib/params-serializer.js.map +1 -0
  7. package/lib/seam/connect/auth.d.ts +4 -3
  8. package/lib/seam/connect/auth.js +59 -8
  9. package/lib/seam/connect/auth.js.map +1 -1
  10. package/lib/seam/connect/client.d.ts +10 -10
  11. package/lib/seam/connect/client.js +16 -49
  12. package/lib/seam/connect/client.js.map +1 -1
  13. package/lib/seam/connect/index.d.ts +2 -1
  14. package/lib/seam/connect/index.js +2 -1
  15. package/lib/seam/connect/index.js.map +1 -1
  16. package/lib/seam/connect/options.d.ts +23 -0
  17. package/lib/seam/connect/options.js +39 -0
  18. package/lib/seam/connect/options.js.map +1 -0
  19. package/lib/seam/connect/parse-options.d.ts +6 -2
  20. package/lib/seam/connect/parse-options.js +35 -10
  21. package/lib/seam/connect/parse-options.js.map +1 -1
  22. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +27 -0
  23. package/lib/seam/connect/routes/access-codes-unmanaged.js +84 -0
  24. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -0
  25. package/lib/seam/connect/routes/access-codes.d.ts +38 -0
  26. package/lib/seam/connect/routes/access-codes.js +113 -0
  27. package/lib/seam/connect/routes/access-codes.js.map +1 -0
  28. package/lib/seam/connect/routes/acs-access-groups.d.ts +36 -0
  29. package/lib/seam/connect/routes/acs-access-groups.js +107 -0
  30. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -0
  31. package/lib/seam/connect/routes/acs-credentials.d.ts +24 -0
  32. package/lib/seam/connect/routes/acs-credentials.js +78 -0
  33. package/lib/seam/connect/routes/acs-credentials.js.map +1 -0
  34. package/lib/seam/connect/routes/acs-systems.d.ts +18 -0
  35. package/lib/seam/connect/routes/acs-systems.js +63 -0
  36. package/lib/seam/connect/routes/acs-systems.js.map +1 -0
  37. package/lib/seam/connect/routes/acs-users.d.ts +39 -0
  38. package/lib/seam/connect/routes/acs-users.js +113 -0
  39. package/lib/seam/connect/routes/acs-users.js.map +1 -0
  40. package/lib/seam/connect/routes/acs.d.ts +18 -0
  41. package/lib/seam/connect/routes/acs.js +63 -0
  42. package/lib/seam/connect/routes/acs.js.map +1 -0
  43. package/lib/seam/connect/routes/action-attempts.d.ts +18 -0
  44. package/lib/seam/connect/routes/action-attempts.js +63 -0
  45. package/lib/seam/connect/routes/action-attempts.js.map +1 -0
  46. package/lib/seam/connect/routes/client-sessions.d.ts +30 -0
  47. package/lib/seam/connect/routes/client-sessions.js +93 -0
  48. package/lib/seam/connect/routes/client-sessions.js.map +1 -0
  49. package/lib/seam/connect/routes/connect-webviews.d.ts +27 -0
  50. package/lib/seam/connect/routes/connect-webviews.js +85 -0
  51. package/lib/seam/connect/routes/connect-webviews.js.map +1 -0
  52. package/lib/seam/connect/routes/connected-accounts.d.ts +21 -0
  53. package/lib/seam/connect/routes/connected-accounts.js +70 -0
  54. package/lib/seam/connect/routes/connected-accounts.js.map +1 -0
  55. package/lib/seam/connect/routes/devices-unmanaged.d.ts +21 -0
  56. package/lib/seam/connect/routes/devices-unmanaged.js +70 -0
  57. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -0
  58. package/lib/seam/connect/routes/devices.d.ts +29 -0
  59. package/lib/seam/connect/routes/devices.js +89 -0
  60. package/lib/seam/connect/routes/devices.js.map +1 -0
  61. package/lib/seam/connect/routes/events.d.ts +18 -0
  62. package/lib/seam/connect/routes/events.js +63 -0
  63. package/lib/seam/connect/routes/events.js.map +1 -0
  64. package/lib/seam/connect/routes/index.d.ts +21 -0
  65. package/lib/seam/connect/routes/index.js +22 -0
  66. package/lib/seam/connect/routes/index.js.map +1 -0
  67. package/lib/seam/connect/routes/locks.d.ts +24 -0
  68. package/lib/seam/connect/routes/locks.js +79 -0
  69. package/lib/seam/connect/routes/locks.js.map +1 -0
  70. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +27 -0
  71. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +84 -0
  72. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -0
  73. package/lib/seam/connect/routes/noise-sensors.d.ts +12 -0
  74. package/lib/seam/connect/routes/noise-sensors.js +51 -0
  75. package/lib/seam/connect/routes/noise-sensors.js.map +1 -0
  76. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +27 -0
  77. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +85 -0
  78. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -0
  79. package/lib/seam/connect/routes/thermostats.d.ts +38 -0
  80. package/lib/seam/connect/routes/thermostats.js +109 -0
  81. package/lib/seam/connect/routes/thermostats.js.map +1 -0
  82. package/lib/seam/connect/routes/webhooks.d.ts +24 -0
  83. package/lib/seam/connect/routes/webhooks.js +78 -0
  84. package/lib/seam/connect/routes/webhooks.js.map +1 -0
  85. package/lib/seam/connect/routes/workspaces.d.ts +17 -7
  86. package/lib/seam/connect/routes/workspaces.js +61 -11
  87. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  88. package/lib/seam/connect/seam-http.d.ts +24 -0
  89. package/lib/seam/connect/seam-http.js +82 -0
  90. package/lib/seam/connect/seam-http.js.map +1 -0
  91. package/package.json +9 -3
  92. package/src/lib/params-serializer.ts +55 -0
  93. package/src/lib/seam/connect/auth.ts +101 -13
  94. package/src/lib/seam/connect/client.ts +30 -62
  95. package/src/lib/seam/connect/env.d.ts +11 -0
  96. package/src/lib/seam/connect/index.ts +2 -1
  97. package/src/lib/seam/connect/{client-options.ts → options.ts} +37 -15
  98. package/src/lib/seam/connect/parse-options.ts +55 -14
  99. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +170 -0
  100. package/src/lib/seam/connect/routes/access-codes.ts +226 -0
  101. package/src/lib/seam/connect/routes/acs-access-groups.ts +216 -0
  102. package/src/lib/seam/connect/routes/acs-credentials.ts +151 -0
  103. package/src/lib/seam/connect/routes/acs-systems.ts +118 -0
  104. package/src/lib/seam/connect/routes/acs-users.ts +221 -0
  105. package/src/lib/seam/connect/routes/acs.ts +101 -0
  106. package/src/lib/seam/connect/routes/action-attempts.ts +118 -0
  107. package/src/lib/seam/connect/routes/client-sessions.ts +187 -0
  108. package/src/lib/seam/connect/routes/connect-webviews.ts +170 -0
  109. package/src/lib/seam/connect/routes/connected-accounts.ts +139 -0
  110. package/src/lib/seam/connect/routes/devices-unmanaged.ts +134 -0
  111. package/src/lib/seam/connect/routes/devices.ts +166 -0
  112. package/src/lib/seam/connect/routes/events.ts +114 -0
  113. package/src/lib/seam/connect/routes/index.ts +21 -0
  114. package/src/lib/seam/connect/routes/locks.ts +148 -0
  115. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +170 -0
  116. package/src/lib/seam/connect/routes/noise-sensors.ts +86 -0
  117. package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +192 -0
  118. package/src/lib/seam/connect/routes/thermostats.ts +208 -0
  119. package/src/lib/seam/connect/routes/webhooks.ts +151 -0
  120. package/src/lib/seam/connect/routes/workspaces.ts +118 -22
  121. package/src/lib/seam/connect/seam-http.ts +141 -0
  122. package/lib/seam/connect/axios.d.ts +0 -3
  123. package/lib/seam/connect/axios.js +0 -17
  124. package/lib/seam/connect/axios.js.map +0 -1
  125. package/lib/seam/connect/client-options.d.ts +0 -19
  126. package/lib/seam/connect/client-options.js +0 -29
  127. package/lib/seam/connect/client-options.js.map +0 -1
  128. package/lib/seam/connect/legacy/workspaces.d.ts +0 -8
  129. package/lib/seam/connect/legacy/workspaces.js +0 -10
  130. package/lib/seam/connect/legacy/workspaces.js.map +0 -1
  131. package/src/lib/seam/connect/axios.ts +0 -23
  132. 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
- import type { RouteRequestParams, RouteResponse } from '@seamapi/types/connect'
2
- import { Axios } from 'axios'
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 { createAxiosClient } from 'lib/seam/connect/axios.js'
6
- import type { SeamHttpOptions } from 'lib/seam/connect/client-options.js'
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
- export class WorkspacesHttp {
10
- client: Axios
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
- constructor(apiKeyOrOptionsOrClient: Axios | string | SeamHttpOptions) {
13
- if (apiKeyOrOptionsOrClient instanceof Axios) {
14
- this.client = apiKeyOrOptionsOrClient
15
- return
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
- const options = parseOptions(apiKeyOrOptionsOrClient)
19
- this.client = createAxiosClient(options)
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: WorkspacesGetParams = {},
90
+ params?: WorkspacesGetParams,
24
91
  ): Promise<WorkspacesGetResponse['workspace']> {
25
- const { data } = await this.client.get<WorkspacesGetResponse>(
26
- '/workspaces/get',
27
- {
28
- params,
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 = SetNonNullable<
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,3 +0,0 @@
1
- import { type Axios } from 'axios';
2
- import { type SeamHttpOptions } from './client-options.js';
3
- export declare const createAxiosClient: (options: Required<SeamHttpOptions>) => Axios;
@@ -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
- >