mirror of
				https://github.com/datahub-project/datahub.git
				synced 2025-10-30 18:26:58 +00:00 
			
		
		
		
	 843a6c5bbb
			
		
	
	
		843a6c5bbb
		
			
		
	
	
	
	
		
			
			* Releases updated version of datahub-web client UI code * Fix typo in yarn lock * Change yarn lock to match yarn registry directories * Previous commit missed some paths * Even more changes to yarnlock missing in previous commit * Include codegen file for typings * Add files to get parity for datahub-web and current OS datahub-midtier * Add in typo fix from previous commit - change to proper license * Implement proper OS fix for person entity picture url * Workarounds for open source DH issues * Fixes institutional memory api and removes unopensourced tabs for datasets * Fixes search dataset deprecation and user search issue as a result of changes * Remove internal only options in the avatar menu
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| // Constant value for the CSRF protection cookie name
 | |
| export const csrfCookieName = 'datahub-csrf-token';
 | |
| 
 | |
| /**
 | |
|  * Builds a regular expression pattern and object using the provided cookie name
 | |
|  * @param {string} cookieName The name of the cookie to match
 | |
|  */
 | |
| const buildCookieRegExp = (cookieName: string): RegExp => new RegExp(cookieName + '="?([^";]+)"?');
 | |
| 
 | |
| /**
 | |
|  * Uses the provided regular expression object to parse the Document cookie property for a
 | |
|  * @param {RegExp} cookieRegExp A RegExp object instance to match against when parsing the cookie string
 | |
|  */
 | |
| const getCookieValue = (cookieRegExp: RegExp): string => {
 | |
|   const [, token = ''] = document.cookie.match(cookieRegExp) || [];
 | |
| 
 | |
|   return token;
 | |
| };
 | |
| 
 | |
| /**
 | |
|  * Stored reference to the default cookie regular expression for CSRF tokens
 | |
|  */
 | |
| const defaultCSRFCookieRegExp = buildCookieRegExp(csrfCookieName);
 | |
| 
 | |
| /**
 | |
|  * Retrieves the csrf token string from the document.cookie string
 | |
|  * @export
 | |
|  * @returns {string}
 | |
|  */
 | |
| export default function getCSRFToken(optionalTokenRegEx: RegExp = defaultCSRFCookieRegExp): string {
 | |
|   return getCookieValue(optionalTokenRegEx);
 | |
| }
 |