@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
package/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# @keystrokehq/sendgrid
|
|
2
|
+
|
|
3
|
+
Official Keystroke integration for **SendGrid** (Twilio) — transactional + marketing email, templates, contacts, lists, segments, suppressions, deliverability, and webhook helpers.
|
|
4
|
+
|
|
5
|
+
This package follows the standard Keystroke [official integration authoring pattern](../integration-authoring/AUTHORING.md). The root entrypoint is intentionally empty; use explicit subpaths.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @keystrokehq/sendgrid
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Connect
|
|
16
|
+
|
|
17
|
+
SendGrid authenticates with a single API key. Create one in the SendGrid console (**Settings → API Keys**) — we recommend a **Restricted Access** key with only the scopes your workflows need.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { sendgrid, type SendGridCredentials } from '@keystrokehq/sendgrid/connection';
|
|
21
|
+
|
|
22
|
+
const credentials: SendGridCredentials = {
|
|
23
|
+
SENDGRID_API_KEY: 'SG.xxx...',
|
|
24
|
+
// Optional:
|
|
25
|
+
SENDGRID_SUBUSER: 'acme-eu', // adds `on-behalf-of: acme-eu` header
|
|
26
|
+
SENDGRID_ACCOUNT_REGION: 'eu', // default: 'global'
|
|
27
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: '-----BEGIN PUBLIC KEY-----\n…\n-----END PUBLIC KEY-----',
|
|
28
|
+
SENDGRID_INBOUND_PARSE_TOKEN: 'token-abc',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
void credentials;
|
|
32
|
+
void sendgrid;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Fields
|
|
36
|
+
|
|
37
|
+
| Field | Required | Purpose |
|
|
38
|
+
|-------|----------|---------|
|
|
39
|
+
| `SENDGRID_API_KEY` | yes | Full or restricted API key. Must start with `SG.`. |
|
|
40
|
+
| `SENDGRID_SUBUSER` | no | Username of a subuser; sent as `on-behalf-of` on every request. |
|
|
41
|
+
| `SENDGRID_ACCOUNT_REGION` | no | `global` (default) or `eu`. Controls the base URL (`api.sendgrid.com` vs `api.eu.sendgrid.com`). |
|
|
42
|
+
| `SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY` | no | Ed25519 public key for verifying Event Webhook deliveries. Fetch with `getSignedPublicKey`, store when enabling signing. |
|
|
43
|
+
| `SENDGRID_INBOUND_PARSE_TOKEN` | no | Keystroke-minted shared secret embedded in the Inbound Parse receiver URL. |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quickstart
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { sendEmail } from '@keystrokehq/sendgrid/mail-send';
|
|
51
|
+
|
|
52
|
+
void sendEmail;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { triggers } from '@keystrokehq/sendgrid/triggers';
|
|
57
|
+
|
|
58
|
+
const onBounce = triggers.bounce({
|
|
59
|
+
name: 'escalate-hard-bounces',
|
|
60
|
+
filter: (event) => event.type === 'hard',
|
|
61
|
+
transform: (event) => ({ email: event.email, reason: event.reason }),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
void onBounce;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Public surface
|
|
70
|
+
|
|
71
|
+
### End-user authoring imports
|
|
72
|
+
|
|
73
|
+
| Import path | Exports |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `@keystrokehq/sendgrid/mail-send` | `sendEmail`, `createBatchId`, `validateBatchId`, `cancelOrPauseScheduledSend`, `updateScheduledSend`, `deleteScheduledSend`, `listScheduledSends`, `getScheduledSend` |
|
|
76
|
+
| `@keystrokehq/sendgrid/templates` | Transactional templates + versions CRUD + activate |
|
|
77
|
+
| `@keystrokehq/sendgrid/marketing-contacts` | Marketing Contacts v3: upsert, search, batch, count, imports, exports, field definitions |
|
|
78
|
+
| `@keystrokehq/sendgrid/marketing-lists` | Marketing Lists v3 CRUD + contact count + remove-contacts |
|
|
79
|
+
| `@keystrokehq/sendgrid/marketing-segments` | Marketing Segments v2 CRUD + refresh + parent-filter |
|
|
80
|
+
| `@keystrokehq/sendgrid/marketing-singlesends` | Single Sends CRUD + schedule + stats + test sends |
|
|
81
|
+
| `@keystrokehq/sendgrid/marketing-customfields` | Marketing custom field definition CRUD |
|
|
82
|
+
| `@keystrokehq/sendgrid/senders` | Marketing senders CRUD |
|
|
83
|
+
| `@keystrokehq/sendgrid/sender-identities` | Verified sender identity CRUD + resend |
|
|
84
|
+
| `@keystrokehq/sendgrid/suppressions` | Global suppressions, groups, bounces, blocks, invalid emails, spam reports |
|
|
85
|
+
| `@keystrokehq/sendgrid/email-validation` | Single + bulk email validation (add-on gated) |
|
|
86
|
+
| `@keystrokehq/sendgrid/stats` | Global, category, automation, mailbox-provider stats + engagement-quality scores |
|
|
87
|
+
| `@keystrokehq/sendgrid/user-account` | Profile, account info, scopes, credit balance |
|
|
88
|
+
| `@keystrokehq/sendgrid/alerts` | Alert CRUD |
|
|
89
|
+
| `@keystrokehq/sendgrid/domains` | Authenticated domain read + validate |
|
|
90
|
+
| `@keystrokehq/sendgrid/api-keys` | API key CRUD |
|
|
91
|
+
| `@keystrokehq/sendgrid/webhooks/event` | Event Webhook configuration, signed-key fetch, signature toggle, test |
|
|
92
|
+
| `@keystrokehq/sendgrid/webhooks/parse` | Inbound Parse configuration + stats |
|
|
93
|
+
| `@keystrokehq/sendgrid/triggers` | 12 direct-binding webhook helpers |
|
|
94
|
+
|
|
95
|
+
### Support imports
|
|
96
|
+
|
|
97
|
+
| Import path | Exports |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `@keystrokehq/sendgrid/connection` | `sendgrid` credential set + `SendGridCredentials` type |
|
|
100
|
+
| `@keystrokehq/sendgrid/client` | `createSendGridClient`, `SendGridError`, `isSendGridError` |
|
|
101
|
+
| `@keystrokehq/sendgrid/schemas` | All Zod v4 schemas — input/output shapes for every resource |
|
|
102
|
+
| `@keystrokehq/sendgrid/events` | Event-name constants + per-event payload schemas |
|
|
103
|
+
| `@keystrokehq/sendgrid/verification` | `verifySendGridEventWebhookRequest`, `verifyInboundParseRequest`, `parseSendGridEventWebhookBody` |
|
|
104
|
+
|
|
105
|
+
### Hidden repo-internal imports (do not use in end-user code)
|
|
106
|
+
|
|
107
|
+
- `@keystrokehq/sendgrid/_official`
|
|
108
|
+
- `@keystrokehq/sendgrid/_runtime`
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Sending email
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { sendEmail } from '@keystrokehq/sendgrid/mail-send';
|
|
116
|
+
|
|
117
|
+
void sendEmail;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The Mail Send operation accepts the full v3 body: multiple `personalizations`, dynamic template substitution, attachments, `categories`, `customArgs`, sandbox mode, and `sendAt` for scheduled sends. Pass a `batchId` to later cancel or pause messages.
|
|
121
|
+
|
|
122
|
+
## Marketing: contacts, lists, segments, single sends
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { upsertContacts } from '@keystrokehq/sendgrid/marketing-contacts';
|
|
126
|
+
import { createList } from '@keystrokehq/sendgrid/marketing-lists';
|
|
127
|
+
import { createSegment } from '@keystrokehq/sendgrid/marketing-segments';
|
|
128
|
+
import { createSingleSend, scheduleSingleSend } from '@keystrokehq/sendgrid/marketing-singlesends';
|
|
129
|
+
|
|
130
|
+
void upsertContacts;
|
|
131
|
+
void createList;
|
|
132
|
+
void createSegment;
|
|
133
|
+
void createSingleSend;
|
|
134
|
+
void scheduleSingleSend;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Suppressions
|
|
138
|
+
|
|
139
|
+
One barrel export covers global, group, bounce, block, invalid, and spam suppressions:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import {
|
|
143
|
+
addGlobalSuppressions,
|
|
144
|
+
createSuppressionGroup,
|
|
145
|
+
listBounces,
|
|
146
|
+
deleteSpamReport,
|
|
147
|
+
} from '@keystrokehq/sendgrid/suppressions';
|
|
148
|
+
|
|
149
|
+
void addGlobalSuppressions;
|
|
150
|
+
void createSuppressionGroup;
|
|
151
|
+
void listBounces;
|
|
152
|
+
void deleteSpamReport;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Webhooks
|
|
156
|
+
|
|
157
|
+
### Event Webhook (signed, Ed25519)
|
|
158
|
+
|
|
159
|
+
Configure via the REST helpers, then verify deliveries with the verification helpers:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import {
|
|
163
|
+
createEventWebhook,
|
|
164
|
+
getSignedPublicKey,
|
|
165
|
+
toggleWebhookSignature,
|
|
166
|
+
} from '@keystrokehq/sendgrid/webhooks/event';
|
|
167
|
+
import { verifySendGridEventWebhookRequest } from '@keystrokehq/sendgrid/verification';
|
|
168
|
+
import { triggers } from '@keystrokehq/sendgrid/triggers';
|
|
169
|
+
|
|
170
|
+
void createEventWebhook;
|
|
171
|
+
void getSignedPublicKey;
|
|
172
|
+
void toggleWebhookSignature;
|
|
173
|
+
void verifySendGridEventWebhookRequest;
|
|
174
|
+
void triggers.delivered;
|
|
175
|
+
void triggers.open;
|
|
176
|
+
void triggers.groupUnsubscribe;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**IMPORTANT:** SendGrid signs the concatenation of the `X-Twilio-Email-Event-Webhook-Timestamp` header value and the raw request body bytes. Your HTTP surface must preserve the raw body — do not JSON-reparse and re-serialize before verifying.
|
|
180
|
+
|
|
181
|
+
### Inbound Parse
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import { createParseSetting } from '@keystrokehq/sendgrid/webhooks/parse';
|
|
185
|
+
import { verifyInboundParseRequest } from '@keystrokehq/sendgrid/verification';
|
|
186
|
+
import { triggers } from '@keystrokehq/sendgrid/triggers';
|
|
187
|
+
|
|
188
|
+
void createParseSetting;
|
|
189
|
+
void verifyInboundParseRequest;
|
|
190
|
+
void triggers.inboundParseReceived;
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
SendGrid does **not** sign Inbound Parse payloads. Verification uses a Keystroke-minted token embedded in the receiver URL (plus an optional IP allowlist). Rotate the token periodically.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Caveats
|
|
198
|
+
|
|
199
|
+
- **No OAuth.** SendGrid v3 only supports API-key auth.
|
|
200
|
+
- **Apple Mail Privacy Protection.** `open` events now carry `sg_machine_open: true` when the open is an Apple MPP cache-fetch. Filter on this flag or your workflows will trigger on every Apple Mail user.
|
|
201
|
+
- **One-click unsubscribe (RFC 8058).** Required by major inbox providers for bulk senders. Set `List-Unsubscribe-Post: List-Unsubscribe=One-Click` in your `headers` on `sendEmail`.
|
|
202
|
+
- **Apple MPP + bounce classification.** `bounce` events include `bounce_classification` — use it to distinguish reputation damage from mailbox-full soft bounces.
|
|
203
|
+
- **Plan-gated endpoints.** `stats.getEngagementQualityScores` requires Pro+. `/messages` (Email Activity add-on) and reseller endpoints also 402/403 on most tenants. The client surfaces these as `SendGridError` with `kind: 'forbidden'` / `'auth'`.
|
|
204
|
+
- **Region split.** An API key scoped to `global` cannot act on `eu` data and vice versa. Set `SENDGRID_ACCOUNT_REGION` correctly at connect time.
|
|
205
|
+
- **Legacy `/contactdb/*`, Legacy Marketing Campaigns, Designs API, Reverse DNS, IP pools, Subusers, Teammates, SSO, Mail/Tracking Settings.** Not wrapped in phase 1. Fall back to the typed client for these:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { createSendGridClient } from '@keystrokehq/sendgrid/client';
|
|
209
|
+
|
|
210
|
+
void createSendGridClient;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
- **Phase 1 coverage.** This package ships ~150 operations focused on Mail Send, Templates, Marketing Contacts/Lists/Segments/Single Sends/CustomFields, Suppressions, Senders, Stats, Email Validation, User Account, Alerts, API Keys, Authenticated Domains, and the Event + Inbound Parse webhook config surface.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Verification helpers
|
|
218
|
+
|
|
219
|
+
`verifySendGridEventWebhookRequest` and `verifyInboundParseRequest` are pure functions — they accept `{ rawBody, signature, timestamp, publicKeyPem }` (Event Webhook) or `{ path, expectedToken, sourceIp?, allowedIps? }` (Inbound Parse) and return a boolean. They have no side effects and no I/O, so they are safe to call from any Keystroke runtime surface.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
MIT © Keystroke
|
|
@@ -0,0 +1,193 @@
|
|
|
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/alerts.d.ts
|
|
6
|
+
declare const createAlert: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
7
|
+
type: z.ZodEnum<{
|
|
8
|
+
usage_limit: "usage_limit";
|
|
9
|
+
stats_notification: "stats_notification";
|
|
10
|
+
}>;
|
|
11
|
+
emailTo: z.ZodString;
|
|
12
|
+
frequency: z.ZodOptional<z.ZodEnum<{
|
|
13
|
+
daily: "daily";
|
|
14
|
+
weekly: "weekly";
|
|
15
|
+
monthly: "monthly";
|
|
16
|
+
}>>;
|
|
17
|
+
percentage: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
19
|
+
id: z.ZodNumber;
|
|
20
|
+
type: z.ZodEnum<{
|
|
21
|
+
usage_limit: "usage_limit";
|
|
22
|
+
stats_notification: "stats_notification";
|
|
23
|
+
}>;
|
|
24
|
+
email_to: z.ZodOptional<z.ZodString>;
|
|
25
|
+
frequency: z.ZodOptional<z.ZodEnum<{
|
|
26
|
+
daily: "daily";
|
|
27
|
+
weekly: "weekly";
|
|
28
|
+
monthly: "monthly";
|
|
29
|
+
}>>;
|
|
30
|
+
percentage: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
created_at: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
updated_at: z.ZodOptional<z.ZodNumber>;
|
|
33
|
+
}, z.core.$catchall<z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
34
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
35
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
36
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
37
|
+
global: "global";
|
|
38
|
+
eu: "eu";
|
|
39
|
+
}>>;
|
|
40
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
41
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
43
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
44
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
45
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
46
|
+
global: "global";
|
|
47
|
+
eu: "eu";
|
|
48
|
+
}>>;
|
|
49
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
50
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
52
|
+
declare const updateAlert: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
53
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
54
|
+
usage_limit: "usage_limit";
|
|
55
|
+
stats_notification: "stats_notification";
|
|
56
|
+
}>>;
|
|
57
|
+
emailTo: z.ZodOptional<z.ZodString>;
|
|
58
|
+
frequency: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
|
|
59
|
+
daily: "daily";
|
|
60
|
+
weekly: "weekly";
|
|
61
|
+
monthly: "monthly";
|
|
62
|
+
}>>>;
|
|
63
|
+
percentage: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
|
|
64
|
+
alertId: z.ZodNumber;
|
|
65
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
66
|
+
id: z.ZodNumber;
|
|
67
|
+
type: z.ZodEnum<{
|
|
68
|
+
usage_limit: "usage_limit";
|
|
69
|
+
stats_notification: "stats_notification";
|
|
70
|
+
}>;
|
|
71
|
+
email_to: z.ZodOptional<z.ZodString>;
|
|
72
|
+
frequency: z.ZodOptional<z.ZodEnum<{
|
|
73
|
+
daily: "daily";
|
|
74
|
+
weekly: "weekly";
|
|
75
|
+
monthly: "monthly";
|
|
76
|
+
}>>;
|
|
77
|
+
percentage: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
created_at: z.ZodOptional<z.ZodNumber>;
|
|
79
|
+
updated_at: z.ZodOptional<z.ZodNumber>;
|
|
80
|
+
}, z.core.$catchall<z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
81
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
82
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
83
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
84
|
+
global: "global";
|
|
85
|
+
eu: "eu";
|
|
86
|
+
}>>;
|
|
87
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
88
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
90
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
91
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
92
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
93
|
+
global: "global";
|
|
94
|
+
eu: "eu";
|
|
95
|
+
}>>;
|
|
96
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
97
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
98
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
99
|
+
declare const deleteAlert: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
100
|
+
alertId: z.ZodNumber;
|
|
101
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
102
|
+
success: z.ZodBoolean;
|
|
103
|
+
}, z.core.$strip>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
104
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
105
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
106
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
107
|
+
global: "global";
|
|
108
|
+
eu: "eu";
|
|
109
|
+
}>>;
|
|
110
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
111
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
113
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
114
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
115
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
116
|
+
global: "global";
|
|
117
|
+
eu: "eu";
|
|
118
|
+
}>>;
|
|
119
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
120
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
121
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
122
|
+
declare const getAlert: _keystrokehq_core0.Operation<z.ZodObject<{
|
|
123
|
+
alertId: z.ZodNumber;
|
|
124
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
125
|
+
id: z.ZodNumber;
|
|
126
|
+
type: z.ZodEnum<{
|
|
127
|
+
usage_limit: "usage_limit";
|
|
128
|
+
stats_notification: "stats_notification";
|
|
129
|
+
}>;
|
|
130
|
+
email_to: z.ZodOptional<z.ZodString>;
|
|
131
|
+
frequency: z.ZodOptional<z.ZodEnum<{
|
|
132
|
+
daily: "daily";
|
|
133
|
+
weekly: "weekly";
|
|
134
|
+
monthly: "monthly";
|
|
135
|
+
}>>;
|
|
136
|
+
percentage: z.ZodOptional<z.ZodNumber>;
|
|
137
|
+
created_at: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
updated_at: z.ZodOptional<z.ZodNumber>;
|
|
139
|
+
}, z.core.$catchall<z.ZodUnknown>>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
140
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
141
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
142
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
143
|
+
global: "global";
|
|
144
|
+
eu: "eu";
|
|
145
|
+
}>>;
|
|
146
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
147
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
148
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
149
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
150
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
151
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
152
|
+
global: "global";
|
|
153
|
+
eu: "eu";
|
|
154
|
+
}>>;
|
|
155
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
156
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
157
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
158
|
+
declare const listAlerts: _keystrokehq_core0.Operation<z.ZodOptional<z.ZodObject<{}, z.core.$strip>>, z.ZodArray<z.ZodObject<{
|
|
159
|
+
id: z.ZodNumber;
|
|
160
|
+
type: z.ZodEnum<{
|
|
161
|
+
usage_limit: "usage_limit";
|
|
162
|
+
stats_notification: "stats_notification";
|
|
163
|
+
}>;
|
|
164
|
+
email_to: z.ZodOptional<z.ZodString>;
|
|
165
|
+
frequency: z.ZodOptional<z.ZodEnum<{
|
|
166
|
+
daily: "daily";
|
|
167
|
+
weekly: "weekly";
|
|
168
|
+
monthly: "monthly";
|
|
169
|
+
}>>;
|
|
170
|
+
percentage: z.ZodOptional<z.ZodNumber>;
|
|
171
|
+
created_at: z.ZodOptional<z.ZodNumber>;
|
|
172
|
+
updated_at: z.ZodOptional<z.ZodNumber>;
|
|
173
|
+
}, z.core.$catchall<z.ZodUnknown>>>, readonly [_keystrokehq_core0.CredentialSet<"sendgrid", z.ZodObject<{
|
|
174
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
175
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
176
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
177
|
+
global: "global";
|
|
178
|
+
eu: "eu";
|
|
179
|
+
}>>;
|
|
180
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
181
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
182
|
+
}, z.core.$strip>, readonly _keystrokehq_core_credential_set0.CredentialConnection<z.ZodObject<{
|
|
183
|
+
SENDGRID_API_KEY: z.ZodString;
|
|
184
|
+
SENDGRID_SUBUSER: z.ZodOptional<z.ZodString>;
|
|
185
|
+
SENDGRID_ACCOUNT_REGION: z.ZodDefault<z.ZodEnum<{
|
|
186
|
+
global: "global";
|
|
187
|
+
eu: "eu";
|
|
188
|
+
}>>;
|
|
189
|
+
SENDGRID_EVENT_WEBHOOK_PUBLIC_KEY: z.ZodOptional<z.ZodString>;
|
|
190
|
+
SENDGRID_INBOUND_PARSE_TOKEN: z.ZodOptional<z.ZodString>;
|
|
191
|
+
}, z.core.$strip>>[] | undefined>], undefined>;
|
|
192
|
+
//#endregion
|
|
193
|
+
export { createAlert, deleteAlert, getAlert, listAlerts, updateAlert };
|
package/dist/alerts.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { n as __exportAll, t as sendgridOperation } from "./factory-BSL0D2L0.mjs";
|
|
2
|
+
import { n as omitUndefined } from "./shared-CQ8JFNXi.mjs";
|
|
3
|
+
import { createSendGridClient } from "./client.mjs";
|
|
4
|
+
import { $t as sendgridAlertFrequencySchema, en as sendgridAlertListSchema, in as sendgridEmailSchema, nn as sendgridAlertTypeSchema, tn as sendgridAlertSchema } from "./webhooks-CKdsIikb.mjs";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
|
|
7
|
+
//#region src/alerts.ts
|
|
8
|
+
var alerts_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
createAlert: () => createAlert,
|
|
10
|
+
deleteAlert: () => deleteAlert,
|
|
11
|
+
getAlert: () => getAlert,
|
|
12
|
+
listAlerts: () => listAlerts,
|
|
13
|
+
updateAlert: () => updateAlert
|
|
14
|
+
});
|
|
15
|
+
const alertId = z.number().int().positive();
|
|
16
|
+
const alertInput = z.object({
|
|
17
|
+
type: sendgridAlertTypeSchema,
|
|
18
|
+
emailTo: sendgridEmailSchema,
|
|
19
|
+
frequency: sendgridAlertFrequencySchema.optional(),
|
|
20
|
+
percentage: z.number().int().min(1).max(100).optional()
|
|
21
|
+
});
|
|
22
|
+
function mapAlertInput(input) {
|
|
23
|
+
return omitUndefined({
|
|
24
|
+
type: input.type,
|
|
25
|
+
email_to: input.emailTo,
|
|
26
|
+
frequency: input.frequency,
|
|
27
|
+
percentage: input.percentage
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const createAlert = sendgridOperation({
|
|
31
|
+
id: "create_alert",
|
|
32
|
+
name: "Create Alert",
|
|
33
|
+
description: "Create a stats-notification or usage-limit alert.",
|
|
34
|
+
input: alertInput,
|
|
35
|
+
output: sendgridAlertSchema,
|
|
36
|
+
needsApproval: true,
|
|
37
|
+
run: async (input, credentials) => {
|
|
38
|
+
const response = await createSendGridClient(credentials).request("/alerts", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: mapAlertInput(input)
|
|
41
|
+
});
|
|
42
|
+
return sendgridAlertSchema.parse(response);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const updateAlert = sendgridOperation({
|
|
46
|
+
id: "update_alert",
|
|
47
|
+
name: "Update Alert",
|
|
48
|
+
description: "Update an alert.",
|
|
49
|
+
input: alertInput.partial().extend({ alertId }),
|
|
50
|
+
output: sendgridAlertSchema,
|
|
51
|
+
needsApproval: true,
|
|
52
|
+
run: async (input, credentials) => {
|
|
53
|
+
const response = await createSendGridClient(credentials).request(`/alerts/${input.alertId}`, {
|
|
54
|
+
method: "PATCH",
|
|
55
|
+
body: omitUndefined({
|
|
56
|
+
type: input.type,
|
|
57
|
+
email_to: input.emailTo,
|
|
58
|
+
frequency: input.frequency,
|
|
59
|
+
percentage: input.percentage
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
return sendgridAlertSchema.parse(response);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const deleteAlert = sendgridOperation({
|
|
66
|
+
id: "delete_alert",
|
|
67
|
+
name: "Delete Alert",
|
|
68
|
+
description: "Delete an alert.",
|
|
69
|
+
input: z.object({ alertId }),
|
|
70
|
+
output: z.object({ success: z.boolean() }),
|
|
71
|
+
needsApproval: true,
|
|
72
|
+
run: async (input, credentials) => {
|
|
73
|
+
await createSendGridClient(credentials).request(`/alerts/${input.alertId}`, { method: "DELETE" });
|
|
74
|
+
return { success: true };
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const getAlert = sendgridOperation({
|
|
78
|
+
id: "get_alert",
|
|
79
|
+
name: "Get Alert",
|
|
80
|
+
description: "Retrieve a single alert by ID.",
|
|
81
|
+
input: z.object({ alertId }),
|
|
82
|
+
output: sendgridAlertSchema,
|
|
83
|
+
run: async (input, credentials) => {
|
|
84
|
+
const response = await createSendGridClient(credentials).request(`/alerts/${input.alertId}`);
|
|
85
|
+
return sendgridAlertSchema.parse(response);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const listAlerts = sendgridOperation({
|
|
89
|
+
id: "list_alerts",
|
|
90
|
+
name: "List Alerts",
|
|
91
|
+
description: "List all configured alerts.",
|
|
92
|
+
input: z.object({}).optional(),
|
|
93
|
+
output: sendgridAlertListSchema,
|
|
94
|
+
run: async (_input, credentials) => {
|
|
95
|
+
const response = await createSendGridClient(credentials).request("/alerts");
|
|
96
|
+
return sendgridAlertListSchema.parse(response ?? []);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { createAlert, deleteAlert, getAlert, listAlerts, alerts_exports as t, updateAlert };
|