run402 1.38.0 → 1.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/domains.mjs CHANGED
@@ -1,4 +1,6 @@
1
- import { resolveProject, API } from "./config.mjs";
1
+ import { resolveProjectId } from "./config.mjs";
2
+ import { getSdk } from "./sdk.mjs";
3
+ import { reportSdkError } from "./sdk-errors.mjs";
2
4
 
3
5
  const HELP = `run402 domains — Manage custom domains
4
6
 
@@ -39,54 +41,48 @@ async function add(args) {
39
41
  const domain = rest[0];
40
42
  const subdomainName = rest[1];
41
43
  if (!domain || !subdomainName) { console.error("Usage: run402 domains add <domain> <subdomain_name> [--project <id>]"); process.exit(1); }
42
- const p = resolveProject(project);
43
- const res = await fetch(`${API}/domains/v1`, {
44
- method: "POST",
45
- headers: { "Authorization": `Bearer ${p.service_key}`, "Content-Type": "application/json" },
46
- body: JSON.stringify({ domain, subdomain_name: subdomainName }),
47
- });
48
- const data = await res.json();
49
- if (!res.ok) { console.error(JSON.stringify({ status: "error", http: res.status, ...data })); process.exit(1); }
50
- console.log(JSON.stringify(data, null, 2));
44
+ const projectId = resolveProjectId(project);
45
+ try {
46
+ const data = await getSdk().domains.add(projectId, domain, subdomainName);
47
+ console.log(JSON.stringify(data, null, 2));
48
+ } catch (err) {
49
+ reportSdkError(err);
50
+ }
51
51
  }
52
52
 
53
- async function list(projectId) {
54
- const p = resolveProject(projectId);
55
- const res = await fetch(`${API}/domains/v1`, {
56
- headers: { "Authorization": `Bearer ${p.service_key}` },
57
- });
58
- const data = await res.json();
59
- if (!res.ok) { console.error(JSON.stringify({ status: "error", http: res.status, ...data })); process.exit(1); }
60
- console.log(JSON.stringify(data, null, 2));
53
+ async function list(projectIdArg) {
54
+ const projectId = resolveProjectId(projectIdArg);
55
+ try {
56
+ const data = await getSdk().domains.list(projectId);
57
+ console.log(JSON.stringify(data, null, 2));
58
+ } catch (err) {
59
+ reportSdkError(err);
60
+ }
61
61
  }
62
62
 
63
63
  async function status(args) {
64
64
  const { project, rest } = parseProjectFlag(args);
65
65
  const domain = rest[0];
66
66
  if (!domain) { console.error("Usage: run402 domains status <domain> [--project <id>]"); process.exit(1); }
67
- const p = resolveProject(project);
68
- const res = await fetch(`${API}/domains/v1/${encodeURIComponent(domain)}`, {
69
- headers: { "Authorization": `Bearer ${p.service_key}` },
70
- });
71
- const data = await res.json();
72
- if (!res.ok) { console.error(JSON.stringify({ status: "error", http: res.status, ...data })); process.exit(1); }
73
- console.log(JSON.stringify(data, null, 2));
67
+ const projectId = resolveProjectId(project);
68
+ try {
69
+ const data = await getSdk().domains.status(projectId, domain);
70
+ console.log(JSON.stringify(data, null, 2));
71
+ } catch (err) {
72
+ reportSdkError(err);
73
+ }
74
74
  }
75
75
 
76
76
  async function deleteDomain(args) {
77
77
  const { project, rest } = parseProjectFlag(args);
78
78
  const domain = rest[0];
79
79
  if (!domain) { console.error("Usage: run402 domains delete <domain> [--project <id>]"); process.exit(1); }
80
- const p = resolveProject(project);
81
- const res = await fetch(`${API}/domains/v1/${encodeURIComponent(domain)}`, {
82
- method: "DELETE",
83
- headers: { "Authorization": `Bearer ${p.service_key}` },
84
- });
85
- if (res.status === 204 || res.ok) {
80
+ const projectId = resolveProjectId(project);
81
+ try {
82
+ await getSdk().domains.remove(domain, { projectId });
86
83
  console.log(JSON.stringify({ status: "ok", message: `Domain '${domain}' released.` }));
87
- } else {
88
- const data = await res.json().catch(() => ({}));
89
- console.error(JSON.stringify({ status: "error", http: res.status, ...data })); process.exit(1);
84
+ } catch (err) {
85
+ reportSdkError(err);
90
86
  }
91
87
  }
92
88