Socket
Socket
Sign inDemoInstall

druxt

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

druxt - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

7

CHANGELOG.md
# druxt
## 0.16.0
### Minor Changes
- dc226c2: Made the \$druxt plugin first to be available to all Druxt module plugins.
- 7b749bd: Added improved error handling.
## 0.15.0

@@ -4,0 +11,0 @@

112

dist/druxt.esm.js

@@ -12,3 +12,3 @@ import chalk from 'chalk';

var name = "druxt";
var version = "0.15.0";
var version = "0.16.0";
var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";

@@ -131,2 +131,11 @@ var keywords = [

});
const extendPlugins = this.options.extendPlugins;
this.options.extendPlugins = (plugins) => {
plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
const index = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
const plugin = plugins[index];
plugins.splice(index, 1);
plugins.unshift(plugin);
return plugins;
};
this.addPlugin({

@@ -142,3 +151,2 @@ src: resolve(__dirname, "../templates/store.js"),

};
DruxtNuxtModule.meta = meta;

@@ -212,5 +220,12 @@ class DruxtClient {

if (Object.keys(permissions).length) {
throw new TypeError(`${res.data.meta.omitted.detail}
Required permissions: ${Object.keys(permissions).join(", ")}.`);
const err = {
response: {
statusText: res.data.meta.omitted.detail,
data: {
errors: [{ detail: `Required permissions:
- ${Object.keys(permissions).join("\n - ")}` }]
}
}
};
throw err;
}

@@ -235,6 +250,37 @@ }

} catch (err) {
response = (err.response || {}).data || err.message;
this.error(err, { url: href });
}
return response;
}
error(err, context = {}) {
let { url } = context;
if (!url && ((err.response || {}).config || {}).url) {
url = err.response.config.url;
}
const title = [
(err.response || {}).status,
(err.response || {}).statusText || err.message
].filter((s) => s).join(": ");
const meta = { url: url && [this.options.baseUrl, url].join("") };
let message = [title];
if (Object.values(meta).filter((o) => o).length) {
message.push(Object.entries(meta).filter(([, v]) => v).map(([key, value]) => `${key.toUpperCase()}: ${value}`).join("\n"));
}
if (((((err.response || {}).data || {}).errors || [])[0] || {}).detail) {
message.push(err.response.data.errors[0].detail);
}
const error = Error(message.join("\n\n"));
error.response = err.response;
error.druxt = context;
throw error;
}
async get(url, options) {
try {
const res = await this.axios.get(url, options);
this.checkPermissions(res);
return res;
} catch (err) {
this.error(err, { url });
}
}
async getCollection(type, query) {

@@ -246,5 +292,4 @@ const { href } = await this.getIndex(type);

const url = this.buildQueryUrl(href, query);
const res = await this.axios.get(url);
this.checkPermissions(res);
return res.data;
const { data } = await this.get(url);
return data;
}

@@ -269,3 +314,9 @@ async getCollectionAll(type, query) {

}
let index = ((await this.axios.get(this.options.endpoint) || {}).data || {}).links;
const url = this.options.endpoint;
const { data } = await this.get(url);
let index = data.links;
if (typeof index !== "object") {
const err = { response: { statusText: "Invalid JSON:API endpoint" } };
this.error(err, { url });
}
const baseUrl = this.options.baseUrl;

@@ -277,5 +328,10 @@ index = Object.fromEntries(Object.entries(index).map(([key, value]) => {

if (index[this.options.jsonapiResourceConfig]) {
const resources = await this.axios.get(index[this.options.jsonapiResourceConfig].href);
for (const resourceType in resources.data.data) {
const resource2 = resources.data.data[resourceType];
let resources = [];
try {
resources = (await this.get(index[this.options.jsonapiResourceConfig].href)).data.data;
} catch (err) {
this.log.warn(err.message);
}
for (const resourceType in resources) {
const resource2 = resources[resourceType];
const internal = resource2.attributes.drupal_internal__id.split("--");

@@ -296,7 +352,3 @@ const item = {

this.index = index;
if (resource) {
const response = this.index[resource] ? this.index[resource] : false;
return response;
}
return this.index;
return resource ? this.index[resource] || false : this.index;
}

@@ -312,8 +364,4 @@ async getRelated(type, id, related, query) {

const url = this.buildQueryUrl(`${href}/${id}/${related}`, query);
try {
const related2 = await this.axios.get(url);
return related2.data;
} catch (e) {
return false;
}
const { data } = await this.get(url);
return data;
}

@@ -328,9 +376,5 @@ async getResource(type, id, query) {

}
const url = this.buildQueryUrl(`${href}/${id}`, query);
try {
const resource = await this.axios.get(url);
return resource.data;
} catch (e) {
return false;
}
const url = this.buildQueryUrl([href, id].join("/"), query);
const { data } = await this.get(url);
return data;
}

@@ -351,3 +395,3 @@ async updateResource(resource) {

} catch (err) {
response = (err.response || {}).data || err.message;
this.error(err);
}

@@ -363,3 +407,3 @@ return response;

const dehydrateResources = ({ commit, queryObject, resources }) => {
return resources.map((data) => {
return (resources || []).map((data) => {
const link = decodeURI(((data.links || {}).self || {}).href || "");

@@ -555,3 +599,5 @@ const href = typeof (queryObject.fields || {})[data.type] === "string" ? [link.split("?")[0], `fields[${data.type}]=${queryObject.fields[data.type]}`].join("?") : link;

DruxtNuxtModule.meta = require("../package.json");
export default DruxtNuxtModule;
export { DruxtClass, DruxtClient, DruxtStore };

@@ -25,3 +25,3 @@ 'use strict';

var name = "druxt";
var version = "0.15.0";
var version = "0.16.0";
var description = "The Fully Decoupled Drupal Framework for Nuxt.js.";

@@ -144,2 +144,11 @@ var keywords = [

});
const extendPlugins = this.options.extendPlugins;
this.options.extendPlugins = (plugins) => {
plugins = typeof extendPlugins === "function" ? extendPlugins(plugins) : plugins;
const index = plugins.findIndex(({ src }) => src === `${this.options.buildDir}/druxt.js`);
const plugin = plugins[index];
plugins.splice(index, 1);
plugins.unshift(plugin);
return plugins;
};
this.addPlugin({

@@ -155,3 +164,2 @@ src: path.resolve(__dirname, "../templates/store.js"),

};
DruxtNuxtModule.meta = meta;

@@ -225,5 +233,12 @@ class DruxtClient {

if (Object.keys(permissions).length) {
throw new TypeError(`${res.data.meta.omitted.detail}
Required permissions: ${Object.keys(permissions).join(", ")}.`);
const err = {
response: {
statusText: res.data.meta.omitted.detail,
data: {
errors: [{ detail: `Required permissions:
- ${Object.keys(permissions).join("\n - ")}` }]
}
}
};
throw err;
}

@@ -248,6 +263,37 @@ }

} catch (err) {
response = (err.response || {}).data || err.message;
this.error(err, { url: href });
}
return response;
}
error(err, context = {}) {
let { url } = context;
if (!url && ((err.response || {}).config || {}).url) {
url = err.response.config.url;
}
const title = [
(err.response || {}).status,
(err.response || {}).statusText || err.message
].filter((s) => s).join(": ");
const meta = { url: url && [this.options.baseUrl, url].join("") };
let message = [title];
if (Object.values(meta).filter((o) => o).length) {
message.push(Object.entries(meta).filter(([, v]) => v).map(([key, value]) => `${key.toUpperCase()}: ${value}`).join("\n"));
}
if (((((err.response || {}).data || {}).errors || [])[0] || {}).detail) {
message.push(err.response.data.errors[0].detail);
}
const error = Error(message.join("\n\n"));
error.response = err.response;
error.druxt = context;
throw error;
}
async get(url, options) {
try {
const res = await this.axios.get(url, options);
this.checkPermissions(res);
return res;
} catch (err) {
this.error(err, { url });
}
}
async getCollection(type, query) {

@@ -259,5 +305,4 @@ const { href } = await this.getIndex(type);

const url = this.buildQueryUrl(href, query);
const res = await this.axios.get(url);
this.checkPermissions(res);
return res.data;
const { data } = await this.get(url);
return data;
}

@@ -282,3 +327,9 @@ async getCollectionAll(type, query) {

}
let index = ((await this.axios.get(this.options.endpoint) || {}).data || {}).links;
const url = this.options.endpoint;
const { data } = await this.get(url);
let index = data.links;
if (typeof index !== "object") {
const err = { response: { statusText: "Invalid JSON:API endpoint" } };
this.error(err, { url });
}
const baseUrl = this.options.baseUrl;

@@ -290,5 +341,10 @@ index = Object.fromEntries(Object.entries(index).map(([key, value]) => {

if (index[this.options.jsonapiResourceConfig]) {
const resources = await this.axios.get(index[this.options.jsonapiResourceConfig].href);
for (const resourceType in resources.data.data) {
const resource2 = resources.data.data[resourceType];
let resources = [];
try {
resources = (await this.get(index[this.options.jsonapiResourceConfig].href)).data.data;
} catch (err) {
this.log.warn(err.message);
}
for (const resourceType in resources) {
const resource2 = resources[resourceType];
const internal = resource2.attributes.drupal_internal__id.split("--");

@@ -309,7 +365,3 @@ const item = {

this.index = index;
if (resource) {
const response = this.index[resource] ? this.index[resource] : false;
return response;
}
return this.index;
return resource ? this.index[resource] || false : this.index;
}

@@ -325,8 +377,4 @@ async getRelated(type, id, related, query) {

const url = this.buildQueryUrl(`${href}/${id}/${related}`, query);
try {
const related2 = await this.axios.get(url);
return related2.data;
} catch (e) {
return false;
}
const { data } = await this.get(url);
return data;
}

@@ -341,9 +389,5 @@ async getResource(type, id, query) {

}
const url = this.buildQueryUrl(`${href}/${id}`, query);
try {
const resource = await this.axios.get(url);
return resource.data;
} catch (e) {
return false;
}
const url = this.buildQueryUrl([href, id].join("/"), query);
const { data } = await this.get(url);
return data;
}

@@ -364,3 +408,3 @@ async updateResource(resource) {

} catch (err) {
response = (err.response || {}).data || err.message;
this.error(err);
}

@@ -376,3 +420,3 @@ return response;

const dehydrateResources = ({ commit, queryObject, resources }) => {
return resources.map((data) => {
return (resources || []).map((data) => {
const link = decodeURI(((data.links || {}).self || {}).href || "");

@@ -568,2 +612,4 @@ const href = typeof (queryObject.fields || {})[data.type] === "string" ? [link.split("?")[0], `fields[${data.type}]=${queryObject.fields[data.type]}`].join("?") : link;

DruxtNuxtModule.meta = require("../package.json");
exports.DruxtClass = DruxtClass;

@@ -570,0 +616,0 @@ exports.DruxtClient = DruxtClient;

{
"name": "druxt",
"version": "0.15.0",
"version": "0.16.0",
"description": "The Fully Decoupled Drupal Framework for Nuxt.js.",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

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