@elementumai/edk 0.13.2 → 0.13.4

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.
Files changed (45) hide show
  1. package/dist-sdk/src/engine/coverage-gaps.d.ts +3 -0
  2. package/dist-sdk/src/engine/coverage-gaps.js +5 -0
  3. package/dist-sdk/src/engine/pull/context.d.ts +10 -4
  4. package/dist-sdk/src/engine/pull/context.js +2 -0
  5. package/dist-sdk/src/engine/pull/stream-root.d.ts +7 -1
  6. package/dist-sdk/src/engine/pull/stream-root.js +6 -0
  7. package/dist-sdk/src/engine/tf/index.d.ts +1 -0
  8. package/dist-sdk/src/engine/tf/index.js +1 -0
  9. package/dist-sdk/src/engine/tf/jsonencode.d.ts +19 -0
  10. package/dist-sdk/src/engine/tf/jsonencode.js +49 -0
  11. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  12. package/dist-sdk/src/entities/automation/approval-trigger-refs.d.ts +20 -0
  13. package/dist-sdk/src/entities/automation/approval-trigger-refs.js +83 -0
  14. package/dist-sdk/src/entities/automation/build.js +1 -1
  15. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +15 -0
  16. package/dist-sdk/src/entities/automation/from-tf.d.ts +2 -0
  17. package/dist-sdk/src/entities/automation/from-tf.js +104 -14
  18. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  19. package/dist-sdk/src/entities/automation/lookup-owner.d.ts +23 -0
  20. package/dist-sdk/src/entities/automation/lookup-owner.js +27 -0
  21. package/dist-sdk/src/entities/automation/module.js +200 -20
  22. package/dist-sdk/src/entities/automation/omitted-ref.d.ts +12 -0
  23. package/dist-sdk/src/entities/automation/omitted-ref.js +21 -0
  24. package/dist-sdk/src/entities/automation/to-tf.js +170 -5
  25. package/dist-sdk/src/entities/automation/triggers.d.ts +47 -1
  26. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +10 -5
  27. package/dist-sdk/src/entities/automation/unsafe-script-output.js +10 -5
  28. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +43 -18
  29. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +37 -21
  30. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +47 -5
  31. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  32. package/dist-sdk/src/entities/shared/filters/ast.d.ts +6 -0
  33. package/dist-sdk/src/entities/shared/filters/index.d.ts +15 -3
  34. package/dist-sdk/src/entities/shared/filters/index.js +19 -1
  35. package/dist-sdk/src/entities/shared/filters/print.js +5 -0
  36. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +13 -0
  37. package/dist-sdk/src/entities/shared/filters/tf-codec.js +74 -1
  38. package/dist-sdk/src/entities/shared/filters/types.d.ts +8 -1
  39. package/dist-sdk/src/entities/widget/from-tf.js +8 -4
  40. package/dist-sdk/src/entities/widget/to-tf.js +2 -1
  41. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +4 -2
  42. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  43. package/dist-sdk/src/graph/index.d.ts +1 -1
  44. package/dist-sdk/src/graph/types.d.ts +36 -0
  45. package/package.json +1 -1
@@ -33,7 +33,9 @@ import { normalizeOnDemandParamKey } from "../../../pull/util.js";
33
33
  import { PROVIDER_FIXED_SYSTEM_FIELD_KEYS, recordFieldWireRefName } from "./system-ref-name.js";
34
34
  import { taskTfLabel } from "./task-label.js";
35
35
  import { slackMessageTriggerReferenceName, slackMessageTriggerRefName } from "./slack-message-refs.js";
36
+ import { approvalTriggerReferenceName, approvalTriggerRefsKey } from "./approval-trigger-refs.js";
36
37
  import { automationRunTargetResourceAttr, automationTargetOwner, bareStaticRunTarget, onDemandRecordParamNames, recordInputMappingProblem } from "./run-target.js";
38
+ import { automationLookupOwnerId } from "./lookup-owner.js";
37
39
  import { FIELD_TYPE_MAP, isOnDemandRecordType } from "../shared/types/field-types.js";
38
40
  /** The context for reading records of `appRefName` (a `kind`), retargeted from the owner. */
39
41
  /**
@@ -841,6 +843,32 @@ function automationTargetToTf(value, ctx, dataBlocks) {
841
843
  : sibling !== undefined && sibling.kind !== "table"
842
844
  ? sibling.tfLabel
843
845
  : undefined;
846
+ const ownAutomations = isOwn ? ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, ctx.appRefName))?.automationRefNames : undefined;
847
+ if (ownAutomations !== undefined && !ownAutomations.has(value.refName) && typeof value.name === "string" && value.name !== "") {
848
+ // An automation of this owner that is not in source (pull leaves it
849
+ // platform-managed, #3047): a reference to its resources would be
850
+ // undeclared, so read its id and published parameter ids through a
851
+ // lookup by display name, the lookup a widget or dynamic-layout button
852
+ // uses (#1901, #2693). It names no publish, so nothing waits on one, and
853
+ // it reads the owner by namespace, so an app change doesn't defer it.
854
+ const label = `${ctx.appTfLabel}_${tsLabelToTfLabel(value.refName)}`;
855
+ const ownerId = automationLookupOwnerId(ctx.parentScope, ctx.appTfLabel, ctx.orgRefs, dataBlocks);
856
+ if (ctx.orgRefs !== undefined) {
857
+ ctx.orgRefs.rawLookup(AUTOMATION_RESOURCE_TYPE, label, value.name, { app_id: ownerId });
858
+ }
859
+ else {
860
+ dataBlocks.set(`${AUTOMATION_RESOURCE_TYPE}.${label}`, {
861
+ kind: "data",
862
+ type: AUTOMATION_RESOURCE_TYPE,
863
+ label,
864
+ attrs: { app_id: ownerId, name: value.name },
865
+ });
866
+ }
867
+ return {
868
+ id: expr.dataAttr(AUTOMATION_RESOURCE_TYPE, label, ["id"]),
869
+ parameterId: (name) => expr.dataAttr(AUTOMATION_RESOURCE_TYPE, label, ["parameter_ids", { index: name }]),
870
+ };
871
+ }
844
872
  if (managedOwnerLabel !== undefined) {
845
873
  const targetOwner = ctx.workspaceAspects?.get(workspaceAspectKey(ownerKind, isOwn ? ctx.appRefName : value.parent ?? ""));
846
874
  const managedHandle = ownerKind === "element"
@@ -1706,7 +1734,9 @@ function foreignFoundRecordFieldId(fieldKey, taskRefKey, refs) {
1706
1734
  return expr.dataAttr("elementum_field", registerForeignFieldLookup(fieldToken, refs.owner, refs.dataBlocks), ["id"]);
1707
1735
  }
1708
1736
  function calculationTriggerMustache(name, refs) {
1709
- const triggerName = onDemandTriggerRefName(name, refs) ?? slackTriggerReferenceName(name, refs);
1737
+ const triggerName = onDemandTriggerRefName(name, refs) ??
1738
+ slackTriggerReferenceName(name, refs) ??
1739
+ approvalTriggerReferenceNameOn(name, refs);
1710
1740
  if (triggerName !== undefined)
1711
1741
  return [`{{trigger name="${triggerName}"}}`];
1712
1742
  const parts = name.split(".");
@@ -2051,6 +2081,13 @@ function findRelatedRecordsAppTitleWireKey(name, taskRefKey, refs) {
2051
2081
  return names?.get("id") ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.id;
2052
2082
  }
2053
2083
  function taskWireRefName(name, taskRefKey, refs) {
2084
+ // A Run Automation task's refs are keyed by the called automation's published
2085
+ // output names, exactly as written (#3026). None of the record/trigger
2086
+ // display-name rewrites below apply: an output named `status`, `id`, `title`
2087
+ // or `record` is not a record field, and rewriting it to "Status"/"ID"/…
2088
+ // indexes a key the refs map does not contain (Invalid index at plan).
2089
+ if (refs.tasks.get(taskRefKey)?.type === TASK_RESOURCES.runAutomation)
2090
+ return name;
2054
2091
  assertFindRelatedRecordsHasNoCountRef(refs.tasks.get(taskRefKey)?.type, name, taskRefKey);
2055
2092
  const handleKey = findRelatedRecordsAppTitleWireKey(name, taskRefKey, refs);
2056
2093
  if (handleKey !== undefined)
@@ -2141,6 +2178,20 @@ function slackTriggerRefName(name, refs) {
2141
2178
  function slackTriggerReferenceName(name, refs) {
2142
2179
  return refs.trigger.type === TRIGGER_RESOURCES.slackMessage ? slackMessageTriggerReferenceName(name) : undefined;
2143
2180
  }
2181
+ /**
2182
+ * An approval process status trigger's refs-map key (#2990); undefined on any
2183
+ * other trigger or for a record reference. A field of the app that shares the
2184
+ * key's display name moves the output to its group-qualified key.
2185
+ */
2186
+ function approvalTriggerRefName(name, refs) {
2187
+ return refs.trigger.type === TRIGGER_RESOURCES.approvalChain
2188
+ ? approvalTriggerRefsKey(name, refs.owner.fieldNames.values())
2189
+ : undefined;
2190
+ }
2191
+ /** An approval process status trigger's `triggerReference.name`; undefined on any other trigger. */
2192
+ function approvalTriggerReferenceNameOn(name, refs) {
2193
+ return refs.trigger.type === TRIGGER_RESOURCES.approvalChain ? approvalTriggerReferenceName(name) : undefined;
2194
+ }
2144
2195
  function triggerWireRefName(name, refs) {
2145
2196
  const onDemandName = onDemandTriggerRefName(name, refs);
2146
2197
  if (onDemandName !== undefined)
@@ -2148,6 +2199,9 @@ function triggerWireRefName(name, refs) {
2148
2199
  const slackName = slackTriggerRefName(name, refs);
2149
2200
  if (slackName !== undefined)
2150
2201
  return slackName;
2202
+ const approvalName = approvalTriggerRefName(name, refs);
2203
+ if (approvalName !== undefined)
2204
+ return approvalName;
2151
2205
  const scalarParams = refs.triggerParamNames.filter((param) => !refs.recordParamNames.includes(param));
2152
2206
  const declared = onDemandTriggerRefKey(name, scalarParams);
2153
2207
  if (declared !== name || scalarParams.includes(name))
@@ -2458,6 +2512,7 @@ function workflowPublishOutputEnvelope(value, refs) {
2458
2512
  triggerReference: {
2459
2513
  name: onDemandTriggerRefName(value.triggerReference.name, refs) ??
2460
2514
  slackTriggerReferenceName(value.triggerReference.name, refs) ??
2515
+ approvalTriggerReferenceNameOn(value.triggerReference.name, refs) ??
2461
2516
  wireRefName(value.triggerReference.name, refs.owner),
2462
2517
  },
2463
2518
  variableReference: null,
@@ -3138,6 +3193,20 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3138
3193
  (value.name === "recordId" || value.name === "record")) {
3139
3194
  return "trigger.recordId";
3140
3195
  }
3196
+ // An approval process status trigger's own outputs (#2990): a filter
3197
+ // reads them by the platform's short form, `trigger.approver.id`, as
3198
+ // the editor saves and export prints it (edk#1569). The bare approver
3199
+ // would walk to the whole user, so a filter names the field it compares.
3200
+ if (refs.trigger.type === TRIGGER_RESOURCES.approvalChain) {
3201
+ const referenceName = approvalTriggerReferenceName(value.name);
3202
+ if (referenceName !== undefined) {
3203
+ if (value.name === "approver") {
3204
+ throw new EntityTfError("filter on ctx.trigger.approver: compare a field of the approver, " +
3205
+ "ctx.trigger.approver.id, .email or .name");
3206
+ }
3207
+ return `trigger.${referenceName}`;
3208
+ }
3209
+ }
3141
3210
  const triggerRefKey = triggerWireRefName(value.name, refs);
3142
3211
  if (refs.trigger.type === TRIGGER_RESOURCES.onDemand) {
3143
3212
  // filter_refs holds only declared inputs, so the user who ran the
@@ -3152,7 +3221,7 @@ function filterReferenceToTf(value, refs, role = "value", realType, operator) {
3152
3221
  // object, so a filter must name the field it compares.
3153
3222
  if (value.name === "triggeredBy") {
3154
3223
  throw new EntityTfError("filter on ctx.trigger.triggeredBy: compare a field of the user who ran the automation, " +
3155
- "ctx.trigger.triggeredBy.id, .email or .name");
3224
+ "ctx.trigger.triggeredBy.id, .email or .name (filter.groupsOf takes ctx.trigger.triggeredBy.id)");
3156
3225
  }
3157
3226
  return `trigger.${value.name}`;
3158
3227
  }
@@ -3740,9 +3809,101 @@ function booleanTaskOutputRealType(reference, refs, authored) {
3740
3809
  const declared = declaredTaskOutputType(task, wireName, envelopeName);
3741
3810
  return declared?.fieldType === "BOOLEAN" && declared.multiple !== true ? "BOOLEAN" : undefined;
3742
3811
  }
3743
- function filterToTf(value, refs) {
3812
+ /**
3813
+ * What a record field holds when a filter reference reads it, for any record
3814
+ * `recordFieldSource` can place: the trigger record, an on-demand record
3815
+ * input, a found record or a record loop item, of this app or another
3816
+ * (edk#3039). A user field is the whole user unless the path ends in `.id`
3817
+ * (mobius normalizeUsers); every other known field is not a user's id.
3818
+ */
3819
+ function recordFieldDeclaredType(reference, refs) {
3820
+ const kind = reference.type?.toString().toUpperCase();
3821
+ const valueReference = kind === "TASK" ? { taskReference: { taskRefKey: reference.taskRefKey, name: reference.name } }
3822
+ : kind === "TRIGGER" ? { triggerReference: { name: reference.name } }
3823
+ : kind === "FOR_EACH" ? { forEachReference: { forEachTaskRefKey: reference.forEachTaskRefKey, name: reference.name } }
3824
+ : undefined;
3825
+ const source = valueReference === undefined ? undefined : recordFieldSource(valueReference, refs);
3826
+ if (source === undefined)
3827
+ return undefined;
3828
+ const address = source.addresses?.get(source.fieldKey);
3829
+ const resourceType = address === undefined ? undefined : address.slice(0, address.indexOf("."));
3830
+ const catalogTypes = source.addresses === undefined && source.ownerRefName !== undefined
3831
+ ? fieldNamesForAppRefName(refs.owner.catalogFieldTypesByAppRefName, source.ownerRefName)
3832
+ : undefined;
3833
+ const catalogType = catalogTypes?.get(source.fieldKey);
3834
+ const ownerKnown = source.addresses !== undefined || catalogTypes !== undefined;
3835
+ // Only a key the owner has is classified. Any other key (pull keeps a deleted
3836
+ // field's raw id, edk#3039 round 6) stays unchecked, as filter.uuid does.
3837
+ const systemField = ownerKnown && SYSTEM_FIELD_KEY_SET.has(source.fieldKey);
3838
+ const isUser = resourceType !== undefined ? resourceType === "elementum_user_field"
3839
+ : catalogType !== undefined ? catalogType === "USER" || catalogType === "USER_ID"
3840
+ : systemField ? OBJECT_VALUED_SYSTEM_FIELD_KINDS[source.fieldKey] === "user"
3841
+ : undefined;
3842
+ if (isUser === undefined)
3843
+ return undefined;
3844
+ const rest = source.rest.join(".");
3845
+ if (isUser)
3846
+ return { type: rest === "id" ? "USER_ID" : rest === "" ? "USER" : "TEXT" };
3847
+ // A deeper path through another field (a dynamic Dropdown's linked record,
3848
+ // `hallPassReason.createdBy.id`) reads that record, which isn't typed here.
3849
+ if (source.rest.length > 1)
3850
+ return undefined;
3851
+ const fieldType = resourceType?.replace(/^elementum_/, "").replace(/_field$/, "").toUpperCase()
3852
+ ?? catalogType
3853
+ ?? (source.fieldKey === "id" ? "RECORD_HANDLE" : "SYSTEM_FIELD");
3854
+ return { type: rest === "" ? fieldType : `${fieldType}_PART` };
3855
+ }
3856
+ /**
3857
+ * The declared type of what a filter reference holds, for `filter.groupsOf`'s
3858
+ * one-user-id check (edk#3039): the user who ran an on-demand automation, a
3859
+ * record field of any app (trigger record, on-demand record input, found
3860
+ * record or record loop item), a record loop's own item, a whole plain-list
3861
+ * loop item, a task output with a declared type, or a variable with a
3862
+ * declared type. Undefined when the type isn't known here.
3863
+ */
3864
+ function filterReferenceDeclaredType(reference, refs) {
3865
+ if (!isObject(reference) || typeof reference.name !== "string")
3866
+ return undefined;
3867
+ const kind = reference.type?.toString().toUpperCase();
3868
+ if (kind === "TRIGGER") {
3869
+ if (refs.trigger?.type === TRIGGER_RESOURCES.onDemand && ON_DEMAND_TRIGGERED_BY_REFS[reference.name] !== undefined) {
3870
+ return { type: reference.name === "triggeredBy" || reference.name === "triggeredBy.id" ? "USER_ID" : "TEXT" };
3871
+ }
3872
+ return recordFieldDeclaredType(reference, refs);
3873
+ }
3874
+ if (kind === "TASK" && typeof reference.taskRefKey === "string") {
3875
+ const task = refs.tasks.get(reference.taskRefKey);
3876
+ if (task === undefined)
3877
+ return undefined;
3878
+ if (/^records?\./.test(reference.name))
3879
+ return recordFieldDeclaredType(reference, refs);
3880
+ const wireName = taskWireRefName(reference.name, reference.taskRefKey, refs);
3881
+ const envelopeName = taskOutputReferenceName(task.type, wireName, task) ?? wireName;
3882
+ const declared = declaredTaskOutputType(task, wireName, envelopeName);
3883
+ return declared === undefined ? undefined : { type: declared.fieldType, multiple: declared.multiple };
3884
+ }
3885
+ if (kind === "FOR_EACH" && typeof reference.forEachTaskRefKey === "string") {
3886
+ if (!refs.recordItemForEachRefKeys.has(reference.forEachTaskRefKey)) {
3887
+ // A plain-list loop's whole item (a user, say) is an object, not an id.
3888
+ return reference.name === "" || reference.name === "item" ? { type: "OBJECT" } : undefined;
3889
+ }
3890
+ // The loop item itself is the record, of any app: its id, never a user's.
3891
+ const [fieldKey] = reference.name.split(".");
3892
+ if (fieldKey === undefined || fieldKey === "" || fieldKey === "item" || fieldKey === "recordId")
3893
+ return { type: "ASPECT_RECORD_ID" };
3894
+ return recordFieldDeclaredType(reference, refs);
3895
+ }
3896
+ if (kind === "VARIABLE" && typeof reference.variableId === "string") {
3897
+ const valueType = refs.variableById.get(reference.variableId)?.valueType;
3898
+ return valueType === undefined ? undefined : { type: valueType };
3899
+ }
3900
+ return undefined;
3901
+ }
3902
+ function filterToTf(value, refs, options = {}) {
3744
3903
  return serializeFilterToTf(value, {
3745
3904
  ...(refs.allowUnknownPicklistOptions === true && { keepUnresolvedOptions: true }),
3905
+ ...(options.allowGroupsOf === true && { allowGroupsOf: true }),
3906
+ referenceDeclaredType: (reference) => filterReferenceDeclaredType(reference, refs),
3746
3907
  field: (field) => valueToTf(field, refs),
3747
3908
  // `userRef(email)` compares as the user's id, through the same user lookup a task value uses (#2891).
3748
3909
  user: (email) => valueToTf({ __kind: "user", email }, refs),
@@ -4042,7 +4203,8 @@ function configAttrs(kind, config, refs) {
4042
4203
  throw new EntityTfError("runAutomation targetAutomationId has an unresolved automation");
4043
4204
  }
4044
4205
  if (key === "filter") {
4045
- attrs.filter = filterToTf(raw, refs);
4206
+ // Only a record search expands filter.groupsOf (ultron), edk#3039.
4207
+ attrs.filter = filterToTf(raw, refs, { allowGroupsOf: kind === TASK_RESOURCES.recordSearch });
4046
4208
  continue;
4047
4209
  }
4048
4210
  if (key === "categorySource" && kind === "elementum_ai_classify_task") {
@@ -4643,7 +4805,10 @@ export function automationToTf(entity, ctx) {
4643
4805
  if (wireType === "variable" && Array.isArray(taskBody.create)) {
4644
4806
  taskBody.create.forEach((candidate, index) => {
4645
4807
  if (isObject(candidate) && typeof candidate.id === "string" && typeof candidate.name === "string") {
4646
- variableById.set(candidate.id, { type: "elementum_variable_task", label: registeredLabel, name: candidate.name, index });
4808
+ variableById.set(candidate.id, {
4809
+ type: "elementum_variable_task", label: registeredLabel, name: candidate.name, index,
4810
+ ...(typeof candidate.type === "string" ? { valueType: candidate.type } : {}),
4811
+ });
4647
4812
  }
4648
4813
  });
4649
4814
  }
@@ -11,6 +11,7 @@
11
11
  import type { ApprovalChainRef, AppOrElementRef, DatamineRef, FieldRef } from "../../catalog/index.js";
12
12
  import type { UnsafePlatformId } from "../../core/platform-id.js";
13
13
  import type { RecordShape } from "../field/record-shape.js";
14
+ import type { CalculationTypedValue } from "../shared/ref.js";
14
15
  import { type InferTriggerType, type WithOnDemandTriggeredBy, type TriggerInputFieldDef, type TriggerInputSchema } from "../../core/triggers/on-demand.js";
15
16
  import type { OnDemandParamTypeAlias } from "../shared/types/field-types.js";
16
17
  import type { Filter } from "./filter.js";
@@ -153,8 +154,53 @@ export interface approvalProcessStatusUpdatedTriggerOptions<A extends AppOrEleme
153
154
  */
154
155
  readonly filter?: Filter | null;
155
156
  }
157
+ /**
158
+ * The user the platform records as having moved the approval process to the
159
+ * trigger's status (the web app's "Final Approval By"): the approver when a
160
+ * person decided, or the user who cancelled. When an approval process expires
161
+ * on its deadline nobody decided, so it doesn't name a decider. The bare
162
+ * `ctx.trigger.approver` reads the id.
163
+ */
164
+ export interface ApprovalProcessStatusUpdatedApprover {
165
+ readonly id: CalculationTypedValue<string, "user">;
166
+ readonly email: string;
167
+ readonly name: string;
168
+ }
169
+ /**
170
+ * What an approval process status trigger gives its steps (#2990): the
171
+ * record, plus who moved the approval process to the status, when, and the
172
+ * status and reason.
173
+ *
174
+ * An approval process with a deadline can expire with nobody acting. It then
175
+ * reports `"APPROVED"` or `"DENIED"` (by its expiration outcome), the same
176
+ * statuses a person's decision gives, but nobody decided, so `approver` is not
177
+ * a person who approved. Only `reason` tells the two apart: on expiry it is
178
+ * "Approval expired due to SLA breach". An expiry that cancels reports the
179
+ * same `"CANCELLED"` as a person cancelling.
180
+ */
181
+ export interface ApprovalProcessStatusUpdatedTriggerOutput<A extends AppOrElementRef = AppOrElementRef> {
182
+ readonly record: RecordShape<A>;
183
+ /** Who the platform records as moving the approval process to this status (the web app's "Final Approval By"); see the expiry note above. */
184
+ readonly approver: ApprovalProcessStatusUpdatedApprover;
185
+ /** When the approval process reached this status (date and time; the web app's "Final Approval At"). */
186
+ readonly approvalUpdatedAt: CalculationTypedValue<string, "datetime">;
187
+ /**
188
+ * The approval process's status, such as `"APPROVED"`. On a
189
+ * `"STEP_APPROVED"` trigger it is that step's own status (`"APPROVED"`),
190
+ * never `"STEP_APPROVED"`, and `approver` and `reason` are that step's
191
+ * decider and comment.
192
+ */
193
+ readonly status: approvalProcessStatusUpdatedStatus;
194
+ /**
195
+ * The approval process's reason: the comment given with a person's
196
+ * decision, the platform's message when it is cancelled, "Approval expired
197
+ * due to SLA breach" on expiry, or the reason an automation passed when it
198
+ * set the status.
199
+ */
200
+ readonly reason: string;
201
+ }
156
202
  /** Fires when an approval chain on a record changes to the configured status. */
157
- export declare function approvalProcessStatusUpdated<A extends AppOrElementRef>(opts: approvalProcessStatusUpdatedTriggerOptions<A>): TriggerChain<RecordTriggerOutput<A>>;
203
+ export declare function approvalProcessStatusUpdated<A extends AppOrElementRef>(opts: approvalProcessStatusUpdatedTriggerOptions<A>): TriggerChain<ApprovalProcessStatusUpdatedTriggerOutput<A>>;
158
204
  export interface AttachmentTriggerOptions<A extends AppOrElementRef = AppOrElementRef> {
159
205
  readonly app: A;
160
206
  /**
@@ -5,11 +5,16 @@ import { type Ref } from "../shared/ref.js";
5
5
  * an output, so the reference round-trips unchanged (#1725).
6
6
  *
7
7
  * The platform resolves only declared outputs, so at runtime this reads
8
- * nothing. Prefer adding the output to the script's `outputs` and reading
9
- * `ctx.actions.<script>.result.<output>`. Build rejects a plain undeclared
10
- * `result.<output>` in a filter, rejects this marker on an undeclared output in a task input, and
11
- * accepts it in filters, workflow outputs and field assignments. On an output
12
- * the script does declare, it builds the same reference as the plain read.
8
+ * nothing, and its publish check rejects the reference ("has a value
9
+ * reference that is no longer valid"): an automation that still uses it
10
+ * plans clean after pull, but any apply that republishes it fails until the
11
+ * script declares the output (#3050). Prefer adding the output to the
12
+ * script's `outputs` and reading `ctx.actions.<script>.result.<output>`.
13
+ * Build rejects a plain undeclared `result.<output>` in a filter, rejects
14
+ * this marker on an undeclared output in a task input, and accepts it in
15
+ * filters, workflow outputs and field assignments, so pulled automations
16
+ * round-trip. On an output the script does declare, it builds the same
17
+ * reference as the plain read.
13
18
  *
14
19
  * @example
15
20
  * ```ts
@@ -13,11 +13,16 @@ const UNSAFE_SCRIPT_OUTPUT_MARKER = "__edkUnsafeScriptOutput::";
13
13
  * an output, so the reference round-trips unchanged (#1725).
14
14
  *
15
15
  * The platform resolves only declared outputs, so at runtime this reads
16
- * nothing. Prefer adding the output to the script's `outputs` and reading
17
- * `ctx.actions.<script>.result.<output>`. Build rejects a plain undeclared
18
- * `result.<output>` in a filter, rejects this marker on an undeclared output in a task input, and
19
- * accepts it in filters, workflow outputs and field assignments. On an output
20
- * the script does declare, it builds the same reference as the plain read.
16
+ * nothing, and its publish check rejects the reference ("has a value
17
+ * reference that is no longer valid"): an automation that still uses it
18
+ * plans clean after pull, but any apply that republishes it fails until the
19
+ * script declares the output (#3050). Prefer adding the output to the
20
+ * script's `outputs` and reading `ctx.actions.<script>.result.<output>`.
21
+ * Build rejects a plain undeclared `result.<output>` in a filter, rejects
22
+ * this marker on an undeclared output in a task input, and accepts it in
23
+ * filters, workflow outputs and field assignments, so pulled automations
24
+ * round-trip. On an output the script does declare, it builds the same
25
+ * reference as the plain read.
21
26
  *
22
27
  * @example
23
28
  * ```ts
@@ -2,15 +2,30 @@ import type { AgentRef, AppOrElementRef, AutomationRef, FieldRef, WidgetRef } fr
2
2
  import type { UnsafePlatformId } from "../../core/platform-id.js";
3
3
  import type { AppViewFieldRef } from "../app/build.js";
4
4
  import type { Filter } from "../shared/filters/types.js";
5
- export type DynamicLayoutTypedValue = {
5
+ interface DynamicLayoutValueMap {
6
6
  readonly string: string;
7
- } | {
8
7
  readonly number: number;
9
- } | {
10
8
  readonly boolean: boolean;
11
- } | {
12
9
  readonly strings: readonly string[];
13
- };
10
+ /**
11
+ * The person viewing the record, as the layout editor's **Current User**.
12
+ * Compare a user field with it using `equals` or `notEquals`.
13
+ */
14
+ readonly currentUser: true;
15
+ /**
16
+ * The groups of the person viewing the record, as the layout editor's
17
+ * **Current User's Groups**. Compare a group field with it: `equals` and
18
+ * `in` are true when the field's group is one of the viewer's groups,
19
+ * `notEquals` and `notIn` when it is not.
20
+ */
21
+ readonly currentUserGroups: true;
22
+ }
23
+ /** A fixed comparison value or default: exactly one of `string`, `number`, `boolean`, `strings`. */
24
+ export type DynamicLayoutTypedValue = ExactlyOneVariant<Pick<DynamicLayoutValueMap, "string" | "number" | "boolean" | "strings">>;
25
+ /** The person viewing the record (the editor's **Current User**); exactly `{ currentUser: true }`. */
26
+ export type DynamicLayoutCurrentUserValue = ExactlyOneVariant<Pick<DynamicLayoutValueMap, "currentUser">>;
27
+ /** The viewer's groups (the editor's **Current User's Groups**); exactly `{ currentUserGroups: true }`. */
28
+ export type DynamicLayoutCurrentUserGroupsValue = ExactlyOneVariant<Pick<DynamicLayoutValueMap, "currentUserGroups">>;
14
29
  export type DynamicLayoutCssLength = {
15
30
  readonly px: number;
16
31
  } | {
@@ -94,6 +109,15 @@ interface DynamicLayoutComponentCommon<ComponentKey extends string = string, Con
94
109
  readonly saveGroup?: SaveGroupKey;
95
110
  readonly blockId?: string;
96
111
  }
112
+ interface DynamicLayoutActionButton {
113
+ readonly label?: string;
114
+ readonly variant?: "default" | "outline" | "ghost";
115
+ readonly icon?: string;
116
+ readonly color?: string;
117
+ readonly fullWidth?: boolean;
118
+ /** Display widget on the layout's owner that the layout editor tied to the button. */
119
+ readonly widget?: WidgetRef;
120
+ }
97
121
  /** @internal Public component variants used to keep the HCL dialect table exhaustive. */
98
122
  export interface DynamicLayoutComponentVariantMap {
99
123
  readonly container: {
@@ -156,6 +180,7 @@ export interface DynamicLayoutComponentVariantMap {
156
180
  readonly variant?: "default" | "outline" | "ghost" | "destructive";
157
181
  readonly icon?: string;
158
182
  readonly confirmMessage?: string;
183
+ readonly fieldName?: string;
159
184
  /** App or element that owns the automation, as the layout editor records it. */
160
185
  readonly automationApp?: AppOrElementRef;
161
186
  readonly color?: string;
@@ -167,15 +192,11 @@ export interface DynamicLayoutComponentVariantMap {
167
192
  /** Run-automation widget the button executes through; omit to have build derive one. */
168
193
  readonly widget?: WidgetRef;
169
194
  };
170
- readonly createButton: {
195
+ readonly createButton: DynamicLayoutActionButton & {
171
196
  readonly target: AppOrElementRef;
172
- readonly label?: string;
173
- readonly variant?: "default" | "outline" | "ghost";
174
197
  };
175
- readonly relateButton: {
176
- readonly label?: string;
177
- readonly variant?: "default" | "outline" | "ghost";
178
- readonly icon?: string;
198
+ readonly relateButton: DynamicLayoutActionButton & {
199
+ readonly target?: AppOrElementRef;
179
200
  };
180
201
  readonly updateBlock: DynamicLayoutBlockCommon & {
181
202
  readonly fields?: readonly AppViewFieldRef[];
@@ -230,21 +251,25 @@ type ExactlyOneVariant<Map extends object> = {
230
251
  };
231
252
  }[keyof Map];
232
253
  export type DynamicLayoutComponent<ComponentKey extends string = string, ConditionKey extends string = string, SaveGroupKey extends string = string> = DynamicLayoutComponentCommon<ComponentKey, ConditionKey, SaveGroupKey> & ExactlyOneVariant<DynamicLayoutComponentVariantMap>;
233
- export type DynamicLayoutComparison = {
254
+ export type DynamicLayoutComparison<Value = DynamicLayoutTypedValue> = {
234
255
  readonly field: AppViewFieldRef;
235
- readonly value: DynamicLayoutTypedValue;
256
+ readonly value: Value;
236
257
  };
258
+ /** `equals` / `notEquals`: a typed value, the viewer, or the viewer's groups. */
259
+ export type DynamicLayoutEqualityComparison = DynamicLayoutComparison<ExactlyOneVariant<Pick<DynamicLayoutValueMap, "string" | "number" | "boolean" | "strings" | "currentUser" | "currentUserGroups">>>;
260
+ /** `in` / `notIn`: a list of strings, or the viewer's groups (the provider accepts nothing else). */
261
+ export type DynamicLayoutMembershipComparison = DynamicLayoutComparison<ExactlyOneVariant<Pick<DynamicLayoutValueMap, "strings" | "currentUserGroups">>>;
237
262
  interface DynamicLayoutConditionVariantMap<ConditionKey extends string> {
238
- readonly equals: DynamicLayoutComparison;
239
- readonly notEquals: DynamicLayoutComparison;
263
+ readonly equals: DynamicLayoutEqualityComparison;
264
+ readonly notEquals: DynamicLayoutEqualityComparison;
240
265
  readonly greaterThan: DynamicLayoutComparison;
241
266
  readonly greaterThanOrEqual: DynamicLayoutComparison;
242
267
  readonly lessThan: DynamicLayoutComparison;
243
268
  readonly lessThanOrEqual: DynamicLayoutComparison;
244
269
  readonly contains: DynamicLayoutComparison;
245
270
  readonly notContains: DynamicLayoutComparison;
246
- readonly in: DynamicLayoutComparison;
247
- readonly notIn: DynamicLayoutComparison;
271
+ readonly in: DynamicLayoutMembershipComparison;
272
+ readonly notIn: DynamicLayoutMembershipComparison;
248
273
  readonly empty: {
249
274
  readonly field: AppViewFieldRef;
250
275
  };
@@ -3,6 +3,7 @@ import { dataRefLabel, optionalString, plainObject, reportAuthoringBlocker, reso
3
3
  import { isTfExpr, isUuid, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
4
4
  import { filterFromTf } from "../access-policy/from-tf.js";
5
5
  import { elementAuditFieldReference, fieldKeyFromTfValue } from "../field/from-tf.js";
6
+ import { omittedAutomationKey } from "../automation/omitted-ref.js";
6
7
  import { filterOwnerForAspect } from "../relationship/from-tf.js";
7
8
  import { filterWireToTf } from "../shared/filters/tf-codec.js";
8
9
  import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
@@ -206,11 +207,13 @@ function componentMap(values, layoutKey, owner, ctx, where) {
206
207
  const automationId = automation["automationId"];
207
208
  if (automation["automationId"] !== undefined) {
208
209
  const label = resourceRefLabel(automation["automationId"], "elementum_automation");
209
- if (label !== undefined) {
210
+ const ref = label !== undefined
210
211
  // The display name lets build look the automation up when pull
211
212
  // leaves it platform-managed, so it is not in source (edk#2693).
212
- automation["automation"] = pulledRef("automation", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName, exportedAutomationName(label, ctx));
213
- }
213
+ ? pulledRef("automation", scopedLabelToBagKey(owner.ownerTfLabel, label, "app"), owner.ownerRefName, exportedAutomationName(label, ctx))
214
+ : omittedButtonAutomation(automation["automationId"], owner, ctx);
215
+ if (ref !== undefined)
216
+ automation["automation"] = ref;
214
217
  else
215
218
  ctx.diagnostics.push(`${where}.components.${id}.automationButton: automation_id is not a managed automation ref; dropped`);
216
219
  delete automation["automationId"];
@@ -264,15 +267,8 @@ function componentMap(values, layoutKey, owner, ctx, where) {
264
267
  const related = plainUnknownObject(component["relatedItemsBlock"]);
265
268
  if (related !== undefined)
266
269
  relatedItemsBlock(related, owner, ctx, `${where}.components.${id}.relatedItemsBlock`);
267
- const create = plainUnknownObject(component["createButton"]);
268
- if (create !== undefined && create["targetAspectId"] !== undefined) {
269
- const ref = aspectRef(create["targetAspectId"], owner, ctx);
270
- if (ref !== undefined)
271
- create["target"] = ref;
272
- else
273
- ctx.diagnostics.push(`${where}.components.${id}.createButton: target_aspect_id is not resolvable; dropped`);
274
- delete create["targetAspectId"];
275
- }
270
+ buttonTarget(plainUnknownObject(component["createButton"]), owner, ctx, `${where}.components.${id}.createButton`);
271
+ buttonTarget(plainUnknownObject(component["relateButton"]), owner, ctx, `${where}.components.${id}.relateButton`);
276
272
  out[id] = component;
277
273
  }
278
274
  return out;
@@ -303,6 +299,10 @@ function managedParameter(parameter, ctx) {
303
299
  const automationLabel = automationId === undefined ? undefined : resourceRefLabel(automationId, "elementum_automation");
304
300
  return automationLabel === undefined ? undefined : { automationLabel, name };
305
301
  }
302
+ function omittedButtonAutomation(value, owner, ctx) {
303
+ const omitted = typeof value === "string" ? omittedAutomationKey(value, owner.ownerTfLabel, ctx) : undefined;
304
+ return omitted === undefined ? undefined : pulledRef("automation", omitted.key, owner.ownerRefName, omitted.name);
305
+ }
306
306
  /** Display name of an exported `elementum_automation`, when the stream has one. */
307
307
  function exportedAutomationName(label, ctx) {
308
308
  const exportedName = ctx.resourceByAddress?.(`elementum_automation.${label}`)?.attrs["name"];
@@ -331,15 +331,7 @@ function relatedItemsBlock(block, owner, ctx, where) {
331
331
  else
332
332
  ctx.diagnostics.push(`${where}: related_aspect_id is not resolvable; dropped`);
333
333
  }
334
- const widgetId = block["widgetId"];
335
- delete block["widgetId"];
336
- if (widgetId !== undefined) {
337
- const label = resourceRefLabel(widgetId, WIDGET_RESOURCE_TYPE);
338
- if (label !== undefined)
339
- block["widget"] = pulledRef("widget", scopedLabelToBagKey(owner.label, label, scopeOf(owner)), owner.ownerRefName);
340
- else
341
- ctx.diagnostics.push(`${where}: widget_id is not a managed widget ref; dropped`);
342
- }
334
+ widgetRef(block, owner, ctx, where);
343
335
  const raw = block["filter"];
344
336
  delete block["filter"];
345
337
  if (raw === undefined)
@@ -533,6 +525,30 @@ function stageIndex(value, owner) {
533
525
  }
534
526
  return undefined;
535
527
  }
528
+ function buttonTarget(button, owner, ctx, where) {
529
+ if (button === undefined)
530
+ return;
531
+ widgetRef(button, owner, ctx, where);
532
+ if (button["targetAspectId"] === undefined)
533
+ return;
534
+ const ref = aspectRef(button["targetAspectId"], owner, ctx);
535
+ if (ref !== undefined)
536
+ button["target"] = ref;
537
+ else
538
+ ctx.diagnostics.push(`${where}: target_aspect_id is not resolvable; dropped`);
539
+ delete button["targetAspectId"];
540
+ }
541
+ function widgetRef(rec, owner, ctx, where) {
542
+ const widgetId = rec["widgetId"];
543
+ delete rec["widgetId"];
544
+ if (widgetId === undefined)
545
+ return;
546
+ const label = resourceRefLabel(widgetId, WIDGET_RESOURCE_TYPE);
547
+ if (label !== undefined)
548
+ rec["widget"] = pulledRef("widget", scopedLabelToBagKey(owner.label, label, scopeOf(owner)), owner.ownerRefName);
549
+ else
550
+ ctx.diagnostics.push(`${where}: widget_id is not a managed widget ref; dropped`);
551
+ }
536
552
  function aspectRef(value, owner, ctx) {
537
553
  if (resourceRefLabel(value, owner.type) === owner.label)
538
554
  return pulledRef(scopeOf(owner), owner.ownerRefName);