sf-plugin-data 0.0.0-stage → 0.1.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.
@@ -0,0 +1,208 @@
1
+ import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
2
+ import { DeployInputError, readDeployInputs } from '../../artifacts/read-deploy-input.js';
3
+ import { preflightDmoDeploy } from '../../services/preflight-dmo-deploy.js';
4
+ import { executeDmoDeploy } from '../../services/execute-dmo-deploy.js';
5
+ import { plugin as packageMetadata } from '../../plugin.js';
6
+ /** Preview or sequential guarded deployment of explicitly selected authored configuration. */
7
+ export default class Deploy extends SfCommand {
8
+ static aliases = ['datacloud:deploy', 'd360:deploy', 'dc:deploy'];
9
+ static summary = 'Deploy explicit authored Data360 configuration or preview without writes.';
10
+ static description = 'Requires explicit files/directories OR exact dmo:ApiName selectors. Repeated selections coalesce. Bare types and implicit deploy-all are forbidden. Preview is strictly read-only. Execution preflights the whole selection, then creates or updates only object and existing non-primary field labels sequentially with fresh checks and qualified readback. Other changes block before writes. Stops on first blocked or failed item; no retry or rollback. No local report/artifact writes.';
11
+ static flags = {
12
+ 'target-org': Flags.optionalOrg(),
13
+ 'api-version': Flags.orgApiVersion({
14
+ default: '65.0',
15
+ summary: 'Target API version (currently 65.0).',
16
+ }),
17
+ 'data-space': Flags.string({
18
+ default: 'default',
19
+ summary: 'Target logical data space (currently default).',
20
+ }),
21
+ 'source-dir': Flags.string({
22
+ char: 'd',
23
+ multiple: true,
24
+ multipleNonGreedy: true,
25
+ summary: 'Explicit authored JSON file or directory; repeatable.',
26
+ }),
27
+ metadata: Flags.string({
28
+ char: 'm',
29
+ multiple: true,
30
+ multipleNonGreedy: true,
31
+ summary: 'Exact dmo:ApiName project member; repeatable.',
32
+ }),
33
+ preview: Flags.boolean({
34
+ default: false,
35
+ summary: 'Strictly read-only target comparison; never executes deployment.',
36
+ }),
37
+ };
38
+ resolveInputs = readDeployInputs;
39
+ preflight = preflightDmoDeploy;
40
+ execute = executeDmoDeploy;
41
+ /**
42
+ * Validate all inputs and preflight the whole selection before any sequential execution.
43
+ * @returns {Promise<DeployEnvelope>} Versioned preview or execution outcomes with mutation evidence.
44
+ */
45
+ async run() {
46
+ const { flags } = await this.parse(Deploy);
47
+ const cwd = process.cwd();
48
+ const plugin = {
49
+ name: packageMetadata.name,
50
+ version: packageMetadata.version,
51
+ };
52
+ const envelope = {
53
+ contract: 'sf-data360-deploy',
54
+ contractVersion: '1.0.0',
55
+ status: 'blocked',
56
+ metadata: {
57
+ operation: 'deploy',
58
+ preview: flags.preview,
59
+ plugin,
60
+ apiVersion: flags['api-version'],
61
+ },
62
+ diagnostics: { warnings: [], errors: [] },
63
+ provenance: {
64
+ producer: plugin.name,
65
+ // eslint-disable-next-line unicorn/no-null -- Stable JSON represents unresolved target identity explicitly.
66
+ targetOrgId: null,
67
+ pluginVersion: plugin.version,
68
+ command: 'sf data360 deploy',
69
+ generatedAt: new Date().toISOString(),
70
+ },
71
+ result: {
72
+ scope: { dataSpace: flags['data-space'] },
73
+ selection: { sourceDir: flags['source-dir'] ?? [], metadata: flags.metadata ?? [] },
74
+ items: [],
75
+ },
76
+ };
77
+ const finish = (status, code) => {
78
+ envelope.status = status;
79
+ if (code)
80
+ envelope.diagnostics.errors.push({
81
+ code,
82
+ message: flags.preview
83
+ ? 'Preview did not complete. Check explicit authored inputs, target authentication and supported scope. No deployment executed.'
84
+ : 'Deployment did not complete. Check item outcomes, explicit inputs, target authentication and supported scope. Mutation may have occurred for unknown mutations; inspect target before any further attempt. No automatic retry or rollback was performed.',
85
+ retryable: false,
86
+ });
87
+ if (status !== 'success')
88
+ process.exitCode = 1;
89
+ if (!this.jsonEnabled()) {
90
+ this.log(flags.preview
91
+ ? `Deploy preview: ${status}${code ? ` (${code})` : ''}. No deployment executed.`
92
+ : `Deploy execution: ${status}${code ? ` (${code})` : ''}. No automatic retry or rollback performed.`);
93
+ for (const item of envelope.result.items) {
94
+ this.log(item.operation === 'preview'
95
+ ? `Preview: ${item.outcome}.`
96
+ : `Execution: ${item.outcome}; mutation: ${item.mutation}.`);
97
+ if (item.operation === 'execute' && item.mutation === 'unknown')
98
+ this.log('Mutation may have occurred. Inspect target before any further attempt.');
99
+ }
100
+ }
101
+ return envelope;
102
+ };
103
+ try {
104
+ const inputs = await this.resolveInputs({
105
+ cwd,
106
+ sourceDir: flags['source-dir'],
107
+ metadata: flags.metadata,
108
+ });
109
+ if (inputs.length === 0)
110
+ return finish('blocked', 'INVALID_SELECTION');
111
+ const org = flags['target-org'];
112
+ if (!org)
113
+ return finish('blocked', 'TARGET_ORG_REQUIRED');
114
+ envelope.provenance.targetOrgId = org.getOrgId();
115
+ const connection = org.getConnection(flags['api-version']);
116
+ let failed = false;
117
+ let blocked = false;
118
+ for (const input of inputs) {
119
+ try {
120
+ const preview = await this.preflight(input.document, connection, flags['api-version'], flags['data-space'], true);
121
+ envelope.result.items.push({
122
+ ...preview,
123
+ identity: { ...input.document.identity },
124
+ operation: 'preview',
125
+ path: input.path,
126
+ });
127
+ if (preview.outcome === 'blocked' || preview.outcome === 'blocked-changes')
128
+ blocked = true;
129
+ }
130
+ catch {
131
+ failed = true;
132
+ envelope.result.items.push({
133
+ identity: { ...input.document.identity },
134
+ operation: 'preview',
135
+ path: input.path,
136
+ outcome: 'blocked',
137
+ target: 'unknown',
138
+ absenceProof: 'none',
139
+ diagnostics: [
140
+ {
141
+ code: 'PREFLIGHT_FAILED',
142
+ message: 'Target preview failed; no deployment was executed.',
143
+ },
144
+ ],
145
+ });
146
+ }
147
+ }
148
+ if (!flags.preview) {
149
+ const items = inputs.map((input, index) => {
150
+ const { outcome, target, absenceProof, diagnostics } = envelope.result.items[index];
151
+ return {
152
+ identity: { ...input.document.identity },
153
+ operation: 'execute',
154
+ path: input.path,
155
+ outcome: 'not-attempted',
156
+ mutation: 'not-attempted',
157
+ preflight: { outcome, target, absenceProof, diagnostics },
158
+ diagnostics: [],
159
+ };
160
+ });
161
+ // Keep whole-selection evidence, but never mistake admission for attempted execution.
162
+ envelope.result.items = items;
163
+ if (!failed && !blocked) {
164
+ for (const [index, input] of inputs.entries()) {
165
+ const item = items[index];
166
+ // Set conservative evidence before awaiting; an unexpected throw cannot erase it.
167
+ item.outcome = 'failed';
168
+ item.mutation = 'unknown';
169
+ try {
170
+ const result = await this.execute(input.document, connection, flags['api-version'], flags['data-space']);
171
+ Object.assign(item, result);
172
+ }
173
+ catch {
174
+ item.diagnostics = [
175
+ {
176
+ code: 'EXECUTION_UNCONFIRMED',
177
+ message: 'Mutation may have occurred. Inspect target before any further attempt; no retry or rollback was performed.',
178
+ },
179
+ ];
180
+ }
181
+ if (item.mutation === 'unknown' || item.outcome === 'failed') {
182
+ failed = true;
183
+ break;
184
+ }
185
+ if (item.outcome === 'blocked') {
186
+ blocked = true;
187
+ break;
188
+ }
189
+ }
190
+ }
191
+ }
192
+ return finish(failed ? 'failed' : blocked ? 'blocked' : 'success', failed
193
+ ? flags.preview
194
+ ? 'PREFLIGHT_FAILED'
195
+ : 'DEPLOY_EXECUTION_FAILED'
196
+ : blocked
197
+ ? flags.preview
198
+ ? 'DEPLOY_PREVIEW_BLOCKED'
199
+ : 'DEPLOY_EXECUTION_BLOCKED'
200
+ : undefined);
201
+ }
202
+ catch (error) {
203
+ if (error instanceof DeployInputError)
204
+ return finish('blocked', error.code);
205
+ return finish('failed', flags.preview ? 'DEPLOY_PREVIEW_FAILED' : 'DEPLOY_EXECUTION_FAILED');
206
+ }
207
+ }
208
+ }
@@ -0,0 +1,75 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ import { Org } from '@salesforce/core';
3
+ import { writeDmoDocument } from '../../artifacts/write-other-dmo.js';
4
+ import { retrieveDmo, selectDmos } from '../../services/retrieve-other-dmo.js';
5
+ export type RetrieveEnvelope = {
6
+ contract: 'sf-data360-retrieve';
7
+ contractVersion: '1.0.0';
8
+ status: 'success' | 'blocked' | 'failed';
9
+ metadata: {
10
+ operation: 'retrieve';
11
+ plugin: {
12
+ name: string;
13
+ version: string;
14
+ };
15
+ apiVersion: string;
16
+ };
17
+ diagnostics: {
18
+ warnings: string[];
19
+ errors: Array<{
20
+ code: string;
21
+ message: string;
22
+ retryable: false;
23
+ identity?: {
24
+ dataSpace: string;
25
+ apiName: string;
26
+ };
27
+ }>;
28
+ };
29
+ provenance: {
30
+ producer: string;
31
+ sourceOrgId: string | null;
32
+ pluginVersion: string;
33
+ command: string;
34
+ generatedAt: string;
35
+ };
36
+ result: {
37
+ scope: {
38
+ dataSpace: string;
39
+ outputDir: string;
40
+ };
41
+ selection: string[];
42
+ items: Array<{
43
+ identity: {
44
+ dataSpace: string;
45
+ apiName: string;
46
+ };
47
+ operation: 'retrieve';
48
+ outcome: 'retrieved' | 'unchanged';
49
+ path: string;
50
+ }>;
51
+ };
52
+ };
53
+ /** Retrieve selected DMO configuration through existing service-owned capability checks. */
54
+ export default class Retrieve extends SfCommand<RetrieveEnvelope> {
55
+ static readonly aliases: string[];
56
+ static readonly summary = "Retrieve Data360 DMOs into a local project.";
57
+ static readonly description = "Repeat -m dmo:ApiName for exact selection, use -m dmo for all DMOs in the selected space, or omit selectors for all implemented families (currently DMO only). Unsupported objects produce per-object diagnostics and a nonzero aggregate while successful files are retained. Differing files require --overwrite; identical bytes are unchanged. Retrieval never mutates the org.";
58
+ static readonly flags: {
59
+ 'target-org': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
60
+ 'api-version': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
61
+ 'data-space': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
62
+ metadata: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
63
+ 'output-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
64
+ overwrite: import("@oclif/core/interfaces").BooleanFlag<boolean>;
65
+ };
66
+ protected acquire: typeof retrieveDmo;
67
+ protected selectDocuments: typeof selectDmos;
68
+ protected resolveOrg: (aliasOrUsername?: string) => Promise<Org>;
69
+ protected writeDocument: typeof writeDmoDocument;
70
+ /**
71
+ * Acquire the complete runtime projection, then publish only its authored candidate.
72
+ * @returns {Promise<RetrieveEnvelope>} Versioned retrieval outcome and payload-free diagnostics.
73
+ */
74
+ run(): Promise<RetrieveEnvelope>;
75
+ }
@@ -0,0 +1,168 @@
1
+ import path from 'node:path';
2
+ import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
3
+ import { Org } from '@salesforce/core';
4
+ import { DmoDocumentError } from '../../artifacts/dmo-document.js';
5
+ import { DmoWriteError, writeDmoDocument } from '../../artifacts/write-other-dmo.js';
6
+ import { DmoRetrieveError, retrieveDmo, selectDmos, validateDmoSelection, } from '../../services/retrieve-other-dmo.js';
7
+ import { ConnectError } from '../../transport/connect-client.js';
8
+ import { plugin as packageMetadata } from '../../plugin.js';
9
+ /** Retrieve selected DMO configuration through existing service-owned capability checks. */
10
+ export default class Retrieve extends SfCommand {
11
+ static aliases = ['datacloud:retrieve', 'd360:retrieve', 'dc:retrieve'];
12
+ static summary = 'Retrieve Data360 DMOs into a local project.';
13
+ static description = 'Repeat -m dmo:ApiName for exact selection, use -m dmo for all DMOs in the selected space, or omit selectors for all implemented families (currently DMO only). Unsupported objects produce per-object diagnostics and a nonzero aggregate while successful files are retained. Differing files require --overwrite; identical bytes are unchanged. Retrieval never mutates the org.';
14
+ static flags = {
15
+ 'target-org': Flags.string({
16
+ char: 'o',
17
+ summary: 'Authenticated org alias or username; defaults to the configured target org.',
18
+ }),
19
+ 'api-version': Flags.orgApiVersion({
20
+ default: '65.0',
21
+ summary: 'Explicit Salesforce API version (current service supports 65.0).',
22
+ }),
23
+ 'data-space': Flags.string({
24
+ default: 'default',
25
+ summary: 'Logical data space (current service supports default).',
26
+ }),
27
+ metadata: Flags.string({
28
+ char: 'm',
29
+ multiple: true,
30
+ multipleNonGreedy: true,
31
+ summary: 'Repeat dmo[:ApiName]; omitted selectors retrieve all implemented families.',
32
+ }),
33
+ 'output-dir': Flags.directory({
34
+ char: 'd',
35
+ exists: false,
36
+ summary: 'Project root for JSON; defaults to the current directory.',
37
+ }),
38
+ overwrite: Flags.boolean({
39
+ char: 'x',
40
+ default: false,
41
+ summary: 'Permit replacing differing selected files.',
42
+ }),
43
+ };
44
+ acquire = retrieveDmo;
45
+ selectDocuments = selectDmos;
46
+ resolveOrg = (aliasOrUsername) => Org.create({ aliasOrUsername });
47
+ writeDocument = writeDmoDocument;
48
+ /**
49
+ * Acquire the complete runtime projection, then publish only its authored candidate.
50
+ * @returns {Promise<RetrieveEnvelope>} Versioned retrieval outcome and payload-free diagnostics.
51
+ */
52
+ async run() {
53
+ const { flags } = await this.parse(Retrieve);
54
+ const plugin = {
55
+ name: packageMetadata.name,
56
+ version: packageMetadata.version,
57
+ };
58
+ const envelope = {
59
+ contract: 'sf-data360-retrieve',
60
+ contractVersion: '1.0.0',
61
+ status: 'blocked',
62
+ metadata: { operation: 'retrieve', plugin, apiVersion: flags['api-version'] },
63
+ diagnostics: { warnings: [], errors: [] },
64
+ provenance: {
65
+ producer: plugin.name,
66
+ // eslint-disable-next-line unicorn/no-null -- Stable JSON envelope represents unresolved org identity explicitly.
67
+ sourceOrgId: null,
68
+ pluginVersion: plugin.version,
69
+ command: 'sf data360 retrieve',
70
+ generatedAt: new Date().toISOString(),
71
+ },
72
+ result: {
73
+ scope: {
74
+ dataSpace: flags['data-space'],
75
+ outputDir: path.resolve(flags['output-dir'] ?? process.cwd()),
76
+ },
77
+ selection: flags.metadata ?? [],
78
+ items: [],
79
+ },
80
+ };
81
+ const finish = (status, code) => {
82
+ envelope.status = status;
83
+ if (code)
84
+ envelope.diagnostics.errors.push({
85
+ code,
86
+ message: 'Retrieval did not complete. Check selection, authenticated org, service capability and output path.',
87
+ retryable: false,
88
+ });
89
+ if (status !== 'success')
90
+ process.exitCode = 1;
91
+ if (!this.jsonEnabled()) {
92
+ this.log(`Retrieve: ${status}${code ? ` (${code})` : ''}.`);
93
+ for (const diagnostic of envelope.diagnostics.errors)
94
+ this.log(`${diagnostic.identity ? `dmo:${diagnostic.identity.apiName}: ` : ''}${diagnostic.code}: ${diagnostic.message}`);
95
+ }
96
+ return envelope;
97
+ };
98
+ const selectors = flags.metadata ?? [];
99
+ try {
100
+ validateDmoSelection(selectors, flags['api-version'], flags['data-space']);
101
+ }
102
+ catch (error) {
103
+ return finish('blocked', error instanceof DmoRetrieveError ? error.code : 'INVALID_SELECTION');
104
+ }
105
+ let org;
106
+ try {
107
+ org = await this.resolveOrg(flags['target-org']);
108
+ }
109
+ catch {
110
+ return finish('blocked', 'TARGET_ORG_REQUIRED');
111
+ }
112
+ let failed = false;
113
+ const diagnose = (error, apiName) => {
114
+ let code = 'RETRIEVE_FAILED';
115
+ if (error instanceof DmoWriteError ||
116
+ error instanceof DmoRetrieveError ||
117
+ error instanceof ConnectError)
118
+ code = error.code;
119
+ else if (error instanceof DmoDocumentError)
120
+ code = 'UNSUPPORTED_DMO_DOCUMENT';
121
+ else
122
+ failed = true;
123
+ if (code === 'OUTPUT_FAILED' ||
124
+ error instanceof ConnectError ||
125
+ code === 'ACQUISITION_FAILED')
126
+ failed = true;
127
+ envelope.diagnostics.errors.push({
128
+ code,
129
+ message: apiName
130
+ ? 'This DMO was not retrieved. Resolve its capability, acquisition or output diagnostic.'
131
+ : 'DMO inventory could not be resolved completely; no files were written.',
132
+ retryable: false,
133
+ ...(apiName ? { identity: { dataSpace: flags['data-space'], apiName } } : {}),
134
+ });
135
+ };
136
+ try {
137
+ envelope.provenance.sourceOrgId = org.getOrgId();
138
+ const connection = org.getConnection(flags['api-version']);
139
+ const names = await this.selectDocuments(connection, selectors, flags['api-version'], flags['data-space']);
140
+ envelope.result.selection = names.map((name) => `dmo:${name}`);
141
+ for (const apiName of names) {
142
+ try {
143
+ const projection = await this.acquire(connection, apiName, flags['api-version'], flags['data-space']);
144
+ if (projection.status !== 'projected' ||
145
+ projection.blockers.length > 0 ||
146
+ !projection.candidate)
147
+ throw new DmoRetrieveError(projection.blockers[0] ?? 'INCOMPLETE_DMO_PROJECTION');
148
+ if (projection.candidate.identity.apiName !== apiName ||
149
+ projection.candidate.identity.dataSpace !== flags['data-space'])
150
+ throw new DmoRetrieveError('INVALID_METADATA');
151
+ const receipt = await this.writeDocument(projection.candidate, flags['output-dir'] ?? process.cwd(), flags.overwrite);
152
+ envelope.result.items.push({
153
+ identity: { ...projection.candidate.identity },
154
+ operation: 'retrieve',
155
+ ...receipt,
156
+ });
157
+ }
158
+ catch (error) {
159
+ diagnose(error, apiName);
160
+ }
161
+ }
162
+ }
163
+ catch (error) {
164
+ diagnose(error);
165
+ }
166
+ return finish(envelope.diagnostics.errors.length === 0 ? 'success' : failed ? 'failed' : 'blocked');
167
+ }
168
+ }
@@ -0,0 +1,4 @@
1
+ export declare const plugin: {
2
+ name: string;
3
+ version: string;
4
+ };
package/lib/plugin.js ADDED
@@ -0,0 +1,3 @@
1
+ import { readFileSync } from 'node:fs';
2
+ // Both src/ and the installed lib/ sit directly beneath this plugin's package root.
3
+ export const plugin = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
@@ -0,0 +1,24 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ import type { DmoDeployPreview } from './preflight-dmo-deploy.js';
3
+ type TargetConnection = Pick<Connection, 'instanceUrl' | 'request' | 'metadata' | 'getApiVersion'>;
4
+ export type DmoCreateExecution = {
5
+ outcome: 'unchanged' | 'blocked' | 'created' | 'failed';
6
+ mutation: 'not-attempted' | 'confirmed-created' | 'unknown';
7
+ preflight?: DmoDeployPreview;
8
+ diagnostics: Array<{
9
+ code: string;
10
+ message: string;
11
+ }>;
12
+ };
13
+ /**
14
+ * Execute one authored create after fresh absence proof; never accepts a saved preview.
15
+ * Snapshot validation happens synchronously before the first await. Only qualified independent
16
+ * readback can establish created status; HTTP failure/ambiguous response never authorizes retry.
17
+ * @param {unknown} document Authored-only document, not a preview or projection.
18
+ * @param {TargetConnection} connection Actual target connection with explicit API version.
19
+ * @param {unknown} apiVersion Explicit API 65.0.
20
+ * @param {unknown} dataSpace Explicit default data space.
21
+ * @returns {Promise<DmoCreateExecution>} Payload-free result retaining possible mutation evidence.
22
+ */
23
+ export declare function executeDmoCreate(document: unknown, connection: TargetConnection, apiVersion: unknown, dataSpace: unknown): Promise<DmoCreateExecution>;
24
+ export {};
@@ -0,0 +1,118 @@
1
+ import { buildDmoCreateRequestFromDocument, validateDmoDocument, } from '../artifacts/dmo-document.js';
2
+ import { ConnectClient } from '../transport/connect-client.js';
3
+ import { compareDmoMeaning, preflightDmoDeploy } from './preflight-dmo-deploy.js';
4
+ import { retrieveDmo } from './retrieve-other-dmo.js';
5
+ /**
6
+ * Execute one authored create after fresh absence proof; never accepts a saved preview.
7
+ * Snapshot validation happens synchronously before the first await. Only qualified independent
8
+ * readback can establish created status; HTTP failure/ambiguous response never authorizes retry.
9
+ * @param {unknown} document Authored-only document, not a preview or projection.
10
+ * @param {TargetConnection} connection Actual target connection with explicit API version.
11
+ * @param {unknown} apiVersion Explicit API 65.0.
12
+ * @param {unknown} dataSpace Explicit default data space.
13
+ * @returns {Promise<DmoCreateExecution>} Payload-free result retaining possible mutation evidence.
14
+ */
15
+ export async function executeDmoCreate(document, connection, apiVersion, dataSpace) {
16
+ let snapshot;
17
+ let source;
18
+ let client;
19
+ try {
20
+ // Validate before serializing so accessor/toJSON payloads cannot run during snapshotting.
21
+ const { name, dataSpaceName, ...spec } = buildDmoCreateRequestFromDocument(document, 'default');
22
+ snapshot = validateDmoDocument({
23
+ schemaVersion: 1,
24
+ kind: 'dmo',
25
+ identity: { dataSpace: dataSpaceName, apiName: `${name}__dlm` },
26
+ spec,
27
+ });
28
+ }
29
+ catch {
30
+ return {
31
+ outcome: 'blocked',
32
+ mutation: 'not-attempted',
33
+ diagnostics: [
34
+ {
35
+ code: 'INVALID_SOURCE',
36
+ message: 'Supply one valid authored-only default-space DMO document.',
37
+ },
38
+ ],
39
+ };
40
+ }
41
+ try {
42
+ if (apiVersion !== '65.0' ||
43
+ dataSpace !== 'default' ||
44
+ connection.getApiVersion() !== apiVersion)
45
+ throw new Error('Invalid scope');
46
+ client = new ConnectClient(connection, apiVersion);
47
+ source = buildDmoCreateRequestFromDocument(snapshot, dataSpace);
48
+ }
49
+ catch {
50
+ return {
51
+ outcome: 'blocked',
52
+ mutation: 'not-attempted',
53
+ diagnostics: [
54
+ {
55
+ code: 'INVALID_SCOPE',
56
+ message: 'Use an explicit API 65.0 connection and default target data space.',
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ const preflight = await preflightDmoDeploy(snapshot, connection, apiVersion, dataSpace);
62
+ if (preflight.outcome !== 'create' ||
63
+ preflight.target !== 'absent' ||
64
+ preflight.absenceProof !== 'complete-inventory')
65
+ return {
66
+ outcome: preflight.outcome === 'unchanged' ? 'unchanged' : 'blocked',
67
+ mutation: 'not-attempted',
68
+ preflight,
69
+ diagnostics: preflight.diagnostics,
70
+ };
71
+ try {
72
+ // The response body is deliberately not trusted or used as the readback identity.
73
+ await client.createDataModelObject(snapshot);
74
+ }
75
+ catch {
76
+ return {
77
+ outcome: 'failed',
78
+ mutation: 'unknown',
79
+ preflight,
80
+ diagnostics: [
81
+ {
82
+ code: 'CREATE_UNCONFIRMED',
83
+ message: 'Creation may have occurred. Inspect target state before any further attempt; no automatic retry or rollback was performed.',
84
+ },
85
+ ],
86
+ };
87
+ }
88
+ try {
89
+ const acquired = await retrieveDmo(connection, `${source.name}__dlm`, apiVersion, dataSpace);
90
+ const target = buildDmoCreateRequestFromDocument(acquired.candidate, dataSpace);
91
+ if (compareDmoMeaning(source, target).length > 0)
92
+ return {
93
+ outcome: 'failed',
94
+ mutation: 'unknown',
95
+ preflight,
96
+ diagnostics: [
97
+ {
98
+ code: 'READBACK_MISMATCH',
99
+ message: 'Creation may have occurred, but qualified target meaning differs. Inspect target; no retry or rollback was performed.',
100
+ },
101
+ ],
102
+ };
103
+ return { outcome: 'created', mutation: 'confirmed-created', preflight, diagnostics: [] };
104
+ }
105
+ catch {
106
+ return {
107
+ outcome: 'failed',
108
+ mutation: 'unknown',
109
+ preflight,
110
+ diagnostics: [
111
+ {
112
+ code: 'READBACK_UNQUALIFIED',
113
+ message: 'Creation may have occurred, but independent target qualification failed. Inspect target; no retry or rollback was performed.',
114
+ },
115
+ ],
116
+ };
117
+ }
118
+ }
@@ -0,0 +1,33 @@
1
+ import type { Connection } from '@salesforce/core';
2
+ import type { DmoCreateExecution } from './execute-dmo-create.js';
3
+ import type { DmoDeployPreview } from './preflight-dmo-deploy.js';
4
+ type TargetConnection = Pick<Connection, 'instanceUrl' | 'request' | 'metadata' | 'getApiVersion'>;
5
+ export type DmoDeployExecution = {
6
+ outcome: DmoCreateExecution['outcome'] | 'updated' | 'not-attempted';
7
+ mutation: DmoCreateExecution['mutation'] | 'confirmed-updated';
8
+ preflight?: DmoDeployPreview;
9
+ diagnostics: Array<{
10
+ code: string;
11
+ message: string;
12
+ }>;
13
+ };
14
+ /**
15
+ * Execute one internal create/unchanged/label-update operation using fresh target evidence.
16
+ * Public CLI intentionally continues to invoke the create-only executor.
17
+ * @param {unknown} document Authored document, never saved admission evidence.
18
+ * @param {TargetConnection} connection Explicit authenticated API 65 connection.
19
+ * @param {unknown} apiVersion Explicit 65.0.
20
+ * @param {unknown} dataSpace Explicit default space.
21
+ * @returns {Promise<DmoDeployExecution>} Attempt and independently confirmed outcome.
22
+ */
23
+ export declare function executeDmoDeploy(document: unknown, connection: TargetConnection, apiVersion: unknown, dataSpace: unknown): Promise<DmoDeployExecution>;
24
+ /**
25
+ * Admit the complete detached selection before writes, then stop on first ambiguity or block.
26
+ * @param {unknown[]} documents Explicit selected authored inputs; duplicate identities are invalid.
27
+ * @param {TargetConnection} connection Actual target connection.
28
+ * @param {unknown} apiVersion Explicit API 65.0.
29
+ * @param {unknown} dataSpace Explicit default space.
30
+ * @returns {Promise<DmoDeployExecution[]>} Ordered item results, including never-attempted tail.
31
+ */
32
+ export declare function executeDmoDeploySelection(documents: unknown[], connection: TargetConnection, apiVersion: unknown, dataSpace: unknown): Promise<DmoDeployExecution[]>;
33
+ export {};