Skip to content

feat: Added ODPEventManager implementation #789

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 36 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6569fdf
WIP initial ODP config and event manager
mikechu-optimizely Aug 30, 2022
cfc2938
Merge branch 'master' into mike/odp-event-manager
mikechu-optimizely Aug 31, 2022
3f1594c
WIP skeleton of methods
mikechu-optimizely Sep 13, 2022
cecfe65
WIP task queue
mikechu-optimizely Sep 14, 2022
f587aca
Remove task queue work
mikechu-optimizely Sep 15, 2022
9cb9f3a
WIP event manager
mikechu-optimizely Sep 19, 2022
a5ca291
WIP ODP event manager
mikechu-optimizely Sep 20, 2022
6c6ff2f
Async and lint warns silenced
mikechu-optimizely Sep 21, 2022
010370e
ODP Event Manager test layout
mikechu-optimizely Sep 21, 2022
11659c8
Finish bug fixes
mikechu-optimizely Sep 21, 2022
bbe5013
Merge branch 'master' into mike/odp-event-manager
mikechu-optimizely Sep 23, 2022
e9ac4b1
Merge branch 'master' into mike/odp-event-manager
mikechu-optimizely Sep 26, 2022
c83d584
WIP ODP event manager unit tests
mikechu-optimizely Sep 26, 2022
f28430a
WIP help from John
mikechu-optimizely Sep 27, 2022
dfda1cd
WIP observer patternizification
mikechu-optimizely Sep 27, 2022
e2808d5
Event manager and dispatcher with unit tests
mikechu-optimizely Sep 29, 2022
b2b8be0
Fixes to for unit tests
mikechu-optimizely Sep 30, 2022
0668890
Merge branch 'master' into mike/odp-event-manager
mikechu-optimizely Sep 30, 2022
74032bf
Update packages/optimizely-sdk/lib/plugins/odp/odp_config.ts
mikechu-optimizely Oct 3, 2022
7e0a881
Review code changes
mikechu-optimizely Oct 3, 2022
d87ed4f
Update packages/optimizely-sdk/lib/plugins/odp/odp_event_dispatcher.ts
mikechu-optimizely Oct 4, 2022
471a9c8
Update packages/optimizely-sdk/lib/plugins/odp/odp_event_dispatcher.ts
mikechu-optimizely Oct 4, 2022
a8f7df2
Update packages/optimizely-sdk/lib/plugins/odp/odp_event_manager.ts
mikechu-optimizely Oct 4, 2022
0157b90
Update packages/optimizely-sdk/lib/plugins/odp/odp_event_manager.ts
mikechu-optimizely Oct 4, 2022
98c75d7
Code review changes
mikechu-optimizely Oct 4, 2022
58a6bd5
Code review edits and JS Doc
mikechu-optimizely Oct 4, 2022
60d435a
Fix message
mikechu-optimizely Oct 4, 2022
ab63fab
Code review requested changes
mikechu-optimizely Oct 5, 2022
b50d357
JS Docs
mikechu-optimizely Oct 5, 2022
dc14b73
Fix data_source_version
mikechu-optimizely Oct 7, 2022
1d2abb8
Remove tsconfig.spec.json
mikechu-optimizely Oct 7, 2022
f82fbff
Read client engine and version from OptiOptions
mikechu-optimizely Oct 10, 2022
46c2720
Code review changes
mikechu-optimizely Oct 10, 2022
554773e
Require client engine & version for ODP Event Manager
mikechu-optimizely Oct 11, 2022
32a0c10
Code review changes
mikechu-optimizely Oct 11, 2022
346da4e
Fix setting timeout; add multiple flush test
mikechu-optimizely Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions packages/optimizely-sdk/lib/plugins/odp/odp_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* Copyright 2022, 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
*
* https://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.
*/

export class OdpConfig {
/**
* Host of ODP audience segments API.
* @private
*/
private _apiHost: string;

/**
* Getter to retrieve the ODP server host
* @public
*/
public get apiHost(): string {
return this._apiHost;
}

/**
* Public API key for the ODP account from which the audience segments will be fetched (optional).
* @private
*/
private _apiKey: string;

/**
* Getter to retrieve the ODP API key
* @public
*/
public get apiKey(): string {
return this._apiKey;
}

/**
* All ODP segments used in the current datafile (associated with apiHost/apiKey).
* @private
*/
private _segmentsToCheck: string[];

/**
* Getter for ODP segments to check
* @public
*/
public get segmentsToCheck(): string[] {
return this._segmentsToCheck;
}

constructor(apiKey: string, apiHost: string, segmentsToCheck?: string[]) {
this._apiKey = apiKey;
this._apiHost = apiHost;
this._segmentsToCheck = segmentsToCheck ?? [];
}

/**
* Update the ODP configuration details
* @param apiKey Public API key for the ODP account
* @param apiHost Host of ODP audience segments API
* @param segmentsToCheck Audience segments
* @returns true if configuration was updated successfully
*/
public update(apiKey: string, apiHost: string, segmentsToCheck: string[]): boolean {
if (this._apiKey === apiKey && this._apiHost === apiHost && this._segmentsToCheck === segmentsToCheck) {
return false;
} else {
this._apiKey = apiKey;
this._apiHost = apiHost;
this._segmentsToCheck = segmentsToCheck;

return true;
}
}

/**
* Determines if ODP configuration has the minimum amount of information
*/
public isReady(): boolean {
return !!this._apiKey && !!this._apiHost;
}
}
Loading