@inforge/migrations-tools-cli 1.2.1 → 1.2.2

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 (2) hide show
  1. package/dist/index.js +55 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -461,6 +461,11 @@ var FlowsHandler = class {
461
461
  };
462
462
 
463
463
  // src/core/metadata/triggers.ts
464
+ import * as fs3 from "fs/promises";
465
+ import * as path3 from "path";
466
+ import { exec } from "child_process";
467
+ import { promisify } from "util";
468
+ var execAsync = promisify(exec);
464
469
  var TriggersHandler = class {
465
470
  logger;
466
471
  constructor() {
@@ -508,26 +513,40 @@ var TriggersHandler = class {
508
513
  triggerNames,
509
514
  status
510
515
  });
516
+ const tempDir = path3.join(process.cwd(), ".trigger-deploy-temp");
511
517
  try {
512
- const updates = triggerNames.map((name) => ({
513
- fullName: name,
514
- status
515
- }));
516
- await this.logger.debug("Preparing Metadata API update", { updates });
517
- const results = await connection.metadata.update("ApexTrigger", updates);
518
- await this.logger.debug("Metadata API update results", {
519
- results: Array.isArray(results) ? results : [results]
520
- });
521
- const resultArray = Array.isArray(results) ? results : [results];
522
- const failures = resultArray.filter((r) => !r.success);
523
- if (failures.length > 0) {
524
- await this.logger.error("Some triggers failed to update", null, {
525
- failures,
526
- totalAttempted: resultArray.length
527
- });
528
- throw new Error(`Failed to update ${failures.length} trigger(s): ${JSON.stringify(failures)}`);
518
+ const triggersDir = path3.join(tempDir, "force-app", "main", "default", "triggers");
519
+ await fs3.mkdir(triggersDir, { recursive: true });
520
+ await this.logger.debug("Created temp deployment directory", { tempDir, triggersDir });
521
+ await this.logger.debug("Retrieving trigger source code");
522
+ for (const triggerName of triggerNames) {
523
+ try {
524
+ const retrieveCmd = `sf project retrieve start --metadata ApexTrigger:${triggerName} --target-org ${connection.getUsername()} --output-dir ${tempDir}`;
525
+ await this.logger.debug("Executing retrieve command", { command: retrieveCmd });
526
+ const { stdout: retrieveOut, stderr: retrieveErr } = await execAsync(retrieveCmd);
527
+ await this.logger.debug("Retrieve result", { stdout: retrieveOut, stderr: retrieveErr });
528
+ const metadataPath = path3.join(triggersDir, `${triggerName}.trigger-meta.xml`);
529
+ const existingMetadata = await fs3.readFile(metadataPath, "utf-8");
530
+ await this.logger.debug("Read existing metadata", { triggerName, metadata: existingMetadata });
531
+ const updatedMetadata = existingMetadata.replace(
532
+ /<status>.*?<\/status>/,
533
+ `<status>${status}</status>`
534
+ );
535
+ await fs3.writeFile(metadataPath, updatedMetadata, "utf-8");
536
+ await this.logger.debug("Updated metadata file", { triggerName, newStatus: status });
537
+ } catch (error) {
538
+ await this.logger.error(`Failed to retrieve trigger ${triggerName}`, error);
539
+ throw error;
540
+ }
529
541
  }
530
- await this.logger.info("Successfully updated trigger status", {
542
+ const deployCmd = `sf project deploy start --source-dir ${path3.join(tempDir, "force-app")} --target-org ${connection.getUsername()}`;
543
+ await this.logger.debug("Executing deploy command", { command: deployCmd });
544
+ const { stdout: deployOut, stderr: deployErr } = await execAsync(deployCmd);
545
+ await this.logger.debug("Deploy result", { stdout: deployOut, stderr: deployErr });
546
+ if (deployErr && !deployErr.includes("Deploy Succeeded")) {
547
+ throw new Error(`Deployment failed: ${deployErr}`);
548
+ }
549
+ await this.logger.info("Successfully updated trigger status via SF CLI deployment", {
531
550
  triggerCount: triggerNames.length,
532
551
  status
533
552
  });
@@ -537,6 +556,13 @@ var TriggersHandler = class {
537
556
  status
538
557
  });
539
558
  throw error;
559
+ } finally {
560
+ try {
561
+ await fs3.rm(tempDir, { recursive: true, force: true });
562
+ await this.logger.debug("Cleaned up temp directory", { tempDir });
563
+ } catch (cleanupError) {
564
+ await this.logger.error("Failed to cleanup temp directory", cleanupError, { tempDir });
565
+ }
540
566
  }
541
567
  }
542
568
  };
@@ -826,7 +852,7 @@ ${managed.length} managed package ${itemType} cannot be deactivated
826
852
  };
827
853
 
828
854
  // src/commands/restore.ts
829
- import * as path3 from "path";
855
+ import * as path4 from "path";
830
856
  var RestoreCommand = class {
831
857
  sfClient;
832
858
  backupManager;
@@ -858,7 +884,7 @@ var RestoreCommand = class {
858
884
  const backupOptions = await Promise.all(
859
885
  backups.map(async (backupPath) => {
860
886
  const backup2 = await this.backupManager.load(backupPath);
861
- const filename = path3.basename(backupPath, ".json");
887
+ const filename = path4.basename(backupPath, ".json");
862
888
  const status = backup2.restoredAt ? `restored on ${backup2.restoredAt.split("T")[0]}` : "not restored";
863
889
  const opType = backup2.operationType === "individual" ? "Individual changes" : "Bulk deactivate";
864
890
  const itemCount = `${backup2.items.length} ${backup2.type === "validation-rules" ? "rules" : backup2.type}`;
@@ -1358,8 +1384,8 @@ var AutomationsCommand = class {
1358
1384
  };
1359
1385
 
1360
1386
  // src/commands/backups.ts
1361
- import * as fs3 from "fs/promises";
1362
- import * as path4 from "path";
1387
+ import * as fs4 from "fs/promises";
1388
+ import * as path5 from "path";
1363
1389
  var BackupsCommand = class {
1364
1390
  backupManager;
1365
1391
  prompts;
@@ -1390,7 +1416,7 @@ var BackupsCommand = class {
1390
1416
  async viewBackups() {
1391
1417
  const backupDir = ".backups";
1392
1418
  try {
1393
- const orgs = await fs3.readdir(backupDir);
1419
+ const orgs = await fs4.readdir(backupDir);
1394
1420
  if (orgs.length === 0) {
1395
1421
  this.prompts.warning("No backups found.");
1396
1422
  return;
@@ -1399,14 +1425,14 @@ var BackupsCommand = class {
1399
1425
  for (const org of orgs) {
1400
1426
  message += `${org}
1401
1427
  `;
1402
- const orgPath = path4.join(backupDir, org);
1403
- const objects = await fs3.readdir(orgPath);
1428
+ const orgPath = path5.join(backupDir, org);
1429
+ const objects = await fs4.readdir(orgPath);
1404
1430
  for (const object of objects) {
1405
- const objectPath = path4.join(orgPath, object);
1406
- const types = await fs3.readdir(objectPath);
1431
+ const objectPath = path5.join(orgPath, object);
1432
+ const types = await fs4.readdir(objectPath);
1407
1433
  for (const type of types) {
1408
- const typePath = path4.join(objectPath, type);
1409
- const files = await fs3.readdir(typePath);
1434
+ const typePath = path5.join(objectPath, type);
1435
+ const files = await fs4.readdir(typePath);
1410
1436
  message += ` ${object} > ${type} (${files.length} backup(s))
1411
1437
  `;
1412
1438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inforge/migrations-tools-cli",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Inforge's interactive CLI for side-effect-free Salesforce data operations by managing automation",
5
5
  "main": "index.js",
6
6
  "type": "module",