@dashai/cli 0.6.0 → 0.7.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/bin.js CHANGED
@@ -1873,7 +1873,7 @@ async function selectWorkspace(opts) {
1873
1873
  if (workspaces.length === 1) {
1874
1874
  return workspaces[0];
1875
1875
  }
1876
- if (process.stdout.isTTY) {
1876
+ if (opts.interactive && process.stdout.isTTY) {
1877
1877
  const choice = await select({
1878
1878
  message: "Which workspace should this module live in?",
1879
1879
  options: workspaces.map((w) => ({
@@ -4064,7 +4064,7 @@ function scanOutboundHosts(dir) {
4064
4064
  const abs = join(dir, d);
4065
4065
  if (existsSync(abs)) walk2(abs);
4066
4066
  }
4067
- return Array.from(hosts).sort();
4067
+ return Array.from(hosts, (h) => `https://${h}`).sort();
4068
4068
  }
4069
4069
  async function moduleConvertCommand(opts) {
4070
4070
  try {
@@ -4108,6 +4108,112 @@ async function moduleConvertCommand(opts) {
4108
4108
  }
4109
4109
  }
4110
4110
 
4111
+ // src/commands/module/register.ts
4112
+ init_config();
4113
+ init_output();
4114
+ init_manifest_io();
4115
+ init_workspaces();
4116
+ init_api_client();
4117
+ var MODULE_KINDS = ["ai_builder", "hand_authored", "custom"];
4118
+ async function moduleRegisterCommand(opts) {
4119
+ let manifest;
4120
+ try {
4121
+ manifest = readManifest(opts.dir);
4122
+ } catch (err) {
4123
+ fail(`Could not read module.json: ${err.message}`);
4124
+ return 1;
4125
+ }
4126
+ if (!manifest) {
4127
+ fail(
4128
+ `No module.json found${opts.dir ? ` in ${opts.dir}` : " in the current directory"}. Run ${code("dashwise module convert")} (existing app) or ${code("dashwise init")} (new) first.`
4129
+ );
4130
+ return 1;
4131
+ }
4132
+ const slug = manifest.module?.slug;
4133
+ if (!slug || typeof slug !== "string") {
4134
+ fail("module.json is missing `module.slug`.");
4135
+ return 1;
4136
+ }
4137
+ const name = opts.name ?? (typeof manifest.module?.name === "string" ? manifest.module.name : slug);
4138
+ const moduleKind = MODULE_KINDS.includes(
4139
+ manifest.module_kind
4140
+ ) ? manifest.module_kind : void 0;
4141
+ const description = typeof manifest.module?.description === "string" ? manifest.module.description : void 0;
4142
+ if (!isLoggedIn()) {
4143
+ fail(`Not logged in. Run ${code("dashwise login")} first.`);
4144
+ return 1;
4145
+ }
4146
+ const cfg = readConfig();
4147
+ if (!cfg) {
4148
+ fail(`CLI config missing. Run ${code("dashwise login")}.`);
4149
+ return 1;
4150
+ }
4151
+ let workspace2;
4152
+ try {
4153
+ workspace2 = await selectWorkspace({
4154
+ apiUrl: resolveApiUrl(),
4155
+ apiToken: cfg.token,
4156
+ ...opts.workspace !== void 0 ? { flag: opts.workspace } : {},
4157
+ interactive: true
4158
+ });
4159
+ } catch (err) {
4160
+ fail(`Workspace selection failed: ${err.message}`);
4161
+ return 1;
4162
+ }
4163
+ info(
4164
+ `Registering "${name}" (slug: ${code(slug)}) in workspace ${code(workspace2.slug)} (id=${workspace2.id})\u2026`
4165
+ );
4166
+ let response;
4167
+ try {
4168
+ response = await createDevInstallation(
4169
+ {
4170
+ slug,
4171
+ name,
4172
+ ...description !== void 0 ? { description } : {},
4173
+ workspaceId: workspace2.id,
4174
+ ...moduleKind !== void 0 ? { moduleKind } : {}
4175
+ },
4176
+ { baseUrl: resolveApiUrl(), auth: { token: cfg.token } }
4177
+ );
4178
+ } catch (err) {
4179
+ if (err instanceof ApiError) {
4180
+ if (err.code === "SLUG_ALREADY_EXISTS") {
4181
+ fail(
4182
+ `A module with slug "${slug}" already exists. Pick a different slug in module.json, or run ${code("dashwise module destroy-dev-install")} to reclaim it.`
4183
+ );
4184
+ } else if (err.code === "FORBIDDEN") {
4185
+ fail(`Not a member of workspace "${workspace2.slug}". Join it, then retry.`);
4186
+ } else {
4187
+ fail(`Registration failed (${err.code || err.status}): ${err.message}`);
4188
+ }
4189
+ return 1;
4190
+ }
4191
+ fail(`Registration failed: ${err.message}`);
4192
+ return 1;
4193
+ }
4194
+ try {
4195
+ upsertModuleEntry(slug, {
4196
+ runtimeToken: response.runtime_token,
4197
+ installationId: response.installation.id,
4198
+ expiresAt: response.runtime_token_expires_at
4199
+ });
4200
+ } catch (err) {
4201
+ warn(
4202
+ `Registered (installation id=${response.installation.id}) but failed to cache the runtime token: ${err.message}
4203
+ Runtime token (save this manually): ${response.runtime_token}
4204
+ Expires: ${response.runtime_token_expires_at}`
4205
+ );
4206
+ return 0;
4207
+ }
4208
+ success(
4209
+ `Registered "${name}" \u2192 module #${response.module.id}, dev install #${response.installation.id}. Runtime token cached.`
4210
+ );
4211
+ info(
4212
+ `Next: ${code("dashwise dev")} to run it against DashWise, or ${code("dashwise module publish")} to deploy. Add tables with ${code("dashwise table create")}.`
4213
+ );
4214
+ return 0;
4215
+ }
4216
+
4111
4217
  // src/commands/module/generate.ts
4112
4218
  init_api_client();
4113
4219
  init_output();
@@ -6650,6 +6756,17 @@ moduleCmd.command("convert [dir]").description(
6650
6756
  });
6651
6757
  }
6652
6758
  );
6759
+ moduleCmd.command("register [dir]").description(
6760
+ "Link an existing local module (a directory with module.json \u2014 e.g. after `module convert`) to DashWise: creates the backend module record + a dev install and caches the runtime token, so `dashwise dev` / `publish` work. Requires login."
6761
+ ).option("--workspace <slug-or-id>", "Target workspace (default: interactive picker).").option("--name <name>", "Override the module name (default: module.json name).").action(
6762
+ async (dir, cmdOpts) => {
6763
+ process.exitCode = await moduleRegisterCommand({
6764
+ ...dir !== void 0 ? { dir } : {},
6765
+ ...cmdOpts.workspace !== void 0 ? { workspace: cmdOpts.workspace } : {},
6766
+ ...cmdOpts.name !== void 0 ? { name: cmdOpts.name } : {}
6767
+ });
6768
+ }
6769
+ );
6653
6770
  moduleCmd.command("generate").description("Regenerate typed wrappers from the local module.json into node_modules/@dashai/generated/.").option("--dir <path>", "Project root (default: current directory).").option("--dry-run", "Print summary without writing files.").action(async (cmdOpts) => {
6654
6771
  process.exitCode = await moduleGenerateCommand({
6655
6772
  ...cmdOpts.dir !== void 0 ? { dir: cmdOpts.dir } : {},
@@ -7015,7 +7132,7 @@ fieldCmd.command("set-type <table-slug> <field-slug> <new-type>").description(
7015
7132
  }
7016
7133
  })();
7017
7134
  function getVersion() {
7018
- return "0.6.0";
7135
+ return "0.7.1";
7019
7136
  }
7020
7137
  function parseIntOption(value) {
7021
7138
  const n = Number.parseInt(value, 10);