@adobe/helix-html-pipeline 6.7.10 → 6.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
+ # [6.8.0](https://github.com/adobe/helix-html-pipeline/compare/v6.7.10...v6.8.0) (2024-04-18)
2
+
3
+
4
+ ### Features
5
+
6
+ * serve /config.json ([#589](https://github.com/adobe/helix-html-pipeline/issues/589)) ([f01f9ce](https://github.com/adobe/helix-html-pipeline/commit/f01f9ced59e21aa406c24babe4200e8267dd72e8))
7
+
1
8
  ## [6.7.10](https://github.com/adobe/helix-html-pipeline/compare/v6.7.9...v6.7.10) (2024-04-17)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-html-pipeline",
3
- "version": "6.7.10",
3
+ "version": "6.8.0",
4
4
  "description": "Helix HTML Pipeline",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/json-pipe.js CHANGED
@@ -46,10 +46,12 @@ async function fetchJsonContent(state, req, res) {
46
46
  owner, repo, ref, contentBusId, partition, s3Loader, log, info,
47
47
  } = state;
48
48
  const { path } = state.info;
49
+ state.content.sourceBus = 'content';
49
50
  let ret = await s3Loader.getObject('helix-content-bus', `${contentBusId}/${partition}${path}`);
50
51
 
51
52
  // if not found, fall back to code bus
52
53
  if (ret.status === 404) {
54
+ state.content.sourceBus = 'code';
53
55
  ret = await s3Loader.getObject('helix-code-bus', `${owner}/${repo}/${ref}${path}`);
54
56
  }
55
57
 
@@ -76,15 +78,23 @@ async function fetchJsonContent(state, req, res) {
76
78
 
77
79
  updateLastModified(state, res, extractLastModified(ret.headers));
78
80
  } else {
81
+ state.content.sourceBus = 'content';
79
82
  res.status = ret.status === 404 ? 404 : 502;
80
83
  res.error = `failed to load ${state.info.resourcePath}: ${ret.status}`;
81
84
  }
82
85
  }
83
86
 
84
- async function computeSurrogateKeys(path, contentBusId) {
87
+ async function computeSurrogateKeys(state) {
85
88
  const keys = [];
86
- keys.push(`${contentBusId}${path}`.replace(/\//g, '_')); // TODO: remove
87
- keys.push(await computeSurrogateKey(`${contentBusId}${path}`));
89
+ const pathKey = state.content?.sourceBus === 'code'
90
+ ? `${state.ref}--${state.repo}--${state.owner}${state.info.path}`
91
+ : `${state.contentBusId}${state.info.path}`;
92
+
93
+ if (state.info.path === '/config.json') {
94
+ keys.push(await computeSurrogateKey(`${state.site}--${state.org}_config.json`));
95
+ }
96
+ keys.push(pathKey.replace(/\//g, '_')); // TODO: remove
97
+ keys.push(await computeSurrogateKey(pathKey));
88
98
  return keys;
89
99
  }
90
100
 
@@ -142,23 +152,27 @@ export async function jsonPipe(state, req) {
142
152
 
143
153
  await authenticate(state, req, res);
144
154
 
145
- if (res.error) {
155
+ if (res.status === 404 && state.info.path === '/config.json' && state.config.public) {
156
+ // special handling for public config
157
+ res.status = 200;
158
+ res.body = JSON.stringify(state.config.public, null, 2);
159
+ } else if (res.error) {
146
160
  if (res.status < 400) {
147
161
  return res;
148
162
  }
149
163
  throw new PipelineStatusError(res.status, res.error);
164
+ } else {
165
+ // filter data
166
+ jsonFilter(state, res, {
167
+ limit: limit ? Number.parseInt(limit, 10) : undefined,
168
+ offset: offset ? Number.parseInt(offset, 10) : undefined,
169
+ sheet,
170
+ raw: limit === undefined && offset === undefined && sheet === undefined,
171
+ });
150
172
  }
151
173
 
152
- // filter data
153
- jsonFilter(state, res, {
154
- limit: limit ? Number.parseInt(limit, 10) : undefined,
155
- offset: offset ? Number.parseInt(offset, 10) : undefined,
156
- sheet,
157
- raw: limit === undefined && offset === undefined && sheet === undefined,
158
- });
159
-
160
174
  // set surrogate keys
161
- const keys = await computeSurrogateKeys(state.info.path, state.contentBusId);
175
+ const keys = await computeSurrogateKeys(state);
162
176
  res.headers.set('x-surrogate-key', keys.join(' '));
163
177
 
164
178
  await setCustomResponseHeaders(state, req, res);
@@ -175,7 +189,7 @@ export async function jsonPipe(state, req) {
175
189
  await setCustomResponseHeaders(state, req, res);
176
190
  }
177
191
  if (res.status === 404) {
178
- const keys = await computeSurrogateKeys(state.info.path, state.contentBusId);
192
+ const keys = await computeSurrogateKeys(state);
179
193
  res.headers.set('x-surrogate-key', keys.join(' '));
180
194
  }
181
195
  return res;