sap-cf-features
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -82,3 +82,4 @@ "use strict"; | ||
const service = getService(); | ||
const url = `/api/v2/evaluateset?${names.map((name) => `flag=${name}`).join('&')}` + identifier ? `&identifier=${identifier || ""}` : ``; | ||
const identifierUrl = identifier ? `&identifier=${identifier || ""}` : ``; | ||
const url = `/api/v2/evaluateset?${names.map((name) => `flag=${name}`).join('&')}${identifierUrl}`; | ||
const response = yield axios_1.default.get(url, { | ||
@@ -98,5 +99,8 @@ url, | ||
const value = Object.values(tenant)[0]; | ||
if (value.httpStatus !== 404) { | ||
if (value && value.httpStatus !== 404) { | ||
acc[flagName] = value.type === "BOOLEAN" ? value.variation === "true" : value.variation; | ||
} | ||
else { | ||
console.error(`Cannot read values for ${flagName}: ${tenant}`); | ||
} | ||
return acc; | ||
@@ -103,0 +107,0 @@ }, {}); |
@@ -36,2 +36,2 @@ export { IFeatureFlagExport, IFeatureFlagMap, IReturnFlag, IFeatureService } from './types'; | ||
*/ | ||
export declare function featureFlagRouter(): import("express-serve-static-core").Router; | ||
export declare function featureFlagRouter(forConnect?: boolean): import("express-serve-static-core").Router; |
@@ -87,3 +87,3 @@ "use strict"; | ||
*/ | ||
function featureFlagRouter() { | ||
function featureFlagRouter(forConnect = false) { | ||
const router = express_1.Router(); | ||
@@ -93,2 +93,13 @@ function getDomain(req) { | ||
} | ||
function respond(res, next, result, status = 200) { | ||
if (forConnect) { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify(result)); | ||
} | ||
else { | ||
res.status(200).json(result); | ||
next(); | ||
} | ||
} | ||
router.get('/:flagName', (req, res, next) => __awaiter(this, void 0, void 0, function* () { | ||
@@ -98,4 +109,3 @@ //@ts-ignore | ||
const result = yield getFeatureFlags(flagName, getDomain(req)); | ||
res.status(200).json(result).end(); | ||
//next(); | ||
respond(res, next, result); | ||
})); | ||
@@ -106,4 +116,3 @@ router.get('/', (req, res, next) => __awaiter(this, void 0, void 0, function* () { | ||
const result = yield getFeatureFlags(flagNames, getDomain(req)); | ||
res.status(200).json(result).end(); | ||
//next(); | ||
respond(res, next, result); | ||
})); | ||
@@ -110,0 +119,0 @@ return router; |
{ | ||
"name": "sap-cf-features", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Read SAP CF feature flags in nodejs", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
16958
332