@heycar/heycars-map 0.9.23-alpha2 → 0.9.23-alpha3
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 +63 -18
- package/dist/index.js +63 -18
- package/dist/src/utils/QueryWxSignatureStatus.d.ts +10 -0
- package/dist/src/utils/helper.d.ts +1 -0
- package/dist/src/utils/mockWx.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19,7 +19,7 @@ if (typeof GeolocationPositionError === "undefined") {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
const name = "@heycar/heycars-map";
|
|
22
|
-
const version = "0.9.23-
|
|
22
|
+
const version = "0.9.23-alpha3";
|
|
23
23
|
const type = "module";
|
|
24
24
|
const bin = {
|
|
25
25
|
checkVersion: "./bin/checkVersion.js"
|
|
@@ -4447,11 +4447,41 @@ const watchVisibilityState = () => {
|
|
|
4447
4447
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
4448
4448
|
return { visibilityStateRef, unwatchVisibilityState };
|
|
4449
4449
|
};
|
|
4450
|
+
class QueryWxSignatureStatus {
|
|
4451
|
+
constructor(timeout) {
|
|
4452
|
+
__publicField(this, "error");
|
|
4453
|
+
__publicField(this, "timeout");
|
|
4454
|
+
__publicField(this, "status", "PENDING");
|
|
4455
|
+
__publicField(this, "pendingStatusPromise", new Promise((resolve, reject) => {
|
|
4456
|
+
wx == null ? void 0 : wx.ready(() => {
|
|
4457
|
+
this.status = "READY";
|
|
4458
|
+
resolve("READY");
|
|
4459
|
+
});
|
|
4460
|
+
wx == null ? void 0 : wx.error((error) => {
|
|
4461
|
+
this.status = "FAIL";
|
|
4462
|
+
this.error = error;
|
|
4463
|
+
reject(error);
|
|
4464
|
+
});
|
|
4465
|
+
setTimeout(() => {
|
|
4466
|
+
if (this.status !== "PENDING")
|
|
4467
|
+
return;
|
|
4468
|
+
this.status = "TIMEOUT";
|
|
4469
|
+
resolve("TIMEOUT");
|
|
4470
|
+
}, this.timeout);
|
|
4471
|
+
}));
|
|
4472
|
+
__publicField(this, "timoutStatusPromise", Promise.resolve("TIMEOUT"));
|
|
4473
|
+
this.timeout = timeout;
|
|
4474
|
+
}
|
|
4475
|
+
get statusPromise() {
|
|
4476
|
+
return this.status === "TIMEOUT" ? this.timoutStatusPromise : this.pendingStatusPromise;
|
|
4477
|
+
}
|
|
4478
|
+
}
|
|
4450
4479
|
function createCustomGeolocationPositionError(message, code) {
|
|
4451
4480
|
const error = new Error(message);
|
|
4452
4481
|
error.code = code;
|
|
4453
4482
|
return error;
|
|
4454
4483
|
}
|
|
4484
|
+
const WX_SIGNATURE_TIMEOUT = 5e3;
|
|
4455
4485
|
const WX_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4456
4486
|
const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4457
4487
|
const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
|
|
@@ -4461,10 +4491,6 @@ const takeIsForceBrowserGeo = () => {
|
|
|
4461
4491
|
const searchParam = new URLSearchParams(location.search);
|
|
4462
4492
|
return searchParam.has(`force-browser-geo`);
|
|
4463
4493
|
};
|
|
4464
|
-
const wxReady = () => new Promise((resolve, reject) => {
|
|
4465
|
-
wx.ready(resolve);
|
|
4466
|
-
wx.error(reject);
|
|
4467
|
-
});
|
|
4468
4494
|
function wechatWatchPosition(onSuccess, onError, option) {
|
|
4469
4495
|
const { timeout } = option;
|
|
4470
4496
|
let enable = true;
|
|
@@ -4472,25 +4498,44 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
4472
4498
|
let lastSuccessfulResponse = void 0;
|
|
4473
4499
|
let geoErrorMessage = void 0;
|
|
4474
4500
|
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
4501
|
+
const onWxSignatureTimeoutErrorOnce = createRunOnce((error) => {
|
|
4502
|
+
console.warn("警告:微信签名超时");
|
|
4503
|
+
onError(error);
|
|
4504
|
+
});
|
|
4505
|
+
const onWxSignatureErrorOnce = createRunOnce((error) => {
|
|
4506
|
+
console.error("微信签名失败:", error);
|
|
4507
|
+
onError(error);
|
|
4508
|
+
});
|
|
4509
|
+
const queryWxSignatureStatus = new QueryWxSignatureStatus(WX_SIGNATURE_TIMEOUT);
|
|
4475
4510
|
const startWatch = async () => {
|
|
4476
|
-
try {
|
|
4477
|
-
await wxReady();
|
|
4478
|
-
} catch (err) {
|
|
4479
|
-
console.error(err);
|
|
4480
|
-
onError == null ? void 0 : onError(
|
|
4481
|
-
createCustomGeolocationPositionError(
|
|
4482
|
-
err.errMsg,
|
|
4483
|
-
// 签名失败,也算无权限的一种
|
|
4484
|
-
GeolocationPositionError.PERMISSION_DENIED
|
|
4485
|
-
)
|
|
4486
|
-
);
|
|
4487
|
-
return;
|
|
4488
|
-
}
|
|
4489
4511
|
do {
|
|
4490
4512
|
if (visibilityStateRef.value === "hidden") {
|
|
4491
4513
|
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4492
4514
|
continue;
|
|
4493
4515
|
}
|
|
4516
|
+
try {
|
|
4517
|
+
const status = await queryWxSignatureStatus.statusPromise;
|
|
4518
|
+
if (status === "TIMEOUT") {
|
|
4519
|
+
onWxSignatureTimeoutErrorOnce == null ? void 0 : onWxSignatureTimeoutErrorOnce(
|
|
4520
|
+
createCustomGeolocationPositionError(
|
|
4521
|
+
"Custom wx ready timeout",
|
|
4522
|
+
GeolocationPositionError.TIMEOUT
|
|
4523
|
+
)
|
|
4524
|
+
);
|
|
4525
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4526
|
+
continue;
|
|
4527
|
+
}
|
|
4528
|
+
} catch (err) {
|
|
4529
|
+
onWxSignatureErrorOnce == null ? void 0 : onWxSignatureErrorOnce(
|
|
4530
|
+
createCustomGeolocationPositionError(
|
|
4531
|
+
err.errMsg,
|
|
4532
|
+
// 签名失败,也算无权限的一种
|
|
4533
|
+
GeolocationPositionError.PERMISSION_DENIED
|
|
4534
|
+
)
|
|
4535
|
+
);
|
|
4536
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4537
|
+
continue;
|
|
4538
|
+
}
|
|
4494
4539
|
const geoPosition = await new Promise((resolve) => {
|
|
4495
4540
|
let isHandled = false;
|
|
4496
4541
|
wx.getLocation({
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ if (typeof GeolocationPositionError === "undefined") {
|
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
const name = "@heycar/heycars-map";
|
|
20
|
-
const version = "0.9.23-
|
|
20
|
+
const version = "0.9.23-alpha3";
|
|
21
21
|
const type = "module";
|
|
22
22
|
const bin = {
|
|
23
23
|
checkVersion: "./bin/checkVersion.js"
|
|
@@ -4445,11 +4445,41 @@ const watchVisibilityState = () => {
|
|
|
4445
4445
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
4446
4446
|
return { visibilityStateRef, unwatchVisibilityState };
|
|
4447
4447
|
};
|
|
4448
|
+
class QueryWxSignatureStatus {
|
|
4449
|
+
constructor(timeout) {
|
|
4450
|
+
__publicField(this, "error");
|
|
4451
|
+
__publicField(this, "timeout");
|
|
4452
|
+
__publicField(this, "status", "PENDING");
|
|
4453
|
+
__publicField(this, "pendingStatusPromise", new Promise((resolve, reject) => {
|
|
4454
|
+
wx == null ? void 0 : wx.ready(() => {
|
|
4455
|
+
this.status = "READY";
|
|
4456
|
+
resolve("READY");
|
|
4457
|
+
});
|
|
4458
|
+
wx == null ? void 0 : wx.error((error) => {
|
|
4459
|
+
this.status = "FAIL";
|
|
4460
|
+
this.error = error;
|
|
4461
|
+
reject(error);
|
|
4462
|
+
});
|
|
4463
|
+
setTimeout(() => {
|
|
4464
|
+
if (this.status !== "PENDING")
|
|
4465
|
+
return;
|
|
4466
|
+
this.status = "TIMEOUT";
|
|
4467
|
+
resolve("TIMEOUT");
|
|
4468
|
+
}, this.timeout);
|
|
4469
|
+
}));
|
|
4470
|
+
__publicField(this, "timoutStatusPromise", Promise.resolve("TIMEOUT"));
|
|
4471
|
+
this.timeout = timeout;
|
|
4472
|
+
}
|
|
4473
|
+
get statusPromise() {
|
|
4474
|
+
return this.status === "TIMEOUT" ? this.timoutStatusPromise : this.pendingStatusPromise;
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4448
4477
|
function createCustomGeolocationPositionError(message, code) {
|
|
4449
4478
|
const error = new Error(message);
|
|
4450
4479
|
error.code = code;
|
|
4451
4480
|
return error;
|
|
4452
4481
|
}
|
|
4482
|
+
const WX_SIGNATURE_TIMEOUT = 5e3;
|
|
4453
4483
|
const WX_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4454
4484
|
const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
|
|
4455
4485
|
const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
|
|
@@ -4459,10 +4489,6 @@ const takeIsForceBrowserGeo = () => {
|
|
|
4459
4489
|
const searchParam = new URLSearchParams(location.search);
|
|
4460
4490
|
return searchParam.has(`force-browser-geo`);
|
|
4461
4491
|
};
|
|
4462
|
-
const wxReady = () => new Promise((resolve, reject) => {
|
|
4463
|
-
wx.ready(resolve);
|
|
4464
|
-
wx.error(reject);
|
|
4465
|
-
});
|
|
4466
4492
|
function wechatWatchPosition(onSuccess, onError, option) {
|
|
4467
4493
|
const { timeout } = option;
|
|
4468
4494
|
let enable = true;
|
|
@@ -4470,25 +4496,44 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
4470
4496
|
let lastSuccessfulResponse = void 0;
|
|
4471
4497
|
let geoErrorMessage = void 0;
|
|
4472
4498
|
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
4499
|
+
const onWxSignatureTimeoutErrorOnce = createRunOnce((error) => {
|
|
4500
|
+
console.warn("警告:微信签名超时");
|
|
4501
|
+
onError(error);
|
|
4502
|
+
});
|
|
4503
|
+
const onWxSignatureErrorOnce = createRunOnce((error) => {
|
|
4504
|
+
console.error("微信签名失败:", error);
|
|
4505
|
+
onError(error);
|
|
4506
|
+
});
|
|
4507
|
+
const queryWxSignatureStatus = new QueryWxSignatureStatus(WX_SIGNATURE_TIMEOUT);
|
|
4473
4508
|
const startWatch = async () => {
|
|
4474
|
-
try {
|
|
4475
|
-
await wxReady();
|
|
4476
|
-
} catch (err) {
|
|
4477
|
-
console.error(err);
|
|
4478
|
-
onError == null ? void 0 : onError(
|
|
4479
|
-
createCustomGeolocationPositionError(
|
|
4480
|
-
err.errMsg,
|
|
4481
|
-
// 签名失败,也算无权限的一种
|
|
4482
|
-
GeolocationPositionError.PERMISSION_DENIED
|
|
4483
|
-
)
|
|
4484
|
-
);
|
|
4485
|
-
return;
|
|
4486
|
-
}
|
|
4487
4509
|
do {
|
|
4488
4510
|
if (visibilityStateRef.value === "hidden") {
|
|
4489
4511
|
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4490
4512
|
continue;
|
|
4491
4513
|
}
|
|
4514
|
+
try {
|
|
4515
|
+
const status = await queryWxSignatureStatus.statusPromise;
|
|
4516
|
+
if (status === "TIMEOUT") {
|
|
4517
|
+
onWxSignatureTimeoutErrorOnce == null ? void 0 : onWxSignatureTimeoutErrorOnce(
|
|
4518
|
+
createCustomGeolocationPositionError(
|
|
4519
|
+
"Custom wx ready timeout",
|
|
4520
|
+
GeolocationPositionError.TIMEOUT
|
|
4521
|
+
)
|
|
4522
|
+
);
|
|
4523
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4524
|
+
continue;
|
|
4525
|
+
}
|
|
4526
|
+
} catch (err) {
|
|
4527
|
+
onWxSignatureErrorOnce == null ? void 0 : onWxSignatureErrorOnce(
|
|
4528
|
+
createCustomGeolocationPositionError(
|
|
4529
|
+
err.errMsg,
|
|
4530
|
+
// 签名失败,也算无权限的一种
|
|
4531
|
+
GeolocationPositionError.PERMISSION_DENIED
|
|
4532
|
+
)
|
|
4533
|
+
);
|
|
4534
|
+
await sleep(WX_GET_LOCATION_INTERVAL);
|
|
4535
|
+
continue;
|
|
4536
|
+
}
|
|
4492
4537
|
const geoPosition = await new Promise((resolve) => {
|
|
4493
4538
|
let isHandled = false;
|
|
4494
4539
|
wx.getLocation({
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type WxSignatureStatus = "PENDING" | "READY" | "TIMEOUT" | "FAIL";
|
|
2
|
+
export declare class QueryWxSignatureStatus {
|
|
3
|
+
private error;
|
|
4
|
+
private timeout;
|
|
5
|
+
private status;
|
|
6
|
+
private pendingStatusPromise;
|
|
7
|
+
private timoutStatusPromise;
|
|
8
|
+
constructor(timeout: number);
|
|
9
|
+
get statusPromise(): Promise<WxSignatureStatus>;
|
|
10
|
+
}
|
|
@@ -25,4 +25,5 @@ export declare const pausableSleep: (milliSeconds: number) => {
|
|
|
25
25
|
export declare const createRunOnce: <P extends any[], R>(fn: (...args: P) => R) => (...args: P) => R;
|
|
26
26
|
export declare const createAsyncNoFailNonNullable: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: NonNullable<R>) => (...args: P) => Promise<NonNullable<R>>;
|
|
27
27
|
export declare const pipeTimeout: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: R, timeout: number) => (...args: P) => Promise<R>;
|
|
28
|
+
export declare const retryUntilSuccess: <P extends any[], R>(fn: (...args: P) => Promise<R>) => (...args: P) => Promise<R>;
|
|
28
29
|
export {};
|