@adobe/helix-html-pipeline 1.7.1 → 1.8.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,10 @@
1
+ # [1.8.0](https://github.com/adobe/helix-html-pipeline/compare/v1.7.1...v1.8.0) (2022-09-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * respect folder mapping also for json ([52b6ca0](https://github.com/adobe/helix-html-pipeline/commit/52b6ca0cf801d5211fb19aff5cd343c8746c5ac1)), closes [#140](https://github.com/adobe/helix-html-pipeline/issues/140)
7
+
1
8
  ## [1.7.1](https://github.com/adobe/helix-html-pipeline/compare/v1.7.0...v1.7.1) (2022-09-13)
2
9
 
3
10
 
package/README.md CHANGED
@@ -19,11 +19,6 @@ This package contains the common code for `helix-pipeline-service` and `helix-cl
19
19
  ```bash
20
20
  $ npm install @adobe/helix-html-pipeline
21
21
  ```
22
-
23
- ## Usage
24
-
25
- See the [API documentation](docs/API.md).
26
-
27
22
  ## Development
28
23
 
29
24
  ### Build
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -8,7 +8,6 @@
8
8
  "scripts": {
9
9
  "test": " c8 mocha",
10
10
  "lint": "eslint .",
11
- "docs": "npx jsdoc2md -c .jsdoc.json --files 'src/*.js' > docs/API.md",
12
11
  "semantic-release": "semantic-release",
13
12
  "prepare": "husky install"
14
13
  },
@@ -40,9 +39,9 @@
40
39
  "hastscript": "7.0.2",
41
40
  "mdast-util-gfm-footnote": "1.0.1",
42
41
  "mdast-util-gfm-strikethrough": "1.0.1",
43
- "mdast-util-gfm-table": "1.0.4",
42
+ "mdast-util-gfm-table": "1.0.6",
44
43
  "mdast-util-gfm-task-list-item": "1.0.1",
45
- "mdast-util-to-hast": "12.2.1",
44
+ "mdast-util-to-hast": "12.2.2",
46
45
  "mdast-util-to-string": "3.1.0",
47
46
  "micromark-extension-gfm-footnote": "1.0.4",
48
47
  "micromark-extension-gfm-strikethrough": "1.0.4",
@@ -70,14 +69,13 @@
70
69
  "@semantic-release/git": "10.0.1",
71
70
  "@semantic-release/npm": "9.0.1",
72
71
  "c8": "7.12.0",
73
- "eslint": "8.23.0",
72
+ "eslint": "8.23.1",
74
73
  "eslint-import-resolver-exports": "1.0.0-beta.3",
75
74
  "eslint-plugin-header": "3.1.1",
76
75
  "eslint-plugin-import": "2.26.0",
77
- "esmock": "2.0.0",
76
+ "esmock": "2.0.1",
78
77
  "husky": "8.0.1",
79
78
  "js-yaml": "4.1.0",
80
- "jsdoc-to-markdown": "7.1.1",
81
79
  "jsdom": "20.0.0",
82
80
  "junit-report-builder": "3.0.1",
83
81
  "lint-staged": "13.0.3",
package/src/html-pipe.js CHANGED
@@ -67,7 +67,7 @@ export async function htmlPipe(state, req) {
67
67
  await fetchConfig(state, req, res);
68
68
 
69
69
  // ...and apply the folder mapping
70
- await folderMapping(state, req, res);
70
+ await folderMapping(state);
71
71
 
72
72
  // load metadata and content in parallel
73
73
  state.timer?.update('content-fetch');
package/src/json-pipe.js CHANGED
@@ -14,6 +14,30 @@ import setCustomResponseHeaders from './steps/set-custom-response-headers.js';
14
14
  import { PipelineResponse } from './PipelineResponse.js';
15
15
  import jsonFilter from './utils/json-filter.js';
16
16
  import { extractLastModified, updateLastModified } from './utils/last-modified.js';
17
+ import fetchConfig from './steps/fetch-config.js';
18
+ import { getPathInfo } from './utils/path.js';
19
+
20
+ /**
21
+ * Checks the fstab for folder mapping entries and then re-adjusts the path infos if needed.
22
+ * Note that json can only be mapped using direct documents mapping.
23
+ *
24
+ * @type PipelineStep
25
+ * @param {PipelineState} state
26
+ */
27
+ export default function folderMapping(state) {
28
+ const folders = state.helixConfig?.fstab?.data.folders;
29
+ if (!folders) {
30
+ return;
31
+ }
32
+ const { path } = state.info;
33
+ const mapped = folders[path];
34
+ if (mapped) {
35
+ state.info = getPathInfo(mapped);
36
+ state.info.unmappedPath = path;
37
+ state.info.resourcePath = mapped;
38
+ state.log.info(`mapped ${path} to ${state.info.resourcePath} (${state.content.sourceBus}-bus)`);
39
+ }
40
+ }
17
41
 
18
42
  /**
19
43
  * Runs the default pipeline and returns the response.
@@ -27,7 +51,7 @@ export async function jsonPipe(state, req) {
27
51
  const {
28
52
  owner, repo, ref, contentBusId, partition, s3Loader,
29
53
  } = state;
30
- const { path } = state.info;
54
+ const { extension } = state.info;
31
55
  const { searchParams } = req.url;
32
56
  const params = Object.fromEntries(searchParams.entries());
33
57
  if (params.sheet) {
@@ -39,7 +63,7 @@ export async function jsonPipe(state, req) {
39
63
  sheet,
40
64
  } = params;
41
65
 
42
- if (!path.endsWith('.json')) {
66
+ if (extension !== '.json') {
43
67
  log.error('only json resources supported.');
44
68
  return new PipelineResponse('', {
45
69
  status: 400,
@@ -49,7 +73,12 @@ export async function jsonPipe(state, req) {
49
73
  });
50
74
  }
51
75
 
76
+ // fetch config and apply the folder mapping
77
+ await fetchConfig(state, req);
78
+ await folderMapping(state);
79
+
52
80
  // fetch data from content bus
81
+ const { path } = state.info;
53
82
  state.timer?.update('json-fetch');
54
83
  let dataResponse = await s3Loader.getObject('helix-content-bus', `${contentBusId}/${partition}${path}`);
55
84
 
@@ -17,7 +17,7 @@ import { PipelineStatusError } from '../PipelineStatusError.js';
17
17
  * @type PipelineStep
18
18
  * @param {PipelineState} state
19
19
  * @param {PipelineRequest} req
20
- * @param {PipelineResponse} res
20
+ * @param {PipelineResponse} [res]
21
21
  * @returns {Promise<void>}
22
22
  */
23
23
  export default async function fetchConfig(state, req, res) {
@@ -47,15 +47,17 @@ export default async function fetchConfig(state, req, res) {
47
47
  });
48
48
  }
49
49
 
50
- // also update last-modified
51
- const configLastModified = extractLastModified(ret.headers);
50
+ if (res) {
51
+ // also update last-modified
52
+ const configLastModified = extractLastModified(ret.headers);
52
53
 
53
- // update last modified of fstab
54
- updateLastModified(state, res, config.fstab?.lastModified || configLastModified);
54
+ // update last modified of fstab
55
+ updateLastModified(state, res, config.fstab?.lastModified || configLastModified);
55
56
 
56
- // for html requests, also consider the HEAD config
57
- if (state.type === 'html' && state.info.selector !== 'plain' && config.head?.lastModified) {
58
- updateLastModified(state, res, config.head.lastModified);
57
+ // for html requests, also consider the HEAD config
58
+ if (state.type === 'html' && state.info.selector !== 'plain' && config.head?.lastModified) {
59
+ updateLastModified(state, res, config.head.lastModified);
60
+ }
59
61
  }
60
62
 
61
63
  state.helixConfig = config;
package/docs/API.md DELETED
@@ -1,251 +0,0 @@
1
- ## Classes
2
-
3
- <dl>
4
- <dt><a href="#PipelineState">PipelineState</a></dt>
5
- <dd></dd>
6
- <dt><a href="#PipelineRequest">PipelineRequest</a></dt>
7
- <dd></dd>
8
- <dt><a href="#PipelineResponse">PipelineResponse</a></dt>
9
- <dd></dd>
10
- <dt><a href="#PipelineState">PipelineState</a></dt>
11
- <dd></dd>
12
- </dl>
13
-
14
- ## Functions
15
-
16
- <dl>
17
- <dt><a href="#searchParamsToObject">searchParamsToObject(searchParams)</a> ⇒ <code>Object</code></dt>
18
- <dd><p>Converts URLSearchParams to an object</p>
19
- </dd>
20
- <dt><a href="#extractBodyData">extractBodyData(request)</a> ⇒ <code>Object</code></dt>
21
- <dd><p>Extracts and parses the body data from the request</p>
22
- </dd>
23
- <dt><a href="#formsPipe">formsPipe(state, request)</a> ⇒ <code><a href="#PipelineResponse">Promise.&lt;PipelineResponse&gt;</a></code></dt>
24
- <dd><p>Handle a pipeline POST request.
25
- At this point POST&#39;s only apply to json files that are backed by a workbook.</p>
26
- </dd>
27
- <dt><a href="#htmlPipe">htmlPipe(state, req)</a> ⇒ <code><a href="#PipelineResponse">PipelineResponse</a></code></dt>
28
- <dd><p>Runs the default pipeline and returns the response.</p>
29
- </dd>
30
- <dt><a href="#jsonPipe">jsonPipe(state, req)</a> ⇒ <code><a href="#PipelineResponse">PipelineResponse</a></code></dt>
31
- <dd><p>Runs the default pipeline and returns the response.</p>
32
- </dd>
33
- <dt><a href="#optionsPipe">optionsPipe(state, request)</a> ⇒ <code>Response</code></dt>
34
- <dd><p>Handles options requests</p>
35
- </dd>
36
- </dl>
37
-
38
- <a name="PipelineState"></a>
39
-
40
- ## PipelineState
41
- **Kind**: global class
42
-
43
- * [PipelineState](#PipelineState)
44
- * [new PipelineState()](#new_PipelineState_new)
45
- * [new PipelineState()](#new_PipelineState_new)
46
- * [.PipelineState](#PipelineState+PipelineState)
47
- * [new exports.PipelineState(opts)](#new_PipelineState+PipelineState_new)
48
-
49
- <a name="new_PipelineState_new"></a>
50
-
51
- ### new PipelineState()
52
- State of the pipeline
53
-
54
- <a name="new_PipelineState_new"></a>
55
-
56
- ### new PipelineState()
57
- State of the pipeline
58
-
59
- <a name="PipelineState+PipelineState"></a>
60
-
61
- ### pipelineState.PipelineState
62
- **Kind**: instance class of [<code>PipelineState</code>](#PipelineState)
63
- <a name="new_PipelineState+PipelineState_new"></a>
64
-
65
- #### new exports.PipelineState(opts)
66
- Creates the pipeline state
67
-
68
-
69
- | Param | Type |
70
- | --- | --- |
71
- | opts | <code>PipelineOptions</code> |
72
-
73
- <a name="PipelineRequest"></a>
74
-
75
- ## PipelineRequest
76
- **Kind**: global class
77
-
78
- * [PipelineRequest](#PipelineRequest)
79
- * [new PipelineRequest()](#new_PipelineRequest_new)
80
- * [.PipelineRequest](#PipelineRequest+PipelineRequest)
81
- * [new exports.PipelineRequest(url, [init])](#new_PipelineRequest+PipelineRequest_new)
82
-
83
- <a name="new_PipelineRequest_new"></a>
84
-
85
- ### new PipelineRequest()
86
- Request of a pipeline
87
-
88
- <a name="PipelineRequest+PipelineRequest"></a>
89
-
90
- ### pipelineRequest.PipelineRequest
91
- **Kind**: instance class of [<code>PipelineRequest</code>](#PipelineRequest)
92
- <a name="new_PipelineRequest+PipelineRequest_new"></a>
93
-
94
- #### new exports.PipelineRequest(url, [init])
95
- Creates the pipeline request
96
-
97
-
98
- | Param | Type |
99
- | --- | --- |
100
- | url | <code>URL</code> \| <code>string</code> |
101
- | [init] | <code>PipelineRequestInit</code> |
102
-
103
- <a name="PipelineResponse"></a>
104
-
105
- ## PipelineResponse
106
- **Kind**: global class
107
-
108
- * [PipelineResponse](#PipelineResponse)
109
- * [new PipelineResponse()](#new_PipelineResponse_new)
110
- * [.PipelineResponse](#PipelineResponse+PipelineResponse)
111
- * [new exports.PipelineResponse()](#new_PipelineResponse+PipelineResponse_new)
112
- * [.json()](#PipelineResponse+json) ⇒ <code>object</code>
113
-
114
- <a name="new_PipelineResponse_new"></a>
115
-
116
- ### new PipelineResponse()
117
- Response of a pipeline
118
-
119
- <a name="PipelineResponse+PipelineResponse"></a>
120
-
121
- ### pipelineResponse.PipelineResponse
122
- **Kind**: instance class of [<code>PipelineResponse</code>](#PipelineResponse)
123
- <a name="new_PipelineResponse+PipelineResponse_new"></a>
124
-
125
- #### new exports.PipelineResponse()
126
- Creates the pipeline response
127
-
128
- <a name="PipelineResponse+json"></a>
129
-
130
- ### pipelineResponse.json() ⇒ <code>object</code>
131
- Returns the json parsed object of `this.body`.
132
-
133
- **Kind**: instance method of [<code>PipelineResponse</code>](#PipelineResponse)
134
- <a name="PipelineState"></a>
135
-
136
- ## PipelineState
137
- **Kind**: global class
138
-
139
- * [PipelineState](#PipelineState)
140
- * [new PipelineState()](#new_PipelineState_new)
141
- * [new PipelineState()](#new_PipelineState_new)
142
- * [.PipelineState](#PipelineState+PipelineState)
143
- * [new exports.PipelineState(opts)](#new_PipelineState+PipelineState_new)
144
-
145
- <a name="new_PipelineState_new"></a>
146
-
147
- ### new PipelineState()
148
- State of the pipeline
149
-
150
- <a name="new_PipelineState_new"></a>
151
-
152
- ### new PipelineState()
153
- State of the pipeline
154
-
155
- <a name="PipelineState+PipelineState"></a>
156
-
157
- ### pipelineState.PipelineState
158
- **Kind**: instance class of [<code>PipelineState</code>](#PipelineState)
159
- <a name="new_PipelineState+PipelineState_new"></a>
160
-
161
- #### new exports.PipelineState(opts)
162
- Creates the pipeline state
163
-
164
-
165
- | Param | Type |
166
- | --- | --- |
167
- | opts | <code>PipelineOptions</code> |
168
-
169
- <a name="searchParamsToObject"></a>
170
-
171
- ## searchParamsToObject(searchParams) ⇒ <code>Object</code>
172
- Converts URLSearchParams to an object
173
-
174
- **Kind**: global function
175
- **Returns**: <code>Object</code> - The converted object
176
-
177
- | Param | Type | Description |
178
- | --- | --- | --- |
179
- | searchParams | <code>URLSearchParams</code> | the search params object |
180
-
181
- <a name="extractBodyData"></a>
182
-
183
- ## extractBodyData(request) ⇒ <code>Object</code>
184
- Extracts and parses the body data from the request
185
-
186
- **Kind**: global function
187
- **Returns**: <code>Object</code> - The body data
188
- **Throws**:
189
-
190
- - <code>Error</code> If an error occurs parsing the body
191
-
192
-
193
- | Param | Type | Description |
194
- | --- | --- | --- |
195
- | request | [<code>PipelineRequest</code>](#PipelineRequest) | the request object (see fetch api) |
196
-
197
- <a name="formsPipe"></a>
198
-
199
- ## formsPipe(state, request) ⇒ [<code>Promise.&lt;PipelineResponse&gt;</code>](#PipelineResponse)
200
- Handle a pipeline POST request.
201
- At this point POST's only apply to json files that are backed by a workbook.
202
-
203
- **Kind**: global function
204
- **Returns**: [<code>Promise.&lt;PipelineResponse&gt;</code>](#PipelineResponse) - a response
205
-
206
- | Param | Type | Description |
207
- | --- | --- | --- |
208
- | state | [<code>PipelineState</code>](#PipelineState) | pipeline options |
209
- | request | [<code>PipelineRequest</code>](#PipelineRequest) | |
210
-
211
- <a name="htmlPipe"></a>
212
-
213
- ## htmlPipe(state, req) ⇒ [<code>PipelineResponse</code>](#PipelineResponse)
214
- Runs the default pipeline and returns the response.
215
-
216
- **Kind**: global function
217
-
218
- | Param | Type |
219
- | --- | --- |
220
- | state | [<code>PipelineState</code>](#PipelineState) |
221
- | req | [<code>PipelineRequest</code>](#PipelineRequest) |
222
-
223
- <a name="htmlPipe..res"></a>
224
-
225
- ### htmlPipe~res : [<code>PipelineResponse</code>](#PipelineResponse)
226
- **Kind**: inner constant of [<code>htmlPipe</code>](#htmlPipe)
227
- <a name="jsonPipe"></a>
228
-
229
- ## jsonPipe(state, req) ⇒ [<code>PipelineResponse</code>](#PipelineResponse)
230
- Runs the default pipeline and returns the response.
231
-
232
- **Kind**: global function
233
-
234
- | Param | Type |
235
- | --- | --- |
236
- | state | [<code>PipelineState</code>](#PipelineState) |
237
- | req | [<code>PipelineRequest</code>](#PipelineRequest) |
238
-
239
- <a name="optionsPipe"></a>
240
-
241
- ## optionsPipe(state, request) ⇒ <code>Response</code>
242
- Handles options requests
243
-
244
- **Kind**: global function
245
- **Returns**: <code>Response</code> - a response
246
-
247
- | Param | Type | Description |
248
- | --- | --- | --- |
249
- | state | [<code>PipelineState</code>](#PipelineState) | pipeline options |
250
- | request | [<code>PipelineRequest</code>](#PipelineRequest) | |
251
-