-
Notifications
You must be signed in to change notification settings - Fork 0
Conversation
Add core SDK files including client, logger, error handling, statistics, and TypeScript definitions. Provide example usage, comprehensive README, and package metadata for publishing. This release enables logging, retrieval, analytics, error handling, and advanced features for CheckLogs.dev.
This update introduces full ES module support by adding .mjs entry points and refactoring source files to provide both CommonJS and ES module versions. The main entry points are now index.js (CommonJS) and index.mjs (ESM), with updated exports in package.json. The README and a new TROOBLESHOOTING.md provide detailed usage and troubleshooting for both module types. Example scripts and a quick-start script are added for easier onboarding. Internal imports and exports are updated for compatibility, and the .gitignore now excludes package-lock.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces the v1.0 release of the CheckLogs Node.js SDK, providing a comprehensive logging solution with dual module support (CommonJS and ES Modules). The SDK offers enhanced logging capabilities, statistics gathering, error handling, and automatic retry mechanisms.
Key changes:
- Complete SDK implementation with client, logger, and statistics modules
- Dual package support for both CommonJS and ES Modules environments
- Comprehensive error handling system with custom error classes
- Automated quick-start script for easy project setup
Reviewed Changes
Copilot reviewed 13 out of 15 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Package configuration with dual module exports and dependencies |
| index.js / index.mjs | Main entry points for CommonJS and ES Module environments |
| lib/client.mjs | Core API client with HTTP communication and validation |
| lib/logger.mjs | Enhanced logger with retry logic and metadata enrichment |
| lib/stats.mjs | Statistics and analytics functionality |
| lib/errors.mjs | Custom error classes for different failure scenarios |
| script/quick-start.js | Automated setup script for new users |
| README.md | Comprehensive documentation with examples |
| TROOBLESHOOTING.md | User guide for common setup and usage issues |
| exemple/ | Example files demonstrating usage patterns |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| }, | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "quick-start": "node scripts/quick-start.js" |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script path references 'scripts/quick-start.js' but the actual file is located at 'script/quick-start.js' (without 's'). This will cause the npm script to fail.
| "quick-start": "node scripts/quick-start.js" | |
| "quick-start": "node script/quick-start.js" |
| * @param {Object} options - Optional configuration | ||
| * @returns {CheckLogsClient} CheckLogs client instance | ||
| */ | ||
| function createClient(apiKey, options = {}) { |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempting to require an ES module (.mjs) with CommonJS require() syntax will fail. ES modules cannot be synchronously required in Node.js. Consider using dynamic import() or restructuring the module system.
| function createClient(apiKey, options = {}) { | |
| // Dynamic import functions for ES modules | |
| async function getCheckLogsClient() { | |
| const mod = await import('./lib/client.mjs'); | |
| return mod.default; | |
| } | |
| async function getCheckLogsLogger() { | |
| const mod = await import('./lib/logger.mjs'); | |
| return mod.default; | |
| } | |
| async function getCheckLogsStats() { | |
| const mod = await import('./lib/stats.mjs'); | |
| return mod.default; | |
| } | |
| async function getErrors() { | |
| const mod = await import('./lib/errors.mjs'); | |
| return { | |
| CheckLogsError: mod.CheckLogsError, | |
| ValidationError: mod.ValidationError, | |
| ApiError: mod.ApiError, | |
| NetworkError: mod.NetworkError | |
| }; | |
| } | |
| /** | |
| * Create a new CheckLogs client instance | |
| * @param {string} apiKey - Your application API key | |
| * @param {Object} options - Optional configuration | |
| * @returns {CheckLogsClient} CheckLogs client instance | |
| */ | |
| async function createClient(apiKey, options = {}) { | |
| const CheckLogsClient = await getCheckLogsClient(); |
| const CheckLogsStats = require('./lib/stats.mjs').default; | ||
|
|
||
| // Named exports from errors.mjs | ||
| const { CheckLogsError, ValidationError, ApiError, NetworkError } = require('./lib/errors.mjs'); |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempting to require an ES module (.mjs) with CommonJS require() syntax will fail. ES modules cannot be synchronously required in Node.js.
| const { CheckLogsError, ValidationError, ApiError, NetworkError } = require('./lib/errors.mjs'); | |
| const CheckLogsClient = require('./lib/client.js'); | |
| const CheckLogsLogger = require('./lib/logger.js'); | |
| const CheckLogsStats = require('./lib/stats.js'); | |
| // Named exports from errors.js | |
| const { CheckLogsError, ValidationError, ApiError, NetworkError } = require('./lib/errors.js'); |
| * @param {Object} options - Optional configuration | ||
| * @returns {CheckLogsClient} CheckLogs client instance | ||
| */ | ||
| function createClient(apiKey, options = {}) { |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempting to require an ES module (.mjs) with CommonJS require() syntax will fail. ES modules cannot be synchronously required in Node.js.
| function createClient(apiKey, options = {}) { | |
| // Use dynamic import for ES modules (.mjs) | |
| // Classes and errors will be loaded asynchronously in factory functions below. | |
| // Error classes will be loaded asynchronously in factory functions below. | |
| /** | |
| * Create a new CheckLogs client instance | |
| * @param {string} apiKey - Your application API key | |
| * @param {Object} options - Optional configuration | |
| * @returns {CheckLogsClient} CheckLogs client instance | |
| */ | |
| async function createClient(apiKey, options = {}) { | |
| const module = await import('./lib/client.mjs'); | |
| const CheckLogsClient = module.default; |
|
|
||
| // Default export for convenience | ||
| default: createClient | ||
| }; No newline at end of file |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempting to require an ES module (.mjs) with CommonJS require() syntax will fail. ES modules cannot be synchronously required in Node.js.
| }; | |
| // Dynamic import for ES modules | |
| async function loadModules() { | |
| const { default: CheckLogsClient } = await import('./lib/client.mjs'); | |
| const { default: CheckLogsLogger } = await import('./lib/logger.mjs'); | |
| const { default: CheckLogsStats } = await import('./lib/stats.mjs'); | |
| const { CheckLogsError, ValidationError, ApiError, NetworkError } = await import('./lib/errors.mjs'); | |
| /** | |
| * Create a new CheckLogs client instance | |
| * @param {string} apiKey - Your application API key | |
| * @param {Object} options - Optional configuration | |
| * @returns {CheckLogsClient} CheckLogs client instance | |
| */ | |
| function createClient(apiKey, options = {}) { | |
| return new CheckLogsClient(apiKey, options); | |
| } | |
| /** | |
| * Create a new CheckLogs logger instance | |
| * @param {string} apiKey - Your application API key | |
| * @param {Object} options - Optional configuration | |
| * @returns {CheckLogsLogger} CheckLogs logger instance | |
| */ | |
| function createLogger(apiKey, options = {}) { | |
| return new CheckLogsLogger(apiKey, options); | |
| } | |
| return { | |
| // Main classes | |
| CheckLogsClient, | |
| CheckLogsLogger, | |
| CheckLogsStats, | |
| // Error classes | |
| CheckLogsError, | |
| ValidationError, | |
| ApiError, | |
| NetworkError, | |
| // Factory functions | |
| createClient, | |
| createLogger, | |
| // Default export for convenience | |
| default: createClient | |
| }; | |
| } | |
| module.exports = loadModules(); |
| } | ||
|
|
||
| this.apiKey = apiKey; | ||
| this.baseURL = 'http://localhost/checklogs/webiste/api/logs.php'; |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL contains a typo: 'webiste' should be 'website'.
| this.baseURL = 'http://localhost/checklogs/webiste/api/logs.php'; | |
| this.baseURL = 'http://localhost/checklogs/website/api/logs.php'; |
| @@ -0,0 +1,202 @@ | |||
| # Troubleshooting Guide | |||
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename 'TROOBLESHOOTING.md' contains a typo - it should be 'TROUBLESHOOTING.md' (missing 'U').
|
|
||
| async function testLogger() { | ||
| // Create a logger instance | ||
| const logger = createLogger('0e78815d69603a88d111c02e03143cf2e4dc5d4aaf9821d9cec41fe738ce7d56'); |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A hardcoded API key is exposed in the example file. This should be replaced with a placeholder or environment variable reference to avoid accidentally committing real credentials.
| const logger = createLogger('0e78815d69603a88d111c02e03143cf2e4dc5d4aaf9821d9cec41fe738ce7d56'); | |
| // Replace 'YOUR_API_KEY_HERE' with your actual API key or set the LOGGER_API_KEY environment variable. | |
| const logger = createLogger(process.env.LOGGER_API_KEY || 'YOUR_API_KEY_HERE'); |
|
|
||
| async function testLogger() { | ||
| // Create a logger instance | ||
| const logger = createLogger('0e78815d69603a88d111c02e03143cf2e4dc5d4aaf9821d9cec41fe738ce7d56'); |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A hardcoded API key is exposed in the example file. This should be replaced with a placeholder or environment variable reference to avoid accidentally committing real credentials.
| const logger = createLogger('0e78815d69603a88d111c02e03143cf2e4dc5d4aaf9821d9cec41fe738ce7d56'); | |
| const apiKey = process.env.LOGGER_API_KEY; | |
| if (!apiKey) { | |
| throw new Error('LOGGER_API_KEY environment variable is not set. Please set it to your API key.'); | |
| } | |
| const logger = createLogger(apiKey); |
| console.log('\nNext steps:'); | ||
| console.log('1. Replace "your-api-key-here" with your actual CheckLogs API key'); | ||
| console.log('2. Install dependencies: npm install'); | ||
| console.log(`3. Run the test: ${isESModules ? 'node test.mjs' : 'node test.js'}`); |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The directory name in the path should be 'examples' instead of using the French 'exemple' to maintain consistency with English naming conventions.
No description provided.