Dashboard API explorer

/api/administrator/sessions (GET)

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

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

Returns array

[
  {
    "sessionid": "sess_901027dc9316b0ad",
    "object": "session",
    "appid": "tests_1656038571",
    "accountid": "acct_88864fce2efa864a",
    "duration": 1200,
    "csrfToken": "0191a9a1f9f3636f9d6903869d6393aab4b310c69174932bb9e8b4db41570945350f8796afcc95636b537d9e60da495a23b473118ff80954aad9990ad47d8060",
    "expiresAt": "2022-06-24T03:02:51.000Z",
    "lastVerifiedAt": "2022-06-24T02:42:51.000Z",
    "ended": false,
    "createdAt": "2022-06-24T02:42:51.511Z",
    "updatedAt": "2022-06-24T02:42:51.511Z"
  },
  {
    "sessionid": "sess_285ec920b939b32b",
    "object": "session",
    "appid": "tests_1656038571",
    "accountid": "acct_72df734bbe04a5a6",
    "duration": 1200,
    "csrfToken": "bfc328d05597dc47ca04b4484e02e5edee110d433012f38d91a9b3ed34450dd347b74a6cab0f8711e90e71d5da9757c24a291f2f0a666af42010ba2da1706747",
    "expiresAt": "2022-06-24T03:02:51.000Z",
    "lastVerifiedAt": "2022-06-24T02:42:51.000Z",
    "ended": false,
    "createdAt": "2022-06-24T02:42:51.480Z",
    "updatedAt": "2022-06-24T02:42:51.480Z"
  },
  {
    "sessionid": "sess_64c2fc67850151c5",
    "object": "session",
    "appid": "tests_1656038571",
    "accountid": "acct_039a96bfb8fa3d3b",
    "duration": 1200,
    "csrfToken": "ded44b382a54dcb8cb35dc374f1e67e8c2920ab212925335922772cf0d8e9ea290d4c6cec81799e21a910964c8cd917951ff6145d90be161a14815023dd76d38",
    "expiresAt": "2022-06-24T03:02:51.000Z",
    "lastVerifiedAt": "2022-06-24T02:42:51.000Z",
    "ended": false,
    "createdAt": "2022-06-24T02:42:51.442Z",
    "updatedAt": "2022-06-24T02:42:51.442Z"
  }
]

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
accountid string optional URL
all boolean optional URL
limit integer optional URL
offset integer optional URL

NodeJS source (view on github)

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

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const where = {
      appid: req.appid || global.appid
    }
    if (req.query.accountid) {
      where.accountid = req.query.accountid
    }
    let sessionids
    if (req.query.all) {
      sessionids = await dashboard.Storage.Session.findAll({
        where,
        attributes: ['sessionid'],
        order: [
          ['createdAt', 'DESC']
        ]
      })
    } else {
      const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
      const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
      sessionids = await dashboard.Storage.Session.findAll({
        where,
        attributes: ['sessionid'],
        offset,
        limit,
        order: [
          ['createdAt', 'DESC']
        ]
      })
    }
    if (!sessionids || !sessionids.length) {
      return null
    }
    const sessions = []
    for (const sessionData of sessionids) {
      req.query.sessionid = sessionData.dataValues.sessionid
      const session = await global.api.administrator.Session.get(req)
      sessions.push(session)
    }
    return sessions
  }
}

Test source (view on github)

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

describe('/api/administrator/sessions', function () {
  const cachedResponses = {}
  const cachedSessions = []
  before(async () => {
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    cachedSessions.unshift(administrator.session.sessionid)
    for (let i = 0, len = global.pageSize + 1; i < len; i++) {
      const user = await TestHelper.createUser()
      cachedSessions.unshift(user.session.sessionid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/sessions?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/sessions?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/sessions?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest(`/api/administrator/sessions?accountid=${administrator.account.accountid}`)
    req4.account = administrator.account
    req4.session = administrator.session
    cachedResponses.accountid = await req4.get()
    const req5 = TestHelper.createRequest('/api/administrator/sessions')
    req5.account = administrator.account
    req5.session = administrator.session
    req5.filename = __filename
    req5.saveResponse = true
    cachedResponses.returns = await req5.get()
    global.pageSize = 3
    cachedResponses.pageSize = await req5.get()
  })
  describe('receives', () => {
    it('optional querystring offset (integer)', async () => {
      const offset = 1
      const sessionsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(sessionsNow[i].sessionid, cachedSessions[offset + i])
      }
    })

    it('optional querystring limit (integer)', async () => {
      const limit = 1
      const sessionsNow = cachedResponses.limit
      assert.strictEqual(sessionsNow.length, limit)
    })

    it('optional querystring all (boolean)', async () => {
      const sessionsNow = cachedResponses.all
      assert.strictEqual(sessionsNow.length, cachedSessions.length)
    })

    it('optional querystring accountid (string)', async () => {
      const sessionsNow = cachedResponses.accountid
      assert.strictEqual(sessionsNow.length, 1)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const sessions = cachedResponses.returns
      assert.strictEqual(sessions.length, global.pageSize)
    })
  })

  describe('redacts', () => {
    it('tokenHash', async () => {
      const sessions = cachedResponses.returns
      assert.strictEqual(undefined, sessions[0].tokenHash)
      assert.strictEqual(undefined, sessions[1].tokenHash)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      global.pageSize = 3
      const profilesNow = cachedResponses.pageSize
      assert.strictEqual(profilesNow.length, global.pageSize)
    })
  })
})