Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

directus-utilities

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

directus-utilities

Utility library for directus

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Utility library for directus

Brings some missing utility functions for directus.

Available functions

exportDefaultPreset

Exports default preset for given collection to a JSON file.

Params
  • directus (IDirectus<TypeMap>): Authenticated directus instance.
  • collection (string): Name of the collection.
  • targetFile (string): Target filename (incl. path) where preset should be exported.

importDefaultPreset

Imports default preset for given collection from a JSON file. If there is already a default preset for the given collection it will be updated otherwise it will be created.

Params
  • directus (IDirectus<TypeMap>): Authenticated directus instance.
  • collection (string): Name of the collection.
  • sourceFile (string): Filename of the previously exported JSON file.

exportPublicPermissions

Exports public permissions to a JSON file.

Params
  • directus (IDirectus<TypeMap>): Authenticated directus instance.
  • targetFile (string): Target filename (incl. path) where permissions should be exported.

importPublicPermissions

Imports public permissions from a JSON file. Creates a new permission entry for a collection which didn't have a public permission yet. Updates an existing permission for a collection when there is already a public permission defined. Deletes public permissions for collections which aren't available in the JSON file anymore.

Params
  • directus (IDirectus<TypeMap>): Authenticated directus instance.
  • sourceFile (string): Filename of the previously exported JSON file.

exportPermissionsByRolename

Exports permissions for a given role to a JSON file.

Params
  • directus (IDirectus<TypeMap>): Authenticated directus instance.
  • rolename (string): Name of the role.
  • targetFile (string): Target filename (incl. path) where permissions should be exported.

importPermissionsByRolename

Imports permissions for a given role from a JSON file. Creates a new permission entry if the role didn't have that permission yet. Updates an existing permission if the role already had such a permission defined. Deletes permissions for the role if they aren't available in the JSON file anymore.

Params
  • directus (IDirectus<TypeMap>): Authenticated directus instance.
  • rolename (string): Name of the role.
  • sourceFile (string): Filename of the previously exported JSON file.

Usage

How to create an authenticated directus instance

const { Directus } = require('@directus/sdk');

const directus = new Directus('http://localhost:8055', {
    auth: {
        staticToken: 'STATIC_TOKEN',
    },
});

If you want to use email and password. You should remove the staticToken above and use the following line.

await directus.auth.login({ email, password })

Examples

// Export default preset
const { Directus } = require('@directus/sdk');
const { exportDefaultPreset } = require('../directus-utilities/dist/index.js');

const run = async () => {
  const directus = new Directus('http://localhost:8055', {
    auth: {
        staticToken: 'STATIC_TOKEN',
    },
  });

  await exportDefaultPreset(directus, 'products', './presets/products-preset.json');
};

run().then(() => {
  process.exit();
});
// Import default preset
const { Directus } = require('@directus/sdk');
const { importDefaultPreset } = require('../directus-utilities/dist/index.js');

const run = async () => {
  const directus = new Directus('http://localhost:8055', {
    auth: {
        staticToken: 'STATIC_TOKEN',
    },
  });

  await importDefaultPreset(directus, 'products', './presets/products-preset.json');
};

run().then(() => {
  process.exit();
});

Keywords

FAQs

Package last updated on 15 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc