@weeb_services/wapi-core
Advanced tools
Comparing version 1.4.1-alpha1 to 1.4.1-alpha10
16
index.js
'use strict' | ||
// Set up winston | ||
const winston = require('winston') | ||
winston.remove(winston.transports.Console) | ||
winston.add(winston.transports.Console, { | ||
timestamp: true, | ||
colorize: true | ||
}) | ||
// Middleware | ||
@@ -15,2 +7,3 @@ module.exports.BaseMiddleware = require('./lib/middleware/base.middleware') | ||
module.exports.PermMiddleware = require('./lib/middleware/perm.middleware') | ||
module.exports.TrackingMiddleware = require('./lib/middleware/tracking.middleware') | ||
@@ -25,1 +18,8 @@ // Routers | ||
module.exports.Utils = require('./lib/utils') | ||
module.exports.Logger = require('./lib/logger') | ||
module.exports.Registrator = require('./lib/registrator') | ||
module.exports.Errors = { | ||
HttpError: require('./lib/structures/errors/HttpError'), | ||
} | ||
module.exports.ShutdownHandler = require('./lib/shutdownHandler') |
'use strict' | ||
const winston = require('winston') | ||
const logger = require('../logger') | ||
@@ -43,3 +43,3 @@ const {HTTPCodes, DefaultResponses} = require('../constants') | ||
} catch (e) { | ||
winston.error(e) | ||
logger.error(e) | ||
const response = this.getResponse(HTTPCodes.INTERNAL_SERVER_ERROR) | ||
@@ -46,0 +46,0 @@ res.status(response.status) |
@@ -5,3 +5,3 @@ const Middleware = require('./base.middleware') | ||
class Track extends Middleware { | ||
constructor (name, version, environment) { | ||
constructor (name, version, environment, trackingKey) { | ||
super() | ||
@@ -11,2 +11,3 @@ this.name = name | ||
this.environment = environment | ||
this.trackingKey = trackingKey | ||
} | ||
@@ -28,3 +29,3 @@ | ||
} | ||
const visitor = ua(req.config.track, uid, {https: true, strictCidFormat: false}) | ||
const visitor = ua(this.trackingKey, uid, {https: true, strictCidFormat: false}) | ||
const trackingData = { | ||
@@ -31,0 +32,0 @@ uid, |
'use strict' | ||
const router = require('express').Router() | ||
const winston = require('winston') | ||
const logger = require('../logger') | ||
@@ -21,3 +21,3 @@ const { HTTPCodes, DefaultResponses } = require('../constants') | ||
} catch (e) { | ||
winston.error(e) | ||
logger.error(e) | ||
this.handleResponse(res, HTTPCodes.INTERNAL_SERVER_ERROR) | ||
@@ -24,0 +24,0 @@ } |
'use strict' | ||
module.exports.checkScopes = (wantedScope, scopes) => { | ||
function checkScopes (wantedScope, scopes) { | ||
if (scopes.indexOf('admin' > -1)) { | ||
@@ -12,1 +12,46 @@ return true | ||
} | ||
function checkPermissions (account, wantedPermissions, requireAccount = true) { | ||
if (!account) { | ||
return !requireAccount | ||
} | ||
if (account.perms.all) { | ||
return true | ||
} | ||
for (const perm of wantedPermissions) { | ||
if (account.perms[perm]) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
function buildMissingScopeMessage (name, env, scopes) { | ||
if (!Array.isArray(scopes)) { | ||
scopes = [scopes] | ||
} | ||
scopes = scopes.map(s => buildFullyQualifiedScope(name, env, s)) | ||
let message = 'missing scope' + scopes.length > 1 ? 's' : '' | ||
message = message + ' ' + scopes.join(' or ') | ||
return message | ||
} | ||
function buildFullyQualifiedScope (name, env, scope) { | ||
const fqScope = `${name}-${env}` | ||
if (scope !== '') { | ||
return fqScope + ':' + scope | ||
} | ||
return fqScope | ||
} | ||
function isTrue (value) { | ||
if (typeof value === 'string') { | ||
return value === 'true' | ||
} else if (typeof value === 'boolean') { | ||
return value | ||
} else { | ||
return false | ||
} | ||
} | ||
module.exports = {buildFullyQualifiedScope, buildMissingScopeMessage, checkPermissions, checkScopes, isTrue} |
{ | ||
"name": "@weeb_services/wapi-core", | ||
"version": "1.4.1-alpha1", | ||
"version": "1.4.1-alpha10", | ||
"description": "Weeb API core", | ||
@@ -22,7 +22,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"axios": "^0.17.1", | ||
"express": "^4.15.3", | ||
"@moebius/http-graceful-shutdown": "^1.0.1", | ||
"axios": "^0.18.0", | ||
"express": "^4.16.3", | ||
"shortid": "^2.2.8", | ||
"universal-analytics": "^0.4.16", | ||
"url-pattern": "^1.0.3", | ||
"winston": "^2.3.1" | ||
"winston": "^3.0.0-rc2" | ||
}, | ||
@@ -33,7 +35,7 @@ "engines": { | ||
"devDependencies": { | ||
"eslint": "^4.17.0", | ||
"eslint-config-standard": "^11.0.0-beta.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-node": "^6.0.0", | ||
"eslint-plugin-promise": "^3.6.0", | ||
"eslint": "^4.18.2", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.9.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.7.0", | ||
"eslint-plugin-standard": "^3.0.1" | ||
@@ -40,0 +42,0 @@ }, |
23
test.js
@@ -1,8 +0,3 @@ | ||
// Set up winston | ||
const winston = require('winston') | ||
winston.remove(winston.transports.Console) | ||
winston.add(winston.transports.Console, { | ||
timestamp: true, | ||
colorize: true, | ||
}) | ||
// Set up logger | ||
const logger = require('./index').Logger | ||
@@ -18,5 +13,5 @@ try { | ||
} | ||
winston.info('Tests loaded.') | ||
logger.info('Tests loaded.') | ||
winston.info(`Testing wapi-core@${pkg.version}`) | ||
logger.info(`Testing wapi-core@${pkg.version}`) | ||
@@ -29,3 +24,3 @@ let successful = 0 | ||
const test = new tests[i]() | ||
winston.info(`Running test for ${test.name}`) | ||
logger.info(`Running test for ${test.name}`) | ||
try { | ||
@@ -36,3 +31,3 @@ await test.run() | ||
failed++ | ||
return winston.error(`Test failed: ${e}`) | ||
return logger.error(`Test failed: ${e}`) | ||
} | ||
@@ -44,9 +39,9 @@ } | ||
.then(() => { | ||
winston.info(`Done. Completed ${successful} test(s) successfully, failed ${failed} test(s).`) | ||
logger.info(`Done. Completed ${successful} test(s) successfully, failed ${failed} test(s).`) | ||
}) | ||
.catch(e => { | ||
winston.error(`Failed to run tests: ${e}`) | ||
logger.error(`Failed to run tests: ${e}`) | ||
}) | ||
} catch (e) { | ||
winston.error(`Failed to run tests: ${e}`) | ||
logger.error(`Failed to run tests: ${e}`) | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
139846
22
539
7
+ Addedshortid@^2.2.8
+ Added@colors/colors@1.6.0(transitive)
+ Added@dabh/diagnostics@2.0.3(transitive)
+ Added@moebius/http-graceful-shutdown@1.1.0(transitive)
+ Added@types/triple-beam@1.3.5(transitive)
+ Addedasync@3.2.6(transitive)
+ Addedaxios@0.18.1(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcolor-string@1.9.1(transitive)
+ Addedcolorspace@1.1.4(transitive)
+ Addedenabled@2.0.0(transitive)
+ Addedfecha@4.2.3(transitive)
+ Addedfn.name@1.1.0(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
+ Addedis-arrayish@0.3.2(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedkuler@2.0.0(transitive)
+ Addedlogform@2.7.0(transitive)
+ Addednanoid@2.1.11(transitive)
+ Addedone-time@1.0.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-stable-stringify@2.5.0(transitive)
+ Addedshortid@2.2.16(transitive)
+ Addedsimple-swizzle@0.2.2(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedtext-hex@1.0.0(transitive)
+ Addedtriple-beam@1.4.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwinston@3.17.0(transitive)
+ Addedwinston-transport@4.9.0(transitive)
- Removedasync@2.6.4(transitive)
- Removedaxios@0.17.1(transitive)
- Removedcolors@1.0.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedeyes@0.1.8(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedlodash@4.17.21(transitive)
- Removedwinston@2.4.7(transitive)
Updatedaxios@^0.18.0
Updatedexpress@^4.16.3
Updatedwinston@^3.0.0-rc2