@fastly/compute-js-static-publish 7.0.2 → 8.0.0-beta.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 +13 -4
- package/README.short.md +13 -4
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/clean.js +62 -108
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/delete.js +50 -72
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/index.js +15 -1
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/list.js +45 -73
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/promote.js +56 -93
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.js +48 -77
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/index.js +15 -1
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/manage/publish-content.js +90 -187
- package/build/cli/{commands → cli/commands}/scaffold/index.d.ts +4 -0
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -0
- package/build/cli/{commands → cli/commands}/scaffold/index.js +262 -38
- package/build/cli/cli/compression/brotli.d.ts.map +1 -0
- package/build/cli/cli/compression/gzip.d.ts.map +1 -0
- package/build/cli/cli/compression/index.d.ts.map +1 -0
- package/build/cli/{index.d.ts.map → cli/index.d.ts.map} +1 -1
- package/build/cli/{index.js → cli/index.js} +8 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +20 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/kv-store-local-provider.js +86 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts +24 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/kv-store-provider.js +182 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts +30 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/s3-storage-provider.js +201 -0
- package/build/cli/cli/storage/storage-provider.d.ts +44 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -0
- package/build/cli/cli/storage/storage-provider.js +26 -0
- package/build/cli/cli/util/api-token.d.ts.map +1 -0
- package/build/cli/cli/util/args.d.ts.map +1 -0
- package/build/cli/cli/util/aws-credentials.d.ts +12 -0
- package/build/cli/cli/util/aws-credentials.d.ts.map +1 -0
- package/build/cli/cli/util/aws-credentials.js +67 -0
- package/build/cli/{util → cli/util}/config.d.ts +1 -1
- package/build/cli/cli/util/config.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/config.js +36 -20
- package/build/cli/cli/util/content-types.d.ts.map +1 -0
- package/build/cli/cli/util/data.d.ts.map +1 -0
- package/build/cli/cli/util/fastly-toml.d.ts.map +1 -0
- package/build/cli/cli/util/files.d.ts.map +1 -0
- package/build/cli/cli/util/kv-store-items.d.ts +5 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/kv-store-items.js +3 -42
- package/build/cli/{util → cli/util}/kv-store-local-server.d.ts +4 -7
- package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/kv-store.d.ts +7 -10
- package/build/cli/cli/util/kv-store.d.ts.map +1 -0
- package/build/cli/cli/util/node.d.ts.map +1 -0
- package/build/cli/cli/util/package.d.ts.map +1 -0
- package/build/cli/{util → cli/util}/package.js +1 -1
- package/build/cli/{util → cli/util}/retryable.d.ts +3 -0
- package/build/cli/cli/util/retryable.d.ts.map +1 -0
- package/build/cli/cli/util/retryable.js +76 -0
- package/build/cli/cli/util/s3.d.ts +7 -0
- package/build/cli/cli/util/s3.d.ts.map +1 -0
- package/build/cli/cli/util/s3.js +43 -0
- package/build/cli/cli/util/variants.d.ts.map +1 -0
- package/build/{models/assets/kvstore-assets.d.ts → cli/models/assets/index.d.ts} +5 -5
- package/build/cli/models/assets/index.d.ts.map +1 -0
- package/build/cli/models/assets/index.js +33 -0
- package/build/cli/models/compression/index.d.ts.map +1 -0
- package/build/cli/models/config/kv-store-config.d.ts +6 -0
- package/build/cli/models/config/kv-store-config.d.ts.map +1 -0
- package/build/cli/models/config/kv-store-config.js +15 -0
- package/build/{models → cli/models}/config/publish-content-config.d.ts +4 -3
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -0
- package/build/cli/models/config/publisher-server-config.d.ts.map +1 -0
- package/build/cli/models/config/s3-storage-config.d.ts +8 -0
- package/build/cli/models/config/s3-storage-config.d.ts.map +1 -0
- package/build/cli/models/config/s3-storage-config.js +11 -0
- package/build/cli/models/config/static-publish-rc.d.ts +31 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -0
- package/build/cli/models/config/static-publish-rc.js +39 -0
- package/build/cli/models/metadata/index.d.ts +2 -0
- package/build/cli/models/metadata/index.d.ts.map +1 -0
- package/build/cli/models/metadata/index.js +8 -0
- package/build/cli/models/server/index.d.ts +7 -0
- package/build/cli/models/server/index.d.ts.map +1 -0
- package/build/cli/models/server/index.js +26 -0
- package/build/cli/models/time/index.d.ts.map +1 -0
- package/build/{models → cli/models}/time/index.js +5 -5
- package/build/server/models/assets/index.d.ts +17 -0
- package/build/server/models/assets/index.d.ts.map +1 -0
- package/build/server/models/assets/index.js +33 -0
- package/build/server/models/compression/index.d.ts +4 -0
- package/build/server/models/compression/index.d.ts.map +1 -0
- package/build/server/models/compression/index.js +11 -0
- package/build/server/models/config/kv-store-config.d.ts +6 -0
- package/build/server/models/config/kv-store-config.d.ts.map +1 -0
- package/build/server/models/config/kv-store-config.js +15 -0
- package/build/server/models/config/publish-content-config.d.ts +40 -0
- package/build/server/models/config/publish-content-config.d.ts.map +1 -0
- package/build/server/models/config/publisher-server-config.d.ts +20 -0
- package/build/server/models/config/publisher-server-config.d.ts.map +1 -0
- package/build/server/models/config/s3-storage-config.d.ts +8 -0
- package/build/server/models/config/s3-storage-config.d.ts.map +1 -0
- package/build/server/models/config/s3-storage-config.js +11 -0
- package/build/server/models/config/static-publish-rc.d.ts +31 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -0
- package/build/server/models/config/static-publish-rc.js +39 -0
- package/build/server/models/metadata/index.d.ts +2 -0
- package/build/server/models/metadata/index.d.ts.map +1 -0
- package/build/server/models/metadata/index.js +8 -0
- package/build/server/models/server/index.d.ts +7 -0
- package/build/server/models/server/index.d.ts.map +1 -0
- package/build/server/models/server/index.js +26 -0
- package/build/server/models/time/index.d.ts +8 -0
- package/build/server/models/time/index.d.ts.map +1 -0
- package/build/server/models/time/index.js +54 -0
- package/build/server/server/collection-selector/from-config-store.d.ts.map +1 -0
- package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -0
- package/build/server/server/collection-selector/from-request.d.ts.map +1 -0
- package/build/server/server/collection-selector/index.d.ts.map +1 -0
- package/build/server/server/collection-selector/request-collection-selector.d.ts.map +1 -0
- package/build/server/server/collection-selector/request-collection-selector.js +5 -0
- package/build/server/server/index.d.ts +8 -0
- package/build/server/server/index.d.ts.map +1 -0
- package/build/server/server/index.js +15 -0
- package/build/server/{publisher-server → server/publisher-server}/index.d.ts +14 -14
- package/build/server/server/publisher-server/index.d.ts.map +1 -0
- package/build/server/{publisher-server → server/publisher-server}/index.js +60 -61
- package/build/server/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
- package/build/server/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
- package/build/server/server/storage/kv-store-provider.d.ts +8 -0
- package/build/server/server/storage/kv-store-provider.d.ts.map +1 -0
- package/build/server/server/storage/kv-store-provider.js +24 -0
- package/build/server/server/storage/s3-storage-provider.d.ts +26 -0
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -0
- package/build/server/server/storage/s3-storage-provider.js +110 -0
- package/build/server/server/storage/storage-provider.d.ts +48 -0
- package/build/server/server/storage/storage-provider.d.ts.map +1 -0
- package/build/server/{util/kv-store.js → server/storage/storage-provider.js} +17 -39
- package/build/server/server/util/cookies.d.ts.map +1 -0
- package/build/server/server/util/kv-store.d.ts.map +1 -0
- package/build/server/server/util/kv-store.js +40 -0
- package/package.json +9 -5
- package/build/cli/commands/manage/clean.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/delete.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/index.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/list.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/promote.d.ts.map +0 -1
- package/build/cli/commands/manage/collections/update-expiration.d.ts.map +0 -1
- package/build/cli/commands/manage/index.d.ts.map +0 -1
- package/build/cli/commands/manage/publish-content.d.ts.map +0 -1
- package/build/cli/commands/scaffold/index.d.ts.map +0 -1
- package/build/cli/compression/brotli.d.ts.map +0 -1
- package/build/cli/compression/gzip.d.ts.map +0 -1
- package/build/cli/compression/index.d.ts.map +0 -1
- package/build/cli/util/api-token.d.ts.map +0 -1
- package/build/cli/util/args.d.ts.map +0 -1
- package/build/cli/util/config.d.ts.map +0 -1
- package/build/cli/util/content-types.d.ts.map +0 -1
- package/build/cli/util/data.d.ts.map +0 -1
- package/build/cli/util/fastly-toml.d.ts.map +0 -1
- package/build/cli/util/files.d.ts.map +0 -1
- package/build/cli/util/kv-store-items.d.ts +0 -13
- package/build/cli/util/kv-store-items.d.ts.map +0 -1
- package/build/cli/util/kv-store-local-server.d.ts.map +0 -1
- package/build/cli/util/kv-store.d.ts.map +0 -1
- package/build/cli/util/node.d.ts.map +0 -1
- package/build/cli/util/package.d.ts.map +0 -1
- package/build/cli/util/retryable.d.ts.map +0 -1
- package/build/cli/util/retryable.js +0 -43
- package/build/cli/util/variants.d.ts.map +0 -1
- package/build/index.d.ts +0 -6
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -7
- package/build/models/assets/kvstore-assets.d.ts.map +0 -1
- package/build/models/assets/kvstore-assets.js +0 -28
- package/build/models/compression/index.d.ts.map +0 -1
- package/build/models/config/publish-content-config.d.ts.map +0 -1
- package/build/models/config/publisher-server-config.d.ts.map +0 -1
- package/build/models/config/static-publish-rc.d.ts +0 -7
- package/build/models/config/static-publish-rc.d.ts.map +0 -1
- package/build/models/server/index.d.ts +0 -5
- package/build/models/server/index.d.ts.map +0 -1
- package/build/models/server/index.js +0 -1
- package/build/models/time/index.d.ts.map +0 -1
- package/build/server/collection-selector/from-config-store.d.ts.map +0 -1
- package/build/server/collection-selector/from-cookie.d.ts.map +0 -1
- package/build/server/collection-selector/from-request.d.ts.map +0 -1
- package/build/server/collection-selector/index.d.ts.map +0 -1
- package/build/server/collection-selector/request-collection-selector.d.ts.map +0 -1
- package/build/server/publisher-server/index.d.ts.map +0 -1
- package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +0 -1
- package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +0 -1
- package/build/server/util/cookies.d.ts.map +0 -1
- package/build/server/util/kv-store.d.ts.map +0 -1
- /package/build/cli/{commands → cli/commands}/manage/clean.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/delete.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/index.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/list.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/promote.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/collections/update-expiration.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/index.d.ts +0 -0
- /package/build/cli/{commands → cli/commands}/manage/publish-content.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/brotli.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/brotli.js +0 -0
- /package/build/cli/{compression → cli/compression}/gzip.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/gzip.js +0 -0
- /package/build/cli/{compression → cli/compression}/index.d.ts +0 -0
- /package/build/cli/{compression → cli/compression}/index.js +0 -0
- /package/build/cli/{index.d.ts → cli/index.d.ts} +0 -0
- /package/build/cli/{util → cli/util}/api-token.d.ts +0 -0
- /package/build/cli/{util → cli/util}/api-token.js +0 -0
- /package/build/cli/{util → cli/util}/args.d.ts +0 -0
- /package/build/cli/{util → cli/util}/args.js +0 -0
- /package/build/cli/{util → cli/util}/content-types.d.ts +0 -0
- /package/build/cli/{util → cli/util}/content-types.js +0 -0
- /package/build/cli/{util → cli/util}/data.d.ts +0 -0
- /package/build/cli/{util → cli/util}/data.js +0 -0
- /package/build/cli/{util → cli/util}/fastly-toml.d.ts +0 -0
- /package/build/cli/{util → cli/util}/fastly-toml.js +0 -0
- /package/build/cli/{util → cli/util}/files.d.ts +0 -0
- /package/build/cli/{util → cli/util}/files.js +0 -0
- /package/build/cli/{util → cli/util}/kv-store-local-server.js +0 -0
- /package/build/cli/{util → cli/util}/kv-store.js +0 -0
- /package/build/cli/{util → cli/util}/node.d.ts +0 -0
- /package/build/cli/{util → cli/util}/node.js +0 -0
- /package/build/cli/{util → cli/util}/package.d.ts +0 -0
- /package/build/cli/{util → cli/util}/variants.d.ts +0 -0
- /package/build/cli/{util → cli/util}/variants.js +0 -0
- /package/build/{models → cli/models}/compression/index.d.ts +0 -0
- /package/build/{models → cli/models}/compression/index.js +0 -0
- /package/build/{models → cli/models}/config/publish-content-config.js +0 -0
- /package/build/{models → cli/models}/config/publisher-server-config.d.ts +0 -0
- /package/build/{models → cli/models}/config/publisher-server-config.js +0 -0
- /package/build/{models → cli/models}/time/index.d.ts +0 -0
- /package/build/{models/config/static-publish-rc.js → server/models/config/publish-content-config.js} +0 -0
- /package/build/server/{collection-selector/request-collection-selector.js → models/config/publisher-server-config.js} +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-config-store.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-config-store.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-cookie.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-cookie.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-request.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/from-request.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/index.d.ts +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/index.js +0 -0
- /package/build/server/{collection-selector → server/collection-selector}/request-collection-selector.d.ts +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.d.ts +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-modified-since.js +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.d.ts +0 -0
- /package/build/server/{publisher-server → server/publisher-server}/serve-preconditions/if-none-match.js +0 -0
- /package/build/server/{util → server/util}/cookies.d.ts +0 -0
- /package/build/server/{util → server/util}/cookies.js +0 -0
- /package/build/server/{util → server/util}/kv-store.d.ts +0 -0
|
@@ -0,0 +1,182 @@
|
|
|
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 { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
|
|
7
|
+
import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
8
|
+
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
9
|
+
import { FetchError, loadApiToken, } from '../util/api-token.js';
|
|
10
|
+
import { rootRelative, } from '../util/files.js';
|
|
11
|
+
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, getKvStoreEntryInfo, } from '../util/kv-store.js';
|
|
12
|
+
import { applyKVStoreEntriesChunks, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
13
|
+
import { concurrentParallel, } from '../util/retryable.js';
|
|
14
|
+
export const buildStoreProvider = (config, context) => {
|
|
15
|
+
if (isKvStoreConfigRc(config) && !context.localMode) {
|
|
16
|
+
console.log(` Working on the Fastly KV Store...`);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const { kvStoreName } = getKvStoreConfigFromRc(config);
|
|
22
|
+
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
23
|
+
const apiTokenResult = loadApiToken({ commandLine: context.fastlyApiToken });
|
|
24
|
+
if (apiTokenResult == null) {
|
|
25
|
+
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.");
|
|
26
|
+
}
|
|
27
|
+
console.log(`✔️ Fastly API Token: ${apiTokenResult.apiToken.slice(0, 4)}${'*'.repeat(apiTokenResult.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
28
|
+
return new KvStoreProvider(kvStoreName, apiTokenResult.apiToken);
|
|
29
|
+
};
|
|
30
|
+
export class KvStoreProvider {
|
|
31
|
+
constructor(storeName, fastlyApiToken) {
|
|
32
|
+
this.fastlyApiContext = { apiToken: fastlyApiToken };
|
|
33
|
+
this.kvStoreName = storeName;
|
|
34
|
+
}
|
|
35
|
+
async getStorageKeys(prefix) {
|
|
36
|
+
return await getKVStoreKeys(this.fastlyApiContext, this.kvStoreName, prefix);
|
|
37
|
+
}
|
|
38
|
+
async getStorageEntry(key) {
|
|
39
|
+
const kvStoreEntry = await getKvStoreEntry(this.fastlyApiContext, this.kvStoreName, key);
|
|
40
|
+
if (kvStoreEntry == null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return kvStoreEntryToStorageEntry(kvStoreEntry);
|
|
44
|
+
}
|
|
45
|
+
async getStorageEntryInfo(key) {
|
|
46
|
+
const kvStoreEntry = await getKvStoreEntry(this.fastlyApiContext, this.kvStoreName, key, true);
|
|
47
|
+
if (kvStoreEntry == null) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return kvStoreEntryToStorageEntry(kvStoreEntry);
|
|
51
|
+
}
|
|
52
|
+
async submitStorageEntry(key, _filePath, data, metadata) {
|
|
53
|
+
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, data ?? new Uint8Array(0), metadata != null ? JSON.stringify(metadata) : undefined);
|
|
54
|
+
}
|
|
55
|
+
async deleteStorageEntry(key) {
|
|
56
|
+
await kvStoreDeleteEntry(this.fastlyApiContext, this.kvStoreName, key);
|
|
57
|
+
}
|
|
58
|
+
async applyBatch(batch) {
|
|
59
|
+
console.log(`🍪 Chunking large files...`);
|
|
60
|
+
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
61
|
+
console.log(`✅ Large files have been chunked.`);
|
|
62
|
+
console.log(`📤 Uploading entries to KV Store.`);
|
|
63
|
+
// fastlyApiContext is non-null if useKvStore is true
|
|
64
|
+
await this.doConcurrentParallel(batch.storageProviderBatchEntries.filter(x => x.write), async ({ filePath, metadataJson }, key) => {
|
|
65
|
+
const fileBytes = fs.readFileSync(filePath);
|
|
66
|
+
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
|
|
67
|
+
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
68
|
+
});
|
|
69
|
+
console.log(`✅ Uploaded entries to KV Store.`);
|
|
70
|
+
}
|
|
71
|
+
async doConcurrentParallel(objects, fn, maxConcurrent = 12) {
|
|
72
|
+
await concurrentParallel(objects, fn, (err) => {
|
|
73
|
+
if (err instanceof FetchError) {
|
|
74
|
+
return `HTTP ${err.status}`;
|
|
75
|
+
}
|
|
76
|
+
else if (err instanceof TypeError) {
|
|
77
|
+
return 'transport';
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}, maxConcurrent);
|
|
81
|
+
}
|
|
82
|
+
calculateNumChunks(size) {
|
|
83
|
+
return Math.ceil(size / KV_STORE_CHUNK_SIZE);
|
|
84
|
+
}
|
|
85
|
+
async getExistingAssetVariant(variantKey) {
|
|
86
|
+
let kvStoreItemMetadata = null;
|
|
87
|
+
const items = [{
|
|
88
|
+
key: variantKey,
|
|
89
|
+
}];
|
|
90
|
+
await this.doConcurrentParallel(items, async (_, variantKey) => {
|
|
91
|
+
// fastlyApiContext is non-null if useKvStore is true
|
|
92
|
+
const kvStoreEntryInfo = await getKvStoreEntryInfo(this.fastlyApiContext, this.kvStoreName, variantKey);
|
|
93
|
+
if (!kvStoreEntryInfo) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let itemMetadata;
|
|
97
|
+
if (kvStoreEntryInfo.metadata != null) {
|
|
98
|
+
try {
|
|
99
|
+
itemMetadata = JSON.parse(kvStoreEntryInfo.metadata);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// if the metadata does not parse successfully as JSON,
|
|
103
|
+
// treat it as though it didn't exist.
|
|
104
|
+
}
|
|
105
|
+
itemMetadata = decodeAssetVariantMetadata(itemMetadata);
|
|
106
|
+
}
|
|
107
|
+
if (itemMetadata != null) {
|
|
108
|
+
let exists = false;
|
|
109
|
+
if (itemMetadata.size <= KV_STORE_CHUNK_SIZE) {
|
|
110
|
+
// For an item equal to or smaller than the chunk size, if it exists
|
|
111
|
+
// and its metadata asserts no chunk count, then we assume it exists.
|
|
112
|
+
if (itemMetadata.numChunks === undefined) {
|
|
113
|
+
exists = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
// For chunked objects, if the first chunk exists, and its metadata asserts
|
|
118
|
+
// the same number of chunks based on size, then we assume it exists (for now).
|
|
119
|
+
// In the future we might actually check for the existence and sizes of
|
|
120
|
+
// every chunk in the KV Store.
|
|
121
|
+
const expectedNumChunks = Math.ceil(itemMetadata.size / KV_STORE_CHUNK_SIZE);
|
|
122
|
+
if (itemMetadata.numChunks === expectedNumChunks) {
|
|
123
|
+
exists = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (exists) {
|
|
127
|
+
kvStoreItemMetadata = {
|
|
128
|
+
contentEncoding: itemMetadata.contentEncoding,
|
|
129
|
+
size: itemMetadata.size,
|
|
130
|
+
hash: itemMetadata.hash,
|
|
131
|
+
numChunks: itemMetadata.numChunks,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return kvStoreItemMetadata;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export function kvStoreEntryToStorageEntry(kvStoreEntry) {
|
|
140
|
+
const storageEntry = {};
|
|
141
|
+
if (kvStoreEntry.response.body != null) {
|
|
142
|
+
storageEntry.data = kvStoreEntry.response.body;
|
|
143
|
+
}
|
|
144
|
+
if (kvStoreEntry.metadata != null) {
|
|
145
|
+
const metadata = parseKvStoreMetadata(kvStoreEntry.metadata);
|
|
146
|
+
if (metadata != null) {
|
|
147
|
+
storageEntry.metadata = metadata;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (kvStoreEntry.generation != null) {
|
|
151
|
+
storageEntry.providerMetadata = {
|
|
152
|
+
generation: kvStoreEntry.generation,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return storageEntry;
|
|
156
|
+
}
|
|
157
|
+
export function parseKvStoreMetadata(metadata) {
|
|
158
|
+
let metadataObject = undefined;
|
|
159
|
+
try {
|
|
160
|
+
metadataObject = JSON.parse(metadata);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// fail if the metadata does not parse successfully as JSON
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (metadataObject == null ||
|
|
167
|
+
typeof metadataObject !== 'object' ||
|
|
168
|
+
Array.isArray(metadataObject)) {
|
|
169
|
+
// fail if the metadata parses to string or something other than an object
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
// Convert any existing non-string values to string during read
|
|
173
|
+
const resultObject = {};
|
|
174
|
+
for (const [key, value] of Object.entries(metadataObject)) {
|
|
175
|
+
if (typeof value === 'string' ||
|
|
176
|
+
typeof value === 'number' ||
|
|
177
|
+
typeof value === 'boolean') {
|
|
178
|
+
resultObject[key] = String(value);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return resultObject;
|
|
182
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
2
|
+
import { type Command, type HttpHandlerOptions } from '@aws-sdk/types';
|
|
3
|
+
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
4
|
+
import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, type StorageProviderBatch } from './storage-provider.js';
|
|
5
|
+
type CommandOutput<C> = C extends Command<any, any, any, infer O, any> ? O : never;
|
|
6
|
+
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
7
|
+
export declare class S3StorageProvider implements StorageProvider {
|
|
8
|
+
constructor(s3Region: string, accessKeyId: string, secretAccessKey: string, s3Bucket: string, s3Endpoint?: string);
|
|
9
|
+
private readonly s3Region;
|
|
10
|
+
private readonly accessKeyId;
|
|
11
|
+
private readonly secretAccessKey;
|
|
12
|
+
private readonly s3Bucket;
|
|
13
|
+
private readonly s3Endpoint?;
|
|
14
|
+
private s3Client?;
|
|
15
|
+
getS3Client(): S3Client;
|
|
16
|
+
sendS3ClientCommand<C extends Command<any, any, any, any, any>>(command: C, options?: HttpHandlerOptions): Promise<CommandOutput<C>>;
|
|
17
|
+
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
18
|
+
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
19
|
+
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
20
|
+
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
21
|
+
deleteStorageEntry(key: string): Promise<void>;
|
|
22
|
+
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
23
|
+
doConcurrentParallel<TObject extends {
|
|
24
|
+
key: string;
|
|
25
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
26
|
+
calculateNumChunks(_size: number): number;
|
|
27
|
+
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=s3-storage-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAMA,OAAO,EAWL,QAAQ,EAET,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAY/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEnF,eAAO,MAAM,kBAAkB,EAAE,sBAoChC,CAAC;AAGF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM;IASrB,OAAO,CAAC,QAAQ,CAAC,QAAQ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EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,GACzB,OAAO,CAAC,IAAI,CAAC;IAkBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;CA8BxF"}
|
|
@@ -0,0 +1,201 @@
|
|
|
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 { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client, S3ServiceException, } from '@aws-sdk/client-s3';
|
|
7
|
+
import { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
|
|
8
|
+
import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
9
|
+
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
10
|
+
import { loadAwsCredentials, } from '../util/aws-credentials.js';
|
|
11
|
+
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
12
|
+
import { rootRelative, } from '../util/files.js';
|
|
13
|
+
export const buildStoreProvider = async (config, context) => {
|
|
14
|
+
if (isS3StorageConfigRc(config)) {
|
|
15
|
+
console.log(` Working on S3 (or compatible) storage...`);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const { region, bucket, endpoint, } = getS3StorageConfigFromRc(config);
|
|
21
|
+
console.log(` | Using S3 storage`);
|
|
22
|
+
console.log(` Region : ${region}`);
|
|
23
|
+
console.log(` Bucket : ${bucket}`);
|
|
24
|
+
console.log(` Endpoint: ${endpoint ?? 'default'}`);
|
|
25
|
+
const awsCredentialsResult = await loadAwsCredentials({
|
|
26
|
+
awsProfile: context.awsProfile,
|
|
27
|
+
awsAccessKeyId: context.awsAccessKeyId,
|
|
28
|
+
awsSecretAccessKey: context.awsSecretAccessKey,
|
|
29
|
+
});
|
|
30
|
+
if (awsCredentialsResult == null) {
|
|
31
|
+
throw new Error("❌ S3 Credentials not provided.\nProvide an AWS access key ID and secret access key that has write access to the S3 Storage.\nRefer to the README file and --help for additional information.");
|
|
32
|
+
}
|
|
33
|
+
console.log(`✔️ S3 Credentials: ${awsCredentialsResult.awsAccessKeyId.slice(0, 4)}${'*'.repeat(awsCredentialsResult.awsAccessKeyId.length - 4)} from '${awsCredentialsResult.source}'`);
|
|
34
|
+
return new S3StorageProvider(region, awsCredentialsResult.awsAccessKeyId, awsCredentialsResult.awsSecretAccessKey, bucket, endpoint);
|
|
35
|
+
};
|
|
36
|
+
export class S3StorageProvider {
|
|
37
|
+
constructor(s3Region, accessKeyId, secretAccessKey, s3Bucket, s3Endpoint) {
|
|
38
|
+
this.s3Region = s3Region;
|
|
39
|
+
this.accessKeyId = accessKeyId;
|
|
40
|
+
this.secretAccessKey = secretAccessKey;
|
|
41
|
+
this.s3Bucket = s3Bucket;
|
|
42
|
+
this.s3Endpoint = s3Endpoint;
|
|
43
|
+
}
|
|
44
|
+
getS3Client() {
|
|
45
|
+
if (this.s3Client != null) {
|
|
46
|
+
return this.s3Client;
|
|
47
|
+
}
|
|
48
|
+
this.s3Client = new S3Client({
|
|
49
|
+
region: this.s3Region,
|
|
50
|
+
endpoint: this.s3Endpoint,
|
|
51
|
+
forcePathStyle: this.s3Endpoint != null,
|
|
52
|
+
credentials: {
|
|
53
|
+
accessKeyId: this.accessKeyId,
|
|
54
|
+
secretAccessKey: this.secretAccessKey,
|
|
55
|
+
},
|
|
56
|
+
maxAttempts: 1,
|
|
57
|
+
});
|
|
58
|
+
return this.s3Client;
|
|
59
|
+
}
|
|
60
|
+
async sendS3ClientCommand(command, options) {
|
|
61
|
+
try {
|
|
62
|
+
return await this.getS3Client().send(command, options);
|
|
63
|
+
}
|
|
64
|
+
catch (ex) {
|
|
65
|
+
if (ex instanceof S3ServiceException && ex.$retryable) {
|
|
66
|
+
throw makeRetryable(ex);
|
|
67
|
+
}
|
|
68
|
+
throw ex;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getStorageKeys(prefix) {
|
|
72
|
+
const input = {
|
|
73
|
+
Bucket: this.s3Bucket,
|
|
74
|
+
MaxKeys: 4096,
|
|
75
|
+
Prefix: prefix,
|
|
76
|
+
ContinuationToken: undefined, // pagination
|
|
77
|
+
};
|
|
78
|
+
const command = new ListObjectsV2Command(input);
|
|
79
|
+
const response = await this.sendS3ClientCommand(command);
|
|
80
|
+
if (response.Contents == null) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return response.Contents
|
|
84
|
+
.map(c => c.Key)
|
|
85
|
+
.filter(c => c != null);
|
|
86
|
+
}
|
|
87
|
+
async getStorageEntry(key) {
|
|
88
|
+
const input = {
|
|
89
|
+
Bucket: this.s3Bucket, // required
|
|
90
|
+
Key: key, // required
|
|
91
|
+
};
|
|
92
|
+
const command = new GetObjectCommand(input);
|
|
93
|
+
let response;
|
|
94
|
+
try {
|
|
95
|
+
response = await this.sendS3ClientCommand(command);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
if (err instanceof S3ServiceException && (err.name === "NotFound" || err.name === "NoSuchKey")) {
|
|
99
|
+
console.log("Object does not exist");
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
throw err; // some other problem (auth, network, etc.)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (response.Body == null) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
data: response.Body.transformToWebStream(),
|
|
111
|
+
metadata: response.Metadata,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
async getStorageEntryInfo(key) {
|
|
115
|
+
const input = {
|
|
116
|
+
Bucket: this.s3Bucket, // required
|
|
117
|
+
Key: key, // required
|
|
118
|
+
};
|
|
119
|
+
const command = new HeadObjectCommand(input);
|
|
120
|
+
let response;
|
|
121
|
+
try {
|
|
122
|
+
response = await this.sendS3ClientCommand(command);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
if (err instanceof S3ServiceException && (err.name === "NotFound" || err.name === "NoSuchKey")) {
|
|
126
|
+
console.log("Object does not exist");
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw err; // some other problem (auth, network, etc.)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
metadata: response.Metadata,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async submitStorageEntry(key, _filePath, data, metadata) {
|
|
138
|
+
const input = {
|
|
139
|
+
Bucket: this.s3Bucket, // required
|
|
140
|
+
Key: key, // required
|
|
141
|
+
Body: data ?? undefined,
|
|
142
|
+
Metadata: metadata,
|
|
143
|
+
};
|
|
144
|
+
const command = new PutObjectCommand(input);
|
|
145
|
+
await this.sendS3ClientCommand(command);
|
|
146
|
+
}
|
|
147
|
+
async deleteStorageEntry(key) {
|
|
148
|
+
const input = {
|
|
149
|
+
Bucket: this.s3Bucket, // required
|
|
150
|
+
Key: key, // required
|
|
151
|
+
};
|
|
152
|
+
const command = new DeleteObjectCommand(input);
|
|
153
|
+
await this.sendS3ClientCommand(command);
|
|
154
|
+
}
|
|
155
|
+
async applyBatch(batch) {
|
|
156
|
+
console.log(`📤 Uploading entries to S3 storage.`);
|
|
157
|
+
// fastlyApiContext is non-null if useKvStore is true
|
|
158
|
+
await this.doConcurrentParallel(batch.storageProviderBatchEntries.filter(x => x.write), async ({ filePath, metadataJson }, key) => {
|
|
159
|
+
// const fileStream = fs.createReadStream(filePath);
|
|
160
|
+
const fileData = fs.readFileSync(filePath);
|
|
161
|
+
await this.submitStorageEntry(key, filePath, fileData, metadataJson);
|
|
162
|
+
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
|
|
163
|
+
});
|
|
164
|
+
console.log(`✅ Uploaded entries to S3 storage.`);
|
|
165
|
+
}
|
|
166
|
+
async doConcurrentParallel(objects, fn, maxConcurrent = 12) {
|
|
167
|
+
await concurrentParallel(objects, fn, (err) => {
|
|
168
|
+
if (err instanceof S3ServiceException) {
|
|
169
|
+
return `S3 error [${err.name}] - ${err.message}`;
|
|
170
|
+
}
|
|
171
|
+
else if (err instanceof TypeError) {
|
|
172
|
+
return 'transport';
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}, maxConcurrent);
|
|
176
|
+
}
|
|
177
|
+
calculateNumChunks(_size) {
|
|
178
|
+
return 1;
|
|
179
|
+
}
|
|
180
|
+
async getExistingAssetVariant(variantKey) {
|
|
181
|
+
let assetVariantMetadata = null;
|
|
182
|
+
await this.doConcurrentParallel([{ key: variantKey }], async (_, variantKey) => {
|
|
183
|
+
const entryInfo = await this.getStorageEntryInfo(variantKey);
|
|
184
|
+
if (entryInfo == null) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const metadata = decodeAssetVariantMetadata(entryInfo.metadata);
|
|
188
|
+
if (metadata != null) {
|
|
189
|
+
if (metadata.numChunks !== undefined) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
assetVariantMetadata = {
|
|
193
|
+
contentEncoding: metadata.contentEncoding,
|
|
194
|
+
size: metadata.size,
|
|
195
|
+
hash: metadata.hash,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return assetVariantMetadata;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type AssetVariantMetadata } from '../../models/assets/index.js';
|
|
2
|
+
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
3
|
+
export interface StorageEntry {
|
|
4
|
+
data?: ReadableStream<Uint8Array>;
|
|
5
|
+
metadata?: Record<string, string>;
|
|
6
|
+
providerMetadata?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export interface StorageProvider {
|
|
9
|
+
getStorageKeys(prefix?: string): Promise<string[] | null>;
|
|
10
|
+
getStorageEntryInfo(key: string): Promise<StorageEntry | null>;
|
|
11
|
+
getStorageEntry(key: string): Promise<StorageEntry | null>;
|
|
12
|
+
submitStorageEntry(key: string, filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
13
|
+
deleteStorageEntry(key: string): Promise<void>;
|
|
14
|
+
applyBatch(batch: StorageProviderBatch): Promise<void>;
|
|
15
|
+
doConcurrentParallel<TObject extends {
|
|
16
|
+
key: string;
|
|
17
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
18
|
+
calculateNumChunks(size: number): number;
|
|
19
|
+
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
20
|
+
}
|
|
21
|
+
export type StorageProviderBatchEntry = {
|
|
22
|
+
write: boolean;
|
|
23
|
+
size: number;
|
|
24
|
+
key: string;
|
|
25
|
+
filePath: string;
|
|
26
|
+
metadataJson?: Record<string, string>;
|
|
27
|
+
};
|
|
28
|
+
export declare class StorageProviderBatch {
|
|
29
|
+
constructor();
|
|
30
|
+
storageProviderBatchEntries: StorageProviderBatchEntry[];
|
|
31
|
+
add(entry: StorageProviderBatchEntry): void;
|
|
32
|
+
}
|
|
33
|
+
export type StorageProviderBuilderContext = {
|
|
34
|
+
computeAppDir: string;
|
|
35
|
+
localMode?: boolean;
|
|
36
|
+
fastlyApiToken?: string;
|
|
37
|
+
awsProfile?: string;
|
|
38
|
+
awsAccessKeyId?: string;
|
|
39
|
+
awsSecretAccessKey?: string;
|
|
40
|
+
};
|
|
41
|
+
export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageProviderBuilderContext) => (Promise<StorageProvider | null> | StorageProvider | null);
|
|
42
|
+
export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
|
|
43
|
+
export declare function loadStorageProviderFromStaticPublishRc(config: StaticPublishRc, context: StorageProviderBuilderContext): Promise<StorageProvider>;
|
|
44
|
+
//# sourceMappingURL=storage-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,oBAAoB,EAC1B,MAAM,8BAA8B,CAAC;AACtC,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;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC3D,kBAAkB,CAChB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,kBAAkB,CAAC,GAAG,E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,6BAA6B,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,CAAC;AAGlI,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
export class StorageProviderBatch {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.storageProviderBatchEntries = [];
|
|
8
|
+
}
|
|
9
|
+
add(entry) {
|
|
10
|
+
this.storageProviderBatchEntries.push(entry);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const _storageProviderBuilders = [];
|
|
14
|
+
export function registerStorageProviderBuilder(builder) {
|
|
15
|
+
_storageProviderBuilders.push(builder);
|
|
16
|
+
}
|
|
17
|
+
export async function loadStorageProviderFromStaticPublishRc(config, context) {
|
|
18
|
+
let storeProvider;
|
|
19
|
+
for (const builder of _storageProviderBuilders) {
|
|
20
|
+
storeProvider = await builder(config, context);
|
|
21
|
+
if (storeProvider != null) {
|
|
22
|
+
return storeProvider;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw new Error('Static Publisher Error: Invalid static-publish.rc.js, storage mode not recognized, or could not instantiate store provider.');
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAUA,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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AI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC;AAE7E,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,oBAAoB,CAAC,CAAC,CAAC,CAsCzB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEpE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EAAE,EACd,iBAAiB,EAAE,gBAAgB,EAAE,GACpC,iBAAiB,CA0BnB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type LoadAwsCredentialsResult = {
|
|
2
|
+
awsAccessKeyId: string;
|
|
3
|
+
awsSecretAccessKey: string;
|
|
4
|
+
source: string;
|
|
5
|
+
};
|
|
6
|
+
export type LoadAwsCredentialsParams = {
|
|
7
|
+
awsProfile?: any;
|
|
8
|
+
awsAccessKeyId?: any;
|
|
9
|
+
awsSecretAccessKey?: any;
|
|
10
|
+
};
|
|
11
|
+
export declare function loadAwsCredentials(params: LoadAwsCredentialsParams): Promise<LoadAwsCredentialsResult | null>;
|
|
12
|
+
//# sourceMappingURL=aws-credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-credentials.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/aws-credentials.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,wBAAwB,GAAG;IACrC,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,cAAc,CAAC,EAAE,GAAG,CAAC;IACrB,kBAAkB,CAAC,EAAE,GAAG,CAAC;CAC1B,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAuEnH"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { fromIni } from '@aws-sdk/credential-providers';
|
|
6
|
+
export async function loadAwsCredentials(params) {
|
|
7
|
+
let awsAccessKeyId = null;
|
|
8
|
+
let awsSecretAccessKey = null;
|
|
9
|
+
let source = '';
|
|
10
|
+
// Try command line arg
|
|
11
|
+
if (typeof params.awsAccessKeyId === 'string' &&
|
|
12
|
+
typeof params.awsSecretAccessKey === 'string') {
|
|
13
|
+
const id = params.awsAccessKeyId.trim() || null;
|
|
14
|
+
const key = params.awsSecretAccessKey.trim() || null;
|
|
15
|
+
if (id != null && key != null) {
|
|
16
|
+
awsAccessKeyId = id;
|
|
17
|
+
awsSecretAccessKey = key;
|
|
18
|
+
source = 'commandline';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Try env (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY)
|
|
22
|
+
if (awsAccessKeyId == null && awsSecretAccessKey == null) {
|
|
23
|
+
const id = process.env.AWS_ACCESS_KEY_ID || null;
|
|
24
|
+
const key = process.env.AWS_SECRET_ACCESS_KEY || null;
|
|
25
|
+
if (id != null && key != null) {
|
|
26
|
+
awsAccessKeyId = id;
|
|
27
|
+
awsSecretAccessKey = key;
|
|
28
|
+
source = 'env';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (awsAccessKeyId == null && awsSecretAccessKey == null) {
|
|
32
|
+
let awsProfile = undefined;
|
|
33
|
+
if (typeof params.awsProfile === 'string') {
|
|
34
|
+
awsProfile = params.awsProfile.trim() || undefined;
|
|
35
|
+
}
|
|
36
|
+
if (awsProfile == null) {
|
|
37
|
+
const profile = process.env.AWS_PROFILE || undefined;
|
|
38
|
+
if (profile != null) {
|
|
39
|
+
awsProfile = profile;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let provider;
|
|
43
|
+
try {
|
|
44
|
+
provider = await fromIni({ profile: awsProfile ?? undefined })();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
provider = null;
|
|
48
|
+
}
|
|
49
|
+
if (provider != null) {
|
|
50
|
+
const id = provider.accessKeyId || null;
|
|
51
|
+
const key = provider.secretAccessKey || null;
|
|
52
|
+
if (id != null && key != null) {
|
|
53
|
+
awsAccessKeyId = id;
|
|
54
|
+
awsSecretAccessKey = key;
|
|
55
|
+
source = `credentials (profile ${awsProfile ?? 'default'})`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (awsAccessKeyId == null || awsSecretAccessKey == null) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
awsAccessKeyId,
|
|
64
|
+
awsSecretAccessKey,
|
|
65
|
+
source,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
1
2
|
import { type PublishContentConfigNormalized } from '../../models/config/publish-content-config.js';
|
|
2
3
|
import { type PublisherServerConfigNormalized } from '../../models/config/publisher-server-config.js';
|
|
3
|
-
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
4
4
|
export declare class LoadConfigError extends Error {
|
|
5
5
|
errors: string[];
|
|
6
6
|
constructor(configFilePath: string, errors: string[]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/config.ts"],"names":[],"mappings":"AASA,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,CA2B1E;AAGD,eAAO,MAAM,0BAA0B,6DAmErC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAyB9G;AA4CD,eAAO,MAAM,6BAA6B,4EA8JxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}
|