@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
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Clas Heinemeyer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @checodo/better-auth-referral
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Referral codes for [better-auth](https://better-auth.com): codes per user, attribution for every sign-up method, and steps such as a first purchase before a referral earns a reward.
|
|
4
|
+
|
|
5
|
+
A community plugin, not made by the better-auth team. It looks and works
|
|
6
|
+
like better-auth's own plugins: a server plugin, a typed client plugin,
|
|
7
|
+
error codes, and database tables.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @checodo/better-auth-referral
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires `better-auth` and `@better-auth/core` 1.7.20 or a later 1.x
|
|
16
|
+
release (peer dependencies). ESM only.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// auth.ts
|
|
22
|
+
import { betterAuth } from "better-auth";
|
|
23
|
+
import { referral } from "@checodo/better-auth-referral";
|
|
24
|
+
|
|
25
|
+
export const auth = betterAuth({
|
|
26
|
+
plugins: [
|
|
27
|
+
referral({
|
|
28
|
+
steps: ["email-verified"],
|
|
29
|
+
onReferralCompleted: async ({ referrerUserId }) => {
|
|
30
|
+
// reward the referrer
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
// auth-client.ts
|
|
39
|
+
import { createAuthClient } from "better-auth/client";
|
|
40
|
+
import { referralClient } from "@checodo/better-auth-referral/client";
|
|
41
|
+
|
|
42
|
+
export const authClient = createAuthClient({ plugins: [referralClient()] });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Create the plugin's tables with the better-auth CLI:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx auth@latest migrate
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Documentation
|
|
52
|
+
|
|
53
|
+
Every option, endpoint, error code, and table:
|
|
54
|
+
[docs](https://github.com/checodo/better-auth-plugins/blob/main/apps/docs/content/docs/referral.mdx).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { i as REFERRAL_ERROR_CODES, t as ReferralPlugin } from "./index-HDtManYT.js";
|
|
2
|
+
/**
|
|
3
|
+
* Client companion to `referral()`. Adds `authClient.referral.getCode`,
|
|
4
|
+
* `createCode`, `regenerateCode`, `checkCode`, `listReferrals`, and
|
|
5
|
+
* `listAllReferrals` (admins), typed from the server plugin. Pass the code
|
|
6
|
+
* at sign-up in the `x-referral-code` header, or as
|
|
7
|
+
* `additionalData.referralCode` of a social sign-in.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createAuthClient } from "better-auth/client";
|
|
12
|
+
* import { referralClient } from "@checodo/better-auth-referral/client";
|
|
13
|
+
*
|
|
14
|
+
* export const authClient = createAuthClient({
|
|
15
|
+
* plugins: [referralClient()],
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const { data } = await authClient.referral.createCode();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const referralClient: () => {
|
|
22
|
+
id: "referral";
|
|
23
|
+
$InferServerPlugin: ReferralPlugin;
|
|
24
|
+
pathMethods: {
|
|
25
|
+
"/referral/get-code": "GET";
|
|
26
|
+
"/referral/create-code": "POST";
|
|
27
|
+
"/referral/regenerate-code": "POST";
|
|
28
|
+
"/referral/check-code": "GET";
|
|
29
|
+
"/referral/list-referrals": "GET";
|
|
30
|
+
"/referral/list-all-referrals": "GET";
|
|
31
|
+
};
|
|
32
|
+
$ERROR_CODES: {
|
|
33
|
+
INVALID_REFERRAL_CODE: import("better-auth").RawError<"INVALID_REFERRAL_CODE">;
|
|
34
|
+
UNKNOWN_REFERRAL_STEP: import("better-auth").RawError<"UNKNOWN_REFERRAL_STEP">;
|
|
35
|
+
CODE_GENERATION_FAILED: import("better-auth").RawError<"CODE_GENERATION_FAILED">;
|
|
36
|
+
METADATA_TOO_LARGE: import("better-auth").RawError<"METADATA_TOO_LARGE">;
|
|
37
|
+
YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS: import("better-auth").RawError<"YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS">;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export { REFERRAL_ERROR_CODES };
|
|
41
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;qBAuBa;;EAGiB,oBAAA"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { t as REFERRAL_ERROR_CODES } from "./error-codes-Bw554PRu.js";
|
|
2
|
+
// src/client.ts
|
|
3
|
+
/**
|
|
4
|
+
* Client companion to `referral()`. Adds `authClient.referral.getCode`,
|
|
5
|
+
* `createCode`, `regenerateCode`, `checkCode`, `listReferrals`, and
|
|
6
|
+
* `listAllReferrals` (admins), typed from the server plugin. Pass the code
|
|
7
|
+
* at sign-up in the `x-referral-code` header, or as
|
|
8
|
+
* `additionalData.referralCode` of a social sign-in.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createAuthClient } from "better-auth/client";
|
|
13
|
+
* import { referralClient } from "@checodo/better-auth-referral/client";
|
|
14
|
+
*
|
|
15
|
+
* export const authClient = createAuthClient({
|
|
16
|
+
* plugins: [referralClient()],
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const { data } = await authClient.referral.createCode();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const referralClient = () => {
|
|
23
|
+
return {
|
|
24
|
+
id: "referral",
|
|
25
|
+
$InferServerPlugin: {},
|
|
26
|
+
pathMethods: {
|
|
27
|
+
"/referral/get-code": "GET",
|
|
28
|
+
"/referral/create-code": "POST",
|
|
29
|
+
"/referral/regenerate-code": "POST",
|
|
30
|
+
"/referral/check-code": "GET",
|
|
31
|
+
"/referral/list-referrals": "GET",
|
|
32
|
+
"/referral/list-all-referrals": "GET"
|
|
33
|
+
},
|
|
34
|
+
$ERROR_CODES: REFERRAL_ERROR_CODES
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export { REFERRAL_ERROR_CODES, referralClient };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"better-auth/client\";\nimport { REFERRAL_ERROR_CODES } from \"./error-codes\";\nimport type { ReferralPlugin } from \"./index\";\n\n/**\n * Client companion to `referral()`. Adds `authClient.referral.getCode`,\n * `createCode`, `regenerateCode`, `checkCode`, `listReferrals`, and\n * `listAllReferrals` (admins), typed from the server plugin. Pass the code\n * at sign-up in the `x-referral-code` header, or as\n * `additionalData.referralCode` of a social sign-in.\n *\n * @example\n * ```ts\n * import { createAuthClient } from \"better-auth/client\";\n * import { referralClient } from \"@checodo/better-auth-referral/client\";\n *\n * export const authClient = createAuthClient({\n * plugins: [referralClient()],\n * });\n *\n * const { data } = await authClient.referral.createCode();\n * ```\n */\nexport const referralClient = () => {\n return {\n id: \"referral\",\n $InferServerPlugin: {} as ReferralPlugin,\n pathMethods: {\n \"/referral/get-code\": \"GET\",\n \"/referral/create-code\": \"POST\",\n \"/referral/regenerate-code\": \"POST\",\n \"/referral/check-code\": \"GET\",\n \"/referral/list-referrals\": \"GET\",\n \"/referral/list-all-referrals\": \"GET\",\n },\n $ERROR_CODES: REFERRAL_ERROR_CODES,\n } satisfies BetterAuthClientPlugin;\n};\n\nexport { REFERRAL_ERROR_CODES } from \"./error-codes\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,uBAAuB;CAClC,OAAO;EACL,IAAI;EACJ,oBAAoB,CAAC;EACrB,aAAa;GACX,sBAAsB;GACtB,yBAAyB;GACzB,6BAA6B;GAC7B,wBAAwB;GACxB,4BAA4B;GAC5B,gCAAgC;EAClC;EACA,cAAc;CAChB;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
|
|
2
|
+
// src/error-codes.ts
|
|
3
|
+
const REFERRAL_ERROR_CODES = defineErrorCodes({
|
|
4
|
+
INVALID_REFERRAL_CODE: "This referral code is invalid",
|
|
5
|
+
UNKNOWN_REFERRAL_STEP: "This referral step is not configured",
|
|
6
|
+
CODE_GENERATION_FAILED: "Could not generate a unique referral code",
|
|
7
|
+
METADATA_TOO_LARGE: "The metadata is too large",
|
|
8
|
+
YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS: "You are not allowed to list all referrals"
|
|
9
|
+
});
|
|
10
|
+
export { REFERRAL_ERROR_CODES as t };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=error-codes-Bw554PRu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-codes-Bw554PRu.js","names":[],"sources":["../src/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const REFERRAL_ERROR_CODES = defineErrorCodes({\n INVALID_REFERRAL_CODE: \"This referral code is invalid\",\n UNKNOWN_REFERRAL_STEP: \"This referral step is not configured\",\n CODE_GENERATION_FAILED: \"Could not generate a unique referral code\",\n METADATA_TOO_LARGE: \"The metadata is too large\",\n YOU_ARE_NOT_ALLOWED_TO_LIST_REFERRALS: \"You are not allowed to list all referrals\",\n});\n\nexport type ReferralErrorCode = keyof typeof REFERRAL_ERROR_CODES;\n"],"mappings":";;AAEA,MAAa,uBAAuB,iBAAiB;CACnD,uBAAuB;CACvB,uBAAuB;CACvB,wBAAwB;CACxB,oBAAoB;CACpB,uCAAuC;AACzC,CAAC"}
|