@nordsym/apiclaw 2.1.0 → 2.2.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.
Files changed (185) hide show
  1. package/README.md +15 -2
  2. package/dist/bin-http.js +0 -0
  3. package/dist/bin.bundled.js +79288 -0
  4. package/dist/funnel-client.d.ts +24 -0
  5. package/dist/funnel-client.d.ts.map +1 -0
  6. package/dist/funnel-client.js +131 -0
  7. package/dist/funnel-client.js.map +1 -0
  8. package/dist/funnel.test.d.ts +2 -0
  9. package/dist/funnel.test.d.ts.map +1 -0
  10. package/dist/funnel.test.js +145 -0
  11. package/dist/funnel.test.js.map +1 -0
  12. package/dist/gateway-client.d.ts.map +1 -1
  13. package/dist/gateway-client.js +24 -2
  14. package/dist/gateway-client.js.map +1 -1
  15. package/dist/index.bundled.js +61263 -0
  16. package/dist/index.js +161 -74
  17. package/dist/index.js.map +1 -1
  18. package/dist/postinstall.d.ts +0 -5
  19. package/dist/postinstall.d.ts.map +1 -1
  20. package/dist/postinstall.js +24 -3
  21. package/dist/postinstall.js.map +1 -1
  22. package/dist/registration-guard.d.ts +29 -0
  23. package/dist/registration-guard.d.ts.map +1 -0
  24. package/dist/registration-guard.js +87 -0
  25. package/dist/registration-guard.js.map +1 -0
  26. package/package.json +7 -2
  27. package/.claude/settings.local.json +0 -9
  28. package/.env.prod +0 -1
  29. package/apiclaw-README.md +0 -494
  30. package/convex/_generated/api.d.ts +0 -137
  31. package/convex/_generated/api.js +0 -23
  32. package/convex/_generated/dataModel.d.ts +0 -60
  33. package/convex/_generated/server.d.ts +0 -143
  34. package/convex/_generated/server.js +0 -93
  35. package/convex/adminActivate.ts +0 -53
  36. package/convex/adminStats.ts +0 -306
  37. package/convex/agents.ts +0 -939
  38. package/convex/analytics.ts +0 -187
  39. package/convex/apiKeys.ts +0 -220
  40. package/convex/backfillAnalytics.ts +0 -272
  41. package/convex/backfillSearchLogs.ts +0 -35
  42. package/convex/billing.ts +0 -834
  43. package/convex/capabilities.ts +0 -157
  44. package/convex/chains.ts +0 -1318
  45. package/convex/credits.ts +0 -211
  46. package/convex/crons.ts +0 -50
  47. package/convex/debugFilestackLogs.ts +0 -16
  48. package/convex/debugGetToken.ts +0 -18
  49. package/convex/directCall.ts +0 -713
  50. package/convex/earnProgress.ts +0 -753
  51. package/convex/email.ts +0 -329
  52. package/convex/feedback.ts +0 -265
  53. package/convex/http.ts +0 -3430
  54. package/convex/inbound.ts +0 -32
  55. package/convex/logs.ts +0 -701
  56. package/convex/migrateFilestack.ts +0 -81
  57. package/convex/migratePartnersProd.ts +0 -174
  58. package/convex/migratePratham.ts +0 -126
  59. package/convex/migrateProviderWorkspaces.ts +0 -175
  60. package/convex/mou.ts +0 -91
  61. package/convex/providerKeys.ts +0 -289
  62. package/convex/providers.ts +0 -1135
  63. package/convex/purchases.ts +0 -183
  64. package/convex/ratelimit.ts +0 -104
  65. package/convex/schema.ts +0 -869
  66. package/convex/searchLogs.ts +0 -265
  67. package/convex/seedAPILayerAPIs.ts +0 -191
  68. package/convex/seedDirectCallConfigs.ts +0 -336
  69. package/convex/seedPratham.ts +0 -149
  70. package/convex/spendAlerts.ts +0 -442
  71. package/convex/stripeActions.ts +0 -607
  72. package/convex/teams.ts +0 -243
  73. package/convex/telemetry.ts +0 -81
  74. package/convex/tsconfig.json +0 -25
  75. package/convex/updateAPIStatus.ts +0 -44
  76. package/convex/usage.ts +0 -260
  77. package/convex/usageReports.ts +0 -357
  78. package/convex/waitlist.ts +0 -55
  79. package/convex/webhooks.ts +0 -494
  80. package/convex/workspaceSettings.ts +0 -143
  81. package/convex/workspaces.ts +0 -1331
  82. package/convex.json +0 -3
  83. package/direct-test.mjs +0 -51
  84. package/email-templates/filestack-provider-outreach.html +0 -162
  85. package/email-templates/partnership-template.html +0 -116
  86. package/email-templates/pratham-draft-preview.txt +0 -57
  87. package/email-templates/pratham-partnership-draft.html +0 -141
  88. package/reports/APIClaw-Session-Report-2026-04-05.pdf +0 -0
  89. package/reports/pipeline/PIPELINE-REPORT.json +0 -153
  90. package/reports/pipeline/acquire_apisguru.json +0 -17
  91. package/reports/pipeline/capabilities.json +0 -38
  92. package/reports/pipeline/discover_azure_recursive.json +0 -1551
  93. package/reports/pipeline/discover_github.json +0 -25
  94. package/reports/pipeline/discover_github_repos.json +0 -49
  95. package/reports/pipeline/discover_swaggerhub.json +0 -24
  96. package/reports/pipeline/discover_well_known.json +0 -23
  97. package/reports/pipeline/fetch_specs.json +0 -19
  98. package/reports/pipeline/generate_providers.json +0 -14
  99. package/reports/pipeline/match_registry.json +0 -11
  100. package/reports/pipeline/parse_specs.json +0 -17
  101. package/reports/pipeline/promote_candidates.json +0 -34
  102. package/reports/pipeline/validate.json +0 -30
  103. package/reports/pipeline/validate_smoke_details.json +0 -3835
  104. package/reports/session-report-2026-04-05.html +0 -433
  105. package/seed-apis-direct.mjs +0 -106
  106. package/src/access-control.ts +0 -174
  107. package/src/adapters/base.ts +0 -364
  108. package/src/adapters/claude-desktop.ts +0 -41
  109. package/src/adapters/cline.ts +0 -88
  110. package/src/adapters/continue.ts +0 -91
  111. package/src/adapters/cursor.ts +0 -43
  112. package/src/adapters/custom.ts +0 -188
  113. package/src/adapters/detect.ts +0 -202
  114. package/src/adapters/index.ts +0 -47
  115. package/src/adapters/windsurf.ts +0 -44
  116. package/src/bin-http.ts +0 -45
  117. package/src/bin.ts +0 -34
  118. package/src/capability-router.ts +0 -331
  119. package/src/chainExecutor.ts +0 -730
  120. package/src/chainResolver.test.ts +0 -246
  121. package/src/chainResolver.ts +0 -658
  122. package/src/cli/commands/demo.ts +0 -109
  123. package/src/cli/commands/doctor.ts +0 -435
  124. package/src/cli/commands/index.ts +0 -9
  125. package/src/cli/commands/login.ts +0 -203
  126. package/src/cli/commands/mcp-install.ts +0 -373
  127. package/src/cli/commands/restore.ts +0 -333
  128. package/src/cli/commands/setup.ts +0 -297
  129. package/src/cli/commands/uninstall.ts +0 -240
  130. package/src/cli/index.ts +0 -148
  131. package/src/cli.ts +0 -370
  132. package/src/confirmation.ts +0 -296
  133. package/src/credentials.ts +0 -455
  134. package/src/credits.ts +0 -329
  135. package/src/crypto.ts +0 -75
  136. package/src/discovery.ts +0 -568
  137. package/src/enterprise/env.ts +0 -156
  138. package/src/enterprise/index.ts +0 -7
  139. package/src/enterprise/script-generator.ts +0 -481
  140. package/src/execute-dynamic.ts +0 -617
  141. package/src/execute.ts +0 -2386
  142. package/src/gateway-client.ts +0 -192
  143. package/src/hivr-whitelist.ts +0 -110
  144. package/src/http-api.ts +0 -286
  145. package/src/http-server-minimal.ts +0 -154
  146. package/src/index.ts +0 -2611
  147. package/src/intelligent-gateway.ts +0 -339
  148. package/src/mcp-analytics.ts +0 -156
  149. package/src/metered.ts +0 -149
  150. package/src/open-apis-generated.ts +0 -157
  151. package/src/open-apis.ts +0 -558
  152. package/src/postinstall.ts +0 -18
  153. package/src/product-whitelist.ts +0 -246
  154. package/src/proxy.ts +0 -36
  155. package/src/session.ts +0 -129
  156. package/src/stripe.ts +0 -497
  157. package/src/telemetry.ts +0 -71
  158. package/src/test.ts +0 -135
  159. package/src/types/convex-api.d.ts +0 -20
  160. package/src/types/convex-api.ts +0 -21
  161. package/src/types.ts +0 -109
  162. package/src/ui/colors.ts +0 -219
  163. package/src/ui/errors.ts +0 -394
  164. package/src/ui/index.ts +0 -17
  165. package/src/ui/prompts.ts +0 -390
  166. package/src/ui/spinner.ts +0 -325
  167. package/src/utils/backup.ts +0 -224
  168. package/src/utils/config.ts +0 -318
  169. package/src/utils/os.ts +0 -124
  170. package/src/utils/paths.ts +0 -203
  171. package/src/webhook.ts +0 -107
  172. package/test-10-working.cjs +0 -97
  173. package/test-14-final.cjs +0 -96
  174. package/test-actual-handlers.ts +0 -92
  175. package/test-apilayer-all-14.ts +0 -249
  176. package/test-apilayer-fixed.ts +0 -248
  177. package/test-direct-endpoints.ts +0 -174
  178. package/test-exact-endpoints.ts +0 -144
  179. package/test-final.ts +0 -83
  180. package/test-full-routing.ts +0 -100
  181. package/test-handlers-correct.ts +0 -217
  182. package/test-numverify-key.ts +0 -41
  183. package/test-via-handlers.ts +0 -92
  184. package/test-worldnews.mjs +0 -26
  185. package/tsconfig.json +0 -20
package/src/ui/prompts.ts DELETED
@@ -1,390 +0,0 @@
1
- /**
2
- * APIClaw MCP Auto-Setup - Interactive Prompts
3
- *
4
- * Inquirer-based prompts for the --wizard mode.
5
- * Provides a guided, interactive setup experience.
6
- */
7
-
8
- import inquirer from 'inquirer';
9
- import { colors, icons, header, box, codeBlock, added, bulletList } from './colors.js';
10
-
11
- /**
12
- * Detected client information
13
- */
14
- export interface DetectedClient {
15
- id: string;
16
- name: string;
17
- detected: boolean;
18
- configPath: string;
19
- alreadyConfigured: boolean;
20
- }
21
-
22
- /**
23
- * Configuration change preview
24
- */
25
- export interface ConfigChange {
26
- clientId: string;
27
- clientName: string;
28
- configPath: string;
29
- action: 'create' | 'update' | 'skip';
30
- diff?: string;
31
- }
32
-
33
- /**
34
- * Wizard result
35
- */
36
- export interface WizardResult {
37
- selectedClients: string[];
38
- workspace?: string;
39
- confirmed: boolean;
40
- dryRun: boolean;
41
- }
42
-
43
- /**
44
- * Display welcome banner
45
- */
46
- export function showWelcome(): void {
47
- console.log(header('APIClaw MCP Auto-Setup'));
48
- console.log(colors.secondary('Configure APIClaw as an MCP server across your AI coding assistants.\n'));
49
- }
50
-
51
- /**
52
- * Prompt for client selection
53
- */
54
- export async function selectClients(clients: DetectedClient[]): Promise<string[]> {
55
- console.log(colors.info(`${icons.search} Detected MCP clients:\n`));
56
-
57
- // Show detection results
58
- for (const client of clients) {
59
- if (client.detected) {
60
- const status = client.alreadyConfigured
61
- ? colors.warning(`(already configured)`)
62
- : colors.success('(detected)');
63
- console.log(` ${icons.success} ${colors.highlight(client.name)} ${status}`);
64
- console.log(colors.muted(` ${client.configPath}`));
65
- } else {
66
- console.log(` ${icons.pending} ${colors.muted(client.name)} ${colors.muted('(not found)')}`);
67
- }
68
- }
69
- console.log();
70
-
71
- const detectedClients = clients.filter(c => c.detected);
72
-
73
- if (detectedClients.length === 0) {
74
- console.log(colors.warning('No MCP clients detected on this system.'));
75
- console.log(colors.secondary('\nYou can still configure a custom path.\n'));
76
- }
77
-
78
- const choices = clients.map(client => ({
79
- name: `${client.name}${client.detected ? '' : ' (not detected)'}${client.alreadyConfigured ? ' ⚠️ already configured' : ''}`,
80
- value: client.id,
81
- checked: client.detected && !client.alreadyConfigured,
82
- disabled: !client.detected && client.id !== 'custom' ? 'Not installed' : false,
83
- }));
84
-
85
- // Add custom option
86
- choices.push({
87
- name: 'Custom config path...',
88
- value: 'custom',
89
- checked: false,
90
- disabled: false,
91
- });
92
-
93
- const { selected } = await inquirer.prompt<{ selected: string[] }>([
94
- {
95
- type: 'checkbox',
96
- name: 'selected',
97
- message: 'Which clients do you want to configure?',
98
- choices,
99
- validate: (answer: string[]) => {
100
- if (answer.length === 0) {
101
- return 'Please select at least one client.';
102
- }
103
- return true;
104
- },
105
- },
106
- ]);
107
-
108
- return selected;
109
- }
110
-
111
- /**
112
- * Prompt for custom config path
113
- */
114
- export async function promptCustomPath(): Promise<string> {
115
- const { customPath } = await inquirer.prompt<{ customPath: string }>([
116
- {
117
- type: 'input',
118
- name: 'customPath',
119
- message: 'Enter the path to your MCP config file:',
120
- validate: (input: string) => {
121
- if (!input.trim()) {
122
- return 'Please enter a valid path.';
123
- }
124
- if (!input.endsWith('.json')) {
125
- return 'Config file should be a .json file.';
126
- }
127
- return true;
128
- },
129
- },
130
- ]);
131
-
132
- return customPath;
133
- }
134
-
135
- /**
136
- * Prompt for workspace ID
137
- */
138
- export async function promptWorkspace(): Promise<string | undefined> {
139
- const { hasWorkspace } = await inquirer.prompt<{ hasWorkspace: boolean }>([
140
- {
141
- type: 'confirm',
142
- name: 'hasWorkspace',
143
- message: 'Do you have an APIClaw workspace ID to link?',
144
- default: false,
145
- },
146
- ]);
147
-
148
- if (!hasWorkspace) {
149
- return undefined;
150
- }
151
-
152
- const { workspace } = await inquirer.prompt<{ workspace: string }>([
153
- {
154
- type: 'input',
155
- name: 'workspace',
156
- message: 'Enter your workspace ID:',
157
- validate: (input: string) => {
158
- if (!input.trim()) {
159
- return 'Please enter a workspace ID.';
160
- }
161
- if (!input.startsWith('ws_')) {
162
- return 'Workspace ID should start with "ws_"';
163
- }
164
- return true;
165
- },
166
- },
167
- ]);
168
-
169
- return workspace;
170
- }
171
-
172
- /**
173
- * Show preview of changes and confirm
174
- */
175
- export async function confirmChanges(
176
- changes: ConfigChange[],
177
- options: { dryRun?: boolean } = {}
178
- ): Promise<boolean> {
179
- console.log(header('Review Changes'));
180
-
181
- for (const change of changes) {
182
- const actionLabel = {
183
- create: colors.success('CREATE'),
184
- update: colors.warning('UPDATE'),
185
- skip: colors.muted('SKIP'),
186
- }[change.action];
187
-
188
- console.log(`${actionLabel} ${colors.highlight(change.clientName)}`);
189
- console.log(colors.muted(` ${change.configPath}\n`));
190
-
191
- if (change.diff) {
192
- console.log(codeBlock(change.diff));
193
- console.log();
194
- }
195
- }
196
-
197
- if (options.dryRun) {
198
- console.log(box(
199
- colors.info('Dry-run mode: No changes will be made.'),
200
- { borderColor: colors.info }
201
- ));
202
- console.log();
203
- return true;
204
- }
205
-
206
- const { confirmed } = await inquirer.prompt<{ confirmed: boolean }>([
207
- {
208
- type: 'confirm',
209
- name: 'confirmed',
210
- message: 'Apply these changes?',
211
- default: true,
212
- },
213
- ]);
214
-
215
- return confirmed;
216
- }
217
-
218
- /**
219
- * Prompt for force overwrite
220
- */
221
- export async function confirmForce(clientName: string): Promise<boolean> {
222
- const { force } = await inquirer.prompt<{ force: boolean }>([
223
- {
224
- type: 'confirm',
225
- name: 'force',
226
- message: `${clientName} already has APIClaw configured. Overwrite?`,
227
- default: false,
228
- },
229
- ]);
230
-
231
- return force;
232
- }
233
-
234
- /**
235
- * Show success message with next steps
236
- */
237
- export function showSuccess(configuredClients: string[]): void {
238
- console.log();
239
- console.log(box(
240
- `${icons.check} APIClaw configured successfully!\n\n` +
241
- `Configured: ${configuredClients.join(', ')}`,
242
- { title: 'Success', borderColor: colors.success }
243
- ));
244
-
245
- console.log(colors.secondary('\nNext steps:'));
246
- console.log(bulletList([
247
- `Restart ${configuredClients.join(' / ')}`,
248
- 'Ask your agent: "List available APIs"',
249
- ], 2));
250
-
251
- console.log(colors.secondary('\nNeed help?'));
252
- console.log(` ${colors.link('https://apiclaw.cloud/docs/setup')}\n`);
253
- }
254
-
255
- /**
256
- * Show dry-run summary
257
- */
258
- export function showDryRunSummary(changes: ConfigChange[]): void {
259
- console.log();
260
- console.log(box(
261
- `${icons.info} Dry-run complete\n\n` +
262
- `Would configure: ${changes.filter(c => c.action !== 'skip').length} client(s)\n` +
263
- `Would skip: ${changes.filter(c => c.action === 'skip').length} client(s)`,
264
- { title: 'Dry Run', borderColor: colors.info }
265
- ));
266
-
267
- console.log(colors.secondary('\nTo apply changes, run:'));
268
- console.log(colors.action(' npx @nordsym/apiclaw setup\n'));
269
- }
270
-
271
- /**
272
- * Run the full interactive wizard
273
- */
274
- export async function runWizard(
275
- clients: DetectedClient[],
276
- options: { dryRun?: boolean } = {}
277
- ): Promise<WizardResult> {
278
- showWelcome();
279
-
280
- // Select clients
281
- const selectedClients = await selectClients(clients);
282
-
283
- // Handle custom path if selected
284
- const finalClients = [...selectedClients];
285
- if (selectedClients.includes('custom')) {
286
- const customPath = await promptCustomPath();
287
- // Remove 'custom' placeholder and add actual path
288
- const idx = finalClients.indexOf('custom');
289
- finalClients[idx] = `custom:${customPath}`;
290
- }
291
-
292
- // Optionally link workspace
293
- const workspace = await promptWorkspace();
294
-
295
- // Build preview changes
296
- const changes: ConfigChange[] = finalClients.map(clientId => {
297
- const isCustom = clientId.startsWith('custom:');
298
- const client = isCustom
299
- ? { id: 'custom', name: 'Custom', configPath: clientId.replace('custom:', ''), alreadyConfigured: false }
300
- : clients.find(c => c.id === clientId)!;
301
-
302
- return {
303
- clientId: client.id,
304
- clientName: client.name,
305
- configPath: client.configPath,
306
- action: client.alreadyConfigured ? 'skip' : 'update',
307
- diff: generateDiff(workspace),
308
- };
309
- });
310
-
311
- // Confirm changes
312
- const confirmed = await confirmChanges(changes, { dryRun: options.dryRun });
313
-
314
- return {
315
- selectedClients: finalClients,
316
- workspace,
317
- confirmed,
318
- dryRun: options.dryRun || false,
319
- };
320
- }
321
-
322
- /**
323
- * Generate diff preview for config change
324
- */
325
- function generateDiff(workspace?: string): string {
326
- const lines = [
327
- added('"apiclaw": {'),
328
- added(' "command": "npx",'),
329
- added(' "args": ["-y", "@nordsym/apiclaw"]'),
330
- ];
331
-
332
- if (workspace) {
333
- lines.splice(2, 0, added(` "env": { "APICLAW_WORKSPACE": "${workspace}" },`));
334
- }
335
-
336
- lines.push(added('}'));
337
-
338
- return lines.join('\n');
339
- }
340
-
341
- /**
342
- * Prompt for restore backup selection
343
- */
344
- export async function selectBackup(backups: { path: string; date: Date; client: string }[]): Promise<string | null> {
345
- if (backups.length === 0) {
346
- console.log(colors.warning('No backups found.'));
347
- return null;
348
- }
349
-
350
- const choices = backups.map(b => ({
351
- name: `${b.client} - ${b.date.toLocaleString()} (${b.path})`,
352
- value: b.path,
353
- }));
354
-
355
- choices.push({
356
- name: 'Cancel',
357
- value: '',
358
- });
359
-
360
- const { backup } = await inquirer.prompt<{ backup: string }>([
361
- {
362
- type: 'list',
363
- name: 'backup',
364
- message: 'Select a backup to restore:',
365
- choices,
366
- },
367
- ]);
368
-
369
- return backup || null;
370
- }
371
-
372
- /**
373
- * Confirm uninstall
374
- */
375
- export async function confirmUninstall(clients: string[]): Promise<boolean> {
376
- console.log(colors.warning('\n⚠️ This will remove APIClaw from:\n'));
377
- console.log(bulletList(clients, 2));
378
- console.log();
379
-
380
- const { confirmed } = await inquirer.prompt<{ confirmed: boolean }>([
381
- {
382
- type: 'confirm',
383
- name: 'confirmed',
384
- message: 'Are you sure you want to uninstall APIClaw?',
385
- default: false,
386
- },
387
- ]);
388
-
389
- return confirmed;
390
- }
package/src/ui/spinner.ts DELETED
@@ -1,325 +0,0 @@
1
- /**
2
- * APIClaw MCP Auto-Setup - Spinner Utilities
3
- *
4
- * Ora-based spinner wrapper with consistent styling and state management.
5
- * Provides a fluent API for progress indication during CLI operations.
6
- */
7
-
8
- import ora, { Ora, Options as OraOptions } from 'ora';
9
- import { colors, icons } from './colors.js';
10
-
11
- export interface SpinnerOptions {
12
- /** Spinner text */
13
- text?: string;
14
- /** Prefix text before spinner */
15
- prefix?: string;
16
- /** Suffix text after spinner */
17
- suffix?: string;
18
- /** Whether to show spinner in CI environments */
19
- showInCI?: boolean;
20
- /** Custom spinner frames */
21
- spinner?: OraOptions['spinner'];
22
- }
23
-
24
- export interface TaskSpinner {
25
- /** Start the spinner with optional text */
26
- start(text?: string): TaskSpinner;
27
- /** Update spinner text */
28
- text(text: string): TaskSpinner;
29
- /** Mark as successful with optional message */
30
- succeed(text?: string): TaskSpinner;
31
- /** Mark as failed with optional message */
32
- fail(text?: string): TaskSpinner;
33
- /** Mark as warning with optional message */
34
- warn(text?: string): TaskSpinner;
35
- /** Show info message without stopping */
36
- info(text?: string): TaskSpinner;
37
- /** Stop spinner without status */
38
- stop(): TaskSpinner;
39
- /** Stop and clear spinner */
40
- clear(): TaskSpinner;
41
- /** Check if spinner is currently spinning */
42
- isSpinning(): boolean;
43
- /** Access underlying ora instance */
44
- readonly ora: Ora;
45
- }
46
-
47
- /**
48
- * Create a task spinner with APIClaw styling
49
- */
50
- export function createSpinner(options: SpinnerOptions = {}): TaskSpinner {
51
- const {
52
- text = '',
53
- prefix = '',
54
- suffix = '',
55
- showInCI = false,
56
- spinner = 'dots',
57
- } = options;
58
-
59
- const oraInstance = ora({
60
- text,
61
- prefixText: prefix,
62
- suffixText: suffix,
63
- spinner,
64
- // Disable spinner in CI by default for cleaner logs
65
- isEnabled: showInCI || !process.env.CI,
66
- });
67
-
68
- const wrapper: TaskSpinner = {
69
- start(newText?: string) {
70
- if (newText) oraInstance.text = newText;
71
- oraInstance.start();
72
- return wrapper;
73
- },
74
-
75
- text(newText: string) {
76
- oraInstance.text = newText;
77
- return wrapper;
78
- },
79
-
80
- succeed(newText?: string) {
81
- oraInstance.succeed(newText);
82
- return wrapper;
83
- },
84
-
85
- fail(newText?: string) {
86
- oraInstance.fail(newText);
87
- return wrapper;
88
- },
89
-
90
- warn(newText?: string) {
91
- oraInstance.warn(newText);
92
- return wrapper;
93
- },
94
-
95
- info(newText?: string) {
96
- oraInstance.info(newText);
97
- return wrapper;
98
- },
99
-
100
- stop() {
101
- oraInstance.stop();
102
- return wrapper;
103
- },
104
-
105
- clear() {
106
- oraInstance.stopAndPersist({ symbol: '' });
107
- return wrapper;
108
- },
109
-
110
- isSpinning() {
111
- return oraInstance.isSpinning;
112
- },
113
-
114
- get ora() {
115
- return oraInstance;
116
- },
117
- };
118
-
119
- return wrapper;
120
- }
121
-
122
- /**
123
- * Convenience function for common spinner patterns
124
- */
125
- export const spinner = {
126
- /**
127
- * Create and start a spinner in one call
128
- */
129
- start(text: string): TaskSpinner {
130
- return createSpinner({ text }).start();
131
- },
132
-
133
- /**
134
- * Run an async task with spinner, auto-succeed/fail
135
- */
136
- async task<T>(
137
- text: string,
138
- fn: (spinner: TaskSpinner) => Promise<T>,
139
- options: {
140
- successText?: string | ((result: T) => string);
141
- failText?: string | ((error: Error) => string);
142
- } = {}
143
- ): Promise<T> {
144
- const s = createSpinner({ text }).start();
145
-
146
- try {
147
- const result = await fn(s);
148
- const successMsg = typeof options.successText === 'function'
149
- ? options.successText(result)
150
- : options.successText || text;
151
- s.succeed(successMsg);
152
- return result;
153
- } catch (error) {
154
- const failMsg = typeof options.failText === 'function'
155
- ? options.failText(error as Error)
156
- : options.failText || `${text} - Failed`;
157
- s.fail(failMsg);
158
- throw error;
159
- }
160
- },
161
-
162
- /**
163
- * Run multiple tasks in sequence with spinners
164
- */
165
- async sequence<T>(
166
- tasks: Array<{
167
- text: string;
168
- task: () => Promise<T>;
169
- successText?: string;
170
- failText?: string;
171
- }>
172
- ): Promise<T[]> {
173
- const results: T[] = [];
174
-
175
- for (const { text, task, successText, failText } of tasks) {
176
- const result = await this.task(text, task, { successText, failText });
177
- results.push(result);
178
- }
179
-
180
- return results;
181
- },
182
- };
183
-
184
- /**
185
- * Progress tracker for multi-step operations
186
- */
187
- export class ProgressTracker {
188
- private current = 0;
189
- private readonly total: number;
190
- private readonly items: string[];
191
- private readonly taskSpinner: TaskSpinner;
192
-
193
- constructor(items: string[]) {
194
- this.items = items;
195
- this.total = items.length;
196
- this.taskSpinner = createSpinner();
197
- }
198
-
199
- /**
200
- * Start tracking progress
201
- */
202
- start(): void {
203
- this.current = 0;
204
- this.updateText();
205
- this.taskSpinner.start();
206
- }
207
-
208
- /**
209
- * Move to next item
210
- */
211
- next(): void {
212
- this.current++;
213
- this.updateText();
214
- }
215
-
216
- /**
217
- * Mark current item as done and move to next
218
- */
219
- done(message?: string): void {
220
- this.taskSpinner.succeed(message || this.items[this.current - 1]);
221
- if (this.current < this.total) {
222
- this.taskSpinner.start(this.formatProgress());
223
- }
224
- }
225
-
226
- /**
227
- * Mark as complete
228
- */
229
- complete(message: string): void {
230
- this.taskSpinner.succeed(message);
231
- }
232
-
233
- /**
234
- * Mark as failed
235
- */
236
- fail(message: string): void {
237
- this.taskSpinner.fail(message);
238
- }
239
-
240
- private updateText(): void {
241
- this.taskSpinner.text(this.formatProgress());
242
- }
243
-
244
- private formatProgress(): string {
245
- const item = this.items[this.current] || 'Processing...';
246
- return `[${this.current + 1}/${this.total}] ${item}`;
247
- }
248
- }
249
-
250
- /**
251
- * Silent spinner for non-interactive/CI environments
252
- * Logs plain text instead of animated spinners
253
- */
254
- export function createSilentSpinner(options: SpinnerOptions = {}): TaskSpinner {
255
- const log = (symbol: string, text?: string) => {
256
- if (text) {
257
- console.log(`${symbol} ${text}`);
258
- }
259
- };
260
-
261
- let currentText = options.text || '';
262
-
263
- const wrapper: TaskSpinner = {
264
- start(text?: string) {
265
- currentText = text || currentText;
266
- log(colors.muted('○'), currentText);
267
- return wrapper;
268
- },
269
-
270
- text(text: string) {
271
- currentText = text;
272
- return wrapper;
273
- },
274
-
275
- succeed(text?: string) {
276
- log(icons.success, text || currentText);
277
- return wrapper;
278
- },
279
-
280
- fail(text?: string) {
281
- log(icons.error, text || currentText);
282
- return wrapper;
283
- },
284
-
285
- warn(text?: string) {
286
- log(icons.warning, text || currentText);
287
- return wrapper;
288
- },
289
-
290
- info(text?: string) {
291
- log(icons.info, text || currentText);
292
- return wrapper;
293
- },
294
-
295
- stop() {
296
- return wrapper;
297
- },
298
-
299
- clear() {
300
- return wrapper;
301
- },
302
-
303
- isSpinning() {
304
- return false;
305
- },
306
-
307
- get ora(): Ora {
308
- // Return a mock for compatibility
309
- return {} as Ora;
310
- },
311
- };
312
-
313
- return wrapper;
314
- }
315
-
316
- /**
317
- * Get appropriate spinner based on environment
318
- */
319
- export function getSpinner(options: SpinnerOptions = {}): TaskSpinner {
320
- // Use silent spinner in CI or when stdout is not a TTY
321
- if (process.env.CI || !process.stdout.isTTY) {
322
- return createSilentSpinner(options);
323
- }
324
- return createSpinner(options);
325
- }