@fastly/compute-js-static-publish 7.0.0-beta.2 → 7.0.0-beta.3
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 +95 -19
- 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 +119 -33
- 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
|
@@ -4,32 +4,55 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { calcExpirationTime } from '../../../../models/time/index.js';
|
|
6
6
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
7
|
-
import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../
|
|
8
|
-
import { loadApiToken } from '../../../
|
|
7
|
+
import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../util/kv-store.js';
|
|
8
|
+
import { loadApiToken } from '../../../util/api-token.js';
|
|
9
9
|
import { parseCommandLine } from '../../../util/args.js';
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { readServiceId } from "../../../util/fastly-toml.js";
|
|
12
|
+
import { isNodeError } from "../../../util/node.js";
|
|
13
|
+
import { getLocalKvStoreEntry, localKvStoreSubmitEntry } from "../../../util/kv-store-local-server.js";
|
|
14
|
+
import fs from "node:fs";
|
|
10
15
|
function help() {
|
|
11
16
|
console.log(`\
|
|
12
17
|
|
|
13
18
|
Usage:
|
|
14
|
-
npx @fastly/compute-js-static-publish collections promote
|
|
15
|
-
--collection-name
|
|
16
|
-
--to
|
|
19
|
+
npx @fastly/compute-js-static-publish collections promote
|
|
20
|
+
--collection-name=<name> \\
|
|
21
|
+
--to=name> \\
|
|
17
22
|
[options]
|
|
18
23
|
|
|
19
24
|
Description:
|
|
20
25
|
Copies an existing collection (content + config) to a new collection name.
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
--collection-name
|
|
24
|
-
--to
|
|
25
|
-
--expires-in <duration> Set new expiration relative to now (e.g., 7d, 1h).
|
|
26
|
-
--expires-at <timestamp> Set new expiration using an absolute ISO 8601 timestamp.
|
|
27
|
+
Required:
|
|
28
|
+
--collection-name=<name> The name of the collection to promote
|
|
29
|
+
--to=<name> The name of the new (target) collection to create or overwrite
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
Expiration:
|
|
32
|
+
--expires-in=<duration> Expiration duration from now.
|
|
33
|
+
Examples: 3d, 12h, 15m, 1w
|
|
34
|
+
|
|
35
|
+
--expires-at=<timestamp> Absolute expiration in ISO 8601 format.
|
|
36
|
+
Example: 2025-05-01T00:00:00Z
|
|
37
|
+
|
|
38
|
+
--expires-never Prevent this collection from expiring.
|
|
39
|
+
|
|
40
|
+
⚠ These three options are mutually exclusive.
|
|
41
|
+
Specify no more than one. If not provided, then the
|
|
42
|
+
existing expiration rule of the collection being
|
|
43
|
+
promoted is used.
|
|
44
|
+
|
|
45
|
+
Global Options:
|
|
46
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
47
|
+
local files that will be used to simulate the KV Store
|
|
48
|
+
with the local development environment.
|
|
49
|
+
|
|
50
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
51
|
+
If not set, the tool will check:
|
|
30
52
|
1. FASTLY_API_TOKEN environment variable
|
|
31
|
-
2.
|
|
32
|
-
|
|
53
|
+
2. Logged-in Fastly CLI profile
|
|
54
|
+
|
|
55
|
+
-h, --help Show this help message and exit.
|
|
33
56
|
`);
|
|
34
57
|
}
|
|
35
58
|
export async function action(actionArgs) {
|
|
@@ -39,6 +62,8 @@ export async function action(actionArgs) {
|
|
|
39
62
|
{ name: 'to', type: String },
|
|
40
63
|
{ name: 'expires-in', type: String },
|
|
41
64
|
{ name: 'expires-at', type: String },
|
|
65
|
+
{ name: 'expires-never', type: Boolean },
|
|
66
|
+
{ name: 'local', type: Boolean },
|
|
42
67
|
{ name: 'fastly-api-token', type: String, },
|
|
43
68
|
];
|
|
44
69
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
@@ -51,7 +76,10 @@ export async function action(actionArgs) {
|
|
|
51
76
|
help();
|
|
52
77
|
return;
|
|
53
78
|
}
|
|
54
|
-
const { verbose, ['collection-name']: collectionNameValue,
|
|
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;
|
|
80
|
+
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
81
|
+
// in other words, the directory that contains `fastly.toml`.
|
|
82
|
+
const computeAppDir = path.resolve();
|
|
55
83
|
if (collectionNameValue == null) {
|
|
56
84
|
console.error("❌ Required argument '--collection-name' not specified.");
|
|
57
85
|
process.exitCode = 1;
|
|
@@ -62,15 +90,55 @@ export async function action(actionArgs) {
|
|
|
62
90
|
process.exitCode = 1;
|
|
63
91
|
return;
|
|
64
92
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
let expirationTime;
|
|
94
|
+
try {
|
|
95
|
+
expirationTime = calcExpirationTime({ expiresIn, expiresAt, expiresNever });
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
console.error(`❌ Cannot process expiration time`);
|
|
99
|
+
console.error(String(err));
|
|
69
100
|
process.exitCode = 1;
|
|
70
101
|
return;
|
|
71
102
|
}
|
|
72
|
-
|
|
73
|
-
|
|
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
|
+
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
|
+
}
|
|
74
142
|
// #### load config
|
|
75
143
|
let staticPublisherRc;
|
|
76
144
|
try {
|
|
@@ -87,43 +155,48 @@ export async function action(actionArgs) {
|
|
|
87
155
|
process.exitCode = 1;
|
|
88
156
|
return;
|
|
89
157
|
}
|
|
90
|
-
let expirationTime;
|
|
91
|
-
try {
|
|
92
|
-
expirationTime = calcExpirationTime({ expiresIn, expiresAt });
|
|
93
|
-
}
|
|
94
|
-
catch (err) {
|
|
95
|
-
console.error(`❌ Cannot process expiration time`);
|
|
96
|
-
console.error(String(err));
|
|
97
|
-
process.exitCode = 1;
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
158
|
const publishId = staticPublisherRc.publishId;
|
|
101
159
|
console.log(` | Publish ID: ${publishId}`);
|
|
102
160
|
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
103
161
|
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
104
162
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
105
163
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
164
|
+
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
165
|
+
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
166
|
+
const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
|
|
106
167
|
const sourceCollectionName = collectionNameValue;
|
|
107
168
|
console.log(`✔️ Collection to copy: ${sourceCollectionName}`);
|
|
108
169
|
const targetCollectionName = toCollectionNameValue;
|
|
109
170
|
console.log(`✔️ Collection to promote to: ${targetCollectionName}`);
|
|
110
|
-
if (expirationTime
|
|
111
|
-
console.log(`✔️
|
|
171
|
+
if (expirationTime === undefined) {
|
|
172
|
+
console.log(`✔️ Not updating expiration timestamp.`);
|
|
173
|
+
}
|
|
174
|
+
else if (expirationTime === null) {
|
|
175
|
+
console.log(`✔️ Updating expiration timestamp: never`);
|
|
112
176
|
}
|
|
113
177
|
else {
|
|
114
|
-
console.log(`✔️
|
|
178
|
+
console.log(`✔️ Updating expiration timestamp: ${new Date(expirationTime * 1000).toISOString()}`);
|
|
115
179
|
}
|
|
116
|
-
if (targetCollectionName === defaultCollectionName && expirationTime
|
|
180
|
+
if (targetCollectionName === defaultCollectionName && expirationTime !== undefined) {
|
|
117
181
|
console.log(` ⚠️ NOTE: Expiration time not enforced for default collection.`);
|
|
118
182
|
}
|
|
119
183
|
const sourceCollectionIndexKey = `${publishId}_index_${sourceCollectionName}`;
|
|
120
184
|
const targetCollectionIndexKey = `${publishId}_index_${targetCollectionName}`;
|
|
121
185
|
const sourceCollectionSettingsKey = `${publishId}_settings_${collectionNameValue}`;
|
|
122
186
|
const targetCollectionSettingsKey = `${publishId}_settings_${targetCollectionName}`;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
187
|
+
let indexEntryInfo, settingsEntryInfo;
|
|
188
|
+
if (localMode) {
|
|
189
|
+
[indexEntryInfo, settingsEntryInfo] = await Promise.all([
|
|
190
|
+
getLocalKvStoreEntry(storeFile, sourceCollectionIndexKey),
|
|
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
|
+
}
|
|
127
200
|
if (!indexEntryInfo) {
|
|
128
201
|
throw new Error(`Error querying index for '${collectionNameValue}' in KV Store`);
|
|
129
202
|
}
|
|
@@ -141,13 +214,34 @@ export async function action(actionArgs) {
|
|
|
141
214
|
if (indexMetadata.publishedTime == null) {
|
|
142
215
|
indexMetadata.publishedTime = Math.floor(Date.now() / 1000);
|
|
143
216
|
}
|
|
144
|
-
if (expirationTime
|
|
145
|
-
|
|
217
|
+
if (expirationTime !== undefined) {
|
|
218
|
+
if (expirationTime === null) {
|
|
219
|
+
delete indexMetadata.expirationTime;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
indexMetadata.expirationTime = expirationTime;
|
|
223
|
+
}
|
|
146
224
|
}
|
|
147
225
|
console.log(`Uploading to KV Store: '${targetCollectionName}'`);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
226
|
+
if (localMode) {
|
|
227
|
+
const staticPublisherKvStoreContent = `${staticPublisherWorkingDir}/kv-store-content`;
|
|
228
|
+
fs.mkdirSync(staticPublisherKvStoreContent, { recursive: true });
|
|
229
|
+
const indexFileName = `index_${collectionNameValue}.json`;
|
|
230
|
+
const indexFilePath = path.resolve(staticPublisherKvStoreContent, indexFileName);
|
|
231
|
+
const indexBody = await indexEntryInfo.response.arrayBuffer();
|
|
232
|
+
fs.writeFileSync(indexFilePath, Buffer.from(indexBody));
|
|
233
|
+
await localKvStoreSubmitEntry(storeFile, targetCollectionIndexKey, path.relative(computeAppDir, indexFilePath), JSON.stringify(indexMetadata));
|
|
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
|
+
}
|
|
152
246
|
console.log("✅ Completed.");
|
|
153
247
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-expiration.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/manage/collections/update-expiration.ts"],"names":[],"mappings":"AA8DA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA2MhD"}
|
|
@@ -4,28 +4,51 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { calcExpirationTime } from '../../../../models/time/index.js';
|
|
6
6
|
import { LoadConfigError, loadStaticPublisherRcFile } from '../../../util/config.js';
|
|
7
|
-
import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../
|
|
8
|
-
import { loadApiToken } from '../../../
|
|
7
|
+
import { getKvStoreEntry, kvStoreSubmitEntry, } from '../../../util/kv-store.js';
|
|
8
|
+
import { loadApiToken } from '../../../util/api-token.js';
|
|
9
9
|
import { parseCommandLine } from '../../../util/args.js';
|
|
10
|
+
import { readServiceId } from "../../../util/fastly-toml.js";
|
|
11
|
+
import { isNodeError } from "../../../util/node.js";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import { getLocalKvStoreEntry, localKvStoreSubmitEntry } from "../../../util/kv-store-local-server.js";
|
|
10
15
|
function help() {
|
|
11
16
|
console.log(`\
|
|
12
17
|
|
|
13
18
|
Usage:
|
|
14
|
-
npx @fastly/compute-js-static-publish collections update-expiration
|
|
19
|
+
npx @fastly/compute-js-static-publish collections update-expiration \\
|
|
20
|
+
--collection-name=<name> \\
|
|
21
|
+
[options]
|
|
15
22
|
|
|
16
23
|
Description:
|
|
17
24
|
Updates the expiration time of an existing collection.
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
--collection-name
|
|
21
|
-
--expires-in <duration> Set new expiration relative to now (e.g., 7d, 1h)
|
|
22
|
-
--expires-at <timestamp> Set new expiration using an absolute ISO 8601 timestamp
|
|
26
|
+
Required:
|
|
27
|
+
--collection-name=<name> The name of the collection to modify
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
Expiration:
|
|
30
|
+
--expires-in=<duration> Expiration duration from now.
|
|
31
|
+
Examples: 3d, 12h, 15m, 1w
|
|
32
|
+
|
|
33
|
+
--expires-at=<timestamp> Absolute expiration in ISO 8601 format.
|
|
34
|
+
Example: 2025-05-01T00:00:00Z
|
|
35
|
+
|
|
36
|
+
--expires-never Prevent this collection from expiring.
|
|
37
|
+
|
|
38
|
+
⚠ These three options are mutually exclusive.
|
|
39
|
+
Specify exactly one.
|
|
40
|
+
|
|
41
|
+
Global Options:
|
|
42
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
43
|
+
local files that will be used to simulate the KV Store
|
|
44
|
+
with the local development environment.
|
|
45
|
+
|
|
46
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
47
|
+
If not set, the tool will check:
|
|
26
48
|
1. FASTLY_API_TOKEN environment variable
|
|
27
|
-
2.
|
|
28
|
-
|
|
49
|
+
2. Logged-in Fastly CLI profile
|
|
50
|
+
|
|
51
|
+
-h, --help Show this help message and exit.
|
|
29
52
|
`);
|
|
30
53
|
}
|
|
31
54
|
export async function action(actionArgs) {
|
|
@@ -34,6 +57,8 @@ export async function action(actionArgs) {
|
|
|
34
57
|
{ name: 'collection-name', type: String, },
|
|
35
58
|
{ name: 'expires-in', type: String },
|
|
36
59
|
{ name: 'expires-at', type: String },
|
|
60
|
+
{ name: 'expires-never', type: Boolean },
|
|
61
|
+
{ name: 'local', type: Boolean },
|
|
37
62
|
{ name: 'fastly-api-token', type: String, },
|
|
38
63
|
];
|
|
39
64
|
const parsed = parseCommandLine(actionArgs, optionDefinitions);
|
|
@@ -46,21 +71,69 @@ export async function action(actionArgs) {
|
|
|
46
71
|
help();
|
|
47
72
|
return;
|
|
48
73
|
}
|
|
49
|
-
const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
74
|
+
const { verbose, ['collection-name']: collectionNameValue, ['expires-in']: expiresIn, ['expires-at']: expiresAt, ['expires-never']: expiresNever, local: localMode, ['fastly-api-token']: fastlyApiToken, } = parsed.commandLineOptions;
|
|
75
|
+
// compute-js-static-publisher cli is always run from the Compute application directory
|
|
76
|
+
// in other words, the directory that contains `fastly.toml`.
|
|
77
|
+
const computeAppDir = path.resolve();
|
|
50
78
|
if (collectionNameValue == null) {
|
|
51
79
|
console.error("❌ Required argument '--collection-name' not specified.");
|
|
52
80
|
process.exitCode = 1;
|
|
53
81
|
return;
|
|
54
82
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
let expirationTime;
|
|
84
|
+
try {
|
|
85
|
+
expirationTime = calcExpirationTime({ expiresIn, expiresAt, expiresNever });
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
console.error(`❌ Cannot process expiration time`);
|
|
89
|
+
console.error(String(err));
|
|
90
|
+
process.exitCode = 1;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (expirationTime === undefined) {
|
|
94
|
+
console.error("❌ Exactly one of '--expires-in', '--expires-at', or '--expires-never' is required.");
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
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'.`);
|
|
59
111
|
process.exitCode = 1;
|
|
60
112
|
return;
|
|
61
113
|
}
|
|
62
|
-
|
|
63
|
-
|
|
114
|
+
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
|
+
}
|
|
64
137
|
// #### load config
|
|
65
138
|
let staticPublisherRc;
|
|
66
139
|
try {
|
|
@@ -77,35 +150,34 @@ export async function action(actionArgs) {
|
|
|
77
150
|
process.exitCode = 1;
|
|
78
151
|
return;
|
|
79
152
|
}
|
|
80
|
-
let expirationTime;
|
|
81
|
-
try {
|
|
82
|
-
expirationTime = calcExpirationTime({ expiresIn, expiresAt });
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
console.error(`❌ Cannot process expiration time`);
|
|
86
|
-
console.error(String(err));
|
|
87
|
-
process.exitCode = 1;
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
153
|
const publishId = staticPublisherRc.publishId;
|
|
91
154
|
console.log(` | Publish ID: ${publishId}`);
|
|
92
155
|
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
93
156
|
console.log(` | Using KV Store: ${kvStoreName}`);
|
|
94
157
|
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
95
158
|
console.log(` | Default Collection Name: ${defaultCollectionName}`);
|
|
159
|
+
const staticPublisherWorkingDir = staticPublisherRc.staticPublisherWorkingDir;
|
|
160
|
+
console.log(` | Static publisher working directory: ${staticPublisherWorkingDir}`);
|
|
161
|
+
const storeFile = path.resolve(staticPublisherWorkingDir, `./kvstore.json`);
|
|
96
162
|
const collectionName = collectionNameValue;
|
|
97
163
|
console.log(`✔️ Collection to update: ${collectionName}`);
|
|
98
|
-
if (expirationTime
|
|
164
|
+
if (expirationTime !== null) {
|
|
99
165
|
console.log(`✔️ Updating expiration timestamp: ${new Date(expirationTime * 1000).toISOString()}`);
|
|
100
166
|
}
|
|
101
167
|
else {
|
|
102
|
-
console.log(`✔️
|
|
168
|
+
console.log(`✔️ Updating expiration timestamp: never`);
|
|
103
169
|
}
|
|
104
170
|
if (collectionName === defaultCollectionName && expirationTime != null) {
|
|
105
171
|
console.log(` ⚠️ NOTE: Expiration time not enforced for default collection.`);
|
|
106
172
|
}
|
|
107
173
|
const collectionIndexKey = `${publishId}_index_${collectionName}`;
|
|
108
|
-
|
|
174
|
+
let indexEntryInfo;
|
|
175
|
+
if (localMode) {
|
|
176
|
+
indexEntryInfo = await getLocalKvStoreEntry(storeFile, collectionIndexKey);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
indexEntryInfo = await getKvStoreEntry(fastlyApiContext, kvStoreName, collectionIndexKey);
|
|
180
|
+
}
|
|
109
181
|
if (!indexEntryInfo) {
|
|
110
182
|
throw new Error(`Error querying index for '${collectionNameValue}' in KV Store`);
|
|
111
183
|
}
|
|
@@ -120,10 +192,24 @@ export async function action(actionArgs) {
|
|
|
120
192
|
if (indexMetadata.publishedTime == null) {
|
|
121
193
|
indexMetadata.publishedTime = Math.floor(Date.now() / 1000);
|
|
122
194
|
}
|
|
123
|
-
if (expirationTime
|
|
195
|
+
if (expirationTime === null) {
|
|
196
|
+
delete indexMetadata.expirationTime;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
124
199
|
indexMetadata.expirationTime = expirationTime;
|
|
125
200
|
}
|
|
126
201
|
console.log(`Uploading to KV Store: '${collectionName}'`);
|
|
127
|
-
|
|
202
|
+
if (localMode) {
|
|
203
|
+
const staticPublisherKvStoreContent = `${staticPublisherWorkingDir}/kv-store-content`;
|
|
204
|
+
fs.mkdirSync(staticPublisherKvStoreContent, { recursive: true });
|
|
205
|
+
const indexFileName = `index_${collectionNameValue}.json`;
|
|
206
|
+
const indexFilePath = path.resolve(staticPublisherKvStoreContent, indexFileName);
|
|
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
|
+
}
|
|
128
214
|
console.log("✅ Completed.");
|
|
129
215
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/manage/index.ts"],"names":[],"mappings":"AAoDA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAyBhD"}
|
|
@@ -26,18 +26,23 @@ Available Commands:
|
|
|
26
26
|
collections update-expiration Modify expiration time for an existing collection
|
|
27
27
|
|
|
28
28
|
Global Options:
|
|
29
|
-
--
|
|
30
|
-
|
|
29
|
+
--local Instead of working with the Fastly KV Store, operate on
|
|
30
|
+
local files that will be used to simulate the KV Store
|
|
31
|
+
with the local development environment.
|
|
32
|
+
|
|
33
|
+
--fastly-api-token=<token> Fastly API token for KV Store access.
|
|
34
|
+
If not set, the tool will check:
|
|
31
35
|
1. FASTLY_API_TOKEN environment variable
|
|
32
|
-
2.
|
|
33
|
-
|
|
36
|
+
2. Logged-in Fastly CLI profile
|
|
37
|
+
|
|
38
|
+
-h, --help Show this help message and exit.
|
|
34
39
|
|
|
35
40
|
Automatic Project Initialization:
|
|
36
41
|
If run in a directory that does not contain a \`static-publish.rc.js\` file, this tool will scaffold a new
|
|
37
42
|
Compute application for you, including Fastly configuration, default routes, and publishing setup.
|
|
38
43
|
|
|
39
44
|
Examples:
|
|
40
|
-
npx @fastly/compute-js-static-publish publish-content --collection-name
|
|
45
|
+
npx @fastly/compute-js-static-publish publish-content --collection-name=live
|
|
41
46
|
npx @fastly/compute-js-static-publish collections list
|
|
42
47
|
npx @fastly/compute-js-static-publish clean --dry-run
|
|
43
48
|
`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publish-content.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/manage/publish-content.ts"],"names":[],"mappings":"AAsGA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA+kBhD"}
|