sf-plugin-data 0.3.0 → 0.5.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.
Files changed (46) hide show
  1. package/README.md +34 -15
  2. package/docs/artifact-format.md +4 -4
  3. package/docs/capabilities.md +10 -10
  4. package/docs/git-workflow.md +5 -6
  5. package/docs/handover.md +32 -32
  6. package/lib/api.d.ts +7 -0
  7. package/lib/api.js +5 -1
  8. package/lib/commands/data360/delete.d.ts +57 -12
  9. package/lib/commands/data360/delete.js +191 -42
  10. package/lib/commands/data360/deploy.d.ts +14 -2
  11. package/lib/commands/data360/deploy.js +32 -20
  12. package/lib/commands/data360/publish.d.ts +2 -2
  13. package/lib/commands/data360/publish.js +14 -12
  14. package/lib/commands/data360/retrieve.d.ts +1 -4
  15. package/lib/commands/data360/retrieve.js +17 -32
  16. package/lib/errors/codes/calculated-insight.js +1 -1
  17. package/lib/errors/codes/data-graph.js +2 -2
  18. package/lib/errors/codes/data-stream.js +1 -1
  19. package/lib/errors/codes/data-transform.js +1 -1
  20. package/lib/errors/codes/dlo.js +1 -1
  21. package/lib/errors/codes/dmo.js +1 -1
  22. package/lib/errors/codes/general.js +6 -4
  23. package/lib/errors/codes/identity-resolution.js +1 -1
  24. package/lib/errors/codes/mapping.js +1 -1
  25. package/lib/errors/codes/relationship.js +1 -1
  26. package/lib/errors/codes/segment.js +2 -2
  27. package/lib/services/command-native-data-graph.js +1 -1
  28. package/lib/services/command-native-dmo.js +1 -1
  29. package/lib/services/delete-calculated-insight.js +1 -1
  30. package/lib/services/delete-identity-resolution.js +1 -1
  31. package/lib/services/delete-segment.js +1 -1
  32. package/lib/services/native-data-graph-crd.d.ts +2 -2
  33. package/lib/services/native-data-graph-crd.js +2 -2
  34. package/lib/services/operation-diagnostic.js +1 -1
  35. package/lib/services/publish-segment.d.ts +1 -1
  36. package/lib/services/run-delete.d.ts +43 -0
  37. package/lib/services/run-delete.js +111 -0
  38. package/lib/services/run-deploy.d.ts +51 -0
  39. package/lib/services/run-deploy.js +107 -0
  40. package/lib/services/run-options.d.ts +23 -0
  41. package/lib/services/run-options.js +38 -0
  42. package/lib/services/run-retrieve.d.ts +3 -3
  43. package/lib/services/run-retrieve.js +6 -2
  44. package/lib/transport/connect-client.d.ts +8 -0
  45. package/lib/transport/connect-client.js +25 -1
  46. package/package.json +1 -1
@@ -20,6 +20,7 @@ import { createNativeDmoDeleteClient } from '../../transport/dmo-native-rest.js'
20
20
  import type { BoundSsot } from '../../transport/bound-ssot.js';
21
21
  import { deleteNativeDmo, previewDeleteNativeDmo } from '../../services/native-dmo.js';
22
22
  import { SfCommand } from '@salesforce/sf-plugins-core';
23
+ import type { Interfaces } from '@oclif/core';
23
24
  import { Connection } from '@salesforce/core';
24
25
  import { createDloClient } from '../../transport/dlo-rest.js';
25
26
  import { createNativeDloDeleteClient } from '../../transport/dlo-native-rest.js';
@@ -158,19 +159,19 @@ export type DeleteEnvelope = {
158
159
  export default class Delete extends SfCommand<DeleteEnvelope> {
159
160
  static readonly aliases: string[];
160
161
  static readonly summary = "Delete exact Data360 Transforms, Segments, IR owners, streams, DLOs, DMOs, single custom DMO fields or mappings.";
161
- static readonly description = "One delete can carry any mix of families, each named exactly with -m. It runs them in reverse dependency order, one phase after the other: graphs, then identity resolution, calculated insights and Segments (a dependent before the component it needs, including a graph or CI/Segment on the unified DMO of a selected IR), then data transforms, then relationships, mappings, DMOs and DLOs, then data streams. A phase starts only after every item of the previous one settled; a blocked, failed or unconfirmed item stops the run, and an item Salesforce is still processing stops the later phases with DELETE_PHASE_NOT_SETTLED (status processing, exit 69, when nothing failed). A -m delete needs no confirmation flag: check the selection with --preview first. Before the first delete, the current definition of each selected transform, Segment, IR, CI and graph is read from the org by its name (read-only); one the org does not have reports unchanged. A transform name resolves to its target ID through the complete transform list: no match is unchanged, two or more matches (ignoring case) are refused with TRANSFORM_TARGET_NOT_RESOLVED. --changed-since <ref> selects the canonical plugin files deleted since the merge base with that reference (every family; changed files are ignored) and deletes their components in the same phase order. Identity and definition come from each file's base content; a path present again is not a delete, while a rename (also one split across commit, index and worktree), an unstaged deletion or a deleted file of no known family blocks before any org call (BLOCKED_GIT_LIFECYCLE). A --changed-since delete needs --confirm-delete (--preview runs without it; --confirm-delete is accepted only with --changed-since), takes no -m or --delete-dlo, and removes no local file. A deleted data transform is resolved by its name like a -m one; a relationship takes its source DMO from the base content; a stream file deleted together with its landing DLO file deletes the stream with its DLO. --preview runs every phase read-only and reports an item whose selected dependents an earlier phase deletes as planned-dependencies (DEPENDENCIES_PLANNED) without checking it further. A stream selected together with its landing DLO is deleted with --delete-dlo semantics and the DLO item reports removedWith the stream; the last mapping of a custom DMO selected together with that DMO is not sent on its own and reports removedWith the DMO; it reports deleted only once its own read answers 404 after the DMO deletion, otherwise deletion-unconfirmed (MAPPING_DELETION_UNCONFIRMED). data-transform:Name uses auto/API68 in the run data space (TRANSFORM_DATASPACE_MISMATCH for another). Preview is GET-only. A target of any owner or namespace is deleted with one native DELETE (Salesforce decides; a 4xx answer is reported as rejected); one whose status is PROCESSING is refused before it (TRANSFORM_DELETE_PROCESSING, in --preview too); settlement needs complete bounded inventory omission of both ID and name, otherwise the result is deletion-unconfirmed (never replay). No DLO, run or data cleanup; exhaustive external-consumer exclusion is not established. segment:Name uses auto/API68 in the run data space (the stored name, <prefix>_<Name> outside default; SEGMENT_DATASPACE_MISMATCH for another). Fresh source bindings and exact runtime/private identity are checked before one native DELETE. Only independent absence or a preserved DELETING/PROCESSING read acknowledges the result; HTTP204 alone is insufficient. No replay, Segment XML, shared-DMO deletion or physical-output cleanup guarantee. identity-resolution:ObjectApiName uses auto/API68 in the run data space (the stored name, <prefix>_<type>_<rulesetId> outside default; IDENTITY_RESOLUTION_DATASPACE_MISMATCH for another) and deletes a present owner that is not PUBLISHING or DELETING. A fresh target-local ID is resolved before one native68 DELETE; bounded exact ID/name absence confirms owner-definition deletion only. Exhaustive external-consumer exclusion and physical profile/output cleanup remain unverified. IR never cascades, runs processing, replays writes or falls back to another API. data-graph:Name uses auto/API68 in the run data space (graph names are unique in the org; DATA_GRAPH_DATASPACE_MISMATCH for a graph of another). Fresh identity, created date, definition, root and ready checks plus explicit empty native dependency/related-segment arrays are mandatory. A draft graph (never built, retrieved as-is) is deleted by name with the same scope and dependency checks. Exhaustive external-consumer exclusion remains unverified; no generated-resource cleanup, storage or credit guarantee. A Graph delete never cascades. calculated-insight:Name__cio uses --api-version auto (68.0) or 68.0 in the run data space (the GET must name it, CI_IDENTITY_CHANGED otherwise). The insight is read by name with the API 68 GET (absent is unchanged; it must answer with that name and data space), deleted with one DELETE in any status, schedule or SQL (Salesforce decides; a 4xx answer is reported as rejected), then read until it answers 404. CI never cascades; no compute, storage or credits guarantee. Exact data-stream:ApiName selects guarded IngestApi stream deletion at auto/API68 in the run data space (its DLO must belong to it). The linked DLO is preserved by default; --delete-dlo explicitly acknowledges deleting that exclusively linked DLO. Selected stream and linked DLO checks only, not unrelated-org preservation. Native routes default to API68; explicit numeric pins are preserved. Relationship deletion (relationship:SourceDmo__dlm:Name; a bare relationship:Name is refused with INVALID_SELECTION) runs first in its phase, before mappings, DMOs and DLOs. The relationships of the named source DMO are listed and the name is looked up ignoring letter case: no match is unchanged, two matches are refused (AMBIGUOUS_RELATIONSHIP_TARGET), and a match whose source object is another DMO is refused (RELATIONSHIP_TARGET_BINDING_MISMATCH). In a --changed-since delete the source DMO and binding come from the deleted file, and when its name is absent but the binding exists under another name the delete is refused with RELATIONSHIP_NAME_MISMATCH. Otherwise one DELETE is sent and its absence confirmed by listing again; a 4xx answer is reported as rejected. --preview only lists. A mapping:Name with a valid local data360/mapping/Name.mapping-meta.json file (with --changed-since, the deleted file's base content) is found in the org the way deploy finds it: by the file's source DLO and target DMO, whatever Salesforce named it (the org name is reported as targetApiName). No org mapping with that binding is unchanged; two or more are refused with AMBIGUOUS_MAPPING_TARGET before any write. Otherwise the exact name is read, and a mapping that reads absent (404) reports unchanged. Mapping deletion runs at native API 61 and up (default 68) and deletes the whole mapping with one Metadata API destructive deployment (ObjectSourceTargetMap), whatever pairs it holds, also onto a standard DMO (Salesforce refuses the last mapping onto a standard DMO copy in a data space other than default; a Failed destructive deployment is reported as rejected). Afterwards the mapping must read absent and the other mappings and the fields of the DMO must be unchanged. The last mapping of a custom DMO is refused before any write (MAPPING_LAST_MAPPING_DELETE_BLOCKED) because Salesforce does not delete it; delete the DMO instead, which removes its mapping. Qualification uses empty custom fixtures, not populated-data guarantees. --preview performs zero writes and reports the planned step. Any partial failure stops the batch; no retries or rollback. Whole-DMO deletion is sent for every DMO, a standard one (creationType Standard) and one read without a creationType included, and Salesforce decides: a 4xx answer is reported as rejected (for example, Salesforce refuses to delete a platform-generated DMO while the identity resolution or graph that owns it exists). Field-level delete: exactly one dmo:Name__dlm with one or more --field Name__c removes the named fields from that DMO. It is the one delete operation that changes mappings it was not given and writes project files. Reads first: every field must exist on the DMO. Any field but the primary key may be named, also the standard, system and generated fields of any DMO: Salesforce decides, and a refused destructive change is reported as rejected. This is the only command that removes such platform-owned fields; every mapping pair targeting a named field is collected, and a mapped field is refused only when the mapping list fails; one that no mapping lists a pair for has no pair to lose and is removed. Then one Metadata API destructive change for all fields, sent once and never retried; Salesforce drops the mapping pairs of the removed fields itself. Fresh reads right before it must still match the plan, and polled reads afterwards must show the fields absent, exactly the collected pairs gone and every other mapping, pair, DMO property and field unchanged; any other difference fails with DMO_FIELD_REMOVAL_SIDE_EFFECT. Nothing is rolled back. After success the existing data360/dmo and data360/mapping files under --output-dir (default: current directory) are overwritten with the current definitions; absent files are not created and no file is deleted. A failed file refresh keeps the confirmed org result and the run is partial (exit 68, LOCAL_REFRESH_FAILED). --field --preview writes nothing and reports pairs, fields and files. --field cannot be combined with another selector, --changed-since or --delete-dlo. Local files: after a confirmed deletion (deleted, or a DLO, DMO, Segment or IR Salesforce accepted and is still deleting) the component's own local file is removed by default, one regular file at a time at its canonical path and never a folder: data360/dlo, data360/dmo, data360/relationship, data360/data-stream, data360/dataTransforms, data360/identityResolution and data360/dataGraphs files, both files of a CI (data360/calculatedInsights/Name__cio.calculatedInsight-meta.json and .calculatedInsight-meta.sql) and the Segment files (data360/segments/Name.segment.json and every Name.segment.*.sql beside it) under the current directory (with --delete-dlo also the linked DLO's file), and the mapping file of that name or the one whose binding matches. Links, hard-linked files and paths outside those folders are refused. Nothing is removed on --preview, which lists the files instead, nor for unchanged, blocked, failed, rejected or unconfirmed deletions. --keep-local-files keeps them. A failed removal keeps the confirmed org result and the run is partial (exit 68) with LOCAL_FILE_REMOVAL_FAILED when a deletion is confirmed, otherwise processing (exit 69).";
162
+ static readonly description = "One delete can carry any mix of families, each named exactly with -m. It runs them in reverse dependency order, one phase after the other: graphs, then identity resolution, calculated insights and Segments (a dependent before the component it needs, including a graph or CI/Segment on the unified DMO of a selected IR), then data transforms, then relationships, mappings, DMOs and DLOs, then data streams. A phase starts only after every item of the previous one settled; a blocked, failed or unconfirmed item stops the run, and an item Salesforce is still processing stops the later phases with DELETE_PHASE_NOT_SETTLED (status processing, exit 69, when nothing failed). Without --preview the delete first runs the same selection read-only, lists every component it would delete and asks once (y/yes deletes; no, no answer within 30 seconds or a failed question sends nothing and reports DELETE_CANCELLED with exit 0); nothing to delete asks nothing. Without a terminal, or with --json, a delete needs --no-prompt (-r) and is otherwise refused before any org call with CONFIRMATION_REQUIRED. --preview never asks. Before the first delete, the current definition of each selected transform, Segment, IR, CI and graph is read from the org by its name (read-only); one the org does not have reports unchanged. A transform name resolves to its target ID through the complete transform list: no match is unchanged, two or more matches (ignoring case) are refused with TRANSFORM_TARGET_NOT_RESOLVED. --changed-since <ref> selects the canonical plugin files deleted since the merge base with that reference (every family; changed files are ignored) and deletes their components in the same phase order. Identity and definition come from each file's base content; a path present again is not a delete, while a rename (also one split across commit, index and worktree), an unstaged deletion or a deleted file of no known family blocks before any org call (BLOCKED_GIT_LIFECYCLE). A --changed-since delete takes no -m or --delete-dlo, and removes no local file. A deleted data transform is resolved by its name like a -m one; a relationship takes its source DMO from the base content; a stream file deleted together with its landing DLO file deletes the stream with its DLO. --preview runs every phase read-only and reports an item whose selected dependents an earlier phase deletes as planned-dependencies (DEPENDENCIES_PLANNED) without checking it further. A stream selected together with its landing DLO is deleted with --delete-dlo semantics and the DLO item reports removedWith the stream; the last mapping of a custom DMO selected together with that DMO is not sent on its own and reports removedWith the DMO; it reports deleted only once its own read answers 404 after the DMO deletion, otherwise deletion-unconfirmed (MAPPING_DELETION_UNCONFIRMED). data-transform:Name uses auto/API68 in the run data space (TRANSFORM_DATASPACE_MISMATCH for another). Preview is GET-only. A target of any owner or namespace is deleted with one native DELETE (Salesforce decides; a 4xx answer is reported as rejected); one whose status is PROCESSING is refused before it (TRANSFORM_DELETE_PROCESSING, in --preview too); settlement needs complete bounded inventory omission of both ID and name, otherwise the result is deletion-unconfirmed (never replay). No DLO, run or data cleanup; exhaustive external-consumer exclusion is not established. segment:Name uses auto/API68 in the run data space (the stored name, <prefix>_<Name> outside default; SEGMENT_DATASPACE_MISMATCH for another). Fresh source bindings and exact runtime/private identity are checked before one native DELETE. Only independent absence or a preserved DELETING/PROCESSING read acknowledges the result; HTTP204 alone is insufficient. No replay, Segment XML, shared-DMO deletion or physical-output cleanup guarantee. identity-resolution:ObjectApiName uses auto/API68 in the run data space (the stored name, <prefix>_<type>_<rulesetId> outside default; IDENTITY_RESOLUTION_DATASPACE_MISMATCH for another) and deletes a present owner that is not PUBLISHING or DELETING. A fresh target-local ID is resolved before one native68 DELETE; bounded exact ID/name absence confirms owner-definition deletion only. Exhaustive external-consumer exclusion and physical profile/output cleanup remain unverified. IR never cascades, runs processing, replays writes or falls back to another API. data-graph:Name uses auto/API68 in the run data space (graph names are unique in the org; DATA_GRAPH_DATASPACE_MISMATCH for a graph of another). Fresh identity, created date, definition, root and ready checks plus explicit empty native dependency/related-segment arrays are mandatory. A draft graph (never built, retrieved as-is) is deleted by name with the same scope and dependency checks. Exhaustive external-consumer exclusion remains unverified; no generated-resource cleanup, storage or credit guarantee. A Graph delete never cascades. calculated-insight:Name__cio uses --api-version auto (68.0) or 68.0 in the run data space (the GET must name it, CI_IDENTITY_CHANGED otherwise). The insight is read by name with the API 68 GET (absent is unchanged; it must answer with that name and data space), deleted with one DELETE in any status, schedule or SQL (Salesforce decides; a 4xx answer is reported as rejected), then read until it answers 404. CI never cascades; no compute, storage or credits guarantee. Exact data-stream:ApiName selects guarded IngestApi stream deletion at auto/API68 in the run data space (its DLO must belong to it). The linked DLO is preserved by default; --delete-dlo explicitly acknowledges deleting that exclusively linked DLO. Selected stream and linked DLO checks only, not unrelated-org preservation. Native routes default to API68; explicit numeric pins are preserved. Relationship deletion (relationship:SourceDmo__dlm:Name; a bare relationship:Name is refused with INVALID_SELECTION) runs first in its phase, before mappings, DMOs and DLOs. The relationships of the named source DMO are listed and the name is looked up ignoring letter case: no match is unchanged, two matches are refused (AMBIGUOUS_RELATIONSHIP_TARGET), and a match whose source object is another DMO is refused (RELATIONSHIP_TARGET_BINDING_MISMATCH). In a --changed-since delete the source DMO and binding come from the deleted file, and when its name is absent but the binding exists under another name the delete is refused with RELATIONSHIP_NAME_MISMATCH. Otherwise one DELETE is sent and its absence confirmed by listing again; a 4xx answer is reported as rejected. --preview only lists. A mapping:Name with a valid local data360/mapping/Name.mapping-meta.json file (with --changed-since, the deleted file's base content) is found in the org the way deploy finds it: by the file's source DLO and target DMO, whatever Salesforce named it (the org name is reported as targetApiName). No org mapping with that binding is unchanged; two or more are refused with AMBIGUOUS_MAPPING_TARGET before any write. Otherwise the exact name is read, and a mapping that reads absent (404) reports unchanged. Mapping deletion runs at native API 61 and up (default 68) and deletes the whole mapping with one Metadata API destructive deployment (ObjectSourceTargetMap), whatever pairs it holds, also onto a standard DMO (Salesforce refuses the last mapping onto a standard DMO copy in a data space other than default; a Failed destructive deployment is reported as rejected). Afterwards the mapping must read absent and the other mappings and the fields of the DMO must be unchanged. The last mapping of a custom DMO is refused before any write (MAPPING_LAST_MAPPING_DELETE_BLOCKED) because Salesforce does not delete it; delete the DMO instead, which removes its mapping. Qualification uses empty custom fixtures, not populated-data guarantees. --preview performs zero writes and reports the planned step. Any partial failure stops the batch; no retries or rollback. Whole-DMO deletion is sent for every DMO, a standard one (creationType Standard) and one read without a creationType included, and Salesforce decides: a 4xx answer is reported as rejected (for example, Salesforce refuses to delete a platform-generated DMO while the identity resolution or graph that owns it exists). Field-level delete: exactly one dmo:Name__dlm with one or more --field Name__c removes the named fields from that DMO. It is the one delete operation that changes mappings it was not given and writes project files. Reads first: every field must exist on the DMO. Any field but the primary key may be named, also the standard, system and generated fields of any DMO: Salesforce decides, and a refused destructive change is reported as rejected. This is the only command that removes such platform-owned fields; every mapping pair targeting a named field is collected, and a mapped field is refused only when the mapping list fails; one that no mapping lists a pair for has no pair to lose and is removed. Then one Metadata API destructive change for all fields, sent once and never retried; Salesforce drops the mapping pairs of the removed fields itself. Fresh reads right before it must still match the plan, and polled reads afterwards must show the fields absent, exactly the collected pairs gone and every other mapping, pair, DMO property and field unchanged; any other difference fails with DMO_FIELD_REMOVAL_SIDE_EFFECT. Nothing is rolled back. After success the existing data360/dmo and data360/mapping files under --output-dir (default: current directory) are overwritten with the current definitions; absent files are not created and no file is deleted. A failed file refresh keeps the confirmed org result and the run is partial (exit 68, LOCAL_REFRESH_FAILED). --field --preview writes nothing and reports pairs, fields and files. --field cannot be combined with another selector, --changed-since or --delete-dlo. Local files: after a confirmed deletion (deleted, or a DLO, DMO, Segment or IR Salesforce accepted and is still deleting) the component's own local file is removed by default, one regular file at a time at its canonical path and never a folder: data360/dlo, data360/dmo, data360/relationship, data360/data-stream, data360/dataTransforms, data360/identityResolution and data360/dataGraphs files, both files of a CI (data360/calculatedInsights/Name__cio.calculatedInsight-meta.json and .calculatedInsight-meta.sql) and the Segment files (data360/segments/Name.segment.json and every Name.segment.*.sql beside it) under the current directory (with --delete-dlo also the linked DLO's file), and the mapping file of that name or the one whose binding matches. Links, hard-linked files and paths outside those folders are refused. Nothing is removed on --preview, which lists the files instead, nor for unchanged, blocked, failed, rejected or unconfirmed deletions. --keep-local-files keeps them. A failed removal keeps the confirmed org result and the run is partial (exit 68) with LOCAL_FILE_REMOVAL_FAILED when a deletion is confirmed, otherwise processing (exit 69).";
162
163
  static readonly flags: {
163
- 'target-org': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
164
- metadata: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
165
- 'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
166
- dataspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
167
- preview: import("@oclif/core/interfaces").BooleanFlag<boolean>;
168
- 'changed-since': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
169
- 'confirm-delete': import("@oclif/core/interfaces").BooleanFlag<boolean>;
170
- 'delete-dlo': import("@oclif/core/interfaces").BooleanFlag<boolean>;
171
- field: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
172
- 'output-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
173
- 'keep-local-files': import("@oclif/core/interfaces").BooleanFlag<boolean>;
164
+ 'target-org': Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
165
+ metadata: Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
166
+ 'api-version': Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
167
+ dataspace: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
168
+ preview: Interfaces.BooleanFlag<boolean>;
169
+ 'changed-since': Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
170
+ 'no-prompt': Interfaces.BooleanFlag<boolean>;
171
+ 'delete-dlo': Interfaces.BooleanFlag<boolean>;
172
+ field: Interfaces.OptionFlag<string[] | undefined, Interfaces.CustomOptions>;
173
+ 'output-dir': Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
174
+ 'keep-local-files': Interfaces.BooleanFlag<boolean>;
174
175
  };
175
176
  protected deleteDataTransform: typeof deleteDataTransform;
176
177
  protected createDataTransformClient: typeof createDataTransformClient;
@@ -194,6 +195,7 @@ export default class Delete extends SfCommand<DeleteEnvelope> {
194
195
  protected readStreamLinkedDlo: typeof readStreamLinkedDlo;
195
196
  protected preflightDeleteDataStream: typeof preflightDeleteDataStream;
196
197
  protected executeDeleteDataStream: typeof executeDeleteDataStream;
198
+ protected streamConnection: (target: string, version: string) => Promise<Connection>;
197
199
  protected createDataStreamClients: (target: string, version: string) => Promise<Parameters<typeof executeDeleteDataStream>[1]>;
198
200
  protected createMappingClient: typeof createMappingClient;
199
201
  protected createMappingSender: (target: string, version: string) => BoundSsot;
@@ -276,5 +278,48 @@ export default class Delete extends SfCommand<DeleteEnvelope> {
276
278
  * @returns {Promise<DeleteEnvelope>} Payload-free deletion evidence.
277
279
  */
278
280
  run(): Promise<DeleteEnvelope>;
281
+ /**
282
+ * Whether a person can answer the confirmation question: stdin and stdout are terminals.
283
+ * @returns {boolean} True in an interactive terminal.
284
+ */
285
+ protected interactiveTerminal(): boolean;
286
+ /**
287
+ * Report data graph progress while the delete waits (for example a retried graph DELETE).
288
+ * oclif logToStderr suppresses output in JSON mode; progress must remain visible.
289
+ * @param {string} message One progress line.
290
+ */
291
+ protected graphProgress(message: string): void;
292
+ /**
293
+ * The project root: where data360/ lives (local files removed or refreshed, relative
294
+ * --output-dir) and the Git selection runs. The CLI uses the current directory.
295
+ * @returns {string} Absolute project root.
296
+ */
297
+ protected projectDirectory(): string;
298
+ /**
299
+ * Ask once whether to delete; no answer within 30 seconds is no.
300
+ * @param {string} message Question and the components it deletes.
301
+ * @returns {Promise<boolean>} True only for an explicit yes.
302
+ */
303
+ protected confirmDeletion(message: string): Promise<boolean>;
304
+ /**
305
+ * The envelope of a delete whose silent preview did not succeed: its refusal, nothing sent and
306
+ * nothing asked.
307
+ * @param {DeleteEnvelope} preview Envelope of the silent preview (blocked, failed or other).
308
+ * @returns {DeleteEnvelope} The preview's status, items and diagnostics.
309
+ */
310
+ private refusedPreview;
311
+ /**
312
+ * The envelope of a delete the user did not confirm: the preview items, nothing sent.
313
+ * @param {DeleteEnvelope} preview Envelope of the silent preview.
314
+ * @returns {DeleteEnvelope} Cancelled envelope, status success.
315
+ */
316
+ private cancelled;
317
+ /**
318
+ * Run the delete, or its preview, and complete the envelope.
319
+ * @param {DeleteFlags} flags Parsed flags.
320
+ * @param {boolean} quiet No output and no exit code: the preview before the question.
321
+ * @returns {Promise<DeleteEnvelope>} Payload-free deletion evidence.
322
+ */
323
+ private execute;
279
324
  }
280
325
  export {};
@@ -470,11 +470,43 @@ function fieldDeleteLines(item) {
470
470
  : `refresh failed (${file.code}): ${file.path}`);
471
471
  return lines;
472
472
  }
473
+ /**
474
+ * A fresh, blocked envelope for one run.
475
+ * @param {DeleteFlags} flags Parsed flags.
476
+ * @returns {DeleteEnvelope} Envelope without items.
477
+ */
478
+ function newEnvelope(flags) {
479
+ return {
480
+ contract: 'sf-data360-delete',
481
+ contractVersion: '1.1.0',
482
+ status: 'blocked',
483
+ metadata: {
484
+ operation: 'delete',
485
+ preview: flags.preview,
486
+ apiVersion: flags['api-version'] ?? 'auto',
487
+ plugin,
488
+ },
489
+ provenance: {
490
+ command: 'sf data360 delete',
491
+ generatedAt: new Date().toISOString(),
492
+ // eslint-disable-next-line unicorn/no-null -- Stable JSON represents unresolved target identity explicitly.
493
+ targetOrgId: null,
494
+ },
495
+ diagnostics: { warnings: [], errors: [] },
496
+ result: { scope: { dataSpace: flags.dataspace ?? 'default' }, items: [] },
497
+ };
498
+ }
499
+ /**
500
+ * A preview item the real run would delete: now, after its dependents, or with its owner.
501
+ * @param {DeleteItem} item Preview item.
502
+ * @returns {boolean} True when the real run would delete it.
503
+ */
504
+ const wouldDelete = (item) => item.outcome === 'delete' || item.outcome === 'planned-dependencies';
473
505
  /** Delete exact native DLO definitions, or preview without mutation. */
474
506
  export default class Delete extends SfCommand {
475
507
  static aliases = ['datacloud:delete', 'd360:delete', 'dc:delete'];
476
508
  static summary = 'Delete exact Data360 Transforms, Segments, IR owners, streams, DLOs, DMOs, single custom DMO fields or mappings.';
477
- static description = "One delete can carry any mix of families, each named exactly with -m. It runs them in reverse dependency order, one phase after the other: graphs, then identity resolution, calculated insights and Segments (a dependent before the component it needs, including a graph or CI/Segment on the unified DMO of a selected IR), then data transforms, then relationships, mappings, DMOs and DLOs, then data streams. A phase starts only after every item of the previous one settled; a blocked, failed or unconfirmed item stops the run, and an item Salesforce is still processing stops the later phases with DELETE_PHASE_NOT_SETTLED (status processing, exit 69, when nothing failed). A -m delete needs no confirmation flag: check the selection with --preview first. Before the first delete, the current definition of each selected transform, Segment, IR, CI and graph is read from the org by its name (read-only); one the org does not have reports unchanged. A transform name resolves to its target ID through the complete transform list: no match is unchanged, two or more matches (ignoring case) are refused with TRANSFORM_TARGET_NOT_RESOLVED. --changed-since <ref> selects the canonical plugin files deleted since the merge base with that reference (every family; changed files are ignored) and deletes their components in the same phase order. Identity and definition come from each file's base content; a path present again is not a delete, while a rename (also one split across commit, index and worktree), an unstaged deletion or a deleted file of no known family blocks before any org call (BLOCKED_GIT_LIFECYCLE). A --changed-since delete needs --confirm-delete (--preview runs without it; --confirm-delete is accepted only with --changed-since), takes no -m or --delete-dlo, and removes no local file. A deleted data transform is resolved by its name like a -m one; a relationship takes its source DMO from the base content; a stream file deleted together with its landing DLO file deletes the stream with its DLO. --preview runs every phase read-only and reports an item whose selected dependents an earlier phase deletes as planned-dependencies (DEPENDENCIES_PLANNED) without checking it further. A stream selected together with its landing DLO is deleted with --delete-dlo semantics and the DLO item reports removedWith the stream; the last mapping of a custom DMO selected together with that DMO is not sent on its own and reports removedWith the DMO; it reports deleted only once its own read answers 404 after the DMO deletion, otherwise deletion-unconfirmed (MAPPING_DELETION_UNCONFIRMED). data-transform:Name uses auto/API68 in the run data space (TRANSFORM_DATASPACE_MISMATCH for another). Preview is GET-only. A target of any owner or namespace is deleted with one native DELETE (Salesforce decides; a 4xx answer is reported as rejected); one whose status is PROCESSING is refused before it (TRANSFORM_DELETE_PROCESSING, in --preview too); settlement needs complete bounded inventory omission of both ID and name, otherwise the result is deletion-unconfirmed (never replay). No DLO, run or data cleanup; exhaustive external-consumer exclusion is not established. segment:Name uses auto/API68 in the run data space (the stored name, <prefix>_<Name> outside default; SEGMENT_DATASPACE_MISMATCH for another). Fresh source bindings and exact runtime/private identity are checked before one native DELETE. Only independent absence or a preserved DELETING/PROCESSING read acknowledges the result; HTTP204 alone is insufficient. No replay, Segment XML, shared-DMO deletion or physical-output cleanup guarantee. identity-resolution:ObjectApiName uses auto/API68 in the run data space (the stored name, <prefix>_<type>_<rulesetId> outside default; IDENTITY_RESOLUTION_DATASPACE_MISMATCH for another) and deletes a present owner that is not PUBLISHING or DELETING. A fresh target-local ID is resolved before one native68 DELETE; bounded exact ID/name absence confirms owner-definition deletion only. Exhaustive external-consumer exclusion and physical profile/output cleanup remain unverified. IR never cascades, runs processing, replays writes or falls back to another API. data-graph:Name uses auto/API68 in the run data space (graph names are unique in the org; DATA_GRAPH_DATASPACE_MISMATCH for a graph of another). Fresh identity, created date, definition, root and ready checks plus explicit empty native dependency/related-segment arrays are mandatory. A draft graph (never built, retrieved as-is) is deleted by name with the same scope and dependency checks. Exhaustive external-consumer exclusion remains unverified; no generated-resource cleanup, storage or credit guarantee. A Graph delete never cascades. calculated-insight:Name__cio uses --api-version auto (68.0) or 68.0 in the run data space (the GET must name it, CI_IDENTITY_CHANGED otherwise). The insight is read by name with the API 68 GET (absent is unchanged; it must answer with that name and data space), deleted with one DELETE in any status, schedule or SQL (Salesforce decides; a 4xx answer is reported as rejected), then read until it answers 404. CI never cascades; no compute, storage or credits guarantee. Exact data-stream:ApiName selects guarded IngestApi stream deletion at auto/API68 in the run data space (its DLO must belong to it). The linked DLO is preserved by default; --delete-dlo explicitly acknowledges deleting that exclusively linked DLO. Selected stream and linked DLO checks only, not unrelated-org preservation. Native routes default to API68; explicit numeric pins are preserved. Relationship deletion (relationship:SourceDmo__dlm:Name; a bare relationship:Name is refused with INVALID_SELECTION) runs first in its phase, before mappings, DMOs and DLOs. The relationships of the named source DMO are listed and the name is looked up ignoring letter case: no match is unchanged, two matches are refused (AMBIGUOUS_RELATIONSHIP_TARGET), and a match whose source object is another DMO is refused (RELATIONSHIP_TARGET_BINDING_MISMATCH). In a --changed-since delete the source DMO and binding come from the deleted file, and when its name is absent but the binding exists under another name the delete is refused with RELATIONSHIP_NAME_MISMATCH. Otherwise one DELETE is sent and its absence confirmed by listing again; a 4xx answer is reported as rejected. --preview only lists. A mapping:Name with a valid local data360/mapping/Name.mapping-meta.json file (with --changed-since, the deleted file's base content) is found in the org the way deploy finds it: by the file's source DLO and target DMO, whatever Salesforce named it (the org name is reported as targetApiName). No org mapping with that binding is unchanged; two or more are refused with AMBIGUOUS_MAPPING_TARGET before any write. Otherwise the exact name is read, and a mapping that reads absent (404) reports unchanged. Mapping deletion runs at native API 61 and up (default 68) and deletes the whole mapping with one Metadata API destructive deployment (ObjectSourceTargetMap), whatever pairs it holds, also onto a standard DMO (Salesforce refuses the last mapping onto a standard DMO copy in a data space other than default; a Failed destructive deployment is reported as rejected). Afterwards the mapping must read absent and the other mappings and the fields of the DMO must be unchanged. The last mapping of a custom DMO is refused before any write (MAPPING_LAST_MAPPING_DELETE_BLOCKED) because Salesforce does not delete it; delete the DMO instead, which removes its mapping. Qualification uses empty custom fixtures, not populated-data guarantees. --preview performs zero writes and reports the planned step. Any partial failure stops the batch; no retries or rollback. Whole-DMO deletion is sent for every DMO, a standard one (creationType Standard) and one read without a creationType included, and Salesforce decides: a 4xx answer is reported as rejected (for example, Salesforce refuses to delete a platform-generated DMO while the identity resolution or graph that owns it exists). Field-level delete: exactly one dmo:Name__dlm with one or more --field Name__c removes the named fields from that DMO. It is the one delete operation that changes mappings it was not given and writes project files. Reads first: every field must exist on the DMO. Any field but the primary key may be named, also the standard, system and generated fields of any DMO: Salesforce decides, and a refused destructive change is reported as rejected. This is the only command that removes such platform-owned fields; every mapping pair targeting a named field is collected, and a mapped field is refused only when the mapping list fails; one that no mapping lists a pair for has no pair to lose and is removed. Then one Metadata API destructive change for all fields, sent once and never retried; Salesforce drops the mapping pairs of the removed fields itself. Fresh reads right before it must still match the plan, and polled reads afterwards must show the fields absent, exactly the collected pairs gone and every other mapping, pair, DMO property and field unchanged; any other difference fails with DMO_FIELD_REMOVAL_SIDE_EFFECT. Nothing is rolled back. After success the existing data360/dmo and data360/mapping files under --output-dir (default: current directory) are overwritten with the current definitions; absent files are not created and no file is deleted. A failed file refresh keeps the confirmed org result and the run is partial (exit 68, LOCAL_REFRESH_FAILED). --field --preview writes nothing and reports pairs, fields and files. --field cannot be combined with another selector, --changed-since or --delete-dlo. Local files: after a confirmed deletion (deleted, or a DLO, DMO, Segment or IR Salesforce accepted and is still deleting) the component's own local file is removed by default, one regular file at a time at its canonical path and never a folder: data360/dlo, data360/dmo, data360/relationship, data360/data-stream, data360/dataTransforms, data360/identityResolution and data360/dataGraphs files, both files of a CI (data360/calculatedInsights/Name__cio.calculatedInsight-meta.json and .calculatedInsight-meta.sql) and the Segment files (data360/segments/Name.segment.json and every Name.segment.*.sql beside it) under the current directory (with --delete-dlo also the linked DLO's file), and the mapping file of that name or the one whose binding matches. Links, hard-linked files and paths outside those folders are refused. Nothing is removed on --preview, which lists the files instead, nor for unchanged, blocked, failed, rejected or unconfirmed deletions. --keep-local-files keeps them. A failed removal keeps the confirmed org result and the run is partial (exit 68) with LOCAL_FILE_REMOVAL_FAILED when a deletion is confirmed, otherwise processing (exit 69).";
509
+ static description = "One delete can carry any mix of families, each named exactly with -m. It runs them in reverse dependency order, one phase after the other: graphs, then identity resolution, calculated insights and Segments (a dependent before the component it needs, including a graph or CI/Segment on the unified DMO of a selected IR), then data transforms, then relationships, mappings, DMOs and DLOs, then data streams. A phase starts only after every item of the previous one settled; a blocked, failed or unconfirmed item stops the run, and an item Salesforce is still processing stops the later phases with DELETE_PHASE_NOT_SETTLED (status processing, exit 69, when nothing failed). Without --preview the delete first runs the same selection read-only, lists every component it would delete and asks once (y/yes deletes; no, no answer within 30 seconds or a failed question sends nothing and reports DELETE_CANCELLED with exit 0); nothing to delete asks nothing. Without a terminal, or with --json, a delete needs --no-prompt (-r) and is otherwise refused before any org call with CONFIRMATION_REQUIRED. --preview never asks. Before the first delete, the current definition of each selected transform, Segment, IR, CI and graph is read from the org by its name (read-only); one the org does not have reports unchanged. A transform name resolves to its target ID through the complete transform list: no match is unchanged, two or more matches (ignoring case) are refused with TRANSFORM_TARGET_NOT_RESOLVED. --changed-since <ref> selects the canonical plugin files deleted since the merge base with that reference (every family; changed files are ignored) and deletes their components in the same phase order. Identity and definition come from each file's base content; a path present again is not a delete, while a rename (also one split across commit, index and worktree), an unstaged deletion or a deleted file of no known family blocks before any org call (BLOCKED_GIT_LIFECYCLE). A --changed-since delete takes no -m or --delete-dlo, and removes no local file. A deleted data transform is resolved by its name like a -m one; a relationship takes its source DMO from the base content; a stream file deleted together with its landing DLO file deletes the stream with its DLO. --preview runs every phase read-only and reports an item whose selected dependents an earlier phase deletes as planned-dependencies (DEPENDENCIES_PLANNED) without checking it further. A stream selected together with its landing DLO is deleted with --delete-dlo semantics and the DLO item reports removedWith the stream; the last mapping of a custom DMO selected together with that DMO is not sent on its own and reports removedWith the DMO; it reports deleted only once its own read answers 404 after the DMO deletion, otherwise deletion-unconfirmed (MAPPING_DELETION_UNCONFIRMED). data-transform:Name uses auto/API68 in the run data space (TRANSFORM_DATASPACE_MISMATCH for another). Preview is GET-only. A target of any owner or namespace is deleted with one native DELETE (Salesforce decides; a 4xx answer is reported as rejected); one whose status is PROCESSING is refused before it (TRANSFORM_DELETE_PROCESSING, in --preview too); settlement needs complete bounded inventory omission of both ID and name, otherwise the result is deletion-unconfirmed (never replay). No DLO, run or data cleanup; exhaustive external-consumer exclusion is not established. segment:Name uses auto/API68 in the run data space (the stored name, <prefix>_<Name> outside default; SEGMENT_DATASPACE_MISMATCH for another). Fresh source bindings and exact runtime/private identity are checked before one native DELETE. Only independent absence or a preserved DELETING/PROCESSING read acknowledges the result; HTTP204 alone is insufficient. No replay, Segment XML, shared-DMO deletion or physical-output cleanup guarantee. identity-resolution:ObjectApiName uses auto/API68 in the run data space (the stored name, <prefix>_<type>_<rulesetId> outside default; IDENTITY_RESOLUTION_DATASPACE_MISMATCH for another) and deletes a present owner that is not PUBLISHING or DELETING. A fresh target-local ID is resolved before one native68 DELETE; bounded exact ID/name absence confirms owner-definition deletion only. Exhaustive external-consumer exclusion and physical profile/output cleanup remain unverified. IR never cascades, runs processing, replays writes or falls back to another API. data-graph:Name uses auto/API68 in the run data space (graph names are unique in the org; DATA_GRAPH_DATASPACE_MISMATCH for a graph of another). Fresh identity, created date, definition, root and ready checks plus explicit empty native dependency/related-segment arrays are mandatory. A draft graph (never built, retrieved as-is) is deleted by name with the same scope and dependency checks. Exhaustive external-consumer exclusion remains unverified; no generated-resource cleanup, storage or credit guarantee. A Graph delete never cascades. calculated-insight:Name__cio uses --api-version auto (68.0) or 68.0 in the run data space (the GET must name it, CI_IDENTITY_CHANGED otherwise). The insight is read by name with the API 68 GET (absent is unchanged; it must answer with that name and data space), deleted with one DELETE in any status, schedule or SQL (Salesforce decides; a 4xx answer is reported as rejected), then read until it answers 404. CI never cascades; no compute, storage or credits guarantee. Exact data-stream:ApiName selects guarded IngestApi stream deletion at auto/API68 in the run data space (its DLO must belong to it). The linked DLO is preserved by default; --delete-dlo explicitly acknowledges deleting that exclusively linked DLO. Selected stream and linked DLO checks only, not unrelated-org preservation. Native routes default to API68; explicit numeric pins are preserved. Relationship deletion (relationship:SourceDmo__dlm:Name; a bare relationship:Name is refused with INVALID_SELECTION) runs first in its phase, before mappings, DMOs and DLOs. The relationships of the named source DMO are listed and the name is looked up ignoring letter case: no match is unchanged, two matches are refused (AMBIGUOUS_RELATIONSHIP_TARGET), and a match whose source object is another DMO is refused (RELATIONSHIP_TARGET_BINDING_MISMATCH). In a --changed-since delete the source DMO and binding come from the deleted file, and when its name is absent but the binding exists under another name the delete is refused with RELATIONSHIP_NAME_MISMATCH. Otherwise one DELETE is sent and its absence confirmed by listing again; a 4xx answer is reported as rejected. --preview only lists. A mapping:Name with a valid local data360/mapping/Name.mapping-meta.json file (with --changed-since, the deleted file's base content) is found in the org the way deploy finds it: by the file's source DLO and target DMO, whatever Salesforce named it (the org name is reported as targetApiName). No org mapping with that binding is unchanged; two or more are refused with AMBIGUOUS_MAPPING_TARGET before any write. Otherwise the exact name is read, and a mapping that reads absent (404) reports unchanged. Mapping deletion runs at native API 61 and up (default 68) and deletes the whole mapping with one Metadata API destructive deployment (ObjectSourceTargetMap), whatever pairs it holds, also onto a standard DMO (Salesforce refuses the last mapping onto a standard DMO copy in a data space other than default; a Failed destructive deployment is reported as rejected). Afterwards the mapping must read absent and the other mappings and the fields of the DMO must be unchanged. The last mapping of a custom DMO is refused before any write (MAPPING_LAST_MAPPING_DELETE_BLOCKED) because Salesforce does not delete it; delete the DMO instead, which removes its mapping. Qualification uses empty custom fixtures, not populated-data guarantees. --preview performs zero writes and reports the planned step. Any partial failure stops the batch; no retries or rollback. Whole-DMO deletion is sent for every DMO, a standard one (creationType Standard) and one read without a creationType included, and Salesforce decides: a 4xx answer is reported as rejected (for example, Salesforce refuses to delete a platform-generated DMO while the identity resolution or graph that owns it exists). Field-level delete: exactly one dmo:Name__dlm with one or more --field Name__c removes the named fields from that DMO. It is the one delete operation that changes mappings it was not given and writes project files. Reads first: every field must exist on the DMO. Any field but the primary key may be named, also the standard, system and generated fields of any DMO: Salesforce decides, and a refused destructive change is reported as rejected. This is the only command that removes such platform-owned fields; every mapping pair targeting a named field is collected, and a mapped field is refused only when the mapping list fails; one that no mapping lists a pair for has no pair to lose and is removed. Then one Metadata API destructive change for all fields, sent once and never retried; Salesforce drops the mapping pairs of the removed fields itself. Fresh reads right before it must still match the plan, and polled reads afterwards must show the fields absent, exactly the collected pairs gone and every other mapping, pair, DMO property and field unchanged; any other difference fails with DMO_FIELD_REMOVAL_SIDE_EFFECT. Nothing is rolled back. After success the existing data360/dmo and data360/mapping files under --output-dir (default: current directory) are overwritten with the current definitions; absent files are not created and no file is deleted. A failed file refresh keeps the confirmed org result and the run is partial (exit 68, LOCAL_REFRESH_FAILED). --field --preview writes nothing and reports pairs, fields and files. --field cannot be combined with another selector, --changed-since or --delete-dlo. Local files: after a confirmed deletion (deleted, or a DLO, DMO, Segment or IR Salesforce accepted and is still deleting) the component's own local file is removed by default, one regular file at a time at its canonical path and never a folder: data360/dlo, data360/dmo, data360/relationship, data360/data-stream, data360/dataTransforms, data360/identityResolution and data360/dataGraphs files, both files of a CI (data360/calculatedInsights/Name__cio.calculatedInsight-meta.json and .calculatedInsight-meta.sql) and the Segment files (data360/segments/Name.segment.json and every Name.segment.*.sql beside it) under the current directory (with --delete-dlo also the linked DLO's file), and the mapping file of that name or the one whose binding matches. Links, hard-linked files and paths outside those folders are refused. Nothing is removed on --preview, which lists the files instead, nor for unchanged, blocked, failed, rejected or unconfirmed deletions. --keep-local-files keeps them. A failed removal keeps the confirmed org result and the run is partial (exit 68) with LOCAL_FILE_REMOVAL_FAILED when a deletion is confirmed, otherwise processing (exit 69).";
478
510
  static flags = {
479
511
  'target-org': Flags.string({
480
512
  char: 'o',
@@ -496,12 +528,13 @@ export default class Delete extends SfCommand {
496
528
  }),
497
529
  preview: Flags.boolean({ default: false, summary: 'Look up and report only; never delete.' }),
498
530
  'changed-since': Flags.string({
499
- summary: 'Delete in the org the components whose canonical plugin files were deleted since the merge base with a commit reference; needs --confirm-delete (not with --preview).',
531
+ summary: 'Delete in the org the components whose canonical plugin files were deleted since the merge base with a commit reference.',
500
532
  exclusive: ['metadata'],
501
533
  }),
502
- 'confirm-delete': Flags.boolean({
503
- dependsOn: ['changed-since'],
504
- summary: 'With --changed-since only: delete the components of the files deleted in the Git range. Not needed with --preview.',
534
+ 'no-prompt': Flags.boolean({
535
+ char: 'r',
536
+ default: false,
537
+ summary: 'Delete without asking for confirmation.',
505
538
  }),
506
539
  'delete-dlo': Flags.boolean({
507
540
  default: false,
@@ -566,11 +599,13 @@ export default class Delete extends SfCommand {
566
599
  readStreamLinkedDlo = readStreamLinkedDlo;
567
600
  preflightDeleteDataStream = preflightDeleteDataStream;
568
601
  executeDeleteDataStream = executeDeleteDataStream;
602
+ // The Connection the stream clients read and delete on; the library passes its caller's.
603
+ streamConnection = async (target, version) => Connection.create({
604
+ authInfo: await AuthInfo.create({ username: target }),
605
+ connectionOptions: { version },
606
+ });
569
607
  createDataStreamClients = async (target, version) => {
570
- const connection = await Connection.create({
571
- authInfo: await AuthInfo.create({ username: target }),
572
- connectionOptions: { version },
573
- });
608
+ const connection = await this.streamConnection(target, version);
574
609
  const reader = new ConnectClient(connection, version);
575
610
  return {
576
611
  // DELETE (including the DLO cascade) is sent once on this same bound Connection.
@@ -715,7 +750,7 @@ export default class Delete extends SfCommand {
715
750
  const fields = [...new Set(flags.field)];
716
751
  // The run's data space, always explicit: --dataspace, or default.
717
752
  const effectiveScope = flags.dataspace ?? 'default';
718
- const root = path.resolve(flags['output-dir'] ?? process.cwd());
753
+ const root = path.resolve(this.projectDirectory(), flags['output-dir'] ?? '.');
719
754
  const item = {
720
755
  family: 'dmo',
721
756
  identity: { dataSpace: effectiveScope, apiName },
@@ -826,7 +861,7 @@ export default class Delete extends SfCommand {
826
861
  return;
827
862
  }
828
863
  envelope.status = 'failed';
829
- refuse('LOCAL_REFRESH_FAILED', `The field(s) ${fields.join(', ')} were deleted from ${apiName} in the org, but ${failed.length === 1 ? 'this project file was' : 'these project files were'} not refreshed: ${failed.map((file) => `${file.path} (${file.code})`).join('; ')}. Do not repeat the delete; refresh with sf data360 retrieve and --overwrite.`);
864
+ refuse('LOCAL_REFRESH_FAILED', `The field(s) ${fields.join(', ')} were deleted from ${apiName} in the org, but ${failed.length === 1 ? 'this project file was' : 'these project files were'} not refreshed: ${failed.map((file) => `${file.path} (${file.code})`).join('; ')}. Do not repeat the delete; refresh with sf data360 retrieve.`);
830
865
  }
831
866
  /**
832
867
  * Delete or preview one relationship by name. The source DMO, named in the selector (or with
@@ -896,8 +931,8 @@ export default class Delete extends SfCommand {
896
931
  item.identity.apiName = apiName;
897
932
  const files = [
898
933
  {
899
- path: path.join(process.cwd(), 'data360', 'relationship', `${apiName}.relationship-meta.json`),
900
- boundary: path.join(process.cwd(), 'data360'),
934
+ path: path.join(this.projectDirectory(), 'data360', 'relationship', `${apiName}.relationship-meta.json`),
935
+ boundary: path.join(this.projectDirectory(), 'data360'),
901
936
  },
902
937
  ];
903
938
  if (preview) {
@@ -931,32 +966,148 @@ export default class Delete extends SfCommand {
931
966
  */
932
967
  async run() {
933
968
  const { flags } = await this.parse(Delete);
934
- const effectiveScope = flags.dataspace ?? 'default';
969
+ if (flags.preview || flags['no-prompt'])
970
+ return this.execute(flags, false);
971
+ // Refused before any org read when nobody can answer the question.
972
+ if (this.jsonEnabled() || !this.interactiveTerminal()) {
973
+ const envelope = newEnvelope(flags);
974
+ envelope.diagnostics.errors.push({
975
+ code: 'CONFIRMATION_REQUIRED',
976
+ message: 'Deleting needs confirmation: run it in a terminal, or pass --no-prompt. Check the selection with --preview first.',
977
+ retryable: false,
978
+ });
979
+ process.exitCode = exitCodeOf(envelope);
980
+ annotateDiagnostics(envelope);
981
+ if (!this.jsonEnabled()) {
982
+ this.log('Delete: blocked.');
983
+ for (const diagnostic of envelope.diagnostics.errors)
984
+ this.log(formatDiagnostic(diagnostic));
985
+ }
986
+ return envelope;
987
+ }
988
+ // The same delete, read-only and silent, shows what would be deleted.
989
+ const preview = await this.execute({ ...flags, preview: true }, true);
990
+ // A preview that was refused or failed asks nothing: its refusal is the run's result.
991
+ if (preview.status !== 'success')
992
+ return this.refusedPreview(preview);
993
+ const planned = preview.result.items.filter((item) => wouldDelete(item));
994
+ if (planned.length === 0)
995
+ return this.execute(flags, false);
996
+ const { dataSpace } = preview.result.scope;
997
+ const message = [
998
+ `Delete ${planned.length} component(s) from data space ${dataSpace}?`,
999
+ ...planned.map((item) => ` ${item.family}:${item.identity.apiName}${item.fields?.length ? ` fields ${item.fields.join(', ')}` : ''}${item.removedWith ? ` (removed with ${item.removedWith})` : ''}`),
1000
+ 'Dependent mappings, DLOs and fields may be found during the run.',
1001
+ ].join('\n');
1002
+ let confirmed = false;
1003
+ try {
1004
+ confirmed = await this.confirmDeletion(message);
1005
+ }
1006
+ catch {
1007
+ confirmed = false;
1008
+ }
1009
+ if (confirmed)
1010
+ return this.execute(flags, false);
1011
+ return this.cancelled(preview);
1012
+ }
1013
+ /**
1014
+ * Whether a person can answer the confirmation question: stdin and stdout are terminals.
1015
+ * @returns {boolean} True in an interactive terminal.
1016
+ */
1017
+ interactiveTerminal() {
1018
+ return process.stdin.isTTY === true && process.stdout.isTTY === true;
1019
+ }
1020
+ /**
1021
+ * Report data graph progress while the delete waits (for example a retried graph DELETE).
1022
+ * oclif logToStderr suppresses output in JSON mode; progress must remain visible.
1023
+ * @param {string} message One progress line.
1024
+ */
1025
+ graphProgress(message) {
1026
+ process.stderr.write(`${message}\n`);
1027
+ }
1028
+ /**
1029
+ * The project root: where data360/ lives (local files removed or refreshed, relative
1030
+ * --output-dir) and the Git selection runs. The CLI uses the current directory.
1031
+ * @returns {string} Absolute project root.
1032
+ */
1033
+ projectDirectory() {
1034
+ return process.cwd();
1035
+ }
1036
+ /**
1037
+ * Ask once whether to delete; no answer within 30 seconds is no.
1038
+ * @param {string} message Question and the components it deletes.
1039
+ * @returns {Promise<boolean>} True only for an explicit yes.
1040
+ */
1041
+ async confirmDeletion(message) {
1042
+ return this.confirm({ message, ms: 30_000, defaultAnswer: false });
1043
+ }
1044
+ /**
1045
+ * The envelope of a delete whose silent preview did not succeed: its refusal, nothing sent and
1046
+ * nothing asked.
1047
+ * @param {DeleteEnvelope} preview Envelope of the silent preview (blocked, failed or other).
1048
+ * @returns {DeleteEnvelope} The preview's status, items and diagnostics.
1049
+ */
1050
+ refusedPreview(preview) {
935
1051
  const envelope = {
936
- contract: 'sf-data360-delete',
937
- contractVersion: '1.1.0',
938
- status: 'blocked',
939
- metadata: {
940
- operation: 'delete',
941
- preview: flags.preview,
942
- apiVersion: flags['api-version'] ?? 'auto',
943
- plugin,
944
- },
945
- provenance: {
946
- command: 'sf data360 delete',
947
- generatedAt: new Date().toISOString(),
948
- // eslint-disable-next-line unicorn/no-null -- Stable JSON represents unresolved target identity explicitly.
949
- targetOrgId: null,
1052
+ ...preview,
1053
+ metadata: { ...preview.metadata, preview: false },
1054
+ };
1055
+ const exitCode = exitCodeOf(envelope);
1056
+ if (exitCode !== 0)
1057
+ process.exitCode = exitCode;
1058
+ if (!this.jsonEnabled()) {
1059
+ this.log(`Delete: ${envelope.status}; nothing was deleted.`);
1060
+ for (const diagnostic of envelope.diagnostics.errors)
1061
+ this.log(formatDiagnostic(diagnostic));
1062
+ }
1063
+ return envelope;
1064
+ }
1065
+ /**
1066
+ * The envelope of a delete the user did not confirm: the preview items, nothing sent.
1067
+ * @param {DeleteEnvelope} preview Envelope of the silent preview.
1068
+ * @returns {DeleteEnvelope} Cancelled envelope, status success.
1069
+ */
1070
+ cancelled(preview) {
1071
+ const reason = 'The delete was not confirmed, so nothing was sent to the org.';
1072
+ const envelope = {
1073
+ ...preview,
1074
+ status: 'success',
1075
+ metadata: { ...preview.metadata, preview: false },
1076
+ diagnostics: {
1077
+ warnings: [`DELETE_CANCELLED: ${reason}`, ...preview.diagnostics.warnings],
1078
+ errors: preview.diagnostics.errors,
950
1079
  },
951
- diagnostics: { warnings: [], errors: [] },
952
- result: { scope: { dataSpace: effectiveScope }, items: [] },
953
1080
  };
1081
+ for (const item of envelope.result.items) {
1082
+ item.mutation = 'not-attempted';
1083
+ item.diagnostics = [
1084
+ ...(item.diagnostics ?? []),
1085
+ { code: 'DELETE_CANCELLED', message: reason },
1086
+ ];
1087
+ }
1088
+ annotateDiagnostics(envelope);
1089
+ if (!this.jsonEnabled()) {
1090
+ this.log('Delete: cancelled; nothing was deleted.');
1091
+ for (const item of envelope.result.items)
1092
+ this.log(`Not deleted: ${item.family}:${item.identity.apiName}.`);
1093
+ }
1094
+ return envelope;
1095
+ }
1096
+ /**
1097
+ * Run the delete, or its preview, and complete the envelope.
1098
+ * @param {DeleteFlags} flags Parsed flags.
1099
+ * @param {boolean} quiet No output and no exit code: the preview before the question.
1100
+ * @returns {Promise<DeleteEnvelope>} Payload-free deletion evidence.
1101
+ */
1102
+ async execute(flags, quiet) {
1103
+ const effectiveScope = flags.dataspace ?? 'default';
1104
+ const envelope = newEnvelope(flags);
954
1105
  const selectorsByItem = new Map();
955
1106
  const keepLocalFiles = flags['keep-local-files'];
956
1107
  const changedSince = flags['changed-since'];
957
1108
  // A file deleted in the Git range is already gone: no local file is listed or removed.
958
1109
  const gitMode = changedSince !== undefined;
959
- const projectData = path.join(process.cwd(), 'data360');
1110
+ const projectData = path.join(this.projectDirectory(), 'data360');
960
1111
  // The local files of each item; removed once its deletion is confirmed.
961
1112
  const localFiles = new Map();
962
1113
  const inProject = (...segments) => ({
@@ -1081,10 +1232,10 @@ export default class Delete extends SfCommand {
1081
1232
  await removeConfirmedFiles();
1082
1233
  envelope.status = settledStatus();
1083
1234
  const exitCode = exitCodeOf(envelope);
1084
- if (exitCode !== 0)
1235
+ if (exitCode !== 0 && !quiet)
1085
1236
  process.exitCode = exitCode;
1086
1237
  annotateDiagnostics(envelope);
1087
- if (!this.jsonEnabled()) {
1238
+ if (!quiet && !this.jsonEnabled()) {
1088
1239
  this.log(`Delete${flags.preview ? ' preview' : ''}: ${envelope.status}.`);
1089
1240
  // The default data space goes without saying; any other is named.
1090
1241
  if (effectiveScope !== 'default')
@@ -1219,7 +1370,10 @@ export default class Delete extends SfCommand {
1219
1370
  let gitDeletions = [];
1220
1371
  if (changedSince !== undefined) {
1221
1372
  envelope.result.selection = { changedSince };
1222
- const selected = await this.selectGitInputs({ cwd: process.cwd(), ref: changedSince });
1373
+ const selected = await this.selectGitInputs({
1374
+ cwd: this.projectDirectory(),
1375
+ ref: changedSince,
1376
+ });
1223
1377
  envelope.provenance.git = selected.provenance;
1224
1378
  gitDeletions = selected.deletions ?? [];
1225
1379
  if (gitDeletions.length === 0) {
@@ -1317,12 +1471,6 @@ export default class Delete extends SfCommand {
1317
1471
  : new DloError('INVALID_SELECTION');
1318
1472
  admitted.set(selector, { desired: source.desired });
1319
1473
  }
1320
- // A Git delete is never an implicit destructive run; a -m delete needs no confirmation.
1321
- if (gitMode && !flags.preview && flags['confirm-delete'] !== true) {
1322
- const error = new DloError('DESTRUCTIVE_CONFIRMATION_REQUIRED');
1323
- replaceExplanation(error, 'Files deleted in the Git range are deleted in the org only with --confirm-delete. Check the selection with --preview, then rerun with --confirm-delete. Nothing was deleted.');
1324
- throw error;
1325
- }
1326
1474
  // Right before each stage: a file deleted in the range must still be gone.
1327
1475
  const stillDeleted = async (candidate) => {
1328
1476
  if (candidate === undefined)
@@ -1488,6 +1636,7 @@ export default class Delete extends SfCommand {
1488
1636
  preview: flags.preview,
1489
1637
  confirmed: true,
1490
1638
  verifyInput,
1639
+ progress: (message) => this.graphProgress(message),
1491
1640
  });
1492
1641
  const item = {
1493
1642
  family: 'data-graph',
@@ -1602,7 +1751,7 @@ export default class Delete extends SfCommand {
1602
1751
  }
1603
1752
  if (result.outcome === 'blocked') {
1604
1753
  envelope.diagnostics.errors.push({
1605
- code: 'DESTRUCTIVE_CONFIRMATION_REQUIRED',
1754
+ code: 'CONFIRMATION_REQUIRED',
1606
1755
  message: 'The transform delete was not confirmed; nothing was changed.',
1607
1756
  retryable: false,
1608
1757
  });
@@ -2099,7 +2248,7 @@ export default class Delete extends SfCommand {
2099
2248
  if (resolved !== undefined)
2100
2249
  return [canonical];
2101
2250
  try {
2102
- const found = await mappingLocalFile(normalizeNativeMapping(firstRead, effectiveScope, 'retrieve'), process.cwd());
2251
+ const found = await mappingLocalFile(normalizeNativeMapping(firstRead, effectiveScope, 'retrieve'), this.projectDirectory());
2103
2252
  return [{ path: found.path, boundary: projectData }];
2104
2253
  }
2105
2254
  catch {