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,116 @@
|
|
|
1
|
+
import { AuthInfo, Connection } from '@salesforce/core';
|
|
2
|
+
import { ConnectClient, ConnectError } from './connect-client.js';
|
|
3
|
+
import { getConnectDiagnostic } from './connect-diagnostic.js';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a failure is Salesforce's answer to an expired access token: HTTP 401 INVALID_SESSION_ID.
|
|
6
|
+
* @param {unknown} error Failure of one request.
|
|
7
|
+
* @returns {boolean} Expired session.
|
|
8
|
+
*/
|
|
9
|
+
function sessionExpired(error) {
|
|
10
|
+
return (error instanceof ConnectError &&
|
|
11
|
+
error.code === 'AUTHENTICATION_FAILED' &&
|
|
12
|
+
error.statusCode === 401 &&
|
|
13
|
+
(getConnectDiagnostic(error)?.errors ?? []).some((entry) => entry.code === 'INVALID_SESSION_ID'));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Routes on the bound Connection: no child CLI and no redirect. A GET answered with an expired
|
|
17
|
+
* session refreshes the token once through Salesforce core (one refresh shared by concurrent
|
|
18
|
+
* reads) and is sent once more. A write (POST, PATCH, PUT, DELETE) keeps ConnectClient.send's
|
|
19
|
+
* write rule: it is resent only after a failure that proves it never left (ECONNREFUSED,
|
|
20
|
+
* ENOTFOUND, EHOSTUNREACH, EAI_AGAIN), never after a reset, timeout, 429 or 503, and never
|
|
21
|
+
* after a token refresh. The caller's read-back decides what the write did.
|
|
22
|
+
*/
|
|
23
|
+
class BoundTransport extends ConnectClient {
|
|
24
|
+
session;
|
|
25
|
+
refreshing;
|
|
26
|
+
constructor(session, version) {
|
|
27
|
+
super(session, version);
|
|
28
|
+
this.session = session;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Dispatch one fixed route.
|
|
32
|
+
* @param {BoundMethod} method Read or write.
|
|
33
|
+
* @param {string} route Root-relative endpoint.
|
|
34
|
+
* @param {unknown} [noContent] Sentinel JSforce returns for HTTP 204.
|
|
35
|
+
* @param {unknown} [body] JSON body of a write.
|
|
36
|
+
* @returns {Promise<unknown>} Untrusted native response.
|
|
37
|
+
*/
|
|
38
|
+
async request(method, route, noContent, body) {
|
|
39
|
+
const url = this.safeUrl(route);
|
|
40
|
+
const request = body === undefined
|
|
41
|
+
? { method, url }
|
|
42
|
+
: {
|
|
43
|
+
method,
|
|
44
|
+
url,
|
|
45
|
+
body: JSON.stringify(body),
|
|
46
|
+
headers: { 'content-type': 'application/json' },
|
|
47
|
+
};
|
|
48
|
+
const send = async () => this.send(request, this.noRefreshReceiver(), noContent);
|
|
49
|
+
try {
|
|
50
|
+
return await send();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const refresh = this.session.refreshAuth;
|
|
54
|
+
if (method !== 'GET' || !sessionExpired(error) || typeof refresh !== 'function')
|
|
55
|
+
throw error;
|
|
56
|
+
try {
|
|
57
|
+
this.refreshing ??= refresh.call(this.session).finally(() => {
|
|
58
|
+
this.refreshing = undefined;
|
|
59
|
+
});
|
|
60
|
+
await this.refreshing;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
return send();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Bind SSOT reads and writes, and the Metadata API calls, to one lazily opened authenticated
|
|
71
|
+
* Connection.
|
|
72
|
+
* Failures surface as ConnectError with the retained API diagnostic; callers map them.
|
|
73
|
+
* @param {string} targetOrg Resolved username of the target org.
|
|
74
|
+
* @param {string} version Numeric API version such as 68.0, already normalized by the caller.
|
|
75
|
+
* @param {BoundConnection} [connect] Supplies the Connection; defaults to the CLI auth for targetOrg.
|
|
76
|
+
* @returns {BoundSsot} Sender; a GET is resent once after an expired-session refresh, a write never.
|
|
77
|
+
* Its Metadata API calls use the same Connection.
|
|
78
|
+
*/
|
|
79
|
+
export function openBoundSsot(targetOrg, version, connect) {
|
|
80
|
+
const open = connect ??
|
|
81
|
+
(async () => Connection.create({
|
|
82
|
+
authInfo: await AuthInfo.create({ username: targetOrg }),
|
|
83
|
+
connectionOptions: { version },
|
|
84
|
+
}));
|
|
85
|
+
let session;
|
|
86
|
+
let transport;
|
|
87
|
+
// Metadata API calls go one at a time even when REST reads run in parallel: they are cheap
|
|
88
|
+
// (about 0.15 s each) and the Metadata API answers REQUEST_LIMIT_EXCEEDED to every call once an
|
|
89
|
+
// org has sent about a thousand in an hour (DB entry data360:a2.retrieve-speed.api68), so
|
|
90
|
+
// they are never sent faster than one after another.
|
|
91
|
+
let metadataQueue = Promise.resolve();
|
|
92
|
+
const oneAtATime = async (call) => {
|
|
93
|
+
const turn = metadataQueue.then(call);
|
|
94
|
+
metadataQueue = turn.catch(() => { });
|
|
95
|
+
return turn;
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
request: async (method, route, noContent, body) => {
|
|
99
|
+
session ??= open();
|
|
100
|
+
const opened = session;
|
|
101
|
+
transport ??= (async () => new BoundTransport(await opened, version))();
|
|
102
|
+
const client = await transport;
|
|
103
|
+
return client.request(method, route, noContent, body);
|
|
104
|
+
},
|
|
105
|
+
metadata: async () => {
|
|
106
|
+
session ??= open();
|
|
107
|
+
const api = (await session).metadata;
|
|
108
|
+
if (!api || typeof api.read !== 'function' || typeof api.update !== 'function')
|
|
109
|
+
throw new ConnectError('REQUEST_FAILED');
|
|
110
|
+
return {
|
|
111
|
+
read: async (type, fullNames) => oneAtATime(async () => api.read(type, fullNames)),
|
|
112
|
+
update: async (type, metadata) => oneAtATime(async () => api.update(type, metadata)),
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { NativeCalculatedInsight } from '../artifacts/native-calculated-insight-document.js';
|
|
2
|
+
import { ConnectClient } from './connect-client.js';
|
|
3
|
+
export type CalculatedInsightClient = {
|
|
4
|
+
get: (apiName: string) => Promise<unknown>;
|
|
5
|
+
/** POST of the document; `draft: true` with --draft, no `draft` key otherwise. */
|
|
6
|
+
create: (document: NativeCalculatedInsight, options?: {
|
|
7
|
+
draft?: true;
|
|
8
|
+
}) => Promise<unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* PATCH of the document; `draft` is sent only when given. `observed` is the org document
|
|
11
|
+
* the update is based on (an unchanged `definitionType` is left out).
|
|
12
|
+
*/
|
|
13
|
+
update: (document: NativeCalculatedInsight, options?: {
|
|
14
|
+
draft?: boolean;
|
|
15
|
+
observed?: NativeCalculatedInsight;
|
|
16
|
+
}) => Promise<unknown>;
|
|
17
|
+
delete: (apiName: string) => Promise<unknown>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The API 68 calculated insight routes. The body is the authored document with the input
|
|
21
|
+
* key names and enum forms (`calculatedInsightInputBody`); Salesforce decides the rest.
|
|
22
|
+
* @param {ConstructorParameters<typeof ConnectClient>[0]} connection Authenticated connection.
|
|
23
|
+
* @param {string} apiVersion '68.0' only.
|
|
24
|
+
* @param {string} dataSpace The run's data space. The item routes take none (names are unique in
|
|
25
|
+
* the org); the create and update bodies carry it as `dataSpaceName` from the file.
|
|
26
|
+
* @returns {CalculatedInsightClient} Exact-name operations.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createCalculatedInsightClient(connection: ConstructorParameters<typeof ConnectClient>[0], apiVersion: string, dataSpace: string): CalculatedInsightClient;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { isDataSpaceName } from '../artifacts/data-space-field.js';
|
|
2
|
+
import { calculatedInsightInputBody, calculatedInsightName, CalculatedInsightError, validateNativeCalculatedInsight, } from '../artifacts/native-calculated-insight-document.js';
|
|
3
|
+
import { ConnectClient } from './connect-client.js';
|
|
4
|
+
/** Internal access to the shared single-attempt, no-refresh transport, not a generic public writer. */
|
|
5
|
+
class CalculatedInsightTransport extends ConnectClient {
|
|
6
|
+
/**
|
|
7
|
+
* Send one request; every returned value remains untrusted.
|
|
8
|
+
* @param {string} route Exact route.
|
|
9
|
+
* @param {'GET' | 'POST' | 'PATCH' | 'DELETE'} method Native verb.
|
|
10
|
+
* @param {Record<string, unknown>} [body] Payload, absent for DELETE and GET.
|
|
11
|
+
* @returns {Promise<unknown>} Raw response, including undefined for an empty DELETE reply.
|
|
12
|
+
*/
|
|
13
|
+
async request(route, method, body) {
|
|
14
|
+
return this.send({
|
|
15
|
+
method,
|
|
16
|
+
url: this.safeUrl(route),
|
|
17
|
+
...(body === undefined
|
|
18
|
+
? {}
|
|
19
|
+
: { body: JSON.stringify(body), headers: { 'content-type': 'application/json' } }),
|
|
20
|
+
}, this.noRefreshReceiver());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The API 68 calculated insight routes. The body is the authored document with the input
|
|
25
|
+
* key names and enum forms (`calculatedInsightInputBody`); Salesforce decides the rest.
|
|
26
|
+
* @param {ConstructorParameters<typeof ConnectClient>[0]} connection Authenticated connection.
|
|
27
|
+
* @param {string} apiVersion '68.0' only.
|
|
28
|
+
* @param {string} dataSpace The run's data space. The item routes take none (names are unique in
|
|
29
|
+
* the org); the create and update bodies carry it as `dataSpaceName` from the file.
|
|
30
|
+
* @returns {CalculatedInsightClient} Exact-name operations.
|
|
31
|
+
*/
|
|
32
|
+
export function createCalculatedInsightClient(connection, apiVersion, dataSpace) {
|
|
33
|
+
if (apiVersion !== '68.0' || !isDataSpaceName(dataSpace))
|
|
34
|
+
throw new CalculatedInsightError('INVALID_CI_SCOPE');
|
|
35
|
+
const transport = new CalculatedInsightTransport(connection, apiVersion);
|
|
36
|
+
const endpoint = `/services/data/v${apiVersion}/ssot/calculated-insights`;
|
|
37
|
+
/**
|
|
38
|
+
* Bind only an exact full CI API name, never an ID or query.
|
|
39
|
+
* @param {string} apiName Full developer name.
|
|
40
|
+
* @returns {string} Exact resource route.
|
|
41
|
+
*/
|
|
42
|
+
function item(apiName) {
|
|
43
|
+
if (typeof apiName !== 'string' || !calculatedInsightName.test(apiName))
|
|
44
|
+
throw new CalculatedInsightError('INVALID_CI_NAME');
|
|
45
|
+
return `${endpoint}/${apiName}`;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
get: async (apiName) => transport.request(item(apiName), 'GET'),
|
|
49
|
+
create: async (document, options) => transport.request(endpoint, 'POST', {
|
|
50
|
+
...calculatedInsightInputBody(validateNativeCalculatedInsight(document), 'create'),
|
|
51
|
+
...(options?.draft === true ? { draft: true } : {}),
|
|
52
|
+
}),
|
|
53
|
+
update: async (document, options) => {
|
|
54
|
+
const checked = validateNativeCalculatedInsight(document);
|
|
55
|
+
return transport.request(item(checked.apiName), 'PATCH', {
|
|
56
|
+
...calculatedInsightInputBody(checked, 'update', options?.observed),
|
|
57
|
+
...(typeof options?.draft === 'boolean' ? { draft: options.draft } : {}),
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
delete: async (apiName) => transport.request(item(apiName), 'DELETE'),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Connection } from '@salesforce/core';
|
|
2
|
+
import type { ApiVersionSelection } from './api-version.js';
|
|
3
|
+
export type TransportErrorCode = 'INVALID_REQUEST' | 'AUTHENTICATION_FAILED' | 'REQUEST_FAILED';
|
|
4
|
+
/** Native 404 codes that name an item as absent or deleted, read from a single REST error. */
|
|
5
|
+
declare const nativeAbsenceCodes: readonly ["ITEM_NOT_FOUND", "ENTITY_IS_DELETED"];
|
|
6
|
+
export type NativeAbsenceCode = (typeof nativeAbsenceCodes)[number];
|
|
7
|
+
/**
|
|
8
|
+
* The request header that makes Connect REST answer in plain text. By default it HTML-escapes
|
|
9
|
+
* every string of a response (`<>"'\&` read as `< > " ' \ &`) while it
|
|
10
|
+
* stores what a write sends as is, so a retrieved label, description, formula or SQL would not be
|
|
11
|
+
* what Salesforce holds (live API 68: data transforms, DLOs, data streams, calculated insights,
|
|
12
|
+
* segments; DB entry data360:connect-rest-entity-encoding-header-api68).
|
|
13
|
+
*/
|
|
14
|
+
export declare const plainTextHeaders: Readonly<Record<string, string>>;
|
|
15
|
+
/**
|
|
16
|
+
* The request with {@link plainTextHeaders} when it goes to a Data 360 (`/ssot/`) route; any
|
|
17
|
+
* other request as it is. Only `/ssot/` routes get the header: a Data 360 read on any other
|
|
18
|
+
* route still returns HTML-escaped text.
|
|
19
|
+
* @param {Parameters<Connection['request']>[0]} request Request as built.
|
|
20
|
+
* @returns {Parameters<Connection['request']>[0]} Request to send.
|
|
21
|
+
*/
|
|
22
|
+
export declare function plainTextRequest(request: Parameters<Connection['request']>[0]): Parameters<Connection['request']>[0];
|
|
23
|
+
/** An intentionally payload-free diagnostic safe for JSON and console output. */
|
|
24
|
+
export declare class ConnectError extends Error {
|
|
25
|
+
readonly code: TransportErrorCode;
|
|
26
|
+
readonly statusCode?: number | undefined;
|
|
27
|
+
readonly nativeCode?: NativeAbsenceCode | undefined;
|
|
28
|
+
constructor(code: TransportErrorCode, statusCode?: number | undefined, nativeCode?: NativeAbsenceCode | undefined);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Bounded retry of in-process requests. GETs retry after network errors and HTTP 429/503;
|
|
32
|
+
* writes retry only when the request provably never reached Salesforce. `sleep` and `warn`
|
|
33
|
+
* are replaceable (tests, commands); `warn` defaults to one stderr line so JSON stdout stays clean.
|
|
34
|
+
*/
|
|
35
|
+
export declare const connectRetry: {
|
|
36
|
+
attempts: number;
|
|
37
|
+
delaysMs: number[];
|
|
38
|
+
maxRetryAfterMs: number;
|
|
39
|
+
sleep: (milliseconds: number) => Promise<void>;
|
|
40
|
+
warn: (message: string) => void;
|
|
41
|
+
};
|
|
42
|
+
type AuthenticatedConnection = Pick<Connection, 'instanceUrl' | 'request'>;
|
|
43
|
+
/** Bounded SSOT transport; Salesforce core owns credentials. */
|
|
44
|
+
export declare class ConnectClient {
|
|
45
|
+
private readonly connection;
|
|
46
|
+
private readonly origin;
|
|
47
|
+
private readonly prefix;
|
|
48
|
+
private readonly selection;
|
|
49
|
+
constructor(connection: AuthenticatedConnection, selection: ApiVersionSelection | string);
|
|
50
|
+
/**
|
|
51
|
+
* Load existing Salesforce CLI authentication without exposing token fields.
|
|
52
|
+
* @param {string} aliasOrUsername Explicit existing org alias or username.
|
|
53
|
+
* @param {string} apiVersion Explicit version; endpoint support is checked by future adapters.
|
|
54
|
+
* @returns {Promise<ConnectClient>} An authenticated client, without making a resource request.
|
|
55
|
+
*/
|
|
56
|
+
static create(aliasOrUsername: string, apiVersion: string): Promise<ConnectClient>;
|
|
57
|
+
/**
|
|
58
|
+
* Read a single SSOT response. Does not infer pagination; see `connectRetry` for the bounded retry.
|
|
59
|
+
* @template T
|
|
60
|
+
* @param {string} path Root-relative SSOT path or same-origin absolute URL, with optional query.
|
|
61
|
+
* @returns {Promise<T>} The unmodified resource response; callers must validate its schema.
|
|
62
|
+
*/
|
|
63
|
+
get<T = unknown>(path: string): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Create one native API68 Segment in the data space of the file (`?dataspace=`), without
|
|
66
|
+
* redirect or replay. The definition goes as written (`segmentWriteBody`); without a schedule in
|
|
67
|
+
* the file it does not refresh.
|
|
68
|
+
* @param {unknown} value Complete admitted portable definition.
|
|
69
|
+
* @param {ReadonlyMap<string, string>} [children] Waterfall child API name to target definition ID.
|
|
70
|
+
* @returns {Promise<unknown>} Untrusted acknowledgement, not settlement.
|
|
71
|
+
*/
|
|
72
|
+
createSegment(value: unknown, children?: ReadonlyMap<string, string>): Promise<unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* PATCH the full authored definition on the native API68 Segment route; the schedule keys go
|
|
75
|
+
* along only when `schedule` is set (the schedule of the file differs from the org's).
|
|
76
|
+
* @param {unknown} value Complete independently admitted desired Segment document.
|
|
77
|
+
* @param {boolean} [schedule] Whether to send the schedule of the file.
|
|
78
|
+
* @param {ReadonlyMap<string, string>} [children] Waterfall child API name to target definition ID.
|
|
79
|
+
* @returns {Promise<unknown>} Untrusted single-attempt response, never settlement evidence.
|
|
80
|
+
*/
|
|
81
|
+
patchSegment(value: unknown, schedule?: boolean, children?: ReadonlyMap<string, string>): Promise<unknown>;
|
|
82
|
+
/**
|
|
83
|
+
* Create exactly one native68 IR owner without refresh, replay or redirect.
|
|
84
|
+
* @param {unknown} value Complete independently admitted portable definition.
|
|
85
|
+
* @param {string} [dataSpacePrefix] Prefix of the ruleset's data space; required outside default.
|
|
86
|
+
* @returns {Promise<unknown>} Untrusted response, never settlement evidence.
|
|
87
|
+
*/
|
|
88
|
+
createIdentityResolution(value: unknown, dataSpacePrefix?: string): Promise<unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* PATCH the complete preserved input shape on one exact native68 owner; never run processing.
|
|
91
|
+
* @param {unknown} value Complete independently admitted desired definition.
|
|
92
|
+
* @param {unknown} [current] Current target definition; lists it has and the file empties are sent empty.
|
|
93
|
+
* @returns {Promise<unknown>} Untrusted response, never settlement evidence.
|
|
94
|
+
*/
|
|
95
|
+
patchIdentityResolution(value: unknown, current?: unknown): Promise<unknown>;
|
|
96
|
+
/**
|
|
97
|
+
* Delete exactly one native68 owner by its freshly resolved Salesforce record ID.
|
|
98
|
+
* No name routing, refresh, replay, redirect or arbitrary DELETE path is exposed.
|
|
99
|
+
* @param {string} id Independently bound target-local IR record ID.
|
|
100
|
+
* @returns {Promise<void>} Acknowledged HTTP204 only, never owner absence proof.
|
|
101
|
+
*/
|
|
102
|
+
deleteIdentityResolution(id: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Delete one exact native68 Segment by API name, without replay or redirect.
|
|
105
|
+
* @param {string} apiName Freshly matched target API name.
|
|
106
|
+
* @returns {Promise<void>} HTTP204 acknowledgement, not independent absence proof.
|
|
107
|
+
*/
|
|
108
|
+
deleteSegment(apiName: string): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Publish one native API68 Segment by its record ID: one POST without a body, never resent
|
|
111
|
+
* after a reset, timeout, 429 or 503 (only a request that provably never left is repeated).
|
|
112
|
+
* @param {string} marketSegmentId Freshly read `1sg` record ID of the segment.
|
|
113
|
+
* @returns {Promise<unknown>} Untrusted acknowledgement (publishStatus, jobId), not the result.
|
|
114
|
+
*/
|
|
115
|
+
publishSegment(marketSegmentId: string): Promise<unknown>;
|
|
116
|
+
/**
|
|
117
|
+
* Run one read-only SOQL query (the core `/query` route, outside SSOT) over the command's own
|
|
118
|
+
* connection, without refresh or redirect; the first page only. Callers check `done`.
|
|
119
|
+
* @param {string} query SOQL built only from validated identifiers and static text.
|
|
120
|
+
* @returns {Promise<unknown>} Untrusted query response.
|
|
121
|
+
*/
|
|
122
|
+
soql(query: string): Promise<unknown>;
|
|
123
|
+
protected noRefreshReceiver(): AuthenticatedConnection;
|
|
124
|
+
private read;
|
|
125
|
+
protected send<T>(request: Parameters<Connection['request']>[0], receiver: AuthenticatedConnection, noContentResponse?: unknown): Promise<T>;
|
|
126
|
+
private sendOnce;
|
|
127
|
+
protected safeUrl(path: string): string;
|
|
128
|
+
}
|
|
129
|
+
export {};
|