Dashboard API explorer

/api/administrator/account (GET)

Account information like email addresses is generated with faker-js it is not real user information.

await global.api.administrator.Account.get(req)

Returns object

{
  "accountid": "acct_057f96e47af70147",
  "object": "account",
  "appid": "tests_1656038565",
  "profileid": "prof_5c3591ffd06b161e",
  "sessionKeyNumber": 1,
  "lastSignedInAt": "2022-06-24T02:42:45.000Z",
  "createdAt": "2022-06-24T02:42:45.922Z",
  "updatedAt": "2022-06-24T02:42:45.940Z"
}

Exceptions

These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:

Exception Circumstances
invalid-accountid unspecified querystring accountid
invalid querystring accountid

NodeJS source (view on github)

const dashboard = require('../../../../index.js')

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.accountid) {
      throw new Error('invalid-accountid')
    }
    let account = await dashboard.StorageCache.get(req.query.accountid)
    if (!account) {
      let accountInfo
      try {
        accountInfo = await dashboard.Storage.Account.findOne({
          where: {
            accountid: req.query.accountid,
            appid: req.appid || global.appid
          }
        })
      } catch (error) {
      }
      if (!accountInfo) {
        throw new Error('invalid-accountid')
      }
      account = {}
      for (const field of accountInfo._options.attributes) {
        account[field] = accountInfo.get(field)
      }
      await dashboard.StorageCache.set(req.query.accountid, account)
    }
    delete (account.sessionKey)
    delete (account.usernameHash)
    delete (account.passwordHash)
    return account
  }
}

Test source (view on github)

/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../test-helper.js')

describe('/api/administrator/account', () => {
  describe('exceptions', () => {
    describe('invalid-accountid', () => {
      it('unspecified querystring accountid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/account')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-accountid')
      })

      it('invalid querystring accountid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/account?accountid=invalid')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-accountid')
      })
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/administrator/account?accountid=${user.account.accountid}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const account = await req.get()
      assert.strictEqual(account.accountid, user.account.accountid)
    })
  })

  describe('redacts', () => {
    it('usernameHash', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/administrator/account?accountid=${user.account.accountid}`)
      req.account = administrator.account
      req.session = administrator.session
      const account = await req.get()
      assert.strictEqual(undefined, account.usernameHash)
    })

    it('passwordHash', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/administrator/account?accountid=${user.account.accountid}`)
      req.account = administrator.account
      req.session = administrator.session
      const account = await req.get()
      assert.strictEqual(account.accountid, user.account.accountid)
      assert.strictEqual(undefined, account.passwordHash)
    })

    it('sessionKey', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/administrator/account?accountid=${user.account.accountid}`)
      req.account = administrator.account
      req.session = administrator.session
      const account = await req.get()
      assert.strictEqual(undefined, account.sessionKey)
    })
  })
})