@fastly/compute-js-static-publish 7.0.0-beta.0 → 7.0.0-beta.2
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 +2 -2
- package/README.short.md +2 -2
- package/build/cli/commands/manage/clean.d.ts +2 -0
- package/build/cli/commands/manage/clean.d.ts.map +1 -0
- package/build/cli/commands/manage/clean.js +201 -0
- package/build/cli/commands/manage/collections/delete.d.ts +2 -0
- package/build/cli/commands/manage/collections/delete.d.ts.map +1 -0
- package/build/cli/commands/{collections → manage/collections}/delete.js +56 -25
- package/build/cli/commands/manage/collections/index.d.ts.map +1 -0
- package/build/cli/commands/{collections → manage/collections}/index.js +27 -22
- package/build/cli/commands/manage/collections/list.d.ts +2 -0
- package/build/cli/commands/manage/collections/list.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/list.js +133 -0
- package/build/cli/commands/manage/collections/promote.d.ts +2 -0
- package/build/cli/commands/manage/collections/promote.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/promote.js +153 -0
- package/build/cli/commands/manage/collections/update-expiration.d.ts +2 -0
- package/build/cli/commands/manage/collections/update-expiration.d.ts.map +1 -0
- package/build/cli/commands/manage/collections/update-expiration.js +129 -0
- package/build/cli/commands/manage/index.d.ts.map +1 -0
- package/build/cli/commands/{index.js → manage/index.js} +26 -29
- package/build/cli/commands/manage/publish-content.d.ts +2 -0
- package/build/cli/commands/manage/publish-content.d.ts.map +1 -0
- package/build/cli/commands/{publish-content.js → manage/publish-content.js} +142 -56
- package/build/cli/commands/{init-app.d.ts → scaffold/index.d.ts} +2 -2
- package/build/cli/commands/scaffold/index.d.ts.map +1 -0
- package/build/cli/commands/{init-app.js → scaffold/index.js} +79 -25
- package/build/cli/fastly-api/api-token.d.ts.map +1 -1
- package/build/cli/fastly-api/api-token.js +7 -1
- package/build/cli/fastly-api/kv-store.d.ts +2 -2
- package/build/cli/fastly-api/kv-store.d.ts.map +1 -1
- package/build/cli/fastly-api/kv-store.js +2 -2
- package/build/cli/index.js +11 -3
- package/build/cli/util/args.d.ts +16 -2
- package/build/cli/util/args.d.ts.map +1 -1
- package/build/cli/util/args.js +32 -6
- package/build/cli/util/fastly-toml.d.ts +2 -0
- package/build/cli/util/fastly-toml.d.ts.map +1 -0
- package/build/cli/util/fastly-toml.js +15 -0
- package/build/cli/util/kv-store-items.d.ts +3 -2
- package/build/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/util/kv-store-items.js +6 -12
- package/build/cli/util/node.d.ts +2 -0
- package/build/cli/util/node.d.ts.map +1 -0
- package/build/cli/util/node.js +10 -0
- package/build/models/server/index.d.ts +5 -0
- package/build/models/server/index.d.ts.map +1 -0
- package/build/models/server/index.js +1 -0
- package/build/models/time/index.d.ts +7 -0
- package/build/models/time/index.d.ts.map +1 -0
- package/build/models/time/index.js +51 -0
- package/build/server/publisher-server/index.d.ts +2 -0
- package/build/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/publisher-server/index.js +38 -4
- package/package.json +3 -2
- package/build/cli/commands/clean.d.ts +0 -2
- package/build/cli/commands/clean.d.ts.map +0 -1
- package/build/cli/commands/clean.js +0 -121
- package/build/cli/commands/collections/delete.d.ts +0 -2
- package/build/cli/commands/collections/delete.d.ts.map +0 -1
- package/build/cli/commands/collections/index.d.ts.map +0 -1
- package/build/cli/commands/collections/list.d.ts +0 -2
- package/build/cli/commands/collections/list.d.ts.map +0 -1
- package/build/cli/commands/collections/list.js +0 -62
- package/build/cli/commands/index.d.ts.map +0 -1
- package/build/cli/commands/init-app.d.ts.map +0 -1
- package/build/cli/commands/publish-content.d.ts +0 -2
- package/build/cli/commands/publish-content.d.ts.map +0 -1
- /package/build/cli/commands/{collections → manage/collections}/index.d.ts +0 -0
- /package/build/cli/commands/{index.d.ts → manage/index.d.ts} +0 -0
package/build/cli/index.js
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* Copyright Fastly, Inc.
|
|
4
4
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import * as scaffoldCommand from './commands/scaffold/index.js';
|
|
8
|
+
import * as manageCommands from './commands/manage/index.js';
|
|
9
|
+
if (!fs.existsSync('./static-publish.rc.js')) {
|
|
10
|
+
console.log("🧑💻Fastly Compute JavaScript Static Publisher (Scaffolding mode)");
|
|
11
|
+
await scaffoldCommand.action(process.argv);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
console.log("🧑💻Fastly Compute JavaScript Static Publisher (Management mode)");
|
|
15
|
+
await manageCommands.action(process.argv);
|
|
16
|
+
}
|
package/build/cli/util/args.d.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
+
import { type CommandLineOptions, type OptionDefinition } from 'command-line-args';
|
|
1
2
|
export type ModeAction = (argv: string[]) => void | Promise<void>;
|
|
2
3
|
export type ActionModule = {
|
|
3
4
|
action: ModeAction;
|
|
4
5
|
};
|
|
6
|
+
export type ActionTable<T extends string> = Record<T, ActionModule>;
|
|
5
7
|
export declare function isHelpArgs(argv: string[]): boolean;
|
|
6
8
|
export declare function findMainCommandNameAndArgs(argv: string[]): [string | null, string[]];
|
|
7
9
|
export type CommandAndArgs<T> = {
|
|
8
10
|
needHelp: false;
|
|
9
11
|
command: T;
|
|
10
12
|
argv: string[];
|
|
11
|
-
}
|
|
13
|
+
};
|
|
14
|
+
export type CommandAndArgsHelp = {
|
|
12
15
|
needHelp: true;
|
|
13
16
|
command: string | null;
|
|
14
17
|
};
|
|
15
|
-
export
|
|
18
|
+
export type CommandAndArgsResult<T> = CommandAndArgs<T> | CommandAndArgsHelp;
|
|
19
|
+
export declare function getCommandAndArgs<T extends string>(argv: string[], actions: ActionTable<T>): CommandAndArgsResult<T>;
|
|
20
|
+
export type CommandLineParsed = {
|
|
21
|
+
needHelp: false;
|
|
22
|
+
commandLineOptions: CommandLineOptions;
|
|
23
|
+
};
|
|
24
|
+
export type CommandLineHelp = {
|
|
25
|
+
needHelp: true;
|
|
26
|
+
error: Error | null;
|
|
27
|
+
};
|
|
28
|
+
export type CommandLineResult = CommandLineParsed | CommandLineHelp;
|
|
29
|
+
export declare function parseCommandLine(argv: string[], optionDefinitions: OptionDefinition[]): CommandLineResult;
|
|
16
30
|
//# sourceMappingURL=args.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/cli/util/args.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/cli/util/args.ts"],"names":[],"mappings":"AAKA,OAAwB,EAAE,KAAK,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEpG,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAClD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAMpE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAKxC;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAepF;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,IAAI,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAA;AAED,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC;AAE7E,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GACtB,oBAAoB,CAAC,CAAC,CAAC,CAiCzB;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,KAAK,CAAC;IAChB,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,IAAI,CAAC;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEpE,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EAAE,EACd,iBAAiB,EAAE,gBAAgB,EAAE,GACpC,iBAAiB,CA0BnB"}
|
package/build/cli/util/args.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import commandLineArgs from 'command-line-args';
|
|
6
|
+
const helpOptionsDefs = [
|
|
7
|
+
{ name: 'help', alias: 'h', type: Boolean },
|
|
8
|
+
];
|
|
6
9
|
export function isHelpArgs(argv) {
|
|
7
|
-
const
|
|
8
|
-
{ name: 'help', type: Boolean, },
|
|
9
|
-
];
|
|
10
|
-
const helpOptions = commandLineArgs(helpDefinitions, { argv, stopAtFirstUnknown: true });
|
|
10
|
+
const helpOptions = commandLineArgs(helpOptionsDefs, { argv, stopAtFirstUnknown: true });
|
|
11
11
|
return !!helpOptions['help'];
|
|
12
12
|
}
|
|
13
13
|
export function findMainCommandNameAndArgs(argv) {
|
|
@@ -22,7 +22,7 @@ export function findMainCommandNameAndArgs(argv) {
|
|
|
22
22
|
}
|
|
23
23
|
return [command, commandArgs];
|
|
24
24
|
}
|
|
25
|
-
export function getCommandAndArgs(argv,
|
|
25
|
+
export function getCommandAndArgs(argv, actions) {
|
|
26
26
|
if (isHelpArgs(argv)) {
|
|
27
27
|
return {
|
|
28
28
|
needHelp: true,
|
|
@@ -32,7 +32,7 @@ export function getCommandAndArgs(argv, modes) {
|
|
|
32
32
|
const result = findMainCommandNameAndArgs(argv);
|
|
33
33
|
const [command, actionArgv] = result;
|
|
34
34
|
if (command != null) {
|
|
35
|
-
for (const modeName of
|
|
35
|
+
for (const modeName of Object.keys(actions)) {
|
|
36
36
|
if (command === modeName) {
|
|
37
37
|
return {
|
|
38
38
|
needHelp: false,
|
|
@@ -53,3 +53,29 @@ export function getCommandAndArgs(argv, modes) {
|
|
|
53
53
|
command,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
export function parseCommandLine(argv, optionDefinitions) {
|
|
57
|
+
let commandLineOptions;
|
|
58
|
+
try {
|
|
59
|
+
commandLineOptions = commandLineArgs([
|
|
60
|
+
...helpOptionsDefs,
|
|
61
|
+
...optionDefinitions,
|
|
62
|
+
], { argv });
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
66
|
+
return {
|
|
67
|
+
needHelp: true,
|
|
68
|
+
error,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (!!commandLineOptions['help']) {
|
|
72
|
+
return {
|
|
73
|
+
needHelp: true,
|
|
74
|
+
error: null,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
needHelp: false,
|
|
79
|
+
commandLineOptions,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastly-toml.d.ts","sourceRoot":"","sources":["../../../src/cli/util/fastly-toml.ts"],"names":[],"mappings":"AAQA,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,sBAQ7C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import toml from 'toml';
|
|
7
|
+
export function readServiceId(filePath) {
|
|
8
|
+
const text = fs.readFileSync(filePath, 'utf8');
|
|
9
|
+
const parsed = toml.parse(text);
|
|
10
|
+
const serviceId = parsed.service_id;
|
|
11
|
+
if (typeof serviceId === 'string') {
|
|
12
|
+
return serviceId;
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export declare function doKvStoreItemsOperation<TObject extends {
|
|
2
|
+
key: string;
|
|
3
|
+
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number): Promise<void>;
|
|
2
4
|
export type KVStoreItemDesc = {
|
|
3
5
|
write: boolean;
|
|
4
6
|
size: number;
|
|
@@ -6,7 +8,6 @@ export type KVStoreItemDesc = {
|
|
|
6
8
|
filePath: string;
|
|
7
9
|
metadataJson?: Record<string, any>;
|
|
8
10
|
};
|
|
9
|
-
export declare function uploadFilesToKVStore(fastlyApiContext: FastlyApiContext, kvStoreName: string, kvStoreItemDescriptions: KVStoreItemDesc[]): Promise<void>;
|
|
10
11
|
export declare function shouldRecreateChunks(chunksDir: string, numChunks: number, item: KVStoreItemDesc, chunkSize: number): boolean;
|
|
11
12
|
export declare function applyKVStoreEntriesChunks(kvStoreItemDescriptions: KVStoreItemDesc[], chunkSize: number): Promise<void>;
|
|
12
13
|
//# sourceMappingURL=kv-store-items.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kv-store-items.d.ts","sourceRoot":"","sources":["../../../src/cli/util/kv-store-items.ts"],"names":[],"mappings":"AAUA,wBAAsB,uBAAuB,CAAC,OAAO,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,EAC3E,OAAO,EAAE,OAAO,EAAE,EAClB,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,iBA6C3B;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,WAkClH;AAED,wBAAsB,yBAAyB,CAAC,uBAAuB,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,MAAM,iBAoG5G"}
|
|
@@ -3,26 +3,20 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import fs from 'node:fs';
|
|
6
|
-
import { directoryExists, getFileSize
|
|
6
|
+
import { directoryExists, getFileSize } from './files.js';
|
|
7
7
|
import { attemptWithRetries } from './retryable.js';
|
|
8
8
|
import { FetchError } from '../fastly-api/api-token.js';
|
|
9
|
-
|
|
10
|
-
export async function uploadFilesToKVStore(fastlyApiContext, kvStoreName, kvStoreItemDescriptions) {
|
|
11
|
-
const maxConcurrent = 12;
|
|
9
|
+
export async function doKvStoreItemsOperation(objects, fn, maxConcurrent = 12) {
|
|
12
10
|
let index = 0; // Shared among workers
|
|
13
11
|
async function worker() {
|
|
14
|
-
while (index <
|
|
12
|
+
while (index < objects.length) {
|
|
15
13
|
const currentIndex = index;
|
|
16
14
|
index = index + 1;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
15
|
+
const object = objects[currentIndex];
|
|
16
|
+
const { key } = object;
|
|
21
17
|
try {
|
|
22
18
|
await attemptWithRetries(async () => {
|
|
23
|
-
|
|
24
|
-
await kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
|
|
25
|
-
console.log(` 🌐 Submitted asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
19
|
+
await fn(object, key, currentIndex);
|
|
26
20
|
}, {
|
|
27
21
|
onAttempt(attempt) {
|
|
28
22
|
if (attempt > 0) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/cli/util/node.ts"],"names":[],"mappings":"AAKA,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,cAAc,CAKtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/server/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type CalcExpirationTimeArg = {
|
|
2
|
+
expiresIn?: string;
|
|
3
|
+
expiresAt?: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function calcExpirationTime({ expiresIn, expiresAt }: CalcExpirationTimeArg): number | undefined;
|
|
6
|
+
export declare function isExpired(unixTime: number): boolean;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/time/index.ts"],"names":[],"mappings":"AAkCA,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,qBAAqB,sBAsBjF;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,WAEzC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
const DURATION_MS = {
|
|
6
|
+
w: 604800000,
|
|
7
|
+
d: 86400000,
|
|
8
|
+
h: 3600000,
|
|
9
|
+
m: 60000,
|
|
10
|
+
s: 1000,
|
|
11
|
+
ms: 1,
|
|
12
|
+
};
|
|
13
|
+
// Parses something like "1d2h30m" or "5m15s" or "150ms"
|
|
14
|
+
function parseDuration(durationStr) {
|
|
15
|
+
const regex = /(\d+(?:\.\d+)?)(ms|[dhms])/g;
|
|
16
|
+
let totalMs = 0;
|
|
17
|
+
let matchedLength = 0;
|
|
18
|
+
for (const match of durationStr.matchAll(regex)) {
|
|
19
|
+
const [res, valueStr, unit] = match;
|
|
20
|
+
const value = parseFloat(valueStr);
|
|
21
|
+
totalMs += value * DURATION_MS[unit];
|
|
22
|
+
matchedLength += res.length;
|
|
23
|
+
}
|
|
24
|
+
if (matchedLength !== durationStr.length) {
|
|
25
|
+
throw new Error(`Invalid duration format: '${durationStr}'`);
|
|
26
|
+
}
|
|
27
|
+
return totalMs;
|
|
28
|
+
}
|
|
29
|
+
export function calcExpirationTime({ expiresIn, expiresAt }) {
|
|
30
|
+
if (expiresIn && expiresAt) {
|
|
31
|
+
throw new Error('Only one of expiresIn or expiresAt may be provided');
|
|
32
|
+
}
|
|
33
|
+
if (expiresIn) {
|
|
34
|
+
const deltaMs = parseDuration(expiresIn);
|
|
35
|
+
console.log(` ⏳ Expiration duration '${expiresIn}' = ${deltaMs} ms`);
|
|
36
|
+
return Math.floor((Date.now() + deltaMs) / 1000); // return UNIX timestamp
|
|
37
|
+
}
|
|
38
|
+
if (expiresAt) {
|
|
39
|
+
const time = Date.parse(expiresAt);
|
|
40
|
+
if (isNaN(time)) {
|
|
41
|
+
throw new Error(`Invalid expiresAt value: '${expiresAt}'`);
|
|
42
|
+
}
|
|
43
|
+
console.log(` ⏰️ Expiration timestamp '${expiresAt}' = '${new Date(time)}'`);
|
|
44
|
+
console.log(` → ${new Date(time).toISOString()}`);
|
|
45
|
+
return Math.floor(time / 1000);
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
export function isExpired(unixTime) {
|
|
50
|
+
return unixTime < Math.floor(Date.now() / 1000);
|
|
51
|
+
}
|
|
@@ -20,6 +20,8 @@ export declare class PublisherServer {
|
|
|
20
20
|
defaultCollectionName: string;
|
|
21
21
|
activeCollectionName: string;
|
|
22
22
|
collectionNameHeader: string | null;
|
|
23
|
+
settingsCached: PublisherServerConfigNormalized | null | undefined;
|
|
24
|
+
kvAssetsIndex: KVAssetEntryMap | null | undefined;
|
|
23
25
|
setActiveCollectionName(collectionName: string): void;
|
|
24
26
|
setCollectionNameHeader(collectionHeader: string | null): void;
|
|
25
27
|
getServerConfig(): Promise<PublisherServerConfigNormalized | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC5B,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,KAAK,+BAA+B,EACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC5B,MAAM,uCAAuC,CAAC;AAO/C,KAAK,cAAc,GAAG;IACpB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,sBAAsB,CAAC;AAE3B,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,WAWpF;AAmBD,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI,CAAC;CACrC,CAAC;AAEF,qBAAa,eAAe;gBAExB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,qBAAqB,EAAE,MAAM;IAS/B,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,eAAe;IAQlD,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IAGpC,cAAc,EAAE,+BAA+B,GAAG,IAAI,GAAG,SAAS,CAAC;IAGnE,aAAa,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,CAAC;IAElD,uBAAuB,CAAC,cAAc,EAAE,MAAM;IAM9C,uBAAuB,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI;IAKjD,eAAe;IAiBf,cAAc;IAoBd,gBAAgB;IAoChB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IA2D5F,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC;IAoDjF,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAcxC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI;IA6DxF,kBAAkB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;YAkC/G,0CAA0C;IAyClD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiDtF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAqE/D"}
|
|
@@ -8,6 +8,7 @@ import { isKVAssetVariantMetadata, } from '../../models/assets/kvstore-assets.js
|
|
|
8
8
|
import { getKVStoreEntry } from '../util/kv-store.js';
|
|
9
9
|
import { checkIfModifiedSince, getIfModifiedSinceHeader } from './serve-preconditions/if-modified-since.js';
|
|
10
10
|
import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if-none-match.js';
|
|
11
|
+
import { isExpired } from "../../models/time/index.js";
|
|
11
12
|
export function buildHeadersSubset(responseHeaders, keys) {
|
|
12
13
|
const resultHeaders = new Headers();
|
|
13
14
|
for (const value of keys) {
|
|
@@ -48,22 +49,29 @@ export class PublisherServer {
|
|
|
48
49
|
}
|
|
49
50
|
setActiveCollectionName(collectionName) {
|
|
50
51
|
this.activeCollectionName = collectionName;
|
|
52
|
+
this.settingsCached = undefined;
|
|
53
|
+
this.kvAssetsIndex = undefined;
|
|
51
54
|
}
|
|
52
55
|
setCollectionNameHeader(collectionHeader) {
|
|
53
56
|
this.collectionNameHeader = collectionHeader;
|
|
54
57
|
}
|
|
55
58
|
// Server config is obtained from the KV Store, and cached for the duration of this object.
|
|
56
|
-
// TODO get from simple cache
|
|
57
59
|
async getServerConfig() {
|
|
60
|
+
if (this.settingsCached !== undefined) {
|
|
61
|
+
return this.settingsCached;
|
|
62
|
+
}
|
|
58
63
|
const settingsFileKey = `${this.publishId}_settings_${this.activeCollectionName}`;
|
|
59
64
|
const kvStore = new KVStore(this.kvStoreName);
|
|
60
65
|
const settingsFile = await getKVStoreEntry(kvStore, settingsFileKey);
|
|
61
66
|
if (settingsFile == null) {
|
|
62
67
|
console.error(`Settings File not found at ${settingsFileKey}.`);
|
|
63
68
|
console.error(`You may need to publish your application.`);
|
|
64
|
-
|
|
69
|
+
this.settingsCached = null;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.settingsCached = (await settingsFile.json());
|
|
65
73
|
}
|
|
66
|
-
return
|
|
74
|
+
return this.settingsCached;
|
|
67
75
|
}
|
|
68
76
|
async getStaticItems() {
|
|
69
77
|
const serverConfig = await this.getServerConfig();
|
|
@@ -85,15 +93,37 @@ export class PublisherServer {
|
|
|
85
93
|
.filter(x => Boolean(x));
|
|
86
94
|
}
|
|
87
95
|
async getKvAssetsIndex() {
|
|
96
|
+
if (this.kvAssetsIndex !== undefined) {
|
|
97
|
+
return this.kvAssetsIndex;
|
|
98
|
+
}
|
|
88
99
|
const indexFileKey = `${this.publishId}_index_${this.activeCollectionName}`;
|
|
89
100
|
const kvStore = new KVStore(this.kvStoreName);
|
|
90
101
|
const indexFile = await getKVStoreEntry(kvStore, indexFileKey);
|
|
91
102
|
if (indexFile == null) {
|
|
92
103
|
console.error(`Index File not found at ${indexFileKey}.`);
|
|
93
104
|
console.error(`You may need to publish your application.`);
|
|
105
|
+
this.kvAssetsIndex = null;
|
|
94
106
|
return null;
|
|
95
107
|
}
|
|
96
|
-
|
|
108
|
+
let collectionIsExpired = false;
|
|
109
|
+
if (this.activeCollectionName !== this.defaultCollectionName) {
|
|
110
|
+
const metadataText = indexFile.metadataText();
|
|
111
|
+
if (metadataText != null) {
|
|
112
|
+
try {
|
|
113
|
+
const metadata = JSON.parse(metadataText);
|
|
114
|
+
collectionIsExpired = metadata.expirationTime != null && isExpired(metadata.expirationTime);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (collectionIsExpired) {
|
|
121
|
+
console.error(`Requested collection expired at ${indexFileKey}.`);
|
|
122
|
+
this.kvAssetsIndex = null;
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
this.kvAssetsIndex = (await indexFile.json());
|
|
126
|
+
return this.kvAssetsIndex;
|
|
97
127
|
}
|
|
98
128
|
async getMatchingAsset(assetKey, applyAuto = false) {
|
|
99
129
|
const serverConfig = await this.getServerConfig();
|
|
@@ -368,6 +398,10 @@ export class PublisherServer {
|
|
|
368
398
|
}
|
|
369
399
|
const url = new URL(request.url);
|
|
370
400
|
const pathname = decodeURI(url.pathname);
|
|
401
|
+
// Custom health check route
|
|
402
|
+
if (pathname === '/healthz') {
|
|
403
|
+
return new Response("OK", { status: 200 });
|
|
404
|
+
}
|
|
371
405
|
const serverConfig = await this.getServerConfig();
|
|
372
406
|
if (serverConfig == null) {
|
|
373
407
|
return new Response(`Settings not found. You may need to publish your application.`, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-beta.
|
|
4
|
+
"version": "7.0.0-beta.2",
|
|
5
5
|
"description": "Static Publisher for Fastly Compute JavaScript",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@fastly/cli": "^11.2.0",
|
|
42
42
|
"command-line-args": "^5.2.1",
|
|
43
|
-
"glob-to-regexp": "^0.4.1"
|
|
43
|
+
"glob-to-regexp": "^0.4.1",
|
|
44
|
+
"toml": "^3.0.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"@fastly/js-compute": "^3.33.2"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clean.ts"],"names":[],"mappings":"AAYA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAoJ1C"}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright Fastly, Inc.
|
|
3
|
-
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
-
*/
|
|
5
|
-
import commandLineArgs from 'command-line-args';
|
|
6
|
-
import { LoadConfigError, loadStaticPublisherRcFile } from '../util/config.js';
|
|
7
|
-
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteFile } from '../fastly-api/kv-store.js';
|
|
8
|
-
import { loadApiToken } from '../fastly-api/api-token.js';
|
|
9
|
-
export async function action(argv) {
|
|
10
|
-
const optionDefinitions = [
|
|
11
|
-
{ name: 'verbose', type: Boolean },
|
|
12
|
-
{ name: 'fastly-api-token', type: String, },
|
|
13
|
-
];
|
|
14
|
-
const commandLineValues = commandLineArgs(optionDefinitions, { argv });
|
|
15
|
-
const { verbose, ['fastly-api-token']: fastlyApiToken, } = commandLineValues;
|
|
16
|
-
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
17
|
-
if (apiTokenResult == null) {
|
|
18
|
-
console.error("❌ Fastly API Token not provided.");
|
|
19
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
20
|
-
process.exitCode = 1;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
24
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
25
|
-
// #### load config
|
|
26
|
-
let staticPublisherRc;
|
|
27
|
-
try {
|
|
28
|
-
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
console.error("❌ Can't load static-publish.rc.js");
|
|
32
|
-
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
33
|
-
if (err instanceof LoadConfigError) {
|
|
34
|
-
for (const error of err.errors) {
|
|
35
|
-
console.error(error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
process.exitCode = 1;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const publishId = staticPublisherRc.publishId;
|
|
42
|
-
console.log(`✔️ Publish ID: ${publishId}`);
|
|
43
|
-
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
44
|
-
console.log(`✔️ Using KV Store: ${kvStoreName}`);
|
|
45
|
-
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
46
|
-
console.log(`✔️ Default Collection Name: ${defaultCollectionName}`);
|
|
47
|
-
// ### KVStore Keys to delete
|
|
48
|
-
const kvKeysToDelete = new Set();
|
|
49
|
-
// ### List all indexes ###
|
|
50
|
-
const indexesPrefix = publishId + '_index_';
|
|
51
|
-
const indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
|
|
52
|
-
if (indexKeys == null) {
|
|
53
|
-
throw new Error(`Can't query indexes in KV Store`);
|
|
54
|
-
}
|
|
55
|
-
// ### Found collections ###
|
|
56
|
-
const foundCollections = indexKeys.map(x => x.slice(indexesPrefix.length));
|
|
57
|
-
console.log('Found collections');
|
|
58
|
-
for (const collection of foundCollections) {
|
|
59
|
-
console.log(collection);
|
|
60
|
-
}
|
|
61
|
-
// TODO ### Determine which ones are not expired, based on an expiration meta
|
|
62
|
-
const liveCollections = foundCollections;
|
|
63
|
-
// ### List all settings ###
|
|
64
|
-
const settingsPrefix = publishId + '_index_';
|
|
65
|
-
const settingsKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, settingsPrefix);
|
|
66
|
-
if (settingsKeys == null) {
|
|
67
|
-
throw new Error(`Can't query settings in KV Store`);
|
|
68
|
-
}
|
|
69
|
-
// If a settings object is found that doesn't match a live collection name then
|
|
70
|
-
// mark it for deletion
|
|
71
|
-
const foundSettingsCollections = settingsKeys.map(key => ({ key, name: key.slice(settingsPrefix.length) }));
|
|
72
|
-
for (const foundSettings of foundSettingsCollections) {
|
|
73
|
-
if (!foundCollections.includes(foundSettings.name)) {
|
|
74
|
-
kvKeysToDelete.add(foundSettings.key);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// ### Go through the index files and make a list of all keys (hashes) that we are keeping
|
|
78
|
-
const assetsIdsInUse = new Set();
|
|
79
|
-
for (const collection of liveCollections) {
|
|
80
|
-
// TODO deal with when the index file is > 20MB
|
|
81
|
-
const kvAssetsIndexResponse = await getKvStoreEntry(fastlyApiContext, kvStoreName, indexesPrefix + collection);
|
|
82
|
-
if (!kvAssetsIndexResponse) {
|
|
83
|
-
throw new Error(`Can't load KV Store entry ${indexesPrefix + collection}`);
|
|
84
|
-
}
|
|
85
|
-
const kvAssetsIndex = (await kvAssetsIndexResponse.response.json());
|
|
86
|
-
for (const [_assetKey, assetEntry] of Object.entries(kvAssetsIndex)) {
|
|
87
|
-
if (assetEntry.key.startsWith('sha256:')) {
|
|
88
|
-
assetsIdsInUse.add(`sha256_${assetEntry.key.slice('sha256:'.length)}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// ### Obtain the assets in the KV Store and find the ones that are not in use
|
|
93
|
-
const assetPrefix = publishId + '_files_';
|
|
94
|
-
const assetKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, assetPrefix);
|
|
95
|
-
if (assetKeys == null) {
|
|
96
|
-
throw new Error(`Can't query assets in KV Store`);
|
|
97
|
-
}
|
|
98
|
-
for (const assetKey of assetKeys) {
|
|
99
|
-
let assetId = assetKey.slice(assetPrefix.length);
|
|
100
|
-
if (assetId.startsWith('sha256_')) {
|
|
101
|
-
assetId = assetId.slice(0, 'sha256_'.length + 64);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// If we don't know what the prefix is, we ignore it
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
if (assetsIdsInUse.has(assetId)) {
|
|
108
|
-
console.log('Asset ID ' + assetId + ' in use');
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
kvKeysToDelete.add(assetKey);
|
|
112
|
-
console.log('Asset ID ' + assetId + ' not in use');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// ### Delete items that have been flagged
|
|
116
|
-
for (const key of kvKeysToDelete) {
|
|
117
|
-
console.log("Deleting item: " + key);
|
|
118
|
-
await kvStoreDeleteFile(fastlyApiContext, kvStoreName, key);
|
|
119
|
-
}
|
|
120
|
-
console.log("✅ Completed.");
|
|
121
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/delete.ts"],"names":[],"mappings":"AAWA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAmG1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/index.ts"],"names":[],"mappings":"AASA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA2BhD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/collections/list.ts"],"names":[],"mappings":"AAWA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,iBAoE1C"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright Fastly, Inc.
|
|
3
|
-
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
-
*/
|
|
5
|
-
import commandLineArgs from 'command-line-args';
|
|
6
|
-
import { LoadConfigError, loadStaticPublisherRcFile } from '../../util/config.js';
|
|
7
|
-
import { getKVStoreKeys } from '../../fastly-api/kv-store.js';
|
|
8
|
-
import { loadApiToken } from '../../fastly-api/api-token.js';
|
|
9
|
-
export async function action(argv) {
|
|
10
|
-
const optionDefinitions = [
|
|
11
|
-
{ name: 'verbose', type: Boolean },
|
|
12
|
-
{ name: 'fastly-api-token', type: String, },
|
|
13
|
-
];
|
|
14
|
-
const commandLineValues = commandLineArgs(optionDefinitions, { argv });
|
|
15
|
-
const { verbose, ['fastly-api-token']: fastlyApiToken, } = commandLineValues;
|
|
16
|
-
const apiTokenResult = loadApiToken({ commandLine: fastlyApiToken });
|
|
17
|
-
if (apiTokenResult == null) {
|
|
18
|
-
console.error("❌ Fastly API Token not provided.");
|
|
19
|
-
console.error("Set the FASTLY_API_TOKEN environment variable to an API token that has write access to the KV Store.");
|
|
20
|
-
process.exitCode = 1;
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const fastlyApiContext = { apiToken: apiTokenResult.apiToken };
|
|
24
|
-
console.log(`✔️ Fastly API Token: ${fastlyApiContext.apiToken.slice(0, 4)}${'*'.repeat(fastlyApiContext.apiToken.length - 4)} from '${apiTokenResult.source}'`);
|
|
25
|
-
// #### load config
|
|
26
|
-
let staticPublisherRc;
|
|
27
|
-
try {
|
|
28
|
-
staticPublisherRc = await loadStaticPublisherRcFile();
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
console.error("❌ Can't load static-publish.rc.js");
|
|
32
|
-
console.error("Run this from a compute-js-static-publish compute-js directory.");
|
|
33
|
-
if (err instanceof LoadConfigError) {
|
|
34
|
-
for (const error of err.errors) {
|
|
35
|
-
console.error(error);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
process.exitCode = 1;
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const publishId = staticPublisherRc.publishId;
|
|
42
|
-
console.log(`✔️ Publish ID: ${publishId}`);
|
|
43
|
-
const kvStoreName = staticPublisherRc.kvStoreName;
|
|
44
|
-
console.log(`✔️ Using KV Store: ${kvStoreName}`);
|
|
45
|
-
const defaultCollectionName = staticPublisherRc.defaultCollectionName;
|
|
46
|
-
console.log(`✔️ Default Collection Name: ${defaultCollectionName}`);
|
|
47
|
-
// ### List all indexes ###
|
|
48
|
-
const indexesPrefix = publishId + '_index_';
|
|
49
|
-
const indexKeys = await getKVStoreKeys(fastlyApiContext, kvStoreName, indexesPrefix);
|
|
50
|
-
if (indexKeys == null) {
|
|
51
|
-
throw new Error(`Can't query indexes in KV Store`);
|
|
52
|
-
}
|
|
53
|
-
// ### Found collections ###
|
|
54
|
-
const foundCollections = indexKeys.map(key => ({ key, name: key.slice(indexesPrefix.length), }));
|
|
55
|
-
if (foundCollections.length === 0) {
|
|
56
|
-
console.log('No collections found.');
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
console.log(`Found collections: ${foundCollections.map(x => `'${x.name}'`).join(', ')}`);
|
|
60
|
-
}
|
|
61
|
-
console.log("✅ Completed.");
|
|
62
|
-
}
|