export type UserOAuthConfig = { accessToken ? : string ; refreshToken : string ; } ; type GetOAuthConfigFromUserID = ( userID : string ) => Promise < UserOAuthConfig > ; type UpdateOAuthConfigForUserID = ( userID : string , config : UserOAuthConfig ) => Promise < void > ; type StorageOptions = { namespace : KVNamespace ; } | StorageFunctions ; export type StorageFunctions = { getOAuthConfigFromUserID : GetOAuthConfigFromUserID ; updateOAuthConfigForUserID : UpdateOAuthConfigForUserID ; } ; const keyFromUserID = ( userID , service ) => `User:${ userID }:${ service }` ; export const makeStorageFunctions = async ( options , service ) : Promise < StorageFunctions > => { if ( "namespace" in options ) { const getOAuthConfigFromUserID = ( userID ) => options . namespace . get ( keyFromUserID ( userID , service ) , "json" ) ; const updateOAuthConfigForUserID = ( userID , config ) => options . namespace . put ( keyFromUserID ( userID , service ) , JSON . stringify ( config ) ) ; return { getOAuthConfigFromUserID , updateOAuthConfigForUserID , } ; } else { return options ; } } ;