@vector-metis/browser-sdk 0.1.1

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.
@@ -0,0 +1,43 @@
1
+ /** 平台注入浏览器能力的公开类型。 */
2
+ export interface BrowserContext {
3
+ appId: string;
4
+ appType: "RUNTIME_APPLICATION_TYPE_WEB";
5
+ tenantId: string;
6
+ userId: string;
7
+ role: string;
8
+ actorType: "RUNTIME_ACTOR_TYPE_USER";
9
+ }
10
+ /** source 应用声明的 Web 依赖。 */
11
+ export interface WebDependency {
12
+ appId: string;
13
+ alias: string;
14
+ required: boolean;
15
+ appType: "RUNTIME_APPLICATION_TYPE_WEB";
16
+ available: boolean;
17
+ webBasePath: string;
18
+ }
19
+ /** 平台注入脚本暴露的能力接口。 */
20
+ export interface InjectedBrowserSDK {
21
+ appURL(path?: string): string;
22
+ getContext(): Promise<BrowserContext>;
23
+ listDependencies(): Promise<WebDependency[]>;
24
+ dependency(aliasOrAppId: string): Promise<WebDependency>;
25
+ dependencyURL(aliasOrAppId: string, path?: string): Promise<string>;
26
+ openAppPage(options: {
27
+ app: string;
28
+ path?: string;
29
+ query?: Record<string, string>;
30
+ }): Promise<void>;
31
+ }
32
+ declare global {
33
+ interface Window {
34
+ Metis?: InjectedBrowserSDK;
35
+ }
36
+ }
37
+ /** 返回平台已经注入的浏览器能力;脚本缺失时明确失败。 */
38
+ export declare function injected(): InjectedBrowserSDK;
39
+ /** 对平台注入能力做延迟解析的类型化代理。 */
40
+ export declare const Metis: InjectedBrowserSDK;
41
+ export type MetisBrowserContext = BrowserContext;
42
+ export type MetisBrowserSDK = InjectedBrowserSDK;
43
+ export type MetisWebDependency = WebDependency;
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ /** 返回平台已经注入的浏览器能力;脚本缺失时明确失败。 */
2
+ export function injected() {
3
+ const sdk = globalThis.window?.Metis;
4
+ if (!sdk) {
5
+ throw new Error("Metis browser SDK is not injected; load /api/runtime/v1/browser-sdk.js first");
6
+ }
7
+ return sdk;
8
+ }
9
+ /** 对平台注入能力做延迟解析的类型化代理。 */
10
+ export const Metis = Object.freeze({
11
+ appURL: (path) => injected().appURL(path),
12
+ getContext: () => injected().getContext(),
13
+ listDependencies: () => injected().listDependencies(),
14
+ dependency: (selector) => injected().dependency(selector),
15
+ dependencyURL: (selector, path) => injected().dependencyURL(selector, path),
16
+ openAppPage: (options) => injected().openAppPage(options),
17
+ });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@vector-metis/browser-sdk",
3
+ "version": "0.1.1",
4
+ "description": "Metis browser SDK for injected application capabilities",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/vector-metis/metis-sdk-typescript.git"
8
+ },
9
+ "type": "module",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": ["dist"],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "test": "tsc -p tsconfig.json && node --test test/sdk.test.mjs",
22
+ "pack": "pnpm build && pnpm pack"
23
+ },
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "5.9.3"
29
+ }
30
+ }