@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,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// The settings that each template reads: build.<template> (read by the build of
|
|
6
|
+
// the app) and templateOptions.<template> (read by the code of the app at
|
|
7
|
+
// runtime). A setting that no template declares gives a warning, not an error,
|
|
8
|
+
// so that an older version of this package can read a newer file.
|
|
9
|
+
export const TEMPLATE_SETTINGS = {
|
|
10
|
+
hono: {
|
|
11
|
+
build: ['extensionsDir'],
|
|
12
|
+
templateOptions: ['bindings', 'extensions'],
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
const isPlainObject = (value) => typeof value === 'object' && value != null && !Array.isArray(value);
|
|
16
|
+
// Checks the build and templateOptions fields of static-publish.rc.js or of
|
|
17
|
+
// static-publish.project.js.
|
|
18
|
+
export function checkTemplateSettings(build, templateOptions) {
|
|
19
|
+
const errors = [];
|
|
20
|
+
const warnings = [];
|
|
21
|
+
for (const [field, value] of [['build', build], ['templateOptions', templateOptions]]) {
|
|
22
|
+
if (value === undefined) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (!isPlainObject(value)) {
|
|
26
|
+
errors.push(`${field} must be an object.`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
for (const [templateName, settings] of Object.entries(value)) {
|
|
30
|
+
const declared = TEMPLATE_SETTINGS[templateName]?.[field];
|
|
31
|
+
if (declared == null) {
|
|
32
|
+
warnings.push(`${field}.${templateName}: no template '${templateName}' has these settings. They are ignored.`);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (!isPlainObject(settings)) {
|
|
36
|
+
errors.push(`${field}.${templateName} must be an object.`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
for (const key of Object.keys(settings)) {
|
|
40
|
+
if (!declared.includes(key)) {
|
|
41
|
+
warnings.push(`${field}.${templateName}.${key} is not a setting of the template '${templateName}'. It is ignored.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// The settings of the hono template.
|
|
47
|
+
if (isPlainObject(build) && isPlainObject(build.hono) && build.hono.extensionsDir !== undefined) {
|
|
48
|
+
const extensionsDir = build.hono.extensionsDir;
|
|
49
|
+
if (typeof extensionsDir !== 'string' || !/^\.\.?\//.test(extensionsDir)) {
|
|
50
|
+
errors.push(`build.hono.extensionsDir must be a relative path that starts with './' or '../'.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (isPlainObject(templateOptions) && isPlainObject(templateOptions.hono)) {
|
|
54
|
+
const hono = templateOptions.hono;
|
|
55
|
+
if (hono.bindings !== undefined) {
|
|
56
|
+
if (!isPlainObject(hono.bindings)) {
|
|
57
|
+
errors.push('templateOptions.hono.bindings must be an object.');
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
for (const [name, resource] of Object.entries(hono.bindings)) {
|
|
61
|
+
if (typeof resource !== 'string' || resource === '') {
|
|
62
|
+
errors.push(`templateOptions.hono.bindings.${name} must be a non-empty string, for example 'ConfigStore:site_config'.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (hono.extensions !== undefined && !isPlainObject(hono.extensions)) {
|
|
68
|
+
errors.push('templateOptions.hono.extensions must be an object, with the options of each module by module name.');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { errors, warnings };
|
|
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,48 @@
|
|
|
1
|
+
import type { Acl } from 'fastly:acl';
|
|
2
|
+
import type { Backend } from 'fastly:backend';
|
|
3
|
+
import type { ConfigStore } from 'fastly:config-store';
|
|
4
|
+
import type { KVStore } from 'fastly:kv-store';
|
|
5
|
+
import type { Logger } from 'fastly:logger';
|
|
6
|
+
import type { SecretStore } from 'fastly:secret-store';
|
|
7
|
+
import type { Hono } from 'hono';
|
|
8
|
+
export type ExtensionBindings = Record<string, string>;
|
|
9
|
+
type ResourceTypes = {
|
|
10
|
+
Acl: Acl;
|
|
11
|
+
Backend: Backend;
|
|
12
|
+
ConfigStore: ConfigStore;
|
|
13
|
+
env: string;
|
|
14
|
+
KVStore: KVStore;
|
|
15
|
+
Logger: Logger;
|
|
16
|
+
SecretStore: SecretStore;
|
|
17
|
+
};
|
|
18
|
+
export type BindingResource<R> = R extends `${infer T}:${string}` ? (T extends keyof ResourceTypes ? ResourceTypes[T] | undefined : unknown) : R extends keyof ResourceTypes ? ResourceTypes[R] | undefined : unknown;
|
|
19
|
+
export type ExtensionEnv<B extends ExtensionBindings> = {
|
|
20
|
+
Bindings: {
|
|
21
|
+
[K in keyof B]: BindingResource<B[K]>;
|
|
22
|
+
};
|
|
23
|
+
Variables: Record<string, any>;
|
|
24
|
+
};
|
|
25
|
+
export declare const EXTENSION_PHASES: readonly ['middleware', 'beforeFiles', 'afterFiles'];
|
|
26
|
+
export type ExtensionPhase = typeof EXTENSION_PHASES[number];
|
|
27
|
+
export type ExtensionPhaseFunction<B extends ExtensionBindings = ExtensionBindings, O = any> = (app: Hono<ExtensionEnv<B>, any, any>, options: O | undefined) => void;
|
|
28
|
+
export type ExtensionPhases<B extends ExtensionBindings = ExtensionBindings, O = any> = {
|
|
29
|
+
[P in ExtensionPhase]?: ExtensionPhaseFunction<B, O>;
|
|
30
|
+
};
|
|
31
|
+
export type DefineExtensionOptions<B extends ExtensionBindings = ExtensionBindings> = {
|
|
32
|
+
bindings?: B;
|
|
33
|
+
};
|
|
34
|
+
export type Extension = {
|
|
35
|
+
kind: 'extension';
|
|
36
|
+
bindings: ExtensionBindings;
|
|
37
|
+
phases: ExtensionPhases<any>;
|
|
38
|
+
};
|
|
39
|
+
export type ExtensionEntry = {
|
|
40
|
+
name: string;
|
|
41
|
+
file: string;
|
|
42
|
+
module: Extension;
|
|
43
|
+
};
|
|
44
|
+
export declare function defineExtension<O = any>(phases: ExtensionPhaseFunction<{}, O> | ExtensionPhases<{}, O>): Extension;
|
|
45
|
+
export declare function defineExtension<const B extends ExtensionBindings, O = any>(options: DefineExtensionOptions<B>, phases: ExtensionPhaseFunction<B, O> | ExtensionPhases<B, O>): Extension;
|
|
46
|
+
export declare function mergeBindings(appBindings: ExtensionBindings | undefined, entries: ExtensionEntry[]): ExtensionBindings;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=extensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../../src/hono/extensions.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// The phases of the app, in the order that the app runs them:
|
|
6
|
+
// - middleware: before all other phases, for example a login check.
|
|
7
|
+
// - beforeFiles: before the published files.
|
|
8
|
+
// - afterFiles: after the published files, only for the requests that no
|
|
9
|
+
// published file matches.
|
|
10
|
+
export const EXTENSION_PHASES = ['middleware', 'beforeFiles', 'afterFiles'];
|
|
11
|
+
export function defineExtension(optionsOrPhases, phases) {
|
|
12
|
+
const [options, value] = phases === undefined ?
|
|
13
|
+
[{}, optionsOrPhases] :
|
|
14
|
+
[optionsOrPhases, phases];
|
|
15
|
+
return {
|
|
16
|
+
kind: 'extension',
|
|
17
|
+
bindings: { ...options.bindings },
|
|
18
|
+
phases: typeof value === 'function' ? { middleware: value } : value,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const isPlainObject = (value) => typeof value === 'object' && value != null && !Array.isArray(value);
|
|
22
|
+
// Checks the modules of the manifest, and merges their bindings with the
|
|
23
|
+
// bindings of the app (templateOptions.hono.bindings), for buildFire(). The
|
|
24
|
+
// same name with the same resource is allowed. Throws for a module that does not
|
|
25
|
+
// default-export defineExtension(…), for phases that are not correct, or for
|
|
26
|
+
// one name with two different resources; the message names the file. Call it at
|
|
27
|
+
// the top level of the app, so that an error stops the build.
|
|
28
|
+
export function mergeBindings(appBindings, entries) {
|
|
29
|
+
const merged = {};
|
|
30
|
+
const sourceOf = {};
|
|
31
|
+
const add = (bindings, source) => {
|
|
32
|
+
for (const [name, resource] of Object.entries(bindings)) {
|
|
33
|
+
if (name in merged && merged[name] !== resource) {
|
|
34
|
+
throw new Error(`The binding '${name}' is '${merged[name]}' in ${sourceOf[name]}, ` +
|
|
35
|
+
`but '${resource}' in ${source}. Use the same resource, or another name.`);
|
|
36
|
+
}
|
|
37
|
+
merged[name] = resource;
|
|
38
|
+
sourceOf[name] ??= source;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
add(appBindings ?? {}, 'templateOptions.hono.bindings');
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
const source = `hono-extensions/${entry.file}`;
|
|
44
|
+
const module = entry.module;
|
|
45
|
+
if (module == null || module.kind !== 'extension') {
|
|
46
|
+
throw new Error(`${source}: the default export must be defineExtension(…).`);
|
|
47
|
+
}
|
|
48
|
+
const phases = module.phases;
|
|
49
|
+
const keys = isPlainObject(phases) ? Object.keys(phases) : [];
|
|
50
|
+
const unknown = keys.filter(key => !EXTENSION_PHASES.includes(key));
|
|
51
|
+
if (!isPlainObject(phases) || keys.length === 0 || unknown.length > 0) {
|
|
52
|
+
throw new Error(`${source}: defineExtension() needs a function, or an object with a function ` +
|
|
53
|
+
`for one or more of the phases ${EXTENSION_PHASES.join(', ')}.` +
|
|
54
|
+
(unknown.length === 1 ? ` '${unknown[0]}' is not a phase.` : '') +
|
|
55
|
+
(unknown.length > 1 ? ` ${unknown.map(x => `'${x}'`).join(', ')} are not phases.` : ''));
|
|
56
|
+
}
|
|
57
|
+
for (const key of keys) {
|
|
58
|
+
if (typeof phases[key] !== 'function') {
|
|
59
|
+
throw new Error(`${source}: the phase ${key} must be a function.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
add(module.bindings ?? {}, source);
|
|
63
|
+
}
|
|
64
|
+
return merged;
|
|
65
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Context, MiddlewareHandler, NotFoundHandler } from 'hono';
|
|
2
|
+
import { PublisherServer, type StaticPublishRc } from '../server/index.js';
|
|
3
|
+
import { type ServeStaticPathOptions } from './path.js';
|
|
4
|
+
export { type BindingResource, type DefineExtensionOptions, EXTENSION_PHASES, type Extension, type ExtensionBindings, type ExtensionEntry, type ExtensionEnv, type ExtensionPhase, type ExtensionPhaseFunction, type ExtensionPhases, defineExtension, mergeBindings, } from './extensions.js';
|
|
5
|
+
export type StaticPublisherVariables = {
|
|
6
|
+
staticPublisher: {
|
|
7
|
+
publisherServer: PublisherServer;
|
|
8
|
+
collectionName: string | null;
|
|
9
|
+
pathname?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type CollectionNameOption = string | null | ((c: Context) => string | null | undefined);
|
|
13
|
+
export type ServeStaticOptions = ServeStaticPathOptions<Context> & {
|
|
14
|
+
collectionName?: CollectionNameOption;
|
|
15
|
+
};
|
|
16
|
+
export type ServeFallbackOptions = {
|
|
17
|
+
collectionName?: CollectionNameOption;
|
|
18
|
+
};
|
|
19
|
+
export type PublisherServerMiddlewareDefaults = {
|
|
20
|
+
collectionName?: CollectionNameOption;
|
|
21
|
+
};
|
|
22
|
+
export type PublisherServerMiddleware = {
|
|
23
|
+
publisherServer: PublisherServer;
|
|
24
|
+
serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
|
|
25
|
+
serveFallback: (options?: ServeFallbackOptions) => NotFoundHandler;
|
|
26
|
+
selectCollection: () => MiddlewareHandler;
|
|
27
|
+
};
|
|
28
|
+
export declare function fromPublisherServer(server: PublisherServer, defaults?: PublisherServerMiddlewareDefaults): PublisherServerMiddleware;
|
|
29
|
+
export declare function fromStaticPublishRc(rc: StaticPublishRc, defaults?: PublisherServerMiddlewareDefaults): PublisherServerMiddleware;
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hono/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAGxE,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,KAAK,sBAAsB,EAA8B,MAAM,WAAW,CAAC;AAEpF,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AAIzB,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE;QACf,eAAe,EAAE,eAAe,CAAC;QAGjC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;QAE9B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH,CAAC;AAMF,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAE/F,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC,OAAO,CAAC,GAAG;IACjE,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC,CAAC;AAIF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,eAAe,EAAE,eAAe,CAAC;IAIjC,WAAW,EAAE,CAAC,OAAO,CAAC,EAAE,kBAAkB,KAAK,iBAAiB,CAAC;IAIjE,aAAa,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,eAAe,CAAC;IAKnE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;CAC3C,CAAC;AAsBF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,GAAE,iCAAsC,GAAG,yBAAyB,CAkDxI;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,eAAe,EAAE,QAAQ,GAAE,iCAAsC,GAAG,yBAAyB,CAEpI"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// Import from the package entry point, which registers the storage providers.
|
|
6
|
+
import { PublisherServer } from '../server/index.js';
|
|
7
|
+
import { resolveServeStaticPathname } from './path.js';
|
|
8
|
+
export { EXTENSION_PHASES, defineExtension, mergeBindings, } from './extensions.js';
|
|
9
|
+
// The selection that selectCollection() of this server made for the request.
|
|
10
|
+
function getSelection(c, server) {
|
|
11
|
+
const selection = c.var.staticPublisher;
|
|
12
|
+
return selection?.publisherServer === server ? selection : undefined;
|
|
13
|
+
}
|
|
14
|
+
function resolveCollectionName(c, option, selection) {
|
|
15
|
+
const value = typeof option === 'function' ? option(c) : option;
|
|
16
|
+
if (value !== undefined) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
// The collection that selectCollection() chose. Without a selection,
|
|
20
|
+
// undefined selects the active collection of the PublisherServer.
|
|
21
|
+
return selection != null ? selection.collectionName : undefined;
|
|
22
|
+
}
|
|
23
|
+
export function fromPublisherServer(server, defaults = {}) {
|
|
24
|
+
const serveStatic = (callOptions = {}) => {
|
|
25
|
+
const options = { ...defaults, ...callOptions };
|
|
26
|
+
return async (c, next) => {
|
|
27
|
+
const selection = getSelection(c, server);
|
|
28
|
+
// For a path source, the path without its prefix. A path option
|
|
29
|
+
// replaces the request path (see resolveServeStaticPathname()).
|
|
30
|
+
const requestPath = selection?.pathname ?? c.req.path;
|
|
31
|
+
const pathname = resolveServeStaticPathname(requestPath, c, options);
|
|
32
|
+
const response = pathname != null ? await server.serveRequest(c.req.raw, {
|
|
33
|
+
collectionName: resolveCollectionName(c, options.collectionName, selection),
|
|
34
|
+
pathname,
|
|
35
|
+
fallback: false,
|
|
36
|
+
healthCheck: false,
|
|
37
|
+
}) : null;
|
|
38
|
+
if (response == null) {
|
|
39
|
+
await next();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return response;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const serveFallback = (callOptions = {}) => {
|
|
46
|
+
const options = { ...defaults, ...callOptions };
|
|
47
|
+
return async (c) => {
|
|
48
|
+
const response = await server.serveFallback(c.req.raw, {
|
|
49
|
+
collectionName: resolveCollectionName(c, options.collectionName, getSelection(c, server)),
|
|
50
|
+
});
|
|
51
|
+
return response ?? c.text('404 Not Found', 404);
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const selectCollection = () => {
|
|
55
|
+
return async (c, next) => {
|
|
56
|
+
const selection = server.resolveCollection(c.req.raw);
|
|
57
|
+
if (selection.response != null) {
|
|
58
|
+
return selection.response;
|
|
59
|
+
}
|
|
60
|
+
c.set('staticPublisher', {
|
|
61
|
+
publisherServer: server,
|
|
62
|
+
collectionName: selection.collectionName,
|
|
63
|
+
pathname: selection.pathname,
|
|
64
|
+
});
|
|
65
|
+
await next();
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
return { publisherServer: server, serveStatic, serveFallback, selectCollection };
|
|
69
|
+
}
|
|
70
|
+
export function fromStaticPublishRc(rc, defaults = {}) {
|
|
71
|
+
return fromPublisherServer(PublisherServer.fromStaticPublishRc(rc), defaults);
|
|
72
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ServeStaticPathOptions<C> = {
|
|
2
|
+
path?: string;
|
|
3
|
+
root?: string;
|
|
4
|
+
rewriteRequestPath?: (path: string, c: C) => string;
|
|
5
|
+
};
|
|
6
|
+
export declare function resolveServeStaticPathname<C>(requestPath: string, c: C, options: ServeStaticPathOptions<C>): string | null;
|
|
7
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/hono/path.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;IAEtC,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,IAAI,CAAC,EAAE,MAAM,CAAC;IAGd,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC;CACrD,CAAC;AAIF,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,CAmB1H"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// The pathname to give to PublisherServer, or null if the path is outside the
|
|
6
|
+
// root. requestPath is decoded, as Hono's c.req.path is.
|
|
7
|
+
export function resolveServeStaticPathname(requestPath, c, options) {
|
|
8
|
+
let root = options.root ?? './';
|
|
9
|
+
if (!root.endsWith('/')) {
|
|
10
|
+
root += '/';
|
|
11
|
+
}
|
|
12
|
+
const base = new URL(encodePath(root), 'https://www.example.com/');
|
|
13
|
+
let reqPath = options.path ??
|
|
14
|
+
(options.rewriteRequestPath != null ? options.rewriteRequestPath(requestPath, c) : requestPath);
|
|
15
|
+
if (reqPath.startsWith('/')) {
|
|
16
|
+
reqPath = '.' + reqPath;
|
|
17
|
+
}
|
|
18
|
+
// A decoded path can have '..'. Do not serve a path outside the root.
|
|
19
|
+
const pathname = new URL(encodePath(reqPath), base).pathname;
|
|
20
|
+
if (!pathname.startsWith(base.pathname)) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return decodePath(pathname);
|
|
24
|
+
}
|
|
25
|
+
// Encode each segment, so that URL resolves only the slashes and the '.' and
|
|
26
|
+
// '..' segments of a decoded path. A '%', '?', or '#' in a segment stays in it.
|
|
27
|
+
function encodePath(path) {
|
|
28
|
+
return path.split('/').map(encodeURIComponent).join('/');
|
|
29
|
+
}
|
|
30
|
+
function decodePath(path) {
|
|
31
|
+
return path.split('/').map(decodeURIComponent).join('/');
|
|
32
|
+
}
|
|
@@ -7,6 +7,12 @@ export type AssetEntry = {
|
|
|
7
7
|
variants: ContentCompressionTypes[];
|
|
8
8
|
};
|
|
9
9
|
export type AssetEntryMap = Record<string, AssetEntry>;
|
|
10
|
+
export declare const HIDDEN_INDEX_KEY_PREFIX = "hidden:";
|
|
11
|
+
export declare const HIDDEN_INDEX_FEATURE = "hidden";
|
|
12
|
+
export declare function hiddenIndexKey(assetKey: string): string;
|
|
13
|
+
export declare function isHiddenIndexKey(indexKey: string): boolean;
|
|
14
|
+
export declare function findAssetEntry(assetEntryMap: AssetEntryMap, assetKey: string, includeHidden: boolean): AssetEntry | null;
|
|
15
|
+
export declare function countHiddenEntries(assetEntryMap: AssetEntryMap): number;
|
|
10
16
|
export type AssetVariantMetadata = {
|
|
11
17
|
contentEncoding?: ContentCompressionTypes;
|
|
12
18
|
size: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/assets/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAqB,MAAM,yBAAyB,CAAC;AAE1F,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,uBAAuB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/assets/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,uBAAuB,EAAqB,MAAM,yBAAyB,CAAC;AAE1F,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,uBAAuB,EAAE,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAOvD,eAAO,MAAM,uBAAuB,YAAY,CAAC;AACjD,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAE7C,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE1D;AAGD,wBAAgB,cAAc,CAAC,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAKxH;AAGD,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,aAAa,GAAG,MAAM,CAEvE;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,CAAC,EAAE,uBAAuB,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAAG,oBAAoB,GAAG,IAAI,CAiC/G"}
|
|
@@ -4,6 +4,30 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { getMetadataFieldValue } from '../metadata/index.js';
|
|
6
6
|
import { isCompressionType } from '../compression/index.js';
|
|
7
|
+
// A hidden file is published, but PublisherServer does not serve it for a
|
|
8
|
+
// request. Its key in the index is this prefix and then the asset key, for
|
|
9
|
+
// example 'hidden:/404.html'. A real asset key always starts with '/', so no
|
|
10
|
+
// request path can match such a key. A collection that has a hidden file
|
|
11
|
+
// requires the 'hidden' feature.
|
|
12
|
+
export const HIDDEN_INDEX_KEY_PREFIX = 'hidden:';
|
|
13
|
+
export const HIDDEN_INDEX_FEATURE = 'hidden';
|
|
14
|
+
export function hiddenIndexKey(assetKey) {
|
|
15
|
+
return HIDDEN_INDEX_KEY_PREFIX + assetKey;
|
|
16
|
+
}
|
|
17
|
+
export function isHiddenIndexKey(indexKey) {
|
|
18
|
+
return indexKey.startsWith(HIDDEN_INDEX_KEY_PREFIX);
|
|
19
|
+
}
|
|
20
|
+
// Find the entry for an asset key. With includeHidden, also find a hidden file.
|
|
21
|
+
export function findAssetEntry(assetEntryMap, assetKey, includeHidden) {
|
|
22
|
+
if (isHiddenIndexKey(assetKey)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return assetEntryMap[assetKey] ?? (includeHidden ? assetEntryMap[hiddenIndexKey(assetKey)] : undefined) ?? null;
|
|
26
|
+
}
|
|
27
|
+
// The number of hidden files in an index.
|
|
28
|
+
export function countHiddenEntries(assetEntryMap) {
|
|
29
|
+
return Object.keys(assetEntryMap).filter(isHiddenIndexKey).length;
|
|
30
|
+
}
|
|
7
31
|
export function decodeAssetVariantMetadata(obj) {
|
|
8
32
|
if (obj == null) {
|
|
9
33
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/collections/index.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,oBAAoB,mGACiE,CAAC;AAEnG,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Fastly, Inc.
|
|
3
|
+
* Licensed under the MIT license. See LICENSE file for details.
|
|
4
|
+
*/
|
|
5
|
+
// A collection name must be a DNS label: lowercase a-z, 0-9, and '-', from
|
|
6
|
+
// 1 to 63 characters, with no '-' at the start or the end. A collection name
|
|
7
|
+
// is used in storage keys, in the surrogate key of the purge, in a cookie,
|
|
8
|
+
// and in hostnames (preview URLs), and a DNS label is safe in all of them.
|
|
9
|
+
// It also cannot have a character that breaks a cookie (';', ',', '=',
|
|
10
|
+
// spaces, quotes, '\', or control characters).
|
|
11
|
+
const COLLECTION_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
12
|
+
export const COLLECTION_NAME_RULE = "Use lowercase a-z, 0-9, and '-', from 1 to 63 characters, with no '-' at the start or the end.";
|
|
13
|
+
export function isValidCollectionName(name) {
|
|
14
|
+
return COLLECTION_NAME_PATTERN.test(name);
|
|
15
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const compressionTypes: readonly [
|
|
1
|
+
export declare const compressionTypes: readonly ['br', 'gzip'];
|
|
2
2
|
export type ContentCompressionTypes = typeof compressionTypes[number];
|
|
3
3
|
export declare function isCompressionType(value: string): value is ContentCompressionTypes;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/compression/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/models/compression/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,YAC3B,IAAI,EACJ,MAAM,CACE,CAAC;AAEX,MAAM,MAAM,uBAAuB,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAEtE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,uBAAuB,CAEjF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare const COLLECTION_PLACEHOLDER = "{collection}";
|
|
2
|
+
export type CollectionSelectionHostSource = {
|
|
3
|
+
type: 'host';
|
|
4
|
+
pattern: string;
|
|
5
|
+
};
|
|
6
|
+
export type CollectionSelectionPathSource = {
|
|
7
|
+
type: 'path';
|
|
8
|
+
prefix: string;
|
|
9
|
+
sticky?: 'cookie';
|
|
10
|
+
};
|
|
11
|
+
export type CollectionSelectionQuerySource = {
|
|
12
|
+
type: 'query';
|
|
13
|
+
param: string;
|
|
14
|
+
sticky?: 'cookie';
|
|
15
|
+
};
|
|
16
|
+
export type CollectionSelectionCookieSource = {
|
|
17
|
+
type: 'cookie';
|
|
18
|
+
cookieName?: string;
|
|
19
|
+
activatePath?: string;
|
|
20
|
+
resetPath?: string;
|
|
21
|
+
maxAge?: number;
|
|
22
|
+
};
|
|
23
|
+
export type CollectionSelectionHeaderSource = {
|
|
24
|
+
type: 'header';
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
export type CollectionSelectionSource = CollectionSelectionHostSource | CollectionSelectionPathSource | CollectionSelectionQuerySource | CollectionSelectionCookieSource | CollectionSelectionHeaderSource;
|
|
28
|
+
export type CollectionSelectionSourceType = CollectionSelectionSource['type'];
|
|
29
|
+
export type CollectionSelection = {
|
|
30
|
+
sources: CollectionSelectionSource[];
|
|
31
|
+
allow?: string[];
|
|
32
|
+
onMissing?: 'not-found' | 'default';
|
|
33
|
+
noindex?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare const COOKIE_SOURCE_DEFAULTS: {
|
|
36
|
+
readonly cookieName: 'publisher-collection';
|
|
37
|
+
readonly activatePath: '/activate';
|
|
38
|
+
readonly resetPath: '/reset';
|
|
39
|
+
};
|
|
40
|
+
export type PatternParts = {
|
|
41
|
+
before: string;
|
|
42
|
+
after: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function splitPattern(pattern: string): PatternParts | null;
|
|
45
|
+
export declare function hostLabelFixedLength(parts: PatternParts): number;
|
|
46
|
+
export declare function maxCollectionNameLengthForHost(pattern: string): number;
|
|
47
|
+
export declare function allowPatternToRegExp(pattern: string): RegExp;
|
|
48
|
+
export declare function isCollectionNameAllowed(collectionName: string, allow: readonly string[] | undefined): boolean;
|
|
49
|
+
export declare function validateCollectionSelection(config: unknown): string[];
|
|
50
|
+
export declare function previewUrl(collectionName: string, baseUrl: string, config: CollectionSelection): string | null;
|
|
51
|
+
export declare function previewUrlTemplates(baseUrl: string, config: CollectionSelection): {
|
|
52
|
+
type: CollectionSelectionSourceType;
|
|
53
|
+
url: string;
|
|
54
|
+
}[];
|
|
55
|
+
//# sourceMappingURL=collection-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collection-selection.d.ts","sourceRoot":"","sources":["../../../../src/models/config/collection-selection.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,sBAAsB,iBAAiB,CAAC;AAErD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,MAAM,CAAC;IAGb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,MAAM,CAAC;IAGb,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,OAAO,CAAC;IAEd,KAAK,EAAE,MAAM,CAAC;IAEd,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,QAAQ,CAAC;IAEf,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,QAAQ,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,6BAA6B,GAC7B,6BAA6B,GAC7B,8BAA8B,GAC9B,+BAA+B,GAC/B,+BAA+B,CAAC;AAEpC,MAAM,MAAM,6BAA6B,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAE9E,MAAM,MAAM,mBAAmB,GAAG;IAGhC,OAAO,EAAE,yBAAyB,EAAE,CAAC;IAGrC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAGjB,SAAS,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAGpC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,sBAAsB;aACjC,UAAU,EAAE,sBAAsB;aAClC,YAAY,EAAE,WAAW;aACzB,SAAS,EAAE,QAAQ;CACX,CAAC;AAaX,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CASjE;AAGD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAKhE;AAGD,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMtE;AAMD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D;AAGD,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAQ7G;AAGD,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CA0GrE;AAOD,wBAAgB,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI,CAiC9G;AAMD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG;IAAE,IAAI,EAAE,6BAA6B,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,CAqBxI"}
|