@uipath/rules-tool 0.0.0-stage → 1.204.0-preview.249

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 (139) hide show
  1. package/LICENSE.txt +3 -0
  2. package/README.md +80 -2
  3. package/dist/DmnFactory-SG3RP3T3-cr8e7mxz.js +8 -0
  4. package/dist/DmnFactory-VWZOSZHH-azx0zqcn.js +8 -0
  5. package/dist/DmnModelTypes-ATR7FVKZ-vkv7n0jn.js +8 -0
  6. package/dist/KieDmnMarshaller-6TTUU5B4-rsxhvw7a.js +8 -0
  7. package/dist/business-rules-d51977r1.js +25 -0
  8. package/dist/business-rules-dekge24t.js +23 -0
  9. package/dist/business-rules-ew76mbwg.js +25 -0
  10. package/dist/business-rules-jmwx05k2.js +25 -0
  11. package/dist/business-rules-zpzqxyce.js +26 -0
  12. package/dist/constants-4r8pfr16.js +22 -0
  13. package/dist/constants-za5vbzp8.js +22 -0
  14. package/dist/embedded-file-reader-0228j82a.js +111 -0
  15. package/dist/embedded-file-reader-wmsg31a8.js +111 -0
  16. package/dist/first-party-service-1qa6cp4d.js +8 -0
  17. package/dist/first-party-service-28dkctkz.js +8 -0
  18. package/dist/first-party-service-4fsz3cnj.js +8 -0
  19. package/dist/first-party-service-ahcc6xc6.js +8 -0
  20. package/dist/first-party-service-y1ccmsvp.js +8 -0
  21. package/dist/first-party-service-zpr1q3nd.js +8 -0
  22. package/dist/hitPolicyResult-4WDHTX4A-dbtkgpqp.js +12 -0
  23. package/dist/index-2zxy6zgp.js +23 -0
  24. package/dist/index-3nx77wfh.js +23 -0
  25. package/dist/index-43zg1wqe.js +19621 -0
  26. package/dist/index-47jera73.js +23 -0
  27. package/dist/index-70jn7cz1.js +19631 -0
  28. package/dist/index-7wc0g78k.js +14 -0
  29. package/dist/index-8kb5kc5y.js +24 -0
  30. package/dist/index-97yad7ms.js +8 -0
  31. package/dist/index-dfn83hxf.js +14 -0
  32. package/dist/index-e301h23h.js +24 -0
  33. package/dist/index-frd259yv.js +24 -0
  34. package/dist/index-gc7cw2jh.js +23 -0
  35. package/dist/index-gya2v502.js +8 -0
  36. package/dist/index-hb3gk1wf.js +24 -0
  37. package/dist/index-nsnfdqd5.js +24 -0
  38. package/dist/index-nzr4mx5p.js +614 -0
  39. package/dist/index-vffktc0w.js +166 -0
  40. package/dist/index-we6zjs66.js +164 -0
  41. package/dist/index-xymrydfw.js +3095 -0
  42. package/dist/index-z2qk2qn6.js +24 -0
  43. package/dist/index-zdwhfpt1.js +3071 -0
  44. package/dist/index-zecwgvg7.js +23 -0
  45. package/dist/index.js +16 -0
  46. package/dist/jmespath-ab6tdc42.js +1485 -0
  47. package/dist/js-yaml-a2bk27p6.js +3151 -0
  48. package/dist/rule-catalog-a5w86qns.js +43 -0
  49. package/dist/rule-catalog-etpf962f.js +69 -0
  50. package/dist/rule-catalog-q5cr17hf.js +58 -0
  51. package/dist/rule-catalog-vc98yg4n.js +43 -0
  52. package/dist/rule-catalog-z3h66kh5.js +56 -0
  53. package/dist/rules-command-error-10qmb5w7.js +13 -0
  54. package/dist/rules-command-error-5bdv4bcx.js +13 -0
  55. package/dist/rules-command-error-cmssf0w4.js +13 -0
  56. package/dist/rules-command-error-fsm3b1mv.js +13 -0
  57. package/dist/rules-debug-service-5rcdh3pj.js +192 -0
  58. package/dist/rules-debug-service-8q7mkd0r.js +199 -0
  59. package/dist/rules-debug-service-b9j29ejz.js +192 -0
  60. package/dist/rules-debug-service-h1ahd6p3.js +192 -0
  61. package/dist/rules-debug-service-v3jr3r1n.js +192 -0
  62. package/dist/rules-init-service-3c2yfa7p.js +687 -0
  63. package/dist/rules-init-service-3wgd9cqp.js +100 -0
  64. package/dist/rules-init-service-8fqytxq0.js +685 -0
  65. package/dist/rules-init-service-pspt7sje.js +100 -0
  66. package/dist/rules-init-service-sbtzw93j.js +102 -0
  67. package/dist/rules-init-service-x7paqa63.js +687 -0
  68. package/dist/rules-init-service-y678kjje.js +100 -0
  69. package/dist/rules-init-service-y7qzmxx0.js +102 -0
  70. package/dist/rules-refresh-service-4xxj6ex6.js +65 -0
  71. package/dist/rules-refresh-service-ba5jk1y9.js +65 -0
  72. package/dist/rules-refresh-service-btn64j8j.js +65 -0
  73. package/dist/rules-refresh-service-qkmphj53.js +65 -0
  74. package/dist/rules-validate-service-dmgnfne7.js +60 -0
  75. package/dist/rules-validate-service-hk2d006t.js +60 -0
  76. package/dist/rules-validate-service-sppr4x13.js +60 -0
  77. package/dist/rules-validate-service-xp05n2d9.js +60 -0
  78. package/dist/tool-0bthsb3x.js +55 -0
  79. package/dist/tool-1dycs173.js +4014 -0
  80. package/dist/tool-1pkqxwwd.js +17472 -0
  81. package/dist/tool-24mr6g8c.js +1556 -0
  82. package/dist/tool-2trg1fpx.js +40 -0
  83. package/dist/tool-39fmkx2d.js +611 -0
  84. package/dist/tool-3e2q1x2y.js +6578 -0
  85. package/dist/tool-3j0747gg.js +17077 -0
  86. package/dist/tool-4z7zcq4z.js +6058 -0
  87. package/dist/tool-56smnjrh.js +73 -0
  88. package/dist/tool-5qygptrc.js +6171 -0
  89. package/dist/tool-5xx6x8pe.js +6596 -0
  90. package/dist/tool-6rp0gx98.js +6578 -0
  91. package/dist/tool-6sqt4zrx.js +571 -0
  92. package/dist/tool-7fkrd618.js +1556 -0
  93. package/dist/tool-7xmarr97.js +17077 -0
  94. package/dist/tool-89xzeteg.js +361 -0
  95. package/dist/tool-8j9f6ns5.js +6396 -0
  96. package/dist/tool-911s9czz.js +570 -0
  97. package/dist/tool-97x3zjcm.js +709 -0
  98. package/dist/tool-9bz2x04j.js +40 -0
  99. package/dist/tool-akh7nnqs.js +704 -0
  100. package/dist/tool-axfzew45.js +1555 -0
  101. package/dist/tool-b71jq9pt.js +389 -0
  102. package/dist/tool-bfj846v8.js +141 -0
  103. package/dist/tool-bvmc017m.js +96 -0
  104. package/dist/tool-bykz5ryf.js +454 -0
  105. package/dist/tool-c76qb8ap.js +17052 -0
  106. package/dist/tool-ca15515v.js +570 -0
  107. package/dist/tool-e1mmqsjr.js +11048 -0
  108. package/dist/tool-epsr41wx.js +48 -0
  109. package/dist/tool-f9qs255w.js +70 -0
  110. package/dist/tool-fbqnqf9k.js +10 -0
  111. package/dist/tool-ga79rety.js +389 -0
  112. package/dist/tool-gb547mcn.js +141 -0
  113. package/dist/tool-gta9rr4h.js +68 -0
  114. package/dist/tool-h2dfnxdq.js +6486 -0
  115. package/dist/tool-hg6vr5y9.js +3769 -0
  116. package/dist/tool-hgvnm4vh.js +1843 -0
  117. package/dist/tool-hjbf9aay.js +571 -0
  118. package/dist/tool-k2s349kn.js +108 -0
  119. package/dist/tool-k5jm64n3.js +5650 -0
  120. package/dist/tool-ketztpgf.js +73 -0
  121. package/dist/tool-mm1x18d6.js +537 -0
  122. package/dist/tool-n1d88ryb.js +6396 -0
  123. package/dist/tool-nmqpwh9m.js +6166 -0
  124. package/dist/tool-pb80pswx.js +73 -0
  125. package/dist/tool-pcsgwpfw.js +40 -0
  126. package/dist/tool-q3c1bjyb.js +454 -0
  127. package/dist/tool-rwp1skmf.js +40 -0
  128. package/dist/tool-s3fbt22r.js +454 -0
  129. package/dist/tool-tmbst1r8.js +68 -0
  130. package/dist/tool-v6w109p0.js +455 -0
  131. package/dist/tool-vyx8fpft.js +46 -0
  132. package/dist/tool-w2js05qv.js +389 -0
  133. package/dist/tool-x67kek1m.js +1838 -0
  134. package/dist/tool-x89947ah.js +17052 -0
  135. package/dist/tool-xhksjdka.js +4005 -0
  136. package/dist/tool-yv3t4gg5.js +108 -0
  137. package/dist/tool-zbyb1ttx.js +5650 -0
  138. package/dist/tool.js +11 -0
  139. package/package.json +43 -5
@@ -0,0 +1,199 @@
1
+ import {
2
+ getAuthContext,
3
+ PersonalWorkspacesApi,
4
+ createApiClient
5
+ } from "./tool-8j9f6ns5.js";
6
+ import {
7
+ getFileSystem,
8
+ catchError,
9
+ logger
10
+ } from "./tool-5qygptrc.js";
11
+ import {
12
+ buildSolutionPackageFromDir,
13
+ uploadOrOverwriteSolution
14
+ } from "./tool-axfzew45.js";
15
+ import {
16
+ RulesCommandError2,
17
+ isJsonObject2
18
+ } from "./tool-9bz2x04j.js";
19
+ import {
20
+ resolveRequiredFolder2
21
+ } from "./tool-f9qs255w.js";
22
+ import {
23
+ findSolutionFile,
24
+ updateSolutionFile
25
+ } from "./tool-s3fbt22r.js";
26
+ import {
27
+ readRulesProjectNameAsync
28
+ } from "./tool-gta9rr4h.js";
29
+
30
+ // src/services/rules-engine-client.ts
31
+ var DEBUG_EVALUATE_PATH = "/v1/business-rules/debug/evaluate";
32
+ var DEFAULT_TIMEOUT_SECONDS = 120;
33
+
34
+ class RulesEngineHttpError extends Error {
35
+ status;
36
+ constructor(status, message) {
37
+ super(message);
38
+ this.status = status;
39
+ this.name = "RulesEngineHttpError";
40
+ }
41
+ }
42
+ async function assertBusinessRulesServiceAsync(config, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
43
+ const [error] = await catchError(postDebugEvaluate(config, {}, timeoutSeconds));
44
+ if (error && !(error instanceof RulesEngineHttpError && error.status === 400)) {
45
+ throw error;
46
+ }
47
+ }
48
+ async function evaluateRuleDebugAsync(config, request, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
49
+ return postDebugEvaluate(config, request, timeoutSeconds);
50
+ }
51
+ async function postDebugEvaluate(config, request, timeoutSeconds) {
52
+ const url = `${config.baseUrl}/${encodeURIComponent(config.organizationId)}/${encodeURIComponent(config.tenantName)}/businessrules_${DEBUG_EVALUATE_PATH}`;
53
+ const [fetchError, response] = await catchError(fetch(url, {
54
+ method: "POST",
55
+ headers: {
56
+ Authorization: `Bearer ${config.authToken}`,
57
+ Accept: "application/json",
58
+ "Content-Type": "application/json",
59
+ ...config.folderKey ? { "x-uipath-folderkey": config.folderKey } : {}
60
+ },
61
+ body: JSON.stringify(request),
62
+ signal: AbortSignal.timeout(timeoutSeconds * 1000)
63
+ }));
64
+ if (fetchError?.name === "TimeoutError") {
65
+ throw new RulesCommandError2(`The rules engine did not answer within ${timeoutSeconds} seconds.`, "timeout", "Run the command again, or pass a larger --timeout.", "RetryLater");
66
+ }
67
+ if (fetchError) {
68
+ throw fetchError;
69
+ }
70
+ if (!response.ok) {
71
+ throw await engineFailure(response, config.tenantName);
72
+ }
73
+ return await response.json();
74
+ }
75
+ async function engineFailure(response, tenantName) {
76
+ const text = await response.text().catch(() => "");
77
+ if (response.status === 404 && /Service: businessrules not found in Organization/i.test(text)) {
78
+ return new RulesCommandError2(`Business Rules is not enabled on tenant '${tenantName}'.`, "configuration_error", "Ask your UiPath contact to enable Business Rules for this tenant, or switch to a tenant that has it with 'uip login tenant set <tenant-name>'.");
79
+ }
80
+ const [, body] = catchError(() => JSON.parse(text));
81
+ const error = isJsonObject2(body) && isJsonObject2(body.error) ? body.error : {};
82
+ if (error.code === "STUDIO_FORBIDDEN") {
83
+ return new RulesCommandError2("Studio Web did not let the rules engine read the uploaded project.", "permission_denied", "Check in Studio Web that your account can open the uploaded solution.");
84
+ }
85
+ const message = typeof error.message === "string" ? error.message : "The rules engine request failed.";
86
+ return new RulesEngineHttpError(response.status, typeof error.code === "string" ? `${message} (${error.code})` : message);
87
+ }
88
+
89
+ // src/services/rules-debug-service.ts
90
+ async function debugRuleProjectAsync(projectPath, options) {
91
+ assertFolderOnlyWithExplain(options);
92
+ const inputs = [{ id: "1", data: await parseInput(options.inputs) }];
93
+ const fs = getFileSystem();
94
+ const projectDir = fs.path.resolve(projectPath);
95
+ const projectName = await readRulesProjectName(projectDir);
96
+ const solutionDir = fs.path.resolve(projectDir, "..");
97
+ await assertSolutionFolder(solutionDir);
98
+ const { config, organizationName } = await loggedInContext(options.loginValidity);
99
+ await assertBusinessRulesServiceAsync(config, options.timeout);
100
+ const folderKey = await traceFolderKey(options);
101
+ const existingSolutionId = (await findSolutionFile(fs, projectDir))?.solutionId;
102
+ logger.info(`Uploading the solution of '${projectName}' to Studio Web...`);
103
+ const uisPath = await buildSolutionPackageFromDir(fs, solutionDir);
104
+ const [uploadError, upload] = await catchError(uploadOrOverwriteSolution(config, organizationName, uisPath, existingSolutionId, fs));
105
+ await fs.rm(uisPath).catch(() => {
106
+ return;
107
+ });
108
+ if (uploadError) {
109
+ throw uploadError;
110
+ }
111
+ if (upload.id !== existingSolutionId) {
112
+ await updateSolutionFile(fs, projectDir, upload.id);
113
+ }
114
+ const project = upload.projects.find((p) => p.name === projectName);
115
+ if (!project) {
116
+ throw new RulesCommandError2(`Studio Web returned no project named '${projectName}' for the uploaded solution.`, "not_found", "Check that the project is listed in the solution's .uipx, then run the command again.");
117
+ }
118
+ logger.info(`Evaluating against Studio Web project ${project.id}...`);
119
+ const response = await evaluateRuleDebugAsync({ ...config, folderKey }, { projectId: project.id, explain: options.explain, inputs }, options.timeout);
120
+ return {
121
+ solutionId: upload.id,
122
+ projectId: project.id,
123
+ studioWebUrl: studioWebDesignerUrl(config.baseUrl, organizationName, project.id, upload.id),
124
+ response
125
+ };
126
+ }
127
+ async function parseInput(raw) {
128
+ if (raw === undefined || raw === "") {
129
+ return {};
130
+ }
131
+ const filePath = raw.startsWith("@") ? raw.slice(1) : undefined;
132
+ const [readError, text] = filePath === undefined ? [undefined, raw] : await catchError(getFileSystem().readFile(filePath, "utf-8"));
133
+ if (readError || text === null) {
134
+ throw new RulesCommandError2(`Input file '${filePath}' could not be read: ${readError?.message ?? "file not found"}.`, "invalid_argument", "Pass --inputs as a JSON object or @file.json pointing at an existing file.");
135
+ }
136
+ const [parseError, parsed] = catchError(() => JSON.parse(text));
137
+ if (parseError || !isJsonObject2(parsed)) {
138
+ throw new RulesCommandError2(parseError ? `--inputs is not valid JSON: ${parseError.message}` : "--inputs must be a JSON object of input values.", "invalid_argument", `Pass --inputs '{"<input>": <value>}' or @file.json holding one such object.`);
139
+ }
140
+ return parsed;
141
+ }
142
+ function studioWebDesignerUrl(baseUrl, organizationName, projectId, solutionId) {
143
+ return `${baseUrl}/${encodeURIComponent(organizationName)}/studio_/designer/${encodeURIComponent(projectId)}?solutionId=${encodeURIComponent(solutionId)}`;
144
+ }
145
+ async function readRulesProjectName(projectDir) {
146
+ const name = await readRulesProjectNameAsync(projectDir);
147
+ if (!name) {
148
+ throw new RulesCommandError2(`${projectDir}/project.uiproj has no Name.`, "invalid_argument", "Set Name in project.uiproj to the rules project's name, as 'uip rules init' writes it.");
149
+ }
150
+ return name;
151
+ }
152
+ async function assertSolutionFolder(solutionDir) {
153
+ const [, entries] = await catchError(getFileSystem().readdir(solutionDir));
154
+ if (!entries?.some((entry) => entry.endsWith(".uipx"))) {
155
+ throw new RulesCommandError2(`${solutionDir} holds no .uipx, so the rules project is not inside a solution.`, "invalid_argument", "Pass a rules project that sits directly inside its solution folder, as 'uip rules init' creates it.");
156
+ }
157
+ }
158
+ async function loggedInContext(loginValidity) {
159
+ const auth = await getAuthContext({
160
+ ensureTokenValidityMinutes: loginValidity,
161
+ requireOrganizationId: true,
162
+ requireOrganizationName: true,
163
+ requireTenantName: true
164
+ });
165
+ return {
166
+ config: {
167
+ baseUrl: auth.baseUrl,
168
+ organizationId: auth.organizationId,
169
+ tenantName: auth.tenantName,
170
+ tenantId: auth.tenantId,
171
+ authToken: auth.accessToken
172
+ },
173
+ organizationName: auth.organizationName
174
+ };
175
+ }
176
+ function assertFolderOnlyWithExplain(options) {
177
+ if (!options.explain && (options.folderPath !== undefined || options.folderKey !== undefined)) {
178
+ throw new RulesCommandError2("--folder-path and --folder-key set the folder the --explain trace is published into, so they need --explain.", "invalid_argument", "Add --explain to trace the run into that folder, or drop the folder option.");
179
+ }
180
+ }
181
+ async function traceFolderKey(options) {
182
+ if (options.folderPath !== undefined || options.folderKey !== undefined) {
183
+ return (await resolveRequiredFolder2(options)).key;
184
+ }
185
+ if (!options.explain) {
186
+ return;
187
+ }
188
+ const api = await createApiClient(PersonalWorkspacesApi, {});
189
+ const personal = await api.personalWorkspacesGetPersonalWorkspace();
190
+ if (!personal?.key) {
191
+ throw new RulesCommandError2("Could not find your personal workspace to publish the trace into.", "invalid_argument", "Pass --folder-path <path> or --folder-key <key> to publish the trace into a folder you can read.");
192
+ }
193
+ return personal.key;
194
+ }
195
+ export {
196
+ debugRuleProjectAsync
197
+ };
198
+
199
+ //# debugId=4A5827A5FC49620264756E2164756E21
@@ -0,0 +1,192 @@
1
+ import {
2
+ getAuthContext,
3
+ PersonalWorkspacesApi,
4
+ createApiClient
5
+ } from "./tool-n1d88ryb.js";
6
+ import {
7
+ getFileSystem,
8
+ catchError,
9
+ logger
10
+ } from "./tool-6rp0gx98.js";
11
+ import {
12
+ buildSolutionPackageFromDir,
13
+ uploadOrOverwriteSolution
14
+ } from "./tool-7fkrd618.js";
15
+ import {
16
+ RulesCommandError2,
17
+ isJsonObject2
18
+ } from "./tool-rwp1skmf.js";
19
+ import {
20
+ assertOneFolderOption2,
21
+ resolveRequiredFolder2
22
+ } from "./tool-ketztpgf.js";
23
+ import {
24
+ findSolutionFile,
25
+ updateSolutionFile
26
+ } from "./tool-q3c1bjyb.js";
27
+ import {
28
+ readRulesProjectNameAsync
29
+ } from "./tool-k2s349kn.js";
30
+
31
+ // src/services/rules-engine-client.ts
32
+ var DEBUG_EVALUATE_PATH = "/v1/business-rules/debug/evaluate";
33
+ var DEFAULT_TIMEOUT_SECONDS = 120;
34
+
35
+ class RulesEngineHttpError extends Error {
36
+ status;
37
+ constructor(status, message) {
38
+ super(message);
39
+ this.status = status;
40
+ this.name = "RulesEngineHttpError";
41
+ }
42
+ }
43
+ async function assertBusinessRulesServiceAsync(config, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
44
+ const [error] = await catchError(postDebugEvaluate(config, {}, timeoutSeconds));
45
+ if (error && !(error instanceof RulesEngineHttpError && error.status === 400)) {
46
+ throw error;
47
+ }
48
+ }
49
+ async function evaluateRuleDebugAsync(config, request, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
50
+ return postDebugEvaluate(config, request, timeoutSeconds);
51
+ }
52
+ async function postDebugEvaluate(config, request, timeoutSeconds) {
53
+ const url = `${config.baseUrl}/${encodeURIComponent(config.organizationId)}/${encodeURIComponent(config.tenantName)}/businessrules_${DEBUG_EVALUATE_PATH}`;
54
+ const [fetchError, response] = await catchError(fetch(url, {
55
+ method: "POST",
56
+ headers: {
57
+ Authorization: `Bearer ${config.authToken}`,
58
+ Accept: "application/json",
59
+ "Content-Type": "application/json",
60
+ ...config.folderKey ? { "x-uipath-folderkey": config.folderKey } : {}
61
+ },
62
+ body: JSON.stringify(request),
63
+ signal: AbortSignal.timeout(timeoutSeconds * 1000)
64
+ }));
65
+ if (fetchError?.name === "TimeoutError") {
66
+ throw new RulesCommandError2(`The rules engine did not answer within ${timeoutSeconds} seconds.`, "timeout", "Run the command again, or pass a larger --timeout.", "RetryLater");
67
+ }
68
+ if (fetchError) {
69
+ throw fetchError;
70
+ }
71
+ if (!response.ok) {
72
+ throw await engineFailure(response, config.tenantName);
73
+ }
74
+ return await response.json();
75
+ }
76
+ async function engineFailure(response, tenantName) {
77
+ const text = await response.text().catch(() => "");
78
+ if (response.status === 404 && /Service: businessrules not found in Organization/i.test(text)) {
79
+ return new RulesCommandError2(`Business Rules is not enabled on tenant '${tenantName}'.`, "configuration_error", "Ask your UiPath contact to enable Business Rules for this tenant, or switch to a tenant that has it with 'uip login tenant set <tenant-name>'.");
80
+ }
81
+ const [, body] = catchError(() => JSON.parse(text));
82
+ const error = isJsonObject2(body) && isJsonObject2(body.error) ? body.error : {};
83
+ if (error.code === "STUDIO_FORBIDDEN") {
84
+ return new RulesCommandError2("Studio Web did not let the rules engine read the uploaded project.", "permission_denied", "Check in Studio Web that your account can open the uploaded solution.");
85
+ }
86
+ const message = typeof error.message === "string" ? error.message : "The rules engine request failed.";
87
+ return new RulesEngineHttpError(response.status, typeof error.code === "string" ? `${message} (${error.code})` : message);
88
+ }
89
+
90
+ // src/services/rules-debug-service.ts
91
+ async function debugRuleProjectAsync(projectPath, options) {
92
+ assertOneFolderOption2(options);
93
+ const inputs = [{ id: "1", data: await parseInput(options.inputs) }];
94
+ const fs = getFileSystem();
95
+ const projectDir = fs.path.resolve(projectPath);
96
+ const projectName = await readRulesProjectName(projectDir);
97
+ const solutionDir = fs.path.resolve(projectDir, "..");
98
+ await assertSolutionFolder(solutionDir);
99
+ const { config, organizationName } = await loggedInContext(options.loginValidity);
100
+ await assertBusinessRulesServiceAsync(config, options.timeout);
101
+ const folderKey = await evaluationFolderKey(options);
102
+ const existingSolutionId = (await findSolutionFile(fs, projectDir))?.solutionId;
103
+ logger.info(`Uploading the solution of '${projectName}' to Studio Web...`);
104
+ const uisPath = await buildSolutionPackageFromDir(fs, solutionDir);
105
+ const [uploadError, upload] = await catchError(uploadOrOverwriteSolution(config, organizationName, uisPath, existingSolutionId, fs));
106
+ await fs.rm(uisPath).catch(() => {
107
+ return;
108
+ });
109
+ if (uploadError) {
110
+ throw uploadError;
111
+ }
112
+ if (upload.id !== existingSolutionId) {
113
+ await updateSolutionFile(fs, projectDir, upload.id);
114
+ }
115
+ const project = upload.projects.find((p) => p.name === projectName);
116
+ if (!project) {
117
+ throw new RulesCommandError2(`Studio Web returned no project named '${projectName}' for the uploaded solution.`, "not_found", "Check that the project is listed in the solution's .uipx, then run the command again.");
118
+ }
119
+ logger.info(`Evaluating against Studio Web project ${project.id}...`);
120
+ const response = await evaluateRuleDebugAsync({ ...config, folderKey }, { projectId: project.id, explain: options.explain, inputs }, options.timeout);
121
+ return {
122
+ solutionId: upload.id,
123
+ projectId: project.id,
124
+ studioWebUrl: studioWebDesignerUrl(config.baseUrl, organizationName, project.id, upload.id),
125
+ response
126
+ };
127
+ }
128
+ async function parseInput(raw) {
129
+ if (raw === undefined || raw === "") {
130
+ return {};
131
+ }
132
+ const filePath = raw.startsWith("@") ? raw.slice(1) : undefined;
133
+ const [readError, text] = filePath === undefined ? [undefined, raw] : await catchError(getFileSystem().readFile(filePath, "utf-8"));
134
+ if (readError || text === null) {
135
+ throw new RulesCommandError2(`Input file '${filePath}' could not be read: ${readError?.message ?? "file not found"}.`, "invalid_argument", "Pass --inputs as a JSON object or @file.json pointing at an existing file.");
136
+ }
137
+ const [parseError, parsed] = catchError(() => JSON.parse(text));
138
+ if (parseError || !isJsonObject2(parsed)) {
139
+ throw new RulesCommandError2(parseError ? `--inputs is not valid JSON: ${parseError.message}` : "--inputs must be a JSON object of input values.", "invalid_argument", `Pass --inputs '{"<input>": <value>}' or @file.json holding one such object.`);
140
+ }
141
+ return parsed;
142
+ }
143
+ function studioWebDesignerUrl(baseUrl, organizationName, projectId, solutionId) {
144
+ return `${baseUrl}/${encodeURIComponent(organizationName)}/studio_/designer/${encodeURIComponent(projectId)}?solutionId=${encodeURIComponent(solutionId)}`;
145
+ }
146
+ async function readRulesProjectName(projectDir) {
147
+ const name = await readRulesProjectNameAsync(projectDir);
148
+ if (!name) {
149
+ throw new RulesCommandError2(`${projectDir}/project.uiproj has no Name.`, "invalid_argument", "Set Name in project.uiproj to the rules project's name, as 'uip rules init' writes it.");
150
+ }
151
+ return name;
152
+ }
153
+ async function assertSolutionFolder(solutionDir) {
154
+ const [, entries] = await catchError(getFileSystem().readdir(solutionDir));
155
+ if (!entries?.some((entry) => entry.endsWith(".uipx"))) {
156
+ throw new RulesCommandError2(`${solutionDir} holds no .uipx, so the rules project is not inside a solution.`, "invalid_argument", "Pass a rules project that sits directly inside its solution folder, as 'uip rules init' creates it.");
157
+ }
158
+ }
159
+ async function loggedInContext(loginValidity) {
160
+ const auth = await getAuthContext({
161
+ ensureTokenValidityMinutes: loginValidity,
162
+ requireOrganizationId: true,
163
+ requireOrganizationName: true,
164
+ requireTenantName: true
165
+ });
166
+ return {
167
+ config: {
168
+ baseUrl: auth.baseUrl,
169
+ organizationId: auth.organizationId,
170
+ tenantName: auth.tenantName,
171
+ tenantId: auth.tenantId,
172
+ authToken: auth.accessToken
173
+ },
174
+ organizationName: auth.organizationName
175
+ };
176
+ }
177
+ async function evaluationFolderKey(options) {
178
+ if (options.folderPath !== undefined || options.folderKey !== undefined) {
179
+ return (await resolveRequiredFolder2(options)).key;
180
+ }
181
+ const api = await createApiClient(PersonalWorkspacesApi, {});
182
+ const personal = await api.personalWorkspacesGetPersonalWorkspace();
183
+ if (!personal?.key) {
184
+ throw new RulesCommandError2("Could not find your personal workspace to run the rules engine in.", "invalid_argument", "Pass --folder-path <path> or --folder-key <key> to run in a folder you can read.");
185
+ }
186
+ return personal.key;
187
+ }
188
+ export {
189
+ debugRuleProjectAsync
190
+ };
191
+
192
+ //# debugId=D45024320EEC44A364756E2164756E21
@@ -0,0 +1,192 @@
1
+ import {
2
+ getAuthContext,
3
+ PersonalWorkspacesApi,
4
+ createApiClient
5
+ } from "./tool-n1d88ryb.js";
6
+ import {
7
+ getFileSystem,
8
+ catchError,
9
+ logger
10
+ } from "./tool-6rp0gx98.js";
11
+ import {
12
+ buildSolutionPackageFromDir,
13
+ uploadOrOverwriteSolution
14
+ } from "./tool-24mr6g8c.js";
15
+ import {
16
+ RulesCommandError2,
17
+ isJsonObject2
18
+ } from "./tool-rwp1skmf.js";
19
+ import {
20
+ assertOneFolderOption2,
21
+ resolveRequiredFolder2
22
+ } from "./tool-ketztpgf.js";
23
+ import {
24
+ findSolutionFile,
25
+ updateSolutionFile
26
+ } from "./tool-q3c1bjyb.js";
27
+ import {
28
+ readRulesProjectNameAsync
29
+ } from "./tool-k2s349kn.js";
30
+
31
+ // src/services/rules-engine-client.ts
32
+ var DEBUG_EVALUATE_PATH = "/v1/business-rules/debug/evaluate";
33
+ var DEFAULT_TIMEOUT_SECONDS = 120;
34
+
35
+ class RulesEngineHttpError extends Error {
36
+ status;
37
+ constructor(status, message) {
38
+ super(message);
39
+ this.status = status;
40
+ this.name = "RulesEngineHttpError";
41
+ }
42
+ }
43
+ async function assertBusinessRulesServiceAsync(config, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
44
+ const [error] = await catchError(postDebugEvaluate(config, {}, timeoutSeconds));
45
+ if (error && !(error instanceof RulesEngineHttpError && error.status === 400)) {
46
+ throw error;
47
+ }
48
+ }
49
+ async function evaluateRuleDebugAsync(config, request, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
50
+ return postDebugEvaluate(config, request, timeoutSeconds);
51
+ }
52
+ async function postDebugEvaluate(config, request, timeoutSeconds) {
53
+ const url = `${config.baseUrl}/${encodeURIComponent(config.organizationId)}/${encodeURIComponent(config.tenantName)}/businessrules_${DEBUG_EVALUATE_PATH}`;
54
+ const [fetchError, response] = await catchError(fetch(url, {
55
+ method: "POST",
56
+ headers: {
57
+ Authorization: `Bearer ${config.authToken}`,
58
+ Accept: "application/json",
59
+ "Content-Type": "application/json",
60
+ ...config.folderKey ? { "x-uipath-folderkey": config.folderKey } : {}
61
+ },
62
+ body: JSON.stringify(request),
63
+ signal: AbortSignal.timeout(timeoutSeconds * 1000)
64
+ }));
65
+ if (fetchError?.name === "TimeoutError") {
66
+ throw new RulesCommandError2(`The rules engine did not answer within ${timeoutSeconds} seconds.`, "timeout", "Run the command again, or pass a larger --timeout.", "RetryLater");
67
+ }
68
+ if (fetchError) {
69
+ throw fetchError;
70
+ }
71
+ if (!response.ok) {
72
+ throw await engineFailure(response, config.tenantName);
73
+ }
74
+ return await response.json();
75
+ }
76
+ async function engineFailure(response, tenantName) {
77
+ const text = await response.text().catch(() => "");
78
+ if (response.status === 404 && /Service: businessrules not found in Organization/i.test(text)) {
79
+ return new RulesCommandError2(`Business Rules is not enabled on tenant '${tenantName}'.`, "configuration_error", "Ask your UiPath contact to enable Business Rules for this tenant, or switch to a tenant that has it with 'uip login tenant set <tenant-name>'.");
80
+ }
81
+ const [, body] = catchError(() => JSON.parse(text));
82
+ const error = isJsonObject2(body) && isJsonObject2(body.error) ? body.error : {};
83
+ if (error.code === "STUDIO_FORBIDDEN") {
84
+ return new RulesCommandError2("Studio Web did not let the rules engine read the uploaded project.", "permission_denied", "Check in Studio Web that your account can open the uploaded solution.");
85
+ }
86
+ const message = typeof error.message === "string" ? error.message : "The rules engine request failed.";
87
+ return new RulesEngineHttpError(response.status, typeof error.code === "string" ? `${message} (${error.code})` : message);
88
+ }
89
+
90
+ // src/services/rules-debug-service.ts
91
+ async function debugRuleProjectAsync(projectPath, options) {
92
+ assertOneFolderOption2(options);
93
+ const inputs = [{ id: "1", data: await parseInput(options.inputs) }];
94
+ const fs = getFileSystem();
95
+ const projectDir = fs.path.resolve(projectPath);
96
+ const projectName = await readRulesProjectName(projectDir);
97
+ const solutionDir = fs.path.resolve(projectDir, "..");
98
+ await assertSolutionFolder(solutionDir);
99
+ const { config, organizationName } = await loggedInContext(options.loginValidity);
100
+ await assertBusinessRulesServiceAsync(config, options.timeout);
101
+ const folderKey = await evaluationFolderKey(options);
102
+ const existingSolutionId = (await findSolutionFile(fs, projectDir))?.solutionId;
103
+ logger.info(`Uploading the solution of '${projectName}' to Studio Web...`);
104
+ const uisPath = await buildSolutionPackageFromDir(fs, solutionDir);
105
+ const [uploadError, upload] = await catchError(uploadOrOverwriteSolution(config, organizationName, uisPath, existingSolutionId, fs));
106
+ await fs.rm(uisPath).catch(() => {
107
+ return;
108
+ });
109
+ if (uploadError) {
110
+ throw uploadError;
111
+ }
112
+ if (upload.id !== existingSolutionId) {
113
+ await updateSolutionFile(fs, projectDir, upload.id);
114
+ }
115
+ const project = upload.projects.find((p) => p.name === projectName);
116
+ if (!project) {
117
+ throw new RulesCommandError2(`Studio Web returned no project named '${projectName}' for the uploaded solution.`, "not_found", "Check that the project is listed in the solution's .uipx, then run the command again.");
118
+ }
119
+ logger.info(`Evaluating against Studio Web project ${project.id}...`);
120
+ const response = await evaluateRuleDebugAsync({ ...config, folderKey }, { projectId: project.id, explain: options.explain, inputs }, options.timeout);
121
+ return {
122
+ solutionId: upload.id,
123
+ projectId: project.id,
124
+ studioWebUrl: studioWebDesignerUrl(config.baseUrl, organizationName, project.id, upload.id),
125
+ response
126
+ };
127
+ }
128
+ async function parseInput(raw) {
129
+ if (raw === undefined || raw === "") {
130
+ return {};
131
+ }
132
+ const filePath = raw.startsWith("@") ? raw.slice(1) : undefined;
133
+ const [readError, text] = filePath === undefined ? [undefined, raw] : await catchError(getFileSystem().readFile(filePath, "utf-8"));
134
+ if (readError || text === null) {
135
+ throw new RulesCommandError2(`Input file '${filePath}' could not be read: ${readError?.message ?? "file not found"}.`, "invalid_argument", "Pass --inputs as a JSON object or @file.json pointing at an existing file.");
136
+ }
137
+ const [parseError, parsed] = catchError(() => JSON.parse(text));
138
+ if (parseError || !isJsonObject2(parsed)) {
139
+ throw new RulesCommandError2(parseError ? `--inputs is not valid JSON: ${parseError.message}` : "--inputs must be a JSON object of input values.", "invalid_argument", `Pass --inputs '{"<input>": <value>}' or @file.json holding one such object.`);
140
+ }
141
+ return parsed;
142
+ }
143
+ function studioWebDesignerUrl(baseUrl, organizationName, projectId, solutionId) {
144
+ return `${baseUrl}/${encodeURIComponent(organizationName)}/studio_/designer/${encodeURIComponent(projectId)}?solutionId=${encodeURIComponent(solutionId)}`;
145
+ }
146
+ async function readRulesProjectName(projectDir) {
147
+ const name = await readRulesProjectNameAsync(projectDir);
148
+ if (!name) {
149
+ throw new RulesCommandError2(`${projectDir}/project.uiproj has no Name.`, "invalid_argument", "Set Name in project.uiproj to the rules project's name, as 'uip rules init' writes it.");
150
+ }
151
+ return name;
152
+ }
153
+ async function assertSolutionFolder(solutionDir) {
154
+ const [, entries] = await catchError(getFileSystem().readdir(solutionDir));
155
+ if (!entries?.some((entry) => entry.endsWith(".uipx"))) {
156
+ throw new RulesCommandError2(`${solutionDir} holds no .uipx, so the rules project is not inside a solution.`, "invalid_argument", "Pass a rules project that sits directly inside its solution folder, as 'uip rules init' creates it.");
157
+ }
158
+ }
159
+ async function loggedInContext(loginValidity) {
160
+ const auth = await getAuthContext({
161
+ ensureTokenValidityMinutes: loginValidity,
162
+ requireOrganizationId: true,
163
+ requireOrganizationName: true,
164
+ requireTenantName: true
165
+ });
166
+ return {
167
+ config: {
168
+ baseUrl: auth.baseUrl,
169
+ organizationId: auth.organizationId,
170
+ tenantName: auth.tenantName,
171
+ tenantId: auth.tenantId,
172
+ authToken: auth.accessToken
173
+ },
174
+ organizationName: auth.organizationName
175
+ };
176
+ }
177
+ async function evaluationFolderKey(options) {
178
+ if (options.folderPath !== undefined || options.folderKey !== undefined) {
179
+ return (await resolveRequiredFolder2(options)).key;
180
+ }
181
+ const api = await createApiClient(PersonalWorkspacesApi, {});
182
+ const personal = await api.personalWorkspacesGetPersonalWorkspace();
183
+ if (!personal?.key) {
184
+ throw new RulesCommandError2("Could not find your personal workspace to run the rules engine in.", "invalid_argument", "Pass --folder-path <path> or --folder-key <key> to run in a folder you can read.");
185
+ }
186
+ return personal.key;
187
+ }
188
+ export {
189
+ debugRuleProjectAsync
190
+ };
191
+
192
+ //# debugId=D45024320EEC44A364756E2164756E21