@elementumai/edk 0.9.20 → 0.10.2
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 +19 -7
- package/dist-sdk/src/catalog/factories.d.ts +10 -2
- package/dist-sdk/src/catalog/factories.js +10 -1
- package/dist-sdk/src/catalog/index.d.ts +2 -2
- package/dist-sdk/src/catalog/index.js +1 -1
- package/dist-sdk/src/catalog/token.js +4 -0
- package/dist-sdk/src/catalog/types.d.ts +7 -1
- package/dist-sdk/src/catalog/types.js +1 -0
- package/dist-sdk/src/core/triggers/on-demand.d.ts +2 -2
- package/dist-sdk/src/core/triggers/on-demand.js +7 -0
- package/dist-sdk/src/core/types/app.d.ts +2 -2
- package/dist-sdk/src/engine/coverage-gaps.d.ts +86 -0
- package/dist-sdk/src/engine/coverage-gaps.js +156 -0
- package/dist-sdk/src/engine/ei/run.d.ts +21 -1
- package/dist-sdk/src/engine/ei/run.js +89 -2
- package/dist-sdk/src/engine/pull/catalog-ref.d.ts +16 -0
- package/dist-sdk/src/engine/pull/catalog-ref.js +24 -0
- package/dist-sdk/src/engine/pull/context.d.ts +68 -6
- package/dist-sdk/src/engine/pull/context.js +40 -1
- package/dist-sdk/src/engine/pull/procedure-refs.d.ts +8 -0
- package/dist-sdk/src/engine/pull/procedure-refs.js +28 -0
- package/dist-sdk/src/engine/pull/result-output.js +27 -1
- package/dist-sdk/src/engine/tf/index.d.ts +1 -1
- package/dist-sdk/src/engine/tf/index.js +1 -1
- package/dist-sdk/src/engine/tf/labels.d.ts +22 -5
- package/dist-sdk/src/engine/tf/labels.js +45 -3
- package/dist-sdk/src/engine/tf/parse.js +3 -2
- package/dist-sdk/src/engine/validation.d.ts +5 -0
- package/dist-sdk/src/engine/validation.js +12 -2
- package/dist-sdk/src/entities/access-policy/from-tf.js +38 -1
- package/dist-sdk/src/entities/access-policy/principal.d.ts +2 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +3 -0
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +42 -19
- package/dist-sdk/src/entities/agent/from-tf.js +11 -3
- package/dist-sdk/src/entities/agent/module.js +2 -0
- package/dist-sdk/src/entities/agent/to-tf.js +14 -3
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +8 -1
- package/dist-sdk/src/entities/agent-tool/from-tf.js +11 -5
- package/dist-sdk/src/entities/agent-tool/module.js +3 -0
- package/dist-sdk/src/entities/app/auto-share.d.ts +38 -0
- package/dist-sdk/src/entities/app/auto-share.js +49 -0
- package/dist-sdk/src/entities/app/build.d.ts +17 -3
- package/dist-sdk/src/entities/app/build.js +56 -4
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +6 -1
- package/dist-sdk/src/entities/app/from-tf.js +4 -0
- package/dist-sdk/src/entities/app/index.d.ts +2 -1
- package/dist-sdk/src/entities/app/index.js +1 -8
- package/dist-sdk/src/entities/app/module.js +2 -1
- package/dist-sdk/src/entities/app/to-tf.d.ts +6 -0
- package/dist-sdk/src/entities/app/to-tf.js +25 -2
- package/dist-sdk/src/entities/automation/build.d.ts +12 -2
- package/dist-sdk/src/entities/automation/build.js +105 -17
- package/dist-sdk/src/entities/automation/calculation-expression.d.ts +7 -7
- package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +17 -4
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +187 -27
- package/dist-sdk/src/entities/automation/from-tf.d.ts +9 -2
- package/dist-sdk/src/entities/automation/from-tf.js +397 -89
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/index.js +1 -1
- package/dist-sdk/src/entities/automation/module.d.ts +3 -0
- package/dist-sdk/src/entities/automation/module.js +70 -7
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +21 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +38 -0
- package/dist-sdk/src/entities/automation/script-code.d.ts +5 -2
- package/dist-sdk/src/entities/automation/script-code.js +23 -5
- package/dist-sdk/src/entities/automation/task-output-labels.d.ts +37 -0
- package/dist-sdk/src/entities/automation/task-output-labels.js +76 -0
- package/dist-sdk/src/entities/automation/tasks.d.ts +92 -20
- package/dist-sdk/src/entities/automation/tasks.js +48 -15
- package/dist-sdk/src/entities/automation/to-tf.d.ts +20 -3
- package/dist-sdk/src/entities/automation/to-tf.js +656 -65
- package/dist-sdk/src/entities/automation/triggers.d.ts +8 -4
- package/dist-sdk/src/entities/automation/types.d.ts +9 -0
- package/dist-sdk/src/entities/automation/types.js +19 -0
- package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +1 -1
- package/dist-sdk/src/entities/automation/value-ref-tf.js +1 -1
- package/dist-sdk/src/entities/chart/from-tf.js +9 -1
- package/dist-sdk/src/entities/data-lookup/module.js +2 -0
- package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/dynamic-layout/to-tf.js +7 -5
- package/dist-sdk/src/entities/element/build.d.ts +3 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/from-tf.js +4 -0
- package/dist-sdk/src/entities/element/module.js +2 -1
- package/dist-sdk/src/entities/element/to-tf.d.ts +1 -1
- package/dist-sdk/src/entities/element/to-tf.js +12 -14
- package/dist-sdk/src/entities/field/build.d.ts +3 -2
- package/dist-sdk/src/entities/field/calc.d.ts +7 -7
- package/dist-sdk/src/entities/field/from-tf.d.ts +4 -4
- package/dist-sdk/src/entities/field/from-tf.js +255 -80
- package/dist-sdk/src/entities/field/module.d.ts +6 -0
- package/dist-sdk/src/entities/field/module.js +23 -2
- package/dist-sdk/src/entities/field/options.js +6 -1
- package/dist-sdk/src/entities/field/order.d.ts +16 -0
- package/dist-sdk/src/entities/field/order.js +41 -0
- package/dist-sdk/src/entities/field/to-tf.d.ts +4 -4
- package/dist-sdk/src/entities/field/to-tf.js +7 -1
- package/dist-sdk/src/entities/field/types.d.ts +7 -0
- package/dist-sdk/src/entities/field/types.js +32 -0
- package/dist-sdk/src/entities/role/from-tf.js +3 -3
- package/dist-sdk/src/entities/role/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/role/to-tf.js +12 -4
- package/dist-sdk/src/entities/service-account/from-tf.js +3 -3
- package/dist-sdk/src/entities/service-account/workspace-owner.d.ts +16 -0
- package/dist-sdk/src/entities/service-account/workspace-owner.js +22 -0
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -1
- package/dist-sdk/src/entities/shared/filters/ast.js +2 -0
- package/dist-sdk/src/entities/shared/filters/index.d.ts +5 -0
- package/dist-sdk/src/entities/shared/filters/index.js +5 -0
- package/dist-sdk/src/entities/shared/filters/print.js +7 -2
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +5 -0
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +42 -7
- package/dist-sdk/src/entities/shared/filters/types.d.ts +8 -3
- package/dist-sdk/src/entities/shared/ref.d.ts +5 -7
- package/dist-sdk/src/entities/shared/ref.js +5 -7
- package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +9 -0
- package/dist-sdk/src/entities/shared/tool-field-ref.js +35 -2
- package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -0
- package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
- package/dist-sdk/src/entities/skill/access-policy.js +3 -3
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +3 -0
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +12 -5
- package/dist-sdk/src/entities/skill/from-tf.js +4 -2
- package/dist-sdk/src/entities/skill/module.js +2 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +41 -8
- package/dist-sdk/src/entities/skill-tool/module.js +3 -0
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +0 -6
- package/dist-sdk/src/entities/skill-tool/to-tf.js +22 -9
- package/dist-sdk/src/entities/task/build.d.ts +8 -0
- package/dist-sdk/src/entities/task/build.js +10 -1
- package/dist-sdk/src/entities/task/from-tf.d.ts +4 -2
- package/dist-sdk/src/entities/task/from-tf.js +7 -2
- package/dist-sdk/src/entities/task/module.js +3 -2
- package/dist-sdk/src/entities/task/to-tf.d.ts +8 -4
- package/dist-sdk/src/entities/task/to-tf.js +32 -1
- package/dist-sdk/src/entities/view/from-tf.js +9 -1
- package/dist-sdk/src/entities/view/module.js +4 -1
- package/dist-sdk/src/entities/view/to-tf.d.ts +6 -7
- package/dist-sdk/src/entities/view/to-tf.js +30 -11
- package/dist-sdk/src/entities/view/types.d.ts +6 -0
- package/dist-sdk/src/entities/view/types.js +6 -0
- package/dist-sdk/src/entities/visual-flow/build.d.ts +16 -1
- package/dist-sdk/src/entities/visual-flow/build.js +9 -0
- package/dist-sdk/src/entities/visual-flow/from-tf.d.ts +14 -0
- package/dist-sdk/src/entities/visual-flow/from-tf.js +51 -3
- package/dist-sdk/src/entities/visual-flow/index.d.ts +1 -1
- package/dist-sdk/src/entities/visual-flow/index.js +1 -1
- package/dist-sdk/src/entities/visual-flow/printer.js +19 -0
- package/dist-sdk/src/entities/visual-flow/to-tf.js +87 -3
- package/dist-sdk/src/entities/widget/from-tf.js +3 -3
- package/dist-sdk/src/entities/widget/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/widget/to-tf.js +7 -6
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +133 -9
- package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
- package/dist-sdk/src/graph/index.d.ts +4 -2
- package/dist-sdk/src/graph/index.js +3 -0
- package/dist-sdk/src/graph/modules.js +2 -1
- package/dist-sdk/src/graph/types.d.ts +41 -3
- package/package.json +7 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityTfError, recordFieldContextOf } from "../../engine/entity.js";
|
|
2
|
-
import { ValidationFailureError } from "../../engine/validation.js";
|
|
3
|
-
import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET
|
|
2
|
+
import { currentValidationMode, recordValidations, ValidationFailureError } from "../../engine/validation.js";
|
|
3
|
+
import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
|
|
4
4
|
import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
|
|
5
5
|
import { isUnsafePlatformId } from "../../core/platform-id.js";
|
|
6
6
|
import { appResourceLabelPrefix, appScopedResourceLabel, expr, isTfExpr, isUuid, sanitizeName, stableIdSuffix, scopedResourceLabel, tfLabelToTsLabel, tsLabelToTfLabel, } from "../../engine/tf/index.js";
|
|
@@ -11,22 +11,36 @@ import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
|
|
|
11
11
|
import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
|
|
12
12
|
import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
|
|
13
13
|
import { referenceValueTypeForField } from "../shared/filters/index.js";
|
|
14
|
-
import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES } from "./output-key-wire-name.js";
|
|
14
|
+
import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES, executeScriptRefsIndex, OUTPUT_KEY_CANONICAL, OUTPUT_KEY_WIRE_NAME } from "./output-key-wire-name.js";
|
|
15
15
|
import { outputFieldTypesFromScriptSchema, scriptOutputReferenceIsDeclared } from "./output-field-types.js";
|
|
16
16
|
import { RESOURCE_TYPE_TO_EXECUTOR, TASK_OUTPUT_CONTRACTS } from "./generated/task-output-contracts.js";
|
|
17
17
|
import { CONNECTOR_ORG_BAG } from "../org/connector.js";
|
|
18
|
+
import { GROUP_ORG_BAG } from "../org/group.js";
|
|
18
19
|
import { FILE_READER_SUB_TYPE_BY_RESOURCE, FILE_READER_SUB_TYPE_BY_TYPE_KEY } from "../file-reader/types.js";
|
|
19
20
|
import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
|
|
20
21
|
import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
|
|
21
22
|
import { TABLE_RESOURCE_TYPE } from "../table/module.js";
|
|
22
|
-
import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE } from "./types.js";
|
|
23
|
-
import { AI_SEARCH_TABLE_OUTPUT_NAMES, TASK_OUTPUT_REFERENCE_NAMES, USER_SEARCH_REF_WIRE_NAMES } from "./task-output-labels.js";
|
|
23
|
+
import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE, automationResourceLabel } from "./types.js";
|
|
24
|
+
import { AI_SEARCH_TABLE_OUTPUT_NAMES, TASK_OUTPUT_REFERENCE_NAMES, TRIGGER_WHOLE_RECORD_MARKER, USER_SEARCH_REF_WIRE_NAMES, triggerAttachmentPayloadRef, triggerWholeRecordRefJson, } from "./task-output-labels.js";
|
|
24
25
|
import { onDemandTriggerRefKey } from "./value-ref-tf.js";
|
|
25
26
|
import { normalizeOnDemandParamKey } from "../../../pull/util.js";
|
|
26
27
|
import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
|
|
27
28
|
import { taskTfLabel } from "./task-label.js";
|
|
28
29
|
import { isOnDemandRecordType } from "../shared/types/field-types.js";
|
|
29
30
|
/** The context for reading records of `appRefName` (a `kind`), retargeted from the owner. */
|
|
31
|
+
/**
|
|
32
|
+
* Wire WorkflowFieldType -> elementum_on_demand_trigger `parameters[].type`.
|
|
33
|
+
* Keys are exactly the provider's OneOf enum; anything else (JSON, OBJECT)
|
|
34
|
+
* is refused at build rather than lowercased into an invalid value (#1415).
|
|
35
|
+
*/
|
|
36
|
+
const ON_DEMAND_TF_PARAM_TYPES = new Map([
|
|
37
|
+
["TEXT", "text"], ["NUMBER", "number"], ["DECIMAL", "decimal"], ["BOOLEAN", "boolean"],
|
|
38
|
+
["DATE", "date"], ["DATETIME", "datetime"], ["USER", "user"], ["USER_ID", "user"],
|
|
39
|
+
["GROUP_ID", "group"], ["ATTACHMENT_ID", "attachment"], ["ASPECT_RECORD", "record"],
|
|
40
|
+
// Already-provider spellings pass through unchanged.
|
|
41
|
+
...["text", "number", "decimal", "boolean", "date", "datetime", "user", "group", "attachment", "record"]
|
|
42
|
+
.map((t) => [t, t]),
|
|
43
|
+
]);
|
|
30
44
|
function recordOwnerContext(owner, appRefName, kind, fieldNames) {
|
|
31
45
|
if (appRefName === owner.appRefName && (kind === undefined || kind === owner.parentScope))
|
|
32
46
|
return owner;
|
|
@@ -49,6 +63,41 @@ function labelHash(value) {
|
|
|
49
63
|
}
|
|
50
64
|
return (hash >>> 0).toString(36);
|
|
51
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Terraform data label for a vault key. Keep this in lockstep with the
|
|
68
|
+
* exporter's VaultEntryLabel: readable for conventional uppercase keys and
|
|
69
|
+
* hash-suffixed whenever normalization could collide.
|
|
70
|
+
*/
|
|
71
|
+
export function vaultEntryLabel(key) {
|
|
72
|
+
let label = key.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
73
|
+
if (label === "" || /^[0-9]/.test(label))
|
|
74
|
+
label = `vault_${label}`;
|
|
75
|
+
if (label.toUpperCase() === key)
|
|
76
|
+
return label;
|
|
77
|
+
let hash = 0x811c9dc5;
|
|
78
|
+
for (const byte of new TextEncoder().encode(key)) {
|
|
79
|
+
hash ^= byte;
|
|
80
|
+
hash = Math.imul(hash, 0x01000193);
|
|
81
|
+
}
|
|
82
|
+
return `${label}_${(hash >>> 0).toString(16).padStart(8, "0")}`;
|
|
83
|
+
}
|
|
84
|
+
function vaultEntryRefToTf(key, refs) {
|
|
85
|
+
if (key === "")
|
|
86
|
+
throw new EntityTfError("secret() requires a vault entry key");
|
|
87
|
+
const label = vaultEntryLabel(key);
|
|
88
|
+
if (refs.owner.orgRefs !== undefined) {
|
|
89
|
+
refs.owner.orgRefs.rawLookup("elementum_vault_entry", label, key);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
refs.dataBlocks.set(`elementum_vault_entry.${label}`, {
|
|
93
|
+
kind: "data",
|
|
94
|
+
type: "elementum_vault_entry",
|
|
95
|
+
label,
|
|
96
|
+
attrs: { key },
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return expr.dataAttr("elementum_vault_entry", label, ["value_reference"]);
|
|
100
|
+
}
|
|
52
101
|
function scopedOptionLocalName(localName, owner) {
|
|
53
102
|
for (const suffix of ["_options_by_label", "_option_ids_by_label"]) {
|
|
54
103
|
if (!localName.endsWith(suffix))
|
|
@@ -79,9 +128,16 @@ const TRIGGER_RESOURCES = {
|
|
|
79
128
|
survey: "elementum_survey_trigger",
|
|
80
129
|
schedule: "elementum_schedule_trigger",
|
|
81
130
|
};
|
|
131
|
+
/**
|
|
132
|
+
* The live platform id of a created variable: `variables[<index>].id` on its
|
|
133
|
+
* elementum_variable_task (edk#1456; was the single-variable `variable_id`).
|
|
134
|
+
*/
|
|
135
|
+
function variableIdAttr(target) {
|
|
136
|
+
return expr.resourceAttr(target.type, target.label, ["variables", { index: String(target.index) }, "id"]);
|
|
137
|
+
}
|
|
82
138
|
/**
|
|
83
139
|
* setVariable tasks share one wire key ("variable") but two distinct
|
|
84
|
-
* resource types depending on create
|
|
140
|
+
* resource types depending on whether they create any variable — TASK_RESOURCES can't
|
|
85
141
|
* carry both under one key. Shared by preRegister (so an explicit
|
|
86
142
|
* hclParent onto an update-variant task resolves to the right type — see
|
|
87
143
|
* edk#287) and emitTasks's own block emission, so the two can never
|
|
@@ -90,14 +146,18 @@ const TRIGGER_RESOURCES = {
|
|
|
90
146
|
function variableTaskResourceType(taskBody, refKey) {
|
|
91
147
|
const creates = Array.isArray(taskBody.create) ? taskBody.create : [];
|
|
92
148
|
const updates = Array.isArray(taskBody.update) ? taskBody.update : [];
|
|
93
|
-
if (creates.length + updates.length
|
|
94
|
-
throw new EntityTfError(`setVariable task "${refKey}" must contain
|
|
149
|
+
if (creates.length + updates.length === 0) {
|
|
150
|
+
throw new EntityTfError(`setVariable task "${refKey}" must contain at least one create or update for Terraform`);
|
|
95
151
|
}
|
|
96
|
-
|
|
152
|
+
// edk#1456: a task with any create entry is an elementum_variable_task
|
|
153
|
+
// (variables, plus updates when mixed); update-only is
|
|
154
|
+
// elementum_update_variable_task (updates).
|
|
155
|
+
return creates.length > 0 ? "elementum_variable_task" : "elementum_update_variable_task";
|
|
97
156
|
}
|
|
98
157
|
const TASK_RESOURCES = {
|
|
99
158
|
message: "elementum_message_task",
|
|
100
159
|
updateField: "elementum_update_field_task",
|
|
160
|
+
bulkUpdateFields: "elementum_bulk_update_fields_task",
|
|
101
161
|
variable: "elementum_variable_task",
|
|
102
162
|
createRecord: "elementum_create_record_task",
|
|
103
163
|
recordSearch: "elementum_record_search_task",
|
|
@@ -120,6 +180,7 @@ const TASK_RESOURCES = {
|
|
|
120
180
|
aiSearchTable: "elementum_ai_search_table_task",
|
|
121
181
|
aiTransform: "elementum_ai_transform_task",
|
|
122
182
|
saveAttachment: "elementum_save_attachment_task",
|
|
183
|
+
unzip: "elementum_unzip_file_task",
|
|
123
184
|
userSearch: "elementum_user_search_task",
|
|
124
185
|
userGroupSearch: "elementum_user_group_search_task",
|
|
125
186
|
calculation: "elementum_calculation_task",
|
|
@@ -440,6 +501,19 @@ function registerForeignFieldLookup(value, ctx, dataBlocks) {
|
|
|
440
501
|
registerForeignOptionsByLabelLocal(fieldLabel, ctx);
|
|
441
502
|
return fieldLabel;
|
|
442
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* A bare platform-id target whose every input names a raw parameter id is a
|
|
506
|
+
* static run: pull prints a static export with an undiscovered target
|
|
507
|
+
* (`target_automation_id` + `input_mappings[].parameter_id`) as
|
|
508
|
+
* `automation: "<uuid>"` + `inputs[].name: "<uuid>"`. Dynamic mappings name
|
|
509
|
+
* the target's inputs, never a parameter id.
|
|
510
|
+
*/
|
|
511
|
+
function bareStaticRunTarget(config) {
|
|
512
|
+
return typeof config.targetAutomationId === "string" &&
|
|
513
|
+
Array.isArray(config.inputMappings) &&
|
|
514
|
+
config.inputMappings.length > 0 &&
|
|
515
|
+
config.inputMappings.every((mapping) => isObject(mapping) && typeof mapping.name === "string" && isUuid(mapping.name));
|
|
516
|
+
}
|
|
443
517
|
/**
|
|
444
518
|
* Resolve an automation token as a managed definition (same stream root or a
|
|
445
519
|
* sibling root in this build) or as a ref-only `data.elementum_automation`
|
|
@@ -460,8 +534,11 @@ function automationTargetToTf(value, ctx, dataBlocks) {
|
|
|
460
534
|
? sibling.tfLabel
|
|
461
535
|
: undefined;
|
|
462
536
|
if (managedOwnerLabel !== undefined) {
|
|
463
|
-
const managedLabel = scopedLabel(managedOwnerLabel, tsLabelToTfLabel(value.refName));
|
|
464
537
|
const targetOwner = ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, isOwn ? ctx.appRefName : value.parent ?? ""));
|
|
538
|
+
const managedHandle = ownerKind === "element"
|
|
539
|
+
? elementHandleOf(isOwn ? ctx.ownerHandle : undefined, targetOwner?.streamRootEntity?.payload)
|
|
540
|
+
: undefined;
|
|
541
|
+
const managedLabel = automationResourceLabel(managedOwnerLabel, value.refName, ownerKind === "element" ? "element" : "app", managedHandle);
|
|
465
542
|
const targetActiveRefs = targetOwner?.activeAutomationRefNames;
|
|
466
543
|
const isActive = targetActiveRefs !== undefined
|
|
467
544
|
? targetActiveRefs.has(value.refName)
|
|
@@ -482,7 +559,11 @@ function automationTargetToTf(value, ctx, dataBlocks) {
|
|
|
482
559
|
type: AUTOMATION_RESOURCE_TYPE,
|
|
483
560
|
label: currentBindingLabel,
|
|
484
561
|
attrs: {
|
|
485
|
-
|
|
562
|
+
// The owner id comes from the target automation itself. Referencing
|
|
563
|
+
// the app/element resource would defer this read whenever the app
|
|
564
|
+
// record has a pending change, making every parameter id unknown
|
|
565
|
+
// (edk#1514). `depends_on` still orders the read after publish.
|
|
566
|
+
app_id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, managedLabel, ["app_id"]),
|
|
486
567
|
id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, managedLabel, ["id"]),
|
|
487
568
|
depends_on: [expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, managedLabel)],
|
|
488
569
|
},
|
|
@@ -839,7 +920,24 @@ function tokenToTf(value, ctx, dataBlocks) {
|
|
|
839
920
|
// label (see ApprovalChainRef); preferring it rewrote live pulls to UUIDs.
|
|
840
921
|
const refName = typeof value.refName === "string" ? value.refName.trim() : "";
|
|
841
922
|
if (refName !== "") {
|
|
842
|
-
|
|
923
|
+
const address = `elementum_approval_process.${scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(refName))}`;
|
|
924
|
+
// Never emit a reference to an approval process this build doesn't
|
|
925
|
+
// declare (edk#1416). The build records the app's discovered
|
|
926
|
+
// approval-chain files; direct callers without that information keep
|
|
927
|
+
// the managed reference.
|
|
928
|
+
const declared = ctx.workspaceAspects
|
|
929
|
+
?.get(workspaceAspectKey("app", ctx.appRefName))
|
|
930
|
+
?.managedChildRefNames?.get("approval-chain");
|
|
931
|
+
if (declared === undefined || declared.has(refName)) {
|
|
932
|
+
return expr.resourceAttr("elementum_approval_process", scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(refName)), ["id"]);
|
|
933
|
+
}
|
|
934
|
+
if (value.unresolvedId !== undefined) {
|
|
935
|
+
ctx.diagnostics.push(`automation ${ctx.automationTfLabel}: approval chain "${refName}" is not declared in this build (${address} would be undeclared); ` +
|
|
936
|
+
`using its pulled platform id ${value.unresolvedId} instead`);
|
|
937
|
+
return value.unresolvedId;
|
|
938
|
+
}
|
|
939
|
+
throw new EntityTfError(`automation ${ctx.automationTfLabel}: approval chain "${refName}" is not declared in this build (${address} is undeclared) ` +
|
|
940
|
+
`and the reference has no unresolvedId — add approval-chains/${refName}.ts to app "${ctx.appRefName}" or reference an existing approval process`);
|
|
843
941
|
}
|
|
844
942
|
if (value.unresolvedId !== undefined)
|
|
845
943
|
return value.unresolvedId;
|
|
@@ -857,6 +955,33 @@ function tokenToTf(value, ctx, dataBlocks) {
|
|
|
857
955
|
}
|
|
858
956
|
return expr.resourceAttr(subType.resourceType, scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(value.refName)), ["id"]);
|
|
859
957
|
}
|
|
958
|
+
case "group": {
|
|
959
|
+
// Static notification/add-watcher recipients (edk#1389). An org.ts
|
|
960
|
+
// group resolves to its catalog lookup (or the managed resource), by
|
|
961
|
+
// key for an org.groups token or by name for a standalone
|
|
962
|
+
// groupRef({ name }) (whose refName is the display name). A group
|
|
963
|
+
// org.ts doesn't carry still builds as a name lookup, which is what
|
|
964
|
+
// the provider resolves anyway.
|
|
965
|
+
const refName = typeof value.refName === "string" ? value.refName : "";
|
|
966
|
+
const name = typeof value.name === "string" && value.name !== "" ? value.name : refName;
|
|
967
|
+
if (name === "")
|
|
968
|
+
throw new EntityTfError("group token has neither refName nor name");
|
|
969
|
+
const resolved = (refName !== "" ? ctx.orgRefs?.byTsLabel(GROUP_ORG_BAG, refName) : undefined)
|
|
970
|
+
?? ctx.orgRefs?.byName(GROUP_ORG_BAG, name);
|
|
971
|
+
if (resolved !== undefined) {
|
|
972
|
+
return resolved.managed === true
|
|
973
|
+
? expr.resourceAttr("elementum_group", resolved.tfLabel, ["id"])
|
|
974
|
+
: expr.dataAttr("elementum_group", resolved.tfLabel, ["id"]);
|
|
975
|
+
}
|
|
976
|
+
const label = sanitizeName(name);
|
|
977
|
+
if (ctx.orgRefs !== undefined) {
|
|
978
|
+
ctx.orgRefs.rawLookup("elementum_group", label, name);
|
|
979
|
+
}
|
|
980
|
+
else {
|
|
981
|
+
dataBlocks.set(`elementum_group.${label}`, { kind: "data", type: "elementum_group", label, attrs: { name } });
|
|
982
|
+
}
|
|
983
|
+
return expr.dataAttr("elementum_group", label, ["id"]);
|
|
984
|
+
}
|
|
860
985
|
default:
|
|
861
986
|
throw new EntityTfError(`catalog ref kind "${value.__kind}" has no automation HCL representation`);
|
|
862
987
|
}
|
|
@@ -1031,7 +1156,7 @@ function calculationFormulaRefToParts(value, refs) {
|
|
|
1031
1156
|
refs.owner.diagnostics.push(`automation unresolved variable ref ${JSON.stringify(value.variableReference.id)} preserved as a literal calculation reference`);
|
|
1032
1157
|
return [`variable.${value.variableReference.id}`];
|
|
1033
1158
|
}
|
|
1034
|
-
return ["variable.",
|
|
1159
|
+
return ["variable.", variableIdAttr(target)];
|
|
1035
1160
|
}
|
|
1036
1161
|
if (isObject(value.templateReference))
|
|
1037
1162
|
return calculationTemplateToParts(value.templateReference, refs);
|
|
@@ -1120,8 +1245,9 @@ const FOUND_RECORD_TASK_TYPES = new Set([
|
|
|
1120
1245
|
/**
|
|
1121
1246
|
* A short-form `task.<id>.<name>` value reference addresses a found record's
|
|
1122
1247
|
* field by its platform reference name `record.<fieldId>` (as ei exports it),
|
|
1123
|
-
* not by the refs-map display label.
|
|
1124
|
-
*
|
|
1248
|
+
* not by the refs-map display label. A record of an app/element outside this
|
|
1249
|
+
* build gets its field id from a `data.elementum_field` lookup. Undefined when
|
|
1250
|
+
* the field's id cannot be resolved, which keeps the display-label form.
|
|
1125
1251
|
*/
|
|
1126
1252
|
function foundRecordFieldReferenceName(targetType, name, taskRefKey, refs) {
|
|
1127
1253
|
const segments = name.split(".");
|
|
@@ -1135,10 +1261,37 @@ function foundRecordFieldReferenceName(targetType, name, taskRefKey, refs) {
|
|
|
1135
1261
|
}
|
|
1136
1262
|
catch (error) {
|
|
1137
1263
|
if (error instanceof EntityTfError)
|
|
1138
|
-
return
|
|
1264
|
+
return foreignFoundRecordFieldReferenceName(segments, taskRefKey, refs);
|
|
1139
1265
|
throw error;
|
|
1140
1266
|
}
|
|
1141
1267
|
}
|
|
1268
|
+
function foreignFoundRecordFieldReferenceName(segments, taskRefKey, refs) {
|
|
1269
|
+
const target = refs.tasks.get(taskRefKey)?.recordTarget;
|
|
1270
|
+
if (target === undefined || (target.__kind !== "app" && target.__kind !== "element") || target.name === undefined) {
|
|
1271
|
+
return undefined;
|
|
1272
|
+
}
|
|
1273
|
+
if (refs.owner.workspaceAspects?.has(workspaceAspectKey(target.__kind, target.refName)))
|
|
1274
|
+
return undefined;
|
|
1275
|
+
const fieldKey = segments[1];
|
|
1276
|
+
const fieldName = refs.fieldNamesByAppRefName?.get(target.refName)?.get(fieldKey);
|
|
1277
|
+
if (fieldName === undefined)
|
|
1278
|
+
return undefined;
|
|
1279
|
+
const fieldToken = {
|
|
1280
|
+
__kind: "field",
|
|
1281
|
+
refName: fieldKey,
|
|
1282
|
+
name: fieldName,
|
|
1283
|
+
parent: target.refName,
|
|
1284
|
+
parentKind: target.__kind,
|
|
1285
|
+
parentName: target.name,
|
|
1286
|
+
...(target.namespace !== undefined ? { parentNamespace: target.namespace } : {}),
|
|
1287
|
+
};
|
|
1288
|
+
const suffix = segments.slice(2).join(".");
|
|
1289
|
+
return [
|
|
1290
|
+
"record.",
|
|
1291
|
+
expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]),
|
|
1292
|
+
...(suffix.length > 0 ? [`.${suffix}`] : []),
|
|
1293
|
+
];
|
|
1294
|
+
}
|
|
1142
1295
|
function calculationTriggerMustache(name, refs) {
|
|
1143
1296
|
const onDemandName = onDemandTriggerRefName(name, refs);
|
|
1144
1297
|
if (onDemandName !== undefined)
|
|
@@ -1202,6 +1355,11 @@ const TS_TRIGGER_REF_TO_WIRE = {
|
|
|
1202
1355
|
// onto FIELD_REF_SUFFIX_TO_WIRE — that table's `id` suffix is " ID", which
|
|
1203
1356
|
// would emit the wrong wire key "Attachment ID" and fail live validation.
|
|
1204
1357
|
"attachment.id": "Attachment Id",
|
|
1358
|
+
// Pull decodes refs["Record"] (ASPECT_RECORD_ID) as the branded accessor
|
|
1359
|
+
// ctx.trigger.recordId (from-tf wireName "Record" → ["recordId"]). Rebuild
|
|
1360
|
+
// must emit the live key — without this entry wireRefName leaves "recordId"
|
|
1361
|
+
// verbatim and plan fails with Invalid index on refs["recordId"].
|
|
1362
|
+
recordId: "Record",
|
|
1205
1363
|
// NOT createdByEmail/updatedByManagerEmail: the real record-field path
|
|
1206
1364
|
// ("record.createdBy.email") never reaches this flat lookup table (see
|
|
1207
1365
|
// from-tf.ts's matching comment) — this table is for genuine trigger-level
|
|
@@ -1221,7 +1379,14 @@ const TS_TRIGGER_REF_TO_WIRE = {
|
|
|
1221
1379
|
body: "Body (Plain Text)",
|
|
1222
1380
|
body_html: "Body (Rich Text)",
|
|
1223
1381
|
};
|
|
1224
|
-
|
|
1382
|
+
// Exclude "Attachment Id" (attachment-trigger ATTACHMENT_ID): its
|
|
1383
|
+
// case-insensitive key collides with save_attachment's distinct live ref
|
|
1384
|
+
// "Attachment ID". Trigger paths resolve via TS_TRIGGER_REF_TO_WIRE
|
|
1385
|
+
// ("attachment.id") before this map; bracket-access "Attachment ID" must
|
|
1386
|
+
// pass through unchanged (#1651).
|
|
1387
|
+
const DISPLAY_REF_CANONICAL_CASE = Object.fromEntries(Object.values(TS_TRIGGER_REF_TO_WIRE)
|
|
1388
|
+
.filter((value) => value !== "Attachment Id")
|
|
1389
|
+
.map((value) => [value.toLowerCase(), value]));
|
|
1225
1390
|
const FIELD_REF_SUFFIX_TO_WIRE = {
|
|
1226
1391
|
"": "",
|
|
1227
1392
|
id: " ID",
|
|
@@ -1511,6 +1676,13 @@ function taskOutputWireRefKey(targetType, name, taskRefKey, refs) {
|
|
|
1511
1676
|
(name === "records" || name === "All matching table rows")) {
|
|
1512
1677
|
return "All matching table rows";
|
|
1513
1678
|
}
|
|
1679
|
+
// refs index only. Envelopes and calc mustaches keep the canonical name
|
|
1680
|
+
// (`result`, `stringArrayResult`); the provider refs map does not (#1656).
|
|
1681
|
+
if (targetType === "elementum_execute_script_task") {
|
|
1682
|
+
const scriptIndex = executeScriptRefsIndex(name);
|
|
1683
|
+
if (scriptIndex !== undefined)
|
|
1684
|
+
return scriptIndex;
|
|
1685
|
+
}
|
|
1514
1686
|
return taskWireRefName(name, taskRefKey, refs);
|
|
1515
1687
|
}
|
|
1516
1688
|
/** The platform's own on-demand "Triggered By" refs (live refs-map keys). */
|
|
@@ -1570,8 +1742,8 @@ function recordParamFieldWireName(paramName, suffix, refs) {
|
|
|
1570
1742
|
return wireRefName(`record.${suffix}`, recordOwnerContext(refs.owner, targetRefName, target.__kind === "element" || target.__kind === "app" ? target.__kind : undefined, targetFieldNames));
|
|
1571
1743
|
}
|
|
1572
1744
|
/** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
|
|
1573
|
-
export function automationRunTargetResourceAttr(appTfLabel, automationRefName, activeAutomationRefNames) {
|
|
1574
|
-
const label =
|
|
1745
|
+
export function automationRunTargetResourceAttr(appTfLabel, automationRefName, activeAutomationRefNames, scope = "app", handle) {
|
|
1746
|
+
const label = automationResourceLabel(appTfLabel, automationRefName, scope, handle);
|
|
1575
1747
|
if (activeAutomationRefNames?.has(automationRefName) === true) {
|
|
1576
1748
|
return expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, label, ["id"]);
|
|
1577
1749
|
}
|
|
@@ -1604,14 +1776,26 @@ function assertLiteralFitsFieldType(value, field) {
|
|
|
1604
1776
|
if (rule === undefined)
|
|
1605
1777
|
return;
|
|
1606
1778
|
const label = field.name ?? field.refName ?? "unknown";
|
|
1607
|
-
if (typeof value
|
|
1608
|
-
|
|
1779
|
+
if (isObject(value) && typeof value.__kind === "string") {
|
|
1780
|
+
const tokenKind = value.__kind;
|
|
1781
|
+
if ((fieldType === "USER" && tokenKind === "user") || (fieldType === "GROUP" && tokenKind === "group"))
|
|
1782
|
+
return;
|
|
1783
|
+
if (tokenKind === "user" || tokenKind === "group") {
|
|
1784
|
+
const identity = tokenKind === "user" && typeof value.email === "string"
|
|
1785
|
+
? value.email
|
|
1786
|
+
: typeof value.name === "string" ? value.name : tokenKind;
|
|
1787
|
+
throw new EntityTfError(`automation field "${label}" (${fieldType}) is given a ${tokenKind} token ${JSON.stringify(identity)}; it needs ${rule.expected}`);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
const text = isObject(value) && value.kind === "literal" && typeof value.value === "string" ? value.value : value;
|
|
1791
|
+
if (typeof text !== "string") {
|
|
1792
|
+
throw new EntityTfError(`automation field "${label}" (${fieldType}) is given a ${typeof text} literal; it needs ${rule.expected}`);
|
|
1609
1793
|
}
|
|
1610
1794
|
// The provider refuses `${...}` templates on these four types too, so a
|
|
1611
1795
|
// template string is not left to the platform here.
|
|
1612
|
-
if (rule.test(
|
|
1796
|
+
if (rule.test(text))
|
|
1613
1797
|
return;
|
|
1614
|
-
throw new EntityTfError(`automation field "${label}" (${fieldType}) is given the text ${JSON.stringify(
|
|
1798
|
+
throw new EntityTfError(`automation field "${label}" (${fieldType}) is given the text ${JSON.stringify(text)}; it needs ${rule.expected}`);
|
|
1615
1799
|
}
|
|
1616
1800
|
/**
|
|
1617
1801
|
* The platform refuses an element record create that leaves the title system
|
|
@@ -1833,7 +2017,7 @@ function workflowPublishOutputEnvelope(value, refs) {
|
|
|
1833
2017
|
return {
|
|
1834
2018
|
taskReference: null,
|
|
1835
2019
|
triggerReference: null,
|
|
1836
|
-
variableReference: { name: expr.template(["variable|",
|
|
2020
|
+
variableReference: { name: expr.template(["variable|", variableIdAttr(target)]) },
|
|
1837
2021
|
};
|
|
1838
2022
|
}
|
|
1839
2023
|
const name = typeof value.variableReference.name === "string" ? value.variableReference.name : undefined;
|
|
@@ -1913,6 +2097,84 @@ function collectUnresolvedForEachItems(value, found) {
|
|
|
1913
2097
|
for (const nested of Object.values(value))
|
|
1914
2098
|
collectUnresolvedForEachItems(nested, found);
|
|
1915
2099
|
}
|
|
2100
|
+
/** The onDemand trigger's record parameters: they expose only a record ID. */
|
|
2101
|
+
function onDemandRecordParamNames(trigger) {
|
|
2102
|
+
const inputs = trigger?.onDemand?.inputs;
|
|
2103
|
+
if (!Array.isArray(inputs))
|
|
2104
|
+
return new Set();
|
|
2105
|
+
return new Set(inputs.flatMap((input) => {
|
|
2106
|
+
const param = input;
|
|
2107
|
+
return typeof param?.name === "string" && isOnDemandRecordType(typeof param.type === "string" ? param.type : undefined) ? [param.name] : [];
|
|
2108
|
+
}));
|
|
2109
|
+
}
|
|
2110
|
+
/** refKey → task kind (`findRelatedRecords`, …) for every task, nested ones included. */
|
|
2111
|
+
function collectPayloadTaskKinds(value, kinds) {
|
|
2112
|
+
if (Array.isArray(value)) {
|
|
2113
|
+
for (const item of value)
|
|
2114
|
+
collectPayloadTaskKinds(item, kinds);
|
|
2115
|
+
return kinds;
|
|
2116
|
+
}
|
|
2117
|
+
if (!isObject(value))
|
|
2118
|
+
return kinds;
|
|
2119
|
+
if (typeof value.refKey === "string" && isObject(value.task)) {
|
|
2120
|
+
const kind = Object.keys(value.task)[0];
|
|
2121
|
+
if (kind !== undefined)
|
|
2122
|
+
kinds.set(value.refKey, kind);
|
|
2123
|
+
}
|
|
2124
|
+
for (const nested of Object.values(value))
|
|
2125
|
+
collectPayloadTaskKinds(nested, kinds);
|
|
2126
|
+
return kinds;
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* edk#1499: script-input field mappings read fields off a whole record. A
|
|
2130
|
+
* value that exposes only a record ID (an onDemand record parameter, or
|
|
2131
|
+
* findRelatedRecords' `.record`) deploys refs["Record"] (ASPECT_RECORD_ID)
|
|
2132
|
+
* plus field mappings, and the script receives `{}` at runtime. Record
|
|
2133
|
+
* triggers' `ctx.trigger.record` and the `.record` of recordSearch,
|
|
2134
|
+
* createRecord and updateField carry the whole record (#1284, #1489).
|
|
2135
|
+
*/
|
|
2136
|
+
export function recordIdFieldMappingFailures(entity, payload, address) {
|
|
2137
|
+
const onDemandRecordParams = onDemandRecordParamNames(payload.trigger);
|
|
2138
|
+
const taskKinds = collectPayloadTaskKinds(payload, new Map());
|
|
2139
|
+
const name = "name" in payload && typeof payload.name === "string" && payload.name !== "" ? payload.name : entity.refName;
|
|
2140
|
+
const failures = [];
|
|
2141
|
+
const visit = (value, action) => {
|
|
2142
|
+
if (Array.isArray(value)) {
|
|
2143
|
+
for (const item of value)
|
|
2144
|
+
visit(item, action);
|
|
2145
|
+
return;
|
|
2146
|
+
}
|
|
2147
|
+
if (!isObject(value))
|
|
2148
|
+
return;
|
|
2149
|
+
const here = typeof value.refKey === "string" && isObject(value.task) ? value.refKey : action;
|
|
2150
|
+
if (Array.isArray(value.field_mappings) && isObject(value.value)) {
|
|
2151
|
+
let source;
|
|
2152
|
+
const trigger = value.value.triggerReference;
|
|
2153
|
+
if (isObject(trigger) && typeof trigger.name === "string" && onDemandRecordParams.has(trigger.name)) {
|
|
2154
|
+
source = `ctx.trigger.${trigger.name} (an on-demand record parameter)`;
|
|
2155
|
+
}
|
|
2156
|
+
const task = value.value.taskReference;
|
|
2157
|
+
if (isObject(task) && typeof task.taskRefKey === "string" && task.name === "record" && taskKinds.get(task.taskRefKey) === "findRelatedRecords") {
|
|
2158
|
+
source = `ctx.actions.${task.taskRefKey}.record (findRelatedRecords)`;
|
|
2159
|
+
}
|
|
2160
|
+
if (source !== undefined) {
|
|
2161
|
+
failures.push({
|
|
2162
|
+
severity: "fatal",
|
|
2163
|
+
address,
|
|
2164
|
+
name,
|
|
2165
|
+
ownerKind: "automation",
|
|
2166
|
+
message: `action "${here ?? "?"}" input "${typeof value.name === "string" ? value.name : "?"}": withFieldMappings(${source}) maps fields off a value that is only a record ID, ` +
|
|
2167
|
+
"so the script would receive {} at runtime. Look the record up first with a recordSearch on that ID " +
|
|
2168
|
+
"(e.g. .recordSearch(\"lookup\", …) filtered on the record id) and pass withFieldMappings(ctx.actions.lookup.record, …).",
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
for (const nested of Object.values(value))
|
|
2173
|
+
visit(nested, here);
|
|
2174
|
+
};
|
|
2175
|
+
visit(payload, undefined);
|
|
2176
|
+
return failures;
|
|
2177
|
+
}
|
|
1916
2178
|
function unresolvedForEachFailures(entity, payload, address) {
|
|
1917
2179
|
const found = [];
|
|
1918
2180
|
collectUnresolvedForEachItems(payload, found);
|
|
@@ -1930,6 +2192,73 @@ function unresolvedForEachFailures(entity, payload, address) {
|
|
|
1930
2192
|
"(e.g. restructure the loops, or pass the value through a variable) before this automation can build",
|
|
1931
2193
|
}));
|
|
1932
2194
|
}
|
|
2195
|
+
/**
|
|
2196
|
+
* execute_script `inputs[].value` only. Provider Read stores the
|
|
2197
|
+
* Mobius-normalized short name (`reasonForClosingEarly`) for on-demand
|
|
2198
|
+
* scalars; emitting refs["Reason for Closing Early"] drifts when that
|
|
2199
|
+
* display name also labels an app field. Other attrs keep refs["…"].
|
|
2200
|
+
*/
|
|
2201
|
+
function executeScriptInputValueToTf(value, refs) {
|
|
2202
|
+
if (isObject(value) &&
|
|
2203
|
+
isObject(value.triggerReference) &&
|
|
2204
|
+
typeof value.triggerReference.name === "string" &&
|
|
2205
|
+
value[TRIGGER_WHOLE_RECORD_MARKER] !== true &&
|
|
2206
|
+
refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
|
|
2207
|
+
const inputName = onDemandTriggerRefKey(value.triggerReference.name, [...refs.triggerParamFieldTypes.keys()]);
|
|
2208
|
+
const input = refs.triggerParamFieldTypes.get(inputName);
|
|
2209
|
+
// userId params publish no refs — fall through so valueToTf refuses them.
|
|
2210
|
+
if (input !== undefined &&
|
|
2211
|
+
!refs.recordParamNames.includes(inputName) &&
|
|
2212
|
+
!refs.userParamNames.includes(inputName)) {
|
|
2213
|
+
const typed = typeof value.fieldType === "string"
|
|
2214
|
+
? { fieldType: value.fieldType, multiple: value.multiple === true }
|
|
2215
|
+
: input;
|
|
2216
|
+
return expr.jsonencode({
|
|
2217
|
+
fieldType: typed.fieldType,
|
|
2218
|
+
multiple: typed.multiple,
|
|
2219
|
+
triggerReference: { name: normalizeOnDemandParamKey(inputName) },
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
return valueToTf(value, refs);
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Pulled createRecord / updateField values sometimes embed a JSON envelope
|
|
2227
|
+
* string whose `triggerReference.name` is `recordId` and whose `fieldType`
|
|
2228
|
+
* is still `TEXT`. Live provider state for that record-trigger identity is
|
|
2229
|
+
* `ASPECT_RECORD_ID` (#1626). `record.id` is the TEXT handle (`refs["ID"]`)
|
|
2230
|
+
* and an on-demand text input that happens to be named `recordId` stays
|
|
2231
|
+
* TEXT, so neither is rewritten. Sibling keys and their order are kept.
|
|
2232
|
+
*/
|
|
2233
|
+
function normalizeTriggerRecordIdEnvelopeString(raw, refs) {
|
|
2234
|
+
const trimmed = raw.trim();
|
|
2235
|
+
if (!trimmed.startsWith("{"))
|
|
2236
|
+
return raw;
|
|
2237
|
+
let parsed;
|
|
2238
|
+
try {
|
|
2239
|
+
parsed = JSON.parse(trimmed);
|
|
2240
|
+
}
|
|
2241
|
+
catch {
|
|
2242
|
+
return raw;
|
|
2243
|
+
}
|
|
2244
|
+
if (!isObject(parsed) || typeof parsed.fieldType !== "string")
|
|
2245
|
+
return raw;
|
|
2246
|
+
if (!isObject(parsed.triggerReference) || typeof parsed.triggerReference.name !== "string")
|
|
2247
|
+
return raw;
|
|
2248
|
+
if (parsed.triggerReference.name !== "recordId")
|
|
2249
|
+
return raw;
|
|
2250
|
+
if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
|
|
2251
|
+
const inputName = onDemandTriggerRefKey(parsed.triggerReference.name, [...refs.triggerParamFieldTypes.keys()]);
|
|
2252
|
+
if (refs.triggerParamFieldTypes.has(inputName))
|
|
2253
|
+
return raw;
|
|
2254
|
+
}
|
|
2255
|
+
if (parsed.fieldType === "ASPECT_RECORD_ID" && parsed.multiple === false)
|
|
2256
|
+
return raw;
|
|
2257
|
+
const envelope = parsed;
|
|
2258
|
+
envelope.fieldType = "ASPECT_RECORD_ID";
|
|
2259
|
+
envelope.multiple = false;
|
|
2260
|
+
return JSON.stringify(envelope);
|
|
2261
|
+
}
|
|
1933
2262
|
function valueToTf(value, refs) {
|
|
1934
2263
|
const catalog = token(value);
|
|
1935
2264
|
if (catalog !== undefined)
|
|
@@ -1971,6 +2300,17 @@ function valueToTf(value, refs) {
|
|
|
1971
2300
|
return expr.resourceAttr(target.type, target.label, ["refs", { index: target.name }]);
|
|
1972
2301
|
}
|
|
1973
2302
|
if (isObject(value.triggerReference) && typeof value.triggerReference.name === "string") {
|
|
2303
|
+
// A record trigger's whole record has no refs key of its own: refs["Record"]
|
|
2304
|
+
// is the record ID (edk#1284). On-demand triggers name record params, not
|
|
2305
|
+
// `record`, so they keep their refs keys.
|
|
2306
|
+
if (value[TRIGGER_WHOLE_RECORD_MARKER] === true && refs.trigger.type !== TRIGGER_RESOURCES.onDemand) {
|
|
2307
|
+
return triggerWholeRecordRefJson(value.triggerReference.name);
|
|
2308
|
+
}
|
|
2309
|
+
if (refs.trigger.type === TRIGGER_RESOURCES.attachment && value.triggerReference.name.startsWith("attachment.")) {
|
|
2310
|
+
const payloadRef = triggerAttachmentPayloadRef(value.triggerReference.name.slice("attachment.".length));
|
|
2311
|
+
if (payloadRef !== undefined)
|
|
2312
|
+
return expr.jsonencode(payloadRef);
|
|
2313
|
+
}
|
|
1974
2314
|
return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerWireRefName(value.triggerReference.name, refs) }]);
|
|
1975
2315
|
}
|
|
1976
2316
|
if (isObject(value.taskReference) && typeof value.taskReference.taskRefKey === "string" && typeof value.taskReference.name === "string") {
|
|
@@ -1995,13 +2335,13 @@ function valueToTf(value, refs) {
|
|
|
1995
2335
|
? refs.owner
|
|
1996
2336
|
: recordOwnerContext(refs.owner, sourceApp, taskTargetKind(source, refs), sourceApp === refs.owner.appRefName
|
|
1997
2337
|
? refs.owner.fieldNames
|
|
1998
|
-
: fieldNamesForAppRefName(refs.fieldNamesByAppRefName, sourceApp)
|
|
2338
|
+
: fieldNamesForAppRefName(refs.fieldNamesByAppRefName, sourceApp)), refs.recordItemForEachRefKeys.has(value.forEachReference.forEachTaskRefKey));
|
|
1999
2339
|
return expr.resourceAttr(target.type, target.label, ["inner", "refs", { index }]);
|
|
2000
2340
|
}
|
|
2001
2341
|
if (isObject(value.templateReference))
|
|
2002
2342
|
return templateToTf(value.templateReference, refs);
|
|
2003
2343
|
if (isObject(value.secretReference) && typeof value.secretReference.secretId === "string") {
|
|
2004
|
-
|
|
2344
|
+
return vaultEntryRefToTf(value.secretReference.secretId, refs);
|
|
2005
2345
|
}
|
|
2006
2346
|
if (typeof value.kind === "string") {
|
|
2007
2347
|
if (value.kind === "localRef" && typeof value.localName === "string" && Array.isArray(value.path)) {
|
|
@@ -2091,6 +2431,18 @@ function onDemandRecordFieldFilterReference(name, refs, operator) {
|
|
|
2091
2431
|
throw new EntityTfError(`filter reference to "${fieldKey}" on on-demand record input "${paramName}": ${target.refName} is not built in this ` +
|
|
2092
2432
|
`workspace or has no field "${fieldKey}", so its field id cannot be resolved`);
|
|
2093
2433
|
}
|
|
2434
|
+
/**
|
|
2435
|
+
* The canonical (`service_tasks`) name of a single-output AI task's output,
|
|
2436
|
+
* when `wireName` is that output's refs display label. The filter short form
|
|
2437
|
+
* `task.<id>.<name>` uses it (`response`), not the label (`Response`).
|
|
2438
|
+
*/
|
|
2439
|
+
function canonicalSingleOutputName(resourceType, wireName) {
|
|
2440
|
+
const taskKey = Object.keys(TASK_RESOURCES).find((key) => TASK_RESOURCES[key] === resourceType);
|
|
2441
|
+
if (taskKey === undefined || OUTPUT_KEY_WIRE_NAME[taskKey] !== wireName)
|
|
2442
|
+
return undefined;
|
|
2443
|
+
return OUTPUT_KEY_CANONICAL[taskKey];
|
|
2444
|
+
}
|
|
2445
|
+
const TRIGGER_REFERENCE_NAME_PATTERN = /^[a-z][A-Za-z0-9]*(?:\.[a-z][A-Za-z0-9]*)*$/;
|
|
2094
2446
|
function filterReferenceToTf(value, refs, role = "value", realType, operator) {
|
|
2095
2447
|
// Raw pass-through for a filter left side the pull-time deserializer
|
|
2096
2448
|
// couldn't decode to a typed ref (filter.ts's leftDescriptor, matching the
|
|
@@ -2195,6 +2547,16 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
|
|
|
2195
2547
|
return `trigger.${value.name.replace(UNRESOLVED_FIELD_MARKER, "")}`;
|
|
2196
2548
|
}
|
|
2197
2549
|
}
|
|
2550
|
+
// Whole-record ID in a FILTER on a record-event trigger: ei exports the
|
|
2551
|
+
// short form `trigger.recordId`. Task inputs correctly use refs["Record"]
|
|
2552
|
+
// (ASPECT_RECORD_ID), but that JSON envelope plans as drift against the
|
|
2553
|
+
// short form after every pull. On-demand must NOT take this path —
|
|
2554
|
+
// `record` / `recordId` there are declared inputs that belong in
|
|
2555
|
+
// filter_refs["Record"] (edk#1524).
|
|
2556
|
+
if (refs.trigger.type !== TRIGGER_RESOURCES.onDemand &&
|
|
2557
|
+
(value.name === "recordId" || value.name === "record")) {
|
|
2558
|
+
return "trigger.recordId";
|
|
2559
|
+
}
|
|
2198
2560
|
const triggerRefKey = triggerWireRefName(value.name, refs);
|
|
2199
2561
|
if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
|
|
2200
2562
|
// filter_refs holds only declared inputs, so the clicking user has no key there.
|
|
@@ -2205,6 +2567,13 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
|
|
|
2205
2567
|
}
|
|
2206
2568
|
return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["filter_refs", { index: triggerRefKey }]);
|
|
2207
2569
|
}
|
|
2570
|
+
// `refs` is keyed by display label. A camelCase path with no display
|
|
2571
|
+
// mapping is the platform's own reference name (`approver.id`, which
|
|
2572
|
+
// `refs` labels "Final Approval By's id"); the short form is how
|
|
2573
|
+
// export and provider Read spell it.
|
|
2574
|
+
if (triggerRefKey === value.name && TRIGGER_REFERENCE_NAME_PATTERN.test(value.name)) {
|
|
2575
|
+
return `trigger.${value.name}`;
|
|
2576
|
+
}
|
|
2208
2577
|
return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerRefKey }]);
|
|
2209
2578
|
}
|
|
2210
2579
|
case "TASK": {
|
|
@@ -2259,6 +2628,73 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
|
|
|
2259
2628
|
},
|
|
2260
2629
|
});
|
|
2261
2630
|
}
|
|
2631
|
+
// A file reader's `refs` keys each parsed value by its own name; the
|
|
2632
|
+
// `jsonValues.<key>` path exists only as a stored envelope.
|
|
2633
|
+
if (isFileReaderTask && wireName.startsWith("jsonValues.")) {
|
|
2634
|
+
return expr.jsonencode({
|
|
2635
|
+
fieldType: (realType ?? "TEXT").toUpperCase(),
|
|
2636
|
+
multiple: false,
|
|
2637
|
+
taskReference: {
|
|
2638
|
+
name: wireName,
|
|
2639
|
+
taskId: expr.resourceAttr(task.type, task.label, ["id"]),
|
|
2640
|
+
},
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2643
|
+
// An explicit filter.text() on a runAutomation output is a TEXT
|
|
2644
|
+
// envelope. A missing realType stays on .refs; the provider's refs
|
|
2645
|
+
// map is already TEXT for outputs ei stores that way.
|
|
2646
|
+
if (task.type === TASK_RESOURCES.runAutomation && realType?.toUpperCase() === "TEXT") {
|
|
2647
|
+
return expr.jsonencode({
|
|
2648
|
+
fieldType: "TEXT",
|
|
2649
|
+
multiple: false,
|
|
2650
|
+
taskReference: {
|
|
2651
|
+
name: wireName,
|
|
2652
|
+
taskId: expr.resourceAttr(task.type, task.label, ["id"]),
|
|
2653
|
+
},
|
|
2654
|
+
});
|
|
2655
|
+
}
|
|
2656
|
+
// Provider Read types a left-value envelope by the comparison's
|
|
2657
|
+
// `real_type` when that differs from the output's declared type: a
|
|
2658
|
+
// text check of a BOOLEAN, NUMBER, or DECIMAL output (#1442), and a
|
|
2659
|
+
// text or uuid check of an ASPECT_RECORD_ID record id (#1569).
|
|
2660
|
+
// `multiple` follows the declaration so an array output is not
|
|
2661
|
+
// flattened. A NUMBER comparison of a DECIMAL script output is the
|
|
2662
|
+
// next branch (#1618).
|
|
2663
|
+
const envelopeName = TASK_OUTPUT_REFERENCE_NAMES[task.type]?.[wireName] ?? wireName;
|
|
2664
|
+
const executor = RESOURCE_TYPE_TO_EXECUTOR[task.type];
|
|
2665
|
+
const declared = task.outputFieldTypes?.get(wireName) ??
|
|
2666
|
+
(executor === undefined ? undefined : TASK_OUTPUT_CONTRACTS[executor]?.[envelopeName]);
|
|
2667
|
+
const compared = realType?.toUpperCase();
|
|
2668
|
+
if (compared !== undefined &&
|
|
2669
|
+
declared !== undefined &&
|
|
2670
|
+
declared.fieldType !== compared &&
|
|
2671
|
+
!(compared === "NUMBER" && declared.fieldType === "DECIMAL")) {
|
|
2672
|
+
return expr.jsonencode({
|
|
2673
|
+
fieldType: compared,
|
|
2674
|
+
multiple: declared.multiple,
|
|
2675
|
+
taskReference: {
|
|
2676
|
+
name: envelopeName,
|
|
2677
|
+
taskId: expr.resourceAttr(task.type, task.label, ["id"]),
|
|
2678
|
+
},
|
|
2679
|
+
});
|
|
2680
|
+
}
|
|
2681
|
+
// `filter.number()` on an execute-script `number` output: the platform
|
|
2682
|
+
// stores the NUMBER envelope the author wrote, while `refs` types the
|
|
2683
|
+
// output from its schema as DECIMAL. Building from `refs` plans
|
|
2684
|
+
// `fieldType` NUMBER -> DECIMAL on every pulled case (#1618: 29
|
|
2685
|
+
// cases across 5 apps, 15 in signatureenvelope). Only this observed
|
|
2686
|
+
// direction is handled; no live DECIMAL envelope on a NUMBER output
|
|
2687
|
+
// has been seen.
|
|
2688
|
+
if (realType?.toUpperCase() === "NUMBER" && declared?.fieldType === "DECIMAL") {
|
|
2689
|
+
return expr.jsonencode({
|
|
2690
|
+
fieldType: "NUMBER",
|
|
2691
|
+
multiple: declared.multiple,
|
|
2692
|
+
taskReference: {
|
|
2693
|
+
name: envelopeName,
|
|
2694
|
+
taskId: expr.resourceAttr(task.type, task.label, ["id"]),
|
|
2695
|
+
},
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2262
2698
|
const ambiguousRecordField = recordRefKeyIsAmbiguous(value.name, wireName, value.taskRefKey, refs)
|
|
2263
2699
|
? foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs)
|
|
2264
2700
|
: undefined;
|
|
@@ -2285,14 +2721,40 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
|
|
|
2285
2721
|
},
|
|
2286
2722
|
});
|
|
2287
2723
|
}
|
|
2288
|
-
|
|
2724
|
+
// A text comparison of a found record's field stores a TEXT envelope
|
|
2725
|
+
// named by field id, while `refs` carries the field's own type
|
|
2726
|
+
// (JSON_TEXT, PICKLIST_ID).
|
|
2727
|
+
const textCastRecordField = realType?.toUpperCase() === "TEXT"
|
|
2728
|
+
? foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs)
|
|
2729
|
+
: undefined;
|
|
2730
|
+
if (textCastRecordField !== undefined) {
|
|
2731
|
+
return expr.jsonencode({
|
|
2732
|
+
fieldType: "TEXT",
|
|
2733
|
+
multiple: false,
|
|
2734
|
+
taskReference: {
|
|
2735
|
+
name: expr.template(textCastRecordField),
|
|
2736
|
+
taskId: expr.resourceAttr(task.type, task.label, ["id"]),
|
|
2737
|
+
},
|
|
2738
|
+
});
|
|
2739
|
+
}
|
|
2740
|
+
const refsIndex = task.type === TASK_RESOURCES.executeScript
|
|
2741
|
+
? executeScriptRefsIndex(wireName) ?? wireName
|
|
2742
|
+
: wireName;
|
|
2743
|
+
return expr.resourceAttr(task.type, task.label, ["refs", { index: refsIndex }]);
|
|
2289
2744
|
}
|
|
2290
2745
|
const recordFieldName = foundRecordFieldReferenceName(task.type, value.name, value.taskRefKey, refs);
|
|
2291
|
-
// The short form addresses user-search outputs by path
|
|
2292
|
-
//
|
|
2746
|
+
// The short form addresses user-search outputs by path, and an AI task's
|
|
2747
|
+
// single output by its canonical name (`response`, edk#1509); only
|
|
2748
|
+
// `.refs` is keyed by their display labels. recordSearch's ASPECT_RECORD_ID
|
|
2749
|
+
// is keyed `First found record id` in refs, but filter RHS / ei export use
|
|
2750
|
+
// the canonical short name `recordId` (service_tasks) — emitting the
|
|
2751
|
+
// display label here plans drift after every pull (edk#1524).
|
|
2293
2752
|
const shortName = task.type === TASK_RESOURCES.userSearch
|
|
2294
2753
|
? USER_SEARCH_PATH_BY_WIRE_NAME.get(wireName) ?? wireName
|
|
2295
|
-
:
|
|
2754
|
+
: task.type === TASK_RESOURCES.recordSearch &&
|
|
2755
|
+
(wireName === "First found record id" || value.name === "record.recordId" || value.name === "recordId")
|
|
2756
|
+
? "recordId"
|
|
2757
|
+
: canonicalSingleOutputName(task.type, wireName) ?? wireName;
|
|
2296
2758
|
return expr.template([
|
|
2297
2759
|
"task.",
|
|
2298
2760
|
expr.resourceAttr(task.type, task.label, ["id"]),
|
|
@@ -2330,7 +2792,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
|
|
|
2330
2792
|
if (target === undefined) {
|
|
2331
2793
|
throw new EntityTfError("variable filter reference could not be resolved to a variable task — the referenced workflow variable must be created by a setVariable task in the same automation");
|
|
2332
2794
|
}
|
|
2333
|
-
return expr.template(["variable.",
|
|
2795
|
+
return expr.template(["variable.", variableIdAttr(target)]);
|
|
2334
2796
|
}
|
|
2335
2797
|
default:
|
|
2336
2798
|
throw new EntityTfError(`unsupported filter reference type "${value.type}"`);
|
|
@@ -2484,8 +2946,8 @@ function filterToTf(value, refs) {
|
|
|
2484
2946
|
if (parsed === undefined)
|
|
2485
2947
|
return authored;
|
|
2486
2948
|
const metadata = refs.owner.fieldMetadata.get(parsed.fieldKey);
|
|
2487
|
-
//
|
|
2488
|
-
if (parsed.suffix === "" && metadata?.fieldType === "PICKLIST" && !isOptionBearingPicklist(metadata)) {
|
|
2949
|
+
// An option picklist's bare or `.id` reference is a UUID. A dynamic dropdown's is stored as text.
|
|
2950
|
+
if ((parsed.suffix === "" || parsed.suffix === "id") && metadata?.fieldType === "PICKLIST" && !isOptionBearingPicklist(metadata)) {
|
|
2489
2951
|
return authored;
|
|
2490
2952
|
}
|
|
2491
2953
|
const inferred = referenceValueTypeForField(metadata?.fieldType, parsed.suffix);
|
|
@@ -2505,8 +2967,22 @@ function filterToTf(value, refs) {
|
|
|
2505
2967
|
literal: (literal, field) => picklistFilterValueToTf(literal, token(field), refs) ?? valueToTf(literal, refs),
|
|
2506
2968
|
});
|
|
2507
2969
|
}
|
|
2508
|
-
/**
|
|
2509
|
-
|
|
2970
|
+
/**
|
|
2971
|
+
* System fields a record-updated trigger cannot meaningfully watch: these never
|
|
2972
|
+
* change after create, or change on every update. The platform stores ID,
|
|
2973
|
+
* Closed At and Closed By in changed_fields, so they round-trip.
|
|
2974
|
+
*/
|
|
2975
|
+
const UNWATCHABLE_SYSTEM_FIELD_KEYS = new Set(["createdAt", "createdBy", "updatedAt", "updatedBy"]);
|
|
2976
|
+
function isRunAutomationValueReference(raw) {
|
|
2977
|
+
if (!isObject(raw))
|
|
2978
|
+
return false;
|
|
2979
|
+
return (isObject(raw.triggerReference) ||
|
|
2980
|
+
isObject(raw.taskReference) ||
|
|
2981
|
+
isObject(raw.forEachReference) ||
|
|
2982
|
+
isObject(raw.templateReference) ||
|
|
2983
|
+
isObject(raw.secretReference) ||
|
|
2984
|
+
isObject(raw.variableReference));
|
|
2985
|
+
}
|
|
2510
2986
|
function configAttrs(kind, config, refs) {
|
|
2511
2987
|
const attrs = {};
|
|
2512
2988
|
for (const [key, raw] of Object.entries(config)) {
|
|
@@ -2556,10 +3032,40 @@ function configAttrs(kind, config, refs) {
|
|
|
2556
3032
|
attrs.code = raw;
|
|
2557
3033
|
continue;
|
|
2558
3034
|
}
|
|
3035
|
+
// execute_script input values: provider Read stores Mobius-normalized
|
|
3036
|
+
// short names for on-demand scalars. Keep that envelope here only —
|
|
3037
|
+
// templates, notifications, and other attrs still use refs["…"].
|
|
3038
|
+
if (key === "inputs" && kind === "elementum_execute_script_task") {
|
|
3039
|
+
if (!Array.isArray(raw))
|
|
3040
|
+
throw new EntityTfError("executeScript inputs must be an array");
|
|
3041
|
+
attrs.inputs = raw.map((item) => {
|
|
3042
|
+
if (!isObject(item) || typeof item.name !== "string") {
|
|
3043
|
+
throw new EntityTfError("invalid executeScript input");
|
|
3044
|
+
}
|
|
3045
|
+
const mapped = {
|
|
3046
|
+
name: item.name,
|
|
3047
|
+
value: executeScriptInputValueToTf(item.value, refs),
|
|
3048
|
+
};
|
|
3049
|
+
if (item.field_mappings !== undefined) {
|
|
3050
|
+
mapped.field_mappings = valueToTf(item.field_mappings, refs);
|
|
3051
|
+
}
|
|
3052
|
+
return mapped;
|
|
3053
|
+
});
|
|
3054
|
+
continue;
|
|
3055
|
+
}
|
|
2559
3056
|
if (key === "inputMappings" && kind === "elementum_run_automation_task") {
|
|
2560
3057
|
if (!Array.isArray(raw))
|
|
2561
3058
|
throw new EntityTfError("runAutomation inputMappings must be an array");
|
|
2562
3059
|
const target = token(config.targetAutomationId);
|
|
3060
|
+
if (bareStaticRunTarget(config)) {
|
|
3061
|
+
attrs.input_mappings = raw.map((mapping) => {
|
|
3062
|
+
if (!isObject(mapping) || typeof mapping.name !== "string" || mapping.value === undefined) {
|
|
3063
|
+
throw new EntityTfError("runAutomation input mapping requires name and value");
|
|
3064
|
+
}
|
|
3065
|
+
return { parameter_id: mapping.name, value: valueToTf(mapping.value, refs) };
|
|
3066
|
+
});
|
|
3067
|
+
continue;
|
|
3068
|
+
}
|
|
2563
3069
|
if (target?.__kind !== "automation") {
|
|
2564
3070
|
attrs.dynamic_input_mappings = raw.map((mapping) => {
|
|
2565
3071
|
if (!isObject(mapping) || typeof mapping.name !== "string" || mapping.value === undefined) {
|
|
@@ -2590,12 +3096,22 @@ function configAttrs(kind, config, refs) {
|
|
|
2590
3096
|
continue;
|
|
2591
3097
|
}
|
|
2592
3098
|
if (key === "targetAutomationRef" && kind === "elementum_run_automation_task") {
|
|
3099
|
+
// A Dynamic Reference is a serialized value reference (trigger, task,
|
|
3100
|
+
// loop, template, secret, variable). `{ type: "DYNAMIC" }` is not one;
|
|
3101
|
+
// that shape still has to be a STATIC catalog target.
|
|
3102
|
+
if (isRunAutomationValueReference(raw)) {
|
|
3103
|
+
if (config.synchronous !== true) {
|
|
3104
|
+
throw new EntityTfError("runAutomation Dynamic Reference target requires synchronous: true");
|
|
3105
|
+
}
|
|
3106
|
+
attrs["target_automation_ref"] = valueToTf(raw, refs);
|
|
3107
|
+
continue;
|
|
3108
|
+
}
|
|
2593
3109
|
if (!isObject(raw) || raw.type !== "STATIC") {
|
|
2594
3110
|
throw new EntityTfError("runAutomation targetAutomationRef must be { type: \"STATIC\", value: ... }");
|
|
2595
3111
|
}
|
|
2596
3112
|
const target = token(raw.value);
|
|
2597
3113
|
if (target?.__kind === "automation") {
|
|
2598
|
-
attrs["target_automation_ref"] = automationRunTargetResourceAttr(refs.owner.appTfLabel, target.refName, refs.owner.activeAutomationRefNames);
|
|
3114
|
+
attrs["target_automation_ref"] = automationRunTargetResourceAttr(refs.owner.appTfLabel, target.refName, refs.owner.activeAutomationRefNames, refs.owner.parentScope, refs.owner.ownerHandle);
|
|
2599
3115
|
continue;
|
|
2600
3116
|
}
|
|
2601
3117
|
// Pull may leave a bare platform UUID when the target automation was
|
|
@@ -2616,7 +3132,7 @@ function configAttrs(kind, config, refs) {
|
|
|
2616
3132
|
continue;
|
|
2617
3133
|
}
|
|
2618
3134
|
if (typeof raw === "string" && raw !== "") {
|
|
2619
|
-
attrs[Array.isArray(config.inputMappings) && config.inputMappings.length > 0
|
|
3135
|
+
attrs[Array.isArray(config.inputMappings) && config.inputMappings.length > 0 && !bareStaticRunTarget(config)
|
|
2620
3136
|
? "target_automation_ref"
|
|
2621
3137
|
: "target_automation_id"] = raw;
|
|
2622
3138
|
refs.owner.diagnostics?.push(`runAutomation: target automation ${JSON.stringify(raw)} is unresolved; emitted as bare id`);
|
|
@@ -2778,15 +3294,17 @@ function configAttrs(kind, config, refs) {
|
|
|
2778
3294
|
const parameters = raw.map((input) => {
|
|
2779
3295
|
if (!isObject(input))
|
|
2780
3296
|
throw new EntityTfError("onDemand input must be an object");
|
|
3297
|
+
if (typeof input.type !== "string" || !ON_DEMAND_TF_PARAM_TYPES.has(input.type)) {
|
|
3298
|
+
throw new EntityTfError(`onDemand parameter ${JSON.stringify(input.name)} has type ${JSON.stringify(input.type)}, which ` +
|
|
3299
|
+
`elementum_on_demand_trigger does not support (allowed: text, number, decimal, boolean, date, ` +
|
|
3300
|
+
`datetime, userId, attachmentId, record). Use "text" for a JSON string.`);
|
|
3301
|
+
}
|
|
2781
3302
|
const mapped = Object.fromEntries(Object.entries(input)
|
|
2782
3303
|
.filter(([k]) => k !== "app")
|
|
2783
3304
|
.map(([k, v]) => [
|
|
2784
3305
|
CONFIG_ATTRS[k] ?? snake(k),
|
|
2785
3306
|
valueToTf(k === "defaultValue" ? unwrapDefault(v) :
|
|
2786
|
-
k === "type" && v === "
|
|
2787
|
-
k === "type" && v === "USER_ID" ? "user" :
|
|
2788
|
-
k === "type" && v === "ASPECT_RECORD" ? "record" :
|
|
2789
|
-
k === "type" && typeof v === "string" ? v.toLowerCase() : v, refs),
|
|
3307
|
+
k === "type" && typeof v === "string" ? ON_DEMAND_TF_PARAM_TYPES.get(v) : v, refs),
|
|
2790
3308
|
]));
|
|
2791
3309
|
if (isOnDemandRecordType(typeof input.type === "string" ? input.type : undefined)) {
|
|
2792
3310
|
const target = token(input.app);
|
|
@@ -2843,9 +3361,16 @@ function configAttrs(kind, config, refs) {
|
|
|
2843
3361
|
const optionValue = staticValue !== undefined
|
|
2844
3362
|
? picklistFilterValueToTf(staticValue, fieldToken, refs)
|
|
2845
3363
|
: undefined;
|
|
3364
|
+
let reference = field.valueReference;
|
|
3365
|
+
if (typeof reference === "string") {
|
|
3366
|
+
reference = normalizeTriggerRecordIdEnvelopeString(reference, refs);
|
|
3367
|
+
}
|
|
3368
|
+
else if (isObject(reference) && typeof reference.value === "string" && Object.keys(reference).length === 1) {
|
|
3369
|
+
reference = { value: normalizeTriggerRecordIdEnvelopeString(reference.value, refs) };
|
|
3370
|
+
}
|
|
2846
3371
|
return {
|
|
2847
3372
|
field_id: valueToTf(field.aspectFieldId, refs),
|
|
2848
|
-
value: optionValue ?? valueToTf(
|
|
3373
|
+
value: optionValue ?? valueToTf(reference, refs),
|
|
2849
3374
|
...(field.operation === "ADD" ? { update_mode: "add" } : {}),
|
|
2850
3375
|
};
|
|
2851
3376
|
});
|
|
@@ -2911,12 +3436,34 @@ function configAttrs(kind, config, refs) {
|
|
|
2911
3436
|
if (key === "basicAuth" && kind === "elementum_api_task") {
|
|
2912
3437
|
if (!isObject(raw))
|
|
2913
3438
|
throw new EntityTfError("apiRequest basicAuth must be an object");
|
|
3439
|
+
// A requiredSecret username is write-only on the platform: emit the
|
|
3440
|
+
// provider's write-only username_wo so a null read never plans a
|
|
3441
|
+
// change (edk#1400).
|
|
3442
|
+
// A secret("KEY") username is bound to a vault entry: emit
|
|
3443
|
+
// reference_username so the platform resolves it at runtime instead of
|
|
3444
|
+
// storing the lookup as a static username (edk#1283).
|
|
2914
3445
|
attrs.basic_auth = {
|
|
2915
|
-
|
|
3446
|
+
...(isVaultSecretRaw(raw.username)
|
|
3447
|
+
? { reference_username: valueToTf(raw.username, refs) }
|
|
3448
|
+
: isRequiredSecretRaw(raw.username)
|
|
3449
|
+
? { username_wo: valueToTf(raw.username, refs) }
|
|
3450
|
+
: { username: valueToTf(raw.username, refs) }),
|
|
2916
3451
|
...(raw.referencePassword !== undefined ? { reference_password: valueToTf(raw.referencePassword, refs) } : {}),
|
|
2917
3452
|
};
|
|
2918
3453
|
continue;
|
|
2919
3454
|
}
|
|
3455
|
+
if (key === "headers" && kind === "elementum_api_task" && Array.isArray(raw)) {
|
|
3456
|
+
// A requiredSecret header value is unreadable on the platform: emit the
|
|
3457
|
+
// write-only value_wo so the imported null never plans a change (edk#1400).
|
|
3458
|
+
attrs.headers = raw.map((h) => {
|
|
3459
|
+
if (!isObject(h))
|
|
3460
|
+
throw new EntityTfError("invalid apiRequest header");
|
|
3461
|
+
const header = { name: valueToTf(h.name, refs) };
|
|
3462
|
+
header[isRequiredSecretRaw(h.value) ? "value_wo" : "value"] = valueToTf(h.value, refs);
|
|
3463
|
+
return header;
|
|
3464
|
+
});
|
|
3465
|
+
continue;
|
|
3466
|
+
}
|
|
2920
3467
|
if (key === "bearerAuth" && kind === "elementum_api_task") {
|
|
2921
3468
|
if (!isObject(raw))
|
|
2922
3469
|
throw new EntityTfError("apiRequest bearerAuth must be an object");
|
|
@@ -2939,8 +3486,15 @@ function configAttrs(kind, config, refs) {
|
|
|
2939
3486
|
attrs.oauth = {
|
|
2940
3487
|
request_type: valueToTf(raw.requestType, refs),
|
|
2941
3488
|
...(raw.url !== undefined ? { url: valueToTf(raw.url, refs) } : {}),
|
|
2942
|
-
|
|
2943
|
-
|
|
3489
|
+
// secret("KEY") client credentials bind to vault entries through the
|
|
3490
|
+
// reference_ attributes; a static string stays client_id/client_secret
|
|
3491
|
+
// (edk#1283).
|
|
3492
|
+
...(raw.clientId !== undefined
|
|
3493
|
+
? { [isVaultSecretRaw(raw.clientId) ? "reference_client_id" : "client_id"]: valueToTf(raw.clientId, refs) }
|
|
3494
|
+
: {}),
|
|
3495
|
+
...(raw.clientSecret !== undefined
|
|
3496
|
+
? { [isVaultSecretRaw(raw.clientSecret) ? "reference_client_secret" : "client_secret"]: valueToTf(raw.clientSecret, refs) }
|
|
3497
|
+
: {}),
|
|
2944
3498
|
...(headers !== undefined ? { headers } : {}),
|
|
2945
3499
|
};
|
|
2946
3500
|
continue;
|
|
@@ -3011,11 +3565,20 @@ function fileReaderDependsOn(blocks) {
|
|
|
3011
3565
|
return deps;
|
|
3012
3566
|
}
|
|
3013
3567
|
/** App- or element-owned `automation` entity → provider HCL blocks. */
|
|
3568
|
+
function elementHandleOf(explicit, payload) {
|
|
3569
|
+
if (explicit !== undefined && explicit !== "")
|
|
3570
|
+
return explicit;
|
|
3571
|
+
if (payload === null || typeof payload !== "object" || !("handle" in payload))
|
|
3572
|
+
return undefined;
|
|
3573
|
+
const handle = payload.handle;
|
|
3574
|
+
return typeof handle === "string" && handle !== "" ? handle : undefined;
|
|
3575
|
+
}
|
|
3014
3576
|
export function automationToTf(entity, ctx) {
|
|
3015
|
-
const automationTfLabel =
|
|
3577
|
+
const automationTfLabel = automationResourceLabel(ctx.appTfLabel, entity.refName, ctx.parentScope, ctx.parentScope === "element" ? ctx.ownerHandle : undefined);
|
|
3016
3578
|
const owner = {
|
|
3017
3579
|
appRefName: ctx.appRefName ?? entity.parent,
|
|
3018
3580
|
parentScope: ctx.parentScope ?? "app",
|
|
3581
|
+
ownerHandle: ctx.ownerHandle,
|
|
3019
3582
|
appTfLabel: ctx.appTfLabel,
|
|
3020
3583
|
automationTfLabel,
|
|
3021
3584
|
fieldAddresses: ctx.fieldAddresses ?? new Map(),
|
|
@@ -3041,6 +3604,16 @@ export function automationToTf(entity, ctx) {
|
|
|
3041
3604
|
const unresolved = unresolvedForEachFailures(entity, payload, `${AUTOMATION_RESOURCE_TYPE}.${automationTfLabel}`);
|
|
3042
3605
|
if (unresolved.length > 0)
|
|
3043
3606
|
throw new ValidationFailureError(unresolved);
|
|
3607
|
+
const recordIdMappings = recordIdFieldMappingFailures(entity, payload, `${AUTOMATION_RESOURCE_TYPE}.${automationTfLabel}`);
|
|
3608
|
+
if (recordIdMappings.length > 0) {
|
|
3609
|
+
// Fatal for build/plan/apply. Pull is a read of live config: it warns by
|
|
3610
|
+
// name and keeps emitting the live shape, so the source is still written
|
|
3611
|
+
// and the user can fix it (edk#1499).
|
|
3612
|
+
if (currentValidationMode() === "pull")
|
|
3613
|
+
recordValidations(recordIdMappings.map((failure) => ({ ...failure, severity: "warning" })));
|
|
3614
|
+
else
|
|
3615
|
+
throw new ValidationFailureError(recordIdMappings);
|
|
3616
|
+
}
|
|
3044
3617
|
if (typeof payload.workflowRevision !== "string")
|
|
3045
3618
|
throw new EntityTfError(`automation "${entity.refName}" has no workflowRevision`);
|
|
3046
3619
|
const label = automationTfLabel;
|
|
@@ -3118,18 +3691,22 @@ export function automationToTf(entity, ctx) {
|
|
|
3118
3691
|
? [[field.name, { fieldType: field.type, multiple: false }]]
|
|
3119
3692
|
: []))
|
|
3120
3693
|
: undefined;
|
|
3694
|
+
const recordTarget = FOUND_RECORD_TASK_TYPES.has(resourceType)
|
|
3695
|
+
? token(taskBody.aspectId ?? taskBody.relatedAspectId)
|
|
3696
|
+
: undefined;
|
|
3121
3697
|
taskRefs.set(refKey, {
|
|
3122
3698
|
type: resourceType,
|
|
3123
3699
|
label: registeredLabel,
|
|
3124
3700
|
...(wireType === "unimplementedTask" ? { isData: true } : {}),
|
|
3125
3701
|
...(outputFieldTypes !== undefined && outputFieldTypes.size > 0 ? { outputFieldTypes } : {}),
|
|
3702
|
+
...(recordTarget !== undefined ? { recordTarget } : {}),
|
|
3126
3703
|
});
|
|
3127
3704
|
if (wireType === "variable" && Array.isArray(taskBody.create)) {
|
|
3128
|
-
|
|
3705
|
+
taskBody.create.forEach((candidate, index) => {
|
|
3129
3706
|
if (isObject(candidate) && typeof candidate.id === "string" && typeof candidate.name === "string") {
|
|
3130
|
-
variableById.set(candidate.id, { type: "elementum_variable_task", label: registeredLabel, name: candidate.name });
|
|
3707
|
+
variableById.set(candidate.id, { type: "elementum_variable_task", label: registeredLabel, name: candidate.name, index });
|
|
3131
3708
|
}
|
|
3132
|
-
}
|
|
3709
|
+
});
|
|
3133
3710
|
}
|
|
3134
3711
|
for (const child of task.children ?? [])
|
|
3135
3712
|
preRegister(child.tasks ?? []);
|
|
@@ -3325,26 +3902,24 @@ export function automationToTf(entity, ctx) {
|
|
|
3325
3902
|
}
|
|
3326
3903
|
if (wireType === "variable") {
|
|
3327
3904
|
const variableType = variableTaskResourceType(inner, refKey);
|
|
3328
|
-
const isCreate = variableType === "elementum_variable_task";
|
|
3329
3905
|
const creates = Array.isArray(inner.create) ? inner.create : [];
|
|
3330
3906
|
const updates = Array.isArray(inner.update) ? inner.update : [];
|
|
3331
|
-
const item = (isCreate ? creates[0] : updates[0]);
|
|
3332
|
-
if (!isObject(item))
|
|
3333
|
-
throw new EntityTfError(`invalid setVariable item on "${refKey}"`);
|
|
3334
3907
|
const variableAttrs = { parent: taskParent, name: displayName };
|
|
3335
|
-
if (
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3908
|
+
if (creates.length > 0) {
|
|
3909
|
+
variableAttrs.variables = creates.map((item) => {
|
|
3910
|
+
if (!isObject(item) || typeof item.name !== "string" || typeof item.type !== "string") {
|
|
3911
|
+
throw new EntityTfError(`variable task "${refKey}" requires name and type on every variable`);
|
|
3912
|
+
}
|
|
3913
|
+
return { name: item.name, type: item.type, ...(item.value !== undefined ? { value: valueToTf(item.value, refs) } : {}) };
|
|
3914
|
+
});
|
|
3342
3915
|
}
|
|
3343
|
-
|
|
3344
|
-
//
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3916
|
+
if (updates.length > 0) {
|
|
3917
|
+
// The provider's attribute is variable_reference; the authoring key stays "variable".
|
|
3918
|
+
variableAttrs.updates = updates.map((item) => {
|
|
3919
|
+
if (!isObject(item))
|
|
3920
|
+
throw new EntityTfError(`invalid setVariable item on "${refKey}"`);
|
|
3921
|
+
return { variable_reference: valueToTf(item.variable, refs), value: valueToTf(item.value, refs) };
|
|
3922
|
+
});
|
|
3348
3923
|
}
|
|
3349
3924
|
blocks.push({ kind: "resource", type: variableType, label: tfLabel, attrs: variableAttrs });
|
|
3350
3925
|
const address = expr.resourceAttr(variableType, tfLabel);
|
|
@@ -3552,3 +4127,19 @@ function requiredSecretVariableBlock(name) {
|
|
|
3552
4127
|
},
|
|
3553
4128
|
};
|
|
3554
4129
|
}
|
|
4130
|
+
/** A serialized secret("KEY") vault-entry reference, optionally wrapped as { value: X }. */
|
|
4131
|
+
function isVaultSecretRaw(value) {
|
|
4132
|
+
if (!isObject(value))
|
|
4133
|
+
return false;
|
|
4134
|
+
if ("value" in value && Object.keys(value).length === 1)
|
|
4135
|
+
return isVaultSecretRaw(value.value);
|
|
4136
|
+
return isObject(value.secretReference) && typeof value.secretReference.secretId === "string";
|
|
4137
|
+
}
|
|
4138
|
+
function isRequiredSecretRaw(value) {
|
|
4139
|
+
if (!isObject(value))
|
|
4140
|
+
return false;
|
|
4141
|
+
// serializeValueOrRef wraps a plain value as { value: X } (unwrapped by valueToTf).
|
|
4142
|
+
if ("value" in value && Object.keys(value).length === 1)
|
|
4143
|
+
return isRequiredSecretRaw(value.value);
|
|
4144
|
+
return value.kind === "requiredSecret" && typeof value.variable === "string";
|
|
4145
|
+
}
|