@fastly/compute-js-static-publish 8.0.0-beta.14 → 8.0.0-beta.16

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 (32) hide show
  1. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  2. package/build/cli/cli/commands/manage/clean.js +2 -3
  3. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  4. package/build/cli/cli/commands/manage/collections/delete.js +2 -3
  5. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  6. package/build/cli/cli/commands/manage/collections/index.js +2 -3
  7. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  8. package/build/cli/cli/commands/manage/collections/list.js +2 -3
  9. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  10. package/build/cli/cli/commands/manage/collections/promote.js +2 -3
  11. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  12. package/build/cli/cli/commands/manage/collections/update-expiration.js +2 -3
  13. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  14. package/build/cli/cli/commands/manage/index.js +2 -3
  15. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  16. package/build/cli/cli/commands/manage/publish-content.js +10 -3
  17. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  18. package/build/cli/cli/storage/s3-storage-provider.js +9 -6
  19. package/build/cli/cli/storage/storage-provider.d.ts +1 -0
  20. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  21. package/build/cli/cli/util/api-token.d.ts.map +1 -1
  22. package/build/cli/cli/util/api-token.js +0 -28
  23. package/build/cli/cli/util/service-id.d.ts +10 -0
  24. package/build/cli/cli/util/service-id.d.ts.map +1 -0
  25. package/build/cli/cli/util/service-id.js +26 -0
  26. package/build/server/server/publisher-server/index.d.ts +7 -0
  27. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  28. package/build/server/server/publisher-server/index.js +106 -41
  29. package/build/server/server/publisher-server/response-cache.d.ts +19 -0
  30. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -0
  31. package/build/server/server/publisher-server/response-cache.js +106 -0
  32. package/package.json +1 -2
@@ -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":"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
@@ -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,iBAuIhD"}
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
@@ -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":"AA+GA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAiiBhD"}
1
+ {"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAoHA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAoiBhD"}
@@ -44,9 +44,14 @@ Optional:
44
44
  Default: rootDir from publish-content.config.js
45
45
 
46
46
  --fastly-api-token=<token> Fastly API token for KV Store or cache access.
47
+ If not set, the tool uses the FASTLY_API_TOKEN
48
+ environment variable.
49
+
50
+ --fastly-service-id=<id> Fastly Service ID to purge after publishing (S3 storage).
47
51
  If not set, the tool will check:
48
- 1. FASTLY_API_TOKEN environment variable
49
- 2. The default profile in the Fastly CLI
52
+ 1. service_id in fastly.toml
53
+ 2. FASTLY_SERVICE_ID environment variable
54
+ If none is found, the purge is skipped.
50
55
 
51
56
  --overwrite-existing Always overwrite existing entries in storage, even if unchanged.
52
57
 
@@ -105,6 +110,7 @@ export async function action(actionArgs) {
105
110
  { name: 'expires-never', type: Boolean },
106
111
  { name: 'local', type: Boolean },
107
112
  { name: 'fastly-api-token', type: String, },
113
+ { name: 'fastly-service-id', type: String, },
108
114
  { name: 'kv-overwrite', type: Boolean },
109
115
  { name: 's3-access-key-id', type: String, },
110
116
  { name: 's3-secret-access-key', type: String, },
@@ -120,7 +126,7 @@ export async function action(actionArgs) {
120
126
  help();
121
127
  return;
122
128
  }
123
- 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, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, ['s3-upload-concurrency']: s3UploadConcurrencyValue, } = parsed.commandLineOptions;
129
+ 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, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, ['s3-upload-concurrency']: s3UploadConcurrencyValue, } = parsed.commandLineOptions;
124
130
  let s3UploadConcurrency;
125
131
  if (s3UploadConcurrencyValue !== undefined) {
126
132
  if (typeof s3UploadConcurrencyValue !== 'string' || !/^\d+$/.test(s3UploadConcurrencyValue) ||
@@ -213,6 +219,7 @@ export async function action(actionArgs) {
213
219
  computeAppDir,
214
220
  localMode,
215
221
  fastlyApiToken,
222
+ fastlyServiceId,
216
223
  s3AccessKeyId,
217
224
  s3SecretAccessKey,
218
225
  s3UploadConcurrency,
@@ -1 +1 @@
1
- {"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AASA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAuB/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAKnF,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,eAAO,MAAM,kBAAkB,EAAE,sBAwDhC,CAAC;AAGF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EACnB,iBAAiB,GAAE,MAAsC;IAY3D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,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AO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B7D"}
@@ -14,7 +14,7 @@ import { loadS3Credentials, } from '../util/s3-credentials.js';
14
14
  import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
15
15
  import { rootRelative, } from '../util/files.js';
16
16
  import { loadApiToken, } from '../util/api-token.js';
17
- import { readServiceId, } from '../util/fastly-toml.js';
17
+ import { loadServiceId, } from '../util/service-id.js';
18
18
  import { purgeSurrogateKey, } from '../util/purge.js';
19
19
  // The number of objects to upload at the same time. S3 accepts many parallel
20
20
  // requests, and each request mostly waits for the network. In a test with small
@@ -40,14 +40,17 @@ export const buildStoreProvider = async (config, context) => {
40
40
  throw new Error("❌ S3 Credentials not provided.\nProvide an access key ID and secret access key that have write access to the S3 or compatible storage.\nRefer to the README file and --help for additional information.");
41
41
  }
42
42
  console.log(`✔️ S3 Credentials: ${s3CredentialsResult.s3AccessKeyId.slice(0, 4)}${'*'.repeat(s3CredentialsResult.s3AccessKeyId.length - 4)} from '${s3CredentialsResult.source}'`);
43
- const fastlyTomlPath = path.resolve(context.computeAppDir, 'fastly.toml');
44
- const serviceId = readServiceId(fastlyTomlPath);
43
+ const serviceIdResult = loadServiceId({
44
+ commandLine: context.fastlyServiceId,
45
+ fastlyTomlPath: path.resolve(context.computeAppDir, 'fastly.toml'),
46
+ });
47
+ const serviceId = serviceIdResult?.serviceId;
45
48
  let apiToken = undefined;
46
- if (serviceId == null) {
47
- console.log(`- Service ID not found in fastly.toml, application may not have been deployed yet. Will skip purge step after publish.`);
49
+ if (serviceIdResult == null) {
50
+ console.log(`- Service ID not found (--fastly-service-id, fastly.toml, or FASTLY_SERVICE_ID). Will skip purge step after publish.`);
48
51
  }
49
52
  else {
50
- console.log(`✔️ Service ID from fastly.toml: ${serviceId}`);
53
+ console.log(`✔️ Service ID from ${serviceIdResult.source}: ${serviceIdResult.serviceId}`);
51
54
  const apiTokenResult = loadApiToken({ commandLine: context.fastlyApiToken });
52
55
  if (apiTokenResult == null) {
53
56
  throw new Error("❌ Fastly API Token not provided.\nSet the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
@@ -35,6 +35,7 @@ export type StorageProviderBuilderContext = {
35
35
  computeAppDir: string;
36
36
  localMode?: boolean;
37
37
  fastlyApiToken?: string;
38
+ fastlyServiceId?: string;
38
39
  s3AccessKeyId?: string;
39
40
  s3SecretAccessKey?: string;
40
41
  s3UploadConcurrency?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IA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C,QAAQ,CAAC,CAqCnB"}
@@ -2,8 +2,6 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- import { spawnSync } from 'node:child_process';
6
- import cli from '@fastly/cli';
7
5
  import { makeRetryable } from './retryable.js';
8
6
  export function loadApiToken(params) {
9
7
  let apiToken = null;
@@ -20,32 +18,6 @@ export function loadApiToken(params) {
20
18
  source = 'env';
21
19
  }
22
20
  }
23
- // Try fastly cli
24
- if (apiToken == null) {
25
- try {
26
- const { stdout, error, status } = spawnSync(cli, ['profile', 'token', '--quiet'], {
27
- encoding: 'utf-8',
28
- });
29
- if (status != null && status !== 0) {
30
- console.warn(`⚠️ Warning: 'fastly profile token' returned a non-zero status code.`);
31
- apiToken = null;
32
- }
33
- else if (error) {
34
- console.warn(`⚠️ Warning: 'fastly profile token' returned an error:`);
35
- console.warn(String(error));
36
- apiToken = null;
37
- }
38
- else {
39
- apiToken = stdout.trim();
40
- }
41
- }
42
- catch {
43
- apiToken = null;
44
- }
45
- if (apiToken != null) {
46
- source = 'fastly-profile-token';
47
- }
48
- }
49
21
  if (apiToken == null) {
50
22
  return null;
51
23
  }
@@ -0,0 +1,10 @@
1
+ export type LoadServiceIdResult = {
2
+ serviceId: string;
3
+ source: string;
4
+ };
5
+ export type LoadServiceIdParams = {
6
+ commandLine: unknown;
7
+ fastlyTomlPath: string;
8
+ };
9
+ export declare function loadServiceId(params: LoadServiceIdParams): LoadServiceIdResult | null;
10
+ //# sourceMappingURL=service-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-id.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/service-id.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAMF,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,GAAG,IAAI,CAmBrF"}
@@ -0,0 +1,26 @@
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 { readServiceId } from './fastly-toml.js';
7
+ // Finds the Fastly Service ID to purge after publishing. Checks, in order:
8
+ // 1. The command line (--fastly-service-id)
9
+ // 2. service_id in fastly.toml
10
+ // 3. The FASTLY_SERVICE_ID environment variable
11
+ export function loadServiceId(params) {
12
+ if (typeof params.commandLine === 'string' && params.commandLine.trim() !== '') {
13
+ return { serviceId: params.commandLine.trim(), source: 'commandline' };
14
+ }
15
+ if (fs.existsSync(params.fastlyTomlPath)) {
16
+ const serviceId = readServiceId(params.fastlyTomlPath);
17
+ if (serviceId != null) {
18
+ return { serviceId, source: 'fastly.toml' };
19
+ }
20
+ }
21
+ const envServiceId = process.env.FASTLY_SERVICE_ID?.trim();
22
+ if (envServiceId) {
23
+ return { serviceId: envServiceId, source: 'env' };
24
+ }
25
+ return null;
26
+ }
@@ -4,6 +4,7 @@ import { type ContentCompressionTypes } from '../../models/compression/index.js'
4
4
  import { type AssetEntry, type AssetEntryMap, type AssetVariantMetadata } from '../../models/assets/index.js';
5
5
  import { type StorageEntry, type StorageProvider } from '../storage/storage-provider.js';
6
6
  import { ServerTiming } from '../util/server-timing.js';
7
+ import { type ResponseCacheOptions } from './response-cache.js';
7
8
  type AssetVariant = {
8
9
  storageEntry: StorageEntry;
9
10
  } & AssetVariantMetadata;
@@ -23,11 +24,13 @@ export declare class PublisherServer {
23
24
  collectionNameHeader: string | null;
24
25
  serverTimingRequestHeader: string | null;
25
26
  serverTiming: ServerTiming | null;
27
+ responseCache: ResponseCacheOptions | null;
26
28
  settingsCached: PublisherServerConfigNormalized | null | undefined;
27
29
  assetEntryMapCache: AssetEntryMap | null | undefined;
28
30
  setActiveCollectionName(collectionName: string): void;
29
31
  setCollectionNameHeader(collectionHeader: string | null): void;
30
32
  setServerTimingRequestHeader(requestHeader: string | null): void;
33
+ setResponseCache(options: ResponseCacheOptions | null): void;
31
34
  beginRequest(request: Request): void;
32
35
  private timed;
33
36
  getServerConfig(): Promise<PublisherServerConfigNormalized | null>;
@@ -37,10 +40,14 @@ export declare class PublisherServer {
37
40
  findAcceptEncodingsGroups(request: Request): Promise<ContentCompressionTypes[][]>;
38
41
  testExtendedCache(pathname: string): Promise<boolean>;
39
42
  handlePreconditions(request: Request, asset: AssetEntry, responseHeaders: Headers): Response | null;
43
+ private handlePreconditionsForLastModified;
40
44
  loadAssetVariant(entry: AssetEntry, variant: ContentCompressionTypes | null): Promise<AssetVariant | null>;
41
45
  private findAssetVariantForAcceptEncodingsGroups;
42
46
  serveAsset(request: Request, asset: AssetEntry, init?: AssetInit): Promise<Response>;
47
+ serveCached(request: Request, keyPath: string, produce: (request: Request) => Promise<Response | null>): Promise<Response | null>;
48
+ private responseFromCache;
43
49
  serveRequest(request: Request): Promise<Response | null>;
50
+ private serveRequestFromStorage;
44
51
  }
45
52
  export {};
46
53
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EAErB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;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AS,GAAE,OAAe,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA2D1F,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;IASjF,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAcxC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI;IAMnG,OAAO,CAAC,kCAAkC;IA6D7B,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;YA8BzG,wCAAwC;IAyChD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IA4DpF,WAAW,CACf,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GACtD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA2D3B,OAAO,CAAC,iBAAiB;IAwBnB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;YAsBhD,uBAAuB;CAwDtC"}
@@ -2,6 +2,8 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
+ /// <reference types="@fastly/js-compute" />
6
+ import { CoreCache } from 'fastly:cache';
5
7
  import { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
6
8
  import { decodeIndexMetadata, } from '../../models/server/index.js';
7
9
  import { isExpired } from '../../models/time/index.js';
@@ -9,6 +11,7 @@ import { loadStorageProviderFromStaticPublishRc, } from '../storage/storage-prov
9
11
  import { checkIfModifiedSince, getIfModifiedSinceHeader } from './serve-preconditions/if-modified-since.js';
10
12
  import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if-none-match.js';
11
13
  import { ServerTiming } from '../util/server-timing.js';
14
+ import { CACHEABLE_STATUSES, buildCacheFillRequest, buildResponseCacheKey, decodeCachedResponseMetadata, encodeCachedResponseMetadata, parseAcceptEncodingGroups, } from './response-cache.js';
12
15
  export function buildHeadersSubset(responseHeaders, keys) {
13
16
  const resultHeaders = new Headers();
14
17
  for (const value of keys) {
@@ -45,6 +48,7 @@ export class PublisherServer {
45
48
  this.collectionNameHeader = 'X-Publisher-Server-Collection';
46
49
  this.serverTimingRequestHeader = null;
47
50
  this.serverTiming = null;
51
+ this.responseCache = null;
48
52
  }
49
53
  static fromStaticPublishRc(config) {
50
54
  const storeProvider = loadStorageProviderFromStaticPublishRc(config);
@@ -63,6 +67,14 @@ export class PublisherServer {
63
67
  setServerTimingRequestHeader(requestHeader) {
64
68
  this.serverTimingRequestHeader = requestHeader;
65
69
  }
70
+ // Cache whole responses with the Core Cache API, keyed by collection, path,
71
+ // and the client's Accept-Encoding. A cache hit does not read the settings,
72
+ // the index, or the file from storage. Entries have the surrogate key
73
+ // `<publishId>-<collectionName>`, which publish-content purges. null (the
74
+ // default) turns the cache off.
75
+ setResponseCache(options) {
76
+ this.responseCache = options;
77
+ }
66
78
  // Start handling a new request. serveRequest() calls this. If you call
67
79
  // getMatchingAsset() and serveAsset() directly, call this first.
68
80
  beginRequest(request) {
@@ -204,46 +216,7 @@ export class PublisherServer {
204
216
  if (serverConfig == null || serverConfig.allowedEncodings.length === 0) {
205
217
  return [];
206
218
  }
207
- const acceptEncodingHeader = request.headers.get('accept-encoding')?.trim() ?? '';
208
- if (acceptEncodingHeader == '') {
209
- return [];
210
- }
211
- const priorityMap = new Map;
212
- for (const headerValue of acceptEncodingHeader.trim().split(',')) {
213
- let [encodingValue, qValueStr] = headerValue.trim().split(';');
214
- encodingValue = encodingValue.trim();
215
- if (!serverConfig.allowedEncodings.includes(encodingValue)) {
216
- continue;
217
- }
218
- let qValue; // q value multiplied by 1000
219
- if (qValueStr == null || !qValueStr.startsWith('q=')) {
220
- // use default of 1.0
221
- qValue = 1000;
222
- }
223
- else {
224
- qValueStr = qValueStr.slice(2); // remove the q=
225
- qValue = parseFloat(qValueStr);
226
- if (Number.isNaN(qValue) || qValue > 1) {
227
- qValue = 1;
228
- }
229
- if (qValue < 0) {
230
- qValue = 0;
231
- }
232
- // q values can have up to 3 decimal digits
233
- qValue = Math.floor(qValue * 1000);
234
- }
235
- let typesForQValue = priorityMap.get(qValue);
236
- if (typesForQValue == null) {
237
- typesForQValue = [];
238
- priorityMap.set(qValue, typesForQValue);
239
- }
240
- typesForQValue.push(encodingValue);
241
- }
242
- // Sort keys, larger numbers to come first
243
- const keysSorted = [...priorityMap.keys()]
244
- .sort((qValueA, qValueB) => qValueB - qValueA);
245
- return keysSorted
246
- .map(qValue => priorityMap.get(qValue));
219
+ return parseAcceptEncodingGroups(request.headers.get('accept-encoding') ?? '', serverConfig.allowedEncodings);
247
220
  }
248
221
  async testExtendedCache(pathname) {
249
222
  const staticItems = await this.getStaticItems();
@@ -259,6 +232,11 @@ export class PublisherServer {
259
232
  });
260
233
  }
261
234
  handlePreconditions(request, asset, responseHeaders) {
235
+ return this.handlePreconditionsForLastModified(request, asset.lastModifiedTime, responseHeaders);
236
+ }
237
+ // lastModifiedTime is in seconds since the epoch, as in AssetEntry. A cached
238
+ // response has its headers, but not its AssetEntry.
239
+ handlePreconditionsForLastModified(request, lastModifiedTime, responseHeaders) {
262
240
  // Handle preconditions according to https://httpwg.org/specs/rfc9110.html#rfc.section.13.2.2
263
241
  // A recipient cache or origin server MUST evaluate the request preconditions defined by this specification in the following order:
264
242
  // 1. When recipient is the origin server and If-Match is present, evaluate the If-Match precondition:
@@ -295,7 +273,7 @@ export class PublisherServer {
295
273
  // For us, method is always GET or HEAD here.
296
274
  const headerValue = getIfModifiedSinceHeader(request);
297
275
  if (headerValue != null) {
298
- const result = checkIfModifiedSince(asset.lastModifiedTime, headerValue);
276
+ const result = checkIfModifiedSince(lastModifiedTime, headerValue);
299
277
  if (!result) {
300
278
  return new Response(null, {
301
279
  status: 304,
@@ -412,6 +390,88 @@ export class PublisherServer {
412
390
  headers,
413
391
  });
414
392
  }
393
+ // Serve a response through the response cache (see setResponseCache()).
394
+ // keyPath identifies the response in the active collection. Include in it
395
+ // anything other than the path and the Accept-Encoding that changes the response.
396
+ // On a miss, produce() is called with a GET request that has no conditional or
397
+ // range headers, and its result is cached if it is a 200 or 404 response, or
398
+ // null (not found). Conditional requests and HEAD are then answered from the
399
+ // cached response. If the cache is off, produce() gets the original request.
400
+ async serveCached(request, keyPath, produce) {
401
+ if (this.responseCache == null) {
402
+ return produce(request);
403
+ }
404
+ const key = buildResponseCacheKey(this.publishId, this.activeCollectionName, keyPath, request);
405
+ const lookupStart = performance.now();
406
+ const entry = CoreCache.transactionLookup(key);
407
+ const state = entry.state();
408
+ if (!state.mustInsertOrUpdate()) {
409
+ const metadata = state.found() && state.usable() ? decodeCachedResponseMetadata(entry.userMetadata()) : null;
410
+ if (metadata != null) {
411
+ this.serverTiming?.add('cache', performance.now() - lookupStart, 'hit');
412
+ return this.responseFromCache(request, metadata, entry.body());
413
+ }
414
+ // Not usable, and another request is not filling it for us: serve without the cache.
415
+ this.serverTiming?.add('cache', performance.now() - lookupStart, 'bypass');
416
+ return produce(request);
417
+ }
418
+ // This request must fill the entry (a miss, or a stale entry after a soft purge).
419
+ this.serverTiming?.add('cache', performance.now() - lookupStart, 'miss');
420
+ let response;
421
+ try {
422
+ response = await produce(buildCacheFillRequest(request));
423
+ }
424
+ catch (err) {
425
+ entry.cancel();
426
+ throw err;
427
+ }
428
+ let metadata;
429
+ let body;
430
+ if (response == null) {
431
+ metadata = { notFound: true };
432
+ body = new ArrayBuffer(0);
433
+ }
434
+ else if (CACHEABLE_STATUSES.includes(response.status)) {
435
+ const headers = new Headers(response.headers);
436
+ // Server-Timing describes one request, so it is not stored.
437
+ headers.delete('Server-Timing');
438
+ metadata = { status: response.status, headers: [...headers] };
439
+ body = await response.arrayBuffer();
440
+ }
441
+ else {
442
+ entry.cancel();
443
+ return response;
444
+ }
445
+ const writer = entry.insert({
446
+ maxAge: this.responseCache.maxAge,
447
+ surrogateKeys: [`${this.publishId}-${this.activeCollectionName}`],
448
+ userMetadata: encodeCachedResponseMetadata(metadata),
449
+ length: body.byteLength,
450
+ });
451
+ writer.append(body);
452
+ writer.close();
453
+ return this.responseFromCache(request, metadata, body);
454
+ }
455
+ responseFromCache(request, metadata, body) {
456
+ if (metadata.notFound) {
457
+ return null;
458
+ }
459
+ const headers = new Headers(metadata.headers);
460
+ if (this.serverTiming != null) {
461
+ headers.append('Server-Timing', this.serverTiming.toHeaderValue());
462
+ }
463
+ const lastModified = headers.get('Last-Modified');
464
+ const lastModifiedMs = lastModified != null ? Date.parse(lastModified) : NaN;
465
+ const lastModifiedTime = Number.isNaN(lastModifiedMs) ? 0 : Math.floor(lastModifiedMs / 1000);
466
+ const preconditionResponse = this.handlePreconditionsForLastModified(request, lastModifiedTime, headers);
467
+ if (preconditionResponse != null) {
468
+ return preconditionResponse;
469
+ }
470
+ return new Response(request.method === 'HEAD' ? null : body, {
471
+ status: metadata.status,
472
+ headers,
473
+ });
474
+ }
415
475
  async serveRequest(request) {
416
476
  this.beginRequest(request);
417
477
  // Only handle GET and HEAD
@@ -424,6 +484,11 @@ export class PublisherServer {
424
484
  if (pathname === '/healthz') {
425
485
  return new Response("OK", { status: 200 });
426
486
  }
487
+ // The fallback pages (SPA, not found) depend on whether the client accepts HTML.
488
+ const keyPath = requestAcceptsTextHtml(request) ? pathname : `${pathname}|no-html`;
489
+ return this.serveCached(request, keyPath, (fillRequest) => this.serveRequestFromStorage(fillRequest, pathname));
490
+ }
491
+ async serveRequestFromStorage(request, pathname) {
427
492
  const serverConfig = await this.getServerConfig();
428
493
  if (serverConfig == null) {
429
494
  return new Response(`Settings not found. You may need to publish your application.`, {
@@ -0,0 +1,19 @@
1
+ import { type ContentCompressionTypes } from '../../models/compression/index.js';
2
+ export type ResponseCacheOptions = {
3
+ maxAge: number;
4
+ };
5
+ export type CachedResponseMetadata = {
6
+ notFound: true;
7
+ } | {
8
+ notFound?: false;
9
+ status: number;
10
+ headers: [string, string][];
11
+ };
12
+ export declare const CACHEABLE_STATUSES: Readonly<number[]>;
13
+ export declare function parseAcceptEncodingGroups(headerValue: string, allowedEncodings: Readonly<ContentCompressionTypes[]>): ContentCompressionTypes[][];
14
+ export declare function acceptEncodingCacheKeyPart(request: Request): string;
15
+ export declare function buildResponseCacheKey(publishId: string, collectionName: string, keyPath: string, request: Request): string;
16
+ export declare function buildCacheFillRequest(request: Request): Request;
17
+ export declare function encodeCachedResponseMetadata(metadata: CachedResponseMetadata): string;
18
+ export declare function decodeCachedResponseMetadata(buffer: ArrayBuffer): CachedResponseMetadata | null;
19
+ //# sourceMappingURL=response-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-cache.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/response-cache.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,uBAAuB,EAE7B,MAAM,mCAAmC,CAAC;AAE3C,MAAM,MAAM,oBAAoB,GAAG;IAIjC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAIF,MAAM,MAAM,sBAAsB,GAC9B;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAClB;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;CAAE,CAAC;AAItE,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAgB,CAAC;AAgBnE,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,QAAQ,CAAC,uBAAuB,EAAE,CAAC,GACpD,uBAAuB,EAAE,EAAE,CA2C7B;AAOD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAQnE;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,UAGjB;AAID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAM/D;AAED,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,sBAAsB,GAAG,MAAM,CAErF;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,WAAW,GAAG,sBAAsB,GAAG,IAAI,CAa/F"}
@@ -0,0 +1,106 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { compressionTypes, } from '../../models/compression/index.js';
6
+ // Statuses that serveAsset() produces for a found file or a not-found page.
7
+ // Anything else (for example, a 500 when the settings are missing) is not cached.
8
+ export const CACHEABLE_STATUSES = [200, 404];
9
+ // Request headers that make a response depend on the client's cached copy.
10
+ // The response that is stored is always the full one.
11
+ const CONDITIONAL_REQUEST_HEADERS = [
12
+ 'If-Match',
13
+ 'If-None-Match',
14
+ 'If-Modified-Since',
15
+ 'If-Unmodified-Since',
16
+ 'If-Range',
17
+ 'Range',
18
+ ];
19
+ // Parses an Accept-Encoding header value into groups of the allowed encodings
20
+ // that have the same q value, highest first. For example, with both br and
21
+ // gzip allowed, 'br;q=1, gzip;q=0.5' gives [['br'], ['gzip']].
22
+ export function parseAcceptEncodingGroups(headerValue, allowedEncodings) {
23
+ const trimmed = headerValue.trim();
24
+ if (trimmed === '' || allowedEncodings.length === 0) {
25
+ return [];
26
+ }
27
+ const priorityMap = new Map;
28
+ for (const item of trimmed.split(',')) {
29
+ let [encodingValue, qValueStr] = item.trim().split(';');
30
+ encodingValue = encodingValue.trim();
31
+ if (!allowedEncodings.includes(encodingValue)) {
32
+ continue;
33
+ }
34
+ let qValue; // q value multiplied by 1000
35
+ if (qValueStr == null || !qValueStr.startsWith('q=')) {
36
+ // use default of 1.0
37
+ qValue = 1000;
38
+ }
39
+ else {
40
+ qValueStr = qValueStr.slice(2); // remove the q=
41
+ qValue = parseFloat(qValueStr);
42
+ if (Number.isNaN(qValue) || qValue > 1) {
43
+ qValue = 1;
44
+ }
45
+ if (qValue < 0) {
46
+ qValue = 0;
47
+ }
48
+ // q values can have up to 3 decimal digits
49
+ qValue = Math.floor(qValue * 1000);
50
+ }
51
+ let typesForQValue = priorityMap.get(qValue);
52
+ if (typesForQValue == null) {
53
+ typesForQValue = [];
54
+ priorityMap.set(qValue, typesForQValue);
55
+ }
56
+ typesForQValue.push(encodingValue);
57
+ }
58
+ // Sort keys, larger numbers to come first
59
+ return [...priorityMap.keys()]
60
+ .sort((qValueA, qValueB) => qValueB - qValueA)
61
+ .map(qValue => priorityMap.get(qValue));
62
+ }
63
+ // Normalizes the request's Accept-Encoding into a short string for the cache
64
+ // key, using every encoding that the publisher can produce. The collection's
65
+ // allowedEncodings is left out on purpose: it would need the settings, and it
66
+ // only changes when the collection is published again, which purges the cache.
67
+ // For example, 'gzip, deflate, br' gives 'br+gzip'.
68
+ export function acceptEncodingCacheKeyPart(request) {
69
+ const groups = parseAcceptEncodingGroups(request.headers.get('Accept-Encoding') ?? '', compressionTypes);
70
+ if (groups.length === 0) {
71
+ return 'identity';
72
+ }
73
+ return groups
74
+ .map(group => [...group].sort().join('+'))
75
+ .join('>');
76
+ }
77
+ export function buildResponseCacheKey(publishId, collectionName, keyPath, request) {
78
+ return `${publishId}_response_${collectionName}_${acceptEncodingCacheKeyPart(request)}_${keyPath}`;
79
+ }
80
+ // The request used to produce a response for the cache: always a GET, without
81
+ // conditional or range headers, so that the stored response is the full one.
82
+ export function buildCacheFillRequest(request) {
83
+ const headers = new Headers(request.headers);
84
+ for (const name of CONDITIONAL_REQUEST_HEADERS) {
85
+ headers.delete(name);
86
+ }
87
+ return new Request(request.url, { method: 'GET', headers });
88
+ }
89
+ export function encodeCachedResponseMetadata(metadata) {
90
+ return JSON.stringify(metadata);
91
+ }
92
+ export function decodeCachedResponseMetadata(buffer) {
93
+ try {
94
+ const value = JSON.parse(new TextDecoder().decode(buffer));
95
+ if (value?.notFound === true) {
96
+ return { notFound: true };
97
+ }
98
+ if (typeof value?.status === 'number' && Array.isArray(value.headers)) {
99
+ return { status: value.status, headers: value.headers };
100
+ }
101
+ }
102
+ catch {
103
+ // Not valid JSON: treat the entry as a miss.
104
+ }
105
+ return null;
106
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fastly/compute-js-static-publish",
3
3
  "type": "module",
4
- "version": "8.0.0-beta.14",
4
+ "version": "8.0.0-beta.16",
5
5
  "description": "Static Publisher for Fastly Compute JavaScript",
6
6
  "main": "build/index.js",
7
7
  "exports": {
@@ -41,7 +41,6 @@
41
41
  "homepage": "https://github.com/fastly/compute-js-static-publish#readme",
42
42
  "dependencies": {
43
43
  "@aws-sdk/client-s3": "3.888.0",
44
- "@fastly/cli": "^16.0.0",
45
44
  "command-line-args": "^5.2.1",
46
45
  "glob-to-regexp": "^0.4.1",
47
46
  "toml": "^3.0.0"