@fastly/compute-js-static-publish 6.2.0 → 7.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 (238) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -575
  3. package/README.short.md +53 -0
  4. package/build/cli/commands/clean.d.ts +2 -0
  5. package/build/cli/commands/clean.d.ts.map +1 -0
  6. package/build/cli/commands/clean.js +121 -0
  7. package/build/cli/commands/collections/delete.d.ts +2 -0
  8. package/build/cli/commands/collections/delete.d.ts.map +1 -0
  9. package/build/cli/commands/collections/delete.js +88 -0
  10. package/build/cli/commands/collections/index.d.ts +2 -0
  11. package/build/cli/commands/collections/index.d.ts.map +1 -0
  12. package/build/cli/commands/collections/index.js +52 -0
  13. package/build/cli/commands/collections/list.d.ts +2 -0
  14. package/build/cli/commands/collections/list.d.ts.map +1 -0
  15. package/build/cli/commands/collections/list.js +62 -0
  16. package/build/cli/commands/index.d.ts +2 -0
  17. package/build/cli/commands/index.d.ts.map +1 -0
  18. package/build/cli/commands/index.js +67 -0
  19. package/build/cli/commands/init-app.d.ts +18 -2
  20. package/build/cli/commands/init-app.d.ts.map +1 -1
  21. package/build/cli/commands/init-app.js +291 -264
  22. package/build/cli/commands/publish-content.d.ts +2 -0
  23. package/build/cli/commands/publish-content.d.ts.map +1 -0
  24. package/build/cli/commands/publish-content.js +472 -0
  25. package/build/cli/compression/brotli.d.ts +1 -1
  26. package/build/cli/compression/brotli.d.ts.map +1 -1
  27. package/build/cli/compression/brotli.js +8 -11
  28. package/build/cli/compression/gzip.d.ts +1 -1
  29. package/build/cli/compression/gzip.d.ts.map +1 -1
  30. package/build/cli/compression/gzip.js +8 -11
  31. package/build/cli/compression/index.d.ts +3 -6
  32. package/build/cli/compression/index.d.ts.map +1 -1
  33. package/build/cli/compression/index.js +8 -9
  34. package/build/cli/fastly-api/api-token.d.ts +17 -0
  35. package/build/cli/fastly-api/api-token.d.ts.map +1 -0
  36. package/build/cli/fastly-api/api-token.js +94 -0
  37. package/build/cli/fastly-api/kv-store.d.ts +24 -0
  38. package/build/cli/fastly-api/kv-store.d.ts.map +1 -0
  39. package/build/cli/{util → fastly-api}/kv-store.js +42 -22
  40. package/build/cli/index.js +7 -91
  41. package/build/cli/util/args.d.ts +16 -0
  42. package/build/cli/util/args.d.ts.map +1 -0
  43. package/build/cli/util/args.js +55 -0
  44. package/build/cli/util/config.d.ts +13 -0
  45. package/build/cli/util/config.d.ts.map +1 -0
  46. package/build/cli/{load-config.js → util/config.js} +234 -187
  47. package/build/{util → cli/util}/content-types.d.ts +1 -2
  48. package/build/cli/util/content-types.d.ts.map +1 -0
  49. package/build/{util → cli/util}/content-types.js +38 -32
  50. package/build/cli/util/data.d.ts +3 -3
  51. package/build/cli/util/data.d.ts.map +1 -1
  52. package/build/cli/util/data.js +6 -2
  53. package/build/cli/util/files.d.ts +10 -2
  54. package/build/cli/util/files.d.ts.map +1 -1
  55. package/build/cli/util/files.js +53 -6
  56. package/build/cli/util/kv-store-items.d.ts +12 -0
  57. package/build/cli/util/kv-store-items.d.ts.map +1 -0
  58. package/build/cli/util/kv-store-items.js +161 -0
  59. package/build/cli/util/kv-store-local-server.d.ts +3 -0
  60. package/build/cli/util/kv-store-local-server.d.ts.map +1 -0
  61. package/build/cli/util/kv-store-local-server.js +35 -0
  62. package/build/cli/util/package.d.ts +9 -0
  63. package/build/cli/util/package.d.ts.map +1 -0
  64. package/build/cli/util/package.js +44 -0
  65. package/build/cli/util/retryable.d.ts +12 -0
  66. package/build/cli/util/retryable.d.ts.map +1 -0
  67. package/build/cli/util/retryable.js +43 -0
  68. package/build/cli/util/variants.d.ts +4 -0
  69. package/build/cli/util/variants.d.ts.map +1 -0
  70. package/build/cli/util/variants.js +27 -0
  71. package/build/index.d.ts +5 -5
  72. package/build/index.d.ts.map +1 -1
  73. package/build/index.js +7 -6
  74. package/build/models/assets/kvstore-assets.d.ts +17 -0
  75. package/build/models/assets/kvstore-assets.d.ts.map +1 -0
  76. package/build/models/assets/kvstore-assets.js +28 -0
  77. package/build/{constants/compression.d.ts → models/compression/index.d.ts} +2 -1
  78. package/build/models/compression/index.d.ts.map +1 -0
  79. package/build/models/compression/index.js +11 -0
  80. package/build/models/config/publish-content-config.d.ts +41 -0
  81. package/build/models/config/publish-content-config.d.ts.map +1 -0
  82. package/build/models/config/publish-content-config.js +5 -0
  83. package/build/models/config/publisher-server-config.d.ts +20 -0
  84. package/build/models/config/publisher-server-config.d.ts.map +1 -0
  85. package/build/models/config/publisher-server-config.js +5 -0
  86. package/build/models/config/static-publish-rc.d.ts +6 -0
  87. package/build/models/config/static-publish-rc.d.ts.map +1 -0
  88. package/build/models/config/static-publish-rc.js +5 -0
  89. package/build/server/collection-selector/from-config-store.d.ts +2 -0
  90. package/build/server/collection-selector/from-config-store.d.ts.map +1 -0
  91. package/build/server/collection-selector/from-config-store.js +15 -0
  92. package/build/server/collection-selector/from-cookie.d.ts +23 -0
  93. package/build/server/collection-selector/from-cookie.d.ts.map +1 -0
  94. package/build/server/collection-selector/from-cookie.js +98 -0
  95. package/build/server/collection-selector/from-request.d.ts +13 -0
  96. package/build/server/collection-selector/from-request.d.ts.map +1 -0
  97. package/build/server/collection-selector/from-request.js +22 -0
  98. package/build/server/collection-selector/index.d.ts +5 -0
  99. package/build/server/collection-selector/index.d.ts.map +1 -0
  100. package/build/server/collection-selector/index.js +7 -0
  101. package/build/server/collection-selector/request-collection-selector.d.ts +5 -0
  102. package/build/server/collection-selector/request-collection-selector.d.ts.map +1 -0
  103. package/build/server/collection-selector/request-collection-selector.js +5 -0
  104. package/build/server/publisher-server/index.d.ts +38 -0
  105. package/build/server/publisher-server/index.d.ts.map +1 -0
  106. package/build/server/publisher-server/index.js +415 -0
  107. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts +3 -0
  108. package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
  109. package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-modified-since.js +6 -2
  110. package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
  111. package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.js +4 -0
  112. package/build/server/util/cookies.d.ts +2 -0
  113. package/build/server/util/cookies.d.ts.map +1 -0
  114. package/build/server/util/cookies.js +14 -0
  115. package/build/server/util/kv-store.d.ts +3 -0
  116. package/build/server/util/kv-store.d.ts.map +1 -0
  117. package/build/server/util/kv-store.js +95 -0
  118. package/package.json +18 -10
  119. package/build/cli/commands/build-static.d.ts +0 -3
  120. package/build/cli/commands/build-static.d.ts.map +0 -1
  121. package/build/cli/commands/build-static.js +0 -541
  122. package/build/cli/commands/clean-kv-store.d.ts +0 -3
  123. package/build/cli/commands/clean-kv-store.d.ts.map +0 -1
  124. package/build/cli/commands/clean-kv-store.js +0 -55
  125. package/build/cli/load-config.d.ts +0 -6
  126. package/build/cli/load-config.d.ts.map +0 -1
  127. package/build/cli/presets/implementations/astro.d.ts +0 -7
  128. package/build/cli/presets/implementations/astro.d.ts.map +0 -1
  129. package/build/cli/presets/implementations/astro.js +0 -23
  130. package/build/cli/presets/implementations/create-react-app.d.ts +0 -11
  131. package/build/cli/presets/implementations/create-react-app.d.ts.map +0 -1
  132. package/build/cli/presets/implementations/create-react-app.js +0 -34
  133. package/build/cli/presets/implementations/docusaurus.d.ts +0 -7
  134. package/build/cli/presets/implementations/docusaurus.d.ts.map +0 -1
  135. package/build/cli/presets/implementations/docusaurus.js +0 -13
  136. package/build/cli/presets/implementations/gatsby.d.ts +0 -7
  137. package/build/cli/presets/implementations/gatsby.d.ts.map +0 -1
  138. package/build/cli/presets/implementations/gatsby.js +0 -13
  139. package/build/cli/presets/implementations/next.d.ts +0 -7
  140. package/build/cli/presets/implementations/next.d.ts.map +0 -1
  141. package/build/cli/presets/implementations/next.js +0 -13
  142. package/build/cli/presets/implementations/sveltekit.d.ts +0 -7
  143. package/build/cli/presets/implementations/sveltekit.d.ts.map +0 -1
  144. package/build/cli/presets/implementations/sveltekit.js +0 -13
  145. package/build/cli/presets/implementations/vite.d.ts +0 -7
  146. package/build/cli/presets/implementations/vite.d.ts.map +0 -1
  147. package/build/cli/presets/implementations/vite.js +0 -13
  148. package/build/cli/presets/implementations/vue.d.ts +0 -7
  149. package/build/cli/presets/implementations/vue.d.ts.map +0 -1
  150. package/build/cli/presets/implementations/vue.js +0 -24
  151. package/build/cli/presets/index.d.ts +0 -3
  152. package/build/cli/presets/index.d.ts.map +0 -1
  153. package/build/cli/presets/index.js +0 -20
  154. package/build/cli/presets/preset-base.d.ts +0 -21
  155. package/build/cli/presets/preset-base.d.ts.map +0 -1
  156. package/build/cli/presets/preset-base.js +0 -1
  157. package/build/cli/util/fastly-api.d.ts +0 -10
  158. package/build/cli/util/fastly-api.d.ts.map +0 -1
  159. package/build/cli/util/fastly-api.js +0 -47
  160. package/build/cli/util/hash.d.ts +0 -5
  161. package/build/cli/util/hash.d.ts.map +0 -1
  162. package/build/cli/util/hash.js +0 -9
  163. package/build/cli/util/id.d.ts +0 -3
  164. package/build/cli/util/id.d.ts.map +0 -1
  165. package/build/cli/util/id.js +0 -17
  166. package/build/cli/util/kv-store.d.ts +0 -16
  167. package/build/cli/util/kv-store.d.ts.map +0 -1
  168. package/build/cli/util/publish-id.d.ts +0 -5
  169. package/build/cli/util/publish-id.d.ts.map +0 -1
  170. package/build/cli/util/publish-id.js +0 -26
  171. package/build/compute-js.d.ts +0 -3
  172. package/build/compute-js.d.ts.map +0 -1
  173. package/build/compute-js.js +0 -2
  174. package/build/constants/compression.d.ts.map +0 -1
  175. package/build/constants/compression.js +0 -4
  176. package/build/server/assets/asset-manager.d.ts +0 -8
  177. package/build/server/assets/asset-manager.d.ts.map +0 -1
  178. package/build/server/assets/asset-manager.js +0 -14
  179. package/build/server/assets/content-asset-kv-store.d.ts +0 -19
  180. package/build/server/assets/content-asset-kv-store.d.ts.map +0 -1
  181. package/build/server/assets/content-asset-kv-store.js +0 -70
  182. package/build/server/assets/content-asset-wasm-inline.d.ts +0 -18
  183. package/build/server/assets/content-asset-wasm-inline.d.ts.map +0 -1
  184. package/build/server/assets/content-asset-wasm-inline.js +0 -52
  185. package/build/server/assets/content-assets.d.ts +0 -46
  186. package/build/server/assets/content-assets.d.ts.map +0 -1
  187. package/build/server/assets/content-assets.js +0 -100
  188. package/build/server/assets/module-assets.d.ts +0 -23
  189. package/build/server/assets/module-assets.d.ts.map +0 -1
  190. package/build/server/assets/module-assets.js +0 -45
  191. package/build/server/kv-store/inline-store-entry.d.ts +0 -25
  192. package/build/server/kv-store/inline-store-entry.d.ts.map +0 -1
  193. package/build/server/kv-store/inline-store-entry.js +0 -100
  194. package/build/server/publisher-server.d.ts +0 -23
  195. package/build/server/publisher-server.d.ts.map +0 -1
  196. package/build/server/publisher-server.js +0 -257
  197. package/build/server/serve-preconditions/if-modified-since.d.ts +0 -4
  198. package/build/server/serve-preconditions/if-modified-since.d.ts.map +0 -1
  199. package/build/server/serve-preconditions/if-none-match.d.ts.map +0 -1
  200. package/build/server/util/http.d.ts +0 -2
  201. package/build/server/util/http.d.ts.map +0 -1
  202. package/build/server/util/http.js +0 -9
  203. package/build/types/compute.d.ts +0 -11
  204. package/build/types/compute.d.ts.map +0 -1
  205. package/build/types/compute.js +0 -1
  206. package/build/types/config-normalized.d.ts +0 -34
  207. package/build/types/config-normalized.d.ts.map +0 -1
  208. package/build/types/config-normalized.js +0 -1
  209. package/build/types/config.d.ts +0 -37
  210. package/build/types/config.d.ts.map +0 -1
  211. package/build/types/config.js +0 -1
  212. package/build/types/content-assets.d.ts +0 -55
  213. package/build/types/content-assets.d.ts.map +0 -1
  214. package/build/types/content-assets.js +0 -1
  215. package/build/types/content-types.d.ts +0 -11
  216. package/build/types/content-types.d.ts.map +0 -1
  217. package/build/types/content-types.js +0 -1
  218. package/build/types/index.d.ts +0 -7
  219. package/build/types/index.d.ts.map +0 -1
  220. package/build/types/index.js +0 -1
  221. package/build/types/module-assets.d.ts +0 -15
  222. package/build/types/module-assets.d.ts.map +0 -1
  223. package/build/types/module-assets.js +0 -1
  224. package/build/types/util.d.ts +0 -7
  225. package/build/types/util.d.ts.map +0 -1
  226. package/build/types/util.js +0 -1
  227. package/build/util/content-types.d.ts.map +0 -1
  228. package/build/util/index.d.ts +0 -3
  229. package/build/util/index.d.ts.map +0 -1
  230. package/build/util/index.js +0 -2
  231. package/build/util/metadata.d.ts +0 -3
  232. package/build/util/metadata.d.ts.map +0 -1
  233. package/build/util/metadata.js +0 -12
  234. package/resources/README.md +0 -3
  235. package/resources/statics-metadata.d.ts +0 -10
  236. package/resources/statics.d.ts +0 -19
  237. package/resources/webpack.config.js +0 -33
  238. /package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.d.ts +0 -0
@@ -0,0 +1,53 @@
1
+ # @fastly/compute-js-static-publish
2
+
3
+ Fastly Compute + KV Store for static websites and web apps.
4
+
5
+ This CLI tool helps you:
6
+
7
+ - ✅ Deploy static sites to Fastly Compute with zero backend
8
+ - 📦 Store files in Fastly KV Store efficiently
9
+ - 🗂 Publish to named collections (`live`, `preview-42`, etc.)
10
+ - 🔄 Switch between collections at runtime
11
+ - 🧹 Clean up old or expired assets
12
+
13
+ ---
14
+
15
+ ## Quick Start
16
+
17
+ Create a directory for your project, place your static files in `./public`, then type:
18
+
19
+ ```sh
20
+ npx @fastly/compute-js-static-publish --root-dir=./public --kv-store-name=site-content
21
+ ```
22
+
23
+ ### 🔧 Local Preview
24
+
25
+ ```sh
26
+ cd compute-js
27
+ npm install
28
+ npm run start # preview locally
29
+ ```
30
+
31
+ Serves your app at `http://127.0.0.1:7676`, powered by a simulated KV Store.
32
+
33
+ ### 🚀 Deploy to Production
34
+
35
+ When you're ready to go live, [create a free Fastly account](https://www.fastly.com/signup/?tier=free) if you haven't already, and then:
36
+
37
+ ```sh
38
+ cd compute-js
39
+ npm run deploy # deploy the app
40
+ npm run publish-content # upload your static files
41
+ ```
42
+
43
+ ## Features
44
+
45
+ - Named collections for previews, staging, production
46
+ - SPA + fallback handling
47
+ - Precompressed Brotli/gzip support
48
+ - CLI tools for publish, promote, and cleanup
49
+
50
+ ## Documentation
51
+
52
+ 📘 Full documentation available on GitHub:
53
+ [https://github.com/fastly/compute-js-static-publish](https://github.com/fastly/compute-js-static-publish)
@@ -0,0 +1,2 @@
1
+ export declare function action(argv: string[]): Promise<void>;
2
+ //# sourceMappingURL=clean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean.ts"],"names":[],"mappings":"AAYA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAoJ1C"}
@@ -0,0 +1,121 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import commandLineArgs from 'command-line-args';
6
+ import { LoadConfigError, loadStaticPublisherRcFile } from '../util/config.js';
7
+ import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteFile } from '../fastly-api/kv-store.js';
8
+ import { loadApiToken } from '../fastly-api/api-token.js';
9
+ export async function action(argv) {
10
+ const optionDefinitions = [
11
+ { name: 'verbose', type: Boolean },
12
+ { name: 'fastly-api-token', type: String, },
13
+ ];
14
+ const commandLineValues = commandLineArgs(optionDefinitions, { argv });
15
+ const { verbose, ['fastly-api-token']: fastlyApiToken, } = commandLineValues;
16
+ const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
17
+ if (apiTokenResult == null) {
18
+ console.error("❌ Fastly API Token not provided.");
19
+ console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
20
+ process.exitCode = 1;
21
+ return;
22
+ }
23
+ const fastlyApiContext = { apiToken: apiTokenResult.apiToken };
24
+ console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
25
+ // #### load config
26
+ let staticPublisherRc;
27
+ try {
28
+ staticPublisherRc = await loadStaticPublisherRcFile();
29
+ }
30
+ catch (err) {
31
+ console.error("❌ Can't load static-publish.rc.js");
32
+ console.error("Run this from a compute-js-static-publish compute-js directory.");
33
+ if (err instanceof LoadConfigError) {
34
+ for (const error of err.errors) {
35
+ console.error(error);
36
+ }
37
+ }
38
+ process.exitCode = 1;
39
+ return;
40
+ }
41
+ const publishId = staticPublisherRc.publishId;
42
+ console.log(`✔️ Publish ID: ${publishId}`);
43
+ const kvStoreName = staticPublisherRc.kvStoreName;
44
+ console.log(`✔️ Using KV Store: ${kvStoreName}`);
45
+ const defaultCollectionName = staticPublisherRc.defaultCollectionName;
46
+ console.log(`✔️ Default Collection Name: ${defaultCollectionName}`);
47
+ // ### KVStore Keys to delete
48
+ const kvKeysToDelete = new Set();
49
+ // ### List all indexes ###
50
+ const indexesPrefix = publishId + '_index_';
51
+ const indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
52
+ if (indexKeys == null) {
53
+ throw new Error(`Can't query indexes in KV Store`);
54
+ }
55
+ // ### Found collections ###
56
+ const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
57
+ console.log('Found collections');
58
+ for (const collection of foundCollections) {
59
+ console.log(collection);
60
+ }
61
+ // TODO ### Determine which ones are not expired, based on an expiration meta
62
+ const liveCollections = foundCollections;
63
+ // ### List all settings ###
64
+ const settingsPrefix = publishId + '_index_';
65
+ const settingsKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, settingsPrefix);
66
+ if (settingsKeys == null) {
67
+ throw new Error(`Can't query settings in KV Store`);
68
+ }
69
+ // If a settings object is found that doesn't match a live collection name then
70
+ // mark it for deletion
71
+ const foundSettingsCollections = settingsKeys.map(key => ({ key, name: key.slice(settingsPrefix.length) }));
72
+ for (const foundSettings of foundSettingsCollections) {
73
+ if (!foundCollections.includes(foundSettings.name)) {
74
+ kvKeysToDelete.add(foundSettings.key);
75
+ }
76
+ }
77
+ // ### Go through the index files and make a list of all keys (hashes) that we are keeping
78
+ const assetsIdsInUse = new Set();
79
+ for (const collection of liveCollections) {
80
+ // TODO deal with when the index file is > 20MB
81
+ const kvAssetsIndexResponse = await getKvStoreEntry(fastlyApiContext, kvStoreName, indexesPrefix + collection);
82
+ if (!kvAssetsIndexResponse) {
83
+ throw new Error(`Can't load KV Store entry ${indexesPrefix + collection}`);
84
+ }
85
+ const kvAssetsIndex = (await kvAssetsIndexResponse.response.json());
86
+ for (const [_assetKey, assetEntry] of Object.entries(kvAssetsIndex)) {
87
+ if (assetEntry.key.startsWith('sha256:')) {
88
+ assetsIdsInUse.add(`sha256_${assetEntry.key.slice('sha256:'.length)}`);
89
+ }
90
+ }
91
+ }
92
+ // ### Obtain the assets in the KV Store and find the ones that are not in use
93
+ const assetPrefix = publishId + '_files_';
94
+ const assetKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, assetPrefix);
95
+ if (assetKeys == null) {
96
+ throw new Error(`Can't query assets in KV Store`);
97
+ }
98
+ for (const assetKey of assetKeys) {
99
+ let assetId = assetKey.slice(assetPrefix.length);
100
+ if (assetId.startsWith('sha256_')) {
101
+ assetId = assetId.slice(0, 'sha256_'.length + 64);
102
+ }
103
+ else {
104
+ // If we don't know what the prefix is, we ignore it
105
+ continue;
106
+ }
107
+ if (assetsIdsInUse.has(assetId)) {
108
+ console.log('Asset ID ' + assetId + ' in use');
109
+ }
110
+ else {
111
+ kvKeysToDelete.add(assetKey);
112
+ console.log('Asset ID ' + assetId + ' not in use');
113
+ }
114
+ }
115
+ // ### Delete items that have been flagged
116
+ for (const key of kvKeysToDelete) {
117
+ console.log("Deleting item: " + key);
118
+ await kvStoreDeleteFile(fastlyApiContext, kvStoreName, key);
119
+ }
120
+ console.log("✅ Completed.");
121
+ }
@@ -0,0 +1,2 @@
1
+ export declare function action(argv: string[]): Promise<void>;
2
+ //# sourceMappingURL=delete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/delete.ts"],"names":[],"mappings":"AAWA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAmG1C"}
@@ -0,0 +1,88 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import commandLineArgs from 'command-line-args';
6
+ import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
7
+ import { getKVStoreKeys, kvStoreDeleteFile } from '../../fastly-api/kv-store.js';
8
+ import { loadApiToken } from '../../fastly-api/api-token.js';
9
+ export async function action(argv) {
10
+ const optionDefinitions = [
11
+ { name: 'verbose', type: Boolean },
12
+ { name: 'fastly-api-token', type: String, },
13
+ { name: 'collection-name', type: String, multiple: true }
14
+ ];
15
+ const commandLineValues = commandLineArgs(optionDefinitions, { argv });
16
+ const { verbose, ['fastly-api-token']: fastlyApiToken, ['collection-name']: collectionNameValue, } = commandLineValues;
17
+ const collectionNamesAsArray = (Array.isArray(collectionNameValue) ? collectionNameValue : [collectionNameValue])
18
+ .filter(x => typeof x === 'string')
19
+ .map(x => x.split(','))
20
+ .flat()
21
+ .map(x => x.trim())
22
+ .filter(Boolean);
23
+ if (collectionNamesAsArray.length === 0) {
24
+ console.error("❌ Required argument '--collection-name' not specified.");
25
+ process.exitCode = 1;
26
+ return;
27
+ }
28
+ const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
29
+ if (apiTokenResult == null) {
30
+ console.error("❌ Fastly API Token not provided.");
31
+ console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
32
+ process.exitCode = 1;
33
+ return;
34
+ }
35
+ const fastlyApiContext = { apiToken: apiTokenResult.apiToken };
36
+ console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
37
+ // #### load config
38
+ let staticPublisherRc;
39
+ try {
40
+ staticPublisherRc = await loadStaticPublisherRcFile();
41
+ }
42
+ catch (err) {
43
+ console.error("❌ Can't load static-publish.rc.js");
44
+ console.error("Run this from a compute-js-static-publish compute-js directory.");
45
+ if (err instanceof LoadConfigError) {
46
+ for (const error of err.errors) {
47
+ console.error(error);
48
+ }
49
+ }
50
+ process.exitCode = 1;
51
+ return;
52
+ }
53
+ const publishId = staticPublisherRc.publishId;
54
+ console.log(`✔️ Publish ID: ${publishId}`);
55
+ const kvStoreName = staticPublisherRc.kvStoreName;
56
+ console.log(`✔️ Using KV Store: ${kvStoreName}`);
57
+ const defaultCollectionName = staticPublisherRc.defaultCollectionName;
58
+ console.log(`✔️ Default Collection Name: ${defaultCollectionName}`);
59
+ console.log(`✔️ Collections to delete: ${collectionNamesAsArray.map(x => `'${x}'`).join(', ')}`);
60
+ const collectionNames = new Set(collectionNamesAsArray);
61
+ const kvKeysToDelete = new Set();
62
+ // ### List all indexes ###
63
+ const indexesPrefix = publishId + '_index_';
64
+ const indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
65
+ if (indexKeys == null) {
66
+ throw new Error(`Can't query indexes in KV Store`);
67
+ }
68
+ // ### Found collections ###
69
+ const foundCollections = indexKeys.map(key => ({ key, name: key.slice(indexesPrefix.length), }));
70
+ if (foundCollections.length === 0) {
71
+ console.log('No collections found.');
72
+ }
73
+ else {
74
+ console.log(`Found collections: ${foundCollections.map(x => `'${x.name}'`).join(', ')}`);
75
+ for (const collection of foundCollections) {
76
+ if (collectionNames.has(collection.name)) {
77
+ console.log(`Flagging collection '${collection.name}' for deletion: ${collection.key}`);
78
+ kvKeysToDelete.add(collection.key);
79
+ }
80
+ }
81
+ }
82
+ // ### Delete items that have been flagged
83
+ for (const key of kvKeysToDelete) {
84
+ console.log("Deleting key from KV Store: " + key);
85
+ await kvStoreDeleteFile(fastlyApiContext, kvStoreName, key);
86
+ }
87
+ console.log("✅ Completed.");
88
+ }
@@ -0,0 +1,2 @@
1
+ export declare function action(actionArgs: string[]): Promise<void>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/index.ts"],"names":[],"mappings":"AASA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA2BhD"}
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { getCommandAndArgs } from '../../util/args.js';
6
+ import * as collectionsDelete from './delete.js';
7
+ import * as collectionsList from './list.js';
8
+ export async function action(actionArgs) {
9
+ const modes = {
10
+ 'delete': collectionsDelete,
11
+ 'list': collectionsList,
12
+ };
13
+ const commandAndArgs = getCommandAndArgs(actionArgs, Object.keys(modes));
14
+ if (commandAndArgs.needHelp) {
15
+ if (commandAndArgs.command != null) {
16
+ console.error(`Unknown subcommand: ${commandAndArgs.command}`);
17
+ console.error(`Specify one of: ${Object.keys(modes).join(', ')}`);
18
+ console.error();
19
+ process.exitCode = 1;
20
+ }
21
+ help();
22
+ return;
23
+ }
24
+ const { command, argv, } = commandAndArgs;
25
+ await modes[command].action(argv);
26
+ }
27
+ function help() {
28
+ console.log(`\
29
+
30
+ Usage:
31
+ npx @fastly/compute-js-static-publish collections <sub-command> [options]
32
+
33
+ Description:
34
+ Manage named collections within a Compute application built with @fastly/compute-js-static-publish.
35
+
36
+ Available Subcommands:
37
+ list List all published collections
38
+ delete Delete a specific collection index
39
+ update-expiration Modify expiration time for an existing collection
40
+
41
+ Global Options:
42
+ --fastly-api-token <token> Fastly API token used for KV Store access. If not provided,
43
+ the tool will try:
44
+ 1. FASTLY_API_TOKEN environment variable
45
+ 2. fastly profile token (via CLI)
46
+ -h, --help Show help for this command or any subcommand
47
+
48
+ Examples:
49
+ npx @fastly/compute-js-static-publish collections list
50
+ npx @fastly/compute-js-static-publish collections delete --collection-name=preview-42
51
+ `);
52
+ }
@@ -0,0 +1,2 @@
1
+ export declare function action(argv: string[]): Promise<void>;
2
+ //# sourceMappingURL=list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/list.ts"],"names":[],"mappings":"AAWA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAoE1C"}
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import commandLineArgs from 'command-line-args';
6
+ import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
7
+ import { getKVStoreKeys } from '../../fastly-api/kv-store.js';
8
+ import { loadApiToken } from '../../fastly-api/api-token.js';
9
+ export async function action(argv) {
10
+ const optionDefinitions = [
11
+ { name: 'verbose', type: Boolean },
12
+ { name: 'fastly-api-token', type: String, },
13
+ ];
14
+ const commandLineValues = commandLineArgs(optionDefinitions, { argv });
15
+ const { verbose, ['fastly-api-token']: fastlyApiToken, } = commandLineValues;
16
+ const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
17
+ if (apiTokenResult == null) {
18
+ console.error("❌ Fastly API Token not provided.");
19
+ console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
20
+ process.exitCode = 1;
21
+ return;
22
+ }
23
+ const fastlyApiContext = { apiToken: apiTokenResult.apiToken };
24
+ console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
25
+ // #### load config
26
+ let staticPublisherRc;
27
+ try {
28
+ staticPublisherRc = await loadStaticPublisherRcFile();
29
+ }
30
+ catch (err) {
31
+ console.error("❌ Can't load static-publish.rc.js");
32
+ console.error("Run this from a compute-js-static-publish compute-js directory.");
33
+ if (err instanceof LoadConfigError) {
34
+ for (const error of err.errors) {
35
+ console.error(error);
36
+ }
37
+ }
38
+ process.exitCode = 1;
39
+ return;
40
+ }
41
+ const publishId = staticPublisherRc.publishId;
42
+ console.log(`✔️ Publish ID: ${publishId}`);
43
+ const kvStoreName = staticPublisherRc.kvStoreName;
44
+ console.log(`✔️ Using KV Store: ${kvStoreName}`);
45
+ const defaultCollectionName = staticPublisherRc.defaultCollectionName;
46
+ console.log(`✔️ Default Collection Name: ${defaultCollectionName}`);
47
+ // ### List all indexes ###
48
+ const indexesPrefix = publishId + '_index_';
49
+ const indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
50
+ if (indexKeys == null) {
51
+ throw new Error(`Can't query indexes in KV Store`);
52
+ }
53
+ // ### Found collections ###
54
+ const foundCollections = indexKeys.map(key => ({ key, name: key.slice(indexesPrefix.length), }));
55
+ if (foundCollections.length === 0) {
56
+ console.log('No collections found.');
57
+ }
58
+ else {
59
+ console.log(`Found collections: ${foundCollections.map(x => `'${x.name}'`).join(', ')}`);
60
+ }
61
+ console.log("✅ Completed.");
62
+ }
@@ -0,0 +1,2 @@
1
+ export declare function action(actionArgs: string[]): Promise<void>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":"AAYA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAkChD"}
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import fs from 'node:fs';
6
+ import { getCommandAndArgs } from '../util/args.js';
7
+ import * as initApp from './init-app.js';
8
+ import * as publishContent from './publish-content.js';
9
+ import * as collections from './collections/index.js';
10
+ export async function action(actionArgs) {
11
+ if (!fs.existsSync('./static-publish.rc.js')) {
12
+ await initApp.action(actionArgs);
13
+ return;
14
+ }
15
+ const modes = {
16
+ 'publish-content': publishContent,
17
+ 'collections': collections,
18
+ };
19
+ const commandAndArgs = getCommandAndArgs(actionArgs, Object.keys(modes));
20
+ if (commandAndArgs.needHelp) {
21
+ if (commandAndArgs.command != null) {
22
+ console.error(`Unknown command: ${commandAndArgs.command}`);
23
+ console.error(`Specify one of: ${Object.keys(modes).join(', ')}`);
24
+ console.error();
25
+ process.exitCode = 1;
26
+ }
27
+ help();
28
+ return;
29
+ }
30
+ const { command, argv, } = commandAndArgs;
31
+ await modes[command].action(argv);
32
+ }
33
+ function help() {
34
+ console.log(`\
35
+
36
+ Usage:
37
+ npx @fastly/compute-js-static-publish <command> [options]
38
+
39
+ Description:
40
+ Manage and publish static content to Fastly Compute using KV Store-backed collections.
41
+ If run outside a scaffolded project, this tool will automatically enter project initialization mode.
42
+
43
+ Available Commands:
44
+ publish-content Publish static files to the KV Store under a named collection
45
+ clean Remove expired collections and unused KV Store content
46
+ collections list List all published collections
47
+ collections delete Delete a specific collection index
48
+ collections promote Copy a collection to another name
49
+ collections update-expiration Modify expiration time for an existing collection
50
+
51
+ Global Options:
52
+ --fastly-api-token <token> Fastly API token used for KV Store access. If not provided,
53
+ the tool will try:
54
+ 1. FASTLY_API_TOKEN environment variable
55
+ 2. fastly profile token (via CLI)
56
+ -h, --help Show help for this command or any subcommand
57
+
58
+ Automatic Project Initialization:
59
+ If run in a directory that does not contain a \`static-publish.rc.js\` file, this tool will scaffold a new
60
+ Compute application for you, including Fastly configuration, default routes, and publishing setup.
61
+
62
+ Examples:
63
+ npx @fastly/compute-js-static-publish publish-content --collection-name live
64
+ npx @fastly/compute-js-static-publish collections list
65
+ npx @fastly/compute-js-static-publish clean --dry-run
66
+ `);
67
+ }
@@ -1,3 +1,19 @@
1
- import { CommandLineOptions } from "command-line-args";
2
- export declare function initApp(commandLineValues: CommandLineOptions): void;
1
+ export type InitAppOptions = {
2
+ outputDir: string | undefined;
3
+ rootDir: string | undefined;
4
+ publicDir: string | undefined;
5
+ staticDirs: string[];
6
+ staticPublisherWorkingDir: string | undefined;
7
+ spa: string | undefined;
8
+ notFoundPage: string | undefined;
9
+ autoIndex: string[];
10
+ autoExt: string[];
11
+ name: string | undefined;
12
+ author: string | undefined;
13
+ description: string | undefined;
14
+ serviceId: string | undefined;
15
+ publishId: string | undefined;
16
+ kvStoreName: string | undefined;
17
+ };
18
+ export declare function action(argv: string[]): Promise<void>;
3
19
  //# sourceMappingURL=init-app.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAiQvD,wBAAgB,OAAO,CAAC,iBAAiB,EAAE,kBAAkB,QAud5D"}
1
+ {"version":3,"file":"init-app.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init-app.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC,CAAC;AA0QF,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAud1C"}