rpc-express-toolkit 2.3.3 → 3.0.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.
@@ -1,80 +1,100 @@
1
- /**
2
- * Example demonstratin // Example 3: Best practices
3
- console.log('3. Best Practices:');
4
- console.log(' ✓ Always use SSL validation in production');
5
- console.log(' ✓ Disable validation only for development with self-signed certificates');
6
- console.log(' ✓ Use environment variables to control SSL behavior');
7
- console.log(' ✓ Never commit process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" to production');
8
- console.log(' ✓ Consider using valid development certificates instead of disabling validation\n');o use RpcClient with self-signed certificates
9
- * in development environments.
10
- *
11
- * WARNING: Only use rejectUnauthorized: false in development!
12
- * Never use this in production as it disables SSL certificate validation.
13
- */
14
-
15
- const { RpcClient } = require('../src/index.js');
16
-
17
- async function demonstrateSSLOptions() {
18
- console.log('=== RPC Client SSL Configuration Example ===\n');
19
-
20
- // Example 1: Standard production client (default - strict SSL)
21
- console.log('1. Production Client (strict SSL validation):');
22
- const productionClient = new RpcClient('https://api.example.com/rpc', {
23
- 'Authorization': 'Bearer prod-token'
24
- });
25
- console.log(' ✓ Created client with strict SSL validation (default)\n');
26
-
27
-
28
-
29
- // Example 2: Development client for self-signed certificates (bypasses ALL SSL validation)
30
- console.log('2. Development Client (bypasses SSL validation):');
31
- console.log(' ⚠️ To bypass SSL validation in Node.js, set BEFORE starting the client:');
32
- console.log(' process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";');
33
- console.log(' ✓ All requests will accept self-signed certificates (development only!)\n');
34
-
35
- // Example 3: Best practice
36
- console.log('3. Best Practices:');
37
- console.log(' ✓ Usa sempre la validazione SSL in produzione');
38
- console.log(' ✓ Disabilita la validazione solo per sviluppo con self-signed');
39
- console.log(' ✓ Usa variabili d’ambiente per controllare il comportamento SSL');
40
- console.log(' ✓ Non committare mai process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" in produzione');
41
- console.log(' ✓ Considera l’uso di certificati di sviluppo validi invece di disabilitare la validazione\n');
42
-
43
- // Example 4: Demonstrate how to choose configuration based on environment
44
- console.log('4. Environment-based Configuration:');
45
- const isDevelopment = process.env.NODE_ENV === 'development';
46
- const baseUrl = isDevelopment ? 'https://localhost:3000/api' : 'https://api.production.com/rpc';
47
- const environmentClient = new RpcClient(baseUrl, {
48
- 'Authorization': `Bearer ${process.env.API_TOKEN || 'default-token'}`,
49
- 'X-Environment': process.env.NODE_ENV || 'development'
50
- });
51
- console.log(` ✓ Created client for ${isDevelopment ? 'development' : 'production'} environment`);
52
- console.log(` ✓ SSL validation: ${isDevelopment ? 'controlled by NODE_TLS_REJECT_UNAUTHORIZED' : 'enabled (secure)'}\n`);
53
-
54
- // Example usage (commented out since we don't have a real server)
55
- /*
56
- try {
57
- // This would work with a real server
58
- const result = await developmentClient.call('ping', {});
59
- console.log('Server response:', result);
60
- } catch (error) {
61
- console.error('Error calling server:', error.message);
62
- }
63
- */
64
-
65
- console.log('5. Best Practices Summary:');
66
- console.log(' ✓ Always use strict SSL validation in production');
67
- console.log(' ✓ Only disable SSL validation for development with self-signed certificates');
68
- console.log(' ✓ Use environment variables to control SSL behavior');
69
- console.log(' ✓ Never commit rejectUnauthorized: false to production code');
70
- console.log(' ✓ Consider using proper development certificates instead of disabling validation\n');
71
-
72
- console.log('=== Example Complete ===');
73
- }
74
-
75
- // Run the example if this file is executed directly
76
- if (require.main === module) {
77
- demonstrateSSLOptions().catch(console.error);
78
- }
79
-
80
- module.exports = { demonstrateSSLOptions };
1
+ /**
2
+ * Example demonstratin // Example 3: Best practices
3
+ console.log('3. Best Practices:');
4
+ console.log(' ✓ Always use SSL validation in production');
5
+ console.log(' ✓ Disable validation only for development with self-signed certificates');
6
+ console.log(' ✓ Use environment variables to control SSL behavior');
7
+ console.log(' ✓ Never commit process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" to production');
8
+ console.log(' ✓ Consider using valid development certificates instead of disabling validation\n');o use RpcClient with self-signed certificates
9
+ * in development environments.
10
+ *
11
+ * WARNING: Only use rejectUnauthorized: false in development!
12
+ * Never use this in production as it disables SSL certificate validation.
13
+ */
14
+
15
+ const { RpcClient } = require('../src/index.js');
16
+
17
+ async function demonstrateSSLOptions() {
18
+ console.log('=== RPC Client SSL Configuration Example ===\n');
19
+
20
+ // Example 1: Standard production client (default - strict SSL)
21
+ console.log('1. Production Client (strict SSL validation):');
22
+ const productionClient = new RpcClient('https://api.example.com/rpc', {
23
+ Authorization: 'Bearer prod-token',
24
+ });
25
+ console.log(' ✓ Created client with strict SSL validation (default)\n');
26
+
27
+ // Example 2: Development client for self-signed certificates (bypasses ALL SSL validation)
28
+ console.log('2. Development Client (bypasses SSL validation):');
29
+ console.log(
30
+ ' ⚠️ To bypass SSL validation in Node.js, set BEFORE starting the client:'
31
+ );
32
+ console.log(' process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";');
33
+ console.log(
34
+ ' ✓ All requests will accept self-signed certificates (development only!)\n'
35
+ );
36
+
37
+ // Example 3: Best practice
38
+ console.log('3. Best Practices:');
39
+ console.log(' ✓ Usa sempre la validazione SSL in produzione');
40
+ console.log(
41
+ ' ✓ Disabilita la validazione solo per sviluppo con self-signed'
42
+ );
43
+ console.log(
44
+ ' ✓ Usa variabili d’ambiente per controllare il comportamento SSL'
45
+ );
46
+ console.log(
47
+ ' ✓ Non committare mai process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" in produzione'
48
+ );
49
+ console.log(
50
+ ' ✓ Considera l’uso di certificati di sviluppo validi invece di disabilitare la validazione\n'
51
+ );
52
+
53
+ // Example 4: Demonstrate how to choose configuration based on environment
54
+ console.log('4. Environment-based Configuration:');
55
+ const isDevelopment = process.env.NODE_ENV === 'development';
56
+ const baseUrl = isDevelopment
57
+ ? 'https://localhost:3000/api'
58
+ : 'https://api.production.com/rpc';
59
+ const environmentClient = new RpcClient(baseUrl, {
60
+ Authorization: `Bearer ${process.env.API_TOKEN || 'default-token'}`,
61
+ 'X-Environment': process.env.NODE_ENV || 'development',
62
+ });
63
+ console.log(
64
+ ` ✓ Created client for ${isDevelopment ? 'development' : 'production'} environment`
65
+ );
66
+ console.log(
67
+ ` ✓ SSL validation: ${isDevelopment ? 'controlled by NODE_TLS_REJECT_UNAUTHORIZED' : 'enabled (secure)'}\n`
68
+ );
69
+
70
+ // Example usage (commented out since we don't have a real server)
71
+ /*
72
+ try {
73
+ // This would work with a real server
74
+ const result = await developmentClient.call('ping', {});
75
+ console.log('Server response:', result);
76
+ } catch (error) {
77
+ console.error('Error calling server:', error.message);
78
+ }
79
+ */
80
+
81
+ console.log('5. Best Practices Summary:');
82
+ console.log(' ✓ Always use strict SSL validation in production');
83
+ console.log(
84
+ ' ✓ Only disable SSL validation for development with self-signed certificates'
85
+ );
86
+ console.log(' ✓ Use environment variables to control SSL behavior');
87
+ console.log(' ✓ Never commit rejectUnauthorized: false to production code');
88
+ console.log(
89
+ ' ✓ Consider using proper development certificates instead of disabling validation\n'
90
+ );
91
+
92
+ console.log('=== Example Complete ===');
93
+ }
94
+
95
+ // Run the example if this file is executed directly
96
+ if (require.main === module) {
97
+ demonstrateSSLOptions().catch(console.error);
98
+ }
99
+
100
+ module.exports = { demonstrateSSLOptions };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rpc-express-toolkit",
3
- "version": "2.3.3",
4
- "description": "Enterprise-ready JSON-RPC 2.0 toolkit for Express.js with simplified APIs, structured logging, middleware system, schema validation, comprehensive BigInt/Date support. Advanced SSL options removed, see README.",
3
+ "version": "3.0.1",
4
+ "description": "Enterprise-ready JSON-RPC 2.0 toolkit for Express.js with simplified APIs, structured logging, middleware system, schema validation, comprehensive BigInt/Date support. JSON middleware validation and explicit configuration.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
7
7
  "files": [
@@ -57,13 +57,13 @@
57
57
  "devDependencies": {
58
58
  "eslint": "^8.57.1",
59
59
  "eslint-config-airbnb-base": "^15.0.0",
60
- "eslint-config-prettier": "^8.8.0",
60
+ "eslint-config-prettier": "^9.1.2",
61
61
  "eslint-plugin-import": "^2.31.0",
62
- "eslint-plugin-prettier": "^4.2.1",
62
+ "eslint-plugin-prettier": "^5.5.3",
63
63
  "husky": "^8.0.0",
64
64
  "jest": "^29.7.0",
65
65
  "lint-staged": "^13.0.0",
66
- "prettier": "^3.4.2",
66
+ "prettier": "^3.6.2",
67
67
  "supertest": "^6.3.3",
68
68
  "terser": "^5.43.1"
69
69
  },