@seamapi/http 0.12.0 → 0.14.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 (50) hide show
  1. package/README.md +12 -0
  2. package/connect.d.ts +1 -0
  3. package/connect.js +1 -0
  4. package/connect.js.map +1 -1
  5. package/dist/connect.cjs +279 -50
  6. package/dist/connect.cjs.map +1 -1
  7. package/dist/connect.d.cts +70 -7
  8. package/lib/seam/connect/auth.js +2 -1
  9. package/lib/seam/connect/auth.js.map +1 -1
  10. package/lib/seam/connect/client.js +2 -2
  11. package/lib/seam/connect/client.js.map +1 -1
  12. package/lib/seam/connect/index.d.ts +0 -1
  13. package/lib/seam/connect/index.js +0 -1
  14. package/lib/seam/connect/index.js.map +1 -1
  15. package/lib/seam/connect/routes/index.d.ts +3 -0
  16. package/lib/seam/connect/routes/index.js +3 -0
  17. package/lib/seam/connect/routes/index.js.map +1 -1
  18. package/lib/seam/connect/routes/networks.d.ts +23 -0
  19. package/lib/seam/connect/routes/networks.js +81 -0
  20. package/lib/seam/connect/routes/networks.js.map +1 -0
  21. package/lib/seam/connect/routes/phones.d.ts +19 -0
  22. package/lib/seam/connect/routes/phones.js +73 -0
  23. package/lib/seam/connect/routes/phones.js.map +1 -0
  24. package/lib/seam/connect/routes/user-identities-enrollment-automations.d.ts +27 -0
  25. package/lib/seam/connect/routes/user-identities-enrollment-automations.js +89 -0
  26. package/lib/seam/connect/routes/user-identities-enrollment-automations.js.map +1 -0
  27. package/lib/seam/connect/routes/user-identities.d.ts +6 -0
  28. package/lib/seam/connect/routes/user-identities.js +12 -0
  29. package/lib/seam/connect/routes/user-identities.js.map +1 -1
  30. package/lib/seam/connect/seam-http.d.ts +3 -1
  31. package/lib/seam/connect/seam-http.js +7 -1
  32. package/lib/seam/connect/seam-http.js.map +1 -1
  33. package/lib/version.d.ts +1 -1
  34. package/lib/version.js +1 -1
  35. package/package.json +4 -3
  36. package/src/connect.ts +1 -0
  37. package/src/lib/seam/connect/auth.ts +2 -1
  38. package/src/lib/seam/connect/client.ts +2 -3
  39. package/src/lib/seam/connect/index.ts +0 -1
  40. package/src/lib/seam/connect/routes/index.ts +3 -0
  41. package/src/lib/seam/connect/routes/networks.ts +171 -0
  42. package/src/lib/seam/connect/routes/phones.ts +151 -0
  43. package/src/lib/seam/connect/routes/user-identities-enrollment-automations.ts +214 -0
  44. package/src/lib/seam/connect/routes/user-identities.ts +30 -0
  45. package/src/lib/seam/connect/seam-http.ts +10 -0
  46. package/src/lib/version.ts +1 -1
  47. package/lib/params-serializer.d.ts +0 -5
  48. package/lib/params-serializer.js +0 -40
  49. package/lib/params-serializer.js.map +0 -1
  50. package/src/lib/params-serializer.ts +0 -44
@@ -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 { 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
+ isSeamHttpOptionsWithConsoleSessionToken,
16
+ isSeamHttpOptionsWithPersonalAccessToken,
17
+ type SeamHttpFromPublishableKeyOptions,
18
+ SeamHttpInvalidOptionsError,
19
+ type SeamHttpOptions,
20
+ type SeamHttpOptionsWithApiKey,
21
+ type SeamHttpOptionsWithClient,
22
+ type SeamHttpOptionsWithClientSessionToken,
23
+ type SeamHttpOptionsWithConsoleSessionToken,
24
+ type SeamHttpOptionsWithPersonalAccessToken,
25
+ type SeamHttpRequestOptions,
26
+ } from 'lib/seam/connect/options.js'
27
+ import {
28
+ limitToSeamHttpRequestOptions,
29
+ parseOptions,
30
+ } from 'lib/seam/connect/parse-options.js'
31
+
32
+ import { SeamHttpClientSessions } from './client-sessions.js'
33
+
34
+ export class SeamHttpPhones {
35
+ client: Client
36
+ readonly defaults: Required<SeamHttpRequestOptions>
37
+
38
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
39
+ const options = parseOptions(apiKeyOrOptions)
40
+ this.client = 'client' in options ? options.client : createClient(options)
41
+ this.defaults = limitToSeamHttpRequestOptions(options)
42
+ }
43
+
44
+ static fromClient(
45
+ client: SeamHttpOptionsWithClient['client'],
46
+ options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
47
+ ): SeamHttpPhones {
48
+ const constructorOptions = { ...options, client }
49
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
50
+ throw new SeamHttpInvalidOptionsError('Missing client')
51
+ }
52
+ return new SeamHttpPhones(constructorOptions)
53
+ }
54
+
55
+ static fromApiKey(
56
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
57
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
58
+ ): SeamHttpPhones {
59
+ const constructorOptions = { ...options, apiKey }
60
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
61
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
62
+ }
63
+ return new SeamHttpPhones(constructorOptions)
64
+ }
65
+
66
+ static fromClientSessionToken(
67
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
68
+ options: Omit<
69
+ SeamHttpOptionsWithClientSessionToken,
70
+ 'clientSessionToken'
71
+ > = {},
72
+ ): SeamHttpPhones {
73
+ const constructorOptions = { ...options, clientSessionToken }
74
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
75
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
76
+ }
77
+ return new SeamHttpPhones(constructorOptions)
78
+ }
79
+
80
+ static async fromPublishableKey(
81
+ publishableKey: string,
82
+ userIdentifierKey: string,
83
+ options: SeamHttpFromPublishableKeyOptions = {},
84
+ ): Promise<SeamHttpPhones> {
85
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
86
+ const clientOptions = parseOptions({ ...options, publishableKey })
87
+ if (isSeamHttpOptionsWithClient(clientOptions)) {
88
+ throw new SeamHttpInvalidOptionsError(
89
+ 'The client option cannot be used with SeamHttp.fromPublishableKey',
90
+ )
91
+ }
92
+ const client = createClient(clientOptions)
93
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
94
+ const { token } = await clientSessions.getOrCreate({
95
+ user_identifier_key: userIdentifierKey,
96
+ })
97
+ return SeamHttpPhones.fromClientSessionToken(token, options)
98
+ }
99
+
100
+ static fromConsoleSessionToken(
101
+ consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
102
+ workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
103
+ options: Omit<
104
+ SeamHttpOptionsWithConsoleSessionToken,
105
+ 'consoleSessionToken' | 'workspaceId'
106
+ > = {},
107
+ ): SeamHttpPhones {
108
+ const constructorOptions = { ...options, consoleSessionToken, workspaceId }
109
+ if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
110
+ throw new SeamHttpInvalidOptionsError(
111
+ 'Missing consoleSessionToken or workspaceId',
112
+ )
113
+ }
114
+ return new SeamHttpPhones(constructorOptions)
115
+ }
116
+
117
+ static fromPersonalAccessToken(
118
+ personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
119
+ workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
120
+ options: Omit<
121
+ SeamHttpOptionsWithPersonalAccessToken,
122
+ 'personalAccessToken' | 'workspaceId'
123
+ > = {},
124
+ ): SeamHttpPhones {
125
+ const constructorOptions = { ...options, personalAccessToken, workspaceId }
126
+ if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
127
+ throw new SeamHttpInvalidOptionsError(
128
+ 'Missing personalAccessToken or workspaceId',
129
+ )
130
+ }
131
+ return new SeamHttpPhones(constructorOptions)
132
+ }
133
+
134
+ async list(body?: PhonesListParams): Promise<PhonesListResponse['phones']> {
135
+ const { data } = await this.client.request<PhonesListResponse>({
136
+ url: '/phones/list',
137
+ method: 'post',
138
+ data: body,
139
+ })
140
+
141
+ return data.phones
142
+ }
143
+ }
144
+
145
+ export type PhonesListParams = RouteRequestBody<'/phones/list'>
146
+
147
+ export type PhonesListResponse = SetNonNullable<
148
+ Required<RouteResponse<'/phones/list'>>
149
+ >
150
+
151
+ export type PhonesListOptions = never
@@ -0,0 +1,214 @@
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
+ isSeamHttpOptionsWithConsoleSessionToken,
16
+ isSeamHttpOptionsWithPersonalAccessToken,
17
+ type SeamHttpFromPublishableKeyOptions,
18
+ SeamHttpInvalidOptionsError,
19
+ type SeamHttpOptions,
20
+ type SeamHttpOptionsWithApiKey,
21
+ type SeamHttpOptionsWithClient,
22
+ type SeamHttpOptionsWithClientSessionToken,
23
+ type SeamHttpOptionsWithConsoleSessionToken,
24
+ type SeamHttpOptionsWithPersonalAccessToken,
25
+ type SeamHttpRequestOptions,
26
+ } from 'lib/seam/connect/options.js'
27
+ import {
28
+ limitToSeamHttpRequestOptions,
29
+ parseOptions,
30
+ } from 'lib/seam/connect/parse-options.js'
31
+
32
+ import { SeamHttpClientSessions } from './client-sessions.js'
33
+
34
+ export class SeamHttpUserIdentitiesEnrollmentAutomations {
35
+ client: Client
36
+ readonly defaults: Required<SeamHttpRequestOptions>
37
+
38
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
39
+ const options = parseOptions(apiKeyOrOptions)
40
+ this.client = 'client' in options ? options.client : createClient(options)
41
+ this.defaults = limitToSeamHttpRequestOptions(options)
42
+ }
43
+
44
+ static fromClient(
45
+ client: SeamHttpOptionsWithClient['client'],
46
+ options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
47
+ ): SeamHttpUserIdentitiesEnrollmentAutomations {
48
+ const constructorOptions = { ...options, client }
49
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
50
+ throw new SeamHttpInvalidOptionsError('Missing client')
51
+ }
52
+ return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions)
53
+ }
54
+
55
+ static fromApiKey(
56
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
57
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
58
+ ): SeamHttpUserIdentitiesEnrollmentAutomations {
59
+ const constructorOptions = { ...options, apiKey }
60
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
61
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
62
+ }
63
+ return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions)
64
+ }
65
+
66
+ static fromClientSessionToken(
67
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
68
+ options: Omit<
69
+ SeamHttpOptionsWithClientSessionToken,
70
+ 'clientSessionToken'
71
+ > = {},
72
+ ): SeamHttpUserIdentitiesEnrollmentAutomations {
73
+ const constructorOptions = { ...options, clientSessionToken }
74
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
75
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
76
+ }
77
+ return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions)
78
+ }
79
+
80
+ static async fromPublishableKey(
81
+ publishableKey: string,
82
+ userIdentifierKey: string,
83
+ options: SeamHttpFromPublishableKeyOptions = {},
84
+ ): Promise<SeamHttpUserIdentitiesEnrollmentAutomations> {
85
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
86
+ const clientOptions = parseOptions({ ...options, publishableKey })
87
+ if (isSeamHttpOptionsWithClient(clientOptions)) {
88
+ throw new SeamHttpInvalidOptionsError(
89
+ 'The client option cannot be used with SeamHttp.fromPublishableKey',
90
+ )
91
+ }
92
+ const client = createClient(clientOptions)
93
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
94
+ const { token } = await clientSessions.getOrCreate({
95
+ user_identifier_key: userIdentifierKey,
96
+ })
97
+ return SeamHttpUserIdentitiesEnrollmentAutomations.fromClientSessionToken(
98
+ token,
99
+ options,
100
+ )
101
+ }
102
+
103
+ static fromConsoleSessionToken(
104
+ consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
105
+ workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
106
+ options: Omit<
107
+ SeamHttpOptionsWithConsoleSessionToken,
108
+ 'consoleSessionToken' | 'workspaceId'
109
+ > = {},
110
+ ): SeamHttpUserIdentitiesEnrollmentAutomations {
111
+ const constructorOptions = { ...options, consoleSessionToken, workspaceId }
112
+ if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
113
+ throw new SeamHttpInvalidOptionsError(
114
+ 'Missing consoleSessionToken or workspaceId',
115
+ )
116
+ }
117
+ return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions)
118
+ }
119
+
120
+ static fromPersonalAccessToken(
121
+ personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
122
+ workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
123
+ options: Omit<
124
+ SeamHttpOptionsWithPersonalAccessToken,
125
+ 'personalAccessToken' | 'workspaceId'
126
+ > = {},
127
+ ): SeamHttpUserIdentitiesEnrollmentAutomations {
128
+ const constructorOptions = { ...options, personalAccessToken, workspaceId }
129
+ if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
130
+ throw new SeamHttpInvalidOptionsError(
131
+ 'Missing personalAccessToken or workspaceId',
132
+ )
133
+ }
134
+ return new SeamHttpUserIdentitiesEnrollmentAutomations(constructorOptions)
135
+ }
136
+
137
+ async get(
138
+ body?: UserIdentitiesEnrollmentAutomationsGetParams,
139
+ ): Promise<
140
+ UserIdentitiesEnrollmentAutomationsGetResponse['enrollment_automation']
141
+ > {
142
+ const { data } =
143
+ await this.client.request<UserIdentitiesEnrollmentAutomationsGetResponse>(
144
+ {
145
+ url: '/user_identities/enrollment_automations/get',
146
+ method: 'post',
147
+ data: body,
148
+ },
149
+ )
150
+
151
+ return data.enrollment_automation
152
+ }
153
+
154
+ async launch(
155
+ body?: UserIdentitiesEnrollmentAutomationsLaunchBody,
156
+ ): Promise<
157
+ UserIdentitiesEnrollmentAutomationsLaunchResponse['enrollment_automation']
158
+ > {
159
+ const { data } =
160
+ await this.client.request<UserIdentitiesEnrollmentAutomationsLaunchResponse>(
161
+ {
162
+ url: '/user_identities/enrollment_automations/launch',
163
+ method: 'post',
164
+ data: body,
165
+ },
166
+ )
167
+
168
+ return data.enrollment_automation
169
+ }
170
+
171
+ async list(
172
+ body?: UserIdentitiesEnrollmentAutomationsListParams,
173
+ ): Promise<
174
+ UserIdentitiesEnrollmentAutomationsListResponse['enrollment_automations']
175
+ > {
176
+ const { data } =
177
+ await this.client.request<UserIdentitiesEnrollmentAutomationsListResponse>(
178
+ {
179
+ url: '/user_identities/enrollment_automations/list',
180
+ method: 'post',
181
+ data: body,
182
+ },
183
+ )
184
+
185
+ return data.enrollment_automations
186
+ }
187
+ }
188
+
189
+ export type UserIdentitiesEnrollmentAutomationsGetParams =
190
+ RouteRequestBody<'/user_identities/enrollment_automations/get'>
191
+
192
+ export type UserIdentitiesEnrollmentAutomationsGetResponse = SetNonNullable<
193
+ Required<RouteResponse<'/user_identities/enrollment_automations/get'>>
194
+ >
195
+
196
+ export type UserIdentitiesEnrollmentAutomationsGetOptions = never
197
+
198
+ export type UserIdentitiesEnrollmentAutomationsLaunchBody =
199
+ RouteRequestBody<'/user_identities/enrollment_automations/launch'>
200
+
201
+ export type UserIdentitiesEnrollmentAutomationsLaunchResponse = SetNonNullable<
202
+ Required<RouteResponse<'/user_identities/enrollment_automations/launch'>>
203
+ >
204
+
205
+ export type UserIdentitiesEnrollmentAutomationsLaunchOptions = never
206
+
207
+ export type UserIdentitiesEnrollmentAutomationsListParams =
208
+ RouteRequestBody<'/user_identities/enrollment_automations/list'>
209
+
210
+ export type UserIdentitiesEnrollmentAutomationsListResponse = SetNonNullable<
211
+ Required<RouteResponse<'/user_identities/enrollment_automations/list'>>
212
+ >
213
+
214
+ export type UserIdentitiesEnrollmentAutomationsListOptions = never
@@ -34,6 +34,7 @@ import {
34
34
  } from 'lib/seam/connect/parse-options.js'
35
35
 
36
36
  import { SeamHttpClientSessions } from './client-sessions.js'
37
+ import { SeamHttpUserIdentitiesEnrollmentAutomations } from './user-identities-enrollment-automations.js'
37
38
 
38
39
  export class SeamHttpUserIdentities {
39
40
  client: Client
@@ -135,6 +136,13 @@ export class SeamHttpUserIdentities {
135
136
  return new SeamHttpUserIdentities(constructorOptions)
136
137
  }
137
138
 
139
+ get enrollmentAutomations(): SeamHttpUserIdentitiesEnrollmentAutomations {
140
+ return SeamHttpUserIdentitiesEnrollmentAutomations.fromClient(
141
+ this.client,
142
+ this.defaults,
143
+ )
144
+ }
145
+
138
146
  async addAcsUser(body?: UserIdentitiesAddAcsUserBody): Promise<void> {
139
147
  await this.client.request<UserIdentitiesAddAcsUserResponse>({
140
148
  url: '/user_identities/add_acs_user',
@@ -204,6 +212,19 @@ export class SeamHttpUserIdentities {
204
212
  return data.accessible_devices
205
213
  }
206
214
 
215
+ async listAcsSystems(
216
+ body?: UserIdentitiesListAcsSystemsParams,
217
+ ): Promise<UserIdentitiesListAcsSystemsResponse['acs_systems']> {
218
+ const { data } =
219
+ await this.client.request<UserIdentitiesListAcsSystemsResponse>({
220
+ url: '/user_identities/list_acs_systems',
221
+ method: 'post',
222
+ data: body,
223
+ })
224
+
225
+ return data.acs_systems
226
+ }
227
+
207
228
  async listAcsUsers(
208
229
  body?: UserIdentitiesListAcsUsersParams,
209
230
  ): Promise<UserIdentitiesListAcsUsersResponse['acs_users']> {
@@ -289,6 +310,15 @@ export type UserIdentitiesListAccessibleDevicesResponse = SetNonNullable<
289
310
 
290
311
  export type UserIdentitiesListAccessibleDevicesOptions = never
291
312
 
313
+ export type UserIdentitiesListAcsSystemsParams =
314
+ RouteRequestBody<'/user_identities/list_acs_systems'>
315
+
316
+ export type UserIdentitiesListAcsSystemsResponse = SetNonNullable<
317
+ Required<RouteResponse<'/user_identities/list_acs_systems'>>
318
+ >
319
+
320
+ export type UserIdentitiesListAcsSystemsOptions = never
321
+
292
322
  export type UserIdentitiesListAcsUsersParams =
293
323
  RouteRequestBody<'/user_identities/list_acs_users'>
294
324
 
@@ -27,7 +27,9 @@ import {
27
27
  SeamHttpDevices,
28
28
  SeamHttpEvents,
29
29
  SeamHttpLocks,
30
+ SeamHttpNetworks,
30
31
  SeamHttpNoiseSensors,
32
+ SeamHttpPhones,
31
33
  SeamHttpThermostats,
32
34
  SeamHttpUserIdentities,
33
35
  SeamHttpWebhooks,
@@ -170,10 +172,18 @@ export class SeamHttp {
170
172
  return SeamHttpLocks.fromClient(this.client, this.defaults)
171
173
  }
172
174
 
175
+ get networks(): SeamHttpNetworks {
176
+ return SeamHttpNetworks.fromClient(this.client, this.defaults)
177
+ }
178
+
173
179
  get noiseSensors(): SeamHttpNoiseSensors {
174
180
  return SeamHttpNoiseSensors.fromClient(this.client, this.defaults)
175
181
  }
176
182
 
183
+ get phones(): SeamHttpPhones {
184
+ return SeamHttpPhones.fromClient(this.client, this.defaults)
185
+ }
186
+
177
187
  get thermostats(): SeamHttpThermostats {
178
188
  return SeamHttpThermostats.fromClient(this.client, this.defaults)
179
189
  }
@@ -1,3 +1,3 @@
1
- const seamapiJavascriptHttpVersion = '0.12.0'
1
+ const seamapiJavascriptHttpVersion = '0.14.0'
2
2
 
3
3
  export default seamapiJavascriptHttpVersion
@@ -1,5 +0,0 @@
1
- import type { CustomParamsSerializer } from 'axios';
2
- export declare const paramsSerializer: CustomParamsSerializer;
3
- export declare class UnserializableParamError extends Error {
4
- constructor(name: string, message: string);
5
- }
@@ -1,40 +0,0 @@
1
- export const paramsSerializer = (params) => {
2
- const searchParams = new URLSearchParams();
3
- for (const [name, value] of Object.entries(params)) {
4
- if (value == null)
5
- continue;
6
- if (Array.isArray(value)) {
7
- if (value.length === 0)
8
- searchParams.set(name, '');
9
- if (value.length === 1 && value[0] === '') {
10
- throw new UnserializableParamError(name, `is a single element array containing the empty string which is unsupported because it serializes to the empty array`);
11
- }
12
- for (const v of value) {
13
- searchParams.append(name, serialize(name, v));
14
- }
15
- continue;
16
- }
17
- searchParams.set(name, serialize(name, value));
18
- }
19
- searchParams.sort();
20
- return searchParams.toString();
21
- };
22
- const serialize = (k, v) => {
23
- if (typeof v === 'string')
24
- return v.toString();
25
- if (typeof v === 'number')
26
- return v.toString();
27
- if (typeof v === 'bigint')
28
- return v.toString();
29
- if (typeof v === 'boolean')
30
- return v.toString();
31
- throw new UnserializableParamError(k, `is a ${typeof v}`);
32
- };
33
- export class UnserializableParamError extends Error {
34
- constructor(name, message) {
35
- super(`Could not serialize parameter: '${name}' ${message}`);
36
- this.name = this.constructor.name;
37
- Error.captureStackTrace(this, this.constructor);
38
- }
39
- }
40
- //# sourceMappingURL=params-serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"params-serializer.js","sourceRoot":"","sources":["../src/lib/params-serializer.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAA2B,CAAC,MAAM,EAAE,EAAE;IACjE,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAA;IAE1C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,IAAI,KAAK,IAAI,IAAI;YAAE,SAAQ;QAE3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;YAClD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;gBAC1C,MAAM,IAAI,wBAAwB,CAChC,IAAI,EACJ,qHAAqH,CACtH,CAAA;YACH,CAAC;YACD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;gBACtB,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YAC/C,CAAC;YACD,SAAQ;QACV,CAAC;QAED,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,YAAY,CAAC,IAAI,EAAE,CAAA;IACnB,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,CAAU,EAAU,EAAE;IAClD,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC9C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC9C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC9C,IAAI,OAAO,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC/C,MAAM,IAAI,wBAAwB,CAAC,CAAC,EAAE,QAAQ,OAAO,CAAC,EAAE,CAAC,CAAA;AAC3D,CAAC,CAAA;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,mCAAmC,IAAI,KAAK,OAAO,EAAE,CAAC,CAAA;QAC5D,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"}
@@ -1,44 +0,0 @@
1
- import type { CustomParamsSerializer } from 'axios'
2
-
3
- export const paramsSerializer: CustomParamsSerializer = (params) => {
4
- const searchParams = new URLSearchParams()
5
-
6
- for (const [name, value] of Object.entries(params)) {
7
- if (value == null) continue
8
-
9
- if (Array.isArray(value)) {
10
- if (value.length === 0) searchParams.set(name, '')
11
- if (value.length === 1 && value[0] === '') {
12
- throw new UnserializableParamError(
13
- name,
14
- `is a single element array containing the empty string which is unsupported because it serializes to the empty array`,
15
- )
16
- }
17
- for (const v of value) {
18
- searchParams.append(name, serialize(name, v))
19
- }
20
- continue
21
- }
22
-
23
- searchParams.set(name, serialize(name, value))
24
- }
25
-
26
- searchParams.sort()
27
- return searchParams.toString()
28
- }
29
-
30
- const serialize = (k: string, v: unknown): string => {
31
- if (typeof v === 'string') return v.toString()
32
- if (typeof v === 'number') return v.toString()
33
- if (typeof v === 'bigint') return v.toString()
34
- if (typeof v === 'boolean') return v.toString()
35
- throw new UnserializableParamError(k, `is a ${typeof v}`)
36
- }
37
-
38
- export class UnserializableParamError extends Error {
39
- constructor(name: string, message: string) {
40
- super(`Could not serialize parameter: '${name}' ${message}`)
41
- this.name = this.constructor.name
42
- Error.captureStackTrace(this, this.constructor)
43
- }
44
- }