MCPcopy
hub / github.com/triggerdotdev/trigger.dev / SendGrid

Class SendGrid

integrations/sendgrid/src/index.ts:21–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19};
20
21export class SendGrid implements TriggerIntegration {
22 // @internal
23 private _options: SendGridIntegrationOptions;
24 // @internal
25 private _client?: MailService;
26 // @internal
27 private _io?: IO;
28 // @internal
29 private _connectionKey?: string;
30
31 constructor(private options: SendGridIntegrationOptions) {
32 this._options = options;
33 }
34
35 get authSource() {
36 return this._options.apiKey ? ("LOCAL" as const) : ("HOSTED" as const);
37 }
38
39 cloneForRun(io: IO, connectionKey: string, auth?: ConnectionAuth) {
40 const apiKey = this._options.apiKey ?? auth?.accessToken;
41
42 if (!apiKey) {
43 throw new Error(
44 `Can't initialize SendGrid integration (${this._options.id}) as apiKey was undefined`
45 );
46 }
47
48 const sendgrid = new SendGrid(this._options);
49 sendgrid._io = io;
50 sendgrid._connectionKey = connectionKey;
51 sendgrid._client = new MailService();
52 sendgrid._client.setApiKey(apiKey);
53 return sendgrid;
54 }
55
56 get id() {
57 return this.options.id;
58 }
59
60 get metadata() {
61 return { id: "sendgrid", name: "SendGrid" };
62 }
63
64 runTask<T, TResult extends Json<T> | void>(
65 key: IntegrationTaskKey,
66 callback: (client: MailService, task: IOTask, io: IO) => Promise<TResult>,
67 options?: RunTaskOptions,
68 errorCallback?: RunTaskErrorCallback
69 ): Promise<TResult> {
70 if (!this._io) throw new Error("No IO");
71 if (!this._connectionKey) throw new Error("No connection key");
72
73 return this._io.runTask(
74 key,
75 (task, io) => {
76 if (!this._client) throw new Error("No client");
77 return callback(this._client, task, io);
78 },

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…