@adobe/helix-admin-support 1.1.37 → 1.2.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,24 @@
1
+ # [1.2.0](https://github.com/adobe/helix-admin-support/compare/v1.1.39...v1.2.0) (2022-08-11)
2
+
3
+
4
+ ### Features
5
+
6
+ * add fetch-config-all ([#57](https://github.com/adobe/helix-admin-support/issues/57)) ([cb5adef](https://github.com/adobe/helix-admin-support/commit/cb5adef3eb52448091ba27fed3f98950b31a2bca))
7
+
8
+ ## [1.1.39](https://github.com/adobe/helix-admin-support/compare/v1.1.38...v1.1.39) (2022-08-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update dependency @adobe/helix-fetch to v3.1.2 ([51146b8](https://github.com/adobe/helix-admin-support/commit/51146b89faf339afc84d4a8f6f4df502ce058bf5))
14
+
15
+ ## [1.1.38](https://github.com/adobe/helix-admin-support/compare/v1.1.37...v1.1.38) (2022-08-03)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **deps:** update external fixes ([#55](https://github.com/adobe/helix-admin-support/issues/55)) ([5c43e77](https://github.com/adobe/helix-admin-support/commit/5c43e779ecc6a4c36654641b345823954eff2710))
21
+
1
22
  ## [1.1.37](https://github.com/adobe/helix-admin-support/compare/v1.1.36...v1.1.37) (2022-07-23)
2
23
 
3
24
 
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@adobe/helix-admin-support",
3
- "version": "1.1.37",
3
+ "version": "1.2.0",
4
4
  "description": "Helix Admin Support Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "types": "src/index.d.ts",
8
8
  "scripts": {
9
9
  "test": "c8 mocha",
10
- "test-ci": "c8 mocha && codecov",
11
10
  "lint": "eslint .",
12
11
  "docs": "npx jsdoc2md -c .jsdoc.json --files 'src/*.js' > docs/API.md",
13
12
  "semantic-release": "semantic-release",
@@ -32,10 +31,10 @@
32
31
  "reporter-options": "configFile=.mocha-multi.json"
33
32
  },
34
33
  "dependencies": {
35
- "@adobe/helix-fetch": "3.1.1",
34
+ "@adobe/helix-fetch": "3.1.2",
36
35
  "@adobe/helix-shared-config": "8.2.0",
37
36
  "@adobe/helix-shared-utils": "2.0.11",
38
- "@aws-sdk/client-s3": "3.135.0"
37
+ "@aws-sdk/client-s3": "3.142.0"
39
38
  },
40
39
  "devDependencies": {
41
40
  "@adobe/eslint-config-helix": "1.3.2",
@@ -43,13 +42,12 @@
43
42
  "@semantic-release/git": "10.0.1",
44
43
  "@semantic-release/npm": "9.0.1",
45
44
  "c8": "7.12.0",
46
- "codecov": "3.8.3",
47
- "eslint": "8.20.0",
45
+ "eslint": "8.21.0",
48
46
  "eslint-plugin-header": "3.1.1",
49
47
  "eslint-plugin-import": "2.26.0",
50
48
  "husky": "8.0.1",
51
49
  "jsdoc-to-markdown": "7.1.1",
52
- "junit-report-builder": "3.0.0",
50
+ "junit-report-builder": "3.0.1",
53
51
  "lint-staged": "13.0.3",
54
52
  "mocha": "10.0.0",
55
53
  "mocha-multi-reporters": "1.5.1",
@@ -0,0 +1,53 @@
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, ModifierSheet, PathInfo} from './index';
13
+ import { ProjectConfig } from './fetch-config';
14
+
15
+
16
+ export declare interface ProjectConfigData {
17
+ data: ProjectConfig;
18
+ lastModified: string;
19
+ }
20
+
21
+ export declare interface ModifierSheetData {
22
+ data: ModifierSheet;
23
+ lastModified: string;
24
+ }
25
+
26
+ /**
27
+ * Combine config stored in /.helix/config-all.json
28
+ */
29
+ export declare interface ConfigAll {
30
+ /**
31
+ * Project config (from /.helix/config.json)
32
+ */
33
+ config?:ProjectConfigData;
34
+
35
+ /**
36
+ * Metadata (from /metadata.json)
37
+ */
38
+ metadata?:ModifierSheet;
39
+
40
+ /**
41
+ * Headers modifier (from /.helix/config.json)
42
+ */
43
+ headers?:ModifierSheet;
44
+ }
45
+
46
+ /**
47
+ * Retrieves the project config from the underlying storage
48
+ * and stores it in the context as projectConfig.
49
+ * @param {AdminContext} ctx the context
50
+ * @param {PathInfo} info path info
51
+ * @returns {Promise<object>} the project configuration
52
+ */
53
+ export function fetchConfigAll(ctx: AdminContext, info:PathInfo): Promise<ProjectConfig>;
@@ -0,0 +1,73 @@
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, 'helix-content-bus', 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
+ }
@@ -56,8 +56,8 @@ async function handleResponse(log, response, key, type) {
56
56
  * Retrieves the project config from the underlying storage
57
57
  * and stores it in the context as projectConfig.
58
58
  * @param {AdminContext} ctx the context
59
- * @param {LookupOptions} opts lookup options
60
- * @returns {Promise<object>} the project configuration
59
+ * @param {PathInfo} opts lookup options
60
+ * @returns {Promise<ProjectConfig>} the project configuration
61
61
  */
62
62
  export async function fetchProjectConfig(ctx, opts) {
63
63
  const { log, attributes } = ctx;
package/src/index.d.ts CHANGED
@@ -12,6 +12,7 @@
12
12
  import { OneDrive } from '@adobe/helix-onedrive-support';
13
13
  import { UniversalContext } from '@adobe/helix-universal';
14
14
  import { ProjectConfig } from './fetch-config';
15
+ import { ConfigAll } from "./fetch-config-all";
15
16
 
16
17
  declare interface AuthInfo {}
17
18
  declare interface MountConfig {}
@@ -20,6 +21,7 @@ declare interface IndexConfig {}
20
21
  declare interface SitemapConfig {}
21
22
 
22
23
  export { fetchProjectConfig } from './fetch-config';
24
+ export { fetchConfigAll } from './fetch-config-all';
23
25
  export { getContentBusId } from './contentbus';
24
26
  export { fetchCrontab } from './fetch-crontab';
25
27
  export { fetchFstab } from './fetch-fstab';
@@ -197,6 +199,11 @@ export declare interface ContextAttributes {
197
199
  * Notifier
198
200
  */
199
201
  notifier?:object;
202
+
203
+ /**
204
+ * combined config
205
+ */
206
+ configAll?:ConfigAll;
200
207
  }
201
208
 
202
209
  export declare interface AdminContext extends UniversalContext {
@@ -216,3 +223,37 @@ export declare interface AdminContext extends UniversalContext {
216
223
  */
217
224
  data?:object;
218
225
  }
226
+
227
+ /**
228
+ * Structure that groups name value pairs by url, used as modifier sheet, for example
229
+ * in metadata.json or headers.json
230
+ *
231
+ * @example
232
+ *
233
+ * | url | key | value | Title | Description |
234
+ * |-------|-----|-------|---------|----------------|
235
+ * | "/*" | "A" | "B" | "" | "" |
236
+ * | "/*" | "C" | "D" | "" | "" |
237
+ * | "/f" | "" | "" | "Hero" | "Once upon..." |
238
+ *
239
+ * becomes:
240
+ *
241
+ * {
242
+ * "/*": [
243
+ * { "key": "A", "value": "B" },
244
+ * { "key": "C", "value": "D" },
245
+ * ],
246
+ * "/f": [
247
+ * { "key": "title", "value": "Hero" },
248
+ * { "key": "description", "value": "Once upon..." },
249
+ * ]
250
+ * }
251
+ */
252
+ export declare interface ModifierSheet {
253
+ [ModifierUrl:string]: Modifier[];
254
+ }
255
+
256
+ export declare interface Modifier {
257
+ key: string;
258
+ value: string;
259
+ }
package/src/index.js CHANGED
@@ -12,6 +12,7 @@
12
12
 
13
13
  export * from './contentbus.js';
14
14
  export * from './fetch-config.js';
15
+ export * from './fetch-config-all.js';
15
16
  export * from './fetch-crontab.js';
16
17
  export * from './fetch-fstab.js';
17
18
  export * from './fetch-ignore.js';