UNPKG

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