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

@eppo/node-server-sdk

Package Overview
Dependencies
Maintainers
4
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eppo/node-server-sdk - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

dist/rule_evaluator.d.ts

18

dist/eppo-client.d.ts
import ExperimentConfigurationRequestor from './experiment/experiment-configuration-requestor';
import { AttributeValueType } from './rule';
/**

@@ -10,19 +11,16 @@ * Client for assigning experiment variations.

*
* @param subject an entity ID, e.g. userId
* @param subjectKey an identifier of the experiment subject, for example a user ID.
* @param experimentKey experiment identifier
* @param subjectAttributes optional attributes associated with the subject, for example name and email.
* The subject attributes are used for evaluating any targeting rules tied to the experiment.
* @returns a variation value if the subject is part of the experiment sample, otherwise null
* @public
*/
getAssignment(subject: string, experimentKey: string): string;
/**
* Returns a Promise that resolves once the client polling process has started.
* @public
*/
waitForInitialization: () => Promise<void>;
getAssignment(subjectKey: string, experimentKey: string, subjectAttributes?: Record<string, AttributeValueType>): string;
}
export default class EppoClient implements IEppoClient {
waitForInitialization: () => Promise<void>;
private configurationRequestor;
constructor(waitForInitialization: () => Promise<void>, configurationRequestor: ExperimentConfigurationRequestor);
getAssignment(subject: string, experimentKey: string): string;
constructor(configurationRequestor: ExperimentConfigurationRequestor);
getAssignment(subjectKey: string, experimentKey: string, subjectAttributes?: {}): string;
private subjectAttributesSatisfyRules;
private getSubjectVariationOverride;

@@ -29,0 +27,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = require("crypto");
const rule_evaluator_1 = require("./rule_evaluator");
const shard_1 = require("./shard");
const validation_1 = require("./validation");
class EppoClient {
constructor(waitForInitialization, configurationRequestor) {
this.waitForInitialization = waitForInitialization;
constructor(configurationRequestor) {
this.configurationRequestor = configurationRequestor;
}
getAssignment(subject, experimentKey) {
(0, validation_1.validateNotBlank)(subject, 'Invalid argument: subject cannot be blank');
getAssignment(subjectKey, experimentKey, subjectAttributes = {}) {
(0, validation_1.validateNotBlank)(subjectKey, 'Invalid argument: subjectKey cannot be blank');
(0, validation_1.validateNotBlank)(experimentKey, 'Invalid argument: experimentKey cannot be blank');
const experimentConfig = this.configurationRequestor.getConfiguration(experimentKey);
if (!(experimentConfig === null || experimentConfig === void 0 ? void 0 : experimentConfig.enabled) ||
!this.isInExperimentSample(subject, experimentKey, experimentConfig)) {
!this.subjectAttributesSatisfyRules(subjectAttributes, experimentConfig.rules) ||
!this.isInExperimentSample(subjectKey, experimentKey, experimentConfig)) {
return null;
}
const override = this.getSubjectVariationOverride(subject, experimentConfig);
const override = this.getSubjectVariationOverride(subjectKey, experimentConfig);
if (override) {

@@ -24,7 +25,13 @@ return override;

const { variations, subjectShards } = experimentConfig;
const shard = (0, shard_1.getShard)(`assignment-${subject}-${experimentKey}`, subjectShards);
const shard = (0, shard_1.getShard)(`assignment-${subjectKey}-${experimentKey}`, subjectShards);
return variations.find((variation) => (0, shard_1.isShardInRange)(shard, variation.shardRange)).name;
}
getSubjectVariationOverride(subject, experimentConfig) {
const subjectHash = (0, crypto_1.createHash)('md5').update(subject).digest('hex');
subjectAttributesSatisfyRules(subjectAttributes, rules) {
if (!rules || rules.length === 0) {
return true;
}
return (0, rule_evaluator_1.matchesAnyRule)(subjectAttributes || {}, rules);
}
getSubjectVariationOverride(subjectKey, experimentConfig) {
const subjectHash = (0, crypto_1.createHash)('md5').update(subjectKey).digest('hex');
return experimentConfig.overrides[subjectHash];

@@ -37,5 +44,5 @@ }

*/
isInExperimentSample(subject, experimentKey, experimentConfig) {
isInExperimentSample(subjectKey, experimentKey, experimentConfig) {
const { percentExposure, subjectShards } = experimentConfig;
const shard = (0, shard_1.getShard)(`exposure-${subject}-${experimentKey}`, subjectShards);
const shard = (0, shard_1.getShard)(`exposure-${subjectKey}-${experimentKey}`, subjectShards);
return shard <= percentExposure * subjectShards;

@@ -42,0 +49,0 @@ }

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

import { Rule } from '../rule';
import { IVariation } from './variation';

@@ -9,3 +10,4 @@ export interface IExperimentConfiguration {

overrides: Record<string, string>;
rules?: Rule[];
}
//# sourceMappingURL=experiment-configuration.d.ts.map

@@ -18,2 +18,3 @@ import { IEppoClient } from './eppo-client';

export { IEppoClient } from './eppo-client';
export { AttributeValueType } from './rule';
/**

@@ -26,3 +27,9 @@ * Initializes the Eppo client with configuration parameters.

*/
export declare function init(config: IClientConfig): IEppoClient;
export declare function init(config: IClientConfig): Promise<IEppoClient>;
/**
* Used to access a singleton SDK client instance.
* Use the method after calling init() to initialize the client.
* @returns a singleton client instance
*/
export declare function getInstance(): IEppoClient;
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.init = void 0;
exports.getInstance = exports.init = void 0;
const axios_1 = require("axios");

@@ -14,2 +14,3 @@ const configuration_store_1 = require("./configuration-store");

let poller = null;
let clientInstance = null;
/**

@@ -22,3 +23,3 @@ * Initializes the Eppo client with configuration parameters.

*/
function init(config) {
async function init(config) {
(0, validation_1.validateNotBlank)(config.apiKey, 'API key required');

@@ -41,6 +42,19 @@ const configurationStore = new configuration_store_1.InMemoryConfigurationStore(constants_1.MAX_CACHE_ENTRIES);

poller = (0, poller_1.default)(constants_1.POLL_INTERVAL_MILLIS, constants_1.JITTER_MILLIS, configurationRequestor.fetchAndStoreConfigurations.bind(configurationRequestor));
const startedPolling = poller.start();
return new eppo_client_1.default(() => startedPolling, configurationRequestor);
clientInstance = new eppo_client_1.default(configurationRequestor);
await poller.start();
return clientInstance;
}
exports.init = init;
/**
* Used to access a singleton SDK client instance.
* Use the method after calling init() to initialize the client.
* @returns a singleton client instance
*/
function getInstance() {
if (!clientInstance) {
throw Error('Expected init() to be called to initialize a client instance');
}
return clientInstance;
}
exports.getInstance = getInstance;
//# sourceMappingURL=index.js.map

@@ -0,2 +1,11 @@

export declare type AttributeValueType = string | number;
/**
* Used to access a singleton SDK client instance.
* Use the method after calling init() to initialize the client.
* @returns a singleton client instance
*/
export declare function getInstance(): IEppoClient;
/**
* Configuration used for initializing the Eppo client

@@ -25,13 +34,10 @@ * @public

*
* @param subject an entity ID, e.g. userId
* @param subjectKey an identifier of the experiment subject, for example a user ID.
* @param experimentKey experiment identifier
* @param subjectAttributes optional attributes associated with the subject, for example name and email.
* The subject attributes are used for evaluating any targeting rules tied to the experiment.
* @returns a variation value if the subject is part of the experiment sample, otherwise null
* @public
*/
getAssignment(subject: string, experimentKey: string): string;
/**
* Returns a Promise that resolves once the client polling process has started.
* @public
*/
waitForInitialization: () => Promise<void>;
getAssignment(subjectKey: string, experimentKey: string, subjectAttributes?: Record<string, AttributeValueType>): string;
}

@@ -46,4 +52,4 @@

*/
export declare function init(config: IClientConfig): IEppoClient;
export declare function init(config: IClientConfig): Promise<IEppoClient>;
export { }
{
"name": "@eppo/node-server-sdk",
"version": "0.4.0",
"version": "1.0.0",
"description": "Eppo node server SDK",

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

@@ -8,27 +8,2 @@ # Eppo Server-Side SDK for Node.js

Install the Eppo SDK as a dependency of your application:
```
yarn add @eppo/node-server-sdk
```
Initialize the SDK client in your application code:
```
import * as EppoSdk from '@eppo/node-server-sdk';
const eppoClient = EppoSdk.init({ apiKey: 'YOUR_API_KEY' });
```
**The client must be a singleton**. The client instance stores assignment configurations in memory. The same client instance should be reused for the lifetime of your application. Do not generate a new instance on every request.
#### Use the shared client instance to assign subjects to variations
Pass a `subject` and `experimentKey` to the client assignment function:
```
const assignedVariation = client.getAssignment("<subject>", "<experimentKey>")
```
The `subject` argument can be any entity identifier (e.g. a user ID). The `experimentKey` argument is the identifier of your Eppo experiment.
The `getAssignment` function will return `null` if the experiment is not running or if the subject is not part of the experiment traffic allocation.
Refer to our [SDK documentation](https://docs.geteppo.com/feature-flagging/randomization-sdk) for how to install and use the SDK.

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