@adobe/helix-config 2.3.4 → 2.5.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
+ # [2.5.0](https://github.com/adobe/helix-config/compare/v2.4.0...v2.5.0) (2024-04-16)
2
+
3
+
4
+ ### Features
5
+
6
+ * calculate contentBusId on update ([#46](https://github.com/adobe/helix-config/issues/46)) ([85724df](https://github.com/adobe/helix-config/commit/85724dfa38738f75934d9b64cc9c01e53bd6c417))
7
+
8
+ # [2.4.0](https://github.com/adobe/helix-config/compare/v2.3.4...v2.4.0) (2024-04-15)
9
+
10
+
11
+ ### Features
12
+
13
+ * add support for raw config ([#45](https://github.com/adobe/helix-config/issues/45)) ([7e3eab3](https://github.com/adobe/helix-config/commit/7e3eab3930ba33b9e04d502e2391e26580badbe6))
14
+
1
15
  ## [2.3.4](https://github.com/adobe/helix-config/compare/v2.3.3...v2.3.4) (2024-04-15)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-config",
3
- "version": "2.3.4",
3
+ "version": "2.5.0",
4
4
  "description": "Helix Config",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -27,9 +27,14 @@ export const SCOPE_PIPELINE = 'pipeline';
27
27
  * Admin Service in JSON includes everything.
28
28
  * @type {string}
29
29
  */
30
- // eslint-disable-next-line no-unused-vars
31
30
  export const SCOPE_ADMIN = 'admin';
32
31
 
32
+ /**
33
+ * Raw config service view, also for legacy sites.
34
+ * @type {string}
35
+ */
36
+ export const SCOPE_RAW = 'raw';
37
+
33
38
  /**
34
39
  * Public / Custom Configs: Sidekick, Production Host, Custom Preview Page / Live Host, Custom JSON.
35
40
  * @type {string}
@@ -80,41 +80,57 @@ export async function resolveLegacyConfig(ctx, rso, scope) {
80
80
  if (!helixConfig) {
81
81
  return null;
82
82
  }
83
- const { contentBusId, ...source } = helixConfig.content.data['/'];
83
+ const { contentBusId } = helixConfig.content.data['/'];
84
+ let source = helixConfig.fstab?.data.mountpoints['/'];
85
+ if (typeof source === 'string') {
86
+ source = {
87
+ type: source.startsWith('https://drive.google.com/')
88
+ ? 'google'
89
+ : 'onedrive',
90
+ url: source,
91
+ };
92
+ }
84
93
  const config = {
85
94
  version: 1,
86
95
  code: {
87
96
  owner: rso.org,
88
97
  repo: rso.site,
98
+ source: {
99
+ type: 'github',
100
+ url: `https://github.com/${rso.org}/${rso.site}`,
101
+ },
89
102
  },
90
103
  content: {
91
104
  contentBusId,
92
105
  source,
93
106
  },
107
+ folders: helixConfig.fstab?.data.folders ?? {},
94
108
  };
95
109
  const configAllPreview = await fetchConfigAll(ctx, config.content.contentBusId, 'preview');
110
+ const configAllLive = await fetchConfigAll(ctx, config.content.contentBusId, 'live');
96
111
  const { access } = configAllPreview?.config?.data || {};
97
112
  if (access) {
98
113
  config.access = access;
99
114
  }
115
+ if (configAllPreview) {
116
+ config.cdn = configAllPreview.config?.data.cdn ?? {};
117
+ if (!config.cdn.prod?.host && configAllPreview.config?.data.host) {
118
+ config.cdn.prod = {
119
+ host: configAllPreview.config.data.host,
120
+ };
121
+ }
122
+ }
123
+
100
124
  if (scope === SCOPE_PIPELINE) {
101
125
  config.metadata = {};
102
126
  if (configAllPreview) {
103
127
  config.headers = configAllPreview.headers?.data ?? {};
104
128
  config.metadata.preview = configAllPreview.metadata ?? {};
105
- config.cdn = configAllPreview.config?.data.cdn ?? {};
106
- if (!config.cdn.prod?.host && configAllPreview.config?.data.host) {
107
- config.cdn.prod = {
108
- host: configAllPreview.config.data.host,
109
- };
110
- }
111
129
  }
112
- const configAllLive = await fetchConfigAll(ctx, config.content.contentBusId, 'live');
113
130
  if (configAllLive?.metadata) {
114
131
  config.metadata.live = configAllLive.metadata;
115
132
  }
116
133
 
117
- config.folders = helixConfig.fstab.data.folders ?? {};
118
134
  if (helixConfig?.head?.data?.html) {
119
135
  config.head = {
120
136
  html: helixConfig.head.data.html,
@@ -12,7 +12,12 @@
12
12
  import { ModifiersConfig } from '@adobe/helix-shared-config/modifiers';
13
13
  import { computeSurrogateKey } from '@adobe/helix-shared-utils';
14
14
  import { PipelineResponse } from './PipelineResponse.js';
15
- import { SCOPE_ADMIN, SCOPE_PIPELINE, SCOPE_DELIVERY } from './ConfigContext.js';
15
+ import {
16
+ SCOPE_ADMIN,
17
+ SCOPE_PIPELINE,
18
+ SCOPE_DELIVERY,
19
+ SCOPE_RAW,
20
+ } from './ConfigContext.js';
16
21
  import { resolveLegacyConfig } from './config-legacy.js';
17
22
 
18
23
  /**
@@ -202,7 +207,7 @@ export async function getConfigResponse(ctx, opts) {
202
207
  live: getAccessConfig(config.access, 'live'),
203
208
  // access.require.repository ?
204
209
  };
205
- if (opts.scope === SCOPE_ADMIN) {
210
+ if (opts.scope === SCOPE_ADMIN || opts.scope === SCOPE_RAW) {
206
211
  config.access.admin = admin;
207
212
  }
208
213
  }
@@ -235,6 +240,7 @@ export async function getConfigResponse(ctx, opts) {
235
240
  ...config.content.source,
236
241
  },
237
242
  };
243
+ delete adminConfig.public;
238
244
  return new PipelineResponse(JSON.stringify(adminConfig, null, 2), {
239
245
  headers: {
240
246
  'content-type': 'application/json',
@@ -243,6 +249,15 @@ export async function getConfigResponse(ctx, opts) {
243
249
  });
244
250
  }
245
251
 
252
+ if (opts.scope === SCOPE_RAW) {
253
+ return new PipelineResponse(JSON.stringify(config, null, 2), {
254
+ headers: {
255
+ 'content-type': 'application/json',
256
+ ...surrogateHeaders,
257
+ },
258
+ });
259
+ }
260
+
246
261
  if (opts.scope === SCOPE_PIPELINE) {
247
262
  // validate that ref exists in code-bus
248
263
  if (!config.head?.html) {
@@ -282,7 +297,7 @@ export async function getConfigResponse(ctx, opts) {
282
297
  const publicConfig = {
283
298
  version: 1,
284
299
  ...rso,
285
- public: {},
300
+ public: config.public || {},
286
301
  };
287
302
  return new PipelineResponse(JSON.stringify(publicConfig, null, 2), {
288
303
  headers: {
@@ -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: {
@@ -29,6 +29,7 @@ const FRAGMENTS = {
29
29
  'access/admin': 'object',
30
30
  'access/preview': 'object',
31
31
  'access/live': 'object',
32
+ public: 'object',
32
33
  },
33
34
  };
34
35
 
@@ -64,6 +65,7 @@ export class ConfigStore {
64
65
  if (await storage.head(this.key)) {
65
66
  throw new StatusCodeError(409, 'config already exists.');
66
67
  }
68
+ updateContentBusId(ctx, data);
67
69
  await storage.put(this.key, JSON.stringify(data), 'application/json');
68
70
  await this.purge(ctx, null, data);
69
71
  }
@@ -100,7 +102,7 @@ export class ConfigStore {
100
102
  // eslint-disable-next-line no-param-reassign
101
103
  data = jsonPut(JSON.parse(buf), relPath, data);
102
104
  }
103
-
105
+ updateContentBusId(ctx, data);
104
106
  await storage.put(this.key, JSON.stringify(data), 'application/json');
105
107
  await this.purge(ctx, old, data);
106
108
  }
@@ -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
+ }