@elementumai/edk 0.12.0 → 0.13.0
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/README.md +2 -0
- package/dist-sdk/src/catalog/factories.d.ts +7 -1
- package/dist-sdk/src/catalog/factories.js +2 -0
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +1 -1
- package/dist-sdk/src/catalog/org.js +79 -34
- package/dist-sdk/src/catalog/token.js +5 -0
- package/dist-sdk/src/catalog/types.d.ts +7 -1
- package/dist-sdk/src/catalog/types.js +3 -0
- package/dist-sdk/src/core/system-fields.d.ts +1 -1
- package/dist-sdk/src/core/system-fields.js +1 -1
- package/dist-sdk/src/core/types/app.d.ts +6 -0
- package/dist-sdk/src/engine/build/context.d.ts +3 -0
- package/dist-sdk/src/engine/pull/authored-address.js +42 -6
- package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
- package/dist-sdk/src/engine/pull/authored-root.js +306 -0
- package/dist-sdk/src/engine/pull/context.d.ts +10 -0
- package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
- package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
- package/dist-sdk/src/engine/pull/org.d.ts +1 -0
- package/dist-sdk/src/engine/pull/org.js +2 -0
- package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
- package/dist-sdk/src/engine/pull/partition.js +43 -0
- package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
- package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +4 -0
- package/dist-sdk/src/engine/pull/ref-only.js +7 -1
- package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
- package/dist-sdk/src/engine/pull/source-resources.js +110 -0
- package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
- package/dist-sdk/src/engine/pull/stream-root.js +563 -0
- package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
- package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
- package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
- package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
- package/dist-sdk/src/entities/access-policy/from-tf.js +18 -3
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
- package/dist-sdk/src/entities/agent/build.d.ts +52 -1
- package/dist-sdk/src/entities/agent/build.js +34 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
- package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
- package/dist-sdk/src/entities/agent/from-tf.js +262 -2
- package/dist-sdk/src/entities/agent/index.d.ts +1 -1
- package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
- package/dist-sdk/src/entities/agent/to-tf.js +158 -14
- package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
- package/dist-sdk/src/entities/app/build.d.ts +33 -13
- package/dist-sdk/src/entities/app/build.js +14 -12
- package/dist-sdk/src/entities/app/from-tf.js +24 -9
- package/dist-sdk/src/entities/app/index.d.ts +1 -0
- package/dist-sdk/src/entities/app/index.js +1 -0
- package/dist-sdk/src/entities/app/module.js +1 -0
- package/dist-sdk/src/entities/app/stage-keys.d.ts +2 -2
- package/dist-sdk/src/entities/app/stage-keys.js +3 -3
- package/dist-sdk/src/entities/app/to-tf.js +1 -0
- package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
- package/dist-sdk/src/entities/approval-chain/build.js +120 -8
- package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
- package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
- package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
- package/dist-sdk/src/entities/approval-chain/index.js +4 -1
- package/dist-sdk/src/entities/approval-chain/module.js +23 -5
- package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
- package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
- package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
- package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
- package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
- package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
- package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
- package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
- package/dist-sdk/src/entities/automation/build.js +70 -27
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +20 -5
- package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -5
- package/dist-sdk/src/entities/automation/from-tf.js +593 -101
- package/dist-sdk/src/entities/automation/index.d.ts +1 -0
- package/dist-sdk/src/entities/automation/index.js +1 -0
- package/dist-sdk/src/entities/automation/module.d.ts +4 -3
- package/dist-sdk/src/entities/automation/module.js +33 -12
- package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
- package/dist-sdk/src/entities/automation/refs-read.js +48 -0
- package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
- package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +11 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +23 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +29 -4
- package/dist-sdk/src/entities/automation/tasks.js +34 -11
- package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
- package/dist-sdk/src/entities/automation/to-tf.js +337 -77
- package/dist-sdk/src/entities/automation/triggers.d.ts +0 -8
- package/dist-sdk/src/entities/automation/triggers.js +26 -11
- package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
- package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
- package/dist-sdk/src/entities/chart/build.d.ts +9 -1
- package/dist-sdk/src/entities/chart/from-tf.js +3 -0
- package/dist-sdk/src/entities/chart/to-tf.js +19 -2
- package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -0
- package/dist-sdk/src/entities/dynamic-layout/from-tf.js +44 -5
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
- package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
- package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
- package/dist-sdk/src/entities/element/build.js +2 -1
- package/dist-sdk/src/entities/element/from-tf.js +15 -2
- package/dist-sdk/src/entities/element/module.js +3 -0
- package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
- package/dist-sdk/src/entities/element/system-fields.js +23 -0
- package/dist-sdk/src/entities/element/to-tf.js +1 -0
- package/dist-sdk/src/entities/field/build.d.ts +9 -0
- package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
- package/dist-sdk/src/entities/field/from-tf.js +99 -6
- package/dist-sdk/src/entities/field/module.js +4 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +5 -1
- package/dist-sdk/src/entities/field/to-tf.js +33 -12
- package/dist-sdk/src/entities/org/category.js +1 -0
- package/dist-sdk/src/entities/org/index.d.ts +1 -0
- package/dist-sdk/src/entities/org/index.js +1 -0
- package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
- package/dist-sdk/src/entities/org/voice-auth.js +33 -0
- package/dist-sdk/src/entities/organization/build.d.ts +3 -0
- package/dist-sdk/src/entities/organization/build.js +2 -0
- package/dist-sdk/src/entities/organization/index.d.ts +1 -0
- package/dist-sdk/src/entities/organization/index.js +1 -0
- package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/organization/to-tf.js +59 -1
- package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
- package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
- package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
- package/dist-sdk/src/entities/phone-service/build.js +1 -0
- package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
- package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
- package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
- package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
- package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
- package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
- package/dist-sdk/src/entities/relationship/module.js +2 -2
- package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
- package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
- package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
- package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
- package/dist-sdk/src/entities/role/permission-levels.js +78 -0
- package/dist-sdk/src/entities/role/to-tf.js +32 -2
- package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
- package/dist-sdk/src/entities/service-account/module.js +4 -1
- package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
- package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
- package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
- package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
- package/dist-sdk/src/entities/shared/filters/index.js +18 -6
- package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
- package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
- package/dist-sdk/src/entities/shared/filters/print.js +9 -5
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
- package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
- package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
- package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
- package/dist-sdk/src/entities/sla/build.d.ts +96 -0
- package/dist-sdk/src/entities/sla/build.js +124 -0
- package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
- package/dist-sdk/src/entities/sla/from-tf.js +164 -0
- package/dist-sdk/src/entities/sla/index.d.ts +1 -0
- package/dist-sdk/src/entities/sla/index.js +1 -0
- package/dist-sdk/src/entities/sla/module.d.ts +4 -0
- package/dist-sdk/src/entities/sla/module.js +73 -0
- package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
- package/dist-sdk/src/entities/sla/printer.js +84 -0
- package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
- package/dist-sdk/src/entities/sla/to-tf.js +81 -0
- package/dist-sdk/src/entities/table/build.d.ts +7 -2
- package/dist-sdk/src/entities/table/build.js +22 -1
- package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
- package/dist-sdk/src/entities/table/from-tf.js +89 -14
- package/dist-sdk/src/entities/table/index.d.ts +1 -1
- package/dist-sdk/src/entities/table/to-tf.js +41 -2
- package/dist-sdk/src/entities/task/from-tf.js +2 -1
- package/dist-sdk/src/entities/view/from-tf.js +7 -4
- package/dist-sdk/src/entities/widget/from-tf.js +13 -2
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +49 -4
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +5 -0
- package/dist-sdk/src/graph/index.js +7 -0
- package/dist-sdk/src/graph/modules.js +11 -1
- package/dist-sdk/src/graph/resource-types.d.ts +47 -0
- package/dist-sdk/src/graph/resource-types.js +62 -0
- package/dist-sdk/src/graph/types.d.ts +78 -6
- package/package.json +6 -3
|
@@ -4,7 +4,8 @@ import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf
|
|
|
4
4
|
import { fieldKeyFromTfRef } from "../field/from-tf.js";
|
|
5
5
|
import { LostStageHandleError, lostStageMessage, pulledStageHandle } from "../app/stage-keys.js";
|
|
6
6
|
import { APPROVAL_PROCESS_RESOURCE_TYPE } from "./module.js";
|
|
7
|
-
|
|
7
|
+
import { approvalStepsFromTf } from "./steps-tf.js";
|
|
8
|
+
const KNOWN = new Set(["id", "app_id", "element_id", "name", "stage_id", "number_of_dynamic_approvers", "locked_field_ids", "managed_by_automation", "approve_button_text", "deny_button_text", "exception_button_text", "default_reason", "approval_summary", "dynamic_chain", "approvers", "table_filter_field_ids"]);
|
|
8
9
|
function stringAttr(attrs, key) { return typeof attrs[key] === "string" ? attrs[key] : undefined; }
|
|
9
10
|
/**
|
|
10
11
|
* The lost-stage warning when an approval process sits on a stage with no
|
|
@@ -22,14 +23,22 @@ export function approvalChainLostStage(block, appTfLabel, stageHandles) {
|
|
|
22
23
|
const pulled = pulledStageHandle(index.index, stageHandles);
|
|
23
24
|
return pulled.kind === "lost" ? lostStageMessage(`${block.type}.${block.label}`, index.index, pulled, "the approval chain is left unmanaged") : undefined;
|
|
24
25
|
}
|
|
25
|
-
export function approvalChainFromTf(block, appTfLabel, ctx, stageHandles) {
|
|
26
|
+
export function approvalChainFromTf(block, appTfLabel, ctx, stageHandles, scope = "app") {
|
|
26
27
|
if (block.type !== APPROVAL_PROCESS_RESOURCE_TYPE || block.label === undefined)
|
|
27
28
|
throw new EntityTfError(`expected ${APPROVAL_PROCESS_RESOURCE_TYPE}`);
|
|
28
29
|
for (const key of Object.keys(block.attrs))
|
|
29
30
|
if (!KNOWN.has(key))
|
|
30
31
|
throw new EntityTfError(`${block.type}.${block.label}: unknown attribute ${key}`);
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
// The owner (edk#373): app_id for an app stream, element_id for an element stream, never both.
|
|
33
|
+
const ownerAttr = scope === "element" ? "element_id" : "app_id";
|
|
34
|
+
const otherAttr = scope === "element" ? "app_id" : "element_id";
|
|
35
|
+
const ownerType = scope === "element" ? "elementum_element" : "elementum_app";
|
|
36
|
+
if (block.attrs[otherAttr] !== undefined)
|
|
37
|
+
throw new EntityTfError(`${block.type}.${block.label}: ${otherAttr} on a ${scope}-owned approval process`);
|
|
38
|
+
if (resourceRefLabel(block.attrs[ownerAttr], ownerType) !== appTfLabel)
|
|
39
|
+
throw new EntityTfError(`${block.type}.${block.label}: wrong ${ownerAttr}`);
|
|
40
|
+
if (scope === "element" && block.attrs["stage_id"] !== undefined)
|
|
41
|
+
throw new EntityTfError(`${block.type}.${block.label}: an element-owned approval process takes no stage_id`);
|
|
33
42
|
const name = stringAttr(block.attrs, "name");
|
|
34
43
|
const count = block.attrs["number_of_dynamic_approvers"];
|
|
35
44
|
const managed = block.attrs["managed_by_automation"];
|
|
@@ -74,7 +83,7 @@ export function approvalChainFromTf(block, appTfLabel, ctx, stageHandles) {
|
|
|
74
83
|
// Keep literal IDs literal even when state can identify the corresponding
|
|
75
84
|
// system field. Export deliberately avoids the owning app's computed
|
|
76
85
|
// `*_field_id` locals because they can be null during fresh import.
|
|
77
|
-
const key = fieldKeyFromTfRef(value, appTfLabel,
|
|
86
|
+
const key = fieldKeyFromTfRef(value, appTfLabel, scope);
|
|
78
87
|
if (key !== undefined) {
|
|
79
88
|
lockedFields.push(key);
|
|
80
89
|
continue;
|
|
@@ -86,8 +95,99 @@ export function approvalChainFromTf(block, appTfLabel, ctx, stageHandles) {
|
|
|
86
95
|
}
|
|
87
96
|
throw new EntityTfError(`${block.type}.${block.label}: locked field is not a local field reference or platform id`);
|
|
88
97
|
}
|
|
98
|
+
const dynamicChain = block.attrs["dynamic_chain"];
|
|
99
|
+
if (dynamicChain !== undefined && typeof dynamicChain !== "boolean")
|
|
100
|
+
throw new EntityTfError(`${block.type}.${block.label}: dynamic_chain must be a literal boolean`);
|
|
101
|
+
// Steps are all or nothing: authoring some of them would make the provider
|
|
102
|
+
// delete the rest, so any step that cannot be authored leaves every step
|
|
103
|
+
// unmanaged with a diagnostic (edk#373).
|
|
104
|
+
let steps;
|
|
105
|
+
if (block.attrs["approvers"] !== undefined) {
|
|
106
|
+
try {
|
|
107
|
+
steps = approvalStepsFromTf(block.attrs["approvers"], `${block.type}.${block.label}.approvers`, { appTfLabel, scope }, ctx);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
ctx.diagnostics.push(`${error instanceof Error ? error.message : String(error)}; the approver steps are left out and stay unmanaged`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Table filter columns are all or nothing (edk#2657): a single unresolvable
|
|
114
|
+
// field leaves the whole list unmanaged so apply does not clear the rest.
|
|
115
|
+
// Kept as one list (edk#2841 S-A) so mixed refs and unsafe ids stay
|
|
116
|
+
// interleaved; order itself is non-authoritative (edk#2841 S2).
|
|
117
|
+
let tableFilterColumns;
|
|
118
|
+
if (block.attrs["table_filter_field_ids"] !== undefined) {
|
|
119
|
+
const rawFilters = block.attrs["table_filter_field_ids"];
|
|
120
|
+
if (!Array.isArray(rawFilters))
|
|
121
|
+
throw new EntityTfError(`${block.type}.${block.label}: table_filter_field_ids must be a list`);
|
|
122
|
+
const entries = [];
|
|
123
|
+
let dropColumns = false;
|
|
124
|
+
// Classify every entry first (edk#2841 S2): only emit "preserved with
|
|
125
|
+
// unsafePlatformId" when the list is kept; otherwise the all-or-nothing
|
|
126
|
+
// unmanaged warning alone is accurate.
|
|
127
|
+
for (const value of rawFilters) {
|
|
128
|
+
const key = fieldKeyFromTfRef(value, appTfLabel, scope);
|
|
129
|
+
if (key !== undefined) {
|
|
130
|
+
entries.push({ key });
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
134
|
+
entries.push({ unsafeId: value });
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
dropColumns = true;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (dropColumns) {
|
|
141
|
+
ctx.diagnostics.push(`${block.type}.${block.label}: a table filter column could not be authored; tableFilterColumns are left out and stay unmanaged`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
for (const entry of entries) {
|
|
145
|
+
if (entry.unsafeId !== undefined) {
|
|
146
|
+
ctx.diagnostics.push(`${block.type}.${block.label}: table filter column ${entry.unsafeId} could not be resolved to a portable field reference; preserved with unsafePlatformId`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
tableFilterColumns = entries;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// S1 / r4519125639: when a pulled priority-group `when` is outside the
|
|
153
|
+
// columns, leave `steps` unset (same all-or-nothing as an unauthorable
|
|
154
|
+
// step) so pull never writes source `approvalProcess()` rejects; keep the
|
|
155
|
+
// warning. Match by owner+fieldKey or by id, not bag key alone.
|
|
156
|
+
if (tableFilterColumns !== undefined && steps !== undefined) {
|
|
157
|
+
const ownerRefName = tfLabelToTsLabel(appTfLabel);
|
|
158
|
+
const allowed = new Set();
|
|
159
|
+
for (const entry of tableFilterColumns) {
|
|
160
|
+
if (entry.key !== undefined)
|
|
161
|
+
allowed.add(`key:${ownerRefName}:${entry.key}`);
|
|
162
|
+
else if (entry.unsafeId !== undefined)
|
|
163
|
+
allowed.add(`id:${entry.unsafeId}`);
|
|
164
|
+
}
|
|
165
|
+
let dropSteps = false;
|
|
166
|
+
for (const [stepIndex, step] of steps.entries()) {
|
|
167
|
+
if (step.kind !== "priorityGroup")
|
|
168
|
+
continue;
|
|
169
|
+
for (const [conditionalIndex, conditional] of step.conditionals.entries()) {
|
|
170
|
+
if (conditional.when === undefined)
|
|
171
|
+
continue;
|
|
172
|
+
for (const field of pullWhenFieldTokens(conditional.when)) {
|
|
173
|
+
if (pullWhenFieldMatches(field, allowed))
|
|
174
|
+
continue;
|
|
175
|
+
const label = pullWhenFieldLabel(field);
|
|
176
|
+
if (label === undefined)
|
|
177
|
+
continue;
|
|
178
|
+
ctx.diagnostics.push(`${block.type}.${block.label}: steps[${stepIndex}] conditionals[${conditionalIndex}].when references field ${JSON.stringify(label)} which is not in tableFilterColumns; the approver steps are left out and stay unmanaged`);
|
|
179
|
+
dropSteps = true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (dropSteps)
|
|
184
|
+
steps = undefined;
|
|
185
|
+
}
|
|
89
186
|
return {
|
|
90
|
-
refName: scopedLabelToBagKey(appTfLabel, block.label,
|
|
187
|
+
refName: scopedLabelToBagKey(appTfLabel, block.label, scope), name,
|
|
188
|
+
...(dynamicChain === true && { dynamicChain: true }),
|
|
189
|
+
...(steps !== undefined && { steps }),
|
|
190
|
+
...(tableFilterColumns !== undefined && { tableFilterColumns }),
|
|
91
191
|
...(stage !== undefined && { stage }), ...(stageId !== undefined && { stageId }),
|
|
92
192
|
numberOfDynamicApprovers: count, managedByAutomation: managed, denyButton: deny, approveButton: approve,
|
|
93
193
|
lockedFields, unsafeLockedFieldIds,
|
|
@@ -96,3 +196,45 @@ export function approvalChainFromTf(block, appTfLabel, ctx, stageHandles) {
|
|
|
96
196
|
...(stringAttr(block.attrs, "approval_summary") !== undefined && { summary: stringAttr(block.attrs, "approval_summary") }),
|
|
97
197
|
};
|
|
98
198
|
}
|
|
199
|
+
/** Field tokens named by a pulled priority-group `when` filter (edk#2841 N-A). */
|
|
200
|
+
function pullWhenFieldTokens(node) {
|
|
201
|
+
if (node === null || typeof node !== "object")
|
|
202
|
+
return [];
|
|
203
|
+
const record = node;
|
|
204
|
+
const out = [];
|
|
205
|
+
if (record["field"] !== undefined)
|
|
206
|
+
out.push(record["field"]);
|
|
207
|
+
const left = record["leftValue"];
|
|
208
|
+
if (left !== null && typeof left === "object") {
|
|
209
|
+
const leftRecord = left;
|
|
210
|
+
if (leftRecord["type"] === "FIELD" && leftRecord["value"] !== undefined)
|
|
211
|
+
out.push(leftRecord["value"]);
|
|
212
|
+
}
|
|
213
|
+
if (Array.isArray(record["children"])) {
|
|
214
|
+
for (const child of record["children"])
|
|
215
|
+
out.push(...pullWhenFieldTokens(child));
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
function pullWhenFieldMatches(field, allowed) {
|
|
220
|
+
if (typeof field === "string" && field.trim() !== "")
|
|
221
|
+
return allowed.has(`id:${field}`);
|
|
222
|
+
if (typeof field === "object" && field !== null) {
|
|
223
|
+
const record = field;
|
|
224
|
+
if (record.kind === "field" && typeof record.fieldKey === "string" && typeof record.appHandle === "string") {
|
|
225
|
+
return allowed.has(`key:${record.appHandle}:${record.fieldKey}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return true; // unrecognized shapes: do not warn (build will surface them)
|
|
229
|
+
}
|
|
230
|
+
function pullWhenFieldLabel(field) {
|
|
231
|
+
if (typeof field === "string" && field.trim() !== "")
|
|
232
|
+
return field;
|
|
233
|
+
if (typeof field === "object" && field !== null) {
|
|
234
|
+
const record = field;
|
|
235
|
+
if (record.kind === "field" && typeof record.fieldKey === "string") {
|
|
236
|
+
return typeof record.appHandle === "string" ? `${record.appHandle}.${record.fieldKey}` : record.fieldKey;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Approval-process authoring.
|
|
2
|
+
* Approval-process authoring. Owned by an app or an element; the ordered
|
|
3
|
+
* approver steps (edk#373) are built with the step factories below.
|
|
3
4
|
* Standalone from v1's `src/approvalChains`.
|
|
4
5
|
*/
|
|
5
6
|
export { approvalProcess, unsafeApprovalStageId, type ApprovalProcessConfigured, type DefineApprovalProcessOptions, type UnsafeApprovalStageId, } from "./build.js";
|
|
7
|
+
export { dynamicEmployeeStep, groupStep, priorityGroup, resolvedQueryStep, runtimeGroup, runtimeUser, userStep, type ApprovalConditional, type ApprovalConditionalApprover, type ApprovalCounts, type ApprovalDynamicEmployeeStep, type ApprovalGroupStep, type ApprovalPriorityGroup, type ApprovalResolvedQueryStep, type ApprovalRuntimeGroup, type ApprovalRuntimeUser, type ApprovalStep, type ApprovalUserStep, } from "./steps.js";
|
|
8
|
+
export { userRef, type RoleUserRef as ApprovalUserRef } from "../role/build.js";
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Approval-process authoring.
|
|
2
|
+
* Approval-process authoring. Owned by an app or an element; the ordered
|
|
3
|
+
* approver steps (edk#373) are built with the step factories below.
|
|
3
4
|
* Standalone from v1's `src/approvalChains`.
|
|
4
5
|
*/
|
|
5
6
|
export { approvalProcess, unsafeApprovalStageId, } from "./build.js";
|
|
7
|
+
export { dynamicEmployeeStep, groupStep, priorityGroup, resolvedQueryStep, runtimeGroup, runtimeUser, userStep, } from "./steps.js";
|
|
8
|
+
export { userRef } from "../role/build.js";
|
|
@@ -28,10 +28,14 @@ function extract(blocks, _stream, ctx) {
|
|
|
28
28
|
const skipped = [];
|
|
29
29
|
const releaseIfManaged = [];
|
|
30
30
|
const diagnostics = [];
|
|
31
|
-
|
|
31
|
+
if (ctx.parentScope === "table")
|
|
32
|
+
return { items, skipped: blocks.map((block) => `${block.type}.${block.label ?? "?"}`), diagnostics: ["approval processes cannot belong to tables"] };
|
|
33
|
+
const scope = ctx.parentScope;
|
|
34
|
+
// Elements carry no stages (edk#373); an app's stage handles keep chains on their own stage (#1136).
|
|
35
|
+
const stageHandles = scope === "app" ? stageHandleIndexFromTfStages(ctx.resourceByAddress?.(`elementum_app.${ctx.appTfLabel}`)?.attrs["stages"]) : undefined;
|
|
32
36
|
for (const block of blocks) {
|
|
33
37
|
try {
|
|
34
|
-
items.push(approvalChainFromTf(block, ctx.appTfLabel, ctx, stageHandles));
|
|
38
|
+
items.push(approvalChainFromTf(block, ctx.appTfLabel, ctx, stageHandles, scope));
|
|
35
39
|
}
|
|
36
40
|
catch (error) {
|
|
37
41
|
const address = `${block.type}.${block.label ?? ""}`;
|
|
@@ -47,12 +51,26 @@ function extract(blocks, _stream, ctx) {
|
|
|
47
51
|
}
|
|
48
52
|
export const approvalChainModule = {
|
|
49
53
|
kind: "approval-chain", stream: { role: "streamMember" }, authoring: { unit: "ownFile", bag: "approval-chains" },
|
|
50
|
-
parents: [{ parent: "app", child: "approval-chain" }],
|
|
54
|
+
parents: [{ parent: "app", child: "approval-chain" }, { parent: "element", child: "approval-chain" }],
|
|
51
55
|
resource: { shape: "single", resourceType: APPROVAL_PROCESS_RESOURCE_TYPE, adoptable: true }, data: NO_DATA,
|
|
52
56
|
lifecycle: {
|
|
53
57
|
participates: true, extractOwnFile: extract,
|
|
54
|
-
printOwnFile: (item, opts) => {
|
|
55
|
-
|
|
58
|
+
printOwnFile: (item, opts) => {
|
|
59
|
+
if (opts.parentScope === "table")
|
|
60
|
+
throw new Error("approval processes cannot belong to tables");
|
|
61
|
+
const chain = item;
|
|
62
|
+
return { refName: chain.refName, source: printApprovalChain(chain, opts.appRefName, opts.parentScope, opts.orgImportPath) };
|
|
63
|
+
},
|
|
64
|
+
toTf: (entity, ctx) => {
|
|
65
|
+
if (ctx.parentScope === "table")
|
|
66
|
+
throw new Error("approval processes cannot belong to tables");
|
|
67
|
+
return approvalChainToTf(entity, {
|
|
68
|
+
appRefName: ctx.appRefName, appTfLabel: ctx.appTfLabel, parentScope: ctx.parentScope,
|
|
69
|
+
orgRefs: ctx.orgRefs, diagnostics: ctx.diagnostics,
|
|
70
|
+
...(ctx.fieldAddresses !== undefined && { fieldAddresses: ctx.fieldAddresses }),
|
|
71
|
+
...(ctx.parentScope !== "element" && { stageKeyByTfLabel: appStageKeyByHandle(ctx.streamRootEntity?.payload) }),
|
|
72
|
+
});
|
|
73
|
+
},
|
|
56
74
|
},
|
|
57
75
|
canvas: { participates: true, label: "Approval processes", glyph: "✓", component: "generic" },
|
|
58
76
|
catalog: { participates: true, refKind: "approvalChain", catalogBag: "approvalChains", renderOrder: 26, catalogRoot: "app", renderEntry: rootParentFactoryEntry("approvalChainRef"), stubRef: stub, refFromAuthoring },
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NormalizedApprovalChain } from "./from-tf.js";
|
|
2
|
-
export declare function printApprovalChain(chain: NormalizedApprovalChain, appRefName: string): string;
|
|
2
|
+
export declare function printApprovalChain(chain: NormalizedApprovalChain, appRefName: string, parentScope?: "app" | "element", orgImportPath?: string): string;
|
|
@@ -1,20 +1,33 @@
|
|
|
1
|
+
import { sdkPackageSpecifier } from "../../internal/sdk-package.js";
|
|
2
|
+
import { printFilter } from "../shared/filters/print.js";
|
|
1
3
|
const safe = (value) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value) ? value : JSON.stringify(value);
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
const member = (value) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value) ? `.${value}` : `[${JSON.stringify(value)}]`;
|
|
5
|
+
export function printApprovalChain(chain, appRefName, parentScope = "app", orgImportPath = "../../../org.js") {
|
|
6
|
+
const steps = chain.steps;
|
|
7
|
+
const used = new Set();
|
|
8
|
+
const printedSteps = steps === undefined ? undefined : steps.map((step) => printStep(step, appRefName, used));
|
|
9
|
+
const imports = [
|
|
10
|
+
"approvalProcess",
|
|
11
|
+
...(chain.stageId !== undefined ? ["unsafeApprovalStageId"] : []),
|
|
12
|
+
...[...used].filter((name) => name !== "org" && name !== "filter").sort(),
|
|
13
|
+
];
|
|
4
14
|
const unsafeLockedFieldIds = chain.unsafeLockedFieldIds ?? [];
|
|
15
|
+
const hasUnsafeTableFilter = (chain.tableFilterColumns ?? []).some((entry) => entry.unsafeId !== undefined);
|
|
5
16
|
const lines = [
|
|
6
17
|
`import { ${imports.join(", ")} } from "@elementumai/edk/approvalProcesses";`,
|
|
7
|
-
...(
|
|
18
|
+
...(used.has("filter") ? [`import { filter } from ${JSON.stringify(sdkPackageSpecifier("app"))};`] : []),
|
|
19
|
+
...(unsafeLockedFieldIds.length > 0 || hasUnsafeTableFilter
|
|
8
20
|
? [`import { unsafePlatformId } from "@elementumai/edk/core";`]
|
|
9
21
|
: []),
|
|
10
22
|
`import catalog from "@catalog";`,
|
|
23
|
+
...(used.has("org") ? [`import { org } from ${JSON.stringify(orgImportPath)};`] : []),
|
|
11
24
|
];
|
|
12
25
|
const lockedFields = [
|
|
13
26
|
...[...chain.lockedFields].sort().map((key) => `catalog.${safe(appRefName)}.fields.${safe(key)}`),
|
|
14
27
|
...[...unsafeLockedFieldIds].sort().map((id) => `unsafePlatformId(${JSON.stringify(id)})`),
|
|
15
28
|
];
|
|
16
29
|
const props = [
|
|
17
|
-
|
|
30
|
+
`${parentScope}: catalog.${safe(appRefName)}`,
|
|
18
31
|
`name: ${JSON.stringify(chain.name)}`,
|
|
19
32
|
...(chain.stage !== undefined ? [`stage: ${JSON.stringify(chain.stage)}`] : []),
|
|
20
33
|
...(chain.stageId !== undefined ? [`unsafeStageId: unsafeApprovalStageId(${JSON.stringify(chain.stageId)})`] : []),
|
|
@@ -26,7 +39,80 @@ export function printApprovalChain(chain, appRefName) {
|
|
|
26
39
|
...(chain.defaultReason !== undefined ? [`defaultReason: ${JSON.stringify(chain.defaultReason)}`] : []),
|
|
27
40
|
...(chain.summary !== undefined ? [`summary: ${JSON.stringify(chain.summary)}`] : []),
|
|
28
41
|
...(lockedFields.length > 0 ? [`lockedFields: [${lockedFields.join(", ")}]`] : []),
|
|
42
|
+
...(chain.dynamicChain === true ? ["dynamicChain: true"] : []),
|
|
29
43
|
];
|
|
30
|
-
|
|
44
|
+
// Mixed refs and unsafePlatformId stay interleaved (edk#2841 S-A); order is non-authoritative (S2).
|
|
45
|
+
const tableFilterColumns = (chain.tableFilterColumns ?? []).map((entry) => entry.unsafeId !== undefined
|
|
46
|
+
? `unsafePlatformId(${JSON.stringify(entry.unsafeId)})`
|
|
47
|
+
: `catalog.${safe(appRefName)}.fields.${safe(entry.key)}`);
|
|
48
|
+
const body = props.map((prop) => ` ${prop},`);
|
|
49
|
+
if (chain.tableFilterColumns !== undefined) {
|
|
50
|
+
body.push(` tableFilterColumns: [${tableFilterColumns.join(", ")}],`);
|
|
51
|
+
}
|
|
52
|
+
if (printedSteps !== undefined) {
|
|
53
|
+
if (printedSteps.length === 0)
|
|
54
|
+
body.push(" steps: [],");
|
|
55
|
+
else
|
|
56
|
+
body.push(" steps: [", ...printedSteps.map((step) => ` ${step.replace(/\n/g, "\n ")},`), " ],");
|
|
57
|
+
}
|
|
58
|
+
lines.push(``, `export default approvalProcess({`, ...body, `});`, ``);
|
|
59
|
+
return lines.join("\n");
|
|
60
|
+
}
|
|
61
|
+
function printCounts(counts) {
|
|
62
|
+
return `approvalsRequired: ${counts.approvalsRequired}, denialsRequired: ${counts.denialsRequired}`;
|
|
63
|
+
}
|
|
64
|
+
function printFilterField(field, appRefName) {
|
|
65
|
+
if (field.kind === "field") {
|
|
66
|
+
const owner = field.appHandle === appRefName || field.foreign === undefined ? appRefName : field.appHandle;
|
|
67
|
+
return `catalog${member(owner)}.fields${member(field.fieldKey)}`;
|
|
68
|
+
}
|
|
69
|
+
// approvalStepsFromTf already left out any step list with such a field, so
|
|
70
|
+
// this is unreachable; never print a placeholder that looks managed.
|
|
71
|
+
throw new Error(`approval step filter: ${field.kind} left-hand side cannot be printed`);
|
|
72
|
+
}
|
|
73
|
+
function printStepFilter(filter, appRefName, used) {
|
|
74
|
+
used.add("filter");
|
|
75
|
+
return printFilter(filter, {
|
|
76
|
+
field: (field) => printFilterField(field, appRefName),
|
|
77
|
+
reference: (reference) => printFilterField(reference, appRefName),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function printApprover(approver, appRefName, used) {
|
|
81
|
+
switch (approver.kind) {
|
|
82
|
+
case "user":
|
|
83
|
+
used.add("userStep");
|
|
84
|
+
used.add("userRef");
|
|
85
|
+
return `userStep(userRef(${JSON.stringify(approver.user.email)}))`;
|
|
86
|
+
case "group":
|
|
87
|
+
used.add("groupStep");
|
|
88
|
+
used.add("org");
|
|
89
|
+
return `groupStep(org.groups${member(approver.group.refName)}, { ${printCounts(approver)} })`;
|
|
90
|
+
case "dynamicEmployee":
|
|
91
|
+
used.add("dynamicEmployeeStep");
|
|
92
|
+
return `dynamicEmployeeStep({ degreesOfSeparation: ${approver.degreesOfSeparation}, autoApproveOnMissing: ${approver.autoApproveOnMissing} })`;
|
|
93
|
+
case "resolvedQuery":
|
|
94
|
+
used.add("resolvedQueryStep");
|
|
95
|
+
return `resolvedQueryStep({ ${approver.filter !== undefined ? `filter: ${printStepFilter(approver.filter, appRefName, used)}, ` : ""}${printCounts(approver)} })`;
|
|
96
|
+
case "runtimeUser":
|
|
97
|
+
used.add("runtimeUser");
|
|
98
|
+
return "runtimeUser()";
|
|
99
|
+
case "runtimeGroup":
|
|
100
|
+
used.add("runtimeGroup");
|
|
101
|
+
return `runtimeGroup({ ${printCounts(approver)} })`;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function printStep(step, appRefName, used) {
|
|
105
|
+
if (step.kind !== "priorityGroup")
|
|
106
|
+
return printApprover(step, appRefName, used);
|
|
107
|
+
used.add("priorityGroup");
|
|
108
|
+
const lines = ["priorityGroup({"];
|
|
109
|
+
if (step.threshold !== undefined)
|
|
110
|
+
lines.push(` threshold: { ${printCounts(step.threshold)} },`);
|
|
111
|
+
lines.push(" conditionals: [");
|
|
112
|
+
for (const conditional of step.conditionals) {
|
|
113
|
+
const when = conditional.when !== undefined ? `when: ${printStepFilter(conditional.when, appRefName, used)}, ` : "";
|
|
114
|
+
lines.push(` { ${when}approver: ${printApprover(conditional.approver, appRefName, used)} },`);
|
|
115
|
+
}
|
|
116
|
+
lines.push(" ],", "})");
|
|
31
117
|
return lines.join("\n");
|
|
32
118
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approver steps (edk#373) to and from the `approvers` attribute of
|
|
3
|
+
* `elementum_approval_process`. The provider, ei export and this codec share
|
|
4
|
+
* one shape (ARCH-H2): each entry sets exactly one of user, group,
|
|
5
|
+
* dynamic_employee, resolved_query or priority_group, users and groups are
|
|
6
|
+
* `data.elementum_user` / `data.elementum_group` lookups, and filters use the
|
|
7
|
+
* shared filter codec.
|
|
8
|
+
*/
|
|
9
|
+
import type { OrgRefLookup } from "../../engine/build/context.js";
|
|
10
|
+
import { type FromTfContext } from "../../engine/pull/context.js";
|
|
11
|
+
import { type ChildResourceScope, type TfValue } from "../../engine/tf/index.js";
|
|
12
|
+
import type { RefExpr } from "../shared/filters/ast.js";
|
|
13
|
+
import type { Filter } from "../shared/filters/types.js";
|
|
14
|
+
export interface ApprovalStepsToTfContext {
|
|
15
|
+
readonly orgRefs: OrgRefLookup;
|
|
16
|
+
readonly ownerTfLabel: string;
|
|
17
|
+
readonly appRefName: string;
|
|
18
|
+
readonly scope: ChildResourceScope;
|
|
19
|
+
readonly diagnostics: string[];
|
|
20
|
+
readonly fieldAddresses?: ReadonlyMap<string, string>;
|
|
21
|
+
}
|
|
22
|
+
/** The `approvers` list for authored steps. Any step that cannot be built fails the build. */
|
|
23
|
+
export declare function approvalStepsToTf(steps: readonly unknown[], where: string, ctx: ApprovalStepsToTfContext): TfValue;
|
|
24
|
+
export interface PulledUser {
|
|
25
|
+
readonly __kind: "user";
|
|
26
|
+
readonly email: string;
|
|
27
|
+
}
|
|
28
|
+
export interface PulledGroup {
|
|
29
|
+
readonly __kind: "group";
|
|
30
|
+
readonly refName: string;
|
|
31
|
+
readonly name: string;
|
|
32
|
+
}
|
|
33
|
+
export interface PulledCounts {
|
|
34
|
+
readonly approvalsRequired: number;
|
|
35
|
+
readonly denialsRequired: number;
|
|
36
|
+
}
|
|
37
|
+
export type PulledFilter = Filter<RefExpr, RefExpr>;
|
|
38
|
+
export type PulledApprover = {
|
|
39
|
+
readonly kind: "user";
|
|
40
|
+
readonly user: PulledUser;
|
|
41
|
+
} | ({
|
|
42
|
+
readonly kind: "group";
|
|
43
|
+
readonly group: PulledGroup;
|
|
44
|
+
} & PulledCounts) | {
|
|
45
|
+
readonly kind: "dynamicEmployee";
|
|
46
|
+
readonly degreesOfSeparation: number;
|
|
47
|
+
readonly autoApproveOnMissing: boolean;
|
|
48
|
+
} | ({
|
|
49
|
+
readonly kind: "resolvedQuery";
|
|
50
|
+
readonly filter?: PulledFilter;
|
|
51
|
+
} & PulledCounts) | {
|
|
52
|
+
readonly kind: "runtimeUser";
|
|
53
|
+
} | ({
|
|
54
|
+
readonly kind: "runtimeGroup";
|
|
55
|
+
} & PulledCounts);
|
|
56
|
+
export type PulledApprovalStep = Exclude<PulledApprover, {
|
|
57
|
+
readonly kind: "runtimeUser";
|
|
58
|
+
} | {
|
|
59
|
+
readonly kind: "runtimeGroup";
|
|
60
|
+
}> | {
|
|
61
|
+
readonly kind: "priorityGroup";
|
|
62
|
+
readonly threshold?: PulledCounts;
|
|
63
|
+
readonly conditionals: readonly {
|
|
64
|
+
readonly when?: PulledFilter;
|
|
65
|
+
readonly approver: PulledApprover;
|
|
66
|
+
}[];
|
|
67
|
+
};
|
|
68
|
+
export interface ApprovalStepsFromTfOwner {
|
|
69
|
+
readonly appTfLabel: string;
|
|
70
|
+
readonly scope: ChildResourceScope;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The authored steps of a pulled `approvers` list. Throws when any step
|
|
74
|
+
* cannot be authored: the caller then leaves every step out (unmanaged)
|
|
75
|
+
* rather than author a list the provider would reconcile by deleting.
|
|
76
|
+
*/
|
|
77
|
+
export declare function approvalStepsFromTf(value: TfValue, where: string, owner: ApprovalStepsFromTfOwner, ctx: FromTfContext): PulledApprovalStep[];
|