@@ -11,13 +11,13 @@ import {
1111 internal ,
1212 LDEmitter ,
1313 LDHeaders ,
14- LDIdentifyOptions ,
1514 LDLogger ,
1615 Platform ,
1716 Response ,
1817 ServiceEndpoints ,
1918} from '@launchdarkly/js-client-sdk-common' ;
2019
20+ import { BrowserIdentifyOptions } from '../BrowserIdentifyOptions' ;
2121import BrowserDataManager from '../src/BrowserDataManager' ;
2222import validateOptions , { ValidatedOptions } from '../src/options' ;
2323import BrowserEncoding from '../src/platform/BrowserEncoding' ;
@@ -196,7 +196,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
196196 ) ;
197197
198198 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
199- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
199+ const identifyOptions : BrowserIdentifyOptions = { } ;
200200 const identifyResolve = jest . fn ( ) ;
201201 const identifyReject = jest . fn ( ) ;
202202
@@ -205,9 +205,91 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
205205 expect ( platform . requests . createEventSource ) . toHaveBeenCalled ( ) ;
206206 } ) ;
207207
208+ it ( 'includes the secure mode hash for streaming requests' , async ( ) => {
209+ dataManager = new BrowserDataManager (
210+ platform ,
211+ flagManager ,
212+ 'test-credential' ,
213+ config ,
214+ validateOptions ( { streaming : true } , logger ) ,
215+ ( ) => ( {
216+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
217+ return `/msdk/evalx/contexts/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
218+ } ,
219+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
220+ return `/msdk/evalx/context` ;
221+ } ,
222+ } ) ,
223+ ( ) => ( {
224+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
225+ return `/meval/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
226+ } ,
227+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
228+ return `/meval` ;
229+ } ,
230+ } ) ,
231+ baseHeaders ,
232+ emitter ,
233+ diagnosticsManager ,
234+ ) ;
235+
236+ const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
237+ const identifyOptions : BrowserIdentifyOptions = { hash : 'potato' } ;
238+ const identifyResolve = jest . fn ( ) ;
239+ const identifyReject = jest . fn ( ) ;
240+
241+ await dataManager . identify ( identifyResolve , identifyReject , context , identifyOptions ) ;
242+
243+ expect ( platform . requests . createEventSource ) . toHaveBeenCalledWith (
244+ '/meval/eyJraW5kIjoidXNlciIsImtleSI6InRlc3QtdXNlciJ9?h=potato&withReasons=true' ,
245+ expect . anything ( ) ,
246+ ) ;
247+ } ) ;
248+
249+ it ( 'includes secure mode hash for initial poll request' , async ( ) => {
250+ dataManager = new BrowserDataManager (
251+ platform ,
252+ flagManager ,
253+ 'test-credential' ,
254+ config ,
255+ validateOptions ( { streaming : false } , logger ) ,
256+ ( ) => ( {
257+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
258+ return `/msdk/evalx/contexts/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
259+ } ,
260+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
261+ return `/msdk/evalx/context` ;
262+ } ,
263+ } ) ,
264+ ( ) => ( {
265+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
266+ return `/meval/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
267+ } ,
268+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
269+ return `/meval` ;
270+ } ,
271+ } ) ,
272+ baseHeaders ,
273+ emitter ,
274+ diagnosticsManager ,
275+ ) ;
276+
277+ const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
278+ const identifyOptions : BrowserIdentifyOptions = { hash : 'potato' } ;
279+ const identifyResolve = jest . fn ( ) ;
280+ const identifyReject = jest . fn ( ) ;
281+
282+ await dataManager . identify ( identifyResolve , identifyReject , context , identifyOptions ) ;
283+
284+ expect ( platform . requests . fetch ) . toHaveBeenCalledWith (
285+ '/msdk/evalx/contexts/eyJraW5kIjoidXNlciIsImtleSI6InRlc3QtdXNlciJ9?withReasons=true&h=potato' ,
286+ expect . anything ( ) ,
287+ ) ;
288+ } ) ;
289+
208290 it ( 'should load cached flags and continue to poll to complete identify' , async ( ) => {
209291 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
210- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
292+ const identifyOptions : BrowserIdentifyOptions = { } ;
211293 const identifyResolve = jest . fn ( ) ;
212294 const identifyReject = jest . fn ( ) ;
213295
@@ -230,7 +312,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
230312
231313 it ( 'should identify from polling when there are no cached flags' , async ( ) => {
232314 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
233- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
315+ const identifyOptions : BrowserIdentifyOptions = { } ;
234316 const identifyResolve = jest . fn ( ) ;
235317 const identifyReject = jest . fn ( ) ;
236318
@@ -253,7 +335,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
253335
254336 it ( 'creates a stream when streaming is enabled after construction' , async ( ) => {
255337 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
256- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
338+ const identifyOptions : BrowserIdentifyOptions = { } ;
257339 const identifyResolve = jest . fn ( ) ;
258340 const identifyReject = jest . fn ( ) ;
259341
@@ -268,7 +350,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
268350
269351 it ( 'does not re-create the stream if it already running' , async ( ) => {
270352 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
271- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
353+ const identifyOptions : BrowserIdentifyOptions = { } ;
272354 const identifyResolve = jest . fn ( ) ;
273355 const identifyReject = jest . fn ( ) ;
274356
@@ -296,7 +378,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
296378
297379 it ( 'starts a stream on demand when not forced on/off' , async ( ) => {
298380 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
299- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
381+ const identifyOptions : BrowserIdentifyOptions = { } ;
300382 const identifyResolve = jest . fn ( ) ;
301383 const identifyReject = jest . fn ( ) ;
302384
@@ -315,7 +397,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
315397
316398 it ( 'does not start a stream when forced off' , async ( ) => {
317399 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
318- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
400+ const identifyOptions : BrowserIdentifyOptions = { } ;
319401 const identifyResolve = jest . fn ( ) ;
320402 const identifyReject = jest . fn ( ) ;
321403
@@ -335,7 +417,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
335417
336418 it ( 'starts streaming on identify if the automatic state is true' , async ( ) => {
337419 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
338- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
420+ const identifyOptions : BrowserIdentifyOptions = { } ;
339421 const identifyResolve = jest . fn ( ) ;
340422 const identifyReject = jest . fn ( ) ;
341423
0 commit comments