The following script is intended to:
- show transactions only related to a given product ID
- for each transaction show the product description, customer name, customer email, amount
- write this data to a Google sheet

The script doesn't currently work.

index.ts
```
import Stripe from 'stripe';
import { google } from 'googleapis';
import dotenv from 'dotenv';
import fs from 'fs';
import { Command } from 'commander';

// Load environment
dotenv.config();

// Async main function with parameters
async function main(productId: string, sheetId: string) {
    try {
        // Environment validation
        if (!process.env.STRIPE_SECRET_KEY) throw new Error("Missing STRIPE_SECRET_KEY");
        if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) throw new Error("Missing credentials path");

        // Credentials check
        fs.accessSync(process.env.GOOGLE_APPLICATION_CREDENTIALS);

        console.log(`Fetching transactions for ${productId}...`);
        const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { apiVersion: '2023-10-16' });

        const product = await stripe.products.retrieve(productId);
        const transactions: TransactionData[] = [];

        const payments = await stripe.paymentIntents.list({ limit: 1 });
        for (const payment of payments.data) {
            transactions.push({
                productDescription: product.description || 'N/A',
                amount: (payment.amount_received / 100).toFixed(2),
                currency: payment.currency.toUpperCase(),
                customerName: null,
                customerEmail: payment.receipt_email || null,
                date: new Date(payment.created * 1000).toISOString()
            });
        }

        if (transactions.length > 0) {
            console.log(`Writing ${transactions.length} transactions to ${sheetId}...`);
            const auth = new google.auth.GoogleAuth({
                keyFile: process.env.GOOGLE_APPLICATION_CREDENTIALS,
                scopes: ['https://www.googleapis.com/auth/spreadsheets']
            });

            const client = await auth.getClient();
            const sheets = google.sheets({ version: 'v4', auth: client });

            await sheets.spreadsheets.values.update({
                spreadsheetId: sheetId,
                range: 'Sheet1!A1',
                valueInputOption: 'USER_ENTERED',
                requestBody: {
                    values: [
                        ['Product', 'Amount', 'Currency', 'Name', 'Email', 'Date'],
                        ...transactions.map(tx => Object.values(tx))
                    ]
                }
            });
        } else {
            console.log("No transactions found to write");
        }

        console.log("Process completed");
    } catch (error) {
        console.error("Error:", error);
        process.exit(1);
    }
}

// CLI setup
const program = new Command();
program
    .requiredOption('-p, --product <productId>', 'Stripe Product ID')
    .requiredOption('-s, --sheet <sheetId>', 'Google Spreadsheet ID')
    .parse(process.argv);

// Execute with CLI arguments
main(program.opts().product, program.opts().sheet)
    .catch(err => {
        console.error("Unhandled error:", err);
        process.exit(1);
    });
```

Your task is to:
1. Analyse what the script currently does
2. Identify the mistakes it has made
3. Outline the changes that should be made
4. Write a new version of the script
5. Add copious logging to the new version
6. Double check your work
7. Present a final version