From 42cc5b4b8d55891dd55ace0142c21d478a3b25fc Mon Sep 17 00:00:00 2001 From: jordangarcia Date: Thu, 23 May 2019 12:08:49 -0700 Subject: [PATCH 1/3] Update index.d.ts file Remove declaring multiple files, this appeared to not be working in the first place. Add logging / errorHandler / eventDispatcher and other top level types Fix the `onReady()` signature to include the proper promise resolved value --- packages/optimizely-sdk/lib/index.d.ts | 401 +++++++++++++------------ 1 file changed, 214 insertions(+), 187 deletions(-) diff --git a/packages/optimizely-sdk/lib/index.d.ts b/packages/optimizely-sdk/lib/index.d.ts index 62b65f104..fb39845f3 100644 --- a/packages/optimizely-sdk/lib/index.d.ts +++ b/packages/optimizely-sdk/lib/index.d.ts @@ -1,5 +1,5 @@ /** - * Copyright 2018, Optimizely + * Copyright 2018-2019, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,198 +14,225 @@ * limitations under the License. */ -declare module '@optimizely/optimizely-sdk' { - export namespace enums { - enum LOG_LEVEL { - NOTSET = 0, - DEBUG = 1, - INFO = 2, - WARNING = 3, - ERROR = 4, - } - - enum NOTIFICATION_TYPES { - ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', - DECISION = 'DECISION:type, userId, attributes, decisionInfo', - OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', - TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', - } - } - - export function createInstance(config: Config): Client; - - interface DatafileOptions { - autoUpdate?: boolean; - updateInterval?: number; - urlTemplate?: string; - } - - // The options object given to Optimizely.createInstance. - export interface Config { - datafile?: object | string; - datafileOptions?: DatafileOptions, - errorHandler?: object; - eventDispatcher?: object; - logger?: object; - logLevel?: enums.LOG_LEVEL.DEBUG | enums.LOG_LEVEL.ERROR | enums.LOG_LEVEL.INFO | enums.LOG_LEVEL.NOTSET | enums.LOG_LEVEL.WARNING; - skipJSONValidation?: boolean; - jsonSchemaValidator?: object; - userProfileService?: UserProfileService | null; - eventBatchSize?: number - eventFlushInterval?: number - sdkKey?: string; - } - - export interface Client { - notificationCenter: NotificationCenter; - activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; - track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void; - getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; - setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean; - getForcedVariation(experimentKey: string, userId: string): string | null; - isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean; - getEnabledFeatures(userId: string, attributes?: UserAttributes): string[]; - getFeatureVariableBoolean(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): boolean | null; - getFeatureVariableDouble(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): number | null; - getFeatureVariableInteger(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): number | null; - getFeatureVariableString(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): string | null; - onReady(options?: { timeout?: number }): Promise - close(): void - } - - // An event to be submitted to Optimizely, enabling tracking the reach and impact of - // tests and feature rollouts. - export interface Event { - // URL to which to send the HTTP request. - url: string, - // HTTP method with which to send the event. - httpVerb: 'POST', - // Value to send in the request body, JSON-serialized. - params: any, - } - - export interface EventDispatcher { - /** - * @param event - * Event being submitted for eventual dispatch. - * @param callback - * After the event has at least been queued for dispatch, call this function to return - * control back to the Client. - */ - dispatchEvent: (event: Event, callback: () => void) => void, - } - - export interface UserProfileService { - lookup: (userId: string) => UserProfile, - save: (profile: UserProfile) => void, - } - - // NotificationCenter-related types - export interface NotificationCenter { - addNotificationListener(notificationType: string, callback: NotificationListener): number; - removeNotificationListener(listenerId: number): boolean; - clearAllNotificationListeners(): void; - clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void; - } - - export type NotificationListener = (notificationData: T) => void; - - export interface ListenerPayload { - userId: string; - attributes: UserAttributes; - } - - export interface ActivateListenerPayload extends ListenerPayload { - experiment: Experiment; - variation: Variation; - logEvent: Event; - } +import { LogHandler, setLogHandler, ErrorHandler } from '@optimizely/js-sdk-logging' - export type UserAttributes = { - [name: string]: string - }; - - export type EventTags = { - [key: string]: string | number | boolean, - }; - - export interface TrackListenerPayload extends ListenerPayload { - eventKey: string; - eventTags: EventTags; - logEvent: Event; - } - - interface Experiment { - id: string, - key: string, - status: string, - layerId: string, - variations: Variation[], - trafficAllocation: Array<{ - entityId: string, - endOfRange: number, - }>, - audienceIds: string[], - forcedVariations: object, - } - - interface Variation { - id: string, - key: string, - } - - export interface Logger { - log: (logLevel: enums.LOG_LEVEL, message: string) => void, - } - - // Information about past bucketing decisions for a user. - export interface UserProfile { - user_id: string, - experiment_bucket_map: { - [experiment_id: string]: { - variation_id: string, - }, - }, - } +export namespace enums { + export enum LOG_LEVEL { + NOTSET = 0, + DEBUG = 1, + INFO = 2, + WARNING = 3, + ERROR = 4, } - declare module '@optimizely/optimizely-sdk/lib/utils/enums'{ - export enum LOG_LEVEL { - NOTSET = 0, - DEBUG = 1, - INFO = 2, - WARNING = 3, - ERROR = 4, - } - - export enum NOTIFICATION_TYPES { - ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', - DECISION = 'DECISION:type, userId, attributes, decisionInfo', - OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', - TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', - } - } - - declare module '@optimizely/optimizely-sdk/lib/plugins/event_dispatcher/index.node.js' { - + export enum NOTIFICATION_TYPES { + ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', + DECISION = 'DECISION:type, userId, attributes, decisionInfo', + OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', + TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', } +} - declare module '@optimizely/optimizely-sdk/lib/utils/json_schema_validator' { - +export namespace logging { + export interface LoggerConfig { + logLevel?: enums.LOG_LEVEL + logToConsole?: boolean + prefix?: string } - - declare module '@optimizely/optimizely-sdk/lib/plugins/error_handler' { + export interface Logger { + log: (logLevel: enums.LOG_LEVEL, message: string) => void } - - declare module '@optimizely/optimizely-sdk/lib/plugins/logger' { - import * as Optimizely from '@optimizely/optimizely-sdk'; - import * as enums from '@optimizely/optimizely-sdk/lib/utils/enums'; - - export interface Config { - logLevel?: enums.LOG_LEVEL, - logToConsole?: boolean, - prefix?: string, + export function createLogger(config: LoggerConfig): Logger + export function createNoOpLogger(): Logger +} + +export function setLogger(logger: LogHandler | null): void + +export function setLogLevel(level: enums.LOG_LEVEL | string): void + +export function createInstance(config: Config): Client + +export const errorHandler: ErrorHandler + +export const eventDispatcher: EventDispatcher + +interface DatafileOptions { + autoUpdate?: boolean + updateInterval?: number + urlTemplate?: string +} + +// The options object given to Optimizely.createInstance. +export interface Config { + datafile?: object | string + datafileOptions?: DatafileOptions + errorHandler?: object + eventDispatcher?: object + logger?: object + logLevel?: + | enums.LOG_LEVEL.DEBUG + | enums.LOG_LEVEL.ERROR + | enums.LOG_LEVEL.INFO + | enums.LOG_LEVEL.NOTSET + | enums.LOG_LEVEL.WARNING + skipJSONValidation?: boolean + jsonSchemaValidator?: object + userProfileService?: UserProfileService | null + eventBatchSize?: number + eventFlushInterval?: number + sdkKey?: string +} + +export interface Client { + notificationCenter: NotificationCenter + activate( + experimentKey: string, + userId: string, + attributes?: UserAttributes, + ): string | null + track( + eventKey: string, + userId: string, + attributes?: UserAttributes, + eventTags?: EventTags, + ): void + getVariation( + experimentKey: string, + userId: string, + attributes?: UserAttributes, + ): string | null + setForcedVariation( + experimentKey: string, + userId: string, + variationKey: string | null, + ): boolean + getForcedVariation(experimentKey: string, userId: string): string | null + isFeatureEnabled( + featureKey: string, + userId: string, + attributes?: UserAttributes, + ): boolean + getEnabledFeatures(userId: string, attributes?: UserAttributes): string[] + getFeatureVariableBoolean( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes, + ): boolean | null + getFeatureVariableDouble( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes, + ): number | null + getFeatureVariableInteger( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes, + ): number | null + getFeatureVariableString( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes, + ): string | null + onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }> + close(): void +} + +// An event to be submitted to Optimizely, enabling tracking the reach and impact of +// tests and feature rollouts. +export interface Event { + // URL to which to send the HTTP request. + url: string + // HTTP method with which to send the event. + httpVerb: 'POST' + // Value to send in the request body, JSON-serialized. + params: any +} + +export interface EventDispatcher { + /** + * @param event + * Event being submitted for eventual dispatch. + * @param callback + * After the event has at least been queued for dispatch, call this function to return + * control back to the Client. + */ + dispatchEvent: (event: Event, callback: () => void) => void +} + +export interface UserProfileService { + lookup: (userId: string) => UserProfile + save: (profile: UserProfile) => void +} + +// NotificationCenter-related types +export interface NotificationCenter { + addNotificationListener( + notificationType: string, + callback: NotificationListener, + ): number + removeNotificationListener(listenerId: number): boolean + clearAllNotificationListeners(): void + clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void +} + +export type NotificationListener = ( + notificationData: T, +) => void + +export interface ListenerPayload { + userId: string + attributes: UserAttributes +} + +export interface ActivateListenerPayload extends ListenerPayload { + experiment: Experiment + variation: Variation + logEvent: Event +} + +export type UserAttributes = { + [name: string]: any +} + +export type EventTags = { + [key: string]: string | number | boolean +} + +export interface TrackListenerPayload extends ListenerPayload { + eventKey: string + eventTags: EventTags + logEvent: Event +} + +interface Experiment { + id: string + key: string + status: string + layerId: string + variations: Variation[] + trafficAllocation: Array<{ + entityId: string + endOfRange: number + }> + audienceIds: string[] + forcedVariations: object +} + +interface Variation { + id: string + key: string +} + +// Information about past bucketing decisions for a user. +export interface UserProfile { + user_id: string + experiment_bucket_map: { + [experiment_id: string]: { + variation_id: string } - export function createLogger(config: Config): Optimizely.Logger; - export function createNoOpLogger(): Optimizely.Logger; } +} From 06b6ada3ce6bcbcf3861ee2479b800bb4b4044e2 Mon Sep 17 00:00:00 2001 From: jordangarcia Date: Fri, 24 May 2019 10:52:25 -0700 Subject: [PATCH 2/3] Update index.d.ts to include other modules again --- packages/optimizely-sdk/lib/index.d.ts | 392 +++++++++++++------------ 1 file changed, 203 insertions(+), 189 deletions(-) diff --git a/packages/optimizely-sdk/lib/index.d.ts b/packages/optimizely-sdk/lib/index.d.ts index fb39845f3..030d81257 100644 --- a/packages/optimizely-sdk/lib/index.d.ts +++ b/packages/optimizely-sdk/lib/index.d.ts @@ -14,225 +14,239 @@ * limitations under the License. */ -import { LogHandler, setLogHandler, ErrorHandler } from '@optimizely/js-sdk-logging' +import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging'; + +declare module '@optimizely/optimizely-sdk' { + export namespace enums { + export enum LOG_LEVEL { + NOTSET = 0, + DEBUG = 1, + INFO = 2, + WARNING = 3, + ERROR = 4, + } -export namespace enums { - export enum LOG_LEVEL { - NOTSET = 0, - DEBUG = 1, - INFO = 2, - WARNING = 3, - ERROR = 4, + export enum NOTIFICATION_TYPES { + ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', + DECISION = 'DECISION:type, userId, attributes, decisionInfo', + OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', + TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', + } } - export enum NOTIFICATION_TYPES { - ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', - DECISION = 'DECISION:type, userId, attributes, decisionInfo', - OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', - TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', + export namespace logging { + export interface LoggerConfig { + logLevel?: enums.LOG_LEVEL; + logToConsole?: boolean; + prefix?: string; + } + export interface Logger { + log: (logLevel: enums.LOG_LEVEL, message: string) => void; + } + export function createLogger(config: LoggerConfig): Logger; + export function createNoOpLogger(): Logger; } -} -export namespace logging { - export interface LoggerConfig { - logLevel?: enums.LOG_LEVEL - logToConsole?: boolean - prefix?: string + export function setLogger(logger: LogHandler | null): void; + + export function setLogLevel(level: enums.LOG_LEVEL | string): void; + + export function createInstance(config: Config): Client; + + export const errorHandler: ErrorHandler; + + export const eventDispatcher: EventDispatcher; + + interface DatafileOptions { + autoUpdate?: boolean; + updateInterval?: number; + urlTemplate?: string; } - export interface Logger { - log: (logLevel: enums.LOG_LEVEL, message: string) => void + + // The options object given to Optimizely.createInstance. + export interface Config { + datafile?: object | string; + datafileOptions?: DatafileOptions; + errorHandler?: object; + eventDispatcher?: object; + logger?: object; + logLevel?: + | enums.LOG_LEVEL.DEBUG + | enums.LOG_LEVEL.ERROR + | enums.LOG_LEVEL.INFO + | enums.LOG_LEVEL.NOTSET + | enums.LOG_LEVEL.WARNING; + skipJSONValidation?: boolean; + jsonSchemaValidator?: object; + userProfileService?: UserProfileService | null; + eventBatchSize?: number; + eventFlushInterval?: number; + sdkKey?: string; } - export function createLogger(config: LoggerConfig): Logger - export function createNoOpLogger(): Logger -} -export function setLogger(logger: LogHandler | null): void + export interface Client { + notificationCenter: NotificationCenter; + activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; + track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void; + getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; + setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean; + getForcedVariation(experimentKey: string, userId: string): string | null; + isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean; + getEnabledFeatures(userId: string, attributes?: UserAttributes): string[]; + getFeatureVariableBoolean( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): boolean | null; + getFeatureVariableDouble( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): number | null; + getFeatureVariableInteger( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): number | null; + getFeatureVariableString( + featureKey: string, + variableKey: string, + userId: string, + attributes?: UserAttributes + ): string | null; + onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>; + close(): void; + } -export function setLogLevel(level: enums.LOG_LEVEL | string): void + // An event to be submitted to Optimizely, enabling tracking the reach and impact of + // tests and feature rollouts. + export interface Event { + // URL to which to send the HTTP request. + url: string; + // HTTP method with which to send the event. + httpVerb: 'POST'; + // Value to send in the request body, JSON-serialized. + params: any; + } -export function createInstance(config: Config): Client + export interface EventDispatcher { + /** + * @param event + * Event being submitted for eventual dispatch. + * @param callback + * After the event has at least been queued for dispatch, call this function to return + * control back to the Client. + */ + dispatchEvent: (event: Event, callback: () => void) => void; + } -export const errorHandler: ErrorHandler + export interface UserProfileService { + lookup: (userId: string) => UserProfile; + save: (profile: UserProfile) => void; + } -export const eventDispatcher: EventDispatcher + // NotificationCenter-related types + export interface NotificationCenter { + addNotificationListener( + notificationType: string, + callback: NotificationListener + ): number; + removeNotificationListener(listenerId: number): boolean; + clearAllNotificationListeners(): void; + clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void; + } -interface DatafileOptions { - autoUpdate?: boolean - updateInterval?: number - urlTemplate?: string -} + export type NotificationListener = (notificationData: T) => void; -// The options object given to Optimizely.createInstance. -export interface Config { - datafile?: object | string - datafileOptions?: DatafileOptions - errorHandler?: object - eventDispatcher?: object - logger?: object - logLevel?: - | enums.LOG_LEVEL.DEBUG - | enums.LOG_LEVEL.ERROR - | enums.LOG_LEVEL.INFO - | enums.LOG_LEVEL.NOTSET - | enums.LOG_LEVEL.WARNING - skipJSONValidation?: boolean - jsonSchemaValidator?: object - userProfileService?: UserProfileService | null - eventBatchSize?: number - eventFlushInterval?: number - sdkKey?: string -} + export interface ListenerPayload { + userId: string; + attributes: UserAttributes; + } -export interface Client { - notificationCenter: NotificationCenter - activate( - experimentKey: string, - userId: string, - attributes?: UserAttributes, - ): string | null - track( - eventKey: string, - userId: string, - attributes?: UserAttributes, - eventTags?: EventTags, - ): void - getVariation( - experimentKey: string, - userId: string, - attributes?: UserAttributes, - ): string | null - setForcedVariation( - experimentKey: string, - userId: string, - variationKey: string | null, - ): boolean - getForcedVariation(experimentKey: string, userId: string): string | null - isFeatureEnabled( - featureKey: string, - userId: string, - attributes?: UserAttributes, - ): boolean - getEnabledFeatures(userId: string, attributes?: UserAttributes): string[] - getFeatureVariableBoolean( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes, - ): boolean | null - getFeatureVariableDouble( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes, - ): number | null - getFeatureVariableInteger( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes, - ): number | null - getFeatureVariableString( - featureKey: string, - variableKey: string, - userId: string, - attributes?: UserAttributes, - ): string | null - onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }> - close(): void -} + export interface ActivateListenerPayload extends ListenerPayload { + experiment: Experiment; + variation: Variation; + logEvent: Event; + } -// An event to be submitted to Optimizely, enabling tracking the reach and impact of -// tests and feature rollouts. -export interface Event { - // URL to which to send the HTTP request. - url: string - // HTTP method with which to send the event. - httpVerb: 'POST' - // Value to send in the request body, JSON-serialized. - params: any -} + export type UserAttributes = { + [name: string]: any; + }; -export interface EventDispatcher { - /** - * @param event - * Event being submitted for eventual dispatch. - * @param callback - * After the event has at least been queued for dispatch, call this function to return - * control back to the Client. - */ - dispatchEvent: (event: Event, callback: () => void) => void -} + export type EventTags = { + [key: string]: string | number | boolean; + }; -export interface UserProfileService { - lookup: (userId: string) => UserProfile - save: (profile: UserProfile) => void -} + export interface TrackListenerPayload extends ListenerPayload { + eventKey: string; + eventTags: EventTags; + logEvent: Event; + } -// NotificationCenter-related types -export interface NotificationCenter { - addNotificationListener( - notificationType: string, - callback: NotificationListener, - ): number - removeNotificationListener(listenerId: number): boolean - clearAllNotificationListeners(): void - clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void -} + interface Experiment { + id: string; + key: string; + status: string; + layerId: string; + variations: Variation[]; + trafficAllocation: Array<{ + entityId: string; + endOfRange: number; + }>; + audienceIds: string[]; + forcedVariations: object; + } -export type NotificationListener = ( - notificationData: T, -) => void + interface Variation { + id: string; + key: string; + } -export interface ListenerPayload { - userId: string - attributes: UserAttributes + // Information about past bucketing decisions for a user. + export interface UserProfile { + user_id: string; + experiment_bucket_map: { + [experiment_id: string]: { + variation_id: string; + }; + }; + } } -export interface ActivateListenerPayload extends ListenerPayload { - experiment: Experiment - variation: Variation - logEvent: Event -} +declare module '@optimizely/optimizely-sdk/lib/utils/enums' { + export enum LOG_LEVEL { + NOTSET = 0, + DEBUG = 1, + INFO = 2, + WARNING = 3, + ERROR = 4, + } -export type UserAttributes = { - [name: string]: any + export enum NOTIFICATION_TYPES { + ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', + DECISION = 'DECISION:type, userId, attributes, decisionInfo', + OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', + TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', + } } -export type EventTags = { - [key: string]: string | number | boolean -} +declare module '@optimizely/optimizely-sdk/lib/plugins/logger' { + import * as Optimizely from '@optimizely/optimizely-sdk' -export interface TrackListenerPayload extends ListenerPayload { - eventKey: string - eventTags: EventTags - logEvent: Event + export function createLogger(config: Optimizely.logging.LoggerConfig): Optimizely.logging.Logger; + export function createNoOpLogger(): Optimizely.logging.Logger; } -interface Experiment { - id: string - key: string - status: string - layerId: string - variations: Variation[] - trafficAllocation: Array<{ - entityId: string - endOfRange: number - }> - audienceIds: string[] - forcedVariations: object -} +declare module '@optimizely/optimizely-sdk/lib/plugins/event_dispatcher/index.node.js' { -interface Variation { - id: string - key: string } -// Information about past bucketing decisions for a user. -export interface UserProfile { - user_id: string - experiment_bucket_map: { - [experiment_id: string]: { - variation_id: string - } - } +declare module '@optimizely/optimizely-sdk/lib/utils/json_schema_validator' { + } + +declare module '@optimizely/optimizely-sdk/lib/plugins/error_handler' { +} \ No newline at end of file From 74194080923f435aa5929a3294a3de67db6237c9 Mon Sep 17 00:00:00 2001 From: jordangarcia Date: Fri, 24 May 2019 11:33:50 -0700 Subject: [PATCH 3/3] Update index.d.ts to support various modules --- packages/optimizely-sdk/lib/index.d.ts | 133 ++++++++++++------------- 1 file changed, 65 insertions(+), 68 deletions(-) diff --git a/packages/optimizely-sdk/lib/index.d.ts b/packages/optimizely-sdk/lib/index.d.ts index 030d81257..a4264c36c 100644 --- a/packages/optimizely-sdk/lib/index.d.ts +++ b/packages/optimizely-sdk/lib/index.d.ts @@ -14,38 +14,11 @@ * limitations under the License. */ -import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging'; - -declare module '@optimizely/optimizely-sdk' { - export namespace enums { - export enum LOG_LEVEL { - NOTSET = 0, - DEBUG = 1, - INFO = 2, - WARNING = 3, - ERROR = 4, - } - - export enum NOTIFICATION_TYPES { - ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', - DECISION = 'DECISION:type, userId, attributes, decisionInfo', - OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', - TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', - } - } - - export namespace logging { - export interface LoggerConfig { - logLevel?: enums.LOG_LEVEL; - logToConsole?: boolean; - prefix?: string; - } - export interface Logger { - log: (logLevel: enums.LOG_LEVEL, message: string) => void; - } - export function createLogger(config: LoggerConfig): Logger; - export function createNoOpLogger(): Logger; - } +declare module "@optimizely/optimizely-sdk" { + import { LogHandler, ErrorHandler } from "@optimizely/js-sdk-logging"; + import * as enums from "@optimizely/optimizely-sdk/lib/utils/enums"; + import * as logging from "@optimizely/optimizely-sdk/lib/plugins/logger"; + export { enums, logging }; export function setLogger(logger: LogHandler | null): void; @@ -67,9 +40,9 @@ declare module '@optimizely/optimizely-sdk' { export interface Config { datafile?: object | string; datafileOptions?: DatafileOptions; - errorHandler?: object; - eventDispatcher?: object; - logger?: object; + errorHandler?: ErrorHandler; + eventDispatcher?: EventDispatcher; + logger?: LogHandler; logLevel?: | enums.LOG_LEVEL.DEBUG | enums.LOG_LEVEL.ERROR @@ -86,12 +59,33 @@ declare module '@optimizely/optimizely-sdk' { export interface Client { notificationCenter: NotificationCenter; - activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; - track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void; - getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null; - setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean; + activate( + experimentKey: string, + userId: string, + attributes?: UserAttributes + ): string | null; + track( + eventKey: string, + userId: string, + attributes?: UserAttributes, + eventTags?: EventTags + ): void; + getVariation( + experimentKey: string, + userId: string, + attributes?: UserAttributes + ): string | null; + setForcedVariation( + experimentKey: string, + userId: string, + variationKey: string | null + ): boolean; getForcedVariation(experimentKey: string, userId: string): string | null; - isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean; + isFeatureEnabled( + featureKey: string, + userId: string, + attributes?: UserAttributes + ): boolean; getEnabledFeatures(userId: string, attributes?: UserAttributes): string[]; getFeatureVariableBoolean( featureKey: string, @@ -117,7 +111,9 @@ declare module '@optimizely/optimizely-sdk' { userId: string, attributes?: UserAttributes ): string | null; - onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>; + onReady(options?: { + timeout?: number; + }): Promise<{ success: boolean; reason?: string }>; close(): void; } @@ -127,7 +123,7 @@ declare module '@optimizely/optimizely-sdk' { // URL to which to send the HTTP request. url: string; // HTTP method with which to send the event. - httpVerb: 'POST'; + httpVerb: "POST"; // Value to send in the request body, JSON-serialized. params: any; } @@ -156,10 +152,14 @@ declare module '@optimizely/optimizely-sdk' { ): number; removeNotificationListener(listenerId: number): boolean; clearAllNotificationListeners(): void; - clearNotificationListeners(notificationType: enums.NOTIFICATION_TYPES): void; + clearNotificationListeners( + notificationType: enums.NOTIFICATION_TYPES + ): void; } - export type NotificationListener = (notificationData: T) => void; + export type NotificationListener = ( + notificationData: T + ) => void; export interface ListenerPayload { userId: string; @@ -216,37 +216,34 @@ declare module '@optimizely/optimizely-sdk' { } } -declare module '@optimizely/optimizely-sdk/lib/utils/enums' { - export enum LOG_LEVEL { - NOTSET = 0, - DEBUG = 1, - INFO = 2, - WARNING = 3, - ERROR = 4, - } +declare module "@optimizely/optimizely-sdk/lib/utils/enums" { + import { LogLevel } from "@optimizely/js-sdk-logging"; + + export { LogLevel as LOG_LEVEL }; export enum NOTIFICATION_TYPES { - ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event', - DECISION = 'DECISION:type, userId, attributes, decisionInfo', - OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', - TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', + ACTIVATE = "ACTIVATE:experiment, user_id,attributes, variation, event", + DECISION = "DECISION:type, userId, attributes, decisionInfo", + OPTIMIZELY_CONFIG_UPDATE = "OPTIMIZELY_CONFIG_UPDATE", + TRACK = "TRACK:event_key, user_id, attributes, event_tags, event" } } -declare module '@optimizely/optimizely-sdk/lib/plugins/logger' { - import * as Optimizely from '@optimizely/optimizely-sdk' - - export function createLogger(config: Optimizely.logging.LoggerConfig): Optimizely.logging.Logger; - export function createNoOpLogger(): Optimizely.logging.Logger; -} - -declare module '@optimizely/optimizely-sdk/lib/plugins/event_dispatcher/index.node.js' { +declare module "@optimizely/optimizely-sdk/lib/plugins/logger" { + import * as enums from "@optimizely/optimizely-sdk/lib/utils/enums"; + import { LogHandler } from "@optimizely/js-sdk-logging"; + export interface LoggerConfig { + logLevel?: enums.LOG_LEVEL; + logToConsole?: boolean; + prefix?: string; + } + export function createLogger(config?: LoggerConfig): LogHandler; + export function createNoOpLogger(): LogHandler; } -declare module '@optimizely/optimizely-sdk/lib/utils/json_schema_validator' { +declare module "@optimizely/optimizely-sdk/lib/plugins/event_dispatcher" {} -} +declare module "@optimizely/optimizely-sdk/lib/utils/json_schema_validator" {} -declare module '@optimizely/optimizely-sdk/lib/plugins/error_handler' { -} \ No newline at end of file +declare module "@optimizely/optimizely-sdk/lib/plugins/error_handler" {}