@fastly/compute-js-static-publish 7.0.1 → 8.0.0-beta.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.
Files changed (256) hide show
  1. package/README.md +13 -4
  2. package/README.short.md +13 -4
  3. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -0
  4. package/build/cli/{commands → cli/commands}/manage/clean.js +62 -108
  5. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -0
  6. package/build/cli/{commands → cli/commands}/manage/collections/delete.js +50 -72
  7. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -0
  8. package/build/cli/{commands → cli/commands}/manage/collections/index.js +15 -1
  9. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -0
  10. package/build/cli/{commands → cli/commands}/manage/collections/list.js +45 -73
  11. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -0
  12. package/build/cli/{commands → cli/commands}/manage/collections/promote.js +56 -93
  13. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
  14. package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.js +48 -77
  15. package/build/cli/cli/commands/manage/index.d.ts.map +1 -0
  16. package/build/cli/{commands → cli/commands}/manage/index.js +15 -1
  17. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -0
  18. package/build/cli/{commands → cli/commands}/manage/publish-content.js +90 -187
  19. package/build/cli/{commands → cli/commands}/scaffold/index.d.ts +4 -0
  20. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -0
  21. package/build/cli/{commands → cli/commands}/scaffold/index.js +262 -38
  22. package/build/cli/cli/compression/brotli.d.ts.map +1 -0
  23. package/build/cli/cli/compression/gzip.d.ts.map +1 -0
  24. package/build/cli/cli/compression/index.d.ts.map +1 -0
  25. package/build/cli/{index.d.ts.map → cli/index.d.ts.map} +1 -1
  26. package/build/cli/{index.js → cli/index.js} +8 -0
  27. package/build/cli/cli/storage/kv-store-local-provider.d.ts +20 -0
  28. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -0
  29. package/build/cli/cli/storage/kv-store-local-provider.js +86 -0
  30. package/build/cli/cli/storage/kv-store-provider.d.ts +24 -0
  31. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -0
  32. package/build/cli/cli/storage/kv-store-provider.js +182 -0
  33. package/build/cli/cli/storage/s3-storage-provider.d.ts +30 -0
  34. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -0
  35. package/build/cli/cli/storage/s3-storage-provider.js +201 -0
  36. package/build/cli/cli/storage/storage-provider.d.ts +44 -0
  37. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -0
  38. package/build/cli/cli/storage/storage-provider.js +26 -0
  39. package/build/cli/cli/util/api-token.d.ts.map +1 -0
  40. package/build/cli/cli/util/args.d.ts.map +1 -0
  41. package/build/cli/cli/util/aws-credentials.d.ts +12 -0
  42. package/build/cli/cli/util/aws-credentials.d.ts.map +1 -0
  43. package/build/cli/cli/util/aws-credentials.js +67 -0
  44. package/build/cli/{util → cli/util}/config.d.ts +1 -1
  45. package/build/cli/cli/util/config.d.ts.map +1 -0
  46. package/build/cli/{util → cli/util}/config.js +36 -20
  47. package/build/cli/cli/util/content-types.d.ts.map +1 -0
  48. package/build/cli/cli/util/data.d.ts.map +1 -0
  49. package/build/cli/cli/util/fastly-toml.d.ts.map +1 -0
  50. package/build/cli/cli/util/files.d.ts.map +1 -0
  51. package/build/cli/{util → cli/util}/files.js +15 -0
  52. package/build/cli/cli/util/kv-store-items.d.ts +5 -0
  53. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -0
  54. package/build/cli/{util → cli/util}/kv-store-items.js +3 -42
  55. package/build/cli/{util → cli/util}/kv-store-local-server.d.ts +4 -7
  56. package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -0
  57. package/build/cli/{util → cli/util}/kv-store.d.ts +7 -10
  58. package/build/cli/cli/util/kv-store.d.ts.map +1 -0
  59. package/build/cli/cli/util/node.d.ts.map +1 -0
  60. package/build/cli/cli/util/package.d.ts.map +1 -0
  61. package/build/cli/{util → cli/util}/package.js +1 -1
  62. package/build/cli/{util → cli/util}/retryable.d.ts +3 -0
  63. package/build/cli/cli/util/retryable.d.ts.map +1 -0
  64. package/build/cli/cli/util/retryable.js +76 -0
  65. package/build/cli/cli/util/s3.d.ts +7 -0
  66. package/build/cli/cli/util/s3.d.ts.map +1 -0
  67. package/build/cli/cli/util/s3.js +43 -0
  68. package/build/cli/cli/util/variants.d.ts.map +1 -0
  69. package/build/{models/assets/kvstore-assets.d.ts → cli/models/assets/index.d.ts} +5 -5
  70. package/build/cli/models/assets/index.d.ts.map +1 -0
  71. package/build/cli/models/assets/index.js +33 -0
  72. package/build/cli/models/compression/index.d.ts.map +1 -0
  73. package/build/cli/models/config/kv-store-config.d.ts +6 -0
  74. package/build/cli/models/config/kv-store-config.d.ts.map +1 -0
  75. package/build/cli/models/config/kv-store-config.js +15 -0
  76. package/build/{models → cli/models}/config/publish-content-config.d.ts +4 -3
  77. package/build/cli/models/config/publish-content-config.d.ts.map +1 -0
  78. package/build/cli/models/config/publisher-server-config.d.ts.map +1 -0
  79. package/build/cli/models/config/s3-storage-config.d.ts +8 -0
  80. package/build/cli/models/config/s3-storage-config.d.ts.map +1 -0
  81. package/build/cli/models/config/s3-storage-config.js +11 -0
  82. package/build/cli/models/config/static-publish-rc.d.ts +31 -0
  83. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -0
  84. package/build/cli/models/config/static-publish-rc.js +39 -0
  85. package/build/cli/models/metadata/index.d.ts +2 -0
  86. package/build/cli/models/metadata/index.d.ts.map +1 -0
  87. package/build/cli/models/metadata/index.js +8 -0
  88. package/build/cli/models/server/index.d.ts +7 -0
  89. package/build/cli/models/server/index.d.ts.map +1 -0
  90. package/build/cli/models/server/index.js +26 -0
  91. package/build/cli/models/time/index.d.ts.map +1 -0
  92. package/build/{models → cli/models}/time/index.js +5 -5
  93. package/build/server/models/assets/index.d.ts +17 -0
  94. package/build/server/models/assets/index.d.ts.map +1 -0
  95. package/build/server/models/assets/index.js +33 -0
  96. package/build/server/models/compression/index.d.ts +4 -0
  97. package/build/server/models/compression/index.d.ts.map +1 -0
  98. package/build/server/models/compression/index.js +11 -0
  99. package/build/server/models/config/kv-store-config.d.ts +6 -0
  100. package/build/server/models/config/kv-store-config.d.ts.map +1 -0
  101. package/build/server/models/config/kv-store-config.js +15 -0
  102. package/build/server/models/config/publish-content-config.d.ts +40 -0
  103. package/build/server/models/config/publish-content-config.d.ts.map +1 -0
  104. package/build/server/models/config/publisher-server-config.d.ts +20 -0
  105. package/build/server/models/config/publisher-server-config.d.ts.map +1 -0
  106. package/build/server/models/config/s3-storage-config.d.ts +8 -0
  107. package/build/server/models/config/s3-storage-config.d.ts.map +1 -0
  108. package/build/server/models/config/s3-storage-config.js +11 -0
  109. package/build/server/models/config/static-publish-rc.d.ts +31 -0
  110. package/build/server/models/config/static-publish-rc.d.ts.map +1 -0
  111. package/build/server/models/config/static-publish-rc.js +39 -0
  112. package/build/server/models/metadata/index.d.ts +2 -0
  113. package/build/server/models/metadata/index.d.ts.map +1 -0
  114. package/build/server/models/metadata/index.js +8 -0
  115. package/build/server/models/server/index.d.ts +7 -0
  116. package/build/server/models/server/index.d.ts.map +1 -0
  117. package/build/server/models/server/index.js +26 -0
  118. package/build/server/models/time/index.d.ts +8 -0
  119. package/build/server/models/time/index.d.ts.map +1 -0
  120. package/build/server/models/time/index.js +54 -0
  121. package/build/server/server/collection-selector/from-config-store.d.ts.map +1 -0
  122. package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -0
  123. package/build/server/server/collection-selector/from-request.d.ts.map +1 -0
  124. package/build/server/server/collection-selector/index.d.ts.map +1 -0
  125. package/build/server/server/collection-selector/request-collection-selector.d.ts.map +1 -0
  126. package/build/server/server/collection-selector/request-collection-selector.js +5 -0
  127. package/build/server/server/index.d.ts +8 -0
  128. package/build/server/server/index.d.ts.map +1 -0
  129. package/build/server/server/index.js +15 -0
  130. package/build/server/{publisher-server → server/publisher-server}/index.d.ts +14 -14
  131. package/build/server/server/publisher-server/index.d.ts.map +1 -0
  132. package/build/server/{publisher-server → server/publisher-server}/index.js +60 -61
  133. package/build/server/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
  134. package/build/server/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
  135. package/build/server/server/storage/kv-store-provider.d.ts +8 -0
  136. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -0
  137. package/build/server/server/storage/kv-store-provider.js +24 -0
  138. package/build/server/server/storage/s3-storage-provider.d.ts +26 -0
  139. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -0
  140. package/build/server/server/storage/s3-storage-provider.js +110 -0
  141. package/build/server/server/storage/storage-provider.d.ts +48 -0
  142. package/build/server/server/storage/storage-provider.d.ts.map +1 -0
  143. package/build/server/{util/kv-store.js → server/storage/storage-provider.js} +17 -39
  144. package/build/server/server/util/cookies.d.ts.map +1 -0
  145. package/build/server/server/util/kv-store.d.ts.map +1 -0
  146. package/build/server/server/util/kv-store.js +40 -0
  147. package/package.json +9 -5
  148. package/build/cli/commands/manage/clean.d.ts.map +0 -1
  149. package/build/cli/commands/manage/collections/delete.d.ts.map +0 -1
  150. package/build/cli/commands/manage/collections/index.d.ts.map +0 -1
  151. package/build/cli/commands/manage/collections/list.d.ts.map +0 -1
  152. package/build/cli/commands/manage/collections/promote.d.ts.map +0 -1
  153. package/build/cli/commands/manage/collections/update-expiration.d.ts.map +0 -1
  154. package/build/cli/commands/manage/index.d.ts.map +0 -1
  155. package/build/cli/commands/manage/publish-content.d.ts.map +0 -1
  156. package/build/cli/commands/scaffold/index.d.ts.map +0 -1
  157. package/build/cli/compression/brotli.d.ts.map +0 -1
  158. package/build/cli/compression/gzip.d.ts.map +0 -1
  159. package/build/cli/compression/index.d.ts.map +0 -1
  160. package/build/cli/util/api-token.d.ts.map +0 -1
  161. package/build/cli/util/args.d.ts.map +0 -1
  162. package/build/cli/util/config.d.ts.map +0 -1
  163. package/build/cli/util/content-types.d.ts.map +0 -1
  164. package/build/cli/util/data.d.ts.map +0 -1
  165. package/build/cli/util/fastly-toml.d.ts.map +0 -1
  166. package/build/cli/util/files.d.ts.map +0 -1
  167. package/build/cli/util/kv-store-items.d.ts +0 -13
  168. package/build/cli/util/kv-store-items.d.ts.map +0 -1
  169. package/build/cli/util/kv-store-local-server.d.ts.map +0 -1
  170. package/build/cli/util/kv-store.d.ts.map +0 -1
  171. package/build/cli/util/node.d.ts.map +0 -1
  172. package/build/cli/util/package.d.ts.map +0 -1
  173. package/build/cli/util/retryable.d.ts.map +0 -1
  174. package/build/cli/util/retryable.js +0 -43
  175. package/build/cli/util/variants.d.ts.map +0 -1
  176. package/build/index.d.ts +0 -6
  177. package/build/index.d.ts.map +0 -1
  178. package/build/index.js +0 -7
  179. package/build/models/assets/kvstore-assets.d.ts.map +0 -1
  180. package/build/models/assets/kvstore-assets.js +0 -28
  181. package/build/models/compression/index.d.ts.map +0 -1
  182. package/build/models/config/publish-content-config.d.ts.map +0 -1
  183. package/build/models/config/publisher-server-config.d.ts.map +0 -1
  184. package/build/models/config/static-publish-rc.d.ts +0 -7
  185. package/build/models/config/static-publish-rc.d.ts.map +0 -1
  186. package/build/models/server/index.d.ts +0 -5
  187. package/build/models/server/index.d.ts.map +0 -1
  188. package/build/models/server/index.js +0 -1
  189. package/build/models/time/index.d.ts.map +0 -1
  190. package/build/server/collection-selector/from-config-store.d.ts.map +0 -1
  191. package/build/server/collection-selector/from-cookie.d.ts.map +0 -1
  192. package/build/server/collection-selector/from-request.d.ts.map +0 -1
  193. package/build/server/collection-selector/index.d.ts.map +0 -1
  194. package/build/server/collection-selector/request-collection-selector.d.ts.map +0 -1
  195. package/build/server/publisher-server/index.d.ts.map +0 -1
  196. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +0 -1
  197. package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +0 -1
  198. package/build/server/util/cookies.d.ts.map +0 -1
  199. package/build/server/util/kv-store.d.ts.map +0 -1
  200. /package/build/cli/{commands → cli/commands}/manage/clean.d.ts +0 -0
  201. /package/build/cli/{commands → cli/commands}/manage/collections/delete.d.ts +0 -0
  202. /package/build/cli/{commands → cli/commands}/manage/collections/index.d.ts +0 -0
  203. /package/build/cli/{commands → cli/commands}/manage/collections/list.d.ts +0 -0
  204. /package/build/cli/{commands → cli/commands}/manage/collections/promote.d.ts +0 -0
  205. /package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.d.ts +0 -0
  206. /package/build/cli/{commands → cli/commands}/manage/index.d.ts +0 -0
  207. /package/build/cli/{commands → cli/commands}/manage/publish-content.d.ts +0 -0
  208. /package/build/cli/{compression → cli/compression}/brotli.d.ts +0 -0
  209. /package/build/cli/{compression → cli/compression}/brotli.js +0 -0
  210. /package/build/cli/{compression → cli/compression}/gzip.d.ts +0 -0
  211. /package/build/cli/{compression → cli/compression}/gzip.js +0 -0
  212. /package/build/cli/{compression → cli/compression}/index.d.ts +0 -0
  213. /package/build/cli/{compression → cli/compression}/index.js +0 -0
  214. /package/build/cli/{index.d.ts → cli/index.d.ts} +0 -0
  215. /package/build/cli/{util → cli/util}/api-token.d.ts +0 -0
  216. /package/build/cli/{util → cli/util}/api-token.js +0 -0
  217. /package/build/cli/{util → cli/util}/args.d.ts +0 -0
  218. /package/build/cli/{util → cli/util}/args.js +0 -0
  219. /package/build/cli/{util → cli/util}/content-types.d.ts +0 -0
  220. /package/build/cli/{util → cli/util}/content-types.js +0 -0
  221. /package/build/cli/{util → cli/util}/data.d.ts +0 -0
  222. /package/build/cli/{util → cli/util}/data.js +0 -0
  223. /package/build/cli/{util → cli/util}/fastly-toml.d.ts +0 -0
  224. /package/build/cli/{util → cli/util}/fastly-toml.js +0 -0
  225. /package/build/cli/{util → cli/util}/files.d.ts +0 -0
  226. /package/build/cli/{util → cli/util}/kv-store-local-server.js +0 -0
  227. /package/build/cli/{util → cli/util}/kv-store.js +0 -0
  228. /package/build/cli/{util → cli/util}/node.d.ts +0 -0
  229. /package/build/cli/{util → cli/util}/node.js +0 -0
  230. /package/build/cli/{util → cli/util}/package.d.ts +0 -0
  231. /package/build/cli/{util → cli/util}/variants.d.ts +0 -0
  232. /package/build/cli/{util → cli/util}/variants.js +0 -0
  233. /package/build/{models → cli/models}/compression/index.d.ts +0 -0
  234. /package/build/{models → cli/models}/compression/index.js +0 -0
  235. /package/build/{models → cli/models}/config/publish-content-config.js +0 -0
  236. /package/build/{models → cli/models}/config/publisher-server-config.d.ts +0 -0
  237. /package/build/{models → cli/models}/config/publisher-server-config.js +0 -0
  238. /package/build/{models → cli/models}/time/index.d.ts +0 -0
  239. /package/build/{models/config/static-publish-rc.js → server/models/config/publish-content-config.js} +0 -0
  240. /package/build/server/{collection-selector/request-collection-selector.js → models/config/publisher-server-config.js} +0 -0
  241. /package/build/server/{collection-selector → server/collection-selector}/from-config-store.d.ts +0 -0
  242. /package/build/server/{collection-selector → server/collection-selector}/from-config-store.js +0 -0
  243. /package/build/server/{collection-selector → server/collection-selector}/from-cookie.d.ts +0 -0
  244. /package/build/server/{collection-selector → server/collection-selector}/from-cookie.js +0 -0
  245. /package/build/server/{collection-selector → server/collection-selector}/from-request.d.ts +0 -0
  246. /package/build/server/{collection-selector → server/collection-selector}/from-request.js +0 -0
  247. /package/build/server/{collection-selector → server/collection-selector}/index.d.ts +0 -0
  248. /package/build/server/{collection-selector → server/collection-selector}/index.js +0 -0
  249. /package/build/server/{collection-selector → server/collection-selector}/request-collection-selector.d.ts +0 -0
  250. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.d.ts +0 -0
  251. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.js +0 -0
  252. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.d.ts +0 -0
  253. /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.js +0 -0
  254. /package/build/server/{util → server/util}/cookies.d.ts +0 -0
  255. /package/build/server/{util → server/util}/cookies.js +0 -0
  256. /package/build/server/{util → server/util}/kv-store.d.ts +0 -0
@@ -3,14 +3,11 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import path from 'node:path';
6
+ import { decodeIndexMetadata } from '../../../../models/server/index.js';
6
7
  import { isExpired } from '../../../../models/time/index.js';
7
- import { loadApiToken } from '../../../util/api-token.js';
8
8
  import { parseCommandLine } from '../../../util/args.js';
9
9
  import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
10
- import { readServiceId } from '../../../util/fastly-toml.js';
11
- import { getKvStoreEntry, getKVStoreKeys } from '../../../util/kv-store.js';
12
- import { isNodeError } from '../../../util/node.js';
13
- import { getLocalKvStoreEntry, getLocalKVStoreKeys } from "../../../util/kv-store-local-server.js";
10
+ import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
14
11
  function help() {
15
12
  console.log(`\
16
13
 
@@ -20,7 +17,7 @@ Usage:
20
17
  Description:
21
18
  Lists all collections currently published in the KV Store.
22
19
 
23
- Global Options:
20
+ KV Store Options:
24
21
  --local Instead of working with the Fastly KV Store, operate on
25
22
  local files that will be used to simulate the KV Store
26
23
  with the local development environment.
@@ -30,6 +27,20 @@ Global Options:
30
27
  1. FASTLY_API_TOKEN environment variable
31
28
  2. Logged-in Fastly CLI profile
32
29
 
30
+ S3 Storage Options:
31
+ --aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
32
+ --aws-secret-access-key=<key> interface with S3.
33
+ If not set, the tool will check:
34
+ 1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
35
+ environment variables
36
+ 2. The aws credentials file, see below
37
+
38
+ --aws-profile=<profile> Profile within the aws credentials file.
39
+ If not set, the tool will check:
40
+ 1. AWS_PROFILE environment variable
41
+ 2. The default profile, if set
42
+
43
+ Global Options:
33
44
  -h, --help Show this help message and exit.
34
45
  `);
35
46
  }
@@ -38,6 +49,9 @@ export async function action(actionArgs) {
38
49
  { name: 'verbose', type: Boolean },
39
50
  { name: 'local', type: Boolean },
40
51
  { name: 'fastly-api-token', type: String, },
52
+ { name: 'aws-profile', type: String, },
53
+ { name: 'aws-access-key-id', type: String, },
54
+ { name: 'aws-secret-access-key', type: String, },
41
55
  ];
42
56
  const parsed = parseCommandLine(actionArgs, optionDefinitions);
43
57
  if (parsed.needHelp) {
@@ -49,49 +63,11 @@ export async function action(actionArgs) {
49
63
  help();
50
64
  return;
51
65
  }
52
- const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
66
+ const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, ['aws-profile']: awsProfile, ['aws-access-key-id']: awsAccessKeyId, ['aws-secret-access-key']: awsSecretAccessKey, } = parsed.commandLineOptions;
53
67
  // compute-js-static-publisher cli is always run from the Compute application directory
54
68
  // in other words, the directory that contains `fastly.toml`.
55
69
  const computeAppDir = path.resolve();
56
- // Check to see if we have a service ID listed in `fastly.toml`.
57
- // If we do NOT, then we do not use the KV Store.
58
- let serviceId;
59
- try {
60
- serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
61
- }
62
- catch (err) {
63
- if (isNodeError(err) && err.code === 'ENOENT') {
64
- console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
65
- process.exitCode = 1;
66
- return;
67
- }
68
- console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
69
- process.exitCode = 1;
70
- return;
71
- }
72
70
  console.log(`📃 Listing collections...`);
73
- // Verify targets
74
- let fastlyApiContext = undefined;
75
- if (localMode) {
76
- console.log(` Working on local simulated KV Store...`);
77
- }
78
- else {
79
- if (serviceId === null) {
80
- console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
81
- process.exitCode = 1;
82
- return;
83
- }
84
- const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
85
- if (apiTokenResult == null) {
86
- console.error("❌ Fastly API Token not provided.");
87
- console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
88
- process.exitCode = 1;
89
- return;
90
- }
91
- fastlyApiContext = { apiToken: apiTokenResult.apiToken };
92
- console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
93
- console.log(` Working on the Fastly KV Store...`);
94
- }
95
71
  // #### load config
96
72
  let staticPublisherRc;
97
73
  try {
@@ -110,24 +86,33 @@ export async function action(actionArgs) {
110
86
  }
111
87
  const publishId = staticPublisherRc.publishId;
112
88
  console.log(` | Publish ID: ${publishId}`);
113
- const kvStoreName = staticPublisherRc.kvStoreName;
114
- console.log(` | Using KV Store: ${kvStoreName}`);
115
89
  const defaultCollectionName = staticPublisherRc.defaultCollectionName;
116
90
  console.log(` | Default Collection Name: ${defaultCollectionName}`);
117
91
  const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
118
92
  console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
119
- const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
120
- // ### List all indexes ###
121
- const indexesPrefix = publishId + '_index_';
122
- let indexKeys;
123
- if (localMode) {
124
- indexKeys = await getLocalKVStoreKeys(storeFile, indexesPrefix);
93
+ // Storage Provider
94
+ let storageProvider;
95
+ try {
96
+ storageProvider = await loadStorageProviderFromStaticPublishRc(staticPublisherRc, {
97
+ computeAppDir,
98
+ localMode,
99
+ fastlyApiToken,
100
+ awsProfile,
101
+ awsAccessKeyId,
102
+ awsSecretAccessKey,
103
+ });
125
104
  }
126
- else {
127
- indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
105
+ catch (err) {
106
+ console.error(`❌ Could not instantiate store provider`);
107
+ console.error(String(err));
108
+ process.exitCode = 1;
109
+ return;
128
110
  }
111
+ // ### List all indexes ###
112
+ const indexesPrefix = publishId + '_index_';
113
+ const indexKeys = await storageProvider.getStorageKeys(indexesPrefix);
129
114
  if (indexKeys == null) {
130
- throw new Error(`❌ Can't query indexes in KV Store`);
115
+ throw new Error(`❌ Can't query indexes in storage`);
131
116
  }
132
117
  // ### Found collections ###
133
118
  const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
@@ -144,24 +129,11 @@ export async function action(actionArgs) {
144
129
  console.log(` ${collection}`);
145
130
  }
146
131
  const indexKey = indexesPrefix + collection;
147
- let kvAssetsIndexResponse;
148
- if (localMode) {
149
- kvAssetsIndexResponse = await getLocalKvStoreEntry(storeFile, indexKey);
150
- }
151
- else {
152
- kvAssetsIndexResponse = await getKvStoreEntry(fastlyApiContext, kvStoreName, indexKey);
153
- }
154
- if (kvAssetsIndexResponse == null) {
155
- throw new Error(`❌ Can't load KV Store entry ${indexesPrefix + collection}`);
156
- }
157
- let indexMetadata;
158
- if (kvAssetsIndexResponse.metadata != null) {
159
- try {
160
- indexMetadata = JSON.parse(kvAssetsIndexResponse.metadata);
161
- }
162
- catch {
163
- }
132
+ const indexEntryInfo = await storageProvider.getStorageEntry(indexKey);
133
+ if (indexEntryInfo == null) {
134
+ throw new Error(`❌ Can't load storage entry ${indexesPrefix + collection}`);
164
135
  }
136
+ let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata);
165
137
  if (indexMetadata == null) {
166
138
  console.log(` No metadata found.`);
167
139
  continue;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AA0EA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0LhD"}
@@ -3,15 +3,12 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
6
8
  import { calcExpirationTime } from '../../../../models/time/index.js';
7
9
  import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
8
- import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../util/kv-store.js';
9
- import { loadApiToken } from '../../../util/api-token.js';
10
10
  import { parseCommandLine } from '../../../util/args.js';
11
- import path from "node:path";
12
- import { readServiceId } from "../../../util/fastly-toml.js";
13
- import { isNodeError } from "../../../util/node.js";
14
- import { getLocalKvStoreEntry, localKvStoreSubmitEntry } from "../../../util/kv-store-local-server.js";
11
+ import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
15
12
  function help() {
16
13
  console.log(`\
17
14
 
@@ -42,7 +39,7 @@ Expiration:
42
39
  existing expiration rule of the collection being
43
40
  promoted is used.
44
41
 
45
- Global Options:
42
+ KV Store Options:
46
43
  --local Instead of working with the Fastly KV Store, operate on
47
44
  local files that will be used to simulate the KV Store
48
45
  with the local development environment.
@@ -52,6 +49,20 @@ Global Options:
52
49
  1. FASTLY_API_TOKEN environment variable
53
50
  2. Logged-in Fastly CLI profile
54
51
 
52
+ S3 Storage Options:
53
+ --aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
54
+ --aws-secret-access-key=<key> interface with S3.
55
+ If not set, the tool will check:
56
+ 1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
57
+ environment variables
58
+ 2. The aws credentials file, see below
59
+
60
+ --aws-profile=<profile> Profile within the aws credentials file.
61
+ If not set, the tool will check:
62
+ 1. AWS_PROFILE environment variable
63
+ 2. The default profile, if set
64
+
65
+ Global Options:
55
66
  -h, --help Show this help message and exit.
56
67
  `);
57
68
  }
@@ -65,6 +76,9 @@ export async function action(actionArgs) {
65
76
  { name: 'expires-never', type: Boolean },
66
77
  { name: 'local', type: Boolean },
67
78
  { name: 'fastly-api-token', type: String, },
79
+ { name: 'aws-profile', type: String, },
80
+ { name: 'aws-access-key-id', type: String, },
81
+ { name: 'aws-secret-access-key', type: String, },
68
82
  ];
69
83
  const parsed = parseCommandLine(actionArgs, optionDefinitions);
70
84
  if (parsed.needHelp) {
@@ -76,7 +90,7 @@ export async function action(actionArgs) {
76
90
  help();
77
91
  return;
78
92
  }
79
- const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
93
+ const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['aws-profile']: awsProfile, ['aws-access-key-id']: awsAccessKeyId, ['aws-secret-access-key']: awsSecretAccessKey, } = parsed.commandLineOptions;
80
94
  // compute-js-static-publisher cli is always run from the Compute application directory
81
95
  // in other words, the directory that contains `fastly.toml`.
82
96
  const computeAppDir = path.resolve();
@@ -100,45 +114,7 @@ export async function action(actionArgs) {
100
114
  process.exitCode = 1;
101
115
  return;
102
116
  }
103
- // Check to see if we have a service ID listed in `fastly.toml`.
104
- // If we do NOT, then we do not use the KV Store.
105
- let serviceId;
106
- try {
107
- serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
108
- }
109
- catch (err) {
110
- if (isNodeError(err) && err.code === 'ENOENT') {
111
- console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
112
- process.exitCode = 1;
113
- return;
114
- }
115
- console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
116
- process.exitCode = 1;
117
- return;
118
- }
119
117
  console.log(`📃 Promoting collection...`);
120
- // Verify targets
121
- let fastlyApiContext = undefined;
122
- if (localMode) {
123
- console.log(` Working on local simulated KV Store...`);
124
- }
125
- else {
126
- if (serviceId === null) {
127
- console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
128
- process.exitCode = 1;
129
- return;
130
- }
131
- const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
132
- if (apiTokenResult == null) {
133
- console.error("❌ Fastly API Token not provided.");
134
- console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
135
- process.exitCode = 1;
136
- return;
137
- }
138
- fastlyApiContext = { apiToken: apiTokenResult.apiToken };
139
- console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
140
- console.log(` Working on the Fastly KV Store...`);
141
- }
142
118
  // #### load config
143
119
  let staticPublisherRc;
144
120
  try {
@@ -157,13 +133,28 @@ export async function action(actionArgs) {
157
133
  }
158
134
  const publishId = staticPublisherRc.publishId;
159
135
  console.log(` | Publish ID: ${publishId}`);
160
- const kvStoreName = staticPublisherRc.kvStoreName;
161
- console.log(` | Using KV Store: ${kvStoreName}`);
162
136
  const defaultCollectionName = staticPublisherRc.defaultCollectionName;
163
137
  console.log(` | Default Collection Name: ${defaultCollectionName}`);
164
138
  const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
165
139
  console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
166
- const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
140
+ // Storage Provider
141
+ let storageProvider;
142
+ try {
143
+ storageProvider = await loadStorageProviderFromStaticPublishRc(staticPublisherRc, {
144
+ computeAppDir,
145
+ localMode,
146
+ fastlyApiToken,
147
+ awsProfile,
148
+ awsAccessKeyId,
149
+ awsSecretAccessKey,
150
+ });
151
+ }
152
+ catch (err) {
153
+ console.error(`❌ Could not instantiate store provider`);
154
+ console.error(String(err));
155
+ process.exitCode = 1;
156
+ return;
157
+ }
167
158
  const sourceCollectionName = collectionNameValue;
168
159
  console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
169
160
  const targetCollectionName = toCollectionNameValue;
@@ -184,33 +175,17 @@ export async function action(actionArgs) {
184
175
  const targetCollectionIndexKey = `${publishId}_index_${targetCollectionName}`;
185
176
  const sourceCollectionSettingsKey = `${publishId}_settings_${collectionNameValue}`;
186
177
  const targetCollectionSettingsKey = `${publishId}_settings_${targetCollectionName}`;
187
- let indexEntryInfo, settingsEntryInfo;
188
- if (localMode) {
189
- [indexEntryInfo, settingsEntryInfo] = await Promise.all([
190
- getLocalKvStoreEntry(storeFile, sourceCollectionIndexKey),
191
- getLocalKvStoreEntry(storeFile, sourceCollectionSettingsKey),
192
- ]);
193
- }
194
- else {
195
- [indexEntryInfo, settingsEntryInfo] = await Promise.all([
196
- getKvStoreEntry(fastlyApiContext, kvStoreName, sourceCollectionIndexKey),
197
- getKvStoreEntry(fastlyApiContext, kvStoreName, sourceCollectionSettingsKey),
198
- ]);
199
- }
178
+ const [indexEntryInfo, settingsEntryInfo] = await Promise.all([
179
+ storageProvider.getStorageEntry(sourceCollectionIndexKey),
180
+ storageProvider.getStorageEntry(sourceCollectionSettingsKey),
181
+ ]);
200
182
  if (!indexEntryInfo) {
201
- throw new Error(`Error querying index for '${collectionNameValue}' in KV Store`);
183
+ throw new Error(`Error querying index for '${collectionNameValue}' in storage`);
202
184
  }
203
185
  if (!settingsEntryInfo) {
204
- throw new Error(`Error querying settings for '${collectionNameValue}' in KV Store`);
205
- }
206
- let indexMetadata = {};
207
- if (indexEntryInfo.metadata != null) {
208
- try {
209
- indexMetadata = JSON.parse(indexEntryInfo.metadata);
210
- }
211
- catch {
212
- }
186
+ throw new Error(`Error querying settings for '${collectionNameValue}' in storage`);
213
187
  }
188
+ let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata) ?? {};
214
189
  if (indexMetadata.publishedTime == null) {
215
190
  indexMetadata.publishedTime = Math.floor(Date.now() / 1000);
216
191
  }
@@ -222,26 +197,14 @@ export async function action(actionArgs) {
222
197
  indexMetadata.expirationTime = expirationTime;
223
198
  }
224
199
  }
225
- console.log(`Uploading to KV Store: '${targetCollectionName}'`);
226
- if (localMode) {
227
- const staticPublisherKvStoreContent = `${staticPublisherWorkingDir}/kv-store-content`;
228
- fs.mkdirSync(staticPublisherKvStoreContent, { recursive: true });
229
- const indexFileName = `index_${collectionNameValue}.json`;
230
- const indexFilePath = path.resolve(staticPublisherKvStoreContent, indexFileName);
231
- const indexBody = await indexEntryInfo.response.arrayBuffer();
232
- fs.writeFileSync(indexFilePath, Buffer.from(indexBody));
233
- await localKvStoreSubmitEntry(storeFile, targetCollectionIndexKey, path.relative(computeAppDir, indexFilePath), JSON.stringify(indexMetadata));
234
- const settingsFileName = `settings_${collectionNameValue}.json`;
235
- const settingsFilePath = path.resolve(staticPublisherKvStoreContent, settingsFileName);
236
- const settingsBody = await settingsEntryInfo.response.arrayBuffer();
237
- fs.writeFileSync(settingsFilePath, Buffer.from(settingsBody));
238
- await localKvStoreSubmitEntry(storeFile, targetCollectionSettingsKey, path.relative(computeAppDir, settingsFilePath), undefined);
239
- }
240
- else {
241
- await Promise.all([
242
- kvStoreSubmitEntry(fastlyApiContext, kvStoreName, targetCollectionIndexKey, indexEntryInfo.response.body, JSON.stringify(indexMetadata)),
243
- kvStoreSubmitEntry(fastlyApiContext, kvStoreName, targetCollectionSettingsKey, settingsEntryInfo.response.body, undefined),
244
- ]);
245
- }
200
+ console.log(`Uploading to storage: '${targetCollectionName}'`);
201
+ const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
202
+ fs.mkdirSync(storageContentDir, { recursive: true });
203
+ const indexFileName = `index_${collectionNameValue}.json`;
204
+ const indexFilePath = path.resolve(storageContentDir, indexFileName);
205
+ await storageProvider.submitStorageEntry(targetCollectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
206
+ const settingsFileName = `settings_${collectionNameValue}.json`;
207
+ const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
208
+ await storageProvider.submitStorageEntry(targetCollectionSettingsKey, settingsFilePath, settingsEntryInfo.data);
246
209
  console.log("✅ Completed.");
247
210
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AAsEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA6JhD"}
@@ -4,14 +4,11 @@
4
4
  */
5
5
  import fs from 'node:fs';
6
6
  import path from 'node:path';
7
+ import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
7
8
  import { calcExpirationTime } from '../../../../models/time/index.js';
8
- import { loadApiToken } from '../../../util/api-token.js';
9
9
  import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
10
10
  import { parseCommandLine } from '../../../util/args.js';
11
- import { readServiceId } from '../../../util/fastly-toml.js';
12
- import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../util/kv-store.js';
13
- import { getLocalKvStoreEntry, localKvStoreSubmitEntry, } from '../../../util/kv-store-local-server.js';
14
- import { isNodeError } from '../../../util/node.js';
11
+ import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
15
12
  function help() {
16
13
  console.log(`\
17
14
 
@@ -38,7 +35,7 @@ Expiration:
38
35
  ⚠ These three options are mutually exclusive.
39
36
  Specify exactly one.
40
37
 
41
- Global Options:
38
+ KV Store Options:
42
39
  --local Instead of working with the Fastly KV Store, operate on
43
40
  local files that will be used to simulate the KV Store
44
41
  with the local development environment.
@@ -48,6 +45,20 @@ Global Options:
48
45
  1. FASTLY_API_TOKEN environment variable
49
46
  2. Logged-in Fastly CLI profile
50
47
 
48
+ S3 Storage Options:
49
+ --aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
50
+ --aws-secret-access-key=<key> interface with S3.
51
+ If not set, the tool will check:
52
+ 1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
53
+ environment variables
54
+ 2. The aws credentials file, see below
55
+
56
+ --aws-profile=<profile> Profile within the aws credentials file.
57
+ If not set, the tool will check:
58
+ 1. AWS_PROFILE environment variable
59
+ 2. The default profile, if set
60
+
61
+ Global Options:
51
62
  -h, --help Show this help message and exit.
52
63
  `);
53
64
  }
@@ -60,6 +71,9 @@ export async function action(actionArgs) {
60
71
  { name: 'expires-never', type: Boolean },
61
72
  { name: 'local', type: Boolean },
62
73
  { name: 'fastly-api-token', type: String, },
74
+ { name: 'aws-profile', type: String, },
75
+ { name: 'aws-access-key-id', type: String, },
76
+ { name: 'aws-secret-access-key', type: String, },
63
77
  ];
64
78
  const parsed = parseCommandLine(actionArgs, optionDefinitions);
65
79
  if (parsed.needHelp) {
@@ -71,7 +85,7 @@ export async function action(actionArgs) {
71
85
  help();
72
86
  return;
73
87
  }
74
- const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
88
+ const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['aws-profile']: awsProfile, ['aws-access-key-id']: awsAccessKeyId, ['aws-secret-access-key']: awsSecretAccessKey, } = parsed.commandLineOptions;
75
89
  // compute-js-static-publisher cli is always run from the Compute application directory
76
90
  // in other words, the directory that contains `fastly.toml`.
77
91
  const computeAppDir = path.resolve();
@@ -95,45 +109,7 @@ export async function action(actionArgs) {
95
109
  process.exitCode = 1;
96
110
  return;
97
111
  }
98
- // Check to see if we have a service ID listed in `fastly.toml`.
99
- // If we do NOT, then we do not use the KV Store.
100
- let serviceId;
101
- try {
102
- serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
103
- }
104
- catch (err) {
105
- if (isNodeError(err) && err.code === 'ENOENT') {
106
- console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
107
- process.exitCode = 1;
108
- return;
109
- }
110
- console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
111
- process.exitCode = 1;
112
- return;
113
- }
114
112
  console.log(`📃 Promoting collection...`);
115
- // Verify targets
116
- let fastlyApiContext = undefined;
117
- if (localMode) {
118
- console.log(` Working on local simulated KV Store...`);
119
- }
120
- else {
121
- if (serviceId === null) {
122
- console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
123
- process.exitCode = 1;
124
- return;
125
- }
126
- const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
127
- if (apiTokenResult == null) {
128
- console.error("❌ Fastly API Token not provided.");
129
- console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
130
- process.exitCode = 1;
131
- return;
132
- }
133
- fastlyApiContext = { apiToken: apiTokenResult.apiToken };
134
- console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
135
- console.log(` Working on the Fastly KV Store...`);
136
- }
137
113
  // #### load config
138
114
  let staticPublisherRc;
139
115
  try {
@@ -152,13 +128,28 @@ export async function action(actionArgs) {
152
128
  }
153
129
  const publishId = staticPublisherRc.publishId;
154
130
  console.log(` | Publish ID: ${publishId}`);
155
- const kvStoreName = staticPublisherRc.kvStoreName;
156
- console.log(` | Using KV Store: ${kvStoreName}`);
157
131
  const defaultCollectionName = staticPublisherRc.defaultCollectionName;
158
132
  console.log(` | Default Collection Name: ${defaultCollectionName}`);
159
133
  const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
160
134
  console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
161
- const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
135
+ // Storage Provider
136
+ let storageProvider;
137
+ try {
138
+ storageProvider = await loadStorageProviderFromStaticPublishRc(staticPublisherRc, {
139
+ computeAppDir,
140
+ localMode,
141
+ fastlyApiToken,
142
+ awsProfile,
143
+ awsAccessKeyId,
144
+ awsSecretAccessKey,
145
+ });
146
+ }
147
+ catch (err) {
148
+ console.error(`❌ Could not instantiate store provider`);
149
+ console.error(String(err));
150
+ process.exitCode = 1;
151
+ return;
152
+ }
162
153
  const collectionName = collectionNameValue;
163
154
  console.log(`✔️ Collection to update: ${collectionName}`);
164
155
  if (expirationTime !== null) {
@@ -171,24 +162,11 @@ export async function action(actionArgs) {
171
162
  console.log(` ⚠️ NOTE: Expiration time not enforced for default collection.`);
172
163
  }
173
164
  const collectionIndexKey = `${publishId}_index_${collectionName}`;
174
- let indexEntryInfo;
175
- if (localMode) {
176
- indexEntryInfo = await getLocalKvStoreEntry(storeFile, collectionIndexKey);
177
- }
178
- else {
179
- indexEntryInfo = await getKvStoreEntry(fastlyApiContext, kvStoreName, collectionIndexKey);
180
- }
165
+ const indexEntryInfo = await storageProvider.getStorageEntry(collectionIndexKey);
181
166
  if (!indexEntryInfo) {
182
- throw new Error(`Error querying index for '${collectionNameValue}' in KV Store`);
183
- }
184
- let indexMetadata = {};
185
- if (indexEntryInfo.metadata != null) {
186
- try {
187
- indexMetadata = JSON.parse(indexEntryInfo.metadata);
188
- }
189
- catch {
190
- }
167
+ throw new Error(`Error querying index for '${collectionNameValue}' in storage`);
191
168
  }
169
+ let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata) ?? {};
192
170
  if (indexMetadata.publishedTime == null) {
193
171
  indexMetadata.publishedTime = Math.floor(Date.now() / 1000);
194
172
  }
@@ -198,18 +176,11 @@ export async function action(actionArgs) {
198
176
  else {
199
177
  indexMetadata.expirationTime = expirationTime;
200
178
  }
201
- console.log(`Uploading to KV Store: '${collectionName}'`);
202
- if (localMode) {
203
- const staticPublisherKvStoreContent = `${staticPublisherWorkingDir}/kv-store-content`;
204
- fs.mkdirSync(staticPublisherKvStoreContent, { recursive: true });
205
- const indexFileName = `index_${collectionNameValue}.json`;
206
- const indexFilePath = path.resolve(staticPublisherKvStoreContent, indexFileName);
207
- const indexBody = await indexEntryInfo.response.arrayBuffer();
208
- fs.writeFileSync(indexFilePath, Buffer.from(indexBody));
209
- await localKvStoreSubmitEntry(storeFile, collectionIndexKey, path.relative(computeAppDir, indexFilePath), JSON.stringify(indexMetadata));
210
- }
211
- else {
212
- await kvStoreSubmitEntry(fastlyApiContext, kvStoreName, collectionIndexKey, indexEntryInfo.response.body, JSON.stringify(indexMetadata));
213
- }
179
+ console.log(`Uploading to storage: '${collectionName}'`);
180
+ const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
181
+ fs.mkdirSync(storageContentDir, { recursive: true });
182
+ const indexFileName = `index_${collectionNameValue}.json`;
183
+ const indexFilePath = path.resolve(storageContentDir, indexFileName);
184
+ await storageProvider.submitStorageEntry(collectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
214
185
  console.log("✅ Completed.");
215
186
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AAkEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
@@ -25,7 +25,7 @@ Available Commands:
25
25
  collections promote Copy a collection to another name
26
26
  collections update-expiration Modify expiration time for an existing collection
27
27
 
28
- Global Options:
28
+ KV Store Options:
29
29
  --local Instead of working with the Fastly KV Store, operate on
30
30
  local files that will be used to simulate the KV Store
31
31
  with the local development environment.
@@ -35,6 +35,20 @@ Global Options:
35
35
  1. FASTLY_API_TOKEN environment variable
36
36
  2. Logged-in Fastly CLI profile
37
37
 
38
+ S3 Storage Options:
39
+ --aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
40
+ --aws-secret-access-key=<key> interface with S3.
41
+ If not set, the tool will check:
42
+ 1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
43
+ environment variables
44
+ 2. The aws credentials file, see below
45
+
46
+ --aws-profile=<profile> Profile within the aws credentials file.
47
+ If not set, the tool will check:
48
+ 1. AWS_PROFILE environment variable
49
+ 2. The default profile, if set
50
+
51
+ Global Options:
38
52
  -h, --help Show this help message and exit.
39
53
 
40
54
  Automatic Project Initialization:
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA2GA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqdhD"}