iwgt 2.4.10 → 2.4.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/dist/server.js CHANGED
@@ -17,6 +17,7 @@ import liquidFilters from './data/references/liquid-filters.json' with { type: '
17
17
  import commonjsReference from './data/references/commonjs-reference.json' with { type: 'json' };
18
18
  import collectionsMenuPatterns from './data/references/collections-menu-patterns.json' with { type: 'json' };
19
19
  import librariesApiReference from './data/references/libraries-api-reference.json' with { type: 'json' };
20
+ import javascriptGuide from './data/references/javascript-guide.json' with { type: 'json' };
20
21
  // Импорт модулей
21
22
  import { generateWidgetFiles } from './generators/index.js';
22
23
  import * as tools from './tools/index.js';
@@ -26,7 +27,7 @@ export class WidgetServer {
26
27
  constructor() {
27
28
  this.server = new Server({
28
29
  name: 'insales-widgets',
29
- version: '2.4.10',
30
+ version: '2.4.12',
30
31
  }, {
31
32
  capabilities: {
32
33
  tools: {},
@@ -251,6 +252,35 @@ export class WidgetServer {
251
252
  },
252
253
  },
253
254
  },
255
+ {
256
+ name: 'get_javascript_guide',
257
+ description: 'Получить руководство по написанию JavaScript для виджетов InSales. Включает принципы, API, паттерны, частые ошибки, отладку и best practices.',
258
+ inputSchema: {
259
+ type: 'object',
260
+ properties: {
261
+ section: {
262
+ type: 'string',
263
+ description: 'Конкретный раздел руководства (principles, global_apis, data_attributes, patterns, common_errors, debugging, linting, checklist, golden_rule)',
264
+ },
265
+ search: {
266
+ type: 'string',
267
+ description: 'Поиск по всему руководству по ключевым словам',
268
+ },
269
+ pattern: {
270
+ type: 'string',
271
+ description: 'ID конкретного паттерна (widget_isolation, declarative_cart, counters, mobile_menu, scroll_animation, products_work, cart_events)',
272
+ },
273
+ error: {
274
+ type: 'string',
275
+ description: 'ID конкретной ошибки (no_widget_isolation, global_selectors, reinventing_wheel, using_imports, return_outside_function, forgot_mobile)',
276
+ },
277
+ api_module: {
278
+ type: 'string',
279
+ description: 'Название модуля API (Cart, Products, EventBus, Shop, ajaxAPI, Template, AjaxSearch)',
280
+ },
281
+ },
282
+ },
283
+ },
254
284
  ],
255
285
  }));
256
286
  // Список ресурсов
@@ -322,6 +352,12 @@ export class WidgetServer {
322
352
  mimeType: 'application/json',
323
353
  description: 'Подробная API документация библиотек: InsalesCutList и другие',
324
354
  },
355
+ {
356
+ uri: 'insales://javascript-guide',
357
+ name: 'JavaScript руководство',
358
+ mimeType: 'application/json',
359
+ description: 'Полное руководство по написанию JavaScript для виджетов InSales: принципы, API, паттерны, ошибки, отладка',
360
+ },
325
361
  ],
326
362
  }));
327
363
  // Чтение ресурсов
@@ -420,7 +456,7 @@ export class WidgetServer {
420
456
  };
421
457
  case 'insales://widget-architecture': {
422
458
  // Читаем markdown файл с документацией об архитектуре
423
- const docPath = join(__dirname, '../context-content/doc/4 поколение/Виджеты/widget-wrapper-and-context.md');
459
+ const docPath = join(__dirname, 'data/widget-wrapper-and-context.md');
424
460
  const content = readFileSync(docPath, 'utf-8');
425
461
  return {
426
462
  contents: [
@@ -442,6 +478,16 @@ export class WidgetServer {
442
478
  },
443
479
  ],
444
480
  };
481
+ case 'insales://javascript-guide':
482
+ return {
483
+ contents: [
484
+ {
485
+ uri,
486
+ mimeType: 'application/json',
487
+ text: JSON.stringify(javascriptGuide, null, 2),
488
+ },
489
+ ],
490
+ };
445
491
  default:
446
492
  throw new Error(`Unknown resource: ${uri}`);
447
493
  }
@@ -543,6 +589,15 @@ export class WidgetServer {
543
589
  },
544
590
  ],
545
591
  };
592
+ case 'get_javascript_guide':
593
+ return {
594
+ content: [
595
+ {
596
+ type: 'text',
597
+ text: JSON.stringify(tools.getJavaScriptGuide(args || {}), null, 2),
598
+ },
599
+ ],
600
+ };
546
601
  default:
547
602
  throw new Error(`Unknown tool: ${name}`);
548
603
  }
@@ -43,4 +43,8 @@ export declare function getLiquidVariables(args?: any): any;
43
43
  * Получить постоянные ссылки InSales
44
44
  */
45
45
  export declare function getInsalesPermanentLinks(args?: any): any;
46
+ /**
47
+ * Получить руководство по JavaScript для виджетов
48
+ */
49
+ export declare function getJavaScriptGuide(args?: any): any;
46
50
  //# sourceMappingURL=index.d.ts.map
@@ -13,6 +13,7 @@ import commonjsApiComplete from '../data/references/commonjs-api-complete.json'
13
13
  import collectionsMenuPatterns from '../data/references/collections-menu-patterns.json' with { type: 'json' };
14
14
  import librariesApiReference from '../data/references/libraries-api-reference.json' with { type: 'json' };
15
15
  import insalesPermanentLinks from '../data/insales-permanent-links.json' with { type: 'json' };
16
+ import javascriptGuide from '../data/references/javascript-guide.json' with { type: 'json' };
16
17
  /**
17
18
  * Получить список блок-темплейтов с фильтрацией
18
19
  */
@@ -147,7 +148,12 @@ export function getLiquidFilters(args = {}) {
147
148
  export function getCommonJSAPI(args = {}) {
148
149
  const { category, module, search } = args;
149
150
  const data = commonjsApiComplete;
150
- let modules = data.modules || [];
151
+ // Получаем модули из global_modules
152
+ const globalModules = data.global_modules || {};
153
+ let modules = Object.keys(globalModules).map(key => ({
154
+ name: key,
155
+ ...globalModules[key]
156
+ }));
151
157
  if (module) {
152
158
  modules = modules.filter((mod) => mod.name === module);
153
159
  }
@@ -158,16 +164,20 @@ export function getCommonJSAPI(args = {}) {
158
164
  const searchLower = search.toLowerCase();
159
165
  modules = modules.filter((mod) => mod.name.toLowerCase().includes(searchLower) ||
160
166
  mod.description?.toLowerCase().includes(searchLower) ||
161
- mod.methods?.some((m) => m.name.toLowerCase().includes(searchLower)));
167
+ (mod.methods && Object.keys(mod.methods).some((methodName) => methodName.toLowerCase().includes(searchLower))) ||
168
+ (mod.events && Object.keys(mod.events).some((eventName) => eventName.toLowerCase().includes(searchLower))));
162
169
  }
163
170
  return {
164
171
  total: modules.length,
165
172
  modules: modules.map((mod) => ({
166
173
  name: mod.name,
167
174
  description: mod.description,
168
- category: mod.category,
169
- methods: mod.methods || [],
170
- events: mod.events || []
175
+ global_access: mod.global_access,
176
+ type: mod.type,
177
+ declarative: mod.declarative,
178
+ methods: mod.methods || {},
179
+ events: mod.events || {},
180
+ data_attributes: mod.data_attributes || {}
171
181
  }))
172
182
  };
173
183
  }
@@ -306,4 +316,125 @@ export function getInsalesPermanentLinks(args = {}) {
306
316
  notes: data.notes
307
317
  };
308
318
  }
319
+ /**
320
+ * Получить руководство по JavaScript для виджетов
321
+ */
322
+ export function getJavaScriptGuide(args = {}) {
323
+ const { section, search, pattern, error, api_module } = args;
324
+ const data = javascriptGuide;
325
+ if (section) {
326
+ const sectionData = data.sections?.[section];
327
+ if (sectionData) {
328
+ return {
329
+ section,
330
+ ...sectionData
331
+ };
332
+ }
333
+ return { error: `Раздел '${section}' не найден` };
334
+ }
335
+ if (pattern) {
336
+ const patterns = data.sections?.patterns?.patterns || [];
337
+ const foundPattern = patterns.find((p) => p.id === pattern);
338
+ if (foundPattern) {
339
+ return {
340
+ pattern: foundPattern
341
+ };
342
+ }
343
+ return { error: `Паттерн '${pattern}' не найден` };
344
+ }
345
+ if (error) {
346
+ const errors = data.sections?.common_errors?.errors || [];
347
+ const foundError = errors.find((e) => e.id === error);
348
+ if (foundError) {
349
+ return {
350
+ error: foundError
351
+ };
352
+ }
353
+ return { error: `Ошибка '${error}' не найдена` };
354
+ }
355
+ if (api_module) {
356
+ const modules = data.sections?.global_apis?.modules || [];
357
+ const foundModule = modules.find((m) => m.name === api_module);
358
+ if (foundModule) {
359
+ return {
360
+ module: foundModule
361
+ };
362
+ }
363
+ return { error: `Модуль API '${api_module}' не найден` };
364
+ }
365
+ if (search) {
366
+ const searchLower = search.toLowerCase();
367
+ const results = {
368
+ sections: {},
369
+ patterns: [],
370
+ errors: [],
371
+ modules: [],
372
+ attributes: []
373
+ };
374
+ // Поиск по разделам
375
+ Object.keys(data.sections || {}).forEach(sectionKey => {
376
+ const section = data.sections[sectionKey];
377
+ if (section.title?.toLowerCase().includes(searchLower) ||
378
+ section.description?.toLowerCase().includes(searchLower)) {
379
+ results.sections[sectionKey] = section;
380
+ }
381
+ });
382
+ // Поиск по паттернам
383
+ const patterns = data.sections?.patterns?.patterns || [];
384
+ patterns.forEach((pattern) => {
385
+ if (pattern.title?.toLowerCase().includes(searchLower) ||
386
+ pattern.description?.toLowerCase().includes(searchLower) ||
387
+ pattern.code?.toLowerCase().includes(searchLower)) {
388
+ results.patterns.push(pattern);
389
+ }
390
+ });
391
+ // Поиск по ошибкам
392
+ const errors = data.sections?.common_errors?.errors || [];
393
+ errors.forEach((error) => {
394
+ if (error.title?.toLowerCase().includes(searchLower) ||
395
+ error.description?.toLowerCase().includes(searchLower)) {
396
+ results.errors.push(error);
397
+ }
398
+ });
399
+ // Поиск по модулям API
400
+ const modules = data.sections?.global_apis?.modules || [];
401
+ modules.forEach((module) => {
402
+ if (module.name?.toLowerCase().includes(searchLower) ||
403
+ module.description?.toLowerCase().includes(searchLower)) {
404
+ results.modules.push(module);
405
+ }
406
+ });
407
+ // Поиск по data-атрибутам
408
+ const attributes = data.sections?.data_attributes?.attributes || [];
409
+ attributes.forEach((attr) => {
410
+ if (attr.name?.toLowerCase().includes(searchLower) ||
411
+ attr.description?.toLowerCase().includes(searchLower)) {
412
+ results.attributes.push(attr);
413
+ }
414
+ });
415
+ return {
416
+ search,
417
+ total: Object.keys(results.sections).length + results.patterns.length +
418
+ results.errors.length + results.modules.length + results.attributes.length,
419
+ results
420
+ };
421
+ }
422
+ return {
423
+ title: data.title,
424
+ description: data.description,
425
+ version: data.version,
426
+ sections: Object.keys(data.sections || {}),
427
+ available_sections: {
428
+ principles: "Основные принципы написания JavaScript",
429
+ global_apis: "Глобальные API (Cart, Products, EventBus, etc.)",
430
+ data_attributes: "Data-атрибуты CommonJS",
431
+ patterns: "Паттерны и примеры кода",
432
+ common_errors: "Частые ошибки и их исправление",
433
+ debugging: "Способы отладки",
434
+ linting: "Линтер и проверка кода",
435
+ checklist: "Чеклист перед завершением",
436
+ golden_rule: "Золотое правило"
437
+ }
438
+ };
439
+ }
309
440
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iwgt",
3
- "version": "2.4.10",
3
+ "version": "2.4.12",
4
4
  "description": "MCP server",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",