New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

adoscopejs

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adoscopejs - npm Package Compare versions

Comparing version 0.0.10 to 0.0.11

dist/src/Contracts/index.js

25

config/adoscope.js

@@ -11,4 +11,27 @@ /*

const Env = use('Env')
module.exports = {
path: 'adoscope'
elabled: Env.get('ADOSCOPE_ENABLED', true),
domain: null,
/*
|--------------------------------------------------------------------------
| Adoscope Path
|--------------------------------------------------------------------------
|
| This is the URI path where Adoscope will be accessible from. You can
| change this path to anything you like.
|
*/
path: 'adoscope',
mime_types: [
//
],
ignore_paths: [
//
]
}

26

dist/providers/AdoscopeProvider.js

@@ -8,3 +8,3 @@ "use strict";

*
* Last Modified: 21/04/2019 3:54:22
* Last Modified: 23/04/2019 10:19:28
* Modified By: Paradox

@@ -27,3 +27,3 @@ *

// NOTE: when publising.
const CONTROLLERS_PATH = '@provider:Adoscope/dist/src/app/Controllers/Http';
const CONTROLLERS_PATH = '@provider:Adoscope/App/Controllers/Http';
// NOTE: local mode.

@@ -44,11 +44,21 @@ //const CONTROLLERS_PATH = 'App/Adoscope/Controllers'

}
monkeyPatch() {
_monkeyPatch() {
const Event = this.app.use('Event');
const { Command } = require(path.join(process.cwd(), 'node_modules', '@adonisjs/ace'));
//const { Command } = require('@adonisjs/ace')
Command.exec = function (args, options, viaAce) {
const commandInstance = typeof (global.make) === 'function' ? global.make(this) : new this();
commandInstance.viaAce = viaAce;
console.log(this.commandName, args, options);
const EntryService = use('Adoscope/Services/EntryService');
EntryService.store({
type: 'command',
content: {
name: this.commandName,
args,
options
}
});
return new Promise(async (resolve, reject) => {
try {
console.log(this.commandName);
const response = await commandInstance.handle(args, options);

@@ -65,10 +75,14 @@ resolve(response);

this.app.singleton('Adonis/Adoscope', (app) => {
return new Adoscope_1.default(app);
return new Adoscope_1.default(app, app.use('Config'), app.use('Route'), app.use('Logger'));
});
}
boot() {
// We MUST autoload this namepace to avoid E_UNDEFINED_METHOD exception when calling Adoscope controller's methods.
this.app.autoload(path.join(__dirname, '../../config'), 'Adoscope/Config');
this.app.autoload(path.join(__dirname, '../src/app'), 'Adoscope/App');
this.app.autoload(path.join(__dirname, '../src/Services'), 'Adoscope/Services');
this._addRoutes();
this.monkeyPatch();
this._monkeyPatch();
}
}
module.exports = AdoscopeProvider;

@@ -8,3 +8,3 @@ "use strict";

*
* Last Modified: 21/04/2019 2:53:06
* Last Modified: 23/04/2019 10:48:03
* Modified By: Paradox

@@ -15,28 +15,64 @@ *

Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const pluralize = require("pluralize");
const RequestWatcher_1 = require("./watchers/RequestWatcher");
const QueryWatcher_1 = require("./watchers/QueryWatcher");
const EntryType_1 = require("./EntryType");
const pathToRegexp = use('path-to-regexp');
class Adoscope {
constructor(app) {
this.app = app;
this.onFinished = app.use('on-finished');
this.Route = app.use('Route');
this.Config = app.use('Config');
this.requestWatcher = new RequestWatcher_1.default(this.Route);
constructor(_app, _config, _route, _logger, _recordingRequest = false) {
this._app = _app;
this._config = _config;
this._route = _route;
this._logger = _logger;
this._recordingRequest = _recordingRequest;
this.data = {};
this._onFinished = this._app.use('on-finished');
this._adoscopeConfig = this._config.merge('adoscope', this._app.use('Adoscope/Config/adoscope'));
this._requestWatcher = new RequestWatcher_1.default(this._adoscopeConfig, this._route, this._logger);
this._queryWatcher = new QueryWatcher_1.default(this._app.use('Database'));
this._queryWatcher.record();
_.each(_.values(EntryType_1.default), (entry) => {
this.data[pluralize.plural(entry)] = [];
});
global.Adoscope = this;
}
_handleApprovedRequests(url) {
let ignoredPaths = _.concat(this._adoscopeConfig.ignore_paths, [
`${this._adoscopeConfig.path}/(.*)?`
]);
let approved = true;
_.each(ignoredPaths, (path) => {
path = path.replace(/\/\*/g, '/(.*)').replace(/^\/|\/$/g, '');
if (pathToRegexp(path).exec(url.replace(/^\/|\/$/g, ''))) {
approved = false;
return false;
}
});
return approved;
}
get recordingRequest() {
return this._recordingRequest;
}
set recordingRequest(value) {
this._recordingRequest = value;
}
scriptVariables() {
return {
path: this.Config.get('adoscope.path'),
path: this._adoscopeConfig.path,
recording: false
};
}
watch(context) {
incomingRequest(context) {
const request = context.request;
const response = context.response;
const session = context.session;
this.onFinished(response.response, (err, res) => {
if (!this._handleApprovedRequests(request.url())) {
return;
}
this._onFinished(response.response, (err, res) => {
if (err) {
console.error(err);
}
console.log('test');
this.requestWatcher.add(request, res, session);
this._requestWatcher.record(request, res, session);
});

@@ -43,0 +79,0 @@ }

@@ -8,2 +8,3 @@ /*

*/
'use strict';
const path = require('path');

@@ -10,0 +11,0 @@ class AdoscopeController {

@@ -13,3 +13,11 @@ /*

}
async index({ response }) {
return response.json({
foo: 'bar'
});
}
async show({}) {
return 'Test';
}
}
module.exports = AdoscopeRequestController;

@@ -5,2 +5,5 @@ 'use strict';

class Entry extends Model {
static get table() {
return 'adoscope_entries';
}
static get primaryKey() {

@@ -7,0 +10,0 @@ return 'uuid';

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

up() {
this.create('telescope_entries', (table) => {
this.create('adoscope_entries', (table) => {
table.increments();

@@ -18,5 +18,5 @@ table.timestamps();

down() {
this.drop('telescope_entries');
this.drop('adoscope_entries');
}
}
module.exports = TelescopeEntriesSchema;

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

"use strict";
/*

@@ -8,3 +7,3 @@ * File: EntryService.ts

*
* Last Modified: 21/04/2019 2:53:57
* Last Modified: 22/04/2019 6:05:36
* Modified By: Paradox

@@ -14,4 +13,3 @@ *

*/
Object.defineProperty(exports, "__esModule", { value: true });
const Entry = require('../../../../Models/Entry');
const Entry = use('Adoscope/App/Models/Entry');
class EntryService {

@@ -30,2 +28,2 @@ constructor() {

}
exports.default = EntryService;
module.exports = EntryService;

@@ -8,3 +8,3 @@ "use strict";

*
* Last Modified: 21/04/2019 2:53:41
* Last Modified: 23/04/2019 11:16:51
* Modified By: Paradox

@@ -15,16 +15,44 @@ *

Object.defineProperty(exports, "__esModule", { value: true });
const mime = require("mime-types");
const EntryService_1 = require("../Services/EntryService");
const _ = require("lodash");
const Adoscope_1 = require("../Adoscope");
class RequestWatcher {
constructor(route, requests = []) {
constructor(config, route, logger) {
this.config = config;
this.route = route;
this.requests = requests;
this.logger = logger;
}
async add(request, response, session) {
async record(request, response, session) {
const url = request.url();
const method = request.method();
const contentType = response.getHeader('Content-Type');
// TODO: Grab route data!
if (session.initiated) {
await EntryService_1.default.store({
type: 'request',
content: {
let _route = this.route.match(url, method);
if (_route) {
let mimeTypes = _.concat(this.config.mime_types, [
'text/html',
'application/json'
]);
let route = _route.route;
if (contentType && _.includes(mimeTypes, contentType.split(';')[0]) && session.initiated) {
// We MUST require it here, otherwise we'll get "Cannot find module Adoscope/Services/EntryService" error.
const EntryService = use('Adoscope/Services/EntryService');
let handler = route.handler;
let file = null;
let handlerData = {};
if (typeof handler !== 'function') {
handler = handler.split('.');
file = handler[0];
handlerData = {
controller: file,
action: handler.length > 1 ? handler[1] : null
};
}
else {
handlerData = {
controller: null,
action: handler.toString()
};
}
/*await EntryService.store({
type: 'request',
content: {
format: mime.extension(contentType),

@@ -39,10 +67,17 @@ content_type: contentType,

path: request.url(),
session_attributes: session.all(),
session_variables: session.all(),
protocol: request.protocol().toUpperCase(),
hostname: request.hostname()
}
});
hostname: request.hostname(),
route_details: {
handler: handlerData,
middlewares: route.middlewareList.filter((middleware: string) => !middleware.startsWith('av:')),
validators: route.middlewareList.filter((middleware: string) => middleware.startsWith('av:'))
}
}
})*/
}
}
Adoscope_1.default.recordingRequest = false;
}
}
exports.default = RequestWatcher;

@@ -7,3 +7,3 @@ /*

*
* Last Modified: 21/04/2019 4:41:38
* Last Modified: 22/04/2019 12:58:48
* Modified By: Paradox

@@ -98,5 +98,5 @@ *

await copyMigrationFile(cli)
await copyModelFile(cli)
//await copyModelFile(cli)
//await copyControllersDirectory(cli)
await copyViewFile(cli)
}
{
"name": "adoscopejs",
"version": "0.0.10",
"version": "0.0.11",
"description": "Debugger for Adonisjs-based applications",

@@ -28,2 +28,3 @@ "main": "index.js",

"mime-types": "^2.1.23",
"on-change": "^1.2.0",
"on-finished": "^2.3.0",

@@ -30,0 +31,0 @@ "pluralize": "^7.0.0",

@@ -7,3 +7,3 @@ /*

*
* Last Modified: 21/04/2019 3:54:22
* Last Modified: 23/04/2019 10:19:28
* Modified By: Paradox

@@ -22,7 +22,6 @@ *

import { ValueOf } from '../src/Contracts'
import Adoscope from '../src/Adoscope'
import EntryType from '../src/EntryType'
type ValueOf<T> = T[keyof T]
class AdoscopeProvider extends ServiceProvider {

@@ -37,3 +36,3 @@ private _addRoutes () {

// NOTE: when publising.
const CONTROLLERS_PATH = '@provider:Adoscope/dist/src/app/Controllers/Http'
const CONTROLLERS_PATH = '@provider:Adoscope/App/Controllers/Http'

@@ -60,5 +59,6 @@ // NOTE: local mode.

private monkeyPatch() {
private _monkeyPatch() {
const Event = this.app.use('Event')
const { Command } = require(path.join(process.cwd(), 'node_modules', '@adonisjs/ace'))
//const { Command } = require('@adonisjs/ace')

@@ -69,6 +69,15 @@ Command.exec = function (args: object, options: object, viaAce: Boolean) {

console.log(this.commandName, args, options)
const EntryService = use('Adoscope/Services/EntryService')
EntryService.store({
type: 'command',
content: {
name: this.commandName,
args,
options
}
})
return new Promise(async (resolve, reject) => {
try {
console.log(this.commandName)
const response = await commandInstance.handle(args, options)

@@ -85,3 +94,3 @@ resolve(response)

this.app.singleton('Adonis/Adoscope', (app: any) => {
return new Adoscope(app)
return new Adoscope(app, app.use('Config'), app.use('Route'), app.use('Logger'))
})

@@ -91,4 +100,8 @@ }

boot () {
// We MUST autoload this namepace to avoid E_UNDEFINED_METHOD exception when calling Adoscope controller's methods.
this.app.autoload(path.join(__dirname, '../../config'), 'Adoscope/Config')
this.app.autoload(path.join(__dirname, '../src/app'), 'Adoscope/App')
this.app.autoload(path.join(__dirname, '../src/Services'), 'Adoscope/Services')
this._addRoutes()
this.monkeyPatch()
this._monkeyPatch()
}

@@ -95,0 +108,0 @@ }

@@ -7,3 +7,3 @@ /*

*
* Last Modified: 21/04/2019 2:53:06
* Last Modified: 23/04/2019 10:48:03
* Modified By: Paradox

@@ -14,22 +14,71 @@ *

import * as _ from 'lodash'
import * as pluralize from 'pluralize'
import { ValueOf } from '../src/Contracts'
import RequestWatcher from './watchers/RequestWatcher'
import QueryWatcher from './watchers/QueryWatcher'
import EntryType from './EntryType'
const pathToRegexp = use('path-to-regexp')
export default class Adoscope {
private onFinished: any
private Route: any
private Config: any
private requestWatcher: RequestWatcher
private _onFinished: any
private _adoscopeConfig: any
private _requestWatcher: RequestWatcher
private _queryWatcher: QueryWatcher
public data: {[x: string]: any} = {}
constructor (private app: any, ) {
this.onFinished = app.use('on-finished')
this.Route = app.use('Route')
this.Config = app.use('Config')
this.requestWatcher = new RequestWatcher(this.Route)
constructor (
private _app: any,
private _config: any,
private _route: any,
private _logger: any,
private _recordingRequest: Boolean = false
) {
this._onFinished = this._app.use('on-finished')
this._adoscopeConfig = this._config.merge('adoscope', this._app.use('Adoscope/Config/adoscope'))
this._requestWatcher = new RequestWatcher(this._adoscopeConfig, this._route, this._logger)
this._queryWatcher = new QueryWatcher(this._app.use('Database'))
this._queryWatcher.record()
_.each(_.values(EntryType), (entry: ValueOf<EntryType>) => {
this.data[pluralize.plural(entry)] = []
})
global.Adoscope = this
}
public scriptVariables(): object {
private _handleApprovedRequests(url: string): Boolean {
let ignoredPaths = _.concat(this._adoscopeConfig.ignore_paths, [
`${this._adoscopeConfig.path}/(.*)?`
])
let approved: Boolean = true
_.each(ignoredPaths, (path: string) => {
path = path.replace(/\/\*/g, '/(.*)').replace(/^\/|\/$/g, '')
if (pathToRegexp(path).exec(url.replace(/^\/|\/$/g, ''))) {
approved = false
return false
}
})
return approved
}
get recordingRequest (): Boolean {
return this._recordingRequest
}
set recordingRequest (value: Boolean) {
this._recordingRequest = value
}
public scriptVariables (): object {
return {
path: this.Config.get('adoscope.path'),
path: this._adoscopeConfig.path,
recording: false

@@ -39,3 +88,3 @@ }

public watch (context: any): void {
public incomingRequest (context: any): void {
const request = context.request

@@ -45,3 +94,7 @@ const response = context.response

this.onFinished(response.response, (err: any, res: any) => {
if (!this._handleApprovedRequests(request.url())) {
return
}
this._onFinished(response.response, (err: any, res: any) => {
if (err) {

@@ -51,7 +104,5 @@ console.error(err)

console.log('test')
this.requestWatcher.add(request, res, session)
this._requestWatcher.record(request, res, session)
})
}
}

@@ -9,2 +9,4 @@ /*

'use strict'
const path = require('path')

@@ -11,0 +13,0 @@

@@ -15,4 +15,14 @@ /*

}
async index ({ response }) {
return response.json({
foo: 'bar'
})
}
async show ({}) {
return 'Test'
}
}
module.exports = AdoscopeRequestController

@@ -7,2 +7,6 @@ 'use strict'

class Entry extends Model {
static get table() {
return 'adoscope_entries'
}
static get primaryKey () {

@@ -9,0 +13,0 @@ return 'uuid'

@@ -7,3 +7,3 @@ 'use strict'

up () {
this.create('telescope_entries', (table) => {
this.create('adoscope_entries', (table) => {
table.increments()

@@ -22,3 +22,3 @@ table.timestamps()

down () {
this.drop('telescope_entries')
this.drop('adoscope_entries')
}

@@ -25,0 +25,0 @@ }

@@ -7,3 +7,3 @@ /*

*
* Last Modified: 21/04/2019 2:53:57
* Last Modified: 22/04/2019 6:05:36
* Modified By: Paradox

@@ -14,5 +14,5 @@ *

const Entry = require('../../../../Models/Entry')
const Entry = use('Adoscope/App/Models/Entry')
export default class EntryService {
class EntryService {
constructor () {

@@ -33,1 +33,3 @@

}
module.exports = EntryService

@@ -7,3 +7,3 @@ /*

*
* Last Modified: 21/04/2019 2:53:41
* Last Modified: 23/04/2019 11:16:51
* Modified By: Paradox

@@ -14,34 +14,77 @@ *

import * as _ from 'lodash'
import * as mime from 'mime-types'
import Adoscope from '../Adoscope';
import EntryService from '../Services/EntryService'
export default class RequestWatcher {
constructor (private route: any, private requests: Array<any> = []) {}
constructor (
private config: any,
private route: any,
private logger: any
) {}
public async add (request: any, response: any, session: any) {
public async record (request: any, response: any, session: any) {
const url = request.url()
const method = request.method()
const contentType = response.getHeader('Content-Type')
// TODO: Grab route data!
let _route = this.route.match(url, method)
if (session.initiated) {
await EntryService.store({
type: 'request',
content: {
format: mime.extension(contentType),
content_type: contentType,
status_text: response.statusMessage,
status_code: response.statusCode,
payload: request.all(),
headers: request.headers(),
cookies: request.cookies(),
response_headers: response.getHeaders(),
path: request.url(),
session_attributes: session.all(),
protocol: request.protocol().toUpperCase(),
hostname: request.hostname()
if (_route) {
let mimeTypes = _.concat(this.config.mime_types, [
'text/html',
'application/json'
])
let route = _route.route
if (contentType && _.includes(mimeTypes, contentType.split(';')[0]) && session.initiated) {
// We MUST require it here, otherwise we'll get "Cannot find module Adoscope/Services/EntryService" error.
const EntryService = use('Adoscope/Services/EntryService')
let handler = route.handler
let file = null
let handlerData = {}
if (typeof handler !== 'function') {
handler = handler.split('.')
file = handler[0]
handlerData = {
controller: file,
action: handler.length > 1 ? handler[1] : null
}
} else {
handlerData = {
controller: null,
action: handler.toString()
}
}
})
/*await EntryService.store({
type: 'request',
content: {
format: mime.extension(contentType),
content_type: contentType,
status_text: response.statusMessage,
status_code: response.statusCode,
payload: request.all(),
headers: request.headers(),
cookies: request.cookies(),
response_headers: response.getHeaders(),
path: request.url(),
session_variables: session.all(),
protocol: request.protocol().toUpperCase(),
hostname: request.hostname(),
route_details: {
handler: handlerData,
middlewares: route.middlewareList.filter((middleware: string) => !middleware.startsWith('av:')),
validators: route.middlewareList.filter((middleware: string) => middleware.startsWith('av:'))
}
}
})*/
}
}
Adoscope.recordingRequest = false
}
}
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