@fastly/compute-js-static-publish 8.0.0 → 8.0.2
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/CHANGELOG.md +544 -0
- package/DOCUMENTATION.md +1243 -0
- package/MIGRATING.md +128 -0
- package/README.md +9 -2
- package/README.short.md +9 -2
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +43 -4
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +13 -16
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +51 -31
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +4 -1
- package/build/cli/cli/storage/kv-store-provider.d.ts +2 -1
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +17 -6
- package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +8 -2
- package/build/cli/cli/storage/storage-provider.d.ts +4 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +32 -0
- package/build/cli/cli/util/api-token.d.ts +2 -1
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.js +38 -3
- package/build/cli/cli/util/kv-store-items.d.ts +1 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +16 -40
- package/build/cli/cli/util/progress.d.ts +11 -0
- package/build/cli/cli/util/progress.d.ts.map +1 -0
- package/build/cli/cli/util/progress.js +32 -0
- package/build/cli/cli/util/purge.d.ts +9 -1
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +16 -8
- package/build/cli/cli/util/s3.d.ts +10 -4
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +13 -35
- package/build/server/server/publisher-server/accept-html.d.ts +2 -0
- package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
- package/build/server/server/publisher-server/accept-html.js +50 -0
- package/build/server/server/publisher-server/index.d.ts +1 -0
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +31 -13
- package/build/server/server/publisher-server/response-cache.d.ts +3 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
- package/build/server/server/publisher-server/response-cache.js +24 -1
- package/package.json +6 -3
|
@@ -7,8 +7,9 @@ import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
|
7
7
|
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
8
8
|
import { FetchError, loadApiToken, } from '../util/api-token.js';
|
|
9
9
|
import { rootRelative, } from '../util/files.js';
|
|
10
|
+
import { ProgressLog } from '../util/progress.js';
|
|
10
11
|
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, kvStoreSubmitBatch, } from '../util/kv-store.js';
|
|
11
|
-
import { applyKVStoreEntriesChunks, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
12
|
+
import { applyKVStoreEntriesChunks, chunkSizes, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
12
13
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
13
14
|
export const buildStoreProvider = (config, context) => {
|
|
14
15
|
if (isKvStoreConfigRc(config) && !context.localMode) {
|
|
@@ -55,7 +56,7 @@ export class KvStoreProvider {
|
|
|
55
56
|
await kvStoreDeleteEntry(this.fastlyApiContext, this.kvStoreName, key);
|
|
56
57
|
}
|
|
57
58
|
async applyBatch(batch, options = {}) {
|
|
58
|
-
const { existingKeys } = options;
|
|
59
|
+
const { existingKeys, verbose = false } = options;
|
|
59
60
|
console.log(`🍪 Chunking large files...`);
|
|
60
61
|
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
61
62
|
console.log(`✅ Large files have been chunked.`);
|
|
@@ -65,15 +66,16 @@ export class KvStoreProvider {
|
|
|
65
66
|
console.log(` | ${batch.storageProviderBatchEntries.length - toWrite.length} chunk(s) already present in the KV Store.`);
|
|
66
67
|
}
|
|
67
68
|
console.log(`📤 Uploading ${toWrite.length} entries to KV Store.`);
|
|
68
|
-
await this.uploadEntries(toWrite);
|
|
69
|
+
await this.uploadEntries(toWrite, verbose);
|
|
69
70
|
console.log(`✅ Uploaded entries to KV Store.`);
|
|
70
71
|
}
|
|
71
|
-
async uploadEntries(entries) {
|
|
72
|
+
async uploadEntries(entries, verbose = false) {
|
|
72
73
|
const { batches, oversized } = packNdjsonBatches(entries);
|
|
74
|
+
const progress = new ProgressLog('Entries uploaded', verbose, entries.length);
|
|
73
75
|
await this.doConcurrentParallel(oversized, async ({ filePath, metadataJson }, key) => {
|
|
74
76
|
const fileBytes = fs.readFileSync(filePath);
|
|
75
77
|
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
|
|
76
|
-
|
|
78
|
+
progress.add(1, () => ` 🌐 Submitted large asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
77
79
|
}, 12, true);
|
|
78
80
|
await this.doConcurrentParallel(batches, async (batch, key) => {
|
|
79
81
|
const lines = batch.entries.map(ndjsonLineForBatchEntry);
|
|
@@ -82,12 +84,13 @@ export class KvStoreProvider {
|
|
|
82
84
|
// Keep only the entries that failed. The retry submits only these entries.
|
|
83
85
|
const failedKeys = new Set(failures.map(f => f.key));
|
|
84
86
|
const submittedCount = batch.entries.length;
|
|
87
|
+
progress.add(submittedCount - failures.length, () => ` 🌐 Submitted ${submittedCount - failures.length} of ${submittedCount} entries to KV Store ("${key}").`);
|
|
85
88
|
batch.entries = batch.entries.filter(entry => failedKeys.has(entry.key));
|
|
86
89
|
const shown = failures.slice(0, 5).map(f => `${f.key} (${f.code ?? 'unknown'}: ${f.reason ?? 'unknown'})`).join(', ');
|
|
87
90
|
const more = failures.length > 5 ? `, and ${failures.length - 5} more` : '';
|
|
88
91
|
throw makeRetryable(new Error(`${failures.length} of ${submittedCount} entries failed: ${shown}${more}`));
|
|
89
92
|
}
|
|
90
|
-
|
|
93
|
+
progress.add(batch.entries.length, () => ` 🌐 Submitted ${batch.entries.length} entries to KV Store ("${key}").`);
|
|
91
94
|
}, 12, true);
|
|
92
95
|
}
|
|
93
96
|
async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
|
|
@@ -107,6 +110,9 @@ export class KvStoreProvider {
|
|
|
107
110
|
calculateNumChunks(size) {
|
|
108
111
|
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
109
112
|
}
|
|
113
|
+
calculateChunkSizes(size) {
|
|
114
|
+
return chunkSizes(size, KV_STORE_CHUNK_SIZE);
|
|
115
|
+
}
|
|
110
116
|
}
|
|
111
117
|
export function kvStoreEntryToStorageEntry(kvStoreEntry) {
|
|
112
118
|
const storageEntry = {};
|
|
@@ -119,6 +125,11 @@ export function kvStoreEntryToStorageEntry(kvStoreEntry) {
|
|
|
119
125
|
storageEntry.metadata = metadata;
|
|
120
126
|
}
|
|
121
127
|
}
|
|
128
|
+
// The API gives the size of the value in this header, also for a HEAD request.
|
|
129
|
+
const storedContentLength = kvStoreEntry.response.headers.get('stored-content-length');
|
|
130
|
+
if (storedContentLength != null) {
|
|
131
|
+
storageEntry.size = Number(storedContentLength);
|
|
132
|
+
}
|
|
122
133
|
if (kvStoreEntry.generation != null) {
|
|
123
134
|
storageEntry.providerMetadata = {
|
|
124
135
|
generation: kvStoreEntry.generation,
|
|
@@ -26,6 +26,7 @@ export declare class S3StorageProvider implements StorageProvider {
|
|
|
26
26
|
key: string;
|
|
27
27
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
28
28
|
calculateNumChunks(_size: number): number;
|
|
29
|
+
calculateChunkSizes(size: number): number[];
|
|
29
30
|
}
|
|
30
31
|
export {};
|
|
31
32
|
//# sourceMappingURL=s3-storage-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAc/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GA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,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;IAaV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BvF,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;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIzC,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;CAI5C"}
|
|
@@ -12,6 +12,7 @@ import { entriesToUpload } from '../util/kv-store-items.js';
|
|
|
12
12
|
import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
13
13
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
14
14
|
import { rootRelative, } from '../util/files.js';
|
|
15
|
+
import { ProgressLog } from '../util/progress.js';
|
|
15
16
|
// The number of objects to upload at the same time. S3 accepts many parallel
|
|
16
17
|
// requests, and each request mostly waits for the network. In a test with small
|
|
17
18
|
// objects, 64 was approximately 4 times faster than 12.
|
|
@@ -156,6 +157,7 @@ export class S3StorageProvider {
|
|
|
156
157
|
}
|
|
157
158
|
return {
|
|
158
159
|
metadata: response.Metadata,
|
|
160
|
+
size: response.ContentLength,
|
|
159
161
|
};
|
|
160
162
|
}
|
|
161
163
|
async submitStorageEntry(key, _filePath, data, metadata) {
|
|
@@ -177,17 +179,18 @@ export class S3StorageProvider {
|
|
|
177
179
|
await this.sendS3ClientCommand(command);
|
|
178
180
|
}
|
|
179
181
|
async applyBatch(batch, options = {}) {
|
|
180
|
-
const { existingKeys } = options;
|
|
182
|
+
const { existingKeys, verbose = false } = options;
|
|
181
183
|
let toWrite = batch.storageProviderBatchEntries;
|
|
182
184
|
if (existingKeys != null) {
|
|
183
185
|
toWrite = entriesToUpload(toWrite, existingKeys);
|
|
184
186
|
}
|
|
185
187
|
console.log(`📤 Uploading ${toWrite.length} entries to S3 storage (${this.uploadConcurrency} at a time).`);
|
|
188
|
+
const progress = new ProgressLog('Entries uploaded', verbose, toWrite.length);
|
|
186
189
|
await this.doConcurrentParallel(toWrite, async ({ filePath, metadataJson }, key) => {
|
|
187
190
|
// const fileStream = fs.createReadStream(filePath);
|
|
188
191
|
const fileData = fs.readFileSync(filePath);
|
|
189
192
|
await this.submitStorageEntry(key, filePath, fileData, metadataJson);
|
|
190
|
-
|
|
193
|
+
progress.add(1, () => ` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
|
|
191
194
|
}, this.uploadConcurrency, true);
|
|
192
195
|
console.log(`✅ Uploaded entries to S3 storage.`);
|
|
193
196
|
}
|
|
@@ -205,4 +208,7 @@ export class S3StorageProvider {
|
|
|
205
208
|
calculateNumChunks(_size) {
|
|
206
209
|
return 1;
|
|
207
210
|
}
|
|
211
|
+
calculateChunkSizes(size) {
|
|
212
|
+
return [size];
|
|
213
|
+
}
|
|
208
214
|
}
|
|
@@ -3,6 +3,7 @@ export interface StorageEntry {
|
|
|
3
3
|
data?: ReadableStream<Uint8Array>;
|
|
4
4
|
metadata?: Record<string, string>;
|
|
5
5
|
providerMetadata?: Record<string, string>;
|
|
6
|
+
size?: number;
|
|
6
7
|
}
|
|
7
8
|
export interface StorageProvider {
|
|
8
9
|
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
@@ -15,6 +16,7 @@ export interface StorageProvider {
|
|
|
15
16
|
key: string;
|
|
16
17
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
17
18
|
calculateNumChunks(size: number): number;
|
|
19
|
+
calculateChunkSizes(size: number): number[];
|
|
18
20
|
}
|
|
19
21
|
export type StorageProviderBatchEntry = {
|
|
20
22
|
size: number;
|
|
@@ -24,6 +26,7 @@ export type StorageProviderBatchEntry = {
|
|
|
24
26
|
};
|
|
25
27
|
export type ApplyBatchOptions = {
|
|
26
28
|
existingKeys?: Set<string>;
|
|
29
|
+
verbose?: boolean;
|
|
27
30
|
};
|
|
28
31
|
export declare class StorageProviderBatch {
|
|
29
32
|
constructor();
|
|
@@ -42,4 +45,5 @@ export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageP
|
|
|
42
45
|
export declare function getStorageKeysByHexPrefix(storageProvider: StorageProvider, prefix: string): Promise<string[] | null>;
|
|
43
46
|
export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
|
|
44
47
|
export declare function loadStorageProviderFromStaticPublishRc(config: StaticPublishRc, context: StorageProviderBuilderContext): Promise<StorageProvider>;
|
|
48
|
+
export declare function isVariantInStorage(storageProvider: StorageProvider, existingKeys: Set<string>, variantKey: string, size: number, numChunks: number): Promise<boolean>;
|
|
45
49
|
//# 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,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACl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,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,CAAC;AAQlI,wBAAsB,yBAAyB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAQ1H;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H;AAOD,wBAAsB,kBAAkB,CACtC,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,EACzB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CA6BlB"}
|
|
@@ -37,3 +37,35 @@ export async function loadStorageProviderFromStaticPublishRc(config, context) {
|
|
|
37
37
|
}
|
|
38
38
|
throw new Error('Static Publisher Error: Invalid static-publish.rc.js, storage mode not recognized, or could not instantiate store provider.');
|
|
39
39
|
}
|
|
40
|
+
// Returns true if storage has the variant with the key `variantKey`, which has
|
|
41
|
+
// `size` bytes in `numChunks` chunks. For a variant in more than one chunk, it
|
|
42
|
+
// also compares the stored size of each chunk with its expected size. It removes
|
|
43
|
+
// a chunk that has a different size, or that is not in storage now, from
|
|
44
|
+
// existingKeys, so that applyBatch() uploads the chunk again.
|
|
45
|
+
export async function isVariantInStorage(storageProvider, existingKeys, variantKey, size, numChunks) {
|
|
46
|
+
const chunkKeys = Array.from({ length: numChunks }, (_, chunkIndex) => chunkIndex === 0 ? variantKey : `${variantKey}_${chunkIndex}`);
|
|
47
|
+
if (!chunkKeys.every(key => existingKeys.has(key))) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (numChunks === 1) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
const expectedSizes = storageProvider.calculateChunkSizes(size);
|
|
54
|
+
const entries = await Promise.all(chunkKeys.map(key => storageProvider.getStorageEntryInfo(key)));
|
|
55
|
+
let found = true;
|
|
56
|
+
for (const [chunkIndex, key] of chunkKeys.entries()) {
|
|
57
|
+
const entry = entries[chunkIndex];
|
|
58
|
+
if (entry == null) {
|
|
59
|
+
existingKeys.delete(key);
|
|
60
|
+
found = false;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const storedSize = entry.size;
|
|
64
|
+
if (storedSize != null && storedSize !== expectedSizes[chunkIndex]) {
|
|
65
|
+
console.log(` ‼️ Chunk "${key}" in storage has ${storedSize} bytes, but it must have ${expectedSizes[chunkIndex]} bytes. It will be uploaded again.`);
|
|
66
|
+
existingKeys.delete(key);
|
|
67
|
+
found = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return found;
|
|
71
|
+
}
|
|
@@ -10,8 +10,9 @@ export type LoadApiParams = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare function loadApiToken(params: LoadApiParams): LoadApiTokenResult | null;
|
|
12
12
|
export declare class FetchError extends Error {
|
|
13
|
-
constructor(message: string, status: number);
|
|
13
|
+
constructor(message: string, status: number, detail?: string);
|
|
14
14
|
status: number;
|
|
15
|
+
detail?: string;
|
|
15
16
|
}
|
|
16
17
|
export declare function callFastlyApi(fastlyApiContext: FastlyApiContext, endpoint: string, operationName: string, queryParams?: URLSearchParams | null, requestInit?: RequestInit): Promise<Response>;
|
|
17
18
|
//# sourceMappingURL=api-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,EAAE,MAAM,CAAC,EAAE,MAAM;IAM5D,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;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,CAuCnB"}
|
|
@@ -34,10 +34,11 @@ const RETRYABLE_STATUS_CODES = [
|
|
|
34
34
|
504, // Gateway Timeout
|
|
35
35
|
];
|
|
36
36
|
export class FetchError extends Error {
|
|
37
|
-
constructor(message, status) {
|
|
37
|
+
constructor(message, status, detail) {
|
|
38
38
|
super(message);
|
|
39
39
|
this.name = 'FetchError';
|
|
40
40
|
this.status = status;
|
|
41
|
+
this.detail = detail;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
function isReadableStream(data) {
|
|
@@ -74,10 +75,44 @@ export async function callFastlyApi(fastlyApiContext, endpoint, operationName, q
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
if (!response.ok) {
|
|
78
|
+
const detail = await readApiErrorDetail(response);
|
|
79
|
+
const status = `${response.status}${detail != null ? ` ${detail}` : ''}`;
|
|
77
80
|
if (!RETRYABLE_STATUS_CODES.includes(response.status)) {
|
|
78
|
-
throw new FetchError(`${operationName} failed: ${
|
|
81
|
+
throw new FetchError(`${operationName} failed: ${status}`, response.status, detail);
|
|
79
82
|
}
|
|
80
|
-
throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${
|
|
83
|
+
throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${status}`, response.status, detail));
|
|
81
84
|
}
|
|
82
85
|
return response;
|
|
83
86
|
}
|
|
87
|
+
// The Content-Type of an error response tells which fields describe the error:
|
|
88
|
+
// - application/json: the Fastly API fields msg and detail, for example
|
|
89
|
+
// {"msg":"Record not found","detail":"Cannot find service"}.
|
|
90
|
+
// - application/problem+json (RFC 9457): the fields title and detail.
|
|
91
|
+
// - Other types, or JSON that is not valid: the start of the text.
|
|
92
|
+
async function readApiErrorDetail(response) {
|
|
93
|
+
let text;
|
|
94
|
+
try {
|
|
95
|
+
text = (await response.text()).trim();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const mediaType = response.headers.get('content-type')?.split(';')[0].trim().toLowerCase();
|
|
101
|
+
const fields = mediaType === 'application/json' ? ['msg', 'detail'] :
|
|
102
|
+
mediaType === 'application/problem+json' ? ['title', 'detail'] :
|
|
103
|
+
null;
|
|
104
|
+
if (fields != null) {
|
|
105
|
+
let json;
|
|
106
|
+
try {
|
|
107
|
+
json = JSON.parse(text);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
json = undefined;
|
|
111
|
+
}
|
|
112
|
+
if (json !== undefined) {
|
|
113
|
+
const parts = fields.map(field => json?.[field]).filter(x => typeof x === 'string' && x !== '');
|
|
114
|
+
return parts.length > 0 ? parts.join(': ') : undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return text !== '' ? text.slice(0, 200) : undefined;
|
|
118
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StorageProviderBatchEntry } from '../storage/storage-provider.js';
|
|
2
2
|
export declare const KV_STORE_CHUNK_SIZE: number;
|
|
3
|
+
export declare function chunkSizes(size: number, chunkSize: number): number[];
|
|
3
4
|
export declare function shouldRecreateChunks(chunksDir: string, numChunks: number, item: StorageProviderBatchEntry, chunkSize: number): boolean;
|
|
4
5
|
export declare function applyKVStoreEntriesChunks(kvStoreItemDescriptions: StorageProviderBatchEntry[], chunkSize: number): Promise<void>;
|
|
5
6
|
export declare const KV_BATCH_MAX_ITEMS = 256;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,eAAO,MAAM,mBAAmB,QAAqB,CAAC;AAItD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAGpE;AAED,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,iBAiEtH;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"}
|
|
@@ -3,9 +3,16 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
+
import { pipeline } from 'node:stream/promises';
|
|
6
7
|
import { directoryExists, getFileSize } from './files.js';
|
|
7
8
|
// split large files into 20MiB chunks
|
|
8
9
|
export const KV_STORE_CHUNK_SIZE = 1_024 * 1_024 * 20;
|
|
10
|
+
// The size of each chunk of a file of `size` bytes. All chunks have chunkSize
|
|
11
|
+
// bytes, except the last, which has the bytes that are left.
|
|
12
|
+
export function chunkSizes(size, chunkSize) {
|
|
13
|
+
const numChunks = Math.ceil(size / chunkSize);
|
|
14
|
+
return Array.from({ length: numChunks }, (_, chunk) => Math.min(chunkSize, size - chunk * chunkSize));
|
|
15
|
+
}
|
|
9
16
|
export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
|
|
10
17
|
console.log(` 📄 '${item.key}' - ${item.size} bytes → ${numChunks} chunks`);
|
|
11
18
|
if (!directoryExists(chunksDir)) {
|
|
@@ -17,7 +24,7 @@ export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
|
|
|
17
24
|
console.log(` ・ Recreating chunks for '${item.key}' - found ${existingChunks} existing chunk(s), expected ${numChunks}`);
|
|
18
25
|
return true;
|
|
19
26
|
}
|
|
20
|
-
const
|
|
27
|
+
const expectedFileSizes = chunkSizes(item.size, chunkSize);
|
|
21
28
|
for (let chunk = 0; chunk < numChunks; chunk++) {
|
|
22
29
|
const chunkFileName = `${chunksDir}/${chunk}`;
|
|
23
30
|
// If the chunk does not exist
|
|
@@ -26,7 +33,7 @@ export function shouldRecreateChunks(chunksDir, numChunks, item, chunkSize) {
|
|
|
26
33
|
return true;
|
|
27
34
|
}
|
|
28
35
|
// or if the chunk isn't the expected size
|
|
29
|
-
const expectedFileSize = chunk
|
|
36
|
+
const expectedFileSize = expectedFileSizes[chunk];
|
|
30
37
|
const existingFileSize = getFileSize(chunkFileName);
|
|
31
38
|
if (existingFileSize !== expectedFileSize) {
|
|
32
39
|
console.log(` ・ Recreating chunks for '${item.key}' - chunk ${chunk} existing file size ${existingFileSize} does not match expected size ${expectedFileSize}`);
|
|
@@ -52,44 +59,13 @@ export async function applyKVStoreEntriesChunks(kvStoreItemDescriptions, chunkSi
|
|
|
52
59
|
// Recreate chunks
|
|
53
60
|
fs.rmSync(chunksDir, { recursive: true, force: true });
|
|
54
61
|
fs.mkdirSync(chunksDir, { recursive: true });
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
inputStream.on('data', (chunk) => {
|
|
63
|
-
let offset = 0;
|
|
64
|
-
while (offset < chunk.length) {
|
|
65
|
-
if (!currentStream || bytesWritten >= chunkSize) {
|
|
66
|
-
if (currentStream != null) {
|
|
67
|
-
currentStream.end();
|
|
68
|
-
}
|
|
69
|
-
const chunkFileName = `${chunksDir}/${chunkIndex}`;
|
|
70
|
-
currentStream = fs.createWriteStream(chunkFileName);
|
|
71
|
-
chunkPaths.push(chunkFileName);
|
|
72
|
-
chunkIndex++;
|
|
73
|
-
bytesWritten = 0;
|
|
74
|
-
}
|
|
75
|
-
const bytesLeftInChunk = chunkSize - bytesWritten;
|
|
76
|
-
const bytesLeftInBuffer = chunk.length - offset;
|
|
77
|
-
const bytesToWrite = Math.min(bytesLeftInChunk, bytesLeftInBuffer);
|
|
78
|
-
const slice = chunk.slice(offset, offset + bytesToWrite);
|
|
79
|
-
currentStream.write(slice);
|
|
80
|
-
bytesWritten += bytesToWrite;
|
|
81
|
-
offset += bytesToWrite;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
inputStream.on('end', () => {
|
|
85
|
-
if (currentStream != null) {
|
|
86
|
-
currentStream.end();
|
|
87
|
-
}
|
|
88
|
-
resolve(chunkPaths.length);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
if (numWrittenChunks !== numChunks) {
|
|
92
|
-
throw new Error(`numWrittenChunks (${numWrittenChunks}) does not equal numChunks (${numChunks})`);
|
|
62
|
+
// Each chunk is a copy of a range of the file. pipeline() resolves
|
|
63
|
+
// after the chunk file is completely written, so the upload reads the
|
|
64
|
+
// full chunk.
|
|
65
|
+
let start = 0;
|
|
66
|
+
for (const [chunkIndex, size] of chunkSizes(item.size, chunkSize).entries()) {
|
|
67
|
+
await pipeline(fs.createReadStream(item.filePath, { start, end: start + size - 1 }), fs.createWriteStream(`${chunksDir}/${chunkIndex}`));
|
|
68
|
+
start += size;
|
|
93
69
|
}
|
|
94
70
|
}
|
|
95
71
|
for (let chunkIndex = 0; chunkIndex < numChunks; chunkIndex++) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const PROGRESS_INTERVAL = 1000;
|
|
2
|
+
export declare class ProgressLog {
|
|
3
|
+
private readonly label;
|
|
4
|
+
private readonly verbose;
|
|
5
|
+
private readonly total?;
|
|
6
|
+
private done;
|
|
7
|
+
private nextReport;
|
|
8
|
+
constructor(label: string, verbose: boolean, total?: number | undefined);
|
|
9
|
+
add(count: number, message: () => string): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/progress.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAKtC,qBAAa,WAAW;IAKpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IANzB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,UAAU,CAAqB;gBAGpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,YAAA;IAIjC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM;CAczC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
export const PROGRESS_INTERVAL = 1000;
|
|
6
|
+
// Logs the progress of a loop over many items. With verbose, it logs a line
|
|
7
|
+
// for each call. Else, it logs one line each time the count passes another
|
|
8
|
+
// PROGRESS_INTERVAL items, so that a large site does not make a large log.
|
|
9
|
+
export class ProgressLog {
|
|
10
|
+
constructor(label, verbose, total) {
|
|
11
|
+
this.label = label;
|
|
12
|
+
this.verbose = verbose;
|
|
13
|
+
this.total = total;
|
|
14
|
+
this.done = 0;
|
|
15
|
+
this.nextReport = PROGRESS_INTERVAL;
|
|
16
|
+
}
|
|
17
|
+
// Records count items. The message is made only if it is logged.
|
|
18
|
+
add(count, message) {
|
|
19
|
+
this.done += count;
|
|
20
|
+
if (this.verbose) {
|
|
21
|
+
console.log(message());
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (this.done < this.nextReport || (this.total != null && this.done >= this.total)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
console.log(` | ${this.label}: ${this.done}${this.total != null ? ` of ${this.total}` : ''}`);
|
|
28
|
+
while (this.nextReport <= this.done) {
|
|
29
|
+
this.nextReport += PROGRESS_INTERVAL;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -15,6 +15,14 @@ export type LoadPurgeTargetParams = {
|
|
|
15
15
|
purgeEnvironments: unknown;
|
|
16
16
|
};
|
|
17
17
|
export declare function loadPurgeTarget(params: LoadPurgeTargetParams): PurgeTarget | null;
|
|
18
|
-
export
|
|
18
|
+
export type PurgeOutcome = {
|
|
19
|
+
result: 'purged';
|
|
20
|
+
} | {
|
|
21
|
+
result: 'not-staged';
|
|
22
|
+
} | {
|
|
23
|
+
result: 'failed';
|
|
24
|
+
reason: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean, environment?: PurgeEnvironment): Promise<PurgeOutcome>;
|
|
19
27
|
export declare function purgeCollection(purgeTarget: PurgeTarget, publishId: string, collectionName: string): Promise<void>;
|
|
20
28
|
//# sourceMappingURL=purge.d.ts.map
|
|
@@ -1 +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,W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ACpB;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,gBAAgB,EAClC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,OAAe,EAC1B,WAAW,GAAE,gBAA+B,GAC3C,OAAO,CAAC,YAAY,CAAC,CA8BvB;AAID,wBAAsB,eAAe,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,iBAiBxG"}
|
|
@@ -75,11 +75,14 @@ export async function purgeSurrogateKey(fastlyApiContext, fastlyServiceId, surro
|
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
77
|
if (err instanceof FetchError) {
|
|
78
|
-
|
|
78
|
+
if (environment === 'staging' && err.status === 404) {
|
|
79
|
+
return { result: 'not-staged' };
|
|
80
|
+
}
|
|
81
|
+
return { result: 'failed', reason: `${err.status}${err.detail != null ? ` ${err.detail}` : ''}` };
|
|
79
82
|
}
|
|
80
83
|
throw err;
|
|
81
84
|
}
|
|
82
|
-
return
|
|
85
|
+
return { result: 'purged' };
|
|
83
86
|
}
|
|
84
87
|
// Purges the cached responses of a collection in each environment of the purge
|
|
85
88
|
// target. A failed purge is a warning, because the change to storage is done.
|
|
@@ -87,12 +90,17 @@ export async function purgeCollection(purgeTarget, publishId, collectionName) {
|
|
|
87
90
|
const surrogateKey = `${publishId}-${collectionName}`;
|
|
88
91
|
for (const environment of purgeTarget.environments) {
|
|
89
92
|
console.log(`Purging surrogate key [${surrogateKey}] on service [${purgeTarget.serviceId}] (${environment})...`);
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const outcome = await purgeSurrogateKey(purgeTarget.fastlyApiContext, purgeTarget.serviceId, surrogateKey, true, environment);
|
|
94
|
+
switch (outcome.result) {
|
|
95
|
+
case 'purged':
|
|
96
|
+
console.log('Purged');
|
|
97
|
+
break;
|
|
98
|
+
case 'not-staged':
|
|
99
|
+
console.log(`Nothing purged (${environment}): the service has no staged version, or the service ID is not correct.`);
|
|
100
|
+
break;
|
|
101
|
+
case 'failed':
|
|
102
|
+
console.warn(`⚠️ Warning: Failed purging (${environment}): ${outcome.reason}. Cached copies may be served until they expire.`);
|
|
103
|
+
break;
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The AWS S3 host name of a bucket, for the backend of the app:
|
|
3
|
+
* <bucket>.s3.<region>.amazonaws.com. The server uses the same host name for a
|
|
4
|
+
* bucket without an endpoint (see objectUrl() in
|
|
5
|
+
* src/server/storage/s3-storage-provider.ts). It needs no credentials and no
|
|
6
|
+
* network.
|
|
7
|
+
*
|
|
8
|
+
* Returns null for a bucket name with a dot: under HTTPS, such a name does not
|
|
9
|
+
* match the certificate of *.s3.<region>.amazonaws.com. Such a bucket needs
|
|
10
|
+
* an endpoint, so that the bucket is in the path of the URL.
|
|
5
11
|
*/
|
|
6
|
-
export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string):
|
|
12
|
+
export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string): string | null;
|
|
7
13
|
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKjG"}
|
package/build/cli/cli/util/s3.js
CHANGED
|
@@ -2,42 +2,20 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import { S3Client, HeadObjectCommand } from '@aws-sdk/client-s3';
|
|
6
|
-
const DUMMY_KEY = 'dummy.dat'; // placeholder, never sent over the network
|
|
7
5
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* The AWS S3 host name of a bucket, for the backend of the app:
|
|
7
|
+
* <bucket>.s3.<region>.amazonaws.com. The server uses the same host name for a
|
|
8
|
+
* bucket without an endpoint (see objectUrl() in
|
|
9
|
+
* src/server/storage/s3-storage-provider.ts). It needs no credentials and no
|
|
10
|
+
* network.
|
|
11
|
+
*
|
|
12
|
+
* Returns null for a bucket name with a dot: under HTTPS, such a name does not
|
|
13
|
+
* match the certificate of *.s3.<region>.amazonaws.com. Such a bucket needs
|
|
14
|
+
* an endpoint, so that the bucket is in the path of the URL.
|
|
11
15
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const captureHostname = (_next) => async (args) => {
|
|
16
|
-
if (typeof args.request === 'object' &&
|
|
17
|
-
args.request != null &&
|
|
18
|
-
'hostname' in args.request &&
|
|
19
|
-
typeof args.request['hostname'] === 'string') {
|
|
20
|
-
hostname = args.request['hostname'];
|
|
21
|
-
}
|
|
22
|
-
const err = new Error('SHORT_CIRCUIT');
|
|
23
|
-
err.name = 'SHORT_CIRCUIT';
|
|
24
|
-
throw err; // short-circuit before auth/send
|
|
25
|
-
};
|
|
26
|
-
client.middlewareStack.add(captureHostname, {
|
|
27
|
-
name: 'captureS3Hostname',
|
|
28
|
-
step: 'build',
|
|
29
|
-
priority: 'high', // run early in build
|
|
30
|
-
});
|
|
31
|
-
try {
|
|
32
|
-
await client.send(new HeadObjectCommand({ Bucket: bucket, Key: DUMMY_KEY }));
|
|
16
|
+
export function findHostnameForAwsS3RegionAndBucket(region, bucket) {
|
|
17
|
+
if (bucket.includes('.')) {
|
|
18
|
+
return null;
|
|
33
19
|
}
|
|
34
|
-
|
|
35
|
-
if (typeof e !== 'object' ||
|
|
36
|
-
e == null ||
|
|
37
|
-
!('name' in e) ||
|
|
38
|
-
e.name !== 'SHORT_CIRCUIT') {
|
|
39
|
-
throw e;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return hostname;
|
|
20
|
+
return `${bucket}.s3.${region}.amazonaws.com`;
|
|
43
21
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accept-html.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/accept-html.ts"],"names":[],"mappings":"AAYA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAyChE"}
|