@salesforce/core 4.0.0 → 4.1.0
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/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/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 +468 -225
- 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/stateAggregator/accessors/aliasAccessor.d.ts +129 -0
- package/lib/stateAggregator/accessors/aliasAccessor.js +263 -0
- 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 +204 -75
- package/lib/testSetup.js +468 -164
- 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 +123 -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/aliasAccessor.d.ts +0 -83
- package/lib/globalInfo/accessors/aliasAccessor.js +0 -130
- 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
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
2
|
+
import { Nullable } from '@salesforce/ts-types';
|
|
3
|
+
import { AuthFields } from '../../org/authInfo';
|
|
4
|
+
import { ConfigContents } from '../../config/configStore';
|
|
5
|
+
import { SfToken } from './tokenAccessor';
|
|
6
|
+
export type Aliasable = string | (Partial<AuthFields> & Partial<SfToken>);
|
|
7
|
+
export declare const DEFAULT_GROUP = "orgs";
|
|
8
|
+
export declare const FILENAME = "alias.json";
|
|
9
|
+
export declare class AliasAccessor extends AsyncOptionalCreatable {
|
|
10
|
+
private fileLocation;
|
|
11
|
+
/** orgs is the default group */
|
|
12
|
+
private aliasStore;
|
|
13
|
+
/**
|
|
14
|
+
* Returns all the aliases for all the values
|
|
15
|
+
*/
|
|
16
|
+
getAll(): ConfigContents<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns all the aliases for a given entity
|
|
19
|
+
*
|
|
20
|
+
* @param entity the aliasable entity that you want to get the aliases of
|
|
21
|
+
*/
|
|
22
|
+
getAll(entity: Aliasable): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Returns the first alias found for a given entity
|
|
25
|
+
*
|
|
26
|
+
* @param entity the aliasable entity that you want to get the alias of
|
|
27
|
+
*/
|
|
28
|
+
get(entity: Aliasable): Nullable<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the value that corresponds to the given alias if it exists
|
|
31
|
+
*
|
|
32
|
+
* @param alias the alias that corresponds to a value
|
|
33
|
+
*/
|
|
34
|
+
getValue(alias: string): Nullable<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the username that corresponds to the given alias if it exists
|
|
37
|
+
*
|
|
38
|
+
* @param alias the alias that corresponds to a username
|
|
39
|
+
*/
|
|
40
|
+
getUsername(alias: string): Nullable<string>;
|
|
41
|
+
/**
|
|
42
|
+
* If the provided string is an alias, it returns the corresponding username.
|
|
43
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
44
|
+
* is the username and return it.
|
|
45
|
+
*
|
|
46
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
47
|
+
* or an alias.
|
|
48
|
+
*
|
|
49
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
50
|
+
*/
|
|
51
|
+
resolveUsername(usernameOrAlias: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* If the provided string is an alias, return it.
|
|
54
|
+
* If the provided string is not an alias, return the username of the provided alias
|
|
55
|
+
*
|
|
56
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
57
|
+
* or an alias.
|
|
58
|
+
*
|
|
59
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
60
|
+
*/
|
|
61
|
+
resolveAlias(usernameOrAlias: string): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Set an alias for the given aliasable entity. Writes to the file
|
|
64
|
+
*
|
|
65
|
+
* @deprecated use setAndSave
|
|
66
|
+
* @param alias the alias you want to set
|
|
67
|
+
* @param entity the aliasable entity that's being aliased
|
|
68
|
+
*/
|
|
69
|
+
set(alias: string, entity: Aliasable): void;
|
|
70
|
+
/**
|
|
71
|
+
* Set an alias for the given aliasable entity. Writes to the file
|
|
72
|
+
*
|
|
73
|
+
* @param alias the alias you want to set
|
|
74
|
+
* @param entity the aliasable entity that's being aliased
|
|
75
|
+
*/
|
|
76
|
+
setAndSave(alias: string, entity: Aliasable): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Unset the given alias. Writes to the file
|
|
79
|
+
*
|
|
80
|
+
* @deprecated use unsetAndSave
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
unset(alias: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Unset the given alias(es). Writes to the file
|
|
86
|
+
*
|
|
87
|
+
*/
|
|
88
|
+
unsetAndSave(alias: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Unsets all the aliases for the given entity.
|
|
91
|
+
*
|
|
92
|
+
* @deprecated use unsetValuesAndSave
|
|
93
|
+
*
|
|
94
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
95
|
+
*/
|
|
96
|
+
unsetAll(entity: Aliasable): void;
|
|
97
|
+
/**
|
|
98
|
+
* Unset all the aliases for the given array of entity.
|
|
99
|
+
*
|
|
100
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
101
|
+
*/
|
|
102
|
+
unsetValuesAndSave(aliasees: Aliasable[]): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated the set/unset methods now write to the file when called. Use (un)setAndSave instead of calling (un)set and then calling write()
|
|
105
|
+
*/
|
|
106
|
+
write(): Promise<ConfigContents>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns true if the provided alias exists
|
|
109
|
+
*
|
|
110
|
+
* @param alias the alias you want to check
|
|
111
|
+
*/
|
|
112
|
+
has(alias: string): boolean;
|
|
113
|
+
protected init(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* go to the fileSystem and read the file, storing a copy in the class's store
|
|
116
|
+
* if the file doesn't exist, create it empty
|
|
117
|
+
*/
|
|
118
|
+
private readFileToAliasStore;
|
|
119
|
+
private saveAliasStoreToFile;
|
|
120
|
+
/**
|
|
121
|
+
* @deprecated use the async version of this method instead
|
|
122
|
+
* provided for the legacy sync set/unset methods. */
|
|
123
|
+
private readFileToAliasStoreSync;
|
|
124
|
+
/**
|
|
125
|
+
* @deprecated use the async version of this method instead
|
|
126
|
+
* provided for the legacy sync set/unset methods */
|
|
127
|
+
private saveAliasStoreToFileSync;
|
|
128
|
+
}
|
|
129
|
+
export declare const getFileLocation: () => string;
|
|
@@ -0,0 +1,263 @@
|
|
|
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.getFileLocation = exports.AliasAccessor = exports.FILENAME = exports.DEFAULT_GROUP = void 0;
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const node_os_1 = require("node:os");
|
|
12
|
+
const promises_1 = require("node:fs/promises");
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const proper_lockfile_1 = require("proper-lockfile");
|
|
15
|
+
const kit_1 = require("@salesforce/kit");
|
|
16
|
+
const global_1 = require("../../global");
|
|
17
|
+
const sfError_1 = require("../../sfError");
|
|
18
|
+
exports.DEFAULT_GROUP = 'orgs';
|
|
19
|
+
exports.FILENAME = 'alias.json';
|
|
20
|
+
const lockOptions = { stale: 10000 };
|
|
21
|
+
const lockRetryOptions = {
|
|
22
|
+
...lockOptions,
|
|
23
|
+
retries: { retries: 10, maxTimeout: 1000, factor: 2 },
|
|
24
|
+
};
|
|
25
|
+
class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
26
|
+
getAll(entity) {
|
|
27
|
+
// This will only return aliases under "orgs". This will need to be modified
|
|
28
|
+
// if/when we want to support more aliases groups.
|
|
29
|
+
if (entity) {
|
|
30
|
+
const nameFromEntity = getNameOf(entity);
|
|
31
|
+
return Array.from(this.aliasStore.entries())
|
|
32
|
+
.filter(([, value]) => nameFromEntity === value)
|
|
33
|
+
.map(([alias]) => alias);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return Object.fromEntries(this.aliasStore.entries());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the first alias found for a given entity
|
|
41
|
+
*
|
|
42
|
+
* @param entity the aliasable entity that you want to get the alias of
|
|
43
|
+
*/
|
|
44
|
+
get(entity) {
|
|
45
|
+
return this.getAll(entity)[0] ?? null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the value that corresponds to the given alias if it exists
|
|
49
|
+
*
|
|
50
|
+
* @param alias the alias that corresponds to a value
|
|
51
|
+
*/
|
|
52
|
+
getValue(alias) {
|
|
53
|
+
return this.aliasStore.get(alias) ?? null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the username that corresponds to the given alias if it exists
|
|
57
|
+
*
|
|
58
|
+
* @param alias the alias that corresponds to a username
|
|
59
|
+
*/
|
|
60
|
+
getUsername(alias) {
|
|
61
|
+
return this.aliasStore.get(alias) ?? null;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* If the provided string is an alias, it returns the corresponding username.
|
|
65
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
66
|
+
* is the username and return it.
|
|
67
|
+
*
|
|
68
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
69
|
+
* or an alias.
|
|
70
|
+
*
|
|
71
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
72
|
+
*/
|
|
73
|
+
resolveUsername(usernameOrAlias) {
|
|
74
|
+
return this.getUsername(usernameOrAlias) ?? usernameOrAlias;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* If the provided string is an alias, return it.
|
|
78
|
+
* If the provided string is not an alias, return the username of the provided alias
|
|
79
|
+
*
|
|
80
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
81
|
+
* or an alias.
|
|
82
|
+
*
|
|
83
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
84
|
+
*/
|
|
85
|
+
resolveAlias(usernameOrAlias) {
|
|
86
|
+
if (this.aliasStore.has(usernameOrAlias))
|
|
87
|
+
return usernameOrAlias;
|
|
88
|
+
return Array.from(this.aliasStore.entries()).find(([, value]) => value === usernameOrAlias)?.[0];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Set an alias for the given aliasable entity. Writes to the file
|
|
92
|
+
*
|
|
93
|
+
* @deprecated use setAndSave
|
|
94
|
+
* @param alias the alias you want to set
|
|
95
|
+
* @param entity the aliasable entity that's being aliased
|
|
96
|
+
*/
|
|
97
|
+
set(alias, entity) {
|
|
98
|
+
// get a very fresh copy to merge with to avoid conflicts
|
|
99
|
+
this.readFileToAliasStoreSync();
|
|
100
|
+
this.aliasStore.set(alias, getNameOf(entity));
|
|
101
|
+
this.saveAliasStoreToFileSync();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Set an alias for the given aliasable entity. Writes to the file
|
|
105
|
+
*
|
|
106
|
+
* @param alias the alias you want to set
|
|
107
|
+
* @param entity the aliasable entity that's being aliased
|
|
108
|
+
*/
|
|
109
|
+
async setAndSave(alias, entity) {
|
|
110
|
+
// get a very fresh copy to merge with to avoid conflicts, then lock
|
|
111
|
+
await this.readFileToAliasStore(true);
|
|
112
|
+
this.aliasStore.set(alias, getNameOf(entity));
|
|
113
|
+
return this.saveAliasStoreToFile();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Unset the given alias. Writes to the file
|
|
117
|
+
*
|
|
118
|
+
* @deprecated use unsetAndSave
|
|
119
|
+
*
|
|
120
|
+
*/
|
|
121
|
+
unset(alias) {
|
|
122
|
+
this.readFileToAliasStoreSync();
|
|
123
|
+
this.aliasStore.delete(alias);
|
|
124
|
+
this.saveAliasStoreToFileSync();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Unset the given alias(es). Writes to the file
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
async unsetAndSave(alias) {
|
|
131
|
+
await this.readFileToAliasStore(true);
|
|
132
|
+
this.aliasStore.delete(alias);
|
|
133
|
+
return this.saveAliasStoreToFile();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Unsets all the aliases for the given entity.
|
|
137
|
+
*
|
|
138
|
+
* @deprecated use unsetValuesAndSave
|
|
139
|
+
*
|
|
140
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
141
|
+
*/
|
|
142
|
+
unsetAll(entity) {
|
|
143
|
+
this.readFileToAliasStoreSync();
|
|
144
|
+
const aliases = this.getAll(entity);
|
|
145
|
+
aliases.forEach((a) => this.aliasStore.delete(a));
|
|
146
|
+
this.saveAliasStoreToFileSync();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Unset all the aliases for the given array of entity.
|
|
150
|
+
*
|
|
151
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
152
|
+
*/
|
|
153
|
+
async unsetValuesAndSave(aliasees) {
|
|
154
|
+
await this.readFileToAliasStore(true);
|
|
155
|
+
(0, kit_1.ensureArray)(aliasees)
|
|
156
|
+
.flatMap((a) => this.getAll(a))
|
|
157
|
+
.map((a) => this.aliasStore.delete(a));
|
|
158
|
+
return this.saveAliasStoreToFile();
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* @deprecated the set/unset methods now write to the file when called. Use (un)setAndSave instead of calling (un)set and then calling write()
|
|
162
|
+
*/
|
|
163
|
+
async write() {
|
|
164
|
+
return Promise.resolve(this.getAll());
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Returns true if the provided alias exists
|
|
168
|
+
*
|
|
169
|
+
* @param alias the alias you want to check
|
|
170
|
+
*/
|
|
171
|
+
has(alias) {
|
|
172
|
+
return this.aliasStore.has(alias);
|
|
173
|
+
}
|
|
174
|
+
async init() {
|
|
175
|
+
this.fileLocation = (0, exports.getFileLocation)();
|
|
176
|
+
await this.readFileToAliasStore();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* go to the fileSystem and read the file, storing a copy in the class's store
|
|
180
|
+
* if the file doesn't exist, create it empty
|
|
181
|
+
*/
|
|
182
|
+
async readFileToAliasStore(useLock = false) {
|
|
183
|
+
if (useLock) {
|
|
184
|
+
await (0, proper_lockfile_1.lock)(this.fileLocation, lockRetryOptions);
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
this.aliasStore = fileContentsRawToAliasStore(await (0, promises_1.readFile)(this.fileLocation, 'utf-8'));
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
if (e instanceof Error && 'code' in e && e.code === 'ENOENT') {
|
|
191
|
+
this.aliasStore = new Map();
|
|
192
|
+
await (0, promises_1.mkdir)((0, node_path_1.dirname)(this.fileLocation), { recursive: true });
|
|
193
|
+
await this.saveAliasStoreToFile();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (useLock)
|
|
197
|
+
return unlockIfLocked(this.fileLocation);
|
|
198
|
+
throw e;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async saveAliasStoreToFile() {
|
|
202
|
+
await (0, promises_1.writeFile)(this.fileLocation, aliasStoreToRawFileContents(this.aliasStore));
|
|
203
|
+
return unlockIfLocked(this.fileLocation);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated use the async version of this method instead
|
|
207
|
+
* provided for the legacy sync set/unset methods. */
|
|
208
|
+
readFileToAliasStoreSync() {
|
|
209
|
+
// the file is guaranteed to exist because this init method ensures it
|
|
210
|
+
// put a lock in place. This method is only used by legacy set/unset methods.
|
|
211
|
+
(0, proper_lockfile_1.lockSync)(this.fileLocation, lockOptions);
|
|
212
|
+
this.aliasStore = fileContentsRawToAliasStore((0, node_fs_1.readFileSync)(this.fileLocation, 'utf-8'));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @deprecated use the async version of this method instead
|
|
216
|
+
* provided for the legacy sync set/unset methods */
|
|
217
|
+
saveAliasStoreToFileSync() {
|
|
218
|
+
(0, node_fs_1.writeFileSync)(this.fileLocation, aliasStoreToRawFileContents(this.aliasStore));
|
|
219
|
+
try {
|
|
220
|
+
(0, proper_lockfile_1.unlockSync)(this.fileLocation);
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
// ignore the error. If it wasn't locked, that's what we wanted
|
|
224
|
+
if (errorIsNotAcquired(e))
|
|
225
|
+
return;
|
|
226
|
+
throw e;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
exports.AliasAccessor = AliasAccessor;
|
|
231
|
+
/**
|
|
232
|
+
* Returns the username of given aliasable entity
|
|
233
|
+
*/
|
|
234
|
+
const getNameOf = (entity) => {
|
|
235
|
+
if (typeof entity === 'string')
|
|
236
|
+
return entity;
|
|
237
|
+
const aliaseeName = entity.username ?? entity.user;
|
|
238
|
+
if (!aliaseeName) {
|
|
239
|
+
throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
|
|
240
|
+
}
|
|
241
|
+
return aliaseeName;
|
|
242
|
+
};
|
|
243
|
+
const fileContentsRawToAliasStore = (contents) => {
|
|
244
|
+
const fileContents = JSON.parse(contents);
|
|
245
|
+
return new Map(Object.entries(fileContents[exports.DEFAULT_GROUP]));
|
|
246
|
+
};
|
|
247
|
+
const aliasStoreToRawFileContents = (aliasStore) => JSON.stringify({ [exports.DEFAULT_GROUP]: Object.fromEntries(Array.from(aliasStore.entries())) });
|
|
248
|
+
// exported for testSetup mocking
|
|
249
|
+
const getFileLocation = () => (0, node_path_1.join)((0, node_os_1.homedir)(), global_1.Global.SFDX_STATE_FOLDER, exports.FILENAME);
|
|
250
|
+
exports.getFileLocation = getFileLocation;
|
|
251
|
+
const unlockIfLocked = async (fileLocation) => {
|
|
252
|
+
try {
|
|
253
|
+
await (0, proper_lockfile_1.unlock)(fileLocation);
|
|
254
|
+
}
|
|
255
|
+
catch (e) {
|
|
256
|
+
// ignore the error. If it wasn't locked, that's what we wanted
|
|
257
|
+
if (errorIsNotAcquired(e))
|
|
258
|
+
return;
|
|
259
|
+
throw e;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const errorIsNotAcquired = (e) => e instanceof Error && 'code' in e && e.code === 'ENOTACQUIRED';
|
|
263
|
+
//# sourceMappingURL=aliasAccessor.js.map
|
|
@@ -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
|
+
}
|