@pmate/cli 0.24.27 → 0.24.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -936,6 +936,15 @@ type ServiceCommandArgs = {
936
936
  history: boolean;
937
937
  search?: string;
938
938
  follow: boolean;
939
+ } | {
940
+ type: Command.Service;
941
+ action: "deploy-logs" | "deploy-history";
942
+ namespace: string;
943
+ name: string;
944
+ env?: string;
945
+ page: number;
946
+ baseUrl?: string;
947
+ json: boolean;
939
948
  } | {
940
949
  type: Command.Service;
941
950
  action: "env-list";
package/dist/index.js CHANGED
@@ -18226,6 +18226,16 @@ var ServiceRegistryClient = class {
18226
18226
  input
18227
18227
  );
18228
18228
  }
18229
+ async listDeployHistory(serviceId, options = {}) {
18230
+ const params = new URLSearchParams();
18231
+ if (options.page !== void 0) {
18232
+ params.set("page", String(options.page));
18233
+ }
18234
+ return this.request(
18235
+ "GET",
18236
+ `/services/by-id/${encodeURIComponent(serviceId)}/deploy-history${params.size > 0 ? `?${params.toString()}` : ""}`
18237
+ );
18238
+ }
18229
18239
  async pullEnv(serviceId, options) {
18230
18240
  const pathname = `/services/by-id/${encodeURIComponent(serviceId)}/env/pull`;
18231
18241
  const response = await fetch(`${this.resolveBaseUrl()}${pathname}`, {
@@ -19829,6 +19839,22 @@ var ServiceCommandHandler = class {
19829
19839
  });
19830
19840
  return;
19831
19841
  }
19842
+ case "deploy-logs":
19843
+ case "deploy-history": {
19844
+ const serviceId = formatNamespacedDisplayId(args.namespace, args.name);
19845
+ const payload = await registry.listDeployHistory(serviceId, {
19846
+ page: args.page
19847
+ });
19848
+ const items = args.env ? payload.items.filter((item) => item.environment === args.env) : payload.items;
19849
+ this.renderDeployHistory(
19850
+ {
19851
+ ...payload,
19852
+ items
19853
+ },
19854
+ args.json
19855
+ );
19856
+ return;
19857
+ }
19832
19858
  case "env-list": {
19833
19859
  const payload = await this.request(
19834
19860
  baseUrl,
@@ -20101,20 +20127,31 @@ var ServiceCommandHandler = class {
20101
20127
  throw new Error(`Unsupported runtime ${runtime.type} for ${service.id} env ${env.name}`);
20102
20128
  }
20103
20129
  async appendDeployHistory(registry, serviceId, environment, status, message) {
20104
- try {
20105
- await registry.appendDeployHistory(serviceId, {
20106
- environment,
20107
- status,
20108
- ...message ? { message } : {}
20109
- });
20110
- } catch (error) {
20111
- ui.warn("Failed to append deploy history", {
20112
- serviceId,
20113
- environment,
20114
- status,
20115
- message: error instanceof Error ? error.message : String(error)
20116
- });
20130
+ let lastError;
20131
+ for (let attempt = 1; attempt <= 5; attempt += 1) {
20132
+ try {
20133
+ await registry.appendDeployHistory(serviceId, {
20134
+ environment,
20135
+ status,
20136
+ ...message ? { message } : {}
20137
+ });
20138
+ return;
20139
+ } catch (error2) {
20140
+ lastError = error2;
20141
+ if (attempt < 5 && shouldRetryDeployHistoryAppend(error2)) {
20142
+ await sleep3(attempt * 1e3);
20143
+ continue;
20144
+ }
20145
+ break;
20146
+ }
20117
20147
  }
20148
+ const error = lastError;
20149
+ ui.warn("Failed to append deploy history", {
20150
+ serviceId,
20151
+ environment,
20152
+ status,
20153
+ message: error instanceof Error ? error.message : String(error)
20154
+ });
20118
20155
  }
20119
20156
  resolveBaseUrl(baseUrl) {
20120
20157
  return (baseUrl || process.env.PMATE_APPS_API_BASE_URL || "https://apps-api.pmate.chat").replace(/\/+$/, "");
@@ -20317,6 +20354,22 @@ var ServiceCommandHandler = class {
20317
20354
  ui.info(formatNamespacedDisplayId(item.namespace, item.name), item);
20318
20355
  }
20319
20356
  }
20357
+ renderDeployHistory(payload, asJson) {
20358
+ if (asJson) {
20359
+ ui.plain(JSON.stringify(payload, null, 2));
20360
+ return;
20361
+ }
20362
+ if (payload.items.length === 0) {
20363
+ ui.warn(`No deploy logs found for ${payload.serviceId}.`);
20364
+ return;
20365
+ }
20366
+ for (const item of payload.items) {
20367
+ const time = new Date(item.createdAt).toISOString();
20368
+ const status = item.status === "success" ? "success" : "failed";
20369
+ const message = item.message ? ` ${item.message}` : "";
20370
+ ui.info(`${time} ${item.environment} ${status}${message}`, item);
20371
+ }
20372
+ }
20320
20373
  async deleteServiceResources(service) {
20321
20374
  switch (this.getServiceType(service)) {
20322
20375
  case "vite":
@@ -20544,6 +20597,13 @@ function splitPrimaryDomain(host) {
20544
20597
  domain: parts.slice(-2).join(".")
20545
20598
  };
20546
20599
  }
20600
+ function shouldRetryDeployHistoryAppend(error) {
20601
+ const message = error instanceof Error ? error.message : String(error);
20602
+ return message.includes("status 502") || message.includes("status 503") || message.includes("status 504") || message.includes("fetch failed") || message.includes("ECONNRESET") || message.includes("ETIMEDOUT");
20603
+ }
20604
+ function sleep3(ms) {
20605
+ return new Promise((resolve) => setTimeout(resolve, ms));
20606
+ }
20547
20607
 
20548
20608
  // src/commands/VercelCommandHandler.ts
20549
20609
  var import_node_child_process12 = require("child_process");
@@ -22859,7 +22919,7 @@ function parseServiceArgs(tokens) {
22859
22919
  json
22860
22920
  };
22861
22921
  }
22862
- if (action === "get" || action === "delete" || action === "deploy" || action === "stop" || action === "init" || action === "log") {
22922
+ if (action === "get" || action === "delete" || action === "deploy" || action === "stop" || action === "init" || action === "log" || action === "deploy-logs" || action === "deploy-history") {
22863
22923
  const ref = rest.shift();
22864
22924
  if (!ref || ref.startsWith("-")) {
22865
22925
  throw new Error(`Usage: service ${action} <ns:objectId> [--base-url <url>] [--json]`);
@@ -22883,7 +22943,7 @@ function parseServiceArgs(tokens) {
22883
22943
  cwd = requireValue6(rest, token);
22884
22944
  break;
22885
22945
  case "--env":
22886
- if (action !== "deploy" && action !== "init" && action !== "stop") {
22946
+ if (action !== "deploy" && action !== "init" && action !== "stop" && action !== "deploy-logs" && action !== "deploy-history") {
22887
22947
  throw new Error(`Unknown service ${action} option: ${token}`);
22888
22948
  }
22889
22949
  env = requireValue6(rest, token);
@@ -22914,6 +22974,9 @@ function parseServiceArgs(tokens) {
22914
22974
  if (action === "log") {
22915
22975
  return { type: "service" /* Service */, action, namespace, name, baseUrl, json, page, history, search, follow };
22916
22976
  }
22977
+ if (action === "deploy-logs" || action === "deploy-history") {
22978
+ return { type: "service" /* Service */, action, namespace, name, env, page, baseUrl, json };
22979
+ }
22917
22980
  if (action === "deploy" || action === "stop") {
22918
22981
  if (action === "deploy" && !env) {
22919
22982
  throw new Error("Missing required option --env for service deploy");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.24.27",
3
+ "version": "0.24.29",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {