@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
@@ -6,8 +6,12 @@
6
6
  * module never names the owner's resource type.
7
7
  *
8
8
  * Unsupported authoring shapes degrade through `diagnostics` — reported,
9
- * never silent, never thrown (plan §4.3). The one hard error is a
10
- * non-canonical bag key: it has no well-defined terraform address.
9
+ * never silent (plan §4.3). Two shapes are hard errors instead: a
10
+ * non-canonical bag key (it has no well-defined terraform address), and a
11
+ * dynamic Dropdown or Multi-Select `filter` that can't be built (#2309):
12
+ * dropping it would leave the whole field resource out and the plan would
13
+ * destroy the field, so `buildDynamicPicklistConfigAttr` throws (see its
14
+ * `failClosed`).
11
15
  */
12
16
  import { EntityTfError } from "../../engine/entity.js";
13
17
  import { typedCoverageGap } from "../../engine/coverage-gaps.js";
@@ -16,10 +20,12 @@ import { expr, isCanonicalTsLabel, sanitizeName, scopedResourceLabel, snakeSlug,
16
20
  import { SYSTEM_FIELD_KEY_SET, systemFieldTag } from "../../core/system-fields.js";
17
21
  import { ELEMENT_AUDIT_SYSTEM_FIELD_KEYS, ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
18
22
  import { filterToTf as filterWireToTfCodec } from "../shared/filters/tf-codec.js";
23
+ import { optionSelectionLiteral, optionsLocalName } from "../shared/filters/option-lookups.js";
19
24
  import { foreignFieldDataLabel } from "../shared/foreign-ref.js";
20
25
  import { isAttachmentMediaType } from "./media-types.js";
21
26
  import { picklistLabel } from "./options.js";
22
27
  import { SUB_TYPE_BY_AUTHORING_TYPE, SUB_TYPE_BY_TYPE_KEY } from "./types.js";
28
+ import { tfChildPartForFieldBagKey } from "./from-tf.js";
23
29
  /** Reconstruct custom-field ownership from a loaded app/element payload. */
24
30
  export function authoredFieldKeysFromPayload(payload) {
25
31
  if (typeof payload !== "object" || payload === null)
@@ -206,7 +212,7 @@ function resolveFieldOnObject(token, object, opts, where, attrName = "relatedLab
206
212
  opts.diagnostics.push(`${where}: ${attrName} token "${refName}" resolves to table "${object.target.tfLabel}" — tables expose columns, not fields; dropped`);
207
213
  return undefined;
208
214
  }
209
- const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind, object.fieldOwnership);
215
+ const value = fieldRefToTfValue(token.fieldType ?? "", refName, object.target.tfLabel, object.target.kind, object.fieldOwnership, token.resourceKey);
210
216
  if (value === undefined) {
211
217
  opts.diagnostics.push(`${where}: ${attrName} token "${refName}" has no terraform field resource mapping (fieldType ${JSON.stringify(token.fieldType ?? "")}); dropped`);
212
218
  }
@@ -271,7 +277,7 @@ function stageOrgRefs(real) {
271
277
  * and committed only once the ENTIRE config resolves — an early `undefined`
272
278
  * return anywhere below leaves no orphaned `data.tf` block behind.
273
279
  */
274
- function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
280
+ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey, field) {
275
281
  if (cfg.relatedAspectId === undefined || cfg.relatedLabelFieldId === undefined) {
276
282
  opts.diagnostics.push(`${where}: dynamic picklist config requires relatedAspectId and relatedLabelFieldId; dropped`);
277
283
  return undefined;
@@ -335,6 +341,23 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
335
341
  if (cfg.valuesRenderType !== undefined)
336
342
  attrs["values_render_type"] = cfg.valuesRenderType;
337
343
  if (cfg.filter !== undefined) {
344
+ // A filter build can't resolve fails the build instead of dropping the
345
+ // whole dynamic config (#2309): without it the field resource is left
346
+ // out and plan destroys the field (the #1978 rule). Pull never prints
347
+ // such a filter: it blocks a filter it can't reconstruct
348
+ // (field/from-tf.ts blockReplaceForcingDrop) and keeps an unextracted
349
+ // field as its platform id.
350
+ const diagnosticsBefore = opts.diagnostics.length;
351
+ const failClosed = (reason) => {
352
+ const resolverNotes = opts.diagnostics.slice(diagnosticsBefore).map((note) => `\n - ${note.replace(/; dropped$/, "")}`).join("");
353
+ // Same shape as the authoring error (#1780): owner kind and name,
354
+ // `fields.<key>`, display name and type; build adds the source file.
355
+ throw new EntityTfError(`${opts.scope ?? "app"} ${JSON.stringify(opts.ownerName ?? opts.appRefName)} fields.${field.bagKey} ` +
356
+ `(${JSON.stringify(field.name)}, dynamic ${typeKey === "multiPicklist" ? "Multi-Select" : "Dropdown"}): ` +
357
+ `config.dynamic.filter ${reason}.${resolverNotes}\n` +
358
+ "Building would drop this field's dynamic config and the plan would destroy the field; " +
359
+ "fix or remove the filter's ref (#2309).");
360
+ };
338
361
  let unresolvedField = false;
339
362
  const owner = {
340
363
  value: opts.objectId,
@@ -343,40 +366,55 @@ function buildDynamicPicklistConfigAttr(cfg, opts, where, typeKey) {
343
366
  target: { kind: opts.scope ?? "app", tfLabel: opts.ownerTfLabel },
344
367
  fieldOwnership: opts.fieldOwnership,
345
368
  };
346
- try {
347
- const filterValue = filterWireToTfCodec(cfg.filter, {
348
- recordField: (token) => {
349
- const value = resolveFieldOnObject(token, owner, opts_, where, "filter record field");
350
- if (value === undefined) {
351
- unresolvedField = true;
352
- return "";
353
- }
354
- return value;
355
- },
356
- recordFieldOwner: () => opts.objectId,
357
- field: (token) => {
358
- const value = resolveFieldOnObject(token, resolvedObject, opts_, where, "filter field");
359
- if (value === undefined) {
360
- // resolveFieldOnObject already pushed a diagnostic — this
361
- // placeholder only satisfies the codec's TfValue return type
362
- // long enough to unwind via the unresolvedField check below.
363
- unresolvedField = true;
364
- return "";
365
- }
366
- return value;
367
- },
368
- reference: () => {
369
- throw new EntityTfError(`${where}: dynamic picklist filter does not support value references`);
369
+ const filter = cfg.filter;
370
+ const buildFilter = () => filterWireToTfCodec(filter, {
371
+ recordField: (token) => {
372
+ const value = resolveFieldOnObject(token, owner, opts_, where, "filter record field");
373
+ if (value === undefined) {
374
+ unresolvedField = true;
375
+ return "";
376
+ }
377
+ return value;
378
+ },
379
+ recordFieldOwner: () => opts.objectId,
380
+ field: (token) => {
381
+ const value = resolveFieldOnObject(token, resolvedObject, opts_, where, "filter field");
382
+ if (value === undefined) {
383
+ // resolveFieldOnObject already pushed a diagnostic — this
384
+ // placeholder only satisfies the codec's TfValue return type
385
+ // long enough to unwind via the unresolvedField check below.
386
+ unresolvedField = true;
387
+ return "";
388
+ }
389
+ return value;
390
+ },
391
+ reference: () => {
392
+ throw new EntityTfError(`${where}: dynamic picklist filter does not support value references`);
393
+ },
394
+ // #2582: a Dropdown option is selected with filter.textOption(label).
395
+ literal: optionSelectionLiteral({
396
+ where: `${where}: config.dynamic.filter`,
397
+ address: where,
398
+ name: field.name,
399
+ ownerKind: "field",
400
+ optionsLocal: (token) => {
401
+ const target = resolvedObject.target;
402
+ return target === undefined || (target.kind !== "app" && target.kind !== "element")
403
+ ? undefined
404
+ : optionsLocalName(target.tfLabel, target.kind, token);
370
405
  },
371
- });
372
- if (unresolvedField)
373
- return undefined;
374
- attrs["filter"] = filterValue;
406
+ }),
407
+ });
408
+ let filterValue;
409
+ try {
410
+ filterValue = buildFilter();
375
411
  }
376
412
  catch (e) {
377
- opts.diagnostics.push(`${where}: filter ${e instanceof Error ? e.message : String(e)}; dropped`);
378
- return undefined;
413
+ failClosed(`can't be built: ${e instanceof Error ? e.message : String(e)}`);
379
414
  }
415
+ if (unresolvedField)
416
+ failClosed("names a field build can't resolve");
417
+ attrs["filter"] = filterValue;
380
418
  }
381
419
  if (cfg.sort !== undefined) {
382
420
  const sort = resolveDynamicPicklistSort(cfg.sort, resolvedObject, opts, where);
@@ -511,12 +549,14 @@ export function fieldToTf(typeKey, inner, opts) {
511
549
  }
512
550
  const bagKey = inner.__refName ?? snakeSlug(name);
513
551
  // The bag key IS the field's terraform label (via the bijection — the
514
- // stable naming contract, Sean 2026-07-22). Non-canonical keys have no
552
+ // stable naming contract, Sean 2026-07-22), except a #1871 re-key that
553
+ // carries `__resourceKey` keeps the natural system-key address so pull
554
+ // then plan does not destroy the live field. Non-canonical keys have no
515
555
  // well-defined address: hard error, not a degradation.
516
556
  if (!isCanonicalTsLabel(bagKey)) {
517
557
  throw new EntityTfError(`field bag key "${bagKey}" is not a canonical tsLabel (see src/engine/tf/labels.ts) — rename the key in fields: {}`);
518
558
  }
519
- const tfLabel = scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(bagKey), scope);
559
+ const tfLabel = scopedResourceLabel(ownerTfLabel, tfChildPartForFieldBagKey(bagKey, inner.__resourceKey), scope);
520
560
  const attrs = {
521
561
  object_id: objectId,
522
562
  name,
@@ -562,7 +602,7 @@ export function fieldToTf(typeKey, inner, opts) {
562
602
  if (typeof include.picklist === "object" && include.picklist !== null) {
563
603
  const field = include.picklist.picklistFieldId;
564
604
  if (field?.refName !== undefined) {
565
- const value = fieldRefToTfValue(field.fieldType ?? "PICKLIST", field.refName, ownerTfLabel, scope, opts.fieldOwnership);
605
+ const value = fieldRefToTfValue(field.fieldType ?? "PICKLIST", field.refName, ownerTfLabel, scope, opts.fieldOwnership, field.resourceKey);
566
606
  if (value !== undefined) {
567
607
  attrs["include_type"] = "PICKLIST";
568
608
  attrs["picklist_field_id"] = value;
@@ -649,7 +689,7 @@ export function fieldToTf(typeKey, inner, opts) {
649
689
  }
650
690
  if (subType.hasOptions === true && inner.config?.dynamic !== undefined) {
651
691
  const where = `field "${name}"`;
652
- const dynamicConfig = buildDynamicPicklistConfigAttr(inner.config.dynamic, opts, where, typeKey);
692
+ const dynamicConfig = buildDynamicPicklistConfigAttr(inner.config.dynamic, opts, where, typeKey, { bagKey, name });
653
693
  if (dynamicConfig === undefined)
654
694
  return undefined;
655
695
  attrs["dynamic_config"] = dynamicConfig;
@@ -702,7 +742,7 @@ export function fieldToTf(typeKey, inner, opts) {
702
742
  diagnostics.push(`field "${name}": parent value reference must target a Dropdown or Multi-Select field; dropped`);
703
743
  continue;
704
744
  }
705
- const parentTfLabel = scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(ref.field.refName), opts.scope ?? "app");
745
+ const parentTfLabel = scopedResourceLabel(opts.ownerTfLabel, tfChildPartForFieldBagKey(ref.field.refName ?? "", ref.field.resourceKey), opts.scope ?? "app");
706
746
  parentValueIds.push(expr.local(`${parentTfLabel}_options_by_label`, [{ index: ref.label }]));
707
747
  }
708
748
  if (parentValueIds.length > 0)
@@ -796,7 +836,7 @@ function allowListToTf(typeKey, inner, opts, attrs, name) {
796
836
  if (token.parent !== undefined && token.parent !== opts.appRefName) {
797
837
  throw new EntityTfError(`${where}: parentGroupField must belong to the same app or element, not ${JSON.stringify(token.parent)}`);
798
838
  }
799
- const value = fieldRefToTfValue(token.fieldType, token.refName ?? "", opts.ownerTfLabel, opts.scope ?? "app", opts.fieldOwnership);
839
+ const value = fieldRefToTfValue(token.fieldType, token.refName ?? "", opts.ownerTfLabel, opts.scope ?? "app", opts.fieldOwnership, token.resourceKey);
800
840
  if (value === undefined)
801
841
  throw new EntityTfError(`${where}: parentGroupField ${JSON.stringify(token.refName ?? "")} does not resolve to a group field resource`);
802
842
  attrs["parent_group_field_id"] = value;
@@ -842,13 +882,13 @@ function scalarOrUndefined(v) {
842
882
  /**
843
883
  * Element system fields resolve through their `element/locals.ts` locals.
844
884
  * Elements have no status/stage fields; the audit fields exist only on some
845
- * elements, which the build checks against `systemFields.audit`. An element
846
- * may author its own field under an audit key (`createdAt: dateTimeField(…)`),
847
- * which shadows the audit field, so a key in `fieldAddresses` is that field.
885
+ * elements, which the build checks against `systemFields.audit`. Custom fields
886
+ * may not use reserved system keys (#1871); pull re-keys a collision to
887
+ * `<key>Custom`. A key in `fieldAddresses` is therefore always a custom field.
848
888
  */
849
889
  const ELEMENT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_SYSTEM_FIELD_KEYS);
850
890
  const ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET = new Set(ELEMENT_AUDIT_SYSTEM_FIELD_KEYS);
851
- export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldOwnership) {
891
+ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app", fieldOwnership, resourceKey) {
852
892
  if (!isCanonicalTsLabel(refName))
853
893
  return undefined;
854
894
  if (scope === "element" &&
@@ -856,9 +896,13 @@ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app
856
896
  fieldOwnership === undefined) {
857
897
  throw new EntityTfError(`element field "${refName}" requires authored-field ownership metadata to distinguish a custom field from the platform audit field`);
858
898
  }
899
+ // Reserved system keys are never custom after #1871 reject/re-key. The
900
+ // fieldOwnership escape remains for leftover source that still keys a
901
+ // custom field as a system key (build rejects new source) and for element
902
+ // audit fields until that path is fully re-keyed.
859
903
  const isSystemField = scope === "element"
860
904
  ? ELEMENT_SYSTEM_FIELD_KEY_SET.has(refName) && !(ELEMENT_AUDIT_SYSTEM_FIELD_KEY_SET.has(refName) && fieldOwnership?.has(refName) === true)
861
- : SYSTEM_FIELD_KEY_SET.has(refName);
905
+ : SYSTEM_FIELD_KEY_SET.has(refName) && !(fieldOwnership?.has(refName) === true);
862
906
  if (isSystemField) {
863
907
  return expr.local(`${ownerTfLabel}_${tsLabelToTfLabel(refName)}_field_id`);
864
908
  }
@@ -872,7 +916,7 @@ export function fieldRefToTfValue(fieldType, refName, ownerTfLabel, scope = "app
872
916
  const subType = SUB_TYPE_BY_AUTHORING_TYPE.get(fieldType);
873
917
  if (subType === undefined)
874
918
  return undefined;
875
- return expr.resourceAttr(subType.resourceType, scopedResourceLabel(ownerTfLabel, tsLabelToTfLabel(refName), scope), ["id"]);
919
+ return expr.resourceAttr(subType.resourceType, scopedResourceLabel(ownerTfLabel, tfChildPartForFieldBagKey(refName, resourceKey), scope), ["id"]);
876
920
  }
877
921
  /**
878
922
  * Why build leaves out an entry: its field reference has no field in source
@@ -13,6 +13,7 @@ export const categoryModule = {
13
13
  // Apps reference categories (`category_id`), so build emits this data
14
14
  // source and the build-vs-export must scope it.
15
15
  referencedByBuild: true,
16
+ managedInOrganization: true,
16
17
  },
17
18
  authoring: { unit: "inline", bag: "categories" },
18
19
  parents: [{ parent: "org", child: "category" }],
@@ -9,5 +9,6 @@ export { connectorModule } from "./connector.js";
9
9
  export { emailAliasModule } from "./email-alias.js";
10
10
  export { groupModule } from "./group.js";
11
11
  export { phoneProviderModule } from "./phone-provider.js";
12
+ export { voiceAuthModule } from "./voice-auth.js";
12
13
  export { roleModule } from "./role.js";
13
14
  export { userModule } from "./user.js";
@@ -9,5 +9,6 @@ export { connectorModule } from "./connector.js";
9
9
  export { emailAliasModule } from "./email-alias.js";
10
10
  export { groupModule } from "./group.js";
11
11
  export { phoneProviderModule } from "./phone-provider.js";
12
+ export { voiceAuthModule } from "./voice-auth.js";
12
13
  export { roleModule } from "./role.js";
13
14
  export { userModule } from "./user.js";
@@ -20,5 +20,10 @@ export const roleModule = {
20
20
  lifecycle: NO_LIFECYCLE,
21
21
  canvas: NO_CANVAS,
22
22
  catalog: NO_CATALOG,
23
+ roundtrip: {
24
+ referenceAliases: [],
25
+ // Provider set attributes (edk#2437): order carries no meaning.
26
+ unorderedListAttributes: ["user_ids", "group_ids", "service_account_ids"],
27
+ },
23
28
  };
24
29
  export const ROLE_RESOURCE_TYPE = "elementum_role";
@@ -0,0 +1,5 @@
1
+ /** Voice auth configs: org-owned reference identities, name-keyed data lookups. */
2
+ import { type EntityKindModule } from "../../graph/types.js";
3
+ export declare const VOICE_AUTH_RESOURCE_TYPE = "elementum_voice_auth_config";
4
+ export declare const VOICE_AUTH_ORG_BAG: "voiceAuths";
5
+ export declare const voiceAuthModule: EntityKindModule;
@@ -0,0 +1,33 @@
1
+ /** Voice auth configs: org-owned reference identities, name-keyed data lookups. */
2
+ import { namedOnlyFactoryEntry } from "../../catalog/render-helpers.js";
3
+ export const VOICE_AUTH_RESOURCE_TYPE = "elementum_voice_auth_config";
4
+ export const VOICE_AUTH_ORG_BAG = "voiceAuths";
5
+ export const voiceAuthModule = {
6
+ kind: "voice-auth",
7
+ stream: { role: "streamMember" },
8
+ data: {
9
+ participates: true,
10
+ resourceType: VOICE_AUTH_RESOURCE_TYPE,
11
+ lookupAttr: "name",
12
+ catalogKind: "voiceAuth",
13
+ orgBag: VOICE_AUTH_ORG_BAG,
14
+ referencedByBuild: true,
15
+ managedInOrganization: true,
16
+ },
17
+ authoring: { unit: "inline", bag: "voiceAuths" },
18
+ parents: [{ parent: "org", child: "voice-auth" }],
19
+ resource: { shape: "single", resourceType: VOICE_AUTH_RESOURCE_TYPE, adoptable: true },
20
+ lifecycle: { participates: true },
21
+ canvas: { participates: true, label: "Voice Auth", glyph: "◉", component: "orgIdentity" },
22
+ catalog: {
23
+ participates: true,
24
+ refKind: "voiceAuth",
25
+ catalogBag: "voiceAuths",
26
+ renderOrder: 116,
27
+ catalogRoot: "org",
28
+ factoryName: "voiceAuthRef",
29
+ renderEntry: namedOnlyFactoryEntry("voiceAuthRef"),
30
+ stubRef: (refName) => ({ __kind: "voiceAuth", refName, name: refName }),
31
+ refFromAuthoring: () => undefined,
32
+ },
33
+ };
@@ -1,3 +1,4 @@
1
+ import { type OrganizationVoiceAuth } from "./voice-auth.js";
1
2
  import type { RoleUserRef } from "../role/build.js";
2
3
  export interface OrganizationCategory {
3
4
  readonly name: string;
@@ -227,6 +228,7 @@ export interface DefineOrganizationOptions {
227
228
  readonly cloudLinks?: Readonly<Record<string, OrganizationCloudLink>>;
228
229
  readonly emailAliases?: Readonly<Record<string, OrganizationEmailAlias>>;
229
230
  readonly phoneProviders?: Readonly<Record<string, OrganizationPhoneProvider>>;
231
+ readonly voiceAuths?: Readonly<Record<string, OrganizationVoiceAuth>>;
230
232
  }
231
233
  export interface ConfiguredOrganization {
232
234
  readonly kind: "organizationConfig";
@@ -235,6 +237,7 @@ export interface ConfiguredOrganization {
235
237
  readonly cloudLinks: Readonly<Record<string, OrganizationCloudLink>>;
236
238
  readonly emailAliases: Readonly<Record<string, OrganizationEmailAlias>>;
237
239
  readonly phoneProviders: Readonly<Record<string, OrganizationPhoneProvider>>;
240
+ readonly voiceAuths: Readonly<Record<string, OrganizationVoiceAuth>>;
238
241
  }
239
242
  /** Organization-owned resources live in one ergonomic, optional `organization.ts` file. */
240
243
  export declare function organization(opts: DefineOrganizationOptions): ConfiguredOrganization;
@@ -143,6 +143,7 @@ export function organization(opts) {
143
143
  requireNames("groups", opts.groups);
144
144
  requireNames("cloudLinks", opts.cloudLinks);
145
145
  requireNames("phoneProviders", opts.phoneProviders);
146
+ requireNames("voiceAuths", opts.voiceAuths);
146
147
  for (const [key, value] of Object.entries(opts.emailAliases ?? {})) {
147
148
  if (key.trim() === "" || value.alias.trim() === "")
148
149
  throw new EdkValidationError(`organization emailAliases.${key} must have a non-empty alias.`);
@@ -161,5 +162,6 @@ export function organization(opts) {
161
162
  cloudLinks: opts.cloudLinks ?? {},
162
163
  emailAliases: opts.emailAliases ?? {},
163
164
  phoneProviders: opts.phoneProviders ?? {},
165
+ voiceAuths: opts.voiceAuths ?? {},
164
166
  };
165
167
  }
@@ -1,2 +1,3 @@
1
1
  export { organization, apiCloudLink, bearerTokenCredentials, bigQueryCloudLink, cloudLinkScheduleUnit, cloudLinkUsageType, cloudLinkWarehouseSize, databricksCloudLink, emailAlias, elementumCloudLink, elementumSnowflakeCloudLink, externalOauthCredentials, passwordCredentials, privateKeyCredentials, serviceAccountCredentials, snowflakeCloudLink, twilioPhoneProvider, type ConfiguredOrganization, type DefineOrganizationOptions, type OrganizationCategory, type OrganizationGroup, redactedSecret, secret, unavailableValue, type CloudLinkCredentials, type CloudLinkSchedule, type CloudLinkScheduleUnit, type CloudLinkUsageType, type CloudLinkWarehouseSize, type OrganizationCloudLink, type OrganizationEmailAlias, type OrganizationPhoneProvider, type OrganizationSecret, type OrganizationSecretValue, type RedactedOrganizationSecret, type UnavailableOrganizationValue, } from "./build.js";
2
+ export { knownCallerAuth, unknownCallerAuth, voiceAuth, voiceAuthFailureAction, type KnownCallerAuth, type OrganizationVoiceAuth, type UnknownCallerAuth, type VoiceAuthCallerTreatment, type VoiceAuthEndCall, type VoiceAuthFailure, type VoiceAuthFailureAction, type VoiceAuthHandoff, type VoiceAuthOtpRecovery, } from "./voice-auth.js";
2
3
  export { userRef, type RoleUserRef as OrganizationUserRef } from "../role/build.js";
@@ -1,2 +1,3 @@
1
1
  export { organization, apiCloudLink, bearerTokenCredentials, bigQueryCloudLink, cloudLinkScheduleUnit, cloudLinkUsageType, cloudLinkWarehouseSize, databricksCloudLink, emailAlias, elementumCloudLink, elementumSnowflakeCloudLink, externalOauthCredentials, passwordCredentials, privateKeyCredentials, serviceAccountCredentials, snowflakeCloudLink, twilioPhoneProvider, redactedSecret, secret, unavailableValue, } from "./build.js";
2
+ export { knownCallerAuth, unknownCallerAuth, voiceAuth, voiceAuthFailureAction, } from "./voice-auth.js";
2
3
  export { userRef } from "../role/build.js";
@@ -5,3 +5,5 @@ export declare function organizationToTf(organization: ConfiguredOrganization, c
5
5
  readonly orgRefs: OrgRefLookup;
6
6
  readonly diagnostics?: string[];
7
7
  }): TfBlock[];
8
+ /** Resource HCL for one organization.ts voice auth, used when adoption imports it. */
9
+ export declare function renderVoiceAuthAdoptionResource(label: string, value: unknown): string | undefined;
@@ -1,4 +1,6 @@
1
- import { expr, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
1
+ import { expr, renderBlock, sanitizeName, tsLabelToTfLabel } from "../../engine/tf/index.js";
2
+ import { VOICE_AUTH_RESOURCE_TYPE } from "../org/voice-auth.js";
3
+ import { voiceAuthFailureAction } from "./voice-auth.js";
2
4
  const CATEGORY = "elementum_category";
3
5
  const GROUP = "elementum_group";
4
6
  const USER = "elementum_user";
@@ -150,5 +152,61 @@ export function organizationToTf(organization, ctx) {
150
152
  for (const [name, block] of resourceVariables)
151
153
  variables.set(name, block);
152
154
  }
155
+ for (const [key, config] of Object.entries(organization.voiceAuths)) {
156
+ blocks.push({ kind: "resource", type: VOICE_AUTH_RESOURCE_TYPE, label: tsLabelToTfLabel(key), attrs: voiceAuthAttrs(config) });
157
+ }
153
158
  return [...variables.values(), ...blocks];
154
159
  }
160
+ /** Resource HCL for one organization.ts voice auth, used when adoption imports it. */
161
+ export function renderVoiceAuthAdoptionResource(label, value) {
162
+ if (!isOrganizationVoiceAuth(value))
163
+ return undefined;
164
+ return renderBlock({
165
+ kind: "resource",
166
+ type: VOICE_AUTH_RESOURCE_TYPE,
167
+ label,
168
+ attrs: voiceAuthAttrs(value),
169
+ }).trimEnd();
170
+ }
171
+ function isOrganizationVoiceAuth(value) {
172
+ if (value === null || typeof value !== "object")
173
+ return false;
174
+ const config = value;
175
+ return typeof config.name === "string" && config.name !== ""
176
+ && typeof config.knownCallers?.treatment === "string"
177
+ && typeof config.unknownCallers?.treatment === "string"
178
+ && typeof config.failure?.action === "string";
179
+ }
180
+ function voiceAuthAttrs(config) {
181
+ const knownCallers = { treatment: config.knownCallers.treatment };
182
+ if (config.knownCallers.firstMessage !== undefined)
183
+ knownCallers["first_message"] = config.knownCallers.firstMessage;
184
+ const unknownCallers = { treatment: config.unknownCallers.treatment };
185
+ if (config.unknownCallers.firstMessage !== undefined)
186
+ unknownCallers["first_message"] = config.unknownCallers.firstMessage;
187
+ const failure = { action: config.failure.action };
188
+ if (config.failure.action === voiceAuthFailureAction.handoff) {
189
+ failure["handoff"] = { phone_number: config.failure.phoneNumber, message: config.failure.message };
190
+ }
191
+ else if (config.failure.message !== undefined) {
192
+ failure["end_call_message"] = config.failure.message;
193
+ }
194
+ const attrs = {
195
+ name: config.name,
196
+ known_callers: knownCallers,
197
+ unknown_callers: unknownCallers,
198
+ failure,
199
+ };
200
+ if (config.instructions !== undefined)
201
+ attrs["instructions"] = config.instructions;
202
+ if (config.firstMessage !== undefined)
203
+ attrs["first_message"] = config.firstMessage;
204
+ if (config.otpRecovery !== undefined) {
205
+ attrs["otp_recovery"] = {
206
+ allow_employee_id_correction: config.otpRecovery.allowEmployeeIdCorrection,
207
+ allow_otp_resend: config.otpRecovery.allowOtpResend,
208
+ repeat_provided_employee_id: config.otpRecovery.repeatProvidedEmployeeId,
209
+ };
210
+ }
211
+ return attrs;
212
+ }
@@ -0,0 +1,60 @@
1
+ /** How a voice auth config treats a caller whose number is already known. */
2
+ export declare const knownCallerAuth: {
3
+ readonly continue: "CONTINUE";
4
+ readonly employeeIdAndOtp: "EMPLOYEE_ID_OTP";
5
+ readonly pin: "PIN";
6
+ };
7
+ export type KnownCallerAuth = (typeof knownCallerAuth)[keyof typeof knownCallerAuth];
8
+ /** How a voice auth config treats a caller whose number is not known. */
9
+ export declare const unknownCallerAuth: {
10
+ readonly continue: "CONTINUE";
11
+ readonly stop: "DO_NOT_CONTINUE";
12
+ readonly employeeIdAndOtp: "EMPLOYEE_ID_OTP";
13
+ };
14
+ export type UnknownCallerAuth = (typeof unknownCallerAuth)[keyof typeof unknownCallerAuth];
15
+ /** What a voice auth config does when verification fails. */
16
+ export declare const voiceAuthFailureAction: {
17
+ readonly endCall: "END_CALL";
18
+ readonly handoff: "HANDOFF";
19
+ };
20
+ export type VoiceAuthFailureAction = (typeof voiceAuthFailureAction)[keyof typeof voiceAuthFailureAction];
21
+ export interface VoiceAuthCallerTreatment<Treatment extends string> {
22
+ readonly treatment: Treatment;
23
+ readonly firstMessage?: string;
24
+ }
25
+ /** End the call, optionally after speaking a message. */
26
+ export interface VoiceAuthEndCall {
27
+ readonly action: typeof voiceAuthFailureAction.endCall;
28
+ readonly message?: string;
29
+ }
30
+ /** Transfer the caller to another number. */
31
+ export interface VoiceAuthHandoff {
32
+ readonly action: typeof voiceAuthFailureAction.handoff;
33
+ readonly phoneNumber: `+${number}`;
34
+ readonly message: string;
35
+ }
36
+ export type VoiceAuthFailure = VoiceAuthEndCall | VoiceAuthHandoff;
37
+ export interface VoiceAuthOtpRecovery {
38
+ readonly allowEmployeeIdCorrection: boolean;
39
+ readonly allowOtpResend: boolean;
40
+ readonly repeatProvidedEmployeeId: boolean;
41
+ }
42
+ export interface OrganizationVoiceAuth {
43
+ readonly name: string;
44
+ readonly instructions?: string;
45
+ readonly firstMessage?: string;
46
+ readonly knownCallers: VoiceAuthCallerTreatment<KnownCallerAuth>;
47
+ readonly unknownCallers: VoiceAuthCallerTreatment<UnknownCallerAuth>;
48
+ readonly failure: VoiceAuthFailure;
49
+ readonly otpRecovery?: VoiceAuthOtpRecovery;
50
+ }
51
+ /** An organization-owned voice authentication policy for phone services. */
52
+ export declare function voiceAuth(opts: {
53
+ readonly name: string;
54
+ readonly instructions?: string;
55
+ readonly firstMessage?: string;
56
+ readonly knownCallers: VoiceAuthCallerTreatment<KnownCallerAuth>;
57
+ readonly unknownCallers: VoiceAuthCallerTreatment<UnknownCallerAuth>;
58
+ readonly failure: VoiceAuthFailure;
59
+ readonly otpRecovery?: VoiceAuthOtpRecovery;
60
+ }): OrganizationVoiceAuth;
@@ -0,0 +1,60 @@
1
+ import { EdkValidationError } from "../../../elementum-entity-client/errors.js";
2
+ /** How a voice auth config treats a caller whose number is already known. */
3
+ export const knownCallerAuth = {
4
+ continue: "CONTINUE",
5
+ employeeIdAndOtp: "EMPLOYEE_ID_OTP",
6
+ pin: "PIN",
7
+ };
8
+ /** How a voice auth config treats a caller whose number is not known. */
9
+ export const unknownCallerAuth = {
10
+ continue: "CONTINUE",
11
+ stop: "DO_NOT_CONTINUE",
12
+ employeeIdAndOtp: "EMPLOYEE_ID_OTP",
13
+ };
14
+ /** What a voice auth config does when verification fails. */
15
+ export const voiceAuthFailureAction = {
16
+ endCall: "END_CALL",
17
+ handoff: "HANDOFF",
18
+ };
19
+ const E164 = /^\+[1-9]\d{7,14}$/;
20
+ function requireTreatment(where, value, allowed) {
21
+ if (value === undefined)
22
+ throw new EdkValidationError(`${where} is required.`);
23
+ if (!Object.values(allowed).includes(value.treatment)) {
24
+ throw new EdkValidationError(`${where}.treatment ${JSON.stringify(value.treatment)} is not supported.`);
25
+ }
26
+ return value;
27
+ }
28
+ /** An organization-owned voice authentication policy for phone services. */
29
+ export function voiceAuth(opts) {
30
+ if (opts.name.trim() === "")
31
+ throw new EdkValidationError("voiceAuth name must be non-empty.");
32
+ const knownCallers = requireTreatment("voiceAuth knownCallers", opts.knownCallers, knownCallerAuth);
33
+ const unknownCallers = requireTreatment("voiceAuth unknownCallers", opts.unknownCallers, unknownCallerAuth);
34
+ const failure = opts.failure;
35
+ if (failure === undefined)
36
+ throw new EdkValidationError("voiceAuth failure is required.");
37
+ if (failure.action === voiceAuthFailureAction.handoff) {
38
+ if (!E164.test(failure.phoneNumber)) {
39
+ throw new EdkValidationError("voiceAuth failure phoneNumber must be an E.164 number such as +14155551234.");
40
+ }
41
+ if (failure.message.trim() === "")
42
+ throw new EdkValidationError("voiceAuth handoff message must be non-empty.");
43
+ }
44
+ else if (failure.action === voiceAuthFailureAction.endCall) {
45
+ // Accepted. A message is optional.
46
+ }
47
+ else {
48
+ const unexpected = failure;
49
+ throw new EdkValidationError(`voiceAuth failure action ${JSON.stringify(unexpected)} is not supported.`);
50
+ }
51
+ return {
52
+ name: opts.name,
53
+ ...(opts.instructions !== undefined ? { instructions: opts.instructions } : {}),
54
+ ...(opts.firstMessage !== undefined ? { firstMessage: opts.firstMessage } : {}),
55
+ knownCallers,
56
+ unknownCallers,
57
+ failure,
58
+ ...(opts.otpRecovery !== undefined ? { otpRecovery: opts.otpRecovery } : {}),
59
+ };
60
+ }
@@ -1,4 +1,4 @@
1
- import { type AgentRef, type CatalogRef, type PhoneProviderRef, type PhoneServiceRef } from "../../catalog/index.js";
1
+ import { type AgentRef, type CatalogRef, type PhoneProviderRef, type PhoneServiceRef, type VoiceAuthRef } from "../../catalog/index.js";
2
2
  import type { DeployableEntity, EntityDeployOptions } from "../../engine/entity.js";
3
3
  import { type PhoneServiceNumber } from "./types.js";
4
4
  /**
@@ -9,6 +9,14 @@ export type PhoneServiceOptions<AppRefName extends string = string> = EntityDepl
9
9
  readonly app: CatalogRef<"app", AppRefName>;
10
10
  readonly agent: AgentRef<NoInfer<AppRefName>>;
11
11
  readonly provider: PhoneProviderRef;
12
+ /**
13
+ * Organization voice-auth policy applied to calls on this number.
14
+ * `catalog.voiceAuths.<key>` after `pull org`. `{ name }` addresses a policy
15
+ * authored in `organization.ts` in the same apply, before that catalog key exists.
16
+ */
17
+ readonly voiceAuth?: VoiceAuthRef | {
18
+ readonly name: string;
19
+ };
12
20
  };
13
21
  export interface PhoneServiceConfigured {
14
22
  ref(refName: string): PhoneServiceRef;
@@ -23,6 +23,7 @@ export function phoneService(opts) {
23
23
  ...(opts.twilioExistingNumber !== undefined ? { twilioExistingNumber: opts.twilioExistingNumber } : {}),
24
24
  ...(opts.twilioNewNumber !== undefined ? { twilioNewNumber: opts.twilioNewNumber } : {}),
25
25
  ...(opts.registration !== undefined ? { registration: opts.registration } : {}),
26
+ ...(opts.voiceAuth !== undefined ? { voiceAuth: opts.voiceAuth } : {}),
26
27
  }),
27
28
  ...(opts.enabled !== undefined ? { enabled: opts.enabled } : {}),
28
29
  };
@@ -27,6 +27,9 @@ export function printPhoneService(service, opts) {
27
27
  lines.push(` app: catalog.${opts.appRefName},`);
28
28
  lines.push(` agent: catalog.${opts.appRefName}.agents.${service.agentKey},`);
29
29
  lines.push(` provider: catalog.phoneProviders.${service.providerKey},`);
30
+ if (service.voiceAuthKey !== undefined) {
31
+ lines.push(` voiceAuth: catalog.voiceAuths.${service.voiceAuthKey},`);
32
+ }
30
33
  if (service.callerAccessMode !== undefined) {
31
34
  lines.push(` callerAccessMode: callerAccessMode.${constantKey(callerAccessMode, service.callerAccessMode)},`);
32
35
  }
@@ -5,6 +5,7 @@ export interface NormalizedPhoneService {
5
5
  readonly refName: string;
6
6
  readonly agentKey: string;
7
7
  readonly providerKey: string;
8
+ readonly voiceAuthKey?: string;
8
9
  readonly callerAccessMode?: CallerAccessMode;
9
10
  readonly twilioExistingNumber?: {
10
11
  readonly phoneNumber: E164PhoneNumber;