kit icon indicating copy to clipboard operation
kit copied to clipboard

ScriptKit not giving error message and not doing anything when executing script

Open deerdear opened this issue 2 years ago • 6 comments

I wrote a script that should immediately schedule a call with someone, send calendar invites with google meet link and auto-join the link. I got it running without scriptkit, but when running it with scriptkit it fails noiselessly.

Configuration on google workspace shouldn't be the issue. Using a service account with full rights...

import "@johnlindquist/kit"
import { google } from "googleapis"
import { JWT } from "google-auth-library"

// get credentials for google service account through environment variables
let SA_EMAIL = await env("GOOGLE_SA_EMAIL")
let SA_KEY = await env("GOOGLE_SA_CREDS")

// Define the scopes and client
let jwtClient = new JWT({
    email: SA_EMAIL,
    key: SA_KEY,
    scopes: ['https://www.googleapis.com/auth/calendar'], // An array of auth scopes
    subject: '[email protected]' // user to impersonate
});


let calendar = google.calendar('v3');

function createEvent(auth, emails) {
  // Define the start and end times
  let startTime = new Date();
  let endTime = new Date();
  endTime.setMinutes(startTime.getMinutes() + 40);

  // Random number
  let randomToken = Math.random() * (10000000 - 100) + 100;

  // Define attendees
  let attendees = emails.map(email => ({email: email}));

  // Define the event
  let event = {
    summary: 'instameet',
    location: 'Online',
    description: 'A meeting created by a script',
    start: {
      dateTime: startTime,
      timeZone: 'Europe/Berlin',
    },
    end: {
      dateTime: endTime,
      timeZone: 'Europe/Berlin',
    },
    attendees: attendees,
    conferenceData: {
      createRequest: {
        requestId: randomToken.toString(),
        conferenceSolutionKey: {
          type: 'hangoutsMeet'
        }
      }
    },
  };

  // Call the Calendar API
  calendar.events.insert({
    auth: auth,
    calendarId: 'primary',
    resource: event,
    conferenceDataVersion: 1,
  }, (err, event) => {
    if (err) {
      console.log('There was an error contacting the Calendar service: ' + err);
      return;
    }
    console.log('Event created: %s', event.data.htmlLink);
    let meetLink = event.data.conferenceData.entryPoints[0].uri;
    import('open').then(openModule => {
    openModule.default(meetLink);
    });
});
}

jwtClient.authorize((err, tokens) => {
  if (err) {
    console.log(err);
    return;
  }
  // Create an event
  createEvent(jwtClient, ['[email protected]','[email protected]' ]);
});

deerdear avatar Jun 22 '23 14:06 deerdear

@deerdear I'm pushing a new build out tonight which will help with some errors not being surfaced. I'll ping you here when it's ready, it that doesn't help, we can debug together

johnlindquist avatar Jun 22 '23 14:06 johnlindquist

Could you give this build a try and see if any information surfaces?

https://github.com/johnlindquist/kitapp/releases/tag/v1.74.2

johnlindquist avatar Jun 23 '23 04:06 johnlindquist

I'm afraid nothing. In the log I just get this: [2023-06-23 10:31:13.465] [verbose] 📝 Submitting... [2023-06-23 10:31:13.472] [verbose] ➡ SET_SCRIPT [2023-06-23 10:31:13.472] [verbose] toProcess: SET_SCRIPT [2023-06-23 10:31:13.472] [verbose] setScript /Users/user/.kenv/scripts/meet.js [2023-06-23 10:31:13.472] [verbose] 📄 scriptPath changed: /Users/user/.kenv/scripts/meet.js [2023-06-23 10:31:13.818] [verbose] ➡ CONSOLE_LOG [2023-06-23 10:31:13.836] [info] DISCONNECT [2023-06-23 10:31:13.842] [info] EXIT { pid: 4468, code: 0 } [2023-06-23 10:31:13.843] [info] 4468: 🟡 exit 0. Prompt process: /Users/user/.kenv/scripts/meet.js [2023-06-23 10:31:13.843] [info] 💮 Stamping: { filePath: '/Users/user/.kenv/scripts/meet.js', runCount: 1, executionTime: 4547 } [2023-06-23 10:31:13.843] [info] 4468: 🛑 removed [2023-06-23 10:31:13.843] [verbose] 📄 scriptPath changed: [2023-06-23 10:31:13.843] [verbose] noScript: scriptPath changed: , prompt count: 0 [2023-06-23 10:31:13.843] [info] Attempt Hide: remove [2023-06-23 10:31:13.843] [verbose] Hiding because remove [2023-06-23 10:31:13.856] [verbose] Blur: accepted [2023-06-23 10:31:13.856] [info] Attempt Hide: Blur [2023-06-23 10:31:13.856] [verbose] Blurred by kit: off

And nothing happens :(

deerdear avatar Jun 23 '23 08:06 deerdear

Have you tried the old-fashioned "add a bunch more console.log statements to see how far it makes it"?

In a terminal, you can:

tail -f ~/.kenv/logs/meet.log

To get a live view of the logging.

johnlindquist avatar Jun 23 '23 13:06 johnlindquist

Yeah, I tried that, but unfortunately it seems like it's dropping out before even doing anything.

meet.log looks like: [2023-06-29 00:19:35.650] [info] 3456: 🟡 exit 0. Prompt process: /Users/user/.kenv/scripts/meet-with.js

[2023-06-29 00:19:35.650] [info] 💮 Stamping: { filePath: '/Users/user/.kenv/scripts/meet-with.js', runCount: 1, executionTime: 386451 }

[2023-06-29 00:19:35.650] [info] 3456: 🛑 removed

[2023-06-29 00:19:35.651] [info] Attempt Hide: remove

deerdear avatar Jun 28 '23 22:06 deerdear

@deerdear Hmm, other scripts work ok?

Are the "googleapis" and "google-auth-library" installed in your ~/.kenv/node_modules dir?

johnlindquist avatar Jun 28 '23 23:06 johnlindquist