@appaflytech/zeyrek-ai-mcp 0.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 (88) hide show
  1. package/.env.example +46 -0
  2. package/README.md +260 -0
  3. package/dist/config.js +128 -0
  4. package/dist/index.js +88 -0
  5. package/dist/knowledge/componentCatalog.js +438 -0
  6. package/dist/knowledge/componentEvents.js +164 -0
  7. package/dist/knowledge/coverage.js +60 -0
  8. package/dist/knowledge/normalize.js +1309 -0
  9. package/dist/knowledge/outlines.js +167 -0
  10. package/dist/knowledge/policy.js +44 -0
  11. package/dist/knowledge/reservedTables.js +75 -0
  12. package/dist/knowledge/rules.js +1725 -0
  13. package/dist/observability/trace.js +337 -0
  14. package/dist/platform/errors.js +132 -0
  15. package/dist/platform/http.js +169 -0
  16. package/dist/platform/responses.js +94 -0
  17. package/dist/platform/token.js +79 -0
  18. package/dist/resources/examples/entity-pair-m2m.json +105 -0
  19. package/dist/resources/examples/flow-list-to-form.json +65 -0
  20. package/dist/resources/examples/flow-load-table.json +178 -0
  21. package/dist/resources/examples/microservice-table-list.json +49 -0
  22. package/dist/resources/examples/middleware-authenticate.json +194 -0
  23. package/dist/resources/examples/page-detail-profile.json +95 -0
  24. package/dist/resources/examples/page-dynamic-form.json +221 -0
  25. package/dist/resources/examples/page-form-upsert.json +279 -0
  26. package/dist/resources/examples/page-html-embed.json +106 -0
  27. package/dist/resources/examples/page-sign-in.json +194 -0
  28. package/dist/resources/examples/workflow-basic.json +94 -0
  29. package/dist/resources/guides/component.md +108 -0
  30. package/dist/resources/guides/entity.md +348 -0
  31. package/dist/resources/guides/expressions.md +139 -0
  32. package/dist/resources/guides/getting-started.md +109 -0
  33. package/dist/resources/guides/html.md +106 -0
  34. package/dist/resources/guides/microservice.md +313 -0
  35. package/dist/resources/guides/middleware.md +271 -0
  36. package/dist/resources/guides/modify-existing.md +35 -0
  37. package/dist/resources/guides/page.md +1574 -0
  38. package/dist/resources/guides/view.md +89 -0
  39. package/dist/resources/guides/workflow.md +359 -0
  40. package/dist/resources/knowledge.js +44 -0
  41. package/dist/resources/schemas/CreateDatasourceCommand.json +54 -0
  42. package/dist/resources/schemas/CreateDiscoveredEntitiesCommand.json +133 -0
  43. package/dist/resources/schemas/CreateEntityCommand.json +387 -0
  44. package/dist/resources/schemas/CreateMicroserviceCommand.json +528 -0
  45. package/dist/resources/schemas/CreateQueryCommand.json +43 -0
  46. package/dist/resources/schemas/CreateViewCommand.json +158 -0
  47. package/dist/resources/schemas/CreateWorkflowCommand.json +1719 -0
  48. package/dist/resources/schemas/Filter.json +124 -0
  49. package/dist/resources/schemas/GetRowsQuery.json +122 -0
  50. package/dist/resources/schemas/PreviewMicroserviceCommand.json +565 -0
  51. package/dist/resources/schemas/PreviewQueryCommand.json +74 -0
  52. package/dist/resources/schemas/PreviewWorkflowCommand.json +981 -0
  53. package/dist/resources/schemas/StepDto.json +900 -0
  54. package/dist/resources/schemas/UpdateDatasourceCommand.json +58 -0
  55. package/dist/resources/schemas/UpdateEntityCommand.json +679 -0
  56. package/dist/resources/schemas/UpdateMicroserviceCommand.json +512 -0
  57. package/dist/resources/schemas/UpdateQueryCommand.json +86 -0
  58. package/dist/resources/schemas/UpdateViewCommand.json +153 -0
  59. package/dist/resources/schemas/UpdateWorkflowCommand.json +1719 -0
  60. package/dist/resources/schemas.js +40 -0
  61. package/dist/server.js +63 -0
  62. package/dist/tools/access.js +27 -0
  63. package/dist/tools/applications.js +59 -0
  64. package/dist/tools/automations.js +103 -0
  65. package/dist/tools/common.js +18 -0
  66. package/dist/tools/components.js +280 -0
  67. package/dist/tools/datasources.js +82 -0
  68. package/dist/tools/dependencies.js +17 -0
  69. package/dist/tools/deployments.js +17 -0
  70. package/dist/tools/dtos.js +54 -0
  71. package/dist/tools/entities.js +166 -0
  72. package/dist/tools/files.js +138 -0
  73. package/dist/tools/flows.js +226 -0
  74. package/dist/tools/folders.js +51 -0
  75. package/dist/tools/layouts.js +105 -0
  76. package/dist/tools/microservices.js +198 -0
  77. package/dist/tools/organizations.js +65 -0
  78. package/dist/tools/pages.js +597 -0
  79. package/dist/tools/platformInfo.js +44 -0
  80. package/dist/tools/projects.js +152 -0
  81. package/dist/tools/queries.js +48 -0
  82. package/dist/tools/rows.js +115 -0
  83. package/dist/tools/screens.js +97 -0
  84. package/dist/tools/templates.js +65 -0
  85. package/dist/tools/variables.js +94 -0
  86. package/dist/tools/views.js +58 -0
  87. package/dist/tools/workflows.js +196 -0
  88. package/package.json +49 -0
@@ -0,0 +1,167 @@
1
+ function asArray(value) {
2
+ return Array.isArray(value) ? value.filter((entry) => Boolean(entry) && typeof entry === 'object') : [];
3
+ }
4
+ export function workflowOutline(definition) {
5
+ return {
6
+ id: definition.id,
7
+ slug: definition.slug,
8
+ name: definition.name,
9
+ type: definition.type,
10
+ parameterDtoId: definition.parameterDtoId ?? null,
11
+ returnDtoId: definition.returnDtoId ?? null,
12
+ stepCount: asArray(definition.steps).length,
13
+ steps: asArray(definition.steps).map(step => ({
14
+ id: step.id,
15
+ name: step.name,
16
+ type: step.type,
17
+ branches: asArray(step.branches).map(branch => ({
18
+ name: branch.name,
19
+ type: branch.type,
20
+ nextStepId: branch.nextStepId ?? null
21
+ }))
22
+ })),
23
+ view: 'outline',
24
+ hint: "Bir step'in tam gövdesi için view:'part', part:'steps[id=<stepId>]' kullanın; değişiklik için workflow_patch."
25
+ };
26
+ }
27
+ export function microserviceOutline(definition) {
28
+ const sourceParameters = (definition.sourceParameters ?? {});
29
+ return {
30
+ id: definition.id,
31
+ slug: definition.slug,
32
+ name: definition.name,
33
+ type: definition.type,
34
+ httpMethod: definition.httpMethod,
35
+ source: definition.source,
36
+ url: definition.url,
37
+ workflowId: definition.workflowId ?? null,
38
+ queryId: definition.queryId ?? null,
39
+ sourceParameters: {
40
+ operation: sourceParameters.operation,
41
+ entityId: sourceParameters.entityId,
42
+ isSingle: sourceParameters.isSingle,
43
+ selectFieldCount: asArray(sourceParameters.selectFields).length,
44
+ selectFieldSlugs: asArray(sourceParameters.selectFields).map(field => field.fieldSlug ?? field.fieldId),
45
+ joinCount: asArray(sourceParameters.joins).length,
46
+ joinPaths: asArray(sourceParameters.joins).map(join => join.path ?? join.alias),
47
+ filterCount: asArray(sourceParameters.filters).length
48
+ },
49
+ view: 'outline',
50
+ hint: "Parça için view:'part', part:'sourceParameters.joins' gibi; değişiklik için microservice_patch."
51
+ };
52
+ }
53
+ export function entityOutline(definition) {
54
+ return {
55
+ id: definition.id,
56
+ slug: definition.slug,
57
+ name: definition.name,
58
+ datasourceId: definition.datasourceId,
59
+ fieldCount: asArray(definition.fields).length,
60
+ fields: asArray(definition.fields).map(field => ({
61
+ id: field.id,
62
+ name: field.name,
63
+ slug: field.slug,
64
+ dbType: field.dbType,
65
+ nullable: field.nullable,
66
+ relationType: field.relationType ?? 'none',
67
+ relationId: field.relationId ?? null
68
+ })),
69
+ view: 'outline',
70
+ hint: "Bir alanın tam gövdesi için view:'part', part:'fields[slug=<slug>]'; değişiklik için entity_patch."
71
+ };
72
+ }
73
+ const segmentPattern = /^(\w+)(?:\[(?:(\d+)|(\w+)=([^\]]+))\])?$/;
74
+ export function resolvePart(definition, part) {
75
+ let current = definition;
76
+ for (const segment of part.split('.')) {
77
+ const match = segmentPattern.exec(segment.trim());
78
+ if (!match || !current || typeof current !== 'object') {
79
+ throw new Error(`part yolu çözülemedi: '${segment}'. Desteklenen biçimler: alanAdi, dizi[3], dizi[id=abc], dizi[slug=email]; segmentler '.' ile bağlanır.`);
80
+ }
81
+ const [, key, index, matchField, matchValue] = match;
82
+ current = current[key];
83
+ if (index !== undefined) {
84
+ current = Array.isArray(current) ? current[Number(index)] : undefined;
85
+ }
86
+ else if (matchField !== undefined) {
87
+ current = Array.isArray(current)
88
+ ? current.find(entry => entry && typeof entry === 'object' && String(entry[matchField]) === matchValue)
89
+ : undefined;
90
+ }
91
+ if (current === undefined) {
92
+ throw new Error(`'${segment}' bulunamadı. Önce view:'outline' ile mevcut id/slug değerlerini görün.`);
93
+ }
94
+ }
95
+ return current;
96
+ }
97
+ const selectorSegment = /^([^/\[\]]+)\[(\w+)=([^\]]+)\]$/;
98
+ function unescapePointer(segment) {
99
+ return segment.replace(/~1/g, '/').replace(/~0/g, '~');
100
+ }
101
+ /**
102
+ * SAKLANAN `steps` dizisinin sırası, create'e GÖNDERİLEN sıra değildir — `/steps/5/...` gibi
103
+ * indeks yolları bu yüzden başka adımı yazıp `applied: N` ile başarı raporlar (crm koşumu B-4).
104
+ * `*_get`'in `part` sözdizimindeki seçiciyi (`steps[id=…]`, `fields[slug=…]`) patch yollarında da
105
+ * kabul edip indekse çeviriyoruz; çözülemeyen seçici, gövde platforma GİTMEDEN hata verir.
106
+ */
107
+ export function resolvePatchPointer(document, path) {
108
+ if (!path.startsWith('/'))
109
+ throw new Error(`JSON Patch yolu '/' ile başlamalı: '${path}'`);
110
+ const segments = path.split('/').slice(1);
111
+ const resolved = [];
112
+ let current = document;
113
+ let rewritten = false;
114
+ for (const segment of segments) {
115
+ const match = selectorSegment.exec(segment);
116
+ if (!match) {
117
+ const key = unescapePointer(segment);
118
+ resolved.push(segment);
119
+ current = key === '-' || !current || typeof current !== 'object'
120
+ ? undefined
121
+ : Array.isArray(current) ? current[Number(key)] : current[key];
122
+ continue;
123
+ }
124
+ const [, key, field, value] = match;
125
+ const collection = current && typeof current === 'object' ? current[key] : undefined;
126
+ if (!Array.isArray(collection)) {
127
+ throw new Error(`Patch yolu çözülemedi: '${path}' — '${key}' bir dizi değil. Mevcut yapıyı workflow_get view:'outline' ile okuyun.`);
128
+ }
129
+ const index = collection.findIndex(entry => entry && typeof entry === 'object' && String(entry[field]) === value);
130
+ if (index === -1) {
131
+ throw new Error(`Patch yolu çözülemedi: '${path}' — '${key}' dizisinde ${field}='${value}' yok. Mevcut id/ad değerlerini workflow_get view:'outline' ile okuyun.`);
132
+ }
133
+ resolved.push(key, String(index));
134
+ current = collection[index];
135
+ rewritten = true;
136
+ }
137
+ const resolvedPath = `/${resolved.join('/')}`;
138
+ return rewritten ? { path: resolvedPath, note: `${path} → ${resolvedPath}` } : { path: resolvedPath };
139
+ }
140
+ /**
141
+ * Yanıtın `applied: N` demekle yetinmemesi için: her op'un hangi step'e indiğini adıyla söyler.
142
+ */
143
+ export function describePatchTarget(document, path) {
144
+ const match = /^\/steps\/(\d+)(\/.*)?$/.exec(path);
145
+ if (!match)
146
+ return path;
147
+ const step = asArray(document.steps)[Number(match[1])];
148
+ return step
149
+ ? `${path} → '${String(step.name ?? step.id ?? '?')}' (${String(step.type ?? '?')}, id ${String(step.id ?? '?')})`
150
+ : `${path} → (dizide ${match[1]}. eleman YOK)`;
151
+ }
152
+ export function resolvePatchOperations(document, operations) {
153
+ const notes = [];
154
+ const targets = [];
155
+ const resolved = operations.map(operation => {
156
+ const path = typeof operation.path === 'string' ? operation.path : '';
157
+ const outcome = resolvePatchPointer(document, path);
158
+ const from = typeof operation.from === 'string' ? resolvePatchPointer(document, operation.from) : undefined;
159
+ if (outcome.note)
160
+ notes.push(outcome.note);
161
+ if (from?.note)
162
+ notes.push(from.note);
163
+ targets.push(describePatchTarget(document, outcome.path));
164
+ return from ? { ...operation, path: outcome.path, from: from.path } : { ...operation, path: outcome.path };
165
+ });
166
+ return { operations: resolved, notes, targets };
167
+ }
@@ -0,0 +1,44 @@
1
+ import { logStep } from '../observability/trace.js';
2
+ export class PolicyBlockError extends Error {
3
+ findings;
4
+ constructor(findings) {
5
+ super([
6
+ 'Politika kontrolü isteği durdurdu (istek platforma gönderilmedi):',
7
+ ...findings.map(finding => `- [${finding.ruleId}] ${finding.message}${finding.guide ? ` (rehber: ${finding.guide})` : ''}`),
8
+ "Bilinçli bir istisnaysa aynı çağrıyı policyOverride: true ile tekrarlayın; kural yanlışsa zeyrek-mcp/docs/08-kural-envanteri.md'ye işleyin."
9
+ ].join('\n'));
10
+ this.findings = findings;
11
+ this.name = 'PolicyBlockError';
12
+ }
13
+ }
14
+ export function evaluatePolicy(config, rules, module, definition, context, policyOverride = false) {
15
+ if (config.policyMode === 'off') {
16
+ logStep('politika', `${module}/${context.operation} · POLICY=off — lint çalıştırılmadı`);
17
+ return [];
18
+ }
19
+ const applicable = rules.filter(rule => rule.module === module && rule.appliesTo.includes(context.operation));
20
+ const raw = applicable.flatMap(rule => rule.check(definition, context));
21
+ const findings = config.policyMode === 'warn' || policyOverride
22
+ ? raw.map(finding => finding.severity === 'block'
23
+ ? { ...finding, severity: 'warn', message: `${finding.message} [block → warn: ${policyOverride ? 'policyOverride' : 'POLICY=warn'}]` }
24
+ : finding)
25
+ : raw;
26
+ logStep('politika', `${module}/${context.operation}${context.workflowKind ? ` (${context.workflowKind})` : ''} · ${applicable.length} kural denendi · ${findings.length === 0 ? 'bulgu yok' : `${findings.length} bulgu`}${policyOverride ? ' · policyOverride açık' : ''}`, findings.map(finding => `[${finding.ruleId}] ${finding.severity}: ${finding.message}`));
27
+ return findings;
28
+ }
29
+ export function enforcePolicy(findings) {
30
+ const blocking = findings.filter(finding => finding.severity === 'block');
31
+ if (blocking.length > 0) {
32
+ logStep('politika ✕', `${blocking.length} block bulgusu isteği durdurdu — platforma HİÇBİR istek gitmedi`, blocking.map(finding => `[${finding.ruleId}] ${finding.message}`));
33
+ throw new PolicyBlockError(blocking);
34
+ }
35
+ return findings;
36
+ }
37
+ export function attachFindings(payload, findings) {
38
+ if (findings.length === 0)
39
+ return payload;
40
+ if (payload && typeof payload === 'object' && !Array.isArray(payload)) {
41
+ return { ...payload, policyFindings: findings };
42
+ }
43
+ return { data: payload, policyFindings: findings };
44
+ }
@@ -0,0 +1,75 @@
1
+ export const reservedTenantTables = [
2
+ 'applications',
3
+ 'audit_trail_values',
4
+ 'audit_trails',
5
+ 'branches',
6
+ 'caches',
7
+ 'component_definition_blocks',
8
+ 'component_definition_events',
9
+ 'component_definition_properties',
10
+ 'component_definition_property_options',
11
+ 'component_definition_validations',
12
+ 'components',
13
+ 'data_transfer_objects',
14
+ 'datasources',
15
+ 'design_component_blocks',
16
+ 'design_component_events',
17
+ 'design_component_properties',
18
+ 'design_component_state_binding_targets',
19
+ 'design_component_state_bindings',
20
+ 'design_component_validations',
21
+ 'design_components',
22
+ 'entities',
23
+ 'entity_applications',
24
+ 'entity_increment_sequences',
25
+ 'entity_index_fields',
26
+ 'entity_indexes',
27
+ 'entity_page_setting_fields',
28
+ 'entity_page_setting_items',
29
+ 'entity_page_settings',
30
+ 'entity_transfer_rows',
31
+ 'fields',
32
+ 'files',
33
+ 'flows',
34
+ 'folder_middlewares',
35
+ 'folder_roles',
36
+ 'folders',
37
+ 'layout_events',
38
+ 'layouts',
39
+ 'microservice_middlewares',
40
+ 'microservice_roles',
41
+ 'microservices',
42
+ 'ms_source_entities',
43
+ 'ms_source_entity_fields',
44
+ 'ms_source_entity_filters',
45
+ 'ms_source_entity_joins',
46
+ 'ms_source_entity_limits',
47
+ 'ms_source_entity_sorts',
48
+ 'ms_type_options',
49
+ 'page_events',
50
+ 'page_middlewares',
51
+ 'page_roles',
52
+ 'pages',
53
+ 'permissions',
54
+ 'projects',
55
+ 'queries',
56
+ 'queued_events',
57
+ 'role_permissions',
58
+ 'roles',
59
+ 'step_rule_condition_rules',
60
+ 'step_rules',
61
+ 'steps',
62
+ 'ui_flow_step_argument_iterates',
63
+ 'ui_flow_step_argument_parameters',
64
+ 'ui_flow_step_argument_rules',
65
+ 'ui_flow_step_arguments',
66
+ 'ui_flow_step_branches',
67
+ 'ui_flow_steps',
68
+ 'user_roles',
69
+ 'users',
70
+ 'variables',
71
+ 'view_fields',
72
+ 'view_tables',
73
+ 'views',
74
+ 'workflows',
75
+ ];