sf-plugin-data 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +572 -240
- package/docs/artifact-format.md +527 -633
- package/docs/capabilities.md +1159 -168
- package/docs/git-workflow.md +135 -12
- package/docs/handover.md +7826 -12
- package/lib/api.d.ts +7 -0
- package/lib/api.js +7 -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 +2297 -0
- package/lib/commands/data360/deploy.d.ts +234 -15
- package/lib/commands/data360/deploy.js +2292 -100
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +292 -0
- package/lib/commands/data360/retrieve.d.ts +260 -13
- package/lib/commands/data360/retrieve.js +1880 -85
- package/lib/commands/data360/segment/members/export.d.ts +101 -0
- package/lib/commands/data360/segment/members/export.js +318 -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 +57 -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/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 +36 -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 +89 -0
- package/lib/services/data-space-check.js +162 -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/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/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,135 @@
|
|
|
1
|
+
import { DloError, dloName } from '../artifacts/dlo-document.js';
|
|
2
|
+
import { isDataSpaceName } from '../artifacts/data-space-field.js';
|
|
3
|
+
import { openBoundSsot } from './bound-ssot.js';
|
|
4
|
+
import { dloFailure } from './dlo-native-rest.js';
|
|
5
|
+
import { nativeApiVersion } from './api-version.js';
|
|
6
|
+
const recordId = /^[A-Za-z0-9]{18}$/u;
|
|
7
|
+
// The data space member routes, proven live on API 68 only (DB entry
|
|
8
|
+
// data360:dlo-dataspace-membership-20261118.api68), whatever version the DLO routes use.
|
|
9
|
+
const dataSpacesEndpoint = '/services/data/v68.0/ssot/data-spaces';
|
|
10
|
+
/**
|
|
11
|
+
* Build a minimal API68 client on the bound in-process connection. Writes are never resent
|
|
12
|
+
* after they may have reached Salesforce; only an actual HTTP 404 indicates absence.
|
|
13
|
+
* @param {string} targetOrg Explicit authenticated org alias or username.
|
|
14
|
+
* @param {string} apiVersion Numeric >=61 or default/auto 68; admission is not live qualification.
|
|
15
|
+
* @param {BoundSsot} [sender] The command's shared sender; defaults to one opened for targetOrg.
|
|
16
|
+
* @param {ReadonlyMap<string, unknown>} [listed] Entries of this run's DLO listing at the same
|
|
17
|
+
* version, by name. A listed name's GET answers with its entry in the item GET's envelope,
|
|
18
|
+
* which Salesforce returns byte for byte the same, instead of another request.
|
|
19
|
+
* @returns {DloClient} Four operations; the caller's read-back decides what a write did.
|
|
20
|
+
*/
|
|
21
|
+
export function createDloClient(targetOrg, apiVersion = '68.0', sender, listed) {
|
|
22
|
+
const version = nativeApiVersion(apiVersion);
|
|
23
|
+
const endpoint = `/services/data/v${version}/ssot/data-lake-objects`;
|
|
24
|
+
if (!targetOrg ||
|
|
25
|
+
targetOrg.startsWith('-') ||
|
|
26
|
+
[...targetOrg].some((character) => character.codePointAt(0) < 32))
|
|
27
|
+
throw new DloError('UNSUPPORTED_DLO_SELECTION');
|
|
28
|
+
const bound = sender ?? openBoundSsot(targetOrg, version);
|
|
29
|
+
/**
|
|
30
|
+
* Send one request on the bound connection, mapping failures to DLO codes.
|
|
31
|
+
* @param {'GET' | 'POST' | 'PATCH' | 'DELETE'} method HTTP operation.
|
|
32
|
+
* @param {string} suffix Validated exact name/ID suffix.
|
|
33
|
+
* @param {Record<string, unknown>} [body] Write definition.
|
|
34
|
+
* @returns {Promise<unknown>} Parsed non-array object, or nothing for a DELETE (HTTP 204).
|
|
35
|
+
*/
|
|
36
|
+
async function request(method, suffix, body) {
|
|
37
|
+
const noContent = Symbol('dlo-no-content');
|
|
38
|
+
let response;
|
|
39
|
+
try {
|
|
40
|
+
response = await bound.request(method, endpoint + suffix, noContent, body);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw dloFailure(error);
|
|
44
|
+
}
|
|
45
|
+
if (method === 'DELETE') {
|
|
46
|
+
if (response !== noContent)
|
|
47
|
+
throw new DloError('DLO_DELETE_UNCONFIRMED');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (response === noContent)
|
|
51
|
+
throw new DloError('DLO_REQUEST_UNCONFIRMED', 204);
|
|
52
|
+
if (typeof response !== 'object' || response === null || Array.isArray(response))
|
|
53
|
+
throw new DloError('INVALID_DLO_RESPONSE');
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validate exact runtime target identity before mutating it.
|
|
58
|
+
* @param {string} id Target-resolved record ID.
|
|
59
|
+
* @returns {string} Safe URL suffix.
|
|
60
|
+
*/
|
|
61
|
+
function idSuffix(id) {
|
|
62
|
+
if (!recordId.test(id))
|
|
63
|
+
throw new DloError('INVALID_DLO_TARGET_ID');
|
|
64
|
+
return `/${id}`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Send one data space member request; its answer is an object (also for the DELETE).
|
|
68
|
+
* @param {'GET' | 'PUT' | 'DELETE'} method HTTP operation.
|
|
69
|
+
* @param {string} suffix Route below /ssot/data-spaces.
|
|
70
|
+
* @param {Record<string, unknown>} [body] PUT body.
|
|
71
|
+
* @returns {Promise<unknown>} Parsed object.
|
|
72
|
+
*/
|
|
73
|
+
async function member(method, suffix, body) {
|
|
74
|
+
let response;
|
|
75
|
+
try {
|
|
76
|
+
response = await bound.request(method, dataSpacesEndpoint + suffix, undefined, body);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw dloFailure(error);
|
|
80
|
+
}
|
|
81
|
+
if (typeof response !== 'object' || response === null || Array.isArray(response))
|
|
82
|
+
throw new DloError('INVALID_DLO_RESPONSE');
|
|
83
|
+
return response;
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
get: async (apiName) => {
|
|
87
|
+
if (!dloName.test(apiName))
|
|
88
|
+
throw new DloError('INVALID_DLO_NAME');
|
|
89
|
+
const entry = listed?.get(apiName);
|
|
90
|
+
if (entry !== undefined)
|
|
91
|
+
return { dataLakeObjects: [structuredClone(entry)] };
|
|
92
|
+
return request('GET', `/${apiName}`);
|
|
93
|
+
},
|
|
94
|
+
create: async (body) => request('POST', '', body),
|
|
95
|
+
update: async (id, body) => request('PATCH', idSuffix(id), body),
|
|
96
|
+
delete: async (id) => {
|
|
97
|
+
await request('DELETE', idSuffix(id));
|
|
98
|
+
},
|
|
99
|
+
putMembers: async (dataSpace, memberNames) => {
|
|
100
|
+
if (memberNames.length === 0 || memberNames.some((name) => !dloName.test(name)))
|
|
101
|
+
throw new DloError('INVALID_DLO_NAME');
|
|
102
|
+
const answer = await member('PUT', `/${spaceSegment(dataSpace)}/members`, {
|
|
103
|
+
members: { members: memberNames.map((memberName) => ({ memberName })) },
|
|
104
|
+
});
|
|
105
|
+
// Live API 68 answers {success: "true", errors: []}; anything else is Salesforce's refusal.
|
|
106
|
+
const { success, errors } = answer;
|
|
107
|
+
if (!(success === true || success === 'true') ||
|
|
108
|
+
(errors !== undefined && !(Array.isArray(errors) && errors.length === 0)))
|
|
109
|
+
throw new DloError('DLO_MEMBERSHIP_UPDATE_REJECTED');
|
|
110
|
+
return answer;
|
|
111
|
+
},
|
|
112
|
+
removeMember: async (dataSpace, memberName) => {
|
|
113
|
+
if (!dloName.test(memberName))
|
|
114
|
+
throw new DloError('INVALID_DLO_NAME');
|
|
115
|
+
const answer = await member('DELETE', `/${spaceSegment(dataSpace)}/members?memberNames=${encodeURIComponent(memberName)}`);
|
|
116
|
+
// Live API 68 answers {results: [{dataSpaceMemberName, errors: {}, success: true}]}.
|
|
117
|
+
const results = answer.results;
|
|
118
|
+
if (!Array.isArray(results) ||
|
|
119
|
+
results.length === 0 ||
|
|
120
|
+
results.some((result) => result?.success !== true))
|
|
121
|
+
throw new DloError('DLO_MEMBERSHIP_UPDATE_REJECTED');
|
|
122
|
+
return answer;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A data space name as one URL path segment.
|
|
128
|
+
* @param {string} dataSpace Data space name.
|
|
129
|
+
* @returns {string} Encoded segment.
|
|
130
|
+
*/
|
|
131
|
+
function spaceSegment(dataSpace) {
|
|
132
|
+
if (!isDataSpaceName(dataSpace))
|
|
133
|
+
throw new DloError('UNSUPPORTED_DLO_DATASPACE');
|
|
134
|
+
return encodeURIComponent(dataSpace);
|
|
135
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BoundConnection } from './bound-ssot.js';
|
|
2
|
+
import type { DmoClient } from './dmo-rest.js';
|
|
3
|
+
export type DmoDeleteClient = Pick<DmoClient, 'get' | 'delete'>;
|
|
4
|
+
/**
|
|
5
|
+
* Map transport failures to DMO codes while keeping the safe API diagnostic.
|
|
6
|
+
* Any GET 404 means absent, matching the child adapter and the DLO delete path.
|
|
7
|
+
* @param {unknown} error Transport failure.
|
|
8
|
+
* @returns {unknown} NativeDmoError with retained diagnostic, or the original error.
|
|
9
|
+
*/
|
|
10
|
+
export declare function dmoFailure(error: unknown): unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Bind DMO delete reads and the exact-name DELETE to one authenticated Connection.
|
|
13
|
+
* @param {string} targetOrg Resolved username of the target org.
|
|
14
|
+
* @param {string} apiVersion Native API version (default/auto 68).
|
|
15
|
+
* @param {BoundConnection} [connect] Supplies the authenticated Connection; tests inject a synthetic one.
|
|
16
|
+
* @returns {DmoDeleteClient} Name GET and name DELETE, each sent at most once.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createNativeDmoDeleteClient(targetOrg: string, apiVersion?: string, connect?: BoundConnection): DmoDeleteClient;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { openBoundSsot } from './bound-ssot.js';
|
|
2
|
+
import { ConnectError } from './connect-client.js';
|
|
3
|
+
import { getConnectDiagnostic, retainConnectDiagnostic } from './connect-diagnostic.js';
|
|
4
|
+
import { NativeDmoError, nativeDmoName } from '../artifacts/native-dmo-document.js';
|
|
5
|
+
import { nativeApiVersion } from './api-version.js';
|
|
6
|
+
/**
|
|
7
|
+
* Map transport failures to DMO codes while keeping the safe API diagnostic.
|
|
8
|
+
* Any GET 404 means absent, matching the child adapter and the DLO delete path.
|
|
9
|
+
* @param {unknown} error Transport failure.
|
|
10
|
+
* @returns {unknown} NativeDmoError with retained diagnostic, or the original error.
|
|
11
|
+
*/
|
|
12
|
+
export function dmoFailure(error) {
|
|
13
|
+
if (!(error instanceof ConnectError))
|
|
14
|
+
return error;
|
|
15
|
+
const status = error.code === 'AUTHENTICATION_FAILED' ? 401 : error.statusCode;
|
|
16
|
+
return retainConnectDiagnostic(new NativeDmoError(status === undefined ? 'DMO_REQUEST_UNCONFIRMED' : 'DMO_HTTP_ERROR', status), getConnectDiagnostic(error));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Bind DMO delete reads and the exact-name DELETE to one authenticated Connection.
|
|
20
|
+
* @param {string} targetOrg Resolved username of the target org.
|
|
21
|
+
* @param {string} apiVersion Native API version (default/auto 68).
|
|
22
|
+
* @param {BoundConnection} [connect] Supplies the authenticated Connection; tests inject a synthetic one.
|
|
23
|
+
* @returns {DmoDeleteClient} Name GET and name DELETE, each sent at most once.
|
|
24
|
+
*/
|
|
25
|
+
export function createNativeDmoDeleteClient(targetOrg, apiVersion = '68.0', connect) {
|
|
26
|
+
const version = nativeApiVersion(apiVersion);
|
|
27
|
+
const endpoint = `/services/data/v${version}/ssot/data-model-objects`;
|
|
28
|
+
const ssot = openBoundSsot(targetOrg, version, connect);
|
|
29
|
+
return {
|
|
30
|
+
get: async (apiName) => {
|
|
31
|
+
if (!nativeDmoName.test(apiName))
|
|
32
|
+
throw new NativeDmoError('INVALID_DMO_NAME');
|
|
33
|
+
try {
|
|
34
|
+
return await ssot.request('GET', `${endpoint}/${apiName}`);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
throw dmoFailure(error);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
delete: async (apiName) => {
|
|
41
|
+
if (!nativeDmoName.test(apiName))
|
|
42
|
+
throw new NativeDmoError('INVALID_DMO_NAME');
|
|
43
|
+
const noContent = Symbol('dmo-deleted');
|
|
44
|
+
let response;
|
|
45
|
+
try {
|
|
46
|
+
response = await ssot.request('DELETE', `${endpoint}/${apiName}`, noContent);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw dmoFailure(error);
|
|
50
|
+
}
|
|
51
|
+
if (response !== noContent)
|
|
52
|
+
throw new NativeDmoError('DMO_DELETE_UNCONFIRMED');
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MetadataRunner } from './project-metadata.js';
|
|
2
|
+
import type { BoundSsot } from './bound-ssot.js';
|
|
3
|
+
export type DmoClient = {
|
|
4
|
+
get: (apiName: string) => Promise<unknown>;
|
|
5
|
+
create: (body: Record<string, unknown>) => Promise<unknown>;
|
|
6
|
+
update: (targetApiName: string, body: Record<string, unknown>) => Promise<unknown>;
|
|
7
|
+
delete: (targetApiName: string) => Promise<void>;
|
|
8
|
+
/** One Metadata API destructive deployment; absent on clients without a Metadata route. */
|
|
9
|
+
removeFields?: (targetApiName: string, fieldNames: string[]) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Render a Metadata API package manifest from already validated content lines.
|
|
13
|
+
* @param {string} version Numeric API version.
|
|
14
|
+
* @param {string[]} lines Indented type entries; empty for the required empty package.xml.
|
|
15
|
+
* @returns {string} Manifest XML ending with LF.
|
|
16
|
+
*/
|
|
17
|
+
export declare function manifest(version: string, lines: string[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Build a native client on the bound in-process connection; writes are never resent after they
|
|
20
|
+
* may have reached Salesforce.
|
|
21
|
+
* @param {string} targetOrg Explicit authenticated alias or username.
|
|
22
|
+
* @param {string} apiVersion Numeric >=61 or default/auto 68; admission is not live qualification.
|
|
23
|
+
* @param {MetadataRunner} runner Installed CLI runner, used only for the destructive field removal.
|
|
24
|
+
* @param {BoundSsot} [sender] The command's shared sender; defaults to one opened for targetOrg.
|
|
25
|
+
* @param {ReadonlyMap<string, unknown>} [listed] Entries of this run's DMO listing at the same
|
|
26
|
+
* version, by name. A listed name's GET answers with its entry, which Salesforce returns byte for
|
|
27
|
+
* byte the same as the item GET, instead of another request.
|
|
28
|
+
* @returns {DmoClient} Name-bound operations; field-removal scratch is retained.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createDmoClient(targetOrg: string, apiVersion?: string, runner?: MetadataRunner, sender?: BoundSsot, listed?: ReadonlyMap<string, unknown>): DmoClient;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { mkdtemp, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { retainMetadataProblems } from './connect-diagnostic.js';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { NativeDmoError, nativeDmoFieldName, nativeDmoName, } from '../artifacts/native-dmo-document.js';
|
|
6
|
+
import { runProjectMetadata, verifyTemporaryDirectory } from './project-metadata.js';
|
|
7
|
+
import { openBoundSsot } from './bound-ssot.js';
|
|
8
|
+
import { dmoFailure } from './dmo-native-rest.js';
|
|
9
|
+
import { nativeApiVersion } from './api-version.js';
|
|
10
|
+
/**
|
|
11
|
+
* Render a Metadata API package manifest from already validated content lines.
|
|
12
|
+
* @param {string} version Numeric API version.
|
|
13
|
+
* @param {string[]} lines Indented type entries; empty for the required empty package.xml.
|
|
14
|
+
* @returns {string} Manifest XML ending with LF.
|
|
15
|
+
*/
|
|
16
|
+
export function manifest(version, lines) {
|
|
17
|
+
return [
|
|
18
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
19
|
+
'<Package xmlns="http://soap.sforce.com/2006/04/metadata">',
|
|
20
|
+
...lines,
|
|
21
|
+
` <version>${version}</version>`,
|
|
22
|
+
'</Package>',
|
|
23
|
+
'',
|
|
24
|
+
].join('\n');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build a native client on the bound in-process connection; writes are never resent after they
|
|
28
|
+
* may have reached Salesforce.
|
|
29
|
+
* @param {string} targetOrg Explicit authenticated alias or username.
|
|
30
|
+
* @param {string} apiVersion Numeric >=61 or default/auto 68; admission is not live qualification.
|
|
31
|
+
* @param {MetadataRunner} runner Installed CLI runner, used only for the destructive field removal.
|
|
32
|
+
* @param {BoundSsot} [sender] The command's shared sender; defaults to one opened for targetOrg.
|
|
33
|
+
* @param {ReadonlyMap<string, unknown>} [listed] Entries of this run's DMO listing at the same
|
|
34
|
+
* version, by name. A listed name's GET answers with its entry, which Salesforce returns byte for
|
|
35
|
+
* byte the same as the item GET, instead of another request.
|
|
36
|
+
* @returns {DmoClient} Name-bound operations; field-removal scratch is retained.
|
|
37
|
+
*/
|
|
38
|
+
export function createDmoClient(targetOrg, apiVersion = '68.0', runner = runProjectMetadata, sender, listed) {
|
|
39
|
+
const version = nativeApiVersion(apiVersion);
|
|
40
|
+
const endpoint = `/services/data/v${version}/ssot/data-model-objects`;
|
|
41
|
+
if (!targetOrg ||
|
|
42
|
+
targetOrg.startsWith('-') ||
|
|
43
|
+
[...targetOrg].some((character) => character.codePointAt(0) < 32))
|
|
44
|
+
throw new NativeDmoError('UNSUPPORTED_DMO_SELECTION');
|
|
45
|
+
const bound = sender ?? openBoundSsot(targetOrg, version);
|
|
46
|
+
/**
|
|
47
|
+
* Validate a full API name, never a resource ID.
|
|
48
|
+
* @param {string} apiName Exact full DMO name.
|
|
49
|
+
* @returns {string} Safe URL suffix.
|
|
50
|
+
*/
|
|
51
|
+
function nameSuffix(apiName) {
|
|
52
|
+
if (!nativeDmoName.test(apiName))
|
|
53
|
+
throw new NativeDmoError('INVALID_DMO_NAME');
|
|
54
|
+
return `/${apiName}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Send one request on the bound connection, mapping failures to DMO codes. A write is never
|
|
58
|
+
* resent once it may have reached Salesforce; the caller's read-back decides what it did.
|
|
59
|
+
* @param {'GET' | 'POST' | 'PATCH' | 'DELETE'} method HTTP verb.
|
|
60
|
+
* @param {string} suffix Validated exact name suffix.
|
|
61
|
+
* @param {Record<string, unknown>} [body] Native input.
|
|
62
|
+
* @returns {Promise<unknown>} Parsed non-array object, or nothing for a DELETE (HTTP 204).
|
|
63
|
+
*/
|
|
64
|
+
async function request(method, suffix, body) {
|
|
65
|
+
const noContent = Symbol('dmo-no-content');
|
|
66
|
+
let response;
|
|
67
|
+
try {
|
|
68
|
+
response = await bound.request(method, endpoint + suffix, noContent, body);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw dmoFailure(error);
|
|
72
|
+
}
|
|
73
|
+
if (method === 'DELETE') {
|
|
74
|
+
if (response !== noContent)
|
|
75
|
+
throw new NativeDmoError('DMO_DELETE_UNCONFIRMED');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (response === noContent)
|
|
79
|
+
throw new NativeDmoError('DMO_REQUEST_UNCONFIRMED', 204);
|
|
80
|
+
if (typeof response !== 'object' || response === null || Array.isArray(response))
|
|
81
|
+
throw new NativeDmoError('INVALID_DMO_RESPONSE');
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Remove custom fields with one Metadata API destructive deployment; never retried.
|
|
86
|
+
* This is the one DMO write left on the child `sf project deploy start` runner: the bound
|
|
87
|
+
* connection has no deploy-and-poll route yet, and the user chose to keep it here for now.
|
|
88
|
+
* @param {string} targetApiName Exact full DMO name.
|
|
89
|
+
* @param {string[]} fieldNames Exact field names ending in __c.
|
|
90
|
+
* @returns {Promise<void>} Resolves only when every member is reported deleted.
|
|
91
|
+
*/
|
|
92
|
+
async function removeFields(targetApiName, fieldNames) {
|
|
93
|
+
if (!nativeDmoName.test(targetApiName))
|
|
94
|
+
throw new NativeDmoError('INVALID_DMO_NAME');
|
|
95
|
+
if (fieldNames.length === 0 ||
|
|
96
|
+
new Set(fieldNames).size !== fieldNames.length ||
|
|
97
|
+
fieldNames.some((name) => typeof name !== 'string' || !nativeDmoFieldName.test(name)))
|
|
98
|
+
throw new NativeDmoError('INVALID_DMO_FIELD');
|
|
99
|
+
// Only names that matched the identifier patterns above reach the XML.
|
|
100
|
+
const members = fieldNames.map((name) => `${targetApiName}.${name}`);
|
|
101
|
+
verifyTemporaryDirectory();
|
|
102
|
+
const root = await mkdtemp(path.join(os.tmpdir(), 'data360-dmo-field-removal-'));
|
|
103
|
+
await writeFile(path.join(root, 'package.xml'), manifest(version, []), { flag: 'wx' });
|
|
104
|
+
await writeFile(path.join(root, 'destructiveChanges.xml'), manifest(version, [
|
|
105
|
+
' <types>',
|
|
106
|
+
...members.map((member) => ` <members>${member}</members>`),
|
|
107
|
+
' <name>CustomField</name>',
|
|
108
|
+
' </types>',
|
|
109
|
+
]), { flag: 'wx' });
|
|
110
|
+
const receipt = await runner([
|
|
111
|
+
'project',
|
|
112
|
+
'deploy',
|
|
113
|
+
'start',
|
|
114
|
+
'--metadata-dir',
|
|
115
|
+
root,
|
|
116
|
+
'--target-org',
|
|
117
|
+
targetOrg,
|
|
118
|
+
'--wait',
|
|
119
|
+
'10',
|
|
120
|
+
'--json',
|
|
121
|
+
], root);
|
|
122
|
+
let envelope = {};
|
|
123
|
+
try {
|
|
124
|
+
const parsed = JSON.parse(receipt.stdout);
|
|
125
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
126
|
+
envelope = parsed;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
/* An unreadable receipt confirms nothing. */
|
|
130
|
+
}
|
|
131
|
+
const result = envelope.result && typeof envelope.result === 'object' ? envelope.result : undefined;
|
|
132
|
+
const details = result?.details && typeof result.details === 'object'
|
|
133
|
+
? result.details
|
|
134
|
+
: {};
|
|
135
|
+
const list = (value) => (Array.isArray(value) ? value : [value]).filter((entry) => Boolean(entry) && typeof entry === 'object');
|
|
136
|
+
const successes = list(details.componentSuccesses);
|
|
137
|
+
if (receipt.exitCode === 0 &&
|
|
138
|
+
envelope.status === 0 &&
|
|
139
|
+
result?.success === true &&
|
|
140
|
+
result.status === 'Succeeded' &&
|
|
141
|
+
members.every((member) => successes.some((entry) => entry.fullName === member &&
|
|
142
|
+
entry.componentType === 'CustomField' &&
|
|
143
|
+
entry.deleted === true)))
|
|
144
|
+
return;
|
|
145
|
+
const failures = list(details.componentFailures);
|
|
146
|
+
// A deployment Salesforce reports Failed with component failures applied nothing.
|
|
147
|
+
const rejected = result?.status === 'Failed' && result.success === false && failures.length > 0;
|
|
148
|
+
throw retainMetadataProblems(new NativeDmoError('DMO_FIELD_REMOVAL_FAILED', undefined, rejected ? true : undefined), [...failures.map((failure) => failure.problem), result?.errorMessage, envelope.message]);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
removeFields,
|
|
152
|
+
get: async (apiName) => {
|
|
153
|
+
const suffix = nameSuffix(apiName);
|
|
154
|
+
const entry = listed?.get(apiName);
|
|
155
|
+
return entry === undefined ? request('GET', suffix) : structuredClone(entry);
|
|
156
|
+
},
|
|
157
|
+
create: async (body) => request('POST', '', body),
|
|
158
|
+
update: async (targetApiName, body) => request('PATCH', nameSuffix(targetApiName), body),
|
|
159
|
+
delete: async (targetApiName) => {
|
|
160
|
+
await request('DELETE', nameSuffix(targetApiName));
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Connection } from '@salesforce/core';
|
|
2
|
+
import type { MetadataRunner } from './project-metadata.js';
|
|
3
|
+
import type { BoundSsot } from './bound-ssot.js';
|
|
4
|
+
export type MappingWriteBody = {
|
|
5
|
+
sourceEntityDeveloperName: string;
|
|
6
|
+
targetEntityDeveloperName: string;
|
|
7
|
+
fieldMapping: {
|
|
8
|
+
sourceFieldDeveloperName: string;
|
|
9
|
+
targetFieldDeveloperName: string;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export type MappingClient = {
|
|
13
|
+
readonly apiVersion: string;
|
|
14
|
+
deleteField: (mappingDeveloperName: string, observedSelector: string) => Promise<void>;
|
|
15
|
+
list: (dmoDeveloperName: string, dloDeveloperName?: string) => Promise<unknown>;
|
|
16
|
+
get: (mappingDeveloperName: string) => Promise<unknown>;
|
|
17
|
+
create: (body: MappingWriteBody) => Promise<unknown>;
|
|
18
|
+
update: (mappingDeveloperName: string, body: MappingWriteBody) => Promise<unknown>;
|
|
19
|
+
/** One Metadata API destructive deployment of the whole mapping; never retried. */
|
|
20
|
+
remove: (mappingDeveloperName: string) => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Metadata API records (`ObjectSourceTargetMap`) by exact name, up to 10 names per read, on
|
|
23
|
+
* the bound Connection; a name without a record is left out. Absent without a Metadata API.
|
|
24
|
+
*/
|
|
25
|
+
readDefinitions?: (names: string[]) => Promise<Array<Record<string, unknown>>>;
|
|
26
|
+
/** One Metadata API `updateMetadata` of a whole record on the bound Connection; never retried. */
|
|
27
|
+
updateDefinition?: (definition: Record<string, unknown>) => Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
/** Metadata API type of a mapping; the record name is the mapping name. */
|
|
30
|
+
export declare const mappingMetadataType = "ObjectSourceTargetMap";
|
|
31
|
+
/** Names per Metadata API read call (the API's limit). */
|
|
32
|
+
export declare const mappingReadBatch = 10;
|
|
33
|
+
/**
|
|
34
|
+
* A Metadata API answer as a list of records.
|
|
35
|
+
* @param {unknown} value One record or several.
|
|
36
|
+
* @returns {unknown[]} Records.
|
|
37
|
+
*/
|
|
38
|
+
export declare function metadataRecords(value: unknown): unknown[];
|
|
39
|
+
/**
|
|
40
|
+
* Read filtered mapping inventories on the existing command-owned connection.
|
|
41
|
+
* Only an explicit transport 404 is the typed no-map condition; other failures propagate.
|
|
42
|
+
* @param {Pick<Connection, 'instanceUrl' | 'request'>} connection Authenticated command connection.
|
|
43
|
+
* @param {string} apiVersion Admitted numeric native version.
|
|
44
|
+
* @param {string} dataSpace The run's data space, sent as `?dataspace=` on every list.
|
|
45
|
+
* @returns {Pick<MappingClient, 'list'>} List-only reader without CLI startup or scratch files.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createMappingInventoryReader(connection: Pick<Connection, 'instanceUrl' | 'request'>, apiVersion: string, dataSpace: string): Pick<MappingClient, 'list'>;
|
|
48
|
+
/**
|
|
49
|
+
* Build a native client on the bound in-process connection. Numeric admission is not
|
|
50
|
+
* live-version qualification.
|
|
51
|
+
* The caller owns target pair resolution; additions send names only, without a field selector.
|
|
52
|
+
* @param {string} targetOrg Explicit authenticated alias or username.
|
|
53
|
+
* @param {string} apiVersion Validated numeric version, or default/auto 68.0.
|
|
54
|
+
* @param {MetadataRunner} runner Installed CLI runner, used only for the destructive `remove`.
|
|
55
|
+
* @param {string} dataSpace The run's data space, sent as `?dataspace=` on every mapping request
|
|
56
|
+
* except the Metadata API calls (their record names are unique in the org).
|
|
57
|
+
* @param {BoundSsot} [sender] The command's shared sender; defaults to one opened for targetOrg.
|
|
58
|
+
* @param {ReadonlyMap<string, unknown>} [listed] Entries of this run's mapping lists at the same
|
|
59
|
+
* version and data space, by name. A listed name's GET answers with a copy of its entry, which
|
|
60
|
+
* Salesforce returns byte for byte the same, instead of another request.
|
|
61
|
+
* @returns {MappingClient} Raw operations; `remove` scratch is retained.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createMappingClient(targetOrg: string, apiVersion: string | undefined, runner: MetadataRunner | undefined, dataSpace: string, sender?: BoundSsot, listed?: ReadonlyMap<string, unknown>): MappingClient;
|