Skip to content

Commit 7419408

Browse files
committed
Update index.d.ts to support various modules
1 parent 06b6ada commit 7419408

File tree

1 file changed

+65
-68
lines changed

1 file changed

+65
-68
lines changed

packages/optimizely-sdk/lib/index.d.ts

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
18-
19-
declare module '@optimizely/optimizely-sdk' {
20-
export namespace enums {
21-
export enum LOG_LEVEL {
22-
NOTSET = 0,
23-
DEBUG = 1,
24-
INFO = 2,
25-
WARNING = 3,
26-
ERROR = 4,
27-
}
28-
29-
export enum NOTIFICATION_TYPES {
30-
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
31-
DECISION = 'DECISION:type, userId, attributes, decisionInfo',
32-
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
33-
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
34-
}
35-
}
36-
37-
export namespace logging {
38-
export interface LoggerConfig {
39-
logLevel?: enums.LOG_LEVEL;
40-
logToConsole?: boolean;
41-
prefix?: string;
42-
}
43-
export interface Logger {
44-
log: (logLevel: enums.LOG_LEVEL, message: string) => void;
45-
}
46-
export function createLogger(config: LoggerConfig): Logger;
47-
export function createNoOpLogger(): Logger;
48-
}
17+
declare module "@optimizely/optimizely-sdk" {
18+
import { LogHandler, ErrorHandler } from "@optimizely/js-sdk-logging";
19+
import * as enums from "@optimizely/optimizely-sdk/lib/utils/enums";
20+
import * as logging from "@optimizely/optimizely-sdk/lib/plugins/logger";
21+
export { enums, logging };
4922

5023
export function setLogger(logger: LogHandler | null): void;
5124

@@ -67,9 +40,9 @@ declare module '@optimizely/optimizely-sdk' {
6740
export interface Config {
6841
datafile?: object | string;
6942
datafileOptions?: DatafileOptions;
70-
errorHandler?: object;
71-
eventDispatcher?: object;
72-
logger?: object;
43+
errorHandler?: ErrorHandler;
44+
eventDispatcher?: EventDispatcher;
45+
logger?: LogHandler;
7346
logLevel?:
7447
| enums.LOG_LEVEL.DEBUG
7548
| enums.LOG_LEVEL.ERROR
@@ -86,12 +59,33 @@ declare module '@optimizely/optimizely-sdk' {
8659

8760
export interface Client {
8861
notificationCenter: NotificationCenter;
89-
activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null;
90-
track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void;
91-
getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null;
92-
setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean;
62+
activate(
63+
experimentKey: string,
64+
userId: string,
65+
attributes?: UserAttributes
66+
): string | null;
67+
track(
68+
eventKey: string,
69+
userId: string,
70+
attributes?: UserAttributes,
71+
eventTags?: EventTags
72+
): void;
73+
getVariation(
74+
experimentKey: string,
75+
userId: string,
76+
attributes?: UserAttributes
77+
): string | null;
78+
setForcedVariation(
79+
experimentKey: string,
80+
userId: string,
81+
variationKey: string | null
82+
): boolean;
9383
getForcedVariation(experimentKey: string, userId: string): string | null;
94-
isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean;
84+
isFeatureEnabled(
85+
featureKey: string,
86+
userId: string,
87+
attributes?: UserAttributes
88+
): boolean;
9589
getEnabledFeatures(userId: string, attributes?: UserAttributes): string[];
9690
getFeatureVariableBoolean(
9791
featureKey: string,
@@ -117,7 +111,9 @@ declare module '@optimizely/optimizely-sdk' {
117111
userId: string,
118112
attributes?: UserAttributes
119113
): string | null;
120-
onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>;
114+
onReady(options?: {
115+
timeout?: number;
116+
}): Promise<{ success: boolean; reason?: string }>;
121117
close(): void;
122118
}
123119

@@ -127,7 +123,7 @@ declare module '@optimizely/optimizely-sdk' {
127123
// URL to which to send the HTTP request.
128124
url: string;
129125
// HTTP method with which to send the event.
130-
httpVerb: 'POST';
126+
httpVerb: "POST";
131127
// Value to send in the request body, JSON-serialized.
132128
params: any;
133129
}
@@ -156,10 +152,14 @@ declare module '@optimizely/optimizely-sdk' {
156152
): number;
157153
removeNotificationListener(listenerId: number): boolean;
158154
clearAllNotificationListeners(): void;
159-
clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void;
155+
clearNotificationListeners(
156+
notificationType: enums.NOTIFICATION_TYPES
157+
): void;
160158
}
161159

162-
export type NotificationListener<T extends ListenerPayload> = (notificationData: T) => void;
160+
export type NotificationListener<T extends ListenerPayload> = (
161+
notificationData: T
162+
) => void;
163163

164164
export interface ListenerPayload {
165165
userId: string;
@@ -216,37 +216,34 @@ declare module '@optimizely/optimizely-sdk' {
216216
}
217217
}
218218

219-
declare module '@optimizely/optimizely-sdk/lib/utils/enums' {
220-
export enum LOG_LEVEL {
221-
NOTSET = 0,
222-
DEBUG = 1,
223-
INFO = 2,
224-
WARNING = 3,
225-
ERROR = 4,
226-
}
219+
declare module "@optimizely/optimizely-sdk/lib/utils/enums" {
220+
import { LogLevel } from "@optimizely/js-sdk-logging";
221+
222+
export { LogLevel as LOG_LEVEL };
227223

228224
export enum NOTIFICATION_TYPES {
229-
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
230-
DECISION = 'DECISION:type, userId, attributes, decisionInfo',
231-
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
232-
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
225+
ACTIVATE = "ACTIVATE:experiment, user_id,attributes, variation, event",
226+
DECISION = "DECISION:type, userId, attributes, decisionInfo",
227+
OPTIMIZELY_CONFIG_UPDATE = "OPTIMIZELY_CONFIG_UPDATE",
228+
TRACK = "TRACK:event_key, user_id, attributes, event_tags, event"
233229
}
234230
}
235231

236-
declare module '@optimizely/optimizely-sdk/lib/plugins/logger' {
237-
import * as Optimizely from '@optimizely/optimizely-sdk'
238-
239-
export function createLogger(config: Optimizely.logging.LoggerConfig): Optimizely.logging.Logger;
240-
export function createNoOpLogger(): Optimizely.logging.Logger;
241-
}
242-
243-
declare module '@optimizely/optimizely-sdk/lib/plugins/event_dispatcher/index.node.js' {
232+
declare module "@optimizely/optimizely-sdk/lib/plugins/logger" {
233+
import * as enums from "@optimizely/optimizely-sdk/lib/utils/enums";
234+
import { LogHandler } from "@optimizely/js-sdk-logging";
244235

236+
export interface LoggerConfig {
237+
logLevel?: enums.LOG_LEVEL;
238+
logToConsole?: boolean;
239+
prefix?: string;
240+
}
241+
export function createLogger(config?: LoggerConfig): LogHandler;
242+
export function createNoOpLogger(): LogHandler;
245243
}
246244

247-
declare module '@optimizely/optimizely-sdk/lib/utils/json_schema_validator' {
245+
declare module "@optimizely/optimizely-sdk/lib/plugins/event_dispatcher" {}
248246

249-
}
247+
declare module "@optimizely/optimizely-sdk/lib/utils/json_schema_validator" {}
250248

251-
declare module '@optimizely/optimizely-sdk/lib/plugins/error_handler' {
252-
}
249+
declare module "@optimizely/optimizely-sdk/lib/plugins/error_handler" {}

0 commit comments

Comments
 (0)