do you see something to improve on this code?

import {
  ComputeOptimizerClient,
  GetEC2InstanceRecommendationsCommand,
} from "@aws-sdk/client-compute-optimizer";
import {
  OrganizationsClient,
  ListAccountsCommand,
} from "@aws-sdk/client-organizations";

import dotenv from "dotenv";
import { writeExcelFile, createPriceListExcel } from "./helperExcel.mjs";
import { getSecretValue } from "./helper.mjs";
import { getAssumedRoleCredentials } from "./assume_master.mjs";
import { HttpsProxyAgent } from "hpagent";

const BLACK_LIST_FAMILIES = JSON.parse(process.env.BLACK_LIST_FAMILIES);
const WHITE_LIST_FAMILIES = JSON.parse(process.env.WHITE_LIST_FAMILIES);
const BUCKET_NAME_SHARED = process.env.BUCKET_NAME_SHARED;
const STS_VPCE = process.env.STS_VPCE;
const HTTP_PROXY = process.env.HTTP_PROXY;
const SECRET_NAME_FINOPS_AUTH = process.env.SECRET_NAME_FINOPS_AUTH;

dotenv.config();

let finops_auth = await getSecretValue(
  process.env.AWS_REGION,
  SECRET_NAME_FINOPS_AUTH
); // Format of secret value username:pass

let master_credentials = await getAssumedRoleCredentials(
  process.env.AWS_REGION,
  STS_VPCE,
  "arn:aws:iam::198979247696:role/finops-cost-report",
  "LambdaCrossAccountSession"
);

let useProxy = null;
if (HTTP_PROXY) {
  let proxy_auth = finops_auth["proxy_auth"]; // Format of secret value username:pass

  const agent = new HttpsProxyAgent({
    proxy: "http://" + proxy_auth + "@" + HTTP_PROXY,
  });

  useProxy = {
    requestHandler: { httpAgent: agent, httpsAgent: agent },
  };
}

const organizationsClient = new OrganizationsClient({
  region: process.env.AWS_REGION,
  ...useProxy,
  credentials: {
    accessKeyId: master_credentials.AccessKeyId,
    secretAccessKey: master_credentials.SecretAccessKey,
    sessionToken: master_credentials.SessionToken,
  },
});

const client = new ComputeOptimizerClient({
  region: process.env.AWS_REGION,
  ...useProxy,
  credentials: {
    accessKeyId: master_credentials.AccessKeyId,
    secretAccessKey: master_credentials.SecretAccessKey,
    sessionToken: master_credentials.SessionToken,
  },
});

async function getEC2InstanceRecommendations(accountIds) {
  const recommendations = [];
  for (const accountId of accountIds) {
    let nextToken;

    do {
      const commandParams = {
        accountIds: [accountId],
        nextToken,
        recommendationPreferences: {
          cpuVendorArchitectures: ["AWS_ARM64", "CURRENT"],
        },
      };
      const command = new GetEC2InstanceRecommendationsCommand(commandParams);
      const response = await client.send(command);
      recommendations.push(...response.instanceRecommendations);
      nextToken = response.nextToken;
    } while (nextToken);
  }

  const transformedData = recommendations.flatMap((item) => {
    return item.recommendationOptions
      .filter((rec) => item.currentInstanceType !== rec.instanceType)
      .map((rec) => {
        // console.log ("recommendations",rec.platformDifferences)
        const appNameTag = item.tags.find((tag) => tag.key === "APP:NAME");
        const appNameValue = appNameTag ? appNameTag.value : null;

        const ownerITTag = item.tags.find((tag) => tag.key === "OWNER:IT");
        const ownerITValue = ownerITTag ? ownerITTag.value : null;

        const envTag = item.tags.find((tag) => tag.key === "ENV:DETAIL");
        const envValue = envTag ? envTag.value : null;

        const blacklistMatch = BLACK_LIST_FAMILIES.find(
          (family) => family === rec.instanceType.split(".")[0]
        );
        const whitelistMatch = WHITE_LIST_FAMILIES.find(
          (family) => family === rec.instanceType.split(".")[0]
        );
        const monetaRecommendation = blacklistMatch
          ? "Blacklist"
          : whitelistMatch
          ? "Whitelist"
          : null;

        return {
          col1: item.accountId,
          col2: item.instanceArn.split("/")[1],
          col3: item.instanceName,
          col4: item.currentPerformanceRisk,
          col5: rec.performanceRisk,
          col6: rec.migrationEffort,
          col7: item.currentInstanceType,
          col8: rec.instanceType,
          col9: rec.projectedUtilizationMetrics,
          col10: rec.rank,
          col11: rec.savingsOpportunityAfterDiscounts
            ? rec.savingsOpportunityAfterDiscounts.estimatedMonthlySavings.value
            : "",
          col12: monetaRecommendation,
          col13: rec.platformDifferences,
          col15: appNameValue,
          col16: ownerITValue,
          col17: envValue,
        };
      });
  });

  let workbook = await createPriceListExcel(transformedData);
  await writeExcelFile(workbook, AWS_REGION, BUCKET_NAME_SHARED);

  return transformedData;
}

async function getRecommendations() {
  try {
    const accountIds = await getAllAccountIds();
    const recommendations = await getEC2InstanceRecommendations(accountIds);
    return recommendations;
  } catch (error) {
    console.error("Error:", error);
    throw error;
  }
}

async function getAllAccountIds() {
  let accounts = [];
  let nextToken;

  do {
    const command = new ListAccountsCommand({ NextToken: nextToken });
    const response = await organizationsClient.send(command);

    accounts.push(...response.Accounts.map((account) => account.Id)); // Collect account IDs
    nextToken = response.NextToken; // Handle pagination
  } while (nextToken);

  return accounts;
}

export const handler = async () => {
  let response = {};
  try {
    let result = await getRecommendations();
    response = {
      statusCode: 200,
      body: result,
    };
  } catch (e) {
    response = {
      statusCode: 500,
      body: e.toString(),
    };
  }
  return response;
};