@createiq/backend 1.0.105 → 1.0.107

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.
@@ -3,12 +3,7 @@
3
3
  import { createSseClient } from '../core/serverSentEvents.gen';
4
4
  import type { HttpMethod } from '../core/types.gen';
5
5
  import { getValidRequestBody } from '../core/utils.gen';
6
- import type {
7
- Client,
8
- Config,
9
- RequestOptions,
10
- ResolvedRequestOptions,
11
- } from './types.gen';
6
+ import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
12
7
  import {
13
8
  buildUrl,
14
9
  createConfig,
@@ -34,20 +29,22 @@ export const createClient = (config: Config = {}): Client => {
34
29
  return getConfig();
35
30
  };
36
31
 
37
- const interceptors = createInterceptors<
38
- Request,
39
- Response,
40
- unknown,
41
- ResolvedRequestOptions
42
- >();
32
+ const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
43
33
 
44
- const beforeRequest = async (options: RequestOptions) => {
34
+ const beforeRequest = async <
35
+ TData = unknown,
36
+ TResponseStyle extends 'data' | 'fields' = 'fields',
37
+ ThrowOnError extends boolean = boolean,
38
+ Url extends string = string,
39
+ >(
40
+ options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
41
+ ) => {
45
42
  const opts = {
46
43
  ..._config,
47
44
  ...options,
48
45
  fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
49
46
  headers: mergeHeaders(_config.headers, options.headers),
50
- serializedBody: undefined,
47
+ serializedBody: undefined as string | undefined,
51
48
  };
52
49
 
53
50
  if (opts.security) {
@@ -62,7 +59,7 @@ export const createClient = (config: Config = {}): Client => {
62
59
  }
63
60
 
64
61
  if (opts.body !== undefined && opts.bodySerializer) {
65
- opts.serializedBody = opts.bodySerializer(opts.body);
62
+ opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
66
63
  }
67
64
 
68
65
  // remove Content-Type header if body is empty to avoid sending invalid requests
@@ -70,13 +67,14 @@ export const createClient = (config: Config = {}): Client => {
70
67
  opts.headers.delete('Content-Type');
71
68
  }
72
69
 
73
- const url = buildUrl(opts);
70
+ const resolvedOpts = opts as typeof opts &
71
+ ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
72
+ const url = buildUrl(resolvedOpts);
74
73
 
75
- return { opts, url };
74
+ return { opts: resolvedOpts, url };
76
75
  };
77
76
 
78
77
  const request: Client['request'] = async (options) => {
79
- // @ts-expect-error
80
78
  const { opts, url } = await beforeRequest(options);
81
79
  const requestInit: ReqInit = {
82
80
  redirect: 'follow',
@@ -95,7 +93,35 @@ export const createClient = (config: Config = {}): Client => {
95
93
  // fetch must be assigned here, otherwise it would throw the error:
96
94
  // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
97
95
  const _fetch = opts.fetch!;
98
- let response = await _fetch(request);
96
+ let response: Response;
97
+
98
+ try {
99
+ response = await _fetch(request);
100
+ } catch (error) {
101
+ // Handle fetch exceptions (AbortError, network errors, etc.)
102
+ let finalError = error;
103
+
104
+ for (const fn of interceptors.error.fns) {
105
+ if (fn) {
106
+ finalError = (await fn(error, undefined as any, request, opts)) as unknown;
107
+ }
108
+ }
109
+
110
+ finalError = finalError || ({} as unknown);
111
+
112
+ if (opts.throwOnError) {
113
+ throw finalError;
114
+ }
115
+
116
+ // Return error response
117
+ return opts.responseStyle === 'data'
118
+ ? undefined
119
+ : {
120
+ error: finalError,
121
+ request,
122
+ response: undefined as any,
123
+ };
124
+ }
99
125
 
100
126
  for (const fn of interceptors.response.fns) {
101
127
  if (fn) {
@@ -114,10 +140,7 @@ export const createClient = (config: Config = {}): Client => {
114
140
  ? getParseAs(response.headers.get('Content-Type'))
115
141
  : opts.parseAs) ?? 'json';
116
142
 
117
- if (
118
- response.status === 204 ||
119
- response.headers.get('Content-Length') === '0'
120
- ) {
143
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
121
144
  let emptyData: any;
122
145
  switch (parseAs) {
123
146
  case 'arrayBuffer':
@@ -149,10 +172,16 @@ export const createClient = (config: Config = {}): Client => {
149
172
  case 'arrayBuffer':
150
173
  case 'blob':
151
174
  case 'formData':
152
- case 'json':
153
175
  case 'text':
154
176
  data = await response[parseAs]();
155
177
  break;
178
+ case 'json': {
179
+ // Some servers return 200 with no Content-Length and empty body.
180
+ // response.json() would throw; read as text and parse if non-empty.
181
+ const text = await response.text();
182
+ data = text ? JSON.parse(text) : {};
183
+ break;
184
+ }
156
185
  case 'stream':
157
186
  return opts.responseStyle === 'data'
158
187
  ? response.body
@@ -213,33 +242,34 @@ export const createClient = (config: Config = {}): Client => {
213
242
  };
214
243
  };
215
244
 
216
- const makeMethodFn =
217
- (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
218
- request({ ...options, method });
245
+ const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
246
+ request({ ...options, method });
219
247
 
220
- const makeSseFn =
221
- (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
222
- const { opts, url } = await beforeRequest(options);
223
- return createSseClient({
224
- ...opts,
225
- body: opts.body as BodyInit | null | undefined,
226
- headers: opts.headers as unknown as Record<string, string>,
227
- method,
228
- onRequest: async (url, init) => {
229
- let request = new Request(url, init);
230
- for (const fn of interceptors.request.fns) {
231
- if (fn) {
232
- request = await fn(request, opts);
233
- }
248
+ const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
249
+ const { opts, url } = await beforeRequest(options);
250
+ return createSseClient({
251
+ ...opts,
252
+ body: opts.body as BodyInit | null | undefined,
253
+ headers: opts.headers as unknown as Record<string, string>,
254
+ method,
255
+ onRequest: async (url, init) => {
256
+ let request = new Request(url, init);
257
+ for (const fn of interceptors.request.fns) {
258
+ if (fn) {
259
+ request = await fn(request, opts);
234
260
  }
235
- return request;
236
- },
237
- url,
238
- });
239
- };
261
+ }
262
+ return request;
263
+ },
264
+ serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
265
+ url,
266
+ });
267
+ };
268
+
269
+ const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options });
240
270
 
241
271
  return {
242
- buildUrl,
272
+ buildUrl: _buildUrl,
243
273
  connect: makeMethodFn('CONNECT'),
244
274
  delete: makeMethodFn('DELETE'),
245
275
  get: makeMethodFn('GET'),
@@ -16,7 +16,6 @@ export type {
16
16
  Config,
17
17
  CreateClientConfig,
18
18
  Options,
19
- OptionsLegacyParser,
20
19
  RequestOptions,
21
20
  RequestResult,
22
21
  ResolvedRequestOptions,
@@ -5,17 +5,13 @@ import type {
5
5
  ServerSentEventsOptions,
6
6
  ServerSentEventsResult,
7
7
  } from '../core/serverSentEvents.gen';
8
- import type {
9
- Client as CoreClient,
10
- Config as CoreConfig,
11
- } from '../core/types.gen';
8
+ import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen';
12
9
  import type { Middleware } from './utils.gen';
13
10
 
14
11
  export type ResponseStyle = 'data' | 'fields';
15
12
 
16
13
  export interface Config<T extends ClientOptions = ClientOptions>
17
- extends Omit<RequestInit, 'body' | 'headers' | 'method'>,
18
- CoreConfig {
14
+ extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
19
15
  /**
20
16
  * Base URL for all requests made by this client.
21
17
  */
@@ -42,14 +38,7 @@ export interface Config<T extends ClientOptions = ClientOptions>
42
38
  *
43
39
  * @default 'auto'
44
40
  */
45
- parseAs?:
46
- | 'arrayBuffer'
47
- | 'auto'
48
- | 'blob'
49
- | 'formData'
50
- | 'json'
51
- | 'stream'
52
- | 'text';
41
+ parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
53
42
  /**
54
43
  * Should we return only data or multiple fields (data, error, response, etc.)?
55
44
  *
@@ -69,12 +58,15 @@ export interface RequestOptions<
69
58
  TResponseStyle extends ResponseStyle = 'fields',
70
59
  ThrowOnError extends boolean = boolean,
71
60
  Url extends string = string,
72
- > extends Config<{
61
+ >
62
+ extends
63
+ Config<{
73
64
  responseStyle: TResponseStyle;
74
65
  throwOnError: ThrowOnError;
75
66
  }>,
76
67
  Pick<
77
68
  ServerSentEventsOptions<TData>,
69
+ | 'onRequest'
78
70
  | 'onSseError'
79
71
  | 'onSseEvent'
80
72
  | 'sseDefaultRetryDelay'
@@ -101,6 +93,7 @@ export interface ResolvedRequestOptions<
101
93
  ThrowOnError extends boolean = boolean,
102
94
  Url extends string = string,
103
95
  > extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
96
+ headers: Headers;
104
97
  serializedBody?: string;
105
98
  }
106
99
 
@@ -116,32 +109,22 @@ export type RequestResult<
116
109
  ? TData[keyof TData]
117
110
  : TData
118
111
  : {
119
- data: TData extends Record<string, unknown>
120
- ? TData[keyof TData]
121
- : TData;
112
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
122
113
  request: Request;
123
114
  response: Response;
124
115
  }
125
116
  >
126
117
  : Promise<
127
118
  TResponseStyle extends 'data'
128
- ?
129
- | (TData extends Record<string, unknown>
130
- ? TData[keyof TData]
131
- : TData)
132
- | undefined
119
+ ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
133
120
  : (
134
121
  | {
135
- data: TData extends Record<string, unknown>
136
- ? TData[keyof TData]
137
- : TData;
122
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
138
123
  error: undefined;
139
124
  }
140
125
  | {
141
126
  data: undefined;
142
- error: TError extends Record<string, unknown>
143
- ? TError[keyof TError]
144
- : TError;
127
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
145
128
  }
146
129
  ) & {
147
130
  request: Request;
@@ -170,7 +153,7 @@ type SseFn = <
170
153
  ThrowOnError extends boolean = false,
171
154
  TResponseStyle extends ResponseStyle = 'fields',
172
155
  >(
173
- options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
156
+ options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
174
157
  ) => Promise<ServerSentEventsResult<TData, TError>>;
175
158
 
176
159
  type RequestFn = <
@@ -180,10 +163,7 @@ type RequestFn = <
180
163
  TResponseStyle extends ResponseStyle = 'fields',
181
164
  >(
182
165
  options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
183
- Pick<
184
- Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>,
185
- 'method'
186
- >,
166
+ Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>,
187
167
  ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
188
168
 
189
169
  type BuildUrlFn = <
@@ -194,16 +174,10 @@ type BuildUrlFn = <
194
174
  url: string;
195
175
  },
196
176
  >(
197
- options: Pick<TData, 'url'> & Options<TData>,
177
+ options: TData & Options<TData>,
198
178
  ) => string;
199
179
 
200
- export type Client = CoreClient<
201
- RequestFn,
202
- Config,
203
- MethodFn,
204
- BuildUrlFn,
205
- SseFn
206
- > & {
180
+ export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
207
181
  interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
208
182
  };
209
183
 
@@ -238,31 +212,4 @@ export type Options<
238
212
  RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
239
213
  'body' | 'path' | 'query' | 'url'
240
214
  > &
241
- Omit<TData, 'url'>;
242
-
243
- export type OptionsLegacyParser<
244
- TData = unknown,
245
- ThrowOnError extends boolean = boolean,
246
- TResponseStyle extends ResponseStyle = 'fields',
247
- > = TData extends { body?: any }
248
- ? TData extends { headers?: any }
249
- ? OmitKeys<
250
- RequestOptions<unknown, TResponseStyle, ThrowOnError>,
251
- 'body' | 'headers' | 'url'
252
- > &
253
- TData
254
- : OmitKeys<
255
- RequestOptions<unknown, TResponseStyle, ThrowOnError>,
256
- 'body' | 'url'
257
- > &
258
- TData &
259
- Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers'>
260
- : TData extends { headers?: any }
261
- ? OmitKeys<
262
- RequestOptions<unknown, TResponseStyle, ThrowOnError>,
263
- 'headers' | 'url'
264
- > &
265
- TData &
266
- Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body'>
267
- : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'url'> &
268
- TData;
215
+ ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
@@ -65,9 +65,7 @@ export const createQuerySerializer = <T = unknown>({
65
65
  /**
66
66
  * Infers parseAs value from provided Content-Type header.
67
67
  */
68
- export const getParseAs = (
69
- contentType: string | null,
70
- ): Exclude<Config['parseAs'], 'auto'> => {
68
+ export const getParseAs = (contentType: string | null): Exclude<Config['parseAs'], 'auto'> => {
71
69
  if (!contentType) {
72
70
  // If no Content-Type header is provided, the best we can do is return the raw response body,
73
71
  // which is effectively the same as the 'stream' option.
@@ -80,10 +78,7 @@ export const getParseAs = (
80
78
  return;
81
79
  }
82
80
 
83
- if (
84
- cleanContent.startsWith('application/json') ||
85
- cleanContent.endsWith('+json')
86
- ) {
81
+ if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
87
82
  return 'json';
88
83
  }
89
84
 
@@ -92,9 +87,7 @@ export const getParseAs = (
92
87
  }
93
88
 
94
89
  if (
95
- ['application/', 'audio/', 'image/', 'video/'].some((type) =>
96
- cleanContent.startsWith(type),
97
- )
90
+ ['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))
98
91
  ) {
99
92
  return 'blob';
100
93
  }
@@ -201,10 +194,7 @@ export const mergeHeaders = (
201
194
  continue;
202
195
  }
203
196
 
204
- const iterator =
205
- header instanceof Headers
206
- ? headersEntries(header)
207
- : Object.entries(header);
197
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
208
198
 
209
199
  for (const [key, value] of iterator) {
210
200
  if (value === null) {
@@ -214,7 +204,7 @@ export const mergeHeaders = (
214
204
  mergedHeaders.append(key, v as string);
215
205
  }
216
206
  } else if (value !== undefined) {
217
- // assume object headers are meant to be JSON stringified, i.e. their
207
+ // assume object headers are meant to be JSON stringified, i.e., their
218
208
  // content value in OpenAPI specification is 'application/json'
219
209
  mergedHeaders.set(
220
210
  key,
@@ -233,10 +223,7 @@ type ErrInterceptor<Err, Res, Req, Options> = (
233
223
  options: Options,
234
224
  ) => Err | Promise<Err>;
235
225
 
236
- type ReqInterceptor<Req, Options> = (
237
- request: Req,
238
- options: Options,
239
- ) => Req | Promise<Req>;
226
+ type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
240
227
 
241
228
  type ResInterceptor<Res, Req, Options> = (
242
229
  response: Res,
@@ -270,10 +257,7 @@ class Interceptors<Interceptor> {
270
257
  return this.fns.indexOf(id);
271
258
  }
272
259
 
273
- update(
274
- id: number | Interceptor,
275
- fn: Interceptor,
276
- ): number | Interceptor | false {
260
+ update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false {
277
261
  const index = this.getInterceptorIndex(id);
278
262
  if (this.fns[index]) {
279
263
  this.fns[index] = fn;
@@ -23,8 +23,7 @@ export const getAuthToken = async (
23
23
  auth: Auth,
24
24
  callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
25
25
  ): Promise<string | undefined> => {
26
- const token =
27
- typeof callback === 'function' ? await callback(auth) : callback;
26
+ const token = typeof callback === 'function' ? await callback(auth) : callback;
28
27
 
29
28
  if (!token) {
30
29
  return;
@@ -1,14 +1,10 @@
1
1
  // This file is auto-generated by @hey-api/openapi-ts
2
2
 
3
- import type {
4
- ArrayStyle,
5
- ObjectStyle,
6
- SerializerOptions,
7
- } from './pathSerializer.gen';
3
+ import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer.gen';
8
4
 
9
5
  export type QuerySerializer = (query: Record<string, unknown>) => string;
10
6
 
11
- export type BodySerializer = (body: any) => any;
7
+ export type BodySerializer = (body: unknown) => unknown;
12
8
 
13
9
  type QuerySerializerOptionsObject = {
14
10
  allowReserved?: boolean;
@@ -24,11 +20,7 @@ export type QuerySerializerOptions = QuerySerializerOptionsObject & {
24
20
  parameters?: Record<string, QuerySerializerOptionsObject>;
25
21
  };
26
22
 
27
- const serializeFormDataPair = (
28
- data: FormData,
29
- key: string,
30
- value: unknown,
31
- ): void => {
23
+ const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => {
32
24
  if (typeof value === 'string' || value instanceof Blob) {
33
25
  data.append(key, value);
34
26
  } else if (value instanceof Date) {
@@ -38,11 +30,7 @@ const serializeFormDataPair = (
38
30
  }
39
31
  };
40
32
 
41
- const serializeUrlSearchParamsPair = (
42
- data: URLSearchParams,
43
- key: string,
44
- value: unknown,
45
- ): void => {
33
+ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => {
46
34
  if (typeof value === 'string') {
47
35
  data.append(key, value);
48
36
  } else {
@@ -51,12 +39,10 @@ const serializeUrlSearchParamsPair = (
51
39
  };
52
40
 
53
41
  export const formDataBodySerializer = {
54
- bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
55
- body: T,
56
- ): FormData => {
42
+ bodySerializer: (body: unknown): FormData => {
57
43
  const data = new FormData();
58
44
 
59
- Object.entries(body).forEach(([key, value]) => {
45
+ Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
60
46
  if (value === undefined || value === null) {
61
47
  return;
62
48
  }
@@ -72,19 +58,15 @@ export const formDataBodySerializer = {
72
58
  };
73
59
 
74
60
  export const jsonBodySerializer = {
75
- bodySerializer: <T>(body: T): string =>
76
- JSON.stringify(body, (_key, value) =>
77
- typeof value === 'bigint' ? value.toString() : value,
78
- ),
61
+ bodySerializer: (body: unknown): string =>
62
+ JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
79
63
  };
80
64
 
81
65
  export const urlSearchParamsBodySerializer = {
82
- bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
83
- body: T,
84
- ): string => {
66
+ bodySerializer: (body: unknown): string => {
85
67
  const data = new URLSearchParams();
86
68
 
87
- Object.entries(body).forEach(([key, value]) => {
69
+ Object.entries(body as Record<string, unknown>).forEach(([key, value]) => {
88
70
  if (value === undefined || value === null) {
89
71
  return;
90
72
  }
@@ -22,6 +22,17 @@ export type Field =
22
22
  */
23
23
  key?: string;
24
24
  map?: string;
25
+ }
26
+ | {
27
+ /**
28
+ * Field name. This is the name we want the user to see and use.
29
+ */
30
+ key: string;
31
+ /**
32
+ * Field mapped name. This is the name we want to use in the request.
33
+ * If `in` is omitted, `map` aliases `key` to the transport layer.
34
+ */
35
+ map: Slot;
25
36
  };
26
37
 
27
38
  export interface Fields {
@@ -41,10 +52,14 @@ const extraPrefixes = Object.entries(extraPrefixesMap);
41
52
 
42
53
  type KeyMap = Map<
43
54
  string,
44
- {
45
- in: Slot;
46
- map?: string;
47
- }
55
+ | {
56
+ in: Slot;
57
+ map?: string;
58
+ }
59
+ | {
60
+ in?: never;
61
+ map: Slot;
62
+ }
48
63
  >;
49
64
 
50
65
  const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
@@ -60,6 +75,10 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
60
75
  map: config.map,
61
76
  });
62
77
  }
78
+ } else if ('key' in config) {
79
+ map.set(config.key, {
80
+ map: config.map,
81
+ });
63
82
  } else if (config.args) {
64
83
  buildKeyMap(config.args, map);
65
84
  }
@@ -77,16 +96,13 @@ interface Params {
77
96
 
78
97
  const stripEmptySlots = (params: Params) => {
79
98
  for (const [slot, value] of Object.entries(params)) {
80
- if (value && typeof value === 'object' && !Object.keys(value).length) {
99
+ if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
81
100
  delete params[slot as Slot];
82
101
  }
83
102
  }
84
103
  };
85
104
 
86
- export const buildClientParams = (
87
- args: ReadonlyArray<unknown>,
88
- fields: FieldsConfig,
89
- ) => {
105
+ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
90
106
  const params: Params = {
91
107
  body: {},
92
108
  headers: {},
@@ -111,7 +127,9 @@ export const buildClientParams = (
111
127
  if (config.key) {
112
128
  const field = map.get(config.key)!;
113
129
  const name = field.map || config.key;
114
- (params[field.in] as Record<string, unknown>)[name] = arg;
130
+ if (field.in) {
131
+ (params[field.in] as Record<string, unknown>)[name] = arg;
132
+ }
115
133
  } else {
116
134
  params.body = arg;
117
135
  }
@@ -120,22 +138,20 @@ export const buildClientParams = (
120
138
  const field = map.get(key);
121
139
 
122
140
  if (field) {
123
- const name = field.map || key;
124
- (params[field.in] as Record<string, unknown>)[name] = value;
141
+ if (field.in) {
142
+ const name = field.map || key;
143
+ (params[field.in] as Record<string, unknown>)[name] = value;
144
+ } else {
145
+ params[field.map] = value;
146
+ }
125
147
  } else {
126
- const extra = extraPrefixes.find(([prefix]) =>
127
- key.startsWith(prefix),
128
- );
148
+ const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
129
149
 
130
150
  if (extra) {
131
151
  const [prefix, slot] = extra;
132
- (params[slot] as Record<string, unknown>)[
133
- key.slice(prefix.length)
134
- ] = value;
135
- } else {
136
- for (const [slot, allowed] of Object.entries(
137
- config.allowExtra ?? {},
138
- )) {
152
+ (params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
153
+ } else if ('allowExtra' in config && config.allowExtra) {
154
+ for (const [slot, allowed] of Object.entries(config.allowExtra)) {
139
155
  if (allowed) {
140
156
  (params[slot as Slot] as Record<string, unknown>)[key] = value;
141
157
  break;