@uipath/rules-tool 0.0.0-stage → 1.204.0-preview.250
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +3 -0
- package/README.md +80 -2
- package/dist/DmnFactory-VWZOSZHH-jkpbxz3n.js +42 -0
- package/dist/DmnModelTypes-ATR7FVKZ-jp35cecy.js +18 -0
- package/dist/KieDmnMarshaller-6TTUU5B4-47q50gk4.js +20 -0
- package/dist/THIRD-PARTY-NOTICES.md +1054 -0
- package/dist/business-rules-bnr581tz.js +26 -0
- package/dist/constants-9pa118cj.js +29 -0
- package/dist/embedded-file-reader-rf2g1kfj.js +114 -0
- package/dist/first-party-service-sd8yaf73.js +27 -0
- package/dist/hitPolicyResult-4WDHTX4A-gk103w84.js +33 -0
- package/dist/index-2hzp9b97.js +116 -0
- package/dist/index-34pj9f36.js +48 -0
- package/dist/index-4c4exdzw.js +3035 -0
- package/dist/index-dqa169gp.js +25 -0
- package/dist/index-fs1nd5ap.js +200 -0
- package/dist/index-sby22td6.js +634 -0
- package/dist/index-t4mx1a5e.js +17 -0
- package/dist/index.js +17 -0
- package/dist/jmespath-231m3hyn.js +1485 -0
- package/dist/js-yaml-88tdqrtd.js +3153 -0
- package/dist/rule-catalog-5gzpe93c.js +46 -0
- package/dist/rules-command-error-20gp2dv9.js +14 -0
- package/dist/rules-debug-service-cmgmbhyh.js +193 -0
- package/dist/rules-init-service-b74thek5.js +104 -0
- package/dist/rules-refresh-service-jgk2kq9d.js +66 -0
- package/dist/rules-validate-service-mr2fk58k.js +63 -0
- package/dist/tool-19b4ect0.js +754 -0
- package/dist/tool-1de529jm.js +39 -0
- package/dist/tool-2cky8jwp.js +17878 -0
- package/dist/tool-4dfpdepw.js +55 -0
- package/dist/tool-53w8skv5.js +262 -0
- package/dist/tool-7haj67tr.js +19 -0
- package/dist/tool-8h4er38s.js +11063 -0
- package/dist/tool-8qy8pkp4.js +40 -0
- package/dist/tool-av4mmsef.js +73 -0
- package/dist/tool-eymjx05p.js +6396 -0
- package/dist/tool-gdtpsdn7.js +342 -0
- package/dist/tool-jd313s2x.js +10 -0
- package/dist/tool-jxvk6306.js +574 -0
- package/dist/tool-m41px07w.js +49 -0
- package/dist/tool-mkn83w88.js +111 -0
- package/dist/tool-pm3ewdxc.js +1115 -0
- package/dist/tool-qgqscsjc.js +46 -0
- package/dist/tool-tkcx6png.js +6558 -0
- package/dist/tool-wmh645tm.js +4022 -0
- package/dist/tool-x0z7hxqr.js +916 -0
- package/dist/tool.js +12 -0
- package/package.json +30 -5
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createResourceBuilderServices,
|
|
3
|
+
exportResourceDefinitionAsync,
|
|
4
|
+
findCatalogEntityAsync,
|
|
5
|
+
getRemoteResourceClients,
|
|
6
|
+
getSolutionAuthContext,
|
|
7
|
+
readSpecEntryPoints,
|
|
8
|
+
toResourceReference
|
|
9
|
+
} from "./tool-2cky8jwp.js";
|
|
10
|
+
import"./tool-gdtpsdn7.js";
|
|
11
|
+
import"./tool-53w8skv5.js";
|
|
12
|
+
import"./tool-pm3ewdxc.js";
|
|
13
|
+
import {
|
|
14
|
+
ruleNotFound
|
|
15
|
+
} from "./tool-av4mmsef.js";
|
|
16
|
+
import"./tool-eymjx05p.js";
|
|
17
|
+
import {
|
|
18
|
+
RulesCommandError
|
|
19
|
+
} from "./tool-8qy8pkp4.js";
|
|
20
|
+
import"./tool-tkcx6png.js";
|
|
21
|
+
import"./tool-1de529jm.js";
|
|
22
|
+
|
|
23
|
+
// src/services/rule-catalog.ts
|
|
24
|
+
var BUSINESS_RULE_ENTITY_TYPE = "BusinessRule";
|
|
25
|
+
async function describeRuleAsync(name, folder) {
|
|
26
|
+
await getSolutionAuthContext({});
|
|
27
|
+
const { catalog, importer } = getRemoteResourceClients(await createResourceBuilderServices());
|
|
28
|
+
const entity = await findCatalogEntityAsync(catalog, { name, entityTypes: [BUSINESS_RULE_ENTITY_TYPE] }, (e) => e.entityName?.toLowerCase() === name.toLowerCase() && e.folderKey?.toLowerCase() === folder.key.toLowerCase());
|
|
29
|
+
if (!entity?.entityKey) {
|
|
30
|
+
throw ruleNotFound(name, folder);
|
|
31
|
+
}
|
|
32
|
+
const definition = await exportResourceDefinitionAsync(importer, toResourceReference(entity));
|
|
33
|
+
return readEntryPoints(definition?.spec, name);
|
|
34
|
+
}
|
|
35
|
+
function readEntryPoints(spec, name) {
|
|
36
|
+
const entryPoints = readSpecEntryPoints(spec);
|
|
37
|
+
if (!entryPoints) {
|
|
38
|
+
throw new RulesCommandError(`Business rule '${name}' has no argument contract on its resource.`, "configuration_error", "Redeploy the rule from its solution with 'uip solution publish' and 'uip solution deploy run' so its package carries entry-points.json. If it still has no contract, contact your tenant administrator.");
|
|
39
|
+
}
|
|
40
|
+
return entryPoints;
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
describeRuleAsync
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//# debugId=973D0BB53E2ADF1A64756E2164756E21
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RulesCommandError,
|
|
3
|
+
isJsonObject,
|
|
4
|
+
reportRulesFailure
|
|
5
|
+
} from "./tool-8qy8pkp4.js";
|
|
6
|
+
import"./tool-tkcx6png.js";
|
|
7
|
+
import"./tool-1de529jm.js";
|
|
8
|
+
export {
|
|
9
|
+
RulesCommandError,
|
|
10
|
+
isJsonObject,
|
|
11
|
+
reportRulesFailure
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//# debugId=B037763673F7A89264756E2164756E21
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildSolutionPackageFromDir,
|
|
3
|
+
uploadOrOverwriteSolution
|
|
4
|
+
} from "./tool-x0z7hxqr.js";
|
|
5
|
+
import {
|
|
6
|
+
findSolutionFile,
|
|
7
|
+
updateSolutionFile
|
|
8
|
+
} from "./tool-pm3ewdxc.js";
|
|
9
|
+
import {
|
|
10
|
+
readRulesProjectNameAsync
|
|
11
|
+
} from "./tool-mkn83w88.js";
|
|
12
|
+
import {
|
|
13
|
+
assertOneFolderOption,
|
|
14
|
+
resolveRequiredFolder
|
|
15
|
+
} from "./tool-av4mmsef.js";
|
|
16
|
+
import {
|
|
17
|
+
PersonalWorkspacesApi,
|
|
18
|
+
createApiClient,
|
|
19
|
+
getAuthContext
|
|
20
|
+
} from "./tool-eymjx05p.js";
|
|
21
|
+
import {
|
|
22
|
+
RulesCommandError,
|
|
23
|
+
isJsonObject
|
|
24
|
+
} from "./tool-8qy8pkp4.js";
|
|
25
|
+
import {
|
|
26
|
+
catchError,
|
|
27
|
+
getFileSystem,
|
|
28
|
+
logger
|
|
29
|
+
} from "./tool-tkcx6png.js";
|
|
30
|
+
import"./tool-1de529jm.js";
|
|
31
|
+
|
|
32
|
+
// src/services/rules-engine-client.ts
|
|
33
|
+
var DEBUG_EVALUATE_PATH = "/v1/business-rules/debug/evaluate";
|
|
34
|
+
var DEFAULT_TIMEOUT_SECONDS = 120;
|
|
35
|
+
|
|
36
|
+
class RulesEngineHttpError extends Error {
|
|
37
|
+
status;
|
|
38
|
+
constructor(status, message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.name = "RulesEngineHttpError";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function assertBusinessRulesServiceAsync(config, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
|
|
45
|
+
const [error] = await catchError(postDebugEvaluate(config, {}, timeoutSeconds));
|
|
46
|
+
if (error && !(error instanceof RulesEngineHttpError && error.status === 400)) {
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function evaluateRuleDebugAsync(config, request, timeoutSeconds = DEFAULT_TIMEOUT_SECONDS) {
|
|
51
|
+
return postDebugEvaluate(config, request, timeoutSeconds);
|
|
52
|
+
}
|
|
53
|
+
async function postDebugEvaluate(config, request, timeoutSeconds) {
|
|
54
|
+
const url = `${config.baseUrl}/${encodeURIComponent(config.organizationId)}/${encodeURIComponent(config.tenantName)}/businessrules_${DEBUG_EVALUATE_PATH}`;
|
|
55
|
+
const [fetchError, response] = await catchError(fetch(url, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
headers: {
|
|
58
|
+
Authorization: `Bearer ${config.authToken}`,
|
|
59
|
+
Accept: "application/json",
|
|
60
|
+
"Content-Type": "application/json",
|
|
61
|
+
...config.folderKey ? { "x-uipath-folderkey": config.folderKey } : {}
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify(request),
|
|
64
|
+
signal: AbortSignal.timeout(timeoutSeconds * 1000)
|
|
65
|
+
}));
|
|
66
|
+
if (fetchError?.name === "TimeoutError") {
|
|
67
|
+
throw new RulesCommandError(`The rules engine did not answer within ${timeoutSeconds} seconds.`, "timeout", "Run the command again, or pass a larger --timeout.", "RetryLater");
|
|
68
|
+
}
|
|
69
|
+
if (fetchError) {
|
|
70
|
+
throw fetchError;
|
|
71
|
+
}
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw await engineFailure(response, config.tenantName);
|
|
74
|
+
}
|
|
75
|
+
return await response.json();
|
|
76
|
+
}
|
|
77
|
+
async function engineFailure(response, tenantName) {
|
|
78
|
+
const text = await response.text().catch(() => "");
|
|
79
|
+
if (response.status === 404 && /Service: businessrules not found in Organization/i.test(text)) {
|
|
80
|
+
return new RulesCommandError(`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>'.");
|
|
81
|
+
}
|
|
82
|
+
const [, body] = catchError(() => JSON.parse(text));
|
|
83
|
+
const error = isJsonObject(body) && isJsonObject(body.error) ? body.error : {};
|
|
84
|
+
if (error.code === "STUDIO_FORBIDDEN") {
|
|
85
|
+
return new RulesCommandError("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.");
|
|
86
|
+
}
|
|
87
|
+
const message = typeof error.message === "string" ? error.message : "The rules engine request failed.";
|
|
88
|
+
return new RulesEngineHttpError(response.status, typeof error.code === "string" ? `${message} (${error.code})` : message);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/services/rules-debug-service.ts
|
|
92
|
+
async function debugRuleProjectAsync(projectPath, options) {
|
|
93
|
+
assertOneFolderOption(options);
|
|
94
|
+
const inputs = [{ id: "1", data: await parseInput(options.inputs) }];
|
|
95
|
+
const fs = getFileSystem();
|
|
96
|
+
const projectDir = fs.path.resolve(projectPath);
|
|
97
|
+
const projectName = await readRulesProjectName(projectDir);
|
|
98
|
+
const solutionDir = fs.path.resolve(projectDir, "..");
|
|
99
|
+
await assertSolutionFolder(solutionDir);
|
|
100
|
+
const { config, organizationName } = await loggedInContext(options.loginValidity);
|
|
101
|
+
await assertBusinessRulesServiceAsync(config, options.timeout);
|
|
102
|
+
const folderKey = await evaluationFolderKey(options);
|
|
103
|
+
const existingSolutionId = (await findSolutionFile(fs, projectDir))?.solutionId;
|
|
104
|
+
logger.info(`Uploading the solution of '${projectName}' to Studio Web...`);
|
|
105
|
+
const uisPath = await buildSolutionPackageFromDir(fs, solutionDir);
|
|
106
|
+
const [uploadError, upload] = await catchError(uploadOrOverwriteSolution(config, organizationName, uisPath, existingSolutionId, fs));
|
|
107
|
+
await fs.rm(uisPath).catch(() => {
|
|
108
|
+
return;
|
|
109
|
+
});
|
|
110
|
+
if (uploadError) {
|
|
111
|
+
throw uploadError;
|
|
112
|
+
}
|
|
113
|
+
if (upload.id !== existingSolutionId) {
|
|
114
|
+
await updateSolutionFile(fs, projectDir, upload.id);
|
|
115
|
+
}
|
|
116
|
+
const project = upload.projects.find((p) => p.name === projectName);
|
|
117
|
+
if (!project) {
|
|
118
|
+
throw new RulesCommandError(`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.");
|
|
119
|
+
}
|
|
120
|
+
logger.info(`Evaluating against Studio Web project ${project.id}...`);
|
|
121
|
+
const response = await evaluateRuleDebugAsync({ ...config, folderKey }, { projectId: project.id, explain: options.explain, inputs }, options.timeout);
|
|
122
|
+
return {
|
|
123
|
+
solutionId: upload.id,
|
|
124
|
+
projectId: project.id,
|
|
125
|
+
studioWebUrl: studioWebDesignerUrl(config.baseUrl, organizationName, project.id, upload.id),
|
|
126
|
+
response
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async function parseInput(raw) {
|
|
130
|
+
if (raw === undefined || raw === "") {
|
|
131
|
+
return {};
|
|
132
|
+
}
|
|
133
|
+
const filePath = raw.startsWith("@") ? raw.slice(1) : undefined;
|
|
134
|
+
const [readError, text] = filePath === undefined ? [undefined, raw] : await catchError(getFileSystem().readFile(filePath, "utf-8"));
|
|
135
|
+
if (readError || text === null) {
|
|
136
|
+
throw new RulesCommandError(`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.");
|
|
137
|
+
}
|
|
138
|
+
const [parseError, parsed] = catchError(() => JSON.parse(text));
|
|
139
|
+
if (parseError || !isJsonObject(parsed)) {
|
|
140
|
+
throw new RulesCommandError(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.`);
|
|
141
|
+
}
|
|
142
|
+
return parsed;
|
|
143
|
+
}
|
|
144
|
+
function studioWebDesignerUrl(baseUrl, organizationName, projectId, solutionId) {
|
|
145
|
+
return `${baseUrl}/${encodeURIComponent(organizationName)}/studio_/designer/${encodeURIComponent(projectId)}?solutionId=${encodeURIComponent(solutionId)}`;
|
|
146
|
+
}
|
|
147
|
+
async function readRulesProjectName(projectDir) {
|
|
148
|
+
const name = await readRulesProjectNameAsync(projectDir);
|
|
149
|
+
if (!name) {
|
|
150
|
+
throw new RulesCommandError(`${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.");
|
|
151
|
+
}
|
|
152
|
+
return name;
|
|
153
|
+
}
|
|
154
|
+
async function assertSolutionFolder(solutionDir) {
|
|
155
|
+
const [, entries] = await catchError(getFileSystem().readdir(solutionDir));
|
|
156
|
+
if (!entries?.some((entry) => entry.endsWith(".uipx"))) {
|
|
157
|
+
throw new RulesCommandError(`${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.");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function loggedInContext(loginValidity) {
|
|
161
|
+
const auth = await getAuthContext({
|
|
162
|
+
ensureTokenValidityMinutes: loginValidity,
|
|
163
|
+
requireOrganizationId: true,
|
|
164
|
+
requireOrganizationName: true,
|
|
165
|
+
requireTenantName: true
|
|
166
|
+
});
|
|
167
|
+
return {
|
|
168
|
+
config: {
|
|
169
|
+
baseUrl: auth.baseUrl,
|
|
170
|
+
organizationId: auth.organizationId,
|
|
171
|
+
tenantName: auth.tenantName,
|
|
172
|
+
tenantId: auth.tenantId,
|
|
173
|
+
authToken: auth.accessToken
|
|
174
|
+
},
|
|
175
|
+
organizationName: auth.organizationName
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async function evaluationFolderKey(options) {
|
|
179
|
+
if (options.folderPath !== undefined || options.folderKey !== undefined) {
|
|
180
|
+
return (await resolveRequiredFolder(options)).key;
|
|
181
|
+
}
|
|
182
|
+
const api = await createApiClient(PersonalWorkspacesApi, {});
|
|
183
|
+
const personal = await api.personalWorkspacesGetPersonalWorkspace();
|
|
184
|
+
if (!personal?.key) {
|
|
185
|
+
throw new RulesCommandError("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.");
|
|
186
|
+
}
|
|
187
|
+
return personal.key;
|
|
188
|
+
}
|
|
189
|
+
export {
|
|
190
|
+
debugRuleProjectAsync
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
//# debugId=176F4486C7DFBCBB64756E2164756E21
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import"./tool-x0z7hxqr.js";
|
|
2
|
+
import {
|
|
3
|
+
prepareProjectLocation,
|
|
4
|
+
tryRegisterProjectInParentSolution
|
|
5
|
+
} from "./tool-pm3ewdxc.js";
|
|
6
|
+
import {
|
|
7
|
+
BINDINGS_FILE,
|
|
8
|
+
ENTRY_POINTS_FILE,
|
|
9
|
+
buildRuleEntryPointsAsync
|
|
10
|
+
} from "./tool-mkn83w88.js";
|
|
11
|
+
import"./tool-8qy8pkp4.js";
|
|
12
|
+
import {
|
|
13
|
+
catchError,
|
|
14
|
+
getFileSystem
|
|
15
|
+
} from "./tool-tkcx6png.js";
|
|
16
|
+
import {
|
|
17
|
+
__require
|
|
18
|
+
} from "./tool-1de529jm.js";
|
|
19
|
+
|
|
20
|
+
// src/services/project-artifacts.ts
|
|
21
|
+
async function ensureProjectArtifacts(args) {
|
|
22
|
+
const { addProjectArtifactsToSolutionAsync } = await import("./index-2hzp9b97.js");
|
|
23
|
+
return addProjectArtifactsToSolutionAsync(args);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/services/rules-init-service.ts
|
|
27
|
+
var VALID_PROJECT_NAME_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
28
|
+
var SEEDED_DMN_FILE = "Business rule.dmn";
|
|
29
|
+
var formatJson = (value) => `${JSON.stringify(value, null, 2)}
|
|
30
|
+
`;
|
|
31
|
+
async function createSeededRuleFilesAsync(ruleName) {
|
|
32
|
+
const { createNewBusinessRuleDmn } = await import("./constants-9pa118cj.js");
|
|
33
|
+
const dmn = createNewBusinessRuleDmn();
|
|
34
|
+
const packaging = await buildRuleEntryPointsAsync([{ name: SEEDED_DMN_FILE, contents: dmn }], undefined, ruleName);
|
|
35
|
+
return {
|
|
36
|
+
[SEEDED_DMN_FILE]: dmn,
|
|
37
|
+
[ENTRY_POINTS_FILE]: packaging.entryPointsContent,
|
|
38
|
+
[BINDINGS_FILE]: packaging.bindingContent
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
var safeMkdir = async (fs, dir) => {
|
|
42
|
+
const [err] = await catchError(fs.mkdir(dir));
|
|
43
|
+
if (err && !(("code" in err) && err.code === "EEXIST")) {
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
async function rulesInitAsync(name, options = {}) {
|
|
48
|
+
if (!VALID_PROJECT_NAME_REGEX.test(name)) {
|
|
49
|
+
throw new Error(`Invalid project name "${name}". Name can only contain letters, numbers, underscores (_), and hyphens (-).`);
|
|
50
|
+
}
|
|
51
|
+
const fs = getFileSystem();
|
|
52
|
+
const { projectDir, autoCreatedSolution } = await prepareProjectLocation(fs, fs.path.resolve(name), name, { skipRegistration: options.skipRegistration });
|
|
53
|
+
const [statError] = await catchError(fs.stat(projectDir));
|
|
54
|
+
const projectDirExists = !statError;
|
|
55
|
+
if (statError && !(("code" in statError) && (statError.code === "ENOENT" || statError.code === "PathNotFound"))) {
|
|
56
|
+
throw statError;
|
|
57
|
+
}
|
|
58
|
+
if (projectDirExists && !options.force) {
|
|
59
|
+
const existingEntries = await fs.readdir(projectDir);
|
|
60
|
+
if (existingEntries.length > 0) {
|
|
61
|
+
throw new Error(`Directory "${name}" already exists and is not empty. Use --force to overwrite.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
await safeMkdir(fs, projectDir);
|
|
65
|
+
const ruleExists = (await fs.readdir(projectDir)).some((entry) => entry.toLowerCase().endsWith(".dmn"));
|
|
66
|
+
const projectFiles = {
|
|
67
|
+
"project.uiproj": formatJson({
|
|
68
|
+
Name: name,
|
|
69
|
+
ProjectType: "BusinessRules"
|
|
70
|
+
}),
|
|
71
|
+
...ruleExists ? {} : await createSeededRuleFilesAsync(name)
|
|
72
|
+
};
|
|
73
|
+
for (const [fileName, content] of Object.entries(projectFiles)) {
|
|
74
|
+
await fs.writeFile(fs.path.join(projectDir, fileName), content);
|
|
75
|
+
}
|
|
76
|
+
const registration = await tryRegisterProjectInParentSolution(fs, projectDir, { skipRegistration: options.skipRegistration });
|
|
77
|
+
const projectArtifacts = await maybeGenerateProjectArtifacts(registration, name);
|
|
78
|
+
return {
|
|
79
|
+
projectName: name,
|
|
80
|
+
projectDir,
|
|
81
|
+
registration,
|
|
82
|
+
autoCreatedSolution,
|
|
83
|
+
projectArtifacts,
|
|
84
|
+
ruleStatus: ruleExists ? "Preserved" : "Created"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function maybeGenerateProjectArtifacts(registration, projectName) {
|
|
88
|
+
if (registration.Status !== "Registered" && registration.Status !== "AlreadyRegistered" || !registration.Solution || !registration.ProjectId) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const fs = getFileSystem();
|
|
92
|
+
return ensureProjectArtifacts({
|
|
93
|
+
solutionDir: fs.path.dirname(registration.Solution),
|
|
94
|
+
projectId: registration.ProjectId,
|
|
95
|
+
projectName,
|
|
96
|
+
projectType: "BusinessRules"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
createSeededRuleFilesAsync,
|
|
101
|
+
rulesInitAsync
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
//# debugId=8300AFD86C3DD0AD64756E2164756E21
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BINDINGS_FILE,
|
|
3
|
+
ENTRY_POINTS_FILE,
|
|
4
|
+
buildRuleEntryPointsAsync,
|
|
5
|
+
readRuleProjectAsync
|
|
6
|
+
} from "./tool-mkn83w88.js";
|
|
7
|
+
import {
|
|
8
|
+
RulesCommandError
|
|
9
|
+
} from "./tool-8qy8pkp4.js";
|
|
10
|
+
import {
|
|
11
|
+
catchError,
|
|
12
|
+
extractErrorMessageSync,
|
|
13
|
+
getFileSystem
|
|
14
|
+
} from "./tool-tkcx6png.js";
|
|
15
|
+
import"./tool-1de529jm.js";
|
|
16
|
+
|
|
17
|
+
// src/services/rules-refresh-service.ts
|
|
18
|
+
async function refreshRuleProjectAsync(projectPath) {
|
|
19
|
+
const fs = getFileSystem();
|
|
20
|
+
const project = await readRuleProjectAsync(projectPath);
|
|
21
|
+
const packaging = await buildRuleEntryPointsAsync(project.dmnFiles, project.publishedEntryPoints, project.ruleName);
|
|
22
|
+
if (packaging.unreadable.length > 0) {
|
|
23
|
+
const names = packaging.unreadable.map((rule) => rule.name).join(", ");
|
|
24
|
+
const reasons = packaging.unreadable.map((rule) => `${rule.name}: ${extractErrorMessageSync(rule.error)}`).join(" ");
|
|
25
|
+
throw new RulesCommandError(`Could not read ${names}, so no package file was written. ${reasons}`, "invalid_argument", "Fix the .dmn file, or open the project in Studio Web to see what it rejects, then run 'uip rules refresh' again.");
|
|
26
|
+
}
|
|
27
|
+
const bindingsPath = fs.path.join(project.projectDir, BINDINGS_FILE);
|
|
28
|
+
const planned = [
|
|
29
|
+
{
|
|
30
|
+
name: ENTRY_POINTS_FILE,
|
|
31
|
+
content: packaging.entryPointsContent,
|
|
32
|
+
changed: packaging.entryPointsChanged
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: BINDINGS_FILE,
|
|
36
|
+
content: packaging.bindingContent,
|
|
37
|
+
changed: await fs.readFile(bindingsPath, "utf-8") !== packaging.bindingContent
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
await Promise.all(planned.filter((f) => f.changed).map((f) => writeFileAtomically(fs.path.join(project.projectDir, f.name), f.content)));
|
|
41
|
+
return {
|
|
42
|
+
projectDir: project.projectDir,
|
|
43
|
+
dmnFiles: project.dmnFiles.map((file) => file.name),
|
|
44
|
+
writtenFiles: planned.filter((f) => f.changed).map((f) => f.name),
|
|
45
|
+
unchangedFiles: planned.filter((f) => !f.changed).map((f) => f.name)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function writeFileAtomically(path, content) {
|
|
49
|
+
const fs = getFileSystem();
|
|
50
|
+
const staging = `${path}.${crypto.randomUUID()}.tmp`;
|
|
51
|
+
const [error] = await catchError((async () => {
|
|
52
|
+
await fs.writeFile(staging, content);
|
|
53
|
+
await fs.rename(staging, path);
|
|
54
|
+
})());
|
|
55
|
+
if (error) {
|
|
56
|
+
await fs.rm(staging).catch(() => {
|
|
57
|
+
return;
|
|
58
|
+
});
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
refreshRuleProjectAsync
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
//# debugId=9DC9E1E1A7863AFA64756E2164756E21
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ENTRY_POINTS_FILE,
|
|
3
|
+
buildRuleEntryPointsAsync,
|
|
4
|
+
readRuleProjectAsync
|
|
5
|
+
} from "./tool-mkn83w88.js";
|
|
6
|
+
import"./tool-8qy8pkp4.js";
|
|
7
|
+
import"./tool-tkcx6png.js";
|
|
8
|
+
import {
|
|
9
|
+
__require
|
|
10
|
+
} from "./tool-1de529jm.js";
|
|
11
|
+
|
|
12
|
+
// src/services/rules-validate-service.ts
|
|
13
|
+
async function validateRuleProjectAsync(projectPath) {
|
|
14
|
+
const project = await readRuleProjectAsync(projectPath);
|
|
15
|
+
const diagnostics = [];
|
|
16
|
+
for (const file of project.dmnFiles) {
|
|
17
|
+
diagnostics.push(...await validateDmnFileAsync(file));
|
|
18
|
+
}
|
|
19
|
+
const packaging = await buildRuleEntryPointsAsync(project.dmnFiles, project.publishedEntryPoints, project.ruleName);
|
|
20
|
+
if (packaging.unreadable.length === 0 && packaging.entryPointsChanged) {
|
|
21
|
+
diagnostics.push({
|
|
22
|
+
file: ENTRY_POINTS_FILE,
|
|
23
|
+
code: "RULES_ENTRY_POINTS_STALE",
|
|
24
|
+
severity: "error",
|
|
25
|
+
message: `${ENTRY_POINTS_FILE} does not match the rule's .dmn.`,
|
|
26
|
+
instructions: `Run 'uip rules refresh "${project.projectDir}"'; each published uniqueId is kept.`,
|
|
27
|
+
target: { kind: "document" }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
projectDir: project.projectDir,
|
|
32
|
+
dmnFiles: project.dmnFiles.map((file) => file.name),
|
|
33
|
+
diagnostics
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async function validateDmnFileAsync(file) {
|
|
37
|
+
const [
|
|
38
|
+
{ validateDmnDocument },
|
|
39
|
+
{ translateDmnDiagnostic },
|
|
40
|
+
{ importDmnDocument },
|
|
41
|
+
{ UnreadableDmnError }
|
|
42
|
+
] = await Promise.all([
|
|
43
|
+
import("./index-4c4exdzw.js"),
|
|
44
|
+
import("./index-t4mx1a5e.js"),
|
|
45
|
+
import("./index-34pj9f36.js"),
|
|
46
|
+
import("./index-fs1nd5ap.js")
|
|
47
|
+
]);
|
|
48
|
+
const diagnostics = await validateDmnDocument(file.contents);
|
|
49
|
+
const imported = diagnostics.some((d) => d.code === "DMN_DOCUMENT_UNREADABLE") ? await importDmnDocument(file.contents) : undefined;
|
|
50
|
+
const reason = imported?.status === "error" ? new UnreadableDmnError(imported.reason).message : undefined;
|
|
51
|
+
return diagnostics.map((diagnostic) => ({
|
|
52
|
+
file: file.name,
|
|
53
|
+
code: diagnostic.code,
|
|
54
|
+
severity: diagnostic.severity,
|
|
55
|
+
message: diagnostic.code === "DMN_DOCUMENT_UNREADABLE" && reason ? `${translateDmnDiagnostic(diagnostic)}: ${reason}` : translateDmnDiagnostic(diagnostic),
|
|
56
|
+
target: diagnostic.target
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
export {
|
|
60
|
+
validateRuleProjectAsync
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//# debugId=815CA3A34812F29264756E2164756E21
|