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

@architect/functions

Package Overview
Dependencies
Maintainers
6
Versions
284
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@architect/functions - npm Package Compare versions

Comparing version 5.2.3 to 5.2.4-RC.0

src/_get-ports.js

50

package.json
{
"name": "@architect/functions",
"version": "5.2.3",
"version": "5.2.4-RC.0",
"description": "Cloud function signatures for HTTP handlers, pub/sub + scheduled, queued functions, table triggers, and more",

@@ -12,6 +12,4 @@ "homepage": "https://github.com/architect/functions",

"main": "src/index",
"types": "types",
"typings": "types",
"types": "types/index.d.ts",
"scripts": {
"dtslint": "dtslint types",
"lint": "eslint --fix .",

@@ -21,3 +19,5 @@ "test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-spec",

"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
"_test": "npm run lint && npm run test:unit",
"test": "npm run lint && npm run test:integration && npm run coverage",
"test:types": "tsd --files types/*.test-d.ts",
"rc": "npm version prerelease --preid RC"

@@ -40,23 +40,29 @@ },

"devDependencies": {
"@architect/asap": "^5.0.1",
"@architect/eslint-config": "1.0.1",
"@architect/asap": "^5.0.2",
"@architect/eslint-config": "2.0.1",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"@architect/sandbox": "^5.3.4",
"@definitelytyped/dtslint": "^0.0.127",
"@types/aws-lambda": "^8.10.103",
"@types/node": "^18.7.16",
"aws-sdk": "2.1055.0",
"@architect/sandbox": "^5.3.6-RC.0",
"@aws-sdk/client-apigatewaymanagementapi": "^3.213.0",
"@aws-sdk/client-dynamodb": "^3.213.0",
"@aws-sdk/client-sns": "^3.213.0",
"@aws-sdk/client-sqs": "^3.213.0",
"@aws-sdk/client-ssm": "^3.213.0",
"@aws-sdk/lib-dynamodb": "^3.214.0",
"@types/aws-lambda": "^8.10.108",
"@types/node": "^18.11.9",
"aws-sdk": "^2.1259.0",
"cross-env": "~7.0.3",
"eslint": "~8.25.0",
"mock-fs": "~5.1.4",
"eslint": "~8.27.0",
"mock-fs": "~5.2.0",
"nyc": "~15.1.0",
"proxyquire": "~2.1.3",
"sinon": "~14.0.1",
"sinon": "~14.0.2",
"tap-spec": "~5.0.0",
"tape": "~5.6.1",
"tiny-json-http": "~7.4.2"
"tiny-json-http": "~7.4.2",
"tsd": "^0.24.1"
},
"files": [
"src/*",
"types/*"
"types/*",
"src/*"
],

@@ -78,4 +84,12 @@ "keywords": [

"eslintConfig": {
"extends": "@architect/eslint-config"
"extends": "@architect/eslint-config",
"rules": {
"global-require": "off"
}
},
"tsd": {
"compilerOptions": {
"strict": false
}
}
}

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

const isNode18 = require('../_node-version')
/**

@@ -6,13 +8,15 @@ * @param {string} type - events, queues, or tables

module.exports = function lookup (callback) {
// We really only want to load aws-sdk if absolutely necessary, and only the client we need
// eslint-disable-next-line
let SSM = require('aws-sdk/clients/ssm')
let { ARC_APP_NAME: app, ARC_ENV: env, ARC_SANDBOX, ARC_STACK_NAME: stack, AWS_REGION } = process.env
let local = env === 'testing'
if (!local && !app && !stack) {
return callback(ReferenceError('ARC_APP_NAME and ARC_STACK_NAME env vars not found'))
}
if (local && !app) {
app = 'arc-app'
}
let Path = `/${stack || toLogicalID(`${app}-${env}`)}`

@@ -37,6 +41,25 @@ let Recursive = true

}
let ssm = new SSM(config)
// shim v2 and v3
let method
if (isNode18) {
const {
SSMClient: SSM, GetParametersByPathCommand
} = require('@aws-sdk/client-ssm')
const ssm = new SSM(config)
method = (params, callback) => {
const command = new GetParametersByPathCommand(params)
return ssm.send(command, callback)
}
}
else {
const SSM = require('aws-sdk/clients/ssm')
const ssm = new SSM(config)
method = (params, callback) => {
return ssm.getParametersByPath(params, callback)
}
}
function getParams (params) {
ssm.getParametersByPath(params, function done (err, result) {
method(params, function done (err, result) {
if (err && local &&

@@ -43,0 +66,0 @@ err.message.includes('Inaccessible host') &&

@@ -0,3 +1,4 @@

let isNode18 = require('../_node-version')
let http = require('http')
let getPorts = require('../lib/get-ports')
let getPorts = require('../_get-ports')
let ledger = { events: {}, queues: {} }

@@ -78,10 +79,23 @@ let port

function eventFactory (arc) {
return function live ({ name, payload }, callback) {
// We really only want to load aws-sdk if absolutely necessary, and only the client we need
// eslint-disable-next-line
let method
if (isNode18) {
let { SNS } = require('@aws-sdk/client-sns')
let sns = new SNS
method = (params, callback) => {
return sns.publish(params, callback)
}
}
else {
let SNS = require('aws-sdk/clients/sns')
let sns = new SNS
method = (params, callback) => {
return sns.publish(params, callback)
}
}
return function live ({ name, payload }, callback) {
function publish (arn, payload, callback) {
let sns = new SNS
sns.publish({
method({
TopicArn: arn,

@@ -110,9 +124,22 @@ Message: JSON.stringify(payload)

function queueFactory (arc) {
return function live ({ name, payload, delaySeconds, groupID }, callback) {
// We really only want to load aws-sdk if absolutely necessary, and only the client we need
// eslint-disable-next-line
let method
if (isNode18) {
let { SQS } = require('@aws-sdk/client-sqs')
let sqs = new SQS
method = (params, callback) => {
return sqs.sendMessage(params, callback)
}
}
else {
let SQS = require('aws-sdk/clients/sqs')
let sqs = new SQS
method = (params, callback) => {
return sqs.sendMessage(params, callback)
}
}
return function live ({ name, payload, delaySeconds, groupID }, callback) {
function publish (arn, payload, callback) {
let sqs = new SQS
let params = {

@@ -126,3 +153,3 @@ QueueUrl: arn,

}
sqs.sendMessage(params, callback)
method(params, callback)
}

@@ -129,0 +156,0 @@

@@ -30,3 +30,3 @@ let parallel = require('run-parallel')

}
return await Promise.all(event.Records.map(async record => {
return Promise.all(event.Records.map(async record => {
try {

@@ -33,0 +33,0 @@ let payload = isEvents ? record.Sns.Message : record.body

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

let { sandboxVersionAtLeast } = require('./lib/version')
let sandboxVersionAtLeast = require('./_sandbox-version')

@@ -3,0 +3,0 @@ /**

let https = require('https')
let getPorts = require('../lib/get-ports')
let db, doc
let isNode18 = require('../_node-version')
let getPorts = require('../_get-ports')

@@ -8,13 +8,10 @@ /**

*/
let db, doc
function getDynamo (type, callback) {
if (!type) throw ReferenceError('Must supply Dynamo service interface type')
// We really only want to load aws-sdk if absolutely necessary
// eslint-disable-next-line
let dynamo = require('aws-sdk/clients/dynamodb')
if (!type)
throw ReferenceError('Must supply Dynamo service interface type')
let { ARC_ENV, ARC_LOCAL, AWS_REGION } = process.env
let local = ARC_ENV === 'testing' || ARC_LOCAL
let DB = dynamo
let Doc = dynamo.DocumentClient

@@ -24,2 +21,3 @@ if (db && type === 'db') {

}
if (doc && type === 'doc') {

@@ -29,21 +27,29 @@ return callback(null, doc)

let DB, Doc
if (isNode18) {
let dynamo = require('@aws-sdk/client-dynamodb')
let docclient = require('@aws-sdk/lib-dynamodb')
DB = dynamo.DynamoDB
Doc = docclient.DynamoDBDocument
}
else {
let dynamo = require('aws-sdk/clients/dynamodb')
DB = dynamo
Doc = dynamo.DocumentClient
}
let local = ARC_ENV === 'testing' || ARC_LOCAL
if (!local) {
let agent = new https.Agent({
keepAlive: true,
maxSockets: 50, // Node can set to Infinity; AWS maxes at 50; check back on this every once in a while
rejectUnauthorized: true,
})
// TODO? migrate to using `AWS_NODEJS_CONNECTION_REUSE_ENABLED`?
let config = {
httpOptions: { agent }
httpOptions: {
agent: new https.Agent({
keepAlive: true,
maxSockets: 50, // Node can set to Infinity; AWS maxes at 50
rejectUnauthorized: true,
})
}
}
if (type === 'db') {
db = new DB(config)
return callback(null, db)
}
if (type === 'doc') {
doc = new Doc(config)
return callback(null, doc)
}
db = isNode18 ? new DB : new DB(config)
doc = isNode18 ? Doc.from(db) : new Doc(config)
return callback(null, type === 'db' ? db : doc)
}

@@ -62,10 +68,5 @@ else {

}
if (type === 'db') {
db = new DB(config)
return callback(null, db)
}
if (type === 'doc') {
doc = new Doc(config)
return callback(null, doc)
}
db = new DB(config)
doc = isNode18 ? Doc.from(db) : new Doc(config)
return callback(null, type === 'db' ? db : doc)
}

@@ -77,4 +78,4 @@ })

module.exports = {
doc: getDynamo.bind({}, 'doc'),
db: getDynamo.bind({}, 'db'),
doc: getDynamo.bind({}, 'doc'),
}

@@ -20,2 +20,3 @@ let waterfall = require('run-waterfall')

module.exports = function tables (arc) {
function api (callback) {

@@ -42,3 +43,5 @@ let promise

})
.catch(callback)
.catch(err => {
callback(err)
})
},

@@ -45,0 +48,0 @@ factory,

@@ -1,7 +0,8 @@

let _api
const isNode18 = require('../_node-version')
let _api, _send, _close, _info
function instantiateAPI () {
if (_api) return
// We really only want to load aws-sdk if absolutely necessary
// eslint-disable-next-line
let ApiGatewayManagementApi = require('aws-sdk/clients/apigatewaymanagementapi')
let {

@@ -14,2 +15,15 @@ ARC_ENV,

} = process.env
if (isNode18) {
var {
ApiGatewayManagementApi,
PostToConnectionCommand,
DeleteConnectionCommand,
GetConnectionCommand
} = require('@aws-sdk/client-apigatewaymanagementapi')
}
else {
var ApiGatewayManagementApi = require('aws-sdk/clients/apigatewaymanagementapi')
}
let local = ARC_ENV === 'testing' || ARC_LOCAL

@@ -19,3 +33,4 @@ if (local) {

let port = ports._arc
if (!port) throw ReferenceError('Architect internal port not found')
if (!port)
throw ReferenceError('Architect internal port not found')
_api = new ApiGatewayManagementApi({

@@ -33,2 +48,35 @@ apiVersion: '2018-11-29',

}
/** idk.. **/
_send = (params, callback) => {
if (isNode18) {
let cmd = new PostToConnectionCommand(params)
return _api.send(cmd, callback)
}
else {
return callback ? _api.postToConnection(params, callback) : _api.postToConnection(params).promise()
}
}
/** idk.. **/
_close = (params, callback) => {
if (isNode18) {
let cmd = new DeleteConnectionCommand(params)
return _api.send(cmd, callback)
}
else {
return callback ? _api.deleteConnection(params, callback) : _api.deleteConnection(params).promise()
}
}
/** idk.. **/
_info = (params, callback) => {
if (isNode18) {
let cmd = new GetConnectionCommand(params)
return _api.send(cmd, callback)
}
else {
return callback ? _api.getConnection(params, callback) : _api.getConnection(params).promise()
}
}
}

@@ -49,12 +97,6 @@

instantiateAPI()
let params = {
return _send({
ConnectionId: id,
Data: JSON.stringify(payload)
}
if (callback) {
_api.postToConnection(params, callback)
return
}
return _api.postToConnection(params).promise()
}, callback)
}

@@ -74,8 +116,5 @@

instantiateAPI()
let params = { ConnectionId: id }
if (callback) {
_api.deleteConnection(params, callback)
return
}
return _api.deleteConnection(params).promise()
return _close({
ConnectionId: id,
}, callback)
}

@@ -95,8 +134,5 @@

instantiateAPI()
let params = { ConnectionId: id }
if (callback) {
_api.getConnection(params, callback)
return
}
return _api.getConnection(params).promise()
return _info({
ConnectionId: id,
}, callback)
}

@@ -103,0 +139,0 @@

@@ -5,3 +5,3 @@ import { SNS, SQS } from "aws-sdk";

// Turn off automatic exporting
export {};
export { };

@@ -21,9 +21,8 @@ interface Params<Payload> {

params: Params<Payload>,
callback: Callback<PublishResult>
callback: Callback<PublishResult>,
): void;
subscribe<Event = any>(
handler:
| ((event: Event) => Promise<void>)
| ((event: Event, callback: Callback<void>) => void)
| ((event: Event, callback: Callback<void>) => void),
): LambdaFunction;

@@ -30,0 +29,0 @@ }

@@ -9,3 +9,3 @@ import {

// Turn off automatic exporting
export {};
export { };

@@ -21,40 +21,17 @@ export type HttpMethods = "GET" | "POST" | "PATCH" | "PUT" | "DELETE";

httpMethod: HttpMethods;
/**
* The absolute path of the request
*/
/** The absolute path of the request */
path: string;
/**
* The absolute path of the request, with resources substituted for actual path parts (e.g. /{foo}/bar)
*/
/** The absolute path of the request, with resources substituted for actual path parts (e.g. /{foo}/bar) */
resource: string;
/**
* Any URL params, if defined in your HTTP Function's path (e.g. foo in GET /:foo/bar)
*/
/** Any URL params, if defined in your HTTP Function's path (e.g. foo in GET /:foo/bar) */
pathParameters: Record<string, string>;
/**
* Any query params if present in the client request
*/
/** Any query params if present in the client request */
queryStringParameters: Record<string, string>;
/**
* All client request headers
*/
/** All client request headers */
headers: Record<string, string>;
/**
* The request body in a base64-encoded buffer. You'll need to parse request.body before you can use it, but Architect provides tools to do this - see parsing request bodies.
*/
/** The request body in a base64-encoded buffer. You'll need to parse request.body before you can use it, but Architect provides tools to do this - see parsing request bodies. */
body: RequestBody;
/**
* Indicates whether body is base64-encoded binary payload (will always be true if body has not null)
*/
/** Indicates whether body is base64-encoded binary payload (will always be true if body has not null) */
isBase64Encoded: boolean;
/**
* When the request/response is run through arc.http.async (https://arc.codes/docs/en/reference/runtime/node#arc.http.async) then it will have session added.
*/
/** When the request/response is run through arc.http.async (https://arc.codes/docs/en/reference/runtime/node#arc.http.async) then it will have session added. */
session?: SessionData | undefined;

@@ -64,17 +41,8 @@ }

export interface HttpResponse {
/**
* Sets the HTTP status code
*/
/** Sets the HTTP status code */
statusCode?: number | undefined;
/**
* Alias for @see statusCode
*/
/** Alias for @see statusCode */
status?: number | undefined;
/**
* All response headers
*/
/** All response headers */
headers?: Record<string, string> | undefined;
/**

@@ -85,3 +53,2 @@ * Contains request body, either as a plain string (no encoding or serialization required) or, if binary, base64-encoded buffer

body?: string | undefined;
/**

@@ -92,8 +59,4 @@ * Indicates whether body is base64-encoded binary payload

isBase64Encoded?: boolean | undefined;
/**
* When the request/response is run through arc.http.async (https://arc.codes/docs/en/reference/runtime/node#arc.http.async) then it will have session added.
*/
/** When the request/response is run through arc.http.async (https://arc.codes/docs/en/reference/runtime/node#arc.http.async) then it will have session added. */
session?: SessionData | undefined;
/**

@@ -104,3 +67,2 @@ * When used with https://arc.codes/docs/en/reference/runtime/node#arc.http.async

json?: JsonBody | undefined;
/**

@@ -116,3 +78,3 @@ * When used with https://arc.codes/docs/en/reference/runtime/node#arc.http.async

res: (resOrError: HttpResponse | Error) => void,
next: () => void
next: () => void,
) => void;

@@ -122,3 +84,3 @@

req: HttpRequest,
context: Context
context: Context,
) => Promise<HttpResponse>;

@@ -128,3 +90,3 @@

event: APIGatewayProxyEvent,
context: Context
context: Context,
) => Promise<APIGatewayProxyResult>;

@@ -135,3 +97,2 @@

async: (...handlers: AsyncHandler[]) => LambdaHandler;
helpers: {

@@ -142,3 +103,2 @@ bodyParser: (req: HttpRequest) => Record<string, any>;

};
session: {

@@ -145,0 +105,0 @@ read(req: HttpRequest): Promise<SessionData>;

@@ -5,3 +5,3 @@ import type { DynamoDB } from "aws-sdk";

// Turn off automatic exporting
export {};
export { };

@@ -8,0 +8,0 @@ // TableName not needed as the library sets it

@@ -5,3 +5,3 @@ import { ApiGatewayManagementApi } from "aws-sdk";

// Turn off automatic exporting
export {};
export { };

@@ -8,0 +8,0 @@ type SendParams = { id: string; payload: any };

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