sf-plugin-data 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +618 -240
- package/docs/artifact-format.md +528 -633
- package/docs/capabilities.md +1160 -168
- package/docs/git-workflow.md +135 -12
- package/docs/handover.md +7826 -12
- package/lib/api.d.ts +13 -0
- package/lib/api.js +10 -0
- package/lib/artifacts/code-fields.d.ts +49 -0
- package/lib/artifacts/code-fields.js +142 -0
- package/lib/artifacts/data-graph-document.d.ts +29 -0
- package/lib/artifacts/data-graph-document.js +52 -0
- package/lib/artifacts/data-space-field.d.ts +65 -0
- package/lib/artifacts/data-space-field.js +98 -0
- package/lib/artifacts/data-stream-document.d.ts +264 -0
- package/lib/artifacts/data-stream-document.js +680 -0
- package/lib/artifacts/data-transform-document.d.ts +152 -0
- package/lib/artifacts/data-transform-document.js +560 -0
- package/lib/artifacts/dependency-selection.d.ts +51 -0
- package/lib/artifacts/dependency-selection.js +154 -0
- package/lib/artifacts/dlo-document.d.ts +93 -0
- package/lib/artifacts/dlo-document.js +253 -0
- package/lib/artifacts/enum-case.d.ts +39 -0
- package/lib/artifacts/enum-case.js +67 -0
- package/lib/artifacts/git-deploy-selection.d.ts +68 -0
- package/lib/artifacts/git-deploy-selection.js +474 -0
- package/lib/artifacts/identity-resolution-document.d.ts +133 -0
- package/lib/artifacts/identity-resolution-document.js +625 -0
- package/lib/artifacts/mapping-document.d.ts +1 -0
- package/lib/artifacts/mapping-document.js +1 -0
- package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
- package/lib/artifacts/native-calculated-insight-document.js +321 -0
- package/lib/artifacts/native-data-graph-document.d.ts +124 -0
- package/lib/artifacts/native-data-graph-document.js +780 -0
- package/lib/artifacts/native-dmo-document.d.ts +151 -0
- package/lib/artifacts/native-dmo-document.js +313 -0
- package/lib/artifacts/native-mapping-document.d.ts +67 -0
- package/lib/artifacts/native-mapping-document.js +187 -0
- package/lib/artifacts/native-relationship-document.d.ts +76 -0
- package/lib/artifacts/native-relationship-document.js +232 -0
- package/lib/artifacts/path-selector.d.ts +55 -0
- package/lib/artifacts/path-selector.js +167 -0
- package/lib/artifacts/read-deploy-input.d.ts +222 -6
- package/lib/artifacts/read-deploy-input.js +1213 -53
- package/lib/artifacts/segment-document.d.ts +183 -0
- package/lib/artifacts/segment-document.js +570 -0
- package/lib/artifacts/verbatim-document.d.ts +203 -0
- package/lib/artifacts/verbatim-document.js +339 -0
- package/lib/artifacts/write-data-graph.d.ts +17 -0
- package/lib/artifacts/write-data-graph.js +162 -0
- package/lib/artifacts/write-data-stream.d.ts +11 -0
- package/lib/artifacts/write-data-stream.js +175 -0
- package/lib/artifacts/write-data-transform.d.ts +11 -0
- package/lib/artifacts/write-data-transform.js +180 -0
- package/lib/artifacts/write-dlo.d.ts +11 -0
- package/lib/artifacts/write-dlo.js +158 -0
- package/lib/artifacts/write-identity-resolution.d.ts +18 -0
- package/lib/artifacts/write-identity-resolution.js +165 -0
- package/lib/artifacts/write-mapping-definition.d.ts +17 -0
- package/lib/artifacts/write-mapping-definition.js +127 -0
- package/lib/artifacts/write-member-export.d.ts +88 -0
- package/lib/artifacts/write-member-export.js +199 -0
- package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
- package/lib/artifacts/write-native-calculated-insight.js +176 -0
- package/lib/artifacts/write-native-dmo.d.ts +11 -0
- package/lib/artifacts/write-native-dmo.js +158 -0
- package/lib/artifacts/write-native-mapping.d.ts +11 -0
- package/lib/artifacts/write-native-mapping.js +157 -0
- package/lib/artifacts/write-native-relationship.d.ts +11 -0
- package/lib/artifacts/write-native-relationship.js +157 -0
- package/lib/artifacts/write-segment.d.ts +26 -0
- package/lib/artifacts/write-segment.js +212 -0
- package/lib/commands/data360/delete.d.ts +280 -0
- package/lib/commands/data360/delete.js +2347 -0
- package/lib/commands/data360/deploy.d.ts +235 -16
- package/lib/commands/data360/deploy.js +2339 -102
- package/lib/commands/data360/list/dataspace.d.ts +53 -0
- package/lib/commands/data360/list/dataspace.js +109 -0
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +298 -0
- package/lib/commands/data360/retrieve.d.ts +283 -14
- package/lib/commands/data360/retrieve.js +1945 -95
- package/lib/commands/data360/segment/members/export.d.ts +101 -0
- package/lib/commands/data360/segment/members/export.js +320 -0
- package/lib/errors/codes/calculated-insight.d.ts +2 -0
- package/lib/errors/codes/calculated-insight.js +25 -0
- package/lib/errors/codes/data-graph.d.ts +2 -0
- package/lib/errors/codes/data-graph.js +22 -0
- package/lib/errors/codes/data-stream.d.ts +2 -0
- package/lib/errors/codes/data-stream.js +70 -0
- package/lib/errors/codes/data-transform.d.ts +2 -0
- package/lib/errors/codes/data-transform.js +35 -0
- package/lib/errors/codes/dependency.d.ts +2 -0
- package/lib/errors/codes/dependency.js +11 -0
- package/lib/errors/codes/dlo.d.ts +2 -0
- package/lib/errors/codes/dlo.js +31 -0
- package/lib/errors/codes/dmo.d.ts +2 -0
- package/lib/errors/codes/dmo.js +28 -0
- package/lib/errors/codes/general.d.ts +2 -0
- package/lib/errors/codes/general.js +58 -0
- package/lib/errors/codes/identity-resolution.d.ts +2 -0
- package/lib/errors/codes/identity-resolution.js +24 -0
- package/lib/errors/codes/mapping.d.ts +2 -0
- package/lib/errors/codes/mapping.js +42 -0
- package/lib/errors/codes/relationship.d.ts +2 -0
- package/lib/errors/codes/relationship.js +21 -0
- package/lib/errors/codes/segment.d.ts +2 -0
- package/lib/errors/codes/segment.js +49 -0
- package/lib/errors/registry.d.ts +60 -0
- package/lib/errors/registry.js +123 -0
- package/lib/exit-code.d.ts +10 -0
- package/lib/exit-code.js +24 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +3 -1
- package/lib/services/acquire-retrieve-selection.d.ts +43 -0
- package/lib/services/acquire-retrieve-selection.js +145 -0
- package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
- package/lib/services/bind-identity-resolution-dependencies.js +238 -0
- package/lib/services/bind-segment-dependencies.d.ts +49 -0
- package/lib/services/bind-segment-dependencies.js +115 -0
- package/lib/services/bounded-reads.d.ts +17 -0
- package/lib/services/bounded-reads.js +42 -0
- package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
- package/lib/services/calculated-insight-sql-checks.js +193 -0
- package/lib/services/command-dlo.d.ts +48 -0
- package/lib/services/command-dlo.js +103 -0
- package/lib/services/command-native-data-graph.d.ts +54 -0
- package/lib/services/command-native-data-graph.js +485 -0
- package/lib/services/command-native-data-stream.d.ts +104 -0
- package/lib/services/command-native-data-stream.js +257 -0
- package/lib/services/command-native-dmo.d.ts +124 -0
- package/lib/services/command-native-dmo.js +338 -0
- package/lib/services/command-native-mapping.d.ts +65 -0
- package/lib/services/command-native-mapping.js +129 -0
- package/lib/services/command-native-relationship.d.ts +46 -0
- package/lib/services/command-native-relationship.js +103 -0
- package/lib/services/cross-dataspace-deploy.d.ts +111 -0
- package/lib/services/cross-dataspace-deploy.js +493 -0
- package/lib/services/cross-dataspace-rename.d.ts +74 -0
- package/lib/services/cross-dataspace-rename.js +1314 -0
- package/lib/services/cross-dataspace-sql.d.ts +109 -0
- package/lib/services/cross-dataspace-sql.js +1301 -0
- package/lib/services/cross-space-context.d.ts +23 -0
- package/lib/services/cross-space-context.js +38 -0
- package/lib/services/crud-plan.d.ts +137 -0
- package/lib/services/crud-plan.js +408 -0
- package/lib/services/data-space-check.d.ts +92 -0
- package/lib/services/data-space-check.js +169 -0
- package/lib/services/data-space-prefix.d.ts +77 -0
- package/lib/services/data-space-prefix.js +127 -0
- package/lib/services/data-transform-space.d.ts +31 -0
- package/lib/services/data-transform-space.js +79 -0
- package/lib/services/delete-calculated-insight.d.ts +44 -0
- package/lib/services/delete-calculated-insight.js +101 -0
- package/lib/services/delete-data-transform.d.ts +52 -0
- package/lib/services/delete-data-transform.js +222 -0
- package/lib/services/delete-dmo-field.d.ts +211 -0
- package/lib/services/delete-dmo-field.js +472 -0
- package/lib/services/delete-identity-resolution.d.ts +43 -0
- package/lib/services/delete-identity-resolution.js +295 -0
- package/lib/services/delete-segment.d.ts +42 -0
- package/lib/services/delete-segment.js +248 -0
- package/lib/services/deploy-result.d.ts +54 -0
- package/lib/services/deploy-result.js +60 -0
- package/lib/services/escaped-copy.d.ts +23 -0
- package/lib/services/escaped-copy.js +88 -0
- package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
- package/lib/services/execute-calculated-insight-deploy.js +96 -0
- package/lib/services/execute-data-transform-deploy.d.ts +56 -0
- package/lib/services/execute-data-transform-deploy.js +168 -0
- package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
- package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
- package/lib/services/execute-segment-deploy.d.ts +45 -0
- package/lib/services/execute-segment-deploy.js +393 -0
- package/lib/services/list-data-spaces.d.ts +17 -0
- package/lib/services/list-data-spaces.js +24 -0
- package/lib/services/local-file-removal.d.ts +36 -0
- package/lib/services/local-file-removal.js +103 -0
- package/lib/services/native-calculated-insight.d.ts +87 -0
- package/lib/services/native-calculated-insight.js +164 -0
- package/lib/services/native-crm-data-stream.d.ts +91 -0
- package/lib/services/native-crm-data-stream.js +272 -0
- package/lib/services/native-data-graph-context.d.ts +12 -0
- package/lib/services/native-data-graph-context.js +139 -0
- package/lib/services/native-data-graph-crd.d.ts +261 -0
- package/lib/services/native-data-graph-crd.js +866 -0
- package/lib/services/native-data-stream.d.ts +329 -0
- package/lib/services/native-data-stream.js +1830 -0
- package/lib/services/native-dlo.d.ts +163 -0
- package/lib/services/native-dlo.js +402 -0
- package/lib/services/native-dmo.d.ts +191 -0
- package/lib/services/native-dmo.js +614 -0
- package/lib/services/native-mapping.d.ts +255 -0
- package/lib/services/native-mapping.js +1226 -0
- package/lib/services/native-relationship.d.ts +132 -0
- package/lib/services/native-relationship.js +512 -0
- package/lib/services/operation-diagnostic.d.ts +83 -0
- package/lib/services/operation-diagnostic.js +272 -0
- package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
- package/lib/services/preflight-calculated-insight-deploy.js +95 -0
- package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
- package/lib/services/preflight-data-transform-deploy.js +104 -0
- package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
- package/lib/services/preflight-identity-resolution-deploy.js +281 -0
- package/lib/services/preflight-segment-deploy.d.ts +31 -0
- package/lib/services/preflight-segment-deploy.js +109 -0
- package/lib/services/publish-calculated-insight.d.ts +40 -0
- package/lib/services/publish-calculated-insight.js +95 -0
- package/lib/services/publish-segment.d.ts +65 -0
- package/lib/services/publish-segment.js +194 -0
- package/lib/services/readback-pace.d.ts +16 -0
- package/lib/services/readback-pace.js +23 -0
- package/lib/services/retrieve-data-transform.d.ts +26 -0
- package/lib/services/retrieve-data-transform.js +65 -0
- package/lib/services/retrieve-identity-resolution.d.ts +40 -0
- package/lib/services/retrieve-identity-resolution.js +87 -0
- package/lib/services/retrieve-inventory.d.ts +32 -0
- package/lib/services/retrieve-inventory.js +151 -0
- package/lib/services/retrieve-segment.d.ts +120 -0
- package/lib/services/retrieve-segment.js +502 -0
- package/lib/services/run-retrieve.d.ts +24 -0
- package/lib/services/run-retrieve.js +51 -0
- package/lib/services/segment-lookup.d.ts +46 -0
- package/lib/services/segment-lookup.js +108 -0
- package/lib/services/segment-members.d.ts +144 -0
- package/lib/services/segment-members.js +402 -0
- package/lib/services/select-native-retrieve.d.ts +60 -0
- package/lib/services/select-native-retrieve.js +226 -0
- package/lib/services/settle-calculated-insight.d.ts +22 -0
- package/lib/services/settle-calculated-insight.js +53 -0
- package/lib/services/sql-tokens.d.ts +58 -0
- package/lib/services/sql-tokens.js +147 -0
- package/lib/transport/api-version.d.ts +36 -0
- package/lib/transport/api-version.js +89 -0
- package/lib/transport/bound-ssot.d.ts +27 -0
- package/lib/transport/bound-ssot.js +116 -0
- package/lib/transport/calculated-insight-rest.d.ts +28 -0
- package/lib/transport/calculated-insight-rest.js +62 -0
- package/lib/transport/connect-client.d.ts +94 -32
- package/lib/transport/connect-client.js +318 -178
- package/lib/transport/connect-diagnostic.d.ts +89 -0
- package/lib/transport/connect-diagnostic.js +331 -0
- package/lib/transport/data-graph-rest.d.ts +27 -0
- package/lib/transport/data-graph-rest.js +76 -0
- package/lib/transport/data-stream-rest.d.ts +62 -0
- package/lib/transport/data-stream-rest.js +348 -0
- package/lib/transport/data-transform-rest.d.ts +25 -0
- package/lib/transport/data-transform-rest.js +100 -0
- package/lib/transport/dlo-native-rest.d.ts +22 -0
- package/lib/transport/dlo-native-rest.js +89 -0
- package/lib/transport/dlo-rest.d.ts +23 -0
- package/lib/transport/dlo-rest.js +135 -0
- package/lib/transport/dmo-native-rest.d.ts +18 -0
- package/lib/transport/dmo-native-rest.js +55 -0
- package/lib/transport/dmo-rest.d.ts +30 -0
- package/lib/transport/dmo-rest.js +163 -0
- package/lib/transport/mapping-rest.d.ts +63 -0
- package/lib/transport/mapping-rest.js +341 -0
- package/lib/transport/project-metadata.d.ts +36 -0
- package/lib/transport/project-metadata.js +118 -0
- package/lib/transport/relationship-rest.d.ts +43 -0
- package/lib/transport/relationship-rest.js +201 -0
- package/package.json +29 -6
- package/lib/artifacts/dmo-document.d.ts +0 -181
- package/lib/artifacts/dmo-document.js +0 -848
- package/lib/artifacts/dmo-update-delta.d.ts +0 -28
- package/lib/artifacts/dmo-update-delta.js +0 -86
- package/lib/artifacts/write-other-dmo.d.ts +0 -17
- package/lib/artifacts/write-other-dmo.js +0 -140
- package/lib/services/execute-dmo-create.d.ts +0 -24
- package/lib/services/execute-dmo-create.js +0 -118
- package/lib/services/execute-dmo-deploy.d.ts +0 -33
- package/lib/services/execute-dmo-deploy.js +0 -197
- package/lib/services/preflight-dmo-deploy.d.ts +0 -69
- package/lib/services/preflight-dmo-deploy.js +0 -161
- package/lib/services/retrieve-other-dmo.d.ts +0 -46
- package/lib/services/retrieve-other-dmo.js +0 -140
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
|
|
3
|
+
import { operationDiagnostic } from './operation-diagnostic.js';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
import { projectNativeIdentityResolution } from '../artifacts/identity-resolution-document.js';
|
|
6
|
+
import { ConnectClient, ConnectError } from '../transport/connect-client.js';
|
|
7
|
+
import { nativeIdentityResolutionDocument, nativeIdentityResolutionConfigurationDelta, bindNativeIdentityResolutionPrecreate, preflightNativeIdentityResolutionDeploy, } from './preflight-identity-resolution-deploy.js';
|
|
8
|
+
import { bindIdentityResolutionDependencies, verifyIdentityResolutionOutputs, } from './bind-identity-resolution-dependencies.js';
|
|
9
|
+
import { errorCodeInfo } from '../errors/registry.js';
|
|
10
|
+
// Native68 retained CREATE was still PUBLISHING at ~78s and PUBLISHED by ~257s.
|
|
11
|
+
// Leave room for independently observed ~31s output binding; this is not an API SLA.
|
|
12
|
+
export const nativeIdentityResolutionPollBudget = Object.freeze({
|
|
13
|
+
reads: 31,
|
|
14
|
+
intervalMs: 10_000,
|
|
15
|
+
timeoutMs: 360_000,
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Execute one qualified full-settings native68 CREATE or PATCH, never retrying a write.
|
|
19
|
+
* The caller must stop its batch on unknown mutation; no fallback or rollback exists here.
|
|
20
|
+
* @param {unknown} value Complete portable native68 desired definition.
|
|
21
|
+
* @param {IdentityResolutionTargetConnection} connection Fixed authenticated native68 receiver.
|
|
22
|
+
* @param {ApiVersionSelection} apiVersion Explicit native68 selection.
|
|
23
|
+
* @param {string} dataSpace The run's data space; the ruleset's c__dataSpace must name it.
|
|
24
|
+
* @param {NativeIdentityResolutionExecutionOptions} options Input/effect guards and synthetic read seams.
|
|
25
|
+
* @returns {Promise<NativeIdentityResolutionDeployExecution>} Payload-free mutation evidence.
|
|
26
|
+
*/
|
|
27
|
+
export async function executeNativeIdentityResolutionDeploy(value, connection, apiVersion, dataSpace, options) {
|
|
28
|
+
let attempted = false;
|
|
29
|
+
let acknowledged = false;
|
|
30
|
+
let failureReason = 'verification-failed';
|
|
31
|
+
let expired = false;
|
|
32
|
+
let operation = 'identity-resolutions.patch';
|
|
33
|
+
const result = (outcome, mutation, code) => ({
|
|
34
|
+
family: 'identity-resolution',
|
|
35
|
+
route: { apiVersion: '68.0', operation },
|
|
36
|
+
outcome,
|
|
37
|
+
mutation,
|
|
38
|
+
diagnostics: code
|
|
39
|
+
? [
|
|
40
|
+
{
|
|
41
|
+
code,
|
|
42
|
+
message: attempted
|
|
43
|
+
? `${acknowledged ? 'IR write acknowledged; settlement unconfirmed' : 'IR write acknowledgement unconfirmed'} (${failureReason}). Stop the batch; inspect the exact target. No retry or rollback was performed.`
|
|
44
|
+
: (errorCodeInfo(code)?.hint ??
|
|
45
|
+
'The identity resolution deployment was blocked by the plugin checks; nothing was written.'),
|
|
46
|
+
},
|
|
47
|
+
]
|
|
48
|
+
: [],
|
|
49
|
+
});
|
|
50
|
+
try {
|
|
51
|
+
const desired = nativeIdentityResolutionDocument(value);
|
|
52
|
+
const selection = { ...apiVersion };
|
|
53
|
+
const { verifyInput, verifyDependencies = bindIdentityResolutionDependencies, verifyOutputs = verifyIdentityResolutionOutputs, now = Date.now, delay: wait = delay, } = options;
|
|
54
|
+
const scope = () => {
|
|
55
|
+
if (expired)
|
|
56
|
+
throw new Error('Settlement cancelled');
|
|
57
|
+
if (selection.requested !== '68.0' ||
|
|
58
|
+
selection.restSelector !== 'v68.0' ||
|
|
59
|
+
selection.soapNumeric !== '68.0' ||
|
|
60
|
+
connection.getApiVersion() !== '68.0' ||
|
|
61
|
+
dataSpace !== desired.c__dataSpace ||
|
|
62
|
+
!isDeepStrictEqual(selection, apiVersion))
|
|
63
|
+
throw new Error('Scope drift');
|
|
64
|
+
};
|
|
65
|
+
scope();
|
|
66
|
+
// Bindings can perform multiple reads internally. Fence their receiver too, so
|
|
67
|
+
// an in-flight read completing after expiration cannot launch its next read.
|
|
68
|
+
const verificationConnection = Object.create(connection);
|
|
69
|
+
Object.defineProperty(verificationConnection, 'getApiVersion', {
|
|
70
|
+
value: () => {
|
|
71
|
+
scope();
|
|
72
|
+
return connection.getApiVersion();
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(verificationConnection, 'request', {
|
|
76
|
+
value: async function (...arguments_) {
|
|
77
|
+
scope();
|
|
78
|
+
const response = await connection.request.apply(this, arguments_);
|
|
79
|
+
scope();
|
|
80
|
+
return response;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
if ('_transport' in connection) {
|
|
84
|
+
const transport = connection._transport;
|
|
85
|
+
const guardedTransport = Object.create(transport);
|
|
86
|
+
guardedTransport.httpRequest = (...arguments_) => {
|
|
87
|
+
scope();
|
|
88
|
+
const pending = transport.httpRequest(...arguments_);
|
|
89
|
+
const guarded = pending.then((value) => {
|
|
90
|
+
scope();
|
|
91
|
+
return value;
|
|
92
|
+
});
|
|
93
|
+
return Object.assign(guarded, { stream: () => pending.stream() });
|
|
94
|
+
};
|
|
95
|
+
Object.defineProperty(verificationConnection, '_transport', { value: guardedTransport });
|
|
96
|
+
}
|
|
97
|
+
let fingerprint;
|
|
98
|
+
const verify = async () => {
|
|
99
|
+
scope();
|
|
100
|
+
const proof = await verifyDependencies(structuredClone(desired), verificationConnection, { ...selection }, dataSpace);
|
|
101
|
+
scope();
|
|
102
|
+
if (!/^[a-f0-9]{64}$/u.test(proof?.fingerprint) ||
|
|
103
|
+
(fingerprint !== undefined && fingerprint !== proof.fingerprint))
|
|
104
|
+
throw new Error('Input drift');
|
|
105
|
+
fingerprint = proof.fingerprint;
|
|
106
|
+
return proof;
|
|
107
|
+
};
|
|
108
|
+
const client = new ConnectClient(connection, selection);
|
|
109
|
+
const path = `/services/data/v68.0/ssot/identity-resolutions/${desired.identity.apiName}`;
|
|
110
|
+
const read = () => {
|
|
111
|
+
scope();
|
|
112
|
+
return client.get(path);
|
|
113
|
+
};
|
|
114
|
+
const project = (raw) => projectNativeIdentityResolution(raw, desired.identity.apiName);
|
|
115
|
+
const outputs = async (projection) => {
|
|
116
|
+
const expected = projection.expectations.outputs.map(({ identity, sourceApiName }) => ({
|
|
117
|
+
identity: structuredClone(identity),
|
|
118
|
+
targetApiName: sourceApiName,
|
|
119
|
+
}));
|
|
120
|
+
const ownerId = projection.expectations.native.id;
|
|
121
|
+
const proof = await verifyOutputs({ targetApiName: desired.identity.apiName, targetId: ownerId, dataSpace }, structuredClone(expected), verificationConnection, { ...selection });
|
|
122
|
+
if (!Array.isArray(proof) || proof.length !== expected.length)
|
|
123
|
+
throw new Error('Output proof absent');
|
|
124
|
+
const ids = new Set([ownerId]);
|
|
125
|
+
for (const [index, binding] of proof.entries()) {
|
|
126
|
+
if (!isDeepStrictEqual(binding.identity, expected[index].identity) ||
|
|
127
|
+
binding.targetApiName !== expected[index].targetApiName ||
|
|
128
|
+
typeof binding.targetId !== 'string' ||
|
|
129
|
+
!binding.targetId.trim() ||
|
|
130
|
+
ids.has(binding.targetId))
|
|
131
|
+
throw new Error('Output mismatch');
|
|
132
|
+
ids.add(binding.targetId);
|
|
133
|
+
}
|
|
134
|
+
scope();
|
|
135
|
+
return structuredClone(proof);
|
|
136
|
+
};
|
|
137
|
+
await verifyInput();
|
|
138
|
+
const preview = await preflightNativeIdentityResolutionDeploy(desired, connection, selection, dataSpace, {
|
|
139
|
+
verifyDependencies: async () => {
|
|
140
|
+
await verify();
|
|
141
|
+
},
|
|
142
|
+
verifyPrecreateInputs: verify,
|
|
143
|
+
...(options.dataSpacePrefix === undefined
|
|
144
|
+
? {}
|
|
145
|
+
: { dataSpacePrefix: options.dataSpacePrefix }),
|
|
146
|
+
});
|
|
147
|
+
if (!['create', 'update', 'unchanged'].includes(preview.outcome))
|
|
148
|
+
throw retainConnectDiagnostic(new Error('Admission failed'), getConnectDiagnostic(preview));
|
|
149
|
+
const creating = preview.outcome === 'create';
|
|
150
|
+
operation = creating ? 'identity-resolutions.post' : 'identity-resolutions.patch';
|
|
151
|
+
let baseline;
|
|
152
|
+
let bound;
|
|
153
|
+
if (!creating) {
|
|
154
|
+
baseline = project(await read());
|
|
155
|
+
bound = await outputs(baseline);
|
|
156
|
+
if (preview.outcome === 'unchanged' && !isDeepStrictEqual(baseline.candidate, desired))
|
|
157
|
+
throw new Error('Target drift');
|
|
158
|
+
if (preview.outcome === 'update' &&
|
|
159
|
+
!nativeIdentityResolutionConfigurationDelta(baseline.candidate, desired))
|
|
160
|
+
throw new Error('Delta refused');
|
|
161
|
+
}
|
|
162
|
+
if (preview.outcome !== 'unchanged' &&
|
|
163
|
+
(options.allowProcessing !== true ||
|
|
164
|
+
(creating && options.allowGeneratedOutputProvisioning !== true)))
|
|
165
|
+
return result('blocked', 'not-attempted', 'IDENTITY_RESOLUTION_EFFECT_ACKNOWLEDGEMENT_REQUIRED');
|
|
166
|
+
await verifyInput();
|
|
167
|
+
await verify();
|
|
168
|
+
if (creating) {
|
|
169
|
+
const fresh = await preflightNativeIdentityResolutionDeploy(desired, connection, selection, dataSpace, {
|
|
170
|
+
verifyDependencies: async () => {
|
|
171
|
+
await verify();
|
|
172
|
+
},
|
|
173
|
+
verifyPrecreateInputs: verify,
|
|
174
|
+
...(options.dataSpacePrefix === undefined
|
|
175
|
+
? {}
|
|
176
|
+
: { dataSpacePrefix: options.dataSpacePrefix }),
|
|
177
|
+
});
|
|
178
|
+
if (preview.outcome !== 'create' ||
|
|
179
|
+
fresh.outcome !== 'create' ||
|
|
180
|
+
!isDeepStrictEqual(preview.precreateBinding, fresh.precreateBinding))
|
|
181
|
+
throw new Error('Precreate drift');
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const fresh = project(await read());
|
|
185
|
+
if (!isDeepStrictEqual(fresh, baseline) || !isDeepStrictEqual(bound, await outputs(fresh)))
|
|
186
|
+
throw new Error('Owner drift');
|
|
187
|
+
}
|
|
188
|
+
await verifyInput();
|
|
189
|
+
await verify();
|
|
190
|
+
// The last owner read is an exact absence check for CREATE, never an upsert decision.
|
|
191
|
+
if (creating) {
|
|
192
|
+
const finalBinding = await bindNativeIdentityResolutionPrecreate(desired, connection, selection, dataSpace, verify);
|
|
193
|
+
if (preview.outcome !== 'create' ||
|
|
194
|
+
!isDeepStrictEqual(finalBinding, preview.precreateBinding))
|
|
195
|
+
throw new Error('Final precreate binding drift');
|
|
196
|
+
try {
|
|
197
|
+
await read();
|
|
198
|
+
throw new Error('Owner appeared');
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
if (!(error instanceof ConnectError &&
|
|
202
|
+
error.statusCode === 404 &&
|
|
203
|
+
error.nativeCode === 'ITEM_NOT_FOUND'))
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else if (!isDeepStrictEqual(project(await read()), baseline))
|
|
208
|
+
throw new Error('Final owner drift');
|
|
209
|
+
scope();
|
|
210
|
+
if (preview.outcome === 'unchanged')
|
|
211
|
+
return result('unchanged', 'not-attempted');
|
|
212
|
+
const started = now();
|
|
213
|
+
if (!Number.isFinite(started))
|
|
214
|
+
throw new Error('Invalid clock');
|
|
215
|
+
let previous = started;
|
|
216
|
+
const remaining = () => {
|
|
217
|
+
const current = now();
|
|
218
|
+
if (!Number.isFinite(current) || current < previous) {
|
|
219
|
+
failureReason = 'invalid-clock';
|
|
220
|
+
throw new Error('Invalid clock');
|
|
221
|
+
}
|
|
222
|
+
previous = current;
|
|
223
|
+
if (current - started >= nativeIdentityResolutionPollBudget.timeoutMs) {
|
|
224
|
+
failureReason = 'deadline-exhausted';
|
|
225
|
+
expired = true;
|
|
226
|
+
throw new Error('Settlement timeout');
|
|
227
|
+
}
|
|
228
|
+
scope();
|
|
229
|
+
return nativeIdentityResolutionPollBudget.timeoutMs - (current - started);
|
|
230
|
+
};
|
|
231
|
+
const deadline = () => {
|
|
232
|
+
remaining();
|
|
233
|
+
};
|
|
234
|
+
// A stalled request/binding cannot extend the real deadline. Expiration fences
|
|
235
|
+
// continuations so a late completion cannot schedule another read or confirm success.
|
|
236
|
+
const bounded = async (work) => {
|
|
237
|
+
let timer;
|
|
238
|
+
try {
|
|
239
|
+
const budget = remaining();
|
|
240
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
241
|
+
timer = setTimeout(() => {
|
|
242
|
+
failureReason = 'deadline-exhausted';
|
|
243
|
+
expired = true;
|
|
244
|
+
reject(new Error('Settlement timeout'));
|
|
245
|
+
}, budget);
|
|
246
|
+
});
|
|
247
|
+
const value = await Promise.race([work(), timeout]);
|
|
248
|
+
deadline();
|
|
249
|
+
return value;
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
clearTimeout(timer);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
if (options.allowProcessing !== true ||
|
|
256
|
+
(creating && options.allowGeneratedOutputProvisioning !== true))
|
|
257
|
+
return result('blocked', 'not-attempted', 'IDENTITY_RESOLUTION_EFFECT_ACKNOWLEDGEMENT_REQUIRED');
|
|
258
|
+
attempted = true;
|
|
259
|
+
const echo = await bounded(async () => {
|
|
260
|
+
const response = creating
|
|
261
|
+
? await client.createIdentityResolution(desired, options.dataSpacePrefix)
|
|
262
|
+
: await client.patchIdentityResolution(desired, baseline?.candidate);
|
|
263
|
+
acknowledged = true;
|
|
264
|
+
return response;
|
|
265
|
+
});
|
|
266
|
+
// The mutation echo is not authoritative. Only independent owner GETs settle configuration.
|
|
267
|
+
// Retain any returned identity anchors, without requiring a full GET-shaped response.
|
|
268
|
+
if (!echo || typeof echo !== 'object' || Array.isArray(echo))
|
|
269
|
+
throw new Error('Malformed response');
|
|
270
|
+
const response = echo;
|
|
271
|
+
// A created owner settles PUBLISHED; an updated one settles in its previous state
|
|
272
|
+
// (an unpublished ruleset stays unpublished) or PUBLISHED. PUBLISHING is in flight.
|
|
273
|
+
const baselineStatus = baseline?.expectations.native.rulesetStatus;
|
|
274
|
+
const settledStatus = (status) => status === 'PUBLISHED' || (!creating && status === baselineStatus);
|
|
275
|
+
if (!['id', 'objectApiName', 'rulesetStatus'].some((key) => Object.hasOwn(response, key)) ||
|
|
276
|
+
(response.rulesetStatus !== undefined &&
|
|
277
|
+
response.rulesetStatus !== 'PUBLISHING' &&
|
|
278
|
+
!settledStatus(response.rulesetStatus)) ||
|
|
279
|
+
(response.objectApiName !== undefined &&
|
|
280
|
+
response.objectApiName !== desired.identity.apiName) ||
|
|
281
|
+
(response.id !== undefined && (typeof response.id !== 'string' || !response.id.trim())) ||
|
|
282
|
+
(baseline && response.id !== undefined && response.id !== baseline.expectations.native.id))
|
|
283
|
+
throw new Error('Mutation identity mismatch');
|
|
284
|
+
// Async: the validated acceptance is the whole result; settlement stays unconfirmed.
|
|
285
|
+
// Without a later GET, the echo itself must name this ruleset, not just look plausible.
|
|
286
|
+
if (options.async === true) {
|
|
287
|
+
const namesRuleset = response.objectApiName === desired.identity.apiName ||
|
|
288
|
+
(!creating &&
|
|
289
|
+
baseline !== undefined &&
|
|
290
|
+
response.id !== undefined &&
|
|
291
|
+
response.id === baseline.expectations.native.id);
|
|
292
|
+
if (!namesRuleset)
|
|
293
|
+
throw new Error('Mutation identity mismatch');
|
|
294
|
+
return result(creating ? 'creation-processing' : 'update-processing', 'acknowledged-processing');
|
|
295
|
+
}
|
|
296
|
+
const compare = (raw) => {
|
|
297
|
+
const observed = raw;
|
|
298
|
+
if (!observed ||
|
|
299
|
+
(observed.rulesetStatus !== 'PUBLISHING' && !settledStatus(observed.rulesetStatus)))
|
|
300
|
+
throw new Error('Malformed response');
|
|
301
|
+
const projection = project(observed);
|
|
302
|
+
if (!isDeepStrictEqual(projection.candidate, desired) ||
|
|
303
|
+
(baseline &&
|
|
304
|
+
(projection.expectations.native.id !== baseline.expectations.native.id ||
|
|
305
|
+
!isDeepStrictEqual(projection.expectations.outputs, baseline.expectations.outputs))))
|
|
306
|
+
throw new Error('Readback mismatch');
|
|
307
|
+
return projection;
|
|
308
|
+
};
|
|
309
|
+
let settledIdentity;
|
|
310
|
+
for (let attempt = 0; attempt < nativeIdentityResolutionPollBudget.reads; attempt++) {
|
|
311
|
+
deadline();
|
|
312
|
+
if (attempt > 0)
|
|
313
|
+
await bounded(() => wait(nativeIdentityResolutionPollBudget.intervalMs));
|
|
314
|
+
deadline();
|
|
315
|
+
const raw = await bounded(read);
|
|
316
|
+
const settled = compare(raw);
|
|
317
|
+
if (Array.isArray(response.reconciliationRules)) {
|
|
318
|
+
const observedRules = settled.expectations.native.reconciliationRules;
|
|
319
|
+
for (const value of response.reconciliationRules) {
|
|
320
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
321
|
+
throw new Error('Malformed response identity');
|
|
322
|
+
const anchor = value;
|
|
323
|
+
const observed = observedRules.find((rule) => rule.entityName === anchor.entityName);
|
|
324
|
+
for (const key of ['unifiedDmoName', 'linkDmoName'])
|
|
325
|
+
if (anchor[key] !== undefined && anchor[key] !== observed?.[key])
|
|
326
|
+
throw new Error('Mutation output identity mismatch');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if ((response.id !== undefined && response.id !== settled.expectations.native.id) ||
|
|
330
|
+
(settledIdentity &&
|
|
331
|
+
(settledIdentity.native.id !== settled.expectations.native.id ||
|
|
332
|
+
!isDeepStrictEqual(settledIdentity.outputs, settled.expectations.outputs))))
|
|
333
|
+
throw new Error('Settlement identity drift');
|
|
334
|
+
settledIdentity = settled.expectations;
|
|
335
|
+
deadline();
|
|
336
|
+
if (!settledStatus(raw.rulesetStatus))
|
|
337
|
+
continue;
|
|
338
|
+
const settledOutputs = await bounded(() => outputs(settled));
|
|
339
|
+
if (baseline && !isDeepStrictEqual(bound, settledOutputs))
|
|
340
|
+
throw new Error('Output drift');
|
|
341
|
+
if (!isDeepStrictEqual(project(await bounded(read)), settled))
|
|
342
|
+
throw new Error('Final settlement drift');
|
|
343
|
+
await bounded(verify);
|
|
344
|
+
deadline();
|
|
345
|
+
return result(creating ? 'created' : 'updated', creating ? 'confirmed-created' : 'confirmed-updated');
|
|
346
|
+
}
|
|
347
|
+
failureReason = 'read-budget-exhausted';
|
|
348
|
+
throw new Error('Settlement budget exhausted');
|
|
349
|
+
}
|
|
350
|
+
catch (error) {
|
|
351
|
+
expired = true;
|
|
352
|
+
const failed = attempted
|
|
353
|
+
? result('failed', 'unknown', 'IDENTITY_RESOLUTION_NATIVE68_MUTATION_UNCONFIRMED')
|
|
354
|
+
: result('blocked', 'not-attempted', 'IDENTITY_RESOLUTION_NATIVE68_ADMISSION_FAILED');
|
|
355
|
+
retainConnectDiagnostic(failed, getConnectDiagnostic(error));
|
|
356
|
+
if (getConnectDiagnostic(error))
|
|
357
|
+
failed.diagnostics[0].message = operationDiagnostic(error, failed.diagnostics[0].message);
|
|
358
|
+
return failed;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Connection } from '@salesforce/core';
|
|
2
|
+
import type { ApiVersionSelection } from '../transport/api-version.js';
|
|
3
|
+
import { bindSegmentChildren, bindSegmentDependencies } from './bind-segment-dependencies.js';
|
|
4
|
+
import { retrieveSegment } from './retrieve-segment.js';
|
|
5
|
+
import type { DeployExecutionResult } from './deploy-result.js';
|
|
6
|
+
export declare const segmentPollBudget: Readonly<{
|
|
7
|
+
reads: 120;
|
|
8
|
+
intervalMs: 1000;
|
|
9
|
+
timeoutMs: 120000;
|
|
10
|
+
}>;
|
|
11
|
+
export type SegmentExecutionOptions = {
|
|
12
|
+
allowProcessing: boolean;
|
|
13
|
+
verifyInput: () => Promise<void>;
|
|
14
|
+
acquire?: typeof retrieveSegment;
|
|
15
|
+
bind?: typeof bindSegmentDependencies;
|
|
16
|
+
children?: typeof bindSegmentChildren;
|
|
17
|
+
read?: (name: string) => Promise<unknown>;
|
|
18
|
+
patch?: (document: unknown, schedule: boolean, children: ReadonlyMap<string, string>) => Promise<unknown>;
|
|
19
|
+
create?: (document: unknown, children: ReadonlyMap<string, string>) => Promise<unknown>;
|
|
20
|
+
now?: () => number;
|
|
21
|
+
delay?: (milliseconds: number) => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export type SegmentDeployExecution = DeployExecutionResult & {
|
|
24
|
+
family: 'segment';
|
|
25
|
+
serverProcessing?: true;
|
|
26
|
+
route: {
|
|
27
|
+
apiVersion: string;
|
|
28
|
+
method: 'POST' | 'PATCH';
|
|
29
|
+
resource: 'segments';
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type TargetConnection = Pick<Connection, 'instanceUrl' | 'request' | 'getApiVersion' | 'getUsername'>;
|
|
33
|
+
/**
|
|
34
|
+
* Execute native68 create-only POST, PATCH of the authored definition, or zero-write equality.
|
|
35
|
+
* The definition is sent as written and Salesforce decides; every write is single-attempt,
|
|
36
|
+
* without replay or rollback.
|
|
37
|
+
* @param {unknown} value Complete authored desired Segment.
|
|
38
|
+
* @param {TargetConnection} connection Command-owned authenticated target.
|
|
39
|
+
* @param {string | ApiVersionSelection} apiVersion API68 selection.
|
|
40
|
+
* @param {string} dataSpace The run's data space; the file's c__dataSpace must name it.
|
|
41
|
+
* @param {SegmentExecutionOptions} options Acknowledgement, JSON digest verifier and bounded test seams.
|
|
42
|
+
* @returns {Promise<SegmentDeployExecution>} Payload-free outcome with conservative mutation evidence.
|
|
43
|
+
*/
|
|
44
|
+
export declare function executeSegmentDeploy(value: unknown, connection: TargetConnection, apiVersion: string | ApiVersionSelection, dataSpace: string, options: SegmentExecutionOptions): Promise<SegmentDeployExecution>;
|
|
45
|
+
export {};
|