import { getServerSettings } from "@cocalc/server/settings" ; import { createClient } from "node-zendesk" ; import type { Client } from "node-zendesk" ; let client = undefined ; let config = "" ; export default async function getClient ( ) { const { zendesk_token : token , zendesk_username : username , zendesk_uri : remoteUri , } = await getServerSettings ( ) ; const config0 = `${ token + username + remoteUri }` ; if ( config == config0 && client != null ) { return client ; } if ( client == null ) { if ( ! token ) { throw Error ( "Support not available -- admin must configure the Zendesk token" ) ; } if ( ! username ) { throw Error ( "Support not available -- admin must configure the Zendesk username" ) ; } if ( ! remoteUri ) { throw Error ( "Support not available -- admin must configure the Zendesk Uri" ) ; } config = config0 ; client = createClient ( { username , token , remoteUri } ) ; } return client ; }