UNPKG

6.32 kBTypeScriptView Raw
1import { AsyncResult, DeployOptions, DeployResultLocator } from '@jsforce/jsforce-node/lib/api/metadata';
2import { JsonMap, Optional } from '@salesforce/ts-types';
3import { Connection as JSForceConnection, ConnectionConfig, HttpRequest, QueryOptions, QueryResult, Record, Schema } from '@jsforce/jsforce-node';
4import { Tooling as JSForceTooling } from '@jsforce/jsforce-node/lib/api/tooling';
5import { StreamPromise } from '@jsforce/jsforce-node/lib/util/promise';
6import { ConfigAggregator } from '../config/configAggregator';
7import { AuthFields, AuthInfo } from './authInfo';
8export declare const SFDX_HTTP_HEADERS: {
9 'content-type': string;
10 'user-agent': string;
11};
12export declare const DNS_ERROR_NAME = "DomainNotFoundError";
13export type DeployOptionsWithRest = Partial<DeployOptions> & {
14 rest?: boolean;
15};
16export interface Tooling<S extends Schema = Schema> extends JSForceTooling<S> {
17 _logger: any;
18}
19/**
20 * Handles connections and requests to Salesforce Orgs.
21 *
22 * ```
23 * // Uses latest API version
24 * const connection = await Connection.create({
25 * authInfo: await AuthInfo.create({ username: 'myAdminUsername' })
26 * });
27 * connection.query('SELECT Name from Account');
28 *
29 * // Use different API version
30 * connection.setApiVersion("42.0");
31 * connection.query('SELECT Name from Account');
32 * ```
33 */
34export declare class Connection<S extends Schema = Schema> extends JSForceConnection<S> {
35 private logger;
36 private options;
37 private username;
38 private hasResolved;
39 private maxApiVersion;
40 /**
41 * Constructor
42 * **Do not directly construct instances of this class -- use {@link Connection.create} instead.**
43 *
44 * @param options The options for the class instance.
45 * @ignore
46 */
47 constructor(options: Connection.Options<S>);
48 /**
49 * Tooling api reference.
50 */
51 get tooling(): Tooling<S>;
52 /**
53 * Creates an instance of a Connection. Performs additional async initializations.
54 *
55 * @param options Constructor options.
56 */
57 static create<S extends Schema>(this: new (options: Connection.Options<S>) => Connection<S>, options: Connection.Options<S>): Promise<Connection<S>>;
58 /**
59 * Async initializer.
60 */
61 init(): Promise<void>;
62 /**
63 * deploy a zipped buffer from the SDRL with REST or SOAP
64 *
65 * @param zipInput data to deploy
66 * @param options JSForce deploy options + a boolean for rest
67 */
68 deploy(zipInput: Buffer, options: DeployOptionsWithRest): Promise<DeployResultLocator<AsyncResult & Schema>>;
69 /**
70 * Send REST API request with given HTTP request info, with connected session information
71 * and SFDX headers.
72 *
73 * @param request HTTP request object or URL to GET request.
74 * @param options HTTP API request options.
75 */
76 request<R = unknown>(request: string | HttpRequest, options?: JsonMap): StreamPromise<R>;
77 /**
78 * The Force API base url for the instance.
79 */
80 baseUrl(): string;
81 /**
82 * Retrieves the highest api version that is supported by the target server instance.
83 */
84 retrieveMaxApiVersion(): Promise<string>;
85 /**
86 * Use the latest API version available on `this.instanceUrl`.
87 */
88 useLatestApiVersion(): Promise<void>;
89 /**
90 * Verify that instance has a reachable DNS entry, otherwise will throw error
91 */
92 isResolvable(): Promise<boolean>;
93 /**
94 * Get the API version used for all connection requests.
95 */
96 getApiVersion(): string;
97 /**
98 * Set the API version for all connection requests.
99 *
100 * **Throws** *{@link SfError}{ name: 'IncorrectAPIVersionError' }* Incorrect API version.
101 *
102 * @param version The API version.
103 */
104 setApiVersion(version: string): void;
105 /**
106 * Getter for AuthInfo.
107 */
108 getAuthInfo(): AuthInfo;
109 /**
110 * Getter for the AuthInfo fields.
111 */
112 getAuthInfoFields(): AuthFields;
113 /**
114 * Getter for the auth fields.
115 */
116 getConnectionOptions(): AuthFields;
117 /**
118 * Getter for the username of the Salesforce Org.
119 */
120 getUsername(): Optional<string>;
121 /**
122 * Returns true if this connection is using access token auth.
123 */
124 isUsingAccessToken(): boolean;
125 /**
126 * Normalize a Salesforce url to include a instance information.
127 *
128 * @param url Partial url.
129 */
130 normalizeUrl(url: string): string;
131 /**
132 * Executes a query and auto-fetches (i.e., "queryMore") all results. This is especially
133 * useful with large query result sizes, such as over 2000 records. The default maximum
134 * fetch size is 10,000 records. Modify this via the options argument.
135 *
136 * @param soql The SOQL string.
137 * @param queryOptions The query options. NOTE: the autoFetch option will always be true.
138 */
139 autoFetchQuery<T extends Schema = S>(soql: string, queryOptions?: Partial<QueryOptions & {
140 tooling: boolean;
141 }>): Promise<QueryResult<T>>;
142 /**
143 * Executes a query using either standard REST or Tooling API, returning a single record.
144 * Will throw if either zero records are found OR multiple records are found.
145 *
146 * @param soql The SOQL string.
147 * @param options The query options.
148 */
149 singleRecordQuery<T extends Record>(soql: string, options?: SingleRecordQueryOptions): Promise<T>;
150 /**
151 * Executes a get request on the baseUrl to force an auth refresh
152 * Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes
153 */
154 refreshAuth(): Promise<void>;
155 private getCachedApiVersion;
156}
157export declare const SingleRecordQueryErrors: {
158 NoRecords: string;
159 MultipleRecords: string;
160};
161export type SingleRecordQueryOptions = {
162 tooling?: boolean;
163 returnChoicesOnMultiple?: boolean;
164 choiceField?: string;
165};
166export declare namespace Connection {
167 /**
168 * Connection Options.
169 */
170 type Options<S extends Schema> = {
171 /**
172 * AuthInfo instance.
173 */
174 authInfo: AuthInfo;
175 /**
176 * ConfigAggregator for getting defaults.
177 */
178 configAggregator?: ConfigAggregator;
179 /**
180 * Additional connection parameters.
181 */
182 connectionOptions?: ConnectionConfig<S>;
183 };
184}