@sap-devx/feature-toggle-node
Advanced tools
Comparing version 1.0.12 to 2.0.0
@@ -1,1 +0,1 @@ | ||
export declare function isFeatureEnabled(extensionName: string, featureToggleName: string): Promise<boolean>; | ||
export declare function isFeatureEnabled(extensionName: string, toggleName: string): Promise<boolean>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isFeatureEnabled = void 0; | ||
const clientManager = require("./unleash_client_manager"); | ||
const contextManager = require("./context_manager"); | ||
const logger_1 = require("./logger"); | ||
async function isFeatureEnabled(extensionName, featureToggleName) { | ||
logger_1.log(`Checking if Extension Name: "${extensionName}", Feature Toggle Name: "${featureToggleName}" is enabled`); | ||
const ftName = `${extensionName}.${featureToggleName}`; | ||
const client_1 = require("./client"); | ||
function validateFeatureToggleName(extensionName, toggleName) { | ||
if (!extensionName || !toggleName) { | ||
const errStr = !extensionName ? "extension " : ""; | ||
throw new Error(`Feature toggle ${errStr}name can not be empty, null or undefined`); | ||
} | ||
} | ||
async function isFeatureEnabled(extensionName, toggleName) { | ||
logger_1.log(`Checking if Extension Name: "${extensionName}", Feature Toggle Name: "${toggleName}" is enabled`); | ||
const ftName = `${extensionName}.${toggleName}`; | ||
try { | ||
if (!extensionName) { | ||
throw new Error("Feature toggle extension name can not be empty, null or undefined"); | ||
} | ||
if (!featureToggleName) { | ||
throw new Error("Feature toggle name can not be empty, null or undefined"); | ||
} | ||
//get unleash client | ||
const client = await clientManager.getUnleashClient(extensionName); | ||
// get the context | ||
const context = contextManager.getContext(extensionName); | ||
//check if the feature is enabled | ||
//fallback value is false (3rd parameter) | ||
return client.isEnabled(ftName, context, false); | ||
validateFeatureToggleName(extensionName, toggleName); | ||
return await client_1.findToggleAndReturnState(ftName); | ||
} | ||
@@ -28,3 +22,3 @@ catch (err) { | ||
logger_1.log(logErr); | ||
return false; // error creating an Unleash client -> return feature is disabled | ||
return false; | ||
} | ||
@@ -31,0 +25,0 @@ } |
@@ -1,1 +0,3 @@ | ||
export declare function getEnv(envName: string, errorMessage: string): string; | ||
export declare function getEnv(envName: string): string; | ||
export declare function getEnvWithError(envName: string, errorMessage: string): string; | ||
export declare function convertPluralNameToSingular(param: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEnv = void 0; | ||
exports.convertPluralNameToSingular = exports.getEnvWithError = exports.getEnv = void 0; | ||
const logger_1 = require("./logger"); | ||
function getEnv(envName, errorMessage) { | ||
//get feature server endpoint from env variable | ||
function throwError(errorMessage) { | ||
throw new Error(`[ERROR] ${errorMessage}`); | ||
} | ||
function getEnv(envName) { | ||
let envValue = process.env[envName]; | ||
if (!envValue) { | ||
throw new Error(`[ERROR] ${errorMessage}`); | ||
if (envValue) { | ||
envValue = envValue.trim().toLowerCase(); | ||
logger_1.log(`${envName} from env is: ${envValue}`); | ||
} | ||
envValue = envValue.trim().toLowerCase(); | ||
logger_1.log(`${envName} from env is: ${envValue}`); | ||
return envValue !== null && envValue !== void 0 ? envValue : ""; | ||
} | ||
exports.getEnv = getEnv; | ||
function getEnvWithError(envName, errorMessage) { | ||
const envValue = getEnv(envName); | ||
if (!envValue.length) { | ||
throwError(errorMessage); | ||
} | ||
return envValue; | ||
} | ||
exports.getEnv = getEnv; | ||
exports.getEnvWithError = getEnvWithError; | ||
function convertPluralNameToSingular(param) { | ||
return param.slice(0, param.length - 1); | ||
} | ||
exports.convertPluralNameToSingular = convertPluralNameToSingular; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@sap-devx/feature-toggle-node", | ||
"version": "1.0.12", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -33,6 +33,8 @@ "main": "lib/api.js", | ||
"await-to-js": "3.0.0", | ||
"parse-duration": "0.4.4", | ||
"unleash-client": "3.4.0" | ||
"node-cache": "5.1.2", | ||
"parse-duration": "0.4.4" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "11.0.0", | ||
"@commitlint/config-conventional": "12.0.1", | ||
"@istanbuljs/nyc-config-typescript": "1.0.1", | ||
@@ -45,7 +47,5 @@ "@types/chai": "4.2.15", | ||
"@typescript-eslint/parser": "2.34.0", | ||
"chai": "4.3.4", | ||
"coveralls": "3.1.0", | ||
"chai": "4.3.4", | ||
"cz-conventional-changelog": "3.3.0", | ||
"@commitlint/cli": "11.0.0", | ||
"@commitlint/config-conventional": "12.0.1", | ||
"eslint": "6.8.0", | ||
@@ -85,3 +85,4 @@ "eslint-config-prettier": "6.15.0", | ||
"src/example/example_simple.ts", | ||
"src/unleash_client_wrapper.ts" | ||
"src/request.ts", | ||
"src/utils.ts" | ||
], | ||
@@ -88,0 +89,0 @@ "reporter": [ |
@@ -13,5 +13,5 @@ [![CircleCI](https://circleci.com/gh/SAP/feature-toggle-node.svg?style=svg)](https://circleci.com/gh/SAP/feature-toggle-node) | ||
## Description | ||
This module is used to inquire if an SAP Business Application Studio feature toggle is enabled or disabled. | ||
This module used to inquire if an SAP Business Application Studio feature toggle enabled or disabled. | ||
This module should be used if your SAP Business Application Studio extension is written in Node.js or TypeScript and you want to control the extension features via feature toggle. | ||
This module should be used if your SAP Business Application Studio extension written in Node.js or TypeScript and you want to control the extension features via feature toggle. | ||
@@ -42,3 +42,2 @@ | ||
To run the feature-toggle-node **locally**, you need to provide the following environment variables: | ||
- `FT_SERVER_ENDPOINT` - Feature toggle server endpoint (mandatory) | ||
- `USER_NAME` - Name of the user logged into SAP Business Application Studio (mandatory) | ||
@@ -50,3 +49,4 @@ - `WORKSPACE_ID` - ID of the workspace (mandatory) | ||
- `LANDSCAPE_NAME` - (mandatory) | ||
- `FT_TOKEN` - Value of the feature toggle server API token (optional) | ||
- `FTM_HOST` - Feature toggle server host (optional) | ||
- `LANDSCAPE_INFRASTRUCTURE` - (optional) | ||
- `SHOW_LOG` - If true, displays console logs (optional) | ||
@@ -57,3 +57,3 @@ | ||
``` | ||
"FT_SERVER_ENDPOINT": "http://unleash.herokuapp.com", | ||
"FTM_HOST": "http://localhost:8080", | ||
"USER_NAME": "user@hotmail.com", | ||
@@ -60,0 +60,0 @@ "TENANT_ID" : "b5c05535-9495-4050-9d68-4356d0d34136", |
@@ -1,35 +0,24 @@ | ||
import { Context } from "unleash-client/lib/context"; | ||
import * as clientManager from "./unleash_client_manager"; | ||
import * as contextManager from "./context_manager"; | ||
import { log } from "./logger"; | ||
import { Unleash } from "unleash-client"; | ||
import { findToggleAndReturnState } from "./client"; | ||
export async function isFeatureEnabled(extensionName: string, featureToggleName: string): Promise<boolean> { | ||
log(`Checking if Extension Name: "${extensionName}", Feature Toggle Name: "${featureToggleName}" is enabled`); | ||
function validateFeatureToggleName(extensionName: string, toggleName: string): void { | ||
if (!extensionName || !toggleName) { | ||
const errStr = !extensionName ? "extension " : ""; | ||
throw new Error(`Feature toggle ${errStr}name can not be empty, null or undefined`); | ||
} | ||
} | ||
const ftName = `${extensionName}.${featureToggleName}`; | ||
export async function isFeatureEnabled(extensionName: string, toggleName: string): Promise<boolean> { | ||
log(`Checking if Extension Name: "${extensionName}", Feature Toggle Name: "${toggleName}" is enabled`); | ||
const ftName = `${extensionName}.${toggleName}`; | ||
try { | ||
if (!extensionName) { | ||
throw new Error("Feature toggle extension name can not be empty, null or undefined"); | ||
} | ||
if (!featureToggleName) { | ||
throw new Error("Feature toggle name can not be empty, null or undefined"); | ||
} | ||
//get unleash client | ||
const client: Unleash = await clientManager.getUnleashClient(extensionName); | ||
// get the context | ||
const context: Context = contextManager.getContext(extensionName); | ||
//check if the feature is enabled | ||
//fallback value is false (3rd parameter) | ||
return client.isEnabled(ftName, context, false); | ||
validateFeatureToggleName(extensionName, toggleName); | ||
return await findToggleAndReturnState(ftName); | ||
} catch (err) { | ||
const logErr = `[ERROR] Failed to determine if feature toggle ${ftName} is enabled. Returning feature DISABLED. Error message: ${err}`; | ||
log(logErr); | ||
return false; // error creating an Unleash client -> return feature is disabled | ||
return false; | ||
} | ||
} |
import { log } from "./logger"; | ||
export function getEnv(envName: string, errorMessage: string): string { | ||
//get feature server endpoint from env variable | ||
function throwError(errorMessage: string): void { | ||
throw new Error(`[ERROR] ${errorMessage}`); | ||
} | ||
export function getEnv(envName: string): string { | ||
let envValue = process.env[envName]; | ||
if (!envValue) { | ||
throw new Error(`[ERROR] ${errorMessage}`); | ||
if (envValue) { | ||
envValue = envValue.trim().toLowerCase(); | ||
log(`${envName} from env is: ${envValue}`); | ||
} | ||
envValue = envValue.trim().toLowerCase(); | ||
log(`${envName} from env is: ${envValue}`); | ||
return envValue ?? ""; | ||
} | ||
export function getEnvWithError(envName: string, errorMessage: string): string { | ||
const envValue = getEnv(envName); | ||
if (!envValue.length) { | ||
throwError(errorMessage); | ||
} | ||
return envValue; | ||
} | ||
export function convertPluralNameToSingular(param: string): string { | ||
return param.slice(0, param.length - 1); | ||
} |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
50719
44
644
2
+ Addednode-cache@5.1.2
+ Addedclone@2.1.2(transitive)
+ Addednode-cache@5.1.2(transitive)
- Removedunleash-client@3.4.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedip@1.1.9(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedmurmurhash3js@3.0.1(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removedunleash-client@3.4.0(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)