@pmate/cli 0.41.0 → 0.42.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.
Files changed (3) hide show
  1. package/README.md +13 -1
  2. package/dist/index.js +796 -481
  3. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -8294,14 +8294,14 @@ function abortError(reason) {
8294
8294
  return reason;
8295
8295
  return new Error(typeof reason === "string" ? reason : "Function stream aborted");
8296
8296
  }
8297
- function ensureWsProtocol(baseUrl) {
8298
- if (/^wss?:\/\//i.test(baseUrl))
8299
- return baseUrl;
8300
- if (/^https:\/\//i.test(baseUrl))
8301
- return baseUrl.replace(/^https:/i, "wss:");
8302
- if (/^http:\/\//i.test(baseUrl))
8303
- return baseUrl.replace(/^http:/i, "ws:");
8304
- return `wss://${baseUrl}`;
8297
+ function ensureWsProtocol(baseUrl2) {
8298
+ if (/^wss?:\/\//i.test(baseUrl2))
8299
+ return baseUrl2;
8300
+ if (/^https:\/\//i.test(baseUrl2))
8301
+ return baseUrl2.replace(/^https:/i, "wss:");
8302
+ if (/^http:\/\//i.test(baseUrl2))
8303
+ return baseUrl2.replace(/^http:/i, "ws:");
8304
+ return `wss://${baseUrl2}`;
8305
8305
  }
8306
8306
  function deferred() {
8307
8307
  let resolve;
@@ -8818,8 +8818,8 @@ __export(index_exports, {
8818
8818
  parseCommandArgs: () => parseCommandArgs
8819
8819
  });
8820
8820
  module.exports = __toCommonJS(index_exports);
8821
- var import_node_fs30 = require("fs");
8822
- var import_node_path35 = __toESM(require("path"));
8821
+ var import_node_fs31 = require("fs");
8822
+ var import_node_path36 = __toESM(require("path"));
8823
8823
 
8824
8824
  // src/managedSession.ts
8825
8825
  var import_node_fs = require("fs");
@@ -10116,7 +10116,7 @@ var AliyunService = class {
10116
10116
  ui.success(`Bucket created: ${bucketName}`);
10117
10117
  }
10118
10118
  /** Upload all files in a directory to OSS, skipping unchanged files. */
10119
- static async uploadDirectory(localDir, bucket, prefix) {
10119
+ static async uploadDirectory(localDir, bucket2, prefix) {
10120
10120
  const cfg = loadPmateConfig();
10121
10121
  const region = cfg.oss?.public?.region?.trim();
10122
10122
  const accessKeyId = cfg.aliyun?.ak?.trim();
@@ -10124,7 +10124,7 @@ var AliyunService = class {
10124
10124
  if (!region) throw new Error("Missing oss.public.region in ~/.pmate/config.yaml.");
10125
10125
  if (!accessKeyId) throw new Error("Missing aliyun.ak in ~/.pmate/config.yaml.");
10126
10126
  if (!accessKeySecret) throw new Error("Missing aliyun.sk in ~/.pmate/config.yaml.");
10127
- const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket });
10127
+ const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
10128
10128
  const files = await this.collectFiles(localDir);
10129
10129
  if (files.length === 0) {
10130
10130
  ui.warn(`No files to upload from ${localDir}`);
@@ -10169,7 +10169,7 @@ var AliyunService = class {
10169
10169
  }
10170
10170
  }
10171
10171
  /** Upload a single file to OSS. */
10172
- static async uploadFile(localFile, bucket, objectKey) {
10172
+ static async uploadFile(localFile, bucket2, objectKey, extraHeaders = {}) {
10173
10173
  const cfg = loadPmateConfig();
10174
10174
  const region = cfg.oss?.public?.region?.trim();
10175
10175
  const accessKeyId = cfg.aliyun?.ak?.trim();
@@ -10180,24 +10180,25 @@ var AliyunService = class {
10180
10180
  if (!(0, import_node_fs5.existsSync)(localFile)) {
10181
10181
  throw new Error(`File not found: ${localFile}`);
10182
10182
  }
10183
- const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket });
10183
+ const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
10184
10184
  const contentType = this.getContentType(localFile);
10185
10185
  const cacheControl = this.getStaticAssetCacheControl(objectKey);
10186
10186
  const headers = {};
10187
10187
  if (contentType) headers["Content-Type"] = contentType;
10188
10188
  if (cacheControl) headers["Cache-Control"] = cacheControl;
10189
+ Object.assign(headers, extraHeaders);
10189
10190
  const options = Object.keys(headers).length > 0 ? { headers } : void 0;
10190
10191
  await client.put(objectKey, localFile, options);
10191
10192
  ui.success(`Uploaded ${objectKey}`);
10192
10193
  }
10193
10194
  /** List objects in a bucket (optionally under a prefix). */
10194
- static async readJsonObject(bucket, objectKey) {
10195
+ static async readJsonObject(bucket2, objectKey) {
10195
10196
  const cfg = loadPmateConfig();
10196
10197
  const region = cfg.oss?.public?.region?.trim();
10197
10198
  const accessKeyId = cfg.aliyun?.ak?.trim();
10198
10199
  const accessKeySecret = cfg.aliyun?.sk?.trim();
10199
10200
  if (!region || !accessKeyId || !accessKeySecret) throw new Error("Missing OSS credentials.");
10200
- const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket });
10201
+ const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
10201
10202
  try {
10202
10203
  const result = await client.get(objectKey);
10203
10204
  return JSON.parse(result.content.toString());
@@ -10206,19 +10207,34 @@ var AliyunService = class {
10206
10207
  throw error;
10207
10208
  }
10208
10209
  }
10209
- static async uploadJsonObject(bucket, objectKey, value) {
10210
+ static async assertUnversionedBucket(bucket2) {
10211
+ const cfg = loadPmateConfig();
10212
+ const region = cfg.oss?.public?.region?.trim(), accessKeyId = cfg.aliyun?.ak?.trim(), accessKeySecret = cfg.aliyun?.sk?.trim();
10213
+ if (!region || !accessKeyId || !accessKeySecret) throw new Error("Missing OSS credentials.");
10214
+ const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
10215
+ const { versionStatus } = await client.getBucketVersioning(bucket2);
10216
+ if (versionStatus) throw new Error("HarmonyOS immutable publication requires an unversioned OSS bucket");
10217
+ }
10218
+ static async removePublicationLock(bucket2, objectKey) {
10219
+ if (!/^harmony\/[\w-]+\/[\w-]+\/\.publish-lock\.json$/.test(objectKey)) throw new Error("Invalid HarmonyOS publication lock key");
10220
+ const cfg = loadPmateConfig();
10221
+ const region = cfg.oss?.public?.region?.trim(), accessKeyId = cfg.aliyun?.ak?.trim(), accessKeySecret = cfg.aliyun?.sk?.trim();
10222
+ if (!region || !accessKeyId || !accessKeySecret) throw new Error("Missing OSS credentials.");
10223
+ await new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 }).delete(objectKey);
10224
+ }
10225
+ static async uploadJsonObject(bucket2, objectKey, value, extraHeaders = {}) {
10210
10226
  const cfg = loadPmateConfig();
10211
10227
  const region = cfg.oss?.public?.region?.trim();
10212
10228
  const accessKeyId = cfg.aliyun?.ak?.trim();
10213
10229
  const accessKeySecret = cfg.aliyun?.sk?.trim();
10214
10230
  if (!region || !accessKeyId || !accessKeySecret) throw new Error("Missing OSS credentials.");
10215
- const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket });
10231
+ const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
10216
10232
  await client.put(objectKey, Buffer.from(JSON.stringify(value)), {
10217
- headers: { "Content-Type": "application/json", "Cache-Control": "no-cache, no-store, must-revalidate" }
10233
+ headers: { "Content-Type": "application/json", "Cache-Control": "no-cache, no-store, must-revalidate", ...extraHeaders }
10218
10234
  });
10219
10235
  }
10220
10236
  /** List objects in a bucket (optionally under a prefix). */
10221
- static async listObjects(bucket, prefix) {
10237
+ static async listObjects(bucket2, prefix) {
10222
10238
  const cfg = loadPmateConfig();
10223
10239
  const region = cfg.oss?.public?.region?.trim();
10224
10240
  const accessKeyId = cfg.aliyun?.ak?.trim();
@@ -10226,7 +10242,7 @@ var AliyunService = class {
10226
10242
  if (!region) throw new Error("Missing oss.public.region in ~/.pmate/config.yaml.");
10227
10243
  if (!accessKeyId) throw new Error("Missing aliyun.ak in ~/.pmate/config.yaml.");
10228
10244
  if (!accessKeySecret) throw new Error("Missing aliyun.sk in ~/.pmate/config.yaml.");
10229
- const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket });
10245
+ const client = new import_ali_oss.default({ region, accessKeyId, accessKeySecret, bucket: bucket2 });
10230
10246
  const normalizedPrefix = prefix ? prefix.replace(/^\/+|\/+$/g, "") : "";
10231
10247
  const objects = await this.listObjectsForClient(client, normalizedPrefix);
10232
10248
  return objects.filter((item) => typeof item.name === "string" && item.name.length > 0).map((item) => ({
@@ -10248,7 +10264,7 @@ var AliyunService = class {
10248
10264
  const result = await client.listBuckets({});
10249
10265
  const buckets = Array.isArray(result) ? result : result?.buckets ?? [];
10250
10266
  return buckets.map(
10251
- (bucket) => typeof bucket === "string" ? bucket : bucket.name
10267
+ (bucket2) => typeof bucket2 === "string" ? bucket2 : bucket2.name
10252
10268
  ).filter(
10253
10269
  (name) => typeof name === "string" && name.trim().length > 0
10254
10270
  );
@@ -10756,8 +10772,8 @@ var StsCommandHandler = class {
10756
10772
  if (!token) {
10757
10773
  throw new Error("Missing session token. Run `pmate login` first.");
10758
10774
  }
10759
- const baseUrl = "https://ci.pmate.chat";
10760
- const response = await fetch(`${baseUrl}/oss/sts`, {
10775
+ const baseUrl2 = "https://ci.pmate.chat";
10776
+ const response = await fetch(`${baseUrl2}/oss/sts`, {
10761
10777
  method: "POST",
10762
10778
  headers: {
10763
10779
  "content-type": "application/json",
@@ -11163,17 +11179,17 @@ var OssCommandHandler = class _OssCommandHandler {
11163
11179
  ui.warn("No buckets found for current access key.");
11164
11180
  return;
11165
11181
  }
11166
- for (const bucket2 of buckets) {
11167
- ui.info(bucket2);
11182
+ for (const bucket3 of buckets) {
11183
+ ui.info(bucket3);
11168
11184
  }
11169
11185
  return;
11170
11186
  }
11171
11187
  const resolvedFile = import_node_path11.default.resolve(process.cwd(), args.filePath);
11172
11188
  this.assertFile(resolvedFile);
11173
11189
  const objectKey = this.normalizeObjectKey(args.objectKey);
11174
- const bucket = this.resolveBucket(args.bucket);
11175
- await AliyunService.uploadFile(resolvedFile, bucket, objectKey);
11176
- const publicUrl = buildOssPublicUrl(bucket, objectKey);
11190
+ const bucket2 = this.resolveBucket(args.bucket);
11191
+ await AliyunService.uploadFile(resolvedFile, bucket2, objectKey);
11192
+ const publicUrl = buildOssPublicUrl(bucket2, objectKey);
11177
11193
  if (publicUrl) {
11178
11194
  ui.plain(publicUrl);
11179
11195
  }
@@ -11202,8 +11218,8 @@ var OssCommandHandler = class _OssCommandHandler {
11202
11218
  return _OssCommandHandler.DEFAULT_BUCKET;
11203
11219
  }
11204
11220
  };
11205
- function buildOssPublicUrl(bucket, objectKey) {
11206
- if (bucket !== "parrot-static") return null;
11221
+ function buildOssPublicUrl(bucket2, objectKey) {
11222
+ if (bucket2 !== "parrot-static") return null;
11207
11223
  const encodedKey = objectKey.split("/").map((segment) => encodeURIComponent(segment)).join("/");
11208
11224
  return `${PARROT_STATIC_PUBLIC_BASE_URL}/${encodedKey}`;
11209
11225
  }
@@ -11819,11 +11835,11 @@ var PrCommandHandler = class {
11819
11835
  await this.run("git", ["rebase", `origin/${baseBranch}`]);
11820
11836
  }
11821
11837
  async ensureGitRepo() {
11822
- const inside = await this.runCapture("git", [
11838
+ const inside2 = await this.runCapture("git", [
11823
11839
  "rev-parse",
11824
11840
  "--is-inside-work-tree"
11825
11841
  ]);
11826
- if (inside.trim() !== "true") {
11842
+ if (inside2.trim() !== "true") {
11827
11843
  throw new Error("This command must be run inside a git repository.");
11828
11844
  }
11829
11845
  }
@@ -12291,14 +12307,14 @@ var SummaryCommandHandler = class {
12291
12307
  };
12292
12308
  }
12293
12309
  async ensureGitRepo(cwd) {
12294
- const inside = await this.runCapture(
12310
+ const inside2 = await this.runCapture(
12295
12311
  "git",
12296
12312
  ["rev-parse", "--is-inside-work-tree"],
12297
12313
  false,
12298
12314
  void 0,
12299
12315
  cwd
12300
12316
  );
12301
- if (inside.trim() !== "true") {
12317
+ if (inside2.trim() !== "true") {
12302
12318
  throw new Error("This command must be run inside a git repository.");
12303
12319
  }
12304
12320
  }
@@ -13876,14 +13892,14 @@ var LinearCommandHandler = class {
13876
13892
  }
13877
13893
  }
13878
13894
  async ensureGitRepo(cwd) {
13879
- const inside = await this.runCapture(
13895
+ const inside2 = await this.runCapture(
13880
13896
  "git",
13881
13897
  ["rev-parse", "--is-inside-work-tree"],
13882
13898
  false,
13883
13899
  void 0,
13884
13900
  cwd
13885
13901
  );
13886
- if (inside.trim() !== "true") {
13902
+ if (inside2.trim() !== "true") {
13887
13903
  throw new Error("This command must be run inside a git repository.");
13888
13904
  }
13889
13905
  }
@@ -13983,10 +13999,10 @@ var LinearCommandHandler = class {
13983
13999
  if (!apiKey) {
13984
14000
  throw new Error("Missing openAI.apiKey in ~/.pmate/config.yaml.");
13985
14001
  }
13986
- const baseUrl = config.openAI?.baseUrl?.trim();
14002
+ const baseUrl2 = config.openAI?.baseUrl?.trim();
13987
14003
  return new import_openai.default({
13988
14004
  apiKey,
13989
- baseURL: baseUrl ? `${baseUrl}/v1` : void 0
14005
+ baseURL: baseUrl2 ? `${baseUrl2}/v1` : void 0
13990
14006
  });
13991
14007
  }
13992
14008
  getResponseText(response) {
@@ -14267,9 +14283,9 @@ ${indent}\`\`\``;
14267
14283
  static richTextToPlain(richText) {
14268
14284
  return richText.map((item) => item.plain_text ?? item.text?.content ?? "").join("").trim();
14269
14285
  }
14270
- static async requestJson(path35, init) {
14286
+ static async requestJson(path36, init) {
14271
14287
  const token = this.getToken();
14272
- const response = await fetch(`${this.baseUrl}${path35}`, {
14288
+ const response = await fetch(`${this.baseUrl}${path36}`, {
14273
14289
  method: init.method,
14274
14290
  headers: {
14275
14291
  Authorization: `Bearer ${token}`,
@@ -15394,8 +15410,8 @@ var import_playwright = require("playwright");
15394
15410
  // src/im1BotClient.ts
15395
15411
  var DEFAULT_IM1_BASE_URL = "http://localhost:39223";
15396
15412
  var Im1BotClient = class {
15397
- constructor(baseUrl = process.env.PMATE_IM1_BASE_URL ?? DEFAULT_IM1_BASE_URL) {
15398
- this.baseUrl = baseUrl;
15413
+ constructor(baseUrl2 = process.env.PMATE_IM1_BASE_URL ?? DEFAULT_IM1_BASE_URL) {
15414
+ this.baseUrl = baseUrl2;
15399
15415
  }
15400
15416
  async health() {
15401
15417
  return this.request("/health");
@@ -16838,11 +16854,11 @@ var RegistryResourceCommandHandler = class {
16838
16854
  async handle(args) {
16839
16855
  const resource = args.type === "function" ? "functions" : "workers";
16840
16856
  const singular = args.type === "function" ? "Function" : "Worker";
16841
- const baseUrl = (args.baseUrl || process.env.PMATE_AGENT_API_BASE_URL || "https://agent-api.pmate.chat").replace(/\/+$/, "");
16857
+ const baseUrl2 = (args.baseUrl || process.env.PMATE_AGENT_API_BASE_URL || "https://agent-api.pmate.chat").replace(/\/+$/, "");
16842
16858
  const token = readRequiredSession({ preferredApp: DEFAULT_APP_ID }).token;
16843
16859
  if (args.action === "list") {
16844
16860
  const query = args.namespace ? `?namespace=${encodeURIComponent(args.namespace)}` : "";
16845
- const { items } = await request(baseUrl, token, "GET", `/v1/${resource}${query}`);
16861
+ const { items } = await request(baseUrl2, token, "GET", `/v1/${resource}${query}`);
16846
16862
  if (args.json) ui.plain(JSON.stringify(items, null, 2));
16847
16863
  else if (!items.length) ui.warn(`No ${resource} found.`);
16848
16864
  else for (const item of items) ui.info(item.id, { status: item.status, ...item.payload });
@@ -16850,18 +16866,18 @@ var RegistryResourceCommandHandler = class {
16850
16866
  }
16851
16867
  const resourcePath = `/v1/${resource}/${encodeURIComponent(args.namespace)}${args.action === "create" ? "" : `/${encodeURIComponent(args.name)}`}`;
16852
16868
  if (args.action === "get" || args.action === "view") {
16853
- const record2 = await request(baseUrl, token, "GET", resourcePath);
16869
+ const record2 = await request(baseUrl2, token, "GET", resourcePath);
16854
16870
  ui.plain(JSON.stringify(record2, null, 2));
16855
16871
  return;
16856
16872
  }
16857
16873
  if (args.action === "create" || args.action === "update") {
16858
16874
  const payload = readJson(args.filePath);
16859
- const record2 = await request(baseUrl, token, args.action === "create" ? "POST" : "PUT", resourcePath, payload);
16875
+ const record2 = await request(baseUrl2, token, args.action === "create" ? "POST" : "PUT", resourcePath, payload);
16860
16876
  ui.success(`${args.action === "create" ? "Created" : "Updated"} ${singular.toLowerCase()} ${record2.id}`);
16861
16877
  if (args.json) ui.plain(JSON.stringify(record2, null, 2));
16862
16878
  return;
16863
16879
  }
16864
- const record = await request(baseUrl, token, "DELETE", resourcePath);
16880
+ const record = await request(baseUrl2, token, "DELETE", resourcePath);
16865
16881
  ui.success(`Disabled ${singular.toLowerCase()} ${record.id}`);
16866
16882
  if (args.json) ui.plain(JSON.stringify(record, null, 2));
16867
16883
  }
@@ -16871,8 +16887,8 @@ function readJson(filePath) {
16871
16887
  if (!(0, import_node_fs15.existsSync)(absolutePath)) throw new Error(`JSON file not found: ${absolutePath}`);
16872
16888
  return JSON.parse((0, import_node_fs15.readFileSync)(absolutePath, "utf8"));
16873
16889
  }
16874
- async function request(baseUrl, token, method, pathname, body) {
16875
- const response = await fetch(`${baseUrl}${pathname}`, {
16890
+ async function request(baseUrl2, token, method, pathname, body) {
16891
+ const response = await fetch(`${baseUrl2}${pathname}`, {
16876
16892
  method,
16877
16893
  headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
16878
16894
  ...body === void 0 ? {} : { body: JSON.stringify(body) }
@@ -16973,9 +16989,9 @@ function descriptorPathSegments(descriptor) {
16973
16989
  const normalized = createDescriptor(descriptor);
16974
16990
  return ["chains", normalized.chain, "namespaces", normalized.ns, normalized.kind, normalized.name];
16975
16991
  }
16976
- function buildPathUrl(baseUrl, pathSegments, query) {
16977
- const path35 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
16978
- const url = new URL(path35, baseUrl);
16992
+ function buildPathUrl(baseUrl2, pathSegments, query) {
16993
+ const path36 = `/${pathSegments.map((segment) => encodeURIComponent(segment)).join("/")}`;
16994
+ const url = new URL(path36, baseUrl2);
16979
16995
  if (query) {
16980
16996
  for (const [key, value] of Object.entries(query)) {
16981
16997
  url.searchParams.set(key, String(value));
@@ -16999,8 +17015,8 @@ function normalizeNamespace(value) {
16999
17015
  return normalized;
17000
17016
  }
17001
17017
  var IndexerClient = class {
17002
- constructor(baseUrl, headers = {}) {
17003
- this.baseUrl = baseUrl;
17018
+ constructor(baseUrl2, headers = {}) {
17019
+ this.baseUrl = baseUrl2;
17004
17020
  this.headers = headers;
17005
17021
  }
17006
17022
  async requestByPath(pathSegments, options = {}) {
@@ -17023,9 +17039,9 @@ var IndexerClient = class {
17023
17039
  }
17024
17040
  };
17025
17041
  var BlockLogAppender = class {
17026
- constructor(chainId, baseUrl, headers = {}) {
17042
+ constructor(chainId, baseUrl2, headers = {}) {
17027
17043
  this.chainId = chainId;
17028
- this.baseUrl = baseUrl;
17044
+ this.baseUrl = baseUrl2;
17029
17045
  this.headers = headers;
17030
17046
  }
17031
17047
  async append(logs) {
@@ -17288,8 +17304,8 @@ var NsCommandHandler = class {
17288
17304
  }
17289
17305
  }
17290
17306
  }
17291
- resolveBaseUrl(baseUrl) {
17292
- return (baseUrl || process.env.PMATE_NAMESPACE_API_BASE_URL || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
17307
+ resolveBaseUrl(baseUrl2) {
17308
+ return (baseUrl2 || process.env.PMATE_NAMESPACE_API_BASE_URL || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
17293
17309
  }
17294
17310
  resolveAuthHeaders() {
17295
17311
  return {
@@ -17433,8 +17449,8 @@ var StoreCommandHandler = class {
17433
17449
  const token = readRequiredSession({ preferredApp: DEFAULT_APP_ID }).token;
17434
17450
  return { Authorization: `Bearer ${token}` };
17435
17451
  }
17436
- resolveBaseUrl(baseUrl) {
17437
- const resolved = baseUrl || process.env.PMATE_STORE_BASE_URL || process.env.BLOCKCHAIN_BASE_URL;
17452
+ resolveBaseUrl(baseUrl2) {
17453
+ const resolved = baseUrl2 || process.env.PMATE_STORE_BASE_URL || process.env.BLOCKCHAIN_BASE_URL;
17438
17454
  if (!resolved) {
17439
17455
  throw new Error(
17440
17456
  "Missing store base URL. Provide --base-url or set PMATE_STORE_BASE_URL / BLOCKCHAIN_BASE_URL."
@@ -17465,8 +17481,8 @@ var StoreCommandHandler = class {
17465
17481
  return args.action === "set" || args.action === "delete";
17466
17482
  }
17467
17483
  async listNamespaces(args) {
17468
- const baseUrl = this.resolveIndexerBaseUrl(args.indexerBaseUrl);
17469
- const url = new URL(`/chains/${encodeURIComponent(args.chain)}/namespaces`, `${baseUrl}/`);
17484
+ const baseUrl2 = this.resolveIndexerBaseUrl(args.indexerBaseUrl);
17485
+ const url = new URL(`/chains/${encodeURIComponent(args.chain)}/namespaces`, `${baseUrl2}/`);
17470
17486
  const response = await fetch(url.toString(), {
17471
17487
  headers: {
17472
17488
  Accept: "application/json",
@@ -17908,11 +17924,11 @@ init_namespacedRef();
17908
17924
  var AppCommandHandler = class {
17909
17925
  async handle(args) {
17910
17926
  const token = this.readToken();
17911
- const baseUrl = this.resolveBaseUrl(args.baseUrl);
17927
+ const baseUrl2 = this.resolveBaseUrl(args.baseUrl);
17912
17928
  switch (args.action) {
17913
17929
  case "list": {
17914
17930
  const response = await this.request(
17915
- baseUrl,
17931
+ baseUrl2,
17916
17932
  token,
17917
17933
  "GET",
17918
17934
  "/apps"
@@ -17930,7 +17946,7 @@ var AppCommandHandler = class {
17930
17946
  case "view": {
17931
17947
  const pathname = this.buildAppPath(args.id);
17932
17948
  const record = await this.request(
17933
- baseUrl,
17949
+ baseUrl2,
17934
17950
  token,
17935
17951
  "GET",
17936
17952
  pathname
@@ -17944,9 +17960,9 @@ var AppCommandHandler = class {
17944
17960
  }
17945
17961
  case "create": {
17946
17962
  const payload = await this.preparePayload(args.filePath);
17947
- await this.requireNamespace(payload, baseUrl);
17963
+ await this.requireNamespace(payload, baseUrl2);
17948
17964
  const record = await this.request(
17949
- baseUrl,
17965
+ baseUrl2,
17950
17966
  token,
17951
17967
  "POST",
17952
17968
  "/apps",
@@ -17960,7 +17976,7 @@ var AppCommandHandler = class {
17960
17976
  const payload = await this.preparePayload(args.filePath, args.id);
17961
17977
  const pathname = this.buildAppPath(args.id);
17962
17978
  const record = await this.request(
17963
- baseUrl,
17979
+ baseUrl2,
17964
17980
  token,
17965
17981
  "PUT",
17966
17982
  pathname,
@@ -17972,7 +17988,7 @@ var AppCommandHandler = class {
17972
17988
  }
17973
17989
  case "icon": {
17974
17990
  const record = await this.request(
17975
- baseUrl,
17991
+ baseUrl2,
17976
17992
  token,
17977
17993
  "GET",
17978
17994
  this.buildAppPath(args.id)
@@ -18006,7 +18022,7 @@ var AppCommandHandler = class {
18006
18022
  case "icon-add": {
18007
18023
  const pathname = this.buildAppPath(args.id);
18008
18024
  const record = await this.request(
18009
- baseUrl,
18025
+ baseUrl2,
18010
18026
  token,
18011
18027
  "GET",
18012
18028
  pathname
@@ -18028,7 +18044,7 @@ var AppCommandHandler = class {
18028
18044
  [name]: source.value
18029
18045
  };
18030
18046
  const updatedRecord = await this.request(
18031
- baseUrl,
18047
+ baseUrl2,
18032
18048
  token,
18033
18049
  "PUT",
18034
18050
  pathname,
@@ -18052,7 +18068,7 @@ var AppCommandHandler = class {
18052
18068
  case "delete": {
18053
18069
  const pathname = this.buildAppPath(args.id);
18054
18070
  const record = await this.request(
18055
- baseUrl,
18071
+ baseUrl2,
18056
18072
  token,
18057
18073
  "DELETE",
18058
18074
  pathname
@@ -18063,7 +18079,7 @@ var AppCommandHandler = class {
18063
18079
  }
18064
18080
  case "rename": {
18065
18081
  const record = await this.request(
18066
- baseUrl,
18082
+ baseUrl2,
18067
18083
  token,
18068
18084
  "POST",
18069
18085
  `/apps/${encodeURIComponent(args.namespace)}/rename`,
@@ -18080,7 +18096,7 @@ var AppCommandHandler = class {
18080
18096
  }
18081
18097
  case "move": {
18082
18098
  const record = await this.request(
18083
- baseUrl,
18099
+ baseUrl2,
18084
18100
  token,
18085
18101
  "POST",
18086
18102
  `/apps/${encodeURIComponent(args.namespace)}/move`,
@@ -18098,8 +18114,8 @@ var AppCommandHandler = class {
18098
18114
  }
18099
18115
  }
18100
18116
  }
18101
- resolveBaseUrl(baseUrl) {
18102
- return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
18117
+ resolveBaseUrl(baseUrl2) {
18118
+ return (baseUrl2 || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
18103
18119
  }
18104
18120
  readToken() {
18105
18121
  return readRequiredSession({
@@ -18126,8 +18142,8 @@ var AppCommandHandler = class {
18126
18142
  resolveFilePath(filePath) {
18127
18143
  return import_node_path24.default.resolve(process.cwd(), filePath);
18128
18144
  }
18129
- async request(baseUrl, token, method, pathname, body) {
18130
- const response = await fetch(`${baseUrl}${pathname}`, {
18145
+ async request(baseUrl2, token, method, pathname, body) {
18146
+ const response = await fetch(`${baseUrl2}${pathname}`, {
18131
18147
  method,
18132
18148
  headers: {
18133
18149
  Authorization: `Bearer ${token}`,
@@ -18146,11 +18162,11 @@ var AppCommandHandler = class {
18146
18162
  }
18147
18163
  return payload.data;
18148
18164
  }
18149
- async requireNamespace(payload, baseUrl) {
18165
+ async requireNamespace(payload, baseUrl2) {
18150
18166
  const namespace = readNamespaceFromPayload(payload);
18151
18167
  const registry = new NamespaceRegistry({
18152
18168
  chain: "pmate",
18153
- registryBaseUrl: baseUrl
18169
+ registryBaseUrl: baseUrl2
18154
18170
  });
18155
18171
  const exists = await registry.exists(namespace);
18156
18172
  if (!exists) {
@@ -18244,15 +18260,15 @@ function readNamespaceFromPayload(payload) {
18244
18260
  }
18245
18261
 
18246
18262
  // src/commands/ServiceCommandHandler.ts
18247
- var import_node_fs26 = require("fs");
18263
+ var import_node_fs27 = require("fs");
18248
18264
  var import_promises5 = require("fs/promises");
18249
- var import_node_path31 = __toESM(require("path"));
18250
- var import_node_child_process13 = require("child_process");
18265
+ var import_node_path32 = __toESM(require("path"));
18266
+ var import_node_child_process14 = require("child_process");
18251
18267
  var import_promises6 = require("readline/promises");
18252
18268
 
18253
18269
  // src/services/NativeServiceDeploy.ts
18254
- var import_node_path29 = __toESM(require("path"));
18255
- var import_node_fs24 = require("fs");
18270
+ var import_node_path30 = __toESM(require("path"));
18271
+ var import_node_fs25 = require("fs");
18256
18272
 
18257
18273
  // src/electronBuild.ts
18258
18274
  var import_node_child_process9 = require("child_process");
@@ -18270,7 +18286,7 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
18270
18286
  if (app.split(":").length !== 2 || segments.some((s) => !/^[\w.-]+$/.test(s) || s === "." || s === "..")) throw new Error("Invalid desktop release identity");
18271
18287
  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
18288
  const { token } = readRequiredSession({ preferredApp: DEFAULT_APP_ID });
18273
- const bucket = "parrot-static";
18289
+ const bucket2 = "parrot-static";
18274
18290
  const prefix = `desktop/${segments.join("/")}/`;
18275
18291
  const url = (key) => `https://parrot-static.pmate.chat/${key.split("/").map(encodeURIComponent).join("/")}`;
18276
18292
  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) => {
@@ -18280,11 +18296,11 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
18280
18296
  });
18281
18297
  if (!artifacts.length) throw new Error("No desktop installers found to publish");
18282
18298
  const manifestKey = prefix + "release.json";
18283
- const existing = await AliyunService.readJsonObject(bucket, manifestKey);
18299
+ const existing = await AliyunService.readJsonObject(bucket2, manifestKey);
18284
18300
  const release = { schemaVersion: 1, app, version, platform, arch, artifacts };
18285
18301
  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);
18302
+ for (const artifact of artifacts) await AliyunService.uploadFile(import_node_path25.default.join(directory, artifact.name), bucket2, artifact.objectKey);
18303
+ await AliyunService.uploadJsonObject(bucket2, manifestKey, release);
18288
18304
  const base = (process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
18289
18305
  const response = await fetch(`${base}/versions/${encodeURIComponent(app)}`, {
18290
18306
  method: "POST",
@@ -18295,7 +18311,7 @@ async function uploadDesktopArtifacts(directory, app, version, platform, arch) {
18295
18311
  });
18296
18312
  const result = await response.json();
18297
18313
  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 };
18314
+ return { bucket: bucket2, manifestUrl: url(manifestKey), downloads: artifacts };
18299
18315
  }
18300
18316
 
18301
18317
  // src/electronBuild.ts
@@ -18520,8 +18536,19 @@ var AndroidApkReleaseService = class {
18520
18536
  const identity = androidArtifactIdentity(service);
18521
18537
  const repoRoot = this.resolveRepoRoot(service, options.cwd);
18522
18538
  const appDir = this.resolveAppDir(service, repoRoot);
18539
+ let publishedFloor = 0;
18540
+ if (options.env === "prod" && options.variant.toLowerCase() === "release") {
18541
+ const expectedPackage2 = "type" in service && service.mobile && "packageName" in service.mobile ? service.mobile.packageName : void 0;
18542
+ for (const key of androidUpdateManifestKeys(service)) {
18543
+ const latest = await AliyunService.readJsonObject(ANDROID_APK_BUCKET, key);
18544
+ if (latest === null) continue;
18545
+ if (!expectedPackage2 || latest.applicationId !== expectedPackage2 || !Number.isSafeInteger(latest.versionCode) || latest.versionCode <= 0) throw new Error("Published Android manifest identity/version is invalid; release stopped");
18546
+ publishedFloor = Math.max(publishedFloor, latest.versionCode);
18547
+ }
18548
+ }
18549
+ const bump = planAndroidProjectVersion(appDir, options.bump, publishedFloor);
18523
18550
  const signing = options.variant.toLowerCase() === "release" ? await this.loadSigning(service.id, options.env) : void 0;
18524
- const bump = bumpAndroidProjectVersion(appDir, options.bump);
18551
+ (0, import_node_fs22.writeFileSync)(bump.filePath, bump.source);
18525
18552
  ui.info("Bumped Android version", {
18526
18553
  file: bump.filePath,
18527
18554
  from: `${bump.previousVersionName} (${bump.previousVersionCode})`,
@@ -18530,6 +18557,8 @@ var AndroidApkReleaseService = class {
18530
18557
  const builtApkPath = await this.runGradleAssembleAndFindApk(repoRoot, appDir, options.variant);
18531
18558
  const apkPath = signing ? await signAndroidApk(builtApkPath, signing) : builtApkPath;
18532
18559
  const metadata = await this.readApkMetadata(apkPath);
18560
+ const expectedPackage = "type" in service && service.mobile && "packageName" in service.mobile ? service.mobile.packageName : void 0;
18561
+ if (expectedPackage && metadata.applicationId !== expectedPackage) throw new Error("APK applicationId does not match registered Android service; upload stopped");
18533
18562
  if (metadata.versionName !== bump.versionName || metadata.versionCode !== bump.versionCode) {
18534
18563
  throw new Error(
18535
18564
  `APK metadata ${metadata.versionName} (${metadata.versionCode}) does not match bumped version ${bump.versionName} (${bump.versionCode}).`
@@ -18845,7 +18874,7 @@ function parseGradleOutputMetadata(source, apkFileName) {
18845
18874
  }
18846
18875
  return { applicationId, versionName, versionCode };
18847
18876
  }
18848
- function bumpAndroidProjectVersion(appDir, bump) {
18877
+ function planAndroidProjectVersion(appDir, bump, publishedFloor = 0) {
18849
18878
  const candidates = [
18850
18879
  import_node_path27.default.join(appDir, "app", "build.gradle.kts"),
18851
18880
  import_node_path27.default.join(appDir, "app", "build.gradle"),
@@ -18855,7 +18884,7 @@ function bumpAndroidProjectVersion(appDir, bump) {
18855
18884
  for (const candidate of candidates) {
18856
18885
  if (!(0, import_node_fs22.existsSync)(candidate)) continue;
18857
18886
  const result = bumpAndroidGradleVersionText((0, import_node_fs22.readFileSync)(candidate, "utf8"), bump);
18858
- (0, import_node_fs22.writeFileSync)(candidate, result.source);
18887
+ if (!Number.isSafeInteger(result.versionCode) || result.versionCode <= publishedFloor) throw new Error(`Android source is behind published versionCode ${publishedFloor}; update the checkout before releasing`);
18859
18888
  return { filePath: candidate, ...result };
18860
18889
  }
18861
18890
  throw new Error(`No Android Gradle version file found under ${appDir}`);
@@ -18951,12 +18980,293 @@ function capitalize(value) {
18951
18980
  return value.slice(0, 1).toUpperCase() + value.slice(1);
18952
18981
  }
18953
18982
 
18954
- // src/services/IosBuildService.ts
18983
+ // src/services/HarmonyReleaseService.ts
18955
18984
  var import_node_child_process11 = require("child_process");
18956
18985
  var import_node_crypto6 = require("crypto");
18957
18986
  var import_node_fs23 = require("fs");
18958
18987
  var import_node_os12 = __toESM(require("os"));
18959
18988
  var import_node_path28 = __toESM(require("path"));
18989
+ var import_json5 = __toESM(require("json5"));
18990
+ var HARMONY_SIGNING_KEYS = ["HARMONY_KEYSTORE_BASE64", "HARMONY_CERTIFICATE_BASE64", "HARMONY_PROFILE_BASE64", "HARMONY_STORE_PASSWORD", "HARMONY_KEY_ALIAS", "HARMONY_KEY_PASSWORD"];
18991
+ var bucket = "parrot-static";
18992
+ var baseUrl = "https://parrot-static.pmate.chat";
18993
+ var inside = (parent, child) => {
18994
+ const rel = import_node_path28.default.relative(parent, child);
18995
+ return !rel || !rel.startsWith(`..${import_node_path28.default.sep}`) && rel !== ".." && !import_node_path28.default.isAbsolute(rel);
18996
+ };
18997
+ var readJson5 = (file) => import_json5.default.parse((0, import_node_fs23.readFileSync)(file, "utf8"));
18998
+ function readHarmonyVersion(appDir, expected) {
18999
+ const app = readJson5(import_node_path28.default.join(appDir, "AppScope/app.json5")).app;
19000
+ if (!app || app.bundleName !== expected) throw new Error("HarmonyOS bundleName does not match service.mobile.bundleName");
19001
+ if (!/^\d+\.\d+\.\d+$/.test(app.versionName ?? "") || !Number.isSafeInteger(app.versionCode) || app.versionCode <= 0) throw new Error("HarmonyOS source requires a stable versionName and positive integer versionCode");
19002
+ return { bundleName: app.bundleName, versionName: app.versionName, versionCode: app.versionCode };
19003
+ }
19004
+ function stageHarmonySources(repoRoot, appDir, target) {
19005
+ const copied = [];
19006
+ const excluded = /* @__PURE__ */ new Set([".git", "node_modules", "oh_modules", ".hvigor", ".idea", "build", "dist", ".gradle", "local.properties"]);
19007
+ const copy = (source) => {
19008
+ if (!inside(repoRoot, source)) throw new Error("HarmonyOS local dependencies must stay inside the repository");
19009
+ if (copied.some((dir) => inside(dir, source))) return;
19010
+ if (!(0, import_node_fs23.existsSync)(source) || !(0, import_node_fs23.lstatSync)(source).isDirectory() || (0, import_node_fs23.lstatSync)(source).isSymbolicLink()) throw new Error("Invalid HarmonyOS source dependency");
19011
+ if (!inside((0, import_node_fs23.realpathSync)(repoRoot), (0, import_node_fs23.realpathSync)(source))) throw new Error("HarmonyOS local dependencies must stay inside the repository");
19012
+ const dest = import_node_path28.default.join(target, import_node_path28.default.relative(repoRoot, source));
19013
+ (0, import_node_fs23.cpSync)(source, dest, { recursive: true, filter: (file) => {
19014
+ if ((0, import_node_fs23.lstatSync)(file).isSymbolicLink()) throw new Error("HarmonyOS source symlinks are not supported");
19015
+ const name = import_node_path28.default.basename(file);
19016
+ return !excluded.has(name) && !name.startsWith(".env") && !/\.(p12|pfx|p7b|keystore|jks|key|pem|cer)$/i.test(name);
19017
+ } });
19018
+ copied.push(source);
19019
+ const inspect = (dir) => {
19020
+ for (const entry of (0, import_node_fs23.readdirSync)(dir, { withFileTypes: true })) {
19021
+ const file = import_node_path28.default.join(dir, entry.name);
19022
+ if (entry.isDirectory()) inspect(file);
19023
+ else if (entry.name === "oh-package.json5") {
19024
+ const manifest = readJson5(file);
19025
+ for (const value of Object.values({ ...manifest.dependencies, ...manifest.devDependencies })) {
19026
+ if (typeof value !== "string" || !value.startsWith("file:")) continue;
19027
+ const original = import_node_path28.default.join(repoRoot, import_node_path28.default.relative(target, import_node_path28.default.dirname(file)));
19028
+ copy(import_node_path28.default.resolve(original, value.slice(5)));
19029
+ }
19030
+ }
19031
+ }
19032
+ };
19033
+ inspect(dest);
19034
+ };
19035
+ copy(appDir);
19036
+ const profile = readJson5(import_node_path28.default.join(appDir, "build-profile.json5"));
19037
+ for (const module2 of profile.modules ?? []) {
19038
+ if (typeof module2.srcPath !== "string") throw new Error("Invalid HarmonyOS module srcPath");
19039
+ copy(import_node_path28.default.resolve(appDir, module2.srcPath));
19040
+ }
19041
+ return import_node_path28.default.join(target, import_node_path28.default.relative(repoRoot, appDir));
19042
+ }
19043
+ function executable(value) {
19044
+ const candidates = value.includes(import_node_path28.default.sep) ? [import_node_path28.default.resolve(value)] : (process.env.PATH ?? "").split(import_node_path28.default.delimiter).map((dir) => import_node_path28.default.join(dir, value));
19045
+ for (const file of candidates) {
19046
+ try {
19047
+ (0, import_node_fs23.accessSync)(file, import_node_fs23.constants.X_OK);
19048
+ if ((0, import_node_fs23.lstatSync)(file).isFile() || (0, import_node_fs23.lstatSync)(file).isSymbolicLink()) return file;
19049
+ } catch {
19050
+ }
19051
+ }
19052
+ throw new Error(`HarmonyOS tool is missing: ${value}; configure the DevEco build toolchain`);
19053
+ }
19054
+ function findHarmonyTools() {
19055
+ if (!["darwin", "linux"].includes(process.platform)) throw new Error("HarmonyOS release scripts require macOS or Linux");
19056
+ const home = "/Applications/DevEco-Studio.app/Contents";
19057
+ const sdk = import_node_path28.default.resolve(process.env.DEVECO_SDK_HOME ?? `${home}/sdk`);
19058
+ if (!(0, import_node_fs23.existsSync)(sdk)) throw new Error("HarmonyOS SDK not found; install DevEco Studio or set DEVECO_SDK_HOME");
19059
+ const tools = { sdk, ohpm: executable(process.env.OHPM_BIN ?? `${home}/tools/ohpm/bin/ohpm`), hvigor: executable(process.env.HVIGORW_BIN ?? `${home}/tools/hvigor/bin/hvigorw`), node: executable(process.env.NODE_BIN ?? process.execPath), java: executable(process.env.JAVA_BIN ?? "java"), signer: process.env.HAP_SIGN_TOOL ?? "" };
19060
+ if (!tools.signer) {
19061
+ const jars = [];
19062
+ const scan = (dir) => {
19063
+ for (const entry of (0, import_node_fs23.readdirSync)(dir, { withFileTypes: true })) {
19064
+ const file = import_node_path28.default.join(dir, entry.name);
19065
+ if (entry.isDirectory()) scan(file);
19066
+ else if (entry.isFile() && entry.name === "hap-sign-tool.jar") jars.push(file);
19067
+ }
19068
+ };
19069
+ scan(sdk);
19070
+ if (jars.length !== 1) throw new Error("Set HAP_SIGN_TOOL to the intended hap-sign-tool.jar");
19071
+ tools.signer = jars[0];
19072
+ }
19073
+ tools.signer = import_node_path28.default.resolve(tools.signer);
19074
+ if (!(0, import_node_fs23.existsSync)(tools.signer)) throw new Error("HAP_SIGN_TOOL does not exist");
19075
+ executable("bash");
19076
+ executable("unzip");
19077
+ return tools;
19078
+ }
19079
+ var runHarmonyCommand = async (command, args, options) => {
19080
+ const log = (0, import_node_fs23.openSync)(options.log, "a", 384);
19081
+ const output = options.output ? (0, import_node_fs23.openSync)(options.output, "w", 384) : void 0;
19082
+ try {
19083
+ return await new Promise((resolve, reject) => {
19084
+ const child = (0, import_node_child_process11.spawn)(command, args, { cwd: options.cwd, env: options.env, detached: process.platform !== "win32", stdio: ["ignore", output ?? (options.capture ? "pipe" : log), log] });
19085
+ let text = "", oversized = false;
19086
+ child.stdout?.on("data", (chunk) => {
19087
+ if (Buffer.byteLength(text) + chunk.length > 1024 * 1024) {
19088
+ oversized = true;
19089
+ child.kill();
19090
+ } else text += chunk.toString();
19091
+ });
19092
+ const interrupt = () => {
19093
+ try {
19094
+ if (process.platform !== "win32" && child.pid) process.kill(-child.pid, "SIGTERM");
19095
+ else child.kill("SIGTERM");
19096
+ } catch {
19097
+ }
19098
+ };
19099
+ process.once("SIGINT", interrupt);
19100
+ process.once("SIGTERM", interrupt);
19101
+ const clean = () => {
19102
+ process.removeListener("SIGINT", interrupt);
19103
+ process.removeListener("SIGTERM", interrupt);
19104
+ };
19105
+ child.once("error", () => {
19106
+ clean();
19107
+ reject(new Error(`Cannot run ${import_node_path28.default.basename(command)}; see ${options.log}`));
19108
+ });
19109
+ child.once("close", (code) => {
19110
+ clean();
19111
+ code === 0 && !oversized ? resolve(text) : reject(new Error(`HarmonyOS ${import_node_path28.default.basename(command)} failed (${code}); see ${options.log}`));
19112
+ });
19113
+ });
19114
+ } finally {
19115
+ (0, import_node_fs23.closeSync)(log);
19116
+ if (output !== void 0) (0, import_node_fs23.closeSync)(output);
19117
+ }
19118
+ };
19119
+ function signingMaterial(values) {
19120
+ for (const key of HARMONY_SIGNING_KEYS) if (!values[key]?.trim()) throw new Error(`Missing HarmonyOS service signing variable: ${key}`);
19121
+ const decode2 = (key) => {
19122
+ const text = values[key].replace(/\s/g, ""), bytes = Buffer.from(text, "base64");
19123
+ if (!bytes.length || bytes.length > 5 * 1024 * 1024 || bytes.toString("base64") !== text) throw new Error(`Invalid HarmonyOS signing material: ${key}`);
19124
+ return bytes;
19125
+ };
19126
+ const certificate = decode2("HARMONY_CERTIFICATE_BASE64");
19127
+ const fingerprint = new import_node_crypto6.X509Certificate(certificate).fingerprint256.replace(/:/g, "");
19128
+ return { keystore: decode2("HARMONY_KEYSTORE_BASE64"), certificate, profile: decode2("HARMONY_PROFILE_BASE64"), fingerprint };
19129
+ }
19130
+ function assertHarmonyMetadata(raw, version) {
19131
+ const data = raw;
19132
+ if (!data?.app || data.app.bundleName !== version.bundleName || data.app.versionName !== version.versionName || data.app.versionCode !== version.versionCode || data.app.debug !== void 0 && data.app.debug !== false || data.module?.debug !== void 0 && data.module.debug !== false) throw new Error("HarmonyOS package identity/version/debug metadata mismatch");
19133
+ }
19134
+ var withHarmonyPublicationLock = async (bucket2, key, publish) => {
19135
+ if (!/^harmony\/[\w-]+\/[\w-]+\/\.publish-lock\.json$/.test(key)) throw new Error("Invalid HarmonyOS publication lock key");
19136
+ await AliyunService.assertUnversionedBucket(bucket2);
19137
+ const owner = (0, import_node_crypto6.randomUUID)();
19138
+ try {
19139
+ await AliyunService.uploadJsonObject(bucket2, key, { owner, createdAt: (/* @__PURE__ */ new Date()).toISOString() }, { "x-oss-forbid-overwrite": "true" });
19140
+ } catch {
19141
+ throw new Error("HarmonyOS publication is locked or the lock cannot be created; verify the active publisher before clearing a stale lock");
19142
+ }
19143
+ try {
19144
+ return await publish();
19145
+ } finally {
19146
+ const lock = await AliyunService.readJsonObject(bucket2, key);
19147
+ if (lock?.owner !== owner) throw new Error("HarmonyOS publication lock ownership changed; refusing to delete another publisher's lock");
19148
+ await AliyunService.removePublicationLock(bucket2, key);
19149
+ }
19150
+ };
19151
+ var HarmonyReleaseService = class {
19152
+ constructor(registry, deps = {}) {
19153
+ this.registry = registry;
19154
+ this.deps = deps;
19155
+ }
19156
+ async release(service, options) {
19157
+ if (!("type" in service) || service.type !== "harmonyos" || !service.mobile || !("bundleName" in service.mobile)) throw new Error("HarmonyOS requires service.mobile.bundleName");
19158
+ if (service.appIds?.length !== 1) throw new Error("HarmonyOS service requires exactly one appIds application identity");
19159
+ const application = service.appIds[0];
19160
+ const root = options.cwd ? import_node_path28.default.resolve(options.cwd) : resolveRepositoryLocalRoot(service.repository ?? service.mobile.repository ?? "");
19161
+ const dir = service.dir ?? service.mobile.dir;
19162
+ if (!dir) throw new Error("HarmonyOS service requires a source directory");
19163
+ const appDir = import_node_path28.default.resolve(root, dir);
19164
+ if (!inside(root, appDir)) throw new Error("HarmonyOS source must stay inside the repository");
19165
+ const version = readHarmonyVersion(appDir, service.mobile.bundleName);
19166
+ const script = service.build?.script ?? "scripts/build-release.sh";
19167
+ if (import_node_path28.default.isAbsolute(script) || !inside(appDir, import_node_path28.default.resolve(appDir, script)) || (!(0, import_node_fs23.existsSync)(import_node_path28.default.resolve(appDir, script)) || !(0, import_node_fs23.lstatSync)(import_node_path28.default.resolve(appDir, script)).isFile())) throw new Error("HarmonyOS build.script must name an existing script inside the application");
19168
+ const prefix = `harmony/${service.namespace}/${service.name}`;
19169
+ if (![service.namespace, service.name].every((v) => /^[\w-]+$/.test(v))) throw new Error("Invalid HarmonyOS service identity");
19170
+ const releasePrefix = `${prefix}/${version.versionName}/${version.versionCode}/`;
19171
+ const manifestUrl = `${baseUrl}/${releasePrefix}release.json`, latestUrl = `${baseUrl}/${prefix}/latest.json`;
19172
+ const plan = { serviceId: service.id, app: application, type: "harmonyos", ...version, appDir, script, manifestUrl, latestUrl, distribution: "oss", appGallerySubmitted: false };
19173
+ if (options.dryRun) return { ...plan, status: "dry-run" };
19174
+ const tools = (this.deps.tools ?? findHarmonyTools)();
19175
+ const read = this.deps.readJson ?? AliyunService.readJsonObject;
19176
+ if (!options.local) {
19177
+ const latest = await read(bucket, `${prefix}/latest.json`);
19178
+ if (latest && (latest.serviceId !== service.id || latest.app !== application || latest.bundleName !== version.bundleName || latest.schemaVersion !== 1 || latest.platform !== "harmonyos" || latest.signature !== "verified" || !Number.isSafeInteger(latest.versionCode) || latest.versionCode <= 0)) throw new Error("Invalid existing HarmonyOS update manifest");
19179
+ if (latest && latest.versionCode >= version.versionCode) throw new Error("HarmonyOS versionCode is already published or behind the latest release; update AppScope/app.json5");
19180
+ if (await read(bucket, `${releasePrefix}release.json`) !== null || (await (this.deps.list ?? AliyunService.listObjects)(bucket, releasePrefix)).length) throw new Error("HarmonyOS release already exists; published objects are immutable");
19181
+ }
19182
+ if (!this.registry) throw new Error("HarmonyOS signing requires the service environment registry");
19183
+ const { values } = await this.registry.resolveEnv(service.id, { stage: "prod", includeSecretValue: true, includeHost: false });
19184
+ const material = signingMaterial(values);
19185
+ const outputBase = options.outDir ? import_node_path28.default.resolve(options.outDir) : import_node_path28.default.join(import_node_os12.default.homedir(), ".pmate/harmony-builds", service.namespace, service.name);
19186
+ if (inside(appDir, outputBase)) throw new Error("HarmonyOS output must be outside the application source directory");
19187
+ (0, import_node_fs23.mkdirSync)(outputBase, { recursive: true, mode: 448 });
19188
+ const output = (0, import_node_fs23.mkdtempSync)(import_node_path28.default.join(outputBase, `release-${version.versionCode}-`)), log = import_node_path28.default.join(output, "build.log");
19189
+ (0, import_node_fs23.writeFileSync)(log, "", { mode: 384 });
19190
+ const temp = (0, import_node_fs23.mkdtempSync)(import_node_path28.default.join(import_node_os12.default.tmpdir(), "pmate-harmony-")), run = this.deps.run ?? runHarmonyCommand;
19191
+ let artifacts = [];
19192
+ try {
19193
+ const staged = stageHarmonySources(root, appDir, import_node_path28.default.join(temp, "checkout"));
19194
+ for (const relative of ["build-profile.json5", "AppScope/app.json5"]) {
19195
+ const file = import_node_path28.default.join(staged, relative);
19196
+ (0, import_node_fs23.writeFileSync)(file, JSON.stringify(readJson5(file), null, 2));
19197
+ }
19198
+ const keys = import_node_path28.default.join(temp, "signing");
19199
+ (0, import_node_fs23.mkdirSync)(keys, { mode: 448 });
19200
+ for (const [name, bytes] of [["release.p12", material.keystore], ["release.cer", material.certificate], ["release.p7b", material.profile]]) (0, import_node_fs23.writeFileSync)(import_node_path28.default.join(keys, name), bytes, { mode: 384 });
19201
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith("HARMONY_")));
19202
+ Object.assign(env, { DEVECO_SDK_HOME: tools.sdk, OHPM_BIN: tools.ohpm, HVIGORW_BIN: tools.hvigor, NODE_BIN: tools.node, JAVA_BIN: tools.java, HAP_SIGN_TOOL: tools.signer, HARMONY_KEYSTORE_FILE: import_node_path28.default.join(keys, "release.p12"), HARMONY_CERTIFICATE_FILE: import_node_path28.default.join(keys, "release.cer"), HARMONY_PROFILE_FILE: import_node_path28.default.join(keys, "release.p7b"), HARMONY_STORE_PASSWORD: values.HARMONY_STORE_PASSWORD, HARMONY_KEY_ALIAS: values.HARMONY_KEY_ALIAS, HARMONY_KEY_PASSWORD: values.HARMONY_KEY_PASSWORD, HARMONY_VERSION_NAME: version.versionName, HARMONY_VERSION_CODE: String(version.versionCode), HARMONY_RELEASE_DRY_RUN: "0" });
19203
+ const opts = { cwd: staged, env, log };
19204
+ await run("bash", [import_node_path28.default.resolve(staged, script)], opts);
19205
+ const dist = import_node_path28.default.join(staged, "dist");
19206
+ const files = (0, import_node_fs23.readdirSync)(dist, { withFileTypes: true }).filter((e) => e.isFile() && /\.(app|hap)$/.test(e.name)).map((e) => import_node_path28.default.join(dist, e.name));
19207
+ if (files.length !== 2 || files.filter((f) => f.endsWith(".app")).length !== 1 || files.filter((f) => f.endsWith(".hap")).length !== 1) throw new Error("HarmonyOS build must produce exactly one signed APP and one signed HAP");
19208
+ const check = async (file, inspectMetadata) => {
19209
+ const id = (0, import_node_crypto6.createHash)("sha256").update(file).digest("hex").slice(0, 16), cert = import_node_path28.default.join(temp, `${id}.cer`);
19210
+ await run(tools.java, ["-jar", tools.signer, "verify-app", "-inFile", file, "-outCertChain", cert, "-outProfile", import_node_path28.default.join(temp, `${id}.p7b`)], opts);
19211
+ if (new import_node_crypto6.X509Certificate((0, import_node_fs23.readFileSync)(cert)).fingerprint256.replace(/:/g, "") !== material.fingerprint) throw new Error("HarmonyOS signer certificate does not match service certificate");
19212
+ if (inspectMetadata) assertHarmonyMetadata(JSON.parse(await run("unzip", ["-p", file, "module.json"], { ...opts, capture: true })), version);
19213
+ };
19214
+ for (const file of files) {
19215
+ await check(file, file.endsWith(".hap"));
19216
+ if (file.endsWith(".app")) {
19217
+ const names = (await run("unzip", ["-Z1", file], { ...opts, capture: true })).split(/\r?\n/).filter((name) => /\.(hap|hsp)$/.test(name));
19218
+ if (!names.length) throw new Error("HarmonyOS APP contains no package modules");
19219
+ for (const [index, name] of names.entries()) {
19220
+ if (name.startsWith("/") || name.includes("\\") || name.split("/").includes("..")) throw new Error("Unsafe HarmonyOS archive member");
19221
+ const embedded = import_node_path28.default.join(temp, `module-${index}${import_node_path28.default.extname(name)}`);
19222
+ await run("unzip", ["-p", file, name], { ...opts, output: embedded });
19223
+ await check(embedded, true);
19224
+ }
19225
+ }
19226
+ }
19227
+ artifacts = [];
19228
+ for (const file of files) {
19229
+ const name = import_node_path28.default.basename(file);
19230
+ if (!/^[A-Za-z0-9._-]+\.(app|hap)$/.test(name)) throw new Error("Invalid HarmonyOS artifact filename");
19231
+ const size = (0, import_node_fs23.statSync)(file).size;
19232
+ if (!size) throw new Error("Empty HarmonyOS artifact");
19233
+ const target = import_node_path28.default.join(output, name);
19234
+ (0, import_node_fs23.cpSync)(file, target);
19235
+ const hash = (0, import_node_crypto6.createHash)("sha256");
19236
+ for await (const chunk of (0, import_node_fs23.createReadStream)(target)) hash.update(chunk);
19237
+ artifacts.push({ name, type: import_node_path28.default.extname(name).slice(1), objectKey: releasePrefix + name, downloadUrl: `${baseUrl}/${releasePrefix}${name}`, sha256: hash.digest("hex"), size });
19238
+ }
19239
+ } finally {
19240
+ (0, import_node_fs23.rmSync)(temp, { recursive: true, force: true });
19241
+ }
19242
+ if (options.local) return { ...plan, status: "local", output, log, artifacts };
19243
+ let revision;
19244
+ try {
19245
+ revision = (0, import_node_child_process11.execFileSync)("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
19246
+ } catch {
19247
+ }
19248
+ const manifest = { schemaVersion: 1, serviceId: service.id, app: application, platform: "harmonyos", distribution: "oss", appGallerySubmitted: false, ...version, signature: "verified", certificateSha256: material.fingerprint, sourceRevision: revision, artifacts, publishedAt: (/* @__PURE__ */ new Date()).toISOString() };
19249
+ const upload = this.deps.upload ?? AliyunService.uploadFile, uploadJson = this.deps.uploadJson ?? AliyunService.uploadJsonObject;
19250
+ await (this.deps.lock ?? withHarmonyPublicationLock)(bucket, `${prefix}/.publish-lock.json`, async () => {
19251
+ const latest = await read(bucket, `${prefix}/latest.json`);
19252
+ if (latest && (latest.serviceId !== service.id || latest.app !== application || latest.bundleName !== version.bundleName || latest.schemaVersion !== 1 || latest.platform !== "harmonyos" || latest.signature !== "verified" || !Number.isSafeInteger(latest.versionCode) || latest.versionCode <= 0)) throw new Error("Invalid existing HarmonyOS update manifest");
19253
+ if (latest && latest.versionCode >= version.versionCode) throw new Error("A same or newer HarmonyOS release was published during the build; latest is unchanged");
19254
+ if (await read(bucket, `${releasePrefix}release.json`) !== null || (await (this.deps.list ?? AliyunService.listObjects)(bucket, releasePrefix)).length) throw new Error("HarmonyOS release already exists; published objects are immutable");
19255
+ for (const artifact of artifacts) await upload(import_node_path28.default.join(output, artifact.name), bucket, artifact.objectKey, { "x-oss-forbid-overwrite": "true" });
19256
+ await uploadJson(bucket, `${releasePrefix}release.json`, manifest, { "x-oss-forbid-overwrite": "true" });
19257
+ await uploadJson(bucket, `${prefix}/latest.json`, manifest);
19258
+ });
19259
+ (0, import_node_fs23.writeFileSync)(import_node_path28.default.join(output, "release.json"), JSON.stringify(manifest, null, 2));
19260
+ return { ...plan, status: "published", output, log, signature: "verified", artifacts };
19261
+ }
19262
+ };
19263
+
19264
+ // src/services/IosBuildService.ts
19265
+ var import_node_child_process12 = require("child_process");
19266
+ var import_node_crypto7 = require("crypto");
19267
+ var import_node_fs24 = require("fs");
19268
+ var import_node_os13 = __toESM(require("os"));
19269
+ var import_node_path29 = __toESM(require("path"));
18960
19270
  function iosBuildInteger(value) {
18961
19271
  if (!/^(0|[1-9]\d*)$/.test(String(value)) || !Number.isSafeInteger(Number(value))) {
18962
19272
  throw new Error(`iOS Build must be a non-negative safe integer: ${String(value)}`);
@@ -18965,13 +19275,13 @@ function iosBuildInteger(value) {
18965
19275
  }
18966
19276
  async function runXcode(args, cwd, logPath) {
18967
19277
  return new Promise((resolve, reject) => {
18968
- const child = (0, import_node_child_process11.spawn)("xcodebuild", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
19278
+ const child = (0, import_node_child_process12.spawn)("xcodebuild", args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
18969
19279
  let output = "";
18970
19280
  child.stdout.on("data", (chunk) => {
18971
19281
  if (args.includes("-json") || args.includes("-version")) output += chunk.toString();
18972
- (0, import_node_fs23.appendFileSync)(logPath, chunk);
19282
+ (0, import_node_fs24.appendFileSync)(logPath, chunk);
18973
19283
  });
18974
- child.stderr.on("data", (chunk) => (0, import_node_fs23.appendFileSync)(logPath, chunk));
19284
+ child.stderr.on("data", (chunk) => (0, import_node_fs24.appendFileSync)(logPath, chunk));
18975
19285
  child.on("error", reject);
18976
19286
  child.on("close", (code) => code === 0 ? resolve(output) : reject(new Error(`xcodebuild failed (${code}); see ${logPath}`)));
18977
19287
  });
@@ -18990,18 +19300,18 @@ var IosBuildService = class {
18990
19300
  const repository = service.repository ?? service.mobile?.repository;
18991
19301
  const dir = service.dir ?? service.mobile?.dir;
18992
19302
  if (!dir || !repository && !options.cwd) throw new Error("iOS service requires repository and dir, or --cwd and dir");
18993
- const repoRoot = options.cwd ? import_node_path28.default.resolve(options.cwd) : resolveRepositoryLocalRoot(repository);
18994
- const appDir = import_node_path28.default.resolve(repoRoot, dir);
18995
- if (!(0, import_node_fs23.existsSync)(appDir)) throw new Error(`iOS app dir not found: ${appDir}`);
19303
+ const repoRoot = options.cwd ? import_node_path29.default.resolve(options.cwd) : resolveRepositoryLocalRoot(repository);
19304
+ const appDir = import_node_path29.default.resolve(repoRoot, dir);
19305
+ if (!(0, import_node_fs24.existsSync)(appDir)) throw new Error(`iOS app dir not found: ${appDir}`);
18996
19306
  const explicit = options.project ?? options.workspace;
18997
- const candidates = explicit ? [import_node_path28.default.resolve(appDir, explicit)] : (0, import_node_fs23.readdirSync)(appDir).filter((name) => /\.(xcodeproj|xcworkspace)$/.test(name)).map((name) => import_node_path28.default.join(appDir, name));
18998
- if (candidates.length !== 1 || !(0, import_node_fs23.existsSync)(candidates[0])) throw new Error("Specify exactly one existing --project or --workspace; project discovery is ambiguous or empty");
19307
+ const candidates = explicit ? [import_node_path29.default.resolve(appDir, explicit)] : (0, import_node_fs24.readdirSync)(appDir).filter((name) => /\.(xcodeproj|xcworkspace)$/.test(name)).map((name) => import_node_path29.default.join(appDir, name));
19308
+ if (candidates.length !== 1 || !(0, import_node_fs24.existsSync)(candidates[0])) throw new Error("Specify exactly one existing --project or --workspace; project discovery is ambiguous or empty");
18999
19309
  const project = candidates[0];
19000
- const expectedExtension = options.workspace ? ".xcworkspace" : options.project ? ".xcodeproj" : import_node_path28.default.extname(project);
19001
- if (![".xcodeproj", ".xcworkspace"].includes(expectedExtension) || import_node_path28.default.extname(project) !== expectedExtension) throw new Error("Invalid Xcode project/workspace extension");
19002
- const root = this.deps.stateRoot ?? import_node_path28.default.join(import_node_os12.default.homedir(), ".pmate", "ios-builds");
19003
- (0, import_node_fs23.mkdirSync)(root, { recursive: true, mode: 448 });
19004
- const preflightLog = import_node_path28.default.join(root, `preflight-${process.pid}-${Date.now()}.log`);
19310
+ const expectedExtension = options.workspace ? ".xcworkspace" : options.project ? ".xcodeproj" : import_node_path29.default.extname(project);
19311
+ if (![".xcodeproj", ".xcworkspace"].includes(expectedExtension) || import_node_path29.default.extname(project) !== expectedExtension) throw new Error("Invalid Xcode project/workspace extension");
19312
+ const root = this.deps.stateRoot ?? import_node_path29.default.join(import_node_os13.default.homedir(), ".pmate", "ios-builds");
19313
+ (0, import_node_fs24.mkdirSync)(root, { recursive: true, mode: 448 });
19314
+ const preflightLog = import_node_path29.default.join(root, `preflight-${process.pid}-${Date.now()}.log`);
19005
19315
  const run = this.deps.run ?? runXcode;
19006
19316
  await run(["-version"], appDir, preflightLog);
19007
19317
  const common2 = [expectedExtension === ".xcworkspace" ? "-workspace" : "-project", project, "-scheme", options.scheme, "-configuration", "Release", "-destination", "generic/platform=iOS"];
@@ -19016,19 +19326,19 @@ var IosBuildService = class {
19016
19326
  if (!bundleId || !/^\d+\.\d+(?:\.\d+)?$/.test(version ?? "") || !/^[A-Z0-9]{10}$/.test(team ?? "")) throw new Error("Missing or invalid bundle ID, MARKETING_VERSION or signing team; use --team if needed");
19017
19327
  if (service.mobile && "bundleId" in service.mobile && service.mobile.bundleId !== bundleId) throw new Error("Service bundle ID does not match application target");
19018
19328
  const currentBuild = iosBuildInteger(cfg.CURRENT_PROJECT_VERSION);
19019
- const key = (0, import_node_crypto6.createHash)("sha256").update(bundleId).digest("hex");
19020
- const statePath = import_node_path28.default.join(root, `${key}.json`);
19021
- const lockPath = import_node_path28.default.join(root, `${key}.lock`);
19329
+ const key = (0, import_node_crypto7.createHash)("sha256").update(bundleId).digest("hex");
19330
+ const statePath = import_node_path29.default.join(root, `${key}.json`);
19331
+ const lockPath = import_node_path29.default.join(root, `${key}.lock`);
19022
19332
  let lock;
19023
19333
  try {
19024
- lock = (0, import_node_fs23.openSync)(lockPath, "wx", 384);
19334
+ lock = (0, import_node_fs24.openSync)(lockPath, "wx", 384);
19025
19335
  } catch (error) {
19026
19336
  if (error.code === "EEXIST") throw new Error(`iOS build already locked: ${lockPath}. Remove only after confirming no build is running.`);
19027
19337
  throw error;
19028
19338
  }
19029
19339
  try {
19030
- (0, import_node_fs23.writeFileSync)(lock, JSON.stringify({ pid: process.pid, bundleId }));
19031
- const previous = (0, import_node_fs23.existsSync)(statePath) ? JSON.parse((0, import_node_fs23.readFileSync)(statePath, "utf8")) : void 0;
19340
+ (0, import_node_fs24.writeFileSync)(lock, JSON.stringify({ pid: process.pid, bundleId }));
19341
+ const previous = (0, import_node_fs24.existsSync)(statePath) ? JSON.parse((0, import_node_fs24.readFileSync)(statePath, "utf8")) : void 0;
19032
19342
  if (previous && previous.bundleId !== bundleId) throw new Error("iOS build state bundle ID mismatch");
19033
19343
  const buildsByVersion = { ...previous?.buildsByVersion };
19034
19344
  if (previous) buildsByVersion[previous.version] = Math.max(buildsByVersion[previous.version] ?? 0, iosBuildInteger(previous.build));
@@ -19036,52 +19346,52 @@ var IosBuildService = class {
19036
19346
  if (priorBuild === void 0 && options.lastBuild === void 0) throw new Error("First build for this marketing version requires --last-build <highest Apple build for this version>; use 0 only for a new version. Import again after external uploads or changing machines.");
19037
19347
  const build = Math.max(currentBuild, priorBuild ?? 0, options.lastBuild ?? 0) + 1;
19038
19348
  iosBuildInteger(build);
19039
- const buildDir = import_node_path28.default.join(root, key, `${version}-${build}`);
19040
- (0, import_node_fs23.mkdirSync)(buildDir, { recursive: true, mode: 448 });
19041
- const archivePath = import_node_path28.default.join(buildDir, "App.xcarchive");
19042
- const logPath = import_node_path28.default.join(buildDir, "build.log");
19349
+ const buildDir = import_node_path29.default.join(root, key, `${version}-${build}`);
19350
+ (0, import_node_fs24.mkdirSync)(buildDir, { recursive: true, mode: 448 });
19351
+ const archivePath = import_node_path29.default.join(buildDir, "App.xcarchive");
19352
+ const logPath = import_node_path29.default.join(buildDir, "build.log");
19043
19353
  buildsByVersion[version] = build;
19044
19354
  const state = { bundleId, version, build, buildsByVersion, status: "reserved", archivePath, logPath };
19045
19355
  const persist = () => {
19046
19356
  const temp = `${statePath}.${process.pid}.tmp`;
19047
- (0, import_node_fs23.writeFileSync)(temp, JSON.stringify(state, null, 2) + "\n", { mode: 384 });
19048
- (0, import_node_fs23.renameSync)(temp, statePath);
19357
+ (0, import_node_fs24.writeFileSync)(temp, JSON.stringify(state, null, 2) + "\n", { mode: 384 });
19358
+ (0, import_node_fs24.renameSync)(temp, statePath);
19049
19359
  };
19050
19360
  persist();
19051
- (0, import_node_fs23.writeFileSync)(logPath, `Service ${service.id}: ${bundleId} ${version} (${build})
19361
+ (0, import_node_fs24.writeFileSync)(logPath, `Service ${service.id}: ${bundleId} ${version} (${build})
19052
19362
  Preflight log: ${preflightLog}
19053
19363
  `, { mode: 384 });
19054
19364
  try {
19055
- await run([...common2, `CURRENT_PROJECT_VERSION=${build}`, `MARKETING_VERSION=${version}`, "-archivePath", archivePath, "-derivedDataPath", import_node_path28.default.join(buildDir, "DerivedData"), "-allowProvisioningUpdates", "archive"], appDir, logPath);
19056
- const applications = import_node_path28.default.join(archivePath, "Products", "Applications");
19057
- const builtApps = (0, import_node_fs23.readdirSync)(applications).filter((name) => name.endsWith(".app"));
19365
+ await run([...common2, `CURRENT_PROJECT_VERSION=${build}`, `MARKETING_VERSION=${version}`, "-archivePath", archivePath, "-derivedDataPath", import_node_path29.default.join(buildDir, "DerivedData"), "-allowProvisioningUpdates", "archive"], appDir, logPath);
19366
+ const applications = import_node_path29.default.join(archivePath, "Products", "Applications");
19367
+ const builtApps = (0, import_node_fs24.readdirSync)(applications).filter((name) => name.endsWith(".app"));
19058
19368
  if (builtApps.length !== 1) throw new Error("Archive must contain exactly one application");
19059
- const plist = (0, import_node_fs23.readFileSync)(import_node_path28.default.join(applications, builtApps[0], "Info.plist"));
19369
+ const plist = (0, import_node_fs24.readFileSync)(import_node_path29.default.join(applications, builtApps[0], "Info.plist"));
19060
19370
  const info = await (this.deps.readPlist ?? readPlist)(plist);
19061
19371
  if (info.CFBundleIdentifier !== bundleId || info.CFBundleShortVersionString !== version || String(info.CFBundleVersion) !== String(build)) throw new Error("Archive metadata does not match requested bundle, version and Build; upload stopped");
19062
- const exportPlist = import_node_path28.default.join(buildDir, "ExportOptions.plist");
19063
- (0, import_node_fs23.writeFileSync)(exportPlist, `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>method</key><string>app-store-connect</string><key>destination</key><string>upload</string><key>teamID</key><string>${team}</string><key>signingStyle</key><string>automatic</string><key>manageAppVersionAndBuildNumber</key><false/><key>uploadSymbols</key><true/></dict></plist>`);
19064
- await run(["-exportArchive", "-archivePath", archivePath, "-exportOptionsPlist", exportPlist, "-exportPath", import_node_path28.default.join(buildDir, "export"), "-allowProvisioningUpdates"], appDir, logPath);
19372
+ const exportPlist = import_node_path29.default.join(buildDir, "ExportOptions.plist");
19373
+ (0, import_node_fs24.writeFileSync)(exportPlist, `<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>method</key><string>app-store-connect</string><key>destination</key><string>upload</string><key>teamID</key><string>${team}</string><key>signingStyle</key><string>automatic</string><key>manageAppVersionAndBuildNumber</key><false/><key>uploadSymbols</key><true/></dict></plist>`);
19374
+ await run(["-exportArchive", "-archivePath", archivePath, "-exportOptionsPlist", exportPlist, "-exportPath", import_node_path29.default.join(buildDir, "export"), "-allowProvisioningUpdates"], appDir, logPath);
19065
19375
  state.status = "uploaded-processing";
19066
19376
  persist();
19067
19377
  return { serviceId: service.id, bundleId, version, build, status: "uploaded-processing", archivePath, logPath };
19068
19378
  } catch (error) {
19069
19379
  state.status = "failed";
19070
19380
  persist();
19071
- (0, import_node_fs23.appendFileSync)(logPath, `
19381
+ (0, import_node_fs24.appendFileSync)(logPath, `
19072
19382
  ${String(error)}
19073
19383
  `);
19074
19384
  throw new Error(`iOS Build ${build} failed; sequence reserved. See ${logPath}. ${String(error)}`);
19075
19385
  }
19076
19386
  } finally {
19077
- (0, import_node_fs23.closeSync)(lock);
19078
- (0, import_node_fs23.unlinkSync)(lockPath);
19387
+ (0, import_node_fs24.closeSync)(lock);
19388
+ (0, import_node_fs24.unlinkSync)(lockPath);
19079
19389
  }
19080
19390
  }
19081
19391
  };
19082
19392
  async function readPlist(input) {
19083
19393
  return new Promise((resolve, reject) => {
19084
- const child = (0, import_node_child_process11.spawn)("plutil", ["-convert", "json", "-o", "-", "--", "-"], { stdio: ["pipe", "pipe", "pipe"] });
19394
+ const child = (0, import_node_child_process12.spawn)("plutil", ["-convert", "json", "-o", "-", "--", "-"], { stdio: ["pipe", "pipe", "pipe"] });
19085
19395
  let output = "";
19086
19396
  let error = "";
19087
19397
  child.stdout.on("data", (chunk) => {
@@ -19122,15 +19432,19 @@ var NativeServiceDeploy = class {
19122
19432
  this.registry = registry;
19123
19433
  }
19124
19434
  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");
19435
+ if (!("type" in service) || !["electron", "ios", "android", "harmonyos"].includes(service.type)) throw new Error("Native deployment requires a supported native service");
19126
19436
  if (service.type !== "android" && (args.env ?? "prod") !== "prod") throw new Error("Native deployment currently supports only --env prod");
19127
19437
  const repository = service.repository ?? service.mobile?.repository;
19128
19438
  const dir = service.dir ?? service.mobile?.dir;
19129
19439
  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}`);
19440
+ const root = args.cwd ? import_node_path30.default.resolve(args.cwd) : resolveRepositoryLocalRoot(repository);
19441
+ const appDir = import_node_path30.default.resolve(root, dir);
19442
+ if (!(0, import_node_fs25.existsSync)(appDir)) throw new Error(`Service source directory not found: ${appDir}`);
19133
19443
  const settings = service.build ?? {};
19444
+ if (service.type === "harmonyos") {
19445
+ rejectNativeOverrides(args, ["dryRun", "local", "outDir"]);
19446
+ return (this.deps.harmony ?? new HarmonyReleaseService(this.registry)).release(service, { cwd: root, dryRun: args.dryRun, local: args.local, outDir: args.outDir });
19447
+ }
19134
19448
  if (service.type === "android") {
19135
19449
  rejectNativeOverrides(args, [...androidKeys, "dryRun"]);
19136
19450
  const artifactIdentity = androidArtifactIdentity(service);
@@ -19159,10 +19473,10 @@ var NativeServiceDeploy = class {
19159
19473
  const options2 = {
19160
19474
  id: app,
19161
19475
  target: "electron",
19162
- config: args.config ? import_node_path29.default.resolve(args.config) : import_node_path29.default.resolve(appDir, settings.config ?? "desktop.config.json"),
19476
+ config: args.config ? import_node_path30.default.resolve(args.config) : import_node_path30.default.resolve(appDir, settings.config ?? "desktop.config.json"),
19163
19477
  platform: args.platform ?? settings.platform ?? (process.platform === "darwin" ? "mac" : process.platform === "win32" ? "win" : process.platform),
19164
19478
  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),
19479
+ outDir: args.outDir ? import_node_path30.default.resolve(args.outDir) : import_node_path30.default.join(root, "release", service.name),
19166
19480
  signed: !args.unsigned,
19167
19481
  dir: !!args.dir,
19168
19482
  dryRun: !!args.dryRun,
@@ -19275,10 +19589,10 @@ async function requestDeveloperLogTool(tool, params, fetcher = fetch, delegate)
19275
19589
  }
19276
19590
 
19277
19591
  // src/services/ServiceRuntimeRunner.ts
19278
- var import_node_fs25 = require("fs");
19279
- var import_node_os13 = __toESM(require("os"));
19280
- var import_node_path30 = __toESM(require("path"));
19281
- var import_node_child_process12 = require("child_process");
19592
+ var import_node_fs26 = require("fs");
19593
+ var import_node_os14 = __toESM(require("os"));
19594
+ var import_node_path31 = __toESM(require("path"));
19595
+ var import_node_child_process13 = require("child_process");
19282
19596
  var import_node_readline = require("readline");
19283
19597
  var import_chalk3 = __toESM(require("chalk"));
19284
19598
  var import_dotenv = require("dotenv");
@@ -19298,8 +19612,8 @@ var ServiceEnvNotFoundError = class extends Error {
19298
19612
  }
19299
19613
  };
19300
19614
  var ServiceRegistryClient = class {
19301
- constructor(baseUrl) {
19302
- this.baseUrl = baseUrl;
19615
+ constructor(baseUrl2) {
19616
+ this.baseUrl = baseUrl2;
19303
19617
  }
19304
19618
  async listHostEnv(hostId) {
19305
19619
  const payload = await this.request(
@@ -19777,14 +20091,14 @@ var ServiceRuntimeRunner = class {
19777
20091
  }
19778
20092
  resolveRepoRoot(service, cwd) {
19779
20093
  if (cwd) {
19780
- return import_node_path30.default.resolve(process.cwd(), cwd);
20094
+ return import_node_path31.default.resolve(process.cwd(), cwd);
19781
20095
  }
19782
20096
  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();
19783
20097
  if (repository) {
19784
20098
  const repoName = repository.replace(/\/+$/, "").split("/").pop()?.replace(/\.git$/i, "");
19785
20099
  if (repoName) {
19786
- const candidate = import_node_path30.default.join(import_node_os13.default.homedir(), "dev", "pmate", repoName);
19787
- if ((0, import_node_fs25.existsSync)(candidate)) {
20100
+ const candidate = import_node_path31.default.join(import_node_os14.default.homedir(), "dev", "pmate", repoName);
20101
+ if ((0, import_node_fs26.existsSync)(candidate)) {
19788
20102
  return candidate;
19789
20103
  }
19790
20104
  }
@@ -19797,13 +20111,13 @@ var ServiceRuntimeRunner = class {
19797
20111
  if (!dir) {
19798
20112
  throw new Error(`Missing service dir for ${service.id}`);
19799
20113
  }
19800
- return import_node_path30.default.resolve(repoRoot, dir);
20114
+ return import_node_path31.default.resolve(repoRoot, dir);
19801
20115
  }
19802
20116
  async deployVite(service, options) {
19803
20117
  this.assertDeployableStaticSite(service);
19804
20118
  const appDir = this.resolveLocalDir(service, options.cwd);
19805
- const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
19806
- if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
20119
+ const packageJsonPath = import_node_path31.default.join(appDir, "package.json");
20120
+ if (!(0, import_node_fs26.existsSync)(packageJsonPath)) {
19807
20121
  throw new Error(`No package.json found at ${packageJsonPath}`);
19808
20122
  }
19809
20123
  const pkg2 = this.loadPackageJson(packageJsonPath);
@@ -19818,8 +20132,8 @@ var ServiceRuntimeRunner = class {
19818
20132
  this.resolveRepoRoot(service, options.cwd),
19819
20133
  buildEnv
19820
20134
  );
19821
- const distDir = import_node_path30.default.join(appDir, "dist");
19822
- if (!(0, import_node_fs25.existsSync)(distDir)) {
20135
+ const distDir = import_node_path31.default.join(appDir, "dist");
20136
+ if (!(0, import_node_fs26.existsSync)(distDir)) {
19823
20137
  throw new Error(`No dist directory found at ${distDir}`);
19824
20138
  }
19825
20139
  const site = this.getSite(service);
@@ -19832,8 +20146,8 @@ var ServiceRuntimeRunner = class {
19832
20146
  async deployStatic(service, options) {
19833
20147
  this.assertDeployableStaticSite(service);
19834
20148
  const appDir = this.resolveLocalDir(service, options.cwd);
19835
- const srcDir = import_node_path30.default.join(appDir, "src");
19836
- if (!(0, import_node_fs25.existsSync)(srcDir)) {
20149
+ const srcDir = import_node_path31.default.join(appDir, "src");
20150
+ if (!(0, import_node_fs26.existsSync)(srcDir)) {
19837
20151
  throw new Error(`No src directory found at ${srcDir}`);
19838
20152
  }
19839
20153
  const site = this.getSite(service);
@@ -19867,8 +20181,8 @@ var ServiceRuntimeRunner = class {
19867
20181
  this.validateFcConfig(service, fc);
19868
20182
  const repoRoot = this.resolveRepoRoot(service, options.cwd);
19869
20183
  const appDir = this.resolveLocalDir(service, options.cwd);
19870
- const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
19871
- if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
20184
+ const packageJsonPath = import_node_path31.default.join(appDir, "package.json");
20185
+ if (!(0, import_node_fs26.existsSync)(packageJsonPath)) {
19872
20186
  throw new Error(`No package.json found at ${packageJsonPath}`);
19873
20187
  }
19874
20188
  const pkg2 = this.loadPackageJson(packageJsonPath);
@@ -19921,15 +20235,15 @@ var ServiceRuntimeRunner = class {
19921
20235
  const repoRoot = this.resolveRepoRoot(service, options.cwd);
19922
20236
  const appDir = this.resolveLocalDir(service, options.cwd);
19923
20237
  await this.ensurePnpmWorkspaceRoot(repoRoot);
19924
- const configPath = import_node_path30.default.join(appDir, fc.configFile ?? "s.yaml");
19925
- if (!(0, import_node_fs25.existsSync)(configPath)) {
20238
+ const configPath = import_node_path31.default.join(appDir, fc.configFile ?? "s.yaml");
20239
+ if (!(0, import_node_fs26.existsSync)(configPath)) {
19926
20240
  throw new Error(`Missing FC config file at ${configPath}`);
19927
20241
  }
19928
- const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
19929
- if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
20242
+ const packageJsonPath = import_node_path31.default.join(appDir, "package.json");
20243
+ if (!(0, import_node_fs26.existsSync)(packageJsonPath)) {
19930
20244
  throw new Error(`No package.json found at ${packageJsonPath}`);
19931
20245
  }
19932
- const rawConfig = (0, import_node_fs25.readFileSync)(configPath, "utf8");
20246
+ const rawConfig = (0, import_node_fs26.readFileSync)(configPath, "utf8");
19933
20247
  if (!rawConfig.includes(fc.functionName)) {
19934
20248
  throw new Error(`FC config ${configPath} does not mention functionName ${fc.functionName}`);
19935
20249
  }
@@ -20219,7 +20533,7 @@ var ServiceRuntimeRunner = class {
20219
20533
  const serverAddress = await resolveServerAddress(server);
20220
20534
  const templateName = exposeType === "websocket" ? "nginx.ws.template" : exposeType === "mixed" ? "nginx.mixed.template" : "nginx.rest.template";
20221
20535
  const templatePath = this.resolveTemplatePath(templateName);
20222
- const template = (0, import_node_fs25.readFileSync)(templatePath, "utf8");
20536
+ const template = (0, import_node_fs26.readFileSync)(templatePath, "utf8");
20223
20537
  const host = `${subdomain}.${("domain" in network ? network.domain?.trim() : void 0) || "pmate.chat"}`;
20224
20538
  const rendered = template.replace(/\$\{\{PORT\}\}/g, String(port)).replace(/\$\{\{HOSTS\}\}/g, host).replace(/\$\{\{HOST\}\}/g, host);
20225
20539
  const remotePath = `/etc/nginx/sites-enabled/${subdomain}.conf`;
@@ -20251,11 +20565,11 @@ var ServiceRuntimeRunner = class {
20251
20565
  }
20252
20566
  if (config.ensurePackageJson) {
20253
20567
  const appDir = this.resolveLocalDir(service, options.cwd);
20254
- const packageJsonPath = import_node_path30.default.join(appDir, "package.json");
20255
- if (!(0, import_node_fs25.existsSync)(packageJsonPath)) {
20568
+ const packageJsonPath = import_node_path31.default.join(appDir, "package.json");
20569
+ if (!(0, import_node_fs26.existsSync)(packageJsonPath)) {
20256
20570
  throw new Error(`Missing package.json at ${packageJsonPath}`);
20257
20571
  }
20258
- const pkgStat = (0, import_node_fs25.statSync)(packageJsonPath);
20572
+ const pkgStat = (0, import_node_fs26.statSync)(packageJsonPath);
20259
20573
  if (!pkgStat.isFile()) {
20260
20574
  throw new Error(`package.json is not a file at ${packageJsonPath}`);
20261
20575
  }
@@ -20666,9 +20980,9 @@ var ServiceRuntimeRunner = class {
20666
20980
  return tokens;
20667
20981
  }
20668
20982
  readPathValue(source, pathExpr) {
20669
- const path35 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
20983
+ const path36 = pathExpr.split(".").map((segment) => segment.trim()).filter(Boolean);
20670
20984
  let cursor = source;
20671
- for (const segment of path35) {
20985
+ for (const segment of path36) {
20672
20986
  if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
20673
20987
  return void 0;
20674
20988
  }
@@ -20711,12 +21025,12 @@ var ServiceRuntimeRunner = class {
20711
21025
  }
20712
21026
  resolveTemplatePath(templateName) {
20713
21027
  const candidates = [
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)
21028
+ import_node_path31.default.join(__dirname, "..", "templates", templateName),
21029
+ import_node_path31.default.join(__dirname, "..", "src", "templates", templateName),
21030
+ import_node_path31.default.join(__dirname, "templates", templateName)
20717
21031
  ];
20718
21032
  for (const candidate of candidates) {
20719
- if ((0, import_node_fs25.existsSync)(candidate)) {
21033
+ if ((0, import_node_fs26.existsSync)(candidate)) {
20720
21034
  return candidate;
20721
21035
  }
20722
21036
  }
@@ -20725,7 +21039,7 @@ var ServiceRuntimeRunner = class {
20725
21039
  writeRemoteConfig(server, content, remotePath) {
20726
21040
  return new Promise((resolve, reject) => {
20727
21041
  const target = `pmate@${server}`;
20728
- const child = (0, import_node_child_process12.spawn)("ssh", [target, "sudo", "tee", remotePath], {
21042
+ const child = (0, import_node_child_process13.spawn)("ssh", [target, "sudo", "tee", remotePath], {
20729
21043
  stdio: ["pipe", "inherit", "inherit"]
20730
21044
  });
20731
21045
  child.on("error", reject);
@@ -20740,7 +21054,7 @@ var ServiceRuntimeRunner = class {
20740
21054
  reloadNginx(server) {
20741
21055
  return new Promise((resolve, reject) => {
20742
21056
  const target = `pmate@${server}`;
20743
- const child = (0, import_node_child_process12.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
21057
+ const child = (0, import_node_child_process13.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
20744
21058
  stdio: ["ignore", "inherit", "inherit"]
20745
21059
  });
20746
21060
  child.on("error", reject);
@@ -20748,7 +21062,7 @@ var ServiceRuntimeRunner = class {
20748
21062
  });
20749
21063
  }
20750
21064
  loadPackageJson(packageJsonPath) {
20751
- const raw = (0, import_node_fs25.readFileSync)(packageJsonPath, "utf8");
21065
+ const raw = (0, import_node_fs26.readFileSync)(packageJsonPath, "utf8");
20752
21066
  const parsed = JSON.parse(raw);
20753
21067
  if (!parsed || typeof parsed !== "object") {
20754
21068
  throw new Error(`Invalid package.json at ${packageJsonPath}`);
@@ -20757,7 +21071,7 @@ var ServiceRuntimeRunner = class {
20757
21071
  }
20758
21072
  writePackageJson(packageJsonPath, data) {
20759
21073
  const serialized = JSON.stringify(data, null, 2);
20760
- (0, import_node_fs25.writeFileSync)(packageJsonPath, `${serialized}
21074
+ (0, import_node_fs26.writeFileSync)(packageJsonPath, `${serialized}
20761
21075
  `, "utf8");
20762
21076
  }
20763
21077
  validateFcConfig(service, fc) {
@@ -20784,8 +21098,8 @@ var ServiceRuntimeRunner = class {
20784
21098
  }
20785
21099
  }
20786
21100
  async ensurePnpmWorkspaceRoot(repoRoot) {
20787
- const workspacePath = import_node_path30.default.join(repoRoot, "pnpm-workspace.yaml");
20788
- if (!(0, import_node_fs25.existsSync)(workspacePath)) {
21101
+ const workspacePath = import_node_path31.default.join(repoRoot, "pnpm-workspace.yaml");
21102
+ if (!(0, import_node_fs26.existsSync)(workspacePath)) {
20789
21103
  throw new Error(`Missing pnpm-workspace.yaml at ${workspacePath}`);
20790
21104
  }
20791
21105
  }
@@ -20859,16 +21173,16 @@ var ServiceRuntimeRunner = class {
20859
21173
  if (!privateKeyPath) {
20860
21174
  throw new Error("Missing ssl.prv in ~/.pmate/config.yaml.");
20861
21175
  }
20862
- if (!(0, import_node_fs25.existsSync)(certificatePath)) {
21176
+ if (!(0, import_node_fs26.existsSync)(certificatePath)) {
20863
21177
  throw new Error(`SSL certificate file not found: ${certificatePath}`);
20864
21178
  }
20865
- if (!(0, import_node_fs25.existsSync)(privateKeyPath)) {
21179
+ if (!(0, import_node_fs26.existsSync)(privateKeyPath)) {
20866
21180
  throw new Error(`SSL private key file not found: ${privateKeyPath}`);
20867
21181
  }
20868
21182
  return {
20869
21183
  certName: host,
20870
- certificate: (0, import_node_fs25.readFileSync)(certificatePath, "utf8"),
20871
- privateKey: (0, import_node_fs25.readFileSync)(privateKeyPath, "utf8")
21184
+ certificate: (0, import_node_fs26.readFileSync)(certificatePath, "utf8"),
21185
+ privateKey: (0, import_node_fs26.readFileSync)(privateKeyPath, "utf8")
20872
21186
  };
20873
21187
  }
20874
21188
  resolveFcProtocol(fc, certConfig) {
@@ -20927,7 +21241,7 @@ var ServiceRuntimeRunner = class {
20927
21241
  }
20928
21242
  runCommandWithEnv(command, args, cwd, env) {
20929
21243
  return new Promise((resolve, reject) => {
20930
- const child = (0, import_node_child_process12.spawn)(command, args, {
21244
+ const child = (0, import_node_child_process13.spawn)(command, args, {
20931
21245
  cwd,
20932
21246
  stdio: "inherit",
20933
21247
  env: { ...process.env, ...env ?? {} }
@@ -20938,7 +21252,7 @@ var ServiceRuntimeRunner = class {
20938
21252
  }
20939
21253
  runShellCommand(command, cwd, env) {
20940
21254
  return new Promise((resolve, reject) => {
20941
- const child = (0, import_node_child_process12.spawn)(command, [], {
21255
+ const child = (0, import_node_child_process13.spawn)(command, [], {
20942
21256
  cwd,
20943
21257
  stdio: "inherit",
20944
21258
  shell: true,
@@ -20949,10 +21263,10 @@ var ServiceRuntimeRunner = class {
20949
21263
  });
20950
21264
  }
20951
21265
  runRemoteCommand(server, command) {
20952
- if (server === "local") return this.runCommandWithEnv("bash", ["-c", command], import_node_os13.default.homedir());
21266
+ if (server === "local") return this.runCommandWithEnv("bash", ["-c", command], import_node_os14.default.homedir());
20953
21267
  return new Promise((resolve, reject) => {
20954
21268
  const target = `pmate@${server}`;
20955
- const child = (0, import_node_child_process12.spawn)("ssh", [target, "bash -ls"], { stdio: ["pipe", "inherit", "inherit"] });
21269
+ const child = (0, import_node_child_process13.spawn)("ssh", [target, "bash -ls"], { stdio: ["pipe", "inherit", "inherit"] });
20956
21270
  child.stdin.on("error", reject);
20957
21271
  child.stdin.end(`${command}
20958
21272
  `);
@@ -21012,8 +21326,8 @@ function parseServiceRef(serviceId) {
21012
21326
  init_namespacedRef();
21013
21327
  var ServiceCommandHandler = class {
21014
21328
  async handle(args) {
21015
- const baseUrl = this.resolveBaseUrl(args.baseUrl);
21016
- const registry = new ServiceRegistryClient(baseUrl);
21329
+ const baseUrl2 = this.resolveBaseUrl(args.baseUrl);
21330
+ const registry = new ServiceRegistryClient(baseUrl2);
21017
21331
  const runtime = new ServiceRuntimeRunner(
21018
21332
  (appId, options) => registry.pullEnv(appId, options)
21019
21333
  );
@@ -21059,10 +21373,10 @@ var ServiceCommandHandler = class {
21059
21373
  }
21060
21374
  case "create": {
21061
21375
  const payload = this.readJsonFile(args.filePath);
21062
- await this.requireNamespace(payload, baseUrl);
21376
+ await this.requireNamespace(payload, baseUrl2);
21063
21377
  await this.requireUniqueServerPort(payload, registry);
21064
21378
  const record = await this.request(
21065
- baseUrl,
21379
+ baseUrl2,
21066
21380
  "POST",
21067
21381
  "/services",
21068
21382
  payload
@@ -21078,7 +21392,7 @@ var ServiceCommandHandler = class {
21078
21392
  name: args.name
21079
21393
  });
21080
21394
  const record = await this.request(
21081
- baseUrl,
21395
+ baseUrl2,
21082
21396
  "PUT",
21083
21397
  `/services/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`,
21084
21398
  payload
@@ -21091,7 +21405,7 @@ var ServiceCommandHandler = class {
21091
21405
  const service = await registry.getService(args.namespace, args.name);
21092
21406
  await this.deleteServiceResources(service);
21093
21407
  const record = await this.request(
21094
- baseUrl,
21408
+ baseUrl2,
21095
21409
  "DELETE",
21096
21410
  `/services/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`
21097
21411
  );
@@ -21101,7 +21415,7 @@ var ServiceCommandHandler = class {
21101
21415
  }
21102
21416
  case "rename": {
21103
21417
  const record = await this.request(
21104
- baseUrl,
21418
+ baseUrl2,
21105
21419
  "POST",
21106
21420
  `/services/${encodeURIComponent(args.namespace)}/rename`,
21107
21421
  {
@@ -21117,7 +21431,7 @@ var ServiceCommandHandler = class {
21117
21431
  }
21118
21432
  case "move": {
21119
21433
  const record = await this.request(
21120
- baseUrl,
21434
+ baseUrl2,
21121
21435
  "POST",
21122
21436
  `/services/${encodeURIComponent(args.namespace)}/move`,
21123
21437
  {
@@ -21136,7 +21450,7 @@ var ServiceCommandHandler = class {
21136
21450
  const certKey = args.sslCert ?? DEFAULT_SSL_CERT_KEY;
21137
21451
  resolveSslCert(certKey);
21138
21452
  const record = await this.request(
21139
- baseUrl,
21453
+ baseUrl2,
21140
21454
  "PUT",
21141
21455
  `/services/${encodeURIComponent(args.namespace)}/${encodeURIComponent(args.name)}`,
21142
21456
  { sslCert: certKey }
@@ -21173,10 +21487,10 @@ var ServiceCommandHandler = class {
21173
21487
  }
21174
21488
  case "deploy": {
21175
21489
  const record = await registry.getService(args.namespace, args.name);
21176
- if ("type" in record && (record.type === "electron" || record.type === "ios" || record.type === "android")) {
21490
+ if ("type" in record && (record.type === "electron" || record.type === "ios" || record.type === "android" || record.type === "harmonyos")) {
21177
21491
  try {
21178
21492
  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));
21493
+ if (!args.dryRun && !args.local) await this.appendDeployHistory(registry, record.id, args.env ?? "prod", "success", String(result.status), typeof result.manifestUrl === "string" ? { manifestUrl: result.manifestUrl, platform: result.type, distribution: result.distribution } : void 0);
21180
21494
  this.renderJson(result, true);
21181
21495
  } catch (error) {
21182
21496
  if (!args.dryRun && !args.local) await this.appendDeployHistory(registry, record.id, args.env ?? "prod", "failed", error instanceof Error ? error.message : String(error));
@@ -21210,7 +21524,7 @@ var ServiceCommandHandler = class {
21210
21524
  case "init": {
21211
21525
  const record = await registry.getService(args.namespace, args.name);
21212
21526
  const withDefaultCert = await this.ensureDefaultSslCertForStaticService(
21213
- baseUrl,
21527
+ baseUrl2,
21214
21528
  record
21215
21529
  );
21216
21530
  const service = await this.materializeServiceEnv(registry, withDefaultCert, args.env);
@@ -21264,7 +21578,7 @@ var ServiceCommandHandler = class {
21264
21578
  }
21265
21579
  case "env-list": {
21266
21580
  const payload = await this.request(
21267
- baseUrl,
21581
+ baseUrl2,
21268
21582
  "GET",
21269
21583
  this.buildEnvPath(args.appId, {
21270
21584
  scope: args.scope,
@@ -21277,7 +21591,7 @@ var ServiceCommandHandler = class {
21277
21591
  }
21278
21592
  case "env-get": {
21279
21593
  const payload = await this.request(
21280
- baseUrl,
21594
+ baseUrl2,
21281
21595
  "GET",
21282
21596
  `${this.buildEnvBasePath(args.appId)}/${encodeURIComponent(args.key)}?${new URLSearchParams({
21283
21597
  scope: args.scope,
@@ -21290,7 +21604,7 @@ var ServiceCommandHandler = class {
21290
21604
  case "env-set": {
21291
21605
  const value = await this.resolveEnvValue(args);
21292
21606
  const payload = await this.request(
21293
- baseUrl,
21607
+ baseUrl2,
21294
21608
  "PUT",
21295
21609
  `${this.buildEnvBasePath(args.appId)}/${encodeURIComponent(args.key)}`,
21296
21610
  {
@@ -21306,7 +21620,7 @@ var ServiceCommandHandler = class {
21306
21620
  }
21307
21621
  case "env-unset": {
21308
21622
  const payload = await this.request(
21309
- baseUrl,
21623
+ baseUrl2,
21310
21624
  "DELETE",
21311
21625
  `${this.buildEnvBasePath(args.appId)}/${encodeURIComponent(args.key)}?${new URLSearchParams({
21312
21626
  scope: args.scope
@@ -21319,7 +21633,7 @@ var ServiceCommandHandler = class {
21319
21633
  }
21320
21634
  case "env-resolve": {
21321
21635
  const payload = await this.request(
21322
- baseUrl,
21636
+ baseUrl2,
21323
21637
  "POST",
21324
21638
  `${this.buildEnvBasePath(args.appId)}/resolve`,
21325
21639
  {
@@ -21333,7 +21647,7 @@ var ServiceCommandHandler = class {
21333
21647
  }
21334
21648
  case "env-pull": {
21335
21649
  const payload = await this.request(
21336
- baseUrl,
21650
+ baseUrl2,
21337
21651
  "POST",
21338
21652
  `${this.buildEnvBasePath(args.appId)}/pull`,
21339
21653
  {
@@ -21342,7 +21656,7 @@ var ServiceCommandHandler = class {
21342
21656
  format: "dotenv"
21343
21657
  }
21344
21658
  );
21345
- const outputPath = import_node_path31.default.resolve(process.cwd(), args.output);
21659
+ const outputPath = import_node_path32.default.resolve(process.cwd(), args.output);
21346
21660
  await (0, import_promises5.writeFile)(outputPath, payload.content, "utf8");
21347
21661
  ui.success(`Wrote env file for ${args.appId} to ${outputPath}`);
21348
21662
  this.renderJson({ ...payload, output: outputPath }, args.json);
@@ -21350,7 +21664,7 @@ var ServiceCommandHandler = class {
21350
21664
  }
21351
21665
  case "env-copy-from": {
21352
21666
  const payload = await this.request(
21353
- baseUrl,
21667
+ baseUrl2,
21354
21668
  "POST",
21355
21669
  `${this.buildEnvBasePath(args.targetAppId)}/copy-from`,
21356
21670
  {
@@ -21367,7 +21681,7 @@ var ServiceCommandHandler = class {
21367
21681
  }
21368
21682
  case "env-update-scope": {
21369
21683
  const payload = await this.request(
21370
- baseUrl,
21684
+ baseUrl2,
21371
21685
  "POST",
21372
21686
  `${this.buildEnvBasePath(args.appId)}/update-scope`,
21373
21687
  {
@@ -21384,7 +21698,7 @@ var ServiceCommandHandler = class {
21384
21698
  }
21385
21699
  case "service-env-list": {
21386
21700
  const payload = await this.request(
21387
- baseUrl,
21701
+ baseUrl2,
21388
21702
  "GET",
21389
21703
  this.buildServiceEnvBasePath(args.appId)
21390
21704
  );
@@ -21393,7 +21707,7 @@ var ServiceCommandHandler = class {
21393
21707
  }
21394
21708
  case "service-env-get": {
21395
21709
  const payload = await this.request(
21396
- baseUrl,
21710
+ baseUrl2,
21397
21711
  "GET",
21398
21712
  `${this.buildServiceEnvBasePath(args.appId)}/${encodeURIComponent(args.envName)}`
21399
21713
  );
@@ -21402,7 +21716,7 @@ var ServiceCommandHandler = class {
21402
21716
  }
21403
21717
  case "service-env-add": {
21404
21718
  const payload = await this.request(
21405
- baseUrl,
21719
+ baseUrl2,
21406
21720
  "PUT",
21407
21721
  `${this.buildServiceEnvBasePath(args.appId)}/${encodeURIComponent(args.envName)}`,
21408
21722
  {
@@ -21415,7 +21729,7 @@ var ServiceCommandHandler = class {
21415
21729
  }
21416
21730
  case "service-env-expose": {
21417
21731
  const payload = await this.request(
21418
- baseUrl,
21732
+ baseUrl2,
21419
21733
  "POST",
21420
21734
  `${this.buildServiceEnvBasePath(args.appId)}/${encodeURIComponent(args.envName)}/expose`,
21421
21735
  {
@@ -21537,14 +21851,15 @@ var ServiceCommandHandler = class {
21537
21851
  }
21538
21852
  throw new Error(`Unsupported runtime ${runtime.type} for ${service.id} env ${env.name}`);
21539
21853
  }
21540
- async appendDeployHistory(registry, serviceId, environment, status, message) {
21854
+ async appendDeployHistory(registry, serviceId, environment, status, message, metadata) {
21541
21855
  let lastError;
21542
21856
  for (let attempt = 1; attempt <= 5; attempt += 1) {
21543
21857
  try {
21544
21858
  await registry.appendDeployHistory(serviceId, {
21545
21859
  environment,
21546
21860
  status,
21547
- ...message ? { message } : {}
21861
+ ...message ? { message } : {},
21862
+ ...metadata ? { metadata } : {}
21548
21863
  });
21549
21864
  return;
21550
21865
  } catch (error2) {
@@ -21564,15 +21879,15 @@ var ServiceCommandHandler = class {
21564
21879
  message: error instanceof Error ? error.message : String(error)
21565
21880
  });
21566
21881
  }
21567
- resolveBaseUrl(baseUrl) {
21568
- return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
21882
+ resolveBaseUrl(baseUrl2) {
21883
+ return (baseUrl2 || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
21569
21884
  }
21570
21885
  readJsonFile(filePath) {
21571
- const absolutePath = import_node_path31.default.resolve(process.cwd(), filePath);
21572
- if (!(0, import_node_fs26.existsSync)(absolutePath)) {
21886
+ const absolutePath = import_node_path32.default.resolve(process.cwd(), filePath);
21887
+ if (!(0, import_node_fs27.existsSync)(absolutePath)) {
21573
21888
  throw new Error(`JSON file not found: ${absolutePath}`);
21574
21889
  }
21575
- const raw = (0, import_node_fs26.readFileSync)(absolutePath, "utf8");
21890
+ const raw = (0, import_node_fs27.readFileSync)(absolutePath, "utf8");
21576
21891
  try {
21577
21892
  return JSON.parse(raw);
21578
21893
  } catch (error) {
@@ -21580,9 +21895,9 @@ var ServiceCommandHandler = class {
21580
21895
  throw new Error(`Invalid JSON in ${absolutePath}: ${message}`);
21581
21896
  }
21582
21897
  }
21583
- async request(baseUrl, method, pathname, body) {
21584
- const token = new ServiceRegistryClient(baseUrl).readToken();
21585
- const response = await fetch(`${baseUrl}${pathname}`, {
21898
+ async request(baseUrl2, method, pathname, body) {
21899
+ const token = new ServiceRegistryClient(baseUrl2).readToken();
21900
+ const response = await fetch(`${baseUrl2}${pathname}`, {
21586
21901
  method,
21587
21902
  headers: {
21588
21903
  Authorization: `Bearer ${token}`,
@@ -21642,7 +21957,7 @@ var ServiceCommandHandler = class {
21642
21957
  rl.close();
21643
21958
  }
21644
21959
  }
21645
- async requireNamespace(payload, baseUrl) {
21960
+ async requireNamespace(payload, baseUrl2) {
21646
21961
  if (!payload || typeof payload !== "object") {
21647
21962
  throw new Error("Service payload must be a JSON object.");
21648
21963
  }
@@ -21652,7 +21967,7 @@ var ServiceCommandHandler = class {
21652
21967
  }
21653
21968
  const registry = new NamespaceRegistry({
21654
21969
  chain: "pmate",
21655
- registryBaseUrl: baseUrl
21970
+ registryBaseUrl: baseUrl2
21656
21971
  });
21657
21972
  const exists = await registry.exists(namespace);
21658
21973
  if (!exists) {
@@ -22052,13 +22367,13 @@ var ServiceCommandHandler = class {
22052
22367
  }
22053
22368
  return [...domains].sort();
22054
22369
  }
22055
- async ensureDefaultSslCertForStaticService(baseUrl, service) {
22370
+ async ensureDefaultSslCertForStaticService(baseUrl2, service) {
22056
22371
  const type = this.getServiceType(service);
22057
22372
  if (type !== "vite" && type !== "static" || service.sslCert) {
22058
22373
  return service;
22059
22374
  }
22060
22375
  const record = await this.request(
22061
- baseUrl,
22376
+ baseUrl2,
22062
22377
  "PUT",
22063
22378
  `/services/${encodeURIComponent(service.namespace)}/${encodeURIComponent(service.name)}`,
22064
22379
  { sslCert: DEFAULT_SSL_CERT_KEY }
@@ -22096,7 +22411,7 @@ var ServiceCommandHandler = class {
22096
22411
  removeRemoteConfig(server, remotePath) {
22097
22412
  return new Promise((resolve, reject) => {
22098
22413
  const target = `pmate@${server}`;
22099
- const child = (0, import_node_child_process13.spawn)("ssh", [target, "sudo", "rm", "-f", remotePath], {
22414
+ const child = (0, import_node_child_process14.spawn)("ssh", [target, "sudo", "rm", "-f", remotePath], {
22100
22415
  stdio: ["ignore", "inherit", "inherit"]
22101
22416
  });
22102
22417
  child.on("error", (error) => {
@@ -22114,7 +22429,7 @@ var ServiceCommandHandler = class {
22114
22429
  reloadNginx(server) {
22115
22430
  return new Promise((resolve, reject) => {
22116
22431
  const target = `pmate@${server}`;
22117
- const child = (0, import_node_child_process13.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
22432
+ const child = (0, import_node_child_process14.spawn)("ssh", [target, "sudo", "nginx", "-s", "reload"], {
22118
22433
  stdio: ["ignore", "inherit", "inherit"]
22119
22434
  });
22120
22435
  child.on("error", (error) => {
@@ -22187,9 +22502,9 @@ function sleep3(ms) {
22187
22502
  }
22188
22503
 
22189
22504
  // src/commands/VercelCommandHandler.ts
22190
- var import_node_child_process14 = require("child_process");
22505
+ var import_node_child_process15 = require("child_process");
22191
22506
  var import_node_util = require("util");
22192
- var execFileAsync = (0, import_node_util.promisify)(import_node_child_process14.execFile);
22507
+ var execFileAsync = (0, import_node_util.promisify)(import_node_child_process15.execFile);
22193
22508
  function parseDeploymentTimestamp(deployment) {
22194
22509
  const candidates = [deployment.createdAt, deployment.readyAt, deployment.ready];
22195
22510
  for (const value of candidates) {
@@ -22297,11 +22612,11 @@ init_sessionStore();
22297
22612
  var RoleCommandHandler = class {
22298
22613
  async handle(args) {
22299
22614
  const token = this.readToken();
22300
- const baseUrl = this.resolveBaseUrl(args.baseUrl);
22615
+ const baseUrl2 = this.resolveBaseUrl(args.baseUrl);
22301
22616
  switch (args.action) {
22302
22617
  case "list": {
22303
22618
  const items = await this.request(
22304
- baseUrl,
22619
+ baseUrl2,
22305
22620
  token,
22306
22621
  "GET",
22307
22622
  "/role/definitions"
@@ -22311,7 +22626,7 @@ var RoleCommandHandler = class {
22311
22626
  }
22312
22627
  case "create": {
22313
22628
  const item = await this.request(
22314
- baseUrl,
22629
+ baseUrl2,
22315
22630
  token,
22316
22631
  "POST",
22317
22632
  "/role/definitions",
@@ -22327,16 +22642,16 @@ var RoleCommandHandler = class {
22327
22642
  }
22328
22643
  }
22329
22644
  }
22330
- resolveBaseUrl(baseUrl) {
22331
- return (baseUrl || process.env.PMATE_AUTH_API_BASE_URL || process.env.AUTH_API_BASE_URL || "https://auth-api-v2.pmate.chat").replace(/\/+$/, "");
22645
+ resolveBaseUrl(baseUrl2) {
22646
+ return (baseUrl2 || process.env.PMATE_AUTH_API_BASE_URL || process.env.AUTH_API_BASE_URL || "https://auth-api-v2.pmate.chat").replace(/\/+$/, "");
22332
22647
  }
22333
22648
  readToken() {
22334
22649
  return readRequiredSession({
22335
22650
  preferredApp: DEFAULT_APP_ID
22336
22651
  }).token;
22337
22652
  }
22338
- async request(baseUrl, token, method, pathname, body) {
22339
- const response = await fetch(`${baseUrl}${pathname}`, {
22653
+ async request(baseUrl2, token, method, pathname, body) {
22654
+ const response = await fetch(`${baseUrl2}${pathname}`, {
22340
22655
  method,
22341
22656
  headers: {
22342
22657
  Authorization: `Bearer ${token}`,
@@ -22380,9 +22695,9 @@ var RoleCommandHandler = class {
22380
22695
  };
22381
22696
 
22382
22697
  // src/commands/AccountCommandHandler.ts
22383
- var import_node_fs27 = require("fs");
22384
- var import_node_crypto7 = require("crypto");
22385
- var import_node_path32 = __toESM(require("path"));
22698
+ var import_node_fs28 = require("fs");
22699
+ var import_node_crypto8 = require("crypto");
22700
+ var import_node_path33 = __toESM(require("path"));
22386
22701
  init_sessionStore();
22387
22702
  var AccountCommandHandler = class {
22388
22703
  async handle(args) {
@@ -22390,9 +22705,9 @@ var AccountCommandHandler = class {
22390
22705
  case "bot-keygen": {
22391
22706
  const keyFile = this.generateBotKeyFile(args.app, args.name);
22392
22707
  const outPath = args.out ? this.resolveFilePath(args.out) : this.resolveDefaultBotKeyPath(args.app, args.name);
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);
22708
+ (0, import_node_fs28.mkdirSync)(import_node_path33.default.dirname(outPath), { recursive: true });
22709
+ (0, import_node_fs28.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
22710
+ (0, import_node_fs28.chmodSync)(outPath, 384);
22396
22711
  if (!args.json) {
22397
22712
  ui.success(`Bot key saved to ${outPath}`);
22398
22713
  }
@@ -22403,9 +22718,9 @@ var AccountCommandHandler = class {
22403
22718
  }
22404
22719
  case "list": {
22405
22720
  const token = this.readToken();
22406
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22721
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22407
22722
  const result = await this.request(
22408
- baseUrl,
22723
+ baseUrl2,
22409
22724
  token,
22410
22725
  "GET",
22411
22726
  `/accounts?${this.buildAccountListQuery(args)}`
@@ -22415,9 +22730,9 @@ var AccountCommandHandler = class {
22415
22730
  }
22416
22731
  case "app-users": {
22417
22732
  const token = this.readToken();
22418
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22733
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22419
22734
  const result = await this.request(
22420
- baseUrl,
22735
+ baseUrl2,
22421
22736
  token,
22422
22737
  "GET",
22423
22738
  `/accounts/app-users/${encodeURIComponent(args.app)}?${this.buildPagedQuery(args)}`
@@ -22427,9 +22742,9 @@ var AccountCommandHandler = class {
22427
22742
  }
22428
22743
  case "view": {
22429
22744
  const token = this.readToken();
22430
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22745
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22431
22746
  const result = await this.request(
22432
- baseUrl,
22747
+ baseUrl2,
22433
22748
  token,
22434
22749
  "GET",
22435
22750
  `/accounts/view?${this.buildAccountViewQuery(args)}`
@@ -22439,9 +22754,9 @@ var AccountCommandHandler = class {
22439
22754
  }
22440
22755
  case "role-list": {
22441
22756
  const token = this.readToken();
22442
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22757
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22443
22758
  const items = await this.request(
22444
- baseUrl,
22759
+ baseUrl2,
22445
22760
  token,
22446
22761
  "GET",
22447
22762
  `/role/bindings?${this.buildRoleBindingsQuery(args)}`
@@ -22451,9 +22766,9 @@ var AccountCommandHandler = class {
22451
22766
  }
22452
22767
  case "role-add": {
22453
22768
  const token = this.readToken();
22454
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22769
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22455
22770
  const item = await this.request(
22456
- baseUrl,
22771
+ baseUrl2,
22457
22772
  token,
22458
22773
  "POST",
22459
22774
  "/role/bindings",
@@ -22469,9 +22784,9 @@ var AccountCommandHandler = class {
22469
22784
  }
22470
22785
  case "role-remove": {
22471
22786
  const token = this.readToken();
22472
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22787
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22473
22788
  await this.request(
22474
- baseUrl,
22789
+ baseUrl2,
22475
22790
  token,
22476
22791
  "DELETE",
22477
22792
  "/role/bindings",
@@ -22486,9 +22801,9 @@ var AccountCommandHandler = class {
22486
22801
  }
22487
22802
  case "visible-app-list": {
22488
22803
  const token = this.readToken();
22489
- const baseUrl = this.resolveAppsBaseUrl(args.baseUrl);
22804
+ const baseUrl2 = this.resolveAppsBaseUrl(args.baseUrl);
22490
22805
  const result = await this.request(
22491
- baseUrl,
22806
+ baseUrl2,
22492
22807
  token,
22493
22808
  "GET",
22494
22809
  `/accounts/${encodeURIComponent(args.account)}/visible-apps`
@@ -22498,9 +22813,9 @@ var AccountCommandHandler = class {
22498
22813
  }
22499
22814
  case "visible-app-add": {
22500
22815
  const token = this.readToken();
22501
- const baseUrl = this.resolveAppsBaseUrl(args.baseUrl);
22816
+ const baseUrl2 = this.resolveAppsBaseUrl(args.baseUrl);
22502
22817
  const item = await this.request(
22503
- baseUrl,
22818
+ baseUrl2,
22504
22819
  token,
22505
22820
  "PUT",
22506
22821
  `/accounts/${encodeURIComponent(args.account)}/visible-apps/${encodePathSegment2(args.app)}`
@@ -22511,9 +22826,9 @@ var AccountCommandHandler = class {
22511
22826
  }
22512
22827
  case "visible-app-remove": {
22513
22828
  const token = this.readToken();
22514
- const baseUrl = this.resolveAppsBaseUrl(args.baseUrl);
22829
+ const baseUrl2 = this.resolveAppsBaseUrl(args.baseUrl);
22515
22830
  const result = await this.request(
22516
- baseUrl,
22831
+ baseUrl2,
22517
22832
  token,
22518
22833
  "DELETE",
22519
22834
  `/accounts/${encodeURIComponent(args.account)}/visible-apps/${encodePathSegment2(args.app)}`
@@ -22526,10 +22841,10 @@ var AccountCommandHandler = class {
22526
22841
  }
22527
22842
  case "visible-app-set": {
22528
22843
  const token = this.readToken();
22529
- const baseUrl = this.resolveAppsBaseUrl(args.baseUrl);
22844
+ const baseUrl2 = this.resolveAppsBaseUrl(args.baseUrl);
22530
22845
  const items = this.resolveVisibleAppsInput(args);
22531
22846
  const result = await this.request(
22532
- baseUrl,
22847
+ baseUrl2,
22533
22848
  token,
22534
22849
  "PUT",
22535
22850
  `/accounts/${encodeURIComponent(args.account)}/visible-apps`,
@@ -22541,9 +22856,9 @@ var AccountCommandHandler = class {
22541
22856
  }
22542
22857
  case "visible-app-resolve": {
22543
22858
  const token = this.readToken();
22544
- const baseUrl = this.resolveAppsBaseUrl(args.baseUrl);
22859
+ const baseUrl2 = this.resolveAppsBaseUrl(args.baseUrl);
22545
22860
  const result = await this.request(
22546
- baseUrl,
22861
+ baseUrl2,
22547
22862
  token,
22548
22863
  "GET",
22549
22864
  "/me/visible-apps"
@@ -22556,10 +22871,10 @@ var AccountCommandHandler = class {
22556
22871
  }
22557
22872
  case "bot-create": {
22558
22873
  const token = this.readToken();
22559
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22874
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22560
22875
  const publicKey = args.publicKey ?? this.readBotKeyFile(args.keyFile, args.app, args.name).publicKey;
22561
22876
  const bot = await this.request(
22562
- baseUrl,
22877
+ baseUrl2,
22563
22878
  token,
22564
22879
  "POST",
22565
22880
  "/accounts/bots",
@@ -22577,9 +22892,9 @@ var AccountCommandHandler = class {
22577
22892
  return;
22578
22893
  }
22579
22894
  case "bot-view": {
22580
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22895
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22581
22896
  const bot = await this.request(
22582
- baseUrl,
22897
+ baseUrl2,
22583
22898
  void 0,
22584
22899
  "GET",
22585
22900
  `/accounts/bots/${encodeURIComponent(args.app)}/${encodeURIComponent(args.name)}`
@@ -22588,9 +22903,9 @@ var AccountCommandHandler = class {
22588
22903
  return;
22589
22904
  }
22590
22905
  case "bot-list": {
22591
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22906
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22592
22907
  const result = await this.request(
22593
- baseUrl,
22908
+ baseUrl2,
22594
22909
  void 0,
22595
22910
  "GET",
22596
22911
  `/accounts/bots?app=${encodeURIComponent(args.app)}`
@@ -22610,9 +22925,9 @@ var AccountCommandHandler = class {
22610
22925
  }
22611
22926
  case "bot-rename": {
22612
22927
  const token = this.readToken();
22613
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22928
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22614
22929
  const bot = await this.request(
22615
- baseUrl,
22930
+ baseUrl2,
22616
22931
  token,
22617
22932
  "POST",
22618
22933
  "/accounts/bots/rename",
@@ -22633,17 +22948,17 @@ var AccountCommandHandler = class {
22633
22948
  return;
22634
22949
  }
22635
22950
  case "bot-login": {
22636
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22951
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22637
22952
  const privateKey = args.privateKey ?? this.readBotKeyFile(args.keyFile, args.app, args.name).privateKey;
22638
22953
  const challenge = await this.request(
22639
- baseUrl,
22954
+ baseUrl2,
22640
22955
  void 0,
22641
22956
  "POST",
22642
22957
  "/accounts/bots/session/challenge",
22643
22958
  { app: args.app, name: args.name }
22644
22959
  );
22645
22960
  const login = await this.request(
22646
- baseUrl,
22961
+ baseUrl2,
22647
22962
  void 0,
22648
22963
  "POST",
22649
22964
  "/accounts/bots/session",
@@ -22660,7 +22975,7 @@ var AccountCommandHandler = class {
22660
22975
  token: login.token,
22661
22976
  app: args.app,
22662
22977
  accountId: login.session.identity.accountId,
22663
- authApiBaseUrl: baseUrl
22978
+ authApiBaseUrl: baseUrl2
22664
22979
  });
22665
22980
  const saved = saveLoginSession({ ...login, profileId }, args.app);
22666
22981
  if (!args.json) {
@@ -22671,9 +22986,9 @@ var AccountCommandHandler = class {
22671
22986
  }
22672
22987
  case "bot-profile-create": {
22673
22988
  const token = this.readToken();
22674
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
22989
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22675
22990
  const profile = await this.request(
22676
- baseUrl,
22991
+ baseUrl2,
22677
22992
  token,
22678
22993
  "POST",
22679
22994
  "/accounts/bots/profile",
@@ -22692,9 +23007,9 @@ var AccountCommandHandler = class {
22692
23007
  }
22693
23008
  case "access-key-create": {
22694
23009
  const token = this.readToken();
22695
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
23010
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22696
23011
  const result = await this.request(
22697
- baseUrl,
23012
+ baseUrl2,
22698
23013
  token,
22699
23014
  "POST",
22700
23015
  "/access-keys",
@@ -22711,9 +23026,9 @@ var AccountCommandHandler = class {
22711
23026
  }
22712
23027
  case "access-key-list": {
22713
23028
  const token = this.readToken();
22714
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
23029
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22715
23030
  const result = await this.request(
22716
- baseUrl,
23031
+ baseUrl2,
22717
23032
  token,
22718
23033
  "GET",
22719
23034
  `/access-keys?${this.buildAccessKeyListQuery(args)}`
@@ -22723,9 +23038,9 @@ var AccountCommandHandler = class {
22723
23038
  }
22724
23039
  case "access-key-disable": {
22725
23040
  const token = this.readToken();
22726
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
23041
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22727
23042
  const item = await this.request(
22728
- baseUrl,
23043
+ baseUrl2,
22729
23044
  token,
22730
23045
  "DELETE",
22731
23046
  `/access-keys/${encodeURIComponent(args.id)}`
@@ -22738,9 +23053,9 @@ var AccountCommandHandler = class {
22738
23053
  }
22739
23054
  case "access-key-rotate": {
22740
23055
  const token = this.readToken();
22741
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
23056
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22742
23057
  const result = await this.request(
22743
- baseUrl,
23058
+ baseUrl2,
22744
23059
  token,
22745
23060
  "POST",
22746
23061
  `/access-keys/${encodeURIComponent(args.id)}/rotate`,
@@ -22754,16 +23069,16 @@ var AccountCommandHandler = class {
22754
23069
  return;
22755
23070
  }
22756
23071
  case "access-key-login": {
22757
- const baseUrl = this.resolveAuthBaseUrl(args.baseUrl);
23072
+ const baseUrl2 = this.resolveAuthBaseUrl(args.baseUrl);
22758
23073
  const secret = args.key ?? this.readAccessKeyFile(args.keyFile, args.app).secret;
22759
23074
  const login = await this.request(
22760
- baseUrl,
23075
+ baseUrl2,
22761
23076
  secret,
22762
23077
  "POST",
22763
23078
  "/access-keys/session",
22764
23079
  { app: args.app }
22765
23080
  );
22766
- const profileId = await this.resolveLoginProfileId(login, args.app, baseUrl);
23081
+ const profileId = await this.resolveLoginProfileId(login, args.app, baseUrl2);
22767
23082
  const saved = saveLoginSession({ ...login, profileId }, args.app);
22768
23083
  if (!args.json) {
22769
23084
  ui.success(`Logged in access key ${login.session.identity.accessKeyId ?? "unknown"} to ${saved.app}`);
@@ -22773,11 +23088,11 @@ var AccountCommandHandler = class {
22773
23088
  }
22774
23089
  }
22775
23090
  }
22776
- resolveAuthBaseUrl(baseUrl) {
22777
- return (baseUrl || process.env.PMATE_AUTH_API_BASE_URL || process.env.AUTH_API_BASE_URL || "https://auth-api-v2.pmate.chat").replace(/\/+$/, "");
23091
+ resolveAuthBaseUrl(baseUrl2) {
23092
+ return (baseUrl2 || process.env.PMATE_AUTH_API_BASE_URL || process.env.AUTH_API_BASE_URL || "https://auth-api-v2.pmate.chat").replace(/\/+$/, "");
22778
23093
  }
22779
- resolveAppsBaseUrl(baseUrl) {
22780
- return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
23094
+ resolveAppsBaseUrl(baseUrl2) {
23095
+ return (baseUrl2 || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
22781
23096
  }
22782
23097
  readToken() {
22783
23098
  return readRequiredSession({
@@ -22817,8 +23132,8 @@ var AccountCommandHandler = class {
22817
23132
  if (args.namespace) params.set("namespace", args.namespace);
22818
23133
  return params.toString();
22819
23134
  }
22820
- async request(baseUrl, token, method, pathname, body) {
22821
- const response = await fetch(`${baseUrl}${pathname}`, {
23135
+ async request(baseUrl2, token, method, pathname, body) {
23136
+ const response = await fetch(`${baseUrl2}${pathname}`, {
22822
23137
  method,
22823
23138
  headers: {
22824
23139
  ...token ? { Authorization: `Bearer ${token}` } : {},
@@ -22952,10 +23267,10 @@ var AccountCommandHandler = class {
22952
23267
  throw new Error("Missing visible apps input");
22953
23268
  }
22954
23269
  const absolutePath = this.resolveFilePath(args.filePath);
22955
- if (!(0, import_node_fs27.existsSync)(absolutePath)) {
23270
+ if (!(0, import_node_fs28.existsSync)(absolutePath)) {
22956
23271
  throw new Error(`JSON file not found: ${absolutePath}`);
22957
23272
  }
22958
- const raw = (0, import_node_fs27.readFileSync)(absolutePath, "utf8");
23273
+ const raw = (0, import_node_fs28.readFileSync)(absolutePath, "utf8");
22959
23274
  let parsed;
22960
23275
  try {
22961
23276
  parsed = JSON.parse(raw);
@@ -22969,19 +23284,19 @@ var AccountCommandHandler = class {
22969
23284
  return parsed;
22970
23285
  }
22971
23286
  resolveFilePath(filePath) {
22972
- return import_node_path32.default.resolve(process.cwd(), filePath);
23287
+ return import_node_path33.default.resolve(process.cwd(), filePath);
22973
23288
  }
22974
23289
  resolveDefaultBotKeyPath(app, name) {
22975
- return import_node_path32.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
23290
+ return import_node_path33.default.join(this.homeDir(), ".pmate", "bots", app, `${name}.bot-key.json`);
22976
23291
  }
22977
23292
  resolveDefaultAccessKeyPath(app, name) {
22978
- return import_node_path32.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
23293
+ return import_node_path33.default.join(this.homeDir(), ".pmate", "access-keys", app, `${name}.access-key.json`);
22979
23294
  }
22980
23295
  homeDir() {
22981
23296
  return process.env.HOME || process.env.USERPROFILE || process.cwd();
22982
23297
  }
22983
23298
  generateBotKeyFile(app, name) {
22984
- const { publicKey, privateKey } = (0, import_node_crypto7.generateKeyPairSync)("ed25519");
23299
+ const { publicKey, privateKey } = (0, import_node_crypto8.generateKeyPairSync)("ed25519");
22985
23300
  return {
22986
23301
  type: "pmate-bot-key",
22987
23302
  version: 1,
@@ -22995,14 +23310,14 @@ var AccountCommandHandler = class {
22995
23310
  }
22996
23311
  renameDefaultBotKeyFile(app, name, newName) {
22997
23312
  const oldPath = this.resolveDefaultBotKeyPath(app, name);
22998
- if (!(0, import_node_fs27.existsSync)(oldPath)) {
23313
+ if (!(0, import_node_fs28.existsSync)(oldPath)) {
22999
23314
  return void 0;
23000
23315
  }
23001
23316
  const keyFile = this.readBotKeyFile(oldPath, app, name);
23002
23317
  const newPath = this.resolveDefaultBotKeyPath(app, newName);
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);
23318
+ (0, import_node_fs28.mkdirSync)(import_node_path33.default.dirname(newPath), { recursive: true, mode: 448 });
23319
+ (0, import_node_fs28.writeFileSync)(newPath, JSON.stringify({ ...keyFile, name: newName }, null, 2));
23320
+ (0, import_node_fs28.chmodSync)(newPath, 384);
23006
23321
  return newPath;
23007
23322
  }
23008
23323
  readBotKeyFile(filePath, expectedApp, expectedName) {
@@ -23010,10 +23325,10 @@ var AccountCommandHandler = class {
23010
23325
  throw new Error("Missing bot key file");
23011
23326
  }
23012
23327
  const absolutePath = this.resolveFilePath(filePath);
23013
- if (!(0, import_node_fs27.existsSync)(absolutePath)) {
23328
+ if (!(0, import_node_fs28.existsSync)(absolutePath)) {
23014
23329
  throw new Error(`Bot key file not found: ${absolutePath}`);
23015
23330
  }
23016
- const parsed = JSON.parse((0, import_node_fs27.readFileSync)(absolutePath, "utf8"));
23331
+ const parsed = JSON.parse((0, import_node_fs28.readFileSync)(absolutePath, "utf8"));
23017
23332
  if (parsed.type !== "pmate-bot-key" || parsed.version !== 1 || parsed.algorithm !== "ed25519" || !parsed.publicKey || !parsed.privateKey) {
23018
23333
  throw new Error(`Invalid PMate bot key file: ${absolutePath}`);
23019
23334
  }
@@ -23030,10 +23345,10 @@ var AccountCommandHandler = class {
23030
23345
  throw new Error("Missing access key file");
23031
23346
  }
23032
23347
  const absolutePath = this.resolveFilePath(filePath);
23033
- if (!(0, import_node_fs27.existsSync)(absolutePath)) {
23348
+ if (!(0, import_node_fs28.existsSync)(absolutePath)) {
23034
23349
  throw new Error(`Access key file not found: ${absolutePath}`);
23035
23350
  }
23036
- const parsed = JSON.parse((0, import_node_fs27.readFileSync)(absolutePath, "utf8"));
23351
+ const parsed = JSON.parse((0, import_node_fs28.readFileSync)(absolutePath, "utf8"));
23037
23352
  if (parsed.type !== "pmate-access-key" || parsed.version !== 1 || !parsed.id || !parsed.app || !parsed.secret || !parsed.expiresAt) {
23038
23353
  throw new Error(`Invalid PMate access key file: ${absolutePath}`);
23039
23354
  }
@@ -23055,9 +23370,9 @@ var AccountCommandHandler = class {
23055
23370
  createdAt: result.key.createdAt
23056
23371
  };
23057
23372
  const outPath = out ? this.resolveFilePath(out) : this.resolveDefaultAccessKeyPath(result.key.app, result.key.name);
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);
23373
+ (0, import_node_fs28.mkdirSync)(import_node_path33.default.dirname(outPath), { recursive: true });
23374
+ (0, import_node_fs28.writeFileSync)(outPath, JSON.stringify(keyFile, null, 2), { mode: 384 });
23375
+ (0, import_node_fs28.chmodSync)(outPath, 384);
23061
23376
  }
23062
23377
  renderAccessKeyCreateResult(result, asJson, out) {
23063
23378
  if (asJson) {
@@ -23103,12 +23418,12 @@ var AccountCommandHandler = class {
23103
23418
  });
23104
23419
  }
23105
23420
  signBotChallenge(challenge, privateKey) {
23106
- const key = (0, import_node_crypto7.createPrivateKey)({
23421
+ const key = (0, import_node_crypto8.createPrivateKey)({
23107
23422
  key: Buffer.from(privateKey, "base64url"),
23108
23423
  format: "der",
23109
23424
  type: "pkcs8"
23110
23425
  });
23111
- return (0, import_node_crypto7.sign)(
23426
+ return (0, import_node_crypto8.sign)(
23112
23427
  null,
23113
23428
  Buffer.from(JSON.stringify({
23114
23429
  id: challenge.id,
@@ -23142,16 +23457,16 @@ function encodePathSegment2(value) {
23142
23457
  }
23143
23458
 
23144
23459
  // src/commands/OrgCommandHandler.ts
23145
- var import_node_fs28 = require("fs");
23146
- var import_node_path33 = __toESM(require("path"));
23460
+ var import_node_fs29 = require("fs");
23461
+ var import_node_path34 = __toESM(require("path"));
23147
23462
  init_sessionStore();
23148
23463
  var OrgCommandHandler = class {
23149
23464
  async handle(args) {
23150
23465
  const token = this.readToken();
23151
- const baseUrl = this.resolveBaseUrl(args.baseUrl);
23466
+ const baseUrl2 = this.resolveBaseUrl(args.baseUrl);
23152
23467
  switch (args.action) {
23153
23468
  case "list": {
23154
- const result = await this.request(baseUrl, token, "GET", "/orgs");
23469
+ const result = await this.request(baseUrl2, token, "GET", "/orgs");
23155
23470
  this.renderJson(result.items, args.json);
23156
23471
  if (!args.json) {
23157
23472
  this.renderOrgList(result.items);
@@ -23161,7 +23476,7 @@ var OrgCommandHandler = class {
23161
23476
  case "get":
23162
23477
  case "view": {
23163
23478
  const record = await this.request(
23164
- baseUrl,
23479
+ baseUrl2,
23165
23480
  token,
23166
23481
  "GET",
23167
23482
  `/orgs/${encodeURIComponent(args.orgId)}`
@@ -23170,7 +23485,7 @@ var OrgCommandHandler = class {
23170
23485
  return;
23171
23486
  }
23172
23487
  case "create": {
23173
- const record = await this.request(baseUrl, token, "POST", "/orgs", {
23488
+ const record = await this.request(baseUrl2, token, "POST", "/orgs", {
23174
23489
  id: args.orgId,
23175
23490
  displayName: args.displayName,
23176
23491
  members: args.members
@@ -23181,7 +23496,7 @@ var OrgCommandHandler = class {
23181
23496
  }
23182
23497
  case "update": {
23183
23498
  const record = await this.request(
23184
- baseUrl,
23499
+ baseUrl2,
23185
23500
  token,
23186
23501
  "PATCH",
23187
23502
  `/orgs/${encodeURIComponent(args.orgId)}`,
@@ -23195,7 +23510,7 @@ var OrgCommandHandler = class {
23195
23510
  }
23196
23511
  case "disable": {
23197
23512
  const record = await this.request(
23198
- baseUrl,
23513
+ baseUrl2,
23199
23514
  token,
23200
23515
  "DELETE",
23201
23516
  `/orgs/${encodeURIComponent(args.orgId)}`
@@ -23206,7 +23521,7 @@ var OrgCommandHandler = class {
23206
23521
  }
23207
23522
  case "member-list": {
23208
23523
  const result = await this.request(
23209
- baseUrl,
23524
+ baseUrl2,
23210
23525
  token,
23211
23526
  "GET",
23212
23527
  `/orgs/${encodeURIComponent(args.orgId)}/members`
@@ -23216,7 +23531,7 @@ var OrgCommandHandler = class {
23216
23531
  }
23217
23532
  case "member-add": {
23218
23533
  const record = await this.request(
23219
- baseUrl,
23534
+ baseUrl2,
23220
23535
  token,
23221
23536
  "PUT",
23222
23537
  `/orgs/${encodeURIComponent(args.orgId)}/members/${encodeURIComponent(args.account)}`
@@ -23227,7 +23542,7 @@ var OrgCommandHandler = class {
23227
23542
  }
23228
23543
  case "member-remove": {
23229
23544
  const record = await this.request(
23230
- baseUrl,
23545
+ baseUrl2,
23231
23546
  token,
23232
23547
  "DELETE",
23233
23548
  `/orgs/${encodeURIComponent(args.orgId)}/members/${encodeURIComponent(args.account)}`
@@ -23239,7 +23554,7 @@ var OrgCommandHandler = class {
23239
23554
  case "member-set": {
23240
23555
  const accounts = this.resolveStringArrayInput(args.accounts, args.filePath, "account");
23241
23556
  const record = await this.request(
23242
- baseUrl,
23557
+ baseUrl2,
23243
23558
  token,
23244
23559
  "PUT",
23245
23560
  `/orgs/${encodeURIComponent(args.orgId)}/members`,
@@ -23251,7 +23566,7 @@ var OrgCommandHandler = class {
23251
23566
  }
23252
23567
  case "visible-app-list": {
23253
23568
  const result = await this.request(
23254
- baseUrl,
23569
+ baseUrl2,
23255
23570
  token,
23256
23571
  "GET",
23257
23572
  `/orgs/${encodeURIComponent(args.orgId)}/visible-apps`
@@ -23261,7 +23576,7 @@ var OrgCommandHandler = class {
23261
23576
  }
23262
23577
  case "visible-app-add": {
23263
23578
  const record = await this.request(
23264
- baseUrl,
23579
+ baseUrl2,
23265
23580
  token,
23266
23581
  "PUT",
23267
23582
  `/orgs/${encodeURIComponent(args.orgId)}/visible-apps/${encodePathSegment3(args.app)}`
@@ -23272,7 +23587,7 @@ var OrgCommandHandler = class {
23272
23587
  }
23273
23588
  case "visible-app-remove": {
23274
23589
  const result = await this.request(
23275
- baseUrl,
23590
+ baseUrl2,
23276
23591
  token,
23277
23592
  "DELETE",
23278
23593
  `/orgs/${encodeURIComponent(args.orgId)}/visible-apps/${encodePathSegment3(args.app)}`
@@ -23286,7 +23601,7 @@ var OrgCommandHandler = class {
23286
23601
  case "visible-app-set": {
23287
23602
  const apps = this.resolveStringArrayInput(args.apps, args.filePath, "app ref");
23288
23603
  const result = await this.request(
23289
- baseUrl,
23604
+ baseUrl2,
23290
23605
  token,
23291
23606
  "PUT",
23292
23607
  `/orgs/${encodeURIComponent(args.orgId)}/visible-apps`,
@@ -23298,8 +23613,8 @@ var OrgCommandHandler = class {
23298
23613
  }
23299
23614
  }
23300
23615
  }
23301
- resolveBaseUrl(baseUrl) {
23302
- return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
23616
+ resolveBaseUrl(baseUrl2) {
23617
+ return (baseUrl2 || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
23303
23618
  }
23304
23619
  readToken() {
23305
23620
  return readRequiredSession({
@@ -23313,11 +23628,11 @@ var OrgCommandHandler = class {
23313
23628
  if (!filePath) {
23314
23629
  throw new Error(`Missing ${itemLabel} input`);
23315
23630
  }
23316
- const absolutePath = import_node_path33.default.resolve(process.cwd(), filePath);
23317
- if (!(0, import_node_fs28.existsSync)(absolutePath)) {
23631
+ const absolutePath = import_node_path34.default.resolve(process.cwd(), filePath);
23632
+ if (!(0, import_node_fs29.existsSync)(absolutePath)) {
23318
23633
  throw new Error(`JSON file not found: ${absolutePath}`);
23319
23634
  }
23320
- const raw = (0, import_node_fs28.readFileSync)(absolutePath, "utf8");
23635
+ const raw = (0, import_node_fs29.readFileSync)(absolutePath, "utf8");
23321
23636
  let parsed;
23322
23637
  try {
23323
23638
  parsed = JSON.parse(raw);
@@ -23330,8 +23645,8 @@ var OrgCommandHandler = class {
23330
23645
  }
23331
23646
  return parsed;
23332
23647
  }
23333
- async request(baseUrl, token, method, pathname, body) {
23334
- const response = await fetch(`${baseUrl}${pathname}`, {
23648
+ async request(baseUrl2, token, method, pathname, body) {
23649
+ const response = await fetch(`${baseUrl2}${pathname}`, {
23335
23650
  method,
23336
23651
  headers: {
23337
23652
  Authorization: `Bearer ${token}`,
@@ -23388,10 +23703,10 @@ function encodePathSegment3(value) {
23388
23703
  }
23389
23704
 
23390
23705
  // src/commands/HostCommandHandler.ts
23391
- var import_node_fs29 = require("fs");
23392
- var import_node_os14 = require("os");
23393
- var import_node_path34 = __toESM(require("path"));
23394
- var import_node_child_process15 = require("child_process");
23706
+ var import_node_fs30 = require("fs");
23707
+ var import_node_os15 = require("os");
23708
+ var import_node_path35 = __toESM(require("path"));
23709
+ var import_node_child_process16 = require("child_process");
23395
23710
  var BLOCK_START = "# >>> pmate host env >>>";
23396
23711
  var BLOCK_END = "# <<< pmate host env <<<";
23397
23712
  var PROFILE_BLOCK = `${BLOCK_START}
@@ -23403,7 +23718,7 @@ fi
23403
23718
  ${BLOCK_END}`;
23404
23719
  var HostCommandHandler = class {
23405
23720
  async handle(args) {
23406
- const hostId = normalizeHostId(args.host ?? process.env.PMATE_HOST_ID ?? (0, import_node_os14.hostname)());
23721
+ const hostId = normalizeHostId(args.host ?? process.env.PMATE_HOST_ID ?? (0, import_node_os15.hostname)());
23407
23722
  const client = new ServiceRegistryClient(args.baseUrl);
23408
23723
  if (args.action === "env-list") {
23409
23724
  const items = await client.listHostEnv(hostId);
@@ -23434,7 +23749,7 @@ async function applyHostEnvRemote(host, values) {
23434
23749
  const content = serializeHostEnv(values);
23435
23750
  const script = buildRemoteApplyScript(Buffer.from(content, "utf8").toString("base64"));
23436
23751
  await new Promise((resolve, reject) => {
23437
- const child = (0, import_node_child_process15.spawn)("ssh", [target, "bash -s"], { stdio: ["pipe", "pipe", "pipe"] });
23752
+ const child = (0, import_node_child_process16.spawn)("ssh", [target, "bash -s"], { stdio: ["pipe", "pipe", "pipe"] });
23438
23753
  let stdout = "";
23439
23754
  let stderr = "";
23440
23755
  child.stdout.on("data", (chunk) => {
@@ -23520,7 +23835,7 @@ function parseRegistryArgs(tokens, type, label) {
23520
23835
  if (!action || !["list", "get", "view", "create", "update", "delete"].includes(action)) {
23521
23836
  throw new Error(`Use: ${label} list|get|view|create|update|delete`);
23522
23837
  }
23523
- let baseUrl;
23838
+ let baseUrl2;
23524
23839
  let json = false;
23525
23840
  let namespace;
23526
23841
  let name;
@@ -23543,7 +23858,7 @@ function parseRegistryArgs(tokens, type, label) {
23543
23858
  return next;
23544
23859
  };
23545
23860
  if (option === "--namespace" || option === "--ns") namespace = value();
23546
- else if (option === "--base-url") baseUrl = value();
23861
+ else if (option === "--base-url") baseUrl2 = value();
23547
23862
  else if (option === "--file") filePath = value();
23548
23863
  else if (option === "--json") json = true;
23549
23864
  else throw new Error(`Unknown ${label} option: ${option}`);
@@ -23551,7 +23866,7 @@ function parseRegistryArgs(tokens, type, label) {
23551
23866
  if ((action === "create" || action === "update") && !filePath) {
23552
23867
  throw new Error(`Missing required option --file for ${label} ${action}`);
23553
23868
  }
23554
- return { type, action, namespace, name, filePath, baseUrl, json };
23869
+ return { type, action, namespace, name, filePath, baseUrl: baseUrl2, json };
23555
23870
  }
23556
23871
 
23557
23872
  // src/callCommandParser.ts
@@ -23619,7 +23934,7 @@ function parseNsArgs(tokens) {
23619
23934
  throw new Error("Missing ns action. Use: ns list|get|create");
23620
23935
  }
23621
23936
  let chain = DEFAULT_CHAIN;
23622
- let baseUrl;
23937
+ let baseUrl2;
23623
23938
  let json = false;
23624
23939
  if (action === "list") {
23625
23940
  takeSharedOptions(rest, {
@@ -23627,13 +23942,13 @@ function parseNsArgs(tokens) {
23627
23942
  chain = value;
23628
23943
  },
23629
23944
  onBaseUrl: (value) => {
23630
- baseUrl = value;
23945
+ baseUrl2 = value;
23631
23946
  },
23632
23947
  onJson: () => {
23633
23948
  json = true;
23634
23949
  }
23635
23950
  });
23636
- return { type: "ns" /* Ns */, action, chain, baseUrl, json };
23951
+ return { type: "ns" /* Ns */, action, chain, baseUrl: baseUrl2, json };
23637
23952
  }
23638
23953
  if (action === "get" || action === "create") {
23639
23954
  const namespace = rest.shift();
@@ -23645,13 +23960,13 @@ function parseNsArgs(tokens) {
23645
23960
  chain = value;
23646
23961
  },
23647
23962
  onBaseUrl: (value) => {
23648
- baseUrl = value;
23963
+ baseUrl2 = value;
23649
23964
  },
23650
23965
  onJson: () => {
23651
23966
  json = true;
23652
23967
  }
23653
23968
  });
23654
- return { type: "ns" /* Ns */, action, namespace, chain, baseUrl, json };
23969
+ return { type: "ns" /* Ns */, action, namespace, chain, baseUrl: baseUrl2, json };
23655
23970
  }
23656
23971
  throw new Error(`Unknown ns action: ${action}`);
23657
23972
  }
@@ -23898,14 +24213,14 @@ function parseAppArgs(tokens) {
23898
24213
  throw new Error("Missing app action. Use: app list|get|view|create|update|rename|move|icon|delete");
23899
24214
  }
23900
24215
  if (action === "build") throw new Error("app build was removed; register an electron service and use pmate service deploy <ns:service>");
23901
- let baseUrl;
24216
+ let baseUrl2;
23902
24217
  let json = false;
23903
24218
  const takeSharedOptions4 = () => {
23904
24219
  while (rest.length > 0) {
23905
24220
  const token = rest[0];
23906
24221
  if (token === "--base-url") {
23907
24222
  rest.shift();
23908
- baseUrl = requireValue3(rest, token);
24223
+ baseUrl2 = requireValue3(rest, token);
23909
24224
  continue;
23910
24225
  }
23911
24226
  if (token === "--json") {
@@ -23930,7 +24245,7 @@ function parseAppArgs(tokens) {
23930
24245
  all = true;
23931
24246
  break;
23932
24247
  case "--base-url":
23933
- baseUrl = requireValue3(rest, token);
24248
+ baseUrl2 = requireValue3(rest, token);
23934
24249
  break;
23935
24250
  case "--json":
23936
24251
  json = true;
@@ -23939,7 +24254,7 @@ function parseAppArgs(tokens) {
23939
24254
  throw new Error(`Unknown app list option: ${token}`);
23940
24255
  }
23941
24256
  }
23942
- return { type: "app" /* App */, action, namespace, all, baseUrl, json };
24257
+ return { type: "app" /* App */, action, namespace, all, baseUrl: baseUrl2, json };
23943
24258
  }
23944
24259
  if (action === "view") {
23945
24260
  const rawRef = rest.shift();
@@ -23955,13 +24270,13 @@ function parseAppArgs(tokens) {
23955
24270
  const token = rest.shift();
23956
24271
  switch (token) {
23957
24272
  case "--base-url":
23958
- baseUrl = requireValue3(rest, token);
24273
+ baseUrl2 = requireValue3(rest, token);
23959
24274
  break;
23960
24275
  default:
23961
24276
  throw new Error(`Unknown app view option: ${token}`);
23962
24277
  }
23963
24278
  }
23964
- return { type: "app" /* App */, action, id, baseUrl, json };
24279
+ return { type: "app" /* App */, action, id, baseUrl: baseUrl2, json };
23965
24280
  }
23966
24281
  if (action === "get" || action === "delete") {
23967
24282
  const rawRef = rest.shift();
@@ -23977,7 +24292,7 @@ function parseAppArgs(tokens) {
23977
24292
  if (rest.length > 0) {
23978
24293
  throw new Error(`Unknown app ${action} option: ${rest[0]}`);
23979
24294
  }
23980
- return { type: "app" /* App */, action, id, baseUrl, json };
24295
+ return { type: "app" /* App */, action, id, baseUrl: baseUrl2, json };
23981
24296
  }
23982
24297
  if (action === "icon") {
23983
24298
  const nextToken = rest[0];
@@ -24041,7 +24356,7 @@ function parseAppArgs(tokens) {
24041
24356
  force = true;
24042
24357
  break;
24043
24358
  case "--base-url":
24044
- baseUrl = requireValue3(rest, token);
24359
+ baseUrl2 = requireValue3(rest, token);
24045
24360
  break;
24046
24361
  case "--json":
24047
24362
  json = true;
@@ -24067,7 +24382,7 @@ function parseAppArgs(tokens) {
24067
24382
  format: format2,
24068
24383
  output: output2,
24069
24384
  force,
24070
- baseUrl,
24385
+ baseUrl: baseUrl2,
24071
24386
  json
24072
24387
  };
24073
24388
  }
@@ -24134,7 +24449,7 @@ function parseAppArgs(tokens) {
24134
24449
  outDir = requireValue3(rest, token);
24135
24450
  break;
24136
24451
  case "--base-url":
24137
- baseUrl = requireValue3(rest, token);
24452
+ baseUrl2 = requireValue3(rest, token);
24138
24453
  break;
24139
24454
  case "--json":
24140
24455
  json = true;
@@ -24169,7 +24484,7 @@ function parseAppArgs(tokens) {
24169
24484
  format,
24170
24485
  output,
24171
24486
  outDir,
24172
- baseUrl,
24487
+ baseUrl: baseUrl2,
24173
24488
  json
24174
24489
  };
24175
24490
  }
@@ -24182,7 +24497,7 @@ function parseAppArgs(tokens) {
24182
24497
  filePath = requireValue3(rest, token);
24183
24498
  break;
24184
24499
  case "--base-url":
24185
- baseUrl = requireValue3(rest, token);
24500
+ baseUrl2 = requireValue3(rest, token);
24186
24501
  break;
24187
24502
  case "--json":
24188
24503
  json = true;
@@ -24194,7 +24509,7 @@ function parseAppArgs(tokens) {
24194
24509
  if (!filePath) {
24195
24510
  throw new Error("Missing required option --file for app create");
24196
24511
  }
24197
- return { type: "app" /* App */, action, filePath, baseUrl, json };
24512
+ return { type: "app" /* App */, action, filePath, baseUrl: baseUrl2, json };
24198
24513
  }
24199
24514
  if (action === "update") {
24200
24515
  const rawRef = rest.shift();
@@ -24212,7 +24527,7 @@ function parseAppArgs(tokens) {
24212
24527
  filePath = requireValue3(rest, token);
24213
24528
  break;
24214
24529
  case "--base-url":
24215
- baseUrl = requireValue3(rest, token);
24530
+ baseUrl2 = requireValue3(rest, token);
24216
24531
  break;
24217
24532
  case "--json":
24218
24533
  json = true;
@@ -24224,7 +24539,7 @@ function parseAppArgs(tokens) {
24224
24539
  if (!filePath) {
24225
24540
  throw new Error("Missing required option --file for app update");
24226
24541
  }
24227
- return { type: "app" /* App */, action, id, filePath, baseUrl, json };
24542
+ return { type: "app" /* App */, action, id, filePath, baseUrl: baseUrl2, json };
24228
24543
  }
24229
24544
  if (action === "rename") {
24230
24545
  let namespace;
@@ -24244,7 +24559,7 @@ function parseAppArgs(tokens) {
24244
24559
  toId = parseBareRenameId(requireValue3(rest, token), "app");
24245
24560
  break;
24246
24561
  case "--base-url":
24247
- baseUrl = requireValue3(rest, token);
24562
+ baseUrl2 = requireValue3(rest, token);
24248
24563
  break;
24249
24564
  case "--json":
24250
24565
  json = true;
@@ -24258,7 +24573,7 @@ function parseAppArgs(tokens) {
24258
24573
  "Usage: app rename --from <id> --to <id> --ns <namespace> [--base-url <url>] [--json]"
24259
24574
  );
24260
24575
  }
24261
- return { type: "app" /* App */, action, namespace, fromId, toId, baseUrl, json };
24576
+ return { type: "app" /* App */, action, namespace, fromId, toId, baseUrl: baseUrl2, json };
24262
24577
  }
24263
24578
  if (action === "move") {
24264
24579
  let namespace;
@@ -24283,7 +24598,7 @@ function parseAppArgs(tokens) {
24283
24598
  toId = parseBareRenameId(requireValue3(rest, token), "app");
24284
24599
  break;
24285
24600
  case "--base-url":
24286
- baseUrl = requireValue3(rest, token);
24601
+ baseUrl2 = requireValue3(rest, token);
24287
24602
  break;
24288
24603
  case "--json":
24289
24604
  json = true;
@@ -24297,7 +24612,7 @@ function parseAppArgs(tokens) {
24297
24612
  "Usage: app move --from <id> --ns <namespace> --to-ns <namespace> [--to <id>] [--base-url <url>] [--json]"
24298
24613
  );
24299
24614
  }
24300
- return { type: "app" /* App */, action, namespace, fromId, targetNamespace, toId, baseUrl, json };
24615
+ return { type: "app" /* App */, action, namespace, fromId, targetNamespace, toId, baseUrl: baseUrl2, json };
24301
24616
  }
24302
24617
  throw new Error(`Unknown app action: ${action}`);
24303
24618
  }
@@ -24353,7 +24668,7 @@ function parseServiceArgs(tokens) {
24353
24668
  if (!action) {
24354
24669
  throw new Error("Missing service action. Use: service list|get|view|create|update|rename|delete|deploy|stop|init|log");
24355
24670
  }
24356
- let baseUrl;
24671
+ let baseUrl2;
24357
24672
  let json = false;
24358
24673
  if (action === "list") {
24359
24674
  let namespace;
@@ -24372,7 +24687,7 @@ function parseServiceArgs(tokens) {
24372
24687
  server = requireValue4(rest, token);
24373
24688
  break;
24374
24689
  case "--base-url":
24375
- baseUrl = requireValue4(rest, token);
24690
+ baseUrl2 = requireValue4(rest, token);
24376
24691
  break;
24377
24692
  case "--json":
24378
24693
  json = true;
@@ -24381,7 +24696,7 @@ function parseServiceArgs(tokens) {
24381
24696
  throw new Error(`Unknown service list option: ${token}`);
24382
24697
  }
24383
24698
  }
24384
- return { type: "service" /* Service */, action, namespace, repository, server, baseUrl, json };
24699
+ return { type: "service" /* Service */, action, namespace, repository, server, baseUrl: baseUrl2, json };
24385
24700
  }
24386
24701
  if (action === "view") {
24387
24702
  const ref = rest.shift();
@@ -24392,7 +24707,7 @@ function parseServiceArgs(tokens) {
24392
24707
  const token = rest.shift();
24393
24708
  switch (token) {
24394
24709
  case "--base-url":
24395
- baseUrl = requireValue4(rest, token);
24710
+ baseUrl2 = requireValue4(rest, token);
24396
24711
  break;
24397
24712
  case "--json":
24398
24713
  json = true;
@@ -24407,7 +24722,7 @@ function parseServiceArgs(tokens) {
24407
24722
  action,
24408
24723
  namespace: parsedRef.namespace,
24409
24724
  name: parsedRef.objectId,
24410
- baseUrl,
24725
+ baseUrl: baseUrl2,
24411
24726
  json
24412
24727
  };
24413
24728
  }
@@ -24437,7 +24752,7 @@ function parseServiceArgs(tokens) {
24437
24752
  dryRun = true;
24438
24753
  break;
24439
24754
  case "--base-url":
24440
- baseUrl = requireValue4(rest, token);
24755
+ baseUrl2 = requireValue4(rest, token);
24441
24756
  break;
24442
24757
  case "--json":
24443
24758
  json = true;
@@ -24456,13 +24771,13 @@ function parseServiceArgs(tokens) {
24456
24771
  name: parsedRef.objectId,
24457
24772
  sslCert,
24458
24773
  dryRun,
24459
- baseUrl,
24774
+ baseUrl: baseUrl2,
24460
24775
  json
24461
24776
  };
24462
24777
  }
24463
24778
  if (action === "ios") throw new Error("service ios build was removed; use pmate service deploy <ns:ios-service>");
24464
24779
  if (action === "apk") {
24465
- return parseServiceApkArgs(rest, { baseUrl, json });
24780
+ return parseServiceApkArgs(rest, { baseUrl: baseUrl2, json });
24466
24781
  }
24467
24782
  if (action === "get" || action === "delete" || action === "deploy" || action === "stop" || action === "init" || action === "log" || action === "deploy-logs" || action === "deploy-history") {
24468
24783
  const ref = rest.shift();
@@ -24530,7 +24845,7 @@ function parseServiceArgs(tokens) {
24530
24845
  if (!Number.isSafeInteger(sinceMs) || sinceMs < 0) throw new Error("Invalid --since-ms");
24531
24846
  break;
24532
24847
  case "--base-url":
24533
- baseUrl = requireValue4(rest, token);
24848
+ baseUrl2 = requireValue4(rest, token);
24534
24849
  break;
24535
24850
  case "--cwd":
24536
24851
  if (action !== "init" && action !== "deploy") {
@@ -24569,11 +24884,11 @@ function parseServiceArgs(tokens) {
24569
24884
  const namespace = parsedRef.namespace;
24570
24885
  const name = parsedRef.objectId;
24571
24886
  if (action === "log") {
24572
- if (app && (history || follow || env || baseUrl)) throw new Error("App logs do not support --history, --follow, --env or --base-url; use --page, --search and --since-ms");
24573
- return { type: "service" /* Service */, action, namespace, name, baseUrl, json, page, history, search, follow, env, ...logFilters, ...app ? { app } : {}, ...sinceMs !== void 0 ? { sinceMs } : {} };
24887
+ if (app && (history || follow || env || baseUrl2)) throw new Error("App logs do not support --history, --follow, --env or --base-url; use --page, --search and --since-ms");
24888
+ return { type: "service" /* Service */, action, namespace, name, baseUrl: baseUrl2, json, page, history, search, follow, env, ...logFilters, ...app ? { app } : {}, ...sinceMs !== void 0 ? { sinceMs } : {} };
24574
24889
  }
24575
24890
  if (action === "deploy-logs" || action === "deploy-history") {
24576
- return { type: "service" /* Service */, action, namespace, name, env, page, baseUrl, json };
24891
+ return { type: "service" /* Service */, action, namespace, name, env, page, baseUrl: baseUrl2, json };
24577
24892
  }
24578
24893
  if (action === "deploy" || action === "stop") {
24579
24894
  if (native.signed && native.unsigned) throw new Error("--signed and --unsigned cannot be combined");
@@ -24591,15 +24906,15 @@ function parseServiceArgs(tokens) {
24591
24906
  native.lastBuild = Number(native.lastBuild);
24592
24907
  }
24593
24908
  if (action === "deploy") env ??= "prod";
24594
- return { type: "service" /* Service */, action, namespace, name, env, ...cwd ? { cwd } : {}, ...native, baseUrl, json };
24909
+ return { type: "service" /* Service */, action, namespace, name, env, ...cwd ? { cwd } : {}, ...native, baseUrl: baseUrl2, json };
24595
24910
  }
24596
24911
  if (action === "init") {
24597
24912
  if (!env) {
24598
24913
  throw new Error("Missing required option --env for service init");
24599
24914
  }
24600
- return { type: "service" /* Service */, action, namespace, name, env, cwd, baseUrl, json };
24915
+ return { type: "service" /* Service */, action, namespace, name, env, cwd, baseUrl: baseUrl2, json };
24601
24916
  }
24602
- return { type: "service" /* Service */, action, namespace, name, baseUrl, json };
24917
+ return { type: "service" /* Service */, action, namespace, name, baseUrl: baseUrl2, json };
24603
24918
  }
24604
24919
  if (action === "create") {
24605
24920
  let filePath;
@@ -24610,7 +24925,7 @@ function parseServiceArgs(tokens) {
24610
24925
  filePath = requireValue4(rest, token);
24611
24926
  break;
24612
24927
  case "--base-url":
24613
- baseUrl = requireValue4(rest, token);
24928
+ baseUrl2 = requireValue4(rest, token);
24614
24929
  break;
24615
24930
  case "--json":
24616
24931
  json = true;
@@ -24622,7 +24937,7 @@ function parseServiceArgs(tokens) {
24622
24937
  if (!filePath) {
24623
24938
  throw new Error("Missing required option --file for service create");
24624
24939
  }
24625
- return { type: "service" /* Service */, action, filePath, baseUrl, json };
24940
+ return { type: "service" /* Service */, action, filePath, baseUrl: baseUrl2, json };
24626
24941
  }
24627
24942
  if (action === "update") {
24628
24943
  const ref = rest.shift();
@@ -24642,7 +24957,7 @@ function parseServiceArgs(tokens) {
24642
24957
  filePath = requireValue4(rest, token);
24643
24958
  break;
24644
24959
  case "--base-url":
24645
- baseUrl = requireValue4(rest, token);
24960
+ baseUrl2 = requireValue4(rest, token);
24646
24961
  break;
24647
24962
  case "--json":
24648
24963
  json = true;
@@ -24654,7 +24969,7 @@ function parseServiceArgs(tokens) {
24654
24969
  if (!filePath) {
24655
24970
  throw new Error("Missing required option --file for service update");
24656
24971
  }
24657
- return { type: "service" /* Service */, action, namespace, name, filePath, baseUrl, json };
24972
+ return { type: "service" /* Service */, action, namespace, name, filePath, baseUrl: baseUrl2, json };
24658
24973
  }
24659
24974
  if (action === "rename") {
24660
24975
  let namespace;
@@ -24674,7 +24989,7 @@ function parseServiceArgs(tokens) {
24674
24989
  to = parseBareRenameId2(requireValue4(rest, token), "service");
24675
24990
  break;
24676
24991
  case "--base-url":
24677
- baseUrl = requireValue4(rest, token);
24992
+ baseUrl2 = requireValue4(rest, token);
24678
24993
  break;
24679
24994
  case "--json":
24680
24995
  json = true;
@@ -24694,7 +25009,7 @@ function parseServiceArgs(tokens) {
24694
25009
  namespace,
24695
25010
  fromName: from,
24696
25011
  toName: to,
24697
- baseUrl,
25012
+ baseUrl: baseUrl2,
24698
25013
  json
24699
25014
  };
24700
25015
  }
@@ -24721,7 +25036,7 @@ function parseServiceArgs(tokens) {
24721
25036
  to = parseBareRenameId2(requireValue4(rest, token), "service");
24722
25037
  break;
24723
25038
  case "--base-url":
24724
- baseUrl = requireValue4(rest, token);
25039
+ baseUrl2 = requireValue4(rest, token);
24725
25040
  break;
24726
25041
  case "--json":
24727
25042
  json = true;
@@ -24742,7 +25057,7 @@ function parseServiceArgs(tokens) {
24742
25057
  fromName: from,
24743
25058
  targetNamespace,
24744
25059
  toName: to,
24745
- baseUrl,
25060
+ baseUrl: baseUrl2,
24746
25061
  json
24747
25062
  };
24748
25063
  }
@@ -24772,16 +25087,16 @@ function parseServiceApkArgs(tokens, defaults) {
24772
25087
  if (action !== "list") throw new Error("Usage: service apk list <ns:service> [--env <env>] [--json]");
24773
25088
  const parsed = parseNamespacedRef(rest.shift() ?? "", { entityLabel: "service ref" });
24774
25089
  let env;
24775
- let baseUrl = defaults.baseUrl;
25090
+ let baseUrl2 = defaults.baseUrl;
24776
25091
  let json = defaults.json;
24777
25092
  while (rest.length) {
24778
25093
  const flag = rest.shift();
24779
25094
  if (flag === "--env") env = requireValue4(rest, flag);
24780
- else if (flag === "--base-url") baseUrl = requireValue4(rest, flag);
25095
+ else if (flag === "--base-url") baseUrl2 = requireValue4(rest, flag);
24781
25096
  else if (flag === "--json") json = true;
24782
25097
  else throw new Error(`Unknown service apk list option: ${flag}`);
24783
25098
  }
24784
- return { type: "service" /* Service */, action: "apk-list", namespace: parsed.namespace, name: parsed.objectId, env, baseUrl, json };
25099
+ return { type: "service" /* Service */, action: "apk-list", namespace: parsed.namespace, name: parsed.objectId, env, baseUrl: baseUrl2, json };
24785
25100
  }
24786
25101
  function parseServiceEnvDefinitionArgs(appId, tokens) {
24787
25102
  const rest = [...tokens];
@@ -24789,14 +25104,14 @@ function parseServiceEnvDefinitionArgs(appId, tokens) {
24789
25104
  if (!action) {
24790
25105
  throw new Error("Usage: service <ns:service> env list|get|add|expose");
24791
25106
  }
24792
- let baseUrl;
25107
+ let baseUrl2;
24793
25108
  let json = false;
24794
25109
  if (action === "list") {
24795
25110
  while (rest.length > 0) {
24796
25111
  const token = rest.shift();
24797
25112
  switch (token) {
24798
25113
  case "--base-url":
24799
- baseUrl = requireValue4(rest, token);
25114
+ baseUrl2 = requireValue4(rest, token);
24800
25115
  break;
24801
25116
  case "--json":
24802
25117
  json = true;
@@ -24805,7 +25120,7 @@ function parseServiceEnvDefinitionArgs(appId, tokens) {
24805
25120
  throw new Error(`Unknown service env list option: ${token}`);
24806
25121
  }
24807
25122
  }
24808
- return { type: "service" /* Service */, action: "service-env-list", appId, baseUrl, json };
25123
+ return { type: "service" /* Service */, action: "service-env-list", appId, baseUrl: baseUrl2, json };
24809
25124
  }
24810
25125
  if (action === "get" || action === "add") {
24811
25126
  const envName = rest.shift();
@@ -24816,7 +25131,7 @@ function parseServiceEnvDefinitionArgs(appId, tokens) {
24816
25131
  const token = rest.shift();
24817
25132
  switch (token) {
24818
25133
  case "--base-url":
24819
- baseUrl = requireValue4(rest, token);
25134
+ baseUrl2 = requireValue4(rest, token);
24820
25135
  break;
24821
25136
  case "--json":
24822
25137
  json = true;
@@ -24830,7 +25145,7 @@ function parseServiceEnvDefinitionArgs(appId, tokens) {
24830
25145
  action: action === "get" ? "service-env-get" : "service-env-add",
24831
25146
  appId,
24832
25147
  envName,
24833
- baseUrl,
25148
+ baseUrl: baseUrl2,
24834
25149
  json
24835
25150
  };
24836
25151
  }
@@ -24860,7 +25175,7 @@ function parseServiceEnvDefinitionArgs(appId, tokens) {
24860
25175
  off = true;
24861
25176
  break;
24862
25177
  case "--base-url":
24863
- baseUrl = requireValue4(rest, token);
25178
+ baseUrl2 = requireValue4(rest, token);
24864
25179
  break;
24865
25180
  case "--json":
24866
25181
  json = true;
@@ -24877,7 +25192,7 @@ function parseServiceEnvDefinitionArgs(appId, tokens) {
24877
25192
  exposeType,
24878
25193
  domain,
24879
25194
  off,
24880
- baseUrl,
25195
+ baseUrl: baseUrl2,
24881
25196
  json
24882
25197
  };
24883
25198
  }
@@ -24889,7 +25204,7 @@ function parseServiceEnvArgs(appId, tokens) {
24889
25204
  if (!action) {
24890
25205
  throw new Error("Usage: service <ns:app> env list|get|set|unset|resolve|pull|copy-from|update-scope");
24891
25206
  }
24892
- let baseUrl;
25207
+ let baseUrl2;
24893
25208
  let json = false;
24894
25209
  if (action === "list") {
24895
25210
  let scope;
@@ -24909,7 +25224,7 @@ function parseServiceEnvArgs(appId, tokens) {
24909
25224
  includeSecretValue = true;
24910
25225
  break;
24911
25226
  case "--base-url":
24912
- baseUrl = requireValue4(rest, token);
25227
+ baseUrl2 = requireValue4(rest, token);
24913
25228
  break;
24914
25229
  case "--json":
24915
25230
  json = true;
@@ -24918,7 +25233,7 @@ function parseServiceEnvArgs(appId, tokens) {
24918
25233
  throw new Error(`Unknown service env list option: ${token}`);
24919
25234
  }
24920
25235
  }
24921
- return { type: "service" /* Service */, action: "env-list", appId, scope, includeSecretMeta, includeSecretValue, baseUrl, json };
25236
+ return { type: "service" /* Service */, action: "env-list", appId, scope, includeSecretMeta, includeSecretValue, baseUrl: baseUrl2, json };
24922
25237
  }
24923
25238
  if (action === "get") {
24924
25239
  const key = rest.shift();
@@ -24938,7 +25253,7 @@ function parseServiceEnvArgs(appId, tokens) {
24938
25253
  includeSecretValue = true;
24939
25254
  break;
24940
25255
  case "--base-url":
24941
- baseUrl = requireValue4(rest, token);
25256
+ baseUrl2 = requireValue4(rest, token);
24942
25257
  break;
24943
25258
  case "--json":
24944
25259
  json = true;
@@ -24948,7 +25263,7 @@ function parseServiceEnvArgs(appId, tokens) {
24948
25263
  }
24949
25264
  }
24950
25265
  scope = scope ?? "all";
24951
- return { type: "service" /* Service */, action: "env-get", appId, key, scope, includeSecretValue, baseUrl, json };
25266
+ return { type: "service" /* Service */, action: "env-get", appId, key, scope, includeSecretValue, baseUrl: baseUrl2, json };
24952
25267
  }
24953
25268
  if (action === "set") {
24954
25269
  const key = rest.shift();
@@ -24976,7 +25291,7 @@ function parseServiceEnvArgs(appId, tokens) {
24976
25291
  prompt = true;
24977
25292
  break;
24978
25293
  case "--base-url":
24979
- baseUrl = requireValue4(rest, token);
25294
+ baseUrl2 = requireValue4(rest, token);
24980
25295
  break;
24981
25296
  case "--json":
24982
25297
  json = true;
@@ -24989,7 +25304,7 @@ function parseServiceEnvArgs(appId, tokens) {
24989
25304
  if (!value && !secret && !prompt) {
24990
25305
  throw new Error("Missing env value. Pass a value or use --prompt.");
24991
25306
  }
24992
- return { type: "service" /* Service */, action: "env-set", appId, key, value, scope, secret, prompt, baseUrl, json };
25307
+ return { type: "service" /* Service */, action: "env-set", appId, key, value, scope, secret, prompt, baseUrl: baseUrl2, json };
24993
25308
  }
24994
25309
  if (action === "unset") {
24995
25310
  const key = rest.shift();
@@ -25005,7 +25320,7 @@ function parseServiceEnvArgs(appId, tokens) {
25005
25320
  scope = requireValue4(rest, token);
25006
25321
  break;
25007
25322
  case "--base-url":
25008
- baseUrl = requireValue4(rest, token);
25323
+ baseUrl2 = requireValue4(rest, token);
25009
25324
  break;
25010
25325
  case "--json":
25011
25326
  json = true;
@@ -25015,7 +25330,7 @@ function parseServiceEnvArgs(appId, tokens) {
25015
25330
  }
25016
25331
  }
25017
25332
  scope = scope ?? "all";
25018
- return { type: "service" /* Service */, action: "env-unset", appId, key, scope, baseUrl, json };
25333
+ return { type: "service" /* Service */, action: "env-unset", appId, key, scope, baseUrl: baseUrl2, json };
25019
25334
  }
25020
25335
  if (action === "resolve") {
25021
25336
  let stage;
@@ -25034,7 +25349,7 @@ function parseServiceEnvArgs(appId, tokens) {
25034
25349
  includeSecretValue = true;
25035
25350
  break;
25036
25351
  case "--base-url":
25037
- baseUrl = requireValue4(rest, token);
25352
+ baseUrl2 = requireValue4(rest, token);
25038
25353
  break;
25039
25354
  case "--json":
25040
25355
  json = true;
@@ -25046,7 +25361,7 @@ function parseServiceEnvArgs(appId, tokens) {
25046
25361
  if (!stage) {
25047
25362
  throw new Error("Usage: service <ns:app> env resolve --stage <dev|preview|prod> [--branch <name>]");
25048
25363
  }
25049
- return { type: "service" /* Service */, action: "env-resolve", appId, stage, branch, includeSecretValue, baseUrl, json };
25364
+ return { type: "service" /* Service */, action: "env-resolve", appId, stage, branch, includeSecretValue, baseUrl: baseUrl2, json };
25050
25365
  }
25051
25366
  if (action === "pull") {
25052
25367
  let stage;
@@ -25065,7 +25380,7 @@ function parseServiceEnvArgs(appId, tokens) {
25065
25380
  output = requireValue4(rest, token);
25066
25381
  break;
25067
25382
  case "--base-url":
25068
- baseUrl = requireValue4(rest, token);
25383
+ baseUrl2 = requireValue4(rest, token);
25069
25384
  break;
25070
25385
  case "--json":
25071
25386
  json = true;
@@ -25077,7 +25392,7 @@ function parseServiceEnvArgs(appId, tokens) {
25077
25392
  if (!stage) {
25078
25393
  throw new Error("Usage: service <ns:app> env pull --stage <dev|preview|prod> [--branch <name>] [--output <path>]");
25079
25394
  }
25080
- return { type: "service" /* Service */, action: "env-pull", appId, stage, branch, output, baseUrl, json };
25395
+ return { type: "service" /* Service */, action: "env-pull", appId, stage, branch, output, baseUrl: baseUrl2, json };
25081
25396
  }
25082
25397
  if (action === "copy-from") {
25083
25398
  const sourceAppId = rest.shift();
@@ -25104,7 +25419,7 @@ function parseServiceEnvArgs(appId, tokens) {
25104
25419
  onlyKeys = requireValue4(rest, token).split(",").map((item) => item.trim()).filter(Boolean);
25105
25420
  break;
25106
25421
  case "--base-url":
25107
- baseUrl = requireValue4(rest, token);
25422
+ baseUrl2 = requireValue4(rest, token);
25108
25423
  break;
25109
25424
  case "--json":
25110
25425
  json = true;
@@ -25113,7 +25428,7 @@ function parseServiceEnvArgs(appId, tokens) {
25113
25428
  throw new Error(`Unknown service env copy-from option: ${token}`);
25114
25429
  }
25115
25430
  }
25116
- return { type: "service" /* Service */, action: "env-copy-from", targetAppId: appId, sourceAppId, scope, includeSecret, overwrite, onlyKeys, baseUrl, json };
25431
+ return { type: "service" /* Service */, action: "env-copy-from", targetAppId: appId, sourceAppId, scope, includeSecret, overwrite, onlyKeys, baseUrl: baseUrl2, json };
25117
25432
  }
25118
25433
  if (action === "update-scope") {
25119
25434
  let fromScope;
@@ -25138,7 +25453,7 @@ function parseServiceEnvArgs(appId, tokens) {
25138
25453
  onlyKeys = requireValue4(rest, token).split(",").map((item) => item.trim()).filter(Boolean);
25139
25454
  break;
25140
25455
  case "--base-url":
25141
- baseUrl = requireValue4(rest, token);
25456
+ baseUrl2 = requireValue4(rest, token);
25142
25457
  break;
25143
25458
  case "--json":
25144
25459
  json = true;
@@ -25158,7 +25473,7 @@ function parseServiceEnvArgs(appId, tokens) {
25158
25473
  toScope,
25159
25474
  overwrite,
25160
25475
  onlyKeys,
25161
- baseUrl,
25476
+ baseUrl: baseUrl2,
25162
25477
  json
25163
25478
  };
25164
25479
  }
@@ -25246,12 +25561,12 @@ function parseRoleArgs(tokens) {
25246
25561
  if (!action) {
25247
25562
  throw new Error("Missing role action. Use: role definition list|create");
25248
25563
  }
25249
- let baseUrl;
25564
+ let baseUrl2;
25250
25565
  let json = false;
25251
25566
  if (action === "list") {
25252
25567
  takeSharedOptions3(rest, {
25253
25568
  onBaseUrl: (value) => {
25254
- baseUrl = value;
25569
+ baseUrl2 = value;
25255
25570
  },
25256
25571
  onJson: () => {
25257
25572
  json = true;
@@ -25261,7 +25576,7 @@ function parseRoleArgs(tokens) {
25261
25576
  type: "role" /* Role */,
25262
25577
  resource,
25263
25578
  action,
25264
- baseUrl,
25579
+ baseUrl: baseUrl2,
25265
25580
  json
25266
25581
  };
25267
25582
  }
@@ -25284,7 +25599,7 @@ function parseRoleArgs(tokens) {
25284
25599
  description = requireValue5(rest, token);
25285
25600
  break;
25286
25601
  case "--base-url":
25287
- baseUrl = requireValue5(rest, token);
25602
+ baseUrl2 = requireValue5(rest, token);
25288
25603
  break;
25289
25604
  case "--json":
25290
25605
  json = true;
@@ -25300,7 +25615,7 @@ function parseRoleArgs(tokens) {
25300
25615
  role,
25301
25616
  displayName,
25302
25617
  description,
25303
- baseUrl,
25618
+ baseUrl: baseUrl2,
25304
25619
  json
25305
25620
  };
25306
25621
  }
@@ -25342,7 +25657,7 @@ function parseAccountArgs(tokens) {
25342
25657
  let nickName;
25343
25658
  let page;
25344
25659
  let pageSize;
25345
- let baseUrl2;
25660
+ let baseUrl3;
25346
25661
  let json2 = false;
25347
25662
  while (rest.length > 0) {
25348
25663
  const token = rest.shift();
@@ -25361,7 +25676,7 @@ function parseAccountArgs(tokens) {
25361
25676
  pageSize = parsePositiveInt(requireValue6(rest, token), token);
25362
25677
  break;
25363
25678
  case "--base-url":
25364
- baseUrl2 = requireValue6(rest, token);
25679
+ baseUrl3 = requireValue6(rest, token);
25365
25680
  break;
25366
25681
  case "--json":
25367
25682
  json2 = true;
@@ -25382,7 +25697,7 @@ function parseAccountArgs(tokens) {
25382
25697
  pageSize,
25383
25698
  mobile,
25384
25699
  nickName,
25385
- baseUrl: baseUrl2,
25700
+ baseUrl: baseUrl3,
25386
25701
  json: json2
25387
25702
  };
25388
25703
  }
@@ -25392,7 +25707,7 @@ function parseAccountArgs(tokens) {
25392
25707
  }).fullId;
25393
25708
  let page;
25394
25709
  let pageSize;
25395
- let baseUrl2;
25710
+ let baseUrl3;
25396
25711
  let json2 = false;
25397
25712
  while (rest.length > 0) {
25398
25713
  const token = rest.shift();
@@ -25404,7 +25719,7 @@ function parseAccountArgs(tokens) {
25404
25719
  pageSize = parsePositiveInt(requireValue6(rest, token), token);
25405
25720
  break;
25406
25721
  case "--base-url":
25407
- baseUrl2 = requireValue6(rest, token);
25722
+ baseUrl3 = requireValue6(rest, token);
25408
25723
  break;
25409
25724
  case "--json":
25410
25725
  json2 = true;
@@ -25419,7 +25734,7 @@ function parseAccountArgs(tokens) {
25419
25734
  app,
25420
25735
  page,
25421
25736
  pageSize,
25422
- baseUrl: baseUrl2,
25737
+ baseUrl: baseUrl3,
25423
25738
  json: json2
25424
25739
  };
25425
25740
  }
@@ -25427,7 +25742,7 @@ function parseAccountArgs(tokens) {
25427
25742
  let account2;
25428
25743
  let mobile;
25429
25744
  let nickName;
25430
- let baseUrl2;
25745
+ let baseUrl3;
25431
25746
  let json2 = false;
25432
25747
  while (rest.length > 0) {
25433
25748
  const token = rest.shift();
@@ -25445,7 +25760,7 @@ function parseAccountArgs(tokens) {
25445
25760
  nickName = requireValue6(rest, token);
25446
25761
  break;
25447
25762
  case "--base-url":
25448
- baseUrl2 = requireValue6(rest, token);
25763
+ baseUrl3 = requireValue6(rest, token);
25449
25764
  break;
25450
25765
  case "--json":
25451
25766
  json2 = true;
@@ -25470,7 +25785,7 @@ function parseAccountArgs(tokens) {
25470
25785
  account: account2,
25471
25786
  mobile,
25472
25787
  nickName,
25473
- baseUrl: baseUrl2,
25788
+ baseUrl: baseUrl3,
25474
25789
  json: json2
25475
25790
  };
25476
25791
  }
@@ -25483,7 +25798,7 @@ function parseAccountArgs(tokens) {
25483
25798
  let app;
25484
25799
  const apps = [];
25485
25800
  let filePath;
25486
- let baseUrl2;
25801
+ let baseUrl3;
25487
25802
  let json2 = false;
25488
25803
  while (rest.length > 0) {
25489
25804
  const token = rest.shift();
@@ -25501,7 +25816,7 @@ function parseAccountArgs(tokens) {
25501
25816
  filePath = requireValue6(rest, token);
25502
25817
  break;
25503
25818
  case "--base-url":
25504
- baseUrl2 = requireValue6(rest, token);
25819
+ baseUrl3 = requireValue6(rest, token);
25505
25820
  break;
25506
25821
  case "--json":
25507
25822
  json2 = true;
@@ -25519,7 +25834,7 @@ function parseAccountArgs(tokens) {
25519
25834
  return {
25520
25835
  type: "account" /* Account */,
25521
25836
  action: "visible-app-resolve",
25522
- baseUrl: baseUrl2,
25837
+ baseUrl: baseUrl3,
25523
25838
  json: json2
25524
25839
  };
25525
25840
  }
@@ -25533,7 +25848,7 @@ function parseAccountArgs(tokens) {
25533
25848
  type: "account" /* Account */,
25534
25849
  action: "visible-app-list",
25535
25850
  account: account2,
25536
- baseUrl: baseUrl2,
25851
+ baseUrl: baseUrl3,
25537
25852
  json: json2
25538
25853
  };
25539
25854
  }
@@ -25548,7 +25863,7 @@ function parseAccountArgs(tokens) {
25548
25863
  action: visibleAction === "add" ? "visible-app-add" : "visible-app-remove",
25549
25864
  account: account2,
25550
25865
  app,
25551
- baseUrl: baseUrl2,
25866
+ baseUrl: baseUrl3,
25552
25867
  json: json2
25553
25868
  };
25554
25869
  }
@@ -25564,7 +25879,7 @@ function parseAccountArgs(tokens) {
25564
25879
  account: account2,
25565
25880
  apps: apps.length > 0 ? apps : void 0,
25566
25881
  filePath,
25567
- baseUrl: baseUrl2,
25882
+ baseUrl: baseUrl3,
25568
25883
  json: json2
25569
25884
  };
25570
25885
  }
@@ -25585,7 +25900,7 @@ function parseAccountArgs(tokens) {
25585
25900
  let newName;
25586
25901
  let nickName;
25587
25902
  let role2;
25588
- let baseUrl2;
25903
+ let baseUrl3;
25589
25904
  let json2 = false;
25590
25905
  while (rest.length > 0) {
25591
25906
  const token = rest.shift();
@@ -25627,7 +25942,7 @@ function parseAccountArgs(tokens) {
25627
25942
  break;
25628
25943
  }
25629
25944
  case "--base-url":
25630
- baseUrl2 = requireValue6(rest, token);
25945
+ baseUrl3 = requireValue6(rest, token);
25631
25946
  break;
25632
25947
  case "--json":
25633
25948
  json2 = true;
@@ -25646,31 +25961,31 @@ function parseAccountArgs(tokens) {
25646
25961
  if (!app || !name || !keyFile && !publicKey) {
25647
25962
  throw new Error("Usage: account bot create --app <ns:app> --name <name> (--key-file <path> | --public-key <key>) [--base-url <url>] [--json]");
25648
25963
  }
25649
- return { type: "account" /* Account */, action: "bot-create", app, name, keyFile, publicKey, baseUrl: baseUrl2, json: json2 };
25964
+ return { type: "account" /* Account */, action: "bot-create", app, name, keyFile, publicKey, baseUrl: baseUrl3, json: json2 };
25650
25965
  }
25651
25966
  if (botAction === "view") {
25652
25967
  if (!app || !name) {
25653
25968
  throw new Error("Usage: account bot view --app <ns:app> --name <name> [--base-url <url>] [--json]");
25654
25969
  }
25655
- return { type: "account" /* Account */, action: "bot-view", app, name, baseUrl: baseUrl2, json: json2 };
25970
+ return { type: "account" /* Account */, action: "bot-view", app, name, baseUrl: baseUrl3, json: json2 };
25656
25971
  }
25657
25972
  if (botAction === "list") {
25658
25973
  if (!app) {
25659
25974
  throw new Error("Usage: account bot list --app <ns:app> [--base-url <url>] [--json]");
25660
25975
  }
25661
- return { type: "account" /* Account */, action: "bot-list", app, baseUrl: baseUrl2, json: json2 };
25976
+ return { type: "account" /* Account */, action: "bot-list", app, baseUrl: baseUrl3, json: json2 };
25662
25977
  }
25663
25978
  if (botAction === "rename") {
25664
25979
  if (!app || !name || !newName) {
25665
25980
  throw new Error("Usage: account bot rename --app <ns:app> --name <name> --new-name <new-name> [--base-url <url>] [--json]");
25666
25981
  }
25667
- return { type: "account" /* Account */, action: "bot-rename", app, name, newName, baseUrl: baseUrl2, json: json2 };
25982
+ return { type: "account" /* Account */, action: "bot-rename", app, name, newName, baseUrl: baseUrl3, json: json2 };
25668
25983
  }
25669
25984
  if (botAction === "login") {
25670
25985
  if (!app || !name || !keyFile && !privateKey) {
25671
25986
  throw new Error("Usage: account bot login --app <ns:app> --name <name> (--key-file <path> | --private-key <key>) [--base-url <url>] [--json]");
25672
25987
  }
25673
- return { type: "account" /* Account */, action: "bot-login", app, name, keyFile, privateKey, baseUrl: baseUrl2, json: json2 };
25988
+ return { type: "account" /* Account */, action: "bot-login", app, name, keyFile, privateKey, baseUrl: baseUrl3, json: json2 };
25674
25989
  }
25675
25990
  if (botAction === "profile") {
25676
25991
  if (botProfileAction !== "create") {
@@ -25679,7 +25994,7 @@ function parseAccountArgs(tokens) {
25679
25994
  if (!app || !name || !nickName) {
25680
25995
  throw new Error("Usage: account bot profile create --app <ns:app> --name <name> --nickname <nickname> [--role <role>] [--base-url <url>] [--json]");
25681
25996
  }
25682
- return { type: "account" /* Account */, action: "bot-profile-create", app, name, nickName, role: role2, baseUrl: baseUrl2, json: json2 };
25997
+ return { type: "account" /* Account */, action: "bot-profile-create", app, name, nickName, role: role2, baseUrl: baseUrl3, json: json2 };
25683
25998
  }
25684
25999
  throw new Error(`Unknown account bot action: ${botAction}`);
25685
26000
  }
@@ -25697,7 +26012,7 @@ function parseAccountArgs(tokens) {
25697
26012
  let key;
25698
26013
  let keyFile;
25699
26014
  let gracePeriodSeconds;
25700
- let baseUrl2;
26015
+ let baseUrl3;
25701
26016
  let json2 = false;
25702
26017
  while (rest.length > 0) {
25703
26018
  const token = rest.shift();
@@ -25732,7 +26047,7 @@ function parseAccountArgs(tokens) {
25732
26047
  keyFile = requireValue6(rest, token);
25733
26048
  break;
25734
26049
  case "--base-url":
25735
- baseUrl2 = requireValue6(rest, token);
26050
+ baseUrl3 = requireValue6(rest, token);
25736
26051
  break;
25737
26052
  case "--json":
25738
26053
  json2 = true;
@@ -25752,28 +26067,28 @@ function parseAccountArgs(tokens) {
25752
26067
  if (!app || !name) {
25753
26068
  throw new Error("Usage: account access-key create --app <ns:app> --name <name> [--expires-at <iso> | --expires-in <duration>] [--namespace <ns>] [--out <path>] [--base-url <url>] [--json]");
25754
26069
  }
25755
- return { type: "account" /* Account */, action: "access-key-create", app, name, namespace: namespace2, expiresAt, out, baseUrl: baseUrl2, json: json2 };
26070
+ return { type: "account" /* Account */, action: "access-key-create", app, name, namespace: namespace2, expiresAt, out, baseUrl: baseUrl3, json: json2 };
25756
26071
  }
25757
26072
  if (keyAction === "list") {
25758
- return { type: "account" /* Account */, action: "access-key-list", app, namespace: namespace2, baseUrl: baseUrl2, json: json2 };
26073
+ return { type: "account" /* Account */, action: "access-key-list", app, namespace: namespace2, baseUrl: baseUrl3, json: json2 };
25759
26074
  }
25760
26075
  if (keyAction === "disable") {
25761
26076
  if (!id) {
25762
26077
  throw new Error("Usage: account access-key disable <id> [--base-url <url>] [--json]");
25763
26078
  }
25764
- return { type: "account" /* Account */, action: "access-key-disable", id, baseUrl: baseUrl2, json: json2 };
26079
+ return { type: "account" /* Account */, action: "access-key-disable", id, baseUrl: baseUrl3, json: json2 };
25765
26080
  }
25766
26081
  if (keyAction === "rotate") {
25767
26082
  if (!id) {
25768
26083
  throw new Error("Usage: account access-key rotate <id> [--expires-at <iso> | --expires-in <duration>] [--grace-period <duration>] [--out <path>] [--base-url <url>] [--json]");
25769
26084
  }
25770
- return { type: "account" /* Account */, action: "access-key-rotate", id, expiresAt, gracePeriodSeconds, out, baseUrl: baseUrl2, json: json2 };
26085
+ return { type: "account" /* Account */, action: "access-key-rotate", id, expiresAt, gracePeriodSeconds, out, baseUrl: baseUrl3, json: json2 };
25771
26086
  }
25772
26087
  if (keyAction === "login") {
25773
26088
  if (!app || !key && !keyFile || key && keyFile) {
25774
26089
  throw new Error("Usage: account access-key login --app <ns:app> (--key <secret> | --key-file <path>) [--base-url <url>] [--json]");
25775
26090
  }
25776
- return { type: "account" /* Account */, action: "access-key-login", app, key, keyFile, baseUrl: baseUrl2, json: json2 };
26091
+ return { type: "account" /* Account */, action: "access-key-login", app, key, keyFile, baseUrl: baseUrl3, json: json2 };
25777
26092
  }
25778
26093
  throw new Error(`Unknown account access-key action: ${keyAction}`);
25779
26094
  }
@@ -25787,7 +26102,7 @@ function parseAccountArgs(tokens) {
25787
26102
  let account;
25788
26103
  let namespace;
25789
26104
  let role;
25790
- let baseUrl;
26105
+ let baseUrl2;
25791
26106
  let json = false;
25792
26107
  while (rest.length > 0) {
25793
26108
  const token = rest.shift();
@@ -25802,7 +26117,7 @@ function parseAccountArgs(tokens) {
25802
26117
  role = requireValue6(rest, token);
25803
26118
  break;
25804
26119
  case "--base-url":
25805
- baseUrl = requireValue6(rest, token);
26120
+ baseUrl2 = requireValue6(rest, token);
25806
26121
  break;
25807
26122
  case "--json":
25808
26123
  json = true;
@@ -25822,7 +26137,7 @@ function parseAccountArgs(tokens) {
25822
26137
  action: "role-list",
25823
26138
  account,
25824
26139
  namespace,
25825
- baseUrl,
26140
+ baseUrl: baseUrl2,
25826
26141
  json
25827
26142
  };
25828
26143
  }
@@ -25838,7 +26153,7 @@ function parseAccountArgs(tokens) {
25838
26153
  account,
25839
26154
  namespace,
25840
26155
  role,
25841
- baseUrl,
26156
+ baseUrl: baseUrl2,
25842
26157
  json
25843
26158
  };
25844
26159
  }
@@ -25883,14 +26198,14 @@ function parseOrgArgs(tokens) {
25883
26198
  "Missing org action. Use: org list|get|view|create|update|disable|member|visible-app"
25884
26199
  );
25885
26200
  }
25886
- let baseUrl;
26201
+ let baseUrl2;
25887
26202
  let json = false;
25888
26203
  const takeSharedOptions4 = () => {
25889
26204
  while (rest.length > 0) {
25890
26205
  const token = rest[0];
25891
26206
  if (token === "--base-url") {
25892
26207
  rest.shift();
25893
- baseUrl = requireValue7(rest, token);
26208
+ baseUrl2 = requireValue7(rest, token);
25894
26209
  continue;
25895
26210
  }
25896
26211
  if (token === "--json") {
@@ -25906,7 +26221,7 @@ function parseOrgArgs(tokens) {
25906
26221
  if (rest.length > 0) {
25907
26222
  throw new Error(`Unknown org list option: ${rest[0]}`);
25908
26223
  }
25909
- return { type: "org" /* Org */, action, baseUrl, json };
26224
+ return { type: "org" /* Org */, action, baseUrl: baseUrl2, json };
25910
26225
  }
25911
26226
  if (action === "get" || action === "view" || action === "disable") {
25912
26227
  const orgId = parseRequiredOrgRef(rest.shift(), action);
@@ -25914,7 +26229,7 @@ function parseOrgArgs(tokens) {
25914
26229
  if (rest.length > 0) {
25915
26230
  throw new Error(`Unknown org ${action} option: ${rest[0]}`);
25916
26231
  }
25917
- return { type: "org" /* Org */, action, orgId, baseUrl, json };
26232
+ return { type: "org" /* Org */, action, orgId, baseUrl: baseUrl2, json };
25918
26233
  }
25919
26234
  if (action === "create") {
25920
26235
  const orgId = parseRequiredOrgRef(rest.shift(), action);
@@ -25930,7 +26245,7 @@ function parseOrgArgs(tokens) {
25930
26245
  members.push(requireValue7(rest, token));
25931
26246
  break;
25932
26247
  case "--base-url":
25933
- baseUrl = requireValue7(rest, token);
26248
+ baseUrl2 = requireValue7(rest, token);
25934
26249
  break;
25935
26250
  case "--json":
25936
26251
  json = true;
@@ -25950,7 +26265,7 @@ function parseOrgArgs(tokens) {
25950
26265
  orgId,
25951
26266
  displayName,
25952
26267
  members,
25953
- baseUrl,
26268
+ baseUrl: baseUrl2,
25954
26269
  json
25955
26270
  };
25956
26271
  }
@@ -25964,7 +26279,7 @@ function parseOrgArgs(tokens) {
25964
26279
  displayName = requireValue7(rest, token);
25965
26280
  break;
25966
26281
  case "--base-url":
25967
- baseUrl = requireValue7(rest, token);
26282
+ baseUrl2 = requireValue7(rest, token);
25968
26283
  break;
25969
26284
  case "--json":
25970
26285
  json = true;
@@ -25983,7 +26298,7 @@ function parseOrgArgs(tokens) {
25983
26298
  action,
25984
26299
  orgId,
25985
26300
  displayName,
25986
- baseUrl,
26301
+ baseUrl: baseUrl2,
25987
26302
  json
25988
26303
  };
25989
26304
  }
@@ -26016,7 +26331,7 @@ function parseOrgArgs(tokens) {
26016
26331
  filePath = requireValue7(memberTokens, token);
26017
26332
  break;
26018
26333
  case "--base-url":
26019
- baseUrl = requireValue7(memberTokens, token);
26334
+ baseUrl2 = requireValue7(memberTokens, token);
26020
26335
  break;
26021
26336
  case "--json":
26022
26337
  json = true;
@@ -26026,7 +26341,7 @@ function parseOrgArgs(tokens) {
26026
26341
  }
26027
26342
  }
26028
26343
  if (subAction === "list") {
26029
- return { type: "org" /* Org */, action: "member-list", orgId, baseUrl, json };
26344
+ return { type: "org" /* Org */, action: "member-list", orgId, baseUrl: baseUrl2, json };
26030
26345
  }
26031
26346
  if (subAction === "add" || subAction === "remove") {
26032
26347
  if (!account) {
@@ -26039,7 +26354,7 @@ function parseOrgArgs(tokens) {
26039
26354
  action: subAction === "add" ? "member-add" : "member-remove",
26040
26355
  orgId,
26041
26356
  account,
26042
- baseUrl,
26357
+ baseUrl: baseUrl2,
26043
26358
  json
26044
26359
  };
26045
26360
  }
@@ -26055,7 +26370,7 @@ function parseOrgArgs(tokens) {
26055
26370
  orgId,
26056
26371
  accounts: accounts.length > 0 ? accounts : void 0,
26057
26372
  filePath,
26058
- baseUrl,
26373
+ baseUrl: baseUrl2,
26059
26374
  json
26060
26375
  };
26061
26376
  }
@@ -26087,7 +26402,7 @@ function parseOrgArgs(tokens) {
26087
26402
  filePath = requireValue7(visibleTokens, token);
26088
26403
  break;
26089
26404
  case "--base-url":
26090
- baseUrl = requireValue7(visibleTokens, token);
26405
+ baseUrl2 = requireValue7(visibleTokens, token);
26091
26406
  break;
26092
26407
  case "--json":
26093
26408
  json = true;
@@ -26097,7 +26412,7 @@ function parseOrgArgs(tokens) {
26097
26412
  }
26098
26413
  }
26099
26414
  if (subAction === "list") {
26100
- return { type: "org" /* Org */, action: "visible-app-list", orgId, baseUrl, json };
26415
+ return { type: "org" /* Org */, action: "visible-app-list", orgId, baseUrl: baseUrl2, json };
26101
26416
  }
26102
26417
  if (subAction === "add" || subAction === "remove") {
26103
26418
  if (!app) {
@@ -26110,7 +26425,7 @@ function parseOrgArgs(tokens) {
26110
26425
  action: subAction === "add" ? "visible-app-add" : "visible-app-remove",
26111
26426
  orgId,
26112
26427
  app,
26113
- baseUrl,
26428
+ baseUrl: baseUrl2,
26114
26429
  json
26115
26430
  };
26116
26431
  }
@@ -26126,7 +26441,7 @@ function parseOrgArgs(tokens) {
26126
26441
  orgId,
26127
26442
  apps: apps.length > 0 ? apps : void 0,
26128
26443
  filePath,
26129
- baseUrl,
26444
+ baseUrl: baseUrl2,
26130
26445
  json
26131
26446
  };
26132
26447
  }
@@ -26171,18 +26486,18 @@ function parseHostArgs(tokens) {
26171
26486
  } else throw new Error("Usage: host env list|set|unset ... | host apply");
26172
26487
  let host;
26173
26488
  let secret = false;
26174
- let baseUrl;
26489
+ let baseUrl2;
26175
26490
  let json = false;
26176
26491
  while (rest.length > 0) {
26177
26492
  const token = rest.shift();
26178
26493
  if (token === "--host") host = requireValue8(rest, token);
26179
26494
  else if (token === "--secret") secret = true;
26180
- else if (token === "--base-url") baseUrl = requireValue8(rest, token);
26495
+ else if (token === "--base-url") baseUrl2 = requireValue8(rest, token);
26181
26496
  else if (token === "--json") json = true;
26182
26497
  else throw new Error(`Unknown host option: ${token}`);
26183
26498
  }
26184
26499
  if (secret && action !== "env-set") throw new Error("--secret is only valid for host env set");
26185
- return { type: "host" /* Host */, action, host, key, value, secret, baseUrl, json };
26500
+ return { type: "host" /* Host */, action, host, key, value, secret, baseUrl: baseUrl2, json };
26186
26501
  }
26187
26502
  function requireValue8(tokens, label) {
26188
26503
  const value = tokens.shift();
@@ -26632,7 +26947,7 @@ function requireValue11(tokens, option) {
26632
26947
 
26633
26948
  // src/index.ts
26634
26949
  var pkg = JSON.parse(
26635
- (0, import_node_fs30.readFileSync)(import_node_path35.default.resolve(__dirname, "..", "package.json"), "utf8")
26950
+ (0, import_node_fs31.readFileSync)(import_node_path36.default.resolve(__dirname, "..", "package.json"), "utf8")
26636
26951
  );
26637
26952
  var HELP_TEXT = [
26638
26953
  import_chalk4.default.bold(`pmate v${pkg.version}`),
@@ -27207,14 +27522,14 @@ function parseOssArgs(tokens) {
27207
27522
  if (action !== "upload") {
27208
27523
  throw new Error(`Unknown oss action: ${action}`);
27209
27524
  }
27210
- let bucket;
27525
+ let bucket2;
27211
27526
  let filePath;
27212
27527
  let objectKey;
27213
27528
  while (rest.length > 0) {
27214
27529
  const token = rest.shift();
27215
27530
  switch (token) {
27216
27531
  case "--bucket":
27217
- bucket = requireValue12(rest, token);
27532
+ bucket2 = requireValue12(rest, token);
27218
27533
  break;
27219
27534
  case "--file":
27220
27535
  filePath = requireValue12(rest, token);
@@ -27232,7 +27547,7 @@ function parseOssArgs(tokens) {
27232
27547
  if (!objectKey) {
27233
27548
  throw new Error("Missing required option --key for oss upload");
27234
27549
  }
27235
- return { type: "oss" /* Oss */, action, bucket, filePath, objectKey };
27550
+ return { type: "oss" /* Oss */, action, bucket: bucket2, filePath, objectKey };
27236
27551
  }
27237
27552
  function parseEnvArgs(tokens) {
27238
27553
  const rest = [...tokens];