@zhin.js/console-contract 1.1.1 → 1.1.3

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.
@@ -2,6 +2,7 @@ export interface NavNode {
2
2
  readonly id: string;
3
3
  readonly type: 'plugin' | 'page';
4
4
  readonly label: string;
5
+ readonly titleI18n?: Readonly<Partial<Record<'zh-CN' | 'en', string>>>;
5
6
  readonly icon?: string;
6
7
  readonly path?: string;
7
8
  readonly order: number;
@@ -10,4 +11,6 @@ export interface NavNode {
10
11
  export interface AccessSnapshot {
11
12
  readonly permissions: readonly string[];
12
13
  readonly roles: readonly string[];
14
+ /** The operator (full-scope token, or a Host without tokens): every Page is allowed. */
15
+ readonly unrestricted?: boolean;
13
16
  }
package/lib/page.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export interface PageMetadata {
2
2
  readonly title?: string;
3
+ /** Explicit display titles; missing locales retain title. */
4
+ readonly titleI18n?: Readonly<Partial<Record<'zh-CN' | 'en', string>>>;
3
5
  readonly icon?: string;
4
6
  readonly order?: number;
5
7
  readonly hideInNav?: boolean;
@@ -8,6 +10,7 @@ export interface PageMetadata {
8
10
  }
9
11
  export interface NormalizedPageMetadata {
10
12
  readonly title: string;
13
+ readonly titleI18n?: Readonly<Partial<Record<'zh-CN' | 'en', string>>>;
11
14
  readonly icon?: string;
12
15
  readonly order: number;
13
16
  readonly hideInNav: boolean;
package/lib/page.js CHANGED
@@ -14,11 +14,13 @@ export function normalizePageMetadata(localName, metadata) {
14
14
  const input = metadata === undefined ? {} : requireRecord(metadata, 'Page metadata');
15
15
  assertKnownMetadataKeys(input);
16
16
  const title = optionalString(input.title, 'Page title') ?? titleFromName(localName);
17
+ const titleI18n = pageTitleTranslations(input.titleI18n);
17
18
  const icon = optionalString(input.icon, 'Page icon');
18
19
  const order = optionalNumber(input.order, 'Page order') ?? 100;
19
20
  const hideInNav = optionalBoolean(input.hideInNav, 'Page hideInNav') ?? false;
20
21
  return Object.freeze({
21
22
  title,
23
+ ...(titleI18n === undefined ? {} : { titleI18n }),
22
24
  icon,
23
25
  order,
24
26
  hideInNav,
@@ -29,6 +31,7 @@ export function normalizePageMetadata(localName, metadata) {
29
31
  function assertKnownMetadataKeys(input) {
30
32
  const known = new Set([
31
33
  'title',
34
+ 'titleI18n',
32
35
  'icon',
33
36
  'order',
34
37
  'hideInNav',
@@ -61,6 +64,7 @@ function normalizePageInput(metadata) {
61
64
  const normalized = normalizePageMetadata('page', metadata);
62
65
  return Object.freeze({
63
66
  title: metadata.title === undefined ? undefined : normalized.title,
67
+ ...(normalized.titleI18n === undefined ? {} : { titleI18n: normalized.titleI18n }),
64
68
  icon: normalized.icon,
65
69
  order: metadata.order === undefined ? undefined : normalized.order,
66
70
  hideInNav: metadata.hideInNav === undefined ? undefined : normalized.hideInNav,
@@ -110,3 +114,18 @@ function stringList(value, label) {
110
114
  });
111
115
  return Object.freeze([...new Set(result)].sort());
112
116
  }
117
+ function pageTitleTranslations(value) {
118
+ if (value === undefined)
119
+ return undefined;
120
+ const input = requireRecord(value, 'Page titleI18n');
121
+ const output = {};
122
+ for (const [locale, title] of Object.entries(input)) {
123
+ if (locale !== 'zh-CN' && locale !== 'en')
124
+ throw new TypeError(`Unsupported Page titleI18n locale: ${locale}`);
125
+ const text = optionalString(title, `Page titleI18n.${locale}`);
126
+ if (text === undefined)
127
+ throw new TypeError(`Page titleI18n.${locale} must be a non-empty string`);
128
+ output[locale] = text;
129
+ }
130
+ return Object.freeze(output);
131
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/console-contract",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Zero-dependency Page, Layout, route and navigation contracts for Zhin.js plugins",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -8,7 +8,6 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./lib/index.d.ts",
11
- "development": "./src/index.ts",
12
11
  "import": "./lib/index.js"
13
12
  }
14
13
  },
@@ -30,7 +29,7 @@
30
29
  "registry": "https://registry.npmjs.org"
31
30
  },
32
31
  "engines": {
33
- "node": "^20.19.0 || >=22.12.0"
32
+ "node": ">=22.19.0"
34
33
  },
35
34
  "license": "MIT",
36
35
  "scripts": {
package/src/navigation.ts CHANGED
@@ -2,6 +2,7 @@ export interface NavNode {
2
2
  readonly id: string;
3
3
  readonly type: 'plugin' | 'page';
4
4
  readonly label: string;
5
+ readonly titleI18n?: Readonly<Partial<Record<'zh-CN' | 'en', string>>>;
5
6
  readonly icon?: string;
6
7
  readonly path?: string;
7
8
  readonly order: number;
@@ -11,4 +12,6 @@ export interface NavNode {
11
12
  export interface AccessSnapshot {
12
13
  readonly permissions: readonly string[];
13
14
  readonly roles: readonly string[];
15
+ /** The operator (full-scope token, or a Host without tokens): every Page is allowed. */
16
+ readonly unrestricted?: boolean;
14
17
  }
package/src/page.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export interface PageMetadata {
2
2
  readonly title?: string;
3
+ /** Explicit display titles; missing locales retain title. */
4
+ readonly titleI18n?: Readonly<Partial<Record<'zh-CN' | 'en', string>>>;
3
5
  readonly icon?: string;
4
6
  readonly order?: number;
5
7
  readonly hideInNav?: boolean;
@@ -9,6 +11,7 @@ export interface PageMetadata {
9
11
 
10
12
  export interface NormalizedPageMetadata {
11
13
  readonly title: string;
14
+ readonly titleI18n?: Readonly<Partial<Record<'zh-CN' | 'en', string>>>;
12
15
  readonly icon?: string;
13
16
  readonly order: number;
14
17
  readonly hideInNav: boolean;
@@ -55,11 +58,13 @@ export function normalizePageMetadata(
55
58
  const input = metadata === undefined ? {} : requireRecord(metadata, 'Page metadata');
56
59
  assertKnownMetadataKeys(input);
57
60
  const title = optionalString(input.title, 'Page title') ?? titleFromName(localName);
61
+ const titleI18n = pageTitleTranslations(input.titleI18n);
58
62
  const icon = optionalString(input.icon, 'Page icon');
59
63
  const order = optionalNumber(input.order, 'Page order') ?? 100;
60
64
  const hideInNav = optionalBoolean(input.hideInNav, 'Page hideInNav') ?? false;
61
65
  return Object.freeze({
62
66
  title,
67
+ ...(titleI18n === undefined ? {} : { titleI18n }),
63
68
  icon,
64
69
  order,
65
70
  hideInNav,
@@ -71,6 +76,7 @@ export function normalizePageMetadata(
71
76
  function assertKnownMetadataKeys(input: Record<string, unknown>): void {
72
77
  const known = new Set([
73
78
  'title',
79
+ 'titleI18n',
74
80
  'icon',
75
81
  'order',
76
82
  'hideInNav',
@@ -105,6 +111,7 @@ function normalizePageInput(metadata: PageMetadata): Readonly<PageMetadata> {
105
111
  const normalized = normalizePageMetadata('page', metadata);
106
112
  return Object.freeze({
107
113
  title: metadata.title === undefined ? undefined : normalized.title,
114
+ ...(normalized.titleI18n === undefined ? {} : { titleI18n: normalized.titleI18n }),
108
115
  icon: normalized.icon,
109
116
  order: metadata.order === undefined ? undefined : normalized.order,
110
117
  hideInNav: metadata.hideInNav === undefined ? undefined : normalized.hideInNav,
@@ -151,3 +158,16 @@ function stringList(value: unknown, label: string): readonly string[] {
151
158
  });
152
159
  return Object.freeze([...new Set(result)].sort());
153
160
  }
161
+
162
+ function pageTitleTranslations(value: unknown): NormalizedPageMetadata['titleI18n'] {
163
+ if (value === undefined) return undefined;
164
+ const input = requireRecord(value, 'Page titleI18n');
165
+ const output: Partial<Record<'zh-CN' | 'en', string>> = {};
166
+ for (const [locale, title] of Object.entries(input)) {
167
+ if (locale !== 'zh-CN' && locale !== 'en') throw new TypeError(`Unsupported Page titleI18n locale: ${locale}`);
168
+ const text = optionalString(title, `Page titleI18n.${locale}`);
169
+ if (text === undefined) throw new TypeError(`Page titleI18n.${locale} must be a non-empty string`);
170
+ output[locale] = text;
171
+ }
172
+ return Object.freeze(output);
173
+ }