@zhin.js/command 1.1.10 → 1.1.11
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/README.md +21 -1
- package/lib/arguments.d.ts +8 -2
- package/lib/arguments.js +40 -27
- package/lib/command-index.d.ts +24 -5
- package/lib/command-index.js +87 -43
- package/lib/command-menu.d.ts +7 -6
- package/lib/command-menu.js +7 -5
- package/lib/definition.d.ts +25 -2
- package/lib/definition.js +34 -1
- package/lib/index.d.ts +1 -1
- package/lib/messages.d.ts +8 -0
- package/lib/messages.js +57 -0
- package/lib/permission-explanation.d.ts +2 -0
- package/lib/permission-explanation.js +15 -12
- package/lib/provider.js +1 -1
- package/package.json +4 -4
- package/src/arguments.ts +54 -26
- package/src/command-index.ts +114 -46
- package/src/command-menu.ts +17 -13
- package/src/definition.ts +48 -1
- package/src/index.ts +1 -1
- package/src/messages.ts +62 -0
- package/src/permission-explanation.ts +16 -13
- package/src/provider.ts +1 -1
|
@@ -2,6 +2,8 @@ import { operationClientAdapter } from '@zhin.js/feature-kit';
|
|
|
2
2
|
import { explainPermitRules, toPermissionSubject, type PermissionSubject, type PermissionConditionExplanation } from '@zhin.js/permission';
|
|
3
3
|
import { resolveCommandSender, resolveCommandSession, type CommandMessage } from './definition.js';
|
|
4
4
|
import type { CommandDescriptor } from './command-index.js';
|
|
5
|
+
import { resolveLocale, type Locale } from '@zhin.js/plugin-runtime';
|
|
6
|
+
import { commandMessages } from './messages.js';
|
|
5
7
|
|
|
6
8
|
/** The exact subject projection used by the real command permit gate. No factories or checkers run. */
|
|
7
9
|
export function toCommandPermissionSubject(source: unknown): PermissionSubject {
|
|
@@ -20,8 +22,9 @@ export type CommandPermissionHostStatus = 'present' | 'missing' | 'unverified';
|
|
|
20
22
|
/** Read-only hypothetical conditions. A match is not permission to execute the command. */
|
|
21
23
|
export function explainCommandPermissions(
|
|
22
24
|
command: Pick<CommandDescriptor, 'adapter' | 'permit'>,
|
|
23
|
-
options: Readonly<{ source?: unknown; rolesKnown?: boolean; permissionHost: CommandPermissionHostStatus }>,
|
|
25
|
+
options: Readonly<{ source?: unknown; rolesKnown?: boolean; permissionHost: CommandPermissionHostStatus; locale?: Locale }>,
|
|
24
26
|
) {
|
|
27
|
+
const locale = resolveLocale(options.locale);
|
|
25
28
|
const projected = toCommandPermissionSubject(options.source);
|
|
26
29
|
const inputSender = options.source && typeof options.source === 'object'
|
|
27
30
|
? (options.source as Pick<CommandMessage, 'sender'>).sender : undefined;
|
|
@@ -36,23 +39,23 @@ export function explainCommandPermissions(
|
|
|
36
39
|
&& subject.sender?.role.length === 1 && subject.sender.role[0] === 'user';
|
|
37
40
|
const actualAdapter = operationClientAdapter(options.source);
|
|
38
41
|
const adapter: PermissionConditionExplanation = !command.adapter
|
|
39
|
-
? { outcome: 'not_evaluated', reason:
|
|
40
|
-
: !actualAdapter ? { outcome: 'unknown', reason:
|
|
41
|
-
: { outcome: commandAdapterMatches(command, options.source) ? 'match' : 'mismatch', reason:
|
|
42
|
-
const rules = explainPermitRules(command.permit ?? [], subject, { rolesKnown: options.rolesKnown });
|
|
42
|
+
? { outcome: 'not_evaluated', reason: commandMessages(locale, 'noAdapter') }
|
|
43
|
+
: !actualAdapter ? { outcome: 'unknown', reason: commandMessages(locale, 'missingEndpoint') }
|
|
44
|
+
: { outcome: commandAdapterMatches(command, options.source) ? 'match' : 'mismatch', reason: commandMessages(locale, 'adapterComparison') };
|
|
45
|
+
const rules = explainPermitRules(command.permit ?? [], subject, { rolesKnown: options.rolesKnown, locale });
|
|
43
46
|
const conditions = [...(command.adapter ? [adapter] : []), ...rules];
|
|
44
47
|
let summary: PermissionConditionExplanation;
|
|
45
|
-
if (conditions.some(item => item.outcome === 'mismatch')) summary = { outcome: 'mismatch', reason: '
|
|
48
|
+
if (conditions.some(item => item.outcome === 'mismatch')) summary = { outcome: 'mismatch', reason: commandMessages(locale, 'conditionMismatch') };
|
|
46
49
|
else if ((rules.length > 0 && options.permissionHost !== 'present') || conditions.some(item => item.outcome === 'unknown')) {
|
|
47
50
|
summary = { outcome: 'unknown', reason: rules.length > 0 && options.permissionHost !== 'present'
|
|
48
|
-
?
|
|
49
|
-
} else if (rules.length === 0) summary = { outcome: 'not_evaluated', reason:
|
|
50
|
-
else if (conditions.some(item => item.outcome === 'not_evaluated')) summary = { outcome: 'not_evaluated', reason: '
|
|
51
|
-
else summary = { outcome: 'match', reason:
|
|
51
|
+
? commandMessages(locale, 'missingPermissionHost') : commandMessages(locale, 'missingEvidence') };
|
|
52
|
+
} else if (rules.length === 0) summary = { outcome: 'not_evaluated', reason: commandMessages(locale, 'noPermit') };
|
|
53
|
+
else if (conditions.some(item => item.outcome === 'not_evaluated')) summary = { outcome: 'not_evaluated', reason: commandMessages(locale, 'uncheckedConditions') };
|
|
54
|
+
else summary = { outcome: 'match', reason: commandMessages(locale, 'conditionsMatch') };
|
|
52
55
|
return Object.freeze({ permissionHost: options.permissionHost, adapter: Object.freeze(adapter), rules, summary: Object.freeze(summary),
|
|
53
|
-
unconstrained: Object.freeze([
|
|
54
|
-
assumptions: Object.freeze(['
|
|
56
|
+
unconstrained: Object.freeze([commandMessages(locale, 'unconstrained')]),
|
|
57
|
+
assumptions: Object.freeze([commandMessages(locale, 'simulatedIdentity'), commandMessages(locale, 'unevaluatedCode'),
|
|
55
58
|
...(defaultedRoles
|
|
56
|
-
? [
|
|
59
|
+
? [commandMessages(locale, 'defaultedRole')] : [])]),
|
|
57
60
|
});
|
|
58
61
|
}
|
package/src/provider.ts
CHANGED
|
@@ -311,7 +311,7 @@ const commandFeature = defineFeatureProvider({
|
|
|
311
311
|
const rawKeyword = rootConfig?.menuKeyword;
|
|
312
312
|
const menu = rawKeyword === false || rawKeyword === ''
|
|
313
313
|
? undefined
|
|
314
|
-
:
|
|
314
|
+
: typeof rawKeyword === 'string' ? { keyword: rawKeyword } : {};
|
|
315
315
|
return { value: new CommandIndex(slots, context.snapshot, menu) };
|
|
316
316
|
},
|
|
317
317
|
},
|