@middy/s3-object-response 2.5.6 → 3.0.0-alpha.3

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.
Files changed (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -4
  3. package/index.js +18 -13
  4. package/package.json +10 -8
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -25,8 +25,6 @@
25
25
  </p>
26
26
  </div>
27
27
 
28
- ** This middleware is a Proof of Concept and requires real world testing before use, not recommended for production **
29
-
30
28
  Fetches S3 object as a stream and writes back to s3 object response.
31
29
 
32
30
  ## Install
@@ -40,8 +38,9 @@ npm install --save @middy/s3-object-response
40
38
 
41
39
  ## Options
42
40
  - `bodyType` (string) (required): How to pass in the s3 object through the handler. Can be `stream` or `promise`.
43
- - `AwsClient` (object) (default `AWS.S3`): AWS.STS class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
41
+ - `AwsClient` (object) (default `AWS.S3`): AWS.S3 class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
44
42
  - `awsClientOptions` (object) (optional): Options to pass to AWS.STS class constructor.
43
+ - `awsClientAssumeRole` (string) (optional): Internal key where secrets are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
45
44
  - `awsClientCapture` (function) (optional): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
46
45
  - `httpsCapture` (function) (optional): Enable XRay by passing `captureHTTPsGlobal` from `aws-xray-sdk` in.
47
46
  - `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
@@ -104,7 +103,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
104
103
 
105
104
  ## License
106
105
 
107
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
106
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
108
107
 
109
108
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
110
109
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/index.js CHANGED
@@ -1,25 +1,29 @@
1
- let https = require('https')
2
- const { URL } = require('url')
1
+ import __https from 'https'
2
+ import { URL } from 'url'
3
3
 
4
- const {
4
+ import {
5
5
  canPrefetch,
6
6
  createPrefetchClient,
7
7
  createClient
8
- } = require('@middy/util')
8
+ } from '@middy/util'
9
9
 
10
- const S3 = require('aws-sdk/clients/s3') // v2
11
- // const { S3 } = require('@aws-sdk/client-s3') // v3
10
+ import S3 from 'aws-sdk/clients/s3.js' // v2
11
+ // import { S3 } from '@aws-sdk/client-s3' // v3
12
12
 
13
13
  const defaults = {
14
- AwsClient: S3, // Allow for XRay
14
+ AwsClient: S3,
15
15
  awsClientOptions: {},
16
16
  awsClientAssumeRole: undefined,
17
17
  awsClientCapture: undefined,
18
18
  httpsCapture: undefined,
19
19
  disablePrefetch: false,
20
- bodyType: undefined
20
+ bodyType: undefined,
21
+
22
+ // For mocking out only, rewire doesn't support ES Modules :(
23
+ __https
21
24
  }
22
25
 
26
+ let https = __https
23
27
  const s3ObjectResponseMiddleware = (opts = {}) => {
24
28
  const options = { ...defaults, ...opts }
25
29
 
@@ -28,7 +32,7 @@ const s3ObjectResponseMiddleware = (opts = {}) => {
28
32
  }
29
33
 
30
34
  if (options.httpsCapture) {
31
- https = options.httpsCapture(https)
35
+ https = options.httpsCapture(options.__https)
32
36
  }
33
37
 
34
38
  let client
@@ -63,16 +67,17 @@ const s3ObjectResponseMiddleware = (opts = {}) => {
63
67
  client = await createClient(options, request)
64
68
  }
65
69
 
66
- request.response.Body = request.response.Body ?? request.response.body
70
+ request.response.Body ??= request.response.body
67
71
  delete request.response.body
68
72
 
69
- return client
73
+ await client
70
74
  .writeGetObjectResponse({
71
75
  ...request.response,
72
76
  ...request.internal.s3ObjectResponse
73
77
  })
74
78
  .promise()
75
- .then(() => ({ statusCode: 200 })) // TODO test if needed
79
+
80
+ return { statusCode: 200 }
76
81
  }
77
82
 
78
83
  return {
@@ -106,4 +111,4 @@ const fetchPromise = (fetchOptions) => {
106
111
  })
107
112
  }
108
113
 
109
- module.exports = s3ObjectResponseMiddleware
114
+ export default s3ObjectResponseMiddleware
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@middy/s3-object-response",
3
- "version": "2.5.6",
3
+ "version": "3.0.0-alpha.3",
4
4
  "description": "S3 object response handling middleware for the middy framework",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "engines": {
7
- "node": ">=12"
7
+ "node": ">=14"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "index.js",
13
+ "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
+ "index.js",
16
17
  "index.d.ts"
17
18
  ],
18
19
  "scripts": {
19
20
  "test": "npm run test:unit",
20
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
21
23
  },
22
24
  "license": "MIT",
23
25
  "keywords": [
@@ -46,12 +48,12 @@
46
48
  },
47
49
  "homepage": "https://github.com/middyjs/middy#readme",
48
50
  "dependencies": {
49
- "@middy/util": "^2.5.6"
51
+ "@middy/util": "^3.0.0-alpha.3"
50
52
  },
51
53
  "devDependencies": {
52
- "@middy/core": "^2.5.6",
54
+ "@middy/core": "^3.0.0-alpha.3",
53
55
  "aws-sdk": "^2.939.0",
54
56
  "aws-xray-sdk": "^3.3.3"
55
57
  },
56
- "gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b"
58
+ "gitHead": "1441158711580313765e6d156046ef0fade0d156"
57
59
  }