@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
@@ -2,9 +2,10 @@ import { dataRefLabel, optionalString, plainObject, resourceRefLabel } from "../
2
2
  import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
3
3
  import { AGENT_RESOURCE_TYPE } from "../agent/module.js";
4
4
  import { APP_RESOURCE_TYPE } from "../app/module.js";
5
+ import { VOICE_AUTH_RESOURCE_TYPE } from "../org/voice-auth.js";
5
6
  import { callerAccessMode } from "./types.js";
6
7
  const KNOWN_ATTRS = new Set([
7
- "app_id", "provider_id", "agent_id", "caller_access_mode", "twilio_existing_number",
8
+ "app_id", "provider_id", "agent_id", "caller_access_mode", "voice_auth_config_id", "twilio_existing_number",
8
9
  "twilio_new_number", "registration",
9
10
  ]);
10
11
  const CALLER_ACCESS_MODES = new Set(Object.values(callerAccessMode));
@@ -43,6 +44,11 @@ export function phoneServiceFromTf(block, opts, ctx) {
43
44
  ctx.diagnostics.push(`${where}: expected exactly one valid Twilio existing number or new area code; skipped`);
44
45
  return undefined;
45
46
  }
47
+ const voiceAuthLabel = dataRefLabel(block.attrs["voice_auth_config_id"], VOICE_AUTH_RESOURCE_TYPE)
48
+ ?? resourceRefLabel(block.attrs["voice_auth_config_id"], VOICE_AUTH_RESOURCE_TYPE);
49
+ if (block.attrs["voice_auth_config_id"] !== undefined && voiceAuthLabel === undefined) {
50
+ ctx.diagnostics.push(`${where}: voice_auth_config_id is not a resolvable ${VOICE_AUTH_RESOURCE_TYPE} reference; omitted`);
51
+ }
46
52
  const callerAccess = optionalString(block.attrs, "caller_access_mode", where, ctx);
47
53
  if (callerAccess !== undefined && !isCallerAccessMode(callerAccess)) {
48
54
  ctx.diagnostics.push(`${where}: unsupported caller_access_mode "${callerAccess}"; omitted`);
@@ -59,6 +65,7 @@ export function phoneServiceFromTf(block, opts, ctx) {
59
65
  refName: scopedLabelToBagKey(opts.appLabel, label, "app"),
60
66
  agentKey: scopedLabelToBagKey(opts.appLabel, agentLabel, "app"),
61
67
  providerKey: tfLabelToTsLabel(providerLabel),
68
+ ...(voiceAuthLabel !== undefined ? { voiceAuthKey: tfLabelToTsLabel(voiceAuthLabel) } : {}),
62
69
  ...(callerAccess !== undefined && isCallerAccessMode(callerAccess) ? { callerAccessMode: callerAccess } : {}),
63
70
  ...(hasExisting ? { twilioExistingNumber: { phoneNumber: existingNumber } } : {}),
64
71
  ...(hasCreated ? { twilioNewNumber: { areaCode: areaCode } } : {}),
@@ -3,6 +3,7 @@ import { expr, scopedResourceLabel, tsLabelToTfLabel } from "../../engine/tf/ind
3
3
  import { APP_RESOURCE_TYPE } from "../app/module.js";
4
4
  import { AGENT_RESOURCE_TYPE } from "../agent/module.js";
5
5
  import { PHONE_PROVIDER_ORG_BAG } from "../org/phone-provider.js";
6
+ import { VOICE_AUTH_ORG_BAG, VOICE_AUTH_RESOURCE_TYPE } from "../org/voice-auth.js";
6
7
  import { PHONE_SERVICE_RESOURCE_TYPE } from "./module.js";
7
8
  export function phoneServiceToTf(entity, opts) {
8
9
  if (entity.kind !== "phone-service") {
@@ -29,6 +30,21 @@ export function phoneServiceToTf(entity, opts) {
29
30
  };
30
31
  if (service.callerAccessMode !== undefined)
31
32
  attrs["caller_access_mode"] = service.callerAccessMode;
33
+ const voiceAuthWire = service.voiceAuth;
34
+ if (voiceAuthWire !== undefined) {
35
+ const voiceAuth = voiceAuthWire.__kind === "voiceAuth" && voiceAuthWire.refName !== undefined
36
+ ? opts.orgRefs.byTsLabel(VOICE_AUTH_ORG_BAG, voiceAuthWire.refName)
37
+ : voiceAuthWire.name !== undefined
38
+ ? opts.orgRefs.byName(VOICE_AUTH_ORG_BAG, voiceAuthWire.name)
39
+ : undefined;
40
+ const described = voiceAuthWire.refName ?? voiceAuthWire.name ?? "";
41
+ if (voiceAuth === undefined) {
42
+ throw new EntityTfError(`phone service "${entity.refName}": voice auth "${described}" is not in org.voiceAuths or organization.ts — re-run \`elementum pull org --data-only\` or author it with voiceAuth(...) and pass { name }`);
43
+ }
44
+ attrs["voice_auth_config_id"] = voiceAuth.managed === true
45
+ ? expr.resourceAttr(VOICE_AUTH_RESOURCE_TYPE, voiceAuth.tfLabel, ["id"])
46
+ : expr.dataAttr(VOICE_AUTH_RESOURCE_TYPE, voiceAuth.tfLabel, ["id"]);
47
+ }
32
48
  if (service.twilioExistingNumber !== undefined) {
33
49
  attrs["twilio_existing_number"] = { phone_number: service.twilioExistingNumber.phoneNumber ?? "" };
34
50
  }
@@ -1,7 +1,7 @@
1
1
  import { optionalString, plainObject, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { reportUnknownAttrs } from "../../engine/pull/attrs.js";
3
3
  import { scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
4
- import { fieldKeyFromTfValue } from "../field/from-tf.js";
4
+ import { elementAuditFieldReference, fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { unextractedFieldRefId } from "../view/from-tf.js";
6
6
  import { RECORD_CREATE_FORM_RESOURCE_TYPE } from "./module.js";
7
7
  const KNOWN_ATTRS = new Set(["app_id", "sections"]);
@@ -59,7 +59,7 @@ function sectionFromTf(raw, index, formWhere, owner, ctx) {
59
59
  ctx.diagnostics.push(`${where}: field_ids entry ${JSON.stringify(fieldId)} is not a known field reference; dropped`);
60
60
  }
61
61
  else
62
- fields.push(key);
62
+ fields.push(key === resolved ? elementAuditFieldReference(fieldId, key, owner, ctx) : key);
63
63
  }
64
64
  const agentLabel = resourceRefLabel(rec["agent_id"], "elementum_agent");
65
65
  if (rec["agent_id"] !== undefined && agentLabel === undefined) {
@@ -1,7 +1,7 @@
1
1
  import { dataRefLabel, reportAuthoringBlocker, resourceRefLabel } from "../../engine/pull/context.js";
2
2
  import { expr, isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel, } from "../../engine/tf/index.js";
3
3
  import { filterFromTf } from "../access-policy/from-tf.js";
4
- import { decodeForeignDataField, fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
4
+ import { decodeForeignDataField, elementAuditFieldReference, fieldKeyFromTfRef, fieldKeyFromTfValue } from "../field/from-tf.js";
5
5
  import { resolveDataAspectTarget, resolveDataTaskTarget } from "../shared/aspect-target-from-tf.js";
6
6
  import { SUB_TYPE_BY_RESOURCE } from "../field/types.js";
7
7
  import { bareForeignFieldIdRef, isBarePlatformId, resolveOwnDataFieldRef, unextractedFieldRefId } from "../view/from-tf.js";
@@ -49,9 +49,14 @@ function relationshipFromTf(block, owner, ctx) {
49
49
  // A field pull did not extract keeps its platform id: its key would print
50
50
  // as nothing and build would drop the column (#1966). With no id the pull
51
51
  // fails (#1978).
52
- const field = owner.unextracted === undefined
52
+ const kept = owner.unextracted === undefined
53
53
  ? fieldKey
54
54
  : unextractedFieldRefId(rec["field_id"], fieldKey, owner.unextracted, ctx, `${where}.columns[${index}]`);
55
+ // A platform audit column keeps its own identity next to an own field
56
+ // under the same key, as in views and layouts (#2513).
57
+ const field = kept === undefined || kept !== fieldKey
58
+ ? kept
59
+ : elementAuditFieldReference(rec["field_id"], kept, { type: ownerResourceType, label: owner.label, scope: owner.scope, refName: owner.ownerRefName }, ctx);
55
60
  // A bare related id ei couldn't name resolves the same way as the owner
56
61
  // side, so the join column is never dropped silently (#1991).
57
62
  const relatedRaw = rec["related_field_id"];
@@ -1,5 +1,5 @@
1
1
  import { NO_CANVAS, NO_CATALOG, NO_LIFECYCLE } from "../../graph/types.js";
2
- import { relationshipPairErrors } from "./pair-check.js";
2
+ import { relationshipPair, relationshipPairErrors } from "./pair-check.js";
3
3
  export const RELATIONSHIP_RESOURCE_TYPE = "elementum_relationship";
4
4
  export const relationshipModule = {
5
5
  kind: "relationship",
@@ -14,5 +14,5 @@ export const relationshipModule = {
14
14
  lifecycle: NO_LIFECYCLE,
15
15
  canvas: NO_CANVAS,
16
16
  catalog: NO_CATALOG,
17
- buildChecks: { validateBuiltBlocks: relationshipPairErrors },
17
+ buildChecks: { validateBuiltRoots: relationshipPairErrors, comparedGroup: relationshipPair },
18
18
  };
@@ -1,7 +1,11 @@
1
1
  import { type TfBlock } from "../../engine/tf/index.js";
2
+ import type { BuildCheckFailure, BuiltRootSource } from "../../graph/types.js";
3
+ /** The pair a relationship block joins, which build hashes per root against the last pull (edk#2430). */
4
+ export declare function relationshipPair(block: TfBlock): string | undefined;
2
5
  /**
3
6
  * A relationship between two managed roots is two platform records, one per side, whose columns the platform
4
7
  * mirrors: changing one side changes the other. Each side lives in its owner's source, so the two must mirror
5
- * each other or the next plan reverts a one-sided edit. Returns one error per root pair that disagrees.
8
+ * each other or the next plan reverts a one-sided edit. Returns one failure per root pair that disagrees,
9
+ * naming both source files and which one differs from its last pull when that is known (edk#2430).
6
10
  */
7
- export declare function relationshipPairErrors(blocks: readonly TfBlock[]): string[];
11
+ export declare function relationshipPairErrors(roots: readonly BuiltRootSource[]): BuildCheckFailure[];
@@ -6,7 +6,7 @@ function managedLabel(value) {
6
6
  function columnLabel(value) {
7
7
  return value !== undefined && isTfExpr(value) && (value.$expr === "resource-attr" || value.$expr === "data-attr") ? value.label : JSON.stringify(value);
8
8
  }
9
- function sideOf(block) {
9
+ function sideOf(block, root) {
10
10
  const owner = managedLabel(block.attrs["object_id"]);
11
11
  const target = managedLabel(block.attrs["related_object_id"]);
12
12
  if (owner === undefined || target === undefined || owner === target || block.label === undefined)
@@ -15,7 +15,7 @@ function sideOf(block) {
15
15
  const attrs = (column ?? {});
16
16
  return [columnLabel(attrs["field_id"]), columnLabel(attrs["related_field_id"])];
17
17
  });
18
- return { label: block.label, owner, target, columns };
18
+ return { label: block.label, owner, target, columns, root, pull: root.pull.group(pairKey(owner, target)) };
19
19
  }
20
20
  /** Columns as one comparable key, oriented from `from`'s side. */
21
21
  function joinKey(side, from) {
@@ -25,22 +25,99 @@ function joinKey(side, from) {
25
25
  function describe(side) {
26
26
  return `[${side.columns.map(([own, related]) => `${own} ↔ ${related}`).join(", ")}]`;
27
27
  }
28
+ function isRelationshipBlock(block) {
29
+ return block.kind === "resource" && block.type === RELATIONSHIP_RESOURCE_TYPE;
30
+ }
31
+ function pairKey(owner, target) {
32
+ return [owner, target].sort().join(" <> ");
33
+ }
34
+ /** The pair a relationship block joins, which build hashes per root against the last pull (edk#2430). */
35
+ export function relationshipPair(block) {
36
+ if (!isRelationshipBlock(block))
37
+ return undefined;
38
+ const owner = managedLabel(block.attrs["object_id"]);
39
+ const target = managedLabel(block.attrs["related_object_id"]);
40
+ return owner === undefined || target === undefined || owner === target ? undefined : pairKey(owner, target);
41
+ }
42
+ const PULLABLE_KINDS = new Set(["app", "element", "task"]);
43
+ function pulledAt(iso) {
44
+ return iso.replace(/\.\d+Z$/, "Z");
45
+ }
46
+ function repull(root) {
47
+ return PULLABLE_KINDS.has(root.kind) ? `\`elementum pull ${root.kind} ${root.tfLabel}\`` : `a fresh pull of ${root.file}`;
48
+ }
49
+ /** One side's relationships against its last pull on this machine, as a clause naming its file. */
50
+ function pullClause(side) {
51
+ const { root, pull: status } = side;
52
+ switch (status.state) {
53
+ case "unchecked":
54
+ return `${root.file} isn't compared with its pull record in this build`;
55
+ case "unreadable":
56
+ return status.what === "record"
57
+ ? `${root.file}'s pull record couldn't be read (.edk-state/pulled-roots.json)`
58
+ : `${root.file} couldn't be read to compare with its pull record`;
59
+ case "unrecorded":
60
+ return `${root.file} has no pull record on this machine`;
61
+ case "unchanged":
62
+ return status.fileEdited
63
+ ? `${root.file} was edited after its last pull (${pulledAt(status.pulledAt)}) but not its relationships to ${side.target}`
64
+ : `${root.file} still matches its last pull (${pulledAt(status.pulledAt)})`;
65
+ case "edited":
66
+ return `${root.file}'s relationships to ${side.target} were edited after its last pull (${pulledAt(status.pulledAt)})`;
67
+ case "unknown":
68
+ return `${root.file} was edited after its last pull (${pulledAt(status.pulledAt)}), and whether that touched its relationships to ${side.target} isn't known`;
69
+ }
70
+ }
71
+ function pulledTogether(a, b) {
72
+ return a.pulledAt === b.pulledAt || (a.pullRun !== undefined && a.pullRun === b.pullRun);
73
+ }
74
+ /**
75
+ * Which of the two sides' relationships differ from their last pull on this machine, as far as that is known.
76
+ * Only this pair's relationships count: an edit elsewhere in a file doesn't make its side the stale one (edk#2430).
77
+ */
78
+ function staleness(leftSide, rightSide) {
79
+ const [left, right] = [leftSide.root, rightSide.root];
80
+ const [a, b] = [leftSide.pull, rightSide.pull];
81
+ if (a.state === "unchecked" || b.state === "unchecked") {
82
+ return "This build doesn't compare files with their pull records, so which side is stale isn't checked.";
83
+ }
84
+ const sides = `${pullClause(leftSide)}; ${pullClause(rightSide)}`;
85
+ // A re-pull rewrites the whole file, so it's only offered for a file with no edits since its pull (edk#2430).
86
+ if ((a.state === "edited" && b.state === "unchanged") || (a.state === "unchanged" && b.state === "edited")) {
87
+ const [edited, untouched] = a.state === "edited" ? [left, right] : [right, left];
88
+ return `${sides}, so the edit is the difference: make the same change in ${untouched.file}, or undo it in ${edited.file} by hand.`;
89
+ }
90
+ if (a.state === "unchanged" && b.state === "unchanged") {
91
+ if (pulledTogether(a, b)) {
92
+ return a.fileEdited || b.fileEdited
93
+ ? `${sides}, and the two were pulled together, so the platform returned the two sides this way; compare both with the platform and fix the relationship by hand.`
94
+ : `${sides}, and the two were pulled together, so the platform returned the two sides this way; re-pull both before changing either.`;
95
+ }
96
+ const [older, newer, olderStatus] = a.pulledAt < b.pulledAt ? [left, right, a] : [right, left, b];
97
+ const fix = olderStatus.fileEdited
98
+ ? `mirror ${newer.file}'s side into it by hand (a re-pull would also drop its other edits since that pull)`
99
+ : `re-pull it with ${repull(older)} before hand-editing either`;
100
+ return `${sides}, and ${older.file} was pulled before ${newer.file}, so ${older.file} is the likely stale side: ${fix}.`;
101
+ }
102
+ return `${sides}, so which side is stale isn't known; compare both with the platform before changing either.`;
103
+ }
28
104
  /**
29
105
  * A relationship between two managed roots is two platform records, one per side, whose columns the platform
30
106
  * mirrors: changing one side changes the other. Each side lives in its owner's source, so the two must mirror
31
- * each other or the next plan reverts a one-sided edit. Returns one error per root pair that disagrees.
107
+ * each other or the next plan reverts a one-sided edit. Returns one failure per root pair that disagrees,
108
+ * naming both source files and which one differs from its last pull when that is known (edk#2430).
32
109
  */
33
- export function relationshipPairErrors(blocks) {
34
- const sides = blocks
35
- .filter((block) => block.kind === "resource" && block.type === RELATIONSHIP_RESOURCE_TYPE)
36
- .map(sideOf)
37
- .filter((side) => side !== undefined);
110
+ export function relationshipPairErrors(roots) {
111
+ const sides = roots.flatMap((root) => root.blocks
112
+ .filter(isRelationshipBlock)
113
+ .map((block) => sideOf(block, root))
114
+ .filter((side) => side !== undefined));
38
115
  const byPair = new Map();
39
116
  for (const side of sides) {
40
- const pair = [side.owner, side.target].sort().join(" <> ");
117
+ const pair = pairKey(side.owner, side.target);
41
118
  byPair.set(pair, [...(byPair.get(pair) ?? []), side]);
42
119
  }
43
- const errors = [];
120
+ const failures = [];
44
121
  for (const [pair, pairSides] of byPair) {
45
122
  const [first] = pair.split(" <> ");
46
123
  const a = pairSides.filter((side) => side.owner === first);
@@ -51,18 +128,28 @@ export function relationshipPairErrors(blocks) {
51
128
  const keysB = b.map((side) => joinKey(side, first)).sort();
52
129
  if (keysA.join(" | ") === keysB.join(" | "))
53
130
  continue;
131
+ const [left, right] = [a[0], b[0]];
132
+ const address = `${RELATIONSHIP_RESOURCE_TYPE}.${left.label}`;
133
+ const stale = staleness(left, right);
54
134
  if (a.length === 1 && b.length === 1) {
55
- const [left, right] = [a[0], b[0]];
56
135
  const mirrored = `[${left.columns.map(([own, related]) => `${related} ↔ ${own}`).join(", ")}]`;
57
- errors.push(`relationship ${left.label} joins ${describe(left)} but its counterpart ${right.label} joins ${describe(right)}. ` +
58
- `The platform mirrors the two sides, so change both: ${right.label} should join ${mirrored} ` +
59
- `(or ${left.label} should mirror ${right.label}).`);
136
+ failures.push({
137
+ address,
138
+ name: left.label,
139
+ message: `relationship ${left.label} (${left.root.file}) joins ${describe(left)} but its counterpart ${right.label} (${right.root.file}) joins ${describe(right)}. ` +
140
+ `The platform mirrors the two sides, so change both: ${right.label} should join ${mirrored} ` +
141
+ `(or ${left.label} should mirror ${right.label}). ${stale}`,
142
+ });
60
143
  }
61
144
  else {
62
- errors.push(`relationships between ${a[0].owner} and ${b[0].owner} don't mirror each other: ` +
63
- `${a.map((side) => `${side.label} ${describe(side)}`).join("; ")} vs ` +
64
- `${b.map((side) => `${side.label} ${describe(side)}`).join("; ")}. The platform mirrors the two sides, so change both.`);
145
+ failures.push({
146
+ address,
147
+ name: left.label,
148
+ message: `relationships between ${left.owner} (${left.root.file}) and ${right.owner} (${right.root.file}) don't mirror each other: ` +
149
+ `${a.map((side) => `${side.label} ${describe(side)}`).join("; ")} vs ` +
150
+ `${b.map((side) => `${side.label} ${describe(side)}`).join("; ")}. The platform mirrors the two sides, so change both. ${stale}`,
151
+ });
65
152
  }
66
153
  }
67
- return errors;
154
+ return failures;
68
155
  }
@@ -4,6 +4,7 @@ import { filterToTf } from "../access-policy/to-tf.js";
4
4
  import { foreignFieldDataLabel, resolveForeignRef } from "../shared/foreign-ref.js";
5
5
  import { authoredFieldKeysFromPayload, droppedEntryGap, fieldLookupName, fieldRefToTfValue, skippedResourceGap, unauthoredSiblingFieldRef, UNRESOLVED_FIELD_REF, } from "../field/to-tf.js";
6
6
  import { SYSTEM_FIELD_ID_ATTR_BY_KEY } from "../view/types.js";
7
+ import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
7
8
  import { autoRelationColumnError } from "./column-contract.js";
8
9
  import { RELATIONSHIP_RESOURCE_TYPE } from "./module.js";
9
10
  import { EntityTfError } from "../../engine/entity.js";
@@ -120,8 +121,10 @@ function resolveOwnerField(value, where, opts) {
120
121
  return undefined;
121
122
  }
122
123
  if (typeof value === "string") {
123
- if (opts.scope === "element" && value !== "id" && value !== "title") {
124
- opts.diagnostics.push(`${where}: element relationships only support system fields "id" and "title"; dropped`);
124
+ // An element's audit keys build to its platform audit field (#2513); the
125
+ // audit-field guard refuses them on an element without audit fields.
126
+ if (opts.scope === "element" && !ELEMENT_SYSTEM_FIELD_KEYS.includes(value)) {
127
+ opts.diagnostics.push(`${where}: element relationships only support system fields ${ELEMENT_SYSTEM_FIELD_KEYS.map((key) => `"${key}"`).join(", ")}; dropped`);
125
128
  return undefined;
126
129
  }
127
130
  const attr = SYSTEM_FIELD_ID_ATTR_BY_KEY.get(value);
@@ -0,0 +1,7 @@
1
+ import type { RolePermission } from "./build.js";
2
+ /**
3
+ * Why a role permission's level can't be used with its group, or undefined
4
+ * when it can. CUSTOM, NONE and groups the table doesn't list are left to
5
+ * the provider, as it does.
6
+ */
7
+ export declare function rolePermissionLevelError(permission: RolePermission): string | undefined;
@@ -0,0 +1,78 @@
1
+ // Which levels each app/element role permission group stores as written
2
+ // (edk#2133). The provider refuses any other level at plan, so the build
3
+ // refuses it first. These are copies of the provider's tables in
4
+ // provider/internal/provider/role_resource.go, where the reasons for each
5
+ // entry are: MAX_LEVEL_BY_GROUP = MaxPermissionLevelByGroup,
6
+ // MIN_LEVEL_BY_GROUP = MinPermissionLevelByGroup and UNSTORED_LEVEL_BY_GROUP
7
+ // = UnstoredPermissionLevelByGroup. The exporter,
8
+ // cmd/elementum/export/hcl_role.go, has its own copies of the max and
9
+ // unstored tables only; the minimum table exists in the provider and here.
10
+ // Change all copies together.
11
+ const LEVEL_RANK = { NONE: 0, VIEW: 1, EDIT: 2, ADMIN: 3 };
12
+ const MAX_LEVEL_BY_GROUP = {
13
+ AGENTS: "ADMIN",
14
+ AI_PROVIDERS: "ADMIN",
15
+ ANALYTICS: "ADMIN",
16
+ APPS: "ADMIN",
17
+ ATTACHMENTS: "EDIT",
18
+ AUTOMATIONS: "ADMIN",
19
+ CONVERSATIONS: "ADMIN",
20
+ RECORDS: "ADMIN",
21
+ RELATIONSHIPS: "ADMIN",
22
+ SERVICES: "ADMIN",
23
+ SLAS: "ADMIN",
24
+ USERS: "ADMIN",
25
+ };
26
+ const MIN_LEVEL_BY_GROUP = {
27
+ AGENTS: "EDIT",
28
+ AI_PROVIDERS: "ADMIN",
29
+ AUTOMATIONS: "EDIT",
30
+ RELATIONSHIPS: "EDIT",
31
+ };
32
+ const UNSTORED_LEVEL_BY_GROUP = {
33
+ ATTACHMENTS: { ADMIN: "EDIT" },
34
+ SLAS: { EDIT: "VIEW" },
35
+ };
36
+ /** An unknown level ranks as NONE, as in the provider's `levelRank[level]` lookup. */
37
+ function rank(level) {
38
+ return LEVEL_RANK[level] ?? 0;
39
+ }
40
+ /** The non-NONE levels a group stores as written, e.g. "VIEW or ADMIN". */
41
+ function supportedLevels(group) {
42
+ const levels = ["VIEW", "EDIT", "ADMIN"].filter((level) => {
43
+ const max = MAX_LEVEL_BY_GROUP[group];
44
+ const min = MIN_LEVEL_BY_GROUP[group];
45
+ if (max !== undefined && rank(level) > rank(max))
46
+ return false;
47
+ if (min !== undefined && rank(level) < rank(min))
48
+ return false;
49
+ return UNSTORED_LEVEL_BY_GROUP[group]?.[level] === undefined;
50
+ });
51
+ return levels.length < 2 ? levels.join("") : `${levels.slice(0, -1).join(", ")} or ${levels[levels.length - 1]}`;
52
+ }
53
+ /**
54
+ * Why a role permission's level can't be used with its group, or undefined
55
+ * when it can. CUSTOM, NONE and groups the table doesn't list are left to
56
+ * the provider, as it does.
57
+ */
58
+ export function rolePermissionLevelError(permission) {
59
+ const group = permission.group;
60
+ const level = permission.level;
61
+ if (level === "CUSTOM" || level === "NONE")
62
+ return undefined;
63
+ const max = MAX_LEVEL_BY_GROUP[group];
64
+ if (max === undefined)
65
+ return undefined;
66
+ const storedAs = UNSTORED_LEVEL_BY_GROUP[group]?.[level];
67
+ if (storedAs !== undefined) {
68
+ return `${group} supports ${supportedLevels(group)}; ${level} is stored as ${storedAs}, so the plan would never converge`;
69
+ }
70
+ const min = MIN_LEVEL_BY_GROUP[group];
71
+ if (min !== undefined && rank(level) > rank("NONE") && rank(level) < rank(min)) {
72
+ return `${group} grants nothing below ${min}, so ${level} would be stored as NONE; use NONE or at least ${min} (${group} supports ${supportedLevels(group)})`;
73
+ }
74
+ if (rank(level) > rank(max)) {
75
+ return `${group} goes up to ${max}, not ${level} (${group} supports ${supportedLevels(group)})`;
76
+ }
77
+ return undefined;
78
+ }
@@ -3,6 +3,8 @@ import { ROLE_RESOURCE_TYPE } from "../org/role.js";
3
3
  import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "../service-account/module.js";
4
4
  import { serviceAccountRefToTf } from "../service-account/to-tf.js";
5
5
  import { describeDroppedEntry, finishMemberList } from "../access-policy/member-list.js";
6
+ import { currentValidationMode, recordValidations, ValidationFailureError } from "../../engine/validation.js";
7
+ import { rolePermissionLevelError } from "./permission-levels.js";
6
8
  function principals(values, type, where, orgRefs, diagnostics) {
7
9
  if (values === undefined)
8
10
  return undefined;
@@ -37,7 +39,9 @@ function principals(values, type, where, orgRefs, diagnostics) {
37
39
  return finishMemberList(where, out, dropped, diagnostics);
38
40
  }
39
41
  export function rolesToTf(roles, opts) {
40
- return Object.entries(roles ?? {}).map(([key, role]) => {
42
+ const invalidRoles = [];
43
+ const blocks = Object.entries(roles ?? {}).map(([key, role]) => {
44
+ const label = scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), opts.scope);
41
45
  const attrs = { object_id: opts.objectId, name: role.name };
42
46
  if (role.description !== undefined)
43
47
  attrs["description"] = role.description;
@@ -79,6 +83,24 @@ export function rolesToTf(roles, opts) {
79
83
  if (serviceAccountIds !== undefined)
80
84
  attrs["service_account_ids"] = serviceAccountIds;
81
85
  }
86
+ if (role.permissions !== undefined) {
87
+ // A level the group doesn't store as written fails plan in the
88
+ // provider; fail the build first, one finding per role, so a single
89
+ // build names every bad role (edk#2133).
90
+ const invalid = role.permissions.flatMap((permission) => {
91
+ const error = rolePermissionLevelError(permission);
92
+ return error === undefined ? [] : [`${permission.group} ${permission.level}: ${error}`];
93
+ });
94
+ if (invalid.length > 0) {
95
+ invalidRoles.push({
96
+ severity: "fatal",
97
+ address: `${ROLE_RESOURCE_TYPE}.${label}`,
98
+ name: role.name,
99
+ ownerKind: "role",
100
+ message: `roles.${key}.permissions (${opts.ownerRefName}): ${invalid.length === 1 ? "this permission level is" : "these permission levels are"} not valid for the group, so plan would fail: ${invalid.join(" | ")}`,
101
+ });
102
+ }
103
+ }
82
104
  if (role.permissions !== undefined)
83
105
  attrs["permissions"] = [...role.permissions].sort((a, b) => a.group.localeCompare(b.group)).map((permission) => ({
84
106
  group: permission.group,
@@ -88,8 +110,16 @@ export function rolesToTf(roles, opts) {
88
110
  return {
89
111
  kind: "resource",
90
112
  type: ROLE_RESOURCE_TYPE,
91
- label: scopedResourceLabel(opts.ownerTfLabel, tsLabelToTfLabel(key), opts.scope),
113
+ label,
92
114
  attrs,
93
115
  };
94
116
  });
117
+ if (invalidRoles.length > 0) {
118
+ // In a build or pull session the findings are collected with the rest; outside one, fail closed.
119
+ if (currentValidationMode() !== undefined)
120
+ recordValidations(invalidRoles);
121
+ else
122
+ throw new ValidationFailureError(invalidRoles);
123
+ }
124
+ return blocks;
95
125
  }
@@ -1,4 +1,5 @@
1
1
  import { type EntityKindModule } from "../../graph/types.js";
2
- export declare const SERVICE_ACCOUNT_RESOURCE_TYPE = "elementum_service_account";
2
+ import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "./resource-type.js";
3
+ export { SERVICE_ACCOUNT_RESOURCE_TYPE };
3
4
  export declare const SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE = "elementum_service_account_access_policy";
4
5
  export declare const serviceAccountModule: EntityKindModule;
@@ -1,6 +1,8 @@
1
1
  import { NO_CANVAS, NO_CATALOG, NO_LIFECYCLE } from "../../graph/types.js";
2
2
  import { GROUP_RESOURCE_TYPE } from "../org/group.js";
3
- export const SERVICE_ACCOUNT_RESOURCE_TYPE = "elementum_service_account";
3
+ import { roleServiceAccountMembershipErrors } from "./role-membership-check.js";
4
+ import { SERVICE_ACCOUNT_RESOURCE_TYPE } from "./resource-type.js";
5
+ export { SERVICE_ACCOUNT_RESOURCE_TYPE };
4
6
  export const SERVICE_ACCOUNT_ACCESS_POLICY_RESOURCE_TYPE = "elementum_service_account_access_policy";
5
7
  export const serviceAccountModule = {
6
8
  kind: "service-account",
@@ -19,6 +21,12 @@ export const serviceAccountModule = {
19
21
  lifecycle: NO_LIFECYCLE,
20
22
  canvas: NO_CANVAS,
21
23
  catalog: NO_CATALOG,
24
+ buildChecks: { validateBuiltRoots: roleServiceAccountMembershipErrors },
25
+ roundtrip: {
26
+ referenceAliases: [],
27
+ // Provider set attributes (edk#2437): order carries no meaning.
28
+ unorderedListAttributes: ["role_ids", "user_ids", "group_ids"],
29
+ },
22
30
  // The platform's own policy names the account's creator, a user, so it is
23
31
  // always dropped; a group-only policy is kept when every group is mapped.
24
32
  portable: {
@@ -0,0 +1,2 @@
1
+ /** The service-account resource type, in a leaf module so build checks can import it without a cycle through module.ts. */
2
+ export declare const SERVICE_ACCOUNT_RESOURCE_TYPE = "elementum_service_account";
@@ -0,0 +1,2 @@
1
+ /** The service-account resource type, in a leaf module so build checks can import it without a cycle through module.ts. */
2
+ export const SERVICE_ACCOUNT_RESOURCE_TYPE = "elementum_service_account";
@@ -18,8 +18,8 @@ interface ExtractedServiceAccountRoles {
18
18
  readonly roles?: readonly ServiceAccountRole[];
19
19
  }
20
20
  /**
21
- * Order-sensitive comparison of each owned service account's export
22
- * `role_ids` with the roles written into source. Named roles compare by
21
+ * Order-insensitive comparison (`role_ids` is a set, edk#2437) of each owned
22
+ * service account's export `role_ids` with the roles written into source. Named roles compare by
23
23
  * display name; raw ids compare by platform id. A value the printer cannot
24
24
  * represent is a disagreement, not a quiet omission.
25
25
  */
@@ -36,9 +36,9 @@ export interface RebuiltServiceAccountRoleLookup {
36
36
  readonly resourceRoleNames: ReadonlyMap<string, string>;
37
37
  }
38
38
  /**
39
- * Same order-sensitive rule, against service-account blocks rebuilt from
40
- * the pulled `.ts`. A printer or to-tf that drops or reorders a raw id
41
- * disagrees here even when extract mirrored the export.
39
+ * Same membership rule, against service-account blocks rebuilt from the
40
+ * pulled `.ts`. A printer or to-tf that drops or changes a raw id disagrees
41
+ * here even when extract mirrored the export.
42
42
  * When `lookup` is set, rebuilt refs resolve through it. Export refs still
43
43
  * use `ctx` and the export blocks.
44
44
  */
@@ -72,16 +72,24 @@ function mismatchLine(where, index, exported, generated, sourceFile, key) {
72
72
  return `${SERVICE_ACCOUNT_ROLE_MISMATCH_PREFIX} ${where}.role_ids[${index}] export ${identityText(exported)} vs generated ${identityText(generated)}; ${nextStep(sourceFile, key, index)}`;
73
73
  }
74
74
  function compareRoleLists(where, key, sourceFile, exported, generated, out) {
75
+ // `role_ids` is a set in the provider (edk#2437), so compare membership,
76
+ // not position: each role pairs with one equal role on the other side, and
77
+ // an unpaired role on either side is a disagreement. A duplicate still shows.
75
78
  if (exported.length === 0 && generated.length === 0)
76
79
  return;
77
- const count = Math.max(exported.length, generated.length);
78
- for (let index = 0; index < count; index += 1) {
79
- const left = exported[index];
80
- const right = generated[index];
81
- if (left !== undefined && right !== undefined && sameIdentity(left, right))
82
- continue;
83
- out.push(mismatchLine(where, index, left, right, sourceFile, key));
84
- }
80
+ const paired = new Set();
81
+ exported.forEach((left, index) => {
82
+ const match = generated.findIndex((right, at) => !paired.has(at) && sameIdentity(left, right));
83
+ if (match >= 0) {
84
+ paired.add(match);
85
+ return;
86
+ }
87
+ out.push(mismatchLine(where, index, left, undefined, sourceFile, key));
88
+ });
89
+ generated.forEach((right, index) => {
90
+ if (!paired.has(index))
91
+ out.push(mismatchLine(where, index, undefined, right, sourceFile, key));
92
+ });
85
93
  }
86
94
  function roleListFromRebuild(value, dataQueues, resourceRoleNames) {
87
95
  if (value === undefined)
@@ -123,8 +131,8 @@ function describedRoleIds(value) {
123
131
  return value.map((item) => describeRoleValue(item)).join(", ");
124
132
  }
125
133
  /**
126
- * Order-sensitive comparison of each owned service account's export
127
- * `role_ids` with the roles written into source. Named roles compare by
134
+ * Order-insensitive comparison (`role_ids` is a set, edk#2437) of each owned
135
+ * service account's export `role_ids` with the roles written into source. Named roles compare by
128
136
  * display name; raw ids compare by platform id. A value the printer cannot
129
137
  * represent is a disagreement, not a quiet omission.
130
138
  */
@@ -132,9 +140,9 @@ export function serviceAccountRoleIdMismatches(blocks, accounts, owner, ctx) {
132
140
  return compareServiceAccountRoleIds(blocks, accounts, owner, ctx);
133
141
  }
134
142
  /**
135
- * Same order-sensitive rule, against service-account blocks rebuilt from
136
- * the pulled `.ts`. A printer or to-tf that drops or reorders a raw id
137
- * disagrees here even when extract mirrored the export.
143
+ * Same membership rule, against service-account blocks rebuilt from the
144
+ * pulled `.ts`. A printer or to-tf that drops or changes a raw id disagrees
145
+ * here even when extract mirrored the export.
138
146
  * When `lookup` is set, rebuilt refs resolve through it. Export refs still
139
147
  * use `ctx` and the export blocks.
140
148
  */
@@ -0,0 +1,20 @@
1
+ import type { BuildCheckFailure, BuiltRootSource } from "../../graph/types.js";
2
+ /**
3
+ * A role's `service_account_ids` and a service account's `role_ids` write the
4
+ * same membership. When both lists are set and disagree about one role and
5
+ * one account, each apply undoes the other forever (edk#2159), so the build
6
+ * stops and names both. Agreement is left alone: on one app both sides naming
7
+ * each other is a dependency cycle that tofu already reports.
8
+ *
9
+ * A role list never holds a raw id (build resolves every account it names), but
10
+ * an account's `role_ids` can (pull keeps another app's role as
11
+ * `unsafePlatformId`), and this check can't tell which role a raw id is. So a
12
+ * role that lists the account is not reported against an account list holding
13
+ * raw ids, and an account list made only of raw ids never names a role here:
14
+ * it is not compared, including when the role's list leaves that account out.
15
+ *
16
+ * The fix-it text says which property to leave off, chosen by which side
17
+ * claims the membership. Leaving a list off is not the same as `[]` (#2124),
18
+ * and naming the membership on both sides is a dependency cycle on one app.
19
+ */
20
+ export declare function roleServiceAccountMembershipErrors(roots: readonly BuiltRootSource[]): BuildCheckFailure[];