UNPKG

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