@droz-js/sdk
Advanced tools
Comparing version 0.2.6 to 0.2.7
{ | ||
"name": "@droz-js/sdk", | ||
"description": "Droz SDK", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "exports": { |
@@ -61,21 +61,23 @@ "use strict"; | ||
if (this.tenantConfigs.has(tenant)) { | ||
return this.tenantConfigs.get(tenant); | ||
return await this.tenantConfigs.get(tenant); | ||
} | ||
return await this.discoverTenantConfig(tenant); | ||
} | ||
static async discoverTenantConfig(tenant) { | ||
// fetch instances from discovery service | ||
const data = await fetch(`${helpers_1.serviceDiscoveryEndpoint}/discover/${tenant}`); | ||
const json = await data.json(); | ||
const instances = json.instances ?? []; | ||
// validate it's a valid tenant | ||
if (instances.length === 0) { | ||
throw new Error(`Invalid tenant '${tenant}', no instances found on service discovery`); | ||
static discoverTenantConfig(tenant) { | ||
async function promise() { | ||
// fetch instances from discovery service | ||
const data = await fetch(`${helpers_1.serviceDiscoveryEndpoint}/discover/${tenant}`); | ||
const json = await data.json(); | ||
const instances = json.instances ?? []; | ||
// validate it's a valid tenant | ||
if (instances.length === 0) { | ||
throw new Error(`Invalid tenant '${tenant}', no instances found on service discovery`); | ||
} | ||
// create tenant config and cache it | ||
return new TenantConfig(tenant, instances); | ||
} | ||
// create tenant config and cache it | ||
const config = new TenantConfig(tenant, instances); | ||
this.tenantConfigs.set(tenant, config); | ||
return config; | ||
this.tenantConfigs.set(tenant, promise()); | ||
return this.tenantConfigs.get(tenant); | ||
} | ||
} | ||
exports.DrozSdk = DrozSdk; |
200102
4491