paymongo-cli 1.4.6 → 1.4.8

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 (39) hide show
  1. package/AGENTS.md +8 -6
  2. package/CHANGELOG.md +77 -1
  3. package/README.md +7 -5
  4. package/TESTING.md +6 -7
  5. package/dist/.tsbuildinfo +1 -1
  6. package/dist/commands/config/actions.js +233 -0
  7. package/dist/commands/config/helpers.js +153 -0
  8. package/dist/commands/config/rate-limit.js +138 -0
  9. package/dist/commands/config.js +5 -565
  10. package/dist/commands/dev/logs.js +3 -3
  11. package/dist/commands/dev/status.js +2 -2
  12. package/dist/commands/dev/stop.js +3 -3
  13. package/dist/commands/dev.js +11 -7
  14. package/dist/commands/env.js +6 -6
  15. package/dist/commands/init.js +4 -4
  16. package/dist/commands/login.js +4 -4
  17. package/dist/commands/payments/actions.js +346 -0
  18. package/dist/commands/payments/helpers.js +62 -0
  19. package/dist/commands/payments.js +2 -458
  20. package/dist/commands/team/index.js +7 -6
  21. package/dist/commands/trigger/actions.js +293 -0
  22. package/dist/commands/trigger/helpers.js +230 -0
  23. package/dist/commands/trigger.js +3 -524
  24. package/dist/commands/webhooks/actions.js +426 -0
  25. package/dist/commands/webhooks/helpers.js +42 -0
  26. package/dist/commands/webhooks.js +2 -493
  27. package/dist/index.js +9 -2
  28. package/dist/services/analytics/service.js +19 -18
  29. package/dist/services/api/client.js +15 -15
  30. package/dist/services/config/manager.js +1 -1
  31. package/dist/services/dev/process-manager.js +30 -32
  32. package/dist/services/dev/server.js +46 -40
  33. package/dist/types/schemas.js +12 -0
  34. package/dist/utils/bulk.js +36 -4
  35. package/dist/utils/constants.js +11 -1
  36. package/dist/utils/errors.js +6 -0
  37. package/dist/utils/validator.js +10 -9
  38. package/dist/utils/webhook-store.js +18 -15
  39. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  ## Project Overview
4
4
 
5
- PayMongo CLI is a developer-first command-line tool for PayMongo payment integration with local webhook forwarding. It uses **ESM modules** with Commander.js for CLI commands and provides both terminal and web-based interfaces.
5
+ PayMongo CLI is a developer-first command-line tool for PayMongo payment integration with local webhook forwarding. It uses **ESM modules** with Commander.js for CLI commands and provides a terminal-first interface.
6
6
 
7
- **Tech Stack**: TypeScript, Node.js 18+, Express, Socket.io, ngrok, Axios, Zod, Winston, Jest
7
+ **Tech Stack**: TypeScript, Node.js 20+, Commander.js, built-in `http`, `undici`, ngrok, Zod, Jest
8
8
 
9
9
  ---
10
10
 
@@ -134,8 +134,10 @@ src/
134
134
  ├── services/ # Business logic
135
135
  │ ├── api/ # PayMongo API client
136
136
  │ ├── config/ # Configuration management
137
- │ ├── web/ # Express + Socket.io server
138
- └── github/ # GitHub integration
137
+ │ ├── dev/ # Local dev server + process management
138
+ ├── analytics/ # Local webhook analytics
139
+ │ ├── payments/ # Payment simulation helpers
140
+ │ └── team/ # Team key-sharing workflows
139
141
  ├── types/ # TypeScript definitions + Zod schemas
140
142
  ├── utils/ # Shared utilities
141
143
  └── index.ts # CLI entry point
@@ -174,8 +176,8 @@ tests/
174
176
  Use `jest.unstable_mockModule()` before dynamic imports:
175
177
 
176
178
  ```typescript
177
- jest.unstable_mockModule('axios', () => ({
178
- default: mockAxios,
179
+ jest.unstable_mockModule('undici', () => ({
180
+ request: mockRequest,
179
181
  }));
180
182
 
181
183
  const { ApiClient } = await import('../../src/services/api/client.js');
package/CHANGELOG.md CHANGED
@@ -7,6 +7,57 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.4.8] - 2026-03-08
11
+
12
+ ### Changed
13
+
14
+ - **Command Modularization** - Refactored the large `config`, `payments`, `webhooks`, and `trigger` command files into focused helper/action modules to improve maintainability and make future changes safer.
15
+ - **Test Execution** - Reworked CLI entry/config integration tests to avoid subprocess spawning in restricted environments while preserving end-to-end behavior checks.
16
+ - **Documentation Alignment** - Updated README, installation, user guide, troubleshooting, testing, and contributor guidance to match the current Node 20+ runtime, `undici` network layer, ngrok token handling, and local team key-sharing workflow.
17
+
18
+ ### Fixed
19
+
20
+ - **Config Validation Drift** - Added `rateLimiting` to the Zod configuration schema so runtime validation matches the declared config type and command behavior.
21
+ - **CLI Test Reliability** - Eliminated environment-specific `EPERM` failures in spawn-based tests by switching to sandbox-friendly execution patterns.
22
+ - **Release Metadata** - Synchronized package metadata by updating the npm package version and lockfile version fields to the current release line.
23
+
24
+ ### Security
25
+
26
+ - **Webhook Verification Defaults** - New configs now enable webhook signature verification by default, and the dev server now rejects requests when verification is enabled but no webhook secret is configured.
27
+ - **Secret Messaging** - Clarified CLI messaging around webhook secret storage to describe the actual `.paymongo` storage location.
28
+
29
+ ## [1.4.7] - 2026-02-27
30
+
31
+ ### Changed
32
+
33
+ - **Error Handling** - Replaced all 60 `process.exit(1)` calls across 10 command files with a `CommandError` throw pattern and centralized global error handler in `index.ts`.
34
+ - **CLI Version** - Version string is now dynamically read from `package.json` instead of being hardcoded, keeping User-Agent headers and `--version` output always in sync.
35
+ - **Magic Numbers** - Extracted hardcoded cache TTL, rate limit thresholds, and API base URL into named constants in `constants.ts`.
36
+ - **Async File I/O** - Converted synchronous `fs` operations to `fs/promises` in dev-mode hot paths:
37
+ - `webhook-store.ts`: Lazy async directory creation, all read/write operations non-blocking.
38
+ - `analytics/service.ts`: Async persistence with `_ready` promise to prevent constructor race conditions.
39
+ - `process-manager.ts`: All static methods async; updated 13 call sites across dev subcommands.
40
+ - **Deduplicated ValidationError** - Removed duplicate `ValidationError` class from `validator.ts`; single definition now lives in `errors.ts` and is re-exported.
41
+ - **DevServer Logging** - Replaced raw `console.log`/`console.error` calls in `DevServer` with structured `Logger` instance for consistent, controllable output.
42
+
43
+ ### Fixed
44
+
45
+ - **Input Sanitization** - Enhanced `validateWebhookUrl()` with max URL length (2048 chars), automatic whitespace trimming, and rejection of URLs containing embedded credentials.
46
+ - **Race Condition** - Fixed analytics service race where `loadEvents()` could overwrite in-memory state written by `recordEvent()` before async load completed.
47
+ - **Unhandled Promises** - `recordEvent()` calls in `DevServer` are now properly awaited via extracted `processWebhookBody()` method, preventing silent failures.
48
+ - **Bulk Import Errors** - `importWebhooks()` and `importPayments()` now catch file-not-found and malformed JSON errors, throwing descriptive `PayMongoError` instead of raw stack traces.
49
+
50
+ ### Added
51
+
52
+ - **Unit Tests** - Added 62 new tests across 3 previously-uncovered modules:
53
+ - `BulkOperations` (19 tests): export/import, file errors, JSON validation, filename generation.
54
+ - `DevProcessManager` (22 tests): state persistence, process detection, log management, uptime formatting.
55
+ - `TeamService` (21 tests): key bundles, member management, serialization, team operations.
56
+
57
+ ### Security
58
+
59
+ - Webhook URL validation now blocks URLs with embedded `user:pass@` credentials to prevent credential leakage.
60
+
10
61
  ## [1.4.6] - 2026-02-03
11
62
 
12
63
  ### Changed
@@ -315,6 +366,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
315
366
 
316
367
  | Version | Release Date | Highlights |
317
368
  | ------- | ------------ | -------------------------------------------------------------------- |
369
+ | [1.4.7] | 2026-02-27 | CommandError pattern, dynamic version, async FS, input sanitization |
370
+ | [1.4.6] | 2026-02-03 | Config validation, webhook signatures, lazy loading |
371
+ | [1.4.5] | 2026-02-01 | AES-256-GCM encryption, .gitignore handling |
372
+ | [1.4.4] | 2026-01-27 | Codebase modularization, integration testing |
318
373
  | [1.4.3] | 2026-01-26 | Enhanced error handling, test output cleanup, API client consolidation |
319
374
  | [1.4.1] | 2026-01-26 | Test coverage completion, ESLint compliance, documentation updates |
320
375
  | [1.4.0] | 2026-01-26 | Code generation, HTTP client migration, GUI removal, performance optimization |
@@ -326,6 +381,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
326
381
  ---
327
382
 
328
383
  ## Upgrade Guide
384
+ ### Upgrading to 1.4.7
385
+
386
+ ```bash
387
+ npm install -g paymongo-cli@latest
388
+ ```
389
+
390
+ **Breaking Changes:** None. This is a backward-compatible patch release.
391
+
392
+ **Improvements:**
393
+ - All `process.exit(1)` calls replaced with structured error handling — CLI now exits cleanly through global error handlers
394
+ - Sync file I/O in dev-mode hot paths converted to async for better event loop performance
395
+ - Webhook URL validation hardened against credential leakage and oversized inputs
396
+ - CLI version always matches `package.json` — no more stale User-Agent strings
397
+ - Duplicate `ValidationError` class consolidated to single definition
398
+ - DevServer uses structured Logger instead of raw console output
399
+ - Bulk import operations now produce user-friendly error messages
400
+ - 62 new unit tests covering BulkOperations, DevProcessManager, and TeamService
401
+
329
402
  ### Upgrading to 1.4.3
330
403
 
331
404
  ```bash
@@ -417,7 +490,10 @@ npm install -g paymongo-cli
417
490
  - [Issue Tracker](https://github.com/leodyversemilla07/paymongo-cli/issues)
418
491
  - [PayMongo API Documentation](https://developers.paymongo.com/)
419
492
 
420
- [Unreleased]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.4...HEAD
493
+ [Unreleased]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.7...HEAD
494
+ [1.4.7]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.6...v1.4.7
495
+ [1.4.6]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.5...v1.4.6
496
+ [1.4.5]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.4...v1.4.5
421
497
  [1.4.4]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.3...v1.4.4
422
498
  [1.4.3]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.1...v1.4.3
423
499
  [1.4.1]: https://github.com/leodyversemilla07/paymongo-cli/compare/v1.4.0...v1.4.1
package/README.md CHANGED
@@ -17,10 +17,10 @@ PayMongo CLI is the official-feel command-line tool designed to streamline your
17
17
  - **Payment Testing**: Create and monitor payment intents and payments directly from your terminal.
18
18
  - **Real-time Monitoring**: Watch webhook events as they happen with formatted terminal logs.
19
19
  - **Privacy-First Analytics**: Optional local webhook event tracking to improve your development workflow (opt-in only).
20
- - **Team Collaboration**: Sync configurations across your team using GitHub integration.
20
+ - **Team Collaboration**: Share API key bundles with teammates for test/live environments.
21
21
  - **Bulk Operations**: Import/export payments and webhooks for easy migration between environments.
22
22
  - **Rate Limiting Protection**: Built-in API abuse prevention with configurable limits and automatic backoff.
23
- - **Secure Management**: Encrypted storage for your API keys.
23
+ - **Secure Management**: Local credential encryption for stored login sessions.
24
24
 
25
25
  ---
26
26
 
@@ -43,10 +43,12 @@ To use the `dev` server with webhook forwarding, you need an ngrok authtoken:
43
43
 
44
44
  1. Sign up at [ngrok.com](https://ngrok.com)
45
45
  2. Copy your authtoken from the [ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken)
46
- 3. Configure it in the CLI:
46
+ 3. Configure it via environment variable or pass it at runtime:
47
47
 
48
48
  ```bash
49
- paymongo config set ngrok.authtoken YOUR_AUTHTOKEN
49
+ export NGROK_AUTHTOKEN=YOUR_AUTHTOKEN
50
+ # or
51
+ paymongo dev --ngrok-token YOUR_AUTHTOKEN
50
52
  ```
51
53
 
52
54
  ---
@@ -168,7 +170,7 @@ Analytics data helps you:
168
170
  | `paymongo config` | View and modify CLI configuration. |
169
171
  | `paymongo config analytics` | Configure webhook analytics settings. |
170
172
  | `paymongo config rate-limit` | Configure rate limiting settings. |
171
- | `paymongo team` | Sync configurations with your team via GitHub. |
173
+ | `paymongo team` | Share API key bundles with your team. |
172
174
  | `paymongo trigger` | Simulate webhook events locally for testing. |
173
175
 
174
176
  > Use `paymongo <command> --help` for detailed information on any command.
package/TESTING.md CHANGED
@@ -4,12 +4,12 @@
4
4
 
5
5
  This document tracks the progress of improving test coverage for the PayMongo CLI project from the initial ~12% to the target 80-85%.
6
6
 
7
- ## Current Status (2026-01-25)
7
+ ## Current Status (2026-03-08)
8
8
 
9
- - **Overall Coverage**: ~65-70% statements (estimated post-all command testing completion)
9
+ - **Overall Coverage**: strong command and service coverage with full green suite
10
10
  - **Target**: ≥80% statements/branches/functions/lines
11
11
  - **Progress**: API client, init command, config command, login command, dev command, env command, trigger command, webhooks command, CLI entry point, and payments command testing completed
12
- - **Total Tests**: 380 passing tests across 23 test suites
12
+ - **Total Tests**: 459 passing tests across 29 test suites
13
13
 
14
14
  ## Completed Work
15
15
 
@@ -79,9 +79,8 @@ This document tracks the progress of improving test coverage for the PayMongo CL
79
79
  - Resolved testing challenges: crypto timingSafeEqual mocking, HTTP request/response simulation, ESM module mocking for complex dependencies
80
80
 
81
81
  - **CLI Entry Point Testing**: ✅ **COMPLETED**
82
- - Created integration tests in `tests/unit/index.test.ts` with 3 test cases
83
82
  - Tests verify CLI initialization, help display, version information, and error handling
84
- - Uses subprocess spawning to test actual CLI behavior rather than complex module mocking
83
+ - Uses in-process execution instead of subprocess spawning for sandbox-friendly test runs
85
84
 
86
85
  - **Payments Command Testing**: ✅ **COMPLETED**
87
86
  - Created comprehensive test file `tests/unit/payments-command.test.ts` with 20 test cases achieving 100% coverage
@@ -195,7 +194,7 @@ This document tracks the progress of improving test coverage for the PayMongo CL
195
194
 
196
195
  1. **ESM Mocking Complexity**: Required careful setup of `jest.unstable_mockModule()` for modern ES modules
197
196
  2. **Interceptor Testing**: Needed to test interceptor functions directly rather than through full API calls
198
- 3. **Error Handler Mocking**: Complex to mock axios.isAxiosError in interceptor context
197
+ 3. **Network Layer Mocking**: `undici` request/response behavior requires careful ESM mocking
199
198
  4. **Commander.js Testing**: Resolved by extracting command action logic to separate exported function for direct testing
200
199
  5. **Console Mocking**: Required global.console usage for reliable spy functionality across test suites
201
200
  6. **ESM Module Resolution**: Fixed import path issues in tests by using '../../src/' prefix for consistency
@@ -219,4 +218,4 @@ This document tracks the progress of improving test coverage for the PayMongo CL
219
218
 
220
219
  ---
221
220
 
222
- _Last updated: 2026-01-25_
221
+ _Last updated: 2026-03-08_