@salesforce/core 4.0.0 → 4.0.1
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/LICENSE.txt +1 -1
- package/README.md +93 -44
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +28 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/config.d.ts +87 -22
- package/lib/config/config.js +117 -65
- package/lib/config/configAggregator.d.ts +41 -35
- package/lib/config/configAggregator.js +102 -73
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +38 -29
- package/lib/config/configGroup.d.ts +141 -0
- package/lib/config/configGroup.js +225 -0
- package/lib/config/configStore.d.ts +9 -9
- package/lib/config/configStore.js +17 -15
- package/lib/config/envVars.d.ts +15 -9
- package/lib/config/envVars.js +71 -47
- package/lib/config/orgUsersConfig.js +2 -0
- package/lib/config/sandboxOrgConfig.js +2 -0
- package/lib/config/sandboxProcessCache.d.ts +16 -0
- package/lib/config/sandboxProcessCache.js +38 -0
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +29 -0
- package/lib/config/ttlConfig.d.ts +34 -0
- package/lib/config/ttlConfig.js +50 -0
- package/lib/crypto/crypto.js +15 -22
- package/lib/crypto/keyChain.js +2 -3
- package/lib/crypto/keyChainImpl.d.ts +5 -3
- package/lib/crypto/keyChainImpl.js +58 -61
- package/lib/crypto/secureBuffer.d.ts +1 -1
- package/lib/deviceOauthService.d.ts +3 -3
- package/lib/deviceOauthService.js +27 -25
- package/lib/exported.d.ts +15 -12
- package/lib/exported.js +28 -16
- package/lib/global.d.ts +11 -3
- package/lib/global.js +39 -12
- package/lib/lifecycleEvents.d.ts +1 -1
- package/lib/lifecycleEvents.js +3 -0
- package/lib/logger.d.ts +19 -9
- package/lib/logger.js +112 -86
- package/lib/messages.d.ts +53 -36
- package/lib/messages.js +81 -91
- package/lib/org/authInfo.d.ts +56 -20
- package/lib/org/authInfo.js +232 -131
- package/lib/org/authRemover.d.ts +8 -7
- package/lib/org/authRemover.js +32 -28
- package/lib/org/connection.d.ts +13 -37
- package/lib/org/connection.js +78 -124
- package/lib/org/index.js +5 -1
- package/lib/org/org.d.ts +151 -48
- package/lib/org/org.js +466 -220
- package/lib/org/orgConfigProperties.d.ts +64 -3
- package/lib/org/orgConfigProperties.js +96 -4
- package/lib/org/permissionSetAssignment.js +4 -13
- package/lib/org/scratchOrgCache.d.ts +20 -0
- package/lib/org/scratchOrgCache.js +33 -0
- package/lib/org/scratchOrgCreate.d.ts +28 -17
- package/lib/org/scratchOrgCreate.js +125 -53
- package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
- package/lib/org/scratchOrgErrorCodes.js +34 -17
- package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
- package/lib/org/scratchOrgInfoApi.d.ts +21 -47
- package/lib/org/scratchOrgInfoApi.js +129 -63
- package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
- package/lib/org/scratchOrgInfoGenerator.js +76 -62
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
- package/lib/org/scratchOrgLifecycleEvents.js +41 -0
- package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
- package/lib/org/scratchOrgSettingsGenerator.js +165 -98
- package/lib/org/scratchOrgTypes.d.ts +43 -0
- package/lib/org/scratchOrgTypes.js +9 -0
- package/lib/org/user.d.ts +1 -1
- package/lib/org/user.js +25 -34
- package/lib/schema/printer.d.ts +6 -0
- package/lib/schema/printer.js +34 -31
- package/lib/schema/validator.d.ts +12 -10
- package/lib/schema/validator.js +56 -76
- package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
- package/lib/{sfdxError.js → sfError.js} +40 -30
- package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
- package/lib/sfProject.js +651 -0
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +27 -12
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +47 -31
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
- package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
- package/lib/stateAggregator/index.d.ts +4 -0
- package/lib/stateAggregator/index.js +27 -0
- package/lib/stateAggregator/stateAggregator.d.ts +25 -0
- package/lib/stateAggregator/stateAggregator.js +46 -0
- package/lib/status/myDomainResolver.d.ts +1 -1
- package/lib/status/myDomainResolver.js +4 -4
- package/lib/status/pollingClient.js +4 -4
- package/lib/status/streamingClient.d.ts +2 -2
- package/lib/status/streamingClient.js +58 -63
- package/lib/status/types.d.ts +2 -2
- package/lib/testSetup.d.ts +206 -75
- package/lib/testSetup.js +463 -165
- package/lib/util/cache.d.ts +2 -2
- package/lib/util/cache.js +6 -6
- package/lib/util/checkLightningDomain.js +3 -4
- package/lib/util/directoryWriter.d.ts +12 -0
- package/lib/util/directoryWriter.js +54 -0
- package/lib/util/getJwtAudienceUrl.js +1 -1
- package/lib/util/internal.d.ts +28 -2
- package/lib/util/internal.js +65 -8
- package/lib/util/jsonXmlTools.js +2 -4
- package/lib/util/mapKeys.d.ts +9 -9
- package/lib/util/mapKeys.js +13 -9
- package/lib/util/sfdc.d.ts +51 -51
- package/lib/util/sfdc.js +74 -79
- package/lib/util/sfdcUrl.d.ts +5 -19
- package/lib/util/sfdcUrl.js +40 -49
- package/lib/util/structuredWriter.d.ts +9 -0
- package/lib/util/structuredWriter.js +3 -0
- package/lib/util/zipWriter.d.ts +8 -6
- package/lib/util/zipWriter.js +13 -13
- package/lib/webOAuthServer.d.ts +20 -6
- package/lib/webOAuthServer.js +102 -56
- package/messageTransformer/messageTransformer.ts +93 -0
- package/messages/auth.md +9 -1
- package/messages/config.md +42 -6
- package/messages/connection.md +8 -0
- package/messages/core.md +10 -0
- package/messages/envVars.md +37 -3
- package/messages/org.md +21 -1
- package/messages/scratchOrgCreate.md +2 -6
- package/messages/scratchOrgErrorCodes.md +17 -1
- package/messages/scratchOrgInfoApi.md +9 -0
- package/messages/scratchOrgInfoGenerator.md +9 -1
- package/package.json +121 -46
- package/CHANGELOG.md +0 -1244
- package/lib/config/keychainConfig.d.ts +0 -19
- package/lib/config/keychainConfig.js +0 -43
- 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/accessors/tokenAccessor.js +0 -35
- package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
- package/lib/globalInfo/globalInfoConfig.js +0 -105
- package/lib/globalInfo/index.d.ts +0 -6
- package/lib/globalInfo/index.js +0 -29
- package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
- package/lib/globalInfo/sfdxDataHandler.js +0 -217
- package/lib/globalInfo/types.d.ts +0 -39
- package/lib/globalInfo/types.js +0 -10
- package/lib/sfdxProject.js +0 -557
- package/lib/util/fs.d.ts +0 -201
- package/lib/util/fs.js +0 -378
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
1
2
|
import { Nullable } from '@salesforce/ts-types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
export declare class AliasAccessor {
|
|
6
|
-
private
|
|
7
|
-
constructor(globalInfo: GlobalInfo);
|
|
3
|
+
import { AuthFields, ConfigContents } from '../../exported';
|
|
4
|
+
import { SfToken } from './tokenAccessor';
|
|
5
|
+
export type Aliasable = string | (Partial<AuthFields> & Partial<SfToken>);
|
|
6
|
+
export declare class AliasAccessor extends AsyncOptionalCreatable {
|
|
7
|
+
private config;
|
|
8
8
|
/**
|
|
9
9
|
* Returns all the aliases for all the values
|
|
10
10
|
*/
|
|
11
|
-
getAll():
|
|
11
|
+
getAll(): ConfigContents<string>;
|
|
12
12
|
/**
|
|
13
13
|
* Returns all the aliases for a given entity
|
|
14
14
|
*
|
|
@@ -55,6 +55,16 @@ export declare class AliasAccessor {
|
|
|
55
55
|
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
56
56
|
*/
|
|
57
57
|
resolveUsername(usernameOrAlias: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* If the provided string is an alias, return it.
|
|
60
|
+
* If the provided string is not an alias, return the username of the provided alias
|
|
61
|
+
*
|
|
62
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
63
|
+
* or an alias.
|
|
64
|
+
*
|
|
65
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
66
|
+
*/
|
|
67
|
+
resolveAlias(usernameOrAlias: string): Nullable<string>;
|
|
58
68
|
/**
|
|
59
69
|
* Set an alias for the given aliasable entity
|
|
60
70
|
*
|
|
@@ -63,19 +73,24 @@ export declare class AliasAccessor {
|
|
|
63
73
|
*/
|
|
64
74
|
set(alias: string, entity: Aliasable): void;
|
|
65
75
|
/**
|
|
66
|
-
*
|
|
76
|
+
* Unset the given alias.
|
|
67
77
|
*
|
|
68
|
-
* @param alias the alias you want to set
|
|
69
|
-
* @param entity the aliasable entity that's being aliased
|
|
70
78
|
*/
|
|
71
|
-
update(alias: string, entity: Aliasable): void;
|
|
72
79
|
unset(alias: string): void;
|
|
73
80
|
/**
|
|
74
|
-
*
|
|
81
|
+
* Unsets all the aliases for the given entity.
|
|
75
82
|
*
|
|
76
83
|
* @param entity the aliasable entity for which you want to unset all aliases
|
|
77
84
|
*/
|
|
78
85
|
unsetAll(entity: Aliasable): void;
|
|
86
|
+
write(): Promise<ConfigContents>;
|
|
87
|
+
/**
|
|
88
|
+
* Returns true if the provided alias exists
|
|
89
|
+
*
|
|
90
|
+
* @param alias the alias you want to check
|
|
91
|
+
*/
|
|
92
|
+
has(alias: string): boolean;
|
|
93
|
+
protected init(): Promise<void>;
|
|
79
94
|
/**
|
|
80
95
|
* Returns the username of given aliasable entity
|
|
81
96
|
*/
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AliasAccessor = void 0;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.globalInfo = globalInfo;
|
|
15
|
-
}
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const aliasesConfig_1 = require("../../config/aliasesConfig");
|
|
12
|
+
const sfError_1 = require("../../sfError");
|
|
13
|
+
class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
16
14
|
getAll(entity) {
|
|
17
|
-
|
|
15
|
+
// This will only return aliases under "orgs". This will need to be modified
|
|
16
|
+
// if/when we want to support more aliases groups.
|
|
17
|
+
const all = (this.config.getGroup() ?? {});
|
|
18
18
|
if (entity) {
|
|
19
19
|
const value = this.getNameOf(entity);
|
|
20
20
|
return Object.entries(all)
|
|
@@ -31,8 +31,7 @@ class AliasAccessor {
|
|
|
31
31
|
* @param entity the aliasable entity that you want to get the alias of
|
|
32
32
|
*/
|
|
33
33
|
get(entity) {
|
|
34
|
-
|
|
35
|
-
return (_a = this.getAll(entity).find((alias) => alias)) !== null && _a !== void 0 ? _a : null;
|
|
34
|
+
return this.getAll(entity).find((alias) => alias) ?? null;
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
37
|
* Returns the value that corresponds to the given alias if it exists
|
|
@@ -40,8 +39,7 @@ class AliasAccessor {
|
|
|
40
39
|
* @param alias the alias that corresponds to a value
|
|
41
40
|
*/
|
|
42
41
|
getValue(alias) {
|
|
43
|
-
|
|
44
|
-
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
42
|
+
return this.getAll()[alias] ?? null;
|
|
45
43
|
}
|
|
46
44
|
/**
|
|
47
45
|
* Returns the username that corresponds to the given alias if it exists
|
|
@@ -49,8 +47,7 @@ class AliasAccessor {
|
|
|
49
47
|
* @param alias the alias that corresponds to a username
|
|
50
48
|
*/
|
|
51
49
|
getUsername(alias) {
|
|
52
|
-
|
|
53
|
-
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
50
|
+
return this.getAll()[alias] ?? null;
|
|
54
51
|
}
|
|
55
52
|
/**
|
|
56
53
|
* If the provided string is an alias, it returns the corresponding value.
|
|
@@ -63,8 +60,7 @@ class AliasAccessor {
|
|
|
63
60
|
* @param valueOrAlias a string that might be a value or might be an alias
|
|
64
61
|
*/
|
|
65
62
|
resolveValue(valueOrAlias) {
|
|
66
|
-
|
|
67
|
-
return (_a = this.getValue(valueOrAlias)) !== null && _a !== void 0 ? _a : valueOrAlias;
|
|
63
|
+
return this.getValue(valueOrAlias) ?? valueOrAlias;
|
|
68
64
|
}
|
|
69
65
|
/**
|
|
70
66
|
* If the provided string is an alias, it returns the corresponding username.
|
|
@@ -77,8 +73,21 @@ class AliasAccessor {
|
|
|
77
73
|
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
78
74
|
*/
|
|
79
75
|
resolveUsername(usernameOrAlias) {
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
return this.getUsername(usernameOrAlias) ?? usernameOrAlias;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* If the provided string is an alias, return it.
|
|
80
|
+
* If the provided string is not an alias, return the username of the provided alias
|
|
81
|
+
*
|
|
82
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
83
|
+
* or an alias.
|
|
84
|
+
*
|
|
85
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
86
|
+
*/
|
|
87
|
+
resolveAlias(usernameOrAlias) {
|
|
88
|
+
if (this.has(usernameOrAlias))
|
|
89
|
+
return usernameOrAlias;
|
|
90
|
+
return Object.entries(this.getAll()).find(([, username]) => username === usernameOrAlias)?.[0];
|
|
82
91
|
}
|
|
83
92
|
/**
|
|
84
93
|
* Set an alias for the given aliasable entity
|
|
@@ -87,24 +96,17 @@ class AliasAccessor {
|
|
|
87
96
|
* @param entity the aliasable entity that's being aliased
|
|
88
97
|
*/
|
|
89
98
|
set(alias, entity) {
|
|
90
|
-
|
|
91
|
-
this.globalInfo.set(`${types_1.SfInfoKeys.ALIASES}["${alias}"]`, value);
|
|
99
|
+
this.config.set(alias, this.getNameOf(entity));
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
|
-
*
|
|
102
|
+
* Unset the given alias.
|
|
95
103
|
*
|
|
96
|
-
* @param alias the alias you want to set
|
|
97
|
-
* @param entity the aliasable entity that's being aliased
|
|
98
104
|
*/
|
|
99
|
-
update(alias, entity) {
|
|
100
|
-
const value = this.getNameOf(entity);
|
|
101
|
-
this.globalInfo.update(`${types_1.SfInfoKeys.ALIASES}["${alias}"]`, value);
|
|
102
|
-
}
|
|
103
105
|
unset(alias) {
|
|
104
|
-
|
|
106
|
+
this.config.unset(alias);
|
|
105
107
|
}
|
|
106
108
|
/**
|
|
107
|
-
*
|
|
109
|
+
* Unsets all the aliases for the given entity.
|
|
108
110
|
*
|
|
109
111
|
* @param entity the aliasable entity for which you want to unset all aliases
|
|
110
112
|
*/
|
|
@@ -112,16 +114,30 @@ class AliasAccessor {
|
|
|
112
114
|
const aliases = this.getAll(entity);
|
|
113
115
|
aliases.forEach((alias) => this.unset(alias));
|
|
114
116
|
}
|
|
117
|
+
async write() {
|
|
118
|
+
return this.config.write();
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns true if the provided alias exists
|
|
122
|
+
*
|
|
123
|
+
* @param alias the alias you want to check
|
|
124
|
+
*/
|
|
125
|
+
has(alias) {
|
|
126
|
+
return this.config.has(alias);
|
|
127
|
+
}
|
|
128
|
+
async init() {
|
|
129
|
+
this.config = await aliasesConfig_1.AliasesConfig.create(aliasesConfig_1.AliasesConfig.getDefaultOptions());
|
|
130
|
+
}
|
|
115
131
|
/**
|
|
116
132
|
* Returns the username of given aliasable entity
|
|
117
133
|
*/
|
|
134
|
+
// eslint-disable-next-line class-methods-use-this
|
|
118
135
|
getNameOf(entity) {
|
|
119
|
-
var _a;
|
|
120
136
|
if (typeof entity === 'string')
|
|
121
137
|
return entity;
|
|
122
|
-
const aliaseeName =
|
|
138
|
+
const aliaseeName = entity.username ?? entity.user;
|
|
123
139
|
if (!aliaseeName) {
|
|
124
|
-
throw new
|
|
140
|
+
throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
|
|
125
141
|
}
|
|
126
142
|
return aliaseeName;
|
|
127
143
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { Nullable } from '@salesforce/ts-types';
|
|
4
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
5
|
+
import { AuthInfoConfig } from '../../config/authInfoConfig';
|
|
6
|
+
import { AuthFields } from '../../org';
|
|
7
|
+
import { ConfigFile } from '../../config/configFile';
|
|
8
|
+
import { ConfigContents } from '../../config/configStore';
|
|
9
|
+
export declare abstract class BaseOrgAccessor<T extends ConfigFile, P extends ConfigContents> extends AsyncOptionalCreatable {
|
|
10
|
+
private configs;
|
|
11
|
+
private contents;
|
|
12
|
+
private logger;
|
|
13
|
+
/**
|
|
14
|
+
* Read the auth file for the given username. Once the file has been read, it can be re-accessed with the `get` method.
|
|
15
|
+
*
|
|
16
|
+
* @param username username to read
|
|
17
|
+
* @param decrypt if true, decrypt encrypted values
|
|
18
|
+
* @param throwOnNotFound throw if file is not found for username
|
|
19
|
+
*/
|
|
20
|
+
read(username: string, decrypt?: boolean, throwOnNotFound?: boolean): Promise<Nullable<P>>;
|
|
21
|
+
/**
|
|
22
|
+
* Read all the auth files under the global state directory
|
|
23
|
+
*
|
|
24
|
+
* @param decrypt if true, decrypt encrypted values
|
|
25
|
+
*/
|
|
26
|
+
readAll(decrypt?: boolean): Promise<P[]>;
|
|
27
|
+
get(username: string, decrypt?: boolean, throwOnNotFound?: true): P;
|
|
28
|
+
/**
|
|
29
|
+
* Return the contents of all the auth files from cache. The `read` or `readAll` methods must be called first in order to populate the cache.
|
|
30
|
+
*
|
|
31
|
+
* @param decrypt if true, decrypt encrypted values
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
getAll(decrypt?: boolean): P[];
|
|
35
|
+
/**
|
|
36
|
+
* Returns true if the username has been cached.
|
|
37
|
+
*
|
|
38
|
+
* @param username
|
|
39
|
+
*/
|
|
40
|
+
has(username: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Returns true if there is an auth file for the given username. The `read` or `readAll` methods must be called first in order to populate the cache.
|
|
43
|
+
*
|
|
44
|
+
* @param username
|
|
45
|
+
*/
|
|
46
|
+
exists(username: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Return the file stats for a given userame's auth file.
|
|
49
|
+
*
|
|
50
|
+
* @param username
|
|
51
|
+
*/
|
|
52
|
+
stat(username: string): Promise<Nullable<fs.Stats>>;
|
|
53
|
+
/**
|
|
54
|
+
* Returns true if there is an auth file for the given username
|
|
55
|
+
*
|
|
56
|
+
* @param username
|
|
57
|
+
*/
|
|
58
|
+
hasFile(username: string): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Return all auth files under the global state directory.
|
|
61
|
+
*/
|
|
62
|
+
list(): Promise<string[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Set the contents for a given username.
|
|
65
|
+
*
|
|
66
|
+
* @param username
|
|
67
|
+
* @param org
|
|
68
|
+
*/
|
|
69
|
+
set(username: string, org: P): void;
|
|
70
|
+
/**
|
|
71
|
+
* Update the contents for a given username.
|
|
72
|
+
*
|
|
73
|
+
* @param username
|
|
74
|
+
* @param org
|
|
75
|
+
*/
|
|
76
|
+
update(username: string, org: Partial<P>): void;
|
|
77
|
+
/**
|
|
78
|
+
* Delete the auth file for a given username.
|
|
79
|
+
*
|
|
80
|
+
* @param username
|
|
81
|
+
*/
|
|
82
|
+
remove(username: string): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Write the contents of the auth file for a given username.
|
|
85
|
+
*
|
|
86
|
+
* @param username
|
|
87
|
+
*/
|
|
88
|
+
write(username: string): Promise<Nullable<P>>;
|
|
89
|
+
protected init(): Promise<void>;
|
|
90
|
+
private getAllFiles;
|
|
91
|
+
private parseUsername;
|
|
92
|
+
private parseFilename;
|
|
93
|
+
protected abstract initAuthFile(username: string, throwOnNotFound?: boolean): Promise<T>;
|
|
94
|
+
protected abstract getFileRegex(): RegExp;
|
|
95
|
+
protected abstract getFileExtension(): string;
|
|
96
|
+
}
|
|
97
|
+
export declare class OrgAccessor extends BaseOrgAccessor<AuthInfoConfig, AuthFields> {
|
|
98
|
+
protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<AuthInfoConfig>;
|
|
99
|
+
protected getFileRegex(): RegExp;
|
|
100
|
+
protected getFileExtension(): string;
|
|
101
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
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 = 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 logger_1 = require("../../logger");
|
|
16
|
+
const messages_1 = require("../../messages");
|
|
17
|
+
function chunk(array, chunkSize) {
|
|
18
|
+
const final = [];
|
|
19
|
+
for (let i = 0, len = array.length; i < len; i += chunkSize)
|
|
20
|
+
final.push(array.slice(i, i + chunkSize));
|
|
21
|
+
return final;
|
|
22
|
+
}
|
|
23
|
+
class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.configs = new Map();
|
|
27
|
+
this.contents = new Map();
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read the auth file for the given username. Once the file has been read, it can be re-accessed with the `get` method.
|
|
31
|
+
*
|
|
32
|
+
* @param username username to read
|
|
33
|
+
* @param decrypt if true, decrypt encrypted values
|
|
34
|
+
* @param throwOnNotFound throw if file is not found for username
|
|
35
|
+
*/
|
|
36
|
+
async read(username, decrypt = false, throwOnNotFound = true) {
|
|
37
|
+
try {
|
|
38
|
+
const config = await this.initAuthFile(username, throwOnNotFound);
|
|
39
|
+
this.configs.set(username, config);
|
|
40
|
+
return this.get(username, decrypt);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Read all the auth files under the global state directory
|
|
48
|
+
*
|
|
49
|
+
* @param decrypt if true, decrypt encrypted values
|
|
50
|
+
*/
|
|
51
|
+
async readAll(decrypt = false) {
|
|
52
|
+
const fileChunks = chunk(await this.getAllFiles(), 50);
|
|
53
|
+
for (const fileChunk of fileChunks) {
|
|
54
|
+
const promises = fileChunk.map(async (f) => {
|
|
55
|
+
const username = this.parseUsername(f);
|
|
56
|
+
const config = await this.initAuthFile(username);
|
|
57
|
+
this.configs.set(username, config);
|
|
58
|
+
});
|
|
59
|
+
// eslint-disable-next-line no-await-in-loop
|
|
60
|
+
await Promise.all(promises);
|
|
61
|
+
}
|
|
62
|
+
return this.getAll(decrypt);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Return the contents of the username's auth file from cache.
|
|
66
|
+
* The `read` or `readAll` methods must be called first in order to populate the cache.
|
|
67
|
+
* If throwOnNotFound is not true, an empty object {} is returned if the org is not found.
|
|
68
|
+
*
|
|
69
|
+
* @param username username to get
|
|
70
|
+
* @param decrypt if true, decrypt encrypted values
|
|
71
|
+
* @param throwOnNotFound if true, throw if the auth file does not already exist in the cache
|
|
72
|
+
*/
|
|
73
|
+
get(username, decrypt = false, throwOnNotFound = false) {
|
|
74
|
+
const config = this.configs.get(username);
|
|
75
|
+
if (throwOnNotFound && config?.keys().length === 0) {
|
|
76
|
+
const messages = new messages_1.Messages('@salesforce/core', 'core', new Map([["authInfoCreationError", "Must pass a username and/or OAuth options when creating an AuthInfo instance."], ["authInfoOverwriteError", "Cannot create an AuthInfo instance that will overwrite existing auth data."], ["authInfoOverwriteError.actions", ["Create the AuthInfo instance using existing auth data by just passing the username. E.g., `AuthInfo.create({ username: 'my@user.org' });`."]], ["authCodeExchangeError", "Error authenticating with auth code due to: %s"], ["authCodeUsernameRetrievalError", "Could not retrieve the username after successful auth code exchange.\n\nDue to: %s"], ["jwtAuthError", "Error authenticating with JWT config due to: %s"], ["jwtAuthErrors", "Error authenticating with JWT.\nErrors encountered:\n%s"], ["refreshTokenAuthError", "Error authenticating with the refresh token due to: %s"], ["orgDataNotAvailableError", "An attempt to refresh the authentication token failed with a 'Data Not Found Error'. The org identified by username %s does not appear to exist. Likely cause is that the org was deleted by another user or has expired."], ["orgDataNotAvailableError.actions", ["Run `sfdx force:org:list --clean` to remove stale org authentications.", "Use `sfdx force:config:set` to update the defaultusername.", "Use `sfdx force:org:create` to create a new org.", "Use `sfdx auth` to authenticate an existing org."]], ["namedOrgNotFound", "No authorization information found for %s."], ["noAliasesFound", "Nothing to set."], ["invalidFormat", "Setting aliases must be in the format <key>=<value> but found: [%s]."], ["invalidJsonCasing", "All JSON input must have heads down camelcase keys. E.g., `{ sfdcLoginUrl: \"https://login.salesforce.com\" }`\nFound \"%s\" at %s"], ["missingClientId", "Client ID is required for JWT authentication."]]));
|
|
77
|
+
throw messages.createError('namedOrgNotFound', [username]);
|
|
78
|
+
}
|
|
79
|
+
if (config) {
|
|
80
|
+
this.contents.set(username, config.getContents(decrypt));
|
|
81
|
+
}
|
|
82
|
+
return this.contents.get(username);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Return the contents of all the auth files from cache. The `read` or `readAll` methods must be called first in order to populate the cache.
|
|
86
|
+
*
|
|
87
|
+
* @param decrypt if true, decrypt encrypted values
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
getAll(decrypt = false) {
|
|
91
|
+
return [...this.configs.keys()].map((username) => this.get(username, decrypt)).filter((org) => !(0, kit_1.isEmpty)(org));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns true if the username has been cached.
|
|
95
|
+
*
|
|
96
|
+
* @param username
|
|
97
|
+
*/
|
|
98
|
+
has(username) {
|
|
99
|
+
return this.contents.has(username);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns true if there is an auth file for the given username. The `read` or `readAll` methods must be called first in order to populate the cache.
|
|
103
|
+
*
|
|
104
|
+
* @param username
|
|
105
|
+
*/
|
|
106
|
+
async exists(username) {
|
|
107
|
+
const config = this.configs.get(username);
|
|
108
|
+
return config ? config.exists() : false;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Return the file stats for a given userame's auth file.
|
|
112
|
+
*
|
|
113
|
+
* @param username
|
|
114
|
+
*/
|
|
115
|
+
async stat(username) {
|
|
116
|
+
const config = this.configs.get(username);
|
|
117
|
+
return config ? config.stat() : null;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns true if there is an auth file for the given username
|
|
121
|
+
*
|
|
122
|
+
* @param username
|
|
123
|
+
*/
|
|
124
|
+
async hasFile(username) {
|
|
125
|
+
try {
|
|
126
|
+
await fs.promises.access(this.parseFilename(username));
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
this.logger.debug(`No auth file found for ${username}`);
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Return all auth files under the global state directory.
|
|
136
|
+
*/
|
|
137
|
+
async list() {
|
|
138
|
+
return this.getAllFiles();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Set the contents for a given username.
|
|
142
|
+
*
|
|
143
|
+
* @param username
|
|
144
|
+
* @param org
|
|
145
|
+
*/
|
|
146
|
+
set(username, org) {
|
|
147
|
+
const config = this.configs.get(username);
|
|
148
|
+
if (config) {
|
|
149
|
+
config.setContentsFromObject(org);
|
|
150
|
+
const contents = config.getContents();
|
|
151
|
+
contents.username ??= username;
|
|
152
|
+
this.contents.set(username, contents);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
org.username ??= username;
|
|
158
|
+
this.contents.set(username, org);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Update the contents for a given username.
|
|
163
|
+
*
|
|
164
|
+
* @param username
|
|
165
|
+
* @param org
|
|
166
|
+
*/
|
|
167
|
+
update(username, org) {
|
|
168
|
+
const existing = this.get(username) || {};
|
|
169
|
+
const merged = Object.assign({}, existing, org);
|
|
170
|
+
return this.set(username, merged);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Delete the auth file for a given username.
|
|
174
|
+
*
|
|
175
|
+
* @param username
|
|
176
|
+
*/
|
|
177
|
+
async remove(username) {
|
|
178
|
+
await this.configs.get(username)?.unlink();
|
|
179
|
+
this.configs.delete(username);
|
|
180
|
+
this.contents.delete(username);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Write the contents of the auth file for a given username.
|
|
184
|
+
*
|
|
185
|
+
* @param username
|
|
186
|
+
*/
|
|
187
|
+
async write(username) {
|
|
188
|
+
const config = this.configs.get(username);
|
|
189
|
+
if (config) {
|
|
190
|
+
return (await config.write());
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const contents = this.contents.get(username) ?? {};
|
|
194
|
+
await this.read(username, false, false);
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
196
|
+
const readConfig = this.configs.get(username);
|
|
197
|
+
readConfig.setContentsFromObject(contents);
|
|
198
|
+
return (await readConfig.write());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async init() {
|
|
202
|
+
this.logger = await logger_1.Logger.child(this.constructor.name);
|
|
203
|
+
}
|
|
204
|
+
async getAllFiles() {
|
|
205
|
+
const regex = this.getFileRegex();
|
|
206
|
+
try {
|
|
207
|
+
return (await fs.promises.readdir(global_1.Global.DIR)).filter((file) => regex.test(file));
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
parseUsername(filename) {
|
|
214
|
+
return filename.replace(this.getFileExtension(), '');
|
|
215
|
+
}
|
|
216
|
+
parseFilename(username) {
|
|
217
|
+
return path.join(global_1.Global.DIR, `${username}${this.getFileExtension()}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.BaseOrgAccessor = BaseOrgAccessor;
|
|
221
|
+
class OrgAccessor extends BaseOrgAccessor {
|
|
222
|
+
// eslint-disable-next-line class-methods-use-this
|
|
223
|
+
async initAuthFile(username, throwOnNotFound = false) {
|
|
224
|
+
return authInfoConfig_1.AuthInfoConfig.create({
|
|
225
|
+
...authInfoConfig_1.AuthInfoConfig.getOptions(username),
|
|
226
|
+
throwOnNotFound,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
// eslint-disable-next-line class-methods-use-this
|
|
230
|
+
getFileRegex() {
|
|
231
|
+
// The regular expression that filters files stored in $HOME/.sfdx
|
|
232
|
+
return /^[^.][^@]*@[^.]+(\.[^.\s]+)+\.json$/;
|
|
233
|
+
}
|
|
234
|
+
// eslint-disable-next-line class-methods-use-this
|
|
235
|
+
getFileExtension() {
|
|
236
|
+
return '.json';
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
exports.OrgAccessor = OrgAccessor;
|
|
240
|
+
//# sourceMappingURL=orgAccessor.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SandboxOrgConfig } from '../../config/sandboxOrgConfig';
|
|
2
|
+
import { SandboxFields } from '../../org';
|
|
3
|
+
import { BaseOrgAccessor } from './orgAccessor';
|
|
4
|
+
export declare class SandboxAccessor extends BaseOrgAccessor<SandboxOrgConfig, SandboxFields> {
|
|
5
|
+
protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<SandboxOrgConfig>;
|
|
6
|
+
protected getFileRegex(): RegExp;
|
|
7
|
+
protected getFileExtension(): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
/* eslint-disable class-methods-use-this */
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SandboxAccessor = void 0;
|
|
11
|
+
const sandboxOrgConfig_1 = require("../../config/sandboxOrgConfig");
|
|
12
|
+
const orgAccessor_1 = require("./orgAccessor");
|
|
13
|
+
class SandboxAccessor extends orgAccessor_1.BaseOrgAccessor {
|
|
14
|
+
async initAuthFile(username, throwOnNotFound = false) {
|
|
15
|
+
return sandboxOrgConfig_1.SandboxOrgConfig.create({
|
|
16
|
+
...sandboxOrgConfig_1.SandboxOrgConfig.getOptions(username),
|
|
17
|
+
throwOnNotFound,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
getFileRegex() {
|
|
21
|
+
return /^(00D.*?)\.sandbox\.json$/;
|
|
22
|
+
}
|
|
23
|
+
getFileExtension() {
|
|
24
|
+
return '.sandbox.json';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SandboxAccessor = SandboxAccessor;
|
|
28
|
+
//# sourceMappingURL=sandboxAccessor.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
2
|
+
import { JsonMap, Optional } from '@salesforce/ts-types';
|
|
3
|
+
export type SfToken = {
|
|
4
|
+
token: string;
|
|
5
|
+
url: string;
|
|
6
|
+
user?: string;
|
|
7
|
+
timestamp: string;
|
|
8
|
+
} & JsonMap;
|
|
9
|
+
export type SfTokens = {
|
|
10
|
+
[key: string]: SfToken;
|
|
11
|
+
};
|
|
12
|
+
export declare class TokenAccessor extends AsyncOptionalCreatable {
|
|
13
|
+
private config;
|
|
14
|
+
/**
|
|
15
|
+
* Return all tokens.
|
|
16
|
+
*
|
|
17
|
+
* @param decrypt
|
|
18
|
+
* @returns {SfTokens}
|
|
19
|
+
*/
|
|
20
|
+
getAll(decrypt?: boolean): SfTokens;
|
|
21
|
+
/**
|
|
22
|
+
* Return a token for the provided name.
|
|
23
|
+
*
|
|
24
|
+
* @param name
|
|
25
|
+
* @param decrypt
|
|
26
|
+
* @returns {Optional<SfToken>}
|
|
27
|
+
*/
|
|
28
|
+
get(name: string, decrypt?: boolean): Optional<SfToken>;
|
|
29
|
+
/**
|
|
30
|
+
* Return true if a given name has a token associated with it.
|
|
31
|
+
*
|
|
32
|
+
* @param name
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
has(name: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Set the token for the provided name.
|
|
38
|
+
*
|
|
39
|
+
* @param name
|
|
40
|
+
* @param token
|
|
41
|
+
*/
|
|
42
|
+
set(name: string, token: Partial<SfToken>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Update the token for the provided name.
|
|
45
|
+
*
|
|
46
|
+
* @param name
|
|
47
|
+
* @param token
|
|
48
|
+
*/
|
|
49
|
+
update(name: string, token: Partial<SfToken>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Unet the token for the provided name.
|
|
52
|
+
*
|
|
53
|
+
* @param name
|
|
54
|
+
*/
|
|
55
|
+
unset(name: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Write the contents to the token file.
|
|
58
|
+
*
|
|
59
|
+
* @returns {Promise<SfTokens>}
|
|
60
|
+
*/
|
|
61
|
+
write(): Promise<SfTokens>;
|
|
62
|
+
protected init(): Promise<void>;
|
|
63
|
+
}
|