dsh-mobile 0.6.1 → 0.6.2

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/lib/index.mjs CHANGED
@@ -14431,14 +14431,15 @@ var ManagedOriginController = class {
14431
14431
  //#region src/release-update.ts
14432
14432
  const PACKAGE_NAME = "dsh-mobile";
14433
14433
  const NPM_LATEST_URL = "https://registry.npmjs.org/dsh-mobile/latest";
14434
- const GITHUB_LATEST_URL = "https://github.com/saya-ch/dsh-mobile/releases/latest";
14435
- const GITHUB_API_LATEST_URL = "https://api.github.com/repos/saya-ch/dsh-mobile/releases/latest";
14434
+ const ANDROID_RELEASE_DESCRIPTOR_URL = "https://raw.githubusercontent.com/saya-ch/dsh-mobile/main/apps/mobile/release.json";
14435
+ const GITHUB_RELEASE_API = "https://api.github.com/repos/saya-ch/dsh-mobile/releases/tags/";
14436
14436
  const GITHUB_RELEASES_URL = "https://github.com/saya-ch/dsh-mobile/releases";
14437
14437
  const RELEASE_NOTES_MAX_CHARS = 4e3;
14438
14438
  const STATUS_CACHE_MS = 6e5;
14439
14439
  const REQUEST_TIMEOUT_MS = 8e3;
14440
14440
  const UPDATE_TIMEOUT_MS = 12e4;
14441
14441
  const UPDATE_TERMINATION_GRACE_MS = 1500;
14442
+ const bundledAndroidRelease = createRequire(import.meta.url)("../apps/mobile/release.json");
14442
14443
  const NUMERIC_VERSION_IDENTIFIER = "(?:0|[1-9]\\d*)";
14443
14444
  const WILDCARD_VERSION_IDENTIFIER = "(?:[xX*])";
14444
14445
  const RANGE_VERSION = `(?:${`${NUMERIC_VERSION_IDENTIFIER}\\.${NUMERIC_VERSION_IDENTIFIER}\\.${NUMERIC_VERSION_IDENTIFIER}(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?`}|${`(?:${WILDCARD_VERSION_IDENTIFIER}|${NUMERIC_VERSION_IDENTIFIER}(?:\\.(?:${WILDCARD_VERSION_IDENTIFIER}|${NUMERIC_VERSION_IDENTIFIER}(?:\\.(?:${WILDCARD_VERSION_IDENTIFIER}|${NUMERIC_VERSION_IDENTIFIER}))?))?)`})`;
@@ -14540,43 +14541,39 @@ async function fetchNpmVersion(fetcher) {
14540
14541
  const payload = await response.json();
14541
14542
  return typeof payload.version === "string" && parseSemver(payload.version) !== void 0 ? payload.version : void 0;
14542
14543
  }
14543
- function githubReleaseVersion(location, responseUrl) {
14544
- let url;
14545
- try {
14546
- url = new URL(location ?? responseUrl, GITHUB_LATEST_URL);
14547
- } catch {
14548
- return;
14549
- }
14550
- if (url.origin !== "https://github.com" || url.username !== "" || url.password !== "" || url.search !== "" || url.hash !== "") return void 0;
14551
- if (!url.pathname.startsWith("/saya-ch/dsh-mobile/releases/tag/v")) return void 0;
14552
- let version;
14553
- try {
14554
- version = decodeURIComponent(url.pathname.slice(34));
14555
- } catch {
14556
- return;
14557
- }
14558
- return parseSemver(version) === void 0 ? void 0 : version;
14544
+ function androidRelease(version, tag) {
14545
+ if (typeof version !== "string" || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.test(version) || parseSemver(version) === void 0 || tag !== `v${version}` && tag !== `android-v${version}`) return void 0;
14546
+ return Object.freeze({
14547
+ version,
14548
+ downloadUrl: `https://github.com/saya-ch/dsh-mobile/releases/download/${tag}/dsh-mobile-android-v${version}.apk`
14549
+ });
14559
14550
  }
14560
- function androidReleaseDownloadUrl(version) {
14561
- if (version === void 0) return GITHUB_RELEASES_URL;
14562
- const tag = `v${version}`;
14563
- return `https://github.com/saya-ch/dsh-mobile/releases/download/${encodeURIComponent(tag)}/dsh-mobile-android-${encodeURIComponent(tag)}.apk`;
14551
+ function androidReleaseDescriptor(payload) {
14552
+ if (typeof payload !== "object" || payload === null) return void 0;
14553
+ const fields = payload;
14554
+ return Number.isSafeInteger(fields.versionCode) && Number(fields.versionCode) > 0 ? androidRelease(fields.version, fields.releaseTag) : void 0;
14564
14555
  }
14565
- async function fetchAndroidVersion(fetcher) {
14566
- const response = await fetcher(GITHUB_LATEST_URL, {
14567
- method: "GET",
14568
- redirect: "manual",
14569
- headers: {
14570
- accept: "text/html",
14571
- "user-agent": "dsh-mobile-release-check"
14572
- },
14573
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
14574
- });
14575
- return githubReleaseVersion(response.headers.get("location"), response.url);
14556
+ async function fetchAndroidRelease(fetcher) {
14557
+ const fallback = androidReleaseDescriptor(bundledAndroidRelease);
14558
+ try {
14559
+ const response = await fetcher(ANDROID_RELEASE_DESCRIPTOR_URL, {
14560
+ redirect: "error",
14561
+ headers: {
14562
+ accept: "application/json",
14563
+ "user-agent": "dsh-mobile-release-check"
14564
+ },
14565
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
14566
+ });
14567
+ if (response.ok) {
14568
+ const release = androidReleaseDescriptor(await response.json());
14569
+ if (release !== void 0) return fallback !== void 0 && comparePluginVersions(release.version, fallback.version) === -1 ? fallback : release;
14570
+ }
14571
+ } catch {}
14572
+ return fallback;
14576
14573
  }
14577
- /** Best-effort body of the latest GitHub release, trimmed to a bounded size. */
14578
- async function fetchReleaseNotes(fetcher) {
14579
- const response = await fetcher(GITHUB_API_LATEST_URL, {
14574
+ /** Best-effort body of the selected npm version's GitHub release, trimmed to a bounded size. */
14575
+ async function fetchReleaseNotes(fetcher, version) {
14576
+ const response = await fetcher(`${GITHUB_RELEASE_API}${encodeURIComponent(`v${version}`)}`, {
14580
14577
  headers: {
14581
14578
  accept: "application/vnd.github+json",
14582
14579
  "user-agent": "dsh-mobile-release-check"
@@ -14781,13 +14778,14 @@ var PluginReleaseManager = class {
14781
14778
  async status(force = false) {
14782
14779
  if (!force && this.cache !== void 0 && this.cache.expiresAt > this.now()) return this.cache.status;
14783
14780
  const updateSupported = isRegistryPluginSpec(this.profileDirectory === void 0 ? void 0 : await profileDependencySpec(this.profileDirectory));
14781
+ const npmVersion = fetchNpmVersion(this.fetcher);
14784
14782
  const [npmResult, androidResult, notesResult] = await Promise.allSettled([
14785
- fetchNpmVersion(this.fetcher),
14786
- fetchAndroidVersion(this.fetcher),
14787
- fetchReleaseNotes(this.fetcher)
14783
+ npmVersion,
14784
+ fetchAndroidRelease(this.fetcher),
14785
+ npmVersion.then((version) => version === void 0 ? void 0 : fetchReleaseNotes(this.fetcher, version))
14788
14786
  ]);
14789
14787
  const latestVersion = npmResult.status === "fulfilled" ? npmResult.value : void 0;
14790
- const androidVersion = androidResult.status === "fulfilled" ? androidResult.value : void 0;
14788
+ const android = androidResult.status === "fulfilled" ? androidResult.value : void 0;
14791
14789
  const releaseNotes = notesResult.status === "fulfilled" ? notesResult.value : void 0;
14792
14790
  const comparison = latestVersion === void 0 ? void 0 : comparePluginVersions(latestVersion, this.installedVersion);
14793
14791
  const status = Object.freeze({
@@ -14795,8 +14793,8 @@ var PluginReleaseManager = class {
14795
14793
  ...latestVersion === void 0 ? {} : { latestVersion },
14796
14794
  updateAvailable: updateSupported && comparison === 1,
14797
14795
  updateSupported,
14798
- ...androidVersion === void 0 ? {} : { androidVersion },
14799
- androidDownloadUrl: androidReleaseDownloadUrl(androidVersion),
14796
+ ...android === void 0 ? {} : { androidVersion: android.version },
14797
+ androidDownloadUrl: android?.downloadUrl ?? GITHUB_RELEASES_URL,
14800
14798
  ...releaseNotes === void 0 ? {} : { releaseNotes }
14801
14799
  });
14802
14800
  this.cache = {