@fastly/compute-js-static-publish 8.0.1 → 8.1.0-beta.1

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 (247) hide show
  1. package/DOCUMENTATION.md +779 -22
  2. package/README.md +2 -2
  3. package/README.short.md +2 -2
  4. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/clean.js +12 -7
  6. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/collections/delete.js +29 -13
  8. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/index.js +6 -1
  10. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/collections/list.js +47 -7
  12. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  13. package/build/cli/cli/commands/manage/collections/promote.js +67 -20
  14. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  15. package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -11
  16. package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
  17. package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
  18. package/build/cli/cli/commands/manage/deploy.js +194 -0
  19. package/build/cli/cli/commands/manage/dev.d.ts +2 -0
  20. package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
  21. package/build/cli/cli/commands/manage/dev.js +77 -0
  22. package/build/cli/cli/commands/manage/eject.d.ts +2 -0
  23. package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
  24. package/build/cli/cli/commands/manage/eject.js +155 -0
  25. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  26. package/build/cli/cli/commands/manage/index.js +37 -1
  27. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  28. package/build/cli/cli/commands/manage/publish-content.js +78 -33
  29. package/build/cli/cli/commands/manage/status.d.ts +2 -0
  30. package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
  31. package/build/cli/cli/commands/manage/status.js +162 -0
  32. package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
  33. package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
  34. package/build/cli/cli/commands/manage/template/index.js +42 -0
  35. package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
  36. package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
  37. package/build/cli/cli/commands/manage/template/init.js +172 -0
  38. package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
  39. package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
  40. package/build/cli/cli/commands/manage/upgrade.js +59 -0
  41. package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
  42. package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
  43. package/build/cli/cli/commands/run-dev-watch.js +41 -0
  44. package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
  45. package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
  46. package/build/cli/cli/commands/run-template-hook.js +28 -0
  47. package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
  48. package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
  49. package/build/cli/cli/commands/scaffold/app-template.js +54 -0
  50. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
  51. package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
  52. package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
  53. package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
  54. package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
  55. package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
  56. package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
  57. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  58. package/build/cli/cli/commands/scaffold/index.js +208 -290
  59. package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
  60. package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
  61. package/build/cli/cli/commands/scaffold/render.js +72 -0
  62. package/build/cli/cli/hono/build.d.ts +43 -0
  63. package/build/cli/cli/hono/build.d.ts.map +1 -0
  64. package/build/cli/cli/hono/build.js +297 -0
  65. package/build/cli/cli/index.js +98 -5
  66. package/build/cli/cli/managed/app.d.ts +21 -0
  67. package/build/cli/cli/managed/app.d.ts.map +1 -0
  68. package/build/cli/cli/managed/app.js +162 -0
  69. package/build/cli/cli/managed/command-helpers.d.ts +6 -0
  70. package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
  71. package/build/cli/cli/managed/command-helpers.js +81 -0
  72. package/build/cli/cli/managed/eject.d.ts +6 -0
  73. package/build/cli/cli/managed/eject.d.ts.map +1 -0
  74. package/build/cli/cli/managed/eject.js +68 -0
  75. package/build/cli/cli/managed/fastly-service.d.ts +8 -0
  76. package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
  77. package/build/cli/cli/managed/fastly-service.js +21 -0
  78. package/build/cli/cli/managed/fingerprint.d.ts +13 -0
  79. package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
  80. package/build/cli/cli/managed/fingerprint.js +60 -0
  81. package/build/cli/cli/managed/lockfile.d.ts +31 -0
  82. package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
  83. package/build/cli/cli/managed/lockfile.js +62 -0
  84. package/build/cli/cli/managed/project-edit.d.ts +3 -0
  85. package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
  86. package/build/cli/cli/managed/project-edit.js +35 -0
  87. package/build/cli/cli/managed/project-file.d.ts +16 -0
  88. package/build/cli/cli/managed/project-file.d.ts.map +1 -0
  89. package/build/cli/cli/managed/project-file.js +119 -0
  90. package/build/cli/cli/managed/template-init.d.ts +12 -0
  91. package/build/cli/cli/managed/template-init.d.ts.map +1 -0
  92. package/build/cli/cli/managed/template-init.js +120 -0
  93. package/build/cli/cli/managed/version-check.d.ts +25 -0
  94. package/build/cli/cli/managed/version-check.d.ts.map +1 -0
  95. package/build/cli/cli/managed/version-check.js +84 -0
  96. package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
  97. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  98. package/build/cli/cli/storage/kv-store-local-provider.js +6 -3
  99. package/build/cli/cli/storage/kv-store-provider.d.ts +1 -0
  100. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  101. package/build/cli/cli/storage/kv-store-provider.js +9 -1
  102. package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
  103. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  104. package/build/cli/cli/storage/s3-storage-provider.js +4 -0
  105. package/build/cli/cli/storage/storage-provider.d.ts +3 -0
  106. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  107. package/build/cli/cli/storage/storage-provider.js +32 -0
  108. package/build/cli/cli/util/api-token.d.ts.map +1 -1
  109. package/build/cli/cli/util/collection-name.d.ts +3 -0
  110. package/build/cli/cli/util/collection-name.d.ts.map +1 -0
  111. package/build/cli/cli/util/collection-name.js +24 -0
  112. package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
  113. package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
  114. package/build/cli/cli/util/collection-selection-flags.js +131 -0
  115. package/build/cli/cli/util/config.d.ts +13 -0
  116. package/build/cli/cli/util/config.d.ts.map +1 -1
  117. package/build/cli/cli/util/config.js +172 -38
  118. package/build/cli/cli/util/data.d.ts.map +1 -1
  119. package/build/cli/cli/util/global-options.d.ts +13 -0
  120. package/build/cli/cli/util/global-options.d.ts.map +1 -0
  121. package/build/cli/cli/util/global-options.js +53 -0
  122. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  123. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  124. package/build/cli/cli/util/kv-store-items.js +16 -40
  125. package/build/cli/cli/util/kv-store-local-server.d.ts +1 -1
  126. package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
  127. package/build/cli/cli/util/kv-store-local-server.js +4 -2
  128. package/build/cli/cli/util/output.d.ts +31 -0
  129. package/build/cli/cli/util/output.d.ts.map +1 -0
  130. package/build/cli/cli/util/output.js +139 -0
  131. package/build/cli/cli/util/package.d.ts +3 -0
  132. package/build/cli/cli/util/package.d.ts.map +1 -1
  133. package/build/cli/cli/util/package.js +12 -0
  134. package/build/cli/cli/util/progress.d.ts.map +1 -1
  135. package/build/cli/cli/util/purge.d.ts +6 -2
  136. package/build/cli/cli/util/purge.d.ts.map +1 -1
  137. package/build/cli/cli/util/purge.js +7 -2
  138. package/build/cli/cli/util/resources.d.ts +2 -0
  139. package/build/cli/cli/util/resources.d.ts.map +1 -0
  140. package/build/cli/cli/util/resources.js +8 -0
  141. package/build/cli/cli/util/service-id.d.ts +1 -0
  142. package/build/cli/cli/util/service-id.d.ts.map +1 -1
  143. package/build/cli/cli/util/service-id.js +5 -1
  144. package/build/cli/cli/util/variants.d.ts.map +1 -1
  145. package/build/cli/models/assets/index.d.ts +6 -0
  146. package/build/cli/models/assets/index.d.ts.map +1 -1
  147. package/build/cli/models/assets/index.js +24 -0
  148. package/build/cli/models/collections/index.d.ts +3 -0
  149. package/build/cli/models/collections/index.d.ts.map +1 -0
  150. package/build/cli/models/collections/index.js +15 -0
  151. package/build/cli/models/compression/index.d.ts +1 -1
  152. package/build/cli/models/compression/index.d.ts.map +1 -1
  153. package/build/cli/models/config/collection-selection.d.ts +55 -0
  154. package/build/cli/models/config/collection-selection.d.ts.map +1 -0
  155. package/build/cli/models/config/collection-selection.js +238 -0
  156. package/build/cli/models/config/item-patterns.d.ts +4 -0
  157. package/build/cli/models/config/item-patterns.d.ts.map +1 -0
  158. package/build/cli/models/config/item-patterns.js +43 -0
  159. package/build/cli/models/config/publish-content-config.d.ts +6 -1
  160. package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
  161. package/build/cli/models/config/static-publish-project.d.ts +23 -0
  162. package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
  163. package/build/cli/models/config/static-publish-project.js +11 -0
  164. package/build/cli/models/config/static-publish-rc.d.ts +25 -0
  165. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
  166. package/build/cli/models/config/static-publish-rc.js +31 -0
  167. package/build/cli/models/config/template-settings.d.ts +10 -0
  168. package/build/cli/models/config/template-settings.d.ts.map +1 -0
  169. package/build/cli/models/config/template-settings.js +72 -0
  170. package/build/cli/models/server/index.d.ts.map +1 -1
  171. package/build/cli/models/server/index.js +6 -2
  172. package/build/server/hono/extensions.d.ts +48 -0
  173. package/build/server/hono/extensions.d.ts.map +1 -0
  174. package/build/server/hono/extensions.js +65 -0
  175. package/build/server/hono/index.d.ts +30 -0
  176. package/build/server/hono/index.d.ts.map +1 -0
  177. package/build/server/hono/index.js +72 -0
  178. package/build/server/hono/path.d.ts +7 -0
  179. package/build/server/hono/path.d.ts.map +1 -0
  180. package/build/server/hono/path.js +32 -0
  181. package/build/server/models/assets/index.d.ts +6 -0
  182. package/build/server/models/assets/index.d.ts.map +1 -1
  183. package/build/server/models/assets/index.js +24 -0
  184. package/build/server/models/collections/index.d.ts +3 -0
  185. package/build/server/models/collections/index.d.ts.map +1 -0
  186. package/build/server/models/collections/index.js +15 -0
  187. package/build/server/models/compression/index.d.ts +1 -1
  188. package/build/server/models/compression/index.d.ts.map +1 -1
  189. package/build/server/models/config/collection-selection.d.ts +55 -0
  190. package/build/server/models/config/collection-selection.d.ts.map +1 -0
  191. package/build/server/models/config/collection-selection.js +238 -0
  192. package/build/server/models/config/item-patterns.d.ts +4 -0
  193. package/build/server/models/config/item-patterns.d.ts.map +1 -0
  194. package/build/server/models/config/item-patterns.js +43 -0
  195. package/build/server/models/config/publish-content-config.d.ts +6 -1
  196. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  197. package/build/server/models/config/static-publish-project.d.ts +23 -0
  198. package/build/server/models/config/static-publish-project.d.ts.map +1 -0
  199. package/build/server/models/config/static-publish-project.js +11 -0
  200. package/build/server/models/config/static-publish-rc.d.ts +25 -0
  201. package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
  202. package/build/server/models/config/static-publish-rc.js +31 -0
  203. package/build/server/models/server/index.d.ts.map +1 -1
  204. package/build/server/models/server/index.js +6 -2
  205. package/build/server/server/collection-selection/index.d.ts +11 -0
  206. package/build/server/server/collection-selection/index.d.ts.map +1 -0
  207. package/build/server/server/collection-selection/index.js +192 -0
  208. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
  209. package/build/server/server/collection-selector/from-cookie.js +6 -8
  210. package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
  211. package/build/server/server/index.d.ts +4 -1
  212. package/build/server/server/index.d.ts.map +1 -1
  213. package/build/server/server/index.js +3 -1
  214. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  215. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  216. package/build/server/server/publisher-server/accept-html.js +50 -0
  217. package/build/server/server/publisher-server/index.d.ts +59 -7
  218. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  219. package/build/server/server/publisher-server/index.js +362 -145
  220. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  221. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  222. package/build/server/server/publisher-server/response-cache.js +24 -1
  223. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
  224. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  225. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  226. package/build/server/server/util/body-length.d.ts.map +1 -1
  227. package/build/server/server/util/server-timing.d.ts.map +1 -1
  228. package/package.json +21 -3
  229. package/resources/app/fastly.toml.njk +58 -0
  230. package/resources/app/gitignore.njk +9 -0
  231. package/resources/app/publish-content.config.from-project.js.njk +9 -0
  232. package/resources/app/publish-content.config.js.njk +35 -0
  233. package/resources/app/static-publish.project.js.njk +83 -0
  234. package/resources/app/static-publish.rc.js.njk +43 -0
  235. package/resources/template-init/hono/_example.ts +22 -0
  236. package/resources/template-init/hono/tsconfig.json +17 -0
  237. package/resources/templates/hono/package-lock.json +4123 -0
  238. package/resources/templates/hono/package.json +15 -0
  239. package/resources/templates/hono/scripts/template_postinstall.js +10 -0
  240. package/resources/templates/hono/scripts/template_prebuild.js +8 -0
  241. package/resources/templates/hono/scripts/template_watch.js +15 -0
  242. package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
  243. package/resources/templates/hono/src/index.ts +53 -0
  244. package/resources/templates/hono/tsconfig.json +17 -0
  245. package/resources/templates/plain/package-lock.json +4088 -0
  246. package/resources/templates/plain/package.json +10 -0
  247. package/resources/templates/plain/src/index.js +34 -0
package/README.md CHANGED
@@ -18,13 +18,13 @@ This CLI tool helps you:
18
18
  Create a directory for your project, place your static files in `./public`, then type:
19
19
 
20
20
  ```sh
21
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name=site-content
21
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
22
22
  ```
23
23
 
24
24
  **New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
25
25
 
26
26
  ```sh
27
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
27
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
28
28
  ```
29
29
 
30
30
  If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
package/README.short.md CHANGED
@@ -18,13 +18,13 @@ This CLI tool helps you:
18
18
  Create a directory for your project, place your static files in `./public`, then type:
19
19
 
20
20
  ```sh
21
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name=site-content
21
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --kv-store-name=site-content
22
22
  ```
23
23
 
24
24
  **New in v8:** S3-compatible storage (such as Fastly Object Storage) is also supported (Beta). To use this mode, type:
25
25
 
26
26
  ```sh
27
- npx @fastly/compute-js-static-publish@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
27
+ npx @fastly/compute-js-static-publish@beta --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
28
28
  ```
29
29
 
30
30
  If the storage needs a custom endpoint, as Fastly Object Storage does, add `--s3-endpoint=<endpoint>` (for example, `--s3-endpoint=https://us-east-1.object.fastlystorage.app`).
@@ -1 +1 @@
1
- {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AA+DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
@@ -2,11 +2,11 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import path from 'node:path';
6
5
  import { decodeIndexMetadata } from '../../../models/server/index.js';
7
6
  import { isExpired } from '../../../models/time/index.js';
8
7
  import { parseCommandLine } from '../../util/args.js';
9
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
8
+ import { errorCodeOf, recordFailure } from '../../util/output.js';
9
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../util/config.js';
10
10
  import { loadStorageProviderFromStaticPublishRc } from '../../storage/storage-provider.js';
11
11
  function help() {
12
12
  console.log(`\
@@ -18,6 +18,11 @@ Description:
18
18
  Cleans up expired or unreferenced items in storage.
19
19
  This can include expired collection indexes and orphaned content assets.
20
20
 
21
+ Do not run clean while publish-content can run for the same storage.
22
+ clean can delete files that a publish uses before the publish writes its
23
+ index. In CI, put the jobs that publish and the job that cleans in the same
24
+ concurrency group.
25
+
21
26
  Options:
22
27
  --delete-expired-collections If set, expired collection index files will be deleted.
23
28
 
@@ -58,7 +63,7 @@ export async function action(actionArgs) {
58
63
  if (parsed.error != null) {
59
64
  console.error(String(parsed.error));
60
65
  console.error();
61
- process.exitCode = 1;
66
+ recordFailure('usage', String(parsed.error));
62
67
  }
63
68
  help();
64
69
  return;
@@ -66,7 +71,7 @@ export async function action(actionArgs) {
66
71
  const { verbose, ['delete-expired-collections']: deleteExpiredCollections, ['dry-run']: dryRun, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
67
72
  // compute-js-static-publisher cli is always run from the Compute application directory
68
73
  // in other words, the directory that contains `fastly.toml`.
69
- const computeAppDir = path.resolve();
74
+ const computeAppDir = getComputeAppDir();
70
75
  console.log(`🧹 Cleaning storage entries...`);
71
76
  // #### load config
72
77
  let staticPublisherRc;
@@ -74,14 +79,14 @@ export async function action(actionArgs) {
74
79
  staticPublisherRc = await loadStaticPublisherRcFile();
75
80
  }
76
81
  catch (err) {
77
- console.error("❌ Can't load static-publish.rc.js");
82
+ console.error(`❌ Can't load ${configFileName()}`);
78
83
  console.error("Run this from a compute-js-static-publish compute-js directory.");
79
84
  if (err instanceof LoadConfigError) {
80
85
  for (const error of err.errors) {
81
86
  console.error(error);
82
87
  }
83
88
  }
84
- process.exitCode = 1;
89
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
85
90
  return;
86
91
  }
87
92
  const publishId = staticPublisherRc.publishId;
@@ -104,7 +109,7 @@ export async function action(actionArgs) {
104
109
  catch (err) {
105
110
  console.error(`❌ Could not instantiate store provider`);
106
111
  console.error(String(err));
107
- process.exitCode = 1;
112
+ recordFailure(errorCodeOf(err), String(err));
108
113
  return;
109
114
  }
110
115
  // ### Asset keys to delete
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAiEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA+JhD"}
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAuEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiLhD"}
@@ -2,9 +2,9 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import path from 'node:path';
6
5
  import { parseCommandLine } from '../../../util/args.js';
7
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
6
+ import { errorCodeOf, fail, recordFailure, setJsonResult } from '../../../util/output.js';
7
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
8
8
  import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
9
9
  import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
10
10
  function help() {
@@ -73,7 +73,7 @@ export async function action(actionArgs) {
73
73
  if (parsed.error != null) {
74
74
  console.error(String(parsed.error));
75
75
  console.error();
76
- process.exitCode = 1;
76
+ recordFailure('usage', String(parsed.error));
77
77
  }
78
78
  help();
79
79
  return;
@@ -81,10 +81,9 @@ export async function action(actionArgs) {
81
81
  const { verbose, ['collection-name']: collectionNameValue, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, local: localMode, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
82
82
  // compute-js-static-publisher cli is always run from the Compute application directory
83
83
  // in other words, the directory that contains `fastly.toml`.
84
- const computeAppDir = path.resolve();
84
+ const computeAppDir = getComputeAppDir();
85
85
  if (collectionNameValue == null) {
86
- console.error("❌ Required argument '--collection-name' not specified.");
87
- process.exitCode = 1;
86
+ fail('usage', "Required argument '--collection-name' not specified.");
88
87
  return;
89
88
  }
90
89
  console.log(`🧹 Deleting storage collection...`);
@@ -94,14 +93,14 @@ export async function action(actionArgs) {
94
93
  staticPublisherRc = await loadStaticPublisherRcFile();
95
94
  }
96
95
  catch (err) {
97
- console.error("❌ Can't load static-publish.rc.js");
96
+ console.error(`❌ Can't load ${configFileName()}`);
98
97
  console.error("Run this from a compute-js-static-publish compute-js directory.");
99
98
  if (err instanceof LoadConfigError) {
100
99
  for (const error of err.errors) {
101
100
  console.error(error);
102
101
  }
103
102
  }
104
- process.exitCode = 1;
103
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
105
104
  return;
106
105
  }
107
106
  const publishId = staticPublisherRc.publishId;
@@ -124,13 +123,12 @@ export async function action(actionArgs) {
124
123
  catch (err) {
125
124
  console.error(`❌ Could not instantiate store provider`);
126
125
  console.error(String(err));
127
- process.exitCode = 1;
126
+ recordFailure(errorCodeOf(err), String(err));
128
127
  return;
129
128
  }
130
129
  const collectionName = collectionNameValue;
131
130
  if (collectionName === defaultCollectionName) {
132
- console.error(`❌ Cannot delete default collection: ${collectionName}`);
133
- process.exitCode = 1;
131
+ fail('usage', `Cannot delete default collection: ${collectionName}`);
134
132
  return;
135
133
  }
136
134
  console.log(`✔️ Collection to delete: ${collectionName}`);
@@ -147,7 +145,7 @@ export async function action(actionArgs) {
147
145
  }
148
146
  catch (err) {
149
147
  console.error(String(err));
150
- process.exitCode = 1;
148
+ recordFailure(errorCodeOf(err), String(err));
151
149
  return;
152
150
  }
153
151
  // ### Asset Keys to delete
@@ -172,14 +170,32 @@ export async function action(actionArgs) {
172
170
  }
173
171
  }
174
172
  }
173
+ // A collection that does not exist is not an error: there is nothing to
174
+ // delete. The purge still runs, in case an earlier delete did not purge.
175
+ if (assetKeysToDelete.size === 0) {
176
+ console.log(`✔️ Collection '${collectionName}' does not exist. Nothing to delete.`);
177
+ }
175
178
  // ### Delete items that have been flagged
176
179
  const items = [...assetKeysToDelete].map(key => ({ key }));
177
180
  await storageProvider.doConcurrentParallel(items, async (_, key) => {
178
181
  console.log(`Deleting key from storage: ${key}`);
179
182
  await storageProvider.deleteStorageEntry(key);
180
183
  }, undefined, true);
184
+ const purgeResults = [];
181
185
  if (purgeTarget != null) {
182
- await purgeCollection(purgeTarget, publishId, collectionName);
186
+ purgeResults.push(...await purgeCollection(purgeTarget, publishId, collectionName));
183
187
  }
184
188
  console.log("✅ Completed.");
189
+ setJsonResult({
190
+ collection: collectionName,
191
+ publishId,
192
+ deleted: assetKeysToDelete.size > 0,
193
+ ...(assetKeysToDelete.size === 0 ? { reason: 'not-found' } : {}),
194
+ // null: no purge (--local, or no Service ID).
195
+ purge: purgeTarget != null ? {
196
+ ok: purgeResults.every(x => x.result !== 'failed'),
197
+ serviceId: purgeTarget.serviceId,
198
+ environments: purgeResults,
199
+ } : null,
200
+ });
185
201
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0BhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAqDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA8BhD"}
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import { getCommandAndArgs } from '../../../util/args.js';
6
+ import { fail, isJsonMode, recordFailure } from '../../../util/output.js';
6
7
  import * as deleteCommand from './delete.js';
7
8
  import * as listCommand from './list.js';
8
9
  import * as promoteCommand from './promote.js';
@@ -60,11 +61,15 @@ export async function action(actionArgs) {
60
61
  console.error(commandAndArgs.error);
61
62
  console.error(`Specify one of the following sub-commands: ${Object.keys(modes).join(', ')}`);
62
63
  console.error();
63
- process.exitCode = 1;
64
+ recordFailure('usage', commandAndArgs.error);
64
65
  }
65
66
  help();
66
67
  return;
67
68
  }
68
69
  const { command, argv, } = commandAndArgs;
70
+ if (isJsonMode() && !['list', 'delete', 'promote'].includes(command)) {
71
+ fail('json-not-supported', `--json is not supported for 'collections ${command}'.`);
72
+ return;
73
+ }
69
74
  await modes[command].action(argv);
70
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AA6CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4IhD"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAoLhD"}
@@ -2,11 +2,12 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import path from 'node:path';
5
+ import { countHiddenEntries } from '../../../../models/assets/index.js';
6
6
  import { decodeIndexMetadata, getUnsupportedIndexFeatures } from '../../../../models/server/index.js';
7
7
  import { isExpired } from '../../../../models/time/index.js';
8
8
  import { parseCommandLine } from '../../../util/args.js';
9
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
9
+ import { errorCodeOf, recordFailure, setJsonResult } from '../../../util/output.js';
10
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
10
11
  import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
11
12
  function help() {
12
13
  console.log(`\
@@ -50,7 +51,7 @@ export async function action(actionArgs) {
50
51
  if (parsed.error != null) {
51
52
  console.error(String(parsed.error));
52
53
  console.error();
53
- process.exitCode = 1;
54
+ recordFailure('usage', String(parsed.error));
54
55
  }
55
56
  help();
56
57
  return;
@@ -58,7 +59,7 @@ export async function action(actionArgs) {
58
59
  const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
59
60
  // compute-js-static-publisher cli is always run from the Compute application directory
60
61
  // in other words, the directory that contains `fastly.toml`.
61
- const computeAppDir = path.resolve();
62
+ const computeAppDir = getComputeAppDir();
62
63
  console.log(`📃 Listing collections...`);
63
64
  // #### load config
64
65
  let staticPublisherRc;
@@ -66,14 +67,14 @@ export async function action(actionArgs) {
66
67
  staticPublisherRc = await loadStaticPublisherRcFile();
67
68
  }
68
69
  catch (err) {
69
- console.error("❌ Can't load static-publish.rc.js");
70
+ console.error(`❌ Can't load ${configFileName()}`);
70
71
  console.error("Run this from a compute-js-static-publish compute-js directory.");
71
72
  if (err instanceof LoadConfigError) {
72
73
  for (const error of err.errors) {
73
74
  console.error(error);
74
75
  }
75
76
  }
76
- process.exitCode = 1;
77
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
77
78
  return;
78
79
  }
79
80
  const publishId = staticPublisherRc.publishId;
@@ -96,7 +97,7 @@ export async function action(actionArgs) {
96
97
  catch (err) {
97
98
  console.error(`❌ Could not instantiate store provider`);
98
99
  console.error(String(err));
99
- process.exitCode = 1;
100
+ recordFailure(errorCodeOf(err), String(err));
100
101
  return;
101
102
  }
102
103
  // ### List all indexes ###
@@ -107,6 +108,8 @@ export async function action(actionArgs) {
107
108
  }
108
109
  // ### Found collections ###
109
110
  const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
111
+ // For --json.
112
+ const collectionInfos = [];
110
113
  if (foundCollections.length === 0) {
111
114
  console.log('No collections found.');
112
115
  }
@@ -125,16 +128,48 @@ export async function action(actionArgs) {
125
128
  throw new Error(`❌ Can't load storage entry ${indexesPrefix + collection}`);
126
129
  }
127
130
  let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata);
131
+ const info = {
132
+ name: collection,
133
+ isDefault: collection === defaultCollectionName,
134
+ publishedAt: null,
135
+ expiresAt: null,
136
+ expired: false,
137
+ requires: [],
138
+ unsupported: [],
139
+ files: null,
140
+ hidden: null,
141
+ };
142
+ collectionInfos.push(info);
128
143
  if (indexMetadata == null) {
129
144
  console.log(` No metadata found.`);
130
145
  continue;
131
146
  }
147
+ if (indexMetadata.publishedTime != null) {
148
+ info.publishedAt = new Date(indexMetadata.publishedTime * 1000).toISOString();
149
+ }
150
+ if (indexMetadata.expirationTime != null) {
151
+ info.expiresAt = new Date(indexMetadata.expirationTime * 1000).toISOString();
152
+ // The expiration time is not enforced for the default collection.
153
+ info.expired = collection !== defaultCollectionName && isExpired(indexMetadata.expirationTime);
154
+ }
155
+ info.requires = indexMetadata.requires ?? [];
156
+ info.unsupported = getUnsupportedIndexFeatures(indexMetadata);
132
157
  if (indexMetadata.publishedTime == null) {
133
158
  console.log(' Published : unknown');
134
159
  }
135
160
  else {
136
161
  console.log(` Published : ${new Date(indexMetadata.publishedTime * 1000)}`);
137
162
  }
163
+ try {
164
+ const assetEntryMap = (await new Response(indexEntryInfo.data).json());
165
+ const fileCount = Object.keys(assetEntryMap).length;
166
+ info.files = fileCount;
167
+ info.hidden = countHiddenEntries(assetEntryMap);
168
+ console.log(` Files : ${fileCount} (${countHiddenEntries(assetEntryMap)} hidden)`);
169
+ }
170
+ catch {
171
+ console.log(' Files : unknown (cannot read the index)');
172
+ }
138
173
  if (indexMetadata.requires != null) {
139
174
  console.log(` Requires : ${indexMetadata.requires.join(', ')}`);
140
175
  const unsupportedFeatures = getUnsupportedIndexFeatures(indexMetadata);
@@ -159,4 +194,9 @@ export async function action(actionArgs) {
159
194
  }
160
195
  }
161
196
  console.log("✅ Completed.");
197
+ setJsonResult({
198
+ publishId,
199
+ defaultCollection: defaultCollectionName,
200
+ collections: collectionInfos,
201
+ });
162
202
  }
@@ -1 +1 @@
1
- {"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAmEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuLhD"}
1
+ {"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAyFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
@@ -6,9 +6,12 @@ import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
8
8
  import { calcExpirationTime } from '../../../../models/time/index.js';
9
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
9
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
10
10
  import { parseCommandLine } from '../../../util/args.js';
11
+ import { errorCodeOf, fail, recordFailure, setJsonResult } from '../../../util/output.js';
12
+ import { checkCollectionNameForWrite } from '../../../util/collection-name.js';
11
13
  import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
14
+ import { loadPurgeTarget, purgeCollection } from '../../../util/purge.js';
12
15
  function help() {
13
16
  console.log(`\
14
17
 
@@ -21,6 +24,9 @@ Usage:
21
24
  Description:
22
25
  Copies an existing collection (content + config) to a new collection name.
23
26
 
27
+ If a Service ID is found, the tool then purges the cached responses of the target
28
+ collection from that service.
29
+
24
30
  Required:
25
31
  --collection-name=<name> The name of the collection to promote
26
32
  --to=<name> The name of the new (target) collection to create or overwrite
@@ -45,10 +51,21 @@ KV Store Options:
45
51
  with the local development environment.
46
52
  KV Store mode only. In S3 mode, --local is an error.
47
53
 
48
- --fastly-api-token=<token> Fastly API token for KV Store access.
54
+ --fastly-api-token=<token> Fastly API token for KV Store or cache access.
49
55
  If not set, the tool uses the FASTLY_API_TOKEN
50
56
  environment variable.
51
57
 
58
+ Purge Options:
59
+ --fastly-service-id=<id> Fastly Service ID to purge after promoting (not with --local).
60
+ If not set, the tool will check:
61
+ 1. FASTLY_SERVICE_ID environment variable
62
+ 2. service_id in fastly.toml
63
+ If none is found, the purge is skipped.
64
+
65
+ --purge-environment=<env> Environment to purge: production, staging, or a
66
+ comma-separated list of both. Can be repeated.
67
+ Default: production
68
+
52
69
  S3 Storage Options (BETA):
53
70
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
54
71
  --s3-secret-access-key=<key> interface with S3 or compatible storage.
@@ -69,6 +86,8 @@ export async function action(actionArgs) {
69
86
  { name: 'expires-never', type: Boolean },
70
87
  { name: 'local', type: Boolean },
71
88
  { name: 'fastly-api-token', type: String, },
89
+ { name: 'fastly-service-id', type: String, },
90
+ { name: 'purge-environment', type: String, multiple: true, },
72
91
  { name: 's3-access-key-id', type: String, },
73
92
  { name: 's3-secret-access-key', type: String, },
74
93
  ];
@@ -77,23 +96,21 @@ export async function action(actionArgs) {
77
96
  if (parsed.error != null) {
78
97
  console.error(String(parsed.error));
79
98
  console.error();
80
- process.exitCode = 1;
99
+ recordFailure('usage', String(parsed.error));
81
100
  }
82
101
  help();
83
102
  return;
84
103
  }
85
- const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
104
+ const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
86
105
  // compute-js-static-publisher cli is always run from the Compute application directory
87
106
  // in other words, the directory that contains `fastly.toml`.
88
- const computeAppDir = path.resolve();
107
+ const computeAppDir = getComputeAppDir();
89
108
  if (collectionNameValue == null) {
90
- console.error("❌ Required argument '--collection-name' not specified.");
91
- process.exitCode = 1;
109
+ fail('usage', "Required argument '--collection-name' not specified.");
92
110
  return;
93
111
  }
94
112
  if (toCollectionNameValue == null) {
95
- console.error("❌ Required argument '--to' not specified.");
96
- process.exitCode = 1;
113
+ fail('usage', "Required argument '--to' not specified.");
97
114
  return;
98
115
  }
99
116
  let expirationTime;
@@ -103,7 +120,7 @@ export async function action(actionArgs) {
103
120
  catch (err) {
104
121
  console.error(`❌ Cannot process expiration time`);
105
122
  console.error(String(err));
106
- process.exitCode = 1;
123
+ recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
107
124
  return;
108
125
  }
109
126
  console.log(`📃 Promoting collection...`);
@@ -113,14 +130,14 @@ export async function action(actionArgs) {
113
130
  staticPublisherRc = await loadStaticPublisherRcFile();
114
131
  }
115
132
  catch (err) {
116
- console.error("❌ Can't load static-publish.rc.js");
133
+ console.error(`❌ Can't load ${configFileName()}`);
117
134
  console.error("Run this from a compute-js-static-publish compute-js directory.");
118
135
  if (err instanceof LoadConfigError) {
119
136
  for (const error of err.errors) {
120
137
  console.error(error);
121
138
  }
122
139
  }
123
- process.exitCode = 1;
140
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
124
141
  return;
125
142
  }
126
143
  const publishId = staticPublisherRc.publishId;
@@ -143,13 +160,32 @@ export async function action(actionArgs) {
143
160
  catch (err) {
144
161
  console.error(`❌ Could not instantiate store provider`);
145
162
  console.error(String(err));
146
- process.exitCode = 1;
163
+ recordFailure(errorCodeOf(err), String(err));
147
164
  return;
148
165
  }
149
166
  const sourceCollectionName = collectionNameValue;
150
167
  console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
168
+ // Purge target: checked now, so that a missing API token fails before anything is written.
169
+ let purgeTarget;
170
+ try {
171
+ purgeTarget = loadPurgeTarget({
172
+ localMode: localMode ?? false,
173
+ computeAppDir,
174
+ fastlyServiceId,
175
+ fastlyApiToken,
176
+ purgeEnvironments: purgeEnvironmentValues,
177
+ });
178
+ }
179
+ catch (err) {
180
+ console.error(String(err));
181
+ process.exitCode = 1;
182
+ return;
183
+ }
151
184
  const targetCollectionName = toCollectionNameValue;
152
185
  console.log(`✔️ Collection to promote to: ${targetCollectionName}`);
186
+ if (!await checkCollectionNameForWrite(storageProvider, publishId, targetCollectionName)) {
187
+ return;
188
+ }
153
189
  if (expirationTime === undefined) {
154
190
  console.log(`✔️ Not updating expiration timestamp.`);
155
191
  }
@@ -170,11 +206,9 @@ export async function action(actionArgs) {
170
206
  storageProvider.getStorageEntry(sourceCollectionIndexKey),
171
207
  storageProvider.getStorageEntry(sourceCollectionSettingsKey),
172
208
  ]);
173
- if (!indexEntryInfo) {
174
- throw new Error(`Error querying index for '${collectionNameValue}' in storage`);
175
- }
176
- if (!settingsEntryInfo) {
177
- throw new Error(`Error querying settings for '${collectionNameValue}' in storage`);
209
+ if (!indexEntryInfo || !settingsEntryInfo) {
210
+ fail('collection-not-found', `Collection '${collectionNameValue}' does not exist.`);
211
+ return;
178
212
  }
179
213
  let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata) ?? {};
180
214
  if (indexMetadata.publishedTime == null) {
@@ -191,11 +225,24 @@ export async function action(actionArgs) {
191
225
  console.log(`Uploading to storage: '${targetCollectionName}'`);
192
226
  const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
193
227
  fs.mkdirSync(storageContentDir, { recursive: true });
194
- const indexFileName = `index_${collectionNameValue}.json`;
228
+ // The files have the name of the target collection, as in publish-content. In
229
+ // --local mode, kvstore.json refers to them, so the target must not share a
230
+ // file with the source.
231
+ const indexFileName = `index_${targetCollectionName}.json`;
195
232
  const indexFilePath = path.resolve(storageContentDir, indexFileName);
196
233
  await storageProvider.submitStorageEntry(targetCollectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
197
- const settingsFileName = `settings_${collectionNameValue}.json`;
234
+ const settingsFileName = `settings_${targetCollectionName}.json`;
198
235
  const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
199
236
  await storageProvider.submitStorageEntry(targetCollectionSettingsKey, settingsFilePath, settingsEntryInfo.data);
237
+ if (purgeTarget != null) {
238
+ await purgeCollection(purgeTarget, publishId, targetCollectionName);
239
+ }
200
240
  console.log("✅ Completed.");
241
+ setJsonResult({
242
+ from: sourceCollectionName,
243
+ to: targetCollectionName,
244
+ publishId,
245
+ // The expiration time of the target, after the promote. null: it does not expire.
246
+ expiresAt: indexMetadata.expirationTime != null ? new Date(indexMetadata.expirationTime * 1000).toISOString() : null,
247
+ });
201
248
  }
@@ -1 +1 @@
1
- {"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AA+DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0JhD"}
1
+ {"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AAqEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAwJhD"}
@@ -6,8 +6,9 @@ import fs from 'node:fs';
6
6
  import path from 'node:path';
7
7
  import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
8
8
  import { calcExpirationTime } from '../../../../models/time/index.js';
9
- import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
9
+ import { LoadConfigError, configFileName, getComputeAppDir, loadStaticPublisherRcFile, } from '../../../util/config.js';
10
10
  import { parseCommandLine } from '../../../util/args.js';
11
+ import { errorCodeOf, fail, recordFailure } from '../../../util/output.js';
11
12
  import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
12
13
  function help() {
13
14
  console.log(`\
@@ -72,7 +73,7 @@ export async function action(actionArgs) {
72
73
  if (parsed.error != null) {
73
74
  console.error(String(parsed.error));
74
75
  console.error();
75
- process.exitCode = 1;
76
+ recordFailure('usage', String(parsed.error));
76
77
  }
77
78
  help();
78
79
  return;
@@ -80,10 +81,9 @@ export async function action(actionArgs) {
80
81
  const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
81
82
  // compute-js-static-publisher cli is always run from the Compute application directory
82
83
  // in other words, the directory that contains `fastly.toml`.
83
- const computeAppDir = path.resolve();
84
+ const computeAppDir = getComputeAppDir();
84
85
  if (collectionNameValue == null) {
85
- console.error("❌ Required argument '--collection-name' not specified.");
86
- process.exitCode = 1;
86
+ fail('usage', "Required argument '--collection-name' not specified.");
87
87
  return;
88
88
  }
89
89
  let expirationTime;
@@ -93,12 +93,11 @@ export async function action(actionArgs) {
93
93
  catch (err) {
94
94
  console.error(`❌ Cannot process expiration time`);
95
95
  console.error(String(err));
96
- process.exitCode = 1;
96
+ recordFailure('usage', `Cannot process expiration time: ${String(err)}`);
97
97
  return;
98
98
  }
99
99
  if (expirationTime === undefined) {
100
- console.error("❌ Exactly one of '--expires-in', '--expires-at', or '--expires-never' is required.");
101
- process.exitCode = 1;
100
+ fail('usage', "Exactly one of '--expires-in', '--expires-at', or '--expires-never' is required.");
102
101
  return;
103
102
  }
104
103
  console.log(`📃 Promoting collection...`);
@@ -108,14 +107,14 @@ export async function action(actionArgs) {
108
107
  staticPublisherRc = await loadStaticPublisherRcFile();
109
108
  }
110
109
  catch (err) {
111
- console.error("❌ Can't load static-publish.rc.js");
110
+ console.error(`❌ Can't load ${configFileName()}`);
112
111
  console.error("Run this from a compute-js-static-publish compute-js directory.");
113
112
  if (err instanceof LoadConfigError) {
114
113
  for (const error of err.errors) {
115
114
  console.error(error);
116
115
  }
117
116
  }
118
- process.exitCode = 1;
117
+ recordFailure('config-invalid', `Can't load ${configFileName()}.`);
119
118
  return;
120
119
  }
121
120
  const publishId = staticPublisherRc.publishId;
@@ -138,7 +137,7 @@ export async function action(actionArgs) {
138
137
  catch (err) {
139
138
  console.error(`❌ Could not instantiate store provider`);
140
139
  console.error(String(err));
141
- process.exitCode = 1;
140
+ recordFailure(errorCodeOf(err), String(err));
142
141
  return;
143
142
  }
144
143
  const collectionName = collectionNameValue;