Skip to content

Commit 510d247

Browse files
mikechu-optimizelyzashraf1985jaeopt
authored
feat: Added ODPEventManager implementation (#789)
* Initial ODP config and event manager * WIP task queue * Remove task queue work * WIP ODP event manager needs tests and REST API sendEvents() * Async and lint warns silenced * ODP Event Manager test layout * Finish bug fixes * WIP ODP event manager unit tests * Event manager and dispatcher with unit tests * Fixes to for unit tests * Update packages/optimizely-sdk/lib/plugins/odp/odp_config.ts Co-authored-by: Zeeshan Ashraf <35262377+zashraf1985@users.noreply.github.com> * Review code changes * Update packages/optimizely-sdk/lib/plugins/odp/odp_event_dispatcher.ts Co-authored-by: Zeeshan Ashraf <35262377+zashraf1985@users.noreply.github.com> * Update packages/optimizely-sdk/lib/plugins/odp/odp_event_dispatcher.ts Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com> * Update packages/optimizely-sdk/lib/plugins/odp/odp_event_manager.ts Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com> * Update packages/optimizely-sdk/lib/plugins/odp/odp_event_manager.ts Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com> * Code review changes * Code review edits and JS Doc * Fix message * Code review requested changes * JS Docs * Fix data_source_version * Remove tsconfig.spec.json * Read client engine and version from OptiOptions * Code review changes * Require client engine & version for ODP Event Manager * Code review changes * Fix setting timeout; add multiple flush test Co-authored-by: Zeeshan Ashraf <35262377+zashraf1985@users.noreply.github.com> Co-authored-by: Jae Kim <45045038+jaeopt@users.noreply.github.com>
1 parent 8bc8ef5 commit 510d247

File tree

6 files changed

+899
-10
lines changed

6 files changed

+899
-10
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* Copyright 2022, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export class OdpConfig {
18+
/**
19+
* Host of ODP audience segments API.
20+
* @private
21+
*/
22+
private _apiHost: string;
23+
24+
/**
25+
* Getter to retrieve the ODP server host
26+
* @public
27+
*/
28+
public get apiHost(): string {
29+
return this._apiHost;
30+
}
31+
32+
/**
33+
* Public API key for the ODP account from which the audience segments will be fetched (optional).
34+
* @private
35+
*/
36+
private _apiKey: string;
37+
38+
/**
39+
* Getter to retrieve the ODP API key
40+
* @public
41+
*/
42+
public get apiKey(): string {
43+
return this._apiKey;
44+
}
45+
46+
/**
47+
* All ODP segments used in the current datafile (associated with apiHost/apiKey).
48+
* @private
49+
*/
50+
private _segmentsToCheck: string[];
51+
52+
/**
53+
* Getter for ODP segments to check
54+
* @public
55+
*/
56+
public get segmentsToCheck(): string[] {
57+
return this._segmentsToCheck;
58+
}
59+
60+
constructor(apiKey: string, apiHost: string, segmentsToCheck?: string[]) {
61+
this._apiKey = apiKey;
62+
this._apiHost = apiHost;
63+
this._segmentsToCheck = segmentsToCheck ?? [];
64+
}
65+
66+
/**
67+
* Update the ODP configuration details
68+
* @param apiKey Public API key for the ODP account
69+
* @param apiHost Host of ODP audience segments API
70+
* @param segmentsToCheck Audience segments
71+
* @returns true if configuration was updated successfully
72+
*/
73+
public update(apiKey: string, apiHost: string, segmentsToCheck: string[]): boolean {
74+
if (this._apiKey === apiKey && this._apiHost === apiHost && this._segmentsToCheck === segmentsToCheck) {
75+
return false;
76+
} else {
77+
this._apiKey = apiKey;
78+
this._apiHost = apiHost;
79+
this._segmentsToCheck = segmentsToCheck;
80+
81+
return true;
82+
}
83+
}
84+
85+
/**
86+
* Determines if ODP configuration has the minimum amount of information
87+
*/
88+
public isReady(): boolean {
89+
return !!this._apiKey && !!this._apiHost;
90+
}
91+
}

0 commit comments

Comments
 (0)