@eluvio/elv-client-js 4.0.20 → 4.0.21

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.
@@ -265,6 +265,7 @@ var AuthorizationClient = /*#__PURE__*/function () {
265
265
  return this.client.ContentObjectMetadata({
266
266
  libraryId: libraryId,
267
267
  objectId: objectId,
268
+ versionHash: versionHash,
268
269
  metadataSubtree: ownerCapKey
269
270
  });
270
271
  case 16:
@@ -3904,6 +3904,7 @@ exports.EncryptionConk = /*#__PURE__*/function () {
3904
3904
  return this.ContentObjectMetadata({
3905
3905
  libraryId: libraryId,
3906
3906
  objectId: objectId,
3907
+ versionHash: versionHash,
3907
3908
  metadataSubtree: ownerCapKey
3908
3909
  });
3909
3910
  case 10:
@@ -535,7 +535,8 @@ exports.UploadFiles = /*#__PURE__*/function () {
535
535
  uploadId: id,
536
536
  jobId: jobId,
537
537
  filePath: _fileInfo2.path,
538
- fileData: _fileInfo2.data
538
+ fileData: _fileInfo2.data,
539
+ encryption: encryption
539
540
  });
540
541
  case 12:
541
542
  delete jobSpecs[j].files[f].data;
@@ -729,7 +730,7 @@ exports.UploadStatus = /*#__PURE__*/function () {
729
730
  }();
730
731
  exports.UploadJobStatus = /*#__PURE__*/function () {
731
732
  var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
732
- var libraryId, objectId, writeToken, uploadId, jobId, path, jobStatus;
733
+ var libraryId, objectId, writeToken, uploadId, jobId, path, retries, jobStatus;
733
734
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
734
735
  while (1) switch (_context9.prev = _context9.next) {
735
736
  case 0:
@@ -740,17 +741,18 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
740
741
  });
741
742
  ValidateWriteToken(writeToken);
742
743
  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;
744
+ retries = 0;
745
+ case 5:
746
+ _context9.prev = 5;
745
747
  _context9.t0 = this.utils;
746
748
  _context9.t1 = this.HttpClient;
747
- _context9.next = 9;
749
+ _context9.next = 10;
748
750
  return this.authClient.AuthorizationHeader({
749
751
  libraryId: libraryId,
750
752
  objectId: objectId,
751
753
  update: true
752
754
  });
753
- case 9:
755
+ case 10:
754
756
  _context9.t2 = _context9.sent;
755
757
  _context9.t3 = path;
756
758
  _context9.t4 = {
@@ -762,31 +764,31 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
762
764
  _context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
763
765
  jobStatus = _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5);
764
766
  return _context9.abrupt("return", jobStatus);
765
- case 17:
766
- _context9.prev = 17;
767
- _context9.t6 = _context9["catch"](4);
767
+ case 18:
768
+ _context9.prev = 18;
769
+ _context9.t6 = _context9["catch"](5);
768
770
  this.Log(_context9.t6, true);
769
771
  retries += 1;
770
772
  if (!(retries >= 5)) {
771
- _context9.next = 23;
773
+ _context9.next = 24;
772
774
  break;
773
775
  }
774
776
  throw _context9.t6;
775
- case 23:
776
- _context9.next = 25;
777
+ case 24:
778
+ _context9.next = 26;
777
779
  return new Promise(function (resolve) {
778
780
  return setTimeout(resolve, 10 * retries * 1000);
779
781
  });
780
- case 25:
782
+ case 26:
781
783
  if (retries < 5) {
782
- _context9.next = 4;
784
+ _context9.next = 5;
783
785
  break;
784
786
  }
785
- case 26:
787
+ case 27:
786
788
  case "end":
787
789
  return _context9.stop();
788
790
  }
789
- }, _callee9, this, [[4, 17]]);
791
+ }, _callee9, this, [[5, 18]]);
790
792
  }));
791
793
  return function (_x10) {
792
794
  return _ref15.apply(this, arguments);
@@ -794,11 +796,11 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
794
796
  }();
795
797
  exports.UploadFileData = /*#__PURE__*/function () {
796
798
  var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref16) {
797
- var libraryId, objectId, writeToken, uploadId, jobId, filePath, fileData, retries, jobStatus, fileStatus, path;
799
+ var libraryId, objectId, writeToken, encryption, uploadId, jobId, filePath, fileData, retries, jobStatus, fileStatus, path;
798
800
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
799
801
  while (1) switch (_context10.prev = _context10.next) {
800
802
  case 0:
801
- libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, filePath = _ref16.filePath, fileData = _ref16.fileData;
803
+ libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, encryption = _ref16.encryption, uploadId = _ref16.uploadId, jobId = _ref16.jobId, filePath = _ref16.filePath, fileData = _ref16.fileData;
802
804
  ValidateParameters({
803
805
  libraryId: libraryId,
804
806
  objectId: objectId
@@ -821,16 +823,19 @@ exports.UploadFileData = /*#__PURE__*/function () {
821
823
  fileStatus = jobStatus.files.find(function (item) {
822
824
  return item.path == filePath;
823
825
  });
826
+ if (encryption && encryption !== "none") {
827
+ fileStatus = fileStatus.encrypted;
828
+ }
824
829
  if (!(fileStatus.rem === 0)) {
825
- _context10.next = 13;
830
+ _context10.next = 14;
826
831
  break;
827
832
  }
828
833
  return _context10.abrupt("return");
829
- case 13:
834
+ case 14:
830
835
  if (fileStatus.skip) {
831
836
  fileData = fileData.slice(fileStatus.skip);
832
837
  }
833
- case 14:
838
+ case 15:
834
839
  path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
835
840
  _context10.t0 = this.utils;
836
841
  _context10.t1 = this.HttpClient;
@@ -840,13 +845,13 @@ exports.UploadFileData = /*#__PURE__*/function () {
840
845
  _context10.t5 = {
841
846
  "Content-type": "application/octet-stream"
842
847
  };
843
- _context10.next = 23;
848
+ _context10.next = 24;
844
849
  return this.authClient.AuthorizationHeader({
845
850
  libraryId: libraryId,
846
851
  objectId: objectId,
847
852
  update: true
848
853
  });
849
- case 23:
854
+ case 24:
850
855
  _context10.t6 = _context10.sent;
851
856
  _context10.t7 = (0, _context10.t4)(_context10.t5, _context10.t6);
852
857
  _context10.t8 = {
@@ -858,35 +863,35 @@ exports.UploadFileData = /*#__PURE__*/function () {
858
863
  failover: false
859
864
  };
860
865
  _context10.t9 = _context10.t1.Request.call(_context10.t1, _context10.t8);
861
- _context10.next = 29;
866
+ _context10.next = 30;
862
867
  return _context10.t0.ResponseToJson.call(_context10.t0, _context10.t9);
863
- case 29:
868
+ case 30:
864
869
  return _context10.abrupt("return", _context10.sent);
865
- case 32:
866
- _context10.prev = 32;
870
+ case 33:
871
+ _context10.prev = 33;
867
872
  _context10.t10 = _context10["catch"](4);
868
873
  this.Log(_context10.t10, true);
869
874
  retries += 1;
870
875
  if (!(retries >= 5)) {
871
- _context10.next = 38;
876
+ _context10.next = 39;
872
877
  break;
873
878
  }
874
879
  throw _context10.t10;
875
- case 38:
876
- _context10.next = 40;
880
+ case 39:
881
+ _context10.next = 41;
877
882
  return new Promise(function (resolve) {
878
883
  return setTimeout(resolve, 10 * retries * 1000);
879
884
  });
880
- case 40:
885
+ case 41:
881
886
  if (retries < 5) {
882
887
  _context10.next = 4;
883
888
  break;
884
889
  }
885
- case 41:
890
+ case 42:
886
891
  case "end":
887
892
  return _context10.stop();
888
893
  }
889
- }, _callee10, this, [[4, 32]]);
894
+ }, _callee10, this, [[4, 33]]);
890
895
  }));
891
896
  return function (_x11) {
892
897
  return _ref17.apply(this, arguments);
@@ -1046,7 +1051,7 @@ exports.DeleteFiles = /*#__PURE__*/function () {
1046
1051
  * @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
1047
1052
  * @param {string=} writeToken - Write token for the draft from which to download the file
1048
1053
  * @param {string} filePath - Path to the file to download
1049
- * @param {string=} format="blob" - Format in which to return the data ("blob" | "arraybuffer" | "buffer)
1054
+ * @param {string=} format="arrayBuffer" - Format in which to return the data ("blob" | "arraybuffer" | "buffer")
1050
1055
  * @param {boolean=} chunked=false - If specified, file will be downloaded and decrypted in chunks. The
1051
1056
  * specified callback will be invoked on completion of each chunk. This is recommended for large files.
1052
1057
  * @param {number=} chunkSize=1000000 - Size of file chunks to request for download
@@ -1126,6 +1131,7 @@ exports.DownloadFile = /*#__PURE__*/function () {
1126
1131
  return this.ContentObjectMetadata({
1127
1132
  libraryId: libraryId,
1128
1133
  objectId: objectId,
1134
+ versionHash: versionHash,
1129
1135
  metadataSubtree: ownerCapKey
1130
1136
  });
1131
1137
  case 17:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.20",
3
+ "version": "4.0.21",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -192,7 +192,7 @@ class AuthorizationClient {
192
192
  if(encryption && encryption !== "none" && objectId && await this.AccessType(objectId) === ACCESS_TYPES.OBJECT) {
193
193
  const owner = await this.Owner({id: objectId});
194
194
  const ownerCapKey = `eluv.caps.iusr${Utils.AddressToHash(this.client.signer.address)}`;
195
- const ownerCap = await this.client.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
195
+ const ownerCap = await this.client.ContentObjectMetadata({libraryId, objectId, versionHash, metadataSubtree: ownerCapKey});
196
196
 
197
197
  if(!Utils.EqualAddress(owner, this.client.signer.address) && !ownerCap) {
198
198
  const cap = await this.ReEncryptionConk({libraryId, objectId});
@@ -2477,7 +2477,7 @@ exports.EncryptionConk = async function({libraryId, objectId, versionHash, write
2477
2477
  const owner = await this.authClient.Owner({id: objectId});
2478
2478
 
2479
2479
  const ownerCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
2480
- const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
2480
+ const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, versionHash, metadataSubtree: ownerCapKey});
2481
2481
 
2482
2482
  if(!this.utils.EqualAddress(owner, this.signer.address) && !ownerCap) {
2483
2483
  if(download) {
@@ -387,7 +387,16 @@ 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, filePath: fileInfo.path, fileData: fileInfo.data});
390
+ await this.UploadFileData({
391
+ libraryId,
392
+ objectId,
393
+ writeToken,
394
+ uploadId: id,
395
+ jobId,
396
+ filePath: fileInfo.path,
397
+ fileData: fileInfo.data,
398
+ encryption
399
+ });
391
400
 
392
401
  delete jobSpecs[j].files[f].data;
393
402
  uploaded += fileInfo.len;
@@ -488,6 +497,7 @@ exports.UploadJobStatus = async function({libraryId, objectId, writeToken, uploa
488
497
  const path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
489
498
 
490
499
  // This request is sent during file data upload and might fail due to congestion
500
+ let retries = 0;
491
501
  do {
492
502
  try {
493
503
  let jobStatus = this.utils.ResponseToJson(
@@ -512,7 +522,7 @@ exports.UploadJobStatus = async function({libraryId, objectId, writeToken, uploa
512
522
 
513
523
  };
514
524
 
515
- exports.UploadFileData = async function({libraryId, objectId, writeToken, uploadId, jobId, filePath, fileData}) {
525
+ exports.UploadFileData = async function({libraryId, objectId, writeToken, encryption, uploadId, jobId, filePath, fileData}) {
516
526
  ValidateParameters({libraryId, objectId});
517
527
  ValidateWriteToken(writeToken);
518
528
 
@@ -523,9 +533,10 @@ exports.UploadFileData = async function({libraryId, objectId, writeToken, upload
523
533
  const jobStatus = await this.UploadJobStatus({libraryId, objectId, writeToken, uploadId, jobId});
524
534
 
525
535
  // Find the status of this file
526
- const fileStatus = jobStatus.files.find(item => {
527
- return item.path == filePath
528
- });
536
+ let fileStatus = jobStatus.files.find(item => item.path == filePath);
537
+ if(encryption && encryption !== "none") {
538
+ fileStatus = fileStatus.encrypted;
539
+ }
529
540
 
530
541
  if(fileStatus.rem === 0) {
531
542
  // Job is actually done
@@ -637,7 +648,7 @@ exports.DeleteFiles = async function({libraryId, objectId, writeToken, filePaths
637
648
  * @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
638
649
  * @param {string=} writeToken - Write token for the draft from which to download the file
639
650
  * @param {string} filePath - Path to the file to download
640
- * @param {string=} format="blob" - Format in which to return the data ("blob" | "arraybuffer" | "buffer)
651
+ * @param {string=} format="arrayBuffer" - Format in which to return the data ("blob" | "arraybuffer" | "buffer")
641
652
  * @param {boolean=} chunked=false - If specified, file will be downloaded and decrypted in chunks. The
642
653
  * specified callback will be invoked on completion of each chunk. This is recommended for large files.
643
654
  * @param {number=} chunkSize=1000000 - Size of file chunks to request for download
@@ -689,7 +700,7 @@ exports.DownloadFile = async function({
689
700
 
690
701
  // If not owner, indicate re-encryption
691
702
  const ownerCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
692
- const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
703
+ const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, versionHash, metadataSubtree: ownerCapKey});
693
704
 
694
705
  if(encrypted && !this.utils.EqualAddress(this.signer.address, await this.ContentObjectOwner({objectId})) && !ownerCap) {
695
706
  headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";