From 62b14f8a61384778112d6c4030ec46c3da269e5c Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:00:19 -0700 Subject: [PATCH] Minor changes from testing. --- packages/sdk/browser/src/index.ts | 18 +++++++++++++++++- .../sdk-client/__tests__/HookRunner.test.ts | 6 +++--- packages/shared/sdk-client/src/HookRunner.ts | 9 ++++++--- .../sdk-client/src/api/integrations/Hooks.ts | 8 ++++---- packages/shared/sdk-client/src/index.ts | 8 ++++++++ 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/packages/sdk/browser/src/index.ts b/packages/sdk/browser/src/index.ts index d171664d6..b90c3a2eb 100644 --- a/packages/sdk/browser/src/index.ts +++ b/packages/sdk/browser/src/index.ts @@ -1,5 +1,13 @@ import { AutoEnvAttributes, + EvaluationSeriesContext, + EvaluationSeriesData, + Hook, + HookMetadata, + IdentifySeriesContext, + IdentifySeriesData, + IdentifySeriesResult, + IdentifySeriesStatus, LDContext, LDContextCommon, LDContextMeta, @@ -19,7 +27,7 @@ import { BrowserClient, LDClient } from './BrowserClient'; import { BrowserIdentifyOptions as LDIdentifyOptions } from './BrowserIdentifyOptions'; import { BrowserOptions as LDOptions } from './options'; -export { +export type { LDClient, LDFlagSet, LDContext, @@ -34,6 +42,14 @@ export { LDEvaluationDetailTyped, LDEvaluationReason, LDIdentifyOptions, + Hook, + HookMetadata, + EvaluationSeriesContext, + EvaluationSeriesData, + IdentifySeriesContext, + IdentifySeriesData, + IdentifySeriesResult, + IdentifySeriesStatus, }; export function init(clientSideId: string, options?: LDOptions): LDClient { diff --git a/packages/shared/sdk-client/__tests__/HookRunner.test.ts b/packages/shared/sdk-client/__tests__/HookRunner.test.ts index 4f6a1709b..85d704df4 100644 --- a/packages/shared/sdk-client/__tests__/HookRunner.test.ts +++ b/packages/shared/sdk-client/__tests__/HookRunner.test.ts @@ -1,6 +1,6 @@ import { LDContext, LDEvaluationDetail, LDLogger } from '@launchdarkly/js-sdk-common'; -import { Hook, IdentifyResult } from '../src/api/integrations/Hooks'; +import { Hook, IdentifySeriesResult } from '../src/api/integrations/Hooks'; import HookRunner from '../src/HookRunner'; describe('given a hook runner and test hook', () => { @@ -135,7 +135,7 @@ describe('given a hook runner and test hook', () => { it('should execute identify hooks', () => { const context: LDContext = { kind: 'user', key: 'user-123' }; const timeout = 10; - const identifyResult: IdentifyResult = { status: 'completed' }; + const identifyResult: IdentifySeriesResult = { status: 'completed' }; const identifyCallback = hookRunner.identify(context, timeout); identifyCallback(identifyResult); @@ -182,7 +182,7 @@ describe('given a hook runner and test hook', () => { it('should pass identify series data from before to after hooks', () => { const context: LDContext = { kind: 'user', key: 'user-123' }; const timeout = 10; - const identifyResult: IdentifyResult = { status: 'completed' }; + const identifyResult: IdentifySeriesResult = { status: 'completed' }; testHook.beforeIdentify = jest .fn() diff --git a/packages/shared/sdk-client/src/HookRunner.ts b/packages/shared/sdk-client/src/HookRunner.ts index f7ea76891..f2f670342 100644 --- a/packages/shared/sdk-client/src/HookRunner.ts +++ b/packages/shared/sdk-client/src/HookRunner.ts @@ -4,9 +4,9 @@ import { EvaluationSeriesContext, EvaluationSeriesData, Hook, - IdentifyResult, IdentifySeriesContext, IdentifySeriesData, + IdentifySeriesResult, } from './api/integrations/Hooks'; import { LDEvaluationDetail } from './api/LDEvaluationDetail'; @@ -97,7 +97,7 @@ function executeAfterIdentify( hooks: Hook[], hookContext: IdentifySeriesContext, updatedData: IdentifySeriesData[], - result: IdentifyResult, + result: IdentifySeriesResult, ) { // This iterates in reverse, versus reversing a shallow copy of the hooks, // for efficiency. @@ -146,7 +146,10 @@ export default class HookRunner { return result; } - identify(context: LDContext, timeout: number | undefined): (result: IdentifyResult) => void { + identify( + context: LDContext, + timeout: number | undefined, + ): (result: IdentifySeriesResult) => void { const hooks: Hook[] = [...this.hooks]; const hookContext: IdentifySeriesContext = { context, diff --git a/packages/shared/sdk-client/src/api/integrations/Hooks.ts b/packages/shared/sdk-client/src/api/integrations/Hooks.ts index 1c195c085..deb1552c2 100644 --- a/packages/shared/sdk-client/src/api/integrations/Hooks.ts +++ b/packages/shared/sdk-client/src/api/integrations/Hooks.ts @@ -59,15 +59,15 @@ export interface IdentifySeriesData { /** * The status an identify operation completed with. */ -export type IdentifyStatus = 'completed' | 'error'; +export type IdentifySeriesStatus = 'completed' | 'error'; /** * The result applies to a single identify operation. An operation may complete * with an error and then later complete successfully. Only the first completion * will be executed in the evaluation series. */ -export interface IdentifyResult { - status: IdentifyStatus; +export interface IdentifySeriesResult { + status: IdentifySeriesStatus; } /** @@ -157,6 +157,6 @@ export interface Hook { afterIdentify?( hookContext: IdentifySeriesContext, data: IdentifySeriesData, - result: IdentifyResult, + result: IdentifySeriesResult, ): IdentifySeriesData; } diff --git a/packages/shared/sdk-client/src/index.ts b/packages/shared/sdk-client/src/index.ts index cae0e4206..7073c9675 100644 --- a/packages/shared/sdk-client/src/index.ts +++ b/packages/shared/sdk-client/src/index.ts @@ -20,6 +20,14 @@ export type { LDOptions, ConnectionMode, LDIdentifyOptions, + Hook, + HookMetadata, + EvaluationSeriesContext, + EvaluationSeriesData, + IdentifySeriesContext, + IdentifySeriesData, + IdentifySeriesResult, + IdentifySeriesStatus, } from './api'; export type { DataManager, DataManagerFactory, ConnectionParams } from './DataManager';