@tpzdsp/next-toolkit 1.4.0 → 1.4.2

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils/http.ts +12 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpzdsp/next-toolkit",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "A reusable React component library for Next.js applications",
5
5
  "type": "module",
6
6
  "private": false,
package/src/utils/http.ts CHANGED
@@ -128,10 +128,21 @@ const post = <Ok, Error = ApiFailure>(
128
128
  body: unknown,
129
129
  options?: RequestInit,
130
130
  ): Promise<Response<Ok, Error>> => {
131
+ let requestBody: string;
132
+
133
+ // If body is an empty object, send an empty string
134
+ if (body && typeof body === 'object' && !Array.isArray(body) && Object.keys(body).length === 0) {
135
+ requestBody = '';
136
+ } else if (body === undefined || body === null) {
137
+ requestBody = '{}';
138
+ } else {
139
+ requestBody = JSON.stringify(body);
140
+ }
141
+
131
142
  const requestOptions = {
132
143
  ...options,
133
144
  method: HttpMethod.Post,
134
- body: JSON.stringify(body),
145
+ body: requestBody,
135
146
  headers: {
136
147
  'Content-Type': MimeTypes.Json,
137
148
  ...options?.headers,