@elementumai/edk 0.12.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist-sdk/src/catalog/factories.d.ts +7 -1
- package/dist-sdk/src/catalog/factories.js +10 -2
- 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 +12 -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/coverage-gaps.d.ts +2 -0
- package/dist-sdk/src/engine/coverage-gaps.js +4 -0
- package/dist-sdk/src/engine/ei/run.d.ts +8 -0
- package/dist-sdk/src/engine/ei/run.js +46 -7
- 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 +34 -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 +159 -0
- package/dist-sdk/src/engine/pull/stream-root.js +579 -0
- package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
- 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 +17 -5
- 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 +70 -1
- package/dist-sdk/src/entities/agent/from-tf.d.ts +36 -1
- package/dist-sdk/src/entities/agent/from-tf.js +289 -2
- package/dist-sdk/src/entities/agent/index.d.ts +1 -1
- package/dist-sdk/src/entities/agent/module.js +1 -0
- package/dist-sdk/src/entities/agent/to-tf.d.ts +11 -11
- package/dist-sdk/src/entities/agent/to-tf.js +179 -17
- 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.d.ts +1 -0
- package/dist-sdk/src/entities/app/from-tf.js +7 -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 +3 -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.d.ts +10 -1
- package/dist-sdk/src/entities/automation/build.js +70 -27
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +21 -5
- package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -5
- package/dist-sdk/src/entities/automation/from-tf.js +665 -112
- package/dist-sdk/src/entities/automation/index.d.ts +2 -1
- 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 +45 -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/system-ref-name.d.ts +23 -3
- package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
- 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 +8 -1
- package/dist-sdk/src/entities/automation/to-tf.js +563 -103
- 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/dashboard/from-tf.d.ts +3 -1
- package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
- package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
- package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
- package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
- package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
- package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
- 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.d.ts +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +4 -7
- package/dist-sdk/src/entities/element/module.js +5 -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 +52 -1
- package/dist-sdk/src/entities/field/from-tf.js +212 -14
- 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 +9 -4
- 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/build.d.ts +3 -4
- 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/search-table/build.d.ts +9 -3
- package/dist-sdk/src/entities/search-table/build.js +4 -4
- package/dist-sdk/src/entities/search-table/printer.js +3 -1
- package/dist-sdk/src/entities/search-table/to-tf.js +20 -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/context.d.ts +14 -1
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +97 -15
- package/dist-sdk/src/entities/shared/filters/index.js +30 -7
- 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.d.ts +2 -0
- package/dist-sdk/src/entities/shared/filters/print.js +19 -6
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +16 -7
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +25 -5
- package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
- 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.d.ts +1 -1
- package/dist-sdk/src/entities/shared/tool-field-ref.js +3 -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 +3 -2
- package/dist-sdk/src/entities/view/custom-view-validate.d.ts +6 -4
- package/dist-sdk/src/entities/view/custom-view-validate.js +36 -18
- package/dist-sdk/src/entities/view/from-tf.js +16 -4
- package/dist-sdk/src/entities/view/to-tf.js +66 -47
- package/dist-sdk/src/entities/visual-flow/module.js +52 -1
- package/dist-sdk/src/entities/widget/from-tf.js +19 -8
- 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 +9 -0
- package/dist-sdk/src/graph/index.js +8 -0
- package/dist-sdk/src/graph/modules.js +13 -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 +113 -6
- package/package.json +7 -4
|
@@ -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[];
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { EntityTfError } from "../../engine/entity.js";
|
|
2
|
+
import { dataRefLabel, groupCatalogKey } from "../../engine/pull/context.js";
|
|
3
|
+
import { expr, sanitizeName, tfLabelToTsLabel } from "../../engine/tf/index.js";
|
|
4
|
+
import { filterFromTf } from "../access-policy/from-tf.js";
|
|
5
|
+
import { filterToTf } from "../access-policy/to-tf.js";
|
|
6
|
+
import { printFilter } from "../shared/filters/print.js";
|
|
7
|
+
import { APP_RESOURCE_TYPE } from "../app/module.js";
|
|
8
|
+
import { ELEMENT_RESOURCE_TYPE } from "../element/module.js";
|
|
9
|
+
function asWire(value, where) {
|
|
10
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
11
|
+
throw new EntityTfError(`${where}: not an approver step`);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function count(value, where) {
|
|
15
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0)
|
|
16
|
+
throw new EntityTfError(`${where}: must be an integer >= 0`);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function countsToTf(wire, where) {
|
|
20
|
+
return {
|
|
21
|
+
approvals_required: count(wire["approvalsRequired"], `${where}.approvalsRequired`),
|
|
22
|
+
denials_required: count(wire["denialsRequired"], `${where}.denialsRequired`),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function filterValue(filter, where, ctx) {
|
|
26
|
+
return filterToTf(filter, where, {
|
|
27
|
+
ownerTfLabel: ctx.ownerTfLabel,
|
|
28
|
+
appRefName: ctx.appRefName,
|
|
29
|
+
ownerRefName: ctx.appRefName,
|
|
30
|
+
scope: ctx.scope,
|
|
31
|
+
objectId: expr.resourceAttr(ctx.scope === "element" ? ELEMENT_RESOURCE_TYPE : APP_RESOURCE_TYPE, ctx.ownerTfLabel, ["id"]),
|
|
32
|
+
diagnostics: ctx.diagnostics,
|
|
33
|
+
resolvePicklistLiterals: false,
|
|
34
|
+
...(ctx.fieldAddresses !== undefined ? { fieldAddresses: ctx.fieldAddresses } : {}),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function userId(wire, where, ctx) {
|
|
38
|
+
const user = wire["user"];
|
|
39
|
+
if (user?.__kind !== "user" || typeof user.email !== "string" || !user.email.includes("@"))
|
|
40
|
+
throw new EntityTfError(`${where}: user must be userRef(email)`);
|
|
41
|
+
// The whole email names the lookup, as field allow-lists and ei export
|
|
42
|
+
// do, so two users sharing a local part never share one data address.
|
|
43
|
+
const label = sanitizeName(user.email);
|
|
44
|
+
if (label === "")
|
|
45
|
+
throw new EntityTfError(`${where}: user email ${JSON.stringify(user.email)} has no usable lookup label`);
|
|
46
|
+
ctx.orgRefs.rawLookup("elementum_user", label, user.email);
|
|
47
|
+
return expr.dataAttr("elementum_user", label, ["id"]);
|
|
48
|
+
}
|
|
49
|
+
function groupId(wire, where, ctx) {
|
|
50
|
+
const group = wire["group"];
|
|
51
|
+
if (group?.__kind !== "group" || typeof group.refName !== "string")
|
|
52
|
+
throw new EntityTfError(`${where}: group must be an org.groups token`);
|
|
53
|
+
const resolved = ctx.orgRefs.byTsLabel("groups", group.refName);
|
|
54
|
+
// A step cannot be dropped: the provider would delete it. Fail the build.
|
|
55
|
+
if (resolved === undefined)
|
|
56
|
+
throw new EntityTfError(`${where}: group token ${JSON.stringify(group.refName)} is not in org.ts`);
|
|
57
|
+
return expr.dataAttr("elementum_group", resolved.tfLabel, ["id"]);
|
|
58
|
+
}
|
|
59
|
+
function approverToTf(wire, where, ctx, conditional) {
|
|
60
|
+
switch (wire["kind"]) {
|
|
61
|
+
case "user":
|
|
62
|
+
return { user: { user_id: userId(wire, where, ctx) } };
|
|
63
|
+
case "group":
|
|
64
|
+
return { group: { group_id: groupId(wire, where, ctx), ...countsToTf(wire, where) } };
|
|
65
|
+
case "dynamicEmployee": {
|
|
66
|
+
const auto = wire["autoApproveOnMissing"];
|
|
67
|
+
if (typeof auto !== "boolean")
|
|
68
|
+
throw new EntityTfError(`${where}.autoApproveOnMissing: must be a boolean`);
|
|
69
|
+
return { dynamic_employee: { degrees_of_separation: count(wire["degreesOfSeparation"], `${where}.degreesOfSeparation`), auto_approve_on_missing: auto } };
|
|
70
|
+
}
|
|
71
|
+
case "resolvedQuery":
|
|
72
|
+
return {
|
|
73
|
+
resolved_query: {
|
|
74
|
+
...(wire["filter"] !== undefined ? { filter: filterValue(wire["filter"], `${where}.filter`, ctx) } : {}),
|
|
75
|
+
...countsToTf(wire, where),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
case "runtimeUser":
|
|
79
|
+
if (!conditional)
|
|
80
|
+
throw new EntityTfError(`${where}: a runtime approver can only be a priorityGroup conditional`);
|
|
81
|
+
return { user: { supplied_at_runtime: true } };
|
|
82
|
+
case "runtimeGroup":
|
|
83
|
+
if (!conditional)
|
|
84
|
+
throw new EntityTfError(`${where}: a runtime approver can only be a priorityGroup conditional`);
|
|
85
|
+
return { group: { supplied_at_runtime: true, ...countsToTf(wire, where) } };
|
|
86
|
+
}
|
|
87
|
+
throw new EntityTfError(`${where}: unknown approver kind ${JSON.stringify(wire["kind"])}`);
|
|
88
|
+
}
|
|
89
|
+
/** The `approvers` list for authored steps. Any step that cannot be built fails the build. */
|
|
90
|
+
export function approvalStepsToTf(steps, where, ctx) {
|
|
91
|
+
return steps.map((raw, index) => {
|
|
92
|
+
const at = `${where}[${index}]`;
|
|
93
|
+
const wire = asWire(raw, at);
|
|
94
|
+
if (wire["kind"] !== "priorityGroup")
|
|
95
|
+
return approverToTf(wire, at, ctx, false);
|
|
96
|
+
const threshold = wire["threshold"];
|
|
97
|
+
const conditionals = wire["conditionals"];
|
|
98
|
+
if (!Array.isArray(conditionals) || conditionals.length === 0)
|
|
99
|
+
throw new EntityTfError(`${at}: a priorityGroup needs conditionals`);
|
|
100
|
+
return {
|
|
101
|
+
priority_group: {
|
|
102
|
+
...(threshold !== undefined ? { threshold: countsToTf(asWire(threshold, `${at}.threshold`), `${at}.threshold`) } : {}),
|
|
103
|
+
conditionals: conditionals.map((rawConditional, k) => {
|
|
104
|
+
const cat = `${at}.conditionals[${k}]`;
|
|
105
|
+
const conditional = asWire(rawConditional, cat);
|
|
106
|
+
return {
|
|
107
|
+
...(conditional["when"] !== undefined ? { conditions: filterValue(conditional["when"], `${cat}.when`, ctx) } : {}),
|
|
108
|
+
approver: approverToTf(asWire(conditional["approver"], `${cat}.approver`), `${cat}.approver`, ctx, true),
|
|
109
|
+
};
|
|
110
|
+
}),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function obj(value, where) {
|
|
116
|
+
if (value === null || value === undefined || typeof value !== "object" || Array.isArray(value))
|
|
117
|
+
throw new EntityTfError(`${where}: expected an object`);
|
|
118
|
+
if ("$expr" in value)
|
|
119
|
+
throw new EntityTfError(`${where}: expected an object`);
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
function pulledCount(attrs, key, where) {
|
|
123
|
+
const value = attrs[key];
|
|
124
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0)
|
|
125
|
+
throw new EntityTfError(`${where}.${key}: must be a literal integer >= 0`);
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
function pulledCounts(attrs, where) {
|
|
129
|
+
return { approvalsRequired: pulledCount(attrs, "approvals_required", where), denialsRequired: pulledCount(attrs, "denials_required", where) };
|
|
130
|
+
}
|
|
131
|
+
function only(attrs, allowed, where) {
|
|
132
|
+
for (const key of Object.keys(attrs))
|
|
133
|
+
if (!allowed.includes(key))
|
|
134
|
+
throw new EntityTfError(`${where}: unknown attribute ${key}`);
|
|
135
|
+
}
|
|
136
|
+
// A filter field that is not a field of the owner (unresolved, or another
|
|
137
|
+
// kind of left side) cannot be authored. Throwing here leaves the whole step
|
|
138
|
+
// list out, unmanaged, with a diagnostic, never a placeholder in source.
|
|
139
|
+
function requireAuthorableFilter(filter, where) {
|
|
140
|
+
const check = (ref) => {
|
|
141
|
+
if (ref.kind === "field")
|
|
142
|
+
return "";
|
|
143
|
+
if (ref.kind === "unresolved")
|
|
144
|
+
throw new EntityTfError(`${where}: filter field ${JSON.stringify(ref.uuid)} is not a field this pull can name`);
|
|
145
|
+
throw new EntityTfError(`${where}: filter left-hand side kind ${JSON.stringify(ref.kind)} cannot be authored`);
|
|
146
|
+
};
|
|
147
|
+
printFilter(filter, { field: check, reference: check });
|
|
148
|
+
return filter;
|
|
149
|
+
}
|
|
150
|
+
function pulledFilter(value, where, owner, ctx) {
|
|
151
|
+
return requireAuthorableFilter(pulledFilterUnchecked(value, where, owner, ctx), where);
|
|
152
|
+
}
|
|
153
|
+
function pulledFilterUnchecked(value, where, owner, ctx) {
|
|
154
|
+
return filterFromTf(value, {
|
|
155
|
+
type: owner.scope === "element" ? "elementum_element" : "elementum_app",
|
|
156
|
+
label: owner.appTfLabel,
|
|
157
|
+
ownerRefName: tfLabelToTsLabel(owner.appTfLabel),
|
|
158
|
+
ownerTfLabel: owner.appTfLabel,
|
|
159
|
+
scope: owner.scope,
|
|
160
|
+
foreignFieldRefsById: ctx.foreignFieldRefsById,
|
|
161
|
+
}, where, ctx, { optionLookupsAsTextOption: true });
|
|
162
|
+
}
|
|
163
|
+
function pulledUser(value, where, ctx) {
|
|
164
|
+
const label = dataRefLabel(value, "elementum_user");
|
|
165
|
+
const email = label === undefined ? undefined : ctx.dataName("elementum_user", label);
|
|
166
|
+
if (email === undefined || !email.includes("@"))
|
|
167
|
+
throw new EntityTfError(`${where}: user_id is not a data.elementum_user lookup by email`);
|
|
168
|
+
return { __kind: "user", email: email.trim() };
|
|
169
|
+
}
|
|
170
|
+
function pulledGroup(value, where, ctx) {
|
|
171
|
+
const label = dataRefLabel(value, "elementum_group");
|
|
172
|
+
const name = label === undefined ? undefined : ctx.dataName("elementum_group", label);
|
|
173
|
+
if (label === undefined || name === undefined || name === "")
|
|
174
|
+
throw new EntityTfError(`${where}: group_id is not a data.elementum_group lookup by name`);
|
|
175
|
+
return { __kind: "group", refName: groupCatalogKey(ctx, label, name), name };
|
|
176
|
+
}
|
|
177
|
+
function pulledApprover(attrs, where, owner, ctx, conditional) {
|
|
178
|
+
const keys = Object.keys(attrs).filter((key) => attrs[key] !== null && attrs[key] !== undefined);
|
|
179
|
+
if (keys.length !== 1)
|
|
180
|
+
throw new EntityTfError(`${where}: must set exactly one approver`);
|
|
181
|
+
const key = keys[0];
|
|
182
|
+
const inner = obj(attrs[key], `${where}.${key}`);
|
|
183
|
+
const at = `${where}.${key}`;
|
|
184
|
+
switch (key) {
|
|
185
|
+
case "user":
|
|
186
|
+
if (inner["supplied_at_runtime"] === true && conditional) {
|
|
187
|
+
only(inner, ["supplied_at_runtime"], at);
|
|
188
|
+
return { kind: "runtimeUser" };
|
|
189
|
+
}
|
|
190
|
+
only(inner, ["user_id"], at);
|
|
191
|
+
return { kind: "user", user: pulledUser(inner["user_id"], at, ctx) };
|
|
192
|
+
case "group":
|
|
193
|
+
if (inner["supplied_at_runtime"] === true && conditional) {
|
|
194
|
+
only(inner, ["supplied_at_runtime", "approvals_required", "denials_required"], at);
|
|
195
|
+
return { kind: "runtimeGroup", ...pulledCounts(inner, at) };
|
|
196
|
+
}
|
|
197
|
+
only(inner, ["group_id", "approvals_required", "denials_required"], at);
|
|
198
|
+
return { kind: "group", group: pulledGroup(inner["group_id"], at, ctx), ...pulledCounts(inner, at) };
|
|
199
|
+
case "dynamic_employee": {
|
|
200
|
+
only(inner, ["degrees_of_separation", "auto_approve_on_missing"], at);
|
|
201
|
+
const auto = inner["auto_approve_on_missing"];
|
|
202
|
+
if (typeof auto !== "boolean")
|
|
203
|
+
throw new EntityTfError(`${at}.auto_approve_on_missing: must be a literal boolean`);
|
|
204
|
+
return { kind: "dynamicEmployee", degreesOfSeparation: pulledCount(inner, "degrees_of_separation", at), autoApproveOnMissing: auto };
|
|
205
|
+
}
|
|
206
|
+
case "resolved_query":
|
|
207
|
+
only(inner, ["filter", "approvals_required", "denials_required"], at);
|
|
208
|
+
return {
|
|
209
|
+
kind: "resolvedQuery",
|
|
210
|
+
...(inner["filter"] !== undefined && inner["filter"] !== null ? { filter: pulledFilter(inner["filter"], `${at}.filter`, owner, ctx) } : {}),
|
|
211
|
+
...pulledCounts(inner, at),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
throw new EntityTfError(`${where}: unknown approver ${key}`);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The authored steps of a pulled `approvers` list. Throws when any step
|
|
218
|
+
* cannot be authored: the caller then leaves every step out (unmanaged)
|
|
219
|
+
* rather than author a list the provider would reconcile by deleting.
|
|
220
|
+
*/
|
|
221
|
+
export function approvalStepsFromTf(value, where, owner, ctx) {
|
|
222
|
+
if (!Array.isArray(value))
|
|
223
|
+
throw new EntityTfError(`${where}: approvers must be a list`);
|
|
224
|
+
return value.map((raw, index) => {
|
|
225
|
+
const at = `${where}[${index}]`;
|
|
226
|
+
const attrs = obj(raw, at);
|
|
227
|
+
if (attrs["priority_group"] === undefined || attrs["priority_group"] === null) {
|
|
228
|
+
const approver = pulledApprover(attrs, at, owner, ctx, false);
|
|
229
|
+
if (approver.kind === "runtimeUser" || approver.kind === "runtimeGroup")
|
|
230
|
+
throw new EntityTfError(`${at}: a runtime approver cannot be a step`);
|
|
231
|
+
return approver;
|
|
232
|
+
}
|
|
233
|
+
if (Object.keys(attrs).length !== 1)
|
|
234
|
+
throw new EntityTfError(`${at}: must set exactly one approver`);
|
|
235
|
+
const group = obj(attrs["priority_group"], `${at}.priority_group`);
|
|
236
|
+
only(group, ["threshold", "conditionals"], `${at}.priority_group`);
|
|
237
|
+
const conditionals = group["conditionals"];
|
|
238
|
+
if (!Array.isArray(conditionals) || conditionals.length === 0)
|
|
239
|
+
throw new EntityTfError(`${at}.priority_group.conditionals: must be a non-empty list`);
|
|
240
|
+
return {
|
|
241
|
+
kind: "priorityGroup",
|
|
242
|
+
...(group["threshold"] !== undefined && group["threshold"] !== null ? { threshold: pulledCounts(obj(group["threshold"], `${at}.priority_group.threshold`), `${at}.priority_group.threshold`) } : {}),
|
|
243
|
+
conditionals: conditionals.map((rawConditional, k) => {
|
|
244
|
+
const cat = `${at}.priority_group.conditionals[${k}]`;
|
|
245
|
+
const conditional = obj(rawConditional, cat);
|
|
246
|
+
only(conditional, ["conditions", "approver"], cat);
|
|
247
|
+
const when = conditional["conditions"];
|
|
248
|
+
return {
|
|
249
|
+
...(when !== undefined && when !== null ? { when: pulledFilter(when, `${cat}.conditions`, owner, ctx) } : {}),
|
|
250
|
+
approver: pulledApprover(obj(conditional["approver"], `${cat}.approver`), `${cat}.approver`, owner, ctx, true),
|
|
251
|
+
};
|
|
252
|
+
}),
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { GroupRef } from "../../catalog/index.js";
|
|
2
|
+
import type { Filter } from "../shared/filters/types.js";
|
|
3
|
+
import type { RoleUserRef } from "../role/build.js";
|
|
4
|
+
export interface ApprovalCounts {
|
|
5
|
+
readonly approvalsRequired: number;
|
|
6
|
+
readonly denialsRequired: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ApprovalUserStep {
|
|
9
|
+
readonly kind: "user";
|
|
10
|
+
readonly user: RoleUserRef;
|
|
11
|
+
}
|
|
12
|
+
export interface ApprovalGroupStep extends ApprovalCounts {
|
|
13
|
+
readonly kind: "group";
|
|
14
|
+
readonly group: GroupRef;
|
|
15
|
+
}
|
|
16
|
+
export interface ApprovalDynamicEmployeeStep {
|
|
17
|
+
readonly kind: "dynamicEmployee";
|
|
18
|
+
/** Levels above the requester (1 is the direct manager). */
|
|
19
|
+
readonly degreesOfSeparation: number;
|
|
20
|
+
/** Approve the step when the requester has no manager at that level. */
|
|
21
|
+
readonly autoApproveOnMissing: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ApprovalResolvedQueryStep extends ApprovalCounts {
|
|
24
|
+
readonly kind: "resolvedQuery";
|
|
25
|
+
/** The users the filter resolves approve. */
|
|
26
|
+
readonly filter?: Filter;
|
|
27
|
+
}
|
|
28
|
+
/** A user supplied when the approval starts; priority-group conditionals only. */
|
|
29
|
+
export interface ApprovalRuntimeUser {
|
|
30
|
+
readonly kind: "runtimeUser";
|
|
31
|
+
}
|
|
32
|
+
/** A group supplied when the approval starts; priority-group conditionals only. */
|
|
33
|
+
export interface ApprovalRuntimeGroup extends ApprovalCounts {
|
|
34
|
+
readonly kind: "runtimeGroup";
|
|
35
|
+
}
|
|
36
|
+
export type ApprovalConditionalApprover = ApprovalUserStep | ApprovalGroupStep | ApprovalDynamicEmployeeStep | ApprovalResolvedQueryStep | ApprovalRuntimeUser | ApprovalRuntimeGroup;
|
|
37
|
+
export interface ApprovalConditional {
|
|
38
|
+
/** The record conditions under which this approver applies; omit to always apply. */
|
|
39
|
+
readonly when?: Filter;
|
|
40
|
+
readonly approver: ApprovalConditionalApprover;
|
|
41
|
+
}
|
|
42
|
+
export interface ApprovalPriorityGroup {
|
|
43
|
+
readonly kind: "priorityGroup";
|
|
44
|
+
readonly threshold?: ApprovalCounts;
|
|
45
|
+
readonly conditionals: readonly ApprovalConditional[];
|
|
46
|
+
}
|
|
47
|
+
export type ApprovalStep = ApprovalUserStep | ApprovalGroupStep | ApprovalDynamicEmployeeStep | ApprovalResolvedQueryStep | ApprovalPriorityGroup;
|
|
48
|
+
/** A fixed user approves: `userStep(userRef("pat@example.com"))`. */
|
|
49
|
+
export declare function userStep(user: RoleUserRef): ApprovalUserStep;
|
|
50
|
+
/** A fixed group approves: `groupStep(org.groups.finance, { approvalsRequired: 1, denialsRequired: 1 })`. */
|
|
51
|
+
export declare function groupStep(group: GroupRef, options: ApprovalCounts): ApprovalGroupStep;
|
|
52
|
+
/** The requester's manager chain approves. */
|
|
53
|
+
export declare function dynamicEmployeeStep(options: {
|
|
54
|
+
readonly degreesOfSeparation: number;
|
|
55
|
+
readonly autoApproveOnMissing: boolean;
|
|
56
|
+
}): ApprovalDynamicEmployeeStep;
|
|
57
|
+
/** The users a filter resolves approve. */
|
|
58
|
+
export declare function resolvedQueryStep(options: ApprovalCounts & {
|
|
59
|
+
readonly filter?: Filter;
|
|
60
|
+
}): ApprovalResolvedQueryStep;
|
|
61
|
+
/** A user supplied when the approval starts. Only valid as a priority-group conditional approver. */
|
|
62
|
+
export declare function runtimeUser(): ApprovalRuntimeUser;
|
|
63
|
+
/** A group supplied when the approval starts. Only valid as a priority-group conditional approver. */
|
|
64
|
+
export declare function runtimeGroup(options: ApprovalCounts): ApprovalRuntimeGroup;
|
|
65
|
+
/** Conditional approvers; needs `dynamicChain: true` on the approval process. */
|
|
66
|
+
export declare function priorityGroup(options: {
|
|
67
|
+
readonly threshold?: ApprovalCounts;
|
|
68
|
+
readonly conditionals: readonly ApprovalConditional[];
|
|
69
|
+
}): ApprovalPriorityGroup;
|
|
70
|
+
/** Checks a step list: no runtime approver as a step, priority groups only on a dynamic chain. */
|
|
71
|
+
export declare function validateApprovalSteps(steps: readonly ApprovalStep[], dynamicChain: boolean): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approver steps of an approval process (edk#373), in order. Users are named
|
|
3
|
+
* by email (`userRef(...)`) and groups by their `org.groups` token, so the
|
|
4
|
+
* source carries no platform ids; build turns them into `data.elementum_user`
|
|
5
|
+
* and `data.elementum_group` lookups.
|
|
6
|
+
*
|
|
7
|
+
* A runtime approver (`runtimeUser()`, `runtimeGroup(...)`), supplied when the
|
|
8
|
+
* approval starts, is only valid as a priority-group conditional, and
|
|
9
|
+
* priority groups only on a dynamic chain (`dynamicChain: true`).
|
|
10
|
+
*/
|
|
11
|
+
import { EdkValidationError } from "../../../elementum-entity-client/errors.js";
|
|
12
|
+
function counts(where, options) {
|
|
13
|
+
const { approvalsRequired, denialsRequired } = options;
|
|
14
|
+
for (const [name, value] of [["approvalsRequired", approvalsRequired], ["denialsRequired", denialsRequired]]) {
|
|
15
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
16
|
+
throw new EdkValidationError(`${where}: ${name} must be an integer >= 0 (got ${String(value)}).`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { approvalsRequired, denialsRequired };
|
|
20
|
+
}
|
|
21
|
+
/** A fixed user approves: `userStep(userRef("pat@example.com"))`. */
|
|
22
|
+
export function userStep(user) {
|
|
23
|
+
if (user?.__kind !== "user" || typeof user.email !== "string" || !user.email.includes("@")) {
|
|
24
|
+
throw new EdkValidationError("userStep requires userRef(email).");
|
|
25
|
+
}
|
|
26
|
+
return { kind: "user", user };
|
|
27
|
+
}
|
|
28
|
+
/** A fixed group approves: `groupStep(org.groups.finance, { approvalsRequired: 1, denialsRequired: 1 })`. */
|
|
29
|
+
export function groupStep(group, options) {
|
|
30
|
+
if (group?.__kind !== "group")
|
|
31
|
+
throw new EdkValidationError("groupStep requires an org.groups token.");
|
|
32
|
+
return { kind: "group", group, ...counts("groupStep", options) };
|
|
33
|
+
}
|
|
34
|
+
/** The requester's manager chain approves. */
|
|
35
|
+
export function dynamicEmployeeStep(options) {
|
|
36
|
+
if (!Number.isInteger(options.degreesOfSeparation) || options.degreesOfSeparation < 0) {
|
|
37
|
+
throw new EdkValidationError("dynamicEmployeeStep: degreesOfSeparation must be an integer >= 0.");
|
|
38
|
+
}
|
|
39
|
+
return { kind: "dynamicEmployee", degreesOfSeparation: options.degreesOfSeparation, autoApproveOnMissing: options.autoApproveOnMissing };
|
|
40
|
+
}
|
|
41
|
+
/** The users a filter resolves approve. */
|
|
42
|
+
export function resolvedQueryStep(options) {
|
|
43
|
+
return { kind: "resolvedQuery", ...counts("resolvedQueryStep", options), ...(options.filter !== undefined ? { filter: options.filter } : {}) };
|
|
44
|
+
}
|
|
45
|
+
/** A user supplied when the approval starts. Only valid as a priority-group conditional approver. */
|
|
46
|
+
export function runtimeUser() {
|
|
47
|
+
return { kind: "runtimeUser" };
|
|
48
|
+
}
|
|
49
|
+
/** A group supplied when the approval starts. Only valid as a priority-group conditional approver. */
|
|
50
|
+
export function runtimeGroup(options) {
|
|
51
|
+
return { kind: "runtimeGroup", ...counts("runtimeGroup", options) };
|
|
52
|
+
}
|
|
53
|
+
/** Conditional approvers; needs `dynamicChain: true` on the approval process. */
|
|
54
|
+
export function priorityGroup(options) {
|
|
55
|
+
if (options.conditionals.length === 0)
|
|
56
|
+
throw new EdkValidationError("priorityGroup needs at least one conditional.");
|
|
57
|
+
for (const conditional of options.conditionals) {
|
|
58
|
+
const kind = conditional?.approver?.kind;
|
|
59
|
+
if (!["user", "group", "dynamicEmployee", "resolvedQuery", "runtimeUser", "runtimeGroup"].includes(String(kind))) {
|
|
60
|
+
throw new EdkValidationError("priorityGroup conditionals need an approver: userStep, groupStep, dynamicEmployeeStep, resolvedQueryStep, runtimeUser or runtimeGroup.");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
kind: "priorityGroup",
|
|
65
|
+
...(options.threshold !== undefined ? { threshold: counts("priorityGroup threshold", options.threshold) } : {}),
|
|
66
|
+
conditionals: options.conditionals,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Checks a step list: no runtime approver as a step, priority groups only on a dynamic chain. */
|
|
70
|
+
export function validateApprovalSteps(steps, dynamicChain) {
|
|
71
|
+
steps.forEach((step, index) => {
|
|
72
|
+
const kind = step?.kind;
|
|
73
|
+
if (kind === "runtimeUser" || kind === "runtimeGroup") {
|
|
74
|
+
throw new EdkValidationError(`approvalProcess steps[${index}]: a runtime approver cannot be a step; use it as a priorityGroup conditional.`);
|
|
75
|
+
}
|
|
76
|
+
if (kind === "priorityGroup" && !dynamicChain) {
|
|
77
|
+
throw new EdkValidationError(`approvalProcess steps[${index}]: priorityGroup needs dynamicChain: true.`);
|
|
78
|
+
}
|
|
79
|
+
if (!["user", "group", "dynamicEmployee", "resolvedQuery", "priorityGroup"].includes(String(kind))) {
|
|
80
|
+
throw new EdkValidationError(`approvalProcess steps[${index}]: not an approver step (use userStep, groupStep, dynamicEmployeeStep, resolvedQueryStep or priorityGroup).`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { type DeployableEntity } from "../../engine/entity.js";
|
|
2
|
-
import { type TfBlock } from "../../engine/tf/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
|
|
3
|
+
import type { OrgRefLookup } from "../../engine/build/context.js";
|
|
4
|
+
export interface ApprovalChainToTfContext {
|
|
5
|
+
readonly appRefName: string;
|
|
6
|
+
/** The owning app's or element's Terraform label. */
|
|
7
|
+
readonly appTfLabel: string;
|
|
8
|
+
/** The owner kind (edk#373); defaults to app for direct callers. */
|
|
9
|
+
readonly parentScope?: ChildResourceScope;
|
|
10
|
+
readonly stageKeyByTfLabel?: ReadonlyMap<string, string>;
|
|
11
|
+
/** Resolves user and group lookups for approver steps (edk#373). */
|
|
12
|
+
readonly orgRefs?: OrgRefLookup;
|
|
13
|
+
readonly diagnostics?: string[];
|
|
14
|
+
/** Authored custom field addresses so a locked system-keyed field prefers the custom resource (#1871). */
|
|
15
|
+
readonly fieldAddresses?: ReadonlyMap<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export declare function approvalChainToTf(entity: DeployableEntity, ctx: ApprovalChainToTfContext): {
|
|
8
18
|
blocks: readonly TfBlock[];
|
|
9
19
|
address: string;
|
|
10
20
|
};
|