Standarizing Sendgrid client usage

pull/5501/head
Leo Giovanetti 2022-11-15 16:21:29 -03:00
parent fc1c50125a
commit 749d0d9bb9
2 changed files with 3 additions and 8 deletions

View File

@ -79,9 +79,6 @@ plugins.push(withAxiom);
/** @type {import("next").NextConfig} */ /** @type {import("next").NextConfig} */
const nextConfig = { const nextConfig = {
experimental: {
esmExternals: false,
},
i18n, i18n,
/* We already do type check on GH actions */ /* We already do type check on GH actions */
typescript: { typescript: {

View File

@ -1,4 +1,4 @@
import sendgrid from "@sendgrid/client"; import client from "@sendgrid/client";
import { ClientRequest } from "@sendgrid/client/src/request"; import { ClientRequest } from "@sendgrid/client/src/request";
import { ClientResponse } from "@sendgrid/client/src/response"; import { ClientResponse } from "@sendgrid/client/src/response";
@ -49,14 +49,12 @@ const environmentApiKey = process.env.SENDGRID_SYNC_API_KEY || "";
* one account only, not configurable by any user at any moment. * one account only, not configurable by any user at any moment.
*/ */
export default class Sendgrid { export default class Sendgrid {
private sendgrid: typeof sendgrid;
private log: typeof logger; private log: typeof logger;
constructor(providedApiKey = "") { constructor(providedApiKey = "") {
this.log = logger.getChildLogger({ prefix: [`[[lib] sendgrid`] }); this.log = logger.getChildLogger({ prefix: [`[[lib] sendgrid`] });
if (!providedApiKey && !environmentApiKey) throw Error("Sendgrid Api Key not present"); if (!providedApiKey && !environmentApiKey) throw Error("Sendgrid Api Key not present");
this.sendgrid = sendgrid; client.setApiKey(providedApiKey || environmentApiKey);
this.sendgrid.setApiKey(providedApiKey || environmentApiKey);
} }
public username = async () => { public username = async () => {
@ -69,7 +67,7 @@ export default class Sendgrid {
public async sendgridRequest<R = ClientResponse>(data: ClientRequest): Promise<R> { public async sendgridRequest<R = ClientResponse>(data: ClientRequest): Promise<R> {
this.log.debug("sendgridRequest:request", data); this.log.debug("sendgridRequest:request", data);
const results = await this.sendgrid.request(data); const results = await client.request(data);
this.log.debug("sendgridRequest:results", results); this.log.debug("sendgridRequest:results", results);
if (results[1].errors) throw Error(`Sendgrid request error: ${results[1].errors}`); if (results[1].errors) throw Error(`Sendgrid request error: ${results[1].errors}`);
return results[1]; return results[1];