opensearch-project / reporting-cli

Apache License 2.0
4 stars 13 forks source link

[FEATURE] nodejs package #36

Open llermaly opened 1 year ago

llermaly commented 1 year ago

Is your feature request related to a problem?

I would like to integrate the CLI to an existing nodejs backend , and instead of using something like the child_process module , or using the source code in javascript directly, would be nice to have a way to invoke the methods directly from nodejs just importing the reporting-cli package.

What solution would you like?

Allow the module to be imported in nodejs and executing calls, e.g:

const report = require("reporting-cli");

const createReport = async () => {
  const reportData = await report.create({
    from: "admin@page.com",
    to: "user@domain.com",
    smtp: {
      host: "smtp.gmail.com",
      port: 465,
      secure: true,
      username: "username",
      password: "password",
    },
    url: "https://www.google.com",
    auth: "basic",
    credentials: {
      username: "username",
      password: "password",
    },
    format: "pdf",
    fileName: "report.pdf",
    subject: "Your report",
    note: "Hello, attached see your report",
  });
  console.log(reportData);
};

createReport();

Is this something that can be done without you creating an additional package?

Thanks

anirudha commented 1 year ago

@rupal-bq how can we release this as a node module ? @llermaly does that solve your usecase? would you be willing to contribute ?

llermaly commented 1 year ago

@anirudha , yes, a node module would make it .

I have never built a package but I can contribute creating a draft based on the solution I'm using so you can go from there. Let me know how can I be useful

llermaly commented 1 year ago

It is possible to use it , see the attached snippet:

const report = require("@opensearch-project/reporting-cli");

const options = {
    url: "http://localhost:5601/goto/8fa30d307ea81f81a5edc692e189c297?security_tenant=private",
    auth: "basic",
    credentials: "admin:admin",
    transport: "smtp",
    smtphost: "smtp.gmail.com",
    smtpport: 465,
    smtpsecure: true,
    smtpusername: "gllermaly",
    smtppassword: "xxxxxxxxxxxxxxxxx",
    from: "test@test.com",
    to: "test@test.com" ,
    format: "pdf",
  };

const sendReport = async () => {
  await report.handler(options);
};

sendReport();

So looks like it is just about documenting it. Thougts? any objection on just invoking the hander without going through the CLI flow?

rupal-bq commented 1 year ago

@rupal-bq how can we release this as a node module ?

@anirudha will need to make some minor changes, test and release next version.

So looks like it is just about documenting it. Thougts? any objection on just invoking the hander without going through the CLI flow?

@llermaly handler function can be surely used for this purpose but earlier it was created to support scheduled reports with AWS Lambda and Lambda can only write to /tmp directory so the file path is hardcoded for handler function. https://github.com/opensearch-project/reporting-cli/blob/main/src/run.js#L13. If you used it as is, report will be downloaded in /tmp folder. This needs to be fixed before documenting about support as a nodejs package.

rupal-bq commented 1 year ago

Also, currently all logs are available only on console. For using this a nodejs package, i think we should return errors/success.