SPB Git

Repository Public

index.ts 4.7 KB 89 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : src/lib/testflight/index.ts9 * Module           : lib10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import type { AppDoc, Distribution } from "@/models/app";4445export const TESTFLIGHT_URL = /^https:\/\/testflight\.apple\.com\/join\/[A-Za-z0-9]{6,12}$/;46export const isPublicInvite = (url: string | null | undefined): url is string => !!url && TESTFLIGHT_URL.test(url);4748export type CheckResult = NonNullable<Distribution["check"]>;4950/**51 * Asks Apple whether a public invitation is live. The host is fixed (no SSRF surface) and the page is read as52 * anonymous text. Apple offers no public API for this, so the wording is matched conservatively: only an53 * invitation page that clearly offers the beta counts as `open`; anything unrecognized is `unknown`.54 */55export async function checkInvite(url: string, fetchImpl: (u: string, i?: RequestInit) => Promise<Response> = fetch): Promise<CheckResult> {56  const at = new Date().toISOString();57  if (!isPublicInvite(url)) return { at, result: "error", detail: "not a public TestFlight invitation URL" };58  try {59    const res = await fetchImpl(url, { redirect: "manual", headers: { "Accept-Language": "en-US", "User-Agent": "Mozilla/5.0 (Macintosh) orix-site-linkcheck" }, signal: AbortSignal.timeout(10_000) });60    if (res.status === 404) return { at, result: "closed", detail: "invitation not found (404)" };61    if (res.status !== 200) return { at, result: "unknown", detail: `HTTP ${res.status}` };62    const html = (await res.text()).slice(0, 200_000);63    if (/beta is full/i.test(html)) return { at, result: "full", detail: "This beta is full" };64    if (/isn.t accepting any new testers|not accepting any new testers|no longer available/i.test(html)) return { at, result: "closed", detail: "not accepting new testers" };65    if (/(Join the .{1,80} beta|View in TestFlight|itms-beta:\/\/)/i.test(html)) return { at, result: "open" };66    return { at, result: "unknown", detail: "unrecognized page" };67  } catch (e) { return { at, result: "error", detail: e instanceof Error ? e.message.slice(0, 200) : "network error" }; }68}6970export type BetaAccess =71  | { kind: "join"; url: string; verifiedAt: string }72  | { kind: "soon"; reason: "no-invite" | "internal-only" | "unverified" | "full" | "closed" }73  | { kind: "none" };7475/**76 * What the site may show for the TestFlight channel. "Join TestFlight" appears only for a public invitation77 * URL that the server has verified as open; an internal build or an unverified link never produces a button.78 */79export function betaAccess(app: Pick<AppDoc, "distribution" | "platforms">): BetaAccess {80  const d = app.distribution.find((x) => x.channel === "testflight");81  if (!d || !app.platforms.some((p) => p === "ios" || p === "ipados")) return { kind: "none" };82  if (d.state === "internal") return { kind: "soon", reason: "internal-only" };83  if (d.state !== "public" || !isPublicInvite(d.url)) return { kind: "soon", reason: "no-invite" };84  if (d.check?.result === "open") return { kind: "join", url: d.url, verifiedAt: d.check.at };85  if (d.check?.result === "full") return { kind: "soon", reason: "full" };86  if (d.check?.result === "closed") return { kind: "soon", reason: "closed" };87  return { kind: "soon", reason: "unverified" };88}89
Files main
Menu

Theme