@cerios/salesforce-sobjectly 0.0.0-stage → 1.0.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 +8 -0
- package/README.md +231 -2
- package/dist/cli.cjs +188 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +196 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/codegen-BgDgU2RR.cjs +1209 -0
- package/dist/codegen-BgDgU2RR.cjs.map +1 -0
- package/dist/codegen-CSx0WAtK.mjs +1110 -0
- package/dist/codegen-CSx0WAtK.mjs.map +1 -0
- package/dist/codegen.cjs +23 -0
- package/dist/codegen.d.cts +312 -0
- package/dist/codegen.d.mts +312 -0
- package/dist/codegen.mjs +10 -0
- package/dist/describe-Dj3J8o-x.d.cts +284 -0
- package/dist/describe-Dj3J8o-x.d.mts +284 -0
- package/dist/index.cjs +65 -0
- package/dist/index.d.cts +2451 -0
- package/dist/index.d.mts +2451 -0
- package/dist/index.mjs +33 -0
- package/dist/index.mjs.map +1 -0
- package/dist/sf-cli-CtWtdkJ0.mjs +3986 -0
- package/dist/sf-cli-CtWtdkJ0.mjs.map +1 -0
- package/dist/sf-cli-DEVZQTR7.cjs +4344 -0
- package/dist/sf-cli-DEVZQTR7.cjs.map +1 -0
- package/package.json +112 -5
- package/sobjectly.config.schema.json +147 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2451 @@
|
|
|
1
|
+
import { A as TransportRequest, C as SalesforceErrorCode, D as HttpMethod, E as AuthProvider, O as HttpTransport, S as KnownSalesforceErrorCode, T as AuthContext, _ as SalesforceGeolocation, a as FieldDescribe, b as UpsertResult, c as RecordTypeInfo, d as DeleteResult, f as GenericRecord, g as SalesforceAddress, h as RestError, i as DescribeSObjectResult, j as TransportResponse, k as StreamingTransportResponse, l as SObjectBasicInfo, m as RecordAttributes, n as DescribeGlobalResult, o as FieldType, p as QueryResponse, r as DescribeGlobalSObject, s as PicklistEntry, t as ChildRelationship, u as ApiVersion, v as SaveError, w as AccessToken, x as WithAttributes, y as SaveResult } from "./describe-Dj3J8o-x.mjs";
|
|
2
|
+
//#region src/http/connection.d.ts
|
|
3
|
+
type QueryParamValue = string | number | boolean | Date | null | undefined | readonly (string | number | boolean)[];
|
|
4
|
+
type ResponseType = "auto" | "json" | "text" | "binary";
|
|
5
|
+
interface RestRequest {
|
|
6
|
+
/** Defaults to `GET`. */
|
|
7
|
+
method?: HttpMethod;
|
|
8
|
+
/**
|
|
9
|
+
* - `"/limits"` or `"limits"`: relative to `/services/data/{apiVersion}`.
|
|
10
|
+
* - `"/services/apexrest/..."`: any path under `/services/` is used as-is on the instance.
|
|
11
|
+
* - `"https://..."`: absolute URLs must be on the instance origin or in `allowedOrigins`.
|
|
12
|
+
*/
|
|
13
|
+
path: string;
|
|
14
|
+
/** Query string parameters. Arrays are joined with commas; `undefined`/`null` are skipped. */
|
|
15
|
+
query?: Record<string, QueryParamValue>;
|
|
16
|
+
/** Objects are sent as JSON. Strings, `Uint8Array` and `URLSearchParams` are sent as-is. */
|
|
17
|
+
body?: unknown;
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
/** How to read the response body. `auto` (default) goes by `Content-Type`. */
|
|
20
|
+
responseType?: ResponseType;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
/** Overrides the client timeout for this request. */
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
/** Allow retries (see `RetryOptions`) for this request even when the method is not idempotent. */
|
|
25
|
+
retry?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface RestResponse<T> {
|
|
28
|
+
status: number;
|
|
29
|
+
headers: Headers;
|
|
30
|
+
data: T;
|
|
31
|
+
}
|
|
32
|
+
interface RetryOptions {
|
|
33
|
+
/** How many times to retry. Defaults to 2. */
|
|
34
|
+
retries?: number;
|
|
35
|
+
/** Statuses that trigger a retry. Defaults to 429, 502, 503 and 504. */
|
|
36
|
+
statusCodes?: number[];
|
|
37
|
+
/** Methods that are retried automatically. Defaults to `GET` and `HEAD`; others need `retry: true` per request. */
|
|
38
|
+
methods?: HttpMethod[];
|
|
39
|
+
/** Backoff base delay. Defaults to 500 ms. `Retry-After` takes precedence. */
|
|
40
|
+
baseDelayMs?: number;
|
|
41
|
+
/** Maximum delay between attempts. Defaults to 30 s. */
|
|
42
|
+
maxDelayMs?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Salesforce error codes that trigger a retry for **any** method, e.g. `["UNABLE_TO_LOCK_ROW"]`.
|
|
45
|
+
* Salesforce rolls the failed request back, so retrying is safe even for mutations.
|
|
46
|
+
*/
|
|
47
|
+
errorCodes?: SalesforceErrorCode[];
|
|
48
|
+
}
|
|
49
|
+
interface RequestEvent {
|
|
50
|
+
method: HttpMethod;
|
|
51
|
+
url: string;
|
|
52
|
+
/** Request headers with `Authorization` redacted. */
|
|
53
|
+
headers: Record<string, string>;
|
|
54
|
+
attempt: number;
|
|
55
|
+
}
|
|
56
|
+
interface ResponseEvent extends RequestEvent {
|
|
57
|
+
status: number;
|
|
58
|
+
durationMs: number;
|
|
59
|
+
/** Response headers without `set-cookie`. */
|
|
60
|
+
responseHeaders: Record<string, string>;
|
|
61
|
+
}
|
|
62
|
+
/** Observability hooks, e.g. for logging in test reports. Tokens are never passed to hooks. */
|
|
63
|
+
interface RequestHooks {
|
|
64
|
+
onRequest?(event: RequestEvent): void;
|
|
65
|
+
onResponse?(event: ResponseEvent): void;
|
|
66
|
+
}
|
|
67
|
+
interface ApiUsage {
|
|
68
|
+
used: number;
|
|
69
|
+
max: number;
|
|
70
|
+
}
|
|
71
|
+
interface ConnectionOptions {
|
|
72
|
+
auth: AuthProvider;
|
|
73
|
+
transport: HttpTransport;
|
|
74
|
+
/** The REST API version, e.g. `"v66.0"`. Required. */
|
|
75
|
+
apiVersion: ApiVersion;
|
|
76
|
+
/** Per-request timeout in milliseconds. Defaults to 120 000. Use `0` to disable. */
|
|
77
|
+
timeoutMs?: number;
|
|
78
|
+
/** Opt-in retries on 429/5xx for idempotent requests. Disabled by default. */
|
|
79
|
+
retry?: RetryOptions | boolean;
|
|
80
|
+
/** Extra origins (besides the instance URL) that absolute URLs may point to. */
|
|
81
|
+
allowedOrigins?: string[];
|
|
82
|
+
/** Headers sent with every request, e.g. `{ "Sforce-Call-Options": "client=my-app" }`. */
|
|
83
|
+
headers?: Record<string, string>;
|
|
84
|
+
hooks?: RequestHooks;
|
|
85
|
+
}
|
|
86
|
+
/** Low-level request executor: auth, URL resolution, encoding, timeouts, retries and errors. */
|
|
87
|
+
export declare class SalesforceConnection {
|
|
88
|
+
readonly apiVersion: ApiVersion;
|
|
89
|
+
private readonly _auth;
|
|
90
|
+
private readonly _transport;
|
|
91
|
+
private readonly _timeoutMs;
|
|
92
|
+
private readonly _retry;
|
|
93
|
+
private readonly _allowedOrigins;
|
|
94
|
+
private readonly _headers;
|
|
95
|
+
private readonly _hooks;
|
|
96
|
+
private _apiUsage;
|
|
97
|
+
constructor(options: ConnectionOptions);
|
|
98
|
+
/** API usage as reported by the last response's `Sforce-Limit-Info` header. */
|
|
99
|
+
get apiUsage(): ApiUsage | undefined;
|
|
100
|
+
get transport(): HttpTransport;
|
|
101
|
+
/** Returns the instance URL of the current token (authenticating if needed). */
|
|
102
|
+
instanceUrl(signal?: AbortSignal): Promise<string>;
|
|
103
|
+
/** Sends a request and returns the parsed body. Throws `SalesforceError` for non-2xx responses. */
|
|
104
|
+
request<T>(request: RestRequest): Promise<T>;
|
|
105
|
+
/** Sends a request and returns status, headers and the parsed body. */
|
|
106
|
+
send<T>(request: RestRequest): Promise<RestResponse<T>>;
|
|
107
|
+
/** Gets a token, bounded by the caller's signal and the request timeout. */
|
|
108
|
+
private getToken;
|
|
109
|
+
private reauthenticate;
|
|
110
|
+
/** Resolves a request path against the instance URL, enforcing the origin allowlist. */
|
|
111
|
+
resolveUrl(path: string, instanceUrl: string, query?: Record<string, QueryParamValue>): URL;
|
|
112
|
+
private sendOnce;
|
|
113
|
+
private prepare;
|
|
114
|
+
private afterResponse;
|
|
115
|
+
private toResult;
|
|
116
|
+
private errorFor;
|
|
117
|
+
/**
|
|
118
|
+
* Sends a GET request and returns the body as a stream of chunks, when the transport supports
|
|
119
|
+
* streaming (`fetchTransport` does). Returns `undefined` otherwise, so callers can fall back to
|
|
120
|
+
* `send`. Non-2xx responses throw `SalesforceError`; the request is re-authenticated once on 401.
|
|
121
|
+
*/
|
|
122
|
+
stream(request: RestRequest): Promise<StreamingTransportResponse | undefined>;
|
|
123
|
+
/**
|
|
124
|
+
* Opens a streamed response. The timeout only covers waiting for the response headers, so a
|
|
125
|
+
* consumer that reads a large body slowly is not cut off.
|
|
126
|
+
*/
|
|
127
|
+
private openStream;
|
|
128
|
+
private shouldRetry;
|
|
129
|
+
/**
|
|
130
|
+
* Network failures and per-attempt timeouts (the transport threw) are retried for idempotent
|
|
131
|
+
* requests when retries are enabled; a caller abort never is.
|
|
132
|
+
*/
|
|
133
|
+
private canRetryFailure;
|
|
134
|
+
private retryDelay;
|
|
135
|
+
private trackApiUsage;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/registry.d.ts
|
|
139
|
+
/** Field kinds the TypeScript type alone can't tell apart. */
|
|
140
|
+
type FieldKindName = "date" | "datetime" | "time" | "multipicklist";
|
|
141
|
+
/**
|
|
142
|
+
* The shape of one entry in a generated `SObjectRegistry`:
|
|
143
|
+
* - `read`: every field as returned by Salesforce;
|
|
144
|
+
* - `create` / `update`: the fields a client may set;
|
|
145
|
+
* - `parents`: child-to-parent relationship name -> parent sObject name (e.g. `{ Account: "Account" }`);
|
|
146
|
+
* - `children`: parent-to-child relationship name -> child sObject name (e.g. `{ Cases: "Case" }`);
|
|
147
|
+
* - `externalIds` (optional): fields usable for upsert / lookup by external id;
|
|
148
|
+
* - `fieldKinds` (optional): date, datetime, time and multipicklist fields;
|
|
149
|
+
* - `recordTypes` (optional): record type DeveloperNames;
|
|
150
|
+
* - `polymorphicParents` (optional): polymorphic lookups -> possible targets (e.g. `{ Owner: "Group" | "User" }`).
|
|
151
|
+
*/
|
|
152
|
+
interface SObjectRegistryEntry {
|
|
153
|
+
read: object;
|
|
154
|
+
create: object;
|
|
155
|
+
update: object;
|
|
156
|
+
parents: object;
|
|
157
|
+
children: object;
|
|
158
|
+
externalIds?: string;
|
|
159
|
+
fieldKinds?: object;
|
|
160
|
+
recordTypes?: string;
|
|
161
|
+
polymorphicParents?: object;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The registry used when no generated registry is supplied: any sObject name, any field.
|
|
165
|
+
* Run the `sobjectly` codegen to get a typed one.
|
|
166
|
+
*/
|
|
167
|
+
interface GenericRegistry {
|
|
168
|
+
[sobjectName: string]: {
|
|
169
|
+
read: GenericRecord;
|
|
170
|
+
create: GenericRecord;
|
|
171
|
+
update: GenericRecord;
|
|
172
|
+
parents: Record<string, string>;
|
|
173
|
+
children: Record<string, string>;
|
|
174
|
+
externalIds: string;
|
|
175
|
+
recordTypes: string;
|
|
176
|
+
polymorphicParents: Record<string, string>;
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/** Every sObject API name in registry `R`. */
|
|
180
|
+
type SObjectName<R> = keyof R & string;
|
|
181
|
+
/** The full record type of sObject `K`. */
|
|
182
|
+
type SObjectRecord<R, K extends SObjectName<R>> = R[K] extends {
|
|
183
|
+
read: infer T extends object;
|
|
184
|
+
} ? T : GenericRecord;
|
|
185
|
+
/** The create input type of sObject `K`. */
|
|
186
|
+
type SObjectCreateInput<R, K extends SObjectName<R>> = R[K] extends {
|
|
187
|
+
create: infer T extends object;
|
|
188
|
+
} ? T : GenericRecord;
|
|
189
|
+
/** The update input type of sObject `K`. */
|
|
190
|
+
type SObjectUpdateInput<R, K extends SObjectName<R>> = R[K] extends {
|
|
191
|
+
update: infer T extends object;
|
|
192
|
+
} ? T : GenericRecord;
|
|
193
|
+
/** Every field name of sObject `K`. */
|
|
194
|
+
type SObjectFieldName<R, K extends SObjectName<R>> = keyof SObjectRecord<R, K> & string;
|
|
195
|
+
/** Fields of `K` usable for upsert and lookup by external id (all fields when the registry doesn't say). */
|
|
196
|
+
type ExternalIdField<R, K extends SObjectName<R>> = R[K] extends {
|
|
197
|
+
externalIds: infer E extends string;
|
|
198
|
+
} ? E : SObjectFieldName<R, K>;
|
|
199
|
+
/** The kind of field `F` (`"date"`, `"datetime"`, `"time"`, `"multipicklist"`), or `undefined` for any other field. */
|
|
200
|
+
type FieldKind<R, K extends SObjectName<R>, F extends string> = R[K] extends {
|
|
201
|
+
fieldKinds: infer M;
|
|
202
|
+
} ? F extends keyof M ? M[F] : undefined : undefined;
|
|
203
|
+
/** Fields of `K` that are multi-select picklists (all fields when the registry doesn't say). */
|
|
204
|
+
type MultiPicklistField<R, K extends SObjectName<R>> = R[K] extends {
|
|
205
|
+
fieldKinds: infer M;
|
|
206
|
+
} ? { [F in keyof M & string]: M[F] extends "multipicklist" ? F : never; }[keyof M & string] : SObjectFieldName<R, K>;
|
|
207
|
+
/** Record type DeveloperNames of `K` (any string when the registry doesn't say). */
|
|
208
|
+
type RecordTypeName<R, K extends SObjectName<R>> = R[K] extends {
|
|
209
|
+
recordTypes: infer T extends string;
|
|
210
|
+
} ? T : string;
|
|
211
|
+
/** Child-to-parent relationship names of sObject `K` (e.g. `"Account"` on `Contact`). */
|
|
212
|
+
type ParentRelationshipName<R, K extends SObjectName<R>> = R[K] extends {
|
|
213
|
+
parents: infer P;
|
|
214
|
+
} ? keyof P & string : never;
|
|
215
|
+
/** The sObject name a parent relationship points to. */
|
|
216
|
+
type ParentSObjectName<R, K extends SObjectName<R>, Rel extends string> = R[K] extends {
|
|
217
|
+
parents: infer P;
|
|
218
|
+
} ? Rel extends keyof P ? P[Rel] & SObjectName<R> : never : never;
|
|
219
|
+
/** Polymorphic relationship names of sObject `K` (e.g. `"Owner"` on `Case`, `"What"` on `Task`). */
|
|
220
|
+
type PolymorphicRelationshipName<R, K extends SObjectName<R>> = R[K] extends {
|
|
221
|
+
polymorphicParents: infer P;
|
|
222
|
+
} ? keyof P & string : never;
|
|
223
|
+
/** The possible target sObject names of a polymorphic relationship. */
|
|
224
|
+
type PolymorphicTargets<R, K extends SObjectName<R>, Rel extends string> = R[K] extends {
|
|
225
|
+
polymorphicParents: infer P;
|
|
226
|
+
} ? Rel extends keyof P ? P[Rel] & string : never : never;
|
|
227
|
+
/** Parent-to-child relationship names of sObject `K` (e.g. `"Contacts"` on `Account`). */
|
|
228
|
+
type ChildRelationshipName<R, K extends SObjectName<R>> = R[K] extends {
|
|
229
|
+
children: infer C;
|
|
230
|
+
} ? keyof C & string : never;
|
|
231
|
+
/** The sObject name a child relationship points to. */
|
|
232
|
+
type ChildSObjectName<R, K extends SObjectName<R>, Rel extends string> = R[K] extends {
|
|
233
|
+
children: infer C;
|
|
234
|
+
} ? Rel extends keyof C ? C[Rel] & SObjectName<R> : never : never;
|
|
235
|
+
/** `PreviousDepth[n]` is the depth left after one more hop; depth 1 allows exactly one hop. */
|
|
236
|
+
type PreviousDepth = [never, never, 1, 2, 3, 4];
|
|
237
|
+
/**
|
|
238
|
+
* Child-to-parent paths from `K`, e.g. `"Account"` or `"Account.Owner"`. `Depth` caps the number
|
|
239
|
+
* of hops (default 3) to keep compile times low on large registries; Salesforce allows 5.
|
|
240
|
+
*/
|
|
241
|
+
type ParentPath<R, K extends SObjectName<R>, Depth extends number = 3> = [Depth] extends [never] ? never : { [Rel in ParentRelationshipName<R, K>]: Rel | `${Rel}.${ParentPath<R, ParentSObjectName<R, K, Rel>, PreviousDepth[Depth]>}`; }[ParentRelationshipName<R, K>];
|
|
242
|
+
/** The sObject name at the end of a parent path. */
|
|
243
|
+
type ParentPathTarget<R, K extends SObjectName<R>, P extends string> = P extends `${infer H}.${infer T}` ? ParentPathTarget<R, ParentSObjectName<R, K, H>, T> : ParentSObjectName<R, K, P>;
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region src/types/api.d.ts
|
|
246
|
+
interface ApiVersionInfo {
|
|
247
|
+
label: string;
|
|
248
|
+
url: string;
|
|
249
|
+
version: string;
|
|
250
|
+
}
|
|
251
|
+
interface LimitInfo {
|
|
252
|
+
Max: number;
|
|
253
|
+
Remaining: number;
|
|
254
|
+
/** Some limits nest per-app sub-limits, e.g. `DailyApiRequests["Salesforce CLI"]`. */
|
|
255
|
+
[subLimit: string]: number | {
|
|
256
|
+
Max: number;
|
|
257
|
+
Remaining: number;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** The `/limits` response, keyed by limit name (e.g. `DailyApiRequests`, `DataStorageMB`). */
|
|
261
|
+
type KnownOrgLimit = "ActiveScratchOrgs" | "ConcurrentAsyncGetReportInstances" | "ConcurrentSyncReportRuns" | "DailyAnalyticsDataflowJobExecutions" | "DailyApiRequests" | "DailyAsyncApexExecutions" | "DailyAsyncApexTests" | "DailyBulkApiBatches" | "DailyBulkV2QueryFileStorageMB" | "DailyBulkV2QueryJobs" | "DailyDeliveredPlatformEvents" | "DailyDurableGenericStreamingApiEvents" | "DailyDurableStreamingApiEvents" | "DailyGenericStreamingApiEvents" | "DailyScratchOrgs" | "DailyStandardVolumePlatformEvents" | "DailyStreamingApiEvents" | "DailyWorkflowEmails" | "DataStorageMB" | "FileStorageMB" | "HourlyAsyncReportRuns" | "HourlyDashboardRefreshes" | "HourlyDashboardResults" | "HourlyDashboardStatuses" | "HourlyLongTermIdMapping" | "HourlyPublishedPlatformEvents" | "HourlyPublishedStandardVolumePlatformEvents" | "HourlyShortTermIdMapping" | "HourlySyncReportRuns" | "HourlyTimeBasedWorkflow" | "MassEmail" | "MonthlyPlatformEventsUsageEntitlement" | "Package2VersionCreates" | "PermissionTypes" | "SingleEmail" | "StreamingApiConcurrentClients";
|
|
262
|
+
/** The `/limits` response, keyed by limit name. Well-known names autocomplete; others are allowed. */
|
|
263
|
+
type OrgLimits = { [Name in KnownOrgLimit]?: LimitInfo; } & Record<string, LimitInfo>;
|
|
264
|
+
interface QueryPlan {
|
|
265
|
+
cardinality: number;
|
|
266
|
+
fields: string[];
|
|
267
|
+
leadingOperationType: "Index" | "Other" | "Sharing" | "TableScan";
|
|
268
|
+
notes: {
|
|
269
|
+
description: string;
|
|
270
|
+
fields: string[];
|
|
271
|
+
tableEnumOrId: string;
|
|
272
|
+
}[];
|
|
273
|
+
/** Above 1 means the query is not selective. */
|
|
274
|
+
relativeCost: number;
|
|
275
|
+
sobjectCardinality: number;
|
|
276
|
+
sobjectType: string;
|
|
277
|
+
}
|
|
278
|
+
interface RecordCountResult {
|
|
279
|
+
sObjects: {
|
|
280
|
+
count: number;
|
|
281
|
+
name: string;
|
|
282
|
+
}[];
|
|
283
|
+
}
|
|
284
|
+
interface DeletedRecordsResult {
|
|
285
|
+
deletedRecords: {
|
|
286
|
+
id: string;
|
|
287
|
+
deletedDate: string;
|
|
288
|
+
}[];
|
|
289
|
+
earliestDateAvailable: string;
|
|
290
|
+
latestDateCovered: string;
|
|
291
|
+
}
|
|
292
|
+
interface UpdatedRecordsResult {
|
|
293
|
+
ids: string[];
|
|
294
|
+
latestDateCovered: string;
|
|
295
|
+
}
|
|
296
|
+
interface SearchResult<T = GenericRecord> {
|
|
297
|
+
searchRecords: WithAttributes<T>[];
|
|
298
|
+
metadata?: {
|
|
299
|
+
entityMetadata: {
|
|
300
|
+
entityName: string;
|
|
301
|
+
fieldMetadata: {
|
|
302
|
+
name: string;
|
|
303
|
+
label: string;
|
|
304
|
+
}[];
|
|
305
|
+
}[];
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
interface ParameterizedSearchSObject {
|
|
309
|
+
name: string;
|
|
310
|
+
fields?: string[];
|
|
311
|
+
limit?: number;
|
|
312
|
+
where?: string;
|
|
313
|
+
orderBy?: string;
|
|
314
|
+
}
|
|
315
|
+
interface ParameterizedSearchRequest {
|
|
316
|
+
q: string;
|
|
317
|
+
fields?: string[];
|
|
318
|
+
sobjects?: ParameterizedSearchSObject[];
|
|
319
|
+
in?: "ALL" | "NAME" | "EMAIL" | "PHONE" | "SIDEBAR";
|
|
320
|
+
overallLimit?: number;
|
|
321
|
+
defaultLimit?: number;
|
|
322
|
+
offset?: number;
|
|
323
|
+
division?: string;
|
|
324
|
+
dataCategories?: {
|
|
325
|
+
groupName: string;
|
|
326
|
+
operator: string;
|
|
327
|
+
categories: string[];
|
|
328
|
+
}[];
|
|
329
|
+
networkIds?: string[];
|
|
330
|
+
metadata?: "LABELS";
|
|
331
|
+
snippet?: string;
|
|
332
|
+
spellCorrection?: boolean;
|
|
333
|
+
}
|
|
334
|
+
interface SearchSuggestionsResult<T = GenericRecord> {
|
|
335
|
+
autoSuggestResults: WithAttributes<T>[];
|
|
336
|
+
hasMoreResults: boolean;
|
|
337
|
+
}
|
|
338
|
+
type CompositeMethod = "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
|
339
|
+
interface CompositeSubrequest {
|
|
340
|
+
method: CompositeMethod;
|
|
341
|
+
/** Must start with `/services/data/vXX.X/`. */
|
|
342
|
+
url: string;
|
|
343
|
+
referenceId: string;
|
|
344
|
+
body?: unknown;
|
|
345
|
+
httpHeaders?: Record<string, string>;
|
|
346
|
+
}
|
|
347
|
+
interface CompositeSubrequestResult<T = unknown> {
|
|
348
|
+
body: T | RestError[] | null;
|
|
349
|
+
httpHeaders: Record<string, string>;
|
|
350
|
+
httpStatusCode: number;
|
|
351
|
+
referenceId: string;
|
|
352
|
+
}
|
|
353
|
+
interface CompositeBatchSubrequest {
|
|
354
|
+
method: CompositeMethod;
|
|
355
|
+
/** Relative to the API version, e.g. `"sobjects/Account/001..."`. */
|
|
356
|
+
url: string;
|
|
357
|
+
richInput?: unknown;
|
|
358
|
+
binaryPartName?: string;
|
|
359
|
+
binaryPartNameAlias?: string;
|
|
360
|
+
}
|
|
361
|
+
interface CompositeBatchResult {
|
|
362
|
+
hasErrors: boolean;
|
|
363
|
+
results: {
|
|
364
|
+
statusCode: number;
|
|
365
|
+
result: unknown;
|
|
366
|
+
}[];
|
|
367
|
+
}
|
|
368
|
+
interface TreeSaveResult {
|
|
369
|
+
hasErrors: boolean;
|
|
370
|
+
results: {
|
|
371
|
+
referenceId: string;
|
|
372
|
+
id?: string;
|
|
373
|
+
errors?: SaveError[];
|
|
374
|
+
}[];
|
|
375
|
+
}
|
|
376
|
+
interface ActionSummary {
|
|
377
|
+
label: string;
|
|
378
|
+
name: string;
|
|
379
|
+
type: string;
|
|
380
|
+
url?: string;
|
|
381
|
+
}
|
|
382
|
+
interface ActionParameterDescribe {
|
|
383
|
+
name: string;
|
|
384
|
+
label: string;
|
|
385
|
+
type: string;
|
|
386
|
+
required: boolean;
|
|
387
|
+
description: string | null;
|
|
388
|
+
maxOccurs: number;
|
|
389
|
+
sobjectType: string | null;
|
|
390
|
+
picklistValues: unknown[] | null;
|
|
391
|
+
[key: string]: unknown;
|
|
392
|
+
}
|
|
393
|
+
interface ActionDescribe {
|
|
394
|
+
name: string;
|
|
395
|
+
label: string;
|
|
396
|
+
type: string;
|
|
397
|
+
description: string | null;
|
|
398
|
+
category?: string;
|
|
399
|
+
inputs: ActionParameterDescribe[];
|
|
400
|
+
outputs: ActionParameterDescribe[];
|
|
401
|
+
[key: string]: unknown;
|
|
402
|
+
}
|
|
403
|
+
interface InvocableActionResult<TOutput = GenericRecord> {
|
|
404
|
+
actionName: string;
|
|
405
|
+
errors: SaveError[] | null;
|
|
406
|
+
isSuccess: boolean;
|
|
407
|
+
outputValues: TOutput | null;
|
|
408
|
+
sortOrder?: number;
|
|
409
|
+
version?: number;
|
|
410
|
+
invocationId?: string | null;
|
|
411
|
+
}
|
|
412
|
+
interface ExecuteAnonymousResult {
|
|
413
|
+
line: number;
|
|
414
|
+
column: number;
|
|
415
|
+
compiled: boolean;
|
|
416
|
+
success: boolean;
|
|
417
|
+
compileProblem: string | null;
|
|
418
|
+
exceptionMessage: string | null;
|
|
419
|
+
exceptionStackTrace: string | null;
|
|
420
|
+
}
|
|
421
|
+
interface RunTestsRequest {
|
|
422
|
+
/** Comma-separated class ids, or use `tests`. */
|
|
423
|
+
classids?: string;
|
|
424
|
+
suiteids?: string;
|
|
425
|
+
maxFailedTests?: number;
|
|
426
|
+
testLevel?: "RunSpecifiedTests" | "RunLocalTests" | "RunAllTestsInOrg";
|
|
427
|
+
skipCodeCoverage?: boolean;
|
|
428
|
+
tests?: {
|
|
429
|
+
classId?: string;
|
|
430
|
+
className?: string;
|
|
431
|
+
testMethods?: string[];
|
|
432
|
+
}[];
|
|
433
|
+
}
|
|
434
|
+
type BulkIngestOperation = "insert" | "update" | "upsert" | "delete" | "hardDelete";
|
|
435
|
+
type BulkQueryOperation = "query" | "queryAll";
|
|
436
|
+
type BulkJobState = "Open" | "UploadComplete" | "InProgress" | "JobComplete" | "Failed" | "Aborted";
|
|
437
|
+
type BulkColumnDelimiter = "COMMA" | "TAB" | "PIPE" | "SEMICOLON" | "CARET" | "BACKQUOTE";
|
|
438
|
+
type BulkLineEnding = "LF" | "CRLF";
|
|
439
|
+
interface BulkJobInfo {
|
|
440
|
+
id: string;
|
|
441
|
+
operation: BulkIngestOperation | BulkQueryOperation;
|
|
442
|
+
object: string;
|
|
443
|
+
createdById: string;
|
|
444
|
+
createdDate: string;
|
|
445
|
+
systemModstamp: string;
|
|
446
|
+
state: BulkJobState;
|
|
447
|
+
concurrencyMode: string;
|
|
448
|
+
contentType: "CSV";
|
|
449
|
+
/** A number, e.g. `66.0`. */
|
|
450
|
+
apiVersion: number;
|
|
451
|
+
jobType?: string;
|
|
452
|
+
lineEnding: BulkLineEnding;
|
|
453
|
+
columnDelimiter: BulkColumnDelimiter;
|
|
454
|
+
contentUrl?: string;
|
|
455
|
+
externalIdFieldName?: string;
|
|
456
|
+
assignmentRuleId?: string;
|
|
457
|
+
numberRecordsProcessed?: number;
|
|
458
|
+
numberRecordsFailed?: number;
|
|
459
|
+
retries?: number;
|
|
460
|
+
totalProcessingTime?: number;
|
|
461
|
+
apiActiveProcessingTime?: number;
|
|
462
|
+
apexProcessingTime?: number;
|
|
463
|
+
errorMessage?: string;
|
|
464
|
+
isPkChunkingSupported?: boolean;
|
|
465
|
+
[key: string]: unknown;
|
|
466
|
+
}
|
|
467
|
+
interface OAuthTokenResponse {
|
|
468
|
+
access_token: string;
|
|
469
|
+
instance_url: string;
|
|
470
|
+
id?: string;
|
|
471
|
+
token_type?: string;
|
|
472
|
+
/** Epoch milliseconds, as a string. */
|
|
473
|
+
issued_at?: string;
|
|
474
|
+
signature?: string;
|
|
475
|
+
scope?: string;
|
|
476
|
+
refresh_token?: string;
|
|
477
|
+
id_token?: string;
|
|
478
|
+
api_instance_url?: string;
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region src/resources/actions.d.ts
|
|
482
|
+
interface InvokeOptions {
|
|
483
|
+
/** Throw a `SalesforceSaveError` when any input reported `isSuccess: false`. Defaults to `true`. */
|
|
484
|
+
throwOnError?: boolean;
|
|
485
|
+
signal?: AbortSignal;
|
|
486
|
+
}
|
|
487
|
+
/** The custom action types of `/actions/custom/{type}`. */
|
|
488
|
+
type CustomActionType = "flow" | "apex" | "quickAction" | "emailAlert" | "submit" | "externalService" | (string & {});
|
|
489
|
+
/** Invocable actions (`/actions/standard`, `/actions/custom`), including autolaunched Flows and `@InvocableMethod` Apex. */
|
|
490
|
+
export declare class ActionsApi {
|
|
491
|
+
private readonly _connection;
|
|
492
|
+
constructor(_connection: SalesforceConnection);
|
|
493
|
+
listStandard(options?: {
|
|
494
|
+
signal?: AbortSignal;
|
|
495
|
+
}): Promise<ActionSummary[]>;
|
|
496
|
+
listCustom(type: CustomActionType, options?: {
|
|
497
|
+
signal?: AbortSignal;
|
|
498
|
+
}): Promise<ActionSummary[]>;
|
|
499
|
+
describeStandard(name: string, options?: {
|
|
500
|
+
signal?: AbortSignal;
|
|
501
|
+
}): Promise<ActionDescribe>;
|
|
502
|
+
describeCustom(type: CustomActionType, name: string, options?: {
|
|
503
|
+
signal?: AbortSignal;
|
|
504
|
+
}): Promise<ActionDescribe>;
|
|
505
|
+
/** Invokes a standard action, e.g. `"emailSimple"` or `"chatterPost"`. One result per input. */
|
|
506
|
+
invokeStandard<TInput extends object = GenericRecord, TOutput = GenericRecord>(name: string, inputs: readonly TInput[], options?: InvokeOptions): Promise<InvocableActionResult<TOutput>[]>;
|
|
507
|
+
/** Invokes a custom action of `type`. One result per input. */
|
|
508
|
+
invokeCustom<TInput extends object = GenericRecord, TOutput = GenericRecord>(type: CustomActionType, name: string, inputs: readonly TInput[], options?: InvokeOptions): Promise<InvocableActionResult<TOutput>[]>;
|
|
509
|
+
/**
|
|
510
|
+
* Runs an autolaunched Flow by API name. Input keys are the Flow's input variable names;
|
|
511
|
+
* `outputValues` holds its output variables plus `Flow__InterviewStatus`.
|
|
512
|
+
*/
|
|
513
|
+
invokeFlow<TInput extends object = GenericRecord, TOutput = GenericRecord>(apiName: string, inputs: readonly TInput[], options?: InvokeOptions): Promise<InvocableActionResult<TOutput>[]>;
|
|
514
|
+
/** Invokes an `@InvocableMethod` of an Apex class (`Namespace__ClassName` for managed packages). */
|
|
515
|
+
invokeApex<TInput extends object = GenericRecord, TOutput = GenericRecord>(className: string, inputs: readonly TInput[], options?: InvokeOptions): Promise<InvocableActionResult<TOutput>[]>;
|
|
516
|
+
private invoke;
|
|
517
|
+
}
|
|
518
|
+
//#endregion
|
|
519
|
+
//#region src/types/platform.d.ts
|
|
520
|
+
interface ApprovalProcessInfo {
|
|
521
|
+
description: string | null;
|
|
522
|
+
id: string;
|
|
523
|
+
name: string;
|
|
524
|
+
object: string;
|
|
525
|
+
sortOrder: number;
|
|
526
|
+
}
|
|
527
|
+
interface ApprovalResult {
|
|
528
|
+
actorIds: string[];
|
|
529
|
+
entityId: string;
|
|
530
|
+
errors: SaveError[] | null;
|
|
531
|
+
instanceId: string;
|
|
532
|
+
instanceStatus: "Approved" | "Rejected" | "Removed" | "Pending" | (string & {});
|
|
533
|
+
/** Ids of the new work items (normalised from `newWorkitemIds` / `newWorkItemIds`). */
|
|
534
|
+
newWorkitemIds: string[];
|
|
535
|
+
success: boolean;
|
|
536
|
+
}
|
|
537
|
+
interface PendingApprovalWorkItem {
|
|
538
|
+
/** The ProcessInstanceWorkitem id (`04i...`), used to approve or reject. */
|
|
539
|
+
id: string;
|
|
540
|
+
actorId: string;
|
|
541
|
+
processInstanceId: string;
|
|
542
|
+
targetObjectId: string;
|
|
543
|
+
}
|
|
544
|
+
interface QuickActionSummary {
|
|
545
|
+
actionEnumOrId: string;
|
|
546
|
+
label: string;
|
|
547
|
+
name: string;
|
|
548
|
+
type: string;
|
|
549
|
+
urls?: Record<string, string>;
|
|
550
|
+
}
|
|
551
|
+
interface QuickActionDescribe {
|
|
552
|
+
name: string;
|
|
553
|
+
label: string;
|
|
554
|
+
type: string;
|
|
555
|
+
targetSobjectType: string | null;
|
|
556
|
+
targetParentField: string | null;
|
|
557
|
+
targetRecordTypeId: string | null;
|
|
558
|
+
contextSobjectType: string | null;
|
|
559
|
+
defaultValues: {
|
|
560
|
+
field: string;
|
|
561
|
+
defaultValue: unknown;
|
|
562
|
+
}[] | null;
|
|
563
|
+
layout: unknown;
|
|
564
|
+
[key: string]: unknown;
|
|
565
|
+
}
|
|
566
|
+
interface QuickActionResult {
|
|
567
|
+
success: boolean;
|
|
568
|
+
created: boolean;
|
|
569
|
+
id?: string;
|
|
570
|
+
ids: string[];
|
|
571
|
+
contextId?: string;
|
|
572
|
+
feedItemIds: string[] | null;
|
|
573
|
+
successMessage: string | null;
|
|
574
|
+
errors: SaveError[];
|
|
575
|
+
}
|
|
576
|
+
interface UiFieldInfo {
|
|
577
|
+
apiName: string;
|
|
578
|
+
label: string;
|
|
579
|
+
dataType: string;
|
|
580
|
+
required: boolean;
|
|
581
|
+
createable: boolean;
|
|
582
|
+
updateable: boolean;
|
|
583
|
+
custom: boolean;
|
|
584
|
+
calculated: boolean;
|
|
585
|
+
nameField: boolean;
|
|
586
|
+
reference: boolean;
|
|
587
|
+
referenceToInfos: {
|
|
588
|
+
apiName: string;
|
|
589
|
+
nameFields: string[];
|
|
590
|
+
}[];
|
|
591
|
+
relationshipName: string | null;
|
|
592
|
+
controllerName: string | null;
|
|
593
|
+
length: number;
|
|
594
|
+
precision: number;
|
|
595
|
+
scale: number;
|
|
596
|
+
[key: string]: unknown;
|
|
597
|
+
}
|
|
598
|
+
interface UiRecordTypeInfo {
|
|
599
|
+
available: boolean;
|
|
600
|
+
defaultRecordTypeMapping: boolean;
|
|
601
|
+
master: boolean;
|
|
602
|
+
name: string;
|
|
603
|
+
recordTypeId: string;
|
|
604
|
+
}
|
|
605
|
+
interface ObjectInfo {
|
|
606
|
+
apiName: string;
|
|
607
|
+
label: string;
|
|
608
|
+
labelPlural: string;
|
|
609
|
+
keyPrefix: string | null;
|
|
610
|
+
custom: boolean;
|
|
611
|
+
createable: boolean;
|
|
612
|
+
updateable: boolean;
|
|
613
|
+
deletable: boolean;
|
|
614
|
+
queryable: boolean;
|
|
615
|
+
nameFields: string[];
|
|
616
|
+
/** The master record type (`012000000000000AAA`) when there is no other default. */
|
|
617
|
+
defaultRecordTypeId: string | null;
|
|
618
|
+
recordTypeInfos: Record<string, UiRecordTypeInfo>;
|
|
619
|
+
dependentFields: Record<string, unknown>;
|
|
620
|
+
fields: Record<string, UiFieldInfo>;
|
|
621
|
+
childRelationships: unknown[];
|
|
622
|
+
[key: string]: unknown;
|
|
623
|
+
}
|
|
624
|
+
interface PicklistValue {
|
|
625
|
+
label: string;
|
|
626
|
+
value: string;
|
|
627
|
+
/** Indexes into the controlling field's `controllerValues`. */
|
|
628
|
+
validFor: number[];
|
|
629
|
+
attributes: Record<string, unknown> | null;
|
|
630
|
+
}
|
|
631
|
+
interface PicklistValues {
|
|
632
|
+
controllerValues: Record<string, number>;
|
|
633
|
+
defaultValue: PicklistValue | null;
|
|
634
|
+
values: PicklistValue[];
|
|
635
|
+
url: string;
|
|
636
|
+
eTag?: string;
|
|
637
|
+
}
|
|
638
|
+
interface UiFieldValue<T = unknown> {
|
|
639
|
+
displayValue: string | null;
|
|
640
|
+
value: T;
|
|
641
|
+
}
|
|
642
|
+
/** A UI API record. `fields` is typed when the record was loaded with typed field names. */
|
|
643
|
+
interface UiRecord<TFields extends object = Record<string, UiFieldValue>> {
|
|
644
|
+
apiName: string;
|
|
645
|
+
id: string;
|
|
646
|
+
fields: TFields;
|
|
647
|
+
childRelationships: Record<string, unknown>;
|
|
648
|
+
lastModifiedById: string | null;
|
|
649
|
+
lastModifiedDate: string | null;
|
|
650
|
+
recordTypeId: string | null;
|
|
651
|
+
recordTypeInfo: UiRecordTypeInfo | null;
|
|
652
|
+
systemModstamp: string | null;
|
|
653
|
+
eTag?: string;
|
|
654
|
+
weakEtag?: number;
|
|
655
|
+
}
|
|
656
|
+
interface UiLayoutComponent {
|
|
657
|
+
apiName: string | null;
|
|
658
|
+
componentType: "Field" | "Canvas" | "CustomLink" | "EmptySpace" | "ReportChart" | "VisualforcePage" | (string & {});
|
|
659
|
+
label: string;
|
|
660
|
+
}
|
|
661
|
+
interface UiLayout {
|
|
662
|
+
id: string;
|
|
663
|
+
layoutType: string;
|
|
664
|
+
mode: string;
|
|
665
|
+
objectApiName: string;
|
|
666
|
+
recordTypeId: string;
|
|
667
|
+
sections: {
|
|
668
|
+
collapsible: boolean;
|
|
669
|
+
columns: number;
|
|
670
|
+
heading: string;
|
|
671
|
+
id: string;
|
|
672
|
+
rows: number;
|
|
673
|
+
useHeading: boolean;
|
|
674
|
+
layoutRows: {
|
|
675
|
+
layoutItems: {
|
|
676
|
+
editableForNew: boolean;
|
|
677
|
+
editableForUpdate: boolean;
|
|
678
|
+
label: string;
|
|
679
|
+
required: boolean;
|
|
680
|
+
layoutComponents: UiLayoutComponent[];
|
|
681
|
+
}[];
|
|
682
|
+
}[];
|
|
683
|
+
}[];
|
|
684
|
+
[key: string]: unknown;
|
|
685
|
+
}
|
|
686
|
+
interface ReportSummary {
|
|
687
|
+
id: string;
|
|
688
|
+
name: string;
|
|
689
|
+
url: string;
|
|
690
|
+
describeUrl: string;
|
|
691
|
+
instancesUrl: string;
|
|
692
|
+
}
|
|
693
|
+
interface ReportFilter {
|
|
694
|
+
column: string;
|
|
695
|
+
operator: "equals" | "notEqual" | "lessThan" | "greaterThan" | "lessOrEqual" | "greaterOrEqual" | "contains" | "notContain" | "startsWith" | "includes" | "excludes" | "within" | (string & {});
|
|
696
|
+
value: string;
|
|
697
|
+
isRunPageEditable?: boolean;
|
|
698
|
+
}
|
|
699
|
+
interface ReportMetadata {
|
|
700
|
+
id: string;
|
|
701
|
+
name: string;
|
|
702
|
+
developerName: string;
|
|
703
|
+
reportFormat: "TABULAR" | "SUMMARY" | "MATRIX" | "MULTI_BLOCK";
|
|
704
|
+
detailColumns: string[];
|
|
705
|
+
aggregates: string[];
|
|
706
|
+
reportFilters: ReportFilter[];
|
|
707
|
+
reportBooleanFilter: string | null;
|
|
708
|
+
groupingsDown: {
|
|
709
|
+
name: string;
|
|
710
|
+
dateGranularity: string;
|
|
711
|
+
sortOrder: string;
|
|
712
|
+
}[];
|
|
713
|
+
groupingsAcross: {
|
|
714
|
+
name: string;
|
|
715
|
+
dateGranularity: string;
|
|
716
|
+
sortOrder: string;
|
|
717
|
+
}[];
|
|
718
|
+
hasDetailRows: boolean;
|
|
719
|
+
[key: string]: unknown;
|
|
720
|
+
}
|
|
721
|
+
interface ReportDataCell {
|
|
722
|
+
label: string;
|
|
723
|
+
value: unknown;
|
|
724
|
+
}
|
|
725
|
+
interface ReportFact {
|
|
726
|
+
aggregates: ReportDataCell[];
|
|
727
|
+
rows?: {
|
|
728
|
+
dataCells: ReportDataCell[];
|
|
729
|
+
}[];
|
|
730
|
+
}
|
|
731
|
+
interface ReportExtendedMetadata {
|
|
732
|
+
aggregateColumnInfo: Record<string, {
|
|
733
|
+
label: string;
|
|
734
|
+
dataType: string;
|
|
735
|
+
}>;
|
|
736
|
+
detailColumnInfo: Record<string, {
|
|
737
|
+
label: string;
|
|
738
|
+
dataType: string;
|
|
739
|
+
}>;
|
|
740
|
+
groupingColumnInfo: Record<string, {
|
|
741
|
+
label: string;
|
|
742
|
+
dataType: string;
|
|
743
|
+
groupingLevel: number;
|
|
744
|
+
}>;
|
|
745
|
+
}
|
|
746
|
+
interface ReportResult {
|
|
747
|
+
attributes: {
|
|
748
|
+
describeUrl: string;
|
|
749
|
+
instancesUrl: string;
|
|
750
|
+
reportId: string;
|
|
751
|
+
reportName: string;
|
|
752
|
+
type: string;
|
|
753
|
+
};
|
|
754
|
+
allData: boolean;
|
|
755
|
+
hasDetailRows: boolean;
|
|
756
|
+
/** Keys like `"T!T"` (grand total), `"0!T"` (first grouping) or `"0_1!0"` (matrix cell). */
|
|
757
|
+
factMap: Record<string, ReportFact>;
|
|
758
|
+
groupingsDown: {
|
|
759
|
+
groupings: unknown[];
|
|
760
|
+
};
|
|
761
|
+
groupingsAcross: {
|
|
762
|
+
groupings: unknown[];
|
|
763
|
+
};
|
|
764
|
+
reportMetadata: ReportMetadata;
|
|
765
|
+
reportExtendedMetadata: ReportExtendedMetadata;
|
|
766
|
+
[key: string]: unknown;
|
|
767
|
+
}
|
|
768
|
+
interface ReportDescribe {
|
|
769
|
+
reportMetadata: ReportMetadata;
|
|
770
|
+
reportExtendedMetadata: ReportExtendedMetadata;
|
|
771
|
+
reportTypeMetadata: Record<string, unknown>;
|
|
772
|
+
}
|
|
773
|
+
interface ReportInstance {
|
|
774
|
+
id: string;
|
|
775
|
+
status: "New" | "Running" | "Success" | "Error";
|
|
776
|
+
url: string;
|
|
777
|
+
ownerId: string;
|
|
778
|
+
hasDetailRows: boolean;
|
|
779
|
+
queryable: boolean;
|
|
780
|
+
requestDate: string;
|
|
781
|
+
completionDate: string | null;
|
|
782
|
+
}
|
|
783
|
+
//#endregion
|
|
784
|
+
//#region src/resources/query.d.ts
|
|
785
|
+
declare const queryCursorRecord: unique symbol;
|
|
786
|
+
/** A `nextRecordsUrl` that remembers the record type of the query it belongs to. */
|
|
787
|
+
type QueryCursor<TRecord> = string & {
|
|
788
|
+
readonly [queryCursorRecord]: TRecord;
|
|
789
|
+
};
|
|
790
|
+
/** One page of query results. Pass `nextRecordsUrl` to `queryMore` to fetch the next page. */
|
|
791
|
+
interface QueryResult<TRecord> {
|
|
792
|
+
records: TRecord[];
|
|
793
|
+
totalSize: number;
|
|
794
|
+
done: boolean;
|
|
795
|
+
nextRecordsUrl?: QueryCursor<TRecord>;
|
|
796
|
+
}
|
|
797
|
+
interface QueryOptions {
|
|
798
|
+
/** Use `/queryAll`, which also returns deleted and archived records. */
|
|
799
|
+
includeDeleted?: boolean;
|
|
800
|
+
/** Preferred page size (200–2000), sent as `Sforce-Query-Options: batchSize=n`. Not guaranteed. */
|
|
801
|
+
batchSize?: number;
|
|
802
|
+
signal?: AbortSignal;
|
|
803
|
+
}
|
|
804
|
+
/** Runs SOQL against `/query`/`/queryAll` (or the Tooling API equivalents) and follows pages. */
|
|
805
|
+
export declare class QueryApi {
|
|
806
|
+
private readonly _connection;
|
|
807
|
+
private readonly _basePath;
|
|
808
|
+
constructor(_connection: SalesforceConnection, _basePath?: "" | "/tooling");
|
|
809
|
+
/** Returns the first page of results. */
|
|
810
|
+
page<TRecord>(soql: string, options?: QueryOptions): Promise<QueryResult<TRecord>>;
|
|
811
|
+
/** Sends a query that is too long for a URL as a composite subrequest (still one API call). */
|
|
812
|
+
private viaComposite;
|
|
813
|
+
/** Fetches the page a cursor points to. */
|
|
814
|
+
more<TRecord>(cursor: QueryCursor<TRecord>, options?: Pick<QueryOptions, "batchSize" | "signal">): Promise<QueryResult<TRecord>>;
|
|
815
|
+
/** Yields every record, fetching further pages on demand. */
|
|
816
|
+
iterate<TRecord>(soql: string, options?: QueryOptions): AsyncGenerator<TRecord, void, undefined>;
|
|
817
|
+
/** Fetches every page and returns all records. */
|
|
818
|
+
collect<TRecord>(soql: string, options?: QueryOptions): Promise<TRecord[]>;
|
|
819
|
+
}
|
|
820
|
+
//#endregion
|
|
821
|
+
//#region src/resources/approvals.d.ts
|
|
822
|
+
interface SubmitOptions {
|
|
823
|
+
comments?: string;
|
|
824
|
+
/** Required when the process step lets the submitter choose the approver. */
|
|
825
|
+
nextApproverIds?: string[];
|
|
826
|
+
/** The approval process to use (API name or id); otherwise the first matching process runs. */
|
|
827
|
+
processDefinitionNameOrId?: string;
|
|
828
|
+
skipEntryCriteria?: boolean;
|
|
829
|
+
/** Submit on behalf of this user id. */
|
|
830
|
+
submitterId?: string;
|
|
831
|
+
/** Throw a `SalesforceSaveError` when Salesforce reports `success: false`. Defaults to `true`. */
|
|
832
|
+
throwOnError?: boolean;
|
|
833
|
+
signal?: AbortSignal;
|
|
834
|
+
}
|
|
835
|
+
interface DecisionOptions {
|
|
836
|
+
comments?: string;
|
|
837
|
+
nextApproverIds?: string[];
|
|
838
|
+
/** Throw a `SalesforceSaveError` when Salesforce reports `success: false`. Defaults to `true`. */
|
|
839
|
+
throwOnError?: boolean;
|
|
840
|
+
signal?: AbortSignal;
|
|
841
|
+
}
|
|
842
|
+
/** Approval processes (`/process/approvals`): submit records, approve and reject pending steps. */
|
|
843
|
+
export declare class ApprovalsApi {
|
|
844
|
+
private readonly _connection;
|
|
845
|
+
private readonly _queries;
|
|
846
|
+
constructor(_connection: SalesforceConnection, _queries: QueryApi);
|
|
847
|
+
/** Lists the approval processes per sObject. */
|
|
848
|
+
list(options?: {
|
|
849
|
+
signal?: AbortSignal;
|
|
850
|
+
}): Promise<Record<string, ApprovalProcessInfo[]>>;
|
|
851
|
+
/** Submits a record for approval. */
|
|
852
|
+
submit(recordId: string, options?: SubmitOptions): Promise<ApprovalResult>;
|
|
853
|
+
/**
|
|
854
|
+
* Approves a pending step. Pass the work item id (`04i...`), or the record id to approve its
|
|
855
|
+
* single pending work item.
|
|
856
|
+
*/
|
|
857
|
+
approve(recordOrWorkitemId: string, options?: DecisionOptions): Promise<ApprovalResult>;
|
|
858
|
+
/** Rejects a pending step. Accepts a work item id or a record id, like `approve`. */
|
|
859
|
+
reject(recordOrWorkitemId: string, options?: DecisionOptions): Promise<ApprovalResult>;
|
|
860
|
+
/** The pending work items of a record (visible to the current user). */
|
|
861
|
+
pending(recordId: string, options?: {
|
|
862
|
+
signal?: AbortSignal;
|
|
863
|
+
}): Promise<PendingApprovalWorkItem[]>;
|
|
864
|
+
private resolveWorkitem;
|
|
865
|
+
private process;
|
|
866
|
+
/**
|
|
867
|
+
* Sends one approval request. Failures such as `NO_APPLICABLE_PROCESS` or `ALREADY_IN_PROCESS`
|
|
868
|
+
* come back as HTTP 400 with an error array; they become an unsuccessful result.
|
|
869
|
+
*/
|
|
870
|
+
private send;
|
|
871
|
+
}
|
|
872
|
+
//#endregion
|
|
873
|
+
//#region src/soql/escape.d.ts
|
|
874
|
+
declare const soqlLiteralBrand: unique symbol;
|
|
875
|
+
/** A value that is inserted into SOQL verbatim. Create one with {@link soqlLiteral}. */
|
|
876
|
+
interface SoqlLiteral {
|
|
877
|
+
readonly [soqlLiteralBrand]: true;
|
|
878
|
+
readonly sql: string;
|
|
879
|
+
}
|
|
880
|
+
/** A value accepted by the typed `where` helpers. */
|
|
881
|
+
type SoqlValue = string | number | boolean | null | Date | SoqlLiteral;
|
|
882
|
+
/**
|
|
883
|
+
* Marks `sql` as a raw SOQL literal, e.g. a date literal such as `soqlLiteral("LAST_N_DAYS:30")`
|
|
884
|
+
* or `soqlLiteral("TODAY")`. Never pass untrusted input.
|
|
885
|
+
*/
|
|
886
|
+
export declare function soqlLiteral(sql: string): SoqlLiteral;
|
|
887
|
+
/**
|
|
888
|
+
* Formats a value as a SOQL literal. Strings are quoted with backslashes, quotes and control
|
|
889
|
+
* characters escaped, which prevents SOQL injection for values from user or external input.
|
|
890
|
+
* In `LIKE` patterns `%` and `_` stay wildcards; use {@link soqlLike} to match them literally.
|
|
891
|
+
*
|
|
892
|
+
* A `Date` becomes a DateTime literal (`yyyy-MM-ddTHH:mm:ssZ`, UTC), which only works against
|
|
893
|
+
* DateTime fields. Use {@link soqlDate} for Date-only fields (e.g. `Birthdate`).
|
|
894
|
+
*/
|
|
895
|
+
export declare function soqlEscape(value: SoqlValue): string;
|
|
896
|
+
/**
|
|
897
|
+
* Formats a `Date` as a Date-only literal (`yyyy-MM-dd`), for use against Date fields. Uses the
|
|
898
|
+
* UTC date unless `local` is set, in which case the date in the local time zone is used.
|
|
899
|
+
*/
|
|
900
|
+
export declare function soqlEscapeDateOnly(value: Date, options?: {
|
|
901
|
+
local?: boolean;
|
|
902
|
+
}): string;
|
|
903
|
+
/**
|
|
904
|
+
* A Date-only literal for the typed `where` helpers, e.g. `where("Birthdate", ">", soqlDate(d))`.
|
|
905
|
+
* Accepts a `Date` or a `yyyy-MM-dd` string. A `Date` uses its UTC date; pass `{ local: true }`
|
|
906
|
+
* to use the date in the local time zone (e.g. for `new Date(2026, 0, 31)`).
|
|
907
|
+
*/
|
|
908
|
+
export declare function soqlDate(value: Date | string, options?: {
|
|
909
|
+
local?: boolean;
|
|
910
|
+
}): SoqlLiteral;
|
|
911
|
+
/** Date literals without a number, e.g. `TODAY` or `THIS_FISCAL_QUARTER`. */
|
|
912
|
+
type SoqlFixedDateLiteral = "YESTERDAY" | "TODAY" | "TOMORROW" | "LAST_WEEK" | "THIS_WEEK" | "NEXT_WEEK" | "LAST_MONTH" | "THIS_MONTH" | "NEXT_MONTH" | "LAST_90_DAYS" | "NEXT_90_DAYS" | "THIS_QUARTER" | "LAST_QUARTER" | "NEXT_QUARTER" | "THIS_YEAR" | "LAST_YEAR" | "NEXT_YEAR" | "THIS_FISCAL_QUARTER" | "LAST_FISCAL_QUARTER" | "NEXT_FISCAL_QUARTER" | "THIS_FISCAL_YEAR" | "LAST_FISCAL_YEAR" | "NEXT_FISCAL_YEAR";
|
|
913
|
+
/** Date literals that take a number, e.g. `LAST_N_DAYS:30`. */
|
|
914
|
+
type SoqlRelativeDateLiteral = "LAST_N_DAYS" | "NEXT_N_DAYS" | "N_DAYS_AGO" | "LAST_N_WEEKS" | "NEXT_N_WEEKS" | "N_WEEKS_AGO" | "LAST_N_MONTHS" | "NEXT_N_MONTHS" | "N_MONTHS_AGO" | "LAST_N_QUARTERS" | "NEXT_N_QUARTERS" | "N_QUARTERS_AGO" | "LAST_N_YEARS" | "NEXT_N_YEARS" | "N_YEARS_AGO" | "LAST_N_FISCAL_QUARTERS" | "NEXT_N_FISCAL_QUARTERS" | "N_FISCAL_QUARTERS_AGO" | "LAST_N_FISCAL_YEARS" | "NEXT_N_FISCAL_YEARS" | "N_FISCAL_YEARS_AGO";
|
|
915
|
+
/**
|
|
916
|
+
* A typed SOQL date literal for date and datetime fields:
|
|
917
|
+
* `soqlDateLiteral("TODAY")`, `soqlDateLiteral("LAST_N_DAYS", 30)`.
|
|
918
|
+
*/
|
|
919
|
+
export declare function soqlDateLiteral(name: SoqlFixedDateLiteral): SoqlLiteral;
|
|
920
|
+
export declare function soqlDateLiteral(name: SoqlRelativeDateLiteral, n: number): SoqlLiteral;
|
|
921
|
+
/**
|
|
922
|
+
* Escapes a term for a SOSL `FIND {...}` clause by backslash-escaping the reserved characters
|
|
923
|
+
* `? & | ! { } [ ] ( ) ^ ~ * : \ " ' + -`.
|
|
924
|
+
*/
|
|
925
|
+
export declare function soslEscape(term: string): string;
|
|
926
|
+
//#endregion
|
|
927
|
+
//#region src/soql/types.d.ts
|
|
928
|
+
type SoqlComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=";
|
|
929
|
+
type SoqlOperator = SoqlComparisonOperator | "LIKE";
|
|
930
|
+
/** Any non-null value the builder can render. */
|
|
931
|
+
type SoqlScalar = string | number | boolean | Date | SoqlLiteral;
|
|
932
|
+
type NonNull<T> = Exclude<T, null | undefined>;
|
|
933
|
+
/** The TypeScript type of field `F` on `K` (`unknown` for untyped registries). */
|
|
934
|
+
type FieldType$1<R, K extends SObjectName<R>, F extends string> = F extends keyof SObjectRecord<R, K> ? SObjectRecord<R, K>[F] : unknown;
|
|
935
|
+
type IsUnknown<T> = unknown extends T ? true : false;
|
|
936
|
+
/**
|
|
937
|
+
* The non-null values `where` accepts for field `F`:
|
|
938
|
+
* - date fields: `soqlDate(date)` or a date literal (a quoted string or `Date` would be invalid SOQL);
|
|
939
|
+
* - datetime fields: a `Date` or a literal;
|
|
940
|
+
* - time fields: a literal;
|
|
941
|
+
* - number fields: a number; boolean fields: a boolean;
|
|
942
|
+
* - string and picklist fields: their value type (picklist unions stay checked).
|
|
943
|
+
*/
|
|
944
|
+
type SoqlFieldValue<R, K extends SObjectName<R>, F extends string> = FieldKind<R, K, F> extends "date" ? SoqlLiteral : FieldKind<R, K, F> extends "datetime" ? Date | SoqlLiteral : FieldKind<R, K, F> extends "time" ? SoqlLiteral : IsUnknown<FieldType$1<R, K, F>> extends true ? SoqlScalar : NonNull<FieldType$1<R, K, F>> extends number ? number | SoqlLiteral : NonNull<FieldType$1<R, K, F>> extends boolean ? boolean : NonNull<FieldType$1<R, K, F>> extends string ? NonNull<FieldType$1<R, K, F>> | SoqlLiteral : SoqlScalar;
|
|
945
|
+
/** The operators that make sense for field `F` (`LIKE` only on text, `=`/`!=` only on booleans). */
|
|
946
|
+
type SoqlOperatorFor<R, K extends SObjectName<R>, F extends string> = FieldKind<R, K, F> extends "multipicklist" ? "=" | "!=" : FieldKind<R, K, F> extends "date" | "datetime" | "time" ? SoqlComparisonOperator : IsUnknown<FieldType$1<R, K, F>> extends true ? SoqlOperator : NonNull<FieldType$1<R, K, F>> extends boolean ? "=" | "!=" : NonNull<FieldType$1<R, K, F>> extends number ? SoqlComparisonOperator : SoqlOperator;
|
|
947
|
+
/**
|
|
948
|
+
* The value `where(field, operator, value)` accepts. `null` works with `!=` on any field
|
|
949
|
+
* (`Id != null`) and with `=` only on nillable fields.
|
|
950
|
+
*/
|
|
951
|
+
type SoqlWhereValue<R, K extends SObjectName<R>, F extends string, O extends string> = SoqlFieldValue<R, K, F> | (O extends "!=" ? null : O extends "=" ? (null extends FieldType$1<R, K, F> ? null : never) : never);
|
|
952
|
+
/** The sObject at the end of a parent path, e.g. `"User"` for `"Account.Owner"` from `Contact`. */
|
|
953
|
+
type PathTarget<R, K extends SObjectName<R>, P extends string> = ParentPathTarget<R, K, P> & SObjectName<R>;
|
|
954
|
+
/** Nests a selection under a dotted parent path: `"Account.Owner"` -> `{ Account: { Owner: V } }`. */
|
|
955
|
+
type NestPath<P extends string, V> = P extends `${infer Head}.${infer Tail}` ? { [Key in Head]: WithAttributes<NestPath<Tail, V>> | null; } : { [Key in P]: WithAttributes<V> | null; };
|
|
956
|
+
/**
|
|
957
|
+
* Fields available on a polymorphic relationship without TYPEOF (the "Name" object), e.g.
|
|
958
|
+
* `Owner.Name` or `What.Type`.
|
|
959
|
+
*/
|
|
960
|
+
interface PolymorphicName {
|
|
961
|
+
Id: string;
|
|
962
|
+
Name: string | null;
|
|
963
|
+
Type: string;
|
|
964
|
+
Alias: string | null;
|
|
965
|
+
Email: string | null;
|
|
966
|
+
FirstName: string | null;
|
|
967
|
+
LastName: string | null;
|
|
968
|
+
IsActive: boolean;
|
|
969
|
+
Phone: string | null;
|
|
970
|
+
Title: string | null;
|
|
971
|
+
Username: string | null;
|
|
972
|
+
}
|
|
973
|
+
type PolymorphicNameField = Extract<keyof PolymorphicName, string>;
|
|
974
|
+
/** A record whose `attributes.type` is narrowed to `T`, so unions can be discriminated. */
|
|
975
|
+
type TypedRecord<T extends string, V> = V & {
|
|
976
|
+
attributes: {
|
|
977
|
+
type: T;
|
|
978
|
+
url?: string;
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
/** Fields selectable for `T` inside TYPEOF: its fields when `T` is in the registry, else the Name fields. */
|
|
982
|
+
type TypeOfField<R, T extends string> = T extends SObjectName<R> ? SObjectFieldName<R, T> : PolymorphicNameField;
|
|
983
|
+
type TypeOfPick<R, T extends string, F extends string> = T extends SObjectName<R> ? Pick<SObjectRecord<R, T>, Extract<F, keyof SObjectRecord<R, T>>> : Pick<PolymorphicName, Extract<F, PolymorphicNameField>>;
|
|
984
|
+
//#endregion
|
|
985
|
+
//#region src/soql/query-builder.d.ts
|
|
986
|
+
type SoqlDirection = "ASC" | "DESC";
|
|
987
|
+
type SoqlNullOrder = "NULLS FIRST" | "NULLS LAST";
|
|
988
|
+
declare const noSelectionBrand: unique symbol;
|
|
989
|
+
/** Marker for "nothing selected yet", which queries `FIELDS(ALL)` and returns the full record. */
|
|
990
|
+
type NoSelection = {
|
|
991
|
+
readonly [noSelectionBrand]: true;
|
|
992
|
+
};
|
|
993
|
+
type SelectedRecord<R, K extends SObjectName<R>, S extends object> = S extends NoSelection ? SObjectRecord<R, K> : S;
|
|
994
|
+
type ExplicitSelection<S extends object> = S extends NoSelection ? object : S;
|
|
995
|
+
type NumericField<R, K extends SObjectName<R>> = string extends keyof SObjectRecord<R, K> ? string : { [P in SObjectFieldName<R, K>]: Exclude<SObjectRecord<R, K>[P], null | undefined> extends number ? P : never; }[SObjectFieldName<R, K>];
|
|
996
|
+
/** The value of a parent-to-child subquery field. Salesforce returns `null` when there are no child rows. */
|
|
997
|
+
type SoqlChildQueryResult<TRecord> = {
|
|
998
|
+
records: WithAttributes<TRecord>[];
|
|
999
|
+
totalSize: number;
|
|
1000
|
+
done: boolean;
|
|
1001
|
+
nextRecordsUrl?: string;
|
|
1002
|
+
};
|
|
1003
|
+
/** The record type a query built with `SoqlQueryBuilder<R, K, S>` returns. */
|
|
1004
|
+
type SoqlQueryRecord<R, K extends SObjectName<R>, S extends object> = WithAttributes<SelectedRecord<R, K, S>>;
|
|
1005
|
+
/**
|
|
1006
|
+
* Builds a `TYPEOF` expression for a polymorphic relationship. Each `when` narrows the result to a
|
|
1007
|
+
* record whose `attributes.type` is that sObject; `else` covers the remaining types with Name fields.
|
|
1008
|
+
*/
|
|
1009
|
+
export declare class TypeOfBuilder<R extends object, Remaining extends string, Result = never> {
|
|
1010
|
+
private readonly _whens;
|
|
1011
|
+
private readonly _types;
|
|
1012
|
+
private _else;
|
|
1013
|
+
/** `WHEN type THEN fields`. */
|
|
1014
|
+
when<T extends Remaining, F extends TypeOfField<R, T>>(sobject: T, firstField: F, ...additionalFields: F[]): TypeOfBuilder<R, Exclude<Remaining, T>, Result | TypedRecord<T, TypeOfPick<R, T, F>>>;
|
|
1015
|
+
/** `ELSE fields`: the Name fields for every type without a `when`. */
|
|
1016
|
+
else<F extends PolymorphicNameField>(firstField: F, ...additionalFields: F[]): TypeOfBuilder<R, never, Result | TypedRecord<Remaining, Pick<PolymorphicName, F>>>;
|
|
1017
|
+
/** @internal */
|
|
1018
|
+
toSoql(relationship: string): string;
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Narrows a record by its `attributes.type`, e.g. the union returned for a `selectTypeOf` field.
|
|
1022
|
+
* TypeScript doesn't narrow on nested properties, so `record.attributes.type === "Account"` alone
|
|
1023
|
+
* won't narrow; this guard does:
|
|
1024
|
+
*
|
|
1025
|
+
* ```ts
|
|
1026
|
+
* if (isSObjectType(task.What, "Account")) task.What.Phone;
|
|
1027
|
+
* ```
|
|
1028
|
+
*/
|
|
1029
|
+
export declare function isSObjectType<U extends {
|
|
1030
|
+
attributes: {
|
|
1031
|
+
type: string;
|
|
1032
|
+
};
|
|
1033
|
+
}, T extends U["attributes"]["type"]>(record: U | null | undefined, type: T): record is Extract<U, {
|
|
1034
|
+
attributes: {
|
|
1035
|
+
type: T;
|
|
1036
|
+
};
|
|
1037
|
+
}>;
|
|
1038
|
+
type TypeOfResult<Remaining extends string, Result> = Result | ([Remaining] extends [never] ? never : TypedRecord<Remaining, object>);
|
|
1039
|
+
/**
|
|
1040
|
+
* A type-safe, fluent SOQL builder. Field names are checked against the registry, values are
|
|
1041
|
+
* checked per field type, and the selected fields narrow the record type the query returns.
|
|
1042
|
+
*
|
|
1043
|
+
* Create one with `client.soql("Account")` or `soqlFor<SObjectRegistry>()("Account")`.
|
|
1044
|
+
*
|
|
1045
|
+
* - `select` for direct fields;
|
|
1046
|
+
* - `selectRelated("Account.Owner", ...)` for child-to-parent paths (up to 3 hops typed);
|
|
1047
|
+
* - `selectChild` for parent-to-child subqueries;
|
|
1048
|
+
* - `selectPolymorphic` / `selectTypeOf` for polymorphic lookups such as `Owner` or `What`;
|
|
1049
|
+
* - `selectRaw` / `whereRaw` for anything else (escape values with `soqlEscape`).
|
|
1050
|
+
*
|
|
1051
|
+
* Builders are **mutable**: every method changes the builder and returns it. To branch off a
|
|
1052
|
+
* shared base query, `clone()` it first:
|
|
1053
|
+
*
|
|
1054
|
+
* ```ts
|
|
1055
|
+
* const base = sf.soql("Account").select("Id");
|
|
1056
|
+
* const energy = base.clone().where("Industry", "=", "Energy");
|
|
1057
|
+
* const banking = base.clone().where("Industry", "=", "Banking");
|
|
1058
|
+
* ```
|
|
1059
|
+
*/
|
|
1060
|
+
export declare class SoqlQueryBuilder<R extends object, K extends SObjectName<R>, S extends object = NoSelection> {
|
|
1061
|
+
private readonly _fromClause;
|
|
1062
|
+
private _fields;
|
|
1063
|
+
private _conditions;
|
|
1064
|
+
private _groupBy;
|
|
1065
|
+
private _having;
|
|
1066
|
+
private _orderBy;
|
|
1067
|
+
private _limit;
|
|
1068
|
+
private _offset;
|
|
1069
|
+
private _withUserMode;
|
|
1070
|
+
private _forClause;
|
|
1071
|
+
private _usesTypeOf;
|
|
1072
|
+
private _countAll;
|
|
1073
|
+
private _usesAggregates;
|
|
1074
|
+
private constructor();
|
|
1075
|
+
/** Returns an independent copy, so the original can be reused as a base for other queries. */
|
|
1076
|
+
clone(): SoqlQueryBuilder<R, K, S>;
|
|
1077
|
+
/** Starts a query on `sobjectName`. Prefer `client.soql()` or `soqlFor<R>()`, which infer `R`. */
|
|
1078
|
+
static from<R extends object, K extends SObjectName<R>>(sobjectName: K): SoqlQueryBuilder<R, K>;
|
|
1079
|
+
/** The sObject (or child relationship, in a subquery) this query selects from. */
|
|
1080
|
+
get sobjectName(): string;
|
|
1081
|
+
/** `true` when the query contains `TYPEOF`, which Bulk API, semi-joins and GROUP BY don't support. */
|
|
1082
|
+
get usesTypeOf(): boolean;
|
|
1083
|
+
/** Adds fields to the select list. The result type is narrowed to the selected fields. */
|
|
1084
|
+
select<F extends SObjectFieldName<R, K>>(firstField: F, ...additionalFields: F[]): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Pick<SObjectRecord<R, K>, F>>;
|
|
1085
|
+
/** Escape hatch for select expressions the typed helpers can't express. The result gains an index signature. */
|
|
1086
|
+
selectRaw(firstExpression: string, ...additionalExpressions: string[]): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Record<string, unknown>>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Selects fields through a child-to-parent path, e.g. `selectRelated("Account", "Name")` or
|
|
1089
|
+
* `selectRelated("Account.Owner", "Email")` from `Contact`. Each level is `| null` in the result.
|
|
1090
|
+
*/
|
|
1091
|
+
selectRelated<P extends ParentPath<R, K>, F extends SObjectFieldName<R, PathTarget<R, K, P>>>(path: P, firstField: F, ...additionalFields: F[]): SoqlQueryBuilder<R, K, ExplicitSelection<S> & NestPath<P, Pick<SObjectRecord<R, PathTarget<R, K, P>>, F>>>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Selects Name fields of a polymorphic lookup without TYPEOF, e.g. `selectPolymorphic("Owner", "Name")`
|
|
1094
|
+
* from `Case`. `attributes.type` tells which sObject it is.
|
|
1095
|
+
*/
|
|
1096
|
+
selectPolymorphic<Rel extends PolymorphicRelationshipName<R, K>, F extends PolymorphicNameField>(relationship: Rel, firstField: F, ...additionalFields: F[]): SoqlQueryBuilder<R, K, ExplicitSelection<S> & { [P in Rel]: TypedRecord<PolymorphicTargets<R, K, Rel>, Pick<PolymorphicName, F>> | null; }>;
|
|
1097
|
+
/**
|
|
1098
|
+
* Adds a `TYPEOF` expression for a polymorphic lookup. The result is a union discriminated on
|
|
1099
|
+
* `attributes.type`:
|
|
1100
|
+
*
|
|
1101
|
+
* ```ts
|
|
1102
|
+
* sf.soql("Task").select("Id").selectTypeOf("What", (t) =>
|
|
1103
|
+
* t.when("Account", "Phone").when("Opportunity", "Amount").else("Name"),
|
|
1104
|
+
* );
|
|
1105
|
+
* ```
|
|
1106
|
+
*/
|
|
1107
|
+
selectTypeOf<Rel extends PolymorphicRelationshipName<R, K>, Remaining extends string, Result>(relationship: Rel, build: (typeOf: TypeOfBuilder<R, PolymorphicTargets<R, K, Rel>>) => TypeOfBuilder<R, Remaining, Result>): SoqlQueryBuilder<R, K, ExplicitSelection<S> & { [P in Rel]: TypeOfResult<Remaining, Result> | null; }>;
|
|
1108
|
+
/**
|
|
1109
|
+
* Adds a parent-to-child subquery, e.g. `selectChild("Contacts", c => c.select("Id", "Email"))`
|
|
1110
|
+
* from `Account` builds `(SELECT Id, Email FROM Contacts)`.
|
|
1111
|
+
*/
|
|
1112
|
+
selectChild<Rel extends ChildRelationshipName<R, K>, ChildSelection extends object, ChildName extends ChildSObjectName<R, K, Rel> = ChildSObjectName<R, K, Rel>>(relationship: Rel, build: (sub: SoqlQueryBuilder<R, ChildName>) => SoqlQueryBuilder<R, ChildName, ChildSelection>): SoqlQueryBuilder<R, K, ExplicitSelection<S> & { [P in Rel]: SoqlChildQueryResult<SelectedRecord<R, ChildName, ChildSelection>> | null; }>;
|
|
1113
|
+
/** `SELECT COUNT() FROM ...`: the count is in the result's `totalSize`; `records` is empty. */
|
|
1114
|
+
count(): SoqlQueryBuilder<R, K, ExplicitSelection<S>>;
|
|
1115
|
+
/** `COUNT(field) alias`. */
|
|
1116
|
+
count<F extends SObjectFieldName<R, K>, A extends string>(field: F, alias: A): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Record<A, number>>;
|
|
1117
|
+
countDistinct<F extends SObjectFieldName<R, K>, A extends string>(field: F, alias: A): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Record<A, number>>;
|
|
1118
|
+
sum<F extends NumericField<R, K>, A extends string>(field: F, alias: A): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Record<A, number | null>>;
|
|
1119
|
+
avg<F extends NumericField<R, K>, A extends string>(field: F, alias: A): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Record<A, number | null>>;
|
|
1120
|
+
min<F extends SObjectFieldName<R, K>, A extends string>(field: F, alias: A): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Record<A, SObjectRecord<R, K>[F] | null>>;
|
|
1121
|
+
max<F extends SObjectFieldName<R, K>, A extends string>(field: F, alias: A): SoqlQueryBuilder<R, K, ExplicitSelection<S> & Record<A, SObjectRecord<R, K>[F] | null>>;
|
|
1122
|
+
/**
|
|
1123
|
+
* Adds `field operator value`. The value is escaped and type-checked against the field:
|
|
1124
|
+
* date fields take `soqlDate()`/`soqlDateLiteral()`, datetime fields a `Date` or literal,
|
|
1125
|
+
* `LIKE` only works on text, and `null` only on nillable fields with `=`/`!=`.
|
|
1126
|
+
*/
|
|
1127
|
+
where<F extends SObjectFieldName<R, K>, O extends SoqlOperatorFor<R, K, F>>(field: F, operator: O, value: SoqlWhereValue<R, K, F, O>): this;
|
|
1128
|
+
/**
|
|
1129
|
+
* Adds a raw condition, wrapped in parentheses so an `OR` inside it can't change how it combines
|
|
1130
|
+
* with other conditions. Escape interpolated values with `soqlEscape`.
|
|
1131
|
+
*/
|
|
1132
|
+
whereRaw(conditionSql: string): this;
|
|
1133
|
+
/** `field IN (...)` with a list of values or a single-field semi-join subquery. */
|
|
1134
|
+
whereIn<F extends SObjectFieldName<R, K>, SK extends SObjectName<R>, SubSelection extends object>(field: F, values: readonly SoqlFieldValue<R, K, F>[] | SoqlQueryBuilder<R, SK, SubSelection>): this;
|
|
1135
|
+
/** `field NOT IN (...)` with a list of values or a single-field anti-join subquery. */
|
|
1136
|
+
whereNotIn<F extends SObjectFieldName<R, K>, SK extends SObjectName<R>, SubSelection extends object>(field: F, values: readonly SoqlFieldValue<R, K, F>[] | SoqlQueryBuilder<R, SK, SubSelection>): this;
|
|
1137
|
+
/**
|
|
1138
|
+
* `field INCLUDES (...)` for multi-select picklists. Each item matches when all its values are
|
|
1139
|
+
* selected: `whereIncludes("Interests__c", [["Golf", "Tennis"], "Chess"])` builds
|
|
1140
|
+
* `INCLUDES ('Golf;Tennis', 'Chess')`.
|
|
1141
|
+
*/
|
|
1142
|
+
whereIncludes(field: MultiPicklistField<R, K>, values: readonly (string | readonly string[])[]): this;
|
|
1143
|
+
/** `field EXCLUDES (...)` for multi-select picklists; items combine like `whereIncludes`. */
|
|
1144
|
+
whereExcludes(field: MultiPicklistField<R, K>, values: readonly (string | readonly string[])[]): this;
|
|
1145
|
+
/**
|
|
1146
|
+
* Wraps conditions in parentheses, joined by `join` (default `OR`). Groups nest, so
|
|
1147
|
+
* `(A OR B) AND (C OR (D AND E))` is expressible. Top-level conditions are always joined with AND.
|
|
1148
|
+
*/
|
|
1149
|
+
whereGroup(build: (group: SoqlQueryBuilder<R, K>) => void, join?: "AND" | "OR"): this;
|
|
1150
|
+
/** Negates a group of conditions: `whereNot(g => g.where("Type", "=", "Prospect"))` builds `(NOT (Type = 'Prospect'))`. */
|
|
1151
|
+
whereNot(build: (group: SoqlQueryBuilder<R, K>) => void, join?: "AND" | "OR"): this;
|
|
1152
|
+
/**
|
|
1153
|
+
* Condition on a parent field, e.g. `whereRelated("Account", "Name", "=", "Acme")` or
|
|
1154
|
+
* `whereRelated("Account.Owner", "IsActive", "=", true)` from `Contact`.
|
|
1155
|
+
*/
|
|
1156
|
+
whereRelated<P extends ParentPath<R, K>, F extends SObjectFieldName<R, PathTarget<R, K, P>>, O extends SoqlOperatorFor<R, PathTarget<R, K, P>, F>>(path: P, field: F, operator: O, value: SoqlWhereValue<R, PathTarget<R, K, P>, F, O>): this;
|
|
1157
|
+
groupBy(...fields: SObjectFieldName<R, K>[]): this;
|
|
1158
|
+
/** Raw `HAVING` condition, e.g. `"COUNT(Id) > 1"`, wrapped in parentheses. */
|
|
1159
|
+
havingRaw(conditionSql: string): this;
|
|
1160
|
+
havingGroup(build: (group: SoqlQueryBuilder<R, K>) => void, join?: "AND" | "OR"): this;
|
|
1161
|
+
orderBy(field: SObjectFieldName<R, K>, direction?: SoqlDirection, nullOrder?: SoqlNullOrder): this;
|
|
1162
|
+
/** Orders by a parent field, e.g. `orderByRelated("Account", "Name", "DESC")`. */
|
|
1163
|
+
orderByRelated<P extends ParentPath<R, K>>(path: P, field: SObjectFieldName<R, PathTarget<R, K, P>>, direction?: SoqlDirection, nullOrder?: SoqlNullOrder): this;
|
|
1164
|
+
/** Raw `ORDER BY` item, e.g. `"Account.Name DESC"`. */
|
|
1165
|
+
orderByRaw(expression: string): this;
|
|
1166
|
+
/** Adds `WITH USER_MODE`, so sharing rules and field-level security of the running user apply. */
|
|
1167
|
+
withUserMode(): this;
|
|
1168
|
+
limit(count: number): this;
|
|
1169
|
+
offset(count: number): this;
|
|
1170
|
+
/** Adds `FOR VIEW`, `FOR REFERENCE` or `FOR UPDATE`. */
|
|
1171
|
+
for(clause: "VIEW" | "REFERENCE" | "UPDATE"): this;
|
|
1172
|
+
/** Returns the SOQL string. Throws when the query is invalid. */
|
|
1173
|
+
build(): string;
|
|
1174
|
+
toString(): string;
|
|
1175
|
+
private cast;
|
|
1176
|
+
/** Adds fields, skipping duplicates. Field names are case-insensitive in SOQL. */
|
|
1177
|
+
private addFields;
|
|
1178
|
+
private groupConditions;
|
|
1179
|
+
/** A group callback may only add conditions (or HAVING conditions); anything else would be lost. */
|
|
1180
|
+
private assertOnly;
|
|
1181
|
+
private whereSet;
|
|
1182
|
+
private whereMultiPicklist;
|
|
1183
|
+
private selectAggregate;
|
|
1184
|
+
private assertValidQuery;
|
|
1185
|
+
}
|
|
1186
|
+
/** Returns a factory for builders bound to registry `R`: `const soql = soqlFor<SObjectRegistry>(); soql("Account")`. */
|
|
1187
|
+
export declare function soqlFor<R extends object = GenericRegistry>(): <K extends SObjectName<R>>(sobjectName: K) => SoqlQueryBuilder<R, K>;
|
|
1188
|
+
//#endregion
|
|
1189
|
+
//#region src/resources/bulk.d.ts
|
|
1190
|
+
type Scalar = string | number | boolean | null | undefined;
|
|
1191
|
+
type FlatKeys<T> = { [P in keyof T & string]: P extends "attributes" ? never : NonNullable<T[P]> extends Scalar ? P : NonNullable<T[P]> extends object ? `${P}.${Exclude<keyof NonNullable<T[P]>, "attributes"> & string}` : P; }[keyof T & string];
|
|
1192
|
+
/**
|
|
1193
|
+
* A row of a Bulk API CSV result. All values are strings; relationship fields become dotted
|
|
1194
|
+
* columns (e.g. `"Account.Name"`).
|
|
1195
|
+
*/
|
|
1196
|
+
type BulkCsvRecord<T> = string extends keyof T ? Record<string, string> : { [P in FlatKeys<T>]: string; };
|
|
1197
|
+
/**
|
|
1198
|
+
* A record to ingest: any subset of the sObject's fields (`null` clears a field), plus dotted
|
|
1199
|
+
* relationship columns for parent lookups by external id (e.g. `"Account.External_Id__c"`).
|
|
1200
|
+
*/
|
|
1201
|
+
type BulkIngestRecord<R extends object, K extends SObjectName<R>> = { [F in SObjectFieldName<R, K>]?: SObjectRecord<R, K>[F] | Date | null; } & {
|
|
1202
|
+
[relationshipColumn: `${string}.${string}`]: string | number | undefined;
|
|
1203
|
+
};
|
|
1204
|
+
interface WaitOptions {
|
|
1205
|
+
/** Delay between status checks. Defaults to 2 000 ms. */
|
|
1206
|
+
pollIntervalMs?: number;
|
|
1207
|
+
/** Give up after this many milliseconds. Defaults to 10 minutes. */
|
|
1208
|
+
timeoutMs?: number;
|
|
1209
|
+
signal?: AbortSignal;
|
|
1210
|
+
}
|
|
1211
|
+
interface BulkIngestJobOptions<K extends string = string> {
|
|
1212
|
+
object: K;
|
|
1213
|
+
operation: BulkIngestOperation;
|
|
1214
|
+
/** Required for `upsert`. */
|
|
1215
|
+
externalIdFieldName?: string;
|
|
1216
|
+
assignmentRuleId?: string;
|
|
1217
|
+
columnDelimiter?: BulkColumnDelimiter;
|
|
1218
|
+
lineEnding?: BulkLineEnding;
|
|
1219
|
+
signal?: AbortSignal;
|
|
1220
|
+
}
|
|
1221
|
+
interface BulkIngestOptions<R extends object, K extends SObjectName<R>> extends BulkIngestJobOptions<K> {
|
|
1222
|
+
/** Required for `upsert`: an external id field of `object`. */
|
|
1223
|
+
externalIdFieldName?: ExternalIdField<R, K>;
|
|
1224
|
+
/** Records to upload; converted to CSV. Pass either `records` or `csv`. */
|
|
1225
|
+
records?: readonly BulkIngestRecord<R, K>[];
|
|
1226
|
+
/** Pre-built CSV to upload. */
|
|
1227
|
+
csv?: string;
|
|
1228
|
+
/** Wait until the job has finished. Defaults to `true`. */
|
|
1229
|
+
wait?: boolean | WaitOptions;
|
|
1230
|
+
}
|
|
1231
|
+
interface BulkQueryOptions {
|
|
1232
|
+
/** `queryAll` also returns deleted and archived records. */
|
|
1233
|
+
includeDeleted?: boolean;
|
|
1234
|
+
columnDelimiter?: BulkColumnDelimiter;
|
|
1235
|
+
lineEnding?: BulkLineEnding;
|
|
1236
|
+
/** Maximum records per result page. */
|
|
1237
|
+
maxRecords?: number;
|
|
1238
|
+
wait?: WaitOptions;
|
|
1239
|
+
signal?: AbortSignal;
|
|
1240
|
+
}
|
|
1241
|
+
/** A Bulk API 2.0 ingest job. */
|
|
1242
|
+
export declare class BulkIngestJob {
|
|
1243
|
+
private readonly _connection;
|
|
1244
|
+
info: BulkJobInfo;
|
|
1245
|
+
constructor(_connection: SalesforceConnection, info: BulkJobInfo);
|
|
1246
|
+
get id(): string;
|
|
1247
|
+
private get path();
|
|
1248
|
+
private get delimiter();
|
|
1249
|
+
/** Uploads CSV data, or records that are converted to CSV. Only allowed while the job is `Open`. */
|
|
1250
|
+
upload(data: string | readonly object[], options?: {
|
|
1251
|
+
signal?: AbortSignal;
|
|
1252
|
+
}): Promise<void>;
|
|
1253
|
+
/** Marks the upload as complete so Salesforce starts processing. */
|
|
1254
|
+
close(options?: {
|
|
1255
|
+
signal?: AbortSignal;
|
|
1256
|
+
}): Promise<BulkJobInfo>;
|
|
1257
|
+
abort(options?: {
|
|
1258
|
+
signal?: AbortSignal;
|
|
1259
|
+
}): Promise<BulkJobInfo>;
|
|
1260
|
+
delete(options?: {
|
|
1261
|
+
signal?: AbortSignal;
|
|
1262
|
+
}): Promise<void>;
|
|
1263
|
+
/** Fetches the current job status. */
|
|
1264
|
+
refresh(options?: {
|
|
1265
|
+
signal?: AbortSignal;
|
|
1266
|
+
}): Promise<BulkJobInfo>;
|
|
1267
|
+
/** Polls until the job is `JobComplete`. Throws `SalesforceBulkJobError` on `Failed`, `Aborted` or timeout. */
|
|
1268
|
+
waitForCompletion(options?: WaitOptions): Promise<BulkJobInfo>;
|
|
1269
|
+
/** Successfully processed rows: `sf__Id`, `sf__Created` and the uploaded columns. */
|
|
1270
|
+
successfulResults(options?: {
|
|
1271
|
+
signal?: AbortSignal;
|
|
1272
|
+
}): Promise<Record<string, string>[]>;
|
|
1273
|
+
/** Failed rows: `sf__Id`, `sf__Error` and the uploaded columns. */
|
|
1274
|
+
failedResults(options?: {
|
|
1275
|
+
signal?: AbortSignal;
|
|
1276
|
+
}): Promise<Record<string, string>[]>;
|
|
1277
|
+
/** Rows that were not processed (e.g. because the job was aborted). */
|
|
1278
|
+
unprocessedRecords(options?: {
|
|
1279
|
+
signal?: AbortSignal;
|
|
1280
|
+
}): Promise<Record<string, string>[]>;
|
|
1281
|
+
private results;
|
|
1282
|
+
private setState;
|
|
1283
|
+
}
|
|
1284
|
+
/** A Bulk API 2.0 query job. */
|
|
1285
|
+
export declare class BulkQueryJob<TRow = Record<string, string>> {
|
|
1286
|
+
private readonly _connection;
|
|
1287
|
+
info: BulkJobInfo;
|
|
1288
|
+
constructor(_connection: SalesforceConnection, info: BulkJobInfo);
|
|
1289
|
+
get id(): string;
|
|
1290
|
+
private get path();
|
|
1291
|
+
refresh(options?: {
|
|
1292
|
+
signal?: AbortSignal;
|
|
1293
|
+
}): Promise<BulkJobInfo>;
|
|
1294
|
+
/** Polls until the job is `JobComplete`. Throws `SalesforceBulkJobError` on `Failed`, `Aborted` or timeout. */
|
|
1295
|
+
waitForCompletion(options?: WaitOptions): Promise<BulkJobInfo>;
|
|
1296
|
+
abort(options?: {
|
|
1297
|
+
signal?: AbortSignal;
|
|
1298
|
+
}): Promise<BulkJobInfo>;
|
|
1299
|
+
delete(options?: {
|
|
1300
|
+
signal?: AbortSignal;
|
|
1301
|
+
}): Promise<void>;
|
|
1302
|
+
/** Yields result pages (following `Sforce-Locator`). The job must be complete. */
|
|
1303
|
+
pages(options?: {
|
|
1304
|
+
maxRecords?: number;
|
|
1305
|
+
signal?: AbortSignal;
|
|
1306
|
+
}): AsyncGenerator<TRow[], void, undefined>;
|
|
1307
|
+
/** Yields every result row. The job must be complete. */
|
|
1308
|
+
records(options?: {
|
|
1309
|
+
maxRecords?: number;
|
|
1310
|
+
signal?: AbortSignal;
|
|
1311
|
+
}): AsyncGenerator<TRow, void, undefined>;
|
|
1312
|
+
}
|
|
1313
|
+
/** Bulk API 2.0: asynchronous ingest (insert/update/upsert/delete) and query of large data volumes. */
|
|
1314
|
+
export declare class BulkApi<R extends object> {
|
|
1315
|
+
private readonly _connection;
|
|
1316
|
+
constructor(_connection: SalesforceConnection);
|
|
1317
|
+
/** Creates an ingest job in state `Open`. Upload data with `job.upload()` and then call `job.close()`. */
|
|
1318
|
+
createIngestJob<K extends SObjectName<R>>(options: BulkIngestJobOptions<K> & {
|
|
1319
|
+
externalIdFieldName?: ExternalIdField<R, K>;
|
|
1320
|
+
}): Promise<BulkIngestJob>;
|
|
1321
|
+
/** Attaches to an existing ingest job. */
|
|
1322
|
+
ingestJob(id: string, options?: {
|
|
1323
|
+
signal?: AbortSignal;
|
|
1324
|
+
}): Promise<BulkIngestJob>;
|
|
1325
|
+
/**
|
|
1326
|
+
* Creates an ingest job, uploads the data, closes the job and (by default) waits for it.
|
|
1327
|
+
* Check `job.info.numberRecordsFailed` and `job.failedResults()` afterwards.
|
|
1328
|
+
*/
|
|
1329
|
+
ingest<K extends SObjectName<R>>(options: BulkIngestOptions<R, K>): Promise<BulkIngestJob>;
|
|
1330
|
+
/** Creates a query job. Wait for it with `job.waitForCompletion()` and read rows with `job.records()`. */
|
|
1331
|
+
createQueryJob<K extends SObjectName<R>, S extends object = NoSelection>(query: SoqlQueryBuilder<R, K, S>, options?: BulkQueryOptions): Promise<BulkQueryJob<BulkCsvRecord<SoqlQueryRecord<R, K, S>>>>;
|
|
1332
|
+
createQueryJob<TRow = Record<string, string>>(soql: string, options?: BulkQueryOptions): Promise<BulkQueryJob<TRow>>;
|
|
1333
|
+
private startQueryJob;
|
|
1334
|
+
/** Attaches to an existing query job. */
|
|
1335
|
+
queryJob<TRow = Record<string, string>>(id: string, options?: {
|
|
1336
|
+
signal?: AbortSignal;
|
|
1337
|
+
}): Promise<BulkQueryJob<TRow>>;
|
|
1338
|
+
/**
|
|
1339
|
+
* Runs a query job, waits for it and yields every row (CSV values are strings).
|
|
1340
|
+
*
|
|
1341
|
+
* ```ts
|
|
1342
|
+
* for await (const row of sf.bulk.query(sf.soql("Account").select("Id", "Name"))) { ... }
|
|
1343
|
+
* ```
|
|
1344
|
+
*/
|
|
1345
|
+
query<K extends SObjectName<R>, S extends object = NoSelection>(query: SoqlQueryBuilder<R, K, S>, options?: BulkQueryOptions): AsyncGenerator<BulkCsvRecord<SoqlQueryRecord<R, K, S>>, void, undefined>;
|
|
1346
|
+
query<TRow = Record<string, string>>(soql: string, options?: BulkQueryOptions): AsyncGenerator<TRow, void, undefined>;
|
|
1347
|
+
}
|
|
1348
|
+
//#endregion
|
|
1349
|
+
//#region src/resources/collections.d.ts
|
|
1350
|
+
interface CollectionOptions {
|
|
1351
|
+
/** Roll back the whole call when one record fails. */
|
|
1352
|
+
allOrNone?: boolean;
|
|
1353
|
+
/** Throw a `SalesforceSaveError` when any record failed. Defaults to `true`. */
|
|
1354
|
+
throwOnError?: boolean;
|
|
1355
|
+
/**
|
|
1356
|
+
* Split more than 200 records into several sequential calls. Each call is its own
|
|
1357
|
+
* transaction, so this cannot be combined with `allOrNone`.
|
|
1358
|
+
*/
|
|
1359
|
+
chunk?: boolean;
|
|
1360
|
+
signal?: AbortSignal;
|
|
1361
|
+
}
|
|
1362
|
+
/** sObject Collections (`/composite/sobjects`): create, update, upsert, delete and retrieve up to 200 records per call. */
|
|
1363
|
+
export declare class CollectionsApi<R extends object> {
|
|
1364
|
+
private readonly _connection;
|
|
1365
|
+
constructor(_connection: SalesforceConnection);
|
|
1366
|
+
create<K extends SObjectName<R>>(sobject: K, records: readonly SObjectCreateInput<R, K>[], options?: CollectionOptions): Promise<SaveResult[]>;
|
|
1367
|
+
/** Updates records; every record needs its `Id`. */
|
|
1368
|
+
update<K extends SObjectName<R>>(sobject: K, records: readonly (SObjectUpdateInput<R, K> & {
|
|
1369
|
+
Id: string;
|
|
1370
|
+
})[], options?: CollectionOptions): Promise<SaveResult[]>;
|
|
1371
|
+
/** Upserts records of one sObject by external id. Every record needs the external id field. */
|
|
1372
|
+
upsert<K extends SObjectName<R>, F extends ExternalIdField<R, K>>(sobject: K, externalIdField: F, records: readonly SObjectCreateInput<R, K>[], options?: CollectionOptions): Promise<UpsertResult[]>;
|
|
1373
|
+
/** Deletes records by id (they may be of different sObjects). */
|
|
1374
|
+
delete(ids: readonly string[], options?: CollectionOptions): Promise<DeleteResult[]>;
|
|
1375
|
+
/** Retrieves records by id with the given fields. Inaccessible or unknown ids yield `null`. */
|
|
1376
|
+
retrieve<K extends SObjectName<R>, F extends SObjectFieldName<R, K>>(sobject: K, ids: readonly string[], fields: readonly F[], options?: {
|
|
1377
|
+
signal?: AbortSignal;
|
|
1378
|
+
}): Promise<(WithAttributes<Pick<SObjectRecord<R, K>, F>> | null)[]>;
|
|
1379
|
+
private save;
|
|
1380
|
+
}
|
|
1381
|
+
//#endregion
|
|
1382
|
+
//#region src/resources/composite.d.ts
|
|
1383
|
+
declare const refResultType: unique symbol;
|
|
1384
|
+
/**
|
|
1385
|
+
* A handle to a composite subrequest. Use `ref("id")` to reference its result in a later
|
|
1386
|
+
* subrequest (it becomes `@{referenceId.id}`) and `response.get(handle)` to read the result.
|
|
1387
|
+
*/
|
|
1388
|
+
interface CompositeRef<T> {
|
|
1389
|
+
readonly referenceId: string;
|
|
1390
|
+
/** Returns the `@{referenceId.path}` expression. Paths can go deeper, e.g. `"records[0].Id"`. */
|
|
1391
|
+
ref(path: (keyof T & string) | (string & {})): string;
|
|
1392
|
+
readonly [refResultType]?: T;
|
|
1393
|
+
}
|
|
1394
|
+
interface SubrequestOptions {
|
|
1395
|
+
/** A custom reference id. Defaults to `ref1`, `ref2`, ... */
|
|
1396
|
+
referenceId?: string;
|
|
1397
|
+
/** Extra headers for this subrequest (not Accept, Authorization or Content-Type). */
|
|
1398
|
+
httpHeaders?: Record<string, string>;
|
|
1399
|
+
}
|
|
1400
|
+
interface CompositeRawSubrequest {
|
|
1401
|
+
method: CompositeMethod;
|
|
1402
|
+
/** Relative to `/services/data/{version}` (e.g. `"/sobjects/Account"`) or a full `/services/...` path. */
|
|
1403
|
+
path: string;
|
|
1404
|
+
body?: unknown;
|
|
1405
|
+
}
|
|
1406
|
+
/** Collects subrequests for `/composite` or one graph of `/composite/graph`. */
|
|
1407
|
+
export declare class CompositeRequestBuilder<R extends object> {
|
|
1408
|
+
private readonly _apiVersion;
|
|
1409
|
+
private readonly _referencePrefix;
|
|
1410
|
+
private readonly _subrequests;
|
|
1411
|
+
private _queryCount;
|
|
1412
|
+
constructor(_apiVersion: ApiVersion, _referencePrefix?: string);
|
|
1413
|
+
/** The subrequests collected so far. */
|
|
1414
|
+
get subrequests(): readonly CompositeSubrequest[];
|
|
1415
|
+
/** Number of query subrequests collected so far (Salesforce allows at most 5 per composite request). */
|
|
1416
|
+
get queryCount(): number;
|
|
1417
|
+
create<K extends SObjectName<R>>(sobject: K, record: SObjectCreateInput<R, K>, options?: SubrequestOptions): CompositeRef<SaveResult>;
|
|
1418
|
+
update<K extends SObjectName<R>>(sobject: K, id: string, record: SObjectUpdateInput<R, K>, options?: SubrequestOptions): CompositeRef<null>;
|
|
1419
|
+
upsert<K extends SObjectName<R>, F extends ExternalIdField<R, K>>(sobject: K, externalIdField: F, externalIdValue: string | number, record: Omit<SObjectCreateInput<R, K>, F>, options?: SubrequestOptions): CompositeRef<UpsertResult>;
|
|
1420
|
+
delete<K extends SObjectName<R>>(sobject: K, id: string, options?: SubrequestOptions): CompositeRef<null>;
|
|
1421
|
+
get<K extends SObjectName<R>, F extends SObjectFieldName<R, K> = SObjectFieldName<R, K>>(sobject: K, id: string, fields?: readonly F[], options?: SubrequestOptions): CompositeRef<WithAttributes<Pick<SObjectRecord<R, K>, F>>>;
|
|
1422
|
+
/** Adds a SOQL query subrequest. Its result is one page (`QueryResponse`). */
|
|
1423
|
+
query<K extends SObjectName<R>, S extends object>(query: SoqlQueryBuilder<R, K, S>, options?: SubrequestOptions): CompositeRef<QueryResponse<SoqlQueryRecord<R, K, S>>>;
|
|
1424
|
+
query<T = Record<string, unknown>>(soql: string, options?: SubrequestOptions): CompositeRef<QueryResponse<T>>;
|
|
1425
|
+
/** Adds any other supported subrequest (sObject collections, describe, ...). */
|
|
1426
|
+
request<T = unknown>(subrequest: CompositeRawSubrequest, options?: SubrequestOptions): CompositeRef<T>;
|
|
1427
|
+
/** `ref1`, `ref2`, ...: skips ids already taken by a custom `referenceId`. */
|
|
1428
|
+
private nextReferenceId;
|
|
1429
|
+
private add;
|
|
1430
|
+
}
|
|
1431
|
+
/** The result of a composite request (or of one graph). */
|
|
1432
|
+
export declare class CompositeResponse {
|
|
1433
|
+
readonly responses: CompositeSubrequestResult[];
|
|
1434
|
+
constructor(responses: CompositeSubrequestResult[]);
|
|
1435
|
+
/** `true` when any subrequest returned a status of 400 or higher. */
|
|
1436
|
+
get hasErrors(): boolean;
|
|
1437
|
+
/** The raw subrequest result for `ref`. */
|
|
1438
|
+
response<T>(ref: CompositeRef<T>): CompositeSubrequestResult<T>;
|
|
1439
|
+
/** The body of the subrequest for `ref`. Throws `SalesforceError` when that subrequest failed. */
|
|
1440
|
+
get<T>(ref: CompositeRef<T>): T;
|
|
1441
|
+
}
|
|
1442
|
+
interface CompositeOptions {
|
|
1443
|
+
/** Roll back all subrequests when one fails. */
|
|
1444
|
+
allOrNone?: boolean;
|
|
1445
|
+
/** Let Salesforce group independent subrequests (default `true` on the server). */
|
|
1446
|
+
collateSubrequests?: boolean;
|
|
1447
|
+
/** Throw a `SalesforceError` for the first failed subrequest. Defaults to `false`. */
|
|
1448
|
+
throwOnError?: boolean;
|
|
1449
|
+
signal?: AbortSignal;
|
|
1450
|
+
}
|
|
1451
|
+
interface CompositeGraphInput<R extends object> {
|
|
1452
|
+
graphId: string;
|
|
1453
|
+
build: (graph: CompositeRequestBuilder<R>) => void;
|
|
1454
|
+
}
|
|
1455
|
+
interface CompositeGraphResult {
|
|
1456
|
+
graphId: string;
|
|
1457
|
+
isSuccessful: boolean;
|
|
1458
|
+
response: CompositeResponse;
|
|
1459
|
+
}
|
|
1460
|
+
interface CompositeBatchRequest {
|
|
1461
|
+
method: CompositeMethod;
|
|
1462
|
+
/** Relative to the API version, e.g. `"/sobjects/Account/001..."`. */
|
|
1463
|
+
path: string;
|
|
1464
|
+
/** The request body (`richInput`). */
|
|
1465
|
+
body?: unknown;
|
|
1466
|
+
}
|
|
1467
|
+
type TreeChildren<R extends object, K extends SObjectName<R>> = string extends ChildRelationshipName<R, K> ? unknown : { [C in ChildRelationshipName<R, K>]?: {
|
|
1468
|
+
records: TreeChildRecord<R, ChildSObjectName<R, K, C>>[];
|
|
1469
|
+
}; };
|
|
1470
|
+
type TreeNodeMeta<R extends object, K extends SObjectName<R>> = {
|
|
1471
|
+
attributes: {
|
|
1472
|
+
type: K;
|
|
1473
|
+
referenceId: string;
|
|
1474
|
+
};
|
|
1475
|
+
} & TreeChildren<R, K>;
|
|
1476
|
+
/** A root record of an sObject tree. */
|
|
1477
|
+
type TreeRecord<R extends object, K extends SObjectName<R>> = SObjectCreateInput<R, K> & TreeNodeMeta<R, K>;
|
|
1478
|
+
/** A child record of an sObject tree; the lookup to the parent is set by Salesforce. */
|
|
1479
|
+
type TreeChildRecord<R extends object, K extends SObjectName<R>> = Partial<SObjectCreateInput<R, K>> & TreeNodeMeta<R, K>;
|
|
1480
|
+
/** `/composite`, `/composite/batch`, `/composite/tree` and `/composite/graph`. */
|
|
1481
|
+
export declare class CompositeApi<R extends object> {
|
|
1482
|
+
private readonly _connection;
|
|
1483
|
+
constructor(_connection: SalesforceConnection);
|
|
1484
|
+
/**
|
|
1485
|
+
* Runs up to 25 subrequests in one call; later subrequests can reference earlier results.
|
|
1486
|
+
*
|
|
1487
|
+
* ```ts
|
|
1488
|
+
* const result = await sf.composite.execute(c => {
|
|
1489
|
+
* const account = c.create("Account", { Name: "Acme" });
|
|
1490
|
+
* c.create("Contact", { LastName: "Doe", AccountId: account.ref("id") });
|
|
1491
|
+
* return { account };
|
|
1492
|
+
* }, { allOrNone: true });
|
|
1493
|
+
* const accountId = result.get(result.refs.account).id;
|
|
1494
|
+
* ```
|
|
1495
|
+
*/
|
|
1496
|
+
execute<TRefs = void>(build: (composite: CompositeRequestBuilder<R>) => TRefs, options?: CompositeOptions): Promise<CompositeResponse & {
|
|
1497
|
+
refs: TRefs;
|
|
1498
|
+
}>;
|
|
1499
|
+
/** `/composite/batch`: up to 25 independent subrequests (each counts against API limits). */
|
|
1500
|
+
batch(requests: CompositeBatchRequest[], options?: {
|
|
1501
|
+
haltOnError?: boolean;
|
|
1502
|
+
signal?: AbortSignal;
|
|
1503
|
+
}): Promise<CompositeBatchResult>;
|
|
1504
|
+
/**
|
|
1505
|
+
* `/composite/tree/{sobject}`: creates up to 200 records with nested children in one
|
|
1506
|
+
* all-or-nothing call. On failure a `SalesforceError` is thrown whose `body` holds the per-record errors.
|
|
1507
|
+
*/
|
|
1508
|
+
tree<K extends SObjectName<R>>(sobject: K, records: TreeRecord<R, K>[], options?: {
|
|
1509
|
+
signal?: AbortSignal;
|
|
1510
|
+
}): Promise<TreeSaveResult>;
|
|
1511
|
+
/** `/composite/graph`: several independent all-or-nothing graphs of subrequests in one call. */
|
|
1512
|
+
graph(graphs: CompositeGraphInput<R>[], options?: {
|
|
1513
|
+
signal?: AbortSignal;
|
|
1514
|
+
}): Promise<CompositeGraphResult[]>;
|
|
1515
|
+
}
|
|
1516
|
+
//#endregion
|
|
1517
|
+
//#region src/resources/events.d.ts
|
|
1518
|
+
/** Platform event sObject names (`...__e`) in registry `R`. */
|
|
1519
|
+
type PlatformEventName<R> = string extends SObjectName<R> ? `${string}__e` : Extract<SObjectName<R>, `${string}__e`>;
|
|
1520
|
+
interface PublishResult {
|
|
1521
|
+
/** `true` when Salesforce accepted (enqueued) the event. */
|
|
1522
|
+
success: boolean;
|
|
1523
|
+
/** The event UUID (`EventUuid`), taken from the `OPERATION_ENQUEUED` entry Salesforce returns. */
|
|
1524
|
+
uuid: string | undefined;
|
|
1525
|
+
/** The returned id. Not unique or meaningful for events; use `uuid` to correlate. */
|
|
1526
|
+
id: string | undefined;
|
|
1527
|
+
/** Real errors (the `OPERATION_ENQUEUED` entry is not an error and is left out). */
|
|
1528
|
+
errors: SaveError[];
|
|
1529
|
+
}
|
|
1530
|
+
interface PublishOptions {
|
|
1531
|
+
/** Throw a `SalesforceSaveError` when any event was not accepted. Defaults to `true`. */
|
|
1532
|
+
throwOnError?: boolean;
|
|
1533
|
+
signal?: AbortSignal;
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Publishes platform events. Payloads are typed by the event's generated create input.
|
|
1537
|
+
*
|
|
1538
|
+
* ```ts
|
|
1539
|
+
* await sf.events.publish("Order_Shipped__e", { Order_Number__c: "A-1" });
|
|
1540
|
+
* await sf.events.publish("Order_Shipped__e", [{ Order_Number__c: "A-1" }, { Order_Number__c: "A-2" }]);
|
|
1541
|
+
* ```
|
|
1542
|
+
*
|
|
1543
|
+
* With the default "Publish Immediately" behaviour, events are published even when later
|
|
1544
|
+
* events in the same call fail; there is no rollback.
|
|
1545
|
+
*/
|
|
1546
|
+
export declare class EventsApi<R extends object> {
|
|
1547
|
+
private readonly _connection;
|
|
1548
|
+
constructor(_connection: SalesforceConnection);
|
|
1549
|
+
publish<K extends PlatformEventName<R> & SObjectName<R>>(eventName: K, events: SObjectCreateInput<R, K> | readonly SObjectCreateInput<R, K>[], options?: PublishOptions): Promise<PublishResult[]>;
|
|
1550
|
+
private publishOne;
|
|
1551
|
+
private publishBatch;
|
|
1552
|
+
}
|
|
1553
|
+
/** Converts a save result, treating the `OPERATION_ENQUEUED` entry as the UUID instead of an error. */
|
|
1554
|
+
export declare function toPublishResult(result: SaveResult): PublishResult;
|
|
1555
|
+
//#endregion
|
|
1556
|
+
//#region src/resources/files.d.ts
|
|
1557
|
+
/** JSON uploads send base64, which Salesforce caps at 37.5 MB encoded (about 28 MB of file data). */
|
|
1558
|
+
export declare const MAX_JSON_UPLOAD_BYTES: number;
|
|
1559
|
+
/** Multipart ContentVersion uploads are limited to 2 GB. */
|
|
1560
|
+
export declare const MAX_UPLOAD_BYTES: number;
|
|
1561
|
+
type FileShareType = "V" | "C" | "I";
|
|
1562
|
+
type FileVisibility = "AllUsers" | "InternalUsers" | "SharedUsers";
|
|
1563
|
+
interface UploadFileOptions {
|
|
1564
|
+
/** The file content. Strings are encoded as UTF-8. */
|
|
1565
|
+
data: Uint8Array | string;
|
|
1566
|
+
/** The file name including extension, e.g. `"invoice.pdf"` (`PathOnClient`). */
|
|
1567
|
+
fileName: string;
|
|
1568
|
+
/** Defaults to the file name without extension. */
|
|
1569
|
+
title?: string;
|
|
1570
|
+
description?: string;
|
|
1571
|
+
/** A record id (or user/library id) to share the file with. */
|
|
1572
|
+
linkTo?: string;
|
|
1573
|
+
/** Link permission: `V` viewer (default), `C` collaborator, `I` inferred from the record. */
|
|
1574
|
+
shareType?: FileShareType;
|
|
1575
|
+
visibility?: FileVisibility;
|
|
1576
|
+
signal?: AbortSignal;
|
|
1577
|
+
}
|
|
1578
|
+
interface NewVersionOptions {
|
|
1579
|
+
data: Uint8Array | string;
|
|
1580
|
+
fileName: string;
|
|
1581
|
+
title?: string;
|
|
1582
|
+
reasonForChange?: string;
|
|
1583
|
+
signal?: AbortSignal;
|
|
1584
|
+
}
|
|
1585
|
+
interface UploadedFile {
|
|
1586
|
+
contentVersionId: string;
|
|
1587
|
+
contentDocumentId: string;
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1590
|
+
* Salesforce Files (ContentVersion / ContentDocument). Small files go up as JSON with base64,
|
|
1591
|
+
* larger ones as multipart (up to 2 GB), which works with every transport.
|
|
1592
|
+
*/
|
|
1593
|
+
export declare class FilesApi {
|
|
1594
|
+
private readonly _connection;
|
|
1595
|
+
/** Files up to this size go up as JSON/base64, larger ones as multipart. */
|
|
1596
|
+
private readonly _jsonUploadLimit;
|
|
1597
|
+
constructor(_connection: SalesforceConnection,
|
|
1598
|
+
/** Files up to this size go up as JSON/base64, larger ones as multipart. */
|
|
1599
|
+
_jsonUploadLimit?: number);
|
|
1600
|
+
/** Uploads a file and optionally links it to a record. */
|
|
1601
|
+
upload(options: UploadFileOptions): Promise<UploadedFile>;
|
|
1602
|
+
/** Adds a new version to an existing file. */
|
|
1603
|
+
newVersion(contentDocumentId: string, options: NewVersionOptions): Promise<UploadedFile>;
|
|
1604
|
+
/** Downloads file content by ContentVersion id (`068...`) or ContentDocument id (`069...`, latest version). */
|
|
1605
|
+
download(id: string, options?: {
|
|
1606
|
+
signal?: AbortSignal;
|
|
1607
|
+
}): Promise<Uint8Array>;
|
|
1608
|
+
/** Shares a file with a record, user or library. Returns the ContentDocumentLink id. */
|
|
1609
|
+
link(contentDocumentId: string, linkedEntityId: string, options?: {
|
|
1610
|
+
shareType?: FileShareType;
|
|
1611
|
+
visibility?: FileVisibility;
|
|
1612
|
+
signal?: AbortSignal;
|
|
1613
|
+
}): Promise<string>;
|
|
1614
|
+
private createVersion;
|
|
1615
|
+
private createVersionMultipart;
|
|
1616
|
+
}
|
|
1617
|
+
//#endregion
|
|
1618
|
+
//#region src/resources/quick-actions.d.ts
|
|
1619
|
+
interface InvokeQuickActionOptions {
|
|
1620
|
+
/** The record the action runs on (e.g. the parent Account of a "New Contact" action). */
|
|
1621
|
+
contextId?: string;
|
|
1622
|
+
/** Throw a `SalesforceSaveError` when Salesforce reports `success: false`. Defaults to `true`. */
|
|
1623
|
+
throwOnError?: boolean;
|
|
1624
|
+
signal?: AbortSignal;
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Quick actions of one sObject (`sf.sobject("Account").quickActions`) or global quick actions
|
|
1628
|
+
* (`sf.quickActions`). An sObject's list also includes the global actions on its layout; those
|
|
1629
|
+
* only exist under `/quickActions`, so calls for them fall back to the global path.
|
|
1630
|
+
*/
|
|
1631
|
+
export declare class QuickActionsApi {
|
|
1632
|
+
private readonly _connection;
|
|
1633
|
+
private readonly _basePath;
|
|
1634
|
+
constructor(_connection: SalesforceConnection, _basePath: string);
|
|
1635
|
+
list(options?: {
|
|
1636
|
+
signal?: AbortSignal;
|
|
1637
|
+
}): Promise<QuickActionSummary[]>;
|
|
1638
|
+
describe(name: string, options?: {
|
|
1639
|
+
signal?: AbortSignal;
|
|
1640
|
+
}): Promise<QuickActionDescribe>;
|
|
1641
|
+
/** The default field values the action would pre-fill, optionally for a context record. */
|
|
1642
|
+
defaultValues(name: string, contextId?: string, options?: {
|
|
1643
|
+
signal?: AbortSignal;
|
|
1644
|
+
}): Promise<GenericRecord>;
|
|
1645
|
+
/** Runs the action with the given record values. */
|
|
1646
|
+
invoke<TRecord extends object = GenericRecord>(name: string, record: TRecord, options?: InvokeQuickActionOptions): Promise<QuickActionResult>;
|
|
1647
|
+
/** Calls the action under this sObject, falling back to the global action of that name. */
|
|
1648
|
+
private send;
|
|
1649
|
+
}
|
|
1650
|
+
//#endregion
|
|
1651
|
+
//#region src/resources/reports.d.ts
|
|
1652
|
+
interface RunReportOptions {
|
|
1653
|
+
/** Include detail rows (not just aggregates). Defaults to `true`. */
|
|
1654
|
+
includeDetails?: boolean;
|
|
1655
|
+
/** Override filters for this run (other metadata comes from the saved report). */
|
|
1656
|
+
filters?: ReportFilter[];
|
|
1657
|
+
/** Boolean filter logic for `filters`, e.g. `"1 AND (2 OR 3)"`. */
|
|
1658
|
+
booleanFilter?: string;
|
|
1659
|
+
signal?: AbortSignal;
|
|
1660
|
+
}
|
|
1661
|
+
interface WaitForReportOptions {
|
|
1662
|
+
/** Delay between status checks. Defaults to 2 000 ms. */
|
|
1663
|
+
pollIntervalMs?: number;
|
|
1664
|
+
/** Give up after this many milliseconds. Defaults to 5 minutes. */
|
|
1665
|
+
timeoutMs?: number;
|
|
1666
|
+
signal?: AbortSignal;
|
|
1667
|
+
}
|
|
1668
|
+
/** A detail row: detail column API name -> `{ label, value }`. */
|
|
1669
|
+
type ReportRow = Record<string, ReportDataCell>;
|
|
1670
|
+
/**
|
|
1671
|
+
* Reports and Dashboards REST API (`/analytics/reports`). Synchronous runs return at most the
|
|
1672
|
+
* first 2 000 detail rows; the org allows 500 synchronous runs per hour.
|
|
1673
|
+
*/
|
|
1674
|
+
export declare class ReportsApi {
|
|
1675
|
+
private readonly _connection;
|
|
1676
|
+
constructor(_connection: SalesforceConnection);
|
|
1677
|
+
/** Recently viewed reports. */
|
|
1678
|
+
list(options?: {
|
|
1679
|
+
signal?: AbortSignal;
|
|
1680
|
+
}): Promise<ReportSummary[]>;
|
|
1681
|
+
describe(reportId: string, options?: {
|
|
1682
|
+
signal?: AbortSignal;
|
|
1683
|
+
}): Promise<ReportDescribe>;
|
|
1684
|
+
/** Runs a report synchronously. */
|
|
1685
|
+
run(reportId: string, options?: RunReportOptions): Promise<ReportResult>;
|
|
1686
|
+
/** Starts an asynchronous run; results stay available for 24 hours. */
|
|
1687
|
+
runAsync(reportId: string, options?: RunReportOptions): Promise<ReportInstance>;
|
|
1688
|
+
/** Status (and, when finished, results) of an asynchronous run. */
|
|
1689
|
+
instance(reportId: string, instanceId: string, options?: {
|
|
1690
|
+
signal?: AbortSignal;
|
|
1691
|
+
}): Promise<ReportResult & {
|
|
1692
|
+
attributes: {
|
|
1693
|
+
status?: ReportInstance["status"];
|
|
1694
|
+
};
|
|
1695
|
+
}>;
|
|
1696
|
+
/** Polls an asynchronous run until it succeeds, then returns the results. */
|
|
1697
|
+
waitForInstance(reportId: string, instanceId: string, options?: WaitForReportOptions): Promise<ReportResult>;
|
|
1698
|
+
/** Flattens detail rows of a report result; see `reportRows`. */
|
|
1699
|
+
toRows(result: ReportResult): ReportRow[];
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Flattens the detail rows of a report result into objects keyed by detail column API name
|
|
1703
|
+
* (e.g. `ACCOUNT.NAME`), each with the cell's `label` and `value`. Works for tabular, summary
|
|
1704
|
+
* and matrix reports; requires `includeDetails`.
|
|
1705
|
+
*/
|
|
1706
|
+
export declare function reportRows(result: ReportResult): ReportRow[];
|
|
1707
|
+
//#endregion
|
|
1708
|
+
//#region src/resources/search.d.ts
|
|
1709
|
+
interface SearchSuggestionsOptions {
|
|
1710
|
+
/** The search text (at least 3 characters for most objects). */
|
|
1711
|
+
q: string;
|
|
1712
|
+
sobject: string;
|
|
1713
|
+
fields?: string[];
|
|
1714
|
+
limit?: number;
|
|
1715
|
+
where?: string;
|
|
1716
|
+
useSearchScope?: boolean;
|
|
1717
|
+
signal?: AbortSignal;
|
|
1718
|
+
}
|
|
1719
|
+
/** SOSL search, parameterized search and search suggestions. */
|
|
1720
|
+
export declare class SearchApi {
|
|
1721
|
+
private readonly _connection;
|
|
1722
|
+
constructor(_connection: SalesforceConnection);
|
|
1723
|
+
/**
|
|
1724
|
+
* Runs a SOSL query, e.g. `FIND {Acme*} IN NAME FIELDS RETURNING Account(Id, Name)`.
|
|
1725
|
+
* Escape user input in the `FIND {...}` term with `soslEscape`.
|
|
1726
|
+
*/
|
|
1727
|
+
sosl<T = GenericRecord>(query: string, options?: {
|
|
1728
|
+
signal?: AbortSignal;
|
|
1729
|
+
}): Promise<SearchResult<T>>;
|
|
1730
|
+
/** `POST /parameterizedSearch`: search without writing SOSL. */
|
|
1731
|
+
parameterized<T = GenericRecord>(request: ParameterizedSearchRequest, options?: {
|
|
1732
|
+
signal?: AbortSignal;
|
|
1733
|
+
}): Promise<SearchResult<T>>;
|
|
1734
|
+
/** `GET /search/suggestions`: auto-suggest records matching the start of a term. */
|
|
1735
|
+
suggestions<T = GenericRecord>(options: SearchSuggestionsOptions): Promise<SearchSuggestionsResult<T>>;
|
|
1736
|
+
}
|
|
1737
|
+
//#endregion
|
|
1738
|
+
//#region src/cache.d.ts
|
|
1739
|
+
/**
|
|
1740
|
+
* An in-memory cache for metadata calls (describe, UI API object info, record type ids).
|
|
1741
|
+
* Concurrent callers share one in-flight request, each waiting with its own abort signal;
|
|
1742
|
+
* failed loads are not cached.
|
|
1743
|
+
*/
|
|
1744
|
+
export declare class MetadataCache {
|
|
1745
|
+
private readonly _enabled;
|
|
1746
|
+
private readonly _entries;
|
|
1747
|
+
constructor(_enabled?: boolean);
|
|
1748
|
+
/**
|
|
1749
|
+
* Returns the cached value for `key`, or loads (and caches) it. `load` receives a signal of
|
|
1750
|
+
* its own: aborting `signal` only stops this caller from waiting.
|
|
1751
|
+
*/
|
|
1752
|
+
getOrLoad<T>(key: string, load: (signal: AbortSignal | undefined) => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
1753
|
+
/** Removes one entry, or every entry when `key` is omitted. */
|
|
1754
|
+
clear(key?: string): void;
|
|
1755
|
+
}
|
|
1756
|
+
//#endregion
|
|
1757
|
+
//#region src/resources/sobject.d.ts
|
|
1758
|
+
interface UpsertOutcome {
|
|
1759
|
+
id: string;
|
|
1760
|
+
/** `true` when a record was inserted, `false` when an existing one was updated. */
|
|
1761
|
+
created: boolean;
|
|
1762
|
+
}
|
|
1763
|
+
interface RequestSignal {
|
|
1764
|
+
signal?: AbortSignal;
|
|
1765
|
+
}
|
|
1766
|
+
/** A picklist option, typed with the field's value type. */
|
|
1767
|
+
interface PicklistOption<TValue> {
|
|
1768
|
+
value: TValue;
|
|
1769
|
+
label: string;
|
|
1770
|
+
isDefault: boolean;
|
|
1771
|
+
}
|
|
1772
|
+
/** Typed operations on one sObject: describe, CRUD, upsert, external ids, blobs and queries. */
|
|
1773
|
+
export declare class SObjectResource<R extends object, K extends SObjectName<R>> {
|
|
1774
|
+
private readonly _connection;
|
|
1775
|
+
private readonly _queries;
|
|
1776
|
+
readonly name: K;
|
|
1777
|
+
private readonly _basePath;
|
|
1778
|
+
private readonly _cache?;
|
|
1779
|
+
constructor(_connection: SalesforceConnection, _queries: QueryApi, name: K, _basePath?: "" | "/tooling", _cache?: MetadataCache | undefined);
|
|
1780
|
+
private get path();
|
|
1781
|
+
/** `GET /sobjects/{name}/describe`: fields, relationships, record types, ... Cached per client. */
|
|
1782
|
+
describe(options?: RequestSignal): Promise<DescribeSObjectResult>;
|
|
1783
|
+
/**
|
|
1784
|
+
* Returns the id of a record type by DeveloperName, e.g. `recordTypeId("Complaint")`. Record type
|
|
1785
|
+
* ids differ between orgs, so resolve them at runtime instead of hard-coding them.
|
|
1786
|
+
*/
|
|
1787
|
+
recordTypeId(developerName: RecordTypeName<R, K>, options?: RequestSignal): Promise<string>;
|
|
1788
|
+
/**
|
|
1789
|
+
* Active picklist values of a field. With `recordType`, only the values available for that
|
|
1790
|
+
* record type are returned (via the UI API).
|
|
1791
|
+
*/
|
|
1792
|
+
picklistValues<F extends SObjectFieldName<R, K>>(field: F, options?: RequestSignal & {
|
|
1793
|
+
recordType?: RecordTypeName<R, K>;
|
|
1794
|
+
}): Promise<PicklistOption<NonNullable<SObjectRecord<R, K>[F]>>[]>;
|
|
1795
|
+
/** Quick actions of this sObject. */
|
|
1796
|
+
get quickActions(): QuickActionsApi;
|
|
1797
|
+
/** `GET /sobjects/{name}`: basic metadata and recently viewed records. */
|
|
1798
|
+
basicInfo(options?: RequestSignal): Promise<SObjectBasicInfo>;
|
|
1799
|
+
/** Creates a record and returns its id. Throws `SalesforceSaveError` if Salesforce reports `success: false`. */
|
|
1800
|
+
create(record: SObjectCreateInput<R, K>, options?: RequestSignal): Promise<string>;
|
|
1801
|
+
/** Retrieves a record with all fields. */
|
|
1802
|
+
get(id: string, options?: RequestSignal): Promise<WithAttributes<SObjectRecord<R, K>>>;
|
|
1803
|
+
/** Retrieves a record with only `fields`; the result type is narrowed accordingly. */
|
|
1804
|
+
get<F extends SObjectFieldName<R, K>>(id: string, fields: readonly F[], options?: RequestSignal): Promise<WithAttributes<Pick<SObjectRecord<R, K>, F>>>;
|
|
1805
|
+
/** Updates fields of a record. */
|
|
1806
|
+
update(id: string, record: SObjectUpdateInput<R, K>, options?: RequestSignal): Promise<void>;
|
|
1807
|
+
/** Deletes a record. */
|
|
1808
|
+
delete(id: string, options?: RequestSignal): Promise<void>;
|
|
1809
|
+
/**
|
|
1810
|
+
* Inserts or updates a record by external id (`PATCH /sobjects/{name}/{field}/{value}`).
|
|
1811
|
+
* Salesforce answers 300 (a `SalesforceError`) when the value matches more than one record.
|
|
1812
|
+
*/
|
|
1813
|
+
upsert<F extends ExternalIdField<R, K>>(externalIdField: F, externalIdValue: string | number, record: Omit<SObjectCreateInput<R, K>, F>, options?: RequestSignal & {
|
|
1814
|
+
updateOnly?: boolean;
|
|
1815
|
+
}): Promise<UpsertOutcome>;
|
|
1816
|
+
/** Retrieves a record by external id. */
|
|
1817
|
+
getByExternalId<F extends SObjectFieldName<R, K> = SObjectFieldName<R, K>>(externalIdField: ExternalIdField<R, K>, externalIdValue: string | number, fields?: readonly F[], options?: RequestSignal): Promise<WithAttributes<Pick<SObjectRecord<R, K>, F>>>;
|
|
1818
|
+
/** Ids of records deleted between `start` and `end` (UTC, at most 15 days back). */
|
|
1819
|
+
getDeleted(start: Date, end: Date, options?: RequestSignal): Promise<DeletedRecordsResult>;
|
|
1820
|
+
/** Ids of records updated between `start` and `end` (UTC, at most 30 days back). */
|
|
1821
|
+
getUpdated(start: Date, end: Date, options?: RequestSignal): Promise<UpdatedRecordsResult>;
|
|
1822
|
+
/** Downloads a blob field, e.g. `sobject("ContentVersion").getBlob(id, "VersionData")`. */
|
|
1823
|
+
getBlob(id: string, field: SObjectFieldName<R, K>, options?: RequestSignal): Promise<Uint8Array>;
|
|
1824
|
+
/** Starts a typed query on this sObject. */
|
|
1825
|
+
soql(): SoqlQueryBuilder<R, K>;
|
|
1826
|
+
/** Runs a query built on this sObject and returns the first page. */
|
|
1827
|
+
query<S extends object = NoSelection>(build: (query: SoqlQueryBuilder<R, K>) => SoqlQueryBuilder<R, K, S>, options?: QueryOptions): Promise<QueryResult<SoqlQueryRecord<R, K, S>>>;
|
|
1828
|
+
/** Runs a query built on this sObject and returns the records of all pages. */
|
|
1829
|
+
collect<S extends object = NoSelection>(build: (query: SoqlQueryBuilder<R, K>) => SoqlQueryBuilder<R, K, S>, options?: QueryOptions): Promise<SoqlQueryRecord<R, K, S>[]>;
|
|
1830
|
+
/** Runs a query built on this sObject and yields records of all pages lazily. */
|
|
1831
|
+
iterate<S extends object = NoSelection>(build: (query: SoqlQueryBuilder<R, K>) => SoqlQueryBuilder<R, K, S>, options?: QueryOptions): AsyncGenerator<SoqlQueryRecord<R, K, S>, void, undefined>;
|
|
1832
|
+
}
|
|
1833
|
+
//#endregion
|
|
1834
|
+
//#region src/resources/debug-logs.d.ts
|
|
1835
|
+
type LogLevel = "NONE" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "FINE" | "FINER" | "FINEST";
|
|
1836
|
+
/** Log levels per category, as on a DebugLevel record. */
|
|
1837
|
+
interface DebugLevels {
|
|
1838
|
+
ApexCode: LogLevel;
|
|
1839
|
+
ApexProfiling: LogLevel;
|
|
1840
|
+
Callout: LogLevel;
|
|
1841
|
+
Database: LogLevel;
|
|
1842
|
+
System: LogLevel;
|
|
1843
|
+
Validation: LogLevel;
|
|
1844
|
+
Visualforce: LogLevel;
|
|
1845
|
+
Workflow: LogLevel;
|
|
1846
|
+
}
|
|
1847
|
+
/** Defaults tuned for debugging Apex: everything from `System.debug` and exceptions, little noise. */
|
|
1848
|
+
export declare const DEFAULT_DEBUG_LEVELS: DebugLevels;
|
|
1849
|
+
/** The DebugLevel this library creates and reuses. */
|
|
1850
|
+
export declare const DEBUG_LEVEL_NAME = "sobjectly";
|
|
1851
|
+
interface ApexLogEntry {
|
|
1852
|
+
id: string;
|
|
1853
|
+
operation: string;
|
|
1854
|
+
request: string;
|
|
1855
|
+
/** `"Success"` or the unhandled exception message. */
|
|
1856
|
+
status: string;
|
|
1857
|
+
startTime: string;
|
|
1858
|
+
durationMilliseconds: number;
|
|
1859
|
+
logLength: number;
|
|
1860
|
+
/** The log text (when `includeBodies` is on). */
|
|
1861
|
+
body?: string;
|
|
1862
|
+
}
|
|
1863
|
+
interface CaptureLogsOptions {
|
|
1864
|
+
/** The user to trace. Defaults to the authenticated user. */
|
|
1865
|
+
userId?: string;
|
|
1866
|
+
/** Log levels; defaults to `DEFAULT_DEBUG_LEVELS`. */
|
|
1867
|
+
levels?: Partial<DebugLevels>;
|
|
1868
|
+
/** Download the log text. Defaults to `true`. */
|
|
1869
|
+
includeBodies?: boolean;
|
|
1870
|
+
/** Wait this long after the callback before collecting logs. Defaults to 1 000 ms. */
|
|
1871
|
+
settleMs?: number;
|
|
1872
|
+
/** How long the trace flag stays active if cleanup fails. Defaults to 30 minutes (max 24 hours). */
|
|
1873
|
+
expirationMinutes?: number;
|
|
1874
|
+
signal?: AbortSignal;
|
|
1875
|
+
}
|
|
1876
|
+
interface CaptureLogsResult<T> {
|
|
1877
|
+
result: T;
|
|
1878
|
+
logs: ApexLogEntry[];
|
|
1879
|
+
/**
|
|
1880
|
+
* Set when restoring the user's trace flag failed. The work's result is still returned; the
|
|
1881
|
+
* flag lapses on its own after `expirationMinutes`.
|
|
1882
|
+
*/
|
|
1883
|
+
cleanupError?: unknown;
|
|
1884
|
+
}
|
|
1885
|
+
/** Thrown by `capture` when the callback throws; carries the logs collected anyway. */
|
|
1886
|
+
export declare class DebugLogCaptureError extends Error {
|
|
1887
|
+
readonly logs: ApexLogEntry[];
|
|
1888
|
+
readonly cause: unknown;
|
|
1889
|
+
/** Set when restoring the user's trace flag failed as well. */
|
|
1890
|
+
readonly cleanupError?: unknown;
|
|
1891
|
+
readonly name: string;
|
|
1892
|
+
constructor(logs: ApexLogEntry[], cause: unknown,
|
|
1893
|
+
/** Set when restoring the user's trace flag failed as well. */
|
|
1894
|
+
cleanupError?: unknown);
|
|
1895
|
+
}
|
|
1896
|
+
/** Apex debug logs through the Tooling API: capture the logs of a block of work, list and read logs. */
|
|
1897
|
+
export declare class DebugLogsApi {
|
|
1898
|
+
private readonly _tooling;
|
|
1899
|
+
/** The latest capture per user: a user has one trace flag, so captures for a user take turns. */
|
|
1900
|
+
private readonly _captures;
|
|
1901
|
+
constructor(_tooling: ToolingApi);
|
|
1902
|
+
/** The id of the authenticated user (from `/services/oauth2/userinfo`). */
|
|
1903
|
+
currentUserId(options?: {
|
|
1904
|
+
signal?: AbortSignal;
|
|
1905
|
+
}): Promise<string>;
|
|
1906
|
+
/** The most recent Apex logs, newest first. */
|
|
1907
|
+
list(options?: {
|
|
1908
|
+
userId?: string;
|
|
1909
|
+
limit?: number;
|
|
1910
|
+
signal?: AbortSignal;
|
|
1911
|
+
}): Promise<ApexLogEntry[]>;
|
|
1912
|
+
/** The text of one Apex log. */
|
|
1913
|
+
body(logId: string, options?: {
|
|
1914
|
+
signal?: AbortSignal;
|
|
1915
|
+
}): Promise<string>;
|
|
1916
|
+
/**
|
|
1917
|
+
* Runs `work` with debug logging enabled for the user, then returns its result together with
|
|
1918
|
+
* the Apex logs it produced (e.g. from triggers, flows or Apex REST calls):
|
|
1919
|
+
*
|
|
1920
|
+
* ```ts
|
|
1921
|
+
* const { result, logs } = await sf.tooling.debugLogs.capture(() => sf.sobject("Case").create({ Subject: "x" }));
|
|
1922
|
+
* console.log(logs.map((log) => log.body).join("\n"));
|
|
1923
|
+
* ```
|
|
1924
|
+
*
|
|
1925
|
+
* Salesforce allows one trace flag per user; an existing flag is reused and restored afterwards,
|
|
1926
|
+
* and captures for the same user through this client run one after another. Only work that runs
|
|
1927
|
+
* while the callback does is traced: async Apex it enqueues (queueable, batch, future) usually
|
|
1928
|
+
* runs later. At most the 200 newest logs of the user are collected.
|
|
1929
|
+
*/
|
|
1930
|
+
capture<T>(work: () => Promise<T>, options?: CaptureLogsOptions): Promise<CaptureLogsResult<T>>;
|
|
1931
|
+
private captureFor;
|
|
1932
|
+
private ensureDebugLevel;
|
|
1933
|
+
/** Enables tracing and returns a function that restores the previous state. */
|
|
1934
|
+
private enableTraceFlag;
|
|
1935
|
+
}
|
|
1936
|
+
//#endregion
|
|
1937
|
+
//#region src/resources/tooling.d.ts
|
|
1938
|
+
/** Thrown by `executeAnonymous` when Apex fails to compile or throws. */
|
|
1939
|
+
export declare class ApexExecutionError extends Error {
|
|
1940
|
+
readonly result: ExecuteAnonymousResult;
|
|
1941
|
+
/** The debug logs, when the Apex ran with `captureLog: true`. */
|
|
1942
|
+
readonly logs: ApexLogEntry[];
|
|
1943
|
+
readonly name: string;
|
|
1944
|
+
constructor(result: ExecuteAnonymousResult,
|
|
1945
|
+
/** The debug logs, when the Apex ran with `captureLog: true`. */
|
|
1946
|
+
logs?: ApexLogEntry[]);
|
|
1947
|
+
}
|
|
1948
|
+
/** Loosely typed result of `runTestsSynchronous`. */
|
|
1949
|
+
interface RunTestsResult {
|
|
1950
|
+
numTestsRun: number;
|
|
1951
|
+
numFailures: number;
|
|
1952
|
+
totalTime: number;
|
|
1953
|
+
successes: Record<string, unknown>[];
|
|
1954
|
+
failures: Record<string, unknown>[];
|
|
1955
|
+
codeCoverage?: Record<string, unknown>[];
|
|
1956
|
+
codeCoverageWarnings?: Record<string, unknown>[];
|
|
1957
|
+
[key: string]: unknown;
|
|
1958
|
+
}
|
|
1959
|
+
/** The Tooling API (`/tooling/...`): metadata-ish sObjects such as ApexClass, anonymous Apex and tests. */
|
|
1960
|
+
interface ExecuteAnonymousOptions {
|
|
1961
|
+
/** Throw `ApexExecutionError` when the Apex doesn't compile or throws. Defaults to `true`. */
|
|
1962
|
+
throwOnError?: boolean;
|
|
1963
|
+
/** Capture the debug log of the execution (see `debugLogs.capture`). */
|
|
1964
|
+
captureLog?: boolean;
|
|
1965
|
+
/** Options for the log capture, e.g. log levels. */
|
|
1966
|
+
logOptions?: Omit<CaptureLogsOptions, "signal">;
|
|
1967
|
+
signal?: AbortSignal;
|
|
1968
|
+
}
|
|
1969
|
+
export declare class ToolingApi {
|
|
1970
|
+
private readonly _connection;
|
|
1971
|
+
private readonly _queries;
|
|
1972
|
+
/** Apex debug logs: capture the logs of a block of work, list and read logs. */
|
|
1973
|
+
readonly debugLogs: DebugLogsApi;
|
|
1974
|
+
constructor(_connection: SalesforceConnection);
|
|
1975
|
+
/** The connection this API uses. */
|
|
1976
|
+
get connection(): SalesforceConnection;
|
|
1977
|
+
/** Runs a Tooling SOQL query and returns the first page. */
|
|
1978
|
+
query<T = GenericRecord>(soql: string, options?: QueryOptions): Promise<QueryResult<T>>;
|
|
1979
|
+
queryMore<T>(cursor: QueryCursor<T>, options?: Pick<QueryOptions, "signal">): Promise<QueryResult<T>>;
|
|
1980
|
+
iterate<T = GenericRecord>(soql: string, options?: QueryOptions): AsyncGenerator<T, void, undefined>;
|
|
1981
|
+
collect<T = GenericRecord>(soql: string, options?: QueryOptions): Promise<T[]>;
|
|
1982
|
+
/** CRUD and describe for a Tooling sObject, e.g. `tooling.sobject("TraceFlag")`. */
|
|
1983
|
+
sobject(name: string): SObjectResource<GenericRegistry, string>;
|
|
1984
|
+
describeGlobal(options?: {
|
|
1985
|
+
signal?: AbortSignal;
|
|
1986
|
+
}): Promise<DescribeGlobalResult>;
|
|
1987
|
+
/**
|
|
1988
|
+
* Executes anonymous Apex. Throws `ApexExecutionError` when it does not compile or throws,
|
|
1989
|
+
* unless `throwOnError` is `false`. Salesforce only accepts the Apex in the query string, so it is
|
|
1990
|
+
* limited to about 12 000 characters once URL-encoded; put longer logic in an Apex class.
|
|
1991
|
+
* With `captureLog: true` the result includes the debug log (`System.debug` output).
|
|
1992
|
+
*/
|
|
1993
|
+
executeAnonymous(apex: string, options: ExecuteAnonymousOptions & {
|
|
1994
|
+
captureLog: true;
|
|
1995
|
+
}): Promise<ExecuteAnonymousResult & {
|
|
1996
|
+
logs: ApexLogEntry[];
|
|
1997
|
+
}>;
|
|
1998
|
+
executeAnonymous(apex: string, options?: ExecuteAnonymousOptions): Promise<ExecuteAnonymousResult>;
|
|
1999
|
+
/** Runs Apex tests synchronously (a single class) and returns the results. */
|
|
2000
|
+
runTestsSynchronous(request: RunTestsRequest, options?: {
|
|
2001
|
+
signal?: AbortSignal;
|
|
2002
|
+
}): Promise<RunTestsResult>;
|
|
2003
|
+
/** Enqueues Apex tests and returns the AsyncApexJob id. */
|
|
2004
|
+
runTestsAsynchronous(request: RunTestsRequest, options?: {
|
|
2005
|
+
signal?: AbortSignal;
|
|
2006
|
+
}): Promise<string>;
|
|
2007
|
+
/** Any other Tooling resource; `path` is relative to `/tooling`. */
|
|
2008
|
+
request<T>(request: RestRequest): Promise<T>;
|
|
2009
|
+
}
|
|
2010
|
+
//#endregion
|
|
2011
|
+
//#region src/resources/ui-api.d.ts
|
|
2012
|
+
interface UiRecordOptions<F extends string> {
|
|
2013
|
+
/** Fields that must be accessible; an inaccessible field fails the request. */
|
|
2014
|
+
fields?: readonly F[];
|
|
2015
|
+
/** Fields that are returned when accessible and silently left out otherwise. */
|
|
2016
|
+
optionalFields?: readonly F[];
|
|
2017
|
+
layoutTypes?: readonly ("Full" | "Compact")[];
|
|
2018
|
+
modes?: readonly ("Create" | "Edit" | "View")[];
|
|
2019
|
+
signal?: AbortSignal;
|
|
2020
|
+
}
|
|
2021
|
+
interface UiLayoutOptions {
|
|
2022
|
+
recordTypeId?: string;
|
|
2023
|
+
mode?: "Create" | "Edit" | "View";
|
|
2024
|
+
layoutType?: "Full" | "Compact";
|
|
2025
|
+
formFactor?: "Large" | "Medium" | "Small";
|
|
2026
|
+
signal?: AbortSignal;
|
|
2027
|
+
}
|
|
2028
|
+
/** The typed `fields` of a UI API record loaded with field names `F` of sObject `K`. */
|
|
2029
|
+
type UiRecordFields<R, K extends SObjectName<R>, F extends string> = { [P in F]: UiFieldValue<P extends keyof SObjectRecord<R, K> ? SObjectRecord<R, K>[P] : unknown>; };
|
|
2030
|
+
/** User Interface API: object info, picklist values per record type, records and layouts. */
|
|
2031
|
+
export declare class UiApi<R extends object> {
|
|
2032
|
+
private readonly _connection;
|
|
2033
|
+
private readonly _cache?;
|
|
2034
|
+
constructor(_connection: SalesforceConnection, _cache?: MetadataCache | undefined);
|
|
2035
|
+
/** `GET /ui-api/object-info/{name}`: fields, record types and defaults as the UI sees them. Cached. */
|
|
2036
|
+
objectInfo<K extends SObjectName<R>>(sobject: K, options?: {
|
|
2037
|
+
signal?: AbortSignal;
|
|
2038
|
+
}): Promise<ObjectInfo>;
|
|
2039
|
+
/** Picklist values of every picklist field for a record type. */
|
|
2040
|
+
picklistValues<K extends SObjectName<R>>(sobject: K, recordTypeId: string, options?: {
|
|
2041
|
+
signal?: AbortSignal;
|
|
2042
|
+
}): Promise<Record<string, PicklistValues>>;
|
|
2043
|
+
/** Picklist values of one field for a record type. */
|
|
2044
|
+
picklistValues<K extends SObjectName<R>>(sobject: K, recordTypeId: string, field: SObjectFieldName<R, K>, options?: {
|
|
2045
|
+
signal?: AbortSignal;
|
|
2046
|
+
}): Promise<PicklistValues>;
|
|
2047
|
+
/**
|
|
2048
|
+
* `GET /ui-api/records/{id}` with typed field names. At least one of `fields`,
|
|
2049
|
+
* `optionalFields` or `layoutTypes` is required.
|
|
2050
|
+
*
|
|
2051
|
+
* ```ts
|
|
2052
|
+
* const record = await sf.uiApi.record("Account", id, { fields: ["Name", "Industry"] });
|
|
2053
|
+
* record.fields.Name.displayValue;
|
|
2054
|
+
* ```
|
|
2055
|
+
*/
|
|
2056
|
+
record<K extends SObjectName<R>, F extends SObjectFieldName<R, K>>(sobject: K, id: string, options: UiRecordOptions<F>): Promise<UiRecord<UiRecordFields<R, K, F>>>;
|
|
2057
|
+
/** `GET /ui-api/layout/{name}`: the page layout sections, rows and fields. */
|
|
2058
|
+
layout<K extends SObjectName<R>>(sobject: K, options?: UiLayoutOptions): Promise<UiLayout>;
|
|
2059
|
+
}
|
|
2060
|
+
//#endregion
|
|
2061
|
+
//#region src/client.d.ts
|
|
2062
|
+
interface SalesforceClientOptions {
|
|
2063
|
+
/** Where access tokens come from: `accessToken()`, `clientCredentials()`, `jwtBearer()`, ... */
|
|
2064
|
+
auth: AuthProvider;
|
|
2065
|
+
/**
|
|
2066
|
+
* The REST API version, e.g. `"v66.0"`. Required: there is no default, so a Salesforce release
|
|
2067
|
+
* never changes the version you call. Tip: pass the `API_VERSION` constant exported by your
|
|
2068
|
+
* generated types, so requests use the version the types were generated with.
|
|
2069
|
+
*/
|
|
2070
|
+
apiVersion: ApiVersion;
|
|
2071
|
+
/** The HTTP transport. Defaults to `fetchTransport()`; pass your own to use another HTTP client. */
|
|
2072
|
+
transport?: HttpTransport;
|
|
2073
|
+
/** Per-request timeout in milliseconds. Defaults to 120 000. Use `0` to disable. */
|
|
2074
|
+
timeoutMs?: number;
|
|
2075
|
+
/** Opt-in retries on 429/5xx. Only `GET`/`HEAD` are retried unless a request sets `retry: true`. */
|
|
2076
|
+
retry?: RetryOptions | boolean;
|
|
2077
|
+
/** Extra origins (besides the instance URL) that absolute URLs may point to. */
|
|
2078
|
+
allowedOrigins?: string[];
|
|
2079
|
+
/** Headers sent with every request, e.g. `{ "Sforce-Call-Options": "client=my-app" }`. */
|
|
2080
|
+
headers?: Record<string, string>;
|
|
2081
|
+
/** Observability hooks. Tokens are redacted. */
|
|
2082
|
+
hooks?: RequestHooks;
|
|
2083
|
+
/**
|
|
2084
|
+
* Cache metadata (describe, UI API object info, record type ids) in memory for the lifetime of
|
|
2085
|
+
* the client. Defaults to `true`; clear it with `clearCache()`.
|
|
2086
|
+
*/
|
|
2087
|
+
cache?: boolean;
|
|
2088
|
+
}
|
|
2089
|
+
interface ApexRestRequest extends Omit<RestRequest, "path"> {
|
|
2090
|
+
/** The `urlMapping` of the `@RestResource`, e.g. `"/accounts/001..."` (namespace included if any). */
|
|
2091
|
+
path: string;
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* A type-safe Salesforce REST API client.
|
|
2095
|
+
*
|
|
2096
|
+
* ```ts
|
|
2097
|
+
* import type { SObjectRegistry } from "./generated/sobjects";
|
|
2098
|
+
*
|
|
2099
|
+
* const sf = new SalesforceClient<SObjectRegistry>({
|
|
2100
|
+
* auth: clientCredentials({ loginUrl, clientId, clientSecret }),
|
|
2101
|
+
* });
|
|
2102
|
+
* const id = await sf.sobject("Account").create({ Name: "Acme" });
|
|
2103
|
+
* ```
|
|
2104
|
+
*
|
|
2105
|
+
* Without a registry type argument the client is untyped: any sObject name and field is accepted.
|
|
2106
|
+
*/
|
|
2107
|
+
export declare class SalesforceClient<R extends object = GenericRegistry> {
|
|
2108
|
+
/** The low-level executor, for advanced use. */
|
|
2109
|
+
readonly connection: SalesforceConnection;
|
|
2110
|
+
/** SOSL, parameterized search and search suggestions. */
|
|
2111
|
+
readonly search: SearchApi;
|
|
2112
|
+
/** Composite, composite batch, sObject tree and composite graph. */
|
|
2113
|
+
readonly composite: CompositeApi<R>;
|
|
2114
|
+
/** sObject collections: up to 200 records per call. */
|
|
2115
|
+
readonly collections: CollectionsApi<R>;
|
|
2116
|
+
/** Invocable actions, including Flows and Apex `@InvocableMethod`s. */
|
|
2117
|
+
readonly actions: ActionsApi;
|
|
2118
|
+
/** The Tooling API. */
|
|
2119
|
+
readonly tooling: ToolingApi;
|
|
2120
|
+
/** Bulk API 2.0 ingest and query jobs. */
|
|
2121
|
+
readonly bulk: BulkApi<R>;
|
|
2122
|
+
/** Publish platform events. */
|
|
2123
|
+
readonly events: EventsApi<R>;
|
|
2124
|
+
/** Approval processes: submit, approve, reject. */
|
|
2125
|
+
readonly approvals: ApprovalsApi;
|
|
2126
|
+
/** Global quick actions (per-sObject actions are on `sobject(name).quickActions`). */
|
|
2127
|
+
readonly quickActions: QuickActionsApi;
|
|
2128
|
+
/** User Interface API: object info, picklist values per record type, records, layouts. */
|
|
2129
|
+
readonly uiApi: UiApi<R>;
|
|
2130
|
+
/** Salesforce Files: upload, download, new versions, sharing. */
|
|
2131
|
+
readonly files: FilesApi;
|
|
2132
|
+
/** Reports: run synchronously or asynchronously and flatten the rows. */
|
|
2133
|
+
readonly reports: ReportsApi;
|
|
2134
|
+
private readonly _queries;
|
|
2135
|
+
private readonly _cache;
|
|
2136
|
+
constructor(options: SalesforceClientOptions);
|
|
2137
|
+
/** Drops cached metadata (describe results, object info, record type ids). */
|
|
2138
|
+
clearCache(): void;
|
|
2139
|
+
get apiVersion(): ApiVersion;
|
|
2140
|
+
/** API usage as reported by the last response (`Sforce-Limit-Info`). */
|
|
2141
|
+
get apiUsage(): ApiUsage | undefined;
|
|
2142
|
+
/** The instance URL of the current access token (authenticates if needed). */
|
|
2143
|
+
instanceUrl(options?: {
|
|
2144
|
+
signal?: AbortSignal;
|
|
2145
|
+
}): Promise<string>;
|
|
2146
|
+
/**
|
|
2147
|
+
* Calls any REST resource. `path` is relative to `/services/data/{apiVersion}` unless it
|
|
2148
|
+
* starts with `/services/` or is an absolute URL on the instance.
|
|
2149
|
+
*
|
|
2150
|
+
* ```ts
|
|
2151
|
+
* const limits = await sf.request<OrgLimits>({ path: "/limits" });
|
|
2152
|
+
* ```
|
|
2153
|
+
*/
|
|
2154
|
+
request<T = unknown>(request: RestRequest): Promise<T>;
|
|
2155
|
+
/** Like `request`, but also returns the status and response headers. */
|
|
2156
|
+
requestWithResponse<T = unknown>(request: RestRequest): Promise<RestResponse<T>>;
|
|
2157
|
+
/** Calls an Apex REST endpoint (`/services/apexrest/...`). */
|
|
2158
|
+
apexRest<T = unknown>(request: ApexRestRequest): Promise<T>;
|
|
2159
|
+
/** Typed operations on one sObject. */
|
|
2160
|
+
sobject<K extends SObjectName<R>>(name: K): SObjectResource<R, K>;
|
|
2161
|
+
/** Starts a typed SOQL query. Run it with `query`, `queryAll`, `iterate` or `collect`. */
|
|
2162
|
+
soql<K extends SObjectName<R>>(sobjectName: K): SoqlQueryBuilder<R, K>;
|
|
2163
|
+
/** Runs a query and returns the first page. Follow `nextRecordsUrl` with `queryMore`. */
|
|
2164
|
+
query<K extends SObjectName<R>, S extends object = NoSelection>(query: SoqlQueryBuilder<R, K, S>, options?: QueryOptions): Promise<QueryResult<SoqlQueryRecord<R, K, S>>>;
|
|
2165
|
+
query<T = GenericRecord>(soql: string, options?: QueryOptions): Promise<QueryResult<T>>;
|
|
2166
|
+
/** Fetches the next page of a query. */
|
|
2167
|
+
queryMore<T>(cursor: QueryCursor<T>, options?: Pick<QueryOptions, "batchSize" | "signal">): Promise<QueryResult<T>>;
|
|
2168
|
+
/** Yields every record of a query, fetching pages lazily. */
|
|
2169
|
+
iterate<K extends SObjectName<R>, S extends object = NoSelection>(query: SoqlQueryBuilder<R, K, S>, options?: QueryOptions): AsyncGenerator<SoqlQueryRecord<R, K, S>, void, undefined>;
|
|
2170
|
+
iterate<T = GenericRecord>(soql: string, options?: QueryOptions): AsyncGenerator<T, void, undefined>;
|
|
2171
|
+
/** Fetches all pages of a query and returns every record. */
|
|
2172
|
+
collect<K extends SObjectName<R>, S extends object = NoSelection>(query: SoqlQueryBuilder<R, K, S>, options?: QueryOptions): Promise<SoqlQueryRecord<R, K, S>[]>;
|
|
2173
|
+
collect<T = GenericRecord>(soql: string, options?: QueryOptions): Promise<T[]>;
|
|
2174
|
+
/** `GET /services/data`: every API version the org supports. Does not count against limits. */
|
|
2175
|
+
versions(options?: {
|
|
2176
|
+
signal?: AbortSignal;
|
|
2177
|
+
}): Promise<ApiVersionInfo[]>;
|
|
2178
|
+
/** `GET /services/data/{version}`: the resources available in this version. */
|
|
2179
|
+
resources(options?: {
|
|
2180
|
+
signal?: AbortSignal;
|
|
2181
|
+
}): Promise<Record<string, string>>;
|
|
2182
|
+
/** `GET /limits`: org limits such as `DailyApiRequests`. */
|
|
2183
|
+
limits(options?: {
|
|
2184
|
+
signal?: AbortSignal;
|
|
2185
|
+
}): Promise<OrgLimits>;
|
|
2186
|
+
/** `GET /limits/recordCount`: approximate record counts per sObject. */
|
|
2187
|
+
recordCount(sobjects: readonly SObjectName<R>[], options?: {
|
|
2188
|
+
signal?: AbortSignal;
|
|
2189
|
+
}): Promise<RecordCountResult>;
|
|
2190
|
+
/** `GET /sobjects`: every sObject visible to the user. */
|
|
2191
|
+
describeGlobal(options?: {
|
|
2192
|
+
signal?: AbortSignal;
|
|
2193
|
+
}): Promise<DescribeGlobalResult>;
|
|
2194
|
+
/**
|
|
2195
|
+
* Asks Salesforce how it would run a query (`GET /query?explain=`, beta), e.g. to check a
|
|
2196
|
+
* filter is selective. Plans are sorted best first; `relativeCost` above 1 means not selective.
|
|
2197
|
+
*/
|
|
2198
|
+
explain(query: string | {
|
|
2199
|
+
build(): string;
|
|
2200
|
+
}, options?: {
|
|
2201
|
+
signal?: AbortSignal;
|
|
2202
|
+
}): Promise<QueryPlan[]>;
|
|
2203
|
+
}
|
|
2204
|
+
//#endregion
|
|
2205
|
+
//#region src/auth/providers.d.ts
|
|
2206
|
+
/** Uses a fixed access token, e.g. one issued by the Salesforce CLI (`sf org display`). */
|
|
2207
|
+
export declare function accessToken(token: AccessToken): AuthProvider;
|
|
2208
|
+
/**
|
|
2209
|
+
* Wraps your own token source. The result is cached until Salesforce answers 401, after which
|
|
2210
|
+
* `fetchToken` is called again.
|
|
2211
|
+
*/
|
|
2212
|
+
export declare function tokenProvider(fetchToken: (context: AuthContext) => Promise<AccessToken>): AuthProvider;
|
|
2213
|
+
interface ClientCredentialsOptions {
|
|
2214
|
+
/** Your My Domain URL, e.g. `https://mydomain.my.salesforce.com`. Required for this flow. */
|
|
2215
|
+
loginUrl: string;
|
|
2216
|
+
clientId: string;
|
|
2217
|
+
clientSecret: string;
|
|
2218
|
+
/** Optional space-separated scopes. */
|
|
2219
|
+
scope?: string;
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* OAuth 2.0 client credentials flow (server-to-server, runs as the app's "Run As" user).
|
|
2223
|
+
* The token is cached in memory and refreshed once when Salesforce answers 401.
|
|
2224
|
+
*/
|
|
2225
|
+
export declare function clientCredentials(options: ClientCredentialsOptions): AuthProvider;
|
|
2226
|
+
interface JwtBearerOptions {
|
|
2227
|
+
/** `https://login.salesforce.com`, `https://test.salesforce.com` or your My Domain URL. */
|
|
2228
|
+
loginUrl: string;
|
|
2229
|
+
/** The consumer key of the connected app / external client app. */
|
|
2230
|
+
clientId: string;
|
|
2231
|
+
/** The username to act as. */
|
|
2232
|
+
username: string;
|
|
2233
|
+
/** The PEM-encoded RSA private key whose certificate is uploaded to the app. */
|
|
2234
|
+
privateKey: string;
|
|
2235
|
+
/**
|
|
2236
|
+
* The JWT `aud` claim. Defaults to `https://test.salesforce.com` for sandbox login URLs and
|
|
2237
|
+
* `https://login.salesforce.com` otherwise.
|
|
2238
|
+
*/
|
|
2239
|
+
audience?: string;
|
|
2240
|
+
/** Lifetime of the assertion in seconds (max 180). Defaults to 180. */
|
|
2241
|
+
expiresInSeconds?: number;
|
|
2242
|
+
}
|
|
2243
|
+
/** OAuth 2.0 JWT bearer flow. The assertion is signed locally with RS256; no extra dependencies. */
|
|
2244
|
+
export declare function jwtBearer(options: JwtBearerOptions): AuthProvider;
|
|
2245
|
+
interface RefreshTokenOptions {
|
|
2246
|
+
loginUrl: string;
|
|
2247
|
+
clientId: string;
|
|
2248
|
+
/** Required unless the app is configured without a secret for the refresh token flow. */
|
|
2249
|
+
clientSecret?: string;
|
|
2250
|
+
refreshToken: string;
|
|
2251
|
+
/** Called when Salesforce rotates the refresh token, so you can store the new one. Errors it throws are ignored. */
|
|
2252
|
+
onRefreshTokenRotated?: (refreshToken: string) => void;
|
|
2253
|
+
}
|
|
2254
|
+
/** Exchanges a refresh token for access tokens. */
|
|
2255
|
+
export declare function refreshToken(options: RefreshTokenOptions): AuthProvider;
|
|
2256
|
+
/** Builds a signed RS256 JWT assertion for the JWT bearer flow. Exported for testing. */
|
|
2257
|
+
export declare function createJwtAssertion(options: JwtBearerOptions, now?: number): string;
|
|
2258
|
+
//#endregion
|
|
2259
|
+
//#region src/auth/sf-cli.d.ts
|
|
2260
|
+
/** Runs a command and returns its stdout. Resolves even on a non-zero exit when stdout was written. */
|
|
2261
|
+
type RunCommand = (command: string, args: readonly string[]) => Promise<string>;
|
|
2262
|
+
interface SfCliOptions {
|
|
2263
|
+
/** The org alias or username (`--target-org`). Defaults to the CLI's default org. */
|
|
2264
|
+
targetOrg?: string;
|
|
2265
|
+
/** The CLI executable. Defaults to `sf`. */
|
|
2266
|
+
command?: string;
|
|
2267
|
+
/** Replaces how the CLI is run, e.g. in tests. */
|
|
2268
|
+
runCommand?: RunCommand;
|
|
2269
|
+
}
|
|
2270
|
+
/**
|
|
2271
|
+
* Uses an org you are logged into with the Salesforce CLI (`sf org login web --alias my-org`).
|
|
2272
|
+
* Handy for local development: no connected app or secrets needed.
|
|
2273
|
+
*
|
|
2274
|
+
* The token comes from `sf org auth show-access-token`, the instance URL from `sf org display`
|
|
2275
|
+
* (which no longer returns tokens). Both run without a shell. On a 401 the CLI is asked again;
|
|
2276
|
+
* it refreshes the token itself.
|
|
2277
|
+
*/
|
|
2278
|
+
export declare function sfCli(options?: SfCliOptions): AuthProvider;
|
|
2279
|
+
//#endregion
|
|
2280
|
+
//#region src/api-version.d.ts
|
|
2281
|
+
/** `true` for a version such as `"v66.0"`. */
|
|
2282
|
+
export declare function isApiVersion(value: unknown): value is ApiVersion;
|
|
2283
|
+
/**
|
|
2284
|
+
* Accepts the ways people write an API version (`"66"`, `"66.0"`, `"v66"`, `"v66.0"`) and
|
|
2285
|
+
* returns the canonical form (`"v66.0"`), or `undefined` when the input is not a version.
|
|
2286
|
+
*/
|
|
2287
|
+
export declare function normalizeApiVersion(input: string): ApiVersion | undefined;
|
|
2288
|
+
//#endregion
|
|
2289
|
+
//#region src/http/fetch-transport.d.ts
|
|
2290
|
+
interface FetchTransportOptions {
|
|
2291
|
+
/** A custom `fetch` implementation. Defaults to `globalThis.fetch`. */
|
|
2292
|
+
fetch?: typeof fetch;
|
|
2293
|
+
}
|
|
2294
|
+
/** The default transport, built on the platform `fetch` (Node.js 20+). Supports streaming. */
|
|
2295
|
+
export declare function fetchTransport(options?: FetchTransportOptions): HttpTransport;
|
|
2296
|
+
//#endregion
|
|
2297
|
+
//#region src/errors.d.ts
|
|
2298
|
+
interface SalesforceErrorDetails {
|
|
2299
|
+
status: number;
|
|
2300
|
+
method: HttpMethod;
|
|
2301
|
+
/**
|
|
2302
|
+
* The request path without the query string (query strings can hold SOQL with personal data).
|
|
2303
|
+
* Note that Salesforce's own error `message` may still quote parts of the query.
|
|
2304
|
+
*/
|
|
2305
|
+
path: string;
|
|
2306
|
+
body: unknown;
|
|
2307
|
+
headers: Record<string, string>;
|
|
2308
|
+
}
|
|
2309
|
+
/** Thrown for every non-2xx Salesforce REST response. */
|
|
2310
|
+
export declare class SalesforceError extends Error {
|
|
2311
|
+
readonly name: string;
|
|
2312
|
+
readonly status: number;
|
|
2313
|
+
readonly method: HttpMethod;
|
|
2314
|
+
readonly path: string;
|
|
2315
|
+
/** The `errorCode` of the first error, e.g. `"MALFORMED_QUERY"` or `"INVALID_FIELD"`. */
|
|
2316
|
+
readonly errorCode: SalesforceErrorCode | undefined;
|
|
2317
|
+
/** All errors Salesforce returned, when the body was the standard error array. */
|
|
2318
|
+
readonly errors: RestError[];
|
|
2319
|
+
/** The parsed response body. */
|
|
2320
|
+
readonly body: unknown;
|
|
2321
|
+
/** Response headers, without `set-cookie`. */
|
|
2322
|
+
readonly headers: Record<string, string>;
|
|
2323
|
+
/** The value of the `Sforce-Limit-Info` header, e.g. `"api-usage=18/15000"`. */
|
|
2324
|
+
readonly limitInfo: string | undefined;
|
|
2325
|
+
constructor(details: SalesforceErrorDetails);
|
|
2326
|
+
}
|
|
2327
|
+
/** Thrown when an OAuth token request fails. Never contains secrets or tokens. */
|
|
2328
|
+
export declare class SalesforceAuthError extends Error {
|
|
2329
|
+
readonly name: string;
|
|
2330
|
+
readonly status: number | undefined;
|
|
2331
|
+
/** The OAuth `error` code, e.g. `"invalid_client"` or `"invalid_grant"`. */
|
|
2332
|
+
readonly error: string | undefined;
|
|
2333
|
+
readonly errorDescription: string | undefined;
|
|
2334
|
+
constructor(message: string, details?: {
|
|
2335
|
+
status?: number;
|
|
2336
|
+
error?: string;
|
|
2337
|
+
errorDescription?: string;
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
/**
|
|
2341
|
+
* Thrown when a call returned HTTP 2xx but one or more items reported `success: false`
|
|
2342
|
+
* (record create, sObject collections, invocable actions, ...).
|
|
2343
|
+
*/
|
|
2344
|
+
export declare class SalesforceSaveError<TResult = unknown> extends Error {
|
|
2345
|
+
readonly name: string;
|
|
2346
|
+
/** Every item result, including the successful ones. */
|
|
2347
|
+
readonly results: TResult[];
|
|
2348
|
+
/** The errors of all failed items, flattened. */
|
|
2349
|
+
readonly errors: SaveError[];
|
|
2350
|
+
constructor(message: string, results: TResult[], errors: SaveError[]);
|
|
2351
|
+
}
|
|
2352
|
+
/** Thrown when a Bulk API 2.0 job ends in `Failed` or `Aborted`, or does not finish in time. */
|
|
2353
|
+
export declare class SalesforceBulkJobError extends Error {
|
|
2354
|
+
readonly name: string;
|
|
2355
|
+
readonly jobId: string;
|
|
2356
|
+
readonly state: string;
|
|
2357
|
+
readonly jobInfo: unknown;
|
|
2358
|
+
constructor(message: string, jobId: string, state: string, jobInfo: unknown);
|
|
2359
|
+
}
|
|
2360
|
+
/**
|
|
2361
|
+
* `true` when `error` is a `SalesforceError` (non-2xx response), optionally with `code` as one of
|
|
2362
|
+
* its error codes.
|
|
2363
|
+
*/
|
|
2364
|
+
export declare function isSalesforceError(error: unknown, code?: SalesforceErrorCode): error is SalesforceError;
|
|
2365
|
+
/**
|
|
2366
|
+
* `true` when `error` carries error code `code`: a `SalesforceError` from a failed request, or a
|
|
2367
|
+
* `SalesforceSaveError` with a failed item (save results, collections, actions). Handy for
|
|
2368
|
+
* `catch` blocks and retry decisions, e.g. `hasErrorCode(error, "UNABLE_TO_LOCK_ROW")`.
|
|
2369
|
+
*/
|
|
2370
|
+
export declare function hasErrorCode(error: unknown, code: SalesforceErrorCode): boolean;
|
|
2371
|
+
/**
|
|
2372
|
+
* Thrown when a call split into several requests (chunked collections, batched events) fails
|
|
2373
|
+
* after earlier chunks already succeeded. `completedResults` holds the results of those chunks,
|
|
2374
|
+
* which Salesforce has committed; `cause` is the error of the failing chunk.
|
|
2375
|
+
*/
|
|
2376
|
+
export declare class SalesforcePartialFailureError<TResult = unknown> extends Error {
|
|
2377
|
+
readonly name: string;
|
|
2378
|
+
readonly completedResults: TResult[];
|
|
2379
|
+
readonly cause: unknown;
|
|
2380
|
+
constructor(message: string, completedResults: TResult[], cause: unknown);
|
|
2381
|
+
}
|
|
2382
|
+
//#endregion
|
|
2383
|
+
//#region src/http/multipart.d.ts
|
|
2384
|
+
interface MultipartPart {
|
|
2385
|
+
/** The form field name, e.g. `entity_content` or `VersionData`. */
|
|
2386
|
+
name: string;
|
|
2387
|
+
filename?: string;
|
|
2388
|
+
contentType: string;
|
|
2389
|
+
data: string | Uint8Array;
|
|
2390
|
+
}
|
|
2391
|
+
/**
|
|
2392
|
+
* Builds a `multipart/form-data` body as bytes, so it can go through any transport without
|
|
2393
|
+
* FormData support.
|
|
2394
|
+
*/
|
|
2395
|
+
export declare function buildMultipart(parts: readonly MultipartPart[], boundary?: string): {
|
|
2396
|
+
body: Uint8Array;
|
|
2397
|
+
contentType: string;
|
|
2398
|
+
};
|
|
2399
|
+
//#endregion
|
|
2400
|
+
//#region src/resources/csv.d.ts
|
|
2401
|
+
interface CsvOptions {
|
|
2402
|
+
delimiter?: string;
|
|
2403
|
+
lineEnding?: BulkLineEnding;
|
|
2404
|
+
}
|
|
2405
|
+
/**
|
|
2406
|
+
* Serializes records to Bulk API CSV. Columns are the union of all keys in first-seen order.
|
|
2407
|
+
* `null` becomes `#N/A` (clears the field), `undefined` stays empty (leaves it unchanged),
|
|
2408
|
+
* `Date` becomes an ISO string (a Date field takes its UTC date), the text `"#N/A"` is written so
|
|
2409
|
+
* that it is stored as text rather than as null, and one level of nesting becomes a relationship column, so
|
|
2410
|
+
* `{ Account: { External_Id__c: "A1" } }` is written as column `Account.External_Id__c`.
|
|
2411
|
+
*/
|
|
2412
|
+
export declare function toCsv(records: readonly object[], options?: CsvOptions): string;
|
|
2413
|
+
/**
|
|
2414
|
+
* An incremental RFC 4180 CSV parser: feed it text chunks with `push` and it returns the rows
|
|
2415
|
+
* completed so far. Quotes, escaped quotes and CRLF may be split across chunks.
|
|
2416
|
+
*
|
|
2417
|
+
* A truly blank line is returned as an empty array (`[]`), so it can be told apart from a row
|
|
2418
|
+
* with one empty value (`[""]`, e.g. a quoted `""` in a single-column file).
|
|
2419
|
+
*/
|
|
2420
|
+
export declare class CsvRowParser {
|
|
2421
|
+
private readonly _delimiter;
|
|
2422
|
+
private _row;
|
|
2423
|
+
private _field;
|
|
2424
|
+
private _inQuotes;
|
|
2425
|
+
/** The current field was quoted, so it exists even when empty. */
|
|
2426
|
+
private _fieldQuoted;
|
|
2427
|
+
/** A `"` was seen inside quotes; the next character decides whether it was an escaped quote. */
|
|
2428
|
+
private _quotePending;
|
|
2429
|
+
/** The last row ended with `\r`; a following `\n` belongs to it. */
|
|
2430
|
+
private _skipLineFeed;
|
|
2431
|
+
private _started;
|
|
2432
|
+
constructor(_delimiter?: string);
|
|
2433
|
+
/** Parses a chunk and returns the rows it completed. */
|
|
2434
|
+
push(chunk: string): string[][];
|
|
2435
|
+
/** Finishes parsing and returns the last row, if any. */
|
|
2436
|
+
end(): string[][];
|
|
2437
|
+
private consume;
|
|
2438
|
+
private consumeUnquoted;
|
|
2439
|
+
}
|
|
2440
|
+
/** Parses CSV (RFC 4180: quoted fields, escaped quotes, CRLF or LF) into rows of strings. */
|
|
2441
|
+
export declare function parseCsvRows(text: string, delimiter?: string): string[][];
|
|
2442
|
+
/**
|
|
2443
|
+
* Parses streamed CSV (with a header row) into objects keyed by column name, yielding each row
|
|
2444
|
+
* as soon as it is complete.
|
|
2445
|
+
*/
|
|
2446
|
+
export declare function parseCsvStream(chunks: AsyncIterable<Uint8Array>, delimiter?: string): AsyncGenerator<Record<string, string>, void, undefined>;
|
|
2447
|
+
/** Parses CSV with a header row into objects keyed by column name. */
|
|
2448
|
+
export declare function parseCsv(text: string, delimiter?: string): Record<string, string>[];
|
|
2449
|
+
//#endregion
|
|
2450
|
+
export type { AccessToken, ActionDescribe, ActionParameterDescribe, ActionSummary, ApexLogEntry, ApexRestRequest, ApiUsage, ApiVersion, ApiVersionInfo, ApprovalProcessInfo, ApprovalResult, AuthContext, AuthProvider, BulkColumnDelimiter, BulkCsvRecord, BulkIngestJobOptions, BulkIngestOperation, BulkIngestOptions, BulkIngestRecord, BulkJobInfo, BulkJobState, BulkLineEnding, BulkQueryOperation, BulkQueryOptions, CaptureLogsOptions, CaptureLogsResult, ChildRelationship, ChildRelationshipName, ChildSObjectName, ClientCredentialsOptions, CollectionOptions, CompositeBatchRequest, CompositeBatchResult, CompositeBatchSubrequest, CompositeGraphInput, CompositeGraphResult, CompositeMethod, CompositeOptions, CompositeRawSubrequest, CompositeRef, CompositeSubrequest, CompositeSubrequestResult, ConnectionOptions, CsvOptions, CustomActionType, DebugLevels, DecisionOptions, DeleteResult, DeletedRecordsResult, DescribeGlobalResult, DescribeGlobalSObject, DescribeSObjectResult, ExecuteAnonymousOptions, ExecuteAnonymousResult, ExternalIdField, FetchTransportOptions, FieldDescribe, FieldKind, FieldKindName, FieldType, FileShareType, FileVisibility, GenericRecord, GenericRegistry, HttpMethod, HttpTransport, InvocableActionResult, InvokeOptions, InvokeQuickActionOptions, JwtBearerOptions, KnownOrgLimit, KnownSalesforceErrorCode, LimitInfo, LogLevel, MultiPicklistField, MultipartPart, NestPath, NewVersionOptions, NoSelection, OAuthTokenResponse, ObjectInfo, OrgLimits, ParameterizedSearchRequest, ParameterizedSearchSObject, ParentPath, ParentPathTarget, ParentRelationshipName, ParentSObjectName, PathTarget, PendingApprovalWorkItem, PicklistEntry, PicklistOption, PicklistValue, PicklistValues, PlatformEventName, PolymorphicName, PolymorphicNameField, PolymorphicRelationshipName, PolymorphicTargets, PublishOptions, PublishResult, QueryCursor, QueryOptions, QueryParamValue, QueryPlan, QueryResponse, QueryResult, QuickActionDescribe, QuickActionResult, QuickActionSummary, RecordAttributes, RecordCountResult, RecordTypeInfo, RecordTypeName, RefreshTokenOptions, ReportDataCell, ReportDescribe, ReportExtendedMetadata, ReportFact, ReportFilter, ReportInstance, ReportMetadata, ReportResult, ReportRow, ReportSummary, RequestEvent, RequestHooks, RequestSignal, ResponseEvent, ResponseType, RestError, RestRequest, RestResponse, RetryOptions, RunCommand, RunReportOptions, RunTestsRequest, RunTestsResult, SObjectBasicInfo, SObjectCreateInput, SObjectFieldName, SObjectName, SObjectRecord, SObjectRegistryEntry, SObjectUpdateInput, SalesforceAddress, SalesforceClientOptions, SalesforceErrorCode, SalesforceGeolocation, SaveError, SaveResult, SearchResult, SearchSuggestionsOptions, SearchSuggestionsResult, SfCliOptions, SoqlChildQueryResult, SoqlComparisonOperator, SoqlDirection, SoqlFieldValue, SoqlFixedDateLiteral, SoqlLiteral, SoqlNullOrder, SoqlOperator, SoqlOperatorFor, SoqlQueryRecord, SoqlRelativeDateLiteral, SoqlScalar, SoqlValue, SoqlWhereValue, StreamingTransportResponse, SubmitOptions, SubrequestOptions, TransportRequest, TransportResponse, TreeChildRecord, TreeRecord, TreeSaveResult, TypedRecord, UiFieldInfo, UiFieldValue, UiLayout, UiLayoutComponent, UiLayoutOptions, UiRecord, UiRecordFields, UiRecordOptions, UiRecordTypeInfo, UpdatedRecordsResult, UploadFileOptions, UploadedFile, UpsertOutcome, UpsertResult, WaitForReportOptions, WaitOptions, WithAttributes };
|
|
2451
|
+
//# sourceMappingURL=index.d.mts.map
|