Skip to content
KeystoneJS LogoKeystoneJS
👋🏻 Keystone 5 has officially moved to maintenance only. For the latest release of Keystone please visit the Keystone website.

List Plugins

This is the last active development release of this package as Keystone 5 is now in a 6 to 12 month active maintenance phase. For more information please read our Keystone 5 and beyond post.

atTracking

Adds createdAt and updatedAt fields to a list. These fields are read-only by will be updated automatically when items are created or updated.

Usage

JS
const { atTracking } = require('@keystonejs/list-plugins');

keystone.createList('ListWithPlugin', {
  fields: {
    // ...
  },
  plugins: [
    atTracking({
      /* ...config */
    }),
  ],
});

Config

OptionTypeDefaultDescription
createdAtFieldStringcreatedAtName of the createdAt field.
updatedAtFieldStringupdatedAtName of the createdAt field.
formatStringMM/DD/YYYY h:mm AFormat of the generated DateTime field.
accessObjectSee: accessChange default access controls.

access

By default access control on at tracking fields is read only:

JS
{
  read: true,
  create: false,
  update: false
}

Disabling created or updated

You can import either createdAt or updatedAt to apply a single tracking field:

JS
const { createdAt, updatedAt } = require('@keystonejs/list-plugins');

Note: The API is the same.

byTracking

Adds createdBy and updatedBy fields to a list. These fields are read-only by will be updated automatically when items are created or updated.

Usage

JS
const { byTracking } = require('@keystonejs/list-plugins');

keystone.createList('ListWithPlugin', {
  fields: {
    // ...
  },
  plugins: [
    byTracking({
      /* ...config */
    }),
  ],
});

Config

OptionTypeDefaultDescription
createdByFieldStringcreatedByName of the createdBy field.
updatedByFieldStringupdatedByName of the createdBy field.
refStringUserA reference to the list authenticated items (users).
accessObjectSee: accessChange default access controls.

access

By default access control on at tracking fields is read only:

JS
{
  read: true,
  create: false,
  update: false
}

Disabling created or updated

You can import either createdBy or updatedBy to apply a single tracking field:

JS
const { createdBy, updatedBy } = require('@keystonejs/list-plugins');

Note: The API is the same.

singleton

This plugin makes a list singleton by allowing only one item in the list. Useful for list which must contain only one items.

Usage

JS
const { singleton } = require('@keystonejs/list-plugins');

keystone.createList('ListWithPlugin', {
  fields: {...},
  plugins: [
    singleton(),
  ],
});

logging

This plugin provides a mechanism for logging all mutations in a Keystone system.

Usage

JS
const { logging } = require('@keystonejs/list-plugins');

keystone.createList('ListWithPlugin', {
  fields: {...},
  plugins: [
    logging(args => console.log(args),
  ],
});

keystone.createAuthStrategy({
  type: PasswordAuthStrategy,
  list: 'User',
  plugins: [
    logging(args => console.log(args),
  ]
})

Provided hooks

The logging plugin will log the arguments of all mutations with the function args => console.log(JSON.stringify(args)). You can customise its behaviour by providing an alternate logging function.

The plugin provides the following hooks:

  • afterChange
  • afterDelete
  • afterAuth
  • afterUnauth

The logging function for each hook recieves specific arguments related to the mutation.

afterChange (create)

OptionTypeDescription
operationString"create"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
originalInputObjectThe original input to the mutation.
createdItemObjectThe database record of the created item.

afterChange (update)

OptionTypeDescription
operationString"update"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
originalInputObjectThe original input to the mutation.
changedItemObjectThe database record of the updated item. This will only include those fields which have actually been changed.

afterDelete

OptionTypeDescription
operationString"delete"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
deletedItemObjectThe database record of the deleted item.

afterAuth

OptionTypeDescription
operationString"authenticate"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
itemObjectThe authenticated item
successBooleanA success indicator returned by authentication strategy
messageStringA success message returned by authentication strategy
tokenStringThe token returned by authentication strategy

afterUnauth

OptionTypeDescription
operationString"unauthenticate"
authedItemObjectThe currently authenticated item.
authedListKeyStringThe list currently authenticated against.
listKeyStringThe key of the list being operated on.
itemIdStringThe ID of the unauthenticated item

On this page

Edit on GitHub