@fastly/compute-js-static-publish 8.0.0-beta.8 → 8.0.0-rc.0
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 +7 -5
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +3 -4
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +2 -3
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +2 -3
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +2 -3
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +2 -3
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +2 -3
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +166 -66
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +7 -4
- 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 -6
- 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 -10
- package/build/cli/cli/storage/kv-store-provider.d.ts +4 -6
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +38 -68
- package/build/cli/cli/storage/s3-storage-provider.d.ts +6 -9
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +45 -80
- package/build/cli/cli/storage/storage-provider.d.ts +7 -6
- 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 +17 -1
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +63 -3
- 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/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 +27 -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 +2 -2
- 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/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/server/publisher-server/index.d.ts +15 -1
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +189 -56
- 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 +2 -5
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +95 -38
- package/build/server/server/storage/storage-provider.d.ts +1 -1
- 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 -7
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
6
|
+
import http from 'node:http';
|
|
7
|
+
import https from 'node:https';
|
|
8
|
+
import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, PutObjectCommand, S3Client, S3ServiceException, paginateListObjectsV2, } from '@aws-sdk/client-s3';
|
|
9
9
|
import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
10
10
|
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
11
|
+
import { entriesToUpload } from '../util/kv-store-items.js';
|
|
11
12
|
import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
12
13
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
13
14
|
import { rootRelative, } from '../util/files.js';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// The number of objects to upload at the same time. S3 accepts many parallel
|
|
16
|
+
// requests, and each request mostly waits for the network. In a test with small
|
|
17
|
+
// objects, 64 was approximately 4 times faster than 12.
|
|
18
|
+
export const DEFAULT_S3_UPLOAD_CONCURRENCY = 64;
|
|
17
19
|
export const buildStoreProvider = async (config, context) => {
|
|
18
20
|
if (isS3StorageConfigRc(config)) {
|
|
19
21
|
console.log(` Working on S3 (or compatible) storage (BETA)...`);
|
|
@@ -34,27 +36,11 @@ export const buildStoreProvider = async (config, context) => {
|
|
|
34
36
|
throw new Error("❌ S3 Credentials not provided.\nProvide an access key ID and secret access key that have write access to the S3 or compatible storage.\nRefer to the README file and --help for additional information.");
|
|
35
37
|
}
|
|
36
38
|
console.log(`✔️ S3 Credentials: ${s3CredentialsResult.s3AccessKeyId.slice(0, 4)}${'*'.repeat(s3CredentialsResult.s3AccessKeyId.length - 4)} from '${s3CredentialsResult.source}'`);
|
|
37
|
-
|
|
38
|
-
const serviceId = readServiceId(fastlyTomlPath);
|
|
39
|
-
let apiToken = undefined;
|
|
40
|
-
if (serviceId == null) {
|
|
41
|
-
console.log(`- Service ID not found in fastly.toml, application may not have been deployed yet. Will skip purge step after publish.`);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
console.log(`✔️ Service ID from fastly.toml: ${serviceId}`);
|
|
45
|
-
const apiTokenResult = loadApiToken({ commandLine: context.fastlyApiToken });
|
|
46
|
-
if (apiTokenResult == null) {
|
|
47
|
-
throw new Error("❌ Fastly API Token not provided.\nSet the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
48
|
-
}
|
|
49
|
-
console.log(`✔️ Fastly API Token: ${apiTokenResult.apiToken.slice(0, 4)}${'*'.repeat(apiTokenResult.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
50
|
-
apiToken = apiTokenResult.apiToken;
|
|
51
|
-
}
|
|
52
|
-
return new S3StorageProvider(serviceId, apiToken, region, s3CredentialsResult.s3AccessKeyId, s3CredentialsResult.s3SecretAccessKey, bucket, endpoint);
|
|
39
|
+
return new S3StorageProvider(region, s3CredentialsResult.s3AccessKeyId, s3CredentialsResult.s3SecretAccessKey, bucket, endpoint, context.s3UploadConcurrency ?? DEFAULT_S3_UPLOAD_CONCURRENCY);
|
|
53
40
|
};
|
|
54
41
|
export class S3StorageProvider {
|
|
55
|
-
constructor(
|
|
56
|
-
this.
|
|
57
|
-
this.fastlyApiContext = fastlyApiToken != null ? { apiToken: fastlyApiToken } : undefined;
|
|
42
|
+
constructor(s3Region, accessKeyId, secretAccessKey, s3Bucket, s3Endpoint, uploadConcurrency = DEFAULT_S3_UPLOAD_CONCURRENCY) {
|
|
43
|
+
this.uploadConcurrency = uploadConcurrency;
|
|
58
44
|
this.s3Region = s3Region;
|
|
59
45
|
this.accessKeyId = accessKeyId;
|
|
60
46
|
this.secretAccessKey = secretAccessKey;
|
|
@@ -65,7 +51,14 @@ export class S3StorageProvider {
|
|
|
65
51
|
if (this.s3Client != null) {
|
|
66
52
|
return this.s3Client;
|
|
67
53
|
}
|
|
54
|
+
// The SDK default is 50 sockets. Use at least one socket for each
|
|
55
|
+
// concurrent upload, so that uploads do not wait for a socket.
|
|
56
|
+
const maxSockets = Math.max(50, this.uploadConcurrency);
|
|
68
57
|
this.s3Client = new S3Client({
|
|
58
|
+
requestHandler: {
|
|
59
|
+
httpAgent: new http.Agent({ keepAlive: true, maxSockets }),
|
|
60
|
+
httpsAgent: new https.Agent({ keepAlive: true, maxSockets }),
|
|
61
|
+
},
|
|
69
62
|
region: this.s3Region,
|
|
70
63
|
endpoint: this.s3Endpoint,
|
|
71
64
|
forcePathStyle: this.s3Endpoint != null,
|
|
@@ -89,20 +82,27 @@ export class S3StorageProvider {
|
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
84
|
async getStorageKeys(prefix) {
|
|
85
|
+
const paginationConfig = {
|
|
86
|
+
client: this.getS3Client(),
|
|
87
|
+
};
|
|
92
88
|
const input = {
|
|
93
89
|
Bucket: this.s3Bucket,
|
|
94
|
-
MaxKeys: 4096,
|
|
95
90
|
Prefix: prefix,
|
|
96
|
-
ContinuationToken: undefined, // pagination
|
|
97
91
|
};
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
const paginator = paginateListObjectsV2(paginationConfig, input);
|
|
93
|
+
const objectKeys = [];
|
|
94
|
+
for await (const { Contents } of paginator) {
|
|
95
|
+
if (Contents == null) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
for (const obj of Contents) {
|
|
99
|
+
if (obj.Key != null) {
|
|
100
|
+
objectKeys.push(obj.Key);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
102
103
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.filter(c => c != null);
|
|
104
|
+
// An empty list is a valid result. The callers use null only for an error.
|
|
105
|
+
return objectKeys;
|
|
106
106
|
}
|
|
107
107
|
async getStorageEntry(key) {
|
|
108
108
|
const input = {
|
|
@@ -172,18 +172,22 @@ export class S3StorageProvider {
|
|
|
172
172
|
const command = new DeleteObjectCommand(input);
|
|
173
173
|
await this.sendS3ClientCommand(command);
|
|
174
174
|
}
|
|
175
|
-
async applyBatch(batch) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
async applyBatch(batch, options = {}) {
|
|
176
|
+
const { existingKeys } = options;
|
|
177
|
+
let toWrite = batch.storageProviderBatchEntries;
|
|
178
|
+
if (existingKeys != null) {
|
|
179
|
+
toWrite = entriesToUpload(toWrite, existingKeys);
|
|
180
|
+
}
|
|
181
|
+
console.log(`📤 Uploading ${toWrite.length} entries to S3 storage (${this.uploadConcurrency} at a time).`);
|
|
182
|
+
await this.doConcurrentParallel(toWrite, async ({ filePath, metadataJson }, key) => {
|
|
179
183
|
// const fileStream = fs.createReadStream(filePath);
|
|
180
184
|
const fileData = fs.readFileSync(filePath);
|
|
181
185
|
await this.submitStorageEntry(key, filePath, fileData, metadataJson);
|
|
182
186
|
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
|
|
183
|
-
});
|
|
187
|
+
}, this.uploadConcurrency, true);
|
|
184
188
|
console.log(`✅ Uploaded entries to S3 storage.`);
|
|
185
189
|
}
|
|
186
|
-
async doConcurrentParallel(objects, fn, maxConcurrent = 12) {
|
|
190
|
+
async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
|
|
187
191
|
await concurrentParallel(objects, fn, (err) => {
|
|
188
192
|
if (err instanceof S3ServiceException) {
|
|
189
193
|
return `S3 error [${err.name}] - ${err.message}`;
|
|
@@ -192,48 +196,9 @@ export class S3StorageProvider {
|
|
|
192
196
|
return 'transport';
|
|
193
197
|
}
|
|
194
198
|
return null;
|
|
195
|
-
}, maxConcurrent);
|
|
199
|
+
}, maxConcurrent, throwOnError);
|
|
196
200
|
}
|
|
197
201
|
calculateNumChunks(_size) {
|
|
198
202
|
return 1;
|
|
199
203
|
}
|
|
200
|
-
async getExistingAssetVariant(variantKey) {
|
|
201
|
-
let assetVariantMetadata = null;
|
|
202
|
-
await this.doConcurrentParallel([{ key: variantKey }], async (_, variantKey) => {
|
|
203
|
-
const entryInfo = await this.getStorageEntryInfo(variantKey);
|
|
204
|
-
if (entryInfo == null) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const metadata = decodeAssetVariantMetadata(entryInfo.metadata);
|
|
208
|
-
if (metadata != null) {
|
|
209
|
-
if (metadata.numChunks !== undefined) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
assetVariantMetadata = {
|
|
213
|
-
contentEncoding: metadata.contentEncoding,
|
|
214
|
-
size: metadata.size,
|
|
215
|
-
hash: metadata.hash,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
return assetVariantMetadata;
|
|
220
|
-
}
|
|
221
|
-
async purgeSurrogateKey(surrogateKey) {
|
|
222
|
-
if (this.fastlyServiceId == null) {
|
|
223
|
-
console.log('Fastly Service ID not set, skipping purge...');
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (this.fastlyApiContext?.apiToken == null) {
|
|
227
|
-
console.log('Fastly API token not set, skipping purge...');
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
console.log(`Purging surrogate key [${surrogateKey}] on service [${this.fastlyServiceId}]...`);
|
|
231
|
-
const result = await purgeSurrogateKey(this.fastlyApiContext, this.fastlyServiceId, surrogateKey, true);
|
|
232
|
-
if (result) {
|
|
233
|
-
console.log('Purged');
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
console.log('Failed purging');
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
204
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
1
|
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
3
2
|
export interface StorageEntry {
|
|
4
3
|
data?: ReadableStream<Uint8Array>;
|
|
@@ -11,21 +10,21 @@ export interface StorageProvider {
|
|
|
11
10
|
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
12
11
|
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
13
12
|
deleteStorageEntry(key: string): Promise<void>;
|
|
14
|
-
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
13
|
+
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
14
|
doConcurrentParallel<TObject extends {
|
|
16
15
|
key: string;
|
|
17
|
-
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
16
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
18
17
|
calculateNumChunks(size: number): number;
|
|
19
|
-
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
20
|
-
purgeSurrogateKey(surrogateKey: string): Promise<void>;
|
|
21
18
|
}
|
|
22
19
|
export type StorageProviderBatchEntry = {
|
|
23
|
-
write: boolean;
|
|
24
20
|
size: number;
|
|
25
21
|
key: string;
|
|
26
22
|
filePath: string;
|
|
27
23
|
metadataJson?: Record<string, string>;
|
|
28
24
|
};
|
|
25
|
+
export type ApplyBatchOptions = {
|
|
26
|
+
existingKeys?: Set<string>;
|
|
27
|
+
};
|
|
29
28
|
export declare class StorageProviderBatch {
|
|
30
29
|
constructor();
|
|
31
30
|
storageProviderBatchEntries: StorageProviderBatchEntry[];
|
|
@@ -37,8 +36,10 @@ export type StorageProviderBuilderContext = {
|
|
|
37
36
|
fastlyApiToken?: string;
|
|
38
37
|
s3AccessKeyId?: string;
|
|
39
38
|
s3SecretAccessKey?: string;
|
|
39
|
+
s3UploadConcurrency?: number;
|
|
40
40
|
};
|
|
41
41
|
export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageProviderBuilderContext) => (Promise<StorageProvider | null> | StorageProvider | null);
|
|
42
|
+
export declare function getStorageKeysByHexPrefix(storageProvider: StorageProvider, prefix: string): Promise<string[] | null>;
|
|
42
43
|
export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
|
|
43
44
|
export declare function loadStorageProviderFromStaticPublishRc(config: StaticPublishRc, context: StorageProviderBuilderContext): Promise<StorageProvider>;
|
|
44
45
|
//# sourceMappingURL=storage-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,
|
|
1
|
+
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"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"}
|
|
@@ -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
|
+
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import { type FastlyApiContext } from './api-token.js';
|
|
2
|
-
export declare
|
|
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>;
|
|
3
19
|
//# sourceMappingURL=purge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"
|
|
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"}
|