@fastly/compute-js-static-publish 8.0.0-beta.2 → 8.0.0-beta.20
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 +19 -5
- package/README.short.md +19 -5
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +17 -24
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +13 -23
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +7 -15
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +12 -22
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +12 -22
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +12 -22
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +7 -15
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +201 -92
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +54 -32
- package/build/cli/cli/compression/brotli.d.ts +2 -1
- package/build/cli/cli/compression/brotli.d.ts.map +1 -1
- package/build/cli/cli/compression/brotli.js +15 -4
- package/build/cli/cli/compression/gzip.d.ts +2 -1
- package/build/cli/cli/compression/gzip.d.ts.map +1 -1
- package/build/cli/cli/compression/gzip.js +8 -4
- package/build/cli/cli/compression/index.d.ts +4 -1
- package/build/cli/cli/compression/index.d.ts.map +1 -1
- package/build/cli/cli/index.js +8 -0
- 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 +6 -6
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +54 -51
- package/build/cli/cli/storage/storage-provider.d.ts +9 -8
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +13 -0
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.js +0 -28
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +8 -1
- package/build/cli/cli/util/content-types.d.ts.map +1 -1
- package/build/cli/cli/util/content-types.js +5 -2
- 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/purge.d.ts +19 -0
- package/build/cli/cli/util/purge.d.ts.map +1 -0
- package/build/cli/cli/util/purge.js +83 -0
- 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/cli/util/service-id.d.ts +10 -0
- package/build/cli/cli/util/service-id.d.ts.map +1 -0
- package/build/cli/cli/util/service-id.js +26 -0
- package/build/cli/cli/util/variants.d.ts +2 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/cli/util/variants.js +8 -4
- package/build/cli/models/assets/index.js +1 -1
- package/build/cli/models/config/publish-content-config.d.ts +2 -0
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- package/build/cli/models/config/s3-storage-config.d.ts +1 -0
- package/build/cli/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/cli/models/config/s3-storage-config.js +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts +1 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +3 -1
- package/build/cli/models/metadata/index.js +1 -1
- package/build/server/models/assets/index.js +1 -1
- package/build/server/models/config/publish-content-config.d.ts +2 -0
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- package/build/server/models/config/s3-storage-config.d.ts +1 -0
- package/build/server/models/config/s3-storage-config.d.ts.map +1 -1
- package/build/server/models/config/s3-storage-config.js +1 -0
- package/build/server/models/config/static-publish-rc.d.ts +1 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +3 -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/publisher-server/index.d.ts +14 -0
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +178 -54
- package/build/server/server/publisher-server/response-cache.d.ts +19 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -0
- package/build/server/server/publisher-server/response-cache.js +106 -0
- package/build/server/server/storage/s3-storage-provider.d.ts +16 -15
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +131 -60
- package/build/server/server/storage/storage-provider.d.ts +2 -2
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/storage-provider.js +2 -1
- package/build/server/server/util/server-timing.d.ts +7 -0
- package/build/server/server/util/server-timing.d.ts.map +1 -0
- package/build/server/server/util/server-timing.js +34 -0
- package/package.json +9 -8
- 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
|
@@ -10,6 +10,19 @@ export class StorageProviderBatch {
|
|
|
10
10
|
this.storageProviderBatchEntries.push(entry);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
// Lists the keys that start with `prefix` followed by a lowercase hex digit.
|
|
14
|
+
// Use it for a prefix that a hex hash follows, such as `<publishId>_files_sha256_`.
|
|
15
|
+
// A listing gets its keys one page at a time, and each page needs the previous
|
|
16
|
+
// page. Thus this function runs one listing for each of the 16 hex digits at the
|
|
17
|
+
// same time. The total time is approximately the time of the largest part.
|
|
18
|
+
// Returns null only if all the listings return null.
|
|
19
|
+
export async function getStorageKeysByHexPrefix(storageProvider, prefix) {
|
|
20
|
+
const parts = await Promise.all('0123456789abcdef'.split('').map((digit) => storageProvider.getStorageKeys(prefix + digit)));
|
|
21
|
+
if (parts.every((part) => part == null)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return parts.flatMap((part) => part ?? []);
|
|
25
|
+
}
|
|
13
26
|
const _storageProviderBuilders = [];
|
|
14
27
|
export function registerStorageProviderBuilder(builder) {
|
|
15
28
|
_storageProviderBuilders.push(builder);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAqCnB"}
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import { spawnSync } from 'node:child_process';
|
|
6
|
-
import cli from '@fastly/cli';
|
|
7
5
|
import { makeRetryable } from './retryable.js';
|
|
8
6
|
export function loadApiToken(params) {
|
|
9
7
|
let apiToken = null;
|
|
@@ -20,32 +18,6 @@ export function loadApiToken(params) {
|
|
|
20
18
|
source = 'env';
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
// Try fastly cli
|
|
24
|
-
if (apiToken == null) {
|
|
25
|
-
try {
|
|
26
|
-
const { stdout, error, status } = spawnSync(cli, ['profile', 'token', '--quiet'], {
|
|
27
|
-
encoding: 'utf-8',
|
|
28
|
-
});
|
|
29
|
-
if (status != null && status !== 0) {
|
|
30
|
-
console.warn(`⚠️ Warning: 'fastly profile token' returned a non-zero status code.`);
|
|
31
|
-
apiToken = null;
|
|
32
|
-
}
|
|
33
|
-
else if (error) {
|
|
34
|
-
console.warn(`⚠️ Warning: 'fastly profile token' returned an error:`);
|
|
35
|
-
console.warn(String(error));
|
|
36
|
-
apiToken = null;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
apiToken = stdout.trim();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
apiToken = null;
|
|
44
|
-
}
|
|
45
|
-
if (apiToken != null) {
|
|
46
|
-
source = 'fastly-profile-token';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
21
|
if (apiToken == null) {
|
|
50
22
|
return null;
|
|
51
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,0CAA0C,CAAC;AAOlD,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AAEtG,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAIrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CA+B1E;AAGD,eAAO,MAAM,0BAA0B,6DAmErC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6B9G;AA4CD,eAAO,MAAM,6BAA6B,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,eAAe,EAIrB,MAAM,0CAA0C,CAAC;AAOlD,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AAEtG,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAIrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CA+B1E;AAGD,eAAO,MAAM,0BAA0B,6DAmErC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA6B9G;AA4CD,eAAO,MAAM,6BAA6B,4EAsKxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}
|
|
@@ -163,7 +163,7 @@ const normalizeContentTypeDefs = buildNormalizeFunctionForArray((config, errors)
|
|
|
163
163
|
return normalizeContentTypeDef(config, errors);
|
|
164
164
|
});
|
|
165
165
|
export const normalizePublishContentConfig = buildNormalizeFunctionForObject((config, errors) => {
|
|
166
|
-
let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, contentCompression, contentTypes, server, } = config;
|
|
166
|
+
let { rootDir, excludeDirs, excludeDotFiles, includeWellKnown, assetInclusionTest, kvStoreAssetInclusionTest, contentCompression, brotliQuality, contentTypes, server, } = config;
|
|
167
167
|
if (!isSpecified(config, 'rootDir')) {
|
|
168
168
|
errors.push('rootDir must be specified.');
|
|
169
169
|
}
|
|
@@ -269,6 +269,12 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
|
|
|
269
269
|
errors.push(`contentCompression, if specified, must be null or an array and can only contain 'br' and 'gzip'.`);
|
|
270
270
|
}
|
|
271
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
|
+
}
|
|
272
278
|
if (!isSpecified(config, 'contentTypes')) {
|
|
273
279
|
contentTypes = [];
|
|
274
280
|
}
|
|
@@ -315,6 +321,7 @@ export const normalizePublishContentConfig = buildNormalizeFunctionForObject((co
|
|
|
315
321
|
includeWellKnown,
|
|
316
322
|
assetInclusionTest,
|
|
317
323
|
contentCompression,
|
|
324
|
+
brotliQuality,
|
|
318
325
|
contentTypes,
|
|
319
326
|
server,
|
|
320
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;
|
|
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/
|
|
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 },
|
|
@@ -49,7 +52,7 @@ export function mergeContentTypes(contentTypes) {
|
|
|
49
52
|
invalid = true;
|
|
50
53
|
}
|
|
51
54
|
if (typeof contentType.contentType !== 'string' || contentType.contentType.indexOf('/') === -1) {
|
|
52
|
-
console.log(`⚠️ Ignoring contentTypes[${index}]: '
|
|
55
|
+
console.log(`⚠️ Ignoring contentTypes[${index}]: 'contentType' must be a string representing a MIME type.`);
|
|
53
56
|
invalid = true;
|
|
54
57
|
}
|
|
55
58
|
if ('text' in contentType && typeof contentType.text !== 'boolean') {
|
|
@@ -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;
|
|
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;AAGlF,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,sEA4DlF,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,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
|
-
|
|
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 += '
|
|
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,19 @@
|
|
|
1
|
+
import { type FastlyApiContext } from './api-token.js';
|
|
2
|
+
export declare const purgeEnvironments: readonly ["production", "staging"];
|
|
3
|
+
export type PurgeEnvironment = typeof purgeEnvironments[number];
|
|
4
|
+
export declare function parsePurgeEnvironments(values: unknown): PurgeEnvironment[];
|
|
5
|
+
export type PurgeTarget = {
|
|
6
|
+
serviceId: string;
|
|
7
|
+
fastlyApiContext: FastlyApiContext;
|
|
8
|
+
environments: PurgeEnvironment[];
|
|
9
|
+
};
|
|
10
|
+
export type LoadPurgeTargetParams = {
|
|
11
|
+
localMode: boolean;
|
|
12
|
+
computeAppDir: string;
|
|
13
|
+
fastlyServiceId: unknown;
|
|
14
|
+
fastlyApiToken: unknown;
|
|
15
|
+
purgeEnvironments: unknown;
|
|
16
|
+
};
|
|
17
|
+
export declare function loadPurgeTarget(params: LoadPurgeTargetParams): PurgeTarget | null;
|
|
18
|
+
export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean, environment?: PurgeEnvironment): Promise<boolean>;
|
|
19
|
+
//# sourceMappingURL=purge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"AAOA,OAAO,EAAiB,KAAK,gBAAgB,EAA4B,MAAM,gBAAgB,CAAC;AAGhG,eAAO,MAAM,iBAAiB,oCAAuC,CAAC;AACtE,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAIhE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAkB1E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAMF,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,WAAW,GAAG,IAAI,CAgCjF;AAED,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,gBAAgB,EAClC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,OAAe,EAC1B,WAAW,GAAE,gBAA+B,oBA4B7C"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { callFastlyApi, FetchError, loadApiToken } from './api-token.js';
|
|
7
|
+
import { loadServiceId } from './service-id.js';
|
|
8
|
+
export const purgeEnvironments = ['production', 'staging'];
|
|
9
|
+
// Parses the values of --purge-environment. The option can be repeated, and
|
|
10
|
+
// each value can be a comma-separated list. The default is production.
|
|
11
|
+
export function parsePurgeEnvironments(values) {
|
|
12
|
+
const list = Array.isArray(values) ? values : values == null ? [] : [values];
|
|
13
|
+
const result = [];
|
|
14
|
+
for (const value of list) {
|
|
15
|
+
for (const item of String(value).split(',')) {
|
|
16
|
+
const name = item.trim();
|
|
17
|
+
if (name === '') {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (!purgeEnvironments.includes(name)) {
|
|
21
|
+
throw new Error(`❌ Unknown --purge-environment '${name}'. Use ${purgeEnvironments.join(', ')}, or a comma-separated list of them.`);
|
|
22
|
+
}
|
|
23
|
+
if (!result.includes(name)) {
|
|
24
|
+
result.push(name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return result.length > 0 ? result : ['production'];
|
|
29
|
+
}
|
|
30
|
+
// Finds the service to purge after publishing, so that it stops serving cached
|
|
31
|
+
// copies of the collection. Returns null, and logs why, if the purge is skipped.
|
|
32
|
+
// Throws if a Service ID is found but an API token is not, so that this fails
|
|
33
|
+
// before anything is uploaded.
|
|
34
|
+
export function loadPurgeTarget(params) {
|
|
35
|
+
// Check the option even when the purge is skipped, so that a typo is reported.
|
|
36
|
+
const environments = parsePurgeEnvironments(params.purgeEnvironments);
|
|
37
|
+
if (params.localMode) {
|
|
38
|
+
console.log(`- Local mode: will skip purge step after publish.`);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const serviceIdResult = loadServiceId({
|
|
42
|
+
commandLine: params.fastlyServiceId,
|
|
43
|
+
fastlyTomlPath: path.resolve(params.computeAppDir, 'fastly.toml'),
|
|
44
|
+
});
|
|
45
|
+
if (serviceIdResult == null) {
|
|
46
|
+
console.log(`- Service ID not found (--fastly-service-id, fastly.toml, or FASTLY_SERVICE_ID). Will skip purge step after publish.`);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
console.log(`✔️ Service ID from ${serviceIdResult.source}: ${serviceIdResult.serviceId}`);
|
|
50
|
+
const apiTokenResult = loadApiToken({ commandLine: params.fastlyApiToken });
|
|
51
|
+
if (apiTokenResult == null) {
|
|
52
|
+
throw new Error("❌ Fastly API Token not provided.\nSet the FASTLY_API_TOKEN environment variable to an API token that can purge the service.");
|
|
53
|
+
}
|
|
54
|
+
console.log(`✔️ Purge environments: ${environments.join(', ')}`);
|
|
55
|
+
return {
|
|
56
|
+
serviceId: serviceIdResult.serviceId,
|
|
57
|
+
fastlyApiContext: { apiToken: apiTokenResult.apiToken },
|
|
58
|
+
environments,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export async function purgeSurrogateKey(fastlyApiContext, fastlyServiceId, surrogateKey, softPurge = false, environment = 'production') {
|
|
62
|
+
const endpoint = `/service/${encodeURIComponent(fastlyServiceId)}/purge`;
|
|
63
|
+
try {
|
|
64
|
+
const headers = new Headers();
|
|
65
|
+
headers.set('surrogate-key', surrogateKey);
|
|
66
|
+
if (softPurge) {
|
|
67
|
+
headers.set('fastly-soft-purge', '1');
|
|
68
|
+
}
|
|
69
|
+
// A purge without this header applies to production. Staging needs it.
|
|
70
|
+
// See https://www.fastly.com/documentation/guides/getting-started/services/working-with-staging/
|
|
71
|
+
if (environment === 'staging') {
|
|
72
|
+
headers.set('fastly-purge-environment', 'staging');
|
|
73
|
+
}
|
|
74
|
+
await callFastlyApi(fastlyApiContext, endpoint, `Purging surrogate key [${surrogateKey}] on service [${fastlyServiceId}] (${environment})`, null, { method: 'POST', headers });
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err instanceof FetchError) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"retryable.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/retryable.ts"],"names":[],"mappings":"AAUA,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,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,iBAgD9B;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,OAAO,EAChD,KAAK,EAAE,KAAK,EAAE,EACd,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,EAEpD,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
|
|
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,
|
|
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"}
|
package/build/cli/cli/util/s3.js
CHANGED
|
@@ -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
|
|
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) => {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type LoadServiceIdResult = {
|
|
2
|
+
serviceId: string;
|
|
3
|
+
source: string;
|
|
4
|
+
};
|
|
5
|
+
export type LoadServiceIdParams = {
|
|
6
|
+
commandLine: unknown;
|
|
7
|
+
fastlyTomlPath: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function loadServiceId(params: LoadServiceIdParams): LoadServiceIdResult | null;
|
|
10
|
+
//# sourceMappingURL=service-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-id.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/service-id.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAMF,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,GAAG,IAAI,CAmBrF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { readServiceId } from './fastly-toml.js';
|
|
7
|
+
// Finds the Fastly Service ID to purge after publishing. Checks, in order:
|
|
8
|
+
// 1. The command line (--fastly-service-id)
|
|
9
|
+
// 2. service_id in fastly.toml
|
|
10
|
+
// 3. The FASTLY_SERVICE_ID environment variable
|
|
11
|
+
export function loadServiceId(params) {
|
|
12
|
+
if (typeof params.commandLine === 'string' && params.commandLine.trim() !== '') {
|
|
13
|
+
return { serviceId: params.commandLine.trim(), source: 'commandline' };
|
|
14
|
+
}
|
|
15
|
+
if (fs.existsSync(params.fastlyTomlPath)) {
|
|
16
|
+
const serviceId = readServiceId(params.fastlyTomlPath);
|
|
17
|
+
if (serviceId != null) {
|
|
18
|
+
return { serviceId, source: 'fastly.toml' };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const envServiceId = process.env.FASTLY_SERVICE_ID?.trim();
|
|
22
|
+
if (envServiceId) {
|
|
23
|
+
return { serviceId: envServiceId, source: 'env' };
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
@@ -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;
|
|
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"}
|