@adobe/helix-admin-support 2.5.2 → 2.6.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,17 @@
1
+ ## [2.6.1](https://github.com/adobe/helix-admin-support/compare/v2.6.0...v2.6.1) (2024-03-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update external fixes ([a785dc5](https://github.com/adobe/helix-admin-support/commit/a785dc512955887673213c9b54340ce14993c8e0))
7
+
8
+ # [2.6.0](https://github.com/adobe/helix-admin-support/compare/v2.5.2...v2.6.0) (2024-03-21)
9
+
10
+
11
+ ### Features
12
+
13
+ * add feature flags util ([fb84527](https://github.com/adobe/helix-admin-support/commit/fb84527ae20f3ec2eb789bba53952213fe45f793))
14
+
1
15
  ## [2.5.2](https://github.com/adobe/helix-admin-support/compare/v2.5.1...v2.5.2) (2024-03-16)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-admin-support",
3
- "version": "2.5.2",
3
+ "version": "2.6.1",
4
4
  "description": "Helix Admin Support Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -37,16 +37,16 @@
37
37
  "@adobe/fetch": "4.1.1",
38
38
  "@adobe/helix-shared-config": "10.4.0",
39
39
  "@adobe/helix-shared-utils": "3.0.1",
40
- "@aws-sdk/client-s3": "3.535.0",
41
- "@aws-sdk/client-sqs": "3.535.0",
42
- "@aws-sdk/node-http-handler": "3.370.0"
40
+ "@aws-sdk/client-s3": "3.540.0",
41
+ "@aws-sdk/client-sqs": "3.540.0",
42
+ "@aws-sdk/node-http-handler": "3.374.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@adobe/eslint-config-helix": "2.0.6",
46
46
  "@adobe/jsonschema2md": "7.1.5",
47
47
  "@semantic-release/changelog": "6.0.3",
48
48
  "@semantic-release/git": "10.0.1",
49
- "@semantic-release/npm": "11.0.3",
49
+ "@semantic-release/npm": "12.0.0",
50
50
  "c8": "9.1.0",
51
51
  "eslint": "8.57.0",
52
52
  "husky": "9.0.11",
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright 2024 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
+ import { AdminContext, PathInfo } from './index';
14
+
15
+ /**
16
+ * Retrieves feature flags for the specified project.
17
+ * @param {AdminContext} ctx the context
18
+ * @param {Pick<PathInfo, 'owner' | 'repo'>} info partial path info
19
+ * @returns {Promise<Record<string, boolean>>} map of { feature name => enabled? }
20
+ */
21
+ export function fetchFeatureFlags(ctx: AdminContext, info: Pick<PathInfo, 'owner' | 'repo'>): Promise<Record<string, boolean>>;
@@ -0,0 +1,91 @@
1
+ /*
2
+ * Copyright 2024 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
+ import { logLevelForStatusCode, propagateStatusCode } from '@adobe/helix-shared-utils';
14
+ import { fetchS3 } from './fetch-s3.js';
15
+
16
+ /**
17
+ * Checks if the response is valid and returns the feature flags.
18
+ *
19
+ * @param {Console} log logger
20
+ * @param {Response} response response from the storage
21
+ * @param {string} key storage key (logging information)
22
+ * @param {string} type type of storage (logging information)
23
+ * @returns {Promise<Record<string, boolean>>}
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 feature flags found in ${type} ${key}`);
33
+ return {};
34
+ }
35
+
36
+ if (response.status === 404) {
37
+ return {};
38
+ }
39
+
40
+ log[logLevelForStatusCode(response.status)](
41
+ `Invalid response (${response.status}) when fetching feature flags from ${type} ${key}`,
42
+ );
43
+ const err = new Error(`Unable to fetch feature flags: ${response.status} ${text}`);
44
+ err.status = propagateStatusCode(response.status);
45
+ throw err;
46
+ }
47
+
48
+ /**
49
+ * Retrieves feature flags for the specified project.
50
+ * @param ctx
51
+ * @param info
52
+ * @returns {Promise<Record<string, boolean>>} map of { feature name => enabled? }
53
+ */
54
+ export async function fetchFeatureFlags(ctx, info) {
55
+ const { log, attributes } = ctx;
56
+ const { repo, owner } = info;
57
+
58
+ if (!attributes.featureFlags) {
59
+ attributes.featureFlags = {};
60
+ }
61
+
62
+ /**
63
+ * each flag file is a simple { [feature: string]: boolean } format
64
+ * repo-level flags override org-level flags
65
+ * @param {Record<string, boolean>} repoData
66
+ * @param {Record<string, boolean>} orgData
67
+ * @returns {Record<string, boolean>}
68
+ */
69
+ const flattenFlags = (repoData, orgData) => ({
70
+ ...orgData,
71
+ ...repoData,
72
+ });
73
+
74
+ /**
75
+ * @param {string} file
76
+ */
77
+ const getFlags = async (file) => {
78
+ if (!attributes.featureFlags[file]) {
79
+ const key = `adobe/helix-admin-website/main/tools/hidden-features/${file}.json`;
80
+ const response = await fetchS3(ctx, 'helix-code-bus', key);
81
+ attributes.featureFlags[file] = await handleResponse(log, response, key, 'code-bus');
82
+ }
83
+ return attributes.featureFlags[file];
84
+ };
85
+
86
+ const [orgData, repoData] = await Promise.all([
87
+ getFlags(`${owner}--all`),
88
+ getFlags(`${owner}--${repo}`),
89
+ ]);
90
+ return flattenFlags(repoData, orgData);
91
+ }
package/src/index.d.ts CHANGED
@@ -13,13 +13,13 @@ import { OneDrive } from '@adobe/helix-onedrive-support';
13
13
  import { UniversalContext } from '@adobe/helix-universal';
14
14
  import { ProjectConfig } from '../types/project-config';
15
15
  import { ConfigAll } from "../types/project-config-all";
16
- import {HelixConfig} from "../types/helix-config";
16
+ import { HelixConfig } from "../types/helix-config";
17
17
 
18
- declare interface AuthInfo {}
19
- declare interface MountConfig {}
20
- declare interface IgnoreConfig {}
21
- declare interface IndexConfig {}
22
- declare interface SitemapConfig {}
18
+ declare interface AuthInfo { }
19
+ declare interface MountConfig { }
20
+ declare interface IgnoreConfig { }
21
+ declare interface IndexConfig { }
22
+ declare interface SitemapConfig { }
23
23
 
24
24
  export * from './fetch-config-all';
25
25
  export * from './fetch-config';
@@ -31,6 +31,7 @@ export * from './fetch-index';
31
31
  export * from './fetch-helix-config';
32
32
  export * from './fetch-s3';
33
33
  export * from './fetch-sitemap';
34
+ export * from './fetch-feature-flags';
34
35
  export * from './flatJson2Object';
35
36
  export * from './BatchedQueueClient';
36
37
  export * from '../types/helix-config';
@@ -41,12 +42,12 @@ export declare interface ErrorResponse {
41
42
  /**
42
43
  * http like status code
43
44
  */
44
- status:number;
45
+ status: number;
45
46
 
46
47
  /**
47
48
  * error message
48
49
  */
49
- error:string;
50
+ error: string;
50
51
  }
51
52
 
52
53
  /**
@@ -56,44 +57,44 @@ export declare interface PathInfo {
56
57
  /**
57
58
  * Original path
58
59
  */
59
- rawPath:string,
60
+ rawPath: string,
60
61
 
61
62
  /**
62
63
  * API route
63
64
  */
64
- route:string;
65
+ route: string;
65
66
 
66
67
  /**
67
68
  * Repository owner (lowercase)
68
69
  */
69
- owner:string;
70
+ owner: string;
70
71
 
71
72
  /**
72
73
  * Repository name (lowercase)
73
74
  */
74
- repo:string;
75
+ repo: string;
75
76
 
76
77
  /**
77
78
  * Repository ref (lowercase)
78
79
  */
79
- ref:string;
80
+ ref: string;
80
81
 
81
82
  /**
82
83
  * Repository ref (case)
83
84
  */
84
- branch:string;
85
+ branch: string;
85
86
 
86
87
  /**
87
88
  * Resource path
88
89
  * @example '/express/index.md'
89
90
  * @example '/en/query-index.json'
90
91
  */
91
- resourcePath:string;
92
+ resourcePath: string;
92
93
 
93
94
  /**
94
95
  * Resource path extension
95
96
  */
96
- ext:string;
97
+ ext: string;
97
98
 
98
99
  /**
99
100
  * Web path
@@ -101,52 +102,52 @@ export declare interface PathInfo {
101
102
  * @example '/blogs/may-21'
102
103
  * @example '/en/query-index.json'
103
104
  */
104
- path:string;
105
+ path: string;
105
106
 
106
107
  /**
107
108
  * The precomputed live url
108
109
  */
109
- liveUrl:string;
110
+ liveUrl: string;
110
111
 
111
112
  /**
112
113
  * The precomputed preview url
113
114
  */
114
- previewUrl:string;
115
+ previewUrl: string;
115
116
 
116
117
  /**
117
118
  * request scheme
118
119
  */
119
- scheme:string;
120
+ scheme: string;
120
121
 
121
122
  /**
122
123
  * request host
123
124
  */
124
- host:string;
125
+ host: string;
125
126
 
126
127
  /**
127
128
  * request method
128
129
  */
129
- method:string;
130
+ method: string;
130
131
 
131
132
  /**
132
133
  * request parameters relevant for creating external links, eg. version-lock
133
134
  */
134
- query:object;
135
+ query: object;
135
136
 
136
137
  /**
137
138
  * function path (aka servletPath)
138
139
  */
139
- functionPath:string;
140
+ functionPath: string;
140
141
 
141
142
  /**
142
143
  * request headers
143
144
  */
144
- headers:object;
145
+ headers: object;
145
146
 
146
147
  /**
147
148
  * request cookies
148
149
  */
149
- cookies?:object;
150
+ cookies?: object;
150
151
  }
151
152
 
152
153
  export declare interface ContextAttributes {
@@ -154,67 +155,67 @@ export declare interface ContextAttributes {
154
155
  /**
155
156
  * optional mount config, once fetched
156
157
  */
157
- mountConfig?:MountConfig;
158
+ mountConfig?: MountConfig;
158
159
 
159
160
  /**
160
161
  * optional ignore config, once fetched
161
162
  */
162
- ignoreConfig?:IgnoreConfig;
163
+ ignoreConfig?: IgnoreConfig;
163
164
 
164
165
  /**
165
166
  * optional index config, once fetched
166
167
  */
167
- indexConfig?:IndexConfig;
168
+ indexConfig?: IndexConfig;
168
169
 
169
170
  /**
170
171
  * optional sitemap config, once fetched
171
172
  */
172
- sitemapConfig?:SitemapConfig;
173
+ sitemapConfig?: SitemapConfig;
173
174
 
174
175
  /**
175
176
  * optional content bus id from the `x-helix-contentbus-id` header or computed from fstab.
176
177
  */
177
- contentBusId?:string;
178
+ contentBusId?: string;
178
179
 
179
180
  /**
180
181
  * optional code bus id
181
182
  */
182
- codeBusId?:string;
183
+ codeBusId?: string;
183
184
 
184
185
  /**
185
186
  * Authentication information
186
187
  */
187
- authInfo:AuthInfo;
188
+ authInfo: AuthInfo;
188
189
 
189
190
  /**
190
191
  * optional project config
191
192
  */
192
- projectConfig?:ProjectConfig;
193
+ projectConfig?: ProjectConfig;
193
194
 
194
195
  /**
195
196
  * optional redirects information
196
197
  */
197
- redirects?:object;
198
+ redirects?: object;
198
199
 
199
200
  /**
200
201
  * onedrive client
201
202
  */
202
- onedrive?:OneDrive;
203
+ onedrive?: OneDrive;
203
204
 
204
205
  /**
205
206
  * Notifier
206
207
  */
207
- notifier?:object;
208
+ notifier?: object;
208
209
 
209
210
  /**
210
211
  * combined config (content)
211
212
  */
212
- configAll?:ConfigAll;
213
+ configAll?: ConfigAll;
213
214
 
214
215
  /**
215
216
  * combined helix-config (code)
216
217
  */
217
- helixConfig?:HelixConfig;
218
+ helixConfig?: HelixConfig;
218
219
  }
219
220
 
220
221
  export declare interface AdminContext extends UniversalContext {
@@ -222,16 +223,16 @@ export declare interface AdminContext extends UniversalContext {
222
223
  /**
223
224
  * optional github token extracted from the `x-github-token` header
224
225
  */
225
- githubToken?:string;
226
+ githubToken?: string;
226
227
 
227
228
  /**
228
229
  * Additional context attributes
229
230
  */
230
- attributes:ContextAttributes;
231
+ attributes: ContextAttributes;
231
232
 
232
233
  /**
233
234
  * context data provided via helix-shared-body
234
235
  */
235
- data?:object;
236
+ data?: object;
236
237
  }
237
238
 
package/src/index.js CHANGED
@@ -20,5 +20,6 @@ export * from './fetch-index.js';
20
20
  export * from './fetch-helix-config.js';
21
21
  export * from './fetch-s3.js';
22
22
  export * from './fetch-sitemap.js';
23
+ export * from './fetch-feature-flags.js';
23
24
  export * from './flatJson2Object.js';
24
25
  export * from './BatchedQueueClient.js';