@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,118 @@
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 { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
7
+ import type { SetNonNullable } from 'type-fest'
8
+
9
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
10
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
11
+ import {
12
+ isSeamHttpOptionsWithApiKey,
13
+ isSeamHttpOptionsWithClient,
14
+ isSeamHttpOptionsWithClientSessionToken,
15
+ type SeamHttpFromPublishableKeyOptions,
16
+ SeamHttpInvalidOptionsError,
17
+ type SeamHttpOptions,
18
+ type SeamHttpOptionsWithApiKey,
19
+ type SeamHttpOptionsWithClient,
20
+ type SeamHttpOptionsWithClientSessionToken,
21
+ } from 'lib/seam/connect/options.js'
22
+ import { parseOptions } from 'lib/seam/connect/parse-options.js'
23
+
24
+ import { SeamHttpClientSessions } from './client-sessions.js'
25
+
26
+ export class SeamHttpActionAttempts {
27
+ client: Client
28
+
29
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
30
+ const clientOptions = parseOptions(apiKeyOrOptions)
31
+ this.client = createClient(clientOptions)
32
+ }
33
+
34
+ static fromClient(
35
+ client: SeamHttpOptionsWithClient['client'],
36
+ options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
37
+ ): SeamHttpActionAttempts {
38
+ const constructorOptions = { ...options, client }
39
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
40
+ throw new SeamHttpInvalidOptionsError('Missing client')
41
+ }
42
+ return new SeamHttpActionAttempts(constructorOptions)
43
+ }
44
+
45
+ static fromApiKey(
46
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
47
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
48
+ ): SeamHttpActionAttempts {
49
+ const constructorOptions = { ...options, apiKey }
50
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
51
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
52
+ }
53
+ return new SeamHttpActionAttempts(constructorOptions)
54
+ }
55
+
56
+ static fromClientSessionToken(
57
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
58
+ options: Omit<
59
+ SeamHttpOptionsWithClientSessionToken,
60
+ 'clientSessionToken'
61
+ > = {},
62
+ ): SeamHttpActionAttempts {
63
+ const constructorOptions = { ...options, clientSessionToken }
64
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
65
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
66
+ }
67
+ return new SeamHttpActionAttempts(constructorOptions)
68
+ }
69
+
70
+ static async fromPublishableKey(
71
+ publishableKey: string,
72
+ userIdentifierKey: string,
73
+ options: SeamHttpFromPublishableKeyOptions = {},
74
+ ): Promise<SeamHttpActionAttempts> {
75
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
76
+ const clientOptions = parseOptions({ ...options, publishableKey })
77
+ const client = createClient(clientOptions)
78
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
79
+ const { token } = await clientSessions.getOrCreate({
80
+ user_identifier_key: userIdentifierKey,
81
+ })
82
+ return SeamHttpActionAttempts.fromClientSessionToken(token, options)
83
+ }
84
+
85
+ async get(
86
+ body: ActionAttemptsGetBody,
87
+ ): Promise<ActionAttemptsGetResponse['action_attempt']> {
88
+ const { data } = await this.client.request<ActionAttemptsGetResponse>({
89
+ url: '/action_attempts/get',
90
+ method: 'post',
91
+ data: body,
92
+ })
93
+ return data.action_attempt
94
+ }
95
+
96
+ async list(
97
+ body: ActionAttemptsListBody,
98
+ ): Promise<ActionAttemptsListResponse['action_attempts']> {
99
+ const { data } = await this.client.request<ActionAttemptsListResponse>({
100
+ url: '/action_attempts/list',
101
+ method: 'post',
102
+ data: body,
103
+ })
104
+ return data.action_attempts
105
+ }
106
+ }
107
+
108
+ export type ActionAttemptsGetBody = RouteRequestBody<'/action_attempts/get'>
109
+
110
+ export type ActionAttemptsGetResponse = SetNonNullable<
111
+ Required<RouteResponse<'/action_attempts/get'>>
112
+ >
113
+
114
+ export type ActionAttemptsListBody = RouteRequestBody<'/action_attempts/list'>
115
+
116
+ export type ActionAttemptsListResponse = SetNonNullable<
117
+ Required<RouteResponse<'/action_attempts/list'>>
118
+ >
@@ -0,0 +1,187 @@
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 { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
7
+ import type { SetNonNullable } from 'type-fest'
8
+
9
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
10
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
11
+ import {
12
+ isSeamHttpOptionsWithApiKey,
13
+ isSeamHttpOptionsWithClient,
14
+ isSeamHttpOptionsWithClientSessionToken,
15
+ type SeamHttpFromPublishableKeyOptions,
16
+ SeamHttpInvalidOptionsError,
17
+ type SeamHttpOptions,
18
+ type SeamHttpOptionsWithApiKey,
19
+ type SeamHttpOptionsWithClient,
20
+ type SeamHttpOptionsWithClientSessionToken,
21
+ } from 'lib/seam/connect/options.js'
22
+ import { parseOptions } from 'lib/seam/connect/parse-options.js'
23
+
24
+ export class SeamHttpClientSessions {
25
+ client: Client
26
+
27
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
28
+ const clientOptions = parseOptions(apiKeyOrOptions)
29
+ this.client = createClient(clientOptions)
30
+ }
31
+
32
+ static fromClient(
33
+ client: SeamHttpOptionsWithClient['client'],
34
+ options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
35
+ ): SeamHttpClientSessions {
36
+ const constructorOptions = { ...options, client }
37
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
38
+ throw new SeamHttpInvalidOptionsError('Missing client')
39
+ }
40
+ return new SeamHttpClientSessions(constructorOptions)
41
+ }
42
+
43
+ static fromApiKey(
44
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
45
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
46
+ ): SeamHttpClientSessions {
47
+ const constructorOptions = { ...options, apiKey }
48
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
49
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
50
+ }
51
+ return new SeamHttpClientSessions(constructorOptions)
52
+ }
53
+
54
+ static fromClientSessionToken(
55
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
56
+ options: Omit<
57
+ SeamHttpOptionsWithClientSessionToken,
58
+ 'clientSessionToken'
59
+ > = {},
60
+ ): SeamHttpClientSessions {
61
+ const constructorOptions = { ...options, clientSessionToken }
62
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
63
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
64
+ }
65
+ return new SeamHttpClientSessions(constructorOptions)
66
+ }
67
+
68
+ static async fromPublishableKey(
69
+ publishableKey: string,
70
+ userIdentifierKey: string,
71
+ options: SeamHttpFromPublishableKeyOptions = {},
72
+ ): Promise<SeamHttpClientSessions> {
73
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
74
+ const clientOptions = parseOptions({ ...options, publishableKey })
75
+ const client = createClient(clientOptions)
76
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
77
+ const { token } = await clientSessions.getOrCreate({
78
+ user_identifier_key: userIdentifierKey,
79
+ })
80
+ return SeamHttpClientSessions.fromClientSessionToken(token, options)
81
+ }
82
+
83
+ async create(
84
+ body: ClientSessionsCreateBody,
85
+ ): Promise<ClientSessionsCreateResponse['client_session']> {
86
+ const { data } = await this.client.request<ClientSessionsCreateResponse>({
87
+ url: '/client_sessions/create',
88
+ method: 'post',
89
+ data: body,
90
+ })
91
+ return data.client_session
92
+ }
93
+
94
+ async delete(body: ClientSessionsDeleteBody): Promise<void> {
95
+ await this.client.request<ClientSessionsDeleteResponse>({
96
+ url: '/client_sessions/delete',
97
+ method: 'post',
98
+ data: body,
99
+ })
100
+ }
101
+
102
+ async get(
103
+ body: ClientSessionsGetBody,
104
+ ): Promise<ClientSessionsGetResponse['client_session']> {
105
+ const { data } = await this.client.request<ClientSessionsGetResponse>({
106
+ url: '/client_sessions/get',
107
+ method: 'post',
108
+ data: body,
109
+ })
110
+ return data.client_session
111
+ }
112
+
113
+ async getOrCreate(
114
+ body: ClientSessionsGetOrCreateBody,
115
+ ): Promise<ClientSessionsGetOrCreateResponse['client_session']> {
116
+ const { data } =
117
+ await this.client.request<ClientSessionsGetOrCreateResponse>({
118
+ url: '/client_sessions/get_or_create',
119
+ method: 'post',
120
+ data: body,
121
+ })
122
+ return data.client_session
123
+ }
124
+
125
+ async grantAccess(
126
+ body: ClientSessionsGrantAccessBody,
127
+ ): Promise<ClientSessionsGrantAccessResponse['client_session']> {
128
+ const { data } =
129
+ await this.client.request<ClientSessionsGrantAccessResponse>({
130
+ url: '/client_sessions/grant_access',
131
+ method: 'post',
132
+ data: body,
133
+ })
134
+ return data.client_session
135
+ }
136
+
137
+ async list(
138
+ body: ClientSessionsListBody,
139
+ ): Promise<ClientSessionsListResponse['client_sessions']> {
140
+ const { data } = await this.client.request<ClientSessionsListResponse>({
141
+ url: '/client_sessions/list',
142
+ method: 'post',
143
+ data: body,
144
+ })
145
+ return data.client_sessions
146
+ }
147
+ }
148
+
149
+ export type ClientSessionsCreateBody =
150
+ RouteRequestBody<'/client_sessions/create'>
151
+
152
+ export type ClientSessionsCreateResponse = SetNonNullable<
153
+ Required<RouteResponse<'/client_sessions/create'>>
154
+ >
155
+
156
+ export type ClientSessionsDeleteBody =
157
+ RouteRequestBody<'/client_sessions/delete'>
158
+
159
+ export type ClientSessionsDeleteResponse = SetNonNullable<
160
+ Required<RouteResponse<'/client_sessions/delete'>>
161
+ >
162
+
163
+ export type ClientSessionsGetBody = RouteRequestBody<'/client_sessions/get'>
164
+
165
+ export type ClientSessionsGetResponse = SetNonNullable<
166
+ Required<RouteResponse<'/client_sessions/get'>>
167
+ >
168
+
169
+ export type ClientSessionsGetOrCreateBody =
170
+ RouteRequestBody<'/client_sessions/get_or_create'>
171
+
172
+ export type ClientSessionsGetOrCreateResponse = SetNonNullable<
173
+ Required<RouteResponse<'/client_sessions/get_or_create'>>
174
+ >
175
+
176
+ export type ClientSessionsGrantAccessBody =
177
+ RouteRequestBody<'/client_sessions/grant_access'>
178
+
179
+ export type ClientSessionsGrantAccessResponse = SetNonNullable<
180
+ Required<RouteResponse<'/client_sessions/grant_access'>>
181
+ >
182
+
183
+ export type ClientSessionsListBody = RouteRequestBody<'/client_sessions/list'>
184
+
185
+ export type ClientSessionsListResponse = SetNonNullable<
186
+ Required<RouteResponse<'/client_sessions/list'>>
187
+ >
@@ -0,0 +1,170 @@
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 SeamHttpConnectWebviews {
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
+ ): SeamHttpConnectWebviews {
42
+ const constructorOptions = { ...options, client }
43
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
44
+ throw new SeamHttpInvalidOptionsError('Missing client')
45
+ }
46
+ return new SeamHttpConnectWebviews(constructorOptions)
47
+ }
48
+
49
+ static fromApiKey(
50
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
51
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
52
+ ): SeamHttpConnectWebviews {
53
+ const constructorOptions = { ...options, apiKey }
54
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
55
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
56
+ }
57
+ return new SeamHttpConnectWebviews(constructorOptions)
58
+ }
59
+
60
+ static fromClientSessionToken(
61
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
62
+ options: Omit<
63
+ SeamHttpOptionsWithClientSessionToken,
64
+ 'clientSessionToken'
65
+ > = {},
66
+ ): SeamHttpConnectWebviews {
67
+ const constructorOptions = { ...options, clientSessionToken }
68
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
69
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
70
+ }
71
+ return new SeamHttpConnectWebviews(constructorOptions)
72
+ }
73
+
74
+ static async fromPublishableKey(
75
+ publishableKey: string,
76
+ userIdentifierKey: string,
77
+ options: SeamHttpFromPublishableKeyOptions = {},
78
+ ): Promise<SeamHttpConnectWebviews> {
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 SeamHttpConnectWebviews.fromClientSessionToken(token, options)
87
+ }
88
+
89
+ async create(
90
+ body: ConnectWebviewsCreateBody,
91
+ ): Promise<ConnectWebviewsCreateResponse['connect_webview']> {
92
+ const { data } = await this.client.request<ConnectWebviewsCreateResponse>({
93
+ url: '/connect_webviews/create',
94
+ method: 'post',
95
+ data: body,
96
+ })
97
+ return data.connect_webview
98
+ }
99
+
100
+ async delete(body: ConnectWebviewsDeleteBody): Promise<void> {
101
+ await this.client.request<ConnectWebviewsDeleteResponse>({
102
+ url: '/connect_webviews/delete',
103
+ method: 'post',
104
+ data: body,
105
+ })
106
+ }
107
+
108
+ async get(
109
+ body: ConnectWebviewsGetBody,
110
+ ): Promise<ConnectWebviewsGetResponse['connect_webview']> {
111
+ const { data } = await this.client.request<ConnectWebviewsGetResponse>({
112
+ url: '/connect_webviews/get',
113
+ method: 'post',
114
+ data: body,
115
+ })
116
+ return data.connect_webview
117
+ }
118
+
119
+ async list(
120
+ body: ConnectWebviewsListBody,
121
+ ): Promise<ConnectWebviewsListResponse['connect_webviews']> {
122
+ const { data } = await this.client.request<ConnectWebviewsListResponse>({
123
+ url: '/connect_webviews/list',
124
+ method: 'post',
125
+ data: body,
126
+ })
127
+ return data.connect_webviews
128
+ }
129
+
130
+ async view(params?: ConnectWebviewsViewParams): Promise<void> {
131
+ await this.client.request<ConnectWebviewsViewResponse>({
132
+ url: '/connect_webviews/view',
133
+ method: 'get',
134
+ params,
135
+ })
136
+ }
137
+ }
138
+
139
+ export type ConnectWebviewsCreateBody =
140
+ RouteRequestBody<'/connect_webviews/create'>
141
+
142
+ export type ConnectWebviewsCreateResponse = SetNonNullable<
143
+ Required<RouteResponse<'/connect_webviews/create'>>
144
+ >
145
+
146
+ export type ConnectWebviewsDeleteBody =
147
+ RouteRequestBody<'/connect_webviews/delete'>
148
+
149
+ export type ConnectWebviewsDeleteResponse = SetNonNullable<
150
+ Required<RouteResponse<'/connect_webviews/delete'>>
151
+ >
152
+
153
+ export type ConnectWebviewsGetBody = RouteRequestBody<'/connect_webviews/get'>
154
+
155
+ export type ConnectWebviewsGetResponse = SetNonNullable<
156
+ Required<RouteResponse<'/connect_webviews/get'>>
157
+ >
158
+
159
+ export type ConnectWebviewsListBody = RouteRequestBody<'/connect_webviews/list'>
160
+
161
+ export type ConnectWebviewsListResponse = SetNonNullable<
162
+ Required<RouteResponse<'/connect_webviews/list'>>
163
+ >
164
+
165
+ export type ConnectWebviewsViewParams =
166
+ RouteRequestParams<'/connect_webviews/view'>
167
+
168
+ export type ConnectWebviewsViewResponse = SetNonNullable<
169
+ Required<RouteResponse<'/connect_webviews/view'>>
170
+ >
@@ -0,0 +1,139 @@
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 SeamHttpConnectedAccounts {
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
+ ): SeamHttpConnectedAccounts {
42
+ const constructorOptions = { ...options, client }
43
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
44
+ throw new SeamHttpInvalidOptionsError('Missing client')
45
+ }
46
+ return new SeamHttpConnectedAccounts(constructorOptions)
47
+ }
48
+
49
+ static fromApiKey(
50
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
51
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
52
+ ): SeamHttpConnectedAccounts {
53
+ const constructorOptions = { ...options, apiKey }
54
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
55
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
56
+ }
57
+ return new SeamHttpConnectedAccounts(constructorOptions)
58
+ }
59
+
60
+ static fromClientSessionToken(
61
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
62
+ options: Omit<
63
+ SeamHttpOptionsWithClientSessionToken,
64
+ 'clientSessionToken'
65
+ > = {},
66
+ ): SeamHttpConnectedAccounts {
67
+ const constructorOptions = { ...options, clientSessionToken }
68
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
69
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
70
+ }
71
+ return new SeamHttpConnectedAccounts(constructorOptions)
72
+ }
73
+
74
+ static async fromPublishableKey(
75
+ publishableKey: string,
76
+ userIdentifierKey: string,
77
+ options: SeamHttpFromPublishableKeyOptions = {},
78
+ ): Promise<SeamHttpConnectedAccounts> {
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 SeamHttpConnectedAccounts.fromClientSessionToken(token, options)
87
+ }
88
+
89
+ async delete(body: ConnectedAccountsDeleteBody): Promise<void> {
90
+ await this.client.request<ConnectedAccountsDeleteResponse>({
91
+ url: '/connected_accounts/delete',
92
+ method: 'post',
93
+ data: body,
94
+ })
95
+ }
96
+
97
+ async get(
98
+ body: ConnectedAccountsGetBody,
99
+ ): Promise<ConnectedAccountsGetResponse['connected_account']> {
100
+ const { data } = await this.client.request<ConnectedAccountsGetResponse>({
101
+ url: '/connected_accounts/get',
102
+ method: 'post',
103
+ data: body,
104
+ })
105
+ return data.connected_account
106
+ }
107
+
108
+ async list(
109
+ params?: ConnectedAccountsListParams,
110
+ ): Promise<ConnectedAccountsListResponse['connected_accounts']> {
111
+ const { data } = await this.client.request<ConnectedAccountsListResponse>({
112
+ url: '/connected_accounts/list',
113
+ method: 'get',
114
+ params,
115
+ })
116
+ return data.connected_accounts
117
+ }
118
+ }
119
+
120
+ export type ConnectedAccountsDeleteBody =
121
+ RouteRequestBody<'/connected_accounts/delete'>
122
+
123
+ export type ConnectedAccountsDeleteResponse = SetNonNullable<
124
+ Required<RouteResponse<'/connected_accounts/delete'>>
125
+ >
126
+
127
+ export type ConnectedAccountsGetBody =
128
+ RouteRequestBody<'/connected_accounts/get'>
129
+
130
+ export type ConnectedAccountsGetResponse = SetNonNullable<
131
+ Required<RouteResponse<'/connected_accounts/get'>>
132
+ >
133
+
134
+ export type ConnectedAccountsListParams =
135
+ RouteRequestParams<'/connected_accounts/list'>
136
+
137
+ export type ConnectedAccountsListResponse = SetNonNullable<
138
+ Required<RouteResponse<'/connected_accounts/list'>>
139
+ >