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

@spotify-confidence/openfeature-server-provider

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spotify-confidence/openfeature-server-provider - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0-rc.0

8

build/cjs/ConfidenceServerProvider.d.ts

@@ -1,8 +0,8 @@

import { EvaluationContext, JsonValue, Logger, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/js-sdk';
import { ConfidenceClient } from '@spotify-confidence/client-http';
import { EvaluationContext, JsonValue, Logger, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/server-sdk';
import { Confidence } from '@spotify-confidence/sdk';
export declare class ConfidenceServerProvider implements Provider {
readonly metadata: ProviderMetadata;
status: ProviderStatus;
private readonly client;
constructor(client: ConfidenceClient);
private readonly confidence;
constructor(client: Confidence);
private convertContext;

@@ -9,0 +9,0 @@ private getFlag;

@@ -24,4 +24,4 @@ "use strict";

exports.ConfidenceServerProvider = void 0;
const js_sdk_1 = require("@openfeature/js-sdk");
const client_http_1 = require("@spotify-confidence/client-http");
const server_sdk_1 = require("@openfeature/server-sdk");
const sdk_1 = require("@spotify-confidence/sdk");
class ConfidenceServerProvider {

@@ -32,11 +32,10 @@ constructor(client) {

};
this.status = js_sdk_1.ProviderStatus.READY;
this.client = client;
this.status = server_sdk_1.ProviderStatus.READY;
this.confidence = client;
}
convertContext(context) {
const { targetingKey } = context, rest = __rest(context, ["targetingKey"]);
if (targetingKey) {
return Object.assign(Object.assign({}, rest), { targeting_key: targetingKey });
}
return rest;
convertContext(_a) {
var { targetingKey } = _a, rest = __rest(_a, ["targetingKey"]);
return {
openFeature: Object.assign({ targeting_key: targetingKey }, convertValue(rest)),
};
}

@@ -46,3 +45,3 @@ getFlag(configuration, flagKey, defaultValue, _logger) {

return {
errorCode: js_sdk_1.ErrorCode.PROVIDER_NOT_READY,
errorCode: server_sdk_1.ErrorCode.PROVIDER_NOT_READY,
value: defaultValue,

@@ -57,3 +56,3 @@ reason: 'ERROR',

return {
errorCode: js_sdk_1.ErrorCode.FLAG_NOT_FOUND,
errorCode: server_sdk_1.ErrorCode.FLAG_NOT_FOUND,
value: defaultValue,

@@ -63,3 +62,3 @@ reason: 'ERROR',

}
if (client_http_1.Configuration.ResolveReason.NoSegmentMatch === flag.reason) {
if (sdk_1.FlagResolution.ResolveReason.NoSegmentMatch === flag.reason) {
return {

@@ -72,3 +71,3 @@ value: defaultValue,

try {
flagValue = client_http_1.Configuration.FlagValue.traverse(flag, pathParts.join('.'));
flagValue = sdk_1.FlagResolution.FlagValue.traverse(flag, pathParts.join('.'));
}

@@ -88,3 +87,3 @@ catch (e) {

}
if (!client_http_1.Configuration.FlagValue.matches(flagValue, defaultValue)) {
if (!sdk_1.FlagResolution.FlagValue.matches(flagValue, defaultValue)) {
return {

@@ -107,3 +106,3 @@ errorCode: 'TYPE_MISMATCH',

return {
errorCode: js_sdk_1.ErrorCode.GENERAL,
errorCode: server_sdk_1.ErrorCode.GENERAL,
value: defaultValue,

@@ -116,6 +115,6 @@ reason: 'ERROR',

return __awaiter(this, void 0, void 0, function* () {
const [flagName, ..._] = flagKey.split('.');
const configuration = yield this.client.resolve(this.convertContext(context || {}), {
flags: [`flags/${flagName}`],
});
const [flagName] = flagKey.split('.');
const configuration = yield this.confidence
.withContext(this.convertContext(context))
.resolve([`flags/${flagName}`]);
return this.getFlag(configuration, flagKey, defaultValue, logger);

@@ -140,7 +139,7 @@ });

switch (reason) {
case client_http_1.Configuration.ResolveReason.Archived:
case sdk_1.FlagResolution.ResolveReason.Archived:
return 'DISABLED';
case client_http_1.Configuration.ResolveReason.Unspecified:
case sdk_1.FlagResolution.ResolveReason.Unspecified:
return 'UNKNOWN';
case client_http_1.Configuration.ResolveReason.Match:
case sdk_1.FlagResolution.ResolveReason.Match:
return 'TARGETING_MATCH';

@@ -151,2 +150,20 @@ default:

}
function convertValue(value) {
if (value === null)
return undefined;
if (typeof value === 'object') {
if (Array.isArray(value)) {
return value.map(convertValue);
}
if (value instanceof Date) {
return value.toISOString();
}
const struct = {};
for (const key of Object.keys(value)) {
struct[key] = convertValue(value[key]);
}
return struct;
}
return value;
}
//# sourceMappingURL=ConfidenceServerProvider.js.map

@@ -1,6 +0,6 @@

import { Provider } from '@openfeature/js-sdk';
import { ConfidenceClientOptions } from '@spotify-confidence/client-http';
import { Provider } from '@openfeature/server-sdk';
import { Confidence } from '@spotify-confidence/sdk';
type ConfidenceProviderFactoryOptions = {
region?: ConfidenceClientOptions['region'];
fetchImplementation: typeof fetch;
region?: 'global' | 'eu' | 'us';
fetchImplementation?: typeof fetch;
clientSecret: string;

@@ -11,3 +11,4 @@ baseUrl?: string;

export declare function createConfidenceServerProvider(options: ConfidenceProviderFactoryOptions): Provider;
export declare function createConfidenceServerProvider(confidence: Confidence): Provider;
export {};
//# sourceMappingURL=factory.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createConfidenceServerProvider = void 0;
const client_http_1 = require("@spotify-confidence/client-http");
const ConfidenceServerProvider_1 = require("./ConfidenceServerProvider");
function createConfidenceServerProvider(options) {
const confidenceClient = new client_http_1.ConfidenceClient(Object.assign(Object.assign({}, options), { apply: true, sdk: {
id: 'SDK_ID_JS_SERVER_PROVIDER',
version: '0.1.5',
} }));
return new ConfidenceServerProvider_1.ConfidenceServerProvider(confidenceClient);
const sdk_1 = require("@spotify-confidence/sdk");
function createConfidenceServerProvider(confidenceOrOptions) {
if (confidenceOrOptions instanceof sdk_1.Confidence) {
return new ConfidenceServerProvider_1.ConfidenceServerProvider(confidenceOrOptions);
}
const confidence = sdk_1.Confidence.create(Object.assign(Object.assign({}, confidenceOrOptions), { environment: 'backend' }));
return new ConfidenceServerProvider_1.ConfidenceServerProvider(confidence);
}
exports.createConfidenceServerProvider = createConfidenceServerProvider;
//# sourceMappingURL=factory.js.map

@@ -1,8 +0,8 @@

import { EvaluationContext, JsonValue, Logger, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/js-sdk';
import { ConfidenceClient } from '@spotify-confidence/client-http';
import { EvaluationContext, JsonValue, Logger, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/server-sdk';
import { Confidence } from '@spotify-confidence/sdk';
export declare class ConfidenceServerProvider implements Provider {
readonly metadata: ProviderMetadata;
status: ProviderStatus;
private readonly client;
constructor(client: ConfidenceClient);
private readonly confidence;
constructor(client: Confidence);
private convertContext;

@@ -9,0 +9,0 @@ private getFlag;

@@ -21,4 +21,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { ErrorCode, ProviderStatus, } from '@openfeature/js-sdk';
import { Configuration } from '@spotify-confidence/client-http';
import { ErrorCode, ProviderStatus, } from '@openfeature/server-sdk';
import { FlagResolution } from '@spotify-confidence/sdk';
export class ConfidenceServerProvider {

@@ -30,10 +30,9 @@ constructor(client) {

this.status = ProviderStatus.READY;
this.client = client;
this.confidence = client;
}
convertContext(context) {
const { targetingKey } = context, rest = __rest(context, ["targetingKey"]);
if (targetingKey) {
return Object.assign(Object.assign({}, rest), { targeting_key: targetingKey });
}
return rest;
convertContext(_a) {
var { targetingKey } = _a, rest = __rest(_a, ["targetingKey"]);
return {
openFeature: Object.assign({ targeting_key: targetingKey }, convertValue(rest)),
};
}

@@ -58,3 +57,3 @@ getFlag(configuration, flagKey, defaultValue, _logger) {

}
if (Configuration.ResolveReason.NoSegmentMatch === flag.reason) {
if (FlagResolution.ResolveReason.NoSegmentMatch === flag.reason) {
return {

@@ -67,3 +66,3 @@ value: defaultValue,

try {
flagValue = Configuration.FlagValue.traverse(flag, pathParts.join('.'));
flagValue = FlagResolution.FlagValue.traverse(flag, pathParts.join('.'));
}

@@ -83,3 +82,3 @@ catch (e) {

}
if (!Configuration.FlagValue.matches(flagValue, defaultValue)) {
if (!FlagResolution.FlagValue.matches(flagValue, defaultValue)) {
return {

@@ -110,6 +109,6 @@ errorCode: 'TYPE_MISMATCH',

return __awaiter(this, void 0, void 0, function* () {
const [flagName, ..._] = flagKey.split('.');
const configuration = yield this.client.resolve(this.convertContext(context || {}), {
flags: [`flags/${flagName}`],
});
const [flagName] = flagKey.split('.');
const configuration = yield this.confidence
.withContext(this.convertContext(context))
.resolve([`flags/${flagName}`]);
return this.getFlag(configuration, flagKey, defaultValue, logger);

@@ -133,7 +132,7 @@ });

switch (reason) {
case Configuration.ResolveReason.Archived:
case FlagResolution.ResolveReason.Archived:
return 'DISABLED';
case Configuration.ResolveReason.Unspecified:
case FlagResolution.ResolveReason.Unspecified:
return 'UNKNOWN';
case Configuration.ResolveReason.Match:
case FlagResolution.ResolveReason.Match:
return 'TARGETING_MATCH';

@@ -144,2 +143,20 @@ default:

}
function convertValue(value) {
if (value === null)
return undefined;
if (typeof value === 'object') {
if (Array.isArray(value)) {
return value.map(convertValue);
}
if (value instanceof Date) {
return value.toISOString();
}
const struct = {};
for (const key of Object.keys(value)) {
struct[key] = convertValue(value[key]);
}
return struct;
}
return value;
}
//# sourceMappingURL=ConfidenceServerProvider.js.map

@@ -1,6 +0,6 @@

import { Provider } from '@openfeature/js-sdk';
import { ConfidenceClientOptions } from '@spotify-confidence/client-http';
import { Provider } from '@openfeature/server-sdk';
import { Confidence } from '@spotify-confidence/sdk';
type ConfidenceProviderFactoryOptions = {
region?: ConfidenceClientOptions['region'];
fetchImplementation: typeof fetch;
region?: 'global' | 'eu' | 'us';
fetchImplementation?: typeof fetch;
clientSecret: string;

@@ -11,3 +11,4 @@ baseUrl?: string;

export declare function createConfidenceServerProvider(options: ConfidenceProviderFactoryOptions): Provider;
export declare function createConfidenceServerProvider(confidence: Confidence): Provider;
export {};
//# sourceMappingURL=factory.d.ts.map

@@ -1,10 +0,10 @@

import { ConfidenceClient } from '@spotify-confidence/client-http';
import { ConfidenceServerProvider } from './ConfidenceServerProvider';
export function createConfidenceServerProvider(options) {
const confidenceClient = new ConfidenceClient(Object.assign(Object.assign({}, options), { apply: true, sdk: {
id: 'SDK_ID_JS_SERVER_PROVIDER',
version: '0.1.5',
} }));
return new ConfidenceServerProvider(confidenceClient);
import { Confidence } from '@spotify-confidence/sdk';
export function createConfidenceServerProvider(confidenceOrOptions) {
if (confidenceOrOptions instanceof Confidence) {
return new ConfidenceServerProvider(confidenceOrOptions);
}
const confidence = Confidence.create(Object.assign(Object.assign({}, confidenceOrOptions), { environment: 'backend' }));
return new ConfidenceServerProvider(confidence);
}
//# sourceMappingURL=factory.js.map

@@ -1,8 +0,8 @@

import { EvaluationContext, JsonValue, Logger, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/js-sdk';
import { ConfidenceClient } from '@spotify-confidence/client-http';
import { EvaluationContext, JsonValue, Logger, Provider, ProviderMetadata, ProviderStatus, ResolutionDetails } from '@openfeature/server-sdk';
import { Confidence } from '@spotify-confidence/sdk';
export declare class ConfidenceServerProvider implements Provider {
readonly metadata: ProviderMetadata;
status: ProviderStatus;
private readonly client;
constructor(client: ConfidenceClient);
private readonly confidence;
constructor(client: Confidence);
private convertContext;

@@ -9,0 +9,0 @@ private getFlag;

@@ -21,4 +21,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { ErrorCode, ProviderStatus, } from '@openfeature/js-sdk';
import { Configuration } from '@spotify-confidence/client-http';
import { ErrorCode, ProviderStatus, } from '@openfeature/server-sdk';
import { FlagResolution } from '@spotify-confidence/sdk';
export class ConfidenceServerProvider {

@@ -30,10 +30,9 @@ constructor(client) {

this.status = ProviderStatus.READY;
this.client = client;
this.confidence = client;
}
convertContext(context) {
const { targetingKey } = context, rest = __rest(context, ["targetingKey"]);
if (targetingKey) {
return Object.assign(Object.assign({}, rest), { targeting_key: targetingKey });
}
return rest;
convertContext(_a) {
var { targetingKey } = _a, rest = __rest(_a, ["targetingKey"]);
return {
openFeature: Object.assign({ targeting_key: targetingKey }, convertValue(rest)),
};
}

@@ -58,3 +57,3 @@ getFlag(configuration, flagKey, defaultValue, _logger) {

}
if (Configuration.ResolveReason.NoSegmentMatch === flag.reason) {
if (FlagResolution.ResolveReason.NoSegmentMatch === flag.reason) {
return {

@@ -67,3 +66,3 @@ value: defaultValue,

try {
flagValue = Configuration.FlagValue.traverse(flag, pathParts.join('.'));
flagValue = FlagResolution.FlagValue.traverse(flag, pathParts.join('.'));
}

@@ -83,3 +82,3 @@ catch (e) {

}
if (!Configuration.FlagValue.matches(flagValue, defaultValue)) {
if (!FlagResolution.FlagValue.matches(flagValue, defaultValue)) {
return {

@@ -110,6 +109,6 @@ errorCode: 'TYPE_MISMATCH',

return __awaiter(this, void 0, void 0, function* () {
const [flagName, ..._] = flagKey.split('.');
const configuration = yield this.client.resolve(this.convertContext(context || {}), {
flags: [`flags/${flagName}`],
});
const [flagName] = flagKey.split('.');
const configuration = yield this.confidence
.withContext(this.convertContext(context))
.resolve([`flags/${flagName}`]);
return this.getFlag(configuration, flagKey, defaultValue, logger);

@@ -133,7 +132,7 @@ });

switch (reason) {
case Configuration.ResolveReason.Archived:
case FlagResolution.ResolveReason.Archived:
return 'DISABLED';
case Configuration.ResolveReason.Unspecified:
case FlagResolution.ResolveReason.Unspecified:
return 'UNKNOWN';
case Configuration.ResolveReason.Match:
case FlagResolution.ResolveReason.Match:
return 'TARGETING_MATCH';

@@ -144,2 +143,20 @@ default:

}
function convertValue(value) {
if (value === null)
return undefined;
if (typeof value === 'object') {
if (Array.isArray(value)) {
return value.map(convertValue);
}
if (value instanceof Date) {
return value.toISOString();
}
const struct = {};
for (const key of Object.keys(value)) {
struct[key] = convertValue(value[key]);
}
return struct;
}
return value;
}
//# sourceMappingURL=ConfidenceServerProvider.js.map

@@ -1,6 +0,6 @@

import { Provider } from '@openfeature/js-sdk';
import { ConfidenceClientOptions } from '@spotify-confidence/client-http';
import { Provider } from '@openfeature/server-sdk';
import { Confidence } from '@spotify-confidence/sdk';
type ConfidenceProviderFactoryOptions = {
region?: ConfidenceClientOptions['region'];
fetchImplementation: typeof fetch;
region?: 'global' | 'eu' | 'us';
fetchImplementation?: typeof fetch;
clientSecret: string;

@@ -11,3 +11,4 @@ baseUrl?: string;

export declare function createConfidenceServerProvider(options: ConfidenceProviderFactoryOptions): Provider;
export declare function createConfidenceServerProvider(confidence: Confidence): Provider;
export {};
//# sourceMappingURL=factory.d.ts.map

@@ -1,10 +0,10 @@

import { ConfidenceClient } from '@spotify-confidence/client-http';
import { ConfidenceServerProvider } from './ConfidenceServerProvider';
export function createConfidenceServerProvider(options) {
const confidenceClient = new ConfidenceClient(Object.assign(Object.assign({}, options), { apply: true, sdk: {
id: 'SDK_ID_JS_SERVER_PROVIDER',
version: '0.1.5',
} }));
return new ConfidenceServerProvider(confidenceClient);
import { Confidence } from '@spotify-confidence/sdk';
export function createConfidenceServerProvider(confidenceOrOptions) {
if (confidenceOrOptions instanceof Confidence) {
return new ConfidenceServerProvider(confidenceOrOptions);
}
const confidence = Confidence.create(Object.assign(Object.assign({}, confidenceOrOptions), { environment: 'backend' }));
return new ConfidenceServerProvider(confidence);
}
//# sourceMappingURL=factory.js.map

@@ -9,2 +9,36 @@ # Changelog

## [0.2.0-rc.0](https://github.com/spotify/confidence-openfeature-provider-js/compare/openfeature-server-provider-v0.1.5...openfeature-server-provider-v0.2.0-rc.0) (2024-04-04)
### โš  BREAKING CHANGES
* Since our peer dependency to `@openfeature/js-sdk` changed into `@openfeature/server-sdk`, users need to install the new package which is concidered a breaking change.
### โœจ New Features
* make provider fetchImplementation optional ([cd242a6](https://github.com/spotify/confidence-openfeature-provider-js/commit/cd242a60804d5565f69d12ec0d35acf8d980f11e))
* send sdk info with apply events ([6b95d0e](https://github.com/spotify/confidence-openfeature-provider-js/commit/6b95d0ea90059cae6fd71882a13a65ee84eb0e2c))
### ๐Ÿงน Chore
* upgrade OpenFeature dependencies ([8f27a92](https://github.com/spotify/confidence-openfeature-provider-js/commit/8f27a924aa5eb7662fdf73be6564eb2e3580b2fc))
### ๐Ÿ“š Documentation
* update readme with setProviderAndWait ([6dd6847](https://github.com/spotify/confidence-openfeature-provider-js/commit/6dd6847ce513f31491ed88f75cd13d7f598bc366))
### ๐Ÿ”„ Refactoring
* providers depend on total confidence ([ac4a56b](https://github.com/spotify/confidence-openfeature-provider-js/commit/ac4a56be0e858cdccacd7fef248ebfec3a2e5dc0))
### Dependencies
* The following workspace dependencies were updated
* dependencies
* @spotify-confidence/sdk bumped from 0.0.1 to 0.0.2
## [0.1.5](https://github.com/spotify/confidence-openfeature-provider-js/compare/openfeature-server-provider-v0.1.4...openfeature-server-provider-v0.1.5) (2024-02-01)

@@ -11,0 +45,0 @@

{
"name": "@spotify-confidence/openfeature-server-provider",
"license": "Apache-2.0",
"version": "0.1.5",
"version": "0.2.0-rc.0",
"module": "build/esm/index.js",

@@ -9,6 +9,10 @@ "main": "build/cjs/index.js",

"dependencies": {
"@spotify-confidence/client-http": "^0.1.4"
"@spotify-confidence/sdk": "0.0.2"
},
"devDependencies": {
"@openfeature/core": "^0.0.24",
"@openfeature/server-sdk": "^1.10.0"
},
"peerDependencies": {
"@openfeature/js-sdk": "^1.4.2"
"@openfeature/server-sdk": "^1.10.0"
},

@@ -24,3 +28,3 @@ "scripts": {

},
"gitHead": "f2461b20ffca3c56183193856fe529542e880be7"
"gitHead": "86023f5a9cb5c641213ae7754be2395174754119"
}

@@ -15,3 +15,3 @@ # OpenFeature JS SDK JavaScript Confidence Provider

```sh
yarn add @openfeature/js-sdk @spotify-confidence/openfeature-server-provider
yarn add @openfeature/server-sdk @spotify-confidence/openfeature-server-provider @openfeature/core
```

@@ -23,3 +23,3 @@

import { createConfidenceServerProvider } from '@spotify-confidence/openfeature-server-provider';
import { OpenFeature } from '@openfeature/js-sdk';
import { OpenFeature } from '@openfeature/server-sdk';

@@ -26,0 +26,0 @@ const provider = createConfidenceServerProvider({

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