@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
@@ -12,6 +12,7 @@ import { LoadConfigError, loadPublishContentConfigFile, loadStaticPublisherRcFil
12
12
  import { applyDefaults } from '../../util/data.js';
13
13
  import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
14
14
  import { ensureVariantFileExists } from '../../util/variants.js';
15
+ import { concurrentMap } from '../../util/retryable.js';
15
16
  import { loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
16
17
  // Storage key format:
17
18
  // <publishId>_index_<preview_id>.json
@@ -42,8 +43,17 @@ Optional:
42
43
  --root-dir=<dir> Directory to publish from. Overrides the config file setting.
43
44
  Default: rootDir from publish-content.config.js
44
45
 
46
+ --fastly-api-token=<token> Fastly API token for KV Store or cache access.
47
+ If not set, the tool will check:
48
+ 1. FASTLY_API_TOKEN environment variable
49
+ 2. The default profile in the Fastly CLI
50
+
45
51
  --overwrite-existing Always overwrite existing entries in storage, even if unchanged.
46
52
 
53
+ --brotli-quality=<0-11> Brotli quality for the 'br' variants. Overrides
54
+ brotliQuality in the config file.
55
+ Default: brotliQuality from publish-content.config.js, or 11
56
+
47
57
  Expiration:
48
58
  --expires-in=<duration> Expiration duration from now.
49
59
  Examples: 3d, 12h, 15m, 1w
@@ -61,25 +71,13 @@ KV Store Options:
61
71
  local files that will be used to simulate the KV Store
62
72
  with the local development environment.
63
73
 
64
- --fastly-api-token=<token> Fastly API token for KV Store access.
65
- If not set, the tool will check:
66
- 1. FASTLY_API_TOKEN environment variable
67
- 2. Logged-in Fastly CLI profile
68
-
69
74
  --kv-overwrite Alias for --overwrite-existing.
70
75
 
71
- S3 Storage Options:
72
- --aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
73
- --aws-secret-access-key=<key> interface with S3.
74
- If not set, the tool will check:
75
- 1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
76
- environment variables
77
- 2. The aws credentials file, see below
78
-
79
- --aws-profile=<profile> Profile within the aws credentials file.
80
- If not set, the tool will check:
81
- 1. AWS_PROFILE environment variable
82
- 2. The default profile, if set
76
+ S3 Storage Options (BETA):
77
+ --s3-access-key-id=<id> Access Key ID and Secret Access Key used to
78
+ --s3-secret-access-key=<key> interface with S3 or compatible storage.
79
+ If not set, the tool will check the S3_ACCESS_KEY_ID
80
+ and S3_SECRET_ACCESS_KEY environment variables.
83
81
 
84
82
  Global Options:
85
83
  -h, --help Show this help message and exit.
@@ -98,15 +96,15 @@ export async function action(actionArgs) {
98
96
  { name: 'collection-name', type: String, },
99
97
  { name: 'root-dir', type: String, },
100
98
  { name: 'overwrite-existing', type: Boolean },
99
+ { name: 'brotli-quality', type: String },
101
100
  { name: 'expires-in', type: String },
102
101
  { name: 'expires-at', type: String },
103
102
  { name: 'expires-never', type: Boolean },
104
103
  { name: 'local', type: Boolean },
105
104
  { name: 'fastly-api-token', type: String, },
106
105
  { name: 'kv-overwrite', type: Boolean },
107
- { name: 'aws-profile', type: String, },
108
- { name: 'aws-access-key-id', type: String, },
109
- { name: 'aws-secret-access-key', type: String, },
106
+ { name: 's3-access-key-id', type: String, },
107
+ { name: 's3-secret-access-key', type: String, },
110
108
  ];
111
109
  const parsed = parseCommandLine(actionArgs, optionDefinitions);
112
110
  if (parsed.needHelp) {
@@ -118,7 +116,7 @@ export async function action(actionArgs) {
118
116
  help();
119
117
  return;
120
118
  }
121
- const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['kv-overwrite']: _kvOverwrite, ['aws-profile']: awsProfile, ['aws-access-key-id']: awsAccessKeyId, ['aws-secret-access-key']: awsSecretAccessKey, } = parsed.commandLineOptions;
119
+ 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, } = parsed.commandLineOptions;
122
120
  const overwriteExisting = _overwriteExisting ?? _kvOverwrite;
123
121
  // compute-js-static-publisher cli is always run from the Compute application directory
124
122
  // in other words, the directory that contains `fastly.toml`.
@@ -155,6 +153,17 @@ export async function action(actionArgs) {
155
153
  process.exitCode = 1;
156
154
  return;
157
155
  }
156
+ // --brotli-quality overrides brotliQuality in the config file.
157
+ let brotliQualitySource = 'config';
158
+ if (brotliQualityValue !== undefined) {
159
+ if (typeof brotliQualityValue !== 'string' || !/^\d+$/.test(brotliQualityValue) || Number(brotliQualityValue) > 11) {
160
+ console.error(`❌ --brotli-quality must be an integer from 0 to 11.`);
161
+ process.exitCode = 1;
162
+ return;
163
+ }
164
+ publishContentConfig.brotliQuality = Number(brotliQualityValue);
165
+ brotliQualitySource = '--brotli-quality';
166
+ }
158
167
  const publicDirRoot = path.resolve(rootDir != null ? rootDir : publishContentConfig.rootDir);
159
168
  if ((computeAppDir + '/').startsWith(publicDirRoot + '/')) {
160
169
  if (verbose) {
@@ -174,6 +183,9 @@ export async function action(actionArgs) {
174
183
  return;
175
184
  }
176
185
  console.log(`✔️ Public directory '${rootRelative(publicDirRoot)}'.`);
186
+ if (publishContentConfig.brotliQuality != null) {
187
+ console.log(`✔️ Brotli quality: ${publishContentConfig.brotliQuality} (from ${brotliQualitySource})`);
188
+ }
177
189
  const publishId = staticPublisherRc.publishId;
178
190
  console.log(` | Publish ID: ${publishId}`);
179
191
  const defaultCollectionName = staticPublisherRc.defaultCollectionName;
@@ -187,9 +199,8 @@ export async function action(actionArgs) {
187
199
  computeAppDir,
188
200
  localMode,
189
201
  fastlyApiToken,
190
- awsProfile,
191
- awsAccessKeyId,
192
- awsSecretAccessKey,
202
+ s3AccessKeyId,
203
+ s3SecretAccessKey,
193
204
  });
194
205
  }
195
206
  catch (err) {
@@ -248,15 +259,35 @@ export async function action(actionArgs) {
248
259
  // and for serving using the local development server.
249
260
  const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
250
261
  fs.mkdirSync(storageContentDir, { recursive: true });
251
- // A list of items in storage at the end of the publishing.
252
- // Includes items that already exist as well. 'write' signifies
253
- // that the item is to be written
262
+ // The items to write to storage.
254
263
  const batch = new StorageProviderBatch();
255
264
  // Assets included in the publishing, keyed by asset key
256
265
  const assetsIndex = {};
257
- const baseHashToVariantMetadatasMap = new Map();
266
+ const baseHashToVariantKeepMap = new Map();
267
+ // #### Keys that are already in storage
268
+ // The key of a file is the hash of its content. If the key exists, storage
269
+ // already has the same content. Thus we do not compress, hash, or upload it again.
270
+ // In local mode, a key can refer to a working file that was deleted, so we do not list.
271
+ let existingKeys;
272
+ if (!overwriteExisting && !localMode) {
273
+ console.log(`🔎 Listing files that are already in storage...`);
274
+ existingKeys = new Set(await storageProvider.getStorageKeys(`${publishId}_files_`) ?? []);
275
+ console.log(`✅ Found ${existingKeys.size} key(s).`);
276
+ }
277
+ let existingVariantCount = 0;
278
+ function isVariantInStorage(variantKey, numChunks) {
279
+ if (existingKeys == null || !existingKeys.has(variantKey)) {
280
+ return false;
281
+ }
282
+ for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
283
+ if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
284
+ return false;
285
+ }
286
+ }
287
+ return true;
288
+ }
258
289
  // #### Iterate files
259
- for (const file of files) {
290
+ const fileResults = await concurrentMap(files, async (file) => {
260
291
  // #### asset key
261
292
  const assetKey = file.slice(publicDirRoot.length)
262
293
  // in Windows, assetKey will otherwise end up as \path\file.html
@@ -285,24 +316,28 @@ export async function action(actionArgs) {
285
316
  includeAsset = true;
286
317
  }
287
318
  if (!includeAsset) {
288
- continue;
319
+ return;
289
320
  }
290
321
  // #### Base file size, hash, last modified time
291
322
  const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
292
323
  console.log(`📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
293
324
  const stats = fs.statSync(file);
294
325
  const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
295
- // #### Metadata per variant
296
- let variantMetadatas = baseHashToVariantMetadatasMap.get(baseHash);
297
- if (variantMetadatas == null) {
298
- variantMetadatas = new Map();
299
- baseHashToVariantMetadatasMap.set(baseHash, variantMetadatas);
326
+ // #### Keep flag per variant
327
+ let variantKeeps = baseHashToVariantKeepMap.get(baseHash);
328
+ if (variantKeeps == null) {
329
+ variantKeeps = new Map();
330
+ baseHashToVariantKeepMap.set(baseHash, variantKeeps);
300
331
  }
332
+ // We know the number of chunks of the original before we read it. For a
333
+ // compressed variant, we know it only if the original fits in one chunk.
334
+ const baseNumChunks = storageProvider.calculateNumChunks(baseSize);
301
335
  const variantsToKeep = [];
302
336
  const variants = [
303
337
  'original',
304
338
  ...contentCompression,
305
339
  ];
340
+ const batchItems = [];
306
341
  for (const variant of variants) {
307
342
  let variantKey = `${publishId}_files_sha256_${baseHash}`;
308
343
  let variantFilename = `${baseHash}`;
@@ -311,78 +346,92 @@ export async function action(actionArgs) {
311
346
  variantFilename = `${variantFilename}_${variant}`;
312
347
  }
313
348
  const variantFilePath = path.resolve(storageContentDir, variantFilename);
314
- let variantMetadata = variantMetadatas.get(variant);
315
- if (variantMetadata != null) {
316
- console.log(` 🏃‍♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
349
+ let keep = variantKeeps.get(variant);
350
+ if (keep != null) {
351
+ if (verbose) {
352
+ console.log(` 🏃‍♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
353
+ }
354
+ }
355
+ else if ((variant === 'original' || baseNumChunks === 1) &&
356
+ isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
357
+ if (verbose) {
358
+ console.log(` ・ Asset found in storage with key "${variantKey}".`);
359
+ }
360
+ existingVariantCount++;
361
+ // We upload a compressed variant only if it is smaller than the
362
+ // original. Thus if it is in storage, the index keeps it.
363
+ keep = true;
364
+ variantKeeps.set(variant, keep);
317
365
  }
318
366
  else {
319
- if (!overwriteExisting) {
320
- const assetVariantMetadata = await storageProvider.getExistingAssetVariant(variantKey);
321
- if (assetVariantMetadata != null) {
322
- console.log(` ・ Asset found in storage with key "${variantKey}".`);
323
- // And we already know its hash and size.
324
- variantMetadata = Object.assign(assetVariantMetadata, { existsInKvStore: true });
325
- }
367
+ await ensureVariantFileExists(variantFilePath, variant, file, verbose, { brotliQuality: publishContentConfig.brotliQuality });
368
+ let contentEncoding, hash, size;
369
+ if (variant === 'original') {
370
+ contentEncoding = undefined;
371
+ hash = baseHash;
372
+ size = baseSize;
326
373
  }
327
- if (variantMetadata == null) {
328
- await ensureVariantFileExists(variantFilePath, variant, file);
329
- if (localMode) {
330
- console.log(` ・ Prepping asset for storage with key "${variantKey}".`);
331
- }
332
- let contentEncoding, hash, size;
333
- if (variant === 'original') {
334
- contentEncoding = undefined;
335
- hash = baseHash;
336
- size = baseSize;
337
- }
338
- else {
339
- contentEncoding = variant;
340
- ({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
341
- }
374
+ else {
375
+ contentEncoding = variant;
376
+ ({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
377
+ }
378
+ // Only keep variants whose file size actually ends up smaller than
379
+ // what we started with. Do not upload the other variants.
380
+ keep = variant === 'original' || size < baseSize;
381
+ variantKeeps.set(variant, keep);
382
+ if (keep) {
342
383
  const numChunks = storageProvider.calculateNumChunks(size);
343
- variantMetadata = {
344
- contentEncoding,
345
- size,
384
+ const metadataJson = {
385
+ size: String(size),
346
386
  hash,
347
- numChunks: numChunks > 1 ? numChunks : undefined,
348
- existsInKvStore: false,
349
387
  };
388
+ if (contentEncoding != null) {
389
+ metadataJson.contentEncoding = contentEncoding;
390
+ }
391
+ if (numChunks > 1) {
392
+ metadataJson.numChunks = String(numChunks);
393
+ }
394
+ batchItems.push({
395
+ size,
396
+ key: variantKey,
397
+ filePath: variantFilePath,
398
+ metadataJson,
399
+ });
350
400
  }
351
- variantMetadatas.set(variant, variantMetadata);
352
- const metadataJson = {
353
- size: String(variantMetadata.size),
354
- hash: variantMetadata.hash,
355
- };
356
- if (variantMetadata.contentEncoding != null) {
357
- metadataJson.contentEncoding = variantMetadata.contentEncoding;
358
- }
359
- if (variantMetadata.numChunks != null) {
360
- metadataJson.numChunks = String(variantMetadata.numChunks);
401
+ else if (verbose) {
402
+ console.log(` ・ Variant "${variantKey}" is not smaller than the original, not uploading.`);
361
403
  }
362
- batch.add({
363
- write: !variantMetadata.existsInKvStore,
364
- size: variantMetadata.size,
365
- key: variantKey,
366
- filePath: variantFilePath,
367
- metadataJson,
368
- });
369
404
  }
370
- // Only keep variants whose file size actually ends up smaller than
371
- // what we started with.
372
- if (variant !== 'original' && variantMetadata.size < baseSize) {
405
+ if (variant !== 'original' && keep) {
373
406
  variantsToKeep.push(variant);
374
407
  }
375
408
  }
376
- assetsIndex[assetKey] = {
377
- key: `sha256:${baseHash}`,
378
- size: baseSize,
379
- contentType: contentTypeTestResult.contentType,
380
- lastModifiedTime,
381
- variants: variantsToKeep,
409
+ return {
410
+ assetKey,
411
+ asset: {
412
+ key: `sha256:${baseHash}`,
413
+ size: baseSize,
414
+ contentType: contentTypeTestResult.contentType,
415
+ lastModifiedTime,
416
+ variants: variantsToKeep,
417
+ },
418
+ batchItems,
382
419
  };
420
+ });
421
+ for (const result of fileResults) {
422
+ if (result == null) {
423
+ continue;
424
+ }
425
+ assetsIndex[result.assetKey] = result.asset;
426
+ for (const batchItem of result.batchItems) {
427
+ batch.add(batchItem);
428
+ }
383
429
  }
384
430
  console.log(`✅ Scan complete.`);
385
- await storageProvider.applyBatch(batch);
431
+ if (existingKeys != null) {
432
+ console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
433
+ }
434
+ await storageProvider.applyBatch(batch, { existingKeys });
386
435
  // #### INDEX FILE
387
436
  console.log(`🗂️ Saving Index...`);
388
437
  const indexFileKey = `${publishId}_index_${collectionName}`;
@@ -458,5 +507,6 @@ export async function action(actionArgs) {
458
507
  const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
459
508
  await storageProvider.submitStorageEntry(settingsFileKey, settingsFilePath, JSON.stringify(serverSettings));
460
509
  console.log(`✅ Settings have been saved.`);
510
+ await storageProvider.purgeSurrogateKey(`${publishId}-${collectionName}`);
461
511
  console.log(`🎉 Completed.`);
462
512
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAsEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAopBhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAuEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyqBhD"}
@@ -12,7 +12,7 @@ import * as fs from 'node:fs';
12
12
  import { parseCommandLine } from '../../util/args.js';
13
13
  import { dotRelative, rootRelative } from '../../util/files.js';
14
14
  import { findComputeJsStaticPublisherVersion } from '../../util/package.js';
15
- import { resolveS3Hostname } from '../../util/s3.js';
15
+ import { findHostnameForAwsS3RegionAndBucket } from '../../util/s3.js';
16
16
  function help() {
17
17
  console.log(`\
18
18
 
@@ -26,8 +26,9 @@ Description:
26
26
  management mode.
27
27
 
28
28
  Options:
29
- --storage-mode <mode> (required) Storage mode for content storage.
30
- Can be "kv-store" or "s3".
29
+ --storage-mode <mode> Storage mode for content storage.
30
+ Can be "kv-store" or "s3" (BETA).
31
+ (default: kv-store)
31
32
  If --storage-mode=kv-store, then:
32
33
  --kv-store-name <name> (required) Name of the KV Store.
33
34
 
@@ -39,8 +40,8 @@ Options:
39
40
  --root-dir <path> (required) Path to static content (e.g., ./public)
40
41
  -o, --output <dir> Output directory for Compute app (default: ./compute-js)
41
42
  --static-publisher-working-dir <dir> Working directory for build artifacts (default: <output>/static-publisher)
42
- --publish-id <id> Advanced. Prefix for KV keys (default: "default")
43
43
  (default: ./compute-js/static-publisher)
44
+ --publish-id <id> Advanced. Prefix for KV keys (default: "default")
44
45
 
45
46
  Compute Service Metadata:
46
47
  --name <name> App name (for fastly.toml)
@@ -201,7 +202,7 @@ function buildOptions(packageJson, commandLineOptions) {
201
202
  }
202
203
  }
203
204
  {
204
- let autoExt = [];
205
+ let autoExt;
205
206
  const autoExtValue = commandLineOptions['auto-ext'];
206
207
  const asArray = Array.isArray(autoExtValue) ? autoExtValue : [autoExtValue];
207
208
  if (asArray.every((x) => typeof x === 'string')) {
@@ -334,8 +335,8 @@ function processPublicDirToken(filepath, publicDir) {
334
335
  export async function action(actionArgs) {
335
336
  const optionDefinitions = [
336
337
  { name: 'verbose', type: Boolean },
337
- // Required. Storage mode for content storage. Can be "kv-store" or "s3".
338
- { name: 'storage-mode', type: String, },
338
+ // Storage mode for content storage. Can be "kv-store" or "s3".
339
+ { name: 'storage-mode', type: String, defaultValue: 'kv-store', },
339
340
  // If storage-mode=kv-store, then:
340
341
  // Required. The name of a Fastly KV Store to hold the content assets.
341
342
  // It is also added to the fastly.toml that is generated.
@@ -504,6 +505,7 @@ export async function action(actionArgs) {
504
505
  else if (!fs.existsSync(spaFilename)) {
505
506
  console.log(`⚠️ Warning: Ignoring specified SPA file '${SPA}' does not exist.`);
506
507
  console.log(` * ${rootRelative(spaFilename)} does not exist.`);
508
+ spaFilename = undefined;
507
509
  }
508
510
  }
509
511
  const NOT_FOUND_PAGE = options.notFoundPage;
@@ -520,6 +522,7 @@ export async function action(actionArgs) {
520
522
  else if (!fs.existsSync(notFoundPageFilename)) {
521
523
  console.log(`⚠️ Warning: Ignoring specified Not Found file '${NOT_FOUND_PAGE}' as it does not exist.`);
522
524
  console.log(` * ${rootRelative(notFoundPageFilename)} does not exist.`);
525
+ notFoundPageFilename = undefined;
523
526
  }
524
527
  }
525
528
  const autoIndex = options.autoIndex;
@@ -540,7 +543,7 @@ export async function action(actionArgs) {
540
543
  const fastlyServiceId = options.serviceId;
541
544
  const storageMode = options.storageMode;
542
545
  if (!(storageMode === 'kv-store' || storageMode === 's3')) {
543
- console.error(`❌ required parameter --storage-mode must be set to 'kv-store' or 's3'.`);
546
+ console.error(`❌ parameter --storage-mode must be set to 'kv-store' or 's3'.`);
544
547
  process.exitCode = 1;
545
548
  return;
546
549
  }
@@ -569,7 +572,11 @@ export async function action(actionArgs) {
569
572
  }
570
573
  let s3Endpoint = options.s3Endpoint;
571
574
  if (s3Endpoint == null || s3Endpoint === '') {
572
- s3Endpoint = await resolveS3Hostname(s3Region, s3Bucket);
575
+ // If endpoint is not presented, we assume it's from AWS,
576
+ // and ask the SDK what the hostname would be.
577
+ // This is required because we need to add the hostname as a
578
+ // backend in the Compute service.
579
+ s3Endpoint = await findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
573
580
  if (s3Endpoint) {
574
581
  console.log('✅ S3 endpoint resolved:', s3Endpoint);
575
582
  }
@@ -614,7 +621,7 @@ export async function action(actionArgs) {
614
621
  console.log('KV Store Name :', kvStoreName);
615
622
  }
616
623
  else if (storageMode === 's3') {
617
- console.log('Storage Name : S3-compatible storage');
624
+ console.log('Storage Name : S3 (or compatible) storage (BETA)');
618
625
  console.log('S3 Region :', s3Region);
619
626
  console.log('S3 Bucket :', s3Bucket);
620
627
  console.log('S3 Endpoint :', String(s3EndpointUrl));
@@ -662,7 +669,7 @@ export async function action(actionArgs) {
662
669
  packageJsonScripts['fastly:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
663
670
  }
664
671
  else if (storageMode === 's3') {
665
- packageJsonScripts['publish'] = 'npx @fastly/compute-js-static-publish publish-content --local';
672
+ packageJsonScripts['s3:publish'] = 'npx @fastly/compute-js-static-publish publish-content';
666
673
  }
667
674
  resourceFiles['package.json'] = JSON.stringify({
668
675
  name,
@@ -671,7 +678,7 @@ export async function action(actionArgs) {
671
678
  author,
672
679
  type: 'module',
673
680
  devDependencies: {
674
- "@fastly/cli": "^12.0.0",
681
+ "@fastly/cli": "^16.0.0",
675
682
  '@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
676
683
  },
677
684
  dependencies: {
@@ -689,10 +696,15 @@ export async function action(actionArgs) {
689
696
  if (storageMode === 'kv-store') {
690
697
  const localServerKvStorePath = dotRelative(computeJsDir, path.resolve(staticPublisherWorkingDir, 'kvstore.json'));
691
698
  fastlyTomlLocalServer = /* language=text */ `\
699
+ [local_server]
700
+
692
701
  [local_server.kv_stores]
693
702
  ${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
694
703
  `;
695
704
  fastlyTomlSetup = /* language=text */ `\
705
+ [setup]
706
+
707
+ [setup.kv_stores]
696
708
  [setup.kv_stores.${kvStoreName}]
697
709
  `;
698
710
  // kvstore.json
@@ -700,24 +712,37 @@ ${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
700
712
  }
701
713
  else if (storageMode === 's3') {
702
714
  fastlyTomlLocalServer = /* language=text */ `\
715
+ [local_server]
716
+
703
717
  [local_server.secret_stores]
704
- [[local_server.secret_stores.AWS_CREDENTIALS]]
705
- key = "AWS_ACCESS_KEY_ID"
706
- env = "AWS_ACCESS_KEY_ID"
707
- [[local_server.secret_stores.AWS_CREDENTIALS]]
708
- key = "AWS_SECRET_ACCESS_KEY"
709
- env = "AWS_SECRET_ACCESS_KEY"
718
+ [[local_server.secret_stores.S3_CREDENTIALS]]
719
+ key = "S3_ACCESS_KEY_ID"
720
+ env = "S3_ACCESS_KEY_ID"
721
+ [[local_server.secret_stores.S3_CREDENTIALS]]
722
+ key = "S3_SECRET_ACCESS_KEY"
723
+ env = "S3_SECRET_ACCESS_KEY"
710
724
 
711
725
  [local_server.backends]
712
- [local_server.backends.aws]
726
+ [local_server.backends.s3_storage]
713
727
  url = "${String(s3EndpointUrl)}"
714
728
  override_host = "${s3EndpointUrl.hostname}"
715
729
  `;
716
730
  fastlyTomlSetup = /* language=text */ `\
717
- [setup.backends.aws]
731
+ [setup]
732
+
733
+ [setup.backends]
734
+ [setup.backends.s3_storage]
718
735
  address = "${s3EndpointUrl.hostname}"
719
736
  description = "S3 API endpoint"
720
737
  port = 443
738
+ [setup.secret_stores]
739
+ [setup.secret_stores.S3_CREDENTIALS]
740
+ description = "Credentials for S3 storage"
741
+ [setup.secret_stores.S3_CREDENTIALS.items]
742
+ [setup.secret_stores.S3_CREDENTIALS.items.S3_ACCESS_KEY_ID]
743
+ description = "Access Key ID"
744
+ [setup.secret_stores.S3_CREDENTIALS.items.S3_SECRET_ACCESS_KEY]
745
+ description = "Secret Access Key"
721
746
  `;
722
747
  }
723
748
  resourceFiles['fastly.toml'] = /* language=text */ `\
@@ -824,7 +849,8 @@ const config = {
824
849
  // excludeDotFiles: true,
825
850
  // includeWellKnown: true,
826
851
  // assetInclusionTest: (assetKey) => true,
827
- // contentCompression: [ 'br', 'gzip' ],
852
+ // contentCompression: [ 'br', 'gzip' ],
853
+ // brotliQuality: 11,
828
854
  // contentTypes: [
829
855
  // { test: /.custom$/, contentType: 'application/x-custom', text: false },
830
856
  // ],
@@ -906,25 +932,21 @@ To publish your content to your S3-compatible bucket
906
932
  Bucket: ${s3Bucket}
907
933
  Endpoint: ${String(s3EndpointUrl)}
908
934
 
909
- Using an AWS profile set with "aws configure", type:
910
- cd ${COMPUTE_JS_DIR}
911
- AWS_PROFILE=xxxx npm run publish
912
-
913
- Using AWS IAM credentials, type:
935
+ Using an access key ID and secret access key for S3, type:
914
936
  cd ${COMPUTE_JS_DIR}
915
- AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npm run publish
937
+ S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run s3:publish
916
938
 
917
939
  To run your Compute application locally
918
940
 
919
941
  Run the following commands:
920
942
  cd ${COMPUTE_JS_DIR}
921
- AWS_ACCESS_KEY_ID=xxxx AWS_SECRET_ACCESS_KEY=xxxx npm run dev:start
943
+ S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run dev:start
922
944
 
923
945
  To build and deploy to your Compute service:
924
946
 
925
- Create a Secret Store in your account named AWS_CREDENTIALS, and set the following values:
926
- AWS_ACCESS_KEY_ID: xxxx
927
- AWS_SECRET_ACCESS_KEY: xxxx
947
+ Create a Secret Store in your account named S3_CREDENTIALS, and set the following values:
948
+ S3_ACCESS_KEY_ID: xxxx
949
+ S3_SECRET_ACCESS_KEY: xxxx
928
950
 
929
951
  Run the following commands:
930
952
  cd ${COMPUTE_JS_DIR}
@@ -1,3 +1,4 @@
1
+ import type { CompressOptions } from './index.js';
1
2
  export declare const key = "br";
2
- export declare function compressTo(src: string, dest: string): Promise<void>;
3
+ export declare function compressTo(src: string, dest: string, options?: CompressOptions): Promise<void>;
3
4
  //# sourceMappingURL=brotli.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/brotli.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,GAAG,OAAO,CAAC;AAExB,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzE"}
1
+ {"version":3,"file":"brotli.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/brotli.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,GAAG,OAAO,CAAC;AAMxB,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAexG"}
@@ -4,9 +4,20 @@
4
4
  */
5
5
  import fs from 'node:fs';
6
6
  import zlib from 'node:zlib';
7
+ import { promisify } from 'node:util';
7
8
  export const key = 'br';
8
- export async function compressTo(src, dest) {
9
- const buffer = fs.readFileSync(src);
10
- const resultBuffer = zlib.brotliCompressSync(buffer);
11
- fs.writeFileSync(dest, resultBuffer);
9
+ // The async version runs on the libuv thread pool, so that more than one
10
+ // file can be compressed at the same time.
11
+ const brotliCompress = promisify(zlib.brotliCompress);
12
+ export async function compressTo(src, dest, options = {}) {
13
+ const buffer = await fs.promises.readFile(src);
14
+ // If no quality is specified, use the zlib default (11, the maximum).
15
+ const zlibOptions = {};
16
+ if (options.brotliQuality != null) {
17
+ zlibOptions.params = {
18
+ [zlib.constants.BROTLI_PARAM_QUALITY]: options.brotliQuality,
19
+ };
20
+ }
21
+ const resultBuffer = await brotliCompress(buffer, zlibOptions);
22
+ await fs.promises.writeFile(dest, resultBuffer);
12
23
  }
@@ -1,3 +1,4 @@
1
+ import type { CompressOptions } from './index.js';
1
2
  export declare const key = "gzip";
2
- export declare function compressTo(src: string, dest: string): Promise<void>;
3
+ export declare function compressTo(src: string, dest: string, _options?: CompressOptions): Promise<void>;
3
4
  //# sourceMappingURL=gzip.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/gzip.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,GAAG,SAAS,CAAC;AAE1B,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzE"}
1
+ {"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../../../../src/cli/compression/gzip.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,eAAO,MAAM,GAAG,SAAS,CAAC;AAM1B,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzG"}
@@ -4,9 +4,13 @@
4
4
  */
5
5
  import fs from 'node:fs';
6
6
  import zlib from 'node:zlib';
7
+ import { promisify } from 'node:util';
7
8
  export const key = 'gzip';
8
- export async function compressTo(src, dest) {
9
- const buffer = fs.readFileSync(src);
10
- const resultBuffer = zlib.gzipSync(buffer);
11
- fs.writeFileSync(dest, resultBuffer);
9
+ // The async version runs on the libuv thread pool, so that more than one
10
+ // file can be compressed at the same time.
11
+ const gzip = promisify(zlib.gzip);
12
+ export async function compressTo(src, dest, _options = {}) {
13
+ const buffer = await fs.promises.readFile(src);
14
+ const resultBuffer = await gzip(buffer);
15
+ await fs.promises.writeFile(dest, resultBuffer);
12
16
  }