@open-wxa/wxa-runner-core 0.6.0 → 0.7.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.d.mts +15 -6
- package/dist/index.d.ts +15 -6
- package/dist/index.js +280 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +274 -72
- package/dist/index.mjs.map +1 -1
- package/dist/runtime/host.js +30 -12
- package/dist/runtime/host.js.map +1 -1
- package/dist/{setup-Cv340Lvj.d.mts → setup-DZ5FeKay.d.mts} +2 -1
- package/dist/{setup-Cv340Lvj.d.ts → setup-DZ5FeKay.d.ts} +2 -1
- package/dist/setup.d.mts +1 -1
- package/dist/setup.d.ts +1 -1
- package/dist/test-api.d.mts +2 -2
- package/dist/test-api.d.ts +2 -2
- package/dist/{testApi-nKsjjEhz.d.ts → testApi-BLozOgCt.d.ts} +1 -1
- package/dist/{testApi-DO2FyR78.d.mts → testApi-CnZOLyWw.d.mts} +1 -1
- package/package.json +3 -3
package/dist/runtime/host.js
CHANGED
|
@@ -551,12 +551,13 @@
|
|
|
551
551
|
}
|
|
552
552
|
|
|
553
553
|
// src/runtime/host/api/misc.ts
|
|
554
|
+
var SERVICE_MARKET = "webapi_servicemarket_jsapi_comm";
|
|
554
555
|
function createMiscApis(appid, options) {
|
|
555
|
-
const
|
|
556
|
+
const viaDevtools = async (api, url, json) => {
|
|
556
557
|
try {
|
|
557
|
-
return await postDevServer(url);
|
|
558
|
+
return await postDevServer(url, json);
|
|
558
559
|
} catch (error) {
|
|
559
|
-
options?.
|
|
560
|
+
options?.onDevtoolsLoginFail?.(api, error.message);
|
|
560
561
|
throw error;
|
|
561
562
|
}
|
|
562
563
|
};
|
|
@@ -568,15 +569,28 @@
|
|
|
568
569
|
},
|
|
569
570
|
// 基础库经这两个接口向后台拉各种配置和小程序信息
|
|
570
571
|
operateWXData: (args, { api }) => {
|
|
572
|
+
if (args.data?.api_name === SERVICE_MARKET) {
|
|
573
|
+
const serviceMarketFail = (reason2) => fail(api, reason2, { err_code: -1 });
|
|
574
|
+
if (!options?.devtoolsLogin) return serviceMarketFail("wx.serviceMarket \u8981\u5411\u5FAE\u4FE1\u670D\u52A1\u5E02\u573A\u771F\u5B9E\u8C03\u7528\uFF0C\u542F\u52A8\u65F6\u52A0 --devtools-login");
|
|
575
|
+
return viaDevtools("serviceMarket.invokeService", "/__wxa__/api/operate-wx-data", { data: args.data }).then(
|
|
576
|
+
({ data }) => ok(api, { data }),
|
|
577
|
+
(error) => serviceMarketFail(error.message)
|
|
578
|
+
);
|
|
579
|
+
}
|
|
571
580
|
if (args.data?.api_name === "webapi_getwxanetwork") return bizDomainUnavailable(api);
|
|
572
581
|
if (args.data?.api_name === "webapi_getwxauserprivacyauthinfo") return ok(api, { data: { data: JSON.stringify(PRIVACY_AUTH_INFO) } });
|
|
573
582
|
return ok(api);
|
|
574
583
|
},
|
|
575
584
|
getAppContact: (args, { api }) => args.keyPath === "WxaAppInfo.Network.BizDomain" ? bizDomainUnavailable(api) : ok(api),
|
|
576
|
-
//
|
|
577
|
-
|
|
585
|
+
// 插件:基础库启动时校验插件、取插件信息,插件里的网络请求要等拿到这两样才发出。插件代码也只在 --devtools-login 时下载
|
|
586
|
+
...options?.devtoolsLogin ? {
|
|
587
|
+
verifyPlugin: (async (args, { api }) => ok(api, await viaDevtools(api, "/__wxa__/api/verify-plugin", { data: args.data }))),
|
|
588
|
+
batchGetContact: (async (args, { api }) => ok(api, await viaDevtools(api, "/__wxa__/api/batch-get-contact", { appIds: args.appIds })))
|
|
589
|
+
} : {},
|
|
590
|
+
// 向微信取不到时明确返回 fail,不退回假数据:配置或登录态的问题要让开发者马上发现
|
|
591
|
+
login: options?.devtoolsLogin ? async (_args, { api }) => ok(api, { code: (await viaDevtools(api, "/__wxa__/api/login")).code }) : (_args, { api }) => ok(api, { code: `wxa_mock_code_${Date.now().toString(36)}` }),
|
|
578
592
|
// 基础库只从 JSON.parse(data) 里取手机号的 code
|
|
579
|
-
getPhoneNumber: options?.
|
|
593
|
+
getPhoneNumber: options?.devtoolsLogin ? async (_args, { api }) => ok(api, await viaDevtools(api, "/__wxa__/api/phone-number")) : (_args, { api }) => ok(api, { data: JSON.stringify({ code: `mock_phone_code_${Date.now()}` }), encryptedData: "mock_encrypted", iv: "mock_iv" }),
|
|
580
594
|
checkSession: () => void 0,
|
|
581
595
|
authorize: () => void 0,
|
|
582
596
|
getSetting: (_args, { api }) => ok(api, {
|
|
@@ -601,8 +615,9 @@
|
|
|
601
615
|
};
|
|
602
616
|
}
|
|
603
617
|
var clipboard = "";
|
|
604
|
-
async function postDevServer(url) {
|
|
605
|
-
const
|
|
618
|
+
async function postDevServer(url, json) {
|
|
619
|
+
const init = json ? { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(json) } : { method: "POST" };
|
|
620
|
+
const response = await fetch(url, init);
|
|
606
621
|
const body = await response.json().catch(() => null);
|
|
607
622
|
if (!response.ok || !body) throw new Error(body?.error || `\u5F00\u53D1\u670D\u52A1\u5668\u8FD4\u56DE HTTP ${response.status}`);
|
|
608
623
|
return body;
|
|
@@ -800,7 +815,10 @@
|
|
|
800
815
|
}
|
|
801
816
|
var rejectBaseLib = (_args, { api }) => fail(api, "\u57FA\u7840\u5E93\u5185\u90E8\u7684\u7F51\u7EDC\u8BF7\u6C42\uFF0Cwxa-runner \u4E0D\u53D1\u51FA");
|
|
802
817
|
function byCaller(forApp, forBaseLib = rejectBaseLib) {
|
|
803
|
-
return (args, context) => args?.__skipDomainCheck__ === true ? forBaseLib(args, context) : forApp(args, context);
|
|
818
|
+
return (args, context) => args?.__skipDomainCheck__ === true && !hasPluginSign(args) ? forBaseLib(args, context) : forApp(args, context);
|
|
819
|
+
}
|
|
820
|
+
function hasPluginSign(args) {
|
|
821
|
+
return Object.keys(args.header || {}).some((name) => name.toLowerCase() === "x-wechat-hostsign");
|
|
804
822
|
}
|
|
805
823
|
function isAudioDownload(args) {
|
|
806
824
|
return args.responseType === "arraybuffer" && args.enableCache === true;
|
|
@@ -2214,7 +2232,7 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2214
2232
|
openImagePreview(this.overlay, urls, current);
|
|
2215
2233
|
}
|
|
2216
2234
|
/**
|
|
2217
|
-
* 在手机外面提示 wxa-runner
|
|
2235
|
+
* 在手机外面提示 wxa-runner 自身的问题(如借用开发者工具登录态失败),不混进小程序的界面。
|
|
2218
2236
|
* 同一时间只显示一条,新的替换旧的:业务代码反复重试时不会堆满屏幕
|
|
2219
2237
|
*/
|
|
2220
2238
|
showNotice(title, message) {
|
|
@@ -2685,8 +2703,8 @@ html, body { margin: 0; height: 100%; background: radial-gradient(120% 80% at 50
|
|
|
2685
2703
|
emitToWebview: (webviewId, event, data) => this.emitToWebview(webviewId, event, data)
|
|
2686
2704
|
}),
|
|
2687
2705
|
...createMiscApis(this.info.appid, {
|
|
2688
|
-
|
|
2689
|
-
|
|
2706
|
+
devtoolsLogin: this.info.devtoolsLogin,
|
|
2707
|
+
onDevtoolsLoginFail: (api, reason2) => this.shell.showNotice(`wx.${api} \u501F\u7528\u5F00\u53D1\u8005\u5DE5\u5177\u767B\u5F55\u6001\u5931\u8D25`, reason2)
|
|
2690
2708
|
})
|
|
2691
2709
|
});
|
|
2692
2710
|
}
|