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,95 @@
1
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
2
+ import { operationDiagnostic } from './operation-diagnostic.js';
3
+ import { rejectedNextAction } from './deploy-result.js';
4
+ import { CalculatedInsightError, calculatedInsightMatches, validateNativeCalculatedInsight, } from '../artifacts/native-calculated-insight-document.js';
5
+ import { createCalculatedInsightClient } from '../transport/calculated-insight-rest.js';
6
+ import { calculatedInsightDeployContext } from './preflight-calculated-insight-deploy.js';
7
+ import { acquireCalculatedInsight } from './native-calculated-insight.js';
8
+ import { rejectedWrite } from './execute-calculated-insight-deploy.js';
9
+ import { settleCalculatedInsight } from './settle-calculated-insight.js';
10
+ /**
11
+ * Publish one existing insight: an ACTIVE insight that holds every key of the document is
12
+ * unchanged; otherwise one PATCH sends the document with `draft: false` (the files' SQL,
13
+ * label and schedule become the active definition) and the insight is read until it is
14
+ * ACTIVE with the document (with `async`, not read after the accepted PATCH). Never creates;
15
+ * one attempt, no replay or rollback.
16
+ * @param {unknown} value Document from the files (JSON with its SQL).
17
+ * @param {CalculatedInsightConnection} connection API 68 connection.
18
+ * @param {ApiVersionSelection} selection Route selection (68.0).
19
+ * @param {string} dataSpace Selected data space.
20
+ * @param {CalculatedInsightPublishOptions} options Input verifier, preview and test seams.
21
+ * @returns {Promise<CalculatedInsightPublishResult>} Payload-free outcome.
22
+ */
23
+ export async function publishCalculatedInsight(value, connection, selection, dataSpace, options) {
24
+ let attempted = false;
25
+ const result = (outcome, mutation, code, error) => retainConnectDiagnostic({
26
+ family: 'calculated-insight',
27
+ route: {
28
+ apiVersion: '68.0',
29
+ method: 'PATCH',
30
+ resource: 'calculated-insights',
31
+ },
32
+ outcome,
33
+ mutation,
34
+ diagnostics: code
35
+ ? [
36
+ {
37
+ code,
38
+ message: (() => {
39
+ const next = mutation === 'rejected'
40
+ ? rejectedNextAction
41
+ : mutation === 'acknowledged-processing'
42
+ ? 'Salesforce accepted the publish; it was sent without waiting until the insight is ACTIVE (--async). It was not resent; run publish with --preview later to check.'
43
+ : mutation === 'unknown'
44
+ ? 'CI publication may have occurred; no replay or rollback was performed.'
45
+ : 'CI publication was not attempted.';
46
+ return getConnectDiagnostic(error) ? operationDiagnostic(error, next) : next;
47
+ })(),
48
+ },
49
+ ]
50
+ : [],
51
+ }, getConnectDiagnostic(error));
52
+ try {
53
+ const desired = validateNativeCalculatedInsight(value);
54
+ if (typeof options.verifyInput !== 'function')
55
+ throw new Error('Required guards');
56
+ if ('preview' in options && typeof options.preview !== 'boolean')
57
+ throw new Error('Preview');
58
+ const context = calculatedInsightDeployContext(connection, selection, dataSpace, desired, options.context);
59
+ await options.verifyInput();
60
+ const acquired = await acquireCalculatedInsight(context, desired.apiName);
61
+ context.check();
62
+ // Publication needs the insight; creating it is `sf data360 deploy`.
63
+ if (acquired.state === 'absent')
64
+ throw new CalculatedInsightError('CI_NOT_FOUND');
65
+ await options.verifyInput();
66
+ if (acquired.status === 'ACTIVE' && calculatedInsightMatches(desired, acquired.document))
67
+ return result('unchanged', 'not-attempted');
68
+ if (options.preview === true)
69
+ return result('publish', 'not-attempted');
70
+ const client = options.nativeClient ?? createCalculatedInsightClient(connection, '68.0', dataSpace);
71
+ context.check();
72
+ attempted = true;
73
+ try {
74
+ await client.update(structuredClone(desired), {
75
+ draft: false,
76
+ observed: acquired.document,
77
+ });
78
+ }
79
+ catch (error) {
80
+ if (rejectedWrite(error))
81
+ return result('failed', 'rejected', 'REQUEST_FAILED', error);
82
+ throw error;
83
+ }
84
+ if (options.async === true)
85
+ return result('publishing', 'acknowledged-processing', 'CI_PUBLISH_STARTED');
86
+ await settleCalculatedInsight(context, desired, 'ACTIVE', options);
87
+ return result('published', 'confirmed-published');
88
+ }
89
+ catch (error) {
90
+ const code = error instanceof CalculatedInsightError ? error.code : undefined;
91
+ return attempted
92
+ ? result('failed', 'unknown', code ?? 'CI_PUBLICATION_UNCONFIRMED', error)
93
+ : result('blocked', 'not-attempted', code ?? 'CI_ADMISSION_FAILED', error);
94
+ }
95
+ }
@@ -0,0 +1,65 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ import type { SegmentDocument } from '../artifacts/segment-document.js';
3
+ import { ConnectClient } from '../transport/connect-client.js';
4
+ import type { ApiVersionSelection } from '../transport/api-version.js';
5
+ /** Default wait for the publish result and the pause between status reads. */
6
+ export declare const segmentPublishWait: Readonly<{
7
+ timeoutSeconds: 1800;
8
+ intervalMs: 30000;
9
+ }>;
10
+ export type SegmentPublishOptions = {
11
+ preview: boolean;
12
+ /** Return once Salesforce accepted the publish, without reading its status afterwards. */
13
+ async?: boolean;
14
+ /** Seconds to wait for SUCCESS or FAILED after Salesforce accepted the publish. */
15
+ waitTimeoutSeconds: number;
16
+ /** The segment file of a `-d` selection: the org must hold this definition. */
17
+ desired?: SegmentDocument;
18
+ /** The run's data space: the segment read must name it (default: default). */
19
+ dataSpace?: string;
20
+ verifyInput: () => Promise<void>;
21
+ client?: Pick<ConnectClient, 'get' | 'publishSegment'>;
22
+ now?: () => number;
23
+ delay?: (milliseconds: number) => Promise<void>;
24
+ progress?: (message: string) => void;
25
+ };
26
+ export type SegmentPublishResult = {
27
+ family: 'segment';
28
+ route: {
29
+ apiVersion: '68.0';
30
+ method: 'POST';
31
+ resource: 'segments/{id}/actions/publish';
32
+ };
33
+ outcome: 'publish' | 'published' | 'publishing' | 'blocked' | 'failed';
34
+ mutation: 'not-attempted' | 'confirmed-published' | 'publish-failed' | 'acknowledged-processing' | 'rejected' | 'unknown';
35
+ segment?: {
36
+ marketSegmentId: string;
37
+ segmentStatus?: string;
38
+ publishStatus?: string;
39
+ lastPublishedEndDateTime?: string;
40
+ jobId?: string;
41
+ };
42
+ waitedSeconds?: number;
43
+ diagnostics: Array<{
44
+ code: string;
45
+ message: string;
46
+ }>;
47
+ };
48
+ type SegmentConnection = Pick<Connection, 'instanceUrl' | 'request' | 'getApiVersion'>;
49
+ /**
50
+ * Publish one segment of the run's data space and wait for the result. The segment is read by
51
+ * its (stored) name, which is unique in the org; a read naming another data space is refused
52
+ * (SEGMENT_DATASPACE_MISMATCH). With a file, the org must hold the file's definition. Salesforce decides whether it can
53
+ * publish now (also while the segment is processing or counting): one POST to
54
+ * `/ssot/segments/{marketSegmentId}/actions/publish` without a body, never resent, then status
55
+ * reads until `publishStatus` is SUCCESS or FAILED for this publish, or the wait ends (still
56
+ * processing, not failed). With `async`, the command returns once Salesforce accepted the POST
57
+ * (started, not finished) and reads nothing afterwards.
58
+ * @param {string} apiName Exact segment name.
59
+ * @param {SegmentConnection} connection Fixed authenticated target.
60
+ * @param {ApiVersionSelection} selection Exact API68 selection.
61
+ * @param {SegmentPublishOptions} options Preview, wait and input guard.
62
+ * @returns {Promise<SegmentPublishResult>} Payload-free publication receipt.
63
+ */
64
+ export declare function publishSegment(apiName: string, connection: SegmentConnection, selection: ApiVersionSelection, options: SegmentPublishOptions): Promise<SegmentPublishResult>;
65
+ export {};
@@ -0,0 +1,194 @@
1
+ import { setTimeout as delay } from 'node:timers/promises';
2
+ import { SegmentError, carriesDefinition } from '../artifacts/segment-document.js';
3
+ import { ConnectClient, ConnectError } from '../transport/connect-client.js';
4
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
5
+ import { projectSegment, segmentSpaceMismatch } from './retrieve-segment.js';
6
+ import { operationDiagnostic, replaceExplanation } from './operation-diagnostic.js';
7
+ /** Default wait for the publish result and the pause between status reads. */
8
+ export const segmentPublishWait = Object.freeze({ timeoutSeconds: 1800, intervalMs: 30_000 });
9
+ /**
10
+ * A plain status value of the segment read, shown in results; anything else is left out.
11
+ * @param {unknown} value Field value.
12
+ * @returns {string | undefined} Bounded text.
13
+ */
14
+ function text(value) {
15
+ return typeof value === 'string' && /^[\w.:+-]{1,64}$/u.test(value) ? value : undefined;
16
+ }
17
+ /**
18
+ * Fail with a plugin-built explanation that names the next step.
19
+ * @param {string} message Explanation built from validated identifiers and static text.
20
+ * @returns {Error} Error carrying the explanation.
21
+ */
22
+ function explained(message) {
23
+ const error = new Error(message);
24
+ replaceExplanation(error, message);
25
+ return error;
26
+ }
27
+ /**
28
+ * Publish one segment of the run's data space and wait for the result. The segment is read by
29
+ * its (stored) name, which is unique in the org; a read naming another data space is refused
30
+ * (SEGMENT_DATASPACE_MISMATCH). With a file, the org must hold the file's definition. Salesforce decides whether it can
31
+ * publish now (also while the segment is processing or counting): one POST to
32
+ * `/ssot/segments/{marketSegmentId}/actions/publish` without a body, never resent, then status
33
+ * reads until `publishStatus` is SUCCESS or FAILED for this publish, or the wait ends (still
34
+ * processing, not failed). With `async`, the command returns once Salesforce accepted the POST
35
+ * (started, not finished) and reads nothing afterwards.
36
+ * @param {string} apiName Exact segment name.
37
+ * @param {SegmentConnection} connection Fixed authenticated target.
38
+ * @param {ApiVersionSelection} selection Exact API68 selection.
39
+ * @param {SegmentPublishOptions} options Preview, wait and input guard.
40
+ * @returns {Promise<SegmentPublishResult>} Payload-free publication receipt.
41
+ */
42
+ export async function publishSegment(apiName, connection, selection, options) {
43
+ let segment;
44
+ let waitedSeconds;
45
+ const result = (outcome, mutation, code, message, error) => retainConnectDiagnostic({
46
+ family: 'segment',
47
+ route: { apiVersion: '68.0', method: 'POST', resource: 'segments/{id}/actions/publish' },
48
+ outcome,
49
+ mutation,
50
+ ...(segment ? { segment } : {}),
51
+ ...(waitedSeconds === undefined ? {} : { waitedSeconds }),
52
+ diagnostics: code ? [{ code, message: message ?? '' }] : [],
53
+ }, getConnectDiagnostic(error));
54
+ const now = options.now ?? Date.now;
55
+ const pause = options.delay ?? (async (milliseconds) => delay(milliseconds));
56
+ const client = options.client ?? new ConnectClient(connection, selection);
57
+ const dataSpace = options.dataSpace ?? 'default';
58
+ const read = async () => {
59
+ if (connection.getApiVersion() !== '68.0')
60
+ throw new Error('Connection drift');
61
+ let response;
62
+ try {
63
+ response = await client.get(`/services/data/v68.0/ssot/segments/${apiName}`);
64
+ }
65
+ catch (error) {
66
+ if (error instanceof ConnectError &&
67
+ error.statusCode === 404 &&
68
+ error.nativeCode === 'ITEM_NOT_FOUND')
69
+ return undefined;
70
+ throw error;
71
+ }
72
+ const segments = response?.segments;
73
+ const value = Array.isArray(segments) ? segments[0] : undefined;
74
+ if (!value || typeof value !== 'object' || Array.isArray(value))
75
+ throw explained(`Salesforce answered the read of segment ${apiName} without a segment.`);
76
+ const raw = value;
77
+ if (raw.apiName !== apiName ||
78
+ typeof raw.marketSegmentId !== 'string' ||
79
+ !/^1sg[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/u.test(raw.marketSegmentId))
80
+ throw explained(`Salesforce answered the read of segment ${apiName} with another name or record ID.`);
81
+ if (raw.dataSpace !== dataSpace)
82
+ throw segmentSpaceMismatch(apiName, raw.dataSpace, dataSpace);
83
+ return {
84
+ raw,
85
+ marketSegmentId: raw.marketSegmentId,
86
+ segmentStatus: text(raw.segmentStatus),
87
+ publishStatus: text(raw.publishStatus),
88
+ lastPublishedEndDateTime: text(raw.lastPublishedEndDateTime),
89
+ };
90
+ };
91
+ const describe = (observed, jobId) => {
92
+ segment = {
93
+ marketSegmentId: observed.marketSegmentId,
94
+ ...(observed.segmentStatus ? { segmentStatus: observed.segmentStatus } : {}),
95
+ ...(observed.publishStatus ? { publishStatus: observed.publishStatus } : {}),
96
+ ...(observed.lastPublishedEndDateTime
97
+ ? { lastPublishedEndDateTime: observed.lastPublishedEndDateTime }
98
+ : {}),
99
+ ...(jobId ? { jobId } : {}),
100
+ };
101
+ };
102
+ // Admission: nothing is sent until the segment is read and, with a file, matches it.
103
+ let baseline;
104
+ try {
105
+ await options.verifyInput();
106
+ const observed = await read();
107
+ if (!observed)
108
+ return result('blocked', 'not-attempted', 'SEGMENT_PUBLISH_ADMISSION_FAILED', `Segment ${apiName} does not exist in the org (HTTP 404 ITEM_NOT_FOUND). Deploy it first with sf data360 deploy. Nothing was published.`);
109
+ baseline = observed;
110
+ describe(baseline);
111
+ if (options.desired) {
112
+ let matches = false;
113
+ try {
114
+ matches = carriesDefinition(projectSegment({ segments: [baseline.raw] }, apiName, 'retrieve').candidate, options.desired);
115
+ }
116
+ catch {
117
+ matches = false;
118
+ }
119
+ if (!matches)
120
+ return result('blocked', 'not-attempted', 'SEGMENT_PUBLISH_DEFINITION_MISMATCH', `Segment ${apiName} in the org does not hold the definition of the file. Deploy the file first, or publish what the org holds with -m segment:${apiName}. Nothing was published.`);
121
+ }
122
+ await options.verifyInput();
123
+ }
124
+ catch (error) {
125
+ return result('blocked', 'not-attempted', error instanceof SegmentError ? error.code : 'SEGMENT_PUBLISH_ADMISSION_FAILED', operationDiagnostic(error, 'The segment could not be read before the publish, so nothing was published.'), error);
126
+ }
127
+ if (options.preview)
128
+ return result('publish', 'not-attempted');
129
+ // One POST; Salesforce decides. A failed or unknown answer is never resent.
130
+ let jobId;
131
+ let acceptedStatus;
132
+ try {
133
+ const answer = await client.publishSegment(baseline.marketSegmentId);
134
+ const body = (answer && typeof answer === 'object' ? answer : {});
135
+ jobId = text(body.jobId);
136
+ acceptedStatus = text(body.publishStatus);
137
+ if (body.success === false)
138
+ return result('failed', 'rejected', 'SEGMENT_PUBLISH_REJECTED', `Salesforce answered the publish of segment ${apiName} with success: false. Nothing was resent.`);
139
+ if (body.success !== true)
140
+ throw explained(`Salesforce answered the publish of segment ${apiName} without success: true, so the publish is not confirmed.`);
141
+ }
142
+ catch (error) {
143
+ const status = getConnectDiagnostic(error)?.statusCode;
144
+ const rejected = error instanceof ConnectError &&
145
+ typeof error.statusCode === 'number' &&
146
+ error.statusCode >= 400 &&
147
+ error.statusCode < 500 &&
148
+ error.statusCode !== 429 &&
149
+ status !== 429;
150
+ return result('failed', rejected ? 'rejected' : 'unknown', rejected ? 'SEGMENT_PUBLISH_REJECTED' : 'SEGMENT_PUBLISH_UNCONFIRMED', operationDiagnostic(error, rejected
151
+ ? 'Salesforce refused the publish; nothing was resent.'
152
+ : 'The publish may have started. Read the segment before publishing again; nothing was resent.'), error);
153
+ }
154
+ // --async: the publish started; nothing is read afterwards and nothing is resent.
155
+ if (options.async === true) {
156
+ // The status of the read before the POST belongs to an earlier publish; report the answer's.
157
+ describe({ ...baseline, publishStatus: acceptedStatus, lastPublishedEndDateTime: undefined }, jobId);
158
+ return result('publishing', 'acknowledged-processing', 'SEGMENT_PUBLISH_STARTED', `Salesforce accepted the publish of segment ${apiName}; it was started without waiting (--async) and runs on in Salesforce. It was not resent; read the segment later for the result.`);
159
+ }
160
+ // Wait for this publish: a terminal status counts once it is new (end time changed, a
161
+ // running status was seen, or the segment had never been published).
162
+ const started = now();
163
+ const deadline = started + options.waitTimeoutSeconds * 1000;
164
+ let running = baseline.publishStatus === undefined;
165
+ for (;;) {
166
+ let observed;
167
+ try {
168
+ observed = await read();
169
+ if (!observed)
170
+ throw explained(`Segment ${apiName} read as absent after the publish.`);
171
+ }
172
+ catch (error) {
173
+ waitedSeconds = Math.round((now() - started) / 1000);
174
+ return result('failed', 'unknown', 'SEGMENT_PUBLISH_UNCONFIRMED', operationDiagnostic(error, 'Salesforce accepted the publish, but its status could not be read. Read the segment before publishing again; nothing was resent.'), error);
175
+ }
176
+ describe(observed, jobId);
177
+ waitedSeconds = Math.round((now() - started) / 1000);
178
+ const status = observed.publishStatus;
179
+ const terminal = status === 'SUCCESS' || status === 'FAILED';
180
+ const fresh = running || observed.lastPublishedEndDateTime !== baseline.lastPublishedEndDateTime;
181
+ if (terminal && fresh)
182
+ return status === 'SUCCESS'
183
+ ? result('published', 'confirmed-published')
184
+ : result('failed', 'publish-failed', 'SEGMENT_PUBLISH_FAILED', `Salesforce reports publishStatus FAILED for segment ${apiName} after ${waitedSeconds} s. Check the segment in Data Cloud before publishing again.`);
185
+ if (!terminal)
186
+ running = true;
187
+ const remaining = deadline - now();
188
+ if (remaining <= 0)
189
+ return result('publishing', 'acknowledged-processing', 'SEGMENT_PUBLISH_STILL_PROCESSING', `Salesforce accepted the publish of segment ${apiName} and is still processing it after ${waitedSeconds} s (publishStatus ${status ?? 'not reported'}). It was not resent; read the segment later for the result.`);
190
+ const wait = Math.min(segmentPublishWait.intervalMs, remaining);
191
+ options.progress?.(`Segment ${apiName}: publishStatus ${status ?? 'not reported'} after ${waitedSeconds} s; next read in ${Math.ceil(wait / 1000)} s.`);
192
+ await pause(wait);
193
+ }
194
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Spacing of the settle reads after a native DLO, DMO or mapping write. Reads go over one bound
3
+ * connection and return in well under a second, so the reads are spaced explicitly instead of
4
+ * relying on per-read process start-up. A read that already shows the settled state ends the wait.
5
+ */
6
+ export declare const readbackPace: {
7
+ attempts: number;
8
+ delayMs: number;
9
+ sleep: (milliseconds: number) => Promise<void>;
10
+ };
11
+ /**
12
+ * Wait before every settle read except the first.
13
+ * @param {number} attempt Zero-based read number.
14
+ * @returns {Promise<void>} Resolves when the next read may be sent.
15
+ */
16
+ export declare function paceReadback(attempt: number): Promise<void>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Spacing of the settle reads after a native DLO, DMO or mapping write. Reads go over one bound
3
+ * connection and return in well under a second, so the reads are spaced explicitly instead of
4
+ * relying on per-read process start-up. A read that already shows the settled state ends the wait.
5
+ */
6
+ export const readbackPace = {
7
+ attempts: 6,
8
+ delayMs: 3000,
9
+ sleep: async (milliseconds) => {
10
+ await new Promise((resolve) => {
11
+ setTimeout(resolve, milliseconds);
12
+ });
13
+ },
14
+ };
15
+ /**
16
+ * Wait before every settle read except the first.
17
+ * @param {number} attempt Zero-based read number.
18
+ * @returns {Promise<void>} Resolves when the next read may be sent.
19
+ */
20
+ export async function paceReadback(attempt) {
21
+ if (attempt > 0)
22
+ await readbackPace.sleep(readbackPace.delayMs);
23
+ }
@@ -0,0 +1,26 @@
1
+ import type { DataTransformObservation } from '../artifacts/data-transform-document.js';
2
+ import type { DataTransformClient } from '../transport/data-transform-rest.js';
3
+ import type { DocumentMode } from '../artifacts/verbatim-document.js';
4
+ /**
5
+ * Acquire one explicitly selected native transform and its schedule (projected into the document
6
+ * and kept as read). HTTP404 remains a read failure, never an absence or create permission. In
7
+ * retrieve mode the schedule read is best effort: a failed read or an answer that is not an object
8
+ * leaves the schedule out of the file (deploy then leaves the schedule alone), with a warning.
9
+ * @param {string} nameOrId Exact selected API name or native record ID.
10
+ * The transform's data space is resolved right after the GET, before anything is projected: its
11
+ * `dataSpaceName`, otherwise the org's MktDataTransform record (`client.dataSpaces`). With
12
+ * `dataSpace`, a transform of another data space is TRANSFORM_DATASPACE_MISMATCH, never a
13
+ * verbatim stand-in.
14
+ * @param {Pick<DataTransformClient, 'get' | 'schedule' | 'dataSpaces'>} client Qualified API68 transport.
15
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (lenient).
16
+ * @param {string[]} [warnings] Receives the retrieve-mode schedule warning.
17
+ * @param {string} [dataSpace] The data space the transform must be in.
18
+ * @returns {Promise<DataTransformObservation>} Input-only artifact and detached observations.
19
+ */
20
+ export declare function retrieveDataTransform(nameOrId: string, client: Pick<DataTransformClient, 'get' | 'schedule' | 'dataSpaces'>, mode?: DocumentMode, warnings?: string[], dataSpace?: string): Promise<DataTransformObservation>;
21
+ /**
22
+ * Return the portable artifact relative path; filesystem publication belongs to command integration.
23
+ * @param {string} apiName Exact admitted transform developer name.
24
+ * @returns {string} Fixed portable JSON destination under the source root.
25
+ */
26
+ export declare function dataTransformArtifactPath(apiName: string): string;
@@ -0,0 +1,65 @@
1
+ import { dataTransformSpaceMismatch, DataTransformError, dataTransformId, dataTransformName, observeDataTransform, } from '../artifacts/data-transform-document.js';
2
+ import { resolveDataTransformSpace } from './data-transform-space.js';
3
+ /**
4
+ * Acquire one explicitly selected native transform and its schedule (projected into the document
5
+ * and kept as read). HTTP404 remains a read failure, never an absence or create permission. In
6
+ * retrieve mode the schedule read is best effort: a failed read or an answer that is not an object
7
+ * leaves the schedule out of the file (deploy then leaves the schedule alone), with a warning.
8
+ * @param {string} nameOrId Exact selected API name or native record ID.
9
+ * The transform's data space is resolved right after the GET, before anything is projected: its
10
+ * `dataSpaceName`, otherwise the org's MktDataTransform record (`client.dataSpaces`). With
11
+ * `dataSpace`, a transform of another data space is TRANSFORM_DATASPACE_MISMATCH, never a
12
+ * verbatim stand-in.
13
+ * @param {Pick<DataTransformClient, 'get' | 'schedule' | 'dataSpaces'>} client Qualified API68 transport.
14
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (lenient).
15
+ * @param {string[]} [warnings] Receives the retrieve-mode schedule warning.
16
+ * @param {string} [dataSpace] The data space the transform must be in.
17
+ * @returns {Promise<DataTransformObservation>} Input-only artifact and detached observations.
18
+ */
19
+ export async function retrieveDataTransform(nameOrId, client, mode = 'deploy', warnings, dataSpace) {
20
+ if (typeof nameOrId !== 'string' ||
21
+ !(dataTransformName.test(nameOrId) || dataTransformId.test(nameOrId)))
22
+ throw new DataTransformError('INVALID_TRANSFORM_SELECTION');
23
+ const runtime = await client.get(nameOrId);
24
+ if (!runtime || typeof runtime !== 'object' || Array.isArray(runtime))
25
+ throw new DataTransformError('INVALID_TRANSFORM_RESPONSE');
26
+ const id = Object.getOwnPropertyDescriptor(runtime, 'id');
27
+ const name = Object.getOwnPropertyDescriptor(runtime, 'name');
28
+ if (!id ||
29
+ !('value' in id) ||
30
+ typeof id.value !== 'string' ||
31
+ !dataTransformId.test(id.value) ||
32
+ !name ||
33
+ !('value' in name) ||
34
+ typeof name.value !== 'string' ||
35
+ !dataTransformName.test(name.value) ||
36
+ (nameOrId !== id.value && nameOrId !== name.value))
37
+ throw new DataTransformError('TRANSFORM_IDENTITY_MISMATCH');
38
+ const space = await resolveDataTransformSpace(runtime, async () => client.dataSpaces());
39
+ if (dataSpace !== undefined && space !== dataSpace)
40
+ throw dataTransformSpaceMismatch(name.value, space, dataSpace);
41
+ if (mode === 'deploy')
42
+ return observeDataTransform(runtime, await client.schedule(id.value), 'deploy', space);
43
+ let schedule;
44
+ try {
45
+ schedule = await client.schedule(id.value);
46
+ }
47
+ catch {
48
+ schedule = undefined;
49
+ }
50
+ if (!schedule || typeof schedule !== 'object' || Array.isArray(schedule)) {
51
+ warnings?.push(`data-transform:${name.value}: its schedule could not be read, so the file leaves it out and a deploy of the file leaves the schedule alone. Check it in Data Cloud.`);
52
+ schedule = {};
53
+ }
54
+ return observeDataTransform(runtime, schedule, mode, space);
55
+ }
56
+ /**
57
+ * Return the portable artifact relative path; filesystem publication belongs to command integration.
58
+ * @param {string} apiName Exact admitted transform developer name.
59
+ * @returns {string} Fixed portable JSON destination under the source root.
60
+ */
61
+ export function dataTransformArtifactPath(apiName) {
62
+ if (typeof apiName !== 'string' || !dataTransformName.test(apiName))
63
+ throw new DataTransformError('INVALID_TRANSFORM_SELECTION');
64
+ return `data360/dataTransforms/${apiName}.dataTransform.json`;
65
+ }
@@ -0,0 +1,40 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ import type { IdentityResolutionDocument, IdentityResolutionProjection } from '../artifacts/identity-resolution-document.js';
3
+ import type { ApiVersionSelection } from '../transport/api-version.js';
4
+ import type { DocumentMode } from '../artifacts/verbatim-document.js';
5
+ export type IdentityResolutionAcquisition = {
6
+ /** The ruleset's name and the run's data space (the ruleset's, once it was read). */
7
+ identity: {
8
+ dataSpace: string;
9
+ apiName: string;
10
+ };
11
+ candidate?: IdentityResolutionDocument;
12
+ blockers: string[];
13
+ expectations?: IdentityResolutionProjection['expectations'];
14
+ };
15
+ /**
16
+ * Acquire one settled qualified owner through its genuine API68 native endpoint.
17
+ * Owner projection is not generated-DMO field/type qualification or target binding.
18
+ * @param {Connection} connection Authenticated command-owned numeric API68 connection.
19
+ * @param {string} apiName Exact exposed owner objectApiName, including its actual suffix.
20
+ * @param {ApiVersionSelection} apiVersion Explicit frozen native version selection.
21
+ * @param {string} dataSpace The run's data space: a ruleset of another one is the blocker
22
+ * IDENTITY_RESOLUTION_DATASPACE_MISMATCH, found before anything is projected.
23
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps what the plugin does not model).
24
+ * @returns {Promise<IdentityResolutionAcquisition>} Candidate and private correlation expectations.
25
+ */
26
+ export declare function retrieveIdentityResolution(connection: Pick<Connection, 'instanceUrl' | 'request' | 'getApiVersion'>, apiName: string, apiVersion: ApiVersionSelection, dataSpace: string, mode?: DocumentMode): Promise<IdentityResolutionAcquisition>;
27
+ /**
28
+ * Every identity resolution ruleset of one data space the API 68 list returns, by owner
29
+ * `objectApiName`. The list has no paging (it answers every ruleset at once and ignores
30
+ * `batchSize`, `limit` and `offset`); extra envelope keys are ignored and a malformed answer is
31
+ * IDENTITY_RESOLUTION_ACQUISITION_FAILED. An entry without a usable name or data space is skipped
32
+ * with a warning, a ruleset of another data space is left out (the list answers every data space
33
+ * whatever `?dataspace=` says, so each entry's `dataSpaceName` decides) and a repeated name is
34
+ * listed once.
35
+ * @param {Pick<Connection, 'instanceUrl' | 'request'>} connection Authenticated API 68 connection.
36
+ * @param {string[]} [warnings] Receives one warning per skipped entry.
37
+ * @param {string} [dataSpace] The run's data space.
38
+ * @returns {Promise<string[]>} Sorted owner names.
39
+ */
40
+ export declare function listIdentityResolutionNames(connection: Pick<Connection, 'instanceUrl' | 'request'>, warnings?: string[], dataSpace?: string): Promise<string[]>;
@@ -0,0 +1,87 @@
1
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
2
+ import { IdentityResolutionError, identityResolutionName, identityResolutionSpace, identityResolutionSpaceMismatch, projectNativeIdentityResolution, } from '../artifacts/identity-resolution-document.js';
3
+ import { isDataSpaceName } from '../artifacts/data-space-field.js';
4
+ import { ConnectClient } from '../transport/connect-client.js';
5
+ import { carryNativeResponse } from '../artifacts/verbatim-document.js';
6
+ /**
7
+ * Acquire one settled qualified owner through its genuine API68 native endpoint.
8
+ * Owner projection is not generated-DMO field/type qualification or target binding.
9
+ * @param {Connection} connection Authenticated command-owned numeric API68 connection.
10
+ * @param {string} apiName Exact exposed owner objectApiName, including its actual suffix.
11
+ * @param {ApiVersionSelection} apiVersion Explicit frozen native version selection.
12
+ * @param {string} dataSpace The run's data space: a ruleset of another one is the blocker
13
+ * IDENTITY_RESOLUTION_DATASPACE_MISMATCH, found before anything is projected.
14
+ * @param {DocumentMode} [mode] `deploy` (strict) or `retrieve` (keeps what the plugin does not model).
15
+ * @returns {Promise<IdentityResolutionAcquisition>} Candidate and private correlation expectations.
16
+ */
17
+ export async function retrieveIdentityResolution(connection, apiName, apiVersion, dataSpace, mode = 'deploy') {
18
+ const version = '68.0';
19
+ if (apiVersion?.requested !== version ||
20
+ apiVersion.restSelector !== `v${version}` ||
21
+ apiVersion.soapNumeric !== version ||
22
+ connection.getApiVersion() !== version ||
23
+ !isDataSpaceName(dataSpace) ||
24
+ typeof apiName !== 'string' ||
25
+ !identityResolutionName.test(apiName))
26
+ throw new IdentityResolutionError('INVALID_SCOPE');
27
+ const identity = { dataSpace, apiName };
28
+ // The raw GET response travels with the result and the candidate, for a verbatim file when
29
+ // the owner cannot be represented.
30
+ let read;
31
+ try {
32
+ const native = await new ConnectClient(connection, apiVersion).get(`/services/data/v68.0/ssot/identity-resolutions/${apiName}`);
33
+ read = { native };
34
+ // The item route reads a ruleset of any data space by name: check its space first. A ruleset
35
+ // of another space is an item failure, never a verbatim file.
36
+ const found = identityResolutionSpace(native);
37
+ if (found !== dataSpace)
38
+ throw identityResolutionSpaceMismatch(apiName, found, dataSpace, 'org');
39
+ const projection = projectNativeIdentityResolution(native, apiName, mode);
40
+ carryNativeResponse(projection.candidate, native);
41
+ return carryNativeResponse({ identity, ...projection, blockers: [] }, native);
42
+ }
43
+ catch (error) {
44
+ const result = retainConnectDiagnostic({
45
+ identity,
46
+ blockers: [
47
+ error instanceof IdentityResolutionError
48
+ ? error.code
49
+ : 'IDENTITY_RESOLUTION_ACQUISITION_FAILED',
50
+ ],
51
+ }, getConnectDiagnostic(error));
52
+ return read ? carryNativeResponse(result, read.native) : result;
53
+ }
54
+ }
55
+ /**
56
+ * Every identity resolution ruleset of one data space the API 68 list returns, by owner
57
+ * `objectApiName`. The list has no paging (it answers every ruleset at once and ignores
58
+ * `batchSize`, `limit` and `offset`); extra envelope keys are ignored and a malformed answer is
59
+ * IDENTITY_RESOLUTION_ACQUISITION_FAILED. An entry without a usable name or data space is skipped
60
+ * with a warning, a ruleset of another data space is left out (the list answers every data space
61
+ * whatever `?dataspace=` says, so each entry's `dataSpaceName` decides) and a repeated name is
62
+ * listed once.
63
+ * @param {Pick<Connection, 'instanceUrl' | 'request'>} connection Authenticated API 68 connection.
64
+ * @param {string[]} [warnings] Receives one warning per skipped entry.
65
+ * @param {string} [dataSpace] The run's data space.
66
+ * @returns {Promise<string[]>} Sorted owner names.
67
+ */
68
+ export async function listIdentityResolutionNames(connection, warnings, dataSpace = 'default') {
69
+ const response = await new ConnectClient(connection, '68.0').get('/services/data/v68.0/ssot/identity-resolutions');
70
+ const entries = response?.identityResolutions;
71
+ if (!response || typeof response !== 'object' || !Array.isArray(entries))
72
+ throw new IdentityResolutionError('IDENTITY_RESOLUTION_ACQUISITION_FAILED');
73
+ const names = new Set();
74
+ for (const [index, entry] of entries.entries()) {
75
+ const item = (entry && typeof entry === 'object' ? entry : {});
76
+ const apiName = typeof item.objectApiName === 'string' ? item.objectApiName : undefined;
77
+ const usable = apiName !== undefined && identityResolutionName.test(apiName);
78
+ if (!usable || typeof item.dataSpaceName !== 'string' || !item.dataSpaceName) {
79
+ warnings?.push(`identity-resolution inventory: skipped ${apiName === undefined ? `the entry at position ${index}` : `"${apiName}"`} because it has no usable ${usable ? 'data space' : 'API name'}.`);
80
+ continue;
81
+ }
82
+ if (item.dataSpaceName === dataSpace)
83
+ names.add(apiName);
84
+ }
85
+ // eslint-disable-next-line unicorn/no-array-sort -- Sorting a new array.
86
+ return [...names].sort();
87
+ }
@@ -0,0 +1,32 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ /**
3
+ * Every data stream `GET /ssot/data-streams` lists (`limit` 1 to 200, `offset`), kept unless its
4
+ * DLO names only other data spaces than the run's.
5
+ * @param {Pick<Connection, 'instanceUrl' | 'request'>} connection Authenticated connection.
6
+ * @param {string} version Numeric API version.
7
+ * @param {string[]} [warnings] Receives one warning per skipped entry.
8
+ * @param {string} [dataSpace] The run's data space.
9
+ * @returns {Promise<string[]>} Sorted stream API names.
10
+ */
11
+ export declare function listDataStreamNames(connection: Pick<Connection, 'instanceUrl' | 'request'>, version: string, warnings?: string[], dataSpace?: string): Promise<string[]>;
12
+ /**
13
+ * Every data transform of the run's data space that `GET /ssot/data-transforms` lists (pages of
14
+ * at most 20, `offset`; the list ignores `?dataspace=`, live API 68). An entry is in the data
15
+ * space its `dataSpaceName` names; for one without it, one SOQL read of the org's
16
+ * MktDataTransform records names it by the entry's record `id`, and a transform without any data
17
+ * space there (a system transform) is listed in default only.
18
+ * @param {Pick<Connection, 'instanceUrl' | 'request'>} connection Authenticated connection.
19
+ * @param {string[]} [warnings] Receives one warning per skipped entry.
20
+ * @param {string} [dataSpace] The run's data space.
21
+ * @returns {Promise<string[]>} Sorted transform names.
22
+ */
23
+ export declare function listDataTransformNames(connection: Pick<Connection, 'instanceUrl' | 'request'>, warnings?: string[], dataSpace?: string): Promise<string[]>;
24
+ /**
25
+ * Every data graph of one data space `GET /ssot/data-graphs/metadata?dataspace=` lists (the route
26
+ * filters by it and has no paging); each entry's own `dataspaceName` must name it too.
27
+ * @param {Pick<Connection, 'instanceUrl' | 'request'>} connection Authenticated connection.
28
+ * @param {string[]} [warnings] Receives one warning per skipped entry.
29
+ * @param {string} [dataSpace] The run's data space.
30
+ * @returns {Promise<string[]>} Sorted graph developer names.
31
+ */
32
+ export declare function listDataGraphNames(connection: Pick<Connection, 'instanceUrl' | 'request'>, warnings?: string[], dataSpace?: string): Promise<string[]>;