@heycar/heycars-map 0.9.23-alpha2 → 0.9.23-alpha4

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 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-alpha2";
22
+ const version = "0.9.23-alpha4";
23
23
  const type = "module";
24
24
  const bin = {
25
25
  checkVersion: "./bin/checkVersion.js"
@@ -4447,11 +4447,53 @@ 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
+ __publicField(this, "readyStatusPromise", Promise.resolve("READY"));
4474
+ this.timeout = timeout;
4475
+ }
4476
+ get statusPromise() {
4477
+ switch (this.status) {
4478
+ case "PENDING":
4479
+ return this.pendingStatusPromise;
4480
+ case "TIMEOUT":
4481
+ return this.timoutStatusPromise;
4482
+ case "READY":
4483
+ return this.readyStatusPromise;
4484
+ case "FAIL":
4485
+ return Promise.reject(this.error);
4486
+ default:
4487
+ throw new Error("MyError: QueryWxSignatureStatus.statusPromise Never !");
4488
+ }
4489
+ }
4490
+ }
4450
4491
  function createCustomGeolocationPositionError(message, code) {
4451
4492
  const error = new Error(message);
4452
4493
  error.code = code;
4453
4494
  return error;
4454
4495
  }
4496
+ const WX_SIGNATURE_TIMEOUT = 5e3;
4455
4497
  const WX_GET_LOCATION_INTERVAL = 1 * 1e3;
4456
4498
  const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
4457
4499
  const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
@@ -4461,10 +4503,6 @@ const takeIsForceBrowserGeo = () => {
4461
4503
  const searchParam = new URLSearchParams(location.search);
4462
4504
  return searchParam.has(`force-browser-geo`);
4463
4505
  };
4464
- const wxReady = () => new Promise((resolve, reject) => {
4465
- wx.ready(resolve);
4466
- wx.error(reject);
4467
- });
4468
4506
  function wechatWatchPosition(onSuccess, onError, option) {
4469
4507
  const { timeout } = option;
4470
4508
  let enable = true;
@@ -4472,25 +4510,44 @@ function wechatWatchPosition(onSuccess, onError, option) {
4472
4510
  let lastSuccessfulResponse = void 0;
4473
4511
  let geoErrorMessage = void 0;
4474
4512
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4513
+ const onWxSignatureTimeoutErrorOnce = createRunOnce((error) => {
4514
+ console.warn("警告:微信签名超时");
4515
+ onError(error);
4516
+ });
4517
+ const onWxSignatureErrorOnce = createRunOnce((error) => {
4518
+ console.error("微信签名失败:", error);
4519
+ onError(error);
4520
+ });
4521
+ const queryWxSignatureStatus = new QueryWxSignatureStatus(WX_SIGNATURE_TIMEOUT);
4475
4522
  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
4523
  do {
4490
4524
  if (visibilityStateRef.value === "hidden") {
4491
4525
  await sleep(WX_GET_LOCATION_INTERVAL);
4492
4526
  continue;
4493
4527
  }
4528
+ try {
4529
+ const status = await queryWxSignatureStatus.statusPromise;
4530
+ if (status === "TIMEOUT") {
4531
+ onWxSignatureTimeoutErrorOnce == null ? void 0 : onWxSignatureTimeoutErrorOnce(
4532
+ createCustomGeolocationPositionError(
4533
+ "Custom wx ready timeout",
4534
+ GeolocationPositionError.TIMEOUT
4535
+ )
4536
+ );
4537
+ await sleep(WX_GET_LOCATION_INTERVAL);
4538
+ continue;
4539
+ }
4540
+ } catch (err) {
4541
+ onWxSignatureErrorOnce == null ? void 0 : onWxSignatureErrorOnce(
4542
+ createCustomGeolocationPositionError(
4543
+ err.errMsg,
4544
+ // 签名失败,也算无权限的一种
4545
+ GeolocationPositionError.PERMISSION_DENIED
4546
+ )
4547
+ );
4548
+ await sleep(WX_GET_LOCATION_INTERVAL);
4549
+ continue;
4550
+ }
4494
4551
  const geoPosition = await new Promise((resolve) => {
4495
4552
  let isHandled = false;
4496
4553
  wx.getLocation({
@@ -8401,8 +8458,9 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
8401
8458
  centerSource.source = "api";
8402
8459
  updatePlace(point);
8403
8460
  };
8404
- const setCenterPlaceByUserSpecified = async (input) => {
8405
- centerSource.source = "api";
8461
+ const setCenterPlaceByUserSpecified = async (input, context2) => {
8462
+ var _a2;
8463
+ centerSource.source = (_a2 = context2 == null ? void 0 : context2.source) != null ? _a2 : "api";
8406
8464
  const place = toPlaceType(input);
8407
8465
  Object.assign(centerPlace, place);
8408
8466
  updateRecommendPlaceOnlyInZone(place);
@@ -8471,7 +8529,9 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
8471
8529
  centerSource.source = "geo";
8472
8530
  emit("loadDefaultGeoLocation", value);
8473
8531
  if (inputPlace) {
8474
- await setCenterPlaceByUserSpecified(inputPlace);
8532
+ await setCenterPlaceByUserSpecified(inputPlace, {
8533
+ source: "geo"
8534
+ });
8475
8535
  } else {
8476
8536
  updatePlace(value.position);
8477
8537
  }
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-alpha2";
20
+ const version = "0.9.23-alpha4";
21
21
  const type = "module";
22
22
  const bin = {
23
23
  checkVersion: "./bin/checkVersion.js"
@@ -4445,11 +4445,53 @@ 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
+ __publicField(this, "readyStatusPromise", Promise.resolve("READY"));
4472
+ this.timeout = timeout;
4473
+ }
4474
+ get statusPromise() {
4475
+ switch (this.status) {
4476
+ case "PENDING":
4477
+ return this.pendingStatusPromise;
4478
+ case "TIMEOUT":
4479
+ return this.timoutStatusPromise;
4480
+ case "READY":
4481
+ return this.readyStatusPromise;
4482
+ case "FAIL":
4483
+ return Promise.reject(this.error);
4484
+ default:
4485
+ throw new Error("MyError: QueryWxSignatureStatus.statusPromise Never !");
4486
+ }
4487
+ }
4488
+ }
4448
4489
  function createCustomGeolocationPositionError(message, code) {
4449
4490
  const error = new Error(message);
4450
4491
  error.code = code;
4451
4492
  return error;
4452
4493
  }
4494
+ const WX_SIGNATURE_TIMEOUT = 5e3;
4453
4495
  const WX_GET_LOCATION_INTERVAL = 1 * 1e3;
4454
4496
  const ALIPAY_GET_LOCATION_INTERVAL = 1 * 1e3;
4455
4497
  const ALIPAY_GEO_CACHE_TIMEOUT = 5e3;
@@ -4459,10 +4501,6 @@ const takeIsForceBrowserGeo = () => {
4459
4501
  const searchParam = new URLSearchParams(location.search);
4460
4502
  return searchParam.has(`force-browser-geo`);
4461
4503
  };
4462
- const wxReady = () => new Promise((resolve, reject) => {
4463
- wx.ready(resolve);
4464
- wx.error(reject);
4465
- });
4466
4504
  function wechatWatchPosition(onSuccess, onError, option) {
4467
4505
  const { timeout } = option;
4468
4506
  let enable = true;
@@ -4470,25 +4508,44 @@ function wechatWatchPosition(onSuccess, onError, option) {
4470
4508
  let lastSuccessfulResponse = void 0;
4471
4509
  let geoErrorMessage = void 0;
4472
4510
  const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
4511
+ const onWxSignatureTimeoutErrorOnce = createRunOnce((error) => {
4512
+ console.warn("警告:微信签名超时");
4513
+ onError(error);
4514
+ });
4515
+ const onWxSignatureErrorOnce = createRunOnce((error) => {
4516
+ console.error("微信签名失败:", error);
4517
+ onError(error);
4518
+ });
4519
+ const queryWxSignatureStatus = new QueryWxSignatureStatus(WX_SIGNATURE_TIMEOUT);
4473
4520
  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
4521
  do {
4488
4522
  if (visibilityStateRef.value === "hidden") {
4489
4523
  await sleep(WX_GET_LOCATION_INTERVAL);
4490
4524
  continue;
4491
4525
  }
4526
+ try {
4527
+ const status = await queryWxSignatureStatus.statusPromise;
4528
+ if (status === "TIMEOUT") {
4529
+ onWxSignatureTimeoutErrorOnce == null ? void 0 : onWxSignatureTimeoutErrorOnce(
4530
+ createCustomGeolocationPositionError(
4531
+ "Custom wx ready timeout",
4532
+ GeolocationPositionError.TIMEOUT
4533
+ )
4534
+ );
4535
+ await sleep(WX_GET_LOCATION_INTERVAL);
4536
+ continue;
4537
+ }
4538
+ } catch (err) {
4539
+ onWxSignatureErrorOnce == null ? void 0 : onWxSignatureErrorOnce(
4540
+ createCustomGeolocationPositionError(
4541
+ err.errMsg,
4542
+ // 签名失败,也算无权限的一种
4543
+ GeolocationPositionError.PERMISSION_DENIED
4544
+ )
4545
+ );
4546
+ await sleep(WX_GET_LOCATION_INTERVAL);
4547
+ continue;
4548
+ }
4492
4549
  const geoPosition = await new Promise((resolve) => {
4493
4550
  let isHandled = false;
4494
4551
  wx.getLocation({
@@ -8399,8 +8456,9 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
8399
8456
  centerSource.source = "api";
8400
8457
  updatePlace(point);
8401
8458
  };
8402
- const setCenterPlaceByUserSpecified = async (input) => {
8403
- centerSource.source = "api";
8459
+ const setCenterPlaceByUserSpecified = async (input, context2) => {
8460
+ var _a2;
8461
+ centerSource.source = (_a2 = context2 == null ? void 0 : context2.source) != null ? _a2 : "api";
8404
8462
  const place = toPlaceType(input);
8405
8463
  Object.assign(centerPlace, place);
8406
8464
  updateRecommendPlaceOnlyInZone(place);
@@ -8469,7 +8527,9 @@ const BusinessRecomendPlaceMap = defineLagecySetup(function BusinessRecomendPlac
8469
8527
  centerSource.source = "geo";
8470
8528
  emit("loadDefaultGeoLocation", value);
8471
8529
  if (inputPlace) {
8472
- await setCenterPlaceByUserSpecified(inputPlace);
8530
+ await setCenterPlaceByUserSpecified(inputPlace, {
8531
+ source: "geo"
8532
+ });
8473
8533
  } else {
8474
8534
  updatePlace(value.position);
8475
8535
  }
@@ -0,0 +1,11 @@
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
+ private readyStatusPromise;
9
+ constructor(timeout: number);
10
+ get statusPromise(): Promise<WxSignatureStatus>;
11
+ }
@@ -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 {};
@@ -1,6 +1,7 @@
1
1
  import type { Wx } from "../types/wx";
2
+ import type { WxSignatureStatus } from "./QueryWxSignatureStatus";
2
3
  interface CreateMockWxProps {
3
- configOk: boolean;
4
+ signatureStatus: WxSignatureStatus;
4
5
  getLocation: {
5
6
  timeout: number;
6
7
  lng?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "0.9.23-alpha2",
3
+ "version": "0.9.23-alpha4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js"