@fastly/compute-js-static-publish 8.0.0-beta.8 → 8.0.0-rc.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 (87) hide show
  1. package/README.md +18 -4
  2. package/README.short.md +18 -4
  3. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  4. package/build/cli/cli/commands/manage/clean.js +7 -5
  5. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  6. package/build/cli/cli/commands/manage/collections/delete.js +3 -4
  7. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  8. package/build/cli/cli/commands/manage/collections/index.js +2 -3
  9. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  10. package/build/cli/cli/commands/manage/collections/list.js +2 -3
  11. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  12. package/build/cli/cli/commands/manage/collections/promote.js +2 -3
  13. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  14. package/build/cli/cli/commands/manage/collections/update-expiration.js +2 -3
  15. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  16. package/build/cli/cli/commands/manage/index.js +2 -3
  17. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  18. package/build/cli/cli/commands/manage/publish-content.js +166 -66
  19. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  20. package/build/cli/cli/commands/scaffold/index.js +7 -4
  21. package/build/cli/cli/compression/brotli.d.ts +2 -1
  22. package/build/cli/cli/compression/brotli.d.ts.map +1 -1
  23. package/build/cli/cli/compression/brotli.js +15 -4
  24. package/build/cli/cli/compression/gzip.d.ts +2 -1
  25. package/build/cli/cli/compression/gzip.d.ts.map +1 -1
  26. package/build/cli/cli/compression/gzip.js +8 -4
  27. package/build/cli/cli/compression/index.d.ts +4 -1
  28. package/build/cli/cli/compression/index.d.ts.map +1 -1
  29. package/build/cli/cli/index.js +8 -0
  30. package/build/cli/cli/storage/kv-store-local-provider.d.ts +3 -6
  31. package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
  32. package/build/cli/cli/storage/kv-store-local-provider.js +3 -10
  33. package/build/cli/cli/storage/kv-store-provider.d.ts +4 -6
  34. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  35. package/build/cli/cli/storage/kv-store-provider.js +38 -68
  36. package/build/cli/cli/storage/s3-storage-provider.d.ts +6 -9
  37. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  38. package/build/cli/cli/storage/s3-storage-provider.js +45 -80
  39. package/build/cli/cli/storage/storage-provider.d.ts +7 -6
  40. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  41. package/build/cli/cli/storage/storage-provider.js +13 -0
  42. package/build/cli/cli/util/api-token.d.ts.map +1 -1
  43. package/build/cli/cli/util/api-token.js +0 -28
  44. package/build/cli/cli/util/config.d.ts.map +1 -1
  45. package/build/cli/cli/util/config.js +8 -1
  46. package/build/cli/cli/util/content-types.d.ts.map +1 -1
  47. package/build/cli/cli/util/content-types.js +5 -2
  48. package/build/cli/cli/util/kv-store-items.d.ts +12 -0
  49. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  50. package/build/cli/cli/util/kv-store-items.js +49 -0
  51. package/build/cli/cli/util/kv-store.d.ts +6 -0
  52. package/build/cli/cli/util/kv-store.d.ts.map +1 -1
  53. package/build/cli/cli/util/kv-store.js +39 -2
  54. package/build/cli/cli/util/purge.d.ts +17 -1
  55. package/build/cli/cli/util/purge.d.ts.map +1 -1
  56. package/build/cli/cli/util/purge.js +63 -3
  57. package/build/cli/cli/util/retryable.d.ts +2 -1
  58. package/build/cli/cli/util/retryable.d.ts.map +1 -1
  59. package/build/cli/cli/util/retryable.js +34 -1
  60. package/build/cli/cli/util/service-id.d.ts +10 -0
  61. package/build/cli/cli/util/service-id.d.ts.map +1 -0
  62. package/build/cli/cli/util/service-id.js +27 -0
  63. package/build/cli/cli/util/variants.d.ts +2 -1
  64. package/build/cli/cli/util/variants.d.ts.map +1 -1
  65. package/build/cli/cli/util/variants.js +2 -2
  66. package/build/cli/models/assets/index.js +1 -1
  67. package/build/cli/models/config/publish-content-config.d.ts +2 -0
  68. package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
  69. package/build/server/models/assets/index.js +1 -1
  70. package/build/server/models/config/publish-content-config.d.ts +2 -0
  71. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  72. package/build/server/server/publisher-server/index.d.ts +15 -1
  73. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  74. package/build/server/server/publisher-server/index.js +189 -56
  75. package/build/server/server/publisher-server/response-cache.d.ts +19 -0
  76. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -0
  77. package/build/server/server/publisher-server/response-cache.js +106 -0
  78. package/build/server/server/storage/s3-storage-provider.d.ts +2 -5
  79. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  80. package/build/server/server/storage/s3-storage-provider.js +95 -38
  81. package/build/server/server/storage/storage-provider.d.ts +1 -1
  82. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  83. package/build/server/server/storage/storage-provider.js +2 -1
  84. package/build/server/server/util/server-timing.d.ts +7 -0
  85. package/build/server/server/util/server-timing.d.ts.map +1 -0
  86. package/build/server/server/util/server-timing.js +34 -0
  87. package/package.json +9 -7
package/README.md CHANGED
@@ -24,22 +24,26 @@ npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name
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@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
28
28
  ```
29
29
 
30
- For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/main/README.md#s3-compatible-storage) section in the full documentation.
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
+
32
+ For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/v8/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
31
33
 
32
34
  ### 🔧 Local Preview
33
35
 
34
36
  ```sh
35
37
  cd compute-js
36
38
  npm install
37
- npm run dev:publish # 'publish' your files to the simulated local KV Store or to the S3 bucket
39
+ npm run dev:publish # 'publish' your files to the simulated local KV Store
38
40
  npm run dev:start # preview locally
39
41
  ```
40
42
 
41
43
  Serves your app at `http://127.0.0.1:7676`. If the app is using the KV Store, your content is served from a simulated KV Store managed by the development server.
42
44
 
45
+ If the app uses S3-compatible storage, use `npm run s3:publish` in place of `npm run dev:publish`. This uploads your files to the bucket. Set the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables before you run `s3:publish` and `dev:start`.
46
+
43
47
  ### 🚀 Deploy to Production
44
48
 
45
49
  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:
@@ -57,6 +61,8 @@ cd compute-js
57
61
  npm run fastly:publish # upload your static files
58
62
  ```
59
63
 
64
+ If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
65
+
60
66
  ## Features
61
67
 
62
68
  - Named collections for previews, staging, production
@@ -67,4 +73,12 @@ npm run fastly:publish # upload your static files
67
73
  ## Documentation
68
74
 
69
75
  📘 Full documentation available on GitHub:
70
- [https://github.com/fastly/compute-js-static-publish](https://github.com/fastly/compute-js-static-publish)
76
+ [https://github.com/fastly/compute-js-static-publish/tree/v8](https://github.com/fastly/compute-js-static-publish/tree/v8)
77
+
78
+ ### Security issues
79
+
80
+ Please see our [SECURITY.md](SECURITY.md) for guidance on reporting security-related issues.
81
+
82
+ ## License
83
+
84
+ [MIT](./LICENSE).
package/README.short.md CHANGED
@@ -24,22 +24,26 @@ npx @fastly/compute-js-static-publish@latest --root-dir=./public --kv-store-name
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@latest --root-dir=./public --storage-mode=s3 --s3-region=<region> --s3-bucket=<bucket-name>
28
28
  ```
29
29
 
30
- For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/main/README.md#s3-compatible-storage) section in the full documentation.
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
+
32
+ For more details, see the [S3-compatible storage](https://github.com/fastly/compute-js-static-publish/blob/v8/README.md#-using-s3-compatible-storage-beta) section in the full documentation.
31
33
 
32
34
  ### 🔧 Local Preview
33
35
 
34
36
  ```sh
35
37
  cd compute-js
36
38
  npm install
37
- npm run dev:publish # 'publish' your files to the simulated local KV Store or to the S3 bucket
39
+ npm run dev:publish # 'publish' your files to the simulated local KV Store
38
40
  npm run dev:start # preview locally
39
41
  ```
40
42
 
41
43
  Serves your app at `http://127.0.0.1:7676`. If the app is using the KV Store, your content is served from a simulated KV Store managed by the development server.
42
44
 
45
+ If the app uses S3-compatible storage, use `npm run s3:publish` in place of `npm run dev:publish`. This uploads your files to the bucket. Set the `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` environment variables before you run `s3:publish` and `dev:start`.
46
+
43
47
  ### 🚀 Deploy to Production
44
48
 
45
49
  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:
@@ -57,6 +61,8 @@ cd compute-js
57
61
  npm run fastly:publish # upload your static files
58
62
  ```
59
63
 
64
+ If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
65
+
60
66
  ## Features
61
67
 
62
68
  - Named collections for previews, staging, production
@@ -67,4 +73,12 @@ npm run fastly:publish # upload your static files
67
73
  ## Documentation
68
74
 
69
75
  📘 Full documentation available on GitHub:
70
- [https://github.com/fastly/compute-js-static-publish](https://github.com/fastly/compute-js-static-publish)
76
+ [https://github.com/fastly/compute-js-static-publish/tree/v8](https://github.com/fastly/compute-js-static-publish/tree/v8)
77
+
78
+ ### Security issues
79
+
80
+ Please see our [SECURITY.md](SECURITY.md) for guidance on reporting security-related issues.
81
+
82
+ ## License
83
+
84
+ [MIT](./LICENSE).
@@ -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,iBAoNhD"}
1
+ {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAmDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0NhD"}
@@ -29,9 +29,8 @@ KV Store Options:
29
29
  with the local development environment.
30
30
 
31
31
  --fastly-api-token=<token> Fastly API token for KV Store access.
32
- If not set, the tool will check:
33
- 1. FASTLY_API_TOKEN environment variable
34
- 2. The default profile in the Fastly CLI
32
+ If not set, the tool uses the FASTLY_API_TOKEN
33
+ environment variable.
35
34
 
36
35
  S3 Storage Options (BETA):
37
36
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
@@ -162,7 +161,10 @@ export async function action(actionArgs) {
162
161
  assetsIdsInUse.add(`sha256_${assetEntry.key.slice('sha256:'.length)}`);
163
162
  }
164
163
  }
165
- });
164
+ }, undefined,
165
+ // If an index cannot be read, stop. If we continue, we mark the files
166
+ // and settings of that collection as not in use, and delete them.
167
+ true);
166
168
  console.log('');
167
169
  // ### List all settings ###
168
170
  console.log('Enumerating settings:');
@@ -217,6 +219,6 @@ export async function action(actionArgs) {
217
219
  console.log(`Deleting key from storage: ${key}`);
218
220
  await storageProvider.deleteStorageEntry(key);
219
221
  }
220
- });
222
+ }, undefined, true);
221
223
  console.log('✅ Completed.');
222
224
  }
@@ -1 +1 @@
1
- {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAkDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqIhD"}
1
+ {"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAiDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuIhD"}
@@ -28,9 +28,8 @@ KV Store Options:
28
28
  with the local development environment.
29
29
 
30
30
  --fastly-api-token=<token> Fastly API token for KV Store access.
31
- If not set, the tool will check:
32
- 1. FASTLY_API_TOKEN environment variable
33
- 2. The default profile in the Fastly CLI
31
+ If not set, the tool uses the FASTLY_API_TOKEN
32
+ environment variable.
34
33
 
35
34
  S3 Storage Options (BETA):
36
35
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
@@ -144,6 +143,6 @@ export async function action(actionArgs) {
144
143
  await storageProvider.doConcurrentParallel(items, async (_, key) => {
145
144
  console.log(`Deleting key from storage: ${key}`);
146
145
  await storageProvider.deleteStorageEntry(key);
147
- });
146
+ }, undefined, true);
148
147
  console.log("✅ Completed.");
149
148
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0BhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AAmDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0BhD"}
@@ -29,9 +29,8 @@ KV Store Options:
29
29
  with the local development environment.
30
30
 
31
31
  --fastly-api-token=<token> Fastly API token for KV Store access.
32
- If not set, the tool will check:
33
- 1. FASTLY_API_TOKEN environment variable
34
- 2. The default profile in the Fastly CLI
32
+ If not set, the tool uses the FASTLY_API_TOKEN
33
+ environment variable.
35
34
 
36
35
  S3 Storage Options (BETA):
37
36
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
@@ -1 +1 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AA6CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmIhD"}
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AA4CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAmIhD"}
@@ -23,9 +23,8 @@ KV Store Options:
23
23
  with the local development environment.
24
24
 
25
25
  --fastly-api-token=<token> Fastly API token for KV Store access.
26
- If not set, the tool will check:
27
- 1. FASTLY_API_TOKEN environment variable
28
- 2. The default profile in the Fastly CLI
26
+ If not set, the tool uses the FASTLY_API_TOKEN
27
+ environment variable.
29
28
 
30
29
  S3 Storage Options (BETA):
31
30
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
@@ -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":"AAkEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAuLhD"}
@@ -45,9 +45,8 @@ KV Store Options:
45
45
  with the local development environment.
46
46
 
47
47
  --fastly-api-token=<token> Fastly API token for KV Store access.
48
- If not set, the tool will check:
49
- 1. FASTLY_API_TOKEN environment variable
50
- 2. The default profile in the Fastly CLI
48
+ If not set, the tool uses the FASTLY_API_TOKEN
49
+ environment variable.
51
50
 
52
51
  S3 Storage Options (BETA):
53
52
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
@@ -1 +1 @@
1
- {"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AA+DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0JhD"}
1
+ {"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AA8DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0JhD"}
@@ -41,9 +41,8 @@ KV Store Options:
41
41
  with the local development environment.
42
42
 
43
43
  --fastly-api-token=<token> Fastly API token for KV Store access.
44
- If not set, the tool will check:
45
- 1. FASTLY_API_TOKEN environment variable
46
- 2. The default profile in the Fastly CLI
44
+ If not set, the tool uses the FASTLY_API_TOKEN
45
+ environment variable.
47
46
 
48
47
  S3 Storage Options (BETA):
49
48
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AA2DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AA0DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
@@ -31,9 +31,8 @@ KV Store Options:
31
31
  with the local development environment.
32
32
 
33
33
  --fastly-api-token=<token> Fastly API token for KV Store access.
34
- If not set, the tool will check:
35
- 1. FASTLY_API_TOKEN environment variable
36
- 2. The default profile in the Fastly CLI
34
+ If not set, the tool uses the FASTLY_API_TOKEN
35
+ environment variable.
37
36
 
38
37
  S3 Storage Options (BETA):
39
38
  --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
@@ -1 +1 @@
1
- {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAsGA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyehD"}
1
+ {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAyHA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAikBhD"}
@@ -12,7 +12,9 @@ import { LoadConfigError, loadPublishContentConfigFile, loadStaticPublisherRcFil
12
12
  import { applyDefaults } from '../../util/data.js';
13
13
  import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
14
14
  import { ensureVariantFileExists } from '../../util/variants.js';
15
- import { loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
15
+ import { concurrentMap } from '../../util/retryable.js';
16
+ import { loadPurgeTarget, purgeSurrogateKey } from '../../util/purge.js';
17
+ import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
16
18
  // Storage key format:
17
19
  // <publishId>_index_<preview_id>.json
18
20
  // <publishId>_settings_<preview_id>.json
@@ -43,12 +45,25 @@ Optional:
43
45
  Default: rootDir from publish-content.config.js
44
46
 
45
47
  --fastly-api-token=<token> Fastly API token for KV Store or cache access.
48
+ If not set, the tool uses the FASTLY_API_TOKEN
49
+ environment variable.
50
+
51
+ --fastly-service-id=<id> Fastly Service ID to purge after publishing (not with --local).
46
52
  If not set, the tool will check:
47
- 1. FASTLY_API_TOKEN environment variable
48
- 2. The default profile in the Fastly CLI
53
+ 1. FASTLY_SERVICE_ID environment variable
54
+ 2. service_id in fastly.toml
55
+ If none is found, the purge is skipped.
56
+
57
+ --purge-environment=<env> Environment to purge: production, staging, or a
58
+ comma-separated list of both. Can be repeated.
59
+ Default: production
49
60
 
50
61
  --overwrite-existing Always overwrite existing entries in storage, even if unchanged.
51
62
 
63
+ --brotli-quality=<0-11> Brotli quality for the 'br' variants. Overrides
64
+ brotliQuality in the config file.
65
+ Default: brotliQuality from publish-content.config.js, or 11
66
+
52
67
  Expiration:
53
68
  --expires-in=<duration> Expiration duration from now.
54
69
  Examples: 3d, 12h, 15m, 1w
@@ -74,6 +89,9 @@ S3 Storage Options (BETA):
74
89
  If not set, the tool will check the S3_ACCESS_KEY_ID
75
90
  and S3_SECRET_ACCESS_KEY environment variables.
76
91
 
92
+ --s3-upload-concurrency=<1-256> Number of objects to upload at the same time.
93
+ Default: 64
94
+
77
95
  Global Options:
78
96
  -h, --help Show this help message and exit.
79
97
 
@@ -91,14 +109,18 @@ export async function action(actionArgs) {
91
109
  { name: 'collection-name', type: String, },
92
110
  { name: 'root-dir', type: String, },
93
111
  { name: 'overwrite-existing', type: Boolean },
112
+ { name: 'brotli-quality', type: String },
94
113
  { name: 'expires-in', type: String },
95
114
  { name: 'expires-at', type: String },
96
115
  { name: 'expires-never', type: Boolean },
97
116
  { name: 'local', type: Boolean },
98
117
  { name: 'fastly-api-token', type: String, },
118
+ { name: 'fastly-service-id', type: String, },
119
+ { name: 'purge-environment', type: String, multiple: true, },
99
120
  { name: 'kv-overwrite', type: Boolean },
100
121
  { name: 's3-access-key-id', type: String, },
101
122
  { name: 's3-secret-access-key', type: String, },
123
+ { name: 's3-upload-concurrency', type: String, },
102
124
  ];
103
125
  const parsed = parseCommandLine(actionArgs, optionDefinitions);
104
126
  if (parsed.needHelp) {
@@ -110,7 +132,17 @@ export async function action(actionArgs) {
110
132
  help();
111
133
  return;
112
134
  }
113
- const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
135
+ const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['brotli-quality']: brotliQualityValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['fastly-service-id']: fastlyServiceId, ['purge-environment']: purgeEnvironmentValues, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, ['s3-upload-concurrency']: s3UploadConcurrencyValue, } = parsed.commandLineOptions;
136
+ let s3UploadConcurrency;
137
+ if (s3UploadConcurrencyValue !== undefined) {
138
+ if (typeof s3UploadConcurrencyValue !== 'string' || !/^\d+$/.test(s3UploadConcurrencyValue) ||
139
+ Number(s3UploadConcurrencyValue) < 1 || Number(s3UploadConcurrencyValue) > 256) {
140
+ console.error(`❌ --s3-upload-concurrency must be an integer from 1 to 256.`);
141
+ process.exitCode = 1;
142
+ return;
143
+ }
144
+ s3UploadConcurrency = Number(s3UploadConcurrencyValue);
145
+ }
114
146
  const overwriteExisting = _overwriteExisting ?? _kvOverwrite;
115
147
  // compute-js-static-publisher cli is always run from the Compute application directory
116
148
  // in other words, the directory that contains `fastly.toml`.
@@ -147,6 +179,17 @@ export async function action(actionArgs) {
147
179
  process.exitCode = 1;
148
180
  return;
149
181
  }
182
+ // --brotli-quality overrides brotliQuality in the config file.
183
+ let brotliQualitySource = 'config';
184
+ if (brotliQualityValue !== undefined) {
185
+ if (typeof brotliQualityValue !== 'string' || !/^\d+$/.test(brotliQualityValue) || Number(brotliQualityValue) > 11) {
186
+ console.error(`❌ --brotli-quality must be an integer from 0 to 11.`);
187
+ process.exitCode = 1;
188
+ return;
189
+ }
190
+ publishContentConfig.brotliQuality = Number(brotliQualityValue);
191
+ brotliQualitySource = '--brotli-quality';
192
+ }
150
193
  const publicDirRoot = path.resolve(rootDir != null ? rootDir : publishContentConfig.rootDir);
151
194
  if ((computeAppDir + '/').startsWith(publicDirRoot + '/')) {
152
195
  if (verbose) {
@@ -166,6 +209,9 @@ export async function action(actionArgs) {
166
209
  return;
167
210
  }
168
211
  console.log(`✔️ Public directory '${rootRelative(publicDirRoot)}'.`);
212
+ if (publishContentConfig.brotliQuality != null) {
213
+ console.log(`✔️ Brotli quality: ${publishContentConfig.brotliQuality} (from ${brotliQualitySource})`);
214
+ }
169
215
  const publishId = staticPublisherRc.publishId;
170
216
  console.log(` | Publish ID: ${publishId}`);
171
217
  const defaultCollectionName = staticPublisherRc.defaultCollectionName;
@@ -181,6 +227,7 @@ export async function action(actionArgs) {
181
227
  fastlyApiToken,
182
228
  s3AccessKeyId,
183
229
  s3SecretAccessKey,
230
+ s3UploadConcurrency,
184
231
  });
185
232
  }
186
233
  catch (err) {
@@ -189,6 +236,22 @@ export async function action(actionArgs) {
189
236
  process.exitCode = 1;
190
237
  return;
191
238
  }
239
+ // Purge target: checked now, so that a missing API token fails before anything is uploaded.
240
+ let purgeTarget;
241
+ try {
242
+ purgeTarget = loadPurgeTarget({
243
+ localMode: localMode ?? false,
244
+ computeAppDir,
245
+ fastlyServiceId,
246
+ fastlyApiToken,
247
+ purgeEnvironments: purgeEnvironmentValues,
248
+ });
249
+ }
250
+ catch (err) {
251
+ console.error(String(err));
252
+ process.exitCode = 1;
253
+ return;
254
+ }
192
255
  // Load content types
193
256
  const contentTypes = mergeContentTypes(publishContentConfig.contentTypes);
194
257
  // #### Collect all file paths
@@ -239,15 +302,38 @@ export async function action(actionArgs) {
239
302
  // and for serving using the local development server.
240
303
  const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
241
304
  fs.mkdirSync(storageContentDir, { recursive: true });
242
- // A list of items in storage at the end of the publishing.
243
- // Includes items that already exist as well. 'write' signifies
244
- // that the item is to be written
305
+ // The items to write to storage.
245
306
  const batch = new StorageProviderBatch();
246
307
  // Assets included in the publishing, keyed by asset key
247
308
  const assetsIndex = {};
248
- const baseHashToVariantMetadatasMap = new Map();
309
+ const baseHashToVariantKeepMap = new Map();
310
+ // #### Keys that are already in storage
311
+ // The key of a file is the hash of its content. If the key exists, storage
312
+ // already has the same content. Thus we do not compress, hash, or upload it again.
313
+ // In local mode, a key can refer to a working file that was deleted, so we do not list.
314
+ // All the keys that the scan looks for start with `<publishId>_files_sha256_` and a hex
315
+ // hash, so we list them in 16 parts at the same time.
316
+ let existingKeys;
317
+ if (!overwriteExisting && !localMode) {
318
+ console.log(`🔎 Listing files that are already in storage...`);
319
+ const listStart = Date.now();
320
+ existingKeys = new Set(await getStorageKeysByHexPrefix(storageProvider, `${publishId}_files_sha256_`) ?? []);
321
+ console.log(`✅ Found ${existingKeys.size} key(s) in ${((Date.now() - listStart) / 1000).toFixed(1)} s.`);
322
+ }
323
+ let existingVariantCount = 0;
324
+ function isVariantInStorage(variantKey, numChunks) {
325
+ if (existingKeys == null || !existingKeys.has(variantKey)) {
326
+ return false;
327
+ }
328
+ for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
329
+ if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
330
+ return false;
331
+ }
332
+ }
333
+ return true;
334
+ }
249
335
  // #### Iterate files
250
- const filePromises = files.map(async (file) => {
336
+ const fileResults = await concurrentMap(files, async (file) => {
251
337
  // #### asset key
252
338
  const assetKey = file.slice(publicDirRoot.length)
253
339
  // in Windows, assetKey will otherwise end up as \path\file.html
@@ -283,12 +369,15 @@ export async function action(actionArgs) {
283
369
  console.log(`📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
284
370
  const stats = fs.statSync(file);
285
371
  const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
286
- // #### Metadata per variant
287
- let variantMetadatas = baseHashToVariantMetadatasMap.get(baseHash);
288
- if (variantMetadatas == null) {
289
- variantMetadatas = new Map();
290
- baseHashToVariantMetadatasMap.set(baseHash, variantMetadatas);
372
+ // #### Keep flag per variant
373
+ let variantKeeps = baseHashToVariantKeepMap.get(baseHash);
374
+ if (variantKeeps == null) {
375
+ variantKeeps = new Map();
376
+ baseHashToVariantKeepMap.set(baseHash, variantKeeps);
291
377
  }
378
+ // We know the number of chunks of the original before we read it. For a
379
+ // compressed variant, we know it only if the original fits in one chunk.
380
+ const baseNumChunks = storageProvider.calculateNumChunks(baseSize);
292
381
  const variantsToKeep = [];
293
382
  const variants = [
294
383
  'original',
@@ -303,67 +392,63 @@ export async function action(actionArgs) {
303
392
  variantFilename = `${variantFilename}_${variant}`;
304
393
  }
305
394
  const variantFilePath = path.resolve(storageContentDir, variantFilename);
306
- let variantMetadata = variantMetadatas.get(variant);
307
- if (variantMetadata != null) {
395
+ let keep = variantKeeps.get(variant);
396
+ if (keep != null) {
308
397
  if (verbose) {
309
398
  console.log(` 🏃‍♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
310
399
  }
311
400
  }
401
+ else if ((variant === 'original' || baseNumChunks === 1) &&
402
+ isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
403
+ if (verbose) {
404
+ console.log(` ・ Asset found in storage with key "${variantKey}".`);
405
+ }
406
+ existingVariantCount++;
407
+ // We upload a compressed variant only if it is smaller than the
408
+ // original. Thus if it is in storage, the index keeps it.
409
+ keep = true;
410
+ variantKeeps.set(variant, keep);
411
+ }
312
412
  else {
313
- if (!overwriteExisting) {
314
- const assetVariantMetadata = await storageProvider.getExistingAssetVariant(variantKey);
315
- if (assetVariantMetadata != null) {
316
- if (verbose) {
317
- console.log(` ・ Asset found in storage with key "${variantKey}".`);
318
- }
319
- // And we already know its hash and size.
320
- variantMetadata = Object.assign(assetVariantMetadata, { existsInKvStore: true });
321
- }
413
+ await ensureVariantFileExists(variantFilePath, variant, file, verbose, { brotliQuality: publishContentConfig.brotliQuality });
414
+ let contentEncoding, hash, size;
415
+ if (variant === 'original') {
416
+ contentEncoding = undefined;
417
+ hash = baseHash;
418
+ size = baseSize;
322
419
  }
323
- if (variantMetadata == null) {
324
- console.log(` ↦ Prepping new asset for storage: "${variantKey}"`);
325
- await ensureVariantFileExists(variantFilePath, variant, file, verbose);
326
- let contentEncoding, hash, size;
327
- if (variant === 'original') {
328
- contentEncoding = undefined;
329
- hash = baseHash;
330
- size = baseSize;
331
- }
332
- else {
333
- contentEncoding = variant;
334
- ({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
335
- }
420
+ else {
421
+ contentEncoding = variant;
422
+ ({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
423
+ }
424
+ // Only keep variants whose file size actually ends up smaller than
425
+ // what we started with. Do not upload the other variants.
426
+ keep = variant === 'original' || size < baseSize;
427
+ variantKeeps.set(variant, keep);
428
+ if (keep) {
336
429
  const numChunks = storageProvider.calculateNumChunks(size);
337
- variantMetadata = {
338
- contentEncoding,
339
- size,
430
+ const metadataJson = {
431
+ size: String(size),
340
432
  hash,
341
- numChunks: numChunks > 1 ? numChunks : undefined,
342
- existsInKvStore: false,
343
433
  };
434
+ if (contentEncoding != null) {
435
+ metadataJson.contentEncoding = contentEncoding;
436
+ }
437
+ if (numChunks > 1) {
438
+ metadataJson.numChunks = String(numChunks);
439
+ }
440
+ batchItems.push({
441
+ size,
442
+ key: variantKey,
443
+ filePath: variantFilePath,
444
+ metadataJson,
445
+ });
344
446
  }
345
- variantMetadatas.set(variant, variantMetadata);
346
- const metadataJson = {
347
- size: String(variantMetadata.size),
348
- hash: variantMetadata.hash,
349
- };
350
- if (variantMetadata.contentEncoding != null) {
351
- metadataJson.contentEncoding = variantMetadata.contentEncoding;
352
- }
353
- if (variantMetadata.numChunks != null) {
354
- metadataJson.numChunks = String(variantMetadata.numChunks);
447
+ else if (verbose) {
448
+ console.log(` ・ Variant "${variantKey}" is not smaller than the original, not uploading.`);
355
449
  }
356
- batchItems.push({
357
- write: !variantMetadata.existsInKvStore,
358
- size: variantMetadata.size,
359
- key: variantKey,
360
- filePath: variantFilePath,
361
- metadataJson,
362
- });
363
450
  }
364
- // Only keep variants whose file size actually ends up smaller than
365
- // what we started with.
366
- if (variant !== 'original' && variantMetadata.size < baseSize) {
451
+ if (variant !== 'original' && keep) {
367
452
  variantsToKeep.push(variant);
368
453
  }
369
454
  }
@@ -379,7 +464,6 @@ export async function action(actionArgs) {
379
464
  batchItems,
380
465
  };
381
466
  });
382
- const fileResults = await Promise.all(filePromises);
383
467
  for (const result of fileResults) {
384
468
  if (result == null) {
385
469
  continue;
@@ -390,7 +474,10 @@ export async function action(actionArgs) {
390
474
  }
391
475
  }
392
476
  console.log(`✅ Scan complete.`);
393
- await storageProvider.applyBatch(batch);
477
+ if (existingKeys != null) {
478
+ console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
479
+ }
480
+ await storageProvider.applyBatch(batch, { existingKeys });
394
481
  // #### INDEX FILE
395
482
  console.log(`🗂️ Saving Index...`);
396
483
  const indexFileKey = `${publishId}_index_${collectionName}`;
@@ -466,6 +553,19 @@ export async function action(actionArgs) {
466
553
  const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
467
554
  await storageProvider.submitStorageEntry(settingsFileKey, settingsFilePath, JSON.stringify(serverSettings));
468
555
  console.log(`✅ Settings have been saved.`);
469
- await storageProvider.purgeSurrogateKey(`${publishId}-${collectionName}`);
556
+ if (purgeTarget != null) {
557
+ const surrogateKey = `${publishId}-${collectionName}`;
558
+ for (const environment of purgeTarget.environments) {
559
+ console.log(`Purging surrogate key [${surrogateKey}] on service [${purgeTarget.serviceId}] (${environment})...`);
560
+ const purged = await purgeSurrogateKey(purgeTarget.fastlyApiContext, purgeTarget.serviceId, surrogateKey, true, environment);
561
+ if (purged) {
562
+ console.log('Purged');
563
+ }
564
+ else {
565
+ // The content is published. Only the cached copies may be stale until they expire.
566
+ console.warn(`⚠️ Warning: Failed purging (${environment}). Cached copies may be served until they expire.`);
567
+ }
568
+ }
569
+ }
470
570
  console.log(`🎉 Completed.`);
471
571
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAuEA,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;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAsqBhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAuEA,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;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyqBhD"}