UNPKG

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