import { v4 as uuidv4 } from 'uuid' ; import { UserSettings } from './internal' ; function _newIdentifier ( type = 'c' ) { const bytes = uuidv4 ( null , Buffer . alloc ( 16 ) ) ; const base64 = bytes . toString ( 'base64' ) ; const slug = base64 . replace ( /\+/g , '-' ) . replace ( /\//g , '_' ) . substring ( 0 , 22 ) ; return type + '_' + slug ; } export async function clientIdAsync ( ) { let clientId = await UserSettings . getAsync ( 'accessToken' , null ) ; if ( clientId === null ) { clientId = _newIdentifier ( ) ; await setClientIdAsync ( clientId ) ; } return clientId ; } export async function setClientIdAsync ( token ) { await UserSettings . setAsync ( 'accessToken' , token ) ; return token ; }