sf-plugin-data 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +618 -240
- package/docs/artifact-format.md +528 -633
- package/docs/capabilities.md +1160 -168
- package/docs/git-workflow.md +135 -12
- package/docs/handover.md +7826 -12
- package/lib/api.d.ts +13 -0
- package/lib/api.js +10 -0
- package/lib/artifacts/code-fields.d.ts +49 -0
- package/lib/artifacts/code-fields.js +142 -0
- package/lib/artifacts/data-graph-document.d.ts +29 -0
- package/lib/artifacts/data-graph-document.js +52 -0
- package/lib/artifacts/data-space-field.d.ts +65 -0
- package/lib/artifacts/data-space-field.js +98 -0
- package/lib/artifacts/data-stream-document.d.ts +264 -0
- package/lib/artifacts/data-stream-document.js +680 -0
- package/lib/artifacts/data-transform-document.d.ts +152 -0
- package/lib/artifacts/data-transform-document.js +560 -0
- package/lib/artifacts/dependency-selection.d.ts +51 -0
- package/lib/artifacts/dependency-selection.js +154 -0
- package/lib/artifacts/dlo-document.d.ts +93 -0
- package/lib/artifacts/dlo-document.js +253 -0
- package/lib/artifacts/enum-case.d.ts +39 -0
- package/lib/artifacts/enum-case.js +67 -0
- package/lib/artifacts/git-deploy-selection.d.ts +68 -0
- package/lib/artifacts/git-deploy-selection.js +474 -0
- package/lib/artifacts/identity-resolution-document.d.ts +133 -0
- package/lib/artifacts/identity-resolution-document.js +625 -0
- package/lib/artifacts/mapping-document.d.ts +1 -0
- package/lib/artifacts/mapping-document.js +1 -0
- package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
- package/lib/artifacts/native-calculated-insight-document.js +321 -0
- package/lib/artifacts/native-data-graph-document.d.ts +124 -0
- package/lib/artifacts/native-data-graph-document.js +780 -0
- package/lib/artifacts/native-dmo-document.d.ts +151 -0
- package/lib/artifacts/native-dmo-document.js +313 -0
- package/lib/artifacts/native-mapping-document.d.ts +67 -0
- package/lib/artifacts/native-mapping-document.js +187 -0
- package/lib/artifacts/native-relationship-document.d.ts +76 -0
- package/lib/artifacts/native-relationship-document.js +232 -0
- package/lib/artifacts/path-selector.d.ts +55 -0
- package/lib/artifacts/path-selector.js +167 -0
- package/lib/artifacts/read-deploy-input.d.ts +222 -6
- package/lib/artifacts/read-deploy-input.js +1213 -53
- package/lib/artifacts/segment-document.d.ts +183 -0
- package/lib/artifacts/segment-document.js +570 -0
- package/lib/artifacts/verbatim-document.d.ts +203 -0
- package/lib/artifacts/verbatim-document.js +339 -0
- package/lib/artifacts/write-data-graph.d.ts +17 -0
- package/lib/artifacts/write-data-graph.js +162 -0
- package/lib/artifacts/write-data-stream.d.ts +11 -0
- package/lib/artifacts/write-data-stream.js +175 -0
- package/lib/artifacts/write-data-transform.d.ts +11 -0
- package/lib/artifacts/write-data-transform.js +180 -0
- package/lib/artifacts/write-dlo.d.ts +11 -0
- package/lib/artifacts/write-dlo.js +158 -0
- package/lib/artifacts/write-identity-resolution.d.ts +18 -0
- package/lib/artifacts/write-identity-resolution.js +165 -0
- package/lib/artifacts/write-mapping-definition.d.ts +17 -0
- package/lib/artifacts/write-mapping-definition.js +127 -0
- package/lib/artifacts/write-member-export.d.ts +88 -0
- package/lib/artifacts/write-member-export.js +199 -0
- package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
- package/lib/artifacts/write-native-calculated-insight.js +176 -0
- package/lib/artifacts/write-native-dmo.d.ts +11 -0
- package/lib/artifacts/write-native-dmo.js +158 -0
- package/lib/artifacts/write-native-mapping.d.ts +11 -0
- package/lib/artifacts/write-native-mapping.js +157 -0
- package/lib/artifacts/write-native-relationship.d.ts +11 -0
- package/lib/artifacts/write-native-relationship.js +157 -0
- package/lib/artifacts/write-segment.d.ts +26 -0
- package/lib/artifacts/write-segment.js +212 -0
- package/lib/commands/data360/delete.d.ts +280 -0
- package/lib/commands/data360/delete.js +2347 -0
- package/lib/commands/data360/deploy.d.ts +235 -16
- package/lib/commands/data360/deploy.js +2339 -102
- package/lib/commands/data360/list/dataspace.d.ts +53 -0
- package/lib/commands/data360/list/dataspace.js +109 -0
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +298 -0
- package/lib/commands/data360/retrieve.d.ts +283 -14
- package/lib/commands/data360/retrieve.js +1945 -95
- package/lib/commands/data360/segment/members/export.d.ts +101 -0
- package/lib/commands/data360/segment/members/export.js +320 -0
- package/lib/errors/codes/calculated-insight.d.ts +2 -0
- package/lib/errors/codes/calculated-insight.js +25 -0
- package/lib/errors/codes/data-graph.d.ts +2 -0
- package/lib/errors/codes/data-graph.js +22 -0
- package/lib/errors/codes/data-stream.d.ts +2 -0
- package/lib/errors/codes/data-stream.js +70 -0
- package/lib/errors/codes/data-transform.d.ts +2 -0
- package/lib/errors/codes/data-transform.js +35 -0
- package/lib/errors/codes/dependency.d.ts +2 -0
- package/lib/errors/codes/dependency.js +11 -0
- package/lib/errors/codes/dlo.d.ts +2 -0
- package/lib/errors/codes/dlo.js +31 -0
- package/lib/errors/codes/dmo.d.ts +2 -0
- package/lib/errors/codes/dmo.js +28 -0
- package/lib/errors/codes/general.d.ts +2 -0
- package/lib/errors/codes/general.js +58 -0
- package/lib/errors/codes/identity-resolution.d.ts +2 -0
- package/lib/errors/codes/identity-resolution.js +24 -0
- package/lib/errors/codes/mapping.d.ts +2 -0
- package/lib/errors/codes/mapping.js +42 -0
- package/lib/errors/codes/relationship.d.ts +2 -0
- package/lib/errors/codes/relationship.js +21 -0
- package/lib/errors/codes/segment.d.ts +2 -0
- package/lib/errors/codes/segment.js +49 -0
- package/lib/errors/registry.d.ts +60 -0
- package/lib/errors/registry.js +123 -0
- package/lib/exit-code.d.ts +10 -0
- package/lib/exit-code.js +24 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +3 -1
- package/lib/services/acquire-retrieve-selection.d.ts +43 -0
- package/lib/services/acquire-retrieve-selection.js +145 -0
- package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
- package/lib/services/bind-identity-resolution-dependencies.js +238 -0
- package/lib/services/bind-segment-dependencies.d.ts +49 -0
- package/lib/services/bind-segment-dependencies.js +115 -0
- package/lib/services/bounded-reads.d.ts +17 -0
- package/lib/services/bounded-reads.js +42 -0
- package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
- package/lib/services/calculated-insight-sql-checks.js +193 -0
- package/lib/services/command-dlo.d.ts +48 -0
- package/lib/services/command-dlo.js +103 -0
- package/lib/services/command-native-data-graph.d.ts +54 -0
- package/lib/services/command-native-data-graph.js +485 -0
- package/lib/services/command-native-data-stream.d.ts +104 -0
- package/lib/services/command-native-data-stream.js +257 -0
- package/lib/services/command-native-dmo.d.ts +124 -0
- package/lib/services/command-native-dmo.js +338 -0
- package/lib/services/command-native-mapping.d.ts +65 -0
- package/lib/services/command-native-mapping.js +129 -0
- package/lib/services/command-native-relationship.d.ts +46 -0
- package/lib/services/command-native-relationship.js +103 -0
- package/lib/services/cross-dataspace-deploy.d.ts +111 -0
- package/lib/services/cross-dataspace-deploy.js +493 -0
- package/lib/services/cross-dataspace-rename.d.ts +74 -0
- package/lib/services/cross-dataspace-rename.js +1314 -0
- package/lib/services/cross-dataspace-sql.d.ts +109 -0
- package/lib/services/cross-dataspace-sql.js +1301 -0
- package/lib/services/cross-space-context.d.ts +23 -0
- package/lib/services/cross-space-context.js +38 -0
- package/lib/services/crud-plan.d.ts +137 -0
- package/lib/services/crud-plan.js +408 -0
- package/lib/services/data-space-check.d.ts +92 -0
- package/lib/services/data-space-check.js +169 -0
- package/lib/services/data-space-prefix.d.ts +77 -0
- package/lib/services/data-space-prefix.js +127 -0
- package/lib/services/data-transform-space.d.ts +31 -0
- package/lib/services/data-transform-space.js +79 -0
- package/lib/services/delete-calculated-insight.d.ts +44 -0
- package/lib/services/delete-calculated-insight.js +101 -0
- package/lib/services/delete-data-transform.d.ts +52 -0
- package/lib/services/delete-data-transform.js +222 -0
- package/lib/services/delete-dmo-field.d.ts +211 -0
- package/lib/services/delete-dmo-field.js +472 -0
- package/lib/services/delete-identity-resolution.d.ts +43 -0
- package/lib/services/delete-identity-resolution.js +295 -0
- package/lib/services/delete-segment.d.ts +42 -0
- package/lib/services/delete-segment.js +248 -0
- package/lib/services/deploy-result.d.ts +54 -0
- package/lib/services/deploy-result.js +60 -0
- package/lib/services/escaped-copy.d.ts +23 -0
- package/lib/services/escaped-copy.js +88 -0
- package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
- package/lib/services/execute-calculated-insight-deploy.js +96 -0
- package/lib/services/execute-data-transform-deploy.d.ts +56 -0
- package/lib/services/execute-data-transform-deploy.js +168 -0
- package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
- package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
- package/lib/services/execute-segment-deploy.d.ts +45 -0
- package/lib/services/execute-segment-deploy.js +393 -0
- package/lib/services/list-data-spaces.d.ts +17 -0
- package/lib/services/list-data-spaces.js +24 -0
- package/lib/services/local-file-removal.d.ts +36 -0
- package/lib/services/local-file-removal.js +103 -0
- package/lib/services/native-calculated-insight.d.ts +87 -0
- package/lib/services/native-calculated-insight.js +164 -0
- package/lib/services/native-crm-data-stream.d.ts +91 -0
- package/lib/services/native-crm-data-stream.js +272 -0
- package/lib/services/native-data-graph-context.d.ts +12 -0
- package/lib/services/native-data-graph-context.js +139 -0
- package/lib/services/native-data-graph-crd.d.ts +261 -0
- package/lib/services/native-data-graph-crd.js +866 -0
- package/lib/services/native-data-stream.d.ts +329 -0
- package/lib/services/native-data-stream.js +1830 -0
- package/lib/services/native-dlo.d.ts +163 -0
- package/lib/services/native-dlo.js +402 -0
- package/lib/services/native-dmo.d.ts +191 -0
- package/lib/services/native-dmo.js +614 -0
- package/lib/services/native-mapping.d.ts +255 -0
- package/lib/services/native-mapping.js +1226 -0
- package/lib/services/native-relationship.d.ts +132 -0
- package/lib/services/native-relationship.js +512 -0
- package/lib/services/operation-diagnostic.d.ts +83 -0
- package/lib/services/operation-diagnostic.js +272 -0
- package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
- package/lib/services/preflight-calculated-insight-deploy.js +95 -0
- package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
- package/lib/services/preflight-data-transform-deploy.js +104 -0
- package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
- package/lib/services/preflight-identity-resolution-deploy.js +281 -0
- package/lib/services/preflight-segment-deploy.d.ts +31 -0
- package/lib/services/preflight-segment-deploy.js +109 -0
- package/lib/services/publish-calculated-insight.d.ts +40 -0
- package/lib/services/publish-calculated-insight.js +95 -0
- package/lib/services/publish-segment.d.ts +65 -0
- package/lib/services/publish-segment.js +194 -0
- package/lib/services/readback-pace.d.ts +16 -0
- package/lib/services/readback-pace.js +23 -0
- package/lib/services/retrieve-data-transform.d.ts +26 -0
- package/lib/services/retrieve-data-transform.js +65 -0
- package/lib/services/retrieve-identity-resolution.d.ts +40 -0
- package/lib/services/retrieve-identity-resolution.js +87 -0
- package/lib/services/retrieve-inventory.d.ts +32 -0
- package/lib/services/retrieve-inventory.js +151 -0
- package/lib/services/retrieve-segment.d.ts +120 -0
- package/lib/services/retrieve-segment.js +502 -0
- package/lib/services/run-retrieve.d.ts +24 -0
- package/lib/services/run-retrieve.js +51 -0
- package/lib/services/segment-lookup.d.ts +46 -0
- package/lib/services/segment-lookup.js +108 -0
- package/lib/services/segment-members.d.ts +144 -0
- package/lib/services/segment-members.js +402 -0
- package/lib/services/select-native-retrieve.d.ts +60 -0
- package/lib/services/select-native-retrieve.js +226 -0
- package/lib/services/settle-calculated-insight.d.ts +22 -0
- package/lib/services/settle-calculated-insight.js +53 -0
- package/lib/services/sql-tokens.d.ts +58 -0
- package/lib/services/sql-tokens.js +147 -0
- package/lib/transport/api-version.d.ts +36 -0
- package/lib/transport/api-version.js +89 -0
- package/lib/transport/bound-ssot.d.ts +27 -0
- package/lib/transport/bound-ssot.js +116 -0
- package/lib/transport/calculated-insight-rest.d.ts +28 -0
- package/lib/transport/calculated-insight-rest.js +62 -0
- package/lib/transport/connect-client.d.ts +94 -32
- package/lib/transport/connect-client.js +318 -178
- package/lib/transport/connect-diagnostic.d.ts +89 -0
- package/lib/transport/connect-diagnostic.js +331 -0
- package/lib/transport/data-graph-rest.d.ts +27 -0
- package/lib/transport/data-graph-rest.js +76 -0
- package/lib/transport/data-stream-rest.d.ts +62 -0
- package/lib/transport/data-stream-rest.js +348 -0
- package/lib/transport/data-transform-rest.d.ts +25 -0
- package/lib/transport/data-transform-rest.js +100 -0
- package/lib/transport/dlo-native-rest.d.ts +22 -0
- package/lib/transport/dlo-native-rest.js +89 -0
- package/lib/transport/dlo-rest.d.ts +23 -0
- package/lib/transport/dlo-rest.js +135 -0
- package/lib/transport/dmo-native-rest.d.ts +18 -0
- package/lib/transport/dmo-native-rest.js +55 -0
- package/lib/transport/dmo-rest.d.ts +30 -0
- package/lib/transport/dmo-rest.js +163 -0
- package/lib/transport/mapping-rest.d.ts +63 -0
- package/lib/transport/mapping-rest.js +341 -0
- package/lib/transport/project-metadata.d.ts +36 -0
- package/lib/transport/project-metadata.js +118 -0
- package/lib/transport/relationship-rest.d.ts +43 -0
- package/lib/transport/relationship-rest.js +201 -0
- package/package.json +29 -6
- package/lib/artifacts/dmo-document.d.ts +0 -181
- package/lib/artifacts/dmo-document.js +0 -848
- package/lib/artifacts/dmo-update-delta.d.ts +0 -28
- package/lib/artifacts/dmo-update-delta.js +0 -86
- package/lib/artifacts/write-other-dmo.d.ts +0 -17
- package/lib/artifacts/write-other-dmo.js +0 -140
- package/lib/services/execute-dmo-create.d.ts +0 -24
- package/lib/services/execute-dmo-create.js +0 -118
- package/lib/services/execute-dmo-deploy.d.ts +0 -33
- package/lib/services/execute-dmo-deploy.js +0 -197
- package/lib/services/preflight-dmo-deploy.d.ts +0 -69
- package/lib/services/preflight-dmo-deploy.js +0 -161
- package/lib/services/retrieve-other-dmo.d.ts +0 -46
- package/lib/services/retrieve-other-dmo.js +0 -140
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { hintOf, operationDiagnostic, replaceExplanation } from './operation-diagnostic.js';
|
|
2
|
+
import { NativeDmoError } from '../artifacts/native-dmo-document.js';
|
|
3
|
+
import { NativeMappingError, nativeMappingName } from '../artifacts/native-mapping-document.js';
|
|
4
|
+
import { preflightNativeDmo, deployNativeDmo, mappedFieldRemoval } from './native-dmo.js';
|
|
5
|
+
import { WriteLedger, rejectedNextAction } from './deploy-result.js';
|
|
6
|
+
const unwritten = 'No write attempted; correct the reported check before another attempt.';
|
|
7
|
+
const identified = new WeakMap();
|
|
8
|
+
/**
|
|
9
|
+
* Warn about read-only field keys whose file value differs from the org. The outcome is not
|
|
10
|
+
* changed: Salesforce takes no input for these keys, so the org keeps its own value.
|
|
11
|
+
* @param {NotSentFieldKey[]} [notSent] Field and key of every differing read-only key.
|
|
12
|
+
* @returns {Array<{code: string, message: string}>} One warning, or none.
|
|
13
|
+
*/
|
|
14
|
+
function notSentDiagnostics(notSent) {
|
|
15
|
+
if (!notSent?.length)
|
|
16
|
+
return [];
|
|
17
|
+
return [
|
|
18
|
+
{
|
|
19
|
+
code: 'DMO_FIELD_KEY_NOT_SENT',
|
|
20
|
+
message: `Salesforce takes no input for these field keys, so the file's values were not sent and the org keeps its own: ${notSent.map(({ field, key }) => `fields.${field}.${key}`).join(', ')}.`,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read the mapped fields and their mappings recorded for a refused field removal.
|
|
26
|
+
* @param {unknown} error Caught error.
|
|
27
|
+
* @returns {MappedField[] | undefined} Recorded fields, or nothing for any other error.
|
|
28
|
+
*/
|
|
29
|
+
export function mappedFieldMappings(error) {
|
|
30
|
+
return error instanceof Error ? identified.get(error) : undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Render one command-line value, quoting it only when a shell would split it.
|
|
34
|
+
* @param {string} value Alias, username or data space as the user passed it.
|
|
35
|
+
* @returns {string} Copyable argument; a value a shell could expand is never echoed.
|
|
36
|
+
*/
|
|
37
|
+
function argument(value) {
|
|
38
|
+
if (/^[\w.@+-]+$/u.test(value))
|
|
39
|
+
return value;
|
|
40
|
+
return /^[\w.@+\- ]+$/u.test(value) ? `"${value}"` : '<value>';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* List, read-only, which mappings targeting the DMO hold a pair for each mapped field.
|
|
44
|
+
* @param {string} apiName Exact DMO full name.
|
|
45
|
+
* @param {string[]} fields Mapped fields the file omits.
|
|
46
|
+
* @param {MappedFieldGuide} guide Mapping inventory source.
|
|
47
|
+
* @returns {Promise<MappingInventory>} Each field with its mapping names in inventory order, and the source of every holder.
|
|
48
|
+
*/
|
|
49
|
+
async function findMappings(apiName, fields, guide) {
|
|
50
|
+
let response;
|
|
51
|
+
try {
|
|
52
|
+
response = (await guide.mappings().list(apiName));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
// A DMO without mappings answers the list with 404: an empty inventory.
|
|
56
|
+
if (!(error instanceof NativeMappingError) ||
|
|
57
|
+
error.code !== 'MAPPING_HTTP_ERROR' ||
|
|
58
|
+
error.status !== 404)
|
|
59
|
+
throw error;
|
|
60
|
+
response = { objectSourceTargetMaps: [] };
|
|
61
|
+
}
|
|
62
|
+
const maps = response?.objectSourceTargetMaps;
|
|
63
|
+
if (!Array.isArray(maps))
|
|
64
|
+
throw new TypeError('Mapping inventory was not returned.');
|
|
65
|
+
const mapped = fields.map((field) => ({ field, mappings: [] }));
|
|
66
|
+
const sources = new Map(fields.map((field) => [field, []]));
|
|
67
|
+
for (const entry of maps) {
|
|
68
|
+
if (entry?.targetEntityDeveloperName !== apiName || !Array.isArray(entry.fieldMappings))
|
|
69
|
+
continue;
|
|
70
|
+
const targets = new Set(entry.fieldMappings.map((pair) => pair?.targetFieldDeveloperName));
|
|
71
|
+
// Names are echoed into commands, so anything outside the mapping-name grammar is not named.
|
|
72
|
+
const name = typeof entry.developerName === 'string' && nativeMappingName.test(entry.developerName)
|
|
73
|
+
? entry.developerName
|
|
74
|
+
: undefined;
|
|
75
|
+
for (const item of mapped) {
|
|
76
|
+
if (!targets.has(item.field))
|
|
77
|
+
continue;
|
|
78
|
+
sources.get(item.field).push(entry.sourceEntityDeveloperName);
|
|
79
|
+
if (name && !item.mappings.includes(name))
|
|
80
|
+
item.mappings.push(name);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { mapped, sources };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Word the refusal: fields, mappings, the file edits and the single command that deploys the
|
|
87
|
+
* mappings and the DMO together, or the generic instruction when no mapping could be identified.
|
|
88
|
+
* @param {string} apiName Exact DMO full name.
|
|
89
|
+
* @param {MappedField[]} mapped Mapped fields with their identified mappings.
|
|
90
|
+
* @param {boolean} lookupFailed Whether the mapping inventory could not be read.
|
|
91
|
+
* @param {MappedFieldGuide} [guide] Target org and data space as passed.
|
|
92
|
+
* @returns {string} One message; command lines stand on their own lines.
|
|
93
|
+
*/
|
|
94
|
+
function mappedRemovalMessage(apiName, mapped, lookupFailed, guide) {
|
|
95
|
+
const fields = mapped.map(({ field }) => field).join(', ');
|
|
96
|
+
const names = [...new Set(mapped.flatMap(({ mappings }) => mappings))];
|
|
97
|
+
const lead = `Field removal refused for ${apiName}: `;
|
|
98
|
+
if (names.length === 0)
|
|
99
|
+
return `${lead}${fields} ${mapped.length === 1 ? 'is' : 'are'} mapped, and Salesforce would drop the mapping pair(s) together with the field(s). The mapping could not be identified (${lookupFailed ? 'the mapping lookup failed' : 'no mapping targeting this DMO lists a pair for the field(s)'}). Retrieve the mapping, remove the pair(s) whose targetFieldDeveloperName is ${fields} from its file, then deploy the mapping and this DMO in one command with --allow-field-removal.`;
|
|
100
|
+
const scope = (guide?.targetOrg === undefined ? '' : ` -o ${argument(guide.targetOrg)}`) +
|
|
101
|
+
(guide?.dataspace === undefined ? '' : ` --dataspace ${argument(guide.dataspace)}`);
|
|
102
|
+
const selectors = names.map((name) => ` -m mapping:${name}`).join('');
|
|
103
|
+
const unidentified = mapped
|
|
104
|
+
.filter(({ mappings }) => mappings.length === 0)
|
|
105
|
+
.map(({ field }) => field);
|
|
106
|
+
const summary = mapped
|
|
107
|
+
.map(({ field, mappings }) => mappings.length > 0
|
|
108
|
+
? `${field} is mapped by ${mappings.join(', ')}`
|
|
109
|
+
: `${field} is mapped by a mapping that could not be identified`)
|
|
110
|
+
.join('; ');
|
|
111
|
+
const edits = [
|
|
112
|
+
...names.map((name) => `In data360/mapping/${name}.mapping-meta.json remove the pair(s) whose targetFieldDeveloperName is ${mapped
|
|
113
|
+
.filter(({ mappings }) => mappings.includes(name))
|
|
114
|
+
.map(({ field }) => field)
|
|
115
|
+
.join(', ')}; keep all other pairs.`),
|
|
116
|
+
`In data360/dmo/${apiName}.dmo-meta.json remove the field(s) ${fields}.`,
|
|
117
|
+
...(unidentified.length > 0
|
|
118
|
+
? [
|
|
119
|
+
`Remove the pair(s) for ${unidentified.join(', ')} from the mapping that holds them in the same way.`,
|
|
120
|
+
]
|
|
121
|
+
: []),
|
|
122
|
+
];
|
|
123
|
+
return [
|
|
124
|
+
`${lead}${summary}. Salesforce would drop the mapping pair(s) together with the field(s), so remove the pair(s) from the mapping file(s) and deploy the mapping(s) and the DMO in one command:`,
|
|
125
|
+
`sf data360 retrieve${scope}${selectors} -m dmo:${apiName} --overwrite`,
|
|
126
|
+
edits.join(' '),
|
|
127
|
+
`sf data360 deploy${scope}${selectors} -m dmo:${apiName} --allow-field-removal`,
|
|
128
|
+
'',
|
|
129
|
+
].join('\n');
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Complete a mapped-field removal refusal with the mappings and commands. The lookup is read-only
|
|
133
|
+
* and never changes the refusal: when it fails or finds nothing, the generic instruction is kept.
|
|
134
|
+
* @param {unknown} error Caught error; anything but DMO_FIELD_REMOVAL_MAPPED is left untouched.
|
|
135
|
+
* @param {MappedFieldGuide} [guide] Mapping inventory source and command context.
|
|
136
|
+
* @returns {Promise<MappedField[] | undefined>} Mapped fields with their mappings, for this refusal only.
|
|
137
|
+
*/
|
|
138
|
+
async function explainMappedRemoval(error, guide) {
|
|
139
|
+
const refused = mappedFieldRemoval(error);
|
|
140
|
+
if (!refused || !(error instanceof Error))
|
|
141
|
+
return undefined;
|
|
142
|
+
let inventory;
|
|
143
|
+
try {
|
|
144
|
+
if (guide)
|
|
145
|
+
inventory = await findMappings(refused.apiName, refused.fields, guide);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
/* The refusal stands; only the mapping names are missing from its explanation. */
|
|
149
|
+
}
|
|
150
|
+
return recordMappedRemoval(error, refused, inventory, guide);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Attach the worded refusal and its mapped fields to the error.
|
|
154
|
+
* @param {Error} error Refusal raised by the preflight.
|
|
155
|
+
* @param {{apiName: string, fields: string[]}} refused DMO and mapped fields it names.
|
|
156
|
+
* @param {string} refused.apiName Exact DMO full name.
|
|
157
|
+
* @param {string[]} refused.fields Mapped fields the file omits.
|
|
158
|
+
* @param {MappingInventory} [inventory] Mapping inventory; absent when the lookup failed.
|
|
159
|
+
* @param {MappedFieldGuide} [guide] Target org and data space as passed.
|
|
160
|
+
* @returns {MappedField[]} Mapped fields with their mappings.
|
|
161
|
+
*/
|
|
162
|
+
function recordMappedRemoval(error, refused, inventory, guide) {
|
|
163
|
+
const mapped = inventory?.mapped ?? refused.fields.map((field) => ({ field, mappings: [] }));
|
|
164
|
+
replaceExplanation(error, mappedRemovalMessage(refused.apiName, mapped, inventory === undefined, guide));
|
|
165
|
+
identified.set(error, mapped);
|
|
166
|
+
return mapped;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Report a refusal raised before any write as a blocked item.
|
|
170
|
+
* @param {unknown} error Caught refusal.
|
|
171
|
+
* @returns {object} Payload-free blocked outcome with the mapped fields of a removal refusal.
|
|
172
|
+
*/
|
|
173
|
+
export function refusedDmo(error) {
|
|
174
|
+
const mappedFields = mappedFieldMappings(error);
|
|
175
|
+
return {
|
|
176
|
+
outcome: 'blocked',
|
|
177
|
+
mutation: 'not-attempted',
|
|
178
|
+
diagnostics: [
|
|
179
|
+
{
|
|
180
|
+
code: error instanceof NativeDmoError || error instanceof NativeMappingError
|
|
181
|
+
? error.code
|
|
182
|
+
: 'DMO_REQUEST_UNCONFIRMED',
|
|
183
|
+
message: operationDiagnostic(error, unwritten),
|
|
184
|
+
...hintOf(error),
|
|
185
|
+
...(mappedFields ? { mappedFields } : {}),
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Decide, read-only and before any write of the batch, which mapped fields a DMO may remove. A
|
|
192
|
+
* mapped field is covered when every target mapping that holds a pair for it is reconciled by a
|
|
193
|
+
* selected mapping file (same source and target object) that keeps no pair for the field.
|
|
194
|
+
* Salesforce then drops those pairs together with the field. Anything not covered, including a
|
|
195
|
+
* failed lookup, is the DMO_FIELD_REMOVAL_MAPPED refusal.
|
|
196
|
+
* @param {unknown} value Portable definition.
|
|
197
|
+
* @param {DmoClient} client Target client; only read.
|
|
198
|
+
* @param {string} requestScope The run's data space.
|
|
199
|
+
* @param {MappedFieldGuide | undefined} guide Mapping inventory source and command context.
|
|
200
|
+
* @param {SelectedMapping[]} selected Mapping files of the same selection.
|
|
201
|
+
* @returns {Promise<DmoRemovalAdmission>} Covered mapped fields; any other refusal is left to the item's own preflight.
|
|
202
|
+
*/
|
|
203
|
+
export async function admitDmoFieldRemoval(value, client, requestScope, guide, selected) {
|
|
204
|
+
try {
|
|
205
|
+
await preflightNativeDmo(value, client, requestScope, { allowFieldRemoval: true });
|
|
206
|
+
return { coveredMappedFields: [] };
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
const refused = mappedFieldRemoval(error);
|
|
210
|
+
if (!refused || !(error instanceof Error))
|
|
211
|
+
return { coveredMappedFields: [] };
|
|
212
|
+
let inventory;
|
|
213
|
+
try {
|
|
214
|
+
if (guide)
|
|
215
|
+
inventory = await findMappings(refused.apiName, refused.fields, guide);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
/* An unread inventory covers nothing. */
|
|
219
|
+
}
|
|
220
|
+
const sources = inventory?.sources;
|
|
221
|
+
const covered = sources !== undefined &&
|
|
222
|
+
refused.fields.every((field) => {
|
|
223
|
+
// A field no mapping holds a pair for has none to lose (Salesforce marks every field
|
|
224
|
+
// of a generated DMO as mapped), so it is covered.
|
|
225
|
+
const holders = sources.get(field);
|
|
226
|
+
return holders.every((source) => selected.some((mapping) => mapping.target === refused.apiName &&
|
|
227
|
+
mapping.source === source &&
|
|
228
|
+
!mapping.targetFields.includes(field)));
|
|
229
|
+
});
|
|
230
|
+
if (covered)
|
|
231
|
+
return { coveredMappedFields: refused.fields };
|
|
232
|
+
recordMappedRemoval(error, refused, inventory, guide);
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Compare an exact native DMO without mutation.
|
|
238
|
+
* @param {unknown} value Portable definition.
|
|
239
|
+
* @param {DmoClient} client Target client.
|
|
240
|
+
* @param {string} requestScope The run's data space.
|
|
241
|
+
* @param {DmoCommandOptions} [options] Opt-in field removal and its refusal guide.
|
|
242
|
+
* @returns {Promise<DmoPreview>} Payload-free comparison naming any planned field removals.
|
|
243
|
+
*/
|
|
244
|
+
export async function preflightDmo(value, client, requestScope, options = {}) {
|
|
245
|
+
const { mappedFieldGuide, ...deployOptions } = options;
|
|
246
|
+
let plan;
|
|
247
|
+
try {
|
|
248
|
+
plan = await preflightNativeDmo(value, client, requestScope, deployOptions);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
// The same refusal is rethrown; only its explanation gains the mappings and commands.
|
|
252
|
+
await explainMappedRemoval(error, mappedFieldGuide);
|
|
253
|
+
throw error;
|
|
254
|
+
}
|
|
255
|
+
const removeFields = plan.operation === 'update' ? plan.removeFields : undefined;
|
|
256
|
+
return {
|
|
257
|
+
family: 'dmo',
|
|
258
|
+
outcome: plan.operation,
|
|
259
|
+
target: plan.operation === 'create' ? 'absent' : 'existing',
|
|
260
|
+
absenceProof: plan.operation === 'create' ? 'confirmed-404' : 'none',
|
|
261
|
+
...(removeFields ? { removeFields } : {}),
|
|
262
|
+
diagnostics: [
|
|
263
|
+
...(removeFields
|
|
264
|
+
? [
|
|
265
|
+
{
|
|
266
|
+
code: 'DMO_FIELD_REMOVAL_PLANNED',
|
|
267
|
+
message: `Fields missing from the file are removed with one Metadata API destructive change: ${removeFields.join(', ')}.${deployOptions.coveredMappedFields?.length ? ` Salesforce drops the mapping pairs of ${deployOptions.coveredMappedFields.join(', ')} together with the field(s), so the selected mapping files find them already gone.` : ''}`,
|
|
268
|
+
},
|
|
269
|
+
]
|
|
270
|
+
: []),
|
|
271
|
+
...notSentDiagnostics(plan.operation === 'create' ? undefined : plan.notSent),
|
|
272
|
+
],
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Execute at most one PATCH and one field removal with conservative dispatch evidence and
|
|
277
|
+
* independent readback, reporting the mapping pairs Salesforce dropped with the fields.
|
|
278
|
+
* @param {unknown} value Portable definition.
|
|
279
|
+
* @param {DmoClient} client Target client.
|
|
280
|
+
* @param {string} requestScope The run's data space.
|
|
281
|
+
* @param {DmoCommandOptions} [options] Opt-in field removal and its refusal guide.
|
|
282
|
+
* @returns {Promise<object>} Payload-free outcome.
|
|
283
|
+
*/
|
|
284
|
+
export async function executeDmo(value, client, requestScope, options = {}) {
|
|
285
|
+
const { mappedFieldGuide, ...deployOptions } = options;
|
|
286
|
+
const ledger = new WriteLedger();
|
|
287
|
+
const remove = client.removeFields;
|
|
288
|
+
const guarded = {
|
|
289
|
+
...client,
|
|
290
|
+
create: async (body) => ledger.run(async () => client.create(body)),
|
|
291
|
+
update: async (name, body) => ledger.run(async () => client.update(name, body)),
|
|
292
|
+
...(remove
|
|
293
|
+
? {
|
|
294
|
+
removeFields: async (name, fieldNames) => ledger.run(async () => remove(name, fieldNames)),
|
|
295
|
+
}
|
|
296
|
+
: {}),
|
|
297
|
+
};
|
|
298
|
+
try {
|
|
299
|
+
const result = await deployNativeDmo(value, guarded, requestScope, undefined, deployOptions);
|
|
300
|
+
if (result.operation === 'unchanged')
|
|
301
|
+
return {
|
|
302
|
+
outcome: 'unchanged',
|
|
303
|
+
mutation: 'not-attempted',
|
|
304
|
+
diagnostics: notSentDiagnostics(result.notSent),
|
|
305
|
+
};
|
|
306
|
+
return {
|
|
307
|
+
outcome: result.operation === 'create' ? 'created' : 'updated',
|
|
308
|
+
mutation: result.operation === 'create'
|
|
309
|
+
? 'confirmed-created'
|
|
310
|
+
: 'confirmed-updated',
|
|
311
|
+
...(result.removedFields ? { removedFields: result.removedFields } : {}),
|
|
312
|
+
...(result.droppedPairs ? { droppedPairs: result.droppedPairs } : {}),
|
|
313
|
+
diagnostics: notSentDiagnostics(result.notSent),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
// Preflight raises this refusal before any dispatch; the mapping lookup is read-only.
|
|
318
|
+
const mappedFields = await explainMappedRemoval(error, mappedFieldGuide);
|
|
319
|
+
const failure = ledger.failure(error);
|
|
320
|
+
return {
|
|
321
|
+
...failure,
|
|
322
|
+
diagnostics: [
|
|
323
|
+
{
|
|
324
|
+
code: error instanceof NativeDmoError || error instanceof NativeMappingError
|
|
325
|
+
? error.code
|
|
326
|
+
: 'DMO_REQUEST_UNCONFIRMED',
|
|
327
|
+
message: operationDiagnostic(error, failure.mutation === 'rejected'
|
|
328
|
+
? rejectedNextAction
|
|
329
|
+
: failure.mutation === 'unknown'
|
|
330
|
+
? 'Write outcome is unknown; inspect target before another attempt. No automatic retry.'
|
|
331
|
+
: unwritten),
|
|
332
|
+
...hintOf(error),
|
|
333
|
+
...(mappedFields ? { mappedFields } : {}),
|
|
334
|
+
},
|
|
335
|
+
],
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { NativeMappingDocument } from '../artifacts/native-mapping-document.js';
|
|
2
|
+
import { deployNativeMapping } from './native-mapping.js';
|
|
3
|
+
import type { MappingDependencies } from './native-mapping.js';
|
|
4
|
+
import type { MappingClient } from '../transport/mapping-rest.js';
|
|
5
|
+
type MappingDiagnostic = {
|
|
6
|
+
code: string;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Compare a mapping without exposing payloads or replaying source identity.
|
|
11
|
+
* @param {unknown} value Portable mapping.
|
|
12
|
+
* @param {MappingClient} client Target mapping transport.
|
|
13
|
+
* @param {MappingDependencies} dependencies Fresh source/target readers.
|
|
14
|
+
* @param {string} requestScope The run's data space.
|
|
15
|
+
* @returns {Promise<object>} Payload-free preview.
|
|
16
|
+
*/
|
|
17
|
+
export declare function preflightMapping(value: unknown, client: MappingClient, dependencies: MappingDependencies, requestScope: string): Promise<{
|
|
18
|
+
plan: ({
|
|
19
|
+
sourceFieldDeveloperName: string;
|
|
20
|
+
targetFieldDeveloperName: string;
|
|
21
|
+
developerName?: string;
|
|
22
|
+
operation: "unmap";
|
|
23
|
+
apiName: string;
|
|
24
|
+
} | {
|
|
25
|
+
sourceFieldDeveloperName: string;
|
|
26
|
+
targetFieldDeveloperName: string;
|
|
27
|
+
apiName?: string | undefined;
|
|
28
|
+
operation: "create" | "add";
|
|
29
|
+
})[];
|
|
30
|
+
labelChange?: {
|
|
31
|
+
from?: string;
|
|
32
|
+
to: string;
|
|
33
|
+
} | undefined;
|
|
34
|
+
family: "mapping";
|
|
35
|
+
outcome: "create" | "update" | "unchanged";
|
|
36
|
+
target: string;
|
|
37
|
+
absenceProof: string;
|
|
38
|
+
diagnostics: MappingDiagnostic[];
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Track write dispatch conservatively and report independent settlement, not response echoes.
|
|
42
|
+
* @param {unknown} value Portable mapping.
|
|
43
|
+
* @param {MappingClient} client Target mapping transport.
|
|
44
|
+
* @param {MappingDependencies} dependencies Fresh source/target readers.
|
|
45
|
+
* @param {Function} [onUpdated] Receive independently confirmed changes without changing JSON.
|
|
46
|
+
* @param {string} requestScope The run's data space.
|
|
47
|
+
* @param {Function} [onResolvedName] Receive the independently verified target name for presentation.
|
|
48
|
+
* @param {Function} [onOrgName] Receive the name the org holds the mapping under, also when
|
|
49
|
+
* unchanged, with the document the deploy confirmed by reading it back.
|
|
50
|
+
* @returns {Promise<object>} Payload-free execution outcome.
|
|
51
|
+
*/
|
|
52
|
+
export declare function executeMapping(value: unknown, client: MappingClient, dependencies: MappingDependencies, onUpdated: Parameters<typeof deployNativeMapping>[3], requestScope: string, onResolvedName?: (apiName: string) => void, onOrgName?: (apiName: string, document: NativeMappingDocument) => void): Promise<{
|
|
53
|
+
diagnostics: MappingDiagnostic[];
|
|
54
|
+
targetApiName?: string | undefined;
|
|
55
|
+
outcome: "updated" | "unchanged" | "created";
|
|
56
|
+
mutation: "not-attempted" | "confirmed-created" | "confirmed-updated";
|
|
57
|
+
} | {
|
|
58
|
+
diagnostics: {
|
|
59
|
+
code: string;
|
|
60
|
+
message: string;
|
|
61
|
+
}[];
|
|
62
|
+
outcome: "failed" | "blocked";
|
|
63
|
+
mutation: "rejected" | "unknown" | "not-attempted";
|
|
64
|
+
}>;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { operationDiagnostic } from './operation-diagnostic.js';
|
|
2
|
+
import { NativeMappingError } from '../artifacts/native-mapping-document.js';
|
|
3
|
+
import { deployNativeMapping, preflightNativeMapping } from './native-mapping.js';
|
|
4
|
+
import { WriteLedger, rejectedNextAction } from './deploy-result.js';
|
|
5
|
+
/**
|
|
6
|
+
* Information for a create that is the first mapping of a standard DMO; never a refusal.
|
|
7
|
+
* @param {string} dmo Target DMO full name.
|
|
8
|
+
* @returns {MappingDiagnostic} Notice carried by the preview item and the created item.
|
|
9
|
+
*/
|
|
10
|
+
function activationNotice(dmo) {
|
|
11
|
+
return {
|
|
12
|
+
code: 'MAPPING_ACTIVATES_STANDARD_DMO',
|
|
13
|
+
message: `Creating the first mapping onto the standard object ${dmo} activates it permanently: it becomes enabled, gets a category and a generated key qualifier field. Deleting the mapping does not undo this.`,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Information for pairs whose source and target data types differ; Salesforce accepts them.
|
|
18
|
+
* @param {Array<object>} differences Pairs with both data types.
|
|
19
|
+
* @returns {MappingDiagnostic} Non-blocking preview notice.
|
|
20
|
+
*/
|
|
21
|
+
function typeNotice(differences) {
|
|
22
|
+
return {
|
|
23
|
+
code: 'MAPPING_FIELD_TYPES_DIFFER',
|
|
24
|
+
message: `These pairs map fields of different data types; Salesforce accepts them: ${differences
|
|
25
|
+
.map(({ source, target, sourceType, targetType }) => `${source} (${sourceType}) -> ${target} (${targetType})`)
|
|
26
|
+
.join(', ')}.`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Compare a mapping without exposing payloads or replaying source identity.
|
|
31
|
+
* @param {unknown} value Portable mapping.
|
|
32
|
+
* @param {MappingClient} client Target mapping transport.
|
|
33
|
+
* @param {MappingDependencies} dependencies Fresh source/target readers.
|
|
34
|
+
* @param {string} requestScope The run's data space.
|
|
35
|
+
* @returns {Promise<object>} Payload-free preview.
|
|
36
|
+
*/
|
|
37
|
+
export async function preflightMapping(value, client, dependencies, requestScope) {
|
|
38
|
+
const plan = await preflightNativeMapping(value, client, dependencies, requestScope);
|
|
39
|
+
return {
|
|
40
|
+
family: 'mapping',
|
|
41
|
+
outcome: plan.operation === 'noop' ? 'unchanged' : plan.operation,
|
|
42
|
+
target: plan.operation === 'create' ? 'absent' : 'existing',
|
|
43
|
+
absenceProof: plan.operation === 'create' ? 'confirmed-pair-lookup' : 'none',
|
|
44
|
+
diagnostics: [
|
|
45
|
+
...(plan.activatesStandardDmo
|
|
46
|
+
? [activationNotice(plan.desired.spec.targetEntityDeveloperName)]
|
|
47
|
+
: []),
|
|
48
|
+
...(plan.typeDifferences?.length ? [typeNotice(plan.typeDifferences)] : []),
|
|
49
|
+
],
|
|
50
|
+
...(plan.labelChange ? { labelChange: plan.labelChange } : {}),
|
|
51
|
+
plan: [
|
|
52
|
+
...(plan.removals ?? []).map((pair) => ({
|
|
53
|
+
operation: 'unmap',
|
|
54
|
+
apiName: plan.target.identity.apiName,
|
|
55
|
+
...pair,
|
|
56
|
+
})),
|
|
57
|
+
...plan.writes.flatMap(({ body }) => body.fieldMapping.map((pair) => ({
|
|
58
|
+
operation: plan.operation === 'create' ? 'create' : 'add',
|
|
59
|
+
...(plan.target ? { apiName: plan.target.identity.apiName } : {}),
|
|
60
|
+
...pair,
|
|
61
|
+
}))),
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Track write dispatch conservatively and report independent settlement, not response echoes.
|
|
67
|
+
* @param {unknown} value Portable mapping.
|
|
68
|
+
* @param {MappingClient} client Target mapping transport.
|
|
69
|
+
* @param {MappingDependencies} dependencies Fresh source/target readers.
|
|
70
|
+
* @param {Function} [onUpdated] Receive independently confirmed changes without changing JSON.
|
|
71
|
+
* @param {string} requestScope The run's data space.
|
|
72
|
+
* @param {Function} [onResolvedName] Receive the independently verified target name for presentation.
|
|
73
|
+
* @param {Function} [onOrgName] Receive the name the org holds the mapping under, also when
|
|
74
|
+
* unchanged, with the document the deploy confirmed by reading it back.
|
|
75
|
+
* @returns {Promise<object>} Payload-free execution outcome.
|
|
76
|
+
*/
|
|
77
|
+
export async function executeMapping(value, client, dependencies, onUpdated, requestScope, onResolvedName, onOrgName) {
|
|
78
|
+
const ledger = new WriteLedger();
|
|
79
|
+
const guarded = {
|
|
80
|
+
...client,
|
|
81
|
+
deleteField: async (name, selector) => ledger.run(async () => client.deleteField(name, selector)),
|
|
82
|
+
create: async (body) => ledger.run(async () => client.create(body)),
|
|
83
|
+
update: async (name, body) => ledger.run(async () => client.update(name, body)),
|
|
84
|
+
...(client.updateDefinition
|
|
85
|
+
? {
|
|
86
|
+
updateDefinition: async (definition) => ledger.run(async () => client.updateDefinition(definition)),
|
|
87
|
+
}
|
|
88
|
+
: {}),
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
const result = await deployNativeMapping(value, guarded, dependencies, onUpdated, requestScope);
|
|
92
|
+
if (result.operation !== 'noop')
|
|
93
|
+
onResolvedName?.(result.document.identity.apiName);
|
|
94
|
+
onOrgName?.(result.document.identity.apiName, result.document);
|
|
95
|
+
return {
|
|
96
|
+
outcome: result.operation === 'noop'
|
|
97
|
+
? 'unchanged'
|
|
98
|
+
: result.operation === 'create'
|
|
99
|
+
? 'created'
|
|
100
|
+
: 'updated',
|
|
101
|
+
mutation: result.operation === 'noop'
|
|
102
|
+
? 'not-attempted'
|
|
103
|
+
: result.operation === 'create'
|
|
104
|
+
? 'confirmed-created'
|
|
105
|
+
: 'confirmed-updated',
|
|
106
|
+
// The name Salesforce generated for a new mapping.
|
|
107
|
+
...(result.operation === 'create' ? { targetApiName: result.document.identity.apiName } : {}),
|
|
108
|
+
diagnostics: (result.activatesStandardDmo
|
|
109
|
+
? [activationNotice(result.document.spec.targetEntityDeveloperName)]
|
|
110
|
+
: []),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
const failure = ledger.failure(error);
|
|
115
|
+
return {
|
|
116
|
+
...failure,
|
|
117
|
+
diagnostics: [
|
|
118
|
+
{
|
|
119
|
+
code: error instanceof NativeMappingError ? error.code : 'MAPPING_REQUEST_UNCONFIRMED',
|
|
120
|
+
message: operationDiagnostic(error, failure.mutation === 'rejected'
|
|
121
|
+
? rejectedNextAction
|
|
122
|
+
: failure.mutation === 'unknown'
|
|
123
|
+
? 'Write outcome is unknown; inspect target before another attempt. No automatic retry.'
|
|
124
|
+
: 'No write attempted; correct the reported check before another attempt.'),
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { RelationshipClient } from '../transport/relationship-rest.js';
|
|
2
|
+
/**
|
|
3
|
+
* Compare a relationship with the org read-only, matched by name, else by its binding.
|
|
4
|
+
* @param {unknown} value Portable relationship.
|
|
5
|
+
* @param {Pick<RelationshipClient, 'list' | 'readDefinitions'>} client Relationship reader.
|
|
6
|
+
* @param {string} requestScope The run's data space.
|
|
7
|
+
* @returns {Promise<object>} Payload-free preview.
|
|
8
|
+
*/
|
|
9
|
+
export declare function preflightRelationship(value: unknown, client: Pick<RelationshipClient, 'list' | 'readDefinitions'>, requestScope: string): Promise<{
|
|
10
|
+
diagnostics: Array<{
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
changes?: string[] | undefined;
|
|
15
|
+
targetApiName?: string | undefined;
|
|
16
|
+
family: "relationship";
|
|
17
|
+
outcome: "create" | "update" | "unchanged";
|
|
18
|
+
target: "absent" | "existing";
|
|
19
|
+
absenceProof: string;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a relationship when absent, update it through the Metadata API when it differs, and
|
|
23
|
+
* report independently confirmed settlement. Salesforce's refusal of the item's first write is
|
|
24
|
+
* `rejected`: nothing was written.
|
|
25
|
+
* @param {unknown} value Portable relationship.
|
|
26
|
+
* @param {RelationshipClient} client Relationship transport.
|
|
27
|
+
* @param {string} requestScope The run's data space.
|
|
28
|
+
* @returns {Promise<object>} Payload-free execution outcome.
|
|
29
|
+
*/
|
|
30
|
+
export declare function executeRelationship(value: unknown, client: Pick<RelationshipClient, 'list' | 'create' | 'readDefinitions' | 'update'>, requestScope: string): Promise<{
|
|
31
|
+
outcome: "updated" | "unchanged" | "created";
|
|
32
|
+
mutation: "not-attempted" | "confirmed-created" | "confirmed-updated";
|
|
33
|
+
targetApiName: string;
|
|
34
|
+
diagnostics: Array<{
|
|
35
|
+
code: string;
|
|
36
|
+
message: string;
|
|
37
|
+
}>;
|
|
38
|
+
} | {
|
|
39
|
+
diagnostics: {
|
|
40
|
+
code: string;
|
|
41
|
+
message: string;
|
|
42
|
+
}[];
|
|
43
|
+
outcome: "failed" | "blocked";
|
|
44
|
+
mutation: "rejected" | "unknown" | "not-attempted";
|
|
45
|
+
targetApiName?: undefined;
|
|
46
|
+
}>;
|