@betterportal/framework 10.6.35 → 10.7.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 (41) hide show
  1. package/lib/adapters/h3.d.ts +2 -0
  2. package/lib/adapters/h3.d.ts.map +1 -1
  3. package/lib/adapters/h3.js +237 -134
  4. package/lib/adapters/h3.js.map +1 -1
  5. package/lib/cli/bp.js +14 -0
  6. package/lib/cli/bp.js.map +1 -1
  7. package/lib/codegen/cli.js +7 -0
  8. package/lib/codegen/cli.js.map +1 -1
  9. package/lib/codegen/init.js +5 -0
  10. package/lib/codegen/init.js.map +1 -1
  11. package/lib/codegen/routeUrlPolicy.d.ts +15 -0
  12. package/lib/codegen/routeUrlPolicy.d.ts.map +1 -0
  13. package/lib/codegen/routeUrlPolicy.js +1185 -0
  14. package/lib/codegen/routeUrlPolicy.js.map +1 -0
  15. package/lib/contracts/registry.d.ts +9 -12
  16. package/lib/contracts/registry.d.ts.map +1 -1
  17. package/lib/contracts/route.d.ts +6 -27
  18. package/lib/contracts/route.d.ts.map +1 -1
  19. package/lib/contracts/route.js.map +1 -1
  20. package/lib/contracts/routeUrl.d.ts +66 -0
  21. package/lib/contracts/routeUrl.d.ts.map +1 -0
  22. package/lib/contracts/routeUrl.js +2 -0
  23. package/lib/contracts/routeUrl.js.map +1 -0
  24. package/lib/contracts/streaming.d.ts +6 -4
  25. package/lib/contracts/streaming.d.ts.map +1 -1
  26. package/lib/contracts/streaming.js.map +1 -1
  27. package/lib/index.d.ts +1 -0
  28. package/lib/index.d.ts.map +1 -1
  29. package/lib/index.js +1 -0
  30. package/lib/index.js.map +1 -1
  31. package/lib/runtime/auth/redirect.d.ts +13 -2
  32. package/lib/runtime/auth/redirect.d.ts.map +1 -1
  33. package/lib/runtime/auth/redirect.js +1 -1
  34. package/lib/runtime/auth/redirect.js.map +1 -1
  35. package/lib/runtime/configProvider.d.ts +8 -0
  36. package/lib/runtime/configProvider.d.ts.map +1 -1
  37. package/lib/runtime/configProvider.js +16 -0
  38. package/lib/runtime/configProvider.js.map +1 -1
  39. package/lib/runtime/llms.js +6 -6
  40. package/lib/runtime/llms.js.map +1 -1
  41. package/package.json +1 -1
@@ -0,0 +1,1185 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import ts from "typescript";
4
+ const legacyFields = new Set(["accountUrl", "loginUrl", "logoutUrl", "socialUrl", "firstAdminUrl", "nextUrl", "mailNextUrl", "sessionNextUrl", "previewPath", "tenantsPath"]);
5
+ const internalPaths = new Set(["apiPath", "viewPath", "uiPath", "absoluteApiPath", "absoluteViewPath"]);
6
+ /** Reject the old routing API and renderer-only URL payloads even in loosely typed source. */
7
+ export function inspectRouteUrlSource(file, source) {
8
+ const tree = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, true, file.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
9
+ const errors = [];
10
+ const rendererFunctions = new Set();
11
+ const declarations = new Map();
12
+ const selections = new Map();
13
+ const initializers = new Map();
14
+ const lengthTypes = new Map();
15
+ const stringTypes = new Map();
16
+ const pendingMutations = [];
17
+ const functions = new Map();
18
+ const propertyKey = (name) => {
19
+ if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name))
20
+ return name.text;
21
+ if (ts.isComputedPropertyName(name) && (ts.isStringLiteralLike(name.expression) || ts.isNumericLiteral(name.expression)))
22
+ return name.expression.text;
23
+ return undefined;
24
+ };
25
+ const collect = (node) => {
26
+ if (file.includes("_renderer.") && ts.isFunctionLike(node)) {
27
+ const declaration = ts.isVariableDeclaration(node.parent) ? node.parent : undefined;
28
+ const name = ts.isFunctionDeclaration(node) ? node.name?.text : declaration && ts.isIdentifier(declaration.name) ? declaration.name.text : undefined;
29
+ const owner = declaration?.parent.parent;
30
+ const exported = ts.isFunctionDeclaration(node) ? ts.getModifiers(node)?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)
31
+ : owner && ts.isVariableStatement(owner) && ts.getModifiers(owner)?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword);
32
+ if (name?.startsWith("render") && exported)
33
+ rendererFunctions.add(node);
34
+ }
35
+ if ((ts.isVariableDeclaration(node) || ts.isParameter(node)) && ts.isIdentifier(node.name)
36
+ && node.type && [ts.SyntaxKind.StringKeyword, ts.SyntaxKind.ArrayType, ts.SyntaxKind.TupleType].includes(node.type.kind)) {
37
+ let scope = node.parent;
38
+ while (!ts.isBlock(scope) && !ts.isSourceFile(scope) && !(ts.isParameter(node) && ts.isFunctionLike(scope)))
39
+ scope = scope.parent;
40
+ const bindings = lengthTypes.get(scope) ?? new Set();
41
+ bindings.add(node.name.text);
42
+ lengthTypes.set(scope, bindings);
43
+ if (node.type.kind === ts.SyntaxKind.StringKeyword) {
44
+ const strings = stringTypes.get(scope) ?? new Set();
45
+ strings.add(node.name.text);
46
+ stringTypes.set(scope, strings);
47
+ }
48
+ }
49
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
50
+ let scope = node.parent;
51
+ while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
52
+ scope = scope.parent;
53
+ const bindings = initializers.get(scope) ?? new Map();
54
+ bindings.set(node.name.text, node.initializer);
55
+ initializers.set(scope, bindings);
56
+ }
57
+ if ((ts.isVariableDeclaration(node) && node.initializer || ts.isParameter(node)) && ts.isObjectBindingPattern(node.name)) {
58
+ let scope = node.parent;
59
+ while (!ts.isBlock(scope) && !ts.isSourceFile(scope) && !(ts.isParameter(node) && ts.isFunctionLike(scope)))
60
+ scope = scope.parent;
61
+ const bindings = selections.get(scope) ?? new Map();
62
+ for (const item of node.name.elements) {
63
+ if (!ts.isIdentifier(item.name))
64
+ continue;
65
+ const key = item.propertyName ?? item.name;
66
+ if (!ts.isIdentifier(key) && !ts.isStringLiteralLike(key))
67
+ continue;
68
+ bindings.set(item.name.text, { expression: node.initializer ?? node.name, field: key.text, rest: !!item.dotDotDotToken });
69
+ }
70
+ selections.set(scope, bindings);
71
+ }
72
+ if (ts.isVariableDeclaration(node) && ts.isArrayBindingPattern(node.name) && node.initializer) {
73
+ let scope = node.parent;
74
+ while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
75
+ scope = scope.parent;
76
+ const bindings = selections.get(scope) ?? new Map();
77
+ for (const [index, item] of node.name.elements.entries()) {
78
+ if (!ts.isBindingElement(item) || !ts.isIdentifier(item.name))
79
+ continue;
80
+ bindings.set(item.name.text, { expression: node.initializer, field: String(index), rest: !!item.dotDotDotToken, element: index });
81
+ }
82
+ selections.set(scope, bindings);
83
+ }
84
+ const declare = (name) => {
85
+ let scope = node.parent;
86
+ while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
87
+ scope = scope.parent;
88
+ const names = declarations.get(scope) ?? new Set();
89
+ names.add(name);
90
+ declarations.set(scope, names);
91
+ };
92
+ if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name)
93
+ declare(node.name.text);
94
+ if (ts.isFunctionDeclaration(node) && node.name) {
95
+ let scope = node.parent;
96
+ while (!ts.isBlock(scope) && !ts.isSourceFile(scope))
97
+ scope = scope.parent;
98
+ const bindings = functions.get(scope) ?? new Map();
99
+ bindings.set(node.name.text, node);
100
+ functions.set(scope, bindings);
101
+ }
102
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name))
103
+ declare(node.name.text);
104
+ if (ts.isImportDeclaration(node) && !node.importClause?.isTypeOnly) {
105
+ if (node.importClause?.name)
106
+ declare(node.importClause.name.text);
107
+ const bindings = node.importClause?.namedBindings;
108
+ if (bindings && ts.isNamespaceImport(bindings))
109
+ declare(bindings.name.text);
110
+ if (bindings && ts.isNamedImports(bindings))
111
+ for (const binding of bindings.elements)
112
+ if (!binding.isTypeOnly)
113
+ declare(binding.name.text);
114
+ }
115
+ if (ts.isBinaryExpression(node) && [ts.SyntaxKind.EqualsToken, ts.SyntaxKind.PlusEqualsToken,
116
+ ts.SyntaxKind.BarBarEqualsToken, ts.SyntaxKind.AmpersandAmpersandEqualsToken,
117
+ ts.SyntaxKind.QuestionQuestionEqualsToken].includes(node.operatorToken.kind)) {
118
+ const assigned = (target, value) => {
119
+ if (ts.isParenthesizedExpression(target)) {
120
+ assigned(target.expression, value);
121
+ return;
122
+ }
123
+ if (ts.isArrayLiteralExpression(target)) {
124
+ for (const [index, item] of target.elements.entries()) {
125
+ if (ts.isOmittedExpression(item))
126
+ continue;
127
+ if (ts.isSpreadElement(item)) {
128
+ const values = ts.isArrayLiteralExpression(value) ? value.elements.slice(index) : [value];
129
+ pendingMutations.push({ target: item.expression, values });
130
+ }
131
+ else
132
+ assigned(item, ts.isArrayLiteralExpression(value) && !value.elements.some(ts.isSpreadElement)
133
+ ? value.elements[index] ?? ts.factory.createIdentifier("undefined") : value);
134
+ }
135
+ return;
136
+ }
137
+ if (ts.isObjectLiteralExpression(target)) {
138
+ for (const item of target.properties) {
139
+ if (ts.isSpreadAssignment(item)) {
140
+ pendingMutations.push({ target: item.expression, values: [value] });
141
+ continue;
142
+ }
143
+ if (!ts.isPropertyAssignment(item) && !ts.isShorthandPropertyAssignment(item))
144
+ continue;
145
+ const name = propertyKey(item.name);
146
+ if (name === undefined)
147
+ continue;
148
+ const source = ts.isObjectLiteralExpression(value) ? value.properties.find(property => property.name && propertyKey(property.name) === name) : undefined;
149
+ const selected = source && ts.isPropertyAssignment(source) ? source.initializer : source && ts.isShorthandPropertyAssignment(source) ? source.name : ts.factory.createPropertyAccessExpression(value, name);
150
+ assigned(ts.isPropertyAssignment(item) ? item.initializer : item.name, selected);
151
+ }
152
+ return;
153
+ }
154
+ pendingMutations.push({ target, values: [value] });
155
+ };
156
+ assigned(node.left, node.right);
157
+ }
158
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
159
+ const method = node.expression.name.text;
160
+ if (["push", "unshift", "splice", "fill"].includes(method))
161
+ pendingMutations.push({
162
+ target: node.expression.expression,
163
+ values: method === "splice" ? node.arguments.slice(2) : method === "fill" ? node.arguments.slice(0, 1) : node.arguments
164
+ });
165
+ if (["set", "append", "add"].includes(method))
166
+ pendingMutations.push({
167
+ target: node.expression.expression, values: node.arguments, collection: true
168
+ });
169
+ if (["defineProperty", "defineProperties"].includes(method) && node.arguments[0])
170
+ pendingMutations.push({
171
+ target: node.arguments[0], values: node.arguments.slice(method === "defineProperty" ? 2 : 1), global: node.expression.expression
172
+ });
173
+ if (method === "assign" && node.arguments[0])
174
+ pendingMutations.push({
175
+ target: node.arguments[0], values: node.arguments.slice(1), global: node.expression.expression
176
+ });
177
+ }
178
+ ts.forEachChild(node, collect);
179
+ };
180
+ collect(tree);
181
+ const references = new Map();
182
+ const reference = (expression, seen = new Set()) => {
183
+ if (seen.has(expression))
184
+ return undefined;
185
+ if (references.has(expression))
186
+ return references.get(expression);
187
+ const next = new Set([...seen, expression]);
188
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)
189
+ || ts.isNonNullExpression(expression) || ts.isSatisfiesExpression(expression)
190
+ || ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression))
191
+ return reference(expression.expression, next);
192
+ if (!ts.isIdentifier(expression))
193
+ return undefined;
194
+ let scope = expression.parent;
195
+ while (scope) {
196
+ if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text)) {
197
+ const initializer = initializers.get(scope)?.get(expression.text);
198
+ const selected = selections.get(scope)?.get(expression.text);
199
+ const alias = initializer ? reference(initializer, next) : selected ? reference(selected.expression, next) : undefined;
200
+ const binding = alias ?? { scope, name: expression.text };
201
+ references.set(expression, binding);
202
+ return binding;
203
+ }
204
+ if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
205
+ return undefined;
206
+ scope = scope.parent;
207
+ }
208
+ return undefined;
209
+ };
210
+ const mutations = new Map();
211
+ for (const mutation of pendingMutations) {
212
+ const binding = reference(mutation.target);
213
+ if (!binding)
214
+ continue;
215
+ const bindings = mutations.get(binding.scope) ?? new Map();
216
+ bindings.set(binding.name, [...bindings.get(binding.name) ?? [], mutation]);
217
+ mutations.set(binding.scope, bindings);
218
+ }
219
+ const rendererPayload = (expression, seen = new Set()) => {
220
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)
221
+ || ts.isNonNullExpression(expression) || ts.isSatisfiesExpression(expression))
222
+ return rendererPayload(expression.expression, seen);
223
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
224
+ return false;
225
+ let scope = expression.parent;
226
+ while (scope) {
227
+ const initializer = initializers.get(scope)?.get(expression.text);
228
+ if (initializer)
229
+ return rendererPayload(initializer, new Set([...seen, expression.text]));
230
+ if (ts.isFunctionLike(scope) && scope.parameters.some(param => ts.isIdentifier(param.name) && param.name.text === expression.text)) {
231
+ const input = scope.parameters[0]?.name;
232
+ return rendererFunctions.has(scope) && input !== undefined && ts.isIdentifier(input) && input.text === expression.text;
233
+ }
234
+ scope = scope.parent;
235
+ }
236
+ return false;
237
+ };
238
+ const collection = (expression, seen = new Set()) => {
239
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
240
+ return collection(expression.expression, seen);
241
+ if (ts.isNewExpression(expression))
242
+ return ["Map", "Set", "Headers", "URLSearchParams", "FormData"].some(name => isGlobal(expression.expression, name));
243
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
244
+ return false;
245
+ let scope = expression.parent;
246
+ while (scope) {
247
+ const initializer = initializers.get(scope)?.get(expression.text);
248
+ if (initializer)
249
+ return collection(initializer, new Set([...seen, expression.text]));
250
+ if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
251
+ return false;
252
+ scope = scope.parent;
253
+ }
254
+ return false;
255
+ };
256
+ const report = (node, message) => {
257
+ const position = tree.getLineAndCharacterOfPosition(node.getStart(tree));
258
+ errors.push({ file: `${file}:${position.line + 1}:${position.character + 1}`, message, severity: "error" });
259
+ };
260
+ const resolveCallback = (expression, seen = new Set()) => {
261
+ if (!expression)
262
+ return undefined;
263
+ if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression) || ts.isFunctionDeclaration(expression) || ts.isMethodDeclaration(expression))
264
+ return expression;
265
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
266
+ return resolveCallback(expression.expression, seen);
267
+ if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && expression.expression.name.text === "bind")
268
+ return resolveCallback(expression.expression.expression, seen);
269
+ if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression)) {
270
+ const field = ts.isPropertyAccessExpression(expression) ? expression.name.text : expression.argumentExpression.text;
271
+ return resolveCallback(selectedProperty(expression.expression, field), seen);
272
+ }
273
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
274
+ return undefined;
275
+ let scope = expression.parent;
276
+ while (scope) {
277
+ const initializer = initializers.get(scope)?.get(expression.text);
278
+ if (initializer)
279
+ return resolveCallback(initializer, new Set([...seen, expression.text]));
280
+ const declaration = functions.get(scope)?.get(expression.text);
281
+ if (declaration)
282
+ return declaration;
283
+ if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
284
+ return undefined;
285
+ if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
286
+ return undefined;
287
+ scope = scope.parent;
288
+ }
289
+ return undefined;
290
+ };
291
+ const arrayValues = (expression, seen = new Set()) => {
292
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
293
+ return arrayValues(expression.expression, seen);
294
+ if (ts.isArrayLiteralExpression(expression)) {
295
+ const values = [];
296
+ for (const element of expression.elements) {
297
+ if (ts.isSpreadElement(element)) {
298
+ const spread = arrayValues(element.expression, seen);
299
+ if (!spread)
300
+ return undefined;
301
+ values.push(...spread);
302
+ }
303
+ else
304
+ values.push(element);
305
+ }
306
+ return values;
307
+ }
308
+ if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Array") && expression.expression.name.text === "of")
309
+ return expression.arguments;
310
+ if (ts.isNewExpression(expression) && isGlobal(expression.expression, "Array"))
311
+ return expression.arguments;
312
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
313
+ return undefined;
314
+ let scope = expression.parent;
315
+ while (scope) {
316
+ const initializer = initializers.get(scope)?.get(expression.text);
317
+ if (initializer)
318
+ return arrayValues(initializer, new Set([...seen, expression.text]));
319
+ if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
320
+ return undefined;
321
+ if (ts.isFunctionLike(scope)) {
322
+ const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
323
+ if (parameter) {
324
+ const input = parameterInputs.get(parameter);
325
+ return input ? arrayValues(input, new Set([...seen, expression.text])) : undefined;
326
+ }
327
+ }
328
+ scope = scope.parent;
329
+ }
330
+ return undefined;
331
+ };
332
+ const argumentValues = (inputs) => inputs.flatMap(input => input && ts.isSpreadElement(input) ? arrayValues(input.expression) ?? [input.expression] : [input]);
333
+ const boundInputs = (expression, inputs, seen = new Set()) => {
334
+ if (seen.has(expression))
335
+ return inputs;
336
+ const next = new Set([...seen, expression]);
337
+ if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && expression.expression.name.text === "bind")
338
+ return boundInputs(expression.expression.expression, [...argumentValues(expression.arguments).slice(1), ...inputs], next);
339
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
340
+ return boundInputs(expression.expression, inputs, next);
341
+ if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression)) {
342
+ const field = ts.isPropertyAccessExpression(expression) ? expression.name.text : expression.argumentExpression.text;
343
+ const selected = selectedProperty(expression.expression, field);
344
+ if (selected)
345
+ return boundInputs(selected, inputs, next);
346
+ }
347
+ if (ts.isIdentifier(expression)) {
348
+ let scope = expression.parent;
349
+ while (scope) {
350
+ const initializer = initializers.get(scope)?.get(expression.text);
351
+ if (initializer)
352
+ return boundInputs(initializer, inputs, next);
353
+ if (declarations.get(scope)?.has(expression.text))
354
+ break;
355
+ scope = scope.parent;
356
+ }
357
+ }
358
+ return inputs;
359
+ };
360
+ const rejectedValue = (expression, seen = new Set()) => {
361
+ if (seen.has(expression))
362
+ return undefined;
363
+ const next = new Set([...seen, expression]);
364
+ if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression)
365
+ && isGlobal(expression.expression.expression, "Promise") && expression.expression.name.text === "reject")
366
+ return expression.arguments[0];
367
+ if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression)) {
368
+ const operation = expression.expression.name.text;
369
+ const handler = expression.arguments[operation === "then" ? 1 : 0];
370
+ if (operation === "finally" || ["then", "catch"].includes(operation)
371
+ && (!handler || handler.kind === ts.SyntaxKind.NullKeyword || isGlobal(handler, "undefined")))
372
+ return rejectedValue(expression.expression.expression, next);
373
+ if (["then", "catch"].includes(operation) && handler)
374
+ return callbackRejection(handler, rejectedValue(expression.expression.expression, next), next);
375
+ }
376
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
377
+ return rejectedValue(expression.expression, next);
378
+ if (ts.isIdentifier(expression)) {
379
+ let scope = expression.parent;
380
+ while (scope) {
381
+ const initializer = initializers.get(scope)?.get(expression.text);
382
+ if (initializer)
383
+ return rejectedValue(initializer, next);
384
+ if (declarations.get(scope)?.has(expression.text))
385
+ break;
386
+ if (ts.isFunctionLike(scope)) {
387
+ const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
388
+ if (parameter) {
389
+ const input = parameterInputs.get(parameter);
390
+ return input ? rejectedValue(input, next) : undefined;
391
+ }
392
+ }
393
+ scope = scope.parent;
394
+ }
395
+ }
396
+ return undefined;
397
+ };
398
+ const selectedElements = (selected) => {
399
+ const values = arrayValues(selected.expression);
400
+ return values && selected.element !== undefined ? selected.rest ? values.slice(selected.element) : values.slice(selected.element, selected.element + 1) : [selected.expression];
401
+ };
402
+ const isStringValue = (expression, seen = new Set()) => {
403
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
404
+ return isStringValue(expression.expression, seen);
405
+ if (ts.isStringLiteralLike(expression) || ts.isTemplateExpression(expression))
406
+ return true;
407
+ if (ts.isPropertyAccessExpression(expression))
408
+ return (internalPaths.has(expression.name.text) || expression.name.text === "absoluteUiPath") && internalValue(expression.expression);
409
+ if (ts.isCallExpression(expression) && isGlobal(expression.expression, "String") || ts.isNewExpression(expression) && isGlobal(expression.expression, "String"))
410
+ return true;
411
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
412
+ return false;
413
+ let scope = expression.parent;
414
+ while (scope) {
415
+ if (stringTypes.get(scope)?.has(expression.text))
416
+ return true;
417
+ const selected = selections.get(scope)?.get(expression.text);
418
+ if (selected?.element !== undefined)
419
+ return !selected.rest && selectedElements(selected).length === 1 && isStringValue(selectedElements(selected)[0], new Set([...seen, expression.text]));
420
+ const initializer = initializers.get(scope)?.get(expression.text);
421
+ if (initializer)
422
+ return isStringValue(initializer, new Set([...seen, expression.text]));
423
+ if (declarations.get(scope)?.has(expression.text) || selected)
424
+ return false;
425
+ if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
426
+ return false;
427
+ scope = scope.parent;
428
+ }
429
+ return false;
430
+ };
431
+ const hasScalarLength = (expression, seen = new Set()) => {
432
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
433
+ return hasScalarLength(expression.expression, seen);
434
+ if (ts.isArrayLiteralExpression(expression) || ts.isStringLiteralLike(expression) || ts.isTemplateExpression(expression))
435
+ return true;
436
+ if (ts.isPropertyAccessExpression(expression))
437
+ return internalPaths.has(expression.name.text) && internalValue(expression.expression);
438
+ if (ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression))
439
+ return internalPaths.has(expression.argumentExpression.text) && internalValue(expression.expression);
440
+ if (ts.isNewExpression(expression))
441
+ return isGlobal(expression.expression, "Array") || isGlobal(expression.expression, "String");
442
+ if (ts.isCallExpression(expression) && isGlobal(expression.expression, "String"))
443
+ return true;
444
+ if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && ["trim", "trimStart", "trimEnd", "replace", "replaceAll", "toLowerCase", "toUpperCase", "normalize", "substring", "substr", "padStart", "padEnd", "repeat", "split", "slice", "filter", "map", "flatMap"].includes(expression.expression.name.text))
445
+ return hasScalarLength(expression.expression.expression, seen);
446
+ if (ts.isCallExpression(expression) && ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Promise") && expression.expression.name.text === "resolve")
447
+ return !!expression.arguments[0] && hasScalarLength(expression.arguments[0], seen);
448
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
449
+ return false;
450
+ let scope = expression.parent;
451
+ while (scope) {
452
+ if (lengthTypes.get(scope)?.has(expression.text))
453
+ return true;
454
+ const initializer = initializers.get(scope)?.get(expression.text);
455
+ if (initializer)
456
+ return hasScalarLength(initializer, new Set([...seen, expression.text]));
457
+ if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
458
+ return false;
459
+ if (ts.isFunctionLike(scope)) {
460
+ const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
461
+ if (parameter) {
462
+ const input = parameterInputs.get(parameter);
463
+ if (!input)
464
+ return false;
465
+ return elementParameters.has(parameter) ? ts.isArrayLiteralExpression(input) && input.elements.every(item => hasScalarLength(item, seen)) : hasScalarLength(input, seen);
466
+ }
467
+ }
468
+ scope = scope.parent;
469
+ }
470
+ return false;
471
+ };
472
+ const parameterInputs = new Map();
473
+ const elementParameters = new Set();
474
+ const promiseResolvers = new Set();
475
+ const isPromiseResolver = (expression, seen = new Set()) => {
476
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
477
+ return isPromiseResolver(expression.expression, seen);
478
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
479
+ return false;
480
+ let scope = expression.parent;
481
+ while (scope) {
482
+ const initializer = initializers.get(scope)?.get(expression.text);
483
+ if (initializer)
484
+ return isPromiseResolver(initializer, new Set([...seen, expression.text]));
485
+ if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
486
+ return false;
487
+ if (ts.isFunctionLike(scope)) {
488
+ const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
489
+ if (parameter)
490
+ return promiseResolvers.has(parameter) || parameterInputs.has(parameter) && isPromiseResolver(parameterInputs.get(parameter));
491
+ }
492
+ scope = scope.parent;
493
+ }
494
+ return false;
495
+ };
496
+ const evaluatingFunctions = new Set();
497
+ const parameterValue = (parameter, index, inputs) => parameter.dotDotDotToken ? ts.factory.createArrayLiteralExpression(inputs.slice(index).map(input => input ?? ts.factory.createIdentifier("undefined"))) : inputs[index];
498
+ const callbackInternal = (callback, seen, inputs = [], elements = [], fulfillOnly = false) => {
499
+ if (!callback?.body || evaluatingFunctions.has(callback))
500
+ return false;
501
+ evaluatingFunctions.add(callback);
502
+ const previous = callback.parameters.map(parameter => ({ parameter, input: parameterInputs.get(parameter), element: elementParameters.has(parameter) }));
503
+ for (const [index, parameter] of callback.parameters.entries()) {
504
+ const input = parameterValue(parameter, index, inputs);
505
+ if (input)
506
+ parameterInputs.set(parameter, input);
507
+ else
508
+ parameterInputs.delete(parameter);
509
+ if (elements.includes(index))
510
+ elementParameters.add(parameter);
511
+ else
512
+ elementParameters.delete(parameter);
513
+ }
514
+ try {
515
+ if (!fulfillOnly && !ts.isBlock(callback.body))
516
+ return internalValue(callback.body, seen);
517
+ let internal = false;
518
+ const returned = (node) => {
519
+ if (node !== callback.body && ts.isFunctionLike(node))
520
+ return;
521
+ if (!fulfillOnly && (ts.isReturnStatement(node) || ts.isYieldExpression(node)) && node.expression && internalValue(node.expression, seen))
522
+ internal = true;
523
+ if (fulfillOnly && ts.isCallExpression(node)) {
524
+ if (isPromiseResolver(node.expression)) {
525
+ if (node.arguments[0] && internalValue(node.arguments[0], seen))
526
+ internal = true;
527
+ }
528
+ else {
529
+ if (callbackValue(node.expression, seen, node.arguments, [], true))
530
+ internal = true;
531
+ for (const argument of node.arguments)
532
+ if (callbackValue(argument, seen, [], [], true))
533
+ internal = true;
534
+ }
535
+ }
536
+ ts.forEachChild(node, returned);
537
+ };
538
+ returned(callback.body);
539
+ return internal;
540
+ }
541
+ finally {
542
+ for (const { parameter, input, element } of previous) {
543
+ if (input)
544
+ parameterInputs.set(parameter, input);
545
+ else
546
+ parameterInputs.delete(parameter);
547
+ if (element)
548
+ elementParameters.add(parameter);
549
+ else
550
+ elementParameters.delete(parameter);
551
+ }
552
+ evaluatingFunctions.delete(callback);
553
+ }
554
+ };
555
+ const callbackValue = (expression, seen, inputs = [], elements = [], fulfillOnly = false) => {
556
+ if (!expression)
557
+ return false;
558
+ const expanded = argumentValues(inputs);
559
+ const combined = boundInputs(expression, expanded);
560
+ const offset = combined.length - expanded.length;
561
+ return callbackInternal(resolveCallback(expression), seen, combined, elements.map(index => index + offset), fulfillOnly);
562
+ };
563
+ const rejectionOrigin = (expression, seen = new Set()) => {
564
+ if (seen.has(expression) || !ts.isIdentifier(expression))
565
+ return expression;
566
+ const next = new Set([...seen, expression]);
567
+ let scope = expression.parent;
568
+ while (scope) {
569
+ const initializer = initializers.get(scope)?.get(expression.text);
570
+ if (initializer)
571
+ return rejectionOrigin(initializer, next);
572
+ if (declarations.get(scope)?.has(expression.text))
573
+ break;
574
+ if (ts.isFunctionLike(scope)) {
575
+ const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
576
+ if (parameter) {
577
+ const input = parameterInputs.get(parameter);
578
+ return input ? rejectionOrigin(input, next) : expression;
579
+ }
580
+ }
581
+ scope = scope.parent;
582
+ }
583
+ return expression;
584
+ };
585
+ const callbackRejection = (expression, input, seen) => {
586
+ const callback = resolveCallback(expression);
587
+ if (!callback?.body || evaluatingFunctions.has(callback))
588
+ return undefined;
589
+ evaluatingFunctions.add(callback);
590
+ const inputs = boundInputs(expression, input ? [input] : []);
591
+ const previous = callback.parameters.map(parameter => ({ parameter, input: parameterInputs.get(parameter) }));
592
+ for (const [index, parameter] of callback.parameters.entries()) {
593
+ const value = parameterValue(parameter, index, inputs);
594
+ if (value)
595
+ parameterInputs.set(parameter, value);
596
+ else
597
+ parameterInputs.delete(parameter);
598
+ }
599
+ try {
600
+ const reasons = [];
601
+ const returned = (node) => {
602
+ if (node !== callback.body && ts.isFunctionLike(node))
603
+ return;
604
+ const value = ts.isThrowStatement(node) ? node.expression : ts.isReturnStatement(node) ? node.expression : node === callback.body && !ts.isBlock(node) ? node : undefined;
605
+ const reason = value && (ts.isThrowStatement(node) ? value : rejectedValue(value, seen));
606
+ if (reason)
607
+ reasons.push(rejectionOrigin(reason));
608
+ ts.forEachChild(node, returned);
609
+ };
610
+ returned(callback.body);
611
+ return reasons.length === 1 ? reasons[0] : reasons.length ? ts.factory.createArrayLiteralExpression(reasons) : undefined;
612
+ }
613
+ finally {
614
+ for (const { parameter, input: previousInput } of previous) {
615
+ if (previousInput)
616
+ parameterInputs.set(parameter, previousInput);
617
+ else
618
+ parameterInputs.delete(parameter);
619
+ }
620
+ evaluatingFunctions.delete(callback);
621
+ }
622
+ };
623
+ const selectedProperty = (expression, field, seen = new Set()) => {
624
+ if (seen.has(expression))
625
+ return undefined;
626
+ const next = new Set([...seen, expression]);
627
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression)
628
+ || ts.isSatisfiesExpression(expression) || ts.isTypeAssertionExpression(expression))
629
+ return selectedProperty(expression.expression, field, next);
630
+ if (ts.isObjectLiteralExpression(expression)) {
631
+ const property = expression.properties.find(item => item.name && propertyKey(item.name) === field);
632
+ return property && ts.isPropertyAssignment(property) ? property.initializer : property && ts.isShorthandPropertyAssignment(property) ? property.name : property && ts.isMethodDeclaration(property) ? property : undefined;
633
+ }
634
+ if (ts.isIdentifier(expression)) {
635
+ let scope = expression.parent;
636
+ while (scope) {
637
+ const initializer = initializers.get(scope)?.get(expression.text);
638
+ if (initializer)
639
+ return selectedProperty(initializer, field, next);
640
+ if (declarations.get(scope)?.has(expression.text) || selections.get(scope)?.has(expression.text))
641
+ break;
642
+ scope = scope.parent;
643
+ }
644
+ }
645
+ return undefined;
646
+ };
647
+ const internalValue = (expression, seen = new Set()) => {
648
+ if (ts.isArrayLiteralExpression(expression))
649
+ return expression.elements.some(value => internalValue(value, seen));
650
+ if (ts.isElementAccessExpression(expression) && ts.isNumericLiteral(expression.argumentExpression)) {
651
+ const values = arrayValues(expression.expression);
652
+ const binding = reference(expression.expression);
653
+ if (values && (!binding || !mutations.get(binding.scope)?.get(binding.name)?.length)) {
654
+ const value = values[Number(expression.argumentExpression.text)];
655
+ return !!value && internalValue(value, seen);
656
+ }
657
+ }
658
+ if (ts.isElementAccessExpression(expression) && isStringValue(expression.expression)) {
659
+ const index = expression.argumentExpression;
660
+ if (ts.isNumericLiteral(index) || ts.isStringLiteralLike(index) && /^\d+$/.test(index.text)
661
+ || ts.isPrefixUnaryExpression(index) && ts.isNumericLiteral(index.operand))
662
+ return false;
663
+ }
664
+ if (ts.isObjectBindingPattern(expression) && ts.isParameter(expression.parent)) {
665
+ const input = parameterInputs.get(expression.parent);
666
+ return !!input && internalValue(input, seen);
667
+ }
668
+ if (ts.isPrefixUnaryExpression(expression) || ts.isPostfixUnaryExpression(expression)
669
+ || ts.isTypeOfExpression(expression) || ts.isVoidExpression(expression) || ts.isDeleteExpression(expression))
670
+ return false;
671
+ if (ts.isBinaryExpression(expression) && [ts.SyntaxKind.EqualsEqualsToken, ts.SyntaxKind.EqualsEqualsEqualsToken,
672
+ ts.SyntaxKind.ExclamationEqualsToken, ts.SyntaxKind.ExclamationEqualsEqualsToken, ts.SyntaxKind.LessThanToken,
673
+ ts.SyntaxKind.LessThanEqualsToken, ts.SyntaxKind.GreaterThanToken, ts.SyntaxKind.GreaterThanEqualsToken,
674
+ ts.SyntaxKind.InKeyword, ts.SyntaxKind.InstanceOfKeyword, ts.SyntaxKind.MinusToken, ts.SyntaxKind.AsteriskToken,
675
+ ts.SyntaxKind.SlashToken, ts.SyntaxKind.PercentToken, ts.SyntaxKind.AsteriskAsteriskToken, ts.SyntaxKind.AmpersandToken,
676
+ ts.SyntaxKind.BarToken, ts.SyntaxKind.CaretToken, ts.SyntaxKind.LessThanLessThanToken,
677
+ ts.SyntaxKind.GreaterThanGreaterThanToken, ts.SyntaxKind.GreaterThanGreaterThanGreaterThanToken].includes(expression.operatorToken.kind))
678
+ return false;
679
+ if (ts.isConditionalExpression(expression))
680
+ return internalValue(expression.whenTrue, seen) || internalValue(expression.whenFalse, seen);
681
+ if (ts.isIdentifier(expression) && !seen.has(expression.text)) {
682
+ const binding = reference(expression);
683
+ if (binding && mutations.get(binding.scope)?.get(binding.name)?.some(mutation => (!mutation.global || isGlobal(mutation.global, "Object")) && (!mutation.collection || collection(mutation.target))
684
+ && mutation.values.some(value => internalValue(value, new Set([...seen, expression.text])))))
685
+ return true;
686
+ let scope = expression.parent;
687
+ while (scope) {
688
+ const selected = selections.get(scope)?.get(expression.text);
689
+ if (selected)
690
+ return selected.element !== undefined ? selectedElements(selected).some(value => internalValue(value, new Set([...seen, expression.text]))) : (selected.rest || internalPaths.has(selected.field)) && internalValue(selected.expression, new Set([...seen, expression.text]));
691
+ const initializer = initializers.get(scope)?.get(expression.text);
692
+ if (initializer)
693
+ return internalValue(initializer, new Set([...seen, expression.text]));
694
+ if (ts.isFunctionLike(scope) && scope.parameters.some(param => ts.isIdentifier(param.name) && param.name.text === expression.text)) {
695
+ const parameter = scope.parameters.find(param => ts.isIdentifier(param.name) && param.name.text === expression.text);
696
+ const input = parameterInputs.get(parameter);
697
+ if (input)
698
+ return internalValue(input, seen);
699
+ const call = scope.parent;
700
+ const first = scope.parameters[0]?.name;
701
+ if (first && ts.isIdentifier(first) && first.text === expression.text && ts.isCallExpression(call)
702
+ && call.arguments[1] === scope && ts.isPropertyAccessExpression(call.expression)
703
+ && isGlobal(call.expression.expression, "Array") && call.expression.name.text === "from") {
704
+ return !!call.arguments[0] && internalValue(call.arguments[0], new Set([...seen, expression.text]));
705
+ }
706
+ break;
707
+ }
708
+ scope = scope.parent;
709
+ }
710
+ }
711
+ if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression)) {
712
+ const field = ts.isPropertyAccessExpression(expression) ? expression.name.text : expression.argumentExpression.text;
713
+ const selected = selectedProperty(expression.expression, field);
714
+ if (selected)
715
+ return internalValue(selected, seen);
716
+ }
717
+ if ((ts.isPropertyAccessExpression(expression) && expression.name.text === "length"
718
+ || ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression) && expression.argumentExpression.text === "length") && hasScalarLength(expression.expression))
719
+ return false;
720
+ if (ts.isPropertyAccessExpression(expression) && expression.name.text === "size" && collection(expression.expression))
721
+ return false;
722
+ if (ts.isPropertyAccessExpression(expression) && expression.name.text === "absoluteUiPath"
723
+ || ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression) && expression.argumentExpression.text === "absoluteUiPath")
724
+ return false;
725
+ if (ts.isPropertyAccessExpression(expression) && internalPaths.has(expression.name.text))
726
+ return internalValue(expression.expression, seen);
727
+ if (ts.isCallExpression(expression) && (authRedirectFunction(expression.expression)
728
+ || isResolverFunction(expression.expression)))
729
+ return true;
730
+ if (ts.isPropertyAccessExpression(expression))
731
+ return internalValue(expression.expression, seen);
732
+ if (ts.isPropertyAssignment(expression))
733
+ return internalValue(expression.initializer, seen);
734
+ // An arbitrary function may consume a URL while returning unrelated domain data.
735
+ if (ts.isCallExpression(expression)) {
736
+ const localCallback = resolveCallback(expression.expression);
737
+ if (localCallback)
738
+ return callbackValue(expression.expression, seen, expression.arguments);
739
+ if (ts.isPropertyAccessExpression(expression.expression) && ["call", "apply"].includes(expression.expression.name.text)) {
740
+ const receiver = expression.expression.expression;
741
+ const callback = resolveCallback(receiver);
742
+ if (callback) {
743
+ const arguments_ = argumentValues(expression.arguments);
744
+ const inputs = expression.expression.name.text === "call" ? arguments_.slice(1)
745
+ : arguments_[1] ? arrayValues(arguments_[1]) ?? [arguments_[1]] : [];
746
+ return callbackValue(receiver, seen, inputs);
747
+ }
748
+ }
749
+ if (isPromiseResolver(expression.expression))
750
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
751
+ if (["encodeURI", "encodeURIComponent", "decodeURI", "decodeURIComponent", "escape", "unescape", "btoa", "atob"].some(name => isGlobal(expression.expression, name)))
752
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
753
+ if (isGlobal(expression.expression, "String") || isGlobal(expression.expression, "Object"))
754
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
755
+ if (isGlobal(expression.expression, "structuredClone"))
756
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
757
+ if (ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Array")) {
758
+ if (expression.expression.name.text === "of")
759
+ return expression.arguments.some(argument => internalValue(argument, seen));
760
+ if (expression.expression.name.text === "from") {
761
+ if (!expression.arguments[1])
762
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
763
+ return callbackValue(expression.arguments[1], seen, [expression.arguments[0]], [0]);
764
+ }
765
+ }
766
+ if (ts.isPropertyAccessExpression(expression.expression) && isGlobal(expression.expression.expression, "Object")) {
767
+ if (expression.expression.name.text === "create")
768
+ return !!expression.arguments[1] && internalValue(expression.arguments[1], seen);
769
+ if (expression.expression.name.text === "defineProperty")
770
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen)
771
+ || !!expression.arguments[2] && internalValue(expression.arguments[2], seen);
772
+ if (expression.expression.name.text === "defineProperties")
773
+ return expression.arguments.some(argument => internalValue(argument, seen));
774
+ if (expression.expression.name.text === "assign")
775
+ return expression.arguments.some(argument => internalValue(argument, seen));
776
+ if (["values", "entries", "freeze", "seal", "preventExtensions"].includes(expression.expression.name.text))
777
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
778
+ if (expression.expression.name.text === "fromEntries")
779
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
780
+ }
781
+ if (ts.isPropertyAccessExpression(expression.expression)) {
782
+ const operation = expression.expression.name.text;
783
+ if ((operation === "charAt" || operation === "at") && isStringValue(expression.expression.expression))
784
+ return false;
785
+ if (["replace", "replaceAll"].includes(operation) && hasScalarLength(expression.expression.expression)) {
786
+ const replacement = expression.arguments[1];
787
+ const callback = resolveCallback(replacement);
788
+ return internalValue(expression.expression.expression, seen) || (callback
789
+ ? callbackValue(replacement, seen, [expression.expression.expression]) : !!replacement && internalValue(replacement, seen));
790
+ }
791
+ if (["toString", "valueOf", "join", "trim", "trimStart", "trimEnd", "trimLeft", "trimRight", "replace", "replaceAll", "toLowerCase", "toUpperCase", "toLocaleLowerCase", "toLocaleUpperCase", "normalize", "substring", "substr", "charAt", "at", "padStart", "padEnd", "repeat", "split"].includes(operation))
792
+ return internalValue(expression.expression.expression, seen);
793
+ if (operation === "fill")
794
+ return internalValue(expression.expression.expression, seen) || !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
795
+ if (operation === "splice") {
796
+ const values = arrayValues(expression.expression.expression);
797
+ const number = (value) => value && ts.isNumericLiteral(value) ? Number(value.text)
798
+ : value && ts.isPrefixUnaryExpression(value) && value.operator === ts.SyntaxKind.MinusToken && ts.isNumericLiteral(value.operand) ? -Number(value.operand.text) : undefined;
799
+ const start = number(expression.arguments[0]);
800
+ const count = number(expression.arguments[1]);
801
+ const binding = reference(expression.expression.expression);
802
+ const earlierMutation = binding && mutations.get(binding.scope)?.get(binding.name)?.some(mutation => mutation.target.getStart(tree) < expression.getStart(tree)
803
+ && mutation.values.some(value => internalValue(value, seen)));
804
+ if (earlierMutation)
805
+ return internalValue(expression.expression.expression, seen);
806
+ if (values && (start !== undefined || !expression.arguments.length) && (count !== undefined || expression.arguments.length < 2)) {
807
+ const index = Math.max(0, Math.min(values.length, start === undefined ? 0 : start < 0 ? values.length + start : start));
808
+ const removed = !expression.arguments.length ? [] : values.slice(index, expression.arguments.length === 1 ? values.length : index + Math.max(0, count));
809
+ return removed.some(value => internalValue(value, seen));
810
+ }
811
+ return internalValue(expression.expression.expression, seen);
812
+ }
813
+ if (["filter", "slice", "sort", "reverse", "copyWithin", "toSorted", "toReversed", "flat", "find", "findLast", "pop", "shift"].includes(operation))
814
+ return internalValue(expression.expression.expression, seen);
815
+ if (operation === "concat")
816
+ return internalValue(expression.expression.expression, seen) || expression.arguments.some(argument => internalValue(argument, seen));
817
+ if (["with", "toSpliced"].includes(operation))
818
+ return internalValue(expression.expression.expression, seen)
819
+ || expression.arguments.slice(operation === "with" ? 1 : 2).some(argument => internalValue(argument, seen));
820
+ }
821
+ if (ts.isPropertyAccessExpression(expression.expression) && ["then", "catch", "finally"].includes(expression.expression.name.text)) {
822
+ const operation = expression.expression.name.text;
823
+ if ((operation === "charAt" || operation === "at") && isStringValue(expression.expression.expression))
824
+ return false;
825
+ if (["replace", "replaceAll"].includes(operation) && hasScalarLength(expression.expression.expression)) {
826
+ const replacement = expression.arguments[1];
827
+ const callback = resolveCallback(replacement);
828
+ return internalValue(expression.expression.expression, seen) || (callback
829
+ ? callbackValue(replacement, seen, [expression.expression.expression]) : !!replacement && internalValue(replacement, seen));
830
+ }
831
+ if (operation === "finally")
832
+ return internalValue(expression.expression.expression, seen);
833
+ for (const [index, argument] of expression.arguments.slice(0, operation === "then" ? 2 : 1).entries()) {
834
+ const input = operation === "then" && index === 0 ? expression.expression.expression : rejectedValue(expression.expression.expression);
835
+ if (callbackValue(argument, seen, input ? [input] : []))
836
+ return true;
837
+ }
838
+ return (operation === "catch" || !expression.arguments[0]) && internalValue(expression.expression.expression, seen);
839
+ }
840
+ if (isResponseConstructor(expression.expression) || ts.isPropertyAccessExpression(expression.expression)
841
+ && expression.expression.name.text === "response" && contextValue(expression.expression.expression))
842
+ return !!expression.arguments[0] && internalValue(expression.arguments[0], seen);
843
+ if (ts.isPropertyAccessExpression(expression.expression) && ["map", "flatMap", "reduce", "reduceRight"].includes(expression.expression.name.text)) {
844
+ if (["reduce", "reduceRight"].includes(expression.expression.name.text) && expression.arguments[1] && internalValue(expression.arguments[1], seen))
845
+ return true;
846
+ return ["reduce", "reduceRight"].includes(expression.expression.name.text)
847
+ ? callbackValue(expression.arguments[0], seen, [expression.arguments[1], expression.expression.expression], [1])
848
+ : callbackValue(expression.arguments[0], seen, [expression.expression.expression], [0]);
849
+ }
850
+ return callbackValue(expression.expression, seen, expression.arguments);
851
+ }
852
+ if (ts.isNewExpression(expression) && isGlobal(expression.expression, "Promise")) {
853
+ const executor = resolveCallback(expression.arguments?.[0]);
854
+ const prefix = expression.arguments?.[0] ? boundInputs(expression.arguments[0], []).length : 0;
855
+ const parameter = executor?.parameters[prefix];
856
+ if (!executor || !parameter)
857
+ return false;
858
+ promiseResolvers.add(parameter);
859
+ try {
860
+ return callbackValue(expression.arguments?.[0], seen, [], [], true);
861
+ }
862
+ finally {
863
+ promiseResolvers.delete(parameter);
864
+ }
865
+ }
866
+ if (ts.isNewExpression(expression) && ["Array", "Map", "Set", "URLSearchParams", "Headers", "FormData", "URL", "String", "Object"].some(name => isGlobal(expression.expression, name)))
867
+ return !!expression.arguments?.some(argument => internalValue(argument, seen));
868
+ if (ts.isNewExpression(expression))
869
+ return isGlobal(expression.expression, "Response") && !!expression.arguments?.[0] && internalValue(expression.arguments[0], seen);
870
+ return expression.getChildren(tree).some(child => internalValue(child, seen));
871
+ };
872
+ const defaultExports = new Set(tree.statements.flatMap(statement => ts.isExportAssignment(statement) && ts.isIdentifier(statement.expression) ? [statement.expression.text] : []));
873
+ const factoryNames = new Set(["createHandler", "createRawHandler", "createStreamHandler", "createSse"]);
874
+ const handlerFactories = new Set();
875
+ const handlerNamespaces = new Set();
876
+ for (const statement of tree.statements) {
877
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.importClause?.isTypeOnly)
878
+ continue;
879
+ const module = statement.moduleSpecifier.text;
880
+ if (module !== "@betterportal/framework" && !module.startsWith("@betterportal/framework/")
881
+ && !/(?:^|[/])\.bp-generated[/]route-runtime(?:\.[cm]?[jt]s)?$/.test(module))
882
+ continue;
883
+ const bindings = statement.importClause?.namedBindings;
884
+ if (bindings && ts.isNamespaceImport(bindings))
885
+ handlerNamespaces.add(bindings.name.text);
886
+ if (bindings && ts.isNamedImports(bindings))
887
+ for (const binding of bindings.elements) {
888
+ if (!binding.isTypeOnly && factoryNames.has(binding.propertyName?.text ?? binding.name.text))
889
+ handlerFactories.add(binding.name.text);
890
+ }
891
+ }
892
+ const factoryImport = (expression, namespace = false, seen = new Set()) => {
893
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
894
+ return factoryImport(expression.expression, namespace, seen);
895
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
896
+ return false;
897
+ let scope = expression.parent;
898
+ while (scope) {
899
+ const initializer = initializers.get(scope)?.get(expression.text);
900
+ if (initializer)
901
+ return namespace ? factoryImport(initializer, true, new Set([...seen, expression.text])) : factory(initializer, new Set([...seen, expression.text]));
902
+ if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
903
+ return false;
904
+ scope = scope.parent;
905
+ }
906
+ return (namespace ? handlerNamespaces : handlerFactories).has(expression.text) && isGlobal(expression, expression.text, true);
907
+ };
908
+ const factory = (expression, seen = new Set()) => ts.isIdentifier(expression) ? factoryImport(expression, false, seen)
909
+ : ts.isPropertyAccessExpression(expression) ? factoryNames.has(expression.name.text) && factoryImport(expression.expression, true, seen)
910
+ || expression.name.text === "forContext" && factory(expression.expression, seen)
911
+ : ts.isCallExpression(expression) ? factory(expression.expression, seen) : false;
912
+ const routeHandlerFile = /(?:^|[/])bp-routes[/](?:.*[/])?(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|SSE|STREAM)\.(?:[cm]?ts|tsx)$/.test(file.replace(/\\/g, "/"));
913
+ const isReturnedValue = (node) => {
914
+ let current = node.parent;
915
+ while (current && !ts.isFunctionLike(current)) {
916
+ if ((ts.isReturnStatement(current) || ts.isYieldExpression(current)))
917
+ return true;
918
+ if (ts.isCallExpression(current) || ts.isNewExpression(current) || ts.isVariableDeclaration(current))
919
+ return false;
920
+ current = current.parent;
921
+ }
922
+ return Boolean(current && ts.isArrowFunction(current) && !ts.isBlock(current.body));
923
+ };
924
+ const ownsHandlerContext = (node) => {
925
+ if (file.includes("_renderer."))
926
+ return false;
927
+ if (routeHandlerFile && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node))) {
928
+ if (node.name && (["handler", "handle"].includes(node.name.text) || defaultExports.has(node.name.text)))
929
+ return true;
930
+ if (ts.getModifiers(node)?.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword))
931
+ return true;
932
+ }
933
+ const parent = node.parent;
934
+ if (routeHandlerFile && ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name)
935
+ && (["handler", "handle"].includes(parent.name.text) || defaultExports.has(parent.name.text)))
936
+ return true;
937
+ if (routeHandlerFile && ts.isExportAssignment(parent))
938
+ return true;
939
+ if (!ts.isCallExpression(parent))
940
+ return false;
941
+ return factory(parent.expression);
942
+ };
943
+ const belongsToHandler = (node) => {
944
+ if (file.includes("_renderer."))
945
+ return false;
946
+ while (node && !ts.isFunctionLike(node) && !ts.isSourceFile(node))
947
+ node = node.parent;
948
+ if (!node || !ts.isFunctionLike(node))
949
+ return false;
950
+ if (ownsHandlerContext(node))
951
+ return true;
952
+ const parent = node.parent;
953
+ if (!ts.isCallExpression(parent))
954
+ return false;
955
+ const callee = parent.expression;
956
+ // A callback contributes to the response only when its call result is returned.
957
+ return ts.isPropertyAccessExpression(callee) && ["map", "flatMap", "reduce", "reduceRight", "transaction", "then", "catch"].includes(callee.name.text)
958
+ && isReturnedValue(parent) && belongsToHandler(parent.parent);
959
+ };
960
+ const inReturnedObject = (node) => {
961
+ let current = node.parent;
962
+ while (current && !ts.isFunctionLike(current)) {
963
+ if (ts.isCallExpression(current) || ts.isNewExpression(current) || ts.isJsxAttribute(current) || ts.isJsxSpreadAttribute(current))
964
+ return false;
965
+ if ((ts.isReturnStatement(current) || ts.isYieldExpression(current)))
966
+ return belongsToHandler(current.parent);
967
+ current = current.parent;
968
+ }
969
+ return Boolean(current && ts.isArrowFunction(current) && !ts.isBlock(current.body) && belongsToHandler(current));
970
+ };
971
+ const contextValue = (expression, seen = new Set()) => {
972
+ if (ts.isObjectBindingPattern(expression) && ts.isParameter(expression.parent)) {
973
+ const parameter = expression.parent;
974
+ const input = parameterInputs.get(parameter);
975
+ if (input)
976
+ return contextValue(input, seen);
977
+ const owner = parameter.parent;
978
+ return ts.isFunctionLike(owner) && (owner.parameters[0] === parameter && ownsHandlerContext(owner)
979
+ || owner.parameters[1] === parameter && rendererFunctions.has(owner)
980
+ || /(?:RouteHandlerContext|ViewRenderContext|HandlerContext)/.test(parameter.type?.getText(tree) ?? ""));
981
+ }
982
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)
983
+ || ts.isNonNullExpression(expression) || ts.isSatisfiesExpression(expression))
984
+ return contextValue(expression.expression, seen);
985
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
986
+ return false;
987
+ let scope = expression.parent;
988
+ while (scope) {
989
+ const selected = selections.get(scope)?.get(expression.text);
990
+ if (selected)
991
+ return selected.element !== undefined ? !selected.rest && selectedElements(selected).some(value => contextValue(value, new Set([...seen, expression.text]))) : selected.rest && contextValue(selected.expression, new Set([...seen, expression.text]));
992
+ const initializer = initializers.get(scope)?.get(expression.text);
993
+ if (initializer)
994
+ return contextValue(initializer, new Set([...seen, expression.text]));
995
+ if (ts.isFunctionLike(scope)) {
996
+ const index = scope.parameters.findIndex(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
997
+ if (index >= 0 && parameterInputs.has(scope.parameters[index]))
998
+ return contextValue(parameterInputs.get(scope.parameters[index]), seen);
999
+ if (index >= 0)
1000
+ return index === 0 && ownsHandlerContext(scope)
1001
+ || index === 1 && rendererFunctions.has(scope)
1002
+ || /(?:RouteHandlerContext|ViewRenderContext|HandlerContext)/.test(scope.parameters[index].type?.getText(tree) ?? "");
1003
+ }
1004
+ scope = scope.parent;
1005
+ }
1006
+ return false;
1007
+ };
1008
+ const isResolverFunction = (expression, seen = new Set()) => {
1009
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
1010
+ return isResolverFunction(expression.expression, seen);
1011
+ if (ts.isPropertyAccessExpression(expression))
1012
+ return expression.name.text === "routeUrl" && contextValue(expression.expression);
1013
+ if (ts.isElementAccessExpression(expression))
1014
+ return ts.isStringLiteralLike(expression.argumentExpression) && expression.argumentExpression.text === "routeUrl" && contextValue(expression.expression);
1015
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
1016
+ return false;
1017
+ let scope = expression.parent;
1018
+ while (scope) {
1019
+ const selected = selections.get(scope)?.get(expression.text);
1020
+ if (selected)
1021
+ return selected.element !== undefined ? !selected.rest && selectedElements(selected).some(value => isResolverFunction(value, new Set([...seen, expression.text]))) : selected.field === "routeUrl" && contextValue(selected.expression);
1022
+ const initializer = initializers.get(scope)?.get(expression.text);
1023
+ if (initializer)
1024
+ return isResolverFunction(initializer, new Set([...seen, expression.text]));
1025
+ if (ts.isFunctionLike(scope)) {
1026
+ const parameter = scope.parameters.find(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text);
1027
+ if (parameter)
1028
+ return parameterInputs.has(parameter) && isResolverFunction(parameterInputs.get(parameter));
1029
+ }
1030
+ scope = scope.parent;
1031
+ }
1032
+ return false;
1033
+ };
1034
+ const authRedirectHelpers = new Set();
1035
+ const authRedirectNamespaces = new Set();
1036
+ for (const statement of tree.statements) {
1037
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)
1038
+ || !/^@betterportal\/framework(?:\/|$)/.test(statement.moduleSpecifier.text) || statement.importClause?.isTypeOnly)
1039
+ continue;
1040
+ const bindings = statement.importClause?.namedBindings;
1041
+ if (bindings && ts.isNamespaceImport(bindings))
1042
+ authRedirectNamespaces.add(bindings.name.text);
1043
+ if (bindings && ts.isNamedImports(bindings))
1044
+ for (const binding of bindings.elements)
1045
+ if (!binding.isTypeOnly && (binding.propertyName?.text ?? binding.name.text) === "resolveAppAuthRedirect")
1046
+ authRedirectHelpers.add(binding.name.text);
1047
+ }
1048
+ const authRedirectFunction = (expression, namespace = false, seen = new Set()) => {
1049
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression))
1050
+ return authRedirectFunction(expression.expression, namespace, seen);
1051
+ if (ts.isPropertyAccessExpression(expression))
1052
+ return expression.name.text === "resolveAppAuthRedirect" && authRedirectFunction(expression.expression, true, seen);
1053
+ if (!ts.isIdentifier(expression) || seen.has(expression.text))
1054
+ return false;
1055
+ let scope = expression.parent;
1056
+ while (scope) {
1057
+ const initializer = initializers.get(scope)?.get(expression.text);
1058
+ if (initializer)
1059
+ return authRedirectFunction(initializer, namespace, new Set([...seen, expression.text]));
1060
+ const selected = selections.get(scope)?.get(expression.text);
1061
+ if (selected)
1062
+ return selected.field === "resolveAppAuthRedirect" && authRedirectFunction(selected.expression, true, new Set([...seen, expression.text]));
1063
+ if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === expression.text))
1064
+ return false;
1065
+ scope = scope.parent;
1066
+ }
1067
+ return (namespace ? authRedirectNamespaces : authRedirectHelpers).has(expression.text) && isGlobal(expression, expression.text, true);
1068
+ };
1069
+ const jsonHelpers = new Set();
1070
+ for (const statement of tree.statements) {
1071
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier)
1072
+ || statement.moduleSpecifier.text !== "@betterportal/framework" || statement.importClause?.isTypeOnly)
1073
+ continue;
1074
+ const bindings = statement.importClause?.namedBindings;
1075
+ if (bindings && ts.isNamedImports(bindings))
1076
+ for (const binding of bindings.elements) {
1077
+ if (!binding.isTypeOnly && (binding.propertyName?.text ?? binding.name.text) === "jsonResponse")
1078
+ jsonHelpers.add(binding.name.text);
1079
+ }
1080
+ }
1081
+ const isGlobal = (expression, name, allowImport = false) => {
1082
+ if (!ts.isIdentifier(expression) || expression.text !== name)
1083
+ return false;
1084
+ let scope = expression.parent;
1085
+ while (scope) {
1086
+ if (declarations.get(scope)?.has(name) && !(allowImport && ts.isSourceFile(scope)) || initializers.get(scope)?.has(name) || selections.get(scope)?.has(name))
1087
+ return false;
1088
+ if (ts.isFunctionLike(scope) && scope.parameters.some(parameter => ts.isIdentifier(parameter.name) && parameter.name.text === name))
1089
+ return false;
1090
+ scope = scope.parent;
1091
+ }
1092
+ return true;
1093
+ };
1094
+ const isResponseConstructor = (expression) => {
1095
+ if (ts.isIdentifier(expression))
1096
+ return jsonHelpers.has(expression.text) && isGlobal(expression, expression.text, true);
1097
+ return ts.isPropertyAccessExpression(expression) && (isGlobal(expression.expression, "Response") && expression.name.text === "json"
1098
+ || isGlobal(expression.expression, "JSON") && ["stringify", "parse"].includes(expression.name.text)
1099
+ || isGlobal(expression.expression, "Promise") && ["resolve", "all", "allSettled", "race", "any"].includes(expression.name.text));
1100
+ };
1101
+ const visit = (node) => {
1102
+ if (ts.isPropertyAccessExpression(node) && node.name.text === "uiRouteUrl" && contextValue(node.expression)
1103
+ || ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression) && node.argumentExpression.text === "uiRouteUrl" && contextValue(node.expression)
1104
+ || ts.isBindingElement(node) && (node.propertyName ?? node.name).getText(tree).replace(/^["']|["']$/g, "") === "uiRouteUrl"
1105
+ && ts.isObjectBindingPattern(node.parent) && ts.isVariableDeclaration(node.parent.parent)
1106
+ && !!node.parent.parent.initializer && contextValue(node.parent.parent.initializer)
1107
+ || ts.isBindingElement(node) && (node.propertyName ?? node.name).getText(tree).replace(/^["']|["']$/g, "") === "uiRouteUrl"
1108
+ && ts.isObjectBindingPattern(node.parent) && ts.isParameter(node.parent.parent) && contextValue(node.parent)) {
1109
+ report(node, "uiRouteUrl was removed. Use ctx.routeUrl({ ... }) and select uiPath or absoluteUiPath.");
1110
+ }
1111
+ if (ts.isPropertyAccessExpression(node) && ["route", "uiRoute", "current", "path"].includes(node.name.text)
1112
+ && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "url" && contextValue(node.expression.expression)) {
1113
+ report(node, "ctx.url helpers were removed. Use ctx.routeUrl({ ... }); omit the target for self.");
1114
+ }
1115
+ if (ts.isCallExpression(node) && isResolverFunction(node.expression)) {
1116
+ if (node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0])
1117
+ && node.arguments[0].properties.some(item => item.name && ["absolute", "origin"].includes(ts.isIdentifier(item.name) || ts.isStringLiteralLike(item.name) ? item.name.text : item.name.getText(tree)))) {
1118
+ report(node, "absolute/origin options were removed. Select the corresponding absolute destination field.");
1119
+ }
1120
+ if ((node.arguments.length > 1 || node.arguments[0] && ts.isStringLiteralLike(node.arguments[0]))) {
1121
+ report(node, "routeUrl no longer accepts a positional view id or returns a string. Pass one options object and select a destination field.");
1122
+ }
1123
+ }
1124
+ let field;
1125
+ if (ts.isPropertyAccessExpression(node))
1126
+ field = node.name.text;
1127
+ if ((ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isBindingElement(node)) && node.name && (ts.isIdentifier(node.name) || ts.isStringLiteralLike(node.name)))
1128
+ field = node.name.text;
1129
+ if (ts.isBindingElement(node) && node.propertyName && (ts.isIdentifier(node.propertyName) || ts.isStringLiteralLike(node.propertyName)))
1130
+ field = node.propertyName.text;
1131
+ if (ts.isElementAccessExpression(node) && node.argumentExpression && ts.isStringLiteralLike(node.argumentExpression))
1132
+ field = node.argumentExpression.text;
1133
+ const payloadAccess = (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node))
1134
+ && rendererPayload(node.expression);
1135
+ const payloadBinding = ts.isBindingElement(node) && ts.isObjectBindingPattern(node.parent)
1136
+ && ts.isVariableDeclaration(node.parent.parent) && node.parent.parent.initializer
1137
+ && rendererPayload(node.parent.parent.initializer);
1138
+ const payloadParameter = ts.isBindingElement(node) && ts.isObjectBindingPattern(node.parent)
1139
+ && ts.isParameter(node.parent.parent) && rendererFunctions.has(node.parent.parent.parent)
1140
+ && ts.isFunctionLike(node.parent.parent.parent) && node.parent.parent.parent.parameters[0] === node.parent.parent;
1141
+ if (field && legacyFields.has(field) && (payloadAccess || payloadBinding || payloadParameter))
1142
+ report(node, `Legacy internal URL field '${field}' was removed. Return domain data/cursors and resolve destinations in the renderer.`);
1143
+ const returned = (ts.isReturnStatement(node) || ts.isYieldExpression(node)) && node.expression && belongsToHandler(node.parent) ? node.expression
1144
+ : ts.isArrowFunction(node) && !ts.isBlock(node.body) && belongsToHandler(node) ? node.body : undefined;
1145
+ if (returned && internalValue(returned))
1146
+ report(node, "Do not return internal route destinations from API handlers. Return domain data and resolve destinations at the point of use.");
1147
+ if ((ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isSpreadAssignment(node)) && inReturnedObject(node) && internalValue(ts.isSpreadAssignment(node) ? node.expression : ts.isPropertyAssignment(node) ? node.initializer : node.name)) {
1148
+ report(node, "Do not return internal route paths as API response fields. Resolve them at the point of use; only public absoluteUiPath links belong in domain responses.");
1149
+ }
1150
+ if ((ts.isStringLiteralLike(node) || ts.isNoSubstitutionTemplateLiteral(node)) && /(?:href|action|hx-(?:get|post|put|patch|delete|download))=["']\{[A-Za-z0-9_$.-]+\}["']/.test(node.text)) {
1151
+ report(node, "Legacy route tokens were removed. Resolve the destination with ctx.routeUrl in the renderer.");
1152
+ }
1153
+ if (ts.isJsxAttribute(node) && node.initializer && ts.isStringLiteralLike(node.initializer)
1154
+ && ["href", "action", "hx-get", "hx-post", "hx-put", "hx-patch", "hx-delete", "hx-download", "sse-connect"].includes(node.name.getText(tree))
1155
+ && /^\{[A-Za-z0-9_$.-]+\}$/.test(node.initializer.text)) {
1156
+ report(node, "Legacy route tokens were removed. Resolve the destination with ctx.routeUrl in the renderer.");
1157
+ }
1158
+ ts.forEachChild(node, visit);
1159
+ };
1160
+ visit(tree);
1161
+ return errors;
1162
+ }
1163
+ /** Inspect project source, including domain helpers outside bp-routes, before generation/build. */
1164
+ export function checkProjectRouteUrls(directory) {
1165
+ if (!fs.existsSync(directory))
1166
+ return [];
1167
+ return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
1168
+ if ((entry.name.startsWith(".") && entry.name !== ".well-known") || entry.name === "node_modules")
1169
+ return [];
1170
+ const file = path.join(directory, entry.name);
1171
+ return entry.isDirectory() ? checkProjectRouteUrls(file) : /\.(?:[cm]?ts|tsx)$/.test(file) ? inspectRouteUrlSource(file, fs.readFileSync(file, "utf8")) : [];
1172
+ });
1173
+ }
1174
+ /** Inspect default source helpers and every configured route/shell input root. */
1175
+ export function checkConfiguredRouteUrls(packageDir, config = {}) {
1176
+ const roots = [...new Set(["src", ...config.routes ?? [], ...config.shells ?? []].map(directory => path.resolve(packageDir, directory)))];
1177
+ const minimal = roots.filter(root => !roots.some(parent => {
1178
+ if (parent === root)
1179
+ return false;
1180
+ const relative = path.relative(parent, root);
1181
+ return relative !== ".." && !relative.startsWith(".." + path.sep) && !path.isAbsolute(relative);
1182
+ }));
1183
+ return minimal.flatMap(checkProjectRouteUrls);
1184
+ }
1185
+ //# sourceMappingURL=routeUrlPolicy.js.map