@lobehub/market-cli 0.0.1 → 0.0.3

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/cli.js CHANGED
@@ -179,14 +179,20 @@ function getPrimaryMacAddress() {
179
179
 
180
180
  // src/commands/register.ts
181
181
  function registerRegisterCommand(program2) {
182
- program2.command("register").description("Register this device as an M2M client and save credentials locally").requiredOption("--name <name>", "Client name for registration").option("--type <type>", "Client type (desktop|mobile|web|server|docker)", "desktop").option("--device-id <id>", "Device identifier (auto-generated if omitted)").option("--base-url <url>", "Market API base URL", "https://market.lobehub.com").option("--output <format>", "Output format (text|json)", "text").action(async (options) => {
182
+ program2.command("register").description("Register this device as an M2M client and save credentials locally").requiredOption("--name <name>", "Client name for registration").option("--description <desc>", "Description of the client").option(
183
+ "--source <source>",
184
+ "Agent source, lowercase with hyphens (e.g. claude-code, open-claw, codex, cursor)"
185
+ ).option("--device-id <id>", "Device identifier (auto-generated if omitted)").option("--base-url <url>", "Market API base URL", "https://market.lobehub.com").option("--output <format>", "Output format (text|json)", "text").action(async (options) => {
183
186
  try {
184
187
  const deviceId = options.deviceId || generateDeviceId();
185
188
  const baseURL = process.env.MARKET_BASE_URL || options.baseUrl;
189
+ const source = options.source;
190
+ const description = [options.description, source && `source: ${source}`].filter(Boolean).join(". ");
186
191
  const sdk = new MarketSDK2({ baseURL });
187
192
  const result = await sdk.auth.registerClient({
188
193
  clientName: options.name,
189
- clientType: options.type,
194
+ clientType: "cli",
195
+ description: description || void 0,
190
196
  deviceId,
191
197
  platform: process.arch,
192
198
  version: process.version
@@ -195,10 +201,10 @@ function registerRegisterCommand(program2) {
195
201
  baseUrl: baseURL,
196
202
  clientId: result.client_id,
197
203
  clientSecret: result.client_secret,
198
- clientType: options.type,
199
204
  deviceId,
200
205
  name: options.name,
201
- registeredAt: (/* @__PURE__ */ new Date()).toISOString()
206
+ registeredAt: (/* @__PURE__ */ new Date()).toISOString(),
207
+ source
202
208
  });
203
209
  formatOutput(options.output, {
204
210
  clientId: result.client_id,
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../src/commands/auth.ts","../src/utils/config.ts","../src/utils/credentials.ts","../src/utils/output.ts","../src/commands/register.ts","../src/utils/deviceId.ts"],"sourcesContent":["import { createRequire } from 'node:module';\n\nimport { Command } from 'commander';\n\nimport { registerAuthCommand } from './commands/auth';\nimport { registerRegisterCommand } from './commands/register';\n\nconst require = createRequire(import.meta.url);\nconst pkg = require('../package.json');\n\nconst program = new Command();\n\nprogram\n .name('lobehub-market')\n .description('LobeHub Market CLI - Device registration and auth management')\n .version(pkg.version);\n\nregisterRegisterCommand(program);\nregisterAuthCommand(program);\n\nprogram.parse();\n","import type { Command } from 'commander';\nimport { MarketSDK } from '@lobehub/market-sdk';\n\nimport { resolveConfig } from '../utils/config';\nimport { deleteCredentials } from '../utils/credentials';\nimport { formatOutput } from '../utils/output';\n\nexport function registerAuthCommand(program: Command): void {\n const auth = program\n .command('auth')\n .description('Manage authentication credentials and tokens');\n\n auth\n .command('status')\n .description('Show credential and token status')\n .option('--output <format>', 'Output format (text|json)', 'text')\n .action(async (options) => {\n try {\n const config = resolveConfig();\n\n if (!config.clientId || !config.clientSecret) {\n console.error(\n 'No credentials found. Run `lobehub-market register` first or set MARKET_CLIENT_ID and MARKET_CLIENT_SECRET.',\n );\n process.exit(1);\n }\n\n const sdk = new MarketSDK({\n baseURL: config.baseUrl,\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n });\n\n const tokenInfo = await sdk.fetchM2MToken();\n\n formatOutput(options.output, {\n baseUrl: config.baseUrl,\n clientId: config.clientId,\n expiresIn: `${tokenInfo.expiresIn}s`,\n source: config.source,\n status: 'authenticated',\n tokenPreview: `${tokenInfo.accessToken.slice(0, 12)}...`,\n });\n } catch (error: any) {\n console.error(`Auth status check failed: ${error.message}`);\n process.exit(1);\n }\n });\n\n auth\n .command('refresh')\n .description('Force refresh the M2M access token')\n .option('--output <format>', 'Output format (text|json)', 'text')\n .action(async (options) => {\n try {\n const config = resolveConfig();\n\n if (!config.clientId || !config.clientSecret) {\n console.error(\n 'No credentials found. Run `lobehub-market register` first or set MARKET_CLIENT_ID and MARKET_CLIENT_SECRET.',\n );\n process.exit(1);\n }\n\n const sdk = new MarketSDK({\n baseURL: config.baseUrl,\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n });\n\n const tokenInfo = await sdk.fetchM2MToken();\n\n formatOutput(options.output, {\n accessToken: tokenInfo.accessToken,\n expiresIn: tokenInfo.expiresIn,\n message: 'Token refreshed successfully',\n });\n } catch (error: any) {\n console.error(`Token refresh failed: ${error.message}`);\n process.exit(1);\n }\n });\n\n auth\n .command('logout')\n .description('Clear local credentials')\n .action(async () => {\n try {\n const deleted = await deleteCredentials();\n if (deleted) {\n console.log('Credentials cleared successfully.');\n } else {\n console.log('No credentials file found.');\n }\n } catch (error: any) {\n console.error(`Logout failed: ${error.message}`);\n process.exit(1);\n }\n });\n}\n","import { existsSync, readFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\nexport interface ResolvedConfig {\n baseUrl: string;\n clientId: string | undefined;\n clientSecret: string | undefined;\n source: 'env' | 'file' | 'mixed' | 'none';\n}\n\nexport function resolveConfig(): ResolvedConfig {\n const envClientId = process.env.MARKET_CLIENT_ID;\n const envClientSecret = process.env.MARKET_CLIENT_SECRET;\n const envBaseUrl = process.env.MARKET_BASE_URL;\n\n let fileCredentials: { baseUrl?: string; clientId?: string; clientSecret?: string } | null = null;\n\n try {\n const filePath = join(homedir(), '.lobehub-market', 'credentials.json');\n if (existsSync(filePath)) {\n const content = readFileSync(filePath, 'utf-8');\n fileCredentials = JSON.parse(content);\n }\n } catch {\n // Ignore file read errors\n }\n\n const clientId = envClientId || fileCredentials?.clientId;\n const clientSecret = envClientSecret || fileCredentials?.clientSecret;\n const baseUrl = envBaseUrl || fileCredentials?.baseUrl || 'https://market.lobehub.com';\n\n let source: ResolvedConfig['source'] = 'none';\n if (clientId && clientSecret) {\n const idFromEnv = !!envClientId;\n const secretFromEnv = !!envClientSecret;\n\n if (idFromEnv && secretFromEnv) {\n source = 'env';\n } else if (!idFromEnv && !secretFromEnv) {\n source = 'file';\n } else {\n source = 'mixed';\n }\n }\n\n return { baseUrl, clientId, clientSecret, source };\n}\n","import { existsSync } from 'node:fs';\nimport { mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\nexport interface StoredCredentials {\n baseUrl: string;\n clientId: string;\n clientSecret: string;\n clientType: string;\n deviceId: string;\n name: string;\n registeredAt: string;\n}\n\nconst CREDENTIALS_DIR = join(homedir(), '.lobehub-market');\nconst CREDENTIALS_FILE = join(CREDENTIALS_DIR, 'credentials.json');\n\nexport async function saveCredentials(credentials: StoredCredentials): Promise<void> {\n if (!existsSync(CREDENTIALS_DIR)) {\n await mkdir(CREDENTIALS_DIR, { mode: 0o700, recursive: true });\n }\n\n const content = JSON.stringify(credentials, null, 2);\n await writeFile(CREDENTIALS_FILE, content, { encoding: 'utf-8', mode: 0o600 });\n}\n\nexport async function loadCredentials(): Promise<StoredCredentials | null> {\n if (!existsSync(CREDENTIALS_FILE)) {\n return null;\n }\n\n const content = await readFile(CREDENTIALS_FILE, 'utf-8');\n return JSON.parse(content) as StoredCredentials;\n}\n\nexport async function deleteCredentials(): Promise<boolean> {\n if (!existsSync(CREDENTIALS_FILE)) {\n return false;\n }\n\n await rm(CREDENTIALS_FILE);\n return true;\n}\n\nexport function getCredentialsPath(): string {\n return CREDENTIALS_FILE;\n}\n","export function formatOutput(format: string, data: Record<string, unknown>): void {\n if (format === 'json') {\n console.log(JSON.stringify(data, null, 2));\n return;\n }\n\n for (const [key, value] of Object.entries(data)) {\n const label = key\n .replaceAll(/([A-Z])/g, ' $1')\n .replace(/^./, (s) => s.toUpperCase())\n .trim();\n console.log(` ${label}: ${value}`);\n }\n}\n","import type { Command } from 'commander';\nimport { MarketSDK } from '@lobehub/market-sdk';\n\nimport { getCredentialsPath, saveCredentials } from '../utils/credentials';\nimport { generateDeviceId } from '../utils/deviceId';\nimport { formatOutput } from '../utils/output';\n\nexport function registerRegisterCommand(program: Command): void {\n program\n .command('register')\n .description('Register this device as an M2M client and save credentials locally')\n .requiredOption('--name <name>', 'Client name for registration')\n .option('--type <type>', 'Client type (desktop|mobile|web|server|docker)', 'desktop')\n .option('--device-id <id>', 'Device identifier (auto-generated if omitted)')\n .option('--base-url <url>', 'Market API base URL', 'https://market.lobehub.com')\n .option('--output <format>', 'Output format (text|json)', 'text')\n .action(async (options) => {\n try {\n const deviceId = options.deviceId || generateDeviceId();\n const baseURL = process.env.MARKET_BASE_URL || options.baseUrl;\n\n const sdk = new MarketSDK({ baseURL });\n\n const result = await sdk.auth.registerClient({\n clientName: options.name,\n clientType: options.type,\n deviceId,\n platform: process.arch,\n version: process.version,\n });\n\n await saveCredentials({\n baseUrl: baseURL,\n clientId: result.client_id,\n clientSecret: result.client_secret,\n clientType: options.type,\n deviceId,\n name: options.name,\n registeredAt: new Date().toISOString(),\n });\n\n formatOutput(options.output, {\n clientId: result.client_id,\n credentialsPath: getCredentialsPath(),\n message: result.message || 'Client registered successfully',\n });\n } catch (error: any) {\n console.error(`Registration failed: ${error.message}`);\n process.exit(1);\n }\n });\n}\n","import { createHash } from 'node:crypto';\nimport { hostname, networkInterfaces } from 'node:os';\n\nexport function generateDeviceId(): string {\n const host = hostname();\n const mac = getPrimaryMacAddress();\n\n const input = mac ? `${host}:${mac}` : host;\n const hash = createHash('sha256').update(input).digest('hex').slice(0, 16);\n\n return `device-${hash}`;\n}\n\nfunction getPrimaryMacAddress(): string | undefined {\n const interfaces = networkInterfaces();\n\n for (const name of Object.keys(interfaces).sort()) {\n const entries = interfaces[name];\n if (!entries) continue;\n\n for (const entry of entries) {\n if (entry.internal) continue;\n if (entry.mac === '00:00:00:00:00:00') continue;\n\n return entry.mac;\n }\n }\n\n return undefined;\n}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;AAAA,QACpB;AAAA,QACA,UAAU,QAAQ;AAAA,QAClB,SAAS,QAAQ;AAAA,MACnB,CAAC;AAED,YAAM,gBAAgB;AAAA,QACpB,SAAS;AAAA,QACT,UAAU,OAAO;AAAA,QACjB,cAAc,OAAO;AAAA,QACrB,YAAY,QAAQ;AAAA,QACpB;AAAA,QACA,MAAM,QAAQ;AAAA,QACd,eAAc,oBAAI,KAAK,GAAE,YAAY;AAAA,MACvC,CAAC;AAED,mBAAa,QAAQ,QAAQ;AAAA,QAC3B,UAAU,OAAO;AAAA,QACjB,iBAAiB,mBAAmB;AAAA,QACpC,SAAS,OAAO,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH,SAAS,OAAY;AACnB,cAAQ,MAAM,wBAAwB,MAAM,OAAO,EAAE;AACrD,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,CAAC;AACL;;;AL5CA,IAAMC,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,MAAMA,SAAQ,iBAAiB;AAErC,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,gBAAgB,EACrB,YAAY,8DAA8D,EAC1E,QAAQ,IAAI,OAAO;AAEtB,wBAAwB,OAAO;AAC/B,oBAAoB,OAAO;AAE3B,QAAQ,MAAM;","names":["existsSync","homedir","join","existsSync","program","MarketSDK","program","MarketSDK","require"]}
1
+ {"version":3,"sources":["../src/cli.ts","../src/commands/auth.ts","../src/utils/config.ts","../src/utils/credentials.ts","../src/utils/output.ts","../src/commands/register.ts","../src/utils/deviceId.ts"],"sourcesContent":["import { createRequire } from 'node:module';\n\nimport { Command } from 'commander';\n\nimport { registerAuthCommand } from './commands/auth';\nimport { registerRegisterCommand } from './commands/register';\n\nconst require = createRequire(import.meta.url);\nconst pkg = require('../package.json');\n\nconst program = new Command();\n\nprogram\n .name('lobehub-market')\n .description('LobeHub Market CLI - Device registration and auth management')\n .version(pkg.version);\n\nregisterRegisterCommand(program);\nregisterAuthCommand(program);\n\nprogram.parse();\n","import type { Command } from 'commander';\nimport { MarketSDK } from '@lobehub/market-sdk';\n\nimport { resolveConfig } from '../utils/config';\nimport { deleteCredentials } from '../utils/credentials';\nimport { formatOutput } from '../utils/output';\n\nexport function registerAuthCommand(program: Command): void {\n const auth = program\n .command('auth')\n .description('Manage authentication credentials and tokens');\n\n auth\n .command('status')\n .description('Show credential and token status')\n .option('--output <format>', 'Output format (text|json)', 'text')\n .action(async (options) => {\n try {\n const config = resolveConfig();\n\n if (!config.clientId || !config.clientSecret) {\n console.error(\n 'No credentials found. Run `lobehub-market register` first or set MARKET_CLIENT_ID and MARKET_CLIENT_SECRET.',\n );\n process.exit(1);\n }\n\n const sdk = new MarketSDK({\n baseURL: config.baseUrl,\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n });\n\n const tokenInfo = await sdk.fetchM2MToken();\n\n formatOutput(options.output, {\n baseUrl: config.baseUrl,\n clientId: config.clientId,\n expiresIn: `${tokenInfo.expiresIn}s`,\n source: config.source,\n status: 'authenticated',\n tokenPreview: `${tokenInfo.accessToken.slice(0, 12)}...`,\n });\n } catch (error: any) {\n console.error(`Auth status check failed: ${error.message}`);\n process.exit(1);\n }\n });\n\n auth\n .command('refresh')\n .description('Force refresh the M2M access token')\n .option('--output <format>', 'Output format (text|json)', 'text')\n .action(async (options) => {\n try {\n const config = resolveConfig();\n\n if (!config.clientId || !config.clientSecret) {\n console.error(\n 'No credentials found. Run `lobehub-market register` first or set MARKET_CLIENT_ID and MARKET_CLIENT_SECRET.',\n );\n process.exit(1);\n }\n\n const sdk = new MarketSDK({\n baseURL: config.baseUrl,\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n });\n\n const tokenInfo = await sdk.fetchM2MToken();\n\n formatOutput(options.output, {\n accessToken: tokenInfo.accessToken,\n expiresIn: tokenInfo.expiresIn,\n message: 'Token refreshed successfully',\n });\n } catch (error: any) {\n console.error(`Token refresh failed: ${error.message}`);\n process.exit(1);\n }\n });\n\n auth\n .command('logout')\n .description('Clear local credentials')\n .action(async () => {\n try {\n const deleted = await deleteCredentials();\n if (deleted) {\n console.log('Credentials cleared successfully.');\n } else {\n console.log('No credentials file found.');\n }\n } catch (error: any) {\n console.error(`Logout failed: ${error.message}`);\n process.exit(1);\n }\n });\n}\n","import { existsSync, readFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\nexport interface ResolvedConfig {\n baseUrl: string;\n clientId: string | undefined;\n clientSecret: string | undefined;\n source: 'env' | 'file' | 'mixed' | 'none';\n}\n\nexport function resolveConfig(): ResolvedConfig {\n const envClientId = process.env.MARKET_CLIENT_ID;\n const envClientSecret = process.env.MARKET_CLIENT_SECRET;\n const envBaseUrl = process.env.MARKET_BASE_URL;\n\n let fileCredentials: { baseUrl?: string; clientId?: string; clientSecret?: string } | null = null;\n\n try {\n const filePath = join(homedir(), '.lobehub-market', 'credentials.json');\n if (existsSync(filePath)) {\n const content = readFileSync(filePath, 'utf-8');\n fileCredentials = JSON.parse(content);\n }\n } catch {\n // Ignore file read errors\n }\n\n const clientId = envClientId || fileCredentials?.clientId;\n const clientSecret = envClientSecret || fileCredentials?.clientSecret;\n const baseUrl = envBaseUrl || fileCredentials?.baseUrl || 'https://market.lobehub.com';\n\n let source: ResolvedConfig['source'] = 'none';\n if (clientId && clientSecret) {\n const idFromEnv = !!envClientId;\n const secretFromEnv = !!envClientSecret;\n\n if (idFromEnv && secretFromEnv) {\n source = 'env';\n } else if (!idFromEnv && !secretFromEnv) {\n source = 'file';\n } else {\n source = 'mixed';\n }\n }\n\n return { baseUrl, clientId, clientSecret, source };\n}\n","import { existsSync } from 'node:fs';\nimport { mkdir, readFile, rm, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\nexport interface StoredCredentials {\n baseUrl: string;\n clientId: string;\n clientSecret: string;\n deviceId: string;\n name: string;\n registeredAt: string;\n source?: string;\n}\n\nconst CREDENTIALS_DIR = join(homedir(), '.lobehub-market');\nconst CREDENTIALS_FILE = join(CREDENTIALS_DIR, 'credentials.json');\n\nexport async function saveCredentials(credentials: StoredCredentials): Promise<void> {\n if (!existsSync(CREDENTIALS_DIR)) {\n await mkdir(CREDENTIALS_DIR, { mode: 0o700, recursive: true });\n }\n\n const content = JSON.stringify(credentials, null, 2);\n await writeFile(CREDENTIALS_FILE, content, { encoding: 'utf-8', mode: 0o600 });\n}\n\nexport async function loadCredentials(): Promise<StoredCredentials | null> {\n if (!existsSync(CREDENTIALS_FILE)) {\n return null;\n }\n\n const content = await readFile(CREDENTIALS_FILE, 'utf-8');\n return JSON.parse(content) as StoredCredentials;\n}\n\nexport async function deleteCredentials(): Promise<boolean> {\n if (!existsSync(CREDENTIALS_FILE)) {\n return false;\n }\n\n await rm(CREDENTIALS_FILE);\n return true;\n}\n\nexport function getCredentialsPath(): string {\n return CREDENTIALS_FILE;\n}\n","export function formatOutput(format: string, data: Record<string, unknown>): void {\n if (format === 'json') {\n console.log(JSON.stringify(data, null, 2));\n return;\n }\n\n for (const [key, value] of Object.entries(data)) {\n const label = key\n .replaceAll(/([A-Z])/g, ' $1')\n .replace(/^./, (s) => s.toUpperCase())\n .trim();\n console.log(` ${label}: ${value}`);\n }\n}\n","import { MarketSDK } from '@lobehub/market-sdk';\nimport type { Command } from 'commander';\n\nimport { getCredentialsPath, saveCredentials } from '../utils/credentials';\nimport { generateDeviceId } from '../utils/deviceId';\nimport { formatOutput } from '../utils/output';\n\nexport function registerRegisterCommand(program: Command): void {\n program\n .command('register')\n .description('Register this device as an M2M client and save credentials locally')\n .requiredOption('--name <name>', 'Client name for registration')\n .option('--description <desc>', 'Description of the client')\n .option(\n '--source <source>',\n 'Agent source, lowercase with hyphens (e.g. claude-code, open-claw, codex, cursor)',\n )\n .option('--device-id <id>', 'Device identifier (auto-generated if omitted)')\n .option('--base-url <url>', 'Market API base URL', 'https://market.lobehub.com')\n .option('--output <format>', 'Output format (text|json)', 'text')\n .action(async (options) => {\n try {\n const deviceId = options.deviceId || generateDeviceId();\n const baseURL = process.env.MARKET_BASE_URL || options.baseUrl;\n const source = options.source;\n\n const description = [options.description, source && `source: ${source}`]\n .filter(Boolean)\n .join('. ');\n\n const sdk = new MarketSDK({ baseURL });\n\n const result = await sdk.auth.registerClient({\n clientName: options.name,\n clientType: 'cli',\n description: description || undefined,\n deviceId,\n platform: process.arch,\n version: process.version,\n });\n\n await saveCredentials({\n baseUrl: baseURL,\n clientId: result.client_id,\n clientSecret: result.client_secret,\n deviceId,\n name: options.name,\n registeredAt: new Date().toISOString(),\n source,\n });\n\n formatOutput(options.output, {\n clientId: result.client_id,\n credentialsPath: getCredentialsPath(),\n message: result.message || 'Client registered successfully',\n });\n } catch (error: any) {\n console.error(`Registration failed: ${error.message}`);\n process.exit(1);\n }\n });\n}\n","import { createHash } from 'node:crypto';\nimport { hostname, networkInterfaces } from 'node:os';\n\nexport function generateDeviceId(): string {\n const host = hostname();\n const mac = getPrimaryMacAddress();\n\n const input = mac ? `${host}:${mac}` : host;\n const hash = createHash('sha256').update(input).digest('hex').slice(0, 16);\n\n return `device-${hash}`;\n}\n\nfunction getPrimaryMacAddress(): string | undefined {\n const interfaces = networkInterfaces();\n\n for (const name of Object.keys(interfaces).sort()) {\n const entries = interfaces[name];\n if (!entries) continue;\n\n for (const entry of entries) {\n if (entry.internal) continue;\n if (entry.mac === '00:00:00:00:00:00') continue;\n\n return entry.mac;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;AAAA,SAAS,qBAAqB;AAE9B,SAAS,eAAe;;;ACDxB,SAAS,iBAAiB;;;ACD1B,SAAS,YAAY,oBAAoB;AACzC,SAAS,eAAe;AACxB,SAAS,YAAY;AASd,SAAS,gBAAgC;AAC9C,QAAM,cAAc,QAAQ,IAAI;AAChC,QAAM,kBAAkB,QAAQ,IAAI;AACpC,QAAM,aAAa,QAAQ,IAAI;AAE/B,MAAI,kBAAyF;AAE7F,MAAI;AACF,UAAM,WAAW,KAAK,QAAQ,GAAG,mBAAmB,kBAAkB;AACtE,Q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ACA,MAAM,QAAQ;AAAA,QACd,eAAc,oBAAI,KAAK,GAAE,YAAY;AAAA,QACrC;AAAA,MACF,CAAC;AAED,mBAAa,QAAQ,QAAQ;AAAA,QAC3B,UAAU,OAAO;AAAA,QACjB,iBAAiB,mBAAmB;AAAA,QACpC,SAAS,OAAO,WAAW;AAAA,MAC7B,CAAC;AAAA,IACH,SAAS,OAAY;AACnB,cAAQ,MAAM,wBAAwB,MAAM,OAAO,EAAE;AACrD,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,CAAC;AACL;;;ALtDA,IAAMC,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,MAAMA,SAAQ,iBAAiB;AAErC,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,gBAAgB,EACrB,YAAY,8DAA8D,EAC1E,QAAQ,IAAI,OAAO;AAEtB,wBAAwB,OAAO;AAC/B,oBAAoB,OAAO;AAE3B,QAAQ,MAAM;","names":["existsSync","homedir","join","existsSync","program","MarketSDK","program","MarketSDK","require"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/market-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "LobeHub Market CLI - Device registration and auth management",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -25,10 +25,10 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@lobehub/market-sdk": "workspace:*",
29
- "commander": "^13.1.0"
28
+ "commander": "^13.1.0",
29
+ "@lobehub/market-sdk": "0.30.4"
30
30
  },
31
31
  "engines": {
32
32
  "node": ">=22.0.0"
33
33
  }
34
- }
34
+ }