import {
  getBaseUrl,
  safeFetchJson
} from "./chunk-QZBSRYSW.js";
import "./chunk-NROPRHIC.js";
import {
  ensureProtocol
} from "./chunk-FB5CMO3J.js";
import {
  fromNeverthrowError,
  outputAndExit,
  successResponse
} from "./chunk-7EBJ4BCH.js";
import {
  ok
} from "./chunk-C7KWYVS3.js";

// src/operations/register.ts
import { z } from "zod";
var registerResponseSchema = z.object({
  origin: z.object({
    id: z.string(),
    origin: z.string(),
    name: z.string()
  }),
  resourceCount: z.number()
});
async function registerOrigin(surface, input, flags) {
  const url = ensureProtocol(input.url);
  const result = await safeFetchJson(
    surface,
    new Request(`${getBaseUrl(flags.dev)}/api/register`, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ url })
    }),
    registerResponseSchema
  );
  if (result.isErr()) {
    return result;
  }
  return ok(result.value);
}

// src/cli/commands/register.ts
var SURFACE = "cli:register";
var registerCommand = async (args) => {
  const result = await registerOrigin(SURFACE, args, args);
  if (result.isErr()) {
    return outputAndExit(fromNeverthrowError(result), args);
  }
  const { origin, resourceCount } = result.value;
  return outputAndExit(
    successResponse({
      origin,
      resourceCount
    }),
    args
  );
};
export {
  registerCommand
};
//# sourceMappingURL=register-NAPAV4G7.js.map