Socket
Socket
Sign inDemoInstall

sap-cf-features

Package Overview
Dependencies
72
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

11

dist/FeatureFlagsApi.d.ts
import { IReturnFlag } from './types';
/**
* @returns Table with the names of all enabled feature flags.
*/
export declare function getAllFlagNames(): Promise<string[]>;
export declare function batchEvaluate(names: string[], tenant: string): Promise<IReturnFlag>;
/**
*
* @param names String table with all names of the feature flags to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns Key value pair of all requested feature flags.
*/
export declare function batchEvaluate(names: string[], identifier?: string): Promise<IReturnFlag>;

58

dist/FeatureFlagsApi.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -11,9 +30,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -23,4 +35,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.batchEvaluate = exports.getAllFlagNames = void 0;
const xsenv = __importStar(require("@sap/xsenv"));
const axios_1 = __importDefault(require("axios"));
/**
* @returns Table with the names of all enabled feature flags.
*/
function getAllFlagNames() {

@@ -30,5 +46,6 @@ return __awaiter(this, void 0, void 0, function* () {

return allFlags.flags
// remove the filter here, because there is something wrong with boolean features
// boolean features that are active are always true. they should only be true when the feature is released no?
// .filter( (flag) => flag.enabled )
// hmmm, there is something wrong with boolean features on SAP side
// boolean features that are active are always default true if they don't have a strategy.
// they should have a default value just as the string values
.filter((flag) => flag.enabled)
.map((flag) => flag.id);

@@ -38,2 +55,5 @@ });

exports.getAllFlagNames = getAllFlagNames;
/**
* @returns Definition of all flags (enabled and disabled) in the system
*/
function exportFlags() {

@@ -54,3 +74,9 @@ return __awaiter(this, void 0, void 0, function* () {

}
function batchEvaluate(names, tenant) {
/**
*
* @param names String table with all names of the feature flags to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns Key value pair of all requested feature flags.
*/
function batchEvaluate(names, identifier) {
return __awaiter(this, void 0, void 0, function* () {

@@ -61,3 +87,3 @@ if (names.length === 0) {

const service = getService();
const url = `/api/v2/evaluateset?${names.map(getFlags).join('&')}&identifier=${tenant || ""}`;
const url = `/api/v2/evaluateset?${names.map((name) => `flag=${name}`).join('&')}` + identifier ? `&identifier=${identifier || ""}` : ``;
const response = yield axios_1.default.get(url, {

@@ -85,6 +111,6 @@ url,

exports.batchEvaluate = batchEvaluate;
function getFlags(name) {
return `flag=${name}`;
}
// get the feature service configuration
/**
* get the feature service configuration
* @returns connection parameters for the feature flag API
*/
function getService() {

@@ -91,0 +117,0 @@ const { featureFlags } = xsenv.getServices({

export { IFeatureFlagExport, IFeatureFlagMap, IReturnFlag, IFeatureService } from './types';
export declare function getFeatureFlags(names: string | string[] | undefined, tenant: string): Promise<import("./types").IReturnFlag>;
export declare function getFeatureFlag(name: string, tenant: string): Promise<string | boolean>;
export declare function getFeatureFlagBoolean(name: string, tenant: string): Promise<boolean | undefined>;
export declare function getFeatureFlagString(name: string, tenant: string): Promise<string | undefined>;
/**
* get a list of feature flags for a certain identifier (e.g. tenant)
* @param names String table with all names of the feature flags to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns Key value pair of all requested feature flags
*/
export declare function getFeatureFlags(names?: string | string[], identifier?: string): Promise<import("./types").IReturnFlag>;
/**
* get a feature flag value for a certain identifier (e.g. tenant)
* @param names String table with all names of the feature flags to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns The value of the requested feature flags
*/
export declare function getFeatureFlag(name: string, identifier?: string): Promise<string | boolean>;
/**
* get a feature flag value for a certain identifier (e.g. tenant)
* @param name Name of the feature flag to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns The boolean value of the requested feature flag
*/
export declare function getFeatureFlagBoolean(name: string, identifier?: string): Promise<boolean | undefined>;
/**
* get a feature flag value for a certain identifier (e.g. tenant)
* @param names Name of the feature flag to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns The string of the requested feature flag
*/
export declare function getFeatureFlagString(name: string, identifier?: string): Promise<string | undefined>;
/**
* Easy way to enable a ui5 app to read tenant aware feature flags.
* @returns An express router.
* default route will list all features
* '/:feature-name' will evaluate one feature
*/
export declare function featureFlagRouter(): import("express-serve-static-core").Router;

@@ -12,14 +12,30 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.featureFlagRouter = exports.getFeatureFlagString = exports.getFeatureFlagBoolean = exports.getFeatureFlag = exports.getFeatureFlags = void 0;
const express_1 = require("express");
const FeatureFlagsApi_1 = require("./FeatureFlagsApi");
function getFeatureFlags(names, tenant) {
/**
* get a list of feature flags for a certain identifier (e.g. tenant)
* @param names String table with all names of the feature flags to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns Key value pair of all requested feature flags
*/
function getFeatureFlags(names, identifier) {
return __awaiter(this, void 0, void 0, function* () {
const flagNames = names ? typeof names === 'string' ? [names] : names : yield FeatureFlagsApi_1.getAllFlagNames();
return FeatureFlagsApi_1.batchEvaluate(flagNames, tenant);
return FeatureFlagsApi_1.batchEvaluate(flagNames, identifier);
});
}
exports.getFeatureFlags = getFeatureFlags;
function getFeatureFlag(name, tenant) {
/**
* get a feature flag value for a certain identifier (e.g. tenant)
* @param names String table with all names of the feature flags to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns The value of the requested feature flags
*/
function getFeatureFlag(name, identifier) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield FeatureFlagsApi_1.batchEvaluate([name], tenant);
if (!name) {
throw 'Please specify a name for the feature you are looking for.';
}
const result = yield FeatureFlagsApi_1.batchEvaluate([name], identifier);
return result[name];

@@ -29,5 +45,11 @@ });

exports.getFeatureFlag = getFeatureFlag;
function getFeatureFlagBoolean(name, tenant) {
/**
* get a feature flag value for a certain identifier (e.g. tenant)
* @param name Name of the feature flag to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns The boolean value of the requested feature flag
*/
function getFeatureFlagBoolean(name, identifier) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield getFeatureFlag(name, tenant);
const result = yield getFeatureFlag(name, identifier);
if (typeof result === "boolean") {

@@ -41,5 +63,11 @@ return result;

exports.getFeatureFlagBoolean = getFeatureFlagBoolean;
function getFeatureFlagString(name, tenant) {
/**
* get a feature flag value for a certain identifier (e.g. tenant)
* @param names Name of the feature flag to evaluate
* @param identifier To make it tenant aware, you can give the name of the tenant here. You can enable features for certain tenants with the direct delivery strategy.
* @returns The string of the requested feature flag
*/
function getFeatureFlagString(name, identifier) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield getFeatureFlag(name, tenant);
const result = yield getFeatureFlag(name, identifier);
if (typeof result === "string") {

@@ -56,2 +84,8 @@ return result;

exports.getFeatureFlagString = getFeatureFlagString;
/**
* Easy way to enable a ui5 app to read tenant aware feature flags.
* @returns An express router.
* default route will list all features
* '/:feature-name' will evaluate one feature
*/
function featureFlagRouter() {

@@ -66,4 +100,4 @@ const router = express_1.Router();

const result = yield getFeatureFlags(flagName, getDomain(req));
res.status(200).json(result);
next();
res.status(200).json(result).end();
//next();
}));

@@ -74,4 +108,4 @@ router.get('/', (req, res, next) => __awaiter(this, void 0, void 0, function* () {

const result = yield getFeatureFlags(flagNames, getDomain(req));
res.status(200).json(result);
next();
res.status(200).json(result).end();
//next();
}));

@@ -78,0 +112,0 @@ return router;

{
"name": "sap-cf-features",
"version": "0.0.3",
"version": "0.0.4",
"description": "Read SAP CF feature flags in nodejs",

@@ -15,4 +15,5 @@ "main": "dist/index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"
"doc": "typedoc --tsconfig ./tsconfig.json",
"build": "tsc && npm run doc",
"deploy": "npm run build && npm publish"
},

@@ -35,4 +36,5 @@ "keywords": [

"@types/sap__xsenv": "^2.0.1",
"typedoc": "^0.17.8",
"typescript": "^3.7.2"
}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc