tas-client
Advanced tools
Comparing version 0.1.16 to 0.1.21
@@ -13,2 +13,10 @@ /** | ||
/** | ||
* Promise that resolves when the experimentation service has completed | ||
* its first request to the Treatment Assignment Service. If this request | ||
* is successful, flights are up-to-date. | ||
*/ | ||
readonly initialFetch: Promise<void>; | ||
/** | ||
* @deprecated Use `getTreatmentVariable` instead. | ||
* | ||
* Returns a value indicating whether the given flight is enabled. | ||
@@ -21,2 +29,4 @@ * It uses the values currently in memory, so the experimentation service | ||
/** | ||
* @deprecated Use `getTreatmentVariable` instead. | ||
* | ||
* Returns a value indicating whether the given flight is enabled. | ||
@@ -28,2 +38,4 @@ * It uses the values currently on cache. | ||
/** | ||
* @deprecated Use `getTreatmentVariableAsync` instead. | ||
* | ||
* Returns a value indicating whether the given flight is enabled. | ||
@@ -44,7 +56,9 @@ * It re-fetches values from the server. | ||
* Returns the value of the treatment variable, or undefined if not found. | ||
* It re-fetches values from the server. | ||
* It re-fetches values from the server. If checkCache is true and the value exists | ||
* in the cache, the Treatment Assignment Service is not called. | ||
* @param config name of the config to check. | ||
* @param name name of the treatment variable. | ||
* @param checkCache check the cache for the variable before calling the TAS. | ||
*/ | ||
getTreatmentVariableAsync<T extends boolean | number | string>(configId: string, name: string): Promise<T | undefined>; | ||
getTreatmentVariableAsync<T extends boolean | number | string>(configId: string, name: string, checkCache?: boolean): Promise<T | undefined>; | ||
} |
{ | ||
"name": "tas-client", | ||
"version": "0.1.16", | ||
"version": "0.1.21", | ||
"description": "This package is intended to be used as an endpoint client to query, refetch, and cache data from the Experimentation service (or any given endpoint). The endpoint result must follow the required structure for experimentation data.", | ||
@@ -34,3 +34,3 @@ "main": "./out/src/index", | ||
"mocha": "^8.0.1", | ||
"nerdbank-gitversioning": "^2.3.183", | ||
"nerdbank-gitversioning": "^3.3.37", | ||
"prettier": "^1.18.2", | ||
@@ -37,0 +37,0 @@ "source-map-support": "^0.5.16", |
@@ -23,2 +23,4 @@ import { IExperimentationService } from '../contracts/IExperimentationService'; | ||
readonly initializePromise: Promise<void>; | ||
private resolveInitialFetchPromise; | ||
readonly initialFetch: Promise<void>; | ||
private cachedTelemetryEvents; | ||
@@ -68,7 +70,9 @@ private _features; | ||
* Returns the value of the treatment variable, or undefined if not found. | ||
* It re-fetches values from the server. | ||
* It re-fetches values from the server. If checkCache is set to true and the value exists | ||
* in the cache, the Treatment Assignment Service is not called. | ||
* @param config name of the config to check. | ||
* @param name name of the treatment variable. | ||
* @param checkCache check the cache for the variable before calling the TAS. | ||
*/ | ||
getTreatmentVariableAsync<T extends boolean | number | string>(configId: string, name: string): Promise<T | undefined>; | ||
getTreatmentVariableAsync<T extends boolean | number | string>(configId: string, name: string, checkCache?: boolean): Promise<T | undefined>; | ||
private PostEventToTelemetry; | ||
@@ -75,0 +79,0 @@ protected invokeInit(): void; |
@@ -19,3 +19,2 @@ "use strict"; | ||
this.featuresConsumed = false; | ||
this.initializePromise = this.loadCachePromise; | ||
this.cachedTelemetryEvents = []; | ||
@@ -34,2 +33,6 @@ this._features = { | ||
this.loadCachePromise = this.loadCachedFeatureData(); | ||
this.initializePromise = this.loadCachePromise; | ||
this.initialFetch = new Promise((resolve, reject) => { | ||
this.resolveInitialFetchPromise = resolve; | ||
}); | ||
} | ||
@@ -59,3 +62,8 @@ get features() { | ||
if (this.fetchPromise != null) { | ||
await this.fetchPromise; | ||
try { | ||
await this.fetchPromise; | ||
} | ||
catch (_a) { | ||
// Fetching features threw. Can happen if not connected to the internet, e.g | ||
} | ||
return this.features; | ||
@@ -76,5 +84,14 @@ } | ||
})); | ||
let featureResults = await this.fetchPromise; | ||
try { | ||
const featureResults = await this.fetchPromise; | ||
this.updateFeatures(featureResults, overrideInMemoryFeatures); | ||
} | ||
catch (_b) { | ||
// Fetching features threw. Can happen if not connected to the internet, e.g. | ||
} | ||
this.fetchPromise = undefined; | ||
this.updateFeatures(featureResults, overrideInMemoryFeatures); | ||
if (this.resolveInitialFetchPromise) { | ||
this.resolveInitialFetchPromise(); | ||
this.resolveInitialFetchPromise = undefined; | ||
} | ||
/** | ||
@@ -191,7 +208,19 @@ * At this point all features have been re-fetched and cache has been updated. | ||
* Returns the value of the treatment variable, or undefined if not found. | ||
* It re-fetches values from the server. | ||
* It re-fetches values from the server. If checkCache is set to true and the value exists | ||
* in the cache, the Treatment Assignment Service is not called. | ||
* @param config name of the config to check. | ||
* @param name name of the treatment variable. | ||
* @param checkCache check the cache for the variable before calling the TAS. | ||
*/ | ||
async getTreatmentVariableAsync(configId, name) { | ||
async getTreatmentVariableAsync(configId, name, checkCache) { | ||
if (checkCache) { | ||
const _featuresConsumed = this.featuresConsumed; | ||
const cachedValue = this.getTreatmentVariable(configId, name); | ||
if (cachedValue === undefined) { | ||
this.featuresConsumed = _featuresConsumed; | ||
} | ||
else { | ||
return cachedValue; | ||
} | ||
} | ||
await this.getFeaturesAsync(true); | ||
@@ -198,0 +227,0 @@ return this.getTreatmentVariable(configId, name); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55591
931