Skip to content

Commit ff62ee4

Browse files
ozayr-zaviaruzair-folio3msohailhussain
authored
feat: Added declaration file for notification center index.d.ts (#574)
Summary: Added declaration file in notification center index.d.ts Test plan: All test cases must work fine. No unit test to test declaration file for now. Co-authored-by: uzair-folio3 <[email protected]> Co-authored-by: Sohail Hussain <[email protected]>
1 parent 530223e commit ff62ee4

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* eslint-disable no-shadow */
2+
/**
3+
* Copyright 2020, Optimizely
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
declare module '@optimizely/optimizely-sdk/lib/core/notification_center' {
19+
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
20+
21+
export enum NOTIFICATION_TYPES {
22+
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
23+
DECISION = 'DECISION:type, userId, attributes, decisionInfo',
24+
LOG_EVENT = 'LOG_EVENT:logEvent',
25+
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
26+
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
27+
}
28+
29+
export enum DECISION_NOTIFICATION_TYPES {
30+
AB_TEST = 'ab-test',
31+
FEATURE = 'feature',
32+
FEATURE_TEST = 'feature-test',
33+
FEATURE_VARIABLE = 'feature-variable',
34+
ALL_FEATURE_VARIABLES = 'all-feature-variables',
35+
}
36+
37+
export type Options = {
38+
logger: LogHandler;
39+
errorHandler: ErrorHandler;
40+
};
41+
42+
export type SourceInfo = {
43+
experimentKey?: string;
44+
variationKey?: string;
45+
};
46+
47+
export type VariableValues = {
48+
[name: string]: unknown;
49+
};
50+
51+
export type DecisionInfo = {
52+
experimentKey?: string;
53+
variationKey?: string;
54+
featureKey?: string;
55+
featureEnabled?: boolean;
56+
source?: string;
57+
sourceInfo?: SourceInfo;
58+
variableKey?: string;
59+
variableValue?: unknown;
60+
variableValues?: VariableValues;
61+
variableType?: string;
62+
};
63+
64+
export interface NotificationData {
65+
type?: string;
66+
userId?: string;
67+
attributes?: import('../../shared_types').UserAttributes;
68+
decisionInfo?: DecisionInfo;
69+
experiment?: import('../../shared_types').Experiment;
70+
variation?: import('../../shared_types').Variation;
71+
logEvent?: import('../../shared_types').Event;
72+
eventKey?: string;
73+
eventTags?: import('../../shared_types').EventTags;
74+
}
75+
76+
export interface NotificationCenter {
77+
/**
78+
* Fires notifications for the argument type. All registered callbacks for this type will be
79+
* called. The notificationData object will be passed on to callbacks called.
80+
* @param {NOTIFICATION_TYPES} notificationType One of NOTIFICATION_TYPES
81+
* @param {NotificationData} notificationData Will be passed to callbacks called
82+
*/
83+
sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData: NotificationData): void;
84+
}
85+
86+
/**
87+
* Create an instance of NotificationCenter
88+
* @param {Options} options
89+
* @returns {NotificationCenter} An instance of NotificationCenter
90+
*/
91+
export function createNotificationCenter(options: Options): NotificationCenter;
92+
}

packages/optimizely-sdk/lib/shared_types.ts

+13
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,16 @@ export interface OptimizelyConfig {
9292
export type EventTags = {
9393
[key: string]: string | number | boolean;
9494
};
95+
96+
// An event to be submitted to Optimizely, enabling tracking the reach and impact of
97+
// tests and feature rollouts.
98+
export interface Event {
99+
// URL to which to send the HTTP request.
100+
url: string;
101+
// HTTP method with which to send the event.
102+
httpVerb: 'POST';
103+
// Value to send in the request body, JSON-serialized.
104+
// TODO[OASIS-6649]: Don't use any type
105+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
106+
params: any;
107+
}

0 commit comments

Comments
 (0)