Skip to content

Commit

Permalink
Minor changes from testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion committed Oct 4, 2024
1 parent c224cd6 commit 62b14f8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
18 changes: 17 additions & 1 deletion packages/sdk/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import {
AutoEnvAttributes,
EvaluationSeriesContext,
EvaluationSeriesData,
Hook,
HookMetadata,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
IdentifySeriesStatus,
LDContext,
LDContextCommon,
LDContextMeta,
Expand All @@ -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,
Expand All @@ -34,6 +42,14 @@ export {
LDEvaluationDetailTyped,
LDEvaluationReason,
LDIdentifyOptions,
Hook,
HookMetadata,
EvaluationSeriesContext,
EvaluationSeriesData,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
IdentifySeriesStatus,
};

export function init(clientSideId: string, options?: LDOptions): LDClient {
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/sdk-client/__tests__/HookRunner.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions packages/shared/sdk-client/src/HookRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
EvaluationSeriesContext,
EvaluationSeriesData,
Hook,
IdentifyResult,
IdentifySeriesContext,
IdentifySeriesData,
IdentifySeriesResult,
} from './api/integrations/Hooks';
import { LDEvaluationDetail } from './api/LDEvaluationDetail';

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/sdk-client/src/api/integrations/Hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -157,6 +157,6 @@ export interface Hook {
afterIdentify?(
hookContext: IdentifySeriesContext,
data: IdentifySeriesData,
result: IdentifyResult,
result: IdentifySeriesResult,
): IdentifySeriesData;
}
8 changes: 8 additions & 0 deletions packages/shared/sdk-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 62b14f8

Please sign in to comment.