@eluvio/elv-client-js 3.2.15 → 3.2.19

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.
@@ -1,6 +1,7 @@
1
1
  const {ElvClient} = require("../ElvClient");
2
2
  const Configuration = require("./Configuration");
3
3
  const {LinkTargetHash, FormatNFT, ActionPopup} = require("./Utils");
4
+ const HTTPClient = require("../HttpClient");
4
5
  const UrlJoin = require("url-join");
5
6
  const Utils = require("../Utils");
6
7
  const Ethers = require("ethers");
@@ -15,7 +16,9 @@ const embedded = inBrowser && window.top !== window.self;
15
16
  * See the Modules section on the sidebar for all client methods unrelated to login and authorization
16
17
  */
17
18
  class ElvWalletClient {
18
- constructor({client, network, mode, marketplaceInfo, storeAuthToken}) {
19
+ constructor({appId, client, network, mode, marketplaceInfo, storeAuthToken}) {
20
+ this.appId = appId;
21
+
19
22
  this.client = client;
20
23
  this.loggedIn = false;
21
24
 
@@ -33,6 +36,9 @@ class ElvWalletClient {
33
36
  this.availableMarketplacesById = {};
34
37
  this.marketplaceHashes = {};
35
38
 
39
+ this.stateStoreUrls = Configuration[network].stateStoreUrls;
40
+ this.stateStoreClient = new HTTPClient({uris: this.stateStoreUrls});
41
+
36
42
  // Caches
37
43
  this.cachedMarketplaces = {};
38
44
  this.cachedCSS = {};
@@ -60,8 +66,10 @@ class ElvWalletClient {
60
66
  *
61
67
  * Specify tenantSlug and marketplaceSlug to automatically associate this tenant with a particular marketplace.
62
68
  *
69
+ *
63
70
  * @methodGroup Initialization
64
71
  * @namedParams
72
+ * @param {string} appId - A string identifying your app. This is used for namespacing user profile data.
65
73
  * @param {string} network=main - Name of the Fabric network to use (`main`, `demo`)
66
74
  * @param {string} mode=production - Environment to use (`production`, `staging`)
67
75
  * @param {Object=} marketplaceParams - Marketplace parameters
@@ -70,6 +78,7 @@ class ElvWalletClient {
70
78
  * @returns {Promise<ElvWalletClient>}
71
79
  */
72
80
  static async Initialize({
81
+ appId="general",
73
82
  network="main",
74
83
  mode="production",
75
84
  marketplaceParams,
@@ -86,6 +95,7 @@ class ElvWalletClient {
86
95
  const client = await ElvClient.FromNetworkName({networkName: network, assumeV3: true});
87
96
 
88
97
  const walletClient = new ElvWalletClient({
98
+ appId,
89
99
  client,
90
100
  network,
91
101
  mode,
@@ -217,6 +227,9 @@ class ElvWalletClient {
217
227
  /**
218
228
  * Direct the user to the Eluvio Media Wallet login page.
219
229
  *
230
+ * For redirect login, the authorization token will be included in the URL parameters of the callbackUrl. Simply re-initialize the wallet client and it will authorize with this token,
231
+ * or you can retrieve the parameter (`elvToken`) yourself and use it in the <a href="#Authenticate">Authenticate</a> method.
232
+ *
220
233
  * <b>NOTE:</b> The domain of the opening window (popup flow) or domain of the `callbackUrl` (redirect flow) MUST be allowed in the metadata of the specified marketplace.
221
234
  *
222
235
  * @methodGroup Login
@@ -682,6 +695,7 @@ class ElvWalletClient {
682
695
  }
683
696
 
684
697
  item.nftTemplateMetadata = ((item.nft_template || {}).nft || {});
698
+ item.nftTemplateHash = ((item.nft_template || {})["."] || {}).source;
685
699
  item.itemIndex = index;
686
700
 
687
701
  return item;
@@ -743,20 +757,29 @@ class ElvWalletClient {
743
757
  priceRange,
744
758
  tokenIdRange,
745
759
  capLimit,
760
+ userAddress,
746
761
  sellerAddress,
747
762
  lastNDays=-1,
763
+ includeCheckoutLocked=false,
748
764
  start=0,
749
765
  limit=50
750
766
  }={}) {
751
767
  collectionIndexes = (collectionIndexes || []).map(i => parseInt(i));
752
768
 
753
769
  let params = {
754
- sort_by: sortBy,
755
- sort_descending: sortDesc,
756
770
  start,
757
- limit
771
+ limit,
772
+ sort_descending: sortDesc
758
773
  };
759
774
 
775
+ if(mode !== "leaderboard") {
776
+ params.sort_by = sortBy;
777
+ }
778
+
779
+ if(mode.includes("listings") && includeCheckoutLocked) {
780
+ params.checkout = true;
781
+ }
782
+
760
783
  let marketplaceInfo, marketplace;
761
784
  if(marketplaceParams) {
762
785
  marketplaceInfo = await this.MarketplaceInfo({marketplaceParams});
@@ -771,6 +794,8 @@ class ElvWalletClient {
771
794
 
772
795
  if(sellerAddress) {
773
796
  filters.push(`seller:eq:${this.client.utils.FormatAddress(sellerAddress)}`);
797
+ } else if(userAddress && mode !== "owned") {
798
+ filters.push(`addr:eq:${this.client.utils.FormatAddress(userAddress)}`);
774
799
  }
775
800
 
776
801
  if(marketplace && collectionIndexes.length >= 0) {
@@ -797,7 +822,7 @@ class ElvWalletClient {
797
822
  }
798
823
  });
799
824
  });
800
- } else if(mode !== "owned" && marketplaceInfo || tenantId) {
825
+ } else if(marketplaceInfo || tenantId) {
801
826
  filters.push(`tenant:eq:${marketplaceInfo ? marketplaceInfo.tenantId : tenantId}`);
802
827
  }
803
828
 
@@ -815,8 +840,7 @@ class ElvWalletClient {
815
840
  if(mode.includes("listing")) {
816
841
  filters.push(`nft/display_name:eq:${filter}`);
817
842
  } else if(mode === "owned") {
818
- filters.push(`meta:@>:{"display_name":"${filter}"}`);
819
- params.exact = false;
843
+ filters.push(`meta/display_name:eq:${filter}`);
820
844
  } else {
821
845
  filters.push(`name:eq:${filter}`);
822
846
  }
@@ -879,12 +903,7 @@ class ElvWalletClient {
879
903
  let path;
880
904
  switch(mode) {
881
905
  case "owned":
882
- path = UrlJoin("as", "wlt", "nfts");
883
-
884
- if(marketplaceInfo) {
885
- path = UrlJoin("as", "wlt", "nfts", marketplaceInfo.tenantId);
886
- }
887
-
906
+ path = UrlJoin("as", "wlt", userAddress || this.UserAddress());
888
907
  break;
889
908
 
890
909
  case "listings":
@@ -911,6 +930,10 @@ class ElvWalletClient {
911
930
  path = UrlJoin("as", "mkt", "stats", "sold");
912
931
  filters.push("seller:co:0x");
913
932
  break;
933
+
934
+ case "leaderboard":
935
+ path = UrlJoin("as", "wlt", "leaders");
936
+ break;
914
937
  }
915
938
 
916
939
  if(filters.length > 0) {
@@ -931,10 +954,7 @@ class ElvWalletClient {
931
954
  await this.client.authClient.MakeAuthServiceRequest({
932
955
  path,
933
956
  method: "GET",
934
- queryParams: params,
935
- headers: mode === "owned" ?
936
- { Authorization: `Bearer ${this.AuthToken()}` } :
937
- {}
957
+ queryParams: params
938
958
  })
939
959
  ) || [];
940
960
 
@@ -945,7 +965,7 @@ class ElvWalletClient {
945
965
  total: paging.total,
946
966
  more: paging.total > start + limit
947
967
  },
948
- results: (contents || []).map(item => ["owned", "listings"].includes(mode) ? FormatNFT(item) : item)
968
+ results: (contents || []).map(item => ["owned", "listings"].includes(mode) ? FormatNFT(this, item) : item)
949
969
  };
950
970
  } catch(error) {
951
971
  if(error.status && error.status.toString() === "404") {
@@ -1028,5 +1048,6 @@ class ElvWalletClient {
1028
1048
  }
1029
1049
 
1030
1050
  Object.assign(ElvWalletClient.prototype, require("./ClientMethods"));
1051
+ Object.assign(ElvWalletClient.prototype, require("./Profile"));
1031
1052
 
1032
1053
  exports.ElvWalletClient = ElvWalletClient;