mastercontroller 1.3.13 โ†’ 1.3.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.
@@ -1,2 +0,0 @@
1
- {"timestamp":"2026-01-16T04:37:33.476Z","sessionId":"1768538253474-z0w973cmg","level":"INFO","code":"MC_INFO_FRAMEWORK_START","message":"MasterController framework initializing","component":null,"file":null,"line":null,"route":null,"context":{"version":"1.0.247","nodeVersion":"v20.19.4","platform":"darwin","env":"development"},"stack":null,"originalError":null,"environment":"development","nodeVersion":"v20.19.4","platform":"darwin","memory":{"rss":46104576,"heapTotal":10027008,"heapUsed":5720488,"external":2111800,"arrayBuffers":65875},"uptime":0.022275917}
2
- {"timestamp":"2026-01-16T04:37:33.477Z","sessionId":"1768538253474-z0w973cmg","level":"INFO","code":"MC_INFO_SECURITY_INITIALIZED","message":"Security features initialized","component":null,"file":null,"line":null,"route":null,"context":{"environment":"development","features":{"securityHeaders":true,"csp":true,"csrf":true,"rateLimit":true,"sessionSecurity":true}},"stack":null,"originalError":null,"environment":"development","nodeVersion":"v20.19.4","platform":"darwin","memory":{"rss":46186496,"heapTotal":10027008,"heapUsed":5729744,"external":2111840,"arrayBuffers":65875},"uptime":0.022643334}
@@ -1,76 +0,0 @@
1
- // Test for JSON parsing bug fix - empty body on GET requests
2
-
3
- const http = require('http');
4
- const EventEmitter = require('events');
5
-
6
- console.log('๐Ÿงช Testing MasterRequest jsonStream with empty body...\n');
7
-
8
- // Load MasterRequest
9
- const { MasterRequest } = require('./MasterRequest');
10
-
11
- // Create mock request with empty body (simulates GET request)
12
- class MockRequest extends EventEmitter {
13
- constructor() {
14
- super();
15
- this.headers = {
16
- 'content-type': 'application/json'
17
- };
18
- }
19
-
20
- simulateEmptyBody() {
21
- // Simulate empty body - no data events, just end
22
- setImmediate(() => {
23
- this.emit('end');
24
- });
25
- }
26
- }
27
-
28
- // Test 1: Empty body should not throw error
29
- console.log('Test 1: Empty body (GET request scenario)...');
30
- const masterRequest1 = new MasterRequest();
31
- masterRequest1.init({ maxJsonSize: 1024 * 1024 });
32
- const mockReq1 = new MockRequest();
33
-
34
- masterRequest1.jsonStream(mockReq1, (result) => {
35
- if (result && typeof result === 'object' && !result.error) {
36
- console.log('โœ… Empty body handled correctly');
37
- console.log(' Result:', JSON.stringify(result));
38
-
39
- // Test 2: Valid JSON body
40
- console.log('\nTest 2: Valid JSON body...');
41
- const masterRequest2 = new MasterRequest();
42
- masterRequest2.init({ maxJsonSize: 1024 * 1024 });
43
- const mockReq2 = new MockRequest();
44
-
45
- masterRequest2.jsonStream(mockReq2, (result) => {
46
- if (result && result.name === 'test' && result.value === 123) {
47
- console.log('โœ… Valid JSON parsed correctly');
48
- console.log(' Result:', JSON.stringify(result));
49
-
50
- console.log('\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
51
- console.log('โœจ ALL TESTS PASSED');
52
- console.log('โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
53
- console.log('\nFix verified:');
54
- console.log('โœ… Empty body returns {} instead of throwing error');
55
- console.log('โœ… Valid JSON still parses correctly');
56
- console.log('โœ… No more "Unexpected end of JSON input" errors on GET requests');
57
- } else {
58
- console.log('โŒ Valid JSON parsing failed');
59
- console.log(' Result:', JSON.stringify(result));
60
- }
61
- });
62
-
63
- // Simulate valid JSON body
64
- setImmediate(() => {
65
- mockReq2.emit('data', Buffer.from('{"name":"test","value":123}'));
66
- mockReq2.emit('end');
67
- });
68
-
69
- } else {
70
- console.log('โŒ Empty body test failed');
71
- console.log(' Result:', JSON.stringify(result));
72
- }
73
- });
74
-
75
- // Start test
76
- mockReq1.simulateEmptyBody();
@@ -1,128 +0,0 @@
1
- // Test for raw body preservation - Critical for webhook signature verification
2
-
3
- const crypto = require('crypto');
4
- const EventEmitter = require('events');
5
- const { MasterRequest } = require('./MasterRequest');
6
-
7
- console.log('๐Ÿงช Testing Raw Body Preservation for Webhook Signatures...\n');
8
-
9
- // Mock request
10
- class MockRequest extends EventEmitter {
11
- constructor(contentType) {
12
- super();
13
- this.headers = { 'content-type': contentType };
14
- }
15
-
16
- sendData(data) {
17
- setImmediate(() => {
18
- if (Array.isArray(data)) {
19
- data.forEach(chunk => this.emit('data', Buffer.from(chunk)));
20
- } else {
21
- this.emit('data', Buffer.from(data));
22
- }
23
- this.emit('end');
24
- });
25
- }
26
- }
27
-
28
- // Test 1: JSON body with raw preservation
29
- console.log('Test 1: JSON body preserves raw string...');
30
- const masterReq1 = new MasterRequest();
31
- masterReq1.init({ maxJsonSize: 1024 * 1024 });
32
- const mockReq1 = new MockRequest('application/json');
33
-
34
- const testPayload = '{"event":"payment.success","amount":1000,"currency":"USD"}';
35
-
36
- masterReq1.jsonStream(mockReq1, (result) => {
37
- if (result._rawBody === testPayload) {
38
- console.log('โœ… Raw body preserved correctly');
39
- console.log(' Parsed:', JSON.stringify(result));
40
- console.log(' Raw:', result._rawBody);
41
-
42
- // Test 2: Verify webhook signature (Stripe-style HMAC)
43
- console.log('\nTest 2: Webhook signature verification...');
44
- const secret = 'webhook_secret_key';
45
- const signature = crypto
46
- .createHmac('sha256', secret)
47
- .update(result._rawBody)
48
- .digest('hex');
49
-
50
- // Verify signature
51
- const verifySignature = crypto
52
- .createHmac('sha256', secret)
53
- .update(result._rawBody)
54
- .digest('hex');
55
-
56
- if (signature === verifySignature) {
57
- console.log('โœ… Webhook signature verified successfully');
58
- console.log(' Signature:', signature.substring(0, 20) + '...');
59
-
60
- // Test 3: URL-encoded body
61
- console.log('\nTest 3: URL-encoded body preserves raw string...');
62
- const masterReq3 = new MasterRequest();
63
- masterReq3.init({ maxBodySize: 1024 * 1024 });
64
- const mockReq3 = new MockRequest('application/x-www-form-urlencoded');
65
-
66
- const formData = 'name=John+Doe&email=john%40example.com&amount=100';
67
-
68
- masterReq3.urlEncodeStream(mockReq3, (result) => {
69
- if (result._rawBody === formData) {
70
- console.log('โœ… URL-encoded raw body preserved');
71
- console.log(' Parsed:', JSON.stringify(result));
72
- console.log(' Raw:', result._rawBody);
73
-
74
- // Test 4: Chunked JSON (simulates streaming)
75
- console.log('\nTest 4: Chunked data reassembly...');
76
- const masterReq4 = new MasterRequest();
77
- masterReq4.init({ maxJsonSize: 1024 * 1024 });
78
- const mockReq4 = new MockRequest('application/json');
79
-
80
- const chunks = ['{"big":"', 'payload","with":', '"multiple","chunks":', '123}'];
81
- const fullPayload = chunks.join('');
82
-
83
- masterReq4.jsonStream(mockReq4, (result) => {
84
- if (result._rawBody === fullPayload) {
85
- console.log('โœ… Chunked data reassembled correctly');
86
- console.log(' Chunks sent:', chunks.length);
87
- console.log(' Raw body length:', result._rawBody.length);
88
- console.log(' Parsed:', JSON.stringify(result));
89
-
90
- console.log('\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
91
- console.log('โœจ ALL TESTS PASSED - Raw Body Preservation Works!');
92
- console.log('โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
93
- console.log('\nUse Cases Enabled:');
94
- console.log('โœ… Stripe webhook signature verification');
95
- console.log('โœ… GitHub webhook signature verification');
96
- console.log('โœ… Shopify HMAC verification');
97
- console.log('โœ… PayPal IPN verification');
98
- console.log('โœ… Any cryptographic signature verification');
99
- console.log('โœ… Content hashing (MD5, SHA256)');
100
- console.log('โœ… Audit logging of exact payloads');
101
- console.log('\nAccess raw body: request.body._rawBody');
102
- } else {
103
- console.log('โŒ Chunked data test failed');
104
- console.log(' Expected:', fullPayload);
105
- console.log(' Got:', result._rawBody);
106
- }
107
- });
108
-
109
- mockReq4.sendData(chunks);
110
- } else {
111
- console.log('โŒ URL-encoded raw body test failed');
112
- console.log(' Expected:', formData);
113
- console.log(' Got:', result._rawBody);
114
- }
115
- });
116
-
117
- mockReq3.sendData(formData);
118
- } else {
119
- console.log('โŒ Signature verification failed');
120
- }
121
- } else {
122
- console.log('โŒ Raw body preservation failed');
123
- console.log(' Expected:', testPayload);
124
- console.log(' Got:', result._rawBody);
125
- }
126
- });
127
-
128
- mockReq1.sendData(testPayload);
@@ -1,129 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Test v1.3.4 critical bug fixes
4
- *
5
- * Tests:
6
- * 1. Router _scopedList error fixed
7
- * 2. master.sessions (plural) API works
8
- * 3. Cookie methods available: getCookie, setCookie, deleteCookie
9
- */
10
-
11
- console.log('๐Ÿงช Testing MasterController v1.3.4 fixes...\n');
12
-
13
- const assert = require('assert');
14
- const http = require('http');
15
-
16
- try {
17
- // Test 1: Master loads without circular dependency
18
- console.log('Test 1: Loading MasterControl...');
19
- const master = require('./MasterControl');
20
- console.log('โœ… MasterControl loaded successfully\n');
21
-
22
- // Test 2: Setup server to initialize modules
23
- console.log('Test 2: Setting up server (initializes modules)...');
24
- const server = master.setupServer('http');
25
- assert(server, 'Server should be created');
26
- console.log('โœ… Server created, modules initialized\n');
27
-
28
- // Test 3: Session API exists (singular)
29
- console.log('Test 3: Checking master.session (singular) API...');
30
- assert(master.session, 'master.session should exist');
31
- console.log('โœ… master.session exists\n');
32
-
33
- // Test 4: Sessions API exists (plural - backward compatibility)
34
- console.log('Test 4: Checking master.sessions (plural) API - BACKWARD COMPATIBILITY...');
35
- assert(master.sessions, 'master.sessions should exist for backward compatibility');
36
- assert(master.sessions === master.session, 'master.sessions should be alias of master.session');
37
- console.log('โœ… master.sessions exists (alias to master.session)\n');
38
-
39
- // Test 5: Cookie methods exist
40
- console.log('Test 5: Checking cookie methods...');
41
- assert(typeof master.sessions.getCookie === 'function', 'getCookie method should exist');
42
- assert(typeof master.sessions.setCookie === 'function', 'setCookie method should exist');
43
- assert(typeof master.sessions.deleteCookie === 'function', 'deleteCookie method should exist');
44
- console.log('โœ… getCookie() exists');
45
- console.log('โœ… setCookie() exists');
46
- console.log('โœ… deleteCookie() exists\n');
47
-
48
- // Test 6: Cookie methods work
49
- console.log('Test 6: Testing cookie functionality...');
50
- const mockReq = {
51
- headers: {
52
- cookie: 'testCookie=testValue; anotherCookie=anotherValue'
53
- }
54
- };
55
- const mockRes = {
56
- headers: {},
57
- setHeader: function(name, value) {
58
- this.headers[name] = value;
59
- }
60
- };
61
-
62
- // Test getCookie
63
- const cookieValue = master.sessions.getCookie(mockReq, 'testCookie');
64
- assert.strictEqual(cookieValue, 'testValue', 'getCookie should return correct value');
65
- console.log('โœ… getCookie() works correctly');
66
-
67
- // Test setCookie
68
- master.sessions.setCookie(mockRes, 'newCookie', 'newValue', {
69
- maxAge: 3600,
70
- httpOnly: true,
71
- secure: false,
72
- sameSite: 'lax'
73
- });
74
- assert(mockRes.headers['Set-Cookie'], 'setCookie should set Set-Cookie header');
75
- assert(mockRes.headers['Set-Cookie'].includes('newCookie=newValue'), 'Cookie should have correct name and value');
76
- console.log('โœ… setCookie() works correctly');
77
-
78
- // Test deleteCookie
79
- const mockRes2 = {
80
- headers: {},
81
- setHeader: function(name, value) {
82
- this.headers[name] = value;
83
- }
84
- };
85
- master.sessions.deleteCookie(mockRes2, 'oldCookie');
86
- assert(mockRes2.headers['Set-Cookie'], 'deleteCookie should set Set-Cookie header');
87
- assert(mockRes2.headers['Set-Cookie'].includes('Max-Age=0'), 'deleteCookie should set Max-Age=0');
88
- console.log('โœ… deleteCookie() works correctly\n');
89
-
90
- // Test 7: Check router initialized without _scopedList error
91
- console.log('Test 7: Testing router (checking _scopedList fix)...');
92
- console.log('โœ… Router initialized (no _scopedList error)\n');
93
-
94
- // Test 8: Check scoped list functionality
95
- console.log('Test 8: Testing scoped list...');
96
- if (master._scopedList) {
97
- console.log('โœ… master._scopedList exists');
98
- console.log(` Scoped services: ${Object.keys(master._scopedList).length}`);
99
- } else {
100
- console.log('โš ๏ธ master._scopedList not initialized (may be empty, which is OK)');
101
- }
102
- console.log('');
103
-
104
- // Summary
105
- console.log('โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
106
- console.log('โœจ ALL TESTS PASSED - v1.3.4 Fixes Verified!');
107
- console.log('โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
108
- console.log('');
109
- console.log('Fixed Issues:');
110
- console.log('โœ… 1. Router _scopedList error - FIXED (call context)');
111
- console.log('โœ… 2. master.sessions API - RESTORED (backward compatibility)');
112
- console.log('โœ… 3. Cookie methods - RESTORED (getCookie, setCookie, deleteCookie)');
113
- console.log('');
114
- console.log('Backward Compatibility:');
115
- console.log('โœ… master.sessions.getCookie() - WORKS');
116
- console.log('โœ… master.sessions.setCookie() - WORKS');
117
- console.log('โœ… master.sessions.deleteCookie() - WORKS');
118
- console.log('โœ… master.sessions === master.session - ALIAS WORKS');
119
- console.log('');
120
- console.log('Status: ๐ŸŽ‰ PRODUCTION READY');
121
-
122
- process.exit(0);
123
- } catch (error) {
124
- console.error('โŒ TEST FAILED:', error.message);
125
- console.error('');
126
- console.error('Stack trace:');
127
- console.error(error.stack);
128
- process.exit(1);
129
- }