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