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

@spotify-confidence/client-http

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spotify-confidence/client-http - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

24

build/cjs/client/ConfidenceClient.d.ts
import { Configuration, ResolveContext } from './Configuration';
type ConfidenceSimpleTypes = {
boolSchema: {};
} | {
doubleSchema: {};
} | {
intSchema: {};
} | {
stringSchema: {};
};
type ConfidenceFlagSchema = {
schema: {
[key: string]: ConfidenceSimpleTypes | {
structSchema: ConfidenceFlagSchema;
};
};
};
export type ResolvedFlag<T = any> = {
flag: string;
variant: string;
value?: T;
flagSchema?: ConfidenceFlagSchema;
reason: Configuration.ResolveReason;
};
export type ConfidenceClientOptions = {

@@ -25,2 +48,3 @@ fetchImplementation: typeof fetch;

}
export {};
//# sourceMappingURL=ConfidenceClient.d.ts.map

58

build/cjs/client/ConfidenceClient.js

@@ -11,5 +11,15 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfidenceClient = void 0;
const ConfidenceFlag_1 = require("./ConfidenceFlag");
class ConfidenceClient {

@@ -36,4 +46,10 @@ constructor(options) {

return {
flags: responseBody.resolvedFlags.reduce((acc, flag) => {
return Object.assign(Object.assign({}, acc), { [flag.flag]: new ConfidenceFlag_1.ConfidenceFlag(flag) });
flags: responseBody.resolvedFlags
.filter(({ flag }) => flag.startsWith('flags/'))
.map((_a) => {
var { flag } = _a, rest = __rest(_a, ["flag"]);
return (Object.assign({ flag: flag.slice('flags/'.length) }, rest));
})
.reduce((acc, flag) => {
return Object.assign(Object.assign({}, acc), { [flag.flag]: resolvedFlagToFlag(flag) });
}, {}),

@@ -61,2 +77,38 @@ resolveToken: responseBody.resolveToken,

exports.ConfidenceClient = ConfidenceClient;
function resolvedFlagToFlag(flag) {
return {
name: flag.flag.replace(/$flag\//, ''),
reason: flag.reason,
variant: flag.variant,
value: flag.value,
schema: parseSchema(flag.flagSchema),
};
}
function parseBaseType(obj) {
if ('boolSchema' in obj) {
return 'boolean';
}
if ('doubleSchema' in obj) {
return 'number';
}
if ('intSchema' in obj) {
return 'number';
}
if ('stringSchema' in obj) {
return 'string';
}
throw new Error(`Confidence: cannot parse schema. unknown schema: ${JSON.stringify(obj)}`);
}
function parseSchema(schema) {
if (!schema) {
return {};
}
return Object.keys(schema.schema).reduce((acc, key) => {
const obj = schema.schema[key];
if ('structSchema' in obj) {
return Object.assign(Object.assign({}, acc), { [key]: parseSchema(obj.structSchema) });
}
return Object.assign(Object.assign({}, acc), { [key]: parseBaseType(obj) });
}, {});
}
//# sourceMappingURL=ConfidenceClient.js.map

23

build/cjs/client/Configuration.d.ts

@@ -12,12 +12,21 @@ export type ResolveContext = {

}
type FlagSchema = 'number' | 'boolean' | 'string' | {
[step: string]: FlagSchema;
};
interface FlagValue<T = unknown> {
readonly value: T;
match<S>(obj: S): this is FlagValue<S>;
value: T;
schema: FlagSchema;
}
interface Flag {
readonly flagName: string;
readonly variant: string;
readonly reason: ResolveReason;
getValue(...path: string[]): FlagValue | null;
interface Flag<T = unknown> extends FlagValue<T> {
name: string;
reason: ResolveReason;
variant: string;
value: T;
schema: FlagSchema;
}
namespace FlagValue {
function matches<T>({ schema }: FlagValue<T>, value: any): value is T;
type Traversed<T, S extends string> = S extends `${infer STEP}.${infer REST}` ? STEP extends keyof T ? Traversed<T[STEP], REST> : unknown : S extends keyof T ? T[S] : never;
function traverse<T, S extends string>(flag: FlagValue<T>, path: S): FlagValue<Traversed<T, S>>;
}
}

@@ -24,0 +33,0 @@ export interface Configuration {

@@ -14,3 +14,35 @@ "use strict";

})(ResolveReason = Configuration.ResolveReason || (Configuration.ResolveReason = {}));
let FlagValue;
(function (FlagValue) {
function matches({ schema }, value) {
return valueMatchesSchema(value, schema);
}
FlagValue.matches = matches;
function traverse(flag, path) {
let value = flag.value;
let schema = flag.schema;
for (const part of path.split('.')) {
if (typeof schema !== 'object') {
throw new Error(`Parse Error. Cannot find path: ${path}. In flag: ${JSON.stringify(flag)}`);
}
value = value[part];
schema = schema[part];
if (schema === undefined) {
throw new Error(`Parse Error. Cannot find path: ${path}. In flag: ${JSON.stringify(flag)}`);
}
}
return { value, schema };
}
FlagValue.traverse = traverse;
})(FlagValue = Configuration.FlagValue || (Configuration.FlagValue = {}));
})(Configuration || (exports.Configuration = Configuration = {}));
function valueMatchesSchema(value, schema) {
if (value === null || schema === null) {
return false;
}
if (typeof schema !== 'object') {
return typeof value === schema;
}
return Object.keys(value).every(key => valueMatchesSchema(value[key], schema[key]));
}
//# sourceMappingURL=Configuration.js.map
export * from './Configuration';
export * from './ConfidenceClient';
export * from './ConfidenceFlag';
//# sourceMappingURL=index.d.ts.map

@@ -19,3 +19,2 @@ "use strict";

__exportStar(require("./ConfidenceClient"), exports);
__exportStar(require("./ConfidenceFlag"), exports);
//# sourceMappingURL=index.js.map
import { Configuration, ResolveContext } from './Configuration';
type ConfidenceSimpleTypes = {
boolSchema: {};
} | {
doubleSchema: {};
} | {
intSchema: {};
} | {
stringSchema: {};
};
type ConfidenceFlagSchema = {
schema: {
[key: string]: ConfidenceSimpleTypes | {
structSchema: ConfidenceFlagSchema;
};
};
};
export type ResolvedFlag<T = any> = {
flag: string;
variant: string;
value?: T;
flagSchema?: ConfidenceFlagSchema;
reason: Configuration.ResolveReason;
};
export type ConfidenceClientOptions = {

@@ -25,2 +48,3 @@ fetchImplementation: typeof fetch;

}
export {};
//# sourceMappingURL=ConfidenceClient.d.ts.map

@@ -10,3 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { ConfidenceFlag } from './ConfidenceFlag';
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
export class ConfidenceClient {

@@ -33,4 +43,10 @@ constructor(options) {

return {
flags: responseBody.resolvedFlags.reduce((acc, flag) => {
return Object.assign(Object.assign({}, acc), { [flag.flag]: new ConfidenceFlag(flag) });
flags: responseBody.resolvedFlags
.filter(({ flag }) => flag.startsWith('flags/'))
.map((_a) => {
var { flag } = _a, rest = __rest(_a, ["flag"]);
return (Object.assign({ flag: flag.slice('flags/'.length) }, rest));
})
.reduce((acc, flag) => {
return Object.assign(Object.assign({}, acc), { [flag.flag]: resolvedFlagToFlag(flag) });
}, {}),

@@ -57,2 +73,38 @@ resolveToken: responseBody.resolveToken,

}
function resolvedFlagToFlag(flag) {
return {
name: flag.flag.replace(/$flag\//, ''),
reason: flag.reason,
variant: flag.variant,
value: flag.value,
schema: parseSchema(flag.flagSchema),
};
}
function parseBaseType(obj) {
if ('boolSchema' in obj) {
return 'boolean';
}
if ('doubleSchema' in obj) {
return 'number';
}
if ('intSchema' in obj) {
return 'number';
}
if ('stringSchema' in obj) {
return 'string';
}
throw new Error(`Confidence: cannot parse schema. unknown schema: ${JSON.stringify(obj)}`);
}
function parseSchema(schema) {
if (!schema) {
return {};
}
return Object.keys(schema.schema).reduce((acc, key) => {
const obj = schema.schema[key];
if ('structSchema' in obj) {
return Object.assign(Object.assign({}, acc), { [key]: parseSchema(obj.structSchema) });
}
return Object.assign(Object.assign({}, acc), { [key]: parseBaseType(obj) });
}, {});
}
//# sourceMappingURL=ConfidenceClient.js.map

@@ -12,12 +12,21 @@ export type ResolveContext = {

}
type FlagSchema = 'number' | 'boolean' | 'string' | {
[step: string]: FlagSchema;
};
interface FlagValue<T = unknown> {
readonly value: T;
match<S>(obj: S): this is FlagValue<S>;
value: T;
schema: FlagSchema;
}
interface Flag {
readonly flagName: string;
readonly variant: string;
readonly reason: ResolveReason;
getValue(...path: string[]): FlagValue | null;
interface Flag<T = unknown> extends FlagValue<T> {
name: string;
reason: ResolveReason;
variant: string;
value: T;
schema: FlagSchema;
}
namespace FlagValue {
function matches<T>({ schema }: FlagValue<T>, value: any): value is T;
type Traversed<T, S extends string> = S extends `${infer STEP}.${infer REST}` ? STEP extends keyof T ? Traversed<T[STEP], REST> : unknown : S extends keyof T ? T[S] : never;
function traverse<T, S extends string>(flag: FlagValue<T>, path: S): FlagValue<Traversed<T, S>>;
}
}

@@ -24,0 +33,0 @@ export interface Configuration {

@@ -11,3 +11,35 @@ export var Configuration;

})(ResolveReason = Configuration.ResolveReason || (Configuration.ResolveReason = {}));
let FlagValue;
(function (FlagValue) {
function matches({ schema }, value) {
return valueMatchesSchema(value, schema);
}
FlagValue.matches = matches;
function traverse(flag, path) {
let value = flag.value;
let schema = flag.schema;
for (const part of path.split('.')) {
if (typeof schema !== 'object') {
throw new Error(`Parse Error. Cannot find path: ${path}. In flag: ${JSON.stringify(flag)}`);
}
value = value[part];
schema = schema[part];
if (schema === undefined) {
throw new Error(`Parse Error. Cannot find path: ${path}. In flag: ${JSON.stringify(flag)}`);
}
}
return { value, schema };
}
FlagValue.traverse = traverse;
})(FlagValue = Configuration.FlagValue || (Configuration.FlagValue = {}));
})(Configuration || (Configuration = {}));
function valueMatchesSchema(value, schema) {
if (value === null || schema === null) {
return false;
}
if (typeof schema !== 'object') {
return typeof value === schema;
}
return Object.keys(value).every(key => valueMatchesSchema(value[key], schema[key]));
}
//# sourceMappingURL=Configuration.js.map
export * from './Configuration';
export * from './ConfidenceClient';
export * from './ConfidenceFlag';
//# sourceMappingURL=index.d.ts.map
export * from './Configuration';
export * from './ConfidenceClient';
export * from './ConfidenceFlag';
//# sourceMappingURL=index.js.map
import { Configuration, ResolveContext } from './Configuration';
type ConfidenceSimpleTypes = {
boolSchema: {};
} | {
doubleSchema: {};
} | {
intSchema: {};
} | {
stringSchema: {};
};
type ConfidenceFlagSchema = {
schema: {
[key: string]: ConfidenceSimpleTypes | {
structSchema: ConfidenceFlagSchema;
};
};
};
export type ResolvedFlag<T = any> = {
flag: string;
variant: string;
value?: T;
flagSchema?: ConfidenceFlagSchema;
reason: Configuration.ResolveReason;
};
export type ConfidenceClientOptions = {

@@ -25,2 +48,3 @@ fetchImplementation: typeof fetch;

}
export {};
//# sourceMappingURL=ConfidenceClient.d.ts.map

@@ -10,3 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { ConfidenceFlag } from './ConfidenceFlag';
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
export class ConfidenceClient {

@@ -33,4 +43,10 @@ constructor(options) {

return {
flags: responseBody.resolvedFlags.reduce((acc, flag) => {
return Object.assign(Object.assign({}, acc), { [flag.flag]: new ConfidenceFlag(flag) });
flags: responseBody.resolvedFlags
.filter(({ flag }) => flag.startsWith('flags/'))
.map((_a) => {
var { flag } = _a, rest = __rest(_a, ["flag"]);
return (Object.assign({ flag: flag.slice('flags/'.length) }, rest));
})
.reduce((acc, flag) => {
return Object.assign(Object.assign({}, acc), { [flag.flag]: resolvedFlagToFlag(flag) });
}, {}),

@@ -57,2 +73,38 @@ resolveToken: responseBody.resolveToken,

}
function resolvedFlagToFlag(flag) {
return {
name: flag.flag.replace(/$flag\//, ''),
reason: flag.reason,
variant: flag.variant,
value: flag.value,
schema: parseSchema(flag.flagSchema),
};
}
function parseBaseType(obj) {
if ('boolSchema' in obj) {
return 'boolean';
}
if ('doubleSchema' in obj) {
return 'number';
}
if ('intSchema' in obj) {
return 'number';
}
if ('stringSchema' in obj) {
return 'string';
}
throw new Error(`Confidence: cannot parse schema. unknown schema: ${JSON.stringify(obj)}`);
}
function parseSchema(schema) {
if (!schema) {
return {};
}
return Object.keys(schema.schema).reduce((acc, key) => {
const obj = schema.schema[key];
if ('structSchema' in obj) {
return Object.assign(Object.assign({}, acc), { [key]: parseSchema(obj.structSchema) });
}
return Object.assign(Object.assign({}, acc), { [key]: parseBaseType(obj) });
}, {});
}
//# sourceMappingURL=ConfidenceClient.js.map

@@ -12,12 +12,21 @@ export type ResolveContext = {

}
type FlagSchema = 'number' | 'boolean' | 'string' | {
[step: string]: FlagSchema;
};
interface FlagValue<T = unknown> {
readonly value: T;
match<S>(obj: S): this is FlagValue<S>;
value: T;
schema: FlagSchema;
}
interface Flag {
readonly flagName: string;
readonly variant: string;
readonly reason: ResolveReason;
getValue(...path: string[]): FlagValue | null;
interface Flag<T = unknown> extends FlagValue<T> {
name: string;
reason: ResolveReason;
variant: string;
value: T;
schema: FlagSchema;
}
namespace FlagValue {
function matches<T>({ schema }: FlagValue<T>, value: any): value is T;
type Traversed<T, S extends string> = S extends `${infer STEP}.${infer REST}` ? STEP extends keyof T ? Traversed<T[STEP], REST> : unknown : S extends keyof T ? T[S] : never;
function traverse<T, S extends string>(flag: FlagValue<T>, path: S): FlagValue<Traversed<T, S>>;
}
}

@@ -24,0 +33,0 @@ export interface Configuration {

@@ -11,3 +11,35 @@ export var Configuration;

})(ResolveReason = Configuration.ResolveReason || (Configuration.ResolveReason = {}));
let FlagValue;
(function (FlagValue) {
function matches({ schema }, value) {
return valueMatchesSchema(value, schema);
}
FlagValue.matches = matches;
function traverse(flag, path) {
let value = flag.value;
let schema = flag.schema;
for (const part of path.split('.')) {
if (typeof schema !== 'object') {
throw new Error(`Parse Error. Cannot find path: ${path}. In flag: ${JSON.stringify(flag)}`);
}
value = value[part];
schema = schema[part];
if (schema === undefined) {
throw new Error(`Parse Error. Cannot find path: ${path}. In flag: ${JSON.stringify(flag)}`);
}
}
return { value, schema };
}
FlagValue.traverse = traverse;
})(FlagValue = Configuration.FlagValue || (Configuration.FlagValue = {}));
})(Configuration || (Configuration = {}));
function valueMatchesSchema(value, schema) {
if (value === null || schema === null) {
return false;
}
if (typeof schema !== 'object') {
return typeof value === schema;
}
return Object.keys(value).every(key => valueMatchesSchema(value[key], schema[key]));
}
//# sourceMappingURL=Configuration.js.map
export * from './Configuration';
export * from './ConfidenceClient';
export * from './ConfidenceFlag';
//# sourceMappingURL=index.d.ts.map
export * from './Configuration';
export * from './ConfidenceClient';
export * from './ConfidenceFlag';
//# sourceMappingURL=index.js.map

@@ -1,3 +0,12 @@

# Change Log
# Changelog
## [0.0.3](https://github.com/spotify/confidence-openfeature-provider-js/compare/client-http-v0.0.2...client-http-v0.0.3) (2023-10-26)
### 🔄 Refactoring
* **client-http,web,server:** use a serializable and more simple configuration object ([fc2093f](https://github.com/spotify/confidence-openfeature-provider-js/commit/fc2093ff51d9525ca866854384751daa9148c6f6))
## Change Log (Old)
All notable changes to this project will be documented in this file.

@@ -4,0 +13,0 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

{
"name": "@spotify-confidence/client-http",
"license": "Apache-2.0",
"version": "0.0.2",
"version": "0.0.3",
"module": "build/esm/index.js",

@@ -17,3 +17,3 @@ "main": "build/cjs/index.js",

},
"gitHead": "c377e3d6611011820bd7799860f96aa1f5fcbe0b"
"gitHead": "6066377a115fb694a7af12ee1a7dc60f73b2fee3"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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