@byline/admin 4.19.0 → 5.1.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/dist/fields/field-services-context.d.ts +1 -1
- package/dist/fields/field-services-types.d.ts +5 -2
- package/dist/forms/available-locales-widget.d.ts +3 -2
- package/dist/forms/available-locales-widget.js +4 -2
- package/dist/forms/document-actions.d.ts +3 -2
- package/dist/forms/document-actions.js +32 -14
- package/dist/forms/form-renderer.d.ts +12 -3
- package/dist/forms/form-renderer.js +98 -8
- package/dist/forms/form-renderer.module.js +1 -0
- package/dist/forms/form-renderer_module.css +12 -0
- package/dist/forms/form-status-display.d.ts +3 -2
- package/dist/forms/form-status-display.js +5 -2
- package/dist/forms/path-widget.d.ts +2 -1
- package/dist/forms/path-widget.js +7 -2
- package/dist/forms/scheduled-publication-control.d.ts +2 -1
- package/dist/forms/scheduled-publication-control.js +12 -8
- package/dist/forms/tree-placement-widget.d.ts +5 -1
- package/dist/forms/tree-placement-widget.js +14 -7
- package/dist/forms/upload-executor.d.ts +2 -2
- package/dist/modules/admin-account/components/change-password.js +18 -0
- package/dist/modules/admin-account/service.d.ts +2 -6
- package/dist/modules/admin-account/service.js +2 -1
- package/dist/modules/admin-users/repository.d.ts +10 -1
- package/dist/modules/auth/index.d.ts +3 -1
- package/dist/modules/auth/index.js +1 -0
- package/dist/modules/auth/jwt-session-provider.d.ts +8 -2
- package/dist/modules/auth/jwt-session-provider.js +222 -70
- package/dist/modules/auth/login-sessions-repository.d.ts +23 -0
- package/dist/modules/auth/login-sessions-repository.js +1 -0
- package/dist/modules/auth/refresh-tokens-repository.d.ts +12 -9
- package/dist/modules/auth/resolve-actor.d.ts +3 -0
- package/dist/modules/auth/resolve-actor.js +5 -2
- package/dist/modules/auth/sign-in-rate-limiter.d.ts +48 -0
- package/dist/modules/auth/sign-in-rate-limiter.js +229 -0
- package/dist/store.d.ts +15 -2
- package/package.json +17 -17
- package/src/fields/field-services-types.ts +10 -2
- package/src/forms/available-locales-widget.tsx +5 -2
- package/src/forms/document-actions.tsx +55 -20
- package/src/forms/form-renderer-submit.test.tsx +131 -2
- package/src/forms/form-renderer.module.css +20 -0
- package/src/forms/form-renderer.tsx +122 -7
- package/src/forms/form-status-display.tsx +6 -1
- package/src/forms/path-widget.tsx +8 -3
- package/src/forms/scheduled-publication-control.tsx +16 -7
- package/src/forms/tree-placement-widget.tsx +34 -7
- package/src/modules/admin-account/components/change-password.test.tsx +72 -0
- package/src/modules/admin-account/components/change-password.tsx +15 -4
- package/src/modules/admin-account/service.ts +8 -7
- package/src/modules/admin-users/repository.ts +10 -1
- package/src/modules/auth/index.ts +13 -1
- package/src/modules/auth/jwt-session-provider.ts +276 -91
- package/src/modules/auth/login-sessions-repository.ts +25 -0
- package/src/modules/auth/refresh-tokens-repository.ts +12 -9
- package/src/modules/auth/resolve-actor.ts +10 -1
- package/src/modules/auth/sign-in-rate-limiter.ts +240 -0
- package/src/store.ts +22 -2
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { createHmac } from "node:crypto";
|
|
2
|
+
import { isIP } from "node:net";
|
|
3
|
+
const DEFAULT_POLICY = {
|
|
4
|
+
account: {
|
|
5
|
+
limit: 10,
|
|
6
|
+
windowSeconds: 900
|
|
7
|
+
},
|
|
8
|
+
ip: {
|
|
9
|
+
limit: 60,
|
|
10
|
+
windowSeconds: 60
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const CLEANUP_TASK_NAME = 'auth.sign-in-counters.cleanup';
|
|
14
|
+
function signInNetwork(ip) {
|
|
15
|
+
const version = isIP(ip);
|
|
16
|
+
if (4 === version) return ip;
|
|
17
|
+
if (6 !== version || ip.includes('%')) throw new Error('Invalid client address');
|
|
18
|
+
const canonical = new URL(`http://[${ip}]/`).hostname.slice(1, -1);
|
|
19
|
+
const mapped = /^::ffff:([0-9a-f]+):([0-9a-f]+)$/.exec(canonical);
|
|
20
|
+
if (mapped) {
|
|
21
|
+
const high = Number.parseInt(mapped[1], 16);
|
|
22
|
+
const low = Number.parseInt(mapped[2], 16);
|
|
23
|
+
return [
|
|
24
|
+
high >>> 8,
|
|
25
|
+
255 & high,
|
|
26
|
+
low >>> 8,
|
|
27
|
+
255 & low
|
|
28
|
+
].join('.');
|
|
29
|
+
}
|
|
30
|
+
const [left, right] = canonical.split('::');
|
|
31
|
+
const head = left ? left.split(':') : [];
|
|
32
|
+
const tail = right ? right.split(':') : [];
|
|
33
|
+
const words = void 0 === right ? head : [
|
|
34
|
+
...head,
|
|
35
|
+
...Array(8 - head.length - tail.length).fill('0'),
|
|
36
|
+
...tail
|
|
37
|
+
];
|
|
38
|
+
return `${words.slice(0, 4).join(':')}::/64`;
|
|
39
|
+
}
|
|
40
|
+
function createPasswordSignInLimiter(store, secret, policy = DEFAULT_POLICY, now = Date.now, options = {}) {
|
|
41
|
+
const secretBytes = 'string' == typeof secret ? new TextEncoder().encode(secret) : secret;
|
|
42
|
+
if (secretBytes.byteLength < 32) throw new Error('Sign-in HMAC secret must contain at least 32 bytes');
|
|
43
|
+
const key = createHmac('sha256', secretBytes).update('byline:password-sign-in:v1').digest();
|
|
44
|
+
const digest = (value)=>createHmac('sha256', key).update(JSON.stringify(value)).digest('hex');
|
|
45
|
+
const rules = structuredClone(policy);
|
|
46
|
+
for (const rule of Object.values(rules))if (!Number.isSafeInteger(rule.limit) || rule.limit < 1 || rule.limit > 1000000 || !Number.isSafeInteger(rule.windowSeconds) || rule.windowSeconds < 1 || rule.windowSeconds > 86400) throw new Error('Invalid password sign-in rate limit policy');
|
|
47
|
+
const slots = options.slots ?? 1;
|
|
48
|
+
const maxQueue = options.maxQueue ?? 4;
|
|
49
|
+
const queueTimeoutMs = options.queueTimeoutMs ?? 250;
|
|
50
|
+
const minimumSlotMs = options.minimumSlotMs ?? 100;
|
|
51
|
+
for (const value of [
|
|
52
|
+
slots,
|
|
53
|
+
queueTimeoutMs,
|
|
54
|
+
minimumSlotMs
|
|
55
|
+
])if (!Number.isSafeInteger(value) || value < 1 || value > 60000) throw new Error('Invalid sign-in capacity policy');
|
|
56
|
+
if (!Number.isSafeInteger(maxQueue) || maxQueue < 0 || maxQueue > 1000) throw new Error('Invalid sign-in queue size');
|
|
57
|
+
const diagnostics = new Map();
|
|
58
|
+
const emit = (event)=>{
|
|
59
|
+
try {
|
|
60
|
+
if (options.onEvent) options.onEvent(event);
|
|
61
|
+
else if ('admitted' !== event.type && 'success' !== event.type) {
|
|
62
|
+
const entry = diagnostics.get(event.type) ?? {
|
|
63
|
+
last: -1 / 0,
|
|
64
|
+
count: 0
|
|
65
|
+
};
|
|
66
|
+
entry.count++;
|
|
67
|
+
if (performance.now() - entry.last >= 10000) {
|
|
68
|
+
console.warn('[byline:password-sign-in]', {
|
|
69
|
+
...event,
|
|
70
|
+
count: entry.count
|
|
71
|
+
});
|
|
72
|
+
entry.last = performance.now();
|
|
73
|
+
entry.count = 0;
|
|
74
|
+
}
|
|
75
|
+
diagnostics.set(event.type, entry);
|
|
76
|
+
}
|
|
77
|
+
} catch {}
|
|
78
|
+
};
|
|
79
|
+
const identifiers = ({ email, ip })=>({
|
|
80
|
+
account: digest([
|
|
81
|
+
'account',
|
|
82
|
+
email.trim().toLowerCase()
|
|
83
|
+
]),
|
|
84
|
+
network: digest([
|
|
85
|
+
'network',
|
|
86
|
+
signInNetwork(ip)
|
|
87
|
+
])
|
|
88
|
+
});
|
|
89
|
+
let active = 0;
|
|
90
|
+
let disposed = false;
|
|
91
|
+
const queue = [];
|
|
92
|
+
const lease = ()=>{
|
|
93
|
+
active++;
|
|
94
|
+
const started = performance.now();
|
|
95
|
+
let released = false;
|
|
96
|
+
return ()=>{
|
|
97
|
+
if (released) return;
|
|
98
|
+
released = true;
|
|
99
|
+
setTimeout(()=>{
|
|
100
|
+
active--;
|
|
101
|
+
queue.shift()?.grant();
|
|
102
|
+
}, Math.max(0, minimumSlotMs - (performance.now() - started))).unref();
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const cleanupTask = {
|
|
106
|
+
name: CLEANUP_TASK_NAME,
|
|
107
|
+
intervalMs: 60000,
|
|
108
|
+
leaseMs: 60000,
|
|
109
|
+
async run (context) {
|
|
110
|
+
const cutoff = new Date(now() - 300000);
|
|
111
|
+
try {
|
|
112
|
+
for(let batch = 0; batch < 32; batch++){
|
|
113
|
+
context.signal.throwIfAborted();
|
|
114
|
+
await context.heartbeat();
|
|
115
|
+
if (await store.purgeExpired(cutoff) < 100) return {
|
|
116
|
+
workRemaining: false
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
workRemaining: true
|
|
121
|
+
};
|
|
122
|
+
} catch (error) {
|
|
123
|
+
emit({
|
|
124
|
+
type: 'cleanup-error'
|
|
125
|
+
});
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
requiredCleanupTask: CLEANUP_TASK_NAME,
|
|
132
|
+
cleanupTask,
|
|
133
|
+
dispose () {
|
|
134
|
+
disposed = true;
|
|
135
|
+
for (const waiter of queue.splice(0))waiter.cancel();
|
|
136
|
+
},
|
|
137
|
+
async acquire () {
|
|
138
|
+
if (disposed) throw new Error('Sign-in limiter disposed');
|
|
139
|
+
if (active < slots) return lease();
|
|
140
|
+
if (queue.length >= maxQueue) {
|
|
141
|
+
emit({
|
|
142
|
+
type: 'capacity'
|
|
143
|
+
});
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return new Promise((resolve)=>{
|
|
147
|
+
const waiter = {
|
|
148
|
+
grant: ()=>{
|
|
149
|
+
clearTimeout(timeout);
|
|
150
|
+
resolve(lease());
|
|
151
|
+
},
|
|
152
|
+
cancel: ()=>{
|
|
153
|
+
clearTimeout(timeout);
|
|
154
|
+
emit({
|
|
155
|
+
type: 'capacity'
|
|
156
|
+
});
|
|
157
|
+
resolve(null);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const timeout = setTimeout(()=>{
|
|
161
|
+
queue.splice(queue.indexOf(waiter), 1);
|
|
162
|
+
waiter.cancel();
|
|
163
|
+
}, queueTimeoutMs);
|
|
164
|
+
queue.push(waiter);
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
recordResult (input, outcome) {
|
|
168
|
+
emit({
|
|
169
|
+
type: outcome,
|
|
170
|
+
...identifiers(input)
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
async consume (input) {
|
|
174
|
+
const time = now();
|
|
175
|
+
const network = signInNetwork(input.ip);
|
|
176
|
+
const ids = identifiers(input);
|
|
177
|
+
try {
|
|
178
|
+
await store.purgeExpired(new Date(time - 300000));
|
|
179
|
+
for (const [scope, identity] of [
|
|
180
|
+
[
|
|
181
|
+
'ip',
|
|
182
|
+
network
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
'account',
|
|
186
|
+
[
|
|
187
|
+
input.email.trim().toLowerCase(),
|
|
188
|
+
network
|
|
189
|
+
]
|
|
190
|
+
]
|
|
191
|
+
]){
|
|
192
|
+
const rule = rules[scope];
|
|
193
|
+
const windowMs = 1000 * rule.windowSeconds;
|
|
194
|
+
const end = (Math.floor(time / windowMs) + 1) * windowMs;
|
|
195
|
+
if (!await store.consume(digest([
|
|
196
|
+
scope,
|
|
197
|
+
identity,
|
|
198
|
+
end
|
|
199
|
+
]), rule.limit, new Date(end))) {
|
|
200
|
+
emit({
|
|
201
|
+
type: 'denied',
|
|
202
|
+
scope,
|
|
203
|
+
...ids
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
allowed: false,
|
|
207
|
+
retryAfterSeconds: Math.max(1, Math.ceil((end - time) / 1000))
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
emit({
|
|
212
|
+
type: 'admitted',
|
|
213
|
+
...ids
|
|
214
|
+
});
|
|
215
|
+
return {
|
|
216
|
+
allowed: true,
|
|
217
|
+
retryAfterSeconds: 0
|
|
218
|
+
};
|
|
219
|
+
} catch (error) {
|
|
220
|
+
emit({
|
|
221
|
+
type: 'store-error',
|
|
222
|
+
...ids
|
|
223
|
+
});
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
export { createPasswordSignInLimiter };
|
package/dist/store.d.ts
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
import type { AdminPermissionsRepository } from './modules/admin-permissions/repository.js';
|
|
9
9
|
import type { AdminPreferencesRepository } from './modules/admin-preferences/repository.js';
|
|
10
10
|
import type { AdminRolesRepository } from './modules/admin-roles/repository.js';
|
|
11
|
-
import type { AdminUsersRepository } from './modules/admin-users/repository.js';
|
|
11
|
+
import type { AdminUsersRepository, AdminUserWithPasswordRow } from './modules/admin-users/repository.js';
|
|
12
|
+
import type { LoginSessionsRepository } from './modules/auth/login-sessions-repository.js';
|
|
12
13
|
import type { RefreshTokensRepository } from './modules/auth/refresh-tokens-repository.js';
|
|
14
|
+
import type { SignInRateLimitStore } from './modules/auth/sign-in-rate-limiter.js';
|
|
13
15
|
/**
|
|
14
16
|
* The bundle of repositories that `@byline/admin` needs from the DB
|
|
15
17
|
* adapter. A DB adapter package (`@byline/db-postgres`, a future
|
|
@@ -19,11 +21,22 @@ import type { RefreshTokensRepository } from './modules/auth/refresh-tokens-repo
|
|
|
19
21
|
* `JwtSessionProvider`, to `seedSuperAdmin`, and (later) to admin-user
|
|
20
22
|
* and admin-role commands.
|
|
21
23
|
*
|
|
22
|
-
* Keeping the
|
|
24
|
+
* Keeping the repositories together as a single argument avoids
|
|
23
25
|
* exploding constructor signatures and makes "needs admin DB access" a
|
|
24
26
|
* single, recognisable type.
|
|
25
27
|
*/
|
|
26
28
|
export interface AdminStore {
|
|
29
|
+
/**
|
|
30
|
+
* Serialize native issuance/revocation against account mutations. Lock the
|
|
31
|
+
* account row first, then operate on refresh rows through the scoped store.
|
|
32
|
+
* The callback and all its writes commit together or roll back together.
|
|
33
|
+
* Never retain the scoped repositories beyond the callback. No automatic retries.
|
|
34
|
+
*/
|
|
35
|
+
withSessionLock<T>(adminUserId: string, work: (store: AdminStore, user: AdminUserWithPasswordRow | null) => Promise<T>): Promise<T>;
|
|
36
|
+
/** Lock distinct account IDs in sorted order in one transaction for account-switch sign-in. */
|
|
37
|
+
withSessionLocks<T>(adminUserIds: string[], work: (store: AdminStore) => Promise<T>): Promise<T>;
|
|
38
|
+
loginSessions: LoginSessionsRepository;
|
|
39
|
+
signInRateLimits: SignInRateLimitStore;
|
|
27
40
|
adminUsers: AdminUsersRepository;
|
|
28
41
|
adminRoles: AdminRolesRepository;
|
|
29
42
|
adminPermissions: AdminPermissionsRepository;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@byline/admin",
|
|
3
3
|
"private": false,
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "5.1.0",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20.9.0"
|
|
8
8
|
},
|
|
@@ -174,40 +174,40 @@
|
|
|
174
174
|
"@codemirror/lang-sql": "^6.10.0",
|
|
175
175
|
"@codemirror/lang-yaml": "^6.1.3",
|
|
176
176
|
"@codemirror/language": "^6.12.4",
|
|
177
|
-
"@codemirror/state": "^6.7.
|
|
178
|
-
"@codemirror/view": "^6.43.
|
|
177
|
+
"@codemirror/state": "^6.7.4",
|
|
178
|
+
"@codemirror/view": "^6.43.11",
|
|
179
179
|
"@lezer/highlight": "^1.2.3",
|
|
180
180
|
"@tanstack/react-form-start": "^1.33.5",
|
|
181
181
|
"clsx": "^2.1.1",
|
|
182
|
-
"jose": "^6.2.
|
|
182
|
+
"jose": "^6.2.12",
|
|
183
183
|
"react-diff-viewer-continued": "^4.4.0",
|
|
184
184
|
"uuid": "^14.0.2",
|
|
185
|
-
"zod": "^4.4
|
|
186
|
-
"@byline/analytics": "
|
|
187
|
-
"@byline/analytics-agent": "
|
|
188
|
-
"@byline/
|
|
189
|
-
"@byline/
|
|
190
|
-
"@byline/
|
|
191
|
-
"@byline/
|
|
185
|
+
"zod": "^4.5.4",
|
|
186
|
+
"@byline/analytics": "5.1.0",
|
|
187
|
+
"@byline/analytics-agent": "5.1.0",
|
|
188
|
+
"@byline/core": "5.1.0",
|
|
189
|
+
"@byline/auth": "5.1.0",
|
|
190
|
+
"@byline/ui": "5.1.0",
|
|
191
|
+
"@byline/i18n": "5.1.0"
|
|
192
192
|
},
|
|
193
193
|
"peerDependencies": {
|
|
194
194
|
"react": "^19.0.0",
|
|
195
195
|
"react-dom": "^19.0.0"
|
|
196
196
|
},
|
|
197
197
|
"devDependencies": {
|
|
198
|
-
"@biomejs/biome": "2.5.
|
|
198
|
+
"@biomejs/biome": "2.5.12",
|
|
199
199
|
"@rsbuild/plugin-react": "^2.1.0",
|
|
200
|
-
"@rslib/core": "^0.
|
|
201
|
-
"@types/node": "^26.
|
|
200
|
+
"@rslib/core": "^1.0.0",
|
|
201
|
+
"@types/node": "^26.5.0",
|
|
202
202
|
"@types/react": "19.2.18",
|
|
203
|
-
"@types/react-dom": "19.2.
|
|
204
|
-
"@vitejs/plugin-react": "^6.1.
|
|
203
|
+
"@types/react-dom": "19.2.7",
|
|
204
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
205
205
|
"jsdom": "^30.0.1",
|
|
206
206
|
"react": "^19.2.8",
|
|
207
207
|
"react-dom": "^19.2.8",
|
|
208
208
|
"typescript": "^7.0.2",
|
|
209
209
|
"typescript-plugin-css-modules": "^5.2.0",
|
|
210
|
-
"vitest": "^
|
|
210
|
+
"vitest": "^5.0.0"
|
|
211
211
|
},
|
|
212
212
|
"publishConfig": {
|
|
213
213
|
"access": "public",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StructuralMutationReceipt } from '@byline/core'
|
|
1
2
|
/**
|
|
2
3
|
* This Source Code is subject to the terms of the Mozilla Public
|
|
3
4
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
@@ -72,6 +73,7 @@ export interface TreeAncestor {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
export interface PlaceTreeNodeInput {
|
|
76
|
+
expectedRevision: number
|
|
75
77
|
collection: string
|
|
76
78
|
documentId: string
|
|
77
79
|
/** The new parent; `null` makes the document a root node. */
|
|
@@ -82,10 +84,16 @@ export interface PlaceTreeNodeInput {
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
/** Place / move a document within its collection's tree. */
|
|
85
|
-
export type PlaceTreeNodeFn = (
|
|
87
|
+
export type PlaceTreeNodeFn = (
|
|
88
|
+
input: PlaceTreeNodeInput
|
|
89
|
+
) => Promise<{ orderKey: string } & StructuralMutationReceipt>
|
|
86
90
|
|
|
87
91
|
/** Remove a document from the tree (back to the unplaced state). */
|
|
88
|
-
export type RemoveFromTreeFn = (input: {
|
|
92
|
+
export type RemoveFromTreeFn = (input: {
|
|
93
|
+
collection: string
|
|
94
|
+
documentId: string
|
|
95
|
+
expectedRevision: number
|
|
96
|
+
}) => Promise<StructuralMutationReceipt>
|
|
89
97
|
|
|
90
98
|
/** Resolve a document's ancestor chain, root-first, hydrated with titles. */
|
|
91
99
|
export type GetTreeAncestorsFn = (input: {
|
|
@@ -27,6 +27,7 @@ export interface AvailableLocalesWidgetLocale {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export interface AvailableLocalesWidgetProps {
|
|
30
|
+
disabled?: boolean
|
|
30
31
|
/** All configured content locales — one checkbox each (code + display label). */
|
|
31
32
|
contentLocales: ReadonlyArray<AvailableLocalesWidgetLocale>
|
|
32
33
|
/**
|
|
@@ -50,6 +51,7 @@ export interface AvailableLocalesWidgetProps {
|
|
|
50
51
|
* `.byline-form-available-locales-list`.
|
|
51
52
|
*/
|
|
52
53
|
export const AvailableLocalesWidget = ({
|
|
54
|
+
disabled: mutationsBlocked = false,
|
|
53
55
|
contentLocales,
|
|
54
56
|
availableVersionLocales,
|
|
55
57
|
}: AvailableLocalesWidgetProps) => {
|
|
@@ -62,6 +64,7 @@ export const AvailableLocalesWidget = ({
|
|
|
62
64
|
|
|
63
65
|
const toggle = useCallback(
|
|
64
66
|
(code: string, checked: boolean) => {
|
|
67
|
+
if (mutationsBlocked) return
|
|
65
68
|
const next = new Set(advertised)
|
|
66
69
|
if (checked) {
|
|
67
70
|
next.add(code)
|
|
@@ -70,7 +73,7 @@ export const AvailableLocalesWidget = ({
|
|
|
70
73
|
}
|
|
71
74
|
setSystemAvailableLocales([...next])
|
|
72
75
|
},
|
|
73
|
-
[advertised, setSystemAvailableLocales]
|
|
76
|
+
[mutationsBlocked, advertised, setSystemAvailableLocales]
|
|
74
77
|
)
|
|
75
78
|
|
|
76
79
|
if (contentLocales.length === 0) {
|
|
@@ -102,7 +105,7 @@ export const AvailableLocalesWidget = ({
|
|
|
102
105
|
label={label}
|
|
103
106
|
intent={intent}
|
|
104
107
|
checked={checked}
|
|
105
|
-
disabled={disabled}
|
|
108
|
+
disabled={mutationsBlocked || disabled}
|
|
106
109
|
onCheckedChange={(value) => toggle(code, value === true)}
|
|
107
110
|
/>
|
|
108
111
|
)
|
|
@@ -41,6 +41,7 @@ export interface DocumentActionsLocaleOption {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function DocumentActions({
|
|
44
|
+
disabled = false,
|
|
44
45
|
publishedVersion,
|
|
45
46
|
onUnpublish,
|
|
46
47
|
onDelete,
|
|
@@ -59,6 +60,7 @@ export function DocumentActions({
|
|
|
59
60
|
onConfirmScheduledPublication,
|
|
60
61
|
onCancelScheduledPublication,
|
|
61
62
|
}: {
|
|
63
|
+
disabled?: boolean
|
|
62
64
|
publishedVersion?: PublishedVersionInfo | null
|
|
63
65
|
onUnpublish?: () => Promise<void>
|
|
64
66
|
onDelete?: () => Promise<void>
|
|
@@ -221,24 +223,29 @@ export function DocumentActions({
|
|
|
221
223
|
onDelete != null
|
|
222
224
|
|
|
223
225
|
const handleOnDelete = () => {
|
|
226
|
+
if (disabled) return
|
|
224
227
|
setShowDeleteConfirm(false)
|
|
225
228
|
if (onDelete) {
|
|
226
|
-
onDelete()
|
|
229
|
+
void onDelete().catch(() => {})
|
|
227
230
|
}
|
|
228
231
|
}
|
|
229
232
|
|
|
230
233
|
const handleOnDuplicate = async () => {
|
|
234
|
+
if (disabled) return
|
|
231
235
|
if (!onDuplicate) return
|
|
232
236
|
setDuplicateBusy(true)
|
|
233
237
|
try {
|
|
234
238
|
await onDuplicate()
|
|
235
239
|
setShowDuplicateConfirm(false)
|
|
240
|
+
} catch {
|
|
241
|
+
// The host reports the failure and retains the editor observation.
|
|
236
242
|
} finally {
|
|
237
243
|
setDuplicateBusy(false)
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
246
|
|
|
241
247
|
const handleOpenDuplicate = () => {
|
|
248
|
+
if (disabled) return
|
|
242
249
|
// Duplicate copies the saved version — block when the form is dirty so
|
|
243
250
|
// unsaved edits are not silently dropped from the copy.
|
|
244
251
|
if (hasUnsavedChanges) {
|
|
@@ -249,6 +256,7 @@ export function DocumentActions({
|
|
|
249
256
|
}
|
|
250
257
|
|
|
251
258
|
const handleOpenCopyToLocale = () => {
|
|
259
|
+
if (disabled) return
|
|
252
260
|
// Copy-to-Locale reads the saved version — block when the form is dirty.
|
|
253
261
|
if (hasUnsavedChanges) {
|
|
254
262
|
onUnsavedChanges?.()
|
|
@@ -263,17 +271,21 @@ export function DocumentActions({
|
|
|
263
271
|
}
|
|
264
272
|
|
|
265
273
|
const handleOnCopyToLocale = async () => {
|
|
274
|
+
if (disabled) return
|
|
266
275
|
if (!onCopyToLocale || !copyTargetLocale) return
|
|
267
276
|
setCopyToLocaleBusy(true)
|
|
268
277
|
try {
|
|
269
278
|
await onCopyToLocale({ targetLocale: copyTargetLocale, overwrite: copyOverwrite })
|
|
270
279
|
setShowCopyToLocaleConfirm(false)
|
|
280
|
+
} catch {
|
|
281
|
+
// The host reports the failure and retains the editor observation.
|
|
271
282
|
} finally {
|
|
272
283
|
setCopyToLocaleBusy(false)
|
|
273
284
|
}
|
|
274
285
|
}
|
|
275
286
|
|
|
276
287
|
const handleOpenDeleteLocale = () => {
|
|
288
|
+
if (disabled) return
|
|
277
289
|
// Delete-Locale removes the saved version's locale content — block when
|
|
278
290
|
// the form is dirty so the editor saves (or discards) first.
|
|
279
291
|
if (hasUnsavedChanges) {
|
|
@@ -288,11 +300,14 @@ export function DocumentActions({
|
|
|
288
300
|
}
|
|
289
301
|
|
|
290
302
|
const handleOnDeleteLocale = async () => {
|
|
303
|
+
if (disabled) return
|
|
291
304
|
if (!onDeleteLocale || !deleteTargetLocale) return
|
|
292
305
|
setDeleteLocaleBusy(true)
|
|
293
306
|
try {
|
|
294
307
|
await onDeleteLocale({ targetLocale: deleteTargetLocale })
|
|
295
308
|
setShowDeleteLocaleConfirm(false)
|
|
309
|
+
} catch {
|
|
310
|
+
// The host reports the failure and retains the editor observation.
|
|
296
311
|
} finally {
|
|
297
312
|
setDeleteLocaleBusy(false)
|
|
298
313
|
}
|
|
@@ -311,6 +326,7 @@ export function DocumentActions({
|
|
|
311
326
|
{hasAnyAction && (
|
|
312
327
|
<DropdownComponent.Root>
|
|
313
328
|
<DropdownComponent.Trigger
|
|
329
|
+
disabled={disabled}
|
|
314
330
|
render={<IconButton variant="text" intent="noeffect" size="sm" />}
|
|
315
331
|
>
|
|
316
332
|
<EllipsisIcon
|
|
@@ -329,7 +345,7 @@ export function DocumentActions({
|
|
|
329
345
|
>
|
|
330
346
|
{/*{publishedVersion && (
|
|
331
347
|
<>
|
|
332
|
-
<DropdownComponent.Item onClick={onUnpublish}>
|
|
348
|
+
<DropdownComponent.Item disabled={disabled} onClick={onUnpublish}>
|
|
333
349
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
334
350
|
<span className={cx('byline-form-actions-item-icon', styles['item-icon'])} />
|
|
335
351
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
@@ -343,10 +359,16 @@ export function DocumentActions({
|
|
|
343
359
|
{schedulingActions.length > 0 && (
|
|
344
360
|
<>
|
|
345
361
|
{schedulingActions.map((action) => (
|
|
346
|
-
<DropdownComponent.Item
|
|
362
|
+
<DropdownComponent.Item
|
|
363
|
+
disabled={disabled}
|
|
364
|
+
key={action.key}
|
|
365
|
+
onClick={action.onSelect}
|
|
366
|
+
>
|
|
347
367
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
348
368
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
349
|
-
<button type="button"
|
|
369
|
+
<button type="button" disabled={disabled}>
|
|
370
|
+
{action.label}
|
|
371
|
+
</button>
|
|
350
372
|
</span>
|
|
351
373
|
</div>
|
|
352
374
|
</DropdownComponent.Item>
|
|
@@ -355,28 +377,34 @@ export function DocumentActions({
|
|
|
355
377
|
</>
|
|
356
378
|
)}
|
|
357
379
|
{copyToLocaleAvailable && (
|
|
358
|
-
<DropdownComponent.Item onClick={handleOpenCopyToLocale}>
|
|
380
|
+
<DropdownComponent.Item disabled={disabled} onClick={handleOpenCopyToLocale}>
|
|
359
381
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
360
382
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
361
|
-
<button type="button"
|
|
383
|
+
<button type="button" disabled={disabled}>
|
|
384
|
+
{t('documentActions.copyToLocaleMenuItem')}
|
|
385
|
+
</button>
|
|
362
386
|
</span>
|
|
363
387
|
</div>
|
|
364
388
|
</DropdownComponent.Item>
|
|
365
389
|
)}
|
|
366
390
|
{deleteLocaleAvailable && (
|
|
367
|
-
<DropdownComponent.Item onClick={handleOpenDeleteLocale}>
|
|
391
|
+
<DropdownComponent.Item disabled={disabled} onClick={handleOpenDeleteLocale}>
|
|
368
392
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
369
393
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
370
|
-
<button type="button"
|
|
394
|
+
<button type="button" disabled={disabled}>
|
|
395
|
+
{t('documentActions.deleteLocale.menuItem')}
|
|
396
|
+
</button>
|
|
371
397
|
</span>
|
|
372
398
|
</div>
|
|
373
399
|
</DropdownComponent.Item>
|
|
374
400
|
)}
|
|
375
401
|
{onDuplicate && (
|
|
376
|
-
<DropdownComponent.Item onClick={handleOpenDuplicate}>
|
|
402
|
+
<DropdownComponent.Item disabled={disabled} onClick={handleOpenDuplicate}>
|
|
377
403
|
<div className={cx('byline-form-actions-item', styles.item)}>
|
|
378
404
|
<span className={cx('byline-form-actions-item-text', styles['item-text'])}>
|
|
379
|
-
<button type="button"
|
|
405
|
+
<button type="button" disabled={disabled}>
|
|
406
|
+
{t('common.actions.duplicate')}
|
|
407
|
+
</button>
|
|
380
408
|
</span>
|
|
381
409
|
</div>
|
|
382
410
|
</DropdownComponent.Item>
|
|
@@ -385,6 +413,7 @@ export function DocumentActions({
|
|
|
385
413
|
<>
|
|
386
414
|
<DropdownComponent.Separator />
|
|
387
415
|
<DropdownComponent.Item
|
|
416
|
+
disabled={disabled}
|
|
388
417
|
onClick={() => {
|
|
389
418
|
setShowDeleteConfirm(true)
|
|
390
419
|
}}
|
|
@@ -454,7 +483,13 @@ export function DocumentActions({
|
|
|
454
483
|
>
|
|
455
484
|
{t('common.actions.cancel')}
|
|
456
485
|
</Button>
|
|
457
|
-
<Button
|
|
486
|
+
<Button
|
|
487
|
+
size="sm"
|
|
488
|
+
style={{ minWidth: '80px' }}
|
|
489
|
+
intent="danger"
|
|
490
|
+
disabled={disabled}
|
|
491
|
+
onClick={handleOnDelete}
|
|
492
|
+
>
|
|
458
493
|
{t('common.actions.delete')}
|
|
459
494
|
</Button>
|
|
460
495
|
</Modal.Actions>
|
|
@@ -533,7 +568,7 @@ export function DocumentActions({
|
|
|
533
568
|
onClick={() => {
|
|
534
569
|
if (!duplicateBusy) setShowDuplicateConfirm(false)
|
|
535
570
|
}}
|
|
536
|
-
disabled={duplicateBusy}
|
|
571
|
+
disabled={disabled || duplicateBusy}
|
|
537
572
|
>
|
|
538
573
|
{t('common.actions.cancel')}
|
|
539
574
|
</Button>
|
|
@@ -542,7 +577,7 @@ export function DocumentActions({
|
|
|
542
577
|
style={{ minWidth: '80px' }}
|
|
543
578
|
intent="primary"
|
|
544
579
|
onClick={handleOnDuplicate}
|
|
545
|
-
disabled={duplicateBusy}
|
|
580
|
+
disabled={disabled || duplicateBusy}
|
|
546
581
|
>
|
|
547
582
|
{duplicateBusy
|
|
548
583
|
? t('documentActions.duplicate.busyButton')
|
|
@@ -611,7 +646,7 @@ export function DocumentActions({
|
|
|
611
646
|
onValueChange={(value) => {
|
|
612
647
|
if (value != null) setCopyTargetLocale(value)
|
|
613
648
|
}}
|
|
614
|
-
disabled={copyToLocaleBusy}
|
|
649
|
+
disabled={disabled || copyToLocaleBusy}
|
|
615
650
|
/>
|
|
616
651
|
</div>
|
|
617
652
|
<div
|
|
@@ -623,7 +658,7 @@ export function DocumentActions({
|
|
|
623
658
|
name="overwrite"
|
|
624
659
|
label={t('documentActions.copyToLocale.overwriteLabel')}
|
|
625
660
|
checked={copyOverwrite}
|
|
626
|
-
disabled={copyToLocaleBusy}
|
|
661
|
+
disabled={disabled || copyToLocaleBusy}
|
|
627
662
|
helpText={t('documentActions.copyToLocale.overwriteHelp')}
|
|
628
663
|
onCheckedChange={(value) => {
|
|
629
664
|
setCopyOverwrite(value === true)
|
|
@@ -647,7 +682,7 @@ export function DocumentActions({
|
|
|
647
682
|
onClick={() => {
|
|
648
683
|
if (!copyToLocaleBusy) setShowCopyToLocaleConfirm(false)
|
|
649
684
|
}}
|
|
650
|
-
disabled={copyToLocaleBusy}
|
|
685
|
+
disabled={disabled || copyToLocaleBusy}
|
|
651
686
|
>
|
|
652
687
|
{t('common.actions.cancel')}
|
|
653
688
|
</Button>
|
|
@@ -656,7 +691,7 @@ export function DocumentActions({
|
|
|
656
691
|
style={{ minWidth: '80px' }}
|
|
657
692
|
intent="primary"
|
|
658
693
|
onClick={handleOnCopyToLocale}
|
|
659
|
-
disabled={copyToLocaleBusy || !copyTargetLocale}
|
|
694
|
+
disabled={disabled || copyToLocaleBusy || !copyTargetLocale}
|
|
660
695
|
>
|
|
661
696
|
{copyToLocaleBusy
|
|
662
697
|
? t('documentActions.copyToLocale.busyButton')
|
|
@@ -711,7 +746,7 @@ export function DocumentActions({
|
|
|
711
746
|
onValueChange={(value) => {
|
|
712
747
|
if (value != null) setDeleteTargetLocale(value)
|
|
713
748
|
}}
|
|
714
|
-
disabled={deleteLocaleBusy}
|
|
749
|
+
disabled={disabled || deleteLocaleBusy}
|
|
715
750
|
/>
|
|
716
751
|
</div>
|
|
717
752
|
<p style={{ marginTop: 'var(--spacing-12)' }}>
|
|
@@ -734,7 +769,7 @@ export function DocumentActions({
|
|
|
734
769
|
onClick={() => {
|
|
735
770
|
if (!deleteLocaleBusy) setShowDeleteLocaleConfirm(false)
|
|
736
771
|
}}
|
|
737
|
-
disabled={deleteLocaleBusy}
|
|
772
|
+
disabled={disabled || deleteLocaleBusy}
|
|
738
773
|
>
|
|
739
774
|
{t('common.actions.cancel')}
|
|
740
775
|
</Button>
|
|
@@ -743,7 +778,7 @@ export function DocumentActions({
|
|
|
743
778
|
style={{ minWidth: '80px' }}
|
|
744
779
|
intent="danger"
|
|
745
780
|
onClick={handleOnDeleteLocale}
|
|
746
|
-
disabled={deleteLocaleBusy || !deleteTargetLocale}
|
|
781
|
+
disabled={disabled || deleteLocaleBusy || !deleteTargetLocale}
|
|
747
782
|
>
|
|
748
783
|
{deleteLocaleBusy
|
|
749
784
|
? t('documentActions.deleteLocale.busyButton')
|