@middy/s3-object-response 3.0.0-alpha.7 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/index.cjs +3 -0
- package/index.js +1 -1
- package/package.json +13 -6
package/README.md
CHANGED
|
@@ -65,6 +65,7 @@ NOTES:
|
|
|
65
65
|
import zlib from 'zlib'
|
|
66
66
|
import middy from '@middy/core'
|
|
67
67
|
import s3ObjectResponse from '@middy/s3-object-response'
|
|
68
|
+
import {captureAWSClient, captureHTTPsGlobal} from 'aws-xray-sdk-core'
|
|
68
69
|
|
|
69
70
|
const handler = middy((event, context) => {
|
|
70
71
|
const readStream = context.s3Object
|
|
@@ -76,6 +77,8 @@ const handler = middy((event, context) => {
|
|
|
76
77
|
|
|
77
78
|
handler
|
|
78
79
|
.use(s3ObjectResponse({
|
|
80
|
+
awsClientCapture: captureAWSClient,
|
|
81
|
+
httpsCapture:captureHTTPsGlobal,
|
|
79
82
|
bodyType: 'stream'
|
|
80
83
|
}))
|
|
81
84
|
```
|
|
@@ -85,6 +88,7 @@ handler
|
|
|
85
88
|
import zlib from 'zlib'
|
|
86
89
|
import middy from '@middy/core'
|
|
87
90
|
import s3ObjectResponse from '@middy/s3-object-response'
|
|
91
|
+
import {captureAWSClient, captureHTTPsGlobal} from 'aws-xray-sdk-core'
|
|
88
92
|
|
|
89
93
|
const handler = middy(async (event, context) => {
|
|
90
94
|
let body = await context.s3Object
|
|
@@ -96,6 +100,8 @@ const handler = middy(async (event, context) => {
|
|
|
96
100
|
|
|
97
101
|
handler
|
|
98
102
|
.use(s3ObjectResponse({
|
|
103
|
+
awsClientCapture: captureAWSClient,
|
|
104
|
+
httpsCapture:captureHTTPsGlobal,
|
|
99
105
|
bodyType: 'promise'
|
|
100
106
|
}))
|
|
101
107
|
```
|
package/index.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _https=_interopRequireDefault(require("https"));var _url=require("url");var _util=require("@middy/util");var _s3Js=_interopRequireDefault(require("aws-sdk/clients/s3.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var _response;const defaults={AwsClient:_s3Js.default,awsClientOptions:{},awsClientAssumeRole:undefined,awsClientCapture:undefined,httpsCapture:undefined,disablePrefetch:false,bodyType:undefined,__https:_https.default};let https=_https.default;const s3ObjectResponseMiddleware=(opts={})=>{const options={...defaults,...opts};if(!["stream","promise"].includes(options.bodyType)){throw new Error("[s3-object-response] bodyType is invalid")}if(options.httpsCapture){https=options.httpsCapture(options.__https)}let client;if((0,_util).canPrefetch(options)){client=(0,_util).createPrefetchClient(options)}const s3ObjectResponseMiddlewareBefore=async request=>{const{inputS3Url,outputRoute,outputToken}=request.event.getObjectContext;request.internal.s3ObjectResponse={RequestRoute:outputRoute,RequestToken:outputToken};const parsedInputS3Url=new _url.URL(inputS3Url);const fetchOptions={method:"GET",host:parsedInputS3Url.hostname,path:parsedInputS3Url.pathname};request.context.s3Object=fetchType(options.bodyType,fetchOptions)};const s3ObjectResponseMiddlewareAfter=async request=>{if(!client){client=await (0,_util).createClient(options,request)}(_response=request.response).Body??(_response.Body=request.response.body);delete request.response.body;await client.writeGetObjectResponse({...request.response,...request.internal.s3ObjectResponse}).promise();return{statusCode:200}};return{before:s3ObjectResponseMiddlewareBefore,after:s3ObjectResponseMiddlewareAfter}};const fetchType=(type,fetchOptions)=>{if(type==="stream"){return fetchStream(fetchOptions)}else if(type==="promise"){return fetchPromise(fetchOptions)}};const fetchStream=fetchOptions=>{return https.request(fetchOptions)};const fetchPromise=fetchOptions=>{return new Promise((resolve,reject)=>{let data="";const stream=fetchStream(fetchOptions);stream.on("data",chunk=>{data+=chunk});stream.on("end",()=>resolve(data));stream.on("error",error=>reject(error))})};var _default=s3ObjectResponseMiddleware;exports.default=_default
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import __https from
|
|
1
|
+
var _response;import __https from"https";import{URL}from"url";import{canPrefetch,createPrefetchClient,createClient}from"@middy/util";import S3 from"aws-sdk/clients/s3.js";const defaults={AwsClient:S3,awsClientOptions:{},awsClientAssumeRole:undefined,awsClientCapture:undefined,httpsCapture:undefined,disablePrefetch:false,bodyType:undefined,__https};let https=__https;const s3ObjectResponseMiddleware=(opts={})=>{const options={...defaults,...opts};if(!["stream","promise"].includes(options.bodyType)){throw new Error("[s3-object-response] bodyType is invalid")}if(options.httpsCapture){https=options.httpsCapture(options.__https)}let client;if(canPrefetch(options)){client=createPrefetchClient(options)}const s3ObjectResponseMiddlewareBefore=async request=>{const{inputS3Url,outputRoute,outputToken}=request.event.getObjectContext;request.internal.s3ObjectResponse={RequestRoute:outputRoute,RequestToken:outputToken};const parsedInputS3Url=new URL(inputS3Url);const fetchOptions={method:"GET",host:parsedInputS3Url.hostname,path:parsedInputS3Url.pathname};request.context.s3Object=fetchType(options.bodyType,fetchOptions)};const s3ObjectResponseMiddlewareAfter=async request=>{if(!client){client=await createClient(options,request)}(_response=request.response).Body??(_response.Body=request.response.body);delete request.response.body;await client.writeGetObjectResponse({...request.response,...request.internal.s3ObjectResponse}).promise();return{statusCode:200}};return{before:s3ObjectResponseMiddlewareBefore,after:s3ObjectResponseMiddlewareAfter}};const fetchType=(type,fetchOptions)=>{if(type==="stream"){return fetchStream(fetchOptions)}else if(type==="promise"){return fetchPromise(fetchOptions)}};const fetchStream=fetchOptions=>{return https.request(fetchOptions)};const fetchPromise=fetchOptions=>{return new Promise((resolve,reject)=>{let data="";const stream=fetchStream(fetchOptions);stream.on("data",chunk=>{data+=chunk});stream.on("end",()=>resolve(data));stream.on("error",error=>reject(error))})};export default s3ObjectResponseMiddleware
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/s3-object-response",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "S3 object response handling middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,10 +10,17 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"exports":
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./index.js",
|
|
16
|
+
"require": "./index.cjs",
|
|
17
|
+
"types": "./index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
14
20
|
"types": "index.d.ts",
|
|
15
21
|
"files": [
|
|
16
22
|
"index.js",
|
|
23
|
+
"index.cjs",
|
|
17
24
|
"index.d.ts"
|
|
18
25
|
],
|
|
19
26
|
"scripts": {
|
|
@@ -46,14 +53,14 @@
|
|
|
46
53
|
"bugs": {
|
|
47
54
|
"url": "https://github.com/middyjs/middy/issues"
|
|
48
55
|
},
|
|
49
|
-
"homepage": "https://
|
|
56
|
+
"homepage": "https://middy.js.org",
|
|
50
57
|
"dependencies": {
|
|
51
|
-
"@middy/util": "^3.0.
|
|
58
|
+
"@middy/util": "^3.0.1"
|
|
52
59
|
},
|
|
53
60
|
"devDependencies": {
|
|
54
|
-
"@middy/core": "^3.0.
|
|
61
|
+
"@middy/core": "^3.0.1",
|
|
55
62
|
"aws-sdk": "^2.939.0",
|
|
56
63
|
"aws-xray-sdk": "^3.3.3"
|
|
57
64
|
},
|
|
58
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "797455e2c2be445867bc03597e0a2d5b0560c9de"
|
|
59
66
|
}
|