@kizunajs/resend 2.0.0-beta.12

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.
@@ -0,0 +1,262 @@
1
+ import * as _$resend from "resend";
2
+ import { CreateBroadcastOptions, CreateEmailOptions, ErrorResponse, Resend, ResendOptions, WebhookEvent, WebhookEventPayload } from "resend";
3
+ import * as _$kizunajs from "kizunajs";
4
+ import * as _$kizunajs_plugin0 from "kizunajs/plugin";
5
+ import { ApiContext, PluginRoutes } from "kizunajs/plugin";
6
+ import { z } from "zod";
7
+
8
+ //#region src/webhooks.d.ts
9
+ /**
10
+ * What a webhook event's function receives.
11
+ */
12
+ type ResendEventContext<Type extends WebhookEvent, Config = unknown> = ApiContext<Config> & {
13
+ event: Extract<WebhookEventPayload, {
14
+ type: Type;
15
+ }>;
16
+ /**
17
+ * The same on every delivery of one event.
18
+ */
19
+ deliveryId: string;
20
+ };
21
+ /**
22
+ * A method, so a function typed from the app's `Config` still fits `on`.
23
+ */
24
+ type EventHandler<Context> = {
25
+ handle(context: Context): Promise<void> | void;
26
+ }['handle'];
27
+ /**
28
+ * What runs for each webhook event, keyed by its type.
29
+ */
30
+ type ResendEventHandlers<Config = unknown> = { [Type in WebhookEvent]?: EventHandler<ResendEventContext<Type, Config>> };
31
+ /**
32
+ * The webhook event functions, with `jobs` and `plugins` typed from `Config`.
33
+ *
34
+ * @example
35
+ * export const resendEvents = defineResendEvents<Config>({
36
+ * 'email.bounced': async ({ event, jobs }) => {
37
+ * await jobs.users.markUndeliverable.queue({
38
+ * input: {
39
+ * email: event.data.to[0],
40
+ * },
41
+ * });
42
+ * },
43
+ * });
44
+ */
45
+ declare const defineResendEvents: <Config = unknown>(handlers: ResendEventHandlers<Config>) => ResendEventHandlers<Config>;
46
+ //#endregion
47
+ //#region src/options.d.ts
48
+ /**
49
+ * A list an app sends to: the Resend segment its contacts sit in, and the topic
50
+ * they opt in and out of.
51
+ */
52
+ declare const ResendListSchema: z.ZodObject<{
53
+ segmentId: z.ZodString;
54
+ topicId: z.ZodOptional<z.ZodString>;
55
+ }, z.core.$strip>;
56
+ declare const ResendPluginOptionsSchema: z.ZodObject<{
57
+ apiKey: z.ZodString;
58
+ from: z.ZodString;
59
+ lists: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
60
+ segmentId: z.ZodString;
61
+ topicId: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strip>>>;
63
+ webhookSecret: z.ZodOptional<z.ZodString>;
64
+ on: z.ZodOptional<z.ZodCustom<ResendEventHandlers, ResendEventHandlers>>;
65
+ intercept: z.ZodOptional<z.ZodObject<{
66
+ enabled: z.ZodBoolean;
67
+ forwardTo: z.ZodOptional<z.ZodUnion<readonly [z.ZodEmail, z.ZodArray<z.ZodEmail>]>>;
68
+ deliverTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
+ subjectPrefix: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strip>>;
71
+ resend: z.ZodOptional<z.ZodCustom<ResendOptions, ResendOptions>>;
72
+ }, z.core.$strip>;
73
+ type ResendPluginProps = z.output<typeof ResendPluginOptionsSchema>;
74
+ type ResendList = z.output<typeof ResendListSchema>;
75
+ //#endregion
76
+ //#region src/requests.d.ts
77
+ /**
78
+ * A call to Resend that answered with an error.
79
+ */
80
+ declare class ResendRequestError extends Error {
81
+ readonly action: string;
82
+ readonly error: ErrorResponse;
83
+ constructor(action: string, error: ErrorResponse);
84
+ }
85
+ type DistributiveOmit<Value, Key extends PropertyKey> = Value extends unknown ? Omit<Value, Key> : never;
86
+ /**
87
+ * An email, with `from` falling back to the plugin's.
88
+ */
89
+ type ResendEmail = DistributiveOmit<CreateEmailOptions, 'from'> & {
90
+ from?: string;
91
+ };
92
+ /**
93
+ * A broadcast to one of the plugin's lists, with `from` falling back to the
94
+ * plugin's.
95
+ */
96
+ type ResendBroadcast = DistributiveOmit<CreateBroadcastOptions, 'from' | 'segmentId' | 'audienceId' | 'topicId' | 'send' | 'scheduledAt'> & {
97
+ /**
98
+ * The list it goes to.
99
+ */
100
+ list: string;
101
+ from?: string;
102
+ /**
103
+ * When to send it, as an ISO 8601 date or a relative time like `in 2 days`.
104
+ * Leave it out to send now.
105
+ */
106
+ scheduledAt?: string;
107
+ };
108
+ interface ResendSubscriber {
109
+ email: string;
110
+ /**
111
+ * The list they join.
112
+ */
113
+ list: string;
114
+ firstName?: string;
115
+ lastName?: string;
116
+ }
117
+ interface ResendEmailChange {
118
+ /**
119
+ * The contact's current address.
120
+ */
121
+ from: string;
122
+ /**
123
+ * Its new address.
124
+ */
125
+ to: string;
126
+ }
127
+ interface ResendUnsubscriber {
128
+ email: string;
129
+ /**
130
+ * The list they leave. Leave it out to unsubscribe them from everything.
131
+ */
132
+ list?: string;
133
+ }
134
+ //#endregion
135
+ //#region src/plugin.d.ts
136
+ /**
137
+ * Send email, run newsletters and broadcasts, and receive webhooks through
138
+ * Resend. Handlers reach it at `plugins.resend`.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * export default defineConfig({
143
+ * routes,
144
+ * plugins: [
145
+ * resendPlugin({
146
+ * apiKey: process.env.RESEND_API_KEY,
147
+ * from: 'Kizuna <hello@example.com>',
148
+ * }),
149
+ * ],
150
+ * });
151
+ * ```
152
+ */
153
+ declare const resendPlugin: {
154
+ <const Slug extends string>(options: {
155
+ apiKey: string;
156
+ from: string;
157
+ lists?: Record<string, {
158
+ segmentId: string;
159
+ topicId?: string | undefined;
160
+ }> | undefined;
161
+ webhookSecret?: string | undefined;
162
+ on?: ResendEventHandlers | undefined;
163
+ intercept?: {
164
+ enabled: boolean;
165
+ forwardTo?: string | string[] | undefined;
166
+ deliverTo?: string[] | undefined;
167
+ subjectPrefix?: string | undefined;
168
+ } | undefined;
169
+ resend?: _$resend.ResendOptions | undefined;
170
+ } & {
171
+ basePath?: _$kizunajs.RoutePath;
172
+ } & _$kizunajs_plugin0.SlugOption<Slug>): _$kizunajs.PluginDeclaration<Slug, {
173
+ exports: {
174
+ client: Resend;
175
+ sendEmail: (email: ResendEmail) => Promise<{
176
+ id: string;
177
+ }>;
178
+ subscribe: ({
179
+ email,
180
+ list: name,
181
+ firstName,
182
+ lastName
183
+ }: ResendSubscriber) => Promise<{
184
+ contactId: string;
185
+ }>;
186
+ changeEmail: ({
187
+ from,
188
+ to
189
+ }: ResendEmailChange) => Promise<{
190
+ contactId: string;
191
+ }>;
192
+ unsubscribe: ({
193
+ email,
194
+ list: name
195
+ }: ResendUnsubscriber) => Promise<void>;
196
+ sendBroadcast: ({
197
+ list: name,
198
+ from,
199
+ scheduledAt,
200
+ ...content
201
+ }: ResendBroadcast) => Promise<{
202
+ id: string;
203
+ }>;
204
+ };
205
+ routes: PluginRoutes;
206
+ }>;
207
+ (options: {
208
+ apiKey: string;
209
+ from: string;
210
+ lists?: Record<string, {
211
+ segmentId: string;
212
+ topicId?: string | undefined;
213
+ }> | undefined;
214
+ webhookSecret?: string | undefined;
215
+ on?: ResendEventHandlers | undefined;
216
+ intercept?: {
217
+ enabled: boolean;
218
+ forwardTo?: string | string[] | undefined;
219
+ deliverTo?: string[] | undefined;
220
+ subjectPrefix?: string | undefined;
221
+ } | undefined;
222
+ resend?: _$resend.ResendOptions | undefined;
223
+ } & {
224
+ basePath?: _$kizunajs.RoutePath;
225
+ }): _$kizunajs.PluginDeclaration<"resend", {
226
+ exports: {
227
+ client: Resend;
228
+ sendEmail: (email: ResendEmail) => Promise<{
229
+ id: string;
230
+ }>;
231
+ subscribe: ({
232
+ email,
233
+ list: name,
234
+ firstName,
235
+ lastName
236
+ }: ResendSubscriber) => Promise<{
237
+ contactId: string;
238
+ }>;
239
+ changeEmail: ({
240
+ from,
241
+ to
242
+ }: ResendEmailChange) => Promise<{
243
+ contactId: string;
244
+ }>;
245
+ unsubscribe: ({
246
+ email,
247
+ list: name
248
+ }: ResendUnsubscriber) => Promise<void>;
249
+ sendBroadcast: ({
250
+ list: name,
251
+ from,
252
+ scheduledAt,
253
+ ...content
254
+ }: ResendBroadcast) => Promise<{
255
+ id: string;
256
+ }>;
257
+ };
258
+ routes: PluginRoutes;
259
+ }>;
260
+ };
261
+ //#endregion
262
+ export { type ResendBroadcast, type ResendEmail, type ResendEmailChange, type ResendEventContext, type ResendEventHandlers, type ResendList, ResendListSchema, ResendPluginOptionsSchema, type ResendPluginProps, ResendRequestError, type ResendSubscriber, type ResendUnsubscriber, defineResendEvents, resendPlugin };
@@ -0,0 +1,262 @@
1
+ import * as _$resend from "resend";
2
+ import { CreateBroadcastOptions, CreateEmailOptions, ErrorResponse, Resend, ResendOptions, WebhookEvent, WebhookEventPayload } from "resend";
3
+ import * as _$kizunajs_plugin0 from "kizunajs/plugin";
4
+ import { ApiContext, PluginRoutes } from "kizunajs/plugin";
5
+ import { z } from "zod";
6
+ import * as _$kizunajs from "kizunajs";
7
+
8
+ //#region src/webhooks.d.ts
9
+ /**
10
+ * What a webhook event's function receives.
11
+ */
12
+ type ResendEventContext<Type extends WebhookEvent, Config = unknown> = ApiContext<Config> & {
13
+ event: Extract<WebhookEventPayload, {
14
+ type: Type;
15
+ }>;
16
+ /**
17
+ * The same on every delivery of one event.
18
+ */
19
+ deliveryId: string;
20
+ };
21
+ /**
22
+ * A method, so a function typed from the app's `Config` still fits `on`.
23
+ */
24
+ type EventHandler<Context> = {
25
+ handle(context: Context): Promise<void> | void;
26
+ }['handle'];
27
+ /**
28
+ * What runs for each webhook event, keyed by its type.
29
+ */
30
+ type ResendEventHandlers<Config = unknown> = { [Type in WebhookEvent]?: EventHandler<ResendEventContext<Type, Config>> };
31
+ /**
32
+ * The webhook event functions, with `jobs` and `plugins` typed from `Config`.
33
+ *
34
+ * @example
35
+ * export const resendEvents = defineResendEvents<Config>({
36
+ * 'email.bounced': async ({ event, jobs }) => {
37
+ * await jobs.users.markUndeliverable.queue({
38
+ * input: {
39
+ * email: event.data.to[0],
40
+ * },
41
+ * });
42
+ * },
43
+ * });
44
+ */
45
+ declare const defineResendEvents: <Config = unknown>(handlers: ResendEventHandlers<Config>) => ResendEventHandlers<Config>;
46
+ //#endregion
47
+ //#region src/options.d.ts
48
+ /**
49
+ * A list an app sends to: the Resend segment its contacts sit in, and the topic
50
+ * they opt in and out of.
51
+ */
52
+ declare const ResendListSchema: z.ZodObject<{
53
+ segmentId: z.ZodString;
54
+ topicId: z.ZodOptional<z.ZodString>;
55
+ }, z.core.$strip>;
56
+ declare const ResendPluginOptionsSchema: z.ZodObject<{
57
+ apiKey: z.ZodString;
58
+ from: z.ZodString;
59
+ lists: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
60
+ segmentId: z.ZodString;
61
+ topicId: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strip>>>;
63
+ webhookSecret: z.ZodOptional<z.ZodString>;
64
+ on: z.ZodOptional<z.ZodCustom<ResendEventHandlers, ResendEventHandlers>>;
65
+ intercept: z.ZodOptional<z.ZodObject<{
66
+ enabled: z.ZodBoolean;
67
+ forwardTo: z.ZodOptional<z.ZodUnion<readonly [z.ZodEmail, z.ZodArray<z.ZodEmail>]>>;
68
+ deliverTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
69
+ subjectPrefix: z.ZodOptional<z.ZodString>;
70
+ }, z.core.$strip>>;
71
+ resend: z.ZodOptional<z.ZodCustom<ResendOptions, ResendOptions>>;
72
+ }, z.core.$strip>;
73
+ type ResendPluginProps = z.output<typeof ResendPluginOptionsSchema>;
74
+ type ResendList = z.output<typeof ResendListSchema>;
75
+ //#endregion
76
+ //#region src/requests.d.ts
77
+ /**
78
+ * A call to Resend that answered with an error.
79
+ */
80
+ declare class ResendRequestError extends Error {
81
+ readonly action: string;
82
+ readonly error: ErrorResponse;
83
+ constructor(action: string, error: ErrorResponse);
84
+ }
85
+ type DistributiveOmit<Value, Key extends PropertyKey> = Value extends unknown ? Omit<Value, Key> : never;
86
+ /**
87
+ * An email, with `from` falling back to the plugin's.
88
+ */
89
+ type ResendEmail = DistributiveOmit<CreateEmailOptions, 'from'> & {
90
+ from?: string;
91
+ };
92
+ /**
93
+ * A broadcast to one of the plugin's lists, with `from` falling back to the
94
+ * plugin's.
95
+ */
96
+ type ResendBroadcast = DistributiveOmit<CreateBroadcastOptions, 'from' | 'segmentId' | 'audienceId' | 'topicId' | 'send' | 'scheduledAt'> & {
97
+ /**
98
+ * The list it goes to.
99
+ */
100
+ list: string;
101
+ from?: string;
102
+ /**
103
+ * When to send it, as an ISO 8601 date or a relative time like `in 2 days`.
104
+ * Leave it out to send now.
105
+ */
106
+ scheduledAt?: string;
107
+ };
108
+ interface ResendSubscriber {
109
+ email: string;
110
+ /**
111
+ * The list they join.
112
+ */
113
+ list: string;
114
+ firstName?: string;
115
+ lastName?: string;
116
+ }
117
+ interface ResendEmailChange {
118
+ /**
119
+ * The contact's current address.
120
+ */
121
+ from: string;
122
+ /**
123
+ * Its new address.
124
+ */
125
+ to: string;
126
+ }
127
+ interface ResendUnsubscriber {
128
+ email: string;
129
+ /**
130
+ * The list they leave. Leave it out to unsubscribe them from everything.
131
+ */
132
+ list?: string;
133
+ }
134
+ //#endregion
135
+ //#region src/plugin.d.ts
136
+ /**
137
+ * Send email, run newsletters and broadcasts, and receive webhooks through
138
+ * Resend. Handlers reach it at `plugins.resend`.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * export default defineConfig({
143
+ * routes,
144
+ * plugins: [
145
+ * resendPlugin({
146
+ * apiKey: process.env.RESEND_API_KEY,
147
+ * from: 'Kizuna <hello@example.com>',
148
+ * }),
149
+ * ],
150
+ * });
151
+ * ```
152
+ */
153
+ declare const resendPlugin: {
154
+ <const Slug extends string>(options: {
155
+ apiKey: string;
156
+ from: string;
157
+ lists?: Record<string, {
158
+ segmentId: string;
159
+ topicId?: string | undefined;
160
+ }> | undefined;
161
+ webhookSecret?: string | undefined;
162
+ on?: ResendEventHandlers | undefined;
163
+ intercept?: {
164
+ enabled: boolean;
165
+ forwardTo?: string | string[] | undefined;
166
+ deliverTo?: string[] | undefined;
167
+ subjectPrefix?: string | undefined;
168
+ } | undefined;
169
+ resend?: _$resend.ResendOptions | undefined;
170
+ } & {
171
+ basePath?: _$kizunajs.RoutePath;
172
+ } & _$kizunajs_plugin0.SlugOption<Slug>): _$kizunajs.PluginDeclaration<Slug, {
173
+ exports: {
174
+ client: Resend;
175
+ sendEmail: (email: ResendEmail) => Promise<{
176
+ id: string;
177
+ }>;
178
+ subscribe: ({
179
+ email,
180
+ list: name,
181
+ firstName,
182
+ lastName
183
+ }: ResendSubscriber) => Promise<{
184
+ contactId: string;
185
+ }>;
186
+ changeEmail: ({
187
+ from,
188
+ to
189
+ }: ResendEmailChange) => Promise<{
190
+ contactId: string;
191
+ }>;
192
+ unsubscribe: ({
193
+ email,
194
+ list: name
195
+ }: ResendUnsubscriber) => Promise<void>;
196
+ sendBroadcast: ({
197
+ list: name,
198
+ from,
199
+ scheduledAt,
200
+ ...content
201
+ }: ResendBroadcast) => Promise<{
202
+ id: string;
203
+ }>;
204
+ };
205
+ routes: PluginRoutes;
206
+ }>;
207
+ (options: {
208
+ apiKey: string;
209
+ from: string;
210
+ lists?: Record<string, {
211
+ segmentId: string;
212
+ topicId?: string | undefined;
213
+ }> | undefined;
214
+ webhookSecret?: string | undefined;
215
+ on?: ResendEventHandlers | undefined;
216
+ intercept?: {
217
+ enabled: boolean;
218
+ forwardTo?: string | string[] | undefined;
219
+ deliverTo?: string[] | undefined;
220
+ subjectPrefix?: string | undefined;
221
+ } | undefined;
222
+ resend?: _$resend.ResendOptions | undefined;
223
+ } & {
224
+ basePath?: _$kizunajs.RoutePath;
225
+ }): _$kizunajs.PluginDeclaration<"resend", {
226
+ exports: {
227
+ client: Resend;
228
+ sendEmail: (email: ResendEmail) => Promise<{
229
+ id: string;
230
+ }>;
231
+ subscribe: ({
232
+ email,
233
+ list: name,
234
+ firstName,
235
+ lastName
236
+ }: ResendSubscriber) => Promise<{
237
+ contactId: string;
238
+ }>;
239
+ changeEmail: ({
240
+ from,
241
+ to
242
+ }: ResendEmailChange) => Promise<{
243
+ contactId: string;
244
+ }>;
245
+ unsubscribe: ({
246
+ email,
247
+ list: name
248
+ }: ResendUnsubscriber) => Promise<void>;
249
+ sendBroadcast: ({
250
+ list: name,
251
+ from,
252
+ scheduledAt,
253
+ ...content
254
+ }: ResendBroadcast) => Promise<{
255
+ id: string;
256
+ }>;
257
+ };
258
+ routes: PluginRoutes;
259
+ }>;
260
+ };
261
+ //#endregion
262
+ export { type ResendBroadcast, type ResendEmail, type ResendEmailChange, type ResendEventContext, type ResendEventHandlers, type ResendList, ResendListSchema, ResendPluginOptionsSchema, type ResendPluginProps, ResendRequestError, type ResendSubscriber, type ResendUnsubscriber, defineResendEvents, resendPlugin };