@sap-devx/feature-toggle-node
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,1 +1,17 @@ | ||
<a name="2.0.0"></a> | ||
# 2.0.0 (2022-01-19) | ||
### Features | ||
- Cache interval chagned to 15 minutes | ||
- Environment variables support | ||
- Removed FT_TOKEN, FT_SERVER_ENDPOINT | ||
- Added LANDSCAPE_INFRASTRUCTURE and FTM_HOST | ||
### BREAKING CHANGES | ||
- New client doesn't support unleash feature toggle anymore | ||
- Support new response from server | ||
<a name="1.0.9"></a> | ||
@@ -2,0 +18,0 @@ |
@@ -17,13 +17,8 @@ "use strict"; | ||
var _a; | ||
try { | ||
const toggles = await request_1.requestFeatureToggles(); | ||
if ((_a = toggles === null || toggles === void 0 ? void 0 : toggles.features) === null || _a === void 0 ? void 0 : _a.length) { | ||
Cache.flushCache(); | ||
Cache.setFeatureToggles(toggles); | ||
logger_1.log("Feature toggle cache updated"); | ||
} | ||
const toggles = await request_1.requestFeatureToggles(); | ||
if ((_a = toggles === null || toggles === void 0 ? void 0 : toggles.features) === null || _a === void 0 ? void 0 : _a.length) { | ||
Cache.flushCache(); | ||
Cache.setFeatureToggles(toggles); | ||
logger_1.log("Feature toggle cache updated"); | ||
} | ||
catch (e) { | ||
logger_1.log(e.message); | ||
} | ||
} | ||
@@ -48,3 +43,12 @@ exports.requestTogglesAndSaveNewCache = requestTogglesAndSaveNewCache; | ||
} | ||
/* | ||
* Starts cache refresh by interval | ||
* Returns boolean value from cache by toggle name | ||
* if toggle name not present function takes all toggles from cache | ||
* and calculate specific toggle | ||
* in case cache with toggles empty | ||
* makes request to server, update cache and calculate toggle value | ||
* */ | ||
async function findToggleAndReturnState(ftName) { | ||
var _a; | ||
if (!timeIntervalId) { | ||
@@ -58,3 +62,3 @@ refreshCacheByInterval(); | ||
const toggles = await getFeatureToggles(); | ||
if (toggles.features.length) { | ||
if ((_a = toggles === null || toggles === void 0 ? void 0 : toggles.features) === null || _a === void 0 ? void 0 : _a.length) { | ||
const toggle = findToggleByName(toggles, ftName); | ||
@@ -61,0 +65,0 @@ if (toggle) { |
@@ -13,3 +13,3 @@ "use strict"; | ||
} | ||
function requestFeatureToggles() { | ||
function makeRequest() { | ||
return new Promise((resolve, reject) => { | ||
@@ -24,6 +24,7 @@ https | ||
res.on("end", () => { | ||
resolve(JSON.parse(Buffer.concat(data).toString())); | ||
resolve(data); | ||
}); | ||
}) | ||
.on("error", (e) => { | ||
logger_1.log(e.message); | ||
reject(e); | ||
@@ -33,3 +34,16 @@ }); | ||
} | ||
/* | ||
* requestFeatureToggles always returns value | ||
* */ | ||
async function requestFeatureToggles() { | ||
try { | ||
const data = await makeRequest(); | ||
return JSON.parse(Buffer.concat(data).toString()); | ||
} | ||
catch (e) { | ||
logger_1.log(e.message); | ||
return {}; | ||
} | ||
} | ||
exports.requestFeatureToggles = requestFeatureToggles; | ||
//# sourceMappingURL=request.js.map |
{ | ||
"name": "@sap-devx/feature-toggle-node", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/api.js", |
@@ -36,11 +36,7 @@ import * as Cache from "./cache"; | ||
export async function requestTogglesAndSaveNewCache(): Promise<void> { | ||
try { | ||
const toggles = await requestFeatureToggles(); | ||
if (toggles?.features?.length) { | ||
Cache.flushCache(); | ||
Cache.setFeatureToggles(toggles); | ||
log("Feature toggle cache updated"); | ||
} | ||
} catch (e) { | ||
log(e.message); | ||
const toggles = await requestFeatureToggles(); | ||
if (toggles?.features?.length) { | ||
Cache.flushCache(); | ||
Cache.setFeatureToggles(toggles); | ||
log("Feature toggle cache updated"); | ||
} | ||
@@ -69,2 +65,10 @@ } | ||
/* | ||
* Starts cache refresh by interval | ||
* Returns boolean value from cache by toggle name | ||
* if toggle name not present function takes all toggles from cache | ||
* and calculate specific toggle | ||
* in case cache with toggles empty | ||
* makes request to server, update cache and calculate toggle value | ||
* */ | ||
export async function findToggleAndReturnState(ftName: string): Promise<boolean> { | ||
@@ -82,3 +86,4 @@ if (!timeIntervalId) { | ||
const toggles: Features = await getFeatureToggles(); | ||
if (toggles.features.length) { | ||
if (toggles?.features?.length) { | ||
const toggle: Toggle | undefined = findToggleByName(toggles, ftName); | ||
@@ -85,0 +90,0 @@ |
@@ -14,3 +14,3 @@ import { log } from "./logger"; | ||
export function requestFeatureToggles(): Promise<Features> { | ||
function makeRequest(): Promise<Uint8Array[]> { | ||
return new Promise((resolve, reject) => { | ||
@@ -27,6 +27,7 @@ https | ||
res.on("end", () => { | ||
resolve(JSON.parse(Buffer.concat(data).toString())); | ||
resolve(data); | ||
}); | ||
}) | ||
.on("error", (e) => { | ||
log(e.message); | ||
reject(e); | ||
@@ -36,1 +37,14 @@ }); | ||
} | ||
/* | ||
* requestFeatureToggles always returns value | ||
* */ | ||
export async function requestFeatureToggles(): Promise<Features> { | ||
try { | ||
const data = await makeRequest(); | ||
return JSON.parse(Buffer.concat(data).toString()); | ||
} catch (e) { | ||
log(e.message); | ||
return {} as Features; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
52368
679
1