Skip to content

Commit 3b02890

Browse files
committed
PR Feedback.
1 parent 0da9d31 commit 3b02890

File tree

10 files changed

+81
-86
lines changed

10 files changed

+81
-86
lines changed

packages/shared/sdk-client/src/DataManager.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ import { DataSourcePaths, StreamingProcessor } from './streaming';
2020
import { DeleteFlag, Flags, PatchFlag } from './types';
2121

2222
export interface DataManager {
23+
/**
24+
* This function handles the data management aspects of the identification process.
25+
*
26+
* @param identifyResolve Called to reject the identify operation.
27+
* @param identifyReject Called to complete the identify operation.
28+
* @param context The context being identified.
29+
* @param identifyOptions Options for identification.
30+
*/
2331
identify(
2432
identifyResolve: () => void,
2533
identifyReject: (err: Error) => void,
@@ -28,6 +36,9 @@ export interface DataManager {
2836
): Promise<void>;
2937
}
3038

39+
/**
40+
* Factory interface for constructing data managers.
41+
*/
3142
export interface DataManagerFactory {
3243
(
3344
flagManager: FlagManager,

packages/shared/sdk-client/src/IdentityProcessor.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/shared/sdk-client/src/LDClientImpl.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import {
2121
import { LDClient, type LDOptions } from './api';
2222
import { LDEvaluationDetail, LDEvaluationDetailTyped } from './api/LDEvaluationDetail';
2323
import { LDIdentifyOptions } from './api/LDIdentifyOptions';
24-
import ConfigurationImpl from './configuration';
25-
import { LDClientInternalOptions } from './configuration/Configuration';
24+
import { Configuration, ConfigurationImpl, LDClientInternalOptions } from './configuration';
2625
import { addAutoEnv } from './context/addAutoEnv';
2726
import { ensureKey } from './context/ensureKey';
2827
import { DataManager, DataManagerFactory } from './DataManager';
@@ -33,15 +32,15 @@ import {
3332
} from './evaluation/evaluationDetail';
3433
import createEventProcessor from './events/createEventProcessor';
3534
import EventFactory from './events/EventFactory';
36-
import DefaultFlagManager from './flag-manager/FlagManager';
35+
import DefaultFlagManager, { FlagManager } from './flag-manager/FlagManager';
3736
import { ItemDescriptor } from './flag-manager/ItemDescriptor';
3837
import LDEmitter, { EventName } from './LDEmitter';
3938
import { DeleteFlag, Flags, PatchFlag } from './types';
4039

4140
const { ClientMessages, ErrorKinds } = internal;
4241

4342
export default class LDClientImpl implements LDClient {
44-
private readonly config: ConfigurationImpl;
43+
private readonly config: Configuration;
4544
private uncheckedContext?: LDContext;
4645
private checkedContext?: Context;
4746
private readonly diagnosticsManager?: internal.DiagnosticsManager;
@@ -55,7 +54,7 @@ export default class LDClientImpl implements LDClient {
5554
private eventFactoryDefault = new EventFactory(false);
5655
private eventFactoryWithReasons = new EventFactory(true);
5756
private emitter: LDEmitter;
58-
private flagManager: DefaultFlagManager;
57+
private flagManager: FlagManager;
5958

6059
private eventSendingEnabled: boolean = false;
6160
private baseHeaders: LDHeaders;

packages/shared/sdk-client/src/configuration/Configuration.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ export interface Configuration {
5656
readonly trackEventModifier: (event: internal.InputCustomEvent) => internal.InputCustomEvent;
5757
}
5858

59-
export default class ConfigurationImpl implements Configuration {
60-
public static DEFAULT_POLLING = 'https://clientsdk.launchdarkly.com';
61-
public static DEFAULT_STREAM = 'https://clientstream.launchdarkly.com';
59+
const DEFAULT_POLLING: string = 'https://clientsdk.launchdarkly.com';
60+
const DEFAULT_STREAM: string = 'https://clientstream.launchdarkly.com';
61+
62+
export { DEFAULT_POLLING, DEFAULT_STREAM };
6263

64+
export default class ConfigurationImpl implements Configuration {
6365
public readonly logger: LDLogger = createSafeLogger();
6466

65-
public readonly baseUri = ConfigurationImpl.DEFAULT_POLLING;
67+
public readonly baseUri = DEFAULT_POLLING;
6668
public readonly eventsUri = ServiceEndpoints.DEFAULT_EVENTS;
67-
public readonly streamUri = ConfigurationImpl.DEFAULT_STREAM;
69+
public readonly streamUri = DEFAULT_STREAM;
6870

6971
public readonly maxCachedContexts = 5;
7072

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
import ConfigurationImpl from './Configuration';
1+
import ConfigurationImpl, {
2+
Configuration,
3+
DEFAULT_POLLING,
4+
DEFAULT_STREAM,
5+
LDClientInternalOptions,
6+
} from './Configuration';
27

3-
export default ConfigurationImpl;
8+
export {
9+
Configuration,
10+
ConfigurationImpl,
11+
LDClientInternalOptions,
12+
DEFAULT_POLLING,
13+
DEFAULT_STREAM,
14+
};

packages/shared/sdk-client/src/context/addAutoEnv.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
Platform,
1212
} from '@launchdarkly/js-sdk-common';
1313

14-
import ConfigurationImpl from '../configuration';
14+
import { Configuration } from '../configuration';
1515
import digest from '../crypto/digest';
1616
import { getOrGenerateKey } from '../storage/getOrGenerateKey';
1717
import { namespaceForGeneratedContextKey } from '../storage/namespaceUtils';
@@ -39,7 +39,7 @@ export const toMulti = (c: LDSingleKindContext) => {
3939
*/
4040
export const addApplicationInfo = async (
4141
{ crypto, info }: Platform,
42-
{ applicationInfo }: ConfigurationImpl,
42+
{ applicationInfo }: Configuration,
4343
): Promise<LDApplication | undefined> => {
4444
const { ld_application } = info.platformData();
4545
let app = deepCompact<LDApplication>(ld_application) ?? ({} as LDApplication);
@@ -103,11 +103,7 @@ export const addDeviceInfo = async (platform: Platform) => {
103103
return undefined;
104104
};
105105

106-
export const addAutoEnv = async (
107-
context: LDContext,
108-
platform: Platform,
109-
config: ConfigurationImpl,
110-
) => {
106+
export const addAutoEnv = async (context: LDContext, platform: Platform, config: Configuration) => {
111107
// LDUser is not supported for auto env reporting
112108
if (isLegacyUser(context)) {
113109
return context as LDUser;

packages/shared/sdk-client/src/diagnostics/createDiagnosticsInitConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { secondsToMillis, ServiceEndpoints } from '@launchdarkly/js-sdk-common';
22

3-
import ConfigurationImpl from '../configuration';
3+
import { Configuration, DEFAULT_POLLING, DEFAULT_STREAM } from '../configuration';
44

55
export type DiagnosticsInitConfig = {
66
// client & server common properties
@@ -17,9 +17,9 @@ export type DiagnosticsInitConfig = {
1717
usingSecureMode: boolean;
1818
bootstrapMode: boolean;
1919
};
20-
const createDiagnosticsInitConfig = (config: ConfigurationImpl): DiagnosticsInitConfig => ({
21-
customBaseURI: config.baseUri !== ConfigurationImpl.DEFAULT_POLLING,
22-
customStreamURI: config.streamUri !== ConfigurationImpl.DEFAULT_STREAM,
20+
const createDiagnosticsInitConfig = (config: Configuration): DiagnosticsInitConfig => ({
21+
customBaseURI: config.baseUri !== DEFAULT_POLLING,
22+
customStreamURI: config.streamUri !== DEFAULT_STREAM,
2323
customEventsURI: config.eventsUri !== ServiceEndpoints.DEFAULT_EVENTS,
2424
eventsCapacity: config.capacity,
2525
eventsFlushIntervalMillis: secondsToMillis(config.flushInterval),

packages/shared/sdk-client/src/diagnostics/createDiagnosticsManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { internal, Platform } from '@launchdarkly/js-sdk-common';
22

3-
import ConfigurationImpl from '../configuration';
3+
import { Configuration } from '../configuration';
44
import createDiagnosticsInitConfig from './createDiagnosticsInitConfig';
55

66
const createDiagnosticsManager = (
77
clientSideID: string,
8-
config: ConfigurationImpl,
8+
config: Configuration,
99
platform: Platform,
1010
) => {
1111
if (config.sendEvents && !config.diagnosticOptOut) {

packages/shared/sdk-client/src/events/createEventProcessor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ClientContext, internal, LDHeaders, Platform } from '@launchdarkly/js-sdk-common';
22

3-
import ConfigurationImpl from '../configuration';
3+
import { Configuration } from '../configuration';
44

55
const createEventProcessor = (
66
clientSideID: string,
7-
config: ConfigurationImpl,
7+
config: Configuration,
88
platform: Platform,
99
baseHeaders: LDHeaders,
1010
diagnosticsManager?: internal.DiagnosticsManager,

packages/shared/sdk-client/src/flag-manager/FlagManager.ts

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,51 @@ import { DefaultFlagStore } from './FlagStore';
66
import FlagUpdater, { FlagsChangeCallback } from './FlagUpdater';
77
import { ItemDescriptor } from './ItemDescriptor';
88

9+
/**
10+
* Top level manager of flags for the client. LDClient should be using this
11+
* interface and not any of the specific instances managed by it. Updates from
12+
* data sources should be directed to the [init] and [upsert] methods of this
13+
* interface.
14+
*/
915
export interface FlagManager {
16+
/**
17+
* Attempts to get a flag by key from the current flags.
18+
*/
1019
get(key: string): ItemDescriptor | undefined;
20+
21+
/**
22+
* Gets all the current flags.
23+
*/
1124
getAll(): { [key: string]: ItemDescriptor };
25+
26+
/**
27+
* Initializes the flag manager with data from a data source.
28+
* Persistence initialization is handled by {@link FlagPersistence}
29+
*/
1230
init(context: Context, newFlags: { [key: string]: ItemDescriptor }): Promise<void>;
31+
32+
/**
33+
* Attempt to update a flag. If the flag is for the wrong context, or
34+
* it is of an older version, then an update will not be performed.
35+
*/
1336
upsert(context: Context, key: string, item: ItemDescriptor): Promise<boolean>;
37+
38+
/**
39+
* Asynchronously load cached values from persistence.
40+
*/
1441
loadCached(context: Context): Promise<boolean>;
42+
43+
/**
44+
* Register a flag change callback.
45+
*/
1546
on(callback: FlagsChangeCallback): void;
47+
48+
/**
49+
* Unregister a flag change callback.
50+
*/
1651
off(callback: FlagsChangeCallback): void;
1752
}
1853

19-
/**
20-
* Top level manager of flags for the client. LDClient should be using this
21-
* class and not any of the specific instances managed by it. Updates from
22-
* data sources should be directed to the [init] and [upsert] methods of this
23-
* class.
24-
*/
2554
export default class DefaultFlagManager implements FlagManager {
2655
private flagStore = new DefaultFlagStore();
2756
private flagUpdater: FlagUpdater;
@@ -71,53 +100,30 @@ export default class DefaultFlagManager implements FlagManager {
71100
);
72101
}
73102

74-
/**
75-
* Attempts to get a flag by key from the current flags.
76-
*/
77103
get(key: string): ItemDescriptor | undefined {
78104
return this.flagStore.get(key);
79105
}
80106

81-
/**
82-
* Gets all the current flags.
83-
*/
84107
getAll(): { [key: string]: ItemDescriptor } {
85108
return this.flagStore.getAll();
86109
}
87110

88-
/**
89-
* Initializes the flag manager with data from a data source.
90-
* Persistence initialization is handled by {@link FlagPersistence}
91-
*/
92111
async init(context: Context, newFlags: { [key: string]: ItemDescriptor }): Promise<void> {
93112
return (await this.flagPersistencePromise).init(context, newFlags);
94113
}
95114

96-
/**
97-
* Attempt to update a flag. If the flag is for the wrong context, or
98-
* it is of an older version, then an update will not be performed.
99-
*/
100115
async upsert(context: Context, key: string, item: ItemDescriptor): Promise<boolean> {
101116
return (await this.flagPersistencePromise).upsert(context, key, item);
102117
}
103118

104-
/**
105-
* Asynchronously load cached values from persistence.
106-
*/
107119
async loadCached(context: Context): Promise<boolean> {
108120
return (await this.flagPersistencePromise).loadCached(context);
109121
}
110122

111-
/**
112-
* Register a flag change callback.
113-
*/
114123
on(callback: FlagsChangeCallback): void {
115124
this.flagUpdater.on(callback);
116125
}
117126

118-
/**
119-
* Unregister a flag change callback.
120-
*/
121127
off(callback: FlagsChangeCallback): void {
122128
this.flagUpdater.off(callback);
123129
}

0 commit comments

Comments
 (0)