@inforge/migrations-tools-cli 1.2.1 → 1.2.3

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 +72 -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,57 @@ 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
+ const sfdxProjectJson = {
521
+ packageDirectories: [
522
+ {
523
+ path: "force-app",
524
+ default: true
525
+ }
526
+ ],
527
+ name: "temp-trigger-deployment",
528
+ namespace: "",
529
+ sfdcLoginUrl: "https://login.salesforce.com",
530
+ sourceApiVersion: "60.0"
531
+ };
532
+ await fs3.writeFile(
533
+ path3.join(tempDir, "sfdx-project.json"),
534
+ JSON.stringify(sfdxProjectJson, null, 2),
535
+ "utf-8"
536
+ );
537
+ await this.logger.debug("Created temp deployment directory with SFDX project", { tempDir, triggersDir });
538
+ await this.logger.debug("Retrieving trigger source code");
539
+ for (const triggerName of triggerNames) {
540
+ try {
541
+ const retrieveCmd = `sf project retrieve start --metadata ApexTrigger:${triggerName} --target-org ${connection.getUsername()}`;
542
+ await this.logger.debug("Executing retrieve command", { command: retrieveCmd, cwd: tempDir });
543
+ const { stdout: retrieveOut, stderr: retrieveErr } = await execAsync(retrieveCmd, { cwd: tempDir });
544
+ await this.logger.debug("Retrieve result", { stdout: retrieveOut, stderr: retrieveErr });
545
+ const metadataPath = path3.join(triggersDir, `${triggerName}.trigger-meta.xml`);
546
+ const existingMetadata = await fs3.readFile(metadataPath, "utf-8");
547
+ await this.logger.debug("Read existing metadata", { triggerName, metadata: existingMetadata });
548
+ const updatedMetadata = existingMetadata.replace(
549
+ /<status>.*?<\/status>/,
550
+ `<status>${status}</status>`
551
+ );
552
+ await fs3.writeFile(metadataPath, updatedMetadata, "utf-8");
553
+ await this.logger.debug("Updated metadata file", { triggerName, newStatus: status });
554
+ } catch (error) {
555
+ await this.logger.error(`Failed to retrieve trigger ${triggerName}`, error);
556
+ throw error;
557
+ }
558
+ }
559
+ const deployCmd = `sf project deploy start --source-dir force-app --target-org ${connection.getUsername()}`;
560
+ await this.logger.debug("Executing deploy command", { command: deployCmd, cwd: tempDir });
561
+ const { stdout: deployOut, stderr: deployErr } = await execAsync(deployCmd, { cwd: tempDir });
562
+ await this.logger.debug("Deploy result", { stdout: deployOut, stderr: deployErr });
563
+ if (deployErr && !deployErr.includes("Deploy Succeeded")) {
564
+ throw new Error(`Deployment failed: ${deployErr}`);
529
565
  }
530
- await this.logger.info("Successfully updated trigger status", {
566
+ await this.logger.info("Successfully updated trigger status via SF CLI deployment", {
531
567
  triggerCount: triggerNames.length,
532
568
  status
533
569
  });
@@ -537,6 +573,13 @@ var TriggersHandler = class {
537
573
  status
538
574
  });
539
575
  throw error;
576
+ } finally {
577
+ try {
578
+ await fs3.rm(tempDir, { recursive: true, force: true });
579
+ await this.logger.debug("Cleaned up temp directory", { tempDir });
580
+ } catch (cleanupError) {
581
+ await this.logger.error("Failed to cleanup temp directory", cleanupError, { tempDir });
582
+ }
540
583
  }
541
584
  }
542
585
  };
@@ -826,7 +869,7 @@ ${managed.length} managed package ${itemType} cannot be deactivated
826
869
  };
827
870
 
828
871
  // src/commands/restore.ts
829
- import * as path3 from "path";
872
+ import * as path4 from "path";
830
873
  var RestoreCommand = class {
831
874
  sfClient;
832
875
  backupManager;
@@ -858,7 +901,7 @@ var RestoreCommand = class {
858
901
  const backupOptions = await Promise.all(
859
902
  backups.map(async (backupPath) => {
860
903
  const backup2 = await this.backupManager.load(backupPath);
861
- const filename = path3.basename(backupPath, ".json");
904
+ const filename = path4.basename(backupPath, ".json");
862
905
  const status = backup2.restoredAt ? `restored on ${backup2.restoredAt.split("T")[0]}` : "not restored";
863
906
  const opType = backup2.operationType === "individual" ? "Individual changes" : "Bulk deactivate";
864
907
  const itemCount = `${backup2.items.length} ${backup2.type === "validation-rules" ? "rules" : backup2.type}`;
@@ -1358,8 +1401,8 @@ var AutomationsCommand = class {
1358
1401
  };
1359
1402
 
1360
1403
  // src/commands/backups.ts
1361
- import * as fs3 from "fs/promises";
1362
- import * as path4 from "path";
1404
+ import * as fs4 from "fs/promises";
1405
+ import * as path5 from "path";
1363
1406
  var BackupsCommand = class {
1364
1407
  backupManager;
1365
1408
  prompts;
@@ -1390,7 +1433,7 @@ var BackupsCommand = class {
1390
1433
  async viewBackups() {
1391
1434
  const backupDir = ".backups";
1392
1435
  try {
1393
- const orgs = await fs3.readdir(backupDir);
1436
+ const orgs = await fs4.readdir(backupDir);
1394
1437
  if (orgs.length === 0) {
1395
1438
  this.prompts.warning("No backups found.");
1396
1439
  return;
@@ -1399,14 +1442,14 @@ var BackupsCommand = class {
1399
1442
  for (const org of orgs) {
1400
1443
  message += `${org}
1401
1444
  `;
1402
- const orgPath = path4.join(backupDir, org);
1403
- const objects = await fs3.readdir(orgPath);
1445
+ const orgPath = path5.join(backupDir, org);
1446
+ const objects = await fs4.readdir(orgPath);
1404
1447
  for (const object of objects) {
1405
- const objectPath = path4.join(orgPath, object);
1406
- const types = await fs3.readdir(objectPath);
1448
+ const objectPath = path5.join(orgPath, object);
1449
+ const types = await fs4.readdir(objectPath);
1407
1450
  for (const type of types) {
1408
- const typePath = path4.join(objectPath, type);
1409
- const files = await fs3.readdir(typePath);
1451
+ const typePath = path5.join(objectPath, type);
1452
+ const files = await fs4.readdir(typePath);
1410
1453
  message += ` ${object} > ${type} (${files.length} backup(s))
1411
1454
  `;
1412
1455
  }
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.3",
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",