Skip to content

Commit 19bc495

Browse files
authored
feat (utils): Add notification types to utils package (#321)
Summary: This PR adds two exports from the utils package: - NOTIFICATION_TYPES, an enum - NotificationCenter, an interface. I want this package to be the home of notification types and the notification center interface, to facilitate using notification center in both the optimizely-sdk package and the event-processor package. Also, I added a new LOG_EVENT notification type. I plan to use this in the event processor when implementing the requirement in OASIS-4976. Test plan: Manually tested Issues: https://optimizely.atlassian.net/browse/OASIS-4976
1 parent 00f6c13 commit 19bc495

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

packages/utils/CHANGELOG.MD

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Changes that have landed but are not yet released.
99

1010
### New Features
1111
- Added `objectEntries`
12+
- Added `NOTIFICATION_TYPES` and `NotificationCenter`
1213

1314
## [0.1.0] - March 1, 2019
1415

packages/utils/src/index.ts

+53
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,56 @@ export function sprintf(format: string, ...args: any[]): string {
102102
}
103103
})
104104
}
105+
/*
106+
* Notification types for use with NotificationCenter
107+
* Format is EVENT: <list of parameters to callback>
108+
*
109+
* SDK consumers can use these to register callbacks with the notification center.
110+
*
111+
* @deprecated since 3.1.0
112+
* ACTIVATE: An impression event will be sent to Optimizely
113+
* Callbacks will receive an object argument with the following properties:
114+
* - experiment {Object}
115+
* - userId {string}
116+
* - attributes {Object|undefined}
117+
* - variation {Object}
118+
* - logEvent {Object}
119+
*
120+
* DECISION: A decision is made in the system. i.e. user activation,
121+
* feature access or feature-variable value retrieval
122+
* Callbacks will receive an object argument with the following properties:
123+
* - type {string}
124+
* - userId {string}
125+
* - attributes {Object|undefined}
126+
* - decisionInfo {Object|undefined}
127+
*
128+
* LOG_EVENT: A batch of events, which could contain impressions and/or conversions,
129+
* will be sent to Optimizely
130+
* Callbacks will receive an object argument with the following properties:
131+
* - url {string}
132+
* - httpVerb {string}
133+
* - params {Object}
134+
*
135+
* OPTIMIZELY_CONFIG_UPDATE: This Optimizely instance has been updated with a new
136+
* config
137+
*
138+
* TRACK: A conversion event will be sent to Optimizely
139+
* Callbacks will receive the an object argument with the following properties:
140+
* - eventKey {string}
141+
* - userId {string}
142+
* - attributes {Object|undefined}
143+
* - eventTags {Object|undefined}
144+
* - logEvent {Object}
145+
*
146+
*/
147+
export enum NOTIFICATION_TYPES {
148+
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
149+
DECISION = 'DECISION:type, userId, attributes, decisionInfo',
150+
LOG_EVENT = 'LOG_EVENT:logEvent',
151+
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
152+
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
153+
}
154+
155+
export interface NotificationCenter {
156+
sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData?: any): void
157+
}

0 commit comments

Comments
 (0)