web-extend-plugin-vue2 0.2.1 → 0.2.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.
package/index.d.ts ADDED
@@ -0,0 +1,246 @@
1
+ /**
2
+ * 公共 API 的 TypeScript 声明;IDE 补全以本文件为准。
3
+ */
4
+
5
+ /** 清单侧路由声明(PRD),需配合 `adaptRouteDeclarations` */
6
+ export type RouteDeclaration = {
7
+ path: string
8
+ name?: string
9
+ title?: string
10
+ meta?: Record<string, unknown>
11
+ children?: RouteDeclaration[]
12
+ /** 由宿主在 `adaptRouteDeclarations` 中解析为 Vue 组件 */
13
+ componentRef: string
14
+ }
15
+
16
+ /** `bootstrapPlugins` 调用 `activator` 时的第二参数 */
17
+ export type PluginActivateContext = {
18
+ /** 清单条目的浅拷贝且已 `Object.freeze`,请勿就地修改嵌套对象 */
19
+ pluginRecord: Readonly<Record<string, unknown>>
20
+ }
21
+
22
+ /**
23
+ * 与 `vue-router` RouteConfig 兼容的宽松对象形态(未安装 vue 类型时仍可用)。
24
+ * 安装 `vue` / `vue-router` 类型后可在业务代码中收窄。
25
+ */
26
+ export type VueRouteConfig = Record<string, unknown>
27
+
28
+ /** 在合成 `name` / `meta.pluginId` 之前转换插件提交的 `RouteConfig` */
29
+ export type TransformRoutesFn = (ctx: {
30
+ pluginId: string
31
+ router: unknown
32
+ routes: ReadonlyArray<VueRouteConfig>
33
+ }) => VueRouteConfig[]
34
+
35
+ /** 接管路由注册;由宿主决定是否调用 `applyInternalRegister` */
36
+ export type InterceptRegisterRoutesFn = (ctx: {
37
+ pluginId: string
38
+ router: unknown
39
+ routes: ReadonlyArray<VueRouteConfig>
40
+ /** 与默认 `registerRoutes` 相同的包装 + `addRoute` / `addRoutes` */
41
+ applyInternalRegister: (routes: VueRouteConfig[]) => void
42
+ }) => void
43
+
44
+ /** PRD → `RouteConfig` */
45
+ export type AdaptRouteDeclarationsFn = (ctx: {
46
+ pluginId: string
47
+ router: unknown
48
+ declarations: ReadonlyArray<RouteDeclaration>
49
+ }) => VueRouteConfig[]
50
+
51
+ /** 宿主传入 `createHostApi` 的 `hostKit`(及 `resolveRuntimeOptions` 中同类字段) */
52
+ export type HostKitOptions = {
53
+ /** `getBridge().request` 允许的URL路径前缀,须以 `/` 开头 */
54
+ bridgeAllowedPathPrefixes?: string[]
55
+ /** 非空时子路由挂到该命名父路由下(需 vue-router ≥3.5 的 `addRoute`) */
56
+ pluginRoutesParentName?: string
57
+ transformRoutes?: TransformRoutesFn
58
+ interceptRegisterRoutes?: InterceptRegisterRoutesFn
59
+ adaptRouteDeclarations?: AdaptRouteDeclarationsFn
60
+ }
61
+
62
+ /** `resolveRuntimeOptions` 全量运行时选项(在默认字段基础上的扩展;未列字段见 README) */
63
+ export type WebExtendPluginRuntimeOptions = HostKitOptions &
64
+ Record<string, unknown> & {
65
+ manifestBase?: string
66
+ manifestListPath?: string
67
+ manifestFetchCredentials?: RequestCredentials
68
+ isDev?: boolean
69
+ webPluginDevOrigin?: string
70
+ webPluginDevIds?: string
71
+ webPluginDevMapJson?: string
72
+ webPluginDevEntryPath?: string
73
+ devPingPath?: string
74
+ devReloadSsePath?: string
75
+ devPingTimeoutMs?: number
76
+ defaultImplicitDevPluginIds?: string[]
77
+ allowedScriptHosts?: string[]
78
+ bootstrapSummary?: boolean
79
+ fetchManifest?: ManifestFetchFn
80
+ }
81
+
82
+ /** 插件 `activator` 收到的宿主 API */
83
+ export interface HostApi {
84
+ /** 宿主实现的 Host API 协议版本,与清单 `hostPluginApiVersion` 对齐 */
85
+ readonly hostPluginApiVersion: string
86
+ /**
87
+ * 动态注册路由。含 PRD 时使用 `componentRef` 树;否则传入 `RouteConfig` 数组。
88
+ * 流水线:`adaptRouteDeclarations` → `transformRoutes` → `interceptRegisterRoutes` 或默认注册。
89
+ */
90
+ registerRoutes(routes: VueRouteConfig[] | RouteDeclaration[]): void
91
+ /** 写入全局菜单注册表,按 `order` 升序 */
92
+ registerMenuItems(items: Record<string, unknown>[]): void
93
+ registerSlotComponents(
94
+ pointId: string,
95
+ components: Array<{ component: unknown; priority?: number }>
96
+ ): void
97
+ registerStylesheetUrls(urls?: string[]): void
98
+ registerScriptUrls(urls?: string[]): void
99
+ registerSanitizedHtmlSnippet(): void
100
+ getBridge(): {
101
+ request(path: string, init?: RequestInit): Promise<Response>
102
+ }
103
+ onTeardown(_pluginId: string, fn: () => void): void
104
+ }
105
+
106
+ export type ManifestFetchContext = { manifestUrl: string; credentials: RequestCredentials }
107
+
108
+ export type ManifestFetchResult = {
109
+ ok: boolean
110
+ status?: number
111
+ data?: unknown
112
+ error?: unknown
113
+ }
114
+
115
+ export type ManifestFetchFn = (ctx: ManifestFetchContext) => Promise<ManifestFetchResult>
116
+
117
+ export type ManifestFetchCacheOptions = {
118
+ ttlMs?: number
119
+ storage?: 'memory' | 'session' | 'local'
120
+ storageKeyPrefix?: string
121
+ cacheKey?: (ctx: ManifestFetchContext) => string
122
+ shouldCache?: (result: ManifestFetchResult) => boolean
123
+ maxEntries?: number
124
+ now?: () => number
125
+ }
126
+
127
+ /** 命名空间聚合对象,按领域分组 */
128
+ export const WebExtendPluginVue2: Readonly<{
129
+ install: (Vue: unknown, router: unknown, options?: WebExtendPluginRuntimeOptions) => Promise<void>
130
+ runtime: Readonly<{
131
+ /** 拉取清单并依次 `activator(hostApi, { pluginRecord })` */
132
+ bootstrapPlugins: (
133
+ router: unknown,
134
+ createHostApiFactory: (id: string, r: unknown, kit?: HostKitOptions) => HostApi,
135
+ runtimeOptions?: WebExtendPluginRuntimeOptions
136
+ ) => Promise<void>
137
+ resolveRuntimeOptions: (user?: WebExtendPluginRuntimeOptions) => WebExtendPluginRuntimeOptions
138
+ defaultFetchWebPluginManifest: (ctx: {
139
+ manifestUrl: string
140
+ credentials: RequestCredentials
141
+ }) => Promise<{ ok: boolean; status?: number; data?: unknown; error?: unknown }>
142
+ composeManifestFetch: (
143
+ inner: ManifestFetchFn,
144
+ ...middlewares: Array<(next: ManifestFetchFn) => ManifestFetchFn>
145
+ ) => ManifestFetchFn
146
+ manifestFetchCacheMiddleware: (options?: ManifestFetchCacheOptions) => (next: ManifestFetchFn) => ManifestFetchFn
147
+ wrapManifestFetchWithCache: (inner: ManifestFetchFn, options?: ManifestFetchCacheOptions) => ManifestFetchFn
148
+ }>
149
+ host: Readonly<{
150
+ createHostApi: (pluginId: string, router: unknown, hostKit?: HostKitOptions) => HostApi
151
+ disposeWebPlugin: (pluginId: string) => void
152
+ createRequestBridge: (config?: { allowedPathPrefixes?: string[] }) => {
153
+ request: (path: string, init?: RequestInit) => Promise<Response>
154
+ }
155
+ registries: unknown
156
+ }>
157
+ config: Readonly<{
158
+ defaultWebExtendPluginRuntime: Record<string, unknown>
159
+ setWebExtendPluginEnv: (env: Record<string, unknown> | null | undefined) => void
160
+ }>
161
+ constants: Readonly<{ HOST_PLUGIN_API_VERSION: string; RUNTIME_CONSOLE_LABEL: string }>
162
+ components: Readonly<{ ExtensionPoint: unknown }>
163
+ presets: Readonly<{
164
+ vueCliAxios: Readonly<{
165
+ id: string
166
+ description: string
167
+ createInstallOptions: (
168
+ deps: { request: (config: Record<string, unknown>) => Promise<unknown> },
169
+ extra?: Record<string, unknown>
170
+ ) => Record<string, unknown>
171
+ manifestPathForApiBase: (manifestUrl: string, apiBase?: string) => string
172
+ unwrapManifestBody: (body: unknown) => object | null
173
+ }>
174
+ }>
175
+ }>
176
+
177
+ export const defaultWebExtendPluginRuntime: Record<string, unknown>
178
+
179
+ /** 拉取清单并依次激活插件;浏览器环境执行 */
180
+ export function bootstrapPlugins(
181
+ router: unknown,
182
+ createHostApiFactory: (id: string, r: unknown, kit?: HostKitOptions) => HostApi,
183
+ runtimeOptions?: WebExtendPluginRuntimeOptions
184
+ ): Promise<void>
185
+
186
+ /** 合并默认配置、环境变量与显式传入字段 */
187
+ export function resolveRuntimeOptions(user?: WebExtendPluginRuntimeOptions): WebExtendPluginRuntimeOptions
188
+
189
+ export function defaultFetchWebPluginManifest(ctx: {
190
+ manifestUrl: string
191
+ credentials: RequestCredentials
192
+ }): Promise<{ ok: boolean; status?: number; data?: unknown; error?: unknown }>
193
+
194
+ /** 构造单个插件在宿主侧的 `hostApi`,供 `activator(hostApi, context)` 使用 */
195
+ export function createHostApi(pluginId: string, router: unknown, hostKit?: HostKitOptions): HostApi
196
+
197
+ export function disposeWebPlugin(pluginId: string): void
198
+ export const registries: unknown
199
+
200
+ export function createRequestBridge(config?: {
201
+ allowedPathPrefixes?: string[]
202
+ }): { request: (path: string, init?: RequestInit) => Promise<Response> }
203
+
204
+ export const HOST_PLUGIN_API_VERSION: string
205
+ /** 控制台日志前缀用的短名称 */
206
+ export const RUNTIME_CONSOLE_LABEL: string
207
+ export function setWebExtendPluginEnv(env: Record<string, unknown> | null | undefined): void
208
+
209
+ /** 注册全局 `ExtensionPoint` 并异步 `bootstrapPlugins` */
210
+ export function installWebExtendPluginVue2(
211
+ Vue: unknown,
212
+ router: unknown,
213
+ options?: WebExtendPluginRuntimeOptions
214
+ ): Promise<void>
215
+
216
+ export const ExtensionPoint: unknown
217
+
218
+ export function createVueCliAxiosInstallOptions(
219
+ deps: { request: (config: Record<string, unknown>) => Promise<unknown> },
220
+ extra?: Record<string, unknown>
221
+ ): Record<string, unknown>
222
+ /** 将完整 manifest URL 转为相对 axios `baseURL` 的请求路径 */
223
+ export function resolveManifestPathUnderApiBase(manifestUrl: string, apiBase?: string): string
224
+ /** 解包裸清单或与 `{ data: { plugins } }` 包装的响应体 */
225
+ export function unwrapNestedManifestBody(body: unknown): object | null
226
+ export const presetVueCliAxios: Readonly<{
227
+ id: string
228
+ description: string
229
+ createInstallOptions: typeof createVueCliAxiosInstallOptions
230
+ manifestPathForApiBase: typeof resolveManifestPathUnderApiBase
231
+ unwrapManifestBody: typeof unwrapNestedManifestBody
232
+ }>
233
+
234
+ export function composeManifestFetch(
235
+ inner: ManifestFetchFn,
236
+ ...middlewares: Array<(next: ManifestFetchFn) => ManifestFetchFn>
237
+ ): ManifestFetchFn
238
+
239
+ export function manifestFetchCacheMiddleware(
240
+ options?: ManifestFetchCacheOptions
241
+ ): (next: ManifestFetchFn) => ManifestFetchFn
242
+
243
+ export function wrapManifestFetchWithCache(
244
+ inner: ManifestFetchFn,
245
+ options?: ManifestFetchCacheOptions
246
+ ): ManifestFetchFn
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "web-extend-plugin-vue2",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "Vue 2 host runtime for web-extend-plugin: manifest bootstrap, hostApi, registries, ExtensionPoint",
8
8
  "type": "module",
9
9
  "main": "./dist/index.cjs",
10
+ "types": "./index.d.ts",
10
11
  "exports": {
11
12
  ".": {
13
+ "types": "./index.d.ts",
12
14
  "import": "./dist/index.mjs",
13
15
  "require": "./dist/index.cjs",
14
16
  "default": "./dist/index.cjs"
15
17
  }
16
18
  },
17
19
  "files": [
18
- "dist"
20
+ "dist",
21
+ "index.d.ts"
19
22
  ],
20
23
  "peerDependencies": {
21
24
  "vue": ">=2.6.14 <3.0.0",