@djvlc/runtime-core 1.0.3 → 1.1.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +175 -30
- package/dist/index.d.ts +175 -30
- package/dist/index.js +1 -1
- package/package.json +1 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _djvlc_contracts_types from '@djvlc/contracts-types';
|
|
2
|
-
import { ExpressionContext, Expression, ExpressionValidationResult, ActionRef, EventHandler, HostApi, NavigateOptions, TrackEvent,
|
|
2
|
+
import { ExpressionContext, Expression, ExpressionValidationResult, ActionRef, EventHandler, PageResolveResponse, ActionResult, HostApi, NavigateOptions, TrackEvent, DialogOptions, DialogResult, ToastOptions, ClipboardApi, StorageApi, ShareOptions, ShareResult, ConfirmOptions, ActionSheetOptions, ActionSheetResult, PreviewImageOptions, ScanCodeResult, ComponentContext, ErrorCode, ManifestItem, PageManifest, CapabilityName, PageSchema, PageLifecycle } from '@djvlc/contracts-types';
|
|
3
3
|
export { ActionExecuteRequest, ActionExecuteResponse, ActionPolicy, ActionRef, ActionResult, AnyValueOrExpression, BlockedComponentInfo, BuiltinActionType, CapabilityDeclaration, CompatInfo, ComponentContext, ComponentMeta, ComponentNode, DataBinding, DataLoadStrategy, DataQueryRequest, DataQueryResponse, DialogOptions, DialogResult, ErrorCode, ErrorMessages, EventDeclaration, EventHandler, Expression, ExpressionContext, ExpressionLocal, ExpressionMeta, ExpressionType, ExpressionValidationResult, HostApi as HostAPI, HostApi, JsonValue, LayoutConfig, LayoutValues, LoopConfig, ManifestItem, NavigateOptions, NodeStyleConfig, PageConfig, PageLifecycle, PageManifest, PageMeta, PageSEO, PageSchema, PageState, PropDefinition, PropsSchema, RuntimeSpec, SchemaVersion, SemVer, StateFieldDefinition, ToastOptions, TrackEvent, UniqueId } from '@djvlc/contracts-types';
|
|
4
|
+
import { UserClientConfig } from '@djvlc/openapi-user-client';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 运行时初始化选项
|
|
@@ -841,6 +842,139 @@ declare class ActionBridge {
|
|
|
841
842
|
private log;
|
|
842
843
|
}
|
|
843
844
|
|
|
845
|
+
/**
|
|
846
|
+
* User API 适配器接口
|
|
847
|
+
* 统一 Runtime 与 User API 的交互:页面解析、动作执行、数据查询、埋点
|
|
848
|
+
* 认证、请求头、重试等逻辑由实现类统一处理,便于测试与切换实现(如 openapi-user-client)
|
|
849
|
+
*/
|
|
850
|
+
|
|
851
|
+
/** 页面解析入参 */
|
|
852
|
+
interface ResolvePageParams {
|
|
853
|
+
pageId: string;
|
|
854
|
+
uid?: string;
|
|
855
|
+
deviceId?: string;
|
|
856
|
+
env?: 'preview' | 'staging' | 'prod';
|
|
857
|
+
channel?: string;
|
|
858
|
+
previewToken?: string;
|
|
859
|
+
}
|
|
860
|
+
/** 动作执行入参 */
|
|
861
|
+
interface ExecuteActionParams {
|
|
862
|
+
actionType: string;
|
|
863
|
+
params: Record<string, unknown>;
|
|
864
|
+
context: {
|
|
865
|
+
pageVersionId: string;
|
|
866
|
+
uid?: string;
|
|
867
|
+
deviceId?: string;
|
|
868
|
+
channel?: string;
|
|
869
|
+
appId: string;
|
|
870
|
+
};
|
|
871
|
+
idempotencyKey: string;
|
|
872
|
+
}
|
|
873
|
+
/** 数据查询入参 */
|
|
874
|
+
interface ExecuteQueryParams {
|
|
875
|
+
queryVersionId: string;
|
|
876
|
+
params?: Record<string, unknown>;
|
|
877
|
+
context: {
|
|
878
|
+
pageVersionId: string;
|
|
879
|
+
uid?: string;
|
|
880
|
+
deviceId?: string;
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
/** 数据查询出参(与 User API /data/query 一致) */
|
|
884
|
+
interface ExecuteQueryResult {
|
|
885
|
+
success: boolean;
|
|
886
|
+
data?: unknown;
|
|
887
|
+
message?: string;
|
|
888
|
+
errorMessage?: string;
|
|
889
|
+
}
|
|
890
|
+
/** 埋点 payload(与 User API /track 一致) */
|
|
891
|
+
interface TrackPayload {
|
|
892
|
+
eventName: string;
|
|
893
|
+
params?: Record<string, unknown>;
|
|
894
|
+
type?: string;
|
|
895
|
+
timestamp?: number;
|
|
896
|
+
context: {
|
|
897
|
+
pageVersionId: string;
|
|
898
|
+
runtimeVersion: string;
|
|
899
|
+
userId?: string;
|
|
900
|
+
deviceId?: string;
|
|
901
|
+
channel?: string;
|
|
902
|
+
appId: string;
|
|
903
|
+
env: string;
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* User API 适配器
|
|
908
|
+
* 只约定入参/出参,不绑定具体 HTTP 库;由 Runtime 注入实现,单测可注入 Mock
|
|
909
|
+
*/
|
|
910
|
+
interface UserApiAdapter {
|
|
911
|
+
/** 页面解析 GET /page/resolve */
|
|
912
|
+
resolvePage(params: ResolvePageParams): Promise<PageResolveResponse>;
|
|
913
|
+
/** 动作执行 POST /actions/execute */
|
|
914
|
+
executeAction<T = unknown>(params: ExecuteActionParams): Promise<ActionResult<T>>;
|
|
915
|
+
/** 数据查询 POST /data/query */
|
|
916
|
+
executeQuery(params: ExecuteQueryParams): Promise<ExecuteQueryResult>;
|
|
917
|
+
/** 埋点 POST /track(可异步、不阻塞) */
|
|
918
|
+
track(payload: TrackPayload): void;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* 基于 @djvlc/openapi-user-client 的 User API 适配器
|
|
923
|
+
* 统一认证、请求头、重试等逻辑,不直接使用 fetch
|
|
924
|
+
*/
|
|
925
|
+
|
|
926
|
+
type OpenApiUserAdapterOptions = UserClientConfig;
|
|
927
|
+
/**
|
|
928
|
+
* 基于 openapi-user-client 的 User API 适配器实现
|
|
929
|
+
* Runtime 与 User API 的交互仅通过此适配器
|
|
930
|
+
*/
|
|
931
|
+
declare class OpenApiUserAdapter implements UserApiAdapter {
|
|
932
|
+
private readonly client;
|
|
933
|
+
constructor(options?: OpenApiUserAdapterOptions);
|
|
934
|
+
resolvePage(params: ResolvePageParams): Promise<PageResolveResponse>;
|
|
935
|
+
executeAction<T = unknown>(params: ExecuteActionParams): Promise<ActionResult<T>>;
|
|
936
|
+
executeQuery(params: ExecuteQueryParams): Promise<ExecuteQueryResult>;
|
|
937
|
+
track(payload: TrackPayload): void;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* 测试用 User API 适配器 Mock
|
|
942
|
+
* 单测中注入,不再 mock global.fetch
|
|
943
|
+
*/
|
|
944
|
+
|
|
945
|
+
interface MockUserApiAdapterOptions {
|
|
946
|
+
/** resolvePage 返回值(可覆盖) */
|
|
947
|
+
resolvePageResponse?: PageResolveResponse;
|
|
948
|
+
/** executeAction 返回值(可覆盖) */
|
|
949
|
+
executeActionResponse?: ActionResult<unknown>;
|
|
950
|
+
/** executeQuery 返回值(可覆盖) */
|
|
951
|
+
executeQueryResponse?: ExecuteQueryResult;
|
|
952
|
+
/** 是否在 resolve 时抛错 */
|
|
953
|
+
resolvePageThrow?: Error;
|
|
954
|
+
/** 是否在 executeAction 时抛错 */
|
|
955
|
+
executeActionThrow?: Error;
|
|
956
|
+
/** 是否在 executeQuery 时抛错 */
|
|
957
|
+
executeQueryThrow?: Error;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* 测试用 Mock 实现
|
|
961
|
+
* 记录调用次数与参数,返回可配置的默认值或自定义值
|
|
962
|
+
*/
|
|
963
|
+
declare class MockUserApiAdapter implements UserApiAdapter {
|
|
964
|
+
private readonly options;
|
|
965
|
+
readonly calls: {
|
|
966
|
+
resolvePage: ResolvePageParams[];
|
|
967
|
+
executeAction: ExecuteActionParams[];
|
|
968
|
+
executeQuery: ExecuteQueryParams[];
|
|
969
|
+
track: TrackPayload[];
|
|
970
|
+
};
|
|
971
|
+
constructor(options?: MockUserApiAdapterOptions);
|
|
972
|
+
resolvePage(params: ResolvePageParams): Promise<PageResolveResponse>;
|
|
973
|
+
executeAction<T = unknown>(params: ExecuteActionParams): Promise<ActionResult<T>>;
|
|
974
|
+
executeQuery(params: ExecuteQueryParams): Promise<ExecuteQueryResult>;
|
|
975
|
+
track(payload: TrackPayload): void;
|
|
976
|
+
}
|
|
977
|
+
|
|
844
978
|
/**
|
|
845
979
|
* Host API 实现
|
|
846
980
|
* 提供给组件的安全 API,完全对齐 @djvlc/contracts-types 中的 HostApi 定义
|
|
@@ -871,12 +1005,8 @@ interface RuntimeContext {
|
|
|
871
1005
|
* Host API 配置
|
|
872
1006
|
*/
|
|
873
1007
|
interface HostAPIOptions {
|
|
874
|
-
/** API
|
|
875
|
-
|
|
876
|
-
/** 认证 Token */
|
|
877
|
-
authToken?: string;
|
|
878
|
-
/** 请求头 */
|
|
879
|
-
headers?: Record<string, string>;
|
|
1008
|
+
/** User API 适配器(必填,仅通过适配器调用 User API) */
|
|
1009
|
+
userApiAdapter: UserApiAdapter;
|
|
880
1010
|
/** 状态管理器 */
|
|
881
1011
|
stateManager: StateManager;
|
|
882
1012
|
/** 事件总线 */
|
|
@@ -919,7 +1049,6 @@ declare class HostAPIImpl implements HostApi {
|
|
|
919
1049
|
getState<T = unknown>(path: string): T | undefined;
|
|
920
1050
|
setState(path: string, value: unknown): void;
|
|
921
1051
|
getContext(): ComponentContext;
|
|
922
|
-
private buildHeaders;
|
|
923
1052
|
private generateIdempotencyKey;
|
|
924
1053
|
private simpleHash;
|
|
925
1054
|
private fallbackCopy;
|
|
@@ -965,6 +1094,8 @@ declare class DjvlcRuntime {
|
|
|
965
1094
|
private renderer;
|
|
966
1095
|
private hostApi;
|
|
967
1096
|
private lifecycleManager;
|
|
1097
|
+
/** User API 适配器,统一认证/请求头,供 PageLoader 与 HostAPIImpl 使用 */
|
|
1098
|
+
private userApiAdapter;
|
|
968
1099
|
private logger;
|
|
969
1100
|
constructor(options: RuntimeOptions);
|
|
970
1101
|
/**
|
|
@@ -1141,17 +1272,17 @@ declare class RenderError extends DjvlcRuntimeError {
|
|
|
1141
1272
|
* 页面加载器配置
|
|
1142
1273
|
*/
|
|
1143
1274
|
interface PageLoaderOptions {
|
|
1144
|
-
/** API 基础 URL */
|
|
1275
|
+
/** API 基础 URL(用于 preconnect、CDN 请求头) */
|
|
1145
1276
|
apiBaseUrl: string;
|
|
1277
|
+
/** User API 适配器(必填,仅通过适配器调用 User API) */
|
|
1278
|
+
userApiAdapter: UserApiAdapter;
|
|
1146
1279
|
/** 环境 */
|
|
1147
1280
|
env?: 'preview' | 'staging' | 'prod';
|
|
1148
1281
|
/** 渠道 */
|
|
1149
1282
|
channel?: string;
|
|
1150
|
-
/** 认证 Token */
|
|
1151
|
-
authToken?: string;
|
|
1152
1283
|
/** 预览 Token */
|
|
1153
1284
|
previewToken?: string;
|
|
1154
|
-
/**
|
|
1285
|
+
/** 请求头(CDN 请求用) */
|
|
1155
1286
|
headers?: Record<string, string>;
|
|
1156
1287
|
/** 缓存配置 */
|
|
1157
1288
|
cache?: {
|
|
@@ -1180,10 +1311,9 @@ declare class PageLoader {
|
|
|
1180
1311
|
deviceId?: string;
|
|
1181
1312
|
}): Promise<PageResolveResult>;
|
|
1182
1313
|
/**
|
|
1183
|
-
*
|
|
1184
|
-
* 严格按照 contracts 中的 PageResolveRequest 和 PageResolveResponse
|
|
1314
|
+
* 通过 User API 适配器调用 resolve
|
|
1185
1315
|
*/
|
|
1186
|
-
private
|
|
1316
|
+
private callResolveViaAdapter;
|
|
1187
1317
|
/**
|
|
1188
1318
|
* 从 CDN 加载 snapshot 和 manifest
|
|
1189
1319
|
*/
|
|
@@ -1222,29 +1352,34 @@ declare class PageLoader {
|
|
|
1222
1352
|
|
|
1223
1353
|
/**
|
|
1224
1354
|
* 组件加载器
|
|
1225
|
-
* 负责从 CDN
|
|
1355
|
+
* 负责从 CDN 动态加载 Web Components,支持 SRI 完整性校验、组件阻断、并行加载与降级处理。
|
|
1356
|
+
* @see SKILL: runtime-component-loading
|
|
1226
1357
|
*/
|
|
1227
1358
|
|
|
1228
1359
|
/**
|
|
1229
1360
|
* 组件加载器配置
|
|
1230
1361
|
*/
|
|
1231
1362
|
interface ComponentLoaderOptions {
|
|
1232
|
-
/** CDN 基础 URL */
|
|
1363
|
+
/** CDN 基础 URL,用于解析相对 entry 路径 */
|
|
1233
1364
|
cdnBaseUrl: string;
|
|
1234
|
-
/** 是否启用 SRI
|
|
1365
|
+
/** 是否启用 SRI 完整性校验,默认 true */
|
|
1235
1366
|
enableSRI?: boolean;
|
|
1236
|
-
/**
|
|
1367
|
+
/** 被阻断的组件列表(如 `['comp@1.0.0']` 或仅组件名 `['comp']`),用于紧急止血 */
|
|
1237
1368
|
blockedComponents?: string[];
|
|
1238
|
-
/**
|
|
1369
|
+
/** 并行加载数量,默认 4 */
|
|
1239
1370
|
concurrency?: number;
|
|
1240
|
-
/**
|
|
1371
|
+
/** 单次请求超时(毫秒),默认 30000 */
|
|
1241
1372
|
timeout?: number;
|
|
1373
|
+
/** 请求 CDN 时附加的请求头(如认证等) */
|
|
1374
|
+
headers?: Record<string, string>;
|
|
1375
|
+
/** 自定义拉取脚本的实现,不传则使用全局 fetch;测试或自定义 CDN 客户端时注入 */
|
|
1376
|
+
fetchComponentScript?: (url: string, init?: RequestInit) => Promise<Response>;
|
|
1242
1377
|
/** 日志器 */
|
|
1243
1378
|
logger?: Logger;
|
|
1244
1379
|
}
|
|
1245
1380
|
/**
|
|
1246
1381
|
* 组件加载器
|
|
1247
|
-
*
|
|
1382
|
+
* 负责从 CDN 加载 Web Components,支持缓存、阻断、SRI 校验与并行加载。
|
|
1248
1383
|
*/
|
|
1249
1384
|
declare class ComponentLoader {
|
|
1250
1385
|
private options;
|
|
@@ -1253,37 +1388,47 @@ declare class ComponentLoader {
|
|
|
1253
1388
|
private blockedSet;
|
|
1254
1389
|
constructor(options: ComponentLoaderOptions);
|
|
1255
1390
|
/**
|
|
1256
|
-
*
|
|
1391
|
+
* 加载单个组件(按 name@version 去重,同一组件并发请求复用同一 Promise)
|
|
1392
|
+
* @param item - 清单项(name、version、entry、integrity 等)
|
|
1393
|
+
* @returns 已加载的组件信息(含 Component 构造函数)
|
|
1394
|
+
* @throws ComponentBlockedError 当组件在阻断列表中
|
|
1395
|
+
* @throws ComponentLoadError 当拉取或执行失败
|
|
1396
|
+
* @throws IntegrityError 当 SRI 校验失败
|
|
1257
1397
|
*/
|
|
1258
1398
|
load(item: ManifestItem): Promise<LoadedComponent>;
|
|
1259
1399
|
/**
|
|
1260
|
-
*
|
|
1400
|
+
* 按 manifest 批量加载组件,按 concurrency 分批并行;关键组件失败会抛出,非关键组件记录失败。
|
|
1401
|
+
* @param manifest - 页面清单(含 components 数组)
|
|
1402
|
+
* @returns 以 name@version 为 key 的加载结果 Map(status: loaded | failed | blocked)
|
|
1261
1403
|
*/
|
|
1262
1404
|
loadAll(manifest: PageManifest): Promise<Map<string, ComponentLoadResult>>;
|
|
1263
1405
|
/**
|
|
1264
|
-
*
|
|
1406
|
+
* 预加载组件:向 document.head 插入 <link rel="preload" as="script">,仅作提示,不阻塞 load。
|
|
1407
|
+
* @param items - 需要预加载的清单项
|
|
1265
1408
|
*/
|
|
1266
1409
|
preload(items: ManifestItem[]): void;
|
|
1267
1410
|
/**
|
|
1268
|
-
*
|
|
1411
|
+
* 检查指定 name@version 的组件是否已加载并缓存
|
|
1269
1412
|
*/
|
|
1270
1413
|
isLoaded(name: string, version: string): boolean;
|
|
1271
1414
|
/**
|
|
1272
|
-
*
|
|
1415
|
+
* 获取已加载的组件信息,未加载则返回 undefined
|
|
1273
1416
|
*/
|
|
1274
1417
|
get(name: string, version: string): LoadedComponent | undefined;
|
|
1275
1418
|
/**
|
|
1276
|
-
*
|
|
1419
|
+
* 检查组件是否在阻断列表中(支持 `name@version` 或仅 `name`)
|
|
1277
1420
|
*/
|
|
1278
1421
|
isBlocked(name: string, version: string): boolean;
|
|
1279
1422
|
/**
|
|
1280
|
-
*
|
|
1423
|
+
* 更新阻断列表(会完全替换当前列表)
|
|
1281
1424
|
*/
|
|
1282
1425
|
updateBlockedList(blocked: string[]): void;
|
|
1283
1426
|
private loadComponent;
|
|
1284
1427
|
private fetchWithTimeout;
|
|
1285
1428
|
private validateIntegrity;
|
|
1286
1429
|
private executeScript;
|
|
1430
|
+
/** kebab-case -> PascalCase,用于匹配组件命名导出 */
|
|
1431
|
+
private kebabToPascal;
|
|
1287
1432
|
private resolveUrl;
|
|
1288
1433
|
private getComponentKey;
|
|
1289
1434
|
private log;
|
|
@@ -2040,4 +2185,4 @@ declare class LifecycleManager {
|
|
|
2040
2185
|
*/
|
|
2041
2186
|
declare const RUNTIME_VERSION = "1.0.0";
|
|
2042
2187
|
|
|
2043
|
-
export { type ASTNode, ActionBridge, type ActionBridgeOptions, ActionError, type ActionExecutor, AssetLoader, type AssetLoaderOptions, BaseRenderer, type BaseRendererOptions, ComponentBlockedError, ComponentLoadError, type ComponentLoadResult, type ComponentLoadStatus, ComponentLoader, type ComponentLoaderOptions, DjvlcRuntime, DjvlcRuntimeError, type EvaluationResult, Evaluator, type EvaluatorOptions, EventBus, type EventBusOptions, type EventHandlerFn, ExpressionEngine, type ExpressionEngineOptions, ExpressionError, HostAPIImpl, type HostAPIOptions, IntegrityError, Lexer, type LifecycleEventType, LifecycleManager, type LifecycleManagerOptions, type LoadedComponent, type LogLevel, type Logger, type MetricType, PageLoadError, PageLoader, type PageLoaderOptions, type PageResolveResult, Parser, type PerformanceMetric, QueryError, RUNTIME_VERSION, RenderError, type Renderer, type RuntimeError, type RuntimeErrorType, type RuntimeEvent, type RuntimeEventType, type RuntimeOptions, type RuntimePhase, type RuntimeState, SUPPORTED_SCHEMA_VERSION as SCHEMA_VERSION, SUPPORTED_SCHEMA_VERSION, SecurityManager, type SecurityManagerOptions, type Span, type StateListener, StateManager, TelemetryManager, type TelemetryManagerOptions, type Token, type TokenType, type Unsubscribe, builtinFunctions, createFallbackElement, createRuntime, registerFallbackComponents };
|
|
2188
|
+
export { type ASTNode, ActionBridge, type ActionBridgeOptions, ActionError, type ActionExecutor, AssetLoader, type AssetLoaderOptions, BaseRenderer, type BaseRendererOptions, ComponentBlockedError, ComponentLoadError, type ComponentLoadResult, type ComponentLoadStatus, ComponentLoader, type ComponentLoaderOptions, DjvlcRuntime, DjvlcRuntimeError, type EvaluationResult, Evaluator, type EvaluatorOptions, EventBus, type EventBusOptions, type EventHandlerFn, type ExecuteActionParams, type ExecuteQueryParams, type ExecuteQueryResult, ExpressionEngine, type ExpressionEngineOptions, ExpressionError, HostAPIImpl, type HostAPIOptions, IntegrityError, Lexer, type LifecycleEventType, LifecycleManager, type LifecycleManagerOptions, type LoadedComponent, type LogLevel, type Logger, type MetricType, MockUserApiAdapter, type MockUserApiAdapterOptions, OpenApiUserAdapter, type OpenApiUserAdapterOptions, PageLoadError, PageLoader, type PageLoaderOptions, type PageResolveResult, Parser, type PerformanceMetric, QueryError, RUNTIME_VERSION, RenderError, type Renderer, type ResolvePageParams, type RuntimeContext, type RuntimeError, type RuntimeErrorType, type RuntimeEvent, type RuntimeEventType, type RuntimeOptions, type RuntimePhase, type RuntimeState, SUPPORTED_SCHEMA_VERSION as SCHEMA_VERSION, SUPPORTED_SCHEMA_VERSION, SecurityManager, type SecurityManagerOptions, type Span, type StateListener, StateManager, TelemetryManager, type TelemetryManagerOptions, type Token, type TokenType, type TrackPayload, type Unsubscribe, type UserApiAdapter, builtinFunctions, createFallbackElement, createRuntime, registerFallbackComponents };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as _djvlc_contracts_types from '@djvlc/contracts-types';
|
|
2
|
-
import { ExpressionContext, Expression, ExpressionValidationResult, ActionRef, EventHandler, HostApi, NavigateOptions, TrackEvent,
|
|
2
|
+
import { ExpressionContext, Expression, ExpressionValidationResult, ActionRef, EventHandler, PageResolveResponse, ActionResult, HostApi, NavigateOptions, TrackEvent, DialogOptions, DialogResult, ToastOptions, ClipboardApi, StorageApi, ShareOptions, ShareResult, ConfirmOptions, ActionSheetOptions, ActionSheetResult, PreviewImageOptions, ScanCodeResult, ComponentContext, ErrorCode, ManifestItem, PageManifest, CapabilityName, PageSchema, PageLifecycle } from '@djvlc/contracts-types';
|
|
3
3
|
export { ActionExecuteRequest, ActionExecuteResponse, ActionPolicy, ActionRef, ActionResult, AnyValueOrExpression, BlockedComponentInfo, BuiltinActionType, CapabilityDeclaration, CompatInfo, ComponentContext, ComponentMeta, ComponentNode, DataBinding, DataLoadStrategy, DataQueryRequest, DataQueryResponse, DialogOptions, DialogResult, ErrorCode, ErrorMessages, EventDeclaration, EventHandler, Expression, ExpressionContext, ExpressionLocal, ExpressionMeta, ExpressionType, ExpressionValidationResult, HostApi as HostAPI, HostApi, JsonValue, LayoutConfig, LayoutValues, LoopConfig, ManifestItem, NavigateOptions, NodeStyleConfig, PageConfig, PageLifecycle, PageManifest, PageMeta, PageSEO, PageSchema, PageState, PropDefinition, PropsSchema, RuntimeSpec, SchemaVersion, SemVer, StateFieldDefinition, ToastOptions, TrackEvent, UniqueId } from '@djvlc/contracts-types';
|
|
4
|
+
import { UserClientConfig } from '@djvlc/openapi-user-client';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* 运行时初始化选项
|
|
@@ -841,6 +842,139 @@ declare class ActionBridge {
|
|
|
841
842
|
private log;
|
|
842
843
|
}
|
|
843
844
|
|
|
845
|
+
/**
|
|
846
|
+
* User API 适配器接口
|
|
847
|
+
* 统一 Runtime 与 User API 的交互:页面解析、动作执行、数据查询、埋点
|
|
848
|
+
* 认证、请求头、重试等逻辑由实现类统一处理,便于测试与切换实现(如 openapi-user-client)
|
|
849
|
+
*/
|
|
850
|
+
|
|
851
|
+
/** 页面解析入参 */
|
|
852
|
+
interface ResolvePageParams {
|
|
853
|
+
pageId: string;
|
|
854
|
+
uid?: string;
|
|
855
|
+
deviceId?: string;
|
|
856
|
+
env?: 'preview' | 'staging' | 'prod';
|
|
857
|
+
channel?: string;
|
|
858
|
+
previewToken?: string;
|
|
859
|
+
}
|
|
860
|
+
/** 动作执行入参 */
|
|
861
|
+
interface ExecuteActionParams {
|
|
862
|
+
actionType: string;
|
|
863
|
+
params: Record<string, unknown>;
|
|
864
|
+
context: {
|
|
865
|
+
pageVersionId: string;
|
|
866
|
+
uid?: string;
|
|
867
|
+
deviceId?: string;
|
|
868
|
+
channel?: string;
|
|
869
|
+
appId: string;
|
|
870
|
+
};
|
|
871
|
+
idempotencyKey: string;
|
|
872
|
+
}
|
|
873
|
+
/** 数据查询入参 */
|
|
874
|
+
interface ExecuteQueryParams {
|
|
875
|
+
queryVersionId: string;
|
|
876
|
+
params?: Record<string, unknown>;
|
|
877
|
+
context: {
|
|
878
|
+
pageVersionId: string;
|
|
879
|
+
uid?: string;
|
|
880
|
+
deviceId?: string;
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
/** 数据查询出参(与 User API /data/query 一致) */
|
|
884
|
+
interface ExecuteQueryResult {
|
|
885
|
+
success: boolean;
|
|
886
|
+
data?: unknown;
|
|
887
|
+
message?: string;
|
|
888
|
+
errorMessage?: string;
|
|
889
|
+
}
|
|
890
|
+
/** 埋点 payload(与 User API /track 一致) */
|
|
891
|
+
interface TrackPayload {
|
|
892
|
+
eventName: string;
|
|
893
|
+
params?: Record<string, unknown>;
|
|
894
|
+
type?: string;
|
|
895
|
+
timestamp?: number;
|
|
896
|
+
context: {
|
|
897
|
+
pageVersionId: string;
|
|
898
|
+
runtimeVersion: string;
|
|
899
|
+
userId?: string;
|
|
900
|
+
deviceId?: string;
|
|
901
|
+
channel?: string;
|
|
902
|
+
appId: string;
|
|
903
|
+
env: string;
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* User API 适配器
|
|
908
|
+
* 只约定入参/出参,不绑定具体 HTTP 库;由 Runtime 注入实现,单测可注入 Mock
|
|
909
|
+
*/
|
|
910
|
+
interface UserApiAdapter {
|
|
911
|
+
/** 页面解析 GET /page/resolve */
|
|
912
|
+
resolvePage(params: ResolvePageParams): Promise<PageResolveResponse>;
|
|
913
|
+
/** 动作执行 POST /actions/execute */
|
|
914
|
+
executeAction<T = unknown>(params: ExecuteActionParams): Promise<ActionResult<T>>;
|
|
915
|
+
/** 数据查询 POST /data/query */
|
|
916
|
+
executeQuery(params: ExecuteQueryParams): Promise<ExecuteQueryResult>;
|
|
917
|
+
/** 埋点 POST /track(可异步、不阻塞) */
|
|
918
|
+
track(payload: TrackPayload): void;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* 基于 @djvlc/openapi-user-client 的 User API 适配器
|
|
923
|
+
* 统一认证、请求头、重试等逻辑,不直接使用 fetch
|
|
924
|
+
*/
|
|
925
|
+
|
|
926
|
+
type OpenApiUserAdapterOptions = UserClientConfig;
|
|
927
|
+
/**
|
|
928
|
+
* 基于 openapi-user-client 的 User API 适配器实现
|
|
929
|
+
* Runtime 与 User API 的交互仅通过此适配器
|
|
930
|
+
*/
|
|
931
|
+
declare class OpenApiUserAdapter implements UserApiAdapter {
|
|
932
|
+
private readonly client;
|
|
933
|
+
constructor(options?: OpenApiUserAdapterOptions);
|
|
934
|
+
resolvePage(params: ResolvePageParams): Promise<PageResolveResponse>;
|
|
935
|
+
executeAction<T = unknown>(params: ExecuteActionParams): Promise<ActionResult<T>>;
|
|
936
|
+
executeQuery(params: ExecuteQueryParams): Promise<ExecuteQueryResult>;
|
|
937
|
+
track(payload: TrackPayload): void;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* 测试用 User API 适配器 Mock
|
|
942
|
+
* 单测中注入,不再 mock global.fetch
|
|
943
|
+
*/
|
|
944
|
+
|
|
945
|
+
interface MockUserApiAdapterOptions {
|
|
946
|
+
/** resolvePage 返回值(可覆盖) */
|
|
947
|
+
resolvePageResponse?: PageResolveResponse;
|
|
948
|
+
/** executeAction 返回值(可覆盖) */
|
|
949
|
+
executeActionResponse?: ActionResult<unknown>;
|
|
950
|
+
/** executeQuery 返回值(可覆盖) */
|
|
951
|
+
executeQueryResponse?: ExecuteQueryResult;
|
|
952
|
+
/** 是否在 resolve 时抛错 */
|
|
953
|
+
resolvePageThrow?: Error;
|
|
954
|
+
/** 是否在 executeAction 时抛错 */
|
|
955
|
+
executeActionThrow?: Error;
|
|
956
|
+
/** 是否在 executeQuery 时抛错 */
|
|
957
|
+
executeQueryThrow?: Error;
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* 测试用 Mock 实现
|
|
961
|
+
* 记录调用次数与参数,返回可配置的默认值或自定义值
|
|
962
|
+
*/
|
|
963
|
+
declare class MockUserApiAdapter implements UserApiAdapter {
|
|
964
|
+
private readonly options;
|
|
965
|
+
readonly calls: {
|
|
966
|
+
resolvePage: ResolvePageParams[];
|
|
967
|
+
executeAction: ExecuteActionParams[];
|
|
968
|
+
executeQuery: ExecuteQueryParams[];
|
|
969
|
+
track: TrackPayload[];
|
|
970
|
+
};
|
|
971
|
+
constructor(options?: MockUserApiAdapterOptions);
|
|
972
|
+
resolvePage(params: ResolvePageParams): Promise<PageResolveResponse>;
|
|
973
|
+
executeAction<T = unknown>(params: ExecuteActionParams): Promise<ActionResult<T>>;
|
|
974
|
+
executeQuery(params: ExecuteQueryParams): Promise<ExecuteQueryResult>;
|
|
975
|
+
track(payload: TrackPayload): void;
|
|
976
|
+
}
|
|
977
|
+
|
|
844
978
|
/**
|
|
845
979
|
* Host API 实现
|
|
846
980
|
* 提供给组件的安全 API,完全对齐 @djvlc/contracts-types 中的 HostApi 定义
|
|
@@ -871,12 +1005,8 @@ interface RuntimeContext {
|
|
|
871
1005
|
* Host API 配置
|
|
872
1006
|
*/
|
|
873
1007
|
interface HostAPIOptions {
|
|
874
|
-
/** API
|
|
875
|
-
|
|
876
|
-
/** 认证 Token */
|
|
877
|
-
authToken?: string;
|
|
878
|
-
/** 请求头 */
|
|
879
|
-
headers?: Record<string, string>;
|
|
1008
|
+
/** User API 适配器(必填,仅通过适配器调用 User API) */
|
|
1009
|
+
userApiAdapter: UserApiAdapter;
|
|
880
1010
|
/** 状态管理器 */
|
|
881
1011
|
stateManager: StateManager;
|
|
882
1012
|
/** 事件总线 */
|
|
@@ -919,7 +1049,6 @@ declare class HostAPIImpl implements HostApi {
|
|
|
919
1049
|
getState<T = unknown>(path: string): T | undefined;
|
|
920
1050
|
setState(path: string, value: unknown): void;
|
|
921
1051
|
getContext(): ComponentContext;
|
|
922
|
-
private buildHeaders;
|
|
923
1052
|
private generateIdempotencyKey;
|
|
924
1053
|
private simpleHash;
|
|
925
1054
|
private fallbackCopy;
|
|
@@ -965,6 +1094,8 @@ declare class DjvlcRuntime {
|
|
|
965
1094
|
private renderer;
|
|
966
1095
|
private hostApi;
|
|
967
1096
|
private lifecycleManager;
|
|
1097
|
+
/** User API 适配器,统一认证/请求头,供 PageLoader 与 HostAPIImpl 使用 */
|
|
1098
|
+
private userApiAdapter;
|
|
968
1099
|
private logger;
|
|
969
1100
|
constructor(options: RuntimeOptions);
|
|
970
1101
|
/**
|
|
@@ -1141,17 +1272,17 @@ declare class RenderError extends DjvlcRuntimeError {
|
|
|
1141
1272
|
* 页面加载器配置
|
|
1142
1273
|
*/
|
|
1143
1274
|
interface PageLoaderOptions {
|
|
1144
|
-
/** API 基础 URL */
|
|
1275
|
+
/** API 基础 URL(用于 preconnect、CDN 请求头) */
|
|
1145
1276
|
apiBaseUrl: string;
|
|
1277
|
+
/** User API 适配器(必填,仅通过适配器调用 User API) */
|
|
1278
|
+
userApiAdapter: UserApiAdapter;
|
|
1146
1279
|
/** 环境 */
|
|
1147
1280
|
env?: 'preview' | 'staging' | 'prod';
|
|
1148
1281
|
/** 渠道 */
|
|
1149
1282
|
channel?: string;
|
|
1150
|
-
/** 认证 Token */
|
|
1151
|
-
authToken?: string;
|
|
1152
1283
|
/** 预览 Token */
|
|
1153
1284
|
previewToken?: string;
|
|
1154
|
-
/**
|
|
1285
|
+
/** 请求头(CDN 请求用) */
|
|
1155
1286
|
headers?: Record<string, string>;
|
|
1156
1287
|
/** 缓存配置 */
|
|
1157
1288
|
cache?: {
|
|
@@ -1180,10 +1311,9 @@ declare class PageLoader {
|
|
|
1180
1311
|
deviceId?: string;
|
|
1181
1312
|
}): Promise<PageResolveResult>;
|
|
1182
1313
|
/**
|
|
1183
|
-
*
|
|
1184
|
-
* 严格按照 contracts 中的 PageResolveRequest 和 PageResolveResponse
|
|
1314
|
+
* 通过 User API 适配器调用 resolve
|
|
1185
1315
|
*/
|
|
1186
|
-
private
|
|
1316
|
+
private callResolveViaAdapter;
|
|
1187
1317
|
/**
|
|
1188
1318
|
* 从 CDN 加载 snapshot 和 manifest
|
|
1189
1319
|
*/
|
|
@@ -1222,29 +1352,34 @@ declare class PageLoader {
|
|
|
1222
1352
|
|
|
1223
1353
|
/**
|
|
1224
1354
|
* 组件加载器
|
|
1225
|
-
* 负责从 CDN
|
|
1355
|
+
* 负责从 CDN 动态加载 Web Components,支持 SRI 完整性校验、组件阻断、并行加载与降级处理。
|
|
1356
|
+
* @see SKILL: runtime-component-loading
|
|
1226
1357
|
*/
|
|
1227
1358
|
|
|
1228
1359
|
/**
|
|
1229
1360
|
* 组件加载器配置
|
|
1230
1361
|
*/
|
|
1231
1362
|
interface ComponentLoaderOptions {
|
|
1232
|
-
/** CDN 基础 URL */
|
|
1363
|
+
/** CDN 基础 URL,用于解析相对 entry 路径 */
|
|
1233
1364
|
cdnBaseUrl: string;
|
|
1234
|
-
/** 是否启用 SRI
|
|
1365
|
+
/** 是否启用 SRI 完整性校验,默认 true */
|
|
1235
1366
|
enableSRI?: boolean;
|
|
1236
|
-
/**
|
|
1367
|
+
/** 被阻断的组件列表(如 `['comp@1.0.0']` 或仅组件名 `['comp']`),用于紧急止血 */
|
|
1237
1368
|
blockedComponents?: string[];
|
|
1238
|
-
/**
|
|
1369
|
+
/** 并行加载数量,默认 4 */
|
|
1239
1370
|
concurrency?: number;
|
|
1240
|
-
/**
|
|
1371
|
+
/** 单次请求超时(毫秒),默认 30000 */
|
|
1241
1372
|
timeout?: number;
|
|
1373
|
+
/** 请求 CDN 时附加的请求头(如认证等) */
|
|
1374
|
+
headers?: Record<string, string>;
|
|
1375
|
+
/** 自定义拉取脚本的实现,不传则使用全局 fetch;测试或自定义 CDN 客户端时注入 */
|
|
1376
|
+
fetchComponentScript?: (url: string, init?: RequestInit) => Promise<Response>;
|
|
1242
1377
|
/** 日志器 */
|
|
1243
1378
|
logger?: Logger;
|
|
1244
1379
|
}
|
|
1245
1380
|
/**
|
|
1246
1381
|
* 组件加载器
|
|
1247
|
-
*
|
|
1382
|
+
* 负责从 CDN 加载 Web Components,支持缓存、阻断、SRI 校验与并行加载。
|
|
1248
1383
|
*/
|
|
1249
1384
|
declare class ComponentLoader {
|
|
1250
1385
|
private options;
|
|
@@ -1253,37 +1388,47 @@ declare class ComponentLoader {
|
|
|
1253
1388
|
private blockedSet;
|
|
1254
1389
|
constructor(options: ComponentLoaderOptions);
|
|
1255
1390
|
/**
|
|
1256
|
-
*
|
|
1391
|
+
* 加载单个组件(按 name@version 去重,同一组件并发请求复用同一 Promise)
|
|
1392
|
+
* @param item - 清单项(name、version、entry、integrity 等)
|
|
1393
|
+
* @returns 已加载的组件信息(含 Component 构造函数)
|
|
1394
|
+
* @throws ComponentBlockedError 当组件在阻断列表中
|
|
1395
|
+
* @throws ComponentLoadError 当拉取或执行失败
|
|
1396
|
+
* @throws IntegrityError 当 SRI 校验失败
|
|
1257
1397
|
*/
|
|
1258
1398
|
load(item: ManifestItem): Promise<LoadedComponent>;
|
|
1259
1399
|
/**
|
|
1260
|
-
*
|
|
1400
|
+
* 按 manifest 批量加载组件,按 concurrency 分批并行;关键组件失败会抛出,非关键组件记录失败。
|
|
1401
|
+
* @param manifest - 页面清单(含 components 数组)
|
|
1402
|
+
* @returns 以 name@version 为 key 的加载结果 Map(status: loaded | failed | blocked)
|
|
1261
1403
|
*/
|
|
1262
1404
|
loadAll(manifest: PageManifest): Promise<Map<string, ComponentLoadResult>>;
|
|
1263
1405
|
/**
|
|
1264
|
-
*
|
|
1406
|
+
* 预加载组件:向 document.head 插入 <link rel="preload" as="script">,仅作提示,不阻塞 load。
|
|
1407
|
+
* @param items - 需要预加载的清单项
|
|
1265
1408
|
*/
|
|
1266
1409
|
preload(items: ManifestItem[]): void;
|
|
1267
1410
|
/**
|
|
1268
|
-
*
|
|
1411
|
+
* 检查指定 name@version 的组件是否已加载并缓存
|
|
1269
1412
|
*/
|
|
1270
1413
|
isLoaded(name: string, version: string): boolean;
|
|
1271
1414
|
/**
|
|
1272
|
-
*
|
|
1415
|
+
* 获取已加载的组件信息,未加载则返回 undefined
|
|
1273
1416
|
*/
|
|
1274
1417
|
get(name: string, version: string): LoadedComponent | undefined;
|
|
1275
1418
|
/**
|
|
1276
|
-
*
|
|
1419
|
+
* 检查组件是否在阻断列表中(支持 `name@version` 或仅 `name`)
|
|
1277
1420
|
*/
|
|
1278
1421
|
isBlocked(name: string, version: string): boolean;
|
|
1279
1422
|
/**
|
|
1280
|
-
*
|
|
1423
|
+
* 更新阻断列表(会完全替换当前列表)
|
|
1281
1424
|
*/
|
|
1282
1425
|
updateBlockedList(blocked: string[]): void;
|
|
1283
1426
|
private loadComponent;
|
|
1284
1427
|
private fetchWithTimeout;
|
|
1285
1428
|
private validateIntegrity;
|
|
1286
1429
|
private executeScript;
|
|
1430
|
+
/** kebab-case -> PascalCase,用于匹配组件命名导出 */
|
|
1431
|
+
private kebabToPascal;
|
|
1287
1432
|
private resolveUrl;
|
|
1288
1433
|
private getComponentKey;
|
|
1289
1434
|
private log;
|
|
@@ -2040,4 +2185,4 @@ declare class LifecycleManager {
|
|
|
2040
2185
|
*/
|
|
2041
2186
|
declare const RUNTIME_VERSION = "1.0.0";
|
|
2042
2187
|
|
|
2043
|
-
export { type ASTNode, ActionBridge, type ActionBridgeOptions, ActionError, type ActionExecutor, AssetLoader, type AssetLoaderOptions, BaseRenderer, type BaseRendererOptions, ComponentBlockedError, ComponentLoadError, type ComponentLoadResult, type ComponentLoadStatus, ComponentLoader, type ComponentLoaderOptions, DjvlcRuntime, DjvlcRuntimeError, type EvaluationResult, Evaluator, type EvaluatorOptions, EventBus, type EventBusOptions, type EventHandlerFn, ExpressionEngine, type ExpressionEngineOptions, ExpressionError, HostAPIImpl, type HostAPIOptions, IntegrityError, Lexer, type LifecycleEventType, LifecycleManager, type LifecycleManagerOptions, type LoadedComponent, type LogLevel, type Logger, type MetricType, PageLoadError, PageLoader, type PageLoaderOptions, type PageResolveResult, Parser, type PerformanceMetric, QueryError, RUNTIME_VERSION, RenderError, type Renderer, type RuntimeError, type RuntimeErrorType, type RuntimeEvent, type RuntimeEventType, type RuntimeOptions, type RuntimePhase, type RuntimeState, SUPPORTED_SCHEMA_VERSION as SCHEMA_VERSION, SUPPORTED_SCHEMA_VERSION, SecurityManager, type SecurityManagerOptions, type Span, type StateListener, StateManager, TelemetryManager, type TelemetryManagerOptions, type Token, type TokenType, type Unsubscribe, builtinFunctions, createFallbackElement, createRuntime, registerFallbackComponents };
|
|
2188
|
+
export { type ASTNode, ActionBridge, type ActionBridgeOptions, ActionError, type ActionExecutor, AssetLoader, type AssetLoaderOptions, BaseRenderer, type BaseRendererOptions, ComponentBlockedError, ComponentLoadError, type ComponentLoadResult, type ComponentLoadStatus, ComponentLoader, type ComponentLoaderOptions, DjvlcRuntime, DjvlcRuntimeError, type EvaluationResult, Evaluator, type EvaluatorOptions, EventBus, type EventBusOptions, type EventHandlerFn, type ExecuteActionParams, type ExecuteQueryParams, type ExecuteQueryResult, ExpressionEngine, type ExpressionEngineOptions, ExpressionError, HostAPIImpl, type HostAPIOptions, IntegrityError, Lexer, type LifecycleEventType, LifecycleManager, type LifecycleManagerOptions, type LoadedComponent, type LogLevel, type Logger, type MetricType, MockUserApiAdapter, type MockUserApiAdapterOptions, OpenApiUserAdapter, type OpenApiUserAdapterOptions, PageLoadError, PageLoader, type PageLoaderOptions, type PageResolveResult, Parser, type PerformanceMetric, QueryError, RUNTIME_VERSION, RenderError, type Renderer, type ResolvePageParams, type RuntimeContext, type RuntimeError, type RuntimeErrorType, type RuntimeEvent, type RuntimeEventType, type RuntimeOptions, type RuntimePhase, type RuntimeState, SUPPORTED_SCHEMA_VERSION as SCHEMA_VERSION, SUPPORTED_SCHEMA_VERSION, SecurityManager, type SecurityManagerOptions, type Span, type StateListener, StateManager, TelemetryManager, type TelemetryManagerOptions, type Token, type TokenType, type TrackPayload, type Unsubscribe, type UserApiAdapter, builtinFunctions, createFallbackElement, createRuntime, registerFallbackComponents };
|