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,295 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
import { IdentityResolutionError, identityResolutionSpace, identityResolutionSpaceMismatch, observeIdentityResolutionOwner, projectNativeIdentityResolution, validateIdentityResolutionDocument, } from '../artifacts/identity-resolution-document.js';
|
|
4
|
+
import { isDataSpaceName } from '../artifacts/data-space-field.js';
|
|
5
|
+
import { isVerbatimDocument, verbatimDataSpace } from '../artifacts/verbatim-document.js';
|
|
6
|
+
import { ConnectClient, ConnectError } from '../transport/connect-client.js';
|
|
7
|
+
import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
|
|
8
|
+
import { inFlightIdentityResolutionStatuses } from './preflight-identity-resolution-deploy.js';
|
|
9
|
+
import { bindIdentityResolutionDependencies, verifyIdentityResolutionOutputs, } from './bind-identity-resolution-dependencies.js';
|
|
10
|
+
import { explanationOf, operationDiagnostic } from './operation-diagnostic.js';
|
|
11
|
+
export const identityResolutionDeleteBudget = Object.freeze({
|
|
12
|
+
timeoutMs: 180_000,
|
|
13
|
+
reads: 13,
|
|
14
|
+
intervalMs: 10_000,
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* The owner of a raw GET, checked only for what names it (the same name; its data space is
|
|
18
|
+
* checked before); used for a verbatim file, whose ruleset the plugin cannot model.
|
|
19
|
+
* @param {unknown} raw Raw GET response.
|
|
20
|
+
* @param {string} apiName Selected name.
|
|
21
|
+
* @returns {Projection} The owner as read, without run statistics, and no outputs.
|
|
22
|
+
*/
|
|
23
|
+
function rawOwner(raw, apiName) {
|
|
24
|
+
const native = observeIdentityResolutionOwner(raw);
|
|
25
|
+
if (native.objectApiName !== apiName)
|
|
26
|
+
throw new Error('Owner identity');
|
|
27
|
+
return { expectations: { native, outputs: [] } };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Delete one matching settled native68 owner definition without replay.
|
|
31
|
+
* Generated definitions are bound before dispatch but never manually deleted. Input/output
|
|
32
|
+
* compatibility is not exhaustive inbound-consumer exclusion or physical profile cleanup.
|
|
33
|
+
* @param {unknown} value Immutable local configuration expectation, not ownership authority.
|
|
34
|
+
* @param {IdentityResolutionTargetConnection} connection Authenticated fixed receiver.
|
|
35
|
+
* @param {ApiVersionSelection} selection Explicit native68 route.
|
|
36
|
+
* @param {string} dataSpace The run's data space; the file and the org ruleset must be in it.
|
|
37
|
+
* @param {IdentityResolutionDeleteOptions} options Confirmation, input guard and private test seams.
|
|
38
|
+
* @returns {Promise<IdentityResolutionDeleteResult>} Payload-free independently observed outcome.
|
|
39
|
+
*/
|
|
40
|
+
export async function deleteIdentityResolution(value, connection, selection, dataSpace, options) {
|
|
41
|
+
let attempted = false;
|
|
42
|
+
let expired = false;
|
|
43
|
+
let timer;
|
|
44
|
+
const result = (outcome, code, error) => retainConnectDiagnostic({
|
|
45
|
+
family: 'identity-resolution',
|
|
46
|
+
route: { apiVersion: '68.0', operation: 'identity-resolutions.delete' },
|
|
47
|
+
outcome,
|
|
48
|
+
mutation: attempted
|
|
49
|
+
? outcome === 'deleted'
|
|
50
|
+
? 'confirmed-deleted'
|
|
51
|
+
: outcome === 'deletion-processing'
|
|
52
|
+
? 'acknowledged-processing'
|
|
53
|
+
: 'unknown'
|
|
54
|
+
: 'not-attempted',
|
|
55
|
+
requiredEffects: outcome === 'delete' ? ['destructive'] : [],
|
|
56
|
+
diagnostics: code
|
|
57
|
+
? [
|
|
58
|
+
{
|
|
59
|
+
code,
|
|
60
|
+
message: operationDiagnostic(error, attempted
|
|
61
|
+
? 'IR deletion may have occurred; owner absence is unconfirmed. No replay, fallback or rollback was performed.'
|
|
62
|
+
: 'IR deletion was not attempted; input, scope, definition, lifecycle or binding is unqualified.'),
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
: [],
|
|
66
|
+
}, getConnectDiagnostic(error));
|
|
67
|
+
try {
|
|
68
|
+
// Read as retrieve writes it: the file and the GET may keep keys the plugin does not model.
|
|
69
|
+
// A verbatim file (a ruleset the plugin cannot model) is deleted by name.
|
|
70
|
+
const verbatim = isVerbatimDocument(value, 'identity-resolution');
|
|
71
|
+
const admit = () => verbatim
|
|
72
|
+
? {
|
|
73
|
+
c__dataSpace: verbatimDataSpace(value),
|
|
74
|
+
identity: { apiName: value.identity.apiName },
|
|
75
|
+
}
|
|
76
|
+
: validateIdentityResolutionDocument(value, 'retrieve');
|
|
77
|
+
const desired = admit();
|
|
78
|
+
if (desired.c__dataSpace !== dataSpace)
|
|
79
|
+
throw identityResolutionSpaceMismatch(desired.identity.apiName, desired.c__dataSpace, dataSpace, 'file');
|
|
80
|
+
const frozen = { ...selection };
|
|
81
|
+
const origin = connection.instanceUrl;
|
|
82
|
+
const request = connection.request;
|
|
83
|
+
const now = options.now ?? Date.now;
|
|
84
|
+
const wait = options.delay ?? delay;
|
|
85
|
+
const started = now();
|
|
86
|
+
let previous = started;
|
|
87
|
+
const check = () => {
|
|
88
|
+
const current = now();
|
|
89
|
+
if (expired ||
|
|
90
|
+
!Number.isFinite(started) ||
|
|
91
|
+
!Number.isFinite(current) ||
|
|
92
|
+
current < previous ||
|
|
93
|
+
current - started >= identityResolutionDeleteBudget.timeoutMs ||
|
|
94
|
+
frozen.requested !== '68.0' ||
|
|
95
|
+
frozen.restSelector !== 'v68.0' ||
|
|
96
|
+
frozen.soapNumeric !== '68.0' ||
|
|
97
|
+
!isDeepStrictEqual(selection, frozen) ||
|
|
98
|
+
connection.getApiVersion() !== '68.0' ||
|
|
99
|
+
connection.instanceUrl !== origin ||
|
|
100
|
+
connection.request !== request ||
|
|
101
|
+
!isDataSpaceName(dataSpace))
|
|
102
|
+
throw new Error('Scope or deadline');
|
|
103
|
+
previous = current;
|
|
104
|
+
};
|
|
105
|
+
check();
|
|
106
|
+
if (typeof options.verifyInput !== 'function' ||
|
|
107
|
+
('preview' in options && typeof options.preview !== 'boolean'))
|
|
108
|
+
throw new Error('Intent');
|
|
109
|
+
const verifyInput = options.verifyInput;
|
|
110
|
+
const preview = options.preview === true;
|
|
111
|
+
const confirmed = options.confirmDelete;
|
|
112
|
+
const input = async () => {
|
|
113
|
+
check();
|
|
114
|
+
await verifyInput();
|
|
115
|
+
check();
|
|
116
|
+
if ((options.preview === true) !== preview ||
|
|
117
|
+
options.confirmDelete !== confirmed ||
|
|
118
|
+
!isDeepStrictEqual(desired, admit()))
|
|
119
|
+
throw new Error('Input drift');
|
|
120
|
+
};
|
|
121
|
+
// Fence every dependency-reader request as well as owner reads after cancellation.
|
|
122
|
+
const receiver = Object.create(connection);
|
|
123
|
+
Object.defineProperty(receiver, 'getApiVersion', {
|
|
124
|
+
value: () => {
|
|
125
|
+
check();
|
|
126
|
+
return connection.getApiVersion();
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(receiver, 'request', {
|
|
130
|
+
value: async function (...arguments_) {
|
|
131
|
+
check();
|
|
132
|
+
const response = await request.apply(this, arguments_);
|
|
133
|
+
check();
|
|
134
|
+
return response;
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
if ('_transport' in connection) {
|
|
138
|
+
const transport = connection._transport;
|
|
139
|
+
const guarded = Object.create(transport);
|
|
140
|
+
guarded.httpRequest = (...arguments_) => {
|
|
141
|
+
check();
|
|
142
|
+
const pending = transport.httpRequest(...arguments_);
|
|
143
|
+
const observed = pending.then((response) => {
|
|
144
|
+
check();
|
|
145
|
+
return response;
|
|
146
|
+
});
|
|
147
|
+
return Object.assign(observed, { stream: () => pending.stream() });
|
|
148
|
+
};
|
|
149
|
+
Object.defineProperty(receiver, '_transport', { value: guarded });
|
|
150
|
+
}
|
|
151
|
+
const client = new ConnectClient(receiver, frozen);
|
|
152
|
+
const base = '/services/data/v68.0/ssot/identity-resolutions/';
|
|
153
|
+
const read = async (identity) => {
|
|
154
|
+
check();
|
|
155
|
+
try {
|
|
156
|
+
const raw = await client.get(`${base}${identity}`);
|
|
157
|
+
check();
|
|
158
|
+
if (raw === undefined)
|
|
159
|
+
throw new Error('Malformed read');
|
|
160
|
+
return raw;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
check();
|
|
164
|
+
if (error instanceof ConnectError &&
|
|
165
|
+
error.statusCode === 404 &&
|
|
166
|
+
error.nativeCode === 'ITEM_NOT_FOUND')
|
|
167
|
+
return undefined;
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const project = (raw) => {
|
|
172
|
+
// The ruleset's real data space, read before anything is projected.
|
|
173
|
+
const found = identityResolutionSpace(raw);
|
|
174
|
+
if (found !== dataSpace)
|
|
175
|
+
throw identityResolutionSpaceMismatch(desired.identity.apiName, found, dataSpace, 'org');
|
|
176
|
+
return verbatim
|
|
177
|
+
? rawOwner(raw, desired.identity.apiName)
|
|
178
|
+
: projectNativeIdentityResolution(raw, desired.identity.apiName, 'retrieve');
|
|
179
|
+
};
|
|
180
|
+
const work = async () => {
|
|
181
|
+
await input();
|
|
182
|
+
const raw = await read(desired.identity.apiName);
|
|
183
|
+
if (raw === undefined) {
|
|
184
|
+
await input();
|
|
185
|
+
if ((await read(desired.identity.apiName)) !== undefined)
|
|
186
|
+
throw new Error('Owner appeared');
|
|
187
|
+
return result('unchanged');
|
|
188
|
+
}
|
|
189
|
+
const baseline = project(raw);
|
|
190
|
+
const id = baseline.expectations.native.id;
|
|
191
|
+
if (typeof id !== 'string' ||
|
|
192
|
+
!/^1ir[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/u.test(id) ||
|
|
193
|
+
(!verbatim && !isDeepStrictEqual(baseline.candidate, desired)))
|
|
194
|
+
throw new Error('Owner mismatch');
|
|
195
|
+
// A DELETE while the API is still processing the ruleset could not be told apart from it.
|
|
196
|
+
if (inFlightIdentityResolutionStatuses.includes(String(baseline.expectations.native.rulesetStatus)))
|
|
197
|
+
return result('blocked', 'IDENTITY_RESOLUTION_NOT_SETTLED');
|
|
198
|
+
if (!isDeepStrictEqual(project(await read(id)), baseline))
|
|
199
|
+
throw new Error('Identity mismatch');
|
|
200
|
+
// Existing binders establish selected input/output compatibility, not reverse consumers.
|
|
201
|
+
// A verbatim file names no inputs or outputs the plugin can bind; it goes by its name.
|
|
202
|
+
const dependencies = verbatim
|
|
203
|
+
? { fingerprint: '0'.repeat(64) }
|
|
204
|
+
: await (options.verifyDependencies ?? bindIdentityResolutionDependencies)(structuredClone(desired), receiver, { ...frozen }, dataSpace, undefined, 'retrieve');
|
|
205
|
+
check();
|
|
206
|
+
if (!/^[a-f0-9]{64}$/u.test(dependencies?.fingerprint))
|
|
207
|
+
throw new Error('Dependency proof');
|
|
208
|
+
const expected = baseline.expectations.outputs.map(({ identity, sourceApiName }) => ({
|
|
209
|
+
identity: structuredClone(identity),
|
|
210
|
+
targetApiName: sourceApiName,
|
|
211
|
+
}));
|
|
212
|
+
const outputs = verbatim
|
|
213
|
+
? []
|
|
214
|
+
: await (options.verifyOutputs ?? verifyIdentityResolutionOutputs)({ targetApiName: desired.identity.apiName, targetId: id, dataSpace }, expected, receiver, { ...frozen }, undefined, undefined, 'retrieve');
|
|
215
|
+
check();
|
|
216
|
+
if (!Array.isArray(outputs) || outputs.length !== expected.length)
|
|
217
|
+
throw new Error('Output proof');
|
|
218
|
+
const ids = new Set([id]);
|
|
219
|
+
for (const [index, binding] of outputs.entries()) {
|
|
220
|
+
if (!isDeepStrictEqual(binding.identity, expected[index].identity) ||
|
|
221
|
+
binding.targetApiName !== expected[index].targetApiName ||
|
|
222
|
+
typeof binding.targetId !== 'string' ||
|
|
223
|
+
!binding.targetId.trim() ||
|
|
224
|
+
ids.has(binding.targetId))
|
|
225
|
+
throw new Error('Output mismatch');
|
|
226
|
+
ids.add(binding.targetId);
|
|
227
|
+
}
|
|
228
|
+
await input();
|
|
229
|
+
if (!isDeepStrictEqual(project(await read(desired.identity.apiName)), baseline) ||
|
|
230
|
+
!isDeepStrictEqual(project(await read(id)), baseline))
|
|
231
|
+
throw new Error('Owner drift');
|
|
232
|
+
await input();
|
|
233
|
+
if (preview)
|
|
234
|
+
return result('delete');
|
|
235
|
+
if (options.confirmDelete !== true)
|
|
236
|
+
return result('blocked', 'DESTRUCTIVE_CONFIRMATION_REQUIRED');
|
|
237
|
+
attempted = true;
|
|
238
|
+
await client.deleteIdentityResolution(id);
|
|
239
|
+
check();
|
|
240
|
+
for (let attempt = 0; attempt < identityResolutionDeleteBudget.reads; attempt++) {
|
|
241
|
+
if (attempt > 0) {
|
|
242
|
+
check();
|
|
243
|
+
await wait(identityResolutionDeleteBudget.intervalMs);
|
|
244
|
+
}
|
|
245
|
+
check();
|
|
246
|
+
const byId = await read(id);
|
|
247
|
+
const byName = await read(desired.identity.apiName);
|
|
248
|
+
if (byId === undefined && byName === undefined)
|
|
249
|
+
return result('deleted');
|
|
250
|
+
for (const observed of [byId, byName]) {
|
|
251
|
+
if (observed === undefined)
|
|
252
|
+
continue;
|
|
253
|
+
const transitional = structuredClone(observed);
|
|
254
|
+
if (!transitional || transitional.rulesetStatus !== 'DELETING')
|
|
255
|
+
throw new Error('Not deleting');
|
|
256
|
+
// An acknowledged DELETE can strip reconciliation/output references while DELETING.
|
|
257
|
+
// Restore only the evidenced empty array for comparison, never for absence or replay.
|
|
258
|
+
if (isDeepStrictEqual(transitional.reconciliationRules, []))
|
|
259
|
+
transitional.reconciliationRules = structuredClone(baseline.expectations.native.reconciliationRules);
|
|
260
|
+
transitional.rulesetStatus = baseline.expectations.native.rulesetStatus;
|
|
261
|
+
if (!isDeepStrictEqual(project(transitional), baseline))
|
|
262
|
+
throw new Error('Readback drift');
|
|
263
|
+
}
|
|
264
|
+
if (byId !== undefined && byName !== undefined)
|
|
265
|
+
return result('deletion-processing');
|
|
266
|
+
}
|
|
267
|
+
check();
|
|
268
|
+
throw new Error('Read budget');
|
|
269
|
+
};
|
|
270
|
+
return await Promise.race([
|
|
271
|
+
work(),
|
|
272
|
+
new Promise((_resolve, reject) => {
|
|
273
|
+
timer = setTimeout(() => {
|
|
274
|
+
expired = true;
|
|
275
|
+
reject(new Error('Deadline'));
|
|
276
|
+
}, identityResolutionDeleteBudget.timeoutMs);
|
|
277
|
+
}),
|
|
278
|
+
]);
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
// A file or ruleset of another data space, or a component it names there: its own code.
|
|
282
|
+
if (!attempted && error instanceof IdentityResolutionError && /DATASPACE/u.test(error.code))
|
|
283
|
+
return {
|
|
284
|
+
...result('blocked'),
|
|
285
|
+
diagnostics: [{ code: error.code, message: explanationOf(error) ?? error.message }],
|
|
286
|
+
};
|
|
287
|
+
return result(attempted ? 'failed' : 'blocked', attempted
|
|
288
|
+
? 'IDENTITY_RESOLUTION_DELETION_UNCONFIRMED'
|
|
289
|
+
: 'IDENTITY_RESOLUTION_DELETE_ADMISSION_FAILED', error);
|
|
290
|
+
}
|
|
291
|
+
finally {
|
|
292
|
+
expired = true;
|
|
293
|
+
clearTimeout(timer);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Connection } from '@salesforce/core';
|
|
2
|
+
import type { ApiVersionSelection } from '../transport/api-version.js';
|
|
3
|
+
import { bindSegmentDependencies } from './bind-segment-dependencies.js';
|
|
4
|
+
export declare const segmentDeleteBudget: Readonly<{
|
|
5
|
+
reads: 12;
|
|
6
|
+
intervalMs: 1000;
|
|
7
|
+
timeoutMs: 120000;
|
|
8
|
+
}>;
|
|
9
|
+
export type SegmentDeleteOptions = {
|
|
10
|
+
preview?: boolean;
|
|
11
|
+
confirmDelete: boolean;
|
|
12
|
+
verifyInput: () => Promise<void>;
|
|
13
|
+
bind?: typeof bindSegmentDependencies;
|
|
14
|
+
now?: () => number;
|
|
15
|
+
delay?: (milliseconds: number) => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
export type SegmentDeleteResult = {
|
|
18
|
+
family: 'segment';
|
|
19
|
+
outcome: 'delete' | 'deleted' | 'deletion-processing' | 'unchanged' | 'blocked' | 'failed';
|
|
20
|
+
mutation: 'not-attempted' | 'confirmed-deleted' | 'acknowledged-processing' | 'unknown';
|
|
21
|
+
requiredEffects: Array<'destructive'>;
|
|
22
|
+
diagnostics: Array<{
|
|
23
|
+
code: string;
|
|
24
|
+
message: string;
|
|
25
|
+
}>;
|
|
26
|
+
};
|
|
27
|
+
type TargetConnection = Pick<Connection, 'instanceUrl' | 'request' | 'getApiVersion' | 'getUsername'>;
|
|
28
|
+
/**
|
|
29
|
+
* Delete one exact native68 JSON-matched Segment, without replay or generated-resource cleanup.
|
|
30
|
+
* Bindings establish selected source compatibility, not exhaustive external-consumer exclusion.
|
|
31
|
+
* A verbatim file (a segment the plugin cannot model, such as one built in the UI) is deleted by
|
|
32
|
+
* name: the GET must name the same segment in the run's data space and keep a deletable status,
|
|
33
|
+
* and must not change between the reads; its definition and source DMO are not compared.
|
|
34
|
+
* @param {unknown} value Complete local JSON expectation, or a verbatim file; not ownership authority.
|
|
35
|
+
* @param {TargetConnection} connection Fixed authenticated target.
|
|
36
|
+
* @param {ApiVersionSelection} selection Exact API68 selection.
|
|
37
|
+
* @param {string} dataSpace The run's data space; the file's c__dataSpace must name it.
|
|
38
|
+
* @param {SegmentDeleteOptions} options Preview, destructive confirmation and fresh input guard.
|
|
39
|
+
* @returns {Promise<SegmentDeleteResult>} Payload-free independent absence or preserved transition.
|
|
40
|
+
*/
|
|
41
|
+
export declare function deleteSegment(value: unknown, connection: TargetConnection, selection: ApiVersionSelection, dataSpace: string, options: SegmentDeleteOptions): Promise<SegmentDeleteResult>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
import { SegmentError, carriesDefinition, validateSegmentDocument, } from '../artifacts/segment-document.js';
|
|
4
|
+
import { isVerbatimDocument, verbatimDataSpace } from '../artifacts/verbatim-document.js';
|
|
5
|
+
import { ConnectClient, ConnectError } from '../transport/connect-client.js';
|
|
6
|
+
import { getConnectDiagnostic, retainConnectDiagnostic } from '../transport/connect-diagnostic.js';
|
|
7
|
+
import { bindSegmentDependencies } from './bind-segment-dependencies.js';
|
|
8
|
+
import { projectSegment, segmentChildNames, segmentSpaceMismatch } from './retrieve-segment.js';
|
|
9
|
+
import { operationDiagnostic } from './operation-diagnostic.js';
|
|
10
|
+
export const segmentDeleteBudget = Object.freeze({
|
|
11
|
+
reads: 12,
|
|
12
|
+
intervalMs: 1000,
|
|
13
|
+
timeoutMs: 120_000,
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Preserve the complete selected definition and private identity, excluding volatile observations.
|
|
17
|
+
* @param {Record<string, unknown>} runtime Strict independently projected runtime.
|
|
18
|
+
* @returns {Record<string, unknown>} Detached stable comparison baseline.
|
|
19
|
+
*/
|
|
20
|
+
function preservation(runtime) {
|
|
21
|
+
const result = structuredClone(runtime);
|
|
22
|
+
for (const key of [
|
|
23
|
+
'segmentStatus',
|
|
24
|
+
'lastModifiedBy',
|
|
25
|
+
'lastModifiedDate',
|
|
26
|
+
'lastSegmentMemberCount',
|
|
27
|
+
])
|
|
28
|
+
delete result[key];
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The segment inside a raw GET, checked only for what names and places it: the same API name in
|
|
33
|
+
* the run's data space. Used for a verbatim file, whose segment the plugin cannot model.
|
|
34
|
+
* @param {unknown} response Raw GET response.
|
|
35
|
+
* @param {string} apiName Selected name.
|
|
36
|
+
* @param {string} dataSpace The run's data space.
|
|
37
|
+
* @returns {{candidate: undefined; runtime: Record<string, unknown>}} The raw segment.
|
|
38
|
+
*/
|
|
39
|
+
function rawSegment(response, apiName, dataSpace) {
|
|
40
|
+
const segments = response?.segments;
|
|
41
|
+
const value = Array.isArray(segments) ? segments[0] : undefined;
|
|
42
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
43
|
+
throw new SegmentError('INVALID_SEGMENT_RESPONSE');
|
|
44
|
+
const raw = value;
|
|
45
|
+
if (raw.apiName !== apiName)
|
|
46
|
+
throw new SegmentError('SEGMENT_IDENTITY_MISMATCH');
|
|
47
|
+
if (raw.dataSpace !== dataSpace)
|
|
48
|
+
throw segmentSpaceMismatch(apiName, raw.dataSpace, dataSpace);
|
|
49
|
+
return { candidate: undefined, runtime: structuredClone(raw) };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Delete one exact native68 JSON-matched Segment, without replay or generated-resource cleanup.
|
|
53
|
+
* Bindings establish selected source compatibility, not exhaustive external-consumer exclusion.
|
|
54
|
+
* A verbatim file (a segment the plugin cannot model, such as one built in the UI) is deleted by
|
|
55
|
+
* name: the GET must name the same segment in the run's data space and keep a deletable status,
|
|
56
|
+
* and must not change between the reads; its definition and source DMO are not compared.
|
|
57
|
+
* @param {unknown} value Complete local JSON expectation, or a verbatim file; not ownership authority.
|
|
58
|
+
* @param {TargetConnection} connection Fixed authenticated target.
|
|
59
|
+
* @param {ApiVersionSelection} selection Exact API68 selection.
|
|
60
|
+
* @param {string} dataSpace The run's data space; the file's c__dataSpace must name it.
|
|
61
|
+
* @param {SegmentDeleteOptions} options Preview, destructive confirmation and fresh input guard.
|
|
62
|
+
* @returns {Promise<SegmentDeleteResult>} Payload-free independent absence or preserved transition.
|
|
63
|
+
*/
|
|
64
|
+
export async function deleteSegment(value, connection, selection, dataSpace, options) {
|
|
65
|
+
let attempted = false;
|
|
66
|
+
const result = (outcome, code, error) => retainConnectDiagnostic({
|
|
67
|
+
family: 'segment',
|
|
68
|
+
outcome,
|
|
69
|
+
mutation: attempted
|
|
70
|
+
? outcome === 'deleted'
|
|
71
|
+
? 'confirmed-deleted'
|
|
72
|
+
: outcome === 'deletion-processing'
|
|
73
|
+
? 'acknowledged-processing'
|
|
74
|
+
: 'unknown'
|
|
75
|
+
: 'not-attempted',
|
|
76
|
+
requiredEffects: outcome === 'delete' ? ['destructive'] : [],
|
|
77
|
+
diagnostics: code
|
|
78
|
+
? [
|
|
79
|
+
{
|
|
80
|
+
code,
|
|
81
|
+
message: operationDiagnostic(error, attempted
|
|
82
|
+
? 'Segment deletion may have occurred; absence is unconfirmed. No replay, fallback or rollback was performed.'
|
|
83
|
+
: 'Segment deletion was not attempted; input, scope, identity, definition or binding is unqualified.'),
|
|
84
|
+
},
|
|
85
|
+
]
|
|
86
|
+
: [],
|
|
87
|
+
}, getConnectDiagnostic(error));
|
|
88
|
+
try {
|
|
89
|
+
// Read as retrieve writes it: the file and the GET may keep keys the plugin does not model.
|
|
90
|
+
const verbatim = isVerbatimDocument(value, 'segment');
|
|
91
|
+
const desired = verbatim
|
|
92
|
+
? { identity: { ...value.identity } }
|
|
93
|
+
: validateSegmentDocument(value, 'retrieve');
|
|
94
|
+
const admit = () => verbatim ? { identity: { ...value.identity } } : validateSegmentDocument(value, 'retrieve');
|
|
95
|
+
// The file (or the verbatim stand-in) names the run's data space.
|
|
96
|
+
const named = verbatim ? verbatimDataSpace(value) : desired.c__dataSpace;
|
|
97
|
+
if (named !== dataSpace)
|
|
98
|
+
throw segmentSpaceMismatch(desired.identity.apiName, named, dataSpace);
|
|
99
|
+
const frozen = { ...selection };
|
|
100
|
+
const origin = connection.instanceUrl;
|
|
101
|
+
const request = connection.request;
|
|
102
|
+
const preview = options.preview === true;
|
|
103
|
+
const confirmed = options.confirmDelete;
|
|
104
|
+
const verify = options.verifyInput;
|
|
105
|
+
const now = options.now ?? Date.now;
|
|
106
|
+
const started = now();
|
|
107
|
+
let previous = started;
|
|
108
|
+
const check = () => {
|
|
109
|
+
const current = now();
|
|
110
|
+
if (!Number.isFinite(started) ||
|
|
111
|
+
!Number.isFinite(current) ||
|
|
112
|
+
current < previous ||
|
|
113
|
+
current - started >= segmentDeleteBudget.timeoutMs ||
|
|
114
|
+
frozen.requested !== '68.0' ||
|
|
115
|
+
frozen.restSelector !== 'v68.0' ||
|
|
116
|
+
frozen.soapNumeric !== '68.0' ||
|
|
117
|
+
!isDeepStrictEqual(selection, frozen) ||
|
|
118
|
+
connection.getApiVersion() !== '68.0' ||
|
|
119
|
+
connection.instanceUrl !== origin ||
|
|
120
|
+
connection.request !== request ||
|
|
121
|
+
dataSpace !== named ||
|
|
122
|
+
(options.preview === true) !== preview ||
|
|
123
|
+
options.confirmDelete !== confirmed ||
|
|
124
|
+
typeof verify !== 'function' ||
|
|
125
|
+
options.verifyInput !== verify ||
|
|
126
|
+
!isDeepStrictEqual(admit(), desired))
|
|
127
|
+
throw new Error('Scope, intent or deadline drift');
|
|
128
|
+
previous = current;
|
|
129
|
+
};
|
|
130
|
+
const input = async () => {
|
|
131
|
+
check();
|
|
132
|
+
await verify();
|
|
133
|
+
check();
|
|
134
|
+
};
|
|
135
|
+
check();
|
|
136
|
+
const client = new ConnectClient(connection, frozen);
|
|
137
|
+
const read = async () => {
|
|
138
|
+
check();
|
|
139
|
+
try {
|
|
140
|
+
const raw = await client.get(`/services/data/v68.0/ssot/segments/${desired.identity.apiName}`);
|
|
141
|
+
check();
|
|
142
|
+
if (verbatim)
|
|
143
|
+
return rawSegment(raw, desired.identity.apiName, dataSpace);
|
|
144
|
+
const found = raw?.segments?.[0]?.dataSpace;
|
|
145
|
+
if (found !== dataSpace)
|
|
146
|
+
throw segmentSpaceMismatch(desired.identity.apiName, found, dataSpace);
|
|
147
|
+
// Waterfall children are compared by name, as retrieve wrote them.
|
|
148
|
+
const children = await segmentChildNames(connection, raw);
|
|
149
|
+
check();
|
|
150
|
+
return projectSegment(raw, desired.identity.apiName, 'retrieve', children);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
check();
|
|
154
|
+
if (error instanceof ConnectError &&
|
|
155
|
+
error.statusCode === 404 &&
|
|
156
|
+
error.nativeCode === 'ITEM_NOT_FOUND')
|
|
157
|
+
return undefined;
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
await input();
|
|
162
|
+
const baseline = await read();
|
|
163
|
+
if (!baseline) {
|
|
164
|
+
await input();
|
|
165
|
+
if (await read())
|
|
166
|
+
throw new Error('Target appeared');
|
|
167
|
+
return result('unchanged');
|
|
168
|
+
}
|
|
169
|
+
const runtime = baseline.runtime;
|
|
170
|
+
if (verbatim) {
|
|
171
|
+
if (!['ACTIVE', 'PROCESSING', 'COUNTING'].includes(String(runtime.segmentStatus)))
|
|
172
|
+
throw new Error('Target status');
|
|
173
|
+
}
|
|
174
|
+
else if (!carriesDefinition(baseline.candidate, desired) ||
|
|
175
|
+
!['ACTIVE', 'PROCESSING', 'COUNTING'].includes(String(runtime.segmentStatus)) ||
|
|
176
|
+
typeof runtime.marketSegmentId !== 'string' ||
|
|
177
|
+
!/^1sg[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/u.test(runtime.marketSegmentId) ||
|
|
178
|
+
typeof runtime.marketSegmentDefinitionId !== 'string' ||
|
|
179
|
+
!/^3HX[A-Za-z0-9]{12}(?:[A-Za-z0-9]{3})?$/u.test(runtime.marketSegmentDefinitionId) ||
|
|
180
|
+
typeof runtime.createdDate !== 'string' ||
|
|
181
|
+
!runtime.createdDate ||
|
|
182
|
+
!runtime.segmentMembershipDmo)
|
|
183
|
+
throw new Error('Target identity or definition');
|
|
184
|
+
// A verbatim file names no source DMO the plugin can bind; the segment goes by its name.
|
|
185
|
+
const bind = options.bind ?? bindSegmentDependencies;
|
|
186
|
+
const document = desired;
|
|
187
|
+
const bindings = verbatim
|
|
188
|
+
? []
|
|
189
|
+
: await bind(document, connection, frozen, dataSpace, undefined, 'retrieve');
|
|
190
|
+
check();
|
|
191
|
+
if (!verbatim && (bindings.length !== 1 || runtime.segmentOnId !== bindings[0].targetId))
|
|
192
|
+
throw new Error('Source identity');
|
|
193
|
+
const matches = (observed) => isDeepStrictEqual(observed.candidate, baseline.candidate) &&
|
|
194
|
+
isDeepStrictEqual(preservation(observed.runtime), preservation(runtime));
|
|
195
|
+
await input();
|
|
196
|
+
if (!verbatim &&
|
|
197
|
+
!isDeepStrictEqual(bindings, await bind(document, connection, frozen, dataSpace, undefined, 'retrieve')))
|
|
198
|
+
throw new Error('Dependency drift');
|
|
199
|
+
check();
|
|
200
|
+
const fresh = await read();
|
|
201
|
+
if (!fresh ||
|
|
202
|
+
!matches(fresh) ||
|
|
203
|
+
!['ACTIVE', 'PROCESSING', 'COUNTING'].includes(String(fresh.runtime.segmentStatus)))
|
|
204
|
+
throw new Error('Target drift');
|
|
205
|
+
await input();
|
|
206
|
+
if (preview)
|
|
207
|
+
return result('delete');
|
|
208
|
+
if (options.confirmDelete !== true)
|
|
209
|
+
return result('blocked', 'DESTRUCTIVE_CONFIRMATION_REQUIRED');
|
|
210
|
+
check();
|
|
211
|
+
attempted = true;
|
|
212
|
+
// HTTP204 proves only acknowledgement. A failed/uncertain DELETE never becomes success.
|
|
213
|
+
let failure;
|
|
214
|
+
try {
|
|
215
|
+
await client.deleteSegment(desired.identity.apiName);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
failure = error;
|
|
219
|
+
}
|
|
220
|
+
check();
|
|
221
|
+
for (let attempt = 0; attempt < segmentDeleteBudget.reads; attempt++) {
|
|
222
|
+
if (attempt > 0)
|
|
223
|
+
await (options.delay ?? delay)(segmentDeleteBudget.intervalMs);
|
|
224
|
+
check();
|
|
225
|
+
const observed = await read();
|
|
226
|
+
if (failure)
|
|
227
|
+
return result('failed', 'SEGMENT_DELETION_UNCONFIRMED', failure);
|
|
228
|
+
if (!observed)
|
|
229
|
+
return result('deleted');
|
|
230
|
+
if (!matches(observed))
|
|
231
|
+
throw new Error('Readback mismatch');
|
|
232
|
+
if (observed.runtime.segmentStatus === 'DELETING' ||
|
|
233
|
+
(fresh.runtime.segmentStatus === 'ACTIVE' &&
|
|
234
|
+
observed.runtime.segmentStatus === 'PROCESSING'))
|
|
235
|
+
return result('deletion-processing');
|
|
236
|
+
if (!['ACTIVE', 'COUNTING', 'PROCESSING'].includes(String(observed.runtime.segmentStatus)))
|
|
237
|
+
throw new Error('Unknown lifecycle');
|
|
238
|
+
}
|
|
239
|
+
throw new Error('Read budget');
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
return result(attempted ? 'failed' : 'blocked', attempted
|
|
243
|
+
? 'SEGMENT_DELETION_UNCONFIRMED'
|
|
244
|
+
: error instanceof SegmentError && error.code === 'SEGMENT_DATASPACE_MISMATCH'
|
|
245
|
+
? error.code
|
|
246
|
+
: 'SEGMENT_DELETE_ADMISSION_FAILED', error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Payload-free preview classification shared by the per-item deploy routes. */
|
|
2
|
+
export type DeployPreviewResult = {
|
|
3
|
+
outcome: 'create' | 'update' | 'unchanged' | 'blocked-changes' | 'blocked';
|
|
4
|
+
target: 'absent' | 'present' | 'unknown';
|
|
5
|
+
absenceProof: 'complete-inventory' | 'none';
|
|
6
|
+
diagnostics: Array<{
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
/** Per-item execution outcome with explicit mutation evidence, shared by the deploy routes. */
|
|
12
|
+
export type DeployExecutionResult = {
|
|
13
|
+
outcome: 'unchanged' | 'blocked' | 'created' | 'failed' | 'updated' | 'creation-processing' | 'update-processing' | 'not-attempted';
|
|
14
|
+
mutation: 'not-attempted' | 'confirmed-created' | 'confirmed-updated' | 'acknowledged-processing' | 'unknown' | 'rejected';
|
|
15
|
+
preflight?: DeployPreviewResult;
|
|
16
|
+
diagnostics: Array<{
|
|
17
|
+
code: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
/** Next action when Salesforce refused the item's first write: nothing was applied for it. */
|
|
22
|
+
export declare const rejectedNextAction = "Salesforce rejected the write and nothing was written for this item; correct the input before another attempt.";
|
|
23
|
+
/**
|
|
24
|
+
* Count the writes of one item, so a failure can say whether anything was applied. Only the
|
|
25
|
+
* item's first write, answered by Salesforce with an HTTP 4xx status or a Metadata API refusal
|
|
26
|
+
* (`*_UPDATE_REJECTED`), is known to have changed nothing; every other failure after the first
|
|
27
|
+
* dispatch stays unknown.
|
|
28
|
+
*/
|
|
29
|
+
export declare class WriteLedger {
|
|
30
|
+
private started;
|
|
31
|
+
private completed;
|
|
32
|
+
private refusal;
|
|
33
|
+
/**
|
|
34
|
+
* Whether any write was sent.
|
|
35
|
+
* @returns {boolean} True after the first dispatch.
|
|
36
|
+
*/
|
|
37
|
+
get dispatched(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Run one write and record how it ended.
|
|
40
|
+
* @template T
|
|
41
|
+
* @param {Function} write The single write.
|
|
42
|
+
* @returns {Promise<T>} Its result.
|
|
43
|
+
*/
|
|
44
|
+
run<T>(write: () => Promise<T>): Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Classify a failure of the item.
|
|
47
|
+
* @param {unknown} error The error that ended the item.
|
|
48
|
+
* @returns {object} Outcome and mutation for the result item.
|
|
49
|
+
*/
|
|
50
|
+
failure(error: unknown): {
|
|
51
|
+
outcome: 'failed' | 'blocked';
|
|
52
|
+
mutation: 'rejected' | 'unknown' | 'not-attempted';
|
|
53
|
+
};
|
|
54
|
+
}
|