@eluvio/elv-client-js 4.0.138 → 4.0.140

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.138",
3
+ "version": "4.0.140",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -185,25 +185,8 @@ class ElvWalletClient {
185
185
  }
186
186
  }
187
187
 
188
- try {
189
- walletClient.topLevelInfoPromise = client.utils.ResponseToJson(
190
- client.MakeAuthServiceRequest({
191
- path: "/as/mw/toplevel",
192
- queryParams: {env: mode}
193
- })
194
- )
195
- .then(info => {
196
- walletClient.topLevelInfo = info;
197
-
198
- if(!skipMarketplaceLoad) {
199
- walletClient.LoadAvailableMarketplaces();
200
- }
201
- });
202
- } catch(error) {
203
- // eslint-disable-next-line no-console
204
- console.error("Unable to load top level info:");
205
- // eslint-disable-next-line no-console
206
- console.error(error);
188
+ if(!skipMarketplaceLoad) {
189
+ walletClient.LoadAvailableMarketplaces();
207
190
  }
208
191
 
209
192
  return walletClient;
@@ -771,39 +754,57 @@ class ElvWalletClient {
771
754
 
772
755
  // Internal loading methods
773
756
 
774
- async LoadAvailableMarketplaces(forceReload=false) {
775
- if(!forceReload && Object.keys(this.availableMarketplaces) > 0) {
776
- return;
757
+ async TopLevelInfo(forceReload=false) {
758
+ if(!this.topLevelInfoPromise || forceReload) {
759
+ this.topLevelInfoPromise = this.client.utils.ResponseToJson(
760
+ this.client.MakeAuthServiceRequest({
761
+ path: "/as/mw/toplevel",
762
+ queryParams: {env: this.mode}
763
+ })
764
+ );
777
765
  }
778
766
 
779
- const marketplaces = this.topLevelInfo.marketplaces;
780
-
781
- let availableMarketplaces = { ...(this.availableMarketplaces || {}) };
782
- let availableMarketplacesById = { ...(this.availableMarketplacesById || {}) };
767
+ return await this.topLevelInfoPromise;
768
+ }
783
769
 
784
- marketplaces.map(marketplaceInfo => {
785
- const marketplaceId = Utils.DecodeVersionHash(marketplaceInfo.source_hash).objectId;
786
- const marketplaceSlug = marketplaceInfo.slug || marketplaceInfo.name;
770
+ async LoadAvailableMarketplaces(forceReload=false) {
771
+ if(!this.availableMarketplacesPromise || forceReload) {
772
+ this.availableMarketplacesPromise = new Promise(async resolve => {
773
+ const topLevelInfo = await this.TopLevelInfo();
774
+ const marketplaces = topLevelInfo.marketplaces;
775
+
776
+ let availableMarketplaces = {...(this.availableMarketplaces || {})};
777
+ let availableMarketplacesById = {...(this.availableMarketplacesById || {})};
778
+
779
+ marketplaces.map(marketplaceInfo => {
780
+ const marketplaceId = Utils.DecodeVersionHash(marketplaceInfo.source_hash).objectId;
781
+ const marketplaceSlug = marketplaceInfo.slug || marketplaceInfo.name;
782
+
783
+ availableMarketplaces[marketplaceInfo.tenant_slug] = availableMarketplaces[marketplaceInfo.tenant_slug] || {};
784
+
785
+ availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug] = {
786
+ ...marketplaceInfo,
787
+ tenantName: marketplaceInfo.tenant_slug,
788
+ tenantSlug: marketplaceInfo.tenant_slug,
789
+ tenantId: marketplaceInfo.tenant_id,
790
+ marketplaceSlug: marketplaceSlug,
791
+ marketplaceId,
792
+ marketplaceHash: marketplaceInfo.source_hash
793
+ };
787
794
 
788
- availableMarketplaces[marketplaceInfo.tenant_slug] = availableMarketplaces[marketplaceInfo.tenant_slug] || {};
795
+ availableMarketplacesById[marketplaceId] = availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug];
789
796
 
790
- availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug] = {
791
- ...marketplaceInfo,
792
- tenantName: marketplaceInfo.tenant_slug,
793
- tenantSlug: marketplaceInfo.tenant_slug,
794
- tenantId: marketplaceInfo.tenant_id,
795
- marketplaceSlug: marketplaceSlug,
796
- marketplaceId,
797
- marketplaceHash: marketplaceInfo.source_hash
798
- };
797
+ this.marketplaceHashes[marketplaceId] = marketplaceInfo.source_hash;
798
+ });
799
799
 
800
- availableMarketplacesById[marketplaceId] = availableMarketplaces[marketplaceInfo.tenant_slug][marketplaceSlug];
800
+ this.availableMarketplaces = availableMarketplaces;
801
+ this.availableMarketplacesById = availableMarketplacesById;
801
802
 
802
- this.marketplaceHashes[marketplaceId] = marketplaceInfo.source_hash;
803
- });
803
+ resolve();
804
+ });
805
+ }
804
806
 
805
- this.availableMarketplaces = availableMarketplaces;
806
- this.availableMarketplacesById = availableMarketplacesById;
807
+ await this.availableMarketplacesPromise;
807
808
  }
808
809
 
809
810
  // Get the hash of the currently linked marketplace
@@ -826,7 +827,8 @@ class ElvWalletClient {
826
827
  }
827
828
 
828
829
  async LoadMarketplace(marketplaceParams) {
829
- await this.topLevelInfoPromise;
830
+ await this.LoadAvailableMarketplaces();
831
+
830
832
  const marketplaceInfo = this.MarketplaceInfo({marketplaceParams});
831
833
 
832
834
  const marketplaceId = marketplaceInfo.marketplaceId;