@inforge/migrations-tools-cli 1.2.0 → 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 +54 -47
  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,45 +513,40 @@ var TriggersHandler = class {
508
513
  triggerNames,
509
514
  status
510
515
  });
511
- const query = `
512
- SELECT Id, Name
513
- FROM ApexTrigger
514
- WHERE Name IN (${triggerNames.map((n) => `'${n}'`).join(", ")})
515
- `;
516
- await this.logger.debug("Executing Tooling API query", { query });
516
+ const tempDir = path3.join(process.cwd(), ".trigger-deploy-temp");
517
517
  try {
518
- const result = await connection.tooling.query(query);
519
- await this.logger.debug("Query result", {
520
- recordCount: result.records.length,
521
- records: result.records
522
- });
523
- if (result.records.length === 0) {
524
- await this.logger.error("No triggers found with specified names", null, {
525
- triggerNames,
526
- query
527
- });
528
- throw new Error("No triggers found with the specified names");
529
- }
530
- const updates = result.records.map((trigger) => ({
531
- Id: trigger.Id,
532
- Status: status
533
- }));
534
- await this.logger.debug("Preparing Tooling API update", { updates });
535
- const results = await connection.tooling.update("ApexTrigger", updates);
536
- await this.logger.debug("Tooling API update results", {
537
- results: Array.isArray(results) ? results : [results]
538
- });
539
- if (Array.isArray(results)) {
540
- const failures = results.filter((r) => !r.success);
541
- if (failures.length > 0) {
542
- await this.logger.error("Some triggers failed to update", null, {
543
- failures,
544
- totalAttempted: results.length
545
- });
546
- 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;
547
540
  }
548
541
  }
549
- 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", {
550
550
  triggerCount: triggerNames.length,
551
551
  status
552
552
  });
@@ -556,6 +556,13 @@ var TriggersHandler = class {
556
556
  status
557
557
  });
558
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
+ }
559
566
  }
560
567
  }
561
568
  };
@@ -845,7 +852,7 @@ ${managed.length} managed package ${itemType} cannot be deactivated
845
852
  };
846
853
 
847
854
  // src/commands/restore.ts
848
- import * as path3 from "path";
855
+ import * as path4 from "path";
849
856
  var RestoreCommand = class {
850
857
  sfClient;
851
858
  backupManager;
@@ -877,7 +884,7 @@ var RestoreCommand = class {
877
884
  const backupOptions = await Promise.all(
878
885
  backups.map(async (backupPath) => {
879
886
  const backup2 = await this.backupManager.load(backupPath);
880
- const filename = path3.basename(backupPath, ".json");
887
+ const filename = path4.basename(backupPath, ".json");
881
888
  const status = backup2.restoredAt ? `restored on ${backup2.restoredAt.split("T")[0]}` : "not restored";
882
889
  const opType = backup2.operationType === "individual" ? "Individual changes" : "Bulk deactivate";
883
890
  const itemCount = `${backup2.items.length} ${backup2.type === "validation-rules" ? "rules" : backup2.type}`;
@@ -1377,8 +1384,8 @@ var AutomationsCommand = class {
1377
1384
  };
1378
1385
 
1379
1386
  // src/commands/backups.ts
1380
- import * as fs3 from "fs/promises";
1381
- import * as path4 from "path";
1387
+ import * as fs4 from "fs/promises";
1388
+ import * as path5 from "path";
1382
1389
  var BackupsCommand = class {
1383
1390
  backupManager;
1384
1391
  prompts;
@@ -1409,7 +1416,7 @@ var BackupsCommand = class {
1409
1416
  async viewBackups() {
1410
1417
  const backupDir = ".backups";
1411
1418
  try {
1412
- const orgs = await fs3.readdir(backupDir);
1419
+ const orgs = await fs4.readdir(backupDir);
1413
1420
  if (orgs.length === 0) {
1414
1421
  this.prompts.warning("No backups found.");
1415
1422
  return;
@@ -1418,14 +1425,14 @@ var BackupsCommand = class {
1418
1425
  for (const org of orgs) {
1419
1426
  message += `${org}
1420
1427
  `;
1421
- const orgPath = path4.join(backupDir, org);
1422
- const objects = await fs3.readdir(orgPath);
1428
+ const orgPath = path5.join(backupDir, org);
1429
+ const objects = await fs4.readdir(orgPath);
1423
1430
  for (const object of objects) {
1424
- const objectPath = path4.join(orgPath, object);
1425
- const types = await fs3.readdir(objectPath);
1431
+ const objectPath = path5.join(orgPath, object);
1432
+ const types = await fs4.readdir(objectPath);
1426
1433
  for (const type of types) {
1427
- const typePath = path4.join(objectPath, type);
1428
- const files = await fs3.readdir(typePath);
1434
+ const typePath = path5.join(objectPath, type);
1435
+ const files = await fs4.readdir(typePath);
1429
1436
  message += ` ${object} > ${type} (${files.length} backup(s))
1430
1437
  `;
1431
1438
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inforge/migrations-tools-cli",
3
- "version": "1.2.0",
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",