@keystrokehq/sendgrid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +225 -0
- package/dist/_official/index.d.mts +2 -0
- package/dist/_official/index.mjs +3 -0
- package/dist/_runtime/index.d.mts +2 -0
- package/dist/_runtime/index.mjs +3 -0
- package/dist/alerts.d.mts +193 -0
- package/dist/alerts.mjs +101 -0
- package/dist/api-keys.d.mts +160 -0
- package/dist/api-keys.mjs +113 -0
- package/dist/client.d.mts +73 -0
- package/dist/client.mjs +261 -0
- package/dist/connection.d.mts +2 -0
- package/dist/connection.mjs +3 -0
- package/dist/domains.d.mts +114 -0
- package/dist/domains.mjs +62 -0
- package/dist/email-validation.d.mts +134 -0
- package/dist/email-validation.mjs +73 -0
- package/dist/events.d.mts +69 -0
- package/dist/events.mjs +28 -0
- package/dist/factory-BSL0D2L0.mjs +25 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/integration-37BovSeK.mjs +23 -0
- package/dist/integration-CmJ2TILG.d.mts +57 -0
- package/dist/mail-send.d.mts +315 -0
- package/dist/mail-send.mjs +218 -0
- package/dist/marketing-contacts.d.mts +607 -0
- package/dist/marketing-contacts.mjs +277 -0
- package/dist/marketing-customfields.d.mts +94 -0
- package/dist/marketing-customfields.mjs +70 -0
- package/dist/marketing-lists.d.mts +184 -0
- package/dist/marketing-lists.mjs +130 -0
- package/dist/marketing-segments.d.mts +340 -0
- package/dist/marketing-segments.mjs +179 -0
- package/dist/marketing-singlesends.d.mts +648 -0
- package/dist/marketing-singlesends.mjs +277 -0
- package/dist/operations.d.mts +25 -0
- package/dist/operations.mjs +69 -0
- package/dist/schemas/index.d.mts +1395 -0
- package/dist/schemas/index.mjs +3 -0
- package/dist/sender-identities.d.mts +218 -0
- package/dist/sender-identities.mjs +109 -0
- package/dist/senders.d.mts +227 -0
- package/dist/senders.mjs +83 -0
- package/dist/shared-CQ8JFNXi.mjs +13 -0
- package/dist/stats.d.mts +215 -0
- package/dist/stats.mjs +107 -0
- package/dist/suppressions.d.mts +785 -0
- package/dist/suppressions.mjs +539 -0
- package/dist/templates.d.mts +451 -0
- package/dist/templates.mjs +238 -0
- package/dist/triggers.d.mts +35 -0
- package/dist/triggers.mjs +98 -0
- package/dist/user-account.d.mts +108 -0
- package/dist/user-account.mjs +59 -0
- package/dist/verification.d.mts +67 -0
- package/dist/verification.mjs +72 -0
- package/dist/webhooks/event.d.mts +287 -0
- package/dist/webhooks/event.mjs +147 -0
- package/dist/webhooks/parse.d.mts +172 -0
- package/dist/webhooks/parse.mjs +125 -0
- package/dist/webhooks-CKdsIikb.mjs +735 -0
- package/package.json +162 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { n as sendgrid } from "./integration-CmJ2TILG.mjs";
|
|
2
|
+
import { sendgridEventWebhookEventSchema, sendgridEventWebhookPayloadSchema, sendgridInboundParsePayloadSchema } from "./schemas/index.mjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { IntegrationTriggerBindingOptions } from "@keystrokehq/integration-authoring";
|
|
5
|
+
import { BoundTrigger, WebhookRequest } from "@keystrokehq/core";
|
|
6
|
+
import { WebhookTriggerManifest } from "@keystrokehq/core/trigger";
|
|
7
|
+
|
|
8
|
+
//#region src/triggers.d.ts
|
|
9
|
+
type SendGridCredentialSets = readonly [typeof sendgrid];
|
|
10
|
+
type EventPayload = z.output<typeof sendgridEventWebhookEventSchema>;
|
|
11
|
+
type InboundParsePayload = z.output<typeof sendgridInboundParsePayloadSchema>;
|
|
12
|
+
type EventBindingOptions<TOutput = EventPayload> = IntegrationTriggerBindingOptions<EventPayload, TOutput, WebhookRequest>;
|
|
13
|
+
type EventBoundTrigger<TOutput = EventPayload> = BoundTrigger<z.output<typeof sendgridEventWebhookPayloadSchema>, SendGridCredentialSets, WebhookTriggerManifest, TOutput, WebhookRequest>;
|
|
14
|
+
type InboundParseBindingOptions<TOutput = InboundParsePayload> = IntegrationTriggerBindingOptions<InboundParsePayload, TOutput, WebhookRequest>;
|
|
15
|
+
type InboundParseBoundTrigger<TOutput = InboundParsePayload> = BoundTrigger<InboundParsePayload, SendGridCredentialSets, WebhookTriggerManifest, TOutput, WebhookRequest>;
|
|
16
|
+
type EventBindingSurface = <TOutput = EventPayload>(options?: EventBindingOptions<TOutput>) => EventBoundTrigger<TOutput>;
|
|
17
|
+
type InboundParseBindingSurface = <TOutput = InboundParsePayload>(options?: InboundParseBindingOptions<TOutput>) => InboundParseBoundTrigger<TOutput>;
|
|
18
|
+
interface SendGridEventTriggerNamespace {
|
|
19
|
+
readonly processed: EventBindingSurface;
|
|
20
|
+
readonly dropped: EventBindingSurface;
|
|
21
|
+
readonly deferred: EventBindingSurface;
|
|
22
|
+
readonly delivered: EventBindingSurface;
|
|
23
|
+
readonly bounce: EventBindingSurface;
|
|
24
|
+
readonly open: EventBindingSurface;
|
|
25
|
+
readonly click: EventBindingSurface;
|
|
26
|
+
readonly spamReport: EventBindingSurface;
|
|
27
|
+
readonly unsubscribe: EventBindingSurface;
|
|
28
|
+
readonly groupUnsubscribe: EventBindingSurface;
|
|
29
|
+
readonly groupResubscribe: EventBindingSurface;
|
|
30
|
+
readonly inboundParseReceived: InboundParseBindingSurface;
|
|
31
|
+
}
|
|
32
|
+
declare const triggers: SendGridEventTriggerNamespace;
|
|
33
|
+
declare const sendgridEventEventNames: readonly ["processed", "dropped", "deferred", "delivered", "bounce", "open", "click", "spam_report", "unsubscribe", "group_unsubscribe", "group_resubscribe"];
|
|
34
|
+
//#endregion
|
|
35
|
+
export { SendGridEventTriggerNamespace, sendgridEventEventNames, triggers };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { t as sendgrid } from "./integration-37BovSeK.mjs";
|
|
2
|
+
import { a as sendgridInboundParsePayloadSchema, r as sendgridEventWebhookPayloadSchema } from "./webhooks-CKdsIikb.mjs";
|
|
3
|
+
import { sendgridEventWebhookEventNames } from "./events.mjs";
|
|
4
|
+
import { verifyInboundParseRequest, verifySendGridEventWebhookRequest } from "./verification.mjs";
|
|
5
|
+
import { createWebhookTriggerBindingFactory } from "@keystrokehq/integration-authoring";
|
|
6
|
+
|
|
7
|
+
//#region src/triggers.ts
|
|
8
|
+
const EVENT_ROUTE = "/sendgrid/events";
|
|
9
|
+
const INBOUND_PARSE_ROUTE = "/sendgrid/inbound-parse";
|
|
10
|
+
const SIGNATURE_HEADER = "x-twilio-email-event-webhook-signature";
|
|
11
|
+
const TIMESTAMP_HEADER = "x-twilio-email-event-webhook-timestamp";
|
|
12
|
+
function findHeader(headers, name) {
|
|
13
|
+
const direct = headers[name] ?? headers[name.toLowerCase()];
|
|
14
|
+
if (direct !== void 0) return direct;
|
|
15
|
+
for (const [key, value] of Object.entries(headers)) if (key.toLowerCase() === name.toLowerCase()) return value;
|
|
16
|
+
}
|
|
17
|
+
function findFirstMatching(payload, event) {
|
|
18
|
+
for (const entry of payload) if (entry.event === event) return entry;
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function createEventWebhookBinding(event, defaultName, defaultDescription) {
|
|
22
|
+
return createWebhookTriggerBindingFactory({
|
|
23
|
+
defaultName,
|
|
24
|
+
defaultDescription,
|
|
25
|
+
path: EVENT_ROUTE,
|
|
26
|
+
method: "POST",
|
|
27
|
+
payload: sendgridEventWebhookPayloadSchema,
|
|
28
|
+
credentialSets: [sendgrid],
|
|
29
|
+
verify: (request, ctx) => {
|
|
30
|
+
const publicKeyPem = ctx.credentials[sendgrid.id].SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY;
|
|
31
|
+
if (!publicKeyPem) throw new Error("SendGrid event-webhook signature key is not configured. Fetch the Ed25519 public key via `getSignedPublicKey` and store it on the connection as `SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY`.");
|
|
32
|
+
const signature = findHeader(request.headers, SIGNATURE_HEADER);
|
|
33
|
+
const timestamp = findHeader(request.headers, TIMESTAMP_HEADER);
|
|
34
|
+
if (!signature || !timestamp) throw new Error("SendGrid event-webhook signature headers are missing.");
|
|
35
|
+
if (!verifySendGridEventWebhookRequest({
|
|
36
|
+
rawBody: request.rawBody,
|
|
37
|
+
signature,
|
|
38
|
+
timestamp,
|
|
39
|
+
publicKeyPem
|
|
40
|
+
})) throw new Error("Invalid SendGrid event-webhook signature.");
|
|
41
|
+
},
|
|
42
|
+
definitionFilter: (payload) => Array.isArray(payload) && payload.some((entry) => entry.event === event),
|
|
43
|
+
mapPayload: (payload) => findFirstMatching(payload, event),
|
|
44
|
+
idempotencyKey: (_payload, mapped) => mapped ? `${mapped.event}:${mapped.sg_event_id}` : void 0,
|
|
45
|
+
response: { successStatus: 200 }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const processedBinding = createEventWebhookBinding("processed", "SendGrid Event: Processed", "Fires when SendGrid accepts a message for delivery.");
|
|
49
|
+
const droppedBinding = createEventWebhookBinding("dropped", "SendGrid Event: Dropped", "Fires when SendGrid drops a message (e.g. suppressed recipient, invalid email).");
|
|
50
|
+
const deferredBinding = createEventWebhookBinding("deferred", "SendGrid Event: Deferred", "Fires when the receiving mail server temporarily rejects the message.");
|
|
51
|
+
const deliveredBinding = createEventWebhookBinding("delivered", "SendGrid Event: Delivered", "Fires when the receiving mail server accepts the message.");
|
|
52
|
+
const bounceBinding = createEventWebhookBinding("bounce", "SendGrid Event: Bounce", "Fires when the receiving mail server permanently rejects the message.");
|
|
53
|
+
const openBinding = createEventWebhookBinding("open", "SendGrid Event: Open", "Fires when the recipient opens the message. Filter `sg_machine_open` to exclude Apple MPP cache-fetches.");
|
|
54
|
+
const clickBinding = createEventWebhookBinding("click", "SendGrid Event: Click", "Fires when the recipient clicks a tracked link.");
|
|
55
|
+
const spamReportBinding = createEventWebhookBinding("spam_report", "SendGrid Event: Spam Report", "Fires when the recipient marks the message as spam via the ISP feedback loop.");
|
|
56
|
+
const unsubscribeBinding = createEventWebhookBinding("unsubscribe", "SendGrid Event: Unsubscribe", "Fires when the recipient uses one-click or List-Unsubscribe headers.");
|
|
57
|
+
const groupUnsubscribeBinding = createEventWebhookBinding("group_unsubscribe", "SendGrid Event: Group Unsubscribe", "Fires when the recipient unsubscribes from a specific suppression group. Includes `asm_group_id`.");
|
|
58
|
+
const groupResubscribeBinding = createEventWebhookBinding("group_resubscribe", "SendGrid Event: Group Resubscribe", "Fires when the recipient re-subscribes to a specific suppression group.");
|
|
59
|
+
const inboundParseBinding = createWebhookTriggerBindingFactory({
|
|
60
|
+
defaultName: "SendGrid Inbound Parse Received",
|
|
61
|
+
defaultDescription: "Fires when SendGrid receives an email for a configured Inbound Parse hostname. Payload is multipart; key fields like `from`, `to`, `subject`, `html`, `text`, and parsed `envelope` pass through.",
|
|
62
|
+
path: INBOUND_PARSE_ROUTE,
|
|
63
|
+
method: "POST",
|
|
64
|
+
payload: sendgridInboundParsePayloadSchema,
|
|
65
|
+
credentialSets: [sendgrid],
|
|
66
|
+
verify: (request, ctx) => {
|
|
67
|
+
const token = ctx.credentials[sendgrid.id].SENDGRID_INBOUND_PARSE_TOKEN;
|
|
68
|
+
if (!token) throw new Error("SendGrid Inbound Parse token is not configured. Generate one and store it on the connection as `SENDGRID_INBOUND_PARSE_TOKEN`; include it in the receiver URL path.");
|
|
69
|
+
if (!verifyInboundParseRequest({
|
|
70
|
+
path: request.path,
|
|
71
|
+
expectedToken: token
|
|
72
|
+
})) throw new Error("Invalid SendGrid Inbound Parse token in request path.");
|
|
73
|
+
},
|
|
74
|
+
idempotencyKey: (payload) => {
|
|
75
|
+
const messageId = typeof payload.headers === "string" ? payload.headers.match(/Message-ID:\s*([^\r\n]+)/iu)?.[1] : void 0;
|
|
76
|
+
if (messageId) return messageId.trim();
|
|
77
|
+
return `${typeof payload.envelope === "string" ? payload.envelope : ""}:${typeof payload.subject === "string" ? payload.subject : ""}`.slice(0, 200);
|
|
78
|
+
},
|
|
79
|
+
response: { successStatus: 200 }
|
|
80
|
+
});
|
|
81
|
+
const triggers = Object.freeze({
|
|
82
|
+
processed: processedBinding,
|
|
83
|
+
dropped: droppedBinding,
|
|
84
|
+
deferred: deferredBinding,
|
|
85
|
+
delivered: deliveredBinding,
|
|
86
|
+
bounce: bounceBinding,
|
|
87
|
+
open: openBinding,
|
|
88
|
+
click: clickBinding,
|
|
89
|
+
spamReport: spamReportBinding,
|
|
90
|
+
unsubscribe: unsubscribeBinding,
|
|
91
|
+
groupUnsubscribe: groupUnsubscribeBinding,
|
|
92
|
+
groupResubscribe: groupResubscribeBinding,
|
|
93
|
+
inboundParseReceived: inboundParseBinding
|
|
94
|
+
});
|
|
95
|
+
const sendgridEventEventNames = sendgridEventWebhookEventNames;
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { sendgridEventEventNames, triggers };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import * as _keystrokehq_core_credential_set0 from "@keystrokehq/core/credential-set";
|
|
3
|
+
import * as _keystrokehq_core0 from "@keystrokehq/core";
|
|
4
|
+
|
|
5
|
+
//#region src/user-account.d.ts
|
|
6
|
+
declare const getUserProfile: _keystrokehq_core0.Operation<z.ZodOptional<z.ZodObject<{}, z.core.$strip>>, z.ZodObject<{
|
|
7
|
+
address: z.ZodOptional<z.ZodString>;
|
|
8
|
+
address2: z.ZodOptional<z.ZodString>;
|
|
9
|
+
city: z.ZodOptional<z.ZodString>;
|
|
10
|
+
company: z.ZodOptional<z.ZodString>;
|
|
11
|
+
country: z.ZodOptional<z.ZodString>;
|
|
12
|
+
first_name: z.ZodOptional<z.ZodString>;
|
|
13
|
+
last_name: z.ZodOptional<z.ZodString>;
|
|
14
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
15
|
+
state: z.ZodOptional<z.ZodString>;
|
|
16
|
+
website: z.ZodOptional<z.ZodString>;
|
|
17
|
+
zip: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$catchall<z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
19
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
20
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
21
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
22
|
+
global: "global";
|
|
23
|
+
eu: "eu";
|
|
24
|
+
}>>;
|
|
25
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
26
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
28
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
29
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
30
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
31
|
+
global: "global";
|
|
32
|
+
eu: "eu";
|
|
33
|
+
}>>;
|
|
34
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
35
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
37
|
+
declare const getAccountInfo: _keystrokehq_core0.Operation<z.ZodOptional<z.ZodObject<{}, z.core.$strip>>, z.ZodObject<{
|
|
38
|
+
type: z.ZodString;
|
|
39
|
+
reputation: z.ZodOptional<z.ZodNumber>;
|
|
40
|
+
}, z.core.$catchall<z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
41
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
42
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
43
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
44
|
+
global: "global";
|
|
45
|
+
eu: "eu";
|
|
46
|
+
}>>;
|
|
47
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
48
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
50
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
51
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
52
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
53
|
+
global: "global";
|
|
54
|
+
eu: "eu";
|
|
55
|
+
}>>;
|
|
56
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
57
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
59
|
+
declare const getUserScopes: _keystrokehq_core0.Operation<z.ZodOptional<z.ZodObject<{}, z.core.$strip>>, z.ZodObject<{
|
|
60
|
+
scopes: z.ZodArray<z.ZodString>;
|
|
61
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
62
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
63
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
64
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
65
|
+
global: "global";
|
|
66
|
+
eu: "eu";
|
|
67
|
+
}>>;
|
|
68
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
69
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
71
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
72
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
73
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
74
|
+
global: "global";
|
|
75
|
+
eu: "eu";
|
|
76
|
+
}>>;
|
|
77
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
78
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
79
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
80
|
+
declare const getCreditBalance: _keystrokehq_core0.Operation<z.ZodOptional<z.ZodObject<{}, z.core.$strip>>, z.ZodObject<{
|
|
81
|
+
remain: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
total: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
overage: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
used: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
last_reset: z.ZodOptional<z.ZodString>;
|
|
86
|
+
next_reset: z.ZodOptional<z.ZodString>;
|
|
87
|
+
reset_frequency: z.ZodOptional<z.ZodString>;
|
|
88
|
+
}, z.core.$catchall<z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
89
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
90
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
91
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
92
|
+
global: "global";
|
|
93
|
+
eu: "eu";
|
|
94
|
+
}>>;
|
|
95
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
96
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
98
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
99
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
100
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
101
|
+
global: "global";
|
|
102
|
+
eu: "eu";
|
|
103
|
+
}>>;
|
|
104
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
105
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
106
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { getAccountInfo, getCreditBalance, getUserProfile, getUserScopes };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { n as __exportAll, t as sendgridOperation } from "./factory-BSL0D2L0.mjs";
|
|
2
|
+
import { createSendGridClient } from "./client.mjs";
|
|
3
|
+
import { f as sendgridAccountInfoSchema, g as sendgridUserProfileSchema, m as sendgridScopesSchema, p as sendgridCreditBalanceSchema } from "./webhooks-CKdsIikb.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/user-account.ts
|
|
7
|
+
var user_account_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
getAccountInfo: () => getAccountInfo,
|
|
9
|
+
getCreditBalance: () => getCreditBalance,
|
|
10
|
+
getUserProfile: () => getUserProfile,
|
|
11
|
+
getUserScopes: () => getUserScopes
|
|
12
|
+
});
|
|
13
|
+
const getUserProfile = sendgridOperation({
|
|
14
|
+
id: "get_user_profile",
|
|
15
|
+
name: "Get User Profile",
|
|
16
|
+
description: "Retrieve the account profile (name, company, mailing address).",
|
|
17
|
+
input: z.object({}).optional(),
|
|
18
|
+
output: sendgridUserProfileSchema,
|
|
19
|
+
run: async (_input, credentials) => {
|
|
20
|
+
const response = await createSendGridClient(credentials).request("/user/profile");
|
|
21
|
+
return sendgridUserProfileSchema.parse(response);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const getAccountInfo = sendgridOperation({
|
|
25
|
+
id: "get_account_info",
|
|
26
|
+
name: "Get Account Info",
|
|
27
|
+
description: "Retrieve account type + reputation score.",
|
|
28
|
+
input: z.object({}).optional(),
|
|
29
|
+
output: sendgridAccountInfoSchema,
|
|
30
|
+
run: async (_input, credentials) => {
|
|
31
|
+
const response = await createSendGridClient(credentials).request("/user/account");
|
|
32
|
+
return sendgridAccountInfoSchema.parse(response);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const getUserScopes = sendgridOperation({
|
|
36
|
+
id: "get_user_scopes",
|
|
37
|
+
name: "Get User Scopes",
|
|
38
|
+
description: "Retrieve the list of API scopes the current API key has access to.",
|
|
39
|
+
input: z.object({}).optional(),
|
|
40
|
+
output: sendgridScopesSchema,
|
|
41
|
+
run: async (_input, credentials) => {
|
|
42
|
+
const response = await createSendGridClient(credentials).request("/scopes");
|
|
43
|
+
return sendgridScopesSchema.parse(response);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const getCreditBalance = sendgridOperation({
|
|
47
|
+
id: "get_credit_balance",
|
|
48
|
+
name: "Get Credit Balance",
|
|
49
|
+
description: "Retrieve the current SendGrid credit balance for the account.",
|
|
50
|
+
input: z.object({}).optional(),
|
|
51
|
+
output: sendgridCreditBalanceSchema,
|
|
52
|
+
run: async (_input, credentials) => {
|
|
53
|
+
const response = await createSendGridClient(credentials).request("/user/credits");
|
|
54
|
+
return sendgridCreditBalanceSchema.parse(response);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { getAccountInfo, getCreditBalance, getUserProfile, getUserScopes, user_account_exports as t };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { sendgridEventWebhookPayloadSchema } from "./schemas/index.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
//#region src/verification.d.ts
|
|
5
|
+
declare const SENDGRID_EVENT_SIGNATURE_HEADER = "x-twilio-email-event-webhook-signature";
|
|
6
|
+
declare const SENDGRID_EVENT_TIMESTAMP_HEADER = "x-twilio-email-event-webhook-timestamp";
|
|
7
|
+
interface SendGridEventWebhookVerifyInput {
|
|
8
|
+
/** Raw request body bytes (not a JSON-reparsed string). */
|
|
9
|
+
readonly rawBody: string | Uint8Array;
|
|
10
|
+
/** Value of the `X-Twilio-Email-Event-Webhook-Signature` header. */
|
|
11
|
+
readonly signature: string;
|
|
12
|
+
/** Value of the `X-Twilio-Email-Event-Webhook-Timestamp` header. */
|
|
13
|
+
readonly timestamp: string;
|
|
14
|
+
/** Ed25519 public key in PEM form (as returned by `GET /v3/user/webhooks/event/settings/signed`). */
|
|
15
|
+
readonly publicKeyPem: string;
|
|
16
|
+
/** Maximum allowed clock skew between provider and verifier, in seconds. Defaults to 300s. */
|
|
17
|
+
readonly toleranceSeconds?: number;
|
|
18
|
+
/** Override `now` in tests. Defaults to `Date.now()`. */
|
|
19
|
+
readonly now?: () => number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Verify a SendGrid Event Webhook request. Returns `true` for a valid signature.
|
|
23
|
+
*
|
|
24
|
+
* SendGrid signs `timestamp + rawBody` with Ed25519. The public key rotates when
|
|
25
|
+
* `TOGGLE_WEBHOOK_SIGNATURE` is toggled, so callers should cache + refresh on
|
|
26
|
+
* verification failures.
|
|
27
|
+
*/
|
|
28
|
+
declare function verifySendGridEventWebhookRequest(input: SendGridEventWebhookVerifyInput): boolean;
|
|
29
|
+
declare function parseSendGridEventWebhookBody(rawBody: string | Uint8Array): z.output<typeof sendgridEventWebhookPayloadSchema>;
|
|
30
|
+
interface SendGridInboundParseVerifyInput {
|
|
31
|
+
/** Full URL path the request arrived at (including any Keystroke-minted token). */
|
|
32
|
+
readonly path: string;
|
|
33
|
+
/** Expected Keystroke-minted parse token (from `SENDGRID_INBOUND_PARSE_TOKEN`). */
|
|
34
|
+
readonly expectedToken: string;
|
|
35
|
+
/** Optional IP allowlist (SendGrid publishes the IP range for Inbound Parse). */
|
|
36
|
+
readonly sourceIp?: string;
|
|
37
|
+
readonly allowedIps?: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Verify an Inbound Parse request.
|
|
41
|
+
*
|
|
42
|
+
* SendGrid does NOT sign Inbound Parse payloads. Verification uses a Keystroke-minted
|
|
43
|
+
* token embedded in the receiver URL, plus an optional IP allowlist check. This is
|
|
44
|
+
* weaker than the Event Webhook's Ed25519 verification — callers are encouraged to
|
|
45
|
+
* rotate `expectedToken` periodically.
|
|
46
|
+
*/
|
|
47
|
+
declare function verifyInboundParseRequest(input: SendGridInboundParseVerifyInput): boolean;
|
|
48
|
+
declare const sendgridInboundParseBodySchema: z.ZodObject<{
|
|
49
|
+
headers: z.ZodOptional<z.ZodString>;
|
|
50
|
+
dkim: z.ZodOptional<z.ZodString>;
|
|
51
|
+
to: z.ZodOptional<z.ZodString>;
|
|
52
|
+
from: z.ZodOptional<z.ZodString>;
|
|
53
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
54
|
+
html: z.ZodOptional<z.ZodString>;
|
|
55
|
+
text: z.ZodOptional<z.ZodString>;
|
|
56
|
+
envelope: z.ZodOptional<z.ZodString>;
|
|
57
|
+
charsets: z.ZodOptional<z.ZodString>;
|
|
58
|
+
SPF: z.ZodOptional<z.ZodString>;
|
|
59
|
+
spam_score: z.ZodOptional<z.ZodString>;
|
|
60
|
+
spam_report: z.ZodOptional<z.ZodString>;
|
|
61
|
+
sender_ip: z.ZodOptional<z.ZodString>;
|
|
62
|
+
attachments: z.ZodOptional<z.ZodString>;
|
|
63
|
+
'attachment-info': z.ZodOptional<z.ZodString>;
|
|
64
|
+
email: z.ZodOptional<z.ZodString>;
|
|
65
|
+
}, z.core.$catchall<z.ZodUnknown>>;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { SENDGRID_EVENT_SIGNATURE_HEADER, SENDGRID_EVENT_TIMESTAMP_HEADER, SendGridEventWebhookVerifyInput, SendGridInboundParseVerifyInput, parseSendGridEventWebhookBody, sendgridInboundParseBodySchema, verifyInboundParseRequest, verifySendGridEventWebhookRequest };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { a as sendgridInboundParsePayloadSchema, r as sendgridEventWebhookPayloadSchema } from "./webhooks-CKdsIikb.mjs";
|
|
2
|
+
import { createPublicKey, createVerify, verify } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
//#region src/verification.ts
|
|
5
|
+
const SENDGRID_EVENT_SIGNATURE_HEADER = "x-twilio-email-event-webhook-signature";
|
|
6
|
+
const SENDGRID_EVENT_TIMESTAMP_HEADER = "x-twilio-email-event-webhook-timestamp";
|
|
7
|
+
/**
|
|
8
|
+
* Verify a SendGrid Event Webhook request. Returns `true` for a valid signature.
|
|
9
|
+
*
|
|
10
|
+
* SendGrid signs `timestamp + rawBody` with Ed25519. The public key rotates when
|
|
11
|
+
* `TOGGLE_WEBHOOK_SIGNATURE` is toggled, so callers should cache + refresh on
|
|
12
|
+
* verification failures.
|
|
13
|
+
*/
|
|
14
|
+
function verifySendGridEventWebhookRequest(input) {
|
|
15
|
+
const tolerance = input.toleranceSeconds ?? 300;
|
|
16
|
+
const nowMs = (input.now ?? Date.now)();
|
|
17
|
+
const timestampSeconds = Number(input.timestamp);
|
|
18
|
+
if (!Number.isFinite(timestampSeconds)) return false;
|
|
19
|
+
if (Math.abs(nowMs / 1e3 - timestampSeconds) > tolerance) return false;
|
|
20
|
+
let publicKey;
|
|
21
|
+
try {
|
|
22
|
+
publicKey = createPublicKey({
|
|
23
|
+
key: input.publicKeyPem,
|
|
24
|
+
format: "pem"
|
|
25
|
+
});
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
let signatureBytes;
|
|
30
|
+
try {
|
|
31
|
+
signatureBytes = Buffer.from(input.signature, "base64");
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const rawBodyBuffer = typeof input.rawBody === "string" ? Buffer.from(input.rawBody, "utf8") : Buffer.from(input.rawBody);
|
|
36
|
+
const payloadBuffer = Buffer.concat([Buffer.from(input.timestamp, "utf8"), rawBodyBuffer]);
|
|
37
|
+
try {
|
|
38
|
+
return verify(null, payloadBuffer, publicKey, signatureBytes);
|
|
39
|
+
} catch {
|
|
40
|
+
const verifier = createVerify("sha256");
|
|
41
|
+
verifier.update(payloadBuffer);
|
|
42
|
+
try {
|
|
43
|
+
return verifier.verify(publicKey, signatureBytes);
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function parseSendGridEventWebhookBody(rawBody) {
|
|
50
|
+
const text = typeof rawBody === "string" ? rawBody : Buffer.from(rawBody).toString("utf8");
|
|
51
|
+
const json = JSON.parse(text);
|
|
52
|
+
return sendgridEventWebhookPayloadSchema.parse(json);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Verify an Inbound Parse request.
|
|
56
|
+
*
|
|
57
|
+
* SendGrid does NOT sign Inbound Parse payloads. Verification uses a Keystroke-minted
|
|
58
|
+
* token embedded in the receiver URL, plus an optional IP allowlist check. This is
|
|
59
|
+
* weaker than the Event Webhook's Ed25519 verification — callers are encouraged to
|
|
60
|
+
* rotate `expectedToken` periodically.
|
|
61
|
+
*/
|
|
62
|
+
function verifyInboundParseRequest(input) {
|
|
63
|
+
if (!input.path.includes(input.expectedToken)) return false;
|
|
64
|
+
if (input.allowedIps && input.allowedIps.length > 0) {
|
|
65
|
+
if (!input.sourceIp || !input.allowedIps.includes(input.sourceIp)) return false;
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
const sendgridInboundParseBodySchema = sendgridInboundParsePayloadSchema;
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { SENDGRID_EVENT_SIGNATURE_HEADER, SENDGRID_EVENT_TIMESTAMP_HEADER, parseSendGridEventWebhookBody, sendgridInboundParseBodySchema, verifyInboundParseRequest, verifySendGridEventWebhookRequest };
|