@adobe/helix-html-pipeline 3.6.1 → 3.6.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [3.6.3](https://github.com/adobe/helix-html-pipeline/compare/v3.6.2...v3.6.3) (2022-11-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handle errors when loading config ([#180](https://github.com/adobe/helix-html-pipeline/issues/180)) ([f4f4b5f](https://github.com/adobe/helix-html-pipeline/commit/f4f4b5ff4f687331c2ec321e53662519cc428eb6)), closes [#179](https://github.com/adobe/helix-html-pipeline/issues/179)
7
+
8
+ ## [3.6.2](https://github.com/adobe/helix-html-pipeline/compare/v3.6.1...v3.6.2) (2022-10-31)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency github-slugger to v2 (main) ([#176](https://github.com/adobe/helix-html-pipeline/issues/176)) ([6bf6b58](https://github.com/adobe/helix-html-pipeline/commit/6bf6b588abdae6eb7584cb3ced7ee5d89a756be1))
14
+
1
15
  ## [3.6.1](https://github.com/adobe/helix-html-pipeline/compare/v3.6.0...v3.6.1) (2022-10-31)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "3.6.1",
3
+ "version": "3.6.3",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -42,7 +42,7 @@
42
42
  "@adobe/helix-markdown-support": "5.0.10",
43
43
  "@adobe/helix-shared-utils": "2.1.0",
44
44
  "cookie": "0.5.0",
45
- "github-slugger": "1.5.0",
45
+ "github-slugger": "2.0.0",
46
46
  "hast-util-raw": "7.2.2",
47
47
  "hast-util-select": "5.0.2",
48
48
  "hast-util-to-html": "8.0.3",
package/src/json-pipe.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+ import { cleanupHeaderValue } from '@adobe/helix-shared-utils';
12
13
  import fetchConfigAll from './steps/fetch-config-all.js';
13
14
  import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
14
15
  import { PipelineResponse } from './PipelineResponse.js';
@@ -17,6 +18,7 @@ import { extractLastModified, updateLastModified } from './utils/last-modified.j
17
18
  import { authenticate } from './steps/authenticate.js';
18
19
  import fetchConfig from './steps/fetch-config.js';
19
20
  import { getPathInfo } from './utils/path.js';
21
+ import { PipelineStatusError } from './PipelineStatusError.js';
20
22
 
21
23
  /**
22
24
  * Checks the fstab for folder mapping entries and then re-adjusts the path infos if needed.
@@ -74,48 +76,58 @@ export async function jsonPipe(state, req) {
74
76
  });
75
77
  }
76
78
 
77
- // fetch config and apply the folder mapping
78
- await fetchConfig(state, req);
79
- await folderMapping(state);
79
+ try {
80
+ // fetch config and apply the folder mapping
81
+ await fetchConfig(state, req);
82
+ await folderMapping(state);
80
83
 
81
- // fetch data from content bus
82
- const { path } = state.info;
83
- state.timer?.update('json-fetch');
84
- let dataResponse = await s3Loader.getObject('helix-content-bus', `${contentBusId}/${partition}${path}`);
84
+ // fetch data from content bus
85
+ const { path } = state.info;
86
+ state.timer?.update('json-fetch');
87
+ let dataResponse = await s3Loader.getObject('helix-content-bus', `${contentBusId}/${partition}${path}`);
85
88
 
86
- // if not found, fall back to code bus
87
- if (dataResponse.status === 404) {
88
- dataResponse = await s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}${path}`);
89
- }
89
+ // if not found, fall back to code bus
90
+ if (dataResponse.status === 404) {
91
+ dataResponse = await s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}${path}`);
92
+ }
90
93
 
91
- // if still not found, return status
92
- if (dataResponse.status !== 200) {
93
- if (dataResponse.status < 500) {
94
- await fetchConfigAll(state, req, dataResponse);
95
- await setCustomResponseHeaders(state, req, dataResponse);
94
+ // if still not found, return status
95
+ if (dataResponse.status !== 200) {
96
+ if (dataResponse.status < 500) {
97
+ await fetchConfigAll(state, req, dataResponse);
98
+ await setCustomResponseHeaders(state, req, dataResponse);
99
+ }
100
+ return dataResponse;
96
101
  }
97
- return dataResponse;
98
- }
99
- const data = dataResponse.body;
102
+ const data = dataResponse.body;
100
103
 
101
- // filter data
102
- const response = jsonFilter(state, data, {
103
- limit: limit ? Number.parseInt(limit, 10) : undefined,
104
- offset: offset ? Number.parseInt(offset, 10) : undefined,
105
- sheet,
106
- raw: limit === undefined && offset === undefined && sheet === undefined,
107
- });
104
+ // filter data
105
+ const response = jsonFilter(state, data, {
106
+ limit: limit ? Number.parseInt(limit, 10) : undefined,
107
+ offset: offset ? Number.parseInt(offset, 10) : undefined,
108
+ sheet,
109
+ raw: limit === undefined && offset === undefined && sheet === undefined,
110
+ });
108
111
 
109
- // set last-modified
110
- updateLastModified(state, response, extractLastModified(dataResponse.headers));
112
+ // set last-modified
113
+ updateLastModified(state, response, extractLastModified(dataResponse.headers));
111
114
 
112
- // set surrogate key
113
- response.headers.set('x-surrogate-key', `${contentBusId}${path}`.replace(/\//g, '_'));
115
+ // set surrogate key
116
+ response.headers.set('x-surrogate-key', `${contentBusId}${path}`.replace(/\//g, '_'));
114
117
 
115
- // Load config-all and set response headers
116
- await fetchConfigAll(state, req, response);
117
- await authenticate(state, req, response);
118
- await setCustomResponseHeaders(state, req, response);
118
+ // Load config-all and set response headers
119
+ await fetchConfigAll(state, req, response);
120
+ await authenticate(state, req, response);
121
+ await setCustomResponseHeaders(state, req, response);
119
122
 
120
- return response;
123
+ return response;
124
+ } catch (e) {
125
+ const res = new PipelineResponse('', {
126
+ status: e instanceof PipelineStatusError ? e.code : 500,
127
+ });
128
+ const level = res.status >= 500 ? 'error' : 'info';
129
+ log[level](`pipeline status: ${res.status} ${e.message}`, e);
130
+ res.headers.set('x-error', cleanupHeaderValue(e.message));
131
+ return res;
132
+ }
121
133
  }
@@ -72,7 +72,8 @@ export async function authenticate(state, req, res) {
72
72
  res.error = 'forbidden.';
73
73
  }
74
74
 
75
- // set some response headers
75
+ // set some response headers for deferred edge authentication
76
+ // AdobePatentID="P11443-US"
76
77
  res.headers.set('x-hlx-auth-allow', allows.join(','));
77
78
  if (authInfo.profile) {
78
79
  res.headers.set('x-hlx-auth-iss', authInfo.profile.iss);
@@ -9,7 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- import GithubSlugger from 'github-slugger';
12
+ import { slug } from 'github-slugger';
13
13
 
14
14
  export class IDSlugger {
15
15
  constructor() {
@@ -22,7 +22,7 @@ export class IDSlugger {
22
22
  * @return {string} A unique slug string
23
23
  */
24
24
  slug(value) {
25
- let id = GithubSlugger.slug(value)
25
+ let id = slug(value)
26
26
  // remove leading numbers
27
27
  .replace(/^\d+-+/, '');
28
28
 
@@ -34,6 +34,11 @@ export class StaticS3Loader {
34
34
  body: '',
35
35
  headers: new Map(),
36
36
  };
37
+ if (response instanceof Error) {
38
+ // eslint-disable-next-line no-console
39
+ console.log(`StaticS3Loader: failing ${bucketId}/${key} -> ${response.message}`);
40
+ throw response;
41
+ }
37
42
  // eslint-disable-next-line no-console
38
43
  console.log(`StaticS3Loader: loading ${bucketId}/${key} -> ${response.status}`);
39
44
  return response;