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.
Files changed (103) hide show
  1. package/README.md +2 -0
  2. package/cli/index.js +2 -0
  3. package/cli.js +206 -0
  4. package/core/detector/detectAxios.js +107 -0
  5. package/core/detector/detectFetch.js +148 -0
  6. package/core/detector/detectForms.js +55 -0
  7. package/core/detector/detectSocket.js +341 -0
  8. package/core/generator/generateControllers.js +17 -0
  9. package/core/generator/generateModels.js +25 -0
  10. package/core/generator/generateRoutes.js +17 -0
  11. package/core/generator/generateServer.js +18 -0
  12. package/core/generator/generateSocket.js +160 -0
  13. package/core/index.js +14 -0
  14. package/core/ir/IRTypes.js +25 -0
  15. package/core/ir/buildIR.js +83 -0
  16. package/core/parser/parseJS.js +26 -0
  17. package/core/parser/parseTS.js +27 -0
  18. package/core/rules/relationRules.js +38 -0
  19. package/core/rules/resourceRules.js +32 -0
  20. package/core/rules/schemaInference.js +26 -0
  21. package/core/scanner/scanProject.js +58 -0
  22. package/deploy/cloudflare.js +41 -0
  23. package/deploy/cloudflareWorker.js +122 -0
  24. package/deploy/connect.js +198 -0
  25. package/deploy/flyio.js +51 -0
  26. package/deploy/index.js +322 -0
  27. package/deploy/netlify.js +29 -0
  28. package/deploy/railway.js +215 -0
  29. package/deploy/render.js +195 -0
  30. package/deploy/utils.js +383 -0
  31. package/deploy/vercel.js +29 -0
  32. package/index.js +18 -0
  33. package/lib/generator/advancedCrudGenerator.js +475 -0
  34. package/lib/generator/crudCodeGenerator.js +486 -0
  35. package/lib/generator/irBasedGenerator.js +360 -0
  36. package/lib/ir-builder/index.js +16 -0
  37. package/lib/ir-builder/irBuilder.js +330 -0
  38. package/lib/ir-builder/rulesEngine.js +353 -0
  39. package/lib/ir-builder/templateEngine.js +193 -0
  40. package/lib/ir-builder/templates/index.js +14 -0
  41. package/lib/ir-builder/templates/model.template.js +47 -0
  42. package/lib/ir-builder/templates/routes-generic.template.js +66 -0
  43. package/lib/ir-builder/templates/routes-user.template.js +105 -0
  44. package/lib/ir-builder/templates/routes.template.js +102 -0
  45. package/lib/ir-builder/templates/validation.template.js +15 -0
  46. package/lib/ir-integration.js +349 -0
  47. package/lib/modes/benchmark.js +162 -0
  48. package/lib/modes/configBasedGenerator.js +2258 -0
  49. package/lib/modes/connect.js +1125 -0
  50. package/lib/modes/doctorAi.js +172 -0
  51. package/lib/modes/generateApi.js +435 -0
  52. package/lib/modes/interactiveSetup.js +548 -0
  53. package/lib/modes/offline.clean.js +14 -0
  54. package/lib/modes/offline.enhanced.js +787 -0
  55. package/lib/modes/offline.js +295 -0
  56. package/lib/modes/offline.v2.js +13 -0
  57. package/lib/modes/sync.js +629 -0
  58. package/lib/scanner/apiEndpointExtractor.js +387 -0
  59. package/lib/scanner/authPatternDetector.js +54 -0
  60. package/lib/scanner/frontendScanner.js +642 -0
  61. package/lib/utils/apiClientGenerator.js +242 -0
  62. package/lib/utils/apiScanner.js +95 -0
  63. package/lib/utils/codeInjector.js +350 -0
  64. package/lib/utils/doctor.js +381 -0
  65. package/lib/utils/envGenerator.js +36 -0
  66. package/lib/utils/loadTester.js +61 -0
  67. package/lib/utils/performanceAnalyzer.js +298 -0
  68. package/lib/utils/resourceDetector.js +281 -0
  69. package/package.json +20 -0
  70. package/templates/.env.template +31 -0
  71. package/templates/advanced.model.template.js +201 -0
  72. package/templates/advanced.route.template.js +341 -0
  73. package/templates/auth.middleware.template.js +87 -0
  74. package/templates/auth.routes.template.js +238 -0
  75. package/templates/auth.user.model.template.js +78 -0
  76. package/templates/cache.middleware.js +34 -0
  77. package/templates/chat.models.template.js +260 -0
  78. package/templates/chat.routes.template.js +478 -0
  79. package/templates/compression.middleware.js +19 -0
  80. package/templates/database.config.js +74 -0
  81. package/templates/errorHandler.middleware.js +54 -0
  82. package/templates/express/controller.ejs +26 -0
  83. package/templates/express/model.ejs +9 -0
  84. package/templates/express/route.ejs +18 -0
  85. package/templates/express/server.ejs +16 -0
  86. package/templates/frontend.env.template +14 -0
  87. package/templates/model.template.js +86 -0
  88. package/templates/package.production.json +51 -0
  89. package/templates/package.template.json +41 -0
  90. package/templates/pagination.utility.js +110 -0
  91. package/templates/production.server.template.js +233 -0
  92. package/templates/rateLimiter.middleware.js +36 -0
  93. package/templates/requestLogger.middleware.js +19 -0
  94. package/templates/response.helper.js +179 -0
  95. package/templates/route.template.js +130 -0
  96. package/templates/security.middleware.js +78 -0
  97. package/templates/server.template.js +91 -0
  98. package/templates/socket.server.template.js +433 -0
  99. package/templates/utils.helper.js +157 -0
  100. package/templates/validation.middleware.js +63 -0
  101. package/templates/validation.schema.js +128 -0
  102. package/utils/fileWriter.js +15 -0
  103. 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;
@@ -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
+