
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
drupal-sdk
Advanced tools
The Drupal SDK is a helper package for calling Drupal endpoints, like the JSON:API, in a more efficient and easy way.
npm install drupal-sdk
Development and bugtracking take place on gitlab.com. See https://gitlab.com/VoidE/drupal-sdk/-/issues for the current issue queue and https://gitlab.com/VoidE/drupal-sdk for the current repository.
const Drupal = new DrupalSDK({
url: 'https://drupal-sdk.prod.voide.dev',
});
async fetchData() {
const items = await Drupal.get('node', 'article').read('12f930ee-8a7b-11eb-8dcd-0242ac130003');
await Drupal.login('username', password);
Drupal.get('node').create({
title: 'Lorem ipsum',
});
}
| Name | Description | Type | Required | Default |
|---|---|---|---|---|
| url | The URL of the Drupal environment | string | true | |
| authMode | The authentication mode to use. For now, only "cookie" is available, but "jwt" will be implemented later on. | string | false | cookie |
| storage | The storage object for storing CSRF tokens and jwt tokens. This object must contain a "setItem" and "getItem" method. Only required when using authentication. | object | false | |
| storageKey | The key to use in your storage object. | string | false | drupal-sdk |
| apiBasePath | The api base path to use in the JSON:API related methods | string | false | /jsonapi |
| useDecoupledRouter | Wheter to use a decoupled router method or not. If true, make sure the https://www.drupal.org/project/decoupled_router module is installed in your drupal website | boolean | false | false |
| token | The authentication token for usage without login | string | false | |
| tokenExpirationTime | The expiration time of the login token | number | false | 30000 |
| methods | An object with methods to override. See the list below. | object | false | {} |
For the following methods, overrides are supported.
All methods will come with an injectableProps argument. This is an object of helper classes in the DrupalSDK. Available classes are:
config - The configuration object passed to the main class.api - The API class to perform API calls to.auth - The Authentication helperstorage - The storage helper to store data in.Arguments
Example
const Drupal = new DrupalSDK({
url: 'https://drupal-sdk.voide.dev',
methods: {
getRoute(path, { api }) {
return api.get('/route', { path });
},
},
});
Arguments
Example
const Drupal = new DrupalSDK({
url: 'https://drupal-sdk.voide.dev',
methods: {
readByPath(path, inputParams, { api }) {
return Drupal.getRoute(path).then((json) => api.get(json.path));
},
},
});
Arguments
Example
const Drupal = new DrupalSDK({
url: 'https://drupal-sdk.voide.dev',
methods: {
readByPath(path, inputParams, { api, storage }) {
const body = {
mail,
pass: password,
};
return api
.post('/user/email-login', body, { _format: 'json' })
.then((json) => {
api.setCSRF(json.csrf_token);
storage.setItem('logout_token', json.logout_token);
return json;
});
},
},
});
In the Drupal SDK a proxy layer between the SDK object and the entity is used. In the context of the SDK and Drupal, we call this layer the EntityStorage.
To get the storage of an entity, please use the following code:
const nodeStorage = Drupal.get('node');
The argument of this get-method is the machine name of the entity.
read a Single EntityArguments
await Drupal.get('node').read('12f930ee-8a7b-11eb-8dcd-0242ac130003');
create a Single Entity -Arguments
Drupal.get('node', 'article').create({ attributes: { title: 'Lorem' } }, { filter: { lorem: 'ipsum' } });
update a Single EntityArguments
Drupal.get('node', 'article').update('74518cfa-77ad-11eb-9439-0242ac130002', { attributes: { title: 'Lorem' } });
delete a Single EntityArguments
Drupal.get('node', 'article').delete('74518cfa-77ad-11eb-9439-0242ac130002');
Accessing protected endpoints will be easy using the Drupal SDK. Just login or provide an access token to the configuration object.
For now, only cookie authentication is available, so let's take a look into that.
Arguments
Drupal.login('username', 'password');
Drupal.logout();
This method is not available by default, but can be created in the methods section of the main configuration object.
Arguments
Drupal.loginByEmail('admin@example.com', 'password');
Arguments
Drupal.requestPassword('admin@example.com');
Arguments
Drupal.requestPassword('username');
FAQs
Javascript SDK for Drupal JSON API
The npm package drupal-sdk receives a total of 28 weekly downloads. As such, drupal-sdk popularity was classified as not popular.
We found that drupal-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.