@pdfbutler/migration-cli 0.0.27 → 0.0.29

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.
Files changed (61) hide show
  1. package/README.md +332 -45
  2. package/lib/commands/butler/pb/admincredentials.js +37 -37
  3. package/lib/commands/butler/pb/admincredentials.js.map +1 -1
  4. package/lib/commands/butler/pb/adminsettings.d.ts +1 -2
  5. package/lib/commands/butler/pb/adminsettings.js +32 -32
  6. package/lib/commands/butler/pb/adminsettings.js.map +1 -1
  7. package/lib/commands/butler/pb/export.d.ts +12 -4
  8. package/lib/commands/butler/pb/export.js +333 -200
  9. package/lib/commands/butler/pb/export.js.map +1 -1
  10. package/lib/commands/butler/pb/exportdatasource.d.ts +28 -0
  11. package/lib/commands/butler/pb/exportdatasource.js +163 -0
  12. package/lib/commands/butler/pb/exportdatasource.js.map +1 -0
  13. package/lib/commands/butler/pb/exportpack.d.ts +15 -0
  14. package/lib/commands/butler/pb/exportpack.js +282 -68
  15. package/lib/commands/butler/pb/exportpack.js.map +1 -1
  16. package/lib/commands/butler/pb/import.d.ts +17 -3
  17. package/lib/commands/butler/pb/import.js +403 -192
  18. package/lib/commands/butler/pb/import.js.map +1 -1
  19. package/lib/commands/butler/pb/importdatasource.d.ts +31 -0
  20. package/lib/commands/butler/pb/importdatasource.js +252 -0
  21. package/lib/commands/butler/pb/importdatasource.js.map +1 -0
  22. package/lib/commands/butler/pb/importpack.d.ts +23 -0
  23. package/lib/commands/butler/pb/importpack.js +391 -69
  24. package/lib/commands/butler/pb/importpack.js.map +1 -1
  25. package/lib/commands/butler/sb/export/signtemplate.d.ts +23 -0
  26. package/lib/commands/butler/sb/export/signtemplate.js +111 -0
  27. package/lib/commands/butler/sb/export/signtemplate.js.map +1 -0
  28. package/lib/commands/butler/sb/import/signtemplate.d.ts +23 -0
  29. package/lib/commands/butler/sb/import/signtemplate.js +108 -0
  30. package/lib/commands/butler/sb/import/signtemplate.js.map +1 -0
  31. package/lib/utils/authentication.d.ts +3 -1
  32. package/lib/utils/authentication.js +13 -17
  33. package/lib/utils/authentication.js.map +1 -1
  34. package/lib/utils/constants.d.ts +134 -89
  35. package/lib/utils/constants.js +65 -20
  36. package/lib/utils/constants.js.map +1 -1
  37. package/lib/utils/extract-templates.d.ts +1 -0
  38. package/lib/utils/extract-templates.js +89 -0
  39. package/lib/utils/extract-templates.js.map +1 -0
  40. package/lib/utils/id-map.d.ts +1 -0
  41. package/lib/utils/id-map.js +22 -0
  42. package/lib/utils/id-map.js.map +1 -0
  43. package/lib/utils/ids.d.ts +2 -0
  44. package/lib/utils/ids.js +21 -0
  45. package/lib/utils/ids.js.map +1 -0
  46. package/lib/utils/logger.d.ts +2 -1
  47. package/lib/utils/logger.js +15 -7
  48. package/lib/utils/logger.js.map +1 -1
  49. package/lib/utils/pack-docconfigs.d.ts +4 -0
  50. package/lib/utils/pack-docconfigs.js +77 -0
  51. package/lib/utils/pack-docconfigs.js.map +1 -0
  52. package/messages/butler.pb.export.md +4 -0
  53. package/messages/butler.pb.exportdatasource.md +51 -0
  54. package/messages/butler.pb.exportpack.md +24 -0
  55. package/messages/butler.pb.import.md +4 -0
  56. package/messages/butler.pb.importdatasource.md +51 -0
  57. package/messages/butler.pb.importpack.md +24 -0
  58. package/messages/butler.sb.export.signtemplate.md +35 -0
  59. package/messages/butler.sb.import.signtemplate.md +35 -0
  60. package/oclif.manifest.json +437 -46
  61. package/package.json +223 -215
@@ -0,0 +1,28 @@
1
+ import { SfCommand } from '@salesforce/sf-plugins-core';
2
+ export type ButlerPbExportdatasourceResult = {
3
+ path: string;
4
+ };
5
+ export default class ButlerPbExportdatasource extends SfCommand<ButlerPbExportdatasourceResult> {
6
+ static readonly summary: string;
7
+ static readonly description: string;
8
+ static readonly examples: string[];
9
+ static readonly flags: {
10
+ target: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ id: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ folder: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
+ 'auth-env-var': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
+ endpoint: import("@oclif/core/lib/interfaces").OptionFlag<import("node:url").URL | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
+ stage: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
+ logs: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
17
+ parents: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
18
+ session: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
19
+ instance: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
20
+ };
21
+ private static readonly dataSourcesFolderName;
22
+ private static isLogsActive;
23
+ private static getDataSourceIds;
24
+ private static exportDataSource;
25
+ private static saveDataSource;
26
+ private static exportDataSourceWithParents;
27
+ run(): Promise<ButlerPbExportdatasourceResult>;
28
+ }
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path = require("path");
4
+ const node_fs_1 = require("node:fs");
5
+ const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
6
+ const core_1 = require("@salesforce/core");
7
+ const logger_1 = require("../../../utils/logger");
8
+ const constants_1 = require("../../../utils/constants");
9
+ const authentication_1 = require("../../../utils/authentication");
10
+ core_1.Messages.importMessagesDirectory(__dirname);
11
+ const messages = core_1.Messages.loadMessages('@pdfbutler/migration-cli', 'butler.pb.exportdatasource');
12
+ class ButlerPbExportdatasource extends sf_plugins_core_1.SfCommand {
13
+ static summary = messages.getMessage('summary');
14
+ static description = messages.getMessage('description');
15
+ static examples = messages.getMessages('examples');
16
+ static flags = {
17
+ target: sf_plugins_core_1.Flags.string({
18
+ summary: messages.getMessage('flags.target.summary'),
19
+ char: 't',
20
+ required: false,
21
+ }),
22
+ id: sf_plugins_core_1.Flags.string({
23
+ summary: messages.getMessage('flags.id.summary'),
24
+ char: 'i',
25
+ required: true,
26
+ }),
27
+ folder: sf_plugins_core_1.Flags.string({
28
+ summary: messages.getMessage('flags.folder.summary'),
29
+ // eslint-disable-next-line sf-plugin/dash-o
30
+ char: 'f',
31
+ required: true,
32
+ }),
33
+ 'auth-env-var': sf_plugins_core_1.Flags.string({
34
+ summary: messages.getMessage('flags.auth-env-var.summary'),
35
+ char: 'a',
36
+ }),
37
+ endpoint: sf_plugins_core_1.Flags.url({
38
+ summary: messages.getMessage('flags.endpoint.summary'),
39
+ char: 'e',
40
+ }),
41
+ stage: sf_plugins_core_1.Flags.string({
42
+ summary: messages.getMessage('flags.stage.summary'),
43
+ char: 's',
44
+ required: true,
45
+ }),
46
+ logs: sf_plugins_core_1.Flags.boolean({
47
+ summary: messages.getMessage('flags.logs.summary'),
48
+ char: 'l',
49
+ }),
50
+ parents: sf_plugins_core_1.Flags.boolean({
51
+ summary: messages.getMessage('flags.parents.summary'),
52
+ char: 'p',
53
+ }),
54
+ session: sf_plugins_core_1.Flags.string({
55
+ summary: messages.getMessage('flags.session.summary'),
56
+ }),
57
+ instance: sf_plugins_core_1.Flags.string({
58
+ summary: messages.getMessage('flags.instance.summary'),
59
+ }),
60
+ };
61
+ static dataSourcesFolderName = 'dataSources';
62
+ static isLogsActive = false;
63
+ static getDataSourceIds(id) {
64
+ logger_1.Logger.info(constants_1.MESSAGE.START_SPLIT_DATA_SOURCES, this.isLogsActive);
65
+ const tokens = id.split(/[\s,]+/).map((item) => item.trim()).filter(Boolean);
66
+ const dataSourceIds = tokens.filter((token) => constants_1.PATTERN.DATA_SOURCE_ID.test(token));
67
+ logger_1.Logger.info(constants_1.MESSAGE.SPLITTED_DATA_SOURCES_LIST.replace('[VALUE]', JSON.stringify(dataSourceIds, null, 2)), this.isLogsActive);
68
+ if (dataSourceIds.length <= 0) {
69
+ throw new Error(constants_1.ERROR.NO_MATCHING_DATA_SOURCES);
70
+ }
71
+ return dataSourceIds;
72
+ }
73
+ static async exportDataSource(connection, dataSourceId) {
74
+ try {
75
+ logger_1.Logger.info(constants_1.MESSAGE.FETCH_DATA, this.isLogsActive);
76
+ const endpoint = `${constants_1.PATH.EXPORT_DATA_SOURCE}${dataSourceId}`;
77
+ const response = await connection.apex.get(endpoint);
78
+ logger_1.Logger.success(constants_1.MESSAGE.FETCH_DATA_SUCCESS, this.isLogsActive);
79
+ return response;
80
+ }
81
+ catch (error) {
82
+ logger_1.Logger.error(constants_1.MESSAGE.FETCH_DATA_FAILED.replace('[ID]', dataSourceId), true);
83
+ throw new Error(constants_1.ERROR.EXPORT_DATA_SOURCE_FAILED);
84
+ }
85
+ }
86
+ static async saveDataSource(outputDir, dataSourceId, data) {
87
+ const dirName = path.join(outputDir, 'sfdc');
88
+ const filePath = path.join(dirName, `${dataSourceId}.json`);
89
+ await node_fs_1.promises.mkdir(dirName, { recursive: true });
90
+ await node_fs_1.promises.writeFile(filePath, JSON.stringify(data, null, 2));
91
+ return filePath;
92
+ }
93
+ static async exportDataSourceWithParents(connection, outputDir, dataSourceId, exportedIds, autoExportParents, logAsStandalone = false, isParentExport = false) {
94
+ if (exportedIds.has(dataSourceId)) {
95
+ return 0;
96
+ }
97
+ if (logAsStandalone) {
98
+ const exportMessage = isParentExport && autoExportParents
99
+ ? constants_1.MESSAGE.EXPORTING_PARENT_DATA_SOURCE
100
+ : constants_1.MESSAGE.EXPORTING_DATA_SOURCE;
101
+ logger_1.Logger.info(exportMessage
102
+ .replace('[INDEX]', '1')
103
+ .replace('[TOTAL]', '1')
104
+ .replace('[ID]', dataSourceId), true);
105
+ }
106
+ const dataSource = await this.exportDataSource(connection, dataSourceId);
107
+ await this.saveDataSource(outputDir, dataSourceId, dataSource);
108
+ exportedIds.add(dataSourceId);
109
+ const payload = dataSource;
110
+ const parentDataSourceId = payload.parentCustomerDataSourceId?.trim();
111
+ if (!parentDataSourceId) {
112
+ return 1;
113
+ }
114
+ if (!autoExportParents) {
115
+ logger_1.Logger.warn(constants_1.MESSAGE.PARENT_DATA_SOURCE_DETECTED_INFO
116
+ .replace('[ID]', dataSourceId)
117
+ .replace('[PARENT_ID]', parentDataSourceId) +
118
+ constants_1.MESSAGE.PARENT_DATA_SOURCE_DETECTED_WARN, true);
119
+ return 1;
120
+ }
121
+ if (exportedIds.has(parentDataSourceId)) {
122
+ return 1;
123
+ }
124
+ logger_1.Logger.info(constants_1.MESSAGE.PARENT_DATA_SOURCE_DETECTED_INFO
125
+ .replace('[ID]', dataSourceId)
126
+ .replace('[PARENT_ID]', parentDataSourceId), true);
127
+ const parentCount = await this.exportDataSourceWithParents(connection, outputDir, parentDataSourceId, exportedIds, autoExportParents, true, true);
128
+ return 1 + parentCount;
129
+ }
130
+ async run() {
131
+ const { flags } = await this.parse(ButlerPbExportdatasource);
132
+ ButlerPbExportdatasource.isLogsActive = !!flags.logs;
133
+ const outputDir = path.join(flags.folder, ButlerPbExportdatasource.dataSourcesFolderName);
134
+ const targetUsername = flags.target;
135
+ const session = flags.session;
136
+ const instance = flags.instance;
137
+ const autoExportParents = Boolean(flags.parents);
138
+ let connection;
139
+ try {
140
+ connection = (await (0, authentication_1.authenticate)(targetUsername, session, instance));
141
+ }
142
+ catch (error) {
143
+ process.exitCode = 1;
144
+ return { path: '' };
145
+ }
146
+ const dataSourceIds = ButlerPbExportdatasource.getDataSourceIds(flags.id);
147
+ const total = dataSourceIds.length;
148
+ const exportedIds = new Set();
149
+ const exportedCount = await dataSourceIds.reduce(async (accPromise, dataSourceId, index) => {
150
+ const acc = await accPromise;
151
+ logger_1.Logger.info(constants_1.MESSAGE.EXPORTING_DATA_SOURCE
152
+ .replace('[INDEX]', (index + 1).toString())
153
+ .replace('[TOTAL]', total.toString())
154
+ .replace('[ID]', dataSourceId), true);
155
+ return (acc +
156
+ (await ButlerPbExportdatasource.exportDataSourceWithParents(connection, outputDir, dataSourceId, exportedIds, autoExportParents)));
157
+ }, Promise.resolve(0));
158
+ logger_1.Logger.success(constants_1.MESSAGE.EXPORTED_DATA_SOURCES_SUCCESS.replace('[VALUE]', exportedCount.toString()), true);
159
+ return { path: path.join(outputDir, 'sfdc') };
160
+ }
161
+ }
162
+ exports.default = ButlerPbExportdatasource;
163
+ //# sourceMappingURL=exportdatasource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exportdatasource.js","sourceRoot":"","sources":["../../../../src/commands/butler/pb/exportdatasource.ts"],"names":[],"mappings":";;AAAA,6BAA8B;AAC9B,qCAAyC;AACzC,iEAA+D;AAC/D,2CAAwD;AAExD,2CAAwC;AACxC,iDAAkE;AAClE,2DAAsD;AAEtD,eAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,eAAQ,CAAC,YAAY,CAAC,0BAA0B,EAAE,4BAA4B,CAAC,CAAC;AAWjG,MAAqB,wBAAyB,SAAQ,2BAAyC;IACtF,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QAC7B,MAAM,EAAE,uBAAK,CAAC,MAAM,CAAC;YACnB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC;YACpD,IAAI,EAAE,GAAG;YACT,QAAQ,EAAE,KAAK;SAChB,CAAC;QACF,EAAE,EAAE,uBAAK,CAAC,MAAM,CAAC;YACf,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,kBAAkB,CAAC;YAChD,IAAI,EAA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AAE,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;iBAC1C,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;iBACpC,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,EAChC,IAAI,CACL,CAAC;YACF,OAAO,CACL,GAAG;gBACH,CAAC,MAAM,wBAAwB,CAAC,2BAA2B,CACzD,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,iBAAiB,CAClB,CAAC,CACH,CAAC;QACJ,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAEvB,eAAM,CAAC,OAAO,CACZ,mBAAO,CAAC,6BAA6B,CAAC,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC,QAAQ,EAAE,CAAC,EAClF,IAAI,CACL,CAAC;QAEF,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC;IAChD,CAAC;;AA9NH,2CA+NC"}
@@ -12,11 +12,26 @@ export default class ButlerPbExportpack extends SfCommand<ButlerPbExportpackResu
12
12
  target: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
13
13
  out: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
14
14
  logs: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
15
+ 'auth-env-var': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
+ endpoint: import("@oclif/core/lib/interfaces").OptionFlag<import("node:url").URL | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
17
+ stage: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
18
+ unzip: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
19
+ templates: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ docconfig: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
15
21
  session: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
22
  instance: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
17
23
  };
18
24
  private static isLogsActive;
25
+ private static processedDocConfigIds;
26
+ private static resolveExportDirectories;
19
27
  private static exportPackData;
20
28
  private static saveToFile;
29
+ private static exportDocConfigData;
30
+ private static saveDocConfigToFile;
31
+ private static saveDocConfigZip;
32
+ private static saveDocConfigUnzipped;
33
+ private static fetchBackendZip;
34
+ private static collectTemplateIdsFromBackend;
35
+ private static exportDocConfigsByMode;
21
36
  run(): Promise<ButlerPbExportpackResult>;
22
37
  }
@@ -1,28 +1,131 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable @typescript-eslint/no-var-requires */
4
- /* eslint-disable @typescript-eslint/no-unsafe-return */
5
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
6
- /* eslint-disable complexity */
7
- /* eslint-disable @typescript-eslint/no-misused-promises */
8
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
9
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
10
- /* eslint-disable @typescript-eslint/no-unsafe-call */
11
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
12
- /* eslint-disable sf-plugin/no-missing-messages */
13
- /* eslint-disable @typescript-eslint/prefer-for-of */
14
- /* eslint-disable no-await-in-loop */
15
- /* eslint-disable @typescript-eslint/no-explicit-any */
16
- /* eslint-disable no-console */
17
- const fs_1 = require("fs");
39
+ const node_fs_1 = require("node:fs");
40
+ const path = __importStar(require("node:path"));
18
41
  const sf_plugins_core_1 = require("@salesforce/sf-plugins-core");
19
42
  const core_1 = require("@salesforce/core");
43
+ const AdmZip = require("adm-zip");
44
+ const got_1 = __importDefault(require("got"));
20
45
  const logger_1 = require("../../../utils/logger");
21
46
  const constants_1 = require("../../../utils/constants");
22
47
  const authentication_1 = require("../../../utils/authentication");
48
+ const ids_1 = require("../../../utils/ids");
49
+ const pack_docconfigs_1 = require("../../../utils/pack-docconfigs");
50
+ const extract_templates_1 = require("../../../utils/extract-templates");
23
51
  core_1.Messages.importMessagesDirectory(__dirname);
24
52
  const messages = core_1.Messages.loadMessages('@pdfbutler/migration-cli', 'butler.pb.exportpack');
25
53
  class ButlerPbExportpack extends sf_plugins_core_1.SfCommand {
54
+ static summary = messages.getMessage('summary');
55
+ static description = messages.getMessage('description');
56
+ static examples = messages.getMessages('examples');
57
+ static flags = {
58
+ name: sf_plugins_core_1.Flags.string({
59
+ summary: messages.getMessage('flags.name.summary'),
60
+ description: messages.getMessage('flags.name.description'),
61
+ char: 'n',
62
+ required: false,
63
+ }),
64
+ pack: sf_plugins_core_1.Flags.string({
65
+ summary: messages.getMessage('flags.pack.summary'),
66
+ char: 'p',
67
+ required: true,
68
+ }),
69
+ target: sf_plugins_core_1.Flags.string({
70
+ summary: messages.getMessage('flags.target.summary'),
71
+ char: 't',
72
+ required: false,
73
+ }),
74
+ out: sf_plugins_core_1.Flags.string({
75
+ summary: messages.getMessage('flags.out.summary'),
76
+ // eslint-disable-next-line sf-plugin/dash-o
77
+ char: 'o',
78
+ required: true,
79
+ }),
80
+ logs: sf_plugins_core_1.Flags.boolean({
81
+ summary: messages.getMessage('flags.logs.summary'),
82
+ char: 'l',
83
+ }),
84
+ 'auth-env-var': sf_plugins_core_1.Flags.string({
85
+ summary: messages.getMessage('flags.auth-env-var.summary'),
86
+ char: 'a',
87
+ }),
88
+ endpoint: sf_plugins_core_1.Flags.url({
89
+ summary: messages.getMessage('flags.endpoint.summary'),
90
+ char: 'e',
91
+ }),
92
+ stage: sf_plugins_core_1.Flags.string({
93
+ summary: messages.getMessage('flags.stage.summary'),
94
+ char: 's',
95
+ required: false,
96
+ }),
97
+ unzip: sf_plugins_core_1.Flags.boolean({
98
+ summary: messages.getMessage('flags.unzip.summary'),
99
+ char: 'u',
100
+ }),
101
+ templates: sf_plugins_core_1.Flags.boolean({
102
+ summary: messages.getMessage('flags.templates.summary'),
103
+ char: 'm',
104
+ }),
105
+ docconfig: sf_plugins_core_1.Flags.string({
106
+ summary: messages.getMessage('flags.docconfig.summary'),
107
+ options: ['none', 'pack', 'lead', 'full'],
108
+ default: 'none',
109
+ required: false,
110
+ char: 'd',
111
+ }),
112
+ session: sf_plugins_core_1.Flags.string({
113
+ summary: messages.getMessage('flags.session.summary'),
114
+ }),
115
+ instance: sf_plugins_core_1.Flags.string({
116
+ summary: messages.getMessage('flags.instance.summary'),
117
+ }),
118
+ };
119
+ static isLogsActive = false;
120
+ static processedDocConfigIds = new Set();
121
+ static resolveExportDirectories(baseOutputDir) {
122
+ const normalizedBaseDir = path.resolve(baseOutputDir);
123
+ return {
124
+ packsSfdc: path.join(normalizedBaseDir, 'packs', 'sfdc'),
125
+ docConfigsRoot: path.join(normalizedBaseDir, 'docConfigs'),
126
+ docConfigsSfdc: path.join(normalizedBaseDir, 'docConfigs', 'sfdc'),
127
+ };
128
+ }
26
129
  static async exportPackData(connection, packId) {
27
130
  const exportUrl = `${constants_1.PATH.EXPORT_PACK}${packId}`;
28
131
  try {
@@ -34,7 +137,7 @@ class ButlerPbExportpack extends sf_plugins_core_1.SfCommand {
34
137
  if (this.isLogsActive) {
35
138
  const message = error instanceof Error ? error.message : String(error);
36
139
  if (message.includes(constants_1.ERROR.URL_NOT_FOUND)) {
37
- logger_1.Logger.error(`${constants_1.ERROR.URL_NOT_FOUND}. ${constants_1.ERROR.VERSION_TOO_LOW}`);
140
+ logger_1.Logger.error(constants_1.ERROR.URL_NOT_FOUND_VERSION_TOO_LOW);
38
141
  }
39
142
  if (message.includes(constants_1.ERROR.ID_NOT_EXIST)) {
40
143
  logger_1.Logger.error(constants_1.ERROR.PACK_NOT_EXIST.replace('[PACK_ID]', packId));
@@ -46,13 +149,10 @@ class ButlerPbExportpack extends sf_plugins_core_1.SfCommand {
46
149
  static async saveToFile(directory, filename, data) {
47
150
  try {
48
151
  logger_1.Logger.info(constants_1.MESSAGE.SAVING_TO_DIRECTORY, this.isLogsActive);
49
- const dirName = `./${directory}/sfdc`;
50
- logger_1.Logger.info(constants_1.MESSAGE.DIRECTORY_HIERARCHY.replace('[PATH]', dirName), this.isLogsActive);
51
- const filePath = `${dirName}/${filename}`;
52
- logger_1.Logger.info(constants_1.MESSAGE.FILE_PATH.replace('[PATH]', filePath), this.isLogsActive);
53
- await fs_1.promises.mkdir(dirName, { recursive: true });
54
- await fs_1.promises.writeFile(filePath, JSON.stringify(data, null, 2));
55
- logger_1.Logger.info(constants_1.MESSAGE.SUCCESS_EXPORT_TO.replace('[PATH]', filePath));
152
+ const filePath = path.join(directory, filename);
153
+ await node_fs_1.promises.mkdir(directory, { recursive: true });
154
+ await node_fs_1.promises.writeFile(filePath, JSON.stringify(data, null, 2));
155
+ logger_1.Logger.success(constants_1.MESSAGE.SUCCESS_EXPORT);
56
156
  return filePath;
57
157
  }
58
158
  catch (error) {
@@ -61,14 +161,158 @@ class ButlerPbExportpack extends sf_plugins_core_1.SfCommand {
61
161
  throw new Error(constants_1.ERROR.FAILED_TO_SAVE_FILE);
62
162
  }
63
163
  }
164
+ static async exportDocConfigData(connection, docConfigId) {
165
+ const exportUrl = `${constants_1.PATH.EXPORT_DOC_CONFIG}${docConfigId}`;
166
+ try {
167
+ logger_1.Logger.info(constants_1.MESSAGE.CALL_SERVICE);
168
+ return await connection.apex.get(exportUrl);
169
+ }
170
+ catch (error) {
171
+ if (this.isLogsActive) {
172
+ const message = error instanceof Error ? error.message : String(error);
173
+ if (message.includes(constants_1.ERROR.URL_NOT_FOUND)) {
174
+ logger_1.Logger.error(constants_1.ERROR.URL_NOT_FOUND_VERSION_TOO_LOW);
175
+ }
176
+ if (message.includes(constants_1.ERROR.ID_NOT_EXIST)) {
177
+ logger_1.Logger.error(constants_1.ERROR.DOC_CONFIG_NOT_EXIST.replace('[DOC_CONFIG_ID]', docConfigId));
178
+ }
179
+ }
180
+ return null;
181
+ }
182
+ }
183
+ static async saveDocConfigToFile(directory, docConfigId, data) {
184
+ try {
185
+ logger_1.Logger.info(constants_1.MESSAGE.SAVING_TO_DIRECTORY, this.isLogsActive);
186
+ const filePath = path.join(directory, `${docConfigId}.json`);
187
+ await node_fs_1.promises.mkdir(directory, { recursive: true });
188
+ await node_fs_1.promises.writeFile(filePath, JSON.stringify(data, null, 2));
189
+ logger_1.Logger.success(constants_1.MESSAGE.SUCCESS_EXPORT);
190
+ }
191
+ catch (error) {
192
+ const message = error instanceof Error ? error.message : String(error);
193
+ logger_1.Logger.error(constants_1.ERROR.SAVING.replace('[MESSAGE]', message));
194
+ throw new Error(constants_1.ERROR.FAILED_TO_SAVE_FILE);
195
+ }
196
+ }
197
+ static async saveDocConfigZip(outputDir, docConfigId, zip, sfdcData) {
198
+ const zipToExport = new AdmZip();
199
+ for (const entry of zip.getEntries()) {
200
+ const entryData = zip.readFile(entry);
201
+ if (entryData != null) {
202
+ zipToExport.addFile(entry.entryName, entryData);
203
+ }
204
+ }
205
+ zipToExport.addFile('sfdc/docconfig.json', Buffer.from(JSON.stringify(sfdcData, null, 2)));
206
+ await node_fs_1.promises.writeFile(path.join(outputDir, `${docConfigId}.zip`), new Uint8Array(zipToExport.toBuffer()));
207
+ logger_1.Logger.success(constants_1.MESSAGE.ARCHIVE_RECORDED);
208
+ }
209
+ static saveDocConfigUnzipped(outputDir, docConfigId, zip) {
210
+ const extractionPath = path.join(outputDir, docConfigId);
211
+ zip.extractAllTo(extractionPath, true);
212
+ logger_1.Logger.success(constants_1.MESSAGE.ARCHIVE_UNZIPPED, this.isLogsActive);
213
+ }
214
+ static async fetchBackendZip(docConfigId, flags) {
215
+ if (!flags.endpoint || !flags['auth-env-var'] || !flags.stage) {
216
+ return null;
217
+ }
218
+ const auth = flags['auth-env-var'];
219
+ const base64Auth = auth.includes(':') ? Buffer.from(auth, 'utf8').toString('base64') : auth;
220
+ const finalUrl = `${flags.endpoint.toString()}config/export-config/${flags.stage}/${docConfigId}`;
221
+ try {
222
+ const buffer = await (0, got_1.default)(finalUrl, {
223
+ headers: { Authorization: `Basic ${base64Auth}` },
224
+ }).buffer();
225
+ return new AdmZip(buffer);
226
+ }
227
+ catch (error) {
228
+ const message = error instanceof Error ? error.message : String(error);
229
+ logger_1.Logger.error(message);
230
+ logger_1.Logger.error(constants_1.MESSAGE.DOC_CONFIG_NO_BACKEND.replace('[VALUE]', docConfigId), this.isLogsActive);
231
+ return null;
232
+ }
233
+ }
234
+ static async collectTemplateIdsFromBackend(zip, outputDir, docConfigId) {
235
+ const tempExtractPath = path.join(outputDir, `.temp_${docConfigId}`);
236
+ zip.extractAllTo(tempExtractPath, true);
237
+ const templateIds = await (0, extract_templates_1.extractTemplateIds)(tempExtractPath);
238
+ await node_fs_1.promises.rm(tempExtractPath, { recursive: true, force: true });
239
+ return templateIds;
240
+ }
241
+ static async exportDocConfigsByMode(connection, docConfigsRoot, docConfigsSfdc, packData, mode, packId, flags) {
242
+ const shouldExportBackend = Boolean(flags.endpoint && flags['auth-env-var'] && flags.stage);
243
+ const shouldExtractTemplates = Boolean(flags.templates && shouldExportBackend);
244
+ if (mode !== 'none' && !shouldExportBackend && (flags.unzip || flags.templates)) {
245
+ logger_1.Logger.error(constants_1.ERROR.EXPORTPACK_DOC_CONFIG_FLAGS_REQUIRED);
246
+ return;
247
+ }
248
+ const initialDocConfigIds = (0, pack_docconfigs_1.getDocConfigIdsByMode)(packData, mode);
249
+ const docConfigIds = [...initialDocConfigIds];
250
+ if (docConfigIds.length === 0) {
251
+ logger_1.Logger.warn(constants_1.MESSAGE.NO_DOC_CONFIGS_IN_PACK.replace('[MODE]', mode).replace('[PACK]', packId));
252
+ return;
253
+ }
254
+ if (ButlerPbExportpack.isLogsActive) {
255
+ logger_1.Logger.info(constants_1.MESSAGE.DOC_CONFIGS_TO_EXPORT.replace('[DOC_CONFIGS]', docConfigIds.join(', ')));
256
+ }
257
+ const processQueue = async () => {
258
+ const docConfigId = docConfigIds.shift();
259
+ if (!docConfigId) {
260
+ return;
261
+ }
262
+ if (this.processedDocConfigIds.has(docConfigId)) {
263
+ await processQueue();
264
+ return;
265
+ }
266
+ logger_1.Logger.info(constants_1.MESSAGE.TRY_EXPORT_DOC_CONFIG.replace('[DOC_CONFIG]', docConfigId));
267
+ const docConfigData = await ButlerPbExportpack.exportDocConfigData(connection, docConfigId);
268
+ if (docConfigData == null) {
269
+ logger_1.Logger.error(constants_1.ERROR.DOC_CONFIG_NOT_EXIST.replace('[DOC_CONFIG_ID]', docConfigId));
270
+ this.processedDocConfigIds.add(docConfigId);
271
+ await processQueue();
272
+ return;
273
+ }
274
+ await ButlerPbExportpack.saveDocConfigToFile(docConfigsSfdc, docConfigId, docConfigData);
275
+ this.processedDocConfigIds.add(docConfigId);
276
+ if (!shouldExportBackend) {
277
+ await processQueue();
278
+ return;
279
+ }
280
+ const backendZip = await ButlerPbExportpack.fetchBackendZip(docConfigId, flags);
281
+ if (!backendZip) {
282
+ await processQueue();
283
+ return;
284
+ }
285
+ if (flags.unzip) {
286
+ ButlerPbExportpack.saveDocConfigUnzipped(docConfigsRoot, docConfigId, backendZip);
287
+ }
288
+ else {
289
+ await ButlerPbExportpack.saveDocConfigZip(docConfigsRoot, docConfigId, backendZip, docConfigData);
290
+ }
291
+ if (shouldExtractTemplates) {
292
+ const discoveredTemplateIds = await ButlerPbExportpack.collectTemplateIdsFromBackend(backendZip, docConfigsRoot, docConfigId);
293
+ const nextBatch = discoveredTemplateIds.filter((id) => !this.processedDocConfigIds.has(id));
294
+ if (nextBatch.length > 0 && ButlerPbExportpack.isLogsActive) {
295
+ logger_1.Logger.info(constants_1.MESSAGE.NEW_TEMPLATES_FOUND.replace('[VALUE]', nextBatch.length.toString()));
296
+ }
297
+ for (const templateId of nextBatch) {
298
+ docConfigIds.push(templateId);
299
+ }
300
+ }
301
+ await processQueue();
302
+ };
303
+ await processQueue();
304
+ }
64
305
  async run() {
65
- const { flags } = await this.parse(ButlerPbExportpack);
306
+ const { flags } = (await this.parse(ButlerPbExportpack));
66
307
  const username = flags.target;
67
308
  const session = flags.session;
68
309
  const instance = flags.instance;
69
310
  const packsIds = flags.pack;
70
311
  const outputDir = flags.out;
71
- ButlerPbExportpack.isLogsActive = flags.logs;
312
+ const directories = ButlerPbExportpack.resolveExportDirectories(outputDir);
313
+ const docConfigMode = flags.docconfig;
314
+ ButlerPbExportpack.isLogsActive = Boolean(flags.logs);
315
+ ButlerPbExportpack.processedDocConfigIds = new Set();
72
316
  if (outputDir.trim().length === 0) {
73
317
  logger_1.Logger.error(constants_1.ERROR.OUT_FLAG_REQUIRED);
74
318
  return { success: false };
@@ -76,60 +320,30 @@ class ButlerPbExportpack extends sf_plugins_core_1.SfCommand {
76
320
  if (ButlerPbExportpack.isLogsActive) {
77
321
  logger_1.Logger.info(constants_1.MESSAGE.USERNAME.replace('[USERNAME]', username));
78
322
  logger_1.Logger.info(constants_1.MESSAGE.PACKS_TO_EXPORT.replace('[PACKS]', packsIds));
79
- logger_1.Logger.info(constants_1.MESSAGE.FOLDER_TO_OUTPUT.replace('[FOLDER]', outputDir));
323
+ logger_1.Logger.info(constants_1.MESSAGE.DOC_CONFIG_EXPORT_MODE.replace('[MODE]', docConfigMode));
80
324
  }
81
325
  const connection = await (0, authentication_1.authenticate)(username, session, instance);
82
- for (const packId of packsIds.split(',')) {
326
+ await (0, ids_1.parseCommaSeparatedValues)(packsIds).reduce(async (previous, packId) => {
327
+ await previous;
83
328
  logger_1.Logger.info(constants_1.MESSAGE.TRY_EXPORT_PACK.replace('[PACK]', packId.trim()));
84
329
  const trimmedPackId = packId.trim();
85
330
  const outputFilename = `${trimmedPackId}.json`;
86
331
  const packData = await ButlerPbExportpack.exportPackData(connection, trimmedPackId);
87
332
  if (packData == null || packData.length < 1) {
88
333
  logger_1.Logger.error(constants_1.ERROR.PACK_NOT_EXIST.replace('[PACK_ID]', trimmedPackId));
89
- continue;
334
+ return;
90
335
  }
91
- await ButlerPbExportpack.saveToFile(outputDir, outputFilename, packData);
92
- }
336
+ const shouldExportPack = docConfigMode === 'none' || docConfigMode === 'full';
337
+ const shouldExportDocConfigs = docConfigMode !== 'none';
338
+ if (shouldExportPack) {
339
+ await ButlerPbExportpack.saveToFile(directories.packsSfdc, outputFilename, packData);
340
+ }
341
+ if (shouldExportDocConfigs) {
342
+ await ButlerPbExportpack.exportDocConfigsByMode(connection, directories.docConfigsRoot, directories.docConfigsSfdc, packData, docConfigMode, trimmedPackId, flags);
343
+ }
344
+ }, Promise.resolve());
93
345
  return { success: true };
94
346
  }
95
347
  }
96
- ButlerPbExportpack.summary = messages.getMessage('summary');
97
- ButlerPbExportpack.description = messages.getMessage('description');
98
- ButlerPbExportpack.examples = messages.getMessages('examples');
99
- ButlerPbExportpack.flags = {
100
- name: sf_plugins_core_1.Flags.string({
101
- summary: messages.getMessage('flags.name.summary'),
102
- description: messages.getMessage('flags.name.description'),
103
- char: 'n',
104
- required: false,
105
- }),
106
- pack: sf_plugins_core_1.Flags.string({
107
- summary: messages.getMessage('flags.pack.summary'),
108
- char: 'p',
109
- required: true,
110
- }),
111
- target: sf_plugins_core_1.Flags.string({
112
- summary: messages.getMessage('flags.target.summary'),
113
- char: 't',
114
- required: false,
115
- }),
116
- out: sf_plugins_core_1.Flags.string({
117
- summary: messages.getMessage('flags.out.summary'),
118
- // eslint-disable-next-line sf-plugin/dash-o
119
- char: 'o',
120
- required: true,
121
- }),
122
- logs: sf_plugins_core_1.Flags.boolean({
123
- summary: messages.getMessage('flags.logs.summary'),
124
- char: 'l',
125
- }),
126
- session: sf_plugins_core_1.Flags.string({
127
- summary: messages.getMessage('flags.session.summary'),
128
- }),
129
- instance: sf_plugins_core_1.Flags.string({
130
- summary: messages.getMessage('flags.instance.summary'),
131
- }),
132
- };
133
- ButlerPbExportpack.isLogsActive = false;
134
348
  exports.default = ButlerPbExportpack;
135
349
  //# sourceMappingURL=exportpack.js.map