offbyt 1.0.0
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/README.md +2 -0
- package/cli/index.js +2 -0
- package/cli.js +206 -0
- package/core/detector/detectAxios.js +107 -0
- package/core/detector/detectFetch.js +148 -0
- package/core/detector/detectForms.js +55 -0
- package/core/detector/detectSocket.js +341 -0
- package/core/generator/generateControllers.js +17 -0
- package/core/generator/generateModels.js +25 -0
- package/core/generator/generateRoutes.js +17 -0
- package/core/generator/generateServer.js +18 -0
- package/core/generator/generateSocket.js +160 -0
- package/core/index.js +14 -0
- package/core/ir/IRTypes.js +25 -0
- package/core/ir/buildIR.js +83 -0
- package/core/parser/parseJS.js +26 -0
- package/core/parser/parseTS.js +27 -0
- package/core/rules/relationRules.js +38 -0
- package/core/rules/resourceRules.js +32 -0
- package/core/rules/schemaInference.js +26 -0
- package/core/scanner/scanProject.js +58 -0
- package/deploy/cloudflare.js +41 -0
- package/deploy/cloudflareWorker.js +122 -0
- package/deploy/connect.js +198 -0
- package/deploy/flyio.js +51 -0
- package/deploy/index.js +322 -0
- package/deploy/netlify.js +29 -0
- package/deploy/railway.js +215 -0
- package/deploy/render.js +195 -0
- package/deploy/utils.js +383 -0
- package/deploy/vercel.js +29 -0
- package/index.js +18 -0
- package/lib/generator/advancedCrudGenerator.js +475 -0
- package/lib/generator/crudCodeGenerator.js +486 -0
- package/lib/generator/irBasedGenerator.js +360 -0
- package/lib/ir-builder/index.js +16 -0
- package/lib/ir-builder/irBuilder.js +330 -0
- package/lib/ir-builder/rulesEngine.js +353 -0
- package/lib/ir-builder/templateEngine.js +193 -0
- package/lib/ir-builder/templates/index.js +14 -0
- package/lib/ir-builder/templates/model.template.js +47 -0
- package/lib/ir-builder/templates/routes-generic.template.js +66 -0
- package/lib/ir-builder/templates/routes-user.template.js +105 -0
- package/lib/ir-builder/templates/routes.template.js +102 -0
- package/lib/ir-builder/templates/validation.template.js +15 -0
- package/lib/ir-integration.js +349 -0
- package/lib/modes/benchmark.js +162 -0
- package/lib/modes/configBasedGenerator.js +2258 -0
- package/lib/modes/connect.js +1125 -0
- package/lib/modes/doctorAi.js +172 -0
- package/lib/modes/generateApi.js +435 -0
- package/lib/modes/interactiveSetup.js +548 -0
- package/lib/modes/offline.clean.js +14 -0
- package/lib/modes/offline.enhanced.js +787 -0
- package/lib/modes/offline.js +295 -0
- package/lib/modes/offline.v2.js +13 -0
- package/lib/modes/sync.js +629 -0
- package/lib/scanner/apiEndpointExtractor.js +387 -0
- package/lib/scanner/authPatternDetector.js +54 -0
- package/lib/scanner/frontendScanner.js +642 -0
- package/lib/utils/apiClientGenerator.js +242 -0
- package/lib/utils/apiScanner.js +95 -0
- package/lib/utils/codeInjector.js +350 -0
- package/lib/utils/doctor.js +381 -0
- package/lib/utils/envGenerator.js +36 -0
- package/lib/utils/loadTester.js +61 -0
- package/lib/utils/performanceAnalyzer.js +298 -0
- package/lib/utils/resourceDetector.js +281 -0
- package/package.json +20 -0
- package/templates/.env.template +31 -0
- package/templates/advanced.model.template.js +201 -0
- package/templates/advanced.route.template.js +341 -0
- package/templates/auth.middleware.template.js +87 -0
- package/templates/auth.routes.template.js +238 -0
- package/templates/auth.user.model.template.js +78 -0
- package/templates/cache.middleware.js +34 -0
- package/templates/chat.models.template.js +260 -0
- package/templates/chat.routes.template.js +478 -0
- package/templates/compression.middleware.js +19 -0
- package/templates/database.config.js +74 -0
- package/templates/errorHandler.middleware.js +54 -0
- package/templates/express/controller.ejs +26 -0
- package/templates/express/model.ejs +9 -0
- package/templates/express/route.ejs +18 -0
- package/templates/express/server.ejs +16 -0
- package/templates/frontend.env.template +14 -0
- package/templates/model.template.js +86 -0
- package/templates/package.production.json +51 -0
- package/templates/package.template.json +41 -0
- package/templates/pagination.utility.js +110 -0
- package/templates/production.server.template.js +233 -0
- package/templates/rateLimiter.middleware.js +36 -0
- package/templates/requestLogger.middleware.js +19 -0
- package/templates/response.helper.js +179 -0
- package/templates/route.template.js +130 -0
- package/templates/security.middleware.js +78 -0
- package/templates/server.template.js +91 -0
- package/templates/socket.server.template.js +433 -0
- package/templates/utils.helper.js +157 -0
- package/templates/validation.middleware.js +63 -0
- package/templates/validation.schema.js +128 -0
- package/utils/fileWriter.js +15 -0
- package/utils/logger.js +18 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Schemas
|
|
3
|
+
* Centralized validation for all endpoints
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { body, query, param, validationResult } from 'express-validator';
|
|
7
|
+
|
|
8
|
+
// Error validation middleware
|
|
9
|
+
export const validateErrors = (req, res, next) => {
|
|
10
|
+
const errors = validationResult(req);
|
|
11
|
+
if (!errors.isEmpty()) {
|
|
12
|
+
return res.status(400).json({
|
|
13
|
+
success: false,
|
|
14
|
+
errors: errors.array()
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
next();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Pagination validation
|
|
21
|
+
export const paginationValidators = [
|
|
22
|
+
query('page').optional().isInt({ min: 1 }).default(1),
|
|
23
|
+
query('limit').optional().isInt({ min: 1, max: 100 }).default(10),
|
|
24
|
+
query('skip').optional().isInt({ min: 0 }).default(0)
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// Search and filter validation
|
|
28
|
+
export const searchValidators = [
|
|
29
|
+
query('search').optional().isString().trim(),
|
|
30
|
+
query('sort').optional().isString(),
|
|
31
|
+
query('fields').optional().isString()
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
// ID validation
|
|
35
|
+
export const idValidator = param('id').isMongoId().withMessage('Invalid ID');
|
|
36
|
+
|
|
37
|
+
// Common validators
|
|
38
|
+
export const validators = {
|
|
39
|
+
// Email
|
|
40
|
+
email: body('email')
|
|
41
|
+
.isEmail()
|
|
42
|
+
.normalizeEmail()
|
|
43
|
+
.withMessage('Invalid email address'),
|
|
44
|
+
|
|
45
|
+
// Password
|
|
46
|
+
password: body('password')
|
|
47
|
+
.isLength({ min: 8 })
|
|
48
|
+
.withMessage('Password must be at least 8 characters'),
|
|
49
|
+
|
|
50
|
+
// Strong password
|
|
51
|
+
strongPassword: body('password')
|
|
52
|
+
.isLength({ min: 12 })
|
|
53
|
+
.matches(/[A-Z]/)
|
|
54
|
+
.withMessage('Password must contain uppercase letters')
|
|
55
|
+
.matches(/[a-z]/)
|
|
56
|
+
.withMessage('Password must contain lowercase letters')
|
|
57
|
+
.matches(/[0-9]/)
|
|
58
|
+
.withMessage('Password must contain numbers')
|
|
59
|
+
.matches(/[!@#$%^&*]/)
|
|
60
|
+
.withMessage('Password must contain special characters'),
|
|
61
|
+
|
|
62
|
+
// Name
|
|
63
|
+
name: body('name')
|
|
64
|
+
.isString()
|
|
65
|
+
.trim()
|
|
66
|
+
.isLength({ min: 2, max: 100 })
|
|
67
|
+
.withMessage('Name must be between 2 and 100 characters'),
|
|
68
|
+
|
|
69
|
+
// URL
|
|
70
|
+
url: body('url').isURL().withMessage('Invalid URL'),
|
|
71
|
+
|
|
72
|
+
// Phone
|
|
73
|
+
phone: body('phone')
|
|
74
|
+
.optional()
|
|
75
|
+
.isMobilePhone()
|
|
76
|
+
.withMessage('Invalid phone number'),
|
|
77
|
+
|
|
78
|
+
// Number fields
|
|
79
|
+
price: body('price')
|
|
80
|
+
.optional()
|
|
81
|
+
.isFloat({ min: 0 })
|
|
82
|
+
.withMessage('Price must be a positive number'),
|
|
83
|
+
|
|
84
|
+
// Status
|
|
85
|
+
status: body('status')
|
|
86
|
+
.isIn(['active', 'inactive', 'pending', 'archived'])
|
|
87
|
+
.withMessage('Invalid status'),
|
|
88
|
+
|
|
89
|
+
// Date
|
|
90
|
+
date: body('date')
|
|
91
|
+
.optional()
|
|
92
|
+
.isISO8601()
|
|
93
|
+
.withMessage('Invalid date format'),
|
|
94
|
+
|
|
95
|
+
// Boolean
|
|
96
|
+
boolean: body('active')
|
|
97
|
+
.optional()
|
|
98
|
+
.isBoolean()
|
|
99
|
+
.toBoolean()
|
|
100
|
+
.withMessage('Must be a boolean value'),
|
|
101
|
+
|
|
102
|
+
// JSON object
|
|
103
|
+
metadata: body('metadata')
|
|
104
|
+
.optional()
|
|
105
|
+
.isObject()
|
|
106
|
+
.withMessage('Metadata must be an object'),
|
|
107
|
+
|
|
108
|
+
// Array
|
|
109
|
+
tags: body('tags')
|
|
110
|
+
.optional()
|
|
111
|
+
.isArray()
|
|
112
|
+
.withMessage('Tags must be an array'),
|
|
113
|
+
|
|
114
|
+
// String array
|
|
115
|
+
stringArray: body('items')
|
|
116
|
+
.optional()
|
|
117
|
+
.custom((value) => {
|
|
118
|
+
if (!Array.isArray(value)) {
|
|
119
|
+
throw new Error('Must be an array');
|
|
120
|
+
}
|
|
121
|
+
if (!value.every(item => typeof item === 'string')) {
|
|
122
|
+
throw new Error('All items must be strings');
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
})
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default validators;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export function writeOutputFiles(baseDir, filesMap = {}) {
|
|
5
|
+
for (const [relativePath, content] of Object.entries(filesMap)) {
|
|
6
|
+
const fullPath = path.join(baseDir, relativePath);
|
|
7
|
+
const fullDir = path.dirname(fullPath);
|
|
8
|
+
if (!fs.existsSync(fullDir)) {
|
|
9
|
+
fs.mkdirSync(fullDir, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
fs.writeFileSync(fullPath, content);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default writeOutputFiles;
|
package/utils/logger.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function logInfo(message) {
|
|
2
|
+
console.log(`[offbyt] ${message}`);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function logWarn(message) {
|
|
6
|
+
console.warn(`[offbyt][warn] ${message}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function logError(message) {
|
|
10
|
+
console.error(`[offbyt][error] ${message}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
logInfo,
|
|
15
|
+
logWarn,
|
|
16
|
+
logError
|
|
17
|
+
};
|
|
18
|
+
|