@seamapi/http 0.1.0 → 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 (122) hide show
  1. package/dist/connect.cjs +752 -366
  2. package/dist/connect.cjs.map +1 -1
  3. package/dist/connect.d.cts +186 -142
  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 +3 -2
  8. package/lib/seam/connect/auth.js +55 -4
  9. package/lib/seam/connect/auth.js.map +1 -1
  10. package/lib/seam/connect/client.d.ts +10 -22
  11. package/lib/seam/connect/client.js +17 -77
  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/{client-options.d.ts → options.d.ts} +7 -7
  17. package/lib/seam/connect/{client-options.js → options.js} +5 -10
  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 +34 -16
  21. package/lib/seam/connect/parse-options.js.map +1 -1
  22. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +10 -9
  23. package/lib/seam/connect/routes/access-codes-unmanaged.js +26 -14
  24. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  25. package/lib/seam/connect/routes/access-codes.d.ts +15 -14
  26. package/lib/seam/connect/routes/access-codes.js +29 -17
  27. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  28. package/lib/seam/connect/routes/acs-access-groups.d.ts +13 -12
  29. package/lib/seam/connect/routes/acs-access-groups.js +26 -14
  30. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  31. package/lib/seam/connect/routes/acs-credentials.d.ts +9 -8
  32. package/lib/seam/connect/routes/acs-credentials.js +26 -14
  33. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  34. package/lib/seam/connect/routes/acs-systems.d.ts +9 -8
  35. package/lib/seam/connect/routes/acs-systems.js +29 -17
  36. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  37. package/lib/seam/connect/routes/acs-users.d.ts +18 -11
  38. package/lib/seam/connect/routes/acs-users.js +40 -14
  39. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  40. package/lib/seam/connect/routes/acs.d.ts +5 -4
  41. package/lib/seam/connect/routes/acs.js +26 -14
  42. package/lib/seam/connect/routes/acs.js.map +1 -1
  43. package/lib/seam/connect/routes/action-attempts.d.ts +7 -6
  44. package/lib/seam/connect/routes/action-attempts.js +26 -14
  45. package/lib/seam/connect/routes/action-attempts.js.map +1 -1
  46. package/lib/seam/connect/routes/client-sessions.d.ts +13 -9
  47. package/lib/seam/connect/routes/client-sessions.js +33 -14
  48. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  49. package/lib/seam/connect/routes/connect-webviews.d.ts +11 -10
  50. package/lib/seam/connect/routes/connect-webviews.js +29 -17
  51. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  52. package/lib/seam/connect/routes/connected-accounts.d.ts +8 -7
  53. package/lib/seam/connect/routes/connected-accounts.js +26 -14
  54. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  55. package/lib/seam/connect/routes/devices-unmanaged.d.ts +8 -7
  56. package/lib/seam/connect/routes/devices-unmanaged.js +26 -14
  57. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
  58. package/lib/seam/connect/routes/devices.d.ts +10 -9
  59. package/lib/seam/connect/routes/devices.js +26 -14
  60. package/lib/seam/connect/routes/devices.js.map +1 -1
  61. package/lib/seam/connect/routes/events.d.ts +7 -6
  62. package/lib/seam/connect/routes/events.js +26 -14
  63. package/lib/seam/connect/routes/events.js.map +1 -1
  64. package/lib/seam/connect/routes/locks.d.ts +9 -8
  65. package/lib/seam/connect/routes/locks.js +26 -14
  66. package/lib/seam/connect/routes/locks.js.map +1 -1
  67. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +10 -9
  68. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +26 -14
  69. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  70. package/lib/seam/connect/routes/noise-sensors.d.ts +5 -4
  71. package/lib/seam/connect/routes/noise-sensors.js +26 -14
  72. package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
  73. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +10 -9
  74. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +26 -14
  75. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
  76. package/lib/seam/connect/routes/thermostats.d.ts +13 -12
  77. package/lib/seam/connect/routes/thermostats.js +26 -14
  78. package/lib/seam/connect/routes/thermostats.js.map +1 -1
  79. package/lib/seam/connect/routes/webhooks.d.ts +9 -8
  80. package/lib/seam/connect/routes/webhooks.js +26 -14
  81. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  82. package/lib/seam/connect/routes/workspaces.d.ts +8 -7
  83. package/lib/seam/connect/routes/workspaces.js +26 -14
  84. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  85. package/lib/seam/connect/seam-http.d.ts +24 -0
  86. package/lib/seam/connect/seam-http.js +82 -0
  87. package/lib/seam/connect/seam-http.js.map +1 -0
  88. package/package.json +7 -4
  89. package/src/lib/params-serializer.ts +55 -0
  90. package/src/lib/seam/connect/auth.ts +94 -6
  91. package/src/lib/seam/connect/client.ts +22 -127
  92. package/src/lib/seam/connect/env.d.ts +11 -0
  93. package/src/lib/seam/connect/index.ts +2 -1
  94. package/src/lib/seam/connect/{client-options.ts → options.ts} +13 -19
  95. package/src/lib/seam/connect/parse-options.ts +50 -23
  96. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +44 -31
  97. package/src/lib/seam/connect/routes/access-codes.ts +48 -48
  98. package/src/lib/seam/connect/routes/acs-access-groups.ts +49 -40
  99. package/src/lib/seam/connect/routes/acs-credentials.ts +40 -28
  100. package/src/lib/seam/connect/routes/acs-systems.ts +40 -30
  101. package/src/lib/seam/connect/routes/acs-users.ts +70 -36
  102. package/src/lib/seam/connect/routes/acs.ts +33 -17
  103. package/src/lib/seam/connect/routes/action-attempts.ts +36 -22
  104. package/src/lib/seam/connect/routes/client-sessions.ts +58 -30
  105. package/src/lib/seam/connect/routes/connect-webviews.ts +45 -34
  106. package/src/lib/seam/connect/routes/connected-accounts.ts +40 -25
  107. package/src/lib/seam/connect/routes/devices-unmanaged.ts +39 -25
  108. package/src/lib/seam/connect/routes/devices.ts +39 -31
  109. package/src/lib/seam/connect/routes/events.ts +36 -22
  110. package/src/lib/seam/connect/routes/locks.ts +38 -28
  111. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +47 -31
  112. package/src/lib/seam/connect/routes/noise-sensors.ts +33 -17
  113. package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +47 -31
  114. package/src/lib/seam/connect/routes/thermostats.ts +42 -40
  115. package/src/lib/seam/connect/routes/webhooks.ts +38 -28
  116. package/src/lib/seam/connect/routes/workspaces.ts +38 -25
  117. package/src/lib/seam/connect/seam-http.ts +141 -0
  118. package/lib/seam/connect/axios.d.ts +0 -3
  119. package/lib/seam/connect/axios.js +0 -19
  120. package/lib/seam/connect/axios.js.map +0 -1
  121. package/lib/seam/connect/client-options.js.map +0 -1
  122. package/src/lib/seam/connect/axios.ts +0 -25
@@ -3,54 +3,55 @@
3
3
  * Do not edit this file or add other files to this directory.
4
4
  */
5
5
 
6
- import type { Axios } from 'axios'
7
-
8
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
6
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
7
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
9
8
  import {
10
9
  isSeamHttpOptionsWithApiKey,
11
10
  isSeamHttpOptionsWithClient,
12
11
  isSeamHttpOptionsWithClientSessionToken,
12
+ type SeamHttpFromPublishableKeyOptions,
13
13
  SeamHttpInvalidOptionsError,
14
14
  type SeamHttpOptions,
15
15
  type SeamHttpOptionsWithApiKey,
16
16
  type SeamHttpOptionsWithClient,
17
17
  type SeamHttpOptionsWithClientSessionToken,
18
- } from 'lib/seam/connect/client-options.js'
18
+ } from 'lib/seam/connect/options.js'
19
19
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
20
20
 
21
21
  import { SeamHttpAcsAccessGroups } from './acs-access-groups.js'
22
22
  import { SeamHttpAcsCredentials } from './acs-credentials.js'
23
23
  import { SeamHttpAcsSystems } from './acs-systems.js'
24
24
  import { SeamHttpAcsUsers } from './acs-users.js'
25
+ import { SeamHttpClientSessions } from './client-sessions.js'
25
26
 
26
27
  export class SeamHttpAcs {
27
- client: Axios
28
+ client: Client
28
29
 
29
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
30
- const options = parseOptions(apiKeyOrOptions)
31
- this.client = createAxiosClient(options)
30
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
31
+ const clientOptions = parseOptions(apiKeyOrOptions)
32
+ this.client = createClient(clientOptions)
32
33
  }
33
34
 
34
35
  static fromClient(
35
36
  client: SeamHttpOptionsWithClient['client'],
36
37
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
37
38
  ): SeamHttpAcs {
38
- const opts = { ...options, client }
39
- if (!isSeamHttpOptionsWithClient(opts)) {
39
+ const constructorOptions = { ...options, client }
40
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
40
41
  throw new SeamHttpInvalidOptionsError('Missing client')
41
42
  }
42
- return new SeamHttpAcs(opts)
43
+ return new SeamHttpAcs(constructorOptions)
43
44
  }
44
45
 
45
46
  static fromApiKey(
46
47
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
47
48
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
48
49
  ): SeamHttpAcs {
49
- const opts = { ...options, apiKey }
50
- if (!isSeamHttpOptionsWithApiKey(opts)) {
50
+ const constructorOptions = { ...options, apiKey }
51
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
51
52
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
52
53
  }
53
- return new SeamHttpAcs(opts)
54
+ return new SeamHttpAcs(constructorOptions)
54
55
  }
55
56
 
56
57
  static fromClientSessionToken(
@@ -60,11 +61,26 @@ export class SeamHttpAcs {
60
61
  'clientSessionToken'
61
62
  > = {},
62
63
  ): SeamHttpAcs {
63
- const opts = { ...options, clientSessionToken }
64
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
64
+ const constructorOptions = { ...options, clientSessionToken }
65
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
65
66
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
66
67
  }
67
- return new SeamHttpAcs(opts)
68
+ return new SeamHttpAcs(constructorOptions)
69
+ }
70
+
71
+ static async fromPublishableKey(
72
+ publishableKey: string,
73
+ userIdentifierKey: string,
74
+ options: SeamHttpFromPublishableKeyOptions = {},
75
+ ): Promise<SeamHttpAcs> {
76
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
77
+ const clientOptions = parseOptions({ ...options, publishableKey })
78
+ const client = createClient(clientOptions)
79
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
80
+ const { token } = await clientSessions.getOrCreate({
81
+ user_identifier_key: userIdentifierKey,
82
+ })
83
+ return SeamHttpAcs.fromClientSessionToken(token, options)
68
84
  }
69
85
 
70
86
  get accessGroups(): SeamHttpAcsAccessGroups {
@@ -4,50 +4,53 @@
4
4
  */
5
5
 
6
6
  import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
7
- import type { Axios } from 'axios'
8
7
  import type { SetNonNullable } from 'type-fest'
9
8
 
10
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
9
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
10
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
11
11
  import {
12
12
  isSeamHttpOptionsWithApiKey,
13
13
  isSeamHttpOptionsWithClient,
14
14
  isSeamHttpOptionsWithClientSessionToken,
15
+ type SeamHttpFromPublishableKeyOptions,
15
16
  SeamHttpInvalidOptionsError,
16
17
  type SeamHttpOptions,
17
18
  type SeamHttpOptionsWithApiKey,
18
19
  type SeamHttpOptionsWithClient,
19
20
  type SeamHttpOptionsWithClientSessionToken,
20
- } from 'lib/seam/connect/client-options.js'
21
+ } from 'lib/seam/connect/options.js'
21
22
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
22
23
 
24
+ import { SeamHttpClientSessions } from './client-sessions.js'
25
+
23
26
  export class SeamHttpActionAttempts {
24
- client: Axios
27
+ client: Client
25
28
 
26
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
27
- const options = parseOptions(apiKeyOrOptions)
28
- this.client = createAxiosClient(options)
29
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
30
+ const clientOptions = parseOptions(apiKeyOrOptions)
31
+ this.client = createClient(clientOptions)
29
32
  }
30
33
 
31
34
  static fromClient(
32
35
  client: SeamHttpOptionsWithClient['client'],
33
36
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
34
37
  ): SeamHttpActionAttempts {
35
- const opts = { ...options, client }
36
- if (!isSeamHttpOptionsWithClient(opts)) {
38
+ const constructorOptions = { ...options, client }
39
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
37
40
  throw new SeamHttpInvalidOptionsError('Missing client')
38
41
  }
39
- return new SeamHttpActionAttempts(opts)
42
+ return new SeamHttpActionAttempts(constructorOptions)
40
43
  }
41
44
 
42
45
  static fromApiKey(
43
46
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
44
47
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
45
48
  ): SeamHttpActionAttempts {
46
- const opts = { ...options, apiKey }
47
- if (!isSeamHttpOptionsWithApiKey(opts)) {
49
+ const constructorOptions = { ...options, apiKey }
50
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
48
51
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
49
52
  }
50
- return new SeamHttpActionAttempts(opts)
53
+ return new SeamHttpActionAttempts(constructorOptions)
51
54
  }
52
55
 
53
56
  static fromClientSessionToken(
@@ -57,11 +60,26 @@ export class SeamHttpActionAttempts {
57
60
  'clientSessionToken'
58
61
  > = {},
59
62
  ): SeamHttpActionAttempts {
60
- const opts = { ...options, clientSessionToken }
61
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
63
+ const constructorOptions = { ...options, clientSessionToken }
64
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
62
65
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
63
66
  }
64
- return new SeamHttpActionAttempts(opts)
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)
65
83
  }
66
84
 
67
85
  async get(
@@ -87,17 +105,13 @@ export class SeamHttpActionAttempts {
87
105
  }
88
106
  }
89
107
 
90
- export type ActionAttemptsGetBody = SetNonNullable<
91
- Required<RouteRequestBody<'/action_attempts/get'>>
92
- >
108
+ export type ActionAttemptsGetBody = RouteRequestBody<'/action_attempts/get'>
93
109
 
94
110
  export type ActionAttemptsGetResponse = SetNonNullable<
95
111
  Required<RouteResponse<'/action_attempts/get'>>
96
112
  >
97
113
 
98
- export type ActionAttemptsListBody = SetNonNullable<
99
- Required<RouteRequestBody<'/action_attempts/list'>>
100
- >
114
+ export type ActionAttemptsListBody = RouteRequestBody<'/action_attempts/list'>
101
115
 
102
116
  export type ActionAttemptsListResponse = SetNonNullable<
103
117
  Required<RouteResponse<'/action_attempts/list'>>
@@ -4,50 +4,51 @@
4
4
  */
5
5
 
6
6
  import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
7
- import type { Axios } from 'axios'
8
7
  import type { SetNonNullable } from 'type-fest'
9
8
 
10
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
9
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
10
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
11
11
  import {
12
12
  isSeamHttpOptionsWithApiKey,
13
13
  isSeamHttpOptionsWithClient,
14
14
  isSeamHttpOptionsWithClientSessionToken,
15
+ type SeamHttpFromPublishableKeyOptions,
15
16
  SeamHttpInvalidOptionsError,
16
17
  type SeamHttpOptions,
17
18
  type SeamHttpOptionsWithApiKey,
18
19
  type SeamHttpOptionsWithClient,
19
20
  type SeamHttpOptionsWithClientSessionToken,
20
- } from 'lib/seam/connect/client-options.js'
21
+ } from 'lib/seam/connect/options.js'
21
22
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
22
23
 
23
24
  export class SeamHttpClientSessions {
24
- client: Axios
25
+ client: Client
25
26
 
26
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
27
- const options = parseOptions(apiKeyOrOptions)
28
- this.client = createAxiosClient(options)
27
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
28
+ const clientOptions = parseOptions(apiKeyOrOptions)
29
+ this.client = createClient(clientOptions)
29
30
  }
30
31
 
31
32
  static fromClient(
32
33
  client: SeamHttpOptionsWithClient['client'],
33
34
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
34
35
  ): SeamHttpClientSessions {
35
- const opts = { ...options, client }
36
- if (!isSeamHttpOptionsWithClient(opts)) {
36
+ const constructorOptions = { ...options, client }
37
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
37
38
  throw new SeamHttpInvalidOptionsError('Missing client')
38
39
  }
39
- return new SeamHttpClientSessions(opts)
40
+ return new SeamHttpClientSessions(constructorOptions)
40
41
  }
41
42
 
42
43
  static fromApiKey(
43
44
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
44
45
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
45
46
  ): SeamHttpClientSessions {
46
- const opts = { ...options, apiKey }
47
- if (!isSeamHttpOptionsWithApiKey(opts)) {
47
+ const constructorOptions = { ...options, apiKey }
48
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
48
49
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
49
50
  }
50
- return new SeamHttpClientSessions(opts)
51
+ return new SeamHttpClientSessions(constructorOptions)
51
52
  }
52
53
 
53
54
  static fromClientSessionToken(
@@ -57,11 +58,26 @@ export class SeamHttpClientSessions {
57
58
  'clientSessionToken'
58
59
  > = {},
59
60
  ): SeamHttpClientSessions {
60
- const opts = { ...options, clientSessionToken }
61
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
61
+ const constructorOptions = { ...options, clientSessionToken }
62
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
62
63
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
63
64
  }
64
- return new SeamHttpClientSessions(opts)
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)
65
81
  }
66
82
 
67
83
  async create(
@@ -94,6 +110,18 @@ export class SeamHttpClientSessions {
94
110
  return data.client_session
95
111
  }
96
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
+
97
125
  async grantAccess(
98
126
  body: ClientSessionsGrantAccessBody,
99
127
  ): Promise<ClientSessionsGrantAccessResponse['client_session']> {
@@ -118,41 +146,41 @@ export class SeamHttpClientSessions {
118
146
  }
119
147
  }
120
148
 
121
- export type ClientSessionsCreateBody = SetNonNullable<
122
- Required<RouteRequestBody<'/client_sessions/create'>>
123
- >
149
+ export type ClientSessionsCreateBody =
150
+ RouteRequestBody<'/client_sessions/create'>
124
151
 
125
152
  export type ClientSessionsCreateResponse = SetNonNullable<
126
153
  Required<RouteResponse<'/client_sessions/create'>>
127
154
  >
128
155
 
129
- export type ClientSessionsDeleteBody = SetNonNullable<
130
- Required<RouteRequestBody<'/client_sessions/delete'>>
131
- >
156
+ export type ClientSessionsDeleteBody =
157
+ RouteRequestBody<'/client_sessions/delete'>
132
158
 
133
159
  export type ClientSessionsDeleteResponse = SetNonNullable<
134
160
  Required<RouteResponse<'/client_sessions/delete'>>
135
161
  >
136
162
 
137
- export type ClientSessionsGetBody = SetNonNullable<
138
- Required<RouteRequestBody<'/client_sessions/get'>>
139
- >
163
+ export type ClientSessionsGetBody = RouteRequestBody<'/client_sessions/get'>
140
164
 
141
165
  export type ClientSessionsGetResponse = SetNonNullable<
142
166
  Required<RouteResponse<'/client_sessions/get'>>
143
167
  >
144
168
 
145
- export type ClientSessionsGrantAccessBody = SetNonNullable<
146
- Required<RouteRequestBody<'/client_sessions/grant_access'>>
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'>>
147
174
  >
148
175
 
176
+ export type ClientSessionsGrantAccessBody =
177
+ RouteRequestBody<'/client_sessions/grant_access'>
178
+
149
179
  export type ClientSessionsGrantAccessResponse = SetNonNullable<
150
180
  Required<RouteResponse<'/client_sessions/grant_access'>>
151
181
  >
152
182
 
153
- export type ClientSessionsListBody = SetNonNullable<
154
- Required<RouteRequestBody<'/client_sessions/list'>>
155
- >
183
+ export type ClientSessionsListBody = RouteRequestBody<'/client_sessions/list'>
156
184
 
157
185
  export type ClientSessionsListResponse = SetNonNullable<
158
186
  Required<RouteResponse<'/client_sessions/list'>>
@@ -8,50 +8,53 @@ import type {
8
8
  RouteRequestParams,
9
9
  RouteResponse,
10
10
  } from '@seamapi/types/connect'
11
- import type { Axios } from 'axios'
12
11
  import type { SetNonNullable } from 'type-fest'
13
12
 
14
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
13
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
14
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
15
15
  import {
16
16
  isSeamHttpOptionsWithApiKey,
17
17
  isSeamHttpOptionsWithClient,
18
18
  isSeamHttpOptionsWithClientSessionToken,
19
+ type SeamHttpFromPublishableKeyOptions,
19
20
  SeamHttpInvalidOptionsError,
20
21
  type SeamHttpOptions,
21
22
  type SeamHttpOptionsWithApiKey,
22
23
  type SeamHttpOptionsWithClient,
23
24
  type SeamHttpOptionsWithClientSessionToken,
24
- } from 'lib/seam/connect/client-options.js'
25
+ } from 'lib/seam/connect/options.js'
25
26
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
26
27
 
28
+ import { SeamHttpClientSessions } from './client-sessions.js'
29
+
27
30
  export class SeamHttpConnectWebviews {
28
- client: Axios
31
+ client: Client
29
32
 
30
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
31
- const options = parseOptions(apiKeyOrOptions)
32
- this.client = createAxiosClient(options)
33
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
34
+ const clientOptions = parseOptions(apiKeyOrOptions)
35
+ this.client = createClient(clientOptions)
33
36
  }
34
37
 
35
38
  static fromClient(
36
39
  client: SeamHttpOptionsWithClient['client'],
37
40
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
38
41
  ): SeamHttpConnectWebviews {
39
- const opts = { ...options, client }
40
- if (!isSeamHttpOptionsWithClient(opts)) {
42
+ const constructorOptions = { ...options, client }
43
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
41
44
  throw new SeamHttpInvalidOptionsError('Missing client')
42
45
  }
43
- return new SeamHttpConnectWebviews(opts)
46
+ return new SeamHttpConnectWebviews(constructorOptions)
44
47
  }
45
48
 
46
49
  static fromApiKey(
47
50
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
48
51
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
49
52
  ): SeamHttpConnectWebviews {
50
- const opts = { ...options, apiKey }
51
- if (!isSeamHttpOptionsWithApiKey(opts)) {
53
+ const constructorOptions = { ...options, apiKey }
54
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
52
55
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
53
56
  }
54
- return new SeamHttpConnectWebviews(opts)
57
+ return new SeamHttpConnectWebviews(constructorOptions)
55
58
  }
56
59
 
57
60
  static fromClientSessionToken(
@@ -61,11 +64,26 @@ export class SeamHttpConnectWebviews {
61
64
  'clientSessionToken'
62
65
  > = {},
63
66
  ): SeamHttpConnectWebviews {
64
- const opts = { ...options, clientSessionToken }
65
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
67
+ const constructorOptions = { ...options, clientSessionToken }
68
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
66
69
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
67
70
  }
68
- return new SeamHttpConnectWebviews(opts)
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)
69
87
  }
70
88
 
71
89
  async create(
@@ -99,12 +117,12 @@ export class SeamHttpConnectWebviews {
99
117
  }
100
118
 
101
119
  async list(
102
- params?: ConnectWebviewsListParams,
120
+ body: ConnectWebviewsListBody,
103
121
  ): Promise<ConnectWebviewsListResponse['connect_webviews']> {
104
122
  const { data } = await this.client.request<ConnectWebviewsListResponse>({
105
123
  url: '/connect_webviews/list',
106
- method: 'get',
107
- params,
124
+ method: 'post',
125
+ data: body,
108
126
  })
109
127
  return data.connect_webviews
110
128
  }
@@ -118,41 +136,34 @@ export class SeamHttpConnectWebviews {
118
136
  }
119
137
  }
120
138
 
121
- export type ConnectWebviewsCreateBody = SetNonNullable<
122
- Required<RouteRequestBody<'/connect_webviews/create'>>
123
- >
139
+ export type ConnectWebviewsCreateBody =
140
+ RouteRequestBody<'/connect_webviews/create'>
124
141
 
125
142
  export type ConnectWebviewsCreateResponse = SetNonNullable<
126
143
  Required<RouteResponse<'/connect_webviews/create'>>
127
144
  >
128
145
 
129
- export type ConnectWebviewsDeleteBody = SetNonNullable<
130
- Required<RouteRequestBody<'/connect_webviews/delete'>>
131
- >
146
+ export type ConnectWebviewsDeleteBody =
147
+ RouteRequestBody<'/connect_webviews/delete'>
132
148
 
133
149
  export type ConnectWebviewsDeleteResponse = SetNonNullable<
134
150
  Required<RouteResponse<'/connect_webviews/delete'>>
135
151
  >
136
152
 
137
- export type ConnectWebviewsGetBody = SetNonNullable<
138
- Required<RouteRequestBody<'/connect_webviews/get'>>
139
- >
153
+ export type ConnectWebviewsGetBody = RouteRequestBody<'/connect_webviews/get'>
140
154
 
141
155
  export type ConnectWebviewsGetResponse = SetNonNullable<
142
156
  Required<RouteResponse<'/connect_webviews/get'>>
143
157
  >
144
158
 
145
- export type ConnectWebviewsListParams = SetNonNullable<
146
- Required<RouteRequestParams<'/connect_webviews/list'>>
147
- >
159
+ export type ConnectWebviewsListBody = RouteRequestBody<'/connect_webviews/list'>
148
160
 
149
161
  export type ConnectWebviewsListResponse = SetNonNullable<
150
162
  Required<RouteResponse<'/connect_webviews/list'>>
151
163
  >
152
164
 
153
- export type ConnectWebviewsViewParams = SetNonNullable<
154
- Required<RouteRequestParams<'/connect_webviews/view'>>
155
- >
165
+ export type ConnectWebviewsViewParams =
166
+ RouteRequestParams<'/connect_webviews/view'>
156
167
 
157
168
  export type ConnectWebviewsViewResponse = SetNonNullable<
158
169
  Required<RouteResponse<'/connect_webviews/view'>>
@@ -8,50 +8,53 @@ import type {
8
8
  RouteRequestParams,
9
9
  RouteResponse,
10
10
  } from '@seamapi/types/connect'
11
- import type { Axios } from 'axios'
12
11
  import type { SetNonNullable } from 'type-fest'
13
12
 
14
- import { createAxiosClient } from 'lib/seam/connect/axios.js'
13
+ import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
14
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
15
15
  import {
16
16
  isSeamHttpOptionsWithApiKey,
17
17
  isSeamHttpOptionsWithClient,
18
18
  isSeamHttpOptionsWithClientSessionToken,
19
+ type SeamHttpFromPublishableKeyOptions,
19
20
  SeamHttpInvalidOptionsError,
20
21
  type SeamHttpOptions,
21
22
  type SeamHttpOptionsWithApiKey,
22
23
  type SeamHttpOptionsWithClient,
23
24
  type SeamHttpOptionsWithClientSessionToken,
24
- } from 'lib/seam/connect/client-options.js'
25
+ } from 'lib/seam/connect/options.js'
25
26
  import { parseOptions } from 'lib/seam/connect/parse-options.js'
26
27
 
28
+ import { SeamHttpClientSessions } from './client-sessions.js'
29
+
27
30
  export class SeamHttpConnectedAccounts {
28
- client: Axios
31
+ client: Client
29
32
 
30
- constructor(apiKeyOrOptions: string | SeamHttpOptions) {
31
- const options = parseOptions(apiKeyOrOptions)
32
- this.client = createAxiosClient(options)
33
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
34
+ const clientOptions = parseOptions(apiKeyOrOptions)
35
+ this.client = createClient(clientOptions)
33
36
  }
34
37
 
35
38
  static fromClient(
36
39
  client: SeamHttpOptionsWithClient['client'],
37
40
  options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
38
41
  ): SeamHttpConnectedAccounts {
39
- const opts = { ...options, client }
40
- if (!isSeamHttpOptionsWithClient(opts)) {
42
+ const constructorOptions = { ...options, client }
43
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
41
44
  throw new SeamHttpInvalidOptionsError('Missing client')
42
45
  }
43
- return new SeamHttpConnectedAccounts(opts)
46
+ return new SeamHttpConnectedAccounts(constructorOptions)
44
47
  }
45
48
 
46
49
  static fromApiKey(
47
50
  apiKey: SeamHttpOptionsWithApiKey['apiKey'],
48
51
  options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
49
52
  ): SeamHttpConnectedAccounts {
50
- const opts = { ...options, apiKey }
51
- if (!isSeamHttpOptionsWithApiKey(opts)) {
53
+ const constructorOptions = { ...options, apiKey }
54
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
52
55
  throw new SeamHttpInvalidOptionsError('Missing apiKey')
53
56
  }
54
- return new SeamHttpConnectedAccounts(opts)
57
+ return new SeamHttpConnectedAccounts(constructorOptions)
55
58
  }
56
59
 
57
60
  static fromClientSessionToken(
@@ -61,11 +64,26 @@ export class SeamHttpConnectedAccounts {
61
64
  'clientSessionToken'
62
65
  > = {},
63
66
  ): SeamHttpConnectedAccounts {
64
- const opts = { ...options, clientSessionToken }
65
- if (!isSeamHttpOptionsWithClientSessionToken(opts)) {
67
+ const constructorOptions = { ...options, clientSessionToken }
68
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
66
69
  throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
67
70
  }
68
- return new SeamHttpConnectedAccounts(opts)
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)
69
87
  }
70
88
 
71
89
  async delete(body: ConnectedAccountsDeleteBody): Promise<void> {
@@ -99,25 +117,22 @@ export class SeamHttpConnectedAccounts {
99
117
  }
100
118
  }
101
119
 
102
- export type ConnectedAccountsDeleteBody = SetNonNullable<
103
- Required<RouteRequestBody<'/connected_accounts/delete'>>
104
- >
120
+ export type ConnectedAccountsDeleteBody =
121
+ RouteRequestBody<'/connected_accounts/delete'>
105
122
 
106
123
  export type ConnectedAccountsDeleteResponse = SetNonNullable<
107
124
  Required<RouteResponse<'/connected_accounts/delete'>>
108
125
  >
109
126
 
110
- export type ConnectedAccountsGetBody = SetNonNullable<
111
- Required<RouteRequestBody<'/connected_accounts/get'>>
112
- >
127
+ export type ConnectedAccountsGetBody =
128
+ RouteRequestBody<'/connected_accounts/get'>
113
129
 
114
130
  export type ConnectedAccountsGetResponse = SetNonNullable<
115
131
  Required<RouteResponse<'/connected_accounts/get'>>
116
132
  >
117
133
 
118
- export type ConnectedAccountsListParams = SetNonNullable<
119
- Required<RouteRequestParams<'/connected_accounts/list'>>
120
- >
134
+ export type ConnectedAccountsListParams =
135
+ RouteRequestParams<'/connected_accounts/list'>
121
136
 
122
137
  export type ConnectedAccountsListResponse = SetNonNullable<
123
138
  Required<RouteResponse<'/connected_accounts/list'>>