@fastly/compute-js-static-publish 8.0.0 → 8.0.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/CHANGELOG.md +544 -0
- package/DOCUMENTATION.md +1243 -0
- package/MIGRATING.md +128 -0
- package/README.md +9 -2
- package/README.short.md +9 -2
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +43 -4
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +13 -16
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +51 -31
- package/build/cli/cli/storage/kv-store-local-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-local-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-local-provider.js +4 -1
- package/build/cli/cli/storage/kv-store-provider.d.ts +2 -1
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +17 -6
- package/build/cli/cli/storage/s3-storage-provider.d.ts +1 -0
- package/build/cli/cli/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/s3-storage-provider.js +8 -2
- package/build/cli/cli/storage/storage-provider.d.ts +4 -0
- package/build/cli/cli/storage/storage-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/storage-provider.js +32 -0
- 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/kv-store-items.d.ts +1 -0
- package/build/cli/cli/util/kv-store-items.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-items.js +16 -40
- 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/cli/cli/util/s3.d.ts +10 -4
- package/build/cli/cli/util/s3.d.ts.map +1 -1
- package/build/cli/cli/util/s3.js +13 -35
- package/build/server/server/publisher-server/accept-html.d.ts +2 -0
- package/build/server/server/publisher-server/accept-html.d.ts.map +1 -0
- package/build/server/server/publisher-server/accept-html.js +50 -0
- 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 +31 -13
- package/build/server/server/publisher-server/response-cache.d.ts +3 -0
- package/build/server/server/publisher-server/response-cache.d.ts.map +1 -1
- package/build/server/server/publisher-server/response-cache.js +24 -1
- package/package.json +6 -3
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// Returns true if the request accepts a text/html response.
|
|
6
|
+
// https://httpwg.org/specs/rfc9110.html#field.accept
|
|
7
|
+
// * A missing or empty Accept header accepts all media types.
|
|
8
|
+
// * The most specific media range that matches text/html gives the q-value:
|
|
9
|
+
// text/html, then text/*, then */*. A q-value of 0 means "not acceptable".
|
|
10
|
+
// * The media type parameters other than q are ignored.
|
|
11
|
+
// * A bare '*' is the same as '*/*'.
|
|
12
|
+
export function requestAcceptsTextHtml(request) {
|
|
13
|
+
const header = (request.headers.get('Accept') ?? '').trim();
|
|
14
|
+
if (header === '') {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
// The highest q-value for each media range that matches text/html
|
|
18
|
+
let htmlQValue = null;
|
|
19
|
+
let textQValue = null;
|
|
20
|
+
let anyQValue = null;
|
|
21
|
+
for (const item of header.split(',')) {
|
|
22
|
+
const [rangeStr, ...paramStrs] = item.split(';');
|
|
23
|
+
const range = rangeStr.trim().toLowerCase();
|
|
24
|
+
if (range === '') {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
let qValue = 1;
|
|
28
|
+
for (const paramStr of paramStrs) {
|
|
29
|
+
const [name, value] = paramStr.split('=');
|
|
30
|
+
if (name.trim().toLowerCase() !== 'q' || value == null) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const parsed = parseFloat(value.trim());
|
|
34
|
+
if (!Number.isNaN(parsed)) {
|
|
35
|
+
qValue = Math.min(Math.max(parsed, 0), 1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (range === 'text/html') {
|
|
39
|
+
htmlQValue = Math.max(htmlQValue ?? 0, qValue);
|
|
40
|
+
}
|
|
41
|
+
else if (range === 'text/*') {
|
|
42
|
+
textQValue = Math.max(textQValue ?? 0, qValue);
|
|
43
|
+
}
|
|
44
|
+
else if (range === '*/*' || range === '*') {
|
|
45
|
+
anyQValue = Math.max(anyQValue ?? 0, qValue);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const qValue = htmlQValue ?? textQValue ?? anyQValue;
|
|
49
|
+
return qValue != null && qValue > 0;
|
|
50
|
+
}
|
|
@@ -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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AG,IAAI;IAMnG,OAAO,CAAC,kCAAkC;IA6D7B,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;YA8BzG,wCAAwC;IAyChD,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC;IAmEpF,WAAW,CACf,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GACtD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA4G3B,OAAO,CAAC,iBAAiB;IA4BnB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;YAsBhD,uBAAuB;CA6EtC"}
|
|
@@ -11,7 +11,8 @@ import { loadStorageProviderFromStaticPublishRc, } from '../storage/storage-prov
|
|
|
11
11
|
import { checkIfModifiedSince, getIfModifiedSinceHeader } from './serve-preconditions/if-modified-since.js';
|
|
12
12
|
import { checkIfNoneMatch, getIfNoneMatchHeader } from './serve-preconditions/if-none-match.js';
|
|
13
13
|
import { ServerTiming } from '../util/server-timing.js';
|
|
14
|
-
import {
|
|
14
|
+
import { requestAcceptsTextHtml } from './accept-html.js';
|
|
15
|
+
import { CACHEABLE_STATUSES, DEFAULT_MAX_BODY_SIZE, buildCacheFillRequest, buildResponseCacheKey, bytesInPieces, decodeCachedResponseMetadata, encodeCachedResponseMetadata, parseAcceptEncodingGroups, readBodyUpTo, streamBytesInPieces, } from './response-cache.js';
|
|
15
16
|
import { checkBodyLength } from '../util/body-length.js';
|
|
16
17
|
export function buildHeadersSubset(responseHeaders, keys) {
|
|
17
18
|
const resultHeaders = new Headers();
|
|
@@ -31,17 +32,10 @@ export function buildHeadersSubset(responseHeaders, keys) {
|
|
|
31
32
|
// * Content-Location, Date, ETag, and Vary
|
|
32
33
|
// * Cache-Control and Expires
|
|
33
34
|
const headersToPreserveForUnmodified = ['Content-Location', 'ETag', 'Vary', 'Cache-Control', 'Expires'];
|
|
34
|
-
function requestAcceptsTextHtml(req) {
|
|
35
|
-
const accept = (req.headers.get('Accept') ?? '')
|
|
36
|
-
.split(',')
|
|
37
|
-
.map(x => x.split(';')[0]);
|
|
38
|
-
if (!accept.includes('text/html') && !accept.includes('*/*') && accept.includes('*')) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
35
|
export class PublisherServer {
|
|
44
36
|
constructor(publishId, storageProvider, defaultCollectionName) {
|
|
37
|
+
// When true, serveCached() does not store the response of the current request.
|
|
38
|
+
this.doNotStoreResponse = false;
|
|
45
39
|
this.publishId = publishId;
|
|
46
40
|
this.storageProvider = storageProvider;
|
|
47
41
|
this.defaultCollectionName = defaultCollectionName;
|
|
@@ -87,6 +81,7 @@ export class PublisherServer {
|
|
|
87
81
|
beginRequest(request) {
|
|
88
82
|
this.settingsCached = undefined;
|
|
89
83
|
this.assetEntryMapCache = undefined;
|
|
84
|
+
this.doNotStoreResponse = false;
|
|
90
85
|
const header = this.serverTimingRequestHeader;
|
|
91
86
|
this.serverTiming = header != null && request.headers.has(header) ? new ServerTiming() : null;
|
|
92
87
|
}
|
|
@@ -450,6 +445,10 @@ export class PublisherServer {
|
|
|
450
445
|
entry.cancel();
|
|
451
446
|
throw err;
|
|
452
447
|
}
|
|
448
|
+
if (this.doNotStoreResponse) {
|
|
449
|
+
entry.cancel();
|
|
450
|
+
return response;
|
|
451
|
+
}
|
|
453
452
|
const insertOptions = {
|
|
454
453
|
// The Core Cache takes maxAge in milliseconds. ResponseCacheOptions.maxAge is in seconds.
|
|
455
454
|
maxAge: this.responseCache.maxAge * 1000,
|
|
@@ -503,9 +502,13 @@ export class PublisherServer {
|
|
|
503
502
|
userMetadata: encodeCachedResponseMetadata(metadata),
|
|
504
503
|
length: readResult.bytes.byteLength,
|
|
505
504
|
});
|
|
506
|
-
|
|
505
|
+
// The body goes to the entry and to the response in pieces. A call with the
|
|
506
|
+
// whole body makes a full copy of it, which needs memory for one more body.
|
|
507
|
+
for (const piece of bytesInPieces(readResult.bytes)) {
|
|
508
|
+
writer.append(piece);
|
|
509
|
+
}
|
|
507
510
|
writer.close();
|
|
508
|
-
return this.responseFromCache(request, metadata, readResult.bytes);
|
|
511
|
+
return this.responseFromCache(request, metadata, streamBytesInPieces(readResult.bytes));
|
|
509
512
|
}
|
|
510
513
|
responseFromCache(request, metadata, body) {
|
|
511
514
|
if (metadata.notFound) {
|
|
@@ -545,7 +548,7 @@ export class PublisherServer {
|
|
|
545
548
|
}
|
|
546
549
|
async serveRequestFromStorage(request, pathname) {
|
|
547
550
|
const serverConfig = await this.getServerConfig();
|
|
548
|
-
if (serverConfig == null) {
|
|
551
|
+
if (serverConfig == null && this.activeCollectionName === this.defaultCollectionName) {
|
|
549
552
|
return new Response(`Settings not found. You may need to publish your application.`, {
|
|
550
553
|
status: 500,
|
|
551
554
|
headers: {
|
|
@@ -553,6 +556,21 @@ export class PublisherServer {
|
|
|
553
556
|
},
|
|
554
557
|
});
|
|
555
558
|
}
|
|
559
|
+
// A collection other than the default collection that is not published, or
|
|
560
|
+
// that expired, gets a 404. It can be published at any time, so the
|
|
561
|
+
// response cache does not store this response.
|
|
562
|
+
if (serverConfig == null ||
|
|
563
|
+
(this.activeCollectionName !== this.defaultCollectionName && await this.getAssetEntryMap() == null)) {
|
|
564
|
+
this.doNotStoreResponse = true;
|
|
565
|
+
return new Response(`Collection '${this.activeCollectionName}' is not available. It is not published, or it expired.`, {
|
|
566
|
+
status: 404,
|
|
567
|
+
headers: {
|
|
568
|
+
'content-type': 'text/plain',
|
|
569
|
+
'x-content-type-options': 'nosniff',
|
|
570
|
+
'cache-control': 'no-store',
|
|
571
|
+
},
|
|
572
|
+
});
|
|
573
|
+
}
|
|
556
574
|
const asset = await this.getMatchingAsset(serverConfig.publicDirPrefix + pathname, true);
|
|
557
575
|
if (asset != null) {
|
|
558
576
|
return this.serveAsset(request, asset, {
|
|
@@ -27,6 +27,9 @@ export type ReadBodyResult = {
|
|
|
27
27
|
body: ReadableStream<Uint8Array>;
|
|
28
28
|
};
|
|
29
29
|
export declare function readBodyUpTo(body: ReadableStream<Uint8Array> | null, maxLength: number): Promise<ReadBodyResult>;
|
|
30
|
+
export declare const BODY_PIECE_SIZE: number;
|
|
31
|
+
export declare function bytesInPieces(bytes: Uint8Array<ArrayBuffer>): Generator<Uint8Array<ArrayBuffer>>;
|
|
32
|
+
export declare function streamBytesInPieces(bytes: Uint8Array<ArrayBuffer>): ReadableStream<Uint8Array>;
|
|
30
33
|
export declare function encodeCachedResponseMetadata(metadata: CachedResponseMetadata): string;
|
|
31
34
|
export declare function decodeCachedResponseMetadata(buffer: ArrayBuffer): CachedResponseMetadata | null;
|
|
32
35
|
//# sourceMappingURL=response-cache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response-cache.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/response-cache.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,uBAAuB,EAE7B,MAAM,mCAAmC,CAAC;AAE3C,MAAM,MAAM,oBAAoB,GAAG;IAIjC,MAAM,EAAE,MAAM,CAAC;IAIf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"response-cache.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/response-cache.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,uBAAuB,EAE7B,MAAM,mCAAmC,CAAC;AAE3C,MAAM,MAAM,oBAAoB,GAAG;IAIjC,MAAM,EAAE,MAAM,CAAC;IAIf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC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AK,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAIjG;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,cAAc,CAAC,UAAU,CAAC,CAY9F;AAED,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,sBAAsB,GAAG,MAAM,CAErF;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,WAAW,GAAG,sBAAsB,GAAG,IAAI,CAgB/F"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
import { compressionTypes, } from '../../models/compression/index.js';
|
|
6
|
-
export const DEFAULT_MAX_BODY_SIZE =
|
|
6
|
+
export const DEFAULT_MAX_BODY_SIZE = 16 * 1024 * 1024;
|
|
7
7
|
// Statuses that serveAsset() produces for a found file or a not-found page.
|
|
8
8
|
// Anything else (for example, a 500 when the settings are missing) is not cached.
|
|
9
9
|
export const CACHEABLE_STATUSES = [200, 404];
|
|
@@ -137,6 +137,29 @@ export async function readBodyUpTo(body, maxLength) {
|
|
|
137
137
|
}
|
|
138
138
|
return { bytes };
|
|
139
139
|
}
|
|
140
|
+
export const BODY_PIECE_SIZE = 1024 * 1024;
|
|
141
|
+
// Gives bytes in pieces of BODY_PIECE_SIZE bytes. The pieces are views of
|
|
142
|
+
// bytes, not copies.
|
|
143
|
+
export function* bytesInPieces(bytes) {
|
|
144
|
+
for (let offset = 0; offset < bytes.byteLength; offset += BODY_PIECE_SIZE) {
|
|
145
|
+
yield bytes.subarray(offset, offset + BODY_PIECE_SIZE);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// A stream of bytes in pieces of BODY_PIECE_SIZE bytes, as bytesInPieces() gives them.
|
|
149
|
+
export function streamBytesInPieces(bytes) {
|
|
150
|
+
const pieces = bytesInPieces(bytes);
|
|
151
|
+
return new ReadableStream({
|
|
152
|
+
pull(controller) {
|
|
153
|
+
const { done, value } = pieces.next();
|
|
154
|
+
if (done) {
|
|
155
|
+
controller.close();
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
controller.enqueue(value);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
140
163
|
export function encodeCachedResponseMetadata(metadata) {
|
|
141
164
|
return JSON.stringify(metadata);
|
|
142
165
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastly/compute-js-static-publish",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "8.0.
|
|
4
|
+
"version": "8.0.2",
|
|
5
5
|
"description": "Static Publisher for Fastly Compute JavaScript",
|
|
6
6
|
"main": "build/server/server/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"compile:server": "tsc -p tsconfig.server.json",
|
|
20
20
|
"test": "npm run build && node --test \"test/unit/*.test.js\"",
|
|
21
21
|
"test:e2e": "npm run build && node --test --test-concurrency=1 \"test/e2e/*.test.js\"",
|
|
22
|
-
"prepublishOnly": "cp README.short.md README.md"
|
|
22
|
+
"prepublishOnly": "cp README.md DOCUMENTATION.md && cp README.short.md README.md"
|
|
23
23
|
},
|
|
24
24
|
"bin": {
|
|
25
25
|
"compute-js-static-publish": "build/cli/cli/index.js"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@types/command-line-args": "^5.2.0",
|
|
57
57
|
"@types/glob-to-regexp": "^0.4.1",
|
|
58
58
|
"@types/node": "^20.11.0",
|
|
59
|
-
"rimraf": "^
|
|
59
|
+
"rimraf": "^6.1.4",
|
|
60
60
|
"typescript": "^5.8.0"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
@@ -68,6 +68,9 @@
|
|
|
68
68
|
"LICENSE",
|
|
69
69
|
"package.json",
|
|
70
70
|
"README.md",
|
|
71
|
+
"DOCUMENTATION.md",
|
|
72
|
+
"CHANGELOG.md",
|
|
73
|
+
"MIGRATING.md",
|
|
71
74
|
"SECURITY.md"
|
|
72
75
|
]
|
|
73
76
|
}
|