Skip to content

Commit

Permalink
feat: flag dependencies (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgiori authored Mar 9, 2023
1 parent 8ca0a27 commit 9f8081e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"homepage": "https://github.com/amplitude/experiment-node-server#readme",
"gitHead": "e8ceef5275b6daf4f7f26c6ac2e1683eeba7aca6",
"dependencies": {
"@amplitude/evaluation-js": "1.0.0"
"@amplitude/evaluation-js": "1.1.0"
}
}
16 changes: 12 additions & 4 deletions packages/node/src/local/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { FlagConfig, FlagConfigCache } from '../types/flag';
import { HttpClient } from '../types/transport';
import { ExperimentUser } from '../types/user';
import { Variants } from '../types/variant';
import { Results, Variants } from '../types/variant';
import { ConsoleLogger } from '../util/logger';
import { Logger } from '../util/logger';

Expand Down Expand Up @@ -80,9 +80,17 @@ export class LocalEvaluationClient {
'flagConfigs:',
flagConfigs,
);
const results: Variants = evaluation.evaluate(flagConfigs, user);
this.logger.debug('[Experiment] evaluate - result: ', results);
return results;
const results: Results = evaluation.evaluate(flagConfigs, user);
const variants: Variants = {};
for (const flagKey in results) {
const flagResult = results[flagKey];
variants[flagKey] = {
value: flagResult.value,
payload: flagResult.payload,
};
}
this.logger.debug('[Experiment] evaluate - variants: ', variants);
return variants;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/local/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class FlagConfigFetcher {
* environment
*/
public async fetch(): Promise<Record<string, FlagConfig>> {
const endpoint = `${this.serverUrl}/sdk/rules?eval_mode=local`;
const endpoint = `${this.serverUrl}/sdk/v1/flags`;
const headers = {
Authorization: `Api-Key ${this.apiKey}`,
Accept: 'application/json',
Expand Down
13 changes: 13 additions & 0 deletions packages/node/src/types/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ export type Variant = {
export type Variants = {
[flagKey: string]: Variant;
};

export type FlagResult = {
value: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
payload: any | null | undefined;
expKey: string | null | undefined;
deployed: boolean;
type: string;
};

export type Results = {
[flagKey: string]: FlagResult;
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@amplitude/evaluation-js@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@amplitude/evaluation-js/-/evaluation-js-1.0.0.tgz#1ae828379d3600f433b37a505514b756c94678ef"
integrity sha512-U2ibGJ+5XLwfyHPmwDdxkqWhxxmZBs/gnPWalKBnmcY4zGXfBi2XkGbHsghlAD3XD3vZ1eMl7xqhHp3CWtpp/g==
"@amplitude/evaluation-js@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@amplitude/evaluation-js/-/evaluation-js-1.1.0.tgz#e8c0ae9843165d5b6ab3183df5ba7f54c523faa7"
integrity sha512-//PMRmRrmBQMA94hYrDKWvU+037IDxM3rfdyPS3GiQKXMTg6CWPZWsOVlbD2RtXf0QMx5C7q2O6bCjId4tsUWQ==

"@amplitude/experiment-js-client@^0.2.0":
version "0.2.0"
Expand Down

0 comments on commit 9f8081e

Please sign in to comment.