@salesforce/core 3.25.0 → 3.26.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/CHANGELOG.md +18 -0
- package/lib/config/config.js +7 -0
- package/lib/exported.d.ts +1 -1
- package/lib/exported.js +2 -4
- package/lib/org/orgConfigProperties.js +5 -0
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +3 -86
- package/lib/stateAggregator/accessors/aliasAccessor.js +1 -117
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +1 -16
- package/lib/stateAggregator/accessors/orgAccessor.js +1 -37
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +0 -39
- package/lib/stateAggregator/accessors/sandboxAccessor.js +1 -55
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +12 -18
- package/lib/stateAggregator/accessors/tokenAccessor.js +2 -30
- package/lib/stateAggregator/index.d.ts +3 -6
- package/lib/stateAggregator/index.js +3 -13
- package/lib/testSetup.js +0 -2
- package/messages/config.md +8 -0
- package/package.json +2 -2
- package/lib/stateAggregator/globalInfoConfig.d.ts +0 -41
- package/lib/stateAggregator/globalInfoConfig.js +0 -113
- package/lib/stateAggregator/sfdxDataHandler.d.ts +0 -59
- package/lib/stateAggregator/sfdxDataHandler.js +0 -328
- package/lib/stateAggregator/types.d.ts +0 -72
- package/lib/stateAggregator/types.js +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.26.1",
|
|
4
4
|
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"types": "lib/exported.d.ts",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"form-data": "^4.0.0",
|
|
49
49
|
"graceful-fs": "^4.2.9",
|
|
50
50
|
"js2xmlparser": "^4.0.1",
|
|
51
|
-
"jsforce": "
|
|
51
|
+
"jsforce": "beta",
|
|
52
52
|
"jsonwebtoken": "8.5.1",
|
|
53
53
|
"ts-retry-promise": "^0.6.0"
|
|
54
54
|
},
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { AnyJson } from '@salesforce/ts-types';
|
|
2
|
-
import { ConfigFile } from '../config/configFile';
|
|
3
|
-
import { ConfigValue } from '../config/configStore';
|
|
4
|
-
import { GlobalInfoOrgAccessor } from './accessors/orgAccessor';
|
|
5
|
-
import { GlobaInfoTokenAccessor } from './accessors/tokenAccessor';
|
|
6
|
-
import { GlobalInfoAliasAccessor } from './accessors/aliasAccessor';
|
|
7
|
-
import { SfInfo } from './types';
|
|
8
|
-
import { GlobalInfoSandboxAccessor } from './accessors/sandboxAccessor';
|
|
9
|
-
export declare function deepCopy<T extends AnyJson>(data: T): T;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated use StateAggregator instead.
|
|
12
|
-
*/
|
|
13
|
-
export declare class GlobalInfo extends ConfigFile<ConfigFile.Options, SfInfo> {
|
|
14
|
-
protected static encryptedKeys: RegExp[];
|
|
15
|
-
private static EMPTY_DATA_MODEL;
|
|
16
|
-
private static instance;
|
|
17
|
-
private sfdxHandler;
|
|
18
|
-
static get emptyDataModel(): SfInfo;
|
|
19
|
-
static getInstance(): Promise<GlobalInfo>;
|
|
20
|
-
/**
|
|
21
|
-
* Clear the cache to force reading from disk.
|
|
22
|
-
*
|
|
23
|
-
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
24
|
-
*/
|
|
25
|
-
static clearInstance(): void;
|
|
26
|
-
static getFileName(): string;
|
|
27
|
-
/**
|
|
28
|
-
* Gets default options for the SfConfig
|
|
29
|
-
*/
|
|
30
|
-
static getDefaultOptions(): ConfigFile.Options;
|
|
31
|
-
get orgs(): GlobalInfoOrgAccessor;
|
|
32
|
-
get tokens(): GlobaInfoTokenAccessor;
|
|
33
|
-
get aliases(): GlobalInfoAliasAccessor;
|
|
34
|
-
get sandboxes(): GlobalInfoSandboxAccessor;
|
|
35
|
-
set(key: string, value: ConfigValue): void;
|
|
36
|
-
write(newContents?: SfInfo): Promise<SfInfo>;
|
|
37
|
-
protected init(): Promise<void>;
|
|
38
|
-
private timestamp;
|
|
39
|
-
private loadSfData;
|
|
40
|
-
private mergeWithSfdxData;
|
|
41
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GlobalInfo = exports.deepCopy = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
-
* All rights reserved.
|
|
7
|
-
* Licensed under the BSD 3-Clause license.
|
|
8
|
-
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
-
*/
|
|
10
|
-
const ts_types_1 = require("@salesforce/ts-types");
|
|
11
|
-
const global_1 = require("../global");
|
|
12
|
-
const configFile_1 = require("../config/configFile");
|
|
13
|
-
const sfdxDataHandler_1 = require("./sfdxDataHandler");
|
|
14
|
-
const orgAccessor_1 = require("./accessors/orgAccessor");
|
|
15
|
-
const tokenAccessor_1 = require("./accessors/tokenAccessor");
|
|
16
|
-
const aliasAccessor_1 = require("./accessors/aliasAccessor");
|
|
17
|
-
const types_1 = require("./types");
|
|
18
|
-
const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
|
|
19
|
-
function deepCopy(data) {
|
|
20
|
-
return JSON.parse(JSON.stringify(data));
|
|
21
|
-
}
|
|
22
|
-
exports.deepCopy = deepCopy;
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated use StateAggregator instead.
|
|
25
|
-
*/
|
|
26
|
-
class GlobalInfo extends configFile_1.ConfigFile {
|
|
27
|
-
constructor() {
|
|
28
|
-
super(...arguments);
|
|
29
|
-
this.sfdxHandler = new sfdxDataHandler_1.SfdxDataHandler();
|
|
30
|
-
}
|
|
31
|
-
static get emptyDataModel() {
|
|
32
|
-
return deepCopy(GlobalInfo.EMPTY_DATA_MODEL);
|
|
33
|
-
}
|
|
34
|
-
static async getInstance() {
|
|
35
|
-
if (!GlobalInfo.instance) {
|
|
36
|
-
GlobalInfo.instance = await GlobalInfo.create();
|
|
37
|
-
}
|
|
38
|
-
return GlobalInfo.instance;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Clear the cache to force reading from disk.
|
|
42
|
-
*
|
|
43
|
-
* *NOTE: Only call this method if you must and you know what you are doing.*
|
|
44
|
-
*/
|
|
45
|
-
static clearInstance() {
|
|
46
|
-
delete GlobalInfo.instance;
|
|
47
|
-
}
|
|
48
|
-
static getFileName() {
|
|
49
|
-
return 'sf.json';
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Gets default options for the SfConfig
|
|
53
|
-
*/
|
|
54
|
-
static getDefaultOptions() {
|
|
55
|
-
return {
|
|
56
|
-
isGlobal: true,
|
|
57
|
-
isState: true,
|
|
58
|
-
filename: GlobalInfo.getFileName(),
|
|
59
|
-
stateFolder: global_1.Global.SF_STATE_FOLDER,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
get orgs() {
|
|
63
|
-
return new orgAccessor_1.GlobalInfoOrgAccessor(this);
|
|
64
|
-
}
|
|
65
|
-
get tokens() {
|
|
66
|
-
return new tokenAccessor_1.GlobaInfoTokenAccessor(this);
|
|
67
|
-
}
|
|
68
|
-
get aliases() {
|
|
69
|
-
return new aliasAccessor_1.GlobalInfoAliasAccessor(this);
|
|
70
|
-
}
|
|
71
|
-
get sandboxes() {
|
|
72
|
-
return new sandboxAccessor_1.GlobalInfoSandboxAccessor(this);
|
|
73
|
-
}
|
|
74
|
-
set(key, value) {
|
|
75
|
-
if ((0, ts_types_1.isPlainObject)(value)) {
|
|
76
|
-
value = this.timestamp(value);
|
|
77
|
-
}
|
|
78
|
-
super.set(key, value);
|
|
79
|
-
}
|
|
80
|
-
async write(newContents) {
|
|
81
|
-
const result = await super.write(newContents);
|
|
82
|
-
if (global_1.Global.SFDX_INTEROPERABILITY)
|
|
83
|
-
await this.sfdxHandler.write(result);
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
async init() {
|
|
87
|
-
await this.initCrypto();
|
|
88
|
-
const contents = global_1.Global.SFDX_INTEROPERABILITY ? await this.mergeWithSfdxData() : await this.loadSfData();
|
|
89
|
-
this.setContents(contents);
|
|
90
|
-
}
|
|
91
|
-
timestamp(data) {
|
|
92
|
-
return { ...data, timestamp: new Date() };
|
|
93
|
-
}
|
|
94
|
-
async loadSfData() {
|
|
95
|
-
const data = await this.read();
|
|
96
|
-
return { ...GlobalInfo.emptyDataModel, ...data };
|
|
97
|
-
}
|
|
98
|
-
async mergeWithSfdxData() {
|
|
99
|
-
const sfData = await this.loadSfData();
|
|
100
|
-
const merged = await this.sfdxHandler.merge(sfData);
|
|
101
|
-
await this.write(merged);
|
|
102
|
-
return merged;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.GlobalInfo = GlobalInfo;
|
|
106
|
-
GlobalInfo.encryptedKeys = [/token/i, /password/i, /secret/i];
|
|
107
|
-
GlobalInfo.EMPTY_DATA_MODEL = {
|
|
108
|
-
[types_1.SfInfoKeys.ORGS]: {},
|
|
109
|
-
[types_1.SfInfoKeys.TOKENS]: {},
|
|
110
|
-
[types_1.SfInfoKeys.ALIASES]: {},
|
|
111
|
-
[types_1.SfInfoKeys.SANDBOXES]: {},
|
|
112
|
-
};
|
|
113
|
-
//# sourceMappingURL=globalInfoConfig.js.map
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ConfigFile } from '../config/configFile';
|
|
2
|
-
import { SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfSandbox } from './types';
|
|
3
|
-
interface Handler<T extends SfInfoKeys> {
|
|
4
|
-
sfKey: T;
|
|
5
|
-
merge: (sfData: SfInfo) => Promise<Partial<SfInfo>>;
|
|
6
|
-
migrate: () => Promise<Pick<SfInfo, T>>;
|
|
7
|
-
write: (latest: SfInfo, original: SfInfo) => Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
interface Changes<T> {
|
|
10
|
-
changed: T;
|
|
11
|
-
deleted: string[];
|
|
12
|
-
}
|
|
13
|
-
export declare class SfdxDataHandler {
|
|
14
|
-
handlers: (AuthHandler | AliasesHandler | SandboxesHandler | TokensHandler)[];
|
|
15
|
-
private original;
|
|
16
|
-
write(latest?: SfInfo): Promise<void>;
|
|
17
|
-
merge(sfData?: SfInfo): Promise<SfInfo>;
|
|
18
|
-
private setOriginal;
|
|
19
|
-
}
|
|
20
|
-
declare abstract class BaseHandler<T extends SfInfoKeys> implements Handler<T> {
|
|
21
|
-
abstract sfKey: T;
|
|
22
|
-
merge(sfData?: SfInfo): Promise<Partial<SfInfo>>;
|
|
23
|
-
abstract migrate(): Promise<Pick<SfInfo, T>>;
|
|
24
|
-
abstract write(latest: SfInfo, original: SfInfo): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
export declare class AuthHandler extends BaseHandler<SfInfoKeys.ORGS> {
|
|
27
|
-
private static authFilenameFilterRegEx;
|
|
28
|
-
sfKey: typeof SfInfoKeys.ORGS;
|
|
29
|
-
migrate(): Promise<Pick<SfInfo, SfInfoKeys.ORGS>>;
|
|
30
|
-
write(latest: SfInfo, original: SfInfo): Promise<void>;
|
|
31
|
-
findChanges(latest: SfInfo, original: SfInfo): Promise<Changes<SfOrgs>>;
|
|
32
|
-
createAuthFileConfig(username: string): Promise<ConfigFile<ConfigFile.Options>>;
|
|
33
|
-
listAllAuthFiles(): Promise<string[]>;
|
|
34
|
-
listAllAuthorizations(): Promise<SfOrg[]>;
|
|
35
|
-
}
|
|
36
|
-
export declare class AliasesHandler extends BaseHandler<SfInfoKeys.ALIASES> {
|
|
37
|
-
private static SFDX_ALIASES_FILENAME;
|
|
38
|
-
sfKey: typeof SfInfoKeys.ALIASES;
|
|
39
|
-
migrate(): Promise<Pick<SfInfo, SfInfoKeys.ALIASES>>;
|
|
40
|
-
merge(sfData?: SfInfo): Promise<Partial<SfInfo>>;
|
|
41
|
-
write(latest: SfInfo): Promise<void>;
|
|
42
|
-
}
|
|
43
|
-
export declare class SandboxesHandler extends BaseHandler<SfInfoKeys.SANDBOXES> {
|
|
44
|
-
private static sandboxFilenameFilterRegEx;
|
|
45
|
-
sfKey: typeof SfInfoKeys.SANDBOXES;
|
|
46
|
-
merge(sfData?: SfInfo): Promise<Partial<SfInfo>>;
|
|
47
|
-
migrate(): Promise<Pick<SfInfo, SfInfoKeys.SANDBOXES>>;
|
|
48
|
-
write(latest: SfInfo, original: SfInfo): Promise<void>;
|
|
49
|
-
listAllSandboxFiles(): Promise<string[]>;
|
|
50
|
-
listAllSandboxes(): Promise<SfSandbox[]>;
|
|
51
|
-
private findChanges;
|
|
52
|
-
}
|
|
53
|
-
export declare class TokensHandler extends BaseHandler<SfInfoKeys.TOKENS> {
|
|
54
|
-
private static SFDX_TOKENS_FILENAME;
|
|
55
|
-
sfKey: typeof SfInfoKeys.TOKENS;
|
|
56
|
-
migrate(): Promise<Pick<SfInfo, SfInfoKeys.TOKENS>>;
|
|
57
|
-
write(latest: SfInfo): Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
export {};
|
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2020, 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.TokensHandler = exports.SandboxesHandler = exports.AliasesHandler = exports.AuthHandler = exports.SfdxDataHandler = void 0;
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const fs = require("fs");
|
|
12
|
-
const kit_1 = require("@salesforce/kit");
|
|
13
|
-
const ts_types_1 = require("@salesforce/ts-types");
|
|
14
|
-
const global_1 = require("../global");
|
|
15
|
-
const configFile_1 = require("../config/configFile");
|
|
16
|
-
const sandboxOrgConfig_1 = require("../config/sandboxOrgConfig");
|
|
17
|
-
const globalInfoConfig_1 = require("./globalInfoConfig");
|
|
18
|
-
const types_1 = require("./types");
|
|
19
|
-
function isEqual(object1, object2) {
|
|
20
|
-
const keys1 = Object.keys(object1).filter((k) => k !== 'timestamp');
|
|
21
|
-
const keys2 = Object.keys(object2).filter((k) => k !== 'timestamp');
|
|
22
|
-
if (keys1.length !== keys2.length)
|
|
23
|
-
return false;
|
|
24
|
-
for (const key of keys1) {
|
|
25
|
-
if (object1[key] !== object2[key])
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
class SfdxDataHandler {
|
|
31
|
-
constructor() {
|
|
32
|
-
this.handlers = [new AuthHandler(), new AliasesHandler(), new SandboxesHandler(), new TokensHandler()];
|
|
33
|
-
}
|
|
34
|
-
async write(latest = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
|
|
35
|
-
await Promise.all(this.handlers.map((handler) => handler.write(latest, this.original)));
|
|
36
|
-
this.setOriginal(latest);
|
|
37
|
-
}
|
|
38
|
-
async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
|
|
39
|
-
let merged = (0, globalInfoConfig_1.deepCopy)(sfData);
|
|
40
|
-
for (const handler of this.handlers) {
|
|
41
|
-
merged = Object.assign(merged, await handler.merge(merged));
|
|
42
|
-
}
|
|
43
|
-
this.setOriginal(merged);
|
|
44
|
-
return merged;
|
|
45
|
-
}
|
|
46
|
-
setOriginal(data) {
|
|
47
|
-
this.original = (0, globalInfoConfig_1.deepCopy)(data);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.SfdxDataHandler = SfdxDataHandler;
|
|
51
|
-
class BaseHandler {
|
|
52
|
-
async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
|
|
53
|
-
const sfdxData = await this.migrate();
|
|
54
|
-
const merged = (0, globalInfoConfig_1.deepCopy)(sfData);
|
|
55
|
-
// Only merge the key this handler is responsible for.
|
|
56
|
-
const key = this.sfKey;
|
|
57
|
-
const sfKeys = Object.keys(sfData[key] ?? {});
|
|
58
|
-
const sfdxKeys = Object.keys(sfdxData[key] ?? {});
|
|
59
|
-
const commonKeys = sfKeys.filter((k) => sfdxKeys.includes(k));
|
|
60
|
-
for (const k of commonKeys) {
|
|
61
|
-
const [newer, older] = [sfData[key][k], sfdxData[key][k]].sort((a, b) => {
|
|
62
|
-
if ((0, ts_types_1.isPlainObject)(a) && (0, ts_types_1.isPlainObject)(b))
|
|
63
|
-
return new Date(a.timestamp) < new Date(b.timestamp) ? 1 : -1;
|
|
64
|
-
return 0;
|
|
65
|
-
});
|
|
66
|
-
(0, kit_1.set)(merged, `${key}["${k}"]`, Object.assign({}, older, newer));
|
|
67
|
-
}
|
|
68
|
-
// Keys that exist in .sfdx but not .sf are added because we assume
|
|
69
|
-
// that this means the key was created using sfdx.
|
|
70
|
-
// However, this is not always a valid assumption because it could
|
|
71
|
-
// also mean that the key was deleted using sf, in which case we
|
|
72
|
-
// do not want to migrate the sfdx key to sf.
|
|
73
|
-
// Programmatically differentiating between a new key and a deleted key
|
|
74
|
-
// would be nearly impossible. Instead, we should ensure that whenever
|
|
75
|
-
// sf deletes a key it also deletes it in sfdx. This way, we can safely
|
|
76
|
-
// assume that we should migrate any keys that exist in in .sfdx
|
|
77
|
-
const unhandledSfdxKeys = sfdxKeys.filter((k) => !sfKeys.includes(k));
|
|
78
|
-
for (const k of unhandledSfdxKeys) {
|
|
79
|
-
(0, kit_1.set)(merged, `${key}["${k}"]`, sfdxData[key][k]);
|
|
80
|
-
}
|
|
81
|
-
// Keys that exist in .sf but not .sfdx are deleted because we assume
|
|
82
|
-
// that this means the key was deleted while using sfdx.
|
|
83
|
-
// We can make this assumption because keys that are created by sf will
|
|
84
|
-
// always be migrated back to sfdx
|
|
85
|
-
const unhandledSfKeys = sfKeys.filter((k) => !sfdxKeys.includes(k));
|
|
86
|
-
for (const k of unhandledSfKeys) {
|
|
87
|
-
delete merged[key][k];
|
|
88
|
-
}
|
|
89
|
-
return merged;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
class AuthHandler extends BaseHandler {
|
|
93
|
-
constructor() {
|
|
94
|
-
super(...arguments);
|
|
95
|
-
this.sfKey = types_1.SfInfoKeys.ORGS;
|
|
96
|
-
}
|
|
97
|
-
async migrate() {
|
|
98
|
-
const oldAuths = await this.listAllAuthorizations();
|
|
99
|
-
const newAuths = oldAuths.reduce((x, y) => Object.assign(x, { [(0, ts_types_1.ensureString)(y.username)]: y }), {});
|
|
100
|
-
return { [this.sfKey]: newAuths };
|
|
101
|
-
}
|
|
102
|
-
async write(latest, original) {
|
|
103
|
-
const { changed, deleted } = await this.findChanges(latest, original);
|
|
104
|
-
await Promise.all(Object.entries(changed)
|
|
105
|
-
.filter(([, authData]) => authData)
|
|
106
|
-
.map(async ([username, authData]) => {
|
|
107
|
-
const config = await this.createAuthFileConfig(username);
|
|
108
|
-
config.setContentsFromObject(authData);
|
|
109
|
-
return config.write();
|
|
110
|
-
}));
|
|
111
|
-
await Promise.all(deleted.map(async (username) => {
|
|
112
|
-
const config = await this.createAuthFileConfig(username);
|
|
113
|
-
return config.unlink();
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
async findChanges(latest, original) {
|
|
117
|
-
const latestAuths = latest.orgs;
|
|
118
|
-
const originalAuths = original.orgs;
|
|
119
|
-
const changed = {};
|
|
120
|
-
for (const [username, auth] of Object.entries(latestAuths)) {
|
|
121
|
-
const originalAuth = originalAuths[username] ?? {};
|
|
122
|
-
if (!isEqual(auth, originalAuth)) {
|
|
123
|
-
changed[username] = auth;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const deleted = Object.keys(originalAuths).filter((username) => !latestAuths[username]);
|
|
127
|
-
return { changed, deleted };
|
|
128
|
-
}
|
|
129
|
-
async createAuthFileConfig(username) {
|
|
130
|
-
const config = await configFile_1.ConfigFile.create({
|
|
131
|
-
filename: `${username}.json`,
|
|
132
|
-
isGlobal: true,
|
|
133
|
-
isState: true,
|
|
134
|
-
stateFolder: global_1.Global.SFDX_STATE_FOLDER,
|
|
135
|
-
throwOnNotFound: false,
|
|
136
|
-
encryptedKeys: ['accessToken', 'refreshToken', 'password', 'clientSecret'],
|
|
137
|
-
});
|
|
138
|
-
return config;
|
|
139
|
-
}
|
|
140
|
-
async listAllAuthFiles() {
|
|
141
|
-
const globalFiles = await fs.promises.readdir(global_1.Global.SFDX_DIR);
|
|
142
|
-
return globalFiles.filter((file) => file.match(AuthHandler.authFilenameFilterRegEx));
|
|
143
|
-
}
|
|
144
|
-
async listAllAuthorizations() {
|
|
145
|
-
const filenames = await this.listAllAuthFiles();
|
|
146
|
-
return Promise.all(filenames
|
|
147
|
-
.map((f) => (0, path_1.basename)(f, (0, path_1.extname)(f)))
|
|
148
|
-
.map(async (username) => {
|
|
149
|
-
const configFile = await this.createAuthFileConfig(username);
|
|
150
|
-
const contents = configFile.getContents();
|
|
151
|
-
const stat = await configFile.stat();
|
|
152
|
-
return { ...contents, timestamp: stat.mtime.toISOString() };
|
|
153
|
-
}));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.AuthHandler = AuthHandler;
|
|
157
|
-
// The regular expression that filters files stored in $HOME/.sfdx
|
|
158
|
-
AuthHandler.authFilenameFilterRegEx = /^[^.][^@]*@[^.]+(\.[^.\s]+)+\.json$/;
|
|
159
|
-
class AliasesHandler extends BaseHandler {
|
|
160
|
-
constructor() {
|
|
161
|
-
super(...arguments);
|
|
162
|
-
this.sfKey = types_1.SfInfoKeys.ALIASES;
|
|
163
|
-
}
|
|
164
|
-
async migrate() {
|
|
165
|
-
const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
|
|
166
|
-
try {
|
|
167
|
-
const x = await fs.promises.readFile(aliasesFilePath, 'utf8');
|
|
168
|
-
const sfdxAliases = (0, kit_1.parseJson)(x).orgs;
|
|
169
|
-
return { [this.sfKey]: { ...sfdxAliases } };
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
return { [this.sfKey]: {} };
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// AliasesHandler implements its own merge method because the structure of aliases is flat instead of nested by SfInfoKey types.
|
|
176
|
-
async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
|
|
177
|
-
const sfdxAliases = (await this.migrate())[types_1.SfInfoKeys.ALIASES];
|
|
178
|
-
const merged = (0, globalInfoConfig_1.deepCopy)(sfData);
|
|
179
|
-
/* Overwrite `sf` aliases with `sfdx` aliases
|
|
180
|
-
* `sf` will always modify `sfdx` files but `sfdx` won't modify `sf` files
|
|
181
|
-
* because of this we can assume that any changes in `sfdx` files that aren't
|
|
182
|
-
* in `sf` are the latest data
|
|
183
|
-
*
|
|
184
|
-
* This breaks down if a user of `sf` manually modifies the `~/.sf/sf.json` file
|
|
185
|
-
* but we don't support that use case out-of-the-box (yet?)
|
|
186
|
-
*
|
|
187
|
-
* Note: See also the explanation on the merge method in the BaseHandler class
|
|
188
|
-
*/
|
|
189
|
-
Object.keys(sfdxAliases).forEach((alias) => {
|
|
190
|
-
merged[types_1.SfInfoKeys.ALIASES][alias] = sfdxAliases[alias];
|
|
191
|
-
});
|
|
192
|
-
/* Delete any aliases that don't exist in sfdx config files
|
|
193
|
-
* Aliases that exist in .sf but not .sfdx are deleted because we assume
|
|
194
|
-
* that this means the alias was deleted while using sfdx. We can make
|
|
195
|
-
* this assumption because keys that are created by sf will always be
|
|
196
|
-
* migrated back to sfdx.
|
|
197
|
-
*
|
|
198
|
-
* Note: See also the explanation on the merge method in the BaseHandler class
|
|
199
|
-
*/
|
|
200
|
-
for (const alias in merged[types_1.SfInfoKeys.ALIASES]) {
|
|
201
|
-
if (!sfdxAliases[alias])
|
|
202
|
-
delete merged[types_1.SfInfoKeys.ALIASES][alias];
|
|
203
|
-
}
|
|
204
|
-
return merged;
|
|
205
|
-
}
|
|
206
|
-
async write(latest) {
|
|
207
|
-
const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
|
|
208
|
-
await fs.promises.writeFile(aliasesFilePath, JSON.stringify({ orgs: latest[types_1.SfInfoKeys.ALIASES] }, null, 2));
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
exports.AliasesHandler = AliasesHandler;
|
|
212
|
-
AliasesHandler.SFDX_ALIASES_FILENAME = 'alias.json';
|
|
213
|
-
class SandboxesHandler extends BaseHandler {
|
|
214
|
-
constructor() {
|
|
215
|
-
super(...arguments);
|
|
216
|
-
this.sfKey = types_1.SfInfoKeys.SANDBOXES;
|
|
217
|
-
}
|
|
218
|
-
async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
|
|
219
|
-
const sfdxData = await this.migrate();
|
|
220
|
-
const merged = (0, globalInfoConfig_1.deepCopy)(sfData);
|
|
221
|
-
// Only merge the key this handler is responsible for.
|
|
222
|
-
const key = this.sfKey;
|
|
223
|
-
const sfKeys = Object.keys(sfData[key] ?? {});
|
|
224
|
-
const sfdxKeys = Object.keys(sfdxData[key] ?? {});
|
|
225
|
-
// sandbox entries for .sf and .sfdx contain static data. Given there
|
|
226
|
-
// can be no mutation during the life of the sandbox, having to merge common keys
|
|
227
|
-
// is unnecessary.
|
|
228
|
-
// Keys that exist in .sfdx but not .sf are added because we assume
|
|
229
|
-
// that this means the key was created using sfdx.
|
|
230
|
-
// However, this is not always a valid assumption because it could
|
|
231
|
-
// also mean that the key was deleted using sf, in which case we
|
|
232
|
-
// do not want to migrate the sfdx key to sf.
|
|
233
|
-
// Programmatically differentiating between a new key and a deleted key
|
|
234
|
-
// would be nearly impossible. Instead, we should ensure that whenever
|
|
235
|
-
// sf deletes a key it also deletes it in sfdx. This way, we can safely
|
|
236
|
-
// assume that we should migrate any keys that exist in .sfdx
|
|
237
|
-
const unhandledSfdxKeys = sfdxKeys.filter((k) => !sfKeys.includes(k));
|
|
238
|
-
for (const k of unhandledSfdxKeys) {
|
|
239
|
-
(0, kit_1.set)(merged, `${key}["${k}"]`, sfdxData[key][k]);
|
|
240
|
-
}
|
|
241
|
-
// Keys that exist in .sf but not .sfdx are deleted because we assume
|
|
242
|
-
// that this means the key was deleted while using sfdx.
|
|
243
|
-
// We can make this assumption because keys that are created by sf will
|
|
244
|
-
// always be migrated back to sfdx
|
|
245
|
-
const unhandledSfKeys = sfKeys.filter((k) => !sfdxKeys.includes(k));
|
|
246
|
-
for (const k of unhandledSfKeys) {
|
|
247
|
-
delete merged[key][k];
|
|
248
|
-
}
|
|
249
|
-
return merged;
|
|
250
|
-
}
|
|
251
|
-
async migrate() {
|
|
252
|
-
const oldSandboxes = await this.listAllSandboxes();
|
|
253
|
-
const newSandboxes = Object.fromEntries(oldSandboxes.map((old) => [old.sandboxOrgId, old]));
|
|
254
|
-
return { [this.sfKey]: newSandboxes };
|
|
255
|
-
}
|
|
256
|
-
async write(latest, original) {
|
|
257
|
-
const { changed, deleted } = await this.findChanges(latest, original);
|
|
258
|
-
for (const sandboxData of Object.values(changed)) {
|
|
259
|
-
if (sandboxData) {
|
|
260
|
-
const orgId = sandboxData.sandboxOrgId;
|
|
261
|
-
const sandboxConfig = new sandboxOrgConfig_1.SandboxOrgConfig(sandboxOrgConfig_1.SandboxOrgConfig.getOptions(orgId));
|
|
262
|
-
sandboxConfig.set(sandboxOrgConfig_1.SandboxOrgConfig.Fields.PROD_ORG_USERNAME, sandboxData.prodOrgUsername);
|
|
263
|
-
await sandboxConfig.write();
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
for (const username of deleted) {
|
|
267
|
-
const originalSandbox = original.sandboxes[username];
|
|
268
|
-
const orgId = originalSandbox.sandboxOrgId;
|
|
269
|
-
const sandboxConfig = new sandboxOrgConfig_1.SandboxOrgConfig(sandboxOrgConfig_1.SandboxOrgConfig.getOptions(orgId));
|
|
270
|
-
await sandboxConfig.unlink();
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
async listAllSandboxFiles() {
|
|
274
|
-
const globalFiles = await fs.promises.readdir(global_1.Global.SFDX_DIR);
|
|
275
|
-
return globalFiles.filter((file) => file.match(SandboxesHandler.sandboxFilenameFilterRegEx));
|
|
276
|
-
}
|
|
277
|
-
async listAllSandboxes() {
|
|
278
|
-
return Promise.all((await this.listAllSandboxFiles()).map(async (filename) => {
|
|
279
|
-
const matches = filename.match(SandboxesHandler.sandboxFilenameFilterRegEx);
|
|
280
|
-
const orgId = matches ? matches[1] : '';
|
|
281
|
-
const sandboxConfig = new sandboxOrgConfig_1.SandboxOrgConfig(sandboxOrgConfig_1.SandboxOrgConfig.getOptions(orgId));
|
|
282
|
-
const stat = await sandboxConfig.stat();
|
|
283
|
-
const contents = { ...(await sandboxConfig.read(true)), sandboxOrgId: orgId };
|
|
284
|
-
const sandbox = Object.assign(contents, { timestamp: stat.mtime.toISOString() });
|
|
285
|
-
return sandbox;
|
|
286
|
-
}));
|
|
287
|
-
}
|
|
288
|
-
async findChanges(latest, original) {
|
|
289
|
-
const latestSandboxes = latest.sandboxes;
|
|
290
|
-
const originalSandboxes = original.sandboxes;
|
|
291
|
-
const changed = {};
|
|
292
|
-
for (const [sandboxOrgId, sandbox] of Object.entries(latestSandboxes)) {
|
|
293
|
-
const originalSandbox = originalSandboxes[sandboxOrgId] ?? {};
|
|
294
|
-
if (!isEqual(sandbox, originalSandbox)) {
|
|
295
|
-
changed[sandboxOrgId] = sandbox;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
const deleted = Object.keys(originalSandboxes).filter((sandboxOrgId) => !latestSandboxes[sandboxOrgId]);
|
|
299
|
-
return { changed, deleted };
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
exports.SandboxesHandler = SandboxesHandler;
|
|
303
|
-
// The regular expression that filters files stored in $HOME/.sfdx
|
|
304
|
-
SandboxesHandler.sandboxFilenameFilterRegEx = /^(00D.*?)\.sandbox\.json$/;
|
|
305
|
-
class TokensHandler extends BaseHandler {
|
|
306
|
-
constructor() {
|
|
307
|
-
super(...arguments);
|
|
308
|
-
this.sfKey = types_1.SfInfoKeys.TOKENS;
|
|
309
|
-
}
|
|
310
|
-
async migrate() {
|
|
311
|
-
const filePath = (0, path_1.join)(global_1.Global.SFDX_DIR, TokensHandler.SFDX_TOKENS_FILENAME);
|
|
312
|
-
try {
|
|
313
|
-
const x = await fs.promises.readFile(filePath, 'utf8');
|
|
314
|
-
const tokens = (0, kit_1.parseJson)(x);
|
|
315
|
-
return { [this.sfKey]: tokens };
|
|
316
|
-
}
|
|
317
|
-
catch (e) {
|
|
318
|
-
return { [this.sfKey]: {} };
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
async write(latest) {
|
|
322
|
-
const filePath = (0, path_1.join)(global_1.Global.SFDX_DIR, TokensHandler.SFDX_TOKENS_FILENAME);
|
|
323
|
-
await fs.promises.writeFile(filePath, JSON.stringify(latest[types_1.SfInfoKeys.TOKENS], null, 2));
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
exports.TokensHandler = TokensHandler;
|
|
327
|
-
TokensHandler.SFDX_TOKENS_FILENAME = 'tokens.json';
|
|
328
|
-
//# sourceMappingURL=sfdxDataHandler.js.map
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { JsonMap } from '@salesforce/ts-types';
|
|
2
|
-
import { AuthFields } from '../org';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated
|
|
5
|
-
*/
|
|
6
|
-
export declare enum SfInfoKeys {
|
|
7
|
-
ORGS = "orgs",
|
|
8
|
-
TOKENS = "tokens",
|
|
9
|
-
ALIASES = "aliases",
|
|
10
|
-
SANDBOXES = "sandboxes"
|
|
11
|
-
}
|
|
12
|
-
export declare type Timestamp = {
|
|
13
|
-
timestamp: string;
|
|
14
|
-
};
|
|
15
|
-
export declare type SfEntry = JsonMap;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated
|
|
18
|
-
*/
|
|
19
|
-
export declare type SfOrg = AuthFields & SfEntry;
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated
|
|
22
|
-
*/
|
|
23
|
-
export interface SfOrgs {
|
|
24
|
-
[key: string]: SfOrg & Timestamp;
|
|
25
|
-
}
|
|
26
|
-
export declare type SfToken = {
|
|
27
|
-
token: string;
|
|
28
|
-
url: string;
|
|
29
|
-
user?: string;
|
|
30
|
-
} & SfEntry;
|
|
31
|
-
/**
|
|
32
|
-
*/
|
|
33
|
-
export declare type SfTokens = {
|
|
34
|
-
[key: string]: SfToken & Timestamp;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* The key will always be the alias and the value will always be the username, e.g.
|
|
38
|
-
* { "MyAlias": "user@salesforce.com" }
|
|
39
|
-
*/
|
|
40
|
-
export declare type SfAliases = {
|
|
41
|
-
[alias: string]: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated
|
|
45
|
-
*/
|
|
46
|
-
export declare type SfSandbox = {
|
|
47
|
-
sandboxOrgId: string;
|
|
48
|
-
prodOrgUsername: string;
|
|
49
|
-
sandboxName?: string;
|
|
50
|
-
sandboxUsername?: string;
|
|
51
|
-
sandboxProcessId?: string;
|
|
52
|
-
sandboxInfoId?: string;
|
|
53
|
-
} & Timestamp & SfEntry;
|
|
54
|
-
/**
|
|
55
|
-
* The key will always be the sandbox username and the value will always be the
|
|
56
|
-
* production org username
|
|
57
|
-
* { "user@salesforce.com.mysandbox": "user@salesforce.com" }
|
|
58
|
-
*
|
|
59
|
-
* @deprecated
|
|
60
|
-
*/
|
|
61
|
-
export interface SfSandboxes {
|
|
62
|
-
[sandboxOrgId: string]: SfSandbox;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @deprecated
|
|
66
|
-
*/
|
|
67
|
-
export declare type SfInfo = {
|
|
68
|
-
[SfInfoKeys.ORGS]: SfOrgs;
|
|
69
|
-
[SfInfoKeys.TOKENS]: SfTokens;
|
|
70
|
-
[SfInfoKeys.ALIASES]: SfAliases;
|
|
71
|
-
[SfInfoKeys.SANDBOXES]: SfSandboxes;
|
|
72
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SfInfoKeys = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated
|
|
6
|
-
*/
|
|
7
|
-
var SfInfoKeys;
|
|
8
|
-
(function (SfInfoKeys) {
|
|
9
|
-
SfInfoKeys["ORGS"] = "orgs";
|
|
10
|
-
SfInfoKeys["TOKENS"] = "tokens";
|
|
11
|
-
SfInfoKeys["ALIASES"] = "aliases";
|
|
12
|
-
SfInfoKeys["SANDBOXES"] = "sandboxes";
|
|
13
|
-
})(SfInfoKeys = exports.SfInfoKeys || (exports.SfInfoKeys = {}));
|
|
14
|
-
//# sourceMappingURL=types.js.map
|