buildfree 1.0.1 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buildfree",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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
 
@@ -152,79 +151,32 @@ class Forms {
152
151
  }
153
152
 
154
153
 
155
- // ========================================================
156
- // ADD FILES
157
154
  // ========================================================
158
155
 
159
- for (const file of files) {
156
+ for (const item of files) {
160
157
 
161
- if (!file) {
158
+ if (!item) {
162
159
  continue;
163
160
  }
164
-
165
-
166
- // ------------------------------------------------------
167
- // BUFFER
168
- // ------------------------------------------------------
169
-
170
- if (file.buffer && Buffer.isBuffer(file.buffer)) {
171
-
172
- formData.append(
173
-
174
- file.fieldname,
175
-
176
- file.buffer,
177
-
178
- {
179
- filename:
180
- file.filename ||
181
- file.originalname ||
182
- "upload",
183
-
184
- contentType:
185
- file.contentType ||
186
- file.mimetype
187
- }
188
-
161
+
162
+ if (!item.fieldname) {
163
+ throw new Error(
164
+ "File fieldname is required"
189
165
  );
190
-
191
- continue;
192
-
193
166
  }
194
-
195
-
196
- // ------------------------------------------------------
197
- // FILE PATH
198
- // ------------------------------------------------------
199
-
200
- if (file.path) {
201
-
202
- if (!fs.existsSync(file.path)) {
203
- throw new Error(`File not found: ${file.path}`);
204
- }
205
-
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
- );
216
-
217
- continue;
218
- }
219
-
220
-
221
- throw new Error(
222
- `Invalid file for field: ${file.fieldname}`
167
+
168
+ if (!item.file) {
169
+ throw new Error(
170
+ `File is required for field: ${item.fieldname}`
171
+ );
172
+ }
173
+
174
+ formData.append(
175
+ item.fieldname,
176
+ item.file
223
177
  );
224
-
225
178
  }
226
179
 
227
-
228
180
  // ========================================================
229
181
  // SUBMIT
230
182
  // ========================================================
@@ -236,10 +188,11 @@ class Forms {
236
188
  formData,
237
189
 
238
190
  {
239
- headers: {
240
- ...formData.getHeaders()
191
+ headers: {
192
+ "x-api-key":
193
+ this.client.defaults.headers["x-api-key"]
194
+ }
241
195
  }
242
- }
243
196
 
244
197
  );
245
198
 
package/src/index.js CHANGED
@@ -5,7 +5,7 @@ class BuildFree {
5
5
 
6
6
  constructor({
7
7
  apiKey,
8
- baseURL = "https://cms-backend-9nkz.onrender.com/api/v1"
8
+ baseURL = "https://api.buildfree.dev/api/v1"
9
9
  } = {}) {
10
10
 
11
11
  // ==========================================