buildfree 1.0.0 → 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 +4 -6
  2. package/src/forms.js +71 -50
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "buildfree",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Official JavaScript SDK for buildfree",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
- "start": "node src/index.js",
9
- "dev": ""
7
+ "start":"node src/index.js",
8
+ "dev":"nodemon src/index.js"
10
9
  },
11
10
  "keywords": [],
12
11
  "author": "BuildFree",
13
12
  "license": "MIT",
14
13
  "dependencies": {
15
- "axios": "^1.20.0",
16
- "nodemon": "^3.1.14"
14
+ "axios": "^1.20.0"
17
15
  }
18
16
  }
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,77 +155,98 @@ 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 (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
- formData.append(
201
+ // // if (!fs.existsSync(file.path)) {
202
+ // // throw new Error(`File not found: ${file.path}`);
203
+ // // }
204
+
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
+ // // );
215
+
216
+ // // continue;
217
+ // // }
203
218
 
204
- file.fieldname,
205
219
 
206
- fs.createReadStream(
207
- file.path
208
- ),
220
+ // throw new Error(
221
+ // `Invalid file for field: ${file.fieldname}`
222
+ // );
209
223
 
210
- {
211
- filename:
212
- file.filename ||
213
- file.originalname
214
- }
224
+ // }
215
225
 
216
- );
226
+ for (const item of files) {
217
227
 
228
+ if (!item) {
218
229
  continue;
219
-
220
230
  }
221
-
222
-
223
- throw new Error(
224
- `Invalid file for field: ${file.fieldname}`
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
225
247
  );
226
-
227
248
  }
228
249
 
229
-
230
250
  // ========================================================
231
251
  // SUBMIT
232
252
  // ========================================================
@@ -238,10 +258,11 @@ class Forms {
238
258
  formData,
239
259
 
240
260
  {
241
- headers: {
242
- ...formData.getHeaders()
261
+ headers: {
262
+ "x-api-key":
263
+ this.client.defaults.headers["x-api-key"]
264
+ }
243
265
  }
244
- }
245
266
 
246
267
  );
247
268