@adobe/helix-config-storage 1.4.0 → 1.6.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 +14 -0
- package/package.json +1 -1
- package/src/config-store.js +14 -1
- package/src/transient-token-store.js +40 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [1.6.0](https://github.com/adobe/helix-config-storage/compare/v1.5.0...v1.6.0) (2024-09-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* allow modify access.admin.roles ([#17](https://github.com/adobe/helix-config-storage/issues/17)) ([20de603](https://github.com/adobe/helix-config-storage/commit/20de603828b9fdb582ae813e978abbe9bb407fad))
|
|
7
|
+
|
|
8
|
+
# [1.5.0](https://github.com/adobe/helix-config-storage/compare/v1.4.0...v1.5.0) (2024-09-02)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* restructure transient-site-tokens ([#15](https://github.com/adobe/helix-config-storage/issues/15)) ([bec495c](https://github.com/adobe/helix-config-storage/commit/bec495cf3b594d38f0f2586fc3addba457be684f))
|
|
14
|
+
|
|
1
15
|
# [1.4.0](https://github.com/adobe/helix-config-storage/compare/v1.3.2...v1.4.0) (2024-08-31)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/config-store.js
CHANGED
|
@@ -39,7 +39,20 @@ const FRAGMENTS_COMMON = {
|
|
|
39
39
|
access: {
|
|
40
40
|
'.': 'object',
|
|
41
41
|
site: 'object',
|
|
42
|
-
admin:
|
|
42
|
+
admin: {
|
|
43
|
+
'.': 'object',
|
|
44
|
+
role: {
|
|
45
|
+
'.': 'object',
|
|
46
|
+
admin: 'object',
|
|
47
|
+
author: 'object',
|
|
48
|
+
publish: 'object',
|
|
49
|
+
develop: 'object',
|
|
50
|
+
basic_author: 'object',
|
|
51
|
+
basic_publish: 'object',
|
|
52
|
+
config: 'object',
|
|
53
|
+
config_admin: 'object',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
43
56
|
preview: 'object',
|
|
44
57
|
live: 'object',
|
|
45
58
|
},
|
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
* @typedef Token
|
|
15
15
|
* @property {string} id
|
|
16
16
|
* @property {string} value
|
|
17
|
-
* @property {string} hash
|
|
18
17
|
* @property {Date} created
|
|
19
|
-
* @property {Date} expires
|
|
20
18
|
*/
|
|
21
19
|
|
|
22
20
|
/**
|
|
@@ -25,20 +23,8 @@
|
|
|
25
23
|
* @property {Token} live
|
|
26
24
|
*/
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
* @typedef SiteTokensData
|
|
30
|
-
* @property {Token[]} preview
|
|
31
|
-
* @property {Token[]} live
|
|
32
|
-
*/
|
|
33
|
-
|
|
26
|
+
import crypto from 'crypto';
|
|
34
27
|
import { HelixStorage } from '@adobe/helix-shared-storage';
|
|
35
|
-
import { createToken } from './utils.js';
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Default expiry time for transient site tokens (24 hours)
|
|
39
|
-
* @type {number}
|
|
40
|
-
*/
|
|
41
|
-
const DEFAULT_EXPIRY_TIME = 24 * 60 * 60 * 1000;
|
|
42
28
|
|
|
43
29
|
/**
|
|
44
30
|
* Store to manage transient site tokens.
|
|
@@ -80,12 +66,12 @@ export class TransientTokenStore {
|
|
|
80
66
|
this.org = org;
|
|
81
67
|
this.site = site;
|
|
82
68
|
this.#key = `orgs/${this.org}/sites/${this.site}/transient-site-tokens.json`;
|
|
83
|
-
this.#now = Date
|
|
69
|
+
this.#now = new Date();
|
|
84
70
|
}
|
|
85
71
|
|
|
86
72
|
/**
|
|
87
73
|
* Returns the current time (mainly used for tests)
|
|
88
|
-
* @returns {
|
|
74
|
+
* @returns {Date}
|
|
89
75
|
*/
|
|
90
76
|
now() {
|
|
91
77
|
return this.#now;
|
|
@@ -94,22 +80,21 @@ export class TransientTokenStore {
|
|
|
94
80
|
/**
|
|
95
81
|
* Loads the transient site tokens from the storage
|
|
96
82
|
* @param ctx
|
|
97
|
-
* @returns {Promise<
|
|
83
|
+
* @returns {Promise<SiteTokens>}
|
|
98
84
|
*/
|
|
99
85
|
async #load(ctx) {
|
|
100
86
|
if (!this.#tokens) {
|
|
101
87
|
this.#tokens = {
|
|
102
|
-
preview:
|
|
103
|
-
live:
|
|
88
|
+
preview: undefined,
|
|
89
|
+
live: undefined,
|
|
104
90
|
};
|
|
105
91
|
this.#modified = false;
|
|
106
92
|
const storage = HelixStorage.fromContext(ctx).configBus();
|
|
107
93
|
const buf = await storage.get(this.#key);
|
|
108
94
|
if (buf) {
|
|
109
95
|
const data = JSON.parse(buf.toString('utf-8'));
|
|
110
|
-
|
|
111
|
-
this.#tokens.
|
|
112
|
-
this.#tokens.live = data.tokens.live.filter(isValid);
|
|
96
|
+
this.#tokens.preview = data.tokens.preview;
|
|
97
|
+
this.#tokens.live = data.tokens.live;
|
|
113
98
|
}
|
|
114
99
|
}
|
|
115
100
|
return this.#tokens;
|
|
@@ -140,12 +125,17 @@ export class TransientTokenStore {
|
|
|
140
125
|
throw new Error(`Invalid partition: ${partition}`);
|
|
141
126
|
}
|
|
142
127
|
const tokens = await this.#load(ctx);
|
|
143
|
-
let token = tokens[partition]
|
|
128
|
+
let token = tokens[partition];
|
|
144
129
|
if (!token) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
const value = crypto.randomBytes(32).toString('base64url');
|
|
131
|
+
const id = crypto.createHash('sha256').update(value).digest().toString('base64url');
|
|
132
|
+
const created = this.#now.toUTCString();
|
|
133
|
+
token = {
|
|
134
|
+
id,
|
|
135
|
+
value,
|
|
136
|
+
created,
|
|
137
|
+
};
|
|
138
|
+
tokens[partition] = token;
|
|
149
139
|
this.#modified = true;
|
|
150
140
|
}
|
|
151
141
|
await this.#save(ctx);
|
|
@@ -153,15 +143,31 @@ export class TransientTokenStore {
|
|
|
153
143
|
}
|
|
154
144
|
|
|
155
145
|
/**
|
|
156
|
-
* Returns the
|
|
146
|
+
* Returns the token header values for the given user id.
|
|
147
|
+
* @param ctx
|
|
148
|
+
* @param partition
|
|
149
|
+
* @param userid
|
|
150
|
+
* @returns {Promise<string>}
|
|
151
|
+
*/
|
|
152
|
+
async getTokenHeader(ctx, partition, userid) {
|
|
153
|
+
const token = await this.getOrCreateToken(ctx, partition);
|
|
154
|
+
const user64 = Buffer.from(userid)
|
|
155
|
+
.toString('base64url');
|
|
156
|
+
const key = `${user64};${this.#now.toISOString().split('T')[0]}`;
|
|
157
|
+
const hash = crypto
|
|
158
|
+
.createHmac('sha512', key)
|
|
159
|
+
.update(token.value, 'utf-8')
|
|
160
|
+
.digest()
|
|
161
|
+
.toString('base64url');
|
|
162
|
+
return `hlxtst_${hash};${user64}`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Returns the transient site tokens
|
|
157
167
|
* @param ctx
|
|
158
168
|
* @returns {Promise<SiteTokens>}
|
|
159
169
|
*/
|
|
160
170
|
async getSiteTokens(ctx) {
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
preview: tokens.preview[0],
|
|
164
|
-
live: tokens.live[0],
|
|
165
|
-
};
|
|
171
|
+
return this.#load(ctx);
|
|
166
172
|
}
|
|
167
173
|
}
|