@fastly/compute-js-static-publish 8.0.1 → 8.1.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/DOCUMENTATION.md +779 -22
- package/README.md +2 -2
- package/README.short.md +2 -2
- package/build/cli/cli/commands/manage/clean.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/clean.js +12 -7
- package/build/cli/cli/commands/manage/collections/delete.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/delete.js +29 -13
- package/build/cli/cli/commands/manage/collections/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/index.js +6 -1
- package/build/cli/cli/commands/manage/collections/list.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/list.js +47 -7
- package/build/cli/cli/commands/manage/collections/promote.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/promote.js +67 -20
- package/build/cli/cli/commands/manage/collections/update-expiration.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/collections/update-expiration.js +10 -11
- package/build/cli/cli/commands/manage/deploy.d.ts +2 -0
- package/build/cli/cli/commands/manage/deploy.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/deploy.js +194 -0
- package/build/cli/cli/commands/manage/dev.d.ts +2 -0
- package/build/cli/cli/commands/manage/dev.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/dev.js +77 -0
- package/build/cli/cli/commands/manage/eject.d.ts +2 -0
- package/build/cli/cli/commands/manage/eject.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/eject.js +155 -0
- package/build/cli/cli/commands/manage/index.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/index.js +37 -1
- package/build/cli/cli/commands/manage/publish-content.d.ts.map +1 -1
- package/build/cli/cli/commands/manage/publish-content.js +78 -33
- package/build/cli/cli/commands/manage/status.d.ts +2 -0
- package/build/cli/cli/commands/manage/status.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/status.js +162 -0
- package/build/cli/cli/commands/manage/template/index.d.ts +2 -0
- package/build/cli/cli/commands/manage/template/index.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/index.js +42 -0
- package/build/cli/cli/commands/manage/template/init.d.ts +13 -0
- package/build/cli/cli/commands/manage/template/init.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/template/init.js +172 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts +2 -0
- package/build/cli/cli/commands/manage/upgrade.d.ts.map +1 -0
- package/build/cli/cli/commands/manage/upgrade.js +59 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts +8 -0
- package/build/cli/cli/commands/run-dev-watch.d.ts.map +1 -0
- package/build/cli/cli/commands/run-dev-watch.js +41 -0
- package/build/cli/cli/commands/run-template-hook.d.ts +2 -0
- package/build/cli/cli/commands/run-template-hook.d.ts.map +1 -0
- package/build/cli/cli/commands/run-template-hook.js +28 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts +17 -0
- package/build/cli/cli/commands/scaffold/app-template.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/app-template.js +54 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts +5 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/fastly-toml-sections.js +154 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts +47 -0
- package/build/cli/cli/commands/scaffold/generate-app.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/generate-app.js +164 -0
- package/build/cli/cli/commands/scaffold/index.d.ts +6 -0
- package/build/cli/cli/commands/scaffold/index.d.ts.map +1 -1
- package/build/cli/cli/commands/scaffold/index.js +208 -290
- package/build/cli/cli/commands/scaffold/render.d.ts +7 -0
- package/build/cli/cli/commands/scaffold/render.d.ts.map +1 -0
- package/build/cli/cli/commands/scaffold/render.js +72 -0
- package/build/cli/cli/hono/build.d.ts +43 -0
- package/build/cli/cli/hono/build.d.ts.map +1 -0
- package/build/cli/cli/hono/build.js +297 -0
- package/build/cli/cli/index.js +98 -5
- package/build/cli/cli/managed/app.d.ts +21 -0
- package/build/cli/cli/managed/app.d.ts.map +1 -0
- package/build/cli/cli/managed/app.js +162 -0
- package/build/cli/cli/managed/command-helpers.d.ts +6 -0
- package/build/cli/cli/managed/command-helpers.d.ts.map +1 -0
- package/build/cli/cli/managed/command-helpers.js +81 -0
- package/build/cli/cli/managed/eject.d.ts +6 -0
- package/build/cli/cli/managed/eject.d.ts.map +1 -0
- package/build/cli/cli/managed/eject.js +68 -0
- package/build/cli/cli/managed/fastly-service.d.ts +8 -0
- package/build/cli/cli/managed/fastly-service.d.ts.map +1 -0
- package/build/cli/cli/managed/fastly-service.js +21 -0
- package/build/cli/cli/managed/fingerprint.d.ts +13 -0
- package/build/cli/cli/managed/fingerprint.d.ts.map +1 -0
- package/build/cli/cli/managed/fingerprint.js +60 -0
- package/build/cli/cli/managed/lockfile.d.ts +31 -0
- package/build/cli/cli/managed/lockfile.d.ts.map +1 -0
- package/build/cli/cli/managed/lockfile.js +62 -0
- package/build/cli/cli/managed/project-edit.d.ts +3 -0
- package/build/cli/cli/managed/project-edit.d.ts.map +1 -0
- package/build/cli/cli/managed/project-edit.js +35 -0
- package/build/cli/cli/managed/project-file.d.ts +16 -0
- package/build/cli/cli/managed/project-file.d.ts.map +1 -0
- package/build/cli/cli/managed/project-file.js +119 -0
- package/build/cli/cli/managed/template-init.d.ts +12 -0
- package/build/cli/cli/managed/template-init.d.ts.map +1 -0
- package/build/cli/cli/managed/template-init.js +120 -0
- package/build/cli/cli/managed/version-check.d.ts +25 -0
- package/build/cli/cli/managed/version-check.d.ts.map +1 -0
- package/build/cli/cli/managed/version-check.js +84 -0
- 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 +6 -3
- package/build/cli/cli/storage/kv-store-provider.d.ts +1 -0
- package/build/cli/cli/storage/kv-store-provider.d.ts.map +1 -1
- package/build/cli/cli/storage/kv-store-provider.js +9 -1
- 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 +4 -0
- package/build/cli/cli/storage/storage-provider.d.ts +3 -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.map +1 -1
- package/build/cli/cli/util/collection-name.d.ts +3 -0
- package/build/cli/cli/util/collection-name.d.ts.map +1 -0
- package/build/cli/cli/util/collection-name.js +24 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts +13 -0
- package/build/cli/cli/util/collection-selection-flags.d.ts.map +1 -0
- package/build/cli/cli/util/collection-selection-flags.js +131 -0
- package/build/cli/cli/util/config.d.ts +13 -0
- package/build/cli/cli/util/config.d.ts.map +1 -1
- package/build/cli/cli/util/config.js +172 -38
- package/build/cli/cli/util/data.d.ts.map +1 -1
- package/build/cli/cli/util/global-options.d.ts +13 -0
- package/build/cli/cli/util/global-options.d.ts.map +1 -0
- package/build/cli/cli/util/global-options.js +53 -0
- 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/kv-store-local-server.d.ts +1 -1
- package/build/cli/cli/util/kv-store-local-server.d.ts.map +1 -1
- package/build/cli/cli/util/kv-store-local-server.js +4 -2
- package/build/cli/cli/util/output.d.ts +31 -0
- package/build/cli/cli/util/output.d.ts.map +1 -0
- package/build/cli/cli/util/output.js +139 -0
- package/build/cli/cli/util/package.d.ts +3 -0
- package/build/cli/cli/util/package.d.ts.map +1 -1
- package/build/cli/cli/util/package.js +12 -0
- package/build/cli/cli/util/progress.d.ts.map +1 -1
- package/build/cli/cli/util/purge.d.ts +6 -2
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +7 -2
- package/build/cli/cli/util/resources.d.ts +2 -0
- package/build/cli/cli/util/resources.d.ts.map +1 -0
- package/build/cli/cli/util/resources.js +8 -0
- package/build/cli/cli/util/service-id.d.ts +1 -0
- package/build/cli/cli/util/service-id.d.ts.map +1 -1
- package/build/cli/cli/util/service-id.js +5 -1
- package/build/cli/cli/util/variants.d.ts.map +1 -1
- package/build/cli/models/assets/index.d.ts +6 -0
- package/build/cli/models/assets/index.d.ts.map +1 -1
- package/build/cli/models/assets/index.js +24 -0
- package/build/cli/models/collections/index.d.ts +3 -0
- package/build/cli/models/collections/index.d.ts.map +1 -0
- package/build/cli/models/collections/index.js +15 -0
- package/build/cli/models/compression/index.d.ts +1 -1
- package/build/cli/models/compression/index.d.ts.map +1 -1
- package/build/cli/models/config/collection-selection.d.ts +55 -0
- package/build/cli/models/config/collection-selection.d.ts.map +1 -0
- package/build/cli/models/config/collection-selection.js +238 -0
- package/build/cli/models/config/item-patterns.d.ts +4 -0
- package/build/cli/models/config/item-patterns.d.ts.map +1 -0
- package/build/cli/models/config/item-patterns.js +43 -0
- package/build/cli/models/config/publish-content-config.d.ts +6 -1
- package/build/cli/models/config/publish-content-config.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-project.d.ts +23 -0
- package/build/cli/models/config/static-publish-project.d.ts.map +1 -0
- package/build/cli/models/config/static-publish-project.js +11 -0
- package/build/cli/models/config/static-publish-rc.d.ts +25 -0
- package/build/cli/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/cli/models/config/static-publish-rc.js +31 -0
- package/build/cli/models/config/template-settings.d.ts +10 -0
- package/build/cli/models/config/template-settings.d.ts.map +1 -0
- package/build/cli/models/config/template-settings.js +72 -0
- package/build/cli/models/server/index.d.ts.map +1 -1
- package/build/cli/models/server/index.js +6 -2
- package/build/server/hono/extensions.d.ts +48 -0
- package/build/server/hono/extensions.d.ts.map +1 -0
- package/build/server/hono/extensions.js +65 -0
- package/build/server/hono/index.d.ts +30 -0
- package/build/server/hono/index.d.ts.map +1 -0
- package/build/server/hono/index.js +72 -0
- package/build/server/hono/path.d.ts +7 -0
- package/build/server/hono/path.d.ts.map +1 -0
- package/build/server/hono/path.js +32 -0
- package/build/server/models/assets/index.d.ts +6 -0
- package/build/server/models/assets/index.d.ts.map +1 -1
- package/build/server/models/assets/index.js +24 -0
- package/build/server/models/collections/index.d.ts +3 -0
- package/build/server/models/collections/index.d.ts.map +1 -0
- package/build/server/models/collections/index.js +15 -0
- package/build/server/models/compression/index.d.ts +1 -1
- package/build/server/models/compression/index.d.ts.map +1 -1
- package/build/server/models/config/collection-selection.d.ts +55 -0
- package/build/server/models/config/collection-selection.d.ts.map +1 -0
- package/build/server/models/config/collection-selection.js +238 -0
- package/build/server/models/config/item-patterns.d.ts +4 -0
- package/build/server/models/config/item-patterns.d.ts.map +1 -0
- package/build/server/models/config/item-patterns.js +43 -0
- package/build/server/models/config/publish-content-config.d.ts +6 -1
- package/build/server/models/config/publish-content-config.d.ts.map +1 -1
- package/build/server/models/config/static-publish-project.d.ts +23 -0
- package/build/server/models/config/static-publish-project.d.ts.map +1 -0
- package/build/server/models/config/static-publish-project.js +11 -0
- package/build/server/models/config/static-publish-rc.d.ts +25 -0
- package/build/server/models/config/static-publish-rc.d.ts.map +1 -1
- package/build/server/models/config/static-publish-rc.js +31 -0
- package/build/server/models/server/index.d.ts.map +1 -1
- package/build/server/models/server/index.js +6 -2
- package/build/server/server/collection-selection/index.d.ts +11 -0
- package/build/server/server/collection-selection/index.d.ts.map +1 -0
- package/build/server/server/collection-selection/index.js +192 -0
- package/build/server/server/collection-selector/from-cookie.d.ts.map +1 -1
- package/build/server/server/collection-selector/from-cookie.js +6 -8
- package/build/server/server/collection-selector/from-request.d.ts.map +1 -1
- package/build/server/server/index.d.ts +4 -1
- package/build/server/server/index.d.ts.map +1 -1
- package/build/server/server/index.js +3 -1
- 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 +59 -7
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +362 -145
- 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/build/server/server/storage/kv-store-provider.d.ts.map +1 -1
- package/build/server/server/storage/s3-storage-provider.d.ts.map +1 -1
- package/build/server/server/storage/storage-provider.d.ts.map +1 -1
- package/build/server/server/util/body-length.d.ts.map +1 -1
- package/build/server/server/util/server-timing.d.ts.map +1 -1
- package/package.json +21 -3
- package/resources/app/fastly.toml.njk +58 -0
- package/resources/app/gitignore.njk +9 -0
- package/resources/app/publish-content.config.from-project.js.njk +9 -0
- package/resources/app/publish-content.config.js.njk +35 -0
- package/resources/app/static-publish.project.js.njk +83 -0
- package/resources/app/static-publish.rc.js.njk +43 -0
- package/resources/template-init/hono/_example.ts +22 -0
- package/resources/template-init/hono/tsconfig.json +17 -0
- package/resources/templates/hono/package-lock.json +4123 -0
- package/resources/templates/hono/package.json +15 -0
- package/resources/templates/hono/scripts/template_postinstall.js +10 -0
- package/resources/templates/hono/scripts/template_prebuild.js +8 -0
- package/resources/templates/hono/scripts/template_watch.js +15 -0
- package/resources/templates/hono/src/hono-extensions.generated.d.ts +5 -0
- package/resources/templates/hono/src/index.ts +53 -0
- package/resources/templates/hono/tsconfig.json +17 -0
- package/resources/templates/plain/package-lock.json +4088 -0
- package/resources/templates/plain/package.json +10 -0
- package/resources/templates/plain/src/index.js +34 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// Parse normalized items. An item that cannot be parsed is skipped, and
|
|
6
|
+
// onError is called for it.
|
|
7
|
+
export function parseItemPatterns(items, onError) {
|
|
8
|
+
const result = [];
|
|
9
|
+
items.forEach((x, i) => {
|
|
10
|
+
if (x.startsWith('re:')) {
|
|
11
|
+
const fragments = x.slice(3).match(/\/(.*?)\/([a-z]*)?$/i);
|
|
12
|
+
let re = null;
|
|
13
|
+
if (fragments != null) {
|
|
14
|
+
try {
|
|
15
|
+
re = new RegExp(fragments[1], fragments[2] || '');
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (re == null) {
|
|
21
|
+
onError?.(i, x);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
result.push(re);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (x !== '') {
|
|
28
|
+
result.push(x);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
export function testItemPatterns(patterns, path) {
|
|
34
|
+
return patterns.some(x => {
|
|
35
|
+
if (x instanceof RegExp) {
|
|
36
|
+
return x.test(path);
|
|
37
|
+
}
|
|
38
|
+
if (x.endsWith('/')) {
|
|
39
|
+
return path.startsWith(x);
|
|
40
|
+
}
|
|
41
|
+
return x === path;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -15,13 +15,17 @@ export type ContentTypeTestResult = {
|
|
|
15
15
|
export interface ExcludeDirTest {
|
|
16
16
|
test(name: string): boolean;
|
|
17
17
|
}
|
|
18
|
-
export type
|
|
18
|
+
export type AssetInclusionTestResult = boolean | {
|
|
19
|
+
hidden?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type AssetInclusionTest = (assetKey: string, contentType?: string) => AssetInclusionTestResult;
|
|
19
22
|
export type PublishContentConfig = {
|
|
20
23
|
rootDir: string;
|
|
21
24
|
excludeDirs?: (string | ExcludeDirTest)[] | string | ExcludeDirTest | null;
|
|
22
25
|
excludeDotFiles?: boolean;
|
|
23
26
|
includeWellKnown?: boolean;
|
|
24
27
|
assetInclusionTest?: AssetInclusionTest | null;
|
|
28
|
+
hiddenItems?: string[] | string | false | null;
|
|
25
29
|
kvStoreAssetInclusionTest?: AssetInclusionTest | null;
|
|
26
30
|
contentCompression?: ('br' | 'gzip')[];
|
|
27
31
|
brotliQuality?: number;
|
|
@@ -34,6 +38,7 @@ export type PublishContentConfigNormalized = {
|
|
|
34
38
|
excludeDotFiles: boolean;
|
|
35
39
|
includeWellKnown: boolean;
|
|
36
40
|
assetInclusionTest: AssetInclusionTest | null;
|
|
41
|
+
hiddenItems: string[];
|
|
37
42
|
contentCompression: ContentCompressionTypes[];
|
|
38
43
|
brotliQuality: number | undefined;
|
|
39
44
|
contentTypes: ContentTypeDef[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAGxD,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAG/B,WAAW,EAAE,MAAM,CAAC;IAIpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;
|
|
1
|
+
{"version":3,"file":"publish-content-config.d.ts","sourceRoot":"","sources":["../../../../src/models/config/publish-content-config.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,uBAAuB,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAGxD,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,GAAG,eAAe,CAAC;IAG/B,WAAW,EAAE,MAAM,CAAC;IAIpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAIf,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AAID,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtE,MAAM,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,KAAK,wBAAwB,CAAC;AAEtG,MAAM,MAAM,oBAAoB,GAAG;IAEjC,OAAO,EAAE,MAAM,CAAC;IAMhB,WAAW,CAAC,EAAE,CAAC,MAAM,GAAG,cAAc,CAAC,EAAE,GAAG,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC;IAI3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAI1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAK3B,kBAAkB,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAQ/C,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;IAI/C,yBAAyB,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAItD,kBAAkB,CAAC,EAAE,CAAC,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC;IAIvC,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;IAGhC,MAAM,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,cAAc,EAAE,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC9C,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,EAAE,uBAAuB,EAAE,CAAC;IAC9C,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,YAAY,EAAE,cAAc,EAAE,CAAC;IAC/B,MAAM,EAAE,+BAA+B,GAAG,IAAI,CAAC;CAChD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type PublishContentConfig } from './publish-content-config.js';
|
|
2
|
+
import { type StaticPublishRc } from './static-publish-rc.js';
|
|
3
|
+
export declare const PROJECT_FILE_NAME = "static-publish.project.js";
|
|
4
|
+
export declare const RC_FILE_NAME = "static-publish.rc.js";
|
|
5
|
+
export declare const MANAGED_APP_DIR = ".static-publish/app";
|
|
6
|
+
export type FastlyTomlSections = {
|
|
7
|
+
local_server?: Record<string, unknown>;
|
|
8
|
+
setup?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export type StaticPublishProjectManaged = {
|
|
11
|
+
name?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
authors?: string[];
|
|
14
|
+
template?: string;
|
|
15
|
+
serviceId?: string;
|
|
16
|
+
staticPublishVersion?: string;
|
|
17
|
+
fastlyToml?: FastlyTomlSections;
|
|
18
|
+
};
|
|
19
|
+
export type StaticPublishProject = StaticPublishRc & {
|
|
20
|
+
publishContent: PublishContentConfig;
|
|
21
|
+
managed?: StaticPublishProjectManaged;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=static-publish-project.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-publish-project.d.ts","sourceRoot":"","sources":["../../../../src/models/config/static-publish-project.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAK9D,eAAO,MAAM,iBAAiB,8BAA8B,CAAC;AAC7D,eAAO,MAAM,YAAY,yBAAyB,CAAC;AAGnD,eAAO,MAAM,eAAe,wBAAwB,CAAC;AAMrD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,CAAC;AAGF,MAAM,MAAM,2BAA2B,GAAG;IAExC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,UAAU,CAAC,EAAE,kBAAkB,CAAC;CACjC,CAAC;AAOF,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG;IACnD,cAAc,EAAE,oBAAoB,CAAC;IACrC,OAAO,CAAC,EAAE,2BAA2B,CAAC;CACvC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// A managed project has one file, static-publish.project.js, in the project
|
|
6
|
+
// dir. The name of the file marks managed mode. An ejected app has
|
|
7
|
+
// static-publish.rc.js and publish-content.config.js in the app dir.
|
|
8
|
+
export const PROJECT_FILE_NAME = 'static-publish.project.js';
|
|
9
|
+
export const RC_FILE_NAME = 'static-publish.rc.js';
|
|
10
|
+
// The generated app of a managed project, relative to the project dir.
|
|
11
|
+
export const MANAGED_APP_DIR = '.static-publish/app';
|
|
@@ -1,7 +1,31 @@
|
|
|
1
|
+
import { type CollectionSelection } from './collection-selection.js';
|
|
1
2
|
export type StaticPublishRcBase = {
|
|
2
3
|
publishId: string;
|
|
3
4
|
defaultCollectionName: string;
|
|
4
5
|
staticPublisherWorkingDir: string;
|
|
6
|
+
generatedFrom?: GeneratedFrom;
|
|
7
|
+
collectionSelection?: CollectionSelection;
|
|
8
|
+
build?: StaticPublishBuild;
|
|
9
|
+
templateOptions?: StaticPublishTemplateOptions;
|
|
10
|
+
};
|
|
11
|
+
export type StaticPublishBuild = {
|
|
12
|
+
hono?: {
|
|
13
|
+
extensionsDir?: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type HonoBindings = Record<string, string>;
|
|
17
|
+
export type HonoTemplateOptions = {
|
|
18
|
+
bindings?: HonoBindings;
|
|
19
|
+
middleware?: Record<string, unknown>;
|
|
20
|
+
routes?: Record<string, unknown>;
|
|
21
|
+
};
|
|
22
|
+
export type StaticPublishTemplateOptions = {
|
|
23
|
+
hono?: HonoTemplateOptions;
|
|
24
|
+
};
|
|
25
|
+
export type GeneratedFrom = {
|
|
26
|
+
template: string;
|
|
27
|
+
staticPublishVersion: string;
|
|
28
|
+
generatedAt: string;
|
|
5
29
|
};
|
|
6
30
|
export type StaticPublishPartialKvStoreNew = {
|
|
7
31
|
storageMode: 'kv-store';
|
|
@@ -29,4 +53,5 @@ export type StaticPublishS3Storage = StaticPublishPartialS3Storage & StaticPubli
|
|
|
29
53
|
export declare function isS3StorageConfigRc(rc: unknown): rc is StaticPublishS3Storage;
|
|
30
54
|
export type StaticPublishPartialStorage = StaticPublishPartialKvStore | StaticPublishPartialS3Storage;
|
|
31
55
|
export type StaticPublishRc = StaticPublishKvStore | StaticPublishS3Storage;
|
|
56
|
+
export declare function checkStaticPublisherWorkingDir(value: unknown): string | null;
|
|
32
57
|
//# sourceMappingURL=static-publish-rc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-publish-rc.d.ts","sourceRoot":"","sources":["../../../../src/models/config/static-publish-rc.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,mBAAmB,GAAG;IAGhC,SAAS,EAAE,MAAM,CAAC;IAGlB,qBAAqB,EAAE,MAAM,CAAC;IAK9B,yBAAyB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"static-publish-rc.d.ts","sourceRoot":"","sources":["../../../../src/models/config/static-publish-rc.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,MAAM,mBAAmB,GAAG;IAGhC,SAAS,EAAE,MAAM,CAAC;IAGlB,qBAAqB,EAAE,MAAM,CAAC;IAK9B,yBAAyB,EAAE,MAAM,CAAC;IAGlC,aAAa,CAAC,EAAE,aAAa,CAAC;IAK9B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAG1C,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAI3B,eAAe,CAAC,EAAE,4BAA4B,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE;QAGL,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH,CAAC;AAIF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD,MAAM,MAAM,mBAAmB,GAAG;IAGhC,QAAQ,CAAC,EAAE,YAAY,CAAC;IAExB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAErC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,CAAC,EAAE,mBAAmB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAE1B,QAAQ,EAAE,MAAM,CAAC;IAEjB,oBAAoB,EAAE,MAAM,CAAC;IAE7B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,WAAW,EAAE,UAAU,CAAC;IACxB,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAGF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,2BAA2B,GACnC,8BAA8B,GAC9B,iCAAiC,CACpC;AAGD,MAAM,MAAM,oBAAoB,GAC9B,2BAA2B,GAAG,mBAAmB,CAAC;AAEpD,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,oBAAoB,CAqBzE;AAGD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,EAAE,IAAI,CAAC;IAClB,EAAE,EAAE;QACF,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAChC,6BAA6B,GAAG,mBAAmB,CAAC;AAEtD,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,sBAAsB,CAyB7E;AAED,MAAM,MAAM,2BAA2B,GACnC,2BAA2B,GAC3B,6BAA6B,CAChC;AAED,MAAM,MAAM,eAAe,GACvB,oBAAoB,GACpB,sBAAsB,CACzB;AAQD,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAuB5E"}
|
|
@@ -39,3 +39,34 @@ export function isS3StorageConfigRc(rc) {
|
|
|
39
39
|
}
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
|
+
// The rule for staticPublisherWorkingDir: a relative path that starts with
|
|
43
|
+
// './' or '../'. The path is relative to the file that has it
|
|
44
|
+
// (static-publish.rc.js or static-publish.project.js). It must not be that
|
|
45
|
+
// file's directory or a directory above it, so that publish-content never
|
|
46
|
+
// writes its files among the customer's own files. Returns an error message,
|
|
47
|
+
// or null if the value is valid.
|
|
48
|
+
export function checkStaticPublisherWorkingDir(value) {
|
|
49
|
+
const message = `staticPublisherWorkingDir must be a relative path that starts with './' or '../', and that is not the directory of the config file or a directory above it.`;
|
|
50
|
+
if (typeof value !== 'string' || !(value.startsWith('./') || value.startsWith('../'))) {
|
|
51
|
+
return message;
|
|
52
|
+
}
|
|
53
|
+
if (value.includes('//') || value.includes('\\')) {
|
|
54
|
+
return message;
|
|
55
|
+
}
|
|
56
|
+
const segments = [];
|
|
57
|
+
for (const segment of value.split('/')) {
|
|
58
|
+
if (segment === '' || segment === '.') {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (segment === '..' && segments.length > 0 && segments[segments.length - 1] !== '..') {
|
|
62
|
+
segments.pop();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
segments.push(segment);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (segments.every(x => x === '..')) {
|
|
69
|
+
return message;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/server/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAIxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAMF,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAGrD,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAqBxF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,aAAa,GAAG,IAAI,CA2BjG;AAGD,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,SAAS,MAAM,EAA6B,GAC9D,MAAM,EAAE,CAEV"}
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
import { HIDDEN_INDEX_FEATURE } from '../assets/index.js';
|
|
5
6
|
import { getMetadataFieldValue } from '../metadata/index.js';
|
|
6
7
|
// The features that this version of PublisherServer supports. A server does
|
|
7
8
|
// not serve a collection that requires a feature that is not in this list.
|
|
8
9
|
// A feature name must not contain a comma, because the metadata uses commas to
|
|
9
|
-
// separate the names. Use short kebab-case names, for example '
|
|
10
|
-
export const SUPPORTED_INDEX_FEATURES = [
|
|
10
|
+
// separate the names. Use short kebab-case names, for example 'hidden'.
|
|
11
|
+
export const SUPPORTED_INDEX_FEATURES = [
|
|
12
|
+
// Hidden files: index keys that start with 'hidden:'.
|
|
13
|
+
HIDDEN_INDEX_FEATURE,
|
|
14
|
+
];
|
|
11
15
|
const KNOWN_FIELDS = ['publishedTime', 'expirationTime', 'requires'];
|
|
12
16
|
export function encodeIndexMetadata(indexMetadata) {
|
|
13
17
|
const result = { ...indexMetadata.otherFields };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type CollectionSelection, type CollectionSelectionSourceType } from '../../models/config/collection-selection.js';
|
|
2
|
+
export type ResolveCollectionResult = {
|
|
3
|
+
collectionName: string | null;
|
|
4
|
+
pathname?: string;
|
|
5
|
+
response?: Response;
|
|
6
|
+
matchedBy?: CollectionSelectionSourceType;
|
|
7
|
+
};
|
|
8
|
+
export declare function sameSiteLocation(value: string): string;
|
|
9
|
+
export declare function isSelectedByUrl(result: ResolveCollectionResult, collectionName: string): boolean;
|
|
10
|
+
export declare function resolveCollection(request: Request, config: CollectionSelection | null | undefined): ResolveCollectionResult;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/server/collection-selection/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,mBAAmB,EAGxB,KAAK,6BAA6B,EAKnC,MAAM,6CAA6C,CAAC;AAGrD,MAAM,MAAM,uBAAuB,GAAG;IAEpC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAG9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB,SAAS,CAAC,EAAE,6BAA6B,CAAC;CAC3C,CAAC;AA6FF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKtD;AAmCD,wBAAgB,eAAe,CAAC,MAAM,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAGhG;AAKD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,GAAG,uBAAuB,CAoE3H"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// Chooses the collection for a request from a collectionSelection config.
|
|
6
|
+
// This module does not import fastly:*, so that the unit tests can load it.
|
|
7
|
+
import { COLLECTION_NAME_RULE, isValidCollectionName } from '../../models/collections/index.js';
|
|
8
|
+
import { COOKIE_SOURCE_DEFAULTS, isCollectionNameAllowed, splitPattern, validateCollectionSelection, } from '../../models/config/collection-selection.js';
|
|
9
|
+
import { getCookieValue } from '../util/cookies.js';
|
|
10
|
+
const NAME_GROUP = '([a-z0-9-]{1,63})';
|
|
11
|
+
function escapeRegExp(value) {
|
|
12
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
13
|
+
}
|
|
14
|
+
const compiledConfigs = new WeakMap();
|
|
15
|
+
function compile(config) {
|
|
16
|
+
let compiled = compiledConfigs.get(config);
|
|
17
|
+
if (compiled != null) {
|
|
18
|
+
return compiled;
|
|
19
|
+
}
|
|
20
|
+
const errors = validateCollectionSelection(config);
|
|
21
|
+
if (errors.length > 0) {
|
|
22
|
+
throw new TypeError(`Invalid collectionSelection:\n${errors.join('\n')}`);
|
|
23
|
+
}
|
|
24
|
+
const cookieSource = config.sources.find(x => x.type === 'cookie');
|
|
25
|
+
const cookie = cookieSource != null ? {
|
|
26
|
+
type: 'cookie',
|
|
27
|
+
cookieName: cookieSource.cookieName ?? COOKIE_SOURCE_DEFAULTS.cookieName,
|
|
28
|
+
activatePath: cookieSource.activatePath ?? COOKIE_SOURCE_DEFAULTS.activatePath,
|
|
29
|
+
resetPath: cookieSource.resetPath ?? COOKIE_SOURCE_DEFAULTS.resetPath,
|
|
30
|
+
maxAge: cookieSource.maxAge,
|
|
31
|
+
} : null;
|
|
32
|
+
const allowed = (value) => value != null && isCollectionNameAllowed(value, config.allow);
|
|
33
|
+
const matchers = config.sources.map((source) => {
|
|
34
|
+
switch (source.type) {
|
|
35
|
+
case 'host': {
|
|
36
|
+
const parts = splitPattern(source.pattern);
|
|
37
|
+
const re = new RegExp(`^${escapeRegExp(parts.before.toLowerCase())}${NAME_GROUP}${escapeRegExp(parts.after.toLowerCase())}$`);
|
|
38
|
+
return (url) => {
|
|
39
|
+
const name = re.exec(url.hostname.toLowerCase())?.[1];
|
|
40
|
+
return allowed(name) ? { collectionName: name } : null;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
case 'path': {
|
|
44
|
+
const parts = splitPattern(source.prefix);
|
|
45
|
+
const re = new RegExp(`^${escapeRegExp(parts.before)}${NAME_GROUP}${escapeRegExp(parts.after)}(/.*)?$`);
|
|
46
|
+
return (url) => {
|
|
47
|
+
const match = re.exec(url.pathname);
|
|
48
|
+
if (match == null || !allowed(match[1])) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
let pathname;
|
|
52
|
+
try {
|
|
53
|
+
pathname = decodeURI(match[2] ?? '/');
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return { collectionName: match[1], pathname };
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
case 'query':
|
|
62
|
+
return (url) => {
|
|
63
|
+
const name = url.searchParams.get(source.param);
|
|
64
|
+
return allowed(name) ? { collectionName: name } : null;
|
|
65
|
+
};
|
|
66
|
+
case 'cookie':
|
|
67
|
+
return (_url, request) => {
|
|
68
|
+
const name = getCookieValue(request, cookie.cookieName);
|
|
69
|
+
return allowed(name) ? { collectionName: name } : null;
|
|
70
|
+
};
|
|
71
|
+
case 'header':
|
|
72
|
+
return (_url, request) => {
|
|
73
|
+
const name = request.headers.get(source.name)?.trim();
|
|
74
|
+
return allowed(name) ? { collectionName: name } : null;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
compiled = { config, cookie, matchers };
|
|
79
|
+
compiledConfigs.set(config, compiled);
|
|
80
|
+
return compiled;
|
|
81
|
+
}
|
|
82
|
+
// A Location value that stays on this site: a path that starts with exactly one
|
|
83
|
+
// '/'. A value such as '//example.com' or '/\example.com' is a URL of another
|
|
84
|
+
// site for a browser, so it becomes '/'. So does a value with control characters.
|
|
85
|
+
export function sameSiteLocation(value) {
|
|
86
|
+
if (!value.startsWith('/') || value[1] === '/' || value[1] === '\\' || /[\u0000-\u001f\u007f]/.test(value)) {
|
|
87
|
+
return '/';
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
function cookieAttributes(url, maxAge) {
|
|
92
|
+
const segments = ['Path=/'];
|
|
93
|
+
if (maxAge != null) {
|
|
94
|
+
segments.push(`Max-Age=${maxAge}`);
|
|
95
|
+
}
|
|
96
|
+
segments.push('HttpOnly');
|
|
97
|
+
if (url.protocol === 'https:') {
|
|
98
|
+
segments.push('Secure');
|
|
99
|
+
}
|
|
100
|
+
segments.push('SameSite=Lax');
|
|
101
|
+
return segments;
|
|
102
|
+
}
|
|
103
|
+
function redirect(location, setCookie) {
|
|
104
|
+
const headers = new Headers();
|
|
105
|
+
headers.append('Set-Cookie', setCookie);
|
|
106
|
+
headers.set('Location', sameSiteLocation(location));
|
|
107
|
+
// A redirect that sets a cookie must not be stored by a shared cache.
|
|
108
|
+
headers.set('Cache-Control', 'no-store');
|
|
109
|
+
return new Response(null, { status: 308, headers });
|
|
110
|
+
}
|
|
111
|
+
function setCookieValue(cookie, url, collectionName) {
|
|
112
|
+
return [`${cookie.cookieName}=${collectionName}`, ...cookieAttributes(url, cookie.maxAge)].join('; ');
|
|
113
|
+
}
|
|
114
|
+
function clearCookieValue(cookie, url) {
|
|
115
|
+
return [`${cookie.cookieName}=`, ...cookieAttributes(url, 0)].join('; ');
|
|
116
|
+
}
|
|
117
|
+
// True if the result selects the collection through the URL (a host, path, or
|
|
118
|
+
// query source). Then the URL names the collection. A sticky source gives a
|
|
119
|
+
// redirect in place of a file, so its result is never selected by URL.
|
|
120
|
+
export function isSelectedByUrl(result, collectionName) {
|
|
121
|
+
return result.response == null && result.collectionName === collectionName &&
|
|
122
|
+
(result.matchedBy === 'host' || result.matchedBy === 'path' || result.matchedBy === 'query');
|
|
123
|
+
}
|
|
124
|
+
// Choose the collection for a request. With no sources, every request gets the
|
|
125
|
+
// default collection (collectionName: null). Throws a TypeError if the config is
|
|
126
|
+
// not valid.
|
|
127
|
+
export function resolveCollection(request, config) {
|
|
128
|
+
if (config == null) {
|
|
129
|
+
return { collectionName: null };
|
|
130
|
+
}
|
|
131
|
+
const compiled = compile(config);
|
|
132
|
+
const url = new URL(request.url);
|
|
133
|
+
// The activate and reset paths of the cookie source.
|
|
134
|
+
const cookie = compiled.cookie;
|
|
135
|
+
if (cookie != null && (request.method === 'GET' || request.method === 'HEAD')) {
|
|
136
|
+
if (url.pathname === cookie.activatePath) {
|
|
137
|
+
const collectionName = url.searchParams.get('collection');
|
|
138
|
+
if (collectionName == null) {
|
|
139
|
+
return { collectionName: null, matchedBy: 'cookie', response: new Response(`Missing required 'collection' query parameter.`, { status: 400 }) };
|
|
140
|
+
}
|
|
141
|
+
if (!isValidCollectionName(collectionName)) {
|
|
142
|
+
return { collectionName: null, matchedBy: 'cookie', response: new Response(`The 'collection' query parameter is not a valid collection name. ${COLLECTION_NAME_RULE}`, { status: 400 }) };
|
|
143
|
+
}
|
|
144
|
+
if (!isCollectionNameAllowed(collectionName, config.allow)) {
|
|
145
|
+
return { collectionName: null, matchedBy: 'cookie', response: new Response(`The collection '${collectionName}' cannot be selected.`, { status: 403 }) };
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
collectionName,
|
|
149
|
+
matchedBy: 'cookie',
|
|
150
|
+
response: redirect(url.searchParams.get('redirectTo') ?? '/', setCookieValue(cookie, url, collectionName)),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (url.pathname === cookie.resetPath) {
|
|
154
|
+
return {
|
|
155
|
+
collectionName: null,
|
|
156
|
+
matchedBy: 'cookie',
|
|
157
|
+
response: redirect(url.searchParams.get('redirectTo') ?? '/', clearCookieValue(cookie, url)),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (const [index, matcher] of compiled.matchers.entries()) {
|
|
162
|
+
const match = matcher(url, request);
|
|
163
|
+
if (match == null) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const source = config.sources[index];
|
|
167
|
+
const result = { collectionName: match.collectionName, matchedBy: source.type };
|
|
168
|
+
if (match.pathname != null) {
|
|
169
|
+
result.pathname = match.pathname;
|
|
170
|
+
}
|
|
171
|
+
// Sticky: set the cookie, and redirect to the URL without the selector.
|
|
172
|
+
if ((source.type === 'path' || source.type === 'query') && source.sticky === 'cookie' && cookie != null &&
|
|
173
|
+
(request.method === 'GET' || request.method === 'HEAD')) {
|
|
174
|
+
let location;
|
|
175
|
+
if (source.type === 'path') {
|
|
176
|
+
// The path without the prefix, not decoded.
|
|
177
|
+
const parts = splitPattern(source.prefix);
|
|
178
|
+
const prefix = parts.before + match.collectionName + parts.after;
|
|
179
|
+
location = (url.pathname.slice(prefix.length) || '/') + url.search;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const params = new URLSearchParams(url.search);
|
|
183
|
+
params.delete(source.param);
|
|
184
|
+
const search = params.toString();
|
|
185
|
+
location = url.pathname + (search !== '' ? `?${search}` : '');
|
|
186
|
+
}
|
|
187
|
+
result.response = redirect(location, setCookieValue(cookie, url, match.collectionName));
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
return { collectionName: null };
|
|
192
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from-cookie.d.ts","sourceRoot":"","sources":["../../../../src/server/collection-selector/from-cookie.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"from-cookie.d.ts","sourceRoot":"","sources":["../../../../src/server/collection-selector/from-cookie.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EACnC,MAAM,kCAAkC,CAAC;AAqB1C,MAAM,MAAM,4BAA4B,GAAG;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qBAAa,wBAAyB,YAAW,6BAA6B;IAC5E,cAAqB;IACrB,YAAmB,UAAU,EAAE,MAAM,EAAE;IACvC,YAAmB,IAAI,EAAE,OAAO,CAAC,4BAA4B,CAAC,EAAE;IAqBzD,IAAI,EAAE,4BAA4B,CAAC;IAEnC,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,4BAA4B,CAEvE;IAEM,aAAa,CAAC,OAAO,EAAE,OAAO,mBAkEpC;CACF;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,4BAA4B,CAAC;IAC7C,gBAAgB,EAAE,QAAQ,GAAG,IAAI,CAAC;CACnC;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,4BAA4B,GAAG,gBAAgB,CAevH"}
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
* Copyright Fastly, Inc.
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
|
+
import { COLLECTION_NAME_RULE, isValidCollectionName } from '../../models/collections/index.js';
|
|
5
6
|
import { getCookieValue } from '../util/cookies.js';
|
|
6
|
-
// The characters that a cookie value can have (cookie-octet in RFC 6265):
|
|
7
|
-
// no controls, spaces, '"', ',', ';', or '\'.
|
|
8
|
-
const COOKIE_VALUE_PATTERN = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]+$/;
|
|
9
7
|
// The redirect target after activate or reset. Only a path on the same site
|
|
10
8
|
// is allowed; anything else gives '/'.
|
|
11
9
|
function getRedirectTo(url) {
|
|
@@ -55,9 +53,9 @@ export class CookieCollectionSelector {
|
|
|
55
53
|
if (collectionName == null) {
|
|
56
54
|
return new Response(`Missing required 'collection' query parameter.`, { status: 400 });
|
|
57
55
|
}
|
|
58
|
-
// The value goes into Set-Cookie
|
|
59
|
-
if (!
|
|
60
|
-
return new Response(`The 'collection' query parameter
|
|
56
|
+
// The value goes into Set-Cookie. A valid collection name is also a valid cookie value.
|
|
57
|
+
if (!isValidCollectionName(collectionName)) {
|
|
58
|
+
return new Response(`The 'collection' query parameter is not a valid collection name. ${COLLECTION_NAME_RULE}`, { status: 400 });
|
|
61
59
|
}
|
|
62
60
|
const redirectTo = getRedirectTo(url);
|
|
63
61
|
const cookieSegments = [
|
|
@@ -78,7 +76,7 @@ export class CookieCollectionSelector {
|
|
|
78
76
|
headers.append("Set-Cookie", cookieSegments.join(';'));
|
|
79
77
|
headers.set("Location", redirectTo);
|
|
80
78
|
return new Response(null, {
|
|
81
|
-
status:
|
|
79
|
+
status: 308,
|
|
82
80
|
headers,
|
|
83
81
|
});
|
|
84
82
|
}
|
|
@@ -99,7 +97,7 @@ export class CookieCollectionSelector {
|
|
|
99
97
|
headers.append("Set-Cookie", cookieSegments.join(';'));
|
|
100
98
|
headers.set("Location", redirectTo);
|
|
101
99
|
return new Response(null, {
|
|
102
|
-
status:
|
|
100
|
+
status: 308,
|
|
103
101
|
headers,
|
|
104
102
|
});
|
|
105
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from-request.d.ts","sourceRoot":"","sources":["../../../../src/server/collection-selector/from-request.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EACnC,MAAM,kCAAkC,CAAC;AAE1C,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,4BAA4B,CAAC;AAC7F,KAAK,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;AAG3D,qBAAa,iCAAkC,YAAW,6BAA6B;
|
|
1
|
+
{"version":3,"file":"from-request.d.ts","sourceRoot":"","sources":["../../../../src/server/collection-selector/from-request.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EACnC,MAAM,kCAAkC,CAAC;AAE1C,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,4BAA4B,CAAC;AAC7F,KAAK,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;AAG3D,qBAAa,iCAAkC,YAAW,6BAA6B;IACrF,YACE,IAAI,EAAE,2BAA2B,EAGlC;IAEM,IAAI,EAAE,2BAA2B,CAAC;IAElC,iBAAiB,CAAC,OAAO,EAAE,OAAO,gCAExC;CACF;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,2BAA2B,GAAG,4BAA4B,CAK7G;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,uBAAuB,GAAG,4BAA4B,CAI5G;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,4BAA4B,CAKhG"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export { type StaticPublishRc } from '../models/config/static-publish-rc.js';
|
|
2
|
+
export { type StaticPublishProject } from '../models/config/static-publish-project.js';
|
|
2
3
|
export { type PublishContentConfig } from '../models/config/publish-content-config.js';
|
|
3
4
|
export * as collectionSelector from './collection-selector/index.js';
|
|
5
|
+
export { type ResolveCollectionResult, resolveCollection, } from './collection-selection/index.js';
|
|
6
|
+
export { type CollectionSelection, type CollectionSelectionSource, previewUrl, validateCollectionSelection, } from '../models/config/collection-selection.js';
|
|
4
7
|
export { CookieCollectionSelector, type CookieCollectionSelectorOpts, } from './collection-selector/from-cookie.js';
|
|
5
8
|
export { type StorageProvider, type StorageProviderBuilder, type StorageEntry, registerStorageProviderBuilder, } from './storage/storage-provider.js';
|
|
6
9
|
export { setSecretStoreForS3Credentials, setSecretStoreKeyForS3AccessKeyId, setSecretStoreKeyForS3SecretAccessKey, setS3CredentialsBuilder, } from './storage/s3-storage-provider.js';
|
|
7
|
-
export { PublisherServer } from './publisher-server/index.js';
|
|
10
|
+
export { type GetMatchingAssetOptions, type ServeFallbackOptions, type ServeRequestOptions, PublisherServer, } from './publisher-server/index.js';
|
|
8
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,kBAAkB,MAAM,gCAAgC,CAAC;AACrE,OAAO,EACL,KAAK,uBAAuB,EAC5B,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,UAAU,EACV,2BAA2B,GAC5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,wBAAwB,EACxB,KAAK,4BAA4B,GAClC,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,8BAA8B,GAC/B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,qCAAqC,EACrC,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,eAAe,GAChB,MAAM,6BAA6B,CAAC"}
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
4
|
*/
|
|
5
5
|
export * as collectionSelector from './collection-selector/index.js';
|
|
6
|
+
export { resolveCollection, } from './collection-selection/index.js';
|
|
7
|
+
export { previewUrl, validateCollectionSelection, } from '../models/config/collection-selection.js';
|
|
6
8
|
export { CookieCollectionSelector, } from './collection-selector/from-cookie.js';
|
|
7
9
|
export { registerStorageProviderBuilder, } from './storage/storage-provider.js';
|
|
8
10
|
export { setSecretStoreForS3Credentials, setSecretStoreKeyForS3AccessKeyId, setSecretStoreKeyForS3SecretAccessKey, setS3CredentialsBuilder, } from './storage/s3-storage-provider.js';
|
|
9
|
-
export { PublisherServer } from './publisher-server/index.js';
|
|
11
|
+
export { PublisherServer, } from './publisher-server/index.js';
|
|
10
12
|
// Register storage builder providers
|
|
11
13
|
import { registerStorageProviderBuilder } from './storage/storage-provider.js';
|
|
12
14
|
import * as kvStoreProvider from './storage/kv-store-provider.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accept-html.d.ts","sourceRoot":"","sources":["../../../../src/server/publisher-server/accept-html.ts"],"names":[],"mappings":"AAYA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAyChE"}
|
|
@@ -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
|
+
}
|