@eluvio/elv-client-js 3.1.92 → 3.1.93

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.
@@ -192,7 +192,7 @@ function () {
192
192
  this.noCache = true;
193
193
  }
194
194
 
195
- if (this.client.signer && this.client.signer.remoteSigner) {
195
+ if (channelAuth && this.client.signer && this.client.signer.remoteSigner) {
196
196
  // Channel auth not supported for remote signer, use a self-signed no-auth token instead
197
197
  noAuth = true;
198
198
  channelAuth = false;
@@ -338,7 +338,7 @@ function () {
338
338
  addr: Utils.FormatAddress(this.client.signer && this.client.signer.address || "")
339
339
  };
340
340
 
341
- if (this.noAuth || noAuth) {
341
+ if (!(!(this.noAuth || noAuth) && !this.client.signer.remoteSigner)) {
342
342
  _context3.next = 29;
343
343
  break;
344
344
  }
@@ -94,10 +94,10 @@ function () {
94
94
  headers: this.RequestHeaders(bodyType, headers)
95
95
  };
96
96
 
97
- if (method === "POST" || method === "PUT") {
97
+ if (method === "POST" || method === "PUT" || method === "DELETE") {
98
98
  if (body && bodyType === "JSON") {
99
99
  fetchParameters.body = JSON.stringify(body);
100
- } else {
100
+ } else if (body) {
101
101
  fetchParameters.body = body;
102
102
  }
103
103
  }
@@ -907,7 +907,8 @@ function () {
907
907
  * Note: This method is not accessible to applications. Eluvio core will drop the request.
908
908
  *
909
909
  * @namedParams
910
- * @param level
910
+ * @param {string} id - The tenant ID in hash format
911
+ * @param {string} address - The group address to use in the hash if id is not provided
911
912
  */
912
913
 
913
914
  }, {
@@ -920,7 +921,7 @@ function () {
920
921
  case 0:
921
922
  id = _ref15.id, address = _ref15.address;
922
923
 
923
- if (!(id && !id.startsWith("iten"))) {
924
+ if (!(id && (!id.startsWith("iten") || !Utils.ValidHash(id)))) {
924
925
  _context13.next = 3;
925
926
  break;
926
927
  }
@@ -928,51 +929,63 @@ function () {
928
929
  throw Error("Invalid tenant ID: ".concat(id));
929
930
 
930
931
  case 3:
931
- if (address) {
932
- id = "iten".concat(Utils.AddressToHash(address));
932
+ if (!address) {
933
+ _context13.next = 7;
934
+ break;
935
+ }
936
+
937
+ if (Utils.ValidAddress(address)) {
938
+ _context13.next = 6;
939
+ break;
933
940
  }
934
941
 
935
- _context13.prev = 4;
936
- _context13.next = 7;
942
+ throw Error("Invalid address: ".concat(address));
943
+
944
+ case 6:
945
+ id = "iten".concat(Utils.AddressToHash(address));
946
+
947
+ case 7:
948
+ _context13.prev = 7;
949
+ _context13.next = 10;
937
950
  return _regeneratorRuntime.awrap(this.client.AccessType({
938
951
  id: id
939
952
  }));
940
953
 
941
- case 7:
954
+ case 10:
942
955
  version = _context13.sent;
943
956
 
944
957
  if (!(version !== this.client.authClient.ACCESS_TYPES.GROUP)) {
945
- _context13.next = 10;
958
+ _context13.next = 13;
946
959
  break;
947
960
  }
948
961
 
949
962
  throw Error("Invalid tenant ID: " + id);
950
963
 
951
- case 10:
952
- _context13.next = 15;
964
+ case 13:
965
+ _context13.next = 18;
953
966
  break;
954
967
 
955
- case 12:
956
- _context13.prev = 12;
957
- _context13.t0 = _context13["catch"](4);
968
+ case 15:
969
+ _context13.prev = 15;
970
+ _context13.t0 = _context13["catch"](7);
958
971
  throw Error("Invalid tenant ID: " + id);
959
972
 
960
- case 15:
961
- _context13.next = 17;
973
+ case 18:
974
+ _context13.next = 20;
962
975
  return _regeneratorRuntime.awrap(this.ReplaceUserMetadata({
963
976
  metadataSubtree: "tenantId",
964
977
  metadata: id
965
978
  }));
966
979
 
967
- case 17:
980
+ case 20:
968
981
  this.tenantId = id;
969
982
 
970
- case 18:
983
+ case 21:
971
984
  case "end":
972
985
  return _context13.stop();
973
986
  }
974
987
  }
975
- }, null, this, [[4, 12]]);
988
+ }, null, this, [[7, 15]]);
976
989
  }
977
990
  /**
978
991
  * Get the URL of the current user's profile image
package/dist/src/Utils.js CHANGED
@@ -6,6 +6,8 @@ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
6
6
 
7
7
  var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
8
8
 
9
+ var _this = this;
10
+
9
11
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
10
12
 
11
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -22,7 +24,9 @@ var VarInt = require("varint");
22
24
 
23
25
  var URI = require("urijs");
24
26
 
25
- var keccak256 = require("ethers").utils.keccak256;
27
+ var _require$utils = require("ethers").utils,
28
+ keccak256 = _require$utils.keccak256,
29
+ getAddress = _require$utils.getAddress;
26
30
  /**
27
31
  * @namespace
28
32
  * @description This is a utility namespace mostly containing functions for managing
@@ -161,6 +165,145 @@ var Utils = {
161
165
  };
162
166
  },
163
167
 
168
+ /**
169
+ * Decode the specified write token into its component parts
170
+ *
171
+ * @param writeToken
172
+ *
173
+ * @returns {Object} - Components of the write token.
174
+ */
175
+ DecodeWriteToken: function DecodeWriteToken(writeToken) {
176
+ /*
177
+ Format:
178
+ - content write token, LRO:
179
+ - prefix: "tq__", "tqw__", "tlro"
180
+ - format:
181
+ prefix + base58(uvarint(len(QID) | QID |
182
+ uvarint(len(NID) | NID |
183
+ uvarint(len(RAND_BYTES) | RAND_BYTES)
184
+ - content part write token:
185
+ - prefix: "tqp_"
186
+ - format:
187
+ prefix + base58(scheme | flags | uvarint(len(RAND_BYTES) | RAND_BYTES)
188
+ - content write token v1, content part write token v1:
189
+ - prefix: "tqw_", "tqpw"
190
+ - format:
191
+ prefix + base58(RAND_BYTES)
192
+ */
193
+ if (writeToken.length < 4) {
194
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (unknown prefix)"));
195
+ }
196
+
197
+ var tokenType;
198
+
199
+ if (writeToken.startsWith("tqw__")) {
200
+ tokenType = "tq__";
201
+ writeToken = writeToken.slice(5);
202
+ } else {
203
+ tokenType = writeToken.slice(0, 4);
204
+ writeToken = writeToken.slice(4);
205
+ }
206
+
207
+ if (writeToken.length === 0) {
208
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (too short)"));
209
+ }
210
+
211
+ switch (tokenType) {
212
+ case "tqw_":
213
+ case "tq__":
214
+ case "tqpw":
215
+ case "tqp_":
216
+ case "tlro":
217
+ break;
218
+
219
+ default:
220
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (unknown prefix)"));
221
+ } // decode base58 payload
222
+
223
+
224
+ var bytes = Utils.FromB58(writeToken);
225
+
226
+ function decodeBytes(isID, prefix) {
227
+ var bsize = VarInt.decode(bytes, 0); // decode: count of bytes to read
228
+
229
+ var offset = VarInt.decode.bytes; // offset in buffer to start read after decode
230
+
231
+ var theBytes;
232
+ var ret;
233
+
234
+ if (isID) {
235
+ theBytes = bytes.slice(offset + 1, bsize + offset); // skip 1st byte (code id) at offset 0
236
+
237
+ if (theBytes.length === 0) {
238
+ ret = "";
239
+ } else {
240
+ ret = prefix + Utils.B58(theBytes);
241
+ }
242
+ } else {
243
+ theBytes = bytes.slice(offset, bsize + offset);
244
+ ret = "0x" + theBytes.toString("hex");
245
+ }
246
+
247
+ bytes = bytes.slice(bsize + offset);
248
+ return ret;
249
+ }
250
+
251
+ var tokenId;
252
+ var qid;
253
+ var nid;
254
+ var scheme;
255
+ var flags;
256
+
257
+ switch (tokenType) {
258
+ case "tqw_": // content write token v1
259
+
260
+ case "tqpw":
261
+ // content part write token v1
262
+ tokenId = "0x" + bytes.toString("hex");
263
+ break;
264
+
265
+ case "tlro": // LRO,
266
+
267
+ case "tq__":
268
+ // content write token
269
+ qid = decodeBytes(true, "iq__");
270
+ nid = decodeBytes(true, "inod");
271
+ tokenId = decodeBytes(false, "");
272
+ break;
273
+
274
+ case "tqp_":
275
+ // content part write token
276
+ if (bytes.length < 3) {
277
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (token truncated)"));
278
+ }
279
+
280
+ scheme = bytes[0];
281
+ flags = bytes[1];
282
+ bytes = bytes.slice(2);
283
+ tokenId = decodeBytes(false, "");
284
+ break;
285
+
286
+ default:
287
+ // already raised
288
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (unknown prefix)"));
289
+ }
290
+
291
+ return {
292
+ tokenType: tokenType,
293
+ // type of token
294
+ tokenId: tokenId,
295
+ // random bytes generated by the fabric node
296
+ objectId: qid,
297
+ // content id for content write token (tq__) or LRO (tlro)
298
+ nodeId: nid,
299
+ // node id where the content write token is valid (tq__)
300
+ scheme: scheme,
301
+ // encryption scheme for part write token - (tqp_)
302
+ flags: flags // flags for part write token (tqp_)
303
+
304
+ };
305
+ },
306
+
164
307
  /**
165
308
  * Convert contract address to multiformat hash
166
309
  *
@@ -259,6 +402,35 @@ var Utils = {
259
402
  return Utils.HashToAddress(firstHash) === Utils.HashToAddress(secondHash);
260
403
  },
261
404
 
405
+ /**
406
+ * Determine whether the address is valid
407
+ *
408
+ * @param {string} address - Address to validate
409
+ *
410
+ * @returns {boolean} - Whether or not the address is valid
411
+ */
412
+ ValidAddress: function ValidAddress(address) {
413
+ try {
414
+ getAddress(address);
415
+ return true;
416
+ } catch (error) {
417
+ _this.Log(error);
418
+
419
+ return false;
420
+ }
421
+ },
422
+
423
+ /**
424
+ * Determine whether the hash is valid
425
+ *
426
+ * @param {string} hash - Hash to validate
427
+ *
428
+ * @returns {boolean} - Whether or not the hash is valid
429
+ */
430
+ ValidHash: function ValidHash(hash) {
431
+ return Utils.ValidAddress(Utils.HashToAddress(hash));
432
+ },
433
+
262
434
  /**
263
435
  * Convert the specified string to a bytes32 string
264
436
  *
@@ -465,37 +465,44 @@ exports.ContentType = function _callee6(_ref5) {
465
465
  }
466
466
 
467
467
  if (!name) {
468
- _context6.next = 8;
468
+ _context6.next = 13;
469
469
  break;
470
470
  }
471
471
 
472
472
  this.Log("Looking up type by name in content space metadata..."); // Look up named type in content space metadata
473
473
 
474
- _context6.next = 7;
474
+ _context6.prev = 5;
475
+ _context6.next = 8;
475
476
  return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
476
477
  libraryId: this.contentSpaceLibraryId,
477
478
  objectId: this.contentSpaceObjectId,
478
479
  metadataSubtree: UrlJoin("public", "contentTypes", name)
479
480
  }));
480
481
 
481
- case 7:
482
+ case 8:
482
483
  typeId = _context6.sent;
484
+ _context6.next = 13;
485
+ break;
483
486
 
484
- case 8:
487
+ case 11:
488
+ _context6.prev = 11;
489
+ _context6.t0 = _context6["catch"](5);
490
+
491
+ case 13:
485
492
  if (typeId) {
486
- _context6.next = 18;
493
+ _context6.next = 23;
487
494
  break;
488
495
  }
489
496
 
490
497
  this.Log("Looking up type by name in available types...");
491
- _context6.next = 12;
498
+ _context6.next = 17;
492
499
  return _regeneratorRuntime.awrap(this.ContentTypes());
493
500
 
494
- case 12:
501
+ case 17:
495
502
  types = _context6.sent;
496
503
 
497
504
  if (!name) {
498
- _context6.next = 17;
505
+ _context6.next = 22;
499
506
  break;
500
507
  }
501
508
 
@@ -503,35 +510,35 @@ exports.ContentType = function _callee6(_ref5) {
503
510
  return (type.name || "").toLowerCase() === name.toLowerCase();
504
511
  }));
505
512
 
506
- case 17:
513
+ case 22:
507
514
  return _context6.abrupt("return", Object.values(types).find(function (type) {
508
515
  return type.hash === versionHash;
509
516
  }));
510
517
 
511
- case 18:
518
+ case 23:
512
519
  if (versionHash) {
513
- _context6.next = 22;
520
+ _context6.next = 27;
514
521
  break;
515
522
  }
516
523
 
517
- _context6.next = 21;
524
+ _context6.next = 26;
518
525
  return _regeneratorRuntime.awrap(this.LatestVersionHash({
519
526
  objectId: typeId
520
527
  }));
521
528
 
522
- case 21:
529
+ case 26:
523
530
  versionHash = _context6.sent;
524
531
 
525
- case 22:
526
- _context6.prev = 22;
532
+ case 27:
533
+ _context6.prev = 27;
527
534
  this.Log("Looking up type by ID...");
528
535
 
529
536
  if (!publicOnly) {
530
- _context6.next = 34;
537
+ _context6.next = 39;
531
538
  break;
532
539
  }
533
540
 
534
- _context6.next = 27;
541
+ _context6.next = 32;
535
542
  return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
536
543
  libraryId: this.contentSpaceLibraryId,
537
544
  objectId: typeId,
@@ -539,46 +546,46 @@ exports.ContentType = function _callee6(_ref5) {
539
546
  metadataSubtree: "public"
540
547
  }));
541
548
 
542
- case 27:
543
- _context6.t0 = _context6.sent;
549
+ case 32:
550
+ _context6.t1 = _context6.sent;
544
551
 
545
- if (_context6.t0) {
546
- _context6.next = 30;
552
+ if (_context6.t1) {
553
+ _context6.next = 35;
547
554
  break;
548
555
  }
549
556
 
550
- _context6.t0 = {};
557
+ _context6.t1 = {};
551
558
 
552
- case 30:
553
- _context6.t1 = _context6.t0;
559
+ case 35:
560
+ _context6.t2 = _context6.t1;
554
561
  metadata = {
555
- "public": _context6.t1
562
+ "public": _context6.t2
556
563
  };
557
- _context6.next = 40;
564
+ _context6.next = 45;
558
565
  break;
559
566
 
560
- case 34:
561
- _context6.next = 36;
567
+ case 39:
568
+ _context6.next = 41;
562
569
  return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
563
570
  libraryId: this.contentSpaceLibraryId,
564
571
  objectId: typeId,
565
572
  versionHash: versionHash
566
573
  }));
567
574
 
568
- case 36:
569
- _context6.t2 = _context6.sent;
575
+ case 41:
576
+ _context6.t3 = _context6.sent;
570
577
 
571
- if (_context6.t2) {
572
- _context6.next = 39;
578
+ if (_context6.t3) {
579
+ _context6.next = 44;
573
580
  break;
574
581
  }
575
582
 
576
- _context6.t2 = {};
583
+ _context6.t3 = {};
577
584
 
578
- case 39:
579
- metadata = _context6.t2;
585
+ case 44:
586
+ metadata = _context6.t3;
580
587
 
581
- case 40:
588
+ case 45:
582
589
  return _context6.abrupt("return", {
583
590
  id: typeId,
584
591
  hash: versionHash,
@@ -586,19 +593,19 @@ exports.ContentType = function _callee6(_ref5) {
586
593
  meta: metadata
587
594
  });
588
595
 
589
- case 43:
590
- _context6.prev = 43;
591
- _context6.t3 = _context6["catch"](22);
596
+ case 48:
597
+ _context6.prev = 48;
598
+ _context6.t4 = _context6["catch"](27);
592
599
  this.Log("Error looking up content type:");
593
- this.Log(_context6.t3);
600
+ this.Log(_context6.t4);
594
601
  throw new Error("Content Type ".concat(name || typeId, " is invalid"));
595
602
 
596
- case 48:
603
+ case 53:
597
604
  case "end":
598
605
  return _context6.stop();
599
606
  }
600
607
  }
601
- }, null, this, [[22, 43]]);
608
+ }, null, this, [[5, 11], [27, 48]]);
602
609
  };
603
610
  /**
604
611
  * List all content types accessible to this user.
@@ -631,25 +638,35 @@ exports.ContentTypes = function _callee8() {
631
638
  this.Log("Personally available types:");
632
639
  this.Log(typeAddresses); // Content space types
633
640
 
634
- _context8.next = 9;
641
+ contentSpaceTypes = {};
642
+ _context8.prev = 8;
643
+ _context8.next = 11;
635
644
  return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
636
645
  libraryId: this.contentSpaceLibraryId,
637
646
  objectId: this.contentSpaceObjectId,
638
647
  metadataSubtree: "public/contentTypes"
639
648
  }));
640
649
 
641
- case 9:
650
+ case 11:
642
651
  _context8.t0 = _context8.sent;
643
652
 
644
653
  if (_context8.t0) {
645
- _context8.next = 12;
654
+ _context8.next = 14;
646
655
  break;
647
656
  }
648
657
 
649
658
  _context8.t0 = {};
650
659
 
651
- case 12:
660
+ case 14:
652
661
  contentSpaceTypes = _context8.t0;
662
+ _context8.next = 19;
663
+ break;
664
+
665
+ case 17:
666
+ _context8.prev = 17;
667
+ _context8.t1 = _context8["catch"](8);
668
+
669
+ case 19:
653
670
  contentSpaceTypeAddresses = Object.values(contentSpaceTypes).map(function (typeId) {
654
671
  return _this3.utils.HashToAddress(typeId);
655
672
  });
@@ -662,7 +679,7 @@ exports.ContentTypes = function _callee8() {
662
679
  }).filter(function (v, i, a) {
663
680
  return a.indexOf(v) === i;
664
681
  });
665
- _context8.next = 19;
682
+ _context8.next = 25;
666
683
  return _regeneratorRuntime.awrap(Promise.all(typeAddresses.map(function _callee7(typeAddress) {
667
684
  var typeId;
668
685
  return _regeneratorRuntime.async(function _callee7$(_context7) {
@@ -702,15 +719,15 @@ exports.ContentTypes = function _callee8() {
702
719
  }, null, null, [[2, 8]]);
703
720
  })));
704
721
 
705
- case 19:
722
+ case 25:
706
723
  return _context8.abrupt("return", this.contentTypes);
707
724
 
708
- case 20:
725
+ case 26:
709
726
  case "end":
710
727
  return _context8.stop();
711
728
  }
712
729
  }
713
- }, null, this);
730
+ }, null, this, [[8, 17]]);
714
731
  };
715
732
  /* Content Libraries */
716
733
 
@@ -502,18 +502,26 @@ exports.CreateContentLibrary = function _callee4(_ref6) {
502
502
 
503
503
  case 19:
504
504
  if (!tenantId) {
505
+ _context5.next = 24;
506
+ break;
507
+ }
508
+
509
+ if (this.utils.ValidHash(tenantId)) {
505
510
  _context5.next = 22;
506
511
  break;
507
512
  }
508
513
 
509
- _context5.next = 22;
514
+ throw Error("Invalid tenant ID: ".concat(tenantId));
515
+
516
+ case 22:
517
+ _context5.next = 24;
510
518
  return _regeneratorRuntime.awrap(this.CallContractMethod({
511
519
  contractAddress: contractAddress,
512
520
  methodName: "putMeta",
513
521
  methodArgs: ["_tenantId", tenantId]
514
522
  }));
515
523
 
516
- case 22:
524
+ case 24:
517
525
  metadata = _objectSpread({}, metadata, {
518
526
  name: name,
519
527
  description: description,
@@ -527,15 +535,15 @@ exports.CreateContentLibrary = function _callee4(_ref6) {
527
535
  this.Log("Contract address: ".concat(contractAddress)); // Set library content object type and metadata on automatically created library object
528
536
 
529
537
  objectId = libraryId.replace("ilib", "iq__");
530
- _context5.next = 29;
538
+ _context5.next = 31;
531
539
  return _regeneratorRuntime.awrap(this.EditContentObject({
532
540
  libraryId: libraryId,
533
541
  objectId: objectId
534
542
  }));
535
543
 
536
- case 29:
544
+ case 31:
537
545
  editResponse = _context5.sent;
538
- _context5.next = 32;
546
+ _context5.next = 34;
539
547
  return _regeneratorRuntime.awrap(this.ReplaceMetadata({
540
548
  libraryId: libraryId,
541
549
  objectId: objectId,
@@ -543,8 +551,8 @@ exports.CreateContentLibrary = function _callee4(_ref6) {
543
551
  writeToken: editResponse.write_token
544
552
  }));
545
553
 
546
- case 32:
547
- _context5.next = 34;
554
+ case 34:
555
+ _context5.next = 36;
548
556
  return _regeneratorRuntime.awrap(this.FinalizeContentObject({
549
557
  libraryId: libraryId,
550
558
  objectId: objectId,
@@ -552,24 +560,24 @@ exports.CreateContentLibrary = function _callee4(_ref6) {
552
560
  commitMessage: "Create library"
553
561
  }));
554
562
 
555
- case 34:
563
+ case 36:
556
564
  if (!image) {
557
- _context5.next = 37;
565
+ _context5.next = 39;
558
566
  break;
559
567
  }
560
568
 
561
- _context5.next = 37;
569
+ _context5.next = 39;
562
570
  return _regeneratorRuntime.awrap(this.SetContentLibraryImage({
563
571
  libraryId: libraryId,
564
572
  image: image,
565
573
  imageName: imageName
566
574
  }));
567
575
 
568
- case 37:
576
+ case 39:
569
577
  this.Log("Library ".concat(libraryId, " created"));
570
578
  return _context5.abrupt("return", libraryId);
571
579
 
572
- case 39:
580
+ case 41:
573
581
  case "end":
574
582
  return _context5.stop();
575
583
  }