@primitivedotdev/sdk 0.2.4 → 0.4.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 (41) hide show
  1. package/README.md +65 -2
  2. package/bin/run.js +5 -0
  3. package/dist/api/generated/client/client.gen.js +235 -0
  4. package/dist/api/generated/client/index.js +6 -0
  5. package/dist/api/generated/client/types.gen.js +2 -0
  6. package/dist/api/generated/client/utils.gen.js +228 -0
  7. package/dist/api/generated/client.gen.js +3 -0
  8. package/dist/api/generated/core/auth.gen.js +14 -0
  9. package/dist/api/generated/core/bodySerializer.gen.js +57 -0
  10. package/dist/api/generated/core/params.gen.js +100 -0
  11. package/dist/api/generated/core/pathSerializer.gen.js +106 -0
  12. package/dist/api/generated/core/queryKeySerializer.gen.js +92 -0
  13. package/dist/api/generated/core/serverSentEvents.gen.js +132 -0
  14. package/dist/api/generated/core/types.gen.js +2 -0
  15. package/dist/api/generated/core/utils.gen.js +87 -0
  16. package/dist/api/generated/index.js +2 -0
  17. package/dist/api/generated/sdk.gen.js +347 -0
  18. package/dist/api/generated/types.gen.js +2 -0
  19. package/dist/api/index.d.ts +1877 -0
  20. package/dist/api/index.js +39 -0
  21. package/dist/chunk-Cl8Af3a2.js +11 -0
  22. package/dist/contract/index.d.ts +3 -3
  23. package/dist/contract/index.js +2 -2
  24. package/dist/{index-BdRIHaXz.d.ts → index-D2OuDGVz.d.ts} +81 -5
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.js +2 -2
  27. package/dist/oclif/api-command.js +218 -0
  28. package/dist/oclif/fish-completion.js +87 -0
  29. package/dist/oclif/index.js +42 -0
  30. package/dist/openapi/index.d.ts +42 -0
  31. package/dist/openapi/index.js +8 -0
  32. package/dist/openapi/openapi.generated.js +2715 -0
  33. package/dist/openapi/operations.generated.js +671 -0
  34. package/dist/parser/index.d.ts +1 -1
  35. package/dist/parser/index.js +40 -25
  36. package/dist/{types-B5IgP-Zx.d.ts → types-C3ms4R0d.d.ts} +4 -0
  37. package/dist/webhook/index.d.ts +3 -3
  38. package/dist/webhook/index.js +2 -2
  39. package/dist/{webhook-Be2vM0F-.js → webhook-uSco6pyX.js} +176 -11
  40. package/oclif.manifest.json +1267 -0
  41. package/package.json +81 -13
package/README.md CHANGED
@@ -2,13 +2,17 @@
2
2
 
3
3
  Official Primitive Node.js SDK.
4
4
 
5
- This package ships three Node.js modules:
5
+ This package ships five Node.js modules and one CLI:
6
6
 
7
7
  - `@primitivedotdev/sdk` for the webhook module
8
+ - `@primitivedotdev/sdk/api` for the generated HTTP API client
9
+ - `@primitivedotdev/sdk/openapi` for the canonical OpenAPI document export
8
10
  - `@primitivedotdev/sdk/contract` for the contract module
9
11
  - `@primitivedotdev/sdk/parser` for the parser module
10
12
 
11
- `contract` and `parser` are only available in the Node SDK. The Go and Python SDKs expose the webhook surface only.
13
+ It also publishes the `primitive` CLI bin from the same package.
14
+
15
+ `contract`, `parser`, and `openapi` are Node-only extras. The Go and Python SDKs expose `webhook` and `api` modules.
12
16
 
13
17
  ## Requirements
14
18
 
@@ -65,6 +69,52 @@ Webhook exports include:
65
69
  - `WEBHOOK_VERSION`
66
70
  - webhook error classes and webhook types
67
71
 
72
+ ### API
73
+
74
+ Use the API module for outbound calls to the Primitive HTTP API.
75
+
76
+ ```ts
77
+ import { PrimitiveApiClient, getAccount } from "@primitivedotdev/sdk/api";
78
+
79
+ const api = new PrimitiveApiClient({ apiKey: process.env.PRIMITIVE_API_KEY });
80
+ const result = await getAccount({ client: api.client });
81
+
82
+ if (result.error) {
83
+ throw result.error;
84
+ }
85
+
86
+ console.log(result.data.id);
87
+ ```
88
+
89
+ The package also ships a generated CLI bin named `primitive`.
90
+
91
+ ### OpenAPI
92
+
93
+ Use the OpenAPI module when another JavaScript application needs the canonical Primitive API spec.
94
+
95
+ ```ts
96
+ import { openapiDocument } from "@primitivedotdev/sdk/openapi";
97
+
98
+ console.log(openapiDocument.openapi);
99
+ ```
100
+
101
+ ### CLI
102
+
103
+ Use the published `primitive` CLI for outbound API access from the terminal.
104
+
105
+ ```bash
106
+ primitive --help
107
+ primitive account get-account --api-key prim_test
108
+ primitive emails download-raw-email --id <uuid> --api-key prim_test --output email.eml
109
+ ```
110
+
111
+ Autocomplete support is available through:
112
+
113
+ - `primitive completion fish`
114
+ - `primitive completion bash`
115
+ - `primitive completion zsh`
116
+ - `primitive completion powershell`
117
+
68
118
  ### Contract
69
119
 
70
120
  Use the contract module when constructing canonical Primitive webhook payloads on the producer side.
@@ -199,10 +249,23 @@ make node-build
199
249
 
200
250
  ```text
201
251
  sdk-node/
252
+ bin/
253
+ run.js
202
254
  src/
255
+ api/
256
+ generated/
257
+ index.ts
203
258
  contract/
204
259
  contract.ts
205
260
  index.ts
261
+ oclif/
262
+ api-command.ts
263
+ fish-completion.ts
264
+ index.ts
265
+ openapi/
266
+ index.ts
267
+ openapi.generated.ts
268
+ operations.generated.ts
206
269
  parser/
207
270
  attachment-bundler.ts
208
271
  attachment-parser.ts
package/bin/run.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execute } from "@oclif/core";
4
+
5
+ await execute({ dir: import.meta.url });
@@ -0,0 +1,235 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import { createSseClient } from '../core/serverSentEvents.gen.js';
3
+ import { getValidRequestBody } from '../core/utils.gen.js';
4
+ import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from './utils.gen.js';
5
+ export const createClient = (config = {}) => {
6
+ let _config = mergeConfigs(createConfig(), config);
7
+ const getConfig = () => ({ ..._config });
8
+ const setConfig = (config) => {
9
+ _config = mergeConfigs(_config, config);
10
+ return getConfig();
11
+ };
12
+ const interceptors = createInterceptors();
13
+ const beforeRequest = async (options) => {
14
+ const opts = {
15
+ ..._config,
16
+ ...options,
17
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
18
+ headers: mergeHeaders(_config.headers, options.headers),
19
+ serializedBody: undefined,
20
+ };
21
+ if (opts.security) {
22
+ await setAuthParams({
23
+ ...opts,
24
+ security: opts.security,
25
+ });
26
+ }
27
+ if (opts.requestValidator) {
28
+ await opts.requestValidator(opts);
29
+ }
30
+ if (opts.body !== undefined && opts.bodySerializer) {
31
+ opts.serializedBody = opts.bodySerializer(opts.body);
32
+ }
33
+ // remove Content-Type header if body is empty to avoid sending invalid requests
34
+ if (opts.body === undefined || opts.serializedBody === '') {
35
+ opts.headers.delete('Content-Type');
36
+ }
37
+ const resolvedOpts = opts;
38
+ const url = buildUrl(resolvedOpts);
39
+ return { opts: resolvedOpts, url };
40
+ };
41
+ const request = async (options) => {
42
+ const { opts, url } = await beforeRequest(options);
43
+ const requestInit = {
44
+ redirect: 'follow',
45
+ ...opts,
46
+ body: getValidRequestBody(opts),
47
+ };
48
+ let request = new Request(url, requestInit);
49
+ for (const fn of interceptors.request.fns) {
50
+ if (fn) {
51
+ request = await fn(request, opts);
52
+ }
53
+ }
54
+ // fetch must be assigned here, otherwise it would throw the error:
55
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
56
+ const _fetch = opts.fetch;
57
+ let response;
58
+ try {
59
+ response = await _fetch(request);
60
+ }
61
+ catch (error) {
62
+ // Handle fetch exceptions (AbortError, network errors, etc.)
63
+ let finalError = error;
64
+ for (const fn of interceptors.error.fns) {
65
+ if (fn) {
66
+ finalError = (await fn(error, undefined, request, opts));
67
+ }
68
+ }
69
+ finalError = finalError || {};
70
+ if (opts.throwOnError) {
71
+ throw finalError;
72
+ }
73
+ // Return error response
74
+ return opts.responseStyle === 'data'
75
+ ? undefined
76
+ : {
77
+ error: finalError,
78
+ request,
79
+ response: undefined,
80
+ };
81
+ }
82
+ for (const fn of interceptors.response.fns) {
83
+ if (fn) {
84
+ response = await fn(response, request, opts);
85
+ }
86
+ }
87
+ const result = {
88
+ request,
89
+ response,
90
+ };
91
+ if (response.ok) {
92
+ const parseAs = (opts.parseAs === 'auto'
93
+ ? getParseAs(response.headers.get('Content-Type'))
94
+ : opts.parseAs) ?? 'json';
95
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
96
+ let emptyData;
97
+ switch (parseAs) {
98
+ case 'arrayBuffer':
99
+ case 'blob':
100
+ case 'text':
101
+ emptyData = await response[parseAs]();
102
+ break;
103
+ case 'formData':
104
+ emptyData = new FormData();
105
+ break;
106
+ case 'stream':
107
+ emptyData = response.body;
108
+ break;
109
+ case 'json':
110
+ default:
111
+ emptyData = {};
112
+ break;
113
+ }
114
+ return opts.responseStyle === 'data'
115
+ ? emptyData
116
+ : {
117
+ data: emptyData,
118
+ ...result,
119
+ };
120
+ }
121
+ let data;
122
+ switch (parseAs) {
123
+ case 'arrayBuffer':
124
+ case 'blob':
125
+ case 'formData':
126
+ case 'text':
127
+ data = await response[parseAs]();
128
+ break;
129
+ case 'json': {
130
+ // Some servers return 200 with no Content-Length and empty body.
131
+ // response.json() would throw; read as text and parse if non-empty.
132
+ const text = await response.text();
133
+ data = text ? JSON.parse(text) : {};
134
+ break;
135
+ }
136
+ case 'stream':
137
+ return opts.responseStyle === 'data'
138
+ ? response.body
139
+ : {
140
+ data: response.body,
141
+ ...result,
142
+ };
143
+ }
144
+ if (parseAs === 'json') {
145
+ if (opts.responseValidator) {
146
+ await opts.responseValidator(data);
147
+ }
148
+ if (opts.responseTransformer) {
149
+ data = await opts.responseTransformer(data);
150
+ }
151
+ }
152
+ return opts.responseStyle === 'data'
153
+ ? data
154
+ : {
155
+ data,
156
+ ...result,
157
+ };
158
+ }
159
+ const textError = await response.text();
160
+ let jsonError;
161
+ try {
162
+ jsonError = JSON.parse(textError);
163
+ }
164
+ catch {
165
+ // noop
166
+ }
167
+ const error = jsonError ?? textError;
168
+ let finalError = error;
169
+ for (const fn of interceptors.error.fns) {
170
+ if (fn) {
171
+ finalError = (await fn(error, response, request, opts));
172
+ }
173
+ }
174
+ finalError = finalError || {};
175
+ if (opts.throwOnError) {
176
+ throw finalError;
177
+ }
178
+ // TODO: we probably want to return error and improve types
179
+ return opts.responseStyle === 'data'
180
+ ? undefined
181
+ : {
182
+ error: finalError,
183
+ ...result,
184
+ };
185
+ };
186
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
187
+ const makeSseFn = (method) => async (options) => {
188
+ const { opts, url } = await beforeRequest(options);
189
+ return createSseClient({
190
+ ...opts,
191
+ body: opts.body,
192
+ headers: opts.headers,
193
+ method,
194
+ onRequest: async (url, init) => {
195
+ let request = new Request(url, init);
196
+ for (const fn of interceptors.request.fns) {
197
+ if (fn) {
198
+ request = await fn(request, opts);
199
+ }
200
+ }
201
+ return request;
202
+ },
203
+ serializedBody: getValidRequestBody(opts),
204
+ url,
205
+ });
206
+ };
207
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
208
+ return {
209
+ buildUrl: _buildUrl,
210
+ connect: makeMethodFn('CONNECT'),
211
+ delete: makeMethodFn('DELETE'),
212
+ get: makeMethodFn('GET'),
213
+ getConfig,
214
+ head: makeMethodFn('HEAD'),
215
+ interceptors,
216
+ options: makeMethodFn('OPTIONS'),
217
+ patch: makeMethodFn('PATCH'),
218
+ post: makeMethodFn('POST'),
219
+ put: makeMethodFn('PUT'),
220
+ request,
221
+ setConfig,
222
+ sse: {
223
+ connect: makeSseFn('CONNECT'),
224
+ delete: makeSseFn('DELETE'),
225
+ get: makeSseFn('GET'),
226
+ head: makeSseFn('HEAD'),
227
+ options: makeSseFn('OPTIONS'),
228
+ patch: makeSseFn('PATCH'),
229
+ post: makeSseFn('POST'),
230
+ put: makeSseFn('PUT'),
231
+ trace: makeSseFn('TRACE'),
232
+ },
233
+ trace: makeMethodFn('TRACE'),
234
+ };
235
+ };
@@ -0,0 +1,6 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen.js';
3
+ export { buildClientParams } from '../core/params.gen.js';
4
+ export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen.js';
5
+ export { createClient } from './client.gen.js';
6
+ export { createConfig, mergeHeaders } from './utils.gen.js';
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,228 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import { getAuthToken } from '../core/auth.gen.js';
3
+ import { jsonBodySerializer } from '../core/bodySerializer.gen.js';
4
+ import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from '../core/pathSerializer.gen.js';
5
+ import { getUrl } from '../core/utils.gen.js';
6
+ export const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
7
+ const querySerializer = (queryParams) => {
8
+ const search = [];
9
+ if (queryParams && typeof queryParams === 'object') {
10
+ for (const name in queryParams) {
11
+ const value = queryParams[name];
12
+ if (value === undefined || value === null) {
13
+ continue;
14
+ }
15
+ const options = parameters[name] || args;
16
+ if (Array.isArray(value)) {
17
+ const serializedArray = serializeArrayParam({
18
+ allowReserved: options.allowReserved,
19
+ explode: true,
20
+ name,
21
+ style: 'form',
22
+ value,
23
+ ...options.array,
24
+ });
25
+ if (serializedArray)
26
+ search.push(serializedArray);
27
+ }
28
+ else if (typeof value === 'object') {
29
+ const serializedObject = serializeObjectParam({
30
+ allowReserved: options.allowReserved,
31
+ explode: true,
32
+ name,
33
+ style: 'deepObject',
34
+ value: value,
35
+ ...options.object,
36
+ });
37
+ if (serializedObject)
38
+ search.push(serializedObject);
39
+ }
40
+ else {
41
+ const serializedPrimitive = serializePrimitiveParam({
42
+ allowReserved: options.allowReserved,
43
+ name,
44
+ value: value,
45
+ });
46
+ if (serializedPrimitive)
47
+ search.push(serializedPrimitive);
48
+ }
49
+ }
50
+ }
51
+ return search.join('&');
52
+ };
53
+ return querySerializer;
54
+ };
55
+ /**
56
+ * Infers parseAs value from provided Content-Type header.
57
+ */
58
+ export const getParseAs = (contentType) => {
59
+ if (!contentType) {
60
+ // If no Content-Type header is provided, the best we can do is return the raw response body,
61
+ // which is effectively the same as the 'stream' option.
62
+ return 'stream';
63
+ }
64
+ const cleanContent = contentType.split(';')[0]?.trim();
65
+ if (!cleanContent) {
66
+ return;
67
+ }
68
+ if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
69
+ return 'json';
70
+ }
71
+ if (cleanContent === 'multipart/form-data') {
72
+ return 'formData';
73
+ }
74
+ if (['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))) {
75
+ return 'blob';
76
+ }
77
+ if (cleanContent.startsWith('text/')) {
78
+ return 'text';
79
+ }
80
+ return;
81
+ };
82
+ const checkForExistence = (options, name) => {
83
+ if (!name) {
84
+ return false;
85
+ }
86
+ if (options.headers.has(name) ||
87
+ options.query?.[name] ||
88
+ options.headers.get('Cookie')?.includes(`${name}=`)) {
89
+ return true;
90
+ }
91
+ return false;
92
+ };
93
+ export const setAuthParams = async ({ security, ...options }) => {
94
+ for (const auth of security) {
95
+ if (checkForExistence(options, auth.name)) {
96
+ continue;
97
+ }
98
+ const token = await getAuthToken(auth, options.auth);
99
+ if (!token) {
100
+ continue;
101
+ }
102
+ const name = auth.name ?? 'Authorization';
103
+ switch (auth.in) {
104
+ case 'query':
105
+ if (!options.query) {
106
+ options.query = {};
107
+ }
108
+ options.query[name] = token;
109
+ break;
110
+ case 'cookie':
111
+ options.headers.append('Cookie', `${name}=${token}`);
112
+ break;
113
+ case 'header':
114
+ default:
115
+ options.headers.set(name, token);
116
+ break;
117
+ }
118
+ }
119
+ };
120
+ export const buildUrl = (options) => getUrl({
121
+ baseUrl: options.baseUrl,
122
+ path: options.path,
123
+ query: options.query,
124
+ querySerializer: typeof options.querySerializer === 'function'
125
+ ? options.querySerializer
126
+ : createQuerySerializer(options.querySerializer),
127
+ url: options.url,
128
+ });
129
+ export const mergeConfigs = (a, b) => {
130
+ const config = { ...a, ...b };
131
+ if (config.baseUrl?.endsWith('/')) {
132
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
133
+ }
134
+ config.headers = mergeHeaders(a.headers, b.headers);
135
+ return config;
136
+ };
137
+ const headersEntries = (headers) => {
138
+ const entries = [];
139
+ headers.forEach((value, key) => {
140
+ entries.push([key, value]);
141
+ });
142
+ return entries;
143
+ };
144
+ export const mergeHeaders = (...headers) => {
145
+ const mergedHeaders = new Headers();
146
+ for (const header of headers) {
147
+ if (!header) {
148
+ continue;
149
+ }
150
+ const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
151
+ for (const [key, value] of iterator) {
152
+ if (value === null) {
153
+ mergedHeaders.delete(key);
154
+ }
155
+ else if (Array.isArray(value)) {
156
+ for (const v of value) {
157
+ mergedHeaders.append(key, v);
158
+ }
159
+ }
160
+ else if (value !== undefined) {
161
+ // assume object headers are meant to be JSON stringified, i.e., their
162
+ // content value in OpenAPI specification is 'application/json'
163
+ mergedHeaders.set(key, typeof value === 'object' ? JSON.stringify(value) : value);
164
+ }
165
+ }
166
+ }
167
+ return mergedHeaders;
168
+ };
169
+ class Interceptors {
170
+ fns = [];
171
+ clear() {
172
+ this.fns = [];
173
+ }
174
+ eject(id) {
175
+ const index = this.getInterceptorIndex(id);
176
+ if (this.fns[index]) {
177
+ this.fns[index] = null;
178
+ }
179
+ }
180
+ exists(id) {
181
+ const index = this.getInterceptorIndex(id);
182
+ return Boolean(this.fns[index]);
183
+ }
184
+ getInterceptorIndex(id) {
185
+ if (typeof id === 'number') {
186
+ return this.fns[id] ? id : -1;
187
+ }
188
+ return this.fns.indexOf(id);
189
+ }
190
+ update(id, fn) {
191
+ const index = this.getInterceptorIndex(id);
192
+ if (this.fns[index]) {
193
+ this.fns[index] = fn;
194
+ return id;
195
+ }
196
+ return false;
197
+ }
198
+ use(fn) {
199
+ this.fns.push(fn);
200
+ return this.fns.length - 1;
201
+ }
202
+ }
203
+ export const createInterceptors = () => ({
204
+ error: new Interceptors(),
205
+ request: new Interceptors(),
206
+ response: new Interceptors(),
207
+ });
208
+ const defaultQuerySerializer = createQuerySerializer({
209
+ allowReserved: false,
210
+ array: {
211
+ explode: true,
212
+ style: 'form',
213
+ },
214
+ object: {
215
+ explode: true,
216
+ style: 'deepObject',
217
+ },
218
+ });
219
+ const defaultHeaders = {
220
+ 'Content-Type': 'application/json',
221
+ };
222
+ export const createConfig = (override = {}) => ({
223
+ ...jsonBodySerializer,
224
+ headers: defaultHeaders,
225
+ parseAs: 'auto',
226
+ querySerializer: defaultQuerySerializer,
227
+ ...override,
228
+ });
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import { createClient, createConfig } from './client/index.js';
3
+ export const client = createClient(createConfig({ baseUrl: 'https://www.primitive.dev/api/v1' }));
@@ -0,0 +1,14 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export const getAuthToken = async (auth, callback) => {
3
+ const token = typeof callback === 'function' ? await callback(auth) : callback;
4
+ if (!token) {
5
+ return;
6
+ }
7
+ if (auth.scheme === 'bearer') {
8
+ return `Bearer ${token}`;
9
+ }
10
+ if (auth.scheme === 'basic') {
11
+ return `Basic ${btoa(token)}`;
12
+ }
13
+ return token;
14
+ };
@@ -0,0 +1,57 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ const serializeFormDataPair = (data, key, value) => {
3
+ if (typeof value === 'string' || value instanceof Blob) {
4
+ data.append(key, value);
5
+ }
6
+ else if (value instanceof Date) {
7
+ data.append(key, value.toISOString());
8
+ }
9
+ else {
10
+ data.append(key, JSON.stringify(value));
11
+ }
12
+ };
13
+ const serializeUrlSearchParamsPair = (data, key, value) => {
14
+ if (typeof value === 'string') {
15
+ data.append(key, value);
16
+ }
17
+ else {
18
+ data.append(key, JSON.stringify(value));
19
+ }
20
+ };
21
+ export const formDataBodySerializer = {
22
+ bodySerializer: (body) => {
23
+ const data = new FormData();
24
+ Object.entries(body).forEach(([key, value]) => {
25
+ if (value === undefined || value === null) {
26
+ return;
27
+ }
28
+ if (Array.isArray(value)) {
29
+ value.forEach((v) => serializeFormDataPair(data, key, v));
30
+ }
31
+ else {
32
+ serializeFormDataPair(data, key, value);
33
+ }
34
+ });
35
+ return data;
36
+ },
37
+ };
38
+ export const jsonBodySerializer = {
39
+ bodySerializer: (body) => JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
40
+ };
41
+ export const urlSearchParamsBodySerializer = {
42
+ bodySerializer: (body) => {
43
+ const data = new URLSearchParams();
44
+ Object.entries(body).forEach(([key, value]) => {
45
+ if (value === undefined || value === null) {
46
+ return;
47
+ }
48
+ if (Array.isArray(value)) {
49
+ value.forEach((v) => serializeUrlSearchParamsPair(data, key, v));
50
+ }
51
+ else {
52
+ serializeUrlSearchParamsPair(data, key, value);
53
+ }
54
+ });
55
+ return data.toString();
56
+ },
57
+ };