@fastly/compute-js-static-publish 8.0.0 → 8.0.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/DOCUMENTATION.md +1227 -0
- package/README.md +9 -2
- package/README.short.md +9 -2
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +8 -3
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +39 -18
- package/build/cli/cli/storage/kv-store-provider.d.ts +1 -1
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +8 -5
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +4 -2
- package/build/cli/cli/storage/storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.d.ts +2 -1
- package/build/cli/cli/util/api-token.d.ts.map +1 -1
- package/build/cli/cli/util/api-token.js +38 -3
- package/build/cli/cli/util/progress.d.ts +11 -0
- package/build/cli/cli/util/progress.d.ts.map +1 -0
- package/build/cli/cli/util/progress.js +32 -0
- package/build/cli/cli/util/purge.d.ts +9 -1
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +16 -8
- package/build/server/server/publisher-server/index.d.ts +1 -0
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +23 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -54,6 +54,12 @@ npm run fastly:deploy # deploy the app
|
|
|
54
54
|
npm run fastly:publish # upload your static files
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
`fastly:publish` needs a Fastly API token that can write to the KV Store. Set the `FASTLY_API_TOKEN` environment variable, or add `-- --fastly-api-token=<token>`. The command does not read the token of your Fastly CLI profile. If you are logged in with the Fastly CLI, you can give it that token:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
|
|
61
|
+
```
|
|
62
|
+
|
|
57
63
|
In the future, unless you have further changes to make to your app itself, you can
|
|
58
64
|
upload further updates to your static files:
|
|
59
65
|
```sh
|
|
@@ -61,7 +67,7 @@ cd compute-js
|
|
|
61
67
|
npm run fastly:publish # upload your static files
|
|
62
68
|
```
|
|
63
69
|
|
|
64
|
-
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
|
|
70
|
+
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates. After the deploy, `fastly.toml` has the service ID, so `s3:publish` also purges the service's cache. For this purge, set `FASTLY_API_TOKEN` too. Without it, `s3:publish` stops with an error before it uploads files.
|
|
65
71
|
|
|
66
72
|
## Features
|
|
67
73
|
|
|
@@ -72,7 +78,8 @@ If the app uses S3-compatible storage, your files are already in the bucket afte
|
|
|
72
78
|
|
|
73
79
|
## Documentation
|
|
74
80
|
|
|
75
|
-
📘
|
|
81
|
+
📘 This package includes the full documentation in [DOCUMENTATION.md](DOCUMENTATION.md), with the CLI reference for this version.
|
|
82
|
+
It is also available on GitHub:
|
|
76
83
|
[https://github.com/fastly/compute-js-static-publish/tree/main](https://github.com/fastly/compute-js-static-publish/tree/main)
|
|
77
84
|
|
|
78
85
|
### Security issues
|
package/README.short.md
CHANGED
|
@@ -54,6 +54,12 @@ npm run fastly:deploy # deploy the app
|
|
|
54
54
|
npm run fastly:publish # upload your static files
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
`fastly:publish` needs a Fastly API token that can write to the KV Store. Set the `FASTLY_API_TOKEN` environment variable, or add `-- --fastly-api-token=<token>`. The command does not read the token of your Fastly CLI profile. If you are logged in with the Fastly CLI, you can give it that token:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
|
|
61
|
+
```
|
|
62
|
+
|
|
57
63
|
In the future, unless you have further changes to make to your app itself, you can
|
|
58
64
|
upload further updates to your static files:
|
|
59
65
|
```sh
|
|
@@ -61,7 +67,7 @@ cd compute-js
|
|
|
61
67
|
npm run fastly:publish # upload your static files
|
|
62
68
|
```
|
|
63
69
|
|
|
64
|
-
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates.
|
|
70
|
+
If the app uses S3-compatible storage, your files are already in the bucket after `npm run s3:publish`. Run `npm run fastly:deploy` to deploy the app, and use `npm run s3:publish` to upload updates. After the deploy, `fastly.toml` has the service ID, so `s3:publish` also purges the service's cache. For this purge, set `FASTLY_API_TOKEN` too. Without it, `s3:publish` stops with an error before it uploads files.
|
|
65
71
|
|
|
66
72
|
## Features
|
|
67
73
|
|
|
@@ -72,7 +78,8 @@ If the app uses S3-compatible storage, your files are already in the bucket afte
|
|
|
72
78
|
|
|
73
79
|
## Documentation
|
|
74
80
|
|
|
75
|
-
📘
|
|
81
|
+
📘 This package includes the full documentation in [DOCUMENTATION.md](DOCUMENTATION.md), with the CLI reference for this version.
|
|
82
|
+
It is also available on GitHub:
|
|
76
83
|
[https://github.com/fastly/compute-js-static-publish/tree/main](https://github.com/fastly/compute-js-static-publish/tree/main)
|
|
77
84
|
|
|
78
85
|
### Security issues
|
|
@@ -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":"AA8HA,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBA4jBhD"}
|
|
@@ -13,6 +13,7 @@ import { applyDefaults } from '../../util/data.js';
|
|
|
13
13
|
import { calculateFileSizeAndHash, enumerateFiles, rootRelative } from '../../util/files.js';
|
|
14
14
|
import { ensureVariantFileExists, OncePerKey } from '../../util/variants.js';
|
|
15
15
|
import { concurrentMap } from '../../util/retryable.js';
|
|
16
|
+
import { ProgressLog } from '../../util/progress.js';
|
|
16
17
|
import { loadPurgeTarget, purgeCollection } from '../../util/purge.js';
|
|
17
18
|
import { getStorageKeysByHexPrefix, loadStorageProviderFromStaticPublishRc, StorageProviderBatch, } from '../../storage/storage-provider.js';
|
|
18
19
|
// Storage key format:
|
|
@@ -94,6 +95,9 @@ S3 Storage Options (BETA):
|
|
|
94
95
|
Default: 64
|
|
95
96
|
|
|
96
97
|
Global Options:
|
|
98
|
+
--verbose Verbose mode. Logs each file and each upload.
|
|
99
|
+
Without this, the log shows the progress after
|
|
100
|
+
each 1000 files or uploads.
|
|
97
101
|
-h, --help Show this help message and exit.
|
|
98
102
|
|
|
99
103
|
Examples:
|
|
@@ -105,7 +109,7 @@ Examples:
|
|
|
105
109
|
}
|
|
106
110
|
export async function action(actionArgs) {
|
|
107
111
|
const optionDefinitions = [
|
|
108
|
-
{ name: 'verbose', type: Boolean },
|
|
112
|
+
{ name: 'verbose', type: Boolean, defaultValue: false },
|
|
109
113
|
{ name: 'config', type: String },
|
|
110
114
|
{ name: 'collection-name', type: String, },
|
|
111
115
|
{ name: 'root-dir', type: String, },
|
|
@@ -338,6 +342,7 @@ export async function action(actionArgs) {
|
|
|
338
342
|
return true;
|
|
339
343
|
}
|
|
340
344
|
// #### Iterate files
|
|
345
|
+
const scanProgress = new ProgressLog('Files scanned', verbose);
|
|
341
346
|
const fileResults = await concurrentMap(files, async (file) => {
|
|
342
347
|
// #### asset key
|
|
343
348
|
const assetKey = file.slice(publicDirRoot.length)
|
|
@@ -371,7 +376,7 @@ export async function action(actionArgs) {
|
|
|
371
376
|
}
|
|
372
377
|
// #### Base file size, hash, last modified time
|
|
373
378
|
const { size: baseSize, hash: baseHash } = await calculateFileSizeAndHash(file);
|
|
374
|
-
|
|
379
|
+
scanProgress.add(1, () => `📄 File '${rootRelative(file)}' - ${baseSize} bytes, sha256: ${baseHash}`);
|
|
375
380
|
const stats = fs.statSync(file);
|
|
376
381
|
const lastModifiedTime = Math.floor((stats.mtime).getTime() / 1000);
|
|
377
382
|
// We know the number of chunks of the original before we read it. For a
|
|
@@ -479,7 +484,7 @@ export async function action(actionArgs) {
|
|
|
479
484
|
else {
|
|
480
485
|
console.log(` | ${batch.storageProviderBatchEntries.length} variant(s) to upload.`);
|
|
481
486
|
}
|
|
482
|
-
await storageProvider.applyBatch(batch, { existingKeys });
|
|
487
|
+
await storageProvider.applyBatch(batch, { existingKeys, verbose });
|
|
483
488
|
// #### INDEX FILE
|
|
484
489
|
console.log(`🗂️ Saving Index...`);
|
|
485
490
|
const indexFileKey = `${publishId}_index_${collectionName}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/cli/commands/scaffold/index.ts"],"names":[],"mappings":"AAwEA,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AA0TF,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,iBAktBhD"}
|
|
@@ -52,8 +52,9 @@ Compute Service Metadata:
|
|
|
52
52
|
Server Config:
|
|
53
53
|
--public-dir <path> Deprecated. Base dir for content (default: root-dir)
|
|
54
54
|
--static-dir <path>,<path...> Directory served with long TTL (can repeat)
|
|
55
|
-
--spa <file> SPA fallback file (e.g., /index.html)
|
|
56
|
-
--not-found-page <file> 404 fallback file (e.g., /404.html)
|
|
55
|
+
--spa <file> SPA fallback file, under --root-dir (e.g., ./public/index.html)
|
|
56
|
+
--not-found-page <file> 404 fallback file, under --root-dir (e.g., ./public/404.html)
|
|
57
|
+
(default: 404.html in --root-dir, if the file exists)
|
|
57
58
|
--auto-index <name>,<name...> Index filename (e.g., index.html,index.htm)
|
|
58
59
|
--auto-ext <ext>,<ext...> Automatic extensions (e.g., .html,.htm)
|
|
59
60
|
|
|
@@ -69,7 +70,7 @@ const defaultOptions = {
|
|
|
69
70
|
staticDirs: [],
|
|
70
71
|
staticPublisherWorkingDir: undefined,
|
|
71
72
|
spa: undefined,
|
|
72
|
-
notFoundPage:
|
|
73
|
+
notFoundPage: undefined,
|
|
73
74
|
autoIndex: ['index.html', 'index.htm'],
|
|
74
75
|
autoExt: ['.html', '.htm'],
|
|
75
76
|
author: 'you@example.com',
|
|
@@ -502,14 +503,17 @@ export async function action(actionArgs) {
|
|
|
502
503
|
spaFilename = processPublicDirToken(SPA, publicDir);
|
|
503
504
|
// At any rate it must exist under the root directory
|
|
504
505
|
if (!spaFilename.startsWith(rootDir)) {
|
|
505
|
-
console.
|
|
506
|
-
console.
|
|
507
|
-
|
|
506
|
+
console.error(`❌ Specified SPA file '${SPA}' is not under the asset root directory.`);
|
|
507
|
+
console.error(` * ${rootRelative(spaFilename)} must be under ${rootRelative(rootDir)}`);
|
|
508
|
+
console.error(` Give the path from the current directory, for example ${rootRelative(rootDir)}/index.html.`);
|
|
509
|
+
process.exitCode = 1;
|
|
510
|
+
return;
|
|
508
511
|
}
|
|
509
|
-
|
|
510
|
-
console.
|
|
511
|
-
console.
|
|
512
|
-
|
|
512
|
+
if (!fs.existsSync(spaFilename)) {
|
|
513
|
+
console.error(`❌ Specified SPA file '${SPA}' does not exist.`);
|
|
514
|
+
console.error(` * ${rootRelative(spaFilename)} does not exist.`);
|
|
515
|
+
process.exitCode = 1;
|
|
516
|
+
return;
|
|
513
517
|
}
|
|
514
518
|
}
|
|
515
519
|
const NOT_FOUND_PAGE = options.notFoundPage;
|
|
@@ -519,14 +523,24 @@ export async function action(actionArgs) {
|
|
|
519
523
|
notFoundPageFilename = processPublicDirToken(NOT_FOUND_PAGE, publicDir);
|
|
520
524
|
// At any rate it must exist under the root directory
|
|
521
525
|
if (!notFoundPageFilename.startsWith(rootDir)) {
|
|
522
|
-
console.
|
|
523
|
-
console.
|
|
524
|
-
|
|
526
|
+
console.error(`❌ Specified Not Found file '${NOT_FOUND_PAGE}' is not under the asset root directory.`);
|
|
527
|
+
console.error(` * ${rootRelative(notFoundPageFilename)} must be under ${rootRelative(rootDir)}`);
|
|
528
|
+
console.error(` Give the path from the current directory, for example ${rootRelative(rootDir)}/404.html.`);
|
|
529
|
+
process.exitCode = 1;
|
|
530
|
+
return;
|
|
525
531
|
}
|
|
526
|
-
|
|
527
|
-
console.
|
|
528
|
-
console.
|
|
529
|
-
|
|
532
|
+
if (!fs.existsSync(notFoundPageFilename)) {
|
|
533
|
+
console.error(`❌ Specified Not Found file '${NOT_FOUND_PAGE}' does not exist.`);
|
|
534
|
+
console.error(` * ${rootRelative(notFoundPageFilename)} does not exist.`);
|
|
535
|
+
process.exitCode = 1;
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
// Without --not-found-page, use 404.html in the public directory if it exists.
|
|
541
|
+
const defaultNotFoundPageFilename = processPublicDirToken('[public-dir]/404.html', publicDir);
|
|
542
|
+
if (fs.existsSync(defaultNotFoundPageFilename)) {
|
|
543
|
+
notFoundPageFilename = defaultNotFoundPageFilename;
|
|
530
544
|
}
|
|
531
545
|
}
|
|
532
546
|
const autoIndex = options.autoIndex;
|
|
@@ -923,7 +937,11 @@ To build and deploy to your Compute service:
|
|
|
923
937
|
|
|
924
938
|
cd ${COMPUTE_JS_DIR}
|
|
925
939
|
npm run fastly:deploy
|
|
926
|
-
npm run fastly:publish
|
|
940
|
+
FASTLY_API_TOKEN=xxxx npm run fastly:publish
|
|
941
|
+
|
|
942
|
+
fastly:publish reads the API token only from FASTLY_API_TOKEN or --fastly-api-token,
|
|
943
|
+
not from your Fastly CLI profile. To use the token of the Fastly CLI, type:
|
|
944
|
+
FASTLY_API_TOKEN=$(npx fastly auth token) npm run fastly:publish
|
|
927
945
|
|
|
928
946
|
`);
|
|
929
947
|
}
|
|
@@ -971,6 +989,9 @@ To build and deploy to your Compute service:
|
|
|
971
989
|
a different name, the Fastly CLI uses it for the resource link too. Then call
|
|
972
990
|
setSecretStoreForS3Credentials() with that name in src/index.js, and deploy again.
|
|
973
991
|
|
|
992
|
+
After the deploy, fastly.toml has the service ID, so s3:publish also purges the
|
|
993
|
+
service's cache. For this purge, s3:publish needs FASTLY_API_TOKEN too.
|
|
994
|
+
|
|
974
995
|
`);
|
|
975
996
|
}
|
|
976
997
|
}
|
|
@@ -12,7 +12,7 @@ export declare class KvStoreProvider implements StorageProvider {
|
|
|
12
12
|
submitStorageEntry(key: string, _filePath: string, data: ReadableStream<Uint8Array> | Uint8Array | string | null | undefined, metadata?: Record<string, string>): Promise<void>;
|
|
13
13
|
deleteStorageEntry(key: string): Promise<void>;
|
|
14
14
|
applyBatch(batch: StorageProviderBatch, options?: ApplyBatchOptions): Promise<void>;
|
|
15
|
-
uploadEntries(entries: StorageProviderBatchEntry[]): Promise<void>;
|
|
15
|
+
uploadEntries(entries: StorageProviderBatchEntry[], verbose?: boolean): Promise<void>;
|
|
16
16
|
doConcurrentParallel<TObject extends {
|
|
17
17
|
key: string;
|
|
18
18
|
}>(objects: TObject[], fn: (obj: TObject, key: string, index: number) => Promise<void>, maxConcurrent?: number, throwOnError?: boolean): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"kv-store-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/kv-store-provider.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,gBAAgB,EAGtB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACL,KAAK,gBAAgB,EAMtB,MAAM,qBAAqB,CAAC;AAY7B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,kBAAkB,EAAE,sBAsBhC,CAAC;AAEF,qBAAa,eAAgB,YAAW,eAAe;gBAEnD,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM;IAMxB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC;IAEd,c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"}
|
|
@@ -7,6 +7,7 @@ import { isKvStoreConfigRc, } from '../../models/config/static-publish-rc.js';
|
|
|
7
7
|
import { getKvStoreConfigFromRc, } from '../../models/config/kv-store-config.js';
|
|
8
8
|
import { FetchError, loadApiToken, } from '../util/api-token.js';
|
|
9
9
|
import { rootRelative, } from '../util/files.js';
|
|
10
|
+
import { ProgressLog } from '../util/progress.js';
|
|
10
11
|
import { getKvStoreEntry, getKVStoreKeys, kvStoreDeleteEntry, kvStoreSubmitEntry, kvStoreSubmitBatch, } from '../util/kv-store.js';
|
|
11
12
|
import { applyKVStoreEntriesChunks, packNdjsonBatches, ndjsonLineForBatchEntry, entriesToUpload, KV_STORE_CHUNK_SIZE, } from '../util/kv-store-items.js';
|
|
12
13
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
@@ -55,7 +56,7 @@ export class KvStoreProvider {
|
|
|
55
56
|
await kvStoreDeleteEntry(this.fastlyApiContext, this.kvStoreName, key);
|
|
56
57
|
}
|
|
57
58
|
async applyBatch(batch, options = {}) {
|
|
58
|
-
const { existingKeys } = options;
|
|
59
|
+
const { existingKeys, verbose = false } = options;
|
|
59
60
|
console.log(`🍪 Chunking large files...`);
|
|
60
61
|
await applyKVStoreEntriesChunks(batch.storageProviderBatchEntries, KV_STORE_CHUNK_SIZE);
|
|
61
62
|
console.log(`✅ Large files have been chunked.`);
|
|
@@ -65,15 +66,16 @@ export class KvStoreProvider {
|
|
|
65
66
|
console.log(` | ${batch.storageProviderBatchEntries.length - toWrite.length} chunk(s) already present in the KV Store.`);
|
|
66
67
|
}
|
|
67
68
|
console.log(`📤 Uploading ${toWrite.length} entries to KV Store.`);
|
|
68
|
-
await this.uploadEntries(toWrite);
|
|
69
|
+
await this.uploadEntries(toWrite, verbose);
|
|
69
70
|
console.log(`✅ Uploaded entries to KV Store.`);
|
|
70
71
|
}
|
|
71
|
-
async uploadEntries(entries) {
|
|
72
|
+
async uploadEntries(entries, verbose = false) {
|
|
72
73
|
const { batches, oversized } = packNdjsonBatches(entries);
|
|
74
|
+
const progress = new ProgressLog('Entries uploaded', verbose, entries.length);
|
|
73
75
|
await this.doConcurrentParallel(oversized, async ({ filePath, metadataJson }, key) => {
|
|
74
76
|
const fileBytes = fs.readFileSync(filePath);
|
|
75
77
|
await kvStoreSubmitEntry(this.fastlyApiContext, this.kvStoreName, key, fileBytes, metadataJson != null ? JSON.stringify(metadataJson) : undefined);
|
|
76
|
-
|
|
78
|
+
progress.add(1, () => ` 🌐 Submitted large asset "${rootRelative(filePath)}" to KV Store with key "${key}".`);
|
|
77
79
|
}, 12, true);
|
|
78
80
|
await this.doConcurrentParallel(batches, async (batch, key) => {
|
|
79
81
|
const lines = batch.entries.map(ndjsonLineForBatchEntry);
|
|
@@ -82,12 +84,13 @@ export class KvStoreProvider {
|
|
|
82
84
|
// Keep only the entries that failed. The retry submits only these entries.
|
|
83
85
|
const failedKeys = new Set(failures.map(f => f.key));
|
|
84
86
|
const submittedCount = batch.entries.length;
|
|
87
|
+
progress.add(submittedCount - failures.length, () => ` 🌐 Submitted ${submittedCount - failures.length} of ${submittedCount} entries to KV Store ("${key}").`);
|
|
85
88
|
batch.entries = batch.entries.filter(entry => failedKeys.has(entry.key));
|
|
86
89
|
const shown = failures.slice(0, 5).map(f => `${f.key} (${f.code ?? 'unknown'}: ${f.reason ?? 'unknown'})`).join(', ');
|
|
87
90
|
const more = failures.length > 5 ? `, and ${failures.length - 5} more` : '';
|
|
88
91
|
throw makeRetryable(new Error(`${failures.length} of ${submittedCount} entries failed: ${shown}${more}`));
|
|
89
92
|
}
|
|
90
|
-
|
|
93
|
+
progress.add(batch.entries.length, () => ` 🌐 Submitted ${batch.entries.length} entries to KV Store ("${key}").`);
|
|
91
94
|
}, 12, true);
|
|
92
95
|
}
|
|
93
96
|
async doConcurrentParallel(objects, fn, maxConcurrent = 12, throwOnError = false) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"s3-storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/s3-storage-provider.ts"],"names":[],"mappings":"AAQA,OAAO,EAUL,QAAQ,EAIT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AASxB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,uBAAuB,CAAC;AAc/B,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAKnF,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,eAAO,MAAM,mBAAmB,wHAAwH,CAAC;AAEzJ,eAAO,MAAM,kBAAkB,EAAE,sBAyChC,CAAC;AAGF,qBAAa,iBAAkB,YAAW,eAAe;gBAErD,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EACnB,iBAAiB,GAAE,MAAsC;IAU3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAA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EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EAC/D,aAAa,GAAE,MAAW,EAC1B,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,IAAI,CAAC;IAmBhB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAI1C"}
|
|
@@ -12,6 +12,7 @@ import { entriesToUpload } from '../util/kv-store-items.js';
|
|
|
12
12
|
import { loadS3Credentials, } from '../util/s3-credentials.js';
|
|
13
13
|
import { concurrentParallel, makeRetryable, } from '../util/retryable.js';
|
|
14
14
|
import { rootRelative, } from '../util/files.js';
|
|
15
|
+
import { ProgressLog } from '../util/progress.js';
|
|
15
16
|
// The number of objects to upload at the same time. S3 accepts many parallel
|
|
16
17
|
// requests, and each request mostly waits for the network. In a test with small
|
|
17
18
|
// objects, 64 was approximately 4 times faster than 12.
|
|
@@ -177,17 +178,18 @@ export class S3StorageProvider {
|
|
|
177
178
|
await this.sendS3ClientCommand(command);
|
|
178
179
|
}
|
|
179
180
|
async applyBatch(batch, options = {}) {
|
|
180
|
-
const { existingKeys } = options;
|
|
181
|
+
const { existingKeys, verbose = false } = options;
|
|
181
182
|
let toWrite = batch.storageProviderBatchEntries;
|
|
182
183
|
if (existingKeys != null) {
|
|
183
184
|
toWrite = entriesToUpload(toWrite, existingKeys);
|
|
184
185
|
}
|
|
185
186
|
console.log(`📤 Uploading ${toWrite.length} entries to S3 storage (${this.uploadConcurrency} at a time).`);
|
|
187
|
+
const progress = new ProgressLog('Entries uploaded', verbose, toWrite.length);
|
|
186
188
|
await this.doConcurrentParallel(toWrite, async ({ filePath, metadataJson }, key) => {
|
|
187
189
|
// const fileStream = fs.createReadStream(filePath);
|
|
188
190
|
const fileData = fs.readFileSync(filePath);
|
|
189
191
|
await this.submitStorageEntry(key, filePath, fileData, metadataJson);
|
|
190
|
-
|
|
192
|
+
progress.add(1, () => ` 🌐 Submitted asset "${rootRelative(filePath)}" to S3 storage with key "${key}".`);
|
|
191
193
|
}, this.uploadConcurrency, true);
|
|
192
194
|
console.log(`✅ Uploaded entries to S3 storage.`);
|
|
193
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-provider.d.ts","sourceRoot":"","sources":["../../../../src/cli/storage/storage-provider.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,eAAe,EACrB,MAAM,0CAA0C,CAAC;AAElD,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1D,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/D,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC3D,kBAAkB,CAChB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACzE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,UAAU,CAAC,KAAK,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,O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IAG3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,qBAAa,oBAAoB;;IAI/B,2BAA2B,EAAE,yBAAyB,EAAE,CAAC;IACzD,GAAG,CAAC,KAAK,EAAE,yBAAyB;CAGrC;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,sBAAsB,GAChC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,GAAG,eAAe,GAAG,IAAI,CAAC,CAAC;AAQlI,wBAAsB,yBAAyB,CAAC,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAQ1H;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,sBAAsB,QAE7E;AAED,wBAAsB,sCAAsC,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,6BAA6B,4BAS3H"}
|
|
@@ -10,8 +10,9 @@ export type LoadApiParams = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare function loadApiToken(params: LoadApiParams): LoadApiTokenResult | null;
|
|
12
12
|
export declare class FetchError extends Error {
|
|
13
|
-
constructor(message: string, status: number);
|
|
13
|
+
constructor(message: string, status: number, detail?: string);
|
|
14
14
|
status: number;
|
|
15
|
+
detail?: string;
|
|
15
16
|
}
|
|
16
17
|
export declare function callFastlyApi(fastlyApiContext: FastlyApiContext, endpoint: string, operationName: string, queryParams?: URLSearchParams | null, requestInit?: RequestInit): Promise<Response>;
|
|
17
18
|
//# sourceMappingURL=api-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"api-token.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/api-token.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,kBAAkB,GAAG,IAAI,CAyB7E;AAaD,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAM5D,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAWD,wBAAsB,aAAa,CACjC,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,eAAe,GAAG,IAAI,EACpC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,QAAQ,CAAC,CAuCnB"}
|
|
@@ -34,10 +34,11 @@ const RETRYABLE_STATUS_CODES = [
|
|
|
34
34
|
504, // Gateway Timeout
|
|
35
35
|
];
|
|
36
36
|
export class FetchError extends Error {
|
|
37
|
-
constructor(message, status) {
|
|
37
|
+
constructor(message, status, detail) {
|
|
38
38
|
super(message);
|
|
39
39
|
this.name = 'FetchError';
|
|
40
40
|
this.status = status;
|
|
41
|
+
this.detail = detail;
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
function isReadableStream(data) {
|
|
@@ -74,10 +75,44 @@ export async function callFastlyApi(fastlyApiContext, endpoint, operationName, q
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
if (!response.ok) {
|
|
78
|
+
const detail = await readApiErrorDetail(response);
|
|
79
|
+
const status = `${response.status}${detail != null ? ` ${detail}` : ''}`;
|
|
77
80
|
if (!RETRYABLE_STATUS_CODES.includes(response.status)) {
|
|
78
|
-
throw new FetchError(`${operationName} failed: ${
|
|
81
|
+
throw new FetchError(`${operationName} failed: ${status}`, response.status, detail);
|
|
79
82
|
}
|
|
80
|
-
throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${
|
|
83
|
+
throw makeRetryable(new FetchError(`Retryable ${operationName} error: ${status}`, response.status, detail));
|
|
81
84
|
}
|
|
82
85
|
return response;
|
|
83
86
|
}
|
|
87
|
+
// The Content-Type of an error response tells which fields describe the error:
|
|
88
|
+
// - application/json: the Fastly API fields msg and detail, for example
|
|
89
|
+
// {"msg":"Record not found","detail":"Cannot find service"}.
|
|
90
|
+
// - application/problem+json (RFC 9457): the fields title and detail.
|
|
91
|
+
// - Other types, or JSON that is not valid: the start of the text.
|
|
92
|
+
async function readApiErrorDetail(response) {
|
|
93
|
+
let text;
|
|
94
|
+
try {
|
|
95
|
+
text = (await response.text()).trim();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const mediaType = response.headers.get('content-type')?.split(';')[0].trim().toLowerCase();
|
|
101
|
+
const fields = mediaType === 'application/json' ? ['msg', 'detail'] :
|
|
102
|
+
mediaType === 'application/problem+json' ? ['title', 'detail'] :
|
|
103
|
+
null;
|
|
104
|
+
if (fields != null) {
|
|
105
|
+
let json;
|
|
106
|
+
try {
|
|
107
|
+
json = JSON.parse(text);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
json = undefined;
|
|
111
|
+
}
|
|
112
|
+
if (json !== undefined) {
|
|
113
|
+
const parts = fields.map(field => json?.[field]).filter(x => typeof x === 'string' && x !== '');
|
|
114
|
+
return parts.length > 0 ? parts.join(': ') : undefined;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return text !== '' ? text.slice(0, 200) : undefined;
|
|
118
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const PROGRESS_INTERVAL = 1000;
|
|
2
|
+
export declare class ProgressLog {
|
|
3
|
+
private readonly label;
|
|
4
|
+
private readonly verbose;
|
|
5
|
+
private readonly total?;
|
|
6
|
+
private done;
|
|
7
|
+
private nextReport;
|
|
8
|
+
constructor(label: string, verbose: boolean, total?: number | undefined);
|
|
9
|
+
add(count: number, message: () => string): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/progress.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAKtC,qBAAa,WAAW;IAKpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IANzB,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,UAAU,CAAqB;gBAGpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,KAAK,CAAC,EAAE,MAAM,YAAA;IAIjC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM;CAczC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
export const PROGRESS_INTERVAL = 1000;
|
|
6
|
+
// Logs the progress of a loop over many items. With verbose, it logs a line
|
|
7
|
+
// for each call. Else, it logs one line each time the count passes another
|
|
8
|
+
// PROGRESS_INTERVAL items, so that a large site does not make a large log.
|
|
9
|
+
export class ProgressLog {
|
|
10
|
+
constructor(label, verbose, total) {
|
|
11
|
+
this.label = label;
|
|
12
|
+
this.verbose = verbose;
|
|
13
|
+
this.total = total;
|
|
14
|
+
this.done = 0;
|
|
15
|
+
this.nextReport = PROGRESS_INTERVAL;
|
|
16
|
+
}
|
|
17
|
+
// Records count items. The message is made only if it is logged.
|
|
18
|
+
add(count, message) {
|
|
19
|
+
this.done += count;
|
|
20
|
+
if (this.verbose) {
|
|
21
|
+
console.log(message());
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (this.done < this.nextReport || (this.total != null && this.done >= this.total)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
console.log(` | ${this.label}: ${this.done}${this.total != null ? ` of ${this.total}` : ''}`);
|
|
28
|
+
while (this.nextReport <= this.done) {
|
|
29
|
+
this.nextReport += PROGRESS_INTERVAL;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -15,6 +15,14 @@ export type LoadPurgeTargetParams = {
|
|
|
15
15
|
purgeEnvironments: unknown;
|
|
16
16
|
};
|
|
17
17
|
export declare function loadPurgeTarget(params: LoadPurgeTargetParams): PurgeTarget | null;
|
|
18
|
-
export
|
|
18
|
+
export type PurgeOutcome = {
|
|
19
|
+
result: 'purged';
|
|
20
|
+
} | {
|
|
21
|
+
result: 'not-staged';
|
|
22
|
+
} | {
|
|
23
|
+
result: 'failed';
|
|
24
|
+
reason: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function purgeSurrogateKey(fastlyApiContext: FastlyApiContext, fastlyServiceId: string, surrogateKey: string, softPurge?: boolean, environment?: PurgeEnvironment): Promise<PurgeOutcome>;
|
|
19
27
|
export declare function purgeCollection(purgeTarget: PurgeTarget, publishId: string, collectionName: string): Promise<void>;
|
|
20
28
|
//# sourceMappingURL=purge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"purge.d.ts","sourceRoot":"","sources":["../../../../src/cli/util/purge.ts"],"names":[],"mappings":"AAOA,OAAO,EAAiB,KAAK,gBAAgB,EAA4B,MAAM,gBAAgB,CAAC;AAGhG,eAAO,MAAM,iBAAiB,oCAAuC,CAAC;AACtE,MAAM,MAAM,gBAAgB,GAAG,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAIhE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAkB1E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAMF,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,WAAW,GAAG,IAAI,CAgCjF;
|
|
1
|
+
{"version":3,"file":"purge.d.ts","sourceRoot":"","sources":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Key(fastlyApiContext, fastlyServiceId, surro
|
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
77
|
if (err instanceof FetchError) {
|
|
78
|
-
|
|
78
|
+
if (environment === 'staging' && err.status === 404) {
|
|
79
|
+
return { result: 'not-staged' };
|
|
80
|
+
}
|
|
81
|
+
return { result: 'failed', reason: `${err.status}${err.detail != null ? ` ${err.detail}` : ''}` };
|
|
79
82
|
}
|
|
80
83
|
throw err;
|
|
81
84
|
}
|
|
82
|
-
return
|
|
85
|
+
return { result: 'purged' };
|
|
83
86
|
}
|
|
84
87
|
// Purges the cached responses of a collection in each environment of the purge
|
|
85
88
|
// target. A failed purge is a warning, because the change to storage is done.
|
|
@@ -87,12 +90,17 @@ export async function purgeCollection(purgeTarget, publishId, collectionName) {
|
|
|
87
90
|
const surrogateKey = `${publishId}-${collectionName}`;
|
|
88
91
|
for (const environment of purgeTarget.environments) {
|
|
89
92
|
console.log(`Purging surrogate key [${surrogateKey}] on service [${purgeTarget.serviceId}] (${environment})...`);
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const outcome = await purgeSurrogateKey(purgeTarget.fastlyApiContext, purgeTarget.serviceId, surrogateKey, true, environment);
|
|
94
|
+
switch (outcome.result) {
|
|
95
|
+
case 'purged':
|
|
96
|
+
console.log('Purged');
|
|
97
|
+
break;
|
|
98
|
+
case 'not-staged':
|
|
99
|
+
console.log(`Nothing purged (${environment}): the service has no staged version, or the service ID is not correct.`);
|
|
100
|
+
break;
|
|
101
|
+
case 'failed':
|
|
102
|
+
console.warn(`⚠️ Warning: Failed purging (${environment}): ${outcome.reason}. Cached copies may be served until they expire.`);
|
|
103
|
+
break;
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
}
|
|
@@ -27,6 +27,7 @@ export declare class PublisherServer {
|
|
|
27
27
|
responseCache: ResponseCacheOptions | null;
|
|
28
28
|
settingsCached: PublisherServerConfigNormalized | null | undefined;
|
|
29
29
|
assetEntryMapCache: AssetEntryMap | null | undefined;
|
|
30
|
+
doNotStoreResponse: boolean;
|
|
30
31
|
setActiveCollectionName(collectionName: string | null): void;
|
|
31
32
|
setCollectionNameHeader(collectionHeader: string | null): void;
|
|
32
33
|
setServerTimingRequestHeader(requestHeader: string | null): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/index.ts"],"names":[],"mappings":"AASA,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,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EAErB,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAEL,KAAK,oBAAoB,EAS1B,MAAM,qBAAqB,CAAC;AAG7B,KAAK,YAAY,GAAG;IAClB,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,oBAAoB,CAAC;AAEzB,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,eAAe,EAAE,eAAe,EAChC,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