@adobe/helix-config 3.7.0 → 3.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,17 @@
1
+ # [3.8.0](https://github.com/adobe/helix-config/compare/v3.7.1...v3.8.0) (2024-07-18)
2
+
3
+
4
+ ### Features
5
+
6
+ * make ConfigStore.validate() overridable ([#139](https://github.com/adobe/helix-config/issues/139)) ([6a85c7f](https://github.com/adobe/helix-config/commit/6a85c7fbefb3687c8c4f8ae2117886507192aaac))
7
+
8
+ ## [3.7.1](https://github.com/adobe/helix-config/compare/v3.7.0...v3.7.1) (2024-07-17)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * include head surrogate key ([#137](https://github.com/adobe/helix-config/issues/137)) ([02cc43a](https://github.com/adobe/helix-config/commit/02cc43aa1a948c69a79f0256ebd90029cfe65f3a)), closes [#135](https://github.com/adobe/helix-config/issues/135)
14
+
1
15
  # [3.7.0](https://github.com/adobe/helix-config/compare/v3.6.3...v3.7.0) (2024-07-17)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-config",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Helix Config",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -257,13 +257,17 @@ async function resolveConfig(ctx, rso, scope) {
257
257
  return config;
258
258
  }
259
259
 
260
- async function getSurrogateKey(opts, profile) {
260
+ async function getSurrogateKey(opts, config) {
261
261
  const { site, org } = opts;
262
+ const profile = config?.extends?.profile;
262
263
  const keys = [
263
264
  await computeSurrogateKey(`${org}_config.json`),
264
265
  ];
265
266
  if (site) {
266
267
  keys.push(await computeSurrogateKey(`${site}--${org}_config.json`));
268
+ if (config?.code?.owner && config?.code?.repo && opts.scope === SCOPE_PIPELINE) {
269
+ keys.push(`${opts.ref}--${config.code.repo}--${config.code.owner}_head`);
270
+ }
267
271
  }
268
272
  if (profile) {
269
273
  keys.push(await computeSurrogateKey(`p:${profile}--${org}_config.json`));
@@ -359,7 +363,7 @@ export async function getConfigResponse(ctx, opts) {
359
363
  const rso = { ref, site, org };
360
364
  const config = await resolveConfig(ctx, rso, scope);
361
365
  const surrogateHeaders = {
362
- 'x-surrogate-key': await getSurrogateKey(opts, config?.extends?.profile),
366
+ 'x-surrogate-key': await getSurrogateKey(opts, config),
363
367
  };
364
368
  if (!config) {
365
369
  return new PipelineResponse('', {
@@ -177,6 +177,15 @@ export class ConfigStore {
177
177
  : `/orgs/${this.org}/${this.type}/${this.name}.json`;
178
178
  }
179
179
 
180
+ /**
181
+ * Validates the config and throws an error if not valid.
182
+ * @param {object} data the data of the config to be updated
183
+ * @returns {Promise<boolean|undefined>}
184
+ */
185
+ async validate(data) {
186
+ return validate(data, this.type);
187
+ }
188
+
180
189
  async create(ctx, data, relPath = '') {
181
190
  if (relPath) {
182
191
  throw new StatusCodeError(409, 'create not supported on substructures.');
@@ -195,7 +204,7 @@ export class ConfigStore {
195
204
  updateContentSource(ctx, data.content);
196
205
  updateCodeSource(ctx, data.code);
197
206
  }
198
- await validate(data, this.type);
207
+ await this.validate(data, this.type);
199
208
  await storage.put(this.key, JSON.stringify(data), 'application/json');
200
209
  await this.purge(ctx, null, data);
201
210
  }
@@ -315,7 +324,7 @@ export class ConfigStore {
315
324
  updateContentSource(ctx, config.content);
316
325
  updateCodeSource(ctx, config.code);
317
326
  }
318
- await validate(config, this.type);
327
+ await this.validate(config, this.type);
319
328
  await storage.put(this.key, JSON.stringify(config), 'application/json');
320
329
  await this.purge(ctx, buf ? JSON.parse(buf) : null, config);
321
330
  return ret ?? redact(data, frag);
@@ -330,7 +339,7 @@ export class ConfigStore {
330
339
  const frag = getFragmentInfo(this.type, relPath);
331
340
  if (frag) {
332
341
  const data = deepPut(JSON.parse(buf), relPath, null);
333
- await validate(data, this.type);
342
+ await this.validate(data, this.type);
334
343
  await storage.put(this.key, JSON.stringify(data), 'application/json');
335
344
  await this.purge(ctx, JSON.parse(buf), data);
336
345
  return;