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) diff --git a/package.json b/package.json index 2574db8..1005c46 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-assignment-details.spec.ts b/src/client/eppo-client-assignment-details.spec.ts index 5a2e5c3..6797778 100644 --- a/src/client/eppo-client-assignment-details.spec.ts +++ b/src/client/eppo-client-assignment-details.spec.ts @@ -9,6 +9,7 @@ import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.stor import { AllocationEvaluationCode } from '../flag-evaluation-details-builder'; import { Flag, ObfuscatedFlag, Variation, VariationType } from '../interfaces'; import { OperatorType } from '../rules'; +import { AttributeType } from '../types'; import EppoClient, { IAssignmentDetails } from './eppo-client'; import { initConfiguration } from './test-utils'; @@ -323,7 +324,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}`); } diff --git a/src/client/eppo-client.spec.ts b/src/client/eppo-client.spec.ts index 6683082..f16a3f8 100644 --- a/src/client/eppo-client.spec.ts +++ b/src/client/eppo-client.spec.ts @@ -17,6 +17,7 @@ import { IConfigurationStore } from '../configuration-store/configuration-store' import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store'; import { MAX_EVENT_QUEUE_SIZE, DEFAULT_POLL_INTERVAL_MS, POLL_JITTER_PCT } from '../constants'; import { Flag, ObfuscatedFlag, VariationType } from '../interfaces'; +import { AttributeType } from '../types'; import EppoClient, { FlagConfigurationRequestParameters, checkTypeMatch } from './eppo-client'; import { initConfiguration } from './test-utils'; @@ -214,7 +215,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}`); } @@ -258,7 +264,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}`); } diff --git a/src/client/eppo-client.ts b/src/client/eppo-client.ts index 05d76c2..899fcb8 100644 --- a/src/client/eppo-client.ts +++ b/src/client/eppo-client.ts @@ -515,7 +515,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; @@ -752,7 +752,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 { @@ -790,7 +790,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, @@ -1010,7 +1010,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}`); } }); @@ -1057,7 +1057,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"],