@fastly/compute-js-static-publish 7.0.0-beta.2 → 7.0.0-beta.4
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 +11 -3
- package/README.short.md +11 -3
- package/build/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/commands/manage/clean.js +96 -20
- package/build/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/commands/manage/collections/delete.js +84 -23
- package/build/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/commands/manage/collections/index.js +14 -8
- package/build/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/commands/manage/collections/list.js +77 -19
- package/build/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/commands/manage/collections/promote.js +139 -45
- package/build/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/commands/manage/collections/update-expiration.js +120 -34
- package/build/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/commands/manage/index.js +10 -5
- package/build/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/commands/manage/publish-content.js +96 -81
- package/build/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/commands/scaffold/index.js +11 -10
- package/build/cli/util/api-token.d.ts.map +1 -0
- package/build/cli/{fastly-api → util}/api-token.js +1 -1
- package/build/cli/util/config.d.ts.map +1 -1
- package/build/cli/util/config.js +19 -19
- package/build/cli/util/kv-store-items.js +1 -1
- package/build/cli/util/kv-store-local-server.d.ts +8 -0
- package/build/cli/util/kv-store-local-server.d.ts.map +1 -1
- package/build/cli/util/kv-store-local-server.js +76 -0
- package/build/cli/{fastly-api → util}/kv-store.d.ts +4 -4
- package/build/cli/util/kv-store.d.ts.map +1 -0
- package/build/cli/{fastly-api → util}/kv-store.js +2 -2
- package/build/models/config/publish-content-config.d.ts +0 -2
- package/build/models/config/publish-content-config.d.ts.map +1 -1
- package/build/models/config/static-publish-rc.d.ts +1 -0
- package/build/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/models/time/index.d.ts +2 -1
- package/build/models/time/index.d.ts.map +1 -1
- package/build/models/time/index.js +6 -3
- package/package.json +1 -1
- package/build/cli/fastly-api/api-token.d.ts.map +0 -1
- package/build/cli/fastly-api/kv-store.d.ts.map +0 -1
- /package/build/cli/{fastly-api → util}/api-token.d.ts +0 -0
package/README.md
CHANGED
|
@@ -25,7 +25,8 @@ npx @fastly/compute-js-static-publish --root-dir=./public --kv-store-name=site-c
|
|
|
25
25
|
```sh
|
|
26
26
|
cd compute-js
|
|
27
27
|
npm install
|
|
28
|
-
npm run
|
|
28
|
+
npm run dev:publish # 'publish' your files to the simulated local KV Store
|
|
29
|
+
npm run dev:start # preview locally
|
|
29
30
|
```
|
|
30
31
|
|
|
31
32
|
Serves your app at `http://127.0.0.1:7676`, powered by a simulated KV Store.
|
|
@@ -36,8 +37,15 @@ When you're ready to go live, [create a free Fastly account](https://www.fastly.
|
|
|
36
37
|
|
|
37
38
|
```sh
|
|
38
39
|
cd compute-js
|
|
39
|
-
npm run
|
|
40
|
-
npm run publish
|
|
40
|
+
npm run fastly:deploy # deploy the app
|
|
41
|
+
npm run fastly:publish # upload your static files
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
In the future, unless you have further changes to make to your app itself, you can
|
|
45
|
+
upload further updates to your static files:
|
|
46
|
+
```sh
|
|
47
|
+
cd compute-js
|
|
48
|
+
npm run fastly:publish # upload your static files
|
|
41
49
|
```
|
|
42
50
|
|
|
43
51
|
## Features
|
package/README.short.md
CHANGED
|
@@ -25,7 +25,8 @@ npx @fastly/compute-js-static-publish --root-dir=./public --kv-store-name=site-c
|
|
|
25
25
|
```sh
|
|
26
26
|
cd compute-js
|
|
27
27
|
npm install
|
|
28
|
-
npm run
|
|
28
|
+
npm run dev:publish # 'publish' your files to the simulated local KV Store
|
|
29
|
+
npm run dev:start # preview locally
|
|
29
30
|
```
|
|
30
31
|
|
|
31
32
|
Serves your app at `http://127.0.0.1:7676`, powered by a simulated KV Store.
|
|
@@ -36,8 +37,15 @@ When you're ready to go live, [create a free Fastly account](https://www.fastly.
|
|
|
36
37
|
|
|
37
38
|
```sh
|
|
38
39
|
cd compute-js
|
|
39
|
-
npm run
|
|
40
|
-
npm run publish
|
|
40
|
+
npm run fastly:deploy # deploy the app
|
|
41
|
+
npm run fastly:publish # upload your static files
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
In the future, unless you have further changes to make to your app itself, you can
|
|
45
|
+
upload further updates to your static files:
|
|
46
|
+
```sh
|
|
47
|
+
cd compute-js
|
|
48
|
+
npm run fastly:publish # upload your static files
|
|
41
49
|
```
|
|
42
50
|
|
|
43
51
|
## Features
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/manage/clean.ts"],"names":[],"mappings":"AAsDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA6ShD"}
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
import path from 'node:path';
|
|
5
6
|
import { isExpired } from '../../../models/time/index.js';
|
|
6
7
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
|
|
7
|
-
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry } from '../../
|
|
8
|
-
import { loadApiToken } from '../../
|
|
8
|
+
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry } from '../../util/kv-store.js';
|
|
9
|
+
import { loadApiToken } from '../../util/api-token.js';
|
|
9
10
|
import { parseCommandLine } from '../../util/args.js';
|
|
11
|
+
import { readServiceId } from '../../util/fastly-toml.js';
|
|
10
12
|
import { doKvStoreItemsOperation } from "../../util/kv-store-items.js";
|
|
13
|
+
import { isNodeError } from '../../util/node.js';
|
|
14
|
+
import { getLocalKvStoreEntry, getLocalKVStoreKeys, localKvStoreDeleteEntry } from "../../util/kv-store-local-server.js";
|
|
11
15
|
function help() {
|
|
12
16
|
console.log(`\
|
|
13
17
|
|
|
@@ -16,17 +20,24 @@ Usage:
|
|
|
16
20
|
|
|
17
21
|
Description:
|
|
18
22
|
Cleans up expired or unreferenced items in the Fastly KV Store.
|
|
19
|
-
This
|
|
23
|
+
This can include expired collection indexes and orphaned content assets.
|
|
20
24
|
|
|
21
25
|
Options:
|
|
22
26
|
--delete-expired-collections If set, expired collection index files will be deleted.
|
|
27
|
+
|
|
23
28
|
--dry-run Show what would be deleted without performing any deletions.
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
Global Options:
|
|
31
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
32
|
+
local files that will be used to simulate the KV Store
|
|
33
|
+
with the local development environment.
|
|
34
|
+
|
|
35
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
36
|
+
If not set, the tool will check:
|
|
27
37
|
1. FASTLY_API_TOKEN environment variable
|
|
28
|
-
2.
|
|
29
|
-
|
|
38
|
+
2. Logged-in Fastly CLI profile
|
|
39
|
+
|
|
40
|
+
-h, --help Show this help message and exit.
|
|
30
41
|
`);
|
|
31
42
|
}
|
|
32
43
|
export async function action(actionArgs) {
|
|
@@ -34,6 +45,7 @@ export async function action(actionArgs) {
|
|
|
34
45
|
{ name: 'verbose', type: Boolean },
|
|
35
46
|
{ name: 'delete-expired-collections', type: Boolean },
|
|
36
47
|
{ name: 'dry-run', type: Boolean },
|
|
48
|
+
{ name: 'local', type: Boolean },
|
|
37
49
|
{ name: 'fastly-api-token', type: String, },
|
|
38
50
|
];
|
|
39
51
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
@@ -46,16 +58,49 @@ export async function action(actionArgs) {
|
|
|
46
58
|
help();
|
|
47
59
|
return;
|
|
48
60
|
}
|
|
49
|
-
const { verbose, ['delete-expired-collections']: deleteExpiredCollections, ['dry-run']: dryRun, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
const { verbose, ['delete-expired-collections']: deleteExpiredCollections, ['dry-run']: dryRun, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
62
|
+
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
63
|
+
// in other words, the directory that contains `fastly.toml`.
|
|
64
|
+
const computeAppDir = path.resolve();
|
|
65
|
+
// Check to see if we have a service ID listed in `fastly.toml`.
|
|
66
|
+
// If we do NOT, then we do not use the KV Store.
|
|
67
|
+
let serviceId;
|
|
68
|
+
try {
|
|
69
|
+
serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (isNodeError(err) && err.code === 'ENOENT') {
|
|
73
|
+
console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
|
|
74
|
+
process.exitCode = 1;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
|
|
54
78
|
process.exitCode = 1;
|
|
55
79
|
return;
|
|
56
80
|
}
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
console.log(`🧹 Cleaning KV Store entries...`);
|
|
82
|
+
// Verify targets
|
|
83
|
+
let fastlyApiContext = undefined;
|
|
84
|
+
if (localMode) {
|
|
85
|
+
console.log(` Working on local simulated KV Store...`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (serviceId === null) {
|
|
89
|
+
console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
94
|
+
if (apiTokenResult == null) {
|
|
95
|
+
console.error("❌ Fastly API Token not provided.");
|
|
96
|
+
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
97
|
+
process.exitCode = 1;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
101
|
+
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
102
|
+
console.log(` Working on the Fastly KV Store...`);
|
|
103
|
+
}
|
|
59
104
|
// #### load config
|
|
60
105
|
let staticPublisherRc;
|
|
61
106
|
try {
|
|
@@ -78,11 +123,20 @@ export async function action(actionArgs) {
|
|
|
78
123
|
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
79
124
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
80
125
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
126
|
+
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
127
|
+
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
128
|
+
const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
|
|
81
129
|
// ### KVStore Keys to delete
|
|
82
130
|
const kvKeysToDelete = new Set();
|
|
83
131
|
// ### List all indexes ###
|
|
84
132
|
const indexesPrefix = publishId + '_index_';
|
|
85
|
-
|
|
133
|
+
let indexKeys;
|
|
134
|
+
if (localMode) {
|
|
135
|
+
indexKeys = await getLocalKVStoreKeys(storeFile, indexesPrefix);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
|
|
139
|
+
}
|
|
86
140
|
if (indexKeys == null) {
|
|
87
141
|
throw new Error(`Can't query indexes in KV Store`);
|
|
88
142
|
}
|
|
@@ -98,8 +152,13 @@ export async function action(actionArgs) {
|
|
|
98
152
|
collection,
|
|
99
153
|
})), async ({ collection }, indexKey) => {
|
|
100
154
|
console.log(`Collection: ${collection}`);
|
|
101
|
-
|
|
102
|
-
|
|
155
|
+
let kvAssetsIndexResponse;
|
|
156
|
+
if (localMode) {
|
|
157
|
+
kvAssetsIndexResponse = await getLocalKvStoreEntry(storeFile, indexKey);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
kvAssetsIndexResponse = await getKvStoreEntry(fastlyApiContext, kvStoreName, indexKey);
|
|
161
|
+
}
|
|
103
162
|
if (!kvAssetsIndexResponse) {
|
|
104
163
|
throw new Error(`Can't load KV Store entry ${indexesPrefix + collection}`);
|
|
105
164
|
}
|
|
@@ -146,7 +205,13 @@ export async function action(actionArgs) {
|
|
|
146
205
|
// ### List all settings ###
|
|
147
206
|
console.log('Enumerating settings:');
|
|
148
207
|
const settingsPrefix = publishId + '_settings_';
|
|
149
|
-
|
|
208
|
+
let settingsKeys;
|
|
209
|
+
if (localMode) {
|
|
210
|
+
settingsKeys = await getLocalKVStoreKeys(storeFile, settingsPrefix);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
settingsKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, settingsPrefix);
|
|
214
|
+
}
|
|
150
215
|
if (settingsKeys == null) {
|
|
151
216
|
throw new Error(`Can't query settings in KV Store`);
|
|
152
217
|
}
|
|
@@ -164,7 +229,13 @@ export async function action(actionArgs) {
|
|
|
164
229
|
// ### Obtain the assets in the KV Store and find the ones that are not in use
|
|
165
230
|
console.log('Enumerating assets:');
|
|
166
231
|
const assetPrefix = publishId + '_files_';
|
|
167
|
-
|
|
232
|
+
let assetKeys;
|
|
233
|
+
if (localMode) {
|
|
234
|
+
assetKeys = await getLocalKVStoreKeys(storeFile, assetPrefix);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
assetKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, assetPrefix);
|
|
238
|
+
}
|
|
168
239
|
if (assetKeys == null) {
|
|
169
240
|
throw new Error(`Can't query assets in KV Store`);
|
|
170
241
|
}
|
|
@@ -194,7 +265,12 @@ export async function action(actionArgs) {
|
|
|
194
265
|
}
|
|
195
266
|
else {
|
|
196
267
|
console.log(`Deleting item from KV Store: ${key}`);
|
|
197
|
-
|
|
268
|
+
if (localMode) {
|
|
269
|
+
await localKvStoreDeleteEntry(storeFile, key);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
await kvStoreDeleteEntry(fastlyApiContext, kvStoreName, key);
|
|
273
|
+
}
|
|
198
274
|
}
|
|
199
275
|
});
|
|
200
276
|
console.log('✅ Completed.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/delete.ts"],"names":[],"mappings":"AAgDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA2KhD"}
|
|
@@ -2,36 +2,49 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { loadApiToken } from '../../../fastly-api/api-token.js';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { loadApiToken } from '../../../util/api-token.js';
|
|
8
7
|
import { parseCommandLine } from "../../../util/args.js";
|
|
9
|
-
import {
|
|
8
|
+
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
9
|
+
import { readServiceId } from '../../../util/fastly-toml.js';
|
|
10
|
+
import { getKVStoreKeys, kvStoreDeleteEntry } from '../../../util/kv-store.js';
|
|
11
|
+
import { doKvStoreItemsOperation } from '../../../util/kv-store-items.js';
|
|
12
|
+
import { getLocalKVStoreKeys, localKvStoreDeleteEntry } from '../../../util/kv-store-local-server.js';
|
|
13
|
+
import { isNodeError } from '../../../util/node.js';
|
|
10
14
|
function help() {
|
|
11
15
|
console.log(`\
|
|
12
16
|
|
|
13
17
|
Usage:
|
|
14
|
-
npx @fastly/compute-js-static-publish collections delete
|
|
15
|
-
--collection-name <name> \\
|
|
16
|
-
[options]
|
|
18
|
+
npx @fastly/compute-js-static-publish collections delete --collection-name=<name> [options]
|
|
17
19
|
|
|
18
20
|
Description:
|
|
19
|
-
Deletes a collection index from the KV Store. The content files will remain
|
|
21
|
+
Deletes a collection index from the KV Store. The content files will remain as they may still
|
|
22
|
+
be referenced by other collection indexes.
|
|
23
|
+
|
|
24
|
+
Use the 'npx @fastly/compute-js-static-publish clean' command afterward to remove content
|
|
25
|
+
files that are no longer referenced by any collection.
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
--collection-name
|
|
27
|
+
Required:
|
|
28
|
+
--collection-name=<name> The name of the collection to delete
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
Global Options:
|
|
31
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
32
|
+
local files that will be used to simulate the KV Store
|
|
33
|
+
with the local development environment.
|
|
34
|
+
|
|
35
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
36
|
+
If not set, the tool will check:
|
|
26
37
|
1. FASTLY_API_TOKEN environment variable
|
|
27
|
-
2.
|
|
28
|
-
|
|
38
|
+
2. Logged-in Fastly CLI profile
|
|
39
|
+
|
|
40
|
+
-h, --help Show this help message and exit.
|
|
29
41
|
`);
|
|
30
42
|
}
|
|
31
43
|
export async function action(actionArgs) {
|
|
32
44
|
const optionDefinitions = [
|
|
33
45
|
{ name: 'verbose', type: Boolean },
|
|
34
46
|
{ name: 'collection-name', type: String },
|
|
47
|
+
{ name: 'local', type: Boolean },
|
|
35
48
|
{ name: 'fastly-api-token', type: String, },
|
|
36
49
|
];
|
|
37
50
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
@@ -44,21 +57,54 @@ export async function action(actionArgs) {
|
|
|
44
57
|
help();
|
|
45
58
|
return;
|
|
46
59
|
}
|
|
47
|
-
const { verbose, ['
|
|
60
|
+
const { verbose, ['collection-name']: collectionNameValue, ['fastly-api-token']: fastlyApiToken, local: localMode, } = parsed.commandLineOptions;
|
|
61
|
+
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
62
|
+
// in other words, the directory that contains `fastly.toml`.
|
|
63
|
+
const computeAppDir = path.resolve();
|
|
48
64
|
if (collectionNameValue == null) {
|
|
49
65
|
console.error("❌ Required argument '--collection-name' not specified.");
|
|
50
66
|
process.exitCode = 1;
|
|
51
67
|
return;
|
|
52
68
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
// Check to see if we have a service ID listed in `fastly.toml`.
|
|
70
|
+
// If we do NOT, then we do not use the KV Store.
|
|
71
|
+
let serviceId;
|
|
72
|
+
try {
|
|
73
|
+
serviceId = readServiceId(path.resolve(computeAppDir, './fastly.toml'));
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (isNodeError(err) && err.code === 'ENOENT') {
|
|
77
|
+
console.warn(`❌ ERROR: can't find 'fastly.toml'.`);
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
console.warn(`❌ ERROR: can't read or parse 'fastly.toml'.`);
|
|
57
82
|
process.exitCode = 1;
|
|
58
83
|
return;
|
|
59
84
|
}
|
|
60
|
-
|
|
61
|
-
|
|
85
|
+
console.log(`🧹 Cleaning KV Store entries...`);
|
|
86
|
+
// Verify targets
|
|
87
|
+
let fastlyApiContext = undefined;
|
|
88
|
+
if (localMode) {
|
|
89
|
+
console.log(` Working on local simulated KV Store...`);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (serviceId === null) {
|
|
93
|
+
console.log(`❌️ 'service_id' not set in 'fastly.toml' - Deploy your Compute app to Fastly before publishing.`);
|
|
94
|
+
process.exitCode = 1;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
98
|
+
if (apiTokenResult == null) {
|
|
99
|
+
console.error("❌ Fastly API Token not provided.");
|
|
100
|
+
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
101
|
+
process.exitCode = 1;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
105
|
+
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
106
|
+
console.log(` Working on the Fastly KV Store...`);
|
|
107
|
+
}
|
|
62
108
|
// #### load config
|
|
63
109
|
let staticPublisherRc;
|
|
64
110
|
try {
|
|
@@ -81,6 +127,9 @@ export async function action(actionArgs) {
|
|
|
81
127
|
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
82
128
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
83
129
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
130
|
+
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
131
|
+
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
132
|
+
const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
|
|
84
133
|
const collectionName = collectionNameValue;
|
|
85
134
|
if (collectionName === defaultCollectionName) {
|
|
86
135
|
console.error(`❌ Cannot delete default collection: ${collectionName}`);
|
|
@@ -88,10 +137,17 @@ export async function action(actionArgs) {
|
|
|
88
137
|
return;
|
|
89
138
|
}
|
|
90
139
|
console.log(`✔️ Collection to delete: ${collectionName}`);
|
|
140
|
+
// ### KVStore Keys to delete
|
|
91
141
|
const kvKeysToDelete = new Set();
|
|
92
142
|
// ### List all indexes ###
|
|
93
143
|
const indexesPrefix = publishId + '_index_';
|
|
94
|
-
|
|
144
|
+
let indexKeys;
|
|
145
|
+
if (localMode) {
|
|
146
|
+
indexKeys = await getLocalKVStoreKeys(storeFile, indexesPrefix);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
|
|
150
|
+
}
|
|
95
151
|
if (indexKeys == null) {
|
|
96
152
|
throw new Error(`Can't query indexes in KV Store`);
|
|
97
153
|
}
|
|
@@ -113,7 +169,12 @@ export async function action(actionArgs) {
|
|
|
113
169
|
const items = [...kvKeysToDelete].map(key => ({ key }));
|
|
114
170
|
await doKvStoreItemsOperation(items, async (_, key) => {
|
|
115
171
|
console.log(`Deleting key from KV Store: ${key}`);
|
|
116
|
-
|
|
172
|
+
if (localMode) {
|
|
173
|
+
await localKvStoreDeleteEntry(storeFile, key);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
await kvStoreDeleteEntry(fastlyApiContext, kvStoreName, key);
|
|
177
|
+
}
|
|
117
178
|
});
|
|
118
179
|
console.log("✅ Completed.");
|
|
119
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/index.ts"],"names":[],"mappings":"AA6CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA0BhD"}
|
|
@@ -17,17 +17,23 @@ Description:
|
|
|
17
17
|
Manage named collections within a Compute application built with @fastly/compute-js-static-publish.
|
|
18
18
|
|
|
19
19
|
Available Subcommands:
|
|
20
|
-
list
|
|
21
|
-
delete
|
|
22
|
-
promote
|
|
23
|
-
|
|
20
|
+
list List all published collections
|
|
21
|
+
delete Delete a specific collection index
|
|
22
|
+
promote Copies an existing collection (content + config)
|
|
23
|
+
to a new collection name
|
|
24
|
+
update-expiration Modify expiration time for an existing collection
|
|
24
25
|
|
|
25
26
|
Global Options:
|
|
26
|
-
--
|
|
27
|
-
|
|
27
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
28
|
+
local files that will be used to simulate the KV Store
|
|
29
|
+
with the local development environment.
|
|
30
|
+
|
|
31
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
32
|
+
If not set, the tool will check:
|
|
28
33
|
1. FASTLY_API_TOKEN environment variable
|
|
29
|
-
2.
|
|
30
|
-
|
|
34
|
+
2. Logged-in Fastly CLI profile
|
|
35
|
+
|
|
36
|
+
-h, --help Show this help message and exit.
|
|
31
37
|
|
|
32
38
|
Examples:
|
|
33
39
|
npx @fastly/compute-js-static-publish collections list
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/list.ts"],"names":[],"mappings":"AA0CA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAsLhD"}
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import { loadApiToken } from '../../../
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { isExpired } from '../../../../models/time/index.js';
|
|
7
|
+
import { loadApiToken } from '../../../util/api-token.js';
|
|
8
8
|
import { parseCommandLine } from '../../../util/args.js';
|
|
9
|
-
import {
|
|
9
|
+
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
10
|
+
import { readServiceId } from '../../../util/fastly-toml.js';
|
|
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
14
|
function help() {
|
|
11
15
|
console.log(`\
|
|
12
16
|
|
|
@@ -16,17 +20,23 @@ Usage:
|
|
|
16
20
|
Description:
|
|
17
21
|
Lists all collections currently published in the KV Store.
|
|
18
22
|
|
|
19
|
-
Options:
|
|
20
|
-
--
|
|
21
|
-
|
|
23
|
+
Global Options:
|
|
24
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
25
|
+
local files that will be used to simulate the KV Store
|
|
26
|
+
with the local development environment.
|
|
27
|
+
|
|
28
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
29
|
+
If not set, the tool will check:
|
|
22
30
|
1. FASTLY_API_TOKEN environment variable
|
|
23
|
-
2.
|
|
24
|
-
|
|
31
|
+
2. Logged-in Fastly CLI profile
|
|
32
|
+
|
|
33
|
+
-h, --help Show this help message and exit.
|
|
25
34
|
`);
|
|
26
35
|
}
|
|
27
36
|
export async function action(actionArgs) {
|
|
28
37
|
const optionDefinitions = [
|
|
29
38
|
{ name: 'verbose', type: Boolean },
|
|
39
|
+
{ name: 'local', type: Boolean },
|
|
30
40
|
{ name: 'fastly-api-token', type: String, },
|
|
31
41
|
];
|
|
32
42
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
@@ -39,16 +49,49 @@ export async function action(actionArgs) {
|
|
|
39
49
|
help();
|
|
40
50
|
return;
|
|
41
51
|
}
|
|
42
|
-
const { verbose, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
const { verbose, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
53
|
+
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
54
|
+
// in other words, the directory that contains `fastly.toml`.
|
|
55
|
+
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'.`);
|
|
47
69
|
process.exitCode = 1;
|
|
48
70
|
return;
|
|
49
71
|
}
|
|
50
|
-
|
|
51
|
-
|
|
72
|
+
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
|
+
}
|
|
52
95
|
// #### load config
|
|
53
96
|
let staticPublisherRc;
|
|
54
97
|
try {
|
|
@@ -71,9 +114,18 @@ export async function action(actionArgs) {
|
|
|
71
114
|
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
72
115
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
73
116
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
117
|
+
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
118
|
+
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
119
|
+
const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
|
|
74
120
|
// ### List all indexes ###
|
|
75
121
|
const indexesPrefix = publishId + '_index_';
|
|
76
|
-
|
|
122
|
+
let indexKeys;
|
|
123
|
+
if (localMode) {
|
|
124
|
+
indexKeys = await getLocalKVStoreKeys(storeFile, indexesPrefix);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
|
|
128
|
+
}
|
|
77
129
|
if (indexKeys == null) {
|
|
78
130
|
throw new Error(`❌ Can't query indexes in KV Store`);
|
|
79
131
|
}
|
|
@@ -92,8 +144,14 @@ export async function action(actionArgs) {
|
|
|
92
144
|
console.log(` ${collection}`);
|
|
93
145
|
}
|
|
94
146
|
const indexKey = indexesPrefix + collection;
|
|
95
|
-
|
|
96
|
-
if (
|
|
147
|
+
let kvAssetsIndexResponse;
|
|
148
|
+
if (localMode) {
|
|
149
|
+
kvAssetsIndexResponse = await getLocalKvStoreEntry(storeFile, indexKey);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
kvAssetsIndexResponse = await getKvStoreEntry(fastlyApiContext, kvStoreName, indexKey);
|
|
153
|
+
}
|
|
154
|
+
if (kvAssetsIndexResponse == null) {
|
|
97
155
|
throw new Error(`❌ Can't load KV Store entry ${indexesPrefix + collection}`);
|
|
98
156
|
}
|
|
99
157
|
let indexMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"promote.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/promote.ts"],"names":[],"mappings":"AAkEA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyOhD"}
|