@@ -5,6 +5,7 @@ import { SignalsIngestSettingsConfig } from '../client'
55import { SandboxSettingsConfig } from '../processor/sandbox'
66import { NetworkSettingsConfig } from '../signal-generators/network-gen'
77import { SignalsPluginSettingsConfig } from '../../types'
8+ import { DebugStorage } from '../../lib/storage/debug-storage'
89
910export type SignalsSettingsConfig = Pick <
1011 SignalsPluginSettingsConfig ,
@@ -111,17 +112,24 @@ export class SignalGlobalSettings {
111112}
112113
113114export class SignalsDebugSettings {
114- private storageType = 'sessionStorage' as const
115115 private static redactionKey = 'segment_signals_debug_redaction_disabled'
116116 private static ingestionKey = 'segment_signals_debug_ingestion_enabled'
117- private static logSignals = 'segment_signals_debug_log_signals_enabled'
117+ private static logSignals = 'segment_signals_log_signals_enabled'
118+ storage : DebugStorage
118119
119120 constructor ( disableRedaction ?: boolean , enableIngestion ?: boolean ) {
121+ this . storage = new DebugStorage ( 'sessionStorage' )
120122 if ( typeof disableRedaction === 'boolean' ) {
121- this . setDebugKey ( SignalsDebugSettings . redactionKey , disableRedaction )
123+ this . storage . setDebugKey (
124+ SignalsDebugSettings . redactionKey ,
125+ disableRedaction
126+ )
122127 }
123128 if ( typeof enableIngestion === 'boolean' ) {
124- this . setDebugKey ( SignalsDebugSettings . ingestionKey , enableIngestion )
129+ this . storage . setDebugKey (
130+ SignalsDebugSettings . ingestionKey ,
131+ enableIngestion
132+ )
125133 }
126134
127135 const debugModeInQs = parseDebugModeQueryString ( )
@@ -132,46 +140,20 @@ export class SignalsDebugSettings {
132140 }
133141
134142 setAllDebugging = ( boolean : boolean ) => {
135- this . setDebugKey ( SignalsDebugSettings . redactionKey , boolean )
136- this . setDebugKey ( SignalsDebugSettings . ingestionKey , boolean )
137- this . setDebugKey ( SignalsDebugSettings . logSignals , boolean )
138- }
139-
140- private setDebugKey = ( key : string , enable : boolean ) : void => {
141- try {
142- if ( enable ) {
143- window [ this . storageType ] . setItem ( key , 'true' )
144- } else {
145- logger . debug ( `Removing debug key ${ key } from storage` )
146- window . sessionStorage . removeItem ( key )
147- }
148- } catch ( e ) {
149- logger . debug ( 'Storage error' , e )
150- }
151- }
152-
153- private getDebugKey = ( key : string ) : boolean => {
154- try {
155- const isEnabled = Boolean ( window [ this . storageType ] . getItem ( key ) )
156- if ( isEnabled ) {
157- logger . debug ( `${ key } =true (app. storage)` )
158- return true
159- }
160- } catch ( e ) {
161- logger . debug ( 'Storage error' , e )
162- }
163- return false
143+ this . storage . setDebugKey ( SignalsDebugSettings . redactionKey , boolean )
144+ this . storage . setDebugKey ( SignalsDebugSettings . ingestionKey , boolean )
145+ this . storage . setDebugKey ( SignalsDebugSettings . logSignals , boolean )
164146 }
165147
166148 getDisableSignalsRedaction = ( ) : boolean => {
167- return this . getDebugKey ( SignalsDebugSettings . redactionKey )
149+ return this . storage . getDebugKey ( SignalsDebugSettings . redactionKey )
168150 }
169151
170152 getEnableSignalsIngestion = ( ) : boolean => {
171- return this . getDebugKey ( SignalsDebugSettings . ingestionKey )
153+ return this . storage . getDebugKey ( SignalsDebugSettings . ingestionKey )
172154 }
173155
174156 getEnableLogSignals = ( ) : boolean => {
175- return this . getDebugKey ( SignalsDebugSettings . logSignals )
157+ return this . storage . getDebugKey ( SignalsDebugSettings . logSignals )
176158 }
177159}
0 commit comments