@elementumai/edk 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +2 -0
  2. package/dist-sdk/src/catalog/factories.d.ts +7 -1
  3. package/dist-sdk/src/catalog/factories.js +2 -0
  4. package/dist-sdk/src/catalog/index.d.ts +2 -2
  5. package/dist-sdk/src/catalog/index.js +1 -1
  6. package/dist-sdk/src/catalog/org.js +79 -34
  7. package/dist-sdk/src/catalog/token.js +5 -0
  8. package/dist-sdk/src/catalog/types.d.ts +7 -1
  9. package/dist-sdk/src/catalog/types.js +3 -0
  10. package/dist-sdk/src/core/system-fields.d.ts +1 -1
  11. package/dist-sdk/src/core/system-fields.js +1 -1
  12. package/dist-sdk/src/core/types/app.d.ts +6 -0
  13. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  14. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  15. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  16. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  17. package/dist-sdk/src/engine/pull/context.d.ts +10 -0
  18. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  19. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  20. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  21. package/dist-sdk/src/engine/pull/org.js +2 -0
  22. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  23. package/dist-sdk/src/engine/pull/partition.js +43 -0
  24. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  25. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  26. package/dist-sdk/src/engine/pull/ref-only.d.ts +4 -0
  27. package/dist-sdk/src/engine/pull/ref-only.js +7 -1
  28. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  29. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  30. package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
  31. package/dist-sdk/src/engine/pull/stream-root.js +563 -0
  32. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  33. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  35. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +7 -0
  36. package/dist-sdk/src/entities/access-policy/from-tf.js +18 -3
  37. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  38. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  39. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  40. package/dist-sdk/src/entities/agent/build.js +34 -0
  41. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
  42. package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
  43. package/dist-sdk/src/entities/agent/from-tf.js +262 -2
  44. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  45. package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
  46. package/dist-sdk/src/entities/agent/to-tf.js +158 -14
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  50. package/dist-sdk/src/entities/app/build.d.ts +33 -13
  51. package/dist-sdk/src/entities/app/build.js +14 -12
  52. package/dist-sdk/src/entities/app/from-tf.js +24 -9
  53. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/index.js +1 -0
  55. package/dist-sdk/src/entities/app/module.js +1 -0
  56. package/dist-sdk/src/entities/app/stage-keys.d.ts +2 -2
  57. package/dist-sdk/src/entities/app/stage-keys.js +3 -3
  58. package/dist-sdk/src/entities/app/to-tf.js +1 -0
  59. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  60. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  61. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  62. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  63. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  64. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  65. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  66. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  67. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  68. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  69. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  70. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  71. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  72. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  73. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  74. package/dist-sdk/src/entities/automation/build.js +70 -27
  75. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +20 -5
  76. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -5
  77. package/dist-sdk/src/entities/automation/from-tf.js +593 -101
  78. package/dist-sdk/src/entities/automation/index.d.ts +1 -0
  79. package/dist-sdk/src/entities/automation/index.js +1 -0
  80. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  81. package/dist-sdk/src/entities/automation/module.js +33 -12
  82. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  83. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  84. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  85. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  86. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +11 -0
  87. package/dist-sdk/src/entities/automation/task-output-labels.js +23 -0
  88. package/dist-sdk/src/entities/automation/tasks.d.ts +29 -4
  89. package/dist-sdk/src/entities/automation/tasks.js +34 -11
  90. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
  91. package/dist-sdk/src/entities/automation/to-tf.js +337 -77
  92. package/dist-sdk/src/entities/automation/triggers.d.ts +0 -8
  93. package/dist-sdk/src/entities/automation/triggers.js +26 -11
  94. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  95. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  96. package/dist-sdk/src/entities/chart/build.d.ts +9 -1
  97. package/dist-sdk/src/entities/chart/from-tf.js +3 -0
  98. package/dist-sdk/src/entities/chart/to-tf.js +19 -2
  99. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +2 -0
  100. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +44 -5
  101. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  102. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  103. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  104. package/dist-sdk/src/entities/element/build.js +2 -1
  105. package/dist-sdk/src/entities/element/from-tf.js +15 -2
  106. package/dist-sdk/src/entities/element/module.js +3 -0
  107. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  108. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  109. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  110. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  111. package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
  112. package/dist-sdk/src/entities/field/from-tf.js +99 -6
  113. package/dist-sdk/src/entities/field/module.js +4 -0
  114. package/dist-sdk/src/entities/field/to-tf.d.ts +5 -1
  115. package/dist-sdk/src/entities/field/to-tf.js +33 -12
  116. package/dist-sdk/src/entities/org/category.js +1 -0
  117. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  118. package/dist-sdk/src/entities/org/index.js +1 -0
  119. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  120. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  121. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  122. package/dist-sdk/src/entities/organization/build.js +2 -0
  123. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  124. package/dist-sdk/src/entities/organization/index.js +1 -0
  125. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  126. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  127. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  128. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  129. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  130. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  131. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  132. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  133. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  134. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  135. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  136. package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
  137. package/dist-sdk/src/entities/relationship/module.js +2 -2
  138. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  139. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  140. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  141. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  142. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  143. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  144. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  145. package/dist-sdk/src/entities/service-account/module.js +4 -1
  146. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  147. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  148. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  149. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  150. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  151. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  152. package/dist-sdk/src/entities/shared/filters/ast.d.ts +2 -0
  153. package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
  154. package/dist-sdk/src/entities/shared/filters/index.js +18 -6
  155. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  156. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  157. package/dist-sdk/src/entities/shared/filters/print.js +9 -5
  158. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
  159. package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
  160. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  161. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  162. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  163. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  164. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  165. package/dist-sdk/src/entities/sla/build.js +124 -0
  166. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  167. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  168. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  169. package/dist-sdk/src/entities/sla/index.js +1 -0
  170. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  171. package/dist-sdk/src/entities/sla/module.js +73 -0
  172. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  173. package/dist-sdk/src/entities/sla/printer.js +84 -0
  174. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  175. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  176. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  177. package/dist-sdk/src/entities/table/build.js +22 -1
  178. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  179. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  180. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  181. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  182. package/dist-sdk/src/entities/task/from-tf.js +2 -1
  183. package/dist-sdk/src/entities/view/from-tf.js +7 -4
  184. package/dist-sdk/src/entities/widget/from-tf.js +13 -2
  185. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +49 -4
  186. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  187. package/dist-sdk/src/graph/index.d.ts +5 -0
  188. package/dist-sdk/src/graph/index.js +7 -0
  189. package/dist-sdk/src/graph/modules.js +11 -1
  190. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  191. package/dist-sdk/src/graph/resource-types.js +62 -0
  192. package/dist-sdk/src/graph/types.d.ts +78 -6
  193. package/package.json +6 -3
@@ -30,6 +30,7 @@ import type { AppRole, RoleUserRef } from "../role/build.js";
30
30
  import type { GroupRef } from "../../catalog/index.js";
31
31
  import type { AppServiceAccount } from "../service-account/build.js";
32
32
  import type { Filter } from "../shared/filters/types.js";
33
+ import type { FilterFieldToken } from "../shared/filters/index.js";
33
34
  import { type DisplayBlock } from "./display-blocks.js";
34
35
  import type { CalculationInclude, Expr, ExprContext, ExprType } from "../field/calc.js";
35
36
  import { type UnsafePlatformId } from "../../core/platform-id.js";
@@ -116,6 +117,17 @@ export interface AppField {
116
117
  * field even when its display name is changed.
117
118
  */
118
119
  readonly tags?: readonly string[];
120
+ /**
121
+ * Natural bag key when this field was re-keyed off a reserved system key
122
+ * (#1871). Build uses it as the terraform child part so the live address
123
+ * does not move. When renaming an already-applied field (for example
124
+ * `closedAt` → `closedAtCustom`), set this to the original key
125
+ * (`resourceKey: "closedAt"`). A brand-new field needs no `resourceKey`.
126
+ * A bag key that already was `closedAtCustom` because the label was
127
+ * `closed_at_custom` must not set it. Pull stamps this automatically
128
+ * when it re-keys.
129
+ */
130
+ readonly resourceKey?: string;
119
131
  /**
120
132
  * Legacy selection values (`PICKLIST` / `MULTI_PICKLIST`). New authoring
121
133
  * should use `config.static.values` on `dropdownField`/`multiSelectField`;
@@ -341,7 +353,7 @@ export interface AppListView extends ManagedViewSharing {
341
353
  * row filters, and field tokens are resolved to deployed field IDs during
342
354
  * Terraform generation. Pulled provider-native filters also round-trip.
343
355
  */
344
- readonly filter?: Filter;
356
+ readonly filter?: Filter<FilterFieldToken, unknown>;
345
357
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
346
358
  readonly sort?: ManagedViewSort;
347
359
  }
@@ -351,7 +363,7 @@ export interface AppAgentView extends ManagedViewSharing {
351
363
  readonly agent: AgentRef;
352
364
  readonly allowRecordCreation?: boolean;
353
365
  /** Provider-native filter object; pulled values round-trip verbatim. */
354
- readonly filter?: Filter;
366
+ readonly filter?: Filter<FilterFieldToken, unknown>;
355
367
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
356
368
  readonly sort?: ManagedViewSort;
357
369
  readonly displayOrder?: number;
@@ -373,7 +385,7 @@ export interface AppCustomView extends ManagedViewSharing {
373
385
  readonly agent?: AgentRef;
374
386
  readonly allowRecordCreation?: boolean;
375
387
  /** Provider-native filter object; pulled values round-trip verbatim. */
376
- readonly filter?: Filter;
388
+ readonly filter?: Filter<FilterFieldToken, unknown>;
377
389
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
378
390
  readonly sort?: ManagedViewSort;
379
391
  readonly displayOrder?: number;
@@ -393,7 +405,7 @@ export interface AppCalendarView extends ManagedViewSharing {
393
405
  readonly displayByField?: AppViewFieldRef;
394
406
  readonly allowRecordCreation?: boolean;
395
407
  /** Provider-native filter object; pulled values round-trip verbatim. */
396
- readonly filter?: Filter;
408
+ readonly filter?: Filter<FilterFieldToken, unknown>;
397
409
  /** Ordered, typed field sorts using the platform's managed-view Sort contract. */
398
410
  readonly sort?: ManagedViewSort;
399
411
  }
@@ -416,7 +428,7 @@ export interface AppDashboardView extends ManagedViewSharing {
416
428
  /** Stable key from the sibling `dashboards` bag. */
417
429
  readonly dashboard: DashboardRef;
418
430
  readonly allowRecordCreation?: boolean;
419
- readonly filter?: Filter;
431
+ readonly filter?: Filter<FilterFieldToken, unknown>;
420
432
  readonly sort?: ManagedViewSort;
421
433
  }
422
434
  /** One group in the immutable new-record form (`elementum_record_create_form`). */
@@ -509,8 +521,10 @@ interface AppV2OptionsBase<F extends Record<string, AppField> = Record<string, A
509
521
  /**
510
522
  * Overrides for the platform's auto-provisioned system fields (ID, Title,
511
523
  * Status, Stage, and the audit fields). Omit entirely when the app keeps
512
- * every deploy default. The canonical keys are reserved — a custom field
513
- * under `fields:` may not reuse them.
524
+ * every deploy default. System-field keys are reserved: a custom field
525
+ * under `fields:` may not use them (#1871). Pull re-keys a colliding
526
+ * custom field to `<key>Custom` and keeps its terraform address on the
527
+ * natural key.
514
528
  */
515
529
  readonly systemFields?: AppSystemFields;
516
530
  /**
@@ -589,13 +603,15 @@ interface AppV2OptionsBase<F extends Record<string, AppField> = Record<string, A
589
603
  */
590
604
  export declare function serializeField(field: AppField, refName?: string, owner?: string): AspectFieldInput;
591
605
  /**
592
- * Reject a custom `fields:` bag key that is ALSO authored under
593
- * `systemFields` — the same slot provisioned twice. Keys not present in
594
- * systemFields stay legal as ordinary fields (existing workspaces key
595
- * plain fields `title` etc.); full reservation of the canonical keys is
596
- * deferred until system-field ref tokens land on `ref().fields`.
606
+ * Reject a custom `fields:` bag key that matches a reserved system-field key
607
+ * (`closedAt`, `title`, `status`, …). Authors rename the custom field (for
608
+ * example to `closedAtCustom`) and, when the field is already applied, set
609
+ * `resourceKey` to the original key (`resourceKey: "closedAt"`) so the
610
+ * terraform address stays put. A brand-new field needs no `resourceKey`.
611
+ * Pull re-keys a colliding custom field the same way and stamps
612
+ * `resourceKey` automatically (#1871 / Q1 A).
597
613
  */
598
- export declare function assertNoSystemKeyCollision(builder: string, name: string, fields: Record<string, AppField>, systemFields: AppSystemFields | undefined): void;
614
+ export declare function assertNoSystemKeyCollision(builder: string, name: string, fields: Record<string, AppField>, reservedKeys?: ReadonlySet<string>): void;
599
615
  /**
600
616
  * Serialize the AUTHORED system-field overrides into tagged compose entries
601
617
  * (the same wire shape a system field carries on pull). Only authored keys
@@ -658,6 +674,10 @@ export type SystemFieldRefs<Parent extends string = string> = {
658
674
  * fields round out the bag via {@link SystemFieldRefs} — a finite union of
659
675
  * literal keys, deliberately NOT a wide `Record<string, FieldRef>`.
660
676
  *
677
+ * Custom `fields:` keys may not collide with {@link SystemFieldKey} (#1871);
678
+ * {@link assertNoSystemKeyCollision} rejects them at build, and pull re-keys
679
+ * a colliding custom field to `<key>Custom`. The intersection stays exact.
680
+ *
661
681
  * That distinction is load-bearing, not style: a wide `string`-keyed index
662
682
  * signature anywhere in this intersection poisons `RecordShape`
663
683
  * (`entities/field/record-shape.ts`) when `DeepRef`
@@ -1,5 +1,5 @@
1
1
  import { slimTokens, viewType } from "../../catalog/index.js";
2
- import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_REQUIRED, SYSTEM_FIELD_TAG_BY_KEY, WRITABLE_SYSTEM_TAG_NAMES, } from "../../core/system-fields.js";
2
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_KEY_SET, SYSTEM_FIELD_REQUIRED, SYSTEM_FIELD_TAG_BY_KEY, WRITABLE_SYSTEM_TAG_NAMES, } from "../../core/system-fields.js";
3
3
  import { serializeDisplayBlocks } from "./display-blocks.js";
4
4
  import { assertCalculatedFieldRoot } from "../field/calc/runtime.js";
5
5
  import { assertAttachmentMediaTypes } from "../field/media-types.js";
@@ -269,6 +269,7 @@ export function serializeField(field, refName, owner) {
269
269
  // the existing id for an update; create lets the server assign one.
270
270
  name: field.name,
271
271
  ...(refName !== undefined ? { __refName: refName } : {}),
272
+ ...(field.resourceKey !== undefined ? { __resourceKey: field.resourceKey } : {}),
272
273
  ...(field.columnName !== undefined ? { columnName: field.columnName } : {}),
273
274
  ...(field.required !== undefined ? { required: field.required } : {}),
274
275
  ...(field.requiredOnClose !== undefined ? { requiredOnClose: field.requiredOnClose } : {}),
@@ -344,18 +345,18 @@ export function serializeField(field, refName, owner) {
344
345
  return { [key]: base };
345
346
  }
346
347
  /**
347
- * Reject a custom `fields:` bag key that is ALSO authored under
348
- * `systemFields` — the same slot provisioned twice. Keys not present in
349
- * systemFields stay legal as ordinary fields (existing workspaces key
350
- * plain fields `title` etc.); full reservation of the canonical keys is
351
- * deferred until system-field ref tokens land on `ref().fields`.
348
+ * Reject a custom `fields:` bag key that matches a reserved system-field key
349
+ * (`closedAt`, `title`, `status`, …). Authors rename the custom field (for
350
+ * example to `closedAtCustom`) and, when the field is already applied, set
351
+ * `resourceKey` to the original key (`resourceKey: "closedAt"`) so the
352
+ * terraform address stays put. A brand-new field needs no `resourceKey`.
353
+ * Pull re-keys a colliding custom field the same way and stamps
354
+ * `resourceKey` automatically (#1871 / Q1 A).
352
355
  */
353
- export function assertNoSystemKeyCollision(builder, name, fields, systemFields) {
354
- if (systemFields === undefined)
355
- return;
356
+ export function assertNoSystemKeyCollision(builder, name, fields, reservedKeys = SYSTEM_FIELD_KEY_SET) {
356
357
  for (const key of Object.keys(fields)) {
357
- if (systemFields[key] !== undefined) {
358
- throw new Error(`${builder} "${name}": fields.${key} collides with the authored systemFields.${key} override — one slot, one author.`);
358
+ if (reservedKeys.has(key)) {
359
+ throw new Error(`${builder} "${name}": fields.${key} uses a reserved system-field key — rename the custom field (for example to ${key}Custom). If the field is already applied, also set resourceKey: "${key}" so the terraform address stays on the live field; a brand-new field needs no resourceKey.`);
359
360
  }
360
361
  }
361
362
  }
@@ -537,6 +538,7 @@ export function app(opts) {
537
538
  ...("dynamicSource" in field && field.dynamicSource === true ? { dynamicSource: true } : {}),
538
539
  ...(field.options !== undefined ? { options: picklistOptionLabels(field.options) } : {}),
539
540
  ...(field.tags !== undefined ? { tags: field.tags } : {}),
541
+ ...(field.resourceKey !== undefined ? { resourceKey: field.resourceKey } : {}),
540
542
  };
541
543
  }
542
544
  for (const key of SYSTEM_FIELD_KEYS) {
@@ -627,7 +629,7 @@ export function app(opts) {
627
629
  return makeRef(refName);
628
630
  },
629
631
  def(refName) {
630
- assertNoSystemKeyCollision("app", opts.name, opts.fields, opts.systemFields);
632
+ assertNoSystemKeyCollision("app", opts.name, opts.fields);
631
633
  const displayBlocks = serializeDisplayBlocks(opts.displayBlocks, "LAYOUT");
632
634
  const recordCreateDisplayBlocks = serializeDisplayBlocks(opts.recordCreateDisplayBlocks, "CREATE");
633
635
  const payload = {
@@ -8,10 +8,10 @@
8
8
  * import blocks and stay data-side — they never reach printed source.
9
9
  */
10
10
  import { autoShareFromTf } from "./auto-share.js";
11
- import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_KEY_BY_HCL_KEY, SYSTEM_FIELD_TAG_BY_KEY, } from "../../core/system-fields.js";
11
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, SYSTEM_FIELD_KEYS, SYSTEM_FIELD_KEY_SET, SYSTEM_FIELD_KEY_BY_HCL_KEY, SYSTEM_FIELD_TAG_BY_KEY, } from "../../core/system-fields.js";
12
12
  import { EntityTfError } from "../../engine/entity.js";
13
13
  import { dataRefLabel, optionalString, plainObject } from "../../engine/pull/context.js";
14
- import { tfLabelToTsLabel } from "../../engine/tf/index.js";
14
+ import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
15
15
  import { accessPolicyBlocksInLabelOrder, accessPolicyFromTf } from "../access-policy/from-tf.js";
16
16
  import { dynamicLayoutCompanionWidgetLabels, dynamicLayoutsFromTf, } from "../dynamic-layout/from-tf.js";
17
17
  import { dashboardsFromTf } from "../dashboard/from-tf.js";
@@ -145,11 +145,25 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
145
145
  // --- System-field attributes/config → tagged NormalizedField entries.
146
146
  const fields = [];
147
147
  const owner = { type: APP_RESOURCE_TYPE, label, scope: "app", refName };
148
- const customFields = fieldBlocks.flatMap((block) => {
149
- const entry = fieldFromTf(block, owner, ctx);
150
- return entry === undefined ? [] : [entry];
151
- });
152
- const hasCustomStatusField = customFields.some((field) => field.key === "status");
148
+ // Two-pass so a non-reserved natural key (e.g. `closedAtCustom`) claims
149
+ // before a re-keyed reserved key (`closedAt` → `closedAtCustom2`) (#1871 B1).
150
+ const usedFieldKeys = new Set();
151
+ const nonReservedBlocks = [];
152
+ const reservedBlocks = [];
153
+ for (const block of fieldBlocks) {
154
+ if (block.label === undefined) {
155
+ nonReservedBlocks.push(block);
156
+ continue;
157
+ }
158
+ const natural = scopedLabelToBagKey(label, block.label, "app");
159
+ (SYSTEM_FIELD_KEY_SET.has(natural) ? reservedBlocks : nonReservedBlocks).push(block);
160
+ }
161
+ const customFields = [];
162
+ for (const block of [...nonReservedBlocks, ...reservedBlocks]) {
163
+ const entry = fieldFromTf(block, owner, ctx, usedFieldKeys);
164
+ if (entry !== undefined)
165
+ customFields.push(entry);
166
+ }
153
167
  const systemConfig = systemFieldConfigFromTf(attrs["system_field_config"], `app "${label}"`, ctx);
154
168
  const titleName = optionalString(attrs, "title_field_name", `app "${label}"`, ctx);
155
169
  if (titleName !== undefined || titleFieldDescription !== undefined || systemConfig.has("title")) {
@@ -161,8 +175,9 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
161
175
  }
162
176
  const statusName = optionalString(attrs, "status_field_name", `app "${label}"`, ctx) ?? DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status;
163
177
  const statusOptions = optionsFromTf(attrs["status_options"], `app "${label}" status_options`, ctx);
164
- if (!hasCustomStatusField
165
- && (statusName !== DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status || statusOptions !== undefined || statusFieldDescription !== undefined || systemConfig.has("status"))) {
178
+ // Custom status-keyed fields re-key to statusCustom (#1871); the platform
179
+ // status override is independent and may also print. Round-trip proof: S1.
180
+ if (statusName !== DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES.status || statusOptions !== undefined || statusFieldDescription !== undefined || systemConfig.has("status")) {
166
181
  const flags = systemConfig.get("status");
167
182
  fields.push({
168
183
  key: "status",
@@ -17,6 +17,7 @@ export { attachmentField, booleanField, calculatedField, dateField, dateTimeFiel
17
17
  export { asc, desc, sortBy, type SortDirection, type SortOrder } from "../shared/types/common.js";
18
18
  export { calc, dateDifUnit, dateTimeTruncPrecision, field, orderByDirection, predicateOp, weekdayMode, type ConcatExprType, type DateDifUnit, type DateTimeTruncPrecision, type Expr, type ExprType, type FieldRefExprType, type OrderByDirection, type Predicate, type PredicateOp, type StringAggOptions, type StringAggOrderBy, type WeekdayMode, } from "../field/calc.js";
19
19
  export { agentEvaluation, type AgentEvaluationConfigured, type AgentEvaluationOptions, } from "../agent-evaluation/index.js";
20
+ export { sla, slaTimeUnit, slaWeekDay, type SlaConfigured, type SlaOptions, type SlaTarget, type SlaTimeUnit, type SlaWeekDay, } from "../sla/index.js";
20
21
  export { phoneService, callerAccessMode, type CallerAccessMode, type E164PhoneNumber, type PhoneServiceConfigured, type PhoneServiceNumber, type PhoneServiceOptions, type PhoneServiceRegistration, } from "../phone-service/index.js";
21
22
  export { preservePulledCalculation } from "./deserializer/pulled-expression.js";
22
23
  export { groupId, userId, type AccessPolicyGroupRef, type AccessPolicyOptions, type AccessPolicyPrincipalRef, type AccessPolicyUserRef, type GroupId, type UserId } from "../access-policy/build.js";
@@ -7,6 +7,7 @@ export { attachmentField, booleanField, calculatedField, dateField, dateTimeFiel
7
7
  export { asc, desc, sortBy } from "../shared/types/common.js";
8
8
  export { calc, dateDifUnit, dateTimeTruncPrecision, field, orderByDirection, predicateOp, weekdayMode, } from "../field/calc.js";
9
9
  export { agentEvaluation, } from "../agent-evaluation/index.js";
10
+ export { sla, slaTimeUnit, slaWeekDay, } from "../sla/index.js";
10
11
  export { phoneService, callerAccessMode, } from "../phone-service/index.js";
11
12
  export { preservePulledCalculation } from "./deserializer/pulled-expression.js";
12
13
  export { groupId, userId } from "../access-policy/build.js";
@@ -78,6 +78,7 @@ export const appModule = {
78
78
  diagnostics: ctx.diagnostics,
79
79
  workspaceAspects: ctx.workspaceAspects,
80
80
  ...(ctx.outOfScopeApps !== undefined && { outOfScopeApps: ctx.outOfScopeApps }),
81
+ ...(ctx.optionIds !== undefined && { optionIds: ctx.optionIds }),
81
82
  });
82
83
  return {
83
84
  blocks: result.blocks,
@@ -12,8 +12,8 @@ export declare function stageKeyFromPicklistValue(pv: PicklistValueWire): AppSta
12
12
  /**
13
13
  * Every tf-label handle that authored source or pull can use for a stage,
14
14
  * mapped to the stage's real `stage_ids_by_key` key (#1136). A layout bag key,
15
- * a dynamic-layout `stage`, an approval chain `stage` or a visual-flow
16
- * `stage` resolves through this map. Handles:
15
+ * a dynamic-layout `stage`, an approval chain `stage`, a visual-flow
16
+ * `stage` or an SLA clock's `stages` entry resolves through this map. Handles:
17
17
  * - the real key itself, when it is a tf label. This covers renamed stages
18
18
  * (`legacy_key` for "Renamed stage") and keys such as `foo__bar` that are
19
19
  * legal tf labels but not the slug;
@@ -14,8 +14,8 @@ export function stageKeyFromPicklistValue(pv) {
14
14
  /**
15
15
  * Every tf-label handle that authored source or pull can use for a stage,
16
16
  * mapped to the stage's real `stage_ids_by_key` key (#1136). A layout bag key,
17
- * a dynamic-layout `stage`, an approval chain `stage` or a visual-flow
18
- * `stage` resolves through this map. Handles:
17
+ * a dynamic-layout `stage`, an approval chain `stage`, a visual-flow
18
+ * `stage` or an SLA clock's `stages` entry resolves through this map. Handles:
19
19
  * - the real key itself, when it is a tf label. This covers renamed stages
20
20
  * (`legacy_key` for "Renamed stage") and keys such as `foo__bar` that are
21
21
  * legal tf labels but not the slug;
@@ -105,7 +105,7 @@ function stageHandleBindings(stages, diagnostics) {
105
105
  const lost = lostTo.get(stage.key);
106
106
  if (bound.has(stage.key) || reported.has(stage.key) || lost === undefined)
107
107
  continue;
108
- diagnostics?.push(`systemFields.stage: stage "${stage.key}" has no handle of its own: its handle "${lost.handle}" is stage "${lost.owner}"'s key. Source cannot reference "${stage.key}", so pull leaves its layouts, dynamic layouts, approval chains and flows unmanaged (each one warned) instead of binding them to "${lost.owner}". Rename one of the stages so each has its own handle.`);
108
+ diagnostics?.push(`systemFields.stage: stage "${stage.key}" has no handle of its own: its handle "${lost.handle}" is stage "${lost.owner}"'s key. Source cannot reference "${stage.key}", so pull leaves its layouts, dynamic layouts, approval chains, flows and SLA clocks unmanaged (each one warned) instead of binding them to "${lost.owner}". Rename one of the stages so each has its own handle.`);
109
109
  }
110
110
  return { byHandle, fallbackLost };
111
111
  }
@@ -345,6 +345,7 @@ export function appToTf(entity, ctx) {
345
345
  objectId,
346
346
  orgRefs: ctx.orgRefs,
347
347
  diagnostics: ctx.diagnostics,
348
+ ...(ctx.optionIds !== undefined && { optionIds: ctx.optionIds }),
348
349
  appRefName: ctx.appRefName,
349
350
  serviceAccounts: payload.serviceAccounts,
350
351
  fieldAddresses,
@@ -1,19 +1,21 @@
1
1
  import { type ApprovalProcessRef, type CatalogRef, type FieldRef } from "../../catalog/index.js";
2
2
  import { type UnsafePlatformId } from "../../core/platform-id.js";
3
3
  import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
4
+ import { type ApprovalStep } from "./steps.js";
4
5
  type AppOwner = CatalogRef<"app">;
5
- type OwnedField<App extends AppOwner> = App extends {
6
+ type ElementOwner = CatalogRef<"element">;
7
+ /** The app or element that owns an approval process (edk#373). */
8
+ type ApprovalOwner = AppOwner | ElementOwner;
9
+ type OwnedField<Owner extends ApprovalOwner> = Owner extends {
6
10
  readonly fields: infer Fields;
7
- } ? Fields extends Readonly<Record<string, FieldRef>> ? Fields[keyof Fields] : FieldRef<App["refName"]> : FieldRef<App["refName"]>;
11
+ } ? Fields extends Readonly<Record<string, FieldRef>> ? Fields[keyof Fields] : FieldRef<Owner["refName"]> : FieldRef<Owner["refName"]>;
8
12
  export interface UnsafeApprovalStageId {
9
13
  readonly __unsafe: "approvalStageId";
10
14
  readonly value: string;
11
15
  }
12
16
  /** Explicit escape hatch used only when pull cannot recover a portable stage key. */
13
17
  export declare function unsafeApprovalStageId(value: string): UnsafeApprovalStageId;
14
- interface DefineApprovalProcessBase<App extends AppOwner> extends EntityDeployOptions {
15
- /** The app that owns this approval process. */
16
- readonly app: App;
18
+ interface DefineApprovalProcessBase<Owner extends ApprovalOwner> extends EntityDeployOptions {
17
19
  readonly name: string;
18
20
  readonly numberOfDynamicApprovers: number;
19
21
  readonly managedByAutomation?: boolean;
@@ -28,19 +30,52 @@ interface DefineApprovalProcessBase<App extends AppOwner> extends EntityDeployOp
28
30
  * Pull uses `unsafePlatformId(...)` only when the platform export contains a
29
31
  * system-field UUID that cannot be reconstructed as a portable catalog ref.
30
32
  */
31
- readonly lockedFields?: readonly (OwnedField<App> | UnsafePlatformId)[];
33
+ readonly lockedFields?: readonly (OwnedField<Owner> | UnsafePlatformId)[];
34
+ /**
35
+ * Whether the process is a dynamic chain (edk#373). Only a dynamic chain
36
+ * takes `priorityGroup` steps. Chosen at create: changing it replaces the
37
+ * approval process. Omit to keep the live value.
38
+ */
39
+ readonly dynamicChain?: boolean;
40
+ /**
41
+ * The approver steps, in order (edk#373): `userStep`, `groupStep`,
42
+ * `dynamicEmployeeStep`, `resolvedQueryStep` and `priorityGroup`. Omit to
43
+ * leave the live steps unmanaged; `[]` removes every step.
44
+ */
45
+ readonly steps?: readonly ApprovalStep[];
46
+ /**
47
+ * App fields that approval preconditions may filter on (edk#2657; the web
48
+ * app's Table filter columns). Omit to leave the live columns unmanaged;
49
+ * `[]` clears them. When both `steps` and `tableFilterColumns` are set,
50
+ * every `when` filter field must appear in the list.
51
+ */
52
+ readonly tableFilterColumns?: readonly (OwnedField<Owner> | UnsafePlatformId)[];
32
53
  }
33
- export type DefineApprovalProcessOptions<App extends AppOwner = AppOwner> = DefineApprovalProcessBase<App> & ({
54
+ /** An app owns the approval process; it may sit on one of the app's stages. */
55
+ type AppOwned<Owner extends ApprovalOwner> = {
56
+ /** The app that owns this approval process. */
57
+ readonly app: Owner;
58
+ readonly element?: never;
59
+ } & ({
34
60
  readonly stage?: string;
35
61
  readonly unsafeStageId?: never;
36
62
  } | {
37
63
  readonly stage?: never;
38
64
  readonly unsafeStageId: UnsafeApprovalStageId;
39
65
  });
40
- export interface ApprovalProcessConfigured<App extends AppOwner = AppOwner> {
41
- ref<const RefName extends string>(refName: RefName): ApprovalProcessRef<App["refName"], RefName>;
66
+ /** An element owns the approval process. Elements have no stages. */
67
+ interface ElementOwned<Owner extends ApprovalOwner> {
68
+ /** The element that owns this approval process; each element record gets its own approvals. */
69
+ readonly element: Owner;
70
+ readonly app?: never;
71
+ readonly stage?: never;
72
+ readonly unsafeStageId?: never;
73
+ }
74
+ export type DefineApprovalProcessOptions<Owner extends ApprovalOwner = ApprovalOwner> = DefineApprovalProcessBase<Owner> & (Owner extends ElementOwner ? ElementOwned<Owner> : AppOwned<Owner>);
75
+ export interface ApprovalProcessConfigured<Owner extends ApprovalOwner = ApprovalOwner> {
76
+ ref<const RefName extends string>(refName: RefName): ApprovalProcessRef<Owner["refName"], RefName>;
42
77
  def(refName: string): DeployableEntity;
43
78
  }
44
- /** Define an app-owned approval process using the provider's dynamic-approver contract. */
45
- export declare function approvalProcess<App extends AppOwner>(opts: DefineApprovalProcessOptions<App>): ApprovalProcessConfigured<App>;
79
+ /** Define an approval process owned by an app or an element, using the provider's dynamic-approver contract. */
80
+ export declare function approvalProcess<Owner extends ApprovalOwner>(opts: DefineApprovalProcessOptions<Owner>): ApprovalProcessConfigured<Owner>;
46
81
  export {};
@@ -1,17 +1,18 @@
1
1
  import { EdkValidationError } from "../../../elementum-entity-client/errors.js";
2
2
  import { slimTokens, } from "../../catalog/index.js";
3
3
  import { isUnsafePlatformId } from "../../core/platform-id.js";
4
+ import { validateApprovalSteps } from "./steps.js";
4
5
  /** Explicit escape hatch used only when pull cannot recover a portable stage key. */
5
6
  export function unsafeApprovalStageId(value) {
6
7
  if (value.trim() === "")
7
8
  throw new EdkValidationError("unsafeApprovalStageId requires a non-empty platform id.");
8
9
  return { __unsafe: "approvalStageId", value };
9
10
  }
10
- /** Define an app-owned approval process using the provider's dynamic-approver contract. */
11
+ /** Define an approval process owned by an app or an element, using the provider's dynamic-approver contract. */
11
12
  export function approvalProcess(opts) {
12
- if ("steps" in opts) {
13
- throw new EdkValidationError("approvalProcess static steps are not supported; use the dynamic approver contract.");
14
- }
13
+ const owner = approvalOwner(opts);
14
+ if (opts.steps !== undefined)
15
+ validateApprovalSteps(opts.steps, opts.dynamicChain === true);
15
16
  if (opts.name.trim() === "")
16
17
  throw new EdkValidationError("approvalProcess requires a non-empty name.");
17
18
  if (!Number.isInteger(opts.numberOfDynamicApprovers) || opts.numberOfDynamicApprovers < 0) {
@@ -20,9 +21,24 @@ export function approvalProcess(opts) {
20
21
  for (const field of opts.lockedFields ?? []) {
21
22
  if (isUnsafePlatformId(field))
22
23
  continue;
23
- if (field.parent !== opts.app.refName) {
24
- throw new EdkValidationError(`approvalProcess locked field ${JSON.stringify(field.refName)} belongs to ${JSON.stringify(field.parent)}, not app ${JSON.stringify(opts.app.refName)}.`);
24
+ if (field.parent !== owner.refName) {
25
+ throw new EdkValidationError(`approvalProcess locked field ${JSON.stringify(field.refName)} belongs to ${JSON.stringify(field.parent)}, not ${owner.__kind} ${JSON.stringify(owner.refName)}.`);
26
+ }
27
+ }
28
+ const tableFilterKeys = new Set();
29
+ for (const field of opts.tableFilterColumns ?? []) {
30
+ if (isUnsafePlatformId(field)) {
31
+ tableFilterKeys.add(`id:${field.value}`);
32
+ continue;
33
+ }
34
+ if (field.parent !== owner.refName) {
35
+ throw new EdkValidationError(`approvalProcess tableFilterColumns field ${JSON.stringify(field.refName)} belongs to ${JSON.stringify(field.parent)}, not ${owner.__kind} ${JSON.stringify(owner.refName)}.`);
25
36
  }
37
+ // Parent + bag key so another app's same-named field cannot satisfy the when check (edk#2841 S1).
38
+ tableFilterKeys.add(`key:${field.parent}:${field.refName}`);
39
+ }
40
+ if (opts.tableFilterColumns !== undefined && opts.steps !== undefined) {
41
+ validateWhenFieldsInTableFilters(opts.steps, tableFilterKeys);
26
42
  }
27
43
  const payload = slimTokens({
28
44
  name: opts.name,
@@ -36,20 +52,25 @@ export function approvalProcess(opts) {
36
52
  approveButton: opts.approveButton ?? "Approve",
37
53
  ...(opts.exceptionButton !== undefined ? { exceptionButton: opts.exceptionButton } : {}),
38
54
  ...(opts.lockedFields !== undefined ? { lockedFieldIds: opts.lockedFields } : {}),
55
+ ...(opts.dynamicChain !== undefined ? { dynamicChain: opts.dynamicChain } : {}),
56
+ ...(opts.tableFilterColumns !== undefined ? { tableFilterFieldIds: opts.tableFilterColumns } : {}),
39
57
  });
58
+ // Filters stay unslimmed, as on SLA targets: the filter codec reads full field tokens.
59
+ if (opts.steps !== undefined)
60
+ payload["steps"] = opts.steps.map(wireStep);
40
61
  return {
41
62
  ref(refName) {
42
63
  return {
43
64
  __kind: "approvalChain",
44
65
  refName,
45
66
  name: opts.name,
46
- parent: opts.app.refName,
67
+ parent: owner.refName,
47
68
  };
48
69
  },
49
70
  def(refName) {
50
71
  return {
51
72
  kind: "approvalChain",
52
- parent: opts.app.refName,
73
+ parent: owner.refName,
53
74
  refName,
54
75
  payload,
55
76
  ...(opts.enabled !== undefined ? { enabled: opts.enabled } : {}),
@@ -57,3 +78,94 @@ export function approvalProcess(opts) {
57
78
  },
58
79
  };
59
80
  }
81
+ /** A step as payload wire: group tokens slimmed to their catalog identity. */
82
+ function wireStep(step) {
83
+ if (step.kind !== "priorityGroup")
84
+ return wireApprover(step);
85
+ return { ...step, conditionals: step.conditionals.map((c) => ({ ...c, approver: wireApprover(c.approver) })) };
86
+ }
87
+ function wireApprover(approver) {
88
+ if (approver.kind === "group")
89
+ return { ...approver, group: { __kind: "group", refName: approver.group.refName, name: approver.group.name } };
90
+ return approver;
91
+ }
92
+ /** The owner the options name: exactly one app or element, and no stage on an element. */
93
+ function approvalOwner(opts) {
94
+ if (opts.app !== undefined && opts.element !== undefined) {
95
+ throw new EdkValidationError("approvalProcess takes exactly one owner: app or element, not both.");
96
+ }
97
+ if (opts.element !== undefined) {
98
+ if (opts.element.__kind !== "element")
99
+ throw new EdkValidationError("approvalProcess element must be an element catalog reference.");
100
+ if (opts.stage !== undefined || opts.unsafeStageId !== undefined) {
101
+ throw new EdkValidationError("approvalProcess on an element takes no stage; elements have no stages.");
102
+ }
103
+ return opts.element;
104
+ }
105
+ if (opts.app === undefined || opts.app.__kind !== "app") {
106
+ throw new EdkValidationError("approvalProcess requires an owner: an app or an element catalog reference.");
107
+ }
108
+ return opts.app;
109
+ }
110
+ /** Every priority-group `when` field must be listed in tableFilterColumns (edk#2657 / #2841 S1). */
111
+ function validateWhenFieldsInTableFilters(steps, allowed) {
112
+ steps.forEach((step, index) => {
113
+ if (step.kind !== "priorityGroup")
114
+ return;
115
+ step.conditionals.forEach((conditional, conditionalIndex) => {
116
+ if (conditional.when === undefined)
117
+ return;
118
+ for (const field of filterFieldTokens(conditional.when)) {
119
+ const key = whenFieldKey(field, index, conditionalIndex);
120
+ if (!allowed.has(key)) {
121
+ // AppField / unsafe ids are lowered to plain id strings before this
122
+ // check (edk#2841 N-B); tell authors to use catalog field tokens so
123
+ // the key can match tableFilterColumns' parent+refName keys.
124
+ if (key.startsWith("id:")) {
125
+ throw new EdkValidationError(`approvalProcess steps[${index}] conditionals[${conditionalIndex}].when references a platform field id (${JSON.stringify(key.slice(3))}) that cannot be matched to tableFilterColumns; author the when with a catalog field token (catalog.<app>.fields.<key>).`);
126
+ }
127
+ const label = key.startsWith("key:") ? key.slice(4) : key;
128
+ throw new EdkValidationError(`approvalProcess steps[${index}] conditionals[${conditionalIndex}].when references field ${JSON.stringify(label)} which is not in tableFilterColumns.`);
129
+ }
130
+ }
131
+ });
132
+ });
133
+ }
134
+ /**
135
+ * Key a `when` left-hand field the same way tableFilterColumns is keyed: owned
136
+ * fields by parent+refName, string / unsafePlatformId by id. Public eq/filter
137
+ * helpers wire unsafePlatformId and app fields to plain id strings first.
138
+ */
139
+ function whenFieldKey(field, stepIndex, conditionalIndex) {
140
+ if (isUnsafePlatformId(field))
141
+ return `id:${field.value}`;
142
+ if (typeof field === "string" && field.trim() !== "")
143
+ return `id:${field}`;
144
+ if (typeof field === "object" && field !== null) {
145
+ const record = field;
146
+ if (typeof record.parent === "string" && typeof record.refName === "string") {
147
+ return `key:${record.parent}:${record.refName}`;
148
+ }
149
+ }
150
+ throw new EdkValidationError(`approvalProcess steps[${stepIndex}] conditionals[${conditionalIndex}].when names a field that cannot be matched to tableFilterColumns.`);
151
+ }
152
+ /** Collect field tokens named by a filter's `field`, FIELD `leftValue`, and nested children. */
153
+ function filterFieldTokens(node) {
154
+ if (node === null || typeof node !== "object")
155
+ return [];
156
+ const record = node;
157
+ const out = [];
158
+ if (record["field"] !== undefined)
159
+ out.push(record["field"]);
160
+ const left = record["leftValue"];
161
+ if (left !== null && typeof left === "object") {
162
+ const leftRecord = left;
163
+ if (leftRecord["type"] === "FIELD" && leftRecord["value"] !== undefined)
164
+ out.push(leftRecord["value"]);
165
+ }
166
+ if (Array.isArray(record["children"])) {
167
+ for (const child of record["children"])
168
+ out.push(...filterFieldTokens(child));
169
+ }
170
+ return out;
171
+ }
@@ -1,6 +1,7 @@
1
1
  import { type FromTfContext } from "../../engine/pull/context.js";
2
- import { type TfBlock } from "../../engine/tf/index.js";
2
+ import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
3
3
  import { type StageHandleIndex } from "../app/stage-keys.js";
4
+ import { type PulledApprovalStep } from "./steps-tf.js";
4
5
  export interface NormalizedApprovalChain {
5
6
  readonly refName: string;
6
7
  readonly name: string;
@@ -15,7 +16,28 @@ export interface NormalizedApprovalChain {
15
16
  readonly summary?: string;
16
17
  readonly lockedFields: readonly string[];
17
18
  readonly unsafeLockedFieldIds?: readonly string[];
19
+ /** Only true is kept; a false or absent dynamic_chain is the default. */
20
+ readonly dynamicChain?: true;
21
+ /** The approver steps (edk#373); absent when the export left them out or they cannot be authored. */
22
+ readonly steps?: readonly PulledApprovalStep[];
23
+ /**
24
+ * App fields preconditions may filter on (edk#2657). Each entry is a
25
+ * portable field key or an unresolved platform id (ARCH-H5 / #2787).
26
+ * Absent when the export left them out or a column could not be authored
27
+ * (all-or-nothing). Kept as one list so mixed refs and `unsafePlatformId`
28
+ * stay interleaved (edk#2841 S-A); column *order* is non-authoritative
29
+ * (edk#2841 S2) — the platform may reorder on write.
30
+ */
31
+ readonly tableFilterColumns?: readonly TableFilterColumnEntry[];
18
32
  }
33
+ /** One table-filter column: portable key or unresolved id (order non-authoritative). */
34
+ export type TableFilterColumnEntry = {
35
+ readonly key: string;
36
+ readonly unsafeId?: never;
37
+ } | {
38
+ readonly unsafeId: string;
39
+ readonly key?: never;
40
+ };
19
41
  /**
20
42
  * The lost-stage warning when an approval process sits on a stage with no
21
43
  * handle of its own (see `pulledStageHandle`, #1136), else undefined. Such a
@@ -23,4 +45,4 @@ export interface NormalizedApprovalChain {
23
45
  * approval task or trigger) cannot be authored either.
24
46
  */
25
47
  export declare function approvalChainLostStage(block: Pick<TfBlock, "type" | "label" | "attrs">, appTfLabel: string, stageHandles: StageHandleIndex | undefined): string | undefined;
26
- export declare function approvalChainFromTf(block: TfBlock, appTfLabel: string, ctx: FromTfContext, stageHandles?: StageHandleIndex): NormalizedApprovalChain;
48
+ export declare function approvalChainFromTf(block: TfBlock, appTfLabel: string, ctx: FromTfContext, stageHandles?: StageHandleIndex, scope?: ChildResourceScope): NormalizedApprovalChain;