@fastly/compute-js-static-publish 7.0.2 → 8.0.0-beta.1
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
|
@@ -3,14 +3,11 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import { decodeIndexMetadata } from '../../../../models/server/index.js';
|
|
6
7
|
import { isExpired } from '../../../../models/time/index.js';
|
|
7
|
-
import { loadApiToken } from '../../../util/api-token.js';
|
|
8
8
|
import { parseCommandLine } from '../../../util/args.js';
|
|
9
9
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
10
|
-
import {
|
|
11
|
-
import { getKvStoreEntry, getKVStoreKeys } from '../../../util/kv-store.js';
|
|
12
|
-
import { isNodeError } from '../../../util/node.js';
|
|
13
|
-
import { getLocalKvStoreEntry, getLocalKVStoreKeys } from "../../../util/kv-store-local-server.js";
|
|
10
|
+
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
14
11
|
function help() {
|
|
15
12
|
console.log(`\
|
|
16
13
|
|
|
@@ -20,7 +17,7 @@ Usage:
|
|
|
20
17
|
Description:
|
|
21
18
|
Lists all collections currently published in the KV Store.
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
KV Store Options:
|
|
24
21
|
--local Instead of working with the Fastly KV Store, operate on
|
|
25
22
|
local files that will be used to simulate the KV Store
|
|
26
23
|
with the local development environment.
|
|
@@ -30,6 +27,20 @@ Global Options:
|
|
|
30
27
|
1. FASTLY_API_TOKEN environment variable
|
|
31
28
|
2. Logged-in Fastly CLI profile
|
|
32
29
|
|
|
30
|
+
S3 Storage Options:
|
|
31
|
+
--aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
|
|
32
|
+
--aws-secret-access-key=<key> interface with S3.
|
|
33
|
+
If not set, the tool will check:
|
|
34
|
+
1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
|
|
35
|
+
environment variables
|
|
36
|
+
2. The aws credentials file, see below
|
|
37
|
+
|
|
38
|
+
--aws-profile=<profile> Profile within the aws credentials file.
|
|
39
|
+
If not set, the tool will check:
|
|
40
|
+
1. AWS_PROFILE environment variable
|
|
41
|
+
2. The default profile, if set
|
|
42
|
+
|
|
43
|
+
Global Options:
|
|
33
44
|
-h, --help Show this help message and exit.
|
|
34
45
|
`);
|
|
35
46
|
}
|
|
@@ -38,6 +49,9 @@ export async function action(actionArgs) {
|
|
|
38
49
|
{ name: 'verbose', type: Boolean },
|
|
39
50
|
{ name: 'local', type: Boolean },
|
|
40
51
|
{ name: 'fastly-api-token', type: String, },
|
|
52
|
+
{ name: 'aws-profile', type: String, },
|
|
53
|
+
{ name: 'aws-access-key-id', type: String, },
|
|
54
|
+
{ name: 'aws-secret-access-key', type: String, },
|
|
41
55
|
];
|
|
42
56
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
43
57
|
if (parsed.needHelp) {
|
|
@@ -49,49 +63,11 @@ export async function action(actionArgs) {
|
|
|
49
63
|
help();
|
|
50
64
|
return;
|
|
51
65
|
}
|
|
52
|
-
const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
66
|
+
const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, ['aws-profile']: awsProfile, ['aws-access-key-id']: awsAccessKeyId, ['aws-secret-access-key']: awsSecretAccessKey, } = parsed.commandLineOptions;
|
|
53
67
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
54
68
|
// in other words, the directory that contains `fastly.toml`.
|
|
55
69
|
const computeAppDir = path.resolve();
|
|
56
|
-
// Check to see if we have a service ID listed in `fastly.toml`.
|
|
57
|
-
// If we do NOT, then we do not use the KV Store.
|
|
58
|
-
let serviceId;
|
|
59
|
-
try {
|
|
60
|
-
serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
if (isNodeError(err) && err.code === 'ENOENT') {
|
|
64
|
-
console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
|
|
65
|
-
process.exitCode = 1;
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
|
|
69
|
-
process.exitCode = 1;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
70
|
console.log(`📃 Listing collections...`);
|
|
73
|
-
// Verify targets
|
|
74
|
-
let fastlyApiContext = undefined;
|
|
75
|
-
if (localMode) {
|
|
76
|
-
console.log(` Working on local simulated KV Store...`);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
if (serviceId === null) {
|
|
80
|
-
console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
|
|
81
|
-
process.exitCode = 1;
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
85
|
-
if (apiTokenResult == null) {
|
|
86
|
-
console.error("❌ Fastly API Token not provided.");
|
|
87
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
88
|
-
process.exitCode = 1;
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
92
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
93
|
-
console.log(` Working on the Fastly KV Store...`);
|
|
94
|
-
}
|
|
95
71
|
// #### load config
|
|
96
72
|
let staticPublisherRc;
|
|
97
73
|
try {
|
|
@@ -110,24 +86,33 @@ export async function action(actionArgs) {
|
|
|
110
86
|
}
|
|
111
87
|
const publishId = staticPublisherRc.publishId;
|
|
112
88
|
console.log(` | Publish ID: ${publishId}`);
|
|
113
|
-
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
114
|
-
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
115
89
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
116
90
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
117
91
|
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
118
92
|
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
93
|
+
// Storage Provider
|
|
94
|
+
let storageProvider;
|
|
95
|
+
try {
|
|
96
|
+
storageProvider = await loadStorageProviderFromStaticPublishRc(staticPublisherRc, {
|
|
97
|
+
computeAppDir,
|
|
98
|
+
localMode,
|
|
99
|
+
fastlyApiToken,
|
|
100
|
+
awsProfile,
|
|
101
|
+
awsAccessKeyId,
|
|
102
|
+
awsSecretAccessKey,
|
|
103
|
+
});
|
|
125
104
|
}
|
|
126
|
-
|
|
127
|
-
|
|
105
|
+
catch (err) {
|
|
106
|
+
console.error(`❌ Could not instantiate store provider`);
|
|
107
|
+
console.error(String(err));
|
|
108
|
+
process.exitCode = 1;
|
|
109
|
+
return;
|
|
128
110
|
}
|
|
111
|
+
// ### List all indexes ###
|
|
112
|
+
const indexesPrefix = publishId + '_index_';
|
|
113
|
+
const indexKeys = await storageProvider.getStorageKeys(indexesPrefix);
|
|
129
114
|
if (indexKeys == null) {
|
|
130
|
-
throw new Error(`❌ Can't query indexes in
|
|
115
|
+
throw new Error(`❌ Can't query indexes in storage`);
|
|
131
116
|
}
|
|
132
117
|
// ### Found collections ###
|
|
133
118
|
const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
|
|
@@ -144,24 +129,11 @@ export async function action(actionArgs) {
|
|
|
144
129
|
console.log(` ${collection}`);
|
|
145
130
|
}
|
|
146
131
|
const indexKey = indexesPrefix + collection;
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
kvAssetsIndexResponse = await getKvStoreEntry(fastlyApiContext, kvStoreName, indexKey);
|
|
153
|
-
}
|
|
154
|
-
if (kvAssetsIndexResponse == null) {
|
|
155
|
-
throw new Error(`❌ Can't load KV Store entry ${indexesPrefix + collection}`);
|
|
156
|
-
}
|
|
157
|
-
let indexMetadata;
|
|
158
|
-
if (kvAssetsIndexResponse.metadata != null) {
|
|
159
|
-
try {
|
|
160
|
-
indexMetadata = JSON.parse(kvAssetsIndexResponse.metadata);
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
}
|
|
132
|
+
const indexEntryInfo = await storageProvider.getStorageEntry(indexKey);
|
|
133
|
+
if (indexEntryInfo == null) {
|
|
134
|
+
throw new Error(`❌ Can't load storage entry ${indexesPrefix + collection}`);
|
|
164
135
|
}
|
|
136
|
+
let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata);
|
|
165
137
|
if (indexMetadata == null) {
|
|
166
138
|
console.log(` No metadata found.`);
|
|
167
139
|
continue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AA0EA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0LhD"}
|
|
@@ -3,15 +3,12 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
|
|
6
8
|
import { calcExpirationTime } from '../../../../models/time/index.js';
|
|
7
9
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
8
|
-
import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../util/kv-store.js';
|
|
9
|
-
import { loadApiToken } from '../../../util/api-token.js';
|
|
10
10
|
import { parseCommandLine } from '../../../util/args.js';
|
|
11
|
-
import
|
|
12
|
-
import { readServiceId } from "../../../util/fastly-toml.js";
|
|
13
|
-
import { isNodeError } from "../../../util/node.js";
|
|
14
|
-
import { getLocalKvStoreEntry, localKvStoreSubmitEntry } from "../../../util/kv-store-local-server.js";
|
|
11
|
+
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
15
12
|
function help() {
|
|
16
13
|
console.log(`\
|
|
17
14
|
|
|
@@ -42,7 +39,7 @@ Expiration:
|
|
|
42
39
|
existing expiration rule of the collection being
|
|
43
40
|
promoted is used.
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
KV Store Options:
|
|
46
43
|
--local Instead of working with the Fastly KV Store, operate on
|
|
47
44
|
local files that will be used to simulate the KV Store
|
|
48
45
|
with the local development environment.
|
|
@@ -52,6 +49,20 @@ Global Options:
|
|
|
52
49
|
1. FASTLY_API_TOKEN environment variable
|
|
53
50
|
2. Logged-in Fastly CLI profile
|
|
54
51
|
|
|
52
|
+
S3 Storage Options:
|
|
53
|
+
--aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
|
|
54
|
+
--aws-secret-access-key=<key> interface with S3.
|
|
55
|
+
If not set, the tool will check:
|
|
56
|
+
1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
|
|
57
|
+
environment variables
|
|
58
|
+
2. The aws credentials file, see below
|
|
59
|
+
|
|
60
|
+
--aws-profile=<profile> Profile within the aws credentials file.
|
|
61
|
+
If not set, the tool will check:
|
|
62
|
+
1. AWS_PROFILE environment variable
|
|
63
|
+
2. The default profile, if set
|
|
64
|
+
|
|
65
|
+
Global Options:
|
|
55
66
|
-h, --help Show this help message and exit.
|
|
56
67
|
`);
|
|
57
68
|
}
|
|
@@ -65,6 +76,9 @@ export async function action(actionArgs) {
|
|
|
65
76
|
{ name: 'expires-never', type: Boolean },
|
|
66
77
|
{ name: 'local', type: Boolean },
|
|
67
78
|
{ name: 'fastly-api-token', type: String, },
|
|
79
|
+
{ name: 'aws-profile', type: String, },
|
|
80
|
+
{ name: 'aws-access-key-id', type: String, },
|
|
81
|
+
{ name: 'aws-secret-access-key', type: String, },
|
|
68
82
|
];
|
|
69
83
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
70
84
|
if (parsed.needHelp) {
|
|
@@ -76,7 +90,7 @@ export async function action(actionArgs) {
|
|
|
76
90
|
help();
|
|
77
91
|
return;
|
|
78
92
|
}
|
|
79
|
-
const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
93
|
+
const { verbose, ['collection-name']: collectionNameValue, to: toCollectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['aws-profile']: awsProfile, ['aws-access-key-id']: awsAccessKeyId, ['aws-secret-access-key']: awsSecretAccessKey, } = parsed.commandLineOptions;
|
|
80
94
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
81
95
|
// in other words, the directory that contains `fastly.toml`.
|
|
82
96
|
const computeAppDir = path.resolve();
|
|
@@ -100,45 +114,7 @@ export async function action(actionArgs) {
|
|
|
100
114
|
process.exitCode = 1;
|
|
101
115
|
return;
|
|
102
116
|
}
|
|
103
|
-
// Check to see if we have a service ID listed in `fastly.toml`.
|
|
104
|
-
// If we do NOT, then we do not use the KV Store.
|
|
105
|
-
let serviceId;
|
|
106
|
-
try {
|
|
107
|
-
serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
if (isNodeError(err) && err.code === 'ENOENT') {
|
|
111
|
-
console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
|
|
112
|
-
process.exitCode = 1;
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
|
|
116
|
-
process.exitCode = 1;
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
117
|
console.log(`📃 Promoting collection...`);
|
|
120
|
-
// Verify targets
|
|
121
|
-
let fastlyApiContext = undefined;
|
|
122
|
-
if (localMode) {
|
|
123
|
-
console.log(` Working on local simulated KV Store...`);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
if (serviceId === null) {
|
|
127
|
-
console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
|
|
128
|
-
process.exitCode = 1;
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
132
|
-
if (apiTokenResult == null) {
|
|
133
|
-
console.error("❌ Fastly API Token not provided.");
|
|
134
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
135
|
-
process.exitCode = 1;
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
139
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
140
|
-
console.log(` Working on the Fastly KV Store...`);
|
|
141
|
-
}
|
|
142
118
|
// #### load config
|
|
143
119
|
let staticPublisherRc;
|
|
144
120
|
try {
|
|
@@ -157,13 +133,28 @@ export async function action(actionArgs) {
|
|
|
157
133
|
}
|
|
158
134
|
const publishId = staticPublisherRc.publishId;
|
|
159
135
|
console.log(` | Publish ID: ${publishId}`);
|
|
160
|
-
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
161
|
-
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
162
136
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
163
137
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
164
138
|
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
165
139
|
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
166
|
-
|
|
140
|
+
// Storage Provider
|
|
141
|
+
let storageProvider;
|
|
142
|
+
try {
|
|
143
|
+
storageProvider = await loadStorageProviderFromStaticPublishRc(staticPublisherRc, {
|
|
144
|
+
computeAppDir,
|
|
145
|
+
localMode,
|
|
146
|
+
fastlyApiToken,
|
|
147
|
+
awsProfile,
|
|
148
|
+
awsAccessKeyId,
|
|
149
|
+
awsSecretAccessKey,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
console.error(`❌ Could not instantiate store provider`);
|
|
154
|
+
console.error(String(err));
|
|
155
|
+
process.exitCode = 1;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
167
158
|
const sourceCollectionName = collectionNameValue;
|
|
168
159
|
console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
|
|
169
160
|
const targetCollectionName = toCollectionNameValue;
|
|
@@ -184,33 +175,17 @@ export async function action(actionArgs) {
|
|
|
184
175
|
const targetCollectionIndexKey = `${publishId}_index_${targetCollectionName}`;
|
|
185
176
|
const sourceCollectionSettingsKey = `${publishId}_settings_${collectionNameValue}`;
|
|
186
177
|
const targetCollectionSettingsKey = `${publishId}_settings_${targetCollectionName}`;
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
getLocalKvStoreEntry(storeFile, sourceCollectionSettingsKey),
|
|
192
|
-
]);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
[indexEntryInfo, settingsEntryInfo] = await Promise.all([
|
|
196
|
-
getKvStoreEntry(fastlyApiContext, kvStoreName, sourceCollectionIndexKey),
|
|
197
|
-
getKvStoreEntry(fastlyApiContext, kvStoreName, sourceCollectionSettingsKey),
|
|
198
|
-
]);
|
|
199
|
-
}
|
|
178
|
+
const [indexEntryInfo, settingsEntryInfo] = await Promise.all([
|
|
179
|
+
storageProvider.getStorageEntry(sourceCollectionIndexKey),
|
|
180
|
+
storageProvider.getStorageEntry(sourceCollectionSettingsKey),
|
|
181
|
+
]);
|
|
200
182
|
if (!indexEntryInfo) {
|
|
201
|
-
throw new Error(`Error querying index for '${collectionNameValue}' in
|
|
183
|
+
throw new Error(`Error querying index for '${collectionNameValue}' in storage`);
|
|
202
184
|
}
|
|
203
185
|
if (!settingsEntryInfo) {
|
|
204
|
-
throw new Error(`Error querying settings for '${collectionNameValue}' in
|
|
205
|
-
}
|
|
206
|
-
let indexMetadata = {};
|
|
207
|
-
if (indexEntryInfo.metadata != null) {
|
|
208
|
-
try {
|
|
209
|
-
indexMetadata = JSON.parse(indexEntryInfo.metadata);
|
|
210
|
-
}
|
|
211
|
-
catch {
|
|
212
|
-
}
|
|
186
|
+
throw new Error(`Error querying settings for '${collectionNameValue}' in storage`);
|
|
213
187
|
}
|
|
188
|
+
let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata) ?? {};
|
|
214
189
|
if (indexMetadata.publishedTime == null) {
|
|
215
190
|
indexMetadata.publishedTime = Math.floor(Date.now() / 1000);
|
|
216
191
|
}
|
|
@@ -222,26 +197,14 @@ export async function action(actionArgs) {
|
|
|
222
197
|
indexMetadata.expirationTime = expirationTime;
|
|
223
198
|
}
|
|
224
199
|
}
|
|
225
|
-
console.log(`Uploading to
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const settingsFileName = `settings_${collectionNameValue}.json`;
|
|
235
|
-
const settingsFilePath = path.resolve(staticPublisherKvStoreContent, settingsFileName);
|
|
236
|
-
const settingsBody = await settingsEntryInfo.response.arrayBuffer();
|
|
237
|
-
fs.writeFileSync(settingsFilePath, Buffer.from(settingsBody));
|
|
238
|
-
await localKvStoreSubmitEntry(storeFile, targetCollectionSettingsKey, path.relative(computeAppDir, settingsFilePath), undefined);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
await Promise.all([
|
|
242
|
-
kvStoreSubmitEntry(fastlyApiContext, kvStoreName, targetCollectionIndexKey, indexEntryInfo.response.body, JSON.stringify(indexMetadata)),
|
|
243
|
-
kvStoreSubmitEntry(fastlyApiContext, kvStoreName, targetCollectionSettingsKey, settingsEntryInfo.response.body, undefined),
|
|
244
|
-
]);
|
|
245
|
-
}
|
|
200
|
+
console.log(`Uploading to storage: '${targetCollectionName}'`);
|
|
201
|
+
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
202
|
+
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
203
|
+
const indexFileName = `index_${collectionNameValue}.json`;
|
|
204
|
+
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
205
|
+
await storageProvider.submitStorageEntry(targetCollectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
|
|
206
|
+
const settingsFileName = `settings_${collectionNameValue}.json`;
|
|
207
|
+
const settingsFilePath = path.resolve(storageContentDir, settingsFileName);
|
|
208
|
+
await storageProvider.submitStorageEntry(targetCollectionSettingsKey, settingsFilePath, settingsEntryInfo.data);
|
|
246
209
|
console.log("✅ Completed.");
|
|
247
210
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AAsEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA6JhD"}
|
|
@@ -4,14 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import { decodeIndexMetadata, encodeIndexMetadata } from '../../../../models/server/index.js';
|
|
7
8
|
import { calcExpirationTime } from '../../../../models/time/index.js';
|
|
8
|
-
import { loadApiToken } from '../../../util/api-token.js';
|
|
9
9
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
10
10
|
import { parseCommandLine } from '../../../util/args.js';
|
|
11
|
-
import {
|
|
12
|
-
import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../util/kv-store.js';
|
|
13
|
-
import { getLocalKvStoreEntry, localKvStoreSubmitEntry, } from '../../../util/kv-store-local-server.js';
|
|
14
|
-
import { isNodeError } from '../../../util/node.js';
|
|
11
|
+
import { loadStorageProviderFromStaticPublishRc } from '../../../storage/storage-provider.js';
|
|
15
12
|
function help() {
|
|
16
13
|
console.log(`\
|
|
17
14
|
|
|
@@ -38,7 +35,7 @@ Expiration:
|
|
|
38
35
|
⚠ These three options are mutually exclusive.
|
|
39
36
|
Specify exactly one.
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
KV Store Options:
|
|
42
39
|
--local Instead of working with the Fastly KV Store, operate on
|
|
43
40
|
local files that will be used to simulate the KV Store
|
|
44
41
|
with the local development environment.
|
|
@@ -48,6 +45,20 @@ Global Options:
|
|
|
48
45
|
1. FASTLY_API_TOKEN environment variable
|
|
49
46
|
2. Logged-in Fastly CLI profile
|
|
50
47
|
|
|
48
|
+
S3 Storage Options:
|
|
49
|
+
--aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
|
|
50
|
+
--aws-secret-access-key=<key> interface with S3.
|
|
51
|
+
If not set, the tool will check:
|
|
52
|
+
1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
|
|
53
|
+
environment variables
|
|
54
|
+
2. The aws credentials file, see below
|
|
55
|
+
|
|
56
|
+
--aws-profile=<profile> Profile within the aws credentials file.
|
|
57
|
+
If not set, the tool will check:
|
|
58
|
+
1. AWS_PROFILE environment variable
|
|
59
|
+
2. The default profile, if set
|
|
60
|
+
|
|
61
|
+
Global Options:
|
|
51
62
|
-h, --help Show this help message and exit.
|
|
52
63
|
`);
|
|
53
64
|
}
|
|
@@ -60,6 +71,9 @@ export async function action(actionArgs) {
|
|
|
60
71
|
{ name: 'expires-never', type: Boolean },
|
|
61
72
|
{ name: 'local', type: Boolean },
|
|
62
73
|
{ name: 'fastly-api-token', type: String, },
|
|
74
|
+
{ name: 'aws-profile', type: String, },
|
|
75
|
+
{ name: 'aws-access-key-id', type: String, },
|
|
76
|
+
{ name: 'aws-secret-access-key', type: String, },
|
|
63
77
|
];
|
|
64
78
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
65
79
|
if (parsed.needHelp) {
|
|
@@ -71,7 +85,7 @@ export async function action(actionArgs) {
|
|
|
71
85
|
help();
|
|
72
86
|
return;
|
|
73
87
|
}
|
|
74
|
-
const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
88
|
+
const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, ['aws-profile']: awsProfile, ['aws-access-key-id']: awsAccessKeyId, ['aws-secret-access-key']: awsSecretAccessKey, } = parsed.commandLineOptions;
|
|
75
89
|
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
76
90
|
// in other words, the directory that contains `fastly.toml`.
|
|
77
91
|
const computeAppDir = path.resolve();
|
|
@@ -95,45 +109,7 @@ export async function action(actionArgs) {
|
|
|
95
109
|
process.exitCode = 1;
|
|
96
110
|
return;
|
|
97
111
|
}
|
|
98
|
-
// Check to see if we have a service ID listed in `fastly.toml`.
|
|
99
|
-
// If we do NOT, then we do not use the KV Store.
|
|
100
|
-
let serviceId;
|
|
101
|
-
try {
|
|
102
|
-
serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
if (isNodeError(err) && err.code === 'ENOENT') {
|
|
106
|
-
console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
|
|
107
|
-
process.exitCode = 1;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
|
|
111
|
-
process.exitCode = 1;
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
112
|
console.log(`📃 Promoting collection...`);
|
|
115
|
-
// Verify targets
|
|
116
|
-
let fastlyApiContext = undefined;
|
|
117
|
-
if (localMode) {
|
|
118
|
-
console.log(` Working on local simulated KV Store...`);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
if (serviceId === null) {
|
|
122
|
-
console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
|
|
123
|
-
process.exitCode = 1;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
127
|
-
if (apiTokenResult == null) {
|
|
128
|
-
console.error("❌ Fastly API Token not provided.");
|
|
129
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
130
|
-
process.exitCode = 1;
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
134
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
135
|
-
console.log(` Working on the Fastly KV Store...`);
|
|
136
|
-
}
|
|
137
113
|
// #### load config
|
|
138
114
|
let staticPublisherRc;
|
|
139
115
|
try {
|
|
@@ -152,13 +128,28 @@ export async function action(actionArgs) {
|
|
|
152
128
|
}
|
|
153
129
|
const publishId = staticPublisherRc.publishId;
|
|
154
130
|
console.log(` | Publish ID: ${publishId}`);
|
|
155
|
-
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
156
|
-
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
157
131
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
158
132
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
159
133
|
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
160
134
|
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
161
|
-
|
|
135
|
+
// Storage Provider
|
|
136
|
+
let storageProvider;
|
|
137
|
+
try {
|
|
138
|
+
storageProvider = await loadStorageProviderFromStaticPublishRc(staticPublisherRc, {
|
|
139
|
+
computeAppDir,
|
|
140
|
+
localMode,
|
|
141
|
+
fastlyApiToken,
|
|
142
|
+
awsProfile,
|
|
143
|
+
awsAccessKeyId,
|
|
144
|
+
awsSecretAccessKey,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
console.error(`❌ Could not instantiate store provider`);
|
|
149
|
+
console.error(String(err));
|
|
150
|
+
process.exitCode = 1;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
162
153
|
const collectionName = collectionNameValue;
|
|
163
154
|
console.log(`✔️ Collection to update: ${collectionName}`);
|
|
164
155
|
if (expirationTime !== null) {
|
|
@@ -171,24 +162,11 @@ export async function action(actionArgs) {
|
|
|
171
162
|
console.log(` ⚠️ NOTE: Expiration time not enforced for default collection.`);
|
|
172
163
|
}
|
|
173
164
|
const collectionIndexKey = `${publishId}_index_${collectionName}`;
|
|
174
|
-
|
|
175
|
-
if (localMode) {
|
|
176
|
-
indexEntryInfo = await getLocalKvStoreEntry(storeFile, collectionIndexKey);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
indexEntryInfo = await getKvStoreEntry(fastlyApiContext, kvStoreName, collectionIndexKey);
|
|
180
|
-
}
|
|
165
|
+
const indexEntryInfo = await storageProvider.getStorageEntry(collectionIndexKey);
|
|
181
166
|
if (!indexEntryInfo) {
|
|
182
|
-
throw new Error(`Error querying index for '${collectionNameValue}' in
|
|
183
|
-
}
|
|
184
|
-
let indexMetadata = {};
|
|
185
|
-
if (indexEntryInfo.metadata != null) {
|
|
186
|
-
try {
|
|
187
|
-
indexMetadata = JSON.parse(indexEntryInfo.metadata);
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
}
|
|
167
|
+
throw new Error(`Error querying index for '${collectionNameValue}' in storage`);
|
|
191
168
|
}
|
|
169
|
+
let indexMetadata = decodeIndexMetadata(indexEntryInfo.metadata) ?? {};
|
|
192
170
|
if (indexMetadata.publishedTime == null) {
|
|
193
171
|
indexMetadata.publishedTime = Math.floor(Date.now() / 1000);
|
|
194
172
|
}
|
|
@@ -198,18 +176,11 @@ export async function action(actionArgs) {
|
|
|
198
176
|
else {
|
|
199
177
|
indexMetadata.expirationTime = expirationTime;
|
|
200
178
|
}
|
|
201
|
-
console.log(`Uploading to
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const indexBody = await indexEntryInfo.response.arrayBuffer();
|
|
208
|
-
fs.writeFileSync(indexFilePath, Buffer.from(indexBody));
|
|
209
|
-
await localKvStoreSubmitEntry(storeFile, collectionIndexKey, path.relative(computeAppDir, indexFilePath), JSON.stringify(indexMetadata));
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
await kvStoreSubmitEntry(fastlyApiContext, kvStoreName, collectionIndexKey, indexEntryInfo.response.body, JSON.stringify(indexMetadata));
|
|
213
|
-
}
|
|
179
|
+
console.log(`Uploading to storage: '${collectionName}'`);
|
|
180
|
+
const storageContentDir = `${staticPublisherWorkingDir}/storage-content`;
|
|
181
|
+
fs.mkdirSync(storageContentDir, { recursive: true });
|
|
182
|
+
const indexFileName = `index_${collectionNameValue}.json`;
|
|
183
|
+
const indexFilePath = path.resolve(storageContentDir, indexFileName);
|
|
184
|
+
await storageProvider.submitStorageEntry(collectionIndexKey, indexFilePath, indexEntryInfo.data, encodeIndexMetadata(indexMetadata));
|
|
214
185
|
console.log("✅ Completed.");
|
|
215
186
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AAkEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
|
|
@@ -25,7 +25,7 @@ Available Commands:
|
|
|
25
25
|
collections promote Copy a collection to another name
|
|
26
26
|
collections update-expiration Modify expiration time for an existing collection
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
KV Store Options:
|
|
29
29
|
--local Instead of working with the Fastly KV Store, operate on
|
|
30
30
|
local files that will be used to simulate the KV Store
|
|
31
31
|
with the local development environment.
|
|
@@ -35,6 +35,20 @@ Global Options:
|
|
|
35
35
|
1. FASTLY_API_TOKEN environment variable
|
|
36
36
|
2. Logged-in Fastly CLI profile
|
|
37
37
|
|
|
38
|
+
S3 Storage Options:
|
|
39
|
+
--aws-access-key-id=<key> AWS Access Key ID and Secret Access Key used to
|
|
40
|
+
--aws-secret-access-key=<key> interface with S3.
|
|
41
|
+
If not set, the tool will check:
|
|
42
|
+
1. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
|
|
43
|
+
environment variables
|
|
44
|
+
2. The aws credentials file, see below
|
|
45
|
+
|
|
46
|
+
--aws-profile=<profile> Profile within the aws credentials file.
|
|
47
|
+
If not set, the tool will check:
|
|
48
|
+
1. AWS_PROFILE environment variable
|
|
49
|
+
2. The default profile, if set
|
|
50
|
+
|
|
51
|
+
Global Options:
|
|
38
52
|
-h, --help Show this help message and exit.
|
|
39
53
|
|
|
40
54
|
Automatic Project Initialization:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AA2GA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAqdhD"}
|