mastercontroller 1.3.9 → 1.3.12
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.
- package/.claude/settings.local.json +6 -1
- package/.eslintrc.json +50 -0
- package/.github/workflows/ci.yml +317 -0
- package/.prettierrc +10 -0
- package/CHANGES.md +296 -0
- package/DEPLOYMENT.md +956 -0
- package/FIXES_APPLIED.md +378 -0
- package/FORTUNE_500_UPGRADE.md +863 -0
- package/MasterAction.js +10 -263
- package/MasterControl.js +226 -43
- package/MasterRequest.js +42 -1
- package/MasterRouter.js +42 -37
- package/PERFORMANCE_SECURITY_AUDIT.md +677 -0
- package/README.md +602 -71
- package/SENIOR_ENGINEER_AUDIT.md +2477 -0
- package/VERIFICATION_CHECKLIST.md +726 -0
- package/error/README.md +2452 -0
- package/monitoring/HealthCheck.js +347 -0
- package/monitoring/PrometheusExporter.js +416 -0
- package/monitoring/README.md +3112 -0
- package/package.json +64 -11
- package/security/MasterValidator.js +140 -10
- package/security/README.md +1805 -0
- package/security/adapters/RedisCSRFStore.js +428 -0
- package/security/adapters/RedisRateLimiter.js +462 -0
- package/security/adapters/RedisSessionStore.js +476 -0
- package/MasterCors.js.tmp +0 -0
- package/MasterHtml.js +0 -649
- package/MasterPipeline.js.tmp +0 -0
- package/MasterRequest.js.tmp +0 -0
- package/MasterRouter.js.tmp +0 -0
- package/MasterSocket.js.tmp +0 -0
- package/MasterTemp.js.tmp +0 -0
- package/MasterTemplate.js +0 -230
- package/MasterTimeout.js.tmp +0 -0
- package/TemplateOverwrite.js +0 -41
- package/TemplateOverwrite.js.tmp +0 -0
- package/error/ErrorBoundary.js +0 -353
- package/error/HydrationMismatch.js +0 -265
- package/error/MasterError.js +0 -240
- package/error/MasterError.js.tmp +0 -0
- package/error/MasterErrorRenderer.js +0 -536
- package/error/MasterErrorRenderer.js.tmp +0 -0
- package/error/SSRErrorHandler.js +0 -273
- package/ssr/hydration-client.js +0 -93
- package/ssr/runtime-ssr.cjs +0 -553
- package/ssr/ssr-shims.js +0 -73
package/error/SSRErrorHandler.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SSRErrorHandler - Server-side rendering error handling
|
|
3
|
-
* Handles component render failures with graceful fallbacks
|
|
4
|
-
* Version: 1.0.1
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { MasterControllerError } = require('./MasterErrorHandler');
|
|
8
|
-
|
|
9
|
-
const isDevelopment = process.env.NODE_ENV !== 'production' && process.env.master === 'development';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Render error component for development mode
|
|
13
|
-
*/
|
|
14
|
-
function renderErrorComponent(options = {}) {
|
|
15
|
-
const {
|
|
16
|
-
component,
|
|
17
|
-
error,
|
|
18
|
-
stack,
|
|
19
|
-
file,
|
|
20
|
-
line,
|
|
21
|
-
details
|
|
22
|
-
} = options;
|
|
23
|
-
|
|
24
|
-
const errorObj = new MasterControllerError({
|
|
25
|
-
code: 'MC_ERR_COMPONENT_RENDER_FAILED',
|
|
26
|
-
message: error || 'Component failed to render on server',
|
|
27
|
-
component,
|
|
28
|
-
file,
|
|
29
|
-
line,
|
|
30
|
-
details: details || stack,
|
|
31
|
-
originalError: options.originalError
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Return full HTML error page in development
|
|
35
|
-
return errorObj.toHTML();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Render fallback component for production mode
|
|
40
|
-
*/
|
|
41
|
-
function renderFallback(componentName, options = {}) {
|
|
42
|
-
const { showSkeleton = true, customMessage } = options;
|
|
43
|
-
|
|
44
|
-
if (showSkeleton) {
|
|
45
|
-
return `
|
|
46
|
-
<div class="mc-fallback" data-component="${componentName}" style="
|
|
47
|
-
padding: 20px;
|
|
48
|
-
background: #f9fafb;
|
|
49
|
-
border-radius: 8px;
|
|
50
|
-
border: 1px dashed #d1d5db;
|
|
51
|
-
min-height: 100px;
|
|
52
|
-
display: flex;
|
|
53
|
-
align-items: center;
|
|
54
|
-
justify-content: center;
|
|
55
|
-
color: #6b7280;
|
|
56
|
-
">
|
|
57
|
-
<div class="mc-fallback-content">
|
|
58
|
-
${customMessage || ''}
|
|
59
|
-
<div class="skeleton-loader" style="
|
|
60
|
-
width: 100%;
|
|
61
|
-
height: 20px;
|
|
62
|
-
background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
|
|
63
|
-
background-size: 200% 100%;
|
|
64
|
-
animation: skeleton-loading 1.5s ease-in-out infinite;
|
|
65
|
-
border-radius: 4px;
|
|
66
|
-
"></div>
|
|
67
|
-
</div>
|
|
68
|
-
<style>
|
|
69
|
-
@keyframes skeleton-loading {
|
|
70
|
-
0% { background-position: 200% 0; }
|
|
71
|
-
100% { background-position: -200% 0; }
|
|
72
|
-
}
|
|
73
|
-
</style>
|
|
74
|
-
</div>
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Minimal fallback - just an empty div
|
|
79
|
-
return `<div class="mc-fallback" data-component="${componentName}"></div>`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Safe component render wrapper
|
|
84
|
-
* Catches errors and returns either error page (dev) or fallback (prod)
|
|
85
|
-
*/
|
|
86
|
-
function safeRenderComponent(component, componentName, filePath) {
|
|
87
|
-
try {
|
|
88
|
-
// Try tempRender first
|
|
89
|
-
if (typeof component.tempRender === 'function') {
|
|
90
|
-
const startTime = Date.now();
|
|
91
|
-
const result = component.tempRender();
|
|
92
|
-
const renderTime = Date.now() - startTime;
|
|
93
|
-
|
|
94
|
-
// Warn about slow renders in development
|
|
95
|
-
if (isDevelopment && renderTime > 100) {
|
|
96
|
-
console.warn(
|
|
97
|
-
new MasterControllerError({
|
|
98
|
-
code: 'MC_ERR_SLOW_RENDER',
|
|
99
|
-
message: `Component rendering slowly on server (${renderTime}ms)`,
|
|
100
|
-
component: componentName,
|
|
101
|
-
file: filePath,
|
|
102
|
-
details: `Render time exceeded 100ms threshold. Consider optimizing this component.`
|
|
103
|
-
}).format()
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return { success: true, html: result, renderTime };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Fallback to connectedCallback
|
|
111
|
-
if (typeof component.connectedCallback === 'function') {
|
|
112
|
-
const startTime = Date.now();
|
|
113
|
-
component.connectedCallback();
|
|
114
|
-
const renderTime = Date.now() - startTime;
|
|
115
|
-
|
|
116
|
-
// Get the rendered HTML
|
|
117
|
-
const html = component.innerHTML || '';
|
|
118
|
-
return { success: true, html, renderTime };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// No render method found
|
|
122
|
-
throw new Error('No tempRender() or connectedCallback() method found');
|
|
123
|
-
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.error(
|
|
126
|
-
new MasterControllerError({
|
|
127
|
-
code: 'MC_ERR_COMPONENT_RENDER_FAILED',
|
|
128
|
-
message: `Failed to render component: ${error.message}`,
|
|
129
|
-
component: componentName,
|
|
130
|
-
file: filePath,
|
|
131
|
-
originalError: error
|
|
132
|
-
}).format()
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
if (isDevelopment) {
|
|
136
|
-
return {
|
|
137
|
-
success: false,
|
|
138
|
-
html: renderErrorComponent({
|
|
139
|
-
component: componentName,
|
|
140
|
-
error: error.message,
|
|
141
|
-
stack: error.stack,
|
|
142
|
-
file: filePath,
|
|
143
|
-
originalError: error
|
|
144
|
-
}),
|
|
145
|
-
renderTime: 0
|
|
146
|
-
};
|
|
147
|
-
} else {
|
|
148
|
-
// Log error for monitoring
|
|
149
|
-
logProductionError(error, componentName, filePath);
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
success: false,
|
|
153
|
-
html: renderFallback(componentName, { showSkeleton: true }),
|
|
154
|
-
renderTime: 0
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Log production errors for monitoring
|
|
162
|
-
*/
|
|
163
|
-
function logProductionError(error, component, file) {
|
|
164
|
-
const errorData = {
|
|
165
|
-
timestamp: new Date().toISOString(),
|
|
166
|
-
component,
|
|
167
|
-
file,
|
|
168
|
-
message: error.message,
|
|
169
|
-
stack: error.stack,
|
|
170
|
-
environment: 'production'
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// Log to console (can be captured by monitoring services)
|
|
174
|
-
console.error('[MasterController Production Error]', JSON.stringify(errorData, null, 2));
|
|
175
|
-
|
|
176
|
-
// Hook for external logging services (Sentry, LogRocket, etc.)
|
|
177
|
-
if (global.masterControllerErrorHook) {
|
|
178
|
-
try {
|
|
179
|
-
global.masterControllerErrorHook(errorData);
|
|
180
|
-
} catch (hookError) {
|
|
181
|
-
console.error('[MasterController] Error hook failed:', hookError.message);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Wrap connectedCallback with try-catch
|
|
188
|
-
*/
|
|
189
|
-
function wrapConnectedCallback(element, componentName, filePath) {
|
|
190
|
-
if (!element || typeof element.connectedCallback !== 'function') {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const originalCallback = element.connectedCallback;
|
|
195
|
-
|
|
196
|
-
element.connectedCallback = function(...args) {
|
|
197
|
-
try {
|
|
198
|
-
return originalCallback.apply(this, args);
|
|
199
|
-
} catch (error) {
|
|
200
|
-
console.error(
|
|
201
|
-
new MasterControllerError({
|
|
202
|
-
code: 'MC_ERR_COMPONENT_RENDER_FAILED',
|
|
203
|
-
message: `connectedCallback failed: ${error.message}`,
|
|
204
|
-
component: componentName,
|
|
205
|
-
file: filePath,
|
|
206
|
-
originalError: error
|
|
207
|
-
}).format()
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
if (isDevelopment) {
|
|
211
|
-
this.innerHTML = renderErrorComponent({
|
|
212
|
-
component: componentName,
|
|
213
|
-
error: error.message,
|
|
214
|
-
stack: error.stack,
|
|
215
|
-
file: filePath,
|
|
216
|
-
originalError: error
|
|
217
|
-
});
|
|
218
|
-
} else {
|
|
219
|
-
logProductionError(error, componentName, filePath);
|
|
220
|
-
this.innerHTML = renderFallback(componentName);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Check if component has required SSR methods
|
|
228
|
-
*/
|
|
229
|
-
function validateSSRComponent(componentClass, componentName, filePath) {
|
|
230
|
-
const warnings = [];
|
|
231
|
-
|
|
232
|
-
// Check for tempRender method
|
|
233
|
-
if (!componentClass.prototype.tempRender && !componentClass.prototype.connectedCallback) {
|
|
234
|
-
warnings.push(
|
|
235
|
-
new MasterControllerError({
|
|
236
|
-
code: 'MC_ERR_TEMPRENDER_MISSING',
|
|
237
|
-
message: 'Component missing tempRender() method for SSR',
|
|
238
|
-
component: componentName,
|
|
239
|
-
file: filePath,
|
|
240
|
-
details: `Add a tempRender() method to enable server-side rendering:\n\n tempRender() {\n return \`<div>Your HTML here</div>\`;\n }`
|
|
241
|
-
})
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Warn if only render() exists (client-only)
|
|
246
|
-
if (componentClass.prototype.render && !componentClass.prototype.tempRender) {
|
|
247
|
-
warnings.push(
|
|
248
|
-
new MasterControllerError({
|
|
249
|
-
code: 'MC_ERR_TEMPRENDER_MISSING',
|
|
250
|
-
message: 'Component has render() but no tempRender() - will not SSR',
|
|
251
|
-
component: componentName,
|
|
252
|
-
file: filePath,
|
|
253
|
-
details: 'For SSR, rename render() to tempRender() or add a separate tempRender() method'
|
|
254
|
-
})
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (warnings.length > 0 && isDevelopment) {
|
|
259
|
-
warnings.forEach(warning => console.warn(warning.format()));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return warnings.length === 0;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
module.exports = {
|
|
266
|
-
renderErrorComponent,
|
|
267
|
-
renderFallback,
|
|
268
|
-
safeRenderComponent,
|
|
269
|
-
wrapConnectedCallback,
|
|
270
|
-
validateSSRComponent,
|
|
271
|
-
logProductionError,
|
|
272
|
-
isDevelopment
|
|
273
|
-
};
|
package/ssr/hydration-client.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MasterController Client-Side Hydration Runtime
|
|
3
|
-
* Handles error boundaries and hydration mismatch detection
|
|
4
|
-
* Version: 2.0.1
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Import error boundary
|
|
8
|
-
import { ErrorBoundary } from '../error/ErrorBoundary.js';
|
|
9
|
-
|
|
10
|
-
// Import hydration mismatch detection
|
|
11
|
-
const isDevelopment = window.location.hostname === 'localhost' ||
|
|
12
|
-
window.location.hostname === '127.0.0.1';
|
|
13
|
-
|
|
14
|
-
if (isDevelopment && typeof require !== 'undefined') {
|
|
15
|
-
try {
|
|
16
|
-
const { enableHydrationMismatchDetection } = require('../error/HydrationMismatch.js');
|
|
17
|
-
enableHydrationMismatchDetection({
|
|
18
|
-
verbose: localStorage.getItem('mc-hydration-debug') === 'true',
|
|
19
|
-
delay: 1000
|
|
20
|
-
});
|
|
21
|
-
} catch (e) {
|
|
22
|
-
console.warn('[MasterController] Could not load hydration mismatch detection:', e.message);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Auto-wrap app root with error boundary if not already wrapped
|
|
27
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
28
|
-
const appRoot = document.querySelector('root-layout') || document.body;
|
|
29
|
-
|
|
30
|
-
// Check if already wrapped
|
|
31
|
-
if (!appRoot.closest('error-boundary')) {
|
|
32
|
-
// Create error boundary wrapper
|
|
33
|
-
const boundary = document.createElement('error-boundary');
|
|
34
|
-
|
|
35
|
-
// Set development mode
|
|
36
|
-
if (isDevelopment) {
|
|
37
|
-
boundary.setAttribute('dev-mode', '');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Configure custom error handler
|
|
41
|
-
boundary.onError = (errorInfo) => {
|
|
42
|
-
console.error('[App Error]', errorInfo);
|
|
43
|
-
|
|
44
|
-
// Send to monitoring service if configured
|
|
45
|
-
if (window.masterControllerErrorReporter) {
|
|
46
|
-
window.masterControllerErrorReporter(errorInfo);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// Wrap content
|
|
51
|
-
const parent = appRoot.parentNode;
|
|
52
|
-
parent.insertBefore(boundary, appRoot);
|
|
53
|
-
boundary.appendChild(appRoot);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Global error reporter hook
|
|
58
|
-
window.masterControllerErrorReporter = window.masterControllerErrorReporter || function(errorData) {
|
|
59
|
-
console.log('[MasterController] Error reported:', errorData);
|
|
60
|
-
|
|
61
|
-
// Example: Send to your monitoring service
|
|
62
|
-
// fetch('/api/errors', {
|
|
63
|
-
// method: 'POST',
|
|
64
|
-
// headers: { 'Content-Type': 'application/json' },
|
|
65
|
-
// body: JSON.stringify(errorData)
|
|
66
|
-
// });
|
|
67
|
-
|
|
68
|
-
// Example: Send to Sentry
|
|
69
|
-
// if (window.Sentry) {
|
|
70
|
-
// Sentry.captureException(new Error(errorData.message), {
|
|
71
|
-
// extra: errorData
|
|
72
|
-
// });
|
|
73
|
-
// }
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// Log successful hydration
|
|
77
|
-
if (isDevelopment) {
|
|
78
|
-
window.addEventListener('load', () => {
|
|
79
|
-
const ssrElements = document.querySelectorAll('[data-ssr]');
|
|
80
|
-
if (ssrElements.length > 0) {
|
|
81
|
-
console.log(
|
|
82
|
-
`%c✓ MasterController Hydration Complete`,
|
|
83
|
-
'color: #10b981; font-weight: bold; font-size: 14px;'
|
|
84
|
-
);
|
|
85
|
-
console.log(` ${ssrElements.length} server-rendered components hydrated`);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Export for manual use
|
|
91
|
-
export {
|
|
92
|
-
ErrorBoundary
|
|
93
|
-
};
|