Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request.scheduledPlan = {
title: "Hello attachment",
url: "https://mycompany.looker.com/look/1",
}
request.formParams = {
to: "test@example.com",
}
request.attachment = {dataJSON: {
fields: [{name: "coolfield", tags: ["looker_dashboard_url"]}],
data: [
{coolfield: {value: "/dashboards/1?myfield=Yes"}},
],
}}
const url = "https://mycompany.looker.com/dashboards/1?myfield=Yes"
/* tslint:disable max-line-length */
const msg = new helpers.classes.Mail({
to: request.formParams.to!,
subject: request.scheduledPlan.title!,
from: "Looker ",
text: `View this data in Looker. ${url}\nResults are attached.`,
html: `<p>View this data in Looker.</p><p><a href="${url}">${request.scheduledPlan.title!} 0</a></p><p>Results are attached.</p>`,
})
msg.addAttachment({
content: "pdf content",
filename: sanitizeFilename("Hello attachment_0.pdf"),
type: "application/pdf",
})
return expectLookerAPIActionMatch(request, "/dashboards/1?myfield=Yes", msg)
})
it("sends right body to filename and address", () => {
const request = new Hub.ActionRequest()
request.scheduledPlan = {
title: "Hello attachment",
url: "https://mycompany.looker.com/look/1",
}
request.formParams = {
to: "test@example.com",
}
request.attachment = {dataBuffer: Buffer.from("1,2,3,4", "utf8")}
const msg = new helpers.classes.Mail({
to: request.formParams.to,
subject: request.scheduledPlan.title as string,
from: "Looker ",
text: `View this data in Looker. ${request.scheduledPlan.url}\n Results are attached.`,
html: `<p><a href="${request.scheduledPlan.url}">View this data in Looker.</a></p><p>Results are attached.</p>`,
attachments: [{
content: request.attachment.dataBuffer!.toString(request.attachment.encoding),
filename: stubFilename,
}],
})
return expectSendGridMatch(request, msg)
})
it("sends right params for cell", async () => {
const request = new D.ActionRequest()
request.type = "cell"
request.params = {
base_url: "https://mycompany.looker.com:19999/api/3.0",
value: "/dashboards/1?myfield=Yes",
}
request.scheduledPlan = {
title: "Hello attachment",
url: "https://mycompany.looker.com/look/1",
}
request.formParams = {
to: "test@example.com",
}
const url = "https://mycompany.looker.com/dashboards/1?myfield=Yes"
const msg = new helpers.classes.Mail({
to: request.formParams.to!,
subject: request.scheduledPlan.title!,
from: "Looker ",
text: `View this data in Looker. ${url}\nResults are attached.`,
html: `<p>View this data in Looker.</p><p><a href="${url}">${request.scheduledPlan.title!} 0</a></p><p>Results are attached.</p>`,
})
msg.addAttachment({
content: "pdf content",
filename: sanitizeFilename("Hello attachment_0.pdf"),
type: "application/pdf",
})
return expectLookerAPIActionMatch(request, "/dashboards/1?myfield=Yes", msg)
})
it("sends with right subject if specified", () => {
const request = new Hub.ActionRequest()
request.scheduledPlan = {
title: "Hello attachment",
url: "https://mycompany.looker.com/look/1",
}
request.formParams = {
to: "test@example.com",
filename: "mywackyfilename",
subject: "mysubject",
}
request.attachment = { dataBuffer: Buffer.from("1,2,3,4", "utf8") }
const msg = new helpers.classes.Mail({
to: request.formParams.to,
subject: request.formParams.subject,
from: "Looker ",
text: `View this data in Looker. ${request.scheduledPlan.url}\n Results are attached.`,
html: `<p><a href="${request.scheduledPlan.url}">View this data in Looker.</a></p><p>Results are attached.</p>`,
attachments: [{
content: request.attachment.dataBuffer!.toString(request.attachment.encoding),
filename: request.formParams.filename!,
}],
})
return expectSendGridMatch(request, msg)
})
import * as helpers from "@sendgrid/helpers";
new helpers.classes.Attachment({
content: "",
filename: "test.txt",
type: "text/plain"
});
new helpers.classes.EmailAddress("someone@example.org");
new helpers.classes.EmailAddress({ name: "Some One", email: "someone@example.org" });
new helpers.classes.Personalization({
to: "someone@example.org",
subject: "Hello Some One",
dynamicTemplateData: {
translations: {
hello: "Привет!"
},
count: 1
import * as helpers from "@sendgrid/helpers";
new helpers.classes.Attachment({
content: "",
filename: "test.txt",
type: "text/plain"
});
new helpers.classes.EmailAddress("someone@example.org");
new helpers.classes.EmailAddress({ name: "Some One", email: "someone@example.org" });
new helpers.classes.Personalization({
to: "someone@example.org",
subject: "Hello Some One",
dynamicTemplateData: {
translations: {
hello: "Привет!"
},
count: 1
}
});
new helpers.classes.Mail({
to: "someone@example.org",
from: "someone@example.org",
async execute(request: Hub.ActionRequest) {
if (!request.attachment || !request.attachment.dataBuffer) {
throw "Couldn't get data from attachment."
}
if (!request.formParams.to) {
throw "Needs a valid email address."
}
const filename = request.formParams.filename || request.suggestedFilename() as string
const plan = request.scheduledPlan
const subject = request.formParams.subject || (plan && plan.title ? plan.title : "Looker")
const from = request.formParams.from ? request.formParams.from : "Looker "
const msg = new helpers.classes.Mail({
to: request.formParams.to,
subject,
from,
text: plan && plan.url ?
`View this data in Looker. ${plan.url}\n Results are attached.`
:
"Results are attached.",
html: plan && plan.url ?
`<p><a href="${plan.url}">View this data in Looker.</a></p><p>Results are attached.</p>`
:
"Results are attached.",
attachments: [{
content: request.attachment.dataBuffer.toString(request.attachment.encoding),
filename,
}],
})
const parsedLookerUrl = URL.parse(lookerUrl)
if (!parsedLookerUrl.pathname) {
throw `Malformed ${TAG} URL`
}
parsedUrl.port = ""
parsedUrl.pathname = parsedLookerUrl.pathname
parsedUrl.search = parsedLookerUrl.search || ""
return parsedUrl.href
})
const displayUrlsText = displayUrls.map((lookerUrl) => (`${lookerUrl}\n`)).join("")
const displayUrlsHTML = displayUrls.map((lookerUrl, i) => (
`<p><a href="${lookerUrl}">${subject} ${i}</a></p>`
)).join("")
const msg = new helpers.classes.Mail({
to: req.formParams.to!,
subject,
from,
text: `View this data in Looker. ${displayUrlsText}Results are attached.`,
html: `<p>View this data in Looker.</p>${displayUrlsHTML}<p>Results are attached.</p>`,
})
await Promise.all(lookerUrls.map(async (lookerUrl, i) => {
const pdf = await this.generatePDFDashboard(client, lookerUrl, req.formParams.format)
msg.addAttachment({
content: pdf.toString("base64"),
filename: sanitizeFilename(`${subject}_${i}.pdf`),
type: "application/pdf",
})
}))
let response