sf-plugin-data 0.1.0 → 0.2.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 (269) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +572 -240
  3. package/docs/artifact-format.md +527 -633
  4. package/docs/capabilities.md +1159 -168
  5. package/docs/git-workflow.md +135 -12
  6. package/docs/handover.md +7826 -12
  7. package/lib/api.d.ts +7 -0
  8. package/lib/api.js +7 -0
  9. package/lib/artifacts/code-fields.d.ts +49 -0
  10. package/lib/artifacts/code-fields.js +142 -0
  11. package/lib/artifacts/data-graph-document.d.ts +29 -0
  12. package/lib/artifacts/data-graph-document.js +52 -0
  13. package/lib/artifacts/data-space-field.d.ts +65 -0
  14. package/lib/artifacts/data-space-field.js +98 -0
  15. package/lib/artifacts/data-stream-document.d.ts +264 -0
  16. package/lib/artifacts/data-stream-document.js +680 -0
  17. package/lib/artifacts/data-transform-document.d.ts +152 -0
  18. package/lib/artifacts/data-transform-document.js +560 -0
  19. package/lib/artifacts/dependency-selection.d.ts +51 -0
  20. package/lib/artifacts/dependency-selection.js +154 -0
  21. package/lib/artifacts/dlo-document.d.ts +93 -0
  22. package/lib/artifacts/dlo-document.js +253 -0
  23. package/lib/artifacts/enum-case.d.ts +39 -0
  24. package/lib/artifacts/enum-case.js +67 -0
  25. package/lib/artifacts/git-deploy-selection.d.ts +68 -0
  26. package/lib/artifacts/git-deploy-selection.js +474 -0
  27. package/lib/artifacts/identity-resolution-document.d.ts +133 -0
  28. package/lib/artifacts/identity-resolution-document.js +625 -0
  29. package/lib/artifacts/mapping-document.d.ts +1 -0
  30. package/lib/artifacts/mapping-document.js +1 -0
  31. package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
  32. package/lib/artifacts/native-calculated-insight-document.js +321 -0
  33. package/lib/artifacts/native-data-graph-document.d.ts +124 -0
  34. package/lib/artifacts/native-data-graph-document.js +780 -0
  35. package/lib/artifacts/native-dmo-document.d.ts +151 -0
  36. package/lib/artifacts/native-dmo-document.js +313 -0
  37. package/lib/artifacts/native-mapping-document.d.ts +67 -0
  38. package/lib/artifacts/native-mapping-document.js +187 -0
  39. package/lib/artifacts/native-relationship-document.d.ts +76 -0
  40. package/lib/artifacts/native-relationship-document.js +232 -0
  41. package/lib/artifacts/path-selector.d.ts +55 -0
  42. package/lib/artifacts/path-selector.js +167 -0
  43. package/lib/artifacts/read-deploy-input.d.ts +222 -6
  44. package/lib/artifacts/read-deploy-input.js +1213 -53
  45. package/lib/artifacts/segment-document.d.ts +183 -0
  46. package/lib/artifacts/segment-document.js +570 -0
  47. package/lib/artifacts/verbatim-document.d.ts +203 -0
  48. package/lib/artifacts/verbatim-document.js +339 -0
  49. package/lib/artifacts/write-data-graph.d.ts +17 -0
  50. package/lib/artifacts/write-data-graph.js +162 -0
  51. package/lib/artifacts/write-data-stream.d.ts +11 -0
  52. package/lib/artifacts/write-data-stream.js +175 -0
  53. package/lib/artifacts/write-data-transform.d.ts +11 -0
  54. package/lib/artifacts/write-data-transform.js +180 -0
  55. package/lib/artifacts/write-dlo.d.ts +11 -0
  56. package/lib/artifacts/write-dlo.js +158 -0
  57. package/lib/artifacts/write-identity-resolution.d.ts +18 -0
  58. package/lib/artifacts/write-identity-resolution.js +165 -0
  59. package/lib/artifacts/write-mapping-definition.d.ts +17 -0
  60. package/lib/artifacts/write-mapping-definition.js +127 -0
  61. package/lib/artifacts/write-member-export.d.ts +88 -0
  62. package/lib/artifacts/write-member-export.js +199 -0
  63. package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
  64. package/lib/artifacts/write-native-calculated-insight.js +176 -0
  65. package/lib/artifacts/write-native-dmo.d.ts +11 -0
  66. package/lib/artifacts/write-native-dmo.js +158 -0
  67. package/lib/artifacts/write-native-mapping.d.ts +11 -0
  68. package/lib/artifacts/write-native-mapping.js +157 -0
  69. package/lib/artifacts/write-native-relationship.d.ts +11 -0
  70. package/lib/artifacts/write-native-relationship.js +157 -0
  71. package/lib/artifacts/write-segment.d.ts +26 -0
  72. package/lib/artifacts/write-segment.js +212 -0
  73. package/lib/commands/data360/delete.d.ts +280 -0
  74. package/lib/commands/data360/delete.js +2297 -0
  75. package/lib/commands/data360/deploy.d.ts +234 -15
  76. package/lib/commands/data360/deploy.js +2292 -100
  77. package/lib/commands/data360/publish.d.ts +93 -0
  78. package/lib/commands/data360/publish.js +292 -0
  79. package/lib/commands/data360/retrieve.d.ts +260 -13
  80. package/lib/commands/data360/retrieve.js +1880 -85
  81. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  82. package/lib/commands/data360/segment/members/export.js +318 -0
  83. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  84. package/lib/errors/codes/calculated-insight.js +25 -0
  85. package/lib/errors/codes/data-graph.d.ts +2 -0
  86. package/lib/errors/codes/data-graph.js +22 -0
  87. package/lib/errors/codes/data-stream.d.ts +2 -0
  88. package/lib/errors/codes/data-stream.js +70 -0
  89. package/lib/errors/codes/data-transform.d.ts +2 -0
  90. package/lib/errors/codes/data-transform.js +35 -0
  91. package/lib/errors/codes/dependency.d.ts +2 -0
  92. package/lib/errors/codes/dependency.js +11 -0
  93. package/lib/errors/codes/dlo.d.ts +2 -0
  94. package/lib/errors/codes/dlo.js +31 -0
  95. package/lib/errors/codes/dmo.d.ts +2 -0
  96. package/lib/errors/codes/dmo.js +28 -0
  97. package/lib/errors/codes/general.d.ts +2 -0
  98. package/lib/errors/codes/general.js +57 -0
  99. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  100. package/lib/errors/codes/identity-resolution.js +24 -0
  101. package/lib/errors/codes/mapping.d.ts +2 -0
  102. package/lib/errors/codes/mapping.js +42 -0
  103. package/lib/errors/codes/relationship.d.ts +2 -0
  104. package/lib/errors/codes/relationship.js +21 -0
  105. package/lib/errors/codes/segment.d.ts +2 -0
  106. package/lib/errors/codes/segment.js +49 -0
  107. package/lib/errors/registry.d.ts +60 -0
  108. package/lib/errors/registry.js +123 -0
  109. package/lib/plugin.d.ts +1 -0
  110. package/lib/plugin.js +3 -1
  111. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  112. package/lib/services/acquire-retrieve-selection.js +145 -0
  113. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  114. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  115. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  116. package/lib/services/bind-segment-dependencies.js +115 -0
  117. package/lib/services/bounded-reads.d.ts +17 -0
  118. package/lib/services/bounded-reads.js +42 -0
  119. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  120. package/lib/services/calculated-insight-sql-checks.js +193 -0
  121. package/lib/services/command-dlo.d.ts +48 -0
  122. package/lib/services/command-dlo.js +103 -0
  123. package/lib/services/command-native-data-graph.d.ts +54 -0
  124. package/lib/services/command-native-data-graph.js +485 -0
  125. package/lib/services/command-native-data-stream.d.ts +104 -0
  126. package/lib/services/command-native-data-stream.js +257 -0
  127. package/lib/services/command-native-dmo.d.ts +124 -0
  128. package/lib/services/command-native-dmo.js +338 -0
  129. package/lib/services/command-native-mapping.d.ts +65 -0
  130. package/lib/services/command-native-mapping.js +129 -0
  131. package/lib/services/command-native-relationship.d.ts +46 -0
  132. package/lib/services/command-native-relationship.js +103 -0
  133. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  134. package/lib/services/cross-dataspace-deploy.js +493 -0
  135. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  136. package/lib/services/cross-dataspace-rename.js +1314 -0
  137. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  138. package/lib/services/cross-dataspace-sql.js +1301 -0
  139. package/lib/services/cross-space-context.d.ts +23 -0
  140. package/lib/services/cross-space-context.js +36 -0
  141. package/lib/services/crud-plan.d.ts +137 -0
  142. package/lib/services/crud-plan.js +408 -0
  143. package/lib/services/data-space-check.d.ts +89 -0
  144. package/lib/services/data-space-check.js +162 -0
  145. package/lib/services/data-space-prefix.d.ts +77 -0
  146. package/lib/services/data-space-prefix.js +127 -0
  147. package/lib/services/data-transform-space.d.ts +31 -0
  148. package/lib/services/data-transform-space.js +79 -0
  149. package/lib/services/delete-calculated-insight.d.ts +44 -0
  150. package/lib/services/delete-calculated-insight.js +101 -0
  151. package/lib/services/delete-data-transform.d.ts +52 -0
  152. package/lib/services/delete-data-transform.js +222 -0
  153. package/lib/services/delete-dmo-field.d.ts +211 -0
  154. package/lib/services/delete-dmo-field.js +472 -0
  155. package/lib/services/delete-identity-resolution.d.ts +43 -0
  156. package/lib/services/delete-identity-resolution.js +295 -0
  157. package/lib/services/delete-segment.d.ts +42 -0
  158. package/lib/services/delete-segment.js +248 -0
  159. package/lib/services/deploy-result.d.ts +54 -0
  160. package/lib/services/deploy-result.js +60 -0
  161. package/lib/services/escaped-copy.d.ts +23 -0
  162. package/lib/services/escaped-copy.js +88 -0
  163. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  164. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  165. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  166. package/lib/services/execute-data-transform-deploy.js +168 -0
  167. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  168. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  169. package/lib/services/execute-segment-deploy.d.ts +45 -0
  170. package/lib/services/execute-segment-deploy.js +393 -0
  171. package/lib/services/local-file-removal.d.ts +36 -0
  172. package/lib/services/local-file-removal.js +103 -0
  173. package/lib/services/native-calculated-insight.d.ts +87 -0
  174. package/lib/services/native-calculated-insight.js +164 -0
  175. package/lib/services/native-crm-data-stream.d.ts +91 -0
  176. package/lib/services/native-crm-data-stream.js +272 -0
  177. package/lib/services/native-data-graph-context.d.ts +12 -0
  178. package/lib/services/native-data-graph-context.js +139 -0
  179. package/lib/services/native-data-graph-crd.d.ts +261 -0
  180. package/lib/services/native-data-graph-crd.js +866 -0
  181. package/lib/services/native-data-stream.d.ts +329 -0
  182. package/lib/services/native-data-stream.js +1830 -0
  183. package/lib/services/native-dlo.d.ts +163 -0
  184. package/lib/services/native-dlo.js +402 -0
  185. package/lib/services/native-dmo.d.ts +191 -0
  186. package/lib/services/native-dmo.js +614 -0
  187. package/lib/services/native-mapping.d.ts +255 -0
  188. package/lib/services/native-mapping.js +1226 -0
  189. package/lib/services/native-relationship.d.ts +132 -0
  190. package/lib/services/native-relationship.js +512 -0
  191. package/lib/services/operation-diagnostic.d.ts +83 -0
  192. package/lib/services/operation-diagnostic.js +272 -0
  193. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  194. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  195. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  196. package/lib/services/preflight-data-transform-deploy.js +104 -0
  197. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  198. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  199. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  200. package/lib/services/preflight-segment-deploy.js +109 -0
  201. package/lib/services/publish-calculated-insight.d.ts +40 -0
  202. package/lib/services/publish-calculated-insight.js +95 -0
  203. package/lib/services/publish-segment.d.ts +65 -0
  204. package/lib/services/publish-segment.js +194 -0
  205. package/lib/services/readback-pace.d.ts +16 -0
  206. package/lib/services/readback-pace.js +23 -0
  207. package/lib/services/retrieve-data-transform.d.ts +26 -0
  208. package/lib/services/retrieve-data-transform.js +65 -0
  209. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  210. package/lib/services/retrieve-identity-resolution.js +87 -0
  211. package/lib/services/retrieve-inventory.d.ts +32 -0
  212. package/lib/services/retrieve-inventory.js +151 -0
  213. package/lib/services/retrieve-segment.d.ts +120 -0
  214. package/lib/services/retrieve-segment.js +502 -0
  215. package/lib/services/segment-lookup.d.ts +46 -0
  216. package/lib/services/segment-lookup.js +108 -0
  217. package/lib/services/segment-members.d.ts +144 -0
  218. package/lib/services/segment-members.js +402 -0
  219. package/lib/services/select-native-retrieve.d.ts +60 -0
  220. package/lib/services/select-native-retrieve.js +226 -0
  221. package/lib/services/settle-calculated-insight.d.ts +22 -0
  222. package/lib/services/settle-calculated-insight.js +53 -0
  223. package/lib/services/sql-tokens.d.ts +58 -0
  224. package/lib/services/sql-tokens.js +147 -0
  225. package/lib/transport/api-version.d.ts +36 -0
  226. package/lib/transport/api-version.js +89 -0
  227. package/lib/transport/bound-ssot.d.ts +27 -0
  228. package/lib/transport/bound-ssot.js +116 -0
  229. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  230. package/lib/transport/calculated-insight-rest.js +62 -0
  231. package/lib/transport/connect-client.d.ts +94 -32
  232. package/lib/transport/connect-client.js +318 -178
  233. package/lib/transport/connect-diagnostic.d.ts +89 -0
  234. package/lib/transport/connect-diagnostic.js +331 -0
  235. package/lib/transport/data-graph-rest.d.ts +27 -0
  236. package/lib/transport/data-graph-rest.js +76 -0
  237. package/lib/transport/data-stream-rest.d.ts +62 -0
  238. package/lib/transport/data-stream-rest.js +348 -0
  239. package/lib/transport/data-transform-rest.d.ts +25 -0
  240. package/lib/transport/data-transform-rest.js +100 -0
  241. package/lib/transport/dlo-native-rest.d.ts +22 -0
  242. package/lib/transport/dlo-native-rest.js +89 -0
  243. package/lib/transport/dlo-rest.d.ts +23 -0
  244. package/lib/transport/dlo-rest.js +135 -0
  245. package/lib/transport/dmo-native-rest.d.ts +18 -0
  246. package/lib/transport/dmo-native-rest.js +55 -0
  247. package/lib/transport/dmo-rest.d.ts +30 -0
  248. package/lib/transport/dmo-rest.js +163 -0
  249. package/lib/transport/mapping-rest.d.ts +63 -0
  250. package/lib/transport/mapping-rest.js +341 -0
  251. package/lib/transport/project-metadata.d.ts +36 -0
  252. package/lib/transport/project-metadata.js +118 -0
  253. package/lib/transport/relationship-rest.d.ts +43 -0
  254. package/lib/transport/relationship-rest.js +201 -0
  255. package/package.json +29 -6
  256. package/lib/artifacts/dmo-document.d.ts +0 -181
  257. package/lib/artifacts/dmo-document.js +0 -848
  258. package/lib/artifacts/dmo-update-delta.d.ts +0 -28
  259. package/lib/artifacts/dmo-update-delta.js +0 -86
  260. package/lib/artifacts/write-other-dmo.d.ts +0 -17
  261. package/lib/artifacts/write-other-dmo.js +0 -140
  262. package/lib/services/execute-dmo-create.d.ts +0 -24
  263. package/lib/services/execute-dmo-create.js +0 -118
  264. package/lib/services/execute-dmo-deploy.d.ts +0 -33
  265. package/lib/services/execute-dmo-deploy.js +0 -197
  266. package/lib/services/preflight-dmo-deploy.d.ts +0 -69
  267. package/lib/services/preflight-dmo-deploy.js +0 -161
  268. package/lib/services/retrieve-other-dmo.d.ts +0 -46
  269. package/lib/services/retrieve-other-dmo.js +0 -140
@@ -0,0 +1,625 @@
1
+ import { identityResolutionName } from './path-selector.js';
2
+ import { isDeepStrictEqual } from 'node:util';
3
+ import { crossSpaceSentence, explainInput, printableKey, } from '../services/operation-diagnostic.js';
4
+ import { dataSpaceKey, isDataSpaceName, readSingleDataSpace } from './data-space-field.js';
5
+ /** Refuse unsupported IR shapes without retaining payloads. */
6
+ export class IdentityResolutionError extends Error {
7
+ code;
8
+ constructor(code) {
9
+ super('Identity resolution configuration could not be admitted.');
10
+ this.code = code;
11
+ this.name = 'IdentityResolutionError';
12
+ }
13
+ }
14
+ const dmoName = /^[A-Za-z][A-Za-z0-9_]*__dlm$/u;
15
+ const objectName = /^[A-Za-z][A-Za-z0-9_]*$/u;
16
+ // Documents keep the established PascalCase spelling of these API values; the API answers
17
+ // in lowercase. Values outside these lists are kept exactly as the API returns them.
18
+ const matchMethods = ['Fuzzy', 'Exact', 'ExactNormalized'];
19
+ const ruleTypes = ['LastUpdated', 'MostFrequent', 'SourceSequence'];
20
+ const configurationTypes = ['Individual'];
21
+ const unsupported = 'UNSUPPORTED_IDENTITY_RESOLUTION_CONFIGURATION';
22
+ /**
23
+ * Enforce a payload-free invariant; with a key path, the refusal names it.
24
+ * @param {unknown} condition Required invariant.
25
+ * @param {string} [keyPath] Printable key path of an authored file.
26
+ * @param {string} [problem] What is wrong with it.
27
+ */
28
+ function requireValid(condition, keyPath, problem) {
29
+ if (condition)
30
+ return;
31
+ const error = new IdentityResolutionError(unsupported);
32
+ if (keyPath !== undefined)
33
+ explainInput(error, `The identity resolution file cannot be deployed: ${keyPath} ${problem ?? 'is not valid'}. Correct the file, or retrieve the ruleset again once the plugin supports it.`);
34
+ throw error;
35
+ }
36
+ /**
37
+ * Check bounded inert JSON before reading properties or cloning.
38
+ * @param {unknown} value Candidate content.
39
+ * @param {Set<object>} ancestors Current recursion path.
40
+ * @param {number} depth Current depth.
41
+ */
42
+ function json(value, ancestors = new Set(), depth = 0) {
43
+ requireValid(depth <= 20);
44
+ if (value === null ||
45
+ typeof value === 'boolean' ||
46
+ (typeof value === 'number' && Number.isFinite(value)))
47
+ return;
48
+ if (typeof value === 'string') {
49
+ requireValid(value.length <= 262_144);
50
+ return;
51
+ }
52
+ requireValid(value && typeof value === 'object' && !ancestors.has(value));
53
+ requireValid(Object.getPrototypeOf(value) === (Array.isArray(value) ? Array.prototype : Object.prototype));
54
+ ancestors.add(value);
55
+ const keys = Reflect.ownKeys(value);
56
+ requireValid(keys.length <= 256);
57
+ for (const key of keys) {
58
+ if (Array.isArray(value) && key === 'length')
59
+ continue;
60
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
61
+ requireValid(typeof key === 'string' &&
62
+ key !== 'toJSON' &&
63
+ descriptor?.enumerable &&
64
+ 'value' in descriptor);
65
+ json(descriptor.value, ancestors, depth + 1);
66
+ }
67
+ if (Array.isArray(value))
68
+ requireValid(Object.keys(value).length === value.length);
69
+ ancestors.delete(value);
70
+ }
71
+ /**
72
+ * Admit a record with all of its required keys. A closed record also rejects every other key;
73
+ * an open one (retrieve) keeps them. With a key path, the refusal names the key.
74
+ * @param {unknown} value Candidate record.
75
+ * @param {string[]} keys Required (and, when closed, complete) key inventory.
76
+ * @param {boolean} [open] Whether keys outside `keys` are kept.
77
+ * @param {string} [keyPath] Printable path of an authored record.
78
+ * @returns {Record<string, unknown>} Checked record.
79
+ */
80
+ function record(value, keys, open = false, keyPath) {
81
+ requireValid(value && typeof value === 'object' && !Array.isArray(value), keyPath, 'is not an object');
82
+ const result = value;
83
+ const at = (key) => keyPath === undefined ? undefined : `${keyPath}.${printableKey(key)}`;
84
+ const missing = keys.find((key) => !Object.hasOwn(result, key));
85
+ requireValid(missing === undefined, at(missing ?? ''), 'is missing');
86
+ const unknown = open ? undefined : Object.keys(result).find((key) => !keys.includes(key));
87
+ requireValid(unknown === undefined, at(unknown ?? ''), 'is not a key an identity resolution file can hold');
88
+ return result;
89
+ }
90
+ /**
91
+ * The keys of a native record the projection does not map, to keep on retrieve. A key that the
92
+ * projected document already uses could not be told apart from it and is refused.
93
+ * @param {Record<string, unknown>} item Native record.
94
+ * @param {string[]} known Native keys the projection maps.
95
+ * @param {string[]} projected Keys of the projected document record.
96
+ * @returns {Record<string, unknown>} Unmapped keys in read order.
97
+ */
98
+ function extras(item, known, projected) {
99
+ const entries = Object.entries(item).filter(([key]) => !known.includes(key));
100
+ requireValid(entries.every(([key]) => !projected.includes(key)));
101
+ return Object.fromEntries(entries.map(([key, value]) => [key, structuredClone(value)]));
102
+ }
103
+ /**
104
+ * Validate display text without changing bytes.
105
+ * @param {unknown} value Candidate text.
106
+ * @param {string} keyPath Printable key path.
107
+ * @param {boolean} empty Whether empty text is admitted.
108
+ */
109
+ function text(value, keyPath, empty = false) {
110
+ requireValid(typeof value === 'string' && (empty || value.trim().length > 0), keyPath, empty ? 'is not text' : 'is not non-empty text');
111
+ }
112
+ /**
113
+ * The entries of a list, or none for a `null` list that retrieve keeps as read.
114
+ * @param {unknown} value Candidate list.
115
+ * @param {string} keyPath Printable key path.
116
+ * @param {boolean} lenient Whether `null` is kept.
117
+ * @returns {unknown[]} Entries to check.
118
+ */
119
+ function list(value, keyPath, lenient) {
120
+ if (lenient && value === null)
121
+ return [];
122
+ requireValid(Array.isArray(value), keyPath, 'is not a list');
123
+ return value;
124
+ }
125
+ /**
126
+ * Validate the complete observed portable variant and return detached data. Retrieve mode keeps
127
+ * keys the plugin does not model and `null` values, and checks only what places the file and
128
+ * builds its structure; deploy checks every type, name and uniqueness rule and names the key path.
129
+ * @param {unknown} value Portable content, never a raw response.
130
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps unknown keys and nulls).
131
+ * @returns {IdentityResolutionDocument} Checked detached document.
132
+ */
133
+ export function validateIdentityResolutionDocument(value, mode = 'deploy') {
134
+ const lenient = mode === 'retrieve';
135
+ if (!lenient)
136
+ json(value);
137
+ requireValid(value && typeof value === 'object' && !Array.isArray(value), '[document]', 'is not an object');
138
+ legacySpace(value.identity, 'identity');
139
+ readSingleDataSpace(value, refuseFile);
140
+ const root = record(value, ['schemaVersion', 'kind', dataSpaceKey, 'identity', 'spec'], false, '[document]');
141
+ const identity = record(root.identity, ['apiName'], false, 'identity');
142
+ requireValid(root.schemaVersion === 1 &&
143
+ root.kind === 'identity-resolution' &&
144
+ typeof identity.apiName === 'string' &&
145
+ identityResolutionName.test(identity.apiName), 'identity', 'is not an identity resolution API name');
146
+ requireValid(root.spec && typeof root.spec === 'object', 'spec', 'is not an object');
147
+ const hasTrustedSources = Object.hasOwn(root.spec, 'trustedSources');
148
+ const spec = record(root.spec, [
149
+ 'configurationType',
150
+ 'label',
151
+ 'description',
152
+ 'doesRunAutomatically',
153
+ 'isCaseSensitive',
154
+ 'secondaryDmo',
155
+ 'filters',
156
+ 'matchRules',
157
+ 'reconciliationRules',
158
+ ...(hasTrustedSources && !lenient ? ['trustedSources'] : []),
159
+ ], lenient, 'spec');
160
+ if (!lenient) {
161
+ // Filters and trusted sources are sent as authored; the API decides what they may contain.
162
+ requireValid(!hasTrustedSources || Array.isArray(spec.trustedSources), 'spec.trustedSources', 'is not a list');
163
+ requireValid(Array.isArray(spec.filters), 'spec.filters', 'is not a list');
164
+ text(spec.configurationType, 'spec.configurationType');
165
+ requireValid(typeof spec.doesRunAutomatically === 'boolean', 'spec.doesRunAutomatically', 'is not true or false');
166
+ requireValid(typeof spec.isCaseSensitive === 'boolean', 'spec.isCaseSensitive', 'is not true or false');
167
+ text(spec.label, 'spec.label');
168
+ text(spec.description, 'spec.description', true);
169
+ }
170
+ validateDmo(spec.secondaryDmo, 'spec.secondaryDmo', lenient);
171
+ const labels = new Set();
172
+ for (const [index, value] of list(spec.matchRules, 'spec.matchRules', lenient).entries()) {
173
+ const rulePath = `spec.matchRules[${index}]`;
174
+ const rule = record(value, ['label', 'criteria'], lenient, rulePath);
175
+ if (!lenient) {
176
+ text(rule.label, `${rulePath}.label`);
177
+ requireValid(!labels.has(rule.label), `${rulePath}.label`, 'repeats another match rule');
178
+ labels.add(rule.label);
179
+ }
180
+ const seen = new Set();
181
+ for (const [position, value] of list(rule.criteria, `${rulePath}.criteria`, lenient).entries()) {
182
+ const criterionPath = `${rulePath}.criteria[${position}]`;
183
+ const party = value !== null &&
184
+ typeof value === 'object' &&
185
+ Object.hasOwn(value, 'partyIdentificationInfo');
186
+ const criterion = record(value, [
187
+ 'field',
188
+ 'matchMethodType',
189
+ 'caseSensitiveMatch',
190
+ 'shouldMatchOnBlank',
191
+ ...(party ? ['partyIdentificationInfo'] : []),
192
+ ], lenient, criterionPath);
193
+ legacySpace(criterion.field, `${criterionPath}.field`);
194
+ const reference = record(criterion.field, ['kind', 'parentApiName', 'apiName'], false, `${criterionPath}.field`);
195
+ validateField(reference, reference.parentApiName, `${criterionPath}.field`, lenient);
196
+ if (lenient)
197
+ continue;
198
+ const info = criterion.partyIdentificationInfo;
199
+ requireValid(!party || (info && typeof info === 'object' && !Array.isArray(info)), `${criterionPath}.partyIdentificationInfo`, 'is not an object');
200
+ text(criterion.matchMethodType, `${criterionPath}.matchMethodType`);
201
+ for (const key of ['caseSensitiveMatch', 'shouldMatchOnBlank'])
202
+ requireValid(typeof criterion[key] === 'boolean', `${criterionPath}.${key}`, 'is not true or false');
203
+ const key = `${String(reference.parentApiName)}.${String(reference.apiName)}`;
204
+ requireValid(!seen.has(key), `${criterionPath}.field`, 'repeats another criterion field');
205
+ seen.add(key);
206
+ }
207
+ }
208
+ // Outputs are identified by owner, entity and role, so each entity appears once.
209
+ const reconciled = new Set();
210
+ for (const [index, value] of list(spec.reconciliationRules, 'spec.reconciliationRules', lenient).entries()) {
211
+ const rulePath = `spec.reconciliationRules[${index}]`;
212
+ const reconciliation = record(value, ['entity', 'ruleType', 'shouldIgnoreEmptyValue', 'fields', 'sources', 'outputs'], lenient, rulePath);
213
+ validateDmo(reconciliation.entity, `${rulePath}.entity`, lenient);
214
+ const entity = reconciliation.entity.apiName;
215
+ if (!lenient)
216
+ requireValid(!reconciled.has(entity), `${rulePath}.entity`, 'repeats another reconciliation rule');
217
+ reconciled.add(entity);
218
+ validateSettings(reconciliation, rulePath, lenient);
219
+ const seen = new Set();
220
+ for (const [position, value] of list(reconciliation.fields, `${rulePath}.fields`, lenient).entries()) {
221
+ const overridePath = `${rulePath}.fields[${position}]`;
222
+ const override = record(value, ['field', 'ruleType', 'shouldIgnoreEmptyValue', 'sources'], lenient, overridePath);
223
+ legacySpace(override.field, `${overridePath}.field`);
224
+ const reference = record(override.field, ['kind', 'parentApiName', 'apiName'], false, `${overridePath}.field`);
225
+ validateField(reference, entity, `${overridePath}.field`, lenient);
226
+ if (!lenient)
227
+ requireValid(!seen.has(reference.apiName), `${overridePath}.field`, 'repeats another field override');
228
+ seen.add(reference.apiName);
229
+ validateSettings(override, overridePath, lenient);
230
+ }
231
+ if (Array.isArray(reconciliation.outputs))
232
+ for (const [position, output] of reconciliation.outputs.entries())
233
+ if (output && typeof output === 'object') {
234
+ const item = output;
235
+ legacySpace(item.owner, `${rulePath}.outputs[${position}].owner`);
236
+ legacySpace(item.entity, `${rulePath}.outputs[${position}].entity`);
237
+ }
238
+ requireValid(isDeepStrictEqual(reconciliation.outputs, outputs(identity.apiName, entity)), `${rulePath}.outputs`, 'is not the unified and link output of this ruleset and entity');
239
+ }
240
+ return structuredClone(value);
241
+ }
242
+ /**
243
+ * Refuse an identity resolution file problem, naming the key.
244
+ * @param {string} code Refusal code.
245
+ * @param {string} keyPath Key path.
246
+ * @param {string} problem What is wrong with it.
247
+ * @returns {IdentityResolutionError} Refusal with an explanation.
248
+ */
249
+ function refuseFile(code, keyPath, problem) {
250
+ return explainInput(new IdentityResolutionError(code), `The identity resolution file cannot be deployed: ${keyPath} ${problem}. Correct the file, or retrieve the ruleset again.`);
251
+ }
252
+ /**
253
+ * Refuse a `dataSpace` key in the identity or a reference: the old place of the data space.
254
+ * Every reference is in the ruleset's own data space (`c__dataSpace`); files are not migrated.
255
+ * @param {unknown} value Identity or reference.
256
+ * @param {string} keyPath Printable key path.
257
+ */
258
+ function legacySpace(value, keyPath) {
259
+ if (value &&
260
+ typeof value === 'object' &&
261
+ !Array.isArray(value) &&
262
+ Object.hasOwn(value, 'dataSpace'))
263
+ throw refuseFile('LEGACY_DATASPACE_KEY', `${keyPath}.dataSpace`, `is the old place of a data space; a ruleset and everything it names are in the ruleset's data space, the top-level key ${dataSpaceKey}, or retrieve the ruleset again`);
264
+ }
265
+ /**
266
+ * Check a logical DMO reference; deploy also checks its name.
267
+ * @param {unknown} value Candidate reference.
268
+ * @param {string} keyPath Printable key path.
269
+ * @param {boolean} lenient Retrieve mode: any name, `null` included.
270
+ */
271
+ function validateDmo(value, keyPath, lenient) {
272
+ legacySpace(value, keyPath);
273
+ const reference = record(value, ['kind', 'apiName'], false, keyPath);
274
+ requireValid(reference.kind === 'dmo' &&
275
+ (lenient || (typeof reference.apiName === 'string' && dmoName.test(reference.apiName))), keyPath, 'is not a DMO (__dlm)');
276
+ }
277
+ /**
278
+ * Check a logical field against its explicit parent; deploy also checks the names.
279
+ * @param {Record<string, unknown>} reference Logical field.
280
+ * @param {unknown} parent Required parent.
281
+ * @param {string} keyPath Printable key path.
282
+ * @param {boolean} lenient Retrieve mode: any names, `null` included.
283
+ */
284
+ function validateField(reference, parent, keyPath, lenient) {
285
+ requireValid(reference.kind === 'dmo-field' &&
286
+ reference.parentApiName === parent &&
287
+ (lenient ||
288
+ (typeof parent === 'string' &&
289
+ dmoName.test(parent) &&
290
+ typeof reference.apiName === 'string' &&
291
+ /^[A-Za-z][A-Za-z0-9_]*__c$/u.test(reference.apiName))), keyPath, 'is not a custom field (__c) of its DMO');
292
+ }
293
+ /**
294
+ * Validate explicit settings without inventing inherited field overrides.
295
+ * @param {Record<string, unknown>} settings Object or explicit field settings.
296
+ * @param {string} keyPath Printable key path.
297
+ * @param {boolean} lenient Retrieve mode: any values, unknown source keys kept.
298
+ */
299
+ function validateSettings(settings, keyPath, lenient) {
300
+ if (!lenient) {
301
+ text(settings.ruleType, `${keyPath}.ruleType`);
302
+ requireValid(typeof settings.shouldIgnoreEmptyValue === 'boolean', `${keyPath}.shouldIgnoreEmptyValue`, 'is not true or false');
303
+ }
304
+ const seen = new Set();
305
+ for (const [index, value] of list(settings.sources, `${keyPath}.sources`, lenient).entries()) {
306
+ const sourcePath = `${keyPath}.sources[${index}]`;
307
+ legacySpace(value, sourcePath);
308
+ const source = record(value, ['kind', 'apiName'], lenient, sourcePath);
309
+ requireValid(source.kind === 'dlo' &&
310
+ (lenient ||
311
+ (typeof source.apiName === 'string' &&
312
+ objectName.test(source.apiName) &&
313
+ !seen.has(source.apiName))), sourcePath, 'is not a unique DLO');
314
+ seen.add(source.apiName);
315
+ }
316
+ }
317
+ /**
318
+ * Build a typed logical DMO reference, not an org-local identity.
319
+ * @param {string} apiName Qualified input API name.
320
+ * @returns {IdentityResolutionDmoReference} Logical reference.
321
+ */
322
+ function dmo(apiName) {
323
+ return { kind: 'dmo', apiName };
324
+ }
325
+ /**
326
+ * Build a typed field reference with explicit parent context.
327
+ * @param {string} parentApiName Parent DMO API name.
328
+ * @param {string} apiName Field API name.
329
+ * @returns {IdentityResolutionFieldReference} Logical reference.
330
+ */
331
+ function field(parentApiName, apiName) {
332
+ return { kind: 'dmo-field', parentApiName, apiName };
333
+ }
334
+ /**
335
+ * Identify generated outputs only through their logical owner, entity and role.
336
+ * @param {string} apiName Authored owner identity.
337
+ * @param {string} entity Reconciliation input entity.
338
+ * @returns {IdentityResolutionOutputIdentity[]} Ordered output identities.
339
+ */
340
+ function outputs(apiName, entity) {
341
+ return ['unified', 'link'].map((role) => ({
342
+ owner: { kind: 'identity-resolution', apiName },
343
+ entity: dmo(entity),
344
+ role,
345
+ }));
346
+ }
347
+ /**
348
+ * The data space a ruleset GET names (`dataSpaceName`): the ruleset's real data space, read
349
+ * before anything is projected. One without a usable one is IDENTITY_RESOLUTION_DATASPACE_UNREADABLE.
350
+ * @param {unknown} native Native response.
351
+ * @returns {string} Data space.
352
+ */
353
+ export function identityResolutionSpace(native) {
354
+ const found = native && typeof native === 'object' && !Array.isArray(native)
355
+ ? native.dataSpaceName
356
+ : undefined;
357
+ if (!isDataSpaceName(found))
358
+ throw new IdentityResolutionError('IDENTITY_RESOLUTION_DATASPACE_UNREADABLE');
359
+ return found;
360
+ }
361
+ /**
362
+ * The refusal of a ruleset whose file, or whose ruleset in the org, is in another data space than
363
+ * the run's.
364
+ * @param {string} apiName Ruleset name.
365
+ * @param {string} found The data space of the file or the org ruleset.
366
+ * @param {string} dataSpace The run's data space.
367
+ * @param {'file' | 'org'} where Whether the file or the org ruleset names `found`.
368
+ * @param {boolean} [crossSpace] A deploy --allow-cross-dataspace can translate: say so.
369
+ * @returns {IdentityResolutionError} IDENTITY_RESOLUTION_DATASPACE_MISMATCH with an explanation.
370
+ */
371
+ export function identityResolutionSpaceMismatch(apiName, found, dataSpace, where, crossSpace = false) {
372
+ return explainInput(new IdentityResolutionError('IDENTITY_RESOLUTION_DATASPACE_MISMATCH'), `${where === 'file' ? `The file of identity resolution ruleset ${apiName} names the data space ${printableKey(found)} in ${dataSpaceKey}` : `Identity resolution ruleset ${apiName} is in the data space ${printableKey(found)} in the org`}, but the run's data space is ${printableKey(dataSpace)} (--dataspace, default "default"). Run the command with --dataspace ${printableKey(found)}${where === 'file' ? ', or correct the file' : ''}. Nothing was written.${crossSpace ? crossSpaceSentence(dataSpace) : ''}`);
373
+ }
374
+ /**
375
+ * Project the genuine API68 owner.
376
+ * @param {unknown} native Exact native owner response.
377
+ * @param {string} apiName Requested owner API name.
378
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps unknown keys and nulls).
379
+ * @returns {IdentityResolutionProjection} Portable definition and private owner expectations.
380
+ */
381
+ export function projectNativeIdentityResolution(native, apiName, mode = 'deploy') {
382
+ return projectOwner(native, apiName, mode);
383
+ }
384
+ /**
385
+ * Map an API enum to the document spelling: known values case-insensitively, others unchanged.
386
+ * Retrieve keeps a value that is not text as read.
387
+ * @param {unknown} value API value.
388
+ * @param {string[]} known Document spellings.
389
+ * @param {boolean} lenient Retrieve mode.
390
+ * @returns {string} Document value.
391
+ */
392
+ function canonical(value, known, lenient) {
393
+ if (lenient && typeof value !== 'string')
394
+ return value;
395
+ requireValid(typeof value === 'string' && (lenient || value.trim().length > 0));
396
+ return known.find((item) => item.toLowerCase() === value.toLowerCase()) ?? value;
397
+ }
398
+ // Read-only run statistics the API adds once a ruleset has run; never configuration.
399
+ const runtimeKeys = new Set([
400
+ 'anonymousUnifiedProfiles',
401
+ 'consolidationRate',
402
+ 'knownUnifiedProfiles',
403
+ 'lastJobCompleted',
404
+ 'lastJobStatus',
405
+ 'matchedSourceProfiles',
406
+ 'sourceProfiles',
407
+ 'totalUnifiedProfiles',
408
+ ]);
409
+ const ownerKeys = [
410
+ 'configurationType',
411
+ 'dataSpaceName',
412
+ 'description',
413
+ 'doesRunAutomatically',
414
+ 'filters',
415
+ 'id',
416
+ 'isCaseSensitive',
417
+ 'label',
418
+ 'matchRules',
419
+ 'objectApiName',
420
+ 'reconciliationRules',
421
+ 'rulesetId',
422
+ 'rulesetStatus',
423
+ 'secondaryDmo',
424
+ 'trustedSources',
425
+ ];
426
+ const criterionKeys = [
427
+ 'caseSensitiveMatch',
428
+ 'entityName',
429
+ 'fieldName',
430
+ 'matchMethodType',
431
+ 'shouldMatchOnBlank',
432
+ ];
433
+ const settingKeys = ['ruleType', 'shouldIgnoreEmptyValue', 'sources'];
434
+ /**
435
+ * The owner as the API returns it, without the run statistics it adds after a run: what a
436
+ * by-name delete of a verbatim file compares between its reads.
437
+ * @param {unknown} native Native response.
438
+ * @returns {Record<string, unknown>} Detached owner.
439
+ */
440
+ export function observeIdentityResolutionOwner(native) {
441
+ if (!native || typeof native !== 'object' || Array.isArray(native))
442
+ throw new IdentityResolutionError('INCOMPLETE_IDENTITY_RESOLUTION');
443
+ return structuredClone(Object.fromEntries(Object.entries(native).filter(([key]) => !runtimeKeys.has(key))));
444
+ }
445
+ /**
446
+ * Project the owner the API returns. Retrieve mode requires the configuration keys but keeps
447
+ * unknown owner and nested keys (after the known ones), `null` values and any names, so only a
448
+ * missing key or a shape that is not a list or object stops the projection (the ruleset is then
449
+ * written verbatim).
450
+ * @param {unknown} native Native response.
451
+ * @param {string} apiName Requested identity.
452
+ * @param {DocumentMode} mode Check mode.
453
+ * @returns {IdentityResolutionProjection} Checked projection.
454
+ */
455
+ function projectOwner(native, apiName, mode) {
456
+ const lenient = mode === 'retrieve';
457
+ if (!lenient)
458
+ json(native);
459
+ requireValid(typeof apiName === 'string' && identityResolutionName.test(apiName));
460
+ requireValid(native && typeof native === 'object' && !Array.isArray(native));
461
+ // The ruleset's own data space is read before anything else is projected.
462
+ const dataSpace = identityResolutionSpace(native);
463
+ const has = (key) => Object.hasOwn(native, key);
464
+ // Native68 may omit filters, trustedSources, description and (default owner) rulesetId.
465
+ const optional = new Set(['filters', 'rulesetId', 'description', 'trustedSources']);
466
+ const observed = Object.fromEntries(Object.entries(native).filter(([key]) => !runtimeKeys.has(key)));
467
+ const raw = record(observed, ownerKeys.filter((key) => !optional.has(key) || has(key)), lenient);
468
+ const rows = (value) => {
469
+ // eslint-disable-next-line unicorn/no-null -- Retrieve keeps a list the API returns as null.
470
+ if (lenient && value === null)
471
+ return null;
472
+ requireValid(Array.isArray(value));
473
+ return value;
474
+ };
475
+ if (!lenient) {
476
+ requireValid(raw.rulesetId === undefined ||
477
+ (typeof raw.rulesetId === 'string' && raw.rulesetId.trim().length > 0));
478
+ requireValid(typeof raw.secondaryDmo === 'string');
479
+ requireValid(typeof raw.id === 'string' && raw.id.trim().length > 0);
480
+ requireValid(typeof raw.rulesetStatus === 'string' && raw.rulesetStatus.trim().length > 0);
481
+ }
482
+ requireValid(raw.objectApiName === apiName);
483
+ const matchRules = rows(raw.matchRules)?.map((value) => {
484
+ const match = record(value, ['criteria', 'label'], lenient);
485
+ const criteria = rows(match.criteria)?.map((value) => {
486
+ const party = value !== null &&
487
+ typeof value === 'object' &&
488
+ Object.hasOwn(value, 'partyIdentificationInfo');
489
+ const item = record(value, [...criterionKeys, ...(party ? ['partyIdentificationInfo'] : [])], lenient);
490
+ if (!lenient)
491
+ requireValid(typeof item.entityName === 'string' && typeof item.fieldName === 'string');
492
+ return {
493
+ field: field(item.entityName, item.fieldName),
494
+ matchMethodType: canonical(item.matchMethodType, matchMethods, lenient),
495
+ caseSensitiveMatch: item.caseSensitiveMatch,
496
+ shouldMatchOnBlank: item.shouldMatchOnBlank,
497
+ ...(party ? { partyIdentificationInfo: item.partyIdentificationInfo } : {}),
498
+ ...extras(item, [...criterionKeys, 'partyIdentificationInfo'], ['field', 'matchMethodType', 'caseSensitiveMatch', 'shouldMatchOnBlank']),
499
+ };
500
+ });
501
+ return {
502
+ label: match.label,
503
+ criteria: criteria ?? match.criteria,
504
+ ...extras(match, ['criteria', 'label'], ['label', 'criteria']),
505
+ };
506
+ });
507
+ const bindings = [];
508
+ const generatedNames = new Set();
509
+ const roles = ['unifiedDmoName', 'linkDmoName'];
510
+ const reconciliationRules = rows(raw.reconciliationRules)?.map((value) => {
511
+ requireValid(value && typeof value === 'object');
512
+ const item = record(value, [
513
+ 'entityName',
514
+ 'fields',
515
+ ...settingKeys,
516
+ // Outputs may not be generated yet; bind only the names the API returns.
517
+ ...roles.filter((key) => Object.hasOwn(value, key)),
518
+ ], lenient);
519
+ if (!lenient)
520
+ requireValid(typeof item.entityName === 'string');
521
+ const entity = item.entityName;
522
+ const identities = outputs(apiName, entity);
523
+ for (const [roleIndex, key] of roles.entries()) {
524
+ const name = item[key];
525
+ if (name === undefined || name === null)
526
+ continue;
527
+ const usable = typeof name === 'string' && dmoName.test(name) && !generatedNames.has(name);
528
+ // Retrieve binds no outputs; a name it cannot use is only left unbound.
529
+ if (lenient && !usable)
530
+ continue;
531
+ requireValid(usable);
532
+ generatedNames.add(name);
533
+ bindings.push({ identity: identities[roleIndex], sourceApiName: name });
534
+ }
535
+ return {
536
+ entity: dmo(entity),
537
+ ...projectSettings(item, lenient),
538
+ fields: projectOverrides(item.fields, entity, lenient),
539
+ outputs: identities,
540
+ ...extras(item, ['entityName', 'fields', ...settingKeys, ...roles], ['entity', 'fields', ...settingKeys, 'outputs']),
541
+ };
542
+ });
543
+ const spec = {
544
+ configurationType: canonical(raw.configurationType, configurationTypes, lenient),
545
+ label: raw.label,
546
+ description: has('description') ? raw.description : '',
547
+ doesRunAutomatically: raw.doesRunAutomatically,
548
+ isCaseSensitive: raw.isCaseSensitive,
549
+ secondaryDmo: dmo(raw.secondaryDmo),
550
+ filters: has('filters') ? raw.filters : [],
551
+ trustedSources: has('trustedSources') ? raw.trustedSources : [],
552
+ matchRules: matchRules ?? raw.matchRules,
553
+ reconciliationRules: reconciliationRules ?? raw.reconciliationRules,
554
+ };
555
+ const candidate = validateIdentityResolutionDocument({
556
+ schemaVersion: 1,
557
+ kind: 'identity-resolution',
558
+ [dataSpaceKey]: dataSpace,
559
+ identity: { apiName: raw.objectApiName },
560
+ spec: { ...spec, ...extras(raw, ownerKeys, Object.keys(spec)) },
561
+ }, mode);
562
+ return {
563
+ candidate,
564
+ expectations: {
565
+ native: structuredClone(raw),
566
+ outputs: structuredClone(bindings),
567
+ },
568
+ };
569
+ }
570
+ /**
571
+ * Map API enum casing to the document spelling and keep ordered source references.
572
+ * @param {Record<string, unknown>} item Exact native settings.
573
+ * @param {boolean} lenient Retrieve mode: `null` sources and unknown source keys kept.
574
+ * @returns {object} Portable settings.
575
+ */
576
+ function projectSettings(item, lenient) {
577
+ if (!(lenient && item.sources === null))
578
+ requireValid(Array.isArray(item.sources));
579
+ return {
580
+ ruleType: canonical(item.ruleType, ruleTypes, lenient),
581
+ shouldIgnoreEmptyValue: item.shouldIgnoreEmptyValue,
582
+ sources: Array.isArray(item.sources)
583
+ ? item.sources.map((value) => {
584
+ const source = record(value, ['name'], lenient);
585
+ return {
586
+ kind: 'dlo',
587
+ apiName: source.name,
588
+ ...extras(source, ['name'], ['kind', 'apiName']),
589
+ };
590
+ })
591
+ : item.sources,
592
+ };
593
+ }
594
+ /**
595
+ * Keep only server-returned explicit field overrides; empty means inheritance.
596
+ * @param {unknown} value Native fields.
597
+ * @param {string} parent Parent entity.
598
+ * @param {boolean} lenient Retrieve mode: `null` and unknown keys kept.
599
+ * @returns {object[]} Portable explicit overrides.
600
+ */
601
+ function projectOverrides(value, parent, lenient) {
602
+ if (lenient && value === null)
603
+ return value;
604
+ requireValid(Array.isArray(value));
605
+ return value.map((value) => {
606
+ const item = record(value, ['fieldName', ...settingKeys], lenient);
607
+ if (!lenient)
608
+ requireValid(typeof item.fieldName === 'string');
609
+ return {
610
+ field: field(parent, item.fieldName),
611
+ ...projectSettings(item, lenient),
612
+ ...extras(item, ['fieldName', ...settingKeys], ['field', ...settingKeys]),
613
+ };
614
+ });
615
+ }
616
+ /**
617
+ * Serialize complete admitted portable content, never private acquisition expectations.
618
+ * @param {unknown} value Portable candidate.
619
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps unknown keys and nulls).
620
+ * @returns {string} Stable JSON bytes with final LF.
621
+ */
622
+ export function serializeIdentityResolutionDocument(value, mode = 'deploy') {
623
+ return `${JSON.stringify(validateIdentityResolutionDocument(value, mode), undefined, 2)}\n`;
624
+ }
625
+ export { identityResolutionName } from './path-selector.js';
@@ -0,0 +1 @@
1
+ export declare const mappingName: RegExp;
@@ -0,0 +1 @@
1
+ export const mappingName = /^[A-Za-z][A-Za-z0-9_]{0,199}$/u;