sf-plugin-data 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +589 -2
- package/bin/run.js +4 -0
- package/docs/artifact-format.md +527 -0
- package/docs/capabilities.md +1208 -0
- package/docs/git-workflow.md +160 -0
- package/docs/handover.md +10446 -0
- 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 +239 -0
- package/lib/artifacts/read-deploy-input.js +1359 -0
- 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 +303 -0
- package/lib/commands/data360/deploy.js +2400 -0
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +292 -0
- package/lib/commands/data360/retrieve.d.ts +322 -0
- package/lib/commands/data360/retrieve.js +1963 -0
- 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 +5 -0
- package/lib/plugin.js +5 -0
- 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 +129 -0
- package/lib/transport/connect-client.js +446 -0
- 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 +96 -4
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Connection } from '@salesforce/core';
|
|
2
|
+
import type { ApiVersionSelection } from '../transport/api-version.js';
|
|
3
|
+
import type { DependencyIdentity } from '../artifacts/dependency-selection.js';
|
|
4
|
+
import type { NativeDmoDocument } from '../artifacts/native-dmo-document.js';
|
|
5
|
+
import type { SegmentAcquisition } from './retrieve-segment.js';
|
|
6
|
+
import { retrieveSegment } from './retrieve-segment.js';
|
|
7
|
+
import { bindSegmentDependencies } from './bind-segment-dependencies.js';
|
|
8
|
+
import type { VerbatimDocument } from '../artifacts/verbatim-document.js';
|
|
9
|
+
/** Payload-free refusal retaining the affected selected identity. */
|
|
10
|
+
export declare class RetrieveSelectionError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly identity: DependencyIdentity;
|
|
13
|
+
constructor(code: string, identity: DependencyIdentity);
|
|
14
|
+
}
|
|
15
|
+
export type RetrieveServices = {
|
|
16
|
+
segment: typeof retrieveSegment;
|
|
17
|
+
/** One raw native read of an exact DMO, at the native API version rather than the Segment's. */
|
|
18
|
+
dmo: (apiName: string) => Promise<unknown>;
|
|
19
|
+
bind: typeof bindSegmentDependencies;
|
|
20
|
+
raw: (name: string) => Promise<unknown>;
|
|
21
|
+
};
|
|
22
|
+
export type RetrieveSelectionEntry = {
|
|
23
|
+
document: NativeDmoDocument;
|
|
24
|
+
} | {
|
|
25
|
+
document: NonNullable<SegmentAcquisition['candidate']>;
|
|
26
|
+
} | {
|
|
27
|
+
document: VerbatimDocument;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Acquire exactly the selected DMOs and Segments and check each Segment's source references.
|
|
31
|
+
* Referenced components are validated, never added to the selection or published.
|
|
32
|
+
* The connection and existing family services retain their transport/version/output admission.
|
|
33
|
+
* @param {DependencyIdentity[]} selected Explicit exact identities (inventory already resolved by caller).
|
|
34
|
+
* @param {Connection} connection Command-owned source connection.
|
|
35
|
+
* @param {ApiVersionSelection} version Resolved API selection for Segment reads.
|
|
36
|
+
* @param {object} [injected] Service overrides; the command supplies its native DMO read.
|
|
37
|
+
* @param {Function} [onFailure] Receives each component that could not be acquired; the others
|
|
38
|
+
* are still acquired. Without it, the first failure is thrown.
|
|
39
|
+
* @param {Function} [onWarning] Receives a warning for each Segment whose DMO could not be bound;
|
|
40
|
+
* the Segment is still retrieved (retrieve checks prerequisites, it never refuses on them).
|
|
41
|
+
* @returns {Promise<RetrieveSelectionEntry[]>} Acquired selection, referenced DMOs first.
|
|
42
|
+
*/
|
|
43
|
+
export declare function acquireRetrieveSelection(selected: DependencyIdentity[], connection: Connection, version: ApiVersionSelection, injected?: Partial<RetrieveServices>, onFailure?: (error: RetrieveSelectionError) => void, onWarning?: (message: string) => void): Promise<RetrieveSelectionEntry[]>;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { nativeApiVersion } from '../transport/api-version.js';
|
|
2
|
+
import { dependencyKey, DependencySelectionError, documentDependencyNode, orderDependencyNodes, } from '../artifacts/dependency-selection.js';
|
|
3
|
+
import { NativeDmoError } from '../artifacts/native-dmo-document.js';
|
|
4
|
+
import { SegmentError } from '../artifacts/segment-document.js';
|
|
5
|
+
import { retrieveSegment } from './retrieve-segment.js';
|
|
6
|
+
import { retrieveNativeDmo } from './native-dmo.js';
|
|
7
|
+
import { bindSegmentDependencies } from './bind-segment-dependencies.js';
|
|
8
|
+
import { explainInput } from './operation-diagnostic.js';
|
|
9
|
+
import { ConnectClient } from '../transport/connect-client.js';
|
|
10
|
+
import { createDmoClient } from '../transport/dmo-rest.js';
|
|
11
|
+
import { openBoundSsot } from '../transport/bound-ssot.js';
|
|
12
|
+
import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
|
|
13
|
+
import { carriedNativeResponse, carryNativeResponse, createVerbatimDocument, verbatimReason, } from '../artifacts/verbatim-document.js';
|
|
14
|
+
/** Payload-free refusal retaining the affected selected identity. */
|
|
15
|
+
export class RetrieveSelectionError extends Error {
|
|
16
|
+
code;
|
|
17
|
+
identity;
|
|
18
|
+
constructor(code, identity) {
|
|
19
|
+
super('A selected component could not be acquired completely; it was not retrieved.');
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.identity = identity;
|
|
22
|
+
this.name = 'RetrieveSelectionError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Retrieve writes files and provisions nothing: no node, edge or request cap (deploy keeps its).
|
|
26
|
+
const unbounded = Object.freeze({
|
|
27
|
+
nodes: Number.POSITIVE_INFINITY,
|
|
28
|
+
edges: Number.POSITIVE_INFINITY,
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Acquire exactly the selected DMOs and Segments and check each Segment's source references.
|
|
32
|
+
* Referenced components are validated, never added to the selection or published.
|
|
33
|
+
* The connection and existing family services retain their transport/version/output admission.
|
|
34
|
+
* @param {DependencyIdentity[]} selected Explicit exact identities (inventory already resolved by caller).
|
|
35
|
+
* @param {Connection} connection Command-owned source connection.
|
|
36
|
+
* @param {ApiVersionSelection} version Resolved API selection for Segment reads.
|
|
37
|
+
* @param {object} [injected] Service overrides; the command supplies its native DMO read.
|
|
38
|
+
* @param {Function} [onFailure] Receives each component that could not be acquired; the others
|
|
39
|
+
* are still acquired. Without it, the first failure is thrown.
|
|
40
|
+
* @param {Function} [onWarning] Receives a warning for each Segment whose DMO could not be bound;
|
|
41
|
+
* the Segment is still retrieved (retrieve checks prerequisites, it never refuses on them).
|
|
42
|
+
* @returns {Promise<RetrieveSelectionEntry[]>} Acquired selection, referenced DMOs first.
|
|
43
|
+
*/
|
|
44
|
+
export async function acquireRetrieveSelection(selected, connection, version, injected, onFailure, onWarning) {
|
|
45
|
+
const services = {
|
|
46
|
+
segment: retrieveSegment,
|
|
47
|
+
// The DMO read rides the command's connection: no child CLI process.
|
|
48
|
+
dmo: async (name) => {
|
|
49
|
+
const username = connection.getUsername() ?? '';
|
|
50
|
+
return createDmoClient(username, nativeApiVersion(), undefined, openBoundSsot(username, nativeApiVersion(), async () => connection)).get(name);
|
|
51
|
+
},
|
|
52
|
+
bind: bindSegmentDependencies,
|
|
53
|
+
raw: async (name) => new ConnectClient(connection, version).get(`/services/data/${version.restSelector}/ssot/data-model-objects/${name}`),
|
|
54
|
+
...injected,
|
|
55
|
+
};
|
|
56
|
+
const identities = new Map();
|
|
57
|
+
const entries = new Map();
|
|
58
|
+
const nodes = new Map();
|
|
59
|
+
const raw = new Map();
|
|
60
|
+
for (const identity of selected)
|
|
61
|
+
identities.set(dependencyKey(identity), identity);
|
|
62
|
+
// Components the document cannot represent: written as Salesforce returned them, outside the
|
|
63
|
+
// dependency order (they bind nothing).
|
|
64
|
+
const verbatim = [];
|
|
65
|
+
for (const [key, identity] of identities) {
|
|
66
|
+
let entry;
|
|
67
|
+
// The raw GET response of this component, once read.
|
|
68
|
+
let read;
|
|
69
|
+
try {
|
|
70
|
+
if (identity.kind === 'segment') {
|
|
71
|
+
const acquired = await services.segment(connection, identity.apiName, version, identity.dataSpace, 'retrieve');
|
|
72
|
+
read = carriedNativeResponse(acquired);
|
|
73
|
+
if (acquired.blockers.length > 0 || !acquired.candidate) {
|
|
74
|
+
const refusal = new SegmentError(acquired.blockers[0] ?? 'INCOMPLETE_SEGMENT');
|
|
75
|
+
throw retainConnectDiagnostic(acquired.explanation === undefined
|
|
76
|
+
? refusal
|
|
77
|
+
: explainInput(refusal, acquired.explanation), getConnectDiagnostic(acquired));
|
|
78
|
+
}
|
|
79
|
+
entry = { document: acquired.candidate };
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const document = await retrieveNativeDmo(identity.apiName, {
|
|
83
|
+
get: async (name) => {
|
|
84
|
+
const native = await services.dmo(name);
|
|
85
|
+
read ??= { native };
|
|
86
|
+
return native;
|
|
87
|
+
},
|
|
88
|
+
}, identity.dataSpace, 'retrieve');
|
|
89
|
+
entry = { document: read ? carryNativeResponse(document, read.native) : document };
|
|
90
|
+
}
|
|
91
|
+
const node = documentDependencyNode(entry.document, 'retrieve');
|
|
92
|
+
if (dependencyKey(node.identity) !== key)
|
|
93
|
+
throw new DependencySelectionError('DEPENDENCY_IDENTITY_UNSUPPORTED');
|
|
94
|
+
entries.set(key, entry);
|
|
95
|
+
nodes.set(key, node);
|
|
96
|
+
if (entry.document.kind === 'segment') {
|
|
97
|
+
const segmentOn = entry.document.spec.segmentOn.apiName;
|
|
98
|
+
try {
|
|
99
|
+
await services.bind(entry.document, connection, version, identity.dataSpace, async (name) => {
|
|
100
|
+
const rawKey = dependencyKey({
|
|
101
|
+
kind: 'dmo',
|
|
102
|
+
dataSpace: identity.dataSpace,
|
|
103
|
+
apiName: name,
|
|
104
|
+
});
|
|
105
|
+
if (!raw.has(rawKey))
|
|
106
|
+
raw.set(rawKey, services.raw(name));
|
|
107
|
+
return raw.get(rawKey);
|
|
108
|
+
}, 'retrieve');
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// A prerequisite that cannot be bound is a warning on retrieve: the file is still
|
|
112
|
+
// written, and deploy binds the DMO in the target org again.
|
|
113
|
+
const code = error instanceof SegmentError ? error.code : 'SEGMENT_DEPENDENCY_ACQUISITION_FAILED';
|
|
114
|
+
onWarning?.(`segment:${identity.apiName}: its DMO ${segmentOn} could not be checked (${code}); the segment was retrieved anyway, and deploy needs that DMO in the target org.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
// A component that failed after its node was built (its binding) is left out entirely.
|
|
120
|
+
const bound = nodes.delete(key);
|
|
121
|
+
entries.delete(key);
|
|
122
|
+
const reason = verbatimReason(error);
|
|
123
|
+
const document = reason === undefined || read === undefined || bound
|
|
124
|
+
? undefined
|
|
125
|
+
: createVerbatimDocument(identity.kind, { dataSpace: identity.dataSpace, apiName: identity.apiName }, reason, read.native);
|
|
126
|
+
if (document) {
|
|
127
|
+
verbatim.push({ document });
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const failure = retainConnectDiagnostic(new RetrieveSelectionError(error instanceof SegmentError ||
|
|
131
|
+
error instanceof NativeDmoError ||
|
|
132
|
+
error instanceof DependencySelectionError
|
|
133
|
+
? error.code
|
|
134
|
+
: 'DEPENDENCY_ACQUISITION_FAILED', identity), getConnectDiagnostic(error));
|
|
135
|
+
// One component failing never blocks the others when the caller collects failures.
|
|
136
|
+
if (!onFailure)
|
|
137
|
+
throw failure;
|
|
138
|
+
onFailure(failure);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return [
|
|
142
|
+
...orderDependencyNodes([...nodes.values()], unbounded).map((key) => entries.get(key)),
|
|
143
|
+
...verbatim,
|
|
144
|
+
];
|
|
145
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IdentityResolutionOutputIdentity } from '../artifacts/identity-resolution-document.js';
|
|
2
|
+
import type { ApiVersionSelection } from '../transport/api-version.js';
|
|
3
|
+
import type { IdentityResolutionTargetConnection } from './preflight-identity-resolution-deploy.js';
|
|
4
|
+
import type { DocumentMode } from '../artifacts/verbatim-document.js';
|
|
5
|
+
import { retrieveIdentityResolution } from './retrieve-identity-resolution.js';
|
|
6
|
+
export type IdentityResolutionOutputBinding = {
|
|
7
|
+
identity: IdentityResolutionOutputIdentity;
|
|
8
|
+
targetApiName: string;
|
|
9
|
+
targetId: string;
|
|
10
|
+
creationType?: string;
|
|
11
|
+
};
|
|
12
|
+
type Acquisition = {
|
|
13
|
+
detail: unknown;
|
|
14
|
+
};
|
|
15
|
+
type Acquire = (name: string, kind?: 'dlo') => Promise<Acquisition>;
|
|
16
|
+
/**
|
|
17
|
+
* Freshly bind the referenced inputs. This is bounded compatibility, not complete DMO schema admission.
|
|
18
|
+
* @param {unknown} value Complete portable IR document.
|
|
19
|
+
* @param {IdentityResolutionTargetConnection} connection Command-owned API68 connection.
|
|
20
|
+
* @param {ApiVersionSelection} selection Explicit API68 family route.
|
|
21
|
+
* @param {string} dataSpace The run's data space; the ruleset's c__dataSpace must name it.
|
|
22
|
+
* @param {Function} acquire Native API 68 detail acquisition seam.
|
|
23
|
+
* @param {DocumentMode} [mode] How the IR is checked: `retrieve` admits a retrieved file (delete).
|
|
24
|
+
* @returns {Promise<{fingerprint: string}>} Stable ordered target-local identity/required-field/key digest.
|
|
25
|
+
*/
|
|
26
|
+
export declare function bindIdentityResolutionDependencies(value: unknown, connection: IdentityResolutionTargetConnection, selection: ApiVersionSelection, dataSpace: string, acquire?: Acquire, mode?: DocumentMode): Promise<{
|
|
27
|
+
fingerprint: string;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Re-read the exact settled target owner, then bind each generated definition it names
|
|
31
|
+
* (identity, data space and unique ID; the creation type is recorded as observed).
|
|
32
|
+
* @param {object} owner Explicit target owner binding, never a source identity.
|
|
33
|
+
* @param {string} owner.targetApiName Exact target owner API name.
|
|
34
|
+
* @param {string} owner.targetId Independently acquired target owner ID.
|
|
35
|
+
* @param {string} owner.dataSpace The ruleset's data space (the run's).
|
|
36
|
+
* @param {object[]} outputs Ordered target-owner-returned names and logical owner/entity/role identities.
|
|
37
|
+
* @param {IdentityResolutionTargetConnection} connection Command-owned connection.
|
|
38
|
+
* @param {ApiVersionSelection} selection Explicit family route.
|
|
39
|
+
* @param {Function} acquire Native API 68 detail acquisition seam.
|
|
40
|
+
* @param {Function} acquireOwner Independent native target owner acquisition seam.
|
|
41
|
+
* @param {DocumentMode} [mode] How the owner GET is read: `retrieve` keeps keys the plugin does not
|
|
42
|
+
* model (delete).
|
|
43
|
+
* @returns {Promise<IdentityResolutionOutputBinding[]>} Independently verified private target bindings.
|
|
44
|
+
*/
|
|
45
|
+
export declare function verifyIdentityResolutionOutputs(owner: {
|
|
46
|
+
targetApiName: string;
|
|
47
|
+
targetId: string;
|
|
48
|
+
dataSpace: string;
|
|
49
|
+
}, outputs: Array<{
|
|
50
|
+
identity: IdentityResolutionOutputIdentity;
|
|
51
|
+
targetApiName: string;
|
|
52
|
+
}>, connection: IdentityResolutionTargetConnection, selection: ApiVersionSelection, acquire?: Acquire, acquireOwner?: typeof retrieveIdentityResolution, mode?: DocumentMode): Promise<IdentityResolutionOutputBinding[]>;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
|
+
import { IdentityResolutionError, projectNativeIdentityResolution, validateIdentityResolutionDocument, } from '../artifacts/identity-resolution-document.js';
|
|
4
|
+
import { ConnectClient } from '../transport/connect-client.js';
|
|
5
|
+
import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
|
|
6
|
+
import { projectDlo, unwrapDlo } from '../artifacts/dlo-document.js';
|
|
7
|
+
import { isDataSpaceName } from '../artifacts/data-space-field.js';
|
|
8
|
+
import { explainInput } from './operation-diagnostic.js';
|
|
9
|
+
import { retrieveIdentityResolution } from './retrieve-identity-resolution.js';
|
|
10
|
+
/**
|
|
11
|
+
* Require exact independently observed compatibility, never an assumed default.
|
|
12
|
+
* @param {unknown} condition Required compatibility invariant.
|
|
13
|
+
*/
|
|
14
|
+
function requireProof(condition) {
|
|
15
|
+
if (!condition)
|
|
16
|
+
throw new IdentityResolutionError('IDENTITY_RESOLUTION_BINDING_UNQUALIFIED');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read a record without accepting absent or array-shaped responses.
|
|
20
|
+
* @param {unknown} value Untrusted response data.
|
|
21
|
+
* @returns {Record<string, unknown>} Required record.
|
|
22
|
+
*/
|
|
23
|
+
function record(value) {
|
|
24
|
+
requireProof(value && typeof value === 'object' && !Array.isArray(value));
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Admit exact native68 binding only.
|
|
29
|
+
* @param {IdentityResolutionTargetConnection} connection Existing family connection.
|
|
30
|
+
* @param {ApiVersionSelection} selection Explicit family version selection.
|
|
31
|
+
*/
|
|
32
|
+
function scope(connection, selection) {
|
|
33
|
+
requireProof(selection?.requested === '68.0' &&
|
|
34
|
+
selection.restSelector === 'v68.0' &&
|
|
35
|
+
selection.soapNumeric === '68.0' &&
|
|
36
|
+
connection.getApiVersion() === '68.0');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Read the native API 68 DMO (in the ruleset's data space) or DLO detail.
|
|
40
|
+
* @param {IdentityResolutionTargetConnection} connection Existing family connection.
|
|
41
|
+
* @param {string} dataSpace The ruleset's data space.
|
|
42
|
+
* @returns {Acquire} Native68 reader.
|
|
43
|
+
*/
|
|
44
|
+
function reader(connection, dataSpace) {
|
|
45
|
+
return async (name, kind) => ({
|
|
46
|
+
detail: await new ConnectClient(connection, '68.0').get(kind === 'dlo'
|
|
47
|
+
? `/services/data/v68.0/ssot/data-lake-objects/${name}`
|
|
48
|
+
: `/services/data/v68.0/ssot/data-model-objects/${name}?dataspace=${encodeURIComponent(dataSpace)}`),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The refusal of a ruleset that names a component of another data space than its own.
|
|
53
|
+
* @param {string} what What the ruleset names (`the DMO X`, `the DLO X`).
|
|
54
|
+
* @param {unknown} found The data space the org names for it (or the DLO's list).
|
|
55
|
+
* @param {string} dataSpace The ruleset's data space.
|
|
56
|
+
* @returns {IdentityResolutionError} IDENTITY_RESOLUTION_DEPENDENCY_OTHER_DATASPACE.
|
|
57
|
+
*/
|
|
58
|
+
function otherSpace(what, found, dataSpace) {
|
|
59
|
+
return explainInput(new IdentityResolutionError('IDENTITY_RESOLUTION_DEPENDENCY_OTHER_DATASPACE'), `The ruleset names ${what}, which is in the data space ${typeof found === 'string' && found ? found : '(none named)'}, not in the ruleset's data space ${dataSpace}. Name the component of the ruleset's data space (outside default a standard DMO copy is <prefix>_<Name> with fields without ssot__); nothing was written.`);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Bound and uniquely index fields; duplicates anywhere are ambiguity, not first-match admission.
|
|
63
|
+
* @param {unknown} value Untrusted response data.
|
|
64
|
+
* @param {string} key Field identity property.
|
|
65
|
+
* @returns {Map<string, Record<string, unknown>>} Unique bounded field index.
|
|
66
|
+
*/
|
|
67
|
+
function fields(value, key) {
|
|
68
|
+
requireProof(Array.isArray(value) && value.length > 0 && value.length <= 4096);
|
|
69
|
+
const result = new Map();
|
|
70
|
+
for (const item of value) {
|
|
71
|
+
const field = record(item);
|
|
72
|
+
const name = field[key];
|
|
73
|
+
requireProof(typeof name === 'string' && /^[A-Za-z][A-Za-z0-9_]*$/u.test(name) && !result.has(name));
|
|
74
|
+
result.set(name, field);
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check the object's identity, data space and referenced fields in its native API 68 detail.
|
|
80
|
+
* Field types and primary keys are recorded as observed; the API decides what it accepts.
|
|
81
|
+
* @param {Acquisition} acquired Native DMO detail.
|
|
82
|
+
* @param {string} name Exact expected DMO name.
|
|
83
|
+
* @param {string[]} required Fields the definition references.
|
|
84
|
+
* @param {string} dataSpace The ruleset's data space; a DMO the read names in another one is
|
|
85
|
+
* IDENTITY_RESOLUTION_DEPENDENCY_OTHER_DATASPACE.
|
|
86
|
+
* @returns {object} Private target identity, referenced fields and observed keys.
|
|
87
|
+
*/
|
|
88
|
+
function compatible(acquired, name, required, dataSpace) {
|
|
89
|
+
const detail = record(acquired.detail);
|
|
90
|
+
if (detail.name === name && detail.dataSpaceName !== dataSpace)
|
|
91
|
+
throw otherSpace(`the DMO ${name}`, detail.dataSpaceName, dataSpace);
|
|
92
|
+
requireProof(detail.name === name && typeof detail.id === 'string' && detail.id.trim().length > 0);
|
|
93
|
+
const rawFields = fields(detail.fields, 'name');
|
|
94
|
+
const verified = required.map((apiName) => {
|
|
95
|
+
requireProof(rawFields.has(apiName));
|
|
96
|
+
return { apiName, dataType: rawFields.get(apiName)?.type };
|
|
97
|
+
});
|
|
98
|
+
const keys = [...rawFields.entries()]
|
|
99
|
+
.filter(([, field]) => field.isPrimaryKey === true)
|
|
100
|
+
.map(([key]) => key);
|
|
101
|
+
return { id: detail.id, creationType: detail.creationType, fields: verified, keys };
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Freshly bind the referenced inputs. This is bounded compatibility, not complete DMO schema admission.
|
|
105
|
+
* @param {unknown} value Complete portable IR document.
|
|
106
|
+
* @param {IdentityResolutionTargetConnection} connection Command-owned API68 connection.
|
|
107
|
+
* @param {ApiVersionSelection} selection Explicit API68 family route.
|
|
108
|
+
* @param {string} dataSpace The run's data space; the ruleset's c__dataSpace must name it.
|
|
109
|
+
* @param {Function} acquire Native API 68 detail acquisition seam.
|
|
110
|
+
* @param {DocumentMode} [mode] How the IR is checked: `retrieve` admits a retrieved file (delete).
|
|
111
|
+
* @returns {Promise<{fingerprint: string}>} Stable ordered target-local identity/required-field/key digest.
|
|
112
|
+
*/
|
|
113
|
+
export async function bindIdentityResolutionDependencies(value, connection, selection, dataSpace, acquire = reader(connection, dataSpace), mode = 'deploy') {
|
|
114
|
+
const document = validateIdentityResolutionDocument(value, mode);
|
|
115
|
+
selection = { ...selection };
|
|
116
|
+
scope(connection, selection);
|
|
117
|
+
requireProof(document.c__dataSpace === dataSpace);
|
|
118
|
+
const acquisitions = new Map();
|
|
119
|
+
const acquireOnce = async (name, kind) => {
|
|
120
|
+
const cacheKey = `${kind ?? 'dmo'}:${name}`;
|
|
121
|
+
const cached = acquisitions.get(cacheKey);
|
|
122
|
+
if (cached)
|
|
123
|
+
return cached;
|
|
124
|
+
const acquired = kind ? await acquire(name, kind) : await acquire(name);
|
|
125
|
+
acquisitions.set(cacheKey, acquired);
|
|
126
|
+
return acquired;
|
|
127
|
+
};
|
|
128
|
+
const bindings = [];
|
|
129
|
+
const ids = new Set();
|
|
130
|
+
for (const rule of document.spec.reconciliationRules) {
|
|
131
|
+
const name = rule.entity.apiName;
|
|
132
|
+
const required = [
|
|
133
|
+
...new Set([
|
|
134
|
+
...document.spec.matchRules
|
|
135
|
+
.flatMap((match) => match.criteria)
|
|
136
|
+
.filter((item) => item.field.parentApiName === name)
|
|
137
|
+
.map((item) => item.field.apiName),
|
|
138
|
+
...rule.fields.map((override) => override.field.apiName),
|
|
139
|
+
]),
|
|
140
|
+
];
|
|
141
|
+
const proof = compatible(await acquireOnce(name), name, required, dataSpace);
|
|
142
|
+
requireProof(!ids.has(proof.id));
|
|
143
|
+
ids.add(proof.id);
|
|
144
|
+
const priorities = [];
|
|
145
|
+
for (const settings of [rule, ...rule.fields]) {
|
|
146
|
+
const sources = [];
|
|
147
|
+
for (const source of settings.sources) {
|
|
148
|
+
const acquired = await acquireOnce(source.apiName, 'dlo');
|
|
149
|
+
const raw = unwrapDlo(acquired.detail);
|
|
150
|
+
// A DLO source must belong to the ruleset's data space (it may belong to others too).
|
|
151
|
+
const portable = projectDlo(raw);
|
|
152
|
+
if (raw.name === source.apiName && !portable.c__dataSpace.includes(dataSpace))
|
|
153
|
+
throw otherSpace(`the DLO ${source.apiName}`, portable.c__dataSpace.join(', '), dataSpace);
|
|
154
|
+
requireProof(portable.identity.apiName === source.apiName &&
|
|
155
|
+
raw.status === 'ACTIVE' &&
|
|
156
|
+
typeof raw.id === 'string' &&
|
|
157
|
+
raw.id.trim().length > 0);
|
|
158
|
+
sources.push({
|
|
159
|
+
identity: source,
|
|
160
|
+
targetId: raw.id,
|
|
161
|
+
fields: portable.spec.fields.map(({ name, dataType, isPrimaryKey }) => ({
|
|
162
|
+
name,
|
|
163
|
+
dataType,
|
|
164
|
+
isPrimaryKey,
|
|
165
|
+
})),
|
|
166
|
+
});
|
|
167
|
+
scope(connection, selection);
|
|
168
|
+
}
|
|
169
|
+
priorities.push({ field: 'field' in settings ? settings.field : undefined, sources });
|
|
170
|
+
}
|
|
171
|
+
bindings.push({
|
|
172
|
+
identity: rule.entity,
|
|
173
|
+
...proof,
|
|
174
|
+
...(priorities.some((entry) => entry.sources.length > 0) ? { priorities } : {}),
|
|
175
|
+
});
|
|
176
|
+
scope(connection, selection);
|
|
177
|
+
}
|
|
178
|
+
return { fingerprint: createHash('sha256').update(JSON.stringify(bindings)).digest('hex') };
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Re-read the exact settled target owner, then bind each generated definition it names
|
|
182
|
+
* (identity, data space and unique ID; the creation type is recorded as observed).
|
|
183
|
+
* @param {object} owner Explicit target owner binding, never a source identity.
|
|
184
|
+
* @param {string} owner.targetApiName Exact target owner API name.
|
|
185
|
+
* @param {string} owner.targetId Independently acquired target owner ID.
|
|
186
|
+
* @param {string} owner.dataSpace The ruleset's data space (the run's).
|
|
187
|
+
* @param {object[]} outputs Ordered target-owner-returned names and logical owner/entity/role identities.
|
|
188
|
+
* @param {IdentityResolutionTargetConnection} connection Command-owned connection.
|
|
189
|
+
* @param {ApiVersionSelection} selection Explicit family route.
|
|
190
|
+
* @param {Function} acquire Native API 68 detail acquisition seam.
|
|
191
|
+
* @param {Function} acquireOwner Independent native target owner acquisition seam.
|
|
192
|
+
* @param {DocumentMode} [mode] How the owner GET is read: `retrieve` keeps keys the plugin does not
|
|
193
|
+
* model (delete).
|
|
194
|
+
* @returns {Promise<IdentityResolutionOutputBinding[]>} Independently verified private target bindings.
|
|
195
|
+
*/
|
|
196
|
+
export async function verifyIdentityResolutionOutputs(owner, outputs, connection, selection, acquire = reader(connection, owner?.dataSpace), acquireOwner = retrieveIdentityResolution, mode = 'deploy') {
|
|
197
|
+
selection = { ...selection };
|
|
198
|
+
scope(connection, selection);
|
|
199
|
+
requireProof(isDataSpaceName(owner?.dataSpace) &&
|
|
200
|
+
typeof owner.targetId === 'string' &&
|
|
201
|
+
owner.targetId.trim() &&
|
|
202
|
+
typeof owner.targetApiName === 'string' &&
|
|
203
|
+
/^[A-Za-z][A-Za-z0-9_]{0,199}$/u.test(owner.targetApiName) &&
|
|
204
|
+
Array.isArray(outputs));
|
|
205
|
+
// Snapshot caller-owned identities/names before asynchronous reads; no generated name is constructed.
|
|
206
|
+
const requested = structuredClone(outputs);
|
|
207
|
+
const target = { ...owner };
|
|
208
|
+
requireProof(requested.every((output) => output.identity.owner.apiName === target.targetApiName));
|
|
209
|
+
const acquired = await acquireOwner(connection, target.targetApiName, { ...selection }, target.dataSpace, mode);
|
|
210
|
+
if (!acquired.expectations || !acquired.candidate || acquired.blockers.length > 0)
|
|
211
|
+
throw retainConnectDiagnostic(new IdentityResolutionError('IDENTITY_RESOLUTION_BINDING_UNQUALIFIED'), getConnectDiagnostic(acquired));
|
|
212
|
+
const projection = projectNativeIdentityResolution(acquired.expectations.native, target.targetApiName, mode);
|
|
213
|
+
const expected = projection.expectations.outputs.map(({ identity, sourceApiName }) => ({
|
|
214
|
+
identity,
|
|
215
|
+
targetApiName: sourceApiName,
|
|
216
|
+
}));
|
|
217
|
+
requireProof(projection.expectations.native.id === target.targetId && isDeepStrictEqual(requested, expected));
|
|
218
|
+
const bindings = [];
|
|
219
|
+
const ids = new Set([target.targetId]);
|
|
220
|
+
for (const output of requested) {
|
|
221
|
+
const proof = compatible(await acquire(output.targetApiName), output.targetApiName, [], target.dataSpace);
|
|
222
|
+
requireProof(!ids.has(proof.id));
|
|
223
|
+
ids.add(proof.id);
|
|
224
|
+
bindings.push({
|
|
225
|
+
...output,
|
|
226
|
+
targetId: proof.id,
|
|
227
|
+
...(typeof proof.creationType === 'string' ? { creationType: proof.creationType } : {}),
|
|
228
|
+
});
|
|
229
|
+
scope(connection, selection);
|
|
230
|
+
}
|
|
231
|
+
const final = await acquireOwner(connection, target.targetApiName, { ...selection }, target.dataSpace, mode);
|
|
232
|
+
if (!final.expectations || !final.candidate || final.blockers.length > 0)
|
|
233
|
+
throw retainConnectDiagnostic(new IdentityResolutionError('IDENTITY_RESOLUTION_BINDING_UNQUALIFIED'), getConnectDiagnostic(final));
|
|
234
|
+
const finalProjection = projectNativeIdentityResolution(final.expectations.native, target.targetApiName, mode);
|
|
235
|
+
requireProof(isDeepStrictEqual(finalProjection, projection));
|
|
236
|
+
scope(connection, selection);
|
|
237
|
+
return bindings;
|
|
238
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Connection } from '@salesforce/core';
|
|
2
|
+
import type { SegmentDocument } from '../artifacts/segment-document.js';
|
|
3
|
+
import type { ApiVersionSelection } from '../transport/api-version.js';
|
|
4
|
+
import type { DocumentMode } from '../artifacts/verbatim-document.js';
|
|
5
|
+
export type SegmentDependencyBinding = {
|
|
6
|
+
identity: SegmentDocument['spec']['segmentOn'];
|
|
7
|
+
targetId: string;
|
|
8
|
+
};
|
|
9
|
+
type ReadConnection = Pick<Connection, 'instanceUrl' | 'request' | 'getApiVersion'>;
|
|
10
|
+
/**
|
|
11
|
+
* Bind the DMO a Segment is built on to its target-local ID with one native API68 read.
|
|
12
|
+
* Only existence, identity and data space are checked (a DMO read that names another data space
|
|
13
|
+
* than the segment's is SEGMENT_DEPENDENCY_OTHER_DATASPACE); whether the DMO suits the Segment is
|
|
14
|
+
* Salesforce's call.
|
|
15
|
+
* @param {unknown} value Complete authored Segment.
|
|
16
|
+
* @param {ReadConnection} connection Authenticated target connection, never modified.
|
|
17
|
+
* @param {string | ApiVersionSelection} apiVersion API68 selection.
|
|
18
|
+
* @param {string} dataSpace The run's data space; the segment's c__dataSpace must name it.
|
|
19
|
+
* @param {Function} acquire Raw DMO detail read, not a write response.
|
|
20
|
+
* @param {DocumentMode} [mode] How the Segment is checked: `retrieve` admits a retrieved file.
|
|
21
|
+
* @returns {Promise<SegmentDependencyBinding[]>} Private target-local binding; no source IDs.
|
|
22
|
+
*/
|
|
23
|
+
export declare function bindSegmentDependencies(value: unknown, connection: ReadConnection, apiVersion: string | ApiVersionSelection, dataSpace: string, acquire?: (name: string) => Promise<unknown>, mode?: DocumentMode): Promise<SegmentDependencyBinding[]>;
|
|
24
|
+
export type SegmentChildBinding = {
|
|
25
|
+
identity: {
|
|
26
|
+
kind: 'segment';
|
|
27
|
+
dataSpace: string;
|
|
28
|
+
apiName: string;
|
|
29
|
+
};
|
|
30
|
+
/** The child's `marketSegmentDefinitionId` in the target org. */
|
|
31
|
+
targetId: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Bind the child segments a Waterfall file names (`spec.childSegments`) to their definition IDs
|
|
35
|
+
* in the target org, one exact segment read per child, in the order of the file. Nothing is read
|
|
36
|
+
* for a segment without child segments. A child that is not a segment API name, or that the
|
|
37
|
+
* target answers with HTTP 404, is SEGMENT_CHILD_NOT_FOUND (the child must exist in the target
|
|
38
|
+
* or be deployed earlier in the same run); another answer without that exact segment and its
|
|
39
|
+
* definition ID is SEGMENT_DEPENDENCY_AMBIGUOUS_OR_MISSING, a child of another data space than the
|
|
40
|
+
* Waterfall's SEGMENT_DEPENDENCY_OTHER_DATASPACE; a failed read
|
|
41
|
+
* SEGMENT_DEPENDENCY_ACQUISITION_FAILED.
|
|
42
|
+
* @param {unknown} value Complete authored Segment.
|
|
43
|
+
* @param {ReadConnection} connection Authenticated target connection, never modified.
|
|
44
|
+
* @param {string | ApiVersionSelection} apiVersion API68 selection.
|
|
45
|
+
* @param {Function} [read] Raw segment GET by API name.
|
|
46
|
+
* @returns {Promise<SegmentChildBinding[]>} Target-local child bindings in file order.
|
|
47
|
+
*/
|
|
48
|
+
export declare function bindSegmentChildren(value: unknown, connection: ReadConnection, apiVersion: string | ApiVersionSelection, read?: (name: string) => Promise<unknown>): Promise<SegmentChildBinding[]>;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { SegmentError, segmentName, validateSegmentDocument, } from '../artifacts/segment-document.js';
|
|
2
|
+
import { explainInput } from './operation-diagnostic.js';
|
|
3
|
+
import { ConnectClient } from '../transport/connect-client.js';
|
|
4
|
+
import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
|
|
5
|
+
import { isDataSpaceName } from '../artifacts/data-space-field.js';
|
|
6
|
+
/**
|
|
7
|
+
* The refusal of a segment whose segmentOn DMO or Waterfall child the org holds in another data
|
|
8
|
+
* space: a segment and everything it names are in one data space.
|
|
9
|
+
* @param {string} what What the segment names (`its DMO X`, `the child segment X`).
|
|
10
|
+
* @param {unknown} found The data space the org names for it.
|
|
11
|
+
* @param {string} dataSpace The segment's data space.
|
|
12
|
+
* @returns {SegmentError} SEGMENT_DEPENDENCY_OTHER_DATASPACE with an explanation.
|
|
13
|
+
*/
|
|
14
|
+
function otherSpace(what, found, dataSpace) {
|
|
15
|
+
return explainInput(new SegmentError('SEGMENT_DEPENDENCY_OTHER_DATASPACE'), `The segment names ${what}, which is in the data space ${isDataSpaceName(found) ? found : '(none named)'}, not in the segment's data space ${dataSpace}. Name the component of the segment's data space (in a non-default data space Salesforce stores it as <prefix>_<Name>); nothing was written.`);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Bind the DMO a Segment is built on to its target-local ID with one native API68 read.
|
|
19
|
+
* Only existence, identity and data space are checked (a DMO read that names another data space
|
|
20
|
+
* than the segment's is SEGMENT_DEPENDENCY_OTHER_DATASPACE); whether the DMO suits the Segment is
|
|
21
|
+
* Salesforce's call.
|
|
22
|
+
* @param {unknown} value Complete authored Segment.
|
|
23
|
+
* @param {ReadConnection} connection Authenticated target connection, never modified.
|
|
24
|
+
* @param {string | ApiVersionSelection} apiVersion API68 selection.
|
|
25
|
+
* @param {string} dataSpace The run's data space; the segment's c__dataSpace must name it.
|
|
26
|
+
* @param {Function} acquire Raw DMO detail read, not a write response.
|
|
27
|
+
* @param {DocumentMode} [mode] How the Segment is checked: `retrieve` admits a retrieved file.
|
|
28
|
+
* @returns {Promise<SegmentDependencyBinding[]>} Private target-local binding; no source IDs.
|
|
29
|
+
*/
|
|
30
|
+
export async function bindSegmentDependencies(value, connection, apiVersion, dataSpace, acquire = async (name) => new ConnectClient(connection, apiVersion).get(`/services/data/v${connection.getApiVersion()}/ssot/data-model-objects/${name}`), mode = 'deploy') {
|
|
31
|
+
const document = validateSegmentDocument(value, mode);
|
|
32
|
+
const version = typeof apiVersion === 'string' ? apiVersion : apiVersion.requested;
|
|
33
|
+
if (document.c__dataSpace !== dataSpace ||
|
|
34
|
+
version !== '68.0' ||
|
|
35
|
+
connection.getApiVersion() !== version ||
|
|
36
|
+
(typeof apiVersion !== 'string' &&
|
|
37
|
+
(apiVersion.restSelector !== `v${version}` || apiVersion.soapNumeric !== version)))
|
|
38
|
+
throw new SegmentError('INVALID_SCOPE');
|
|
39
|
+
const name = document.spec.segmentOn.apiName;
|
|
40
|
+
try {
|
|
41
|
+
const detail = await acquire(name);
|
|
42
|
+
if (!detail ||
|
|
43
|
+
typeof detail !== 'object' ||
|
|
44
|
+
Array.isArray(detail) ||
|
|
45
|
+
detail.name !== name ||
|
|
46
|
+
typeof detail.id !== 'string' ||
|
|
47
|
+
!detail.id)
|
|
48
|
+
throw new SegmentError('SEGMENT_DEPENDENCY_AMBIGUOUS_OR_MISSING');
|
|
49
|
+
// A read without a data space leaves the decision to Salesforce's write.
|
|
50
|
+
const found = detail.dataSpaceName;
|
|
51
|
+
if (found !== undefined && found !== null && found !== dataSpace)
|
|
52
|
+
throw otherSpace(`its DMO ${name}`, found, dataSpace);
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
identity: { ...document.spec.segmentOn },
|
|
56
|
+
targetId: detail.id,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof SegmentError)
|
|
62
|
+
throw error;
|
|
63
|
+
throw retainConnectDiagnostic(new SegmentError('SEGMENT_DEPENDENCY_ACQUISITION_FAILED'), getConnectDiagnostic(error));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Bind the child segments a Waterfall file names (`spec.childSegments`) to their definition IDs
|
|
68
|
+
* in the target org, one exact segment read per child, in the order of the file. Nothing is read
|
|
69
|
+
* for a segment without child segments. A child that is not a segment API name, or that the
|
|
70
|
+
* target answers with HTTP 404, is SEGMENT_CHILD_NOT_FOUND (the child must exist in the target
|
|
71
|
+
* or be deployed earlier in the same run); another answer without that exact segment and its
|
|
72
|
+
* definition ID is SEGMENT_DEPENDENCY_AMBIGUOUS_OR_MISSING, a child of another data space than the
|
|
73
|
+
* Waterfall's SEGMENT_DEPENDENCY_OTHER_DATASPACE; a failed read
|
|
74
|
+
* SEGMENT_DEPENDENCY_ACQUISITION_FAILED.
|
|
75
|
+
* @param {unknown} value Complete authored Segment.
|
|
76
|
+
* @param {ReadConnection} connection Authenticated target connection, never modified.
|
|
77
|
+
* @param {string | ApiVersionSelection} apiVersion API68 selection.
|
|
78
|
+
* @param {Function} [read] Raw segment GET by API name.
|
|
79
|
+
* @returns {Promise<SegmentChildBinding[]>} Target-local child bindings in file order.
|
|
80
|
+
*/
|
|
81
|
+
export async function bindSegmentChildren(value, connection, apiVersion, read = async (name) => new ConnectClient(connection, apiVersion).get(`/services/data/v${connection.getApiVersion()}/ssot/segments/${name}`)) {
|
|
82
|
+
const document = validateSegmentDocument(value);
|
|
83
|
+
const names = document.spec.childSegments ?? [];
|
|
84
|
+
const bindings = [];
|
|
85
|
+
for (const name of names) {
|
|
86
|
+
const missing = () => explainInput(new SegmentError('SEGMENT_CHILD_NOT_FOUND'), `The child segment ${segmentName.test(name) ? name : '[not a segment API name]'} of spec.childSegments is not in the target org. Deploy it first (in the same run it is deployed before the Waterfall) or correct the name; nothing was written.`);
|
|
87
|
+
if (!segmentName.test(name))
|
|
88
|
+
throw missing();
|
|
89
|
+
let response;
|
|
90
|
+
try {
|
|
91
|
+
response = await read(name);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const diagnostic = getConnectDiagnostic(error);
|
|
95
|
+
if (diagnostic?.statusCode === 404)
|
|
96
|
+
throw retainConnectDiagnostic(missing(), diagnostic);
|
|
97
|
+
throw retainConnectDiagnostic(new SegmentError('SEGMENT_DEPENDENCY_ACQUISITION_FAILED'), diagnostic);
|
|
98
|
+
}
|
|
99
|
+
const child = response?.segments;
|
|
100
|
+
const entry = (Array.isArray(child) && child.length === 1 ? child[0] : undefined);
|
|
101
|
+
if (!entry ||
|
|
102
|
+
entry.apiName !== name ||
|
|
103
|
+
typeof entry.marketSegmentDefinitionId !== 'string' ||
|
|
104
|
+
!entry.marketSegmentDefinitionId)
|
|
105
|
+
throw new SegmentError('SEGMENT_DEPENDENCY_AMBIGUOUS_OR_MISSING');
|
|
106
|
+
// A read by name finds a segment in any data space; a Waterfall takes children of its own.
|
|
107
|
+
if (entry.dataSpace !== document.c__dataSpace)
|
|
108
|
+
throw otherSpace(`the child segment ${name}`, entry.dataSpace, document.c__dataSpace);
|
|
109
|
+
bindings.push({
|
|
110
|
+
identity: { kind: 'segment', dataSpace: document.c__dataSpace, apiName: name },
|
|
111
|
+
targetId: entry.marketSegmentDefinitionId,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return bindings;
|
|
115
|
+
}
|