@apotech-os/cli 0.4.0 → 0.5.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -22713,6 +22713,32 @@ var FunctionTriggerSchema = external_exports.discriminatedUnion("type", [
22713
22713
  * AppSyncService.validateManifestConstraints, not here in the Zod schema.
22714
22714
  */
22715
22715
  name: external_exports.string()
22716
+ }),
22717
+ /**
22718
+ * Called synchronously by an app UI page, which receives the handler's return
22719
+ * value in the HTTP response.
22720
+ *
22721
+ * This is the only way a page can reach an integration: the action endpoint
22722
+ * requires an app token, and a browser session is refused. The platform mints
22723
+ * the token server-side and runs the handler in-process.
22724
+ *
22725
+ * Distinct from `httpRoute`, which is fire-and-forget (it dispatches an event
22726
+ * and answers with a run id). Keeping them as separate trigger types keeps one
22727
+ * handler tied to one dispatch path and one payload shape.
22728
+ *
22729
+ * SECURITY: the handler runs with the app's FULL manifest role, not the
22730
+ * caller's. Treat every uiInvoke function as a semi-public endpoint and
22731
+ * re-check anything sensitive inside the handler.
22732
+ */
22733
+ external_exports.object({
22734
+ type: external_exports.literal("uiInvoke"),
22735
+ /**
22736
+ * Minimum role the CALLING SESSION must hold on this app.
22737
+ * Defaults to EDITOR — fail-closed, since the handler is privileged.
22738
+ */
22739
+ minRole: external_exports.enum(["VIEWER", "EDITOR", "ADMIN"]).optional(),
22740
+ /** Wall-clock budget in ms. Clamped server-side by APP_SYNC_INVOKE_MAX_MS. */
22741
+ timeoutMs: external_exports.number().int().min(1e3).max(3e4).optional()
22716
22742
  })
22717
22743
  ]);
22718
22744
  var FunctionDefSchema = external_exports.object({
@@ -23549,102 +23575,14 @@ function buildRemoteCommand() {
23549
23575
  }
23550
23576
 
23551
23577
  // src/commands/login.ts
23552
- var import_child_process = require("child_process");
23553
- var import_os4 = require("os");
23554
- function clientLabel() {
23555
- try {
23556
- return `${(0, import_os4.userInfo)().username}@${(0, import_os4.hostname)()}`;
23557
- } catch {
23558
- return (0, import_os4.hostname)();
23559
- }
23560
- }
23561
- function openBrowser(url2) {
23562
- const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
23563
- try {
23564
- const child = (0, import_child_process.spawn)(command, [url2], {
23565
- detached: true,
23566
- stdio: "ignore",
23567
- shell: process.platform === "win32"
23568
- });
23569
- child.on("error", () => void 0);
23570
- child.unref();
23571
- } catch {
23572
- }
23573
- }
23574
- function sleep(ms) {
23575
- return new Promise((resolve4) => setTimeout(resolve4, ms));
23576
- }
23577
- async function postJson(url2, body) {
23578
- const res = await fetch(url2, {
23579
- method: "POST",
23580
- headers: { "Content-Type": "application/json" },
23581
- body: JSON.stringify(body)
23582
- });
23583
- const parsed = await res.json().catch(() => void 0);
23584
- return { status: res.status, body: parsed };
23585
- }
23586
- async function promptForKey(remote) {
23587
- const passwordMod = await Promise.resolve().then(() => (init_esm5(), esm_exports2));
23588
- const password = passwordMod.default;
23589
- const key = await password({ message: `API key for "${remote}":` });
23590
- storeApiKey(remote, key);
23591
- console.log(`Credentials stored for remote "${remote}".`);
23592
- }
23593
- async function browserLogin(remote, baseUrl) {
23594
- const device = await postJson(`${baseUrl.replace(/\/$/, "")}/platform/cli-auth/device`, {
23595
- clientLabel: clientLabel()
23596
- });
23597
- if (device.status === 404) {
23598
- console.log("This server does not support browser login yet \u2014 falling back to an API key.");
23599
- console.log("Create one in the web app under Param\xE8tres \u203A Cl\xE9s API.");
23600
- await promptForKey(remote);
23601
- return;
23602
- }
23603
- if (device.status >= 400) {
23604
- throw new Error(`Could not start the login flow (HTTP ${device.status}).`);
23605
- }
23606
- const auth = device.body;
23607
- console.log(`Opening ${auth.verificationUriComplete} in your browser\u2026`);
23608
- console.log(` Confirmation code: ${auth.userCode}`);
23609
- console.log(" (If the browser did not open, visit the URL above.)");
23610
- openBrowser(auth.verificationUriComplete);
23611
- const key = await pollForKey(baseUrl, auth);
23612
- storeApiKey(remote, key);
23613
- console.log(`Logged in to remote "${remote}". Credentials stored in ~/.wopilo/credentials.json.`);
23614
- }
23615
- async function pollForKey(baseUrl, auth) {
23616
- const tokenUrl = `${baseUrl.replace(/\/$/, "")}/platform/cli-auth/token`;
23617
- const deadline = Date.now() + auth.expiresIn * 1e3;
23618
- process.stdout.write("Waiting for approval\u2026 ");
23619
- while (Date.now() < deadline) {
23620
- await sleep(auth.interval * 1e3);
23621
- if (Date.now() >= deadline) break;
23622
- const res = await postJson(tokenUrl, { deviceCode: auth.deviceCode });
23623
- const result = res.body;
23624
- if (result?.status === "approved") {
23625
- console.log("\u2713");
23626
- return result.apiKey;
23627
- }
23628
- if (result?.status === "denied") {
23629
- console.log("\u2717");
23630
- throw new Error("Login was denied in the browser.");
23631
- }
23632
- if (result?.status === "expired") {
23633
- console.log("\u2717");
23634
- throw new Error("Login request expired. Run the command again.");
23635
- }
23636
- }
23637
- console.log("\u2717");
23638
- throw new Error("Login request expired. Run the command again.");
23639
- }
23640
23578
  function buildLoginCommand() {
23641
- return new Command("login").description("Log in to a remote server (opens your browser)").requiredOption("--remote <name>", "Remote alias").option("--with-key", "Paste an existing API key instead of using the browser (CI/headless)").action(async (opts) => {
23642
- const baseUrl = getRemoteUrl(opts.remote);
23643
- if (opts.withKey) {
23644
- await promptForKey(opts.remote);
23645
- return;
23646
- }
23647
- await browserLogin(opts.remote, baseUrl);
23579
+ return new Command("login").description("Store an API key for a remote server").requiredOption("--remote <name>", "Remote alias").action(async (opts) => {
23580
+ getRemoteUrl(opts.remote);
23581
+ const passwordMod = await Promise.resolve().then(() => (init_esm5(), esm_exports2));
23582
+ const password = passwordMod.default;
23583
+ const key = await password({ message: `API key for "${opts.remote}":` });
23584
+ storeApiKey(opts.remote, key);
23585
+ console.log(`Credentials stored for remote "${opts.remote}".`);
23648
23586
  });
23649
23587
  }
23650
23588