import { EventEmitter } from 'events'; import { BatchDescribeSObjectOptions, DescribeSObjectOptions, DescribeSObjectResult, DescribeGlobalResult, } from './describe-result'; import { Query, QueryResult, ExecuteOptions } from './query'; import { Record } from './record'; import { RecordResult } from './record-result'; import { SObject } from './salesforce-object'; import { Analytics } from './api/analytics'; import { Chatter } from './api/chatter'; import { Metadata } from './api/metadata'; import { SoapApi } from './api/soap'; import { Apex } from './api/apex'; import { Bulk } from './bulk'; import { Cache } from './cache'; import { OAuth2, Streaming } from '.'; import { HttpApiOptions } from './http-api'; import { LimitInfo, LimitsInfo } from './limits-info'; export type Callback = (err: Error | null, result: T) => void; // The type for these options was determined by looking at the usage // of the options object in Connection.create and other methods // go to http://jsforce.github.io/jsforce/doc/connection.js.html#line568 // and search for options export interface RestApiOptions { headers?: { [x: string]: string } | undefined; allowRecursive?: boolean | undefined; allOrNone?: boolean | undefined; } // These are pulled out because according to http://jsforce.github.io/jsforce/doc/connection.js.html#line49 // the oauth options can either be in the `oauth2` property OR spread across the main connection export interface PartialOAuth2Options { clientId?: string | undefined; clientSecret?: string | undefined; loginUrl?: string | undefined; redirectUri?: string | undefined; tokenServiceUrl?: string | undefined; authzServiceUrl?: string | undefined; } export interface RequestInfo { body?: string | undefined; headers?: object | undefined; method?: string | undefined; url?: string | undefined; } export interface ConnectionOptions extends PartialOAuth2Options { accessToken?: string | undefined; callOptions?: Object | undefined; instanceUrl?: string | undefined; loginUrl?: string | undefined; logLevel?: string | undefined; maxRequest?: number | undefined; oauth2?: Partial | undefined; proxyUrl?: string | undefined; httpProxy?: string | undefined; redirectUri?: string | undefined; refreshToken?: string | undefined; refreshFn?: | ((conn: Connection, callback: (err: Error | null, accessToken: string, res?: unknown) => void) => unknown) | undefined; serverUrl?: string | undefined; sessionId?: string | undefined; signedRequest?: string | Object | undefined; version?: string | undefined; } export interface UserInfo { id: string; organizationId: string; url: string; } // The identity URL is a RESTful API to query for additional information // about users, such as their username, email address, and org ID. // It also returns endpoints that the client can talk to, // such as photos for profiles and accessible API endpoints. // https://help.salesforce.com/articleView?id=remoteaccess_using_openid.htm // https://jsforce.github.io/jsforce/doc/Connection.html#identity export interface IdentityInfo { id: string; asserted_user: boolean; user_id: string; organization_id: string; username: string; nick_name: string; display_name: string; email: string; email_verified: boolean; first_name: string | null; last_name: string; timezone: string; photos: { picture: string; thumbnail: string; }; addr_street: string | null; addr_city: string | null; addr_state: string | null; addr_country: string | null; addr_zip: string | null; mobile_phone: string | null; mobile_phone_verified: boolean; is_lightning_login_user: boolean; status: { created_date: Date | null; body: string | null; }; urls: { enterprise: string; metadata: string; partner: string; rest: string; sobjects: string; search: string; query: string; recent: string; tooling_soap: string; tooling_rest: string; profile: string; feeds: string; groups: string; users: string; feed_items: string; feed_elements: string; custom_domain?: string | undefined; }; active: boolean; user_type: string; language: string; locale: string; utcOffset: number; last_modified_date: Date; is_app_installed: boolean; // And possible other attributes. [key: string]: any; } export abstract class RestApi { get(path: string, options: object, callback: () => object): Promise; post(path: string, body: object, options: object, callback: () => object): Promise; put(path: string, body: object, options: object, callback: () => object): Promise; patch(path: string, body: object, options: object, callback: () => object): Promise; del(path: string, options: object, callback: () => object): Promise; } export interface ExecuteAnonymousResult { compiled: boolean; compileProblem: string; success: boolean; line: number; column: number; exceptionMessage: string; exceptionStackTrace: string; } export type ConnectionEvent = 'refresh'; export interface SearchResult { searchRecords: Record[]; } /** * the methods exposed here are done so that a client can use 'declaration augmentation' to get intellisense on their own projects. * for example, given a type * * interface Foo { * thing: string; * yes: boolean; * } * * you can write * * declare module "jsforce" { * interface Connection { * sobject(type: 'Foo'): SObject * } * } * * to ensure that you have the correct data types for the various collection names. */ export abstract class BaseConnection extends EventEmitter { _baseUrl(): string; request( info: RequestInfo | string, options?: HttpApiOptions, callback?: (err: Error, Object: T) => void, ): Promise; query( soql: string, options?: ExecuteOptions, callback?: (err: Error, result: QueryResult) => void, ): Query>; queryMore( locator: string, options?: ExecuteOptions, callback?: (err: Error, result: QueryResult) => void, ): Promise>; create( type: string, records: Record | Array>, options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; create( records: Record | Array>, options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; insert( type: string, records: Record | Array>, options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; retrieve( type: string, ids: string | string[], options?: RestApiOptions, callback?: (err: Error, result: Record | Array>) => void, ): Promise | Array>>; update( type: string, records: Record | Array>, options?: RestApiOptions, callback?: (err: Error, result: RecordResult | Array>) => void, ): Promise; update( records: Record | Array>, options?: RestApiOptions, callback?: (err: Error, result: RecordResult | Array>) => void, ): Promise; upsert( type: string, records: Record | Array>, extIdField: string, options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; upsert( records: Record | Array>, extIdField: string, options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; del( type: string, ids: string | string[], options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; delete( type: string, ids: string | string[], options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; destroy( type: string, ids: string | string[], options?: RestApiOptions, callback?: (err: Error, result: RecordResult | RecordResult[]) => void, ): Promise; describe$: { /** Returns a value from the cache if it exists, otherwise calls Connection.describe */ ( type: string | DescribeSObjectOptions, callback?: (err: Error, result: DescribeSObjectResult) => void, ): DescribeSObjectResult; clear(): void; }; describe( type: string | DescribeSObjectOptions, callback?: (err: Error, result: DescribeSObjectResult) => void, ): Promise; batchDescribe( options: BatchDescribeSObjectOptions, callback?: (err: Error, result: DescribeSObjectResult[]) => void, ): Promise; describeGlobal$: { /** Returns a value from the cache if it exists, otherwise calls Connection.describeGlobal */ (callback?: (err: Error, result: DescribeGlobalResult) => void): DescribeGlobalResult; clear(): void; }; describeGlobal(callback?: (err: Error, result: DescribeGlobalResult) => void): Promise; // we want any object to be accepted if the user doesn't decide to give an explicit type sobject(resource: string): SObject; recent(callback?: (err: Error, result: RecordResult[]) => void): Promise; recent(param: number | string, callback?: (err: Error, result: RecordResult[]) => void): Promise; recent( type: string, limit: number, callback?: (err: Error, result: RecordResult[]) => void, ): Promise; search(sosl: string, callback?: (err: Error, result: SearchResult) => void): Promise>; } export class Connection extends BaseConnection { constructor(params: ConnectionOptions); tooling: Tooling; analytics: Analytics; apex: Apex; chatter: Chatter; metadata: Metadata; soap: SoapApi; bulk: Bulk; oauth2: OAuth2; streaming: Streaming; cache: Cache; limitInfo?: LimitInfo; // Specific to Connection instanceUrl: string; version: string; accessToken: string; refreshToken?: string | undefined; userInfo?: UserInfo | undefined; initialize(options?: ConnectionOptions): void; queryAll( soql: string, options?: object, callback?: (err: Error, result: QueryResult) => void, ): Query>; authorize(code: string, callback?: (err: Error, res: UserInfo) => void): Promise; login(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; loginByOAuth2(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; loginBySoap(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; logout(revoke: boolean, callback?: (err: Error, res: undefined) => void): Promise; logout(callback?: (err: Error, res: undefined) => void): Promise; logoutByOAuth2(revoke: boolean, callback?: (err: Error, res: undefined) => void): Promise; logoutByOAuth2(callback?: (err: Error, res: undefined) => void): Promise; logoutBySoap(revoke: boolean, callback?: (err: Error, res: undefined) => void): Promise; logoutBySoap(callback?: (err: Error, res: undefined) => void): Promise; limits(callback?: (err: Error, res: undefined) => void): Promise; identity(callback?: (err: Error, res: IdentityInfo) => void): Promise; requestPost( url: string, body: object, options_callback?: HttpApiOptions | ((err: Error, Object: T) => void), ): Promise; requestPost( url: string, body: object, options?: HttpApiOptions, callback?: (err: Error, Object: T) => void, ): Promise; } export class Tooling extends BaseConnection { _logger: any; // Specific to tooling executeAnonymous(body: string, callback?: (err: Error, res: any) => void): Promise; }