From 9d2b009aabecea0a1b2a0f497c4ae15083cc939d Mon Sep 17 00:00:00 2001 From: Nicky Bondarenko Date: Wed, 27 Nov 2024 16:10:10 +0100 Subject: [PATCH] feat: move logger into evaluateFlag --- api/sdk.api.md | 2 ++ packages/sdk/src/Confidence.test.ts | 1 + packages/sdk/src/Confidence.ts | 15 +++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/api/sdk.api.md b/api/sdk.api.md index 8f6b3b96..e703e56a 100644 --- a/api/sdk.api.md +++ b/api/sdk.api.md @@ -64,6 +64,8 @@ export interface ConfidenceOptions { // @public export interface Configuration { + // (undocumented) + readonly clientSecret: string; readonly environment: 'client' | 'backend'; // Warning: (ae-forgotten-export) The symbol "EventSenderEngine" needs to be exported by the entry point index.d.ts // diff --git a/packages/sdk/src/Confidence.test.ts b/packages/sdk/src/Confidence.test.ts index e31bd03d..2f89d631 100644 --- a/packages/sdk/src/Confidence.test.ts +++ b/packages/sdk/src/Confidence.test.ts @@ -23,6 +23,7 @@ describe('Confidence', () => { beforeEach(() => { confidence = new Confidence({ + clientSecret: 'secret', timeout: 10, environment: 'client', logger: {}, diff --git a/packages/sdk/src/Confidence.ts b/packages/sdk/src/Confidence.ts index 900308e6..fbab81b4 100644 --- a/packages/sdk/src/Confidence.ts +++ b/packages/sdk/src/Confidence.ts @@ -293,6 +293,7 @@ export class Confidence implements EventSender, Trackable, FlagResolver { value: defaultValue, }; } else { + this.showLoggerLink(path, this.getContext()); evaluation = this.currentFlags.evaluate(path, defaultValue); } if (!this.currentFlags || !Value.equal(this.currentFlags.context, this.getContext())) { @@ -313,13 +314,15 @@ export class Confidence implements EventSender, Trackable, FlagResolver { getFlag(path: string, defaultValue: number): Promise; getFlag(path: string, defaultValue: T): Promise; async getFlag(path: string, defaultValue: any): Promise { - const clientKey = this.config.clientSecret; - const flag = (await this.evaluateFlag(path, defaultValue)).value; - const context = this._context; - this.config.logger.debug?.( - `Resolve debug: https://app.confidence.spotify.com/flags/resolver-test?client-key=${clientKey}&flag=flags/${flag}&context=${context}`, + return (await this.evaluateFlag(path, defaultValue)).value; + } + + private showLoggerLink(flag: string, context: Context) { + this.config.logger.info?.( + `Resolve debug: https://app.confidence.spotify.com/flags/resolver-test?client-key=${ + this.config.clientSecret + }&flag=flags/${flag}&context=${JSON.stringify(context)}`, ); - return flag; } /**