@adobe/helix-config 2.4.0 → 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 +7 -0
- package/package.json +1 -1
- package/src/storage/config-store.js +3 -2
- package/src/storage/utils.js +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
# [2.4.0](https://github.com/adobe/helix-config/compare/v2.3.4...v2.4.0) (2024-04-15)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -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: {
|
|
@@ -65,6 +65,7 @@ export class ConfigStore {
|
|
|
65
65
|
if (await storage.head(this.key)) {
|
|
66
66
|
throw new StatusCodeError(409, 'config already exists.');
|
|
67
67
|
}
|
|
68
|
+
updateContentBusId(ctx, data);
|
|
68
69
|
await storage.put(this.key, JSON.stringify(data), 'application/json');
|
|
69
70
|
await this.purge(ctx, null, data);
|
|
70
71
|
}
|
|
@@ -101,7 +102,7 @@ export class ConfigStore {
|
|
|
101
102
|
// eslint-disable-next-line no-param-reassign
|
|
102
103
|
data = jsonPut(JSON.parse(buf), relPath, data);
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
updateContentBusId(ctx, data);
|
|
105
106
|
await storage.put(this.key, JSON.stringify(data), 'application/json');
|
|
106
107
|
await this.purge(ctx, old, data);
|
|
107
108
|
}
|
package/src/storage/utils.js
CHANGED
|
@@ -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
|
+
}
|