@fastly/compute-js-static-publish 6.3.0 → 7.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +31 -586
- package/README.short.md +53 -0
- package/build/cli/commands/clean.d.ts +2 -0
- package/build/cli/commands/clean.d.ts.map +1 -0
- package/build/cli/commands/clean.js +121 -0
- package/build/cli/commands/collections/delete.d.ts +2 -0
- package/build/cli/commands/collections/delete.d.ts.map +1 -0
- package/build/cli/commands/collections/delete.js +88 -0
- package/build/cli/commands/collections/index.d.ts +2 -0
- package/build/cli/commands/collections/index.d.ts.map +1 -0
- package/build/cli/commands/collections/index.js +52 -0
- package/build/cli/commands/collections/list.d.ts +2 -0
- package/build/cli/commands/collections/list.d.ts.map +1 -0
- package/build/cli/commands/collections/list.js +62 -0
- package/build/cli/commands/index.d.ts +2 -0
- package/build/cli/commands/index.d.ts.map +1 -0
- package/build/cli/commands/index.js +67 -0
- package/build/cli/commands/init-app.d.ts +18 -2
- package/build/cli/commands/init-app.d.ts.map +1 -1
- package/build/cli/commands/init-app.js +299 -266
- package/build/cli/commands/publish-content.d.ts +2 -0
- package/build/cli/commands/publish-content.d.ts.map +1 -0
- package/build/cli/commands/publish-content.js +472 -0
- package/build/cli/compression/brotli.d.ts +1 -1
- package/build/cli/compression/brotli.d.ts.map +1 -1
- package/build/cli/compression/brotli.js +8 -11
- package/build/cli/compression/gzip.d.ts +1 -1
- package/build/cli/compression/gzip.d.ts.map +1 -1
- package/build/cli/compression/gzip.js +8 -11
- package/build/cli/compression/index.d.ts +3 -6
- package/build/cli/compression/index.d.ts.map +1 -1
- package/build/cli/compression/index.js +8 -9
- package/build/cli/fastly-api/api-token.d.ts +17 -0
- package/build/cli/fastly-api/api-token.d.ts.map +1 -0
- package/build/cli/fastly-api/api-token.js +94 -0
- package/build/cli/fastly-api/kv-store.d.ts +24 -0
- package/build/cli/fastly-api/kv-store.d.ts.map +1 -0
- package/build/cli/{util → fastly-api}/kv-store.js +42 -22
- package/build/cli/index.js +7 -91
- package/build/cli/util/args.d.ts +16 -0
- package/build/cli/util/args.d.ts.map +1 -0
- package/build/cli/util/args.js +55 -0
- package/build/cli/util/config.d.ts +13 -0
- package/build/cli/util/config.d.ts.map +1 -0
- package/build/cli/{load-config.js → util/config.js} +234 -187
- package/build/{util → cli/util}/content-types.d.ts +1 -2
- package/build/cli/util/content-types.d.ts.map +1 -0
- package/build/{util → cli/util}/content-types.js +11 -6
- package/build/cli/util/data.d.ts +3 -3
- package/build/cli/util/data.d.ts.map +1 -1
- package/build/cli/util/data.js +6 -2
- package/build/cli/util/files.d.ts +10 -2
- package/build/cli/util/files.d.ts.map +1 -1
- package/build/cli/util/files.js +53 -6
- package/build/cli/util/kv-store-items.d.ts +12 -0
- package/build/cli/util/kv-store-items.d.ts.map +1 -0
- package/build/cli/util/kv-store-items.js +161 -0
- package/build/cli/util/kv-store-local-server.d.ts +3 -0
- package/build/cli/util/kv-store-local-server.d.ts.map +1 -0
- package/build/cli/util/kv-store-local-server.js +35 -0
- package/build/cli/util/package.d.ts +9 -0
- package/build/cli/util/package.d.ts.map +1 -0
- package/build/cli/util/package.js +44 -0
- package/build/cli/util/retryable.d.ts +12 -0
- package/build/cli/util/retryable.d.ts.map +1 -0
- package/build/cli/util/retryable.js +43 -0
- package/build/cli/util/variants.d.ts +4 -0
- package/build/cli/util/variants.d.ts.map +1 -0
- package/build/cli/util/variants.js +27 -0
- package/build/index.d.ts +5 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -6
- package/build/models/assets/kvstore-assets.d.ts +17 -0
- package/build/models/assets/kvstore-assets.d.ts.map +1 -0
- package/build/models/assets/kvstore-assets.js +28 -0
- package/build/{constants/compression.d.ts → models/compression/index.d.ts} +2 -1
- package/build/models/compression/index.d.ts.map +1 -0
- package/build/models/compression/index.js +11 -0
- package/build/models/config/publish-content-config.d.ts +41 -0
- package/build/models/config/publish-content-config.d.ts.map +1 -0
- package/build/models/config/publish-content-config.js +5 -0
- package/build/models/config/publisher-server-config.d.ts +20 -0
- package/build/models/config/publisher-server-config.d.ts.map +1 -0
- package/build/models/config/publisher-server-config.js +5 -0
- package/build/models/config/static-publish-rc.d.ts +6 -0
- package/build/models/config/static-publish-rc.d.ts.map +1 -0
- package/build/models/config/static-publish-rc.js +5 -0
- package/build/server/collection-selector/from-config-store.d.ts +2 -0
- package/build/server/collection-selector/from-config-store.d.ts.map +1 -0
- package/build/server/collection-selector/from-config-store.js +15 -0
- package/build/server/collection-selector/from-cookie.d.ts +23 -0
- package/build/server/collection-selector/from-cookie.d.ts.map +1 -0
- package/build/server/collection-selector/from-cookie.js +98 -0
- package/build/server/collection-selector/from-request.d.ts +13 -0
- package/build/server/collection-selector/from-request.d.ts.map +1 -0
- package/build/server/collection-selector/from-request.js +22 -0
- package/build/server/collection-selector/index.d.ts +5 -0
- package/build/server/collection-selector/index.d.ts.map +1 -0
- package/build/server/collection-selector/index.js +7 -0
- package/build/server/collection-selector/request-collection-selector.d.ts +5 -0
- package/build/server/collection-selector/request-collection-selector.d.ts.map +1 -0
- package/build/server/collection-selector/request-collection-selector.js +5 -0
- package/build/server/publisher-server/index.d.ts +38 -0
- package/build/server/publisher-server/index.d.ts.map +1 -0
- package/build/server/publisher-server/index.js +418 -0
- package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts +3 -0
- package/build/server/publisher-server/serve-preconditions/if-modified-since.d.ts.map +1 -0
- package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-modified-since.js +6 -2
- package/build/server/publisher-server/serve-preconditions/if-none-match.d.ts.map +1 -0
- package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.js +4 -0
- package/build/server/util/cookies.d.ts +2 -0
- package/build/server/util/cookies.d.ts.map +1 -0
- package/build/server/util/cookies.js +14 -0
- package/build/server/util/kv-store.d.ts +3 -0
- package/build/server/util/kv-store.d.ts.map +1 -0
- package/build/server/util/kv-store.js +95 -0
- package/package.json +18 -10
- package/build/cli/commands/build-static.d.ts +0 -3
- package/build/cli/commands/build-static.d.ts.map +0 -1
- package/build/cli/commands/build-static.js +0 -541
- package/build/cli/commands/clean-kv-store.d.ts +0 -3
- package/build/cli/commands/clean-kv-store.d.ts.map +0 -1
- package/build/cli/commands/clean-kv-store.js +0 -55
- package/build/cli/load-config.d.ts +0 -6
- package/build/cli/load-config.d.ts.map +0 -1
- package/build/cli/presets/implementations/astro.d.ts +0 -7
- package/build/cli/presets/implementations/astro.d.ts.map +0 -1
- package/build/cli/presets/implementations/astro.js +0 -23
- package/build/cli/presets/implementations/create-react-app.d.ts +0 -11
- package/build/cli/presets/implementations/create-react-app.d.ts.map +0 -1
- package/build/cli/presets/implementations/create-react-app.js +0 -34
- package/build/cli/presets/implementations/docusaurus.d.ts +0 -7
- package/build/cli/presets/implementations/docusaurus.d.ts.map +0 -1
- package/build/cli/presets/implementations/docusaurus.js +0 -13
- package/build/cli/presets/implementations/gatsby.d.ts +0 -7
- package/build/cli/presets/implementations/gatsby.d.ts.map +0 -1
- package/build/cli/presets/implementations/gatsby.js +0 -13
- package/build/cli/presets/implementations/next.d.ts +0 -7
- package/build/cli/presets/implementations/next.d.ts.map +0 -1
- package/build/cli/presets/implementations/next.js +0 -13
- package/build/cli/presets/implementations/sveltekit.d.ts +0 -7
- package/build/cli/presets/implementations/sveltekit.d.ts.map +0 -1
- package/build/cli/presets/implementations/sveltekit.js +0 -13
- package/build/cli/presets/implementations/vite.d.ts +0 -7
- package/build/cli/presets/implementations/vite.d.ts.map +0 -1
- package/build/cli/presets/implementations/vite.js +0 -13
- package/build/cli/presets/implementations/vue.d.ts +0 -7
- package/build/cli/presets/implementations/vue.d.ts.map +0 -1
- package/build/cli/presets/implementations/vue.js +0 -24
- package/build/cli/presets/index.d.ts +0 -3
- package/build/cli/presets/index.d.ts.map +0 -1
- package/build/cli/presets/index.js +0 -20
- package/build/cli/presets/preset-base.d.ts +0 -21
- package/build/cli/presets/preset-base.d.ts.map +0 -1
- package/build/cli/presets/preset-base.js +0 -1
- package/build/cli/util/fastly-api.d.ts +0 -10
- package/build/cli/util/fastly-api.d.ts.map +0 -1
- package/build/cli/util/fastly-api.js +0 -47
- package/build/cli/util/hash.d.ts +0 -5
- package/build/cli/util/hash.d.ts.map +0 -1
- package/build/cli/util/hash.js +0 -9
- package/build/cli/util/id.d.ts +0 -3
- package/build/cli/util/id.d.ts.map +0 -1
- package/build/cli/util/id.js +0 -17
- package/build/cli/util/kv-store.d.ts +0 -16
- package/build/cli/util/kv-store.d.ts.map +0 -1
- package/build/cli/util/publish-id.d.ts +0 -5
- package/build/cli/util/publish-id.d.ts.map +0 -1
- package/build/cli/util/publish-id.js +0 -26
- package/build/compute-js.d.ts +0 -3
- package/build/compute-js.d.ts.map +0 -1
- package/build/compute-js.js +0 -2
- package/build/constants/compression.d.ts.map +0 -1
- package/build/constants/compression.js +0 -4
- package/build/server/assets/asset-manager.d.ts +0 -8
- package/build/server/assets/asset-manager.d.ts.map +0 -1
- package/build/server/assets/asset-manager.js +0 -14
- package/build/server/assets/content-asset-kv-store.d.ts +0 -19
- package/build/server/assets/content-asset-kv-store.d.ts.map +0 -1
- package/build/server/assets/content-asset-kv-store.js +0 -70
- package/build/server/assets/content-asset-wasm-inline.d.ts +0 -18
- package/build/server/assets/content-asset-wasm-inline.d.ts.map +0 -1
- package/build/server/assets/content-asset-wasm-inline.js +0 -52
- package/build/server/assets/content-assets.d.ts +0 -46
- package/build/server/assets/content-assets.d.ts.map +0 -1
- package/build/server/assets/content-assets.js +0 -100
- package/build/server/assets/module-assets.d.ts +0 -23
- package/build/server/assets/module-assets.d.ts.map +0 -1
- package/build/server/assets/module-assets.js +0 -45
- package/build/server/kv-store/inline-store-entry.d.ts +0 -25
- package/build/server/kv-store/inline-store-entry.d.ts.map +0 -1
- package/build/server/kv-store/inline-store-entry.js +0 -100
- package/build/server/publisher-server.d.ts +0 -23
- package/build/server/publisher-server.d.ts.map +0 -1
- package/build/server/publisher-server.js +0 -257
- package/build/server/serve-preconditions/if-modified-since.d.ts +0 -4
- package/build/server/serve-preconditions/if-modified-since.d.ts.map +0 -1
- package/build/server/serve-preconditions/if-none-match.d.ts.map +0 -1
- package/build/server/util/http.d.ts +0 -2
- package/build/server/util/http.d.ts.map +0 -1
- package/build/server/util/http.js +0 -9
- package/build/types/compute.d.ts +0 -11
- package/build/types/compute.d.ts.map +0 -1
- package/build/types/compute.js +0 -1
- package/build/types/config-normalized.d.ts +0 -34
- package/build/types/config-normalized.d.ts.map +0 -1
- package/build/types/config-normalized.js +0 -1
- package/build/types/config.d.ts +0 -37
- package/build/types/config.d.ts.map +0 -1
- package/build/types/config.js +0 -1
- package/build/types/content-assets.d.ts +0 -55
- package/build/types/content-assets.d.ts.map +0 -1
- package/build/types/content-assets.js +0 -1
- package/build/types/content-types.d.ts +0 -11
- package/build/types/content-types.d.ts.map +0 -1
- package/build/types/content-types.js +0 -1
- package/build/types/index.d.ts +0 -7
- package/build/types/index.d.ts.map +0 -1
- package/build/types/index.js +0 -1
- package/build/types/module-assets.d.ts +0 -15
- package/build/types/module-assets.d.ts.map +0 -1
- package/build/types/module-assets.js +0 -1
- package/build/types/util.d.ts +0 -7
- package/build/types/util.d.ts.map +0 -1
- package/build/types/util.js +0 -1
- package/build/util/content-types.d.ts.map +0 -1
- package/build/util/index.d.ts +0 -3
- package/build/util/index.d.ts.map +0 -1
- package/build/util/index.js +0 -2
- package/build/util/metadata.d.ts +0 -3
- package/build/util/metadata.d.ts.map +0 -1
- package/build/util/metadata.js +0 -12
- package/resources/README.md +0 -3
- package/resources/statics-metadata.d.ts +0 -10
- package/resources/statics.d.ts +0 -19
- package/resources/webpack.config.js +0 -41
- /package/build/server/{serve-preconditions → publisher-server/serve-preconditions}/if-none-match.d.ts +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import cli from '@fastly/cli';
|
|
7
|
+
import { makeRetryable } from '../util/retryable.js';
|
|
8
|
+
;
|
|
9
|
+
export function loadApiToken(params) {
|
|
10
|
+
let apiToken = null;
|
|
11
|
+
let source = '';
|
|
12
|
+
// Try command line arg
|
|
13
|
+
if (typeof params.commandLine === 'string') {
|
|
14
|
+
apiToken = params.commandLine.trim();
|
|
15
|
+
source = 'commandline';
|
|
16
|
+
}
|
|
17
|
+
// Try env (FASTLY_API_TOKEN)
|
|
18
|
+
if (apiToken == null) {
|
|
19
|
+
apiToken = process.env.FASTLY_API_TOKEN || null;
|
|
20
|
+
if (apiToken != null) {
|
|
21
|
+
source = 'env';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Try fastly cli
|
|
25
|
+
if (apiToken == null) {
|
|
26
|
+
try {
|
|
27
|
+
const { stdout, error } = spawnSync(cli, ['profile', 'token', '--quiet'], {
|
|
28
|
+
encoding: 'utf-8',
|
|
29
|
+
});
|
|
30
|
+
apiToken = error ? null : stdout.trim();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
apiToken = null;
|
|
34
|
+
}
|
|
35
|
+
if (apiToken != null) {
|
|
36
|
+
source = 'fastly-profile-token';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (apiToken == null) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return { apiToken, source };
|
|
43
|
+
}
|
|
44
|
+
const RETRYABLE_STATUS_CODES = [
|
|
45
|
+
408, // Request Timeout
|
|
46
|
+
409, // Conflict (depends)
|
|
47
|
+
423, // Locked
|
|
48
|
+
429, // Too Many Requests
|
|
49
|
+
500, // Internal Server Error
|
|
50
|
+
502, // Bad Gateway
|
|
51
|
+
503, // Service Unavailable
|
|
52
|
+
504, // Gateway Timeout
|
|
53
|
+
];
|
|
54
|
+
export class FetchError extends Error {
|
|
55
|
+
constructor(message, status) {
|
|
56
|
+
super(message);
|
|
57
|
+
this.name = 'FetchError';
|
|
58
|
+
this.status = status;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function callFastlyApi(fastlyApiContext, endpoint, operationName, queryParams, requestInit) {
|
|
62
|
+
const url = new URL(endpoint, 'https://api.fastly.com/');
|
|
63
|
+
if (queryParams != null) {
|
|
64
|
+
for (const [key, value] of queryParams.entries()) {
|
|
65
|
+
url.searchParams.append(key, value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const headers = new Headers(requestInit?.headers);
|
|
69
|
+
headers.set('Fastly-Key', fastlyApiContext.apiToken);
|
|
70
|
+
const request = new Request(url, {
|
|
71
|
+
...requestInit,
|
|
72
|
+
headers,
|
|
73
|
+
redirect: 'error',
|
|
74
|
+
});
|
|
75
|
+
let response;
|
|
76
|
+
try {
|
|
77
|
+
response = await fetch(request);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
if (err instanceof TypeError) {
|
|
81
|
+
throw makeRetryable(err);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
if (!RETRYABLE_STATUS_CODES.includes(response.status)) {
|
|
89
|
+
throw new FetchError(`${operationName} failed: ${response.status}`, response.status);
|
|
90
|
+
}
|
|
91
|
+
throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${response.status}`, response.status));
|
|
92
|
+
}
|
|
93
|
+
return response;
|
|
94
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type FastlyApiContext } from './api-token.js';
|
|
2
|
+
type KVStoreInfo = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getKVStoreIdForNameMap(fastlyApiContext: FastlyApiContext): Promise<Record<string, string>>;
|
|
7
|
+
export declare function getKVStoreIdForName(fastlyApiContext: FastlyApiContext, kvStoreName: string): Promise<string>;
|
|
8
|
+
export declare function getKVStoreInfos(fastlyApiContext: FastlyApiContext): Promise<KVStoreInfo[]>;
|
|
9
|
+
export declare const _getKVStoreKeys: (fastlyApiContext: FastlyApiContext, operationName: string, kvStoreId: string, prefix?: string | undefined) => Promise<string[]>;
|
|
10
|
+
export declare function getKVStoreKeys(fastlyApiContext: FastlyApiContext, kvStoreName: string, prefix?: string): Promise<string[] | null>;
|
|
11
|
+
export declare function getKvStoreEntryInfo(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<false | {
|
|
12
|
+
metadata: string | null;
|
|
13
|
+
generation: string | null;
|
|
14
|
+
response: Response;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function getKvStoreEntry(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, metadataOnly?: boolean): Promise<false | {
|
|
17
|
+
metadata: string | null;
|
|
18
|
+
generation: string | null;
|
|
19
|
+
response: Response;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function kvStoreSubmitFile(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string, data: Uint8Array | string, metadata: string | undefined): Promise<void>;
|
|
22
|
+
export declare function kvStoreDeleteFile(fastlyApiContext: FastlyApiContext, kvStoreName: string, key: string): Promise<void>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=kv-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kv-store.d.ts","sourceRoot":"","sources":["../../../src/cli/fastly-api/kv-store.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAElF,KAAK,WAAW,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAmBF,wBAAsB,sBAAsB,CAAC,gBAAgB,EAAE,gBAAgB,mCAkB9E;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,mBAKhG;AAqCD,wBAAsB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB,0BAcvE;AAED,eAAO,MAAM,eAAe,qBAjDgB,gBAAgB,iBAAiB,MAAM,sEAyDlF,CAAC;AAEF,wBAAsB,cAAc,CAClC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,4BAchB;AAED,wBAAsB,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;;;;GAI7G;AAED,wBAAsB,eAAe,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,OAAO;;;;GA8BvB;AAGD,wBAAsB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,iBAmBpK;AAED,wBAAsB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,iBAa3G"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { callFastlyApi, FetchError } from './api-token.js';
|
|
2
6
|
const cache = new WeakMap();
|
|
3
7
|
export async function getKVStoreIdForNameMap(fastlyApiContext) {
|
|
4
8
|
const cacheEntry = cache.get(fastlyApiContext);
|
|
@@ -20,7 +24,7 @@ export async function getKVStoreIdForName(fastlyApiContext, kvStoreName) {
|
|
|
20
24
|
}
|
|
21
25
|
function createArrayGetter() {
|
|
22
26
|
return function (fn) {
|
|
23
|
-
return async function (fastlyApiContext, ...args) {
|
|
27
|
+
return async function (fastlyApiContext, operationName, ...args) {
|
|
24
28
|
const results = [];
|
|
25
29
|
let cursor = null;
|
|
26
30
|
while (true) {
|
|
@@ -29,10 +33,7 @@ function createArrayGetter() {
|
|
|
29
33
|
queryParams.set('cursor', cursor);
|
|
30
34
|
}
|
|
31
35
|
const endpoint = fn(...args);
|
|
32
|
-
const response = await callFastlyApi(fastlyApiContext, endpoint, queryParams);
|
|
33
|
-
if (response.status !== 200) {
|
|
34
|
-
throw new Error('Unexpected data format');
|
|
35
|
-
}
|
|
36
|
+
const response = await callFastlyApi(fastlyApiContext, endpoint, operationName, queryParams);
|
|
36
37
|
const infos = await response.json();
|
|
37
38
|
for (const item of infos.data) {
|
|
38
39
|
results.push(item);
|
|
@@ -53,45 +54,67 @@ export async function getKVStoreInfos(fastlyApiContext) {
|
|
|
53
54
|
if (kvStoreInfos != null) {
|
|
54
55
|
return kvStoreInfos;
|
|
55
56
|
}
|
|
56
|
-
kvStoreInfos = await _getKVStoreInfos(fastlyApiContext);
|
|
57
|
+
kvStoreInfos = await _getKVStoreInfos(fastlyApiContext, 'Listing KV Stores');
|
|
57
58
|
cache.set(fastlyApiContext, { ...cacheEntry, kvStoreInfos });
|
|
58
59
|
return kvStoreInfos;
|
|
59
60
|
}
|
|
60
|
-
export const _getKVStoreKeys = createArrayGetter()((kvStoreId) =>
|
|
61
|
-
|
|
61
|
+
export const _getKVStoreKeys = createArrayGetter()((kvStoreId, prefix) => {
|
|
62
|
+
let endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys`;
|
|
63
|
+
if (prefix != null) {
|
|
64
|
+
endpoint += '?prefix=' + encodeURIComponent(prefix);
|
|
65
|
+
}
|
|
66
|
+
return endpoint;
|
|
67
|
+
});
|
|
68
|
+
export async function getKVStoreKeys(fastlyApiContext, kvStoreName, prefix) {
|
|
62
69
|
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
63
70
|
if (kvStoreId == null) {
|
|
64
71
|
return null;
|
|
65
72
|
}
|
|
66
|
-
return await _getKVStoreKeys(fastlyApiContext, kvStoreId);
|
|
73
|
+
return await _getKVStoreKeys(fastlyApiContext, `Listing Keys for KV Store [${kvStoreId}] ${kvStoreName}${prefix != null ? ` (prefix '${prefix}')` : ''}`, kvStoreId, prefix);
|
|
67
74
|
}
|
|
68
|
-
export async function
|
|
75
|
+
export async function getKvStoreEntryInfo(fastlyApiContext, kvStoreName, key) {
|
|
76
|
+
return getKvStoreEntry(fastlyApiContext, kvStoreName, key, true);
|
|
77
|
+
}
|
|
78
|
+
export async function getKvStoreEntry(fastlyApiContext, kvStoreName, key, metadataOnly) {
|
|
69
79
|
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
70
80
|
if (kvStoreId == null) {
|
|
71
81
|
return false;
|
|
72
82
|
}
|
|
73
83
|
const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
let response;
|
|
85
|
+
try {
|
|
86
|
+
response = await callFastlyApi(fastlyApiContext, endpoint, `Checking existence of [${key}]`, null, { method: metadataOnly ? 'HEAD' : 'GET' });
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (err instanceof FetchError && err.status === 404) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
const metadata = response.headers.get('metadata');
|
|
95
|
+
const generation = response.headers.get('generation');
|
|
96
|
+
return {
|
|
97
|
+
metadata,
|
|
98
|
+
generation,
|
|
99
|
+
response,
|
|
100
|
+
};
|
|
76
101
|
}
|
|
77
102
|
const encoder = new TextEncoder();
|
|
78
|
-
export async function kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, data) {
|
|
103
|
+
export async function kvStoreSubmitFile(fastlyApiContext, kvStoreName, key, data, metadata) {
|
|
79
104
|
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
80
105
|
if (kvStoreId == null) {
|
|
81
106
|
throw new Error('KV Store not found');
|
|
82
107
|
}
|
|
83
108
|
const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
|
|
84
109
|
const body = typeof data === 'string' ? encoder.encode(data) : data;
|
|
85
|
-
|
|
110
|
+
await callFastlyApi(fastlyApiContext, endpoint, `Submitting item [${key}]`, null, {
|
|
86
111
|
method: 'PUT',
|
|
87
112
|
headers: {
|
|
88
113
|
'content-type': 'application/octet-stream',
|
|
114
|
+
...(metadata != null ? { metadata } : null)
|
|
89
115
|
},
|
|
90
116
|
body,
|
|
91
117
|
});
|
|
92
|
-
if (response.status !== 200) {
|
|
93
|
-
throw new Error(`Submitting item ${key} gave error: ${response.status}`);
|
|
94
|
-
}
|
|
95
118
|
}
|
|
96
119
|
export async function kvStoreDeleteFile(fastlyApiContext, kvStoreName, key) {
|
|
97
120
|
const kvStoreId = await getKVStoreIdForName(fastlyApiContext, kvStoreName);
|
|
@@ -99,10 +122,7 @@ export async function kvStoreDeleteFile(fastlyApiContext, kvStoreName, key) {
|
|
|
99
122
|
throw new Error('KV Store not found');
|
|
100
123
|
}
|
|
101
124
|
const endpoint = `/resources/stores/kv/${encodeURIComponent(kvStoreId)}/keys/${encodeURIComponent(key)}`;
|
|
102
|
-
|
|
125
|
+
await callFastlyApi(fastlyApiContext, endpoint, `Deleting item [${key}]`, null, {
|
|
103
126
|
method: 'DELETE',
|
|
104
127
|
});
|
|
105
|
-
if (response.status < 200 || response.status >= 300) {
|
|
106
|
-
throw new Error(`Deleting item '${key}' gave error: ${response.status}`);
|
|
107
|
-
}
|
|
108
128
|
}
|
package/build/cli/index.js
CHANGED
|
@@ -1,92 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// - vite
|
|
10
|
-
// - sveltekit
|
|
11
|
-
// - vue
|
|
12
|
-
// - next
|
|
13
|
-
// - astro
|
|
14
|
-
// - gatsby
|
|
15
|
-
// - docusaurus
|
|
16
|
-
{ name: 'preset', type: String, },
|
|
17
|
-
{ name: 'build-static', type: Boolean },
|
|
18
|
-
{ name: 'suppress-framework-warnings', type: Boolean },
|
|
19
|
-
{ name: 'output', alias: 'o', type: String, defaultValue: './compute-js', },
|
|
20
|
-
// Whether the scaffolded project should use webpack to bundle assets.
|
|
21
|
-
{ name: 'webpack', type: Boolean, defaultValue: false },
|
|
22
|
-
// The 'root' directory for the publishing.
|
|
23
|
-
// All assets are expected to exist under this root. Required.
|
|
24
|
-
// For backwards compatibility, if this value is not provided,
|
|
25
|
-
// then the value of 'public-dir' is used.
|
|
26
|
-
{ name: 'root-dir', type: String, },
|
|
27
|
-
// The 'public' directory. The Publisher Server will
|
|
28
|
-
// resolve requests relative to this directory. If not specified,
|
|
29
|
-
// defaults to the same value as 'root-dir'. See README for
|
|
30
|
-
// details.
|
|
31
|
-
{ name: 'public-dir', type: String, },
|
|
32
|
-
// Directories to specify as containing 'static' files. The
|
|
33
|
-
// Publisher Server will serve files from these directories
|
|
34
|
-
// with a long TTL.
|
|
35
|
-
{ name: 'static-dir', type: String, multiple: true, },
|
|
36
|
-
// The 'static content root directory' where the Static Publisher
|
|
37
|
-
// outputs its metadata files and loaders.
|
|
38
|
-
{ name: 'static-content-root-dir', type: String, },
|
|
39
|
-
// Path to a file to be used to serve in a SPA application.
|
|
40
|
-
// The Publisher Server will serve this file with a 200 status code
|
|
41
|
-
// when the request doesn't match a known file, and the accept
|
|
42
|
-
// header includes text/html. You may use the '[public-dir]' token
|
|
43
|
-
// if you wish to specify this as a relative path from the 'public-dir'.
|
|
44
|
-
{ name: 'spa', type: String, },
|
|
45
|
-
// Path to a file to be used to serve as a 404 not found page.
|
|
46
|
-
// The Publisher Server will serve this file with a 404 status code
|
|
47
|
-
// when the request doesn't match a known file, and the accept
|
|
48
|
-
// header includes text/html. You may use the '[public-dir]' token
|
|
49
|
-
// if you wish to specify this as a relative path from the 'public-dir'.
|
|
50
|
-
{ name: 'not-found-page', type: String, },
|
|
51
|
-
// List of files to automatically use as index, for example, index.html,index.htm
|
|
52
|
-
// If a request comes in but the route does not exist, we check the route
|
|
53
|
-
// plus a slash plus the items in this array.
|
|
54
|
-
{ name: 'auto-index', type: String, multiple: true, },
|
|
55
|
-
// List of extensions to apply to a path name, for example, if
|
|
56
|
-
// http://example.com/about is requested, we can respond with http://example.com/about.html
|
|
57
|
-
{ name: 'auto-ext', type: String, multiple: true, },
|
|
58
|
-
// Components from fastly.toml
|
|
59
|
-
// Name of the application, to be inserted into fastly.toml
|
|
60
|
-
{ name: 'name', type: String, },
|
|
61
|
-
// Name of the author, to be inserted into fastly.toml
|
|
62
|
-
{ name: 'author', type: String, },
|
|
63
|
-
// Description of the application, to be inserted into fastly.toml
|
|
64
|
-
{ name: 'description', type: String, },
|
|
65
|
-
// Fastly Service ID to be added to the fastly.toml that is generated.
|
|
66
|
-
{ name: 'service-id', type: String },
|
|
67
|
-
// The name of a Fastly KV Store to hold the content assets.
|
|
68
|
-
// It must be linked to the service specified by `--service-id`.
|
|
69
|
-
{ name: 'kv-store-name', type: String },
|
|
70
|
-
// Clean KV Store mode
|
|
71
|
-
{ name: 'clean-kv-store', type: Boolean, },
|
|
72
|
-
];
|
|
73
|
-
const commandLineValues = commandLineArgs(optionDefinitions);
|
|
74
|
-
console.log("Fastly Compute JavaScript Static Publisher");
|
|
75
|
-
let mode = 'init-app';
|
|
76
|
-
if (commandLineValues['build-static']) {
|
|
77
|
-
mode = 'build-static';
|
|
78
|
-
}
|
|
79
|
-
else if (commandLineValues['clean-kv-store']) {
|
|
80
|
-
mode = 'clean-kv-store';
|
|
81
|
-
}
|
|
82
|
-
switch (mode) {
|
|
83
|
-
case 'build-static':
|
|
84
|
-
await buildStaticLoader(commandLineValues);
|
|
85
|
-
break;
|
|
86
|
-
case 'init-app':
|
|
87
|
-
initApp(commandLineValues);
|
|
88
|
-
break;
|
|
89
|
-
case 'clean-kv-store':
|
|
90
|
-
await cleanKVStore(commandLineValues);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Fastly, Inc.
|
|
4
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
5
|
+
*/
|
|
6
|
+
import { action } from './commands/index.js';
|
|
7
|
+
console.log("🧑💻 Fastly Compute JavaScript Static Publisher");
|
|
8
|
+
await action(process.argv);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type ModeAction = (argv: string[]) => void | Promise<void>;
|
|
2
|
+
export type ActionModule = {
|
|
3
|
+
action: ModeAction;
|
|
4
|
+
};
|
|
5
|
+
export declare function isHelpArgs(argv: string[]): boolean;
|
|
6
|
+
export declare function findMainCommandNameAndArgs(argv: string[]): [string | null, string[]];
|
|
7
|
+
export type CommandAndArgs<T> = {
|
|
8
|
+
needHelp: false;
|
|
9
|
+
command: T;
|
|
10
|
+
argv: string[];
|
|
11
|
+
} | {
|
|
12
|
+
needHelp: true;
|
|
13
|
+
command: string | null;
|
|
14
|
+
};
|
|
15
|
+
export declare function getCommandAndArgs<T extends string>(argv: string[], modes: T[]): CommandAndArgs<T>;
|
|
16
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/cli/util/args.ts"],"names":[],"mappings":"AAOA,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;AAElD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAQxC;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,CAAC,CAepF;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAC1B;IACA,QAAQ,EAAE,KAAK,CAAC;IAChB,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,GACC;IACA,QAAQ,EAAE,IAAI,CAAC;IACf,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CACA;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,IAAI,EAAE,MAAM,EAAE,EACd,KAAK,EAAE,CAAC,EAAE,GACT,cAAc,CAAC,CAAC,CAAC,CAiCnB"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
export function isHelpArgs(argv) {
|
|
7
|
+
const helpDefinitions = [
|
|
8
|
+
{ name: 'help', type: Boolean, },
|
|
9
|
+
];
|
|
10
|
+
const helpOptions = commandLineArgs(helpDefinitions, { argv, stopAtFirstUnknown: true });
|
|
11
|
+
return !!helpOptions['help'];
|
|
12
|
+
}
|
|
13
|
+
export function findMainCommandNameAndArgs(argv) {
|
|
14
|
+
const mainDefinitions = [
|
|
15
|
+
{ name: 'command', type: String, defaultOption: true },
|
|
16
|
+
];
|
|
17
|
+
const mainOptions = commandLineArgs(mainDefinitions, { argv, stopAtFirstUnknown: true });
|
|
18
|
+
const commandArgs = mainOptions._unknown || [];
|
|
19
|
+
const command = mainOptions['command'];
|
|
20
|
+
if (typeof command !== 'string') {
|
|
21
|
+
return [null, commandArgs];
|
|
22
|
+
}
|
|
23
|
+
return [command, commandArgs];
|
|
24
|
+
}
|
|
25
|
+
export function getCommandAndArgs(argv, modes) {
|
|
26
|
+
if (isHelpArgs(argv)) {
|
|
27
|
+
return {
|
|
28
|
+
needHelp: true,
|
|
29
|
+
command: null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const result = findMainCommandNameAndArgs(argv);
|
|
33
|
+
const [command, actionArgv] = result;
|
|
34
|
+
if (command != null) {
|
|
35
|
+
for (const modeName of modes) {
|
|
36
|
+
if (command === modeName) {
|
|
37
|
+
return {
|
|
38
|
+
needHelp: false,
|
|
39
|
+
command: command,
|
|
40
|
+
argv: actionArgv,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
commandLineArgs([], { argv: actionArgv });
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
console.log(String(err));
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
needHelp: true,
|
|
53
|
+
command,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PublishContentConfigNormalized } from '../../models/config/publish-content-config.js';
|
|
2
|
+
import { type PublisherServerConfigNormalized } from '../../models/config/publisher-server-config.js';
|
|
3
|
+
import { type StaticPublishRc } from '../../models/config/static-publish-rc.js';
|
|
4
|
+
export declare class LoadConfigError extends Error {
|
|
5
|
+
errors: string[];
|
|
6
|
+
constructor(configFilePath: string, errors: string[]);
|
|
7
|
+
}
|
|
8
|
+
export declare function loadStaticPublisherRcFile(): Promise<StaticPublishRc>;
|
|
9
|
+
export declare const normalizeStaticPublisherRc: (obj: unknown, errCtx?: string[]) => StaticPublishRc | null;
|
|
10
|
+
export declare function loadPublishContentConfigFile(configFile: string): Promise<PublishContentConfigNormalized>;
|
|
11
|
+
export declare const normalizePublishContentConfig: (obj: unknown, errCtx?: string[]) => PublishContentConfigNormalized | null;
|
|
12
|
+
export declare const normalizePublisherServerConfig: (obj: unknown, errCtx?: string[]) => PublisherServerConfigNormalized | null;
|
|
13
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/util/config.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,8BAA8B,EAEpC,MAAM,+CAA+C,CAAC;AAOvD,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gDAAgD,CAAC;AACtG,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAEhF,qBAAa,eAAgB,SAAQ,KAAK;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE;CAIrD;AAED,wBAAsB,yBAAyB,IAAI,OAAO,CAAC,eAAe,CAAC,CA2B1E;AAGD,eAAO,MAAM,0BAA0B,6DA2CrC,CAAC;AAEH,wBAAsB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAyB9G;AA4CD,eAAO,MAAM,6BAA6B,4EAuKxC,CAAC;AAEH,eAAO,MAAM,8BAA8B,6EAkIzC,CAAC"}
|