Class

AdminBro

AdminBro(options)

Main class for AdminBro extension. It takes AdminBroOptions as a parameter and creates an admin instance.

Its main responsibility is to fetch all the resources and/or databases given by a user. Its instance is a currier - injected in all other classes.

Constructor

# new AdminBro(options)

Parameters:
Name Type Description
options AdminBroOptions

options passed to adminBro

View Source admin-bro/src/admin-bro.ts, line 44

Example
const AdminBro = require('admin-bro')
const admin = new AdminBro(AdminBroOptions)

Members

ActionsMap

# static ACTIONS

List of all default actions. If you want to change behaviour for all actions lika list, edit, show and delete you can do this here.

View Source admin-bro/src/admin-bro.ts, line 271

Example

Modifying accessibility rules for all show actions

const { ACTIONS } = require('admin-bro')
ACTIONS.show.isAccessible = () => {...}
Class.<BaseDatabase>

# static BaseDatabase

abstract class for all databases. External adapters have to implement that.

View Source admin-bro/src/admin-bro.ts, line 227

Class.<BaseProperty>

# static BaseProperty

abstract class for all properties. External adapters have to implement that or at least their BaseResource implementation should return records of this type.

View Source admin-bro/src/admin-bro.ts, line 247

Class.<BaseRecord>

# static BaseRecord

abstract class for all records. External adapters have to implement that or at least their BaseResource implementation should return records of this type.

View Source admin-bro/src/admin-bro.ts, line 234

Class.<BaseResource>

# static BaseResource

abstract class for all resources. External adapters have to implement that.

View Source admin-bro/src/admin-bro.ts, line 240

Class.<Filter>

# static Filter

Filter object passed to find method of BaseResource. External adapters have to use it

View Source admin-bro/src/admin-bro.ts, line 253

RouterType

# static Router

Contains set of routes availables within the application. It is used by external plugins.

View Source admin-bro/src/admin-bro.ts, line 221

Example
const { Router } = require('admin-bro')
Router.routes.forEach(route => {
  // map your framework routes to admin-bro routes
  // see how `admin-bro-expressjs` plugin does it.
})
UserComponentsMap

# static UserComponents

List of all bundled components

View Source admin-bro/src/admin-bro.ts, line 283

Class.<ValidationError>

# static ValidationError

Validation error which is thrown when record fails validation. External adapters have to use it.

View Source admin-bro/src/admin-bro.ts, line 260

string

# static VERSION

AdminBro version

View Source admin-bro/src/admin-bro.ts, line 277

AdminBroOptions

# options

Options given by a user

View Source admin-bro/src/admin-bro.ts, line 55

Array.<BaseResource>

# resources

List of all resources available for the AdminBro. They can be fetched with the AdminBro#findResource method

View Source admin-bro/src/admin-bro.ts, line 50

Methods

# static bundle(src) → {String}

Requires given .jsx/.tsx file, that it can be bundled to the frontend. It will be available under AdminBro.UserComponents[componentId].

Parameters:
Name Type Description
src String

path to a file containing react component.

View Source admin-bro/src/admin-bro.ts, line 151

componentId - uniq id of a component

String
Example
const adminBroOptions = {
  dashboard: {
    component: AdminBro.bundle('./path/to/component'),
  }
}

# static registerAdapter(options)

Registers various database adapters written for AdminBro.

Parameters:
Name Type Description
options Object
Database Class.<BaseDatabase>

subclass of BaseDatabase

Resource Class.<BaseResource>

subclass of BaseResource

View Source admin-bro/src/admin-bro.ts, line 75

Example
const AdminBro = require('admin-bro')
const MongooseAdapter = require('admin-bro-mongoose')
AdminBro.registerAdapter(MongooseAdapter)

# async static renderLogin(options) → {Promise.<string>}

Renders an entire login page with email and password fields using Renderer.

Used by external plugins

Parameters:
Name Type Attributes Description
options Object
action String

login form action url - it could be '/admin/login'

errorMessage String <optional>

optional error message. When set, renderer will print this message in the form

View Source admin-bro/src/admin-bro.ts, line 111

HTML of the rendered page

Promise.<string>

# findResource(resourceId) → {BaseResource}

Returns resource base on its ID

Parameters:
Name Type Description
resourceId String

ID of a resource defined under BaseResource#id

View Source admin-bro/src/admin-bro.ts, line 125

when resource with given id cannot be found

Error

found resource

BaseResource
Example
const User = admin.findResource('users')
await User.findOne(userId)

# async initialize()

Initializes AdminBro instance in production. This function should be called by all external plugins.

View Source admin-bro/src/admin-bro.ts, line 91

Type Definitions

object

# CurrentAdmin

Currently logged in admin.

Usage with TypeScript

import { CurrentAdmin } from 'admin-bro'
Properties:
Name Type Attributes Description
email string

Admin has one required field which is an email

{...} any

Also you can put as many other fields to it as you like.

id string <optional>

Id of your admin user

View Source admin-bro/src/current-admin.interface.ts, line 3

object

# RouterType

Type representing the AdminBro.Router

Properties:
Name Type Attributes Description
assets Array.<object>
assets[].path string
assets[].src string
routes Array.<object>
routes[].method string
routes[].path string
routes[].Controller any
routes[].action string
routes[].contentType string <optional>

View Source admin-bro/src/backend/router.ts, line 138