@appaflytech/zeyrek-ai-mcp 0.0.73 → 0.0.74
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.
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
const WRITING_TABLE_OPERATIONS = new Set(['create', 'upsert', 'update', 'delete', 'bulk-create', 'bulk-delete', 'bulk-update', 'bulk-upsert']);
|
|
2
|
+
const READING_TABLE_OPERATIONS = new Set(['get', 'count']);
|
|
3
|
+
const PASSIVE_STEP_TYPES = new Set(['start', 'response', 'code', 'condition', 'variable', 'convert', 'redirect']);
|
|
4
|
+
const SIDE_EFFECT_STEP_TYPES = { email: 'e-posta', 'file-upload': 'dosya yükleme', setcookie: 'çerez', 'set-user': 'oturum kullanıcısı' };
|
|
5
|
+
const SUB_WORKFLOW_DEPTH = 3;
|
|
6
|
+
const DISCRIMINATOR_FIELDS = ['a', 'action', 'op', 'kind', 'mode', 'islem'];
|
|
7
|
+
const OTHER_VALUE = '\u0000';
|
|
8
|
+
const stepsOf = (body) => (Array.isArray(body?.steps) ? body.steps : []);
|
|
9
|
+
// Yorum ve metin sabiti ayıklanır: `WHERE note <> 'INSERT INTO x'` yazma değildir.
|
|
10
|
+
const stripSql = (sql) => sql
|
|
11
|
+
.replace(/--[^\n]*/g, ' ')
|
|
12
|
+
.replace(/\/\*[\s\S]*?\*\//g, ' ')
|
|
13
|
+
.replace(/'(?:[^']|'')*'/g, "''");
|
|
14
|
+
export function sqlWrites(sql) {
|
|
15
|
+
if (typeof sql !== 'string' || sql.trim() === '')
|
|
16
|
+
return [];
|
|
17
|
+
const text = stripSql(sql);
|
|
18
|
+
const found = [];
|
|
19
|
+
for (const match of text.matchAll(/\b(INSERT\s+INTO\s+[\w."]+|DELETE\s+FROM\s+[\w."]+|UPDATE\s+[\w."]+(?:\s+(?:AS\s+)?\w+)?\s+SET|MERGE\s+INTO\s+[\w."]+|TRUNCATE\s+[\w."]+|ALTER\s+TABLE\s+[\w."]+|DROP\s+TABLE\s+[\w."]+|CREATE\s+TABLE\s+[\w."]+)/gi)) {
|
|
20
|
+
// `SELECT … FOR UPDATE` satır kilididir, yazma değil.
|
|
21
|
+
if (/FOR\s+$/i.test(text.slice(Math.max(0, match.index - 6), match.index)))
|
|
22
|
+
continue;
|
|
23
|
+
found.push(String(match[1]).replace(/\s+/g, ' ').replace(/^(UPDATE\s+[\w."]+)\s+(?:AS\s+)?\w+\s+SET$/i, '$1 SET'));
|
|
24
|
+
}
|
|
25
|
+
return found;
|
|
26
|
+
}
|
|
27
|
+
function stepEffect(step) {
|
|
28
|
+
// Döngü tek bir iç adımı koşturur; etkisi o adımın etkisidir.
|
|
29
|
+
const type = step.type === 'loop' ? String(step.rule?.stepType ?? '') : String(step.type ?? '');
|
|
30
|
+
const rule = (step.type === 'loop' ? step.rule?.stepRule : step.rule) ?? {};
|
|
31
|
+
const label = String(step.name ?? step.id ?? '?');
|
|
32
|
+
if (type === 'table') {
|
|
33
|
+
const operation = String(rule.operation ?? '');
|
|
34
|
+
if (WRITING_TABLE_OPERATIONS.has(operation))
|
|
35
|
+
return { writes: [`${label}: tablo ${operation}`], unknown: [] };
|
|
36
|
+
if (READING_TABLE_OPERATIONS.has(operation))
|
|
37
|
+
return { writes: [], unknown: [] };
|
|
38
|
+
return { writes: [], unknown: [`${label}: tablo işlemi '${operation}'`] };
|
|
39
|
+
}
|
|
40
|
+
if (type === 'query') {
|
|
41
|
+
if (typeof rule.rawQuery !== 'string' || rule.rawQuery.trim() === '')
|
|
42
|
+
return { writes: [], unknown: [`${label}: kayıtlı sorgu okunmadı`] };
|
|
43
|
+
return { writes: sqlWrites(rule.rawQuery).map(write => `${label}: ${write}`), unknown: [] };
|
|
44
|
+
}
|
|
45
|
+
if (type === 'workflow') {
|
|
46
|
+
return typeof rule.workflowId === 'string' && rule.workflowId !== ''
|
|
47
|
+
? { writes: [], unknown: [], subWorkflow: rule.workflowId }
|
|
48
|
+
: { writes: [], unknown: [`${label}: alt akış kimliği yok`] };
|
|
49
|
+
}
|
|
50
|
+
if (SIDE_EFFECT_STEP_TYPES[type])
|
|
51
|
+
return { writes: [`${label}: ${SIDE_EFFECT_STEP_TYPES[type]}`], unknown: [] };
|
|
52
|
+
if (PASSIVE_STEP_TYPES.has(type))
|
|
53
|
+
return { writes: [], unknown: [] };
|
|
54
|
+
return { writes: [], unknown: [`${label}: ${type || 'tipsiz'} adımı`] };
|
|
55
|
+
}
|
|
56
|
+
/** Kök akışın çağırdığı alt akış kimlikleri (döngünün iç adımı dahil); yükleyici bunlarla bir sonraki katmanı çeker. */
|
|
57
|
+
export function subWorkflowIds(body) {
|
|
58
|
+
return [...new Set(stepsOf(body).map(step => stepEffect(step).subWorkflow).filter((id) => typeof id === 'string'))];
|
|
59
|
+
}
|
|
60
|
+
function effectOf(step, subWorkflows, depth, seen) {
|
|
61
|
+
const own = stepEffect(step);
|
|
62
|
+
if (!own.subWorkflow)
|
|
63
|
+
return own;
|
|
64
|
+
if (seen.has(own.subWorkflow))
|
|
65
|
+
return { writes: [], unknown: [] };
|
|
66
|
+
if (depth >= SUB_WORKFLOW_DEPTH)
|
|
67
|
+
return { writes: [], unknown: [`${String(step.name ?? step.id)}: alt akış derinliği ${SUB_WORKFLOW_DEPTH}'ü aşıyor`] };
|
|
68
|
+
const body = subWorkflows.get(own.subWorkflow);
|
|
69
|
+
if (!body)
|
|
70
|
+
return { writes: [], unknown: [`${String(step.name ?? step.id)}: alt akış okunamadı (${own.subWorkflow})`] };
|
|
71
|
+
const inner = bodyEffect(body, subWorkflows, depth + 1, new Set(seen).add(own.subWorkflow));
|
|
72
|
+
return { writes: inner.writes.map(write => `${String(step.name ?? step.id)} › ${write}`), unknown: inner.unknown };
|
|
73
|
+
}
|
|
74
|
+
function bodyEffect(body, subWorkflows, depth, seen) {
|
|
75
|
+
const effect = { writes: [], unknown: [] };
|
|
76
|
+
for (const step of stepsOf(body)) {
|
|
77
|
+
const inner = effectOf(step, subWorkflows, depth, seen);
|
|
78
|
+
effect.writes.push(...inner.writes);
|
|
79
|
+
effect.unknown.push(...inner.unknown);
|
|
80
|
+
}
|
|
81
|
+
return effect;
|
|
82
|
+
}
|
|
83
|
+
export function workflowEffect(body, subWorkflows = new Map()) {
|
|
84
|
+
return bodyEffect(body, subWorkflows, 0, new Set());
|
|
85
|
+
}
|
|
86
|
+
const literalComparison = (field) => new RegExp(`[\\w.\\[\\]'"]+\\.${field}\\s*(===|==|!==|!=)\\s*["']([\\w-]+)["']`, 'g');
|
|
87
|
+
const includesComparison = (field) => new RegExp(`\\[([^\\]]*)\\]\\.includes\\(\\s*[\\w.]+\\.${field}\\s*\\)`, 'g');
|
|
88
|
+
// Koşul ifadesini ayırıcı değere göre değerlendirir; ifade yalnız bu karşılaştırmalardan (ve `ok === true`
|
|
89
|
+
// doğrulama bayrağından) oluşmuyorsa `undefined` döner ve çağıran iki dalı da izler.
|
|
90
|
+
function guardValue(expression, field, value) {
|
|
91
|
+
let text = String(expression ?? '');
|
|
92
|
+
let touched = false;
|
|
93
|
+
text = text.replace(literalComparison(field), (_, operator, literal) => {
|
|
94
|
+
touched = true;
|
|
95
|
+
return (literal === value) !== operator.startsWith('!') ? 'true' : 'false';
|
|
96
|
+
});
|
|
97
|
+
text = text.replace(includesComparison(field), (_, items) => {
|
|
98
|
+
touched = true;
|
|
99
|
+
return items.split(',').map(item => item.trim().replace(/^['"]|['"]$/g, '')).includes(value) ? 'true' : 'false';
|
|
100
|
+
});
|
|
101
|
+
if (!touched)
|
|
102
|
+
return undefined;
|
|
103
|
+
const reduced = text.replace(/[\w.]+\.ok\s*===\s*true/g, 'true').replace(/\s+/g, '');
|
|
104
|
+
if (!/^[()!&|]*(?:(?:true|false)[()!&|]*)+$/.test(reduced))
|
|
105
|
+
return undefined;
|
|
106
|
+
return evaluateBoolean(reduced);
|
|
107
|
+
}
|
|
108
|
+
// Yalnız true / false, !, &&, || ve parantezden oluşan ifadeyi değerlendirir (eval yok).
|
|
109
|
+
function evaluateBoolean(expression) {
|
|
110
|
+
let position = 0;
|
|
111
|
+
const peek = (token) => expression.startsWith(token, position);
|
|
112
|
+
const orExpression = () => {
|
|
113
|
+
let left = andExpression();
|
|
114
|
+
while (peek('||')) {
|
|
115
|
+
position += 2;
|
|
116
|
+
const right = andExpression();
|
|
117
|
+
left = left === undefined || right === undefined ? undefined : left || right;
|
|
118
|
+
}
|
|
119
|
+
return left;
|
|
120
|
+
};
|
|
121
|
+
const andExpression = () => {
|
|
122
|
+
let left = unary();
|
|
123
|
+
while (peek('&&')) {
|
|
124
|
+
position += 2;
|
|
125
|
+
const right = unary();
|
|
126
|
+
left = left === undefined || right === undefined ? undefined : left && right;
|
|
127
|
+
}
|
|
128
|
+
return left;
|
|
129
|
+
};
|
|
130
|
+
const unary = () => {
|
|
131
|
+
if (peek('!')) {
|
|
132
|
+
position += 1;
|
|
133
|
+
const inner = unary();
|
|
134
|
+
return inner === undefined ? undefined : !inner;
|
|
135
|
+
}
|
|
136
|
+
if (peek('(')) {
|
|
137
|
+
position += 1;
|
|
138
|
+
const inner = orExpression();
|
|
139
|
+
if (!peek(')'))
|
|
140
|
+
return undefined;
|
|
141
|
+
position += 1;
|
|
142
|
+
return inner;
|
|
143
|
+
}
|
|
144
|
+
if (peek('true')) {
|
|
145
|
+
position += 4;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (peek('false')) {
|
|
149
|
+
position += 5;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
};
|
|
154
|
+
const result = orExpression();
|
|
155
|
+
return position === expression.length ? result : undefined;
|
|
156
|
+
}
|
|
157
|
+
function discriminatorField(steps) {
|
|
158
|
+
const counts = new Map();
|
|
159
|
+
const literals = new Map();
|
|
160
|
+
for (const step of steps.filter(candidate => candidate.type === 'condition')) {
|
|
161
|
+
for (const item of step.rule?.items ?? []) {
|
|
162
|
+
const expression = String(item.expression ?? '');
|
|
163
|
+
for (const field of DISCRIMINATOR_FIELDS) {
|
|
164
|
+
for (const match of expression.matchAll(literalComparison(field))) {
|
|
165
|
+
counts.set(field, (counts.get(field) ?? 0) + 1);
|
|
166
|
+
literals.set(field, (literals.get(field) ?? new Set()).add(String(match[2])));
|
|
167
|
+
}
|
|
168
|
+
for (const match of expression.matchAll(includesComparison(field))) {
|
|
169
|
+
counts.set(field, (counts.get(field) ?? 0) + 1);
|
|
170
|
+
for (const literal of String(match[1]).split(','))
|
|
171
|
+
literals.set(field, (literals.get(field) ?? new Set()).add(literal.trim().replace(/^['"]|['"]$/g, '')));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const field = [...counts].sort((left, right) => right[1] - left[1])[0]?.[0];
|
|
177
|
+
return field ? { field, literals: literals.get(field) ?? new Set() } : undefined;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Ayırıcı alanın her değeri için akış yürütülür: değerlendirilebilen koşulda tek dal, değerlendirilemeyende bütün dallar
|
|
181
|
+
* izlenir (`global-error` / `error` dalı izlenmez). Yolunda yazma yoksa ve 2xx yanıta varıyorsa değer okuyandır.
|
|
182
|
+
*/
|
|
183
|
+
export function actionEffects(body, subWorkflows = new Map()) {
|
|
184
|
+
const steps = stepsOf(body);
|
|
185
|
+
const discriminator = discriminatorField(steps);
|
|
186
|
+
if (!discriminator)
|
|
187
|
+
return undefined;
|
|
188
|
+
const byId = new Map(steps.map(step => [String(step.id), step]));
|
|
189
|
+
const first = (steps.find(step => step.type === 'start')?.branches ?? []).find(branch => branch.type !== 'global-error')?.nextStepId;
|
|
190
|
+
const reading = [];
|
|
191
|
+
const writing = [];
|
|
192
|
+
// Listede olmayan bir değer de denenir: `else` dalı çoğu akışta "geri kalan eylemler"dir (yazan ya da 422 dönen).
|
|
193
|
+
for (const value of [...discriminator.literals, OTHER_VALUE]) {
|
|
194
|
+
let writes = false;
|
|
195
|
+
let reachesSuccess = false;
|
|
196
|
+
let budget = 20000;
|
|
197
|
+
const visit = (stepId, seen) => {
|
|
198
|
+
if (budget-- <= 0 || !stepId || seen.has(stepId))
|
|
199
|
+
return;
|
|
200
|
+
const step = byId.get(stepId);
|
|
201
|
+
if (!step)
|
|
202
|
+
return;
|
|
203
|
+
const effect = effectOf(step, subWorkflows, 0, new Set());
|
|
204
|
+
if (effect.writes.length > 0)
|
|
205
|
+
writes = true;
|
|
206
|
+
if (step.type === 'response') {
|
|
207
|
+
const status = Number(step.rule?.httpStatusCode ?? 200);
|
|
208
|
+
if (status >= 200 && status < 300)
|
|
209
|
+
reachesSuccess = true;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const next = new Set(seen).add(stepId);
|
|
213
|
+
const branches = (step.branches ?? []).filter(branch => branch.type !== 'global-error' && branch.type !== 'error');
|
|
214
|
+
if (step.type !== 'condition') {
|
|
215
|
+
for (const branch of branches)
|
|
216
|
+
visit(branch.nextStepId, next);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const items = step.rule?.items ?? [];
|
|
220
|
+
let decided = false;
|
|
221
|
+
for (const item of items) {
|
|
222
|
+
const truth = guardValue(item.expression, discriminator.field, value);
|
|
223
|
+
if (truth === false)
|
|
224
|
+
continue;
|
|
225
|
+
visit(branches.find(branch => branch.id === item.branchId)?.nextStepId, next);
|
|
226
|
+
if (truth === true) {
|
|
227
|
+
decided = true;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (!decided) {
|
|
232
|
+
const fallback = branches.find(branch => !items.some(item => item.branchId === branch.id));
|
|
233
|
+
visit(fallback?.nextStepId, next);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
visit(first, new Set());
|
|
237
|
+
const label = value === OTHER_VALUE ? 'listede olmayan değer' : value;
|
|
238
|
+
// Listede olmayan değer yalnız yazıyorsa söylenir: okuma yolu çoğunlukla tekrar korumasının önbellek dönüşüdür.
|
|
239
|
+
if (writes)
|
|
240
|
+
writing.push(label);
|
|
241
|
+
else if (reachesSuccess && value !== OTHER_VALUE)
|
|
242
|
+
reading.push(label);
|
|
243
|
+
}
|
|
244
|
+
return { field: discriminator.field, reading, writing };
|
|
245
|
+
}
|
|
246
|
+
const RULE = 'MS-031';
|
|
247
|
+
const GUIDE = 'ngapps://guides/microservice';
|
|
248
|
+
const LEGACY_NOTE = ' Uyumsuzluk bu yazımdan önce de vardı; yazım engellenmedi.';
|
|
249
|
+
const list = (items, limit = 3) => items.slice(0, limit).join('; ') + (items.length > limit ? ` (+${items.length - limit})` : '');
|
|
250
|
+
const getWrites = (method, effect) => method === 'GET' && effect.writes.length > 0;
|
|
251
|
+
const nonGetReadOnly = (method, effect) => method !== 'GET' && effect.writes.length === 0 && effect.unknown.length === 0;
|
|
252
|
+
export function methodEffectFindings(input) {
|
|
253
|
+
if (input.type === 'schedule-job')
|
|
254
|
+
return [];
|
|
255
|
+
const method = input.method.toUpperCase();
|
|
256
|
+
const previousMethod = input.previous?.method.toUpperCase();
|
|
257
|
+
const grade = (heldBefore) => heldBefore
|
|
258
|
+
? { severity: 'warn', suffix: LEGACY_NOTE }
|
|
259
|
+
: { severity: 'block', suffix: '' };
|
|
260
|
+
const findings = [];
|
|
261
|
+
if (getWrites(method, input.effect)) {
|
|
262
|
+
const { severity, suffix } = grade(input.previous !== undefined && getWrites(previousMethod ?? '', input.previous.effect));
|
|
263
|
+
findings.push({
|
|
264
|
+
ruleId: RULE,
|
|
265
|
+
severity,
|
|
266
|
+
message: `'${input.slug}' GET ama bağlı iş akışı yazıyor (${list(input.effect.writes)}). GET tekrarlanabilir, önbelleğe alınabilir sayılır ve parametreleri adres satırında / sunucu günlüğünde görünür; yazan uç POST olmalı (güncelleme PUT, silme DELETE). Akış hem okuyup hem yazıyorsa okumayı ayrı bir GET uca ayırın.${suffix}`,
|
|
267
|
+
guide: GUIDE
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (nonGetReadOnly(method, input.effect)) {
|
|
271
|
+
const { severity, suffix } = grade(input.previous !== undefined && nonGetReadOnly(previousMethod ?? '', input.previous.effect));
|
|
272
|
+
findings.push({
|
|
273
|
+
ruleId: RULE,
|
|
274
|
+
severity,
|
|
275
|
+
message: `'${input.slug}' ${method} ama bağlı iş akışı hiçbir yolda yazmıyor. Okuyan uç GET olmalı: parametreler query-string'e taşınır (gövde değil), mobil veri önbelleği yalnız GET okumayı saklar (FLOW-044). Gövdede parola ya da tek kullanımlık bilet gibi adrese düşmemesi gereken bir değer taşıyorsa bu bilinçli bir istisnadır: policyOverride: true.${suffix}`,
|
|
276
|
+
guide: GUIDE
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (method !== 'GET' && input.actions && input.actions.reading.length > 0 && input.actions.writing.length > 0) {
|
|
280
|
+
findings.push({
|
|
281
|
+
ruleId: RULE,
|
|
282
|
+
severity: 'warn',
|
|
283
|
+
message: `'${input.slug}' tek uçta '${input.actions.field}' ayırıcısıyla hem okuyor hem yazıyor (okuyan: ${input.actions.reading.join(', ')}; yazan: ${input.actions.writing.join(', ')}). Okuyan değerleri ayrı bir GET uca ayırın, yazanlar bu uçta kalsın — liste ile form aynı POST'u paylaşmasın.`,
|
|
284
|
+
guide: GUIDE
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return findings;
|
|
288
|
+
}
|
|
@@ -35,6 +35,10 @@ servis formunda görünür ve `microservice_get` outline görünümünde geri ok
|
|
|
35
35
|
|
|
36
36
|
## Karar kuralları
|
|
37
37
|
|
|
38
|
+
**Yöntem iş akışının etkisini izler (MS-031, block):** hiçbir yolda yazmayan uç GET (parametreler query-string'de),
|
|
39
|
+
yazan uç POST / PUT / DELETE. Bir sayfanın listesi ile formu tek POST'u `action` / `op` alanıyla paylaşmaz — okuyan
|
|
40
|
+
eylemler ayrı bir GET uca ayrılır. Gövdede parola / tek kullanımlık bilet taşıyan okuyucu bilinçli istisnadır (`policyOverride`).
|
|
41
|
+
|
|
38
42
|
1. **Kaynak seçimi sırası: `table` → `view` → `workflow` → `query`.**
|
|
39
43
|
- `table`: tek entity üzerinde CRUD/listeleme — varsayılan tercih. Filtre, join, sıralama,
|
|
40
44
|
alan seçimi hepsi `sourceParameters` ile platform-native.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { applyPolicyMode } from '../knowledge/policy.js';
|
|
2
|
+
import { actionEffects, methodEffectFindings, subWorkflowIds, workflowEffect } from '../knowledge/methodEffect.js';
|
|
3
|
+
import { unwrap } from './screens.js';
|
|
4
|
+
const read = async (context, path) => context.platform.tenant('GET', context.project, path, { environment: context.environment })
|
|
5
|
+
.then(payload => unwrap(payload))
|
|
6
|
+
.catch(() => undefined);
|
|
7
|
+
async function subWorkflowsOf(context, root) {
|
|
8
|
+
const loaded = new Map();
|
|
9
|
+
let frontier = subWorkflowIds(root);
|
|
10
|
+
for (let depth = 0; depth < 3 && frontier.length > 0; depth++) {
|
|
11
|
+
const next = [];
|
|
12
|
+
for (const id of frontier.filter(candidate => !loaded.has(candidate))) {
|
|
13
|
+
const body = await read(context, `/workflows/${context.applicationId}/${id}`);
|
|
14
|
+
loaded.set(id, body);
|
|
15
|
+
next.push(...subWorkflowIds(body));
|
|
16
|
+
}
|
|
17
|
+
frontier = next;
|
|
18
|
+
}
|
|
19
|
+
return loaded;
|
|
20
|
+
}
|
|
21
|
+
const TABLE_WRITES = new Set(['create', 'upsert', 'update', 'delete', 'bulk-create', 'bulk-delete', 'bulk-update', 'bulk-upsert']);
|
|
22
|
+
/** Ucun kendi tanımından okunabilen etki: tablo kaynaklıda işlem, iş akışı kaynaklıda akış + alt akışlar. Bilinmiyorsa `undefined`. */
|
|
23
|
+
async function endpointEffect(context, definition) {
|
|
24
|
+
const source = String(definition.source ?? '');
|
|
25
|
+
if (source === 'table') {
|
|
26
|
+
const operation = String(definition.sourceParameters?.operation ?? '');
|
|
27
|
+
if (TABLE_WRITES.has(operation))
|
|
28
|
+
return { effect: { writes: [`tablo ${operation}`], unknown: [] } };
|
|
29
|
+
return operation === 'get' || operation === 'count' ? { effect: { writes: [], unknown: [] } } : undefined;
|
|
30
|
+
}
|
|
31
|
+
if (source !== 'workflow' || typeof definition.workflowId !== 'string' || definition.workflowId === '')
|
|
32
|
+
return undefined;
|
|
33
|
+
const body = await read(context, `/workflows/${context.applicationId}/${definition.workflowId}`);
|
|
34
|
+
if (!body)
|
|
35
|
+
return undefined;
|
|
36
|
+
const subs = await subWorkflowsOf(context, body);
|
|
37
|
+
return { effect: workflowEffect(body, subs), body, subs };
|
|
38
|
+
}
|
|
39
|
+
const methodOf = (definition) => String(definition?.httpMethod ?? 'get').toUpperCase();
|
|
40
|
+
/**
|
|
41
|
+
* Uç yazımı (`microservice_create` / `update` / `patch`). `before` yazımdan önceki kayıttır; yoksa yeni uçtur. Uç başka bir
|
|
42
|
+
* akışa ya da kaynağa bağlanıyorsa önceki etki bilinmez ve yazım yeni bir uç gibi değerlendirilir.
|
|
43
|
+
*/
|
|
44
|
+
export async function microserviceMethodFindings(context, definition, before) {
|
|
45
|
+
if (context.platform.config.policyMode === 'off')
|
|
46
|
+
return [];
|
|
47
|
+
const current = await endpointEffect(context, definition);
|
|
48
|
+
if (!current)
|
|
49
|
+
return [];
|
|
50
|
+
const sameBinding = before !== undefined
|
|
51
|
+
&& String(before.source ?? '') === String(definition.source ?? '')
|
|
52
|
+
&& String(before.workflowId ?? '') === String(definition.workflowId ?? '');
|
|
53
|
+
const findings = methodEffectFindings({
|
|
54
|
+
slug: String(definition.slug ?? definition.name ?? '?'),
|
|
55
|
+
method: methodOf(definition),
|
|
56
|
+
type: typeof definition.type === 'string' ? definition.type : undefined,
|
|
57
|
+
effect: current.effect,
|
|
58
|
+
actions: current.body ? actionEffects(current.body, current.subs) : undefined,
|
|
59
|
+
previous: sameBinding ? { method: methodOf(before), effect: current.effect } : undefined
|
|
60
|
+
});
|
|
61
|
+
return applyPolicyMode(context.platform.config, findings, context.policyOverride);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* İş akışı yazımı: akışa bağlı her uç, akışın yazımdan önceki ve sonraki etkisiyle karşılaştırılır. Yazımdan önce
|
|
65
|
+
* olmayan uyumsuzluk durdurur (GET uca bağlı okuyan akışa yazma eklemek gibi), önceden olan uyarı olarak kalır.
|
|
66
|
+
* Yalnız doğrudan bağlı uçlar değerlendirilir; bu akışı alt akış olarak çağıran akışların uçları değil.
|
|
67
|
+
*/
|
|
68
|
+
export async function boundMethodFindings(context, workflowId, before, after) {
|
|
69
|
+
if (context.platform.config.policyMode === 'off')
|
|
70
|
+
return [];
|
|
71
|
+
const dependencies = await read(context, `/workflows/${context.applicationId}/${workflowId}/dependencies`);
|
|
72
|
+
const bound = (Array.isArray(dependencies?.depended) ? dependencies.depended : [])
|
|
73
|
+
.filter(node => node?.module === 'microservice' && typeof node.id === 'string');
|
|
74
|
+
if (bound.length === 0)
|
|
75
|
+
return [];
|
|
76
|
+
const afterSubs = await subWorkflowsOf(context, after);
|
|
77
|
+
const afterEffect = workflowEffect(after, afterSubs);
|
|
78
|
+
const previousEffect = before ? workflowEffect(before, await subWorkflowsOf(context, before)) : undefined;
|
|
79
|
+
const actions = actionEffects(after, afterSubs);
|
|
80
|
+
const findings = [];
|
|
81
|
+
for (const node of bound) {
|
|
82
|
+
const endpoint = await read(context, `/microservices/${context.applicationId}/${String(node.id)}`);
|
|
83
|
+
if (!endpoint || String(endpoint.source ?? '') !== 'workflow' || String(endpoint.workflowId ?? '') !== workflowId)
|
|
84
|
+
continue;
|
|
85
|
+
findings.push(...methodEffectFindings({
|
|
86
|
+
slug: String(endpoint.slug ?? node.slug ?? node.id),
|
|
87
|
+
method: methodOf(endpoint),
|
|
88
|
+
type: typeof endpoint.type === 'string' ? endpoint.type : undefined,
|
|
89
|
+
effect: afterEffect,
|
|
90
|
+
actions,
|
|
91
|
+
// Önceki gövde okunamadıysa uyumsuzluğun bu yazımla gelip gelmediği bilinmez: uyarıda kalır, durdurmaz.
|
|
92
|
+
previous: { method: methodOf(endpoint), effect: previousEffect ?? afterEffect }
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
return applyPolicyMode(context.platform.config, findings, context.policyOverride);
|
|
96
|
+
}
|
|
@@ -21,6 +21,7 @@ import { headersForMode } from '../platform/http.js';
|
|
|
21
21
|
import { fetchHost, flowPath, unwrap } from './screens.js';
|
|
22
22
|
import { captchaNotConfiguredMessage, captchaTokenProblem } from '../knowledge/coverage.js';
|
|
23
23
|
import { projectCaptchaProvider } from './projects.js';
|
|
24
|
+
import { microserviceMethodFindings } from './methodEffect.js';
|
|
24
25
|
import fastJsonPatch from 'fast-json-patch';
|
|
25
26
|
import { jsonArray } from '../platform/jsonArray.js';
|
|
26
27
|
import { z } from 'zod';
|
|
@@ -443,7 +444,11 @@ export function registerMicroserviceTools(server, platform) {
|
|
|
443
444
|
? createFindings
|
|
444
445
|
: enforcePolicy(evaluatePolicy(config, policyRules, 'microservice', definition, { operation: 'update' }, policyOverride))),
|
|
445
446
|
...scopeFindings,
|
|
446
|
-
...await legacyRoleListFindings(platform, project, environment, definition, 'microservice', policyOverride)
|
|
447
|
+
...await legacyRoleListFindings(platform, project, environment, definition, 'microservice', policyOverride),
|
|
448
|
+
// MS-031: liste satırı akış kimliğini taşımaz; var olan uçta önceki hâl ayrıntıdan okunur.
|
|
449
|
+
...enforcePolicy(await microserviceMethodFindings({ platform, project, environment, applicationId: resolvedApplicationId, policyOverride }, definition, existing === undefined
|
|
450
|
+
? undefined
|
|
451
|
+
: await platform.tenant('GET', project, `/microservices/${resolvedApplicationId}/${String(existing.id)}`, { environment }).then(unwrap).catch(() => existing)))
|
|
447
452
|
];
|
|
448
453
|
const drift = unmappedMembers(existing === undefined ? 'CreateMicroserviceCommand' : 'UpdateMicroserviceCommand', definition);
|
|
449
454
|
const payload = existing === undefined
|
|
@@ -470,7 +475,8 @@ export function registerMicroserviceTools(server, platform) {
|
|
|
470
475
|
const findings = [
|
|
471
476
|
...enforcePolicy(evaluatePolicy(config, policyRules, 'microservice', definition, { operation: 'update' }, policyOverride)),
|
|
472
477
|
...await queryScopeFindings(platform, project, environment, definition),
|
|
473
|
-
...await legacyRoleListFindings(platform, project, environment, definition, 'microservice', policyOverride)
|
|
478
|
+
...await legacyRoleListFindings(platform, project, environment, definition, 'microservice', policyOverride),
|
|
479
|
+
...enforcePolicy(await microserviceMethodFindings({ platform, project, environment, applicationId: resolvedApplicationId, policyOverride }, definition, await platform.tenant('GET', project, `/microservices/${resolvedApplicationId}/${id}`, { environment }).then(unwrap).catch(() => definition)))
|
|
474
480
|
];
|
|
475
481
|
const drift = unmappedMembers('UpdateMicroserviceCommand', definition);
|
|
476
482
|
// MS-029 / CAPTCHA-003: kayıtlı tanım yalnız bayrağı açan gövdede okunur — bayrak bu yazımla mı açılıyor?
|
|
@@ -506,7 +512,8 @@ export function registerMicroserviceTools(server, platform) {
|
|
|
506
512
|
const normalized = normalizeMicroserviceDefinition(patched);
|
|
507
513
|
const findings = [
|
|
508
514
|
...enforcePolicy(evaluatePolicy(config, policyRules, 'microservice', patched, { operation: 'update' }, policyOverride)),
|
|
509
|
-
...await queryScopeFindings(platform, project, environment, patched)
|
|
515
|
+
...await queryScopeFindings(platform, project, environment, patched),
|
|
516
|
+
...enforcePolicy(await microserviceMethodFindings({ platform, project, environment, applicationId: resolvedApplicationId, policyOverride }, patched, definition))
|
|
510
517
|
];
|
|
511
518
|
const drift = introducedUnmappedMembers('UpdateMicroserviceCommand', (current?.data ?? current), patched);
|
|
512
519
|
// Gövde değil FARK gönderilir: gateway normalizasyonları da op'a çevrilsin diye net diff
|
package/dist/tools/workflows.js
CHANGED
|
@@ -15,6 +15,8 @@ import fastJsonPatch from 'fast-json-patch';
|
|
|
15
15
|
import { jsonArray } from '../platform/jsonArray.js';
|
|
16
16
|
import { z } from 'zod';
|
|
17
17
|
import { constraintSummary } from '../knowledge/backendConstraints.js';
|
|
18
|
+
import { boundMethodFindings } from './methodEffect.js';
|
|
19
|
+
import { unwrap } from './screens.js';
|
|
18
20
|
import { unmappedMembers, introducedUnmappedMembers, withUnmappedMembers } from '../knowledge/schemaGuard.js';
|
|
19
21
|
const workflowIfExistsParam = ifExistsParam('workflow', 'mevcut workflow\'u bu tanımla tam gövde günceller (id\'si korunur; workflow_update ile aynı yazma)');
|
|
20
22
|
const policyOverrideParam = z.boolean().optional()
|
|
@@ -187,7 +189,11 @@ export function registerWorkflowTools(server, platform) {
|
|
|
187
189
|
});
|
|
188
190
|
// Kayıt bulunduysa yazma bir UPDATE'tir: gövde kuralları workflow_update ile aynı kipte yeniden
|
|
189
191
|
// değerlendirilir (R-1). Adım denetimleri operasyondan bağımsızdır, tekrar koşmaz.
|
|
190
|
-
const findings = existing === undefined ? createFindings : enforcePolicy([
|
|
192
|
+
const findings = existing === undefined ? createFindings : enforcePolicy([
|
|
193
|
+
...bodyFindings('update'),
|
|
194
|
+
...stepFindings,
|
|
195
|
+
...await boundMethodFindings({ platform, project, environment, applicationId, policyOverride }, String(existing.id), await platform.tenant('GET', project, `/workflows/${applicationId}/${String(existing.id)}`, { environment }).then(unwrap).catch(() => undefined), definition)
|
|
196
|
+
]);
|
|
191
197
|
const drift = unmappedMembers(existing === undefined ? 'CreateWorkflowCommand' : 'UpdateWorkflowCommand', definition);
|
|
192
198
|
const payload = existing === undefined
|
|
193
199
|
? await platform.tenant('POST', project, `/workflows/${applicationId}`, { environment, body: definition })
|
|
@@ -210,7 +216,8 @@ export function registerWorkflowTools(server, platform) {
|
|
|
210
216
|
...await undefinedInputFieldFindings(platform, project, environment, definition, definition.type, policyOverride),
|
|
211
217
|
...await responseDtoFieldFindings(platform, project, environment, definition, definition.type, policyOverride),
|
|
212
218
|
...await identityMiddlewareFindings(platform, project, environment, definition, definition.type, policyOverride),
|
|
213
|
-
...await simpleProjectPushUserFindings(platform, project, environment, definition, policyOverride)
|
|
219
|
+
...await simpleProjectPushUserFindings(platform, project, environment, definition, policyOverride),
|
|
220
|
+
...await boundMethodFindings({ platform, project, environment, applicationId, policyOverride }, id, await platform.tenant('GET', project, `/workflows/${applicationId}/${id}`, { environment }).then(unwrap).catch(() => undefined), definition)
|
|
214
221
|
]);
|
|
215
222
|
const drift = unmappedMembers('UpdateWorkflowCommand', definition);
|
|
216
223
|
const payload = await platform.tenant('PUT', project, `/workflows/${applicationId}/${id}`, { environment, body: definition });
|
|
@@ -235,7 +242,8 @@ export function registerWorkflowTools(server, platform) {
|
|
|
235
242
|
...await undefinedInputFieldFindings(platform, project, environment, patched, patched.type, policyOverride),
|
|
236
243
|
...await responseDtoFieldFindings(platform, project, environment, patched, patched.type, policyOverride),
|
|
237
244
|
...await identityMiddlewareFindings(platform, project, environment, patched, patched.type, policyOverride),
|
|
238
|
-
...await simpleProjectPushUserFindings(platform, project, environment, patched, policyOverride)
|
|
245
|
+
...await simpleProjectPushUserFindings(platform, project, environment, patched, policyOverride),
|
|
246
|
+
...await boundMethodFindings({ platform, project, environment, applicationId, policyOverride }, id, definition, patched)
|
|
239
247
|
]);
|
|
240
248
|
const drift = introducedUnmappedMembers('UpdateWorkflowCommand', (current?.data ?? current), patched);
|
|
241
249
|
// Gövde değil FARK gönderilir: gateway normalizasyonları da op'a çevrilsin diye net diff
|
package/package.json
CHANGED