Skip to content

[FFM-1263] flag rules evaluations, repository with persistent #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
"plugin:jest/recommended",
"prettier"
],
"rules": {}
"rules": {
"@typescript-eslint/no-unused-vars": [2, { "argsIgnorePattern": "^_" }]
}
}
6 changes: 5 additions & 1 deletion example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { CfClient } from 'ff-nodejs-server-sdk';

const client = new CfClient('1c100d25-4c3f-487b-b198-3b3d01df5794');
client.boolVariation('test', null, false);

setInterval(() => {
const value = client.boolVariation('test', null, false);
console.log("Evaluation for flag test and target none: ", value);
}, 10000);
64 changes: 64 additions & 0 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
},
"author": "[email protected]",
"dependencies": {
"ff-nodejs-server-sdk": "file:../"
"ff-nodejs-server-sdk": "file:.."
}
}
69 changes: 64 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"devDependencies": {
"@types/eventsource": "^1.1.6",
"@types/jest": "~26.0.23",
"@types/keyv": "^3.1.3",
"@types/node": "^14.17.11",
"@typescript-eslint/eslint-plugin": "~4.28.2",
"@typescript-eslint/parser": "~4.28.2",
Expand Down Expand Up @@ -40,6 +41,9 @@
"@openapitools/openapi-generator-cli": "^2.3.10",
"eventsource": "^1.1.0",
"jwt-decode": "^3.1.2",
"keyv": "^4.0.3",
"keyv-file": "^0.2.0",
"murmurhash": "^2.0.0",
"node-cache": "^5.1.2",
"tslib": "~2.3.0"
},
Expand Down
43 changes: 43 additions & 0 deletions src/boolean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Operator } from "./types";

export class Bool implements Operator {
private value: boolean;

constructor(value: boolean) {
this.value = value;
}
startsWith(_value: string[]): boolean {
return false;
}
endsWith(_value: string[]): boolean {
return false;
}
match(_value: string[]): boolean {
return false;
}
contains(_value: string[]): boolean {
return false;
}
equalSensitive(_value: string[]): boolean {
return false;
}
equal(value: string[]): boolean {
return this.value === (value[0].toLowerCase() === 'true');
}
greaterThan(_value: string[]): boolean {
return false;
}
greaterThanEqual(_value: string[]): boolean {
return false;
}
lessThan(_value: string[]): boolean {
return false;
}
lessThanEqual(_value: string[]): boolean {
return false;
}
inList(_value: string[]): boolean {
return this.value
}

}
24 changes: 4 additions & 20 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,15 @@
import { FeatureConfig, Segment } from "./openapi";
import { KeyValueStore } from "./types";

export type CacheValueType = FeatureConfig | Segment;

export interface Cache {
set(key: string, value: CacheValueType): void;
get(key: string): CacheValueType;
del(key: string): void;
}

export class SimpleCache implements Cache {
export class SimpleCache implements KeyValueStore {
private cache = {};

set(key: string, value: CacheValueType): void {
set(key: string, value: unknown): void {
this.cache[key] = value;
}
get(key: string): CacheValueType {
get(key: string): unknown {
return this.cache[key];
}
del(key: string): void {
delete this.cache[key];
}
}

export const formatFlagKey = (key: string): string => {
return `flags/${key}`
}

export const formatSegmentKey = (key: string): string => {
return `segments/${key}`
}
36 changes: 36 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { SimpleCache } from "./cache";
import { ConsoleLog } from "./log";
import { FileStore } from "./store";
import { Options } from "./types";

export const ONE_HUNDRED = 100;

export const SEGMENT_MATCH_OPERATOR = 'segmentMatch',
IN_OPERATOR = 'in',
EQUAL_OPERATOR = 'equal',
GT_OPERATOR = 'gt',
STARTS_WITH_OPERATOR = 'starts_with',
ENDS_WITH_OPERATOR = 'ends_with',
CONTAINS_OPERATOR = 'contains',
EQUAL_SENSITIVE_OPERATOR = 'equal_sensitive';

export const BASE_URL = 'https://config.ff.harness.io/api/1.0',
EVENTS_URL = 'https://events.ff.harness.io/api/1.0',
SECOND = 1000,
MINUTE = 60 * SECOND,
PULL_INTERVAL = 1 * MINUTE,
PERSIST_INTERVAL = 1 * MINUTE,
EVENTS_SYNC_INTERVAL = 1 * MINUTE;

export const defaultOptions: Options = {
baseUrl: BASE_URL,
eventsUrl: EVENTS_URL,
pollInterval: PULL_INTERVAL,
persistInterval: PERSIST_INTERVAL,
eventsSyncInterval: EVENTS_SYNC_INTERVAL,
enableStream: true,
enableAnalytics: true,
cache: new SimpleCache(),
store: new FileStore(),
logger: new ConsoleLog(),
};
Loading