From 9682d6fa38c23a399bfa6c838b2d5ebb703e6260 Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Tue, 19 Nov 2024 14:03:33 -0800 Subject: [PATCH 1/4] chore: tsc enable `strict` type checks --- package.json | 3 ++- src/bandit-evaluator.ts | 4 ++-- src/client/eppo-client.ts | 10 +++++----- src/evaluator.ts | 4 ++-- src/http-client.ts | 2 +- src/poller.ts | 4 ++-- tsconfig.json | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index fb7305d..97f4f51 100644 --- a/package.json +++ b/package.json @@ -72,5 +72,6 @@ "md5": "^2.3.0", "pino": "^8.19.0", "semver": "^7.5.4" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/bandit-evaluator.ts b/src/bandit-evaluator.ts index 156e50e..74ab920 100644 --- a/src/bandit-evaluator.ts +++ b/src/bandit-evaluator.ts @@ -20,8 +20,8 @@ export interface BanditEvaluation { } export class BanditEvaluator { - private assignmentShards = BANDIT_ASSIGNMENT_SHARDS; // We just hard code this for now - private sharder: Sharder = new MD5Sharder(); + private readonly assignmentShards = BANDIT_ASSIGNMENT_SHARDS; // We just hard code this for now + private readonly sharder: Sharder = new MD5Sharder(); public evaluateBandit( flagKey: string, diff --git a/src/client/eppo-client.ts b/src/client/eppo-client.ts index d791b20..f277d21 100644 --- a/src/client/eppo-client.ts +++ b/src/client/eppo-client.ts @@ -509,7 +509,7 @@ export default class EppoClient { ); evaluationDetails.banditAction = action; } - } catch (err) { + } catch (err: any) { logger.error('Error determining bandit action', err); if (!this.isGracefulFailureMode) { throw err; @@ -700,7 +700,7 @@ export default class EppoClient { expectedVariationType, ); return this.parseVariationWithDetails(result, defaultValue, expectedVariationType); - } catch (error) { + } catch (error: any) { const eppoValue = this.rethrowIfNotGraceful(error, defaultValue); if (error instanceof FlagEvaluationError && error.flagEvaluationDetails) { return { @@ -738,7 +738,7 @@ export default class EppoClient { eppoValue: EppoValue.valueOf(result.variation.value, expectedVariationType), flagEvaluationDetails: result.flagEvaluationDetails, }; - } catch (error) { + } catch (error: any) { const eppoValue = this.rethrowIfNotGraceful(error, defaultValue); return { eppoValue, @@ -958,7 +958,7 @@ export default class EppoClient { eventsToFlush.forEach((event) => { try { logFunction(event); - } catch (error) { + } catch (error: any) { logger.error(`[Eppo SDK] Error flushing event to logger: ${error.message}`); } }); @@ -1005,7 +1005,7 @@ export default class EppoClient { allocationKey: allocationKey ?? '__eppo_no_allocation', variationKey: variation?.key ?? '__eppo_no_variation', }); - } catch (error) { + } catch (error: any) { logger.error(`[Eppo SDK] Error logging assignment event: ${error.message}`); } } diff --git a/src/evaluator.ts b/src/evaluator.ts index d0845b2..d0d4282 100644 --- a/src/evaluator.ts +++ b/src/evaluator.ts @@ -32,7 +32,7 @@ export interface FlagEvaluation { } export class Evaluator { - sharder: Sharder; + private readonly sharder: Sharder; constructor(sharder?: Sharder) { this.sharder = sharder ?? new MD5Sharder(); @@ -133,7 +133,7 @@ export class Evaluator { 'No allocations matched. Falling back to "Default Allocation", serving NULL', ), ); - } catch (err) { + } catch (err: any) { const flagEvaluationDetails = flagEvaluationDetailsBuilder.gracefulBuild( 'ASSIGNMENT_ERROR', `Assignment Error: ${err.message}`, diff --git a/src/http-client.ts b/src/http-client.ts index 6bb1ac6..b6ded5c 100644 --- a/src/http-client.ts +++ b/src/http-client.ts @@ -61,7 +61,7 @@ export default class FetchHttpClient implements IHttpClient { throw new HttpRequestError('Failed to fetch data', response?.status); } return await response.json(); - } catch (error) { + } catch (error: any) { if (error.name === 'AbortError') { throw new HttpRequestError('Request timed out', 408, error); } else if (error instanceof HttpRequestError) { diff --git a/src/poller.ts b/src/poller.ts index 5e9dcad..386b0e7 100644 --- a/src/poller.ts +++ b/src/poller.ts @@ -48,7 +48,7 @@ export default function initPoller( startRequestSuccess = true; previousPollFailed = false; logger.info('Eppo SDK successfully requested initial configuration'); - } catch (pollingError) { + } catch (pollingError: any) { previousPollFailed = true; logger.warn( `Eppo SDK encountered an error with initial poll of configurations: ${pollingError.message}`, @@ -116,7 +116,7 @@ export default function initPoller( previousPollFailed = false; logger.info('Eppo SDK poll successful; resuming normal polling'); } - } catch (error) { + } catch (error: any) { previousPollFailed = true; logger.warn(`Eppo SDK encountered an error polling configurations: ${error.message}`); const maxTries = 1 + (options?.maxPollRetries ?? DEFAULT_POLL_CONFIG_REQUEST_RETRIES); diff --git a/tsconfig.json b/tsconfig.json index 51babe2..583833b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "target": "es2017", "outDir": "dist", "noImplicitAny": true, - "strictNullChecks": true, + "strict": true, "strictPropertyInitialization": true }, "include": ["src/**/*.ts"], From 17df32587a307e7d82a190e64472f5b1c7d63036 Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Tue, 19 Nov 2024 14:09:20 -0800 Subject: [PATCH 2/4] fix types --- src/client/eppo-client-assignment-details.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/client/eppo-client-assignment-details.spec.ts b/src/client/eppo-client-assignment-details.spec.ts index 2e89889..e8c7f5f 100644 --- a/src/client/eppo-client-assignment-details.spec.ts +++ b/src/client/eppo-client-assignment-details.spec.ts @@ -13,6 +13,7 @@ import { AllocationEvaluationCode } from '../flag-evaluation-details-builder'; import FetchHttpClient from '../http-client'; import { Flag, ObfuscatedFlag, Variation, VariationType } from '../interfaces'; import { OperatorType } from '../rules'; +import { AttributeType } from '../types'; import EppoClient, { IAssignmentDetails } from './eppo-client'; @@ -345,7 +346,12 @@ describe('EppoClient get*AssignmentDetails', () => { [VariationType.STRING]: client.getStringAssignmentDetails.bind(client), [VariationType.JSON]: client.getJSONAssignmentDetails.bind(client), }; - const assignmentFn = typeAssignmentDetailsFunctions[variationType]; + const assignmentFn = typeAssignmentDetailsFunctions[variationType] as ( + flagKey: string, + subjectKey: string, + subjectAttributes: Record, + defaultValue: boolean | string | number | object, + ) => IAssignmentDetails; if (!assignmentFn) { throw new Error(`Unknown variation type: ${variationType}`); } From 4367aee5db5a77bc13c21922b51ed12a0981567a Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Tue, 19 Nov 2024 14:12:33 -0800 Subject: [PATCH 3/4] more fixes --- src/client/eppo-client.spec.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/client/eppo-client.spec.ts b/src/client/eppo-client.spec.ts index d5d91f9..9015f37 100644 --- a/src/client/eppo-client.spec.ts +++ b/src/client/eppo-client.spec.ts @@ -20,8 +20,13 @@ import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.stor import { MAX_EVENT_QUEUE_SIZE, POLL_INTERVAL_MS, POLL_JITTER_PCT } from '../constants'; import FetchHttpClient from '../http-client'; import { Flag, ObfuscatedFlag, VariationType } from '../interfaces'; +import { AttributeType } from '../types'; -import EppoClient, { FlagConfigurationRequestParameters, checkTypeMatch } from './eppo-client'; +import EppoClient, { + FlagConfigurationRequestParameters, + checkTypeMatch, + IAssignmentDetails, +} from './eppo-client'; export async function init(configurationStore: IConfigurationStore) { const apiEndpoints = new ApiEndpoints({ @@ -236,7 +241,12 @@ describe('EppoClient E2E test', () => { [VariationType.JSON]: client.getJSONAssignment.bind(client), }; - const assignmentFn = typeAssignmentFunctions[variationType]; + const assignmentFn = typeAssignmentFunctions[variationType] as ( + flagKey: string, + subjectKey: string, + subjectAttributes: Record, + defaultValue: boolean | string | number | object, + ) => never; if (!assignmentFn) { throw new Error(`Unknown variation type: ${variationType}`); } @@ -280,7 +290,12 @@ describe('EppoClient E2E test', () => { [VariationType.JSON]: client.getJSONAssignment.bind(client), }; - const assignmentFn = typeAssignmentFunctions[variationType]; + const assignmentFn = typeAssignmentFunctions[variationType] as ( + flagKey: string, + subjectKey: string, + subjectAttributes: Record, + defaultValue: boolean | string | number | object, + ) => never; if (!assignmentFn) { throw new Error(`Unknown variation type: ${variationType}`); } From fb066639e4301a3d4fe71492a0fe5e814019509a Mon Sep 17 00:00:00 2001 From: Felipe Lima Date: Tue, 19 Nov 2024 14:23:33 -0800 Subject: [PATCH 4/4] readme reword --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 235f782..25018e6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Eppo JS Common SDK for library +# Common library for Eppo's JavasScript SDK [![](https://img.shields.io/npm/v/@eppo/js-client-sdk-common)](https://www.npmjs.com/package/@eppo/js-client-sdk-common) [![](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](https://eppo-exp.github.io/js-client-sdk/js-client-sdk-common.html)