@ikenxuan/amagi 6.6.0 → 7.0.0-beta.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.
- package/README.md +57 -36
- package/dist/default/index.cjs +82 -11313
- package/dist/default/index.d.ts +2 -29342
- package/dist/default/index.mjs +2 -11160
- package/dist/exports/compat.cjs +267 -0
- package/dist/exports/compat.d.ts +1121 -0
- package/dist/exports/compat.mjs +168 -0
- package/dist/exports/signing.cjs +437 -0
- package/dist/exports/signing.d.ts +698 -0
- package/dist/exports/signing.mjs +380 -0
- package/dist/index-nCXqYNq0.d.ts +52366 -0
- package/dist/src-AA7Elfxn.mjs +56550 -0
- package/dist/src-BmVVZLDU.cjs +57029 -0
- package/dist/tokens-BFqSOfhx.mjs +1001 -0
- package/dist/tokens-DHKAuPVW.cjs +1294 -0
- package/package.json +12 -2
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
const require_src = require("../src-BmVVZLDU.cjs");
|
|
6
|
+
//#region src/exports/compat.ts
|
|
7
|
+
/** 模块级只执行一次的迁移提示(不刷屏) */
|
|
8
|
+
require_src.emitLogWarn("[@ikenxuan/amagi/compat] 你正在使用 v6 兼容入口;v7 迁移说明见 https://github.com/ikenxuan/amagi (v8 将移除 compat)");
|
|
9
|
+
/**
|
|
10
|
+
* `ErrorKind` → v6 信封顶层 `code`。
|
|
11
|
+
*
|
|
12
|
+
* v6 信封顶层 `code` 的语义并不统一(ApiError code 直接当 HTTP 状态、
|
|
13
|
+
* 平台码与 amagi 错误码混用),因此这里是近似而非逐字还原:取
|
|
14
|
+
* kind → HTTP 语义码的稳定映射,平台原文码保留在 `error.code`。
|
|
15
|
+
*/
|
|
16
|
+
const KIND_LEGACY_CODE = {
|
|
17
|
+
validation: 400,
|
|
18
|
+
auth: 401,
|
|
19
|
+
forbidden: 403,
|
|
20
|
+
not_found: 404,
|
|
21
|
+
rate_limit: 429,
|
|
22
|
+
risk: 403,
|
|
23
|
+
unavailable: 503,
|
|
24
|
+
network: 500,
|
|
25
|
+
timeout: 504,
|
|
26
|
+
parse: 502,
|
|
27
|
+
internal: 500,
|
|
28
|
+
unknown: 500
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 把 v7 信封回填成 v6 信封(纯函数,不抛错)。
|
|
32
|
+
*
|
|
33
|
+
* - 成功:`code: 200`,`error` 键运行时补 `undefined`
|
|
34
|
+
* - 失败:顶层 `code` 取 {@link KIND_LEGACY_CODE};平台码进 `error.code`;
|
|
35
|
+
* 原始响应体进 `error.data`(没有则 null)
|
|
36
|
+
*/
|
|
37
|
+
const toLegacy = (r) => {
|
|
38
|
+
if (r.success) return {
|
|
39
|
+
success: true,
|
|
40
|
+
code: 200,
|
|
41
|
+
message: r.message,
|
|
42
|
+
data: r.data,
|
|
43
|
+
error: void 0
|
|
44
|
+
};
|
|
45
|
+
const e = r.error;
|
|
46
|
+
const requestType = r.meta.endpoint.includes(".") ? r.meta.endpoint.split(".").slice(1).join(".") : r.meta.endpoint;
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
code: KIND_LEGACY_CODE[e.kind],
|
|
50
|
+
message: r.message,
|
|
51
|
+
data: void 0,
|
|
52
|
+
error: {
|
|
53
|
+
code: e.platform?.code ?? e.code,
|
|
54
|
+
data: e.raw ?? null,
|
|
55
|
+
amagiError: {
|
|
56
|
+
errorDescription: e.message,
|
|
57
|
+
requestType,
|
|
58
|
+
requestUrl: void 0
|
|
59
|
+
},
|
|
60
|
+
amagiMessage: e.message
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/** 是不是 v6 信封(顶层带 `code`)。passport 等保留方法返回 v6 信封,直接透传 */
|
|
65
|
+
const isLegacyEnvelope = (r) => typeof r === "object" && r !== null && "success" in r && "code" in r;
|
|
66
|
+
/** `kind: 'validation'` 的失败信封 → v6 的抛出行为(抛 ValidationError) */
|
|
67
|
+
const validationErrorOf = (e) => {
|
|
68
|
+
const errors = e.issues && e.issues.length > 0 ? e.issues.map((i) => ({
|
|
69
|
+
field: i.path,
|
|
70
|
+
message: i.message
|
|
71
|
+
})) : [{
|
|
72
|
+
field: "(endpoint)",
|
|
73
|
+
message: e.message
|
|
74
|
+
}];
|
|
75
|
+
return new require_src.ValidationError("参数验证失败", errors);
|
|
76
|
+
};
|
|
77
|
+
/** 一次调用的结果收口:v6 信封透传;v7 信封转 toLegacy;校验失败恢复抛出 */
|
|
78
|
+
const settle = async (promise) => {
|
|
79
|
+
const out = await promise;
|
|
80
|
+
if (isLegacyEnvelope(out)) return out;
|
|
81
|
+
const result = out;
|
|
82
|
+
if (!result.success && result.error.kind === "validation") throw validationErrorOf(result.error);
|
|
83
|
+
return toLegacy(result);
|
|
84
|
+
};
|
|
85
|
+
const WRAP_CACHE = /* @__PURE__ */ new WeakMap();
|
|
86
|
+
/**
|
|
87
|
+
* 把一个 fetcher 对象包装成「结果转 v6 信封」的版本。
|
|
88
|
+
*
|
|
89
|
+
* 包装发生在 get 时,方法集合自动跟随原对象;每个方法只包一次并缓存
|
|
90
|
+
* (WeakMap 按目标对象 + 键)。非函数属性(若存在)原样透传。
|
|
91
|
+
*/
|
|
92
|
+
const wrapFetcher = (fetcher) => {
|
|
93
|
+
return new Proxy(fetcher, { get(target, prop, receiver) {
|
|
94
|
+
const value = Reflect.get(target, prop, receiver);
|
|
95
|
+
if (typeof value !== "function" || prop === "then") return value;
|
|
96
|
+
let cache = WRAP_CACHE.get(target);
|
|
97
|
+
if (!cache) {
|
|
98
|
+
cache = /* @__PURE__ */ new Map();
|
|
99
|
+
WRAP_CACHE.set(target, cache);
|
|
100
|
+
}
|
|
101
|
+
let wrapped = cache.get(prop);
|
|
102
|
+
if (!wrapped) {
|
|
103
|
+
const fn = value;
|
|
104
|
+
wrapped = (...args) => settle(Promise.resolve(fn.apply(target, args)));
|
|
105
|
+
cache.set(prop, wrapped);
|
|
106
|
+
}
|
|
107
|
+
return wrapped;
|
|
108
|
+
} });
|
|
109
|
+
};
|
|
110
|
+
/** 兼容版 client 工厂:`createAmagiClient` 的每个平台 fetcher 包一层 */
|
|
111
|
+
const compatCreateAmagiClient = (options) => {
|
|
112
|
+
const client = require_src.createAmagiClient(options);
|
|
113
|
+
return {
|
|
114
|
+
...client,
|
|
115
|
+
douyin: {
|
|
116
|
+
...client.douyin,
|
|
117
|
+
douyinApiUrls: require_src.douyinApiUrls,
|
|
118
|
+
fetcher: wrapFetcher(client.douyin.fetcher)
|
|
119
|
+
},
|
|
120
|
+
bilibili: {
|
|
121
|
+
...client.bilibili,
|
|
122
|
+
bilibiliApiUrls: require_src.bilibiliApiUrls,
|
|
123
|
+
fetcher: wrapFetcher(client.bilibili.fetcher)
|
|
124
|
+
},
|
|
125
|
+
kuaishou: {
|
|
126
|
+
...client.kuaishou,
|
|
127
|
+
kuaishouApiUrls: require_src.kuaishouApiUrls,
|
|
128
|
+
fetcher: wrapFetcher(client.kuaishou.fetcher)
|
|
129
|
+
},
|
|
130
|
+
xiaohongshu: {
|
|
131
|
+
...client.xiaohongshu,
|
|
132
|
+
xiaohongshuApiUrls: require_src.xiaohongshuApiUrls,
|
|
133
|
+
fetcher: wrapFetcher(client.xiaohongshu.fetcher)
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
/** 兼容版静态 fetcher */
|
|
138
|
+
const compatDouyinFetcher = wrapFetcher(require_src.douyinFetcher);
|
|
139
|
+
const compatBilibiliFetcher = wrapFetcher(require_src.bilibiliFetcher);
|
|
140
|
+
const compatKuaishouFetcher = wrapFetcher(require_src.kuaishouFetcher);
|
|
141
|
+
const compatXiaohongshuFetcher = wrapFetcher(require_src.xiaohongshuFetcher);
|
|
142
|
+
/** 兼容版 bound 工厂(返回的 fetcher 已包层) */
|
|
143
|
+
const compatCreateBoundDouyinFetcher = (cookie, requestConfig) => wrapFetcher(require_src.createBoundDouyinFetcher(cookie, requestConfig));
|
|
144
|
+
const compatCreateBoundBilibiliFetcher = (cookie, requestConfig) => wrapFetcher(require_src.createBoundBilibiliFetcher(cookie, requestConfig));
|
|
145
|
+
const compatCreateBoundKuaishouFetcher = (cookie, requestConfig) => wrapFetcher(require_src.createBoundKuaishouFetcher(cookie, requestConfig));
|
|
146
|
+
const compatCreateBoundXiaohongshuFetcher = (cookie, requestConfig) => wrapFetcher(require_src.createBoundXiaohongshuFetcher(cookie, requestConfig));
|
|
147
|
+
function CreateAmagiCompatApp(options = {}) {
|
|
148
|
+
return compatCreateAmagiClient(options);
|
|
149
|
+
}
|
|
150
|
+
Object.defineProperty(CreateAmagiCompatApp, "version", {
|
|
151
|
+
value: require_src.amagi.version,
|
|
152
|
+
writable: false,
|
|
153
|
+
enumerable: true,
|
|
154
|
+
configurable: false
|
|
155
|
+
});
|
|
156
|
+
CreateAmagiCompatApp.douyin = require_src.amagi.douyin;
|
|
157
|
+
CreateAmagiCompatApp.bilibili = require_src.amagi.bilibili;
|
|
158
|
+
CreateAmagiCompatApp.kuaishou = require_src.amagi.kuaishou;
|
|
159
|
+
CreateAmagiCompatApp.xiaohongshu = require_src.amagi.xiaohongshu;
|
|
160
|
+
CreateAmagiCompatApp.events = require_src.amagi.events;
|
|
161
|
+
CreateAmagiCompatApp.on = require_src.amagi.on;
|
|
162
|
+
CreateAmagiCompatApp.once = require_src.amagi.once;
|
|
163
|
+
CreateAmagiCompatApp.douyinFetcher = compatDouyinFetcher;
|
|
164
|
+
CreateAmagiCompatApp.bilibiliFetcher = compatBilibiliFetcher;
|
|
165
|
+
CreateAmagiCompatApp.kuaishouFetcher = compatKuaishouFetcher;
|
|
166
|
+
CreateAmagiCompatApp.xiaohongshuFetcher = compatXiaohongshuFetcher;
|
|
167
|
+
CreateAmagiCompatApp.createBoundDouyinFetcher = compatCreateBoundDouyinFetcher;
|
|
168
|
+
CreateAmagiCompatApp.createBoundBilibiliFetcher = compatCreateBoundBilibiliFetcher;
|
|
169
|
+
CreateAmagiCompatApp.createBoundKuaishouFetcher = compatCreateBoundKuaishouFetcher;
|
|
170
|
+
CreateAmagiCompatApp.createBoundXiaohongshuFetcher = compatCreateBoundXiaohongshuFetcher;
|
|
171
|
+
//#endregion
|
|
172
|
+
exports.AMAGI_BUS_EVENT_NAMES = require_src.AMAGI_BUS_EVENT_NAMES;
|
|
173
|
+
exports.AdditionalType = require_src.AdditionalType;
|
|
174
|
+
exports.AmagiThrownError = require_src.AmagiThrownError;
|
|
175
|
+
exports.ApiError = require_src.ApiError;
|
|
176
|
+
exports.CommentType = require_src.CommentType;
|
|
177
|
+
exports.CreateAmagiCompatApp = CreateAmagiCompatApp;
|
|
178
|
+
exports.default = CreateAmagiCompatApp;
|
|
179
|
+
exports.CreateApp = require_src.CreateApp;
|
|
180
|
+
exports.DynamicType = require_src.DynamicType;
|
|
181
|
+
exports.KIND_LEGACY_CODE = KIND_LEGACY_CODE;
|
|
182
|
+
exports.KUAISHOU_H5_CAPTCHA_RESULT = require_src.KUAISHOU_H5_CAPTCHA_RESULT;
|
|
183
|
+
exports.KUAISHOU_PC_CAPTCHA_RESULT = require_src.KUAISHOU_PC_CAPTCHA_RESULT;
|
|
184
|
+
exports.MajorType = require_src.MajorType;
|
|
185
|
+
exports.ValidationError = require_src.ValidationError;
|
|
186
|
+
exports.amagi = require_src.amagi;
|
|
187
|
+
exports.amagiEvents = require_src.amagiEvents;
|
|
188
|
+
exports.assertValidBilibiliParams = require_src.assertValidBilibiliParams;
|
|
189
|
+
exports.assertValidDouyinParams = require_src.assertValidDouyinParams;
|
|
190
|
+
exports.assertValidKuaishouParams = require_src.assertValidKuaishouParams;
|
|
191
|
+
exports.assertValidXiaohongshuParams = require_src.assertValidXiaohongshuParams;
|
|
192
|
+
exports.av2bv = require_src.av2bv;
|
|
193
|
+
exports.bilibiliApiUrls = require_src.bilibiliApiUrls;
|
|
194
|
+
exports.bilibiliFetcher = compatBilibiliFetcher;
|
|
195
|
+
exports.compatBilibiliFetcher = compatBilibiliFetcher;
|
|
196
|
+
exports.bilibiliUtils = require_src.bilibiliUtils;
|
|
197
|
+
exports.bv2av = require_src.bv2av;
|
|
198
|
+
exports.checkPassportQrcode = require_src.checkPassportQrcode;
|
|
199
|
+
exports.compatCreateBoundBilibiliFetcher = compatCreateBoundBilibiliFetcher;
|
|
200
|
+
exports.createBoundBilibiliFetcher = compatCreateBoundBilibiliFetcher;
|
|
201
|
+
exports.compatCreateBoundDouyinFetcher = compatCreateBoundDouyinFetcher;
|
|
202
|
+
exports.createBoundDouyinFetcher = compatCreateBoundDouyinFetcher;
|
|
203
|
+
exports.compatCreateBoundKuaishouFetcher = compatCreateBoundKuaishouFetcher;
|
|
204
|
+
exports.createBoundKuaishouFetcher = compatCreateBoundKuaishouFetcher;
|
|
205
|
+
exports.compatCreateBoundXiaohongshuFetcher = compatCreateBoundXiaohongshuFetcher;
|
|
206
|
+
exports.createBoundXiaohongshuFetcher = compatCreateBoundXiaohongshuFetcher;
|
|
207
|
+
exports.compatDouyinFetcher = compatDouyinFetcher;
|
|
208
|
+
exports.douyinFetcher = compatDouyinFetcher;
|
|
209
|
+
exports.compatKuaishouFetcher = compatKuaishouFetcher;
|
|
210
|
+
exports.kuaishouFetcher = compatKuaishouFetcher;
|
|
211
|
+
exports.compatXiaohongshuFetcher = compatXiaohongshuFetcher;
|
|
212
|
+
exports.xiaohongshuFetcher = compatXiaohongshuFetcher;
|
|
213
|
+
exports.createAmagiClient = compatCreateAmagiClient;
|
|
214
|
+
exports.createBilibiliRoutes = require_src.createBilibiliRoutes;
|
|
215
|
+
exports.createClient = require_src.createClient;
|
|
216
|
+
exports.createDouyinRoutes = require_src.createDouyinRoutes;
|
|
217
|
+
exports.createErrorResponse = require_src.createErrorResponse;
|
|
218
|
+
exports.createKuaishouRoutes = require_src.createKuaishouRoutes;
|
|
219
|
+
exports.createSuccessResponse = require_src.createSuccessResponse;
|
|
220
|
+
exports.createXiaohongshuRoutes = require_src.createXiaohongshuRoutes;
|
|
221
|
+
exports.douyinApiUrls = require_src.douyinApiUrls;
|
|
222
|
+
Object.defineProperty(exports, "douyinPassport", {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function() {
|
|
225
|
+
return require_src.passport_exports;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
exports.douyinSign = require_src.douyinSign;
|
|
229
|
+
exports.douyinUtils = require_src.douyinUtils;
|
|
230
|
+
exports.emitApiError = require_src.emitApiError;
|
|
231
|
+
exports.emitApiSuccess = require_src.emitApiSuccess;
|
|
232
|
+
exports.emitHttpRequest = require_src.emitHttpRequest;
|
|
233
|
+
exports.emitHttpResponse = require_src.emitHttpResponse;
|
|
234
|
+
exports.emitLog = require_src.emitLog;
|
|
235
|
+
exports.emitLogDebug = require_src.emitLogDebug;
|
|
236
|
+
exports.emitLogError = require_src.emitLogError;
|
|
237
|
+
exports.emitLogInfo = require_src.emitLogInfo;
|
|
238
|
+
exports.emitLogMark = require_src.emitLogMark;
|
|
239
|
+
exports.emitLogWarn = require_src.emitLogWarn;
|
|
240
|
+
exports.emitNetworkError = require_src.emitNetworkError;
|
|
241
|
+
exports.emitNetworkRetry = require_src.emitNetworkRetry;
|
|
242
|
+
exports.fetchData = require_src.fetchData;
|
|
243
|
+
exports.fetchResponse = require_src.fetchResponse;
|
|
244
|
+
exports.handleError = require_src.handleError;
|
|
245
|
+
exports.isFailure = require_src.isFailure;
|
|
246
|
+
exports.isNetworkErrorResult = require_src.isNetworkErrorResult;
|
|
247
|
+
exports.isSuccess = require_src.isSuccess;
|
|
248
|
+
exports.kuaishouApiUrls = require_src.kuaishouApiUrls;
|
|
249
|
+
exports.kuaishouSign = require_src.kuaishouSign;
|
|
250
|
+
exports.kuaishouUtils = require_src.kuaishouUtils;
|
|
251
|
+
exports.parseDmSegMobileReply = require_src.parseDmSegMobileReply;
|
|
252
|
+
exports.parseKuaishouCaptcha = require_src.parseKuaishouCaptcha;
|
|
253
|
+
exports.qtparam = require_src.qtparam;
|
|
254
|
+
exports.requestPassportQrcode = require_src.requestPassportQrcode;
|
|
255
|
+
exports.sendPassportVerifyCode = require_src.sendPassportVerifyCode;
|
|
256
|
+
exports.toLegacy = toLegacy;
|
|
257
|
+
exports.unwrap = require_src.unwrap;
|
|
258
|
+
exports.validateBilibiliParams = require_src.validateBilibiliParams;
|
|
259
|
+
exports.validateDouyinParams = require_src.validateDouyinParams;
|
|
260
|
+
exports.validateKuaishouParams = require_src.validateKuaishouParams;
|
|
261
|
+
exports.validatePassportVerifyCode = require_src.validatePassportVerifyCode;
|
|
262
|
+
exports.validateXiaohongshuParams = require_src.validateXiaohongshuParams;
|
|
263
|
+
exports.wbi_sign = require_src.wbi_sign;
|
|
264
|
+
exports.wrapFetcher = wrapFetcher;
|
|
265
|
+
exports.xiaohongshuApiUrls = require_src.xiaohongshuApiUrls;
|
|
266
|
+
exports.xiaohongshuSign = require_src.xiaohongshuSign;
|
|
267
|
+
exports.xiaohongshuUtils = require_src.xiaohongshuUtils;
|