@salesforce/core 3.19.2 → 3.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +6 -18
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +27 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/configAggregator.d.ts +5 -3
- package/lib/config/configAggregator.js +13 -1
- package/lib/config/configFile.js +2 -2
- package/lib/config/configGroup.d.ts +141 -0
- package/lib/config/configGroup.js +224 -0
- package/lib/config/configStore.d.ts +2 -2
- package/lib/config/configStore.js +1 -2
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +28 -0
- package/lib/crypto/keyChainImpl.js +1 -1
- package/lib/exported.d.ts +1 -1
- package/lib/exported.js +6 -5
- package/lib/global.d.ts +8 -0
- package/lib/global.js +10 -0
- package/lib/org/authInfo.d.ts +1 -1
- package/lib/org/authInfo.js +22 -22
- package/lib/org/authRemover.d.ts +6 -5
- package/lib/org/authRemover.js +22 -16
- package/lib/org/connection.js +1 -1
- package/lib/org/org.d.ts +12 -4
- package/lib/org/org.js +28 -26
- package/lib/org/scratchOrgCreate.js +5 -7
- package/lib/org/scratchOrgInfoApi.js +1 -1
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +79 -1
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +119 -2
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +53 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +201 -0
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.d.ts +12 -1
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.js +22 -2
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +28 -0
- package/lib/{globalInfo → stateAggregator}/accessors/tokenAccessor.js +34 -2
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.d.ts +11 -8
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.js +7 -4
- package/lib/stateAggregator/index.d.ts +7 -0
- package/lib/{globalInfo → stateAggregator}/index.js +5 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.d.ts +7 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.js +25 -2
- package/lib/stateAggregator/stateAggregator.d.ts +20 -0
- package/lib/stateAggregator/stateAggregator.js +38 -0
- package/lib/{globalInfo → stateAggregator}/types.d.ts +25 -10
- package/lib/{globalInfo → stateAggregator}/types.js +3 -0
- package/lib/testSetup.d.ts +30 -6
- package/lib/testSetup.js +79 -11
- package/package.json +1 -1
- package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
- package/lib/globalInfo/accessors/orgAccessor.js +0 -45
- package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
- package/lib/globalInfo/index.d.ts +0 -6
|
@@ -13,7 +13,7 @@ const messages_1 = require("../messages");
|
|
|
13
13
|
const logger_1 = require("../logger");
|
|
14
14
|
const configAggregator_1 = require("../config/configAggregator");
|
|
15
15
|
const sfProject_1 = require("../sfProject");
|
|
16
|
-
const
|
|
16
|
+
const stateAggregator_1 = require("../stateAggregator");
|
|
17
17
|
const org_1 = require("./org");
|
|
18
18
|
const scratchOrgInfoApi_1 = require("./scratchOrgInfoApi");
|
|
19
19
|
const scratchOrgSettingsGenerator_1 = require("./scratchOrgSettingsGenerator");
|
|
@@ -73,12 +73,10 @@ const scratchOrgResume = async (jobId) => {
|
|
|
73
73
|
// At this point, the scratch org is "good".
|
|
74
74
|
// Some hubs have all the usernames set to `null`
|
|
75
75
|
const username = (_a = soi.Username) !== null && _a !== void 0 ? _a : soi.SignupUsername;
|
|
76
|
-
// re-auth only if the org isn't in
|
|
77
|
-
const
|
|
78
|
-
const scratchOrgAuthInfo =
|
|
79
|
-
? await authInfo_1.AuthInfo.create({
|
|
80
|
-
username,
|
|
81
|
-
})
|
|
76
|
+
// re-auth only if the org isn't in StateAggregator
|
|
77
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
78
|
+
const scratchOrgAuthInfo = (await stateAggregator.orgs.exists(username))
|
|
79
|
+
? await authInfo_1.AuthInfo.create({ username })
|
|
82
80
|
: await (0, scratchOrgInfoApi_1.authorizeScratchOrg)({
|
|
83
81
|
scratchOrgInfoComplete: soi,
|
|
84
82
|
hubOrg,
|
|
@@ -203,7 +203,7 @@ const checkOrgDoesntExist = async (scratchOrgInfo) => {
|
|
|
203
203
|
catch (error) {
|
|
204
204
|
const sfError = sfError_1.SfError.wrap(error);
|
|
205
205
|
// if an AuthInfo couldn't be created that means no AuthFile exists.
|
|
206
|
-
if (sfError.name === '
|
|
206
|
+
if (sfError.name === 'NamedOrgNotFoundError') {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
209
|
// Something unexpected
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
1
2
|
import { Nullable } from '@salesforce/ts-types';
|
|
3
|
+
import { ConfigContents } from '../../exported';
|
|
2
4
|
import { GlobalInfo } from '../globalInfoConfig';
|
|
3
5
|
import { SfAliases, SfOrg, SfToken } from '../types';
|
|
4
6
|
export declare type Aliasable = string | Partial<SfOrg> | Partial<SfToken>;
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
export declare class GlobalInfoAliasAccessor {
|
|
6
11
|
private globalInfo;
|
|
7
12
|
constructor(globalInfo: GlobalInfo);
|
|
8
13
|
/**
|
|
@@ -81,3 +86,76 @@ export declare class AliasAccessor {
|
|
|
81
86
|
*/
|
|
82
87
|
private getNameOf;
|
|
83
88
|
}
|
|
89
|
+
export declare class AliasAccessor extends AsyncOptionalCreatable {
|
|
90
|
+
private config;
|
|
91
|
+
/**
|
|
92
|
+
* Returns all the aliases for all the values
|
|
93
|
+
*/
|
|
94
|
+
getAll(): ConfigContents<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns all the aliases for a given entity
|
|
97
|
+
*
|
|
98
|
+
* @param entity the aliasable entity that you want to get the aliases of
|
|
99
|
+
*/
|
|
100
|
+
getAll(entity: Aliasable): string[];
|
|
101
|
+
/**
|
|
102
|
+
* Returns the first alias found for a given entity
|
|
103
|
+
*
|
|
104
|
+
* @param entity the aliasable entity that you want to get the alias of
|
|
105
|
+
*/
|
|
106
|
+
get(entity: Aliasable): Nullable<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the value that corresponds to the given alias if it exists
|
|
109
|
+
*
|
|
110
|
+
* @param alias the alias that corresponds to a value
|
|
111
|
+
*/
|
|
112
|
+
getValue(alias: string): Nullable<string>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the username that corresponds to the given alias if it exists
|
|
115
|
+
*
|
|
116
|
+
* @param alias the alias that corresponds to a username
|
|
117
|
+
*/
|
|
118
|
+
getUsername(alias: string): Nullable<string>;
|
|
119
|
+
/**
|
|
120
|
+
* If the provided string is an alias, it returns the corresponding value.
|
|
121
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
122
|
+
* is the value and return it.
|
|
123
|
+
*
|
|
124
|
+
* This method is helpful when you don't know if the string you have is a value
|
|
125
|
+
* or an alias.
|
|
126
|
+
*
|
|
127
|
+
* @param valueOrAlias a string that might be a value or might be an alias
|
|
128
|
+
*/
|
|
129
|
+
resolveValue(valueOrAlias: string): string;
|
|
130
|
+
/**
|
|
131
|
+
* If the provided string is an alias, it returns the corresponding username.
|
|
132
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
133
|
+
* is the username and return it.
|
|
134
|
+
*
|
|
135
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
136
|
+
* or an alias.
|
|
137
|
+
*
|
|
138
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
139
|
+
*/
|
|
140
|
+
resolveUsername(usernameOrAlias: string): string;
|
|
141
|
+
/**
|
|
142
|
+
* Set an alias for the given aliasable entity
|
|
143
|
+
*
|
|
144
|
+
* @param alias the alias you want to set
|
|
145
|
+
* @param entity the aliasable entity that's being aliased
|
|
146
|
+
*/
|
|
147
|
+
set(alias: string, entity: Aliasable): void;
|
|
148
|
+
unset(alias: string): void;
|
|
149
|
+
/**
|
|
150
|
+
* This method unsets all the aliases for the given entity.
|
|
151
|
+
*
|
|
152
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
153
|
+
*/
|
|
154
|
+
unsetAll(entity: Aliasable): void;
|
|
155
|
+
write(): Promise<ConfigContents>;
|
|
156
|
+
protected init(): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Returns the username of given aliasable entity
|
|
159
|
+
*/
|
|
160
|
+
private getNameOf;
|
|
161
|
+
}
|
|
@@ -6,10 +6,15 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.AliasAccessor = void 0;
|
|
9
|
+
exports.AliasAccessor = exports.GlobalInfoAliasAccessor = void 0;
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const aliasesConfig_1 = require("../../config/aliasesConfig");
|
|
10
12
|
const sfError_1 = require("../../sfError");
|
|
11
13
|
const types_1 = require("../types");
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
17
|
+
class GlobalInfoAliasAccessor {
|
|
13
18
|
constructor(globalInfo) {
|
|
14
19
|
this.globalInfo = globalInfo;
|
|
15
20
|
}
|
|
@@ -126,5 +131,117 @@ class AliasAccessor {
|
|
|
126
131
|
return aliaseeName;
|
|
127
132
|
}
|
|
128
133
|
}
|
|
134
|
+
exports.GlobalInfoAliasAccessor = GlobalInfoAliasAccessor;
|
|
135
|
+
class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
136
|
+
getAll(entity) {
|
|
137
|
+
// This will only return aliases under "orgs". This will need to be modified
|
|
138
|
+
// if/when we want to support more aliases groups.
|
|
139
|
+
const all = (this.config.getGroup() || {});
|
|
140
|
+
if (entity) {
|
|
141
|
+
const value = this.getNameOf(entity);
|
|
142
|
+
return Object.entries(all)
|
|
143
|
+
.filter((entry) => entry[1] === value)
|
|
144
|
+
.map((entry) => entry[0]);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return all;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the first alias found for a given entity
|
|
152
|
+
*
|
|
153
|
+
* @param entity the aliasable entity that you want to get the alias of
|
|
154
|
+
*/
|
|
155
|
+
get(entity) {
|
|
156
|
+
var _a;
|
|
157
|
+
return (_a = this.getAll(entity).find((alias) => alias)) !== null && _a !== void 0 ? _a : null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns the value that corresponds to the given alias if it exists
|
|
161
|
+
*
|
|
162
|
+
* @param alias the alias that corresponds to a value
|
|
163
|
+
*/
|
|
164
|
+
getValue(alias) {
|
|
165
|
+
var _a;
|
|
166
|
+
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns the username that corresponds to the given alias if it exists
|
|
170
|
+
*
|
|
171
|
+
* @param alias the alias that corresponds to a username
|
|
172
|
+
*/
|
|
173
|
+
getUsername(alias) {
|
|
174
|
+
var _a;
|
|
175
|
+
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* If the provided string is an alias, it returns the corresponding value.
|
|
179
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
180
|
+
* is the value and return it.
|
|
181
|
+
*
|
|
182
|
+
* This method is helpful when you don't know if the string you have is a value
|
|
183
|
+
* or an alias.
|
|
184
|
+
*
|
|
185
|
+
* @param valueOrAlias a string that might be a value or might be an alias
|
|
186
|
+
*/
|
|
187
|
+
resolveValue(valueOrAlias) {
|
|
188
|
+
var _a;
|
|
189
|
+
return (_a = this.getValue(valueOrAlias)) !== null && _a !== void 0 ? _a : valueOrAlias;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* If the provided string is an alias, it returns the corresponding username.
|
|
193
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
194
|
+
* is the username and return it.
|
|
195
|
+
*
|
|
196
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
197
|
+
* or an alias.
|
|
198
|
+
*
|
|
199
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
200
|
+
*/
|
|
201
|
+
resolveUsername(usernameOrAlias) {
|
|
202
|
+
var _a;
|
|
203
|
+
return (_a = this.getUsername(usernameOrAlias)) !== null && _a !== void 0 ? _a : usernameOrAlias;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Set an alias for the given aliasable entity
|
|
207
|
+
*
|
|
208
|
+
* @param alias the alias you want to set
|
|
209
|
+
* @param entity the aliasable entity that's being aliased
|
|
210
|
+
*/
|
|
211
|
+
set(alias, entity) {
|
|
212
|
+
this.config.set(alias, this.getNameOf(entity));
|
|
213
|
+
}
|
|
214
|
+
unset(alias) {
|
|
215
|
+
this.config.unset(alias);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* This method unsets all the aliases for the given entity.
|
|
219
|
+
*
|
|
220
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
221
|
+
*/
|
|
222
|
+
unsetAll(entity) {
|
|
223
|
+
const aliases = this.getAll(entity);
|
|
224
|
+
aliases.forEach((alias) => this.unset(alias));
|
|
225
|
+
}
|
|
226
|
+
async write() {
|
|
227
|
+
return this.config.write();
|
|
228
|
+
}
|
|
229
|
+
async init() {
|
|
230
|
+
this.config = await aliasesConfig_1.AliasesConfig.create(aliasesConfig_1.AliasesConfig.getDefaultOptions());
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Returns the username of given aliasable entity
|
|
234
|
+
*/
|
|
235
|
+
getNameOf(entity) {
|
|
236
|
+
var _a;
|
|
237
|
+
if (typeof entity === 'string')
|
|
238
|
+
return entity;
|
|
239
|
+
const aliaseeName = (_a = entity.username) !== null && _a !== void 0 ? _a : entity.user;
|
|
240
|
+
if (!aliaseeName) {
|
|
241
|
+
throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
|
|
242
|
+
}
|
|
243
|
+
return aliaseeName;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
129
246
|
exports.AliasAccessor = AliasAccessor;
|
|
130
247
|
//# sourceMappingURL=aliasAccessor.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { JsonMap, Nullable, Optional } from '@salesforce/ts-types';
|
|
4
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
5
|
+
import { AuthInfoConfig } from '../../config/authInfoConfig';
|
|
6
|
+
import { GlobalInfo } from '../globalInfoConfig';
|
|
7
|
+
import { SfOrgs, SfOrg } from '../types';
|
|
8
|
+
import { AuthFields } from '../../org';
|
|
9
|
+
import { ConfigFile } from '../../config/configFile';
|
|
10
|
+
import { ConfigContents } from '../../config/configStore';
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export declare class GlobalInfoOrgAccessor {
|
|
15
|
+
private globalInfo;
|
|
16
|
+
constructor(globalInfo: GlobalInfo);
|
|
17
|
+
getAll(decrypt?: boolean): SfOrgs;
|
|
18
|
+
get(username: string, decrypt?: boolean): Optional<SfOrg>;
|
|
19
|
+
has(username: string): boolean;
|
|
20
|
+
set(username: string, org: SfOrg): void;
|
|
21
|
+
update(username: string, org: Partial<SfOrg>): void;
|
|
22
|
+
unset(username: string): void;
|
|
23
|
+
}
|
|
24
|
+
export declare abstract class BaseOrgAccessor<T extends ConfigFile, P extends ConfigContents> extends AsyncOptionalCreatable {
|
|
25
|
+
private configs;
|
|
26
|
+
private contents;
|
|
27
|
+
private logger;
|
|
28
|
+
read(username: string, decrypt?: boolean, throwOnNotFound?: boolean): Promise<Nullable<P>>;
|
|
29
|
+
readAll(decrypt?: boolean): Promise<P[]>;
|
|
30
|
+
get(username: string, decrypt?: boolean): Nullable<P>;
|
|
31
|
+
getAll(decrypt?: boolean): P[];
|
|
32
|
+
has(username: string): boolean;
|
|
33
|
+
exists(username: string): Promise<boolean>;
|
|
34
|
+
stat(username: string): Promise<Nullable<fs.Stats>>;
|
|
35
|
+
hasFile(username: string): Promise<boolean>;
|
|
36
|
+
list(): Promise<string[]>;
|
|
37
|
+
set(username: string, org: P): void;
|
|
38
|
+
update(username: string, org: Partial<P> & JsonMap): void;
|
|
39
|
+
remove(username: string): Promise<void>;
|
|
40
|
+
write(username: string): Promise<Nullable<P>>;
|
|
41
|
+
protected init(): Promise<void>;
|
|
42
|
+
private getAllFiles;
|
|
43
|
+
private parseUsername;
|
|
44
|
+
private parseFilename;
|
|
45
|
+
protected abstract initAuthFile(username: string, throwOnNotFound?: boolean): Promise<T>;
|
|
46
|
+
protected abstract getFileRegex(): RegExp;
|
|
47
|
+
protected abstract getFileExtension(): string;
|
|
48
|
+
}
|
|
49
|
+
export declare class OrgAccessor extends BaseOrgAccessor<AuthInfoConfig, AuthFields> {
|
|
50
|
+
protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<AuthInfoConfig>;
|
|
51
|
+
protected getFileRegex(): RegExp;
|
|
52
|
+
protected getFileExtension(): string;
|
|
53
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.OrgAccessor = exports.BaseOrgAccessor = exports.GlobalInfoOrgAccessor = void 0;
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const path = require("path");
|
|
12
|
+
const kit_1 = require("@salesforce/kit");
|
|
13
|
+
const authInfoConfig_1 = require("../../config/authInfoConfig");
|
|
14
|
+
const global_1 = require("../../global");
|
|
15
|
+
const types_1 = require("../types");
|
|
16
|
+
const logger_1 = require("../../logger");
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
class GlobalInfoOrgAccessor {
|
|
21
|
+
constructor(globalInfo) {
|
|
22
|
+
this.globalInfo = globalInfo;
|
|
23
|
+
}
|
|
24
|
+
getAll(decrypt = false) {
|
|
25
|
+
return this.globalInfo.get(types_1.SfInfoKeys.ORGS, decrypt);
|
|
26
|
+
}
|
|
27
|
+
get(username, decrypt = false) {
|
|
28
|
+
const auth = this.globalInfo.get(`${types_1.SfInfoKeys.ORGS}["${username}"]`, decrypt);
|
|
29
|
+
// For legacy, some things wants the username in the returned auth info.
|
|
30
|
+
if (auth && !auth.username)
|
|
31
|
+
auth.username = username;
|
|
32
|
+
return auth;
|
|
33
|
+
}
|
|
34
|
+
has(username) {
|
|
35
|
+
return !!this.getAll()[username];
|
|
36
|
+
}
|
|
37
|
+
set(username, org) {
|
|
38
|
+
var _a;
|
|
39
|
+
// For legacy, and to keep things standard, some things wants the username in auth info.
|
|
40
|
+
(_a = org.username) !== null && _a !== void 0 ? _a : (org.username = username);
|
|
41
|
+
this.globalInfo.set(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
|
|
42
|
+
}
|
|
43
|
+
update(username, org) {
|
|
44
|
+
var _a;
|
|
45
|
+
// For legacy, and to keep things standard, some things wants the username in auth info.
|
|
46
|
+
(_a = org.username) !== null && _a !== void 0 ? _a : (org.username = username);
|
|
47
|
+
this.globalInfo.update(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
|
|
48
|
+
}
|
|
49
|
+
unset(username) {
|
|
50
|
+
delete this.globalInfo.get(types_1.SfInfoKeys.ORGS)[username];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.GlobalInfoOrgAccessor = GlobalInfoOrgAccessor;
|
|
54
|
+
function chunk(array, chunkSize) {
|
|
55
|
+
const final = [];
|
|
56
|
+
for (let i = 0, len = array.length; i < len; i += chunkSize)
|
|
57
|
+
final.push(array.slice(i, i + chunkSize));
|
|
58
|
+
return final;
|
|
59
|
+
}
|
|
60
|
+
class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
|
|
61
|
+
constructor() {
|
|
62
|
+
super(...arguments);
|
|
63
|
+
this.configs = new Map();
|
|
64
|
+
this.contents = new Map();
|
|
65
|
+
}
|
|
66
|
+
async read(username, decrypt = false, throwOnNotFound = true) {
|
|
67
|
+
try {
|
|
68
|
+
const config = await this.initAuthFile(username, throwOnNotFound);
|
|
69
|
+
this.configs.set(username, config);
|
|
70
|
+
return this.get(username, decrypt);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async readAll(decrypt = false) {
|
|
77
|
+
const fileChunks = chunk(await this.getAllFiles(), 50);
|
|
78
|
+
for (const fileChunk of fileChunks) {
|
|
79
|
+
const promises = fileChunk.map(async (f) => {
|
|
80
|
+
const username = this.parseUsername(f);
|
|
81
|
+
const config = await this.initAuthFile(username);
|
|
82
|
+
this.configs.set(username, config);
|
|
83
|
+
});
|
|
84
|
+
await Promise.all(promises);
|
|
85
|
+
}
|
|
86
|
+
return this.getAll(decrypt);
|
|
87
|
+
}
|
|
88
|
+
get(username, decrypt = false) {
|
|
89
|
+
const config = this.configs.get(username);
|
|
90
|
+
if (config) {
|
|
91
|
+
this.contents.set(username, config.getContents(decrypt));
|
|
92
|
+
}
|
|
93
|
+
return this.contents.get(username);
|
|
94
|
+
}
|
|
95
|
+
getAll(decrypt = false) {
|
|
96
|
+
return [...this.configs.keys()].reduce((orgs, username) => {
|
|
97
|
+
const org = this.get(username, decrypt);
|
|
98
|
+
return org && !(0, kit_1.isEmpty)(org) ? orgs.concat([org]) : orgs;
|
|
99
|
+
}, []);
|
|
100
|
+
}
|
|
101
|
+
has(username) {
|
|
102
|
+
return this.contents.has(username);
|
|
103
|
+
}
|
|
104
|
+
async exists(username) {
|
|
105
|
+
const config = this.configs.get(username);
|
|
106
|
+
return config ? await config.exists() : false;
|
|
107
|
+
}
|
|
108
|
+
async stat(username) {
|
|
109
|
+
const config = this.configs.get(username);
|
|
110
|
+
return config ? await config.stat() : null;
|
|
111
|
+
}
|
|
112
|
+
async hasFile(username) {
|
|
113
|
+
try {
|
|
114
|
+
await fs.promises.access(this.parseFilename(username));
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
this.logger.debug(`No auth file found for ${username}`);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async list() {
|
|
123
|
+
return this.getAllFiles();
|
|
124
|
+
}
|
|
125
|
+
set(username, org) {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
const config = this.configs.get(username);
|
|
128
|
+
if (config) {
|
|
129
|
+
config.setContentsFromObject(org);
|
|
130
|
+
const contents = config.getContents();
|
|
131
|
+
(_a = contents.username) !== null && _a !== void 0 ? _a : (contents.username = username);
|
|
132
|
+
this.contents.set(username, contents);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
(_b = org.username) !== null && _b !== void 0 ? _b : (org.username = username);
|
|
137
|
+
this.contents.set(username, org);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
update(username, org) {
|
|
141
|
+
const existing = this.get(username) || {};
|
|
142
|
+
const merged = Object.assign({}, existing, org);
|
|
143
|
+
return this.set(username, merged);
|
|
144
|
+
}
|
|
145
|
+
async remove(username) {
|
|
146
|
+
var _a;
|
|
147
|
+
await ((_a = this.configs.get(username)) === null || _a === void 0 ? void 0 : _a.unlink());
|
|
148
|
+
this.configs.delete(username);
|
|
149
|
+
this.contents.delete(username);
|
|
150
|
+
}
|
|
151
|
+
async write(username) {
|
|
152
|
+
const config = this.configs.get(username);
|
|
153
|
+
if (config) {
|
|
154
|
+
return (await config.write());
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const contents = this.contents.get(username) || {};
|
|
158
|
+
await this.read(username, false, false);
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
160
|
+
const config = this.configs.get(username);
|
|
161
|
+
config.setContentsFromObject(contents);
|
|
162
|
+
return (await config.write());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async init() {
|
|
166
|
+
this.logger = await logger_1.Logger.child(this.constructor.name);
|
|
167
|
+
}
|
|
168
|
+
async getAllFiles() {
|
|
169
|
+
const regex = this.getFileRegex();
|
|
170
|
+
try {
|
|
171
|
+
return (await fs.promises.readdir(global_1.Global.DIR)).filter((file) => regex.test(file));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
parseUsername(filename) {
|
|
178
|
+
return filename.replace(this.getFileExtension(), '');
|
|
179
|
+
}
|
|
180
|
+
parseFilename(username) {
|
|
181
|
+
return path.join(global_1.Global.DIR, `${username}${this.getFileExtension()}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.BaseOrgAccessor = BaseOrgAccessor;
|
|
185
|
+
class OrgAccessor extends BaseOrgAccessor {
|
|
186
|
+
async initAuthFile(username, throwOnNotFound = false) {
|
|
187
|
+
return authInfoConfig_1.AuthInfoConfig.create({
|
|
188
|
+
...authInfoConfig_1.AuthInfoConfig.getOptions(username),
|
|
189
|
+
throwOnNotFound,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
getFileRegex() {
|
|
193
|
+
// The regular expression that filters files stored in $HOME/.sfdx
|
|
194
|
+
return /^[^.][^@]*@[^.]+(\.[^.\s]+)+\.json$/;
|
|
195
|
+
}
|
|
196
|
+
getFileExtension() {
|
|
197
|
+
return '.json';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.OrgAccessor = OrgAccessor;
|
|
201
|
+
//# sourceMappingURL=orgAccessor.js.map
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Nullable } from '@salesforce/ts-types';
|
|
2
|
+
import { SandboxOrgConfig } from '../../config/sandboxOrgConfig';
|
|
3
|
+
import { SandboxFields } from '../../org';
|
|
2
4
|
import { GlobalInfo } from '../globalInfoConfig';
|
|
3
5
|
import { SfSandbox, SfSandboxes } from '../types';
|
|
4
|
-
|
|
6
|
+
import { BaseOrgAccessor } from './orgAccessor';
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
export declare class GlobalInfoSandboxAccessor {
|
|
5
11
|
private globalInfo;
|
|
6
12
|
constructor(globalInfo: GlobalInfo);
|
|
7
13
|
/**
|
|
@@ -34,3 +40,8 @@ export declare class SandboxAccessor {
|
|
|
34
40
|
set(sandboxOrgId: string, entity: SfSandbox): void;
|
|
35
41
|
unset(sandboxOrgId: string): void;
|
|
36
42
|
}
|
|
43
|
+
export declare class SandboxAccessor extends BaseOrgAccessor<SandboxOrgConfig, SandboxFields> {
|
|
44
|
+
protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<SandboxOrgConfig>;
|
|
45
|
+
protected getFileRegex(): RegExp;
|
|
46
|
+
protected getFileExtension(): string;
|
|
47
|
+
}
|
|
@@ -6,9 +6,14 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.SandboxAccessor = void 0;
|
|
9
|
+
exports.SandboxAccessor = exports.GlobalInfoSandboxAccessor = void 0;
|
|
10
|
+
const sandboxOrgConfig_1 = require("../../config/sandboxOrgConfig");
|
|
10
11
|
const types_1 = require("../types");
|
|
11
|
-
|
|
12
|
+
const orgAccessor_1 = require("./orgAccessor");
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
class GlobalInfoSandboxAccessor {
|
|
12
17
|
constructor(globalInfo) {
|
|
13
18
|
this.globalInfo = globalInfo;
|
|
14
19
|
}
|
|
@@ -59,5 +64,20 @@ class SandboxAccessor {
|
|
|
59
64
|
delete this.globalInfo.get(types_1.SfInfoKeys.SANDBOXES)[sandboxOrgId];
|
|
60
65
|
}
|
|
61
66
|
}
|
|
67
|
+
exports.GlobalInfoSandboxAccessor = GlobalInfoSandboxAccessor;
|
|
68
|
+
class SandboxAccessor extends orgAccessor_1.BaseOrgAccessor {
|
|
69
|
+
async initAuthFile(username, throwOnNotFound = false) {
|
|
70
|
+
return sandboxOrgConfig_1.SandboxOrgConfig.create({
|
|
71
|
+
...sandboxOrgConfig_1.SandboxOrgConfig.getOptions(username),
|
|
72
|
+
throwOnNotFound,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
getFileRegex() {
|
|
76
|
+
return /^(00D.*?)\.sandbox\.json$/;
|
|
77
|
+
}
|
|
78
|
+
getFileExtension() {
|
|
79
|
+
return '.sandbox.json';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
62
82
|
exports.SandboxAccessor = SandboxAccessor;
|
|
63
83
|
//# sourceMappingURL=sandboxAccessor.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
2
|
+
import { Optional } from '@salesforce/ts-types';
|
|
3
|
+
import { GlobalInfo } from '../globalInfoConfig';
|
|
4
|
+
import { SfTokens, SfToken, Timestamp } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated
|
|
7
|
+
*/
|
|
8
|
+
export declare class GlobaInfoTokenAccessor {
|
|
9
|
+
private globalInfo;
|
|
10
|
+
constructor(globalInfo: GlobalInfo);
|
|
11
|
+
getAll(decrypt?: boolean): SfTokens;
|
|
12
|
+
get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
|
|
13
|
+
has(name: string): boolean;
|
|
14
|
+
set(name: string, token: SfToken): void;
|
|
15
|
+
update(name: string, token: Partial<SfToken>): void;
|
|
16
|
+
unset(name: string): void;
|
|
17
|
+
}
|
|
18
|
+
export declare class TokenAccessor extends AsyncOptionalCreatable {
|
|
19
|
+
private config;
|
|
20
|
+
getAll(decrypt?: boolean): SfTokens;
|
|
21
|
+
get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
|
|
22
|
+
has(name: string): boolean;
|
|
23
|
+
set(name: string, token: SfToken): void;
|
|
24
|
+
update(name: string, token: Partial<SfToken>): void;
|
|
25
|
+
unset(name: string): void;
|
|
26
|
+
write(): Promise<SfTokens>;
|
|
27
|
+
protected init(): Promise<void>;
|
|
28
|
+
}
|
|
@@ -6,9 +6,14 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.TokenAccessor = void 0;
|
|
9
|
+
exports.TokenAccessor = exports.GlobaInfoTokenAccessor = void 0;
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const tokensConfig_1 = require("../../config/tokensConfig");
|
|
10
12
|
const types_1 = require("../types");
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
class GlobaInfoTokenAccessor {
|
|
12
17
|
constructor(globalInfo) {
|
|
13
18
|
this.globalInfo = globalInfo;
|
|
14
19
|
}
|
|
@@ -31,5 +36,32 @@ class TokenAccessor {
|
|
|
31
36
|
delete this.globalInfo.get(types_1.SfInfoKeys.TOKENS)[name];
|
|
32
37
|
}
|
|
33
38
|
}
|
|
39
|
+
exports.GlobaInfoTokenAccessor = GlobaInfoTokenAccessor;
|
|
40
|
+
class TokenAccessor extends kit_1.AsyncOptionalCreatable {
|
|
41
|
+
getAll(decrypt = false) {
|
|
42
|
+
return this.config.getContents(decrypt) || {};
|
|
43
|
+
}
|
|
44
|
+
get(name, decrypt = false) {
|
|
45
|
+
return this.config.get(name, decrypt);
|
|
46
|
+
}
|
|
47
|
+
has(name) {
|
|
48
|
+
return !!this.getAll()[name];
|
|
49
|
+
}
|
|
50
|
+
set(name, token) {
|
|
51
|
+
this.config.set(name, token);
|
|
52
|
+
}
|
|
53
|
+
update(name, token) {
|
|
54
|
+
this.config.update(name, token);
|
|
55
|
+
}
|
|
56
|
+
unset(name) {
|
|
57
|
+
this.config.unset(name);
|
|
58
|
+
}
|
|
59
|
+
async write() {
|
|
60
|
+
return this.config.write();
|
|
61
|
+
}
|
|
62
|
+
async init() {
|
|
63
|
+
this.config = await tokensConfig_1.TokensConfig.create();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
34
66
|
exports.TokenAccessor = TokenAccessor;
|
|
35
67
|
//# sourceMappingURL=tokenAccessor.js.map
|