@uipath/packager-tool-case 1.205.0-preview.277 → 1.206.0-preview.279

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.
@@ -73,6 +73,25 @@ export declare const entryPointBpmnNames: (entryPointsJson: string) => string[]
73
73
  * compiles to is a project shipping its own, which is a supported shape.
74
74
  */
75
75
  export declare const misnamedEntryPointBpmn: (declared: readonly string[], casePlanFileName: string) => string | undefined;
76
+ /**
77
+ * The entry a staged package's operate.json `main` names, and where it came
78
+ * from: operate.json's own `main` when set, else entry-points.json's first
79
+ * entry, which is what pack scaffolds `main` from once the default entry
80
+ * point is listed first. `filePath` is "" when neither names one.
81
+ */
82
+ export declare const stagedMainEntryPoint: (operateJson: string | null | undefined, entryPointsJson: string) => {
83
+ filePath: string;
84
+ source: "operate.json" | "entry-points.json";
85
+ };
86
+ /**
87
+ * What to tell the author when the staged `main` resolves to `resolved`, a
88
+ * file that is not a declared `.bpmn` the project ships. `own` is the
89
+ * sidecar the case plan compiles to.
90
+ */
91
+ export declare const stagedMainProblem: (staged: ReturnType<typeof stagedMainEntryPoint>, resolved: string, own: string | undefined) => {
92
+ problem: string;
93
+ fix: string | undefined;
94
+ };
76
95
  /**
77
96
  * `package-descriptor.json` for a case package, naming whichever plan file
78
97
  * and `.bpmn` files the build actually produced.
@@ -0,0 +1,40 @@
1
+ import { type DefaultEntryPointParams, type IFileSystem } from "@uipath/solutionpackager-tool-core";
2
+ /** A case plan trigger node, with the entry point fields Studio Web reads from it. */
3
+ export interface CasePlanTrigger {
4
+ id: string;
5
+ label?: string;
6
+ entryPointId?: string;
7
+ isDefault: boolean;
8
+ }
9
+ /**
10
+ * The trigger nodes of a parsed case plan, in document order. A current
11
+ * `uipath.case.trigger` keeps its label under `data.display` and its fields
12
+ * under `data.inputs`; a legacy `case-management:Trigger` keeps its label on
13
+ * `data` and its fields under `data.uipath`, as Studio Web reads them, or under
14
+ * `data.inputs` in older files.
15
+ */
16
+ export declare function readCasePlanTriggers(plan: unknown): CasePlanTrigger[];
17
+ /**
18
+ * `entryPoints` with the plan's default flags: when a trigger in the plan is
19
+ * flagged default, the plan owns every flag, as a Studio Web publish orders
20
+ * from the plan, so only the entries naming a flagged trigger in its compiled
21
+ * BPMN keep one. A plan with no flagged trigger leaves the entries as they are.
22
+ *
23
+ * @throws {CasePlanDefaultNotListedError} when a flagged trigger has no entry,
24
+ * since the package could not start from it and another start would run.
25
+ */
26
+ export declare function withCasePlanDefaults<T extends {
27
+ filePath?: unknown;
28
+ isDefault?: unknown;
29
+ }>(entryPoints: readonly T[], plan: unknown, casePlanFileName: string): T[];
30
+ /** The case plan flags a trigger default that entry-points.json has no entry for. */
31
+ export declare class CasePlanDefaultNotListedError extends Error {
32
+ readonly triggerIds: readonly string[];
33
+ constructor(triggerIds: readonly string[]);
34
+ }
35
+ /**
36
+ * The `withDefaults` step `applyDefaultEntryPoint` takes for a staged case
37
+ * project: {@link withCasePlanDefaults} with the plan in `contentFolder`, or
38
+ * `undefined` when there is no plan to read.
39
+ */
40
+ export declare function casePlanDefaults(fs: IFileSystem, contentFolder: string): Promise<DefaultEntryPointParams["withDefaults"]>;
@@ -0,0 +1,22 @@
1
+ import type { CaseAppRole } from "./case-roles.js";
2
+ /** `value.name.defaultValue` of a `Role` entry, or `undefined` for anything else. */
3
+ export declare const roleBindingName: (entry: unknown) => string | undefined;
4
+ /**
5
+ * Make each `Role` entry join its role by name.
6
+ *
7
+ * `solution pack` finds the role resource of a `Role` binding by the name in
8
+ * `value.name.defaultValue`, and `bindings sync` writes the role's name there.
9
+ * Studio Web's publish writes the role resource's minted key instead, since its
10
+ * backend joins by key. A sidecar from Studio Web then names no resource, and
11
+ * the sync mints an empty role named after the key next to the real one, which
12
+ * deploy rejects.
13
+ *
14
+ * An entry is rewritten only when its name is not a role name and its
15
+ * `metadata.displayName` is one, which is what Studio Web writes for it. Every
16
+ * other entry, and every other field of a rewritten one, is left as it was.
17
+ * The input is not changed.
18
+ */
19
+ export declare const reconcileRoleBindings: (resources: readonly unknown[], roles: readonly Pick<CaseAppRole, "name">[]) => {
20
+ resources: unknown[];
21
+ changed: boolean;
22
+ };
@@ -0,0 +1,20 @@
1
+ import type { IFileSystem, ProjectResourceContribution } from "@uipath/solutionpackager-tool-core";
2
+ export declare const ROLE_RESOURCE_KIND = "role";
3
+ /**
4
+ * The type Studio Web stamps on a case-app role (`createVirtualResource({
5
+ * kind: "role", type: "case-role" })`) and filters on at publish. The SDK's
6
+ * `role` row is type-less, so the case side supplies it.
7
+ */
8
+ export declare const CASE_ROLE_RESOURCE_TYPE = "case-role";
9
+ /**
10
+ * The case side of the project resource contribution contract: one spec patch
11
+ * per role in `metadata.caseRoles`, targeting the `role` resource the
12
+ * project's `Role` binding mints at sync time.
13
+ *
14
+ * Permissions travel on the role resource and nowhere else — the package
15
+ * carries the binding, the binding carries the name, and `spec.actions` is
16
+ * what AuthZ reads. Studio Web writes it on publish (`materializeRoleResources`);
17
+ * this is the pack-time equivalent. Reads only files the case project owns and
18
+ * returns plain data (AGENTS.md Hard Rule #19).
19
+ */
20
+ export declare function describeCaseRoles(projectDir: string, fs: IFileSystem): Promise<ProjectResourceContribution>;
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Case-app roles (the "Personas" of a case) as `caseplan.json` carries them
3
+ * under `metadata.caseRoles`.
4
+ *
5
+ * Zero imports on purpose: every consumer — the case packager's resource
6
+ * contribution, `sdd convert`, the strict audit and `bindings sync` — reads
7
+ * this leaf, and nothing heavier should ride along with it.
8
+ *
9
+ * `@uipath/case-schema` owns the schema but does not export these names, so
10
+ * this is a copy. `case-roles.spec.ts` in `case-tool` pins the copy by running
11
+ * the schema package's validator over a plan that grants every key here.
12
+ */
13
+ /** Permission key, as an SDD names it → the literal the role resource carries. */
14
+ export declare const CASE_APP_ROLE_ACTIONS: {
15
+ readonly View: "CaseManagement.Cases.View";
16
+ readonly Create: "CaseManagement.Cases.Create";
17
+ readonly Edit: "CaseManagement.Cases.Edit";
18
+ readonly Close: "CaseManagement.Cases.Close";
19
+ readonly Reopen: "CaseManagement.Cases.Reopen";
20
+ readonly Assign: "CaseManagement.Cases.Assign";
21
+ readonly ManageSLA: "CaseManagement.Cases.ManageSLA";
22
+ readonly RunAdhocTasks: "CaseManagement.Cases.RunAdhocTasks";
23
+ readonly SelectStage: "CaseManagement.Cases.SelectStage";
24
+ readonly ViewSummary: "CaseManagement.Cases.ViewSummary";
25
+ readonly LogsView: "Orchestrator.Logs.View";
26
+ readonly TasksView: "Orchestrator.Tasks.View";
27
+ readonly TasksCreate: "Orchestrator.Tasks.Create";
28
+ readonly TasksEdit: "Orchestrator.Tasks.Edit";
29
+ readonly TasksDelete: "Orchestrator.Tasks.Delete";
30
+ readonly TaskAssignmentView: "Orchestrator.TaskAssignment.View";
31
+ readonly TaskAssignmentCreate: "Orchestrator.TaskAssignment.Create";
32
+ readonly TaskAssignmentEdit: "Orchestrator.TaskAssignment.Edit";
33
+ readonly TaskAssignmentDelete: "Orchestrator.TaskAssignment.Delete";
34
+ readonly TaskSelfAssignmentCreate: "Orchestrator.TaskSelfAssignment.Create";
35
+ readonly TaskSelfAssignmentEdit: "Orchestrator.TaskSelfAssignment.Edit";
36
+ readonly TaskSelfAssignmentDelete: "Orchestrator.TaskSelfAssignment.Delete";
37
+ };
38
+ /**
39
+ * Literals the schema still reads on a plan but no longer offers: Studio
40
+ * Web's dialog does not grant them and its validation ignores them. Kept on
41
+ * a role as written, never granted from an SDD.
42
+ */
43
+ export declare const LEGACY_CASE_APP_ROLE_ACTIONS: readonly string[];
44
+ export type CaseAppRoleActionKey = keyof typeof CASE_APP_ROLE_ACTIONS;
45
+ export type CaseAppRoleAction = (typeof CASE_APP_ROLE_ACTIONS)[CaseAppRoleActionKey];
46
+ /** Canonical order: the order the schema lists them, which is the persist order. */
47
+ export declare const CASE_APP_ROLE_ACTION_KEYS: readonly CaseAppRoleActionKey[];
48
+ /** The only permissions the backend can evaluate while a stage is active. */
49
+ export declare const STAGE_ALLOWED_ROLE_ACTION_KEYS: readonly CaseAppRoleActionKey[];
50
+ /**
51
+ * Permissions the Case Designer publishes only when a tenant feature flag is
52
+ * on (PO.Frontend `CaseRoleScopeUtil`, 4d7f567): with the flag off it strips
53
+ * them at publish. Both flags default to off. The CLI cannot read a tenant's
54
+ * flags at pack time, so it writes the grant as the SDD states it and
55
+ * reports it. The flag is the Designer's gate, not the server's: on alpha
56
+ * with both flags off (2026-10-15), deploy accepted every one of these and
57
+ * AuthZ created the roles with them at process scope, `Assign`,
58
+ * `Orchestrator.Tasks.View` and `Orchestrator.Logs.View` included.
59
+ */
60
+ export declare const TENANT_GATED_ROLE_ACTIONS: readonly {
61
+ flag: string;
62
+ keys: readonly CaseAppRoleActionKey[];
63
+ }[];
64
+ /** The tenant flag that gates a permission key, or `undefined` when none does. */
65
+ export declare const roleActionGateOf: (key: CaseAppRoleActionKey) => string | undefined;
66
+ export declare const CASE_ROLE_SCOPES: readonly ["case", "stages"];
67
+ export type CaseRoleScope = (typeof CASE_ROLE_SCOPES)[number];
68
+ export declare const CASE_ROLE_NAME_MAX_LENGTH = 64;
69
+ export declare const CASE_ROLE_DESCRIPTION_MAX_LENGTH = 500;
70
+ /** Characters the schema rejects in a role name. */
71
+ export declare const CASE_ROLE_NAME_FORBIDDEN: RegExp;
72
+ /** The case-app versions whose app has a roles model; `v1` has none. */
73
+ export declare const CASE_APP_VERSIONS_WITH_ROLES: readonly string[];
74
+ export interface CaseAppRole {
75
+ id: string;
76
+ name: string;
77
+ /** The role resource's `spec.description`. Deploy requires it non-empty. */
78
+ description?: string;
79
+ isDefault?: boolean;
80
+ /** As the plan stores them; {@link publishedRoleActions} is what deploys. */
81
+ actions: CaseAppRoleAction[];
82
+ scope: CaseRoleScope;
83
+ /** Stage node ids a `stages` role applies to. */
84
+ stageIds?: string[];
85
+ }
86
+ export declare const isLegacyRoleAction: (literal: string) => boolean;
87
+ /** The permission key a literal stands for, or `undefined` for a foreign or legacy one. */
88
+ export declare const roleActionKeyOf: (literal: string) => CaseAppRoleActionKey | undefined;
89
+ /**
90
+ * The permission key an SDD cell names, read without regard to case or the
91
+ * `CaseManagement.Cases.` prefix: `view`, `View` and
92
+ * `CaseManagement.Cases.View` all resolve to `View`.
93
+ */
94
+ export declare const roleActionKeyFor: (text: string) => CaseAppRoleActionKey | undefined;
95
+ /** Deploy's Customize step rejects an empty description, so the name stands in. */
96
+ export declare const roleDescriptionOf: (role: Pick<CaseAppRole, "name" | "description">) => string;
97
+ /**
98
+ * The plan's stage nodes, id → label. A stage with no label is left out:
99
+ * AuthZ scopes a stage role by the label, so an unlabelled stage cannot carry
100
+ * one, and falling back to the id would scope the role to a name no stage has.
101
+ */
102
+ export declare const caseStageLabels: (nodes: unknown) => Map<string, string>;
103
+ /** The role's stage ids that name a labelled stage of the plan, in the role's order. */
104
+ export declare const liveStageIdsOf: (role: Pick<CaseAppRole, "stageIds">, stages: ReadonlyMap<string, string>) => string[];
105
+ /**
106
+ * The actions a role deploys with: the list Studio Web's publish writes to
107
+ * the role resource's `spec.actions` (PO.Frontend `CaseRoleBindingsUtil`,
108
+ * 4d7f567), not the plan's as stored. A legacy literal is left out, as is,
109
+ * at `stages` scope, a permission the backend cannot evaluate while a stage
110
+ * is active. A tenant-gated permission stays: see
111
+ * {@link TENANT_GATED_ROLE_ACTIONS}.
112
+ */
113
+ export declare const publishedRoleActions: (role: Pick<CaseAppRole, "actions" | "scope">) => CaseAppRoleAction[];
114
+ /**
115
+ * Whether a role has anything to deploy: a permission its publish keeps
116
+ * ({@link publishedRoleActions}), and at `stages` scope a live stage. The one
117
+ * rule `bindings sync` and `solution pack` share, so pack never asks for a
118
+ * Role entry that sync will not write.
119
+ */
120
+ export declare const roleDeploys: (role: Pick<CaseAppRole, "actions" | "scope" | "stageIds">, stages: ReadonlyMap<string, string>) => boolean;
121
+ /**
122
+ * The name the solution stores a role resource under: the sync collapses
123
+ * virtual resources by case-folded name, so two roles that differ only by
124
+ * case would mint one resource. The schema itself keeps them apart.
125
+ */
126
+ export declare const roleResourceKey: (name: string) => string;
127
+ /** The fields of a role this module reads; anything else on an entry is the Designer's. */
128
+ export declare const CASE_ROLE_FIELDS: readonly string[];
129
+ /** The raw `metadata.caseRoles` entries of a plan, whatever their shape. */
130
+ export declare const caseRoleEntries: (plan: unknown) => unknown[];
131
+ /**
132
+ * One `metadata.caseRoles` entry as a role, or `undefined` when it lacks a
133
+ * name, a scope or an actions array: `case validate` reports those, and a
134
+ * contributor that guessed at them would mint a resource deploy then
135
+ * rejects. Foreign action literals are dropped; legacy ones are kept.
136
+ */
137
+ export declare const readCaseRole: (entry: unknown) => CaseAppRole | undefined;
138
+ /** `metadata.caseRoles` of a parsed plan, as far as each entry reads as a role. */
139
+ export declare const readCaseRoles: (plan: unknown) => CaseAppRole[];
@@ -0,0 +1,164 @@
1
+ // src/case-roles.ts
2
+ var CASE_APP_ROLE_ACTIONS = {
3
+ View: "CaseManagement.Cases.View",
4
+ Create: "CaseManagement.Cases.Create",
5
+ Edit: "CaseManagement.Cases.Edit",
6
+ Close: "CaseManagement.Cases.Close",
7
+ Reopen: "CaseManagement.Cases.Reopen",
8
+ Assign: "CaseManagement.Cases.Assign",
9
+ ManageSLA: "CaseManagement.Cases.ManageSLA",
10
+ RunAdhocTasks: "CaseManagement.Cases.RunAdhocTasks",
11
+ SelectStage: "CaseManagement.Cases.SelectStage",
12
+ ViewSummary: "CaseManagement.Cases.ViewSummary",
13
+ LogsView: "Orchestrator.Logs.View",
14
+ TasksView: "Orchestrator.Tasks.View",
15
+ TasksCreate: "Orchestrator.Tasks.Create",
16
+ TasksEdit: "Orchestrator.Tasks.Edit",
17
+ TasksDelete: "Orchestrator.Tasks.Delete",
18
+ TaskAssignmentView: "Orchestrator.TaskAssignment.View",
19
+ TaskAssignmentCreate: "Orchestrator.TaskAssignment.Create",
20
+ TaskAssignmentEdit: "Orchestrator.TaskAssignment.Edit",
21
+ TaskAssignmentDelete: "Orchestrator.TaskAssignment.Delete",
22
+ TaskSelfAssignmentCreate: "Orchestrator.TaskSelfAssignment.Create",
23
+ TaskSelfAssignmentEdit: "Orchestrator.TaskSelfAssignment.Edit",
24
+ TaskSelfAssignmentDelete: "Orchestrator.TaskSelfAssignment.Delete"
25
+ };
26
+ var LEGACY_CASE_APP_ROLE_ACTIONS = [
27
+ "CaseManagement.Cases.Manage"
28
+ ];
29
+ var CASE_APP_ROLE_ACTION_KEYS = Object.keys(CASE_APP_ROLE_ACTIONS);
30
+ var STAGE_ALLOWED_ROLE_ACTION_KEYS = [
31
+ "View",
32
+ "Assign",
33
+ "ManageSLA",
34
+ "RunAdhocTasks"
35
+ ];
36
+ var TENANT_GATED_ROLE_ACTIONS = [
37
+ { flag: "panel-enableCaseRoleAssign", keys: ["Assign"] },
38
+ {
39
+ flag: "panel-enableCaseRoleTaskPermissions",
40
+ keys: [
41
+ "TasksView",
42
+ "TasksCreate",
43
+ "TasksEdit",
44
+ "TasksDelete",
45
+ "TaskAssignmentView",
46
+ "TaskAssignmentCreate",
47
+ "TaskAssignmentEdit",
48
+ "TaskAssignmentDelete",
49
+ "TaskSelfAssignmentCreate",
50
+ "TaskSelfAssignmentEdit",
51
+ "TaskSelfAssignmentDelete"
52
+ ]
53
+ }
54
+ ];
55
+ var roleActionGateOf = (key) => TENANT_GATED_ROLE_ACTIONS.find((gate) => gate.keys.includes(key))?.flag;
56
+ var CASE_ROLE_SCOPES = ["case", "stages"];
57
+ var CASE_ROLE_NAME_MAX_LENGTH = 64;
58
+ var CASE_ROLE_DESCRIPTION_MAX_LENGTH = 500;
59
+ var CASE_ROLE_NAME_FORBIDDEN = /[<>"%;&']/;
60
+ var CASE_APP_VERSIONS_WITH_ROLES = ["v2", "custom"];
61
+ var ACTION_KEY_BY_LITERAL = new Map(CASE_APP_ROLE_ACTION_KEYS.map((key) => [CASE_APP_ROLE_ACTIONS[key], key]));
62
+ var ACTION_KEY_BY_FOLDED = new Map(CASE_APP_ROLE_ACTION_KEYS.map((key) => [key.toLowerCase(), key]));
63
+ var isLegacyRoleAction = (literal) => LEGACY_CASE_APP_ROLE_ACTIONS.includes(literal);
64
+ var roleActionKeyOf = (literal) => ACTION_KEY_BY_LITERAL.get(literal);
65
+ var roleActionKeyFor = (text) => {
66
+ const trimmed = text.trim();
67
+ return ACTION_KEY_BY_LITERAL.get(trimmed) ?? ACTION_KEY_BY_FOLDED.get(trimmed.toLowerCase());
68
+ };
69
+ var roleDescriptionOf = (role) => role.description?.trim() || role.name;
70
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
71
+ var STAGE_NODE_TYPE = "case-management:Stage";
72
+ var caseStageLabels = (nodes) => {
73
+ const labels = new Map;
74
+ for (const node of Array.isArray(nodes) ? nodes : []) {
75
+ if (!isRecord(node))
76
+ continue;
77
+ const { id, type, data } = node;
78
+ if (type !== STAGE_NODE_TYPE || typeof id !== "string")
79
+ continue;
80
+ const label = isRecord(data) ? data.label : undefined;
81
+ if (typeof label === "string" && label.trim() !== "") {
82
+ labels.set(id, label);
83
+ }
84
+ }
85
+ return labels;
86
+ };
87
+ var liveStageIdsOf = (role, stages) => (role.stageIds ?? []).filter((stageId) => stages.has(stageId));
88
+ var publishedRoleActions = (role) => role.actions.filter((action) => {
89
+ const key = roleActionKeyOf(action);
90
+ if (key === undefined)
91
+ return false;
92
+ return role.scope !== "stages" || STAGE_ALLOWED_ROLE_ACTION_KEYS.includes(key);
93
+ });
94
+ var roleDeploys = (role, stages) => publishedRoleActions(role).length > 0 && (role.scope !== "stages" || liveStageIdsOf(role, stages).length > 0);
95
+ var roleResourceKey = (name) => name.trim().toLowerCase();
96
+ var CASE_ROLE_FIELDS = [
97
+ "id",
98
+ "name",
99
+ "description",
100
+ "isDefault",
101
+ "actions",
102
+ "scope",
103
+ "stageIds"
104
+ ];
105
+ var caseRoleEntries = (plan) => {
106
+ if (!isRecord(plan) || !isRecord(plan.metadata))
107
+ return [];
108
+ const entries = plan.metadata.caseRoles;
109
+ return Array.isArray(entries) ? entries : [];
110
+ };
111
+ var readCaseRole = (entry) => {
112
+ if (!isRecord(entry))
113
+ return;
114
+ const { id, name, description, isDefault, actions, scope, stageIds } = entry;
115
+ if (typeof name !== "string" || name.trim() === "")
116
+ return;
117
+ if (scope !== "case" && scope !== "stages")
118
+ return;
119
+ if (!Array.isArray(actions))
120
+ return;
121
+ return {
122
+ id: typeof id === "string" ? id : name,
123
+ name,
124
+ ...typeof description === "string" && { description },
125
+ ...typeof isDefault === "boolean" && { isDefault },
126
+ actions: actions.filter((action) => typeof action === "string" && (roleActionKeyOf(action) !== undefined || isLegacyRoleAction(action))),
127
+ scope,
128
+ ...Array.isArray(stageIds) && {
129
+ stageIds: stageIds.filter((stageId) => typeof stageId === "string")
130
+ }
131
+ };
132
+ };
133
+ var readCaseRoles = (plan) => caseRoleEntries(plan).flatMap((entry) => {
134
+ const role = readCaseRole(entry);
135
+ return role === undefined ? [] : [role];
136
+ });
137
+ export {
138
+ CASE_APP_ROLE_ACTIONS,
139
+ CASE_APP_ROLE_ACTION_KEYS,
140
+ CASE_APP_VERSIONS_WITH_ROLES,
141
+ CASE_ROLE_DESCRIPTION_MAX_LENGTH,
142
+ CASE_ROLE_FIELDS,
143
+ CASE_ROLE_NAME_FORBIDDEN,
144
+ CASE_ROLE_NAME_MAX_LENGTH,
145
+ CASE_ROLE_SCOPES,
146
+ LEGACY_CASE_APP_ROLE_ACTIONS,
147
+ STAGE_ALLOWED_ROLE_ACTION_KEYS,
148
+ TENANT_GATED_ROLE_ACTIONS,
149
+ caseRoleEntries,
150
+ caseStageLabels,
151
+ isLegacyRoleAction,
152
+ liveStageIdsOf,
153
+ publishedRoleActions,
154
+ readCaseRole,
155
+ readCaseRoles,
156
+ roleActionGateOf,
157
+ roleActionKeyFor,
158
+ roleActionKeyOf,
159
+ roleDeploys,
160
+ roleDescriptionOf,
161
+ roleResourceKey
162
+ };
163
+
164
+ //# debugId=BA3FA1EBCEC6904D64756E2164756E21
@@ -1,8 +1,10 @@
1
- import { type IFileSystem, type IProjectToolFactory, type IToolLogger, type ProjectTool, type ProjectType } from "@uipath/solutionpackager-tool-core";
1
+ import { type IFileSystem, type IProjectToolFactory, type IToolLogger, type ProjectResourceContribution, type ProjectTool, type ProjectType } from "@uipath/solutionpackager-tool-core";
2
2
  /**
3
3
  * Factory for creating Case Management project tools
4
4
  */
5
5
  export declare class CaseToolFactory implements IProjectToolFactory {
6
6
  readonly supportedTypes: readonly ProjectType[];
7
7
  createAsync(logger: IToolLogger, fileSystem: IFileSystem): Promise<ProjectTool>;
8
+ /** The case roles' spec — see `case-role-contribution.ts`. */
9
+ describeResourcesAsync(projectDir: string, fileSystem: IFileSystem): Promise<ProjectResourceContribution>;
8
10
  }
@@ -17,6 +17,17 @@ export declare class CaseTool extends ProjectTool {
17
17
  buildAsync(options: IProjectBuildOptions, _cancellationToken?: AbortSignal): Promise<ToolResult>;
18
18
  packAsync(options: IProjectPackOptions, cancellationToken?: AbortSignal): Promise<ToolResult>;
19
19
  dispose(): Promise<void>;
20
+ /**
21
+ * Make the packaged `bindings_v2.json` join each `Role` entry to its role
22
+ * by name, as `solution pack` reconciled the solution's resources. Studio
23
+ * Web writes the role resource's key there; the resource is named after
24
+ * the role, so the entry would name nothing the package contains.
25
+ *
26
+ * Only the staged copy changes: the project's own sidecar is Studio
27
+ * Web's, and is left as it wrote it. Anything unreadable is left as is.
28
+ */
29
+ private reconcileRoleBindingNames;
30
+ private readJson;
20
31
  /**
21
32
  * Copy all files from source path to content/.
22
33
  * Case Management projects keep all files in content/ (no separate folder).
@@ -65,16 +76,13 @@ export declare class CaseTool extends ProjectTool {
65
76
  */
66
77
  private readEntryPointBpmnFiles;
67
78
  /**
68
- * The name `entry-points.json`'s first entry resolves to, unfiltered by
69
- * the `.bpmn` suffix `readEntryPointBpmnFiles` applies.
70
- *
71
- * `createOperateFile` derives operate.json's `main` the same way
72
- * (`resolveEntryPointMain` in packager-core), so `checkEntryPointBpmnPresent`
73
- * has to check the exact value that call will end up trusting, not just
74
- * the declared list as a whole. Only called once `readEntryPointBpmnFiles`
75
- * has proven the file exists and parses, so the read here cannot fail.
79
+ * The entry the package's operate.json `main` names. Runs after
80
+ * `applyDefaultEntryPoint`, so a flagged default is already in `main` or
81
+ * first in entry-points.json, where `createOperateFile` takes `main` from.
82
+ * Without an entry-points.json nothing declares an entry point, so there
83
+ * is no `main` to check, as before.
76
84
  */
77
- private firstEntryPointFileName;
85
+ private stagedMain;
78
86
  /**
79
87
  * Create operate.json file if it doesn't already exist
80
88
  */
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __commonJS
3
- } from "./node-1de529jm.js";
3
+ } from "./node-dhtszrf6.js";
4
4
 
5
5
  // ../../../node_modules/@uipath/case-schema/dist/index.cjs
6
6
  var require_dist = __commonJS(function(exports, module) {
@@ -16067,6 +16067,7 @@ var require_dist = __commonJS(function(exports, module) {
16067
16067
  };
16068
16068
  var JOB_ATTACHMENT_TYPE_NAME = "job-attachment";
16069
16069
  var JOB_ATTACHMENT_REF = `#/definitions/${JOB_ATTACHMENT_TYPE_NAME}`;
16070
+ var { $schema: _fileSchemaHeader, ...FILE_ITEM_SCHEMA } = FILE_TYPE_JSON_SCHEMA;
16070
16071
  var DATA_FABRIC_TYPE_JSON_SCHEMA = {
16071
16072
  $schema: "http://json-schema.org/draft-07/schema#",
16072
16073
  type: "object",
@@ -62523,7 +62524,7 @@ return { upsertKeys: allEventsUpdatedKeys, deleteKeys: [...exitedStageKeysToDele
62523
62524
  Object.defineProperty(p, "definedBy", {
62524
62525
  value: t3
62525
62526
  });
62526
- var { replaces, redefines } = p;
62527
+ var replaces = p.replaces, redefines = p.redefines;
62527
62528
  if (replaces || redefines) {
62528
62529
  this.redefineProperty(p, replaces || redefines, replaces);
62529
62530
  } else {
@@ -64245,7 +64246,7 @@ return { upsertKeys: allEventsUpdatedKeys, deleteKeys: [...exitedStageKeysToDele
64245
64246
  ElementSerializer.prototype.parseContainments = function(properties) {
64246
64247
  var self2 = this, body = this.body, element = this.element;
64247
64248
  forEach(properties, function(p) {
64248
- var value = element.get(p.name), isReference = p.isReference, isMany = p.isMany;
64249
+ var value = element.get(p.name), { isReference, isMany } = p;
64249
64250
  if (!isMany) {
64250
64251
  value = [value];
64251
64252
  }
@@ -64304,7 +64305,7 @@ return { upsertKeys: allEventsUpdatedKeys, deleteKeys: [...exitedStageKeysToDele
64304
64305
  };
64305
64306
  ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
64306
64307
  var namespaces = this.getNamespaces(local);
64307
- var { prefix: prefix2, uri: uri2 } = ns, newPrefix, idx, wellknownUri;
64308
+ var prefix2 = ns.prefix, uri2 = ns.uri, newPrefix, idx, wellknownUri;
64308
64309
  if (!prefix2 && !uri2) {
64309
64310
  return { localName: ns.localName };
64310
64311
  }
@@ -79568,4 +79569,4 @@ return { upsertKeys: allEventsUpdatedKeys, deleteKeys: [...exitedStageKeysToDele
79568
79569
  });
79569
79570
  export default require_dist();
79570
79571
 
79571
- //# debugId=3AABAD1CC1CBED5864756E2164756E21
79572
+ //# debugId=E4F5669F0B0C3CF364756E2164756E21
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { CaseToolFactory } from "./case-tool-factory.js";
2
2
  export { type CaseBpmnCompiler, registerCaseBpmnCompiler, } from "./case-bpmn-compiler.js";
3
- export { buildCasePackageDescriptor, CasePlanFileNames, casePlanSidecarName, entryPointBpmnNames, findCasePlanFileName, misnamedEntryPointBpmn, normalizeEntryPointPath, resolveDeclaredFileName, } from "./case-plan-file.js";
3
+ export { buildCasePackageDescriptor, CasePlanFileNames, casePlanSidecarName, entryPointBpmnNames, findCasePlanFileName, misnamedEntryPointBpmn, normalizeEntryPointPath, resolveDeclaredFileName, stagedMainEntryPoint, stagedMainProblem, } from "./case-plan-file.js";
4
+ export { CasePlanDefaultNotListedError, type CasePlanTrigger, casePlanDefaults, readCasePlanTriggers, withCasePlanDefaults, } from "./case-plan-triggers.js";
5
+ export { describeCaseRoles } from "./case-role-contribution.js";
4
6
  export { CaseToolFactory };
package/dist/index.js CHANGED
@@ -6,32 +6,10 @@ import {
6
6
  ProjectTypes as ProjectTypes2
7
7
  } from "@uipath/solutionpackager-tool-core";
8
8
 
9
- // src/case-tool.ts
10
- import {
11
- ensureContentOperateFile,
12
- NugetConstants as NugetConstants2,
13
- NugetPackager,
14
- Path,
15
- ProjectTool,
16
- ProjectTypes,
17
- TemporaryStorageService,
18
- ToolErrorCodes,
19
- ToolResult
20
- } from "@uipath/solutionpackager-tool-core";
21
-
22
- // src/case-bpmn-compiler.ts
23
- var COMPILER_KEY = Symbol.for("@uipath/packager-tool-case/caseBpmnCompiler");
24
- var _global = globalThis;
25
- function registerCaseBpmnCompiler(caseBpmnCompiler) {
26
- _global[COMPILER_KEY] = caseBpmnCompiler;
27
- }
28
- function getCaseBpmnCompiler() {
29
- return _global[COMPILER_KEY];
30
- }
31
-
32
9
  // src/case-plan-file.ts
33
10
  import {
34
- NugetConstants
11
+ NugetConstants,
12
+ parseJsonObject
35
13
  } from "@uipath/solutionpackager-tool-core";
36
14
  var CasePlanFileNames = [
37
15
  "caseplan.case",
@@ -77,6 +55,25 @@ var misnamedEntryPointBpmn = (declared, casePlanFileName) => {
77
55
  const otherPlans = new Set(CasePlanFileNames.filter((name) => name !== casePlanFileName).map(casePlanSidecarName));
78
56
  return declared.find((file) => file !== own && otherPlans.has(file));
79
57
  };
58
+ var stagedMainEntryPoint = (operateJson, entryPointsJson) => {
59
+ const main = parseJsonObject(operateJson)?.main;
60
+ if (typeof main === "string" && main !== "") {
61
+ return { filePath: main, source: "operate.json" };
62
+ }
63
+ const entryPoints = parseJsonObject(entryPointsJson)?.entryPoints;
64
+ const first = Array.isArray(entryPoints) ? entryPoints[0]?.filePath : undefined;
65
+ return {
66
+ filePath: typeof first === "string" ? first : "",
67
+ source: "entry-points.json"
68
+ };
69
+ };
70
+ var stagedMainProblem = (staged, resolved, own) => staged.source === "operate.json" ? {
71
+ problem: `operate.json's main names '${staged.filePath}', which resolves to '${resolved}'`,
72
+ fix: own ? `Mark the entry for '${own}' as default, or point operate.json's main at it` : undefined
73
+ } : {
74
+ problem: `entry-points.json's first entry point resolves to '${resolved}'`,
75
+ fix: own ? `Mark the entry for '${own}' as default, or make it the first entry` : undefined
76
+ };
80
77
  var buildCasePackageDescriptor = (contentFileNames) => ({
81
78
  $schema: "https://cloud.uipath.com/draft/2024-12/package-descriptor",
82
79
  files: {
@@ -90,6 +87,331 @@ var buildCasePackageDescriptor = (contentFileNames) => ({
90
87
  }
91
88
  });
92
89
 
90
+ // src/case-role-bindings.ts
91
+ var ROLE_RESOURCE = "role";
92
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
93
+ var roleBindingName = (entry) => {
94
+ if (!isRecord(entry))
95
+ return;
96
+ if (String(entry.resource).toLowerCase() !== ROLE_RESOURCE) {
97
+ return;
98
+ }
99
+ const name = isRecord(entry.value) ? entry.value.name : undefined;
100
+ const defaultValue = isRecord(name) ? name.defaultValue : undefined;
101
+ return typeof defaultValue === "string" ? defaultValue : undefined;
102
+ };
103
+ var reconcileRoleBindings = (resources, roles) => {
104
+ const roleNames = new Set(roles.map((role) => role.name));
105
+ let changed = false;
106
+ const reconciled = resources.map((entry) => {
107
+ const bound = roleBindingName(entry);
108
+ if (bound === undefined || roleNames.has(bound))
109
+ return entry;
110
+ const record = entry;
111
+ const displayName = isRecord(record.metadata) ? record.metadata.displayName : undefined;
112
+ if (typeof displayName !== "string" || !roleNames.has(displayName)) {
113
+ return entry;
114
+ }
115
+ const value = record.value;
116
+ const name = value.name;
117
+ changed = true;
118
+ return {
119
+ ...record,
120
+ value: { ...value, name: { ...name, defaultValue: displayName } }
121
+ };
122
+ });
123
+ return { resources: reconciled, changed };
124
+ };
125
+
126
+ // src/case-roles.ts
127
+ var CASE_APP_ROLE_ACTIONS = {
128
+ View: "CaseManagement.Cases.View",
129
+ Create: "CaseManagement.Cases.Create",
130
+ Edit: "CaseManagement.Cases.Edit",
131
+ Close: "CaseManagement.Cases.Close",
132
+ Reopen: "CaseManagement.Cases.Reopen",
133
+ Assign: "CaseManagement.Cases.Assign",
134
+ ManageSLA: "CaseManagement.Cases.ManageSLA",
135
+ RunAdhocTasks: "CaseManagement.Cases.RunAdhocTasks",
136
+ SelectStage: "CaseManagement.Cases.SelectStage",
137
+ ViewSummary: "CaseManagement.Cases.ViewSummary",
138
+ LogsView: "Orchestrator.Logs.View",
139
+ TasksView: "Orchestrator.Tasks.View",
140
+ TasksCreate: "Orchestrator.Tasks.Create",
141
+ TasksEdit: "Orchestrator.Tasks.Edit",
142
+ TasksDelete: "Orchestrator.Tasks.Delete",
143
+ TaskAssignmentView: "Orchestrator.TaskAssignment.View",
144
+ TaskAssignmentCreate: "Orchestrator.TaskAssignment.Create",
145
+ TaskAssignmentEdit: "Orchestrator.TaskAssignment.Edit",
146
+ TaskAssignmentDelete: "Orchestrator.TaskAssignment.Delete",
147
+ TaskSelfAssignmentCreate: "Orchestrator.TaskSelfAssignment.Create",
148
+ TaskSelfAssignmentEdit: "Orchestrator.TaskSelfAssignment.Edit",
149
+ TaskSelfAssignmentDelete: "Orchestrator.TaskSelfAssignment.Delete"
150
+ };
151
+ var LEGACY_CASE_APP_ROLE_ACTIONS = [
152
+ "CaseManagement.Cases.Manage"
153
+ ];
154
+ var CASE_APP_ROLE_ACTION_KEYS = Object.keys(CASE_APP_ROLE_ACTIONS);
155
+ var STAGE_ALLOWED_ROLE_ACTION_KEYS = [
156
+ "View",
157
+ "Assign",
158
+ "ManageSLA",
159
+ "RunAdhocTasks"
160
+ ];
161
+ var ACTION_KEY_BY_LITERAL = new Map(CASE_APP_ROLE_ACTION_KEYS.map((key) => [CASE_APP_ROLE_ACTIONS[key], key]));
162
+ var ACTION_KEY_BY_FOLDED = new Map(CASE_APP_ROLE_ACTION_KEYS.map((key) => [key.toLowerCase(), key]));
163
+ var isLegacyRoleAction = (literal) => LEGACY_CASE_APP_ROLE_ACTIONS.includes(literal);
164
+ var roleActionKeyOf = (literal) => ACTION_KEY_BY_LITERAL.get(literal);
165
+ var roleDescriptionOf = (role) => role.description?.trim() || role.name;
166
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
167
+ var STAGE_NODE_TYPE = "case-management:Stage";
168
+ var caseStageLabels = (nodes) => {
169
+ const labels = new Map;
170
+ for (const node of Array.isArray(nodes) ? nodes : []) {
171
+ if (!isRecord2(node))
172
+ continue;
173
+ const { id, type, data } = node;
174
+ if (type !== STAGE_NODE_TYPE || typeof id !== "string")
175
+ continue;
176
+ const label = isRecord2(data) ? data.label : undefined;
177
+ if (typeof label === "string" && label.trim() !== "") {
178
+ labels.set(id, label);
179
+ }
180
+ }
181
+ return labels;
182
+ };
183
+ var liveStageIdsOf = (role, stages) => (role.stageIds ?? []).filter((stageId) => stages.has(stageId));
184
+ var publishedRoleActions = (role) => role.actions.filter((action) => {
185
+ const key = roleActionKeyOf(action);
186
+ if (key === undefined)
187
+ return false;
188
+ return role.scope !== "stages" || STAGE_ALLOWED_ROLE_ACTION_KEYS.includes(key);
189
+ });
190
+ var roleDeploys = (role, stages) => publishedRoleActions(role).length > 0 && (role.scope !== "stages" || liveStageIdsOf(role, stages).length > 0);
191
+ var roleResourceKey = (name) => name.trim().toLowerCase();
192
+ var caseRoleEntries = (plan) => {
193
+ if (!isRecord2(plan) || !isRecord2(plan.metadata))
194
+ return [];
195
+ const entries = plan.metadata.caseRoles;
196
+ return Array.isArray(entries) ? entries : [];
197
+ };
198
+ var readCaseRole = (entry) => {
199
+ if (!isRecord2(entry))
200
+ return;
201
+ const { id, name, description, isDefault, actions, scope, stageIds } = entry;
202
+ if (typeof name !== "string" || name.trim() === "")
203
+ return;
204
+ if (scope !== "case" && scope !== "stages")
205
+ return;
206
+ if (!Array.isArray(actions))
207
+ return;
208
+ return {
209
+ id: typeof id === "string" ? id : name,
210
+ name,
211
+ ...typeof description === "string" && { description },
212
+ ...typeof isDefault === "boolean" && { isDefault },
213
+ actions: actions.filter((action) => typeof action === "string" && (roleActionKeyOf(action) !== undefined || isLegacyRoleAction(action))),
214
+ scope,
215
+ ...Array.isArray(stageIds) && {
216
+ stageIds: stageIds.filter((stageId) => typeof stageId === "string")
217
+ }
218
+ };
219
+ };
220
+ var readCaseRoles = (plan) => caseRoleEntries(plan).flatMap((entry) => {
221
+ const role = readCaseRole(entry);
222
+ return role === undefined ? [] : [role];
223
+ });
224
+
225
+ // src/case-role-contribution.ts
226
+ var BINDINGS_FILE_NAME = "bindings_v2.json";
227
+ var ROLE_RESOURCE_KIND = "role";
228
+ var CASE_ROLE_RESOURCE_TYPE = "case-role";
229
+ async function describeCaseRoles(projectDir, fs) {
230
+ const entries = await fs.readdir(projectDir);
231
+ const planName = findCasePlanFileName(entries);
232
+ if (planName === undefined)
233
+ return {};
234
+ const plan = await readJson(fs, fs.path.join(projectDir, planName));
235
+ if (plan === undefined)
236
+ return {};
237
+ const stages = caseStageLabels(isRecord3(plan) ? plan.nodes : undefined);
238
+ const roles = readCaseRoles(plan).filter((role) => roleDeploys(role, stages));
239
+ if (roles.length === 0)
240
+ return {};
241
+ const collisions = nameCollisions(roles);
242
+ if (collisions.length > 0) {
243
+ return {
244
+ errors: [
245
+ {
246
+ code: "case_role_name_collision",
247
+ message: `${planName} declares case roles whose names differ only by case (${collisions.join("; ")}). The solution stores one role resource per name regardless of case, so they would deploy as one.`,
248
+ instructions: `Rename one role of each pair in the Case Designer, run 'uip maestro case bindings sync ${planName}' in ${projectDir}, then pack again.`
249
+ }
250
+ ]
251
+ };
252
+ }
253
+ const sidecar = await readBindingResources(fs, projectDir);
254
+ const reconciled = reconcileRoleBindings(sidecar, roles);
255
+ const bound = roleBindingNames(reconciled.resources);
256
+ const unbound = roles.filter((role) => !bound.has(role.name));
257
+ if (unbound.length > 0) {
258
+ const names = unbound.map((role) => `"${role.name}"`).join(", ");
259
+ return {
260
+ errors: [
261
+ {
262
+ code: "case_role_unbound",
263
+ message: `${planName} declares case role(s) ${names} with no matching Role entry in ${BINDINGS_FILE_NAME}, so the solution would deploy without them.`,
264
+ instructions: `Run 'uip maestro case bindings sync ${planName}' in ${projectDir} to write the Role entries, then pack again.`
265
+ }
266
+ ]
267
+ };
268
+ }
269
+ return {
270
+ specPatch: roles.map(rolePatch),
271
+ ...reconciled.changed && {
272
+ bindings: reconciled.resources
273
+ }
274
+ };
275
+ }
276
+ var nameCollisions = (roles) => {
277
+ const byKey = new Map;
278
+ for (const role of roles) {
279
+ const key = roleResourceKey(role.name);
280
+ byKey.set(key, [...byKey.get(key) ?? [], role.name]);
281
+ }
282
+ return [...byKey.values()].filter((names) => names.length > 1).map((names) => names.map((name) => `"${name}"`).join(" and "));
283
+ };
284
+ var rolePatch = (role) => ({
285
+ kind: ROLE_RESOURCE_KIND,
286
+ type: CASE_ROLE_RESOURCE_TYPE,
287
+ name: role.name,
288
+ values: {
289
+ description: roleDescriptionOf(role),
290
+ actions: publishedRoleActions(role)
291
+ }
292
+ });
293
+ var roleBindingNames = (resources) => {
294
+ const names = new Set;
295
+ for (const entry of resources) {
296
+ const name = roleBindingName(entry);
297
+ if (name !== undefined)
298
+ names.add(name);
299
+ }
300
+ return names;
301
+ };
302
+ async function readBindingResources(fs, projectDir) {
303
+ const file = await readJson(fs, fs.path.join(projectDir, BINDINGS_FILE_NAME));
304
+ return isRecord3(file) && Array.isArray(file.resources) ? file.resources : [];
305
+ }
306
+ async function readJson(fs, path) {
307
+ try {
308
+ const raw = await fs.readFile(path, "utf-8");
309
+ if (raw === null || raw === undefined || raw === "")
310
+ return;
311
+ return JSON.parse(raw);
312
+ } catch {
313
+ return;
314
+ }
315
+ }
316
+ var isRecord3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
317
+
318
+ // src/case-tool.ts
319
+ import {
320
+ applyDefaultEntryPoint,
321
+ ensureContentOperateFile,
322
+ NugetConstants as NugetConstants2,
323
+ NugetPackager,
324
+ Path as Path2,
325
+ ProjectTool,
326
+ ProjectTypes,
327
+ TemporaryStorageService,
328
+ ToolErrorCodes,
329
+ ToolResult
330
+ } from "@uipath/solutionpackager-tool-core";
331
+
332
+ // src/case-bpmn-compiler.ts
333
+ var COMPILER_KEY = Symbol.for("@uipath/packager-tool-case/caseBpmnCompiler");
334
+ var _global = globalThis;
335
+ function registerCaseBpmnCompiler(caseBpmnCompiler) {
336
+ _global[COMPILER_KEY] = caseBpmnCompiler;
337
+ }
338
+ function getCaseBpmnCompiler() {
339
+ return _global[COMPILER_KEY];
340
+ }
341
+
342
+ // src/case-plan-triggers.ts
343
+ import {
344
+ isDefaultFlag,
345
+ Path,
346
+ readJsonObjectFile
347
+ } from "@uipath/solutionpackager-tool-core";
348
+ var nonEmpty = (value) => typeof value === "string" && value !== "" ? value : undefined;
349
+ function readCasePlanTriggers(plan) {
350
+ const nodes = plan?.nodes;
351
+ if (!Array.isArray(nodes))
352
+ return [];
353
+ const triggers = [];
354
+ for (const node of nodes) {
355
+ if (typeof node !== "object" || node === null)
356
+ continue;
357
+ const isCurrent = node.type === "uipath.case.trigger";
358
+ if (!isCurrent && node.type !== "case-management:Trigger")
359
+ continue;
360
+ if (typeof node.id !== "string")
361
+ continue;
362
+ const inputs = node.data?.inputs;
363
+ const uipath = isCurrent ? undefined : node.data?.uipath;
364
+ const label = nonEmpty(isCurrent ? node.data?.display?.label : node.data?.label);
365
+ const entryPointId = nonEmpty(uipath?.entryPointId) ?? nonEmpty(inputs?.entryPointId);
366
+ const isDefault = uipath?.isDefault ?? inputs?.isDefault;
367
+ triggers.push({
368
+ id: node.id,
369
+ ...label !== undefined && { label },
370
+ ...entryPointId !== undefined && { entryPointId },
371
+ isDefault: isDefaultFlag(isDefault)
372
+ });
373
+ }
374
+ return triggers;
375
+ }
376
+ function withCasePlanDefaults(entryPoints, plan, casePlanFileName) {
377
+ const flagged = new Set(readCasePlanTriggers(plan).filter((trigger) => trigger.isDefault).map((trigger) => trigger.id));
378
+ if (flagged.size === 0)
379
+ return [...entryPoints];
380
+ const sidecar = casePlanSidecarName(casePlanFileName);
381
+ const listed = new Set(entryPoints.flatMap((entry) => typeof entry === "object" && entry !== null && typeof entry.filePath === "string" && resolveDeclaredFileName(entry.filePath) === sidecar ? [entry.filePath.split("#")[1] ?? ""] : []));
382
+ const unlisted = [...flagged].filter((id) => !listed.has(id));
383
+ if (unlisted.length > 0) {
384
+ throw new CasePlanDefaultNotListedError(unlisted);
385
+ }
386
+ return entryPoints.map((entry) => {
387
+ if (typeof entry !== "object" || entry === null)
388
+ return entry;
389
+ const { isDefault: _isDefault, ...rest } = entry;
390
+ const filePath = typeof entry.filePath === "string" ? entry.filePath : "";
391
+ const isDefault = resolveDeclaredFileName(filePath) === sidecar && flagged.has(filePath.split("#")[1] ?? "");
392
+ return isDefault ? { ...rest, isDefault: true } : rest;
393
+ });
394
+ }
395
+
396
+ class CasePlanDefaultNotListedError extends Error {
397
+ triggerIds;
398
+ constructor(triggerIds) {
399
+ const names = triggerIds.map((id) => `'${id}'`).join(", ");
400
+ super(`The case plan flags ${triggerIds.length === 1 ? "trigger" : "triggers"} ${names} as the default, but entry-points.json has no entry for ${triggerIds.length === 1 ? "it" : "them"}, so the package could not start from ${triggerIds.length === 1 ? "it" : "them"}. Run 'uip maestro case init --force' to add the entry, then try again.`);
401
+ this.triggerIds = triggerIds;
402
+ this.name = "CasePlanDefaultNotListedError";
403
+ }
404
+ }
405
+ async function casePlanDefaults(fs, contentFolder) {
406
+ const casePlanFileName = findCasePlanFileName(await fs.readdir(contentFolder));
407
+ if (!casePlanFileName)
408
+ return;
409
+ const plan = (await readJsonObjectFile(fs, Path.join(contentFolder, casePlanFileName)))?.value;
410
+ if (!plan)
411
+ return;
412
+ return (entryPoints) => withCasePlanDefaults(entryPoints, plan, casePlanFileName);
413
+ }
414
+
93
415
  // src/case-tool.ts
94
416
  var CaseConstants = {
95
417
  EntryPointsFileName: "entry-points.json"
@@ -111,11 +433,23 @@ class CaseTool extends ProjectTool {
111
433
  }
112
434
  async buildAsync(options, _cancellationToken) {
113
435
  const tempFolder = await this._temporaryStorage.getTempFolderPath();
114
- const localBuildFolder = Path.join(tempFolder, NugetConstants2.OutputFolderName);
115
- const contentFolder = Path.join(localBuildFolder, NugetConstants2.ContentFolderName);
436
+ const localBuildFolder = Path2.join(tempFolder, NugetConstants2.OutputFolderName);
437
+ const contentFolder = Path2.join(localBuildFolder, NugetConstants2.ContentFolderName);
116
438
  try {
117
439
  this.logger.progress("Copying files...");
118
440
  await this.copyFiles(options.projectPath, contentFolder);
441
+ try {
442
+ await applyDefaultEntryPoint(this.fileSystem, {
443
+ contentFolder,
444
+ withDefaults: await casePlanDefaults(this.fileSystem, contentFolder)
445
+ });
446
+ } catch (error) {
447
+ if (!(error instanceof CasePlanDefaultNotListedError)) {
448
+ throw error;
449
+ }
450
+ return ToolResult.error(ToolErrorCodes.InternalError, error.message);
451
+ }
452
+ await this.reconcileRoleBindingNames(contentFolder);
119
453
  this.logger.progress("Compiling case plan to BPMN...");
120
454
  const compileResult = await this.compileCasePlan(options.projectPath, contentFolder);
121
455
  if (!compileResult.isSuccess) {
@@ -143,7 +477,7 @@ class CaseTool extends ProjectTool {
143
477
  try {
144
478
  this.logger.progress("Creating NuGet package...");
145
479
  const nupkgFileName = `${options.package.id}.${options.package.version}.nupkg`;
146
- const nupkgPath = Path.join(options.outputPath, nupkgFileName);
480
+ const nupkgPath = Path2.join(options.outputPath, nupkgFileName);
147
481
  const packager = new NugetPackager(this.fileSystem);
148
482
  const result = await packager.packAsync(localBuildFolder, options.package, nupkgPath);
149
483
  this.logger.progress("Package created successfully");
@@ -162,16 +496,39 @@ class CaseTool extends ProjectTool {
162
496
  await this._temporaryStorage.cleanup();
163
497
  } catch {}
164
498
  }
499
+ async reconcileRoleBindingNames(contentFolder) {
500
+ const planName = findCasePlanFileName(await this.fileSystem.readdir(contentFolder));
501
+ if (planName === undefined)
502
+ return;
503
+ const bindingsPath = Path2.join(contentFolder, "bindings_v2.json");
504
+ const plan = await this.readJson(Path2.join(contentFolder, planName));
505
+ const file = await this.readJson(bindingsPath);
506
+ if (!isRecord4(file) || !Array.isArray(file.resources))
507
+ return;
508
+ const { resources, changed } = reconcileRoleBindings(file.resources, readCaseRoles(plan));
509
+ if (!changed)
510
+ return;
511
+ await this.fileSystem.writeFile(bindingsPath, `${JSON.stringify({ ...file, resources }, null, 2)}
512
+ `);
513
+ }
514
+ async readJson(path) {
515
+ try {
516
+ const raw = await this.fileSystem.readFile(path);
517
+ return raw && raw.length > 0 ? JSON.parse(new TextDecoder().decode(raw)) : undefined;
518
+ } catch {
519
+ return;
520
+ }
521
+ }
165
522
  async copyFiles(sourcePath, contentFolder) {
166
523
  await this.fileSystem.mkdir(contentFolder);
167
524
  const files = await this.fileSystem.readdir(sourcePath);
168
525
  for (const file of files) {
169
- const sourceFile = Path.join(sourcePath, file);
526
+ const sourceFile = Path2.join(sourcePath, file);
170
527
  const stat = await this.fileSystem.stat(sourceFile);
171
528
  if (stat?.isFile()) {
172
529
  const content = await this.fileSystem.readFile(sourceFile);
173
530
  if (content) {
174
- const destinationFile = Path.join(contentFolder, file);
531
+ const destinationFile = Path2.join(contentFolder, file);
175
532
  await this.fileSystem.writeFile(destinationFile, content);
176
533
  }
177
534
  }
@@ -184,14 +541,14 @@ class CaseTool extends ProjectTool {
184
541
  return this.checkEntryPointBpmnPresent(contentFolder, casePlanFileName);
185
542
  }
186
543
  const sidecarFileName = casePlanSidecarName(casePlanFileName);
187
- const casePlanPath = Path.join(projectPath, casePlanFileName);
544
+ const casePlanPath = Path2.join(projectPath, casePlanFileName);
188
545
  const casePlan = await this.fileSystem.readFile(casePlanPath);
189
546
  if (!casePlan || casePlan.length === 0) {
190
547
  return ToolResult.error(ToolErrorCodes.InternalError, `'${casePlanFileName}' in ${projectPath} is empty, so there is nothing to compile into '${sidecarFileName}'. Author the case plan, or re-scaffold the project with 'uip maestro case init'.`);
191
548
  }
192
549
  try {
193
550
  const bpmnXml = await compile(new TextDecoder().decode(casePlan));
194
- await this.fileSystem.writeFile(Path.join(contentFolder, sidecarFileName), bpmnXml);
551
+ await this.fileSystem.writeFile(Path2.join(contentFolder, sidecarFileName), bpmnXml);
195
552
  return await this.checkEntryPointBpmnPresent(contentFolder, casePlanFileName);
196
553
  } catch (error) {
197
554
  const message = error instanceof Error ? error.message : String(error);
@@ -206,10 +563,11 @@ class CaseTool extends ProjectTool {
206
563
  }
207
564
  const own = casePlanFileName ? casePlanSidecarName(casePlanFileName) : undefined;
208
565
  const fix = own ?? `Author a case plan (${CasePlanFileNames.join(", ")}) so pack can compile it (see 'uip maestro case init'), then pack again.`;
209
- const firstEntry = await this.firstEntryPointFileName(contentFolder);
210
- if (firstEntry && !referenced.includes(firstEntry)) {
211
- const firstEntryFix = own ? `Point the first entry point at '${own}', then pack again.` : fix;
212
- return ToolResult.error(ToolErrorCodes.InternalError, `'${CaseConstants.EntryPointsFileName}' first entry point resolves to '${firstEntry}', which is not a declared .bpmn file this project ships, so operate.json's main would name a file pack cannot produce. ${firstEntryFix}`);
566
+ const staged = await this.stagedMain(contentFolder);
567
+ const mainEntry = resolveDeclaredFileName(staged.filePath);
568
+ if (staged.filePath && !referenced.includes(mainEntry)) {
569
+ const wording = stagedMainProblem(staged, mainEntry, own);
570
+ return ToolResult.error(ToolErrorCodes.InternalError, `${wording.problem}, which is not a declared .bpmn file this project ships, so the package's main would name a file pack cannot produce. ${wording.fix ? `${wording.fix}, then pack again.` : fix}`);
213
571
  }
214
572
  if (referenced.length === 0) {
215
573
  return ToolResult.success();
@@ -230,7 +588,7 @@ class CaseTool extends ProjectTool {
230
588
  return ToolResult.error(ToolErrorCodes.InternalError, `'${CaseConstants.EntryPointsFileName}' points at ${missingList}, which the package does not contain, so it would deploy and activate and then fault every job. ${missingFix}`);
231
589
  }
232
590
  async readEntryPointBpmnFiles(contentFolder) {
233
- const entryPointsPath = Path.join(contentFolder, CaseConstants.EntryPointsFileName);
591
+ const entryPointsPath = Path2.join(contentFolder, CaseConstants.EntryPointsFileName);
234
592
  if (!await this.fileSystem.exists(entryPointsPath)) {
235
593
  return [];
236
594
  }
@@ -240,11 +598,16 @@ class CaseTool extends ProjectTool {
240
598
  }
241
599
  return entryPointBpmnNames(new TextDecoder().decode(raw));
242
600
  }
243
- async firstEntryPointFileName(contentFolder) {
244
- const raw = await this.fileSystem.readFile(Path.join(contentFolder, CaseConstants.EntryPointsFileName));
245
- const parsed = JSON.parse(raw ? new TextDecoder().decode(raw) : "{}");
246
- const filePath = parsed.entryPoints?.[0]?.filePath ?? "";
247
- return resolveDeclaredFileName(filePath);
601
+ async stagedMain(contentFolder) {
602
+ const read = async (name) => {
603
+ const raw = await this.fileSystem.readFile(Path2.join(contentFolder, name));
604
+ return raw ? new TextDecoder().decode(raw) : null;
605
+ };
606
+ const entryPoints = await read(CaseConstants.EntryPointsFileName);
607
+ if (entryPoints === null) {
608
+ return { filePath: "", source: "entry-points.json" };
609
+ }
610
+ return stagedMainEntryPoint(await read(NugetConstants2.OperateFileName), entryPoints);
248
611
  }
249
612
  async createOperateFile(options, contentFolder) {
250
613
  await ensureContentOperateFile(this.fileSystem, {
@@ -256,11 +619,12 @@ class CaseTool extends ProjectTool {
256
619
  }
257
620
  async createPackageDescriptor(localBuildFolder, contentFolder) {
258
621
  const contentFiles = await this.fileSystem.readdir(contentFolder);
259
- const packageDescriptorPath = Path.join(localBuildFolder, NugetConstants2.ContentFolderName, NugetConstants2.PackageDescriptorFileName);
622
+ const packageDescriptorPath = Path2.join(localBuildFolder, NugetConstants2.ContentFolderName, NugetConstants2.PackageDescriptorFileName);
260
623
  const packageDescriptorJson = JSON.stringify(buildCasePackageDescriptor(contentFiles), null, 2);
261
624
  await this.fileSystem.writeFile(packageDescriptorPath, packageDescriptorJson);
262
625
  }
263
626
  }
627
+ var isRecord4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
264
628
 
265
629
  // src/case-tool-factory.ts
266
630
  class CaseToolFactory {
@@ -270,21 +634,31 @@ class CaseToolFactory {
270
634
  async createAsync(logger, fileSystem) {
271
635
  return new CaseTool(fileSystem, logger);
272
636
  }
637
+ async describeResourcesAsync(projectDir, fileSystem) {
638
+ return describeCaseRoles(projectDir, fileSystem);
639
+ }
273
640
  }
274
641
 
275
642
  // src/index.ts
276
643
  toolsFactoryRepository.registerProjectToolFactory(new CaseToolFactory);
277
644
  export {
645
+ CasePlanDefaultNotListedError,
278
646
  CasePlanFileNames,
279
647
  CaseToolFactory,
280
648
  buildCasePackageDescriptor,
649
+ casePlanDefaults,
281
650
  casePlanSidecarName,
651
+ describeCaseRoles,
282
652
  entryPointBpmnNames,
283
653
  findCasePlanFileName,
284
654
  misnamedEntryPointBpmn,
285
655
  normalizeEntryPointPath,
656
+ readCasePlanTriggers,
286
657
  registerCaseBpmnCompiler,
287
- resolveDeclaredFileName
658
+ resolveDeclaredFileName,
659
+ stagedMainEntryPoint,
660
+ stagedMainProblem,
661
+ withCasePlanDefaults
288
662
  };
289
663
 
290
- //# debugId=478D1E7AE28D7DC664756E2164756E21
664
+ //# debugId=7D0628597ABAD99064756E2164756E21
@@ -1,4 +1,3 @@
1
- import { createRequire } from "node:module";
2
1
  var __create = Object.create;
3
2
  var __getProtoOf = Object.getPrototypeOf;
4
3
  var __defProp = Object.defineProperty;
@@ -18,7 +17,7 @@ var __toESM = (mod, isNodeMode, target) => {
18
17
  return cached;
19
18
  }
20
19
  target = mod != null ? __create(__getProtoOf(mod)) : {};
21
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
20
+ const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
22
21
  if (mod && typeof mod === "object" || typeof mod === "function") {
23
22
  for (let key of __getOwnPropNames(mod))
24
23
  if (!__hasOwnProp.call(to, key))
@@ -32,8 +31,7 @@ var __toESM = (mod, isNodeMode, target) => {
32
31
  return to;
33
32
  };
34
33
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
35
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
36
34
 
37
- export { __toESM, __commonJS, __require };
35
+ export { __toESM, __commonJS };
38
36
 
39
- //# debugId=4A15A0D6FCDB684764756E2164756E21
37
+ //# debugId=B4558D3C3EDD652164756E2164756E21
package/dist/node.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import {
2
- __require,
3
2
  __toESM
4
- } from "./node-1de529jm.js";
3
+ } from "./node-dhtszrf6.js";
5
4
 
6
5
  // src/case-bpmn-compiler.ts
7
6
  var COMPILER_KEY = Symbol.for("@uipath/packager-tool-case/caseBpmnCompiler");
@@ -12,7 +11,7 @@ function registerCaseBpmnCompiler(caseBpmnCompiler) {
12
11
 
13
12
  // src/node.ts
14
13
  var compileCasePlan = async (casePlanJson) => {
15
- const { serializeCaseDiskJsonToBpmnAndRulesJson } = await import("./index-5w2cx41d.js").then((m)=>__toESM(m.default,1));
14
+ const { serializeCaseDiskJsonToBpmnAndRulesJson } = await import("./index-kyh0jafk.js").then((m)=>__toESM(m.default,1));
16
15
  const { bpmnXml } = await serializeCaseDiskJsonToBpmnAndRulesJson(casePlanJson);
17
16
  return bpmnXml;
18
17
  };
@@ -23,4 +22,4 @@ export {
23
22
  registerNodeCaseBpmnCompiler
24
23
  };
25
24
 
26
- //# debugId=0A08F635657DD68164756E2164756E21
25
+ //# debugId=169AA9D93C7D06B364756E2164756E21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uipath/packager-tool-case",
3
- "version": "1.205.0-preview.277",
3
+ "version": "1.206.0-preview.279",
4
4
  "description": "UiPath Case Management tool implementation",
5
5
  "type": "module",
6
6
  "exports": {
@@ -8,6 +8,10 @@
8
8
  "./node": {
9
9
  "types": "./dist/node.d.ts",
10
10
  "default": "./dist/node.js"
11
+ },
12
+ "./roles": {
13
+ "types": "./dist/case-roles.d.ts",
14
+ "default": "./dist/case-roles.js"
11
15
  }
12
16
  },
13
17
  "repository": {
@@ -25,7 +29,7 @@
25
29
  "author": "UiPath",
26
30
  "license": "SEE LICENSE IN LICENSE.txt",
27
31
  "peerDependencies": {
28
- "@uipath/solutionpackager-tool-core": "1.205.0"
32
+ "@uipath/solutionpackager-tool-core": "1.206.0"
29
33
  },
30
- "gitHead": "0dc7b5ef3ba1d723a8f2eee6b760c20f4ac294c7"
34
+ "gitHead": "d2176feff38d4e91a9d84723af847b2dfd5c6008"
31
35
  }