@acomo/cli 1.0.12 → 1.0.13

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
@@ -1,38 +1,23 @@
1
1
  #!/usr/bin/env node
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
3
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
+ }) : x)(function(x) {
6
+ if (typeof require !== "undefined") return require.apply(this, arguments);
7
+ throw Error('Dynamic require of "' + x + '" is not supported');
8
+ });
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
11
12
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
13
 
29
14
  // src/index.ts
30
- var import_fs6 = require("fs");
31
- var import_path6 = require("path");
32
- var import_url2 = require("url");
15
+ import { readFileSync as readFileSync4 } from "fs";
16
+ import { resolve as resolve5, dirname as dirname3 } from "path";
17
+ import { fileURLToPath as fileURLToPath2 } from "url";
33
18
 
34
19
  // ../node_modules/yargs/lib/platform-shims/esm.mjs
35
- var import_assert = require("assert");
20
+ import { notStrictEqual, strictEqual } from "assert";
36
21
 
37
22
  // ../node_modules/cliui/build/lib/index.js
38
23
  var align = {
@@ -323,30 +308,30 @@ function ui(opts) {
323
308
  }
324
309
 
325
310
  // ../node_modules/escalade/sync/index.mjs
326
- var import_path = require("path");
327
- var import_fs = require("fs");
311
+ import { dirname, resolve } from "path";
312
+ import { readdirSync, statSync } from "fs";
328
313
  function sync_default(start, callback) {
329
- let dir = (0, import_path.resolve)(".", start);
330
- let tmp, stats = (0, import_fs.statSync)(dir);
314
+ let dir = resolve(".", start);
315
+ let tmp, stats = statSync(dir);
331
316
  if (!stats.isDirectory()) {
332
- dir = (0, import_path.dirname)(dir);
317
+ dir = dirname(dir);
333
318
  }
334
319
  while (true) {
335
- tmp = callback(dir, (0, import_fs.readdirSync)(dir));
336
- if (tmp) return (0, import_path.resolve)(dir, tmp);
337
- dir = (0, import_path.dirname)(tmp = dir);
320
+ tmp = callback(dir, readdirSync(dir));
321
+ if (tmp) return resolve(dir, tmp);
322
+ dir = dirname(tmp = dir);
338
323
  if (tmp === dir) break;
339
324
  }
340
325
  }
341
326
 
342
327
  // ../node_modules/yargs/lib/platform-shims/esm.mjs
343
- var import_util3 = require("util");
344
- var import_fs4 = require("fs");
345
- var import_url = require("url");
328
+ import { inspect } from "util";
329
+ import { readFileSync as readFileSync3 } from "fs";
330
+ import { fileURLToPath } from "url";
346
331
 
347
332
  // ../node_modules/yargs-parser/build/lib/index.js
348
- var import_util = require("util");
349
- var import_path2 = require("path");
333
+ import { format } from "util";
334
+ import { normalize, resolve as resolve2 } from "path";
350
335
 
351
336
  // ../node_modules/yargs-parser/build/lib/string-utils.js
352
337
  function camelCase(str) {
@@ -1284,7 +1269,7 @@ function stripQuotes(val) {
1284
1269
  }
1285
1270
 
1286
1271
  // ../node_modules/yargs-parser/build/lib/index.js
1287
- var import_fs2 = require("fs");
1272
+ import { readFileSync } from "fs";
1288
1273
  var _a;
1289
1274
  var _b;
1290
1275
  var _c;
@@ -1302,16 +1287,16 @@ var parser = new YargsParser({
1302
1287
  env: () => {
1303
1288
  return env;
1304
1289
  },
1305
- format: import_util.format,
1306
- normalize: import_path2.normalize,
1307
- resolve: import_path2.resolve,
1290
+ format,
1291
+ normalize,
1292
+ resolve: resolve2,
1308
1293
  // TODO: figure out a way to combine ESM and CJS coverage, such that
1309
1294
  // we can exercise all the lines below:
1310
1295
  require: (path2) => {
1311
- if (typeof require !== "undefined") {
1312
- return require(path2);
1296
+ if (typeof __require !== "undefined") {
1297
+ return __require(path2);
1313
1298
  } else if (path2.match(/\.json$/)) {
1314
- return JSON.parse((0, import_fs2.readFileSync)(path2, "utf8"));
1299
+ return JSON.parse(readFileSync(path2, "utf8"));
1315
1300
  } else {
1316
1301
  throw Error("only .json config files are supported in ESM");
1317
1302
  }
@@ -1330,7 +1315,7 @@ yargsParser.looksLikeNumber = looksLikeNumber;
1330
1315
  var lib_default = yargsParser;
1331
1316
 
1332
1317
  // ../node_modules/yargs/lib/platform-shims/esm.mjs
1333
- var import_path4 = require("path");
1318
+ import { basename, dirname as dirname2, extname, relative, resolve as resolve4 } from "path";
1334
1319
 
1335
1320
  // ../node_modules/yargs/build/lib/utils/process-argv.js
1336
1321
  function getProcessArgvBinIndex() {
@@ -1363,19 +1348,19 @@ var YError = class _YError extends Error {
1363
1348
  };
1364
1349
 
1365
1350
  // ../node_modules/y18n/build/lib/platform-shims/node.js
1366
- var import_fs3 = require("fs");
1367
- var import_util2 = require("util");
1368
- var import_path3 = require("path");
1351
+ import { readFileSync as readFileSync2, statSync as statSync2, writeFile } from "fs";
1352
+ import { format as format2 } from "util";
1353
+ import { resolve as resolve3 } from "path";
1369
1354
  var node_default = {
1370
1355
  fs: {
1371
- readFileSync: import_fs3.readFileSync,
1372
- writeFile: import_fs3.writeFile
1356
+ readFileSync: readFileSync2,
1357
+ writeFile
1373
1358
  },
1374
- format: import_util2.format,
1375
- resolve: import_path3.resolve,
1359
+ format: format2,
1360
+ resolve: resolve3,
1376
1361
  exists: (file) => {
1377
1362
  try {
1378
- return (0, import_fs3.statSync)(file).isFile();
1363
+ return statSync2(file).isFile();
1379
1364
  } catch (err) {
1380
1365
  return false;
1381
1366
  }
@@ -1550,27 +1535,26 @@ var y18n2 = (opts) => {
1550
1535
  var y18n_default = y18n2;
1551
1536
 
1552
1537
  // ../node_modules/yargs/lib/platform-shims/esm.mjs
1553
- var import_meta = {};
1554
1538
  var REQUIRE_ERROR = "require is not supported by ESM";
1555
1539
  var REQUIRE_DIRECTORY_ERROR = "loading a directory of commands is not supported yet for ESM";
1556
- var __dirname2;
1540
+ var __dirname;
1557
1541
  try {
1558
- __dirname2 = (0, import_url.fileURLToPath)(import_meta.url);
1542
+ __dirname = fileURLToPath(import.meta.url);
1559
1543
  } catch (e) {
1560
- __dirname2 = process.cwd();
1544
+ __dirname = process.cwd();
1561
1545
  }
1562
- var mainFilename = __dirname2.substring(0, __dirname2.lastIndexOf("node_modules"));
1546
+ var mainFilename = __dirname.substring(0, __dirname.lastIndexOf("node_modules"));
1563
1547
  var esm_default = {
1564
1548
  assert: {
1565
- notStrictEqual: import_assert.notStrictEqual,
1566
- strictEqual: import_assert.strictEqual
1549
+ notStrictEqual,
1550
+ strictEqual
1567
1551
  },
1568
1552
  cliui: ui,
1569
1553
  findUp: sync_default,
1570
1554
  getEnv: (key) => {
1571
1555
  return process.env[key];
1572
1556
  },
1573
- inspect: import_util3.inspect,
1557
+ inspect,
1574
1558
  getCallerFile: () => {
1575
1559
  throw new YError(REQUIRE_DIRECTORY_ERROR);
1576
1560
  },
@@ -1578,11 +1562,11 @@ var esm_default = {
1578
1562
  mainFilename: mainFilename || process.cwd(),
1579
1563
  Parser: lib_default,
1580
1564
  path: {
1581
- basename: import_path4.basename,
1582
- dirname: import_path4.dirname,
1583
- extname: import_path4.extname,
1584
- relative: import_path4.relative,
1585
- resolve: import_path4.resolve
1565
+ basename,
1566
+ dirname: dirname2,
1567
+ extname,
1568
+ relative,
1569
+ resolve: resolve4
1586
1570
  },
1587
1571
  process: {
1588
1572
  argv: () => process.argv,
@@ -1593,7 +1577,7 @@ var esm_default = {
1593
1577
  nextTick: process.nextTick,
1594
1578
  stdColumns: typeof process.stdout.columns !== "undefined" ? process.stdout.columns : null
1595
1579
  },
1596
- readFileSync: import_fs4.readFileSync,
1580
+ readFileSync: readFileSync3,
1597
1581
  require: () => {
1598
1582
  throw new YError(REQUIRE_ERROR);
1599
1583
  },
@@ -1604,7 +1588,7 @@ var esm_default = {
1604
1588
  return [...str].length;
1605
1589
  },
1606
1590
  y18n: y18n_default({
1607
- directory: (0, import_path4.resolve)(__dirname2, "../../../locales"),
1591
+ directory: resolve4(__dirname, "../../../locales"),
1608
1592
  updateFiles: false
1609
1593
  })
1610
1594
  };
@@ -1815,10 +1799,10 @@ function isFunction(arg) {
1815
1799
 
1816
1800
  // ../node_modules/yargs/build/lib/utils/which-module.js
1817
1801
  function whichModule(exported) {
1818
- if (typeof require === "undefined")
1802
+ if (typeof __require === "undefined")
1819
1803
  return null;
1820
- for (let i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) {
1821
- mod = require.cache[files[i]];
1804
+ for (let i = 0, files = Object.keys(__require.cache), mod; i < files.length; i++) {
1805
+ mod = __require.cache[files[i]];
1822
1806
  if (mod.exports === exported)
1823
1807
  return mod;
1824
1808
  }
@@ -3343,7 +3327,7 @@ function applyExtends(config, cwd, mergeExtends, _shim) {
3343
3327
  let pathToDefault = null;
3344
3328
  if (!isPath) {
3345
3329
  try {
3346
- pathToDefault = require.resolve(config.extends);
3330
+ pathToDefault = __require.resolve(config.extends);
3347
3331
  } catch (_err) {
3348
3332
  return config;
3349
3333
  }
@@ -3352,7 +3336,7 @@ function applyExtends(config, cwd, mergeExtends, _shim) {
3352
3336
  }
3353
3337
  checkForCircularExtends(pathToDefault);
3354
3338
  previouslyVisitedConfigs.push(pathToDefault);
3355
- defaultConfig = isPath ? JSON.parse(shim2.readFileSync(pathToDefault, "utf8")) : require(config.extends);
3339
+ defaultConfig = isPath ? JSON.parse(shim2.readFileSync(pathToDefault, "utf8")) : __require(config.extends);
3356
3340
  delete config.extends;
3357
3341
  defaultConfig = applyExtends(defaultConfig, shim2.path.dirname(pathToDefault), mergeExtends, shim2);
3358
3342
  }
@@ -12115,32 +12099,35 @@ var textFieldType = (type) => {
12115
12099
  };
12116
12100
 
12117
12101
  // src/lib/config-store.ts
12118
- var import_fs5 = __toESM(require("fs"));
12119
- var import_path5 = __toESM(require("path"));
12120
- var import_os = __toESM(require("os"));
12121
- var CONFIG_DIR = import_path5.default.join(import_os.default.homedir(), ".acomo");
12122
- var CONFIG_FILE = import_path5.default.join(CONFIG_DIR, "config.json");
12102
+ import fs from "fs";
12103
+ import path from "path";
12104
+ import os from "os";
12105
+ var CONFIG_DIR = path.join(os.homedir(), ".acomo");
12106
+ var CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
12123
12107
  var ENV_KEYS = {
12124
12108
  baseUrl: "ACOMO_BASE_URL",
12125
12109
  tenantId: "ACOMO_TENANT_ID",
12126
- accessToken: "ACOMO_ACCESS_TOKEN",
12127
- email: "ACOMO_EMAIL"
12110
+ accessToken: "ACOMO_ACCESS_TOKEN"
12128
12111
  };
12112
+ var DEFAULT_BASE_URL = "https://acomo.app";
12129
12113
  function loadEnvConfig() {
12130
12114
  const env2 = {};
12131
12115
  if (process.env[ENV_KEYS.baseUrl]) env2.baseUrl = process.env[ENV_KEYS.baseUrl];
12132
12116
  if (process.env[ENV_KEYS.tenantId]) env2.tenantId = process.env[ENV_KEYS.tenantId];
12133
12117
  if (process.env[ENV_KEYS.accessToken]) env2.accessToken = process.env[ENV_KEYS.accessToken];
12134
- if (process.env[ENV_KEYS.email]) env2.email = process.env[ENV_KEYS.email];
12135
12118
  return env2;
12136
12119
  }
12137
12120
  function loadConfig() {
12138
12121
  try {
12139
- if (!import_fs5.default.existsSync(CONFIG_FILE)) {
12122
+ if (!fs.existsSync(CONFIG_FILE)) {
12140
12123
  return null;
12141
12124
  }
12142
- const content = import_fs5.default.readFileSync(CONFIG_FILE, "utf-8");
12143
- return JSON.parse(content);
12125
+ const content = fs.readFileSync(CONFIG_FILE, "utf-8");
12126
+ const raw = JSON.parse(content);
12127
+ const baseUrl = typeof raw.baseUrl === "string" ? raw.baseUrl : "";
12128
+ const tenantId = typeof raw.tenantId === "string" ? raw.tenantId : "";
12129
+ const accessToken = typeof raw.accessToken === "string" ? raw.accessToken : "";
12130
+ return { baseUrl, tenantId, accessToken };
12144
12131
  } catch (error) {
12145
12132
  return null;
12146
12133
  }
@@ -12152,10 +12139,9 @@ function resolveConfig() {
12152
12139
  return null;
12153
12140
  }
12154
12141
  const merged = {
12155
- baseUrl: envConfig.baseUrl ?? fileConfig?.baseUrl ?? "",
12142
+ baseUrl: (envConfig.baseUrl ?? fileConfig?.baseUrl ?? "").trim(),
12156
12143
  tenantId: envConfig.tenantId ?? fileConfig?.tenantId ?? "",
12157
- accessToken: envConfig.accessToken ?? fileConfig?.accessToken ?? "",
12158
- email: envConfig.email ?? fileConfig?.email
12144
+ accessToken: envConfig.accessToken ?? fileConfig?.accessToken ?? ""
12159
12145
  };
12160
12146
  if (!merged.accessToken || !merged.tenantId) {
12161
12147
  return null;
@@ -12163,36 +12149,45 @@ function resolveConfig() {
12163
12149
  return merged;
12164
12150
  }
12165
12151
  function saveConfig(config) {
12166
- if (!import_fs5.default.existsSync(CONFIG_DIR)) {
12167
- import_fs5.default.mkdirSync(CONFIG_DIR, { recursive: true });
12152
+ if (!fs.existsSync(CONFIG_DIR)) {
12153
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
12168
12154
  }
12169
- import_fs5.default.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), {
12155
+ fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), {
12170
12156
  mode: 384
12171
12157
  });
12172
12158
  }
12173
12159
  function clearConfig() {
12174
12160
  try {
12175
- if (import_fs5.default.existsSync(CONFIG_FILE)) {
12176
- import_fs5.default.unlinkSync(CONFIG_FILE);
12161
+ if (fs.existsSync(CONFIG_FILE)) {
12162
+ fs.unlinkSync(CONFIG_FILE);
12177
12163
  }
12178
12164
  } catch (error) {
12179
12165
  }
12180
12166
  }
12181
12167
 
12182
12168
  // src/lib/api-client.ts
12183
- function createConfiguration(options) {
12169
+ var REQUIRED_KEYS = [
12170
+ { key: "baseUrl", envKey: ENV_KEYS.baseUrl },
12171
+ { key: "tenantId", envKey: ENV_KEYS.tenantId },
12172
+ { key: "accessToken", envKey: ENV_KEYS.accessToken }
12173
+ ];
12174
+ function createConfiguration() {
12184
12175
  const config = resolveConfig();
12185
12176
  if (!config) {
12186
- throw new Error("\u8A8D\u8A3C\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002`acomo login` \u3092\u5B9F\u884C\u3059\u308B\u304B\u3001\u74B0\u5883\u5909\u6570 (ACOMO_ACCESS_TOKEN, ACOMO_TENANT_ID) \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
12177
+ throw new Error("\u8A8D\u8A3C\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002`acomo login` \u3092\u5B9F\u884C\u3059\u308B\u304B\u3001\u74B0\u5883\u5909\u6570 (ACOMO_ACCESS_TOKEN, ACOMO_TENANT_ID, ACOMO_BASE_URL) \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
12178
+ }
12179
+ const missing = REQUIRED_KEYS.filter(({ key }) => !config[key] || String(config[key]).trim() === "");
12180
+ if (missing.length > 0) {
12181
+ const keys = missing.map(({ key }) => key).join(", ");
12182
+ const envVars = missing.map(({ envKey }) => envKey).join(", ");
12183
+ const message = missing.length === 1 ? `${missing[0].key} \u304C\u672A\u8A2D\u5B9A\u3067\u3059\u3002\`acomo login\` \u3092\u5B9F\u884C\u3059\u308B\u304B\u3001\u74B0\u5883\u5909\u6570 ${missing[0].envKey} \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002` : `\u6B21\u306E\u8A2D\u5B9A\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059: ${keys}\u3002\`acomo login\` \u3092\u5B9F\u884C\u3059\u308B\u304B\u3001\u74B0\u5883\u5909\u6570 ${envVars} \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`;
12184
+ throw new Error(message);
12187
12185
  }
12188
12186
  const params = {
12189
12187
  basePath: config.baseUrl,
12190
12188
  accessToken: config.accessToken,
12191
12189
  apiKey: config.tenantId
12192
12190
  };
12193
- if (options?.accept === "text/plain") {
12194
- params.headers = { Accept: "text/plain" };
12195
- }
12196
12191
  return new Configuration(params);
12197
12192
  }
12198
12193
  function extractApiClasses() {
@@ -12221,7 +12216,7 @@ function buildOperationRegistry(config) {
12221
12216
  }
12222
12217
 
12223
12218
  // src/commands/login.ts
12224
- var readline = __toESM(require("readline"));
12219
+ import * as readline from "readline";
12225
12220
  function command2() {
12226
12221
  return "login";
12227
12222
  }
@@ -12229,125 +12224,80 @@ function describe() {
12229
12224
  return "acomo \u306B\u30ED\u30B0\u30A4\u30F3\u3057\u307E\u3059";
12230
12225
  }
12231
12226
  var helpOptions = [
12232
- { name: "url", type: "string", description: `Base URL (env: ${ENV_KEYS.baseUrl})` },
12233
- { name: "tenant-id", type: "string", description: `Tenant ID (env: ${ENV_KEYS.tenantId})` },
12234
- { name: "token", type: "string", description: `\u30A2\u30AF\u30BB\u30B9\u30C8\u30FC\u30AF\u30F3\uFF08\u76F4\u63A5\u6307\u5B9A\u3059\u308B\u5834\u5408\uFF09 (env: ${ENV_KEYS.accessToken})` },
12235
- { name: "email", type: "string", description: `\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9 (env: ${ENV_KEYS.email})` },
12236
- { name: "password", type: "string", description: "\u30D1\u30B9\u30EF\u30FC\u30C9" }
12227
+ { name: "base-url", type: "string", description: `baseUrl (env: ${ENV_KEYS.baseUrl})` },
12228
+ { name: "tenant-id", type: "string", description: `tenantId (env: ${ENV_KEYS.tenantId})` },
12229
+ { name: "access-token", type: "string", description: `accessToken (env: ${ENV_KEYS.accessToken})` }
12237
12230
  ];
12238
12231
  function builder(yargs) {
12239
- return yargs.option("url", {
12232
+ return yargs.option("base-url", {
12240
12233
  type: "string",
12241
- description: `Base URL (env: ${ENV_KEYS.baseUrl})`,
12242
- default: process.env[ENV_KEYS.baseUrl] || "https://acomo.app"
12234
+ description: `baseUrl (env: ${ENV_KEYS.baseUrl})`
12243
12235
  }).option("tenant-id", {
12244
12236
  type: "string",
12245
- description: `Tenant ID (env: ${ENV_KEYS.tenantId})`,
12237
+ description: `tenantId (env: ${ENV_KEYS.tenantId})`,
12246
12238
  default: process.env[ENV_KEYS.tenantId]
12247
- }).option("token", {
12239
+ }).option("access-token", {
12248
12240
  type: "string",
12249
- description: `\u30A2\u30AF\u30BB\u30B9\u30C8\u30FC\u30AF\u30F3\uFF08\u76F4\u63A5\u6307\u5B9A\u3059\u308B\u5834\u5408\uFF09 (env: ${ENV_KEYS.accessToken})`,
12241
+ description: `accessToken (env: ${ENV_KEYS.accessToken})`,
12250
12242
  default: process.env[ENV_KEYS.accessToken]
12251
- }).option("email", {
12252
- type: "string",
12253
- description: `\u30E1\u30FC\u30EB\u30A2\u30C9\u30EC\u30B9 (env: ${ENV_KEYS.email})`,
12254
- default: process.env[ENV_KEYS.email]
12255
- }).option("password", {
12256
- type: "string",
12257
- description: "\u30D1\u30B9\u30EF\u30FC\u30C9"
12258
12243
  });
12259
12244
  }
12260
- async function promptInput(question, hidden = false) {
12245
+ async function promptInput(question, defaultValue, displayDefault) {
12261
12246
  const rl = readline.createInterface({
12262
12247
  input: process.stdin,
12263
12248
  output: process.stdout
12264
12249
  });
12250
+ const shown = displayDefault !== void 0 ? displayDefault : defaultValue;
12251
+ const prompt = shown !== void 0 && shown !== "" ? `${question} [${shown}]: ` : `${question}: `;
12265
12252
  return new Promise((resolve6) => {
12266
- if (hidden) {
12267
- const stdin = process.stdin;
12268
- if (stdin.setRawMode) stdin.setRawMode(true);
12269
- process.stdout.write(question);
12270
- let password = "";
12271
- stdin.on("data", (char) => {
12272
- const c = char.toString();
12273
- if (c === "\n" || c === "\r" || c === "") {
12274
- stdin.pause();
12275
- if (stdin.setRawMode) stdin.setRawMode(false);
12276
- process.stdout.write("\n");
12277
- rl.close();
12278
- resolve6(password);
12279
- } else if (c === "") {
12280
- process.exit(130);
12281
- } else if (c === "\x7F") {
12282
- if (password.length > 0) {
12283
- password = password.slice(0, -1);
12284
- process.stdout.write("\b \b");
12285
- }
12286
- } else {
12287
- password += c;
12288
- process.stdout.write("*");
12289
- }
12290
- });
12291
- } else {
12292
- rl.question(question, (answer) => {
12293
- rl.close();
12294
- resolve6(answer);
12295
- });
12296
- }
12253
+ rl.question(prompt, (answer) => {
12254
+ rl.close();
12255
+ const trimmed = answer.trim();
12256
+ resolve6(trimmed !== "" ? trimmed : defaultValue ?? "");
12257
+ });
12297
12258
  });
12298
12259
  }
12260
+ function maskAccessToken(token) {
12261
+ return token && token.length > 10 ? `${token.slice(0, 10)}...` : token;
12262
+ }
12299
12263
  async function handler(argv) {
12300
12264
  try {
12301
- const url = argv.url || "https://acomo.app";
12302
- const tenantId = argv.tenantId;
12265
+ const existing = loadConfig();
12266
+ const defaultBaseUrl = argv.baseUrl ?? existing?.baseUrl ?? process.env[ENV_KEYS.baseUrl] ?? DEFAULT_BASE_URL;
12267
+ const defaultTenantId = argv.tenantId ?? existing?.tenantId ?? process.env[ENV_KEYS.tenantId] ?? "";
12268
+ const defaultAccessToken = argv.accessToken ?? existing?.accessToken ?? process.env[ENV_KEYS.accessToken] ?? "";
12269
+ let baseUrl;
12270
+ let tenantId;
12271
+ let accessToken;
12272
+ if (process.stdin.isTTY) {
12273
+ baseUrl = (await promptInput("baseUrl", defaultBaseUrl)).trim() || defaultBaseUrl;
12274
+ tenantId = (await promptInput("tenantId", defaultTenantId)).trim();
12275
+ accessToken = (await promptInput("accessToken", defaultAccessToken, maskAccessToken(defaultAccessToken))).trim();
12276
+ } else {
12277
+ baseUrl = defaultBaseUrl;
12278
+ tenantId = defaultTenantId;
12279
+ accessToken = defaultAccessToken;
12280
+ }
12303
12281
  if (!tenantId) {
12304
- console.error(`Tenant ID \u304C\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002--tenant-id \u30AA\u30D7\u30B7\u30E7\u30F3\u307E\u305F\u306F\u74B0\u5883\u5909\u6570 ${ENV_KEYS.tenantId} \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`);
12282
+ console.error(
12283
+ `tenantId \u304C\u6307\u5B9A\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002--tenant-id \u30AA\u30D7\u30B7\u30E7\u30F3\u307E\u305F\u306F\u74B0\u5883\u5909\u6570 ${ENV_KEYS.tenantId} \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
12284
+ );
12305
12285
  process.exit(1);
12306
12286
  }
12307
- if (argv.token) {
12308
- saveConfig({
12309
- baseUrl: url,
12310
- tenantId,
12311
- accessToken: argv.token,
12312
- email: argv.email
12313
- });
12314
- console.log("\u30A2\u30AF\u30BB\u30B9\u30C8\u30FC\u30AF\u30F3\u3092\u8A2D\u5B9A\u3057\u307E\u3057\u305F\u3002");
12315
- return;
12316
- }
12317
- let email = argv.email;
12318
- let password = argv.password;
12319
- if (!process.stdin.isTTY && (!email || !password)) {
12287
+ if (!accessToken) {
12320
12288
  console.error(
12321
- `\u975E\u30A4\u30F3\u30BF\u30E9\u30AF\u30C6\u30A3\u30D6\u74B0\u5883\u3067\u306F --token, --email, --password \u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\u3002
12322
- \u63A8\u5968: acomo login --tenant-id <id> --token <token>
12289
+ `\u975E\u30A4\u30F3\u30BF\u30E9\u30AF\u30C6\u30A3\u30D6\u74B0\u5883\u3067\u306F --access-token \u3068 --tenant-id\uFF08\u307E\u305F\u306F\u74B0\u5883\u5909\u6570\uFF09\u306E\u6307\u5B9A\u304C\u5FC5\u8981\u3067\u3059\u3002
12290
+ acomo login --tenant-id <id> --access-token <accessToken>
12323
12291
  \u307E\u305F\u306F\u74B0\u5883\u5909\u6570 ${ENV_KEYS.accessToken}, ${ENV_KEYS.tenantId} \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002`
12324
12292
  );
12325
12293
  process.exit(1);
12326
12294
  }
12327
- if (!email) {
12328
- email = await promptInput("Email: ");
12329
- }
12330
- if (!password) {
12331
- password = await promptInput("Password: ", true);
12332
- }
12333
- const config = new Configuration({
12334
- basePath: url
12335
- });
12336
- const authApi = new AuthApi(config);
12337
- const response = await authApi.signInWithEmailAndPassword({
12338
- signInDto: {
12339
- authTenantId: tenantId,
12340
- email,
12341
- password
12342
- }
12343
- });
12344
12295
  saveConfig({
12345
- baseUrl: url,
12296
+ baseUrl: baseUrl || DEFAULT_BASE_URL,
12346
12297
  tenantId,
12347
- accessToken: response.accessToken,
12348
- email
12298
+ accessToken
12349
12299
  });
12350
- console.log("\u30ED\u30B0\u30A4\u30F3\u306B\u6210\u529F\u3057\u307E\u3057\u305F\u3002");
12300
+ console.log("\u30ED\u30B0\u30A4\u30F3\u60C5\u5831\u3092\u8A2D\u5B9A\u3057\u307E\u3057\u305F\u3002");
12351
12301
  } catch (error) {
12352
12302
  console.error("\u30ED\u30B0\u30A4\u30F3\u306B\u5931\u6557\u3057\u307E\u3057\u305F:", error.message);
12353
12303
  process.exit(1);
@@ -12384,7 +12334,7 @@ function describe3() {
12384
12334
  }
12385
12335
  var helpPositionals = [
12386
12336
  { name: "subcommand", type: "string", required: true, description: "show | set" },
12387
- { name: "key", type: "string", required: false, description: "\u8A2D\u5B9A\u30AD\u30FC (baseUrl, tenantId, accessToken, email)\uFF08set \u6642\uFF09" },
12337
+ { name: "key", type: "string", required: false, description: "\u8A2D\u5B9A\u30AD\u30FC (baseUrl, tenantId, accessToken)\uFF08set \u6642\uFF09" },
12388
12338
  { name: "value", type: "string", required: false, description: "\u8A2D\u5B9A\u5024\uFF08set \u6642\uFF09" }
12389
12339
  ];
12390
12340
  var helpOptions3 = [];
@@ -12401,7 +12351,7 @@ function builder3(yargs) {
12401
12351
  "\u8A2D\u5B9A\u3092\u66F4\u65B0",
12402
12352
  (y) => y.positional("key", {
12403
12353
  type: "string",
12404
- description: "\u8A2D\u5B9A\u30AD\u30FC (baseUrl, tenantId, accessToken, email)"
12354
+ description: "\u8A2D\u5B9A\u30AD\u30FC (baseUrl, tenantId, accessToken)"
12405
12355
  }).positional("value", {
12406
12356
  type: "string",
12407
12357
  description: "\u8A2D\u5B9A\u5024"
@@ -12425,6 +12375,11 @@ async function showHandler(argv) {
12425
12375
  accessToken: config.accessToken ? `${config.accessToken.slice(0, 10)}...` : ""
12426
12376
  };
12427
12377
  console.log(JSON.stringify(masked, null, 2));
12378
+ if (!config.baseUrl || config.baseUrl.trim() === "") {
12379
+ console.error(
12380
+ "baseUrl \u304C\u672A\u8A2D\u5B9A\u3067\u3059\u3002API \u547C\u3073\u51FA\u3057\u304C\u5931\u6557\u3059\u308B\u53EF\u80FD\u6027\u304C\u3042\u308A\u307E\u3059\u3002`acomo login` \u3067\u8A2D\u5B9A\u3059\u308B\u304B\u3001\u74B0\u5883\u5909\u6570 ACOMO_BASE_URL \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
12381
+ );
12382
+ }
12428
12383
  } catch (error) {
12429
12384
  console.error("\u8A2D\u5B9A\u306E\u8AAD\u307F\u8FBC\u307F\u306B\u5931\u6557\u3057\u307E\u3057\u305F:", error.message);
12430
12385
  process.exit(1);
@@ -12438,7 +12393,7 @@ async function setHandler(argv) {
12438
12393
  process.exit(1);
12439
12394
  }
12440
12395
  const { key, value } = argv;
12441
- const allowedKeys = ["baseUrl", "tenantId", "accessToken", "email"];
12396
+ const allowedKeys = ["baseUrl", "tenantId", "accessToken"];
12442
12397
  if (!allowedKeys.includes(key)) {
12443
12398
  console.error(`\u7121\u52B9\u306A\u30AD\u30FC\u3067\u3059: ${key}`);
12444
12399
  console.error(`\u5229\u7528\u53EF\u80FD\u306A\u30AD\u30FC: ${allowedKeys.join(", ")}`);
@@ -13638,14 +13593,16 @@ function buildCommandHelp(params) {
13638
13593
  }
13639
13594
 
13640
13595
  // src/index.ts
13641
- var import_meta2 = {};
13642
- var scriptDir = typeof __dirname !== "undefined" ? __dirname : (0, import_path6.dirname)((0, import_url2.fileURLToPath)(import_meta2.url));
13596
+ var scriptDir = dirname3(fileURLToPath2(import.meta.url));
13643
13597
  var GLOBAL_OPTIONS2 = [
13644
- { name: "format", type: "string", description: "\u51FA\u529B\u5F62\u5F0F\uFF08API \u306E Accept \u30D8\u30C3\u30C0\u30FC\uFF09\u3002\u30D1\u30A4\u30D7\u6642\u306F json \u304C\u30C7\u30D5\u30A9\u30EB\u30C8\u3002", choices: ["text", "json"] },
13645
13598
  { name: "help", type: "boolean", description: "Show help" },
13646
13599
  { name: "version", type: "boolean", description: "Show version number" }
13647
13600
  ];
13648
- var OPTIONS_WITH_VALUE = /* @__PURE__ */ new Set(["-f", "--format", "--url", "--tenant-id", "--token", "--email", "--password"]);
13601
+ var OPTIONS_WITH_VALUE = /* @__PURE__ */ new Set([
13602
+ "--base-url",
13603
+ "--tenant-id",
13604
+ "--access-token"
13605
+ ]);
13649
13606
  function getHelpRequestedCommand(argv) {
13650
13607
  const args = argv.slice(2);
13651
13608
  let helpRequested = false;
@@ -13677,15 +13634,6 @@ var EXIT_CODES = {
13677
13634
  VALIDATION: 3,
13678
13635
  NOT_FOUND: 4
13679
13636
  };
13680
- function isJsonOutput() {
13681
- const args = process.argv;
13682
- const fIdx = args.indexOf("--format");
13683
- const fAliasIdx = args.indexOf("-f");
13684
- if (fIdx !== -1 && args[fIdx + 1] === "json") return true;
13685
- if (fAliasIdx !== -1 && args[fAliasIdx + 1] === "json") return true;
13686
- if (!process.stdout.isTTY && fIdx === -1 && fAliasIdx === -1) return true;
13687
- return false;
13688
- }
13689
13637
  async function resolveParams(positional) {
13690
13638
  if (positional) {
13691
13639
  try {
@@ -13715,7 +13663,8 @@ function placeholderForType(type) {
13715
13663
  if (type === "number" || type === "integer") return 0;
13716
13664
  if (type === "boolean") return false;
13717
13665
  if (type.includes("[]")) return [];
13718
- if (type === "object" || /[A-Z]/.test(type) || type.endsWith("Dto")) return {};
13666
+ if (type === "object" || /[A-Z]/.test(type) || type.endsWith("Dto"))
13667
+ return {};
13719
13668
  return "";
13720
13669
  }
13721
13670
  function buildExampleParams(params) {
@@ -13737,9 +13686,21 @@ function normalizeDescription(desc) {
13737
13686
  }
13738
13687
  function buildRootHelpDescriptor() {
13739
13688
  const commands = [
13740
- { name: command2(), kind: "builtin-command", summary: describe() },
13741
- { name: command3(), kind: "builtin-command", summary: describe2() },
13742
- { name: "config", kind: "builtin-command", summary: describe3() }
13689
+ {
13690
+ name: command2(),
13691
+ kind: "builtin-command",
13692
+ summary: describe()
13693
+ },
13694
+ {
13695
+ name: command3(),
13696
+ kind: "builtin-command",
13697
+ summary: describe2()
13698
+ },
13699
+ {
13700
+ name: "config",
13701
+ kind: "builtin-command",
13702
+ summary: describe3()
13703
+ }
13743
13704
  ];
13744
13705
  const config = resolveConfig();
13745
13706
  if (config) {
@@ -13764,7 +13725,7 @@ function buildBuiltinHelpDescriptor(cmd) {
13764
13725
  if (cmd === command2()) {
13765
13726
  summary = describe();
13766
13727
  options = [...helpOptions, ...GLOBAL_OPTIONS2];
13767
- exampleCommand = "acomo login --tenant-id <id> --token <token>";
13728
+ exampleCommand = "acomo login --tenant-id <tenantId> --access-token <accessToken>";
13768
13729
  } else if (cmd === command3()) {
13769
13730
  summary = describe2();
13770
13731
  options = [...helpOptions2, ...GLOBAL_OPTIONS2];
@@ -13818,14 +13779,21 @@ function buildApiCommandHelpDescriptor(operationId) {
13818
13779
  return entry;
13819
13780
  })
13820
13781
  } : null;
13821
- const minimalArgs = { ...buildExampleParams(paramInfo.params) };
13782
+ const minimalArgs = {
13783
+ ...buildExampleParams(paramInfo.params)
13784
+ };
13822
13785
  if (paramInfo.requestBody) {
13823
13786
  const bodyExample = buildExampleBody(paramInfo.requestBody.properties);
13824
13787
  for (const [k, v] of Object.entries(bodyExample)) minimalArgs[k] = v;
13825
13788
  }
13826
13789
  const exampleCommand = `acomo ${operationId} '${JSON.stringify(minimalArgs)}'`;
13827
13790
  const positionals = [
13828
- { name: "params", type: "object", required: false, description: "JSON \u30D1\u30E9\u30E1\u30FC\u30BF" }
13791
+ {
13792
+ name: "params",
13793
+ type: "object",
13794
+ required: false,
13795
+ description: "JSON \u30D1\u30E9\u30E1\u30FC\u30BF"
13796
+ }
13829
13797
  ];
13830
13798
  return buildCommandHelp({
13831
13799
  command: operationId,
@@ -13845,52 +13813,58 @@ function buildApiCommandHelpDescriptor(operationId) {
13845
13813
  exampleCommand
13846
13814
  });
13847
13815
  }
13848
- function handleError(error) {
13849
- const jsonMode = isJsonOutput();
13816
+ async function handleError(error) {
13817
+ const jsonMode = !process.stdout.isTTY;
13850
13818
  if (error.name === "ResponseError") {
13851
13819
  const status = error.response?.status || 0;
13852
13820
  const exitCode = status === 401 || status === 403 ? EXIT_CODES.AUTH : status === 404 ? EXIT_CODES.NOT_FOUND : EXIT_CODES.GENERAL;
13853
13821
  if (error.response) {
13854
- const contentType = error.response.headers?.get?.("content-type") ?? "";
13855
- const bodyPromise = contentType.includes("text/plain") ? error.response.text().then((t) => ({ message: t })) : error.response.json().catch(() => ({ message: error.message }));
13856
- bodyPromise.then((body) => {
13857
- if (jsonMode) {
13858
- const errObj = {
13859
- error: true,
13860
- code: status === 401 ? "AUTH_REQUIRED" : status === 403 ? "FORBIDDEN" : status === 404 ? "NOT_FOUND" : "API_ERROR",
13861
- status,
13862
- message: body.message ?? error.message,
13863
- ...status === 401 ? { suggestion: "`acomo login` \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002" } : {}
13864
- };
13865
- console.error(JSON.stringify(errObj));
13866
- } else {
13867
- console.error(`API \u30A8\u30E9\u30FC (${status})`);
13868
- console.error(
13869
- typeof body === "string" ? body : JSON.stringify(body, null, 2)
13870
- );
13871
- if (status === 401) {
13872
- console.error("\n`acomo login` \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
13873
- }
13874
- }
13875
- }).catch(() => {
13876
- if (jsonMode) {
13877
- console.error(
13878
- JSON.stringify({
13879
- error: true,
13880
- code: "API_ERROR",
13881
- status,
13882
- message: error.message
13883
- })
13884
- );
13885
- } else {
13886
- console.error(error.message);
13822
+ let body;
13823
+ try {
13824
+ body = await error.response.json();
13825
+ } catch {
13826
+ body = { message: error.message };
13827
+ }
13828
+ if (jsonMode) {
13829
+ const errObj = {
13830
+ error: true,
13831
+ code: status === 401 ? "AUTH_REQUIRED" : status === 403 ? "FORBIDDEN" : status === 404 ? "NOT_FOUND" : "API_ERROR",
13832
+ status,
13833
+ message: body.message ?? error.message,
13834
+ ...status === 401 ? { suggestion: "`acomo login` \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002" } : {}
13835
+ };
13836
+ console.error(JSON.stringify(errObj));
13837
+ } else {
13838
+ console.error(`API \u30A8\u30E9\u30FC (${status})`);
13839
+ console.error(
13840
+ typeof body === "string" ? body : JSON.stringify(body, null, 2)
13841
+ );
13842
+ if (status === 401) {
13843
+ console.error("\n`acomo login` \u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002");
13887
13844
  }
13888
- }).finally(() => {
13889
- process.exit(exitCode);
13890
- });
13891
- return process.exit(exitCode);
13845
+ }
13846
+ process.exit(exitCode);
13892
13847
  }
13893
13848
  }
13849
+ if (error.name === "FetchError") {
13850
+ const message = "\u63A5\u7D9A\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002baseUrl\uFF08ACOMO_BASE_URL\uFF09\u3068\u30CD\u30C3\u30C8\u30EF\u30FC\u30AF\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002";
13851
+ if (jsonMode) {
13852
+ console.error(
13853
+ JSON.stringify({
13854
+ error: true,
13855
+ code: "CONNECTION_ERROR",
13856
+ message,
13857
+ suggestion: "`acomo login` \u3067 baseUrl \u3092\u8A2D\u5B9A\u3059\u308B\u304B\u3001\u74B0\u5883\u5909\u6570 ACOMO_BASE_URL \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
13858
+ })
13859
+ );
13860
+ } else {
13861
+ console.error(message);
13862
+ console.error(
13863
+ "\n`acomo login` \u3067 baseUrl \u3092\u8A2D\u5B9A\u3059\u308B\u304B\u3001\u74B0\u5883\u5909\u6570 ACOMO_BASE_URL \u3092\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002"
13864
+ );
13865
+ }
13866
+ process.exit(EXIT_CODES.GENERAL);
13867
+ }
13894
13868
  if (error.name === "RequiredError") {
13895
13869
  if (jsonMode) {
13896
13870
  console.error(
@@ -13953,15 +13927,9 @@ async function main() {
13953
13927
  process.exit(0);
13954
13928
  }
13955
13929
  const pkg = JSON.parse(
13956
- (0, import_fs6.readFileSync)((0, import_path6.resolve)(scriptDir, "../package.json"), "utf-8")
13930
+ readFileSync4(resolve5(scriptDir, "../package.json"), "utf-8")
13957
13931
  );
13958
- const argv = yargs_default(hideBin(process.argv)).scriptName("acomo").usage("Usage: $0 <command> [options]").option("format", {
13959
- alias: "f",
13960
- type: "string",
13961
- description: "\u51FA\u529B\u5F62\u5F0F\uFF08API \u306E Accept \u30D8\u30C3\u30C0\u30FC\uFF09\u3002\u30D1\u30A4\u30D7\u6642\u306F json \u304C\u30C7\u30D5\u30A9\u30EB\u30C8\u3002",
13962
- choices: ["text", "json"],
13963
- default: process.stdout.isTTY ? "text" : "json"
13964
- }).help().alias("h", "help").version(pkg.version).alias("v", "version");
13932
+ const argv = yargs_default(hideBin(process.argv)).scriptName("acomo").usage("Usage: $0 <command> [options]").help().alias("h", "help").version(pkg.version).alias("v", "version");
13965
13933
  argv.command(
13966
13934
  command2(),
13967
13935
  describe(),
@@ -13999,18 +13967,27 @@ async function main() {
13999
13967
  },
14000
13968
  async (cmdArgv) => {
14001
13969
  try {
14002
- const params = await resolveParams(cmdArgv.params);
13970
+ const params = await resolveParams(
13971
+ cmdArgv.params
13972
+ );
14003
13973
  const entry = registry.get(operationId);
14004
- const format3 = cmdArgv.format ?? "text";
14005
- const apiConfig = createConfiguration(
14006
- format3 === "text" ? { accept: "text/plain" } : void 0
13974
+ const apiConfig = createConfiguration();
13975
+ const instance = new entry.instance.constructor(
13976
+ apiConfig
14007
13977
  );
14008
- const instance = new entry.instance.constructor(apiConfig);
14009
- const rawResponse = await instance[entry.method + "Raw"](params ?? {});
13978
+ const rawResponse = await instance[entry.method + "Raw"](
13979
+ params ?? {}
13980
+ );
13981
+ if (!rawResponse.raw.ok) {
13982
+ throw new ResponseError(
13983
+ rawResponse.raw,
13984
+ "Response returned an error code"
13985
+ );
13986
+ }
14010
13987
  const text = await rawResponse.raw.text();
14011
13988
  process.stdout.write(text + "\n");
14012
13989
  } catch (error) {
14013
- handleError(error);
13990
+ await handleError(error);
14014
13991
  }
14015
13992
  }
14016
13993
  );
@@ -14020,8 +13997,8 @@ async function main() {
14020
13997
  }
14021
13998
  argv.demandCommand(1, "\u30B3\u30DE\u30F3\u30C9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002").strict().parse();
14022
13999
  }
14023
- main().catch((error) => {
14024
- handleError(error);
14000
+ main().catch(async (error) => {
14001
+ await handleError(error);
14025
14002
  });
14026
14003
  /*! Bundled license information:
14027
14004