@elementumai/edk 0.9.18 → 0.9.20

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 (219) hide show
  1. package/README.md +154 -9
  2. package/dist-sdk/src/catalog/factories.d.ts +35 -1
  3. package/dist-sdk/src/catalog/factories.js +36 -0
  4. package/dist-sdk/src/catalog/from-authoring.d.ts +13 -8
  5. package/dist-sdk/src/catalog/from-authoring.js +34 -9
  6. package/dist-sdk/src/catalog/index.d.ts +2 -2
  7. package/dist-sdk/src/catalog/index.js +2 -2
  8. package/dist-sdk/src/catalog/org.d.ts +39 -1
  9. package/dist-sdk/src/catalog/org.js +460 -50
  10. package/dist-sdk/src/catalog/render.js +6 -6
  11. package/dist-sdk/src/catalog/token.js +7 -0
  12. package/dist-sdk/src/catalog/types.d.ts +44 -1
  13. package/dist-sdk/src/catalog/types.js +13 -0
  14. package/dist-sdk/src/core/triggers/on-demand.d.ts +39 -3
  15. package/dist-sdk/src/core/triggers/on-demand.js +10 -2
  16. package/dist-sdk/src/engine/build/context.d.ts +1 -1
  17. package/dist-sdk/src/engine/ei/run.d.ts +149 -0
  18. package/dist-sdk/src/engine/ei/run.js +1132 -0
  19. package/dist-sdk/src/engine/logging.d.ts +17 -0
  20. package/dist-sdk/src/engine/logging.js +18 -0
  21. package/dist-sdk/src/engine/pull/ref-only.d.ts +5 -0
  22. package/dist-sdk/src/engine/pull/ref-only.js +64 -27
  23. package/dist-sdk/src/engine/pull/result-output.d.ts +8 -0
  24. package/dist-sdk/src/engine/pull/result-output.js +88 -4
  25. package/dist-sdk/src/engine/tf/expr.js +39 -14
  26. package/dist-sdk/src/engine/tf/index.d.ts +3 -3
  27. package/dist-sdk/src/engine/tf/index.js +2 -2
  28. package/dist-sdk/src/engine/tf/labels.d.ts +8 -0
  29. package/dist-sdk/src/engine/tf/labels.js +13 -0
  30. package/dist-sdk/src/engine/tf/model.d.ts +22 -1
  31. package/dist-sdk/src/engine/tf/parse.d.ts +19 -0
  32. package/dist-sdk/src/engine/tf/parse.js +197 -10
  33. package/dist-sdk/src/engine/tf/render.d.ts +4 -2
  34. package/dist-sdk/src/engine/tf/render.js +41 -7
  35. package/dist-sdk/src/engine/validation.d.ts +39 -0
  36. package/dist-sdk/src/engine/validation.js +85 -0
  37. package/dist-sdk/src/engine/workspace/loader.js +49 -12
  38. package/dist-sdk/src/entities/access-policy/from-tf.d.ts +11 -1
  39. package/dist-sdk/src/entities/access-policy/from-tf.js +6 -1
  40. package/dist-sdk/src/entities/access-policy/to-tf.d.ts +11 -0
  41. package/dist-sdk/src/entities/access-policy/to-tf.js +16 -6
  42. package/dist-sdk/src/entities/agent/build.d.ts +4 -16
  43. package/dist-sdk/src/entities/agent/build.js +40 -5
  44. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +4 -2
  45. package/dist-sdk/src/entities/agent/to-tf.js +6 -3
  46. package/dist-sdk/src/entities/agent-tool/from-tf.d.ts +2 -0
  47. package/dist-sdk/src/entities/agent-tool/from-tf.js +7 -1
  48. package/dist-sdk/src/entities/agent-tool/to-tf.d.ts +2 -2
  49. package/dist-sdk/src/entities/agent-tool/to-tf.js +29 -6
  50. package/dist-sdk/src/entities/app/build.d.ts +98 -19
  51. package/dist-sdk/src/entities/app/build.js +51 -19
  52. package/dist-sdk/src/entities/app/deserializer/normalize.d.ts +22 -1
  53. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  54. package/dist-sdk/src/entities/app/from-tf.js +11 -5
  55. package/dist-sdk/src/entities/app/index.d.ts +6 -5
  56. package/dist-sdk/src/entities/app/index.js +2 -0
  57. package/dist-sdk/src/entities/app/module.js +18 -2
  58. package/dist-sdk/src/entities/app/to-tf.js +21 -11
  59. package/dist-sdk/src/entities/automation/build.d.ts +49 -6
  60. package/dist-sdk/src/entities/automation/build.js +163 -19
  61. package/dist-sdk/src/entities/automation/deserializer/print-automation.d.ts +24 -1
  62. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +320 -39
  63. package/dist-sdk/src/entities/automation/from-tf.d.ts +28 -6
  64. package/dist-sdk/src/entities/automation/from-tf.js +563 -74
  65. package/dist-sdk/src/entities/automation/generated/task-output-contracts.d.ts +33 -0
  66. package/dist-sdk/src/entities/automation/generated/task-output-contracts.js +183 -0
  67. package/dist-sdk/src/entities/automation/index.d.ts +2 -2
  68. package/dist-sdk/src/entities/automation/index.js +1 -1
  69. package/dist-sdk/src/entities/automation/module.d.ts +2 -0
  70. package/dist-sdk/src/entities/automation/module.js +93 -8
  71. package/dist-sdk/src/entities/automation/output-field-types.d.ts +7 -0
  72. package/dist-sdk/src/entities/automation/output-field-types.js +36 -0
  73. package/dist-sdk/src/entities/automation/output-key-wire-name.d.ts +9 -0
  74. package/dist-sdk/src/entities/automation/output-key-wire-name.js +13 -0
  75. package/dist-sdk/src/entities/automation/script-code.d.ts +17 -0
  76. package/dist-sdk/src/entities/automation/script-code.js +91 -5
  77. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +16 -0
  78. package/dist-sdk/src/entities/automation/system-ref-name.js +48 -0
  79. package/dist-sdk/src/entities/automation/task-output-labels.d.ts +17 -0
  80. package/dist-sdk/src/entities/automation/task-output-labels.js +47 -0
  81. package/dist-sdk/src/entities/automation/tasks.d.ts +53 -4
  82. package/dist-sdk/src/entities/automation/tasks.js +38 -9
  83. package/dist-sdk/src/entities/automation/to-tf.d.ts +4 -0
  84. package/dist-sdk/src/entities/automation/to-tf.js +647 -167
  85. package/dist-sdk/src/entities/automation/triggers.d.ts +4 -2
  86. package/dist-sdk/src/entities/automation/triggers.js +4 -0
  87. package/dist-sdk/src/entities/automation/types.js +1 -0
  88. package/dist-sdk/src/entities/chart/from-tf.js +33 -17
  89. package/dist-sdk/src/entities/chart/module.js +3 -1
  90. package/dist-sdk/src/entities/chart/printer.d.ts +1 -0
  91. package/dist-sdk/src/entities/chart/printer.js +26 -16
  92. package/dist-sdk/src/entities/chart/rebind-owner.d.ts +3 -0
  93. package/dist-sdk/src/entities/chart/rebind-owner.js +42 -0
  94. package/dist-sdk/src/entities/chart/to-tf.js +21 -12
  95. package/dist-sdk/src/entities/dashboard/build.d.ts +4 -0
  96. package/dist-sdk/src/entities/dashboard/from-tf.js +15 -4
  97. package/dist-sdk/src/entities/dashboard/to-tf.d.ts +2 -0
  98. package/dist-sdk/src/entities/dashboard/to-tf.js +13 -0
  99. package/dist-sdk/src/entities/dashboard-widget/module.js +4 -0
  100. package/dist-sdk/src/entities/dynamic-layout/build.d.ts +72 -30
  101. package/dist-sdk/src/entities/dynamic-layout/dialect.d.ts +3 -0
  102. package/dist-sdk/src/entities/dynamic-layout/dialect.js +5 -0
  103. package/dist-sdk/src/entities/dynamic-layout/from-tf.d.ts +9 -6
  104. package/dist-sdk/src/entities/dynamic-layout/from-tf.js +188 -26
  105. package/dist-sdk/src/entities/dynamic-layout/module.js +4 -1
  106. package/dist-sdk/src/entities/dynamic-layout/to-tf.d.ts +5 -1
  107. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +254 -23
  108. package/dist-sdk/src/entities/element/build.d.ts +33 -13
  109. package/dist-sdk/src/entities/element/build.js +5 -1
  110. package/dist-sdk/src/entities/element/from-tf.d.ts +12 -0
  111. package/dist-sdk/src/entities/element/from-tf.js +64 -3
  112. package/dist-sdk/src/entities/element/index.d.ts +5 -2
  113. package/dist-sdk/src/entities/element/index.js +2 -0
  114. package/dist-sdk/src/entities/element/module.js +11 -3
  115. package/dist-sdk/src/entities/element/to-tf.js +20 -2
  116. package/dist-sdk/src/entities/field/build.d.ts +14 -1
  117. package/dist-sdk/src/entities/field/build.js +3 -0
  118. package/dist-sdk/src/entities/field/from-tf.d.ts +3 -0
  119. package/dist-sdk/src/entities/field/from-tf.js +50 -1
  120. package/dist-sdk/src/entities/field/media-types.d.ts +6 -0
  121. package/dist-sdk/src/entities/field/media-types.js +30 -0
  122. package/dist-sdk/src/entities/field/module.js +1 -0
  123. package/dist-sdk/src/entities/field/to-tf.d.ts +23 -2
  124. package/dist-sdk/src/entities/field/to-tf.js +142 -22
  125. package/dist-sdk/src/entities/file-reader/from-tf.js +14 -5
  126. package/dist-sdk/src/entities/file-reader/module.js +1 -0
  127. package/dist-sdk/src/entities/file-reader/types.d.ts +2 -0
  128. package/dist-sdk/src/entities/file-reader/types.js +1 -1
  129. package/dist-sdk/src/entities/portal/build.d.ts +26 -0
  130. package/dist-sdk/src/entities/portal/build.js +37 -0
  131. package/dist-sdk/src/entities/portal/from-tf.d.ts +27 -0
  132. package/dist-sdk/src/entities/portal/from-tf.js +75 -0
  133. package/dist-sdk/src/entities/portal/index.d.ts +1 -0
  134. package/dist-sdk/src/entities/portal/index.js +1 -0
  135. package/dist-sdk/src/entities/portal/module.d.ts +3 -0
  136. package/dist-sdk/src/entities/portal/module.js +28 -0
  137. package/dist-sdk/src/entities/portal/to-tf.d.ts +12 -0
  138. package/dist-sdk/src/entities/portal/to-tf.js +73 -0
  139. package/dist-sdk/src/entities/portal/types.d.ts +1 -0
  140. package/dist-sdk/src/entities/portal/types.js +1 -0
  141. package/dist-sdk/src/entities/relationship/from-tf.d.ts +8 -1
  142. package/dist-sdk/src/entities/relationship/from-tf.js +53 -10
  143. package/dist-sdk/src/entities/relationship/module.js +2 -0
  144. package/dist-sdk/src/entities/relationship/pair-check.d.ts +7 -0
  145. package/dist-sdk/src/entities/relationship/pair-check.js +68 -0
  146. package/dist-sdk/src/entities/relationship/to-tf.d.ts +10 -0
  147. package/dist-sdk/src/entities/relationship/to-tf.js +31 -13
  148. package/dist-sdk/src/entities/search-table/module.js +1 -0
  149. package/dist-sdk/src/entities/search-table/to-tf.d.ts +1 -0
  150. package/dist-sdk/src/entities/search-table/to-tf.js +1 -1
  151. package/dist-sdk/src/entities/service-account/build.d.ts +15 -2
  152. package/dist-sdk/src/entities/service-account/from-tf.d.ts +2 -4
  153. package/dist-sdk/src/entities/service-account/from-tf.js +17 -5
  154. package/dist-sdk/src/entities/service-account/role-fidelity.d.ts +56 -0
  155. package/dist-sdk/src/entities/service-account/role-fidelity.js +243 -0
  156. package/dist-sdk/src/entities/service-account/to-tf.d.ts +14 -0
  157. package/dist-sdk/src/entities/service-account/to-tf.js +17 -0
  158. package/dist-sdk/src/entities/shared/aspect-target-from-tf.d.ts +1 -1
  159. package/dist-sdk/src/entities/shared/aspect-target-from-tf.js +5 -2
  160. package/dist-sdk/src/entities/shared/filters/ast.d.ts +15 -2
  161. package/dist-sdk/src/entities/shared/filters/index.d.ts +25 -2
  162. package/dist-sdk/src/entities/shared/filters/index.js +38 -5
  163. package/dist-sdk/src/entities/shared/filters/print.js +31 -3
  164. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +25 -3
  165. package/dist-sdk/src/entities/shared/filters/tf-codec.js +51 -15
  166. package/dist-sdk/src/entities/shared/filters/types.d.ts +22 -5
  167. package/dist-sdk/src/entities/shared/foreign-ref.d.ts +16 -0
  168. package/dist-sdk/src/entities/shared/foreign-ref.js +17 -1
  169. package/dist-sdk/src/entities/shared/tool-field-ref.js +6 -9
  170. package/dist-sdk/src/entities/shared/types/field-types.d.ts +10 -5
  171. package/dist-sdk/src/entities/shared/types/field-types.js +4 -0
  172. package/dist-sdk/src/entities/skill/access-policy.d.ts +17 -0
  173. package/dist-sdk/src/entities/skill/access-policy.js +101 -0
  174. package/dist-sdk/src/entities/skill/build.d.ts +3 -0
  175. package/dist-sdk/src/entities/skill/build.js +3 -0
  176. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.d.ts +4 -1
  177. package/dist-sdk/src/entities/skill/deserializer/print-skill-v2.js +23 -1
  178. package/dist-sdk/src/entities/skill/from-tf.d.ts +2 -0
  179. package/dist-sdk/src/entities/skill/from-tf.js +70 -22
  180. package/dist-sdk/src/entities/skill/index.d.ts +2 -0
  181. package/dist-sdk/src/entities/skill/index.js +1 -0
  182. package/dist-sdk/src/entities/skill/input-coverage.d.ts +7 -0
  183. package/dist-sdk/src/entities/skill/input-coverage.js +11 -0
  184. package/dist-sdk/src/entities/skill/module.js +1 -0
  185. package/dist-sdk/src/entities/skill/to-tf.d.ts +2 -2
  186. package/dist-sdk/src/entities/skill/to-tf.js +19 -6
  187. package/dist-sdk/src/entities/skill-tool/from-tf.d.ts +2 -0
  188. package/dist-sdk/src/entities/skill-tool/from-tf.js +8 -2
  189. package/dist-sdk/src/entities/skill-tool/to-tf.d.ts +2 -2
  190. package/dist-sdk/src/entities/skill-tool/to-tf.js +29 -6
  191. package/dist-sdk/src/entities/table/catalog.d.ts +14 -0
  192. package/dist-sdk/src/entities/table/catalog.js +66 -0
  193. package/dist-sdk/src/entities/table/module.js +2 -1
  194. package/dist-sdk/src/entities/table/to-tf.js +5 -5
  195. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +89 -0
  196. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +277 -0
  197. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +51 -0
  198. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +360 -0
  199. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +151 -0
  200. package/dist-sdk/src/entities/view/agent-view-layout.js +21 -0
  201. package/dist-sdk/src/entities/view/from-tf.d.ts +6 -3
  202. package/dist-sdk/src/entities/view/from-tf.js +161 -14
  203. package/dist-sdk/src/entities/view/module.js +30 -3
  204. package/dist-sdk/src/entities/view/to-tf.d.ts +24 -2
  205. package/dist-sdk/src/entities/view/to-tf.js +95 -9
  206. package/dist-sdk/src/entities/view/types.d.ts +4 -15
  207. package/dist-sdk/src/entities/view/types.js +17 -15
  208. package/dist-sdk/src/entities/widget/build.d.ts +16 -1
  209. package/dist-sdk/src/entities/widget/build.js +11 -1
  210. package/dist-sdk/src/entities/widget/to-tf.js +36 -10
  211. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.d.ts +38 -10
  212. package/dist-sdk/src/generated/ragnarok/ragnarok-spec.js +2 -2
  213. package/dist-sdk/src/graph/index.d.ts +54 -0
  214. package/dist-sdk/src/graph/index.js +30 -0
  215. package/dist-sdk/src/graph/modules.js +2 -0
  216. package/dist-sdk/src/graph/types.d.ts +133 -2
  217. package/dist-sdk/src/internal/sdk-package.d.ts +1 -1
  218. package/dist-sdk/src/internal/sdk-package.js +1 -0
  219. package/package.json +11 -1
@@ -1,18 +1,38 @@
1
+ import { parse } from "acorn";
1
2
  import { readFileSync } from "node:fs";
2
3
  import { createRequire } from "node:module";
3
4
  import { dirname, isAbsolute, resolve } from "node:path";
4
5
  import { currentImportingFile, currentSourceText } from "../../engine/build/source-context.js";
5
- let tsModule;
6
+ let packageTsModule;
6
7
  function getTs() {
7
- if (tsModule === undefined) {
8
+ if (packageTsModule === undefined) {
8
9
  try {
9
- tsModule = createRequire(import.meta.url)("typescript");
10
+ packageTsModule = createRequire(import.meta.url)("typescript");
10
11
  }
11
12
  catch {
12
- tsModule = null;
13
+ packageTsModule = null;
13
14
  }
14
15
  }
15
- return tsModule ?? undefined;
16
+ if (packageTsModule !== null)
17
+ return packageTsModule;
18
+ // The SDK intentionally does not require TypeScript at runtime. When an
19
+ // authored inline body does need type erasure, resolve the workspace's
20
+ // optional TypeScript from the automation being loaded, not only from the
21
+ // caller's cwd (`elementum build /path/to/org` may run anywhere).
22
+ const importingFile = currentSourceText()?.filePath ?? currentImportingFile();
23
+ const roots = [
24
+ ...(importingFile === undefined ? [] : [importingFile]),
25
+ resolve(process.cwd(), "package.json"),
26
+ ];
27
+ for (const root of roots) {
28
+ try {
29
+ return createRequire(root)("typescript");
30
+ }
31
+ catch {
32
+ // Try the next legitimate module root.
33
+ }
34
+ }
35
+ return undefined;
16
36
  }
17
37
  /**
18
38
  * Reference a plain-JavaScript script file for `executeScript`'s `code:`.
@@ -119,6 +139,72 @@ export class ScriptCodeError extends Error {
119
139
  this.name = "ScriptCodeError";
120
140
  }
121
141
  }
142
+ const SCRIPT_WRAPPER_OPEN = "function __edkScript(input) {\n";
143
+ const SCRIPT_WRAPPER_CLOSE = "\n}\n";
144
+ function scriptSyntaxErrors(wrapped, fileName, ts) {
145
+ const output = ts.transpileModule(wrapped, {
146
+ fileName,
147
+ reportDiagnostics: true,
148
+ compilerOptions: { target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, removeComments: false },
149
+ });
150
+ return (output.diagnostics ?? [])
151
+ .filter((diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error)
152
+ .map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
153
+ }
154
+ function plainJavaScriptSyntaxError(body) {
155
+ try {
156
+ parse(body, {
157
+ ecmaVersion: "latest",
158
+ sourceType: "script",
159
+ allowReturnOutsideFunction: true,
160
+ allowAwaitOutsideFunction: true,
161
+ });
162
+ return undefined;
163
+ }
164
+ catch (error) {
165
+ return error instanceof Error ? error.message : String(error);
166
+ }
167
+ }
168
+ /**
169
+ * The platform runs a script body as plain JavaScript, so TypeScript-only
170
+ * syntax (`const out: Record<string, string> = {}`, `x as T`, `value!`,
171
+ * `implements`) fails there at runtime. A body that parses as JavaScript,
172
+ * which includes every pulled script, is returned unchanged so it round-trips
173
+ * byte for byte (`f(a < b, c > (d))` stays two comparisons). One that parses
174
+ * only as TypeScript has its types erased by the TypeScript transpiler with an
175
+ * ESNext target, so no syntax is downleveled into helpers; one that parses as
176
+ * neither is refused. `label` names the script in errors. With
177
+ * `stripTypes: false` (script files, which must hold plain JavaScript)
178
+ * TypeScript syntax is refused instead of stripped.
179
+ */
180
+ export function toPlatformScriptBody(body, label, options = {}) {
181
+ const wrapped = `${SCRIPT_WRAPPER_OPEN}${body}${SCRIPT_WRAPPER_CLOSE}`;
182
+ const plainJsRefusal = () => new ScriptCodeError(`${label}: script files must be plain JavaScript, but this one uses TypeScript syntax (type annotations, \`as\`, \`!\`, ...).`);
183
+ const jsError = plainJavaScriptSyntaxError(body);
184
+ if (jsError === undefined)
185
+ return body;
186
+ if (options.stripTypes === false)
187
+ throw plainJsRefusal();
188
+ const ts = (options.loadTypeScript === undefined ? getTs() : options.loadTypeScript());
189
+ if (ts === undefined) {
190
+ throw new ScriptCodeError(`${label}: the script body is not plain JavaScript and TypeScript is unavailable: ${jsError}`);
191
+ }
192
+ const tsErrors = scriptSyntaxErrors(wrapped, "script.ts", ts);
193
+ if (tsErrors.length > 0) {
194
+ throw new ScriptCodeError(`${label}: the script body does not parse: ${tsErrors.join("; ")}`);
195
+ }
196
+ const output = ts.transpileModule(wrapped, {
197
+ fileName: "script.ts",
198
+ compilerOptions: { target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, removeComments: false },
199
+ }).outputText;
200
+ const start = output.indexOf("function __edkScript(input)");
201
+ const open = start < 0 ? -1 : output.indexOf("{", start);
202
+ const close = output.lastIndexOf("}");
203
+ if (open < 0 || close <= open) {
204
+ throw new ScriptCodeError(`${label}: could not remove TypeScript types from the script body.`);
205
+ }
206
+ return dedent(output.slice(open + 1, close).replace(/^\n+/, "").replace(/\n[ \t]*$/, ""));
207
+ }
122
208
  /**
123
209
  * Extract the platform script body from an authored code function. Accepts the
124
210
  * shapes a transpiler emits for `(input) => …`: arrow with block body, arrow
@@ -0,0 +1,16 @@
1
+ import { type SystemFieldKey } from "../../core/system-fields.js";
2
+ /**
3
+ * System fields the provider cannot rename. Their ref names are always built
4
+ * from DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, whatever the app authored.
5
+ */
6
+ export declare const PROVIDER_FIXED_SYSTEM_FIELD_KEYS: ReadonlySet<SystemFieldKey>;
7
+ /** The refs-map key a build emits for a record field display name plus wire suffix. */
8
+ export declare function recordFieldWireRefName(fieldName: string, wireSuffix: string): string;
9
+ /**
10
+ * Whether decoding `wireName` as `<key><wireSuffix>` is lossless: a build of
11
+ * the typed path must emit a key the live refs map resolves identically.
12
+ * Older organizations name audit fields "Closed by" / "Created on"; decoding
13
+ * those to a typed key would rebuild as "Closed By" / "Created At", which is a
14
+ * different (missing) map key.
15
+ */
16
+ export declare function systemRefNameRoundTrips(key: SystemFieldKey, wireSuffix: string, wireName: string): boolean;
@@ -0,0 +1,48 @@
1
+ import { DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES } from "../../core/system-fields.js";
2
+ /**
3
+ * System fields the provider cannot rename. Their ref names are always built
4
+ * from DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES, whatever the app authored.
5
+ */
6
+ export const PROVIDER_FIXED_SYSTEM_FIELD_KEYS = new Set([
7
+ "stage",
8
+ "createdAt",
9
+ "createdBy",
10
+ "updatedAt",
11
+ "updatedBy",
12
+ "closedAt",
13
+ "closedBy",
14
+ ]);
15
+ /** Ref keys the provider publishes under both spellings (see withAuditEmailRefAliases). */
16
+ const PROVIDER_ALIASED_REF_NAMES = new Map([
17
+ ["Created by Email", "Created By Email"],
18
+ ["Created By Email", "Created by Email"],
19
+ ["Updated by Email", "Updated By Email"],
20
+ ["Updated By Email", "Updated by Email"],
21
+ ["Created by Manager Email", "Created By Manager Email"],
22
+ ["Created By Manager Email", "Created by Manager Email"],
23
+ ["Updated by Manager Email", "Updated By Manager Email"],
24
+ ["Updated By Manager Email", "Updated by Manager Email"],
25
+ ]);
26
+ /** The refs-map key a build emits for a record field display name plus wire suffix. */
27
+ export function recordFieldWireRefName(fieldName, wireSuffix) {
28
+ const refName = `${fieldName}${wireSuffix}`;
29
+ // Email audit refs have historically varied in the capitalization of "by"
30
+ // between organizations. The provider exposes both spellings as aliases,
31
+ // so author the established lowercase wire name consistently.
32
+ return /^(Created|Updated) By (?:Manager )?Email$/.test(refName)
33
+ ? refName.replace(/ By(?= (?:Manager )?Email$)/, " by")
34
+ : refName;
35
+ }
36
+ /**
37
+ * Whether decoding `wireName` as `<key><wireSuffix>` is lossless: a build of
38
+ * the typed path must emit a key the live refs map resolves identically.
39
+ * Older organizations name audit fields "Closed by" / "Created on"; decoding
40
+ * those to a typed key would rebuild as "Closed By" / "Created At", which is a
41
+ * different (missing) map key.
42
+ */
43
+ export function systemRefNameRoundTrips(key, wireSuffix, wireName) {
44
+ if (!PROVIDER_FIXED_SYSTEM_FIELD_KEYS.has(key))
45
+ return true;
46
+ const emitted = recordFieldWireRefName(DEPLOY_DEFAULT_SYSTEM_FIELD_NAMES[key], wireSuffix);
47
+ return emitted === wireName || PROVIDER_ALIASED_REF_NAMES.get(emitted) === wireName;
48
+ }
@@ -0,0 +1,17 @@
1
+ /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
+ export declare const USER_SEARCH_REF_WIRE_NAMES: Readonly<Record<string, string>>;
3
+ /**
4
+ * Task-own outputs whose WorkflowTaskReference name (what an exported
5
+ * envelope and a calculation mustache carry) differs from the provider
6
+ * refs-map key, per resource type. Captured live with `ei refs --from-remote`
7
+ * and matching mobius' `shared.json` label tables.
8
+ */
9
+ export declare const TASK_OUTPUT_REFERENCE_NAMES: Readonly<Record<string, Readonly<Record<string, string>>>>;
10
+ /**
11
+ * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
12
+ * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
13
+ * `record_reference` needs; a field-mapped input needs the record itself.
14
+ */
15
+ export declare const WHOLE_RECORD_REF_WIRE_NAMES: Readonly<Record<string, string>>;
16
+ /** aiSearchTable accessor → [refs-map display label, canonical `service_tasks` output name]. */
17
+ export declare const AI_SEARCH_TABLE_OUTPUT_NAMES: Readonly<Record<string, readonly [display: string, canonical: string]>>;
@@ -0,0 +1,47 @@
1
+ /** userSearch authoring output → provider refs-map key (as exported from live user-search tasks). */
2
+ export const USER_SEARCH_REF_WIRE_NAMES = {
3
+ "user.id": "User's Id",
4
+ "user.name": "User's Name",
5
+ "user.email": "User's Email",
6
+ "user.managerName": "Manager Name",
7
+ "user.managerEmail": "Manager Email",
8
+ users: "All found users",
9
+ count: "Users Size",
10
+ };
11
+ /**
12
+ * Task-own outputs whose WorkflowTaskReference name (what an exported
13
+ * envelope and a calculation mustache carry) differs from the provider
14
+ * refs-map key, per resource type. Captured live with `ei refs --from-remote`
15
+ * and matching mobius' `shared.json` label tables.
16
+ */
17
+ export const TASK_OUTPUT_REFERENCE_NAMES = {
18
+ elementum_record_search_task: {
19
+ "Records Size": "count",
20
+ "First found record id": "recordId",
21
+ },
22
+ elementum_user_group_search_task: {
23
+ "Groups Size": "count",
24
+ "First found group": "group",
25
+ ID: "group.id",
26
+ Name: "group.name",
27
+ "All found groups": "groups",
28
+ },
29
+ };
30
+ /**
31
+ * A record-bearing task's whole-record output (ASPECT_RECORD). The bare
32
+ * `.record` accessor otherwise builds the ASPECT_RECORD_ID `Record` key a
33
+ * `record_reference` needs; a field-mapped input needs the record itself.
34
+ */
35
+ export const WHOLE_RECORD_REF_WIRE_NAMES = {
36
+ recordSearch: "First found record",
37
+ createRecord: "Created record",
38
+ updateField: "Updated record",
39
+ };
40
+ /** aiSearchTable accessor → [refs-map display label, canonical `service_tasks` output name]. */
41
+ export const AI_SEARCH_TABLE_OUTPUT_NAMES = {
42
+ records: ["All Records", "searchTableRecords"],
43
+ recordsText: ["All Records Text", "searchTableRecordsText"],
44
+ recordsJson: ["All Records JSON", "searchTableRecordsJson"],
45
+ firstRecordText: ["First Record Text", "firstFoundRecordText"],
46
+ firstRecordJson: ["First Record JSON", "firstFoundRecordJson"],
47
+ };
@@ -388,6 +388,18 @@ export interface ApiRequestHeader {
388
388
  readonly name: string;
389
389
  readonly value: ValueOrRef<unknown>;
390
390
  }
391
+ /**
392
+ * A required sensitive Terraform variable for a write-only value the export
393
+ * could not read (an API header, or basic auth's username). Plan refuses
394
+ * until `TF_VAR_<variable>` is a non-empty string. This is not a vault
395
+ * secret — vault-entry references are a separate contract.
396
+ */
397
+ export interface RequiredSecret {
398
+ readonly kind: "requiredSecret";
399
+ readonly variable: string;
400
+ }
401
+ export declare function requiredSecret(variable: string): RequiredSecret;
402
+ export declare function isRequiredSecret(value: unknown): value is RequiredSecret;
391
403
  export interface ApiRequestBasicAuth {
392
404
  readonly username: ValueOrRef<unknown>;
393
405
  /**
@@ -494,6 +506,14 @@ export interface AiSearchTableOptions {
494
506
  */
495
507
  export interface AiSearchTableOutput {
496
508
  readonly records: readonly unknown[];
509
+ /** `refs["All Records Text"]`: every found record rendered as text (e.g. for an AI prompt). */
510
+ readonly recordsText: string;
511
+ /** `refs["All Records JSON"]`. */
512
+ readonly recordsJson: unknown;
513
+ /** `refs["First Record Text"]`. */
514
+ readonly firstRecordText: string;
515
+ /** `refs["First Record JSON"]`. */
516
+ readonly firstRecordJson: unknown;
497
517
  }
498
518
  export declare function aiSearchTable(opts: AiSearchTableOptions): ActionDef<AiSearchTableOutput>;
499
519
  export interface AiSummarizeOptions {
@@ -566,8 +586,8 @@ type Empty = Record<string, never>;
566
586
  export interface NotificationOptions {
567
587
  readonly title: ValueOrRef<string>;
568
588
  readonly message: ValueOrRef<string>;
569
- /** Plain-text description shown in the notification's metadata (not templated). */
570
- readonly description?: string;
589
+ /** Description shown in the notification's metadata. Supports templates with value references. */
590
+ readonly description?: ValueOrRef<string>;
571
591
  readonly userIds?: readonly string[];
572
592
  readonly groupIds?: readonly string[];
573
593
  readonly userRefs?: readonly ValueOrRef<string>[];
@@ -603,8 +623,37 @@ export interface UserSearchOptions {
603
623
  /** Pre-built wire filter over user attributes. */
604
624
  readonly filter: Filter;
605
625
  }
606
- export declare function userSearch(opts: UserSearchOptions): ActionDef<RecordSearchOutput>;
607
- export declare function userGroupSearch(opts: UserSearchOptions): ActionDef<RecordSearchOutput>;
626
+ /** The first user a user search found. */
627
+ export interface FoundUserShape {
628
+ readonly id: string;
629
+ readonly name: string;
630
+ readonly email: string;
631
+ readonly managerName: string;
632
+ readonly managerEmail: string;
633
+ }
634
+ /** Outputs of a user search (the platform's "User's Id", "Manager Email", "All found users", …). */
635
+ export interface UserSearchOutput {
636
+ /** `refs["Users Size"]`: how many users matched. */
637
+ readonly count: number;
638
+ readonly user: FoundUserShape;
639
+ readonly users: readonly unknown[];
640
+ }
641
+ export declare function userSearch(opts: UserSearchOptions): ActionDef<UserSearchOutput>;
642
+ export interface UserGroupShape {
643
+ readonly id: string;
644
+ readonly name: string;
645
+ }
646
+ /** Platform output names of a user-group search (`task.<id>.count`, `.group.id`, `.groups`). */
647
+ export interface UserGroupSearchOutput {
648
+ readonly count: number;
649
+ readonly group: UserGroupShape;
650
+ readonly groups: readonly UserGroupShape[];
651
+ }
652
+ export interface UserGroupSearchOptions {
653
+ /** Pre-built wire filter over user-group attributes (`catalog.userGroups.fields`). */
654
+ readonly filter: Filter;
655
+ }
656
+ export declare function userGroupSearch(opts: UserGroupSearchOptions): ActionDef<UserGroupSearchOutput>;
608
657
  export interface SaveAttachmentOptions {
609
658
  readonly record: ValueOrRef<unknown>;
610
659
  readonly file: ValueOrRef<unknown>;
@@ -1,7 +1,7 @@
1
1
  import { serializeValueOrRef } from "../../core/wire/ref-serializer.js";
2
2
  import { isExpr } from "../field/calc/runtime.js";
3
3
  import { renderCalculationExpression, } from "./calculation-expression.js";
4
- import { extractScriptBody, isScriptFile, readScriptFile } from "./script-code.js";
4
+ import { extractScriptBody, isScriptFile, readScriptFile, toPlatformScriptBody } from "./script-code.js";
5
5
  function workflowFields(fields) {
6
6
  return fields.map((f) => {
7
7
  const updateMode = "updateMode" in f ? f.updateMode : undefined;
@@ -17,6 +17,9 @@ function workflowFields(fields) {
17
17
  };
18
18
  });
19
19
  }
20
+ function recordKindOf(target) {
21
+ return target.__kind === "app" || target.__kind === "element" ? { __recordKind: target.__kind } : {};
22
+ }
20
23
  export function recordSearch(opts) {
21
24
  return {
22
25
  key: "recordSearch",
@@ -27,6 +30,7 @@ export function recordSearch(opts) {
27
30
  ...(opts.limit !== undefined ? { limit: opts.limit } : {}),
28
31
  },
29
32
  __recordApp: opts.app.refName,
33
+ ...recordKindOf(opts.app),
30
34
  };
31
35
  }
32
36
  export function tableRecordsSearch(opts) {
@@ -54,6 +58,7 @@ export function createRecord(opts) {
54
58
  ...(opts.record !== undefined ? { recordReference: serializeValueOrRef(opts.record) } : {}),
55
59
  },
56
60
  __recordApp: opts.app.refName,
61
+ ...recordKindOf(opts.app),
57
62
  };
58
63
  }
59
64
  /** Update fields on an existing record. `value: ""` or `value: null` clears a nullable field (including Dropdown). */
@@ -68,6 +73,7 @@ export function updateField(opts) {
68
73
  workflowFields: workflowFields(opts.fields),
69
74
  },
70
75
  __recordApp: opts.app.refName,
76
+ ...recordKindOf(opts.app),
71
77
  };
72
78
  }
73
79
  export function findRelatedRecords(opts) {
@@ -249,21 +255,29 @@ function outputSchemaNode(name, type) {
249
255
  },
250
256
  };
251
257
  }
252
- const properties = type.properties === undefined
253
- ? undefined
254
- : Object.entries(type.properties).map(([propertyName, propertyType]) => outputSchemaNode(propertyName, propertyType));
258
+ return outputSchemaObjectNode(name, type.properties);
259
+ }
260
+ /**
261
+ * The platform's object node. An object with no properties carries no
262
+ * `properties` key: live GraphQL returns `properties: []`, and both ei export
263
+ * and provider import omit the empty list, so emitting `properties = []`
264
+ * would differ from imported state and plan an in-place update. The provider
265
+ * sends the required empty list itself when the key is absent.
266
+ */
267
+ function outputSchemaObjectNode(name, declared) {
268
+ const properties = Object.entries(declared ?? {})
269
+ .map(([propertyName, propertyType]) => outputSchemaNode(propertyName, propertyType));
255
270
  return {
256
271
  object: {
257
272
  ...(name === undefined ? {} : { name }),
258
- ...(properties === undefined ? {} : { properties }),
273
+ ...(properties.length === 0 ? {} : { properties }),
259
274
  },
260
275
  };
261
276
  }
262
277
  /** Map an output schema to the platform's tagged object shape. */
263
278
  function outputSchema(outputs) {
264
279
  const { name: rootName, properties: declared } = normalizeScriptOutputs(outputs);
265
- const properties = Object.entries(declared).map(([name, type]) => outputSchemaNode(name, type));
266
- return { object: { ...(rootName !== undefined ? { name: rootName } : {}), properties } };
280
+ return outputSchemaObjectNode(rootName, declared);
267
281
  }
268
282
  const EXECUTE_SCRIPT_LIST_INPUT_MARKER = "__edkExecuteScriptListInput";
269
283
  /**
@@ -308,7 +322,22 @@ export function executeScriptActionDefWithBody(body, opts) {
308
322
  };
309
323
  }
310
324
  export function executeScript(opts) {
311
- return executeScriptActionDefWithBody(isScriptFile(opts.code) ? readScriptFile(opts.code) : extractScriptBody(opts.code), opts);
325
+ const body = isScriptFile(opts.code)
326
+ ? toPlatformScriptBody(readScriptFile(opts.code), `executeScript scriptFile("${opts.code.path}")`, { stripTypes: false })
327
+ : toPlatformScriptBody(extractScriptBody(opts.code), "executeScript");
328
+ return executeScriptActionDefWithBody(body, opts);
329
+ }
330
+ const TF_VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
331
+ export function requiredSecret(variable) {
332
+ if (!TF_VARIABLE_NAME.test(variable)) {
333
+ throw new Error(`requiredSecret() needs a Terraform variable name (letters, digits, underscore; no leading digit), got ${JSON.stringify(variable)}`);
334
+ }
335
+ return { kind: "requiredSecret", variable };
336
+ }
337
+ export function isRequiredSecret(value) {
338
+ return typeof value === "object" && value !== null &&
339
+ value.kind === "requiredSecret" &&
340
+ typeof value.variable === "string";
312
341
  }
313
342
  function apiRequestHeaders(headers) {
314
343
  return (headers ?? []).map((h) => ({ name: h.name, value: serializeValueOrRef(h.value) }));
@@ -506,7 +535,7 @@ export function notification(opts) {
506
535
  config: {
507
536
  titleReference: serializeValueOrRef(opts.title),
508
537
  messageReference: serializeValueOrRef(opts.message),
509
- ...(opts.description !== undefined ? { description: opts.description } : {}),
538
+ ...(opts.description !== undefined ? { descriptionReference: serializeValueOrRef(opts.description) } : {}),
510
539
  ...(opts.userIds?.length ? { userIds: opts.userIds } : {}),
511
540
  ...(opts.groupIds?.length ? { groupIds: opts.groupIds } : {}),
512
541
  ...(opts.userRefs !== undefined ? { users: refList(opts.userRefs) } : {}),
@@ -8,6 +8,10 @@ export interface AutomationToTfContext {
8
8
  readonly appRefName?: string;
9
9
  /** The product owner kind; defaults to app for direct legacy callers. */
10
10
  readonly parentScope?: "app" | "element";
11
+ /** Element owners only: the element declares `systemFields.audit`. */
12
+ readonly ownerAuditFields?: boolean;
13
+ /** RefNames of the workspace's elements without `systemFields.audit`. */
14
+ readonly elementsWithoutAuditFields?: ReadonlySet<string>;
11
15
  readonly appTfLabel: string;
12
16
  readonly fieldAddresses?: ReadonlyMap<string, string>;
13
17
  readonly fieldNames?: ReadonlyMap<string, string>;