@checodo/better-auth-referral 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +7 -0
- package/LICENSE.md +21 -0
- package/README.md +53 -2
- package/dist/client.d.ts +41 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +39 -0
- package/dist/client.js.map +1 -0
- package/dist/error-codes-Bw554PRu.js +12 -0
- package/dist/error-codes-Bw554PRu.js.map +1 -0
- package/dist/index-HDtManYT.d.ts +777 -0
- package/dist/index-HDtManYT.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +957 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -3
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
import { GenericEndpointContext } from "@better-auth/core";
|
|
2
|
+
import { InferOptionSchema } from "better-auth";
|
|
3
|
+
declare const referralSchema: {
|
|
4
|
+
/** One code per user. */
|
|
5
|
+
referralCode: {
|
|
6
|
+
fields: {
|
|
7
|
+
userId: {
|
|
8
|
+
type: "string";
|
|
9
|
+
required: true;
|
|
10
|
+
references: {
|
|
11
|
+
model: string;
|
|
12
|
+
field: string;
|
|
13
|
+
onDelete: "cascade";
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/** Uppercase. */
|
|
17
|
+
code: {
|
|
18
|
+
type: "string";
|
|
19
|
+
required: true;
|
|
20
|
+
};
|
|
21
|
+
createdAt: {
|
|
22
|
+
type: "date";
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
indexes: {
|
|
27
|
+
fields: [string];
|
|
28
|
+
unique: true;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
/** Who referred whom. A user is referred at most once. */
|
|
32
|
+
referral: {
|
|
33
|
+
fields: {
|
|
34
|
+
referrerUserId: {
|
|
35
|
+
type: "string";
|
|
36
|
+
required: true;
|
|
37
|
+
index: true;
|
|
38
|
+
references: {
|
|
39
|
+
model: string;
|
|
40
|
+
field: string;
|
|
41
|
+
onDelete: "cascade";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
referredUserId: {
|
|
45
|
+
type: "string";
|
|
46
|
+
required: true;
|
|
47
|
+
references: {
|
|
48
|
+
model: string;
|
|
49
|
+
field: string;
|
|
50
|
+
onDelete: "cascade";
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/** The code used at sign-up, kept even if the code changes. */
|
|
54
|
+
code: {
|
|
55
|
+
type: "string";
|
|
56
|
+
required: true;
|
|
57
|
+
};
|
|
58
|
+
/** "pending" | "completed" */
|
|
59
|
+
status: {
|
|
60
|
+
type: "string";
|
|
61
|
+
required: true;
|
|
62
|
+
index: true;
|
|
63
|
+
};
|
|
64
|
+
completedAt: {
|
|
65
|
+
type: "date";
|
|
66
|
+
required: false;
|
|
67
|
+
};
|
|
68
|
+
createdAt: {
|
|
69
|
+
type: "date";
|
|
70
|
+
required: true;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
indexes: {
|
|
74
|
+
fields: [string];
|
|
75
|
+
unique: true;
|
|
76
|
+
}[];
|
|
77
|
+
};
|
|
78
|
+
/** Steps a referred user has completed. Each step counts once. */
|
|
79
|
+
referralStep: {
|
|
80
|
+
fields: {
|
|
81
|
+
referralId: {
|
|
82
|
+
type: "string";
|
|
83
|
+
required: true;
|
|
84
|
+
references: {
|
|
85
|
+
model: string;
|
|
86
|
+
field: string;
|
|
87
|
+
onDelete: "cascade";
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
step: {
|
|
91
|
+
type: "string";
|
|
92
|
+
required: true;
|
|
93
|
+
};
|
|
94
|
+
/** JSON-encoded. */
|
|
95
|
+
metadata: {
|
|
96
|
+
type: "string";
|
|
97
|
+
required: false;
|
|
98
|
+
};
|
|
99
|
+
completedAt: {
|
|
100
|
+
type: "date";
|
|
101
|
+
required: true;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
indexes: {
|
|
105
|
+
fields: [string, string];
|
|
106
|
+
unique: true;
|
|
107
|
+
}[];
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
type ReferralSchema = typeof referralSchema;
|
|
111
|
+
/**
|
|
112
|
+
* - `pending` the referred user signed up; required `steps` are still open
|
|
113
|
+
* - `completed` every required step is done; `onReferralCompleted` has run
|
|
114
|
+
*/
|
|
115
|
+
type ReferralStatus = "pending" | "completed";
|
|
116
|
+
/** A user's referral code, as stored in the `referralCode` table. */
|
|
117
|
+
interface ReferralCode {
|
|
118
|
+
id: string;
|
|
119
|
+
userId: string;
|
|
120
|
+
/** Uppercase. */
|
|
121
|
+
code: string;
|
|
122
|
+
createdAt: Date;
|
|
123
|
+
}
|
|
124
|
+
/** A referral, as stored in the `referral` table. */
|
|
125
|
+
interface Referral {
|
|
126
|
+
id: string;
|
|
127
|
+
/** The user whose code was used. */
|
|
128
|
+
referrerUserId: string;
|
|
129
|
+
/** The user who signed up with it. Unique: a user is referred at most once. */
|
|
130
|
+
referredUserId: string;
|
|
131
|
+
/** The code used at sign-up. */
|
|
132
|
+
code: string;
|
|
133
|
+
status: ReferralStatus;
|
|
134
|
+
completedAt?: Date | null | undefined;
|
|
135
|
+
createdAt: Date;
|
|
136
|
+
}
|
|
137
|
+
/** A completed step of a referral, as stored in the `referralStep` table. */
|
|
138
|
+
interface ReferralStep {
|
|
139
|
+
id: string;
|
|
140
|
+
referralId: string;
|
|
141
|
+
step: string;
|
|
142
|
+
/** JSON-encoded `metadata` passed when the step was completed. */
|
|
143
|
+
metadata?: string | null | undefined;
|
|
144
|
+
completedAt: Date;
|
|
145
|
+
}
|
|
146
|
+
/** A referral with the steps completed so far. */
|
|
147
|
+
interface ReferralWithSteps extends Referral {
|
|
148
|
+
steps: string[];
|
|
149
|
+
}
|
|
150
|
+
/** What `allowReferral` decides on. */
|
|
151
|
+
interface ReferralCandidate {
|
|
152
|
+
referrerUserId: string;
|
|
153
|
+
referredUser: {
|
|
154
|
+
id: string;
|
|
155
|
+
email: string;
|
|
156
|
+
};
|
|
157
|
+
code: string;
|
|
158
|
+
/** The request that created the user, `null` outside a request. */
|
|
159
|
+
context: GenericEndpointContext | null;
|
|
160
|
+
}
|
|
161
|
+
interface ReferralOptions {
|
|
162
|
+
/** Length of generated codes. Between 6 and 32. Defaults to `8`. */
|
|
163
|
+
codeLength?: number | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Generates codes instead of the built-in generator (random, without
|
|
166
|
+
* look-alike characters such as `0`/`O` and `1`/`I`). Codes may use
|
|
167
|
+
* letters, digits, `-`, and `_` (4 to 64 characters) and are stored in
|
|
168
|
+
* uppercase. Collisions are retried.
|
|
169
|
+
*/
|
|
170
|
+
generateCode?: (() => string | Promise<string>) | undefined;
|
|
171
|
+
/** Give every new user a code when they sign up, not only on `createCode`. Defaults to `false`. */
|
|
172
|
+
createCodeOnSignUp?: boolean | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Steps a referred user must complete before the referral counts, after
|
|
175
|
+
* signing up, e.g. `["email-verified", "first-purchase"]`.
|
|
176
|
+
* `"email-verified"` is recorded automatically when the user's email is
|
|
177
|
+
* verified; record your own steps with `auth.api.completeReferralStep`.
|
|
178
|
+
* With `[]`, a referral completes at sign-up, which makes fake sign-ups
|
|
179
|
+
* worth rewards.
|
|
180
|
+
*
|
|
181
|
+
* Defaults to `["email-verified"]` when the app sends verification emails
|
|
182
|
+
* (`emailVerification.sendVerificationEmail`), otherwise to `[]`.
|
|
183
|
+
*/
|
|
184
|
+
steps?: readonly string[] | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* How many users one user can refer, across all their codes:
|
|
187
|
+
* `regenerateCode` doesn't reset the count. Unlimited by default.
|
|
188
|
+
*/
|
|
189
|
+
maxReferralsPerUser?: number | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* What happens when someone signs up with a code that doesn't exist or
|
|
192
|
+
* whose owner has reached `maxReferralsPerUser`: `"ignore"` signs them up without a
|
|
193
|
+
* referral, `"reject"` fails the sign-up with `INVALID_REFERRAL_CODE`.
|
|
194
|
+
* Defaults to `"ignore"`.
|
|
195
|
+
*/
|
|
196
|
+
invalidCode?: "ignore" | "reject" | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Decides whether a sign-up with a valid code counts as a referral, e.g.
|
|
199
|
+
* to skip sign-ups from the referrer's own IP address. Returning `false`
|
|
200
|
+
* (or throwing, which is logged) signs the user up without a referral.
|
|
201
|
+
*/
|
|
202
|
+
allowReferral?: ((candidate: ReferralCandidate) => boolean | Promise<boolean>) | undefined;
|
|
203
|
+
/** Called when a referral is recorded at sign-up. Errors are logged. */
|
|
204
|
+
onReferral?: ((referral: Referral) => void | Promise<void>) | undefined;
|
|
205
|
+
/** Called when a step of a referral is completed for the first time. Errors are logged. */
|
|
206
|
+
onStepCompleted?: ((details: {
|
|
207
|
+
referral: Referral;
|
|
208
|
+
step: string;
|
|
209
|
+
}) => void | Promise<void>) | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* Called once per referral, when every required step is done: grant
|
|
212
|
+
* rewards here. Errors are logged.
|
|
213
|
+
*/
|
|
214
|
+
onReferralCompleted?: ((referral: Referral) => void | Promise<void>) | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Show referrers the emails of the users they referred only masked
|
|
217
|
+
* (`a***@example.com`). Defaults to `true`.
|
|
218
|
+
*/
|
|
219
|
+
maskEmails?: boolean | undefined;
|
|
220
|
+
/** Don't show referrers the names of the users they referred. Defaults to `false`. */
|
|
221
|
+
hideNames?: boolean | undefined;
|
|
222
|
+
/**
|
|
223
|
+
* Users with one of these roles (the `role` field of better-auth's
|
|
224
|
+
* `admin` plugin) may list all referrals. Defaults to `["admin"]`.
|
|
225
|
+
*/
|
|
226
|
+
adminRoles?: readonly string[] | undefined;
|
|
227
|
+
/** Users with these ids may list all referrals, whatever their role. */
|
|
228
|
+
adminUserIds?: readonly string[] | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Rename the plugin's tables or their columns, like better-auth's own
|
|
231
|
+
* plugins: `{ referral: { modelName: "referrals" } }`.
|
|
232
|
+
*/
|
|
233
|
+
schema?: InferOptionSchema<ReferralSchema> | undefined;
|
|
234
|
+
}
|
|
235
|
+
declare const REFERRAL_ERROR_CODES: {
|
|
236
|
+
INVALID_REFERRAL_CODE: import("better-auth").RawError<"INVALID_REFERRAL_CODE">;
|
|
237
|
+
UNKNOWN_REFERRAL_STEP: import("better-auth").RawError<"UNKNOWN_REFERRAL_STEP">;
|
|
238
|
+
CODE_GENERATION_FAILED: import("better-auth").RawError<"CODE_GENERATION_FAILED">;
|
|
239
|
+
METADATA_TOO_LARGE: import("better-auth").RawError<"METADATA_TOO_LARGE">;
|
|
240
|
+
YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS: import("better-auth").RawError<"YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS">;
|
|
241
|
+
};
|
|
242
|
+
type ReferralErrorCode = keyof typeof REFERRAL_ERROR_CODES;
|
|
243
|
+
/** A step the plugin records itself, when the referred user's email is verified. */
|
|
244
|
+
declare const EMAIL_VERIFIED_STEP = "email-verified";
|
|
245
|
+
/**
|
|
246
|
+
* Gives users referral codes, attributes new users to the code they signed
|
|
247
|
+
* up with (any sign-up method), and tracks steps a referral must complete
|
|
248
|
+
* before it counts, e.g. a verified email or a first purchase.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* import { betterAuth } from "better-auth";
|
|
253
|
+
* import { referral } from "@checodo/better-auth-referral";
|
|
254
|
+
*
|
|
255
|
+
* export const auth = betterAuth({
|
|
256
|
+
* plugins: [
|
|
257
|
+
* referral({
|
|
258
|
+
* steps: ["email-verified", "first-purchase"],
|
|
259
|
+
* onReferralCompleted: async ({ referrerUserId }) => {
|
|
260
|
+
* await grantCredit(referrerUserId);
|
|
261
|
+
* },
|
|
262
|
+
* }),
|
|
263
|
+
* ],
|
|
264
|
+
* });
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare const referral: (options?: ReferralOptions) => {
|
|
268
|
+
id: "referral";
|
|
269
|
+
version: string;
|
|
270
|
+
init(ctx: import("better-auth").AuthContext): {
|
|
271
|
+
options: {
|
|
272
|
+
databaseHooks: {
|
|
273
|
+
user?: {
|
|
274
|
+
create?: {
|
|
275
|
+
before?: (user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
276
|
+
data: {
|
|
277
|
+
id?: string | undefined;
|
|
278
|
+
createdAt?: Date | undefined;
|
|
279
|
+
updatedAt?: Date | undefined;
|
|
280
|
+
email?: string | undefined;
|
|
281
|
+
emailVerified?: boolean | undefined;
|
|
282
|
+
name?: string | undefined;
|
|
283
|
+
image?: string | null | undefined;
|
|
284
|
+
} & Record<string, any>;
|
|
285
|
+
}>;
|
|
286
|
+
after?: (user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
287
|
+
};
|
|
288
|
+
update?: {
|
|
289
|
+
before?: (user: Partial<import("better-auth").User> & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
290
|
+
data: {
|
|
291
|
+
[x: string]: any;
|
|
292
|
+
id?: string | undefined;
|
|
293
|
+
createdAt?: Date | undefined;
|
|
294
|
+
updatedAt?: Date | undefined;
|
|
295
|
+
email?: string | undefined;
|
|
296
|
+
emailVerified?: boolean | undefined;
|
|
297
|
+
name?: string | undefined;
|
|
298
|
+
image?: string | null | undefined;
|
|
299
|
+
};
|
|
300
|
+
}>;
|
|
301
|
+
after?: (user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
302
|
+
};
|
|
303
|
+
delete?: {
|
|
304
|
+
before?: (user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void>;
|
|
305
|
+
after?: (user: import("better-auth").User & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
session?: {
|
|
309
|
+
create?: {
|
|
310
|
+
before?: (session: import("better-auth").Session & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
311
|
+
data: {
|
|
312
|
+
id?: string | undefined;
|
|
313
|
+
createdAt?: Date | undefined;
|
|
314
|
+
updatedAt?: Date | undefined;
|
|
315
|
+
userId?: string | undefined;
|
|
316
|
+
expiresAt?: Date | undefined;
|
|
317
|
+
token?: string | undefined;
|
|
318
|
+
ipAddress?: string | null | undefined;
|
|
319
|
+
userAgent?: string | null | undefined;
|
|
320
|
+
} & Record<string, any>;
|
|
321
|
+
}>;
|
|
322
|
+
after?: (session: import("better-auth").Session & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
323
|
+
};
|
|
324
|
+
update?: {
|
|
325
|
+
before?: (session: Partial<import("better-auth").Session> & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
326
|
+
data: {
|
|
327
|
+
[x: string]: any;
|
|
328
|
+
id?: string | undefined;
|
|
329
|
+
createdAt?: Date | undefined;
|
|
330
|
+
updatedAt?: Date | undefined;
|
|
331
|
+
userId?: string | undefined;
|
|
332
|
+
expiresAt?: Date | undefined;
|
|
333
|
+
token?: string | undefined;
|
|
334
|
+
ipAddress?: string | null | undefined;
|
|
335
|
+
userAgent?: string | null | undefined;
|
|
336
|
+
};
|
|
337
|
+
}>;
|
|
338
|
+
after?: (session: import("better-auth").Session & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
339
|
+
};
|
|
340
|
+
delete?: {
|
|
341
|
+
before?: (session: import("better-auth").Session & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void>;
|
|
342
|
+
after?: (session: import("better-auth").Session & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
account?: {
|
|
346
|
+
create?: {
|
|
347
|
+
before?: (account: import("better-auth").Account, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
348
|
+
data: {
|
|
349
|
+
id?: string | undefined;
|
|
350
|
+
createdAt?: Date | undefined;
|
|
351
|
+
updatedAt?: Date | undefined;
|
|
352
|
+
providerId?: string | undefined;
|
|
353
|
+
accountId?: string | undefined;
|
|
354
|
+
userId?: string | undefined;
|
|
355
|
+
accessToken?: string | null | undefined;
|
|
356
|
+
refreshToken?: string | null | undefined;
|
|
357
|
+
idToken?: string | null | undefined;
|
|
358
|
+
accessTokenExpiresAt?: Date | null | undefined;
|
|
359
|
+
refreshTokenExpiresAt?: Date | null | undefined;
|
|
360
|
+
scope?: string | null | undefined;
|
|
361
|
+
password?: string | null | undefined;
|
|
362
|
+
} & Record<string, any>;
|
|
363
|
+
}>;
|
|
364
|
+
after?: (account: import("better-auth").Account, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
365
|
+
};
|
|
366
|
+
update?: {
|
|
367
|
+
before?: (account: Partial<import("better-auth").Account> & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
368
|
+
data: {
|
|
369
|
+
[x: string]: any;
|
|
370
|
+
id?: string | undefined;
|
|
371
|
+
createdAt?: Date | undefined;
|
|
372
|
+
updatedAt?: Date | undefined;
|
|
373
|
+
providerId?: string | undefined;
|
|
374
|
+
accountId?: string | undefined;
|
|
375
|
+
userId?: string | undefined;
|
|
376
|
+
accessToken?: string | null | undefined;
|
|
377
|
+
refreshToken?: string | null | undefined;
|
|
378
|
+
idToken?: string | null | undefined;
|
|
379
|
+
accessTokenExpiresAt?: Date | null | undefined;
|
|
380
|
+
refreshTokenExpiresAt?: Date | null | undefined;
|
|
381
|
+
scope?: string | null | undefined;
|
|
382
|
+
password?: string | null | undefined;
|
|
383
|
+
};
|
|
384
|
+
}>;
|
|
385
|
+
after?: (account: import("better-auth").Account & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
386
|
+
};
|
|
387
|
+
delete?: {
|
|
388
|
+
before?: (account: import("better-auth").Account & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void>;
|
|
389
|
+
after?: (account: import("better-auth").Account & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
verification?: {
|
|
393
|
+
create?: {
|
|
394
|
+
before?: (verification: import("better-auth").Verification & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
395
|
+
data: {
|
|
396
|
+
id?: string | undefined;
|
|
397
|
+
createdAt?: Date | undefined;
|
|
398
|
+
updatedAt?: Date | undefined;
|
|
399
|
+
value?: string | undefined;
|
|
400
|
+
expiresAt?: Date | undefined;
|
|
401
|
+
identifier?: string | undefined;
|
|
402
|
+
} & Record<string, any>;
|
|
403
|
+
}>;
|
|
404
|
+
after?: (verification: import("better-auth").Verification & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
405
|
+
};
|
|
406
|
+
update?: {
|
|
407
|
+
before?: (verification: Partial<import("better-auth").Verification> & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void | {
|
|
408
|
+
data: {
|
|
409
|
+
[x: string]: any;
|
|
410
|
+
id?: string | undefined;
|
|
411
|
+
createdAt?: Date | undefined;
|
|
412
|
+
updatedAt?: Date | undefined;
|
|
413
|
+
value?: string | undefined;
|
|
414
|
+
expiresAt?: Date | undefined;
|
|
415
|
+
identifier?: string | undefined;
|
|
416
|
+
};
|
|
417
|
+
}>;
|
|
418
|
+
after?: (verification: import("better-auth").Verification & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
419
|
+
};
|
|
420
|
+
delete?: {
|
|
421
|
+
before?: (verification: import("better-auth").Verification & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<boolean | void>;
|
|
422
|
+
after?: (verification: import("better-auth").Verification & Record<string, unknown>, context: import("better-auth").GenericEndpointContext | null) => Promise<void>;
|
|
423
|
+
};
|
|
424
|
+
};
|
|
425
|
+
} | undefined;
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
schema: {
|
|
429
|
+
referralCode: {
|
|
430
|
+
fields: {
|
|
431
|
+
userId: {
|
|
432
|
+
type: "string";
|
|
433
|
+
required: true;
|
|
434
|
+
references: {
|
|
435
|
+
model: string;
|
|
436
|
+
field: string;
|
|
437
|
+
onDelete: "cascade";
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
code: {
|
|
441
|
+
type: "string";
|
|
442
|
+
required: true;
|
|
443
|
+
};
|
|
444
|
+
createdAt: {
|
|
445
|
+
type: "date";
|
|
446
|
+
required: true;
|
|
447
|
+
};
|
|
448
|
+
};
|
|
449
|
+
indexes: {
|
|
450
|
+
fields: [string];
|
|
451
|
+
unique: true;
|
|
452
|
+
}[];
|
|
453
|
+
};
|
|
454
|
+
referral: {
|
|
455
|
+
fields: {
|
|
456
|
+
referrerUserId: {
|
|
457
|
+
type: "string";
|
|
458
|
+
required: true;
|
|
459
|
+
index: true;
|
|
460
|
+
references: {
|
|
461
|
+
model: string;
|
|
462
|
+
field: string;
|
|
463
|
+
onDelete: "cascade";
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
referredUserId: {
|
|
467
|
+
type: "string";
|
|
468
|
+
required: true;
|
|
469
|
+
references: {
|
|
470
|
+
model: string;
|
|
471
|
+
field: string;
|
|
472
|
+
onDelete: "cascade";
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
code: {
|
|
476
|
+
type: "string";
|
|
477
|
+
required: true;
|
|
478
|
+
};
|
|
479
|
+
status: {
|
|
480
|
+
type: "string";
|
|
481
|
+
required: true;
|
|
482
|
+
index: true;
|
|
483
|
+
};
|
|
484
|
+
completedAt: {
|
|
485
|
+
type: "date";
|
|
486
|
+
required: false;
|
|
487
|
+
};
|
|
488
|
+
createdAt: {
|
|
489
|
+
type: "date";
|
|
490
|
+
required: true;
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
indexes: {
|
|
494
|
+
fields: [string];
|
|
495
|
+
unique: true;
|
|
496
|
+
}[];
|
|
497
|
+
};
|
|
498
|
+
referralStep: {
|
|
499
|
+
fields: {
|
|
500
|
+
referralId: {
|
|
501
|
+
type: "string";
|
|
502
|
+
required: true;
|
|
503
|
+
references: {
|
|
504
|
+
model: string;
|
|
505
|
+
field: string;
|
|
506
|
+
onDelete: "cascade";
|
|
507
|
+
};
|
|
508
|
+
};
|
|
509
|
+
step: {
|
|
510
|
+
type: "string";
|
|
511
|
+
required: true;
|
|
512
|
+
};
|
|
513
|
+
metadata: {
|
|
514
|
+
type: "string";
|
|
515
|
+
required: false;
|
|
516
|
+
};
|
|
517
|
+
completedAt: {
|
|
518
|
+
type: "date";
|
|
519
|
+
required: true;
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
indexes: {
|
|
523
|
+
fields: [string, string];
|
|
524
|
+
unique: true;
|
|
525
|
+
}[];
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
endpoints: {
|
|
529
|
+
listReferrals: import("better-auth").StrictEndpoint<"/referral/list-referrals", {
|
|
530
|
+
method: "GET";
|
|
531
|
+
use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
532
|
+
session: {
|
|
533
|
+
session: Record<string, any> & {
|
|
534
|
+
id: string;
|
|
535
|
+
createdAt: Date;
|
|
536
|
+
updatedAt: Date;
|
|
537
|
+
userId: string;
|
|
538
|
+
expiresAt: Date;
|
|
539
|
+
token: string;
|
|
540
|
+
ipAddress?: string | null | undefined;
|
|
541
|
+
userAgent?: string | null | undefined;
|
|
542
|
+
};
|
|
543
|
+
user: Record<string, any> & {
|
|
544
|
+
id: string;
|
|
545
|
+
createdAt: Date;
|
|
546
|
+
updatedAt: Date;
|
|
547
|
+
email: string;
|
|
548
|
+
emailVerified: boolean;
|
|
549
|
+
name: string;
|
|
550
|
+
image?: string | null | undefined;
|
|
551
|
+
};
|
|
552
|
+
};
|
|
553
|
+
}>>[];
|
|
554
|
+
query: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
555
|
+
limit: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
|
|
556
|
+
offset: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
|
|
557
|
+
status: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
558
|
+
pending: "pending";
|
|
559
|
+
completed: "completed";
|
|
560
|
+
}>>;
|
|
561
|
+
}, import("zod/v4/core").$strip>>;
|
|
562
|
+
metadata: {
|
|
563
|
+
openapi: {
|
|
564
|
+
description: string;
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
}, {
|
|
568
|
+
referrals: {
|
|
569
|
+
id: string;
|
|
570
|
+
status: ReferralStatus;
|
|
571
|
+
steps: string[];
|
|
572
|
+
createdAt: Date;
|
|
573
|
+
completedAt: Date | null;
|
|
574
|
+
referredUser: {
|
|
575
|
+
name: string | null;
|
|
576
|
+
email: string | null;
|
|
577
|
+
};
|
|
578
|
+
}[];
|
|
579
|
+
total: number;
|
|
580
|
+
completed: number;
|
|
581
|
+
}>;
|
|
582
|
+
listAllReferrals: import("better-auth").StrictEndpoint<"/referral/list-all-referrals", {
|
|
583
|
+
method: "GET";
|
|
584
|
+
use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
585
|
+
session: {
|
|
586
|
+
session: Record<string, any> & {
|
|
587
|
+
id: string;
|
|
588
|
+
createdAt: Date;
|
|
589
|
+
updatedAt: Date;
|
|
590
|
+
userId: string;
|
|
591
|
+
expiresAt: Date;
|
|
592
|
+
token: string;
|
|
593
|
+
ipAddress?: string | null | undefined;
|
|
594
|
+
userAgent?: string | null | undefined;
|
|
595
|
+
};
|
|
596
|
+
user: Record<string, any> & {
|
|
597
|
+
id: string;
|
|
598
|
+
createdAt: Date;
|
|
599
|
+
updatedAt: Date;
|
|
600
|
+
email: string;
|
|
601
|
+
emailVerified: boolean;
|
|
602
|
+
name: string;
|
|
603
|
+
image?: string | null | undefined;
|
|
604
|
+
};
|
|
605
|
+
};
|
|
606
|
+
}>>[];
|
|
607
|
+
query: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
608
|
+
limit: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
|
|
609
|
+
offset: import("zod").ZodDefault<import("zod").ZodCoercedNumber<unknown>>;
|
|
610
|
+
referrerUserId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
611
|
+
status: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
612
|
+
pending: "pending";
|
|
613
|
+
completed: "completed";
|
|
614
|
+
}>>;
|
|
615
|
+
}, import("zod/v4/core").$strip>>;
|
|
616
|
+
metadata: {
|
|
617
|
+
openapi: {
|
|
618
|
+
description: string;
|
|
619
|
+
};
|
|
620
|
+
};
|
|
621
|
+
}, {
|
|
622
|
+
referrals: ReferralWithSteps[];
|
|
623
|
+
total: number;
|
|
624
|
+
}>;
|
|
625
|
+
completeReferralStep: import("better-auth").StrictEndpoint<string, {
|
|
626
|
+
method: "POST";
|
|
627
|
+
body: import("zod").ZodObject<{
|
|
628
|
+
userId: import("zod").ZodString;
|
|
629
|
+
step: import("zod").ZodString;
|
|
630
|
+
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
|
|
631
|
+
}, import("zod/v4/core").$strip>;
|
|
632
|
+
metadata: {
|
|
633
|
+
openapi: {
|
|
634
|
+
description: string;
|
|
635
|
+
};
|
|
636
|
+
};
|
|
637
|
+
}, {
|
|
638
|
+
referral: ReferralWithSteps | null;
|
|
639
|
+
}>;
|
|
640
|
+
getReferralCode: import("better-auth").StrictEndpoint<"/referral/get-code", {
|
|
641
|
+
method: "GET";
|
|
642
|
+
use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
643
|
+
session: {
|
|
644
|
+
session: Record<string, any> & {
|
|
645
|
+
id: string;
|
|
646
|
+
createdAt: Date;
|
|
647
|
+
updatedAt: Date;
|
|
648
|
+
userId: string;
|
|
649
|
+
expiresAt: Date;
|
|
650
|
+
token: string;
|
|
651
|
+
ipAddress?: string | null | undefined;
|
|
652
|
+
userAgent?: string | null | undefined;
|
|
653
|
+
};
|
|
654
|
+
user: Record<string, any> & {
|
|
655
|
+
id: string;
|
|
656
|
+
createdAt: Date;
|
|
657
|
+
updatedAt: Date;
|
|
658
|
+
email: string;
|
|
659
|
+
emailVerified: boolean;
|
|
660
|
+
name: string;
|
|
661
|
+
image?: string | null | undefined;
|
|
662
|
+
};
|
|
663
|
+
};
|
|
664
|
+
}>>[];
|
|
665
|
+
metadata: {
|
|
666
|
+
openapi: {
|
|
667
|
+
description: string;
|
|
668
|
+
};
|
|
669
|
+
};
|
|
670
|
+
}, {
|
|
671
|
+
code: string | null;
|
|
672
|
+
}>;
|
|
673
|
+
createReferralCode: import("better-auth").StrictEndpoint<"/referral/create-code", {
|
|
674
|
+
method: "POST";
|
|
675
|
+
use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
676
|
+
session: {
|
|
677
|
+
session: Record<string, any> & {
|
|
678
|
+
id: string;
|
|
679
|
+
createdAt: Date;
|
|
680
|
+
updatedAt: Date;
|
|
681
|
+
userId: string;
|
|
682
|
+
expiresAt: Date;
|
|
683
|
+
token: string;
|
|
684
|
+
ipAddress?: string | null | undefined;
|
|
685
|
+
userAgent?: string | null | undefined;
|
|
686
|
+
};
|
|
687
|
+
user: Record<string, any> & {
|
|
688
|
+
id: string;
|
|
689
|
+
createdAt: Date;
|
|
690
|
+
updatedAt: Date;
|
|
691
|
+
email: string;
|
|
692
|
+
emailVerified: boolean;
|
|
693
|
+
name: string;
|
|
694
|
+
image?: string | null | undefined;
|
|
695
|
+
};
|
|
696
|
+
};
|
|
697
|
+
}>>[];
|
|
698
|
+
metadata: {
|
|
699
|
+
openapi: {
|
|
700
|
+
description: string;
|
|
701
|
+
};
|
|
702
|
+
};
|
|
703
|
+
}, {
|
|
704
|
+
code: string;
|
|
705
|
+
}>;
|
|
706
|
+
regenerateReferralCode: import("better-auth").StrictEndpoint<"/referral/regenerate-code", {
|
|
707
|
+
method: "POST";
|
|
708
|
+
use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
709
|
+
session: {
|
|
710
|
+
session: Record<string, any> & {
|
|
711
|
+
id: string;
|
|
712
|
+
createdAt: Date;
|
|
713
|
+
updatedAt: Date;
|
|
714
|
+
userId: string;
|
|
715
|
+
expiresAt: Date;
|
|
716
|
+
token: string;
|
|
717
|
+
ipAddress?: string | null | undefined;
|
|
718
|
+
userAgent?: string | null | undefined;
|
|
719
|
+
};
|
|
720
|
+
user: Record<string, any> & {
|
|
721
|
+
id: string;
|
|
722
|
+
createdAt: Date;
|
|
723
|
+
updatedAt: Date;
|
|
724
|
+
email: string;
|
|
725
|
+
emailVerified: boolean;
|
|
726
|
+
name: string;
|
|
727
|
+
image?: string | null | undefined;
|
|
728
|
+
};
|
|
729
|
+
};
|
|
730
|
+
}>>[];
|
|
731
|
+
metadata: {
|
|
732
|
+
openapi: {
|
|
733
|
+
description: string;
|
|
734
|
+
};
|
|
735
|
+
};
|
|
736
|
+
}, {
|
|
737
|
+
code: string;
|
|
738
|
+
}>;
|
|
739
|
+
checkReferralCode: import("better-auth").StrictEndpoint<"/referral/check-code", {
|
|
740
|
+
method: "GET";
|
|
741
|
+
query: import("zod").ZodObject<{
|
|
742
|
+
code: import("zod").ZodString;
|
|
743
|
+
}, import("zod/v4/core").$strip>;
|
|
744
|
+
metadata: {
|
|
745
|
+
openapi: {
|
|
746
|
+
description: string;
|
|
747
|
+
};
|
|
748
|
+
};
|
|
749
|
+
}, {
|
|
750
|
+
valid: boolean;
|
|
751
|
+
}>;
|
|
752
|
+
};
|
|
753
|
+
rateLimit: {
|
|
754
|
+
pathMatcher: (path: string) => path is "/referral/check-code";
|
|
755
|
+
window: number;
|
|
756
|
+
max: number;
|
|
757
|
+
}[];
|
|
758
|
+
$ERROR_CODES: {
|
|
759
|
+
INVALID_REFERRAL_CODE: import("better-auth").RawError<"INVALID_REFERRAL_CODE">;
|
|
760
|
+
UNKNOWN_REFERRAL_STEP: import("better-auth").RawError<"UNKNOWN_REFERRAL_STEP">;
|
|
761
|
+
CODE_GENERATION_FAILED: import("better-auth").RawError<"CODE_GENERATION_FAILED">;
|
|
762
|
+
METADATA_TOO_LARGE: import("better-auth").RawError<"METADATA_TOO_LARGE">;
|
|
763
|
+
YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS: import("better-auth").RawError<"YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS">;
|
|
764
|
+
};
|
|
765
|
+
options: ReferralOptions;
|
|
766
|
+
};
|
|
767
|
+
type ReferralPlugin = ReturnType<typeof referral>;
|
|
768
|
+
/** Lets `auth.$context.getPlugin("referral")` infer this plugin's exact type. */
|
|
769
|
+
declare module "@better-auth/core" {
|
|
770
|
+
interface BetterAuthPluginRegistry<AuthOptions, Options> {
|
|
771
|
+
referral: {
|
|
772
|
+
creator: typeof referral;
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
export { ReferralErrorCode as a, ReferralCode as c, ReferralStep as d, ReferralWithSteps as f, REFERRAL_ERROR_CODES as i, ReferralOptions as l, referral as n, Referral as o, EMAIL_VERIFIED_STEP as r, ReferralCandidate as s, ReferralPlugin as t, ReferralStatus as u };
|
|
777
|
+
//# sourceMappingURL=index-HDtManYT.d.ts.map
|