Socket
Socket
Sign inDemoInstall

druxt-router

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

druxt-router - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

83

dist/druxt-router.esm.js

@@ -27,8 +27,12 @@ import { resolve } from 'path';

mapState({
entity: function (state) { return state.druxtRouter.entities[state.druxtRouter.route.entity.uuid]; },
entity: function (state) { return state.druxtRouter.entities[state.druxtRouter.route.data.entity.uuid]; },
redirect: function (state) { return state.druxtRouter.redirect; },
route: function (state) { return state.druxtRouter.route; }
route: function (state) { return state.druxtRouter.route.data; }
})),
render: function render (createElement) {
if (typeof this.entity === 'undefined') {
return
}
return createElement('div', {

@@ -40,3 +44,3 @@ key: this.route.entity.uuid,

}
}, JSON.stringify(this.route))
}, JSON.stringify(this.entity.data))
},

@@ -92,3 +96,8 @@

DruxtRouter.prototype.get = async function get (path) {
var route = await this.getRoute(path);
var ref = await this.getRoute(path);
var route = ref.data;
var routeError = ref.error;
if (routeError) {
return { route: route, error: routeError }
}

@@ -175,5 +184,19 @@ var redirect = this.getRedirect(path, route);

var url = "/router/translate-path?path=" + path;
var response = await this.axios.get(url);
return response.data
var response = await this.axios.get(url, {
// Prevent invalid routes (404) from throwing validation errors.
validateStatus: function (status) { return status < 500; }
});
var data = response.data;
// Process Axios error.
var error = false;
if (!(response.status >= 200 && response.status < 300)) {
error = {
statusCode: response.status,
message: response.statusText
};
}
return { data: data, error: error }
};

@@ -295,47 +318,25 @@

actions: {
// @TODO - Change this to use the 'getRoute' and 'getEntity' actions.
get: async function get (ref, path) {
var commit = ref.commit;
var dispatch = ref.dispatch;
var state = ref.state;
// Return cached data, if present.
// @TODO - Handle cache busting.
if (typeof state.routes[path] !== 'undefined' && typeof state.entities[state.routes[path].entity.uuid] !== 'undefined') {
var route = state.entities[state.routes[path].entity.uuid];
var redirect = this.$druxtRouter().getRedirect(path, route);
var entity = state.entities[state.routes[path].entity.uuid];
// Get route by path from 'getRoute'.
var ref$1 = await dispatch('getRoute', path);
var route = ref$1.data;
var routeError = ref$1.error;
commit('setRoute', path);
commit('setRedirect', redirect);
return { entity: entity, redirect: redirect, route: route }
// Handle route errors.
if (typeof routeError.statusCode !== 'undefined') {
return this.app.context.error(routeError)
}
// Get data from router.
try {
var ref$1 = await this.$druxtRouter().get(path);
var entity$1 = ref$1.entity;
var redirect$1 = ref$1.redirect;
var route$1 = ref$1.route;
commit('setRoute', path);
commit('addRoute', { path: path, redirect: redirect$1, route: route$1 });
commit('setRoute', path);
var redirect = this.$druxtRouter().getRedirect(path, route);
commit('setRedirect', redirect);
commit('setRedirect', redirect$1);
var entity = await dispatch('getEntity', { id: route.entity.uuid, type: route.jsonapi.resourceName });
commit('addEntity', entity$1);
return { entity: entity$1, redirect: redirect$1, route: route$1 }
// Handle errors.
} catch (err) {
if (typeof err.response === 'undefined') {
throw err
}
return this.app.context.error({
statusCode: err.response.status,
message: err.response.statusText
})
}
return { entity: entity, redirect: redirect, route: route }
},

@@ -342,0 +343,0 @@

@@ -1,1 +0,1 @@

var DruxtRouter=function(t,e,r,i,o){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i,o=o&&o.hasOwnProperty("default")?o.default:o;var n={name:"druxt-router",head:function(){return{title:this.title,link:[{rel:"canonical",href:this.canonical||this.route.entity.canonical}],meta:this.metatags||!1}},computed:Object.assign({},{title:function(){return this.route.label}},r.mapState({entity:function(t){return t.druxtRouter.entities[t.druxtRouter.route.entity.uuid]},redirect:function(t){return t.druxtRouter.redirect},route:function(t){return t.druxtRouter.route}})),render:function(t){return t("div",{key:this.route.entity.uuid,props:{type:""+this.route.jsonapi.resourceName,uuid:this.route.entity.uuid}},JSON.stringify(this.route))},fetch:async function(t){var e=t.store,r=t.redirect,i=t.route,o=await e.dispatch("druxtRouter/get",i.fullPath);o.redirect&&r(o.redirect)}},u=function(t,e){if(void 0===e&&(e={}),!t)throw new Error("The 'baseURL' parameter is required.");var r={baseURL:t};"object"==typeof e.axios&&(r=Object.assign(r,e.axios)),this.axios=i.create(r),this.setOptions(e)};u.prototype.setOptions=function(t){void 0===t&&(t={}),"function"==typeof t.preprocessEntity&&(this.preprocessEntity=t.preprocessEntity)},u.prototype.get=async function(t){var e=await this.getRoute(t),r=this.getRedirect(t,e);return{entity:await this.getResourceByRoute(e),redirect:r,route:e}},u.prototype.getRedirect=function(t,e){if(Array.isArray(e.redirect)&&void 0!==e.redirect[0].to)return e.redirect[0].to;if(e.isHomePath)return"/"!==t&&"/";if("string"==typeof e.resolved){var r=new o(e.resolved);if(t!==r.pathname)return r.pathname}return!1},u.prototype.getResource=async function(t){var e=t.id,r=t.type,i="/api/"+r.replace("--","/")+"/"+e,o=await this.axios.get(i),n={id:e,type:r,data:o.data};return this.preprocessEntity&&(n._raw=n.data,n.data=await this.preprocessEntity(o)),n},u.prototype.getResourceByRoute=function(t){return this.getResource({id:t.entity.uuid,type:t.jsonapi.resourceName})},u.prototype.getRoute=async function(t){var e="/router/translate-path?path="+t;return(await this.axios.get(e)).data};var s=require("vuex"),a={props:{uuid:{type:String,required:!0},type:{type:String,required:!0}},created:function(){var t=this;void 0===this.entities[this.uuid]&&(this.loading=!0,this.getEntity({id:this.uuid,type:this.type}).then((function(e){t.loading="function"==typeof t.onDruxtRouterLoad&&!!t.onDruxtRouterLoad(e)})))},data:function(){return{loading:!1}},computed:Object.assign({},{entity:function(){return this.entities[this.uuid]},ready:function(){return!this.loading&&!!this.entity}},s.mapState({entities:function(t){return t.druxtRouter.entities}})),methods:Object.assign({},s.mapActions({getEntity:"druxtRouter/getEntity"}))};return t.DruxtRouter=u,t.DruxtRouterComponent=n,t.DruxtRouterEntityMixin=a,t.DruxtRouterStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");e.registerModule("druxtRouter",{namespaced:!0,state:function(){return{entities:{},redirect:!1,route:{},routes:{}}},mutations:{addEntity:function(t,e){void 0!==e.id&&(t.entities[e.id]=e)},setRedirect:function(t,e){t.redirect=e},addRoute:function(t,e){var r=e.path,i=e.route;"string"==typeof r&&void 0!==i&&(t.routes[r]=i)},setRoute:function(t,e){"string"==typeof e&&void 0!==t.routes[e]&&(t.route=t.routes[e])}},actions:{get:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e]&&void 0!==i.entities[i.routes[e].entity.uuid]){var o=i.entities[i.routes[e].entity.uuid],n=this.$druxtRouter().getRedirect(e,o),u=i.entities[i.routes[e].entity.uuid];return r("setRoute",e),r("setRedirect",n),{entity:u,redirect:n,route:o}}try{var s=await this.$druxtRouter().get(e),a=s.entity,d=s.redirect,c=s.route;return r("addRoute",{path:e,redirect:d,route:c}),r("setRoute",e),r("setRedirect",d),r("addEntity",a),{entity:a,redirect:d,route:c}}catch(t){if(void 0===t.response)throw t;return this.app.context.error({statusCode:t.response.status,message:t.response.statusText})}},getEntity:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.entities[e.id])return i.entities[e.id];var o=await this.$druxtRouter().getResource(e);return r("addEntity",o),o},getRoute:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e])return i.routes[e];var o=await this.$druxtRouter().getRoute(e);return r("addRoute",{path:e,route:o}),o}}},{preserveState:Boolean(e.state.druxtRouter)})},t.default=function(t){var r=this;void 0===t&&(t={});var i=Object.assign({},this.options["druxt-router"],t);this.extendRoutes((function(t,e){i.component||(i.component=e(r.options.buildDir,"components/druxt-router.js"),r.addTemplate({src:e(__dirname,"../nuxt/component.js"),fileName:"components/druxt-router.js",options:i})),t.push({name:"druxt-router",path:"*",component:i.component,chunkName:"druxt-router"})})),this.addPlugin({src:e.resolve(__dirname,"../nuxt/plugin.js"),fileName:"druxt-router.js",options:i}),this.addPlugin({src:e.resolve(__dirname,"../nuxt/store.js"),fileName:"store/druxt-router.js",options:i})},t}({},path,vuex,axios,Url);
var DruxtRouter=function(t,e,r,i,o){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i,o=o&&o.hasOwnProperty("default")?o.default:o;var n={name:"druxt-router",head:function(){return{title:this.title,link:[{rel:"canonical",href:this.canonical||this.route.entity.canonical}],meta:this.metatags||!1}},computed:Object.assign({},{title:function(){return this.route.label}},r.mapState({entity:function(t){return t.druxtRouter.entities[t.druxtRouter.route.data.entity.uuid]},redirect:function(t){return t.druxtRouter.redirect},route:function(t){return t.druxtRouter.route.data}})),render:function(t){if(void 0!==this.entity)return t("div",{key:this.route.entity.uuid,props:{type:""+this.route.jsonapi.resourceName,uuid:this.route.entity.uuid}},JSON.stringify(this.entity.data))},fetch:async function(t){var e=t.store,r=t.redirect,i=t.route,o=await e.dispatch("druxtRouter/get",i.fullPath);o.redirect&&r(o.redirect)}},u=function(t,e){if(void 0===e&&(e={}),!t)throw new Error("The 'baseURL' parameter is required.");var r={baseURL:t};"object"==typeof e.axios&&(r=Object.assign(r,e.axios)),this.axios=i.create(r),this.setOptions(e)};u.prototype.setOptions=function(t){void 0===t&&(t={}),"function"==typeof t.preprocessEntity&&(this.preprocessEntity=t.preprocessEntity)},u.prototype.get=async function(t){var e=await this.getRoute(t),r=e.data,i=e.error;if(i)return{route:r,error:i};var o=this.getRedirect(t,r);return{entity:await this.getResourceByRoute(r),redirect:o,route:r}},u.prototype.getRedirect=function(t,e){if(Array.isArray(e.redirect)&&void 0!==e.redirect[0].to)return e.redirect[0].to;if(e.isHomePath)return"/"!==t&&"/";if("string"==typeof e.resolved){var r=new o(e.resolved);if(t!==r.pathname)return r.pathname}return!1},u.prototype.getResource=async function(t){var e=t.id,r=t.type,i="/api/"+r.replace("--","/")+"/"+e,o=await this.axios.get(i),n={id:e,type:r,data:o.data};return this.preprocessEntity&&(n._raw=n.data,n.data=await this.preprocessEntity(o)),n},u.prototype.getResourceByRoute=function(t){return this.getResource({id:t.entity.uuid,type:t.jsonapi.resourceName})},u.prototype.getRoute=async function(t){var e="/router/translate-path?path="+t,r=await this.axios.get(e,{validateStatus:function(t){return t<500}}),i=r.data,o=!1;return r.status>=200&&r.status<300||(o={statusCode:r.status,message:r.statusText}),{data:i,error:o}};var a=require("vuex"),s={props:{uuid:{type:String,required:!0},type:{type:String,required:!0}},created:function(){var t=this;void 0===this.entities[this.uuid]&&(this.loading=!0,this.getEntity({id:this.uuid,type:this.type}).then((function(e){t.loading="function"==typeof t.onDruxtRouterLoad&&!!t.onDruxtRouterLoad(e)})))},data:function(){return{loading:!1}},computed:Object.assign({},{entity:function(){return this.entities[this.uuid]},ready:function(){return!this.loading&&!!this.entity}},a.mapState({entities:function(t){return t.druxtRouter.entities}})),methods:Object.assign({},a.mapActions({getEntity:"druxtRouter/getEntity"}))};return t.DruxtRouter=u,t.DruxtRouterComponent=n,t.DruxtRouterEntityMixin=s,t.DruxtRouterStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");e.registerModule("druxtRouter",{namespaced:!0,state:function(){return{entities:{},redirect:!1,route:{},routes:{}}},mutations:{addEntity:function(t,e){void 0!==e.id&&(t.entities[e.id]=e)},setRedirect:function(t,e){t.redirect=e},addRoute:function(t,e){var r=e.path,i=e.route;"string"==typeof r&&void 0!==i&&(t.routes[r]=i)},setRoute:function(t,e){"string"==typeof e&&void 0!==t.routes[e]&&(t.route=t.routes[e])}},actions:{get:async function(t,e){var r=t.commit,i=t.dispatch,o=(t.state,await i("getRoute",e)),n=o.data,u=o.error;if(void 0!==u.statusCode)return this.app.context.error(u);r("setRoute",e);var a=this.$druxtRouter().getRedirect(e,n);return r("setRedirect",a),{entity:await i("getEntity",{id:n.entity.uuid,type:n.jsonapi.resourceName}),redirect:a,route:n}},getEntity:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.entities[e.id])return i.entities[e.id];var o=await this.$druxtRouter().getResource(e);return r("addEntity",o),o},getRoute:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e])return i.routes[e];var o=await this.$druxtRouter().getRoute(e);return r("addRoute",{path:e,route:o}),o}}},{preserveState:Boolean(e.state.druxtRouter)})},t.default=function(t){var r=this;void 0===t&&(t={});var i=Object.assign({},this.options["druxt-router"],t);this.extendRoutes((function(t,e){i.component||(i.component=e(r.options.buildDir,"components/druxt-router.js"),r.addTemplate({src:e(__dirname,"../nuxt/component.js"),fileName:"components/druxt-router.js",options:i})),t.push({name:"druxt-router",path:"*",component:i.component,chunkName:"druxt-router"})})),this.addPlugin({src:e.resolve(__dirname,"../nuxt/plugin.js"),fileName:"druxt-router.js",options:i}),this.addPlugin({src:e.resolve(__dirname,"../nuxt/store.js"),fileName:"store/druxt-router.js",options:i})},t}({},path,vuex,axios,Url);

@@ -22,8 +22,12 @@ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var path=require('path'),vuex$1=require('vuex'),axios=_interopDefault(require('axios')),Url=_interopDefault(require('url-parse'));var DruxtRouterComponent = {

vuex$1.mapState({
entity: function (state) { return state.druxtRouter.entities[state.druxtRouter.route.entity.uuid]; },
entity: function (state) { return state.druxtRouter.entities[state.druxtRouter.route.data.entity.uuid]; },
redirect: function (state) { return state.druxtRouter.redirect; },
route: function (state) { return state.druxtRouter.route; }
route: function (state) { return state.druxtRouter.route.data; }
})),
render: function render (createElement) {
if (typeof this.entity === 'undefined') {
return
}
return createElement('div', {

@@ -35,3 +39,3 @@ key: this.route.entity.uuid,

}
}, JSON.stringify(this.route))
}, JSON.stringify(this.entity.data))
},

@@ -85,3 +89,8 @@

DruxtRouter.prototype.get = async function get (path) {
var route = await this.getRoute(path);
var ref = await this.getRoute(path);
var route = ref.data;
var routeError = ref.error;
if (routeError) {
return { route: route, error: routeError }
}

@@ -168,5 +177,19 @@ var redirect = this.getRedirect(path, route);

var url = "/router/translate-path?path=" + path;
var response = await this.axios.get(url);
return response.data
var response = await this.axios.get(url, {
// Prevent invalid routes (404) from throwing validation errors.
validateStatus: function (status) { return status < 500; }
});
var data = response.data;
// Process Axios error.
var error = false;
if (!(response.status >= 200 && response.status < 300)) {
error = {
statusCode: response.status,
message: response.statusText
};
}
return { data: data, error: error }
};var vuex = require('vuex');

@@ -284,47 +307,25 @@

actions: {
// @TODO - Change this to use the 'getRoute' and 'getEntity' actions.
get: async function get (ref, path) {
var commit = ref.commit;
var dispatch = ref.dispatch;
var state = ref.state;
// Return cached data, if present.
// @TODO - Handle cache busting.
if (typeof state.routes[path] !== 'undefined' && typeof state.entities[state.routes[path].entity.uuid] !== 'undefined') {
var route = state.entities[state.routes[path].entity.uuid];
var redirect = this.$druxtRouter().getRedirect(path, route);
var entity = state.entities[state.routes[path].entity.uuid];
// Get route by path from 'getRoute'.
var ref$1 = await dispatch('getRoute', path);
var route = ref$1.data;
var routeError = ref$1.error;
commit('setRoute', path);
commit('setRedirect', redirect);
return { entity: entity, redirect: redirect, route: route }
// Handle route errors.
if (typeof routeError.statusCode !== 'undefined') {
return this.app.context.error(routeError)
}
// Get data from router.
try {
var ref$1 = await this.$druxtRouter().get(path);
var entity$1 = ref$1.entity;
var redirect$1 = ref$1.redirect;
var route$1 = ref$1.route;
commit('setRoute', path);
commit('addRoute', { path: path, redirect: redirect$1, route: route$1 });
commit('setRoute', path);
var redirect = this.$druxtRouter().getRedirect(path, route);
commit('setRedirect', redirect);
commit('setRedirect', redirect$1);
var entity = await dispatch('getEntity', { id: route.entity.uuid, type: route.jsonapi.resourceName });
commit('addEntity', entity$1);
return { entity: entity$1, redirect: redirect$1, route: route$1 }
// Handle errors.
} catch (err) {
if (typeof err.response === 'undefined') {
throw err
}
return this.app.context.error({
statusCode: err.response.status,
message: err.response.statusText
})
}
return { entity: entity, redirect: redirect, route: route }
},

@@ -331,0 +332,0 @@

{
"name": "druxt-router",
"version": "0.7.0",
"version": "0.8.0",
"description": "Provides a Nuxt <-> Drupal router.",

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

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