@pdfbutler/migration-cli 0.0.26 → 0.0.27
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/lib/commands/butler/pb/admincredentials.d.ts +0 -5
- package/lib/commands/butler/pb/admincredentials.js +10 -79
- package/lib/commands/butler/pb/admincredentials.js.map +1 -1
- package/lib/commands/butler/pb/adminsettings.d.ts +0 -5
- package/lib/commands/butler/pb/adminsettings.js +10 -79
- package/lib/commands/butler/pb/adminsettings.js.map +1 -1
- package/lib/commands/butler/pb/export.d.ts +0 -5
- package/lib/commands/butler/pb/export.js +31 -139
- package/lib/commands/butler/pb/export.js.map +1 -1
- package/lib/commands/butler/pb/exportpack.d.ts +0 -5
- package/lib/commands/butler/pb/exportpack.js +22 -101
- package/lib/commands/butler/pb/exportpack.js.map +1 -1
- package/lib/commands/butler/pb/import.d.ts +0 -7
- package/lib/commands/butler/pb/import.js +32 -131
- package/lib/commands/butler/pb/import.js.map +1 -1
- package/lib/commands/butler/pb/importpack.d.ts +0 -5
- package/lib/commands/butler/pb/importpack.js +20 -101
- package/lib/commands/butler/pb/importpack.js.map +1 -1
- package/lib/utils/authentication.d.ts +2 -0
- package/lib/utils/authentication.js +73 -0
- package/lib/utils/authentication.js.map +1 -0
- package/lib/utils/constants.d.ts +101 -0
- package/lib/utils/constants.js +105 -0
- package/lib/utils/constants.js.map +1 -0
- package/lib/utils/logger.d.ts +8 -0
- package/lib/utils/logger.js +43 -0
- package/lib/utils/logger.js.map +1 -0
- package/oclif.manifest.json +1 -7
- package/package.json +1 -1
|
@@ -15,10 +15,5 @@ export default class ButlerPbAdmincredentials extends SfCommand<ButlerPbAdmincre
|
|
|
15
15
|
session: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
16
|
instance: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
17
|
};
|
|
18
|
-
private static log;
|
|
19
|
-
private static isBlank;
|
|
20
|
-
private static authenticateWithTarget;
|
|
21
|
-
private static authenticateWitsSession;
|
|
22
|
-
private static authenticate;
|
|
23
18
|
run(): Promise<ButlerPbAdmincredentialsResult>;
|
|
24
19
|
}
|
|
@@ -16,81 +16,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
/* eslint-disable no-console */
|
|
17
17
|
const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
|
|
18
18
|
const core_1 = require("@salesforce/core");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const ERROR_VERSION = 'Verify that you have PDFButler version greater than v1.440.';
|
|
23
|
-
const MSG_CONNECTION_FAILED = 'Connection to Salesforce has been failed.';
|
|
24
|
-
const MSG_CREATION_CONNECTION = 'Creating Connection with the Salesforce org.';
|
|
25
|
-
const MSG_AUTHORIZATION = 'Authorization with the username: [VALUE].';
|
|
26
|
-
const MSG_NO_AUTH_PARAMS = 'No authentication parameters provided. Please provide either username or session and instance parameters.';
|
|
27
|
-
const MSG_RUN_AUTH_COMMAND = 'Run the command "sf org login web" before authenticating with the target.';
|
|
28
|
-
const MSG_CHECK_SESSION_INSTANCE = 'Check if the session is up to date and if the instance is correct.';
|
|
19
|
+
const logger_1 = require("../../../utils/logger");
|
|
20
|
+
const constants_1 = require("../../../utils/constants");
|
|
21
|
+
const authentication_1 = require("../../../utils/authentication");
|
|
29
22
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
30
23
|
const messages = core_1.Messages.loadMessages('@pdfbutler/migration-cli', 'butler.pb.admincredentials');
|
|
31
24
|
class ButlerPbAdmincredentials extends sf_plugins_core_1.SfCommand {
|
|
32
|
-
static log(message, type = 'info') {
|
|
33
|
-
const prefix = type === 'info' ? '[INFO]' : '[ERROR]';
|
|
34
|
-
console.log(`${prefix} ${message}`);
|
|
35
|
-
}
|
|
36
|
-
static isBlank(value) {
|
|
37
|
-
return value?.trim() === ''
|
|
38
|
-
|| value === null
|
|
39
|
-
|| value === undefined;
|
|
40
|
-
}
|
|
41
|
-
static async authenticateWithTarget(username) {
|
|
42
|
-
try {
|
|
43
|
-
this.log(MSG_AUTHORIZATION.replace('[VALUE]', username));
|
|
44
|
-
const authInfo = await core_1.AuthInfo.create({ username });
|
|
45
|
-
this.log(MSG_CREATION_CONNECTION);
|
|
46
|
-
const connection = await core_1.Connection.create({ authInfo });
|
|
47
|
-
this.log(`Connected to ${username} (Org ID: ${authInfo.getFields().orgId})`);
|
|
48
|
-
return connection;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
this.log(MSG_RUN_AUTH_COMMAND, 'error');
|
|
52
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
static async authenticateWitsSession(session, instance) {
|
|
56
|
-
if (!this.isBlank(instance) && !this.isBlank(session)) {
|
|
57
|
-
const connection = await new jsforce.Connection({
|
|
58
|
-
instanceUrl: `${instance}`,
|
|
59
|
-
sessionId: `${session}`,
|
|
60
|
-
});
|
|
61
|
-
this.log(`Connected to ${connection.instanceUrl}`);
|
|
62
|
-
return connection;
|
|
63
|
-
}
|
|
64
|
-
else if (!this.isBlank(session) && this.isBlank(instance)) {
|
|
65
|
-
this.log('Instance URL (--instance) cannot be empty', 'error');
|
|
66
|
-
}
|
|
67
|
-
else if (this.isBlank(session) && !this.isBlank(instance)) {
|
|
68
|
-
this.log('Session Id (--session) cannot be empty', 'error');
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this.log('Session Id and Instance URL (--session and --instance) cannot be empty', 'error');
|
|
72
|
-
}
|
|
73
|
-
this.log(MSG_CHECK_SESSION_INSTANCE, 'error');
|
|
74
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
75
|
-
}
|
|
76
|
-
static async authenticate(username, session, instance) {
|
|
77
|
-
let connection;
|
|
78
|
-
if (this.isBlank(username) && (this.isBlank(session) || this.isBlank(instance))) {
|
|
79
|
-
throw new Error(MSG_NO_AUTH_PARAMS);
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
if (this.isBlank(session) || this.isBlank(instance)) {
|
|
83
|
-
connection = await this.authenticateWithTarget(username);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
connection = await this.authenticateWitsSession(session, instance);
|
|
87
|
-
}
|
|
88
|
-
return connection;
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
25
|
async run() {
|
|
95
26
|
const { flags } = await this.parse(ButlerPbAdmincredentials);
|
|
96
27
|
const targetUsername = flags.target;
|
|
@@ -102,19 +33,19 @@ class ButlerPbAdmincredentials extends sf_plugins_core_1.SfCommand {
|
|
|
102
33
|
userPassword: flags['user-password'],
|
|
103
34
|
};
|
|
104
35
|
try {
|
|
105
|
-
const connection = await
|
|
106
|
-
|
|
107
|
-
await connection.apex.put(
|
|
108
|
-
|
|
36
|
+
const connection = await (0, authentication_1.authenticate)(targetUsername, session, instance);
|
|
37
|
+
logger_1.Logger.info(constants_1.MESSAGE.SENDING_TO_ENDPOINT.replace('[URL]', JSON.stringify(data, null, 2)));
|
|
38
|
+
await connection.apex.put(constants_1.PATH.ADMIN, data, { headers: { 'Content-Type': 'application/json' } });
|
|
39
|
+
logger_1.Logger.success(constants_1.MESSAGE.SUCCESS_IMPORT_CREDENTIALS);
|
|
109
40
|
return { success: true };
|
|
110
41
|
}
|
|
111
42
|
catch (error) {
|
|
112
43
|
const message = error instanceof Error ? error.message : String(error);
|
|
113
|
-
if (message.includes(
|
|
114
|
-
|
|
44
|
+
if (message.includes(constants_1.ERROR.URL_NOT_FOUND)) {
|
|
45
|
+
logger_1.Logger.error(`${constants_1.ERROR.URL_NOT_FOUND}. ${constants_1.ERROR.VERSION_TOO_LOW}`);
|
|
115
46
|
}
|
|
116
47
|
else {
|
|
117
|
-
|
|
48
|
+
logger_1.Logger.error(constants_1.ERROR.IMPORT_CREDENTIALS.replace('[MESSAGE]', message));
|
|
118
49
|
}
|
|
119
50
|
return { success: false };
|
|
120
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admincredentials.js","sourceRoot":"","sources":["../../../../src/commands/butler/pb/admincredentials.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wDAAwD;AACxD,4DAA4D;AAC5D,+BAA+B;AAC/B,2DAA2D;AAC3D,0DAA0D;AAC1D,qEAAqE;AACrE,sDAAsD;AACtD,+DAA+D;AAC/D,kDAAkD;AAClD,qDAAqD;AACrD,qCAAqC;AACrC,uDAAuD;AACvD,+BAA+B;AAC/B,iEAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"admincredentials.js","sourceRoot":"","sources":["../../../../src/commands/butler/pb/admincredentials.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wDAAwD;AACxD,4DAA4D;AAC5D,+BAA+B;AAC/B,2DAA2D;AAC3D,0DAA0D;AAC1D,qEAAqE;AACrE,sDAAsD;AACtD,+DAA+D;AAC/D,kDAAkD;AAClD,qDAAqD;AACrD,qCAAqC;AACrC,uDAAuD;AACvD,+BAA+B;AAC/B,iEAA+D;AAC/D,2CAA4C;AAC5C,kDAA+C;AAC/C,wDAA+D;AAC/D,kEAA6D;AAE7D,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,0BAA0B,EAAE,4BAA4B,CAAC,CAAC;AAMjG,MAAqB,wBAAyB,SAAQ,2BAAyC;IAuCtF,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAE7D,MAAM,cAAc,GAAG,KAAK,CAAC,MAAgB,CAAC;QAC9C,MAAM,OAAO,GAAG,KAAK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AC,MAAM,CAAC;QACrB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,wBAAwB,CAAC;KACvD,CAAC;CACH,CAAC;kBArCiB,wBAAwB"}
|
|
@@ -15,10 +15,5 @@ export default class ButlerPbAdminsettings extends SfCommand<ButlerPbAdminsettin
|
|
|
15
15
|
session: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
16
|
instance: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
17
|
};
|
|
18
|
-
private static log;
|
|
19
|
-
private static isBlank;
|
|
20
|
-
private static authenticateWithTarget;
|
|
21
|
-
private static authenticateWitsSession;
|
|
22
|
-
private static authenticate;
|
|
23
18
|
run(): Promise<ButlerPbAdminsettingsResult>;
|
|
24
19
|
}
|
|
@@ -16,81 +16,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
/* eslint-disable no-console */
|
|
17
17
|
const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
|
|
18
18
|
const core_1 = require("@salesforce/core");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const ERROR_VERSION = 'Verify that you have PDFButler version greater than v1.440.';
|
|
23
|
-
const MSG_CONNECTION_FAILED = 'Connection to Salesforce has been failed.';
|
|
24
|
-
const MSG_CREATION_CONNECTION = 'Creating Connection with the Salesforce org.';
|
|
25
|
-
const MSG_AUTHORIZATION = 'Authorization with the username: [VALUE].';
|
|
26
|
-
const MSG_NO_AUTH_PARAMS = 'No authentication parameters provided. Please provide either username or session and instance parameters.';
|
|
27
|
-
const MSG_RUN_AUTH_COMMAND = 'Run the command "sf org login web" before authenticating with the target.';
|
|
28
|
-
const MSG_CHECK_SESSION_INSTANCE = 'Check if the session is up to date and if the instance is correct.';
|
|
19
|
+
const logger_1 = require("../../../utils/logger");
|
|
20
|
+
const constants_1 = require("../../../utils/constants");
|
|
21
|
+
const authentication_1 = require("../../../utils/authentication");
|
|
29
22
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
30
23
|
const messages = core_1.Messages.loadMessages('@pdfbutler/migration-cli', 'butler.pb.adminsettings');
|
|
31
24
|
class ButlerPbAdminsettings extends sf_plugins_core_1.SfCommand {
|
|
32
|
-
static log(message, type = 'info') {
|
|
33
|
-
const prefix = type === 'info' ? '[INFO]' : '[ERROR]';
|
|
34
|
-
console.log(`${prefix} ${message}`);
|
|
35
|
-
}
|
|
36
|
-
static isBlank(value) {
|
|
37
|
-
return value?.trim() === ''
|
|
38
|
-
|| value === null
|
|
39
|
-
|| value === undefined;
|
|
40
|
-
}
|
|
41
|
-
static async authenticateWithTarget(username) {
|
|
42
|
-
try {
|
|
43
|
-
this.log(MSG_AUTHORIZATION.replace('[VALUE]', username));
|
|
44
|
-
const authInfo = await core_1.AuthInfo.create({ username });
|
|
45
|
-
this.log(MSG_CREATION_CONNECTION);
|
|
46
|
-
const connection = await core_1.Connection.create({ authInfo });
|
|
47
|
-
this.log(`Connected to ${username} (Org ID: ${authInfo.getFields().orgId})`);
|
|
48
|
-
return connection;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
this.log(MSG_RUN_AUTH_COMMAND, 'error');
|
|
52
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
static async authenticateWitsSession(session, instance) {
|
|
56
|
-
if (!this.isBlank(instance) && !this.isBlank(session)) {
|
|
57
|
-
const connection = await new jsforce.Connection({
|
|
58
|
-
instanceUrl: `${instance}`,
|
|
59
|
-
sessionId: `${session}`,
|
|
60
|
-
});
|
|
61
|
-
this.log(`Connected to ${connection.instanceUrl}`);
|
|
62
|
-
return connection;
|
|
63
|
-
}
|
|
64
|
-
else if (!this.isBlank(session) && this.isBlank(instance)) {
|
|
65
|
-
this.log('Instance URL (--instance) cannot be empty', 'error');
|
|
66
|
-
}
|
|
67
|
-
else if (this.isBlank(session) && !this.isBlank(instance)) {
|
|
68
|
-
this.log('Session Id (--session) cannot be empty', 'error');
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this.log('Session Id and Instance URL (--session and --instance) cannot be empty', 'error');
|
|
72
|
-
}
|
|
73
|
-
this.log(MSG_CHECK_SESSION_INSTANCE, 'error');
|
|
74
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
75
|
-
}
|
|
76
|
-
static async authenticate(username, session, instance) {
|
|
77
|
-
let connection;
|
|
78
|
-
if (this.isBlank(username) && (this.isBlank(session) || this.isBlank(instance))) {
|
|
79
|
-
throw new Error(MSG_NO_AUTH_PARAMS);
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
if (this.isBlank(session) || this.isBlank(instance)) {
|
|
83
|
-
connection = await this.authenticateWithTarget(username);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
connection = await this.authenticateWitsSession(session, instance);
|
|
87
|
-
}
|
|
88
|
-
return connection;
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
25
|
async run() {
|
|
95
26
|
const { flags } = await this.parse(ButlerPbAdminsettings);
|
|
96
27
|
const targetUsername = flags.target;
|
|
@@ -102,19 +33,19 @@ class ButlerPbAdminsettings extends sf_plugins_core_1.SfCommand {
|
|
|
102
33
|
stage: flags.stage,
|
|
103
34
|
};
|
|
104
35
|
try {
|
|
105
|
-
const connection = await
|
|
106
|
-
|
|
107
|
-
await connection.apex.post(
|
|
108
|
-
|
|
36
|
+
const connection = await (0, authentication_1.authenticate)(targetUsername, session, instance);
|
|
37
|
+
logger_1.Logger.info(constants_1.MESSAGE.SENDING_TO_ENDPOINT.replace('[URL]', JSON.stringify(data, null, 2)));
|
|
38
|
+
await connection.apex.post(constants_1.PATH.ADMIN, data, { headers: { 'Content-Type': 'application/json' } });
|
|
39
|
+
logger_1.Logger.success(constants_1.MESSAGE.SUCCESS_IMPORT_SETTINGS);
|
|
109
40
|
return { success: true };
|
|
110
41
|
}
|
|
111
42
|
catch (error) {
|
|
112
43
|
const message = error instanceof Error ? error.message : String(error);
|
|
113
|
-
if (message.includes(
|
|
114
|
-
|
|
44
|
+
if (message.includes(constants_1.ERROR.URL_NOT_FOUND)) {
|
|
45
|
+
logger_1.Logger.error(`${constants_1.ERROR.URL_NOT_FOUND}. ${constants_1.ERROR.VERSION_TOO_LOW}`);
|
|
115
46
|
}
|
|
116
47
|
else {
|
|
117
|
-
|
|
48
|
+
logger_1.Logger.error(constants_1.ERROR.IMPORT_SETTINGS.replace('[MESSAGE]', message));
|
|
118
49
|
}
|
|
119
50
|
return { success: false };
|
|
120
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adminsettings.js","sourceRoot":"","sources":["../../../../src/commands/butler/pb/adminsettings.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wDAAwD;AACxD,4DAA4D;AAC5D,+BAA+B;AAC/B,2DAA2D;AAC3D,0DAA0D;AAC1D,qEAAqE;AACrE,sDAAsD;AACtD,+DAA+D;AAC/D,kDAAkD;AAClD,qDAAqD;AACrD,qCAAqC;AACrC,uDAAuD;AACvD,+BAA+B;AAC/B,iEAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"adminsettings.js","sourceRoot":"","sources":["../../../../src/commands/butler/pb/adminsettings.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wDAAwD;AACxD,4DAA4D;AAC5D,+BAA+B;AAC/B,2DAA2D;AAC3D,0DAA0D;AAC1D,qEAAqE;AACrE,sDAAsD;AACtD,+DAA+D;AAC/D,kDAAkD;AAClD,qDAAqD;AACrD,qCAAqC;AACrC,uDAAuD;AACvD,+BAA+B;AAC/B,iEAA+D;AAC/D,2CAA4C;AAC5C,kDAA+C;AAC/C,wDAA+D;AAC/D,kEAA6D;AAE7D,eAAQ,CAA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OAAO,EAAE,uBAAK,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,uBAAuB,CAAC;KACtD,CAAC;IACF,QAAQ,EAAE,uBAAK,CAAC,MAAM,CAAC;QACrB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,wBAAwB,CAAC;KACvD,CAAC;CACH,CAAC;kBAhCiB,qBAAqB"}
|
|
@@ -27,11 +27,6 @@ export default class ButlerPbExport extends SfCommand<Buffer> {
|
|
|
27
27
|
};
|
|
28
28
|
private static isLogsActive;
|
|
29
29
|
private static getDocConfigIds;
|
|
30
|
-
private static isBlank;
|
|
31
|
-
private static log;
|
|
32
|
-
private static authenticateWithTarget;
|
|
33
|
-
private static authenticateWitsSession;
|
|
34
|
-
private static authenticate;
|
|
35
30
|
private static getDocConfigs;
|
|
36
31
|
private static convertBufferToUtf8;
|
|
37
32
|
run(): Promise<Buffer>;
|
|
@@ -19,134 +19,38 @@ const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
|
|
|
19
19
|
const core_1 = require("@salesforce/core");
|
|
20
20
|
const AdmZip = require("adm-zip");
|
|
21
21
|
const got_1 = require("got");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const CUT_AFTER = 150;
|
|
26
|
-
const MSG_SPLITTED_DOC_CONFIGS = 'Number of DocConfig Ids after splitting: [VALUE].';
|
|
27
|
-
const MSG_AUTHORIZATION = 'Authorization with the username: [VALUE].';
|
|
28
|
-
const MSG_EXPORTED_DOC_CONFIGS = 'Number of exported DocConfigs: [VALUE].';
|
|
29
|
-
const MSG_FOLDER_CREATED = 'Folder structure created at: [VALUE].';
|
|
30
|
-
const MSG_DOC_CONFIG_HAS_NO_BACKEND = 'DocConfig with ID - [VALUE], does not have a backend.';
|
|
31
|
-
const MSG_NO_AUTH_PARAMS = 'No authentication parameters provided. Please provide either username or session and instance parameters.';
|
|
32
|
-
const MSG_NO_MATCHING_DOC_CONFIGS = 'No matching Doc Configs ids found.';
|
|
33
|
-
const MSG_CONNECTION_FAILED = 'Connection to Salesforce has been failed.';
|
|
34
|
-
const MSG_EXPORT_FAILED = 'DocConfig export has failed. Check the IDs and try again.';
|
|
35
|
-
const MSG_BACKEND_DATA_ARCHIVED = 'Exported data from backend has been archived.';
|
|
36
|
-
const MSG_BLANK_BACKEND = 'One or more docConfigs have no backend.';
|
|
37
|
-
const MSG_USER_HAS_PERMISSIONS = 'User has read/write permissions.';
|
|
38
|
-
const MSG_USER_HAS_NO_PERMISSIONS = "User doesn't have read/write permissions.";
|
|
39
|
-
const MSG_ARCHIVE_UNZIPPED = 'Archive unzipped and recorded locally.';
|
|
40
|
-
const MSG_ARCHIVE_RECORDED = 'Archive recorded locally.';
|
|
41
|
-
const MSG_CREATION_CONNECTION = 'Creating Connection with the Salesforce org.';
|
|
42
|
-
const MSG_FETCH_DATA = 'Attempting to fetch data from the org.';
|
|
43
|
-
const MSG_UNZIP_FILES = 'Unzipping the files.';
|
|
44
|
-
const MSG_SAVE_AS_ZIP = 'Saving as zip.';
|
|
45
|
-
const MSG_SAVE_BACKEND = 'Saving backend only.';
|
|
46
|
-
const MSG_PARTIAL_EXPORT_ACTIVE = 'The partial export is active. DocConfigs that do not have a backend will not be exported.';
|
|
47
|
-
const MSG_TRY_TO_GET_DOC_CONFIG_BACKEND = 'Trying to get backend of DocConfig with ID: [VALUE]';
|
|
48
|
-
const MSG_START_EXPORT_BACKEND = 'Starting to export DocConfigs backend.';
|
|
49
|
-
const MSG_RUN_AUTH_COMMAND = 'Run the command "sf org login web" before authenticating with the target.';
|
|
50
|
-
const MSG_CHECK_SESSION_INSTANCE = 'Check if the session is up to date and if the instance is correct.';
|
|
22
|
+
const logger_1 = require("../../../utils/logger");
|
|
23
|
+
const constants_1 = require("../../../utils/constants");
|
|
24
|
+
const authentication_1 = require("../../../utils/authentication");
|
|
51
25
|
core_1.Messages.importMessagesDirectory(__dirname);
|
|
52
26
|
const messages = core_1.Messages.loadMessages('@pdfbutler/migration-cli', 'butler.pb.export');
|
|
53
27
|
class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
54
28
|
static getDocConfigIds(id) {
|
|
55
|
-
const docConfigIds = id.split(
|
|
29
|
+
const docConfigIds = id.split(constants_1.PATTERN.DOC_CONFIG).filter((n) => n);
|
|
56
30
|
docConfigIds.map((docId) => {
|
|
57
31
|
if (!docId.trim() || docId.length < 36) {
|
|
58
32
|
docConfigIds.splice(docConfigIds.indexOf(docId), 1);
|
|
59
33
|
}
|
|
60
34
|
});
|
|
61
|
-
|
|
62
|
-
this.log(MSG_SPLITTED_DOC_CONFIGS.replace('[VALUE]', docConfigIds.length.toString()));
|
|
35
|
+
logger_1.Logger.info(constants_1.MESSAGE.SPLITTED_DOC_CONFIGS.replace('[VALUE]', docConfigIds.length.toString()), this.isLogsActive);
|
|
63
36
|
if (docConfigIds.length < 0) {
|
|
64
|
-
throw new Error(
|
|
37
|
+
throw new Error(constants_1.ERROR.NO_MATCHING_DOC_CONFIGS);
|
|
65
38
|
}
|
|
66
39
|
return docConfigIds;
|
|
67
40
|
}
|
|
68
|
-
static isBlank(value) {
|
|
69
|
-
return value === ''
|
|
70
|
-
|| value === null
|
|
71
|
-
|| value === undefined;
|
|
72
|
-
}
|
|
73
|
-
static log(message, type = 'info') {
|
|
74
|
-
const prefix = type === 'info' ? '[INFO]' : '[ERROR]';
|
|
75
|
-
console.log(`${prefix} ${message}`);
|
|
76
|
-
}
|
|
77
|
-
static async authenticateWithTarget(username) {
|
|
78
|
-
try {
|
|
79
|
-
if (this.isLogsActive)
|
|
80
|
-
this.log(MSG_AUTHORIZATION.replace('[VALUE]', username));
|
|
81
|
-
const authInfo = await core_1.AuthInfo.create({ username });
|
|
82
|
-
if (this.isLogsActive)
|
|
83
|
-
this.log(MSG_CREATION_CONNECTION);
|
|
84
|
-
const connection = await core_1.Connection.create({ authInfo });
|
|
85
|
-
this.log(`Connected to ${username} (Org ID: ${authInfo.getFields().orgId})`);
|
|
86
|
-
return connection;
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
this.log(MSG_RUN_AUTH_COMMAND, 'error');
|
|
90
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
static async authenticateWitsSession(session, instance) {
|
|
94
|
-
session = session.trim();
|
|
95
|
-
instance = instance.trim();
|
|
96
|
-
const isInstanceBlank = this.isBlank(instance);
|
|
97
|
-
const isSessionBlank = this.isBlank(session);
|
|
98
|
-
if (!isInstanceBlank && !isSessionBlank) {
|
|
99
|
-
const connection = await new jsforce.Connection({
|
|
100
|
-
instanceUrl: `${instance}`,
|
|
101
|
-
sessionId: `${session}`,
|
|
102
|
-
});
|
|
103
|
-
this.log(`Connected to ${connection.instanceUrl}`);
|
|
104
|
-
return connection;
|
|
105
|
-
}
|
|
106
|
-
else if (!isSessionBlank && isInstanceBlank) {
|
|
107
|
-
this.log('Instance URL (--instance) cannot be empty', 'error');
|
|
108
|
-
}
|
|
109
|
-
else if (isSessionBlank && !isInstanceBlank) {
|
|
110
|
-
this.log('Session Id (--session) cannot be empty', 'error');
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
this.log('Session Id and Instance URL (--session and --instance) cannot be empty', 'error');
|
|
114
|
-
}
|
|
115
|
-
this.log(MSG_CHECK_SESSION_INSTANCE, 'error');
|
|
116
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
117
|
-
}
|
|
118
|
-
static async authenticate(username, session, instance) {
|
|
119
|
-
let connection;
|
|
120
|
-
if (this.isBlank(username) && (this.isBlank(session) || this.isBlank(instance))) {
|
|
121
|
-
throw new Error(MSG_NO_AUTH_PARAMS);
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
if (this.isBlank(session) || this.isBlank(instance)) {
|
|
125
|
-
connection = await this.authenticateWithTarget(username);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
connection = await this.authenticateWitsSession(session, instance);
|
|
129
|
-
}
|
|
130
|
-
return connection;
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
throw new Error(MSG_CONNECTION_FAILED);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
41
|
static async getDocConfigs(docConfigIds, connection) {
|
|
137
42
|
let docConfigPromises;
|
|
138
43
|
let responses = [];
|
|
139
44
|
try {
|
|
140
|
-
|
|
141
|
-
this.log(MSG_FETCH_DATA);
|
|
45
|
+
logger_1.Logger.info(constants_1.MESSAGE.FETCH_DATA, ButlerPbExport.isLogsActive);
|
|
142
46
|
docConfigPromises = docConfigIds.map(async (docConfigId) => {
|
|
143
|
-
const endpoint = `${
|
|
47
|
+
const endpoint = `${constants_1.PATH.EXPORT_DOC_CONFIG}${docConfigId}`;
|
|
144
48
|
return connection.apex.get(endpoint);
|
|
145
49
|
});
|
|
146
50
|
responses = await Promise.all(docConfigPromises);
|
|
147
51
|
}
|
|
148
52
|
catch (e) {
|
|
149
|
-
throw new Error(
|
|
53
|
+
throw new Error(constants_1.ERROR.EXPORT_FAILED);
|
|
150
54
|
}
|
|
151
55
|
return responses;
|
|
152
56
|
}
|
|
@@ -160,7 +64,7 @@ class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
|
160
64
|
}
|
|
161
65
|
async run() {
|
|
162
66
|
const { flags } = await this.parse(ButlerPbExport);
|
|
163
|
-
ButlerPbExport.isLogsActive = flags.logs;
|
|
67
|
+
ButlerPbExport.isLogsActive = !!flags.logs;
|
|
164
68
|
const outDir = flags.out;
|
|
165
69
|
const isUseShortPath = flags.shortpaths;
|
|
166
70
|
let docConfigIds = [];
|
|
@@ -169,31 +73,27 @@ class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
|
169
73
|
const session = flags.session;
|
|
170
74
|
const instance = flags.instance;
|
|
171
75
|
docConfigIds = ButlerPbExport.getDocConfigIds(flags.id);
|
|
172
|
-
|
|
173
|
-
const connection = await
|
|
76
|
+
logger_1.Logger.info(JSON.stringify(docConfigIds, null, 2));
|
|
77
|
+
const connection = await (0, authentication_1.authenticate)(targetUsername, session, instance);
|
|
174
78
|
docConfigResponses = await ButlerPbExport.getDocConfigs(docConfigIds, connection);
|
|
175
|
-
|
|
176
|
-
ButlerPbExport.log(MSG_EXPORTED_DOC_CONFIGS.replace('[VALUE]', docConfigResponses.length.toString()));
|
|
79
|
+
logger_1.Logger.info(constants_1.MESSAGE.EXPORTED_DOC_CONFIGS.replace('[VALUE]', docConfigResponses.length.toString()), ButlerPbExport.isLogsActive);
|
|
177
80
|
if (docConfigResponses.length < 1)
|
|
178
|
-
throw new Error(
|
|
81
|
+
throw new Error(constants_1.ERROR.NO_MATCHING_DOC_CONFIGS);
|
|
179
82
|
let zipMap = new Map();
|
|
180
83
|
let result = Buffer.from('');
|
|
181
84
|
if (!flags.backend) {
|
|
182
|
-
|
|
183
|
-
ButlerPbExport.log(MSG_START_EXPORT_BACKEND);
|
|
85
|
+
logger_1.Logger.info(constants_1.MESSAGE.START_EXPORT_BACKEND, ButlerPbExport.isLogsActive);
|
|
184
86
|
const auth = flags['auth-env-var'];
|
|
185
87
|
let base64Auth = auth;
|
|
186
88
|
if (auth?.indexOf(':')) {
|
|
187
89
|
base64Auth = Buffer.from(auth).toString('base64');
|
|
188
90
|
}
|
|
189
|
-
|
|
190
|
-
ButlerPbExport.log(MSG_PARTIAL_EXPORT_ACTIVE);
|
|
91
|
+
logger_1.Logger.info(constants_1.MESSAGE.PARTIAL_EXPORT_ACTIVE, ButlerPbExport.isLogsActive && flags.partial);
|
|
191
92
|
for (const docConfigId of docConfigIds) {
|
|
192
|
-
|
|
193
|
-
ButlerPbExport.log(MSG_TRY_TO_GET_DOC_CONFIG_BACKEND.replace('[VALUE]', docConfigId));
|
|
93
|
+
logger_1.Logger.info(constants_1.MESSAGE.TRY_GET_DOC_CONFIG_BACKEND.replace('[VALUE]', docConfigId), ButlerPbExport.isLogsActive);
|
|
194
94
|
let finalUrl = `${flags.endpoint?.toString()}config/export-config/${flags.stage}/${docConfigId}`;
|
|
195
95
|
if (isUseShortPath) {
|
|
196
|
-
|
|
96
|
+
logger_1.Logger.info(constants_1.MESSAGE.USED_SHORT_PATH);
|
|
197
97
|
finalUrl += '?shortPaths=true';
|
|
198
98
|
}
|
|
199
99
|
try {
|
|
@@ -203,15 +103,13 @@ class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
|
203
103
|
},
|
|
204
104
|
}).buffer();
|
|
205
105
|
zipMap.set(docConfigId, new AdmZip(result));
|
|
206
|
-
|
|
207
|
-
ButlerPbExport.log(MSG_BACKEND_DATA_ARCHIVED);
|
|
106
|
+
logger_1.Logger.info(constants_1.MESSAGE.BACKEND_DATA_ARCHIVED, ButlerPbExport.isLogsActive);
|
|
208
107
|
}
|
|
209
108
|
catch (err) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
ButlerPbExport.log(MSG_DOC_CONFIG_HAS_NO_BACKEND.replace('[VALUE]', docConfigId));
|
|
109
|
+
logger_1.Logger.error(JSON.stringify(err));
|
|
110
|
+
logger_1.Logger.error(constants_1.MESSAGE.DOC_CONFIG_NO_BACKEND.replace('[VALUE]', docConfigId), ButlerPbExport.isLogsActive);
|
|
213
111
|
if (!flags.partial) {
|
|
214
|
-
throw new Error(
|
|
112
|
+
throw new Error(constants_1.ERROR.BLANK_BACKEND);
|
|
215
113
|
}
|
|
216
114
|
}
|
|
217
115
|
}
|
|
@@ -219,22 +117,20 @@ class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
|
219
117
|
else {
|
|
220
118
|
zipMap = new Map();
|
|
221
119
|
}
|
|
222
|
-
|
|
223
|
-
ButlerPbExport.log(MSG_FOLDER_CREATED.replace('[VALUE]', `./${outDir}/sfdc`));
|
|
120
|
+
logger_1.Logger.info(constants_1.MESSAGE.FOLDER_CREATED.replace('[VALUE]', `./${outDir}/sfdc`), ButlerPbExport.isLogsActive);
|
|
224
121
|
await fs_1.promises.mkdir(`./${outDir}/sfdc`, { recursive: true });
|
|
225
122
|
if (ButlerPbExport.isLogsActive) {
|
|
226
123
|
try {
|
|
227
124
|
await fs_1.promises.access(`./${outDir}`, fs_1.promises.constants.R_OK | fs_1.promises.constants.W_OK);
|
|
228
|
-
|
|
125
|
+
logger_1.Logger.info(constants_1.MESSAGE.USER_HAS_PERMISSIONS);
|
|
229
126
|
}
|
|
230
127
|
catch (err) {
|
|
231
|
-
|
|
128
|
+
logger_1.Logger.error(constants_1.ERROR.USER_NO_PERMISSIONS);
|
|
232
129
|
}
|
|
233
130
|
}
|
|
234
131
|
if (zipMap.size > 0) {
|
|
235
132
|
if (flags.unzip) {
|
|
236
|
-
|
|
237
|
-
ButlerPbExport.log(MSG_UNZIP_FILES);
|
|
133
|
+
logger_1.Logger.info(constants_1.MESSAGE.UNZIP_FILES, ButlerPbExport.isLogsActive);
|
|
238
134
|
const extractionAndWritePromises = Array.from(zipMap.entries()).map(async ([key, value]) => {
|
|
239
135
|
ButlerPbExport.convertBufferToUtf8(value).extractAllTo(`./${outDir}/${key}`, false);
|
|
240
136
|
const filePath = `./${outDir}/sfdc/${key}.json`;
|
|
@@ -242,19 +138,17 @@ class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
|
242
138
|
await fs_1.promises.writeFile(filePath, data);
|
|
243
139
|
});
|
|
244
140
|
await Promise.all(extractionAndWritePromises);
|
|
245
|
-
|
|
246
|
-
ButlerPbExport.log(MSG_ARCHIVE_UNZIPPED);
|
|
141
|
+
logger_1.Logger.info(constants_1.MESSAGE.ARCHIVE_UNZIPPED, ButlerPbExport.isLogsActive);
|
|
247
142
|
}
|
|
248
143
|
else {
|
|
249
|
-
|
|
250
|
-
ButlerPbExport.log(MSG_SAVE_AS_ZIP);
|
|
144
|
+
logger_1.Logger.info(constants_1.MESSAGE.SAVE_AS_ZIP, ButlerPbExport.isLogsActive);
|
|
251
145
|
const zipAndWritePromises = Array.from(zipMap.entries()).map(async ([key, value]) => {
|
|
252
146
|
const zipToExport = new AdmZip();
|
|
253
147
|
for (const entry of value.getEntries()) {
|
|
254
148
|
let entryName = entry.entryName;
|
|
255
149
|
const fileName = entryName.substring(Number(entryName.lastIndexOf('/')) + 1, entryName.lastIndexOf('.'));
|
|
256
150
|
entryName = flags.cut ?
|
|
257
|
-
entryName.replace(fileName, fileName.substring(0,
|
|
151
|
+
entryName.replace(fileName, fileName.substring(0, constants_1.CUT.AFTER))
|
|
258
152
|
: entryName;
|
|
259
153
|
zipToExport.addFile(entryName, value.readFile(entry));
|
|
260
154
|
}
|
|
@@ -264,8 +158,7 @@ class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
|
264
158
|
await Promise.all([zipPromise, jsonPromise]);
|
|
265
159
|
});
|
|
266
160
|
await Promise.all(zipAndWritePromises);
|
|
267
|
-
|
|
268
|
-
ButlerPbExport.log(MSG_ARCHIVE_RECORDED);
|
|
161
|
+
logger_1.Logger.success(constants_1.MESSAGE.ARCHIVE_RECORDED);
|
|
269
162
|
}
|
|
270
163
|
}
|
|
271
164
|
else {
|
|
@@ -275,8 +168,7 @@ class ButlerPbExport extends sf_plugins_core_1.SfCommand {
|
|
|
275
168
|
await fs_1.promises.writeFile(filePath, data);
|
|
276
169
|
});
|
|
277
170
|
await Promise.all(writePromises);
|
|
278
|
-
|
|
279
|
-
ButlerPbExport.log(MSG_SAVE_BACKEND);
|
|
171
|
+
logger_1.Logger.success(constants_1.MESSAGE.SAVE_BACKEND);
|
|
280
172
|
}
|
|
281
173
|
return result;
|
|
282
174
|
}
|