@@ -11,14 +11,14 @@ 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
2120import BrowserDataManager from '../src/BrowserDataManager' ;
21+ import { BrowserIdentifyOptions } from '../src/BrowserIdentifyOptions' ;
2222import validateOptions , { ValidatedOptions } from '../src/options' ;
2323import BrowserEncoding from '../src/platform/BrowserEncoding' ;
2424import BrowserInfo from '../src/platform/BrowserInfo' ;
@@ -193,7 +193,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
193193 ) ;
194194
195195 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
196- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
196+ const identifyOptions : BrowserIdentifyOptions = { } ;
197197 const identifyResolve = jest . fn ( ) ;
198198 const identifyReject = jest . fn ( ) ;
199199
@@ -202,9 +202,91 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
202202 expect ( platform . requests . createEventSource ) . toHaveBeenCalled ( ) ;
203203 } ) ;
204204
205+ it ( 'includes the secure mode hash for streaming requests' , async ( ) => {
206+ dataManager = new BrowserDataManager (
207+ platform ,
208+ flagManager ,
209+ 'test-credential' ,
210+ config ,
211+ validateOptions ( { streaming : true } , logger ) ,
212+ ( ) => ( {
213+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
214+ return `/msdk/evalx/contexts/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
215+ } ,
216+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
217+ return `/msdk/evalx/context` ;
218+ } ,
219+ } ) ,
220+ ( ) => ( {
221+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
222+ return `/meval/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
223+ } ,
224+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
225+ return `/meval` ;
226+ } ,
227+ } ) ,
228+ baseHeaders ,
229+ emitter ,
230+ diagnosticsManager ,
231+ ) ;
232+
233+ const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
234+ const identifyOptions : BrowserIdentifyOptions = { hash : 'potato' } ;
235+ const identifyResolve = jest . fn ( ) ;
236+ const identifyReject = jest . fn ( ) ;
237+
238+ await dataManager . identify ( identifyResolve , identifyReject , context , identifyOptions ) ;
239+
240+ expect ( platform . requests . createEventSource ) . toHaveBeenCalledWith (
241+ '/meval/eyJraW5kIjoidXNlciIsImtleSI6InRlc3QtdXNlciJ9?h=potato&withReasons=true' ,
242+ expect . anything ( ) ,
243+ ) ;
244+ } ) ;
245+
246+ it ( 'includes secure mode hash for initial poll request' , async ( ) => {
247+ dataManager = new BrowserDataManager (
248+ platform ,
249+ flagManager ,
250+ 'test-credential' ,
251+ config ,
252+ validateOptions ( { streaming : false } , logger ) ,
253+ ( ) => ( {
254+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
255+ return `/msdk/evalx/contexts/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
256+ } ,
257+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
258+ return `/msdk/evalx/context` ;
259+ } ,
260+ } ) ,
261+ ( ) => ( {
262+ pathGet ( encoding : Encoding , _plainContextString : string ) : string {
263+ return `/meval/${ base64UrlEncode ( _plainContextString , encoding ) } ` ;
264+ } ,
265+ pathReport ( _encoding : Encoding , _plainContextString : string ) : string {
266+ return `/meval` ;
267+ } ,
268+ } ) ,
269+ baseHeaders ,
270+ emitter ,
271+ diagnosticsManager ,
272+ ) ;
273+
274+ const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
275+ const identifyOptions : BrowserIdentifyOptions = { hash : 'potato' } ;
276+ const identifyResolve = jest . fn ( ) ;
277+ const identifyReject = jest . fn ( ) ;
278+
279+ await dataManager . identify ( identifyResolve , identifyReject , context , identifyOptions ) ;
280+
281+ expect ( platform . requests . fetch ) . toHaveBeenCalledWith (
282+ '/msdk/evalx/contexts/eyJraW5kIjoidXNlciIsImtleSI6InRlc3QtdXNlciJ9?withReasons=true&h=potato' ,
283+ expect . anything ( ) ,
284+ ) ;
285+ } ) ;
286+
205287 it ( 'should load cached flags and continue to poll to complete identify' , async ( ) => {
206288 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
207- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
289+
208290 flagManager . loadCached . mockResolvedValue ( true ) ;
209291
210292 let identifyResolve : ( ) => void ;
@@ -216,7 +298,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
216298 identifyReject = jest . fn ( ) ;
217299
218300 // this is the function under test
219- dataManager . identify ( identifyResolve , identifyReject , context , identifyOptions ) ;
301+ dataManager . identify ( identifyResolve , identifyReject , context , { } ) ;
220302 } ) ;
221303
222304 expect ( logger . debug ) . toHaveBeenCalledWith (
@@ -234,7 +316,6 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
234316
235317 it ( 'should identify from polling when there are no cached flags' , async ( ) => {
236318 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
237- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
238319
239320 let identifyResolve : ( ) => void ;
240321 let identifyReject : ( err : Error ) => void ;
@@ -245,7 +326,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
245326 identifyReject = jest . fn ( ) ;
246327
247328 // this is the function under test
248- dataManager . identify ( identifyResolve , identifyReject , context , identifyOptions ) ;
329+ dataManager . identify ( identifyResolve , identifyReject , context , { } ) ;
249330 } ) ;
250331
251332 expect ( logger . debug ) . not . toHaveBeenCalledWith (
@@ -263,7 +344,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
263344
264345 it ( 'creates a stream when streaming is enabled after construction' , async ( ) => {
265346 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
266- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
347+ const identifyOptions : BrowserIdentifyOptions = { } ;
267348 const identifyResolve = jest . fn ( ) ;
268349 const identifyReject = jest . fn ( ) ;
269350
@@ -278,7 +359,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
278359
279360 it ( 'does not re-create the stream if it already running' , async ( ) => {
280361 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
281- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
362+ const identifyOptions : BrowserIdentifyOptions = { } ;
282363 const identifyResolve = jest . fn ( ) ;
283364 const identifyReject = jest . fn ( ) ;
284365
@@ -306,7 +387,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
306387
307388 it ( 'starts a stream on demand when not forced on/off' , async ( ) => {
308389 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
309- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
390+ const identifyOptions : BrowserIdentifyOptions = { } ;
310391 const identifyResolve = jest . fn ( ) ;
311392 const identifyReject = jest . fn ( ) ;
312393
@@ -325,7 +406,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
325406
326407 it ( 'does not start a stream when forced off' , async ( ) => {
327408 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
328- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
409+ const identifyOptions : BrowserIdentifyOptions = { } ;
329410 const identifyResolve = jest . fn ( ) ;
330411 const identifyReject = jest . fn ( ) ;
331412
@@ -345,7 +426,7 @@ describe('given a BrowserDataManager with mocked dependencies', () => {
345426
346427 it ( 'starts streaming on identify if the automatic state is true' , async ( ) => {
347428 const context = Context . fromLDContext ( { kind : 'user' , key : 'test-user' } ) ;
348- const identifyOptions : LDIdentifyOptions = { waitForNetworkResults : false } ;
429+ const identifyOptions : BrowserIdentifyOptions = { } ;
349430 const identifyResolve = jest . fn ( ) ;
350431 const identifyReject = jest . fn ( ) ;
351432
0 commit comments