@adobe/aio-lib-web 7.3.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 CHANGED
@@ -30,4 +30,4 @@ Contributions are welcomed! Read the [Contributing Guide](./.github/CONTRIBUTING
30
30
 
31
31
  ## Licensing
32
32
 
33
- This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.
33
+ This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.
@@ -20,19 +20,52 @@ const http = require('http')
20
20
  // Proxy support for AWS SDK v3 (inspired by PR #224 by pat-lego, with compatibility fixes)
21
21
  const { NodeHttpHandler } = require('@smithy/node-http-handler')
22
22
  const { ProxyAgent } = require('proxy-agent')
23
+ const { EnvHttpProxyAgent } = require('undici')
23
24
  const { codes, logAndThrow } = require('./StorageError')
25
+ const aioLibEnv = require('@adobe/aio-lib-env')
26
+
27
+ // Set AIO_DEPLOYMENT_SERVICE_URL env var to override the default deploy-service url
28
+ // dev deploy => https://deploy-service.dev.app-builder.adp.adobe.io
29
+ // run local => http://localhost:3000
30
+ const getDeploymentServiceUrl = () => {
31
+ if (process.env.AIO_DEPLOYMENT_SERVICE_URL) {
32
+ return process.env.AIO_DEPLOYMENT_SERVICE_URL
33
+ }
34
+ return aioLibEnv.getCliEnv() === aioLibEnv.PROD_ENV
35
+ ? 'https://deploy-service.app-builder.adp.adobe.io'
36
+ : 'https://deploy-service.stg.app-builder.corp.adp.adobe.io'
37
+ }
24
38
 
25
39
  const fileExtensionPattern = /\*\.[0-9a-zA-Z]+$/
26
40
 
41
+ let fetchDispatcher
42
+ const getFetchDispatcher = () => {
43
+ if (!fetchDispatcher) {
44
+ fetchDispatcher = new EnvHttpProxyAgent()
45
+ }
46
+ return fetchDispatcher
47
+ }
48
+
49
+ const deployServiceFetch = (url, init) => {
50
+ return fetch(url, { ...init, dispatcher: getFetchDispatcher() })
51
+ }
52
+
27
53
  module.exports = class RemoteStorage {
28
54
  /**
29
- * @param {object} creds
55
+ * Without creds the deploy-service CDN API is used.
56
+ * With creds (BYO AWS S3) the S3 bucket is accessed directly.
57
+ *
58
+ * @param {object} [creds]
30
59
  * @param {string} creds.accessKeyId
31
60
  * @param {string} creds.secretAccessKey
32
61
  * @param {string} creds.params.Bucket
33
62
  * @param {string} [creds.sessionToken]
34
63
  */
35
64
  constructor (creds) {
65
+ if (creds === undefined || creds === null) {
66
+ // deploy-service mode
67
+ return
68
+ }
36
69
  const res = joi.object().keys({
37
70
  sessionToken: joi.string(),
38
71
  accessKeyId: joi.string().required(),
@@ -75,97 +108,196 @@ module.exports = class RemoteStorage {
75
108
  }
76
109
 
77
110
  /**
78
- * Checks if prefix exists
79
- * @param {string} prefix
80
- * @returns {boolean}
111
+ * Checks if any files exist for the namespace
112
+ * @param {string} authToken - Authorization header value (unused for BYO S3)
113
+ * @param {string} prefix - unused for deploy-service, S3 prefix for BYO S3
114
+ * @param {Object} appConfig - application config
115
+ * @returns {Promise<boolean>} true if files exist, false otherwise
81
116
  */
82
- async folderExists (prefix) {
117
+ async folderExists (authToken, prefix, appConfig) {
83
118
  if (typeof prefix !== 'string') {
84
119
  throw new Error('prefix must be a valid string')
85
120
  }
86
- const listParams = {
87
- Bucket: this.bucket,
88
- Prefix: prefix
89
- }
90
- const listedObjects = await this.s3.listObjectsV2(listParams)
121
+ if (this.s3) {
122
+ const listParams = {
123
+ Bucket: this.bucket,
124
+ Prefix: prefix
125
+ }
126
+ const listedObjects = await this.s3.listObjectsV2(listParams)
91
127
 
92
- return listedObjects.KeyCount > 0
128
+ return listedObjects.KeyCount > 0
129
+ }
130
+ // Call the list files endpoint (GET /files) - there is no GET /files/:key route
131
+ const response = await deployServiceFetch(`${getDeploymentServiceUrl()}/cdn-api/namespaces/${appConfig.ow.namespace}/files`, {
132
+ method: 'GET',
133
+ headers: {
134
+ Authorization: authToken
135
+ }
136
+ })
137
+ if (!response.ok) {
138
+ throw new Error(`cannot check if folder exists, request failed: ${response.status} ${response.statusText}`)
139
+ }
140
+ const files = await response.json()
141
+ // Check if there are any files (folder "exists" if it has content)
142
+ return Array.isArray(files) && files.length > 0
93
143
  }
94
144
 
95
145
  /**
96
- * Deletes all files in a prefix location
97
- * @param {string} prefix
146
+ * Empties all files for the namespace or deletes a specific file
147
+ * @param {string} authToken - Authorization header value
148
+ * @param {string} prefix - '/' to delete all files, or a specific file path
149
+ * @param {Object} appConfig - application config
150
+ * @returns {Promise<boolean>} true if the folder was emptied, false otherwise
98
151
  */
99
- async emptyFolder (prefix) {
100
- if (typeof prefix !== 'string') throw new Error('prefix must be a valid string')
101
- const listParams = {
102
- Bucket: this.bucket,
103
- Prefix: prefix
152
+ async emptyFolder (authToken, prefix, appConfig) {
153
+ if (typeof prefix !== 'string') {
154
+ throw new Error('prefix must be a valid string')
104
155
  }
105
- const listedObjects = await this.s3.listObjectsV2(listParams)
156
+ if (this.s3) {
157
+ const listParams = {
158
+ Bucket: this.bucket,
159
+ Prefix: prefix
160
+ }
161
+ const listedObjects = await this.s3.listObjectsV2(listParams)
106
162
 
107
- if (listedObjects.KeyCount < 1) {
163
+ if (listedObjects.KeyCount < 1) {
164
+ return
165
+ }
166
+ const deleteParams = {
167
+ Bucket: this.bucket,
168
+ Delete: { Objects: [] }
169
+ }
170
+ listedObjects.Contents.forEach(({ Key }) => {
171
+ deleteParams.Delete.Objects.push({ Key })
172
+ })
173
+ await this.s3.deleteObjects(deleteParams)
174
+ if (listedObjects.IsTruncated) {
175
+ await this.emptyFolder(authToken, prefix, appConfig)
176
+ }
108
177
  return
109
178
  }
110
- const deleteParams = {
111
- Bucket: this.bucket,
112
- Delete: { Objects: [] }
113
- }
114
- listedObjects.Contents.forEach(({ Key }) => {
115
- deleteParams.Delete.Objects.push({ Key })
179
+ // Server route is DELETE /files/:key
180
+ // When key='/' the server triggers emptyStorageForNamespace
181
+ // URL construction: /files/ (trailing slash makes :key = '/')
182
+ const deploymentServiceUrl = getDeploymentServiceUrl()
183
+ const url = prefix === '/'
184
+ ? `${deploymentServiceUrl}/cdn-api/namespaces/${appConfig.ow.namespace}/files/`
185
+ : `${deploymentServiceUrl}/cdn-api/namespaces/${appConfig.ow.namespace}/files/${prefix}`
186
+
187
+ const response = await deployServiceFetch(url, {
188
+ method: 'DELETE',
189
+ headers: {
190
+ Authorization: authToken
191
+ }
116
192
  })
117
- await this.s3.deleteObjects(deleteParams)
118
- if (listedObjects.IsTruncated) {
119
- await this.emptyFolder(prefix)
120
- }
193
+ return response.ok
121
194
  }
122
195
 
123
196
  /**
124
- * Uploads a file
125
- * @param {string} file
126
- * @param {string} prefix - prefix to upload the file to
197
+ * Uploads a file to the CDN API
198
+ * @param {string} authToken - Authorization header value
199
+ * @param {string} file - Full local file path
200
+ * @param {string} filePath - Path relative to namespace (e.g., 'images/photo.jpg' or 'index.html')
201
+ * This becomes file.name in the API request. The server will prepend the namespace.
127
202
  * @param {Object} appConfig - application config
128
- * @param {string} distRoot - Distribution root dir
203
+ * @param {string} distRoot - Distribution root dir (used for header matching)
129
204
  */
130
- async uploadFile (file, prefix, appConfig, distRoot) {
131
- if (typeof prefix !== 'string') {
132
- throw new Error('prefix must be a valid string')
205
+ async uploadFile (authToken, file, filePath, appConfig, distRoot) {
206
+ if (typeof filePath !== 'string') {
207
+ throw new Error('filePath must be a valid string')
208
+ }
209
+ if (this.s3) {
210
+ // BYO S3: filePath is the S3 prefix to upload the file to
211
+ const prefix = filePath
212
+ const content = await fs.readFile(file)
213
+ const mimeType = mime.lookup(path.extname(file))
214
+ // first we will grab it from the global config: htmlCacheDuration, etc.
215
+ const cacheControlString = this._getCacheControlConfig(mimeType, appConfig.app)
216
+ const uploadParams = {
217
+ Bucket: this.bucket,
218
+ Key: this._urlJoin(prefix, path.basename(file)),
219
+ Body: content
220
+ }
221
+ // if we found it in the global config, we will use it ( for now )
222
+ if (cacheControlString) {
223
+ uploadParams.CacheControl = cacheControlString
224
+ }
225
+ // add response headers if specified in manifest
226
+ const responseHeaders = this.getResponseHeadersForFile(file, distRoot, appConfig) ?? {}
227
+ // here we allow overriding the cache control if specified in response headers
228
+ // this is considered more specific than the general cache control config
229
+ // ideally we deprecate cache control config in favor of response headers directly
230
+ if (responseHeaders?.['adp-cache-control']) {
231
+ uploadParams.CacheControl = responseHeaders['adp-cache-control']
232
+ delete responseHeaders['adp-cache-control']
233
+ }
234
+
235
+ // we only set metadata if we have added anything to responseHeaders object
236
+ // it is not null, but could be empty
237
+ if (Object.keys(responseHeaders).length > 0) {
238
+ uploadParams.Metadata = responseHeaders
239
+ }
240
+ // s3 misses some mime types like for css files
241
+ if (mimeType) {
242
+ uploadParams.ContentType = mimeType
243
+ }
244
+ // Note: putObject is recommended for files < 100MB and has a limit of 5GB, which is ok for our use case of storing static web assets
245
+ // if we intend to store larger files, we should use multipart upload and https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_storage.html
246
+ return this.s3.putObject(uploadParams)
133
247
  }
248
+ const url = `${getDeploymentServiceUrl()}/cdn-api/namespaces/${appConfig.ow.namespace}/files`
249
+
134
250
  const content = await fs.readFile(file)
135
251
  const mimeType = mime.lookup(path.extname(file))
136
252
  // first we will grab it from the global config: htmlCacheDuration, etc.
137
- const cacheControlString = this._getCacheControlConfig(mimeType, appConfig.app)
138
- const uploadParams = {
139
- Bucket: this.bucket,
140
- Key: this._urlJoin(prefix, path.basename(file)),
141
- Body: content
142
- }
143
- // if we found it in the global config, we will use it ( for now )
144
- if (cacheControlString) {
145
- uploadParams.CacheControl = cacheControlString
146
- }
253
+ let cacheControlString = this._getCacheControlConfig(mimeType, appConfig.app)
147
254
  // add response headers if specified in manifest
148
255
  const responseHeaders = this.getResponseHeadersForFile(file, distRoot, appConfig) ?? {}
149
256
  // here we allow overriding the cache control if specified in response headers
150
257
  // this is considered more specific than the general cache control config
151
258
  // ideally we deprecate cache control config in favor of response headers directly
152
259
  if (responseHeaders?.['adp-cache-control']) {
153
- uploadParams.CacheControl = responseHeaders['adp-cache-control']
260
+ cacheControlString = responseHeaders['adp-cache-control']
154
261
  delete responseHeaders['adp-cache-control']
155
262
  }
156
-
157
- // we only set metadata if we have added anything to responseHeaders object
158
- // it is not null, but could be empty
159
- if (Object.keys(responseHeaders).length > 0) {
160
- uploadParams.Metadata = responseHeaders
263
+ // server expected body is: { contentType, cacheControl, customHeaders: {}, file: { name, content } }
264
+ // file.name is the path relative to namespace (e.g., 'images/photo.jpg' or 'index.html')
265
+ // The server will prepend the namespace to create the S3 key: ${namespace}/${file.name}
266
+ const fileName = path.basename(file)
267
+ let relativeFilePath = filePath
268
+ if (relativeFilePath.startsWith('/')) {
269
+ relativeFilePath = relativeFilePath.substring(1)
270
+ }
271
+ // Use _urlJoin to normalize backslashes and construct the file path
272
+ const filePathForServer = this._urlJoin(relativeFilePath, fileName)
273
+ // NOTE: File content is base64-encoded in the JSON body
274
+ // which increases payload size by ~33%. Look at getting server to handle
275
+ // multipart uploads to avoid this.
276
+ const data = {
277
+ file: {
278
+ contentType: mimeType,
279
+ cacheControl: cacheControlString,
280
+ customHeaders: responseHeaders,
281
+ name: filePathForServer,
282
+ content: Buffer.from(content).toString('base64')
283
+ }
161
284
  }
162
- // s3 misses some mime types like for css files
163
- if (mimeType) {
164
- uploadParams.ContentType = mimeType
285
+ const response = await deployServiceFetch(url, {
286
+ method: 'PUT',
287
+ body: JSON.stringify(data),
288
+ headers: {
289
+ 'Content-Type': 'application/json',
290
+ Authorization: authToken
291
+ }
292
+ }).catch(error => {
293
+ console.error('Error uploading file:', file)
294
+ throw error
295
+ })
296
+ if (!response.ok) {
297
+ console.error('Failed to upload file:', file)
298
+ throw new Error(`Failed to upload file: ${response.statusText}`)
165
299
  }
166
- // Note: putObject is recommended for files < 100MB and has a limit of 5GB, which is ok for our use case of storing static web assets
167
- // if we intend to store larger files, we should use multipart upload and https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_storage.html
168
- return this.s3.putObject(uploadParams)
300
+ return response.status
169
301
  }
170
302
 
171
303
  getResponseHeadersForFile (file, distRoot, appConfig) {
@@ -250,15 +382,17 @@ module.exports = class RemoteStorage {
250
382
  }
251
383
 
252
384
  /**
253
- * Uploads all files in a dir to - recursion is supported
254
- * @param {string} dir - directory with files to upload
255
- * @param {string} prefix - prefix to upload the dir to
385
+ * Uploads all files in a directory recursively to the CDN API
386
+ * @param {string} authToken - Authorization header value
387
+ * @param {string} dir - Local directory with files to upload
388
+ * @param {string} basePath - Base path prefix for all files (e.g., from config.s3.folder)
389
+ * This is combined with each file's relative directory path.
256
390
  * @param {Object} appConfig - application config
257
391
  * @param {function} [postFileUploadCallback] - called for each uploaded file
258
392
  */
259
- async uploadDir (dir, prefix, appConfig, postFileUploadCallback) {
260
- if (typeof prefix !== 'string') {
261
- throw new Error('prefix must be a valid string')
393
+ async uploadDir (authToken, dir, basePath, appConfig, postFileUploadCallback) {
394
+ if (typeof basePath !== 'string') {
395
+ throw new Error('basePath must be a valid string')
262
396
  }
263
397
  // walk the whole directory recursively using klaw.
264
398
  const files = await this.walkDir(dir)
@@ -271,18 +405,28 @@ module.exports = class RemoteStorage {
271
405
  let fileBatch = files.splice(0, batchSize)
272
406
  const allResults = []
273
407
  while (fileBatch.length > 0) {
274
- const res = await Promise.all(fileBatch.map(async f => {
275
- // get file's relative folder to the base directory.
276
- let prefixDirectory = path.dirname(path.relative(dir, f))
277
- // base directory returns ".", ignore that.
278
- prefixDirectory = prefixDirectory === '.' ? '' : prefixDirectory
279
- // newPrefix is now the initial prefix plus the files relative directory path.
280
- const newPrefix = this._urlJoin(prefix, prefixDirectory)
281
- const s3Res = await this.uploadFile(f, newPrefix, appConfig, dir)
408
+ // this used to sleep, but I don't think we need it here.
409
+ // I am leaving it here in case we see issues with rate limiting.
410
+ // sleep for 100ms to prevent rate limiting
411
+ // await new Promise(resolve => setTimeout(resolve, 100))
412
+ const res = await Promise.all(fileBatch.map(async file => {
413
+ // Calculate the file's relative directory path from the base directory
414
+ // e.g., if dir='/dist' and file='/dist/images/photo.jpg', relativeDir='images'
415
+ let relativeDir = path.dirname(path.relative(dir, file))
416
+ // path.relative returns '.' for files in the root directory, normalize to empty string
417
+ relativeDir = relativeDir === '.' ? '' : relativeDir
418
+
419
+ // Combine basePath with relativeDir to get the full file path relative to namespace
420
+ // e.g., basePath='' + relativeDir='images' = 'images'
421
+ // basePath='assets' + relativeDir='images' = 'assets/images'
422
+ const filePath = this._urlJoin(basePath, relativeDir)
423
+
424
+ // Upload file with the calculated filePath (server will prepend namespace)
425
+ const s3Result = await this.uploadFile(authToken, file, filePath, appConfig, dir)
282
426
  if (postFileUploadCallback) {
283
- postFileUploadCallback(f)
427
+ postFileUploadCallback(file)
284
428
  }
285
- return s3Res
429
+ return s3Result
286
430
  }))
287
431
  allResults.push(res)
288
432
  fileBatch = files.splice(0, batchSize)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-lib-web",
3
- "version": "7.3.0",
3
+ "version": "8.0.0",
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": {
@@ -30,8 +30,9 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@adobe/aio-lib-core-config": "^5",
33
+ "@adobe/aio-lib-core-errors": "^4.0.1",
33
34
  "@adobe/aio-lib-core-logging": "^3",
34
- "@adobe/aio-lib-core-tvm": "^4",
35
+ "@adobe/aio-lib-env": "^3.0.1",
35
36
  "@aws-sdk/client-s3": "^3.1045.0",
36
37
  "@smithy/node-http-handler": "^4.0.2",
37
38
  "core-js": "^3.25.1",
@@ -42,7 +43,8 @@
42
43
  "mime-types": "^2.1.24",
43
44
  "parcel": "^2.15.4",
44
45
  "proxy-agent": "^6.3.0",
45
- "regenerator-runtime": "^0.13.7"
46
+ "regenerator-runtime": "^0.13.7",
47
+ "undici": "^7.30.2"
46
48
  },
47
49
  "devDependencies": {
48
50
  "@adobe/eslint-config-aio-lib-config": "^4.0.0",
package/src/deploy-web.js CHANGED
@@ -11,7 +11,6 @@ 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 fs = require('fs-extra')
17
16
  const path = require('path')
@@ -21,6 +20,16 @@ const deployWeb = async (config, log) => {
21
20
  throw new Error('cannot deploy web, app has no frontend or config is invalid')
22
21
  }
23
22
 
23
+ // byo: user supplied AWS S3 credentials, files are uploaded directly to the bucket
24
+ const byoCreds = config.s3 && config.s3.creds
25
+ let bearerToken
26
+ if (!byoCreds) {
27
+ bearerToken = await config?.ow?.auth_handler?.getAuthHeader()
28
+ if (!bearerToken) {
29
+ throw new Error('cannot deploy web, Authorization is required')
30
+ }
31
+ }
32
+
24
33
  /// build files
25
34
  const dist = config.web.distProd
26
35
  if (!fs.existsSync(dist) ||
@@ -30,19 +39,29 @@ const deployWeb = async (config, log) => {
30
39
  throw new Error(`missing files in ${dist}, maybe you forgot to build your UI ?`)
31
40
  }
32
41
 
33
- const creds = await getS3Credentials(config)
34
-
35
- const remoteStorage = new RemoteStorage(creds)
36
- const exists = await remoteStorage.folderExists(config.s3.folder + '/')
37
-
38
- if (exists) {
42
+ const remoteStorage = byoCreds ? new RemoteStorage(byoCreds) : new RemoteStorage()
43
+ // validate config.app.hostname and config.ow.namespace are not empty and are valid and do not contain invalid characters
44
+ if (!config.app.hostname || !config.ow.namespace) {
45
+ throw new Error('config.app.hostname and config.ow.namespace are required')
46
+ }
47
+ if (!config.app.hostname.match(/^[a-zA-Z0-9.-]+$/)) {
48
+ throw new Error('config.app.hostname is invalid')
49
+ }
50
+ if (!config.ow.namespace.match(/^[a-zA-Z0-9_-]+$/)) {
51
+ throw new Error('config.ow.namespace is invalid')
52
+ }
53
+ // byo uses the s3 folder as prefix in the bucket, deploy-service uses the namespace
54
+ const folderPrefix = byoCreds ? config.s3.folder + '/' : '/'
55
+ if (await remoteStorage.folderExists(bearerToken, folderPrefix, config)) {
39
56
  if (log) {
40
57
  log('warning: an existing deployment will be overwritten')
41
58
  }
42
- await remoteStorage.emptyFolder(config.s3.folder + '/')
59
+ await remoteStorage.emptyFolder(bearerToken, folderPrefix, config)
43
60
  }
44
61
  const _log = log ? (f) => log(`deploying ${path.relative(dist, f)}`) : null
45
- await remoteStorage.uploadDir(dist, config.s3.folder, config, _log)
62
+ // deploy-service prepends `${namespace}/` to file.name, so do not send a folder prefix
63
+ // (config.s3.folder is the namespace and would duplicate it: <ns>/<ns>/...)
64
+ await remoteStorage.uploadDir(bearerToken, dist, byoCreds ? config.s3.folder : '', config, _log)
46
65
 
47
66
  const url = `https://${config.ow.namespace}.${config.app.hostname}/index.html`
48
67
  return url
@@ -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