@architect/asap
Advanced tools
Comparing version 7.0.2 to 7.0.3-RC.0
{ | ||
"name": "@architect/asap", | ||
"version": "7.0.2", | ||
"version": "7.0.3-RC.0", | ||
"description": "Architect Static Asset Proxy (ASAP) - a helpful library for Lambda-based static asset delivery", | ||
@@ -27,9 +27,11 @@ "main": "src/asap.js", | ||
], | ||
"dependencies": { | ||
"@aws-lite/client": "~0.16.0-RC.0", | ||
"@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.54.0", | ||
"eslint": "~8.56.0", | ||
"mime-types": "~2.1.35", | ||
@@ -40,3 +42,3 @@ "mock-tmp": "~0.0.2", | ||
"tap-arc": "~1.2.2", | ||
"tape": "~5.7.2" | ||
"tape": "~5.7.4" | ||
}, | ||
@@ -43,0 +45,0 @@ "keywords": [ |
@@ -1,13 +0,6 @@ | ||
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 | ||
} | ||
/** | ||
@@ -34,4 +27,3 @@ * Peek into a dir without a trailing slash to see if it's got an index.html file | ||
// eslint-disable-next-line | ||
async function getLocal (file) { | ||
async function getLocal ({ Key: file }) { | ||
if (!file.startsWith(sandboxPath)) { | ||
@@ -57,26 +49,9 @@ file = join(sandboxPath, file) | ||
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 | ||
async function get (Key) { | ||
let getter = local ? getLocal : await getS3() | ||
try { | ||
return await getter(file) | ||
return await getter({ Bucket, Key, rawResponsePayload: true }) | ||
} | ||
catch (err) { | ||
if (err.name === 'NoSuchKey') { | ||
if (err.name === 'NoSuchKey' || err.code === 'NoSuchKey') { | ||
err.statusCode = 404 | ||
@@ -83,0 +58,0 @@ return err |
let { existsSync, readFileSync } = require('fs') | ||
let { extname, join } = require('path') | ||
let _isNode18 = require('../lib/is-node-18') | ||
let getS3 = require('../lib/get-s3') | ||
let _isHTMLorJSON = require('../lib/is-html-json') | ||
@@ -29,2 +29,3 @@ let binaryTypes = require('../lib/binary-types') | ||
module.exports = async function readS3 (params) { | ||
let { Bucket, Key, IfNoneMatch, isFolder, config, rootPath } = params | ||
@@ -73,3 +74,3 @@ let { ARC_STATIC_PREFIX } = process.env | ||
let options = { Bucket, Key } | ||
let options = { Bucket, Key, rawResponsePayload: true } | ||
if (IfNoneMatch) { | ||
@@ -79,34 +80,10 @@ options.IfNoneMatch = IfNoneMatch | ||
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 s3 = await getS3() | ||
let result | ||
try { | ||
result = await method(options) | ||
result = await s3(options) | ||
} | ||
catch (err) { | ||
// ETag matches (getObject error code of NotModified), so don't transit the whole file | ||
if (err.code === 'NotModified' || err['$metadata']?.httpStatusCode === 304) { | ||
if (err.code === 'NotModified' || err.statusCode === 304) { | ||
matchedETag = true | ||
@@ -113,0 +90,0 @@ headers.etag = IfNoneMatch |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
10
9
31810
2
897
1
+ Added@aws-lite/s3@^0.1.16
+ Added@aws-lite/client@0.16.1(transitive)
+ Added@aws-lite/s3@0.1.22(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedini@4.1.3(transitive)