@hapaul/api 0.1.14 → 0.1.16

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.
package/dist/index.d.ts CHANGED
@@ -1422,6 +1422,7 @@ type ResponseError<T extends PathsWithMethod<paths, M>, M extends Methods> = Err
1422
1422
  type ClientConfig = {
1423
1423
  baseUrl?: string;
1424
1424
  fetch?: typeof fetch;
1425
+ bodySerializer?: (data: any, headers: Headers) => any;
1425
1426
  };
1426
1427
  type RequestConfig<T extends PathsWithMethod<paths, M>, M extends Methods, C = {}> = ClientConfig & {
1427
1428
  method: M;
@@ -1448,6 +1449,7 @@ declare class Client<C> {
1448
1449
  private middlewares;
1449
1450
  private baseUrl;
1450
1451
  private fetch;
1452
+ private bodySerializer;
1451
1453
  constructor(config?: ClientConfig);
1452
1454
  use(middleware: Middleware<C>): void;
1453
1455
  request<T extends PathsWithMethod<paths, M>, M extends Methods>(method: M, path: T, ...params: RequestParams<T, M, C>): RequestResponse<T, M>;
package/dist/index.js CHANGED
@@ -3,10 +3,12 @@ var Client = class {
3
3
  middlewares;
4
4
  baseUrl;
5
5
  fetch;
6
+ bodySerializer;
6
7
  constructor(config) {
7
8
  this.middlewares = [];
8
9
  this.baseUrl = config?.baseUrl ?? "";
9
10
  this.fetch = config?.fetch ?? fetch;
11
+ this.bodySerializer = config?.bodySerializer ?? defaultBodySerializer;
10
12
  }
11
13
  use(middleware) {
12
14
  this.middlewares.push(middleware);
@@ -29,7 +31,7 @@ var Client = class {
29
31
  const body = requestConfig.body;
30
32
  if (!contentType) headers.set("Content-Type", "application/json");
31
33
  try {
32
- const serializedBody = defaultBodySerializer(body, headers);
34
+ const serializedBody = this.bodySerializer(body, headers);
33
35
  let response = await this.fetch(url, {
34
36
  ...requestConfig,
35
37
  body: serializedBody,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hapaul/api",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [