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,116 @@
1
+ import { AuthInfo, Connection } from '@salesforce/core';
2
+ import { ConnectClient, ConnectError } from './connect-client.js';
3
+ import { getConnectDiagnostic } from './connect-diagnostic.js';
4
+ /**
5
+ * Whether a failure is Salesforce's answer to an expired access token: HTTP 401 INVALID_SESSION_ID.
6
+ * @param {unknown} error Failure of one request.
7
+ * @returns {boolean} Expired session.
8
+ */
9
+ function sessionExpired(error) {
10
+ return (error instanceof ConnectError &&
11
+ error.code === 'AUTHENTICATION_FAILED' &&
12
+ error.statusCode === 401 &&
13
+ (getConnectDiagnostic(error)?.errors ?? []).some((entry) => entry.code === 'INVALID_SESSION_ID'));
14
+ }
15
+ /**
16
+ * Routes on the bound Connection: no child CLI and no redirect. A GET answered with an expired
17
+ * session refreshes the token once through Salesforce core (one refresh shared by concurrent
18
+ * reads) and is sent once more. A write (POST, PATCH, PUT, DELETE) keeps ConnectClient.send's
19
+ * write rule: it is resent only after a failure that proves it never left (ECONNREFUSED,
20
+ * ENOTFOUND, EHOSTUNREACH, EAI_AGAIN), never after a reset, timeout, 429 or 503, and never
21
+ * after a token refresh. The caller's read-back decides what the write did.
22
+ */
23
+ class BoundTransport extends ConnectClient {
24
+ session;
25
+ refreshing;
26
+ constructor(session, version) {
27
+ super(session, version);
28
+ this.session = session;
29
+ }
30
+ /**
31
+ * Dispatch one fixed route.
32
+ * @param {BoundMethod} method Read or write.
33
+ * @param {string} route Root-relative endpoint.
34
+ * @param {unknown} [noContent] Sentinel JSforce returns for HTTP 204.
35
+ * @param {unknown} [body] JSON body of a write.
36
+ * @returns {Promise<unknown>} Untrusted native response.
37
+ */
38
+ async request(method, route, noContent, body) {
39
+ const url = this.safeUrl(route);
40
+ const request = body === undefined
41
+ ? { method, url }
42
+ : {
43
+ method,
44
+ url,
45
+ body: JSON.stringify(body),
46
+ headers: { 'content-type': 'application/json' },
47
+ };
48
+ const send = async () => this.send(request, this.noRefreshReceiver(), noContent);
49
+ try {
50
+ return await send();
51
+ }
52
+ catch (error) {
53
+ const refresh = this.session.refreshAuth;
54
+ if (method !== 'GET' || !sessionExpired(error) || typeof refresh !== 'function')
55
+ throw error;
56
+ try {
57
+ this.refreshing ??= refresh.call(this.session).finally(() => {
58
+ this.refreshing = undefined;
59
+ });
60
+ await this.refreshing;
61
+ }
62
+ catch {
63
+ throw error;
64
+ }
65
+ return send();
66
+ }
67
+ }
68
+ }
69
+ /**
70
+ * Bind SSOT reads and writes, and the Metadata API calls, to one lazily opened authenticated
71
+ * Connection.
72
+ * Failures surface as ConnectError with the retained API diagnostic; callers map them.
73
+ * @param {string} targetOrg Resolved username of the target org.
74
+ * @param {string} version Numeric API version such as 68.0, already normalized by the caller.
75
+ * @param {BoundConnection} [connect] Supplies the Connection; defaults to the CLI auth for targetOrg.
76
+ * @returns {BoundSsot} Sender; a GET is resent once after an expired-session refresh, a write never.
77
+ * Its Metadata API calls use the same Connection.
78
+ */
79
+ export function openBoundSsot(targetOrg, version, connect) {
80
+ const open = connect ??
81
+ (async () => Connection.create({
82
+ authInfo: await AuthInfo.create({ username: targetOrg }),
83
+ connectionOptions: { version },
84
+ }));
85
+ let session;
86
+ let transport;
87
+ // Metadata API calls go one at a time even when REST reads run in parallel: they are cheap
88
+ // (about 0.15 s each) and the Metadata API answers REQUEST_LIMIT_EXCEEDED to every call once an
89
+ // org has sent about a thousand in an hour (DB entry data360:a2.retrieve-speed.api68), so
90
+ // they are never sent faster than one after another.
91
+ let metadataQueue = Promise.resolve();
92
+ const oneAtATime = async (call) => {
93
+ const turn = metadataQueue.then(call);
94
+ metadataQueue = turn.catch(() => { });
95
+ return turn;
96
+ };
97
+ return {
98
+ request: async (method, route, noContent, body) => {
99
+ session ??= open();
100
+ const opened = session;
101
+ transport ??= (async () => new BoundTransport(await opened, version))();
102
+ const client = await transport;
103
+ return client.request(method, route, noContent, body);
104
+ },
105
+ metadata: async () => {
106
+ session ??= open();
107
+ const api = (await session).metadata;
108
+ if (!api || typeof api.read !== 'function' || typeof api.update !== 'function')
109
+ throw new ConnectError('REQUEST_FAILED');
110
+ return {
111
+ read: async (type, fullNames) => oneAtATime(async () => api.read(type, fullNames)),
112
+ update: async (type, metadata) => oneAtATime(async () => api.update(type, metadata)),
113
+ };
114
+ },
115
+ };
116
+ }
@@ -0,0 +1,28 @@
1
+ import type { NativeCalculatedInsight } from '../artifacts/native-calculated-insight-document.js';
2
+ import { ConnectClient } from './connect-client.js';
3
+ export type CalculatedInsightClient = {
4
+ get: (apiName: string) => Promise<unknown>;
5
+ /** POST of the document; `draft: true` with --draft, no `draft` key otherwise. */
6
+ create: (document: NativeCalculatedInsight, options?: {
7
+ draft?: true;
8
+ }) => Promise<unknown>;
9
+ /**
10
+ * PATCH of the document; `draft` is sent only when given. `observed` is the org document
11
+ * the update is based on (an unchanged `definitionType` is left out).
12
+ */
13
+ update: (document: NativeCalculatedInsight, options?: {
14
+ draft?: boolean;
15
+ observed?: NativeCalculatedInsight;
16
+ }) => Promise<unknown>;
17
+ delete: (apiName: string) => Promise<unknown>;
18
+ };
19
+ /**
20
+ * The API 68 calculated insight routes. The body is the authored document with the input
21
+ * key names and enum forms (`calculatedInsightInputBody`); Salesforce decides the rest.
22
+ * @param {ConstructorParameters<typeof ConnectClient>[0]} connection Authenticated connection.
23
+ * @param {string} apiVersion '68.0' only.
24
+ * @param {string} dataSpace The run's data space. The item routes take none (names are unique in
25
+ * the org); the create and update bodies carry it as `dataSpaceName` from the file.
26
+ * @returns {CalculatedInsightClient} Exact-name operations.
27
+ */
28
+ export declare function createCalculatedInsightClient(connection: ConstructorParameters<typeof ConnectClient>[0], apiVersion: string, dataSpace: string): CalculatedInsightClient;
@@ -0,0 +1,62 @@
1
+ import { isDataSpaceName } from '../artifacts/data-space-field.js';
2
+ import { calculatedInsightInputBody, calculatedInsightName, CalculatedInsightError, validateNativeCalculatedInsight, } from '../artifacts/native-calculated-insight-document.js';
3
+ import { ConnectClient } from './connect-client.js';
4
+ /** Internal access to the shared single-attempt, no-refresh transport, not a generic public writer. */
5
+ class CalculatedInsightTransport extends ConnectClient {
6
+ /**
7
+ * Send one request; every returned value remains untrusted.
8
+ * @param {string} route Exact route.
9
+ * @param {'GET' | 'POST' | 'PATCH' | 'DELETE'} method Native verb.
10
+ * @param {Record<string, unknown>} [body] Payload, absent for DELETE and GET.
11
+ * @returns {Promise<unknown>} Raw response, including undefined for an empty DELETE reply.
12
+ */
13
+ async request(route, method, body) {
14
+ return this.send({
15
+ method,
16
+ url: this.safeUrl(route),
17
+ ...(body === undefined
18
+ ? {}
19
+ : { body: JSON.stringify(body), headers: { 'content-type': 'application/json' } }),
20
+ }, this.noRefreshReceiver());
21
+ }
22
+ }
23
+ /**
24
+ * The API 68 calculated insight routes. The body is the authored document with the input
25
+ * key names and enum forms (`calculatedInsightInputBody`); Salesforce decides the rest.
26
+ * @param {ConstructorParameters<typeof ConnectClient>[0]} connection Authenticated connection.
27
+ * @param {string} apiVersion '68.0' only.
28
+ * @param {string} dataSpace The run's data space. The item routes take none (names are unique in
29
+ * the org); the create and update bodies carry it as `dataSpaceName` from the file.
30
+ * @returns {CalculatedInsightClient} Exact-name operations.
31
+ */
32
+ export function createCalculatedInsightClient(connection, apiVersion, dataSpace) {
33
+ if (apiVersion !== '68.0' || !isDataSpaceName(dataSpace))
34
+ throw new CalculatedInsightError('INVALID_CI_SCOPE');
35
+ const transport = new CalculatedInsightTransport(connection, apiVersion);
36
+ const endpoint = `/services/data/v${apiVersion}/ssot/calculated-insights`;
37
+ /**
38
+ * Bind only an exact full CI API name, never an ID or query.
39
+ * @param {string} apiName Full developer name.
40
+ * @returns {string} Exact resource route.
41
+ */
42
+ function item(apiName) {
43
+ if (typeof apiName !== 'string' || !calculatedInsightName.test(apiName))
44
+ throw new CalculatedInsightError('INVALID_CI_NAME');
45
+ return `${endpoint}/${apiName}`;
46
+ }
47
+ return {
48
+ get: async (apiName) => transport.request(item(apiName), 'GET'),
49
+ create: async (document, options) => transport.request(endpoint, 'POST', {
50
+ ...calculatedInsightInputBody(validateNativeCalculatedInsight(document), 'create'),
51
+ ...(options?.draft === true ? { draft: true } : {}),
52
+ }),
53
+ update: async (document, options) => {
54
+ const checked = validateNativeCalculatedInsight(document);
55
+ return transport.request(item(checked.apiName), 'PATCH', {
56
+ ...calculatedInsightInputBody(checked, 'update', options?.observed),
57
+ ...(typeof options?.draft === 'boolean' ? { draft: options.draft } : {}),
58
+ });
59
+ },
60
+ delete: async (apiName) => transport.request(item(apiName), 'DELETE'),
61
+ };
62
+ }
@@ -1,20 +1,52 @@
1
1
  import type { Connection } from '@salesforce/core';
2
- import type { DmoUpdatePatch } from '../artifacts/dmo-update-delta.js';
3
- export type TransportErrorCode = 'INVALID_REQUEST' | 'AUTHENTICATION_FAILED' | 'REQUEST_FAILED' | 'INVALID_PAGE' | 'INCOMPLETE_LIST';
2
+ import type { ApiVersionSelection } from './api-version.js';
3
+ export type TransportErrorCode = 'INVALID_REQUEST' | 'AUTHENTICATION_FAILED' | 'REQUEST_FAILED';
4
+ /** Native 404 codes that name an item as absent or deleted, read from a single REST error. */
5
+ declare const nativeAbsenceCodes: readonly ["ITEM_NOT_FOUND", "ENTITY_IS_DELETED"];
6
+ export type NativeAbsenceCode = (typeof nativeAbsenceCodes)[number];
7
+ /**
8
+ * The request header that makes Connect REST answer in plain text. By default it HTML-escapes
9
+ * every string of a response (`<>"'\&` read as `&lt; &gt; &quot; &#39; &#92; &amp;`) while it
10
+ * stores what a write sends as is, so a retrieved label, description, formula or SQL would not be
11
+ * what Salesforce holds (live API 68: data transforms, DLOs, data streams, calculated insights,
12
+ * segments; DB entry data360:connect-rest-entity-encoding-header-api68).
13
+ */
14
+ export declare const plainTextHeaders: Readonly<Record<string, string>>;
15
+ /**
16
+ * The request with {@link plainTextHeaders} when it goes to a Data 360 (`/ssot/`) route; any
17
+ * other request as it is. Only `/ssot/` routes get the header: a Data 360 read on any other
18
+ * route still returns HTML-escaped text.
19
+ * @param {Parameters<Connection['request']>[0]} request Request as built.
20
+ * @returns {Parameters<Connection['request']>[0]} Request to send.
21
+ */
22
+ export declare function plainTextRequest(request: Parameters<Connection['request']>[0]): Parameters<Connection['request']>[0];
4
23
  /** An intentionally payload-free diagnostic safe for JSON and console output. */
5
24
  export declare class ConnectError extends Error {
6
25
  readonly code: TransportErrorCode;
7
26
  readonly statusCode?: number | undefined;
8
- constructor(code: TransportErrorCode, statusCode?: number | undefined);
27
+ readonly nativeCode?: NativeAbsenceCode | undefined;
28
+ constructor(code: TransportErrorCode, statusCode?: number | undefined, nativeCode?: NativeAbsenceCode | undefined);
9
29
  }
30
+ /**
31
+ * Bounded retry of in-process requests. GETs retry after network errors and HTTP 429/503;
32
+ * writes retry only when the request provably never reached Salesforce. `sleep` and `warn`
33
+ * are replaceable (tests, commands); `warn` defaults to one stderr line so JSON stdout stays clean.
34
+ */
35
+ export declare const connectRetry: {
36
+ attempts: number;
37
+ delaysMs: number[];
38
+ maxRetryAfterMs: number;
39
+ sleep: (milliseconds: number) => Promise<void>;
40
+ warn: (message: string) => void;
41
+ };
10
42
  type AuthenticatedConnection = Pick<Connection, 'instanceUrl' | 'request'>;
11
43
  /** Bounded SSOT transport; Salesforce core owns credentials. */
12
44
  export declare class ConnectClient {
13
45
  private readonly connection;
14
- private readonly apiVersion;
15
46
  private readonly origin;
16
47
  private readonly prefix;
17
- constructor(connection: AuthenticatedConnection, apiVersion: string);
48
+ private readonly selection;
49
+ constructor(connection: AuthenticatedConnection, selection: ApiVersionSelection | string);
18
50
  /**
19
51
  * Load existing Salesforce CLI authentication without exposing token fields.
20
52
  * @param {string} aliasOrUsername Explicit existing org alias or username.
@@ -23,45 +55,75 @@ export declare class ConnectClient {
23
55
  */
24
56
  static create(aliasOrUsername: string, apiVersion: string): Promise<ConnectClient>;
25
57
  /**
26
- * Read a single SSOT response. Does not infer pagination or retry a failed call.
58
+ * Read a single SSOT response. Does not infer pagination; see `connectRetry` for the bounded retry.
27
59
  * @template T
28
60
  * @param {string} path Root-relative SSOT path or same-origin absolute URL, with optional query.
29
61
  * @returns {Promise<T>} The unmodified resource response; callers must validate its schema.
30
62
  */
31
63
  get<T = unknown>(path: string): Promise<T>;
32
64
  /**
33
- * Create one validated authored DMO at the fixed API65 endpoint, without retry or redirect.
34
- * A per-call receiver masks JSforce's refresh delegate (which otherwise replays POST on 401).
35
- * Never mutates the supplied connection or exposes a generic write route.
36
- * @param {unknown} document Independently validated authored-only default-space document.
37
- * @returns {Promise<unknown>} Untrusted response, never proof of successful creation.
65
+ * Create one native API68 Segment in the data space of the file (`?dataspace=`), without
66
+ * redirect or replay. The definition goes as written (`segmentWriteBody`); without a schedule in
67
+ * the file it does not refresh.
68
+ * @param {unknown} value Complete admitted portable definition.
69
+ * @param {ReadonlyMap<string, string>} [children] Waterfall child API name to target definition ID.
70
+ * @returns {Promise<unknown>} Untrusted acknowledgement, not settlement.
38
71
  */
39
- createDataModelObject(document: unknown): Promise<unknown>;
72
+ createSegment(value: unknown, children?: ReadonlyMap<string, string>): Promise<unknown>;
40
73
  /**
41
- * Send one PATCH to an exact API65 DMO route without refresh, retry or redirect.
42
- * Callers must qualify the patch and authorize execution independently; this is transport only.
43
- * @param {string} dataModelObjectName Exact qualified DMO API name.
44
- * @param {DmoUpdatePatch} patch Caller-qualified update payload, not validated here.
45
- * @returns {Promise<unknown>} Untrusted response, never proof of a successful update.
74
+ * PATCH the full authored definition on the native API68 Segment route; the schedule keys go
75
+ * along only when `schedule` is set (the schedule of the file differs from the org's).
76
+ * @param {unknown} value Complete independently admitted desired Segment document.
77
+ * @param {boolean} [schedule] Whether to send the schedule of the file.
78
+ * @param {ReadonlyMap<string, string>} [children] Waterfall child API name to target definition ID.
79
+ * @returns {Promise<unknown>} Untrusted single-attempt response, never settlement evidence.
46
80
  */
47
- patchDataModelObject(dataModelObjectName: string, patch: DmoUpdatePatch): Promise<unknown>;
48
- private writeReceiver;
49
- private read;
50
- private send;
81
+ patchSegment(value: unknown, schedule?: boolean, children?: ReadonlyMap<string, string>): Promise<unknown>;
82
+ /**
83
+ * Create exactly one native68 IR owner without refresh, replay or redirect.
84
+ * @param {unknown} value Complete independently admitted portable definition.
85
+ * @param {string} [dataSpacePrefix] Prefix of the ruleset's data space; required outside default.
86
+ * @returns {Promise<unknown>} Untrusted response, never settlement evidence.
87
+ */
88
+ createIdentityResolution(value: unknown, dataSpacePrefix?: string): Promise<unknown>;
89
+ /**
90
+ * PATCH the complete preserved input shape on one exact native68 owner; never run processing.
91
+ * @param {unknown} value Complete independently admitted desired definition.
92
+ * @param {unknown} [current] Current target definition; lists it has and the file empties are sent empty.
93
+ * @returns {Promise<unknown>} Untrusted response, never settlement evidence.
94
+ */
95
+ patchIdentityResolution(value: unknown, current?: unknown): Promise<unknown>;
51
96
  /**
52
- * Read the offset-paginated DMO inventory, without projecting resource fields.
53
- * A short page terminates the list; unsupported continuation shapes fail closed.
54
- * @returns {Promise<Array<Record<string, unknown>>>} Complete raw DMO entries or an error, never a partial list.
97
+ * Delete exactly one native68 owner by its freshly resolved Salesforce record ID.
98
+ * No name routing, refresh, replay, redirect or arbitrary DELETE path is exposed.
99
+ * @param {string} id Independently bound target-local IR record ID.
100
+ * @returns {Promise<void>} Acknowledged HTTP204 only, never owner absence proof.
55
101
  */
56
- listDataModelObjects(): Promise<Array<Record<string, unknown>>>;
102
+ deleteIdentityResolution(id: string): Promise<void>;
57
103
  /**
58
- * Acquire raw incoming and outgoing relationships in one explicit data space.
59
- * Pagination metadata must prove exhaustion; raw records are not portable artifacts.
60
- * @param {string} dataModelObjectName Exact DMO API name, including any namespace.
61
- * @param {string} dataSpace Exact server data-space name; never silently defaults.
62
- * @returns {Promise<Array<Record<string, unknown>>>} Complete raw relationships or an error.
104
+ * Delete one exact native68 Segment by API name, without replay or redirect.
105
+ * @param {string} apiName Freshly matched target API name.
106
+ * @returns {Promise<void>} HTTP204 acknowledgement, not independent absence proof.
63
107
  */
64
- listDataModelObjectRelationships(dataModelObjectName: string, dataSpace: string): Promise<Array<Record<string, unknown>>>;
65
- private safeUrl;
108
+ deleteSegment(apiName: string): Promise<void>;
109
+ /**
110
+ * Publish one native API68 Segment by its record ID: one POST without a body, never resent
111
+ * after a reset, timeout, 429 or 503 (only a request that provably never left is repeated).
112
+ * @param {string} marketSegmentId Freshly read `1sg` record ID of the segment.
113
+ * @returns {Promise<unknown>} Untrusted acknowledgement (publishStatus, jobId), not the result.
114
+ */
115
+ publishSegment(marketSegmentId: string): Promise<unknown>;
116
+ /**
117
+ * Run one read-only SOQL query (the core `/query` route, outside SSOT) over the command's own
118
+ * connection, without refresh or redirect; the first page only. Callers check `done`.
119
+ * @param {string} query SOQL built only from validated identifiers and static text.
120
+ * @returns {Promise<unknown>} Untrusted query response.
121
+ */
122
+ soql(query: string): Promise<unknown>;
123
+ protected noRefreshReceiver(): AuthenticatedConnection;
124
+ private read;
125
+ protected send<T>(request: Parameters<Connection['request']>[0], receiver: AuthenticatedConnection, noContentResponse?: unknown): Promise<T>;
126
+ private sendOnce;
127
+ protected safeUrl(path: string): string;
66
128
  }
67
129
  export {};