@adobe/helix-config 2.18.0 → 2.18.2

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
+ ## [2.18.2](https://github.com/adobe/helix-config/compare/v2.18.1...v2.18.2) (2024-05-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * use webcrypto for better support ([#82](https://github.com/adobe/helix-config/issues/82)) ([0eb3a5b](https://github.com/adobe/helix-config/commit/0eb3a5b3ddba9a809c617e09d40f7d6ba98e0663))
7
+
8
+ ## [2.18.1](https://github.com/adobe/helix-config/compare/v2.18.0...v2.18.1) (2024-05-09)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * allow to set public configuration ([#80](https://github.com/adobe/helix-config/issues/80)) ([3a5b175](https://github.com/adobe/helix-config/commit/3a5b175f1afc074edd398f5a75a0c271c91ddc72))
14
+
1
15
  # [2.18.0](https://github.com/adobe/helix-config/compare/v2.17.0...v2.18.0) (2024-05-09)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-config",
3
- "version": "2.18.0",
3
+ "version": "2.18.2",
4
4
  "description": "Helix Config",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -36,18 +36,11 @@
36
36
  "reporter": "mocha-multi-reporters",
37
37
  "reporter-options": "configFile=.mocha-multi.json"
38
38
  },
39
- "imports": {
40
- "#crypto": {
41
- "node": "./src/crypto.node.js",
42
- "browser": "./src/crypto.worker.js",
43
- "worker": "./src/crypto.worker.js"
44
- }
45
- },
46
39
  "devDependencies": {
47
40
  "@adobe/eslint-config-helix": "2.0.6",
48
41
  "@semantic-release/changelog": "6.0.3",
49
42
  "@semantic-release/git": "10.0.1",
50
- "@semantic-release/npm": "12.0.0",
43
+ "@semantic-release/npm": "12.0.1",
51
44
  "c8": "9.1.0",
52
45
  "eslint": "8.57.0",
53
46
  "husky": "9.0.11",
@@ -58,7 +51,7 @@
58
51
  "mocha-multi-reporters": "1.5.1",
59
52
  "mocha-suppress-logs": "0.5.1",
60
53
  "nock": "13.5.4",
61
- "semantic-release": "23.0.8"
54
+ "semantic-release": "23.1.1"
62
55
  },
63
56
  "lint-staged": {
64
57
  "*.js": "eslint",
@@ -72,6 +65,6 @@
72
65
  "@adobe/helix-shared-utils": "3.0.2",
73
66
  "ajv": "8.13.0",
74
67
  "ajv-formats": "3.0.1",
75
- "jose": "5.2.4"
68
+ "jose": "5.3.0"
76
69
  }
77
70
  }
@@ -32,6 +32,7 @@ const ROOT_PROPERTIES = {
32
32
  robots: {},
33
33
  extends: {},
34
34
  tokens: {},
35
+ public: {},
35
36
  };
36
37
 
37
38
  const FORCED_TYPES = {
@@ -12,7 +12,6 @@
12
12
  import { ModifiersConfig } from '@adobe/helix-shared-config/modifiers';
13
13
  import { computeSurrogateKey } from '@adobe/helix-shared-utils';
14
14
  // eslint-disable-next-line import/no-unresolved
15
- import cryptoImpl from '#crypto';
16
15
  import { PipelineResponse } from './PipelineResponse.js';
17
16
  import {
18
17
  SCOPE_ADMIN,
@@ -69,23 +68,35 @@ export function canonicalArrayString(root, partition, prop) {
69
68
  * Returns the hash of the global delivery token if defined.
70
69
  * @param ctx
71
70
  * @param rso
72
- * @returns {string|null}
71
+ * @returns {Promise<string|null>}
73
72
  */
74
- function getGlobalTokenHash(ctx, rso) {
73
+ async function getGlobalTokenHash(ctx, rso) {
75
74
  if (!ctx.env.HLX_GLOBAL_DELIVERY_TOKEN) {
76
75
  return null;
77
76
  }
78
- return cryptoImpl
79
- .createHmac('sha512', rso.org)
80
- .update(ctx.env.HLX_GLOBAL_DELIVERY_TOKEN, 'utf-8')
81
- .digest()
82
- .toString('base64url');
77
+ // use webcrypto for better support for cloudflare workers
78
+ const enc = new TextEncoder('utf-8');
79
+ const key = await crypto.subtle.importKey(
80
+ 'raw',
81
+ enc.encode(rso.org),
82
+ {
83
+ name: 'HMAC',
84
+ hash: { name: 'SHA-512' },
85
+ },
86
+ false,
87
+ ['sign', 'verify'],
88
+ );
89
+ const buffer = await crypto.subtle.sign('HMAC', key, enc.encode(ctx.env.HLX_GLOBAL_DELIVERY_TOKEN));
90
+ return btoa(String.fromCharCode(...new Uint8Array(buffer)))
91
+ .replaceAll('/', '_')
92
+ .replaceAll('+', '-')
93
+ .replaceAll('=', '');
83
94
  }
84
95
 
85
96
  /**
86
97
  * Returns the normalized access configuration for the give partition.
87
98
  */
88
- export function getAccessConfig(ctx, config, partition, rso) {
99
+ export async function getAccessConfig(ctx, config, partition, rso) {
89
100
  const { access, tokens = {} } = config;
90
101
  const apiKeyId = toArray(access[partition]?.apiKeyId ?? access.apiKeyId);
91
102
  const allow = toArray(access[partition]?.allow ?? access.allow);
@@ -107,7 +118,7 @@ export function getAccessConfig(ctx, config, partition, rso) {
107
118
  // if an apiKeyId is defined but no tokenHash, create a fake one so that auth is still enforced.
108
119
  if (cfg.apiKeyId.length) {
109
120
  // add global token hash if defined and needed
110
- const globalTokenHash = getGlobalTokenHash(ctx, rso);
121
+ const globalTokenHash = await getGlobalTokenHash(ctx, rso);
111
122
  if (cfg.tokenHash.length && globalTokenHash) {
112
123
  // augment the list of hashes with the global one if exists
113
124
  cfg.tokenHash.push(globalTokenHash);
@@ -279,8 +290,8 @@ export async function getConfigResponse(ctx, opts) {
279
290
  // normalize access config
280
291
  const { admin = {} } = config.access;
281
292
  config.access = {
282
- preview: getAccessConfig(ctx, config, 'preview', rso),
283
- live: getAccessConfig(ctx, config, 'live', rso),
293
+ preview: await getAccessConfig(ctx, config, 'preview', rso),
294
+ live: await getAccessConfig(ctx, config, 'live', rso),
284
295
  // access.require.repository ?
285
296
  };
286
297
  if (opts.scope === SCOPE_ADMIN || opts.scope === SCOPE_RAW) {
@@ -49,6 +49,9 @@
49
49
  },
50
50
  "robots": {
51
51
  "$ref": "https://ns.adobe.com/helix/config/robots"
52
+ },
53
+ "public": {
54
+ "$ref": "https://ns.adobe.com/helix/config/public"
52
55
  }
53
56
  },
54
57
  "required": [
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2018 Adobe. All rights reserved.
2
+ * Copyright 2024 Adobe. All rights reserved.
3
3
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License. You may obtain a copy
5
5
  * of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -9,8 +9,4 @@
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
-
13
- // node runtime
14
- import cryptoImpl from 'node:crypto';
15
-
16
- export default cryptoImpl;
12
+ module.exports = require('./public.schema.json');
@@ -0,0 +1,18 @@
1
+ {
2
+ "meta:license": [
3
+ "Copyright 2024 Adobe. All rights reserved.",
4
+ "This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
5
+ "you may not use this file except in compliance with the License. You may obtain a copy",
6
+ "of the License at http://www.apache.org/licenses/LICENSE-2.0",
7
+ "",
8
+ "Unless required by applicable law or agreed to in writing, software distributed under",
9
+ "the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
10
+ "OF ANY KIND, either express or implied. See the License for the specific language",
11
+ "governing permissions and limitations under the License."
12
+ ],
13
+ "$schema": "http://json-schema.org/draft-07/schema#",
14
+ "$id": "https://ns.adobe.com/helix/config/public",
15
+ "type": "object",
16
+ "title": "public",
17
+ "description": "Public configuration"
18
+ }
@@ -55,6 +55,9 @@
55
55
  "robots": {
56
56
  "$ref": "https://ns.adobe.com/helix/config/robots"
57
57
  },
58
+ "public": {
59
+ "$ref": "https://ns.adobe.com/helix/config/public"
60
+ },
58
61
  "extends": {
59
62
  "profile": {
60
63
  "type": "string",
@@ -26,6 +26,7 @@ import markupSchema from '../schemas/content-source-markup.schema.cjs';
26
26
  import metadataSchema from '../schemas/metadata-source.schema.cjs';
27
27
  import orgSchema from '../schemas/org.schema.cjs';
28
28
  import onedriveSchema from '../schemas/content-source-onedrive.schema.cjs';
29
+ import publicSchema from '../schemas/public.schema.cjs';
29
30
  import profileSchema from '../schemas/profile.schema.cjs';
30
31
  import robotsSchema from '../schemas/robots.schema.cjs';
31
32
  import sidekickSchema from '../schemas/sidekick.schema.cjs';
@@ -46,6 +47,7 @@ const SCHEMAS = [
46
47
  metadataSchema,
47
48
  orgSchema,
48
49
  onedriveSchema,
50
+ publicSchema,
49
51
  profileSchema,
50
52
  robotsSchema,
51
53
  sidekickSchema,
@@ -31,6 +31,7 @@ export interface HelixProfileConfig {
31
31
  sidekick?: SidekickConfig;
32
32
  metadata?: Metadata;
33
33
  robots?: Robots;
34
+ public?: Public;
34
35
  }
35
36
  /**
36
37
  * Defines the content bus location and source.
@@ -246,3 +247,9 @@ export interface Metadata {
246
247
  export interface Robots {
247
248
  txt?: string;
248
249
  }
250
+ /**
251
+ * Public configuration
252
+ */
253
+ export interface Public {
254
+ [k: string]: unknown;
255
+ }
@@ -35,6 +35,7 @@ export interface HelixSiteConfig {
35
35
  sidekick?: SidekickConfig;
36
36
  metadata?: Metadata;
37
37
  robots?: Robots;
38
+ public?: Public;
38
39
  extends?: {
39
40
  [k: string]: unknown;
40
41
  };
@@ -253,3 +254,9 @@ export interface Metadata {
253
254
  export interface Robots {
254
255
  txt?: string;
255
256
  }
257
+ /**
258
+ * Public configuration
259
+ */
260
+ export interface Public {
261
+ [k: string]: unknown;
262
+ }
@@ -1,15 +0,0 @@
1
- /*
2
- * Copyright 2018 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- // browser/worker runtime
14
- // eslint-disable-next-line no-undef
15
- export default crypto;