@adobe/helix-html-pipeline 1.0.0 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/package.json +1 -1
- package/src/html-pipe.js +10 -0
- package/src/steps/extract-metadata.js +10 -51
- package/src/steps/fetch-content.js +4 -4
- package/src/steps/folder-mapping.js +2 -2
- package/src/steps/set-custom-response-headers.js +2 -13
- package/src/utils/metadata.js +66 -0
- package/test/StaticS3Loader.js +45 -0
- package/.eslintrc.cjs +0 -33
- package/.husky/pre-commit +0 -4
- package/.mocha-multi.json +0 -6
- package/.nycrc.json +0 -10
- package/.releaserc.cjs +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.0.3](https://github.com/adobe/helix-html-pipeline/compare/v1.0.2...v1.0.3) (2022-03-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* fix canonical url and 404.html response, clean up meta ([5f3e999](https://github.com/adobe/helix-html-pipeline/commit/5f3e999a6e305fb6ecf7d2fefe3a38274a135433))
|
|
7
|
+
|
|
8
|
+
## [1.0.2](https://github.com/adobe/helix-html-pipeline/compare/v1.0.1...v1.0.2) (2022-03-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* canonical url and 404.html response ([9f4e473](https://github.com/adobe/helix-html-pipeline/commit/9f4e47372d6aea1252f179ad661b0d2fb03429bd))
|
|
14
|
+
|
|
15
|
+
## [1.0.1](https://github.com/adobe/helix-html-pipeline/compare/v1.0.0...v1.0.1) (2022-03-07)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* include static s3 loader ([0a89e2f](https://github.com/adobe/helix-html-pipeline/commit/0a89e2fda5d6a8ab3e67724fd0b436c8b1aa6e58))
|
|
21
|
+
|
|
1
22
|
# 1.0.0 (2022-03-07)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
package/src/html-pipe.js
CHANGED
|
@@ -33,6 +33,7 @@ import splitSections from './steps/split-sections.js';
|
|
|
33
33
|
import tohtml from './steps/stringify-response.js';
|
|
34
34
|
import { PipelineStatusError } from './PipelineStatusError.js';
|
|
35
35
|
import { PipelineResponse } from './PipelineResponse.js';
|
|
36
|
+
import { validatePathInfo } from './utils/path.js';
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* Runs the default pipeline and returns the response.
|
|
@@ -43,6 +44,15 @@ import { PipelineResponse } from './PipelineResponse.js';
|
|
|
43
44
|
export async function htmlPipe(state, req) {
|
|
44
45
|
const { log } = state;
|
|
45
46
|
|
|
47
|
+
if (!validatePathInfo(state.info)) {
|
|
48
|
+
return new PipelineResponse('', {
|
|
49
|
+
status: 404,
|
|
50
|
+
headers: {
|
|
51
|
+
'x-error': 'invalid path',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
/** @type PipelineResponse */
|
|
47
57
|
const res = new PipelineResponse();
|
|
48
58
|
|
|
@@ -11,17 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { resolve } from 'url';
|
|
13
13
|
import { getAbsoluteUrl, makeCanonicalHtmlUrl, optimizeImageURL } from './utils.js';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Converts all non-valid characters to `-`.
|
|
17
|
-
* @param {string} text input text
|
|
18
|
-
* @returns {string} the meta name
|
|
19
|
-
*/
|
|
20
|
-
function toMetaName(text) {
|
|
21
|
-
return text
|
|
22
|
-
.toLowerCase()
|
|
23
|
-
.replace(/[^0-9a-z:_]/gi, '-');
|
|
24
|
-
}
|
|
14
|
+
import { filterGlobalMetadata, toMetaName, ALLOWED_RESPONSE_HEADERS } from '../utils/metadata.js';
|
|
25
15
|
|
|
26
16
|
/**
|
|
27
17
|
* Cleans up comma-separated string lists and returns an array.
|
|
@@ -98,40 +88,6 @@ function readBlockConfig($block) {
|
|
|
98
88
|
return config;
|
|
99
89
|
}
|
|
100
90
|
|
|
101
|
-
function applyMetaRule(target, obj) {
|
|
102
|
-
Object.keys(obj).forEach((key) => {
|
|
103
|
-
const metaKey = toMetaName(key);
|
|
104
|
-
if (metaKey !== 'url' && obj[key]) {
|
|
105
|
-
target[metaKey] = obj[key];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function globToRegExp(glob) {
|
|
111
|
-
const reString = glob
|
|
112
|
-
.replace(/\*\*/g, '_')
|
|
113
|
-
.replace(/\*/g, '[0-9a-z-.]*')
|
|
114
|
-
.replace(/_/g, '.*');
|
|
115
|
-
return new RegExp(`^${reString}$`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function filterGlobalMetadata(metaRules, path) {
|
|
119
|
-
const metaConfig = {};
|
|
120
|
-
metaRules.forEach((rule) => {
|
|
121
|
-
const glob = rule.url || rule.URL || rule.Url;
|
|
122
|
-
if (glob && typeof glob === 'string' && /[0-9a-z-/*]/.test(glob)) {
|
|
123
|
-
if (glob.indexOf('*') >= 0) {
|
|
124
|
-
if (globToRegExp(glob).test(path)) {
|
|
125
|
-
applyMetaRule(metaConfig, rule);
|
|
126
|
-
}
|
|
127
|
-
} else if (glob === path) {
|
|
128
|
-
applyMetaRule(metaConfig, rule);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
return metaConfig;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
91
|
/**
|
|
136
92
|
* Looks for metadata in the document.
|
|
137
93
|
* @param {HTMLDocument} document The document
|
|
@@ -196,11 +152,13 @@ export default function extractMetaData(state, req) {
|
|
|
196
152
|
});
|
|
197
153
|
if (Object.keys(metaConfig).length > 0) {
|
|
198
154
|
// add rest to meta.custom
|
|
199
|
-
meta.custom = Object.
|
|
200
|
-
name
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
155
|
+
meta.custom = Object.entries(metaConfig)
|
|
156
|
+
.filter(([name]) => !ALLOWED_RESPONSE_HEADERS.includes(name))
|
|
157
|
+
.map(([name, value]) => ({
|
|
158
|
+
name,
|
|
159
|
+
value,
|
|
160
|
+
property: name.includes(':'),
|
|
161
|
+
}));
|
|
204
162
|
}
|
|
205
163
|
|
|
206
164
|
if (meta.keywords) {
|
|
@@ -233,7 +191,8 @@ export default function extractMetaData(state, req) {
|
|
|
233
191
|
});
|
|
234
192
|
meta.description = `${desc.slice(0, 25).join(' ')}${desc.length > 25 ? ' ...' : ''}`;
|
|
235
193
|
}
|
|
236
|
-
|
|
194
|
+
// use the req.url and not the state.info.path in case of folder mapping
|
|
195
|
+
meta.url = makeCanonicalHtmlUrl(getAbsoluteUrl(req.headers, req.url.pathname));
|
|
237
196
|
if (!meta.canonical) {
|
|
238
197
|
meta.canonical = meta.url;
|
|
239
198
|
}
|
|
@@ -26,7 +26,7 @@ export default async function fetchContent(state, req, res) {
|
|
|
26
26
|
|
|
27
27
|
const isCode = state.content.sourceBus === 'code';
|
|
28
28
|
const key = isCode
|
|
29
|
-
? `${owner}/${repo}/${ref}
|
|
29
|
+
? `${owner}/${repo}/${ref}${info.resourcePath}`
|
|
30
30
|
: `${contentBusId}/${partition}${info.resourcePath}`;
|
|
31
31
|
const bucketId = isCode ? 'helix-code-bus' : 'helix-content-bus';
|
|
32
32
|
|
|
@@ -55,12 +55,12 @@ export default async function fetchContent(state, req, res) {
|
|
|
55
55
|
// (https://github.com/adobe/helix-pipeline-service/issues/290)
|
|
56
56
|
if (state.info.originalFilename === 'index') {
|
|
57
57
|
res.status = 404;
|
|
58
|
-
res.error = `request to ${info.
|
|
58
|
+
res.error = `request to ${info.resourcePath} not allowed (no-index).`;
|
|
59
59
|
}
|
|
60
60
|
} else {
|
|
61
61
|
// keep 404, but propagate others as 502
|
|
62
62
|
res.status = ret.status === 404 ? 404 : 502;
|
|
63
|
-
res.error = `failed to load ${info.
|
|
63
|
+
res.error = `failed to load ${info.resourcePath} from ${state.content.sourceBus}-bus: ${ret.status}`;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if (res.status === 404) {
|
|
@@ -74,7 +74,7 @@ export default async function fetchContent(state, req, res) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// keep 404 response status
|
|
77
|
-
res.body =
|
|
77
|
+
res.body = ret404.body;
|
|
78
78
|
res.headers.set('last-modified', ret404.headers.get('last-modified'));
|
|
79
79
|
res.headers.set('content-type', 'text/html; charset=utf-8');
|
|
80
80
|
res.headers.set('x-surrogate-key', `${ref}--${repo}--${owner}_404`);
|
|
@@ -53,9 +53,9 @@ export default function folderMapping(state) {
|
|
|
53
53
|
// special case: use code-bus
|
|
54
54
|
state.content.sourceBus = 'code';
|
|
55
55
|
state.info.resourcePath = mapped;
|
|
56
|
-
state.log.info(`mapped ${path} to ${state.info.resourcePath} (
|
|
56
|
+
state.log.info(`mapped ${path} to ${state.info.resourcePath} (code-bus)`);
|
|
57
57
|
} else {
|
|
58
|
-
state.log.info(`mapped ${path} to ${state.info.path} (
|
|
58
|
+
state.log.info(`mapped ${path} to ${state.info.path} (content-bus)`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -10,18 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
|
|
13
|
-
import { filterGlobalMetadata } from '
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Array of headers allowed in the metadata.json file.
|
|
17
|
-
*/
|
|
18
|
-
const allowList = [
|
|
19
|
-
'content-security-policy',
|
|
20
|
-
'content-security-policy-report-only',
|
|
21
|
-
'access-control-allow-origin',
|
|
22
|
-
'access-control-allow-methods',
|
|
23
|
-
'link',
|
|
24
|
-
];
|
|
13
|
+
import { filterGlobalMetadata, ALLOWED_RESPONSE_HEADERS } from '../utils/metadata.js';
|
|
25
14
|
|
|
26
15
|
/**
|
|
27
16
|
* Decorates the pipeline response object with the headers defined in metadata.json.
|
|
@@ -34,7 +23,7 @@ const allowList = [
|
|
|
34
23
|
export default function setCustomResponseHeaders(state, req, res) {
|
|
35
24
|
const meta = filterGlobalMetadata(state.metadata, state.info.path);
|
|
36
25
|
Object.entries(meta).forEach(([name, value]) => {
|
|
37
|
-
if (
|
|
26
|
+
if (ALLOWED_RESPONSE_HEADERS.includes(name)) {
|
|
38
27
|
res.headers.set(name, cleanupHeaderValue(value));
|
|
39
28
|
}
|
|
40
29
|
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Converts all non-valid characters to `-`.
|
|
14
|
+
* @param {string} text input text
|
|
15
|
+
* @returns {string} the meta name
|
|
16
|
+
*/
|
|
17
|
+
export function toMetaName(text) {
|
|
18
|
+
return text
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(/[^0-9a-z:_]/gi, '-');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function applyMetaRule(target, obj) {
|
|
24
|
+
Object.keys(obj).forEach((key) => {
|
|
25
|
+
const metaKey = toMetaName(key);
|
|
26
|
+
if (metaKey !== 'url' && obj[key]) {
|
|
27
|
+
target[metaKey] = obj[key];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function globToRegExp(glob) {
|
|
33
|
+
const reString = glob
|
|
34
|
+
.replace(/\*\*/g, '_')
|
|
35
|
+
.replace(/\*/g, '[0-9a-z-.]*')
|
|
36
|
+
.replace(/_/g, '.*');
|
|
37
|
+
return new RegExp(`^${reString}$`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function filterGlobalMetadata(metaRules, path) {
|
|
41
|
+
const metaConfig = {};
|
|
42
|
+
metaRules.forEach((rule) => {
|
|
43
|
+
const glob = rule.url || rule.URL || rule.Url;
|
|
44
|
+
if (glob && typeof glob === 'string' && /[0-9a-z-/*]/.test(glob)) {
|
|
45
|
+
if (glob.indexOf('*') >= 0) {
|
|
46
|
+
if (globToRegExp(glob).test(path)) {
|
|
47
|
+
applyMetaRule(metaConfig, rule);
|
|
48
|
+
}
|
|
49
|
+
} else if (glob === path) {
|
|
50
|
+
applyMetaRule(metaConfig, rule);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return metaConfig;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Array of headers allowed in the metadata.json file.
|
|
59
|
+
*/
|
|
60
|
+
export const ALLOWED_RESPONSE_HEADERS = [
|
|
61
|
+
'content-security-policy',
|
|
62
|
+
'content-security-policy-report-only',
|
|
63
|
+
'access-control-allow-origin',
|
|
64
|
+
'access-control-allow-methods',
|
|
65
|
+
'link',
|
|
66
|
+
];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* @implements S3Loader
|
|
14
|
+
*/
|
|
15
|
+
export class StaticS3Loader {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.buckets = {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
reply(bucketId, key, response) {
|
|
21
|
+
let bucket = this.buckets[bucketId];
|
|
22
|
+
if (!bucket) {
|
|
23
|
+
bucket = {};
|
|
24
|
+
this.buckets[bucketId] = bucket;
|
|
25
|
+
}
|
|
26
|
+
bucket[key] = response;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async getObject(bucketId, key) {
|
|
31
|
+
const bucket = this.buckets[bucketId];
|
|
32
|
+
const response = bucket?.[key] ?? {
|
|
33
|
+
status: 404,
|
|
34
|
+
body: '',
|
|
35
|
+
headers: new Map(),
|
|
36
|
+
};
|
|
37
|
+
// eslint-disable-next-line no-console
|
|
38
|
+
console.log(`StaticS3Loader: loading ${bucketId}/${key} -> ${response.status}`);
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async headObject(bucketId, key) {
|
|
43
|
+
return this.getObject(bucketId, key);
|
|
44
|
+
}
|
|
45
|
+
}
|
package/.eslintrc.cjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2021 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
root: true,
|
|
15
|
-
extends: '@adobe/helix',
|
|
16
|
-
env: {
|
|
17
|
-
node: true,
|
|
18
|
-
es6: true,
|
|
19
|
-
},
|
|
20
|
-
parserOptions: {
|
|
21
|
-
sourceType: 'module',
|
|
22
|
-
ecmaVersion: 2020,
|
|
23
|
-
},
|
|
24
|
-
rules: {
|
|
25
|
-
'import/extensions': [2, 'ignorePackages'],
|
|
26
|
-
'import/prefer-default-export': 0,
|
|
27
|
-
'no-param-reassign': ['error', { props: false }],
|
|
28
|
-
},
|
|
29
|
-
globals: {
|
|
30
|
-
__rootdir: true,
|
|
31
|
-
__testdir: true,
|
|
32
|
-
},
|
|
33
|
-
};
|
package/.husky/pre-commit
DELETED
package/.mocha-multi.json
DELETED
package/.nycrc.json
DELETED
package/.releaserc.cjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
plugins: [
|
|
3
|
-
"@semantic-release/commit-analyzer",
|
|
4
|
-
"@semantic-release/release-notes-generator",
|
|
5
|
-
["@semantic-release/changelog", {
|
|
6
|
-
"changelogFile": "CHANGELOG.md",
|
|
7
|
-
}],
|
|
8
|
-
"@semantic-release/npm",
|
|
9
|
-
["@semantic-release/git", {
|
|
10
|
-
"assets": ["package.json", "CHANGELOG.md"],
|
|
11
|
-
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
12
|
-
}],
|
|
13
|
-
["@semantic-release/github", {}]
|
|
14
|
-
],
|
|
15
|
-
branches: ['main'],
|
|
16
|
-
};
|