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

@architect/asap

Package Overview
Dependencies
Maintainers
6
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@architect/asap - npm Package Compare versions

Comparing version 7.0.0 to 7.0.1

src/lib/is-node-18.js

12

package.json
{
"name": "@architect/asap",
"version": "7.0.0",
"version": "7.0.1",
"description": "Architect Static Asset Proxy (ASAP) - a helpful library for Lambda-based static asset delivery",

@@ -27,11 +27,9 @@ "main": "src/asap.js",

],
"dependencies": {
"@aws-lite/client": "^0.15.2",
"@aws-lite/s3": "^0.1.16"
},
"devDependencies": {
"@architect/eslint-config": "~2.1.2",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"@aws-sdk/client-s3": "3.188.0",
"aws-sdk": "^2.1363.0",
"cross-env": "7.0.3",
"eslint": "~8.56.0",
"eslint": "~8.54.0",
"mime-types": "~2.1.35",

@@ -42,3 +40,3 @@ "mock-tmp": "~0.0.2",

"tap-arc": "~1.2.2",
"tape": "~5.7.4"
"tape": "~5.7.2"
},

@@ -45,0 +43,0 @@ "keywords": [

@@ -0,6 +1,13 @@

let _isNode18 = require('../lib/is-node-18')
let { existsSync, readdirSync, readFileSync, statSync } = require('fs')
let { join, parse } = require('path')
let getS3 = require('../lib/get-s3')
let { httpError } = require('../lib/error')
let s3
if (process.env.__TESTING__) {
// eslint-disable-next-line
let S3 = require('aws-sdk/clients/s3')
s3 = new S3
}
/**

@@ -27,3 +34,4 @@ * Peek into a dir without a trailing slash to see if it's got an index.html file

async function getLocal ({ Key: file }) {
// eslint-disable-next-line
async function getLocal (file) {
if (!file.startsWith(sandboxPath)) {

@@ -49,9 +57,26 @@ file = join(sandboxPath, file)

async function get (Key) {
let getter = local ? getLocal : await getS3()
async function getS3 (Key) {
if (_isNode18) {
// eslint-disable-next-line
let { S3 } = require('@aws-sdk/client-s3')
let s3 = new S3({ region: process.env.AWS_REGION || 'us-west-2' })
return s3.getObject({ Bucket, Key })
}
else {
if (!process.env.__TESTING__) {
// eslint-disable-next-line
let S3 = require('aws-sdk/clients/s3')
s3 = new S3
}
return s3.getObject({ Bucket, Key }).promise()
}
}
async function get (file) {
let getter = local ? getLocal : getS3
try {
return await getter({ Bucket, Key })
return await getter(file)
}
catch (err) {
if (err.name === 'NoSuchKey' || err.code === 'NoSuchKey') {
if (err.name === 'NoSuchKey') {
err.statusCode = 404

@@ -58,0 +83,0 @@ return err

let { existsSync, readFileSync } = require('fs')
let { extname, join } = require('path')
let getS3 = require('../lib/get-s3')
let _isNode18 = require('../lib/is-node-18')
let _isHTMLorJSON = require('../lib/is-html-json')

@@ -77,10 +77,34 @@ let binaryTypes = require('../lib/binary-types')

let s3 = await getS3()
let method
if (_isNode18) {
// eslint-disable-next-line
let { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3')
let client = new S3Client({ region: process.env.AWS_REGION || 'us-west-2' })
method = async params => {
let command = new GetObjectCommand(params)
let res = await client.send(command)
let streamToString = stream => new Promise((resolve, reject) => {
let chunks = []
stream.on('data', chunk => chunks.push(chunk))
stream.on('error', reject)
stream.on('end', () => resolve(Buffer.concat(chunks)))
})
let Body = await streamToString(res.Body)
return { ...res, ...{ Body } }
}
}
else {
// eslint-disable-next-line
let S3 = require('aws-sdk/clients/s3')
let s3 = new S3
method = params => s3.getObject(params).promise()
}
let result
try {
result = await s3(options)
result = await method(options)
}
catch (err) {
// ETag matches (getObject error code of NotModified), so don't transit the whole file
if (err.code === 'NotModified' || err.statusCode === 304) {
if (err.code === 'NotModified' || err['$metadata']?.httpStatusCode === 304) {
matchedETag = true

@@ -87,0 +111,0 @@ headers.etag = IfNoneMatch

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