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,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add an explanation only after the existing safety predicate rejects; never changes its outcome.
|
|
3
|
+
* @template {Error} T
|
|
4
|
+
* @param {T} error Existing typed error and compatibility code.
|
|
5
|
+
* @param {string} check Static operation/check description.
|
|
6
|
+
* @param {unknown} resource Resource API name where independently known.
|
|
7
|
+
* @param {unknown} expected Expected protected state (not retained).
|
|
8
|
+
* @param {unknown} observed Observed protected state (not retained).
|
|
9
|
+
* @param {string} [path] Logical comparison root.
|
|
10
|
+
* @param {string} [hint] Static sentence naming the way forward.
|
|
11
|
+
* @returns {T} The original error with a bounded, safe human explanation.
|
|
12
|
+
*/
|
|
13
|
+
export declare function explainMismatch<T extends Error>(error: T, check: string, resource: unknown, expected: unknown, observed: unknown, path?: string, hint?: string): T;
|
|
14
|
+
/**
|
|
15
|
+
* Replace the explanation of an already refused operation with complete plugin-built
|
|
16
|
+
* instructions. A text ending in a line break keeps the next action on its own line.
|
|
17
|
+
* @param {Error} error Existing typed refusal; its code and outcome are untouched.
|
|
18
|
+
* @param {string} message Bounded text built only from validated identifiers.
|
|
19
|
+
*/
|
|
20
|
+
export declare function replaceExplanation(error: Error, message: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* The plugin-built explanation of a refusal, if one was attached.
|
|
23
|
+
* @param {unknown} error Caught error.
|
|
24
|
+
* @returns {string | undefined} Explanation text.
|
|
25
|
+
*/
|
|
26
|
+
export declare function explanationOf(error: unknown): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* A key of an authored file as it may appear in a message: a plain identifier, otherwise a
|
|
29
|
+
* placeholder, so free text in a key is never echoed.
|
|
30
|
+
* @param {string} key Object key.
|
|
31
|
+
* @returns {string} Printable key.
|
|
32
|
+
*/
|
|
33
|
+
export declare function printableKey(key: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Attach an explanation that names the offending key path of an authored file.
|
|
36
|
+
* @template {Error} T
|
|
37
|
+
* @param {T} error Typed refusal; its code is untouched.
|
|
38
|
+
* @param {string} detail Sentence built only from printable keys and static text.
|
|
39
|
+
* @returns {T} The same error.
|
|
40
|
+
*/
|
|
41
|
+
export declare function explainInput<T extends Error>(error: T, detail: string): T;
|
|
42
|
+
/**
|
|
43
|
+
* Give a refusal a cause-specific hint in place of the registered hint of its code, for a code
|
|
44
|
+
* with several causes.
|
|
45
|
+
* @template {Error} T
|
|
46
|
+
* @param {T} error Typed refusal.
|
|
47
|
+
* @param {string} hint Static sentence naming the way forward for this cause.
|
|
48
|
+
* @returns {T} The same error.
|
|
49
|
+
*/
|
|
50
|
+
export declare function withHint<T extends Error>(error: T, hint: string): T;
|
|
51
|
+
/**
|
|
52
|
+
* The cause-specific hint of a refusal, as a diagnostic property, or none.
|
|
53
|
+
* @param {unknown} error Caught error.
|
|
54
|
+
* @returns {{hint?: string}} `{ hint }` or an empty object.
|
|
55
|
+
*/
|
|
56
|
+
export declare function hintOf(error: unknown): {
|
|
57
|
+
hint?: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Explain a refusal of a file whose data space is not the run's, naming both.
|
|
61
|
+
* @template {Error} T
|
|
62
|
+
* @param {T} error Typed refusal (a *_DATASPACE_MISMATCH or UNSUPPORTED_RELATIONSHIP_DATASPACE).
|
|
63
|
+
* @param {string} apiName The file's validated component name.
|
|
64
|
+
* @param {string} fileSpace The data space the file names in c__dataSpace.
|
|
65
|
+
* @param {string} runSpace The run's data space.
|
|
66
|
+
* @param {boolean} [crossSpace] A deploy of a kind --allow-cross-dataspace can translate: say so.
|
|
67
|
+
* @returns {T} The same error with the explanation.
|
|
68
|
+
*/
|
|
69
|
+
export declare function explainSpaceMismatch<T extends Error>(error: T, apiName: string, fileSpace: string, runSpace: string, crossSpace?: boolean): T;
|
|
70
|
+
/**
|
|
71
|
+
* The sentence a deploy refusal adds for a file --allow-cross-dataspace can translate.
|
|
72
|
+
* @param {string} runSpace The run's data space.
|
|
73
|
+
* @returns {string} The sentence, with a leading space.
|
|
74
|
+
*/
|
|
75
|
+
export declare function crossSpaceSentence(runSpace: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Reuse existing diagnostic messages while distinguishing local verification from API rejection.
|
|
78
|
+
* Arbitrary exception messages, bodies and stack traces are never forwarded.
|
|
79
|
+
* @param {unknown} error Caught error.
|
|
80
|
+
* @param {string} nextAction Existing outcome-specific safe next action.
|
|
81
|
+
* @returns {string} Bounded diagnostic suitable for console and JSON.
|
|
82
|
+
*/
|
|
83
|
+
export declare function operationDiagnostic(error: unknown, nextAction: string): string;
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { diagnosticDataProperty, getConnectDiagnostic, getMetadataProblems, } from '../transport/connect-diagnostic.js';
|
|
3
|
+
import { registerCauseHint } from '../errors/registry.js';
|
|
4
|
+
const details = new WeakMap();
|
|
5
|
+
const hints = new WeakMap();
|
|
6
|
+
const visibleKeys = new Set([
|
|
7
|
+
'name',
|
|
8
|
+
'apiName',
|
|
9
|
+
'dataSpace',
|
|
10
|
+
'dataSpaceName',
|
|
11
|
+
'connectionName',
|
|
12
|
+
'event',
|
|
13
|
+
'availabilityStatus',
|
|
14
|
+
'availability',
|
|
15
|
+
'status',
|
|
16
|
+
'dataType',
|
|
17
|
+
'datatype',
|
|
18
|
+
'category',
|
|
19
|
+
'isPrimaryKey',
|
|
20
|
+
'isMapped',
|
|
21
|
+
'isDynamicLookup',
|
|
22
|
+
'creationType',
|
|
23
|
+
'usageTag',
|
|
24
|
+
'refreshMode',
|
|
25
|
+
'connectorType',
|
|
26
|
+
'dataStreamType',
|
|
27
|
+
'sourceFieldName',
|
|
28
|
+
'targetFieldName',
|
|
29
|
+
'sourceFieldDeveloperName',
|
|
30
|
+
'targetFieldDeveloperName',
|
|
31
|
+
'sourceEntityDeveloperName',
|
|
32
|
+
'targetEntityDeveloperName',
|
|
33
|
+
]);
|
|
34
|
+
/**
|
|
35
|
+
* Render only bounded schema identifiers, enums and flags; never raw objects or free text.
|
|
36
|
+
* @param {unknown} value Compared leaf.
|
|
37
|
+
* @param {string} key Leaf property name.
|
|
38
|
+
* @returns {string} Safe diagnostic value.
|
|
39
|
+
*/
|
|
40
|
+
function safeValue(value, key) {
|
|
41
|
+
if (value === undefined)
|
|
42
|
+
return '[missing]';
|
|
43
|
+
if (value === null)
|
|
44
|
+
return 'null';
|
|
45
|
+
if (!visibleKeys.has(key))
|
|
46
|
+
return '[redacted]';
|
|
47
|
+
if (typeof value === 'boolean' || typeof value === 'number')
|
|
48
|
+
return String(value);
|
|
49
|
+
if (typeof value === 'string' && /^[A-Za-z][A-Za-z0-9_ -]{0,119}$/u.test(value))
|
|
50
|
+
return JSON.stringify(value);
|
|
51
|
+
return '[redacted]';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Describe the first concrete mismatch without serializing snapshots or secret-bearing fields.
|
|
55
|
+
* @param {unknown} expected Expected protected state.
|
|
56
|
+
* @param {unknown} observed Freshly observed state.
|
|
57
|
+
* @param {string} path Logical field path supplied by the check.
|
|
58
|
+
* @param {number} [depth] Bounded traversal depth.
|
|
59
|
+
* @returns {string} Safe first differing path and leaf values.
|
|
60
|
+
*/
|
|
61
|
+
function difference(expected, observed, path, depth = 0) {
|
|
62
|
+
if (depth < 12 &&
|
|
63
|
+
expected &&
|
|
64
|
+
observed &&
|
|
65
|
+
typeof expected === 'object' &&
|
|
66
|
+
typeof observed === 'object') {
|
|
67
|
+
const a = expected;
|
|
68
|
+
const b = observed;
|
|
69
|
+
if (Array.isArray(expected) && Array.isArray(observed) && expected.length !== observed.length)
|
|
70
|
+
return `${path}.length: expected ${expected.length}; observed ${observed.length}`;
|
|
71
|
+
for (const key of [...new Set([...Object.keys(a), ...Object.keys(b)])].slice(0, 500)) {
|
|
72
|
+
if (!isDeepStrictEqual(a[key], b[key])) {
|
|
73
|
+
// Do not blame an admitted native mapping permutation when another field drifted.
|
|
74
|
+
if (key === 'mappings' && Array.isArray(a[key]) && Array.isArray(b[key])) {
|
|
75
|
+
const remaining = [...b[key]];
|
|
76
|
+
if (a[key].length === remaining.length &&
|
|
77
|
+
a[key].every((entry) => {
|
|
78
|
+
const index = remaining.findIndex((item) => isDeepStrictEqual(entry, item));
|
|
79
|
+
if (index === -1)
|
|
80
|
+
return false;
|
|
81
|
+
remaining.splice(index, 1);
|
|
82
|
+
return true;
|
|
83
|
+
}))
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// Unknown keys can themselves contain secrets; never echo them.
|
|
87
|
+
const safeKey = visibleKeys.has(key) ||
|
|
88
|
+
/^\d{1,5}$/u.test(key) ||
|
|
89
|
+
[
|
|
90
|
+
'identity',
|
|
91
|
+
'spec',
|
|
92
|
+
'fields',
|
|
93
|
+
'sourceFields',
|
|
94
|
+
'mappings',
|
|
95
|
+
'fieldMappings',
|
|
96
|
+
'binding',
|
|
97
|
+
'target',
|
|
98
|
+
'observed',
|
|
99
|
+
'inventory',
|
|
100
|
+
'dataLakeObjectInfo',
|
|
101
|
+
'dataSpaceInfo',
|
|
102
|
+
'parents',
|
|
103
|
+
'document',
|
|
104
|
+
'body',
|
|
105
|
+
'newDlo',
|
|
106
|
+
'primaryKey',
|
|
107
|
+
'connectorInfo',
|
|
108
|
+
'refreshConfig',
|
|
109
|
+
'source',
|
|
110
|
+
'connectionId',
|
|
111
|
+
'recordId',
|
|
112
|
+
'id',
|
|
113
|
+
'label',
|
|
114
|
+
].includes(key)
|
|
115
|
+
? key
|
|
116
|
+
: '[other property]';
|
|
117
|
+
if (safeKey === '[other property]')
|
|
118
|
+
return `${path}.${safeKey}: protected value changed (values redacted)`;
|
|
119
|
+
return difference(a[key], b[key], `${path}.${safeKey}`, depth + 1);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (expected && observed && typeof expected === 'object' && typeof observed === 'object')
|
|
124
|
+
return `${path}: protected content differs (values redacted; diagnostic traversal limit or admitted ordering difference)`;
|
|
125
|
+
const key = path.split('.').at(-1);
|
|
126
|
+
return `${path}: expected ${safeValue(expected, key)}; observed ${safeValue(observed, key)}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Add an explanation only after the existing safety predicate rejects; never changes its outcome.
|
|
130
|
+
* @template {Error} T
|
|
131
|
+
* @param {T} error Existing typed error and compatibility code.
|
|
132
|
+
* @param {string} check Static operation/check description.
|
|
133
|
+
* @param {unknown} resource Resource API name where independently known.
|
|
134
|
+
* @param {unknown} expected Expected protected state (not retained).
|
|
135
|
+
* @param {unknown} observed Observed protected state (not retained).
|
|
136
|
+
* @param {string} [path] Logical comparison root.
|
|
137
|
+
* @param {string} [hint] Static sentence naming the way forward.
|
|
138
|
+
* @returns {T} The original error with a bounded, safe human explanation.
|
|
139
|
+
*/
|
|
140
|
+
export function explainMismatch(error, check, resource, expected, observed, path = 'state', hint) {
|
|
141
|
+
const identity = safeValue(resource, 'apiName');
|
|
142
|
+
const message = `Plugin verification failed during ${check} for ${identity}: ${difference(expected, observed, path)}.${hint ? ` ${hint}` : ''}`;
|
|
143
|
+
details.set(error, message);
|
|
144
|
+
error.message = `${error.message} ${message}`;
|
|
145
|
+
return error;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Replace the explanation of an already refused operation with complete plugin-built
|
|
149
|
+
* instructions. A text ending in a line break keeps the next action on its own line.
|
|
150
|
+
* @param {Error} error Existing typed refusal; its code and outcome are untouched.
|
|
151
|
+
* @param {string} message Bounded text built only from validated identifiers.
|
|
152
|
+
*/
|
|
153
|
+
export function replaceExplanation(error, message) {
|
|
154
|
+
details.set(error, message);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The plugin-built explanation of a refusal, if one was attached.
|
|
158
|
+
* @param {unknown} error Caught error.
|
|
159
|
+
* @returns {string | undefined} Explanation text.
|
|
160
|
+
*/
|
|
161
|
+
export function explanationOf(error) {
|
|
162
|
+
return error instanceof Error ? details.get(error) : undefined;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A key of an authored file as it may appear in a message: a plain identifier, otherwise a
|
|
166
|
+
* placeholder, so free text in a key is never echoed.
|
|
167
|
+
* @param {string} key Object key.
|
|
168
|
+
* @returns {string} Printable key.
|
|
169
|
+
*/
|
|
170
|
+
export function printableKey(key) {
|
|
171
|
+
return /^[A-Za-z_$][A-Za-z0-9_$-]{0,79}$/u.test(key) ? key : '[unnamed key]';
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Attach an explanation that names the offending key path of an authored file.
|
|
175
|
+
* @template {Error} T
|
|
176
|
+
* @param {T} error Typed refusal; its code is untouched.
|
|
177
|
+
* @param {string} detail Sentence built only from printable keys and static text.
|
|
178
|
+
* @returns {T} The same error.
|
|
179
|
+
*/
|
|
180
|
+
export function explainInput(error, detail) {
|
|
181
|
+
details.set(error, detail);
|
|
182
|
+
error.message = `${error.message} ${detail}`;
|
|
183
|
+
return error;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Give a refusal a cause-specific hint in place of the registered hint of its code, for a code
|
|
187
|
+
* with several causes.
|
|
188
|
+
* @template {Error} T
|
|
189
|
+
* @param {T} error Typed refusal.
|
|
190
|
+
* @param {string} hint Static sentence naming the way forward for this cause.
|
|
191
|
+
* @returns {T} The same error.
|
|
192
|
+
*/
|
|
193
|
+
export function withHint(error, hint) {
|
|
194
|
+
registerCauseHint(hint);
|
|
195
|
+
hints.set(error, hint);
|
|
196
|
+
return error;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The cause-specific hint of a refusal, as a diagnostic property, or none.
|
|
200
|
+
* @param {unknown} error Caught error.
|
|
201
|
+
* @returns {{hint?: string}} `{ hint }` or an empty object.
|
|
202
|
+
*/
|
|
203
|
+
export function hintOf(error) {
|
|
204
|
+
const hint = error instanceof Error ? hints.get(error) : undefined;
|
|
205
|
+
return hint === undefined ? {} : { hint };
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Explain a refusal of a file whose data space is not the run's, naming both.
|
|
209
|
+
* @template {Error} T
|
|
210
|
+
* @param {T} error Typed refusal (a *_DATASPACE_MISMATCH or UNSUPPORTED_RELATIONSHIP_DATASPACE).
|
|
211
|
+
* @param {string} apiName The file's validated component name.
|
|
212
|
+
* @param {string} fileSpace The data space the file names in c__dataSpace.
|
|
213
|
+
* @param {string} runSpace The run's data space.
|
|
214
|
+
* @param {boolean} [crossSpace] A deploy of a kind --allow-cross-dataspace can translate: say so.
|
|
215
|
+
* @returns {T} The same error with the explanation.
|
|
216
|
+
*/
|
|
217
|
+
export function explainSpaceMismatch(error, apiName, fileSpace, runSpace, crossSpace = false) {
|
|
218
|
+
return explainInput(error, `${apiName} names the data space ${printableKey(fileSpace)} in c__dataSpace, but the run's data space is ${printableKey(runSpace)} (--dataspace, default "default"). Run the command with --dataspace ${printableKey(fileSpace)}, or correct the file.${crossSpace ? crossSpaceSentence(runSpace) : ''}`);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The sentence a deploy refusal adds for a file --allow-cross-dataspace can translate.
|
|
222
|
+
* @param {string} runSpace The run's data space.
|
|
223
|
+
* @returns {string} The sentence, with a leading space.
|
|
224
|
+
*/
|
|
225
|
+
export function crossSpaceSentence(runSpace) {
|
|
226
|
+
return ` To deploy it into ${printableKey(runSpace)} instead, add --allow-cross-dataspace (-c).`;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Reuse existing diagnostic messages while distinguishing local verification from API rejection.
|
|
230
|
+
* Arbitrary exception messages, bodies and stack traces are never forwarded.
|
|
231
|
+
* @param {unknown} error Caught error.
|
|
232
|
+
* @param {string} nextAction Existing outcome-specific safe next action.
|
|
233
|
+
* @returns {string} Bounded diagnostic suitable for console and JSON.
|
|
234
|
+
*/
|
|
235
|
+
export function operationDiagnostic(error, nextAction) {
|
|
236
|
+
const connect = getConnectDiagnostic(error);
|
|
237
|
+
const apiDetail = connect
|
|
238
|
+
? [
|
|
239
|
+
...(connect.errors ?? []).map(({ code, message }) => [code, message].filter(Boolean).join(': ')),
|
|
240
|
+
...(connect.requestId ? [`Request ID: ${connect.requestId}`] : []),
|
|
241
|
+
].join('; ')
|
|
242
|
+
: '';
|
|
243
|
+
// Salesforce's own sentence may already end the detail; never add a second period.
|
|
244
|
+
const remote = apiDetail
|
|
245
|
+
? ` Salesforce API detail: ${apiDetail}${/[.!?]$/u.test(apiDetail) ? '' : '.'}`
|
|
246
|
+
: '';
|
|
247
|
+
if (connect && connect.kind !== 'api-error') {
|
|
248
|
+
const explanation = connect.statusCode === 429
|
|
249
|
+
? 'Connect API rate limiting: HTTP 429 Too Many Requests.'
|
|
250
|
+
: 'Connect API HTTP 503 Service Unavailable: POSSIBLE Connect rate limit; maintenance, load or other availability issues are also possible. The cause is not confirmed.';
|
|
251
|
+
const wait = connect.retryAfter === undefined ? '' : ` Server Retry-After: ${connect.retryAfter}.`;
|
|
252
|
+
return `${explanation} Reduce request frequency and try later; effective limits can vary with load and change.${wait}${remote} Inspect the target before rerunning a write whose outcome is unknown; no automatic replay was performed. ${nextAction}`;
|
|
253
|
+
}
|
|
254
|
+
const problems = getMetadataProblems(error);
|
|
255
|
+
if (problems)
|
|
256
|
+
return `Salesforce Metadata API did not confirm the destructive deployment${problems.length > 0 ? `: ${problems.join('; ')}` : '; no problem text is disclosed'}. ${nextAction}`;
|
|
257
|
+
if (error instanceof Error && details.has(error)) {
|
|
258
|
+
const detail = details.get(error);
|
|
259
|
+
return `${detail}${detail.endsWith('\n') ? '' : ' '}${nextAction}`;
|
|
260
|
+
}
|
|
261
|
+
const status = connect?.statusCode ??
|
|
262
|
+
diagnosticDataProperty(error, 'status') ??
|
|
263
|
+
diagnosticDataProperty(error, 'statusCode');
|
|
264
|
+
// A 403 with Salesforce's text is a refusal of the request (the text was admitted only for
|
|
265
|
+
// codes that do not concern access), not an authentication failure.
|
|
266
|
+
const refusal = status === 403 && (connect?.errors ?? []).some(({ message }) => message);
|
|
267
|
+
if (connect && (status === 401 || (status === 403 && !refusal)))
|
|
268
|
+
return `Salesforce API authentication or authorization failed (HTTP ${status}); no authentication response is disclosed.${remote} ${nextAction}`;
|
|
269
|
+
if (typeof status === 'number' && Number.isInteger(status) && status >= 400 && status <= 599)
|
|
270
|
+
return `Salesforce API rejected the request (HTTP ${status}); no response payload is disclosed.${remote} ${nextAction}`;
|
|
271
|
+
return `Plugin verification or request completion failed; no Salesforce rejection was confirmed. ${nextAction}`;
|
|
272
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { NativeCalculatedInsight } from '../artifacts/native-calculated-insight-document.js';
|
|
2
|
+
import type { ApiVersionSelection } from '../transport/api-version.js';
|
|
3
|
+
import type { CalculatedInsightAcquisition, CalculatedInsightConnection, CalculatedInsightReadContext } from './native-calculated-insight.js';
|
|
4
|
+
export type CalculatedInsightDeployIntent = {
|
|
5
|
+
draft?: true;
|
|
6
|
+
context?: CalculatedInsightReadContext;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The read context of one item: API 68 and the data space of the document only.
|
|
10
|
+
* @param {CalculatedInsightConnection} connection API 68 connection.
|
|
11
|
+
* @param {ApiVersionSelection} selection Route selection (68.0).
|
|
12
|
+
* @param {string} dataSpace Selected data space.
|
|
13
|
+
* @param {NativeCalculatedInsight} desired Document; its `dataSpace` must be the selected one.
|
|
14
|
+
* @param {CalculatedInsightReadContext} [context] Injected context.
|
|
15
|
+
* @returns {CalculatedInsightReadContext} Checked context.
|
|
16
|
+
*/
|
|
17
|
+
export declare function calculatedInsightDeployContext(connection: CalculatedInsightConnection, selection: ApiVersionSelection, dataSpace: string, desired: NativeCalculatedInsight, context?: CalculatedInsightReadContext): CalculatedInsightReadContext;
|
|
18
|
+
export type CalculatedInsightPlan = {
|
|
19
|
+
action: 'create' | 'update' | 'unchanged';
|
|
20
|
+
acquired: CalculatedInsightAcquisition;
|
|
21
|
+
/** The `draft` value an update sends: true with --draft or for a DRAFT insight, else none. */
|
|
22
|
+
draft?: true;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Create when the name reads absent, unchanged when the org insight holds every key of the
|
|
26
|
+
* document, update otherwise. An update of a DRAFT insight keeps it a draft: deploy never
|
|
27
|
+
* publishes (that is `sf data360 publish`).
|
|
28
|
+
* @param {NativeCalculatedInsight} desired Document from the files.
|
|
29
|
+
* @param {CalculatedInsightReadContext} context Read context.
|
|
30
|
+
* @param {boolean} draft --draft given.
|
|
31
|
+
* @returns {Promise<CalculatedInsightPlan>} Action and the read it is based on.
|
|
32
|
+
*/
|
|
33
|
+
export declare function planNativeCalculatedInsightDeploy(desired: NativeCalculatedInsight, context: CalculatedInsightReadContext, draft: boolean): Promise<CalculatedInsightPlan>;
|
|
34
|
+
export type CalculatedInsightPreview = {
|
|
35
|
+
family: 'calculated-insight';
|
|
36
|
+
outcome: 'create' | 'update' | 'unchanged' | 'blocked';
|
|
37
|
+
target: 'present' | 'absent' | 'unknown';
|
|
38
|
+
absenceProof: 'none' | 'native-item-not-found';
|
|
39
|
+
route: {
|
|
40
|
+
apiVersion: '68.0';
|
|
41
|
+
method: 'POST' | 'PATCH';
|
|
42
|
+
resource: 'calculated-insights';
|
|
43
|
+
};
|
|
44
|
+
diagnostics: Array<{
|
|
45
|
+
code: string;
|
|
46
|
+
message: string;
|
|
47
|
+
}>;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Preview one create, update or no-op from one GET; never writes.
|
|
51
|
+
* @param {unknown} value Document from the files (JSON with its SQL).
|
|
52
|
+
* @param {CalculatedInsightConnection} connection API 68 connection.
|
|
53
|
+
* @param {ApiVersionSelection} selection Route selection (68.0).
|
|
54
|
+
* @param {string} dataSpace Selected data space.
|
|
55
|
+
* @param {CalculatedInsightDeployIntent} options --draft and an injected read context.
|
|
56
|
+
* @returns {Promise<CalculatedInsightPreview>} Payload-free classification.
|
|
57
|
+
*/
|
|
58
|
+
export declare function preflightCalculatedInsightDeploy(value: unknown, connection: CalculatedInsightConnection, selection: ApiVersionSelection, dataSpace: string, options?: CalculatedInsightDeployIntent): Promise<CalculatedInsightPreview>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { getConnectDiagnostic } from '../transport/connect-diagnostic.js';
|
|
2
|
+
import { refuseEscapedCopy } from './escaped-copy.js';
|
|
3
|
+
import { explanationOf, operationDiagnostic } from './operation-diagnostic.js';
|
|
4
|
+
import { CalculatedInsightError, calculatedInsightMatches, calculatedInsightSpaceMismatch, validateNativeCalculatedInsight, } from '../artifacts/native-calculated-insight-document.js';
|
|
5
|
+
import { acquireCalculatedInsight, calculatedInsightReadContext, } from './native-calculated-insight.js';
|
|
6
|
+
/**
|
|
7
|
+
* The read context of one item: API 68 and the data space of the document only.
|
|
8
|
+
* @param {CalculatedInsightConnection} connection API 68 connection.
|
|
9
|
+
* @param {ApiVersionSelection} selection Route selection (68.0).
|
|
10
|
+
* @param {string} dataSpace Selected data space.
|
|
11
|
+
* @param {NativeCalculatedInsight} desired Document; its `dataSpace` must be the selected one.
|
|
12
|
+
* @param {CalculatedInsightReadContext} [context] Injected context.
|
|
13
|
+
* @returns {CalculatedInsightReadContext} Checked context.
|
|
14
|
+
*/
|
|
15
|
+
export function calculatedInsightDeployContext(connection, selection, dataSpace, desired, context) {
|
|
16
|
+
// The routes are API 68 only, and the file names the data space it belongs to.
|
|
17
|
+
if (selection.requested !== '68.0')
|
|
18
|
+
throw new Error('Native CI scope');
|
|
19
|
+
if (desired.dataSpace !== dataSpace)
|
|
20
|
+
throw calculatedInsightSpaceMismatch(desired, dataSpace);
|
|
21
|
+
const result = context ?? calculatedInsightReadContext(connection, dataSpace);
|
|
22
|
+
result.check();
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create when the name reads absent, unchanged when the org insight holds every key of the
|
|
27
|
+
* document, update otherwise. An update of a DRAFT insight keeps it a draft: deploy never
|
|
28
|
+
* publishes (that is `sf data360 publish`).
|
|
29
|
+
* @param {NativeCalculatedInsight} desired Document from the files.
|
|
30
|
+
* @param {CalculatedInsightReadContext} context Read context.
|
|
31
|
+
* @param {boolean} draft --draft given.
|
|
32
|
+
* @returns {Promise<CalculatedInsightPlan>} Action and the read it is based on.
|
|
33
|
+
*/
|
|
34
|
+
export async function planNativeCalculatedInsightDeploy(desired, context, draft) {
|
|
35
|
+
context.check();
|
|
36
|
+
const acquired = await acquireCalculatedInsight(context, desired.apiName);
|
|
37
|
+
context.check();
|
|
38
|
+
if (acquired.state === 'absent')
|
|
39
|
+
return { action: 'create', acquired };
|
|
40
|
+
refuseEscapedCopy(desired, acquired.document, (code) => new CalculatedInsightError(code));
|
|
41
|
+
if (calculatedInsightMatches(desired, acquired.document))
|
|
42
|
+
return { action: 'unchanged', acquired };
|
|
43
|
+
return {
|
|
44
|
+
action: 'update',
|
|
45
|
+
acquired,
|
|
46
|
+
...(draft || acquired.status === 'DRAFT' ? { draft: true } : {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Preview one create, update or no-op from one GET; never writes.
|
|
51
|
+
* @param {unknown} value Document from the files (JSON with its SQL).
|
|
52
|
+
* @param {CalculatedInsightConnection} connection API 68 connection.
|
|
53
|
+
* @param {ApiVersionSelection} selection Route selection (68.0).
|
|
54
|
+
* @param {string} dataSpace Selected data space.
|
|
55
|
+
* @param {CalculatedInsightDeployIntent} options --draft and an injected read context.
|
|
56
|
+
* @returns {Promise<CalculatedInsightPreview>} Payload-free classification.
|
|
57
|
+
*/
|
|
58
|
+
export async function preflightCalculatedInsightDeploy(value, connection, selection, dataSpace, options = {}) {
|
|
59
|
+
const route = {
|
|
60
|
+
apiVersion: '68.0',
|
|
61
|
+
method: 'PATCH',
|
|
62
|
+
resource: 'calculated-insights',
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
const desired = validateNativeCalculatedInsight(value);
|
|
66
|
+
const context = calculatedInsightDeployContext(connection, selection, dataSpace, desired, options.context);
|
|
67
|
+
const plan = await planNativeCalculatedInsightDeploy(desired, context, options.draft === true);
|
|
68
|
+
return {
|
|
69
|
+
family: 'calculated-insight',
|
|
70
|
+
outcome: plan.action,
|
|
71
|
+
target: plan.acquired.state,
|
|
72
|
+
absenceProof: plan.acquired.state === 'absent' ? 'native-item-not-found' : 'none',
|
|
73
|
+
route: { ...route, method: plan.action === 'create' ? 'POST' : 'PATCH' },
|
|
74
|
+
diagnostics: [],
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
return {
|
|
79
|
+
family: 'calculated-insight',
|
|
80
|
+
outcome: 'blocked',
|
|
81
|
+
target: 'unknown',
|
|
82
|
+
absenceProof: 'none',
|
|
83
|
+
route,
|
|
84
|
+
diagnostics: [
|
|
85
|
+
{
|
|
86
|
+
code: error instanceof CalculatedInsightError ? error.code : 'CI_ADMISSION_FAILED',
|
|
87
|
+
// Salesforce's answer or the plugin's own explanation (a data space mismatch).
|
|
88
|
+
message: getConnectDiagnostic(error) || explanationOf(error) !== undefined
|
|
89
|
+
? operationDiagnostic(error, 'Native CI deployment was not attempted.')
|
|
90
|
+
: 'The calculated insight could not be read or its file or data space is invalid; nothing was sent.',
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DataTransformDocument, DataTransformObservation } from '../artifacts/data-transform-document.js';
|
|
2
|
+
import type { DataTransformClient } from '../transport/data-transform-rest.js';
|
|
3
|
+
export type DataTransformDeploySelection = {
|
|
4
|
+
operation: 'create';
|
|
5
|
+
} | {
|
|
6
|
+
operation: 'update';
|
|
7
|
+
targetId: string;
|
|
8
|
+
};
|
|
9
|
+
export type DataTransformDeployPlan = {
|
|
10
|
+
operation: 'create' | 'update' | 'unchanged';
|
|
11
|
+
document: DataTransformDocument;
|
|
12
|
+
targetId?: string;
|
|
13
|
+
current?: DataTransformObservation;
|
|
14
|
+
/** Whether the definition is sent (create POST or update PUT). */
|
|
15
|
+
writeDefinition: boolean;
|
|
16
|
+
/** Whether the schedule of the file is sent with the schedule PUT. */
|
|
17
|
+
writeSchedule: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Preflight a create, or an update of the target the deploy resolved by name. The definition is
|
|
21
|
+
* unchanged when it equals the org's projected input (enum values ignoring letter case); the
|
|
22
|
+
* schedule is unchanged when the file has none (left alone) or it equals the org's projected
|
|
23
|
+
* schedule (a new transform has none). What differs is sent as written and Salesforce decides.
|
|
24
|
+
* @param {unknown} value Portable artifact.
|
|
25
|
+
* @param {DataTransformDeploySelection} selection Create, or update with the resolved target ID.
|
|
26
|
+
* @param {DataTransformClient} client Native API68 transform transport.
|
|
27
|
+
* @param {object} [options] Preview-only native validation control.
|
|
28
|
+
* @param {boolean} [options.skipServerValidation] Skip validation POST for GET-only preview.
|
|
29
|
+
* @returns {Promise<DataTransformDeployPlan>} Fresh target-bound plan, not a replay token.
|
|
30
|
+
*/
|
|
31
|
+
export declare function preflightDataTransformDeploy(value: unknown, selection: DataTransformDeploySelection, client: DataTransformClient, options?: {
|
|
32
|
+
skipServerValidation?: boolean;
|
|
33
|
+
}): Promise<DataTransformDeployPlan>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { DataTransformError, refuseEscapedTransformExpressions, sameDataTransformDefinition, sameDataTransformSchedule, validateDataTransformDocument, } from '../artifacts/data-transform-document.js';
|
|
2
|
+
import { refuseEscapedCopy } from './escaped-copy.js';
|
|
3
|
+
import { retrieveDataTransform } from './retrieve-data-transform.js';
|
|
4
|
+
import { explainInput, printableKey } from './operation-diagnostic.js';
|
|
5
|
+
import { displayableApiText } from '../transport/connect-diagnostic.js';
|
|
6
|
+
/**
|
|
7
|
+
* One validation issue as it may be shown: its error code when it is a code, and its message (plain
|
|
8
|
+
* text: the client asks for it, plainTextHeaders) when it passes the display filter of REST
|
|
9
|
+
* errors. A possessive `'s` reads as `’s`, so the filter does not take it
|
|
10
|
+
* for a quoted value. Anything else is left out.
|
|
11
|
+
* @param {unknown} issue Validation issue.
|
|
12
|
+
* @returns {string | undefined} Displayable text, or none.
|
|
13
|
+
*/
|
|
14
|
+
function issueText(issue) {
|
|
15
|
+
if (!issue || typeof issue !== 'object' || Array.isArray(issue))
|
|
16
|
+
return undefined;
|
|
17
|
+
const { errorCode, errorMessage } = issue;
|
|
18
|
+
const code = typeof errorCode === 'string' && /^[A-Z][A-Z0-9_]{0,79}$/u.test(errorCode)
|
|
19
|
+
? errorCode
|
|
20
|
+
: undefined;
|
|
21
|
+
const message = typeof errorMessage === 'string'
|
|
22
|
+
? displayableApiText(errorMessage.replaceAll(/(?<=[A-Za-z0-9_])'(?=s\b)/gu, '’'))
|
|
23
|
+
: undefined;
|
|
24
|
+
return code || message ? [code, message].filter(Boolean).join(': ') : undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* TRANSFORM_VALIDATION_FAILED with Salesforce's issues: at most three, each as {@link issueText}
|
|
28
|
+
* admits it.
|
|
29
|
+
* @param {string} name Transform name.
|
|
30
|
+
* @param {unknown[]} issues Validation issues (at least one).
|
|
31
|
+
* @returns {DataTransformError} The refusal.
|
|
32
|
+
*/
|
|
33
|
+
function validationRefusal(name, issues) {
|
|
34
|
+
const texts = [
|
|
35
|
+
...new Set(issues.map((issue) => issueText(issue)).filter((text) => text !== undefined)),
|
|
36
|
+
];
|
|
37
|
+
const shown = `${texts.slice(0, 3).join('; ')}${texts.length > 3 ? `; and ${texts.length - 3} more` : ''}`;
|
|
38
|
+
return explainInput(new DataTransformError('TRANSFORM_VALIDATION_FAILED'), `Salesforce validation rejected the data transform ${name}${shown ? `: ${shown}${/[.!?]$/u.test(shown) ? '' : '.'}` : ' without an issue text that can be shown.'} Nothing was created.`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Preflight a create, or an update of the target the deploy resolved by name. The definition is
|
|
42
|
+
* unchanged when it equals the org's projected input (enum values ignoring letter case); the
|
|
43
|
+
* schedule is unchanged when the file has none (left alone) or it equals the org's projected
|
|
44
|
+
* schedule (a new transform has none). What differs is sent as written and Salesforce decides.
|
|
45
|
+
* @param {unknown} value Portable artifact.
|
|
46
|
+
* @param {DataTransformDeploySelection} selection Create, or update with the resolved target ID.
|
|
47
|
+
* @param {DataTransformClient} client Native API68 transform transport.
|
|
48
|
+
* @param {object} [options] Preview-only native validation control.
|
|
49
|
+
* @param {boolean} [options.skipServerValidation] Skip validation POST for GET-only preview.
|
|
50
|
+
* @returns {Promise<DataTransformDeployPlan>} Fresh target-bound plan, not a replay token.
|
|
51
|
+
*/
|
|
52
|
+
export async function preflightDataTransformDeploy(value, selection, client, options = {}) {
|
|
53
|
+
const document = validateDataTransformDocument(value);
|
|
54
|
+
refuseEscapedTransformExpressions(document);
|
|
55
|
+
// A create can name its data space only through dataSpaceName; without it the data space of
|
|
56
|
+
// the new transform is not proven, so a create outside default is refused before any write.
|
|
57
|
+
if (selection.operation === 'create' &&
|
|
58
|
+
document.c__dataSpace !== 'default' &&
|
|
59
|
+
typeof document.definition.dataSpaceName !== 'string')
|
|
60
|
+
throw explainInput(new DataTransformError('TRANSFORM_DATASPACE_MISMATCH'), `Data transform ${String(document.definition.name)} does not exist yet and its definition names no dataSpaceName, so a create cannot put it into the data space ${printableKey(document.c__dataSpace)} (c__dataSpace). Add definition.dataSpaceName, or create it in Data Cloud; nothing was written.`);
|
|
61
|
+
let current;
|
|
62
|
+
if (selection.operation === 'update') {
|
|
63
|
+
current = await retrieveDataTransform(selection.targetId, client);
|
|
64
|
+
if (current.document.definition.name !== document.definition.name)
|
|
65
|
+
throw new DataTransformError('TRANSFORM_IDENTITY_MISMATCH');
|
|
66
|
+
// Names are unique in the org: the transform of that name must be in the file's data space.
|
|
67
|
+
if (current.document.c__dataSpace !== document.c__dataSpace)
|
|
68
|
+
throw explainInput(new DataTransformError('TRANSFORM_DATASPACE_MISMATCH'), `The org's data transform ${String(document.definition.name)} is in the data space ${printableKey(current.document.c__dataSpace)}, but the file names ${printableKey(document.c__dataSpace)} in c__dataSpace. A transform does not move between data spaces; nothing was written.`);
|
|
69
|
+
}
|
|
70
|
+
if (current)
|
|
71
|
+
refuseEscapedCopy(document.definition, current.document.definition, (code) => new DataTransformError(code));
|
|
72
|
+
const writeDefinition = !current || !sameDataTransformDefinition(current.document, document);
|
|
73
|
+
const writeSchedule = document.schedule !== undefined &&
|
|
74
|
+
!sameDataTransformSchedule(current?.document.schedule, document.schedule);
|
|
75
|
+
if (current && !writeDefinition && !writeSchedule)
|
|
76
|
+
return {
|
|
77
|
+
operation: 'unchanged',
|
|
78
|
+
document,
|
|
79
|
+
targetId: current.targetId,
|
|
80
|
+
current,
|
|
81
|
+
writeDefinition,
|
|
82
|
+
writeSchedule,
|
|
83
|
+
};
|
|
84
|
+
// The validation endpoint rejects an existing owner's own output (live-observed), so only create is validated.
|
|
85
|
+
if (selection.operation === 'create' && !options.skipServerValidation) {
|
|
86
|
+
const validation = await client.validate(document.definition);
|
|
87
|
+
if (!validation ||
|
|
88
|
+
typeof validation !== 'object' ||
|
|
89
|
+
Array.isArray(validation) ||
|
|
90
|
+
!Array.isArray(validation.issues))
|
|
91
|
+
throw new DataTransformError('TRANSFORM_VALIDATION_FAILED');
|
|
92
|
+
const issues = validation.issues;
|
|
93
|
+
if (issues.length > 0)
|
|
94
|
+
throw validationRefusal(String(document.definition.name), issues);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
operation: selection.operation,
|
|
98
|
+
document,
|
|
99
|
+
targetId: current?.targetId,
|
|
100
|
+
current,
|
|
101
|
+
writeDefinition,
|
|
102
|
+
writeSchedule,
|
|
103
|
+
};
|
|
104
|
+
}
|