@akinon/next 1.36.0-rc.1 → 1.36.0-rc.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.36.0-rc.2
4
+
5
+ ### Minor Changes
6
+
7
+ - dff0d59: ZERO-2659: add formData support to proxy api requests
8
+
3
9
  ## 1.36.0-rc.1
4
10
 
5
11
  ## 1.36.0-rc.0
package/api/client.ts CHANGED
@@ -78,12 +78,13 @@ async function proxyRequest(...args) {
78
78
  fetchOptions.headers['Content-Type'] = options.contentType;
79
79
  }
80
80
 
81
+ const isMultipartFormData = req.headers.get('content-type')?.includes('multipart/form-data;');
82
+
81
83
  if (req.method !== 'GET') {
82
- const formData = new URLSearchParams();
83
- let body = {};
84
+ let body: Record<string, any> | FormData = {};
84
85
 
85
86
  try {
86
- body = await req.json();
87
+ body = isMultipartFormData ? await req.formData() : await req.json();
87
88
  } catch (error) {
88
89
  logger.error(
89
90
  `Client Proxy Request - Error while parsing request body to JSON`,
@@ -94,13 +95,21 @@ async function proxyRequest(...args) {
94
95
  );
95
96
  }
96
97
 
97
- Object.keys(body ?? {}).forEach((key) => {
98
- if (body[key]) {
99
- formData.append(key, body[key]);
100
- }
101
- });
98
+ if (isMultipartFormData) {
99
+ fetchOptions.body = body as FormData;
100
+ } else {
101
+ const formData = new FormData();
102
+
103
+ Object.keys(body ?? {}).forEach((key) => {
104
+ if (body[key]) {
105
+ formData.append(key, body[key]);
106
+ }
107
+ });
102
108
 
103
- fetchOptions.body = !options.useFormData ? JSON.stringify(body) : formData;
109
+ fetchOptions.body = !options.useFormData
110
+ ? JSON.stringify(body)
111
+ : formData;
112
+ }
104
113
  }
105
114
 
106
115
  let url = `${commerceUrl}/${slug.replace(/,/g, '/')}`;
@@ -123,15 +123,16 @@ const accountApi = api.injectEndpoints({
123
123
  query: ({ page, status, limit }) =>
124
124
  buildClientRequestUrl(account.getQuotations(page, status, limit))
125
125
  }),
126
- sendContact: builder.mutation<void, ContactFormType>({
127
- query: (body) => ({
128
- url: buildClientRequestUrl(account.sendContact, {
129
- contentType: 'application/json',
130
- responseType: 'text'
131
- }),
132
- method: 'POST',
133
- body
134
- })
126
+ sendContact: builder.mutation<void, FormData>({
127
+ query: (body) => {
128
+ return {
129
+ url: buildClientRequestUrl(account.sendContact, {
130
+ useFormData: true
131
+ }),
132
+ method: 'POST',
133
+ body
134
+ };
135
+ }
135
136
  }),
136
137
  cancelOrder: builder.mutation<void, AccountOrderCancellation>({
137
138
  query: ({ id, ...body }) => ({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.36.0-rc.1",
4
+ "version": "1.36.0-rc.2",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -35,7 +35,7 @@
35
35
  "@typescript-eslint/eslint-plugin": "6.7.4",
36
36
  "@typescript-eslint/parser": "6.7.4",
37
37
  "eslint": "^8.14.0",
38
- "@akinon/eslint-plugin-projectzero": "1.36.0-rc.1",
38
+ "@akinon/eslint-plugin-projectzero": "1.36.0-rc.2",
39
39
  "eslint-config-prettier": "8.5.0"
40
40
  }
41
41
  }
@@ -61,4 +61,5 @@ export type ContactFormType = {
61
61
  order?: string;
62
62
  country_code?: string;
63
63
  order_needed?: boolean;
64
+ file?: FileList
64
65
  };