sf-plugin-data 0.0.0-stage → 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 (256) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +589 -2
  3. package/bin/run.js +4 -0
  4. package/docs/artifact-format.md +527 -0
  5. package/docs/capabilities.md +1208 -0
  6. package/docs/git-workflow.md +160 -0
  7. package/docs/handover.md +10446 -0
  8. package/lib/api.d.ts +7 -0
  9. package/lib/api.js +7 -0
  10. package/lib/artifacts/code-fields.d.ts +49 -0
  11. package/lib/artifacts/code-fields.js +142 -0
  12. package/lib/artifacts/data-graph-document.d.ts +29 -0
  13. package/lib/artifacts/data-graph-document.js +52 -0
  14. package/lib/artifacts/data-space-field.d.ts +65 -0
  15. package/lib/artifacts/data-space-field.js +98 -0
  16. package/lib/artifacts/data-stream-document.d.ts +264 -0
  17. package/lib/artifacts/data-stream-document.js +680 -0
  18. package/lib/artifacts/data-transform-document.d.ts +152 -0
  19. package/lib/artifacts/data-transform-document.js +560 -0
  20. package/lib/artifacts/dependency-selection.d.ts +51 -0
  21. package/lib/artifacts/dependency-selection.js +154 -0
  22. package/lib/artifacts/dlo-document.d.ts +93 -0
  23. package/lib/artifacts/dlo-document.js +253 -0
  24. package/lib/artifacts/enum-case.d.ts +39 -0
  25. package/lib/artifacts/enum-case.js +67 -0
  26. package/lib/artifacts/git-deploy-selection.d.ts +68 -0
  27. package/lib/artifacts/git-deploy-selection.js +474 -0
  28. package/lib/artifacts/identity-resolution-document.d.ts +133 -0
  29. package/lib/artifacts/identity-resolution-document.js +625 -0
  30. package/lib/artifacts/mapping-document.d.ts +1 -0
  31. package/lib/artifacts/mapping-document.js +1 -0
  32. package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
  33. package/lib/artifacts/native-calculated-insight-document.js +321 -0
  34. package/lib/artifacts/native-data-graph-document.d.ts +124 -0
  35. package/lib/artifacts/native-data-graph-document.js +780 -0
  36. package/lib/artifacts/native-dmo-document.d.ts +151 -0
  37. package/lib/artifacts/native-dmo-document.js +313 -0
  38. package/lib/artifacts/native-mapping-document.d.ts +67 -0
  39. package/lib/artifacts/native-mapping-document.js +187 -0
  40. package/lib/artifacts/native-relationship-document.d.ts +76 -0
  41. package/lib/artifacts/native-relationship-document.js +232 -0
  42. package/lib/artifacts/path-selector.d.ts +55 -0
  43. package/lib/artifacts/path-selector.js +167 -0
  44. package/lib/artifacts/read-deploy-input.d.ts +239 -0
  45. package/lib/artifacts/read-deploy-input.js +1359 -0
  46. package/lib/artifacts/segment-document.d.ts +183 -0
  47. package/lib/artifacts/segment-document.js +570 -0
  48. package/lib/artifacts/verbatim-document.d.ts +203 -0
  49. package/lib/artifacts/verbatim-document.js +339 -0
  50. package/lib/artifacts/write-data-graph.d.ts +17 -0
  51. package/lib/artifacts/write-data-graph.js +162 -0
  52. package/lib/artifacts/write-data-stream.d.ts +11 -0
  53. package/lib/artifacts/write-data-stream.js +175 -0
  54. package/lib/artifacts/write-data-transform.d.ts +11 -0
  55. package/lib/artifacts/write-data-transform.js +180 -0
  56. package/lib/artifacts/write-dlo.d.ts +11 -0
  57. package/lib/artifacts/write-dlo.js +158 -0
  58. package/lib/artifacts/write-identity-resolution.d.ts +18 -0
  59. package/lib/artifacts/write-identity-resolution.js +165 -0
  60. package/lib/artifacts/write-mapping-definition.d.ts +17 -0
  61. package/lib/artifacts/write-mapping-definition.js +127 -0
  62. package/lib/artifacts/write-member-export.d.ts +88 -0
  63. package/lib/artifacts/write-member-export.js +199 -0
  64. package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
  65. package/lib/artifacts/write-native-calculated-insight.js +176 -0
  66. package/lib/artifacts/write-native-dmo.d.ts +11 -0
  67. package/lib/artifacts/write-native-dmo.js +158 -0
  68. package/lib/artifacts/write-native-mapping.d.ts +11 -0
  69. package/lib/artifacts/write-native-mapping.js +157 -0
  70. package/lib/artifacts/write-native-relationship.d.ts +11 -0
  71. package/lib/artifacts/write-native-relationship.js +157 -0
  72. package/lib/artifacts/write-segment.d.ts +26 -0
  73. package/lib/artifacts/write-segment.js +212 -0
  74. package/lib/commands/data360/delete.d.ts +280 -0
  75. package/lib/commands/data360/delete.js +2297 -0
  76. package/lib/commands/data360/deploy.d.ts +303 -0
  77. package/lib/commands/data360/deploy.js +2400 -0
  78. package/lib/commands/data360/publish.d.ts +93 -0
  79. package/lib/commands/data360/publish.js +292 -0
  80. package/lib/commands/data360/retrieve.d.ts +322 -0
  81. package/lib/commands/data360/retrieve.js +1963 -0
  82. package/lib/commands/data360/segment/members/export.d.ts +101 -0
  83. package/lib/commands/data360/segment/members/export.js +318 -0
  84. package/lib/errors/codes/calculated-insight.d.ts +2 -0
  85. package/lib/errors/codes/calculated-insight.js +25 -0
  86. package/lib/errors/codes/data-graph.d.ts +2 -0
  87. package/lib/errors/codes/data-graph.js +22 -0
  88. package/lib/errors/codes/data-stream.d.ts +2 -0
  89. package/lib/errors/codes/data-stream.js +70 -0
  90. package/lib/errors/codes/data-transform.d.ts +2 -0
  91. package/lib/errors/codes/data-transform.js +35 -0
  92. package/lib/errors/codes/dependency.d.ts +2 -0
  93. package/lib/errors/codes/dependency.js +11 -0
  94. package/lib/errors/codes/dlo.d.ts +2 -0
  95. package/lib/errors/codes/dlo.js +31 -0
  96. package/lib/errors/codes/dmo.d.ts +2 -0
  97. package/lib/errors/codes/dmo.js +28 -0
  98. package/lib/errors/codes/general.d.ts +2 -0
  99. package/lib/errors/codes/general.js +57 -0
  100. package/lib/errors/codes/identity-resolution.d.ts +2 -0
  101. package/lib/errors/codes/identity-resolution.js +24 -0
  102. package/lib/errors/codes/mapping.d.ts +2 -0
  103. package/lib/errors/codes/mapping.js +42 -0
  104. package/lib/errors/codes/relationship.d.ts +2 -0
  105. package/lib/errors/codes/relationship.js +21 -0
  106. package/lib/errors/codes/segment.d.ts +2 -0
  107. package/lib/errors/codes/segment.js +49 -0
  108. package/lib/errors/registry.d.ts +60 -0
  109. package/lib/errors/registry.js +123 -0
  110. package/lib/plugin.d.ts +5 -0
  111. package/lib/plugin.js +5 -0
  112. package/lib/services/acquire-retrieve-selection.d.ts +43 -0
  113. package/lib/services/acquire-retrieve-selection.js +145 -0
  114. package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
  115. package/lib/services/bind-identity-resolution-dependencies.js +238 -0
  116. package/lib/services/bind-segment-dependencies.d.ts +49 -0
  117. package/lib/services/bind-segment-dependencies.js +115 -0
  118. package/lib/services/bounded-reads.d.ts +17 -0
  119. package/lib/services/bounded-reads.js +42 -0
  120. package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
  121. package/lib/services/calculated-insight-sql-checks.js +193 -0
  122. package/lib/services/command-dlo.d.ts +48 -0
  123. package/lib/services/command-dlo.js +103 -0
  124. package/lib/services/command-native-data-graph.d.ts +54 -0
  125. package/lib/services/command-native-data-graph.js +485 -0
  126. package/lib/services/command-native-data-stream.d.ts +104 -0
  127. package/lib/services/command-native-data-stream.js +257 -0
  128. package/lib/services/command-native-dmo.d.ts +124 -0
  129. package/lib/services/command-native-dmo.js +338 -0
  130. package/lib/services/command-native-mapping.d.ts +65 -0
  131. package/lib/services/command-native-mapping.js +129 -0
  132. package/lib/services/command-native-relationship.d.ts +46 -0
  133. package/lib/services/command-native-relationship.js +103 -0
  134. package/lib/services/cross-dataspace-deploy.d.ts +111 -0
  135. package/lib/services/cross-dataspace-deploy.js +493 -0
  136. package/lib/services/cross-dataspace-rename.d.ts +74 -0
  137. package/lib/services/cross-dataspace-rename.js +1314 -0
  138. package/lib/services/cross-dataspace-sql.d.ts +109 -0
  139. package/lib/services/cross-dataspace-sql.js +1301 -0
  140. package/lib/services/cross-space-context.d.ts +23 -0
  141. package/lib/services/cross-space-context.js +36 -0
  142. package/lib/services/crud-plan.d.ts +137 -0
  143. package/lib/services/crud-plan.js +408 -0
  144. package/lib/services/data-space-check.d.ts +89 -0
  145. package/lib/services/data-space-check.js +162 -0
  146. package/lib/services/data-space-prefix.d.ts +77 -0
  147. package/lib/services/data-space-prefix.js +127 -0
  148. package/lib/services/data-transform-space.d.ts +31 -0
  149. package/lib/services/data-transform-space.js +79 -0
  150. package/lib/services/delete-calculated-insight.d.ts +44 -0
  151. package/lib/services/delete-calculated-insight.js +101 -0
  152. package/lib/services/delete-data-transform.d.ts +52 -0
  153. package/lib/services/delete-data-transform.js +222 -0
  154. package/lib/services/delete-dmo-field.d.ts +211 -0
  155. package/lib/services/delete-dmo-field.js +472 -0
  156. package/lib/services/delete-identity-resolution.d.ts +43 -0
  157. package/lib/services/delete-identity-resolution.js +295 -0
  158. package/lib/services/delete-segment.d.ts +42 -0
  159. package/lib/services/delete-segment.js +248 -0
  160. package/lib/services/deploy-result.d.ts +54 -0
  161. package/lib/services/deploy-result.js +60 -0
  162. package/lib/services/escaped-copy.d.ts +23 -0
  163. package/lib/services/escaped-copy.js +88 -0
  164. package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
  165. package/lib/services/execute-calculated-insight-deploy.js +96 -0
  166. package/lib/services/execute-data-transform-deploy.d.ts +56 -0
  167. package/lib/services/execute-data-transform-deploy.js +168 -0
  168. package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
  169. package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
  170. package/lib/services/execute-segment-deploy.d.ts +45 -0
  171. package/lib/services/execute-segment-deploy.js +393 -0
  172. package/lib/services/local-file-removal.d.ts +36 -0
  173. package/lib/services/local-file-removal.js +103 -0
  174. package/lib/services/native-calculated-insight.d.ts +87 -0
  175. package/lib/services/native-calculated-insight.js +164 -0
  176. package/lib/services/native-crm-data-stream.d.ts +91 -0
  177. package/lib/services/native-crm-data-stream.js +272 -0
  178. package/lib/services/native-data-graph-context.d.ts +12 -0
  179. package/lib/services/native-data-graph-context.js +139 -0
  180. package/lib/services/native-data-graph-crd.d.ts +261 -0
  181. package/lib/services/native-data-graph-crd.js +866 -0
  182. package/lib/services/native-data-stream.d.ts +329 -0
  183. package/lib/services/native-data-stream.js +1830 -0
  184. package/lib/services/native-dlo.d.ts +163 -0
  185. package/lib/services/native-dlo.js +402 -0
  186. package/lib/services/native-dmo.d.ts +191 -0
  187. package/lib/services/native-dmo.js +614 -0
  188. package/lib/services/native-mapping.d.ts +255 -0
  189. package/lib/services/native-mapping.js +1226 -0
  190. package/lib/services/native-relationship.d.ts +132 -0
  191. package/lib/services/native-relationship.js +512 -0
  192. package/lib/services/operation-diagnostic.d.ts +83 -0
  193. package/lib/services/operation-diagnostic.js +272 -0
  194. package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
  195. package/lib/services/preflight-calculated-insight-deploy.js +95 -0
  196. package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
  197. package/lib/services/preflight-data-transform-deploy.js +104 -0
  198. package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
  199. package/lib/services/preflight-identity-resolution-deploy.js +281 -0
  200. package/lib/services/preflight-segment-deploy.d.ts +31 -0
  201. package/lib/services/preflight-segment-deploy.js +109 -0
  202. package/lib/services/publish-calculated-insight.d.ts +40 -0
  203. package/lib/services/publish-calculated-insight.js +95 -0
  204. package/lib/services/publish-segment.d.ts +65 -0
  205. package/lib/services/publish-segment.js +194 -0
  206. package/lib/services/readback-pace.d.ts +16 -0
  207. package/lib/services/readback-pace.js +23 -0
  208. package/lib/services/retrieve-data-transform.d.ts +26 -0
  209. package/lib/services/retrieve-data-transform.js +65 -0
  210. package/lib/services/retrieve-identity-resolution.d.ts +40 -0
  211. package/lib/services/retrieve-identity-resolution.js +87 -0
  212. package/lib/services/retrieve-inventory.d.ts +32 -0
  213. package/lib/services/retrieve-inventory.js +151 -0
  214. package/lib/services/retrieve-segment.d.ts +120 -0
  215. package/lib/services/retrieve-segment.js +502 -0
  216. package/lib/services/segment-lookup.d.ts +46 -0
  217. package/lib/services/segment-lookup.js +108 -0
  218. package/lib/services/segment-members.d.ts +144 -0
  219. package/lib/services/segment-members.js +402 -0
  220. package/lib/services/select-native-retrieve.d.ts +60 -0
  221. package/lib/services/select-native-retrieve.js +226 -0
  222. package/lib/services/settle-calculated-insight.d.ts +22 -0
  223. package/lib/services/settle-calculated-insight.js +53 -0
  224. package/lib/services/sql-tokens.d.ts +58 -0
  225. package/lib/services/sql-tokens.js +147 -0
  226. package/lib/transport/api-version.d.ts +36 -0
  227. package/lib/transport/api-version.js +89 -0
  228. package/lib/transport/bound-ssot.d.ts +27 -0
  229. package/lib/transport/bound-ssot.js +116 -0
  230. package/lib/transport/calculated-insight-rest.d.ts +28 -0
  231. package/lib/transport/calculated-insight-rest.js +62 -0
  232. package/lib/transport/connect-client.d.ts +129 -0
  233. package/lib/transport/connect-client.js +446 -0
  234. package/lib/transport/connect-diagnostic.d.ts +89 -0
  235. package/lib/transport/connect-diagnostic.js +331 -0
  236. package/lib/transport/data-graph-rest.d.ts +27 -0
  237. package/lib/transport/data-graph-rest.js +76 -0
  238. package/lib/transport/data-stream-rest.d.ts +62 -0
  239. package/lib/transport/data-stream-rest.js +348 -0
  240. package/lib/transport/data-transform-rest.d.ts +25 -0
  241. package/lib/transport/data-transform-rest.js +100 -0
  242. package/lib/transport/dlo-native-rest.d.ts +22 -0
  243. package/lib/transport/dlo-native-rest.js +89 -0
  244. package/lib/transport/dlo-rest.d.ts +23 -0
  245. package/lib/transport/dlo-rest.js +135 -0
  246. package/lib/transport/dmo-native-rest.d.ts +18 -0
  247. package/lib/transport/dmo-native-rest.js +55 -0
  248. package/lib/transport/dmo-rest.d.ts +30 -0
  249. package/lib/transport/dmo-rest.js +163 -0
  250. package/lib/transport/mapping-rest.d.ts +63 -0
  251. package/lib/transport/mapping-rest.js +341 -0
  252. package/lib/transport/project-metadata.d.ts +36 -0
  253. package/lib/transport/project-metadata.js +118 -0
  254. package/lib/transport/relationship-rest.d.ts +43 -0
  255. package/lib/transport/relationship-rest.js +201 -0
  256. package/package.json +96 -4
@@ -0,0 +1,60 @@
1
+ /** Next action when Salesforce refused the item's first write: nothing was applied for it. */
2
+ export const rejectedNextAction = 'Salesforce rejected the write and nothing was written for this item; correct the input before another attempt.';
3
+ /**
4
+ * Count the writes of one item, so a failure can say whether anything was applied. Only the
5
+ * item's first write, answered by Salesforce with an HTTP 4xx status or a Metadata API refusal
6
+ * (`*_UPDATE_REJECTED`), is known to have changed nothing; every other failure after the first
7
+ * dispatch stays unknown.
8
+ */
9
+ export class WriteLedger {
10
+ started = 0;
11
+ completed = 0;
12
+ refusal;
13
+ /**
14
+ * Whether any write was sent.
15
+ * @returns {boolean} True after the first dispatch.
16
+ */
17
+ get dispatched() {
18
+ return this.started > 0;
19
+ }
20
+ /**
21
+ * Run one write and record how it ended.
22
+ * @template T
23
+ * @param {Function} write The single write.
24
+ * @returns {Promise<T>} Its result.
25
+ */
26
+ async run(write) {
27
+ this.started++;
28
+ try {
29
+ const result = await write();
30
+ this.completed++;
31
+ return result;
32
+ }
33
+ catch (error) {
34
+ const status = error?.status;
35
+ const code = error?.code;
36
+ if (this.started === 1 &&
37
+ typeof code === 'string' &&
38
+ ((code.endsWith('_HTTP_ERROR') &&
39
+ typeof status === 'number' &&
40
+ status >= 400 &&
41
+ status < 500) ||
42
+ // A Metadata API update Salesforce answered with success false or a SOAP fault.
43
+ code.endsWith('_UPDATE_REJECTED')))
44
+ this.refusal = error;
45
+ throw error;
46
+ }
47
+ }
48
+ /**
49
+ * Classify a failure of the item.
50
+ * @param {unknown} error The error that ended the item.
51
+ * @returns {object} Outcome and mutation for the result item.
52
+ */
53
+ failure(error) {
54
+ if (this.refusal !== undefined && this.refusal === error)
55
+ return { outcome: 'failed', mutation: 'rejected' };
56
+ return this.dispatched
57
+ ? { outcome: 'failed', mutation: 'unknown' }
58
+ : { outcome: 'blocked', mutation: 'not-attempted' };
59
+ }
60
+ }
@@ -0,0 +1,23 @@
1
+ /** The code of {@link refuseEscapedCopy}; documented in docs/errors/general. */
2
+ export declare const escapedCopyCode = "HTML_ESCAPED_FILE";
3
+ /**
4
+ * The path of the first string of a file that differs from the org's value only by HTML
5
+ * escaping: decoding it once gives exactly the org's value. Without the plain-text request
6
+ * header Connect REST returns every string so, and Salesforce stores what a write sends as is,
7
+ * so deploying such a file would store the entities literally. A string that equals the org's
8
+ * (also one holding an entity Salesforce stores) or decodes to anything else is never matched.
9
+ * @param {unknown} file Value from the file.
10
+ * @param {unknown} org The org's value in the same file form.
11
+ * @param {string} [at] JSON path of `file`.
12
+ * @param {number} [depth] Nesting depth.
13
+ * @returns {string | undefined} JSON path, or none.
14
+ */
15
+ export declare function escapedCopyPath(file: unknown, org: unknown, at?: string, depth?: number): string | undefined;
16
+ /**
17
+ * Refuse a file that holds HTML-escaped copies of the org's text before any write: Salesforce
18
+ * would store the entities literally.
19
+ * @param {unknown} file Document from the file.
20
+ * @param {unknown} org The org's document in the same form.
21
+ * @param {(code: string) => Error} refusal The item type's error for a code.
22
+ */
23
+ export declare function refuseEscapedCopy(file: unknown, org: unknown, refusal: (code: string) => Error): void;
@@ -0,0 +1,88 @@
1
+ import { unescapeSalesforceHtml } from '../artifacts/native-calculated-insight-document.js';
2
+ import { explainInput, printableKey } from './operation-diagnostic.js';
3
+ /** The code of {@link refuseEscapedCopy}; documented in docs/errors/general. */
4
+ export const escapedCopyCode = 'HTML_ESCAPED_FILE';
5
+ const isRecord = (value) => Boolean(value) && typeof value === 'object' && !Array.isArray(value);
6
+ /** Keys that name an array entry, in order of preference. */
7
+ const entryKeys = [
8
+ 'name',
9
+ 'apiName',
10
+ 'developerName',
11
+ 'targetFieldName',
12
+ 'targetFieldDeveloperName',
13
+ ];
14
+ /**
15
+ * The org entry an array entry of the file is compared with: the one of the same name (the first
16
+ * naming key the entry has) when there is one, otherwise the one at the same position.
17
+ * @param {unknown[]} org Org array.
18
+ * @param {unknown} entry File entry.
19
+ * @param {number} index Position of the entry in the file.
20
+ * @returns {unknown} Org entry, or undefined.
21
+ */
22
+ function counterpart(org, entry, index) {
23
+ const key = isRecord(entry)
24
+ ? entryKeys.find((name) => typeof entry[name] === 'string')
25
+ : undefined;
26
+ if (key !== undefined) {
27
+ const named = org.find((other) => isRecord(other) && other[key] === entry[key]);
28
+ if (named !== undefined)
29
+ return named;
30
+ }
31
+ return org[index];
32
+ }
33
+ /**
34
+ * The path of the first string of a file that differs from the org's value only by HTML
35
+ * escaping: decoding it once gives exactly the org's value. Without the plain-text request
36
+ * header Connect REST returns every string so, and Salesforce stores what a write sends as is,
37
+ * so deploying such a file would store the entities literally. A string that equals the org's
38
+ * (also one holding an entity Salesforce stores) or decodes to anything else is never matched.
39
+ * @param {unknown} file Value from the file.
40
+ * @param {unknown} org The org's value in the same file form.
41
+ * @param {string} [at] JSON path of `file`.
42
+ * @param {number} [depth] Nesting depth.
43
+ * @returns {string | undefined} JSON path, or none.
44
+ */
45
+ export function escapedCopyPath(file, org, at = '', depth = 0) {
46
+ if (typeof file === 'string')
47
+ return typeof org === 'string' &&
48
+ file !== org &&
49
+ file.includes('&') &&
50
+ unescapeSalesforceHtml(file) === org
51
+ ? at || '(document)'
52
+ : undefined;
53
+ if (depth > 40)
54
+ return undefined;
55
+ if (Array.isArray(file)) {
56
+ if (!Array.isArray(org))
57
+ return undefined;
58
+ for (const [index, entry] of file.entries()) {
59
+ const found = escapedCopyPath(entry, counterpart(org, entry, index), `${at}[${index}]`, depth + 1);
60
+ if (found !== undefined)
61
+ return found;
62
+ }
63
+ return undefined;
64
+ }
65
+ if (!isRecord(file) || !isRecord(org))
66
+ return undefined;
67
+ for (const [key, entry] of Object.entries(file)) {
68
+ if (!Object.hasOwn(org, key))
69
+ continue;
70
+ const path = at ? `${at}.${printableKey(key)}` : printableKey(key);
71
+ const found = escapedCopyPath(entry, org[key], path, depth + 1);
72
+ if (found !== undefined)
73
+ return found;
74
+ }
75
+ return undefined;
76
+ }
77
+ /**
78
+ * Refuse a file that holds HTML-escaped copies of the org's text before any write: Salesforce
79
+ * would store the entities literally.
80
+ * @param {unknown} file Document from the file.
81
+ * @param {unknown} org The org's document in the same form.
82
+ * @param {(code: string) => Error} refusal The item type's error for a code.
83
+ */
84
+ export function refuseEscapedCopy(file, org, refusal) {
85
+ const at = escapedCopyPath(file, org);
86
+ if (at !== undefined)
87
+ throw explainInput(refusal(escapedCopyCode), `The file holds HTML-escaped text at ${at} (an entity such as &amp; or &#39; where the org holds the character itself) that Salesforce would store literally, since it never decodes entities it is sent. Retrieve it again, or write the characters themselves; nothing was written.`);
88
+ }
@@ -0,0 +1,42 @@
1
+ import type { ApiVersionSelection } from '../transport/api-version.js';
2
+ import type { CalculatedInsightClient } from '../transport/calculated-insight-rest.js';
3
+ import type { CalculatedInsightDeployIntent } from './preflight-calculated-insight-deploy.js';
4
+ import type { CalculatedInsightTiming } from './settle-calculated-insight.js';
5
+ import type { CalculatedInsightConnection } from './native-calculated-insight.js';
6
+ export type CalculatedInsightExecutionOptions = CalculatedInsightDeployIntent & CalculatedInsightTiming & {
7
+ nativeClient?: Pick<CalculatedInsightClient, 'create' | 'update'>;
8
+ verifyInput: () => Promise<void>;
9
+ };
10
+ export type CalculatedInsightExecution = {
11
+ family: 'calculated-insight';
12
+ route: {
13
+ apiVersion: '68.0';
14
+ method: 'POST' | 'PATCH';
15
+ resource: 'calculated-insights';
16
+ };
17
+ outcome: 'unchanged' | 'blocked' | 'created' | 'updated' | 'failed';
18
+ mutation: 'not-attempted' | 'confirmed-created' | 'confirmed-updated' | 'unknown' | 'rejected';
19
+ diagnostics: Array<{
20
+ code: string;
21
+ message: string;
22
+ }>;
23
+ };
24
+ /**
25
+ * Whether a write failed with Salesforce's synchronous HTTP 4xx answer (nothing applied).
26
+ * @param {unknown} error Write failure.
27
+ * @returns {boolean} True for a 4xx refusal.
28
+ */
29
+ export declare function rejectedWrite(error: unknown): boolean;
30
+ /**
31
+ * Deploy one calculated insight: one GET decides create (POST), update (PATCH) or unchanged;
32
+ * the document is sent as authored (input key names and enum forms translated) and
33
+ * Salesforce decides. A 4xx answer is `rejected`; after any other write outcome the insight
34
+ * is read until it holds the document. One attempt, no replay or rollback.
35
+ * @param {unknown} value Document from the files (JSON with its SQL).
36
+ * @param {CalculatedInsightConnection} connection API 68 connection.
37
+ * @param {ApiVersionSelection} selection Route selection (68.0).
38
+ * @param {string} dataSpace Selected data space.
39
+ * @param {CalculatedInsightExecutionOptions} options --draft, input verifier and test seams.
40
+ * @returns {Promise<CalculatedInsightExecution>} Payload-free outcome.
41
+ */
42
+ export declare function executeCalculatedInsightDeploy(value: unknown, connection: CalculatedInsightConnection, selection: ApiVersionSelection, dataSpace: string, options: CalculatedInsightExecutionOptions): Promise<CalculatedInsightExecution>;
@@ -0,0 +1,96 @@
1
+ import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
2
+ import { explanationOf, operationDiagnostic } from './operation-diagnostic.js';
3
+ import { rejectedNextAction } from './deploy-result.js';
4
+ import { CalculatedInsightError, validateNativeCalculatedInsight, } from '../artifacts/native-calculated-insight-document.js';
5
+ import { createCalculatedInsightClient } from '../transport/calculated-insight-rest.js';
6
+ import { ConnectError } from '../transport/connect-client.js';
7
+ import { calculatedInsightDeployContext, planNativeCalculatedInsightDeploy, } from './preflight-calculated-insight-deploy.js';
8
+ import { settleCalculatedInsight } from './settle-calculated-insight.js';
9
+ /**
10
+ * Whether a write failed with Salesforce's synchronous HTTP 4xx answer (nothing applied).
11
+ * @param {unknown} error Write failure.
12
+ * @returns {boolean} True for a 4xx refusal.
13
+ */
14
+ export function rejectedWrite(error) {
15
+ const status = getConnectDiagnostic(error)?.statusCode ??
16
+ (error instanceof ConnectError ? error.statusCode : undefined);
17
+ return typeof status === 'number' && status >= 400 && status < 500;
18
+ }
19
+ /**
20
+ * Deploy one calculated insight: one GET decides create (POST), update (PATCH) or unchanged;
21
+ * the document is sent as authored (input key names and enum forms translated) and
22
+ * Salesforce decides. A 4xx answer is `rejected`; after any other write outcome the insight
23
+ * is read until it holds the document. One attempt, no replay or rollback.
24
+ * @param {unknown} value Document from the files (JSON with its SQL).
25
+ * @param {CalculatedInsightConnection} connection API 68 connection.
26
+ * @param {ApiVersionSelection} selection Route selection (68.0).
27
+ * @param {string} dataSpace Selected data space.
28
+ * @param {CalculatedInsightExecutionOptions} options --draft, input verifier and test seams.
29
+ * @returns {Promise<CalculatedInsightExecution>} Payload-free outcome.
30
+ */
31
+ export async function executeCalculatedInsightDeploy(value, connection, selection, dataSpace, options) {
32
+ let attempted = false;
33
+ let method = 'PATCH';
34
+ const result = (outcome, mutation, code, error) => retainConnectDiagnostic({
35
+ family: 'calculated-insight',
36
+ route: { apiVersion: '68.0', method, resource: 'calculated-insights' },
37
+ outcome,
38
+ mutation,
39
+ diagnostics: code
40
+ ? [
41
+ {
42
+ code,
43
+ message: (() => {
44
+ const next = mutation === 'rejected'
45
+ ? rejectedNextAction
46
+ : mutation === 'unknown'
47
+ ? 'CI mutation may have occurred; no replay or rollback was performed.'
48
+ : 'CI deployment was not attempted.';
49
+ // Salesforce's answer or the plugin's own explanation (an escaped file).
50
+ return getConnectDiagnostic(error) || explanationOf(error) !== undefined
51
+ ? operationDiagnostic(error, next)
52
+ : next;
53
+ })(),
54
+ },
55
+ ]
56
+ : [],
57
+ }, getConnectDiagnostic(error));
58
+ try {
59
+ const desired = validateNativeCalculatedInsight(value);
60
+ const context = calculatedInsightDeployContext(connection, selection, dataSpace, desired, options.context);
61
+ if (typeof options.verifyInput !== 'function')
62
+ throw new Error('Guards absent');
63
+ await options.verifyInput();
64
+ const plan = await planNativeCalculatedInsightDeploy(desired, context, options.draft === true);
65
+ await options.verifyInput();
66
+ if (plan.action === 'unchanged')
67
+ return result('unchanged', 'not-attempted');
68
+ method = plan.action === 'create' ? 'POST' : 'PATCH';
69
+ const client = options.nativeClient ?? createCalculatedInsightClient(connection, '68.0', dataSpace);
70
+ context.check();
71
+ attempted = true;
72
+ try {
73
+ await (plan.action === 'create'
74
+ ? client.create(structuredClone(desired), options.draft ? { draft: true } : undefined)
75
+ : client.update(structuredClone(desired), {
76
+ // A DRAFT insight stays a draft: deploy never publishes.
77
+ ...(plan.draft ? { draft: true } : {}),
78
+ ...(plan.acquired.state === 'present' ? { observed: plan.acquired.document } : {}),
79
+ }));
80
+ }
81
+ catch (error) {
82
+ if (rejectedWrite(error))
83
+ return result('failed', 'rejected', 'REQUEST_FAILED', error);
84
+ throw error;
85
+ }
86
+ await settleCalculatedInsight(context, desired, 'present', options);
87
+ return plan.action === 'create'
88
+ ? result('created', 'confirmed-created')
89
+ : result('updated', 'confirmed-updated');
90
+ }
91
+ catch (error) {
92
+ return attempted
93
+ ? result('failed', 'unknown', error instanceof CalculatedInsightError ? error.code : 'CI_MUTATION_UNCONFIRMED', error)
94
+ : result('blocked', 'not-attempted', error instanceof CalculatedInsightError ? error.code : 'CI_ADMISSION_FAILED', error);
95
+ }
96
+ }
@@ -0,0 +1,56 @@
1
+ import { DataTransformError } from '../artifacts/data-transform-document.js';
2
+ import type { DataTransformObservation } from '../artifacts/data-transform-document.js';
3
+ import type { DataTransformClient } from '../transport/data-transform-rest.js';
4
+ import type { DataTransformDeploySelection } from './preflight-data-transform-deploy.js';
5
+ /**
6
+ * The definition was written, but the schedule of the file was not: Salesforce refused the
7
+ * schedule PUT (`TRANSFORM_SCHEDULE_REJECTED`, its answer in `cause`), or the transform was still
8
+ * processing at the end of the bound and the PUT was not sent (`TRANSFORM_SCHEDULE_NOT_SENT`).
9
+ */
10
+ export declare class DataTransformScheduleError extends DataTransformError {
11
+ readonly definition: 'create' | 'update';
12
+ readonly cause?: unknown | undefined;
13
+ /**
14
+ * @param {'TRANSFORM_SCHEDULE_REJECTED' | 'TRANSFORM_SCHEDULE_NOT_SENT'} code Outcome code.
15
+ * @param {'create' | 'update'} definition The definition write that was confirmed.
16
+ * @param {unknown} [cause] Salesforce's refusal of the schedule PUT.
17
+ */
18
+ constructor(code: 'TRANSFORM_SCHEDULE_REJECTED' | 'TRANSFORM_SCHEDULE_NOT_SENT', definition: 'create' | 'update', cause?: unknown | undefined);
19
+ }
20
+ /**
21
+ * Whether a transform deploy failed because Salesforce refused its first write (HTTP 4xx), so
22
+ * nothing was written for the transform.
23
+ * @param {unknown} error Error thrown by {@link executeDataTransformDeploy}.
24
+ * @returns {boolean} True for that refusal.
25
+ */
26
+ export declare function rejectedTransformWrite(error: unknown): boolean;
27
+ /**
28
+ * Freshly preflight, then send what changed exactly once: the definition (create POST or update
29
+ * PUT), then the schedule PUT of the file. Afterwards the transform and its schedule are read back
30
+ * for their identity; Salesforce stores a normalized form, so the definition is not compared with
31
+ * the file (retrieve gives the stored form), and a written schedule must read back with the
32
+ * frequency of the file. A 4xx answer to the first write is Salesforce's refusal (see
33
+ * {@link rejectedTransformWrite}); any other error after dispatch is not absence or permission to
34
+ * replay; processing is not run success.
35
+ * @param {unknown} value Portable input artifact.
36
+ * @param {DataTransformDeploySelection} selection Create, or update of the target resolved by name.
37
+ * @param {DataTransformClient} client Native transform adapter.
38
+ * @param {object} [options] Input verification and mutation boundary notification.
39
+ * @param {() => Promise<void>} [options.verifyInput] Reverify captured local bytes.
40
+ * @param {() => void} [options.onDispatch] Notify immediately before invoking the first write.
41
+ * @param {() => number} [options.now] Clock of the settle poll.
42
+ * @param {(milliseconds: number) => Promise<void>} [options.delay] Sleep of the settle poll.
43
+ * @returns {Promise<{operation: 'create' | 'update' | 'unchanged', observation: DataTransformObservation, scheduleWritten?: true, serverProcessing?: true}>} The stored transform as read back, never computation completion.
44
+ */
45
+ export declare function executeDataTransformDeploy(value: unknown, selection: DataTransformDeploySelection, client: DataTransformClient, options?: {
46
+ verifyInput?: () => Promise<void>;
47
+ onDispatch?: () => void;
48
+ /** Clock and sleep for the settle poll before a schedule PUT; tests inject fakes. */
49
+ now?: () => number;
50
+ delay?: (milliseconds: number) => Promise<void>;
51
+ }): Promise<{
52
+ operation: 'create' | 'update' | 'unchanged';
53
+ observation: DataTransformObservation;
54
+ scheduleWritten?: true;
55
+ serverProcessing?: true;
56
+ }>;
@@ -0,0 +1,168 @@
1
+ import { DataTransformError, dataTransformId, observeDataTransform, serializeDataTransformDocument, unscheduled, } from '../artifacts/data-transform-document.js';
2
+ import { setTimeout as wait } from 'node:timers/promises';
3
+ import { rejectedWrite } from './execute-calculated-insight-deploy.js';
4
+ import { preflightDataTransformDeploy } from './preflight-data-transform-deploy.js';
5
+ /**
6
+ * The frequency of a schedule in lower case, for the readback check.
7
+ * @param {Record<string, unknown> | undefined} schedule Projected or authored schedule.
8
+ * @returns {string | undefined} Lower-case frequency, if any.
9
+ */
10
+ function frequency(schedule) {
11
+ return typeof schedule?.frequency === 'string' ? schedule.frequency.toLowerCase() : undefined;
12
+ }
13
+ /**
14
+ * A new or updated transform answers `PROCESSING` (live it stayed so for about 2.5 minutes after a
15
+ * create), and Salesforce refuses a schedule PUT on a transform that is not active (400
16
+ * `INVALID_STATUS`). Before the schedule PUT the transform is read until it is no longer
17
+ * processing, within this bound.
18
+ */
19
+ const SETTLE_BUDGET_MS = 300_000;
20
+ const SETTLE_INTERVAL_MS = 5000;
21
+ /**
22
+ * The definition was written, but the schedule of the file was not: Salesforce refused the
23
+ * schedule PUT (`TRANSFORM_SCHEDULE_REJECTED`, its answer in `cause`), or the transform was still
24
+ * processing at the end of the bound and the PUT was not sent (`TRANSFORM_SCHEDULE_NOT_SENT`).
25
+ */
26
+ export class DataTransformScheduleError extends DataTransformError {
27
+ definition;
28
+ cause;
29
+ /**
30
+ * @param {'TRANSFORM_SCHEDULE_REJECTED' | 'TRANSFORM_SCHEDULE_NOT_SENT'} code Outcome code.
31
+ * @param {'create' | 'update'} definition The definition write that was confirmed.
32
+ * @param {unknown} [cause] Salesforce's refusal of the schedule PUT.
33
+ */
34
+ constructor(code, definition, cause) {
35
+ super(code);
36
+ this.definition = definition;
37
+ this.cause = cause;
38
+ }
39
+ }
40
+ /** Errors of an item's first write that Salesforce answered with a 4xx: nothing was written. */
41
+ const refusals = new WeakSet();
42
+ /**
43
+ * Whether a transform deploy failed because Salesforce refused its first write (HTTP 4xx), so
44
+ * nothing was written for the transform.
45
+ * @param {unknown} error Error thrown by {@link executeDataTransformDeploy}.
46
+ * @returns {boolean} True for that refusal.
47
+ */
48
+ export function rejectedTransformWrite(error) {
49
+ return typeof error === 'object' && error !== null && refusals.has(error);
50
+ }
51
+ /**
52
+ * Freshly preflight, then send what changed exactly once: the definition (create POST or update
53
+ * PUT), then the schedule PUT of the file. Afterwards the transform and its schedule are read back
54
+ * for their identity; Salesforce stores a normalized form, so the definition is not compared with
55
+ * the file (retrieve gives the stored form), and a written schedule must read back with the
56
+ * frequency of the file. A 4xx answer to the first write is Salesforce's refusal (see
57
+ * {@link rejectedTransformWrite}); any other error after dispatch is not absence or permission to
58
+ * replay; processing is not run success.
59
+ * @param {unknown} value Portable input artifact.
60
+ * @param {DataTransformDeploySelection} selection Create, or update of the target resolved by name.
61
+ * @param {DataTransformClient} client Native transform adapter.
62
+ * @param {object} [options] Input verification and mutation boundary notification.
63
+ * @param {() => Promise<void>} [options.verifyInput] Reverify captured local bytes.
64
+ * @param {() => void} [options.onDispatch] Notify immediately before invoking the first write.
65
+ * @param {() => number} [options.now] Clock of the settle poll.
66
+ * @param {(milliseconds: number) => Promise<void>} [options.delay] Sleep of the settle poll.
67
+ * @returns {Promise<{operation: 'create' | 'update' | 'unchanged', observation: DataTransformObservation, scheduleWritten?: true, serverProcessing?: true}>} The stored transform as read back, never computation completion.
68
+ */
69
+ export async function executeDataTransformDeploy(value, selection, client, options = {}) {
70
+ const plan = await preflightDataTransformDeploy(value, selection, client);
71
+ if (plan.operation === 'unchanged') {
72
+ await options.verifyInput?.();
73
+ return { operation: 'unchanged', observation: plan.current };
74
+ }
75
+ await options.verifyInput?.();
76
+ // Last remote check before the writes; this is not an atomic server-side conditional write.
77
+ // The schedule compares as projected, so a moved next run time is no drift.
78
+ if (plan.current) {
79
+ const fresh = observeDataTransform(await client.get(plan.targetId), await client.schedule(plan.targetId));
80
+ if (fresh.targetId !== plan.targetId ||
81
+ serializeDataTransformDocument(fresh.document) !==
82
+ serializeDataTransformDocument(plan.current.document))
83
+ throw new DataTransformError('TRANSFORM_TARGET_DRIFT');
84
+ }
85
+ options.onDispatch?.();
86
+ let first = true;
87
+ const write = async (send) => {
88
+ const isFirst = first;
89
+ first = false;
90
+ try {
91
+ return await send();
92
+ }
93
+ catch (error) {
94
+ if (isFirst && rejectedWrite(error) && typeof error === 'object' && error !== null)
95
+ refusals.add(error);
96
+ throw error;
97
+ }
98
+ };
99
+ let targetId = plan.targetId;
100
+ let receiptStatus;
101
+ if (plan.writeDefinition) {
102
+ const response = await write(async () => plan.operation === 'create'
103
+ ? client.create(plan.document.definition)
104
+ : client.update(plan.targetId, plan.document.definition));
105
+ if (!response || typeof response !== 'object' || Array.isArray(response))
106
+ throw new DataTransformError('TRANSFORM_WRITE_UNCONFIRMED');
107
+ const receipt = response;
108
+ if (typeof receipt.id !== 'string' ||
109
+ !dataTransformId.test(receipt.id) ||
110
+ receipt.name !== plan.document.definition.name ||
111
+ (plan.targetId !== undefined && receipt.id !== plan.targetId))
112
+ throw new DataTransformError('TRANSFORM_WRITE_IDENTITY_MISMATCH');
113
+ targetId = receipt.id;
114
+ receiptStatus = receipt.status;
115
+ }
116
+ if (plan.writeSchedule && plan.writeDefinition) {
117
+ // After a definition write, wait until the transform is no longer processing; a 4xx answer
118
+ // to the schedule PUT then leaves the written definition in place.
119
+ const definition = plan.operation === 'create' ? 'create' : 'update';
120
+ const now = options.now ?? Date.now;
121
+ const delay = options.delay ?? (async (milliseconds) => wait(milliseconds));
122
+ const deadline = now() + SETTLE_BUDGET_MS;
123
+ for (;;) {
124
+ const read = await client.get(targetId);
125
+ const status = read && typeof read === 'object' ? read.status : undefined;
126
+ if (typeof status !== 'string' || status.toUpperCase() !== 'PROCESSING')
127
+ break;
128
+ if (now() >= deadline)
129
+ throw new DataTransformScheduleError('TRANSFORM_SCHEDULE_NOT_SENT', definition);
130
+ await delay(Math.min(SETTLE_INTERVAL_MS, Math.max(0, deadline - now())));
131
+ }
132
+ try {
133
+ await write(async () => client.setSchedule(targetId, plan.document.schedule));
134
+ }
135
+ catch (error) {
136
+ if (rejectedWrite(error))
137
+ throw new DataTransformScheduleError('TRANSFORM_SCHEDULE_REJECTED', definition, error);
138
+ throw error;
139
+ }
140
+ }
141
+ else if (plan.writeSchedule)
142
+ await write(async () => client.setSchedule(targetId, plan.document.schedule));
143
+ const raw = await client.get(targetId);
144
+ const rawSchedule = await client.schedule(targetId);
145
+ let observed;
146
+ try {
147
+ observed = observeDataTransform(raw, rawSchedule);
148
+ }
149
+ catch (error) {
150
+ // A readback that is not a transform of this name is an identity mismatch.
151
+ if (error instanceof DataTransformError)
152
+ throw new DataTransformError('TRANSFORM_READBACK_MISMATCH');
153
+ throw error;
154
+ }
155
+ if (observed.targetId !== targetId ||
156
+ observed.document.definition.name !== plan.document.definition.name ||
157
+ (plan.writeSchedule &&
158
+ frequency(observed.document.schedule ?? unscheduled) !== frequency(plan.document.schedule)))
159
+ throw new DataTransformError('TRANSFORM_READBACK_MISMATCH');
160
+ return {
161
+ operation: plan.operation,
162
+ observation: observed,
163
+ ...(plan.writeSchedule ? { scheduleWritten: true } : {}),
164
+ ...(receiptStatus === 'PROCESSING' || observed.runtime.status === 'PROCESSING'
165
+ ? { serverProcessing: true }
166
+ : {}),
167
+ };
168
+ }
@@ -0,0 +1,48 @@
1
+ import type { ApiVersionSelection } from '../transport/api-version.js';
2
+ import type { IdentityResolutionTargetConnection } from './preflight-identity-resolution-deploy.js';
3
+ import { bindIdentityResolutionDependencies, verifyIdentityResolutionOutputs } from './bind-identity-resolution-dependencies.js';
4
+ export declare const nativeIdentityResolutionPollBudget: Readonly<{
5
+ reads: 31;
6
+ intervalMs: 10000;
7
+ timeoutMs: 360000;
8
+ }>;
9
+ export type NativeIdentityResolutionExecutionOptions = {
10
+ allowProcessing: boolean;
11
+ allowGeneratedOutputProvisioning: boolean;
12
+ /**
13
+ * Return once Salesforce accepts the write, without settlement reads. A later identical
14
+ * deploy is the status check: NOT_SETTLED while in flight, unchanged once settled.
15
+ */
16
+ async?: boolean;
17
+ /** The prefix of the run's data space as the org's list names it; required outside default. */
18
+ dataSpacePrefix?: string;
19
+ verifyInput: () => Promise<void>;
20
+ verifyDependencies?: typeof bindIdentityResolutionDependencies;
21
+ verifyOutputs?: typeof verifyIdentityResolutionOutputs;
22
+ now?: () => number;
23
+ delay?: (milliseconds: number) => Promise<void>;
24
+ };
25
+ export type NativeIdentityResolutionDeployExecution = {
26
+ family: 'identity-resolution';
27
+ route: {
28
+ apiVersion: '68.0';
29
+ operation: 'identity-resolutions.post' | 'identity-resolutions.patch';
30
+ };
31
+ outcome: 'unchanged' | 'blocked' | 'created' | 'updated' | 'creation-processing' | 'update-processing' | 'failed';
32
+ mutation: 'not-attempted' | 'confirmed-created' | 'confirmed-updated' | 'acknowledged-processing' | 'unknown';
33
+ diagnostics: Array<{
34
+ code: string;
35
+ message: string;
36
+ }>;
37
+ };
38
+ /**
39
+ * Execute one qualified full-settings native68 CREATE or PATCH, never retrying a write.
40
+ * The caller must stop its batch on unknown mutation; no fallback or rollback exists here.
41
+ * @param {unknown} value Complete portable native68 desired definition.
42
+ * @param {IdentityResolutionTargetConnection} connection Fixed authenticated native68 receiver.
43
+ * @param {ApiVersionSelection} apiVersion Explicit native68 selection.
44
+ * @param {string} dataSpace The run's data space; the ruleset's c__dataSpace must name it.
45
+ * @param {NativeIdentityResolutionExecutionOptions} options Input/effect guards and synthetic read seams.
46
+ * @returns {Promise<NativeIdentityResolutionDeployExecution>} Payload-free mutation evidence.
47
+ */
48
+ export declare function executeNativeIdentityResolutionDeploy(value: unknown, connection: IdentityResolutionTargetConnection, apiVersion: ApiVersionSelection, dataSpace: string, options: NativeIdentityResolutionExecutionOptions): Promise<NativeIdentityResolutionDeployExecution>;