@eluvio/elv-client-js 4.0.105 → 4.0.107

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.
@@ -420,20 +420,20 @@ await client.userProfileClient.UserMetadata()
420
420
  }
421
421
 
422
422
  /**
423
- * Return the ID of the tenant this user belongs to, if set.
423
+ * Return the ID of the tenant admin group set for current user
424
424
  *
425
425
  * @return {Promise<string>} - Tenant ID
426
426
  */
427
427
  async TenantId() {
428
428
  if(!this.tenantId) {
429
- this.tenantId = await this.UserMetadata({metadataSubtree: "tenantId"});
429
+ const {objectId} = await this.UserWalletObjectInfo();
430
+ this.tenantId = await this.client.TenantId({ objectId });
430
431
  }
431
-
432
432
  return this.tenantId;
433
433
  }
434
434
 
435
435
  /**
436
- * Set the current user's tenant
436
+ * Set the current user's tenant admin group ID
437
437
  *
438
438
  * Note: This method is not accessible to applications. Eluvio core will drop the request.
439
439
  *
@@ -441,7 +441,8 @@ await client.userProfileClient.UserMetadata()
441
441
  * @param {string} id - The tenant ID in hash format
442
442
  * @param {string} address - The group address to use in the hash if id is not provided
443
443
  */
444
- async SetTenantId({id, address}) {
444
+ async SetTenantId({ id, address }) {
445
+
445
446
  if(id && (!id.startsWith("iten") || !Utils.ValidHash(id))) {
446
447
  throw Error(`Invalid tenant ID: ${id}`);
447
448
  }
@@ -454,19 +455,11 @@ await client.userProfileClient.UserMetadata()
454
455
  id = `iten${Utils.AddressToHash(address)}`;
455
456
  }
456
457
 
457
- try {
458
- const version = await this.client.AccessType({id});
459
-
460
- if(version !== this.client.authClient.ACCESS_TYPES.GROUP) {
461
- throw Error("Invalid tenant ID: " + id);
462
- }
463
- } catch(error) {
464
- throw Error("Invalid tenant ID: " + id);
465
- }
466
-
467
- await this.ReplaceUserMetadata({metadataSubtree: "tenantId", metadata: id});
458
+ const {objectId} = await this.UserWalletObjectInfo();
468
459
 
469
- this.tenantId = id;
460
+ const tenantInfo = await this.client.SetTenantId({ objectId, tenantId: id });
461
+ this.tenantContractId = tenantInfo.tenantContractId;
462
+ this.tenantId = tenantInfo.tenantId;
470
463
  }
471
464
 
472
465
  /**
@@ -477,9 +470,7 @@ await client.userProfileClient.UserMetadata()
477
470
  async TenantContractId() {
478
471
  if(!this.tenantContractId) {
479
472
  const {objectId} = await this.UserWalletObjectInfo();
480
- this.tenantContractId = await this.client.TenantContractId({
481
- contractAddress: this.client.utils.HashToAddress(objectId)
482
- });
473
+ this.tenantContractId = await this.client.TenantContractId({ objectId });
483
474
  }
484
475
  return this.tenantContractId;
485
476
  }
@@ -498,6 +489,14 @@ await client.userProfileClient.UserMetadata()
498
489
 
499
490
  const tenantInfo = await this.client.SetTenantContractId({ objectId,tenantContractId });
500
491
  this.tenantContractId = tenantInfo.tenantContractId;
492
+ this.tenantId = tenantInfo.tenantId;
493
+ }
494
+
495
+ async ResetTenantId(){
496
+ const {objectId} = await this.UserWalletObjectInfo();
497
+ await this.client.ResetTenantId({objectId});
498
+ this.tenantId = this.client.TenantId({objectId});
499
+ this.tenantContractId = this.client.TenantContractId({objectId});
501
500
  }
502
501
 
503
502
  /**
@@ -11,7 +11,8 @@ const {
11
11
  ValidateAddress,
12
12
  ValidateParameters,
13
13
  ValidatePresence,
14
- ValidateObject, ValidateVersion
14
+ ValidateObject,
15
+ ValidateVersion
15
16
  } = require("../Validation");
16
17
  const Utils=require("../Utils");
17
18
 
@@ -579,19 +580,7 @@ exports.SendFunds = async function({recipient, ether}) {
579
580
  return await transaction.wait();
580
581
  };
581
582
 
582
- /**
583
- * Retrieve the ID of the tenant contract for the specified object
584
- *
585
- * @methodGroup Tenant
586
- * @namedParams
587
- * @param {string=} contractAddress - The address of the object
588
- * @param {string=} objectId - The ID of the object
589
- * @param {string=} versionHash - A version hash of the object
590
- *
591
- * @returns {Promise<string|undefined>}
592
- */
593
- exports.TenantContractId = async function({contractAddress, objectId, versionHash}) {
594
-
583
+ const GetObjectIDAndContractAddress = async function({contractAddress, objectId, versionHash}){
595
584
  if(contractAddress){
596
585
  ValidateAddress(contractAddress);
597
586
  objectId = Utils.AddressToObjectId(contractAddress);
@@ -606,32 +595,165 @@ exports.TenantContractId = async function({contractAddress, objectId, versionHas
606
595
  throw Error("contractAddress or objectId or versionHash not specified");
607
596
  }
608
597
 
609
- const hasGetMetaMethod = await this.authClient.ContractHasMethod({
610
- contractAddress: contractAddress,
611
- methodName: "getMeta"
612
- });
598
+ return {
599
+ contractAddress,
600
+ objectId
601
+ };
602
+ };
603
+
604
+ /**
605
+ * Retrieve the ID of the tenant admin group set for the specified object
606
+ *
607
+ * @methodGroup Tenant
608
+ * @namedParams
609
+ * @param {string=} contractAddress - The address of the object
610
+ * @param {string=} objectId - The ID of the object
611
+ * @param {string=} versionHash - A version hash of the object
612
+ *
613
+ * @returns {Promise<string|undefined>}
614
+ */
615
+ exports.TenantId = async function({contractAddress, objectId, versionHash}) {
613
616
 
614
- if(hasGetMetaMethod) {
615
- const tenantContractId = await this.ContractMetadata({
616
- contractAddress:contractAddress,
617
- metadataKey:"_ELV_TENANT_ID"
617
+ objectInfo = await GetObjectIDAndContractAddress({contractAddress, objectId, versionHash});
618
+ contractAddress = objectInfo.contractAddress;
619
+ objectId = objectInfo.objectId;
620
+
621
+ let tenantId;
622
+ try {
623
+ const hasGetMetaMethod = await this.authClient.ContractHasMethod({
624
+ contractAddress: contractAddress,
625
+ methodName: "getMeta"
618
626
  });
619
- if(tenantContractId !== "") {
620
- return tenantContractId;
627
+
628
+ if(hasGetMetaMethod) {
629
+ tenantId = await this.ContractMetadata({
630
+ contractAddress:contractAddress,
631
+ metadataKey:"_tenantId"
632
+ });
621
633
  }
634
+
635
+ // If the getMeta method does not exist or is not set in the contract, check the fabric metadata.
636
+ if(tenantId === undefined) {
637
+ const libraryId = await this.ContentObjectLibraryId({ objectId });
638
+
639
+ tenantId = await this.ContentObjectMetadata({
640
+ libraryId,
641
+ objectId,
642
+ metadataSubtree: "tenantId",
643
+ });
644
+ }
645
+ return tenantId;
646
+ } catch(e) {
647
+ return "";
622
648
  }
649
+ };
623
650
 
624
- const libraryId = await this.ContentObjectLibraryId({ objectId });
651
+ /**
652
+ * Retrieve the ID of the tenant contract for the specified object
653
+ *
654
+ * @methodGroup Tenant
655
+ * @namedParams
656
+ * @param {string=} contractAddress - The address of the object
657
+ * @param {string=} objectId - The ID of the object
658
+ * @param {string=} versionHash - A version hash of the object
659
+ *
660
+ * @returns {Promise<string|undefined>}
661
+ */
662
+ exports.TenantContractId = async function({contractAddress, objectId, versionHash}) {
625
663
 
626
- return await this.ContentObjectMetadata({
627
- libraryId,
628
- objectId,
629
- metadataSubtree: "tenantContractId",
664
+ objectInfo = await GetObjectIDAndContractAddress({contractAddress, objectId, versionHash});
665
+ contractAddress = objectInfo.contractAddress;
666
+ objectId = objectInfo.objectId;
667
+
668
+ try {
669
+ const hasGetMetaMethod = await this.authClient.ContractHasMethod({
670
+ contractAddress: contractAddress,
671
+ methodName: "getMeta"
672
+ });
673
+ let tenantContractId;
674
+ if(hasGetMetaMethod) {
675
+ tenantContractId = await this.ContractMetadata({
676
+ contractAddress:contractAddress,
677
+ metadataKey:"_ELV_TENANT_ID"
678
+ });
679
+ }
680
+
681
+ // If the getMeta method does not exist or is not set in the contract, check the fabric metadata.
682
+ if(tenantContractId === undefined) {
683
+ const libraryId = await this.ContentObjectLibraryId({ objectId });
684
+
685
+ tenantContractId = await this.ContentObjectMetadata({
686
+ libraryId,
687
+ objectId,
688
+ metadataSubtree: "tenantContractId",
689
+ });
690
+ }
691
+ return tenantContractId;
692
+ } catch(e) {
693
+ return "";
694
+ }
695
+ };
696
+
697
+ /**
698
+ * Set the tenant contract ID and tenant admin group ID for the specified object
699
+ * when tenant admin group ID is provided
700
+ *
701
+ * @methodGroup Tenant
702
+ * @namedParams
703
+ * @param {string=} contractAddress - The address of the object
704
+ * @param {string=} objectId - The ID of the object
705
+ * @param {string=} versionHash - A version hash of the object
706
+ * @param {string} tenantContractId - The tenant contract ID to set
707
+ * @param {string} tenantId - The tenant ID to set
708
+ *
709
+ * @returns {Promise<{tenantId: (undefined|string), tenantContractId}>}
710
+ */
711
+ exports.SetTenantId = async function({contractAddress, objectId, versionHash, tenantId}) {
712
+ objectInfo = await GetObjectIDAndContractAddress({contractAddress, objectId, versionHash});
713
+ contractAddress = objectInfo.contractAddress;
714
+ objectId = objectInfo.objectId;
715
+
716
+ const objectVersion = await this.authClient.AccessType(objectId);
717
+ if(objectVersion !== this.authClient.ACCESS_TYPES.GROUP &&
718
+ objectVersion !== this.authClient.ACCESS_TYPES.WALLET &&
719
+ objectVersion !== this.authClient.ACCESS_TYPES.LIBRARY &&
720
+ objectVersion !== this.authClient.ACCESS_TYPES.TYPE &&
721
+ objectVersion !== this.authClient.ACCESS_TYPES.TENANT) {
722
+ throw Error(`Invalid object ID: ${objectId},
723
+ applicable only for wallet,group, library or content_type object.`);
724
+ }
725
+
726
+ ValidateObject(tenantId);
727
+
728
+ if(!tenantId.startsWith("iten") || !Utils.ValidHash(tenantId)) {
729
+ throw Error(`Invalid tenant ID: ${tenantId}`);
730
+ }
731
+
732
+ const version = await this.authClient.AccessType(tenantId);
733
+ if(version !== this.authClient.ACCESS_TYPES.GROUP) {
734
+ throw Error("Invalid tenant ID: " + tenantId);
735
+ }
736
+
737
+ // get tenantContractId set for the tenant admin group
738
+ tenantContractId = await this.TenantContractId({
739
+ objectId: tenantId
630
740
  });
741
+ if(tenantContractId){
742
+ return await this.SetTenantContractId({
743
+ contractAddress,
744
+ objectId,
745
+ versionHash,
746
+ tenantContractId
747
+ });
748
+ } else {
749
+ throw Error("Invalid tenantId: tenant contract id not found");
750
+ }
631
751
  };
632
752
 
753
+
633
754
  /**
634
- * Set the tenant contract ID for the specified object
755
+ * Set the tenant contract ID and tenant admin group ID for the specified object
756
+ * when tenant contract ID is provided
635
757
  *
636
758
  * @methodGroup Tenant
637
759
  * @namedParams
@@ -644,19 +766,20 @@ exports.TenantContractId = async function({contractAddress, objectId, versionHas
644
766
  */
645
767
  exports.SetTenantContractId = async function({contractAddress, objectId, versionHash, tenantContractId}) {
646
768
 
647
- if(contractAddress){
648
- ValidateAddress(contractAddress);
649
- objectId = Utils.AddressToObjectId(contractAddress);
650
- } else if(versionHash){
651
- ValidateVersion(versionHash);
652
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
653
- contractAddress = Utils.HashToAddress(objectId);
654
- } else if(objectId){
655
- ValidateObject(objectId);
656
- contractAddress=Utils.HashToAddress(objectId);
657
- } else {
658
- throw Error("contractAddress or objectId or versionHash not specified");
769
+ objectInfo = await GetObjectIDAndContractAddress({contractAddress, objectId, versionHash});
770
+ contractAddress = objectInfo.contractAddress;
771
+ objectId = objectInfo.objectId;
772
+
773
+ const objectVersion = await this.authClient.AccessType(objectId);
774
+ if(objectVersion !== this.authClient.ACCESS_TYPES.GROUP &&
775
+ objectVersion !== this.authClient.ACCESS_TYPES.WALLET &&
776
+ objectVersion !== this.authClient.ACCESS_TYPES.LIBRARY &&
777
+ objectVersion !== this.authClient.ACCESS_TYPES.TYPE &&
778
+ objectVersion !== this.authClient.ACCESS_TYPES.TENANT) {
779
+ throw Error(`Invalid object ID: ${objectId},
780
+ applicable only for wallet,group, library or content_type object.`);
659
781
  }
782
+
660
783
  ValidateObject(tenantContractId);
661
784
 
662
785
  if(tenantContractId && (!tenantContractId.startsWith("iten") || !Utils.ValidHash(tenantContractId))) {
@@ -727,3 +850,82 @@ exports.SetTenantContractId = async function({contractAddress, objectId, version
727
850
  tenantId: !tenantAdminGroupAddress ? undefined : `iten${Utils.AddressToHash(tenantAdminGroupAddress)}`
728
851
  };
729
852
  };
853
+
854
+ /**
855
+ * Remove the tenant contract ID and tenant admin group ID for the specified object
856
+ *
857
+ * @methodGroup Tenant
858
+ * @namedParams
859
+ * @param {string=} contractAddress - The address of the object
860
+ * @param {string=} objectId - The ID of the object
861
+ * @param {string=} versionHash - A version hash of the object
862
+ *
863
+ * @returns {Promise<void>}
864
+ */
865
+ exports.ResetTenantId = async function({contractAddress, objectId, versionHash}) {
866
+
867
+ objectInfo = await GetObjectIDAndContractAddress({contractAddress, objectId, versionHash});
868
+ contractAddress = objectInfo.contractAddress;
869
+ objectId = objectInfo.objectId;
870
+
871
+ const objectVersion = await this.authClient.AccessType(objectId);
872
+ if(objectVersion !== this.authClient.ACCESS_TYPES.GROUP &&
873
+ objectVersion !== this.authClient.ACCESS_TYPES.WALLET &&
874
+ objectVersion !== this.authClient.ACCESS_TYPES.LIBRARY &&
875
+ objectVersion !== this.authClient.ACCESS_TYPES.TYPE &&
876
+ objectVersion !== this.authClient.ACCESS_TYPES.TENANT) {
877
+ throw Error(`Invalid object ID: ${objectId},
878
+ applicable only for wallet,group, library or content_type object.`);
879
+ }
880
+
881
+ let tenantContractId = this.TenantContractId({objectId});
882
+ let tenantId = this.TenantId({objectId});
883
+
884
+ if(tenantContractId || tenantId){
885
+ const hasPutMetaMethod = await this.authClient.ContractHasMethod({
886
+ contractAddress: contractAddress,
887
+ methodName: "putMeta"
888
+ });
889
+
890
+ if(hasPutMetaMethod) {
891
+
892
+ await this.ReplaceContractMetadata({
893
+ contractAddress: contractAddress,
894
+ metadataKey: "_ELV_TENANT_ID",
895
+ metadata: ""
896
+ });
897
+
898
+ await this.ReplaceContractMetadata({
899
+ contractAddress: contractAddress,
900
+ metadataKey: "_tenantId",
901
+ metadata: ""
902
+ });
903
+
904
+ } else {
905
+ const libraryId = await this.ContentObjectLibraryId({ objectId });
906
+ const editRequest = await this.EditContentObject({libraryId, objectId});
907
+
908
+ await this.MergeMetadata({
909
+ libraryId,
910
+ objectId,
911
+ writeToken: editRequest.write_token,
912
+ metadata: {
913
+ tenantContractId: undefined,
914
+ tenantId: undefined
915
+ },
916
+ });
917
+
918
+ await this.FinalizeContentObject({
919
+ libraryId,
920
+ objectId,
921
+ writeToken: editRequest.write_token,
922
+ commitMessage: "remove tenant_contract_id"
923
+ });
924
+ }
925
+ } else {
926
+ // eslint-disable-next-line no-console
927
+ console.warn("No tenant ID associated with current tenant.");
928
+ }
929
+ };
930
+
931
+
@@ -508,7 +508,7 @@ class LiveConf {
508
508
  elem.media_type = 1;
509
509
  elem.stream_name = "video";
510
510
  elem.stream_index = 0;
511
- elem.representation = "videovideo_" + videoStream.width + "x" + videoStream.height + "_h264@" + elem.bit_rate;
511
+ elem.representation = "videovideo_" + elem.width + "x" + elem.height + "_h264@" + elem.bit_rate;
512
512
  conf.live_recording.recording_config.recording_params.ladder_specs.push(elem);
513
513
  }
514
514
  // Currently the recording bitrate is the top bitrate of the ladder (it will be configurable separately in the future)