UNPKG

9.38 kBTypeScriptView Raw
1import { AsyncCreatable } from '@salesforce/kit';
2import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
3import { AuthFields, AuthInfo } from './authInfo';
4import { ConfigAggregator } from './config/configAggregator';
5import { OrgUsersConfig } from './config/orgUsersConfig';
6import { SandboxOrgConfig } from './config/sandboxOrgConfig';
7import { Connection } from './connection';
8/**
9 * Provides a way to manage a locally authenticated Org.
10 *
11 * **See** {@link AuthInfo}
12 *
13 * **See** {@link Connection}
14 *
15 * **See** {@link Aliases}
16 *
17 * **See** {@link Config}
18 *
19 * ```
20 * // Email username
21 * const org1: Org = await Org.create({ aliasOrUsername: 'foo@example.com' });
22 * // The defaultusername config property
23 * const org2: Org = await Org.create({});
24 * // Full Connection
25 * const org3: Org = await Org.create({
26 * connection: await Connection.create({
27 * authInfo: await AuthInfo.create({ username: 'username' })
28 * })
29 * });
30 * ```
31 *
32 * **See** https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_usernames_orgs.htm
33 */
34export declare class Org extends AsyncCreatable<Org.Options> {
35 private status;
36 private configAggregator;
37 private logger;
38 private connection;
39 private options;
40 /**
41 * @ignore
42 */
43 constructor(options: Org.Options);
44 /**
45 * Clean all data files in the org's data path. Usually <workspace>/.sfdx/orgs/<username>.
46 * @param orgDataPath A relative path other than "orgs/".
47 * @param throwWhenRemoveFails Should the remove org operations throw an error on failure?
48 */
49 cleanLocalOrgData(orgDataPath?: string, throwWhenRemoveFails?: boolean): Promise<void>;
50 /**
51 * @ignore
52 */
53 retrieveOrgUsersConfig(): Promise<OrgUsersConfig>;
54 /**
55 * Removes the scratch org config file at $HOME/.sfdx/[name].json, any project level org
56 * files, all user auth files for the org, matching default config settings, and any
57 * matching aliases.
58 * @param throwWhenRemoveFails Determines if the call should throw an error or fail silently.
59 */
60 remove(throwWhenRemoveFails?: boolean): Promise<void>;
61 /**
62 * Check that this org is a scratch org by asking the dev hub if it knows about it.
63 *
64 * **Throws** *{@link SfdxError}{ name: 'NotADevHub' }* Not a Dev Hub.
65 *
66 * **Throws** *{@link SfdxError}{ name: 'NoResults' }* No results.
67 *
68 * @param devHubUsernameOrAlias The username or alias of the dev hub org.
69 */
70 checkScratchOrg(devHubUsernameOrAlias?: string): Promise<Partial<AuthFields>>;
71 /**
72 * Returns the Org object or null if this org is not affiliated with a Dev Hub (according to the local config).
73 */
74 getDevHubOrg(): Promise<Optional<Org>>;
75 /**
76 * Returns `true` if the org is a Dev Hub.
77 *
78 * **Note** This relies on a cached value in the auth file. If that property
79 * is not cached, this method will **always return false even if the org is a
80 * dev hub**. If you need accuracy, use the {@link Org.determineIfDevHubOrg} method.
81 */
82 isDevHubOrg(): boolean;
83 /**
84 * Returns `true` if the org is a Dev Hub.
85 *
86 * Use a cached value. If the cached value is not set, then check access to the
87 * ScratchOrgInfo object to determine if the org is a dev hub.
88 *
89 * @param forceServerCheck Ignore the cached value and go straight to the server
90 * which will be required if the org flips on the dev hub after the value is already
91 * cached locally.
92 */
93 determineIfDevHubOrg(forceServerCheck?: boolean): Promise<boolean>;
94 /**
95 * Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.
96 */
97 refreshAuth(): Promise<void>;
98 /**
99 * Reads and returns the content of all user auth files for this org as an array.
100 */
101 readUserAuthFiles(): Promise<AuthInfo[]>;
102 /**
103 * Adds a username to the user config for this org. For convenience `this` object is returned.
104 *
105 * ```
106 * const org: Org = await Org.create({
107 * connection: await Connection.create({
108 * authInfo: await AuthInfo.create('foo@example.com')
109 * })
110 * });
111 * const userAuth: AuthInfo = await AuthInfo.create({
112 * username: 'bar@example.com'
113 * });
114 * await org.addUsername(userAuth);
115 * ```
116 *
117 * @param {AuthInfo | string} auth The AuthInfo for the username to add.
118 */
119 addUsername(auth: AuthInfo | string): Promise<Org>;
120 /**
121 * Removes a username from the user config for this object. For convenience `this` object is returned.
122 *
123 * **Throws** *{@link SfdxError}{ name: 'MissingAuthInfo' }* Auth info is missing.
124 *
125 * @param {AuthInfo | string} auth The AuthInfo containing the username to remove.
126 */
127 removeUsername(auth: AuthInfo | string): Promise<Org>;
128 /**
129 * Sets the key/value pair in the sandbox config for this org. For convenience `this` object is returned.
130 *
131 *
132 * @param {key} The key for this value
133 * @param {value} The value to save
134 */
135 setSandboxOrgConfigField(field: SandboxOrgConfig.Fields, value: string): Promise<Org>;
136 /**
137 * Returns an org config field. Returns undefined if the field is not set or invalid.
138 */
139 getSandboxOrgConfigField(field: SandboxOrgConfig.Fields): Promise<Optional<AnyJson>>;
140 /**
141 * Retrieves the highest api version that is supported by the target server instance. If the apiVersion configured for
142 * Sfdx is greater than the one returned in this call an api version mismatch occurs. In the case of the CLI that
143 * results in a warning.
144 */
145 retrieveMaxApiVersion(): Promise<string>;
146 /**
147 * Returns the admin username used to create the org.
148 */
149 getUsername(): Optional<string>;
150 /**
151 * Returns the orgId for this org.
152 */
153 getOrgId(): string;
154 /**
155 * Returns for the config aggregator.
156 */
157 getConfigAggregator(): ConfigAggregator;
158 /**
159 * Returns an org field. Returns undefined if the field is not set or invalid.
160 */
161 getField(key: Org.Fields): AnyJson;
162 /**
163 * Returns a map of requested fields.
164 */
165 getFields(keys: Org.Fields[]): JsonMap;
166 /**
167 * Returns the JSForce connection for the org.
168 */
169 getConnection(): Connection;
170 /**
171 * Initialize async components.
172 */
173 protected init(): Promise<void>;
174 /**
175 * **Throws** *{@link SfdxError} Throws and unsupported error.
176 */
177 protected getDefaultOptions(): Org.Options;
178 /**
179 * Returns a promise to delete an auth info file from the local file system and any related cache information for
180 * this Org.. You don't want to call this method directly. Instead consider calling Org.remove()
181 */
182 private removeAuth;
183 /**
184 * Deletes the users config file
185 */
186 private removeUsersConfig;
187 /**
188 * @ignore
189 */
190 private retrieveSandboxOrgConfig;
191 private manageDelete;
192 /**
193 * Remove the org users auth file.
194 * @param throwWhenRemoveFails true if manageDelete should throw or not if the deleted fails.
195 */
196 private removeUsers;
197 /**
198 * Remove an associate sandbox config.
199 * @param throwWhenRemoveFails true if manageDelete should throw or not if the deleted fails.
200 */
201 private removeSandboxConfig;
202}
203export declare namespace Org {
204 /**
205 * Constructor Options for and Org.
206 */
207 interface Options {
208 aliasOrUsername?: string;
209 connection?: Connection;
210 aggregator?: ConfigAggregator;
211 isDevHub?: boolean;
212 }
213 /**
214 * Scratch Org status.
215 */
216 enum Status {
217 /**
218 * The scratch org is active.
219 */
220 ACTIVE = "ACTIVE",
221 /**
222 * The scratch org has expired.
223 */
224 EXPIRED = "EXPIRED",
225 /**
226 * The org is a scratch Org but no dev hub is indicated.
227 */
228 UNKNOWN = "UNKNOWN",
229 /**
230 * The dev hub configuration is reporting an active Scratch org but the AuthInfo cannot be found.
231 */
232 MISSING = "MISSING"
233 }
234 /**
235 * Org Fields.
236 */
237 enum Fields {
238 /**
239 * The org alias.
240 */
241 ALIAS = "alias",
242 CREATED = "created",
243 /**
244 * The Salesforce instance the org was created on. e.g. `cs42`.
245 */
246 CREATED_ORG_INSTANCE = "createdOrgInstance",
247 /**
248 * The username of the dev hub org that created this org. Only populated for scratch orgs.
249 */
250 DEV_HUB_USERNAME = "devHubUsername",
251 /**
252 * The full url of the instance the org lives on.
253 */
254 INSTANCE_URL = "instanceUrl",
255 /**
256 * Is the current org a dev hub org. e.g. They have access to the `ScratchOrgInfo` object.
257 */
258 IS_DEV_HUB = "isDevHub",
259 /**
260 * The login url of the org. e.g. `https://login.salesforce.com` or `https://test.salesforce.com`.
261 */
262 LOGIN_URL = "loginUrl",
263 /**
264 * The org ID.
265 */
266 ORG_ID = "orgId",
267 /**
268 * The `OrgStatus` of the org.
269 */
270 STATUS = "status",
271 /**
272 * The snapshot used to create the scratch org.
273 */
274 SNAPSHOT = "snapshot"
275 }
276}