@zhin.js/contract 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 凉菜
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ /** Host API + plugin entry routes (entries, esm, @assets). Remote UI uses root paths (/dashboard, …). */
2
+ export declare const DEFAULT_CONSOLE_BASE_PATH = "/";
3
+ export declare const CONSOLE_HOST_REACT_NAMESPACE_KEY = "__ZHIN_CONSOLE_HOST_REACT_NAMESPACE__";
4
+ export declare const CONSOLE_SHARED_MODULES_KEY = "__ZHIN_CONSOLE_SHARED_MODULES__";
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C,eAAO,MAAM,gCAAgC,0CAA0C,CAAC;AAExF,eAAO,MAAM,0BAA0B,oCAAoC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Host API + plugin entry routes (entries, esm, @assets). Remote UI uses root paths (/dashboard, …). */
2
+ export const DEFAULT_CONSOLE_BASE_PATH = "/";
3
+ export const CONSOLE_HOST_REACT_NAMESPACE_KEY = "__ZHIN_CONSOLE_HOST_REACT_NAMESPACE__";
4
+ export const CONSOLE_SHARED_MODULES_KEY = "__ZHIN_CONSOLE_SHARED_MODULES__";
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAE7C,MAAM,CAAC,MAAM,gCAAgC,GAAG,uCAAuC,CAAC;AAExF,MAAM,CAAC,MAAM,0BAA0B,GAAG,iCAAiC,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,90 @@
1
+ export { DEFAULT_CONSOLE_BASE_PATH, CONSOLE_HOST_REACT_NAMESPACE_KEY, CONSOLE_SHARED_MODULES_KEY, } from "./constants.js";
2
+ export type RuntimeEnv = "development" | "production";
3
+ export type ConsoleUser = {
4
+ id: string;
5
+ name: string;
6
+ roles?: string[];
7
+ permissions: string[];
8
+ };
9
+ export type ConsoleAuthContext = unknown;
10
+ export type ConsoleAuthAdapter = {
11
+ getUser(ctx: ConsoleAuthContext): Promise<ConsoleUser | null> | ConsoleUser | null;
12
+ hasPermission(user: ConsoleUser, permission: string): boolean;
13
+ };
14
+ export type EntryModuleSpec = string | {
15
+ dev: string;
16
+ prod?: string;
17
+ };
18
+ export type ConsoleEntryPaths = {
19
+ development: string;
20
+ production: string;
21
+ };
22
+ export type ConsoleEntry = {
23
+ id: string;
24
+ paths?: ConsoleEntryPaths;
25
+ serverPaths?: {
26
+ development: string;
27
+ production: string;
28
+ };
29
+ module?: EntryModuleSpec;
30
+ packageEntry?: string;
31
+ order?: number;
32
+ enabled?: boolean;
33
+ meta?: {
34
+ name?: string;
35
+ version?: string;
36
+ };
37
+ requiredPermissions?: string[];
38
+ };
39
+ export type ConsoleFileAddEntryInput = {
40
+ id?: string;
41
+ development: string;
42
+ production: string;
43
+ serverDevelopment?: string;
44
+ serverProduction?: string;
45
+ order?: number;
46
+ enabled?: boolean;
47
+ meta?: {
48
+ name?: string;
49
+ version?: string;
50
+ };
51
+ requiredPermissions?: string[];
52
+ };
53
+ export type ConsoleClientEntry = Omit<ConsoleEntry, "serverPaths"> & {
54
+ resolvedModule: string;
55
+ };
56
+ export type PluginAddRouteInput = {
57
+ path: string;
58
+ name: string;
59
+ element: unknown;
60
+ parent?: string | null;
61
+ icon?: unknown;
62
+ meta?: {
63
+ hideInMenu?: boolean;
64
+ order?: number;
65
+ group?: string;
66
+ fullWidth?: boolean;
67
+ };
68
+ requiredPermissions?: string[];
69
+ requiredRoles?: string[];
70
+ };
71
+ export type PluginAddToolInput = {
72
+ id?: string;
73
+ name: string;
74
+ icon?: unknown;
75
+ parent?: string | null;
76
+ path?: string;
77
+ };
78
+ export type PluginRegisterHostApi = {
79
+ React: typeof import("react");
80
+ addRoute(input: PluginAddRouteInput): void;
81
+ /** 与旧版控制台 register(api) 对齐,等价于 addRoute */
82
+ addPage(input: PluginAddRouteInput): void;
83
+ addTool(input: PluginAddToolInput): string;
84
+ };
85
+ export type ConsolePluginRegister = (api: PluginRegisterHostApi) => void | Promise<void>;
86
+ export type ConsoleEntriesResponse = {
87
+ entries: ConsoleClientEntry[];
88
+ runtimeEnvHint: RuntimeEnv | null;
89
+ };
90
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EAC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AO,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,cAAc,OAAO,CAAC,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC3C,2CAA2C;IAC3C,OAAO,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC1C,OAAO,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,qBAAqB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzF,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,cAAc,EAAE,UAAU,GAAG,IAAI,CAAC;CACnC,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { DEFAULT_CONSOLE_BASE_PATH, CONSOLE_HOST_REACT_NAMESPACE_KEY, CONSOLE_SHARED_MODULES_KEY, } from "./constants.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@zhin.js/contract",
3
+ "version": "1.0.0",
4
+ "description": "Zhin console / PageManager shared contract (entries, PluginRegisterHostApi)",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./lib/index.d.ts",
9
+ "development": "./src/index.ts",
10
+ "import": "./lib/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "lib",
15
+ "src"
16
+ ],
17
+ "devDependencies": {
18
+ "@types/react": "^19.2.15",
19
+ "rimraf": "^6.0.1",
20
+ "typescript": "^6.0.2"
21
+ },
22
+ "license": "MIT",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/zhinjs/zhin.git",
26
+ "directory": "packages/console/contract"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public",
30
+ "registry": "https://registry.npmjs.org"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc -p tsconfig.json",
34
+ "clean": "rimraf lib",
35
+ "typecheck": "tsc -p tsconfig.json --noEmit"
36
+ }
37
+ }
@@ -0,0 +1,6 @@
1
+ /** Host API + plugin entry routes (entries, esm, @assets). Remote UI uses root paths (/dashboard, …). */
2
+ export const DEFAULT_CONSOLE_BASE_PATH = "/";
3
+
4
+ export const CONSOLE_HOST_REACT_NAMESPACE_KEY = "__ZHIN_CONSOLE_HOST_REACT_NAMESPACE__";
5
+
6
+ export const CONSOLE_SHARED_MODULES_KEY = "__ZHIN_CONSOLE_SHARED_MODULES__";
package/src/index.ts ADDED
@@ -0,0 +1,100 @@
1
+ export {
2
+ DEFAULT_CONSOLE_BASE_PATH,
3
+ CONSOLE_HOST_REACT_NAMESPACE_KEY,
4
+ CONSOLE_SHARED_MODULES_KEY,
5
+ } from "./constants.js";
6
+
7
+ export type RuntimeEnv = "development" | "production";
8
+
9
+ export type ConsoleUser = {
10
+ id: string;
11
+ name: string;
12
+ roles?: string[];
13
+ permissions: string[];
14
+ };
15
+
16
+ export type ConsoleAuthContext = unknown;
17
+
18
+ export type ConsoleAuthAdapter = {
19
+ getUser(ctx: ConsoleAuthContext): Promise<ConsoleUser | null> | ConsoleUser | null;
20
+ hasPermission(user: ConsoleUser, permission: string): boolean;
21
+ };
22
+
23
+ export type EntryModuleSpec =
24
+ | string
25
+ | {
26
+ dev: string;
27
+ prod?: string;
28
+ };
29
+
30
+ export type ConsoleEntryPaths = {
31
+ development: string;
32
+ production: string;
33
+ };
34
+
35
+ export type ConsoleEntry = {
36
+ id: string;
37
+ paths?: ConsoleEntryPaths;
38
+ serverPaths?: { development: string; production: string };
39
+ module?: EntryModuleSpec;
40
+ packageEntry?: string;
41
+ order?: number;
42
+ enabled?: boolean;
43
+ meta?: { name?: string; version?: string };
44
+ requiredPermissions?: string[];
45
+ };
46
+
47
+ export type ConsoleFileAddEntryInput = {
48
+ id?: string;
49
+ development: string;
50
+ production: string;
51
+ serverDevelopment?: string;
52
+ serverProduction?: string;
53
+ order?: number;
54
+ enabled?: boolean;
55
+ meta?: { name?: string; version?: string };
56
+ requiredPermissions?: string[];
57
+ };
58
+
59
+ export type ConsoleClientEntry = Omit<ConsoleEntry, "serverPaths"> & {
60
+ resolvedModule: string;
61
+ };
62
+
63
+ export type PluginAddRouteInput = {
64
+ path: string;
65
+ name: string;
66
+ element: unknown;
67
+ parent?: string | null;
68
+ icon?: unknown;
69
+ meta?: {
70
+ hideInMenu?: boolean;
71
+ order?: number;
72
+ group?: string;
73
+ fullWidth?: boolean;
74
+ };
75
+ requiredPermissions?: string[];
76
+ requiredRoles?: string[];
77
+ };
78
+
79
+ export type PluginAddToolInput = {
80
+ id?: string;
81
+ name: string;
82
+ icon?: unknown;
83
+ parent?: string | null;
84
+ path?: string;
85
+ };
86
+
87
+ export type PluginRegisterHostApi = {
88
+ React: typeof import("react");
89
+ addRoute(input: PluginAddRouteInput): void;
90
+ /** 与旧版控制台 register(api) 对齐,等价于 addRoute */
91
+ addPage(input: PluginAddRouteInput): void;
92
+ addTool(input: PluginAddToolInput): string;
93
+ };
94
+
95
+ export type ConsolePluginRegister = (api: PluginRegisterHostApi) => void | Promise<void>;
96
+
97
+ export type ConsoleEntriesResponse = {
98
+ entries: ConsoleClientEntry[];
99
+ runtimeEnvHint: RuntimeEnv | null;
100
+ };