@storyblok/management-api-client 0.1.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 (73) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +241 -0
  3. package/dist/_virtual/rolldown_runtime.js +25 -0
  4. package/dist/client/client.d.mts +7 -0
  5. package/dist/client/client.d.ts +7 -0
  6. package/dist/client/client.js +160 -0
  7. package/dist/client/client.js.map +1 -0
  8. package/dist/client/client.mjs +159 -0
  9. package/dist/client/client.mjs.map +1 -0
  10. package/dist/client/index.js +4 -0
  11. package/dist/client/index.mjs +4 -0
  12. package/dist/client/types.d.mts +116 -0
  13. package/dist/client/types.d.ts +116 -0
  14. package/dist/client/utils.d.mts +23 -0
  15. package/dist/client/utils.d.ts +23 -0
  16. package/dist/client/utils.js +242 -0
  17. package/dist/client/utils.js.map +1 -0
  18. package/dist/client/utils.mjs +236 -0
  19. package/dist/client/utils.mjs.map +1 -0
  20. package/dist/core/auth.d.mts +21 -0
  21. package/dist/core/auth.d.ts +21 -0
  22. package/dist/core/auth.js +13 -0
  23. package/dist/core/auth.js.map +1 -0
  24. package/dist/core/auth.mjs +12 -0
  25. package/dist/core/auth.mjs.map +1 -0
  26. package/dist/core/bodySerializer.d.mts +13 -0
  27. package/dist/core/bodySerializer.d.ts +13 -0
  28. package/dist/core/bodySerializer.js +7 -0
  29. package/dist/core/bodySerializer.js.map +1 -0
  30. package/dist/core/bodySerializer.mjs +6 -0
  31. package/dist/core/bodySerializer.mjs.map +1 -0
  32. package/dist/core/params.js +12 -0
  33. package/dist/core/params.js.map +1 -0
  34. package/dist/core/params.mjs +11 -0
  35. package/dist/core/params.mjs.map +1 -0
  36. package/dist/core/pathSerializer.d.mts +14 -0
  37. package/dist/core/pathSerializer.d.ts +14 -0
  38. package/dist/core/pathSerializer.js +85 -0
  39. package/dist/core/pathSerializer.js.map +1 -0
  40. package/dist/core/pathSerializer.mjs +82 -0
  41. package/dist/core/pathSerializer.mjs.map +1 -0
  42. package/dist/core/types.d.mts +78 -0
  43. package/dist/core/types.d.ts +78 -0
  44. package/dist/index.d.mts +50 -0
  45. package/dist/index.d.ts +50 -0
  46. package/dist/index.js +84 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/index.mjs +82 -0
  49. package/dist/index.mjs.map +1 -0
  50. package/dist/sdk-registry.generated.d.mts +28 -0
  51. package/dist/sdk-registry.generated.d.ts +28 -0
  52. package/dist/sdk-registry.generated.js +26 -0
  53. package/dist/sdk-registry.generated.js.map +1 -0
  54. package/dist/sdk-registry.generated.mjs +26 -0
  55. package/dist/sdk-registry.generated.mjs.map +1 -0
  56. package/examples/index.ts +32 -0
  57. package/generate.ts +125 -0
  58. package/package.json +79 -0
  59. package/src/__tests__/integration.test.ts +143 -0
  60. package/src/__tests__/region-resolution.test.ts +89 -0
  61. package/src/client/client.ts +246 -0
  62. package/src/client/index.ts +22 -0
  63. package/src/client/types.ts +222 -0
  64. package/src/client/utils.ts +417 -0
  65. package/src/core/auth.ts +40 -0
  66. package/src/core/bodySerializer.ts +88 -0
  67. package/src/core/params.ts +151 -0
  68. package/src/core/pathSerializer.ts +179 -0
  69. package/src/core/types.ts +118 -0
  70. package/src/index.ts +129 -0
  71. package/src/shared-client.ts +13 -0
  72. package/tsconfig.json +25 -0
  73. package/tsdown.config.ts +21 -0
@@ -0,0 +1,417 @@
1
+ import { getAuthToken } from '../core/auth';
2
+ import type {
3
+ QuerySerializer,
4
+ QuerySerializerOptions,
5
+ } from '../core/bodySerializer';
6
+ import { jsonBodySerializer } from '../core/bodySerializer';
7
+ import {
8
+ serializeArrayParam,
9
+ serializeObjectParam,
10
+ serializePrimitiveParam,
11
+ } from '../core/pathSerializer';
12
+ import type { Client, ClientOptions, Config, RequestOptions } from './types';
13
+
14
+ interface PathSerializer {
15
+ path: Record<string, unknown>;
16
+ url: string;
17
+ }
18
+
19
+ const PATH_PARAM_RE = /\{[^{}]+\}/g;
20
+
21
+ type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
22
+ type MatrixStyle = 'label' | 'matrix' | 'simple';
23
+ type ArraySeparatorStyle = ArrayStyle | MatrixStyle;
24
+
25
+ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
26
+ let url = _url;
27
+ const matches = _url.match(PATH_PARAM_RE);
28
+ if (matches) {
29
+ for (const match of matches) {
30
+ let explode = false;
31
+ let name = match.substring(1, match.length - 1);
32
+ let style: ArraySeparatorStyle = 'simple';
33
+
34
+ if (name.endsWith('*')) {
35
+ explode = true;
36
+ name = name.substring(0, name.length - 1);
37
+ }
38
+
39
+ if (name.startsWith('.')) {
40
+ name = name.substring(1);
41
+ style = 'label';
42
+ } else if (name.startsWith(';')) {
43
+ name = name.substring(1);
44
+ style = 'matrix';
45
+ }
46
+
47
+ const value = path[name];
48
+
49
+ if (value === undefined || value === null) {
50
+ continue;
51
+ }
52
+
53
+ if (Array.isArray(value)) {
54
+ url = url.replace(
55
+ match,
56
+ serializeArrayParam({ explode, name, style, value }),
57
+ );
58
+ continue;
59
+ }
60
+
61
+ if (typeof value === 'object') {
62
+ url = url.replace(
63
+ match,
64
+ serializeObjectParam({
65
+ explode,
66
+ name,
67
+ style,
68
+ value: value as Record<string, unknown>,
69
+ valueOnly: true,
70
+ }),
71
+ );
72
+ continue;
73
+ }
74
+
75
+ if (style === 'matrix') {
76
+ url = url.replace(
77
+ match,
78
+ `;${serializePrimitiveParam({
79
+ name,
80
+ value: value as string,
81
+ })}`,
82
+ );
83
+ continue;
84
+ }
85
+
86
+ const replaceValue = encodeURIComponent(
87
+ style === 'label' ? `.${value as string}` : (value as string),
88
+ );
89
+ url = url.replace(match, replaceValue);
90
+ }
91
+ }
92
+ return url;
93
+ };
94
+
95
+ export const createQuerySerializer = <T = unknown>({
96
+ allowReserved,
97
+ array,
98
+ object,
99
+ }: QuerySerializerOptions = {}) => {
100
+ const querySerializer = (queryParams: T) => {
101
+ const search: string[] = [];
102
+ if (queryParams && typeof queryParams === 'object') {
103
+ for (const name in queryParams) {
104
+ const value = queryParams[name];
105
+
106
+ if (value === undefined || value === null) {
107
+ continue;
108
+ }
109
+
110
+ if (Array.isArray(value)) {
111
+ const serializedArray = serializeArrayParam({
112
+ allowReserved,
113
+ explode: true,
114
+ name,
115
+ style: 'form',
116
+ value,
117
+ ...array,
118
+ });
119
+ if (serializedArray) search.push(serializedArray);
120
+ } else if (typeof value === 'object') {
121
+ const serializedObject = serializeObjectParam({
122
+ allowReserved,
123
+ explode: true,
124
+ name,
125
+ style: 'deepObject',
126
+ value: value as Record<string, unknown>,
127
+ ...object,
128
+ });
129
+ if (serializedObject) search.push(serializedObject);
130
+ } else {
131
+ const serializedPrimitive = serializePrimitiveParam({
132
+ allowReserved,
133
+ name,
134
+ value: value as string,
135
+ });
136
+ if (serializedPrimitive) search.push(serializedPrimitive);
137
+ }
138
+ }
139
+ }
140
+ return search.join('&');
141
+ };
142
+ return querySerializer;
143
+ };
144
+
145
+ /**
146
+ * Infers parseAs value from provided Content-Type header.
147
+ */
148
+ export const getParseAs = (
149
+ contentType: string | null,
150
+ ): Exclude<Config['parseAs'], 'auto'> => {
151
+ if (!contentType) {
152
+ // If no Content-Type header is provided, the best we can do is return the raw response body,
153
+ // which is effectively the same as the 'stream' option.
154
+ return 'stream';
155
+ }
156
+
157
+ const cleanContent = contentType.split(';')[0]?.trim();
158
+
159
+ if (!cleanContent) {
160
+ return;
161
+ }
162
+
163
+ if (
164
+ cleanContent.startsWith('application/json') ||
165
+ cleanContent.endsWith('+json')
166
+ ) {
167
+ return 'json';
168
+ }
169
+
170
+ if (cleanContent === 'multipart/form-data') {
171
+ return 'formData';
172
+ }
173
+
174
+ if (
175
+ ['application/', 'audio/', 'image/', 'video/'].some((type) =>
176
+ cleanContent.startsWith(type),
177
+ )
178
+ ) {
179
+ return 'blob';
180
+ }
181
+
182
+ if (cleanContent.startsWith('text/')) {
183
+ return 'text';
184
+ }
185
+
186
+ return;
187
+ };
188
+
189
+ export const setAuthParams = async ({
190
+ security,
191
+ ...options
192
+ }: Pick<Required<RequestOptions>, 'security'> &
193
+ Pick<RequestOptions, 'auth' | 'query'> & {
194
+ headers: Headers;
195
+ }) => {
196
+ for (const auth of security) {
197
+ const token = await getAuthToken(auth, options.auth);
198
+
199
+ if (!token) {
200
+ continue;
201
+ }
202
+
203
+ const name = auth.name ?? 'Authorization';
204
+
205
+ switch (auth.in) {
206
+ case 'query':
207
+ if (!options.query) {
208
+ options.query = {};
209
+ }
210
+ options.query[name] = token;
211
+ break;
212
+ case 'cookie':
213
+ options.headers.append('Cookie', `${name}=${token}`);
214
+ break;
215
+ case 'header':
216
+ default:
217
+ options.headers.set(name, token);
218
+ break;
219
+ }
220
+
221
+ return;
222
+ }
223
+ };
224
+
225
+ export const buildUrl: Client['buildUrl'] = (options) => {
226
+ const url = getUrl({
227
+ baseUrl: options.baseUrl as string,
228
+ path: options.path,
229
+ query: options.query,
230
+ querySerializer:
231
+ typeof options.querySerializer === 'function'
232
+ ? options.querySerializer
233
+ : createQuerySerializer(options.querySerializer),
234
+ url: options.url,
235
+ });
236
+ return url;
237
+ };
238
+
239
+ export const getUrl = ({
240
+ baseUrl,
241
+ path,
242
+ query,
243
+ querySerializer,
244
+ url: _url,
245
+ }: {
246
+ baseUrl?: string;
247
+ path?: Record<string, unknown>;
248
+ query?: Record<string, unknown>;
249
+ querySerializer: QuerySerializer;
250
+ url: string;
251
+ }) => {
252
+ const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
253
+ let url = (baseUrl ?? '') + pathUrl;
254
+ if (path) {
255
+ url = defaultPathSerializer({ path, url });
256
+ }
257
+ let search = query ? querySerializer(query) : '';
258
+ if (search.startsWith('?')) {
259
+ search = search.substring(1);
260
+ }
261
+ if (search) {
262
+ url += `?${search}`;
263
+ }
264
+ return url;
265
+ };
266
+
267
+ export const mergeConfigs = (a: Config, b: Config): Config => {
268
+ const config = { ...a, ...b };
269
+ if (config.baseUrl?.endsWith('/')) {
270
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
271
+ }
272
+ config.headers = mergeHeaders(a.headers, b.headers);
273
+ return config;
274
+ };
275
+
276
+ export const mergeHeaders = (
277
+ ...headers: Array<Required<Config>['headers'] | undefined>
278
+ ): Headers => {
279
+ const mergedHeaders = new Headers();
280
+ for (const header of headers) {
281
+ if (!header || typeof header !== 'object') {
282
+ continue;
283
+ }
284
+
285
+ const iterator =
286
+ header instanceof Headers ? header.entries() : Object.entries(header);
287
+
288
+ for (const [key, value] of iterator) {
289
+ if (value === null) {
290
+ mergedHeaders.delete(key);
291
+ } else if (Array.isArray(value)) {
292
+ for (const v of value) {
293
+ mergedHeaders.append(key, v as string);
294
+ }
295
+ } else if (value !== undefined) {
296
+ // assume object headers are meant to be JSON stringified, i.e. their
297
+ // content value in OpenAPI specification is 'application/json'
298
+ mergedHeaders.set(
299
+ key,
300
+ typeof value === 'object' ? JSON.stringify(value) : (value as string),
301
+ );
302
+ }
303
+ }
304
+ }
305
+ return mergedHeaders;
306
+ };
307
+
308
+ type ErrInterceptor<Err, Res, Req, Options> = (
309
+ error: Err,
310
+ response: Res,
311
+ request: Req,
312
+ options: Options,
313
+ ) => Err | Promise<Err>;
314
+
315
+ type ReqInterceptor<Req, Options> = (
316
+ request: Req,
317
+ options: Options,
318
+ ) => Req | Promise<Req>;
319
+
320
+ type ResInterceptor<Res, Req, Options> = (
321
+ response: Res,
322
+ request: Req,
323
+ options: Options,
324
+ ) => Res | Promise<Res>;
325
+
326
+ class Interceptors<Interceptor> {
327
+ _fns: (Interceptor | null)[];
328
+
329
+ constructor() {
330
+ this._fns = [];
331
+ }
332
+
333
+ clear() {
334
+ this._fns = [];
335
+ }
336
+
337
+ getInterceptorIndex(id: number | Interceptor): number {
338
+ if (typeof id === 'number') {
339
+ return this._fns[id] ? id : -1;
340
+ } else {
341
+ return this._fns.indexOf(id);
342
+ }
343
+ }
344
+ exists(id: number | Interceptor) {
345
+ const index = this.getInterceptorIndex(id);
346
+ return !!this._fns[index];
347
+ }
348
+
349
+ eject(id: number | Interceptor) {
350
+ const index = this.getInterceptorIndex(id);
351
+ if (this._fns[index]) {
352
+ this._fns[index] = null;
353
+ }
354
+ }
355
+
356
+ update(id: number | Interceptor, fn: Interceptor) {
357
+ const index = this.getInterceptorIndex(id);
358
+ if (this._fns[index]) {
359
+ this._fns[index] = fn;
360
+ return id;
361
+ } else {
362
+ return false;
363
+ }
364
+ }
365
+
366
+ use(fn: Interceptor) {
367
+ this._fns = [...this._fns, fn];
368
+ return this._fns.length - 1;
369
+ }
370
+ }
371
+
372
+ // `createInterceptors()` response, meant for external use as it does not
373
+ // expose internals
374
+ export interface Middleware<Req, Res, Err, Options> {
375
+ error: Pick<
376
+ Interceptors<ErrInterceptor<Err, Res, Req, Options>>,
377
+ 'eject' | 'use'
378
+ >;
379
+ request: Pick<Interceptors<ReqInterceptor<Req, Options>>, 'eject' | 'use'>;
380
+ response: Pick<
381
+ Interceptors<ResInterceptor<Res, Req, Options>>,
382
+ 'eject' | 'use'
383
+ >;
384
+ }
385
+
386
+ // do not add `Middleware` as return type so we can use _fns internally
387
+ export const createInterceptors = <Req, Res, Err, Options>() => ({
388
+ error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
389
+ request: new Interceptors<ReqInterceptor<Req, Options>>(),
390
+ response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
391
+ });
392
+
393
+ const defaultQuerySerializer = createQuerySerializer({
394
+ allowReserved: false,
395
+ array: {
396
+ explode: true,
397
+ style: 'form',
398
+ },
399
+ object: {
400
+ explode: true,
401
+ style: 'deepObject',
402
+ },
403
+ });
404
+
405
+ const defaultHeaders = {
406
+ 'Content-Type': 'application/json',
407
+ };
408
+
409
+ export const createConfig = <T extends ClientOptions = ClientOptions>(
410
+ override: Config<Omit<ClientOptions, keyof T> & T> = {},
411
+ ): Config<Omit<ClientOptions, keyof T> & T> => ({
412
+ ...jsonBodySerializer,
413
+ headers: defaultHeaders,
414
+ parseAs: 'auto',
415
+ querySerializer: defaultQuerySerializer,
416
+ ...override,
417
+ });
@@ -0,0 +1,40 @@
1
+ export type AuthToken = string | undefined;
2
+
3
+ export interface Auth {
4
+ /**
5
+ * Which part of the request do we use to send the auth?
6
+ *
7
+ * @default 'header'
8
+ */
9
+ in?: 'header' | 'query' | 'cookie';
10
+ /**
11
+ * Header or query parameter name.
12
+ *w
13
+ * @default 'Authorization'
14
+ */
15
+ name?: string;
16
+ scheme?: 'basic' | 'bearer';
17
+ type: 'apiKey' | 'http';
18
+ }
19
+
20
+ export const getAuthToken = async (
21
+ auth: Auth,
22
+ callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
23
+ ): Promise<string | undefined> => {
24
+ const token =
25
+ typeof callback === 'function' ? await callback(auth) : callback;
26
+
27
+ if (!token) {
28
+ return;
29
+ }
30
+
31
+ if (auth.scheme === 'bearer') {
32
+ return `Bearer ${token}`;
33
+ }
34
+
35
+ if (auth.scheme === 'basic') {
36
+ return `Basic ${btoa(token)}`;
37
+ }
38
+
39
+ return token;
40
+ };
@@ -0,0 +1,88 @@
1
+ import type {
2
+ ArrayStyle,
3
+ ObjectStyle,
4
+ SerializerOptions,
5
+ } from './pathSerializer';
6
+
7
+ export type QuerySerializer = (query: Record<string, unknown>) => string;
8
+
9
+ export type BodySerializer = (body: any) => any;
10
+
11
+ export interface QuerySerializerOptions {
12
+ allowReserved?: boolean;
13
+ array?: SerializerOptions<ArrayStyle>;
14
+ object?: SerializerOptions<ObjectStyle>;
15
+ }
16
+
17
+ const serializeFormDataPair = (
18
+ data: FormData,
19
+ key: string,
20
+ value: unknown,
21
+ ): void => {
22
+ if (typeof value === 'string' || value instanceof Blob) {
23
+ data.append(key, value);
24
+ } else {
25
+ data.append(key, JSON.stringify(value));
26
+ }
27
+ };
28
+
29
+ const serializeUrlSearchParamsPair = (
30
+ data: URLSearchParams,
31
+ key: string,
32
+ value: unknown,
33
+ ): void => {
34
+ if (typeof value === 'string') {
35
+ data.append(key, value);
36
+ } else {
37
+ data.append(key, JSON.stringify(value));
38
+ }
39
+ };
40
+
41
+ export const formDataBodySerializer = {
42
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
43
+ body: T,
44
+ ): FormData => {
45
+ const data = new FormData();
46
+
47
+ Object.entries(body).forEach(([key, value]) => {
48
+ if (value === undefined || value === null) {
49
+ return;
50
+ }
51
+ if (Array.isArray(value)) {
52
+ value.forEach((v) => serializeFormDataPair(data, key, v));
53
+ } else {
54
+ serializeFormDataPair(data, key, value);
55
+ }
56
+ });
57
+
58
+ return data;
59
+ },
60
+ };
61
+
62
+ export const jsonBodySerializer = {
63
+ bodySerializer: <T>(body: T): string =>
64
+ JSON.stringify(body, (_key, value) =>
65
+ typeof value === 'bigint' ? value.toString() : value,
66
+ ),
67
+ };
68
+
69
+ export const urlSearchParamsBodySerializer = {
70
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
71
+ body: T,
72
+ ): string => {
73
+ const data = new URLSearchParams();
74
+
75
+ Object.entries(body).forEach(([key, value]) => {
76
+ if (value === undefined || value === null) {
77
+ return;
78
+ }
79
+ if (Array.isArray(value)) {
80
+ value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
81
+ } else {
82
+ serializeUrlSearchParamsPair(data, key, value);
83
+ }
84
+ });
85
+
86
+ return data.toString();
87
+ },
88
+ };
@@ -0,0 +1,151 @@
1
+ type Slot = 'body' | 'headers' | 'path' | 'query';
2
+
3
+ export type Field =
4
+ | {
5
+ in: Exclude<Slot, 'body'>;
6
+ /**
7
+ * Field name. This is the name we want the user to see and use.
8
+ */
9
+ key: string;
10
+ /**
11
+ * Field mapped name. This is the name we want to use in the request.
12
+ * If omitted, we use the same value as `key`.
13
+ */
14
+ map?: string;
15
+ }
16
+ | {
17
+ in: Extract<Slot, 'body'>;
18
+ /**
19
+ * Key isn't required for bodies.
20
+ */
21
+ key?: string;
22
+ map?: string;
23
+ };
24
+
25
+ export interface Fields {
26
+ allowExtra?: Partial<Record<Slot, boolean>>;
27
+ args?: ReadonlyArray<Field>;
28
+ }
29
+
30
+ export type FieldsConfig = ReadonlyArray<Field | Fields>;
31
+
32
+ const extraPrefixesMap: Record<string, Slot> = {
33
+ $body_: 'body',
34
+ $headers_: 'headers',
35
+ $path_: 'path',
36
+ $query_: 'query',
37
+ };
38
+ const extraPrefixes = Object.entries(extraPrefixesMap);
39
+
40
+ type KeyMap = Map<
41
+ string,
42
+ {
43
+ in: Slot;
44
+ map?: string;
45
+ }
46
+ >;
47
+
48
+ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
49
+ if (!map) {
50
+ map = new Map();
51
+ }
52
+
53
+ for (const config of fields) {
54
+ if ('in' in config) {
55
+ if (config.key) {
56
+ map.set(config.key, {
57
+ in: config.in,
58
+ map: config.map,
59
+ });
60
+ }
61
+ } else if (config.args) {
62
+ buildKeyMap(config.args, map);
63
+ }
64
+ }
65
+
66
+ return map;
67
+ };
68
+
69
+ interface Params {
70
+ body: unknown;
71
+ headers: Record<string, unknown>;
72
+ path: Record<string, unknown>;
73
+ query: Record<string, unknown>;
74
+ }
75
+
76
+ const stripEmptySlots = (params: Params) => {
77
+ for (const [slot, value] of Object.entries(params)) {
78
+ if (value && typeof value === 'object' && !Object.keys(value).length) {
79
+ delete params[slot as Slot];
80
+ }
81
+ }
82
+ };
83
+
84
+ export const buildClientParams = (
85
+ args: ReadonlyArray<unknown>,
86
+ fields: FieldsConfig,
87
+ ) => {
88
+ const params: Params = {
89
+ body: {},
90
+ headers: {},
91
+ path: {},
92
+ query: {},
93
+ };
94
+
95
+ const map = buildKeyMap(fields);
96
+
97
+ let config: FieldsConfig[number] | undefined;
98
+
99
+ for (const [index, arg] of args.entries()) {
100
+ if (fields[index]) {
101
+ config = fields[index];
102
+ }
103
+
104
+ if (!config) {
105
+ continue;
106
+ }
107
+
108
+ if ('in' in config) {
109
+ if (config.key) {
110
+ const field = map.get(config.key)!;
111
+ const name = field.map || config.key;
112
+ (params[field.in] as Record<string, unknown>)[name] = arg;
113
+ } else {
114
+ params.body = arg;
115
+ }
116
+ } else {
117
+ for (const [key, value] of Object.entries(arg ?? {})) {
118
+ const field = map.get(key);
119
+
120
+ if (field) {
121
+ const name = field.map || key;
122
+ (params[field.in] as Record<string, unknown>)[name] = value;
123
+ } else {
124
+ const extra = extraPrefixes.find(([prefix]) =>
125
+ key.startsWith(prefix),
126
+ );
127
+
128
+ if (extra) {
129
+ const [prefix, slot] = extra;
130
+ (params[slot] as Record<string, unknown>)[
131
+ key.slice(prefix.length)
132
+ ] = value;
133
+ } else {
134
+ for (const [slot, allowed] of Object.entries(
135
+ config.allowExtra ?? {},
136
+ )) {
137
+ if (allowed) {
138
+ (params[slot as Slot] as Record<string, unknown>)[key] = value;
139
+ break;
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+
148
+ stripEmptySlots(params);
149
+
150
+ return params;
151
+ };