@adobe/helix-config 2.15.1 → 2.16.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
+ # [2.16.0](https://github.com/adobe/helix-config/compare/v2.15.1...v2.16.0) (2024-05-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * add global token hash if needed ([#76](https://github.com/adobe/helix-config/issues/76)) ([ac4a139](https://github.com/adobe/helix-config/commit/ac4a139497a98302ef9627644f5b9918ee76c282))
7
+
1
8
  ## [2.15.1](https://github.com/adobe/helix-config/compare/v2.15.0...v2.15.1) (2024-05-07)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-config",
3
- "version": "2.15.1",
3
+ "version": "2.16.0",
4
4
  "description": "Helix Config",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "type": "module",
12
12
  "scripts": {
13
- "test": "c8 mocha",
13
+ "test": "c8 mocha --spec 'test/**/*.test.js'",
14
14
  "lint": "eslint .",
15
15
  "docs:types": "node ./test/dev/generate-types.js",
16
16
  "semantic-release": "semantic-release",
@@ -66,7 +66,7 @@ export function canonicalArrayString(root, partition, prop) {
66
66
  /**
67
67
  * Returns the normalized access configuration for the give partition.
68
68
  */
69
- export function getAccessConfig(config, partition) {
69
+ export function getAccessConfig(ctx, config, partition) {
70
70
  const { access, tokens = {} } = config;
71
71
  const apiKeyId = toArray(access[partition]?.apiKeyId ?? access.apiKeyId);
72
72
  const allow = toArray(access[partition]?.allow ?? access.allow);
@@ -84,11 +84,20 @@ export function getAccessConfig(config, partition) {
84
84
  if (allow.length && !cfg.apiKeyId.length) {
85
85
  cfg.apiKeyId.push('dummy');
86
86
  }
87
- // if an apiKeyId is defined but no tokenHash, create a fake one so that auth is still
88
- // enforced.
89
- if (cfg.apiKeyId.length && !cfg.tokenHash.length) {
90
- cfg.tokenHash.push('n/a');
87
+
88
+ // if an apiKeyId is defined but no tokenHash, create a fake one so that auth is still enforced.
89
+ if (cfg.apiKeyId.length) {
90
+ // add global token hash if defined and needed
91
+ const globalTokenHash = ctx.env.HLX_GLOBAL_TOKEN_HASH;
92
+ if (cfg.tokenHash.length && globalTokenHash) {
93
+ // augment the list of hashes with the global one if exists
94
+ cfg.tokenHash.push(globalTokenHash);
95
+ } else if (!cfg.tokenHash.length) {
96
+ // add a dummy or global hash if no tokens match the apiKeyIds.
97
+ cfg.tokenHash.push(globalTokenHash || 'n/a');
98
+ }
91
99
  }
100
+
92
101
  // todo: remove after auth rewrite
93
102
  if (allow) {
94
103
  cfg.allow = allow;
@@ -255,8 +264,8 @@ export async function getConfigResponse(ctx, opts) {
255
264
  // normalize access config
256
265
  const { admin = {} } = config.access;
257
266
  config.access = {
258
- preview: getAccessConfig(config, 'preview'),
259
- live: getAccessConfig(config, 'live'),
267
+ preview: getAccessConfig(ctx, config, 'preview'),
268
+ live: getAccessConfig(ctx, config, 'live'),
260
269
  // access.require.repository ?
261
270
  };
262
271
  if (opts.scope === SCOPE_ADMIN || opts.scope === SCOPE_RAW) {