@fastly/compute-js-static-publish 8.0.0-rc.2 → 8.0.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 (58) hide show
  1. package/DOCUMENTATION.md +1227 -0
  2. package/README.md +9 -2
  3. package/README.short.md +9 -2
  4. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  5. package/build/cli/cli/commands/manage/clean.js +1 -0
  6. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  7. package/build/cli/cli/commands/manage/collections/delete.js +39 -2
  8. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  9. package/build/cli/cli/commands/manage/collections/index.js +1 -0
  10. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  11. package/build/cli/cli/commands/manage/collections/list.js +10 -1
  12. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  13. package/build/cli/cli/commands/manage/collections/promote.js +1 -0
  14. package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
  15. package/build/cli/cli/commands/manage/collections/update-expiration.js +1 -0
  16. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  17. package/build/cli/cli/commands/manage/index.js +1 -0
  18. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  19. package/build/cli/cli/commands/manage/publish-content.js +72 -76
  20. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  21. package/build/cli/cli/commands/scaffold/index.js +39 -18
  22. package/build/cli/cli/storage/kv-store-provider.d.ts +1 -1
  23. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  24. package/build/cli/cli/storage/kv-store-provider.js +8 -5
  25. package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
  26. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  27. package/build/cli/cli/storage/s3-storage-provider.js +12 -6
  28. package/build/cli/cli/storage/storage-provider.d.ts +1 -0
  29. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  30. package/build/cli/cli/util/api-token.d.ts +2 -1
  31. package/build/cli/cli/util/api-token.d.ts.map +1 -1
  32. package/build/cli/cli/util/api-token.js +38 -3
  33. package/build/cli/cli/util/progress.d.ts +11 -0
  34. package/build/cli/cli/util/progress.d.ts.map +1 -0
  35. package/build/cli/cli/util/progress.js +32 -0
  36. package/build/cli/cli/util/purge.d.ts +10 -1
  37. package/build/cli/cli/util/purge.d.ts.map +1 -1
  38. package/build/cli/cli/util/purge.js +31 -8
  39. package/build/cli/cli/util/service-id.js +1 -1
  40. package/build/cli/cli/util/variants.d.ts +7 -0
  41. package/build/cli/cli/util/variants.d.ts.map +1 -1
  42. package/build/cli/cli/util/variants.js +17 -0
  43. package/build/cli/models/server/index.d.ts +4 -0
  44. package/build/cli/models/server/index.d.ts.map +1 -1
  45. package/build/cli/models/server/index.js +34 -1
  46. package/build/server/models/server/index.d.ts +4 -0
  47. package/build/server/models/server/index.d.ts.map +1 -1
  48. package/build/server/models/server/index.js +34 -1
  49. package/build/server/server/publisher-server/index.d.ts +1 -1
  50. package/build/server/server/publisher-server/index.d.ts.map +1 -1
  51. package/build/server/server/publisher-server/index.js +85 -53
  52. package/build/server/server/publisher-server/response-cache.d.ts +13 -0
  53. package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
  54. package/build/server/server/publisher-server/response-cache.js +54 -0
  55. package/build/server/server/util/body-length.d.ts +5 -0
  56. package/build/server/server/util/body-length.d.ts.map +1 -0
  57. package/build/server/server/util/body-length.js +63 -0
  58. package/package.json +5 -4
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACL,KAAK,gBAAgB,EAMtB,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,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UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAYV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBvF,aAAa,CAAC,OAAO,EAAE,yBAAyB,EAAE,EAAE,OAAO,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA4C5F,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,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;IAqBhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAIzC;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,gBAAgB,gBAuB/B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
@@ -7,6 +7,7 @@ import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
7
7
  import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
8
8
  import { FetchError, loadApiToken, } from '../util/api-token.js';
9
9
  import { rootRelative, } from '../util/files.js';
10
+ import { ProgressLog } from '../util/progress.js';
10
11
  import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, kvStoreSubmitBatch, } from '../util/kv-store.js';
11
12
  import { applyKVStoreEntriesChunks, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
12
13
  import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
@@ -55,7 +56,7 @@ export class KvStoreProvider {
55
56
  await kvStoreDeleteEntry(this.fastlyApiContext, this.kvStoreName, key);
56
57
  }
57
58
  async applyBatch(batch, options = {}) {
58
- const { existingKeys } = options;
59
+ const { existingKeys, verbose = false } = options;
59
60
  console.log(`🍪 Chunking large files...`);
60
61
  await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
61
62
  console.log(`✅ Large files have been chunked.`);
@@ -65,15 +66,16 @@ export class KvStoreProvider {
65
66
  console.log(` | ${batch.storageProviderBatchEntries.length - toWrite.length} chunk(s) already present in the KV Store.`);
66
67
  }
67
68
  console.log(`📤 Uploading ${toWrite.length} entries to KV Store.`);
68
- await this.uploadEntries(toWrite);
69
+ await this.uploadEntries(toWrite, verbose);
69
70
  console.log(`✅ Uploaded entries to KV Store.`);
70
71
  }
71
- async uploadEntries(entries) {
72
+ async uploadEntries(entries, verbose = false) {
72
73
  const { batches, oversized } = packNdjsonBatches(entries);
74
+ const progress = new ProgressLog('Entries uploaded', verbose, entries.length);
73
75
  await this.doConcurrentParallel(oversized, async ({ filePath, metadataJson }, key) => {
74
76
  const fileBytes = fs.readFileSync(filePath);
75
77
  await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
76
- console.log(` 🌐 Submitted large asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
78
+ progress.add(1, () => ` 🌐 Submitted large asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
77
79
  }, 12, true);
78
80
  await this.doConcurrentParallel(batches, async (batch, key) => {
79
81
  const lines = batch.entries.map(ndjsonLineForBatchEntry);
@@ -82,12 +84,13 @@ export class KvStoreProvider {
82
84
  // Keep only the entries that failed. The retry submits only these entries.
83
85
  const failedKeys = new Set(failures.map(f => f.key));
84
86
  const submittedCount = batch.entries.length;
87
+ progress.add(submittedCount - failures.length, () => ` 🌐 Submitted ${submittedCount - failures.length} of ${submittedCount} entries to KV Store ("${key}").`);
85
88
  batch.entries = batch.entries.filter(entry => failedKeys.has(entry.key));
86
89
  const shown = failures.slice(0, 5).map(f => `${f.key} (${f.code ?? 'unknown'}: ${f.reason ?? 'unknown'})`).join(', ');
87
90
  const more = failures.length > 5 ? `, and ${failures.length - 5} more` : '';
88
91
  throw makeRetryable(new Error(`${failures.length} of ${submittedCount} entries failed: ${shown}${more}`));
89
92
  }
90
- console.log(` 🌐 Submitted ${batch.entries.length} entries to KV Store ("${key}").`);
93
+ progress.add(batch.entries.length, () => ` 🌐 Submitted ${batch.entries.length} entries to KV Store ("${key}").`);
91
94
  }, 12, true);
92
95
  }
93
96
  async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
@@ -3,6 +3,7 @@ import { type Command, type HttpHandlerOptions } from '@aws-sdk/types';
3
3
  import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
4
4
  type CommandOutput<C> = C extends Command<any, any, any, infer O, any> ? O : never;
5
5
  export declare const DEFAULT_S3_UPLOAD_CONCURRENCY = 64;
6
+ export declare const S3_LOCAL_MODE_ERROR = "--local is available only in KV Store mode. In S3 mode, the commands always use the bucket in static-publish.rc.js.";
6
7
  export declare const buildStoreProvider: StorageProviderBuilder;
7
8
  export declare class S3StorageProvider implements StorageProvider {
8
9
  constructor(s3Region: string, accessKeyId: string, secretAccessKey: string, s3Bucket: string, s3Endpoint?: string, uploadConcurrency?: number);
@@ -1 +1 @@
1
- {"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAA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AAY,GAAG,IAAI,CAAC;IA6B1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAwB9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAaV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BvF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,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;CAI1C"}
@@ -12,17 +12,22 @@ import { entriesToUpload } from '../util/kv-store-items.js';
12
12
  import { loadS3Credentials, } from '../util/s3-credentials.js';
13
13
  import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
14
14
  import { rootRelative, } from '../util/files.js';
15
+ import { ProgressLog } from '../util/progress.js';
15
16
  // The number of objects to upload at the same time. S3 accepts many parallel
16
17
  // requests, and each request mostly waits for the network. In a test with small
17
18
  // objects, 64 was approximately 4 times faster than 12.
18
19
  export const DEFAULT_S3_UPLOAD_CONCURRENCY = 64;
20
+ export const S3_LOCAL_MODE_ERROR = '--local is available only in KV Store mode. In S3 mode, the commands always use the bucket in static-publish.rc.js.';
19
21
  export const buildStoreProvider = async (config, context) => {
20
- if (isS3StorageConfigRc(config)) {
21
- console.log(` Working on S3 (or compatible) storage (BETA)...`);
22
- }
23
- else {
22
+ if (!isS3StorageConfigRc(config)) {
24
23
  return null;
25
24
  }
25
+ // There is no local simulation of S3 storage. Stop before the command
26
+ // connects to the bucket.
27
+ if (context.localMode) {
28
+ throw new Error(S3_LOCAL_MODE_ERROR);
29
+ }
30
+ console.log(` Working on S3 (or compatible) storage (BETA)...`);
26
31
  const { region, bucket, endpoint, } = getS3StorageConfigFromRc(config);
27
32
  console.log(` | Using S3 storage (BETA)`);
28
33
  console.log(` Region : ${region}`);
@@ -173,17 +178,18 @@ export class S3StorageProvider {
173
178
  await this.sendS3ClientCommand(command);
174
179
  }
175
180
  async applyBatch(batch, options = {}) {
176
- const { existingKeys } = options;
181
+ const { existingKeys, verbose = false } = options;
177
182
  let toWrite = batch.storageProviderBatchEntries;
178
183
  if (existingKeys != null) {
179
184
  toWrite = entriesToUpload(toWrite, existingKeys);
180
185
  }
181
186
  console.log(`📤 Uploading ${toWrite.length} entries to S3 storage (${this.uploadConcurrency} at a time).`);
187
+ const progress = new ProgressLog('Entries uploaded', verbose, toWrite.length);
182
188
  await this.doConcurrentParallel(toWrite, async ({ filePath, metadataJson }, key) => {
183
189
  // const fileStream = fs.createReadStream(filePath);
184
190
  const fileData = fs.readFileSync(filePath);
185
191
  await this.submitStorageEntry(key, filePath, fileData, metadataJson);
186
- console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
192
+ progress.add(1, () => ` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
187
193
  }, this.uploadConcurrency, true);
188
194
  console.log(`✅ Uploaded entries to S3 storage.`);
189
195
  }
@@ -24,6 +24,7 @@ export type StorageProviderBatchEntry = {
24
24
  };
25
25
  export type ApplyBatchOptions = {
26
26
  existingKeys?: Set<string>;
27
+ verbose?: boolean;
27
28
  };
28
29
  export declare class StorageProviderBatch {
29
30
  constructor();
@@ -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,IAAI,CAAC,CAAC;IAC3D,kBAAkB,CAChB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,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E,6BAA6B,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,CAAC;AAQlI,wBAAsB,yBAAyB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAQ1H;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H"}
@@ -10,8 +10,9 @@ export type LoadApiParams = {
10
10
  };
11
11
  export declare function loadApiToken(params: LoadApiParams): LoadApiTokenResult | null;
12
12
  export declare class FetchError extends Error {
13
- constructor(message: string, status: number);
13
+ constructor(message: string, status: number, detail?: string);
14
14
  status: number;
15
+ detail?: string;
15
16
  }
16
17
  export declare function callFastlyApi(fastlyApiContext: FastlyApiContext, endpoint: string, operationName: string, queryParams?: URLSearchParams | null, requestInit?: RequestInit): Promise<Response>;
17
18
  //# sourceMappingURL=api-token.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAqCnB"}
1
+ {"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAM5D,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}
@@ -34,10 +34,11 @@ const RETRYABLE_STATUS_CODES = [
34
34
  504, // Gateway Timeout
35
35
  ];
36
36
  export class FetchError extends Error {
37
- constructor(message, status) {
37
+ constructor(message, status, detail) {
38
38
  super(message);
39
39
  this.name = 'FetchError';
40
40
  this.status = status;
41
+ this.detail = detail;
41
42
  }
42
43
  }
43
44
  function isReadableStream(data) {
@@ -74,10 +75,44 @@ export async function callFastlyApi(fastlyApiContext, endpoint, operationName, q
74
75
  }
75
76
  }
76
77
  if (!response.ok) {
78
+ const detail = await readApiErrorDetail(response);
79
+ const status = `${response.status}${detail != null ? ` ${detail}` : ''}`;
77
80
  if (!RETRYABLE_STATUS_CODES.includes(response.status)) {
78
- throw new FetchError(`${operationName} failed: ${response.status}`, response.status);
81
+ throw new FetchError(`${operationName} failed: ${status}`, response.status, detail);
79
82
  }
80
- throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${response.status}`, response.status));
83
+ throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${status}`, response.status, detail));
81
84
  }
82
85
  return response;
83
86
  }
87
+ // The Content-Type of an error response tells which fields describe the error:
88
+ // - application/json: the Fastly API fields msg and detail, for example
89
+ // {"msg":"Record not found","detail":"Cannot find service"}.
90
+ // - application/problem+json (RFC 9457): the fields title and detail.
91
+ // - Other types, or JSON that is not valid: the start of the text.
92
+ async function readApiErrorDetail(response) {
93
+ let text;
94
+ try {
95
+ text = (await response.text()).trim();
96
+ }
97
+ catch {
98
+ return undefined;
99
+ }
100
+ const mediaType = response.headers.get('content-type')?.split(';')[0].trim().toLowerCase();
101
+ const fields = mediaType === 'application/json' ? ['msg', 'detail'] :
102
+ mediaType === 'application/problem+json' ? ['title', 'detail'] :
103
+ null;
104
+ if (fields != null) {
105
+ let json;
106
+ try {
107
+ json = JSON.parse(text);
108
+ }
109
+ catch {
110
+ json = undefined;
111
+ }
112
+ if (json !== undefined) {
113
+ const parts = fields.map(field => json?.[field]).filter(x => typeof x === 'string' && x !== '');
114
+ return parts.length > 0 ? parts.join(': ') : undefined;
115
+ }
116
+ }
117
+ return text !== '' ? text.slice(0, 200) : undefined;
118
+ }
@@ -0,0 +1,11 @@
1
+ export declare const PROGRESS_INTERVAL = 1000;
2
+ export declare class ProgressLog {
3
+ private readonly label;
4
+ private readonly verbose;
5
+ private readonly total?;
6
+ private done;
7
+ private nextReport;
8
+ constructor(label: string, verbose: boolean, total?: number | undefined);
9
+ add(count: number, message: () => string): void;
10
+ }
11
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/progress.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAKtC,qBAAa,WAAW;IAKpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IANzB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,UAAU,CAAqB;gBAGpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,YAAA;IAIjC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM;CAczC"}
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ export const PROGRESS_INTERVAL = 1000;
6
+ // Logs the progress of a loop over many items. With verbose, it logs a line
7
+ // for each call. Else, it logs one line each time the count passes another
8
+ // PROGRESS_INTERVAL items, so that a large site does not make a large log.
9
+ export class ProgressLog {
10
+ constructor(label, verbose, total) {
11
+ this.label = label;
12
+ this.verbose = verbose;
13
+ this.total = total;
14
+ this.done = 0;
15
+ this.nextReport = PROGRESS_INTERVAL;
16
+ }
17
+ // Records count items. The message is made only if it is logged.
18
+ add(count, message) {
19
+ this.done += count;
20
+ if (this.verbose) {
21
+ console.log(message());
22
+ return;
23
+ }
24
+ if (this.done < this.nextReport || (this.total != null && this.done >= this.total)) {
25
+ return;
26
+ }
27
+ console.log(` | ${this.label}: ${this.done}${this.total != null ? ` of ${this.total}` : ''}`);
28
+ while (this.nextReport <= this.done) {
29
+ this.nextReport += PROGRESS_INTERVAL;
30
+ }
31
+ }
32
+ }
@@ -15,5 +15,14 @@ export type LoadPurgeTargetParams = {
15
15
  purgeEnvironments: unknown;
16
16
  };
17
17
  export declare function loadPurgeTarget(params: LoadPurgeTargetParams): PurgeTarget | null;
18
- export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean, environment?: PurgeEnvironment): Promise<boolean>;
18
+ export type PurgeOutcome = {
19
+ result: 'purged';
20
+ } | {
21
+ result: 'not-staged';
22
+ } | {
23
+ result: 'failed';
24
+ reason: string;
25
+ };
26
+ export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean, environment?: PurgeEnvironment): Promise<PurgeOutcome>;
27
+ export declare function purgeCollection(purgeTarget: PurgeTarget, publishId: string, collectionName: string): Promise<void>;
19
28
  //# sourceMappingURL=purge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"AAOA,OAAO,EAAiB,KAAK,gBAAgB,EAA4B,MAAM,gBAAgB,CAAC;AAGhG,eAAO,MAAM,iBAAiB,oCAAuC,CAAC;AACtE,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAIhE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAkB1E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B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,gBAAgB,EAClC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,OAAe,EAC1B,WAAW,GAAE,gBAA+B,GAC3C,OAAO,CAAC,YAAY,CAAC,CA8BvB;AAID,wBAAsB,eAAe,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iBAiBxG"}
@@ -27,15 +27,15 @@ export function parsePurgeEnvironments(values) {
27
27
  }
28
28
  return result.length > 0 ? result : ['production'];
29
29
  }
30
- // Finds the service to purge after publishing, so that it stops serving cached
31
- // copies of the collection. Returns null, and logs why, if the purge is skipped.
32
- // Throws if a Service ID is found but an API token is not, so that this fails
33
- // before anything is uploaded.
30
+ // Finds the service to purge after a change to a collection, so that it stops
31
+ // serving cached copies of the collection. Returns null, and logs why, if the
32
+ // purge is skipped. Throws if a Service ID is found but an API token is not, so
33
+ // that a command can fail before it changes storage.
34
34
  export function loadPurgeTarget(params) {
35
35
  // Check the option even when the purge is skipped, so that a typo is reported.
36
36
  const environments = parsePurgeEnvironments(params.purgeEnvironments);
37
37
  if (params.localMode) {
38
- console.log(`- Local mode: will skip purge step after publish.`);
38
+ console.log(`- Local mode: will skip the purge.`);
39
39
  return null;
40
40
  }
41
41
  const serviceIdResult = loadServiceId({
@@ -43,7 +43,7 @@ export function loadPurgeTarget(params) {
43
43
  fastlyTomlPath: path.resolve(params.computeAppDir, 'fastly.toml'),
44
44
  });
45
45
  if (serviceIdResult == null) {
46
- console.log(`- Service ID not found (--fastly-service-id, FASTLY_SERVICE_ID, or fastly.toml). Will skip purge step after publish.`);
46
+ console.log(`- Service ID not found (--fastly-service-id, FASTLY_SERVICE_ID, or fastly.toml). Will skip the purge.`);
47
47
  return null;
48
48
  }
49
49
  console.log(`✔️ Service ID from ${serviceIdResult.source}: ${serviceIdResult.serviceId}`);
@@ -75,9 +75,32 @@ export async function purgeSurrogateKey(fastlyApiContext, fastlyServiceId, surro
75
75
  }
76
76
  catch (err) {
77
77
  if (err instanceof FetchError) {
78
- return false;
78
+ if (environment === 'staging' && err.status === 404) {
79
+ return { result: 'not-staged' };
80
+ }
81
+ return { result: 'failed', reason: `${err.status}${err.detail != null ? ` ${err.detail}` : ''}` };
79
82
  }
80
83
  throw err;
81
84
  }
82
- return true;
85
+ return { result: 'purged' };
86
+ }
87
+ // Purges the cached responses of a collection in each environment of the purge
88
+ // target. A failed purge is a warning, because the change to storage is done.
89
+ export async function purgeCollection(purgeTarget, publishId, collectionName) {
90
+ const surrogateKey = `${publishId}-${collectionName}`;
91
+ for (const environment of purgeTarget.environments) {
92
+ console.log(`Purging surrogate key [${surrogateKey}] on service [${purgeTarget.serviceId}] (${environment})...`);
93
+ const outcome = await purgeSurrogateKey(purgeTarget.fastlyApiContext, purgeTarget.serviceId, surrogateKey, true, environment);
94
+ switch (outcome.result) {
95
+ case 'purged':
96
+ console.log('Purged');
97
+ break;
98
+ case 'not-staged':
99
+ console.log(`Nothing purged (${environment}): the service has no staged version, or the service ID is not correct.`);
100
+ break;
101
+ case 'failed':
102
+ console.warn(`⚠️ Warning: Failed purging (${environment}): ${outcome.reason}. Cached copies may be served until they expire.`);
103
+ break;
104
+ }
105
+ }
83
106
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import fs from 'node:fs';
6
6
  import { readServiceId } from './fastly-toml.js';
7
- // Finds the Fastly Service ID to purge after publishing. Checks, in order:
7
+ // Finds the Fastly Service ID to purge after a change to a collection. Checks, in order:
8
8
  // 1. The command line (--fastly-service-id)
9
9
  // 2. The FASTLY_SERVICE_ID environment variable
10
10
  // 3. service_id in fastly.toml
@@ -1,5 +1,12 @@
1
1
  import { type ContentCompressionTypes } from '../../models/compression/index.js';
2
2
  import { type CompressOptions } from '../compression/index.js';
3
3
  export type Variants = 'original' | ContentCompressionTypes;
4
+ export declare class OncePerKey<T> {
5
+ private readonly promises;
6
+ run(key: string, fn: () => Promise<T>): {
7
+ promise: Promise<T>;
8
+ first: boolean;
9
+ };
10
+ }
4
11
  export declare function ensureVariantFileExists(variantFilePath: string, variant: Variants, file: string, verbose: boolean, compressOptions?: CompressOptions): Promise<void>;
5
12
  //# sourceMappingURL=variants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/variants.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAQ,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGrE,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,uBAAuB,CAAC;AAE5D,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,eAAe,GAAE,eAAoB,iBA6BtC"}
1
+ {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/variants.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAQ,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGrE,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,uBAAuB,CAAC;AAK5D,qBAAa,UAAU,CAAC,CAAC;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;IAE1D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;CAShF;AAED,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,eAAe,GAAE,eAAoB,iBA6BtC"}
@@ -5,6 +5,23 @@
5
5
  import fs from 'node:fs';
6
6
  import { algs } from '../compression/index.js';
7
7
  import { rootRelative } from './files.js';
8
+ // Runs an async function one time for each key. The first call for a key
9
+ // starts the function and stores its promise before it returns. Later calls
10
+ // for the same key, also concurrent calls, get the same promise.
11
+ export class OncePerKey {
12
+ constructor() {
13
+ this.promises = new Map();
14
+ }
15
+ run(key, fn) {
16
+ let promise = this.promises.get(key);
17
+ if (promise != null) {
18
+ return { promise, first: false };
19
+ }
20
+ promise = fn();
21
+ this.promises.set(key, promise);
22
+ return { promise, first: true };
23
+ }
24
+ }
8
25
  export async function ensureVariantFileExists(variantFilePath, variant, file, verbose, compressOptions = {}) {
9
26
  // Compress/prepare the asset if it doesn't already exist
10
27
  // We disregard chunked copies of the file and only check for the existence
@@ -1,7 +1,11 @@
1
1
  export type IndexMetadata = {
2
2
  publishedTime?: number;
3
3
  expirationTime?: number;
4
+ requires?: string[];
5
+ otherFields?: Record<string, string>;
4
6
  };
7
+ export declare const SUPPORTED_INDEX_FEATURES: readonly string[];
5
8
  export declare function encodeIndexMetadata(indexMetadata: IndexMetadata): Record<string, string>;
6
9
  export declare function decodeIndexMetadata(obj: Record<string, string> | undefined): IndexMetadata | null;
10
+ export declare function getUnsupportedIndexFeatures(indexMetadata: IndexMetadata, supportedFeatures?: readonly string[]): string[];
7
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CAUjG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAO,CAAC;AAI9D,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA2BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
@@ -3,14 +3,28 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import { getMetadataFieldValue } from '../metadata/index.js';
6
+ // The features that this version of PublisherServer supports. A server does
7
+ // not serve a collection that requires a feature that is not in this list.
8
+ // A feature name must not contain a comma, because the metadata uses commas to
9
+ // separate the names. Use short kebab-case names, for example 'my-feature'.
10
+ export const SUPPORTED_INDEX_FEATURES = [];
11
+ const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires'];
6
12
  export function encodeIndexMetadata(indexMetadata) {
7
- const result = {};
13
+ const result = { ...indexMetadata.otherFields };
8
14
  if (indexMetadata.publishedTime != null && !isNaN(indexMetadata.publishedTime)) {
9
15
  result['publishedTime'] = String(indexMetadata.publishedTime);
10
16
  }
11
17
  if (indexMetadata.expirationTime != null && !isNaN(indexMetadata.expirationTime)) {
12
18
  result['expirationTime'] = String(indexMetadata.expirationTime);
13
19
  }
20
+ if (indexMetadata.requires != null && indexMetadata.requires.length > 0) {
21
+ for (const feature of indexMetadata.requires) {
22
+ if (feature.includes(',')) {
23
+ throw new Error(`Feature name '${feature}' must not contain a comma.`);
24
+ }
25
+ }
26
+ result['requires'] = indexMetadata.requires.join(',');
27
+ }
14
28
  return result;
15
29
  }
16
30
  export function decodeIndexMetadata(obj) {
@@ -19,8 +33,27 @@ export function decodeIndexMetadata(obj) {
19
33
  }
20
34
  const publishedTime = parseFloat(getMetadataFieldValue(obj, 'publishedTime'));
21
35
  const expirationTime = parseFloat(getMetadataFieldValue(obj, 'expirationTime'));
36
+ const requiresValue = getMetadataFieldValue(obj, 'requires');
37
+ const requires = requiresValue != null
38
+ ? String(requiresValue).split(',').map(x => x.trim()).filter(x => x !== '')
39
+ : [];
40
+ // S3 makes the metadata keys lowercase, so compare the keys without case.
41
+ const knownKeys = KNOWN_FIELDS.map(x => x.toLowerCase());
42
+ let otherFields;
43
+ for (const [key, value] of Object.entries(obj)) {
44
+ if (!knownKeys.includes(key.toLowerCase())) {
45
+ otherFields ??= {};
46
+ otherFields[key] = String(value);
47
+ }
48
+ }
22
49
  return {
23
50
  publishedTime: !isNaN(publishedTime) ? publishedTime : undefined,
24
51
  expirationTime: !isNaN(expirationTime) ? expirationTime : undefined,
52
+ requires: requires.length > 0 ? requires : undefined,
53
+ otherFields,
25
54
  };
26
55
  }
56
+ // Returns the features in requires that are not in supportedFeatures.
57
+ export function getUnsupportedIndexFeatures(indexMetadata, supportedFeatures = SUPPORTED_INDEX_FEATURES) {
58
+ return (indexMetadata.requires ?? []).filter(x => !supportedFeatures.includes(x));
59
+ }
@@ -1,7 +1,11 @@
1
1
  export type IndexMetadata = {
2
2
  publishedTime?: number;
3
3
  expirationTime?: number;
4
+ requires?: string[];
5
+ otherFields?: Record<string, string>;
4
6
  };
7
+ export declare const SUPPORTED_INDEX_FEATURES: readonly string[];
5
8
  export declare function encodeIndexMetadata(indexMetadata: IndexMetadata): Record<string, string>;
6
9
  export declare function decodeIndexMetadata(obj: Record<string, string> | undefined): IndexMetadata | null;
10
+ export declare function getUnsupportedIndexFeatures(indexMetadata: IndexMetadata, supportedFeatures?: readonly string[]): string[];
7
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CAUjG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAAO,CAAC;AAI9D,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA2BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
@@ -3,14 +3,28 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import { getMetadataFieldValue } from '../metadata/index.js';
6
+ // The features that this version of PublisherServer supports. A server does
7
+ // not serve a collection that requires a feature that is not in this list.
8
+ // A feature name must not contain a comma, because the metadata uses commas to
9
+ // separate the names. Use short kebab-case names, for example 'my-feature'.
10
+ export const SUPPORTED_INDEX_FEATURES = [];
11
+ const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires'];
6
12
  export function encodeIndexMetadata(indexMetadata) {
7
- const result = {};
13
+ const result = { ...indexMetadata.otherFields };
8
14
  if (indexMetadata.publishedTime != null && !isNaN(indexMetadata.publishedTime)) {
9
15
  result['publishedTime'] = String(indexMetadata.publishedTime);
10
16
  }
11
17
  if (indexMetadata.expirationTime != null && !isNaN(indexMetadata.expirationTime)) {
12
18
  result['expirationTime'] = String(indexMetadata.expirationTime);
13
19
  }
20
+ if (indexMetadata.requires != null && indexMetadata.requires.length > 0) {
21
+ for (const feature of indexMetadata.requires) {
22
+ if (feature.includes(',')) {
23
+ throw new Error(`Feature name '${feature}' must not contain a comma.`);
24
+ }
25
+ }
26
+ result['requires'] = indexMetadata.requires.join(',');
27
+ }
14
28
  return result;
15
29
  }
16
30
  export function decodeIndexMetadata(obj) {
@@ -19,8 +33,27 @@ export function decodeIndexMetadata(obj) {
19
33
  }
20
34
  const publishedTime = parseFloat(getMetadataFieldValue(obj, 'publishedTime'));
21
35
  const expirationTime = parseFloat(getMetadataFieldValue(obj, 'expirationTime'));
36
+ const requiresValue = getMetadataFieldValue(obj, 'requires');
37
+ const requires = requiresValue != null
38
+ ? String(requiresValue).split(',').map(x => x.trim()).filter(x => x !== '')
39
+ : [];
40
+ // S3 makes the metadata keys lowercase, so compare the keys without case.
41
+ const knownKeys = KNOWN_FIELDS.map(x => x.toLowerCase());
42
+ let otherFields;
43
+ for (const [key, value] of Object.entries(obj)) {
44
+ if (!knownKeys.includes(key.toLowerCase())) {
45
+ otherFields ??= {};
46
+ otherFields[key] = String(value);
47
+ }
48
+ }
22
49
  return {
23
50
  publishedTime: !isNaN(publishedTime) ? publishedTime : undefined,
24
51
  expirationTime: !isNaN(expirationTime) ? expirationTime : undefined,
52
+ requires: requires.length > 0 ? requires : undefined,
53
+ otherFields,
25
54
  };
26
55
  }
56
+ // Returns the features in requires that are not in supportedFeatures.
57
+ export function getUnsupportedIndexFeatures(indexMetadata, supportedFeatures = SUPPORTED_INDEX_FEATURES) {
58
+ return (indexMetadata.requires ?? []).filter(x => !supportedFeatures.includes(x));
59
+ }
@@ -27,6 +27,7 @@ export declare class PublisherServer {
27
27
  responseCache: ResponseCacheOptions | null;
28
28
  settingsCached: PublisherServerConfigNormalized | null | undefined;
29
29
  assetEntryMapCache: AssetEntryMap | null | undefined;
30
+ doNotStoreResponse: boolean;
30
31
  setActiveCollectionName(collectionName: string | null): void;
31
32
  setCollectionNameHeader(collectionHeader: string | null): void;
32
33
  setServerTimingRequestHeader(requestHeader: string | null): void;
@@ -45,7 +46,6 @@ export declare class PublisherServer {
45
46
  private findAssetVariantForAcceptEncodingsGroups;
46
47
  serveAsset(request: Request, asset: AssetEntry, init?: AssetInit): Promise<Response>;
47
48
  serveCached(request: Request, keyPath: string, produce: (request: Request) => Promise<Response | null>): Promise<Response | null>;
48
- private copyBodyToCache;
49
49
  private responseFromCache;
50
50
  serveRequest(request: Request): Promise<Response | null>;
51
51
  private serveRequestFromStorage;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK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