@adobe/helix-config 2.4.0 → 2.5.1
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 +14 -0
- package/package.json +1 -1
- package/src/config-legacy.js +3 -8
- package/src/config-view.js +14 -11
- package/src/storage/config-store.js +3 -2
- package/src/storage/utils.js +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.5.1](https://github.com/adobe/helix-config/compare/v2.5.0...v2.5.1) (2024-04-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* use head from ref and return 404 if missing ([#47](https://github.com/adobe/helix-config/issues/47)) ([61ab5b5](https://github.com/adobe/helix-config/commit/61ab5b5b6758752c6c87cb64b02d10155a674ab6))
|
|
7
|
+
|
|
8
|
+
# [2.5.0](https://github.com/adobe/helix-config/compare/v2.4.0...v2.5.0) (2024-04-16)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* calculate contentBusId on update ([#46](https://github.com/adobe/helix-config/issues/46)) ([85724df](https://github.com/adobe/helix-config/commit/85724dfa38738f75934d9b64cc9c01e53bd6c417))
|
|
14
|
+
|
|
1
15
|
# [2.4.0](https://github.com/adobe/helix-config/compare/v2.3.4...v2.4.0) (2024-04-15)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/config-legacy.js
CHANGED
|
@@ -17,14 +17,13 @@ const HELIX_CONTENT_BUS = 'helix-content-bus';
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Retrieves the helix-config.json which is an aggregate from fstab.yaml and head.html.
|
|
20
|
-
* Note: it always uses the branch `main`.
|
|
21
20
|
*
|
|
22
21
|
* @param {ConfigContext} ctx the context
|
|
23
22
|
* @param {RSO} rso
|
|
24
23
|
* @returns {Promise<HelixConfig|null>} the helix-config or {@code null} if optional and not found.
|
|
25
24
|
*/
|
|
26
25
|
async function fetchHelixConfig(ctx, rso) {
|
|
27
|
-
const key = `${rso.org}/${rso.site}/
|
|
26
|
+
const key = `${rso.org}/${rso.site}/${rso.ref}/helix-config.json`;
|
|
28
27
|
const res = await ctx.loader.getObject(HELIX_CODE_BUS, key);
|
|
29
28
|
if (!res.body) {
|
|
30
29
|
return null;
|
|
@@ -105,6 +104,8 @@ export async function resolveLegacyConfig(ctx, rso, scope) {
|
|
|
105
104
|
source,
|
|
106
105
|
},
|
|
107
106
|
folders: helixConfig.fstab?.data.folders ?? {},
|
|
107
|
+
/* c8 ignore next */
|
|
108
|
+
head: helixConfig?.head?.data ?? {},
|
|
108
109
|
};
|
|
109
110
|
const configAllPreview = await fetchConfigAll(ctx, config.content.contentBusId, 'preview');
|
|
110
111
|
const configAllLive = await fetchConfigAll(ctx, config.content.contentBusId, 'live');
|
|
@@ -130,12 +131,6 @@ export async function resolveLegacyConfig(ctx, rso, scope) {
|
|
|
130
131
|
if (configAllLive?.metadata) {
|
|
131
132
|
config.metadata.live = configAllLive.metadata;
|
|
132
133
|
}
|
|
133
|
-
|
|
134
|
-
if (helixConfig?.head?.data?.html) {
|
|
135
|
-
config.head = {
|
|
136
|
-
html: helixConfig.head.data.html,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
134
|
}
|
|
140
135
|
return config;
|
|
141
136
|
}
|
package/src/config-view.js
CHANGED
|
@@ -167,6 +167,8 @@ async function resolveConfig(ctx, rso, scope) {
|
|
|
167
167
|
preview: await loadMetadata(ctx, config, 'preview'),
|
|
168
168
|
live: await loadMetadata(ctx, config, 'live'),
|
|
169
169
|
};
|
|
170
|
+
}
|
|
171
|
+
if (scope === SCOPE_PIPELINE || scope === SCOPE_DELIVERY) {
|
|
170
172
|
config.head = await loadHeadHtml(ctx, config, rso.ref);
|
|
171
173
|
}
|
|
172
174
|
|
|
@@ -212,6 +214,17 @@ export async function getConfigResponse(ctx, opts) {
|
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
|
|
217
|
+
if (!config.head?.html && (opts.scope === SCOPE_PIPELINE || opts.scope === SCOPE_DELIVERY)) {
|
|
218
|
+
// validate that ref exists in code-bus
|
|
219
|
+
return new PipelineResponse('', {
|
|
220
|
+
status: 404,
|
|
221
|
+
headers: {
|
|
222
|
+
'x-error': 'ref does not exist (no head.html)',
|
|
223
|
+
...surrogateHeaders,
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
215
228
|
if (opts.scope === SCOPE_DELIVERY) {
|
|
216
229
|
return new PipelineResponse('', {
|
|
217
230
|
headers: {
|
|
@@ -250,6 +263,7 @@ export async function getConfigResponse(ctx, opts) {
|
|
|
250
263
|
}
|
|
251
264
|
|
|
252
265
|
if (opts.scope === SCOPE_RAW) {
|
|
266
|
+
delete config.head;
|
|
253
267
|
return new PipelineResponse(JSON.stringify(config, null, 2), {
|
|
254
268
|
headers: {
|
|
255
269
|
'content-type': 'application/json',
|
|
@@ -259,17 +273,6 @@ export async function getConfigResponse(ctx, opts) {
|
|
|
259
273
|
}
|
|
260
274
|
|
|
261
275
|
if (opts.scope === SCOPE_PIPELINE) {
|
|
262
|
-
// validate that ref exists in code-bus
|
|
263
|
-
if (!config.head?.html) {
|
|
264
|
-
return new PipelineResponse('', {
|
|
265
|
-
status: 404,
|
|
266
|
-
headers: {
|
|
267
|
-
'x-error': 'ref does not exist (no head.html)',
|
|
268
|
-
...surrogateHeaders,
|
|
269
|
-
},
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
276
|
// remove all properties except `host`. pipeline doesn't need the others.
|
|
274
277
|
retainProperty(config.cdn, 'host');
|
|
275
278
|
const pipelineConfig = {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { HelixStorage } from './storage.js';
|
|
13
13
|
import { StatusCodeError } from './status-code-error.js';
|
|
14
|
-
import { jsonGet, jsonPut } from './utils.js';
|
|
14
|
+
import { jsonGet, jsonPut, updateContentBusId } from './utils.js';
|
|
15
15
|
|
|
16
16
|
const FRAGMENTS = {
|
|
17
17
|
sites: {
|
|
@@ -65,6 +65,7 @@ export class ConfigStore {
|
|
|
65
65
|
if (await storage.head(this.key)) {
|
|
66
66
|
throw new StatusCodeError(409, 'config already exists.');
|
|
67
67
|
}
|
|
68
|
+
updateContentBusId(ctx, data);
|
|
68
69
|
await storage.put(this.key, JSON.stringify(data), 'application/json');
|
|
69
70
|
await this.purge(ctx, null, data);
|
|
70
71
|
}
|
|
@@ -101,7 +102,7 @@ export class ConfigStore {
|
|
|
101
102
|
// eslint-disable-next-line no-param-reassign
|
|
102
103
|
data = jsonPut(JSON.parse(buf), relPath, data);
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
updateContentBusId(ctx, data);
|
|
105
106
|
await storage.put(this.key, JSON.stringify(data), 'application/json');
|
|
106
107
|
await this.purge(ctx, old, data);
|
|
107
108
|
}
|
package/src/storage/utils.js
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
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 crypto from 'crypto';
|
|
13
|
+
|
|
12
14
|
export function jsonGet(obj, path) {
|
|
13
15
|
return path.split('/').reduce((o, p) => o[p], obj);
|
|
14
16
|
}
|
|
@@ -30,3 +32,28 @@ export function jsonPut(obj, path, value) {
|
|
|
30
32
|
}
|
|
31
33
|
return obj;
|
|
32
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Update the contentBusId field of the content object based on the source URL.
|
|
38
|
+
* @param ctx
|
|
39
|
+
* @param data
|
|
40
|
+
* @returns {boolean}
|
|
41
|
+
*/
|
|
42
|
+
export function updateContentBusId(ctx, data) {
|
|
43
|
+
if (!data.content?.source?.url) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const sha256 = crypto
|
|
47
|
+
.createHash('sha256')
|
|
48
|
+
.update(data.content.source.url)
|
|
49
|
+
.digest('hex');
|
|
50
|
+
const contentBusId = `${sha256.substring(0, 59)}`;
|
|
51
|
+
if (contentBusId === data.content.contentBusId) {
|
|
52
|
+
ctx.log.info(`contentBusId is already correct for ${data.content.source.url}: ${contentBusId}`);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
ctx.log.info(`Updating contentBusId for ${data.content.source.url}: ${contentBusId}`);
|
|
56
|
+
// eslint-disable-next-line no-param-reassign
|
|
57
|
+
data.content.contentBusId = contentBusId;
|
|
58
|
+
return true;
|
|
59
|
+
}
|