@fastly/compute-js-static-publish 8.0.0-beta.6 → 8.0.0-beta.8
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 +1 -1
- package/README.short.md +1 -1
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +11 -20
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +11 -20
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +6 -13
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +11 -20
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +11 -20
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +11 -20
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +6 -13
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +16 -24
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +47 -28
- 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 +2 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +2 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts +4 -1
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +50 -12
- package/build/cli/cli/storage/storage-provider.d.ts +3 -3
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/purge.d.ts +3 -0
- package/build/cli/cli/util/purge.d.ts.map +1 -0
- package/build/cli/cli/util/purge.js +23 -0
- package/build/cli/cli/util/s3-credentials.d.ts +11 -0
- package/build/cli/cli/util/s3-credentials.d.ts.map +1 -0
- package/build/cli/cli/util/s3-credentials.js +38 -0
- package/build/cli/cli/util/s3.d.ts +1 -1
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +1 -1
- package/build/cli/models/metadata/index.js +1 -1
- package/build/server/models/metadata/index.js +1 -1
- package/build/server/server/index.d.ts +1 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +1 -1
- package/build/server/server/publisher-server/index.js +2 -2
- package/build/server/server/storage/s3-storage-provider.d.ts +13 -14
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.js +45 -36
- package/build/server/server/storage/storage-provider.d.ts +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/package.json +2 -3
- package/build/cli/cli/util/aws-credentials.d.ts +0 -12
- package/build/cli/cli/util/aws-credentials.d.ts.map +0 -1
- package/build/cli/cli/util/aws-credentials.js +0 -67
|
@@ -12,7 +12,7 @@ import * as fs from 'node:fs';
|
|
|
12
12
|
import { parseCommandLine } from '../../util/args.js';
|
|
13
13
|
import { dotRelative, rootRelative } from '../../util/files.js';
|
|
14
14
|
import { findComputeJsStaticPublisherVersion } from '../../util/package.js';
|
|
15
|
-
import {
|
|
15
|
+
import { findHostnameForAwsS3RegionAndBucket } from '../../util/s3.js';
|
|
16
16
|
function help() {
|
|
17
17
|
console.log(`\
|
|
18
18
|
|
|
@@ -26,8 +26,9 @@ Description:
|
|
|
26
26
|
management mode.
|
|
27
27
|
|
|
28
28
|
Options:
|
|
29
|
-
--storage-mode <mode>
|
|
30
|
-
Can be "kv-store" or "s3".
|
|
29
|
+
--storage-mode <mode> Storage mode for content storage.
|
|
30
|
+
Can be "kv-store" or "s3" (BETA).
|
|
31
|
+
(default: kv-store)
|
|
31
32
|
If --storage-mode=kv-store, then:
|
|
32
33
|
--kv-store-name <name> (required) Name of the KV Store.
|
|
33
34
|
|
|
@@ -39,8 +40,8 @@ Options:
|
|
|
39
40
|
--root-dir <path> (required) Path to static content (e.g., ./public)
|
|
40
41
|
-o, --output <dir> Output directory for Compute app (default: ./compute-js)
|
|
41
42
|
--static-publisher-working-dir <dir> Working directory for build artifacts (default: <output>/static-publisher)
|
|
42
|
-
--publish-id <id> Advanced. Prefix for KV keys (default: "default")
|
|
43
43
|
(default: ./compute-js/static-publisher)
|
|
44
|
+
--publish-id <id> Advanced. Prefix for KV keys (default: "default")
|
|
44
45
|
|
|
45
46
|
Compute Service Metadata:
|
|
46
47
|
--name <name> App name (for fastly.toml)
|
|
@@ -334,8 +335,8 @@ function processPublicDirToken(filepath, publicDir) {
|
|
|
334
335
|
export async function action(actionArgs) {
|
|
335
336
|
const optionDefinitions = [
|
|
336
337
|
{ name: 'verbose', type: Boolean },
|
|
337
|
-
//
|
|
338
|
-
{ name: 'storage-mode', type: String, },
|
|
338
|
+
// Storage mode for content storage. Can be "kv-store" or "s3".
|
|
339
|
+
{ name: 'storage-mode', type: String, defaultValue: 'kv-store', },
|
|
339
340
|
// If storage-mode=kv-store, then:
|
|
340
341
|
// Required. The name of a Fastly KV Store to hold the content assets.
|
|
341
342
|
// It is also added to the fastly.toml that is generated.
|
|
@@ -540,7 +541,7 @@ export async function action(actionArgs) {
|
|
|
540
541
|
const fastlyServiceId = options.serviceId;
|
|
541
542
|
const storageMode = options.storageMode;
|
|
542
543
|
if (!(storageMode === 'kv-store' || storageMode === 's3')) {
|
|
543
|
-
console.error(`❌
|
|
544
|
+
console.error(`❌ parameter --storage-mode must be set to 'kv-store' or 's3'.`);
|
|
544
545
|
process.exitCode = 1;
|
|
545
546
|
return;
|
|
546
547
|
}
|
|
@@ -569,7 +570,11 @@ export async function action(actionArgs) {
|
|
|
569
570
|
}
|
|
570
571
|
let s3Endpoint = options.s3Endpoint;
|
|
571
572
|
if (s3Endpoint == null || s3Endpoint === '') {
|
|
572
|
-
|
|
573
|
+
// If endpoint is not presented, we assume it's from AWS,
|
|
574
|
+
// and ask the SDK what the hostname would be.
|
|
575
|
+
// This is required because we need to add the hostname as a
|
|
576
|
+
// backend in the Compute service.
|
|
577
|
+
s3Endpoint = await findHostnameForAwsS3RegionAndBucket(s3Region, s3Bucket);
|
|
573
578
|
if (s3Endpoint) {
|
|
574
579
|
console.log('✅ S3 endpoint resolved:', s3Endpoint);
|
|
575
580
|
}
|
|
@@ -614,7 +619,7 @@ export async function action(actionArgs) {
|
|
|
614
619
|
console.log('KV Store Name :', kvStoreName);
|
|
615
620
|
}
|
|
616
621
|
else if (storageMode === 's3') {
|
|
617
|
-
console.log('Storage Name : S3
|
|
622
|
+
console.log('Storage Name : S3 (or compatible) storage (BETA)');
|
|
618
623
|
console.log('S3 Region :', s3Region);
|
|
619
624
|
console.log('S3 Bucket :', s3Bucket);
|
|
620
625
|
console.log('S3 Endpoint :', String(s3EndpointUrl));
|
|
@@ -671,7 +676,7 @@ export async function action(actionArgs) {
|
|
|
671
676
|
author,
|
|
672
677
|
type: 'module',
|
|
673
678
|
devDependencies: {
|
|
674
|
-
"@fastly/cli": "^
|
|
679
|
+
"@fastly/cli": "^13.1.0",
|
|
675
680
|
'@fastly/compute-js-static-publish': computeJsStaticPublisherVersion,
|
|
676
681
|
},
|
|
677
682
|
dependencies: {
|
|
@@ -689,10 +694,15 @@ export async function action(actionArgs) {
|
|
|
689
694
|
if (storageMode === 'kv-store') {
|
|
690
695
|
const localServerKvStorePath = dotRelative(computeJsDir, path.resolve(staticPublisherWorkingDir, 'kvstore.json'));
|
|
691
696
|
fastlyTomlLocalServer = /* language=text */ `\
|
|
697
|
+
[local_server]
|
|
698
|
+
|
|
692
699
|
[local_server.kv_stores]
|
|
693
700
|
${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
694
701
|
`;
|
|
695
702
|
fastlyTomlSetup = /* language=text */ `\
|
|
703
|
+
[setup]
|
|
704
|
+
|
|
705
|
+
[setup.kv_stores]
|
|
696
706
|
[setup.kv_stores.${kvStoreName}]
|
|
697
707
|
`;
|
|
698
708
|
// kvstore.json
|
|
@@ -700,24 +710,37 @@ ${kvStoreName} = { file = "${localServerKvStorePath}", format = "json" }
|
|
|
700
710
|
}
|
|
701
711
|
else if (storageMode === 's3') {
|
|
702
712
|
fastlyTomlLocalServer = /* language=text */ `\
|
|
713
|
+
[local_server]
|
|
714
|
+
|
|
703
715
|
[local_server.secret_stores]
|
|
704
|
-
[[local_server.secret_stores.
|
|
705
|
-
key = "
|
|
706
|
-
env = "
|
|
707
|
-
[[local_server.secret_stores.
|
|
708
|
-
key = "
|
|
709
|
-
env = "
|
|
716
|
+
[[local_server.secret_stores.S3_CREDENTIALS]]
|
|
717
|
+
key = "S3_ACCESS_KEY_ID"
|
|
718
|
+
env = "S3_ACCESS_KEY_ID"
|
|
719
|
+
[[local_server.secret_stores.S3_CREDENTIALS]]
|
|
720
|
+
key = "S3_SECRET_ACCESS_KEY"
|
|
721
|
+
env = "S3_SECRET_ACCESS_KEY"
|
|
710
722
|
|
|
711
723
|
[local_server.backends]
|
|
712
|
-
[local_server.backends.
|
|
724
|
+
[local_server.backends.s3_storage]
|
|
713
725
|
url = "${String(s3EndpointUrl)}"
|
|
714
726
|
override_host = "${s3EndpointUrl.hostname}"
|
|
715
727
|
`;
|
|
716
728
|
fastlyTomlSetup = /* language=text */ `\
|
|
717
|
-
[setup
|
|
729
|
+
[setup]
|
|
730
|
+
|
|
731
|
+
[setup.backends]
|
|
732
|
+
[setup.backends.s3_storage]
|
|
718
733
|
address = "${s3EndpointUrl.hostname}"
|
|
719
734
|
description = "S3 API endpoint"
|
|
720
735
|
port = 443
|
|
736
|
+
[setup.secret_stores]
|
|
737
|
+
[setup.secret_stores.S3_CREDENTIALS]
|
|
738
|
+
description = "Credentials for S3 storage"
|
|
739
|
+
[setup.secret_stores.S3_CREDENTIALS.items]
|
|
740
|
+
[setup.secret_stores.S3_CREDENTIALS.items.S3_ACCESS_KEY_ID]
|
|
741
|
+
description = "Access Key ID"
|
|
742
|
+
[setup.secret_stores.S3_CREDENTIALS.items.S3_SECRET_ACCESS_KEY]
|
|
743
|
+
description = "Secret Access Key"
|
|
721
744
|
`;
|
|
722
745
|
}
|
|
723
746
|
resourceFiles['fastly.toml'] = /* language=text */ `\
|
|
@@ -906,25 +929,21 @@ To publish your content to your S3-compatible bucket
|
|
|
906
929
|
Bucket: ${s3Bucket}
|
|
907
930
|
Endpoint: ${String(s3EndpointUrl)}
|
|
908
931
|
|
|
909
|
-
Using an
|
|
910
|
-
cd ${COMPUTE_JS_DIR}
|
|
911
|
-
AWS_PROFILE=xxxx npm run s3:publish
|
|
912
|
-
|
|
913
|
-
Using AWS IAM credentials, type:
|
|
932
|
+
Using an access key ID and secret access key for S3, type:
|
|
914
933
|
cd ${COMPUTE_JS_DIR}
|
|
915
|
-
|
|
934
|
+
S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run s3:publish
|
|
916
935
|
|
|
917
936
|
To run your Compute application locally
|
|
918
937
|
|
|
919
938
|
Run the following commands:
|
|
920
939
|
cd ${COMPUTE_JS_DIR}
|
|
921
|
-
|
|
940
|
+
S3_ACCESS_KEY_ID=xxxx S3_SECRET_ACCESS_KEY=xxxx npm run dev:start
|
|
922
941
|
|
|
923
942
|
To build and deploy to your Compute service:
|
|
924
943
|
|
|
925
|
-
Create a Secret Store in your account named
|
|
926
|
-
|
|
927
|
-
|
|
944
|
+
Create a Secret Store in your account named S3_CREDENTIALS, and set the following values:
|
|
945
|
+
S3_ACCESS_KEY_ID: xxxx
|
|
946
|
+
S3_SECRET_ACCESS_KEY: xxxx
|
|
928
947
|
|
|
929
948
|
Run the following commands:
|
|
930
949
|
cd ${COMPUTE_JS_DIR}
|
|
@@ -16,5 +16,6 @@ export declare class KvStoreLocalProvider implements StorageProvider {
|
|
|
16
16
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
17
17
|
calculateNumChunks(size: number): number;
|
|
18
18
|
getExistingAssetVariant(_variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
19
|
+
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
19
20
|
}
|
|
20
21
|
//# sourceMappingURL=kv-store-local-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-local-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-local-provider.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,oBAAoB,EAC1B,MAAM,8BAA8B,CAAC;AAoBtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,kBAAkB,EAAE,sBAkBhC,CAAC;AAEF,qBAAa,oBAAqB,YAAW,eAAe;gBAExD,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM;IAMvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAEzB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAQzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAc1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAA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C,MAAM,EAAE,GAAG,IAAI,CAAC;IAQzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAc1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAsBV,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9C,UAAU,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBtD,oBAAoB,CAAC,OAAO,SAAS;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EACxD,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;IAWhB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIlC,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAMlF,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAE9D"}
|
|
@@ -18,6 +18,7 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
18
18
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
19
19
|
calculateNumChunks(size: number): number;
|
|
20
20
|
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
21
|
+
purgeSurrogateKey(_surrogateKey: string): Promise<void>;
|
|
21
22
|
}
|
|
22
23
|
export declare function kvStoreEntryToStorageEntry(kvStoreEntry: KvStoreEntryInfo): StorageEntry;
|
|
23
24
|
export declare function parseKvStoreMetadata(metadata: string): Record<string, string> | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EACL,KAAK,gBAAgB,EAMtB,MAAM,qBAAqB,CAAC;AAQ7B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,kBAAkB,EAAE,sBAsBhC,CAAC;AAEF,qBAAa,eAAgB,YAAW,eAAe;gBAEnD,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM;IAMxB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IAEd,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAUzD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAe1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAiB9D,kBAAkB,CACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UA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AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,iCAiCpD"}
|
|
@@ -5,7 +5,9 @@ import { type StorageEntry, type StorageProvider, type StorageProviderBuilder, t
|
|
|
5
5
|
type CommandOutput<C> = C extends Command<any, any, any, infer O, any> ? O : never;
|
|
6
6
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
7
7
|
export declare class S3StorageProvider implements StorageProvider {
|
|
8
|
-
constructor(s3Region: string, accessKeyId: string, secretAccessKey: string, s3Bucket: string, s3Endpoint?: string);
|
|
8
|
+
constructor(fastlyServiceId: string | undefined, fastlyApiToken: string | undefined, s3Region: string, accessKeyId: string, secretAccessKey: string, s3Bucket: string, s3Endpoint?: string);
|
|
9
|
+
private readonly fastlyServiceId?;
|
|
10
|
+
private readonly fastlyApiContext?;
|
|
9
11
|
private readonly s3Region;
|
|
10
12
|
private readonly accessKeyId;
|
|
11
13
|
private readonly secretAccessKey;
|
|
@@ -25,6 +27,7 @@ export declare class S3StorageProvider implements StorageProvider {
|
|
|
25
27
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
26
28
|
calculateNumChunks(_size: number): number;
|
|
27
29
|
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
30
|
+
purgeSurrogateKey(surrogateKey: string): Promise<void>;
|
|
28
31
|
}
|
|
29
32
|
export {};
|
|
30
33
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAOA,OAAO,EAWL,QAAQ,EAET,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ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|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
6
7
|
import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client, S3ServiceException, } from '@aws-sdk/client-s3';
|
|
7
8
|
import { decodeAssetVariantMetadata, } from '../../models/assets/index.js';
|
|
8
9
|
import { isS3StorageConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
9
10
|
import { getS3StorageConfigFromRc, } from '../../models/config/s3-storage-config.js';
|
|
10
|
-
import {
|
|
11
|
+
import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
11
12
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
12
13
|
import { rootRelative, } from '../util/files.js';
|
|
14
|
+
import { loadApiToken, } from '../util/api-token.js';
|
|
15
|
+
import { readServiceId, } from '../util/fastly-toml.js';
|
|
16
|
+
import { purgeSurrogateKey, } from '../util/purge.js';
|
|
13
17
|
export const buildStoreProvider = async (config, context) => {
|
|
14
18
|
if (isS3StorageConfigRc(config)) {
|
|
15
|
-
console.log(` Working on S3 (or compatible) storage...`);
|
|
19
|
+
console.log(` Working on S3 (or compatible) storage (BETA)...`);
|
|
16
20
|
}
|
|
17
21
|
else {
|
|
18
22
|
return null;
|
|
19
23
|
}
|
|
20
24
|
const { region, bucket, endpoint, } = getS3StorageConfigFromRc(config);
|
|
21
|
-
console.log(` | Using S3 storage`);
|
|
25
|
+
console.log(` | Using S3 storage (BETA)`);
|
|
22
26
|
console.log(` Region : ${region}`);
|
|
23
27
|
console.log(` Bucket : ${bucket}`);
|
|
24
28
|
console.log(` Endpoint: ${endpoint ?? 'default'}`);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
awsSecretAccessKey: context.awsSecretAccessKey,
|
|
29
|
+
const s3CredentialsResult = await loadS3Credentials({
|
|
30
|
+
s3AccessKeyId: context.s3AccessKeyId,
|
|
31
|
+
s3SecretAccessKey: context.s3SecretAccessKey,
|
|
29
32
|
});
|
|
30
|
-
if (
|
|
31
|
-
throw new Error("❌ S3 Credentials not provided.\nProvide an
|
|
33
|
+
if (s3CredentialsResult == null) {
|
|
34
|
+
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.");
|
|
32
35
|
}
|
|
33
|
-
console.log(`✔️ S3 Credentials: ${
|
|
34
|
-
|
|
36
|
+
console.log(`✔️ S3 Credentials: ${s3CredentialsResult.s3AccessKeyId.slice(0, 4)}${'*'.repeat(s3CredentialsResult.s3AccessKeyId.length - 4)} from '${s3CredentialsResult.source}'`);
|
|
37
|
+
const fastlyTomlPath = path.resolve(context.computeAppDir, 'fastly.toml');
|
|
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);
|
|
35
53
|
};
|
|
36
54
|
export class S3StorageProvider {
|
|
37
|
-
constructor(s3Region, accessKeyId, secretAccessKey, s3Bucket, s3Endpoint) {
|
|
55
|
+
constructor(fastlyServiceId, fastlyApiToken, s3Region, accessKeyId, secretAccessKey, s3Bucket, s3Endpoint) {
|
|
56
|
+
this.fastlyServiceId = fastlyServiceId;
|
|
57
|
+
this.fastlyApiContext = fastlyApiToken != null ? { apiToken: fastlyApiToken } : undefined;
|
|
38
58
|
this.s3Region = s3Region;
|
|
39
59
|
this.accessKeyId = accessKeyId;
|
|
40
60
|
this.secretAccessKey = secretAccessKey;
|
|
@@ -198,4 +218,22 @@ export class S3StorageProvider {
|
|
|
198
218
|
});
|
|
199
219
|
return assetVariantMetadata;
|
|
200
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
|
+
}
|
|
201
239
|
}
|
|
@@ -17,6 +17,7 @@ export interface StorageProvider {
|
|
|
17
17
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
18
18
|
calculateNumChunks(size: number): number;
|
|
19
19
|
getExistingAssetVariant(variantKey: string): Promise<AssetVariantMetadata | null>;
|
|
20
|
+
purgeSurrogateKey(surrogateKey: string): Promise<void>;
|
|
20
21
|
}
|
|
21
22
|
export type StorageProviderBatchEntry = {
|
|
22
23
|
write: boolean;
|
|
@@ -34,9 +35,8 @@ export type StorageProviderBuilderContext = {
|
|
|
34
35
|
computeAppDir: string;
|
|
35
36
|
localMode?: boolean;
|
|
36
37
|
fastlyApiToken?: string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
awsSecretAccessKey?: string;
|
|
38
|
+
s3AccessKeyId?: string;
|
|
39
|
+
s3SecretAccessKey?: string;
|
|
40
40
|
};
|
|
41
41
|
export type StorageProviderBuilder = (config: StaticPublishRc, context: StorageProviderBuilderContext) => (Promise<StorageProvider | null> | StorageProvider | null);
|
|
42
42
|
export declare function registerStorageProviderBuilder(builder: StorageProviderBuilder): void;
|
|
@@ -1 +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,U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CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC,CAAC;AAEF,qBAAa,oBAAoB;;IAI/B,2BAA2B,EAAE,yBAAyB,EAAE,CAAC;IACzD,GAAG,CAAC,KAAK,EAAE,yBAAyB;CAGrC;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AACF,MAAM,MAAM,sBAAsB,GAChC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,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 @@
|
|
|
1
|
+
{"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAElF,wBAAsB,iBAAiB,CACrC,gBAAgB,EAAE,gBAAgB,EAClC,eAAe,EAAE,MAAM,EACvB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,OAAe,oBAuB3B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { callFastlyApi, FetchError } from './api-token.js';
|
|
6
|
+
export async function purgeSurrogateKey(fastlyApiContext, fastlyServiceId, surrogateKey, softPurge = false) {
|
|
7
|
+
const endpoint = `/service/${encodeURIComponent(fastlyServiceId)}/purge`;
|
|
8
|
+
try {
|
|
9
|
+
const headers = new Headers();
|
|
10
|
+
headers.set('surrogate-key', surrogateKey);
|
|
11
|
+
if (softPurge) {
|
|
12
|
+
headers.set('fastly-soft-purge', '1');
|
|
13
|
+
}
|
|
14
|
+
await callFastlyApi(fastlyApiContext, endpoint, `Purging surrogate key [${surrogateKey}] on service [${fastlyServiceId}]`, null, { method: 'POST', headers });
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (err instanceof FetchError) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type LoadS3CredentialsResult = {
|
|
2
|
+
s3AccessKeyId: string;
|
|
3
|
+
s3SecretAccessKey: string;
|
|
4
|
+
source: string;
|
|
5
|
+
};
|
|
6
|
+
export type LoadS3CredentialsParams = {
|
|
7
|
+
s3AccessKeyId?: any;
|
|
8
|
+
s3SecretAccessKey?: any;
|
|
9
|
+
};
|
|
10
|
+
export declare function loadS3Credentials(params: LoadS3CredentialsParams): Promise<LoadS3CredentialsResult | null>;
|
|
11
|
+
//# sourceMappingURL=s3-credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"s3-credentials.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3-credentials.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,iBAAiB,CAAC,EAAE,GAAG,CAAC;CACzB,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAwChH"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
export async function loadS3Credentials(params) {
|
|
6
|
+
let s3AccessKeyId = null;
|
|
7
|
+
let s3SecretAccessKey = null;
|
|
8
|
+
let source = '';
|
|
9
|
+
// Try command line arg
|
|
10
|
+
if (typeof params.s3AccessKeyId === 'string' &&
|
|
11
|
+
typeof params.s3SecretAccessKey === 'string') {
|
|
12
|
+
const id = params.s3AccessKeyId.trim() || null;
|
|
13
|
+
const key = params.s3SecretAccessKey.trim() || null;
|
|
14
|
+
if (id != null && key != null) {
|
|
15
|
+
s3AccessKeyId = id;
|
|
16
|
+
s3SecretAccessKey = key;
|
|
17
|
+
source = 'commandline';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// Try env (S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY)
|
|
21
|
+
if (s3AccessKeyId == null && s3SecretAccessKey == null) {
|
|
22
|
+
const id = process.env.S3_ACCESS_KEY_ID || null;
|
|
23
|
+
const key = process.env.S3_SECRET_ACCESS_KEY || null;
|
|
24
|
+
if (id != null && key != null) {
|
|
25
|
+
s3AccessKeyId = id;
|
|
26
|
+
s3SecretAccessKey = key;
|
|
27
|
+
source = 'env';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (s3AccessKeyId == null || s3SecretAccessKey == null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
s3AccessKeyId,
|
|
35
|
+
s3SecretAccessKey,
|
|
36
|
+
source,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* - Uses client-s3's own endpoint resolution logic (so it's always accurate).
|
|
4
4
|
* - No network calls; intercepts at the build step.
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function findHostnameForAwsS3RegionAndBucket(region: string, bucket: string): Promise<string>;
|
|
7
7
|
//# sourceMappingURL=s3.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAsB,
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/s3.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,wBAAsB,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqCzG"}
|
package/build/cli/cli/util/s3.js
CHANGED
|
@@ -9,7 +9,7 @@ const DUMMY_KEY = 'dummy.dat'; // placeholder, never sent over the network
|
|
|
9
9
|
* - Uses client-s3's own endpoint resolution logic (so it's always accurate).
|
|
10
10
|
* - No network calls; intercepts at the build step.
|
|
11
11
|
*/
|
|
12
|
-
export async function
|
|
12
|
+
export async function findHostnameForAwsS3RegionAndBucket(region, bucket) {
|
|
13
13
|
const client = new S3Client({ region });
|
|
14
14
|
let hostname = '';
|
|
15
15
|
const captureHostname = (_next) => async (args) => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
//
|
|
5
|
+
// To work with some platforms such as S3 that insist on lowercasing their metadata keys
|
|
6
6
|
export function getMetadataFieldValue(metadata, key) {
|
|
7
7
|
return metadata[key] ?? metadata[key.toLowerCase()] ?? undefined;
|
|
8
8
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
//
|
|
5
|
+
// To work with some platforms such as S3 that insist on lowercasing their metadata keys
|
|
6
6
|
export function getMetadataFieldValue(metadata, key) {
|
|
7
7
|
return metadata[key] ?? metadata[key.toLowerCase()] ?? undefined;
|
|
8
8
|
}
|
|
@@ -3,6 +3,6 @@ export { type PublishContentConfig } from '../models/config/publish-content-conf
|
|
|
3
3
|
export * as collectionSelector from './collection-selector/index.js';
|
|
4
4
|
export { CookieCollectionSelector, type CookieCollectionSelectorOpts, } from './collection-selector/from-cookie.js';
|
|
5
5
|
export { type StorageProvider, type StorageProviderBuilder, type StorageEntry, registerStorageProviderBuilder, } from './storage/storage-provider.js';
|
|
6
|
-
export {
|
|
6
|
+
export { setSecretStoreForS3Credentials, setSecretStoreKeyForS3AccessKeyId, setSecretStoreKeyForS3SecretAccessKey, setS3CredentialsBuilder, } from './storage/s3-storage-provider.js';
|
|
7
7
|
export { PublisherServer } from './publisher-server/index.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export * as collectionSelector from './collection-selector/index.js';
|
|
6
6
|
export { CookieCollectionSelector, } from './collection-selector/from-cookie.js';
|
|
7
7
|
export { registerStorageProviderBuilder, } from './storage/storage-provider.js';
|
|
8
|
-
export {
|
|
8
|
+
export { setSecretStoreForS3Credentials, setSecretStoreKeyForS3AccessKeyId, setSecretStoreKeyForS3SecretAccessKey, setS3CredentialsBuilder, } from './storage/s3-storage-provider.js';
|
|
9
9
|
export { PublisherServer } from './publisher-server/index.js';
|
|
10
10
|
// Register storage builder providers
|
|
11
11
|
import { registerStorageProviderBuilder } from './storage/storage-provider.js';
|
|
@@ -61,7 +61,7 @@ export class PublisherServer {
|
|
|
61
61
|
return this.settingsCached;
|
|
62
62
|
}
|
|
63
63
|
const settingsFileKey = `${this.publishId}_settings_${this.activeCollectionName}`;
|
|
64
|
-
const settingsFile = await this.storageProvider.getEntry(settingsFileKey);
|
|
64
|
+
const settingsFile = await this.storageProvider.getEntry(settingsFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'settings']);
|
|
65
65
|
if (settingsFile == null) {
|
|
66
66
|
console.error(`Settings File not found at ${settingsFileKey}.`);
|
|
67
67
|
console.error(`You may need to publish your application.`);
|
|
@@ -96,7 +96,7 @@ export class PublisherServer {
|
|
|
96
96
|
return this.assetEntryMapCache;
|
|
97
97
|
}
|
|
98
98
|
const indexFileKey = `${this.publishId}_index_${this.activeCollectionName}`;
|
|
99
|
-
const indexFile = await this.storageProvider.getEntry(indexFileKey);
|
|
99
|
+
const indexFile = await this.storageProvider.getEntry(indexFileKey, [`${this.publishId}-${this.activeCollectionName}`, 'index']);
|
|
100
100
|
if (indexFile == null) {
|
|
101
101
|
console.error(`Index File not found at ${indexFileKey}.`);
|
|
102
102
|
console.error(`You may need to publish your application.`);
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Command } from '@smithy/types';
|
|
2
|
+
import { S3ClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from '@aws-sdk/client-s3';
|
|
2
3
|
import { type StorageEntry, type StorageProvider, StorageProviderBuilder } from './storage-provider.js';
|
|
3
|
-
export type
|
|
4
|
+
export type S3Credentials = {
|
|
4
5
|
accessKeyId: string;
|
|
5
6
|
secretAccessKey: string;
|
|
6
7
|
};
|
|
7
|
-
export type
|
|
8
|
+
export type S3CredentialsBuilder = () => (S3Credentials | Promise<S3Credentials>);
|
|
8
9
|
export declare const buildStoreProvider: StorageProviderBuilder;
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
|
|
14
|
-
secretAccessKey: string;
|
|
15
|
-
}>;
|
|
16
|
-
export declare function setAwsCredentialsBuilder(awsCredentialsBuilder: AwsCredentialsBuilder): void;
|
|
10
|
+
export declare function setSecretStoreForS3Credentials(secretStoreName: string): void;
|
|
11
|
+
export declare function setSecretStoreKeyForS3AccessKeyId(secretStoreKey: string): void;
|
|
12
|
+
export declare function setSecretStoreKeyForS3SecretAccessKey(secretStoreKey: string): void;
|
|
13
|
+
export declare function buildS3CredentialsFromSecretStore(): Promise<S3Credentials>;
|
|
14
|
+
export declare function setS3CredentialsBuilder(s3CredentialsBuilder: S3CredentialsBuilder): void;
|
|
17
15
|
export type S3StorageProviderParams = {
|
|
18
16
|
s3Endpoint?: string;
|
|
19
17
|
s3FastlyBackendName?: string;
|
|
20
18
|
};
|
|
19
|
+
type S3ClientCommand<InputType extends ServiceInputTypes, OutputType extends ServiceOutputTypes> = Command<ServiceInputTypes, InputType, ServiceOutputTypes, OutputType, S3ClientResolvedConfig>;
|
|
21
20
|
export declare class S3StorageProvider implements StorageProvider {
|
|
22
21
|
constructor(s3Region: string, s3Bucket: string, params?: S3StorageProviderParams);
|
|
23
22
|
private readonly s3Region;
|
|
24
23
|
private readonly s3Bucket;
|
|
25
24
|
private readonly s3Endpoint?;
|
|
26
25
|
private readonly s3FastlyBackendName?;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
getEntry(key: string): Promise<StorageEntry | null>;
|
|
26
|
+
sendS3Command<InputType extends ServiceInputTypes, OutputType extends ServiceOutputTypes>(command: S3ClientCommand<InputType, OutputType>, requestInit?: RequestInit): Promise<OutputType>;
|
|
27
|
+
getEntry(key: string, tags?: string[]): Promise<StorageEntry | null>;
|
|
30
28
|
}
|
|
29
|
+
export {};
|
|
31
30
|
//# sourceMappingURL=s3-storage-provider.d.ts.map
|