@nordsym/apiclaw 1.5.13 → 1.5.15

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.
Files changed (70) hide show
  1. package/dist/bin.js +1 -1
  2. package/dist/cli/commands/mcp-install.js +44 -49
  3. package/dist/cli/commands/mcp-install.js.map +1 -1
  4. package/dist/cli/index.js +7 -0
  5. package/dist/convex/adminActivate.js +46 -0
  6. package/dist/convex/adminStats.js +41 -0
  7. package/dist/convex/agents.js +498 -0
  8. package/dist/convex/analytics.js +165 -0
  9. package/dist/convex/billing.js +654 -0
  10. package/dist/convex/capabilities.js +144 -0
  11. package/dist/convex/chains.js +1041 -0
  12. package/dist/convex/credits.js +185 -0
  13. package/dist/convex/crons.js +16 -0
  14. package/dist/convex/directCall.js +626 -0
  15. package/dist/convex/earnProgress.js +648 -0
  16. package/dist/convex/email.js +299 -0
  17. package/dist/convex/feedback.js +226 -0
  18. package/dist/convex/http.js +909 -0
  19. package/dist/convex/logs.js +486 -0
  20. package/dist/convex/mou.js +81 -0
  21. package/dist/convex/providerKeys.js +256 -0
  22. package/dist/convex/providers.js +755 -0
  23. package/dist/convex/purchases.js +156 -0
  24. package/dist/convex/ratelimit.js +90 -0
  25. package/dist/convex/schema.js +709 -0
  26. package/dist/convex/searchLogs.js +128 -0
  27. package/dist/convex/spendAlerts.js +379 -0
  28. package/dist/convex/stripeActions.js +410 -0
  29. package/dist/convex/teams.js +214 -0
  30. package/dist/convex/telemetry.js +73 -0
  31. package/dist/convex/usage.js +228 -0
  32. package/dist/convex/waitlist.js +48 -0
  33. package/dist/convex/webhooks.js +409 -0
  34. package/dist/convex/workspaces.js +879 -0
  35. package/dist/src/analytics.js +129 -0
  36. package/dist/src/bin.js +17 -0
  37. package/dist/src/capability-router.js +240 -0
  38. package/dist/src/chainExecutor.js +451 -0
  39. package/dist/src/chainResolver.js +518 -0
  40. package/dist/src/cli/commands/doctor.js +324 -0
  41. package/dist/src/cli/commands/mcp-install.js +255 -0
  42. package/dist/src/cli/commands/restore.js +259 -0
  43. package/dist/src/cli/commands/setup.js +205 -0
  44. package/dist/src/cli/commands/uninstall.js +188 -0
  45. package/dist/src/cli/index.js +111 -0
  46. package/dist/src/cli.js +302 -0
  47. package/dist/src/confirmation.js +240 -0
  48. package/dist/src/credentials.js +357 -0
  49. package/dist/src/credits.js +260 -0
  50. package/dist/src/crypto.js +66 -0
  51. package/dist/src/discovery.js +504 -0
  52. package/dist/src/enterprise/env.js +123 -0
  53. package/dist/src/enterprise/script-generator.js +460 -0
  54. package/dist/src/execute-dynamic.js +473 -0
  55. package/dist/src/execute.js +1727 -0
  56. package/dist/src/index.js +2062 -0
  57. package/dist/src/metered.js +80 -0
  58. package/dist/src/open-apis.js +276 -0
  59. package/dist/src/proxy.js +28 -0
  60. package/dist/src/session.js +86 -0
  61. package/dist/src/stripe.js +407 -0
  62. package/dist/src/telemetry.js +49 -0
  63. package/dist/src/types.js +2 -0
  64. package/dist/src/utils/backup.js +181 -0
  65. package/dist/src/utils/config.js +220 -0
  66. package/dist/src/utils/os.js +105 -0
  67. package/dist/src/utils/paths.js +159 -0
  68. package/package.json +1 -1
  69. package/src/bin.ts +1 -1
  70. package/src/cli/index.ts +8 -0
@@ -0,0 +1,460 @@
1
+ /**
2
+ * Enterprise Script Generator
3
+ * Generates self-contained deployment scripts for bash and PowerShell
4
+ */
5
+ import { ENV_VARS, DEFAULT_API_URL } from './env.js';
6
+ // Env var names as strings for embedding in scripts
7
+ const WORKSPACE_VAR = ENV_VARS.WORKSPACE;
8
+ const API_URL_VAR = ENV_VARS.API_URL;
9
+ const TELEMETRY_VAR = ENV_VARS.DISABLE_TELEMETRY;
10
+ /**
11
+ * Generate self-contained bash deployment script
12
+ */
13
+ export function generateBashScript(options = {}) {
14
+ const serverName = options.serverName || 'apiclaw';
15
+ const workspaceVal = options.workspace || '';
16
+ const apiUrlVal = options.apiUrl || DEFAULT_API_URL;
17
+ const disableTelemetry = options.disableTelemetry ? 'true' : '';
18
+ const verbose = options.verbose ? '1' : '';
19
+ return `#!/usr/bin/env bash
20
+ #
21
+ # APIClaw MCP Auto-Setup Script
22
+ # Generated by: npx @nordsym/apiclaw setup --enterprise
23
+ #
24
+ # This script automatically configures APIClaw for all detected MCP clients.
25
+ # Supports: Claude Desktop, Cursor, Windsurf, Cline, Continue
26
+ #
27
+
28
+ set -e
29
+
30
+ # Configuration
31
+ SERVER_NAME="${serverName}"
32
+ WORKSPACE="${workspaceVal}"
33
+ API_URL="${apiUrlVal}"
34
+ DEFAULT_API_URL="${DEFAULT_API_URL}"
35
+ DISABLE_TELEMETRY="${disableTelemetry}"
36
+ VERBOSE="${verbose}"
37
+
38
+ # Environment variable names
39
+ ENV_WORKSPACE="${WORKSPACE_VAR}"
40
+ ENV_API_URL="${API_URL_VAR}"
41
+ ENV_TELEMETRY="${TELEMETRY_VAR}"
42
+
43
+ # Colors
44
+ RED='\\033[0;31m'
45
+ GREEN='\\033[0;32m'
46
+ YELLOW='\\033[1;33m'
47
+ BLUE='\\033[0;34m'
48
+ NC='\\033[0m' # No Color
49
+
50
+ log_info() { echo -e "\${BLUE}ℹ\${NC} $1"; }
51
+ log_success() { echo -e "\${GREEN}✓\${NC} $1"; }
52
+ log_warn() { echo -e "\${YELLOW}⚠\${NC} $1"; }
53
+ log_error() { echo -e "\${RED}✗\${NC} $1"; }
54
+ log_verbose() { [[ -n "$VERBOSE" ]] && echo -e " $1"; }
55
+
56
+ # Detect OS
57
+ detect_os() {
58
+ case "$(uname -s)" in
59
+ Darwin*) echo "mac" ;;
60
+ Linux*) echo "linux" ;;
61
+ MINGW*|MSYS*|CYGWIN*) echo "win" ;;
62
+ *) echo "linux" ;;
63
+ esac
64
+ }
65
+
66
+ OS=$(detect_os)
67
+ HOME_DIR="$HOME"
68
+
69
+ # Set paths based on OS
70
+ case "$OS" in
71
+ mac)
72
+ APP_DATA="$HOME_DIR/Library/Application Support"
73
+ ;;
74
+ linux)
75
+ APP_DATA="\${XDG_CONFIG_HOME:-$HOME_DIR/.config}"
76
+ ;;
77
+ win)
78
+ APP_DATA="\${APPDATA:-$HOME_DIR/AppData/Roaming}"
79
+ ;;
80
+ esac
81
+
82
+ echo ""
83
+ echo "🔧 APIClaw MCP Auto-Setup"
84
+ echo "========================="
85
+ echo ""
86
+ log_info "Detected OS: $OS"
87
+
88
+ # Check for Node.js
89
+ if ! command -v node &> /dev/null; then
90
+ log_error "Node.js is required but not installed."
91
+ exit 1
92
+ fi
93
+ log_success "Node.js $(node --version) found"
94
+
95
+ # Check for npx
96
+ if ! command -v npx &> /dev/null; then
97
+ log_error "npx is required but not installed."
98
+ exit 1
99
+ fi
100
+ log_success "npx available"
101
+
102
+ # Generate APIClaw server config JSON
103
+ generate_config() {
104
+ local env_block=""
105
+
106
+ if [[ -n "$WORKSPACE" ]] || [[ -n "$API_URL" && "$API_URL" != "$DEFAULT_API_URL" ]] || [[ -n "$DISABLE_TELEMETRY" ]]; then
107
+ env_block='"env": {'
108
+ local first=true
109
+
110
+ if [[ -n "$WORKSPACE" ]]; then
111
+ env_block+="\\"$ENV_WORKSPACE\\": \\"$WORKSPACE\\""
112
+ first=false
113
+ fi
114
+
115
+ if [[ -n "$API_URL" && "$API_URL" != "$DEFAULT_API_URL" ]]; then
116
+ [[ "$first" == "false" ]] && env_block+=','
117
+ env_block+="\\"$ENV_API_URL\\": \\"$API_URL\\""
118
+ first=false
119
+ fi
120
+
121
+ if [[ -n "$DISABLE_TELEMETRY" ]]; then
122
+ [[ "$first" == "false" ]] && env_block+=','
123
+ env_block+="\\"$ENV_TELEMETRY\\": \\"true\\""
124
+ fi
125
+
126
+ env_block+='},'
127
+ fi
128
+
129
+ if [[ -n "$env_block" ]]; then
130
+ echo "{\\"command\\": \\"npx\\", \\"args\\": [\\"-y\\", \\"@nordsym/apiclaw\\"], $env_block}"
131
+ else
132
+ echo "{\\"command\\": \\"npx\\", \\"args\\": [\\"-y\\", \\"@nordsym/apiclaw\\"]}"
133
+ fi
134
+ }
135
+
136
+ # Merge APIClaw into existing config using Node.js
137
+ merge_config() {
138
+ local config_path="$1"
139
+ local apiclaw_config
140
+ apiclaw_config=$(generate_config)
141
+
142
+ if [[ -f "$config_path" ]]; then
143
+ # Backup existing
144
+ cp "$config_path" "$config_path.backup.$(date +%s).json"
145
+
146
+ # Read existing config
147
+ local existing
148
+ existing=$(cat "$config_path")
149
+
150
+ # Use node to merge JSON
151
+ node -e "
152
+ const fs = require('fs');
153
+ const existing = JSON.parse(process.argv[1] || '{}');
154
+ const apiclaw = JSON.parse(process.argv[2]);
155
+
156
+ if (!existing.mcpServers) existing.mcpServers = {};
157
+ existing.mcpServers['$SERVER_NAME'] = apiclaw;
158
+
159
+ fs.writeFileSync('$config_path', JSON.stringify(existing, null, 2));
160
+ " "$existing" "$apiclaw_config"
161
+ else
162
+ # Create new config
163
+ mkdir -p "$(dirname "$config_path")"
164
+ node -e "
165
+ const fs = require('fs');
166
+ const apiclaw = JSON.parse(process.argv[1]);
167
+ const config = { mcpServers: { '$SERVER_NAME': apiclaw } };
168
+ fs.writeFileSync('$config_path', JSON.stringify(config, null, 2));
169
+ " "$apiclaw_config"
170
+ fi
171
+ }
172
+
173
+ # Client config paths
174
+ declare -A CLIENT_PATHS
175
+
176
+ case "$OS" in
177
+ mac)
178
+ CLIENT_PATHS=(
179
+ ["Claude Desktop"]="$APP_DATA/Claude/claude_desktop_config.json"
180
+ ["Cursor"]="$APP_DATA/Cursor/User/globalStorage/cursor.mcp/config.json"
181
+ ["Windsurf"]="$HOME_DIR/.codeium/windsurf/mcp_config.json"
182
+ ["Cline"]="$APP_DATA/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json"
183
+ ["Continue"]="$HOME_DIR/.continue/config.json"
184
+ )
185
+ ;;
186
+ linux)
187
+ CLIENT_PATHS=(
188
+ ["Claude Desktop"]="$APP_DATA/Claude/claude_desktop_config.json"
189
+ ["Cursor"]="$APP_DATA/Cursor/User/globalStorage/cursor.mcp/config.json"
190
+ ["Windsurf"]="$HOME_DIR/.codeium/windsurf/mcp_config.json"
191
+ ["Cline"]="$APP_DATA/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json"
192
+ ["Continue"]="$HOME_DIR/.continue/config.json"
193
+ )
194
+ ;;
195
+ win)
196
+ CLIENT_PATHS=(
197
+ ["Claude Desktop"]="$APP_DATA/Claude/claude_desktop_config.json"
198
+ ["Cursor"]="$APP_DATA/Cursor/User/globalStorage/cursor.mcp/config.json"
199
+ ["Windsurf"]="$USERPROFILE/.codeium/windsurf/mcp_config.json"
200
+ ["Cline"]="$APP_DATA/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json"
201
+ ["Continue"]="$USERPROFILE/.continue/config.json"
202
+ )
203
+ ;;
204
+ esac
205
+
206
+ # Configure each client
207
+ echo ""
208
+ log_info "Scanning for MCP clients..."
209
+ echo ""
210
+
211
+ configured=0
212
+ skipped=0
213
+
214
+ for client in "\${!CLIENT_PATHS[@]}"; do
215
+ config_path="\${CLIENT_PATHS[$client]}"
216
+ config_dir=$(dirname "$config_path")
217
+
218
+ # Check if client is installed (config dir exists or we can create it)
219
+ if [[ -d "$config_dir" ]] || [[ -f "$config_path" ]]; then
220
+ log_info "Configuring $client..."
221
+
222
+ if merge_config "$config_path"; then
223
+ log_success "$client configured"
224
+ ((configured++))
225
+ else
226
+ log_error "Failed to configure $client"
227
+ fi
228
+ else
229
+ log_verbose "$client not detected (no config directory)"
230
+ ((skipped++))
231
+ fi
232
+ done
233
+
234
+ # Summary
235
+ echo ""
236
+ echo "========================="
237
+ echo ""
238
+
239
+ if [[ $configured -gt 0 ]]; then
240
+ log_success "Configured $configured client(s)"
241
+ echo ""
242
+ echo "🎉 APIClaw is ready! Restart your MCP clients to activate."
243
+ else
244
+ log_warn "No MCP clients were detected."
245
+ echo ""
246
+ echo "Install one of these clients first:"
247
+ echo " • Claude Desktop: https://claude.ai/download"
248
+ echo " • Cursor: https://cursor.sh"
249
+ echo " • Windsurf: https://codeium.com/windsurf"
250
+ fi
251
+
252
+ echo ""
253
+ `;
254
+ }
255
+ /**
256
+ * Generate self-contained PowerShell deployment script
257
+ */
258
+ export function generatePowerShellScript(options = {}) {
259
+ const serverName = options.serverName || 'apiclaw';
260
+ const workspaceVal = options.workspace || '';
261
+ const apiUrlVal = options.apiUrl || DEFAULT_API_URL;
262
+ const disableTelemetry = options.disableTelemetry;
263
+ const verbose = options.verbose;
264
+ return `#Requires -Version 5.1
265
+ <#
266
+ .SYNOPSIS
267
+ APIClaw MCP Auto-Setup Script
268
+
269
+ .DESCRIPTION
270
+ Automatically configures APIClaw for all detected MCP clients.
271
+ Supports: Claude Desktop, Cursor, Windsurf, Cline, Continue
272
+
273
+ .NOTES
274
+ Generated by: npx @nordsym/apiclaw setup --enterprise
275
+ #>
276
+
277
+ [CmdletBinding()]
278
+ param()
279
+
280
+ $ErrorActionPreference = "Stop"
281
+
282
+ # Configuration
283
+ $ServerName = "${serverName}"
284
+ $Workspace = "${workspaceVal}"
285
+ $ApiUrl = "${apiUrlVal}"
286
+ $DefaultApiUrl = "${DEFAULT_API_URL}"
287
+ $DisableTelemetry = $${disableTelemetry ? 'true' : 'false'}
288
+ $VerboseMode = $${verbose ? 'true' : 'false'}
289
+
290
+ # Env var names
291
+ $EnvWorkspace = "${WORKSPACE_VAR}"
292
+ $EnvApiUrl = "${API_URL_VAR}"
293
+ $EnvTelemetry = "${TELEMETRY_VAR}"
294
+
295
+ # Helper functions
296
+ function Write-Info { param($Message) Write-Host "ℹ $Message" -ForegroundColor Blue }
297
+ function Write-Success { param($Message) Write-Host "✓ $Message" -ForegroundColor Green }
298
+ function Write-Warn { param($Message) Write-Host "⚠ $Message" -ForegroundColor Yellow }
299
+ function Write-Err { param($Message) Write-Host "✗ $Message" -ForegroundColor Red }
300
+
301
+ Write-Host ""
302
+ Write-Host "🔧 APIClaw MCP Auto-Setup" -ForegroundColor Cyan
303
+ Write-Host "=========================" -ForegroundColor Cyan
304
+ Write-Host ""
305
+
306
+ # Check for Node.js
307
+ try {
308
+ $nodeVersion = & node --version 2>$null
309
+ Write-Success "Node.js $nodeVersion found"
310
+ } catch {
311
+ Write-Err "Node.js is required but not installed."
312
+ exit 1
313
+ }
314
+
315
+ # Check for npx
316
+ try {
317
+ $null = & npx --version 2>$null
318
+ Write-Success "npx available"
319
+ } catch {
320
+ Write-Err "npx is required but not installed."
321
+ exit 1
322
+ }
323
+
324
+ # Generate APIClaw config
325
+ function Get-ApiclawConfig {
326
+ $config = @{
327
+ command = "npx"
328
+ args = @("-y", "@nordsym/apiclaw")
329
+ }
330
+
331
+ $env = @{}
332
+ if ($Workspace) { $env[$EnvWorkspace] = $Workspace }
333
+ if ($ApiUrl -and $ApiUrl -ne $DefaultApiUrl) { $env[$EnvApiUrl] = $ApiUrl }
334
+ if ($DisableTelemetry) { $env[$EnvTelemetry] = "true" }
335
+
336
+ if ($env.Count -gt 0) {
337
+ $config["env"] = $env
338
+ }
339
+
340
+ return $config
341
+ }
342
+
343
+ # Merge config into existing file
344
+ function Merge-Config {
345
+ param(
346
+ [string]$ConfigPath
347
+ )
348
+
349
+ $configDir = Split-Path -Parent $ConfigPath
350
+
351
+ # Ensure directory exists
352
+ if (!(Test-Path $configDir)) {
353
+ New-Item -ItemType Directory -Path $configDir -Force | Out-Null
354
+ }
355
+
356
+ # Read existing or create new
357
+ if (Test-Path $ConfigPath) {
358
+ # Backup existing
359
+ $backupPath = "$ConfigPath.backup.$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds()).json"
360
+ Copy-Item $ConfigPath $backupPath
361
+
362
+ $existing = Get-Content $ConfigPath -Raw | ConvertFrom-Json -AsHashtable
363
+ } else {
364
+ $existing = @{}
365
+ }
366
+
367
+ # Ensure mcpServers exists
368
+ if (!$existing.ContainsKey("mcpServers")) {
369
+ $existing["mcpServers"] = @{}
370
+ }
371
+
372
+ # Add APIClaw
373
+ $existing["mcpServers"][$ServerName] = Get-ApiclawConfig
374
+
375
+ # Write back
376
+ $existing | ConvertTo-Json -Depth 10 | Set-Content $ConfigPath -Encoding UTF8
377
+ }
378
+
379
+ # Client paths
380
+ $AppData = $env:APPDATA
381
+ $UserProfile = $env:USERPROFILE
382
+
383
+ $ClientPaths = @{
384
+ "Claude Desktop" = "$AppData\\Claude\\claude_desktop_config.json"
385
+ "Cursor" = "$AppData\\Cursor\\User\\globalStorage\\cursor.mcp\\config.json"
386
+ "Windsurf" = "$UserProfile\\.codeium\\windsurf\\mcp_config.json"
387
+ "Cline" = "$AppData\\Code\\User\\globalStorage\\saoudrizwan.claude-dev\\settings\\cline_mcp_settings.json"
388
+ "Continue" = "$UserProfile\\.continue\\config.json"
389
+ }
390
+
391
+ Write-Host ""
392
+ Write-Info "Scanning for MCP clients..."
393
+ Write-Host ""
394
+
395
+ $configured = 0
396
+
397
+ foreach ($client in $ClientPaths.Keys) {
398
+ $configPath = $ClientPaths[$client]
399
+ $configDir = Split-Path -Parent $configPath
400
+
401
+ if ((Test-Path $configDir) -or (Test-Path $configPath)) {
402
+ Write-Info "Configuring $client..."
403
+
404
+ try {
405
+ Merge-Config -ConfigPath $configPath
406
+ Write-Success "$client configured"
407
+ $configured++
408
+ } catch {
409
+ Write-Err "Failed to configure $client: $_"
410
+ }
411
+ }
412
+ }
413
+
414
+ Write-Host ""
415
+ Write-Host "=========================" -ForegroundColor Cyan
416
+ Write-Host ""
417
+
418
+ if ($configured -gt 0) {
419
+ Write-Success "Configured $configured client(s)"
420
+ Write-Host ""
421
+ Write-Host "🎉 APIClaw is ready! Restart your MCP clients to activate." -ForegroundColor Green
422
+ } else {
423
+ Write-Warn "No MCP clients were detected."
424
+ Write-Host ""
425
+ Write-Host "Install one of these clients first:"
426
+ Write-Host " • Claude Desktop: https://claude.ai/download"
427
+ Write-Host " • Cursor: https://cursor.sh"
428
+ Write-Host " • Windsurf: https://codeium.com/windsurf"
429
+ }
430
+
431
+ Write-Host ""
432
+ `;
433
+ }
434
+ /**
435
+ * Generate script based on target platform
436
+ */
437
+ export function generateScript(platform, options = {}) {
438
+ // Auto-detect platform
439
+ let targetPlatform = platform === 'auto'
440
+ ? (process.platform === 'win32' ? 'powershell' : 'bash')
441
+ : platform;
442
+ if (targetPlatform === 'powershell') {
443
+ return {
444
+ script: generatePowerShellScript(options),
445
+ filename: 'apiclaw-setup.ps1',
446
+ platform: 'powershell',
447
+ };
448
+ }
449
+ return {
450
+ script: generateBashScript(options),
451
+ filename: 'apiclaw-setup.sh',
452
+ platform: 'bash',
453
+ };
454
+ }
455
+ /**
456
+ * Get file extension for platform
457
+ */
458
+ export function getScriptExtension(platform) {
459
+ return platform === 'powershell' ? '.ps1' : '.sh';
460
+ }