sf-plugin-data 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +589 -2
- package/bin/run.js +4 -0
- package/docs/artifact-format.md +527 -0
- package/docs/capabilities.md +1208 -0
- package/docs/git-workflow.md +160 -0
- package/docs/handover.md +10446 -0
- package/lib/api.d.ts +7 -0
- package/lib/api.js +7 -0
- package/lib/artifacts/code-fields.d.ts +49 -0
- package/lib/artifacts/code-fields.js +142 -0
- package/lib/artifacts/data-graph-document.d.ts +29 -0
- package/lib/artifacts/data-graph-document.js +52 -0
- package/lib/artifacts/data-space-field.d.ts +65 -0
- package/lib/artifacts/data-space-field.js +98 -0
- package/lib/artifacts/data-stream-document.d.ts +264 -0
- package/lib/artifacts/data-stream-document.js +680 -0
- package/lib/artifacts/data-transform-document.d.ts +152 -0
- package/lib/artifacts/data-transform-document.js +560 -0
- package/lib/artifacts/dependency-selection.d.ts +51 -0
- package/lib/artifacts/dependency-selection.js +154 -0
- package/lib/artifacts/dlo-document.d.ts +93 -0
- package/lib/artifacts/dlo-document.js +253 -0
- package/lib/artifacts/enum-case.d.ts +39 -0
- package/lib/artifacts/enum-case.js +67 -0
- package/lib/artifacts/git-deploy-selection.d.ts +68 -0
- package/lib/artifacts/git-deploy-selection.js +474 -0
- package/lib/artifacts/identity-resolution-document.d.ts +133 -0
- package/lib/artifacts/identity-resolution-document.js +625 -0
- package/lib/artifacts/mapping-document.d.ts +1 -0
- package/lib/artifacts/mapping-document.js +1 -0
- package/lib/artifacts/native-calculated-insight-document.d.ts +142 -0
- package/lib/artifacts/native-calculated-insight-document.js +321 -0
- package/lib/artifacts/native-data-graph-document.d.ts +124 -0
- package/lib/artifacts/native-data-graph-document.js +780 -0
- package/lib/artifacts/native-dmo-document.d.ts +151 -0
- package/lib/artifacts/native-dmo-document.js +313 -0
- package/lib/artifacts/native-mapping-document.d.ts +67 -0
- package/lib/artifacts/native-mapping-document.js +187 -0
- package/lib/artifacts/native-relationship-document.d.ts +76 -0
- package/lib/artifacts/native-relationship-document.js +232 -0
- package/lib/artifacts/path-selector.d.ts +55 -0
- package/lib/artifacts/path-selector.js +167 -0
- package/lib/artifacts/read-deploy-input.d.ts +239 -0
- package/lib/artifacts/read-deploy-input.js +1359 -0
- package/lib/artifacts/segment-document.d.ts +183 -0
- package/lib/artifacts/segment-document.js +570 -0
- package/lib/artifacts/verbatim-document.d.ts +203 -0
- package/lib/artifacts/verbatim-document.js +339 -0
- package/lib/artifacts/write-data-graph.d.ts +17 -0
- package/lib/artifacts/write-data-graph.js +162 -0
- package/lib/artifacts/write-data-stream.d.ts +11 -0
- package/lib/artifacts/write-data-stream.js +175 -0
- package/lib/artifacts/write-data-transform.d.ts +11 -0
- package/lib/artifacts/write-data-transform.js +180 -0
- package/lib/artifacts/write-dlo.d.ts +11 -0
- package/lib/artifacts/write-dlo.js +158 -0
- package/lib/artifacts/write-identity-resolution.d.ts +18 -0
- package/lib/artifacts/write-identity-resolution.js +165 -0
- package/lib/artifacts/write-mapping-definition.d.ts +17 -0
- package/lib/artifacts/write-mapping-definition.js +127 -0
- package/lib/artifacts/write-member-export.d.ts +88 -0
- package/lib/artifacts/write-member-export.js +199 -0
- package/lib/artifacts/write-native-calculated-insight.d.ts +21 -0
- package/lib/artifacts/write-native-calculated-insight.js +176 -0
- package/lib/artifacts/write-native-dmo.d.ts +11 -0
- package/lib/artifacts/write-native-dmo.js +158 -0
- package/lib/artifacts/write-native-mapping.d.ts +11 -0
- package/lib/artifacts/write-native-mapping.js +157 -0
- package/lib/artifacts/write-native-relationship.d.ts +11 -0
- package/lib/artifacts/write-native-relationship.js +157 -0
- package/lib/artifacts/write-segment.d.ts +26 -0
- package/lib/artifacts/write-segment.js +212 -0
- package/lib/commands/data360/delete.d.ts +280 -0
- package/lib/commands/data360/delete.js +2297 -0
- package/lib/commands/data360/deploy.d.ts +303 -0
- package/lib/commands/data360/deploy.js +2400 -0
- package/lib/commands/data360/publish.d.ts +93 -0
- package/lib/commands/data360/publish.js +292 -0
- package/lib/commands/data360/retrieve.d.ts +322 -0
- package/lib/commands/data360/retrieve.js +1963 -0
- package/lib/commands/data360/segment/members/export.d.ts +101 -0
- package/lib/commands/data360/segment/members/export.js +318 -0
- package/lib/errors/codes/calculated-insight.d.ts +2 -0
- package/lib/errors/codes/calculated-insight.js +25 -0
- package/lib/errors/codes/data-graph.d.ts +2 -0
- package/lib/errors/codes/data-graph.js +22 -0
- package/lib/errors/codes/data-stream.d.ts +2 -0
- package/lib/errors/codes/data-stream.js +70 -0
- package/lib/errors/codes/data-transform.d.ts +2 -0
- package/lib/errors/codes/data-transform.js +35 -0
- package/lib/errors/codes/dependency.d.ts +2 -0
- package/lib/errors/codes/dependency.js +11 -0
- package/lib/errors/codes/dlo.d.ts +2 -0
- package/lib/errors/codes/dlo.js +31 -0
- package/lib/errors/codes/dmo.d.ts +2 -0
- package/lib/errors/codes/dmo.js +28 -0
- package/lib/errors/codes/general.d.ts +2 -0
- package/lib/errors/codes/general.js +57 -0
- package/lib/errors/codes/identity-resolution.d.ts +2 -0
- package/lib/errors/codes/identity-resolution.js +24 -0
- package/lib/errors/codes/mapping.d.ts +2 -0
- package/lib/errors/codes/mapping.js +42 -0
- package/lib/errors/codes/relationship.d.ts +2 -0
- package/lib/errors/codes/relationship.js +21 -0
- package/lib/errors/codes/segment.d.ts +2 -0
- package/lib/errors/codes/segment.js +49 -0
- package/lib/errors/registry.d.ts +60 -0
- package/lib/errors/registry.js +123 -0
- package/lib/plugin.d.ts +5 -0
- package/lib/plugin.js +5 -0
- package/lib/services/acquire-retrieve-selection.d.ts +43 -0
- package/lib/services/acquire-retrieve-selection.js +145 -0
- package/lib/services/bind-identity-resolution-dependencies.d.ts +53 -0
- package/lib/services/bind-identity-resolution-dependencies.js +238 -0
- package/lib/services/bind-segment-dependencies.d.ts +49 -0
- package/lib/services/bind-segment-dependencies.js +115 -0
- package/lib/services/bounded-reads.d.ts +17 -0
- package/lib/services/bounded-reads.js +42 -0
- package/lib/services/calculated-insight-sql-checks.d.ts +33 -0
- package/lib/services/calculated-insight-sql-checks.js +193 -0
- package/lib/services/command-dlo.d.ts +48 -0
- package/lib/services/command-dlo.js +103 -0
- package/lib/services/command-native-data-graph.d.ts +54 -0
- package/lib/services/command-native-data-graph.js +485 -0
- package/lib/services/command-native-data-stream.d.ts +104 -0
- package/lib/services/command-native-data-stream.js +257 -0
- package/lib/services/command-native-dmo.d.ts +124 -0
- package/lib/services/command-native-dmo.js +338 -0
- package/lib/services/command-native-mapping.d.ts +65 -0
- package/lib/services/command-native-mapping.js +129 -0
- package/lib/services/command-native-relationship.d.ts +46 -0
- package/lib/services/command-native-relationship.js +103 -0
- package/lib/services/cross-dataspace-deploy.d.ts +111 -0
- package/lib/services/cross-dataspace-deploy.js +493 -0
- package/lib/services/cross-dataspace-rename.d.ts +74 -0
- package/lib/services/cross-dataspace-rename.js +1314 -0
- package/lib/services/cross-dataspace-sql.d.ts +109 -0
- package/lib/services/cross-dataspace-sql.js +1301 -0
- package/lib/services/cross-space-context.d.ts +23 -0
- package/lib/services/cross-space-context.js +36 -0
- package/lib/services/crud-plan.d.ts +137 -0
- package/lib/services/crud-plan.js +408 -0
- package/lib/services/data-space-check.d.ts +89 -0
- package/lib/services/data-space-check.js +162 -0
- package/lib/services/data-space-prefix.d.ts +77 -0
- package/lib/services/data-space-prefix.js +127 -0
- package/lib/services/data-transform-space.d.ts +31 -0
- package/lib/services/data-transform-space.js +79 -0
- package/lib/services/delete-calculated-insight.d.ts +44 -0
- package/lib/services/delete-calculated-insight.js +101 -0
- package/lib/services/delete-data-transform.d.ts +52 -0
- package/lib/services/delete-data-transform.js +222 -0
- package/lib/services/delete-dmo-field.d.ts +211 -0
- package/lib/services/delete-dmo-field.js +472 -0
- package/lib/services/delete-identity-resolution.d.ts +43 -0
- package/lib/services/delete-identity-resolution.js +295 -0
- package/lib/services/delete-segment.d.ts +42 -0
- package/lib/services/delete-segment.js +248 -0
- package/lib/services/deploy-result.d.ts +54 -0
- package/lib/services/deploy-result.js +60 -0
- package/lib/services/escaped-copy.d.ts +23 -0
- package/lib/services/escaped-copy.js +88 -0
- package/lib/services/execute-calculated-insight-deploy.d.ts +42 -0
- package/lib/services/execute-calculated-insight-deploy.js +96 -0
- package/lib/services/execute-data-transform-deploy.d.ts +56 -0
- package/lib/services/execute-data-transform-deploy.js +168 -0
- package/lib/services/execute-native-identity-resolution-deploy.d.ts +48 -0
- package/lib/services/execute-native-identity-resolution-deploy.js +360 -0
- package/lib/services/execute-segment-deploy.d.ts +45 -0
- package/lib/services/execute-segment-deploy.js +393 -0
- package/lib/services/local-file-removal.d.ts +36 -0
- package/lib/services/local-file-removal.js +103 -0
- package/lib/services/native-calculated-insight.d.ts +87 -0
- package/lib/services/native-calculated-insight.js +164 -0
- package/lib/services/native-crm-data-stream.d.ts +91 -0
- package/lib/services/native-crm-data-stream.js +272 -0
- package/lib/services/native-data-graph-context.d.ts +12 -0
- package/lib/services/native-data-graph-context.js +139 -0
- package/lib/services/native-data-graph-crd.d.ts +261 -0
- package/lib/services/native-data-graph-crd.js +866 -0
- package/lib/services/native-data-stream.d.ts +329 -0
- package/lib/services/native-data-stream.js +1830 -0
- package/lib/services/native-dlo.d.ts +163 -0
- package/lib/services/native-dlo.js +402 -0
- package/lib/services/native-dmo.d.ts +191 -0
- package/lib/services/native-dmo.js +614 -0
- package/lib/services/native-mapping.d.ts +255 -0
- package/lib/services/native-mapping.js +1226 -0
- package/lib/services/native-relationship.d.ts +132 -0
- package/lib/services/native-relationship.js +512 -0
- package/lib/services/operation-diagnostic.d.ts +83 -0
- package/lib/services/operation-diagnostic.js +272 -0
- package/lib/services/preflight-calculated-insight-deploy.d.ts +58 -0
- package/lib/services/preflight-calculated-insight-deploy.js +95 -0
- package/lib/services/preflight-data-transform-deploy.d.ts +33 -0
- package/lib/services/preflight-data-transform-deploy.js +104 -0
- package/lib/services/preflight-identity-resolution-deploy.d.ts +107 -0
- package/lib/services/preflight-identity-resolution-deploy.js +281 -0
- package/lib/services/preflight-segment-deploy.d.ts +31 -0
- package/lib/services/preflight-segment-deploy.js +109 -0
- package/lib/services/publish-calculated-insight.d.ts +40 -0
- package/lib/services/publish-calculated-insight.js +95 -0
- package/lib/services/publish-segment.d.ts +65 -0
- package/lib/services/publish-segment.js +194 -0
- package/lib/services/readback-pace.d.ts +16 -0
- package/lib/services/readback-pace.js +23 -0
- package/lib/services/retrieve-data-transform.d.ts +26 -0
- package/lib/services/retrieve-data-transform.js +65 -0
- package/lib/services/retrieve-identity-resolution.d.ts +40 -0
- package/lib/services/retrieve-identity-resolution.js +87 -0
- package/lib/services/retrieve-inventory.d.ts +32 -0
- package/lib/services/retrieve-inventory.js +151 -0
- package/lib/services/retrieve-segment.d.ts +120 -0
- package/lib/services/retrieve-segment.js +502 -0
- package/lib/services/segment-lookup.d.ts +46 -0
- package/lib/services/segment-lookup.js +108 -0
- package/lib/services/segment-members.d.ts +144 -0
- package/lib/services/segment-members.js +402 -0
- package/lib/services/select-native-retrieve.d.ts +60 -0
- package/lib/services/select-native-retrieve.js +226 -0
- package/lib/services/settle-calculated-insight.d.ts +22 -0
- package/lib/services/settle-calculated-insight.js +53 -0
- package/lib/services/sql-tokens.d.ts +58 -0
- package/lib/services/sql-tokens.js +147 -0
- package/lib/transport/api-version.d.ts +36 -0
- package/lib/transport/api-version.js +89 -0
- package/lib/transport/bound-ssot.d.ts +27 -0
- package/lib/transport/bound-ssot.js +116 -0
- package/lib/transport/calculated-insight-rest.d.ts +28 -0
- package/lib/transport/calculated-insight-rest.js +62 -0
- package/lib/transport/connect-client.d.ts +129 -0
- package/lib/transport/connect-client.js +446 -0
- package/lib/transport/connect-diagnostic.d.ts +89 -0
- package/lib/transport/connect-diagnostic.js +331 -0
- package/lib/transport/data-graph-rest.d.ts +27 -0
- package/lib/transport/data-graph-rest.js +76 -0
- package/lib/transport/data-stream-rest.d.ts +62 -0
- package/lib/transport/data-stream-rest.js +348 -0
- package/lib/transport/data-transform-rest.d.ts +25 -0
- package/lib/transport/data-transform-rest.js +100 -0
- package/lib/transport/dlo-native-rest.d.ts +22 -0
- package/lib/transport/dlo-native-rest.js +89 -0
- package/lib/transport/dlo-rest.d.ts +23 -0
- package/lib/transport/dlo-rest.js +135 -0
- package/lib/transport/dmo-native-rest.d.ts +18 -0
- package/lib/transport/dmo-native-rest.js +55 -0
- package/lib/transport/dmo-rest.d.ts +30 -0
- package/lib/transport/dmo-rest.js +163 -0
- package/lib/transport/mapping-rest.d.ts +63 -0
- package/lib/transport/mapping-rest.js +341 -0
- package/lib/transport/project-metadata.d.ts +36 -0
- package/lib/transport/project-metadata.js +118 -0
- package/lib/transport/relationship-rest.d.ts +43 -0
- package/lib/transport/relationship-rest.js +201 -0
- package/package.json +96 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Connection } from '@salesforce/core';
|
|
3
|
+
import { plugin } from '../../plugin.js';
|
|
4
|
+
import { readDeployInputs, verifyCalculatedInsightInputDigest, verifySegmentInputDigest } from '../../artifacts/read-deploy-input.js';
|
|
5
|
+
import { publishSegment } from '../../services/publish-segment.js';
|
|
6
|
+
import type { SegmentPublishResult } from '../../services/publish-segment.js';
|
|
7
|
+
import { publishCalculatedInsight } from '../../services/publish-calculated-insight.js';
|
|
8
|
+
import type { CalculatedInsightPublishResult } from '../../services/publish-calculated-insight.js';
|
|
9
|
+
import { calculatedInsightReadContext } from '../../services/native-calculated-insight.js';
|
|
10
|
+
export type PublishEnvelope = {
|
|
11
|
+
contract: 'sf-data360-publish';
|
|
12
|
+
contractVersion: '1.0.0';
|
|
13
|
+
status: 'success' | 'processing' | 'blocked' | 'failed';
|
|
14
|
+
metadata: {
|
|
15
|
+
operation: 'publish';
|
|
16
|
+
preview: boolean;
|
|
17
|
+
apiVersion: string;
|
|
18
|
+
plugin: typeof plugin;
|
|
19
|
+
};
|
|
20
|
+
provenance: {
|
|
21
|
+
command: 'sf data360 publish';
|
|
22
|
+
generatedAt: string;
|
|
23
|
+
};
|
|
24
|
+
diagnostics: {
|
|
25
|
+
warnings: string[];
|
|
26
|
+
errors: Array<{
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
retryable: false;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
result: {
|
|
33
|
+
items: Array<(CalculatedInsightPublishResult | SegmentPublishResult) & {
|
|
34
|
+
identity: {
|
|
35
|
+
apiName: string;
|
|
36
|
+
dataSpace: string;
|
|
37
|
+
};
|
|
38
|
+
operation: 'preview' | 'publish';
|
|
39
|
+
routes: Array<{
|
|
40
|
+
operation: string;
|
|
41
|
+
apiVersion: string;
|
|
42
|
+
transport: 'native' | 'metadata';
|
|
43
|
+
}>;
|
|
44
|
+
}>;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Publish one native Calculated Insight draft (JSON plus SQL file) without deploying or
|
|
49
|
+
* scheduling it, or publish one segment and wait for the result (--async: return once started).
|
|
50
|
+
*/
|
|
51
|
+
export default class Publish extends SfCommand<PublishEnvelope> {
|
|
52
|
+
static readonly aliases: string[];
|
|
53
|
+
static readonly summary = "Publish one Data360 Calculated Insight draft or one segment.";
|
|
54
|
+
static readonly description = "Segment: -m segment:Name (the segment as the org holds it) or -d data360/segments/Name.segment.json (or one of its .segment.<model>.sql files; the org must hold the definition of the file, otherwise SEGMENT_PUBLISH_DEFINITION_MISMATCH: deploy it first). A file retrieved as-is (verbatim) is refused with VERBATIM_NOT_DEPLOYABLE. --api-version auto (68.0) or 68.0, in the run data space (--dataspace; a segment or file of another data space is SEGMENT_DATASPACE_MISMATCH). The segment is read by name (absent is SEGMENT_PUBLISH_ADMISSION_FAILED), then one API 68 POST /ssot/segments/{marketSegmentId}/actions/publish without a body starts the publish; it runs on command, needs no acknowledgement flag and is never resent. Salesforce decides whether the segment can be published now, also while it is PROCESSING or COUNTING; a 4xx answer is reported with its text (SEGMENT_PUBLISH_REJECTED). The segment is then read every 30 seconds (progress on stderr) until publishStatus is SUCCESS (published) or FAILED (SEGMENT_PUBLISH_FAILED) for this publish. --wait-timeout sets that wait in whole seconds (default 1800; a publish took about 15 minutes in a test); when it runs out the result is publishing (status processing, exit 0, SEGMENT_PUBLISH_STILL_PROCESSING): still processing, not failed, and not resent. --async returns right after Salesforce accepted the POST, without any read afterwards: outcome publishing, mutation acknowledged-processing, status processing, exit 0, SEGMENT_PUBLISH_STARTED (started, not finished); --async and --wait-timeout cannot be combined. Members are readable only after SUCCESS. --preview reads the segment and reports what would be published without publishing. Calculated insight: requires one exact --source-dir data360/calculatedInsights/Name__cio.calculatedInsight-meta.json or its .calculatedInsight-meta.sql file (the JSON is joined with its SQL; a missing SQL file or another Name__cio.calculatedInsight-meta.* file beside them is refused with INVALID_SOURCE), --api-version auto (68.0) or 68.0 and the run data space (--dataspace, default: default; --data-space is a compatibility alias), which c__dataSpace in the file must name (CI_DATASPACE_MISMATCH otherwise). The insight must exist (create it with sf data360 deploy, --draft for a draft). An ACTIVE insight that holds every key of the file is unchanged; otherwise one API 68 PATCH sends the file (translated like deploy) with draft: false, and the insight is read until it is ACTIVE with the file; with --async it is not read after Salesforce accepted the PATCH (outcome publishing, mutation acknowledged-processing, status processing, exit 0, CI_PUBLISH_STARTED). Salesforce decides; a 4xx answer is reported as rejected. --preview is read-only. An unknown outcome is not retried or rolled back.";
|
|
55
|
+
static readonly flags: {
|
|
56
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
57
|
+
'source-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
58
|
+
metadata: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
59
|
+
async: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
60
|
+
'wait-timeout': import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
61
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
62
|
+
dataspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
63
|
+
preview: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
64
|
+
};
|
|
65
|
+
protected resolveInputs: typeof readDeployInputs;
|
|
66
|
+
protected verifyCalculatedInsightInput: typeof verifyCalculatedInsightInputDigest;
|
|
67
|
+
protected calculatedInsightContext: typeof calculatedInsightReadContext;
|
|
68
|
+
protected publishCalculatedInsight: typeof publishCalculatedInsight;
|
|
69
|
+
protected verifySegmentInput: typeof verifySegmentInputDigest;
|
|
70
|
+
protected publishSegment: typeof publishSegment;
|
|
71
|
+
protected segmentProgress: (message: string) => void;
|
|
72
|
+
protected resolveConnection: (alias?: string) => Promise<Connection>;
|
|
73
|
+
/**
|
|
74
|
+
* Validate exact intent before auth and delegate one guarded publication.
|
|
75
|
+
* @returns {Promise<PublishEnvelope>} Payload-free publication receipt.
|
|
76
|
+
*/
|
|
77
|
+
run(): Promise<PublishEnvelope>;
|
|
78
|
+
/**
|
|
79
|
+
* Publish one segment, named by -m segment:Name or by its file, and wait for the result.
|
|
80
|
+
* @param {PublishEnvelope} envelope Receipt to fill.
|
|
81
|
+
* @param {PublishFlags} flags Parsed flags.
|
|
82
|
+
* @param {string} snapshot Flags as parsed, to detect drift.
|
|
83
|
+
* @param {string} [member] The -m segment:Name selector, when given.
|
|
84
|
+
*/
|
|
85
|
+
private runSegment;
|
|
86
|
+
/**
|
|
87
|
+
* Set the exit code and print the human summary.
|
|
88
|
+
* @param {PublishEnvelope} envelope Filled receipt.
|
|
89
|
+
* @param {boolean} preview Whether this was a preview.
|
|
90
|
+
* @returns {PublishEnvelope} The same receipt.
|
|
91
|
+
*/
|
|
92
|
+
private finish;
|
|
93
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { AuthInfo, ConfigAggregator, Connection, StateAggregator } from '@salesforce/core';
|
|
3
|
+
import { plugin } from '../../plugin.js';
|
|
4
|
+
import { DeployInputError, readDeployInputs, verifyCalculatedInsightInputDigest, verifySegmentInputDigest, } from '../../artifacts/read-deploy-input.js';
|
|
5
|
+
import { SegmentError, segmentName } from '../../artifacts/segment-document.js';
|
|
6
|
+
import { explainSpaceMismatch, operationDiagnostic } from '../../services/operation-diagnostic.js';
|
|
7
|
+
import { publishSegment, segmentPublishWait } from '../../services/publish-segment.js';
|
|
8
|
+
import { publishCalculatedInsight } from '../../services/publish-calculated-insight.js';
|
|
9
|
+
import { calculatedInsightReadContext } from '../../services/native-calculated-insight.js';
|
|
10
|
+
import { annotateDiagnostics, formatDiagnostic } from '../../errors/registry.js';
|
|
11
|
+
/**
|
|
12
|
+
* Publish one native Calculated Insight draft (JSON plus SQL file) without deploying or
|
|
13
|
+
* scheduling it, or publish one segment and wait for the result (--async: return once started).
|
|
14
|
+
*/
|
|
15
|
+
export default class Publish extends SfCommand {
|
|
16
|
+
static aliases = ['datacloud:publish', 'd360:publish', 'dc:publish'];
|
|
17
|
+
static summary = 'Publish one Data360 Calculated Insight draft or one segment.';
|
|
18
|
+
static description = 'Segment: -m segment:Name (the segment as the org holds it) or -d data360/segments/Name.segment.json (or one of its .segment.<model>.sql files; the org must hold the definition of the file, otherwise SEGMENT_PUBLISH_DEFINITION_MISMATCH: deploy it first). A file retrieved as-is (verbatim) is refused with VERBATIM_NOT_DEPLOYABLE. --api-version auto (68.0) or 68.0, in the run data space (--dataspace; a segment or file of another data space is SEGMENT_DATASPACE_MISMATCH). The segment is read by name (absent is SEGMENT_PUBLISH_ADMISSION_FAILED), then one API 68 POST /ssot/segments/{marketSegmentId}/actions/publish without a body starts the publish; it runs on command, needs no acknowledgement flag and is never resent. Salesforce decides whether the segment can be published now, also while it is PROCESSING or COUNTING; a 4xx answer is reported with its text (SEGMENT_PUBLISH_REJECTED). The segment is then read every 30 seconds (progress on stderr) until publishStatus is SUCCESS (published) or FAILED (SEGMENT_PUBLISH_FAILED) for this publish. --wait-timeout sets that wait in whole seconds (default 1800; a publish took about 15 minutes in a test); when it runs out the result is publishing (status processing, exit 0, SEGMENT_PUBLISH_STILL_PROCESSING): still processing, not failed, and not resent. --async returns right after Salesforce accepted the POST, without any read afterwards: outcome publishing, mutation acknowledged-processing, status processing, exit 0, SEGMENT_PUBLISH_STARTED (started, not finished); --async and --wait-timeout cannot be combined. Members are readable only after SUCCESS. --preview reads the segment and reports what would be published without publishing. Calculated insight: requires one exact --source-dir data360/calculatedInsights/Name__cio.calculatedInsight-meta.json or its .calculatedInsight-meta.sql file (the JSON is joined with its SQL; a missing SQL file or another Name__cio.calculatedInsight-meta.* file beside them is refused with INVALID_SOURCE), --api-version auto (68.0) or 68.0 and the run data space (--dataspace, default: default; --data-space is a compatibility alias), which c__dataSpace in the file must name (CI_DATASPACE_MISMATCH otherwise). The insight must exist (create it with sf data360 deploy, --draft for a draft). An ACTIVE insight that holds every key of the file is unchanged; otherwise one API 68 PATCH sends the file (translated like deploy) with draft: false, and the insight is read until it is ACTIVE with the file; with --async it is not read after Salesforce accepted the PATCH (outcome publishing, mutation acknowledged-processing, status processing, exit 0, CI_PUBLISH_STARTED). Salesforce decides; a 4xx answer is reported as rejected. --preview is read-only. An unknown outcome is not retried or rolled back.';
|
|
19
|
+
static flags = {
|
|
20
|
+
'target-org': Flags.string({
|
|
21
|
+
char: 'o',
|
|
22
|
+
summary: 'Authenticated target org alias or username.',
|
|
23
|
+
}),
|
|
24
|
+
'source-dir': Flags.string({
|
|
25
|
+
char: 'd',
|
|
26
|
+
summary: 'One exact CI JSON file or its SQL file, or one segment JSON or SQL file.',
|
|
27
|
+
}),
|
|
28
|
+
metadata: Flags.string({
|
|
29
|
+
char: 'm',
|
|
30
|
+
summary: 'One segment to publish as the org holds it: segment:Name.',
|
|
31
|
+
exclusive: ['source-dir'],
|
|
32
|
+
}),
|
|
33
|
+
async: Flags.boolean({
|
|
34
|
+
default: false,
|
|
35
|
+
exclusive: ['wait-timeout'],
|
|
36
|
+
summary: 'Start the publish and return at once (status processing, exit 0) without waiting for the result; not with --wait-timeout.',
|
|
37
|
+
}),
|
|
38
|
+
'wait-timeout': Flags.integer({
|
|
39
|
+
exclusive: ['async'],
|
|
40
|
+
summary: `Segment only: seconds to wait for SUCCESS or FAILED (default ${segmentPublishWait.timeoutSeconds}).`,
|
|
41
|
+
}),
|
|
42
|
+
'api-version': Flags.string({ summary: 'Native lifecycle route: auto (68.0) or 68.0.' }),
|
|
43
|
+
dataspace: Flags.string({
|
|
44
|
+
aliases: ['data-space'],
|
|
45
|
+
summary: "The run's data space (default: default); a segment or calculated insight file must name it in c__dataSpace.",
|
|
46
|
+
}),
|
|
47
|
+
preview: Flags.boolean({ default: false, summary: 'Read and report only; never publish.' }),
|
|
48
|
+
};
|
|
49
|
+
resolveInputs = readDeployInputs;
|
|
50
|
+
verifyCalculatedInsightInput = verifyCalculatedInsightInputDigest;
|
|
51
|
+
calculatedInsightContext = calculatedInsightReadContext;
|
|
52
|
+
publishCalculatedInsight = publishCalculatedInsight;
|
|
53
|
+
verifySegmentInput = verifySegmentInputDigest;
|
|
54
|
+
publishSegment = publishSegment;
|
|
55
|
+
segmentProgress = (message) => {
|
|
56
|
+
// oclif logToStderr suppresses output in JSON mode; progress must remain visible.
|
|
57
|
+
process.stderr.write(`${message}
|
|
58
|
+
`);
|
|
59
|
+
};
|
|
60
|
+
resolveConnection = async (alias) => {
|
|
61
|
+
const aggregator = await ConfigAggregator.create();
|
|
62
|
+
const state = await StateAggregator.getInstance();
|
|
63
|
+
const target = alias ?? aggregator.getPropertyValue('target-org');
|
|
64
|
+
return Connection.create({
|
|
65
|
+
authInfo: await AuthInfo.create({
|
|
66
|
+
username: target ? state.aliases.resolveUsername(target) : undefined,
|
|
67
|
+
}),
|
|
68
|
+
connectionOptions: { version: '68.0' },
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Validate exact intent before auth and delegate one guarded publication.
|
|
73
|
+
* @returns {Promise<PublishEnvelope>} Payload-free publication receipt.
|
|
74
|
+
*/
|
|
75
|
+
async run() {
|
|
76
|
+
const { flags } = await this.parse(Publish);
|
|
77
|
+
const envelope = {
|
|
78
|
+
contract: 'sf-data360-publish',
|
|
79
|
+
contractVersion: '1.0.0',
|
|
80
|
+
status: 'blocked',
|
|
81
|
+
metadata: {
|
|
82
|
+
operation: 'publish',
|
|
83
|
+
preview: flags.preview,
|
|
84
|
+
apiVersion: flags['api-version'] ?? 'auto',
|
|
85
|
+
plugin,
|
|
86
|
+
},
|
|
87
|
+
provenance: { command: 'sf data360 publish', generatedAt: new Date().toISOString() },
|
|
88
|
+
diagnostics: { warnings: [], errors: [] },
|
|
89
|
+
result: { items: [] },
|
|
90
|
+
};
|
|
91
|
+
let code = 'INVALID_SELECTION';
|
|
92
|
+
try {
|
|
93
|
+
const source = flags['source-dir'];
|
|
94
|
+
const member = flags.metadata;
|
|
95
|
+
const segmentFile = typeof source === 'string' && /\.segment\.(?:json|[A-Za-z0-9_]+\.sql)$/u.test(source);
|
|
96
|
+
const segmentMember = typeof member === 'string' &&
|
|
97
|
+
member.startsWith('segment:') &&
|
|
98
|
+
segmentName.test(member.slice(8));
|
|
99
|
+
if (member !== undefined && (!segmentMember || source !== undefined))
|
|
100
|
+
throw new Error('Selection');
|
|
101
|
+
if (member === undefined &&
|
|
102
|
+
(typeof source !== 'string' ||
|
|
103
|
+
!source ||
|
|
104
|
+
(!segmentFile && !/\.calculatedInsight-meta\.(?:json|sql)$/u.test(source))))
|
|
105
|
+
throw new Error('Selection');
|
|
106
|
+
const segment = segmentMember || segmentFile;
|
|
107
|
+
code = 'INVALID_WAIT_TIMEOUT_SCOPE';
|
|
108
|
+
const waitTimeout = flags['wait-timeout'];
|
|
109
|
+
if (waitTimeout !== undefined &&
|
|
110
|
+
(!segment || !Number.isSafeInteger(waitTimeout) || waitTimeout < 1))
|
|
111
|
+
throw new Error('Wait timeout');
|
|
112
|
+
code = 'INVALID_SCOPE';
|
|
113
|
+
const dataSpace = flags.dataspace ?? 'default';
|
|
114
|
+
// A calculated insight or segment is published in the run's data space.
|
|
115
|
+
if (!['auto', '68.0'].includes(flags['api-version'] ?? 'auto'))
|
|
116
|
+
throw new Error('Scope');
|
|
117
|
+
const snapshot = JSON.stringify(flags);
|
|
118
|
+
if (segment) {
|
|
119
|
+
await this.runSegment(envelope, flags, snapshot, segmentMember ? member : undefined);
|
|
120
|
+
return this.finish(envelope, flags.preview);
|
|
121
|
+
}
|
|
122
|
+
code = 'INVALID_SOURCE';
|
|
123
|
+
const inputs = await this.resolveInputs({
|
|
124
|
+
cwd: process.cwd(),
|
|
125
|
+
sourceDir: [source],
|
|
126
|
+
});
|
|
127
|
+
if (inputs.length !== 1 || inputs[0].document.kind !== 'calculated-insight')
|
|
128
|
+
throw new Error('Selection');
|
|
129
|
+
const input = inputs[0];
|
|
130
|
+
const desired = input.native;
|
|
131
|
+
const verifyInput = async () => {
|
|
132
|
+
if (JSON.stringify(flags) !== snapshot)
|
|
133
|
+
throw new Error('Intent drift');
|
|
134
|
+
await this.verifyCalculatedInsightInput(input);
|
|
135
|
+
};
|
|
136
|
+
await verifyInput();
|
|
137
|
+
code = 'TARGET_ORG_REQUIRED';
|
|
138
|
+
const connection = await this.resolveConnection(flags['target-org']);
|
|
139
|
+
code = 'CI_ADMISSION_FAILED';
|
|
140
|
+
const context = this.calculatedInsightContext(connection, dataSpace);
|
|
141
|
+
await verifyInput();
|
|
142
|
+
const result = await this.publishCalculatedInsight(desired, connection, {
|
|
143
|
+
requested: '68.0',
|
|
144
|
+
restSelector: 'v68.0',
|
|
145
|
+
soapNumeric: '68.0',
|
|
146
|
+
}, dataSpace, {
|
|
147
|
+
context,
|
|
148
|
+
preview: flags.preview,
|
|
149
|
+
...(flags.async ? { async: true } : {}),
|
|
150
|
+
verifyInput,
|
|
151
|
+
});
|
|
152
|
+
envelope.result.items.push({
|
|
153
|
+
...result,
|
|
154
|
+
identity: { apiName: desired.apiName, dataSpace: desired.dataSpace },
|
|
155
|
+
operation: flags.preview ? 'preview' : 'publish',
|
|
156
|
+
routes: [
|
|
157
|
+
{ operation: 'calculated-insight.publish', apiVersion: '68.0', transport: 'native' },
|
|
158
|
+
{ operation: 'calculated-insight.get', apiVersion: '68.0', transport: 'native' },
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
envelope.status =
|
|
162
|
+
result.outcome === 'failed'
|
|
163
|
+
? 'failed'
|
|
164
|
+
: result.outcome === 'blocked'
|
|
165
|
+
? 'blocked'
|
|
166
|
+
: result.outcome === 'publishing'
|
|
167
|
+
? 'processing'
|
|
168
|
+
: 'success';
|
|
169
|
+
// A publish started with --async is reported on the item, not as an error.
|
|
170
|
+
if (result.outcome !== 'publishing')
|
|
171
|
+
envelope.diagnostics.errors.push(...result.diagnostics.map((diagnostic) => ({ ...diagnostic, retryable: false })));
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
envelope.diagnostics.errors.push({
|
|
175
|
+
code: error instanceof DeployInputError ? error.code : code,
|
|
176
|
+
// A verbatim file (retrieved as-is) is named with its kind, name and reason.
|
|
177
|
+
message: error instanceof DeployInputError && error.code === 'VERBATIM_NOT_DEPLOYABLE'
|
|
178
|
+
? error.message
|
|
179
|
+
: 'Publication stopped. Verify the exact JSON and SQL source, API 68, the data space (--dataspace) and target access. Inspect unknown outcomes before another attempt; no automatic retry or rollback.',
|
|
180
|
+
retryable: false,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return this.finish(envelope, flags.preview);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Publish one segment, named by -m segment:Name or by its file, and wait for the result.
|
|
187
|
+
* @param {PublishEnvelope} envelope Receipt to fill.
|
|
188
|
+
* @param {PublishFlags} flags Parsed flags.
|
|
189
|
+
* @param {string} snapshot Flags as parsed, to detect drift.
|
|
190
|
+
* @param {string} [member] The -m segment:Name selector, when given.
|
|
191
|
+
*/
|
|
192
|
+
async runSegment(envelope, flags, snapshot, member) {
|
|
193
|
+
let code = 'INVALID_SOURCE';
|
|
194
|
+
const dataSpace = flags.dataspace ?? 'default';
|
|
195
|
+
try {
|
|
196
|
+
let apiName;
|
|
197
|
+
let desired;
|
|
198
|
+
let input;
|
|
199
|
+
if (member)
|
|
200
|
+
apiName = member.slice(8);
|
|
201
|
+
else {
|
|
202
|
+
const inputs = await this.resolveInputs({
|
|
203
|
+
cwd: process.cwd(),
|
|
204
|
+
sourceDir: [flags['source-dir']],
|
|
205
|
+
});
|
|
206
|
+
if (inputs.length !== 1 || inputs[0].document.kind !== 'segment')
|
|
207
|
+
throw new Error('Selection');
|
|
208
|
+
input = inputs[0];
|
|
209
|
+
desired = input.document;
|
|
210
|
+
apiName = desired.identity.apiName;
|
|
211
|
+
if (desired.c__dataSpace !== dataSpace) {
|
|
212
|
+
code = 'SEGMENT_DATASPACE_MISMATCH';
|
|
213
|
+
throw explainSpaceMismatch(new SegmentError(code), apiName, desired.c__dataSpace, dataSpace);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const verifyInput = async () => {
|
|
217
|
+
if (JSON.stringify(flags) !== snapshot)
|
|
218
|
+
throw new Error('Intent drift');
|
|
219
|
+
if (input)
|
|
220
|
+
await this.verifySegmentInput(input);
|
|
221
|
+
};
|
|
222
|
+
await verifyInput();
|
|
223
|
+
code = 'TARGET_ORG_REQUIRED';
|
|
224
|
+
const connection = await this.resolveConnection(flags['target-org']);
|
|
225
|
+
const result = await this.publishSegment(apiName, connection, { requested: '68.0', restSelector: 'v68.0', soapNumeric: '68.0' }, {
|
|
226
|
+
preview: flags.preview,
|
|
227
|
+
...(flags.async ? { async: true } : {}),
|
|
228
|
+
waitTimeoutSeconds: flags['wait-timeout'] ?? segmentPublishWait.timeoutSeconds,
|
|
229
|
+
desired,
|
|
230
|
+
dataSpace,
|
|
231
|
+
verifyInput,
|
|
232
|
+
progress: this.segmentProgress,
|
|
233
|
+
});
|
|
234
|
+
envelope.result.items.push({
|
|
235
|
+
...result,
|
|
236
|
+
identity: { apiName, dataSpace },
|
|
237
|
+
operation: flags.preview ? 'preview' : 'publish',
|
|
238
|
+
routes: [
|
|
239
|
+
{ operation: 'segments.get', apiVersion: '68.0', transport: 'native' },
|
|
240
|
+
{ operation: 'segments.publish', apiVersion: '68.0', transport: 'native' },
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
envelope.status =
|
|
244
|
+
result.outcome === 'failed'
|
|
245
|
+
? 'failed'
|
|
246
|
+
: result.outcome === 'blocked'
|
|
247
|
+
? 'blocked'
|
|
248
|
+
: result.outcome === 'publishing'
|
|
249
|
+
? 'processing'
|
|
250
|
+
: 'success';
|
|
251
|
+
// Still processing is reported on the item, not as an error.
|
|
252
|
+
if (result.outcome !== 'publishing')
|
|
253
|
+
envelope.diagnostics.errors.push(...result.diagnostics.map((diagnostic) => ({ ...diagnostic, retryable: false })));
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
envelope.diagnostics.errors.push({
|
|
257
|
+
code: error instanceof DeployInputError ? error.code : code,
|
|
258
|
+
message: error instanceof DeployInputError && error.code === 'VERBATIM_NOT_DEPLOYABLE'
|
|
259
|
+
? error.message
|
|
260
|
+
: code === 'SEGMENT_DATASPACE_MISMATCH'
|
|
261
|
+
? operationDiagnostic(error, 'Nothing was published.')
|
|
262
|
+
: 'Publication stopped. Verify the segment selection (-m segment:Name or its .segment.json file), API 68 and data space (--dataspace), and target access. Nothing was published.',
|
|
263
|
+
retryable: false,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Set the exit code and print the human summary.
|
|
269
|
+
* @param {PublishEnvelope} envelope Filled receipt.
|
|
270
|
+
* @param {boolean} preview Whether this was a preview.
|
|
271
|
+
* @returns {PublishEnvelope} The same receipt.
|
|
272
|
+
*/
|
|
273
|
+
finish(envelope, preview) {
|
|
274
|
+
if (envelope.status !== 'success' && envelope.status !== 'processing')
|
|
275
|
+
process.exitCode = 1;
|
|
276
|
+
annotateDiagnostics(envelope);
|
|
277
|
+
if (!this.jsonEnabled()) {
|
|
278
|
+
this.log(`Publish${preview ? ' preview' : ''}: ${envelope.status}.`);
|
|
279
|
+
for (const item of envelope.result.items) {
|
|
280
|
+
this.log(`${item.outcome}: ${item.identity.apiName}; mutation: ${item.mutation}.`);
|
|
281
|
+
if (item.family === 'segment' && item.segment?.publishStatus)
|
|
282
|
+
this.log(`publishStatus: ${item.segment.publishStatus}${item.waitedSeconds === undefined ? '' : ` after ${item.waitedSeconds} s`}.`);
|
|
283
|
+
if (item.outcome === 'publishing')
|
|
284
|
+
for (const diagnostic of item.diagnostics)
|
|
285
|
+
this.log(formatDiagnostic(diagnostic));
|
|
286
|
+
}
|
|
287
|
+
for (const diagnostic of envelope.diagnostics.errors)
|
|
288
|
+
this.log(formatDiagnostic(diagnostic));
|
|
289
|
+
}
|
|
290
|
+
return envelope;
|
|
291
|
+
}
|
|
292
|
+
}
|