meta {
  name: Wakapi
  seq: 1
}

auth {
  mode: none
}

script:pre-request {
  const apiKey = bru.getEnvVar('API_KEY')
  
  if (!apiKey) {
      throw new Error('no api key given')
  }
  
  const token = base64encode(apiKey)
  bru.setVar('TOKEN', token)
  
  function base64encode(str) {
      return Buffer.from(str, 'utf-8').toString('base64')
  }
  
  bru.setVar('tsNow', parseInt(new Date().getTime() / 1000))
  bru.setVar('ts1MinAgo', parseInt((new Date().getTime() - 1000*60*1) / 1000))
  bru.setVar('ts2MinAgo', parseInt((new Date().getTime() - 1000*60*2) / 1000))
  bru.setVar('ts1HourAgo', parseInt((new Date().getTime() - 1000*60*60*1) / 1000))
  bru.setVar('ts1MonthAgo', parseInt((new Date().getTime() - 1000*60*60*24*30*1) / 1000))
}

docs {
  # Wakapi basic API routes
  
  Start by selecting an environment (there is a premade one called "dev") and configuring your `API_KEY`.
  
  For a complete list of API routes, refer to <https://wakapi.dev/swagger-ui>.
}
