@uploadcare/upload-client 6.0.1-alpha.5 → 6.0.1-alpha.6

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.
@@ -264,6 +264,13 @@ var getFormData = () => new FormData();
264
264
  const isReactNativeUri = (uri) => {
265
265
  return uri.startsWith('file:') || uri.startsWith('content:');
266
266
  };
267
+ const isReactNativeAsset = (asset) => {
268
+ return (typeof asset === 'object' &&
269
+ !!asset &&
270
+ 'uri' in asset &&
271
+ typeof asset.uri === 'string' &&
272
+ isReactNativeUri(asset.uri));
273
+ };
267
274
 
268
275
  /**
269
276
  * FileData type guard.
@@ -273,7 +280,8 @@ const isFileData = (data) => {
273
280
  ((typeof Blob !== 'undefined' && data instanceof Blob) ||
274
281
  (typeof File !== 'undefined' && data instanceof File) ||
275
282
  (typeof Buffer !== 'undefined' && data instanceof Buffer) ||
276
- (typeof data === 'string' && isReactNativeUri(data))));
283
+ (typeof data === 'string' && isReactNativeUri(data)) ||
284
+ (typeof data === 'object' && isReactNativeAsset(data))));
277
285
  };
278
286
  /**
279
287
  * Uuid type guard.
@@ -450,10 +458,6 @@ function retryIfFailed(fn, options) {
450
458
  }));
451
459
  }
452
460
 
453
- function getStoreValue(store) {
454
- return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
455
- }
456
-
457
461
  /**
458
462
  * Performs file uploading request to Uploadcare Upload API.
459
463
  * Can be canceled and has progress.
@@ -466,7 +470,6 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
466
470
  }),
467
471
  headers: {
468
472
  'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
469
- 'content-type': 'multipart/form-data'
470
473
  },
471
474
  data: buildFormData({
472
475
  file: {
@@ -475,10 +478,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
475
478
  contentType
476
479
  },
477
480
  UPLOADCARE_PUB_KEY: publicKey,
478
- UPLOADCARE_STORE: getStoreValue(store),
479
- signature: secureSignature,
480
- expire: secureExpire,
481
- source: source,
481
+ // UPLOADCARE_STORE: getStoreValue(store),
482
+ // signature: secureSignature,
483
+ // expire: secureExpire,
484
+ // source: source,
482
485
  metadata
483
486
  }),
484
487
  signal,
@@ -494,6 +497,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
494
497
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
495
498
  }
496
499
 
500
+ function getStoreValue(store) {
501
+ return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
502
+ }
503
+
497
504
  var TypeEnum;
498
505
  (function (TypeEnum) {
499
506
  TypeEnum["Token"] = "token";
@@ -288,6 +288,13 @@ var getFormData = () => new NodeFormData();
288
288
  const isReactNativeUri = (uri) => {
289
289
  return uri.startsWith('file:') || uri.startsWith('content:');
290
290
  };
291
+ const isReactNativeAsset = (asset) => {
292
+ return (typeof asset === 'object' &&
293
+ !!asset &&
294
+ 'uri' in asset &&
295
+ typeof asset.uri === 'string' &&
296
+ isReactNativeUri(asset.uri));
297
+ };
291
298
 
292
299
  /**
293
300
  * FileData type guard.
@@ -297,7 +304,8 @@ const isFileData = (data) => {
297
304
  ((typeof Blob !== 'undefined' && data instanceof Blob) ||
298
305
  (typeof File !== 'undefined' && data instanceof File) ||
299
306
  (typeof Buffer !== 'undefined' && data instanceof Buffer) ||
300
- (typeof data === 'string' && isReactNativeUri(data))));
307
+ (typeof data === 'string' && isReactNativeUri(data)) ||
308
+ (typeof data === 'object' && isReactNativeAsset(data))));
301
309
  };
302
310
  /**
303
311
  * Uuid type guard.
@@ -474,10 +482,6 @@ function retryIfFailed(fn, options) {
474
482
  }));
475
483
  }
476
484
 
477
- function getStoreValue(store) {
478
- return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
479
- }
480
-
481
485
  /**
482
486
  * Performs file uploading request to Uploadcare Upload API.
483
487
  * Can be canceled and has progress.
@@ -490,7 +494,6 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
490
494
  }),
491
495
  headers: {
492
496
  'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
493
- 'content-type': 'multipart/form-data'
494
497
  },
495
498
  data: buildFormData({
496
499
  file: {
@@ -499,10 +502,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
499
502
  contentType
500
503
  },
501
504
  UPLOADCARE_PUB_KEY: publicKey,
502
- UPLOADCARE_STORE: getStoreValue(store),
503
- signature: secureSignature,
504
- expire: secureExpire,
505
- source: source,
505
+ // UPLOADCARE_STORE: getStoreValue(store),
506
+ // signature: secureSignature,
507
+ // expire: secureExpire,
508
+ // source: source,
506
509
  metadata
507
510
  }),
508
511
  signal,
@@ -518,6 +521,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
518
521
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
519
522
  }
520
523
 
524
+ function getStoreValue(store) {
525
+ return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
526
+ }
527
+
521
528
  var TypeEnum;
522
529
  (function (TypeEnum) {
523
530
  TypeEnum["Token"] = "token";
@@ -256,15 +256,25 @@ const request = ({ method, url, data, headers = {}, signal, onProgress }) => new
256
256
  const isReactNativeUri = (uri) => {
257
257
  return uri.startsWith('file:') || uri.startsWith('content:');
258
258
  };
259
+ const isReactNativeAsset = (asset) => {
260
+ return (typeof asset === 'object' &&
261
+ !!asset &&
262
+ 'uri' in asset &&
263
+ typeof asset.uri === 'string' &&
264
+ isReactNativeUri(asset.uri));
265
+ };
259
266
 
260
267
  const getFileOptions = ({ name }) => name ? [name] : [];
261
268
  const transformFile = (file, name, contentType) => {
262
269
  if (typeof file === 'string' && isReactNativeUri(file)) {
270
+ return { uri: file, name, type: contentType };
271
+ }
272
+ if (isReactNativeAsset(file)) {
263
273
  return file;
264
274
  }
265
- // const uri = URL.createObjectURL(file as BrowserFile)
266
- // const type = contentType || (file as BrowserFile).type
267
- return file;
275
+ const uri = URL.createObjectURL(file);
276
+ const type = contentType || file.type;
277
+ return { uri, name, type };
268
278
  };
269
279
  var getFormData = () => new FormData();
270
280
 
@@ -276,7 +286,8 @@ const isFileData = (data) => {
276
286
  ((typeof Blob !== 'undefined' && data instanceof Blob) ||
277
287
  (typeof File !== 'undefined' && data instanceof File) ||
278
288
  (typeof Buffer !== 'undefined' && data instanceof Buffer) ||
279
- (typeof data === 'string' && isReactNativeUri(data))));
289
+ (typeof data === 'string' && isReactNativeUri(data)) ||
290
+ (typeof data === 'object' && isReactNativeAsset(data))));
280
291
  };
281
292
  /**
282
293
  * Uuid type guard.
@@ -312,7 +323,7 @@ const isFileValue = (value) => !!value &&
312
323
  function collectParams(params, inputKey, inputValue) {
313
324
  if (isFileValue(inputValue)) {
314
325
  const { name, contentType } = inputValue;
315
- const file = transformFile(inputValue.data); // lgtm [js/superfluous-trailing-arguments]
326
+ const file = transformFile(inputValue.data, name, contentType); // lgtm [js/superfluous-trailing-arguments]
316
327
  const options = getFileOptions({ name, contentType });
317
328
  params.push([inputKey, file, ...options]);
318
329
  }
@@ -453,10 +464,6 @@ function retryIfFailed(fn, options) {
453
464
  }));
454
465
  }
455
466
 
456
- function getStoreValue(store) {
457
- return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
458
- }
459
-
460
467
  /**
461
468
  * Performs file uploading request to Uploadcare Upload API.
462
469
  * Can be canceled and has progress.
@@ -469,7 +476,6 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
469
476
  }),
470
477
  headers: {
471
478
  'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
472
- 'content-type': 'multipart/form-data'
473
479
  },
474
480
  data: buildFormData({
475
481
  file: {
@@ -478,10 +484,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
478
484
  contentType
479
485
  },
480
486
  UPLOADCARE_PUB_KEY: publicKey,
481
- UPLOADCARE_STORE: getStoreValue(store),
482
- signature: secureSignature,
483
- expire: secureExpire,
484
- source: source,
487
+ // UPLOADCARE_STORE: getStoreValue(store),
488
+ // signature: secureSignature,
489
+ // expire: secureExpire,
490
+ // source: source,
485
491
  metadata
486
492
  }),
487
493
  signal,
@@ -497,6 +503,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
497
503
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
498
504
  }
499
505
 
506
+ function getStoreValue(store) {
507
+ return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
508
+ }
509
+
500
510
  var TypeEnum;
501
511
  (function (TypeEnum) {
502
512
  TypeEnum["Token"] = "token";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uploadcare/upload-client",
3
- "version": "6.0.1-alpha.5",
3
+ "version": "6.0.1-alpha.6",
4
4
  "description": "Library for work with Uploadcare Upload API",
5
5
  "type": "module",
6
6
  "module": "./dist/index.node.js",