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,341 @@
|
|
|
1
|
+
import { displayableApiText, getConnectDiagnostic, retainConnectDiagnostic, retainMetadataProblems, } from './connect-diagnostic.js';
|
|
2
|
+
import { manifest } from './dmo-rest.js';
|
|
3
|
+
import { ConnectClient, ConnectError } from './connect-client.js';
|
|
4
|
+
import { mkdtemp, writeFile } from 'node:fs/promises';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { NativeMappingError, mappingDloName, mappingDmoName, nativeMappingName, validateNativeMappingDocument, } from '../artifacts/native-mapping-document.js';
|
|
8
|
+
import { runProjectMetadata, verifyTemporaryDirectory } from './project-metadata.js';
|
|
9
|
+
import { nativeApiVersion } from './api-version.js';
|
|
10
|
+
import { openBoundSsot } from './bound-ssot.js';
|
|
11
|
+
import { replaceExplanation } from '../services/operation-diagnostic.js';
|
|
12
|
+
/** Metadata API type of a mapping; the record name is the mapping name. */
|
|
13
|
+
export const mappingMetadataType = 'ObjectSourceTargetMap';
|
|
14
|
+
/** Names per Metadata API read call (the API's limit). */
|
|
15
|
+
export const mappingReadBatch = 10;
|
|
16
|
+
/**
|
|
17
|
+
* SOAP faults where Salesforce refused the request itself, so nothing was applied. The request
|
|
18
|
+
* limit is not one of them here: it says nothing about the label, so it is reported apart.
|
|
19
|
+
*/
|
|
20
|
+
const clientFault = /^(?:soapenv:Client|sf:(?:INVALID_\w+|MALFORMED_\w+|INSUFFICIENT_ACCESS|API_DISABLED_FOR_ORG|UNSUPPORTED_API_VERSION))$/u;
|
|
21
|
+
/**
|
|
22
|
+
* A Metadata API answer as a list of records.
|
|
23
|
+
* @param {unknown} value One record or several.
|
|
24
|
+
* @returns {unknown[]} Records.
|
|
25
|
+
*/
|
|
26
|
+
export function metadataRecords(value) {
|
|
27
|
+
if (value === undefined || value === null)
|
|
28
|
+
return [];
|
|
29
|
+
return Array.isArray(value) ? value : [value];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Salesforce's refusal of a mapping label update: the label was not changed.
|
|
33
|
+
* @param {string} name Mapping name.
|
|
34
|
+
* @param {Array<{code?: unknown; message?: unknown}>} problems Salesforce's answers.
|
|
35
|
+
* @returns {NativeMappingError} MAPPING_LABEL_UPDATE_REJECTED with an explanation.
|
|
36
|
+
*/
|
|
37
|
+
function labelRefusal(name, problems) {
|
|
38
|
+
const said = problems
|
|
39
|
+
.slice(0, 3)
|
|
40
|
+
.map(({ code, message }) => [
|
|
41
|
+
typeof code === 'string' && /^[\w:.-]{1,80}$/u.test(code) ? code : undefined,
|
|
42
|
+
displayableApiText(message),
|
|
43
|
+
]
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.join(': '))
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
const error = new NativeMappingError('MAPPING_LABEL_UPDATE_REJECTED');
|
|
48
|
+
replaceExplanation(error, `Salesforce refused the Metadata API update of the ${mappingMetadataType} ${name}${said.length > 0 ? `: ${said.join('; ').replace(/\.$/u, '')}` : ' without a text the plugin can show'}. The label was not changed.`);
|
|
49
|
+
return error;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Metadata API read and update of mappings on the bound Connection.
|
|
53
|
+
* @param {Function} open The bound sender's Metadata API.
|
|
54
|
+
* @returns {Pick<MappingClient, 'readDefinitions' | 'updateDefinition'>} Both calls.
|
|
55
|
+
*/
|
|
56
|
+
function metadataCalls(open) {
|
|
57
|
+
return {
|
|
58
|
+
readDefinitions: async (names) => {
|
|
59
|
+
if (names.some((name) => !nativeMappingName.test(name)))
|
|
60
|
+
throw new NativeMappingError('INVALID_MAPPING_NAME');
|
|
61
|
+
const found = [];
|
|
62
|
+
for (let start = 0; start < names.length; start += mappingReadBatch) {
|
|
63
|
+
let answer;
|
|
64
|
+
try {
|
|
65
|
+
const api = await open();
|
|
66
|
+
answer = await api.read(mappingMetadataType, names.slice(start, start + mappingReadBatch));
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const failure = new NativeMappingError('MAPPING_LABEL_READ_FAILED');
|
|
70
|
+
const text = displayableApiText(error?.message);
|
|
71
|
+
replaceExplanation(failure, `The Metadata API read of ${mappingMetadataType} failed${text ? `: ${text}` : ''}.`);
|
|
72
|
+
throw failure;
|
|
73
|
+
}
|
|
74
|
+
for (const entry of metadataRecords(answer))
|
|
75
|
+
if (entry &&
|
|
76
|
+
typeof entry === 'object' &&
|
|
77
|
+
!Array.isArray(entry) &&
|
|
78
|
+
typeof entry.fullName === 'string')
|
|
79
|
+
found.push(entry);
|
|
80
|
+
}
|
|
81
|
+
return found;
|
|
82
|
+
},
|
|
83
|
+
updateDefinition: async (definition) => {
|
|
84
|
+
const name = definition.fullName;
|
|
85
|
+
if (typeof name !== 'string' || !nativeMappingName.test(name))
|
|
86
|
+
throw new NativeMappingError('INVALID_MAPPING_NAME');
|
|
87
|
+
let answer;
|
|
88
|
+
try {
|
|
89
|
+
const api = await open();
|
|
90
|
+
answer = await api.update(mappingMetadataType, definition);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
// Only a client fault is Salesforce refusing the request; a server fault (soapenv:Server,
|
|
94
|
+
// sf:UNKNOWN_EXCEPTION) may follow an applied update, so it stays unconfirmed.
|
|
95
|
+
const fault = error;
|
|
96
|
+
if (typeof fault?.name === 'string' && clientFault.test(fault.name))
|
|
97
|
+
throw labelRefusal(name, [{ code: fault.name, message: fault.message }]);
|
|
98
|
+
const unconfirmed = new NativeMappingError('MAPPING_REQUEST_UNCONFIRMED');
|
|
99
|
+
if (fault?.name === 'sf:REQUEST_LIMIT_EXCEEDED')
|
|
100
|
+
replaceExplanation(unconfirmed, `Salesforce did not take the Metadata API update of the ${mappingMetadataType} ${name}: the org's API request limit is used up (sf:REQUEST_LIMIT_EXCEEDED), so the label was not changed. Rerun the deploy once the limit has reset; the file needs no change.`);
|
|
101
|
+
throw unconfirmed;
|
|
102
|
+
}
|
|
103
|
+
const [result] = metadataRecords(answer);
|
|
104
|
+
if (result?.success === true)
|
|
105
|
+
return;
|
|
106
|
+
if (result?.success === false)
|
|
107
|
+
throw labelRefusal(name, metadataRecords(result.errors).map((entry) => {
|
|
108
|
+
const problem = (entry ?? {});
|
|
109
|
+
return { code: problem.statusCode, message: problem.message };
|
|
110
|
+
}));
|
|
111
|
+
throw new NativeMappingError('MAPPING_REQUEST_UNCONFIRMED');
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Read filtered mapping inventories on the existing command-owned connection.
|
|
117
|
+
* Only an explicit transport 404 is the typed no-map condition; other failures propagate.
|
|
118
|
+
* @param {Pick<Connection, 'instanceUrl' | 'request'>} connection Authenticated command connection.
|
|
119
|
+
* @param {string} apiVersion Admitted numeric native version.
|
|
120
|
+
* @param {string} dataSpace The run's data space, sent as `?dataspace=` on every list.
|
|
121
|
+
* @returns {Pick<MappingClient, 'list'>} List-only reader without CLI startup or scratch files.
|
|
122
|
+
*/
|
|
123
|
+
export function createMappingInventoryReader(connection, apiVersion, dataSpace) {
|
|
124
|
+
const version = nativeApiVersion(apiVersion);
|
|
125
|
+
const client = new ConnectClient(connection, version);
|
|
126
|
+
return {
|
|
127
|
+
list: async (dmoDeveloperName, dloDeveloperName) => {
|
|
128
|
+
if (!mappingDmoName.test(dmoDeveloperName) ||
|
|
129
|
+
(dloDeveloperName !== undefined && !mappingDloName.test(dloDeveloperName)))
|
|
130
|
+
throw new NativeMappingError('INVALID_MAPPING_BINDING');
|
|
131
|
+
const query = new URLSearchParams({ dataspace: dataSpace });
|
|
132
|
+
query.set('dmoDeveloperName', dmoDeveloperName);
|
|
133
|
+
if (dloDeveloperName !== undefined)
|
|
134
|
+
query.set('dloDeveloperName', dloDeveloperName);
|
|
135
|
+
try {
|
|
136
|
+
return await client.get(`/services/data/v${version}/ssot/data-model-object-mappings?${query}`);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (error instanceof ConnectError &&
|
|
140
|
+
error.code === 'REQUEST_FAILED' &&
|
|
141
|
+
error.statusCode === 404)
|
|
142
|
+
throw new NativeMappingError('MAPPING_HTTP_ERROR', 404);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Require explicit operation input, never convert saved read evidence into a send policy.
|
|
150
|
+
* @param {MappingWriteBody} body Explicit caller-selected pairs.
|
|
151
|
+
*/
|
|
152
|
+
function validateBody(body) {
|
|
153
|
+
if (!body || Object.keys(body).length !== 3 || !Array.isArray(body.fieldMapping))
|
|
154
|
+
throw new NativeMappingError('INVALID_MAPPING_BODY');
|
|
155
|
+
validateNativeMappingDocument({
|
|
156
|
+
schemaVersion: 1,
|
|
157
|
+
kind: 'mapping',
|
|
158
|
+
c__dataSpace: 'default',
|
|
159
|
+
identity: { apiName: 'Input' },
|
|
160
|
+
spec: {
|
|
161
|
+
sourceEntityDeveloperName: body.sourceEntityDeveloperName,
|
|
162
|
+
targetEntityDeveloperName: body.targetEntityDeveloperName,
|
|
163
|
+
fieldMappings: body.fieldMapping,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
if (body.fieldMapping.some((field) => Object.keys(field).length !== 2))
|
|
167
|
+
throw new NativeMappingError('INVALID_MAPPING_BODY');
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Build a native client on the bound in-process connection. Numeric admission is not
|
|
171
|
+
* live-version qualification.
|
|
172
|
+
* The caller owns target pair resolution; additions send names only, without a field selector.
|
|
173
|
+
* @param {string} targetOrg Explicit authenticated alias or username.
|
|
174
|
+
* @param {string} apiVersion Validated numeric version, or default/auto 68.0.
|
|
175
|
+
* @param {MetadataRunner} runner Installed CLI runner, used only for the destructive `remove`.
|
|
176
|
+
* @param {string} dataSpace The run's data space, sent as `?dataspace=` on every mapping request
|
|
177
|
+
* except the Metadata API calls (their record names are unique in the org).
|
|
178
|
+
* @param {BoundSsot} [sender] The command's shared sender; defaults to one opened for targetOrg.
|
|
179
|
+
* @param {ReadonlyMap<string, unknown>} [listed] Entries of this run's mapping lists at the same
|
|
180
|
+
* version and data space, by name. A listed name's GET answers with a copy of its entry, which
|
|
181
|
+
* Salesforce returns byte for byte the same, instead of another request.
|
|
182
|
+
* @returns {MappingClient} Raw operations; `remove` scratch is retained.
|
|
183
|
+
*/
|
|
184
|
+
export function createMappingClient(targetOrg, apiVersion = '68.0', runner = runProjectMetadata, dataSpace, sender, listed) {
|
|
185
|
+
const version = nativeApiVersion(apiVersion);
|
|
186
|
+
if (!targetOrg ||
|
|
187
|
+
targetOrg.startsWith('-') ||
|
|
188
|
+
[...targetOrg].some((character) => character.codePointAt(0) < 32))
|
|
189
|
+
throw new NativeMappingError('UNSUPPORTED_MAPPING_SELECTION');
|
|
190
|
+
const bound = sender ?? openBoundSsot(targetOrg, version);
|
|
191
|
+
const endpoint = `/services/data/v${version}/ssot/data-model-object-mappings`;
|
|
192
|
+
const scopeQuery = `?${new URLSearchParams({ dataspace: dataSpace })}`;
|
|
193
|
+
/**
|
|
194
|
+
* Validate exact mapping names, never source IDs or guessed suffixes.
|
|
195
|
+
* @param {string} name Native mapping developer name.
|
|
196
|
+
* @returns {string} Exact item suffix.
|
|
197
|
+
*/
|
|
198
|
+
function nameSuffix(name) {
|
|
199
|
+
if (!nativeMappingName.test(name))
|
|
200
|
+
throw new NativeMappingError('INVALID_MAPPING_NAME');
|
|
201
|
+
return `/${name}`;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Send one request on the bound connection: no child CLI, token refresh or redirect, and a
|
|
205
|
+
* write is never resent once it may have reached Salesforce. Not settlement evidence.
|
|
206
|
+
* @param {'GET' | 'POST' | 'PATCH' | 'DELETE'} method HTTP verb.
|
|
207
|
+
* @param {string} suffix Validated route and query.
|
|
208
|
+
* @param {MappingWriteBody} [body] Explicit operation input.
|
|
209
|
+
* @returns {Promise<unknown>} Parsed non-array object; nothing for a successful DELETE.
|
|
210
|
+
*/
|
|
211
|
+
async function request(method, suffix, body) {
|
|
212
|
+
if (body)
|
|
213
|
+
validateBody(body);
|
|
214
|
+
const noContent = Symbol('mapping-no-content');
|
|
215
|
+
let response;
|
|
216
|
+
try {
|
|
217
|
+
response = await bound.request(method, endpoint + suffix, noContent, body);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
if (!(error instanceof ConnectError))
|
|
221
|
+
throw error;
|
|
222
|
+
const status = error.code === 'AUTHENTICATION_FAILED' ? 401 : error.statusCode;
|
|
223
|
+
throw retainConnectDiagnostic(new NativeMappingError(status === undefined ? 'MAPPING_REQUEST_UNCONFIRMED' : 'MAPPING_HTTP_ERROR', status), getConnectDiagnostic(error));
|
|
224
|
+
}
|
|
225
|
+
// DELETE accepts documented 200 and observed 204; the body is ignored because absence is
|
|
226
|
+
// proven later by typed-404 settlement reads.
|
|
227
|
+
if (method === 'DELETE')
|
|
228
|
+
return;
|
|
229
|
+
if (response === noContent)
|
|
230
|
+
throw new NativeMappingError('MAPPING_REQUEST_UNCONFIRMED', 204);
|
|
231
|
+
if (typeof response !== 'object' || response === null || Array.isArray(response))
|
|
232
|
+
throw new NativeMappingError('INVALID_MAPPING_RESPONSE');
|
|
233
|
+
return response;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Delete one mapping with one Metadata API destructive deployment; never retried.
|
|
237
|
+
* This is the one mapping write left on the child `sf project deploy start` runner: the bound
|
|
238
|
+
* connection has no deploy-and-poll route yet, and the user chose to keep it here for now.
|
|
239
|
+
* @param {string} name Exact native mapping developer name.
|
|
240
|
+
* @returns {Promise<void>} Resolves only when the member is reported deleted.
|
|
241
|
+
*/
|
|
242
|
+
async function remove(name) {
|
|
243
|
+
// Only a name that matched the identifier pattern reaches the XML.
|
|
244
|
+
if (!nativeMappingName.test(name))
|
|
245
|
+
throw new NativeMappingError('INVALID_MAPPING_NAME');
|
|
246
|
+
verifyTemporaryDirectory();
|
|
247
|
+
const root = await mkdtemp(path.join(os.tmpdir(), 'data360-mapping-delete-'));
|
|
248
|
+
await writeFile(path.join(root, 'package.xml'), manifest(version, []), { flag: 'wx' });
|
|
249
|
+
await writeFile(path.join(root, 'destructiveChanges.xml'), manifest(version, [
|
|
250
|
+
' <types>',
|
|
251
|
+
` <members>${name}</members>`,
|
|
252
|
+
' <name>ObjectSourceTargetMap</name>',
|
|
253
|
+
' </types>',
|
|
254
|
+
]), { flag: 'wx' });
|
|
255
|
+
const receipt = await runner([
|
|
256
|
+
'project',
|
|
257
|
+
'deploy',
|
|
258
|
+
'start',
|
|
259
|
+
'--metadata-dir',
|
|
260
|
+
root,
|
|
261
|
+
'--target-org',
|
|
262
|
+
targetOrg,
|
|
263
|
+
'--wait',
|
|
264
|
+
'10',
|
|
265
|
+
'--json',
|
|
266
|
+
], root);
|
|
267
|
+
let envelope = {};
|
|
268
|
+
try {
|
|
269
|
+
const parsed = JSON.parse(receipt.stdout);
|
|
270
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
271
|
+
envelope = parsed;
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
/* An unreadable receipt confirms nothing. */
|
|
275
|
+
}
|
|
276
|
+
const result = envelope.result && typeof envelope.result === 'object' ? envelope.result : undefined;
|
|
277
|
+
const details = result?.details && typeof result.details === 'object'
|
|
278
|
+
? result.details
|
|
279
|
+
: {};
|
|
280
|
+
const list = (value) => (Array.isArray(value) ? value : [value]).filter((entry) => Boolean(entry) && typeof entry === 'object');
|
|
281
|
+
if (receipt.exitCode === 0 &&
|
|
282
|
+
envelope.status === 0 &&
|
|
283
|
+
result?.success === true &&
|
|
284
|
+
result.status === 'Succeeded' &&
|
|
285
|
+
list(details.componentSuccesses).some((entry) => entry.fullName === name &&
|
|
286
|
+
entry.componentType === 'ObjectSourceTargetMap' &&
|
|
287
|
+
entry.deleted === true))
|
|
288
|
+
return;
|
|
289
|
+
const failures = list(details.componentFailures);
|
|
290
|
+
// A deployment Salesforce reports Failed with component failures applied nothing.
|
|
291
|
+
const rejected = result?.status === 'Failed' && result.success === false && failures.length > 0;
|
|
292
|
+
throw retainMetadataProblems(new NativeMappingError('MAPPING_DELETE_FAILED', undefined, rejected ? true : undefined), [...failures.map((failure) => failure.problem), result?.errorMessage, envelope.message]);
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
apiVersion: version,
|
|
296
|
+
remove,
|
|
297
|
+
deleteField: async (name, observedSelector) => {
|
|
298
|
+
// Validate the observed selector through the existing artifact grammar, never synthesize it.
|
|
299
|
+
validateNativeMappingDocument({
|
|
300
|
+
schemaVersion: 1,
|
|
301
|
+
kind: 'mapping',
|
|
302
|
+
c__dataSpace: 'default',
|
|
303
|
+
identity: { apiName: name },
|
|
304
|
+
spec: {
|
|
305
|
+
sourceEntityDeveloperName: 'Input__dll',
|
|
306
|
+
targetEntityDeveloperName: 'Input__dlm',
|
|
307
|
+
fieldMappings: [
|
|
308
|
+
{
|
|
309
|
+
sourceFieldDeveloperName: 'Input__c',
|
|
310
|
+
targetFieldDeveloperName: 'Input__c',
|
|
311
|
+
developerName: observedSelector,
|
|
312
|
+
},
|
|
313
|
+
],
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
if (!observedSelector)
|
|
317
|
+
throw new NativeMappingError('INVALID_MAPPING_FIELD');
|
|
318
|
+
await request('DELETE', `${nameSuffix(name)}/field-mappings/${observedSelector}${scopeQuery}`);
|
|
319
|
+
},
|
|
320
|
+
list: async (dmoDeveloperName, dloDeveloperName) => {
|
|
321
|
+
if (!mappingDmoName.test(dmoDeveloperName) ||
|
|
322
|
+
(dloDeveloperName !== undefined && !mappingDloName.test(dloDeveloperName)))
|
|
323
|
+
throw new NativeMappingError('INVALID_MAPPING_BINDING');
|
|
324
|
+
const query = new URLSearchParams({ dataspace: dataSpace });
|
|
325
|
+
query.set('dmoDeveloperName', dmoDeveloperName);
|
|
326
|
+
if (dloDeveloperName !== undefined)
|
|
327
|
+
query.set('dloDeveloperName', dloDeveloperName);
|
|
328
|
+
return request('GET', `?${query}`);
|
|
329
|
+
},
|
|
330
|
+
get: async (name) => {
|
|
331
|
+
const suffix = nameSuffix(name);
|
|
332
|
+
const entry = listed?.get(name);
|
|
333
|
+
if (entry !== undefined)
|
|
334
|
+
return structuredClone(entry);
|
|
335
|
+
return request('GET', `${suffix}${scopeQuery}`);
|
|
336
|
+
},
|
|
337
|
+
create: async (body) => request('POST', scopeQuery, body),
|
|
338
|
+
update: async (name, body) => request('PATCH', `${nameSuffix(name)}/field-mappings${scopeQuery}`, body),
|
|
339
|
+
...(bound.metadata ? metadataCalls(bound.metadata) : {}),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type MetadataRunner = (arguments_: string[], cwd: string) => Promise<{
|
|
2
|
+
exitCode: number;
|
|
3
|
+
stdout: string;
|
|
4
|
+
}>;
|
|
5
|
+
/**
|
|
6
|
+
* Refuse unsafe temporary placement before creating any scratch roots.
|
|
7
|
+
* @returns {void} Nothing when the current process has safe OS temporary placement.
|
|
8
|
+
*/
|
|
9
|
+
export declare function verifyTemporaryDirectory(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Run work in which every directory's ancestor chain is checked once. A later check of a path
|
|
12
|
+
* below a checked directory still resolves that path's own real path, which proves that no
|
|
13
|
+
* ancestor has since become a link or junction; a path that does not exist proves it through
|
|
14
|
+
* its parent's real path instead. Files are never remembered.
|
|
15
|
+
* @template T
|
|
16
|
+
* @param {() => Promise<T>} work The run.
|
|
17
|
+
* @returns {Promise<T>} Its result.
|
|
18
|
+
*/
|
|
19
|
+
export declare function withCheckedDirectories<T>(work: () => Promise<T>): Promise<T>;
|
|
20
|
+
/**
|
|
21
|
+
* Inspect the exact ancestor chain without following filesystem aliases or links.
|
|
22
|
+
* @param {string} file Absolute path to inspect.
|
|
23
|
+
* @returns {Promise<import('node:fs').Stats>} Checked entry.
|
|
24
|
+
*/
|
|
25
|
+
export declare function inspectSegmentPath(file: string): Promise<import('node:fs').Stats>;
|
|
26
|
+
/**
|
|
27
|
+
* Run the installed CLI using argument arrays only, with finite output and elapsed bounds.
|
|
28
|
+
* Windows invokes the installed JS entry through Node, never shell-interpolated arguments.
|
|
29
|
+
* @param {string[]} arguments_ Exact CLI arguments.
|
|
30
|
+
* @param {string} cwd Owned scratch project.
|
|
31
|
+
* @returns {Promise<{exitCode: number; stdout: string}>} Structured stdout and actual exit status.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runProjectMetadata(arguments_: string[], cwd: string): Promise<{
|
|
34
|
+
exitCode: number;
|
|
35
|
+
stdout: string;
|
|
36
|
+
}>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { lstat, realpath } from 'node:fs/promises';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { SegmentError } from '../artifacts/segment-document.js';
|
|
7
|
+
const normalize = (value) => process.platform === 'win32' ? value.toLowerCase() : value;
|
|
8
|
+
/**
|
|
9
|
+
* Refuse unsafe temporary placement before creating any scratch roots.
|
|
10
|
+
* @returns {void} Nothing when the current process has safe OS temporary placement.
|
|
11
|
+
*/
|
|
12
|
+
export function verifyTemporaryDirectory() {
|
|
13
|
+
if (process.platform !== 'win32')
|
|
14
|
+
return;
|
|
15
|
+
for (const [key, value] of Object.entries({
|
|
16
|
+
TEMP: process.env.TEMP,
|
|
17
|
+
node: os.tmpdir(),
|
|
18
|
+
TMP: process.env.TMP,
|
|
19
|
+
TMPDIR: process.env.TMPDIR,
|
|
20
|
+
})) {
|
|
21
|
+
if ((key === 'TEMP' || key === 'node' || value) &&
|
|
22
|
+
(!value ||
|
|
23
|
+
!path.isAbsolute(value) ||
|
|
24
|
+
path
|
|
25
|
+
.resolve(value)
|
|
26
|
+
.replace(/[\\/]+$/u, '')
|
|
27
|
+
.toLowerCase() !== String.raw `f:\temp`))
|
|
28
|
+
throw new SegmentError('UNSAFE_TEMP');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Directories already checked in the current run (see withCheckedDirectories), by exact path.
|
|
32
|
+
const checkedDirectories = new AsyncLocalStorage();
|
|
33
|
+
/**
|
|
34
|
+
* Run work in which every directory's ancestor chain is checked once. A later check of a path
|
|
35
|
+
* below a checked directory still resolves that path's own real path, which proves that no
|
|
36
|
+
* ancestor has since become a link or junction; a path that does not exist proves it through
|
|
37
|
+
* its parent's real path instead. Files are never remembered.
|
|
38
|
+
* @template T
|
|
39
|
+
* @param {() => Promise<T>} work The run.
|
|
40
|
+
* @returns {Promise<T>} Its result.
|
|
41
|
+
*/
|
|
42
|
+
export async function withCheckedDirectories(work) {
|
|
43
|
+
return checkedDirectories.run(new Map(), work);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Inspect the exact ancestor chain without following filesystem aliases or links.
|
|
47
|
+
* @param {string} file Absolute path to inspect.
|
|
48
|
+
* @returns {Promise<import('node:fs').Stats>} Checked entry.
|
|
49
|
+
*/
|
|
50
|
+
export async function inspectSegmentPath(file) {
|
|
51
|
+
const checked = checkedDirectories.getStore();
|
|
52
|
+
const known = checked?.get(file);
|
|
53
|
+
if (known)
|
|
54
|
+
return known;
|
|
55
|
+
const parent = path.dirname(file);
|
|
56
|
+
if (parent !== file) {
|
|
57
|
+
const ancestor = await inspectSegmentPath(parent);
|
|
58
|
+
if (!ancestor.isDirectory())
|
|
59
|
+
throw new SegmentError('UNSAFE_PATH');
|
|
60
|
+
}
|
|
61
|
+
let stat;
|
|
62
|
+
try {
|
|
63
|
+
stat = await lstat(file);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
// A remembered parent may have become a link since; its real path shows it.
|
|
67
|
+
if (checked?.has(parent) &&
|
|
68
|
+
error.code === 'ENOENT' &&
|
|
69
|
+
normalize(await realpath(parent)) !== normalize(parent))
|
|
70
|
+
throw new SegmentError('UNSAFE_PATH');
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
if (stat.isSymbolicLink() || normalize(await realpath(file)) !== normalize(file))
|
|
74
|
+
throw new SegmentError('UNSAFE_PATH');
|
|
75
|
+
if (checked && stat.isDirectory())
|
|
76
|
+
checked.set(file, stat);
|
|
77
|
+
return stat;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Run the installed CLI using argument arrays only, with finite output and elapsed bounds.
|
|
81
|
+
* Windows invokes the installed JS entry through Node, never shell-interpolated arguments.
|
|
82
|
+
* @param {string[]} arguments_ Exact CLI arguments.
|
|
83
|
+
* @param {string} cwd Owned scratch project.
|
|
84
|
+
* @returns {Promise<{exitCode: number; stdout: string}>} Structured stdout and actual exit status.
|
|
85
|
+
*/
|
|
86
|
+
export async function runProjectMetadata(arguments_, cwd) {
|
|
87
|
+
// Never retried: the child's network error is not visible, so a retry could write twice.
|
|
88
|
+
const executable = process.platform === 'win32' ? process.execPath : 'sf';
|
|
89
|
+
let parameters = arguments_;
|
|
90
|
+
if (process.platform === 'win32') {
|
|
91
|
+
// Standard npm global Windows installation; absence blocks rather than installing or invoking cmd.exe.
|
|
92
|
+
const entry = path.join(process.env.APPDATA ?? '', 'npm', 'node_modules', '@salesforce', 'cli', 'bin', 'run.js');
|
|
93
|
+
const stat = await inspectSegmentPath(entry);
|
|
94
|
+
if (!process.env.APPDATA || !stat.isFile())
|
|
95
|
+
throw new SegmentError('STANDARD_CLI_UNAVAILABLE');
|
|
96
|
+
parameters = [entry, ...arguments_];
|
|
97
|
+
}
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
execFile(executable, parameters, {
|
|
100
|
+
cwd,
|
|
101
|
+
timeout: 330_000,
|
|
102
|
+
maxBuffer: 4_194_304,
|
|
103
|
+
windowsHide: true,
|
|
104
|
+
env: {
|
|
105
|
+
...process.env,
|
|
106
|
+
SF_AUTOUPDATE_DISABLE: 'true',
|
|
107
|
+
SF_DISABLE_TELEMETRY: 'true',
|
|
108
|
+
SF_DISABLE_SOURCE_MEMBER_POLLING: 'true',
|
|
109
|
+
},
|
|
110
|
+
}, (error, stdout) => {
|
|
111
|
+
if (error && (!('code' in error) || typeof error.code !== 'number')) {
|
|
112
|
+
reject(new SegmentError('STANDARD_RETRIEVE_UNKNOWN'));
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
resolve({ exitCode: error ? Number(error.code) : 0, stdout });
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BoundSsot } from './bound-ssot.js';
|
|
2
|
+
import type { NativeRelationshipSpec } from '../artifacts/native-relationship-document.js';
|
|
3
|
+
/** Proven page size; `nextPageUrl` repeats the current offset, so callers page by offset. */
|
|
4
|
+
export declare const relationshipPageSize = 200;
|
|
5
|
+
export type RelationshipClient = {
|
|
6
|
+
readonly apiVersion: string;
|
|
7
|
+
/** One page of every relationship the DMO is source or target of; undefined for 204. */
|
|
8
|
+
list: (dmoName: string, offset: number) => Promise<unknown>;
|
|
9
|
+
/** One POST creating exactly one relationship on its source DMO; never resent once sent. */
|
|
10
|
+
create: (relationship: NativeRelationshipSpec) => Promise<unknown>;
|
|
11
|
+
/** One DELETE by exact relationship name; never retried. */
|
|
12
|
+
remove: (relationshipName: string) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Metadata API records (`FieldSrcTrgtRelationship`) by exact name, on the bound Connection;
|
|
15
|
+
* a name Salesforce returns no record for is left out. Absent without a bound sender.
|
|
16
|
+
*/
|
|
17
|
+
readDefinitions?: (names: string[]) => Promise<Array<Record<string, unknown>>>;
|
|
18
|
+
/** One Metadata API `updateMetadata` of a whole record on the bound Connection; never retried. */
|
|
19
|
+
update?: (definition: Record<string, unknown>) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
/** Metadata API type of a Data Cloud relationship; the record name is the relationship name. */
|
|
22
|
+
export declare const relationshipMetadataType = "FieldSrcTrgtRelationship";
|
|
23
|
+
/** Names per Metadata API read call (the API's limit). */
|
|
24
|
+
export declare const relationshipReadBatch = 10;
|
|
25
|
+
/**
|
|
26
|
+
* Whether an update refusal was Salesforce's generic "An unexpected error occurred" answer
|
|
27
|
+
* (UNKNOWN_EXCEPTION). Salesforce gives it both for a change it refuses and, now and then, for a
|
|
28
|
+
* valid change that succeeds when sent again (live, API 68).
|
|
29
|
+
* @param {unknown} error Failure of `update`.
|
|
30
|
+
* @returns {boolean} The generic unexpected-error refusal.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isUnexpectedUpdateRefusal(error: unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Build a native relationship client on the bound in-process connection; the POST and DELETE
|
|
35
|
+
* are never resent once they may have reached Salesforce.
|
|
36
|
+
* @param {string} targetOrg Explicit authenticated alias or username.
|
|
37
|
+
* @param {string} apiVersion Validated numeric version, or default/auto 68.0.
|
|
38
|
+
* @param {string} dataSpace The run's data space, sent as `?dataspace=` on every REST request
|
|
39
|
+
* (the Metadata API calls take record names, which are unique in the org).
|
|
40
|
+
* @param {BoundSsot} [sender] The command's shared sender; defaults to one opened for targetOrg.
|
|
41
|
+
* @returns {RelationshipClient} Raw operations.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createRelationshipClient(targetOrg: string, apiVersion: string | undefined, dataSpace: string, sender?: BoundSsot): RelationshipClient;
|