buildfree 1.0.1 → 1.0.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/forms.js +74 -51
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buildfree",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Official JavaScript SDK for buildfree",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/forms.js CHANGED
@@ -1,6 +1,5 @@
1
1
  const axios = require("axios");
2
- const FormData = require("form-data");
3
- const fs = require("fs");
2
+
4
3
 
5
4
  class Forms {
6
5
 
@@ -156,74 +155,97 @@ class Forms {
156
155
  // ADD FILES
157
156
  // ========================================================
158
157
 
159
- for (const file of files) {
158
+ // for (const file of files) {
160
159
 
161
- if (!file) {
162
- continue;
163
- }
160
+ // if (!file) {
161
+ // continue;
162
+ // }
164
163
 
165
164
 
166
- // ------------------------------------------------------
167
- // BUFFER
168
- // ------------------------------------------------------
165
+ // // ------------------------------------------------------
166
+ // // BUFFER
167
+ // // ------------------------------------------------------
169
168
 
170
- if (file.buffer && Buffer.isBuffer(file.buffer)) {
169
+ // // if (file.buffer && Buffer.isBuffer(file.buffer)) {
171
170
 
172
- formData.append(
171
+ // // formData.append(
173
172
 
174
- file.fieldname,
173
+ // // file.fieldname,
175
174
 
176
- file.buffer,
175
+ // // file.buffer,
177
176
 
178
- {
179
- filename:
180
- file.filename ||
181
- file.originalname ||
182
- "upload",
177
+ // // {
178
+ // // filename:
179
+ // // file.filename ||
180
+ // // file.originalname ||
181
+ // // "upload",
183
182
 
184
- contentType:
185
- file.contentType ||
186
- file.mimetype
187
- }
183
+ // // contentType:
184
+ // // file.contentType ||
185
+ // // file.mimetype
186
+ // // }
188
187
 
189
- );
188
+ // // );
190
189
 
191
- continue;
190
+ // // continue;
192
191
 
193
- }
192
+ // // }
194
193
 
195
194
 
196
- // ------------------------------------------------------
197
- // FILE PATH
198
- // ------------------------------------------------------
195
+ // // // ------------------------------------------------------
196
+ // // // FILE PATH
197
+ // // // ------------------------------------------------------
199
198
 
200
- if (file.path) {
199
+ // // if (file.path) {
201
200
 
202
- if (!fs.existsSync(file.path)) {
203
- throw new Error(`File not found: ${file.path}`);
204
- }
201
+ // // if (!fs.existsSync(file.path)) {
202
+ // // throw new Error(`File not found: ${file.path}`);
203
+ // // }
205
204
 
206
- formData.append(
207
- file.fieldname,
208
- fs.createReadStream(file.path),
209
- {
210
- filename:
211
- file.filename ||
212
- file.originalname ||
213
- file.path.split(/[\\/]/).pop()
214
- }
215
- );
205
+ // // formData.append(
206
+ // // file.fieldname,
207
+ // // fs.createReadStream(file.path),
208
+ // // {
209
+ // // filename:
210
+ // // file.filename ||
211
+ // // file.originalname ||
212
+ // // file.path.split(/[\\/]/).pop()
213
+ // // }
214
+ // // );
216
215
 
217
- continue;
218
- }
216
+ // // continue;
217
+ // // }
219
218
 
220
219
 
221
- throw new Error(
222
- `Invalid file for field: ${file.fieldname}`
223
- );
220
+ // throw new Error(
221
+ // `Invalid file for field: ${file.fieldname}`
222
+ // );
224
223
 
225
- }
224
+ // }
226
225
 
226
+ for (const item of files) {
227
+
228
+ if (!item) {
229
+ continue;
230
+ }
231
+
232
+ if (!item.fieldname) {
233
+ throw new Error(
234
+ "File fieldname is required"
235
+ );
236
+ }
237
+
238
+ if (!item.file) {
239
+ throw new Error(
240
+ `File is required for field: ${item.fieldname}`
241
+ );
242
+ }
243
+
244
+ formData.append(
245
+ item.fieldname,
246
+ item.file
247
+ );
248
+ }
227
249
 
228
250
  // ========================================================
229
251
  // SUBMIT
@@ -236,10 +258,11 @@ class Forms {
236
258
  formData,
237
259
 
238
260
  {
239
- headers: {
240
- ...formData.getHeaders()
261
+ headers: {
262
+ "x-api-key":
263
+ this.client.defaults.headers["x-api-key"]
264
+ }
241
265
  }
242
- }
243
266
 
244
267
  );
245
268