sf-plugin-data 0.5.0 → 0.5.2

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.
@@ -566,7 +566,8 @@ export default class Delete extends SfCommand {
566
566
  deleteCalculatedInsight = deleteCalculatedInsight;
567
567
  /** The org ID of the connection this run resolved (provenance only); unset before that. */
568
568
  resolvedOrgId;
569
- // No configured or resolvable org is TARGET_ORG_REQUIRED, as in publish.
569
+ // Without --target-org an unusable org is TARGET_ORG_REQUIRED; a given one is
570
+ // AUTHENTICATION_FAILED, as in publish.
570
571
  resolveConnection = async (alias) => {
571
572
  try {
572
573
  const aggregator = await ConfigAggregator.create();
@@ -580,7 +581,7 @@ export default class Delete extends SfCommand {
580
581
  });
581
582
  }
582
583
  catch {
583
- throw new DloError('TARGET_ORG_REQUIRED');
584
+ throw new DloError(alias === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED');
584
585
  }
585
586
  };
586
587
  /**
@@ -19,7 +19,7 @@ import { preflightDataStream, executeDataStream, } from '../../services/command-
19
19
  import { verifyDataStreamInputDigest } from '../../artifacts/read-deploy-input.js';
20
20
  import { DataStreamError } from '../../artifacts/data-stream-document.js';
21
21
  import { dataStreamApiVersion } from '../../transport/api-version.js';
22
- import { ConnectClient } from '../../transport/connect-client.js';
22
+ import { ConnectClient, ConnectError } from '../../transport/connect-client.js';
23
23
  import { createDataStreamClient, createDataStreamReferenceReader, } from '../../transport/data-stream-rest.js';
24
24
  import { preflightMapping, executeMapping } from '../../services/command-native-mapping.js';
25
25
  import { createMappingClient } from '../../transport/mapping-rest.js';
@@ -101,8 +101,9 @@ const resolveTargetOrg = async (aliasOrUsername) => {
101
101
  };
102
102
  }
103
103
  catch (error) {
104
+ // A given --target-org that cannot be used is an authentication failure (cause kept).
104
105
  if (aliasOrUsername)
105
- throw error;
106
+ throw Object.assign(new ConnectError('AUTHENTICATION_FAILED'), { cause: error });
106
107
  return undefined;
107
108
  }
108
109
  };
@@ -1479,6 +1480,8 @@ export default class Deploy extends SfCommand {
1479
1480
  };
1480
1481
  let failed = false;
1481
1482
  let blocked = false;
1483
+ // Items whose own preflight stopped the run: their reason is also the execute item's.
1484
+ const stoppers = new Set();
1482
1485
  for (const input of inputs) {
1483
1486
  // A parent created by an earlier stage of this preview does not exist yet: report the
1484
1487
  // item as planned instead of comparing it against a target that cannot hold it.
@@ -1530,6 +1533,7 @@ export default class Deploy extends SfCommand {
1530
1533
  (preview.outcome === 'create' &&
1531
1534
  !effects.includes('generated-output-provisioning')))) {
1532
1535
  blocked = true;
1536
+ stoppers.add(input.path);
1533
1537
  preview.diagnostics.push({
1534
1538
  code: 'PROCESSING_ACKNOWLEDGEMENT_REQUIRED',
1535
1539
  message: 'IR processing and CREATE generated-output provisioning require explicit --allow-processing. No batch writes were attempted.',
@@ -1545,6 +1549,7 @@ export default class Deploy extends SfCommand {
1545
1549
  ['create', 'update'].includes(preview.outcome) &&
1546
1550
  (flags['allow-processing'] !== true || !effects?.includes('processing'))) {
1547
1551
  blocked = true;
1552
+ stoppers.add(input.path);
1548
1553
  preview.diagnostics.push({
1549
1554
  code: 'PROCESSING_ACKNOWLEDGEMENT_REQUIRED',
1550
1555
  message: 'Segment create and update start processing in Data Cloud and need --allow-processing. Nothing was written.',
@@ -1558,11 +1563,14 @@ export default class Deploy extends SfCommand {
1558
1563
  operation: 'preview',
1559
1564
  path: input.path,
1560
1565
  });
1561
- if (preview.outcome === 'blocked' || preview.outcome === 'blocked-changes')
1566
+ if (preview.outcome === 'blocked' || preview.outcome === 'blocked-changes') {
1562
1567
  blocked = true;
1568
+ stoppers.add(input.path);
1569
+ }
1563
1570
  }
1564
1571
  catch (error) {
1565
1572
  failed = true;
1573
+ stoppers.add(input.path);
1566
1574
  envelope.result.items.push({
1567
1575
  identity: reportedIdentity(input.document, effectiveScope),
1568
1576
  operation: 'preview',
@@ -1630,7 +1638,7 @@ export default class Deploy extends SfCommand {
1630
1638
  .requiredEffects,
1631
1639
  }
1632
1640
  : {}),
1633
- diagnostics: [],
1641
+ diagnostics: stoppers.has(input.path) ? [...diagnostics] : [],
1634
1642
  };
1635
1643
  });
1636
1644
  // Keep whole-selection evidence, but never mistake admission for attempted execution.
@@ -58,11 +58,18 @@ export default class ListDataSpace extends SfCommand {
58
58
  connection = await this.resolveConnection(flags['target-org']);
59
59
  }
60
60
  catch {
61
- envelope.diagnostics.errors.push({
62
- code: 'TARGET_ORG_REQUIRED',
63
- message: 'No usable target org: pass -o with an authenticated alias or username, or set target-org.',
64
- retryable: false,
65
- });
61
+ // A given --target-org that cannot be used is an authentication failure.
62
+ envelope.diagnostics.errors.push(flags['target-org'] === undefined
63
+ ? {
64
+ code: 'TARGET_ORG_REQUIRED',
65
+ message: 'No usable target org: pass -o with an authenticated alias or username, or set target-org.',
66
+ retryable: false,
67
+ }
68
+ : {
69
+ code: 'AUTHENTICATION_FAILED',
70
+ message: 'The target org given with -o is unknown or not authenticated: log in to it with sf org login web, or pass another alias or username.',
71
+ retryable: false,
72
+ });
66
73
  return this.finish(envelope);
67
74
  }
68
75
  try {
@@ -137,7 +137,8 @@ export default class Publish extends SfCommand {
137
137
  await this.verifyCalculatedInsightInput(input);
138
138
  };
139
139
  await verifyInput();
140
- code = 'TARGET_ORG_REQUIRED';
140
+ // A given --target-org that cannot be used is an authentication failure.
141
+ code = flags['target-org'] === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED';
141
142
  const connection = await this.resolveConnection(flags['target-org']);
142
143
  code = 'CI_ADMISSION_FAILED';
143
144
  const context = this.calculatedInsightContext(connection, dataSpace);
@@ -225,7 +226,8 @@ export default class Publish extends SfCommand {
225
226
  await this.verifySegmentInput(input);
226
227
  };
227
228
  await verifyInput();
228
- code = 'TARGET_ORG_REQUIRED';
229
+ // A given --target-org that cannot be used is an authentication failure.
230
+ code = flags['target-org'] === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED';
229
231
  const connection = await this.resolveConnection(flags['target-org']);
230
232
  const result = await this.publishSegment(apiName, connection, { requested: '68.0', restSelector: 'v68.0', soapNumeric: '68.0' }, {
231
233
  preview: flags.preview,
@@ -627,7 +627,9 @@ export default class Retrieve extends SfCommand {
627
627
  org = await this.resolveOrg(flags['target-org']);
628
628
  }
629
629
  catch {
630
- return { status: 'blocked', selection: selectors, code: 'TARGET_ORG_REQUIRED' };
630
+ // A given --target-org that cannot be used is an authentication failure.
631
+ const code = flags['target-org'] === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED';
632
+ return { status: 'blocked', selection: selectors, code };
631
633
  }
632
634
  const connection = org.getConnection('68.0');
633
635
  envelope.provenance.sourceOrgId ??= org.getOrgId();
@@ -741,7 +743,9 @@ export default class Retrieve extends SfCommand {
741
743
  org = await this.resolveOrg(flags['target-org']);
742
744
  }
743
745
  catch {
744
- return { status: 'blocked', selection: selectors, code: 'TARGET_ORG_REQUIRED' };
746
+ // A given --target-org that cannot be used is an authentication failure.
747
+ const code = flags['target-org'] === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED';
748
+ return { status: 'blocked', selection: selectors, code };
745
749
  }
746
750
  const connection = org.getConnection(version);
747
751
  const target = flags['target-org'] ?? connection.getUsername();
@@ -1008,7 +1012,9 @@ export default class Retrieve extends SfCommand {
1008
1012
  org = await this.resolveOrg(flags['target-org']);
1009
1013
  }
1010
1014
  catch {
1011
- return { status: 'blocked', selection: selectors, code: 'TARGET_ORG_REQUIRED' };
1015
+ // A given --target-org that cannot be used is an authentication failure.
1016
+ const code = flags['target-org'] === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED';
1017
+ return { status: 'blocked', selection: selectors, code };
1012
1018
  }
1013
1019
  const connection = org.getConnection(version);
1014
1020
  const target = flags['target-org'] ?? connection.getUsername();
@@ -1335,7 +1341,9 @@ export default class Retrieve extends SfCommand {
1335
1341
  org = await this.resolveOrg(flags['target-org']);
1336
1342
  }
1337
1343
  catch {
1338
- return { status: 'blocked', selection: selectors, code: 'TARGET_ORG_REQUIRED' };
1344
+ // A given --target-org that cannot be used is an authentication failure.
1345
+ const code = flags['target-org'] === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED';
1346
+ return { status: 'blocked', selection: selectors, code };
1339
1347
  }
1340
1348
  let selection = selectors;
1341
1349
  const before = envelope.diagnostics.errors.length;
@@ -1960,7 +1968,8 @@ export default class Retrieve extends SfCommand {
1960
1968
  org = await this.resolveOrg(flags['target-org']);
1961
1969
  }
1962
1970
  catch {
1963
- throw new DataSpaceError('TARGET_ORG_REQUIRED');
1971
+ // A given --target-org that cannot be used is an authentication failure.
1972
+ throw new DataSpaceError(flags['target-org'] === undefined ? 'TARGET_ORG_REQUIRED' : 'AUTHENTICATION_FAILED');
1964
1973
  }
1965
1974
  const connection = org.getConnection('68.0');
1966
1975
  return openBoundSsot(flags['target-org'] ?? '', '68.0', async () => connection);
@@ -163,7 +163,10 @@ export default class SegmentMembersExport extends SfCommand {
163
163
  connection = await this.resolveConnection(flags['target-org']);
164
164
  }
165
165
  catch {
166
- return fail('TARGET_ORG_REQUIRED', 'No usable target org: pass -o with an authenticated alias or username, or set target-org.');
166
+ // A given --target-org that cannot be used is an authentication failure.
167
+ return flags['target-org'] === undefined
168
+ ? fail('TARGET_ORG_REQUIRED', 'No usable target org: pass -o with an authenticated alias or username, or set target-org.')
169
+ : fail('AUTHENTICATION_FAILED', 'The target org given with -o is unknown or not authenticated: log in to it with sf org login web, or pass another alias or username.');
167
170
  }
168
171
  const sender = this.createSender
169
172
  ? this.createSender(connection, version)
@@ -48,6 +48,40 @@ function safeMessage(value) {
48
48
  return;
49
49
  return message;
50
50
  }
51
+ /**
52
+ * Salesforce's segment criteria validator answers with a serialized list of error blocks
53
+ * (`... Errors: [class DbtSqlValidationErrorBlock {\n errorCode: X\n arguments: [text]\n}]`),
54
+ * which safeMessage refuses for its brackets and line breaks. Keep the lead sentence and the code
55
+ * and text of each block (at most three); every text part passes safeMessage on its own, and a
56
+ * block whose text does not keeps its code alone. The joined message must pass safeMessage too.
57
+ * @param {unknown} value Structured API message leaf.
58
+ * @returns {string | undefined} The rewritten message, or undefined for any other shape.
59
+ */
60
+ function validationBlocks(value) {
61
+ if (typeof value !== 'string' || value.length > 4000)
62
+ return;
63
+ const start = value.indexOf(' Errors: [class ');
64
+ if (start === -1)
65
+ return;
66
+ const lead = safeMessage(value.slice(0, start))?.replace(/\.$/u, '');
67
+ const blocks = [
68
+ ...value
69
+ .slice(start)
70
+ .matchAll(/\{\s*errorCode: ([A-Z][A-Z0-9_]{0,79})\s+arguments: \[([^\n]*)\]\s*\}/gu),
71
+ ]
72
+ .slice(0, 3)
73
+ .map(([, code, text]) => {
74
+ const safe = safeMessage(text);
75
+ return safe ? `${code}: ${safe}` : code;
76
+ });
77
+ while (blocks.length > 0 && `${lead}: ${blocks.join('; ')}`.length > 400)
78
+ blocks.pop();
79
+ if (!lead || blocks.length === 0)
80
+ return;
81
+ // Parts that pass one by one can still form a refused pattern together (select … from).
82
+ const message = `${lead}: ${blocks.join('; ')}`;
83
+ return safeMessage(message) === undefined ? undefined : message;
84
+ }
51
85
  /**
52
86
  * Normalize only REST error records/arrays and their known data/errors containers.
53
87
  * No arbitrary keys, native Error.message, causes or raw objects are retained.
@@ -95,7 +129,7 @@ function apiErrors(candidate) {
95
129
  if (budget < 0)
96
130
  return;
97
131
  const code = typeof rawCode === 'string' && /^[A-Z][A-Z0-9_]{0,79}$/u.test(rawCode) ? rawCode : undefined;
98
- const message = safeMessage(rawMessage);
132
+ const message = safeMessage(rawMessage) ?? validationBlocks(rawMessage);
99
133
  const size = result.reduce((total, entry) => total + (entry.code?.length ?? 0) + (entry.message?.length ?? 0) + 4, 0);
100
134
  if ((code || message) && size + (code?.length ?? 0) + (message?.length ?? 0) + 4 <= 1300)
101
135
  result.push(Object.freeze({ ...(code ? { code } : {}), ...(message ? { message } : {}) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sf-plugin-data",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Salesforce CLI bootstrap for portable Data360 configuration",
5
5
  "author": {
6
6
  "name": "Jörn Berkefeld",