@elementumai/edk 0.11.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 (222) hide show
  1. package/README.md +40 -6
  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/triggers/on-demand.d.ts +2 -0
  13. package/dist-sdk/src/core/triggers/on-demand.js +3 -0
  14. package/dist-sdk/src/core/types/app.d.ts +6 -0
  15. package/dist-sdk/src/engine/build/context.d.ts +3 -0
  16. package/dist-sdk/src/engine/coverage-gaps.d.ts +5 -0
  17. package/dist-sdk/src/engine/coverage-gaps.js +9 -0
  18. package/dist-sdk/src/engine/ei/run.d.ts +20 -1
  19. package/dist-sdk/src/engine/ei/run.js +102 -14
  20. package/dist-sdk/src/engine/pull/authored-address.js +42 -6
  21. package/dist-sdk/src/engine/pull/authored-root.d.ts +88 -0
  22. package/dist-sdk/src/engine/pull/authored-root.js +306 -0
  23. package/dist-sdk/src/engine/pull/context.d.ts +10 -0
  24. package/dist-sdk/src/engine/pull/field-refs-registry.d.ts +114 -0
  25. package/dist-sdk/src/engine/pull/field-refs-registry.js +501 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +1 -0
  27. package/dist-sdk/src/engine/pull/org.js +2 -0
  28. package/dist-sdk/src/engine/pull/partition.d.ts +8 -0
  29. package/dist-sdk/src/engine/pull/partition.js +43 -0
  30. package/dist-sdk/src/engine/pull/pulled-roots.d.ts +89 -0
  31. package/dist-sdk/src/engine/pull/pulled-roots.js +203 -0
  32. package/dist-sdk/src/engine/pull/ref-only.d.ts +22 -0
  33. package/dist-sdk/src/engine/pull/ref-only.js +59 -1
  34. package/dist-sdk/src/engine/pull/source-resources.d.ts +39 -0
  35. package/dist-sdk/src/engine/pull/source-resources.js +110 -0
  36. package/dist-sdk/src/engine/pull/stream-root.d.ts +148 -0
  37. package/dist-sdk/src/engine/pull/stream-root.js +563 -0
  38. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.d.ts +47 -0
  39. package/dist-sdk/src/engine/workspace/reserved-catalog-keys.js +115 -0
  40. package/dist-sdk/src/entities/access-policy/build.d.ts +2 -1
  41. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +9 -1
  42. package/dist-sdk/src/entities/access-policy/from-tf.js +25 -4
  43. package/dist-sdk/src/entities/access-policy/module.js +5 -0
  44. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +19 -0
  45. package/dist-sdk/src/entities/access-policy/to-tf.js +65 -8
  46. package/dist-sdk/src/entities/agent/build.d.ts +52 -1
  47. package/dist-sdk/src/entities/agent/build.js +34 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +68 -0
  49. package/dist-sdk/src/entities/agent/from-tf.d.ts +34 -1
  50. package/dist-sdk/src/entities/agent/from-tf.js +262 -2
  51. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  52. package/dist-sdk/src/entities/agent/to-tf.d.ts +8 -10
  53. package/dist-sdk/src/entities/agent/to-tf.js +158 -14
  54. package/dist-sdk/src/entities/agent-tool/from-tf.js +6 -0
  55. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  56. package/dist-sdk/src/entities/agent-tool/to-tf.js +2 -2
  57. package/dist-sdk/src/entities/app/build.d.ts +34 -14
  58. package/dist-sdk/src/entities/app/build.js +93 -16
  59. package/dist-sdk/src/entities/app/from-tf.js +25 -11
  60. package/dist-sdk/src/entities/app/index.d.ts +1 -0
  61. package/dist-sdk/src/entities/app/index.js +1 -0
  62. package/dist-sdk/src/entities/app/module.js +1 -0
  63. package/dist-sdk/src/entities/app/stage-keys.d.ts +20 -5
  64. package/dist-sdk/src/entities/app/stage-keys.js +43 -9
  65. package/dist-sdk/src/entities/app/to-tf.js +2 -0
  66. package/dist-sdk/src/entities/approval-chain/build.d.ts +46 -11
  67. package/dist-sdk/src/entities/approval-chain/build.js +120 -8
  68. package/dist-sdk/src/entities/approval-chain/from-tf.d.ts +24 -2
  69. package/dist-sdk/src/entities/approval-chain/from-tf.js +148 -6
  70. package/dist-sdk/src/entities/approval-chain/index.d.ts +4 -1
  71. package/dist-sdk/src/entities/approval-chain/index.js +4 -1
  72. package/dist-sdk/src/entities/approval-chain/module.js +23 -5
  73. package/dist-sdk/src/entities/approval-chain/printer.d.ts +1 -1
  74. package/dist-sdk/src/entities/approval-chain/printer.js +91 -5
  75. package/dist-sdk/src/entities/approval-chain/steps-tf.d.ts +77 -0
  76. package/dist-sdk/src/entities/approval-chain/steps-tf.js +255 -0
  77. package/dist-sdk/src/entities/approval-chain/steps.d.ts +71 -0
  78. package/dist-sdk/src/entities/approval-chain/steps.js +83 -0
  79. package/dist-sdk/src/entities/approval-chain/to-tf.d.ts +16 -6
  80. package/dist-sdk/src/entities/approval-chain/to-tf.js +37 -4
  81. package/dist-sdk/src/entities/automation/build.d.ts +50 -24
  82. package/dist-sdk/src/entities/automation/build.js +86 -33
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +52 -8
  84. package/dist-sdk/src/entities/automation/from-tf.d.ts +38 -6
  85. package/dist-sdk/src/entities/automation/from-tf.js +855 -157
  86. package/dist-sdk/src/entities/automation/index.d.ts +2 -1
  87. package/dist-sdk/src/entities/automation/index.js +1 -0
  88. package/dist-sdk/src/entities/automation/module.d.ts +4 -3
  89. package/dist-sdk/src/entities/automation/module.js +33 -12
  90. package/dist-sdk/src/entities/automation/refs-read.d.ts +19 -0
  91. package/dist-sdk/src/entities/automation/refs-read.js +48 -0
  92. package/dist-sdk/src/entities/automation/run-target.d.ts +2 -0
  93. package/dist-sdk/src/entities/automation/run-target.js +5 -0
  94. package/dist-sdk/src/entities/automation/script-code.d.ts +2 -1
  95. package/dist-sdk/src/entities/automation/script-code.js +82 -1
  96. package/dist-sdk/src/entities/automation/script-lint.d.ts +13 -0
  97. package/dist-sdk/src/entities/automation/script-lint.js +418 -0
  98. package/dist-sdk/src/entities/automation/slack-message-refs.d.ts +9 -0
  99. package/dist-sdk/src/entities/automation/slack-message-refs.js +75 -0
  100. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +12 -1
  101. package/dist-sdk/src/entities/automation/task-output-labels.js +32 -1
  102. package/dist-sdk/src/entities/automation/tasks.d.ts +76 -18
  103. package/dist-sdk/src/entities/automation/tasks.js +52 -15
  104. package/dist-sdk/src/entities/automation/to-tf.d.ts +3 -0
  105. package/dist-sdk/src/entities/automation/to-tf.js +585 -97
  106. package/dist-sdk/src/entities/automation/triggers.d.ts +48 -23
  107. package/dist-sdk/src/entities/automation/triggers.js +27 -12
  108. package/dist-sdk/src/entities/automation/unsafe-script-output.d.ts +50 -0
  109. package/dist-sdk/src/entities/automation/unsafe-script-output.js +92 -0
  110. package/dist-sdk/src/entities/chart/build.d.ts +18 -2
  111. package/dist-sdk/src/entities/chart/from-tf.d.ts +2 -2
  112. package/dist-sdk/src/entities/chart/from-tf.js +28 -1
  113. package/dist-sdk/src/entities/chart/index.d.ts +1 -1
  114. package/dist-sdk/src/entities/chart/printer.js +5 -2
  115. package/dist-sdk/src/entities/chart/to-tf.js +38 -3
  116. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +3 -0
  117. package/dist-sdk/src/entities/dynamic-layout/condition-keys.d.ts +48 -0
  118. package/dist-sdk/src/entities/dynamic-layout/condition-keys.js +261 -0
  119. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +45 -6
  120. package/dist-sdk/src/entities/dynamic-layout/module.js +2 -1
  121. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +46 -12
  122. package/dist-sdk/src/entities/element/audit-field-guard.d.ts +9 -0
  123. package/dist-sdk/src/entities/element/audit-field-guard.js +88 -0
  124. package/dist-sdk/src/entities/element/build.js +2 -1
  125. package/dist-sdk/src/entities/element/from-tf.js +15 -2
  126. package/dist-sdk/src/entities/element/module.js +3 -0
  127. package/dist-sdk/src/entities/element/system-fields.d.ts +13 -0
  128. package/dist-sdk/src/entities/element/system-fields.js +23 -0
  129. package/dist-sdk/src/entities/element/to-tf.js +2 -0
  130. package/dist-sdk/src/entities/field/build.d.ts +9 -0
  131. package/dist-sdk/src/entities/field/from-tf.d.ts +29 -1
  132. package/dist-sdk/src/entities/field/from-tf.js +99 -6
  133. package/dist-sdk/src/entities/field/module.js +12 -2
  134. package/dist-sdk/src/entities/field/to-tf.d.ts +13 -3
  135. package/dist-sdk/src/entities/field/to-tf.js +90 -46
  136. package/dist-sdk/src/entities/org/category.js +1 -0
  137. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  138. package/dist-sdk/src/entities/org/index.js +1 -0
  139. package/dist-sdk/src/entities/org/role.js +5 -0
  140. package/dist-sdk/src/entities/org/voice-auth.d.ts +5 -0
  141. package/dist-sdk/src/entities/org/voice-auth.js +33 -0
  142. package/dist-sdk/src/entities/organization/build.d.ts +3 -0
  143. package/dist-sdk/src/entities/organization/build.js +2 -0
  144. package/dist-sdk/src/entities/organization/index.d.ts +1 -0
  145. package/dist-sdk/src/entities/organization/index.js +1 -0
  146. package/dist-sdk/src/entities/organization/to-tf.d.ts +2 -0
  147. package/dist-sdk/src/entities/organization/to-tf.js +59 -1
  148. package/dist-sdk/src/entities/organization/voice-auth.d.ts +60 -0
  149. package/dist-sdk/src/entities/organization/voice-auth.js +60 -0
  150. package/dist-sdk/src/entities/phone-service/build.d.ts +9 -1
  151. package/dist-sdk/src/entities/phone-service/build.js +1 -0
  152. package/dist-sdk/src/entities/phone-service/deserializer/print-phone-service.js +3 -0
  153. package/dist-sdk/src/entities/phone-service/from-tf.d.ts +1 -0
  154. package/dist-sdk/src/entities/phone-service/from-tf.js +8 -1
  155. package/dist-sdk/src/entities/phone-service/to-tf.js +16 -0
  156. package/dist-sdk/src/entities/record-create-form/from-tf.js +2 -2
  157. package/dist-sdk/src/entities/relationship/from-tf.js +7 -2
  158. package/dist-sdk/src/entities/relationship/module.js +2 -2
  159. package/dist-sdk/src/entities/relationship/pair-check.d.ts +6 -2
  160. package/dist-sdk/src/entities/relationship/pair-check.js +105 -18
  161. package/dist-sdk/src/entities/relationship/to-tf.js +5 -2
  162. package/dist-sdk/src/entities/role/permission-levels.d.ts +7 -0
  163. package/dist-sdk/src/entities/role/permission-levels.js +78 -0
  164. package/dist-sdk/src/entities/role/to-tf.js +32 -2
  165. package/dist-sdk/src/entities/service-account/module.d.ts +2 -1
  166. package/dist-sdk/src/entities/service-account/module.js +9 -1
  167. package/dist-sdk/src/entities/service-account/resource-type.d.ts +2 -0
  168. package/dist-sdk/src/entities/service-account/resource-type.js +2 -0
  169. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +5 -5
  170. package/dist-sdk/src/entities/service-account/role-fidelity.js +21 -13
  171. package/dist-sdk/src/entities/service-account/role-membership-check.d.ts +20 -0
  172. package/dist-sdk/src/entities/service-account/role-membership-check.js +80 -0
  173. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +15 -0
  174. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +36 -0
  175. package/dist-sdk/src/entities/shared/filters/ast.d.ts +4 -0
  176. package/dist-sdk/src/entities/shared/filters/index.d.ts +85 -14
  177. package/dist-sdk/src/entities/shared/filters/index.js +18 -6
  178. package/dist-sdk/src/entities/shared/filters/option-lookups.d.ts +57 -0
  179. package/dist-sdk/src/entities/shared/filters/option-lookups.js +108 -0
  180. package/dist-sdk/src/entities/shared/filters/print.js +9 -5
  181. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +12 -7
  182. package/dist-sdk/src/entities/shared/filters/tf-codec.js +9 -5
  183. package/dist-sdk/src/entities/shared/raw-option-id.d.ts +30 -0
  184. package/dist-sdk/src/entities/shared/raw-option-id.js +41 -0
  185. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -2
  186. package/dist-sdk/src/entities/shared/types/field-types.d.ts +6 -3
  187. package/dist-sdk/src/entities/shared/types/field-types.js +3 -1
  188. package/dist-sdk/src/entities/skill/input-coverage.js +5 -2
  189. package/dist-sdk/src/entities/skill/module.js +2 -0
  190. package/dist-sdk/src/entities/sla/build.d.ts +96 -0
  191. package/dist-sdk/src/entities/sla/build.js +124 -0
  192. package/dist-sdk/src/entities/sla/from-tf.d.ts +40 -0
  193. package/dist-sdk/src/entities/sla/from-tf.js +164 -0
  194. package/dist-sdk/src/entities/sla/index.d.ts +1 -0
  195. package/dist-sdk/src/entities/sla/index.js +1 -0
  196. package/dist-sdk/src/entities/sla/module.d.ts +4 -0
  197. package/dist-sdk/src/entities/sla/module.js +73 -0
  198. package/dist-sdk/src/entities/sla/printer.d.ts +2 -0
  199. package/dist-sdk/src/entities/sla/printer.js +84 -0
  200. package/dist-sdk/src/entities/sla/to-tf.d.ts +12 -0
  201. package/dist-sdk/src/entities/sla/to-tf.js +81 -0
  202. package/dist-sdk/src/entities/table/build.d.ts +7 -2
  203. package/dist-sdk/src/entities/table/build.js +22 -1
  204. package/dist-sdk/src/entities/table/deserializer/normalize.d.ts +4 -1
  205. package/dist-sdk/src/entities/table/from-tf.js +89 -14
  206. package/dist-sdk/src/entities/table/index.d.ts +1 -1
  207. package/dist-sdk/src/entities/table/to-tf.js +41 -2
  208. package/dist-sdk/src/entities/task/from-tf.js +2 -1
  209. package/dist-sdk/src/entities/task/to-tf.js +1 -0
  210. package/dist-sdk/src/entities/view/from-tf.d.ts +8 -4
  211. package/dist-sdk/src/entities/view/from-tf.js +10 -9
  212. package/dist-sdk/src/entities/view/module.js +5 -0
  213. package/dist-sdk/src/entities/widget/from-tf.js +15 -4
  214. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +51 -4
  215. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  216. package/dist-sdk/src/graph/index.d.ts +20 -2
  217. package/dist-sdk/src/graph/index.js +19 -0
  218. package/dist-sdk/src/graph/modules.js +11 -1
  219. package/dist-sdk/src/graph/resource-types.d.ts +47 -0
  220. package/dist-sdk/src/graph/resource-types.js +62 -0
  221. package/dist-sdk/src/graph/types.d.ts +116 -6
  222. package/package.json +6 -3
@@ -68,8 +68,8 @@ export declare function agentToolBareLabel(agentBareTfLabel: string, toolName: s
68
68
  * tool's order is part of its address. Pull pins every tool ei suffixed
69
69
  * (agentFromTf), so a pulled agent rebuilds its exported labels even when ei
70
70
  * counted a tool pull doesn't print. Every known tool kind counts, implemented
71
- * or not, as in ei. Parity holds within one agent only: ei's counter spans
72
- * the whole app and is keyed on the agent's display name (edk#2000).
71
+ * or not, as in ei. ei counts per agent too, keyed on the agent's label, so
72
+ * another agent's tools never shift these (edk#2000).
73
73
  */
74
74
  export declare function agentToolLabelSuffixes(agentBareTfLabel: string, tools: readonly Record<string, unknown>[]): readonly string[];
75
75
  /** A tool entry's (`{ createRecord: { name, ... } }`) platform name, or "". */
@@ -178,8 +178,8 @@ export function agentToolBareLabel(agentBareTfLabel, toolName, labelSuffix) {
178
178
  * tool's order is part of its address. Pull pins every tool ei suffixed
179
179
  * (agentFromTf), so a pulled agent rebuilds its exported labels even when ei
180
180
  * counted a tool pull doesn't print. Every known tool kind counts, implemented
181
- * or not, as in ei. Parity holds within one agent only: ei's counter spans
182
- * the whole app and is keyed on the agent's display name (edk#2000).
181
+ * or not, as in ei. ei counts per agent too, keyed on the agent's label, so
182
+ * another agent's tools never shift these (edk#2000).
183
183
  */
184
184
  export function agentToolLabelSuffixes(agentBareTfLabel, tools) {
185
185
  return collisionLabelSuffixes(tools.map((entry) => {
@@ -30,9 +30,10 @@ 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
- import type { UnsafePlatformId } from "../../core/platform-id.js";
36
+ import { type UnsafePlatformId } from "../../core/platform-id.js";
36
37
  /**
37
38
  * One entry of a dynamic picklist's `sort.orders` — `field` is a token on
38
39
  * the related aspect (same convention as `relatedLabelFieldId`), resolved
@@ -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,9 +1,10 @@
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";
6
6
  import { assertFieldAllowList } from "../field/allow-list.js";
7
+ import { isUnsafePlatformId } from "../../core/platform-id.js";
7
8
  /** Where a classic layout section renders: the main area or the record side panel. */
8
9
  export const layoutSectionDisplayLocation = {
9
10
  center: "CENTER",
@@ -137,15 +138,16 @@ function unwrapUnsafePlatformIds(value) {
137
138
  * added without re-running `elementum generate`) evaluates to `undefined`; the
138
139
  * TF emitter then drops the whole dynamic config, omits the field resource,
139
140
  * and the plan destroys the field. Throw instead, naming the owner, the
140
- * field's bag key and the missing ref, so the build fails closed. `filter`
141
- * operands are NOT checked here (out of scope for #1780).
141
+ * field's bag key and the missing ref, so the build fails closed. Every field
142
+ * operand inside `filter` is checked the same way (#2309): see
143
+ * {@link assertDynamicFilterRefs}.
142
144
  */
143
145
  function assertDynamicPicklistRefs(field, dynamic, refName, owner) {
144
146
  const typeLabel = field.type === "MULTI_PICKLIST" ? "Multi-Select" : "Dropdown";
145
147
  const where = `${owner !== undefined ? `${owner} ` : ""}${refName !== undefined ? `fields.${refName}` : "field"} ` +
146
148
  `(${JSON.stringify(field.name)}, dynamic ${typeLabel})`;
147
- const missing = (path) => {
148
- throw new Error(`${where}: ${path} is undefined. The catalog ref it names doesn't resolve: the referenced field, app, element ` +
149
+ const missing = (path, refersTo) => {
150
+ throw new Error(`${where}: ${path} is undefined${refersTo !== undefined ? ` (${refersTo})` : ""}. The catalog ref it names doesn't resolve: the referenced field, app, element ` +
149
151
  `or task was removed or renamed, or it was just added and the catalog hasn't been regenerated (run ` +
150
152
  `\`elementum generate\`, then build again). Building would drop this field's dynamic config and the plan ` +
151
153
  `would destroy the field; fix or remove the ref.`);
@@ -169,6 +171,79 @@ function assertDynamicPicklistRefs(field, dynamic, refName, owner) {
169
171
  missing(`config.dynamic.sort[${i}].field`);
170
172
  });
171
173
  }
174
+ if (dynamic.filter !== undefined) {
175
+ // Name where each filter field lives (#2309): a left side or `fieldValue`
176
+ // operand is a field of the Dropdown's source, a `recordField` operand a
177
+ // field of the record that owns the Dropdown.
178
+ const source = describeDynamicSource(dynamic.relatedAspectId);
179
+ const scopes = {
180
+ source: source !== undefined ? `a field of the Dropdown's source, ${source}` : "a field of the Dropdown's source",
181
+ record: `a field of ${owner ?? "the record that owns this Dropdown"}`,
182
+ };
183
+ assertDynamicFilterRefs(dynamic.filter, "config.dynamic.filter", missing, scopes);
184
+ }
185
+ }
186
+ /** `element "demoSharedVendor"` for a catalog ref, `platform id "…"` for an unsafe id; `undefined` if absent. */
187
+ function describeDynamicSource(source) {
188
+ if (source === null || typeof source !== "object")
189
+ return undefined;
190
+ if (isUnsafePlatformId(source))
191
+ return `platform id ${JSON.stringify(source.value)}`;
192
+ const ref = source;
193
+ if (typeof ref.__kind !== "string" || typeof ref.refName !== "string")
194
+ return undefined;
195
+ return `${ref.__kind} ${JSON.stringify(ref.refName)}`;
196
+ }
197
+ /** Filter types whose node carries children or nothing, not a left side. */
198
+ const DYNAMIC_FILTER_BRANCH_TYPES = new Set(["AND", "OR"]);
199
+ const DYNAMIC_FILTER_CONSTANT_TYPES = new Set(["TRUE", "FALSE"]);
200
+ /**
201
+ * A dynamic Dropdown filter's field operands must be present, the same rule as
202
+ * the refs {@link assertDynamicPicklistRefs} checks (#2309). A removed field
203
+ * evaluates to `undefined`: `filter.isNotNull(catalog.x.fields.removed)` keeps
204
+ * `field: undefined`, and `fieldValue(...)` / `recordField(...)` keep an
205
+ * `undefined` operand. The TF emitter can't build that filter, drops the whole
206
+ * dynamic config, leaves the field out, and the plan destroys it. Walks
207
+ * `and`/`or` children so the error names the exact path.
208
+ */
209
+ function assertDynamicFilterRefs(node, path, missing, scopes) {
210
+ if (node == null)
211
+ missing(path);
212
+ if (typeof node !== "object")
213
+ return;
214
+ const filter = node;
215
+ const type = typeof filter.type === "string" ? filter.type.toUpperCase() : undefined;
216
+ if (type === undefined || DYNAMIC_FILTER_CONSTANT_TYPES.has(type))
217
+ return;
218
+ if (DYNAMIC_FILTER_BRANCH_TYPES.has(type)) {
219
+ if (Array.isArray(filter.children)) {
220
+ filter.children.forEach((child, i) => assertDynamicFilterRefs(child, `${path}.children[${i}]`, missing, scopes));
221
+ }
222
+ return;
223
+ }
224
+ const hasLeft = ["field", "field_id", "leftValue", "left_value"].some((key) => Object.hasOwn(filter, key));
225
+ if (!hasLeft || (Object.hasOwn(filter, "field") && filter.field == null))
226
+ missing(`${path}.field`, scopes.source);
227
+ if (Object.hasOwn(filter, "leftValue"))
228
+ assertDynamicFilterOperand(filter.leftValue, `${path}.leftValue`, missing, scopes);
229
+ for (const key of ["value", "min", "max"]) {
230
+ if (Object.hasOwn(filter, key))
231
+ assertDynamicFilterOperand(filter[key], `${path}.${key}`, missing, scopes);
232
+ }
233
+ if (Array.isArray(filter.values)) {
234
+ filter.values.forEach((value, i) => assertDynamicFilterOperand(value, `${path}.values[${i}]`, missing, scopes));
235
+ }
236
+ }
237
+ /** A `FIELD` or `RECORD_FIELD` operand whose field is `undefined` names a removed field. */
238
+ function assertDynamicFilterOperand(operand, path, missing, scopes) {
239
+ if (operand === null || typeof operand !== "object")
240
+ return;
241
+ const value = operand;
242
+ const type = typeof value.type === "string" ? value.type.toUpperCase() : undefined;
243
+ if (type === "FIELD" && value.value == null && value.field == null && value.field_id == null)
244
+ missing(`${path}.value`, scopes.source);
245
+ if (type === "RECORD_FIELD" && value.field == null)
246
+ missing(`${path}.field`, scopes.record);
172
247
  }
173
248
  /**
174
249
  * Serialize an authored field to its `AspectFieldInput` wire shape — shared
@@ -194,6 +269,7 @@ export function serializeField(field, refName, owner) {
194
269
  // the existing id for an update; create lets the server assign one.
195
270
  name: field.name,
196
271
  ...(refName !== undefined ? { __refName: refName } : {}),
272
+ ...(field.resourceKey !== undefined ? { __resourceKey: field.resourceKey } : {}),
197
273
  ...(field.columnName !== undefined ? { columnName: field.columnName } : {}),
198
274
  ...(field.required !== undefined ? { required: field.required } : {}),
199
275
  ...(field.requiredOnClose !== undefined ? { requiredOnClose: field.requiredOnClose } : {}),
@@ -269,18 +345,18 @@ export function serializeField(field, refName, owner) {
269
345
  return { [key]: base };
270
346
  }
271
347
  /**
272
- * Reject a custom `fields:` bag key that is ALSO authored under
273
- * `systemFields` — the same slot provisioned twice. Keys not present in
274
- * systemFields stay legal as ordinary fields (existing workspaces key
275
- * plain fields `title` etc.); full reservation of the canonical keys is
276
- * 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).
277
355
  */
278
- export function assertNoSystemKeyCollision(builder, name, fields, systemFields) {
279
- if (systemFields === undefined)
280
- return;
356
+ export function assertNoSystemKeyCollision(builder, name, fields, reservedKeys = SYSTEM_FIELD_KEY_SET) {
281
357
  for (const key of Object.keys(fields)) {
282
- if (systemFields[key] !== undefined) {
283
- 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.`);
284
360
  }
285
361
  }
286
362
  }
@@ -462,6 +538,7 @@ export function app(opts) {
462
538
  ...("dynamicSource" in field && field.dynamicSource === true ? { dynamicSource: true } : {}),
463
539
  ...(field.options !== undefined ? { options: picklistOptionLabels(field.options) } : {}),
464
540
  ...(field.tags !== undefined ? { tags: field.tags } : {}),
541
+ ...(field.resourceKey !== undefined ? { resourceKey: field.resourceKey } : {}),
465
542
  };
466
543
  }
467
544
  for (const key of SYSTEM_FIELD_KEYS) {
@@ -552,7 +629,7 @@ export function app(opts) {
552
629
  return makeRef(refName);
553
630
  },
554
631
  def(refName) {
555
- assertNoSystemKeyCollision("app", opts.name, opts.fields, opts.systemFields);
632
+ assertNoSystemKeyCollision("app", opts.name, opts.fields);
556
633
  const displayBlocks = serializeDisplayBlocks(opts.displayBlocks, "LAYOUT");
557
634
  const recordCreateDisplayBlocks = serializeDisplayBlocks(opts.recordCreateDisplayBlocks, "CREATE");
558
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",
@@ -223,8 +238,7 @@ export function appFromTf(appBlock, fieldBlocks, ctx, viewBlocks = { layoutBlock
223
238
  const unextracted = { type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app", fieldKeys, fieldKeysByName, unextractedFieldIds };
224
239
  const { layouts, listViews, calendarViews, kanbanViews, dashboardViews, agentViews, customViews, viewOrder, deleteDefaultListView } = viewsFromTf(viewBlocks.layoutBlocks, viewBlocks.listViewBlocks, viewBlocks.calendarViewBlocks, viewBlocks.kanbanViewBlocks, viewBlocks.dashboardViewBlocks, viewBlocks.agentViewBlocks, viewBlocks.managedViewOrderBlocks, {
225
240
  type: APP_RESOURCE_TYPE, label, ownerTfLabel: label, scope: "app",
226
- stageKeys: stageHandles.keys,
227
- stageKeyByHandle: stageHandles.byHandle,
241
+ stageHandles,
228
242
  fieldKeys,
229
243
  fieldKeysByName,
230
244
  unextractedFieldIds,
@@ -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;
@@ -28,14 +28,25 @@ export declare function stageKeyFromPicklistValue(pv: PicklistValueWire): AppSta
28
28
  * derive the same handle, the first keeps it and a diagnostic says so,
29
29
  * instead of silently rebinding. A stage left with no handle that maps to
30
30
  * its own key (a punctuation key whose only handle is another stage's key,
31
- * e.g. `pre-approval` next to `pre_approval`) is diagnosed too. Pull never
32
- * writes another stage's handle for it: see {@link pulledStageHandle}.
31
+ * e.g. `pre-approval` next to `pre_approval`) is diagnosed too. So is a
32
+ * stage whose only handle is the `SanitizeName` fallback and another stage
33
+ * already holds it: two stages whose names have no usable characters
34
+ * (`"!!!"` and `"日本"`) both fall back to `resource`, and the second has no
35
+ * handle at all (#1767). Pull never writes another stage's handle for it:
36
+ * see {@link pulledStageHandle}.
33
37
  */
34
38
  export declare function stageKeyByHandle(stages: readonly AppStageKey[], diagnostics?: string[]): Map<string, string>;
39
+ /** A stage left with no handle because its only fallback handle belongs to another stage (#1767). */
40
+ export interface FallbackLostStage {
41
+ readonly handle: string;
42
+ readonly owner: string;
43
+ }
35
44
  /** An app's stage handles plus its real stage keys, for pull-side resolution (#1136). */
36
45
  export interface StageHandleIndex {
37
46
  readonly byHandle: ReadonlyMap<string, string>;
38
47
  readonly keys: ReadonlySet<string>;
48
+ /** Stages whose only (fallback) handle another stage holds, by real key (#1767). */
49
+ readonly fallbackLost?: ReadonlyMap<string, FallbackLostStage>;
39
50
  }
40
51
  /** {@link stageKeyByHandle} plus the real key set. */
41
52
  export declare function stageHandleIndex(stages: readonly AppStageKey[], diagnostics?: string[]): StageHandleIndex;
@@ -50,6 +61,7 @@ export type PulledStageHandle = {
50
61
  readonly kind: "lost";
51
62
  readonly handle: string;
52
63
  readonly owner: string;
64
+ readonly fallback?: true;
53
65
  } | {
54
66
  readonly kind: "none";
55
67
  };
@@ -60,7 +72,9 @@ export type PulledStageHandle = {
60
72
  * slug is another stage's own key, e.g. `pre-approval` next to
61
73
  * `pre_approval`), returns `lost`: writing that handle would bind the
62
74
  * reference to the other stage on build, so the caller leaves the
63
- * reference out with a diagnostic instead. Without an index (or for an
75
+ * reference out with a diagnostic instead. The same holds for a stage whose
76
+ * only handle is the shared `SanitizeName` fallback another stage holds
77
+ * (#1767). Without an index (or for an
64
78
  * index that is not one of the app's stages) this is `stageHandleTfLabel`.
65
79
  */
66
80
  export declare function pulledStageHandle(index: string, stages: StageHandleIndex | undefined): PulledStageHandle;
@@ -77,6 +91,7 @@ export declare class LostStageHandleError extends EntityTfError {
77
91
  export declare function lostStageMessage(where: string, index: string, lost: {
78
92
  readonly handle: string;
79
93
  readonly owner: string;
94
+ readonly fallback?: true;
80
95
  }, outcome: string): string;
81
96
  /** The owning app's stage handles (see {@link stageKeyByHandle}) from its built payload, for child entities. */
82
97
  export declare function appStageKeyByHandle(payload: unknown): Map<string, string> | undefined;
@@ -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;
@@ -30,10 +30,17 @@ export function stageKeyFromPicklistValue(pv) {
30
30
  * derive the same handle, the first keeps it and a diagnostic says so,
31
31
  * instead of silently rebinding. A stage left with no handle that maps to
32
32
  * its own key (a punctuation key whose only handle is another stage's key,
33
- * e.g. `pre-approval` next to `pre_approval`) is diagnosed too. Pull never
34
- * writes another stage's handle for it: see {@link pulledStageHandle}.
33
+ * e.g. `pre-approval` next to `pre_approval`) is diagnosed too. So is a
34
+ * stage whose only handle is the `SanitizeName` fallback and another stage
35
+ * already holds it: two stages whose names have no usable characters
36
+ * (`"!!!"` and `"日本"`) both fall back to `resource`, and the second has no
37
+ * handle at all (#1767). Pull never writes another stage's handle for it:
38
+ * see {@link pulledStageHandle}.
35
39
  */
36
40
  export function stageKeyByHandle(stages, diagnostics) {
41
+ return stageHandleBindings(stages, diagnostics).byHandle;
42
+ }
43
+ function stageHandleBindings(stages, diagnostics) {
37
44
  const byHandle = new Map();
38
45
  for (const stage of stages) {
39
46
  if (isTfLabel(stage.key) && !byHandle.has(stage.key))
@@ -78,17 +85,34 @@ export function stageKeyByHandle(stages, diagnostics) {
78
85
  byHandle.set(exportHandle, stage.key);
79
86
  }
80
87
  const bound = new Set(byHandle.values());
88
+ const fallbackLost = new Map();
89
+ for (const stage of stages) {
90
+ if (bound.has(stage.key) || reported.has(stage.key) || lostTo.has(stage.key) || fallbackLost.has(stage.key))
91
+ continue;
92
+ const exportHandle = sanitizeName(stage.name);
93
+ const owner = byHandle.get(exportHandle);
94
+ if (owner === undefined || owner === stage.key)
95
+ continue;
96
+ fallbackLost.set(stage.key, { handle: exportHandle, owner });
97
+ // An empty slug ("!!!", "日本") has no handle characters at all; a
98
+ // non-empty one ("1st!!!") has them, but only as the same fallback.
99
+ const why = snakeSlug(stage.name) === ""
100
+ ? `its name ${JSON.stringify(stage.name)} has no characters a handle can use, so its only handle is the fallback handle "${exportHandle}"`
101
+ : `its only handle is the fallback handle "${exportHandle}" that its name ${JSON.stringify(stage.name)} produces`;
102
+ diagnostics?.push(`systemFields.stage: stage "${stage.key}" has no handle of its own: ${why}, and stage "${owner}" already holds that handle. 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 "${owner}". Rename one of the stages so their names produce different handles (#1767).`);
103
+ }
81
104
  for (const stage of stages) {
82
105
  const lost = lostTo.get(stage.key);
83
106
  if (bound.has(stage.key) || reported.has(stage.key) || lost === undefined)
84
107
  continue;
85
- 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.`);
86
109
  }
87
- return byHandle;
110
+ return { byHandle, fallbackLost };
88
111
  }
89
112
  /** {@link stageKeyByHandle} plus the real key set. */
90
113
  export function stageHandleIndex(stages, diagnostics) {
91
- return { byHandle: stageKeyByHandle(stages, diagnostics), keys: new Set(stages.map((stage) => stage.key)) };
114
+ const { byHandle, fallbackLost } = stageHandleBindings(stages, diagnostics);
115
+ return { byHandle, keys: new Set(stages.map((stage) => stage.key)), ...(fallbackLost.size > 0 ? { fallbackLost } : {}) };
92
116
  }
93
117
  /** The stage handles of an `elementum_app` block's `stages` attribute, or undefined when it has none. */
94
118
  export function stageHandleIndexFromTfStages(value) {
@@ -111,7 +135,9 @@ export function stageHandleIndexFromTfStages(value) {
111
135
  * slug is another stage's own key, e.g. `pre-approval` next to
112
136
  * `pre_approval`), returns `lost`: writing that handle would bind the
113
137
  * reference to the other stage on build, so the caller leaves the
114
- * reference out with a diagnostic instead. Without an index (or for an
138
+ * reference out with a diagnostic instead. The same holds for a stage whose
139
+ * only handle is the shared `SanitizeName` fallback another stage holds
140
+ * (#1767). Without an index (or for an
115
141
  * index that is not one of the app's stages) this is `stageHandleTfLabel`.
116
142
  */
117
143
  export function pulledStageHandle(index, stages) {
@@ -123,6 +149,9 @@ export function pulledStageHandle(index, stages) {
123
149
  for (const [handle, key] of stages.byHandle)
124
150
  if (key === index && isTfLabel(handle))
125
151
  return { kind: "handle", handle };
152
+ const fallbackLost = stages.fallbackLost?.get(index);
153
+ if (fallbackLost !== undefined)
154
+ return { kind: "lost", handle: fallbackLost.handle, owner: fallbackLost.owner, fallback: true };
126
155
  if (preferred === undefined)
127
156
  return { kind: "none" };
128
157
  const owner = stages.byHandle.get(preferred);
@@ -142,7 +171,12 @@ export class LostStageHandleError extends EntityTfError {
142
171
  }
143
172
  /** The per-reference warning for a `lost` {@link pulledStageHandle}. */
144
173
  export function lostStageMessage(where, index, lost, outcome) {
145
- return `${where}: stage "${index}" has no handle of its own (its handle "${lost.handle}" is stage "${lost.owner}"'s key); ${outcome} instead of binding it to "${lost.owner}" (#1136)`;
174
+ // A fallback loss (#1767): the handle is the SanitizeName fallback the other
175
+ // stage holds, not that stage's key, so the #1136 sentence would be false.
176
+ const why = lost.fallback === true
177
+ ? `its only handle is the fallback handle "${lost.handle}", which stage "${lost.owner}" already holds`
178
+ : `its handle "${lost.handle}" is stage "${lost.owner}"'s key`;
179
+ return `${where}: stage "${index}" has no handle of its own (${why}); ${outcome} instead of binding it to "${lost.owner}" (${lost.fallback === true ? "#1767" : "#1136"})`;
146
180
  }
147
181
  /** The owning app's stage handles (see {@link stageKeyByHandle}) from its built payload, for child entities. */
148
182
  export function appStageKeyByHandle(payload) {
@@ -227,6 +227,7 @@ export function appToTf(entity, ctx) {
227
227
  const field = fieldToTf(typeKey, inner, {
228
228
  ownerTfLabel: ctx.appTfLabel,
229
229
  appRefName: ctx.appRefName,
230
+ ...(payload.name !== undefined && { ownerName: payload.name }),
230
231
  objectId,
231
232
  diagnostics: ctx.diagnostics,
232
233
  orgRefs: ctx.orgRefs,
@@ -344,6 +345,7 @@ export function appToTf(entity, ctx) {
344
345
  objectId,
345
346
  orgRefs: ctx.orgRefs,
346
347
  diagnostics: ctx.diagnostics,
348
+ ...(ctx.optionIds !== undefined && { optionIds: ctx.optionIds }),
347
349
  appRefName: ctx.appRefName,
348
350
  serviceAccounts: payload.serviceAccounts,
349
351
  fieldAddresses,