Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pbs/vanna

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pbs/vanna - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

35

dist/vanna.js

@@ -14,2 +14,6 @@ "use strict";

var _lodash = require("lodash.defaults");
var _lodash2 = _interopRequireDefault(_lodash);
var _invariant = require("invariant");

@@ -19,2 +23,6 @@

var _lodash3 = require("lodash.isboolean");
var _lodash4 = _interopRequireDefault(_lodash3);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -28,3 +36,3 @@

(0, _invariant2.default)(uri, "uri is a required setup parameter");
return options;
return (0, _lodash2.default)(options, { fallbacks: {} });
}

@@ -78,4 +86,3 @@

exports.getManifest = getManifest = _overrides.getManifest || getManifest;
getManifest(uri).then(function (manifest) {
(_overrides.getManifest || getManifest)(uri).then(function (manifest) {
_this.manifest = manifest;

@@ -92,11 +99,18 @@ }).then(cb).catch(function () {

key: "variation",
value: function variation(featureName, _ref2) {
var fallback = _ref2.fallback;
value: function variation(featureName) {
var variationOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options2 = this.options,
fallbacks = _options2.fallbacks,
userSegment = _options2.userSegment;
var globalFallback = fallbacks[featureName];
var variationFallback = variationOptions.fallback;
(0, _invariant2.default)((0, _lodash4.default)(globalFallback) || (0, _lodash4.default)(variationFallback), "feature fallback must be set globally or per variation call");
if (!this.manifest) {
return fallback;
if ((0, _lodash4.default)(globalFallback)) {
return globalFallback;
}
return variationFallback;
}
var userSegment = this.options.userSegment;
var feature = this.manifest.features[featureName];

@@ -107,4 +121,5 @@ (0, _invariant2.default)(feature, featureName + " is not a valid feature");

var getFeatureVariation = _overrides.getFeatureVariation || getFeatureVariation;
return getFeatureVariation(feature, { userSegment: userSegment });
return (_overrides.getFeatureVariation || getFeatureVariation)(feature, {
userSegment: userSegment
});
}

@@ -111,0 +126,0 @@ }]);

@@ -8,2 +8,5 @@ import { VannaClient } from "../src/vanna";

userSegment: "alpha-users",
fallbacks: {
"some-feature": false
},
_overrides: {

@@ -15,5 +18,3 @@ getManifest: () => Promise.resolve(exampleManifest)

client.on("ready", () => {
const isSomeFeatureEnabled = client.variation("some-feature", {
fallback: false
});
const isSomeFeatureEnabled = client.variation("some-feature");
if (isSomeFeatureEnabled) {

@@ -20,0 +21,0 @@ console.log("Some feature is enabled :)");

{
"name": "@pbs/vanna",
"version": "0.4.0",
"version": "0.5.0",
"description": "Feature flagging service client",

@@ -24,3 +24,5 @@ "main": "dist/vanna.js",

"dependencies": {
"invariant": "^2.2.4"
"invariant": "^2.2.4",
"lodash.defaults": "^4.2.0",
"lodash.isboolean": "^3.0.3"
},

@@ -27,0 +29,0 @@ "devDependencies": {

@@ -33,3 +33,6 @@ # Vanna Javascript (Browser) Client

uri: "https://vanna.example.com/project",
userSegment: "beta-tester"
userSegment: "beta-tester",
fallbacks: {
"your-feature-slug": false
}
});

@@ -36,0 +39,0 @@

@@ -0,2 +1,4 @@

import defaults from "lodash.defaults";
import invariant from "invariant";
import isBoolean from "lodash.isboolean";

@@ -6,3 +8,3 @@ export function validateOptions(options) {

invariant(uri, "uri is a required setup parameter");
return options;
return defaults(options, { fallbacks: {} });
}

@@ -40,4 +42,3 @@

const { uri, _overrides } = this.options;
getManifest = _overrides.getManifest || getManifest;
getManifest(uri)
(_overrides.getManifest || getManifest)(uri)
.then(manifest => {

@@ -56,8 +57,17 @@ this.manifest = manifest;

variation(featureName, { fallback }) {
variation(featureName, variationOptions = {}) {
const { fallbacks, userSegment } = this.options;
const globalFallback = fallbacks[featureName];
const variationFallback = variationOptions.fallback;
invariant(
isBoolean(globalFallback) || isBoolean(variationFallback),
"feature fallback must be set globally or per variation call"
);
if (!this.manifest) {
return fallback;
if (isBoolean(globalFallback)) {
return globalFallback;
}
return variationFallback;
}
const { userSegment } = this.options;
const feature = this.manifest.features[featureName];

@@ -67,5 +77,5 @@ invariant(feature, `${featureName} is not a valid feature`);

const { _overrides } = this.options;
const getFeatureVariation =
_overrides.getFeatureVariation || getFeatureVariation;
return getFeatureVariation(feature, { userSegment });
return (_overrides.getFeatureVariation || getFeatureVariation)(feature, {
userSegment
});
}

@@ -72,0 +82,0 @@ }

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