snow-flow 2.0.2 → 2.0.4

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 (173) hide show
  1. package/{.claude/mcp-config.json → .mcp.json} +13 -12
  2. package/.releaserc.json +47 -0
  3. package/README.md +48 -1
  4. package/package.json +1 -1
  5. package/.claude/claude-settings.json +0 -15
  6. package/.claude/commands/analysis/README.md +0 -9
  7. package/.claude/commands/automation/README.md +0 -9
  8. package/.claude/commands/github/README.md +0 -11
  9. package/.claude/commands/helpers/standard-checkpoint-hooks.sh +0 -179
  10. package/.claude/commands/hooks/README.md +0 -11
  11. package/.claude/commands/monitoring/README.md +0 -9
  12. package/.claude/commands/optimization/README.md +0 -9
  13. package/.claude/commands/training/README.md +0 -9
  14. package/.claude/commands/workflows/README.md +0 -9
  15. package/.claude/config.json +0 -36
  16. package/.claude/helpers/github-setup.sh +0 -28
  17. package/.claude/helpers/quick-start.sh +0 -19
  18. package/.claude/helpers/setup-mcp.sh +0 -18
  19. package/.claude/settings.json +0 -114
  20. package/.claude/settings.local.json +0 -33
  21. package/.claude-flow/metrics/agent-metrics.json +0 -1
  22. package/.claude-flow/metrics/performance.json +0 -9
  23. package/.claude-flow/metrics/system-metrics.json +0 -15986
  24. package/.claude-flow/metrics/task-metrics.json +0 -10
  25. package/.roo/README.md +0 -402
  26. package/.roo/mcp-list.txt +0 -257
  27. package/.roo/mcp.json +0 -32
  28. package/.roo/workflows/basic-tdd.json +0 -32
  29. package/.roomodes +0 -201
  30. package/CLAUDE.md +0 -393
  31. package/bin/snow-flow.js +0 -3
  32. package/dist/cli.js.bak +0 -2052
  33. package/dist/config/snow-flow-config.d.ts +0 -1492
  34. package/dist/config/snow-flow-config.js +0 -938
  35. package/scripts/create-env.js +0 -91
  36. package/scripts/postinstall.js +0 -30
  37. package/scripts/register-mcp-servers.js +0 -210
  38. package/scripts/reset-mcp-servers.js +0 -246
  39. package/scripts/setup-mcp.js +0 -106
  40. package/scripts/update-version.js +0 -31
  41. package/src/agents/README.md +0 -192
  42. package/src/agents/base-agent.ts +0 -251
  43. package/src/agents/coordinator.ts +0 -971
  44. package/src/agents/index.ts +0 -18
  45. package/src/agents/queen-403-handler.ts +0 -230
  46. package/src/agents/queen-agent.ts +0 -1399
  47. package/src/agents/script-writer-agent.ts +0 -769
  48. package/src/agents/security-agent.ts +0 -726
  49. package/src/agents/widget-creator-agent.ts +0 -568
  50. package/src/api/error-handling.ts +0 -1758
  51. package/src/api/natural-language-mapper.ts +0 -630
  52. package/src/api/performance-optimizer.ts +0 -891
  53. package/src/api/transaction-manager.ts +0 -754
  54. package/src/cli/deploy-artifact.ts +0 -304
  55. package/src/cli/snow-flow-cli-integration.ts +0 -434
  56. package/src/cli.ts +0 -4455
  57. package/src/cli.ts.bak +0 -5616
  58. package/src/compliance/advanced-compliance-system.ts +0 -1268
  59. package/src/compliance/index.ts +0 -19
  60. package/src/config/snow-flow-config.ts +0 -1019
  61. package/src/documentation/index.ts +0 -16
  62. package/src/documentation/self-documenting-system.ts +0 -1421
  63. package/src/dynamic-version.ts +0 -44
  64. package/src/healing/index.ts +0 -20
  65. package/src/healing/self-healing-system.ts +0 -1435
  66. package/src/health/README.md +0 -161
  67. package/src/health/system-health.ts +0 -995
  68. package/src/index.ts +0 -60
  69. package/src/intelligence/acl-analyzer.ts +0 -377
  70. package/src/intelligence/auto-resolution-engine.ts +0 -643
  71. package/src/intelligence/gap-analysis-engine.ts +0 -488
  72. package/src/intelligence/manual-instructions-generator.ts +0 -744
  73. package/src/intelligence/mcp-coverage-analyzer.ts +0 -708
  74. package/src/intelligence/multi-pass-requirements-analyzer.ts +0 -603
  75. package/src/intelligence/performance-recommendations-engine.ts +0 -1223
  76. package/src/intelligence/requirements-analyzer.ts +0 -1148
  77. package/src/intelligence/task-analyzer.ts +0 -628
  78. package/src/managers/scope-manager.ts +0 -555
  79. package/src/mcp/advanced/servicenow-advanced-features-mcp.ts +0 -16110
  80. package/src/mcp/base-mcp-server.ts +0 -660
  81. package/src/mcp/http-transport-wrapper.ts +0 -426
  82. package/src/mcp/service-discovery-client.ts +0 -312
  83. package/src/mcp/servicenow-automation-mcp-refactored.ts +0 -678
  84. package/src/mcp/servicenow-automation-mcp.ts +0 -838
  85. package/src/mcp/servicenow-deployment-mcp-refactored.ts +0 -1292
  86. package/src/mcp/servicenow-deployment-mcp.ts +0 -7244
  87. package/src/mcp/servicenow-graph-memory-mcp-refactored.ts +0 -721
  88. package/src/mcp/servicenow-graph-memory-mcp.ts +0 -832
  89. package/src/mcp/servicenow-integration-mcp-refactored.ts +0 -655
  90. package/src/mcp/servicenow-integration-mcp.ts +0 -819
  91. package/src/mcp/servicenow-intelligent-mcp-refactored.ts +0 -977
  92. package/src/mcp/servicenow-intelligent-mcp.ts +0 -4638
  93. package/src/mcp/servicenow-mcp-server.ts +0 -728
  94. package/src/mcp/servicenow-memory-mcp.ts +0 -474
  95. package/src/mcp/servicenow-operations-mcp-refactored.ts +0 -1995
  96. package/src/mcp/servicenow-operations-mcp.ts +0 -3384
  97. package/src/mcp/servicenow-platform-development-mcp-refactored.ts +0 -611
  98. package/src/mcp/servicenow-platform-development-mcp.ts +0 -970
  99. package/src/mcp/servicenow-progressive-indexer.ts +0 -370
  100. package/src/mcp/servicenow-reporting-analytics-mcp-refactored.ts +0 -695
  101. package/src/mcp/servicenow-reporting-analytics-mcp.ts +0 -1123
  102. package/src/mcp/servicenow-security-compliance-mcp-refactored.ts +0 -642
  103. package/src/mcp/servicenow-security-compliance-mcp.ts +0 -1157
  104. package/src/mcp/servicenow-update-set-mcp-refactored.ts +0 -751
  105. package/src/mcp/servicenow-update-set-mcp.ts +0 -811
  106. package/src/mcp/shared/agent-context-provider.ts +0 -365
  107. package/src/mcp/shared/base-mcp-server.ts +0 -2463
  108. package/src/mcp/shared/mcp-memory-manager.ts +0 -540
  109. package/src/mcp/shared/mcp-resource-manager.ts +0 -367
  110. package/src/mcp/snow-flow-mcp.ts +0 -911
  111. package/src/mcp/start-all-mcp-servers.ts +0 -102
  112. package/src/mcp/start-servicenow-mcp.ts +0 -67
  113. package/src/monitoring/enhanced-monitoring-system.ts +0 -1345
  114. package/src/monitoring/performance-tracker.ts +0 -777
  115. package/src/optimization/cost-optimization-engine.ts +0 -1125
  116. package/src/optimization/index.ts +0 -10
  117. package/src/queen/README.md +0 -403
  118. package/src/queen/agent-factory.ts +0 -574
  119. package/src/queen/index.ts +0 -94
  120. package/src/queen/mcp-execution-bridge.ts +0 -681
  121. package/src/queen/neural-learning.ts +0 -319
  122. package/src/queen/parallel-agent-engine.ts +0 -848
  123. package/src/queen/queen-memory-system.ts +0 -490
  124. package/src/queen/queen-memory.ts +0 -456
  125. package/src/queen/servicenow-queen.ts +0 -1029
  126. package/src/queen/types.ts +0 -87
  127. package/src/rollback/smart-rollback-system.ts +0 -866
  128. package/src/schemas/deployment.schema.json +0 -58
  129. package/src/schemas/flow.schema.json +0 -79
  130. package/src/schemas/widget.schema.json +0 -72
  131. package/src/snow-flow-system.ts +0 -541
  132. package/src/sparc/sparc-help.ts +0 -49
  133. package/src/sparc/team-sparc.ts +0 -88
  134. package/src/strategies/global-scope-strategy.ts +0 -736
  135. package/src/templates/base/application.template.json +0 -45
  136. package/src/templates/base/business_rule.template.json +0 -33
  137. package/src/templates/base/script_include.template.json +0 -18
  138. package/src/templates/base/table.template.json +0 -64
  139. package/src/templates/base/widget.template.json +0 -25
  140. package/src/templates/patterns/composite.incident-management.template.json +0 -140
  141. package/src/templates/patterns/widget.dashboard.template.json +0 -238
  142. package/src/templates/patterns/widget.datatable.template.json +0 -292
  143. package/src/testing/integration-test-suite.ts +0 -1276
  144. package/src/types/index.ts +0 -183
  145. package/src/types/neo4j-driver.d.ts +0 -23
  146. package/src/types/servicenow.types.ts +0 -307
  147. package/src/types/snow-flow.types.ts +0 -186
  148. package/src/types/todo.types.ts +0 -70
  149. package/src/utils/action-type-cache.ts +0 -286
  150. package/src/utils/agent-detector.ts +0 -573
  151. package/src/utils/artifact-tracker.ts +0 -379
  152. package/src/utils/dependency-detector.ts +0 -233
  153. package/src/utils/deployment-metadata-handler.ts +0 -518
  154. package/src/utils/error-recovery.ts +0 -680
  155. package/src/utils/logger.ts +0 -60
  156. package/src/utils/mcp-auth-middleware.ts +0 -262
  157. package/src/utils/mcp-config-manager.ts +0 -270
  158. package/src/utils/mcp-server-manager.ts +0 -446
  159. package/src/utils/mcp-tool-registry.ts +0 -298
  160. package/src/utils/migrate-snow-flow.ts +0 -98
  161. package/src/utils/oauth-html-templates.ts +0 -188
  162. package/src/utils/scope-utils.ts +0 -443
  163. package/src/utils/servicenow-client.ts +0 -3321
  164. package/src/utils/servicenow-id-generator.ts +0 -181
  165. package/src/utils/snow-memory-manager.ts +0 -605
  166. package/src/utils/snow-oauth.ts +0 -797
  167. package/src/utils/template-engine.ts +0 -463
  168. package/src/utils/theme-manager.ts +0 -295
  169. package/src/utils/unified-auth-store.ts +0 -222
  170. package/src/utils/update-set-importer.ts +0 -422
  171. package/src/utils/update-set-xml-packager.ts +0 -371
  172. package/src/utils/widget-template-generator.ts +0 -1744
  173. package/src/version.ts +0 -1950
@@ -1,379 +0,0 @@
1
- /**
2
- * Artifact Tracker - Manages consistent sys_id tracking and validation
3
- * Solves the sys_id inconsistency problem identified in feedback
4
- */
5
-
6
- import { Logger } from './logger.js';
7
- import { ServiceNowClient } from './servicenow-client.js';
8
-
9
- export interface ArtifactSession {
10
- sessionId: string;
11
- artifacts: Map<string, TrackedArtifact>;
12
- createdAt: Date;
13
- lastAccessed: Date;
14
- }
15
-
16
- export interface TrackedArtifact {
17
- sys_id: string;
18
- table: string;
19
- name: string;
20
- type: string;
21
- status: 'pending' | 'deployed' | 'modified' | 'error';
22
- operations: ArtifactOperation[];
23
- lastValidated: Date;
24
- updateSetId?: string;
25
- }
26
-
27
- export interface ArtifactOperation {
28
- operation: 'create' | 'update' | 'delete' | 'validate';
29
- timestamp: Date;
30
- success: boolean;
31
- details: string;
32
- error?: string;
33
- }
34
-
35
- export class ArtifactTracker {
36
- private logger: Logger;
37
- private client: ServiceNowClient;
38
- private sessions: Map<string, ArtifactSession> = new Map();
39
- private currentSessionId: string | null = null;
40
-
41
- constructor() {
42
- this.logger = new Logger('ArtifactTracker');
43
- this.client = new ServiceNowClient();
44
- }
45
-
46
- /**
47
- * Create or resume a tracking session
48
- */
49
- startSession(sessionId?: string): string {
50
- const id = sessionId || this.generateSessionId();
51
-
52
- if (!this.sessions.has(id)) {
53
- this.sessions.set(id, {
54
- sessionId: id,
55
- artifacts: new Map(),
56
- createdAt: new Date(),
57
- lastAccessed: new Date()
58
- });
59
- this.logger.info(`Started new artifact tracking session: ${id}`);
60
- } else {
61
- const session = this.sessions.get(id)!;
62
- session.lastAccessed = new Date();
63
- this.logger.info(`Resumed artifact tracking session: ${id}`);
64
- }
65
-
66
- this.currentSessionId = id;
67
- return id;
68
- }
69
-
70
- /**
71
- * Track a new artifact
72
- */
73
- trackArtifact(
74
- sys_id: string,
75
- table: string,
76
- name: string,
77
- type: string,
78
- operation: 'create' | 'update' = 'create'
79
- ): TrackedArtifact {
80
- if (!this.currentSessionId) {
81
- this.startSession();
82
- }
83
-
84
- const session = this.sessions.get(this.currentSessionId!)!;
85
-
86
- // Check for existing tracking
87
- const existingKey = this.findArtifactKey(sys_id, name, type);
88
- if (existingKey && existingKey !== sys_id) {
89
- this.logger.warn(`Sys_id inconsistency detected! Found existing artifact with different sys_id:`, {
90
- new_sys_id: sys_id,
91
- existing_sys_id: existingKey,
92
- name,
93
- type
94
- });
95
- }
96
-
97
- const artifact: TrackedArtifact = {
98
- sys_id,
99
- table,
100
- name,
101
- type,
102
- status: operation === 'create' ? 'pending' : 'modified',
103
- operations: [{
104
- operation,
105
- timestamp: new Date(),
106
- success: true,
107
- details: `Artifact tracked for ${operation}`
108
- }],
109
- lastValidated: new Date()
110
- };
111
-
112
- session.artifacts.set(sys_id, artifact);
113
- this.logger.info(`Tracking artifact: ${name} (${sys_id}) in table ${table}`);
114
-
115
- return artifact;
116
- }
117
-
118
- /**
119
- * Validate that a sys_id actually exists in ServiceNow
120
- */
121
- async validateArtifact(sys_id: string): Promise<boolean> {
122
- if (!this.currentSessionId) {
123
- return false;
124
- }
125
-
126
- const session = this.sessions.get(this.currentSessionId);
127
- if (!session) {
128
- return false;
129
- }
130
-
131
- const artifact = session.artifacts.get(sys_id);
132
- if (!artifact) {
133
- this.logger.warn(`Cannot validate unknown artifact: ${sys_id}`);
134
- return false;
135
- }
136
-
137
- try {
138
- this.logger.info(`Validating artifact ${sys_id} in table ${artifact.table}`);
139
-
140
- // getRecord returns the data directly or throws an error
141
- const data = await this.client.getRecord(artifact.table, sys_id);
142
-
143
- // If we got here without throwing, the record exists
144
- const isValid = !!data;
145
-
146
- // Update tracking
147
- artifact.operations.push({
148
- operation: 'validate',
149
- timestamp: new Date(),
150
- success: isValid,
151
- details: isValid ? 'Artifact exists in ServiceNow' : 'Artifact not found in ServiceNow',
152
- error: undefined
153
- });
154
- artifact.lastValidated = new Date();
155
-
156
- return isValid;
157
- } catch (error) {
158
- // Handle specific error cases
159
- const errorMessage = String(error);
160
- let validationDetails = 'Validation error';
161
- let skipErrorStatus = false;
162
-
163
- // Check if it's a permission error (403) or authentication error (401)
164
- if (errorMessage.includes('403') || errorMessage.includes('Forbidden')) {
165
- validationDetails = 'Unable to validate - insufficient read permissions';
166
- skipErrorStatus = true; // Don't mark as error since deployment succeeded
167
- this.logger.warn(`Permission issue during validation for ${sys_id}, but deployment was successful`);
168
- } else if (errorMessage.includes('401') || errorMessage.includes('Unauthorized')) {
169
- validationDetails = 'Unable to validate - authentication issue';
170
- skipErrorStatus = true;
171
- this.logger.warn(`Authentication issue during validation for ${sys_id}, but deployment was successful`);
172
- } else {
173
- this.logger.error(`Error validating artifact ${sys_id}:`, error);
174
- }
175
-
176
- artifact.operations.push({
177
- operation: 'validate',
178
- timestamp: new Date(),
179
- success: false,
180
- details: validationDetails,
181
- error: errorMessage
182
- });
183
-
184
- // Only mark as error if it's not a permission issue and deployment already succeeded
185
- if (!skipErrorStatus && artifact.status !== 'deployed') {
186
- artifact.status = 'error';
187
- }
188
-
189
- // For permission/auth errors on successfully deployed artifacts, consider it valid
190
- if (skipErrorStatus && artifact.status === 'deployed') {
191
- return true;
192
- }
193
-
194
- return false;
195
- }
196
- }
197
-
198
- /**
199
- * Record an operation on a tracked artifact
200
- */
201
- recordOperation(
202
- sys_id: string,
203
- operation: 'create' | 'update' | 'delete',
204
- success: boolean,
205
- details: string,
206
- error?: string
207
- ): void {
208
- if (!this.currentSessionId) {
209
- return;
210
- }
211
-
212
- const session = this.sessions.get(this.currentSessionId);
213
- if (!session) {
214
- return;
215
- }
216
-
217
- const artifact = session.artifacts.get(sys_id);
218
- if (!artifact) {
219
- this.logger.warn(`Cannot record operation for unknown artifact: ${sys_id}`);
220
- return;
221
- }
222
-
223
- artifact.operations.push({
224
- operation,
225
- timestamp: new Date(),
226
- success,
227
- details,
228
- error
229
- });
230
-
231
- // Update status
232
- if (success) {
233
- artifact.status = operation === 'create' ? 'deployed' : 'modified';
234
- } else {
235
- artifact.status = 'error';
236
- }
237
-
238
- this.logger.info(`Recorded ${operation} operation for ${sys_id}: ${success ? 'success' : 'failure'}`);
239
- }
240
-
241
- /**
242
- * Get all tracked artifacts in current session
243
- */
244
- getTrackedArtifacts(): TrackedArtifact[] {
245
- if (!this.currentSessionId) {
246
- return [];
247
- }
248
-
249
- const session = this.sessions.get(this.currentSessionId);
250
- if (!session) {
251
- return [];
252
- }
253
-
254
- return Array.from(session.artifacts.values());
255
- }
256
-
257
- /**
258
- * Get specific artifact by sys_id
259
- */
260
- getArtifact(sys_id: string): TrackedArtifact | null {
261
- if (!this.currentSessionId) {
262
- return null;
263
- }
264
-
265
- const session = this.sessions.get(this.currentSessionId);
266
- if (!session) {
267
- return null;
268
- }
269
-
270
- return session.artifacts.get(sys_id) || null;
271
- }
272
-
273
- /**
274
- * Find sys_id inconsistencies
275
- */
276
- findInconsistencies(): Array<{
277
- artifacts: TrackedArtifact[];
278
- issue: string;
279
- }> {
280
- const inconsistencies = [];
281
-
282
- if (!this.currentSessionId) {
283
- return inconsistencies;
284
- }
285
-
286
- const session = this.sessions.get(this.currentSessionId);
287
- if (!session) {
288
- return inconsistencies;
289
- }
290
-
291
- const artifacts = Array.from(session.artifacts.values());
292
- const nameTypeMap = new Map<string, TrackedArtifact[]>();
293
-
294
- // Group by name + type
295
- for (const artifact of artifacts) {
296
- const key = `${artifact.name}:${artifact.type}`;
297
- if (!nameTypeMap.has(key)) {
298
- nameTypeMap.set(key, []);
299
- }
300
- nameTypeMap.get(key)!.push(artifact);
301
- }
302
-
303
- // Find duplicates
304
- for (const [key, duplicates] of nameTypeMap.entries()) {
305
- if (duplicates.length > 1) {
306
- inconsistencies.push({
307
- artifacts: duplicates,
308
- issue: `Multiple sys_ids for same artifact: ${key}`
309
- });
310
- }
311
- }
312
-
313
- return inconsistencies;
314
- }
315
-
316
- /**
317
- * Generate session summary for debugging
318
- */
319
- getSessionSummary(): any {
320
- if (!this.currentSessionId) {
321
- return { error: 'No active session' };
322
- }
323
-
324
- const session = this.sessions.get(this.currentSessionId);
325
- if (!session) {
326
- return { error: 'Session not found' };
327
- }
328
-
329
- const artifacts = Array.from(session.artifacts.values());
330
- const summary = {
331
- sessionId: this.currentSessionId,
332
- artifactCount: artifacts.length,
333
- statusCounts: {
334
- pending: artifacts.filter(a => a.status === 'pending').length,
335
- deployed: artifacts.filter(a => a.status === 'deployed').length,
336
- modified: artifacts.filter(a => a.status === 'modified').length,
337
- error: artifacts.filter(a => a.status === 'error').length
338
- },
339
- inconsistencies: this.findInconsistencies(),
340
- artifacts: artifacts.map(a => ({
341
- sys_id: a.sys_id,
342
- name: a.name,
343
- type: a.type,
344
- status: a.status,
345
- operationCount: a.operations.length,
346
- lastValidated: a.lastValidated
347
- }))
348
- };
349
-
350
- return summary;
351
- }
352
-
353
- private findArtifactKey(sys_id: string, name: string, type: string): string | null {
354
- if (!this.currentSessionId) {
355
- return null;
356
- }
357
-
358
- const session = this.sessions.get(this.currentSessionId);
359
- if (!session) {
360
- return null;
361
- }
362
-
363
- // Look for existing artifact with same name and type
364
- for (const [existingSysId, artifact] of session.artifacts.entries()) {
365
- if (artifact.name === name && artifact.type === type && existingSysId !== sys_id) {
366
- return existingSysId;
367
- }
368
- }
369
-
370
- return null;
371
- }
372
-
373
- private generateSessionId(): string {
374
- return `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
375
- }
376
- }
377
-
378
- // Global instance for session management
379
- export const artifactTracker = new ArtifactTracker();
@@ -1,233 +0,0 @@
1
- /**
2
- * Dependency Detector for ServiceNow Widgets
3
- * Automatically detects external libraries used in widget code
4
- * and manages their installation in Service Portal themes
5
- */
6
-
7
- import { logger } from '../utils/logger';
8
-
9
- export interface DependencyInfo {
10
- name: string;
11
- version?: string;
12
- cdnUrl: string;
13
- minifiedUrl?: string;
14
- integrity?: string;
15
- type: 'js' | 'css';
16
- description: string;
17
- detectionPatterns: RegExp[];
18
- }
19
-
20
- // Common libraries used in ServiceNow widgets
21
- export const KNOWN_DEPENDENCIES: DependencyInfo[] = [
22
- {
23
- name: 'Chart.js',
24
- version: '4.4.1',
25
- cdnUrl: 'https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.js',
26
- minifiedUrl: 'https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js',
27
- type: 'js',
28
- description: 'Simple yet flexible JavaScript charting library',
29
- detectionPatterns: [
30
- /new\s+Chart\s*\(/gi,
31
- /Chart\.register/gi,
32
- /Chart\.defaults/gi,
33
- /require\s*\(\s*['"]chart\.js['"]\s*\)/gi,
34
- /import.*from\s+['"]chart\.js['"]/gi
35
- ]
36
- },
37
- {
38
- name: 'moment.js',
39
- version: '2.29.4',
40
- cdnUrl: 'https://cdn.jsdelivr.net/npm/moment@2.29.4/moment.js',
41
- minifiedUrl: 'https://cdn.jsdelivr.net/npm/moment@2.29.4/moment.min.js',
42
- type: 'js',
43
- description: 'Parse, validate, manipulate, and display dates and times',
44
- detectionPatterns: [
45
- /moment\s*\(/gi,
46
- /moment\.utc/gi,
47
- /moment\.format/gi,
48
- /require\s*\(\s*['"]moment['"]\s*\)/gi,
49
- /import.*from\s+['"]moment['"]/gi
50
- ]
51
- },
52
- {
53
- name: 'lodash',
54
- version: '4.17.21',
55
- cdnUrl: 'https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.js',
56
- minifiedUrl: 'https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js',
57
- type: 'js',
58
- description: 'Modern JavaScript utility library',
59
- detectionPatterns: [
60
- /_\.\w+\s*\(/gi,
61
- /lodash\.\w+/gi,
62
- /require\s*\(\s*['"]lodash['"]\s*\)/gi,
63
- /import.*from\s+['"]lodash['"]/gi
64
- ]
65
- },
66
- {
67
- name: 'd3.js',
68
- version: '7.8.5',
69
- cdnUrl: 'https://cdn.jsdelivr.net/npm/d3@7.8.5/dist/d3.js',
70
- minifiedUrl: 'https://cdn.jsdelivr.net/npm/d3@7.8.5/dist/d3.min.js',
71
- type: 'js',
72
- description: 'Data-Driven Documents - powerful visualization library',
73
- detectionPatterns: [
74
- /d3\.\w+\s*\(/gi,
75
- /d3\.select/gi,
76
- /d3\.scale/gi,
77
- /require\s*\(\s*['"]d3['"]\s*\)/gi,
78
- /import.*from\s+['"]d3['"]/gi
79
- ]
80
- },
81
- {
82
- name: 'axios',
83
- version: '1.6.5',
84
- cdnUrl: 'https://cdn.jsdelivr.net/npm/axios@1.6.5/dist/axios.js',
85
- minifiedUrl: 'https://cdn.jsdelivr.net/npm/axios@1.6.5/dist/axios.min.js',
86
- type: 'js',
87
- description: 'Promise based HTTP client',
88
- detectionPatterns: [
89
- /axios\.\w+\s*\(/gi,
90
- /axios\.get/gi,
91
- /axios\.post/gi,
92
- /require\s*\(\s*['"]axios['"]\s*\)/gi,
93
- /import.*from\s+['"]axios['"]/gi
94
- ]
95
- },
96
- {
97
- name: 'jQuery',
98
- version: '3.7.1',
99
- cdnUrl: 'https://code.jquery.com/jquery-3.7.1.js',
100
- minifiedUrl: 'https://code.jquery.com/jquery-3.7.1.min.js',
101
- integrity: 'sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=',
102
- type: 'js',
103
- description: 'jQuery JavaScript Library',
104
- detectionPatterns: [
105
- /\$\s*\(/gi,
106
- /jQuery\s*\(/gi,
107
- /\$\.ajax/gi,
108
- /\$\.\w+\s*\(/gi,
109
- /require\s*\(\s*['"]jquery['"]\s*\)/gi
110
- ]
111
- },
112
- {
113
- name: 'Bootstrap',
114
- version: '5.3.2',
115
- cdnUrl: 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.js',
116
- minifiedUrl: 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js',
117
- type: 'js',
118
- description: 'Bootstrap JavaScript bundle',
119
- detectionPatterns: [
120
- /bootstrap\.\w+/gi,
121
- /new\s+bootstrap\.\w+/gi,
122
- /data-bs-\w+/gi,
123
- /class=["'].*\b(btn|modal|dropdown|collapse)\b/gi
124
- ]
125
- },
126
- {
127
- name: 'Bootstrap CSS',
128
- version: '5.3.2',
129
- cdnUrl: 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.css',
130
- minifiedUrl: 'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css',
131
- type: 'css',
132
- description: 'Bootstrap CSS framework',
133
- detectionPatterns: [
134
- /class=["'].*\b(container|row|col-|btn-|alert-|modal-)\b/gi,
135
- /@import.*bootstrap/gi
136
- ]
137
- }
138
- ];
139
-
140
- export class DependencyDetector {
141
- /**
142
- * Detect dependencies in widget code
143
- */
144
- static detectDependencies(code: string): DependencyInfo[] {
145
- const detectedDeps: DependencyInfo[] = [];
146
- const codeToAnalyze = code.toLowerCase();
147
-
148
- for (const dep of KNOWN_DEPENDENCIES) {
149
- for (const pattern of dep.detectionPatterns) {
150
- if (pattern.test(code)) {
151
- // Avoid duplicates
152
- if (!detectedDeps.find(d => d.name === dep.name)) {
153
- detectedDeps.push(dep);
154
- logger.info(`🔍 Detected dependency: ${dep.name}`);
155
- }
156
- break;
157
- }
158
- }
159
- }
160
-
161
- return detectedDeps;
162
- }
163
-
164
- /**
165
- * Analyze widget for dependencies
166
- */
167
- static analyzeWidget(widget: {
168
- template?: string;
169
- css?: string;
170
- client_script?: string;
171
- server_script?: string;
172
- }): DependencyInfo[] {
173
- const allCode = [
174
- widget.template || '',
175
- widget.css || '',
176
- widget.client_script || '',
177
- widget.server_script || ''
178
- ].join('\n');
179
-
180
- return this.detectDependencies(allCode);
181
- }
182
-
183
- /**
184
- * Generate script tags for dependencies
185
- */
186
- static generateScriptTags(dependencies: DependencyInfo[], useMinified = true): string {
187
- const tags: string[] = [];
188
-
189
- for (const dep of dependencies) {
190
- const url = useMinified && dep.minifiedUrl ? dep.minifiedUrl : dep.cdnUrl;
191
-
192
- if (dep.type === 'js') {
193
- if (dep.integrity) {
194
- tags.push(`<script src="${url}" integrity="${dep.integrity}" crossorigin="anonymous"></script>`);
195
- } else {
196
- tags.push(`<script src="${url}"></script>`);
197
- }
198
- } else if (dep.type === 'css') {
199
- if (dep.integrity) {
200
- tags.push(`<link rel="stylesheet" href="${url}" integrity="${dep.integrity}" crossorigin="anonymous">`);
201
- } else {
202
- tags.push(`<link rel="stylesheet" href="${url}">`);
203
- }
204
- }
205
- }
206
-
207
- return tags.join('\n');
208
- }
209
-
210
- /**
211
- * Check if a dependency is likely already loaded
212
- */
213
- static isDependencyLoaded(themeContent: string, dependency: DependencyInfo): boolean {
214
- // Check for various patterns that indicate the library is already loaded
215
- const patterns = [
216
- new RegExp(dependency.name.replace('.', '\\.'), 'i'),
217
- new RegExp(dependency.cdnUrl.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i'),
218
- new RegExp(dependency.minifiedUrl?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') || '', 'i')
219
- ];
220
-
221
- return patterns.some(pattern => pattern.test(themeContent));
222
- }
223
-
224
- /**
225
- * Get missing dependencies from theme
226
- */
227
- static getMissingDependencies(
228
- detectedDeps: DependencyInfo[],
229
- themeContent: string
230
- ): DependencyInfo[] {
231
- return detectedDeps.filter(dep => !this.isDependencyLoaded(themeContent, dep));
232
- }
233
- }