| 
									
										
										
										
											2022-03-09 22:56:05 +00:00
										 |  |  | import slugify from "@calcom/lib/slugify"; | 
					
						
							| 
									
										
										
										
											2021-09-28 08:57:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-24 17:45:56 +00:00
										 |  |  | export type ResponseUsernameApi = { | 
					
						
							| 
									
										
										
										
											2022-03-09 22:56:05 +00:00
										 |  |  |   available: boolean; | 
					
						
							|  |  |  |   premium: boolean; | 
					
						
							|  |  |  |   message?: string; | 
					
						
							|  |  |  |   suggestion?: string; | 
					
						
							| 
									
										
										
										
											2022-03-24 17:45:56 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export async function checkPremiumUsername(_username: string): Promise<ResponseUsernameApi> { | 
					
						
							| 
									
										
										
										
											2021-09-28 08:57:30 +00:00
										 |  |  |   const username = slugify(_username); | 
					
						
							|  |  |  |   const response = await fetch("https://cal.com/api/username", { | 
					
						
							|  |  |  |     credentials: "include", | 
					
						
							|  |  |  |     headers: { | 
					
						
							|  |  |  |       "Content-Type": "application/json", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     body: JSON.stringify({ username }), | 
					
						
							|  |  |  |     method: "POST", | 
					
						
							|  |  |  |     mode: "cors", | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const json = await response.json(); | 
					
						
							| 
									
										
										
										
											2022-03-09 22:56:05 +00:00
										 |  |  |   return json; | 
					
						
							| 
									
										
										
										
											2021-09-28 08:57:30 +00:00
										 |  |  | } |