@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.
@@ -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
- const creds = await getS3Credentials(config)
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(creds)
30
+ const remoteStorage = byoCreds ? new RemoteStorage(byoCreds) : new RemoteStorage()
31
+ const folderPrefix = byoCreds ? config.s3.folder + '/' : '/'
24
32
 
25
- if (!(await remoteStorage.folderExists(config.s3.folder + '/'))) {
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(config.s3.folder + '/')
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
@@ -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