@keak/sdk 1.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.
Files changed (89) hide show
  1. package/README.md +131 -0
  2. package/dist/Conversion.d.ts +13 -0
  3. package/dist/Conversion.d.ts.map +1 -0
  4. package/dist/KeakToolbarShadow.d.ts +21 -0
  5. package/dist/KeakToolbarShadow.d.ts.map +1 -0
  6. package/dist/components/ui/card.d.ts +9 -0
  7. package/dist/components/ui/card.d.ts.map +1 -0
  8. package/dist/components/ui/html-preview.d.ts +9 -0
  9. package/dist/components/ui/html-preview.d.ts.map +1 -0
  10. package/dist/components/ui/simple-tabs.d.ts +26 -0
  11. package/dist/components/ui/simple-tabs.d.ts.map +1 -0
  12. package/dist/components/ui/spinner.d.ts +6 -0
  13. package/dist/components/ui/spinner.d.ts.map +1 -0
  14. package/dist/components/ui/tabs.d.ts +13 -0
  15. package/dist/components/ui/tabs.d.ts.map +1 -0
  16. package/dist/components/ui/textarea.d.ts +6 -0
  17. package/dist/components/ui/textarea.d.ts.map +1 -0
  18. package/dist/index.cjs.js +17407 -0
  19. package/dist/index.cjs.js.map +1 -0
  20. package/dist/index.d.ts +101 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +17395 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/runtime/sourceInjector.d.ts +2 -0
  25. package/dist/runtime/sourceInjector.d.ts.map +1 -0
  26. package/dist/scripts/sourcePathInjection.d.ts +11 -0
  27. package/dist/scripts/sourcePathInjection.d.ts.map +1 -0
  28. package/dist/services/index.d.ts +7 -0
  29. package/dist/services/index.d.ts.map +1 -0
  30. package/dist/services/telemetry/index.d.ts +20 -0
  31. package/dist/services/telemetry/index.d.ts.map +1 -0
  32. package/dist/services/telemetry/telemetryService.d.ts +66 -0
  33. package/dist/services/telemetry/telemetryService.d.ts.map +1 -0
  34. package/dist/services/telemetry/types.d.ts +64 -0
  35. package/dist/services/telemetry/types.d.ts.map +1 -0
  36. package/dist/toolbar/AIPromptPanel.d.ts +9 -0
  37. package/dist/toolbar/AIPromptPanel.d.ts.map +1 -0
  38. package/dist/toolbar/ElementSelector.d.ts +8 -0
  39. package/dist/toolbar/ElementSelector.d.ts.map +1 -0
  40. package/dist/toolbar/ExperimentPanel.d.ts +9 -0
  41. package/dist/toolbar/ExperimentPanel.d.ts.map +1 -0
  42. package/dist/toolbar/KeakToolbar.d.ts +10 -0
  43. package/dist/toolbar/KeakToolbar.d.ts.map +1 -0
  44. package/dist/toolbar/MetricsPanel.d.ts +7 -0
  45. package/dist/toolbar/MetricsPanel.d.ts.map +1 -0
  46. package/dist/toolbar/PageScanPanel.d.ts +15 -0
  47. package/dist/toolbar/PageScanPanel.d.ts.map +1 -0
  48. package/dist/toolbar/components/PrimaryButton.d.ts +12 -0
  49. package/dist/toolbar/components/PrimaryButton.d.ts.map +1 -0
  50. package/dist/toolbar/components/WarningButton.d.ts +12 -0
  51. package/dist/toolbar/components/WarningButton.d.ts.map +1 -0
  52. package/dist/toolbar/components/icons/index.d.ts +13 -0
  53. package/dist/toolbar/components/icons/index.d.ts.map +1 -0
  54. package/dist/toolbar/components/ui/Badge.d.ts +10 -0
  55. package/dist/toolbar/components/ui/Badge.d.ts.map +1 -0
  56. package/dist/toolbar/components/ui/Button.d.ts +12 -0
  57. package/dist/toolbar/components/ui/Button.d.ts.map +1 -0
  58. package/dist/toolbar/components/ui/Progress.d.ts +5 -0
  59. package/dist/toolbar/components/ui/Progress.d.ts.map +1 -0
  60. package/dist/toolbar/components/ui/Tabs.d.ts +44 -0
  61. package/dist/toolbar/components/ui/Tabs.d.ts.map +1 -0
  62. package/dist/toolbar/components/ui/dropdown-menu.d.ts +28 -0
  63. package/dist/toolbar/components/ui/dropdown-menu.d.ts.map +1 -0
  64. package/dist/toolbar/lib/utils.d.ts +3 -0
  65. package/dist/toolbar/lib/utils.d.ts.map +1 -0
  66. package/dist/toolbar/utils/fiberSource.d.ts +64 -0
  67. package/dist/toolbar/utils/fiberSource.d.ts.map +1 -0
  68. package/dist/toolbar/utils/keakCodeClient.d.ts +104 -0
  69. package/dist/toolbar/utils/keakCodeClient.d.ts.map +1 -0
  70. package/dist/toolbar.css +1 -0
  71. package/dist/toolbar.js +1257 -0
  72. package/dist/toolbar.js.map +1 -0
  73. package/dist/utils/generateElementId.d.ts +44 -0
  74. package/dist/utils/generateElementId.d.ts.map +1 -0
  75. package/dist/utils/injectDataId.d.ts +33 -0
  76. package/dist/utils/injectDataId.d.ts.map +1 -0
  77. package/package.json +152 -0
  78. package/src/cli/ai-helper.js +206 -0
  79. package/src/cli/code-transformer.js +354 -0
  80. package/src/cli/conversion-detector.js +716 -0
  81. package/src/cli/framework-config.js +477 -0
  82. package/src/cli/install.js +618 -0
  83. package/src/cli/keak-setup.js +43 -0
  84. package/src/cli/revert-conversions.js +264 -0
  85. package/src/cli/safe-transformer.js +456 -0
  86. package/src/cli/simple-transformer.js +339 -0
  87. package/src/plugins/README.md +131 -0
  88. package/src/plugins/babel-source-inject.cjs +170 -0
  89. package/src/plugins/next.cjs +145 -0
@@ -0,0 +1,264 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+
6
+ class ConversionReverter {
7
+ constructor() {
8
+ this.stats = {
9
+ filesProcessed: 0,
10
+ filesReverted: 0,
11
+ backupsFound: 0
12
+ };
13
+ }
14
+
15
+ // Find all .keak-backup files
16
+ findBackupFiles(dir) {
17
+ const backups = [];
18
+
19
+ if (!fs.existsSync(dir)) return backups;
20
+
21
+ const items = fs.readdirSync(dir);
22
+
23
+ for (const item of items) {
24
+ const fullPath = path.join(dir, item);
25
+
26
+ // Skip common directories
27
+ if (['node_modules', '.git', 'dist', 'build', '.next', 'coverage'].includes(item)) {
28
+ continue;
29
+ }
30
+
31
+ const stat = fs.statSync(fullPath);
32
+
33
+ if (stat.isDirectory()) {
34
+ backups.push(...this.findBackupFiles(fullPath));
35
+ } else if (item.endsWith('.keak-backup')) {
36
+ backups.push(fullPath);
37
+ }
38
+ }
39
+
40
+ return backups;
41
+ }
42
+
43
+ // Revert a single file
44
+ revertFile(backupPath) {
45
+ try {
46
+ const originalPath = backupPath.replace('.keak-backup', '');
47
+
48
+ if (!fs.existsSync(backupPath)) {
49
+ return { success: false, error: 'Backup file not found' };
50
+ }
51
+
52
+ // Read backup content
53
+ const backupContent = fs.readFileSync(backupPath, 'utf-8');
54
+
55
+ // Write back to original file
56
+ fs.writeFileSync(originalPath, backupContent);
57
+
58
+ // Remove backup file
59
+ fs.unlinkSync(backupPath);
60
+
61
+ return { success: true, restored: true };
62
+ } catch (error) {
63
+ return { success: false, error: error.message };
64
+ }
65
+ }
66
+
67
+ // Process all backup files in a directory
68
+ processDirectory(rootDir) {
69
+ console.log(`๐Ÿ” Scanning for backup files in ${rootDir}...`);
70
+
71
+ const backupFiles = this.findBackupFiles(rootDir);
72
+ this.stats.backupsFound = backupFiles.length;
73
+
74
+ console.log(`๐Ÿ“ Found ${backupFiles.length} backup files`);
75
+
76
+ if (backupFiles.length === 0) {
77
+ console.log('โœจ No backup files found - nothing to revert');
78
+ return [];
79
+ }
80
+
81
+ const results = [];
82
+
83
+ for (const backupPath of backupFiles) {
84
+ console.log(`๐Ÿ”„ Reverting ${path.relative(rootDir, backupPath)}...`);
85
+
86
+ const result = this.revertFile(backupPath);
87
+ result.filePath = backupPath;
88
+ results.push(result);
89
+
90
+ this.stats.filesProcessed++;
91
+
92
+ if (result.success && result.restored) {
93
+ console.log(`โœ… Reverted ${path.relative(rootDir, backupPath.replace('.keak-backup', ''))}`);
94
+ this.stats.filesReverted++;
95
+ } else {
96
+ console.log(`โŒ Failed to revert ${path.relative(rootDir, backupPath)}: ${result.error}`);
97
+ }
98
+ }
99
+
100
+ return results;
101
+ }
102
+
103
+ // Remove any remaining Conversion imports and components
104
+ cleanupConversionCode(rootDir) {
105
+ console.log(`๐Ÿงน Cleaning up remaining Conversion components...`);
106
+
107
+ const reactFiles = this.findReactFiles(rootDir);
108
+ let cleanedFiles = 0;
109
+
110
+ for (const filePath of reactFiles) {
111
+ try {
112
+ const content = fs.readFileSync(filePath, 'utf-8');
113
+ let modified = content;
114
+
115
+ // Remove Conversion imports
116
+ modified = modified.replace(/import\s*{\s*Conversion\s*}\s*from\s*['"]keak-sdk['"];\s*\n?/g, '');
117
+
118
+ // Remove orphaned Conversion wrapper tags (in case of partial cleanup)
119
+ modified = modified.replace(/]*\s*\n?/g, '');
120
+ modified = modified.replace(/<\/Conversion\s*\n?/g, '');
121
+
122
+ // Clean up any malformed JSX from failed transformations
123
+ modified = this.fixMalformedJSX(modified);
124
+
125
+ if (modified !== content) {
126
+ fs.writeFileSync(filePath, modified);
127
+ cleanedFiles++;
128
+ console.log(`๐Ÿงน Cleaned ${path.relative(rootDir, filePath)}`);
129
+ }
130
+ } catch (error) {
131
+ console.warn(`โš ๏ธ Could not clean ${path.relative(rootDir, filePath)}: ${error.message}`);
132
+ }
133
+ }
134
+
135
+ if (cleanedFiles 0) {
136
+ console.log(`โœ… Cleaned ${cleanedFiles} files`);
137
+ } else {
138
+ console.log('โœจ No cleanup needed');
139
+ }
140
+ }
141
+
142
+ // Fix malformed JSX patterns
143
+ fixMalformedJSX(content) {
144
+ let fixed = content;
145
+
146
+ // Fix broken JSX elements that start with numbers (from failed transforms)
147
+ fixed = fixed.replace(/<(\d+)[^]*/g, '');
148
+ fixed = fixed.replace(/<\/(\d+)/g, '');
149
+
150
+ // Fix malformed attribute values
151
+ fixed = fixed.replace(/label="[^"]*&[^;]*;[^"]*"/g, 'label=""');
152
+
153
+ // Remove empty Conversion components
154
+ fixed = fixed.replace(/]*\s*<\/Conversion/g, '');
155
+
156
+ return fixed;
157
+ }
158
+
159
+ // Find React files (same as transformer)
160
+ findReactFiles(dir) {
161
+ const files = [];
162
+
163
+ if (!fs.existsSync(dir)) return files;
164
+
165
+ const items = fs.readdirSync(dir);
166
+
167
+ for (const item of items) {
168
+ const fullPath = path.join(dir, item);
169
+
170
+ // Skip directories we don't want to process
171
+ if (['node_modules', '.git', 'dist', 'build', '.next', 'coverage'].includes(item)) {
172
+ continue;
173
+ }
174
+
175
+ const stat = fs.statSync(fullPath);
176
+
177
+ if (stat.isDirectory()) {
178
+ files.push(...this.findReactFiles(fullPath));
179
+ } else if (this.isReactFile(item, fullPath)) {
180
+ files.push(fullPath);
181
+ }
182
+ }
183
+
184
+ return files;
185
+ }
186
+
187
+ // Check if file is a React file
188
+ isReactFile(filename, fullPath) {
189
+ // Check extension
190
+ if (!/\.(jsx|tsx|js|ts)$/.test(filename)) return false;
191
+
192
+ try {
193
+ const content = fs.readFileSync(fullPath, 'utf-8');
194
+
195
+ // Must contain JSX or React imports
196
+ return (
197
+ content.includes('import') && (
198
+ content.includes('react') ||
199
+ content.includes('React') ||
200
+ /\s*<\w+/.test(content) // JSX elements
201
+ )
202
+ );
203
+ } catch (error) {
204
+ return false;
205
+ }
206
+ }
207
+
208
+ // Generate report
209
+ generateReport() {
210
+ return {
211
+ summary: `
212
+ ๐Ÿ”„ Conversion Tracking Reverted!
213
+
214
+ ๐Ÿ“Š Summary:
215
+ โ€ข Backup files found: ${this.stats.backupsFound}
216
+ โ€ข Files processed: ${this.stats.filesProcessed}
217
+ โ€ข Files reverted: ${this.stats.filesReverted}
218
+
219
+ โœ… All conversion tracking changes have been reverted.
220
+ ๐Ÿ—‘๏ธ Backup files have been removed.
221
+ ๐Ÿงน Cleanup completed.
222
+ `,
223
+ stats: this.stats
224
+ };
225
+ }
226
+ }
227
+
228
+ export default ConversionReverter;
229
+
230
+ // CLI execution
231
+ if (import.meta.url === `file://${process.argv[1]}`) {
232
+ const reverter = new ConversionReverter();
233
+ const targetDir = process.argv[2] || process.cwd();
234
+
235
+ console.log('๐Ÿ”„ Reverting conversion tracking changes...\n');
236
+
237
+ const results = reverter.processDirectory(targetDir);
238
+
239
+ // Also clean up any remaining conversion code
240
+ reverter.cleanupConversionCode(targetDir);
241
+
242
+ const report = reverter.generateReport();
243
+
244
+ console.log(report.summary);
245
+
246
+ // Show any errors
247
+ const errors = results.filter(r =!r.success);
248
+ if (errors.length 0) {
249
+ console.log('\nโš ๏ธ Some files had issues:');
250
+ errors.forEach(error ={
251
+ console.log(`โŒ ${path.relative(targetDir, error.filePath)}: ${error.error}`);
252
+ });
253
+ }
254
+
255
+ console.log(`
256
+ ๐Ÿ”ง What was done:
257
+ 1. All backup files (.keak-backup) were restored to original files
258
+ 2. Conversion component imports were removed
259
+ 3. Malformed JSX was cleaned up
260
+ 4. Your codebase is back to its original state
261
+
262
+ ๐Ÿ’ก You can now run 'npx keak-setup conversions' again if you want to retry
263
+ `);
264
+ }