npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

drupal_jsonapi_entities

v0.3.0

Published

Drupal JSON:API Entities

Readme

Drupal JSON:API Entities

CircleCI Known Vulnerabilities codecov

Build a Drupal Entity form/view field schema from your Drupal JSON:API entitiy with ease.

Installation

$ npm install drupal_jsonapi_entities

Documentation

new drupalJSONAPIEntities()

import drupalJSONAPIEntities from 'drupal_jsonapi_entities'

const drupalEntities = new drupalJSONAPIEntities(url, options)

The constructor takes two arguments:

  • url: The base URL of the Drupal instance.
  • options: The API options.

Available API options (options argument)

  • auth: An array for use authorizing the client with the Drupal instance. Currently only supports OAuth2 password flow.
    • clientId: The Oauth 2 Client ID.
    • clientSecret: The Oauth 2 Client secret.
    • user: The Drupal username.
    • pass: The Drupal user passsword.

getFormSchema()

const formSchema = await drupalEntities.getFormSchema(entityType, bundle, mode)

The method takes three arguments:

  • entityType: The Drupal entity type ID.
  • bundle: The Drupal bundle ID for the entity type.
  • mode: The form display mode. Default: default.

Returns a JSON object:

  • fields: An array of field objects, sorted by weight.
    • cardinality: Allowed number of values.
    • description: Help text.
    • id: Machine name.
    • property: True if field is a property on the Drupal entity.
    • label: Label.
    • required: Required field.
    • settings: Merged object of field settings.
    • type: Field type machine name.
    • weight: Form display field weight.
    • group: (optional) Group.
  • groups: An array of Drupal Field Group module group objects, sorted by weight.
    • children: Array of fields in group.
    • format_settings: Settings for the display of the group.
    • format_type: Type of group for display.
    • id: Machine name.
    • label: Label.
    • weight: Weight.

Drupal requirements

JSON:API resources:

  • entity_form_display--entity_form_display
  • field_config--field_config
  • field_storage_config--field_storage_config

Permissions:

  • administer display modes
  • administer ENTITY_TYPE fields

getViewSchema()

const viewSchema = await drupalEntities.getViewSchema(entityType, bundle, mode)

The method takes three arguments:

  • entityType: The Drupal entity type ID.
  • bundle: The Drupal bundle ID for the entity type.
  • mode: The view display mode. Default: default.

Returns a JSON object:

  • fields: An array of field objects, sorted by weight.
    • description: Help text.
    • id: Machine name.
    • property: True if field is a property on the Drupal entity.
    • label: Label.
    • labelPosition: Label position.
    • required: Required field.
    • settings: Merged object of field settings.
    • thirdPartySettings: Settings of any third party modules.
    • type: Field type machine name.
    • weight: Form display field weight.
    • group: (optional) Group.
  • groups: An array of Drupal Field Group module group objects, sorted by weight.
    • children: Array of fields in group.
    • format_settings: Settings for the display of the group.
    • format_type: Type of group for display.
    • id: Machine name.
    • label: Label.
    • weight: Weight.

Drupal requirements

JSON:API resources:

  • entity_form_display--entity_form_display
  • entity_view_display--entity_view_display
  • field_config--field_config
  • field_storage_config--field_storage_config

Permissions:

  • administer display modes
  • administer ENTITY_TYPE fields

Nuxt.js module

Drupal JSON:API Entities provides a Nuxt.js module for easily caching the schema(s).

Getting started with Nuxt.js

Add drupal_jsonapi_entities/nuxt to the modules section of your nuxt.config.js file.

module.exports = {
  modules: [
    // Drupal JSON:API entities.
    [
      'drupal_jsonapi_entities/nuxt',
      {
        baseUrl: process.env.API_URL,
        auth: {
          clientId: process.env.API_CONSUMER_CLIENT_ID,
          clientSecret: process.env.API_CONSUMER_CLIENT_SECRET,
          user: process.env.API_CONSUMER_USERNAME,
          pass: process.env.API_CONSUMER_PASSWORD
        }
      }
    ],
  ]
}

Add a drupalJSONAPIEntities section to your nuxt.config.js file in the following format for all required Entity types, Bundles, Schema types and Modes:

module.exports = {
  drupalJSONAPIEntities: {
    'entityType': { 'bundle': { 'type': [ 'mode' ] } }
  }
}

Example:

module.exports = {
  drupalJSONAPIEntities: {
    'node': {
      'recipe': {
        form: [ 'default' ],
        view: [ 'default' ],
      }
    }
  }
}

The module provides a plugin, which returns the Drupal JSON:API Entities schema(s).

this.$drupalJSONAPIEntities()