Skip to content

feat: Added declaration file for notification center index.d.ts #574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 28, 2020
92 changes: 92 additions & 0 deletions packages/optimizely-sdk/lib/core/notification_center/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* eslint-disable no-shadow */
/**
* Copyright 2020, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare module '@optimizely/optimizely-sdk/lib/core/notification_center' {
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';

export enum NOTIFICATION_TYPES {
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
DECISION = 'DECISION:type, userId, attributes, decisionInfo',
LOG_EVENT = 'LOG_EVENT:logEvent',
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
}

export enum DECISION_NOTIFICATION_TYPES {
AB_TEST = 'ab-test',
FEATURE = 'feature',
FEATURE_TEST = 'feature-test',
FEATURE_VARIABLE = 'feature-variable',
ALL_FEATURE_VARIABLES = 'all-feature-variables',
}

export type Options = {
logger: LogHandler;
errorHandler: ErrorHandler;
};

export type SourceInfo = {
experimentKey?: string;
variationKey?: string;
};

export type VariableValues = {
[name: string]: unknown;
};

export type DecisionInfo = {
experimentKey?: string;
variationKey?: string;
featureKey?: string;
featureEnabled?: boolean;
source?: string;
sourceInfo?: SourceInfo;
variableKey?: string;
variableValue?: unknown;
variableValues?: VariableValues;
variableType?: string;
};

export interface NotificationData {
type?: string;
userId?: string;
attributes?: import('../../shared_types').UserAttributes;
decisionInfo?: DecisionInfo;
experiment?: import('../../shared_types').Experiment;
variation?: import('../../shared_types').Variation;
logEvent?: import('../../shared_types').Event;
eventKey?: string;
eventTags?: import('../../shared_types').EventTags;
}

export interface NotificationCenter {
/**
* Fires notifications for the argument type. All registered callbacks for this type will be
* called. The notificationData object will be passed on to callbacks called.
* @param {NOTIFICATION_TYPES} notificationType One of NOTIFICATION_TYPES
* @param {NotificationData} notificationData Will be passed to callbacks called
*/
sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData: NotificationData): void;
}

/**
* Create an instance of NotificationCenter
* @param {Options} options
* @returns {NotificationCenter} An instance of NotificationCenter
*/
export function createNotificationCenter(options: Options): NotificationCenter;
}
13 changes: 13 additions & 0 deletions packages/optimizely-sdk/lib/shared_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,16 @@ export interface OptimizelyConfig {
export type EventTags = {
[key: string]: string | number | boolean;
};

// 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.
// TODO[OASIS-6649]: Don't use any type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: any;
}