@adobe/helix-admin-support 5.2.2 → 6.0.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 CHANGED
@@ -1,3 +1,25 @@
1
+ ## [6.0.1](https://github.com/adobe/helix-admin-support/compare/v6.0.0...v6.0.1) (2026-11-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * harden flatJson2object ([837d401](https://github.com/adobe/helix-admin-support/commit/837d40191215c20643a02553b463cf6b4a6cd7c1))
7
+
8
+ # [6.0.0](https://github.com/adobe/helix-admin-support/compare/v5.2.2...v6.0.0) (2026-09-18)
9
+
10
+
11
+ * feat!: use helix storage for content/code bus access ([#564](https://github.com/adobe/helix-admin-support/issues/564)) ([e007540](https://github.com/adobe/helix-admin-support/commit/e0075404cd5d092ad7647006354a164c16419db9))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * fetch-config, fetch-config-all, fetch-fstab, and
17
+ fetch-helix-config (and their exports, including calculateContentBusId)
18
+ have been removed. fetchCrontab, fetchIndex, and fetchSitemap now read
19
+ contentBusId from context.attributes.contentBusId directly (the
20
+ fstab/helix-config.json fallback lookup is gone) and require
21
+ context.attributes.storage to be set; they throw if storage is missing.
22
+
1
23
  ## [5.2.2](https://github.com/adobe/helix-admin-support/compare/v5.2.1...v5.2.2) (2026-09-17)
2
24
 
3
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-admin-support",
3
- "version": "5.2.2",
3
+ "version": "6.0.1",
4
4
  "description": "Helix Admin Support Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -45,7 +45,8 @@
45
45
  "@smithy/node-http-handler": "^4.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@adobe/eslint-config-helix": "3.0.31",
48
+ "@adobe/eslint-config-helix": "3.0.35",
49
+ "@adobe/helix-shared-storage-s3": "2.0.1",
49
50
  "@adobe/jsonschema2md": "8.0.11",
50
51
  "@eslint/config-helpers": "0.7.0",
51
52
  "@semantic-release/changelog": "7.0.0",
@@ -54,16 +55,16 @@
54
55
  "eslint": "9.39.5",
55
56
  "husky": "9.1.7",
56
57
  "jsdoc-to-markdown": "9.1.3",
57
- "json-schema-to-typescript": "15.0.4",
58
+ "json-schema-to-typescript": "16.0.0",
58
59
  "junit-report-builder": "5.1.2",
59
- "lint-staged": "17.4.1",
60
- "mocha": "11.8.0",
61
- "mocha-multi-reporters": "1.5.1",
60
+ "lint-staged": "17.6.0",
61
+ "mocha": "12.0.3",
62
+ "mocha-multi-reporters": "1.5.2",
62
63
  "mocha-suppress-logs": "0.6.0",
63
- "nock": "14.0.17",
64
+ "nock": "15.0.6",
64
65
  "semantic-release": "25.0.9",
65
66
  "xml2js": "0.6.2",
66
- "yaml": "2.9.0"
67
+ "yaml": "2.9.1"
67
68
  },
68
69
  "lint-staged": {
69
70
  "*.js": "eslint",
@@ -12,23 +12,13 @@
12
12
  import { AdminContext, PathInfo } from './index';
13
13
 
14
14
  /**
15
- * Retrieves the content bus id by calculating the hash from the fstab.
16
- * @param {AdminContext} ctx the context
17
- * @param {PathInfo} info lookup options
18
- * @returns {Promise<string|null>} the content bus id
19
- * or {@code null} if mountpoint not found in fstab
20
- */
21
- export function calculateContentBusId(ctx, info): Promise<string|null>;
22
-
23
- /**
24
- * Retrieves the content bus id either from the context or by reading fstab entry of
25
- * helix-config.json. If the helix-config.json does contain the information (yet) it will fall back
26
- * to {@link #calculateContentBusId}.
15
+ * Retrieves the content bus id from the context.
27
16
  *
28
17
  * @param {AdminContext} ctx the context
29
18
  * @param {PathInfo} info lookup options
30
- * @param {boolean} optional returns {@code null} if the contentBusId can't be computed due to
31
- * missing helix-config or fstab.
19
+ * @param {boolean} optional if {@code true} it will return {@code null} if none of the sources
20
+ * exists.
32
21
  * @returns {Promise<string>} the content bus id
22
+ * @deprecated
33
23
  */
34
24
  export function getContentBusId(ctx:AdminContext, info:PathInfo, optional:boolean): Promise<string>;
package/src/contentbus.js CHANGED
@@ -9,41 +9,6 @@
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
- import { fetchFstab } from './fetch-fstab.js';
14
- import { fetchHelixConfig } from './fetch-helix-config.js';
15
-
16
- /**
17
- * Retrieves the content bus id by calculating the hash from the fstab.
18
- * @param {AdminContext} ctx the context
19
- * @param {PathInfo} info lookup options
20
- * @returns {Promise<string|null>} the content bus id or {@code null}
21
- * if no fstab or no mountpoint not found in fstab
22
- */
23
- export async function calculateContentBusId(ctx, info) {
24
- const { path } = info;
25
- const fstab = await fetchFstab(ctx, info, true);
26
- if (!fstab) {
27
- return null;
28
- }
29
- const mp = fstab.match(path);
30
- if (!mp) {
31
- ctx.log.error(`path specified is not mounted in fstab.yaml: ${path}`);
32
- return null;
33
- }
34
- if (!mp.url) {
35
- ctx.log.error(`mountpoint has no URL defined: ${path}`);
36
- return null;
37
- }
38
- const sha256 = crypto
39
- .createHash('sha256')
40
- .update(mp.url)
41
- .digest('hex');
42
- const contentBusId = `${sha256.substring(0, 59)}`;
43
- ctx.log.info(`computed contentBusId: ${contentBusId} for ${mp.url} of ${info.repo}--${info.owner}`);
44
- return contentBusId;
45
- }
46
-
47
12
  /**
48
13
  * Retrieves the content bus id either from the context or by reading fstab entry of
49
14
  * helix-config.json. If the helix-config.json does contain the information (yet) it will fall back
@@ -54,26 +19,11 @@ export async function calculateContentBusId(ctx, info) {
54
19
  * @param {boolean} optional if {@code true} it will return {@code null} if none of the sources
55
20
  * exists.
56
21
  * @returns {Promise<string>} the content bus id
22
+ * @deprecated
57
23
  */
58
24
  export async function getContentBusId(ctx, info, optional) {
59
- const fetchId = async () => {
60
- const helixConfig = await fetchHelixConfig(ctx, info, true);
61
- if (helixConfig?.content?.data) {
62
- const id = helixConfig.content.data['/']?.contentBusId;
63
- if (id) {
64
- ctx.log.info(`loaded contentBusId: ${id} for ${info.repo}--${info.owner}`);
65
- return id;
66
- }
67
- }
68
- return calculateContentBusId(ctx, { ...info, path: '/' });
69
- };
70
-
71
- if (ctx.attributes.contentBusId === undefined) {
72
- ctx.attributes.contentBusId = await fetchId();
73
- }
74
-
75
- if (ctx.attributes.contentBusId || optional) {
76
- return ctx.attributes.contentBusId;
25
+ if (ctx.attributes?.contentBusId || optional) {
26
+ return ctx.attributes?.contentBusId;
77
27
  }
78
28
  const err = new Error(`unable to load contentbus-id for ${info.owner}/${info.repo}/${info.ref}`);
79
29
  err.status = 404;
@@ -9,13 +9,12 @@
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 { AdminContext, PathInfo } from './index';
12
+ import { AdminContext } from './index';
13
13
 
14
14
  /**
15
15
  * Retrieves the project config from the underlying storage
16
16
  * and stores it in the context as projectConfig.
17
17
  * @param {AdminContext} ctx the context
18
- * @param {PathInfo} info path info
19
18
  * @returns {Promise<object>} the crontab
20
19
  */
21
- export function fetchCrontab(ctx:AdminContext, info:PathInfo): Promise<object>;
20
+ export function fetchCrontab(ctx:AdminContext): Promise<object>;
@@ -11,64 +11,61 @@
11
11
  */
12
12
  import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
13
13
 
14
- import { fetchS3 } from './fetch-s3.js';
15
- import { getContentBusId } from './contentbus.js';
16
-
17
14
  /**
18
15
  * Checks if the response is valid and returns the project config.
19
16
  *
20
17
  * @param {Logger} log logger
21
- * @param {Response} response content response from the storage
18
+ * @param {Buffer} buffer content response from the storage
22
19
  * @param {string} key storage key (logging information)
23
20
  * @param {string} type type of storage (logging information)
24
21
  * @returns {Promise<ProjectConfig>} the helix project config or null
25
22
  */
26
- async function handleResponse(log, response, key, type) {
27
- const text = await response.text();
28
- if (response.ok) {
29
- let props;
30
- try {
31
- const json = JSON.parse(text);
32
- props = json.data;
33
- // eslint-disable-next-line no-empty
34
- } catch (ignore) { }
35
- if (!props) {
36
- log.info(`Empty or invalid .helix/crontab.json found in ${type} ${key}`);
37
- return null;
38
- }
39
- return props;
23
+ async function handleResponse(log, buffer, key, type) {
24
+ if (!buffer) {
25
+ log.info(`No .helix/crontab.json found in ${type} ${key}`);
26
+ return null;
40
27
  }
41
-
42
- if (response.status === 404) {
43
- log.info(`No .helix/crontab.json found in ${type} ${key}, ${text}`);
28
+ let props;
29
+ try {
30
+ const json = JSON.parse(buffer);
31
+ props = json.data;
32
+ // eslint-disable-next-line no-empty
33
+ } catch (ignore) { }
34
+ if (!props) {
35
+ log.info(`Empty or invalid .helix/crontab.json found in ${type} ${key}`);
44
36
  return null;
45
37
  }
46
-
47
- log[logLevelForStatusCode(response.status)](
48
- `Invalid response (${response.status}) when fetching crontab from ${type} ${key}`,
49
- );
50
- const err = new Error(`Unable to fetch crontab: ${response.status} ${text}`);
51
- err.status = propagateStatusCode(response.status);
52
- throw err;
38
+ return props;
53
39
  }
54
40
 
55
41
  /**
56
42
  * Retrieves the project config from the underlying storage
57
43
  * and stores it in the context as projectConfig.
58
44
  * @param {AdminContext} ctx the context
59
- * @param {LookupOptions} opts lookup options
60
45
  * @returns {Promise<ProjectConfig>} the project configuration
61
46
  */
62
- export async function fetchCrontab(ctx, opts) {
47
+ export async function fetchCrontab(ctx) {
63
48
  const { log, attributes } = ctx;
64
49
  const getConfig = async () => {
65
- const contentBusId = await getContentBusId(ctx, opts, true);
50
+ const { storage, contentBusId } = attributes;
66
51
  if (!contentBusId) {
67
52
  return null;
68
53
  }
54
+ if (!storage) {
55
+ throw Error('storage required to fetch crontab.');
56
+ }
69
57
  const key = `${contentBusId}/preview/.helix/crontab.json`;
70
- const response = await fetchS3(ctx, 'content', key);
71
- return handleResponse(log, response, key, 'content-bus');
58
+ try {
59
+ const buffer = await storage.contentBus().get(key);
60
+ return handleResponse(log, buffer, key, 'content-bus');
61
+ } catch (e) {
62
+ log[logLevelForStatusCode(e.status)](
63
+ `Invalid response (${e.status}) when fetching crontab from ${key}`,
64
+ );
65
+ const err = new Error(`Unable to fetch crontab: ${e.status} ${e.message}`);
66
+ err.status = propagateStatusCode(e.status);
67
+ throw err;
68
+ }
72
69
  };
73
70
 
74
71
  if (attributes.crontab === undefined) {
@@ -9,9 +9,9 @@
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 { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
12
+
13
13
  import { IndexConfig } from '@adobe/helix-shared-config';
14
- import { fetchS3 } from './fetch-s3.js';
14
+ import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
15
15
  import { getContentBusId } from './contentbus.js';
16
16
 
17
17
  /**
@@ -28,26 +28,17 @@ const INDEX_LOCATION = 'preview/.helix/query.yaml';
28
28
  * Checks if the response is valid and returns an index config.
29
29
  *
30
30
  * @param {Logger} log logger
31
- * @param {Response} response content response from the storage
31
+ * @param {Buffer} buffer content response from the storage
32
32
  * @param {string} key storage key (logging information)
33
33
  * @param {string} type type of storage (logging information
34
34
  * @returns {Promise<IndexConfig>} the index config or null
35
35
  */
36
- async function handleResponse(log, response, key, type) {
37
- const text = await response.text();
38
- if (response.ok) {
39
- return new IndexConfig().withSource(text).init();
40
- }
41
-
42
- if (response.status === 404) {
43
- log.info(`No index configuration found in ${type} ${key}, ${text}`);
44
- return null;
36
+ async function handleResponse(log, buffer, key, type) {
37
+ if (buffer) {
38
+ return new IndexConfig().withSource(buffer.toString('utf-8')).init();
45
39
  }
46
-
47
- log[logLevelForStatusCode(response.status)](`Invalid response (${response.status}) when fetching index configuration from ${type} ${key}`);
48
- const err = new Error(`Unable to fetch index configuration: ${response.status} ${text}`);
49
- err.status = propagateStatusCode(response.status);
50
- throw err;
40
+ log.info(`No index configuration found in ${type} ${key}`);
41
+ return null;
51
42
  }
52
43
 
53
44
  /**
@@ -72,18 +63,29 @@ export async function fetchIndex(ctx, opts, optional) {
72
63
  return null;
73
64
  }
74
65
 
75
- let key = `${contentBusId}/${INDEX_LOCATION}`;
76
- let response = await fetchS3(ctx, 'content', key);
77
- attributes.indexConfig = await handleResponse(log, response, key, 'content-bus');
78
- if (attributes.indexConfig) {
79
- return attributes.indexConfig;
66
+ const { storage } = attributes;
67
+ if (!storage) {
68
+ throw Error('storage required to fetch index.');
80
69
  }
70
+ let key = `${contentBusId}/${INDEX_LOCATION}`;
71
+ try {
72
+ let buffer = await storage.contentBus().get(key);
73
+ attributes.indexConfig = await handleResponse(log, buffer, key, 'content-bus');
74
+ if (attributes.indexConfig) {
75
+ return attributes.indexConfig;
76
+ }
81
77
 
82
- key = `${owner}/${repo}/main/${INDEX_CONFIGURATION_NAME}`;
83
- response = await fetchS3(ctx, 'code', key);
84
- attributes.indexConfig = await handleResponse(log, response, key, 'code-bus');
85
- if (attributes.indexConfig || optional) {
86
- return attributes.indexConfig;
78
+ key = `${owner}/${repo}/main/${INDEX_CONFIGURATION_NAME}`;
79
+ buffer = await storage.codeBus().get(key);
80
+ attributes.indexConfig = await handleResponse(log, buffer, key, 'code-bus');
81
+ if (attributes.indexConfig || optional) {
82
+ return attributes.indexConfig;
83
+ }
84
+ } catch (e) {
85
+ log[logLevelForStatusCode(e.status)](`Invalid response (${e.status}) when fetching index configuration: ${key}`);
86
+ const err = new Error(`Unable to fetch index configuration: ${e.status} ${e.message}`);
87
+ err.status = propagateStatusCode(e.status);
88
+ throw err;
87
89
  }
88
90
 
89
91
  const err = new Error(`no index configuration for ${owner}/${repo}/main`);
@@ -9,9 +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 { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
13
12
  import { SitemapConfig } from '@adobe/helix-shared-config';
14
- import { fetchS3 } from './fetch-s3.js';
13
+ import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
15
14
  import { getContentBusId } from './contentbus.js';
16
15
 
17
16
  /**
@@ -28,25 +27,14 @@ const SITEMAP_LOCATION = 'preview/.helix/sitemap.yaml';
28
27
  * @param {string} type type of storage (logging information
29
28
  * @returns {Promise<SitemapConfig>} the sitemap config or null
30
29
  */
31
- async function handleResponse(log, response, key, type) {
32
- const text = await response.text();
33
- if (response.ok) {
34
- const cfg = await new SitemapConfig().withSource(text).init();
35
- cfg.sourceType = type;
36
- return cfg;
37
- }
38
-
39
- if (response.status === 404) {
40
- log.info(`No helix-sitemap.yaml found in ${type} ${key}, ${text}`);
30
+ async function handleResponse(log, buffer, key, type) {
31
+ if (!buffer) {
32
+ log.info(`No helix-sitemap.yaml found in ${type} ${key}`);
41
33
  return null;
42
34
  }
43
-
44
- log[logLevelForStatusCode(response.status)](
45
- `Invalid response (${response.status}) when fetching sitemap configuration from ${type} ${key}`,
46
- );
47
- const err = new Error(`Unable to fetch sitemap configuration: ${response.status} ${text}`);
48
- err.status = propagateStatusCode(response.status);
49
- throw err;
35
+ const cfg = await new SitemapConfig().withSource(buffer.toString('utf-8')).init();
36
+ cfg.sourceType = type;
37
+ return cfg;
50
38
  }
51
39
 
52
40
  /**
@@ -68,19 +56,32 @@ export async function fetchSitemap(ctx, opts, optional) {
68
56
  if (!contentBusId) {
69
57
  return null;
70
58
  }
59
+ const { storage } = attributes;
60
+ if (!storage) {
61
+ throw Error('storage required to fetch sitemap.');
62
+ }
71
63
 
72
64
  let key = `${contentBusId}/${SITEMAP_LOCATION}`;
73
- let response = await fetchS3(ctx, 'content', key);
74
- attributes.sitemapConfig = await handleResponse(log, response, key, 'content-bus');
75
- if (attributes.sitemapConfig) {
76
- return attributes.sitemapConfig;
77
- }
65
+ try {
66
+ let buffer = await storage.contentBus().get(key);
67
+ attributes.sitemapConfig = await handleResponse(log, buffer, key, 'content-bus');
68
+ if (attributes.sitemapConfig) {
69
+ return attributes.sitemapConfig;
70
+ }
78
71
 
79
- key = `${owner}/${repo}/main/helix-sitemap.yaml`;
80
- response = await fetchS3(ctx, 'code', key);
81
- attributes.sitemapConfig = await handleResponse(log, response, key, 'code-bus');
82
- if (attributes.sitemapConfig || optional) {
83
- return attributes.sitemapConfig;
72
+ key = `${owner}/${repo}/main/helix-sitemap.yaml`;
73
+ buffer = await storage.codeBus().get(key);
74
+ attributes.sitemapConfig = await handleResponse(log, buffer, key, 'code-bus');
75
+ if (attributes.sitemapConfig || optional) {
76
+ return attributes.sitemapConfig;
77
+ }
78
+ } catch (e) {
79
+ log[logLevelForStatusCode(e.status)](
80
+ `Invalid response (${e.status}) when fetching sitemap configuration from ${key}`,
81
+ );
82
+ const err = new Error(`Unable to fetch sitemap configuration: ${e.status} ${e.message}`);
83
+ err.status = propagateStatusCode(e.status);
84
+ throw err;
84
85
  }
85
86
  const err = new Error(`no sitemap configuration for ${owner}/${repo}/main`);
86
87
  err.status = 404;
@@ -53,35 +53,39 @@
53
53
  * @param {string} [keyName = 'key'] name of the key column.
54
54
  * @param {string} [valueName = 'value'] name of the value column.
55
55
  */
56
+ function setProperty(o, key, value) {
57
+ Object.defineProperty(o, key, {
58
+ value,
59
+ writable: true,
60
+ enumerable: true,
61
+ configurable: true,
62
+ });
63
+ }
64
+
56
65
  export function flatJson2object(rows, keyName = 'key', valueName = 'value') {
57
66
  const arrays = [];
58
67
  const update = (o, segs, value) => {
59
68
  const seg = segs.shift();
60
69
  if (segs.length) {
61
- if (seg in o) {
70
+ if (Object.hasOwn(o, seg)) {
62
71
  update(o[seg], segs, value);
63
72
  return o;
64
73
  }
65
74
  const n = Number.parseInt(segs[0], 10);
66
- if (Number.isNaN(n)) {
67
- // eslint-disable-next-line no-param-reassign
68
- o[seg] = update(Object.create(null), segs, value);
69
- } else {
70
- // eslint-disable-next-line no-param-reassign
71
- o[seg] = update([], segs, value);
72
- arrays.push(o[seg]);
75
+ const child = Number.isNaN(n) ? Object.create(null) : [];
76
+ setProperty(o, seg, update(child, segs, value));
77
+ if (Array.isArray(child)) {
78
+ arrays.push(child);
73
79
  }
74
80
  return o;
75
81
  }
76
- if (!(seg in o)) {
77
- // eslint-disable-next-line no-param-reassign
78
- o[seg] = value;
82
+ if (!Object.hasOwn(o, seg)) {
83
+ setProperty(o, seg, value);
79
84
  } else if (Array.isArray(o[seg])) {
80
85
  // eslint-disable-next-line no-param-reassign
81
86
  o[seg].push(value);
82
87
  } else {
83
- // eslint-disable-next-line no-param-reassign
84
- o[seg] = [o[seg], value];
88
+ setProperty(o, seg, [o[seg], value]);
85
89
  }
86
90
  return o;
87
91
  };
package/src/index.d.ts CHANGED
@@ -21,15 +21,10 @@ declare interface IgnoreConfig { }
21
21
  declare interface IndexConfig { }
22
22
  declare interface SitemapConfig { }
23
23
 
24
- export * from './fetch-config-all';
25
- export * from './fetch-config';
26
24
  export * from './contentbus';
27
25
  export * from './fetch-crontab';
28
- export * from './fetch-fstab';
29
26
  export * from './fetch-ignore';
30
27
  export * from './fetch-index';
31
- export * from './fetch-helix-config';
32
- export * from './fetch-s3';
33
28
  export * from './fetch-sitemap';
34
29
  export * from './flatJson2Object';
35
30
  export * from './BatchedQueueClient';
@@ -177,6 +172,12 @@ export declare interface ContextAttributes {
177
172
  */
178
173
  contentBusId?: string;
179
174
 
175
+ /**
176
+ * storage client (e.g. from `@adobe/helix-shared-storage-s3`) exposing `contentBus()` and
177
+ * `codeBus()` accessors. Required by `fetchCrontab`, `fetchIndex`, and `fetchSitemap`.
178
+ */
179
+ storage?: object;
180
+
180
181
  /**
181
182
  * optional code bus id
182
183
  */
package/src/index.js CHANGED
@@ -11,13 +11,9 @@
11
11
  */
12
12
 
13
13
  export * from './contentbus.js';
14
- export * from './fetch-config.js';
15
- export * from './fetch-config-all.js';
16
14
  export * from './fetch-crontab.js';
17
- export * from './fetch-fstab.js';
18
15
  export * from './fetch-ignore.js';
19
16
  export * from './fetch-index.js';
20
- export * from './fetch-helix-config.js';
21
17
  export * from './fetch-s3.js';
22
18
  export * from './fetch-sitemap.js';
23
19
  export * from './flatJson2Object.js';
@@ -1,22 +0,0 @@
1
- /*
2
- * Copyright 2022 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
- import {AdminContext, PathInfo} from './index';
13
- import {ConfigAll} from "../types/project-config-all";
14
-
15
- /**
16
- * Retrieves the project config from the underlying storage
17
- * and stores it in the context as projectConfig.
18
- * @param {AdminContext} ctx the context
19
- * @param {PathInfo} info path info
20
- * @returns {Promise<ConfigAll>} the project configuration
21
- */
22
- export function fetchConfigAll(ctx: AdminContext, info:PathInfo): Promise<ConfigAll>;
@@ -1,73 +0,0 @@
1
- /*
2
- * Copyright 2021 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
- import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
13
- import { fetchS3 } from './fetch-s3.js';
14
- import { getContentBusId } from './contentbus.js';
15
-
16
- /**
17
- * Checks if the response is valid and returns the project config.
18
- *
19
- * @param {Console} log logger
20
- * @param {Response} response content response from the storage
21
- * @param {string} key storage key (logging information)
22
- * @param {string} type type of storage (logging information)
23
- * @returns {Promise<ConfigAll>} the helix project config or null
24
- */
25
- async function handleResponse(log, response, key, type) {
26
- const text = await response.text();
27
- if (response.ok) {
28
- try {
29
- return JSON.parse(text);
30
- // eslint-disable-next-line no-empty
31
- } catch { }
32
- log.info(`Empty or invalid /.helix/config-all.json found in ${type} ${key}`);
33
- return null;
34
- }
35
-
36
- if (response.status === 404) {
37
- log.info(`No /.helix/config-all.json found in ${type} ${key}, ${text}`);
38
- return null;
39
- }
40
-
41
- log[logLevelForStatusCode(response.status)](
42
- `Invalid response (${response.status}) when fetching config-all from ${type} ${key}`,
43
- );
44
- const err = new Error(`Unable to fetch config-all: ${response.status} ${text}`);
45
- err.status = propagateStatusCode(response.status);
46
- throw err;
47
- }
48
-
49
- /**
50
- * Retrieves the project config from the underlying storage
51
- * and stores it in the context as projectConfig.
52
- * @param {AdminContext} ctx the context
53
- * @param {PathInfo} opts lookup options
54
- * @returns {Promise<ConfigAll>} the project configuration
55
- */
56
- export async function fetchConfigAll(ctx, opts) {
57
- const { log, attributes } = ctx;
58
- const partition = opts.route === 'preview' || opts.route === 'live' ? opts.route : 'preview';
59
- const getConfig = async () => {
60
- const contentBusId = await getContentBusId(ctx, opts, true);
61
- if (!contentBusId) {
62
- return null;
63
- }
64
- const key = `${contentBusId}/${partition}/.helix/config-all.json`;
65
- const response = await fetchS3(ctx, 'content', key);
66
- return handleResponse(log, response, key, 'content-bus');
67
- };
68
-
69
- if (attributes.configAll === undefined) {
70
- attributes.configAll = await getConfig();
71
- }
72
- return attributes.configAll;
73
- }
@@ -1,22 +0,0 @@
1
- /*
2
- * Copyright 2022 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
- import { AdminContext, PathInfo } from './index';
13
- import { ProjectConfig } from "../types/project-config";
14
-
15
- /**
16
- * Retrieves the project config from the underlying storage
17
- * and stores it in the context as projectConfig.
18
- * @param {AdminContext} ctx the context
19
- * @param {PathInfo} info path info
20
- * @returns {Promise<object>} the project configuration
21
- */
22
- export function fetchProjectConfig(ctx:AdminContext, info:PathInfo): Promise<ProjectConfig>;
@@ -1,78 +0,0 @@
1
- /*
2
- * Copyright 2021 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
- import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
13
- import { fetchS3 } from './fetch-s3.js';
14
- import { getContentBusId } from './contentbus.js';
15
- import { flatJson2object } from './flatJson2Object.js';
16
-
17
- /**
18
- * Checks if the response is valid and returns the project config.
19
- *
20
- * @param {Console} log logger
21
- * @param {Response} response content response from the storage
22
- * @param {string} key storage key (logging information)
23
- * @param {string} type type of storage (logging information)
24
- * @returns {Promise<ProjectConfig>} the helix project config or null
25
- */
26
- async function handleResponse(log, response, key, type) {
27
- const text = await response.text();
28
- if (response.ok) {
29
- let props;
30
- try {
31
- const json = JSON.parse(text);
32
- props = json.data || json.default?.data;
33
- // eslint-disable-next-line no-empty
34
- } catch (ignore) { }
35
- if (!props) {
36
- log.info(`Empty or invalid .helix/config.json found in ${type} ${key}`);
37
- return null;
38
- }
39
- return flatJson2object(props);
40
- }
41
-
42
- if (response.status === 404) {
43
- log.info(`No .helix/config.json found in ${type} ${key}, ${text}`);
44
- return null;
45
- }
46
-
47
- log[logLevelForStatusCode(response.status)](
48
- `Invalid response (${response.status}) when fetching project configuration from ${type} ${key}`,
49
- );
50
- const err = new Error(`Unable to fetch project configuration: ${response.status} ${text}`);
51
- err.status = propagateStatusCode(response.status);
52
- throw err;
53
- }
54
-
55
- /**
56
- * Retrieves the project config from the underlying storage
57
- * and stores it in the context as projectConfig.
58
- * @param {AdminContext} ctx the context
59
- * @param {PathInfo} opts lookup options
60
- * @returns {Promise<ProjectConfig>} the project configuration
61
- */
62
- export async function fetchProjectConfig(ctx, opts) {
63
- const { log, attributes } = ctx;
64
- const getConfig = async () => {
65
- const contentBusId = await getContentBusId(ctx, opts, true);
66
- if (!contentBusId) {
67
- return null;
68
- }
69
- const key = `${contentBusId}/preview/.helix/config.json`;
70
- const response = await fetchS3(ctx, 'content', key);
71
- return handleResponse(log, response, key, 'content-bus');
72
- };
73
-
74
- if (attributes.projectConfig === undefined) {
75
- attributes.projectConfig = await getConfig();
76
- }
77
- return attributes.projectConfig;
78
- }
@@ -1,22 +0,0 @@
1
- /*
2
- * Copyright 2022 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
- import { MountConfig } from '@adobe/helix-shared-config';
13
- import { AdminContext, PathInfo } from './index';
14
-
15
- /**
16
- * Retrieves the fstab from the underlying storage and stores it in the context as mountConfig.
17
- * @param {AdminContext} ctx the context
18
- * @param {PathInfo} info path info
19
- * @param {boolean} optional if {@code true}, no error is thrown if the fstab can't be retrieved
20
- * @returns {Promise<MountConfig>} the fstab
21
- */
22
- export function fetchFstab(ctx:AdminContext, info:PathInfo, optional:boolean):Promise<MountConfig>;
@@ -1,76 +0,0 @@
1
- /*
2
- * Copyright 2021 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
- import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
13
- import { MountConfig } from '@adobe/helix-shared-config';
14
- import { fetchS3 } from './fetch-s3.js';
15
-
16
- /**
17
- * Checks if the response is valid and returns a mount config.
18
- *
19
- * @param {Logger} log logger
20
- * @param {Response} response content response from the storage
21
- * @param {string} key storage key (logging information)
22
- * @param {string} type type of storage (logging information)
23
- * @param {string} source source information
24
- * @returns {Promise<MountConfig>} the mount config or null
25
- */
26
- async function handleResponse(log, response, key, type, source = type) {
27
- const text = await response.text();
28
- if (response.ok) {
29
- const cfg = await new MountConfig().withSource(text).init();
30
- cfg.sourceType = type;
31
- return cfg;
32
- }
33
-
34
- if (response.status === 404) {
35
- log.info(`No fstab.yaml found in ${source} ${key}, ${text}`);
36
- return null;
37
- }
38
-
39
- log[logLevelForStatusCode(response.status)](`Invalid response (${response.status}) when fetching fstab from ${source} ${key}`);
40
- const err = new Error(`Unable to fetch fstab: ${response.status} ${text}`);
41
- err.status = propagateStatusCode(response.status);
42
- throw err;
43
- }
44
-
45
- /**
46
- * Retrieves the fstab from the underlying storage and stores it in the context as mountConfig.
47
- * @param {AdminContext} ctx the context
48
- * @param {LookupOptions} opts lookup options
49
- * @param {boolean} optional if {@code true}, no error is thrown if the fstab can't be retrieved
50
- * @returns {Promise<MountConfig>} the fstab
51
- */
52
- export async function fetchFstab(ctx, opts, optional) {
53
- const { log, attributes } = ctx;
54
- const loadFstab = async () => {
55
- const { owner, repo } = opts;
56
- if (!owner || !repo) {
57
- return null;
58
- }
59
-
60
- const key = `${owner}/${repo}/main/fstab.yaml`;
61
- const response = await fetchS3(ctx, 'code', key);
62
- return handleResponse(log, response, key, 'code-bus');
63
- };
64
-
65
- if (!('mountConfig' in attributes)) {
66
- attributes.mountConfig = await loadFstab(ctx, opts);
67
- }
68
-
69
- if (attributes.mountConfig || optional) {
70
- return attributes.mountConfig;
71
- }
72
-
73
- const err = new Error(`no fstab for ${opts.owner}/${opts.repo}/main/fstab.yaml`);
74
- err.status = 404;
75
- throw err;
76
- }
@@ -1,23 +0,0 @@
1
- /*
2
- * Copyright 2023 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
- import { AdminContext, PathInfo } from './index';
13
- import {HelixConfig} from "../types/helix-config";
14
-
15
- /**
16
- * Retrieves the helix-config.json which is an aggregate from fstab.yaml and head.html.
17
- *
18
- * @param {AdminContext} ctx the context
19
- * @param {PathInfo} info path info
20
- * @param {boolean} optional if {@code true} returns null if not found
21
- * @returns {Promise<HelixConfig>} the helix-config or {@code null} if optional and not found.
22
- */
23
- export function fetchHelixConfig(ctx, info, optional): Promise<HelixConfig>;
@@ -1,94 +0,0 @@
1
- /*
2
- * Copyright 2021 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
- import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
13
- import { MountConfig } from '@adobe/helix-shared-config';
14
- import { fetchS3 } from './fetch-s3.js';
15
-
16
- /**
17
- * Checks if the response is valid and returns the helix config.
18
- *
19
- * @param {Logger} log logger
20
- * @param {Response} response content response from the storage
21
- * @param {string} key storage key (logging information)
22
- * @param {string} type type of storage (logging information
23
- * @returns {Promise<HelixConfig>} the index config or null
24
- */
25
- async function handleResponse(log, response, key, type) {
26
- const text = await response.text();
27
- if (response.ok) {
28
- const config = JSON.parse(text);
29
- // create mountconfig of the fstab entry
30
- if (config.fstab?.data) {
31
- config.fstab.data = await new MountConfig()
32
- .withSource(JSON.stringify(config.fstab.data)).init();
33
- }
34
-
35
- // set contentbus id, if present in header
36
- const cbid = response.headers.get('x-contentbus-id');
37
- if (cbid && !config.content) {
38
- // create the content section if not already present
39
- config.content = {
40
- data: Object.create(null),
41
- };
42
- const content = config.content.data;
43
- const nvps = cbid.split(/;\s+/);
44
- for (const nv of nvps) {
45
- const [path, id] = nv.split('=');
46
- if (!content[path]) {
47
- content[path] = {};
48
- }
49
- content[path].contentBusId = id;
50
- }
51
- }
52
- return config;
53
- }
54
-
55
- if (response.status === 404) {
56
- return null;
57
- }
58
-
59
- log[logLevelForStatusCode(response.status)](`Invalid response (${response.status}) when fetching helix-config from ${type} ${key}`);
60
- const err = new Error(`Unable to fetch helix-config: ${response.status} ${text}`);
61
- err.status = propagateStatusCode(response.status);
62
- throw err;
63
- }
64
-
65
- /**
66
- * Retrieves the helix-config.json which is an aggregate from fstab.yaml and head.html.
67
- * Note: it always uses the branch `main`.
68
- *
69
- * @param {AdminContext} ctx the context
70
- * @param {PathInfo} info path info
71
- * @param {boolean} optional if {@code true} returns null if not found
72
- * @returns {Promise<HelixConfig>} the helix-config or {@code null} if optional and not found.
73
- */
74
- export async function fetchHelixConfig(ctx, info, optional) {
75
- const { attributes, log } = ctx;
76
- const { owner, repo } = info;
77
-
78
- if (!('helixConfig' in attributes)) {
79
- if (owner && repo) {
80
- const key = `${owner}/${repo}/main/helix-config.json`;
81
- const response = await fetchS3(ctx, 'code', key);
82
- attributes.helixConfig = await handleResponse(log, response, key, 'code-bus');
83
- } else {
84
- attributes.helixConfig = null;
85
- }
86
- }
87
-
88
- if (attributes.helixConfig || optional) {
89
- return attributes.helixConfig;
90
- }
91
- const err = Error(`no helix-config for ${owner}/${repo}`);
92
- err.status = 404;
93
- throw err;
94
- }