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.17.2 to 0.17.3

14

dist/druxt-router.esm.js

@@ -546,10 +546,14 @@ import { resolve } from 'path';

DruxtRouter.prototype.getRedirect = function getRedirect (path, route) {
if ( route === void 0 ) route = {};
// Redirect to route provided redirect.
if (Array.isArray(route.redirect) && typeof route.redirect[0].to !== 'undefined') {
if (((route.redirect || [])[0] || {}).to) {
return route.redirect[0].to
}
var url = Url(path);
// Redirect to root if route is home path but path isn't root.
if (route.isHomePath) {
if (path !== '/') {
if (url.pathname !== '/') {
return '/'

@@ -563,6 +567,6 @@ }

if (typeof route.canonical === 'string') {
var url = new Url(route.canonical);
var canonicalUrl = new Url(route.canonical);
if (path !== url.pathname) {
return url.pathname
if (url.pathname !== canonicalUrl.pathname) {
return canonicalUrl.pathname
}

@@ -569,0 +573,0 @@ }

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

var DruxtRouter=function(t,e,r,i,n,o,s){"use strict";o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s;function a(t,e,r,i,n,o,s,a,u,d){"boolean"!=typeof s&&(u=a,a=s,s=!1);var c,p="function"==typeof r?r.options:r;if(t&&t.render&&(p.render=t.render,p.staticRenderFns=t.staticRenderFns,p._compiled=!0,n&&(p.functional=!0)),i&&(p._scopeId=i),o?(c=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,u(t)),t&&t._registeredComponents&&t._registeredComponents.add(o)},p._ssrRegister=c):e&&(c=s?function(t){e.call(this,d(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,a(t))}),c)if(p.functional){var f=p.render;p.render=function(t,e){return c.call(e),f(t,e)}}else{var h=p.beforeCreate;p.beforeCreate=h?[].concat(h,c):[c]}return r}var u=a({render:function(){var t=this,e=t.$createElement,r=t._self._c||e;return t.$fetchState.pending?t._e():r(t.wrapper.component,t._b({tag:"component",class:t.wrapper.class,style:t.wrapper.style},"component",t.wrapper.propsData,!1),[r(t.component.is,t._b({tag:"component"},"component",t.component.propsData,!1),[t._v("\n "+t._s(t.route)+"\n ")])],1)},staticRenderFns:[]},undefined,{name:"DruxtRouter",mixins:[r.DruxtComponentMixin],middleware:async function(t){var e=t.store,r=t.redirect,i=t.route,n=await e.dispatch("druxtRouter/get",i.fullPath);n.redirect&&r(n.redirect)},computed:Object.assign({},{module:function(){return!(!(this.route||{}).component||!this.route.component.startsWith("druxt-"))&&this.route.component.substring(6)},title:function(){return this.route.label||!1},props:function(){return this.route.props||!1}},i.mapState({redirect:function(t){return t.druxtRouter.redirect},route:function(t){return t.druxtRouter.route}})),head:function(){return{title:this.title,link:[{rel:"canonical",href:this.canonical||this.route.canonical}],meta:this.metatags||!1}},druxt:function(t){var e=t.vm;return{componentOptions:[[e.module?e.module:"error",e.route.isHomePath?"front":"not-front"],["default"]],propsData:{route:e.route}}}},undefined,false,undefined,!1,void 0,void 0,void 0),d=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),delete e.axios),this.axios=o.create(r),this.options=Object.assign({},{endpoint:"/jsonapi",jsonapiResourceConfig:"jsonapi_resource_config--jsonapi_resource_config",types:[{type:"entity",canonical:function(t){return t.entity.canonical},component:"druxt-entity",property:"entity",props:function(t){return{type:t.jsonapi.resourceName,uuid:t.entity.uuid}}},{type:"views",canonical:function(t){return t.resolved},component:"druxt-view",property:"view",props:function(t){return{displayId:t.view.display_id,type:t.jsonapi.resourceName,uuid:t.view.uuid,viewId:t.view.view_id}}}]},e),this.index=null};d.prototype.addHeaders=function(t){if(void 0===t)return!1;for(var e in t)this.axios.defaults.headers.common[e]=t[e]},d.prototype.buildQueryUrl=function(t,e){return e?"string"==typeof e?"?"===e.charAt(0)?t+e:[t,e].join("?"):"object"==typeof e&&"function"==typeof e.getQueryString?[t,e.getQueryString()].join("?"):"object"==typeof e&&Object.keys(e).length?[t,n.stringify(e)].join("?"):t:t},d.prototype.checkPermissions=function(t){if(t.data.meta&&t.data.meta.omitted){var e={};for(var r in delete t.data.meta.omitted.links.help,t.data.meta.omitted.links){var i=t.data.meta.omitted.links[r].meta.detail.match(/'(.*?)'/);i&&i[1]&&(e[i[1]]=!0)}if(Object.keys(e).length)throw new TypeError(t.data.meta.omitted.detail+"\n\n Required permissions: "+Object.keys(e).join(", ")+".")}},d.prototype.get=async function(t){var e=await this.getRoute(t);return e.error?{route:e}:{redirect:this.getRedirect(t,e),route:e}},d.prototype.getIndex=async function(t){if(this.index&&!t)return this.index;if(this.index&&t)return!!this.index[t]&&this.index[t];var e=await this.axios.get(this.options.endpoint);if(this.index=e.data.links,this.index[this.options.jsonapiResourceConfig]){var r=await this.axios.get(this.index[this.options.jsonapiResourceConfig].href);for(var i in r.data.data){var n=r.data.data[i],o=n.attributes.drupal_internal__id.split("--"),s={resourceType:n.attributes.resourceType,entityType:o[0],bundle:o[1],resourceFields:n.attributes.resourceFields},a=[s.entityType,s.bundle].join("--");this.index[a]=Object.assign({},s,this.index[a])}}return t?!!this.index[t]&&this.index[t]:this.index},d.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.canonical){var r=new s(e.canonical);if(t!==r.pathname)return r.pathname}return!1},d.prototype.getResource=async function(t){void 0===t&&(t={});var e=t.id,r=t.type;if(!e||!r)return!1;var i=(await this.getIndex(r)).href;i||(i=this.options.endpoint+"/"+r.replace("--","/"));var n=i+"/"+e;try{return(await this.axios.get(n)).data.data}catch(t){return!1}},d.prototype.getResources=async function(t,e,r){void 0===r&&(r={});var i=[],n=(await this.getIndex(t)).href;if(!n)return!1;var o=this.buildQueryUrl(n,e);this.addHeaders(r.headers);for(var s=!0;s;){var a=await this.axios.get(o);this.checkPermissions(a),i=i.concat(a.data.data),r.all&&a.data&&a.data.links&&a.data.links.next?o=a.data.links.next.href:s=!1}return i},d.prototype.getResourceByRoute=function(t){return this.getResource({id:t.entity.uuid,type:t.jsonapi.resourceName})},d.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=Object.assign({},{isHomePath:!1,jsonapi:{},label:!1,redirect:!1},r.data),n={error:!1,type:!1,canonical:!1,component:!1,isHomePath:i.isHomePath,jsonapi:i.jsonapi,label:i.label,props:!1,redirect:i.redirect,resolvedPath:s(i.resolved).pathname};for(var o in this.options.types){var a=Object.assign({},this.options.types[o]);if("string"==typeof a.property&&void 0!==i[a.property]){delete a.property,"function"==typeof a.canonical&&(a.canonical=a.canonical(i)),"function"==typeof a.props&&(a.props=a.props(i)),n=Object.assign({},n,a);break}}return r.status>=200&&r.status<300||(n.error={statusCode:r.status,message:r.statusText},n.component="error"),n};var c={props:{mode:{type:String,default:"default"},type:{type:String,required:!0},uuid:{type:String,required:!0}},fetch:async function(){void 0===this.entities[this.uuid]?!this.entity&&this.uuid&&this.type&&(this.entity=await this.getEntity({id:this.uuid,type:this.type}),this.loading=!1):this.entity=this.entities[this.uuid]},data:function(){return{entity:!1,loading:!0}},computed:Object.assign({},i.mapState({entities:function(t){return t.druxtRouter.entities}})),methods:Object.assign({},i.mapActions({getEntity:"druxtRouter/getEntity"}))},p={props:{route:{type:Object,required:!0}}};return t.DruxtRouter=d,t.DruxtRouterComponent=u,t.DruxtRouterEntityMixin=c,t.DruxtRouterMixin=p,t.DruxtRouterStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");var r="druxtRouter";e.registerModule(r,{namespaced:!0,state:function(){return{entities:{},redirect:!1,route:{},routes:{}}},mutations:{addEntity:function(t,e){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,n=(t.state,await i("getRoute",e));if(n.error&&void 0!==n.error.statusCode&&((this.app||{}).context||{}).error)return this.app.context.error(n.error);r("setRoute",e);var o=this.$druxtRouter().getRedirect(e,n);return r("setRedirect",o),{redirect:o,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 n=await this.$druxtRouter().getResource(e);return r("addEntity",n),n},getResources:async function(t,e){t.commit,t.state;var r=e.resource,i=e.query,n=e.options;return await this.$druxtRouter().getResources(r,i,n)},getRoute:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e])return i.routes[e];var n=await this.$druxtRouter().getRoute(e);return r("addRoute",{path:e,route:n}),n}}},{preserveState:Boolean(e.state[r])})},t.default=function(t){var r=this;if(void 0===this.options||!this.options.druxt)throw new TypeError("Druxt settings missing.");var i=this.options.druxt;i.router=i.router||{},this.extendRoutes((function(t,e){i.router.component||(i.router.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.router.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,druxt,vuex,querystring,axios,Url);
var DruxtRouter=function(t,e,r,i,n,o,s){"use strict";o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s;function a(t,e,r,i,n,o,s,a,u,d){"boolean"!=typeof s&&(u=a,a=s,s=!1);var c,p="function"==typeof r?r.options:r;if(t&&t.render&&(p.render=t.render,p.staticRenderFns=t.staticRenderFns,p._compiled=!0,n&&(p.functional=!0)),i&&(p._scopeId=i),o?(c=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,u(t)),t&&t._registeredComponents&&t._registeredComponents.add(o)},p._ssrRegister=c):e&&(c=s?function(t){e.call(this,d(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,a(t))}),c)if(p.functional){var h=p.render;p.render=function(t,e){return c.call(e),h(t,e)}}else{var f=p.beforeCreate;p.beforeCreate=f?[].concat(f,c):[c]}return r}var u=a({render:function(){var t=this,e=t.$createElement,r=t._self._c||e;return t.$fetchState.pending?t._e():r(t.wrapper.component,t._b({tag:"component",class:t.wrapper.class,style:t.wrapper.style},"component",t.wrapper.propsData,!1),[r(t.component.is,t._b({tag:"component"},"component",t.component.propsData,!1),[t._v("\n "+t._s(t.route)+"\n ")])],1)},staticRenderFns:[]},undefined,{name:"DruxtRouter",mixins:[r.DruxtComponentMixin],middleware:async function(t){var e=t.store,r=t.redirect,i=t.route,n=await e.dispatch("druxtRouter/get",i.fullPath);n.redirect&&r(n.redirect)},computed:Object.assign({},{module:function(){return!(!(this.route||{}).component||!this.route.component.startsWith("druxt-"))&&this.route.component.substring(6)},title:function(){return this.route.label||!1},props:function(){return this.route.props||!1}},i.mapState({redirect:function(t){return t.druxtRouter.redirect},route:function(t){return t.druxtRouter.route}})),head:function(){return{title:this.title,link:[{rel:"canonical",href:this.canonical||this.route.canonical}],meta:this.metatags||!1}},druxt:function(t){var e=t.vm;return{componentOptions:[[e.module?e.module:"error",e.route.isHomePath?"front":"not-front"],["default"]],propsData:{route:e.route}}}},undefined,false,undefined,!1,void 0,void 0,void 0),d=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),delete e.axios),this.axios=o.create(r),this.options=Object.assign({},{endpoint:"/jsonapi",jsonapiResourceConfig:"jsonapi_resource_config--jsonapi_resource_config",types:[{type:"entity",canonical:function(t){return t.entity.canonical},component:"druxt-entity",property:"entity",props:function(t){return{type:t.jsonapi.resourceName,uuid:t.entity.uuid}}},{type:"views",canonical:function(t){return t.resolved},component:"druxt-view",property:"view",props:function(t){return{displayId:t.view.display_id,type:t.jsonapi.resourceName,uuid:t.view.uuid,viewId:t.view.view_id}}}]},e),this.index=null};d.prototype.addHeaders=function(t){if(void 0===t)return!1;for(var e in t)this.axios.defaults.headers.common[e]=t[e]},d.prototype.buildQueryUrl=function(t,e){return e?"string"==typeof e?"?"===e.charAt(0)?t+e:[t,e].join("?"):"object"==typeof e&&"function"==typeof e.getQueryString?[t,e.getQueryString()].join("?"):"object"==typeof e&&Object.keys(e).length?[t,n.stringify(e)].join("?"):t:t},d.prototype.checkPermissions=function(t){if(t.data.meta&&t.data.meta.omitted){var e={};for(var r in delete t.data.meta.omitted.links.help,t.data.meta.omitted.links){var i=t.data.meta.omitted.links[r].meta.detail.match(/'(.*?)'/);i&&i[1]&&(e[i[1]]=!0)}if(Object.keys(e).length)throw new TypeError(t.data.meta.omitted.detail+"\n\n Required permissions: "+Object.keys(e).join(", ")+".")}},d.prototype.get=async function(t){var e=await this.getRoute(t);return e.error?{route:e}:{redirect:this.getRedirect(t,e),route:e}},d.prototype.getIndex=async function(t){if(this.index&&!t)return this.index;if(this.index&&t)return!!this.index[t]&&this.index[t];var e=await this.axios.get(this.options.endpoint);if(this.index=e.data.links,this.index[this.options.jsonapiResourceConfig]){var r=await this.axios.get(this.index[this.options.jsonapiResourceConfig].href);for(var i in r.data.data){var n=r.data.data[i],o=n.attributes.drupal_internal__id.split("--"),s={resourceType:n.attributes.resourceType,entityType:o[0],bundle:o[1],resourceFields:n.attributes.resourceFields},a=[s.entityType,s.bundle].join("--");this.index[a]=Object.assign({},s,this.index[a])}}return t?!!this.index[t]&&this.index[t]:this.index},d.prototype.getRedirect=function(t,e){if(void 0===e&&(e={}),((e.redirect||[])[0]||{}).to)return e.redirect[0].to;var r=s(t);if(e.isHomePath)return"/"!==r.pathname&&"/";if("string"==typeof e.canonical){var i=new s(e.canonical);if(r.pathname!==i.pathname)return i.pathname}return!1},d.prototype.getResource=async function(t){void 0===t&&(t={});var e=t.id,r=t.type;if(!e||!r)return!1;var i=(await this.getIndex(r)).href;i||(i=this.options.endpoint+"/"+r.replace("--","/"));var n=i+"/"+e;try{return(await this.axios.get(n)).data.data}catch(t){return!1}},d.prototype.getResources=async function(t,e,r){void 0===r&&(r={});var i=[],n=(await this.getIndex(t)).href;if(!n)return!1;var o=this.buildQueryUrl(n,e);this.addHeaders(r.headers);for(var s=!0;s;){var a=await this.axios.get(o);this.checkPermissions(a),i=i.concat(a.data.data),r.all&&a.data&&a.data.links&&a.data.links.next?o=a.data.links.next.href:s=!1}return i},d.prototype.getResourceByRoute=function(t){return this.getResource({id:t.entity.uuid,type:t.jsonapi.resourceName})},d.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=Object.assign({},{isHomePath:!1,jsonapi:{},label:!1,redirect:!1},r.data),n={error:!1,type:!1,canonical:!1,component:!1,isHomePath:i.isHomePath,jsonapi:i.jsonapi,label:i.label,props:!1,redirect:i.redirect,resolvedPath:s(i.resolved).pathname};for(var o in this.options.types){var a=Object.assign({},this.options.types[o]);if("string"==typeof a.property&&void 0!==i[a.property]){delete a.property,"function"==typeof a.canonical&&(a.canonical=a.canonical(i)),"function"==typeof a.props&&(a.props=a.props(i)),n=Object.assign({},n,a);break}}return r.status>=200&&r.status<300||(n.error={statusCode:r.status,message:r.statusText},n.component="error"),n};var c={props:{mode:{type:String,default:"default"},type:{type:String,required:!0},uuid:{type:String,required:!0}},fetch:async function(){void 0===this.entities[this.uuid]?!this.entity&&this.uuid&&this.type&&(this.entity=await this.getEntity({id:this.uuid,type:this.type}),this.loading=!1):this.entity=this.entities[this.uuid]},data:function(){return{entity:!1,loading:!0}},computed:Object.assign({},i.mapState({entities:function(t){return t.druxtRouter.entities}})),methods:Object.assign({},i.mapActions({getEntity:"druxtRouter/getEntity"}))},p={props:{route:{type:Object,required:!0}}};return t.DruxtRouter=d,t.DruxtRouterComponent=u,t.DruxtRouterEntityMixin=c,t.DruxtRouterMixin=p,t.DruxtRouterStore=function(t){var e=t.store;if(void 0===e)throw new TypeError("Vuex store not found.");var r="druxtRouter";e.registerModule(r,{namespaced:!0,state:function(){return{entities:{},redirect:!1,route:{},routes:{}}},mutations:{addEntity:function(t,e){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,n=(t.state,await i("getRoute",e));if(n.error&&void 0!==n.error.statusCode&&((this.app||{}).context||{}).error)return this.app.context.error(n.error);r("setRoute",e);var o=this.$druxtRouter().getRedirect(e,n);return r("setRedirect",o),{redirect:o,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 n=await this.$druxtRouter().getResource(e);return r("addEntity",n),n},getResources:async function(t,e){t.commit,t.state;var r=e.resource,i=e.query,n=e.options;return await this.$druxtRouter().getResources(r,i,n)},getRoute:async function(t,e){var r=t.commit,i=t.state;if(void 0!==i.routes[e])return i.routes[e];var n=await this.$druxtRouter().getRoute(e);return r("addRoute",{path:e,route:n}),n}}},{preserveState:Boolean(e.state[r])})},t.default=function(t){var r=this;if(void 0===this.options||!this.options.druxt)throw new TypeError("Druxt settings missing.");var i=this.options.druxt;i.router=i.router||{},this.extendRoutes((function(t,e){i.router.component||(i.router.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.router.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,druxt,vuex,querystring,axios,Url);

@@ -531,10 +531,14 @@ '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'),druxt=require('druxt'),vuex=require('vuex'),querystring=require('querystring'),axios=_interopDefault(require('axios')),Url=_interopDefault(require('url-parse'));/**

DruxtRouter.prototype.getRedirect = function getRedirect (path, route) {
if ( route === void 0 ) route = {};
// Redirect to route provided redirect.
if (Array.isArray(route.redirect) && typeof route.redirect[0].to !== 'undefined') {
if (((route.redirect || [])[0] || {}).to) {
return route.redirect[0].to
}
var url = Url(path);
// Redirect to root if route is home path but path isn't root.
if (route.isHomePath) {
if (path !== '/') {
if (url.pathname !== '/') {
return '/'

@@ -548,6 +552,6 @@ }

if (typeof route.canonical === 'string') {
var url = new Url(route.canonical);
var canonicalUrl = new Url(route.canonical);
if (path !== url.pathname) {
return url.pathname
if (url.pathname !== canonicalUrl.pathname) {
return canonicalUrl.pathname
}

@@ -554,0 +558,0 @@ }

{
"name": "druxt-router",
"version": "0.17.2",
"version": "0.17.3",
"description": "Simple decoupled Drupal routing for Nuxt.",

@@ -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