Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lib

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lib - npm Package Compare versions

Comparing version 2.2.6 to 3.0.0-rc1

4

lib.js

@@ -21,5 +21,5 @@ const appendLibPath = require('./lib/append.js');

} else {
let p = parseParameters(args);
let p = parseParameters(names, args);
let func = isLocal ? executeLocal : executeRemote;
let execute = func.bind(null, cfg, names, p.args, p.kwargs, p.body);
let execute = func.bind(null, cfg, names, p.params);
if (p.callback) {

@@ -26,0 +26,0 @@ return execute(p.callback);

@@ -6,3 +6,3 @@ const path = require('path');

module.exports = (cfg, names, args, kwargs, body, callback) => {
module.exports = (cfg, names, params, callback) => {

@@ -19,2 +19,5 @@ try {

let args = Array.isArray(params) ? params : [];
let kwargs = Array.isArray(params) ? {} : params;
names = names.length === 1 && pkg.stdlib.defaultFunction ?

@@ -54,3 +57,3 @@ names.concat(pkg.stdlib.defaultFunction) :

let fnParams = {args: args, kwargs: kwargs};
fnParams.buffer = body instanceof Buffer ? body : new Buffer(0);
fnParams.buffer = new Buffer(0);
fnParams.remoteAddress = '::1';

@@ -57,0 +60,0 @@ fnParams.service = '.';

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

module.exports = (args) => {
function formatBuffer(b) {
return Buffer.isBuffer(b) ? {_base64: b.toString('base64')} : b;
}
let kwargs = {};
let body;
let content;
let callback = typeof args[args.length - 1] === 'function' ? args.pop() : null;
function containsKeywords(params) {
return params.length &&
typeof params[0] === 'object' &&
!Array.isArray(params[0]) &&
!Buffer.isBuffer(params[0]);
}
if ((args.length === 1 || args.length === 2) && args[0] instanceof Buffer) {
body = args.shift();
kwargs = args.shift();
kwargs = typeof kwargs === 'object' && kwargs !== null ? kwargs : {};
function formatParams(params) {
if (containsKeywords(params)) {
if (params.length > 1) {
throw new Error('Can not send additional arguments with parameters as keywords');
} else {
return Object.keys(params[0]).reduce((body, name) => {
body[name] = formatBuffer(body[name]);
return body;
}, params[0]);
}
} else {
kwargs = typeof args[args.length - 1] === 'object' && args[args.length - 1] !== null ? args.pop() : {};
body = {args: args, kwargs: kwargs};
return params.map(formatBuffer);
}
}
args.forEach(arg => {
if (
arg !== null &&
typeof arg !== 'boolean' &&
typeof arg !== 'string' &&
typeof arg !== 'number'
) {
let err = new TypeError(`${names.join('.')}: All arguments must be Boolean, Number, String or null`);
let stack = err.stack.split('\n');
stack = stack.slice(0, 1).concat(stack.slice(5));
stack[1] = stack[1].replace('Object.<anonymous>', names.join('.'));
err.stack = stack.join('\n');
throw err;
}
});
module.exports = (names, params) => {
let callback;
if (typeof params[params.length - 1] === 'function') {
callback = params.pop();
}
return {
args: args,
kwargs: kwargs,
body: body,
params: formatParams(params),
callback: callback

@@ -38,0 +38,0 @@ };

@@ -7,5 +7,4 @@ const https = require('https');

const PATH = '/';
const KEYS = {};
module.exports = (cfg, names, args, kwargs, body, callback) => {
module.exports = (cfg, names, params, callback) => {

@@ -16,32 +15,27 @@ cfg = cfg || {};

cfg.path = cfg.path || PATH;
cfg.keys = cfg.keys || KEYS;
cfg.debug = !!cfg.debug;
cfg.token = cfg.token || null;
cfg.keys = cfg.keys || null;
cfg.webhook = cfg.webhook || null;
cfg.convert = !!cfg.convert;
let pathname = cfg.debug ?
names.slice(3).join('/') :
names.slice(0, 2).join('/') + names.slice(2).join('/');
names.slice(0, 2).join('/') + names.slice(2).join('/')
pathname = pathname + '/';
let headers = {};
let responded = false;
let body;
if (body instanceof Buffer) {
headers['Content-Type'] = 'application/octet-stream';
pathname += '?' + Object.keys(kwargs).map(key => `${encodeURI(key)}=${encodeURI(kwargs[key])}`).join('&');
} else {
headers['Content-Type'] = 'application/json';
body = new Buffer(JSON.stringify(body));
}
headers['Content-Type'] = 'application/json';
headers['X-Faaslang'] = 'true';
body = new Buffer(JSON.stringify(params));
if (cfg.token) {
headers['Authorization'] = `Bearer ${cfg.token}`;
}
cfg.token && (headers['Authorization'] = `Bearer ${cfg.token}`);
cfg.keys && (headers['X-Authorization-Keys'] = JSON.stringify(cfg.keys));
cfg.webhook && (headers['X-Webhook'] = cfg.webhook);
cfg.convert && (headers['X-Convert-Strings'] = 'true');
if (cfg.webhook) {
headers['X-Webhook'] = cfg.webhook;
}
let responded = false;
if (Object.keys(cfg.keys).length) {
headers['X-Authorization-Keys'] = JSON.stringify(cfg.keys);
}
let req = (cfg.port === 443 ? https : http).request({

@@ -48,0 +42,0 @@ host: cfg.host,

{
"name": "lib",
"version": "2.2.6",
"version": "3.0.0-rc1",
"description": "StdLib: Standard Library for Microservices Node.js Bindings",

@@ -5,0 +5,0 @@ "main": "lib.js",

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