@adobe/helix-html-pipeline 5.4.4 → 5.5.0

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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [5.5.0](https://github.com/adobe/helix-html-pipeline/compare/v5.4.5...v5.5.0) (2024-01-23)
2
+
3
+
4
+ ### Features
5
+
6
+ * add pipeline for sitemap.xml ([#507](https://github.com/adobe/helix-html-pipeline/issues/507)) ([8256184](https://github.com/adobe/helix-html-pipeline/commit/825618471a50a0641d64de0b7bb0cb6a78578d52))
7
+
8
+ ## [5.4.5](https://github.com/adobe/helix-html-pipeline/compare/v5.4.4...v5.4.5) (2024-01-22)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update external major ([#503](https://github.com/adobe/helix-html-pipeline/issues/503)) ([6c84eb2](https://github.com/adobe/helix-html-pipeline/commit/6c84eb258c731162935d502b34da01f1bdc12690))
14
+
1
15
  ## [5.4.4](https://github.com/adobe/helix-html-pipeline/compare/v5.4.3...v5.4.4) (2023-12-30)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "5.4.4",
3
+ "version": "5.5.0",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -52,9 +52,9 @@
52
52
  "hast-util-select": "6.0.2",
53
53
  "hast-util-to-html": "9.0.0",
54
54
  "hast-util-to-string": "3.0.0",
55
- "hastscript": "8.0.0",
55
+ "hastscript": "9.0.0",
56
56
  "jose": "5.2.0",
57
- "mdast-util-to-hast": "13.0.2",
57
+ "mdast-util-to-hast": "13.1.0",
58
58
  "mdast-util-to-string": "4.0.0",
59
59
  "mime": "4.0.1",
60
60
  "rehype-format": "5.0.0",
@@ -75,15 +75,15 @@
75
75
  "@semantic-release/changelog": "6.0.3",
76
76
  "@semantic-release/git": "10.0.1",
77
77
  "@semantic-release/npm": "11.0.2",
78
- "c8": "8.0.1",
78
+ "c8": "9.1.0",
79
79
  "eslint": "8.56.0",
80
80
  "eslint-import-resolver-exports": "1.0.0-beta.5",
81
81
  "eslint-plugin-header": "3.1.1",
82
82
  "eslint-plugin-import": "2.29.1",
83
- "esmock": "2.6.0",
83
+ "esmock": "2.6.2",
84
84
  "husky": "8.0.3",
85
85
  "js-yaml": "4.1.0",
86
- "jsdom": "23.0.1",
86
+ "jsdom": "24.0.0",
87
87
  "junit-report-builder": "3.1.0",
88
88
  "lint-staged": "15.2.0",
89
89
  "mocha": "10.2.0",
package/src/index.js CHANGED
@@ -13,6 +13,7 @@ export * from './html-pipe.js';
13
13
  export * from './json-pipe.js';
14
14
  export * from './options-pipe.js';
15
15
  export * from './forms-pipe.js';
16
+ export * from './sitemap-pipe.js';
16
17
  export * from './PipelineContent.js';
17
18
  export * from './PipelineRequest.js';
18
19
  export * from './PipelineResponse.js';
@@ -0,0 +1,111 @@
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
+ import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
13
+ import { authenticate, requireProject } from './steps/authenticate.js';
14
+ import fetchConfig from './steps/fetch-config.js';
15
+ import fetchContent from './steps/fetch-content.js';
16
+ import fetchConfigAll from './steps/fetch-config-all.js';
17
+ import renderCode from './steps/render-code.js';
18
+ import setXSurrogateKeyHeader from './steps/set-x-surrogate-key-header.js';
19
+ import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
20
+ import { PipelineStatusError } from './PipelineStatusError.js';
21
+ import { PipelineResponse } from './PipelineResponse.js';
22
+
23
+ /**
24
+ * Serves or renders the sitemap xml. The sitemap is always served from the preview content-bus
25
+ * partition.
26
+ *
27
+ * todo: currently only serves an existing sitemap.xml from the contentbus.
28
+ * generate sitemap on the fly based on the sitemap.json
29
+ *
30
+ * @param {PipelineState} state
31
+ * @param {PipelineRequest} req
32
+ * @returns {PipelineResponse}
33
+ */
34
+ export async function sitemapPipe(state, req) {
35
+ const { log } = state;
36
+ state.type = 'sitemap';
37
+ // force loading from preview
38
+ state.partition = 'preview';
39
+
40
+ if (state.info?.path !== '/sitemap.xml') {
41
+ // this should not happen as it would mean that the caller used the wrong route. so we respond
42
+ // with a 500 to indicate that something is wrong.
43
+ return new PipelineResponse('', {
44
+ status: 500,
45
+ headers: {
46
+ 'x-error': 'invalid route',
47
+ },
48
+ });
49
+ }
50
+
51
+ /** @type PipelineResponse */
52
+ const res = new PipelineResponse('', {
53
+ headers: {
54
+ 'content-type': 'text/html; charset=utf-8',
55
+ },
56
+ });
57
+
58
+ // check if .auth request
59
+
60
+ try { // fetch config first, since we need to compute the content-bus-id from the fstab ...
61
+ state.timer?.update('config-fetch');
62
+ await fetchConfig(state, req, res);
63
+ if (!state.contentBusId) {
64
+ res.status = 400;
65
+ res.headers.set('x-error', 'contentBusId missing');
66
+ return res;
67
+ }
68
+
69
+ // fetch sitemap.xml
70
+
71
+ state.timer?.update('content-fetch');
72
+ await Promise.all([
73
+ fetchConfigAll(state, req, res),
74
+ fetchContent(state, req, res),
75
+ ]);
76
+
77
+ await requireProject(state, req, res);
78
+ if (res.error !== 401) {
79
+ await authenticate(state, req, res);
80
+ }
81
+
82
+ if (res.error) {
83
+ // if content loading produced an error, we're done.
84
+ const level = res.status >= 500 ? 'error' : 'info';
85
+ log[level](`pipeline status: ${res.status} ${res.error}`);
86
+ res.headers.set('x-error', cleanupHeaderValue(res.error));
87
+ if (res.status < 500) {
88
+ await setCustomResponseHeaders(state, req, res);
89
+ }
90
+ return res;
91
+ }
92
+
93
+ state.timer?.update('serialize');
94
+ await renderCode(state, req, res);
95
+ await setCustomResponseHeaders(state, req, res);
96
+ await setXSurrogateKeyHeader(state, req, res);
97
+ } catch (e) {
98
+ res.error = e.message;
99
+ if (e instanceof PipelineStatusError) {
100
+ res.status = e.code;
101
+ } else {
102
+ res.status = 500;
103
+ }
104
+
105
+ const level = res.status >= 500 ? 'error' : 'info';
106
+ log[level](`pipeline status: ${res.status} ${res.error}`, e);
107
+ res.headers.set('x-error', cleanupHeaderValue(res.error));
108
+ }
109
+
110
+ return res;
111
+ }