New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sap-devx/feature-toggle-node

Package Overview
Dependencies
Maintainers
12
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap-devx/feature-toggle-node - npm Package Compare versions

Comparing version 1.0.12 to 2.0.0

lib/cache.d.ts

2

lib/api.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc