@fastly/compute-js-static-publish 8.0.0 → 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 +1984 -0
- package/README.md +11 -4
- package/README.short.md +11 -4
- 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 +85 -35
- 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 +239 -300
- 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 +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/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 +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 +15 -3
- package/build/cli/cli/util/purge.d.ts.map +1 -1
- package/build/cli/cli/util/purge.js +23 -10
- 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 -6
- package/build/server/server/publisher-server/index.d.ts.map +1 -1
- package/build/server/server/publisher-server/index.js +370 -131
- 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 +23 -4
- 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,238 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
import { COLLECTION_NAME_RULE, isValidCollectionName } from '../collections/index.js';
|
|
6
|
+
// Collection selection: the options that choose which collection serves a
|
|
7
|
+
// request, for example for previews. The config is data only (strings, numbers,
|
|
8
|
+
// and booleans), so that each field can also be a scaffold flag.
|
|
9
|
+
// The resolver is in server/collection-selection/.
|
|
10
|
+
export const COLLECTION_PLACEHOLDER = '{collection}';
|
|
11
|
+
export const COOKIE_SOURCE_DEFAULTS = {
|
|
12
|
+
cookieName: 'publisher-collection',
|
|
13
|
+
activatePath: '/activate',
|
|
14
|
+
resetPath: '/reset',
|
|
15
|
+
};
|
|
16
|
+
const SOURCE_TYPES = ['host', 'path', 'query', 'cookie', 'header'];
|
|
17
|
+
// RFC 7230 token: the characters of a header name or a cookie name.
|
|
18
|
+
const TOKEN_PATTERN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
19
|
+
// A host label has at most 63 characters.
|
|
20
|
+
const MAX_LABEL_LENGTH = 63;
|
|
21
|
+
const ALLOW_PATTERN = /^[a-z0-9*-]+$/;
|
|
22
|
+
export function splitPattern(pattern) {
|
|
23
|
+
const index = pattern.indexOf(COLLECTION_PLACEHOLDER);
|
|
24
|
+
if (index === -1 || pattern.indexOf(COLLECTION_PLACEHOLDER, index + 1) !== -1) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
before: pattern.slice(0, index),
|
|
29
|
+
after: pattern.slice(index + COLLECTION_PLACEHOLDER.length),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// The fixed text in the host label that has the placeholder.
|
|
33
|
+
export function hostLabelFixedLength(parts) {
|
|
34
|
+
const before = parts.before.slice(parts.before.lastIndexOf('.') + 1);
|
|
35
|
+
const afterDot = parts.after.indexOf('.');
|
|
36
|
+
const after = afterDot === -1 ? parts.after : parts.after.slice(0, afterDot);
|
|
37
|
+
return before.length + after.length;
|
|
38
|
+
}
|
|
39
|
+
// The longest collection name that fits in the host label of a host pattern.
|
|
40
|
+
export function maxCollectionNameLengthForHost(pattern) {
|
|
41
|
+
const parts = splitPattern(pattern);
|
|
42
|
+
if (parts == null) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
return MAX_LABEL_LENGTH - hostLabelFixedLength(parts);
|
|
46
|
+
}
|
|
47
|
+
function escapeRegExp(value) {
|
|
48
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
49
|
+
}
|
|
50
|
+
export function allowPatternToRegExp(pattern) {
|
|
51
|
+
return new RegExp('^' + pattern.split('*').map(escapeRegExp).join('[a-z0-9-]*') + '$');
|
|
52
|
+
}
|
|
53
|
+
// Returns true if the name is valid, and allow (if set) has a pattern that matches it.
|
|
54
|
+
export function isCollectionNameAllowed(collectionName, allow) {
|
|
55
|
+
if (!isValidCollectionName(collectionName)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (allow == null) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return allow.some(pattern => allowPatternToRegExp(pattern).test(collectionName));
|
|
62
|
+
}
|
|
63
|
+
// Returns the errors in a collectionSelection config. An empty list means that it is valid.
|
|
64
|
+
export function validateCollectionSelection(config) {
|
|
65
|
+
const errors = [];
|
|
66
|
+
if (config == null || typeof config !== 'object' || Array.isArray(config)) {
|
|
67
|
+
return ['collectionSelection must be an object.'];
|
|
68
|
+
}
|
|
69
|
+
const { sources, allow, onMissing, noindex } = config;
|
|
70
|
+
if (!Array.isArray(sources)) {
|
|
71
|
+
errors.push('collectionSelection.sources must be an array.');
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
let cookieSources = 0;
|
|
75
|
+
let stickySources = 0;
|
|
76
|
+
sources.forEach((source, index) => {
|
|
77
|
+
const name = `collectionSelection.sources[${index}]`;
|
|
78
|
+
if (source == null || typeof source !== 'object') {
|
|
79
|
+
errors.push(`${name} must be an object.`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const s = source;
|
|
83
|
+
if (typeof s.type !== 'string' || !SOURCE_TYPES.includes(s.type)) {
|
|
84
|
+
errors.push(`${name}.type must be one of ${SOURCE_TYPES.map(x => `'${x}'`).join(', ')}.`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
switch (s.type) {
|
|
88
|
+
case 'host': {
|
|
89
|
+
const parts = typeof s.pattern === 'string' ? splitPattern(s.pattern) : null;
|
|
90
|
+
if (parts == null) {
|
|
91
|
+
errors.push(`${name}.pattern must be a string with exactly one ${COLLECTION_PLACEHOLDER}.`);
|
|
92
|
+
}
|
|
93
|
+
else if (!/^[a-z0-9.-]*$/i.test(parts.before + parts.after)) {
|
|
94
|
+
errors.push(`${name}.pattern must be a hostname: use only a-z, 0-9, '-', and '.' around ${COLLECTION_PLACEHOLDER}.`);
|
|
95
|
+
}
|
|
96
|
+
else if (MAX_LABEL_LENGTH - hostLabelFixedLength(parts) < 1) {
|
|
97
|
+
errors.push(`${name}.pattern: the host label with ${COLLECTION_PLACEHOLDER} has no room for a name (at most ${MAX_LABEL_LENGTH} characters).`);
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 'path': {
|
|
102
|
+
const parts = typeof s.prefix === 'string' ? splitPattern(s.prefix) : null;
|
|
103
|
+
if (parts == null) {
|
|
104
|
+
errors.push(`${name}.prefix must be a string with exactly one ${COLLECTION_PLACEHOLDER}.`);
|
|
105
|
+
}
|
|
106
|
+
else if (!parts.before.startsWith('/')) {
|
|
107
|
+
errors.push(`${name}.prefix must start with '/'.`);
|
|
108
|
+
}
|
|
109
|
+
else if (parts.after.endsWith('/')) {
|
|
110
|
+
errors.push(`${name}.prefix must not end with '/'.`);
|
|
111
|
+
}
|
|
112
|
+
else if (/[?#]/.test(parts.before + parts.after)) {
|
|
113
|
+
errors.push(`${name}.prefix must not contain '?' or '#'.`);
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'query':
|
|
118
|
+
if (typeof s.param !== 'string' || s.param === '') {
|
|
119
|
+
errors.push(`${name}.param must be a non-empty string.`);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case 'cookie':
|
|
123
|
+
cookieSources++;
|
|
124
|
+
if (s.cookieName !== undefined && (typeof s.cookieName !== 'string' || !TOKEN_PATTERN.test(s.cookieName))) {
|
|
125
|
+
errors.push(`${name}.cookieName must be a valid cookie name.`);
|
|
126
|
+
}
|
|
127
|
+
for (const field of ['activatePath', 'resetPath']) {
|
|
128
|
+
if (s[field] !== undefined && (typeof s[field] !== 'string' || !s[field].startsWith('/'))) {
|
|
129
|
+
errors.push(`${name}.${field} must be a string that starts with '/'.`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (s.maxAge !== undefined && (!Number.isInteger(s.maxAge) || s.maxAge < 0)) {
|
|
133
|
+
errors.push(`${name}.maxAge must be an integer that is 0 or more.`);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case 'header':
|
|
137
|
+
if (typeof s.name !== 'string' || !TOKEN_PATTERN.test(s.name)) {
|
|
138
|
+
errors.push(`${name}.name must be a valid header name.`);
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (s.sticky !== undefined) {
|
|
143
|
+
if (s.type !== 'path' && s.type !== 'query') {
|
|
144
|
+
errors.push(`${name}.sticky is only for the 'path' and 'query' sources.`);
|
|
145
|
+
}
|
|
146
|
+
else if (s.sticky !== 'cookie') {
|
|
147
|
+
errors.push(`${name}.sticky must be 'cookie'.`);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
stickySources++;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
if (cookieSources > 1) {
|
|
155
|
+
errors.push(`collectionSelection.sources must have at most one 'cookie' source.`);
|
|
156
|
+
}
|
|
157
|
+
if (stickySources > 0 && cookieSources === 0) {
|
|
158
|
+
errors.push(`sticky: 'cookie' needs a 'cookie' source in collectionSelection.sources, for the settings of the cookie.`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (allow !== undefined) {
|
|
162
|
+
if (!Array.isArray(allow) || !allow.every(x => typeof x === 'string' && ALLOW_PATTERN.test(x))) {
|
|
163
|
+
errors.push(`collectionSelection.allow must be an array of patterns. Use a-z, 0-9, '-', and '*'.`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (onMissing !== undefined && onMissing !== 'not-found' && onMissing !== 'default') {
|
|
167
|
+
errors.push(`collectionSelection.onMissing must be 'not-found' or 'default'.`);
|
|
168
|
+
}
|
|
169
|
+
if (noindex !== undefined && typeof noindex !== 'boolean') {
|
|
170
|
+
errors.push(`collectionSelection.noindex must be a boolean.`);
|
|
171
|
+
}
|
|
172
|
+
return errors;
|
|
173
|
+
}
|
|
174
|
+
// The URL that shows a collection, from the first source that can make one.
|
|
175
|
+
// baseUrl is the URL of the service, for example 'https://example.edgecompute.app'.
|
|
176
|
+
// The host source uses only its protocol. Returns null if no source can make a
|
|
177
|
+
// URL (for example, only a header source). Throws for a name that cannot be
|
|
178
|
+
// selected, or that does not fit in the host label.
|
|
179
|
+
export function previewUrl(collectionName, baseUrl, config) {
|
|
180
|
+
if (!isValidCollectionName(collectionName)) {
|
|
181
|
+
throw new Error(`'${collectionName}' is not a valid collection name. ${COLLECTION_NAME_RULE}`);
|
|
182
|
+
}
|
|
183
|
+
if (!isCollectionNameAllowed(collectionName, config.allow)) {
|
|
184
|
+
throw new Error(`'${collectionName}' is not in collectionSelection.allow.`);
|
|
185
|
+
}
|
|
186
|
+
const base = new URL(baseUrl);
|
|
187
|
+
for (const source of config.sources) {
|
|
188
|
+
switch (source.type) {
|
|
189
|
+
case 'host': {
|
|
190
|
+
const maxLength = maxCollectionNameLengthForHost(source.pattern);
|
|
191
|
+
if (collectionName.length > maxLength) {
|
|
192
|
+
throw new Error(`'${collectionName}' is too long for the host pattern '${source.pattern}': a host label has at most ${MAX_LABEL_LENGTH} characters, so the name can have at most ${maxLength}.`);
|
|
193
|
+
}
|
|
194
|
+
return `${base.protocol}//${source.pattern.replace(COLLECTION_PLACEHOLDER, collectionName).toLowerCase()}/`;
|
|
195
|
+
}
|
|
196
|
+
case 'path':
|
|
197
|
+
return `${base.origin}${source.prefix.replace(COLLECTION_PLACEHOLDER, collectionName)}/`;
|
|
198
|
+
case 'query': {
|
|
199
|
+
const url = new URL('/', base);
|
|
200
|
+
url.searchParams.set(source.param, collectionName);
|
|
201
|
+
return url.href;
|
|
202
|
+
}
|
|
203
|
+
case 'cookie': {
|
|
204
|
+
const url = new URL(source.activatePath ?? COOKIE_SOURCE_DEFAULTS.activatePath, base);
|
|
205
|
+
url.searchParams.set('collection', collectionName);
|
|
206
|
+
url.searchParams.set('redirectTo', '/');
|
|
207
|
+
return url.href;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
// The preview URL of each source that can make one, with the {collection}
|
|
214
|
+
// placeholder in it. For example, for CI tools that show the link of a pull
|
|
215
|
+
// request. baseUrl is like the one of previewUrl(), and can be a placeholder
|
|
216
|
+
// such as 'https://<service domain>'.
|
|
217
|
+
export function previewUrlTemplates(baseUrl, config) {
|
|
218
|
+
const base = baseUrl.replace(/\/+$/, '');
|
|
219
|
+
const protocol = /^([a-z]+:)\/\//i.exec(base)?.[1] ?? 'https:';
|
|
220
|
+
const result = [];
|
|
221
|
+
for (const source of config.sources) {
|
|
222
|
+
switch (source.type) {
|
|
223
|
+
case 'host':
|
|
224
|
+
result.push({ type: 'host', url: `${protocol}//${source.pattern}/` });
|
|
225
|
+
break;
|
|
226
|
+
case 'path':
|
|
227
|
+
result.push({ type: 'path', url: `${base}${source.prefix}/` });
|
|
228
|
+
break;
|
|
229
|
+
case 'query':
|
|
230
|
+
result.push({ type: 'query', url: `${base}/?${encodeURIComponent(source.param)}=${COLLECTION_PLACEHOLDER}` });
|
|
231
|
+
break;
|
|
232
|
+
case 'cookie':
|
|
233
|
+
result.push({ type: 'cookie', url: `${base}${source.activatePath ?? COOKIE_SOURCE_DEFAULTS.activatePath}?collection=${COLLECTION_PLACEHOLDER}&redirectTo=%2F` });
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type ItemPattern = string | RegExp;
|
|
2
|
+
export declare function parseItemPatterns(items: readonly string[], onError?: (index: number, item: string) => void): ItemPattern[];
|
|
3
|
+
export declare function testItemPatterns(patterns: readonly ItemPattern[], path: string): boolean;
|
|
4
|
+
//# sourceMappingURL=item-patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-patterns.d.ts","sourceRoot":"","sources":["../../../../src/models/config/item-patterns.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAI1C,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,GAC9C,WAAW,EAAE,CAwBf;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAUxF"}
|
|
@@ -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"}
|