@instafy/cli 0.1.8-staging.364 → 0.1.8-staging.365
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/auth.js +27 -5
- package/dist/index.js +44 -44
- package/package.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -45,11 +45,33 @@ function looksLikeLocalControllerUrl(controllerUrl) {
|
|
|
45
45
|
return controllerUrl.includes("127.0.0.1") || controllerUrl.includes("localhost");
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
async function isStudioHealthy(studioUrl, timeoutMs) {
|
|
49
|
+
const target = new URL("/cli/login", studioUrl).toString();
|
|
50
|
+
const abort = new AbortController();
|
|
51
|
+
const timeout = setTimeout(() => abort.abort(), timeoutMs);
|
|
52
|
+
timeout.unref?.();
|
|
53
|
+
try {
|
|
54
|
+
const response = await fetch(target, { signal: abort.signal });
|
|
55
|
+
return response.ok;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
clearTimeout(timeout);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function resolveDefaultStudioUrl(controllerUrl) {
|
|
65
|
+
const hosted = "https://staging.instafy.dev";
|
|
66
|
+
if (isStagingCli) {
|
|
67
|
+
return hosted;
|
|
68
|
+
}
|
|
69
|
+
if (!looksLikeLocalControllerUrl(controllerUrl)) {
|
|
70
|
+
return hosted;
|
|
51
71
|
}
|
|
52
|
-
|
|
72
|
+
const local = "http://localhost:5173";
|
|
73
|
+
const healthy = await isStudioHealthy(local, 250);
|
|
74
|
+
return healthy ? local : hosted;
|
|
53
75
|
}
|
|
54
76
|
async function isControllerHealthy(controllerUrl, timeoutMs) {
|
|
55
77
|
const target = `${controllerUrl.replace(/\/$/, "")}/healthz`;
|
|
@@ -228,7 +250,7 @@ export async function login(options) {
|
|
|
228
250
|
const studioUrl = normalizeUrl(options.studioUrl ?? null) ??
|
|
229
251
|
normalizeUrl(process.env["INSTAFY_STUDIO_URL"] ?? null) ??
|
|
230
252
|
(isStagingCli ? null : resolveConfiguredStudioUrl({ profile })) ??
|
|
231
|
-
|
|
253
|
+
(await resolveDefaultStudioUrl(controllerUrl));
|
|
232
254
|
const url = new URL("/cli/login", studioUrl);
|
|
233
255
|
url.searchParams.set("serverUrl", controllerUrl);
|
|
234
256
|
if (options.json) {
|
package/dist/index.js
CHANGED
|
@@ -77,44 +77,6 @@ program
|
|
|
77
77
|
process.exit(1);
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
program
|
|
81
|
-
.command("profile:list")
|
|
82
|
-
.description("List saved CLI profiles (~/.instafy/profiles)")
|
|
83
|
-
.option("--json", "Output JSON")
|
|
84
|
-
.action(async (opts) => {
|
|
85
|
-
try {
|
|
86
|
-
const names = listInstafyProfileNames();
|
|
87
|
-
const profiles = names.map((name) => {
|
|
88
|
-
const config = readInstafyProfileConfig(name);
|
|
89
|
-
return {
|
|
90
|
-
name,
|
|
91
|
-
path: getInstafyProfileConfigPath(name),
|
|
92
|
-
controllerUrl: config.controllerUrl ?? null,
|
|
93
|
-
studioUrl: config.studioUrl ?? null,
|
|
94
|
-
accessTokenSet: Boolean(config.accessToken),
|
|
95
|
-
updatedAt: config.updatedAt ?? null,
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
if (opts.json) {
|
|
99
|
-
console.log(JSON.stringify({ profiles }, null, 2));
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (profiles.length === 0) {
|
|
103
|
-
console.log(kleur.yellow("No profiles found."));
|
|
104
|
-
console.log(`Create one with: ${kleur.cyan("instafy login --profile <name>")}`);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
console.log(kleur.green("Instafy CLI profiles"));
|
|
108
|
-
for (const profile of profiles) {
|
|
109
|
-
const token = profile.accessTokenSet ? kleur.green("token") : kleur.yellow("no-token");
|
|
110
|
-
console.log(`- ${kleur.cyan(profile.name)} (${token})`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
console.error(kleur.red(String(error)));
|
|
115
|
-
process.exit(1);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
80
|
const projectInitCommand = program
|
|
119
81
|
.command("project:init")
|
|
120
82
|
.description("Create an Instafy project and link this folder (.instafy/project.json)")
|
|
@@ -170,6 +132,44 @@ program
|
|
|
170
132
|
process.exit(1);
|
|
171
133
|
}
|
|
172
134
|
});
|
|
135
|
+
program
|
|
136
|
+
.command("profile:list")
|
|
137
|
+
.description("List saved CLI profiles (~/.instafy/profiles)")
|
|
138
|
+
.option("--json", "Output JSON")
|
|
139
|
+
.action(async (opts) => {
|
|
140
|
+
try {
|
|
141
|
+
const names = listInstafyProfileNames();
|
|
142
|
+
const profiles = names.map((name) => {
|
|
143
|
+
const config = readInstafyProfileConfig(name);
|
|
144
|
+
return {
|
|
145
|
+
name,
|
|
146
|
+
path: getInstafyProfileConfigPath(name),
|
|
147
|
+
controllerUrl: config.controllerUrl ?? null,
|
|
148
|
+
studioUrl: config.studioUrl ?? null,
|
|
149
|
+
accessTokenSet: Boolean(config.accessToken),
|
|
150
|
+
updatedAt: config.updatedAt ?? null,
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
if (opts.json) {
|
|
154
|
+
console.log(JSON.stringify({ profiles }, null, 2));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (profiles.length === 0) {
|
|
158
|
+
console.log(kleur.yellow("No profiles found."));
|
|
159
|
+
console.log(`Create one with: ${kleur.cyan("instafy login --profile <name>")}`);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
console.log(kleur.green("Instafy CLI profiles"));
|
|
163
|
+
for (const profile of profiles) {
|
|
164
|
+
const token = profile.accessTokenSet ? kleur.green("token") : kleur.yellow("no-token");
|
|
165
|
+
console.log(`- ${kleur.cyan(profile.name)} (${token})`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
console.error(kleur.red(String(error)));
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
173
|
const configCommand = program.command("config").description("Get/set saved CLI configuration");
|
|
174
174
|
configCommand
|
|
175
175
|
.command("path")
|
|
@@ -339,8 +339,8 @@ runtimeTokenCommand
|
|
|
339
339
|
}
|
|
340
340
|
});
|
|
341
341
|
const gitTokenCommand = program
|
|
342
|
-
.command("git:token")
|
|
343
|
-
.description("
|
|
342
|
+
.command("git:token", { hidden: true })
|
|
343
|
+
.description("Advanced: mint a git access token for the project repo")
|
|
344
344
|
.option("--project <id>", "Project UUID (defaults to .instafy/project.json)");
|
|
345
345
|
addServerUrlOptions(gitTokenCommand);
|
|
346
346
|
addAccessTokenOptions(gitTokenCommand, "Instafy access token (required)");
|
|
@@ -601,22 +601,22 @@ function configureApiCommand(command, method) {
|
|
|
601
601
|
});
|
|
602
602
|
}
|
|
603
603
|
const apiGetCommand = program
|
|
604
|
-
.command("api:get")
|
|
604
|
+
.command("api:get", { hidden: true })
|
|
605
605
|
.description("Advanced: authenticated GET request to the controller API")
|
|
606
606
|
.argument("<path>", "API path (or full URL), e.g. /conversations/<id>/messages?limit=50");
|
|
607
607
|
configureApiCommand(apiGetCommand, "GET");
|
|
608
608
|
const apiPostCommand = program
|
|
609
|
-
.command("api:post")
|
|
609
|
+
.command("api:post", { hidden: true })
|
|
610
610
|
.description("Advanced: authenticated POST request to the controller API")
|
|
611
611
|
.argument("<path>", "API path (or full URL)");
|
|
612
612
|
configureApiCommand(apiPostCommand, "POST");
|
|
613
613
|
const apiPatchCommand = program
|
|
614
|
-
.command("api:patch")
|
|
614
|
+
.command("api:patch", { hidden: true })
|
|
615
615
|
.description("Advanced: authenticated PATCH request to the controller API")
|
|
616
616
|
.argument("<path>", "API path (or full URL)");
|
|
617
617
|
configureApiCommand(apiPatchCommand, "PATCH");
|
|
618
618
|
const apiDeleteCommand = program
|
|
619
|
-
.command("api:delete")
|
|
619
|
+
.command("api:delete", { hidden: true })
|
|
620
620
|
.description("Advanced: authenticated DELETE request to the controller API")
|
|
621
621
|
.argument("<path>", "API path (or full URL)");
|
|
622
622
|
configureApiCommand(apiDeleteCommand, "DELETE");
|
package/package.json
CHANGED