@elementumai/edk 0.9.5 → 0.9.7
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 +31 -1
- package/dist-sdk/src/catalog/factories.d.ts +12 -3
- package/dist-sdk/src/catalog/factories.js +9 -6
- package/dist-sdk/src/catalog/org.js +26 -13
- package/dist-sdk/src/catalog/types.d.ts +22 -1
- package/dist-sdk/src/core/index.d.ts +1 -1
- package/dist-sdk/src/core/system-fields.d.ts +4 -0
- package/dist-sdk/src/core/system-fields.js +15 -0
- package/dist-sdk/src/core/types/app.d.ts +14 -9
- package/dist-sdk/src/core/types/platform.d.ts +1 -1
- package/dist-sdk/src/engine/build/context.d.ts +4 -0
- package/dist-sdk/src/engine/pull/context.d.ts +9 -0
- package/dist-sdk/src/engine/pull/ref-only.d.ts +14 -0
- package/dist-sdk/src/engine/pull/ref-only.js +35 -2
- package/dist-sdk/src/entities/access-policy/from-tf.js +14 -2
- package/dist-sdk/src/entities/access-policy/to-tf.d.ts +6 -0
- package/dist-sdk/src/entities/access-policy/to-tf.js +4 -1
- package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +18 -1
- package/dist-sdk/src/entities/agent/module.js +1 -0
- package/dist-sdk/src/entities/agent/to-tf.d.ts +1 -0
- package/dist-sdk/src/entities/agent/to-tf.js +1 -0
- package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +9 -0
- package/dist-sdk/src/entities/agent-tool/from-tf.js +10 -2
- package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -0
- package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -3
- package/dist-sdk/src/entities/app/build.d.ts +42 -22
- package/dist-sdk/src/entities/app/build.js +12 -5
- package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +10 -0
- package/dist-sdk/src/entities/app/from-tf.js +71 -8
- package/dist-sdk/src/entities/app/index.d.ts +3 -2
- package/dist-sdk/src/entities/app/index.js +2 -1
- package/dist-sdk/src/entities/app/to-tf.js +16 -0
- package/dist-sdk/src/entities/automation/build.d.ts +31 -19
- package/dist-sdk/src/entities/automation/build.js +85 -7
- package/dist-sdk/src/entities/automation/catalog-render.js +5 -2
- package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +5 -3
- package/dist-sdk/src/entities/automation/deserializer/print-automation.js +26 -12
- package/dist-sdk/src/entities/automation/from-tf.js +364 -31
- package/dist-sdk/src/entities/automation/index.d.ts +1 -1
- package/dist-sdk/src/entities/automation/module.js +2 -2
- package/dist-sdk/src/entities/automation/operators.d.ts +2 -2
- package/dist-sdk/src/entities/automation/operators.js +1 -0
- package/dist-sdk/src/entities/automation/output-field-types.d.ts +17 -0
- package/dist-sdk/src/entities/automation/output-field-types.js +45 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +8 -0
- package/dist-sdk/src/entities/automation/output-key-wire-name.js +16 -0
- package/dist-sdk/src/entities/automation/script-code.js +153 -25
- package/dist-sdk/src/entities/automation/tasks.d.ts +100 -37
- package/dist-sdk/src/entities/automation/tasks.js +44 -43
- package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -1
- package/dist-sdk/src/entities/automation/to-tf.js +454 -58
- package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +78 -0
- package/dist-sdk/src/entities/automation/value-ref-tf.js +193 -0
- package/dist-sdk/src/entities/element/build.js +1 -0
- package/dist-sdk/src/entities/element/index.d.ts +2 -1
- package/dist-sdk/src/entities/element/index.js +2 -1
- package/dist-sdk/src/entities/field/build.d.ts +94 -3
- package/dist-sdk/src/entities/field/build.js +82 -3
- package/dist-sdk/src/entities/field/from-tf.js +92 -1
- package/dist-sdk/src/entities/field/locals.js +6 -7
- package/dist-sdk/src/entities/field/options.d.ts +2 -0
- package/dist-sdk/src/entities/field/options.js +12 -2
- package/dist-sdk/src/entities/field/record-shape.d.ts +12 -15
- package/dist-sdk/src/entities/field/to-tf.d.ts +12 -2
- package/dist-sdk/src/entities/field/to-tf.js +172 -51
- package/dist-sdk/src/entities/field/types.js +2 -0
- package/dist-sdk/src/entities/record-create-form/to-tf.js +5 -8
- package/dist-sdk/src/entities/relationship/from-tf.js +91 -9
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +9 -0
- package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +39 -0
- package/dist-sdk/src/entities/shared/filters/ast.d.ts +18 -1
- package/dist-sdk/src/entities/shared/filters/ast.js +1 -0
- package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +6 -1
- package/dist-sdk/src/entities/shared/filters/tf-codec.js +6 -4
- package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +5 -3
- package/dist-sdk/src/entities/shared/tool-field-ref.js +11 -16
- package/dist-sdk/src/entities/shared/types/common.d.ts +7 -5
- package/dist-sdk/src/entities/shared/types/platform.d.ts +15 -2
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +1 -1
- package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +44 -15
- package/dist-sdk/src/entities/skill/from-tf.js +11 -1
- package/dist-sdk/src/entities/skill/input-coverage.d.ts +68 -0
- package/dist-sdk/src/entities/skill/input-coverage.js +184 -0
- package/dist-sdk/src/entities/skill/module.js +2 -0
- package/dist-sdk/src/entities/skill/to-tf.d.ts +3 -0
- package/dist-sdk/src/entities/skill/to-tf.js +7 -2
- package/dist-sdk/src/entities/skill/tools.d.ts +10 -1
- package/dist-sdk/src/entities/skill/tools.js +0 -5
- package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +19 -0
- package/dist-sdk/src/entities/skill-tool/from-tf.js +40 -11
- package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +4 -2
- package/dist-sdk/src/entities/skill-tool/to-tf.js +24 -16
- package/dist-sdk/src/entities/table/to-tf.js +18 -1
- package/dist-sdk/src/entities/view/to-tf.js +8 -3
- package/dist-sdk/src/entities/visual-flow/from-tf.js +6 -2
- package/dist-sdk/src/graph/types.d.ts +3 -0
- package/package.json +2 -1
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { EntityTfError, recordFieldContextOf } from "../../engine/entity.js";
|
|
2
2
|
import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
|
|
3
|
-
import { appResourceLabelPrefix, appScopedResourceLabel, expr, isTfExpr, isUuid, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel, } from "../../engine/tf/index.js";
|
|
3
|
+
import { appResourceLabelPrefix, appScopedResourceLabel, expr, isCanonicalTsLabel, isTfExpr, isUuid, sanitizeName, scopedResourceLabel, snakeSlug, tsLabelToTfLabel, } from "../../engine/tf/index.js";
|
|
4
4
|
import { workspaceAspectKey } from "../../engine/build/context.js";
|
|
5
5
|
import { SEARCH_TABLE_RESOURCE_TYPES } from "../search-table/types.js";
|
|
6
6
|
import { fieldRefToTfValue } from "../field/to-tf.js";
|
|
7
7
|
import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
|
|
8
8
|
import { resolveForeignRef } from "../shared/foreign-ref.js";
|
|
9
9
|
import { filterToTf as serializeFilterToTf } from "../shared/filters/tf-codec.js";
|
|
10
|
+
import { API_TASK_REF_AUTHORING_NAMES, API_TASK_REF_WIRE_NAMES } from "./output-key-wire-name.js";
|
|
11
|
+
import { outputFieldTypesFromScriptSchema } from "./output-field-types.js";
|
|
10
12
|
import { CONNECTOR_ORG_BAG } from "../org/connector.js";
|
|
11
13
|
import { FILE_READER_SUB_TYPE_BY_RESOURCE, FILE_READER_SUB_TYPE_BY_TYPE_KEY } from "../file-reader/types.js";
|
|
12
14
|
import { UNRESOLVED_FIELD_MARKER } from "../shared/ref.js";
|
|
13
15
|
import { TABLE_RESOURCE_TYPE } from "../table/module.js";
|
|
14
16
|
import { AUTOMATION_RESOURCE_TYPE, WORKFLOW_PUBLISH_RESOURCE_TYPE } from "./types.js";
|
|
17
|
+
import { onDemandTriggerRefKey } from "./value-ref-tf.js";
|
|
15
18
|
function scopedLabel(appTfLabel, label) {
|
|
16
19
|
return appScopedResourceLabel(appTfLabel, label);
|
|
17
20
|
}
|
|
@@ -117,9 +120,12 @@ const CONFIG_ATTRS = {
|
|
|
117
120
|
fireOnRecovery: "fire_on_recovery",
|
|
118
121
|
emailAliasId: "email_alias_id",
|
|
119
122
|
approvalChainTemplateId: "approval_chain_template_id",
|
|
123
|
+
approvalProcessId: "approval_process_id",
|
|
120
124
|
surveyTemplateId: "survey_template_id",
|
|
121
125
|
workflowFields: "fields",
|
|
122
126
|
recordReference: "record_reference",
|
|
127
|
+
requesterReference: "requester_reference",
|
|
128
|
+
approverReferences: "approver_references",
|
|
123
129
|
recordId: "record_reference",
|
|
124
130
|
sourceRecordIds: "source_record_ids",
|
|
125
131
|
targetRecordId: "target_record_id",
|
|
@@ -148,8 +154,6 @@ const CONFIG_ATTRS = {
|
|
|
148
154
|
categorySource: "category_source",
|
|
149
155
|
titleReference: "title",
|
|
150
156
|
messageReference: "message",
|
|
151
|
-
userValueReferences: "user_value_references",
|
|
152
|
-
groupValueReferences: "group_value_references",
|
|
153
157
|
notifyWatchers: "notify_watchers",
|
|
154
158
|
fieldId: "field_id",
|
|
155
159
|
userId: "user_id",
|
|
@@ -272,9 +276,10 @@ function foreignFieldNaming(value) {
|
|
|
272
276
|
* `locals.tf` attrs, when the build wired one up ({@link
|
|
273
277
|
* AutomationToTfContext.localsAttrs}). Cross-app counterpart to
|
|
274
278
|
* `field/locals.ts`'s same-app `appendFieldLocals`; unconditional per field
|
|
275
|
-
* (options empty for non-picklist/calculated fields
|
|
276
|
-
*
|
|
277
|
-
*
|
|
279
|
+
* (options empty for non-picklist/calculated fields, and for a dynamic or
|
|
280
|
+
* API-sourced picklist, whose record-backed labels are not a lookup
|
|
281
|
+
* domain), matching that same-app precedent of always emitting the local
|
|
282
|
+
* whether or not any automation ends up looking a label up through it.
|
|
278
283
|
*/
|
|
279
284
|
function registerForeignOptionsByLabelLocal(fieldLabel, ctx) {
|
|
280
285
|
if (ctx.localsAttrs === undefined)
|
|
@@ -333,6 +338,80 @@ function crossAppFieldToTf(value, ctx, dataBlocks) {
|
|
|
333
338
|
registerForeignOptionsByLabelLocal(fieldLabel, ctx);
|
|
334
339
|
return expr.dataAttr("elementum_field", fieldLabel, ["id"]);
|
|
335
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Resolve an automation token as a managed definition (same stream root or a
|
|
343
|
+
* sibling root in this build) or as a ref-only `data.elementum_automation`
|
|
344
|
+
* lookup. The latter deliberately preserves the provider's static
|
|
345
|
+
* `automation { id }` + `inputMappings.parameter.id` contract; it must never
|
|
346
|
+
* degrade to `target_automation_ref` / `dynamic_input_mappings`.
|
|
347
|
+
*/
|
|
348
|
+
function automationTargetToTf(value, ctx, dataBlocks) {
|
|
349
|
+
const ownerKind = value.parentKind ?? ctx.parentScope;
|
|
350
|
+
const isOwn = value.parent === undefined ||
|
|
351
|
+
(value.parent === ctx.appRefName && ownerKind === ctx.parentScope);
|
|
352
|
+
const sibling = !isOwn && value.parent !== undefined
|
|
353
|
+
? ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, value.parent))
|
|
354
|
+
: undefined;
|
|
355
|
+
const managedOwnerLabel = isOwn
|
|
356
|
+
? ctx.appTfLabel
|
|
357
|
+
: sibling !== undefined && sibling.kind !== "table"
|
|
358
|
+
? sibling.tfLabel
|
|
359
|
+
: undefined;
|
|
360
|
+
if (managedOwnerLabel !== undefined) {
|
|
361
|
+
const managedLabel = scopedLabel(managedOwnerLabel, tsLabelToTfLabel(value.refName));
|
|
362
|
+
return {
|
|
363
|
+
id: expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, managedLabel, ["id"]),
|
|
364
|
+
parameterId: (name) => expr.resourceAttr("elementum_on_demand_trigger", managedLabel, ["parameter_ids", { index: name }]),
|
|
365
|
+
managedLabel,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
if (value.parent === undefined || value.parent === "") {
|
|
369
|
+
throw new EntityTfError(`foreign automation ref "${value.refName}" has no parent`);
|
|
370
|
+
}
|
|
371
|
+
if (value.parentName === undefined || value.parentName === "") {
|
|
372
|
+
throw new EntityTfError(`foreign automation ref "${value.parent}.${value.refName}" has no parentName; the owner lookup cannot use a refName as a display name`);
|
|
373
|
+
}
|
|
374
|
+
if (value.name === undefined || value.name === "") {
|
|
375
|
+
throw new EntityTfError(`foreign automation ref "${value.parent}.${value.refName}" has no lookup name`);
|
|
376
|
+
}
|
|
377
|
+
let ownerLabel;
|
|
378
|
+
let ownerId;
|
|
379
|
+
if (ctx.orgRefs !== undefined) {
|
|
380
|
+
const owner = resolveForeignRef(ownerKind, { name: value.parentName, namespace: value.parentNamespace }, ctx.orgRefs, ctx.diagnostics, `automation "${value.refName}" owner`);
|
|
381
|
+
ownerLabel = owner.tfLabel;
|
|
382
|
+
ownerId = owner.value;
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
const owner = foreignRootLookup(ownerKind, {
|
|
386
|
+
name: value.parentName,
|
|
387
|
+
namespace: value.parentNamespace,
|
|
388
|
+
});
|
|
389
|
+
ownerLabel = owner.tfLabel;
|
|
390
|
+
ownerId = expr.dataAttr(owner.resourceType, owner.tfLabel, ["id"]);
|
|
391
|
+
dataBlocks.set(`${owner.resourceType}.${owner.tfLabel}`, {
|
|
392
|
+
kind: "data",
|
|
393
|
+
type: owner.resourceType,
|
|
394
|
+
label: owner.tfLabel,
|
|
395
|
+
attrs: { [owner.lookupAttr]: owner.lookupValue },
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
const automationLabel = `${ownerLabel}_${tsLabelToTfLabel(value.refName)}`;
|
|
399
|
+
if (ctx.orgRefs !== undefined) {
|
|
400
|
+
ctx.orgRefs.rawLookup(AUTOMATION_RESOURCE_TYPE, automationLabel, value.name, { app_id: ownerId });
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
dataBlocks.set(`${AUTOMATION_RESOURCE_TYPE}.${automationLabel}`, {
|
|
404
|
+
kind: "data",
|
|
405
|
+
type: AUTOMATION_RESOURCE_TYPE,
|
|
406
|
+
label: automationLabel,
|
|
407
|
+
attrs: { app_id: ownerId, name: value.name },
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
id: expr.dataAttr(AUTOMATION_RESOURCE_TYPE, automationLabel, ["id"]),
|
|
412
|
+
parameterId: (name) => expr.dataAttr(AUTOMATION_RESOURCE_TYPE, automationLabel, ["parameter_ids", { index: name }]),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
336
415
|
function tokenToTf(value, ctx, dataBlocks) {
|
|
337
416
|
switch (value.__kind) {
|
|
338
417
|
case "user": {
|
|
@@ -415,10 +494,7 @@ function tokenToTf(value, ctx, dataBlocks) {
|
|
|
415
494
|
return expr.dataAttr("elementum_cloudlink", label, ["id"]);
|
|
416
495
|
}
|
|
417
496
|
case "automation":
|
|
418
|
-
|
|
419
|
-
throw new EntityTfError(`cross-app automation ref "${value.parent}.${value.refName}" is not supported`);
|
|
420
|
-
}
|
|
421
|
-
return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(value.refName)), ["id"]);
|
|
497
|
+
return automationTargetToTf(value, ctx, dataBlocks).id;
|
|
422
498
|
case "agent":
|
|
423
499
|
return expr.resourceAttr("elementum_agent", scopedLabel(ctx.appTfLabel, tsLabelToTfLabel(value.refName)), ["id"]);
|
|
424
500
|
case "phone-service":
|
|
@@ -453,6 +529,32 @@ function tokenToTf(value, ctx, dataBlocks) {
|
|
|
453
529
|
}
|
|
454
530
|
return expr.dataAttr(TABLE_RESOURCE_TYPE, label, ["id"]);
|
|
455
531
|
}
|
|
532
|
+
case "tableColumn": {
|
|
533
|
+
// Columns are addressed by DISPLAY name in `field_ids`, never by bag key.
|
|
534
|
+
const columnName = value.name ?? value.refName;
|
|
535
|
+
const owner = value.parent;
|
|
536
|
+
if (owner === undefined || owner === "") {
|
|
537
|
+
throw new EntityTfError(`table column ref "${value.refName}" is missing its owning table`);
|
|
538
|
+
}
|
|
539
|
+
const sibling = ctx.workspaceAspects?.get(workspaceAspectKey("table", owner));
|
|
540
|
+
if (sibling !== undefined) {
|
|
541
|
+
return expr.resourceAttr(TABLE_RESOURCE_TYPE, sibling.tfLabel, ["field_ids", { index: columnName }]);
|
|
542
|
+
}
|
|
543
|
+
const tableName = value.parentName ?? owner;
|
|
544
|
+
const label = tsLabelToTfLabel(owner);
|
|
545
|
+
if (ctx.orgRefs !== undefined) {
|
|
546
|
+
ctx.orgRefs.rawLookup(TABLE_RESOURCE_TYPE, label, tableName);
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
dataBlocks.set(`${TABLE_RESOURCE_TYPE}.${label}`, {
|
|
550
|
+
kind: "data",
|
|
551
|
+
type: TABLE_RESOURCE_TYPE,
|
|
552
|
+
label,
|
|
553
|
+
attrs: { name: tableName },
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
return expr.dataAttr(TABLE_RESOURCE_TYPE, label, ["field_ids", { index: columnName }]);
|
|
557
|
+
}
|
|
456
558
|
case "searchTable": {
|
|
457
559
|
// Ownership + variant contract:
|
|
458
560
|
// snowflake / linked -> owned by an ELEMENT
|
|
@@ -715,8 +817,8 @@ const TS_TRIGGER_REF_TO_WIRE = {
|
|
|
715
817
|
"triggeredBy.id": "Triggered By's Id",
|
|
716
818
|
"triggeredBy.name": "Triggered By's Name",
|
|
717
819
|
"triggeredBy.email": "Triggered By's Email",
|
|
718
|
-
createdByEmail: "Created
|
|
719
|
-
updatedByManagerEmail: "Updated
|
|
820
|
+
createdByEmail: "Created By Email",
|
|
821
|
+
updatedByManagerEmail: "Updated By Manager Email",
|
|
720
822
|
slackThreadId: "Slack Thread ID",
|
|
721
823
|
slackChannelId: "Slack Channel ID",
|
|
722
824
|
messageAuthorEmail: "Message Author Email",
|
|
@@ -734,6 +836,10 @@ const FIELD_REF_SUFFIX_TO_WIRE = {
|
|
|
734
836
|
email: " Email",
|
|
735
837
|
name: " Name",
|
|
736
838
|
fieldId: " Field ID",
|
|
839
|
+
// A dynamically sourced Dropdown field's selected source record.
|
|
840
|
+
// Live refs name this "<Field> - Record" (ASPECT_RECORD_ID), distinct from
|
|
841
|
+
// `id` → " ID" (the selection's PICKLIST_ID).
|
|
842
|
+
recordId: " - Record",
|
|
737
843
|
// Matches the literal path segment from-tf.ts now produces for this suffix
|
|
738
844
|
// ("as text", not camelCase "asText") - Ref<T> has no ".asText" property
|
|
739
845
|
// anywhere in the type system, so authored code can only reach this suffix
|
|
@@ -745,6 +851,15 @@ const FIELD_REF_SUFFIX_TO_WIRE = {
|
|
|
745
851
|
"employee.manager.email": " Manager Email",
|
|
746
852
|
"employee.manager.name": " Manager Name",
|
|
747
853
|
};
|
|
854
|
+
const PROVIDER_FIXED_SYSTEM_FIELD_KEYS = new Set([
|
|
855
|
+
"stage",
|
|
856
|
+
"createdAt",
|
|
857
|
+
"createdBy",
|
|
858
|
+
"updatedAt",
|
|
859
|
+
"updatedBy",
|
|
860
|
+
"closedAt",
|
|
861
|
+
"closedBy",
|
|
862
|
+
]);
|
|
748
863
|
function wireRefName(name, ctx) {
|
|
749
864
|
const known = TS_TRIGGER_REF_TO_WIRE[name];
|
|
750
865
|
if (known !== undefined)
|
|
@@ -755,13 +870,25 @@ function wireRefName(name, ctx) {
|
|
|
755
870
|
const parts = name.split(".");
|
|
756
871
|
if (parts[0] === "record" && parts.length >= 2) {
|
|
757
872
|
const fieldKey = parts[1];
|
|
873
|
+
// Pull preserves a deleted/unresolvable platform field as an explicit
|
|
874
|
+
// bracket-access escape on the record ref. Rebuild that escape byte-for-
|
|
875
|
+
// byte instead of trying to resolve the UUID as a current catalog key.
|
|
876
|
+
// This is not a public authoring path: the printer is the only supported
|
|
877
|
+
// producer, and it marks the access as an unresolved-field TODO.
|
|
878
|
+
if (isUuid(fieldKey))
|
|
879
|
+
return name;
|
|
758
880
|
// System fields (title/status/stage/createdBy/...) have no entry in
|
|
759
881
|
// ctx.fieldNames - that map only carries the app's custom fields bag.
|
|
760
882
|
// Fall back to the provider's default display name for them; a renamed
|
|
761
883
|
// system field won't match and still throws below, same as an unknown
|
|
762
884
|
// custom field key would.
|
|
763
|
-
const
|
|
764
|
-
|
|
885
|
+
const systemFieldKey = SYSTEM_FIELD_KEY_SET.has(fieldKey)
|
|
886
|
+
? fieldKey
|
|
887
|
+
: undefined;
|
|
888
|
+
const fieldName = systemFieldKey !== undefined && PROVIDER_FIXED_SYSTEM_FIELD_KEYS.has(systemFieldKey)
|
|
889
|
+
? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[systemFieldKey]
|
|
890
|
+
: ctx.fieldNames.get(fieldKey) ??
|
|
891
|
+
(systemFieldKey !== undefined ? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[systemFieldKey] : undefined);
|
|
765
892
|
if (fieldName === undefined) {
|
|
766
893
|
throw new EntityTfError(`automation reference "${name}" targets field "${parts[1]}" which does not exist in app "${ctx.appRefName}"`);
|
|
767
894
|
}
|
|
@@ -770,15 +897,11 @@ function wireRefName(name, ctx) {
|
|
|
770
897
|
if (wireSuffix === undefined) {
|
|
771
898
|
throw new EntityTfError(`automation reference "${name}" has unsupported record-field path "${suffix}"`);
|
|
772
899
|
}
|
|
773
|
-
//
|
|
774
|
-
//
|
|
775
|
-
//
|
|
776
|
-
//
|
|
777
|
-
|
|
778
|
-
// case-insensitively; build must reproduce the platform's exact casing
|
|
779
|
-
// since terraform's refs[] map lookup is case-sensitive.
|
|
780
|
-
const prefix = wireSuffix.length > 0 && fieldName.endsWith(" By") ? `${fieldName.slice(0, -3)} by` : fieldName;
|
|
781
|
-
return `${prefix}${wireSuffix}`;
|
|
900
|
+
// Build must reproduce the live refs[] key's exact casing because the
|
|
901
|
+
// Terraform map lookup is case-sensitive. The current provider emits
|
|
902
|
+
// compound audit refs with the system field's display casing intact
|
|
903
|
+
// (for example "Created By ID").
|
|
904
|
+
return `${fieldName}${wireSuffix}`;
|
|
782
905
|
}
|
|
783
906
|
// A webhook trigger's body/headers refs (ctx.trigger.body["X"]) can only
|
|
784
907
|
// type-check against DeepRefs<WebhookTriggerOutput>, so parts[0] being
|
|
@@ -838,6 +961,127 @@ function taskWireRefName(name, taskRefKey, refs) {
|
|
|
838
961
|
fieldNames: foreignNames ?? new Map(),
|
|
839
962
|
});
|
|
840
963
|
}
|
|
964
|
+
function triggerWireRefName(name, refs) {
|
|
965
|
+
const declared = onDemandTriggerRefKey(name, refs.triggerParamNames);
|
|
966
|
+
if (declared !== name || refs.triggerParamNames.includes(name))
|
|
967
|
+
return declared;
|
|
968
|
+
return wireRefName(name, refs.owner);
|
|
969
|
+
}
|
|
970
|
+
/** Run-automation targets reference publish for ACTIVE automations, automation for draft/inactive. */
|
|
971
|
+
export function automationRunTargetResourceAttr(appTfLabel, automationRefName, activeAutomationRefNames) {
|
|
972
|
+
const label = appScopedResourceLabel(appTfLabel, tsLabelToTfLabel(automationRefName));
|
|
973
|
+
if (activeAutomationRefNames?.has(automationRefName) === true) {
|
|
974
|
+
return expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, label, ["id"]);
|
|
975
|
+
}
|
|
976
|
+
return expr.resourceAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]);
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* workflow_publish outputs must match provider Read / ei export: a typed
|
|
980
|
+
* `jsonencode({ fieldType, multiple, taskReference|... })` envelope — not
|
|
981
|
+
* `task.refs[...]`, which can still resolve to a generic TEXT blob.
|
|
982
|
+
*/
|
|
983
|
+
function workflowPublishOutputValueToTf(value, refs) {
|
|
984
|
+
// Pulled `.outputs()` often wraps each envelope as `{ value: <envelope> }`
|
|
985
|
+
// (ValueOrRef STATIC). Unwrap before classifying so name-only variable refs
|
|
986
|
+
// still become `jsonencode(...)` strings.
|
|
987
|
+
while (isObject(value) && "value" in value && Object.keys(value).length === 1) {
|
|
988
|
+
value = value.value;
|
|
989
|
+
}
|
|
990
|
+
const envelope = workflowPublishOutputEnvelope(value, refs);
|
|
991
|
+
if (envelope !== undefined)
|
|
992
|
+
return expr.jsonencode(envelope);
|
|
993
|
+
// Export-shaped envelopes (often name-only variable refs) must stay JSON
|
|
994
|
+
// strings — the provider schema requires `outputs[].value` to be a string.
|
|
995
|
+
if (isObject(value) && ("taskReference" in value || "triggerReference" in value || "variableReference" in value)) {
|
|
996
|
+
return expr.jsonencode(valueToTf(value, refs));
|
|
997
|
+
}
|
|
998
|
+
return valueToTf(value, refs);
|
|
999
|
+
}
|
|
1000
|
+
function workflowPublishOutputEnvelope(value, refs) {
|
|
1001
|
+
if (!isObject(value))
|
|
1002
|
+
return undefined;
|
|
1003
|
+
if (isObject(value.taskReference) && typeof value.taskReference.taskRefKey === "string" && typeof value.taskReference.name === "string") {
|
|
1004
|
+
const target = refs.tasks.get(value.taskReference.taskRefKey);
|
|
1005
|
+
if (target === undefined)
|
|
1006
|
+
return undefined;
|
|
1007
|
+
const isFileReaderTask = target.type === "elementum_ai_file_read_task" || target.type === "elementum_file_reader_task";
|
|
1008
|
+
const isAiSearchTableRecords = target.type === "elementum_ai_search_table_task" &&
|
|
1009
|
+
(value.taskReference.name === "records" || value.taskReference.name === "All Records");
|
|
1010
|
+
const isTableRecordsSearchRecords = target.type === "elementum_table_records_search_task" &&
|
|
1011
|
+
(value.taskReference.name === "records" || value.taskReference.name === "All matching table rows");
|
|
1012
|
+
const wireName = isFileReaderTask
|
|
1013
|
+
? value.taskReference.name
|
|
1014
|
+
: isAiSearchTableRecords
|
|
1015
|
+
? "All Records"
|
|
1016
|
+
: isTableRecordsSearchRecords
|
|
1017
|
+
? value.taskReference.name === "All matching table rows"
|
|
1018
|
+
? "All matching table rows"
|
|
1019
|
+
: "records"
|
|
1020
|
+
: taskWireRefName(value.taskReference.name, value.taskReference.taskRefKey, refs);
|
|
1021
|
+
const typed = publishOutputType(value, target, wireName);
|
|
1022
|
+
return {
|
|
1023
|
+
fieldType: typed.fieldType,
|
|
1024
|
+
multiple: typed.multiple,
|
|
1025
|
+
taskReference: {
|
|
1026
|
+
name: wireName,
|
|
1027
|
+
taskId: expr.resourceAttr(target.type, target.label, ["id"]),
|
|
1028
|
+
},
|
|
1029
|
+
// ei export always pads the unused reference arms with null.
|
|
1030
|
+
triggerReference: null,
|
|
1031
|
+
variableReference: null,
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
if (isObject(value.triggerReference) && typeof value.triggerReference.name === "string") {
|
|
1035
|
+
const typed = publishOutputType(value, undefined, value.triggerReference.name);
|
|
1036
|
+
return {
|
|
1037
|
+
fieldType: typed.fieldType,
|
|
1038
|
+
multiple: typed.multiple,
|
|
1039
|
+
taskReference: null,
|
|
1040
|
+
triggerReference: { name: wireRefName(value.triggerReference.name, refs.owner) },
|
|
1041
|
+
variableReference: null,
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
if (isObject(value.variableReference)) {
|
|
1045
|
+
const id = typeof value.variableReference.id === "string" ? value.variableReference.id : undefined;
|
|
1046
|
+
const name = typeof value.variableReference.name === "string" ? value.variableReference.name : undefined;
|
|
1047
|
+
// ei export / pull shape: `variableReference = { name = "variable|<uuid>" }`
|
|
1048
|
+
// with sibling null refs — not fieldType+id. Prefer that wire form.
|
|
1049
|
+
const wireName = name ?? (id !== undefined ? `variable|${id}` : undefined);
|
|
1050
|
+
if (wireName !== undefined) {
|
|
1051
|
+
return {
|
|
1052
|
+
taskReference: null,
|
|
1053
|
+
triggerReference: null,
|
|
1054
|
+
variableReference: { name: wireName },
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return undefined;
|
|
1059
|
+
}
|
|
1060
|
+
function publishOutputType(value, target, wireName) {
|
|
1061
|
+
if (typeof value.fieldType === "string") {
|
|
1062
|
+
return { fieldType: value.fieldType, multiple: value.multiple === true };
|
|
1063
|
+
}
|
|
1064
|
+
if (target?.outputFieldTypes !== undefined) {
|
|
1065
|
+
const fromSchema = target.outputFieldTypes.get(wireName) ?? target.outputFieldTypes.get(wireName.replace(/^result\./, ""));
|
|
1066
|
+
if (fromSchema !== undefined)
|
|
1067
|
+
return fromSchema;
|
|
1068
|
+
}
|
|
1069
|
+
if (target !== undefined) {
|
|
1070
|
+
if ((target.type === "elementum_create_record_task" || target.type === "elementum_find_related_records_task") &&
|
|
1071
|
+
(wireName === "Record" || wireName === "Record ID")) {
|
|
1072
|
+
return { fieldType: "ASPECT_RECORD_ID", multiple: false };
|
|
1073
|
+
}
|
|
1074
|
+
if ((target.type === "elementum_record_search_task" || target.type === "elementum_find_related_records_task") &&
|
|
1075
|
+
(wireName === "All found records" || wireName === "records")) {
|
|
1076
|
+
return { fieldType: "ASPECT_RECORD_ID", multiple: true };
|
|
1077
|
+
}
|
|
1078
|
+
if ((target.type === "elementum_ai_search_table_task" || target.type === "elementum_table_records_search_task") &&
|
|
1079
|
+
(wireName === "All Records" || wireName === "records" || wireName === "All matching table rows")) {
|
|
1080
|
+
return { fieldType: "TABLE_RECORD", multiple: true };
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
return { fieldType: "TEXT", multiple: value.multiple === true };
|
|
1084
|
+
}
|
|
841
1085
|
function valueToTf(value, refs) {
|
|
842
1086
|
const catalog = token(value);
|
|
843
1087
|
if (catalog !== undefined)
|
|
@@ -861,7 +1105,7 @@ function valueToTf(value, refs) {
|
|
|
861
1105
|
return expr.resourceAttr(target.type, target.label, ["refs", { index: target.name }]);
|
|
862
1106
|
}
|
|
863
1107
|
if (isObject(value.triggerReference) && typeof value.triggerReference.name === "string") {
|
|
864
|
-
return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index:
|
|
1108
|
+
return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerWireRefName(value.triggerReference.name, refs) }]);
|
|
865
1109
|
}
|
|
866
1110
|
if (isObject(value.taskReference) && typeof value.taskReference.taskRefKey === "string" && typeof value.taskReference.name === "string") {
|
|
867
1111
|
const target = refs.tasks.get(value.taskReference.taskRefKey);
|
|
@@ -883,11 +1127,16 @@ function valueToTf(value, refs) {
|
|
|
883
1127
|
// from rewriteForwardTaskRefName so either path emits the same key.
|
|
884
1128
|
const isAiSearchTableRecords = target.type === "elementum_ai_search_table_task" &&
|
|
885
1129
|
(value.taskReference.name === "records" || value.taskReference.name === "All Records");
|
|
1130
|
+
// tableRecordsSearch uses yet another wire key: "All matching table rows".
|
|
1131
|
+
const isTableRecordsSearchRecords = target.type === "elementum_table_records_search_task" &&
|
|
1132
|
+
(value.taskReference.name === "records" || value.taskReference.name === "All matching table rows");
|
|
886
1133
|
const refKey = isFileReaderTask
|
|
887
1134
|
? value.taskReference.name
|
|
888
1135
|
: isAiSearchTableRecords
|
|
889
1136
|
? "All Records"
|
|
890
|
-
:
|
|
1137
|
+
: isTableRecordsSearchRecords
|
|
1138
|
+
? "All matching table rows"
|
|
1139
|
+
: taskWireRefName(value.taskReference.name, value.taskReference.taskRefKey, refs);
|
|
891
1140
|
return expr.resourceAttr(target.type, target.label, ["refs", { index: refKey }]);
|
|
892
1141
|
}
|
|
893
1142
|
if (isObject(value.forEachReference) && typeof value.forEachReference.forEachTaskRefKey === "string" && typeof value.forEachReference.name === "string") {
|
|
@@ -923,7 +1172,7 @@ function unwrapDefault(value) {
|
|
|
923
1172
|
const values = Object.values(value);
|
|
924
1173
|
return values.length === 1 ? values[0] : value;
|
|
925
1174
|
}
|
|
926
|
-
function filterReferenceToTf(value, refs) {
|
|
1175
|
+
function filterReferenceToTf(value, refs, role = "value", realType) {
|
|
927
1176
|
// Raw pass-through for a filter left side the pull-time deserializer
|
|
928
1177
|
// couldn't decode to a typed ref (filter.ts's leftDescriptor, matching the
|
|
929
1178
|
// UNRESOLVED_REFERENCE_MARKER case) - reproduces the original value_reference
|
|
@@ -947,6 +1196,7 @@ function filterReferenceToTf(value, refs) {
|
|
|
947
1196
|
const fieldKey = parts[1];
|
|
948
1197
|
const address = refs.owner.fieldAddresses.get(fieldKey);
|
|
949
1198
|
const suffix = parts.slice(2).join(".");
|
|
1199
|
+
const wireSuffix = suffix === "recordId" ? "10000001-2000-4000-a000-800000000000" : suffix;
|
|
950
1200
|
// A bare reference to a PICKLIST field (STATUS/STAGE included —
|
|
951
1201
|
// `serializeSystemFields` wire-wraps both as a picklist too) has no
|
|
952
1202
|
// valid suffix-less wire form — confirmed live via the platform's
|
|
@@ -967,7 +1217,7 @@ function filterReferenceToTf(value, refs) {
|
|
|
967
1217
|
return expr.template([
|
|
968
1218
|
"trigger.record.",
|
|
969
1219
|
addressExpr(address, ["id"]),
|
|
970
|
-
...(
|
|
1220
|
+
...(wireSuffix.length > 0 ? [`.${wireSuffix}`] : []),
|
|
971
1221
|
]);
|
|
972
1222
|
}
|
|
973
1223
|
// System fields (id/title/status/createdBy/updatedBy/...) have no
|
|
@@ -983,7 +1233,7 @@ function filterReferenceToTf(value, refs) {
|
|
|
983
1233
|
return expr.template([
|
|
984
1234
|
"trigger.record.",
|
|
985
1235
|
expr.local(`${refs.owner.appTfLabel}_${tsLabelToTfLabel(fieldKey)}_field_id`),
|
|
986
|
-
...(
|
|
1236
|
+
...(wireSuffix.length > 0 ? [`.${wireSuffix}`] : []),
|
|
987
1237
|
]);
|
|
988
1238
|
}
|
|
989
1239
|
// Orphaned field reference: from-tf.ts round-trips a filter
|
|
@@ -997,7 +1247,11 @@ function filterReferenceToTf(value, refs) {
|
|
|
997
1247
|
return `trigger.${value.name}`;
|
|
998
1248
|
}
|
|
999
1249
|
}
|
|
1000
|
-
|
|
1250
|
+
const triggerRefKey = triggerWireRefName(value.name, refs);
|
|
1251
|
+
if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
|
|
1252
|
+
return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["filter_refs", { index: triggerRefKey }]);
|
|
1253
|
+
}
|
|
1254
|
+
return expr.resourceAttr(refs.trigger.type, refs.trigger.label, ["refs", { index: triggerRefKey }]);
|
|
1001
1255
|
}
|
|
1002
1256
|
case "TASK": {
|
|
1003
1257
|
if (typeof value.taskRefKey !== "string" || typeof value.name !== "string")
|
|
@@ -1005,7 +1259,37 @@ function filterReferenceToTf(value, refs) {
|
|
|
1005
1259
|
const task = refs.tasks.get(value.taskRefKey);
|
|
1006
1260
|
if (task === undefined)
|
|
1007
1261
|
throw new EntityTfError(`unresolved task filter ref "${value.taskRefKey}"`);
|
|
1008
|
-
|
|
1262
|
+
const wireName = taskWireRefName(value.name, value.taskRefKey, refs);
|
|
1263
|
+
// left_value (switch cases): provider Read stores the JSON envelope that
|
|
1264
|
+
// `.refs["…"]` evaluates to (#490). Emitting the short `task.<id>.…`
|
|
1265
|
+
// string matches record_search RHS state but perpetual-diffs left_value.
|
|
1266
|
+
// value (RHS, e.g. record_search filters): state / ei use the short form.
|
|
1267
|
+
//
|
|
1268
|
+
// API `statusCode` is the exception: ei export jsonencodes the authored
|
|
1269
|
+
// TEXT envelope (`name = "statusCode"`). `.refs["API Response Status
|
|
1270
|
+
// Code"]` is NUMBER and plans against that export (Sanofi saveAttachment).
|
|
1271
|
+
if (role === "left") {
|
|
1272
|
+
const isApiStatusCode = task.type === TASK_RESOURCES.api &&
|
|
1273
|
+
(value.name === "statusCode" ||
|
|
1274
|
+
value.name === API_TASK_REF_WIRE_NAMES.statusCode ||
|
|
1275
|
+
wireName === API_TASK_REF_WIRE_NAMES.statusCode);
|
|
1276
|
+
if (isApiStatusCode) {
|
|
1277
|
+
return expr.jsonencode({
|
|
1278
|
+
fieldType: (realType ?? "TEXT").toUpperCase(),
|
|
1279
|
+
multiple: false,
|
|
1280
|
+
taskReference: {
|
|
1281
|
+
name: API_TASK_REF_AUTHORING_NAMES[wireName] ?? "statusCode",
|
|
1282
|
+
taskId: expr.resourceAttr(task.type, task.label, ["id"]),
|
|
1283
|
+
},
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
return expr.resourceAttr(task.type, task.label, ["refs", { index: wireName }]);
|
|
1287
|
+
}
|
|
1288
|
+
return expr.template([
|
|
1289
|
+
"task.",
|
|
1290
|
+
expr.resourceAttr(task.type, task.label, ["id"]),
|
|
1291
|
+
`.${wireName}`,
|
|
1292
|
+
]);
|
|
1009
1293
|
}
|
|
1010
1294
|
case "FOR_EACH": {
|
|
1011
1295
|
if (typeof value.forEachTaskRefKey !== "string" || typeof value.name !== "string")
|
|
@@ -1024,7 +1308,7 @@ function filterReferenceToTf(value, refs) {
|
|
|
1024
1308
|
function picklistFilterValueToTf(value, field, refs) {
|
|
1025
1309
|
if (typeof value !== "string" ||
|
|
1026
1310
|
field?.__kind !== "field" ||
|
|
1027
|
-
field.fieldType !== "PICKLIST" ||
|
|
1311
|
+
(field.fieldType !== "PICKLIST" && field.fieldType !== "MULTI_PICKLIST") ||
|
|
1028
1312
|
field.options === undefined)
|
|
1029
1313
|
return undefined;
|
|
1030
1314
|
// An empty value is the platform's explicit "clear this field" payload,
|
|
@@ -1115,7 +1399,7 @@ function filterToTf(value, refs) {
|
|
|
1115
1399
|
return serializeFilterToTf(value, {
|
|
1116
1400
|
field: (field) => valueToTf(field, refs),
|
|
1117
1401
|
fieldFromLeftValue: (left) => fieldFromFilterLeftValue(left, refs),
|
|
1118
|
-
reference: (reference) => filterReferenceToTf(reference, refs),
|
|
1402
|
+
reference: (reference, role, realType) => filterReferenceToTf(reference, refs, role ?? "value", realType),
|
|
1119
1403
|
literal: (literal, field) => picklistFilterValueToTf(literal, token(field), refs) ?? valueToTf(literal, refs),
|
|
1120
1404
|
});
|
|
1121
1405
|
}
|
|
@@ -1143,6 +1427,72 @@ function configAttrs(kind, config, refs) {
|
|
|
1143
1427
|
attrs.relate_to_record_reference = valueToTf(raw, refs);
|
|
1144
1428
|
continue;
|
|
1145
1429
|
}
|
|
1430
|
+
if (key === "code" && kind === "elementum_execute_script_task") {
|
|
1431
|
+
if (typeof raw !== "string")
|
|
1432
|
+
throw new EntityTfError("executeScript code must be a string");
|
|
1433
|
+
attrs.code = raw;
|
|
1434
|
+
continue;
|
|
1435
|
+
}
|
|
1436
|
+
if (key === "inputMappings" && kind === "elementum_run_automation_task") {
|
|
1437
|
+
if (!Array.isArray(raw))
|
|
1438
|
+
throw new EntityTfError("runAutomation inputMappings must be an array");
|
|
1439
|
+
const target = token(config.targetAutomationId);
|
|
1440
|
+
if (target?.__kind !== "automation") {
|
|
1441
|
+
attrs.dynamic_input_mappings = raw.map((mapping) => {
|
|
1442
|
+
if (!isObject(mapping) || typeof mapping.name !== "string" || mapping.value === undefined) {
|
|
1443
|
+
throw new EntityTfError("runAutomation input mapping requires name and value");
|
|
1444
|
+
}
|
|
1445
|
+
return { name: mapping.name, value: valueToTf(mapping.value, refs) };
|
|
1446
|
+
});
|
|
1447
|
+
continue;
|
|
1448
|
+
}
|
|
1449
|
+
const resolvedTarget = automationTargetToTf(target, refs.owner, refs.dataBlocks);
|
|
1450
|
+
attrs.input_mappings = raw.map((mapping) => {
|
|
1451
|
+
if (!isObject(mapping) || typeof mapping.name !== "string" || mapping.value === undefined) {
|
|
1452
|
+
throw new EntityTfError("runAutomation input mapping requires name and value");
|
|
1453
|
+
}
|
|
1454
|
+
return {
|
|
1455
|
+
parameter_id: resolvedTarget.parameterId(mapping.name),
|
|
1456
|
+
value: valueToTf(mapping.value, refs),
|
|
1457
|
+
};
|
|
1458
|
+
});
|
|
1459
|
+
continue;
|
|
1460
|
+
}
|
|
1461
|
+
if (key === "targetAutomationRef" && kind === "elementum_run_automation_task") {
|
|
1462
|
+
if (!isObject(raw) || raw.type !== "STATIC") {
|
|
1463
|
+
throw new EntityTfError("runAutomation targetAutomationRef must be { type: \"STATIC\", value: ... }");
|
|
1464
|
+
}
|
|
1465
|
+
const target = token(raw.value);
|
|
1466
|
+
if (target?.__kind === "automation") {
|
|
1467
|
+
attrs["target_automation_ref"] = automationRunTargetResourceAttr(refs.owner.appTfLabel, target.refName, refs.owner.activeAutomationRefNames);
|
|
1468
|
+
continue;
|
|
1469
|
+
}
|
|
1470
|
+
// Pull may leave a bare platform UUID when the target automation was
|
|
1471
|
+
// not discovered in this stream (ei export does the same). Emit
|
|
1472
|
+
// target_automation_id so the parent automation still builds —
|
|
1473
|
+
// otherwise skill tools that only need the catalog key fail closed.
|
|
1474
|
+
if (typeof raw.value === "string" && raw.value !== "") {
|
|
1475
|
+
attrs["target_automation_id"] = raw.value;
|
|
1476
|
+
refs.owner.diagnostics?.push(`runAutomation: target automation ${JSON.stringify(raw.value)} is unresolved; emitted as bare id`);
|
|
1477
|
+
continue;
|
|
1478
|
+
}
|
|
1479
|
+
throw new EntityTfError("runAutomation targetAutomationRef has an unresolved automation");
|
|
1480
|
+
}
|
|
1481
|
+
if (key === "targetAutomationId" && kind === "elementum_run_automation_task") {
|
|
1482
|
+
const target = token(raw);
|
|
1483
|
+
if (target?.__kind === "automation") {
|
|
1484
|
+
attrs["target_automation_id"] = automationTargetToTf(target, refs.owner, refs.dataBlocks).id;
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
if (typeof raw === "string" && raw !== "") {
|
|
1488
|
+
attrs[Array.isArray(config.inputMappings) && config.inputMappings.length > 0
|
|
1489
|
+
? "target_automation_ref"
|
|
1490
|
+
: "target_automation_id"] = raw;
|
|
1491
|
+
refs.owner.diagnostics?.push(`runAutomation: target automation ${JSON.stringify(raw)} is unresolved; emitted as bare id`);
|
|
1492
|
+
continue;
|
|
1493
|
+
}
|
|
1494
|
+
throw new EntityTfError("runAutomation targetAutomationId has an unresolved automation");
|
|
1495
|
+
}
|
|
1146
1496
|
if (key === "filter") {
|
|
1147
1497
|
attrs.filter = filterToTf(raw, refs);
|
|
1148
1498
|
continue;
|
|
@@ -1292,12 +1642,24 @@ function configAttrs(kind, config, refs) {
|
|
|
1292
1642
|
const staticValue = isObject(field.valueReference) && "value" in field.valueReference
|
|
1293
1643
|
? field.valueReference.value
|
|
1294
1644
|
: undefined;
|
|
1645
|
+
if (Array.isArray(staticValue)) {
|
|
1646
|
+
if (fieldToken?.fieldType !== "MULTI_PICKLIST") {
|
|
1647
|
+
throw new EntityTfError(`automation field "${fieldToken?.name ?? fieldToken?.refName ?? "unknown"}" uses an array value but is not a Multi-Select field`);
|
|
1648
|
+
}
|
|
1649
|
+
const values = staticValue.map((value) => picklistFilterValueToTf(value, fieldToken, refs) ?? valueToTf(value, refs));
|
|
1650
|
+
return {
|
|
1651
|
+
field_id: valueToTf(field.aspectFieldId, refs),
|
|
1652
|
+
value: expr.jsonencode(values),
|
|
1653
|
+
...(field.operation === "ADD" ? { update_mode: "add" } : {}),
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1295
1656
|
const optionValue = staticValue !== undefined
|
|
1296
1657
|
? picklistFilterValueToTf(staticValue, fieldToken, refs)
|
|
1297
1658
|
: undefined;
|
|
1298
1659
|
return {
|
|
1299
1660
|
field_id: valueToTf(field.aspectFieldId, refs),
|
|
1300
1661
|
value: optionValue ?? valueToTf(field.valueReference, refs),
|
|
1662
|
+
...(field.operation === "ADD" ? { update_mode: "add" } : {}),
|
|
1301
1663
|
};
|
|
1302
1664
|
});
|
|
1303
1665
|
continue;
|
|
@@ -1456,24 +1818,26 @@ function fileReaderDependsOn(blocks) {
|
|
|
1456
1818
|
return deps;
|
|
1457
1819
|
}
|
|
1458
1820
|
function taskLabel(automationLabel, refKey) {
|
|
1459
|
-
// ei's task label is `<auto>_<sanitizeName(task name)>`
|
|
1460
|
-
//
|
|
1461
|
-
//
|
|
1462
|
-
//
|
|
1463
|
-
//
|
|
1464
|
-
//
|
|
1465
|
-
//
|
|
1466
|
-
//
|
|
1467
|
-
//
|
|
1468
|
-
//
|
|
1469
|
-
|
|
1470
|
-
|
|
1821
|
+
// ei's task label is `<auto>_<sanitizeName(task name)>` for display-name
|
|
1822
|
+
// stems. Pulled refKeys that are already canonical camelCase (e.g.
|
|
1823
|
+
// `commodityBHit_1`) must use the lossless `tsLabelToTfLabel` bijection —
|
|
1824
|
+
// `sanitizeName` lowercases before splitCamelCase and collapses
|
|
1825
|
+
// single-letter camel segments (`commodityBHit` → `commodityb_hit`), which
|
|
1826
|
+
// plans destroy+create against export's `commodity_b_hit_1`.
|
|
1827
|
+
//
|
|
1828
|
+
// ALLCAPS / SCREAMING_SNAKE refKeys (`GREETING`) also round-trip the
|
|
1829
|
+
// bijection (via ugly `_g_r_e_e_t_i_n_g`), but ei's SanitizeName yields
|
|
1830
|
+
// `greeting` — require a lowercase letter before preferring the bijection.
|
|
1831
|
+
const normalized = isCanonicalTsLabel(refKey) && /[a-z]/.test(refKey)
|
|
1832
|
+
? tsLabelToTfLabel(refKey)
|
|
1833
|
+
: sanitizeName(refKey);
|
|
1471
1834
|
return normalized.startsWith(`${automationLabel}_`) ? normalized : `${automationLabel}_${normalized}`;
|
|
1472
1835
|
}
|
|
1473
1836
|
/** App- or element-owned `automation` entity → provider HCL blocks. */
|
|
1474
1837
|
export function automationToTf(entity, ctx) {
|
|
1475
1838
|
const owner = {
|
|
1476
1839
|
appRefName: ctx.appRefName ?? entity.parent,
|
|
1840
|
+
parentScope: ctx.parentScope ?? "app",
|
|
1477
1841
|
appTfLabel: ctx.appTfLabel,
|
|
1478
1842
|
fieldAddresses: ctx.fieldAddresses ?? new Map(),
|
|
1479
1843
|
fieldNames: ctx.fieldNames ?? new Map(),
|
|
@@ -1482,6 +1846,7 @@ export function automationToTf(entity, ctx) {
|
|
|
1482
1846
|
localsAttrs: ctx.localsAttrs,
|
|
1483
1847
|
workspaceAspects: ctx.workspaceAspects,
|
|
1484
1848
|
diagnostics: ctx.diagnostics ?? [],
|
|
1849
|
+
activeAutomationRefNames: ctx.activeAutomationRefNames,
|
|
1485
1850
|
};
|
|
1486
1851
|
if (entity.kind !== "automation")
|
|
1487
1852
|
throw new EntityTfError(`automationToTf expects kind "automation"; got "${entity.kind}"`);
|
|
@@ -1549,7 +1914,14 @@ export function automationToTf(entity, ctx) {
|
|
|
1549
1914
|
throw new EntityTfError(`task "${refKey}" sanitizes to the same tf label as task "${collidingRefKey}" (${registeredLabel}) — rename one of them`);
|
|
1550
1915
|
}
|
|
1551
1916
|
usedLabels.set(registeredLabel, refKey);
|
|
1552
|
-
|
|
1917
|
+
const outputFieldTypes = wireType === "executeScript"
|
|
1918
|
+
? outputFieldTypesFromScriptSchema(taskBody.outputSchema)
|
|
1919
|
+
: undefined;
|
|
1920
|
+
taskRefs.set(refKey, {
|
|
1921
|
+
type: resourceType,
|
|
1922
|
+
label: registeredLabel,
|
|
1923
|
+
...(outputFieldTypes !== undefined && outputFieldTypes.size > 0 ? { outputFieldTypes } : {}),
|
|
1924
|
+
});
|
|
1553
1925
|
if (wireType === "variable" && Array.isArray(taskBody.create)) {
|
|
1554
1926
|
for (const candidate of taskBody.create) {
|
|
1555
1927
|
if (isObject(candidate) && typeof candidate.id === "string" && typeof candidate.name === "string") {
|
|
@@ -1564,8 +1936,12 @@ export function automationToTf(entity, ctx) {
|
|
|
1564
1936
|
preRegister(payload.tasks ?? []);
|
|
1565
1937
|
const dataBlocks = new Map();
|
|
1566
1938
|
const recordFieldContext = recordFieldContextOf(entity);
|
|
1939
|
+
const triggerParamNames = triggerKey === "onDemand" && isObject(triggerConfig) && Array.isArray(triggerConfig.inputs)
|
|
1940
|
+
? triggerConfig.inputs.flatMap((input) => isObject(input) && typeof input.name === "string" ? [input.name] : [])
|
|
1941
|
+
: [];
|
|
1567
1942
|
const refs = {
|
|
1568
1943
|
trigger: { type: triggerType, label },
|
|
1944
|
+
triggerParamNames,
|
|
1569
1945
|
tasks: taskRefs,
|
|
1570
1946
|
owner,
|
|
1571
1947
|
dataBlocks,
|
|
@@ -1608,7 +1984,19 @@ export function automationToTf(entity, ctx) {
|
|
|
1608
1984
|
if (explicitParent === undefined) {
|
|
1609
1985
|
throw new EntityTfError(`task "${refKey}" has unresolved explicit parent "${task.hclParent}"`);
|
|
1610
1986
|
}
|
|
1611
|
-
|
|
1987
|
+
// Naming the ENCLOSING forEach as the explicit parent means "head of the
|
|
1988
|
+
// loop body" (`<for_each>.inner`), not "sibling after the loop" (the
|
|
1989
|
+
// bare task) — ei writes those as two different addresses. Dropping the
|
|
1990
|
+
// path lifts the task out of the loop, and the provider then resolves
|
|
1991
|
+
// its operator context to the loop's own parent.
|
|
1992
|
+
const inBodyOfExplicitParent = initialParent.$expr === "resource-attr" &&
|
|
1993
|
+
initialParent.type === explicitParent.type &&
|
|
1994
|
+
initialParent.label === explicitParent.label &&
|
|
1995
|
+
initialParent.path.length === 1 &&
|
|
1996
|
+
initialParent.path[0] === "inner";
|
|
1997
|
+
taskParent = inBodyOfExplicitParent
|
|
1998
|
+
? initialParent
|
|
1999
|
+
: expr.resourceAttr(explicitParent.type, explicitParent.label);
|
|
1612
2000
|
}
|
|
1613
2001
|
if (wireType === "variable") {
|
|
1614
2002
|
const variableType = variableTaskResourceType(inner, refKey);
|
|
@@ -1652,15 +2040,17 @@ export function automationToTf(entity, ctx) {
|
|
|
1652
2040
|
const block = { kind: "resource", type: resourceType, label: tfLabel, attrs };
|
|
1653
2041
|
if (wireType === "runAutomation") {
|
|
1654
2042
|
const target = token(inner.targetAutomationId) ?? (isObject(inner.targetAutomationRef) ? token(inner.targetAutomationRef.value) : undefined);
|
|
1655
|
-
if (target ===
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
2043
|
+
if (target?.__kind === "automation") {
|
|
2044
|
+
const targetLabel = scopedLabel(owner.appTfLabel, tsLabelToTfLabel(target.refName));
|
|
2045
|
+
// A publish resource only exists for ACTIVE automations. Depending on
|
|
2046
|
+
// a draft/inactive target's publish address produces invalid HCL.
|
|
2047
|
+
if (ctx.activeAutomationRefNames?.has(target.refName) === true) {
|
|
2048
|
+
block.attrs.depends_on = [expr.resourceAttr(WORKFLOW_PUBLISH_RESOURCE_TYPE, targetLabel)];
|
|
2049
|
+
runAutomationPublishes.add(targetLabel);
|
|
2050
|
+
}
|
|
1663
2051
|
}
|
|
2052
|
+
// Bare-UUID / unresolved targets skip depends_on — configAttrs already
|
|
2053
|
+
// emitted target_automation_id as a literal and pushed a diagnostic.
|
|
1664
2054
|
}
|
|
1665
2055
|
blocks.push(block);
|
|
1666
2056
|
const address = expr.resourceAttr(resourceType, tfLabel);
|
|
@@ -1687,17 +2077,23 @@ export function automationToTf(entity, ctx) {
|
|
|
1687
2077
|
let previous;
|
|
1688
2078
|
for (const [index, child] of children.entries()) {
|
|
1689
2079
|
const branchType = wireType === "switch" ? "elementum_switch_case" : "elementum_fork_join_branch";
|
|
2080
|
+
const isDefault = wireType === "switch" && (child.isDefault === true || child.label === null);
|
|
1690
2081
|
// ei's own resource label follows the branch's real display text
|
|
1691
2082
|
// (a default branch renamed "Default Path" exports as
|
|
1692
2083
|
// "..._default_path", not a hardcoded "..._default") - confirmed live.
|
|
1693
|
-
const
|
|
2084
|
+
const fallbackLabel = isDefault ? "default" : `branch_${index + 1}`;
|
|
2085
|
+
const branchLabel = `${tfLabel}_${snakeSlug(child.label ?? child.defaultLabel ?? fallbackLabel)}`;
|
|
1694
2086
|
const branchAttrs = {
|
|
1695
2087
|
[wireType === "switch" ? "switch_task" : "fork_join_task"]: address,
|
|
1696
|
-
|
|
2088
|
+
...(isDefault
|
|
2089
|
+
? { label: child.defaultLabel ?? "Default" }
|
|
2090
|
+
: child.label !== undefined && child.label !== null
|
|
2091
|
+
? { label: child.label }
|
|
2092
|
+
: {}),
|
|
1697
2093
|
...(previous !== undefined ? { [wireType === "switch" ? "previous_case_id" : "previous_branch_id"]: { ...previous, path: ["id"] } } : {}),
|
|
1698
2094
|
};
|
|
1699
2095
|
if (wireType === "switch") {
|
|
1700
|
-
if (
|
|
2096
|
+
if (isDefault) {
|
|
1701
2097
|
// The provider schema documents `filter`/`is_default` as
|
|
1702
2098
|
// mutually exclusive ways to mark a switch default case, but
|
|
1703
2099
|
// the platform doesn't retroactively normalize existing cases
|
|
@@ -1762,7 +2158,7 @@ export function automationToTf(entity, ctx) {
|
|
|
1762
2158
|
? { outputs: outputValues.map((output) => {
|
|
1763
2159
|
if (typeof output.name !== "string")
|
|
1764
2160
|
throw new EntityTfError("automation output has no name");
|
|
1765
|
-
return { name: output.name, value:
|
|
2161
|
+
return { name: output.name, value: workflowPublishOutputValueToTf(output.value, refs) };
|
|
1766
2162
|
}) }
|
|
1767
2163
|
: {}),
|
|
1768
2164
|
},
|