index.ts
4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* 环境能力补齐必须在任何业务代码前执行:原生小程序运行时没有全局 AbortController /
* AbortSignal,缺失会令每次请求抛 `AbortController is not defined`。仅在全局确实缺失时
* 安装最小实现,web / 现代浏览器有原生实现时本模块为 no-op。
*/
import './core/polyfill';
/**
* @uj/api-core 主入口 —— 对外只有三个统一门面:
*
* createSigner(options?) 签名器,选型靠 kind / algorithm,不传即最新 glsx SHA1
* createStrategy(options?) 请求方案配置,选型靠 kind,不传即最新 rpc-gateway
* createClient(options?) 客户端实例,选型靠 kind,不传即最新 rpc-gateway
*
* 老系统显式传参(kind:'rop' / 'md5' / 'gsc' / 'web-host' / 'rest' 等)。
* 旧版那些具名预设全部降级到 `@uj/api-core/legacy`,不再从主入口导出。
*/
export type {
GatewayCredential,
GatewayStrategy,
HeaderSigner,
HeaderSignInput,
NormalizedEnvelope,
RawRequest,
RawResponse,
RequestSender,
ResponseVerifier,
RpcCall,
Signer,
SignInput,
} from './core/types';
export { registerGateway, resolveGateway } from './gateway/registry';
export {
createRpcDispatcher,
flattenFormParams,
prepareRpcCall,
unwrapEnvelope,
RpcError,
} from './gateway/dispatcher';
export type { RpcDispatcherDeps, RpcPrepareDeps } from './gateway/dispatcher';
// 传输层适配:每种 transport 一个 RequestSender 构造器,由 dispatcher 的 sender 注入。
export {
createHostSender,
createWxSender,
createUniSender,
createFetchSender,
createAutoSender,
} from './transport/senders';
export type { HostRequestConfig, HostSendFn } from './transport/senders';
// 【统一门面 1/3】签名器:所有算法 / 预设都通过参数确定。
export { createSigner } from './signing/signers';
export type {
SignAlgorithm,
Canonicalizer,
SignFieldNames,
SignerOptions,
CreateSignerOptions,
SignerKind,
HmacSignerOptions,
HmacHeaderNames,
SdkSignerOptions,
} from './signing/signers';
// 【统一门面 2/3】请求方案:createStrategy 上挂 define/register/resolve/list 与 signature.*。
export { createStrategy } from './gateway/strategies';
export type {
StrategyKind,
CreateStrategyOptions,
RequestStrategy,
RequestStrategySpec,
SignatureStrategy,
SignatureSpec,
PreparedRequest,
SessionValue,
} from './gateway/strategies';
// 【统一门面 3/3】客户端实例:new Request(createStrategy(options))。
export { createClient } from './client/clients';
export type { ClientKind, CreateClientOptions } from './client/clients';
// 摘要 / MAC 算法 helper(供自定义 Signer 注入;hmacSha256Sync 为同步纯实现,原生小程序可用)。
export { md5, sha1, sha256, hmacSha256, hmacSha256Sync } from './signing/crypto';
// 两个独立老适配器:mp 的 newRequest.js / 离线钉值测试仍在用,且小程序「构建 npm」
// 不保证解析 exports 子路径,故保留在主入口(它们不是新门面的预设,形态与 Request 不同)。
export {
createGscClient,
createGscHeaderSigner,
processGscSignParams,
flattenGscParams,
buildGscQuery,
generateGscNonce,
} from './gateway/gsc';
export type {
GscClient,
GscClientOptions,
GscEvents,
GscHeaderSignerOptions,
GscRequestConfig,
GscResponseConfig,
GscResponseData,
GscSessionConfig,
} from './gateway/gsc';
export { createLegacyRopClient } from './gateway/rop';
export type {
RopClient,
RopClientOptions,
RopEvents,
RopHosts,
RopCredential,
RopResolveCredential,
RopRequestOptions,
RopUiAdapter,
RopLoadingAdapter,
} from './gateway/rop';
// 统一请求门面:抹平平台(auto/wx/uni/fetch/host)、签名、拦截器。
// 同时提供 '@uj/api-core/Request' 子路径入口(src/Request.ts)。
export {
Request,
createRequest,
Defaults,
InterceptorManager,
RequestError,
isRequestError,
cancelRequests,
setActiveScope,
getActiveScope,
activeRequestCount,
requestKey,
} from './core/facade';
// 子路径 `@uj/api-core/Request` 别名到本 bundle,需在此提供默认导出。
export { Request as default } from './core/facade';
export type {
RequestConfig,
RequestTransport,
RequestProfile,
SignaturePreset,
BodySignFn,
SessionOptions,
ResponseOptions,
RequestEvents,
UiAdapter,
RetryOptions,
ErrorHandler,
Interceptor,
} from './core/facade';