1 | import { EventEmitter } from 'events';
|
2 | import {
|
3 | BatchDescribeSObjectOptions,
|
4 | DescribeSObjectOptions,
|
5 | DescribeSObjectResult,
|
6 | DescribeGlobalResult,
|
7 | } from './describe-result';
|
8 | import { Query, QueryResult, ExecuteOptions } from './query';
|
9 | import { Record } from './record';
|
10 | import { RecordResult } from './record-result';
|
11 | import { SObject } from './salesforce-object';
|
12 | import { Analytics } from './api/analytics';
|
13 | import { Chatter } from './api/chatter';
|
14 | import { Metadata } from './api/metadata';
|
15 | import { SoapApi } from './api/soap';
|
16 | import { Apex } from './api/apex';
|
17 | import { Bulk } from './bulk';
|
18 | import { Cache } from './cache';
|
19 | import { OAuth2, Streaming } from '.';
|
20 | import { HttpApiOptions } from './http-api';
|
21 | import { LimitInfo, LimitsInfo } from './limits-info';
|
22 |
|
23 | export type Callback<T> = (err: Error | null, result: T) => void;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | export interface RestApiOptions {
|
29 | headers?: { [x: string]: string } | undefined;
|
30 | allowRecursive?: boolean | undefined;
|
31 | allOrNone?: boolean | undefined;
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 | export interface PartialOAuth2Options {
|
37 | clientId?: string | undefined;
|
38 | clientSecret?: string | undefined;
|
39 | loginUrl?: string | undefined;
|
40 | redirectUri?: string | undefined;
|
41 | tokenServiceUrl?: string | undefined;
|
42 | authzServiceUrl?: string | undefined;
|
43 | }
|
44 |
|
45 | export interface RequestInfo {
|
46 | body?: string | undefined;
|
47 | headers?: object | undefined;
|
48 | method?: string | undefined;
|
49 | url?: string | undefined;
|
50 | }
|
51 |
|
52 | export interface ConnectionOptions extends PartialOAuth2Options {
|
53 | accessToken?: string | undefined;
|
54 | callOptions?: Object | undefined;
|
55 | instanceUrl?: string | undefined;
|
56 | loginUrl?: string | undefined;
|
57 | logLevel?: string | undefined;
|
58 | maxRequest?: number | undefined;
|
59 | oauth2?: Partial<PartialOAuth2Options> | undefined;
|
60 | proxyUrl?: string | undefined;
|
61 | httpProxy?: string | undefined;
|
62 | redirectUri?: string | undefined;
|
63 | refreshToken?: string | undefined;
|
64 | refreshFn?:
|
65 | | ((conn: Connection, callback: (err: Error | null, accessToken: string, res?: unknown) => void) => unknown)
|
66 | | undefined;
|
67 | serverUrl?: string | undefined;
|
68 | sessionId?: string | undefined;
|
69 | signedRequest?: string | Object | undefined;
|
70 | version?: string | undefined;
|
71 | }
|
72 |
|
73 | export interface UserInfo {
|
74 | id: string;
|
75 | organizationId: string;
|
76 | url: string;
|
77 | }
|
78 |
|
79 | // The identity URL is a RESTful API to query for additional information
|
80 | // about users, such as their username, email address, and org ID.
|
81 | // It also returns endpoints that the client can talk to,
|
82 | // such as photos for profiles and accessible API endpoints.
|
83 | // https://help.salesforce.com/articleView?id=remoteaccess_using_openid.htm
|
84 | // https://jsforce.github.io/jsforce/doc/Connection.html#identity
|
85 | export interface IdentityInfo {
|
86 | id: string;
|
87 | asserted_user: boolean;
|
88 | user_id: string;
|
89 | organization_id: string;
|
90 | username: string;
|
91 | nick_name: string;
|
92 | display_name: string;
|
93 | email: string;
|
94 | email_verified: boolean;
|
95 | first_name: string | null;
|
96 | last_name: string;
|
97 | timezone: string;
|
98 | photos: {
|
99 | picture: string;
|
100 | thumbnail: string;
|
101 | };
|
102 | addr_street: string | null;
|
103 | addr_city: string | null;
|
104 | addr_state: string | null;
|
105 | addr_country: string | null;
|
106 | addr_zip: string | null;
|
107 | mobile_phone: string | null;
|
108 | mobile_phone_verified: boolean;
|
109 | is_lightning_login_user: boolean;
|
110 | status: {
|
111 | created_date: Date | null;
|
112 | body: string | null;
|
113 | };
|
114 | urls: {
|
115 | enterprise: string;
|
116 | metadata: string;
|
117 | partner: string;
|
118 | rest: string;
|
119 | sobjects: string;
|
120 | search: string;
|
121 | query: string;
|
122 | recent: string;
|
123 | tooling_soap: string;
|
124 | tooling_rest: string;
|
125 | profile: string;
|
126 | feeds: string;
|
127 | groups: string;
|
128 | users: string;
|
129 | feed_items: string;
|
130 | feed_elements: string;
|
131 | custom_domain?: string | undefined;
|
132 | };
|
133 | active: boolean;
|
134 | user_type: string;
|
135 | language: string;
|
136 | locale: string;
|
137 | utcOffset: number;
|
138 | last_modified_date: Date;
|
139 | is_app_installed: boolean;
|
140 | // And possible other attributes.
|
141 | [key: string]: any;
|
142 | }
|
143 |
|
144 | export abstract class RestApi {
|
145 | get(path: string, options: object, callback: () => object): Promise<object>;
|
146 | post(path: string, body: object, options: object, callback: () => object): Promise<object>;
|
147 | put(path: string, body: object, options: object, callback: () => object): Promise<object>;
|
148 | patch(path: string, body: object, options: object, callback: () => object): Promise<object>;
|
149 | del(path: string, options: object, callback: () => object): Promise<object>;
|
150 | }
|
151 |
|
152 | export interface ExecuteAnonymousResult {
|
153 | compiled: boolean;
|
154 | compileProblem: string;
|
155 | success: boolean;
|
156 | line: number;
|
157 | column: number;
|
158 | exceptionMessage: string;
|
159 | exceptionStackTrace: string;
|
160 | }
|
161 |
|
162 | export type ConnectionEvent = 'refresh';
|
163 |
|
164 | export interface SearchResult<T> {
|
165 | searchRecords: Record<T>[];
|
166 | }
|
167 |
|
168 | /**
|
169 | * the methods exposed here are done so that a client can use 'declaration augmentation' to get intellisense on their own projects.
|
170 | * for example, given a type
|
171 | *
|
172 | * interface Foo {
|
173 | * thing: string;
|
174 | * yes: boolean;
|
175 | * }
|
176 | *
|
177 | * you can write
|
178 | *
|
179 | * declare module "jsforce" {
|
180 | * interface Connection {
|
181 | * sobject(type: 'Foo'): SObject<Foo>
|
182 | * }
|
183 | * }
|
184 | *
|
185 | * to ensure that you have the correct data types for the various collection names.
|
186 | */
|
187 | export abstract class BaseConnection extends EventEmitter {
|
188 | _baseUrl(): string;
|
189 | request<T = object>(
|
190 | info: RequestInfo | string,
|
191 | options?: HttpApiOptions,
|
192 | callback?: (err: Error, Object: T) => void,
|
193 | ): Promise<T>;
|
194 | query<T>(
|
195 | soql: string,
|
196 | options?: ExecuteOptions,
|
197 | callback?: (err: Error, result: QueryResult<T>) => void,
|
198 | ): Query<QueryResult<T>>;
|
199 | queryMore<T>(
|
200 | locator: string,
|
201 | options?: ExecuteOptions,
|
202 | callback?: (err: Error, result: QueryResult<T>) => void,
|
203 | ): Promise<QueryResult<T>>;
|
204 | create<T>(
|
205 | type: string,
|
206 | records: Record<T> | Array<Record<T>>,
|
207 | options?: RestApiOptions,
|
208 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
209 | ): Promise<RecordResult | RecordResult[]>;
|
210 | create<T>(
|
211 | records: Record<T> | Array<Record<T>>,
|
212 | options?: RestApiOptions,
|
213 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
214 | ): Promise<RecordResult | RecordResult[]>;
|
215 | insert<T>(
|
216 | type: string,
|
217 | records: Record<T> | Array<Record<T>>,
|
218 | options?: RestApiOptions,
|
219 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
220 | ): Promise<RecordResult | RecordResult[]>;
|
221 | retrieve<T>(
|
222 | type: string,
|
223 | ids: string | string[],
|
224 | options?: RestApiOptions,
|
225 | callback?: (err: Error, result: Record<T> | Array<Record<T>>) => void,
|
226 | ): Promise<Record<T> | Array<Record<T>>>;
|
227 | update<T>(
|
228 | type: string,
|
229 | records: Record<T> | Array<Record<T>>,
|
230 | options?: RestApiOptions,
|
231 | callback?: (err: Error, result: RecordResult | Array<Record<T>>) => void,
|
232 | ): Promise<RecordResult | RecordResult[]>;
|
233 | update<T>(
|
234 | records: Record<T> | Array<Record<T>>,
|
235 | options?: RestApiOptions,
|
236 | callback?: (err: Error, result: RecordResult | Array<Record<T>>) => void,
|
237 | ): Promise<RecordResult | RecordResult[]>;
|
238 | upsert<T>(
|
239 | type: string,
|
240 | records: Record<T> | Array<Record<T>>,
|
241 | extIdField: string,
|
242 | options?: RestApiOptions,
|
243 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
244 | ): Promise<RecordResult | RecordResult[]>;
|
245 | upsert<T>(
|
246 | records: Record<T> | Array<Record<T>>,
|
247 | extIdField: string,
|
248 | options?: RestApiOptions,
|
249 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
250 | ): Promise<RecordResult | RecordResult[]>;
|
251 | del<T>(
|
252 | type: string,
|
253 | ids: string | string[],
|
254 | options?: RestApiOptions,
|
255 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
256 | ): Promise<RecordResult | RecordResult[]>;
|
257 | delete<T>(
|
258 | type: string,
|
259 | ids: string | string[],
|
260 | options?: RestApiOptions,
|
261 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
262 | ): Promise<RecordResult | RecordResult[]>;
|
263 | destroy<T>(
|
264 | type: string,
|
265 | ids: string | string[],
|
266 | options?: RestApiOptions,
|
267 | callback?: (err: Error, result: RecordResult | RecordResult[]) => void,
|
268 | ): Promise<RecordResult | RecordResult[]>;
|
269 | describe$: {
|
270 | /** Returns a value from the cache if it exists, otherwise calls Connection.describe */
|
271 | (
|
272 | type: string | DescribeSObjectOptions,
|
273 | callback?: (err: Error, result: DescribeSObjectResult) => void,
|
274 | ): DescribeSObjectResult;
|
275 | clear(): void;
|
276 | };
|
277 | describe(
|
278 | type: string | DescribeSObjectOptions,
|
279 | callback?: (err: Error, result: DescribeSObjectResult) => void,
|
280 | ): Promise<DescribeSObjectResult>;
|
281 | batchDescribe(
|
282 | options: BatchDescribeSObjectOptions,
|
283 | callback?: (err: Error, result: DescribeSObjectResult[]) => void,
|
284 | ): Promise<DescribeSObjectResult[]>;
|
285 | describeGlobal$: {
|
286 | /** Returns a value from the cache if it exists, otherwise calls Connection.describeGlobal */
|
287 | (callback?: (err: Error, result: DescribeGlobalResult) => void): DescribeGlobalResult;
|
288 | clear(): void;
|
289 | };
|
290 | describeGlobal<T>(callback?: (err: Error, result: DescribeGlobalResult) => void): Promise<DescribeGlobalResult>;
|
291 | // we want any object to be accepted if the user doesn't decide to give an explicit type
|
292 | sobject<T = object>(resource: string): SObject<T>;
|
293 | recent(callback?: (err: Error, result: RecordResult[]) => void): Promise<RecordResult[]>;
|
294 | recent(param: number | string, callback?: (err: Error, result: RecordResult[]) => void): Promise<RecordResult[]>;
|
295 | recent(
|
296 | type: string,
|
297 | limit: number,
|
298 | callback?: (err: Error, result: RecordResult[]) => void,
|
299 | ): Promise<RecordResult[]>;
|
300 | search<T>(sosl: string, callback?: (err: Error, result: SearchResult<T>) => void): Promise<SearchResult<T>>;
|
301 | }
|
302 |
|
303 | export class Connection extends BaseConnection {
|
304 | constructor(params: ConnectionOptions);
|
305 |
|
306 | tooling: Tooling;
|
307 | analytics: Analytics;
|
308 | apex: Apex;
|
309 | chatter: Chatter;
|
310 | metadata: Metadata;
|
311 | soap: SoapApi;
|
312 | bulk: Bulk;
|
313 | oauth2: OAuth2;
|
314 | streaming: Streaming;
|
315 | cache: Cache;
|
316 | limitInfo?: LimitInfo;
|
317 |
|
318 | // Specific to Connection
|
319 | instanceUrl: string;
|
320 | version: string;
|
321 | accessToken: string;
|
322 | refreshToken?: string | undefined;
|
323 | userInfo?: UserInfo | undefined;
|
324 | initialize(options?: ConnectionOptions): void;
|
325 | queryAll<T>(
|
326 | soql: string,
|
327 | options?: object,
|
328 | callback?: (err: Error, result: QueryResult<T>) => void,
|
329 | ): Query<QueryResult<T>>;
|
330 | authorize(code: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
|
331 | login(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
|
332 | loginByOAuth2(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
|
333 | loginBySoap(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
|
334 | logout(revoke: boolean, callback?: (err: Error, res: undefined) => void): Promise<void>;
|
335 | logout(callback?: (err: Error, res: undefined) => void): Promise<void>;
|
336 | logoutByOAuth2(revoke: boolean, callback?: (err: Error, res: undefined) => void): Promise<void>;
|
337 | logoutByOAuth2(callback?: (err: Error, res: undefined) => void): Promise<void>;
|
338 | logoutBySoap(revoke: boolean, callback?: (err: Error, res: undefined) => void): Promise<void>;
|
339 | logoutBySoap(callback?: (err: Error, res: undefined) => void): Promise<void>;
|
340 | limits(callback?: (err: Error, res: undefined) => void): Promise<LimitsInfo>;
|
341 | identity(callback?: (err: Error, res: IdentityInfo) => void): Promise<IdentityInfo>;
|
342 | requestPost<T = object>(
|
343 | url: string,
|
344 | body: object,
|
345 | options_callback?: HttpApiOptions | ((err: Error, Object: T) => void),
|
346 | ): Promise<T>;
|
347 | requestPost<T = object>(
|
348 | url: string,
|
349 | body: object,
|
350 | options?: HttpApiOptions,
|
351 | callback?: (err: Error, Object: T) => void,
|
352 | ): Promise<T>;
|
353 | }
|
354 |
|
355 | export class Tooling extends BaseConnection {
|
356 | _logger: any;
|
357 |
|
358 | // Specific to tooling
|
359 | executeAnonymous(body: string, callback?: (err: Error, res: any) => void): Promise<ExecuteAnonymousResult>;
|
360 | }
|
361 |
|
\ | No newline at end of file |