better-auth-lead 0.4.3 → 0.6.0

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,472 @@
1
+ import { InferOptionSchema, StandardSchemaV1 } from "better-auth";
2
+
3
+ //#region src/schema.d.ts
4
+ declare const lead$1: {
5
+ lead: {
6
+ fields: {
7
+ createdAt: {
8
+ type: "date";
9
+ defaultValue: () => Date;
10
+ required: true;
11
+ input: false;
12
+ };
13
+ updatedAt: {
14
+ type: "date";
15
+ defaultValue: () => Date;
16
+ onUpdate: () => Date;
17
+ required: true;
18
+ input: false;
19
+ };
20
+ email: {
21
+ type: "string";
22
+ required: false;
23
+ unique: true;
24
+ };
25
+ userId: {
26
+ type: "string";
27
+ required: false;
28
+ unique: true;
29
+ references: {
30
+ model: string;
31
+ field: string;
32
+ };
33
+ };
34
+ confirmed: {
35
+ type: "boolean";
36
+ defaultValue: false;
37
+ required: true;
38
+ input: false;
39
+ };
40
+ confirmationSentAt: {
41
+ type: "date";
42
+ required: false;
43
+ input: false;
44
+ };
45
+ metadata: {
46
+ type: "string";
47
+ required: false;
48
+ };
49
+ };
50
+ };
51
+ };
52
+ //#endregion
53
+ //#region src/type.d.ts
54
+ interface LeadOptions {
55
+ /**
56
+ * Send a verification email
57
+ * @param data the data object
58
+ * @param request the request object
59
+ */
60
+ sendConfirmationEmail?: (
61
+ /**
62
+ * @param lead the lead to send the confirmation email to
63
+ * @param email the email address to send the confirmation to
64
+ * @param url the confirmation url
65
+ * @param token the confirmation token
66
+ * @param unsubscribeUrl the one-click unsubscribe URL (RFC 8058) to include in List-Unsubscribe headers
67
+ */
68
+
69
+ data: {
70
+ lead: Lead;
71
+ email: string;
72
+ url: string;
73
+ token: string;
74
+ unsubscribeUrl: string;
75
+ }, request?: Request) => Promise<boolean>;
76
+ onConfirmed?: (
77
+ /**
78
+ * @param lead the lead that confirmed their subscription
79
+ */
80
+
81
+ data: {
82
+ lead: Lead;
83
+ }, request?: Request) => Promise<void>;
84
+ /**
85
+ * Number of seconds the confirmation token is
86
+ * valid for.
87
+ * @default 3600 seconds (1 hour)
88
+ */
89
+ expiresIn?: number;
90
+ /**
91
+ * Number of seconds the unsubscribe token is valid for.
92
+ * Should be long-lived since users may click the link long
93
+ * after receiving the email.
94
+ * @default undefined (no expiry)
95
+ */
96
+ unsubscribeExpiresIn?: number;
97
+ /**
98
+ * Rate limit configuration for /lead/subscribe and /lead/resend endpoints.
99
+ */
100
+ rateLimit?: {
101
+ /**
102
+ * Time window in seconds for which the rate limit applies.
103
+ * @default 10 seconds
104
+ */
105
+ window: number;
106
+ /**
107
+ * Maximum number of requests allowed within the time window.
108
+ * @default 3 requests
109
+ */
110
+ max: number;
111
+ };
112
+ /**
113
+ * Schema for the lead plugin
114
+ */
115
+ schema?: InferOptionSchema<typeof lead$1> | undefined;
116
+ metadata?: {
117
+ validationSchema?: StandardSchemaV1;
118
+ };
119
+ /**
120
+ * Admin-only endpoints. Requires the better-auth `admin` plugin to be
121
+ * registered. When enabled, exposes `GET /lead/list` which returns all
122
+ * leads to users whose role matches `admin.roles`.
123
+ */
124
+ admin?: {
125
+ /**
126
+ * Enable admin endpoints (e.g. `/lead/list`).
127
+ * @default false
128
+ */
129
+ enabled?: boolean;
130
+ /**
131
+ * Roles allowed to call admin endpoints. The check is performed against
132
+ * `session.user.role` (added by the admin plugin), which may contain a
133
+ * comma-separated list of roles.
134
+ * @default ['admin']
135
+ */
136
+ roles?: string[];
137
+ };
138
+ }
139
+ interface Lead {
140
+ /**
141
+ * Database identifier
142
+ */
143
+ id: string;
144
+ createdAt: Date;
145
+ updatedAt: Date;
146
+ email: string | null;
147
+ userId: string | null;
148
+ confirmed: boolean;
149
+ confirmationSentAt: Date | null;
150
+ metadata?: string;
151
+ }
152
+ type LeadPayload = {
153
+ email?: string | null;
154
+ userId?: string | null;
155
+ metadata?: string;
156
+ };
157
+ //#endregion
158
+ //#region src/index.d.ts
159
+ declare const lead: <O extends LeadOptions>(options?: O) => {
160
+ id: "lead";
161
+ schema: {
162
+ lead: {
163
+ fields: {
164
+ createdAt: {
165
+ type: "date";
166
+ defaultValue: () => Date;
167
+ required: true;
168
+ input: false;
169
+ };
170
+ updatedAt: {
171
+ type: "date";
172
+ defaultValue: () => Date;
173
+ onUpdate: () => Date;
174
+ required: true;
175
+ input: false;
176
+ };
177
+ email: {
178
+ type: "string";
179
+ required: false;
180
+ unique: true;
181
+ };
182
+ userId: {
183
+ type: "string";
184
+ required: false;
185
+ unique: true;
186
+ references: {
187
+ model: string;
188
+ field: string;
189
+ };
190
+ };
191
+ confirmed: {
192
+ type: "boolean";
193
+ defaultValue: false;
194
+ required: true;
195
+ input: false;
196
+ };
197
+ confirmationSentAt: {
198
+ type: "date";
199
+ required: false;
200
+ input: false;
201
+ };
202
+ metadata: {
203
+ type: "string";
204
+ required: false;
205
+ };
206
+ };
207
+ };
208
+ };
209
+ endpoints: {
210
+ listLeads?: import("better-auth").StrictEndpoint<"/lead/list-leads", {
211
+ method: "GET";
212
+ query: import("zod").ZodObject<{
213
+ searchValue: import("zod").ZodOptional<import("zod").ZodString>;
214
+ searchField: import("zod").ZodOptional<import("zod").ZodEnum<{
215
+ email: "email";
216
+ }>>;
217
+ searchOperator: import("zod").ZodOptional<import("zod").ZodEnum<{
218
+ contains: "contains";
219
+ starts_with: "starts_with";
220
+ ends_with: "ends_with";
221
+ }>>;
222
+ limit: import("zod").ZodOptional<import("zod").ZodCoercedNumber<unknown>>;
223
+ offset: import("zod").ZodOptional<import("zod").ZodCoercedNumber<unknown>>;
224
+ sortBy: import("zod").ZodOptional<import("zod").ZodString>;
225
+ sortDirection: import("zod").ZodOptional<import("zod").ZodEnum<{
226
+ asc: "asc";
227
+ desc: "desc";
228
+ }>>;
229
+ filterField: import("zod").ZodOptional<import("zod").ZodString>;
230
+ filterValue: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodUnion<[import("zod").ZodUnion<[import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodNumber]>, import("zod").ZodBoolean]>, import("zod").ZodArray<import("zod").ZodString>]>, import("zod").ZodArray<import("zod").ZodNumber>]>>;
231
+ filterOperator: import("zod").ZodOptional<import("zod").ZodEnum<{
232
+ in: "in";
233
+ contains: "contains";
234
+ starts_with: "starts_with";
235
+ ends_with: "ends_with";
236
+ eq: "eq";
237
+ ne: "ne";
238
+ lt: "lt";
239
+ lte: "lte";
240
+ gt: "gt";
241
+ gte: "gte";
242
+ not_in: "not_in";
243
+ }>>;
244
+ }, import("better-auth").$strip>;
245
+ use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
246
+ session: {
247
+ session: Record<string, any> & {
248
+ id: string;
249
+ createdAt: Date;
250
+ updatedAt: Date;
251
+ userId: string;
252
+ expiresAt: Date;
253
+ token: string;
254
+ ipAddress?: string | null | undefined;
255
+ userAgent?: string | null | undefined;
256
+ };
257
+ user: Record<string, any> & {
258
+ id: string;
259
+ createdAt: Date;
260
+ updatedAt: Date;
261
+ email: string;
262
+ emailVerified: boolean;
263
+ name: string;
264
+ image?: string | null | undefined;
265
+ };
266
+ };
267
+ }>)[];
268
+ }, {
269
+ leads: Lead[];
270
+ total: number;
271
+ limit: number;
272
+ offset: number;
273
+ }> | undefined;
274
+ getLead?: import("better-auth").StrictEndpoint<"lead/get-lead", {
275
+ method: "POST";
276
+ query: import("zod").ZodObject<{
277
+ id: import("zod").ZodString;
278
+ }, import("better-auth").$strip>;
279
+ use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
280
+ session: {
281
+ session: Record<string, any> & {
282
+ id: string;
283
+ createdAt: Date;
284
+ updatedAt: Date;
285
+ userId: string;
286
+ expiresAt: Date;
287
+ token: string;
288
+ ipAddress?: string | null | undefined;
289
+ userAgent?: string | null | undefined;
290
+ };
291
+ user: Record<string, any> & {
292
+ id: string;
293
+ createdAt: Date;
294
+ updatedAt: Date;
295
+ email: string;
296
+ emailVerified: boolean;
297
+ name: string;
298
+ image?: string | null | undefined;
299
+ };
300
+ };
301
+ }>)[];
302
+ }, Lead> | undefined;
303
+ removeLead?: import("better-auth").StrictEndpoint<"lead/remove-lead", {
304
+ method: "POST";
305
+ body: import("zod").ZodObject<{
306
+ leadId: import("zod").ZodCoercedString<unknown>;
307
+ }, import("better-auth").$strip>;
308
+ use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
309
+ session: {
310
+ session: Record<string, any> & {
311
+ id: string;
312
+ createdAt: Date;
313
+ updatedAt: Date;
314
+ userId: string;
315
+ expiresAt: Date;
316
+ token: string;
317
+ ipAddress?: string | null | undefined;
318
+ userAgent?: string | null | undefined;
319
+ };
320
+ user: Record<string, any> & {
321
+ id: string;
322
+ createdAt: Date;
323
+ updatedAt: Date;
324
+ email: string;
325
+ emailVerified: boolean;
326
+ name: string;
327
+ image?: string | null | undefined;
328
+ };
329
+ };
330
+ }>)[];
331
+ }, {
332
+ success: boolean;
333
+ }> | undefined;
334
+ subscribe: import("better-auth").StrictEndpoint<"/lead/subscribe", {
335
+ method: "POST";
336
+ body: import("zod").ZodObject<{
337
+ email: import("zod").ZodOptional<import("zod").ZodString>;
338
+ metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
339
+ }, import("better-auth").$strip>;
340
+ metadata: {
341
+ $Infer: {
342
+ body: {
343
+ email?: string;
344
+ metadata?: (O extends {
345
+ metadata: {
346
+ validationSchema: import("better-auth").StandardSchemaV1<unknown, infer Out>;
347
+ };
348
+ } ? Out : Record<string, any>) | undefined;
349
+ };
350
+ };
351
+ };
352
+ }, {
353
+ status: boolean;
354
+ }>;
355
+ verify: import("better-auth").StrictEndpoint<"/lead/verify", {
356
+ method: "GET";
357
+ query: import("zod").ZodObject<{
358
+ token: import("zod").ZodString;
359
+ }, import("better-auth").$strip>;
360
+ }, {
361
+ status: boolean;
362
+ }>;
363
+ unsubscribe: import("better-auth").StrictEndpoint<"/lead/unsubscribe", {
364
+ method: "POST";
365
+ query: import("zod").ZodObject<{
366
+ token: import("zod").ZodString;
367
+ }, import("better-auth").$strip>;
368
+ metadata: {
369
+ allowedMediaTypes: never[];
370
+ };
371
+ }, {
372
+ status: boolean;
373
+ }>;
374
+ unsubscribeSession: import("better-auth").StrictEndpoint<"/lead/unsubscribe-session", {
375
+ method: "POST";
376
+ use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
377
+ session: {
378
+ session: Record<string, any> & {
379
+ id: string;
380
+ createdAt: Date;
381
+ updatedAt: Date;
382
+ userId: string;
383
+ expiresAt: Date;
384
+ token: string;
385
+ ipAddress?: string | null | undefined;
386
+ userAgent?: string | null | undefined;
387
+ };
388
+ user: Record<string, any> & {
389
+ id: string;
390
+ createdAt: Date;
391
+ updatedAt: Date;
392
+ email: string;
393
+ emailVerified: boolean;
394
+ name: string;
395
+ image?: string | null | undefined;
396
+ };
397
+ };
398
+ }>)[];
399
+ }, {
400
+ status: boolean;
401
+ }>;
402
+ resend: import("better-auth").StrictEndpoint<"/lead/resend", {
403
+ method: "POST";
404
+ body: import("zod").ZodObject<{
405
+ email: import("zod").ZodOptional<import("zod").ZodString>;
406
+ }, import("better-auth").$strip>;
407
+ }, {
408
+ status: boolean;
409
+ }>;
410
+ update: import("better-auth").StrictEndpoint<"/lead/update", {
411
+ method: "POST";
412
+ body: import("zod").ZodObject<{
413
+ metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodAny>>;
414
+ }, import("better-auth").$strip>;
415
+ use: ((inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
416
+ session: {
417
+ session: Record<string, any> & {
418
+ id: string;
419
+ createdAt: Date;
420
+ updatedAt: Date;
421
+ userId: string;
422
+ expiresAt: Date;
423
+ token: string;
424
+ ipAddress?: string | null | undefined;
425
+ userAgent?: string | null | undefined;
426
+ };
427
+ user: Record<string, any> & {
428
+ id: string;
429
+ createdAt: Date;
430
+ updatedAt: Date;
431
+ email: string;
432
+ emailVerified: boolean;
433
+ name: string;
434
+ image?: string | null | undefined;
435
+ };
436
+ };
437
+ }>)[];
438
+ metadata: {
439
+ $Infer: {
440
+ body: {
441
+ metadata?: (O extends {
442
+ metadata: {
443
+ validationSchema: import("better-auth").StandardSchemaV1<unknown, infer Out>;
444
+ };
445
+ } ? Out : Record<string, any>) | undefined;
446
+ };
447
+ };
448
+ };
449
+ }, {
450
+ status: boolean;
451
+ }>;
452
+ };
453
+ options: NoInfer<O>;
454
+ rateLimit: {
455
+ pathMatcher: (path: string) => boolean;
456
+ window: number;
457
+ max: number;
458
+ }[];
459
+ $ERROR_CODES: {
460
+ FORBIDDEN: import("better-auth").RawError<"FORBIDDEN">;
461
+ INVALID_EMAIL: import("better-auth").RawError<"INVALID_EMAIL">;
462
+ INVALID_TOKEN: import("better-auth").RawError<"INVALID_TOKEN">;
463
+ TOKEN_EXPIRED: import("better-auth").RawError<"TOKEN_EXPIRED">;
464
+ INVALID_METADATA: import("better-auth").RawError<"INVALID_METADATA">;
465
+ EMAIL_OR_SESSION_REQUIRED: import("better-auth").RawError<"EMAIL_OR_SESSION_REQUIRED">;
466
+ ADMIN_PLUGIN_REQUIRED: import("better-auth").RawError<"ADMIN_PLUGIN_REQUIRED">;
467
+ LEAD_NOT_FOUND: import("better-auth").RawError<"LEAD_NOT_FOUND">;
468
+ };
469
+ };
470
+ //#endregion
471
+ export { LeadPayload as i, Lead as n, LeadOptions as r, lead as t };
472
+ //# sourceMappingURL=index-BX1SlAVz.d.mts.map
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as LeadPayload, n as Lead, r as LeadOptions, t as lead } from "./index-P6m89iLp.mjs";
1
+ import { i as LeadPayload, n as Lead, r as LeadOptions, t as lead } from "./index-BX1SlAVz.mjs";
2
2
  export { type Lead, type LeadOptions, type LeadPayload, lead };