sf-plugin-data 0.1.0 → 0.3.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 (277) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +618 -240
  3. package/docs/artifact-format.md +528 -633
  4. package/docs/capabilities.md +1160 -168
  5. package/docs/git-workflow.md +135 -12
  6. package/docs/handover.md +7826 -12
  7. package/lib/api.d.ts +13 -0
  8. package/lib/api.js +10 -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 +2347 -0
  75. package/lib/commands/data360/deploy.d.ts +235 -16
  76. package/lib/commands/data360/deploy.js +2339 -102
  77. package/lib/commands/data360/list/dataspace.d.ts +53 -0
  78. package/lib/commands/data360/list/dataspace.js +109 -0
  79. package/lib/commands/data360/publish.d.ts +93 -0
  80. package/lib/commands/data360/publish.js +298 -0
  81. package/lib/commands/data360/retrieve.d.ts +283 -14
  82. package/lib/commands/data360/retrieve.js +1945 -95
  83. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  84. package/lib/commands/data360/segment/members/export.js +320 -0
  85. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  86. package/lib/errors/codes/calculated-insight.js +25 -0
  87. package/lib/errors/codes/data-graph.d.ts +2 -0
  88. package/lib/errors/codes/data-graph.js +22 -0
  89. package/lib/errors/codes/data-stream.d.ts +2 -0
  90. package/lib/errors/codes/data-stream.js +70 -0
  91. package/lib/errors/codes/data-transform.d.ts +2 -0
  92. package/lib/errors/codes/data-transform.js +35 -0
  93. package/lib/errors/codes/dependency.d.ts +2 -0
  94. package/lib/errors/codes/dependency.js +11 -0
  95. package/lib/errors/codes/dlo.d.ts +2 -0
  96. package/lib/errors/codes/dlo.js +31 -0
  97. package/lib/errors/codes/dmo.d.ts +2 -0
  98. package/lib/errors/codes/dmo.js +28 -0
  99. package/lib/errors/codes/general.d.ts +2 -0
  100. package/lib/errors/codes/general.js +58 -0
  101. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  102. package/lib/errors/codes/identity-resolution.js +24 -0
  103. package/lib/errors/codes/mapping.d.ts +2 -0
  104. package/lib/errors/codes/mapping.js +42 -0
  105. package/lib/errors/codes/relationship.d.ts +2 -0
  106. package/lib/errors/codes/relationship.js +21 -0
  107. package/lib/errors/codes/segment.d.ts +2 -0
  108. package/lib/errors/codes/segment.js +49 -0
  109. package/lib/errors/registry.d.ts +60 -0
  110. package/lib/errors/registry.js +123 -0
  111. package/lib/exit-code.d.ts +10 -0
  112. package/lib/exit-code.js +24 -0
  113. package/lib/plugin.d.ts +1 -0
  114. package/lib/plugin.js +3 -1
  115. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  116. package/lib/services/acquire-retrieve-selection.js +145 -0
  117. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  118. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  119. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  120. package/lib/services/bind-segment-dependencies.js +115 -0
  121. package/lib/services/bounded-reads.d.ts +17 -0
  122. package/lib/services/bounded-reads.js +42 -0
  123. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  124. package/lib/services/calculated-insight-sql-checks.js +193 -0
  125. package/lib/services/command-dlo.d.ts +48 -0
  126. package/lib/services/command-dlo.js +103 -0
  127. package/lib/services/command-native-data-graph.d.ts +54 -0
  128. package/lib/services/command-native-data-graph.js +485 -0
  129. package/lib/services/command-native-data-stream.d.ts +104 -0
  130. package/lib/services/command-native-data-stream.js +257 -0
  131. package/lib/services/command-native-dmo.d.ts +124 -0
  132. package/lib/services/command-native-dmo.js +338 -0
  133. package/lib/services/command-native-mapping.d.ts +65 -0
  134. package/lib/services/command-native-mapping.js +129 -0
  135. package/lib/services/command-native-relationship.d.ts +46 -0
  136. package/lib/services/command-native-relationship.js +103 -0
  137. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  138. package/lib/services/cross-dataspace-deploy.js +493 -0
  139. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  140. package/lib/services/cross-dataspace-rename.js +1314 -0
  141. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  142. package/lib/services/cross-dataspace-sql.js +1301 -0
  143. package/lib/services/cross-space-context.d.ts +23 -0
  144. package/lib/services/cross-space-context.js +38 -0
  145. package/lib/services/crud-plan.d.ts +137 -0
  146. package/lib/services/crud-plan.js +408 -0
  147. package/lib/services/data-space-check.d.ts +92 -0
  148. package/lib/services/data-space-check.js +169 -0
  149. package/lib/services/data-space-prefix.d.ts +77 -0
  150. package/lib/services/data-space-prefix.js +127 -0
  151. package/lib/services/data-transform-space.d.ts +31 -0
  152. package/lib/services/data-transform-space.js +79 -0
  153. package/lib/services/delete-calculated-insight.d.ts +44 -0
  154. package/lib/services/delete-calculated-insight.js +101 -0
  155. package/lib/services/delete-data-transform.d.ts +52 -0
  156. package/lib/services/delete-data-transform.js +222 -0
  157. package/lib/services/delete-dmo-field.d.ts +211 -0
  158. package/lib/services/delete-dmo-field.js +472 -0
  159. package/lib/services/delete-identity-resolution.d.ts +43 -0
  160. package/lib/services/delete-identity-resolution.js +295 -0
  161. package/lib/services/delete-segment.d.ts +42 -0
  162. package/lib/services/delete-segment.js +248 -0
  163. package/lib/services/deploy-result.d.ts +54 -0
  164. package/lib/services/deploy-result.js +60 -0
  165. package/lib/services/escaped-copy.d.ts +23 -0
  166. package/lib/services/escaped-copy.js +88 -0
  167. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  168. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  169. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  170. package/lib/services/execute-data-transform-deploy.js +168 -0
  171. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  172. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  173. package/lib/services/execute-segment-deploy.d.ts +45 -0
  174. package/lib/services/execute-segment-deploy.js +393 -0
  175. package/lib/services/list-data-spaces.d.ts +17 -0
  176. package/lib/services/list-data-spaces.js +24 -0
  177. package/lib/services/local-file-removal.d.ts +36 -0
  178. package/lib/services/local-file-removal.js +103 -0
  179. package/lib/services/native-calculated-insight.d.ts +87 -0
  180. package/lib/services/native-calculated-insight.js +164 -0
  181. package/lib/services/native-crm-data-stream.d.ts +91 -0
  182. package/lib/services/native-crm-data-stream.js +272 -0
  183. package/lib/services/native-data-graph-context.d.ts +12 -0
  184. package/lib/services/native-data-graph-context.js +139 -0
  185. package/lib/services/native-data-graph-crd.d.ts +261 -0
  186. package/lib/services/native-data-graph-crd.js +866 -0
  187. package/lib/services/native-data-stream.d.ts +329 -0
  188. package/lib/services/native-data-stream.js +1830 -0
  189. package/lib/services/native-dlo.d.ts +163 -0
  190. package/lib/services/native-dlo.js +402 -0
  191. package/lib/services/native-dmo.d.ts +191 -0
  192. package/lib/services/native-dmo.js +614 -0
  193. package/lib/services/native-mapping.d.ts +255 -0
  194. package/lib/services/native-mapping.js +1226 -0
  195. package/lib/services/native-relationship.d.ts +132 -0
  196. package/lib/services/native-relationship.js +512 -0
  197. package/lib/services/operation-diagnostic.d.ts +83 -0
  198. package/lib/services/operation-diagnostic.js +272 -0
  199. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  200. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  201. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  202. package/lib/services/preflight-data-transform-deploy.js +104 -0
  203. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  204. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  205. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  206. package/lib/services/preflight-segment-deploy.js +109 -0
  207. package/lib/services/publish-calculated-insight.d.ts +40 -0
  208. package/lib/services/publish-calculated-insight.js +95 -0
  209. package/lib/services/publish-segment.d.ts +65 -0
  210. package/lib/services/publish-segment.js +194 -0
  211. package/lib/services/readback-pace.d.ts +16 -0
  212. package/lib/services/readback-pace.js +23 -0
  213. package/lib/services/retrieve-data-transform.d.ts +26 -0
  214. package/lib/services/retrieve-data-transform.js +65 -0
  215. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  216. package/lib/services/retrieve-identity-resolution.js +87 -0
  217. package/lib/services/retrieve-inventory.d.ts +32 -0
  218. package/lib/services/retrieve-inventory.js +151 -0
  219. package/lib/services/retrieve-segment.d.ts +120 -0
  220. package/lib/services/retrieve-segment.js +502 -0
  221. package/lib/services/run-retrieve.d.ts +24 -0
  222. package/lib/services/run-retrieve.js +51 -0
  223. package/lib/services/segment-lookup.d.ts +46 -0
  224. package/lib/services/segment-lookup.js +108 -0
  225. package/lib/services/segment-members.d.ts +144 -0
  226. package/lib/services/segment-members.js +402 -0
  227. package/lib/services/select-native-retrieve.d.ts +60 -0
  228. package/lib/services/select-native-retrieve.js +226 -0
  229. package/lib/services/settle-calculated-insight.d.ts +22 -0
  230. package/lib/services/settle-calculated-insight.js +53 -0
  231. package/lib/services/sql-tokens.d.ts +58 -0
  232. package/lib/services/sql-tokens.js +147 -0
  233. package/lib/transport/api-version.d.ts +36 -0
  234. package/lib/transport/api-version.js +89 -0
  235. package/lib/transport/bound-ssot.d.ts +27 -0
  236. package/lib/transport/bound-ssot.js +116 -0
  237. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  238. package/lib/transport/calculated-insight-rest.js +62 -0
  239. package/lib/transport/connect-client.d.ts +94 -32
  240. package/lib/transport/connect-client.js +318 -178
  241. package/lib/transport/connect-diagnostic.d.ts +89 -0
  242. package/lib/transport/connect-diagnostic.js +331 -0
  243. package/lib/transport/data-graph-rest.d.ts +27 -0
  244. package/lib/transport/data-graph-rest.js +76 -0
  245. package/lib/transport/data-stream-rest.d.ts +62 -0
  246. package/lib/transport/data-stream-rest.js +348 -0
  247. package/lib/transport/data-transform-rest.d.ts +25 -0
  248. package/lib/transport/data-transform-rest.js +100 -0
  249. package/lib/transport/dlo-native-rest.d.ts +22 -0
  250. package/lib/transport/dlo-native-rest.js +89 -0
  251. package/lib/transport/dlo-rest.d.ts +23 -0
  252. package/lib/transport/dlo-rest.js +135 -0
  253. package/lib/transport/dmo-native-rest.d.ts +18 -0
  254. package/lib/transport/dmo-native-rest.js +55 -0
  255. package/lib/transport/dmo-rest.d.ts +30 -0
  256. package/lib/transport/dmo-rest.js +163 -0
  257. package/lib/transport/mapping-rest.d.ts +63 -0
  258. package/lib/transport/mapping-rest.js +341 -0
  259. package/lib/transport/project-metadata.d.ts +36 -0
  260. package/lib/transport/project-metadata.js +118 -0
  261. package/lib/transport/relationship-rest.d.ts +43 -0
  262. package/lib/transport/relationship-rest.js +201 -0
  263. package/package.json +29 -6
  264. package/lib/artifacts/dmo-document.d.ts +0 -181
  265. package/lib/artifacts/dmo-document.js +0 -848
  266. package/lib/artifacts/dmo-update-delta.d.ts +0 -28
  267. package/lib/artifacts/dmo-update-delta.js +0 -86
  268. package/lib/artifacts/write-other-dmo.d.ts +0 -17
  269. package/lib/artifacts/write-other-dmo.js +0 -140
  270. package/lib/services/execute-dmo-create.d.ts +0 -24
  271. package/lib/services/execute-dmo-create.js +0 -118
  272. package/lib/services/execute-dmo-deploy.d.ts +0 -33
  273. package/lib/services/execute-dmo-deploy.js +0 -197
  274. package/lib/services/preflight-dmo-deploy.d.ts +0 -69
  275. package/lib/services/preflight-dmo-deploy.js +0 -161
  276. package/lib/services/retrieve-other-dmo.d.ts +0 -46
  277. package/lib/services/retrieve-other-dmo.js +0 -140
@@ -0,0 +1,107 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ import type { IdentityResolutionDocument } from '../artifacts/identity-resolution-document.js';
3
+ import type { ApiVersionSelection } from '../transport/api-version.js';
4
+ import { bindIdentityResolutionDependencies } from './bind-identity-resolution-dependencies.js';
5
+ /**
6
+ * Admit a complete authored definition for the native68 route; the API decides its settings.
7
+ * @param {unknown} value Complete portable definition.
8
+ * @returns {IdentityResolutionDocument} Detached native68 definition.
9
+ */
10
+ export declare function nativeIdentityResolutionDocument(value: unknown): IdentityResolutionDocument;
11
+ /**
12
+ * Build the CREATE input from the document, never replaying source IDs or generated names.
13
+ * The API names a ruleset `<type>_<rulesetId>` (`<prefix>_<type>_<rulesetId>` outside the
14
+ * default data space, live API 68), so the ruleset ID is everything after the type and its
15
+ * underscore; a name equal to the type creates the default ruleset (no ID). Preflight refuses
16
+ * names that are neither (IDENTITY_RESOLUTION_NAME_TYPE_MISMATCH); outside default a name
17
+ * without the org's prefix, or no prefix at all, is IDENTITY_RESOLUTION_NAME_NOT_STORED.
18
+ * @param {unknown} value Complete native68 portable definition.
19
+ * @param {string} [dataSpacePrefix] The prefix the org's data space list names for the
20
+ * ruleset's data space; required outside default.
21
+ * @returns {Record<string, unknown>} Detached native request, not execution authorization.
22
+ */
23
+ export declare function buildNativeIdentityResolutionCreate(value: unknown, dataSpacePrefix?: string): Record<string, unknown>;
24
+ /**
25
+ * Serialize the complete qualified parent PATCH shape without generated output identities.
26
+ * Empty explicit overrides reset fields to object inheritance; source order is semantic.
27
+ * @param {unknown} value Complete native68 desired definition.
28
+ * @param {unknown} [current] Current target definition, when updating.
29
+ * @returns {Record<string, unknown>} Detached input-shaped configuration.
30
+ */
31
+ export declare function buildNativeIdentityResolutionUpdate(value: unknown, current?: unknown): Record<string, unknown>;
32
+ /**
33
+ * Compare complete configuration while retaining exact logical owner identity.
34
+ * @param {unknown} current Independently projected settled target.
35
+ * @param {unknown} value Complete desired definition.
36
+ * @returns {boolean} Qualified full supported configuration semantic delta.
37
+ */
38
+ export declare function nativeIdentityResolutionConfigurationDelta(current: unknown, value: unknown): boolean;
39
+ export declare const inFlightIdentityResolutionStatuses: string[];
40
+ export type NativeIdentityResolutionPrecreateBinding = {
41
+ phase: 'precreate';
42
+ inputsFingerprint: string;
43
+ fingerprint: string;
44
+ };
45
+ /**
46
+ * Bind desired configuration and verified inputs without guessing future output names.
47
+ * This is drift evidence only, never a substitute for settled owner/output proof.
48
+ * @param {unknown} value Complete qualified native68 source.
49
+ * @param {IdentityResolutionTargetConnection} connection Native68 receiver.
50
+ * @param {ApiVersionSelection} selection Explicit native68 selection.
51
+ * @param {string} dataSpace The run's data space (the ruleset's).
52
+ * @param {Function} verifyDependencies Fresh input identity/field/key verifier.
53
+ * @returns {Promise<NativeIdentityResolutionPrecreateBinding>} Private non-authorizing binding.
54
+ */
55
+ export declare function bindNativeIdentityResolutionPrecreate(value: unknown, connection: IdentityResolutionTargetConnection, selection: ApiVersionSelection, dataSpace: string, verifyDependencies?: typeof bindIdentityResolutionDependencies): Promise<NativeIdentityResolutionPrecreateBinding>;
56
+ type NativeIdentityResolutionExistingPreview = {
57
+ family: 'identity-resolution';
58
+ outcome: 'unchanged' | 'update' | 'blocked' | 'blocked-changes';
59
+ target: 'present' | 'absent' | 'unknown';
60
+ absenceProof: 'none' | 'exact-item-not-found';
61
+ route: {
62
+ apiVersion: '68.0';
63
+ operation: 'identity-resolutions.patch';
64
+ };
65
+ requiredEffects: Array<'processing'>;
66
+ diagnostics: Array<{
67
+ code: string;
68
+ message: string;
69
+ }>;
70
+ };
71
+ export type NativeIdentityResolutionCreatePreview = {
72
+ family: 'identity-resolution';
73
+ outcome: 'create';
74
+ target: 'absent';
75
+ absenceProof: 'exact-item-not-found';
76
+ route: {
77
+ apiVersion: '68.0';
78
+ operation: 'identity-resolutions.post';
79
+ };
80
+ requiredEffects: Array<'processing' | 'generated-output-provisioning'>;
81
+ diagnostics: [];
82
+ precreateBinding: NativeIdentityResolutionPrecreateBinding;
83
+ };
84
+ export type NativeIdentityResolutionPreview = NativeIdentityResolutionExistingPreview | NativeIdentityResolutionCreatePreview;
85
+ /**
86
+ * Read-only native68 admission; exact absence plus compatible input binding previews CREATE.
87
+ * Outputs are allocated by POST and require independent settled owner/output binding afterward.
88
+ * This preview alone is not write authorization; historical public deploy remains separate.
89
+ * @param {unknown} value Complete authored document.
90
+ * @param {IdentityResolutionTargetConnection} connection Explicit native68 receiver.
91
+ * @param {ApiVersionSelection} selection Explicit native68 route.
92
+ * @param {string} dataSpace The run's data space; the file's c__dataSpace and the org
93
+ * ruleset's must be it (IDENTITY_RESOLUTION_DATASPACE_MISMATCH).
94
+ * @param {object} options Private independent dependency reader seam.
95
+ * @param {Function} [options.verifyDependencies] Input-only dependency verification.
96
+ * @returns {Promise<NativeIdentityResolutionPreview>} Payload-free non-authorizing preview.
97
+ */
98
+ export declare function preflightNativeIdentityResolutionDeploy(value: unknown, connection: IdentityResolutionTargetConnection, selection: ApiVersionSelection, dataSpace: string, options?: Pick<IdentityResolutionPreflightOptions, 'verifyDependencies'> & {
99
+ verifyPrecreateInputs?: typeof bindIdentityResolutionDependencies;
100
+ /** The prefix of the run's data space as the org's list names it; required outside default. */
101
+ dataSpacePrefix?: string;
102
+ }): Promise<NativeIdentityResolutionPreview>;
103
+ export type IdentityResolutionTargetConnection = Pick<Connection, 'instanceUrl' | 'request' | 'getApiVersion'>;
104
+ export type IdentityResolutionPreflightOptions = {
105
+ verifyDependencies?: (document: IdentityResolutionDocument, connection: IdentityResolutionTargetConnection, apiVersion: ApiVersionSelection, dataSpace: string) => Promise<void>;
106
+ };
107
+ export {};
@@ -0,0 +1,281 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { refuseEscapedCopy } from './escaped-copy.js';
3
+ import { isDeepStrictEqual } from 'node:util';
4
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
5
+ import { explanationOf, operationDiagnostic } from './operation-diagnostic.js';
6
+ import { IdentityResolutionError, identityResolutionSpace, identityResolutionSpaceMismatch, projectNativeIdentityResolution, validateIdentityResolutionDocument, } from '../artifacts/identity-resolution-document.js';
7
+ import { isDataSpaceName } from '../artifacts/data-space-field.js';
8
+ import { ConnectClient, ConnectError } from '../transport/connect-client.js';
9
+ import { bindIdentityResolutionDependencies } from './bind-identity-resolution-dependencies.js';
10
+ import { errorCodeInfo } from '../errors/registry.js';
11
+ /**
12
+ * Admit a complete authored definition for the native68 route; the API decides its settings.
13
+ * @param {unknown} value Complete portable definition.
14
+ * @returns {IdentityResolutionDocument} Detached native68 definition.
15
+ */
16
+ export function nativeIdentityResolutionDocument(value) {
17
+ return validateIdentityResolutionDocument(value);
18
+ }
19
+ /**
20
+ * Build the CREATE input from the document, never replaying source IDs or generated names.
21
+ * The API names a ruleset `<type>_<rulesetId>` (`<prefix>_<type>_<rulesetId>` outside the
22
+ * default data space, live API 68), so the ruleset ID is everything after the type and its
23
+ * underscore; a name equal to the type creates the default ruleset (no ID). Preflight refuses
24
+ * names that are neither (IDENTITY_RESOLUTION_NAME_TYPE_MISMATCH); outside default a name
25
+ * without the org's prefix, or no prefix at all, is IDENTITY_RESOLUTION_NAME_NOT_STORED.
26
+ * @param {unknown} value Complete native68 portable definition.
27
+ * @param {string} [dataSpacePrefix] The prefix the org's data space list names for the
28
+ * ruleset's data space; required outside default.
29
+ * @returns {Record<string, unknown>} Detached native request, not execution authorization.
30
+ */
31
+ export function buildNativeIdentityResolutionCreate(value, dataSpacePrefix) {
32
+ const document = nativeIdentityResolutionDocument(value);
33
+ const name = typeName(document, dataSpacePrefix);
34
+ const prefix = `${document.spec.configurationType}_`;
35
+ const rulesetId = name.toLowerCase().startsWith(prefix.toLowerCase())
36
+ ? name.slice(prefix.length)
37
+ : '';
38
+ return {
39
+ configurationType: document.spec.configurationType,
40
+ ...(rulesetId ? { rulesetId } : {}),
41
+ dataSpaceName: document.c__dataSpace,
42
+ secondaryDmo: document.spec.secondaryDmo.apiName,
43
+ ...buildNativeIdentityResolutionUpdate(document),
44
+ };
45
+ }
46
+ /**
47
+ * The ruleset name without the data space prefix Salesforce puts before `<type>` outside the
48
+ * default data space. The prefix is the one the org's data space list names, never guessed.
49
+ * @param {IdentityResolutionDocument} document Admitted ruleset.
50
+ * @param {string} [dataSpacePrefix] The prefix of the ruleset's data space; required outside default.
51
+ * @returns {string} `<type>` or `<type>_<rulesetId>` as the file names it.
52
+ */
53
+ function typeName(document, dataSpacePrefix) {
54
+ const name = document.identity.apiName;
55
+ if (document.c__dataSpace === 'default')
56
+ return name;
57
+ if (dataSpacePrefix === undefined || !name.startsWith(`${dataSpacePrefix}_`))
58
+ throw new Error('IDENTITY_RESOLUTION_NAME_NOT_STORED');
59
+ return name.slice(dataSpacePrefix.length + 1);
60
+ }
61
+ /**
62
+ * Serialize the complete qualified parent PATCH shape without generated output identities.
63
+ * Empty explicit overrides reset fields to object inheritance; source order is semantic.
64
+ * @param {unknown} value Complete native68 desired definition.
65
+ * @param {unknown} [current] Current target definition, when updating.
66
+ * @returns {Record<string, unknown>} Detached input-shaped configuration.
67
+ */
68
+ export function buildNativeIdentityResolutionUpdate(value, current) {
69
+ const document = nativeIdentityResolutionDocument(value);
70
+ const existing = current === undefined ? undefined : nativeIdentityResolutionDocument(current);
71
+ const settings = (item) => ({
72
+ ruleType: item.ruleType,
73
+ shouldIgnoreEmptyValue: item.shouldIgnoreEmptyValue,
74
+ sources: item.sources.map((source) => ({ name: source.apiName })),
75
+ });
76
+ // Empty filters and trusted sources stay omitted, as in the proven requests, unless the
77
+ // existing ruleset has entries: then the empty list is sent and the API decides.
78
+ const lists = Object.fromEntries(['filters', 'trustedSources']
79
+ .filter((key) => (document.spec[key]?.length ?? 0) > 0 || (existing?.spec[key]?.length ?? 0) > 0)
80
+ .map((key) => [key, document.spec[key] ?? []]));
81
+ return {
82
+ label: document.spec.label,
83
+ description: document.spec.description,
84
+ doesRunAutomatically: document.spec.doesRunAutomatically,
85
+ isCaseSensitive: document.spec.isCaseSensitive,
86
+ ...lists,
87
+ matchRules: document.spec.matchRules.map((rule) => ({
88
+ label: rule.label,
89
+ criteria: rule.criteria.map((criterion) => ({
90
+ entityName: criterion.field.parentApiName,
91
+ fieldName: criterion.field.apiName,
92
+ matchMethodType: criterion.matchMethodType,
93
+ shouldMatchOnBlank: criterion.shouldMatchOnBlank,
94
+ caseSensitiveMatch: criterion.caseSensitiveMatch,
95
+ ...(criterion.partyIdentificationInfo
96
+ ? { partyIdentificationInfo: criterion.partyIdentificationInfo }
97
+ : {}),
98
+ })),
99
+ })),
100
+ reconciliationRules: document.spec.reconciliationRules.map((rule) => ({
101
+ entityName: rule.entity.apiName,
102
+ ...settings(rule),
103
+ fields: rule.fields.map((override) => ({
104
+ fieldName: override.field.apiName,
105
+ ...settings(override),
106
+ })),
107
+ })),
108
+ };
109
+ }
110
+ /**
111
+ * Compare complete configuration while retaining exact logical owner identity.
112
+ * @param {unknown} current Independently projected settled target.
113
+ * @param {unknown} value Complete desired definition.
114
+ * @returns {boolean} Qualified full supported configuration semantic delta.
115
+ */
116
+ export function nativeIdentityResolutionConfigurationDelta(current, value) {
117
+ const expected = nativeIdentityResolutionDocument(current);
118
+ const desired = nativeIdentityResolutionDocument(value);
119
+ // PATCH carries neither configuration type nor secondary DMO, so it cannot change them.
120
+ return (isDeepStrictEqual(expected.identity, desired.identity) &&
121
+ expected.spec.configurationType === desired.spec.configurationType &&
122
+ isDeepStrictEqual(expected.spec.secondaryDmo, desired.spec.secondaryDmo) &&
123
+ !isDeepStrictEqual(expected, desired));
124
+ }
125
+ export const inFlightIdentityResolutionStatuses = ['PUBLISHING', 'DELETING'];
126
+ /**
127
+ * Hash private binding evidence without exposing target resource identities.
128
+ * @param {unknown} input Complete detached binding evidence.
129
+ * @returns {string} SHA256 digest.
130
+ */
131
+ function bindingDigest(input) {
132
+ return createHash('sha256').update(JSON.stringify(input)).digest('hex');
133
+ }
134
+ /**
135
+ * Bind desired configuration and verified inputs without guessing future output names.
136
+ * This is drift evidence only, never a substitute for settled owner/output proof.
137
+ * @param {unknown} value Complete qualified native68 source.
138
+ * @param {IdentityResolutionTargetConnection} connection Native68 receiver.
139
+ * @param {ApiVersionSelection} selection Explicit native68 selection.
140
+ * @param {string} dataSpace The run's data space (the ruleset's).
141
+ * @param {Function} verifyDependencies Fresh input identity/field/key verifier.
142
+ * @returns {Promise<NativeIdentityResolutionPrecreateBinding>} Private non-authorizing binding.
143
+ */
144
+ export async function bindNativeIdentityResolutionPrecreate(value, connection, selection, dataSpace, verifyDependencies = bindIdentityResolutionDependencies) {
145
+ const desired = nativeIdentityResolutionDocument(value);
146
+ const frozen = { ...selection };
147
+ const checkScope = () => {
148
+ if (frozen.requested !== '68.0' ||
149
+ frozen.restSelector !== 'v68.0' ||
150
+ frozen.soapNumeric !== '68.0' ||
151
+ connection.getApiVersion() !== '68.0' ||
152
+ dataSpace !== desired.c__dataSpace ||
153
+ !isDeepStrictEqual(selection, frozen))
154
+ throw new Error('INVALID_SCOPE');
155
+ };
156
+ checkScope();
157
+ const inputs = await verifyDependencies(structuredClone(desired), connection, { ...frozen }, dataSpace);
158
+ checkScope();
159
+ if (!/^[a-f0-9]{64}$/u.test(inputs?.fingerprint))
160
+ throw new Error('IDENTITY_RESOLUTION_BINDING_UNQUALIFIED');
161
+ return {
162
+ phase: 'precreate',
163
+ inputsFingerprint: inputs.fingerprint,
164
+ fingerprint: bindingDigest({ phase: 'precreate', desired, inputs }),
165
+ };
166
+ }
167
+ /**
168
+ * Read-only native68 admission; exact absence plus compatible input binding previews CREATE.
169
+ * Outputs are allocated by POST and require independent settled owner/output binding afterward.
170
+ * This preview alone is not write authorization; historical public deploy remains separate.
171
+ * @param {unknown} value Complete authored document.
172
+ * @param {IdentityResolutionTargetConnection} connection Explicit native68 receiver.
173
+ * @param {ApiVersionSelection} selection Explicit native68 route.
174
+ * @param {string} dataSpace The run's data space; the file's c__dataSpace and the org
175
+ * ruleset's must be it (IDENTITY_RESOLUTION_DATASPACE_MISMATCH).
176
+ * @param {object} options Private independent dependency reader seam.
177
+ * @param {Function} [options.verifyDependencies] Input-only dependency verification.
178
+ * @returns {Promise<NativeIdentityResolutionPreview>} Payload-free non-authorizing preview.
179
+ */
180
+ export async function preflightNativeIdentityResolutionDeploy(value, connection, selection, dataSpace, options = {}) {
181
+ const result = {
182
+ family: 'identity-resolution',
183
+ outcome: 'blocked',
184
+ target: 'unknown',
185
+ absenceProof: 'none',
186
+ route: { apiVersion: '68.0', operation: 'identity-resolutions.patch' },
187
+ requiredEffects: [],
188
+ diagnostics: [],
189
+ };
190
+ try {
191
+ const desired = nativeIdentityResolutionDocument(value);
192
+ const frozen = { ...selection };
193
+ if (frozen.requested !== '68.0' ||
194
+ frozen.restSelector !== 'v68.0' ||
195
+ frozen.soapNumeric !== '68.0' ||
196
+ connection.getApiVersion() !== '68.0' ||
197
+ !isDataSpaceName(dataSpace))
198
+ throw new Error('INVALID_SCOPE');
199
+ if (desired.c__dataSpace !== dataSpace)
200
+ throw identityResolutionSpaceMismatch(desired.identity.apiName, desired.c__dataSpace, dataSpace, 'file');
201
+ const verify = options.verifyDependencies ?? bindIdentityResolutionDependencies;
202
+ await verify(structuredClone(desired), connection, { ...frozen }, dataSpace);
203
+ const client = new ConnectClient(connection, frozen);
204
+ let raw;
205
+ try {
206
+ raw = await client.get(`/services/data/v68.0/ssot/identity-resolutions/${desired.identity.apiName}`);
207
+ }
208
+ catch (error) {
209
+ if (error instanceof ConnectError &&
210
+ error.statusCode === 404 &&
211
+ error.nativeCode === 'ITEM_NOT_FOUND') {
212
+ result.target = 'absent';
213
+ result.absenceProof = 'exact-item-not-found';
214
+ // The API names a new ruleset `<type>_<rulesetId>` (or `<type>`); a file name that
215
+ // does not follow it would create a ruleset under another name than the file's.
216
+ const name = typeName(desired, options.dataSpacePrefix).toLowerCase();
217
+ const type = desired.spec.configurationType.toLowerCase();
218
+ if (name !== type && !(name.startsWith(`${type}_`) && name.length > type.length + 1))
219
+ throw new Error('IDENTITY_RESOLUTION_NAME_TYPE_MISMATCH');
220
+ const precreateBinding = await bindNativeIdentityResolutionPrecreate(desired, connection, frozen, dataSpace, options.verifyPrecreateInputs);
221
+ if (!isDeepStrictEqual(selection, frozen) || connection.getApiVersion() !== '68.0')
222
+ throw new Error('INVALID_SCOPE');
223
+ return {
224
+ family: 'identity-resolution',
225
+ outcome: 'create',
226
+ target: 'absent',
227
+ absenceProof: 'exact-item-not-found',
228
+ route: { apiVersion: '68.0', operation: 'identity-resolutions.post' },
229
+ requiredEffects: ['processing', 'generated-output-provisioning'],
230
+ diagnostics: [],
231
+ precreateBinding,
232
+ };
233
+ }
234
+ throw retainConnectDiagnostic(new Error('IDENTITY_RESOLUTION_TARGET_UNQUALIFIED'), getConnectDiagnostic(error));
235
+ }
236
+ // The org ruleset's real data space, read before it is projected.
237
+ const found = identityResolutionSpace(raw);
238
+ if (found !== dataSpace)
239
+ throw identityResolutionSpaceMismatch(desired.identity.apiName, found, dataSpace, 'org');
240
+ const projection = projectNativeIdentityResolution(raw, desired.identity.apiName);
241
+ const current = projection.candidate;
242
+ if (!isDeepStrictEqual(selection, frozen) || connection.getApiVersion() !== '68.0')
243
+ throw new Error('INVALID_SCOPE');
244
+ // A write while the API is still processing the ruleset could not be told apart from it.
245
+ if (inFlightIdentityResolutionStatuses.includes(String(projection.expectations.native.rulesetStatus)))
246
+ throw new Error('IDENTITY_RESOLUTION_NOT_SETTLED');
247
+ result.target = 'present';
248
+ refuseEscapedCopy(desired, current, (code) => new IdentityResolutionError(code));
249
+ result.outcome = isDeepStrictEqual(current, desired)
250
+ ? 'unchanged'
251
+ : nativeIdentityResolutionConfigurationDelta(current, desired)
252
+ ? 'update'
253
+ : 'blocked-changes';
254
+ if (result.outcome === 'update')
255
+ result.requiredEffects = ['processing'];
256
+ if (result.outcome === 'blocked-changes')
257
+ throw new Error('IDENTITY_RESOLUTION_UPDATE_UNQUALIFIED');
258
+ }
259
+ catch (error) {
260
+ // A data space or escaped-text refusal keeps its own code and explanation.
261
+ const spaced = error instanceof IdentityResolutionError &&
262
+ (/DATASPACE/u.test(error.code) || error.code === 'HTML_ESCAPED_FILE');
263
+ const code = spaced
264
+ ? error.code
265
+ : error instanceof Error &&
266
+ /^(?:IDENTITY_RESOLUTION_[A-Z0-9_]+|INVALID_SCOPE)$/u.test(error.message)
267
+ ? error.message
268
+ : 'IDENTITY_RESOLUTION_NATIVE68_ADMISSION_FAILED';
269
+ const fallback = (spaced ? explanationOf(error) : undefined) ??
270
+ errorCodeInfo(code)?.hint ??
271
+ 'The identity resolution deployment did not pass the plugin checks.';
272
+ retainConnectDiagnostic(result, getConnectDiagnostic(error));
273
+ result.diagnostics = [
274
+ {
275
+ code,
276
+ message: getConnectDiagnostic(error) ? operationDiagnostic(error, fallback) : fallback,
277
+ },
278
+ ];
279
+ }
280
+ return result;
281
+ }
@@ -0,0 +1,31 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ import type { ApiVersionSelection } from '../transport/api-version.js';
3
+ import { retrieveSegment } from './retrieve-segment.js';
4
+ import { bindSegmentChildren, bindSegmentDependencies } from './bind-segment-dependencies.js';
5
+ import type { DeployPreviewResult } from './deploy-result.js';
6
+ export type SegmentDeployPreview = DeployPreviewResult & {
7
+ family: 'segment';
8
+ route: {
9
+ apiVersion: string;
10
+ method: 'GET';
11
+ resource: 'segments';
12
+ };
13
+ requiredEffects: Array<'processing'>;
14
+ };
15
+ /**
16
+ * Classify one authored Segment against the target by its exact name at API68: exact
17
+ * ITEM_NOT_FOUND404 is create, a readable Segment is update or unchanged. The authored
18
+ * definition is not judged; Salesforce decides about it on the write. A schedule the write would
19
+ * send is reported as SEGMENT_SCHEDULE_CHANGE beside create or update. The child segments a
20
+ * Waterfall file names must exist in the target (SEGMENT_CHILD_NOT_FOUND otherwise); the target
21
+ * read names the children of the org segment by them.
22
+ * @param {unknown} value Desired bounded authored document.
23
+ * @param {Connection} connection Command-owned authenticated target connection.
24
+ * @param {string | ApiVersionSelection} apiVersion API68 selection.
25
+ * @param {string} dataSpace The run's data space; the file's c__dataSpace must name it.
26
+ * @param {Function} acquire Independent acquisition seam for deterministic synthetic tests.
27
+ * @param {Function} bind Fresh independent target dependency binding; never cached across calls.
28
+ * @param {Function} children Fresh binding of the Waterfall child segments of the file.
29
+ * @returns {Promise<SegmentDeployPreview>} Read-only semantic classification and possible effects.
30
+ */
31
+ export declare function preflightSegmentDeploy(value: unknown, connection: Pick<Connection, 'instanceUrl' | 'request' | 'getApiVersion' | 'getUsername'>, apiVersion: string | ApiVersionSelection, dataSpace: string, acquire?: typeof retrieveSegment, bind?: typeof bindSegmentDependencies, children?: typeof bindSegmentChildren): Promise<SegmentDeployPreview>;
@@ -0,0 +1,109 @@
1
+ import { refuseEscapedCopy } from './escaped-copy.js';
2
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
3
+ import { explanationOf, operationDiagnostic } from './operation-diagnostic.js';
4
+ import { carriesDefinition, segmentScheduleNotice, validateSegmentDocument, } from '../artifacts/segment-document.js';
5
+ import { retrieveSegment } from './retrieve-segment.js';
6
+ import { SegmentError } from '../artifacts/segment-document.js';
7
+ import { bindSegmentChildren, bindSegmentDependencies } from './bind-segment-dependencies.js';
8
+ /**
9
+ * Classify one authored Segment against the target by its exact name at API68: exact
10
+ * ITEM_NOT_FOUND404 is create, a readable Segment is update or unchanged. The authored
11
+ * definition is not judged; Salesforce decides about it on the write. A schedule the write would
12
+ * send is reported as SEGMENT_SCHEDULE_CHANGE beside create or update. The child segments a
13
+ * Waterfall file names must exist in the target (SEGMENT_CHILD_NOT_FOUND otherwise); the target
14
+ * read names the children of the org segment by them.
15
+ * @param {unknown} value Desired bounded authored document.
16
+ * @param {Connection} connection Command-owned authenticated target connection.
17
+ * @param {string | ApiVersionSelection} apiVersion API68 selection.
18
+ * @param {string} dataSpace The run's data space; the file's c__dataSpace must name it.
19
+ * @param {Function} acquire Independent acquisition seam for deterministic synthetic tests.
20
+ * @param {Function} bind Fresh independent target dependency binding; never cached across calls.
21
+ * @param {Function} children Fresh binding of the Waterfall child segments of the file.
22
+ * @returns {Promise<SegmentDeployPreview>} Read-only semantic classification and possible effects.
23
+ */
24
+ export async function preflightSegmentDeploy(value, connection, apiVersion, dataSpace, acquire = retrieveSegment, bind = bindSegmentDependencies, children = bindSegmentChildren) {
25
+ const requested = typeof apiVersion === 'string' ? apiVersion : apiVersion.requested;
26
+ const result = (outcome, target, code, evidence) => retainConnectDiagnostic({
27
+ family: 'segment',
28
+ route: { apiVersion: requested, method: 'GET', resource: 'segments' },
29
+ outcome,
30
+ target,
31
+ absenceProof: 'none',
32
+ requiredEffects: ['create', 'update'].includes(outcome) ? ['processing'] : [],
33
+ diagnostics: code
34
+ ? [
35
+ {
36
+ code,
37
+ message: getConnectDiagnostic(evidence) || explanationOf(evidence)
38
+ ? operationDiagnostic(evidence, 'Segment preview is not execution authorization. Resolve the reported cause before deployment.')
39
+ : 'Segment preview is not execution authorization. Resolve the reported cause before deployment.',
40
+ },
41
+ ]
42
+ : [],
43
+ }, getConnectDiagnostic(evidence));
44
+ let desired;
45
+ // A schedule the deploy would send makes the segment publish on it in the target org.
46
+ const withNotice = (preview, current) => {
47
+ const notice = segmentScheduleNotice(desired, current);
48
+ if (notice)
49
+ preview.diagnostics.push(notice);
50
+ return preview;
51
+ };
52
+ try {
53
+ desired = validateSegmentDocument(value);
54
+ }
55
+ catch {
56
+ return result('blocked', 'unknown', 'INVALID_SOURCE');
57
+ }
58
+ // The file's data space must be the run's (deploy refuses that earlier, naming both).
59
+ if (desired.c__dataSpace !== dataSpace)
60
+ return result('blocked', 'unknown', 'SEGMENT_DATASPACE_MISMATCH');
61
+ if (requested !== '68.0' ||
62
+ connection.getApiVersion() !== requested ||
63
+ (typeof apiVersion !== 'string' &&
64
+ (apiVersion.soapNumeric !== requested || apiVersion.restSelector !== `v${requested}`)))
65
+ return result('blocked', 'unknown', 'INVALID_SCOPE');
66
+ // Definition ID of each Waterfall child in the target to its API name.
67
+ let names;
68
+ try {
69
+ // The DMO the Segment is built on must exist; its ID binds the readback.
70
+ await bind(desired, connection, apiVersion, dataSpace);
71
+ const bound = await children(desired, connection, apiVersion);
72
+ names = new Map(bound.map((child) => [child.targetId, child.identity.apiName]));
73
+ }
74
+ catch (error) {
75
+ return result('blocked', 'unknown', error instanceof SegmentError ? error.code : 'SEGMENT_DEPENDENCY_ACQUISITION_FAILED', error);
76
+ }
77
+ try {
78
+ const acquired = await acquire(connection, desired.identity.apiName, apiVersion, dataSpace, 'deploy', names);
79
+ // POST is create-only (observed duplicate409), never an upsert; only exact 404 is absence.
80
+ const diagnostic = getConnectDiagnostic(acquired);
81
+ if (!acquired.candidate &&
82
+ !acquired.expectations &&
83
+ acquired.blockers.length === 1 &&
84
+ acquired.blockers[0] === 'SEGMENT_ACQUISITION_FAILED' &&
85
+ diagnostic?.statusCode === 404 &&
86
+ diagnostic.errors?.length === 1 &&
87
+ diagnostic.errors[0].code === 'ITEM_NOT_FOUND')
88
+ return withNotice(result('create', 'absent'));
89
+ if (!acquired.candidate || acquired.blockers.length > 0 || !acquired.expectations)
90
+ return result('blocked', 'unknown', acquired.blockers[0] ?? 'SEGMENT_ACQUISITION_FAILED', acquired);
91
+ const current = validateSegmentDocument(acquired.candidate);
92
+ if (JSON.stringify(current.identity) !== JSON.stringify(desired.identity) ||
93
+ current.c__dataSpace !== desired.c__dataSpace)
94
+ return result('blocked', 'unknown', 'SEGMENT_TARGET_IDENTITY_MISMATCH');
95
+ // The segment was read: an escaped copy is refused against a present target.
96
+ try {
97
+ refuseEscapedCopy(desired, current, (code) => new SegmentError(code));
98
+ }
99
+ catch (error) {
100
+ return result('blocked', 'present', error instanceof SegmentError ? error.code : 'SEGMENT_ACQUISITION_FAILED', error);
101
+ }
102
+ return carriesDefinition(current, desired)
103
+ ? result('unchanged', 'present')
104
+ : withNotice(result('update', 'present'), current);
105
+ }
106
+ catch (error) {
107
+ return result('blocked', 'unknown', error instanceof SegmentError ? error.code : 'SEGMENT_ACQUISITION_FAILED', error);
108
+ }
109
+ }
@@ -0,0 +1,40 @@
1
+ import type { ApiVersionSelection } from '../transport/api-version.js';
2
+ import type { CalculatedInsightClient } from '../transport/calculated-insight-rest.js';
3
+ import type { CalculatedInsightConnection, CalculatedInsightReadContext } from './native-calculated-insight.js';
4
+ import type { CalculatedInsightTiming } from './settle-calculated-insight.js';
5
+ export type CalculatedInsightPublishOptions = CalculatedInsightTiming & {
6
+ preview?: boolean;
7
+ /** Return once Salesforce accepted the PATCH, without reading until ACTIVE. */
8
+ async?: boolean;
9
+ verifyInput: () => Promise<void>;
10
+ context?: CalculatedInsightReadContext;
11
+ nativeClient?: Pick<CalculatedInsightClient, 'update'>;
12
+ };
13
+ export type CalculatedInsightPublishResult = {
14
+ family: 'calculated-insight';
15
+ route: {
16
+ apiVersion: '68.0';
17
+ method: 'PATCH';
18
+ resource: 'calculated-insights';
19
+ };
20
+ outcome: 'publish' | 'published' | 'publishing' | 'unchanged' | 'blocked' | 'failed';
21
+ mutation: 'not-attempted' | 'confirmed-published' | 'acknowledged-processing' | 'unknown' | 'rejected';
22
+ diagnostics: Array<{
23
+ code: string;
24
+ message: string;
25
+ }>;
26
+ };
27
+ /**
28
+ * Publish one existing insight: an ACTIVE insight that holds every key of the document is
29
+ * unchanged; otherwise one PATCH sends the document with `draft: false` (the files' SQL,
30
+ * label and schedule become the active definition) and the insight is read until it is
31
+ * ACTIVE with the document (with `async`, not read after the accepted PATCH). Never creates;
32
+ * one attempt, no replay or rollback.
33
+ * @param {unknown} value Document from the files (JSON with its SQL).
34
+ * @param {CalculatedInsightConnection} connection API 68 connection.
35
+ * @param {ApiVersionSelection} selection Route selection (68.0).
36
+ * @param {string} dataSpace Selected data space.
37
+ * @param {CalculatedInsightPublishOptions} options Input verifier, preview and test seams.
38
+ * @returns {Promise<CalculatedInsightPublishResult>} Payload-free outcome.
39
+ */
40
+ export declare function publishCalculatedInsight(value: unknown, connection: CalculatedInsightConnection, selection: ApiVersionSelection, dataSpace: string, options: CalculatedInsightPublishOptions): Promise<CalculatedInsightPublishResult>;