UNPKG

5.25 kBTypeScriptView Raw
1import { JsonCollection, JsonMap, Optional } from '@salesforce/ts-types';
2import { Tooling as JSForceTooling } from 'jsforce';
3import { ExecuteOptions } from 'jsforce';
4import { QueryResult } from 'jsforce';
5import { RequestInfo } from 'jsforce';
6import { ConnectionOptions } from 'jsforce';
7import { Connection as JSForceConnection } from 'jsforce';
8import { AuthFields, AuthInfo } from './authInfo';
9import { ConfigAggregator } from './config/configAggregator';
10export declare const SFDX_HTTP_HEADERS: {
11 'content-type': string;
12 'user-agent': string;
13};
14export interface Tooling extends JSForceTooling {
15 /**
16 * Executes a query and auto-fetches (i.e., "queryMore") all results. This is especially
17 * useful with large query result sizes, such as over 2000 records. The default maximum
18 * fetch size is 10,000 records. Modify this via the options argument.
19 * @param soql The SOQL string.
20 * @param options The query options. NOTE: the autoFetch option will always be true.
21 */
22 autoFetchQuery<T>(soql: string, options?: ExecuteOptions): Promise<QueryResult<T>>;
23}
24/**
25 * Handles connections and requests to Salesforce Orgs.
26 *
27 * ```
28 * // Uses latest API version
29 * const connection = await Connection.create({
30 * authInfo: await AuthInfo.create({ username: 'myAdminUsername' })
31 * });
32 * connection.query('SELECT Name from Account');
33 *
34 * // Use different API version
35 * connection.setApiVersion("42.0");
36 * connection.query('SELECT Name from Account');
37 * ```
38 */
39export declare class Connection extends JSForceConnection {
40 /**
41 * Creates an instance of a Connection. Performs additional async initializations.
42 * @param options Constructor options.
43 */
44 static create(this: new (options: Connection.Options) => Connection, options: Connection.Options): Promise<Connection>;
45 /**
46 * Tooling api reference.
47 */
48 tooling: Tooling;
49 private logger;
50 private _logger;
51 private _transport;
52 private _normalizeUrl;
53 private options;
54 /**
55 * Constructor
56 * **Do not directly construct instances of this class -- use {@link Connection.create} instead.**
57 * @param options The options for the class instance.
58 * @ignore
59 */
60 constructor(options: Connection.Options);
61 /**
62 * Async initializer.
63 */
64 init(): Promise<void>;
65 /**
66 * Send REST API request with given HTTP request info, with connected session information
67 * and SFDX headers.
68 *
69 * @param request HTTP request object or URL to GET request.
70 * @param options HTTP API request options.
71 */
72 request(request: RequestInfo | string, options?: JsonMap): Promise<JsonCollection>;
73 /**
74 * Send REST API request with given HTTP request info, with connected session information
75 * and SFDX headers. This method returns a raw http response which includes a response body and statusCode.
76 *
77 * @param request HTTP request object or URL to GET request.
78 */
79 requestRaw(request: RequestInfo): Promise<JsonMap>;
80 /**
81 * The Force API base url for the instance.
82 */
83 baseUrl(): string;
84 /**
85 * Retrieves the highest api version that is supported by the target server instance.
86 */
87 retrieveMaxApiVersion(): Promise<string>;
88 /**
89 * Use the latest API version available on `this.instanceUrl`.
90 */
91 useLatestApiVersion(): Promise<void>;
92 /**
93 * Get the API version used for all connection requests.
94 */
95 getApiVersion(): string;
96 /**
97 * Set the API version for all connection requests.
98 *
99 * **Throws** *{@link SfdxError}{ name: 'IncorrectAPIVersion' }* Incorrect API version.
100 * @param version The API version.
101 */
102 setApiVersion(version: string): void;
103 /**
104 * Getter for the AuthInfo.
105 */
106 getAuthInfoFields(): AuthFields;
107 /**
108 * Getter for the auth fields.
109 */
110 getConnectionOptions(): AuthFields;
111 /**
112 * Getter for the username of the Salesforce Org.
113 */
114 getUsername(): Optional<string>;
115 /**
116 * Returns true if this connection is using access token auth.
117 */
118 isUsingAccessToken(): boolean;
119 /**
120 * Normalize a Salesforce url to include a instance information.
121 * @param url Partial url.
122 */
123 normalizeUrl(url: string): string;
124 /**
125 * Executes a query and auto-fetches (i.e., "queryMore") all results. This is especially
126 * useful with large query result sizes, such as over 2000 records. The default maximum
127 * fetch size is 10,000 records. Modify this via the options argument.
128 * @param soql The SOQL string.
129 * @param options The query options. NOTE: the autoFetch option will always be true.
130 */
131 autoFetchQuery<T>(soql: string, options?: ExecuteOptions): Promise<QueryResult<T>>;
132}
133export declare namespace Connection {
134 /**
135 * Connection Options.
136 */
137 interface Options {
138 /**
139 * AuthInfo instance.
140 */
141 authInfo: AuthInfo;
142 /**
143 * ConfigAggregator for getting defaults.
144 */
145 configAggregator?: ConfigAggregator;
146 /**
147 * Additional connection parameters.
148 */
149 connectionOptions?: ConnectionOptions;
150 }
151}