@elementumai/edk 0.8.0-preview.11 → 0.8.2-alpha.5

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 (180) hide show
  1. package/README.md +510 -324
  2. package/dist-sdk/src/catalog/ai-provider-models.d.ts +30 -0
  3. package/dist-sdk/src/catalog/ai-provider-models.js +63 -0
  4. package/dist-sdk/src/catalog/factories.d.ts +56 -3
  5. package/dist-sdk/src/catalog/factories.js +83 -4
  6. package/dist-sdk/src/catalog/from-authoring.js +19 -2
  7. package/dist-sdk/src/catalog/index.d.ts +3 -2
  8. package/dist-sdk/src/catalog/index.js +3 -2
  9. package/dist-sdk/src/catalog/org.d.ts +1 -1
  10. package/dist-sdk/src/catalog/org.js +134 -50
  11. package/dist-sdk/src/catalog/render.d.ts +13 -1
  12. package/dist-sdk/src/catalog/render.js +21 -4
  13. package/dist-sdk/src/catalog/token.js +18 -0
  14. package/dist-sdk/src/catalog/types.d.ts +75 -3
  15. package/dist-sdk/src/catalog/types.js +3 -0
  16. package/dist-sdk/src/core/system-fields.d.ts +2 -0
  17. package/dist-sdk/src/core/system-fields.js +2 -0
  18. package/dist-sdk/src/core/types/ai-provider.d.ts +10 -23
  19. package/dist-sdk/src/core/types/ai-provider.js +1 -25
  20. package/dist-sdk/src/core/types/app.d.ts +26 -1
  21. package/dist-sdk/src/engine/build/context.d.ts +58 -0
  22. package/dist-sdk/src/engine/build/context.js +11 -1
  23. package/dist-sdk/src/engine/build/source-context.d.ts +45 -0
  24. package/dist-sdk/src/engine/build/source-context.js +23 -0
  25. package/dist-sdk/src/engine/pull/context.d.ts +15 -0
  26. package/dist-sdk/src/engine/pull/org.d.ts +10 -0
  27. package/dist-sdk/src/engine/pull/org.js +34 -4
  28. package/dist-sdk/src/engine/tf/index.d.ts +2 -2
  29. package/dist-sdk/src/engine/tf/index.js +2 -2
  30. package/dist-sdk/src/engine/tf/labels.d.ts +54 -0
  31. package/dist-sdk/src/engine/tf/labels.js +75 -0
  32. package/dist-sdk/src/engine/tf/parse.d.ts +15 -0
  33. package/dist-sdk/src/engine/tf/parse.js +162 -0
  34. package/dist-sdk/src/entities/access-policy/build.d.ts +26 -0
  35. package/dist-sdk/src/entities/access-policy/build.js +7 -0
  36. package/dist-sdk/src/entities/access-policy/filter.d.ts +61 -0
  37. package/dist-sdk/src/entities/access-policy/filter.js +83 -0
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +66 -0
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +187 -0
  40. package/dist-sdk/src/entities/access-policy/module.d.ts +3 -0
  41. package/dist-sdk/src/entities/access-policy/module.js +17 -0
  42. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +43 -0
  43. package/dist-sdk/src/entities/access-policy/to-tf.js +164 -0
  44. package/dist-sdk/src/entities/access-policy/types.d.ts +4 -0
  45. package/dist-sdk/src/entities/access-policy/types.js +10 -0
  46. package/dist-sdk/src/entities/agent/build.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent/build.js +1 -0
  48. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.d.ts +38 -3
  49. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +257 -32
  50. package/dist-sdk/src/entities/agent/from-tf.d.ts +29 -9
  51. package/dist-sdk/src/entities/agent/from-tf.js +146 -19
  52. package/dist-sdk/src/entities/agent/index.d.ts +1 -1
  53. package/dist-sdk/src/entities/agent/module.js +14 -4
  54. package/dist-sdk/src/entities/agent/to-tf.d.ts +46 -1
  55. package/dist-sdk/src/entities/agent/to-tf.js +160 -14
  56. package/dist-sdk/src/entities/agent/tools.d.ts +88 -9
  57. package/dist-sdk/src/entities/agent/tools.js +46 -7
  58. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.d.ts +17 -0
  59. package/dist-sdk/src/entities/agent-a2a-skill/from-tf.js +64 -0
  60. package/dist-sdk/src/entities/agent-a2a-skill/module.d.ts +4 -0
  61. package/dist-sdk/src/entities/agent-a2a-skill/module.js +14 -0
  62. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.d.ts +40 -0
  63. package/dist-sdk/src/entities/agent-a2a-skill/to-tf.js +47 -0
  64. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +51 -4
  65. package/dist-sdk/src/entities/agent-tool/from-tf.js +131 -35
  66. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +11 -4
  67. package/dist-sdk/src/entities/agent-tool/to-tf.js +176 -30
  68. package/dist-sdk/src/entities/agent-tool/types.d.ts +5 -4
  69. package/dist-sdk/src/entities/agent-tool/types.js +38 -6
  70. package/dist-sdk/src/entities/app/build.d.ts +91 -13
  71. package/dist-sdk/src/entities/app/build.js +63 -5
  72. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +3 -0
  73. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -1
  74. package/dist-sdk/src/entities/app/from-tf.js +32 -22
  75. package/dist-sdk/src/entities/app/index.d.ts +4 -1
  76. package/dist-sdk/src/entities/app/index.js +2 -1
  77. package/dist-sdk/src/entities/app/module.js +10 -2
  78. package/dist-sdk/src/entities/app/to-tf.d.ts +5 -0
  79. package/dist-sdk/src/entities/app/to-tf.js +45 -4
  80. package/dist-sdk/src/entities/automation/build.d.ts +57 -13
  81. package/dist-sdk/src/entities/automation/build.js +62 -42
  82. package/dist-sdk/src/entities/automation/deserializer/ast.d.ts +25 -8
  83. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +16 -1
  84. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +206 -47
  85. package/dist-sdk/src/entities/automation/filter.d.ts +37 -3
  86. package/dist-sdk/src/entities/automation/filter.js +54 -3
  87. package/dist-sdk/src/entities/automation/from-tf.d.ts +26 -27
  88. package/dist-sdk/src/entities/automation/from-tf.js +1344 -222
  89. package/dist-sdk/src/entities/automation/index.d.ts +4 -0
  90. package/dist-sdk/src/entities/automation/index.js +4 -0
  91. package/dist-sdk/src/entities/automation/module.js +29 -32
  92. package/dist-sdk/src/entities/automation/operators.d.ts +29 -2
  93. package/dist-sdk/src/entities/automation/operators.js +27 -1
  94. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +19 -0
  95. package/dist-sdk/src/entities/automation/output-key-wire-name.js +24 -0
  96. package/dist-sdk/src/entities/automation/script-code.d.ts +10 -21
  97. package/dist-sdk/src/entities/automation/script-code.js +272 -5
  98. package/dist-sdk/src/entities/automation/tasks.d.ts +125 -19
  99. package/dist-sdk/src/entities/automation/tasks.js +83 -15
  100. package/dist-sdk/src/entities/automation/to-tf.d.ts +10 -29
  101. package/dist-sdk/src/entities/automation/to-tf.js +1291 -230
  102. package/dist-sdk/src/entities/automation/triggers.d.ts +9 -1
  103. package/dist-sdk/src/entities/automation/types.d.ts +29 -4
  104. package/dist-sdk/src/entities/automation/types.js +76 -46
  105. package/dist-sdk/src/entities/element/build.d.ts +44 -13
  106. package/dist-sdk/src/entities/element/build.js +45 -3
  107. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -1
  108. package/dist-sdk/src/entities/element/from-tf.js +28 -14
  109. package/dist-sdk/src/entities/element/index.d.ts +4 -1
  110. package/dist-sdk/src/entities/element/index.js +2 -1
  111. package/dist-sdk/src/entities/element/module.js +4 -1
  112. package/dist-sdk/src/entities/element/to-tf.js +26 -3
  113. package/dist-sdk/src/entities/field/build.d.ts +61 -14
  114. package/dist-sdk/src/entities/field/build.js +10 -0
  115. package/dist-sdk/src/entities/field/calc/runtime.js +4 -0
  116. package/dist-sdk/src/entities/field/from-tf.d.ts +5 -3
  117. package/dist-sdk/src/entities/field/from-tf.js +118 -7
  118. package/dist-sdk/src/entities/field/module.js +3 -2
  119. package/dist-sdk/src/entities/field/to-tf.d.ts +46 -11
  120. package/dist-sdk/src/entities/field/to-tf.js +166 -17
  121. package/dist-sdk/src/entities/field/types.d.ts +26 -0
  122. package/dist-sdk/src/entities/field/types.js +34 -12
  123. package/dist-sdk/src/entities/file-reader/build.d.ts +108 -50
  124. package/dist-sdk/src/entities/file-reader/build.js +23 -23
  125. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.d.ts +6 -0
  126. package/dist-sdk/src/entities/file-reader/deserializer/print-file-reader.js +109 -0
  127. package/dist-sdk/src/entities/file-reader/from-tf.d.ts +13 -0
  128. package/dist-sdk/src/entities/file-reader/from-tf.js +172 -0
  129. package/dist-sdk/src/entities/file-reader/index.d.ts +8 -3
  130. package/dist-sdk/src/entities/file-reader/index.js +7 -2
  131. package/dist-sdk/src/entities/file-reader/module.d.ts +3 -0
  132. package/dist-sdk/src/entities/file-reader/module.js +115 -0
  133. package/dist-sdk/src/entities/file-reader/to-tf.d.ts +14 -0
  134. package/dist-sdk/src/entities/file-reader/to-tf.js +84 -0
  135. package/dist-sdk/src/entities/file-reader/types.d.ts +32 -0
  136. package/dist-sdk/src/entities/file-reader/types.js +30 -0
  137. package/dist-sdk/src/entities/org/ai-provider.d.ts +13 -0
  138. package/dist-sdk/src/entities/org/ai-provider.js +46 -0
  139. package/dist-sdk/src/entities/org/connector.d.ts +8 -1
  140. package/dist-sdk/src/entities/org/connector.js +12 -14
  141. package/dist-sdk/src/entities/org/group.js +10 -1
  142. package/dist-sdk/src/entities/org/index.d.ts +1 -0
  143. package/dist-sdk/src/entities/org/index.js +1 -0
  144. package/dist-sdk/src/entities/org/user.js +10 -1
  145. package/dist-sdk/src/entities/shared/filters/ast.d.ts +59 -9
  146. package/dist-sdk/src/entities/shared/filters/types.d.ts +1 -1
  147. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +17 -0
  148. package/dist-sdk/src/entities/shared/tool-field-ref.js +46 -0
  149. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -1
  150. package/dist-sdk/src/entities/shared/types/field-types.js +9 -0
  151. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +19 -0
  152. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +128 -11
  153. package/dist-sdk/src/entities/skill/from-tf.js +4 -3
  154. package/dist-sdk/src/entities/skill/index.d.ts +1 -1
  155. package/dist-sdk/src/entities/skill/module.js +7 -1
  156. package/dist-sdk/src/entities/skill/to-tf.d.ts +26 -0
  157. package/dist-sdk/src/entities/skill/to-tf.js +65 -4
  158. package/dist-sdk/src/entities/skill/tools.d.ts +37 -8
  159. package/dist-sdk/src/entities/skill/tools.js +43 -1
  160. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +34 -4
  161. package/dist-sdk/src/entities/skill-tool/from-tf.js +128 -18
  162. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +13 -1
  163. package/dist-sdk/src/entities/skill-tool/to-tf.js +164 -25
  164. package/dist-sdk/src/entities/skill-tool/types.d.ts +5 -7
  165. package/dist-sdk/src/entities/skill-tool/types.js +47 -11
  166. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -2
  167. package/dist-sdk/src/entities/view/from-tf.js +11 -9
  168. package/dist-sdk/src/entities/view/to-tf.d.ts +9 -7
  169. package/dist-sdk/src/entities/view/to-tf.js +39 -18
  170. package/dist-sdk/src/entities/view/types.d.ts +1 -1
  171. package/dist-sdk/src/entities/view/types.js +1 -1
  172. package/dist-sdk/src/graph/deferred-catalog-render.d.ts +0 -5
  173. package/dist-sdk/src/graph/deferred-catalog-render.js +1 -20
  174. package/dist-sdk/src/graph/index.d.ts +8 -0
  175. package/dist-sdk/src/graph/index.js +13 -9
  176. package/dist-sdk/src/graph/modules.js +8 -1
  177. package/dist-sdk/src/graph/types.d.ts +98 -4
  178. package/package.json +49 -16
  179. package/dist-sdk/src/entities/automation/value-ref-tf.d.ts +0 -76
  180. package/dist-sdk/src/entities/automation/value-ref-tf.js +0 -190
@@ -44,6 +44,168 @@ export class TfParseError extends Error {
44
44
  }
45
45
  }
46
46
  const KNOWN_TOP_LEVEL = new Set(["resource", "data", "locals", "import", "provider", "terraform"]);
47
+ const BACKEND_TOP_LEVEL = new Set(["terraform", "variable", "locals"]);
48
+ const BACKEND_SECRET_KEYS = new Set([
49
+ "access_key",
50
+ "access_token",
51
+ "account_key",
52
+ "authorization",
53
+ "bearer_token",
54
+ "client_certificate",
55
+ "client_certificate_password",
56
+ "client_certificate_path",
57
+ "client_key",
58
+ "client_key_password",
59
+ "client_key_pem",
60
+ "client_key_path",
61
+ "client_secret",
62
+ "conn_str",
63
+ "credentials",
64
+ "credentials_file",
65
+ "credentials_json",
66
+ "encryption_key",
67
+ "id_token",
68
+ "password",
69
+ "private_key",
70
+ "private_key_path",
71
+ "sas_token",
72
+ "secret_access_key",
73
+ "secret_id",
74
+ "secret_key",
75
+ "shared_credentials_file",
76
+ "shared_credentials_files",
77
+ "sse_customer_key",
78
+ "token",
79
+ "username",
80
+ "web_identity_token",
81
+ "web_identity_token_file",
82
+ ]);
83
+ const ALWAYS_LOCKING_BACKENDS = new Set([
84
+ "azurerm",
85
+ "cos",
86
+ "gcs",
87
+ "kubernetes",
88
+ "pg",
89
+ "remote",
90
+ ]);
91
+ const SUPPORTED_LOCKING_BACKENDS = [
92
+ ...ALWAYS_LOCKING_BACKENDS,
93
+ "consul",
94
+ "http",
95
+ "oss",
96
+ "s3",
97
+ ].sort();
98
+ /**
99
+ * Validate the dedicated workspace backend source. Credential-bearing keys
100
+ * and the small set of backend-specific locking switches are policy-critical;
101
+ * every other backend argument stays opaque and is preserved verbatim.
102
+ *
103
+ * This deliberately reuses the ONE hcl2json entry point while bypassing the
104
+ * entity expression grammar: OpenTofu backend configuration may contain
105
+ * init-time `var.*`, `local.*`, and nested backend blocks that are not part of
106
+ * ei's entity dialect. The source is projected byte-for-byte after validation;
107
+ * OpenTofu remains the authority for backend-specific arguments.
108
+ */
109
+ export async function inspectBackendHcl(text) {
110
+ assertNoUnsafeIntegers(text);
111
+ let raw;
112
+ try {
113
+ raw = await parseWithHcl2Json("backend.tf", text);
114
+ }
115
+ catch (e) {
116
+ throw new TfParseError(`backend.tf HCL parse failed: ${e instanceof Error ? e.message : String(e)}`);
117
+ }
118
+ for (const key of Object.keys(raw)) {
119
+ if (!BACKEND_TOP_LEVEL.has(key)) {
120
+ throw new TfParseError(`backend.tf contains unsupported top-level "${key}" content — only terraform, variable, and locals blocks belong in the backend source`);
121
+ }
122
+ }
123
+ const rejectSecretKeys = (node, path = []) => {
124
+ if (Array.isArray(node)) {
125
+ for (const [index, child] of node.entries())
126
+ rejectSecretKeys(child, [...path, String(index)]);
127
+ return;
128
+ }
129
+ if (typeof node !== "object" || node === null)
130
+ return;
131
+ for (const [key, child] of Object.entries(node)) {
132
+ if (BACKEND_SECRET_KEYS.has(key.toLowerCase())) {
133
+ throw new TfParseError(`backend.tf contains credential-bearing "${[...path, key].join(".")}" configuration — ` +
134
+ "backend credentials must come from environment variables or workload identity");
135
+ }
136
+ rejectSecretKeys(child, [...path, key]);
137
+ }
138
+ };
139
+ rejectSecretKeys(raw);
140
+ const declarations = [];
141
+ const terraformBodies = raw["terraform"];
142
+ if (terraformBodies !== undefined && !Array.isArray(terraformBodies)) {
143
+ throw new TfParseError("backend.tf has an unexpected terraform block shape");
144
+ }
145
+ for (const [index, body] of (terraformBodies ?? []).entries()) {
146
+ if (typeof body !== "object" || body === null || Array.isArray(body)) {
147
+ throw new TfParseError(`backend.tf has an unexpected terraform block body at index ${index}`);
148
+ }
149
+ const nested = body["backend"];
150
+ if (nested === undefined)
151
+ continue;
152
+ if (typeof nested !== "object" || nested === null || Array.isArray(nested)) {
153
+ throw new TfParseError(`backend.tf has an unexpected backend declaration shape at terraform block ${index}`);
154
+ }
155
+ for (const [type, bodies] of Object.entries(nested)) {
156
+ if (!Array.isArray(bodies)) {
157
+ throw new TfParseError(`backend.tf has an unexpected backend "${type}" body shape`);
158
+ }
159
+ for (const body of bodies) {
160
+ if (typeof body !== "object" || body === null || Array.isArray(body)) {
161
+ throw new TfParseError(`backend.tf has an unexpected backend "${type}" body shape`);
162
+ }
163
+ declarations.push({ type, body: body });
164
+ }
165
+ }
166
+ }
167
+ if (declarations.length !== 1) {
168
+ throw new TfParseError(`backend.tf must contain exactly one backend declaration; found ${declarations.length}`);
169
+ }
170
+ const declaration = declarations[0];
171
+ assertLockingBackend(declaration.type, declaration.body);
172
+ return { type: declaration.type };
173
+ }
174
+ function assertLockingBackend(type, body) {
175
+ if (ALWAYS_LOCKING_BACKENDS.has(type))
176
+ return;
177
+ if (type === "consul") {
178
+ if (body["lock"] === undefined || body["lock"] === true || body["lock"] === "${true}")
179
+ return;
180
+ throw new TfParseError('backend "consul" must omit lock or set lock = true');
181
+ }
182
+ if (type === "http") {
183
+ if (hasLiteralBackendValue(body, "lock_address") && hasLiteralBackendValue(body, "unlock_address"))
184
+ return;
185
+ throw new TfParseError('backend "http" must configure both lock_address and unlock_address; HTTP state is otherwise unlocked');
186
+ }
187
+ if (type === "oss") {
188
+ if (hasLiteralBackendValue(body, "tablestore_endpoint") &&
189
+ hasLiteralBackendValue(body, "tablestore_table")) {
190
+ return;
191
+ }
192
+ throw new TfParseError('backend "oss" must configure tablestore_endpoint and tablestore_table for state locking');
193
+ }
194
+ if (type === "s3") {
195
+ if (body["use_lockfile"] === true ||
196
+ body["use_lockfile"] === "${true}" ||
197
+ hasLiteralBackendValue(body, "dynamodb_table")) {
198
+ return;
199
+ }
200
+ throw new TfParseError('backend "s3" must set use_lockfile = true or configure dynamodb_table for state locking');
201
+ }
202
+ throw new TfParseError(`backend "${type}" is not accepted because EDK cannot verify state locking; supported locking backends: ` +
203
+ SUPPORTED_LOCKING_BACKENDS.join(", "));
204
+ }
205
+ function hasLiteralBackendValue(body, key) {
206
+ const value = body[key];
207
+ return typeof value === "string" && value !== "" && !value.startsWith("${");
208
+ }
47
209
  export async function parseHcl(text) {
48
210
  assertNoUnsafeIntegers(text);
49
211
  let raw;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Access-policy authoring options — the `accessPolicies: [...]` array shared
3
+ * by `defineApp`/`defineElement` (`entities/app/build.ts` /
4
+ * `entities/element/build.ts`). Kept here, not duplicated per parent, since
5
+ * both parents accept the identical shape.
6
+ */
7
+ import type { GroupRef } from "../../catalog/index.js";
8
+ import type { AccessPolicyPrincipalRef } from "./from-tf.js";
9
+ import type { AccessPolicyFilter } from "./filter.js";
10
+ /**
11
+ * A principal (user/group) reference: a raw platform id — EDK has no
12
+ * `org.users` catalog bag to reference a user by handle (see
13
+ * `entities/org/user.ts`) — or, for groups only, a real `org.groups.<key>`
14
+ * catalog token. `AccessPolicyPrincipalRef` is the pulled-source echo (see
15
+ * that type's own doc comment) — round-tripped, not meant to be hand-authored.
16
+ */
17
+ export type AccessPolicyUserRef = string | AccessPolicyPrincipalRef;
18
+ export type AccessPolicyGroupRef = string | GroupRef | AccessPolicyPrincipalRef;
19
+ export interface AccessPolicyOptions {
20
+ /** Row-level-security predicate. Omit for the platform default (matches every record). */
21
+ readonly filter?: AccessPolicyFilter;
22
+ readonly userIds?: readonly AccessPolicyUserRef[];
23
+ readonly groupIds?: readonly AccessPolicyGroupRef[];
24
+ /** Always raw platform ids — ei's exporter carries no `elementum_service_account` resource to reference yet. */
25
+ readonly serviceAccountIds?: readonly string[];
26
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Access-policy authoring options — the `accessPolicies: [...]` array shared
3
+ * by `defineApp`/`defineElement` (`entities/app/build.ts` /
4
+ * `entities/element/build.ts`). Kept here, not duplicated per parent, since
5
+ * both parents accept the identical shape.
6
+ */
7
+ export {};
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Access-policy filter helpers — build the platform's wire `Filter` shape.
3
+ *
4
+ * Unlike automation's filter DSL (`entities/automation/filter.ts`), an access
5
+ * policy's filter has no trigger/task context to reference — it is always a
6
+ * plain row-level-security predicate over the OWNING app/element's own
7
+ * fields (confirmed by the frozen provider schema: `elementum_access_policy`
8
+ * carries `object_id` + `filter` + principal lists, nothing else). So the
9
+ * left-hand side of every operator is always a `FieldRef` catalog token —
10
+ * there is no `Ref`/`leftValue` row-less mode to support, and no user-directory
11
+ * field scope either (that's a distinct concept used elsewhere, e.g. approval
12
+ * chains — access policies filter the aspect's own records, never a fixed
13
+ * user-directory attribute).
14
+ *
15
+ * Operator/value-type coverage matches what `entities/automation/from-tf.ts`'s
16
+ * `decodeFilter` can round-trip (true/false/and/or/is_null/in/between/eq/gt/
17
+ * gte/lt/lte/like; text/number/boolean/null/current_user/field values) — this
18
+ * repo has no wider working filter-grammar implementation to match.
19
+ */
20
+ import type { FieldRef } from "../../catalog/index.js";
21
+ import type { LikeMode } from "../shared/filters/index.js";
22
+ /** A wire filter (embeds `FieldRef` tokens at `field` positions). */
23
+ export type AccessPolicyFilter = Record<string, unknown>;
24
+ type Primitive = string | number | boolean | null;
25
+ /**
26
+ * Marker produced by {@link currentUser} — compares against the acting
27
+ * user's id/email/domain rather than a literal value.
28
+ */
29
+ export interface CurrentUserFilterValue {
30
+ readonly __kind: "currentUser";
31
+ readonly currentUserType: "id" | "email" | "domain";
32
+ }
33
+ export type AccessPolicyFilterValue = Primitive | FieldRef | CurrentUserFilterValue;
34
+ /** Compare against the current (acting) user — id by default. */
35
+ export declare function currentUser(type?: "id" | "email" | "domain"): CurrentUserFilterValue;
36
+ /** Match every record (the minimal valid filter — the default when a policy has none configured). */
37
+ export declare function whereTrue(): AccessPolicyFilter;
38
+ /** Match no record. */
39
+ export declare function whereFalse(): AccessPolicyFilter;
40
+ export declare function eq(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
41
+ export declare function neq(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
42
+ export declare function gt(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
43
+ export declare function gte(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
44
+ export declare function lt(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
45
+ export declare function lte(field: FieldRef, v: AccessPolicyFilterValue): AccessPolicyFilter;
46
+ export declare function like(field: FieldRef, v: string, options?: {
47
+ readonly not?: boolean;
48
+ readonly caseInsensitive?: boolean;
49
+ readonly mode?: LikeMode;
50
+ }): AccessPolicyFilter;
51
+ export declare function isNull(field: FieldRef, options?: {
52
+ readonly not?: boolean;
53
+ }): AccessPolicyFilter;
54
+ export declare function isNotNull(field: FieldRef): AccessPolicyFilter;
55
+ export declare function isIn(field: FieldRef, values: readonly AccessPolicyFilterValue[]): AccessPolicyFilter;
56
+ export declare function between(field: FieldRef, low: AccessPolicyFilterValue, high: AccessPolicyFilterValue, options?: {
57
+ readonly not?: boolean;
58
+ }): AccessPolicyFilter;
59
+ export declare function and(...children: AccessPolicyFilter[]): AccessPolicyFilter;
60
+ export declare function or(...children: AccessPolicyFilter[]): AccessPolicyFilter;
61
+ export {};
@@ -0,0 +1,83 @@
1
+ /** Compare against the current (acting) user — id by default. */
2
+ export function currentUser(type = "id") {
3
+ return { __kind: "currentUser", currentUserType: type };
4
+ }
5
+ function isCurrentUserValue(value) {
6
+ return typeof value === "object" && value !== null && value.__kind === "currentUser";
7
+ }
8
+ function isFieldValue(value) {
9
+ return typeof value === "object" && value !== null && value.__kind === "field";
10
+ }
11
+ /** Map a filter value to the platform's `Value` wire shape. */
12
+ function value(v) {
13
+ if (isCurrentUserValue(v))
14
+ return { type: "CURRENT_USER", currentUserType: v.currentUserType };
15
+ if (isFieldValue(v))
16
+ return { type: "FIELD", value: v };
17
+ if (v === null)
18
+ return { type: "NULL" };
19
+ if (typeof v === "number")
20
+ return { type: "NUMBER", value: v };
21
+ if (typeof v === "boolean")
22
+ return { type: "BOOLEAN", value: v };
23
+ return { type: "TEXT", value: v };
24
+ }
25
+ /** Match every record (the minimal valid filter — the default when a policy has none configured). */
26
+ export function whereTrue() {
27
+ return { type: "TRUE" };
28
+ }
29
+ /** Match no record. */
30
+ export function whereFalse() {
31
+ return { type: "FALSE" };
32
+ }
33
+ export function eq(field, v) {
34
+ return { type: "EQUALS", field, value: value(v) };
35
+ }
36
+ export function neq(field, v) {
37
+ return { type: "EQUALS", field, value: value(v), not: true };
38
+ }
39
+ export function gt(field, v) {
40
+ return { type: "GREATER_THAN", field, value: value(v) };
41
+ }
42
+ export function gte(field, v) {
43
+ return { type: "GREATER_THAN_EQUALS", field, value: value(v) };
44
+ }
45
+ export function lt(field, v) {
46
+ return { type: "LESS_THAN", field, value: value(v) };
47
+ }
48
+ export function lte(field, v) {
49
+ return { type: "LESS_THAN_EQUALS", field, value: value(v) };
50
+ }
51
+ export function like(field, v, options) {
52
+ return {
53
+ type: "LIKE",
54
+ field,
55
+ value: value(v),
56
+ ...(options?.not ? { not: true } : {}),
57
+ ...(options?.caseInsensitive !== undefined ? { caseInsensitive: options.caseInsensitive } : {}),
58
+ ...(options?.mode ? { mode: options.mode } : {}),
59
+ };
60
+ }
61
+ export function isNull(field, options) {
62
+ return { type: "IS_NULL", field, ...(options?.not ? { not: true } : {}) };
63
+ }
64
+ export function isNotNull(field) {
65
+ return isNull(field, { not: true });
66
+ }
67
+ export function isIn(field, values) {
68
+ return { type: "IN", field, values: values.map((v) => value(v)) };
69
+ }
70
+ export function between(field, low, high, options) {
71
+ return {
72
+ type: "BETWEEN",
73
+ field,
74
+ values: [value(low), value(high)],
75
+ ...(options?.not ? { not: true } : {}),
76
+ };
77
+ }
78
+ export function and(...children) {
79
+ return { type: "AND", children };
80
+ }
81
+ export function or(...children) {
82
+ return { type: "OR", children };
83
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Access-policy extraction (#69): one `elementum_access_policy` block → the
3
+ * normalized shape the app/element printer consumes. The owning app/element's
4
+ * from-tf drives the pass and says who the owner is — this module never
5
+ * names the app/element resource type.
6
+ *
7
+ * `object_id` is always self (ei's exporter never emits a foreign owner —
8
+ * confirmed by `cmd/elementum/export/hcl_access_policy.go`'s `collectOwners`,
9
+ * which only ever sets `object_id` to the SAME app/element/task being
10
+ * exported) — so a block whose `object_id` doesn't match the owner is
11
+ * dropped with a diagnostic rather than silently misattributed.
12
+ */
13
+ import { type FromTfContext } from "../../engine/pull/context.js";
14
+ import { type ChildResourceScope, type TfBlock } from "../../engine/tf/index.js";
15
+ import type { FilterAst } from "../shared/filters/ast.js";
16
+ export interface AccessPolicyOwner {
17
+ readonly type: string;
18
+ readonly label: string;
19
+ /** `appRefName`/`elementRefName` — the owner's EDK refName (catalog root), used to build field refs. */
20
+ readonly ownerRefName: string;
21
+ /** The owner's terraform label (namespace) — used to strip the child-resource label prefix off `*_field` refs. */
22
+ readonly ownerTfLabel: string;
23
+ readonly scope: ChildResourceScope;
24
+ }
25
+ /**
26
+ * A resolved `data.elementum_user`/`data.elementum_group` reference, decoded
27
+ * from a pulled stream — reproduced byte-for-byte by `to-tf.ts`'s
28
+ * `rawLookup`, never re-derived. Also a valid `AccessPolicyUserRef`/
29
+ * `AccessPolicyGroupRef` (see `build.ts`), so the printer can round-trip it
30
+ * straight into `userIds`/`groupIds` without a separate print-time shape.
31
+ */
32
+ export interface AccessPolicyPrincipalRef {
33
+ readonly __kind: "orgPrincipalRef";
34
+ readonly dataType: "elementum_user" | "elementum_group";
35
+ /** The data block's own label, captured verbatim — reproduced byte-for-byte, never re-derived. */
36
+ readonly label: string;
37
+ /** The data block's lookup-attr value ("email" for a user, "name" for a group). */
38
+ readonly value: string;
39
+ }
40
+ /**
41
+ * FilterAst kinds {@link decodeFilter} can emit — same set as
42
+ * `access-policy/filter.ts` (no consecutiveRange / contains / overlaps).
43
+ * Printer + hoist walker switch on this, not the full automation FilterAst,
44
+ * so an automation-only kind cannot silently grow AP coverage. A new
45
+ * FilterAst kind still fails exhaustiveness here until it is excluded or
46
+ * implemented in decodeFilter + filter.ts.
47
+ */
48
+ export type AccessPolicyFilterAst = Exclude<FilterAst, {
49
+ kind: "and" | "or";
50
+ } | {
51
+ kind: "consecutiveRange";
52
+ } | {
53
+ kind: "contains" | "overlaps";
54
+ }> | {
55
+ kind: "and" | "or";
56
+ children: readonly AccessPolicyFilterAst[];
57
+ };
58
+ export interface NormalizedAccessPolicy {
59
+ readonly filter: AccessPolicyFilterAst;
60
+ readonly userIds?: readonly (string | AccessPolicyPrincipalRef)[];
61
+ readonly groupIds?: readonly (string | AccessPolicyPrincipalRef)[];
62
+ /** Always raw platform ids — ei's exporter carries no `elementum_service_account` resource to reference yet. */
63
+ readonly serviceAccountIds?: readonly string[];
64
+ }
65
+ /** One `elementum_access_policy` block → its normalized shape, or undefined when it belongs to a different owner. */
66
+ export declare function accessPolicyFromTf(block: TfBlock, owner: AccessPolicyOwner, ctx: FromTfContext): NormalizedAccessPolicy | undefined;
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Access-policy extraction (#69): one `elementum_access_policy` block → the
3
+ * normalized shape the app/element printer consumes. The owning app/element's
4
+ * from-tf drives the pass and says who the owner is — this module never
5
+ * names the app/element resource type.
6
+ *
7
+ * `object_id` is always self (ei's exporter never emits a foreign owner —
8
+ * confirmed by `cmd/elementum/export/hcl_access_policy.go`'s `collectOwners`,
9
+ * which only ever sets `object_id` to the SAME app/element/task being
10
+ * exported) — so a block whose `object_id` doesn't match the owner is
11
+ * dropped with a diagnostic rather than silently misattributed.
12
+ */
13
+ import { EntityTfError } from "../../engine/entity.js";
14
+ import { dataRefLabel, resourceRefLabel } from "../../engine/pull/context.js";
15
+ import { isTfExpr, scopedLabelToBagKey, tfLabelToTsLabel } from "../../engine/tf/index.js";
16
+ import { KNOWN_ACCESS_POLICY_ATTRS } from "./types.js";
17
+ function isObject(value) {
18
+ return typeof value === "object" && value !== null && !Array.isArray(value);
19
+ }
20
+ function fieldRef(value, owner, where) {
21
+ if (isTfExpr(value) && value.$expr === "resource-attr" && value.type.endsWith("_field") && value.path[0] === "id") {
22
+ return { kind: "field", appHandle: owner.ownerRefName, fieldKey: scopedLabelToBagKey(owner.ownerTfLabel, value.label, owner.scope) };
23
+ }
24
+ // A system field (status/title/id/stage/…) has no own resource block — ei
25
+ // addresses its id via a `<ownerTfLabel>_<field>_field_id` local instead
26
+ // (same shape automation's decodeValue resolves for trigger/task field
27
+ // refs). Extremely common on real access-policy filters (row-level
28
+ // security keyed off Status is the whole point of the feature).
29
+ if (isTfExpr(value) && value.$expr === "local") {
30
+ const prefix = `${owner.ownerTfLabel}_`;
31
+ if (value.name.startsWith(prefix) && value.name.endsWith("_field_id")) {
32
+ return { kind: "field", appHandle: owner.ownerRefName, fieldKey: tfLabelToTsLabel(value.name.slice(prefix.length, -9)) };
33
+ }
34
+ }
35
+ if (typeof value === "string")
36
+ return { kind: "unresolved", uuid: value, hint: "field" };
37
+ throw new EntityTfError(`${where}: field reference cannot be reconstructed`);
38
+ }
39
+ /**
40
+ * A picklist-typed literal filter value ("Open") emits as a
41
+ * `local.<...>_options_by_label[label]` lookup on build, not a plain
42
+ * `{type:"text", value}` object (see `to-tf.ts`'s `picklistLiteralToTf`) —
43
+ * collapse it back to its readable label, mirroring automation's own
44
+ * `picklistOptionLabel`.
45
+ */
46
+ function picklistOptionLabel(value) {
47
+ if (value === undefined || !isTfExpr(value) || value.$expr !== "local" || value.path.length !== 1)
48
+ return undefined;
49
+ const segment = value.path[0];
50
+ const isOptionsLookup = value.name.endsWith("_options_by_label") || value.name.endsWith("_option_ids_by_label");
51
+ return isOptionsLookup && typeof segment === "object" && segment !== null && "index" in segment && typeof segment.index === "string"
52
+ ? segment.index
53
+ : undefined;
54
+ }
55
+ function filterValue(value, owner, where) {
56
+ const optionLabel = picklistOptionLabel(value);
57
+ if (optionLabel !== undefined)
58
+ return { kind: "text", value: optionLabel };
59
+ if (!isObject(value) || isTfExpr(value))
60
+ throw new EntityTfError(`${where}: filter value has an unrecognized shape`);
61
+ const type = typeof value.type === "string" ? value.type.toLowerCase() : undefined;
62
+ if (type === undefined)
63
+ throw new EntityTfError(`${where}: filter value has no type`);
64
+ if (type === "null")
65
+ return { kind: "null" };
66
+ if (type === "current_user") {
67
+ const raw = typeof value.current_user_type === "string" ? value.current_user_type.toLowerCase() : "id";
68
+ const currentUserType = raw === "email" || raw === "domain" ? raw : "id";
69
+ return { kind: "currentUser", currentUserType };
70
+ }
71
+ if (["text", "number", "boolean", "uuid", "date", "datetime"].includes(type)) {
72
+ return { kind: type, value: value.value };
73
+ }
74
+ if (type === "field")
75
+ return { kind: "reference", ref: fieldRef(value.value, owner, where) };
76
+ throw new EntityTfError(`${where}: unsupported filter value type "${type}"`);
77
+ }
78
+ /**
79
+ * Decode one `filter` attribute. Kinds are the {@link AccessPolicyFilterAst}
80
+ * set — `filter.ts` builders plus what ei actually exports. consecutiveRange /
81
+ * contains / overlaps throw here rather than decode into FilterAst nodes the
82
+ * printer cannot author.
83
+ */
84
+ function decodeFilter(value, owner, where) {
85
+ if (!isObject(value) || isTfExpr(value) || typeof value.type !== "string")
86
+ throw new EntityTfError(`${where}: invalid filter object`);
87
+ const type = value.type.toLowerCase();
88
+ if (type === "true" || type === "false")
89
+ return { kind: type };
90
+ if (type === "and" || type === "or") {
91
+ if (!Array.isArray(value.children))
92
+ throw new EntityTfError(`${where}: ${type} filter has no children`);
93
+ return { kind: type, children: value.children.map((child) => decodeFilter(child, owner, where)) };
94
+ }
95
+ if (value.field_id === undefined)
96
+ throw new EntityTfError(`${where}: ${type} filter has no field_id`);
97
+ const left = fieldRef(value.field_id, owner, where);
98
+ const not = value.not === true ? { not: true } : {};
99
+ if (type === "is_null")
100
+ return { kind: "isNull", left, ...not };
101
+ if (type === "in") {
102
+ if (!Array.isArray(value.values))
103
+ throw new EntityTfError(`${where}: in filter has no values`);
104
+ return { kind: "in", left, values: value.values.map((item) => filterValue(item, owner, where)), ...not };
105
+ }
106
+ if (type === "between") {
107
+ if (!Array.isArray(value.values) || value.values.length !== 2)
108
+ throw new EntityTfError(`${where}: between filter requires two values`);
109
+ return { kind: "between", left, values: [filterValue(value.values[0], owner, where), filterValue(value.values[1], owner, where)], ...not };
110
+ }
111
+ const kindByType = {
112
+ equals: "eq", greater_than: "gt", greater_than_equals: "gte", less_than: "lt", less_than_equals: "lte", like: "like",
113
+ };
114
+ const kind = kindByType[type];
115
+ if (kind === undefined || value.value === undefined)
116
+ throw new EntityTfError(`${where}: unsupported filter type "${type}"`);
117
+ const right = filterValue(value.value, owner, where);
118
+ return kind === "like"
119
+ ? { kind, left, right, ...not, ...(typeof value.case_insensitive === "boolean" ? { caseInsensitive: value.case_insensitive } : {}), ...(typeof value.mode === "string" ? { mode: value.mode.toLowerCase() } : {}) }
120
+ : { kind, left, right, ...not };
121
+ }
122
+ /** Decode one `user_ids`/`group_ids` list item: a `data.elementum_user|group` lookup, or a raw platform id fallback. undefined = dropped, with a diagnostic already pushed. */
123
+ function principalListItem(item, dataType, where, ctx) {
124
+ const label = dataRefLabel(item, dataType);
125
+ if (label !== undefined) {
126
+ const value = ctx.dataName(dataType, label);
127
+ if (value !== undefined)
128
+ return { __kind: "orgPrincipalRef", dataType, label, value };
129
+ ctx.diagnostics.push(`${where}: references data.${dataType}.${label}, but the stream has no matching data block; dropped`);
130
+ return undefined;
131
+ }
132
+ if (typeof item === "string")
133
+ return item;
134
+ ctx.diagnostics.push(`${where}: list item has an unrecognized shape; dropped`);
135
+ return undefined;
136
+ }
137
+ function principalList(value, dataType, where, ctx) {
138
+ if (value === undefined)
139
+ return undefined;
140
+ if (!Array.isArray(value)) {
141
+ ctx.diagnostics.push(`${where}: is not a list; dropped`);
142
+ return undefined;
143
+ }
144
+ const items = [];
145
+ for (const item of value) {
146
+ const decoded = principalListItem(item, dataType, where, ctx);
147
+ if (decoded !== undefined)
148
+ items.push(decoded);
149
+ }
150
+ return items.length > 0 ? items : undefined;
151
+ }
152
+ /** One `elementum_access_policy` block → its normalized shape, or undefined when it belongs to a different owner. */
153
+ export function accessPolicyFromTf(block, owner, ctx) {
154
+ const label = block.label;
155
+ if (label === undefined || label === "")
156
+ throw new EntityTfError("elementum_access_policy block is missing its label");
157
+ const where = `access policy (${block.type}.${label})`;
158
+ const attrs = block.attrs;
159
+ for (const key of Object.keys(attrs)) {
160
+ if (!KNOWN_ACCESS_POLICY_ATTRS.has(key)) {
161
+ ctx.diagnostics.push(`${where}: unhandled attribute "${key}" — the export dialect grew; extend accessPolicyFromTf deliberately`);
162
+ }
163
+ }
164
+ if (resourceRefLabel(attrs["object_id"], owner.type) !== owner.label) {
165
+ ctx.diagnostics.push(`${where}: object_id does not reference ${owner.type}.${owner.label}; skipped`);
166
+ return undefined;
167
+ }
168
+ const filter = attrs["filter"] !== undefined ? decodeFilter(attrs["filter"], owner, where) : { kind: "true" };
169
+ const userIds = principalList(attrs["user_ids"], "elementum_user", `${where}: user_ids`, ctx);
170
+ const groupIds = principalList(attrs["group_ids"], "elementum_group", `${where}: group_ids`, ctx);
171
+ let serviceAccountIds;
172
+ const saAttr = attrs["service_account_ids"];
173
+ if (Array.isArray(saAttr)) {
174
+ serviceAccountIds = saAttr.filter((id) => typeof id === "string");
175
+ if (serviceAccountIds.length === 0)
176
+ serviceAccountIds = undefined;
177
+ }
178
+ else if (saAttr !== undefined) {
179
+ ctx.diagnostics.push(`${where}: service_account_ids is not a list; dropped`);
180
+ }
181
+ return {
182
+ filter,
183
+ ...(userIds !== undefined && { userIds }),
184
+ ...(groupIds !== undefined && { groupIds }),
185
+ ...(serviceAccountIds !== undefined && { serviceAccountIds }),
186
+ };
187
+ }
@@ -0,0 +1,3 @@
1
+ /** The access-policy entity's registry entry (see src/graph/). */
2
+ import { type EntityKindModule } from "../../graph/types.js";
3
+ export declare const accessPolicyModule: EntityKindModule;
@@ -0,0 +1,17 @@
1
+ /** The access-policy entity's registry entry (see src/graph/). */
2
+ import { NO_CATALOG, NO_DATA, NO_LIFECYCLE, } from "../../graph/types.js";
3
+ import { ACCESS_POLICY_RESOURCE_TYPE } from "./types.js";
4
+ export const accessPolicyModule = {
5
+ kind: "access-policy",
6
+ stream: { role: "streamMember" },
7
+ authoring: { unit: "inline", bag: "accessPolicies" },
8
+ parents: [
9
+ { parent: "app", child: "access-policy" },
10
+ { parent: "element", child: "access-policy" },
11
+ ],
12
+ resource: { shape: "single", resourceType: ACCESS_POLICY_RESOURCE_TYPE, adoptable: true },
13
+ data: NO_DATA,
14
+ lifecycle: NO_LIFECYCLE,
15
+ canvas: { participates: true, label: "Access Policies", glyph: "🔒", component: "generic" },
16
+ catalog: NO_CATALOG,
17
+ };