@adobe/aio-lib-web 7.2.0 → 8.0.0
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 +1 -1
- package/e2e/e2e.js +12 -4
- package/lib/remote-storage.js +219 -75
- package/package.json +5 -3
- package/src/build-web.js +11 -1
- package/src/bundle.js +28 -6
- package/src/constants.js +19 -0
- package/src/deploy-web.js +28 -9
- package/src/undeploy-web.js +18 -6
- package/test/jest.setup.js +28 -0
- package/test/lib/remote-storage.test.js +952 -554
- package/test/src/build-web.test.js +40 -1
- package/test/src/bundle.test.js +52 -0
- package/test/src/deploy-web.test.js +197 -79
- package/test/src/undeploy-web.test.js +88 -19
- package/lib/getS3Creds.js +0 -42
- package/test/lib/getS3Creds.test.js +0 -73
package/src/undeploy-web.js
CHANGED
|
@@ -11,22 +11,34 @@ governing permissions and limitations under the License.
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
const RemoteStorage = require('../lib/remote-storage')
|
|
14
|
-
const getS3Credentials = require('../lib/getS3Creds')
|
|
15
14
|
|
|
16
15
|
const undeployWeb = async (config) => {
|
|
17
16
|
if (!config || !config.app || !config.app.hasFrontend) {
|
|
18
17
|
throw new Error('cannot undeploy web, app has no frontend or config is invalid')
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
// byo: user supplied AWS S3 credentials, files are deleted directly from the bucket
|
|
21
|
+
const byoCreds = config.s3 && config.s3.creds
|
|
22
|
+
let bearerToken
|
|
23
|
+
if (!byoCreds) {
|
|
24
|
+
bearerToken = await config?.ow?.auth_handler?.getAuthHeader()
|
|
25
|
+
if (!bearerToken) {
|
|
26
|
+
throw new Error('cannot undeploy web, Authorization is required')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
22
29
|
|
|
23
|
-
const remoteStorage = new RemoteStorage(
|
|
30
|
+
const remoteStorage = byoCreds ? new RemoteStorage(byoCreds) : new RemoteStorage()
|
|
31
|
+
const folderPrefix = byoCreds ? config.s3.folder + '/' : '/'
|
|
24
32
|
|
|
25
|
-
if (!(await remoteStorage.folderExists(
|
|
26
|
-
throw new Error(`cannot undeploy static files, there is no deployment for ${config.s3.folder}`)
|
|
33
|
+
if (!(await remoteStorage.folderExists(bearerToken, folderPrefix, config))) {
|
|
34
|
+
throw new Error(`cannot undeploy static files, there is no deployment for ${byoCreds ? config.s3.folder : config.ow.namespace}`)
|
|
27
35
|
}
|
|
28
36
|
|
|
29
|
-
await remoteStorage.emptyFolder(
|
|
37
|
+
const deleted = await remoteStorage.emptyFolder(bearerToken, folderPrefix, config)
|
|
38
|
+
// the byo s3 flow does not return a result
|
|
39
|
+
if (!byoCreds && !deleted) {
|
|
40
|
+
throw new Error('cannot undeploy static files, failed to delete deployment files')
|
|
41
|
+
}
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
module.exports = undeployWeb
|
package/test/jest.setup.js
CHANGED
|
@@ -119,6 +119,30 @@ global.configWithModifiedWeb = (config, newWebConfig) => {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
global.fakeS3Bucket = 'fake-bucket'
|
|
122
|
+
global.fakeNamespace = 'fake-namespace'
|
|
123
|
+
global.fakeAuthToken = 'Bearer fake-auth-token'
|
|
124
|
+
|
|
125
|
+
// Config structure for deploy-service API (auth token is passed to RemoteStorage methods)
|
|
126
|
+
global.fakeAppConfig = {
|
|
127
|
+
ow: {
|
|
128
|
+
namespace: global.fakeNamespace
|
|
129
|
+
},
|
|
130
|
+
app: {
|
|
131
|
+
htmlCacheDuration: 60,
|
|
132
|
+
jsCacheDuration: 604800,
|
|
133
|
+
cssCacheDuration: 604800,
|
|
134
|
+
imageCacheDuration: 604800
|
|
135
|
+
},
|
|
136
|
+
web: {
|
|
137
|
+
'response-headers': {
|
|
138
|
+
'/*': {
|
|
139
|
+
testHeader: 'foo'
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Legacy config structure (kept for backwards compatibility with other tests)
|
|
122
146
|
global.fakeConfig = {
|
|
123
147
|
tvm: {
|
|
124
148
|
runtime: {
|
|
@@ -157,6 +181,10 @@ global.fakeConfig = {
|
|
|
157
181
|
testHeader: 'foo'
|
|
158
182
|
}
|
|
159
183
|
}
|
|
184
|
+
},
|
|
185
|
+
// Add ow property to legacy config for tests that use both
|
|
186
|
+
ow: {
|
|
187
|
+
namespace: global.fakeNamespace
|
|
160
188
|
}
|
|
161
189
|
}
|
|
162
190
|
|