@fastly/compute-js-static-publish 8.0.0-beta.1 → 8.0.0-beta.11

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 (98) hide show
  1. package/README.md +19 -5
  2. package/README.short.md +19 -5
  3. package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
  4. package/build/cli/cli/commands/manage/clean.js +16 -22
  5. package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
  6. package/build/cli/cli/commands/manage/collections/delete.js +12 -21
  7. package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
  8. package/build/cli/cli/commands/manage/collections/index.js +6 -13
  9. package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
  10. package/build/cli/cli/commands/manage/collections/list.js +11 -20
  11. package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
  12. package/build/cli/cli/commands/manage/collections/promote.js +11 -20
  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 +11 -20
  15. package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
  16. package/build/cli/cli/commands/manage/index.js +6 -13
  17. package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
  18. package/build/cli/cli/commands/manage/publish-content.js +142 -92
  19. package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
  20. package/build/cli/cli/commands/scaffold/index.js +53 -31
  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 +4 -5
  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 +4 -7
  33. package/build/cli/cli/storage/kv-store-provider.d.ts +5 -5
  34. package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
  35. package/build/cli/cli/storage/kv-store-provider.js +39 -65
  36. package/build/cli/cli/storage/s3-storage-provider.d.ts +7 -6
  37. package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
  38. package/build/cli/cli/storage/s3-storage-provider.js +76 -48
  39. package/build/cli/cli/storage/storage-provider.d.ts +8 -8
  40. package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
  41. package/build/cli/cli/util/config.d.ts.map +1 -1
  42. package/build/cli/cli/util/config.js +27 -11
  43. package/build/cli/cli/util/content-types.d.ts.map +1 -1
  44. package/build/cli/cli/util/content-types.js +4 -1
  45. package/build/cli/cli/util/kv-store-items.d.ts +12 -0
  46. package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
  47. package/build/cli/cli/util/kv-store-items.js +49 -0
  48. package/build/cli/cli/util/kv-store.d.ts +6 -0
  49. package/build/cli/cli/util/kv-store.d.ts.map +1 -1
  50. package/build/cli/cli/util/kv-store.js +39 -2
  51. package/build/cli/cli/util/purge.d.ts +3 -0
  52. package/build/cli/cli/util/purge.d.ts.map +1 -0
  53. package/build/cli/cli/util/purge.js +23 -0
  54. package/build/cli/cli/util/retryable.d.ts +2 -1
  55. package/build/cli/cli/util/retryable.d.ts.map +1 -1
  56. package/build/cli/cli/util/retryable.js +34 -1
  57. package/build/cli/cli/util/s3-credentials.d.ts +11 -0
  58. package/build/cli/cli/util/s3-credentials.d.ts.map +1 -0
  59. package/build/cli/cli/util/s3-credentials.js +38 -0
  60. package/build/cli/cli/util/s3.d.ts +1 -1
  61. package/build/cli/cli/util/s3.d.ts.map +1 -1
  62. package/build/cli/cli/util/s3.js +1 -1
  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 +8 -4
  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/cli/models/config/s3-storage-config.d.ts +1 -0
  70. package/build/cli/models/config/s3-storage-config.d.ts.map +1 -1
  71. package/build/cli/models/config/s3-storage-config.js +1 -0
  72. package/build/cli/models/config/static-publish-rc.d.ts +1 -0
  73. package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
  74. package/build/cli/models/config/static-publish-rc.js +3 -1
  75. package/build/cli/models/metadata/index.js +1 -1
  76. package/build/server/models/assets/index.js +1 -1
  77. package/build/server/models/config/publish-content-config.d.ts +2 -0
  78. package/build/server/models/config/publish-content-config.d.ts.map +1 -1
  79. package/build/server/models/config/s3-storage-config.d.ts +1 -0
  80. package/build/server/models/config/s3-storage-config.d.ts.map +1 -1
  81. package/build/server/models/config/s3-storage-config.js +1 -0
  82. package/build/server/models/config/static-publish-rc.d.ts +1 -0
  83. package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
  84. package/build/server/models/config/static-publish-rc.js +3 -1
  85. package/build/server/models/metadata/index.js +1 -1
  86. package/build/server/server/index.d.ts +1 -1
  87. package/build/server/server/index.d.ts.map +1 -1
  88. package/build/server/server/index.js +1 -1
  89. package/build/server/server/publisher-server/index.js +2 -2
  90. package/build/server/server/storage/s3-storage-provider.d.ts +19 -15
  91. package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
  92. package/build/server/server/storage/s3-storage-provider.js +52 -38
  93. package/build/server/server/storage/storage-provider.d.ts +1 -1
  94. package/build/server/server/storage/storage-provider.d.ts.map +1 -1
  95. package/package.json +2 -3
  96. package/build/cli/cli/util/aws-credentials.d.ts +0 -12
  97. package/build/cli/cli/util/aws-credentials.d.ts.map +0 -1
  98. package/build/cli/cli/util/aws-credentials.js +0 -67
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import path from 'node:path';
6
+ import { pathToFileURL } from 'node:url';
6
7
  import globToRegExp from 'glob-to-regexp';
7
8
  import { isKvStoreConfigRc, isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
8
9
  import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
@@ -17,16 +18,20 @@ export class LoadConfigError extends Error {
17
18
  export async function loadStaticPublisherRcFile() {
18
19
  let configRaw;
19
20
  const configFile = './static-publish.rc.js';
21
+ const configFilePath = path.resolve(configFile);
20
22
  try {
21
- const filePath = path.resolve(configFile);
22
- configRaw = (await import(filePath)).default;
23
+ configRaw = (await import(pathToFileURL(configFilePath).href)).default;
23
24
  }
24
- catch {
25
- //
25
+ catch (ex) {
26
+ throw new LoadConfigError(configFile, [
27
+ `Unable to load ${configFilePath}`,
28
+ String(ex),
29
+ ]);
26
30
  }
27
31
  if (configRaw == null) {
28
32
  throw new LoadConfigError(configFile, [
29
- 'Unable to load ' + configFile,
33
+ `Unable to load ${configFilePath}`,
34
+ `default export does not exist or is null.`
30
35
  ]);
31
36
  }
32
37
  const errors = [];
@@ -97,16 +102,20 @@ export const normalizeStaticPublisherRc = buildNormalizeFunctionForObject((confi
97
102
  });
98
103
  export async function loadPublishContentConfigFile(configFile) {
99
104
  let configRaw;
105
+ const configFilePath = path.resolve(configFile);
100
106
  try {
101
- const filePath = path.resolve(configFile);
102
- configRaw = (await import(filePath)).default;
107
+ configRaw = (await import(pathToFileURL(configFilePath).href)).default;
103
108
  }
104
- catch {
105
- //
109
+ catch (ex) {
110
+ throw new LoadConfigError(configFile, [
111
+ `Unable to load ${configFilePath}`,
112
+ String(ex),
113
+ ]);
106
114
  }
107
115
  if (configRaw == null) {
108
116
  throw new LoadConfigError(configFile, [
109
- 'Unable to load ' + configFile,
117
+ `Unable to load ${configFilePath}`,
118
+ `default export does not exist or is null.`
110
119
  ]);
111
120
  }
112
121
  const errors = [];
@@ -154,7 +163,7 @@ const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors)
154
163
  return normalizeContentTypeDef(config, errors);
155
164
  });
156
165
  export const normalizePublishContentConfig = buildNormalizeFunctionForObject((config, errors) => {
157
- let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, contentCompression, contentTypes, server, } = config;
166
+ let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, contentCompression, brotliQuality, contentTypes, server, } = config;
158
167
  if (!isSpecified(config, 'rootDir')) {
159
168
  errors.push('rootDir must be specified.');
160
169
  }
@@ -260,6 +269,12 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
260
269
  errors.push(`contentCompression, if specified, must be null or an array and can only contain 'br' and 'gzip'.`);
261
270
  }
262
271
  }
272
+ if (!isSpecified(config, 'brotliQuality') || brotliQuality === null) {
273
+ brotliQuality = undefined;
274
+ }
275
+ else if (!Number.isInteger(brotliQuality) || brotliQuality < 0 || brotliQuality > 11) {
276
+ errors.push('brotliQuality, if specified, must be an integer from 0 to 11.');
277
+ }
263
278
  if (!isSpecified(config, 'contentTypes')) {
264
279
  contentTypes = [];
265
280
  }
@@ -306,6 +321,7 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
306
321
  includeWellKnown,
307
322
  assetInclusionTest,
308
323
  contentCompression,
324
+ brotliQuality,
309
325
  contentTypes,
310
326
  server,
311
327
  };
@@ -1 +1 @@
1
- {"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/content-types.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,+CAA+C,CAAC;AAqCvD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,cAAc,EAAE,oBAmD/D;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CAkBrI"}
1
+ {"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/content-types.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC3B,MAAM,+CAA+C,CAAC;AAwCvD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,cAAc,EAAE,oBAmD/D;AAED,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,cAAc,EAAE,GAAG,IAAI,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CAkBrI"}
@@ -18,8 +18,10 @@ const defaultContentTypes = [
18
18
  { test: /\.gif$/, contentType: 'image/gif', text: false },
19
19
  { test: /\.jp(e)?g$/, contentType: 'image/jpeg', text: false },
20
20
  { test: /\.ico$/, contentType: 'image/vnd.microsoft.icon', text: false },
21
- { test: /\.tif(f)?$/, contentType: 'image/png', text: false },
21
+ { test: /\.tif(f)?$/, contentType: 'image/tiff', text: false },
22
22
  { test: /\.webp$/, contentType: 'image/webp', text: false },
23
+ { test: /\.avif$/, contentType: 'image/avif', text: false },
24
+ { test: /\.jxl$/, contentType: 'image/jxl', text: false },
23
25
  { test: /\.aac$/, contentType: 'audio/aac', text: false },
24
26
  { test: /\.mp3$/, contentType: 'audio/mpeg', text: false },
25
27
  { test: /\.avi$/, contentType: 'video/x-msvideo', text: false },
@@ -29,6 +31,7 @@ const defaultContentTypes = [
29
31
  { test: /\.pdf$/, contentType: 'application/pdf', text: false },
30
32
  { test: /\.tar$/, contentType: 'application/x-tar', text: false, precompressAsset: true, },
31
33
  { test: /\.zip$/, contentType: 'application/zip', text: false },
34
+ { test: /\.wasm$/, contentType: 'application/wasm', text: false },
32
35
  { test: /\.eot$/, contentType: 'application/vnd.ms-fontobject', text: false },
33
36
  { test: /\.otf$/, contentType: 'font/otf', text: false },
34
37
  { test: /\.ttf$/, contentType: 'font/ttf', text: false },
@@ -2,4 +2,16 @@ import { StorageProviderBatchEntry } from '../storage/storage-provider.js';
2
2
  export declare const KV_STORE_CHUNK_SIZE: number;
3
3
  export declare function shouldRecreateChunks(chunksDir: string, numChunks: number, item: StorageProviderBatchEntry, chunkSize: number): boolean;
4
4
  export declare function applyKVStoreEntriesChunks(kvStoreItemDescriptions: StorageProviderBatchEntry[], chunkSize: number): Promise<void>;
5
+ export declare const KV_BATCH_MAX_ITEMS = 256;
6
+ export declare const KV_BATCH_MAX_BYTES: number;
7
+ export type NdjsonBatch = {
8
+ key: string;
9
+ entries: StorageProviderBatchEntry[];
10
+ };
11
+ export declare function packNdjsonBatches(entries: StorageProviderBatchEntry[], maxItems?: number, maxBytes?: number): {
12
+ batches: NdjsonBatch[];
13
+ oversized: StorageProviderBatchEntry[];
14
+ };
15
+ export declare function ndjsonLineForBatchEntry(entry: StorageProviderBatchEntry): string;
16
+ export declare function entriesToUpload(entries: StorageProviderBatchEntry[], existingKeys: Set<string>): StorageProviderBatchEntry[];
5
17
  //# sourceMappingURL=kv-store-items.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAEtD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,WAkC5H;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoGtH"}
1
+ {"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAEtD,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,WAkC5H;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,yBAAyB,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoGtH;AAED,eAAO,MAAM,kBAAkB,MAAM,CAAC;AACtC,eAAO,MAAM,kBAAkB,QAAoB,CAAC;AAEpD,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,yBAAyB,EAAE,CAAC;CACtC,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,yBAAyB,EAAE,EACpC,QAAQ,GAAE,MAA2B,EACrC,QAAQ,GAAE,MAA2B,GACpC;IAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAAC,SAAS,EAAE,yBAAyB,EAAE,CAAA;CAAE,CAuCpE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,GAAG,MAAM,CAOhF;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,yBAAyB,EAAE,EACpC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,GACxB,yBAAyB,EAAE,CAE7B"}
@@ -114,3 +114,52 @@ export async function applyKVStoreEntriesChunks(kvStoreItemDescriptions, chunkSi
114
114
  }
115
115
  }
116
116
  }
117
+ export const KV_BATCH_MAX_ITEMS = 256;
118
+ export const KV_BATCH_MAX_BYTES = 8 * 1_024 * 1_024;
119
+ export function packNdjsonBatches(entries, maxItems = KV_BATCH_MAX_ITEMS, maxBytes = KV_BATCH_MAX_BYTES) {
120
+ const lineBytesFor = (entry) => {
121
+ const envelope = JSON.stringify({
122
+ key: entry.key,
123
+ value: '',
124
+ ...(entry.metadataJson != null ? { metadata: JSON.stringify(entry.metadataJson) } : {}),
125
+ });
126
+ return envelope.length + Math.ceil(entry.size / 3) * 4;
127
+ };
128
+ const oversized = [];
129
+ const groups = [];
130
+ let current = [];
131
+ let currentBytes = 0;
132
+ for (const entry of entries) {
133
+ const lineBytes = lineBytesFor(entry);
134
+ if (lineBytes > maxBytes) {
135
+ oversized.push(entry);
136
+ continue;
137
+ }
138
+ if (current.length > 0 && (current.length >= maxItems || currentBytes + lineBytes > maxBytes)) {
139
+ groups.push(current);
140
+ current = [];
141
+ currentBytes = 0;
142
+ }
143
+ current.push(entry);
144
+ currentBytes += lineBytes;
145
+ }
146
+ if (current.length > 0) {
147
+ groups.push(current);
148
+ }
149
+ const batches = groups.map((groupEntries, i) => ({
150
+ key: `batch-${i}`,
151
+ entries: groupEntries,
152
+ }));
153
+ return { batches, oversized };
154
+ }
155
+ export function ndjsonLineForBatchEntry(entry) {
156
+ const value = fs.readFileSync(entry.filePath).toString('base64');
157
+ return JSON.stringify({
158
+ key: entry.key,
159
+ value,
160
+ ...(entry.metadataJson != null ? { metadata: JSON.stringify(entry.metadataJson) } : {}),
161
+ });
162
+ }
163
+ export function entriesToUpload(entries, existingKeys) {
164
+ return entries.filter((entry) => !existingKeys.has(entry.key));
165
+ }
@@ -17,5 +17,11 @@ export declare function getKvStoreEntryInfo(fastlyApiContext: FastlyApiContext,
17
17
  export declare function getKvStoreEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, metadataOnly?: boolean): Promise<KvStoreEntryInfo | null>;
18
18
  export declare function kvStoreSubmitEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: ReadableStream<Uint8Array> | Uint8Array | string, metadata: string | undefined): Promise<void>;
19
19
  export declare function kvStoreDeleteEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<void>;
20
+ export type KvStoreBatchError = {
21
+ key: string;
22
+ code?: string;
23
+ reason?: string;
24
+ };
25
+ export declare function kvStoreSubmitBatch(fastlyApiContext: FastlyApiContext, kvStoreName: string, ndjsonLines: string[]): Promise<KvStoreBatchError[]>;
20
26
  export {};
21
27
  //# sourceMappingURL=kv-store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAElF,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAUF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AASF,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,mCAkB9E;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAKhG;AAqCD,wBAAsB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB,0BAcvE;AAED,eAAO,MAAM,eAAe,qBAjDgB,gBAAgB,iBAAiB,MAAM,sEAyDlF,CAAC;AAEF,wBAAsB,cAAc,CAClC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,4BAchB;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAIhJ;AAED,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO,GACrB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA6BlC;AAGD,wBAAsB,kBAA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AIhJ;AAED,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO,GACrB,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA6BlC;AAGD,wBAAsB,kBAAkB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,EACtD,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAoB7B;AAED,wBAAsB,kBAAkB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,iBAa5G;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAKF,wBAAsB,kBAAkB,CACtC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAwC9B"}
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
5
  import { callFastlyApi, FetchError } from './api-token.js';
6
+ import { makeRetryable } from './retryable.js';
6
7
  const cache = new WeakMap();
7
8
  export async function getKVStoreIdForNameMap(fastlyApiContext) {
8
9
  const cacheEntry = cache.get(fastlyApiContext);
@@ -59,9 +60,12 @@ export async function getKVStoreInfos(fastlyApiContext) {
59
60
  return kvStoreInfos;
60
61
  }
61
62
  export const _getKVStoreKeys = createArrayGetter()((kvStoreId, prefix) => {
62
- let endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys`;
63
+ // Read from the primary data source. An eventual read can show a key
64
+ // that was deleted a short time ago. Then publish-content does not upload
65
+ // an item that the new index needs.
66
+ let endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys?consistency=strong`;
63
67
  if (prefix != null) {
64
- endpoint += '?prefix=' + encodeURIComponent(prefix);
68
+ endpoint += '&prefix=' + encodeURIComponent(prefix);
65
69
  }
66
70
  return endpoint;
67
71
  });
@@ -126,3 +130,36 @@ export async function kvStoreDeleteEntry(fastlyApiContext, kvStoreName, key) {
126
130
  method: 'DELETE',
127
131
  });
128
132
  }
133
+ // Returns the items that the KV Store reports as failed. The caller can
134
+ // submit only these items again. Throws if the response does not identify
135
+ // the failed items.
136
+ export async function kvStoreSubmitBatch(fastlyApiContext, kvStoreName, ndjsonLines) {
137
+ const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
138
+ if (kvStoreId == null) {
139
+ throw new Error(`KV Store '${kvStoreName}' not found.`);
140
+ }
141
+ const response = await callFastlyApi(fastlyApiContext, `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/batch`, `Submitting batch of ${ndjsonLines.length} item(s) to KV Store`, null, {
142
+ method: 'PUT',
143
+ headers: { 'Content-Type': 'application/x-ndjson' },
144
+ body: ndjsonLines.join('\n'),
145
+ });
146
+ // A 207 response has the body
147
+ // {"title":"some inserts failed","errors":[{"key":"...","code":"...","reason":"..."}]}
148
+ // A 200 response has the body {"title":"success","errors":[]}.
149
+ // Read the body in all cases, so that the connection can be used again.
150
+ const detail = await response.text().catch(() => '');
151
+ let errors;
152
+ try {
153
+ errors = JSON.parse(detail)?.errors;
154
+ }
155
+ catch {
156
+ errors = undefined;
157
+ }
158
+ if (Array.isArray(errors) && errors.every(e => typeof e?.key === 'string')) {
159
+ return errors.map(e => ({ key: e.key, code: e.code, reason: e.reason }));
160
+ }
161
+ if (response.status === 207) {
162
+ throw makeRetryable(new FetchError(`Batch upload partially failed (207): ${detail.slice(0, 300)}`, 207));
163
+ }
164
+ return [];
165
+ }
@@ -0,0 +1,3 @@
1
+ import { type FastlyApiContext } from './api-token.js';
2
+ export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean): Promise<boolean>;
3
+ //# sourceMappingURL=purge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAElF,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,gBAAgB,EAClC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,OAAe,oBAuB3B"}
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ import { callFastlyApi, FetchError } from './api-token.js';
6
+ export async function purgeSurrogateKey(fastlyApiContext, fastlyServiceId, surrogateKey, softPurge = false) {
7
+ const endpoint = `/service/${encodeURIComponent(fastlyServiceId)}/purge`;
8
+ try {
9
+ const headers = new Headers();
10
+ headers.set('surrogate-key', surrogateKey);
11
+ if (softPurge) {
12
+ headers.set('fastly-soft-purge', '1');
13
+ }
14
+ await callFastlyApi(fastlyApiContext, endpoint, `Purging surrogate key [${surrogateKey}] on service [${fastlyServiceId}]`, null, { method: 'POST', headers });
15
+ }
16
+ catch (err) {
17
+ if (err instanceof FetchError) {
18
+ return false;
19
+ }
20
+ throw err;
21
+ }
22
+ return true;
23
+ }
@@ -10,6 +10,7 @@ type RetryWithBackoffOptions = {
10
10
  export declare function attemptWithRetries<TResult>(fn: () => Promise<TResult>, options?: RetryWithBackoffOptions): Promise<TResult>;
11
11
  export declare function concurrentParallel<TObject extends {
12
12
  key: string;
13
- }>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, buildStatusMessage: (err: unknown) => (string | null), maxConcurrent?: number): Promise<void>;
13
+ }>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, buildStatusMessage: (err: unknown) => (string | null), maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
14
+ export declare function concurrentMap<TItem, TResult>(items: TItem[], fn: (item: TItem, index: number) => Promise<TResult>, maxConcurrent?: number): Promise<TResult[]>;
14
15
  export {};
15
16
  //# sourceMappingURL=retryable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"retryable.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/retryable.ts"],"names":[],"mappings":"AAQA,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,SAGzC;AACD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,OAK9C;AAED,KAAK,uBAAuB,GAAG;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAClE,CAAC;AACF,wBAAsB,kBAAkB,CAAC,OAAO,EAC9C,EAAE,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAC1B,OAAO,GAAE,uBAA4B,oBAsCtC;AAED,wBAAsB,kBAAkB,CAAC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EACtE,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,kBAAkB,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,EACrD,a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,aAAa,GAAE,MAA6C,GAC3D,OAAO,CAAC,OAAO,EAAE,CAAC,CA4BpB"}
@@ -2,6 +2,7 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
+ import { availableParallelism } from 'node:os';
5
6
  let _globalBackoffUntil = 0;
6
7
  const retryableSymbol = Symbol();
7
8
  export function makeRetryable(error) {
@@ -41,8 +42,9 @@ export async function attemptWithRetries(fn, options = {}) {
41
42
  }
42
43
  return result;
43
44
  }
44
- export async function concurrentParallel(objects, fn, buildStatusMessage, maxConcurrent = 12) {
45
+ export async function concurrentParallel(objects, fn, buildStatusMessage, maxConcurrent = 12, throwOnError = false) {
45
46
  let index = 0; // Shared among workers
47
+ const failures = [];
46
48
  async function worker() {
47
49
  while (index < objects.length) {
48
50
  const currentIndex = index;
@@ -68,9 +70,40 @@ export async function concurrentParallel(objects, fn, buildStatusMessage, maxCon
68
70
  const e = err instanceof Error ? err : new Error(String(err));
69
71
  console.error(` ❌ Failed: ${key} → ${e.message}`);
70
72
  console.error(e.stack);
73
+ failures.push(key);
71
74
  }
72
75
  }
73
76
  }
74
77
  const workers = Array.from({ length: maxConcurrent }, () => worker());
75
78
  await Promise.all(workers);
79
+ if (throwOnError && failures.length > 0) {
80
+ const shown = failures.slice(0, 10).join(', ');
81
+ const more = failures.length > 10 ? `, and ${failures.length - 10} more` : '';
82
+ throw new Error(`${failures.length} of ${objects.length} operation(s) failed: ${shown}${more}`);
83
+ }
84
+ }
85
+ export async function concurrentMap(items, fn,
86
+ // Each call can keep files open, so do not use too many at a time.
87
+ maxConcurrent = Math.min(availableParallelism(), 16)) {
88
+ const results = new Array(items.length);
89
+ let index = 0;
90
+ let failed = false;
91
+ async function worker() {
92
+ // If one item fails, do not start more items.
93
+ while (!failed && index < items.length) {
94
+ const currentIndex = index;
95
+ index = index + 1;
96
+ try {
97
+ results[currentIndex] = await fn(items[currentIndex], currentIndex);
98
+ }
99
+ catch (err) {
100
+ failed = true;
101
+ const message = err instanceof Error ? err.message : String(err);
102
+ throw Object.assign(new Error(`Failed to process '${String(items[currentIndex])}': ${message}`), { cause: err });
103
+ }
104
+ }
105
+ }
106
+ const workers = Array.from({ length: Math.min(maxConcurrent, items.length) }, () => worker());
107
+ await Promise.all(workers);
108
+ return results;
76
109
  }
@@ -0,0 +1,11 @@
1
+ export type LoadS3CredentialsResult = {
2
+ s3AccessKeyId: string;
3
+ s3SecretAccessKey: string;
4
+ source: string;
5
+ };
6
+ export type LoadS3CredentialsParams = {
7
+ s3AccessKeyId?: any;
8
+ s3SecretAccessKey?: any;
9
+ };
10
+ export declare function loadS3Credentials(params: LoadS3CredentialsParams): Promise<LoadS3CredentialsResult | null>;
11
+ //# sourceMappingURL=s3-credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"s3-credentials.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3-credentials.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,iBAAiB,CAAC,EAAE,GAAG,CAAC;CACzB,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAwChH"}
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright Fastly, Inc.
3
+ * Licensed under the MIT license. See LICENSE file for details.
4
+ */
5
+ export async function loadS3Credentials(params) {
6
+ let s3AccessKeyId = null;
7
+ let s3SecretAccessKey = null;
8
+ let source = '';
9
+ // Try command line arg
10
+ if (typeof params.s3AccessKeyId === 'string' &&
11
+ typeof params.s3SecretAccessKey === 'string') {
12
+ const id = params.s3AccessKeyId.trim() || null;
13
+ const key = params.s3SecretAccessKey.trim() || null;
14
+ if (id != null && key != null) {
15
+ s3AccessKeyId = id;
16
+ s3SecretAccessKey = key;
17
+ source = 'commandline';
18
+ }
19
+ }
20
+ // Try env (S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY)
21
+ if (s3AccessKeyId == null && s3SecretAccessKey == null) {
22
+ const id = process.env.S3_ACCESS_KEY_ID || null;
23
+ const key = process.env.S3_SECRET_ACCESS_KEY || null;
24
+ if (id != null && key != null) {
25
+ s3AccessKeyId = id;
26
+ s3SecretAccessKey = key;
27
+ source = 'env';
28
+ }
29
+ }
30
+ if (s3AccessKeyId == null || s3SecretAccessKey == null) {
31
+ return null;
32
+ }
33
+ return {
34
+ s3AccessKeyId,
35
+ s3SecretAccessKey,
36
+ source,
37
+ };
38
+ }
@@ -3,5 +3,5 @@
3
3
  * - Uses client-s3's own endpoint resolution logic (so it's always accurate).
4
4
  * - No network calls; intercepts at the build step.
5
5
  */
6
- export declare function resolveS3Hostname(region: string, bucket: string): Promise<string>;
6
+ export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string): Promise<string>;
7
7
  //# sourceMappingURL=s3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCvF"}
1
+ {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAsB,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCzG"}
@@ -9,7 +9,7 @@ const DUMMY_KEY = 'dummy.dat'; // placeholder, never sent over the network
9
9
  * - Uses client-s3's own endpoint resolution logic (so it's always accurate).
10
10
  * - No network calls; intercepts at the build step.
11
11
  */
12
- export async function resolveS3Hostname(region, bucket) {
12
+ export async function findHostnameForAwsS3RegionAndBucket(region, bucket) {
13
13
  const client = new S3Client({ region });
14
14
  let hostname = '';
15
15
  const captureHostname = (_next) => async (args) => {
@@ -1,4 +1,5 @@
1
1
  import { type ContentCompressionTypes } from '../../models/compression/index.js';
2
+ import { type CompressOptions } from '../compression/index.js';
2
3
  export type Variants = 'original' | ContentCompressionTypes;
3
- export declare function ensureVariantFileExists(variantFilePath: string, variant: Variants, file: string): Promise<void>;
4
+ export declare function ensureVariantFileExists(variantFilePath: string, variant: Variants, file: string, verbose: boolean, compressOptions?: CompressOptions): Promise<void>;
4
5
  //# 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;AAIjF,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,uBAAuB,CAAC;AAE5D,wBAAsB,uBAAuB,CAC3C,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,QAAQ,EACjB,IAAI,EAAE,MAAM,iBAyBb"}
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"}
@@ -5,19 +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
- export async function ensureVariantFileExists(variantFilePath, variant, file) {
8
+ export async function ensureVariantFileExists(variantFilePath, variant, file, verbose, compressOptions = {}) {
9
9
  // Compress/prepare the asset if it doesn't already exist
10
10
  // We disregard chunked copies of the file and only check for the existence
11
11
  // of the main copy of the file at this point.
12
12
  if (!fs.existsSync(variantFilePath)) {
13
13
  if (variant === 'original') {
14
14
  fs.cpSync(file, variantFilePath);
15
- console.log(` 📄→📄 Copied file '${rootRelative(file)}' to '${rootRelative(variantFilePath)}'.`);
15
+ if (verbose) {
16
+ console.log(` 📄→📄 Copied file '${rootRelative(file)}' to '${rootRelative(variantFilePath)}'.`);
17
+ }
16
18
  }
17
19
  else {
18
20
  const compressTo = algs[variant];
19
- await compressTo(file, variantFilePath);
20
- console.log(` 📄→🗄️ Compressed file '${rootRelative(file)}' to '${rootRelative(variantFilePath)}' [${variant}].`);
21
+ await compressTo(file, variantFilePath, compressOptions);
22
+ if (verbose) {
23
+ console.log(` 📄→🗄️ Compressed file '${rootRelative(file)}' to '${rootRelative(variantFilePath)}' [${variant}].`);
24
+ }
21
25
  }
22
26
  // However, if we did just create the file,
23
27
  // we delete any chunked copies that may exist as they can be out of date.
@@ -20,7 +20,7 @@ export function decodeAssetVariantMetadata(obj) {
20
20
  if (hash == null) {
21
21
  return null;
22
22
  }
23
- const numChunks = parseFloat(getMetadataFieldValue(obj, 'contentEncoding'));
23
+ const numChunks = parseInt(getMetadataFieldValue(obj, 'numChunks'), 10);
24
24
  const assetVariantMetadata = {
25
25
  size,
26
26
  hash,
@@ -24,6 +24,7 @@ export type PublishContentConfig = {
24
24
  assetInclusionTest?: AssetInclusionTest | null;
25
25
  kvStoreAssetInclusionTest?: AssetInclusionTest | null;
26
26
  contentCompression?: ('br' | 'gzip')[];
27
+ brotliQuality?: number;
27
28
  contentTypes?: ContentTypeDef[];
28
29
  server?: PublisherServerConfig | null;
29
30
  };
@@ -34,6 +35,7 @@ export type PublishContentConfigNormalized = {
34
35
  includeWellKnown: boolean;
35
36
  assetInclusionTest: AssetInclusionTest | null;
36
37
  contentCompression: ContentCompressionTypes[];
38
+ brotliQuality: number | undefined;
37
39
  contentTypes: ContentTypeDef[];
38
40
  server: PublisherServerConfigNormalized | null;
39
41
  };
@@ -1 +1 @@
1
- {"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAGxD,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAG/B,WAAW,EAAE,MAAM,CAAC;IAIpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;AAErF,MAAM,MAAM,oBAAoB,GAAG;IAEjC,OAAO,EAAE,MAAM,CAAC;IAMhB,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE,GAAG,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC;IAI3E,eAAe,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CAChD,CAAC"}
@@ -3,6 +3,7 @@ export type S3StorageConfig = {
3
3
  region: string;
4
4
  bucket: string;
5
5
  endpoint?: string;
6
+ fastlyBackendName?: string;
6
7
  };
7
8
  export declare function getS3StorageConfigFromRc(rc: StaticPublishS3Storage): S3StorageConfig;
8
9
  //# sourceMappingURL=s3-storage-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"s3-storage-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/s3-storage-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,sBAAsB,GAAG,eAAe,CAMpF"}
1
+ {"version":3,"file":"s3-storage-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/s3-storage-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,sBAAsB,GAAG,eAAe,CAOpF"}
@@ -7,5 +7,6 @@ export function getS3StorageConfigFromRc(rc) {
7
7
  region: rc.s3.region,
8
8
  bucket: rc.s3.bucket,
9
9
  endpoint: rc.s3.endpoint,
10
+ fastlyBackendName: rc.s3.fastlyBackendName,
10
11
  };
11
12
  }
@@ -22,6 +22,7 @@ export type StaticPublishPartialS3Storage = {
22
22
  region: string;
23
23
  bucket: string;
24
24
  endpoint?: string;
25
+ fastlyBackendName?: string;
25
26
  };
26
27
  };
27
28
  export type StaticPublishS3Storage = StaticPublishPartialS3Storage & StaticPublishRcBase;
@@ -1 +1 @@
1
- {"version":3,"file":"static-publish-rc.d.ts","sourceRoot":"","sources":["../../../../src/models/config/static-publish-rc.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,mBAAmB,GAAG;IAGhC,SAAS,EAAE,MAAM,CAAC;IAGlB,qBAAqB,EAAE,MAAM,CAAC;IAK9B,yBAAyB,EAAE,MAAM,CAAC;CACnC,CAAC;AAGF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,WAAW,EAAE,UAAU,CAAC;IACxB,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAGF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,2BAA2B,GACnC,8BAA8B,GAC9B,iCAAiC,CACpC;AAGD,MAAM,MAAM,oBAAoB,GAC9B,2BAA2B,GAAG,mBAAmB,CAAC;AAEpD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,oBAAoB,CAqBzE;AAGD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,EAAE,IAAI,CAAC;IAClB,EAAE,EAAE;QACF,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAChC,6BAA6B,GAAG,mBAAmB,CAAC;AAEtD,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,sBAAsB,CAqB7E;AAED,MAAM,MAAM,2BAA2B,GACnC,2BAA2B,GAC3B,6BAA6B,CAChC;AAED,MAAM,MAAM,eAAe,GACvB,oBAAoB,GACpB,sBAAsB,CACzB"}
1
+ {"version":3,"file":"static-publish-rc.d.ts","sourceRoot":"","sources":["../../../../src/models/config/static-publish-rc.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,mBAAmB,GAAG;IAGhC,SAAS,EAAE,MAAM,CAAC;IAGlB,qBAAqB,EAAE,MAAM,CAAC;IAK9B,yBAAyB,EAAE,MAAM,CAAC;CACnC,CAAC;AAGF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,WAAW,EAAE,UAAU,CAAC;IACxB,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAGF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,2BAA2B,GACnC,8BAA8B,GAC9B,iCAAiC,CACpC;AAGD,MAAM,MAAM,oBAAoB,GAC9B,2BAA2B,GAAG,mBAAmB,CAAC;AAEpD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,oBAAoB,CAqBzE;AAGD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,EAAE,IAAI,CAAC;IAClB,EAAE,EAAE;QACF,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAChC,6BAA6B,GAAG,mBAAmB,CAAC;AAEtD,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,sBAAsB,CAyB7E;AAED,MAAM,MAAM,2BAA2B,GACnC,2BAA2B,GAC3B,6BAA6B,CAChC;AAED,MAAM,MAAM,eAAe,GACvB,oBAAoB,GACpB,sBAAsB,CACzB"}
@@ -30,7 +30,9 @@ export function isS3StorageConfigRc(rc) {
30
30
  if ('region' in rc.s3 && typeof rc.s3.region === 'string' &&
31
31
  'bucket' in rc.s3 && typeof rc.s3.bucket === 'string' && (!('endpoint' in rc.s3) ||
32
32
  rc.s3.endpoint === undefined ||
33
- typeof rc.s3.endpoint === 'string')) {
33
+ typeof rc.s3.endpoint === 'string') && (!('fastlyBackendName' in rc.s3) ||
34
+ rc.s3.fastlyBackendName === undefined ||
35
+ typeof rc.s3.fastlyBackendName === 'string')) {
34
36
  return true;
35
37
  }
36
38
  }
@@ -2,7 +2,7 @@
2
2
  * Copyright Fastly, Inc.
3
3
  * Licensed under the MIT license. See LICENSE file for details.
4
4
  */
5
- // This exists because some platforms such as AWS insist on lowercasing their metadata keys
5
+ // To work with some platforms such as S3 that insist on lowercasing their metadata keys
6
6
  export function getMetadataFieldValue(metadata, key) {
7
7
  return metadata[key] ?? metadata[key.toLowerCase()] ?? undefined;
8
8
  }
@@ -20,7 +20,7 @@ export function decodeAssetVariantMetadata(obj) {
20
20
  if (hash == null) {
21
21
  return null;
22
22
  }
23
- const numChunks = parseFloat(getMetadataFieldValue(obj, 'contentEncoding'));
23
+ const numChunks = parseInt(getMetadataFieldValue(obj, 'numChunks'), 10);
24
24
  const assetVariantMetadata = {
25
25
  size,
26
26
  hash,