| 
									
										
										
										
											2017-11-14 21:54:12 -05:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const protected_session = require('./protected_session'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = function(req) { | 
					
						
							|  |  |  |     const browserId = req.headers['x-browser-id']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function isProtectedSessionAvailable() { | 
					
						
							|  |  |  |         return protected_session.isProtectedSessionAvailable(req); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function getDataKey() { | 
					
						
							|  |  |  |         if (!isProtectedSessionAvailable()) { | 
					
						
							|  |  |  |             throw new Error("Protected session is not available"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return protected_session.getDataKey(req); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 18:56:52 -05:00
										 |  |  |     function getDataKeyOrNull() { | 
					
						
							|  |  |  |         if (!isProtectedSessionAvailable()) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return protected_session.getDataKey(req); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 21:54:12 -05:00
										 |  |  |     return { | 
					
						
							|  |  |  |         browserId, | 
					
						
							|  |  |  |         isProtectedSessionAvailable, | 
					
						
							| 
									
										
										
										
											2017-11-17 18:56:52 -05:00
										 |  |  |         getDataKey, | 
					
						
							|  |  |  |         getDataKeyOrNull | 
					
						
							| 
									
										
										
										
											2017-11-14 21:54:12 -05:00
										 |  |  |     }; | 
					
						
							|  |  |  | }; |