11/**
2- * Copyright 2022-2023 , Optimizely
2+ * Copyright 2022-2024 , Optimizely
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -19,90 +19,29 @@ import { checkArrayEquality } from '../../utils/fns';
1919export class OdpConfig {
2020 /**
2121 * Host of ODP audience segments API.
22- * @private
2322 */
24- private _apiHost : string ;
25-
26- /**
27- * Getter to retrieve the ODP server host
28- * @public
29- */
30- get apiHost ( ) : string {
31- return this . _apiHost ;
32- }
23+ readonly apiHost : string ;
3324
3425 /**
3526 * Public API key for the ODP account from which the audience segments will be fetched (optional).
36- * @private
3727 */
38- private _apiKey : string ;
39-
40- /**
41- * Getter to retrieve the ODP API key
42- * @public
43- */
44- get apiKey ( ) : string {
45- return this . _apiKey ;
46- }
28+ readonly apiKey : string ;
4729
4830 /**
4931 * Url for sending events via pixel.
50- * @private
51- */
52- private _pixelUrl : string ;
53-
54- /**
55- * Getter to retrieve the ODP pixel URL
56- * @public
5732 */
58- get pixelUrl ( ) : string {
59- return this . _pixelUrl ;
60- }
33+ readonly pixelUrl : string ;
6134
6235 /**
6336 * All ODP segments used in the current datafile (associated with apiHost/apiKey).
64- * @private
65- */
66- private _segmentsToCheck : string [ ] ;
67-
68- /**
69- * Getter for ODP segments to check
70- * @public
71- */
72- get segmentsToCheck ( ) : string [ ] {
73- return this . _segmentsToCheck ;
74- }
75-
76- constructor ( apiKey ?: string , apiHost ?: string , pixelUrl ?: string , segmentsToCheck ?: string [ ] ) {
77- this . _apiKey = apiKey ?? '' ;
78- this . _apiHost = apiHost ?? '' ;
79- this . _pixelUrl = pixelUrl ?? '' ;
80- this . _segmentsToCheck = segmentsToCheck ?? [ ] ;
81- }
82-
83- /**
84- * Update the ODP configuration details
85- * @param {OdpConfig } config New ODP Config to potentially update self with
86- * @returns true if configuration was updated successfully
8737 */
88- update ( config : OdpConfig ) : boolean {
89- if ( this . equals ( config ) ) {
90- return false ;
91- } else {
92- if ( config . apiKey ) this . _apiKey = config . apiKey ;
93- if ( config . apiHost ) this . _apiHost = config . apiHost ;
94- if ( config . pixelUrl ) this . _pixelUrl = config . pixelUrl ;
95- if ( config . segmentsToCheck ) this . _segmentsToCheck = config . segmentsToCheck ;
38+ readonly segmentsToCheck : string [ ] ;
9639
97- return true ;
98- }
99- }
100-
101- /**
102- * Determines if ODP configuration has the minimum amount of information
103- */
104- isReady ( ) : boolean {
105- return ! ! this . _apiKey && ! ! this . _apiHost ;
40+ constructor ( apiKey : string , apiHost : string , pixelUrl : string , segmentsToCheck : string [ ] ) {
41+ this . apiKey = apiKey ;
42+ this . apiHost = apiHost ;
43+ this . pixelUrl = pixelUrl ;
44+ this . segmentsToCheck = segmentsToCheck ;
10645 }
10746
10847 /**
@@ -112,10 +51,33 @@ export class OdpConfig {
11251 */
11352 equals ( configToCompare : OdpConfig ) : boolean {
11453 return (
115- this . _apiHost === configToCompare . _apiHost &&
116- this . _apiKey === configToCompare . _apiKey &&
117- this . _pixelUrl === configToCompare . _pixelUrl &&
118- checkArrayEquality ( this . segmentsToCheck , configToCompare . _segmentsToCheck )
54+ this . apiHost === configToCompare . apiHost &&
55+ this . apiKey === configToCompare . apiKey &&
56+ this . pixelUrl === configToCompare . pixelUrl &&
57+ checkArrayEquality ( this . segmentsToCheck , configToCompare . segmentsToCheck )
11958 ) ;
12059 }
12160}
61+
62+ export type OdpNotIntegratedConfig = {
63+ readonly integrated : false ;
64+ }
65+
66+ export type OdpIntegratedConfig = {
67+ readonly integrated : true ;
68+ readonly odpConfig : OdpConfig ;
69+ }
70+
71+ export const odpIntegrationsAreEqual = ( config1 : OdpIntegrationConfig , config2 : OdpIntegrationConfig ) : boolean => {
72+ if ( config1 . integrated !== config2 . integrated ) {
73+ return false ;
74+ }
75+
76+ if ( config1 . integrated && config2 . integrated ) {
77+ return config1 . odpConfig . equals ( config2 . odpConfig ) ;
78+ }
79+
80+ return true ;
81+ }
82+
83+ export type OdpIntegrationConfig = OdpNotIntegratedConfig | OdpIntegratedConfig ;
0 commit comments