@seamapi/http 1.1.1 → 1.3.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.
@@ -0,0 +1,196 @@
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
+
8
+ import {
9
+ getAuthHeadersForClientSessionToken,
10
+ warnOnInsecureuserIdentifierKey,
11
+ } from 'lib/seam/connect/auth.js'
12
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
13
+ import {
14
+ isSeamHttpOptionsWithApiKey,
15
+ isSeamHttpOptionsWithClient,
16
+ isSeamHttpOptionsWithClientSessionToken,
17
+ isSeamHttpOptionsWithConsoleSessionToken,
18
+ isSeamHttpOptionsWithPersonalAccessToken,
19
+ type SeamHttpFromPublishableKeyOptions,
20
+ SeamHttpInvalidOptionsError,
21
+ type SeamHttpOptions,
22
+ type SeamHttpOptionsWithApiKey,
23
+ type SeamHttpOptionsWithClient,
24
+ type SeamHttpOptionsWithClientSessionToken,
25
+ type SeamHttpOptionsWithConsoleSessionToken,
26
+ type SeamHttpOptionsWithPersonalAccessToken,
27
+ type SeamHttpRequestOptions,
28
+ } from 'lib/seam/connect/options.js'
29
+ import {
30
+ limitToSeamHttpRequestOptions,
31
+ parseOptions,
32
+ } from 'lib/seam/connect/parse-options.js'
33
+ import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
+ import type { SetNonNullable } from 'lib/types.js'
35
+
36
+ import { SeamHttpClientSessions } from './client-sessions.js'
37
+
38
+ export class SeamHttpAcsUsersUnmanaged {
39
+ client: Client
40
+ readonly defaults: Required<SeamHttpRequestOptions>
41
+
42
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
43
+ const options = parseOptions(apiKeyOrOptions)
44
+ this.client = 'client' in options ? options.client : createClient(options)
45
+ this.defaults = limitToSeamHttpRequestOptions(options)
46
+ }
47
+
48
+ static fromClient(
49
+ client: SeamHttpOptionsWithClient['client'],
50
+ options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
51
+ ): SeamHttpAcsUsersUnmanaged {
52
+ const constructorOptions = { ...options, client }
53
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
54
+ throw new SeamHttpInvalidOptionsError('Missing client')
55
+ }
56
+ return new SeamHttpAcsUsersUnmanaged(constructorOptions)
57
+ }
58
+
59
+ static fromApiKey(
60
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
61
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
62
+ ): SeamHttpAcsUsersUnmanaged {
63
+ const constructorOptions = { ...options, apiKey }
64
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
65
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
66
+ }
67
+ return new SeamHttpAcsUsersUnmanaged(constructorOptions)
68
+ }
69
+
70
+ static fromClientSessionToken(
71
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
72
+ options: Omit<
73
+ SeamHttpOptionsWithClientSessionToken,
74
+ 'clientSessionToken'
75
+ > = {},
76
+ ): SeamHttpAcsUsersUnmanaged {
77
+ const constructorOptions = { ...options, clientSessionToken }
78
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
79
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
80
+ }
81
+ return new SeamHttpAcsUsersUnmanaged(constructorOptions)
82
+ }
83
+
84
+ static async fromPublishableKey(
85
+ publishableKey: string,
86
+ userIdentifierKey: string,
87
+ options: SeamHttpFromPublishableKeyOptions = {},
88
+ ): Promise<SeamHttpAcsUsersUnmanaged> {
89
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
90
+ const clientOptions = parseOptions({ ...options, publishableKey })
91
+ if (isSeamHttpOptionsWithClient(clientOptions)) {
92
+ throw new SeamHttpInvalidOptionsError(
93
+ 'The client option cannot be used with SeamHttp.fromPublishableKey',
94
+ )
95
+ }
96
+ const client = createClient(clientOptions)
97
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
98
+ const { token } = await clientSessions.getOrCreate({
99
+ user_identifier_key: userIdentifierKey,
100
+ })
101
+ return SeamHttpAcsUsersUnmanaged.fromClientSessionToken(token, options)
102
+ }
103
+
104
+ static fromConsoleSessionToken(
105
+ consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
106
+ workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
107
+ options: Omit<
108
+ SeamHttpOptionsWithConsoleSessionToken,
109
+ 'consoleSessionToken' | 'workspaceId'
110
+ > = {},
111
+ ): SeamHttpAcsUsersUnmanaged {
112
+ const constructorOptions = { ...options, consoleSessionToken, workspaceId }
113
+ if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
114
+ throw new SeamHttpInvalidOptionsError(
115
+ 'Missing consoleSessionToken or workspaceId',
116
+ )
117
+ }
118
+ return new SeamHttpAcsUsersUnmanaged(constructorOptions)
119
+ }
120
+
121
+ static fromPersonalAccessToken(
122
+ personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
123
+ workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
124
+ options: Omit<
125
+ SeamHttpOptionsWithPersonalAccessToken,
126
+ 'personalAccessToken' | 'workspaceId'
127
+ > = {},
128
+ ): SeamHttpAcsUsersUnmanaged {
129
+ const constructorOptions = { ...options, personalAccessToken, workspaceId }
130
+ if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
131
+ throw new SeamHttpInvalidOptionsError(
132
+ 'Missing personalAccessToken or workspaceId',
133
+ )
134
+ }
135
+ return new SeamHttpAcsUsersUnmanaged(constructorOptions)
136
+ }
137
+
138
+ async updateClientSessionToken(
139
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
140
+ ): Promise<void> {
141
+ const { headers } = this.client.defaults
142
+ const authHeaders = getAuthHeadersForClientSessionToken({
143
+ clientSessionToken,
144
+ })
145
+ for (const key of Object.keys(authHeaders)) {
146
+ if (headers[key] == null) {
147
+ throw new Error(
148
+ 'Cannot update a clientSessionToken on a client created without a clientSessionToken',
149
+ )
150
+ }
151
+ }
152
+ this.client.defaults.headers = { ...headers, ...authHeaders }
153
+ const clientSessions = SeamHttpClientSessions.fromClient(this.client)
154
+ await clientSessions.get()
155
+ }
156
+
157
+ get(
158
+ body?: AcsUsersUnmanagedGetParams,
159
+ ): SeamHttpRequest<AcsUsersUnmanagedGetResponse, 'acs_user'> {
160
+ return new SeamHttpRequest(this, {
161
+ path: '/acs/users/unmanaged/get',
162
+ method: 'post',
163
+ body,
164
+ responseKey: 'acs_user',
165
+ })
166
+ }
167
+
168
+ list(
169
+ body?: AcsUsersUnmanagedListParams,
170
+ ): SeamHttpRequest<AcsUsersUnmanagedListResponse, 'acs_users'> {
171
+ return new SeamHttpRequest(this, {
172
+ path: '/acs/users/unmanaged/list',
173
+ method: 'post',
174
+ body,
175
+ responseKey: 'acs_users',
176
+ })
177
+ }
178
+ }
179
+
180
+ export type AcsUsersUnmanagedGetParams =
181
+ RouteRequestBody<'/acs/users/unmanaged/get'>
182
+
183
+ export type AcsUsersUnmanagedGetResponse = SetNonNullable<
184
+ Required<RouteResponse<'/acs/users/unmanaged/get'>>
185
+ >
186
+
187
+ export type AcsUsersUnmanagedGetOptions = never
188
+
189
+ export type AcsUsersUnmanagedListParams =
190
+ RouteRequestBody<'/acs/users/unmanaged/list'>
191
+
192
+ export type AcsUsersUnmanagedListResponse = SetNonNullable<
193
+ Required<RouteResponse<'/acs/users/unmanaged/list'>>
194
+ >
195
+
196
+ export type AcsUsersUnmanagedListOptions = never
@@ -33,6 +33,7 @@ import {
33
33
  import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
34
34
  import type { SetNonNullable } from 'lib/types.js'
35
35
 
36
+ import { SeamHttpAcsUsersUnmanaged } from './acs-users-unmanaged.js'
36
37
  import { SeamHttpClientSessions } from './client-sessions.js'
37
38
 
38
39
  export class SeamHttpAcsUsers {
@@ -154,6 +155,10 @@ export class SeamHttpAcsUsers {
154
155
  await clientSessions.get()
155
156
  }
156
157
 
158
+ get unmanaged(): SeamHttpAcsUsersUnmanaged {
159
+ return SeamHttpAcsUsersUnmanaged.fromClient(this.client, this.defaults)
160
+ }
161
+
157
162
  addToAccessGroup(
158
163
  body?: AcsUsersAddToAccessGroupBody,
159
164
  ): SeamHttpRequest<void, undefined> {
@@ -9,6 +9,7 @@ export * from './acs-credentials.js'
9
9
  export * from './acs-entrances.js'
10
10
  export * from './acs-systems.js'
11
11
  export * from './acs-users.js'
12
+ export * from './acs-users-unmanaged.js'
12
13
  export * from './action-attempts.js'
13
14
  export * from './client-sessions.js'
14
15
  export * from './connect-webviews.js'
@@ -1,3 +1,3 @@
1
- const seamapiJavascriptHttpVersion = '1.1.1'
1
+ const seamapiJavascriptHttpVersion = '1.3.0'
2
2
 
3
3
  export default seamapiJavascriptHttpVersion