1
1
/**
2
- * Copyright 2022-2023 , Optimizely
2
+ * Copyright 2022-2024 , Optimizely
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -19,90 +19,29 @@ import { checkArrayEquality } from '../../utils/fns';
19
19
export class OdpConfig {
20
20
/**
21
21
* Host of ODP audience segments API.
22
- * @private
23
22
*/
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 ;
33
24
34
25
/**
35
26
* Public API key for the ODP account from which the audience segments will be fetched (optional).
36
- * @private
37
27
*/
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 ;
47
29
48
30
/**
49
31
* 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
57
32
*/
58
- get pixelUrl ( ) : string {
59
- return this . _pixelUrl ;
60
- }
33
+ readonly pixelUrl : string ;
61
34
62
35
/**
63
36
* 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
87
37
*/
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 [ ] ;
96
39
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 ;
106
45
}
107
46
108
47
/**
@@ -112,10 +51,33 @@ export class OdpConfig {
112
51
*/
113
52
equals ( configToCompare : OdpConfig ) : boolean {
114
53
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 )
119
58
) ;
120
59
}
121
60
}
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