Skip to content

Commit 6d0ee27

Browse files
refactor: split types into shared/client/server modules for proper SDK dependency isolation
- src/types/ now contains only SDK-independent types (no LDContext/LDEvaluationReason) - src/client-side/types/ has client-specific types importing from js-client-sdk-common - src/server-side/types/ has server-specific types importing from js-server-sdk-common - server.ts barrel re-exports shared + server types (bigSegments, dataSystem, migrations) - client.ts barrel re-exports shared + client types (SDKConfigClientSideParams) - index.ts exports only universal types with no SDK dependency - server-node contract tests now import CommandParams, CreateInstanceParams, SDKConfigParams from shared package - Added @launchdarkly/js-server-sdk-common as optional peer dependency Co-Authored-By: Steven Zhang <szhang@launchdarkly.com>
1 parent 6cf71df commit 6d0ee27

12 files changed

Lines changed: 411 additions & 268 deletions

File tree

packages/sdk/server-node/contract-tests/src/sdkClientEntity.ts

Lines changed: 7 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import got from 'got';
22

3-
import { ServerSideTestHook as TestHook } from '@launchdarkly/js-contract-test-utils/server';
3+
import {
4+
CommandParams,
5+
CreateInstanceParams,
6+
SDKConfigParams,
7+
ServerSideTestHook as TestHook,
8+
} from '@launchdarkly/js-contract-test-utils/server';
49
import ld, {
510
createMigration,
611
DataSourceOptions,
712
LDClient,
813
LDConcurrentExecution,
914
LDContext,
1015
LDExecutionOrdering,
11-
LDFlagValue,
1216
LDMigrationError,
13-
LDMigrationStage,
1417
LDMigrationSuccess,
1518
LDOptions,
1619
LDSerialExecution,
@@ -25,152 +28,7 @@ import { Log, sdkLogger } from './log.js';
2528
const badCommandError = new Error('unsupported command');
2629
export { badCommandError };
2730

28-
interface SdkConfigOptions {
29-
credential: string;
30-
startWaitTimeMs?: number;
31-
initCanFail?: boolean;
32-
serviceEndpoints?: {
33-
streaming?: string;
34-
polling?: string;
35-
events?: string;
36-
};
37-
tls?: {
38-
skipVerifyPeer?: boolean;
39-
customCAFile?: string;
40-
};
41-
streaming?: {
42-
baseUri?: string;
43-
initialRetryDelayMs?: number;
44-
filter?: string;
45-
};
46-
polling?: {
47-
baseUri?: string;
48-
pollIntervalMs?: number;
49-
filter?: string;
50-
};
51-
events?: {
52-
baseUri?: string;
53-
capacity?: number;
54-
enableDiagnostics: boolean;
55-
allAttributesPrivate?: boolean;
56-
globalPrivateAttributes?: string[];
57-
flushIntervalMs?: number;
58-
omitAnonymousContexts?: boolean;
59-
enableGzip?: boolean;
60-
};
61-
tags?: {
62-
applicationId?: string;
63-
applicationVersion?: string;
64-
};
65-
bigSegments?: {
66-
callbackUri: string;
67-
userCacheSize?: number;
68-
userCacheTimeMs?: number;
69-
statusPollIntervalMs?: number;
70-
staleAfterMs?: number;
71-
};
72-
hooks?: {
73-
hooks: {
74-
name: string;
75-
callbackUri: string;
76-
data?: Record<string, Record<string, unknown>>;
77-
errors?: Record<string, string>;
78-
}[];
79-
};
80-
wrapper?: {
81-
name: string;
82-
version: string;
83-
};
84-
proxy?: {
85-
httpProxy?: string;
86-
};
87-
dataSystem?: {
88-
initializers?: SDKDataSystemInitializerParams[];
89-
synchronizers?: SDKDataSystemSynchronizerParams[];
90-
payloadFilter?: string;
91-
};
92-
}
93-
94-
interface CreateInstanceParams {
95-
configuration: SdkConfigOptions;
96-
tag: string;
97-
}
98-
99-
export interface SDKDataSystemSynchronizerParams {
100-
streaming?: SDKDataSourceStreamingParams;
101-
polling?: SDKDataSourcePollingParams;
102-
}
103-
104-
export interface SDKDataSystemInitializerParams {
105-
polling?: SDKDataSourcePollingParams;
106-
}
107-
108-
export interface SDKDataSourceStreamingParams {
109-
baseUri?: string;
110-
initialRetryDelayMs?: number;
111-
}
112-
113-
export interface SDKDataSourcePollingParams {
114-
baseUri?: string;
115-
pollIntervalMs?: number;
116-
}
117-
118-
interface CommandParams {
119-
command: string;
120-
evaluate?: {
121-
flagKey: string;
122-
context?: LDContext;
123-
user?: LDUser;
124-
defaultValue: LDFlagValue;
125-
detail?: boolean;
126-
valueType?: string;
127-
};
128-
evaluateAll?: {
129-
context?: LDContext;
130-
user?: LDUser;
131-
clientSideOnly?: boolean;
132-
detailsOnlyForTrackedFlags?: boolean;
133-
withReasons?: boolean;
134-
};
135-
identifyEvent?: {
136-
context?: LDContext;
137-
user?: LDUser;
138-
};
139-
customEvent?: {
140-
eventKey: string;
141-
context?: LDContext;
142-
user?: LDUser;
143-
data?: any;
144-
metricValue?: number;
145-
};
146-
migrationVariation?: {
147-
key: string;
148-
context: LDContext;
149-
defaultStage: LDMigrationStage;
150-
};
151-
migrationOperation?: {
152-
operation: string;
153-
key: string;
154-
context: LDContext;
155-
defaultStage: LDMigrationStage;
156-
payload: any;
157-
readExecutionOrder: string;
158-
trackLatency?: boolean;
159-
trackErrors?: boolean;
160-
trackConsistency?: boolean;
161-
newEndpoint: string;
162-
oldEndpoint: string;
163-
};
164-
registerFlagChangeListener?: {
165-
listenerId: string;
166-
callbackUri: string;
167-
};
168-
unregisterListener?: {
169-
listenerId: string;
170-
};
171-
}
172-
173-
export function makeSdkConfig(options: SdkConfigOptions, tag: string): LDOptions {
31+
export function makeSdkConfig(options: SDKConfigParams, tag: string): LDOptions {
17432
const cf: LDOptions = {
17533
logger: sdkLogger(tag),
17634
diagnosticOptOut: true,

packages/tooling/contract-test-utils/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@
4141
"@launchdarkly/js-client-sdk-common": "workspace:^"
4242
},
4343
"peerDependencies": {
44+
"@launchdarkly/js-server-sdk-common": "workspace:^",
4445
"@launchdarkly/node-server-sdk": "workspace:^",
4546
"got": "14.4.7"
4647
},
4748
"peerDependenciesMeta": {
49+
"@launchdarkly/js-server-sdk-common": {
50+
"optional": true
51+
},
4852
"@launchdarkly/node-server-sdk": {
4953
"optional": true
5054
},
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { LDContext, LDEvaluationReason } from '@launchdarkly/js-client-sdk-common';
2+
3+
import {
4+
CommandType,
5+
ContextBuildParams,
6+
ContextComparisonPairParams,
7+
ContextConvertParams,
8+
HookStage,
9+
ValueType,
10+
} from '../../types/CommandParams';
11+
12+
// Re-export shared types for convenience
13+
export { CommandType, ValueType } from '../../types/CommandParams';
14+
export type {
15+
EvaluateAllFlagsResponse,
16+
ContextBuildParams,
17+
ContextBuildSingleParams,
18+
ContextBuildResponse,
19+
ContextConvertParams,
20+
ContextComparisonPairParams,
21+
ContextComparisonParams,
22+
ContextComparisonSingleParams,
23+
AttributeDefinition,
24+
PrivateAttribute,
25+
ContextComparisonResponse,
26+
SecureModeHashResponse,
27+
} from '../../types/CommandParams';
28+
export { HookStage } from '../../types/CommandParams';
29+
30+
export interface CommandParams {
31+
command: CommandType;
32+
evaluate?: EvaluateFlagParams;
33+
evaluateAll?: EvaluateAllFlagsParams;
34+
customEvent?: CustomEventParams;
35+
identifyEvent?: IdentifyEventParams;
36+
contextBuild?: ContextBuildParams;
37+
contextConvert?: ContextConvertParams;
38+
contextComparison?: ContextComparisonPairParams;
39+
secureModeHash?: SecureModeHashParams;
40+
}
41+
42+
export interface EvaluateFlagParams {
43+
flagKey: string;
44+
context?: LDContext;
45+
user?: any;
46+
valueType: ValueType;
47+
defaultValue: unknown;
48+
detail: boolean;
49+
}
50+
51+
export interface EvaluateFlagResponse {
52+
value: unknown;
53+
variationIndex?: number;
54+
reason?: LDEvaluationReason;
55+
}
56+
57+
export interface EvaluateAllFlagsParams {
58+
context?: LDContext;
59+
user?: any;
60+
withReasons: boolean;
61+
clientSideOnly: boolean;
62+
detailsOnlyForTrackedFlags: boolean;
63+
}
64+
65+
export interface CustomEventParams {
66+
eventKey: string;
67+
context?: LDContext;
68+
user?: any;
69+
data?: unknown;
70+
omitNullData: boolean;
71+
metricValue?: number;
72+
}
73+
74+
export interface IdentifyEventParams {
75+
context?: LDContext;
76+
user?: any;
77+
}
78+
79+
export interface SecureModeHashParams {
80+
context?: LDContext;
81+
user?: any;
82+
}
83+
84+
export interface EvaluationSeriesContext {
85+
flagKey: string;
86+
context: LDContext;
87+
defaultValue: unknown;
88+
method: string;
89+
}
90+
91+
export interface HookExecutionPayload {
92+
evaluationSeriesContext?: EvaluationSeriesContext;
93+
evaluationSeriesData?: Record<string, unknown>;
94+
evaluationDetail?: EvaluateFlagResponse;
95+
stage?: HookStage;
96+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { LDContext } from '@launchdarkly/js-client-sdk-common';
2+
3+
import {
4+
SDKConfigEventParams,
5+
SDKConfigHooksParams,
6+
SDKConfigPollingParams,
7+
SDKConfigProxyParams,
8+
SDKConfigServiceEndpointsParams,
9+
SDKConfigStreamingParams,
10+
SDKConfigTagsParams,
11+
SDKConfigTLSParams,
12+
SDKConfigWrapper,
13+
} from '../../types/ConfigParams';
14+
15+
// Re-export shared config types for convenience
16+
export type {
17+
SDKConfigTLSParams,
18+
SDKConfigServiceEndpointsParams,
19+
SDKConfigStreamingParams,
20+
SDKConfigPollingParams,
21+
SDKConfigEventParams,
22+
SDKConfigTagsParams,
23+
SDKConfigEvaluationHookData,
24+
SDKConfigHookInstance,
25+
SDKConfigHooksParams,
26+
SDKConfigProxyParams,
27+
SDKConfigWrapper,
28+
} from '../../types/ConfigParams';
29+
30+
export interface SDKConfigClientSideParams {
31+
initialContext?: LDContext;
32+
initialUser?: any;
33+
evaluationReasons?: boolean;
34+
useReport?: boolean;
35+
includeEnvironmentAttributes?: boolean;
36+
}
37+
38+
export interface SDKConfigParams {
39+
credential: string;
40+
startWaitTimeMs?: number; // UnixMillisecondTime
41+
initCanFail?: boolean;
42+
serviceEndpoints?: SDKConfigServiceEndpointsParams;
43+
tls?: SDKConfigTLSParams;
44+
streaming?: SDKConfigStreamingParams;
45+
polling?: SDKConfigPollingParams;
46+
events?: SDKConfigEventParams;
47+
tags?: SDKConfigTagsParams;
48+
clientSide?: SDKConfigClientSideParams;
49+
hooks?: SDKConfigHooksParams;
50+
wrapper?: SDKConfigWrapper;
51+
proxy?: SDKConfigProxyParams;
52+
}
53+
54+
export interface CreateInstanceParams {
55+
configuration: SDKConfigParams;
56+
tag: string;
57+
}

packages/tooling/contract-test-utils/src/client.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
// Re-export universal exports
2-
export * from './index';
1+
// Re-export shared base types (no SDK dependency)
2+
export * from './types/CommandParams';
3+
export * from './types/ConfigParams';
4+
5+
// Re-export client-specific types (uses @launchdarkly/js-client-sdk-common)
6+
export * from './client-side/types/CommandParams';
7+
export * from './client-side/types/ConfigParams';
8+
9+
// Re-export shared utilities
10+
export { makeLogger } from './logging/makeLogger';
11+
export { ClientPool } from './server-side/ClientPool';
312

413
// Client-side exports
514
export { default as ClientSideTestHook } from './client-side/TestHook';
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
// Universal exports (no SDK dependency)
2+
// These types have no references to LDContext or LDEvaluationReason.
3+
// SDK-specific types are exported from ./client and ./server subpaths.
24
export * from './types/CommandParams';
3-
export {
4-
type CreateInstanceParams,
5-
type SDKConfigParams,
6-
type SDKConfigTLSParams,
7-
type SDKConfigServiceEndpointsParams,
8-
type SDKConfigStreamingParams,
9-
type SDKConfigPollingParams,
10-
type SDKConfigEventParams,
11-
type SDKConfigTagsParams,
12-
type SDKConfigClientSideParams,
13-
type SDKConfigEvaluationHookData,
14-
type SDKConfigHookInstance,
15-
type SDKConfigHooksParams,
16-
type SDKConfigProxyParams,
17-
type SDKConfigWrapper,
18-
} from './types/ConfigParams';
5+
export * from './types/ConfigParams';
196
export { makeLogger } from './logging/makeLogger';
207
export { ClientPool } from './server-side/ClientPool';

0 commit comments

Comments
 (0)