@uploadcare/upload-client 6.0.1-alpha.4 → 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.
@@ -465,7 +469,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
465
469
  jsonerrors: 1
466
470
  }),
467
471
  headers: {
468
- 'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent })
472
+ 'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
469
473
  },
470
474
  data: buildFormData({
471
475
  file: {
@@ -474,10 +478,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
474
478
  contentType
475
479
  },
476
480
  UPLOADCARE_PUB_KEY: publicKey,
477
- UPLOADCARE_STORE: getStoreValue(store),
478
- signature: secureSignature,
479
- expire: secureExpire,
480
- source: source,
481
+ // UPLOADCARE_STORE: getStoreValue(store),
482
+ // signature: secureSignature,
483
+ // expire: secureExpire,
484
+ // source: source,
481
485
  metadata
482
486
  }),
483
487
  signal,
@@ -493,6 +497,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
493
497
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
494
498
  }
495
499
 
500
+ function getStoreValue(store) {
501
+ return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
502
+ }
503
+
496
504
  var TypeEnum;
497
505
  (function (TypeEnum) {
498
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.
@@ -489,7 +493,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
489
493
  jsonerrors: 1
490
494
  }),
491
495
  headers: {
492
- 'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent })
496
+ 'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
493
497
  },
494
498
  data: buildFormData({
495
499
  file: {
@@ -498,10 +502,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
498
502
  contentType
499
503
  },
500
504
  UPLOADCARE_PUB_KEY: publicKey,
501
- UPLOADCARE_STORE: getStoreValue(store),
502
- signature: secureSignature,
503
- expire: secureExpire,
504
- source: source,
505
+ // UPLOADCARE_STORE: getStoreValue(store),
506
+ // signature: secureSignature,
507
+ // expire: secureExpire,
508
+ // source: source,
505
509
  metadata
506
510
  }),
507
511
  signal,
@@ -517,6 +521,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
517
521
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
518
522
  }
519
523
 
524
+ function getStoreValue(store) {
525
+ return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
526
+ }
527
+
520
528
  var TypeEnum;
521
529
  (function (TypeEnum) {
522
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)) {
263
270
  return { uri: file, name, type: contentType };
264
271
  }
265
- // const uri = URL.createObjectURL(file as BrowserFile)
266
- // const type = contentType || (file as BrowserFile).type
267
- return file;
272
+ if (isReactNativeAsset(file)) {
273
+ return file;
274
+ }
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.
@@ -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.
@@ -468,7 +475,7 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
468
475
  jsonerrors: 1
469
476
  }),
470
477
  headers: {
471
- 'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent })
478
+ 'X-UC-User-Agent': getUserAgent({ publicKey, integration, userAgent }),
472
479
  },
473
480
  data: buildFormData({
474
481
  file: {
@@ -477,10 +484,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
477
484
  contentType
478
485
  },
479
486
  UPLOADCARE_PUB_KEY: publicKey,
480
- UPLOADCARE_STORE: getStoreValue(store),
481
- signature: secureSignature,
482
- expire: secureExpire,
483
- source: source,
487
+ // UPLOADCARE_STORE: getStoreValue(store),
488
+ // signature: secureSignature,
489
+ // expire: secureExpire,
490
+ // source: source,
484
491
  metadata
485
492
  }),
486
493
  signal,
@@ -496,6 +503,10 @@ function base(file, { publicKey, fileName, contentType, baseURL = defaultSetting
496
503
  }), { retryNetworkErrorMaxTimes, retryThrottledRequestMaxTimes });
497
504
  }
498
505
 
506
+ function getStoreValue(store) {
507
+ return typeof store === 'undefined' ? 'auto' : store ? '1' : '0';
508
+ }
509
+
499
510
  var TypeEnum;
500
511
  (function (TypeEnum) {
501
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.4",
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",