@fastly/compute-js-static-publish 8.0.0-beta.7 → 8.0.0-beta.9
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.
- package/README.md +18 -4
- package/README.short.md +18 -4
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +15 -21
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +11 -20
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +5 -12
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +10 -19
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +10 -19
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -19
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +5 -12
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +93 -80
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +31 -29
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +3 -5
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +3 -8
- package/build/cli/cli/storage/kv-store-provider.d.ts +4 -5
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +38 -66
- package/build/cli/cli/storage/s3-storage-provider.d.ts +3 -5
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +35 -46
- package/build/cli/cli/storage/storage-provider.d.ts +7 -8
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/content-types.d.ts.map +1 -1
- package/build/cli/cli/util/content-types.js +4 -1
- package/build/cli/cli/util/kv-store-items.d.ts +12 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +49 -0
- package/build/cli/cli/util/kv-store.d.ts +6 -0
- package/build/cli/cli/util/kv-store.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store.js +39 -2
- package/build/cli/cli/util/retryable.d.ts +2 -1
- package/build/cli/cli/util/retryable.d.ts.map +1 -1
- package/build/cli/cli/util/retryable.js +34 -1
- package/build/cli/cli/util/s3-credentials.d.ts +11 -0
- package/build/cli/cli/util/s3-credentials.d.ts.map +1 -0
- package/build/cli/cli/util/s3-credentials.js +38 -0
- package/build/cli/cli/util/s3.d.ts +1 -1
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +1 -1
- package/build/cli/models/assets/index.js +1 -1
- package/build/cli/models/metadata/index.js +1 -1
- package/build/server/models/assets/index.js +1 -1
- package/build/server/models/metadata/index.js +1 -1
- package/build/server/server/index.d.ts +1 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +1 -1
- package/build/server/server/storage/s3-storage-provider.d.ts +7 -7
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +28 -28
- package/package.json +2 -3
- package/build/cli/cli/util/aws-credentials.d.ts +0 -12
- package/build/cli/cli/util/aws-credentials.d.ts.map +0 -1
- 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
|
|
@@ -45,7 +46,7 @@ Optional:
|
|
|
45
46
|
--fastly-api-token=<token> Fastly API token for KV Store or cache access.
|
|
46
47
|
If not set, the tool will check:
|
|
47
48
|
1. FASTLY_API_TOKEN environment variable
|
|
48
|
-
2.
|
|
49
|
+
2. The default profile in the Fastly CLI
|
|
49
50
|
|
|
50
51
|
--overwrite-existing Always overwrite existing entries in storage, even if unchanged.
|
|
51
52
|
|
|
@@ -69,17 +70,10 @@ KV Store Options:
|
|
|
69
70
|
--kv-overwrite Alias for --overwrite-existing.
|
|
70
71
|
|
|
71
72
|
S3 Storage Options (BETA):
|
|
72
|
-
--
|
|
73
|
-
--
|
|
74
|
-
If not set, the tool will check
|
|
75
|
-
|
|
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
|
|
73
|
+
--s3-access-key-id=<id> Access Key ID and Secret Access Key used to
|
|
74
|
+
--s3-secret-access-key=<key> interface with S3 or compatible storage.
|
|
75
|
+
If not set, the tool will check the S3_ACCESS_KEY_ID
|
|
76
|
+
and S3_SECRET_ACCESS_KEY environment variables.
|
|
83
77
|
|
|
84
78
|
Global Options:
|
|
85
79
|
-h, --help Show this help message and exit.
|
|
@@ -104,9 +98,8 @@ export async function action(actionArgs) {
|
|
|
104
98
|
{ name: 'local', type: Boolean },
|
|
105
99
|
{ name: 'fastly-api-token', type: String, },
|
|
106
100
|
{ name: 'kv-overwrite', type: Boolean },
|
|
107
|
-
{ name: '
|
|
108
|
-
{ name: '
|
|
109
|
-
{ name: 'aws-secret-access-key', type: String, },
|
|
101
|
+
{ name: 's3-access-key-id', type: String, },
|
|
102
|
+
{ name: 's3-secret-access-key', type: String, },
|
|
110
103
|
];
|
|
111
104
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
112
105
|
if (parsed.needHelp) {
|
|
@@ -118,7 +111,7 @@ export async function action(actionArgs) {
|
|
|
118
111
|
help();
|
|
119
112
|
return;
|
|
120
113
|
}
|
|
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, ['
|
|
114
|
+
const { verbose, config: configFilePathValue, ['collection-name']: collectionNameValue, ['root-dir']: rootDir, ['overwrite-existing']: _overwriteExisting, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['kv-overwrite']: _kvOverwrite, ['s3-access-key-id']: s3AccessKeyId, ['s3-secret-access-key']: s3SecretAccessKey, } = parsed.commandLineOptions;
|
|
122
115
|
const overwriteExisting = _overwriteExisting ?? _kvOverwrite;
|
|
123
116
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
124
117
|
// in other words, the directory that contains `fastly.toml`.
|
|
@@ -187,9 +180,8 @@ export async function action(actionArgs) {
|
|
|
187
180
|
computeAppDir,
|
|
188
181
|
localMode,
|
|
189
182
|
fastlyApiToken,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
awsSecretAccessKey,
|
|
183
|
+
s3AccessKeyId,
|
|
184
|
+
s3SecretAccessKey,
|
|
193
185
|
});
|
|
194
186
|
}
|
|
195
187
|
catch (err) {
|
|
@@ -248,15 +240,35 @@ export async function action(actionArgs) {
|
|
|
248
240
|
// and for serving using the local development server.
|
|
249
241
|
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
250
242
|
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
251
|
-
//
|
|
252
|
-
// Includes items that already exist as well. 'write' signifies
|
|
253
|
-
// that the item is to be written
|
|
243
|
+
// The items to write to storage.
|
|
254
244
|
const batch = new StorageProviderBatch();
|
|
255
245
|
// Assets included in the publishing, keyed by asset key
|
|
256
246
|
const assetsIndex = {};
|
|
257
|
-
const
|
|
247
|
+
const baseHashToVariantKeepMap = new Map();
|
|
248
|
+
// #### Keys that are already in storage
|
|
249
|
+
// The key of a file is the hash of its content. If the key exists, storage
|
|
250
|
+
// already has the same content. Thus we do not compress, hash, or upload it again.
|
|
251
|
+
// In local mode, a key can refer to a working file that was deleted, so we do not list.
|
|
252
|
+
let existingKeys;
|
|
253
|
+
if (!overwriteExisting && !localMode) {
|
|
254
|
+
console.log(`🔎 Listing files that are already in storage...`);
|
|
255
|
+
existingKeys = new Set(await storageProvider.getStorageKeys(`${publishId}_files_`) ?? []);
|
|
256
|
+
console.log(`✅ Found ${existingKeys.size} key(s).`);
|
|
257
|
+
}
|
|
258
|
+
let existingVariantCount = 0;
|
|
259
|
+
function isVariantInStorage(variantKey, numChunks) {
|
|
260
|
+
if (existingKeys == null || !existingKeys.has(variantKey)) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
for (let chunkIndex = 1; chunkIndex < numChunks; chunkIndex++) {
|
|
264
|
+
if (!existingKeys.has(`${variantKey}_${chunkIndex}`)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
258
270
|
// #### Iterate files
|
|
259
|
-
const
|
|
271
|
+
const fileResults = await concurrentMap(files, async (file) => {
|
|
260
272
|
// #### asset key
|
|
261
273
|
const assetKey = file.slice(publicDirRoot.length)
|
|
262
274
|
// in Windows, assetKey will otherwise end up as \path\file.html
|
|
@@ -292,12 +304,15 @@ export async function action(actionArgs) {
|
|
|
292
304
|
console.log(`📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
|
|
293
305
|
const stats = fs.statSync(file);
|
|
294
306
|
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
295
|
-
// ####
|
|
296
|
-
let
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
307
|
+
// #### Keep flag per variant
|
|
308
|
+
let variantKeeps = baseHashToVariantKeepMap.get(baseHash);
|
|
309
|
+
if (variantKeeps == null) {
|
|
310
|
+
variantKeeps = new Map();
|
|
311
|
+
baseHashToVariantKeepMap.set(baseHash, variantKeeps);
|
|
300
312
|
}
|
|
313
|
+
// We know the number of chunks of the original before we read it. For a
|
|
314
|
+
// compressed variant, we know it only if the original fits in one chunk.
|
|
315
|
+
const baseNumChunks = storageProvider.calculateNumChunks(baseSize);
|
|
301
316
|
const variantsToKeep = [];
|
|
302
317
|
const variants = [
|
|
303
318
|
'original',
|
|
@@ -312,67 +327,63 @@ export async function action(actionArgs) {
|
|
|
312
327
|
variantFilename = `${variantFilename}_${variant}`;
|
|
313
328
|
}
|
|
314
329
|
const variantFilePath = path.resolve(storageContentDir, variantFilename);
|
|
315
|
-
let
|
|
316
|
-
if (
|
|
330
|
+
let keep = variantKeeps.get(variant);
|
|
331
|
+
if (keep != null) {
|
|
317
332
|
if (verbose) {
|
|
318
333
|
console.log(` 🏃♂️ Asset "${variantKey}" is identical to an item we already know about, reusing existing copy.`);
|
|
319
334
|
}
|
|
320
335
|
}
|
|
336
|
+
else if ((variant === 'original' || baseNumChunks === 1) &&
|
|
337
|
+
isVariantInStorage(variantKey, variant === 'original' ? baseNumChunks : 1)) {
|
|
338
|
+
if (verbose) {
|
|
339
|
+
console.log(` ・ Asset found in storage with key "${variantKey}".`);
|
|
340
|
+
}
|
|
341
|
+
existingVariantCount++;
|
|
342
|
+
// We upload a compressed variant only if it is smaller than the
|
|
343
|
+
// original. Thus if it is in storage, the index keeps it.
|
|
344
|
+
keep = true;
|
|
345
|
+
variantKeeps.set(variant, keep);
|
|
346
|
+
}
|
|
321
347
|
else {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
// And we already know its hash and size.
|
|
329
|
-
variantMetadata = Object.assign(assetVariantMetadata, { existsInKvStore: true });
|
|
330
|
-
}
|
|
348
|
+
await ensureVariantFileExists(variantFilePath, variant, file, verbose);
|
|
349
|
+
let contentEncoding, hash, size;
|
|
350
|
+
if (variant === 'original') {
|
|
351
|
+
contentEncoding = undefined;
|
|
352
|
+
hash = baseHash;
|
|
353
|
+
size = baseSize;
|
|
331
354
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
else {
|
|
342
|
-
contentEncoding = variant;
|
|
343
|
-
({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
|
|
344
|
-
}
|
|
355
|
+
else {
|
|
356
|
+
contentEncoding = variant;
|
|
357
|
+
({ hash, size } = await calculateFileSizeAndHash(variantFilePath));
|
|
358
|
+
}
|
|
359
|
+
// Only keep variants whose file size actually ends up smaller than
|
|
360
|
+
// what we started with. Do not upload the other variants.
|
|
361
|
+
keep = variant === 'original' || size < baseSize;
|
|
362
|
+
variantKeeps.set(variant, keep);
|
|
363
|
+
if (keep) {
|
|
345
364
|
const numChunks = storageProvider.calculateNumChunks(size);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
size,
|
|
365
|
+
const metadataJson = {
|
|
366
|
+
size: String(size),
|
|
349
367
|
hash,
|
|
350
|
-
numChunks: numChunks > 1 ? numChunks : undefined,
|
|
351
|
-
existsInKvStore: false,
|
|
352
368
|
};
|
|
369
|
+
if (contentEncoding != null) {
|
|
370
|
+
metadataJson.contentEncoding = contentEncoding;
|
|
371
|
+
}
|
|
372
|
+
if (numChunks > 1) {
|
|
373
|
+
metadataJson.numChunks = String(numChunks);
|
|
374
|
+
}
|
|
375
|
+
batchItems.push({
|
|
376
|
+
size,
|
|
377
|
+
key: variantKey,
|
|
378
|
+
filePath: variantFilePath,
|
|
379
|
+
metadataJson,
|
|
380
|
+
});
|
|
353
381
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
size: String(variantMetadata.size),
|
|
357
|
-
hash: variantMetadata.hash,
|
|
358
|
-
};
|
|
359
|
-
if (variantMetadata.contentEncoding != null) {
|
|
360
|
-
metadataJson.contentEncoding = variantMetadata.contentEncoding;
|
|
361
|
-
}
|
|
362
|
-
if (variantMetadata.numChunks != null) {
|
|
363
|
-
metadataJson.numChunks = String(variantMetadata.numChunks);
|
|
382
|
+
else if (verbose) {
|
|
383
|
+
console.log(` ・ Variant "${variantKey}" is not smaller than the original, not uploading.`);
|
|
364
384
|
}
|
|
365
|
-
batchItems.push({
|
|
366
|
-
write: !variantMetadata.existsInKvStore,
|
|
367
|
-
size: variantMetadata.size,
|
|
368
|
-
key: variantKey,
|
|
369
|
-
filePath: variantFilePath,
|
|
370
|
-
metadataJson,
|
|
371
|
-
});
|
|
372
385
|
}
|
|
373
|
-
|
|
374
|
-
// what we started with.
|
|
375
|
-
if (variant !== 'original' && variantMetadata.size < baseSize) {
|
|
386
|
+
if (variant !== 'original' && keep) {
|
|
376
387
|
variantsToKeep.push(variant);
|
|
377
388
|
}
|
|
378
389
|
}
|
|
@@ -388,7 +399,6 @@ export async function action(actionArgs) {
|
|
|
388
399
|
batchItems,
|
|
389
400
|
};
|
|
390
401
|
});
|
|
391
|
-
const fileResults = await Promise.all(filePromises);
|
|
392
402
|
for (const result of fileResults) {
|
|
393
403
|
if (result == null) {
|
|
394
404
|
continue;
|
|
@@ -399,7 +409,10 @@ export async function action(actionArgs) {
|
|
|
399
409
|
}
|
|
400
410
|
}
|
|
401
411
|
console.log(`✅ Scan complete.`);
|
|
402
|
-
|
|
412
|
+
if (existingKeys != null) {
|
|
413
|
+
console.log(` | ${existingVariantCount} variant(s) already in storage, ${batch.storageProviderBatchEntries.length} to upload.`);
|
|
414
|
+
}
|
|
415
|
+
await storageProvider.applyBatch(batch, { existingKeys });
|
|
403
416
|
// #### INDEX FILE
|
|
404
417
|
console.log(`🗂️ Saving Index...`);
|
|
405
418
|
const indexFileKey = `${publishId}_index_${collectionName}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAuEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,
|
|
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,iBAwqBhD"}
|
|
@@ -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 {
|
|
15
|
+
import { findHostnameForAwsS3RegionAndBucket } from '../../util/s3.js';
|
|
16
16
|
function help() {
|
|
17
17
|
console.log(`\
|
|
18
18
|
|
|
@@ -202,7 +202,7 @@ function buildOptions(packageJson, commandLineOptions) {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
{
|
|
205
|
-
let autoExt
|
|
205
|
+
let autoExt;
|
|
206
206
|
const autoExtValue = commandLineOptions['auto-ext'];
|
|
207
207
|
const asArray = Array.isArray(autoExtValue) ? autoExtValue : [autoExtValue];
|
|
208
208
|
if (asArray.every((x) => typeof x === 'string')) {
|
|
@@ -505,6 +505,7 @@ export async function action(actionArgs) {
|
|
|
505
505
|
else if (!fs.existsSync(spaFilename)) {
|
|
506
506
|
console.log(`⚠️ Warning: Ignoring specified SPA file '${SPA}' does not exist.`);
|
|
507
507
|
console.log(` * ${rootRelative(spaFilename)} does not exist.`);
|
|
508
|
+
spaFilename = undefined;
|
|
508
509
|
}
|
|
509
510
|
}
|
|
510
511
|
const NOT_FOUND_PAGE = options.notFoundPage;
|
|
@@ -521,6 +522,7 @@ export async function action(actionArgs) {
|
|
|
521
522
|
else if (!fs.existsSync(notFoundPageFilename)) {
|
|
522
523
|
console.log(`⚠️ Warning: Ignoring specified Not Found file '${NOT_FOUND_PAGE}' as it does not exist.`);
|
|
523
524
|
console.log(` * ${rootRelative(notFoundPageFilename)} does not exist.`);
|
|
525
|
+
notFoundPageFilename = undefined;
|
|
524
526
|
}
|
|
525
527
|
}
|
|
526
528
|
const autoIndex = options.autoIndex;
|
|
@@ -570,7 +572,11 @@ export async function action(actionArgs) {
|
|
|
570
572
|
}
|
|
571
573
|
let s3Endpoint = options.s3Endpoint;
|
|
572
574
|
if (s3Endpoint == null || s3Endpoint === '') {
|
|
573
|
-
|
|
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);
|
|
574
580
|
if (s3Endpoint) {
|
|
575
581
|
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
576
582
|
}
|
|
@@ -615,7 +621,7 @@ export async function action(actionArgs) {
|
|
|
615
621
|
console.log('KV Store Name :', kvStoreName);
|
|
616
622
|
}
|
|
617
623
|
else if (storageMode === 's3') {
|
|
618
|
-
console.log('Storage Name : S3
|
|
624
|
+
console.log('Storage Name : S3 (or compatible) storage (BETA)');
|
|
619
625
|
console.log('S3 Region :', s3Region);
|
|
620
626
|
console.log('S3 Bucket :', s3Bucket);
|
|
621
627
|
console.log('S3 Endpoint :', String(s3EndpointUrl));
|
|
@@ -672,7 +678,7 @@ export async function action(actionArgs) {
|
|
|
672
678
|
author,
|
|
673
679
|
type: 'module',
|
|
674
680
|
devDependencies: {
|
|
675
|
-
"@fastly/cli": "^
|
|
681
|
+
"@fastly/cli": "^16.0.0",
|
|
676
682
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
677
683
|
},
|
|
678
684
|
dependencies: {
|
|
@@ -709,15 +715,15 @@ ${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
|
709
715
|
[local_server]
|
|
710
716
|
|
|
711
717
|
[local_server.secret_stores]
|
|
712
|
-
[[local_server.secret_stores.
|
|
713
|
-
key = "
|
|
714
|
-
env = "
|
|
715
|
-
[[local_server.secret_stores.
|
|
716
|
-
key = "
|
|
717
|
-
env = "
|
|
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"
|
|
718
724
|
|
|
719
725
|
[local_server.backends]
|
|
720
|
-
[local_server.backends.
|
|
726
|
+
[local_server.backends.s3_storage]
|
|
721
727
|
url = "${String(s3EndpointUrl)}"
|
|
722
728
|
override_host = "${s3EndpointUrl.hostname}"
|
|
723
729
|
`;
|
|
@@ -725,18 +731,18 @@ override_host = "${s3EndpointUrl.hostname}"
|
|
|
725
731
|
[setup]
|
|
726
732
|
|
|
727
733
|
[setup.backends]
|
|
728
|
-
[setup.backends.
|
|
734
|
+
[setup.backends.s3_storage]
|
|
729
735
|
address = "${s3EndpointUrl.hostname}"
|
|
730
736
|
description = "S3 API endpoint"
|
|
731
737
|
port = 443
|
|
732
738
|
[setup.secret_stores]
|
|
733
|
-
[setup.secret_stores.
|
|
739
|
+
[setup.secret_stores.S3_CREDENTIALS]
|
|
734
740
|
description = "Credentials for S3 storage"
|
|
735
|
-
[setup.secret_stores.
|
|
736
|
-
[setup.secret_stores.
|
|
737
|
-
description = "
|
|
738
|
-
[setup.secret_stores.
|
|
739
|
-
description = "
|
|
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"
|
|
740
746
|
`;
|
|
741
747
|
}
|
|
742
748
|
resourceFiles['fastly.toml'] = /* language=text */ `\
|
|
@@ -925,25 +931,21 @@ To publish your content to your S3-compatible bucket
|
|
|
925
931
|
Bucket: ${s3Bucket}
|
|
926
932
|
Endpoint: ${String(s3EndpointUrl)}
|
|
927
933
|
|
|
928
|
-
Using an
|
|
929
|
-
cd ${COMPUTE_JS_DIR}
|
|
930
|
-
AWS_PROFILE=xxxx npm run s3:publish
|
|
931
|
-
|
|
932
|
-
Using AWS IAM credentials, type:
|
|
934
|
+
Using an access key ID and secret access key for S3, type:
|
|
933
935
|
cd ${COMPUTE_JS_DIR}
|
|
934
|
-
|
|
936
|
+
S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run s3:publish
|
|
935
937
|
|
|
936
938
|
To run your Compute application locally
|
|
937
939
|
|
|
938
940
|
Run the following commands:
|
|
939
941
|
cd ${COMPUTE_JS_DIR}
|
|
940
|
-
|
|
942
|
+
S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run dev:start
|
|
941
943
|
|
|
942
944
|
To build and deploy to your Compute service:
|
|
943
945
|
|
|
944
|
-
Create a Secret Store in your account named
|
|
945
|
-
|
|
946
|
-
|
|
946
|
+
Create a Secret Store in your account named S3_CREDENTIALS, and set the following values:
|
|
947
|
+
S3_ACCESS_KEY_ID: xxxx
|
|
948
|
+
S3_SECRET_ACCESS_KEY: xxxx
|
|
947
949
|
|
|
948
950
|
Run the following commands:
|
|
949
951
|
cd ${COMPUTE_JS_DIR}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
1
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type ApplyBatchOptions } from './storage-provider.js';
|
|
3
2
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
4
3
|
export declare class KvStoreLocalProvider implements StorageProvider {
|
|
5
4
|
constructor(storeFile: string, computeAppDir: string);
|
|
@@ -10,12 +9,11 @@ export declare class KvStoreLocalProvider implements StorageProvider {
|
|
|
10
9
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
11
10
|
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
12
11
|
deleteStorageEntry(key: string): Promise<void>;
|
|
13
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
12
|
+
applyBatch(batch: StorageProviderBatch, _options?: ApplyBatchOptions): Promise<void>;
|
|
14
13
|
doConcurrentParallel<TObject extends {
|
|
15
14
|
key: string;
|
|
16
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
15
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
17
16
|
calculateNumChunks(size: number): number;
|
|
18
|
-
getExistingAssetVariant(_variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
19
17
|
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
20
18
|
}
|
|
21
19
|
//# sourceMappingURL=kv-store-local-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"AA0BA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,kBAAkB,EAAE,sBAkBhC,CAAC;AAEF,qBAAa,oBAAqB,YAAW,eAAe;gBAExD,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM;IAMvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAEzB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAQzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAc1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe9D,kBAAkB,CACtB,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;IAsBV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,QAAQ,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBxF,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,CAAC,EAAE,MAAM,EACtB,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAYhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAE9D"}
|
|
@@ -64,7 +64,7 @@ export class KvStoreLocalProvider {
|
|
|
64
64
|
async deleteStorageEntry(key) {
|
|
65
65
|
await localKvStoreDeleteEntry(this.storeFile, key);
|
|
66
66
|
}
|
|
67
|
-
async applyBatch(batch) {
|
|
67
|
+
async applyBatch(batch, _options = {}) {
|
|
68
68
|
console.log(`🍪 Chunking large files...`);
|
|
69
69
|
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
70
70
|
console.log(`✅ Large files have been chunked.`);
|
|
@@ -72,17 +72,12 @@ export class KvStoreLocalProvider {
|
|
|
72
72
|
writeKVStoreEntriesForLocal(this.storeFile, this.computeAppDir, batch.storageProviderBatchEntries);
|
|
73
73
|
console.log(`✅ Wrote KV Store entries for local server.`);
|
|
74
74
|
}
|
|
75
|
-
async doConcurrentParallel(objects, fn, maxConcurrent) {
|
|
76
|
-
await concurrentParallel(objects, fn, () => null, maxConcurrent);
|
|
75
|
+
async doConcurrentParallel(objects, fn, maxConcurrent, throwOnError = false) {
|
|
76
|
+
await concurrentParallel(objects, fn, () => null, maxConcurrent, throwOnError);
|
|
77
77
|
}
|
|
78
78
|
calculateNumChunks(size) {
|
|
79
79
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
80
80
|
}
|
|
81
|
-
async getExistingAssetVariant(_variantKey) {
|
|
82
|
-
// The purpose of this function is to use a HEAD request against storage
|
|
83
|
-
// to save time by checking for an existing item. This is not applicable for local.
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
81
|
async purgeSurrogateKey(_surrogateKey) {
|
|
87
82
|
}
|
|
88
83
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
1
|
import { type FastlyApiContext } from '../util/api-token.js';
|
|
3
2
|
import { type KvStoreEntryInfo } from '../util/kv-store.js';
|
|
4
|
-
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
3
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch, type StorageProviderBatchEntry, type ApplyBatchOptions } from './storage-provider.js';
|
|
5
4
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
6
5
|
export declare class KvStoreProvider implements StorageProvider {
|
|
7
6
|
constructor(storeName: string, fastlyApiToken: string);
|
|
@@ -12,12 +11,12 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
12
11
|
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
13
12
|
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
14
13
|
deleteStorageEntry(key: string): Promise<void>;
|
|
15
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
14
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
|
+
uploadEntries(entries: StorageProviderBatchEntry[]): Promise<void>;
|
|
16
16
|
doConcurrentParallel<TObject extends {
|
|
17
17
|
key: string;
|
|
18
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
18
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
19
19
|
calculateNumChunks(size: number): number;
|
|
20
|
-
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
21
20
|
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
22
21
|
}
|
|
23
22
|
export declare function kvStoreEntryToStorageEntry(kvStoreEntry: KvStoreEntryInfo): StorageEntry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"
|
|
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,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,kBAAkB,EAAE,sBAsBhC,CAAC;AAEF,qBAAa,eAAgB,YAAW,eAAe;gBAEnD,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM;IAMxB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IAEd,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAUzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAiB9D,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;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,GAAG,OAAO,CAAC,IAAI,CAAC;IA0ClE,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;IAIlC,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAE9D;AAED,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,gBAAgB,gBAuB/B;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
|