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,201 @@
1
+ import { displayableApiText, getConnectDiagnostic, retainConnectDiagnostic, } from './connect-diagnostic.js';
2
+ import { replaceExplanation } from '../services/operation-diagnostic.js';
3
+ import { ConnectError } from './connect-client.js';
4
+ import { nativeApiVersion } from './api-version.js';
5
+ import { openBoundSsot } from './bound-ssot.js';
6
+ import { NativeRelationshipError, nativeRelationshipName, relationshipDmoName, validateNativeRelationshipDocument, } from '../artifacts/native-relationship-document.js';
7
+ /** Proven page size; `nextPageUrl` repeats the current offset, so callers page by offset. */
8
+ export const relationshipPageSize = 200;
9
+ /** Metadata API type of a Data Cloud relationship; the record name is the relationship name. */
10
+ export const relationshipMetadataType = 'FieldSrcTrgtRelationship';
11
+ /** Names per Metadata API read call (the API's limit). */
12
+ export const relationshipReadBatch = 10;
13
+ /** Refusals that were Salesforce's generic "unexpected error" (UNKNOWN_EXCEPTION). */
14
+ const unexpectedRefusals = new WeakSet();
15
+ /**
16
+ * Whether an update refusal was Salesforce's generic "An unexpected error occurred" answer
17
+ * (UNKNOWN_EXCEPTION). Salesforce gives it both for a change it refuses and, now and then, for a
18
+ * valid change that succeeds when sent again (live, API 68).
19
+ * @param {unknown} error Failure of `update`.
20
+ * @returns {boolean} The generic unexpected-error refusal.
21
+ */
22
+ export function isUnexpectedUpdateRefusal(error) {
23
+ return typeof error === 'object' && error !== null && unexpectedRefusals.has(error);
24
+ }
25
+ /**
26
+ * Salesforce's refusal of an update: nothing was changed. Codes and texts pass the display
27
+ * filter of REST errors; a text that does not pass is left out.
28
+ * @param {string} name Relationship name.
29
+ * @param {Array<{code?: unknown; message?: unknown}>} problems Salesforce's answers.
30
+ * @returns {NativeRelationshipError} RELATIONSHIP_UPDATE_REJECTED with an explanation.
31
+ */
32
+ function updateRefusal(name, problems) {
33
+ const parts = problems
34
+ .slice(0, 3)
35
+ .map(({ code, message }) => [
36
+ typeof code === 'string' && /^[\w:.-]{1,80}$/u.test(code) ? code : undefined,
37
+ displayableApiText(message),
38
+ ]
39
+ .filter(Boolean)
40
+ .join(': '));
41
+ const said = parts.filter(Boolean);
42
+ const error = new NativeRelationshipError('RELATIONSHIP_UPDATE_REJECTED');
43
+ if (problems.length === 1 &&
44
+ problems[0].code === 'UNKNOWN_EXCEPTION' &&
45
+ typeof problems[0].message === 'string' &&
46
+ problems[0].message.startsWith('An unexpected error occurred.'))
47
+ unexpectedRefusals.add(error);
48
+ replaceExplanation(error, `Salesforce refused the Metadata API update of the relationship ${name}${said.length > 0 ? `: ${said.join('; ')}` : ' without a text the plugin can show'}. Nothing was changed.`);
49
+ return error;
50
+ }
51
+ /** SOAP faults where Salesforce refused the request itself, so nothing was applied. */
52
+ const clientFault = /^(?:soapenv:Client|sf:(?:INVALID_\w+|MALFORMED_\w+|REQUEST_LIMIT_EXCEEDED|INSUFFICIENT_ACCESS|API_DISABLED_FOR_ORG|UNSUPPORTED_API_VERSION))$/u;
53
+ /**
54
+ * A Metadata API answer as a list of records.
55
+ * @param {unknown} value One record or several.
56
+ * @returns {unknown[]} Records.
57
+ */
58
+ function records(value) {
59
+ if (value === undefined || value === null)
60
+ return [];
61
+ return Array.isArray(value) ? value : [value];
62
+ }
63
+ /**
64
+ * Build a native relationship client on the bound in-process connection; the POST and DELETE
65
+ * are never resent once they may have reached Salesforce.
66
+ * @param {string} targetOrg Explicit authenticated alias or username.
67
+ * @param {string} apiVersion Validated numeric version, or default/auto 68.0.
68
+ * @param {string} dataSpace The run's data space, sent as `?dataspace=` on every REST request
69
+ * (the Metadata API calls take record names, which are unique in the org).
70
+ * @param {BoundSsot} [sender] The command's shared sender; defaults to one opened for targetOrg.
71
+ * @returns {RelationshipClient} Raw operations.
72
+ */
73
+ export function createRelationshipClient(targetOrg, apiVersion = '68.0', dataSpace, sender) {
74
+ const version = nativeApiVersion(apiVersion);
75
+ if (!targetOrg ||
76
+ targetOrg.startsWith('-') ||
77
+ [...targetOrg].some((character) => character.codePointAt(0) < 32))
78
+ throw new NativeRelationshipError('UNSUPPORTED_RELATIONSHIP_SELECTION');
79
+ const endpoint = `/services/data/v${version}/ssot/data-model-objects`;
80
+ const scopeQuery = `?${new URLSearchParams({ dataspace: dataSpace })}`;
81
+ const noContent = Symbol('relationship-no-content');
82
+ const bound = sender ?? openBoundSsot(targetOrg, version);
83
+ /**
84
+ * Send one request on the bound connection: no child CLI, token refresh or redirect, and the
85
+ * POST is never resent once it may have reached Salesforce. Not settlement evidence.
86
+ * @param {'GET' | 'POST' | 'DELETE'} method HTTP verb.
87
+ * @param {string} route Validated route and query.
88
+ * @param {object} [body] Explicit create body.
89
+ * @returns {Promise<unknown>} Parsed object or `noContent` for GET/POST; nothing for DELETE.
90
+ */
91
+ async function request(method, route, body) {
92
+ let response;
93
+ try {
94
+ response = await bound.request(method, route, noContent, body);
95
+ }
96
+ catch (error) {
97
+ if (!(error instanceof ConnectError))
98
+ throw error;
99
+ const status = error.code === 'AUTHENTICATION_FAILED' ? 401 : error.statusCode;
100
+ throw retainConnectDiagnostic(new NativeRelationshipError(status === undefined ? 'RELATIONSHIP_REQUEST_UNCONFIRMED' : 'RELATIONSHIP_HTTP_ERROR', status), getConnectDiagnostic(error));
101
+ }
102
+ // Absence after a DELETE is proven by a later list, not by this body.
103
+ if (method === 'DELETE')
104
+ return;
105
+ if (response === noContent)
106
+ return noContent;
107
+ if (typeof response !== 'object' || response === null || Array.isArray(response))
108
+ throw new NativeRelationshipError('INVALID_RELATIONSHIP_RESPONSE');
109
+ return response;
110
+ }
111
+ return {
112
+ apiVersion: version,
113
+ list: async (dmoName, offset) => {
114
+ if (!relationshipDmoName.test(dmoName) || !Number.isSafeInteger(offset) || offset < 0)
115
+ throw new NativeRelationshipError('INVALID_RELATIONSHIP_BINDING');
116
+ const query = new URLSearchParams({ dataspace: dataSpace });
117
+ query.set('limit', String(relationshipPageSize));
118
+ query.set('offset', String(offset));
119
+ const response = await request('GET', `${endpoint}/${dmoName}/relationships?${query}`);
120
+ return response === noContent ? undefined : response;
121
+ },
122
+ create: async (relationship) => {
123
+ const spec = validateNativeRelationshipDocument({
124
+ schemaVersion: 1,
125
+ kind: 'relationship',
126
+ c__dataSpace: 'default',
127
+ identity: { apiName: 'Input' },
128
+ spec: relationship,
129
+ }).spec;
130
+ const response = await request('POST', `${endpoint}/${spec.sourceObjectName}/relationships${scopeQuery}`, { relationships: [spec] });
131
+ return response === noContent ? undefined : response;
132
+ },
133
+ remove: async (relationshipName) => {
134
+ if (!nativeRelationshipName.test(relationshipName))
135
+ throw new NativeRelationshipError('INVALID_RELATIONSHIP_NAME');
136
+ await request('DELETE', `${endpoint}/relationships/${relationshipName}${scopeQuery}`);
137
+ },
138
+ ...(sender?.metadata ? metadataCalls(sender.metadata) : {}),
139
+ };
140
+ }
141
+ /**
142
+ * Metadata API read and update of relationships on the bound Connection.
143
+ * @param {Function} open The bound sender's Metadata API.
144
+ * @returns {Pick<RelationshipClient, 'readDefinitions' | 'update'>} Both calls.
145
+ */
146
+ function metadataCalls(open) {
147
+ return {
148
+ readDefinitions: async (names) => {
149
+ if (names.some((name) => !nativeRelationshipName.test(name)))
150
+ throw new NativeRelationshipError('INVALID_RELATIONSHIP_NAME');
151
+ const api = await open();
152
+ const found = [];
153
+ for (let start = 0; start < names.length; start += relationshipReadBatch) {
154
+ let answer;
155
+ try {
156
+ answer = await api.read(relationshipMetadataType, names.slice(start, start + relationshipReadBatch));
157
+ }
158
+ catch (error) {
159
+ const failure = new NativeRelationshipError('RELATIONSHIP_REQUEST_UNCONFIRMED');
160
+ const text = displayableApiText(error?.message);
161
+ replaceExplanation(failure, `The Metadata API read of ${relationshipMetadataType} failed${text ? `: ${text}` : ''}.`);
162
+ throw failure;
163
+ }
164
+ for (const entry of records(answer))
165
+ if (entry &&
166
+ typeof entry === 'object' &&
167
+ !Array.isArray(entry) &&
168
+ typeof entry.fullName === 'string')
169
+ found.push(entry);
170
+ }
171
+ return found;
172
+ },
173
+ update: async (definition) => {
174
+ const name = definition.fullName;
175
+ if (typeof name !== 'string' || !nativeRelationshipName.test(name))
176
+ throw new NativeRelationshipError('INVALID_RELATIONSHIP_NAME');
177
+ const api = await open();
178
+ let answer;
179
+ try {
180
+ answer = await api.update(relationshipMetadataType, definition);
181
+ }
182
+ catch (error) {
183
+ // Only a client fault is Salesforce refusing the request; a server fault (soapenv:Server,
184
+ // sf:UNKNOWN_EXCEPTION) may follow an applied update, so it stays unconfirmed.
185
+ const fault = error;
186
+ if (typeof fault?.name === 'string' && clientFault.test(fault.name))
187
+ throw updateRefusal(name, [{ code: fault.name, message: fault.message }]);
188
+ throw new NativeRelationshipError('RELATIONSHIP_REQUEST_UNCONFIRMED');
189
+ }
190
+ const [result] = records(answer);
191
+ if (result?.success === true)
192
+ return;
193
+ if (result?.success === false)
194
+ throw updateRefusal(name, records(result.errors).map((entry) => {
195
+ const problem = (entry ?? {});
196
+ return { code: problem.statusCode, message: problem.message };
197
+ }));
198
+ throw new NativeRelationshipError('RELATIONSHIP_REQUEST_UNCONFIRMED');
199
+ },
200
+ };
201
+ }
package/package.json CHANGED
@@ -1,13 +1,32 @@
1
1
  {
2
2
  "name": "sf-plugin-data",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Salesforce CLI bootstrap for portable Data360 configuration",
5
5
  "author": {
6
6
  "name": "Jörn Berkefeld",
7
7
  "email": "joern.berkefeld@gmail.com"
8
8
  },
9
9
  "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/JoernBerkefeld/sf-plugin-data.git"
13
+ },
14
+ "homepage": "https://github.com/JoernBerkefeld/sf-plugin-data#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/JoernBerkefeld/sf-plugin-data/issues"
17
+ },
10
18
  "type": "module",
19
+ "exports": {
20
+ "./api": {
21
+ "types": "./lib/api.d.ts",
22
+ "default": "./lib/api.js"
23
+ },
24
+ "./path-selector": {
25
+ "types": "./lib/artifacts/path-selector.d.ts",
26
+ "default": "./lib/artifacts/path-selector.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
11
30
  "engines": {
12
31
  "node": "^22.22.2 || ^24.15.0"
13
32
  },
@@ -16,7 +35,7 @@
16
35
  "lib",
17
36
  "README.md",
18
37
  "LICENSE",
19
- "docs"
38
+ "docs/*.md"
20
39
  ],
21
40
  "oclif": {
22
41
  "bin": "sf",
@@ -43,20 +62,24 @@
43
62
  "lint:fix": "npm run lint -- --fix",
44
63
  "format": "prettier --write .",
45
64
  "format:check": "prettier --check .",
46
- "test": "npm run build && node --test test/*.test.mjs",
47
- "smoke": "node --test test/cli.test.mjs",
65
+ "test": "npm run build && node scripts/run-tests.mjs",
66
+ "smoke": "node scripts/run-tests.mjs test/cli.test.mjs",
48
67
  "smoke:package": "node scripts/package-smoke.mjs",
49
68
  "prepare": "husky || true",
50
- "prepack": "npm run build"
69
+ "prepack": "npm run build",
70
+ "verify:own-dependencies-latest": "node scripts/verify-own-dependencies-latest.mjs",
71
+ "preversion": "npm run verify:own-dependencies-latest"
51
72
  },
52
73
  "publishConfig": {
53
74
  "access": "public",
54
75
  "registry": "https://registry.npmjs.org/"
55
76
  },
56
77
  "dependencies": {
78
+ "@inquirer/select": "5.2.8",
57
79
  "@oclif/core": "4.13.2",
58
80
  "@salesforce/core": "8.31.3",
59
- "@salesforce/sf-plugins-core": "12.2.0"
81
+ "@salesforce/sf-plugins-core": "12.2.0",
82
+ "salesforce-data360-rules": "0.2.0"
60
83
  },
61
84
  "devDependencies": {
62
85
  "@eslint/js": "9.39.4",
@@ -1,181 +0,0 @@
1
- declare const fieldTypes: readonly ["Number", "Text", "Date", "DateTime", "Url", "Phone", "Email", "Percent", "Boolean", "Currency", "ArrayOfFloats", "ArrayOfTexts"];
2
- export type DmoField = {
3
- name: string;
4
- label: string;
5
- description?: string;
6
- dataType: (typeof fieldTypes)[number];
7
- category?: string;
8
- isPrimaryKey: boolean;
9
- isDynamicLookup: boolean;
10
- };
11
- export type DmoDocument = {
12
- schemaVersion: 1;
13
- kind: 'dmo';
14
- identity: {
15
- dataSpace: string;
16
- apiName: string;
17
- };
18
- spec: {
19
- label: string;
20
- description?: string;
21
- category: 'Profile' | 'Other' | 'Engagement';
22
- eventDateTimeFieldName?: string;
23
- recordModifiedFieldName?: string;
24
- fields: DmoField[];
25
- };
26
- };
27
- /** Payload-free local contract failure; never interpolate untrusted document values. */
28
- export declare class DmoDocumentError extends Error {
29
- constructor();
30
- }
31
- /**
32
- * Classify documented raw keys only; configuration still needs lossless adapter handling.
33
- * @param {'object' | 'field'} level Raw response level.
34
- * @param {string} key Response property name.
35
- * @returns {'configuration' | 'observation' | 'unknown'} Unknown keys must block export.
36
- */
37
- export declare function classifyDmoRawField(level: 'object' | 'field', key: string): 'configuration' | 'observation' | 'unknown';
38
- /**
39
- * Validate the initial custom-schema subset, without coercion or an API-support claim.
40
- * @param {unknown} value Parsed JSON document (not a raw org response).
41
- * @returns {DmoDocument} The validated document; no projection or field removal occurs.
42
- */
43
- export declare function validateDmoDocument(value: unknown): DmoDocument;
44
- export type DmoFieldProjection = {
45
- status: 'incomplete';
46
- blockers: string[];
47
- candidate: DmoDocument;
48
- /** All raw configuration, including generated fields; never a deploy input. */
49
- configuration: Record<string, unknown>;
50
- };
51
- /**
52
- * Project custom fields while retaining every raw configuration value in an incomplete result.
53
- * @param {unknown} value Raw custom DMO detail, not a list or a portable document.
54
- * @returns {DmoFieldProjection} Diagnostic candidate only; relationship acquisition is still required.
55
- */
56
- export declare function projectDmoRawFields(value: unknown): DmoFieldProjection;
57
- export type DmoJoinedFields = {
58
- fields: DmoField[];
59
- qualifierBindings: Array<{
60
- fieldName: string;
61
- qualifierFieldName: string;
62
- }>;
63
- blockers: string[];
64
- expectations: {
65
- connect: Array<Record<string, unknown>>;
66
- metadata: Array<Record<string, unknown>>;
67
- };
68
- };
69
- /**
70
- * Join common field semantics without qualifying object configuration or generated replay.
71
- * @param {unknown} connectFields Complete Connect field collection.
72
- * @param {unknown} metadataFields Complete Metadata field collection.
73
- * @returns {DmoJoinedFields} Authored fields, exact qualifier bindings and unresolved replay semantics.
74
- */
75
- export declare function joinDmoConnectMetadataFields(connectFields: unknown, metadataFields: unknown): DmoJoinedFields;
76
- export type DmoCommonProjection = {
77
- status: 'projected' | 'incomplete';
78
- blockers: string[];
79
- /** Absent when an Engagement event designation is unavailable. */
80
- candidate?: DmoDocument;
81
- createIdentity: {
82
- status: 'verified';
83
- name: string;
84
- sourceApiName: string;
85
- };
86
- qualifierBindings: DmoJoinedFields['qualifierBindings'];
87
- expectations: {
88
- connect: Record<string, unknown>;
89
- metadata: Record<string, unknown>;
90
- relationships: unknown[];
91
- };
92
- };
93
- /**
94
- * Compose exact common object joins and qualify only evidenced replay semantics.
95
- * @param {unknown} connect Complete Connect object detail.
96
- * @param {unknown} metadata Exact matching Metadata CustomObject.
97
- * @param {unknown} relationships Complete separately acquired relationship inventory.
98
- * @returns {DmoCommonProjection} Qualified authored candidate or precise incomplete diagnostics.
99
- */
100
- export declare function projectCommonDmoConnectMetadata(connect: unknown, metadata: unknown, relationships: unknown): DmoCommonProjection;
101
- export type DmoConnectMetadataProjection = {
102
- status: 'projected';
103
- blockers: [];
104
- candidate: DmoDocument;
105
- createIdentity: {
106
- status: 'verified';
107
- name: string;
108
- sourceApiName: string;
109
- };
110
- qualifierBindings: Array<{
111
- fieldName: string;
112
- qualifierFieldName: string;
113
- }>;
114
- /** Complete admitted readback contracts, not writable Metadata API input. */
115
- expectations: {
116
- connect: Record<string, unknown>;
117
- metadata: Record<string, unknown>;
118
- };
119
- };
120
- /**
121
- * Join the proven relationship-free Other shape and invert its documented custom DMO suffix.
122
- * @param {unknown} connect Connect DMO detail.
123
- * @param {unknown} metadata Matching Metadata API CustomObject.
124
- * @param {unknown} relationships Complete separately acquired relationship inventory.
125
- * @returns {DmoConnectMetadataProjection} Offline projection, verified create identity and exact readback expectations.
126
- */
127
- export declare function projectDmoConnectMetadata(connect: unknown, metadata: unknown, relationships: unknown): DmoConnectMetadataProjection;
128
- export type DmoCreateRequest = {
129
- name: string;
130
- label: string;
131
- description?: string;
132
- dataSpaceName: 'default';
133
- category: DmoDocument['spec']['category'];
134
- eventDateTimeFieldName?: string;
135
- recordModifiedFieldName?: string;
136
- fields: Array<{
137
- name: string;
138
- label: string;
139
- dataType: DmoField['dataType'];
140
- description?: string;
141
- category?: string;
142
- isPrimaryKey: boolean;
143
- isDynamicLookup: boolean;
144
- }>;
145
- };
146
- /**
147
- * Map authored custom schema to the documented Connect input, not a raw response.
148
- * @param {unknown} value Parsed authored document, never a runtime projection.
149
- * @param {unknown} targetDataSpace Explicit target binding; this slice supports default only.
150
- * @returns {DmoCreateRequest} Fresh allowlisted request, without a runtime acceptance claim.
151
- */
152
- export declare function buildDmoCreateRequestFromDocument(value: unknown, targetDataSpace: unknown): DmoCreateRequest;
153
- export type OtherDmoCreateRequest = {
154
- name: string;
155
- label: string;
156
- description?: string;
157
- dataSpaceName: 'default';
158
- category: 'Other';
159
- fields: Array<Pick<DmoField, 'name' | 'label' | 'dataType' | 'isPrimaryKey' | 'isDynamicLookup'>>;
160
- };
161
- /**
162
- * Construct only the evidenced default-space Other request, rechecking the complete projection.
163
- * @param {unknown} value Joined projection, including its independent readback expectations.
164
- * @param {unknown} targetDataSpace Explicit target binding; only default has replay evidence.
165
- * @returns {OtherDmoCreateRequest} Fresh authored-only request; no transport or generated-field replay.
166
- */
167
- export declare function buildOtherDmoCreateRequest(value: unknown, targetDataSpace: unknown): OtherDmoCreateRequest;
168
- /**
169
- * Map an authored document independently of internal source-readback expectations.
170
- * @param {unknown} value Parsed authored document, never a runtime projection.
171
- * @param {unknown} targetDataSpace Explicit target binding; only default has replay evidence.
172
- * @returns {OtherDmoCreateRequest} Fresh request for the evidenced two-field Other subset.
173
- */
174
- export declare function buildOtherDmoCreateRequestFromDocument(value: unknown, targetDataSpace: unknown): OtherDmoCreateRequest;
175
- /**
176
- * Serialize validated DMO JSON with sorted object keys, original arrays and a final LF.
177
- * @param {unknown} value Parsed portable document.
178
- * @returns {string} Deterministic JSON text; UTF-8 encoding belongs to the future writer.
179
- */
180
- export declare function serializeDmoDocument(value: unknown): string;
181
- export {};