@eluvio/elv-client-js 4.0.18 → 4.0.20

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.
@@ -422,7 +422,7 @@ var FrameClient = /*#__PURE__*/function () {
422
422
  }, {
423
423
  key: "FileMethods",
424
424
  value: function FileMethods() {
425
- return ["DownloadFile", "DownloadPart", "UpdateContentObjectGraph", "UploadFiles", "UploadFilesFromS3", "UploadPart", "UploadPartChunk"];
425
+ return ["CreateFileUploadJob", "DownloadEncrypted", "DownloadFile", "DownloadPart", "FinalizeUploadJob", "UpdateContentObjectGraph", "UploadFileData", "UploadFiles", "UploadFilesFromS3", "UploadJobStatus", "UploadPart", "UploadPartChunk", "UploadStatus"];
426
426
  }
427
427
  }]);
428
428
  return FrameClient;
@@ -534,6 +534,7 @@ exports.UploadFiles = /*#__PURE__*/function () {
534
534
  writeToken: writeToken,
535
535
  uploadId: id,
536
536
  jobId: jobId,
537
+ filePath: _fileInfo2.path,
537
538
  fileData: _fileInfo2.data
538
539
  });
539
540
  case 12:
@@ -558,8 +559,10 @@ exports.UploadFiles = /*#__PURE__*/function () {
558
559
  return function UploadJob(_x4, _x5) {
559
560
  return _ref8.apply(this, arguments);
560
561
  };
561
- }(); // Preparing jobs is done asyncronously
562
- PrepareJobs();
562
+ }(); // Preparing jobs is done asynchronously
563
+ PrepareJobs()["catch"](function (e) {
564
+ throw e;
565
+ });
563
566
 
564
567
  // Upload the first several chunks in sequence, to determine average upload rate
565
568
  rateTestJobs = Math.min(3, jobs.length);
@@ -726,7 +729,7 @@ exports.UploadStatus = /*#__PURE__*/function () {
726
729
  }();
727
730
  exports.UploadJobStatus = /*#__PURE__*/function () {
728
731
  var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
729
- var libraryId, objectId, writeToken, uploadId, jobId, path;
732
+ var libraryId, objectId, writeToken, uploadId, jobId, path, jobStatus;
730
733
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
731
734
  while (1) switch (_context9.prev = _context9.next) {
732
735
  case 0:
@@ -736,16 +739,18 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
736
739
  objectId: objectId
737
740
  });
738
741
  ValidateWriteToken(writeToken);
739
- path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
742
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId); // This request is sent during file data upload and might fail due to congestion
743
+ case 4:
744
+ _context9.prev = 4;
740
745
  _context9.t0 = this.utils;
741
746
  _context9.t1 = this.HttpClient;
742
- _context9.next = 8;
747
+ _context9.next = 9;
743
748
  return this.authClient.AuthorizationHeader({
744
749
  libraryId: libraryId,
745
750
  objectId: objectId,
746
751
  update: true
747
752
  });
748
- case 8:
753
+ case 9:
749
754
  _context9.t2 = _context9.sent;
750
755
  _context9.t3 = path;
751
756
  _context9.t4 = {
@@ -755,12 +760,33 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
755
760
  failover: false
756
761
  };
757
762
  _context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
758
- return _context9.abrupt("return", _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5));
759
- case 13:
763
+ jobStatus = _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5);
764
+ return _context9.abrupt("return", jobStatus);
765
+ case 17:
766
+ _context9.prev = 17;
767
+ _context9.t6 = _context9["catch"](4);
768
+ this.Log(_context9.t6, true);
769
+ retries += 1;
770
+ if (!(retries >= 5)) {
771
+ _context9.next = 23;
772
+ break;
773
+ }
774
+ throw _context9.t6;
775
+ case 23:
776
+ _context9.next = 25;
777
+ return new Promise(function (resolve) {
778
+ return setTimeout(resolve, 10 * retries * 1000);
779
+ });
780
+ case 25:
781
+ if (retries < 5) {
782
+ _context9.next = 4;
783
+ break;
784
+ }
785
+ case 26:
760
786
  case "end":
761
787
  return _context9.stop();
762
788
  }
763
- }, _callee9, this);
789
+ }, _callee9, this, [[4, 17]]);
764
790
  }));
765
791
  return function (_x10) {
766
792
  return _ref15.apply(this, arguments);
@@ -768,16 +794,43 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
768
794
  }();
769
795
  exports.UploadFileData = /*#__PURE__*/function () {
770
796
  var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref16) {
771
- var libraryId, objectId, writeToken, uploadId, jobId, fileData, path;
797
+ var libraryId, objectId, writeToken, uploadId, jobId, filePath, fileData, retries, jobStatus, fileStatus, path;
772
798
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
773
799
  while (1) switch (_context10.prev = _context10.next) {
774
800
  case 0:
775
- libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, fileData = _ref16.fileData;
801
+ libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, filePath = _ref16.filePath, fileData = _ref16.fileData;
776
802
  ValidateParameters({
777
803
  libraryId: libraryId,
778
804
  objectId: objectId
779
805
  });
780
806
  ValidateWriteToken(writeToken);
807
+ retries = 0;
808
+ case 4:
809
+ _context10.prev = 4;
810
+ _context10.next = 7;
811
+ return this.UploadJobStatus({
812
+ libraryId: libraryId,
813
+ objectId: objectId,
814
+ writeToken: writeToken,
815
+ uploadId: uploadId,
816
+ jobId: jobId
817
+ });
818
+ case 7:
819
+ jobStatus = _context10.sent;
820
+ // Find the status of this file
821
+ fileStatus = jobStatus.files.find(function (item) {
822
+ return item.path == filePath;
823
+ });
824
+ if (!(fileStatus.rem === 0)) {
825
+ _context10.next = 13;
826
+ break;
827
+ }
828
+ return _context10.abrupt("return");
829
+ case 13:
830
+ if (fileStatus.skip) {
831
+ fileData = fileData.slice(fileStatus.skip);
832
+ }
833
+ case 14:
781
834
  path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
782
835
  _context10.t0 = this.utils;
783
836
  _context10.t1 = this.HttpClient;
@@ -787,13 +840,13 @@ exports.UploadFileData = /*#__PURE__*/function () {
787
840
  _context10.t5 = {
788
841
  "Content-type": "application/octet-stream"
789
842
  };
790
- _context10.next = 12;
843
+ _context10.next = 23;
791
844
  return this.authClient.AuthorizationHeader({
792
845
  libraryId: libraryId,
793
846
  objectId: objectId,
794
847
  update: true
795
848
  });
796
- case 12:
849
+ case 23:
797
850
  _context10.t6 = _context10.sent;
798
851
  _context10.t7 = (0, _context10.t4)(_context10.t5, _context10.t6);
799
852
  _context10.t8 = {
@@ -805,13 +858,35 @@ exports.UploadFileData = /*#__PURE__*/function () {
805
858
  failover: false
806
859
  };
807
860
  _context10.t9 = _context10.t1.Request.call(_context10.t1, _context10.t8);
808
- _context10.next = 18;
861
+ _context10.next = 29;
809
862
  return _context10.t0.ResponseToJson.call(_context10.t0, _context10.t9);
810
- case 18:
863
+ case 29:
864
+ return _context10.abrupt("return", _context10.sent);
865
+ case 32:
866
+ _context10.prev = 32;
867
+ _context10.t10 = _context10["catch"](4);
868
+ this.Log(_context10.t10, true);
869
+ retries += 1;
870
+ if (!(retries >= 5)) {
871
+ _context10.next = 38;
872
+ break;
873
+ }
874
+ throw _context10.t10;
875
+ case 38:
876
+ _context10.next = 40;
877
+ return new Promise(function (resolve) {
878
+ return setTimeout(resolve, 10 * retries * 1000);
879
+ });
880
+ case 40:
881
+ if (retries < 5) {
882
+ _context10.next = 4;
883
+ break;
884
+ }
885
+ case 41:
811
886
  case "end":
812
887
  return _context10.stop();
813
888
  }
814
- }, _callee10, this);
889
+ }, _callee10, this, [[4, 32]]);
815
890
  }));
816
891
  return function (_x11) {
817
892
  return _ref17.apply(this, arguments);
@@ -2482,8 +2482,6 @@ exports.RejectMarketplaceOffer = /*#__PURE__*/function () {
2482
2482
  /* Voting */
2483
2483
 
2484
2484
  /**
2485
- * <b><i>Requires login</i></b>
2486
- *
2487
2485
  * Retrieve the current status of the specified voting event
2488
2486
  *
2489
2487
  * @methodGroup Voting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.18",
3
+ "version": "4.0.20",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -54,7 +54,6 @@ class FrameClient {
54
54
  this.Crypto = Crypto;
55
55
  this.Crypto.ElvCrypto();
56
56
 
57
-
58
57
  // Dynamically defined methods defined in AllowedMethods
59
58
  for(const methodName of this.AllowedMethods()){
60
59
  this[methodName] = async (args) => {
@@ -258,13 +257,19 @@ class FrameClient {
258
257
 
259
258
  static FileMethods() {
260
259
  return [
260
+ "CreateFileUploadJob",
261
+ "DownloadEncrypted",
261
262
  "DownloadFile",
262
263
  "DownloadPart",
264
+ "FinalizeUploadJob",
263
265
  "UpdateContentObjectGraph",
266
+ "UploadFileData",
264
267
  "UploadFiles",
265
268
  "UploadFilesFromS3",
269
+ "UploadJobStatus",
266
270
  "UploadPart",
267
- "UploadPartChunk"
271
+ "UploadPartChunk",
272
+ "UploadStatus"
268
273
  ];
269
274
  }
270
275
 
@@ -387,7 +387,7 @@ exports.UploadFiles = async function({libraryId, objectId, writeToken, fileInfo,
387
387
  for(let f = 0; f < files.length; f++) {
388
388
  const fileInfo = files[f];
389
389
 
390
- await this.UploadFileData({libraryId, objectId, writeToken, uploadId: id, jobId, fileData: fileInfo.data});
390
+ await this.UploadFileData({libraryId, objectId, writeToken, uploadId: id, jobId, filePath: fileInfo.path, fileData: fileInfo.data});
391
391
 
392
392
  delete jobSpecs[j].files[f].data;
393
393
  uploaded += fileInfo.len;
@@ -403,8 +403,10 @@ exports.UploadFiles = async function({libraryId, objectId, writeToken, fileInfo,
403
403
  }
404
404
  };
405
405
 
406
- // Preparing jobs is done asyncronously
407
- PrepareJobs();
406
+ // Preparing jobs is done asynchronously
407
+ PrepareJobs().catch(e => {
408
+ throw e;
409
+ });
408
410
 
409
411
  // Upload the first several chunks in sequence, to determine average upload rate
410
412
  const rateTestJobs = Math.min(3, jobs.length);
@@ -485,35 +487,80 @@ exports.UploadJobStatus = async function({libraryId, objectId, writeToken, uploa
485
487
 
486
488
  const path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
487
489
 
488
- return this.utils.ResponseToJson(
489
- this.HttpClient.Request({
490
- headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
491
- method: "GET",
492
- path: path,
493
- failover: false
494
- })
495
- );
490
+ // This request is sent during file data upload and might fail due to congestion
491
+ do {
492
+ try {
493
+ let jobStatus = this.utils.ResponseToJson(
494
+ this.HttpClient.Request({
495
+ headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
496
+ method: "GET",
497
+ path: path,
498
+ failover: false
499
+ })
500
+ );
501
+ return jobStatus;
502
+ } catch(error) {
503
+ this.Log(error, true);
504
+
505
+ retries += 1;
506
+ if(retries >= 5) {
507
+ throw error;
508
+ }
509
+ await new Promise(resolve => setTimeout(resolve, 10 * retries * 1000));
510
+ }
511
+ } while(retries < 5);
512
+
496
513
  };
497
514
 
498
- exports.UploadFileData = async function({libraryId, objectId, writeToken, uploadId, jobId, fileData}) {
515
+ exports.UploadFileData = async function({libraryId, objectId, writeToken, uploadId, jobId, filePath, fileData}) {
499
516
  ValidateParameters({libraryId, objectId});
500
517
  ValidateWriteToken(writeToken);
501
518
 
502
- let path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
519
+ let retries = 0;
520
+ do {
521
+ try {
503
522
 
504
- await this.utils.ResponseToJson(
505
- this.HttpClient.Request({
506
- method: "POST",
507
- path: path,
508
- body: fileData,
509
- bodyType: "BINARY",
510
- headers: {
511
- "Content-type": "application/octet-stream",
512
- ...(await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}))
513
- },
514
- failover: false
515
- })
516
- );
523
+ const jobStatus = await this.UploadJobStatus({libraryId, objectId, writeToken, uploadId, jobId});
524
+
525
+ // Find the status of this file
526
+ const fileStatus = jobStatus.files.find(item => {
527
+ return item.path == filePath
528
+ });
529
+
530
+ if(fileStatus.rem === 0) {
531
+ // Job is actually done
532
+ return;
533
+ } else if(fileStatus.skip) {
534
+ fileData = fileData.slice(fileStatus.skip);
535
+ }
536
+
537
+ let path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
538
+
539
+ return await this.utils.ResponseToJson(
540
+ this.HttpClient.Request({
541
+ method: "POST",
542
+ path: path,
543
+ body: fileData,
544
+ bodyType: "BINARY",
545
+ headers: {
546
+ "Content-type": "application/octet-stream",
547
+ ...(await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}))
548
+ },
549
+ failover: false
550
+ })
551
+ );
552
+ } catch(error){
553
+ this.Log(error, true);
554
+
555
+ retries += 1;
556
+
557
+ if(retries >= 5) {
558
+ throw error;
559
+ }
560
+
561
+ await new Promise(resolve => setTimeout(resolve, 10 * retries * 1000));
562
+ }
563
+ } while(retries < 5);
517
564
  };
518
565
 
519
566
  exports.FinalizeUploadJob = async function({libraryId, objectId, writeToken}) {
@@ -1481,8 +1481,6 @@ exports.RejectMarketplaceOffer = async function({offerId}) {
1481
1481
  /* Voting */
1482
1482
 
1483
1483
  /**
1484
- * <b><i>Requires login</i></b>
1485
- *
1486
1484
  * Retrieve the current status of the specified voting event
1487
1485
  *
1488
1486
  * @methodGroup Voting