sails-hook-adminx
Advanced tools
Comparing version 0.0.10 to 0.1.0
@@ -45,3 +45,3 @@ /** | ||
.sort(sort) | ||
.paginate({page:page, limit:limit}) | ||
.paginate(page, limit) | ||
.then(function (items) { | ||
@@ -71,2 +71,3 @@ return model.count() | ||
model.create(item) | ||
.fetch() | ||
.then(resultFilterAll) | ||
@@ -84,4 +85,5 @@ .then(res.ok) | ||
if (!model) return res.badRequest('schema doesn\'t exist'); | ||
if (!id) return res.badRequest('id not provided'); | ||
model.findOneById(id) | ||
model.findOne({ id: id }) | ||
.populateAll() | ||
@@ -101,9 +103,8 @@ .then(resultFilterAll) | ||
if (!model) return res.badRequest('schema doesn\'t exist'); | ||
if (!id) return res.badRequest('id not provided'); | ||
if (!item || !_.isObject(item)) return res.badRequest('item not provided'); | ||
model.update( | ||
{ id: id }, | ||
item) | ||
.then(_.last) | ||
model.update({ id: id }, item) | ||
.then(function (item) { | ||
return model.findOneById(id) | ||
return model.findOne({ id: id }) | ||
.populateAll(); | ||
@@ -142,3 +143,4 @@ }) | ||
model.destroy(id) | ||
model.destroy({ id: id }) | ||
.fetch() | ||
.then(_.last) | ||
@@ -168,3 +170,3 @@ .then(resultFilterAll) // Bypass 'protected' attrs | ||
var sailsAttrs = _.clone(model._attributes); | ||
var sailsAttrs = _.clone(model.attributes); | ||
if(!sailsAttrs) { | ||
@@ -200,5 +202,8 @@ throw Error('AdminX can\'t find Sails attributes, are you sure you\'re running a compatible Sails verion?'); | ||
var type = item.type; | ||
var o = {}; | ||
// Make sure we don't search on dates | ||
if (type !== 'date' && type !== 'datetime') { | ||
var o = {}; | ||
if(type == 'number') { | ||
o[index] = query; | ||
where.or.push(o); | ||
} else if (type !== 'datetime') { | ||
o[index] = { contains: query }; | ||
@@ -205,0 +210,0 @@ where.or.push(o); |
@@ -28,16 +28,16 @@ /** | ||
// securityLevel: 2, | ||
origin: [ | ||
allowOrigins: [ | ||
'http://adminx.io', | ||
'https://adminx.io', | ||
'http://adminx-production.herokuapp.com', | ||
'https://adminx-production.herokuapp.com', | ||
'http://adminx-production.herokuapp.com', // Temporary safe failback until stable DNS | ||
'https://adminx-production.herokuapp.com', // Temporary safe failback until stable DNS | ||
'http://staging.adminx.io', | ||
'https://staging.adminx.io', | ||
'http://adminx-staging.herokuapp.com', | ||
'https://adminx-staging.herokuapp.com' | ||
].join(','), | ||
'http://adminx-staging.herokuapp.com', // Temporary safe failback until stable DNS | ||
'https://adminx-staging.herokuapp.com' // Temporary safe failback until stable DNS | ||
], | ||
credentials: false, | ||
methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD', | ||
headers: 'content-type,adminx-data-auth-token' //WARNING: This doesn't seem to work, but leaving it. | ||
allowCredentials: false, | ||
allowRequestMethods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD', | ||
allowRequestHeaders: 'content-type,adminx-data-auth-token' //WARNING: This doesn't seem to work, but leaving it. | ||
} | ||
@@ -44,0 +44,0 @@ } |
98
index.js
@@ -0,3 +1,6 @@ | ||
const adminxHeaderAuth = require('./api/policies/adminxHeaderAuth'); | ||
const adminxController = require('./api/controllers/AdminXController'); | ||
module.exports = function (sails) { | ||
var loader = require('sails-util-mvcsloader')(sails); | ||
// var loader = require('sails-util-mvcsloader')(sails); | ||
@@ -9,2 +12,11 @@ // Declare a var that will act as a reference to this hook. | ||
/* --------- | ||
* DEFAULTS | ||
* --------- | ||
* The defaults feature can be implemented either as an object or a function which takes a single argument (see “using | ||
* defaults as a function” below) and returns an object. The object you specify will be used to provide default | ||
* configuration values for Sails. You should use this feature to specify default settings for your hook. | ||
* | ||
* https://next.sailsjs.com/documentation/concepts/extending-sails/hooks/hook-specification/defaults | ||
*/ | ||
defaults: { | ||
@@ -15,11 +27,17 @@ adminx: { | ||
}, | ||
policies: { | ||
AdminXController: { | ||
'*': ['adminxHeaderAuth'] | ||
}, | ||
} | ||
//_hookTimeout: 20000 // wait 20 seconds before timing out | ||
}, | ||
/* ---------- | ||
* CONFIGURE | ||
* ---------- | ||
* The configure feature provides a way to configure a hook after the defaults objects have been applied to all hooks. | ||
* By the time a custom hook’s configure() function runs, all user-level configuration and core hook settings will | ||
* have been merged into sails.config. However, you should not depend on other custom hooks’ configuration at this point, | ||
* as the load order of custom hooks is not guaranteed. | ||
* | ||
* https://next.sailsjs.com/documentation/concepts/extending-sails/hooks/hook-specification/configure | ||
*/ | ||
configure: function () { | ||
// Load policies under ./api/policies and config under ./config | ||
/*// Load policies under ./api/policies and config under ./config | ||
// https://github.com/leeroybrun/sails-util-mvcsloader#loading-config--policies | ||
@@ -29,14 +47,20 @@ loader.configure({ | ||
config: __dirname + '/config' // Path to the config to load | ||
}); | ||
});*/ | ||
//SAILS BUG: It seems sails OPTIONS requests don't return the headers configured on a per-route basis | ||
//SOLUTION: Modify sails.config.headers on the fly to add ours | ||
var headerName = 'adminx-data-auth-token'; | ||
if (sails.config.cors.headers.indexOf(headerName) === -1) { | ||
sails.config.cors.headers += ',' + headerName; | ||
} | ||
/*var headerName = 'adminx-data-auth-token'; | ||
if (sails.config.cors.allowRequestHeaders.indexOf(headerName) === -1) { | ||
sails.config.cors.allowRequestHeaders += ',' + headerName; | ||
}*/ | ||
}, | ||
/* ----------- | ||
* INITIALIZE | ||
* ----------- | ||
* The initialize feature allows a hook to perform startup tasks that may be asynchronous or rely on other hooks. | ||
* All Sails configuration is guaranteed to be completed before a hook’s initialize function runs. | ||
* | ||
* https://next.sailsjs.com/documentation/concepts/extending-sails/hooks/hook-specification/initialize | ||
*/ | ||
initialize: function (cb) { | ||
@@ -49,7 +73,7 @@ // Assign this hook object to the `hook` var. | ||
// Load controllers under ./api/controllers and services under ./services | ||
/*// Load controllers under ./api/controllers and services under ./services | ||
// https://github.com/leeroybrun/sails-util-mvcsloader#loading-models--controllers--services | ||
loader.inject({ | ||
controllers: __dirname + '/api/controllers', // Path to the controllers to load | ||
services: __dirname + '/api/services' // Path to the services to load | ||
// services: __dirname + '/api/services' // Path to the services to load | ||
}, function(err) { | ||
@@ -59,5 +83,45 @@ // Signal that initialization of this hook is complete | ||
return cb(err); | ||
}); | ||
});*/ | ||
cb(); | ||
}, | ||
/* ----------------- | ||
* REGISTER ACTIONS | ||
* ----------------- | ||
* If your hook adds new actions to an app, and you want to guarantee that those actions will be maintained even after | ||
* a call to sails.reloadActions(), you should register the actions from within a registerActions method. | ||
* https://next.sailsjs.com/documentation/concepts/extending-sails/hooks/hook-specification/register-actions | ||
*/ | ||
registerActions: function (cb) { | ||
sails.log('No actions registered'); | ||
}, | ||
/* | ||
* ROUTES | ||
* The routes feature allows a custom hook to easily bind new routes to a Sails app at load time. | ||
* If implemented, routes should be an object with either a before key, an after key, or both. | ||
* The values of those keys should in turn be objects whose keys are route addresses, and whose values are route-handling | ||
* functions with the standard (req, res, next) parameters. Any routes specified in the before object will be bound | ||
* before custom user routes (as defined in sails.config.routes) and blueprint routes. Conversely, routes specified | ||
* in the after object will be bound after custom and blueprint routes. | ||
* | ||
* https://next.sailsjs.com/documentation/concepts/extending-sails/hooks/hook-specification/routes | ||
*/ | ||
routes: { | ||
before: { | ||
'/adminx*': adminxHeaderAuth, | ||
'/adminx/app/config': adminxController['app/config'], | ||
'/adminx/item/list': adminxController['item/list'], | ||
'/adminx/item/create': adminxController['item/create'], | ||
'/adminx/item/read': adminxController['item/read'], | ||
'/adminx/item/update': adminxController['item/update'], | ||
'/adminx/item/action': adminxController['item/action'], | ||
'/adminx/item/delete': adminxController['item/delete'] | ||
}, | ||
after: { | ||
} | ||
} | ||
}; | ||
}; |
{ | ||
"name": "sails-hook-adminx", | ||
"version": "0.0.10", | ||
"description": "AdminX hook for Sails.js", | ||
"version": "0.1.0", | ||
"description": "AdminX hook for Sails.js. AdminX is a sleek admin panel that integrates with any database, without coding.", | ||
"keywords": [ | ||
"adminx", | ||
"sails", | ||
@@ -44,4 +45,5 @@ "sailsjs", | ||
"mocha": "^3.4.2", | ||
"sails": "^0.12.13", | ||
"sails-disk": "^0.10.10", | ||
"sails": "^1.0.0-41", | ||
"sails-disk": "^1.0.0-11", | ||
"sails-hook-orm": "^2.0.0-22", | ||
"should": "^11.2.1", | ||
@@ -52,3 +54,3 @@ "supertest": "^3.0.0" | ||
"lodash.mergewith": "^4.6.0", | ||
"sails-util-mvcsloader": "^0.4.0" | ||
"sails-util-mvcsloader": "https://github.com/adminxhq/sails-util-mvcsloader" | ||
}, | ||
@@ -55,0 +57,0 @@ "scripts": { |
@@ -5,2 +5,3 @@ # sails-hook-adminx | ||
[![npm version](https://badge.fury.io/js/sails-hook-adminx.svg)](https://badge.fury.io/js/sails-hook-adminx) | ||
[![Known Vulnerabilities](https://snyk.io/test/npm/sails-hook-adminx/badge.svg)](https://snyk.io/test/npm/sails-hook-adminx) | ||
[![Join the chat at https://gitter.im/adminxhq/sails-hook-adminx](https://badges.gitter.im/adminxhq/sails-hook-adminx.svg)](https://gitter.im/adminxhq/sails-hook-adminx?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
@@ -21,11 +22,14 @@ [![Twitter Follow](https://img.shields.io/twitter/follow/adminxhq.svg?style=social&maxAge=3600)](https://twitter.com/adminxhq) | ||
### Requirements | ||
- sails 0.12 | ||
- for sails 1.0 use sails-hook-adminx@0.1 | ||
- for sails 0.12 use sails-hook-adminx@0.0 | ||
- Waterline: this integrations requires you to use the default Sails ORM | ||
### Table of versions | ||
### What does sails-hook-adminx do under the bonnet? | ||
1. Initializes on `sails lift` as the `sails-hook-adminx` | ||
2. Exposes a REST API under `/adminx/*` | ||
3. Adds CORS (Cross Origin Resource Sharing) configuration to open access from AdminX servers (https://adminx.io) | ||
3. Adds CORS (Cross Origin Resource Sharing) configuration to open access from AdminX-served-pages on your browser to your servers (https://adminx.io) | ||
An AdminX Panel is then able to connect to your server securely. | ||
An AdminX Panel is then able to connect from your browser to your server securely. | ||
@@ -32,0 +36,0 @@ ### Install |
@@ -34,3 +34,3 @@ var Sails = require('sails').Sails; | ||
}, | ||
connections: { | ||
datastores: { | ||
testDiskDb: { | ||
@@ -41,4 +41,10 @@ adapter: 'sails-disk' | ||
models: { | ||
connection: 'testDiskDb', | ||
migrate: 'drop' | ||
datastore: 'testDiskDb', | ||
migrate: 'drop', | ||
attributes: { | ||
createdAt: {type: 'number', autoCreatedAt: true,}, | ||
updatedAt: {type: 'number', autoUpdatedAt: true,}, | ||
id: {type: 'number', autoIncrement: true,}, | ||
}, | ||
primaryKey: 'id' | ||
}, | ||
@@ -49,5 +55,9 @@ adminx: { | ||
globals: { | ||
models: true | ||
models: true, | ||
_: require('lodash'), | ||
async: require('async'), | ||
sails: true | ||
}, | ||
log: {level: "verbose"} | ||
session: { secret: 'secret123' }, | ||
log: { level: 'verbose' } | ||
},function (err, _sails) { | ||
@@ -78,6 +88,7 @@ if (err) return done(err); | ||
sails.emit('hook:orm:reload'); | ||
done(); | ||
// TODO: Keep an eye if the way to do this changes | ||
// https://www.npmjs.com/package/sails-hook-orm#hookormreload | ||
// sails.hooks.orm.reload(); | ||
done(); | ||
}); | ||
@@ -97,8 +108,9 @@ | ||
// Test that Sails can lift with the hook in place | ||
it ('sails does not crash', function() { | ||
return true; | ||
it ('sails does not crash', function (done) { | ||
done(); | ||
}); | ||
it ('sails has loaded test models', function() { | ||
it ('sails has loaded test models', function (done) { | ||
sails.models.apple.should.be.an.Object(); | ||
done(); | ||
}); | ||
@@ -113,10 +125,7 @@ | ||
it('admin config auth disabled', function() { | ||
return true; //TODO: implement | ||
it('CORS config has loaded', function (done) { | ||
sails.config.routes['/adminx*'].cors.allowOrigins.should.be.an.Array(); | ||
done(); | ||
}); | ||
it('CORS config has loaded', function() { | ||
return true; //TODO: implement | ||
}); | ||
it('/app/config auth-protected', function (done) { | ||
@@ -156,3 +165,3 @@ request(httpApp) | ||
it('/item/list no schema param', function (done) { | ||
it('/item/list no params', function (done) { | ||
request(httpApp) | ||
@@ -189,4 +198,4 @@ .get(path + '/item/list') | ||
request(httpApp) | ||
.get(path + '/item/create') | ||
.query({ schema: schema, item: item }) | ||
.post(path + '/item/create') | ||
.send({ schema: schema, item: item }) | ||
.set(dataAuthHeaderName, dataAuthToken) | ||
@@ -204,8 +213,25 @@ .expect(200) | ||
it('/item/update no schema param', function (done) { | ||
it('/item/read no params', function (done) { | ||
request(httpApp) | ||
.get(path + '/item/update') | ||
.get(path + '/item/read') | ||
.set(dataAuthHeaderName, dataAuthToken) | ||
.expect(400) | ||
.end(done) | ||
}); | ||
it('/item/read working', function (done) { | ||
request(httpApp) | ||
.get(path + '/item/read') | ||
.query({ schema: schema, id: item.id }) | ||
.set(dataAuthHeaderName, dataAuthToken) | ||
.expect(200) | ||
.end(done) | ||
}); | ||
it('/item/update no params', function (done) { | ||
request(httpApp) | ||
.post(path + '/item/update') | ||
.set(dataAuthHeaderName, dataAuthToken) | ||
.expect(400) | ||
.end(done) | ||
; | ||
@@ -216,4 +242,4 @@ }); | ||
request(httpApp) | ||
.get(path + '/item/update') | ||
.query({ schema: schema, id: item.id, item: item }) | ||
.post(path + '/item/update') | ||
.send({ schema: schema, id: item.id, item: item }) | ||
.set(dataAuthHeaderName, dataAuthToken) | ||
@@ -225,2 +251,3 @@ .expect(200) | ||
data.should.have.property('id').eql(item.id); | ||
data.should.have.property('grownBy').eql(null); | ||
}) | ||
@@ -231,5 +258,5 @@ .end(done) | ||
it('/item/action no schema', function (done) { | ||
it('/item/action no params', function (done) { | ||
request(httpApp) | ||
.get(path + '/item/action') | ||
.post(path + '/item/action') | ||
.set(dataAuthHeaderName, dataAuthToken) | ||
@@ -243,3 +270,3 @@ .expect(400) | ||
request(httpApp) | ||
.get(path + '/item/action') | ||
.post(path + '/item/action') | ||
.query({ schema: schema, id: item.id, item: item, action: 'makeJuice', data: item }) | ||
@@ -256,5 +283,5 @@ .set(dataAuthHeaderName, dataAuthToken) | ||
it('/item/delete no schema', function (done) { | ||
it('/item/delete no params', function (done) { | ||
request(httpApp) | ||
.get(path + '/item/delete') | ||
.post(path + '/item/delete') | ||
.set(dataAuthHeaderName, dataAuthToken) | ||
@@ -268,3 +295,3 @@ .expect(400) | ||
request(httpApp) | ||
.get(path + '/item/delete') | ||
.post(path + '/item/delete') | ||
.query({ schema: schema, id: item.id }) | ||
@@ -271,0 +298,0 @@ .set(dataAuthHeaderName, dataAuthToken) |
@@ -11,18 +11,18 @@ /** | ||
name: { type: 'string' }, | ||
origin: { type: 'text', protected: true }, | ||
email: { type: 'email' }, | ||
quantity: {type: 'integer'}, | ||
price: {type: 'float'}, | ||
rippenedAt: {type: 'date'}, | ||
pickedAt: {type: 'datetime'}, | ||
origin: { type: 'string' }, | ||
email: { type: 'string', isEmail: true }, | ||
quantity: {type: 'number'}, | ||
price: {type: 'number'}, | ||
rippenedAt: {type: 'string', columnType: 'datetime'}, | ||
pickedAt: {type: 'string', columnType: 'datetime'}, | ||
organic: { type: 'boolean' }, | ||
dnaSequence: { type: 'binary' }, | ||
images: { type: 'array' }, | ||
ratings: { type: 'array' }, | ||
tags: { type: 'array' }, | ||
dnaSequence: { type: 'ref', columnType: 'binary' }, | ||
images: { type: 'json', columnType: 'array' }, | ||
ratings: { type: 'json', columnType: 'array' }, | ||
tags: { type: 'json', columnType: 'array' }, | ||
metadata: { type: 'json' }, | ||
grownBy: { model: 'tree' }, | ||
relatedTo: { collection: 'apple' }, | ||
description: { type: 'mediumtext' }, | ||
history: { type: 'longtext' } | ||
description: { type: 'string' }, | ||
history: { type: 'string' } | ||
}, | ||
@@ -29,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
HTTP dependency
Supply chain riskContains a dependency which resolves to a remote HTTP URL which could be used to inject untrusted code and reduce overall package reliability.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
686
127
99049
6
1
1
- Removedasync@0.9.2(transitive)
- Removedfs-extra@0.8.1(transitive)
- Removedinclude-all@0.1.6(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsonfile@1.1.1(transitive)
- Removedlodash@2.4.23.10.1(transitive)
- Removedminimist@0.0.10(transitive)
- Removedmkdirp@0.3.5(transitive)
- Removedncp@0.4.2(transitive)
- Removedoptimist@0.6.1(transitive)
- Removedrimraf@2.2.8(transitive)
- Removedsails-build-dictionary@0.10.1(transitive)
- Removedsails-util@0.10.6(transitive)
- Removedsails-util-mvcsloader@0.4.0(transitive)
- Removedswitchback@1.1.3(transitive)
- Removedunderscore.string@2.3.12.3.3(transitive)
- Removedwordwrap@0.0.3(transitive)
Updatedsails-util-mvcsloader@https://github.com/adminxhq/sails-util-mvcsloader