@adobe/aio-lib-web 7.0.4 → 7.0.6

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.
@@ -17,6 +17,9 @@ const fs = require('fs-extra')
17
17
  const joi = require('joi')
18
18
  const klaw = require('klaw')
19
19
  const http = require('http')
20
+ // Proxy support for AWS SDK v3 (inspired by PR #224 by pat-lego, with compatibility fixes)
21
+ const { NodeHttpHandler } = require('@smithy/node-http-handler')
22
+ const { ProxyAgent } = require('proxy-agent')
20
23
  const { codes, logAndThrow } = require('./StorageError')
21
24
 
22
25
  const fileExtensionPattern = /\*\.[0-9a-zA-Z]+$/
@@ -71,8 +74,20 @@ module.exports = class RemoteStorage {
71
74
  }
72
75
  this.bucket = creds.params.Bucket
73
76
 
77
+ // Configure proxy support for AWS SDK v3
78
+ // ProxyAgent automatically handles proxy environment variables via proxy-from-env
79
+ const agent = new ProxyAgent()
80
+ const s3Config = {
81
+ credentials,
82
+ region,
83
+ requestHandler: new NodeHttpHandler({
84
+ httpAgent: agent,
85
+ httpsAgent: agent
86
+ })
87
+ }
88
+
74
89
  // https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/classes/s3.html#constructor
75
- this.s3 = new S3({ credentials, region })
90
+ this.s3 = new S3(s3Config)
76
91
  }
77
92
 
78
93
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-lib-web",
3
- "version": "7.0.4",
3
+ "version": "7.0.6",
4
4
  "description": "Utility tooling library to build and deploy Adobe I/O Project Firefly app static sites to CDN",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -33,6 +33,7 @@
33
33
  "@adobe/aio-lib-core-logging": "^3",
34
34
  "@adobe/aio-lib-core-tvm": "^4",
35
35
  "@aws-sdk/client-s3": "^3.624.0",
36
+ "@smithy/node-http-handler": "^4.0.2",
36
37
  "core-js": "^3.25.1",
37
38
  "fs-extra": "^11",
38
39
  "joi": "^17.2.1",
@@ -40,18 +41,21 @@
40
41
  "lodash.clonedeep": "^4.5.0",
41
42
  "mime-types": "^2.1.24",
42
43
  "parcel": "^2.7.0",
44
+ "proxy-agent": "^6.3.0",
43
45
  "regenerator-runtime": "^0.13.7"
44
46
  },
45
47
  "devDependencies": {
48
+ "@adobe/eslint-config-aio-lib-config": "^4.0.0",
46
49
  "@types/hapi__joi": "^17",
47
50
  "@types/jest": "^29",
48
- "eslint": "^8",
49
- "eslint-config-standard": "^17",
50
- "eslint-plugin-import": "^2.18.2",
51
- "eslint-plugin-jest": "^27.0.2",
52
- "eslint-plugin-n": "^15.2.5",
53
- "eslint-plugin-node": "^11",
54
- "eslint-plugin-promise": "^6",
51
+ "eslint": "^8.57.1",
52
+ "eslint-config-standard": "^17.1.0",
53
+ "eslint-plugin-import": "^2.31.0",
54
+ "eslint-plugin-jest": "^27.9.0",
55
+ "eslint-plugin-jsdoc": "^48.11.0",
56
+ "eslint-plugin-n": "^15.7.0",
57
+ "eslint-plugin-node": "^11.1.0",
58
+ "eslint-plugin-promise": "^6.6.0",
55
59
  "eslint-plugin-standard": "^5",
56
60
  "jest": "^29",
57
61
  "jsdoc-to-markdown": "^8",
@@ -49,7 +49,8 @@ describe('RemoteStorage', () => {
49
49
  sessionToken: global.fakeTVMResponse.sessionToken,
50
50
  expiration: new Date(global.fakeTVMResponse.expiration)
51
51
  },
52
- region: 'us-east-1'
52
+ region: 'us-east-1',
53
+ requestHandler: expect.any(Object)
53
54
  })
54
55
  rs.bucket = global.fakeTVMResponse.Bucket
55
56
  })
@@ -59,13 +60,122 @@ describe('RemoteStorage', () => {
59
60
  expect(S3).toHaveBeenCalledWith({
60
61
  credentials: {
61
62
  accessKeyId: global.fakeTVMResponse.accessKeyId,
62
- secretAccessKey: global.fakeTVMResponse.secretAccessKey
63
+ secretAccessKey: global.fakeTVMResponse.secretAccessKey,
64
+ sessionToken: undefined,
65
+ expiration: undefined
63
66
  },
64
- region: 'us-east-1'
67
+ region: 'us-east-1',
68
+ requestHandler: expect.any(Object)
65
69
  })
66
70
  rs.bucket = global.fakeTVMResponse.Bucket
67
71
  })
68
72
 
73
+ describe('Proxy configuration', () => {
74
+ const originalEnv = process.env
75
+
76
+ beforeEach(() => {
77
+ // Clear environment variables before each test
78
+ delete process.env.https_proxy
79
+ delete process.env.HTTPS_PROXY
80
+ delete process.env.http_proxy
81
+ delete process.env.HTTP_PROXY
82
+ })
83
+
84
+ afterAll(() => {
85
+ // Restore original environment
86
+ process.env = originalEnv
87
+ })
88
+
89
+ test('Constructor uses HTTPS_PROXY when set (uppercase)', async () => {
90
+ process.env.HTTPS_PROXY = 'http://proxy.example.com:8080'
91
+ // eslint-disable-next-line no-new
92
+ new RemoteStorage(global.fakeTVMResponse)
93
+
94
+ expect(S3).toHaveBeenCalledWith(expect.objectContaining({
95
+ requestHandler: expect.any(Object),
96
+ credentials: expect.any(Object),
97
+ region: 'us-east-1'
98
+ }))
99
+ })
100
+
101
+ test('Constructor uses https_proxy when set (lowercase)', async () => {
102
+ process.env.https_proxy = 'http://proxy.example.com:3128'
103
+ // eslint-disable-next-line no-new
104
+ new RemoteStorage(global.fakeTVMResponse)
105
+
106
+ expect(S3).toHaveBeenCalledWith(expect.objectContaining({
107
+ requestHandler: expect.any(Object),
108
+ credentials: expect.any(Object),
109
+ region: 'us-east-1'
110
+ }))
111
+ })
112
+
113
+ test('Constructor uses HTTP_PROXY when HTTPS_PROXY not set', async () => {
114
+ process.env.HTTP_PROXY = 'http://proxy.example.com:8080'
115
+ // eslint-disable-next-line no-new
116
+ new RemoteStorage(global.fakeTVMResponse)
117
+
118
+ expect(S3).toHaveBeenCalledWith(expect.objectContaining({
119
+ requestHandler: expect.any(Object),
120
+ credentials: expect.any(Object),
121
+ region: 'us-east-1'
122
+ }))
123
+ })
124
+
125
+ test('Constructor uses http_proxy when other proxy vars not set', async () => {
126
+ process.env.http_proxy = 'http://proxy.example.com:3128'
127
+ // eslint-disable-next-line no-new
128
+ new RemoteStorage(global.fakeTVMResponse)
129
+
130
+ expect(S3).toHaveBeenCalledWith(expect.objectContaining({
131
+ requestHandler: expect.any(Object),
132
+ credentials: expect.any(Object),
133
+ region: 'us-east-1'
134
+ }))
135
+ })
136
+
137
+ test('Constructor prioritizes HTTPS_PROXY over HTTP_PROXY', async () => {
138
+ process.env.HTTPS_PROXY = 'http://https-proxy.example.com:8080'
139
+ process.env.HTTP_PROXY = 'http://http-proxy.example.com:8080'
140
+ // eslint-disable-next-line no-new
141
+ new RemoteStorage(global.fakeTVMResponse)
142
+
143
+ expect(S3).toHaveBeenCalledWith(expect.objectContaining({
144
+ requestHandler: expect.any(Object),
145
+ credentials: expect.any(Object),
146
+ region: 'us-east-1'
147
+ }))
148
+ })
149
+
150
+ test('Constructor prioritizes https_proxy over HTTP_PROXY', async () => {
151
+ process.env.https_proxy = 'http://https-proxy.example.com:3128'
152
+ process.env.HTTP_PROXY = 'http://http-proxy.example.com:8080'
153
+ // eslint-disable-next-line no-new
154
+ new RemoteStorage(global.fakeTVMResponse)
155
+
156
+ expect(S3).toHaveBeenCalledWith(expect.objectContaining({
157
+ requestHandler: expect.any(Object),
158
+ credentials: expect.any(Object),
159
+ region: 'us-east-1'
160
+ }))
161
+ })
162
+
163
+ test('Constructor always includes requestHandler with ProxyAgent', async () => {
164
+ // eslint-disable-next-line no-new
165
+ new RemoteStorage(global.fakeTVMResponse)
166
+
167
+ expect(S3).toHaveBeenCalledWith({
168
+ credentials: expect.any(Object),
169
+ region: 'us-east-1',
170
+ requestHandler: expect.any(Object)
171
+ })
172
+
173
+ // ProxyAgent handles proxy detection automatically via proxy-from-env
174
+ const s3CallArgs = S3.mock.calls[S3.mock.calls.length - 1][0]
175
+ expect(s3CallArgs).toHaveProperty('requestHandler')
176
+ })
177
+ })
178
+
69
179
  test('folderExists missing prefix', async () => {
70
180
  const rs = new RemoteStorage(global.fakeTVMResponse)
71
181
  await expect(rs.folderExists()).rejects.toEqual(expect.objectContaining({ message: 'prefix must be a valid string' }))