@architect/asap
Advanced tools
Comparing version 7.0.0 to 7.0.1
{ | ||
"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 |
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
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
32964
0
931
12
12
- Removed@aws-lite/client@^0.15.2
- Removed@aws-lite/s3@^0.1.16
- Removed@aws-lite/client@0.15.2(transitive)
- Removed@aws-lite/s3@0.1.22(transitive)
- Removedaws4@1.13.2(transitive)
- Removedini@4.1.3(transitive)