Skip to content
Snippets Groups Projects
account.js 1.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • const { log } = require('cozy-konnector-libs')
    const { isLocal } = require('./env')
    
    function getAccountId() {
      log('info', `getAccountId`)
      try {
        return JSON.parse(process.env.COZY_FIELDS).account
      } catch (err) {
        throw new Error(`You must provide 'account' in COZY_FIELDS: ${err.message}`)
      }
    }
    
    function getAccountRev() {
      log('info', `getAccountRev`)
      try {
        return isLocal()
          ? 'fakeAccountRev'
          : JSON.parse(process.env.COZY_FIELDS).account_rev
      } catch (err) {
        throw new Error(`You must provide 'account' in COZY_FIELDS: ${err.message}`)
      }
    }
    
    /**
     * Return account secrets.
     * For local testing, change value with values from your konnector-dev-config.json
    
     * @returns {Fields}
    
     */
    function getAccountSecret() {
      try {
        return isLocal()
    
          ? JSON.parse(process.env.COZY_FIELDS)
    
          : JSON.parse(process.env.COZY_PARAMETERS).secret
      } catch (err) {
        throw new Error(
          `You must provide 'account-types' in COZY_PARAMETERS: ${err.message}`
        )
      }
    }
    module.exports = { getAccountId, getAccountRev, getAccountSecret }