@pmate/cli 0.39.0 → 0.41.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.js CHANGED
@@ -8818,8 +8818,8 @@ __export(index_exports, {
8818
8818
  parseCommandArgs: () => parseCommandArgs
8819
8819
  });
8820
8820
  module.exports = __toCommonJS(index_exports);
8821
- var import_node_fs29 = require("fs");
8822
- var import_node_path34 = __toESM(require("path"));
8821
+ var import_node_fs30 = require("fs");
8822
+ var import_node_path35 = __toESM(require("path"));
8823
8823
 
8824
8824
  // src/managedSession.ts
8825
8825
  var import_node_fs = require("fs");
@@ -14267,9 +14267,9 @@ ${indent}\`\`\``;
14267
14267
  static richTextToPlain(richText) {
14268
14268
  return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
14269
14269
  }
14270
- static async requestJson(path34, init) {
14270
+ static async requestJson(path35, init) {
14271
14271
  const token = this.getToken();
14272
- const response = await fetch(`${this.baseUrl}${path34}`, {
14272
+ const response = await fetch(`${this.baseUrl}${path35}`, {
14273
14273
  method: init.method,
14274
14274
  headers: {
14275
14275
  Authorization: `Bearer ${token}`,
@@ -16974,8 +16974,8 @@ function descriptorPathSegments(descriptor) {
16974
16974
  return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
16975
16975
  }
16976
16976
  function buildPathUrl(baseUrl, pathSegments, query) {
16977
- const path34 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
16978
- const url = new URL(path34, baseUrl);
16977
+ const path35 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
16978
+ const url = new URL(path35, baseUrl);
16979
16979
  if (query) {
16980
16980
  for (const [key, value] of Object.entries(query)) {
16981
16981
  url.searchParams.set(key, String(value));
@@ -17535,207 +17535,15 @@ var StoreCommandHandler = class {
17535
17535
  }
17536
17536
  };
17537
17537
 
17538
- // src/electronBuild.ts
17539
- var import_node_child_process9 = require("child_process");
17538
+ // src/commands/AppCommandHandler.ts
17540
17539
  var import_node_fs19 = require("fs");
17541
- var import_node_os9 = require("os");
17542
17540
  var import_node_path24 = __toESM(require("path"));
17543
-
17544
- // src/desktopRelease.ts
17545
- init_sessionStore();
17546
- var import_node_crypto4 = require("crypto");
17547
- var import_node_fs18 = require("fs");
17548
- var import_node_path23 = __toESM(require("path"));
17549
- async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
17550
- const segments = [...app.split(":"), version, platform, arch];
17551
- if (app.split(":").length !== 2 || segments.some((s) => !/^[\w.-]+$/.test(s) || s === "." || s === "..")) throw new Error("Invalid desktop release identity");
17552
- if (!["mac", "win"].includes(platform) || !["arm64", "x64"].includes(arch) || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) throw new Error("Desktop publication requires a stable version and supported target");
17553
- const { token } = readRequiredSession({ preferredApp: DEFAULT_APP_ID });
17554
- const bucket = "parrot-static";
17555
- const prefix = `desktop/${segments.join("/")}/`;
17556
- const url = (key) => `https://parrot-static.pmate.chat/${key.split("/").map(encodeURIComponent).join("/")}`;
17557
- const artifacts = (0, import_node_fs18.readdirSync)(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && (platform === "mac" ? /\.(dmg|zip)$/i : /\.(exe|zip)$/i).test(entry.name)).sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
17558
- const bytes = (0, import_node_fs18.readFileSync)(import_node_path23.default.join(directory, entry.name));
17559
- const objectKey = prefix + entry.name;
17560
- return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex"), size: bytes.length };
17561
- });
17562
- if (!artifacts.length) throw new Error("No desktop installers found to publish");
17563
- const manifestKey = prefix + "release.json";
17564
- const existing = await AliyunService.readJsonObject(bucket, manifestKey);
17565
- const release = { schemaVersion: 1, app, version, platform, arch, artifacts };
17566
- if (existing !== null && JSON.stringify(existing) !== JSON.stringify(release)) throw new Error("Desktop release already exists with different artifacts; bump the app version");
17567
- for (const artifact of artifacts) await AliyunService.uploadFile(import_node_path23.default.join(directory, artifact.name), bucket, artifact.objectKey);
17568
- await AliyunService.uploadJsonObject(bucket, manifestKey, release);
17569
- const base = (process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
17570
- const response = await fetch(`${base}/versions/${encodeURIComponent(app)}`, {
17571
- method: "POST",
17572
- headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
17573
- body: JSON.stringify({ version, platform, arch, manifestUrl: url(manifestKey) }),
17574
- signal: AbortSignal.timeout(3e4),
17575
- redirect: "error"
17576
- });
17577
- const result = await response.json();
17578
- if (!response.ok || result.success !== true) throw new Error(`Installers uploaded but version registration failed: ${result.message || response.status}. Retry this release before announcing it.`);
17579
- return { bucket, manifestUrl: url(manifestKey), downloads: artifacts };
17580
- }
17581
-
17582
- // src/electronBuild.ts
17583
- var ELECTRON_VERSION = "44.5.1";
17584
- var BUILDER_VERSION = "26.15.3";
17585
- function readDesktopConfig(file, appId) {
17586
- const c = JSON.parse((0, import_node_fs19.readFileSync)(file, "utf8"));
17587
- if (c.schemaVersion !== 2 || c.app !== appId) throw new Error("Desktop config schemaVersion/app mismatch");
17588
- for (const key of ["productName", "bundleId", "version", "icon"]) {
17589
- if (typeof c[key] !== "string" || !c[key].trim()) throw new Error(`Missing desktop ${key}`);
17590
- }
17591
- if (!/^[a-zA-Z][\w-]*(\.[a-zA-Z][\w-]*)+$/.test(c.bundleId)) throw new Error("Invalid desktop bundleId");
17592
- if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(c.version)) throw new Error("Invalid desktop version");
17593
- const origin = (value) => {
17594
- const url = new URL(value);
17595
- if (url.protocol !== "https:" || url.origin !== value || url.username || url.password) throw new Error("Desktop origins must be exact HTTPS origins, without paths or credentials");
17596
- };
17597
- origin(c.origin);
17598
- if (!Array.isArray(c.authOrigins)) throw new Error("authOrigins must be an array");
17599
- c.authOrigins.forEach(origin);
17600
- if (c.externalOrigins !== void 0 && !Array.isArray(c.externalOrigins)) throw new Error("externalOrigins must be an array");
17601
- c.externalOrigins?.forEach(origin);
17602
- if (c.notaryProfile !== void 0 && (typeof c.notaryProfile !== "string" || !c.notaryProfile.trim())) throw new Error("Invalid notaryProfile");
17603
- if ("web" in c) throw new Error("Remote desktop builds do not accept web build configuration; remove web");
17604
- return c;
17605
- }
17606
- function repositoryRoot(cwd) {
17607
- let dir = import_node_path24.default.resolve(cwd);
17608
- while (true) {
17609
- if ((0, import_node_fs19.existsSync)(import_node_path24.default.join(dir, ".git"))) return dir;
17610
- const parent = import_node_path24.default.dirname(dir);
17611
- if (parent === dir) return void 0;
17612
- dir = parent;
17613
- }
17614
- }
17615
- function resolveDesktopPaths(args, cwd = process.cwd()) {
17616
- const root = repositoryRoot(cwd);
17617
- const name = args.id.split(":")[1];
17618
- let file = args.config ? import_node_path24.default.resolve(cwd, args.config) : void 0;
17619
- if (!file) {
17620
- let dir = import_node_path24.default.resolve(cwd);
17621
- while (true) {
17622
- const candidates = [.../* @__PURE__ */ new Set([import_node_path24.default.join(dir, "desktop.config.json"), import_node_path24.default.join(dir, "apps", name, "desktop.config.json")])];
17623
- const matches = candidates.filter((candidate) => (0, import_node_fs19.existsSync)(candidate) && JSON.parse((0, import_node_fs19.readFileSync)(candidate, "utf8")).app === args.id);
17624
- if (matches.length > 1) throw new Error("Ambiguous desktop config; specify --config");
17625
- if (matches.length === 1) {
17626
- file = matches[0];
17627
- break;
17628
- }
17629
- const parent = import_node_path24.default.dirname(dir);
17630
- if (dir === root || parent === dir) break;
17631
- dir = parent;
17632
- }
17633
- }
17634
- if (!file) throw new Error(`No desktop config for ${args.id}; specify --config`);
17635
- return { file, output: args.outDir ? import_node_path24.default.resolve(cwd, args.outDir) : import_node_path24.default.join(root ?? import_node_path24.default.dirname(file), "release", name) };
17636
- }
17637
- function desktopBuildEnvironment(config, env = process.env) {
17638
- return { ...env, ...env.APPLE_KEYCHAIN_PROFILE ? {} : config.notaryProfile ? { APPLE_KEYCHAIN_PROFILE: config.notaryProfile } : {} };
17639
- }
17640
- function requireNotaryCredentials(env) {
17641
- if (env.APPLE_ID || env.APPLE_APP_SPECIFIC_PASSWORD) {
17642
- if (env.APPLE_ID && env.APPLE_APP_SPECIFIC_PASSWORD && env.APPLE_TEAM_ID) return;
17643
- } else if (env.APPLE_API_KEY || env.APPLE_API_KEY_ID || env.APPLE_API_ISSUER) {
17644
- if (env.APPLE_API_KEY && env.APPLE_API_KEY_ID && env.APPLE_API_ISSUER) return;
17645
- } else if (env.APPLE_KEYCHAIN_PROFILE) return;
17646
- throw new Error("macOS signed builds require complete Apple notarization credentials or APPLE_KEYCHAIN_PROFILE");
17647
- }
17648
- function requireSigningIdentity(env, inspect = () => (0, import_node_child_process9.execFileSync)("security", ["find-identity", "-v", "-p", "codesigning"], { encoding: "utf8" })) {
17649
- if (env.CSC_LINK) return;
17650
- if (!inspect().includes("Developer ID Application:")) throw new Error("No Developer ID Application signing identity available");
17651
- }
17652
- async function publishVerifiedDesktop(args, artifacts, config, verify = verifyMacRelease, upload = uploadDesktopArtifacts) {
17653
- if (args.signed && args.platform === "mac") await verify(artifacts);
17654
- if (args.dir || !args.signed) return void 0;
17655
- return upload(artifacts, config.app, config.version, args.platform, args.arch);
17656
- }
17657
- async function verifyMacRelease(artifacts, run = runBuildCommand, inspect = (app) => (0, import_node_child_process9.spawnSync)("codesign", ["-dv", "--verbose=4", app], { encoding: "utf8" })) {
17658
- const apps = (0, import_node_fs19.readdirSync)(artifacts, { recursive: true, withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.endsWith(".app")).map((entry) => import_node_path24.default.join(entry.parentPath, entry.name)).filter((file) => !file.slice(0, -4).includes(".app/"));
17659
- if (!apps.length) throw new Error("No packaged macOS app found; refusing publication");
17660
- for (const app of apps) {
17661
- await run(["codesign", "--verify", "--deep", "--strict", app], artifacts);
17662
- const signature = inspect(app);
17663
- if (signature.status !== 0 || !signature.stderr.includes("Authority=Developer ID Application:")) throw new Error("Packaged app lacks Developer ID Application signature");
17664
- await run(["xcrun", "stapler", "validate", app], artifacts);
17665
- await run(["spctl", "--assess", "--type", "execute", "--verbose=2", app], artifacts);
17666
- }
17667
- }
17668
- async function runBuildCommand(command, cwd, env = process.env) {
17669
- await new Promise((resolve, reject) => {
17670
- const child = (0, import_node_child_process9.spawn)(command[0], command.slice(1), { cwd, env, stdio: "inherit", shell: false });
17671
- child.once("error", reject);
17672
- child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`${command[0]} failed (${signal ?? code})`)));
17673
- });
17674
- }
17675
- async function buildDesktop(args) {
17676
- const { file, output } = resolveDesktopPaths(args);
17677
- const c = readDesktopConfig(file, args.id);
17678
- const base = import_node_path24.default.dirname(file);
17679
- const icon = import_node_path24.default.resolve(base, c.icon);
17680
- const env = desktopBuildEnvironment(c);
17681
- if (!(0, import_node_fs19.existsSync)(icon) || !(0, import_node_fs19.statSync)(icon).isFile()) throw new Error(`Desktop icon not found: ${icon}`);
17682
- if (!["mac", "win"].includes(args.platform) || !["arm64", "x64"].includes(args.arch)) throw new Error("Supported target: mac|win --arch arm64|x64");
17683
- if (args.platform === "mac" && process.platform !== "darwin") throw new Error("macOS desktop packaging requires a macOS build host");
17684
- const plan = { config: file, notaryProfile: env.APPLE_KEYCHAIN_PROFILE, app: c.app, productName: c.productName, version: c.version, target: "electron", platform: args.platform, arch: args.arch, contentSource: "remote", origin: c.origin, output, electron: ELECTRON_VERSION, builder: BUILDER_VERSION, signed: args.signed };
17685
- console.log(JSON.stringify({ phase: "plan", ...plan }, null, 2));
17686
- if (args.dryRun) return;
17687
- if (args.signed && args.platform === "mac") {
17688
- requireNotaryCredentials(env);
17689
- requireSigningIdentity(env);
17690
- }
17691
- (0, import_node_fs19.mkdirSync)(output, { recursive: true });
17692
- const staging = (0, import_node_fs19.mkdtempSync)(import_node_path24.default.join(output, ".desktop-build-"));
17693
- const appDir = import_node_path24.default.join(staging, "app");
17694
- (0, import_node_fs19.mkdirSync)(appDir);
17695
- const templateDir = import_node_path24.default.join(__dirname, "templates", "electron");
17696
- (0, import_node_fs19.cpSync)(templateDir, appDir, { recursive: true });
17697
- (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(appDir, "desktop-config.json"), JSON.stringify({ app: c.app, productName: c.productName, origin: c.origin, authOrigins: c.authOrigins, externalOrigins: c.externalOrigins ?? [], bundleId: c.bundleId }));
17698
- (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(appDir, "package.json"), JSON.stringify({ name: c.bundleId.replace(/\./g, "-"), version: c.version, description: `${c.productName} desktop application`, author: "PMate", main: "main.cjs", dependencies: { "@pmate/chat-sdk": "0.11.7" } }));
17699
- await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
17700
- const cache = import_node_path24.default.join((0, import_node_os9.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
17701
- (0, import_node_fs19.mkdirSync)(cache, { recursive: true });
17702
- const toolPackage = { name: "pmate-desktop-toolchain", private: true, dependencies: { electron: ELECTRON_VERSION, "electron-builder": BUILDER_VERSION } };
17703
- if (!(0, import_node_fs19.existsSync)(import_node_path24.default.join(cache, "node_modules", "electron", "dist", "Electron.app")) || !(0, import_node_fs19.existsSync)(import_node_path24.default.join(cache, "node_modules", "electron-builder", "cli.js"))) {
17704
- (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(cache, "package.json"), JSON.stringify(toolPackage));
17705
- await runBuildCommand(["npm", (0, import_node_fs19.existsSync)(import_node_path24.default.join(cache, "package-lock.json")) ? "ci" : "install", "--no-audit", "--no-fund"], cache);
17706
- }
17707
- const builderConfig = {
17708
- appId: c.bundleId,
17709
- productName: c.productName,
17710
- electronVersion: ELECTRON_VERSION,
17711
- directories: { app: appDir, output: import_node_path24.default.join(staging, "artifacts") },
17712
- files: ["**/*"],
17713
- asar: true,
17714
- artifactName: "${productName}-${version}-${arch}.${ext}",
17715
- publish: [{ provider: "generic", url: `https://parrot-static.pmate.chat/desktop/${c.app.split(":").map(encodeURIComponent).join("/")}/${c.version}/${args.platform}/${args.arch}/` }],
17716
- mac: { icon, target: args.dir ? ["dir"] : ["dmg", "zip"], category: "public.app-category.social-networking", hardenedRuntime: args.signed, extendInfo: { NSMicrophoneUsageDescription: `${c.productName} uses your microphone for voice calls and voice messages.` }, ...args.signed ? {} : { identity: "-", notarize: false } },
17717
- win: { icon, target: args.dir ? ["dir"] : ["nsis", "zip"], ...args.signed ? {} : { signExecutable: false } },
17718
- forceCodeSigning: args.signed
17719
- };
17720
- const configPath = import_node_path24.default.join(staging, "builder.json");
17721
- (0, import_node_fs19.writeFileSync)(configPath, JSON.stringify(builderConfig));
17722
- await runBuildCommand([process.execPath, import_node_path24.default.join(cache, "node_modules", "electron-builder", "cli.js"), "--config", configPath, args.platform === "mac" ? "--mac" : "--win", `--${args.arch}`, "--publish", "never"], appDir, { ...env, ...args.signed ? {} : { CSC_IDENTITY_AUTO_DISCOVERY: "false" } });
17723
- const result = { ...plan, signature: args.signed ? args.platform === "mac" ? "Developer ID signed; notarization and Gatekeeper required before publication" : "configured-signing-required; verify Authenticode before distribution" : args.platform === "mac" ? "ad-hoc; local development" : "unsigned; local development", artifacts: import_node_path24.default.join(staging, "artifacts") };
17724
- (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(staging, "build-report.json"), JSON.stringify(result, null, 2));
17725
- const publication = await publishVerifiedDesktop(args, result.artifacts, c);
17726
- (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(staging, "build-report.json"), JSON.stringify({ ...result, publication }, null, 2));
17727
- console.log(JSON.stringify({ phase: "complete", report: import_node_path24.default.join(staging, "build-report.json"), artifacts: result.artifacts, signature: result.signature, publication }, null, 2));
17728
- }
17729
-
17730
- // src/commands/AppCommandHandler.ts
17731
- var import_node_fs21 = require("fs");
17732
- var import_node_path26 = __toESM(require("path"));
17733
17541
  init_sessionStore();
17734
17542
 
17735
17543
  // src/appIcon.ts
17736
- var import_node_fs20 = require("fs");
17737
- var import_node_os10 = __toESM(require("os"));
17738
- var import_node_path25 = __toESM(require("path"));
17544
+ var import_node_fs18 = require("fs");
17545
+ var import_node_os9 = __toESM(require("os"));
17546
+ var import_node_path23 = __toESM(require("path"));
17739
17547
  var import_sharp = __toESM(require("sharp"));
17740
17548
  init_namespacedRef();
17741
17549
  var ANDROID_ICON_SPECS = [
@@ -17840,13 +17648,13 @@ function createAppIconExportPlans(input) {
17840
17648
  if (!input.outDir) {
17841
17649
  throw new Error("App icon preset export requires --out-dir.");
17842
17650
  }
17843
- const outDir = import_node_path25.default.resolve(input.cwd, input.outDir);
17844
- (0, import_node_fs20.mkdirSync)(outDir, { recursive: true });
17651
+ const outDir = import_node_path23.default.resolve(input.cwd, input.outDir);
17652
+ (0, import_node_fs18.mkdirSync)(outDir, { recursive: true });
17845
17653
  return specs.map((spec) => ({
17846
17654
  width: spec.width,
17847
17655
  height: spec.height,
17848
17656
  format: "png",
17849
- outputPath: import_node_path25.default.join(
17657
+ outputPath: import_node_path23.default.join(
17850
17658
  outDir,
17851
17659
  `${namespace}-${objectId}-${spec.name}-${spec.width}x${spec.height}.png`
17852
17660
  )
@@ -17859,8 +17667,8 @@ function createAppIconExportPlans(input) {
17859
17667
  if (!input.output) {
17860
17668
  throw new Error("Single-size app icon export requires --output.");
17861
17669
  }
17862
- const resolvedOutput = import_node_path25.default.resolve(input.cwd, input.output);
17863
- (0, import_node_fs20.mkdirSync)(import_node_path25.default.dirname(resolvedOutput), { recursive: true });
17670
+ const resolvedOutput = import_node_path23.default.resolve(input.cwd, input.output);
17671
+ (0, import_node_fs18.mkdirSync)(import_node_path23.default.dirname(resolvedOutput), { recursive: true });
17864
17672
  return [
17865
17673
  {
17866
17674
  width: input.width,
@@ -17874,7 +17682,7 @@ async function exportAppIcon(icon, plans) {
17874
17682
  const svg = await resolveAppIconSvg(icon);
17875
17683
  for (const plan of plans) {
17876
17684
  const bytes = await renderAppIcon(svg, plan.width, plan.height, plan.format);
17877
- (0, import_node_fs20.writeFileSync)(plan.outputPath, bytes);
17685
+ (0, import_node_fs18.writeFileSync)(plan.outputPath, bytes);
17878
17686
  }
17879
17687
  }
17880
17688
  async function renderAppIconVariant(input) {
@@ -17882,9 +17690,9 @@ async function renderAppIconVariant(input) {
17882
17690
  const bytes = await renderAppIcon(svg, input.width, input.height, input.format);
17883
17691
  let outputPath;
17884
17692
  if (input.output) {
17885
- outputPath = import_node_path25.default.resolve(input.cwd, input.output);
17886
- (0, import_node_fs20.mkdirSync)(import_node_path25.default.dirname(outputPath), { recursive: true });
17887
- (0, import_node_fs20.writeFileSync)(outputPath, bytes);
17693
+ outputPath = import_node_path23.default.resolve(input.cwd, input.output);
17694
+ (0, import_node_fs18.mkdirSync)(import_node_path23.default.dirname(outputPath), { recursive: true });
17695
+ (0, import_node_fs18.writeFileSync)(outputPath, bytes);
17888
17696
  }
17889
17697
  if (input.name) {
17890
17698
  return {
@@ -17905,7 +17713,7 @@ async function renderAppIconVariant(input) {
17905
17713
  };
17906
17714
  }
17907
17715
  async function loadAppIconVariantFile(input) {
17908
- const absolutePath = import_node_path25.default.resolve(input.cwd, input.filePath);
17716
+ const absolutePath = import_node_path23.default.resolve(input.cwd, input.filePath);
17909
17717
  const format = inferVariantFormatFromPath(absolutePath);
17910
17718
  return {
17911
17719
  value: input.name ? await uploadAppIconVariantAsset({
@@ -17914,7 +17722,7 @@ async function loadAppIconVariantFile(input) {
17914
17722
  name: input.name,
17915
17723
  format,
17916
17724
  sourcePath: absolutePath
17917
- }) : createImageDataUrl((0, import_node_fs20.readFileSync)(absolutePath), format),
17725
+ }) : createImageDataUrl((0, import_node_fs18.readFileSync)(absolutePath), format),
17918
17726
  format,
17919
17727
  absolutePath
17920
17728
  };
@@ -17973,7 +17781,7 @@ function shouldAutoGenerateDefaultVariant(icon) {
17973
17781
  return looksLikeSvgMarkup(icon) || looksLikeSvgUrl(icon);
17974
17782
  }
17975
17783
  function inferVariantFormatFromPath(filePath) {
17976
- const ext = import_node_path25.default.extname(filePath).toLowerCase();
17784
+ const ext = import_node_path23.default.extname(filePath).toLowerCase();
17977
17785
  switch (ext) {
17978
17786
  case ".png":
17979
17787
  return "png";
@@ -18044,13 +17852,13 @@ async function uploadAppIconVariantAsset(input) {
18044
17852
  await AliyunService.uploadFile(sourcePath, DEFAULT_APP_ICON_VARIANT_BUCKET, objectKey);
18045
17853
  } finally {
18046
17854
  if (shouldCleanup) {
18047
- (0, import_node_fs20.rmSync)(import_node_path25.default.dirname(sourcePath), { recursive: true, force: true });
17855
+ (0, import_node_fs18.rmSync)(import_node_path23.default.dirname(sourcePath), { recursive: true, force: true });
18048
17856
  }
18049
17857
  }
18050
17858
  return `${DEFAULT_APP_ICON_VARIANT_PUBLIC_BASE_URL}/${objectKey}`;
18051
17859
  }
18052
17860
  function buildAppIconVariantObjectKey(input) {
18053
- return import_node_path25.default.posix.join(
17861
+ return import_node_path23.default.posix.join(
18054
17862
  "apps",
18055
17863
  `${resolveAppIconAssetStem(input.icon, input.appRef)}-${input.name}.${extensionForIconFormat(input.format)}`
18056
17864
  );
@@ -18059,8 +17867,8 @@ function resolveAppIconAssetStem(icon, appRef2) {
18059
17867
  if (icon) {
18060
17868
  try {
18061
17869
  const url = new URL(icon);
18062
- const ext = import_node_path25.default.posix.extname(url.pathname);
18063
- const basename = import_node_path25.default.posix.basename(url.pathname, ext);
17870
+ const ext = import_node_path23.default.posix.extname(url.pathname);
17871
+ const basename = import_node_path23.default.posix.basename(url.pathname, ext);
18064
17872
  const normalized = sanitizeAppIconAssetStem(basename);
18065
17873
  if (normalized) {
18066
17874
  return normalized;
@@ -18089,9 +17897,9 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
18089
17897
  if (!bytes) {
18090
17898
  throw new Error("App icon variant upload requires bytes or a source file.");
18091
17899
  }
18092
- const tempDir = (0, import_node_fs20.mkdtempSync)(import_node_path25.default.join(import_node_os10.default.tmpdir(), "pmate-app-icon-"));
18093
- const tempPath = import_node_path25.default.join(tempDir, import_node_path25.default.basename(objectKey) || `variant.${extensionForIconFormat(format)}`);
18094
- (0, import_node_fs20.writeFileSync)(tempPath, bytes);
17900
+ const tempDir = (0, import_node_fs18.mkdtempSync)(import_node_path23.default.join(import_node_os9.default.tmpdir(), "pmate-app-icon-"));
17901
+ const tempPath = import_node_path23.default.join(tempDir, import_node_path23.default.basename(objectKey) || `variant.${extensionForIconFormat(format)}`);
17902
+ (0, import_node_fs18.writeFileSync)(tempPath, bytes);
18095
17903
  return tempPath;
18096
17904
  }
18097
17905
 
@@ -18099,7 +17907,6 @@ function writeTempAppIconVariantFile(objectKey, format, bytes) {
18099
17907
  init_namespacedRef();
18100
17908
  var AppCommandHandler = class {
18101
17909
  async handle(args) {
18102
- if (args.action === "build") return buildDesktop(args);
18103
17910
  const token = this.readToken();
18104
17911
  const baseUrl = this.resolveBaseUrl(args.baseUrl);
18105
17912
  switch (args.action) {
@@ -18301,10 +18108,10 @@ var AppCommandHandler = class {
18301
18108
  }
18302
18109
  readJsonFile(filePath) {
18303
18110
  const absolutePath = this.resolveFilePath(filePath);
18304
- if (!(0, import_node_fs21.existsSync)(absolutePath)) {
18111
+ if (!(0, import_node_fs19.existsSync)(absolutePath)) {
18305
18112
  throw new Error(`JSON file not found: ${absolutePath}`);
18306
18113
  }
18307
- const raw = (0, import_node_fs21.readFileSync)(absolutePath, "utf8");
18114
+ const raw = (0, import_node_fs19.readFileSync)(absolutePath, "utf8");
18308
18115
  try {
18309
18116
  return JSON.parse(raw);
18310
18117
  } catch (error) {
@@ -18314,10 +18121,10 @@ var AppCommandHandler = class {
18314
18121
  }
18315
18122
  async preparePayload(filePath, appRef2) {
18316
18123
  const absolutePath = this.resolveFilePath(filePath);
18317
- return prepareAppPayload(this.readJsonFile(filePath), import_node_path26.default.dirname(absolutePath), { appRef: appRef2 });
18124
+ return prepareAppPayload(this.readJsonFile(filePath), import_node_path24.default.dirname(absolutePath), { appRef: appRef2 });
18318
18125
  }
18319
18126
  resolveFilePath(filePath) {
18320
- return import_node_path26.default.resolve(process.cwd(), filePath);
18127
+ return import_node_path24.default.resolve(process.cwd(), filePath);
18321
18128
  }
18322
18129
  async request(baseUrl, token, method, pathname, body) {
18323
18130
  const response = await fetch(`${baseUrl}${pathname}`, {
@@ -18437,18 +18244,207 @@ function readNamespaceFromPayload(payload) {
18437
18244
  }
18438
18245
 
18439
18246
  // src/commands/ServiceCommandHandler.ts
18440
- var import_node_fs25 = require("fs");
18247
+ var import_node_fs26 = require("fs");
18441
18248
  var import_promises5 = require("fs/promises");
18442
- var import_node_path30 = __toESM(require("path"));
18249
+ var import_node_path31 = __toESM(require("path"));
18443
18250
  var import_node_child_process13 = require("child_process");
18444
18251
  var import_promises6 = require("readline/promises");
18445
18252
 
18446
- // src/services/IosBuildService.ts
18447
- var import_node_child_process11 = require("child_process");
18448
- var import_node_crypto6 = require("crypto");
18449
- var import_node_fs23 = require("fs");
18450
- var import_node_os12 = __toESM(require("os"));
18451
- var import_node_path28 = __toESM(require("path"));
18253
+ // src/services/NativeServiceDeploy.ts
18254
+ var import_node_path29 = __toESM(require("path"));
18255
+ var import_node_fs24 = require("fs");
18256
+
18257
+ // src/electronBuild.ts
18258
+ var import_node_child_process9 = require("child_process");
18259
+ var import_node_fs21 = require("fs");
18260
+ var import_node_os10 = require("os");
18261
+ var import_node_path26 = __toESM(require("path"));
18262
+
18263
+ // src/desktopRelease.ts
18264
+ init_sessionStore();
18265
+ var import_node_crypto4 = require("crypto");
18266
+ var import_node_fs20 = require("fs");
18267
+ var import_node_path25 = __toESM(require("path"));
18268
+ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
18269
+ const segments = [...app.split(":"), version, platform, arch];
18270
+ if (app.split(":").length !== 2 || segments.some((s) => !/^[\w.-]+$/.test(s) || s === "." || s === "..")) throw new Error("Invalid desktop release identity");
18271
+ if (!["mac", "win"].includes(platform) || !["arm64", "x64"].includes(arch) || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) throw new Error("Desktop publication requires a stable version and supported target");
18272
+ const { token } = readRequiredSession({ preferredApp: DEFAULT_APP_ID });
18273
+ const bucket = "parrot-static";
18274
+ const prefix = `desktop/${segments.join("/")}/`;
18275
+ const url = (key) => `https://parrot-static.pmate.chat/${key.split("/").map(encodeURIComponent).join("/")}`;
18276
+ const artifacts = (0, import_node_fs20.readdirSync)(directory, { withFileTypes: true }).filter((entry) => entry.isFile() && (platform === "mac" ? /\.(dmg|zip)$/i : /\.(exe|zip)$/i).test(entry.name)).sort((a, b) => a.name.localeCompare(b.name)).map((entry) => {
18277
+ const bytes = (0, import_node_fs20.readFileSync)(import_node_path25.default.join(directory, entry.name));
18278
+ const objectKey = prefix + entry.name;
18279
+ return { name: entry.name, objectKey, downloadUrl: url(objectKey), sha256: (0, import_node_crypto4.createHash)("sha256").update(bytes).digest("hex"), size: bytes.length };
18280
+ });
18281
+ if (!artifacts.length) throw new Error("No desktop installers found to publish");
18282
+ const manifestKey = prefix + "release.json";
18283
+ const existing = await AliyunService.readJsonObject(bucket, manifestKey);
18284
+ const release = { schemaVersion: 1, app, version, platform, arch, artifacts };
18285
+ if (existing !== null && JSON.stringify(existing) !== JSON.stringify(release)) throw new Error("Desktop release already exists with different artifacts; bump the app version");
18286
+ for (const artifact of artifacts) await AliyunService.uploadFile(import_node_path25.default.join(directory, artifact.name), bucket, artifact.objectKey);
18287
+ await AliyunService.uploadJsonObject(bucket, manifestKey, release);
18288
+ const base = (process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
18289
+ const response = await fetch(`${base}/versions/${encodeURIComponent(app)}`, {
18290
+ method: "POST",
18291
+ headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
18292
+ body: JSON.stringify({ version, platform, arch, manifestUrl: url(manifestKey) }),
18293
+ signal: AbortSignal.timeout(3e4),
18294
+ redirect: "error"
18295
+ });
18296
+ const result = await response.json();
18297
+ if (!response.ok || result.success !== true) throw new Error(`Installers uploaded but version registration failed: ${result.message || response.status}. Retry this release before announcing it.`);
18298
+ return { bucket, manifestUrl: url(manifestKey), downloads: artifacts };
18299
+ }
18300
+
18301
+ // src/electronBuild.ts
18302
+ var ELECTRON_VERSION = "44.5.1";
18303
+ var BUILDER_VERSION = "26.15.3";
18304
+ function readDesktopConfig(file, appId) {
18305
+ const c = JSON.parse((0, import_node_fs21.readFileSync)(file, "utf8"));
18306
+ if (c.schemaVersion !== 2 || c.app !== appId) throw new Error("Desktop config schemaVersion/app mismatch");
18307
+ for (const key of ["productName", "bundleId", "version", "icon"]) {
18308
+ if (typeof c[key] !== "string" || !c[key].trim()) throw new Error(`Missing desktop ${key}`);
18309
+ }
18310
+ if (!/^[a-zA-Z][\w-]*(\.[a-zA-Z][\w-]*)+$/.test(c.bundleId)) throw new Error("Invalid desktop bundleId");
18311
+ if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(c.version)) throw new Error("Invalid desktop version");
18312
+ const origin = (value) => {
18313
+ const url = new URL(value);
18314
+ if (url.protocol !== "https:" || url.origin !== value || url.username || url.password) throw new Error("Desktop origins must be exact HTTPS origins, without paths or credentials");
18315
+ };
18316
+ origin(c.origin);
18317
+ if (!Array.isArray(c.authOrigins)) throw new Error("authOrigins must be an array");
18318
+ c.authOrigins.forEach(origin);
18319
+ if (c.externalOrigins !== void 0 && !Array.isArray(c.externalOrigins)) throw new Error("externalOrigins must be an array");
18320
+ c.externalOrigins?.forEach(origin);
18321
+ if (c.notaryProfile !== void 0 && (typeof c.notaryProfile !== "string" || !c.notaryProfile.trim())) throw new Error("Invalid notaryProfile");
18322
+ if ("web" in c) throw new Error("Remote desktop builds do not accept web build configuration; remove web");
18323
+ return c;
18324
+ }
18325
+ function repositoryRoot(cwd) {
18326
+ let dir = import_node_path26.default.resolve(cwd);
18327
+ while (true) {
18328
+ if ((0, import_node_fs21.existsSync)(import_node_path26.default.join(dir, ".git"))) return dir;
18329
+ const parent = import_node_path26.default.dirname(dir);
18330
+ if (parent === dir) return void 0;
18331
+ dir = parent;
18332
+ }
18333
+ }
18334
+ function resolveDesktopPaths(args, cwd = process.cwd()) {
18335
+ const root = repositoryRoot(cwd);
18336
+ const name = args.id.split(":")[1];
18337
+ let file = args.config ? import_node_path26.default.resolve(cwd, args.config) : void 0;
18338
+ if (!file) {
18339
+ let dir = import_node_path26.default.resolve(cwd);
18340
+ while (true) {
18341
+ const candidates = [.../* @__PURE__ */ new Set([import_node_path26.default.join(dir, "desktop.config.json"), import_node_path26.default.join(dir, "apps", name, "desktop.config.json")])];
18342
+ const matches = candidates.filter((candidate) => (0, import_node_fs21.existsSync)(candidate) && JSON.parse((0, import_node_fs21.readFileSync)(candidate, "utf8")).app === args.id);
18343
+ if (matches.length > 1) throw new Error("Ambiguous desktop config; specify --config");
18344
+ if (matches.length === 1) {
18345
+ file = matches[0];
18346
+ break;
18347
+ }
18348
+ const parent = import_node_path26.default.dirname(dir);
18349
+ if (dir === root || parent === dir) break;
18350
+ dir = parent;
18351
+ }
18352
+ }
18353
+ if (!file) throw new Error(`No desktop config for ${args.id}; specify --config`);
18354
+ return { file, output: args.outDir ? import_node_path26.default.resolve(cwd, args.outDir) : import_node_path26.default.join(root ?? import_node_path26.default.dirname(file), "release", name) };
18355
+ }
18356
+ function desktopBuildEnvironment(config, env = process.env) {
18357
+ return { ...env, ...env.APPLE_KEYCHAIN_PROFILE ? {} : config.notaryProfile ? { APPLE_KEYCHAIN_PROFILE: config.notaryProfile } : {} };
18358
+ }
18359
+ function requireNotaryCredentials(env) {
18360
+ if (env.APPLE_ID || env.APPLE_APP_SPECIFIC_PASSWORD) {
18361
+ if (env.APPLE_ID && env.APPLE_APP_SPECIFIC_PASSWORD && env.APPLE_TEAM_ID) return;
18362
+ } else if (env.APPLE_API_KEY || env.APPLE_API_KEY_ID || env.APPLE_API_ISSUER) {
18363
+ if (env.APPLE_API_KEY && env.APPLE_API_KEY_ID && env.APPLE_API_ISSUER) return;
18364
+ } else if (env.APPLE_KEYCHAIN_PROFILE) return;
18365
+ throw new Error("macOS signed builds require complete Apple notarization credentials or APPLE_KEYCHAIN_PROFILE");
18366
+ }
18367
+ function requireSigningIdentity(env, inspect = () => (0, import_node_child_process9.execFileSync)("security", ["find-identity", "-v", "-p", "codesigning"], { encoding: "utf8" })) {
18368
+ if (env.CSC_LINK) return;
18369
+ if (!inspect().includes("Developer ID Application:")) throw new Error("No Developer ID Application signing identity available");
18370
+ }
18371
+ async function publishVerifiedDesktop(args, artifacts, config, verify = verifyMacRelease, upload = uploadDesktopArtifacts) {
18372
+ if (args.signed && args.platform === "mac") await verify(artifacts);
18373
+ if (args.local || args.dir || !args.signed) return void 0;
18374
+ return upload(artifacts, config.app, config.version, args.platform, args.arch);
18375
+ }
18376
+ async function verifyMacRelease(artifacts, run = runBuildCommand, inspect = (app) => (0, import_node_child_process9.spawnSync)("codesign", ["-dv", "--verbose=4", app], { encoding: "utf8" })) {
18377
+ const apps = (0, import_node_fs21.readdirSync)(artifacts, { recursive: true, withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name.endsWith(".app")).map((entry) => import_node_path26.default.join(entry.parentPath, entry.name)).filter((file) => !file.slice(0, -4).includes(".app/"));
18378
+ if (!apps.length) throw new Error("No packaged macOS app found; refusing publication");
18379
+ for (const app of apps) {
18380
+ await run(["codesign", "--verify", "--deep", "--strict", app], artifacts);
18381
+ const signature = inspect(app);
18382
+ if (signature.status !== 0 || !signature.stderr.includes("Authority=Developer ID Application:")) throw new Error("Packaged app lacks Developer ID Application signature");
18383
+ await run(["xcrun", "stapler", "validate", app], artifacts);
18384
+ await run(["spctl", "--assess", "--type", "execute", "--verbose=2", app], artifacts);
18385
+ }
18386
+ }
18387
+ async function runBuildCommand(command, cwd, env = process.env) {
18388
+ await new Promise((resolve, reject) => {
18389
+ const child = (0, import_node_child_process9.spawn)(command[0], command.slice(1), { cwd, env, stdio: "inherit", shell: false });
18390
+ child.once("error", reject);
18391
+ child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`${command[0]} failed (${signal ?? code})`)));
18392
+ });
18393
+ }
18394
+ async function buildDesktop(args) {
18395
+ const { file, output } = resolveDesktopPaths(args);
18396
+ const c = readDesktopConfig(file, args.id);
18397
+ const base = import_node_path26.default.dirname(file);
18398
+ const icon = import_node_path26.default.resolve(base, c.icon);
18399
+ const env = desktopBuildEnvironment(c);
18400
+ if (!(0, import_node_fs21.existsSync)(icon) || !(0, import_node_fs21.statSync)(icon).isFile()) throw new Error(`Desktop icon not found: ${icon}`);
18401
+ if (!["mac", "win"].includes(args.platform) || !["arm64", "x64"].includes(args.arch)) throw new Error("Supported target: mac|win --arch arm64|x64");
18402
+ if (args.platform === "mac" && process.platform !== "darwin") throw new Error("macOS desktop packaging requires a macOS build host");
18403
+ const plan = { config: file, notaryProfile: env.APPLE_KEYCHAIN_PROFILE, app: c.app, productName: c.productName, version: c.version, target: "electron", platform: args.platform, arch: args.arch, contentSource: "remote", origin: c.origin, output, electron: ELECTRON_VERSION, builder: BUILDER_VERSION, signed: args.signed };
18404
+ console.log(JSON.stringify({ phase: "plan", ...plan }, null, 2));
18405
+ if (args.dryRun) return;
18406
+ if (args.signed && args.platform === "mac") {
18407
+ requireNotaryCredentials(env);
18408
+ requireSigningIdentity(env);
18409
+ }
18410
+ (0, import_node_fs21.mkdirSync)(output, { recursive: true });
18411
+ const staging = (0, import_node_fs21.mkdtempSync)(import_node_path26.default.join(output, ".desktop-build-"));
18412
+ const appDir = import_node_path26.default.join(staging, "app");
18413
+ (0, import_node_fs21.mkdirSync)(appDir);
18414
+ const templateDir = import_node_path26.default.join(__dirname, "templates", "electron");
18415
+ (0, import_node_fs21.cpSync)(templateDir, appDir, { recursive: true });
18416
+ (0, import_node_fs21.writeFileSync)(import_node_path26.default.join(appDir, "desktop-config.json"), JSON.stringify({ app: c.app, productName: c.productName, origin: c.origin, authOrigins: c.authOrigins, externalOrigins: c.externalOrigins ?? [], bundleId: c.bundleId }));
18417
+ (0, import_node_fs21.writeFileSync)(import_node_path26.default.join(appDir, "package.json"), JSON.stringify({ name: c.bundleId.replace(/\./g, "-"), version: c.version, description: `${c.productName} desktop application`, author: "PMate", main: "main.cjs", dependencies: { "@pmate/chat-sdk": "0.11.7" } }));
18418
+ await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
18419
+ const cache = import_node_path26.default.join((0, import_node_os10.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
18420
+ (0, import_node_fs21.mkdirSync)(cache, { recursive: true });
18421
+ const toolPackage = { name: "pmate-desktop-toolchain", private: true, dependencies: { electron: ELECTRON_VERSION, "electron-builder": BUILDER_VERSION } };
18422
+ if (!(0, import_node_fs21.existsSync)(import_node_path26.default.join(cache, "node_modules", "electron", "dist", "Electron.app")) || !(0, import_node_fs21.existsSync)(import_node_path26.default.join(cache, "node_modules", "electron-builder", "cli.js"))) {
18423
+ (0, import_node_fs21.writeFileSync)(import_node_path26.default.join(cache, "package.json"), JSON.stringify(toolPackage));
18424
+ await runBuildCommand(["npm", (0, import_node_fs21.existsSync)(import_node_path26.default.join(cache, "package-lock.json")) ? "ci" : "install", "--no-audit", "--no-fund"], cache);
18425
+ }
18426
+ const builderConfig = {
18427
+ appId: c.bundleId,
18428
+ productName: c.productName,
18429
+ electronVersion: ELECTRON_VERSION,
18430
+ directories: { app: appDir, output: import_node_path26.default.join(staging, "artifacts") },
18431
+ files: ["**/*"],
18432
+ asar: true,
18433
+ artifactName: "${productName}-${version}-${arch}.${ext}",
18434
+ publish: [{ provider: "generic", url: `https://parrot-static.pmate.chat/desktop/${c.app.split(":").map(encodeURIComponent).join("/")}/${c.version}/${args.platform}/${args.arch}/` }],
18435
+ mac: { icon, target: args.dir ? ["dir"] : ["dmg", "zip"], category: "public.app-category.social-networking", hardenedRuntime: args.signed, extendInfo: { NSMicrophoneUsageDescription: `${c.productName} uses your microphone for voice calls and voice messages.` }, ...args.signed ? {} : { identity: "-", notarize: false } },
18436
+ win: { icon, target: args.dir ? ["dir"] : ["nsis", "zip"], ...args.signed ? {} : { signExecutable: false } },
18437
+ forceCodeSigning: args.signed
18438
+ };
18439
+ const configPath = import_node_path26.default.join(staging, "builder.json");
18440
+ (0, import_node_fs21.writeFileSync)(configPath, JSON.stringify(builderConfig));
18441
+ await runBuildCommand([process.execPath, import_node_path26.default.join(cache, "node_modules", "electron-builder", "cli.js"), "--config", configPath, args.platform === "mac" ? "--mac" : "--win", `--${args.arch}`, "--publish", "never"], appDir, { ...env, ...args.signed ? {} : { CSC_IDENTITY_AUTO_DISCOVERY: "false" } });
18442
+ const result = { ...plan, signature: args.signed ? args.platform === "mac" ? "Developer ID signed; notarization and Gatekeeper required before publication" : "configured-signing-required; verify Authenticode before distribution" : args.platform === "mac" ? "ad-hoc; local development" : "unsigned; local development", artifacts: import_node_path26.default.join(staging, "artifacts") };
18443
+ (0, import_node_fs21.writeFileSync)(import_node_path26.default.join(staging, "build-report.json"), JSON.stringify(result, null, 2));
18444
+ const publication = await publishVerifiedDesktop(args, result.artifacts, c);
18445
+ (0, import_node_fs21.writeFileSync)(import_node_path26.default.join(staging, "build-report.json"), JSON.stringify({ ...result, publication }, null, 2));
18446
+ console.log(JSON.stringify({ phase: "complete", report: import_node_path26.default.join(staging, "build-report.json"), artifacts: result.artifacts, signature: result.signature, publication }, null, 2));
18447
+ }
18452
18448
 
18453
18449
  // src/services/AndroidApkReleaseService.ts
18454
18450
  var import_node_child_process10 = require("child_process");
@@ -18504,12 +18500,24 @@ async function signAndroidApk(apkPath, signing) {
18504
18500
  process.removeListener("SIGTERM", interrupted);
18505
18501
  }
18506
18502
  }
18503
+ function androidArtifactIdentity(service) {
18504
+ const id = "type" in service ? service.build?.artifactServiceId : void 0;
18505
+ if (!id) return { namespace: service.namespace, name: service.name };
18506
+ const match = /^([A-Za-z0-9_-]+):([A-Za-z0-9_.-]+)$/.exec(id);
18507
+ if (!match || match[1] !== service.namespace || [".", ".."].includes(match[2])) throw new Error("Android artifactServiceId must be a valid service ID in the same namespace");
18508
+ return { namespace: match[1], name: match[2] };
18509
+ }
18510
+ function androidUpdateManifestKeys(service) {
18511
+ const identity = androidArtifactIdentity(service);
18512
+ return [.../* @__PURE__ */ new Set([buildAndroidLatestManifestObjectKey(service.namespace, service.name), buildAndroidLatestManifestObjectKey(identity.namespace, identity.name)])];
18513
+ }
18507
18514
  var AndroidApkReleaseService = class {
18508
18515
  constructor(registry) {
18509
18516
  this.registry = registry;
18510
18517
  }
18511
18518
  async release(service, options) {
18512
18519
  this.assertAndroidService(service);
18520
+ const identity = androidArtifactIdentity(service);
18513
18521
  const repoRoot = this.resolveRepoRoot(service, options.cwd);
18514
18522
  const appDir = this.resolveAppDir(service, repoRoot);
18515
18523
  const signing = options.variant.toLowerCase() === "release" ? await this.loadSigning(service.id, options.env) : void 0;
@@ -18527,7 +18535,7 @@ var AndroidApkReleaseService = class {
18527
18535
  `APK metadata ${metadata.versionName} (${metadata.versionCode}) does not match bumped version ${bump.versionName} (${bump.versionCode}).`
18528
18536
  );
18529
18537
  }
18530
- const objectKey = buildAndroidApkObjectKey(service.namespace, service.name, metadata.versionName);
18538
+ const objectKey = buildAndroidApkObjectKey(identity.namespace, identity.name, metadata.versionName);
18531
18539
  const existing = await this.findExistingObject(objectKey);
18532
18540
  if (existing && !options.force) {
18533
18541
  throw new Error(`APK already exists at ${ANDROID_APK_PUBLIC_BASE_URL}/${objectKey}. Re-run with --force to overwrite it.`);
@@ -18551,7 +18559,7 @@ var AndroidApkReleaseService = class {
18551
18559
  size,
18552
18560
  gitCommit: await this.readGitCommit(repoRoot)
18553
18561
  };
18554
- const catalogKey = service.namespace === "pmate" && service.name === "factory-android" && options.env === "preview" ? "apks/pmate/factory-android/releases.json" : null;
18562
+ const catalogKey = identity.namespace === "pmate" && identity.name === "factory-android" && options.env === "preview" ? "apks/pmate/factory-android/releases.json" : null;
18555
18563
  const nextCatalog = catalogKey ? mergeFactoryApkCatalog(await AliyunService.readJsonObject(ANDROID_APK_BUCKET, catalogKey), artifact) : null;
18556
18564
  await AliyunService.uploadFile(apkPath, ANDROID_APK_BUCKET, objectKey);
18557
18565
  if (this.registry) {
@@ -18585,14 +18593,16 @@ var AndroidApkReleaseService = class {
18585
18593
  releaseNotes: options.releaseNotes,
18586
18594
  minimumVersionCode: options.minimumVersionCode
18587
18595
  });
18588
- const objectKey = buildAndroidLatestManifestObjectKey(service.namespace, service.name);
18596
+ const objectKeys = androidUpdateManifestKeys(service);
18589
18597
  const tempDir = (0, import_node_fs22.mkdtempSync)(import_node_path27.default.join(import_node_os11.default.tmpdir(), "pmate-apk-latest-"));
18590
18598
  const manifestPath = import_node_path27.default.join(tempDir, "latest.json");
18591
18599
  try {
18592
18600
  (0, import_node_fs22.writeFileSync)(manifestPath, `${JSON.stringify(manifest, null, 2)}
18593
18601
  `);
18594
- await AliyunService.uploadFile(manifestPath, ANDROID_APK_BUCKET, objectKey);
18595
- ui.success(`Published Android update manifest ${ANDROID_APK_PUBLIC_BASE_URL}/${objectKey}`);
18602
+ for (const objectKey of objectKeys) {
18603
+ await AliyunService.uploadFile(manifestPath, ANDROID_APK_BUCKET, objectKey);
18604
+ ui.success(`Published Android update manifest ${ANDROID_APK_PUBLIC_BASE_URL}/${objectKey}`);
18605
+ }
18596
18606
  } finally {
18597
18607
  (0, import_node_fs22.rmSync)(tempDir, { recursive: true, force: true });
18598
18608
  }
@@ -18607,7 +18617,8 @@ var AndroidApkReleaseService = class {
18607
18617
  ui.warn("Falling back to OSS object listing for APK versions", error instanceof Error ? error.message : String(error));
18608
18618
  }
18609
18619
  }
18610
- const prefix = `apks/${service.namespace}/${service.name}`;
18620
+ const identity = androidArtifactIdentity(service);
18621
+ const prefix = `apks/${identity.namespace}/${identity.name}`;
18611
18622
  const objects = await AliyunService.listObjects(ANDROID_APK_BUCKET, prefix);
18612
18623
  return objects.filter((item) => item.name.endsWith(".apk")).map((item) => {
18613
18624
  const versionName = import_node_path27.default.basename(item.name, ".apk");
@@ -18941,6 +18952,11 @@ function capitalize(value) {
18941
18952
  }
18942
18953
 
18943
18954
  // src/services/IosBuildService.ts
18955
+ var import_node_child_process11 = require("child_process");
18956
+ var import_node_crypto6 = require("crypto");
18957
+ var import_node_fs23 = require("fs");
18958
+ var import_node_os12 = __toESM(require("os"));
18959
+ var import_node_path28 = __toESM(require("path"));
18944
18960
  function iosBuildInteger(value) {
18945
18961
  if (!/^(0|[1-9]\d*)$/.test(String(value)) || !Number.isSafeInteger(Number(value))) {
18946
18962
  throw new Error(`iOS Build must be a non-negative safe integer: ${String(value)}`);
@@ -19091,6 +19107,87 @@ async function readPlist(input) {
19091
19107
  });
19092
19108
  }
19093
19109
 
19110
+ // src/services/NativeServiceDeploy.ts
19111
+ var electronKeys = ["config", "platform", "arch", "outDir", "unsigned", "signed", "dir"];
19112
+ var androidKeys = ["variant", "bump", "force", "releaseNotes", "minimumVersionCode"];
19113
+ var iosKeys = ["scheme", "team", "project", "workspace", "lastBuild"];
19114
+ function rejectNativeOverrides(args, allowed = []) {
19115
+ for (const key of [...electronKeys, ...iosKeys, ...androidKeys, "local", "dryRun"]) {
19116
+ if (args[key] !== void 0 && !allowed.includes(key)) throw new Error(`--${key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)} is not supported for this service type`);
19117
+ }
19118
+ }
19119
+ var NativeServiceDeploy = class {
19120
+ constructor(deps = {}, registry) {
19121
+ this.deps = deps;
19122
+ this.registry = registry;
19123
+ }
19124
+ async deploy(service, args) {
19125
+ if (!("type" in service) || !["electron", "ios", "android"].includes(service.type)) throw new Error("Native deployment requires an electron, ios or android service");
19126
+ if (service.type !== "android" && (args.env ?? "prod") !== "prod") throw new Error("Native deployment currently supports only --env prod");
19127
+ const repository = service.repository ?? service.mobile?.repository;
19128
+ const dir = service.dir ?? service.mobile?.dir;
19129
+ if (!dir || !repository && !args.cwd) throw new Error("Native service requires repository and dir");
19130
+ const root = args.cwd ? import_node_path29.default.resolve(args.cwd) : resolveRepositoryLocalRoot(repository);
19131
+ const appDir = import_node_path29.default.resolve(root, dir);
19132
+ if (!(0, import_node_fs24.existsSync)(appDir)) throw new Error(`Service source directory not found: ${appDir}`);
19133
+ const settings = service.build ?? {};
19134
+ if (service.type === "android") {
19135
+ rejectNativeOverrides(args, [...androidKeys, "dryRun"]);
19136
+ const artifactIdentity = androidArtifactIdentity(service);
19137
+ const updateManifests = androidUpdateManifestKeys(service);
19138
+ const options2 = {
19139
+ cwd: root,
19140
+ env: args.env ?? "prod",
19141
+ variant: args.variant ?? settings.variant ?? "release",
19142
+ bump: args.bump ?? settings.bump ?? "patch",
19143
+ force: !!args.force,
19144
+ releaseNotes: args.releaseNotes,
19145
+ minimumVersionCode: args.minimumVersionCode
19146
+ };
19147
+ if (!["dev", "preview", "prod"].includes(options2.env)) throw new Error("Android deployment requires env dev, preview or prod");
19148
+ if (!["release", "debug"].includes(options2.variant)) throw new Error("Android variant must be release or debug");
19149
+ if (options2.env === "prod" && options2.variant !== "release") throw new Error("Android production deployment requires a signed release variant");
19150
+ if (!["patch", "minor", "major"].includes(options2.bump)) throw new Error("Android bump must be patch, minor or major");
19151
+ if (args.dryRun) return { serviceId: service.id, status: "dry-run", type: "android", appDir, artifactIdentity, updateManifests, packageName: service.mobile && "packageName" in service.mobile ? service.mobile.packageName : void 0, ...options2 };
19152
+ const artifact = await (this.deps.android ?? new AndroidApkReleaseService(this.registry)).release(service, options2);
19153
+ return { ...artifact, status: "published" };
19154
+ }
19155
+ if (service.type === "electron") {
19156
+ rejectNativeOverrides(args, [...electronKeys, "local", "dryRun"]);
19157
+ if (service.appIds?.length !== 1) throw new Error("Electron service requires exactly one appIds application identity");
19158
+ const app = service.appIds[0];
19159
+ const options2 = {
19160
+ id: app,
19161
+ target: "electron",
19162
+ config: args.config ? import_node_path29.default.resolve(args.config) : import_node_path29.default.resolve(appDir, settings.config ?? "desktop.config.json"),
19163
+ platform: args.platform ?? settings.platform ?? (process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : process.platform),
19164
+ arch: args.arch ?? settings.arch ?? process.arch,
19165
+ outDir: args.outDir ? import_node_path29.default.resolve(args.outDir) : import_node_path29.default.join(root, "release", service.name),
19166
+ signed: !args.unsigned,
19167
+ dir: !!args.dir,
19168
+ dryRun: !!args.dryRun,
19169
+ local: !!args.local,
19170
+ json: args.json
19171
+ };
19172
+ await (this.deps.desktop ?? buildDesktop)(options2);
19173
+ return { serviceId: service.id, appId: app, status: args.dryRun ? "dry-run" : args.local ? "local" : "published", platform: options2.platform, arch: options2.arch, output: options2.outDir };
19174
+ }
19175
+ rejectNativeOverrides(args, [...iosKeys, "dryRun"]);
19176
+ const options = {
19177
+ cwd: root,
19178
+ scheme: args.scheme ?? settings.scheme ?? "",
19179
+ team: args.team ?? settings.team,
19180
+ project: args.project ?? (args.workspace ? void 0 : settings.project),
19181
+ workspace: args.workspace ?? (args.project ? void 0 : settings.workspace),
19182
+ lastBuild: args.lastBuild
19183
+ };
19184
+ if (!options.scheme.trim()) throw new Error("iOS service requires build.scheme; update the service configuration or pass --scheme");
19185
+ if (options.project && options.workspace) throw new Error("Use only one project or workspace");
19186
+ if (args.dryRun) return { serviceId: service.id, status: "dry-run", type: "ios", appDir, ...options };
19187
+ return { ...await (this.deps.ios ?? new IosBuildService()).build(service, options) };
19188
+ }
19189
+ };
19190
+
19094
19191
  // src/services/DeveloperLogsClient.ts
19095
19192
  init_sessionStore();
19096
19193
  init_namespacedRef();
@@ -19178,9 +19275,9 @@ async function requestDeveloperLogTool(tool, params, fetcher = fetch, delegate)
19178
19275
  }
19179
19276
 
19180
19277
  // src/services/ServiceRuntimeRunner.ts
19181
- var import_node_fs24 = require("fs");
19278
+ var import_node_fs25 = require("fs");
19182
19279
  var import_node_os13 = __toESM(require("os"));
19183
- var import_node_path29 = __toESM(require("path"));
19280
+ var import_node_path30 = __toESM(require("path"));
19184
19281
  var import_node_child_process12 = require("child_process");
19185
19282
  var import_node_readline = require("readline");
19186
19283
  var import_chalk3 = __toESM(require("chalk"));
@@ -19680,14 +19777,14 @@ var ServiceRuntimeRunner = class {
19680
19777
  }
19681
19778
  resolveRepoRoot(service, cwd) {
19682
19779
  if (cwd) {
19683
- return import_node_path29.default.resolve(process.cwd(), cwd);
19780
+ return import_node_path30.default.resolve(process.cwd(), cwd);
19684
19781
  }
19685
19782
  const repository = this.getType(service) === "vite" || this.getType(service) === "static" ? this.getRepoStaticSite(service).repository.trim() : this.getType(service) === "fc" ? this.getFc(service).repository?.trim() : this.getType(service) === "ios" || this.getType(service) === "android" ? void 0 : this.getNetwork(service).repository?.trim();
19686
19783
  if (repository) {
19687
19784
  const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
19688
19785
  if (repoName) {
19689
- const candidate = import_node_path29.default.join(import_node_os13.default.homedir(), "dev", "pmate", repoName);
19690
- if ((0, import_node_fs24.existsSync)(candidate)) {
19786
+ const candidate = import_node_path30.default.join(import_node_os13.default.homedir(), "dev", "pmate", repoName);
19787
+ if ((0, import_node_fs25.existsSync)(candidate)) {
19691
19788
  return candidate;
19692
19789
  }
19693
19790
  }
@@ -19700,13 +19797,13 @@ var ServiceRuntimeRunner = class {
19700
19797
  if (!dir) {
19701
19798
  throw new Error(`Missing service dir for ${service.id}`);
19702
19799
  }
19703
- return import_node_path29.default.resolve(repoRoot, dir);
19800
+ return import_node_path30.default.resolve(repoRoot, dir);
19704
19801
  }
19705
19802
  async deployVite(service, options) {
19706
19803
  this.assertDeployableStaticSite(service);
19707
19804
  const appDir = this.resolveLocalDir(service, options.cwd);
19708
- const packageJsonPath = import_node_path29.default.join(appDir, "package.json");
19709
- if (!(0, import_node_fs24.existsSync)(packageJsonPath)) {
19805
+ const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
19806
+ if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
19710
19807
  throw new Error(`No package.json found at ${packageJsonPath}`);
19711
19808
  }
19712
19809
  const pkg2 = this.loadPackageJson(packageJsonPath);
@@ -19721,8 +19818,8 @@ var ServiceRuntimeRunner = class {
19721
19818
  this.resolveRepoRoot(service, options.cwd),
19722
19819
  buildEnv
19723
19820
  );
19724
- const distDir = import_node_path29.default.join(appDir, "dist");
19725
- if (!(0, import_node_fs24.existsSync)(distDir)) {
19821
+ const distDir = import_node_path30.default.join(appDir, "dist");
19822
+ if (!(0, import_node_fs25.existsSync)(distDir)) {
19726
19823
  throw new Error(`No dist directory found at ${distDir}`);
19727
19824
  }
19728
19825
  const site = this.getSite(service);
@@ -19735,8 +19832,8 @@ var ServiceRuntimeRunner = class {
19735
19832
  async deployStatic(service, options) {
19736
19833
  this.assertDeployableStaticSite(service);
19737
19834
  const appDir = this.resolveLocalDir(service, options.cwd);
19738
- const srcDir = import_node_path29.default.join(appDir, "src");
19739
- if (!(0, import_node_fs24.existsSync)(srcDir)) {
19835
+ const srcDir = import_node_path30.default.join(appDir, "src");
19836
+ if (!(0, import_node_fs25.existsSync)(srcDir)) {
19740
19837
  throw new Error(`No src directory found at ${srcDir}`);
19741
19838
  }
19742
19839
  const site = this.getSite(service);
@@ -19770,8 +19867,8 @@ var ServiceRuntimeRunner = class {
19770
19867
  this.validateFcConfig(service, fc);
19771
19868
  const repoRoot = this.resolveRepoRoot(service, options.cwd);
19772
19869
  const appDir = this.resolveLocalDir(service, options.cwd);
19773
- const packageJsonPath = import_node_path29.default.join(appDir, "package.json");
19774
- if (!(0, import_node_fs24.existsSync)(packageJsonPath)) {
19870
+ const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
19871
+ if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
19775
19872
  throw new Error(`No package.json found at ${packageJsonPath}`);
19776
19873
  }
19777
19874
  const pkg2 = this.loadPackageJson(packageJsonPath);
@@ -19824,15 +19921,15 @@ var ServiceRuntimeRunner = class {
19824
19921
  const repoRoot = this.resolveRepoRoot(service, options.cwd);
19825
19922
  const appDir = this.resolveLocalDir(service, options.cwd);
19826
19923
  await this.ensurePnpmWorkspaceRoot(repoRoot);
19827
- const configPath = import_node_path29.default.join(appDir, fc.configFile ?? "s.yaml");
19828
- if (!(0, import_node_fs24.existsSync)(configPath)) {
19924
+ const configPath = import_node_path30.default.join(appDir, fc.configFile ?? "s.yaml");
19925
+ if (!(0, import_node_fs25.existsSync)(configPath)) {
19829
19926
  throw new Error(`Missing FC config file at ${configPath}`);
19830
19927
  }
19831
- const packageJsonPath = import_node_path29.default.join(appDir, "package.json");
19832
- if (!(0, import_node_fs24.existsSync)(packageJsonPath)) {
19928
+ const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
19929
+ if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
19833
19930
  throw new Error(`No package.json found at ${packageJsonPath}`);
19834
19931
  }
19835
- const rawConfig = (0, import_node_fs24.readFileSync)(configPath, "utf8");
19932
+ const rawConfig = (0, import_node_fs25.readFileSync)(configPath, "utf8");
19836
19933
  if (!rawConfig.includes(fc.functionName)) {
19837
19934
  throw new Error(`FC config ${configPath} does not mention functionName ${fc.functionName}`);
19838
19935
  }
@@ -20122,7 +20219,7 @@ var ServiceRuntimeRunner = class {
20122
20219
  const serverAddress = await resolveServerAddress(server);
20123
20220
  const templateName = exposeType === "websocket" ? "nginx.ws.template" : exposeType === "mixed" ? "nginx.mixed.template" : "nginx.rest.template";
20124
20221
  const templatePath = this.resolveTemplatePath(templateName);
20125
- const template = (0, import_node_fs24.readFileSync)(templatePath, "utf8");
20222
+ const template = (0, import_node_fs25.readFileSync)(templatePath, "utf8");
20126
20223
  const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
20127
20224
  const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
20128
20225
  const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
@@ -20154,11 +20251,11 @@ var ServiceRuntimeRunner = class {
20154
20251
  }
20155
20252
  if (config.ensurePackageJson) {
20156
20253
  const appDir = this.resolveLocalDir(service, options.cwd);
20157
- const packageJsonPath = import_node_path29.default.join(appDir, "package.json");
20158
- if (!(0, import_node_fs24.existsSync)(packageJsonPath)) {
20254
+ const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
20255
+ if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
20159
20256
  throw new Error(`Missing package.json at ${packageJsonPath}`);
20160
20257
  }
20161
- const pkgStat = (0, import_node_fs24.statSync)(packageJsonPath);
20258
+ const pkgStat = (0, import_node_fs25.statSync)(packageJsonPath);
20162
20259
  if (!pkgStat.isFile()) {
20163
20260
  throw new Error(`package.json is not a file at ${packageJsonPath}`);
20164
20261
  }
@@ -20569,9 +20666,9 @@ var ServiceRuntimeRunner = class {
20569
20666
  return tokens;
20570
20667
  }
20571
20668
  readPathValue(source, pathExpr) {
20572
- const path34 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
20669
+ const path35 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
20573
20670
  let cursor = source;
20574
- for (const segment of path34) {
20671
+ for (const segment of path35) {
20575
20672
  if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
20576
20673
  return void 0;
20577
20674
  }
@@ -20614,12 +20711,12 @@ var ServiceRuntimeRunner = class {
20614
20711
  }
20615
20712
  resolveTemplatePath(templateName) {
20616
20713
  const candidates = [
20617
- import_node_path29.default.join(__dirname, "..", "templates", templateName),
20618
- import_node_path29.default.join(__dirname, "..", "src", "templates", templateName),
20619
- import_node_path29.default.join(__dirname, "templates", templateName)
20714
+ import_node_path30.default.join(__dirname, "..", "templates", templateName),
20715
+ import_node_path30.default.join(__dirname, "..", "src", "templates", templateName),
20716
+ import_node_path30.default.join(__dirname, "templates", templateName)
20620
20717
  ];
20621
20718
  for (const candidate of candidates) {
20622
- if ((0, import_node_fs24.existsSync)(candidate)) {
20719
+ if ((0, import_node_fs25.existsSync)(candidate)) {
20623
20720
  return candidate;
20624
20721
  }
20625
20722
  }
@@ -20651,7 +20748,7 @@ var ServiceRuntimeRunner = class {
20651
20748
  });
20652
20749
  }
20653
20750
  loadPackageJson(packageJsonPath) {
20654
- const raw = (0, import_node_fs24.readFileSync)(packageJsonPath, "utf8");
20751
+ const raw = (0, import_node_fs25.readFileSync)(packageJsonPath, "utf8");
20655
20752
  const parsed = JSON.parse(raw);
20656
20753
  if (!parsed || typeof parsed !== "object") {
20657
20754
  throw new Error(`Invalid package.json at ${packageJsonPath}`);
@@ -20660,7 +20757,7 @@ var ServiceRuntimeRunner = class {
20660
20757
  }
20661
20758
  writePackageJson(packageJsonPath, data) {
20662
20759
  const serialized = JSON.stringify(data, null, 2);
20663
- (0, import_node_fs24.writeFileSync)(packageJsonPath, `${serialized}
20760
+ (0, import_node_fs25.writeFileSync)(packageJsonPath, `${serialized}
20664
20761
  `, "utf8");
20665
20762
  }
20666
20763
  validateFcConfig(service, fc) {
@@ -20687,8 +20784,8 @@ var ServiceRuntimeRunner = class {
20687
20784
  }
20688
20785
  }
20689
20786
  async ensurePnpmWorkspaceRoot(repoRoot) {
20690
- const workspacePath = import_node_path29.default.join(repoRoot, "pnpm-workspace.yaml");
20691
- if (!(0, import_node_fs24.existsSync)(workspacePath)) {
20787
+ const workspacePath = import_node_path30.default.join(repoRoot, "pnpm-workspace.yaml");
20788
+ if (!(0, import_node_fs25.existsSync)(workspacePath)) {
20692
20789
  throw new Error(`Missing pnpm-workspace.yaml at ${workspacePath}`);
20693
20790
  }
20694
20791
  }
@@ -20762,16 +20859,16 @@ var ServiceRuntimeRunner = class {
20762
20859
  if (!privateKeyPath) {
20763
20860
  throw new Error("Missing ssl.prv in ~/.pmate/config.yaml.");
20764
20861
  }
20765
- if (!(0, import_node_fs24.existsSync)(certificatePath)) {
20862
+ if (!(0, import_node_fs25.existsSync)(certificatePath)) {
20766
20863
  throw new Error(`SSL certificate file not found: ${certificatePath}`);
20767
20864
  }
20768
- if (!(0, import_node_fs24.existsSync)(privateKeyPath)) {
20865
+ if (!(0, import_node_fs25.existsSync)(privateKeyPath)) {
20769
20866
  throw new Error(`SSL private key file not found: ${privateKeyPath}`);
20770
20867
  }
20771
20868
  return {
20772
20869
  certName: host,
20773
- certificate: (0, import_node_fs24.readFileSync)(certificatePath, "utf8"),
20774
- privateKey: (0, import_node_fs24.readFileSync)(privateKeyPath, "utf8")
20870
+ certificate: (0, import_node_fs25.readFileSync)(certificatePath, "utf8"),
20871
+ privateKey: (0, import_node_fs25.readFileSync)(privateKeyPath, "utf8")
20775
20872
  };
20776
20873
  }
20777
20874
  resolveFcProtocol(fc, certConfig) {
@@ -21076,6 +21173,18 @@ var ServiceCommandHandler = class {
21076
21173
  }
21077
21174
  case "deploy": {
21078
21175
  const record = await registry.getService(args.namespace, args.name);
21176
+ if ("type" in record && (record.type === "electron" || record.type === "ios" || record.type === "android")) {
21177
+ try {
21178
+ const result = await new NativeServiceDeploy({}, registry).deploy(record, args);
21179
+ if (!args.dryRun && !args.local) await this.appendDeployHistory(registry, record.id, args.env ?? "prod", "success", String(result.status));
21180
+ this.renderJson(result, true);
21181
+ } catch (error) {
21182
+ if (!args.dryRun && !args.local) await this.appendDeployHistory(registry, record.id, args.env ?? "prod", "failed", error instanceof Error ? error.message : String(error));
21183
+ throw error;
21184
+ }
21185
+ return;
21186
+ }
21187
+ rejectNativeOverrides(args);
21079
21188
  const service = await this.materializeServiceEnv(registry, record, args.env);
21080
21189
  try {
21081
21190
  await runtime.deploy(service, { envName: args.env, ...args.cwd ? { cwd: args.cwd } : {} });
@@ -21146,31 +21255,6 @@ var ServiceCommandHandler = class {
21146
21255
  );
21147
21256
  return;
21148
21257
  }
21149
- case "ios-build": {
21150
- const record = await registry.getService(args.namespace, args.name);
21151
- const result = await new IosBuildService().build(record, args);
21152
- if (args.json) this.renderJson(result, true);
21153
- else {
21154
- ui.success(`Uploaded iOS ${result.version} (${result.build}); Apple processing, TestFlight availability not yet verified`);
21155
- this.renderJson(result, true);
21156
- }
21157
- return;
21158
- }
21159
- case "apk-release": {
21160
- const record = await registry.getService(args.namespace, args.name);
21161
- const apkRelease = new AndroidApkReleaseService(registry);
21162
- const artifact = await apkRelease.release(record, {
21163
- env: args.env,
21164
- variant: args.variant,
21165
- bump: args.bump,
21166
- cwd: args.cwd,
21167
- force: args.force,
21168
- releaseNotes: args.releaseNotes,
21169
- minimumVersionCode: args.minimumVersionCode
21170
- });
21171
- this.renderApkArtifacts([artifact], args.json);
21172
- return;
21173
- }
21174
21258
  case "apk-list": {
21175
21259
  const record = await registry.getService(args.namespace, args.name);
21176
21260
  const apkRelease = new AndroidApkReleaseService(registry);
@@ -21258,7 +21342,7 @@ var ServiceCommandHandler = class {
21258
21342
  format: "dotenv"
21259
21343
  }
21260
21344
  );
21261
- const outputPath = import_node_path30.default.resolve(process.cwd(), args.output);
21345
+ const outputPath = import_node_path31.default.resolve(process.cwd(), args.output);
21262
21346
  await (0, import_promises5.writeFile)(outputPath, payload.content, "utf8");
21263
21347
  ui.success(`Wrote env file for ${args.appId} to ${outputPath}`);
21264
21348
  this.renderJson({ ...payload, output: outputPath }, args.json);
@@ -21484,11 +21568,11 @@ var ServiceCommandHandler = class {
21484
21568
  return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
21485
21569
  }
21486
21570
  readJsonFile(filePath) {
21487
- const absolutePath = import_node_path30.default.resolve(process.cwd(), filePath);
21488
- if (!(0, import_node_fs25.existsSync)(absolutePath)) {
21571
+ const absolutePath = import_node_path31.default.resolve(process.cwd(), filePath);
21572
+ if (!(0, import_node_fs26.existsSync)(absolutePath)) {
21489
21573
  throw new Error(`JSON file not found: ${absolutePath}`);
21490
21574
  }
21491
- const raw = (0, import_node_fs25.readFileSync)(absolutePath, "utf8");
21575
+ const raw = (0, import_node_fs26.readFileSync)(absolutePath, "utf8");
21492
21576
  try {
21493
21577
  return JSON.parse(raw);
21494
21578
  } catch (error) {
@@ -22296,9 +22380,9 @@ var RoleCommandHandler = class {
22296
22380
  };
22297
22381
 
22298
22382
  // src/commands/AccountCommandHandler.ts
22299
- var import_node_fs26 = require("fs");
22383
+ var import_node_fs27 = require("fs");
22300
22384
  var import_node_crypto7 = require("crypto");
22301
- var import_node_path31 = __toESM(require("path"));
22385
+ var import_node_path32 = __toESM(require("path"));
22302
22386
  init_sessionStore();
22303
22387
  var AccountCommandHandler = class {
22304
22388
  async handle(args) {
@@ -22306,9 +22390,9 @@ var AccountCommandHandler = class {
22306
22390
  case "bot-keygen": {
22307
22391
  const keyFile = this.generateBotKeyFile(args.app, args.name);
22308
22392
  const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
22309
- (0, import_node_fs26.mkdirSync)(import_node_path31.default.dirname(outPath), { recursive: true });
22310
- (0, import_node_fs26.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
22311
- (0, import_node_fs26.chmodSync)(outPath, 384);
22393
+ (0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(outPath), { recursive: true });
22394
+ (0, import_node_fs27.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
22395
+ (0, import_node_fs27.chmodSync)(outPath, 384);
22312
22396
  if (!args.json) {
22313
22397
  ui.success(`Bot key saved to ${outPath}`);
22314
22398
  }
@@ -22868,10 +22952,10 @@ var AccountCommandHandler = class {
22868
22952
  throw new Error("Missing visible apps input");
22869
22953
  }
22870
22954
  const absolutePath = this.resolveFilePath(args.filePath);
22871
- if (!(0, import_node_fs26.existsSync)(absolutePath)) {
22955
+ if (!(0, import_node_fs27.existsSync)(absolutePath)) {
22872
22956
  throw new Error(`JSON file not found: ${absolutePath}`);
22873
22957
  }
22874
- const raw = (0, import_node_fs26.readFileSync)(absolutePath, "utf8");
22958
+ const raw = (0, import_node_fs27.readFileSync)(absolutePath, "utf8");
22875
22959
  let parsed;
22876
22960
  try {
22877
22961
  parsed = JSON.parse(raw);
@@ -22885,13 +22969,13 @@ var AccountCommandHandler = class {
22885
22969
  return parsed;
22886
22970
  }
22887
22971
  resolveFilePath(filePath) {
22888
- return import_node_path31.default.resolve(process.cwd(), filePath);
22972
+ return import_node_path32.default.resolve(process.cwd(), filePath);
22889
22973
  }
22890
22974
  resolveDefaultBotKeyPath(app, name) {
22891
- return import_node_path31.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
22975
+ return import_node_path32.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
22892
22976
  }
22893
22977
  resolveDefaultAccessKeyPath(app, name) {
22894
- return import_node_path31.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
22978
+ return import_node_path32.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
22895
22979
  }
22896
22980
  homeDir() {
22897
22981
  return process.env.HOME || process.env.USERPROFILE || process.cwd();
@@ -22911,14 +22995,14 @@ var AccountCommandHandler = class {
22911
22995
  }
22912
22996
  renameDefaultBotKeyFile(app, name, newName) {
22913
22997
  const oldPath = this.resolveDefaultBotKeyPath(app, name);
22914
- if (!(0, import_node_fs26.existsSync)(oldPath)) {
22998
+ if (!(0, import_node_fs27.existsSync)(oldPath)) {
22915
22999
  return void 0;
22916
23000
  }
22917
23001
  const keyFile = this.readBotKeyFile(oldPath, app, name);
22918
23002
  const newPath = this.resolveDefaultBotKeyPath(app, newName);
22919
- (0, import_node_fs26.mkdirSync)(import_node_path31.default.dirname(newPath), { recursive: true, mode: 448 });
22920
- (0, import_node_fs26.writeFileSync)(newPath, JSON.stringify({ ...keyFile, name: newName }, null, 2));
22921
- (0, import_node_fs26.chmodSync)(newPath, 384);
23003
+ (0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(newPath), { recursive: true, mode: 448 });
23004
+ (0, import_node_fs27.writeFileSync)(newPath, JSON.stringify({ ...keyFile, name: newName }, null, 2));
23005
+ (0, import_node_fs27.chmodSync)(newPath, 384);
22922
23006
  return newPath;
22923
23007
  }
22924
23008
  readBotKeyFile(filePath, expectedApp, expectedName) {
@@ -22926,10 +23010,10 @@ var AccountCommandHandler = class {
22926
23010
  throw new Error("Missing bot key file");
22927
23011
  }
22928
23012
  const absolutePath = this.resolveFilePath(filePath);
22929
- if (!(0, import_node_fs26.existsSync)(absolutePath)) {
23013
+ if (!(0, import_node_fs27.existsSync)(absolutePath)) {
22930
23014
  throw new Error(`Bot key file not found: ${absolutePath}`);
22931
23015
  }
22932
- const parsed = JSON.parse((0, import_node_fs26.readFileSync)(absolutePath, "utf8"));
23016
+ const parsed = JSON.parse((0, import_node_fs27.readFileSync)(absolutePath, "utf8"));
22933
23017
  if (parsed.type !== "pmate-bot-key" || parsed.version !== 1 || parsed.algorithm !== "ed25519" || !parsed.publicKey || !parsed.privateKey) {
22934
23018
  throw new Error(`Invalid PMate bot key file: ${absolutePath}`);
22935
23019
  }
@@ -22946,10 +23030,10 @@ var AccountCommandHandler = class {
22946
23030
  throw new Error("Missing access key file");
22947
23031
  }
22948
23032
  const absolutePath = this.resolveFilePath(filePath);
22949
- if (!(0, import_node_fs26.existsSync)(absolutePath)) {
23033
+ if (!(0, import_node_fs27.existsSync)(absolutePath)) {
22950
23034
  throw new Error(`Access key file not found: ${absolutePath}`);
22951
23035
  }
22952
- const parsed = JSON.parse((0, import_node_fs26.readFileSync)(absolutePath, "utf8"));
23036
+ const parsed = JSON.parse((0, import_node_fs27.readFileSync)(absolutePath, "utf8"));
22953
23037
  if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
22954
23038
  throw new Error(`Invalid PMate access key file: ${absolutePath}`);
22955
23039
  }
@@ -22971,9 +23055,9 @@ var AccountCommandHandler = class {
22971
23055
  createdAt: result.key.createdAt
22972
23056
  };
22973
23057
  const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
22974
- (0, import_node_fs26.mkdirSync)(import_node_path31.default.dirname(outPath), { recursive: true });
22975
- (0, import_node_fs26.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
22976
- (0, import_node_fs26.chmodSync)(outPath, 384);
23058
+ (0, import_node_fs27.mkdirSync)(import_node_path32.default.dirname(outPath), { recursive: true });
23059
+ (0, import_node_fs27.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
23060
+ (0, import_node_fs27.chmodSync)(outPath, 384);
22977
23061
  }
22978
23062
  renderAccessKeyCreateResult(result, asJson, out) {
22979
23063
  if (asJson) {
@@ -23058,8 +23142,8 @@ function encodePathSegment2(value) {
23058
23142
  }
23059
23143
 
23060
23144
  // src/commands/OrgCommandHandler.ts
23061
- var import_node_fs27 = require("fs");
23062
- var import_node_path32 = __toESM(require("path"));
23145
+ var import_node_fs28 = require("fs");
23146
+ var import_node_path33 = __toESM(require("path"));
23063
23147
  init_sessionStore();
23064
23148
  var OrgCommandHandler = class {
23065
23149
  async handle(args) {
@@ -23229,11 +23313,11 @@ var OrgCommandHandler = class {
23229
23313
  if (!filePath) {
23230
23314
  throw new Error(`Missing ${itemLabel} input`);
23231
23315
  }
23232
- const absolutePath = import_node_path32.default.resolve(process.cwd(), filePath);
23233
- if (!(0, import_node_fs27.existsSync)(absolutePath)) {
23316
+ const absolutePath = import_node_path33.default.resolve(process.cwd(), filePath);
23317
+ if (!(0, import_node_fs28.existsSync)(absolutePath)) {
23234
23318
  throw new Error(`JSON file not found: ${absolutePath}`);
23235
23319
  }
23236
- const raw = (0, import_node_fs27.readFileSync)(absolutePath, "utf8");
23320
+ const raw = (0, import_node_fs28.readFileSync)(absolutePath, "utf8");
23237
23321
  let parsed;
23238
23322
  try {
23239
23323
  parsed = JSON.parse(raw);
@@ -23304,9 +23388,9 @@ function encodePathSegment3(value) {
23304
23388
  }
23305
23389
 
23306
23390
  // src/commands/HostCommandHandler.ts
23307
- var import_node_fs28 = require("fs");
23391
+ var import_node_fs29 = require("fs");
23308
23392
  var import_node_os14 = require("os");
23309
- var import_node_path33 = __toESM(require("path"));
23393
+ var import_node_path34 = __toESM(require("path"));
23310
23394
  var import_node_child_process15 = require("child_process");
23311
23395
  var BLOCK_START = "# >>> pmate host env >>>";
23312
23396
  var BLOCK_END = "# <<< pmate host env <<<";
@@ -23813,27 +23897,7 @@ function parseAppArgs(tokens) {
23813
23897
  if (!action) {
23814
23898
  throw new Error("Missing app action. Use: app list|get|view|create|update|rename|move|icon|delete");
23815
23899
  }
23816
- if (action === "build") {
23817
- const id = parseNamespacedRef(rest.shift() ?? "", { entityLabel: "app ref" }).fullId;
23818
- const options = {};
23819
- const switches = /* @__PURE__ */ new Set();
23820
- while (rest.length) {
23821
- const key = rest.shift();
23822
- if (["--dry-run", "--signed", "--unsigned", "--dir", "--json"].includes(key)) {
23823
- if (switches.has(key)) throw new Error(`Duplicate option: ${key}`);
23824
- switches.add(key);
23825
- } else if (["--target", "--config", "--platform", "--arch", "--out-dir"].includes(key)) {
23826
- if (options[key]) throw new Error(`Duplicate option: ${key}`);
23827
- options[key] = requireValue3(rest, key);
23828
- } else throw new Error(`Unknown app build option: ${key}`);
23829
- }
23830
- if (options["--target"] && options["--target"] !== "electron") throw new Error("Supported target: electron");
23831
- if (switches.has("--signed") && switches.has("--unsigned")) throw new Error("--signed and --unsigned cannot be combined");
23832
- const platform = options["--platform"] ?? (process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : process.platform);
23833
- const arch = options["--arch"] ?? process.arch;
23834
- if (!["mac", "win"].includes(platform) || !["arm64", "x64"].includes(arch)) throw new Error("Supported target: --platform mac|win --arch arm64|x64");
23835
- return { type: "app" /* App */, action, id, target: "electron", config: options["--config"], platform, arch, outDir: options["--out-dir"], dryRun: switches.has("--dry-run"), signed: !switches.has("--unsigned"), dir: switches.has("--dir"), json: switches.has("--json") };
23836
- }
23900
+ if (action === "build") throw new Error("app build was removed; register an electron service and use pmate service deploy <ns:service>");
23837
23901
  let baseUrl;
23838
23902
  let json = false;
23839
23903
  const takeSharedOptions4 = () => {
@@ -24396,7 +24460,7 @@ function parseServiceArgs(tokens) {
24396
24460
  json
24397
24461
  };
24398
24462
  }
24399
- if (action === "ios") return parseServiceIosArgs(rest);
24463
+ if (action === "ios") throw new Error("service ios build was removed; use pmate service deploy <ns:ios-service>");
24400
24464
  if (action === "apk") {
24401
24465
  return parseServiceApkArgs(rest, { baseUrl, json });
24402
24466
  }
@@ -24405,6 +24469,9 @@ function parseServiceArgs(tokens) {
24405
24469
  if (!ref || ref.startsWith("-")) {
24406
24470
  throw new Error(`Usage: service ${action} <ns:objectId> [--base-url <url>] [--json]`);
24407
24471
  }
24472
+ const native = {};
24473
+ const buildValues = ["--config", "--platform", "--arch", "--out-dir", "--scheme", "--team", "--project", "--workspace", "--last-build", "--variant", "--bump", "--release-notes", "--minimum-version-code"];
24474
+ const buildFlags = ["--dry-run", "--local", "--unsigned", "--signed", "--dir", "--force"];
24408
24475
  let cwd;
24409
24476
  let page = 0;
24410
24477
  let app;
@@ -24416,6 +24483,13 @@ function parseServiceArgs(tokens) {
24416
24483
  let env;
24417
24484
  while (rest.length > 0) {
24418
24485
  const token = rest.shift();
24486
+ if (buildValues.includes(token) || buildFlags.includes(token)) {
24487
+ if (action !== "deploy") throw new Error(`Unknown service ${action} option: ${token}`);
24488
+ const key = token.slice(2).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
24489
+ if (native[key] !== void 0) throw new Error(`Duplicate option: ${token}`);
24490
+ native[key] = buildFlags.includes(token) ? true : requireValue4(rest, token);
24491
+ continue;
24492
+ }
24419
24493
  switch (token) {
24420
24494
  case "--category": {
24421
24495
  if (action !== "log") throw new Error(`Unknown service ${action} option: ${token}`);
@@ -24502,8 +24576,22 @@ function parseServiceArgs(tokens) {
24502
24576
  return { type: "service" /* Service */, action, namespace, name, env, page, baseUrl, json };
24503
24577
  }
24504
24578
  if (action === "deploy" || action === "stop") {
24579
+ if (native.signed && native.unsigned) throw new Error("--signed and --unsigned cannot be combined");
24580
+ if ((native.unsigned || native.dir) && !native.local) throw new Error("Use --local with --unsigned or --dir; deploy otherwise publishes a release");
24581
+ if (native.platform && !["mac", "win"].includes(String(native.platform))) throw new Error("Supported platform: mac|win");
24582
+ if (native.arch && !["arm64", "x64"].includes(String(native.arch))) throw new Error("Supported architecture: arm64|x64");
24583
+ if (native.project && native.workspace) throw new Error("Use only one of --project or --workspace");
24584
+ if (native.bump && !["patch", "minor", "major"].includes(String(native.bump))) throw new Error("--bump must be patch, minor or major");
24585
+ if (native.minimumVersionCode !== void 0) {
24586
+ if (!/^(0|[1-9]\d*)$/.test(String(native.minimumVersionCode)) || !Number.isSafeInteger(Number(native.minimumVersionCode))) throw new Error("--minimum-version-code must be a non-negative safe integer");
24587
+ native.minimumVersionCode = Number(native.minimumVersionCode);
24588
+ }
24589
+ if (native.lastBuild !== void 0) {
24590
+ if (!/^(0|[1-9]\d*)$/.test(String(native.lastBuild)) || !Number.isSafeInteger(Number(native.lastBuild))) throw new Error("--last-build must be a non-negative safe integer");
24591
+ native.lastBuild = Number(native.lastBuild);
24592
+ }
24505
24593
  if (action === "deploy") env ??= "prod";
24506
- return { type: "service" /* Service */, action, namespace, name, env, ...cwd ? { cwd } : {}, baseUrl, json };
24594
+ return { type: "service" /* Service */, action, namespace, name, env, ...cwd ? { cwd } : {}, ...native, baseUrl, json };
24507
24595
  }
24508
24596
  if (action === "init") {
24509
24597
  if (!env) {
@@ -24679,111 +24767,21 @@ function looksLikeNamespacedRef(value) {
24679
24767
  }
24680
24768
  function parseServiceApkArgs(tokens, defaults) {
24681
24769
  const rest = [...tokens];
24682
- const apkAction = rest.shift();
24683
- if (apkAction !== "release" && apkAction !== "list") {
24684
- throw new Error("Usage: service apk release|list <ns:service> [--env <env>] [--json]");
24685
- }
24686
- const ref = rest.shift();
24687
- if (!ref || ref.startsWith("-")) {
24688
- throw new Error(`Usage: service apk ${apkAction} <ns:service> [--env <env>] [--json]`);
24689
- }
24690
- const parsedRef = parseNamespacedRef(ref, { entityLabel: "service ref" });
24770
+ const action = rest.shift();
24771
+ if (action === "release") throw new Error("service apk release was removed; use pmate service deploy <ns:android-service>");
24772
+ if (action !== "list") throw new Error("Usage: service apk list <ns:service> [--env <env>] [--json]");
24773
+ const parsed = parseNamespacedRef(rest.shift() ?? "", { entityLabel: "service ref" });
24774
+ let env;
24691
24775
  let baseUrl = defaults.baseUrl;
24692
24776
  let json = defaults.json;
24693
- let env;
24694
- let variant = "debug";
24695
- let cwd;
24696
- let force = false;
24697
- let major = false;
24698
- let minor = false;
24699
- let releaseNotes;
24700
- let minimumVersionCode;
24701
- while (rest.length > 0) {
24702
- const token = rest.shift();
24703
- switch (token) {
24704
- case "--env":
24705
- env = requireValue4(rest, token);
24706
- break;
24707
- case "--variant":
24708
- if (apkAction !== "release") {
24709
- throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24710
- }
24711
- variant = requireValue4(rest, token);
24712
- break;
24713
- case "--cwd":
24714
- if (apkAction !== "release") {
24715
- throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24716
- }
24717
- cwd = requireValue4(rest, token);
24718
- break;
24719
- case "--force":
24720
- if (apkAction !== "release") {
24721
- throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24722
- }
24723
- force = true;
24724
- break;
24725
- case "--major":
24726
- if (apkAction !== "release") {
24727
- throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24728
- }
24729
- major = true;
24730
- break;
24731
- case "--minor":
24732
- if (apkAction !== "release") {
24733
- throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24734
- }
24735
- minor = true;
24736
- break;
24737
- case "--release-notes":
24738
- if (apkAction !== "release") throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24739
- releaseNotes = requireValue4(rest, token);
24740
- break;
24741
- case "--minimum-version-code": {
24742
- if (apkAction !== "release") throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24743
- const value = Number(requireValue4(rest, token));
24744
- if (!Number.isInteger(value) || value < 0) throw new Error("--minimum-version-code must be a non-negative integer");
24745
- minimumVersionCode = value;
24746
- break;
24747
- }
24748
- case "--base-url":
24749
- baseUrl = requireValue4(rest, token);
24750
- break;
24751
- case "--json":
24752
- json = true;
24753
- break;
24754
- default:
24755
- throw new Error(`Unknown service apk ${apkAction} option: ${token}`);
24756
- }
24757
- }
24758
- if (major && minor) {
24759
- throw new Error("Use only one of --major or --minor for service apk release");
24760
- }
24761
- if (apkAction === "list") {
24762
- return {
24763
- type: "service" /* Service */,
24764
- action: "apk-list",
24765
- namespace: parsedRef.namespace,
24766
- name: parsedRef.objectId,
24767
- env,
24768
- baseUrl,
24769
- json
24770
- };
24777
+ while (rest.length) {
24778
+ const flag = rest.shift();
24779
+ if (flag === "--env") env = requireValue4(rest, flag);
24780
+ else if (flag === "--base-url") baseUrl = requireValue4(rest, flag);
24781
+ else if (flag === "--json") json = true;
24782
+ else throw new Error(`Unknown service apk list option: ${flag}`);
24771
24783
  }
24772
- return {
24773
- type: "service" /* Service */,
24774
- action: "apk-release",
24775
- namespace: parsedRef.namespace,
24776
- name: parsedRef.objectId,
24777
- env: env ?? "preview",
24778
- variant,
24779
- bump: major ? "major" : minor ? "minor" : "patch",
24780
- cwd,
24781
- force,
24782
- releaseNotes,
24783
- minimumVersionCode,
24784
- baseUrl,
24785
- json
24786
- };
24784
+ return { type: "service" /* Service */, action: "apk-list", namespace: parsed.namespace, name: parsed.objectId, env, baseUrl, json };
24787
24785
  }
24788
24786
  function parseServiceEnvDefinitionArgs(appId, tokens) {
24789
24787
  const rest = [...tokens];
@@ -25166,48 +25164,6 @@ function parseServiceEnvArgs(appId, tokens) {
25166
25164
  }
25167
25165
  throw new Error(`Unknown service env action: ${action}`);
25168
25166
  }
25169
- function parseServiceIosArgs(tokens) {
25170
- const rest = [...tokens];
25171
- if (rest.shift() !== "build") throw new Error("Usage: service ios build <ns:service> --scheme <scheme>");
25172
- const ref = rest.shift();
25173
- if (!ref || ref.startsWith("-")) throw new Error("Missing iOS service ref");
25174
- const parsed = parseNamespacedRef(ref, { entityLabel: "service ref" });
25175
- const values = {};
25176
- let json = false;
25177
- const allowed = ["--scheme", "--project", "--workspace", "--team", "--cwd", "--last-build", "--base-url"];
25178
- while (rest.length) {
25179
- const token = rest.shift();
25180
- if (token === "--json") {
25181
- json = true;
25182
- continue;
25183
- }
25184
- if (!allowed.includes(token)) throw new Error(`Unknown service ios build option: ${token}`);
25185
- if (values[token] !== void 0) throw new Error(`Duplicate option: ${token}`);
25186
- values[token] = requireValue4(rest, token);
25187
- }
25188
- if (!values["--scheme"]) throw new Error("An explicit --scheme is required");
25189
- if (values["--project"] && values["--workspace"]) throw new Error("Use only one of --project or --workspace");
25190
- let lastBuild;
25191
- if (values["--last-build"] !== void 0) {
25192
- const value = values["--last-build"];
25193
- if (!/^(0|[1-9]\d*)$/.test(value) || !Number.isSafeInteger(Number(value))) throw new Error("--last-build must be a non-negative safe integer");
25194
- lastBuild = Number(value);
25195
- }
25196
- return {
25197
- type: "service" /* Service */,
25198
- action: "ios-build",
25199
- namespace: parsed.namespace,
25200
- name: parsed.objectId,
25201
- scheme: values["--scheme"],
25202
- project: values["--project"],
25203
- workspace: values["--workspace"],
25204
- team: values["--team"],
25205
- cwd: values["--cwd"],
25206
- lastBuild,
25207
- baseUrl: values["--base-url"],
25208
- json
25209
- };
25210
- }
25211
25167
 
25212
25168
  // src/logsCommandParser.ts
25213
25169
  init_namespacedRef();
@@ -26676,7 +26632,7 @@ function requireValue11(tokens, option) {
26676
26632
 
26677
26633
  // src/index.ts
26678
26634
  var pkg = JSON.parse(
26679
- (0, import_node_fs29.readFileSync)(import_node_path34.default.resolve(__dirname, "..", "package.json"), "utf8")
26635
+ (0, import_node_fs30.readFileSync)(import_node_path35.default.resolve(__dirname, "..", "package.json"), "utf8")
26680
26636
  );
26681
26637
  var HELP_TEXT = [
26682
26638
  import_chalk4.default.bold(`pmate v${pkg.version}`),
@@ -26825,7 +26781,6 @@ var HELP_TEXT = [
26825
26781
  ` ${import_chalk4.default.gray(" kv list|get|exists|set|delete <name> [options]")}`,
26826
26782
  ` ${import_chalk4.default.gray(" defaults: chain=pmate namespace=pmate env base URLs from BLOCKCHAIN_BASE_URL / INDEXER_BASE_URL")}`,
26827
26783
  ` ${import_chalk4.default.cyan("app")} Manage app registry entries via apps-api`,
26828
- ` ${import_chalk4.default.gray(" build <ns:app> [--target electron] [--config <file>] [--platform mac|win] [--arch arm64|x64] [--out-dir <dir>] [--dir] [--dry-run] [--unsigned|--signed]")}`,
26829
26784
  ` ${import_chalk4.default.gray(" list [--ns <namespace>] [--all] [--base-url <url>] [--json]")}`,
26830
26785
  ` ${import_chalk4.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
26831
26786
  ` ${import_chalk4.default.gray(" view <ns:objectId> [--base-url <url>]")}`,
@@ -26841,7 +26796,7 @@ var HELP_TEXT = [
26841
26796
  ` ${import_chalk4.default.gray(" delete <ns:objectId> [--base-url <url>] [--json]")}`,
26842
26797
  ` ${import_chalk4.default.gray(" default base URL: https://apps-api.pmate.chat")}`,
26843
26798
  ` ${import_chalk4.default.cyan("service")} Manage service registry entries via apps-api`,
26844
- " ios build <ns:service> --scheme <name> [--team <id>] [--last-build <n>] [--cwd <repo>] [--project <path>|--workspace <path>] [--json]",
26799
+ " deploy <ns:service> [--env prod] [--cwd <repo>] [--dry-run] [--local] [--unsigned] [--platform mac|win] [--arch arm64|x64] [--config <file>] [--out-dir <dir>] [--scheme <name>] [--team <id>] [--variant release|debug] [--bump patch|minor|major]",
26845
26800
  ` ${import_chalk4.default.gray(" list [--namespace <ns>] [--repo <owner/name|https://github.com/owner/name>] [--server <name>] [--base-url <url>] [--json]")}`,
26846
26801
  ` ${import_chalk4.default.gray(" get <ns:objectId> [--base-url <url>] [--json]")}`,
26847
26802
  ` ${import_chalk4.default.gray(" view <ns:objectId> [--base-url <url>]")}`,