@fastly/compute-js-static-publish 8.0.1 → 8.0.3-rc.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 (63) hide show
  1. package/CHANGELOG.md +557 -0
  2. package/DOCUMENTATION.md +59 -38
  3. package/MIGRATING.md +128 -0
  4. package/README.md +3 -3
  5. package/README.short.md +3 -3
  6. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/clean.js +27 -0
  8. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/promote.js +43 -4
  10. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/publish-content.js +43 -14
  12. package/build/cli/cli/commands/scaffold/index.js +12 -13
  13. package/build/cli/cli/storage/kv-store-local-provider.d.ts +3 -2
  14. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  15. package/build/cli/cli/storage/kv-store-local-provider.js +6 -15
  16. package/build/cli/cli/storage/kv-store-provider.d.ts +3 -2
  17. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  18. package/build/cli/cli/storage/kv-store-provider.js +11 -2
  19. package/build/cli/cli/storage/s3-storage-provider.d.ts +3 -2
  20. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  21. package/build/cli/cli/storage/s3-storage-provider.js +6 -1
  22. package/build/cli/cli/storage/storage-provider.d.ts +6 -1
  23. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  24. package/build/cli/cli/storage/storage-provider.js +48 -0
  25. package/build/cli/cli/util/kv-store-items.d.ts +1 -0
  26. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  27. package/build/cli/cli/util/kv-store-items.js +16 -40
  28. package/build/cli/cli/util/kv-store.d.ts +1 -1
  29. package/build/cli/cli/util/kv-store.d.ts.map +1 -1
  30. package/build/cli/cli/util/s3.d.ts +10 -4
  31. package/build/cli/cli/util/s3.d.ts.map +1 -1
  32. package/build/cli/cli/util/s3.js +13 -35
  33. package/build/cli/models/index-parts/index.d.ts +20 -0
  34. package/build/cli/models/index-parts/index.d.ts.map +1 -0
  35. package/build/cli/models/index-parts/index.js +76 -0
  36. package/build/cli/models/server/index.d.ts +2 -0
  37. package/build/cli/models/server/index.d.ts.map +1 -1
  38. package/build/cli/models/server/index.js +7 -1
  39. package/build/server/models/index-parts/index.d.ts +20 -0
  40. package/build/server/models/index-parts/index.d.ts.map +1 -0
  41. package/build/server/models/index-parts/index.js +76 -0
  42. package/build/server/models/server/index.d.ts +2 -0
  43. package/build/server/models/server/index.d.ts.map +1 -1
  44. package/build/server/models/server/index.js +7 -1
  45. package/build/server/server/index.d.ts +1 -1
  46. package/build/server/server/index.d.ts.map +1 -1
  47. package/build/server/server/publisher-server/accept-html.d.ts +2 -0
  48. package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
  49. package/build/server/server/publisher-server/accept-html.js +50 -0
  50. package/build/server/server/publisher-server/index.d.ts +5 -0
  51. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  52. package/build/server/server/publisher-server/index.js +103 -33
  53. package/build/server/server/publisher-server/response-cache.d.ts +3 -0
  54. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  55. package/build/server/server/publisher-server/response-cache.js +24 -1
  56. package/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
  57. package/build/server/server/storage/kv-store-provider.js +1 -0
  58. package/build/server/server/storage/s3-storage-provider.d.ts +2 -2
  59. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  60. package/build/server/server/storage/s3-storage-provider.js +5 -2
  61. package/build/server/server/storage/storage-provider.d.ts +12 -1
  62. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  63. package/package.json +4 -2
package/DOCUMENTATION.md CHANGED
@@ -56,7 +56,7 @@ Serve static websites and web apps at the edge — no backends and no CDN in
56
56
  Create a directory for your project, place your static files in `./public`, then type:
57
57
 
58
58
  ```sh
59
- npx @fastly/compute-js-static-publish@latest \
59
+ npx @fastly/compute-js-static-publish@rc \
60
60
  --root-dir=./public \
61
61
  --kv-store-name=site-content
62
62
  ```
@@ -117,7 +117,7 @@ FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
117
117
  Create a directory for your project, place your static files in `./public`, then type:
118
118
 
119
119
  ```sh
120
- npx @fastly/compute-js-static-publish@latest \
120
+ npx @fastly/compute-js-static-publish@rc \
121
121
  --root-dir=./public \
122
122
  --storage-mode=s3 \
123
123
  --s3-region=<s3 region> \
@@ -128,13 +128,15 @@ npx @fastly/compute-js-static-publish@latest \
128
128
  > If the storage requires a custom endpoint, such as is the case with Fastly Object Storage, specify it using `--s3-endpoint=<endpoint>`. For example:
129
129
  >
130
130
  > ```sh
131
- > npx @fastly/compute-js-static-publish@latest \
131
+ > npx @fastly/compute-js-static-publish@rc \
132
132
  > --root-dir=./public \
133
133
  > --storage-mode=s3 \
134
- > --s3-region=us-east \
134
+ > --s3-region=us-east-1 \
135
135
  > --s3-bucket=my-static-content-bucket \
136
- > --s3-endpoint=https://us-east.object.fastlystorage.app
136
+ > --s3-endpoint=https://us-east-1.object.fastlystorage.app
137
137
  > ```
138
+ >
139
+ > For the regions of Fastly Object Storage and their endpoints, see [Working with Object Storage](https://www.fastly.com/documentation/guides/platform/object-storage/working-with-object-storage/#managing-object-storage-buckets-and-objects).
138
140
 
139
141
  You get a Compute app in `./compute-js` with:
140
142
 
@@ -343,7 +345,10 @@ You can override this file for a single `publish-content` command by specifying
343
345
  `'../site/public'`, set it to `'/public'`. The value starts with `/` and does not
344
346
  end with `/` (default: `''`). The scaffolder sets it from `--root-dir` and `--public-dir`.
345
347
  - `spaFile` - Path to a file to be used to serve in a SPA application.
346
- - `notFoundPageFile` - Path to a file to be used to serve as a 404 not found page.
348
+ - `notFoundPageFile` - Path to a file to be used to serve as a 404 not found page.
349
+ The server serves `spaFile` or `notFoundPageFile` only to a request that accepts HTML: its `Accept`
350
+ header is missing or empty, or has `text/html`, `text/*`, or `*/*` with a q-value that is not 0.
351
+ For other requests, `serveRequest()` returns `null`.
347
352
  - `autoIndex` - List of files to automatically use as index.
348
353
  - `autoExt` - List of extensions to automatically apply to a path and retry when
349
354
  the requested path is not found.
@@ -360,10 +365,12 @@ Collections are a powerful feature that allow you to publish and manage multiple
360
365
  - Server configuration (e.g., fallback file, static directories, etc.)
361
366
  - An index file that maps paths to those hashes
362
367
 
368
+ For an index with 2,000 entries or more, `publish-content` also stores the index in parts, about 400 entries in each part. Then `PublisherServer` reads only the part that has the path of a request, not the whole index. The full index is still stored, so an older version of `PublisherServer` serves the same content.
369
+
363
370
  Collections are published using a `--collection-name`, and can be reused, updated, or deleted independently. For example, you can create a staging version of your site using:
364
371
 
365
372
  ```sh
366
- npx @fastly/compute-js-static-publish publish-content \
373
+ npx @fastly/compute-js-static-publish@rc publish-content \
367
374
  --collection-name=staging \
368
375
  --expires-in=7d \
369
376
  --config=./publish-content.config.js
@@ -459,7 +466,7 @@ collectionSelector.fromConfigStore('my-config-store', 'collection-key');
459
466
  If you're happy with a preview or staging collection and want to make it live, use the `collections promote` command:
460
467
 
461
468
  ```sh
462
- npx @fastly/compute-js-static-publish collections promote \
469
+ npx @fastly/compute-js-static-publish@rc collections promote \
463
470
  --collection-name=staging
464
471
  --to=live
465
472
  ```
@@ -469,7 +476,7 @@ This copies all content and server settings from the `staging` collection to `li
469
476
  You can also specify a new expiration:
470
477
 
471
478
  ```sh
472
- npx @fastly/compute-js-static-publish collections promote \
479
+ npx @fastly/compute-js-static-publish@rc collections promote \
473
480
  --collection-name=preview-42 \
474
481
  --to=staging \
475
482
  --expires-in=7d
@@ -639,13 +646,14 @@ npm run fastly:clean
639
646
 
640
647
  These scripts run against the local and Fastly KV Stores respectively, and run the following command:
641
648
  ```
642
- npx @fastly/compute-js-static-publish clean --delete-expired-collections
649
+ npx @fastly/compute-js-static-publish@rc clean --delete-expired-collections
643
650
  ```
644
651
 
645
652
  This removes:
646
653
 
647
654
  - Expired collection index files (only if `--delete-expired-collections` is passed)
648
655
  - Unused content blobs (no longer referenced)
656
+ - Index parts that no index uses
649
657
  - Orphaned server config files
650
658
 
651
659
  ### 🔍 Dry Run Mode
@@ -653,7 +661,7 @@ This removes:
653
661
  Preview what will be deleted without making changes:
654
662
 
655
663
  ```sh
656
- npx @fastly/compute-js-static-publish clean --dry-run
664
+ npx @fastly/compute-js-static-publish@rc clean --dry-run
657
665
  ```
658
666
 
659
667
  > ⚠️ Cleanup never deletes the default collection and never deletes content that’s still in use.
@@ -675,7 +683,9 @@ Assets are stored in multiple formats (uncompressed + compressed) if configured.
675
683
 
676
684
  ## 🧩 Using PublisherServer in Custom Apps
677
685
 
678
- You can combine PublisherServer with custom logic to support APIs, authentication, redirects, or A/B testing. `PublisherServer` returns `null` when it cannot handle a request, allowing you to chain in your own logic.
686
+ You can combine PublisherServer with custom logic to support APIs, authentication, redirects, or A/B testing. Handle your own routes before you call `serveRequest()`.
687
+
688
+ `serveRequest()` returns `null` for a method other than `GET` or `HEAD`, and when no file matches and no SPA file or 404 page applies. If `publish-content.config.js` sets a 404 page or an SPA file, `serveRequest()` serves that page for each path that has no file. Thus, code after `serveRequest()` does not run for those requests.
679
689
 
680
690
  ```js
681
691
  import { PublisherServer } from '@fastly/compute-js-static-publish';
@@ -688,12 +698,7 @@ addEventListener("fetch", event => {
688
698
  });
689
699
 
690
700
  async function handleRequest(request) {
691
- const response = await publisherServer.serveRequest(request);
692
- if (response) {
693
- return response;
694
- }
695
-
696
- // Add your custom logic here
701
+ // Add your custom logic here, before serveRequest()
697
702
  const url = new URL(request.url);
698
703
  if (url.pathname === '/api/hello') {
699
704
  return new Response(JSON.stringify({ greeting: "hi" }), {
@@ -701,6 +706,11 @@ async function handleRequest(request) {
701
706
  });
702
707
  }
703
708
 
709
+ const response = await publisherServer.serveRequest(request);
710
+ if (response != null) {
711
+ return response;
712
+ }
713
+
704
714
  return new Response("Not Found", { status: 404 });
705
715
  }
706
716
  ```
@@ -723,6 +733,7 @@ Server-Timing: settings;dur=12.3, index;dur=40.1, index-body;dur=31.0, index-par
723
733
  |------|-------------|
724
734
  | `settings` | Reading and parsing the collection's settings |
725
735
  | `index` | Reading the collection's index, until the response headers arrive |
736
+ | `index-part` | Reading and parsing one part of the index, if the index has parts. Can appear more than one time, for example when `autoExt` tries more than one path. |
726
737
  | `index-body` | Reading the body of the index |
727
738
  | `index-parse` | Parsing the index |
728
739
  | `asset` | Reading the file, until the response headers arrive. Can appear more than one time, one time for each variant that is tried. |
@@ -744,7 +755,7 @@ Any client can send the request header. Choose a name that is not easy to guess
744
755
 
745
756
  ### 🗄️ Caching Responses with the Core Cache
746
757
 
747
- To serve a file, `PublisherServer` reads the collection's settings, the collection's index, and the file. Fastly can cache these reads, but `PublisherServer` must still parse the index for each request, and the index of a large site is large. To skip this work, `PublisherServer` can cache whole responses with the Fastly [Core Cache](https://www.fastly.com/documentation/guides/concepts/cache/) API:
758
+ To serve a file, `PublisherServer` reads the collection's settings, the collection's index, and the file. Fastly can cache these reads, but `PublisherServer` must still parse the index (or one part of it) for each request. To skip this work, `PublisherServer` can cache whole responses with the Fastly [Core Cache](https://www.fastly.com/documentation/guides/concepts/cache/) API:
748
759
 
749
760
  ```js
750
761
  publisherServer.setResponseCache({ maxAge: 3600 });
@@ -752,17 +763,18 @@ publisherServer.setResponseCache({ maxAge: 3600 });
752
763
 
753
764
  `maxAge` is in seconds. This is off by default.
754
765
 
755
- `maxBodySize` sets the largest response, in bytes, to cache. The default is 8 MiB (`8 * 1024 * 1024`). A larger response is served from storage each time:
766
+ `maxBodySize` sets the largest response, in bytes, to cache. The default is 16 MiB (`16 * 1024 * 1024`). A larger response is served from storage each time:
756
767
 
757
768
  ```js
758
- publisherServer.setResponseCache({ maxAge: 3600, maxBodySize: 16 * 1024 * 1024 });
769
+ publisherServer.setResponseCache({ maxAge: 3600, maxBodySize: 4 * 1024 * 1024 });
759
770
  ```
760
771
 
761
772
  - A response is cached by the publish ID, the collection, the path, and the client's `Accept-Encoding`. A cache hit does not read the settings, the index, or the file.
762
773
  - A path that does not match a file is cached, too, so a missing path does not read the index again.
763
774
  - If several requests miss the same response at the same time, one request produces it, and the others wait for it.
764
775
  - Only `200` and `404` responses are cached. Conditional requests (`304`) and `HEAD` requests are answered from the cached response.
765
- - Each cached response has the surrogate key `<publishId>-<collectionName>`. After you publish, `publish-content` purges this key (see [`--fastly-service-id`](#publish-content)), so the next request gets the new content.
776
+ - Each cached response has the surrogate key `<publishId>-<collectionName>`. After you publish, `publish-content` purges this key (see [`--fastly-service-id`](#publish-content)), so the next request gets the new content. `collections promote` and `collections delete` purge the key of the collection that they change.
777
+ - In S3 mode, the server also keeps the settings, the index, and the files that it reads from storage in the Fastly cache. The settings and the index are kept for 1 hour, with the surrogate key of the collection. The files and the index parts are kept for 1 year, with the surrogate key `<publishId>-files`, because their keys have the hash of their content. Thus after a publish, a file that did not change is read from the cache, not from storage. A publish does not purge `<publishId>-files`. To remove the cached copies of all files, purge it yourself.
766
778
 
767
779
  `serveRequest()` uses the response cache automatically. If you call `getMatchingAsset()` and `serveAsset()` directly, wrap them in `serveCached()`. When a response is not cached yet, `serveCached()` calls your function to produce it, with a `GET` request that has no conditional headers:
768
780
 
@@ -781,7 +793,7 @@ The second argument identifies the response in the collection. If anything other
781
793
 
782
794
  Notes:
783
795
 
784
- - A response is read completely before it is cached, so a request uses memory for one response, up to `maxBodySize`. Other requests that wait for the same response get it when it is cached.
796
+ - A response is read completely before it is cached. The request that caches it uses memory of about two times the body, up to two times `maxBodySize`. A Compute instance has a limit on its memory, so do not set `maxBodySize` larger than 48 MiB (`48 * 1024 * 1024`). Other requests that wait for the same response get it when it is cached.
785
797
  - A response is cached only if its body has the size in the file's metadata. If storage returns a different body, nothing is cached, the request gets an error, and the next request reads the file again.
786
798
  - With `--local`, `publish-content` cannot purge the local cache. Restart `fastly compute serve` to see newly published content, or leave the response cache off in local development.
787
799
  - On staging, a purge must include the `Fastly-Purge-Environment: staging` header to clear the staging cache. Without it, a purge clears only the production cache. Use `publish-content --purge-environment=production,staging` to purge both.
@@ -825,7 +837,7 @@ You can stream `assetVariant.storageEntry.body` directly to a `Response`, or rea
825
837
  ### Available Commands
826
838
 
827
839
  #### Outside a Compute App Directory
828
- - `npx @fastly/compute-js-static-publish@latest [options]` - Scaffold a new Compute app
840
+ - `npx @fastly/compute-js-static-publish@rc [options]` - Scaffold a new Compute app
829
841
 
830
842
  #### Inside a Compute App Directory
831
843
  - `publish-content` - Publish static files to storage (KV Store or S3-compatible storage) under a named collection
@@ -843,12 +855,12 @@ Run outside an existing Compute app directory:
843
855
 
844
856
  ```sh
845
857
  # Using KV store storage
846
- npx @fastly/compute-js-static-publish@latest \
858
+ npx @fastly/compute-js-static-publish@rc \
847
859
  --root-dir=./public \
848
860
  --kv-store-name=<site-content>
849
861
 
850
862
  # Using S3 storage (BETA)
851
- npx @fastly/compute-js-static-publish@latest \
863
+ npx @fastly/compute-js-static-publish@rc \
852
864
  --root-dir=./public \
853
865
  --storage-mode=s3 \
854
866
  --s3-region=<s3 region> \
@@ -859,7 +871,7 @@ npx @fastly/compute-js-static-publish@latest \
859
871
  #### Full options list
860
872
 
861
873
  ```sh
862
- npx @fastly/compute-js-static-publish@latest \
874
+ npx @fastly/compute-js-static-publish@rc \
863
875
  --root-dir=./public \
864
876
  { [--storage-mode=kv-store] --kv-store-name=<site-content> | \
865
877
  --storage-mode=s3 --s3-region=<s3 region> --s3-bucket=<bucket name> [--s3-endpoint=<endpoint>] } \
@@ -914,7 +926,7 @@ Once you're in the scaffolded Compute app directory (with `static-publish.rc.js`
914
926
  #### `publish-content`
915
927
 
916
928
  ```sh
917
- npx @fastly/compute-js-static-publish publish-content \
929
+ npx @fastly/compute-js-static-publish@rc publish-content \
918
930
  [--root-dir=./public] \
919
931
  [--collection-name=preview-42] \
920
932
  [--config=./publish-content.config.js] \
@@ -931,7 +943,7 @@ npx @fastly/compute-js-static-publish publish-content \
931
943
 
932
944
  Publishes static files from your local root directory into a named collection, in the storage that `static-publish.rc.js` specifies: the Fastly KV Store, S3-compatible storage (BETA), or a local dev directory (`--local`, KV Store mode only).
933
945
 
934
- Before it scans your files, the command lists the files that are already in storage. Files that already exist with the same hash are not compressed or uploaded again. With the KV Store, the command uploads the remaining files in batches.
946
+ Before it scans your files, the command lists the files that are already in storage. Files that already exist with the same hash are not compressed or uploaded again. With the KV Store, a file larger than 20 MiB is stored in chunks, and the command uploads a chunk again if the chunk in storage does not have the correct size. Then the command uploads the remaining files in batches.
935
947
 
936
948
  After this process is complete, the PublisherServer object in the Compute application will see the updated index of files and updated server settings from the `publish-content.config.js` file.
937
949
 
@@ -942,7 +954,7 @@ After this process is complete, the PublisherServer object in the Compute applic
942
954
  - `--root-dir`: Source directory to read files from (overrides value in `publish-content.config.js`)
943
955
  - `--overwrite-existing`: Always upload all files, even if they are already in storage. `--kv-overwrite` is an alias.
944
956
  - `--brotli-quality`: Brotli quality for the `br` variants, an integer from 0 to 11. Overrides `brotliQuality` in `publish-content.config.js`. This is useful in CI, where the config file is generated at each run.
945
- - `--fastly-service-id`: The Fastly Service ID to purge after publishing. The command purges the surrogate key `<publishId>-<collectionName>`, so that the service stops serving cached copies of the collection's settings, index, files, and responses (see [response cache](#️-caching-responses-with-the-core-cache)). If not set, the tool will check:
957
+ - `--fastly-service-id`: The Fastly Service ID to purge after publishing. The command purges the surrogate key `<publishId>-<collectionName>`, so that the service stops serving cached copies of the collection's settings, index, and responses (see [response cache](#️-caching-responses-with-the-core-cache)). If not set, the tool will check:
946
958
  - **`FASTLY_SERVICE_ID` environment variable**
947
959
  - `service_id` in `fastly.toml`
948
960
 
@@ -972,13 +984,13 @@ After this process is complete, the PublisherServer object in the Compute applic
972
984
  #### `clean`
973
985
 
974
986
  ```sh
975
- npx @fastly/compute-js-static-publish clean \
987
+ npx @fastly/compute-js-static-publish@rc clean \
976
988
  [--delete-expired-collections] \
977
989
  [--dry-run]
978
990
  ```
979
991
 
980
992
  Cleans up expired or unreferenced items in storage (KV Store or S3-compatible storage).
981
- This can include expired collection indexes and orphaned content assets.
993
+ This can include expired collection indexes, orphaned content assets, and index parts that no index uses.
982
994
 
983
995
  ##### Options:
984
996
 
@@ -998,7 +1010,7 @@ This can include expired collection indexes and orphaned content assets.
998
1010
  #### `collections list`
999
1011
 
1000
1012
  ```sh
1001
- npx @fastly/compute-js-static-publish collections list
1013
+ npx @fastly/compute-js-static-publish@rc collections list
1002
1014
  ```
1003
1015
  Lists all collections currently published in storage.
1004
1016
 
@@ -1017,13 +1029,15 @@ Lists all collections currently published in storage.
1017
1029
  #### `collections promote`
1018
1030
 
1019
1031
  ```sh
1020
- npx @fastly/compute-js-static-publish collections promote \
1032
+ npx @fastly/compute-js-static-publish@rc collections promote \
1021
1033
  --collection-name=preview-42 \
1022
1034
  --to=live \
1023
1035
  [--expires-in=7d | --expires-at=2025-06-01T00:00Z | --expires-never]
1024
1036
  ```
1025
1037
  Copies an existing collection (content + config) to a new collection name.
1026
1038
 
1039
+ If a Service ID is found, the command then purges the surrogate key `<publishId>-<collectionName>` of the target collection, so that the service stops serving cached responses of the old content. This uses the same options as [`publish-content`](#publish-content).
1040
+
1027
1041
  ##### Options:
1028
1042
 
1029
1043
  - `--collection-name`: The name of the source collection to promote (required)
@@ -1043,6 +1057,11 @@ Copies an existing collection (content + config) to a new collection name.
1043
1057
 
1044
1058
  - `--fastly-api-token`: API token to use when publishing. If not set, the tool uses the **`FASTLY_API_TOKEN` environment variable**.
1045
1059
 
1060
+ **Purge Options:**
1061
+
1062
+ - `--fastly-service-id`: The Fastly Service ID to purge after promoting. If not set, the tool checks the `FASTLY_SERVICE_ID` environment variable, then `service_id` in `fastly.toml`. If none is found, the command skips the purge. The purge also needs an API token (see `--fastly-api-token`), also in S3 mode. With `--local`, there is no purge. If the purge fails, the command shows a warning and completes, because the collection is already promoted.
1063
+ - `--purge-environment`: The environments to purge: `production` (the default), `staging`, or both, as a comma-separated list. You can also repeat the option.
1064
+
1046
1065
  **S3 Storage Options (BETA):**
1047
1066
 
1048
1067
  - `--s3-access-key-id`, `--s3-secret-access-key`: Access key ID and secret access key for S3-compatible storage. If not set, the tool will check the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables.
@@ -1050,7 +1069,7 @@ Copies an existing collection (content + config) to a new collection name.
1050
1069
  #### `collections update-expiration`
1051
1070
 
1052
1071
  ```sh
1053
- npx @fastly/compute-js-static-publish collections update-expiration \
1072
+ npx @fastly/compute-js-static-publish@rc collections update-expiration \
1054
1073
  --collection-name=preview-42 \
1055
1074
  --expires-in=3d | --expires-at=2025-06-01T00:00Z | --expires-never
1056
1075
  ```
@@ -1080,13 +1099,13 @@ Sets or updates the expiration time of an existing collection.
1080
1099
  #### `collections delete`
1081
1100
 
1082
1101
  ```sh
1083
- npx @fastly/compute-js-static-publish collections delete \
1102
+ npx @fastly/compute-js-static-publish@rc collections delete \
1084
1103
  --collection-name=preview-42
1085
1104
  ```
1086
1105
 
1087
1106
  Deletes a collection index from storage. The content files will remain as they may still be referenced by other collection indexes.
1088
1107
 
1089
- Use the `npx @fastly/compute-js-static-publish clean` command afterward to remove content files that are no longer referenced by any collection.
1108
+ Use the `npx @fastly/compute-js-static-publish@rc clean` command afterward to remove content files that are no longer referenced by any collection.
1090
1109
 
1091
1110
  If a Service ID is found, the command then purges the surrogate key `<publishId>-<collectionName>`, so that the service stops serving cached responses of the deleted collection. This uses the same options as [`publish-content`](#publish-content).
1092
1111
 
@@ -1204,7 +1223,7 @@ async function handleRequest(event) {
1204
1223
 
1205
1224
  ## 📚 Next Steps
1206
1225
 
1207
- - View CLI command help: `npx @fastly/compute-js-static-publish --help`
1226
+ - View CLI command help: `npx @fastly/compute-js-static-publish@rc --help`
1208
1227
  - Use in CI to automate branch previews
1209
1228
  - Visit [https://developer.fastly.com](https://developer.fastly.com) for Compute platform docs
1210
1229
 
@@ -1212,6 +1231,8 @@ async function handleRequest(event) {
1212
1231
 
1213
1232
  To build the package, run `npm run build`. To run the tests, see [test/README.md](./test/README.md).
1214
1233
 
1234
+ In the code, its comments, and the docs for developers of this package, a **customer** is a developer who uses this package to publish a site, and a **visitor** is a person who opens the customer's site.
1235
+
1215
1236
  ## Issues
1216
1237
 
1217
1238
  If you encounter any non-security-related bug or unexpected behavior, please [file an issue][bug] using the bug report template.
package/MIGRATING.md ADDED
@@ -0,0 +1,128 @@
1
+ # Migration Guide
2
+
3
+ New major versions of `@fastly/compute-js-static-publish` can involve changes to the files that
4
+ are generated during scaffolding. For this reason, it is recommended that you re-scaffold your application.
5
+
6
+ This is straightforward if you're using `compute-js-static-publisher` out-of-the-box. Otherwise, read on.
7
+
8
+ > [!NOTE]
9
+ > This document is under construction.
10
+ >
11
+
12
+ ## Upgrade from v7 to v8
13
+
14
+ v8 can use the files that v7 published. The storage key layout did not change. v8 also accepts the v7 format of
15
+ `static-publish.rc.js` (`kvStoreName` at the top level). Thus, an app that uses the KV Store does not need a new
16
+ scaffold.
17
+
18
+ To upgrade an app that uses the KV Store:
19
+
20
+ 1. In the `compute-js/` directory of your app, install v8:
21
+
22
+ ```sh
23
+ npm install @fastly/compute-js-static-publish@rc
24
+ ```
25
+
26
+ 2. Make sure that the CLI can get a Fastly API token. Set the `FASTLY_API_TOKEN` environment variable, or use
27
+ `--fastly-api-token`. v8 no longer uses the token logged in by the Fastly CLI.
28
+
29
+ 3. Build and deploy your app again. The Wasm binary contains a copy of `static-publish.rc.js`, and the server code
30
+ changed.
31
+
32
+ 4. Publish your content again with `npm run publish-content`. This step is optional. v8 serves the content that v7
33
+ published.
34
+
35
+ ### Changes to examine
36
+
37
+ - **The CLI purges after it publishes.** In v8, `publish-content` purges the surrogate key `<publishId>-<collection>`
38
+ in KV Store mode too. It finds the Service ID from `--fastly-service-id`, then the `FASTLY_SERVICE_ID`
39
+ environment variable, then `service_id` in `fastly.toml`. If it finds a Service ID, the API token must have permission to purge
40
+ that service. If you do not want a purge, make sure that the CLI does not find a Service ID. If the purge fails,
41
+ the CLI shows a warning, and the publish is complete. `collections delete` purges the same way after it deletes a
42
+ collection.
43
+ - **`kvStoreAssetInclusionTest` has a new name.** In `publish-content.config.js`, use `assetInclusionTest`. The old
44
+ name continues to work, but it is deprecated.
45
+ - **Imports of files in `build/` are not supported.** Import the named exports of
46
+ `@fastly/compute-js-static-publish`.
47
+ - **`--public-dir` and `server.publicDirPrefix` are deprecated.** `publish-content` shows a warning if
48
+ `publicDirPrefix` is not empty. See [Stop using `publicDirPrefix`](#stop-using-publicdirprefix-deprecated).
49
+ - **The `@fastly/cli` dependency is removed** from this package. A scaffolded app continues to have `@fastly/cli` as
50
+ its own dependency.
51
+
52
+ ### Stop using `publicDirPrefix` (deprecated)
53
+
54
+ `--public-dir` and `server.publicDirPrefix` are deprecated. A future version will remove them. If `publish-content`
55
+ shows a warning about `server.publicDirPrefix`, do the steps in this section. If it does not show the warning, you do
56
+ not use this feature, and you do not have to do anything.
57
+
58
+ `publicDirPrefix` lets you publish files that requests cannot get. For example, with this layout, `rootDir` is
59
+ `'../site'` and `publicDirPrefix` is `'/public'`:
60
+
61
+ ```
62
+ site/
63
+ 404.html published as /404.html, but /404.html is not a URL
64
+ templates/
65
+ email.html published as /templates/email.html, but it is not a URL
66
+ public/
67
+ index.html published as /public/index.html, served at /index.html
68
+ ```
69
+
70
+ To stop using `publicDirPrefix`:
71
+
72
+ 1. Find the files that are under `rootDir` but not under the public directory (`site/public/` in the example). For
73
+ each file, do one of these steps:
74
+ - If your app does not use the file, do nothing. After step 2, the CLI does not publish it.
75
+ - If the file is your `spaFile` or your `notFoundPageFile`, move it into the public directory. Then requests can
76
+ also get it at its own URL, for example `/404.html`.
77
+ - If your code reads the file with `getMatchingAsset()`, move it into the public directory. Then requests can also
78
+ get it at its own URL. To prevent this, return a response in `src/index.js` before you call `serveRequest()`:
79
+
80
+ ```js
81
+ const url = new URL(request.url);
82
+ if (url.pathname.startsWith('/templates/')) {
83
+ return new Response('Not found', { status: 404 });
84
+ }
85
+ const response = await publisherServer.serveRequest(request);
86
+ ```
87
+
88
+ 2. In `publish-content.config.js`:
89
+ - Set `rootDir` to the public directory, for example `'../site/public'`.
90
+ - Remove `publicDirPrefix` from the `server` section.
91
+ - In `spaFile` and `notFoundPageFile`, remove the prefix, for example change `'/public/404.html'` to
92
+ `'/404.html'`. These values are asset keys, and asset keys are relative to `rootDir`.
93
+ - Do not change `staticItems`. These values are already relative to the public directory.
94
+
95
+ 3. If your code calls `getMatchingAsset()` with a key that starts with the prefix, remove the prefix from the key, for
96
+ example change `'/public/index.html'` to `'/index.html'`. Then build and deploy your app. Between the deploy and
97
+ step 4, your code does not find these files.
98
+
99
+ 4. Publish each collection that you serve again. Each collection keeps its old settings and its old index until you
100
+ publish it again. The keys of the files are the hashes of the content, so the CLI does not upload the same files
101
+ again.
102
+
103
+ ### Move from the KV Store to S3-compatible storage (BETA)
104
+
105
+ You do not have to move to S3-compatible storage. The KV Store continues to be the default storage mode.
106
+
107
+ There is no tool that moves your content from the KV Store to a bucket. The CLI publishes from your source files.
108
+ Thus, to move, you publish your content again into the bucket:
109
+
110
+ 1. Scaffold a new app with `--storage-mode=s3`, `--s3-region`, `--s3-bucket`, and, if necessary, `--s3-endpoint`.
111
+ Scaffold it into a different directory, so that you can compare the new files with your current app.
112
+
113
+ 2. Copy your changes from your current app into the new app, for example the changes to `src/index.js` and to
114
+ `publish-content.config.js`. Keep the same `publishId` and `defaultCollectionName`.
115
+
116
+ 3. Set up the S3 credentials for publishing and for the server. See "Using S3 Compatible Storage (Beta)" in
117
+ `README.md`.
118
+
119
+ 4. Publish each collection that you need again, from its source files. The collections that are in the KV Store
120
+ are not copied.
121
+
122
+ 5. Build and deploy the new app. Then examine your site.
123
+
124
+ 6. When you do not need the KV Store content, delete it. Before you do this, make sure that no service version
125
+ that is active or staged uses that KV Store.
126
+
127
+ > [!NOTE]
128
+ > S3-compatible storage is in beta. The configuration and these steps can change before this feature is stable.
package/README.md CHANGED
@@ -18,18 +18,18 @@ 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@rc --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@rc --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`).
31
31
 
32
- For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/main/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
32
+ For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/rc/8.0.3/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
33
33
 
34
34
  ### 🔧 Local Preview
35
35
 
package/README.short.md CHANGED
@@ -18,18 +18,18 @@ 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@rc --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@rc --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`).
31
31
 
32
- For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/main/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
32
+ For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/rc/8.0.3/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
33
33
 
34
34
  ### 🔧 Local Preview
35
35
 
@@ -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":"AAqDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqPhD"}
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import path from 'node:path';
6
6
  import { decodeIndexMetadata } from '../../../models/server/index.js';
7
+ import { getIndexPartsPrefix, getIndexPartsSetPrefix, parseIndexPartKey } from '../../../models/index-parts/index.js';
7
8
  import { isExpired } from '../../../models/time/index.js';
8
9
  import { parseCommandLine } from '../../util/args.js';
9
10
  import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
@@ -121,6 +122,8 @@ export async function action(actionArgs) {
121
122
  const liveCollections = new Set();
122
123
  // All asset keys (hashes) that we are keeping
123
124
  const assetsIdsInUse = new Set();
125
+ // The key prefixes of the index parts that we are keeping
126
+ const indexPartsInUse = new Set();
124
127
  console.log('Processing collections:');
125
128
  await storageProvider.doConcurrentParallel(foundCollections.map(collection => ({
126
129
  key: indexesPrefix + collection,
@@ -156,6 +159,9 @@ export async function action(actionArgs) {
156
159
  return;
157
160
  }
158
161
  liveCollections.add(collection);
162
+ if (indexMetadata.indexParts != null) {
163
+ indexPartsInUse.add(getIndexPartsSetPrefix(publishId, indexMetadata.indexParts));
164
+ }
159
165
  const kvAssetsIndex = (await new Response(indexEntryInfo.data).json());
160
166
  for (const [_assetKey, assetEntry] of Object.entries(kvAssetsIndex)) {
161
167
  if (assetEntry.key.startsWith('sha256:')) {
@@ -210,6 +216,27 @@ export async function action(actionArgs) {
210
216
  }
211
217
  }
212
218
  console.log('');
219
+ // ### Find the index parts that no live index uses
220
+ console.log('Enumerating index parts:');
221
+ const indexPartKeys = await storageProvider.getStorageKeys(getIndexPartsPrefix(publishId));
222
+ if (indexPartKeys == null) {
223
+ throw new Error(`Can't query index parts in storage`);
224
+ }
225
+ for (const indexPartKey of indexPartKeys) {
226
+ const parsed = parseIndexPartKey(publishId, indexPartKey);
227
+ if (parsed == null) {
228
+ // If we don't know the format, we ignore it
229
+ continue;
230
+ }
231
+ if (indexPartsInUse.has(getIndexPartsSetPrefix(publishId, parsed))) {
232
+ console.log(` ${indexPartKey}: in use`);
233
+ }
234
+ else {
235
+ assetKeysToDelete.add(indexPartKey);
236
+ console.log(` ${indexPartKey}: not in use - ✅ marking for deletion`);
237
+ }
238
+ }
239
+ console.log('');
213
240
  // ### Delete items that have been flagged
214
241
  const items = [...assetKeysToDelete].map(key => ({ key }));
215
242
  await storageProvider.doConcurrentParallel(items, async (_, key) => {
@@ -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":"AAkFA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmNhD"}