better-auth-solana-payments 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/README.md +91 -0
- package/dist/client.d.mts +58 -0
- package/dist/client.d.mts.map +1 -0
- package/dist/client.mjs +33 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index-BAy-bbzL.d.mts +243 -0
- package/dist/index-BAy-bbzL.d.mts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +392 -0
- package/dist/index.mjs.map +1 -0
- package/dist/version-Ctrvqbjd.mjs +6 -0
- package/dist/version-Ctrvqbjd.mjs.map +1 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Better Auth Solana Payments
|
|
2
|
+
|
|
3
|
+
One-time Solana payment integration for [Better Auth](https://www.better-auth.com).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add better-auth better-auth-solana-payments solana-payments
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node.js 22 or later.
|
|
12
|
+
|
|
13
|
+
## Server setup
|
|
14
|
+
|
|
15
|
+
Create a read-only Solana Payments SDK client and register the Better Auth plugin.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { betterAuth } from "better-auth";
|
|
19
|
+
import { solanaPayments } from "better-auth-solana-payments";
|
|
20
|
+
import { SOLANA_USDT, createReadOnlySolanaPayments } from "solana-payments";
|
|
21
|
+
|
|
22
|
+
const client = createReadOnlySolanaPayments({
|
|
23
|
+
rpcUrl: process.env.SOLANA_RPC_URL!,
|
|
24
|
+
token: SOLANA_USDT,
|
|
25
|
+
commitment: "confirmed",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const auth = betterAuth({
|
|
29
|
+
plugins: [
|
|
30
|
+
solanaPayments({
|
|
31
|
+
client,
|
|
32
|
+
recipient: process.env.SOLANA_RECIPIENT!,
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Client setup
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { createAuthClient } from "better-auth/client";
|
|
42
|
+
import { solanaPaymentsClient } from "better-auth-solana-payments/client";
|
|
43
|
+
|
|
44
|
+
export const authClient = createAuthClient({
|
|
45
|
+
plugins: [solanaPaymentsClient()],
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## One-time payment flow
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
const created = await authClient.payment.create({
|
|
53
|
+
// A decimal string in the configured token's display units; never use a JavaScript number.
|
|
54
|
+
amount: "2.5",
|
|
55
|
+
metadata: { orderId: "order_123" },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (created.data?.paymentUrl) {
|
|
59
|
+
// Present this Solana Pay URL as a link or QR code for the signed-in customer.
|
|
60
|
+
window.location.assign(created.data.paymentUrl);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const verified = await authClient.payment.verify({
|
|
64
|
+
reference: created.data!.reference,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (verified.data?.status === "paid") {
|
|
68
|
+
// Grant the entitlement only after server-side verification reports a paid payment.
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const payment = await authClient.payment.get({
|
|
72
|
+
reference: created.data!.reference,
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`payment.create` persists a pending payment intent and returns its reference and Solana Pay URL.
|
|
77
|
+
After the customer signs the transaction, call `payment.verify` with that reference. The server
|
|
78
|
+
uses its configured RPC client to verify the matching token transfer before marking the payment
|
|
79
|
+
paid. `payment.get` reads the current status without attempting verification.
|
|
80
|
+
|
|
81
|
+
Amounts are decimal strings in the configured token's display units (for example, `"2.5"` is
|
|
82
|
+
2.5 USDT with the default six-decimal USDT token). Do not pass JavaScript numbers, which can lose
|
|
83
|
+
precision for token amounts.
|
|
84
|
+
|
|
85
|
+
The browser may supply only the amount, optional metadata, reference, and optional organization
|
|
86
|
+
ID. The server controls the recipient and token configuration, so clients cannot redirect funds
|
|
87
|
+
or choose another mint. The integration uses a read-only RPC client: it stores no private keys and
|
|
88
|
+
never signs or sends a transaction on behalf of a customer.
|
|
89
|
+
|
|
90
|
+
This package supports one-time payments only. It does not create recurring subscriptions or
|
|
91
|
+
perform recurring charges.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { t as solanaPayments } from "./index-BAy-bbzL.mjs";
|
|
2
|
+
import { BetterFetch, BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
3
|
+
import { BetterAuthClientPlugin } from "better-auth/client";
|
|
4
|
+
//#region src/client.d.ts
|
|
5
|
+
type FetchResult<T, O extends BetterFetchOption | undefined> = O extends {
|
|
6
|
+
throw: true;
|
|
7
|
+
} ? T : BetterFetchResponse<T>;
|
|
8
|
+
interface SolanaPaymentResponse {
|
|
9
|
+
id: string;
|
|
10
|
+
reference: string;
|
|
11
|
+
amount: string;
|
|
12
|
+
mint: string;
|
|
13
|
+
decimals: number;
|
|
14
|
+
recipient: string;
|
|
15
|
+
status: "pending" | "paid" | "expired" | "failed";
|
|
16
|
+
expiresAt: Date;
|
|
17
|
+
signature?: string;
|
|
18
|
+
slot?: string;
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
paymentUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
interface SolanaPaymentActions {
|
|
23
|
+
create: <O extends BetterFetchOption | undefined = undefined>(data: {
|
|
24
|
+
amount: string;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
organizationId?: string;
|
|
27
|
+
}, options?: O) => Promise<FetchResult<SolanaPaymentResponse, O>>;
|
|
28
|
+
verify: <O extends BetterFetchOption | undefined = undefined>(data: {
|
|
29
|
+
reference: string;
|
|
30
|
+
organizationId?: string;
|
|
31
|
+
}, options?: O) => Promise<FetchResult<SolanaPaymentResponse, O>>;
|
|
32
|
+
get: <O extends BetterFetchOption | undefined = undefined>(data: {
|
|
33
|
+
reference: string;
|
|
34
|
+
organizationId?: string;
|
|
35
|
+
}, options?: O) => Promise<FetchResult<SolanaPaymentResponse, O>>;
|
|
36
|
+
}
|
|
37
|
+
interface SolanaPaymentsClientActions {
|
|
38
|
+
payment: SolanaPaymentActions;
|
|
39
|
+
}
|
|
40
|
+
declare module "better-auth/client" {
|
|
41
|
+
interface BetterAuthClient {
|
|
42
|
+
payment: SolanaPaymentActions;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
declare module "better-auth" {
|
|
46
|
+
interface BetterAuthClientPlugins {
|
|
47
|
+
solanaPayments: ReturnType<typeof solanaPaymentsClient>;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
type SolanaPaymentsClientPluginInstance = Omit<BetterAuthClientPlugin, "id" | "$InferServerPlugin" | "getActions"> & {
|
|
51
|
+
id: "solanaPayments";
|
|
52
|
+
$InferServerPlugin: ReturnType<typeof solanaPayments>;
|
|
53
|
+
getActions: ($fetch: BetterFetch, $store: unknown, options: unknown) => SolanaPaymentsClientActions;
|
|
54
|
+
};
|
|
55
|
+
declare const solanaPaymentsClient: () => SolanaPaymentsClientPluginInstance;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { FetchResult, SolanaPaymentActions, SolanaPaymentResponse, SolanaPaymentsClientActions, solanaPaymentsClient };
|
|
58
|
+
//# sourceMappingURL=client.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;KAMY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;UAEP;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,WAAW;EACX;;UAGe;EACf,SAAS,UAAU,2CACjB;IACE;IACA,WAAW;IACX;KAEF,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,SAAS,UAAU,2CACjB;IAAQ;IAAmB;KAC3B,UAAU,MACP,QAAQ,YAAY,uBAAuB;EAChD,MAAM,UAAU,2CACd;IAAQ;IAAmB;KAC3B,UAAU,MACP,QAAQ,YAAY,uBAAuB;;UAGjC;EACf,SAAS;;;YAIC;IACR,SAAS;;;;YAKD;IACR,gBAAgB,kBAAkB;;;KAIjC,qCAAqC,KACxC;EAGA;EACA,oBAAoB,kBAAkB;EACtC,aACE,QAAQ,aACR,iBACA,qBACG;;cAGM,4BAA2B"}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-Ctrvqbjd.mjs";
|
|
2
|
+
//#region src/client.ts
|
|
3
|
+
const solanaPaymentsClient = () => ({
|
|
4
|
+
id: "solanaPayments",
|
|
5
|
+
version: PACKAGE_VERSION,
|
|
6
|
+
$InferServerPlugin: {},
|
|
7
|
+
pathMethods: {
|
|
8
|
+
"/solana-payments/create-payment": "POST",
|
|
9
|
+
"/solana-payments/verify-payment": "POST",
|
|
10
|
+
"/solana-payments/payment": "GET"
|
|
11
|
+
},
|
|
12
|
+
getActions: ($fetch) => ({ payment: {
|
|
13
|
+
create: (data, options) => $fetch("/solana-payments/create-payment", {
|
|
14
|
+
...options,
|
|
15
|
+
method: "POST",
|
|
16
|
+
body: data
|
|
17
|
+
}),
|
|
18
|
+
verify: (data, options) => $fetch("/solana-payments/verify-payment", {
|
|
19
|
+
...options,
|
|
20
|
+
method: "POST",
|
|
21
|
+
body: data
|
|
22
|
+
}),
|
|
23
|
+
get: (data, options) => $fetch("/solana-payments/payment", {
|
|
24
|
+
...options,
|
|
25
|
+
method: "GET",
|
|
26
|
+
query: data
|
|
27
|
+
})
|
|
28
|
+
} })
|
|
29
|
+
});
|
|
30
|
+
//#endregion
|
|
31
|
+
export { solanaPaymentsClient };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterFetch, BetterFetchOption, BetterFetchResponse } from \"@better-fetch/fetch\";\nimport type { BetterAuthClientPlugin } from \"better-auth/client\";\n\nimport type { solanaPayments as solanaPaymentsServer } from \"./index.ts\";\nimport { PACKAGE_VERSION } from \"./version.ts\";\n\nexport type FetchResult<T, O extends BetterFetchOption | undefined> = O extends { throw: true }\n ? T\n : BetterFetchResponse<T>;\n\nexport interface SolanaPaymentResponse {\n id: string;\n reference: string;\n amount: string;\n mint: string;\n decimals: number;\n recipient: string;\n status: \"pending\" | \"paid\" | \"expired\" | \"failed\";\n expiresAt: Date;\n signature?: string;\n slot?: string;\n metadata?: Record<string, unknown>;\n paymentUrl?: string;\n}\n\nexport interface SolanaPaymentActions {\n create: <O extends BetterFetchOption | undefined = undefined>(\n data: {\n amount: string;\n metadata?: Record<string, unknown>;\n organizationId?: string;\n },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n verify: <O extends BetterFetchOption | undefined = undefined>(\n data: { reference: string; organizationId?: string },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n get: <O extends BetterFetchOption | undefined = undefined>(\n data: { reference: string; organizationId?: string },\n options?: O,\n ) => Promise<FetchResult<SolanaPaymentResponse, O>>;\n}\n\nexport interface SolanaPaymentsClientActions {\n payment: SolanaPaymentActions;\n}\n\ndeclare module \"better-auth/client\" {\n interface BetterAuthClient {\n payment: SolanaPaymentActions;\n }\n}\n\ndeclare module \"better-auth\" {\n interface BetterAuthClientPlugins {\n solanaPayments: ReturnType<typeof solanaPaymentsClient>;\n }\n}\n\ntype SolanaPaymentsClientPluginInstance = Omit<\n BetterAuthClientPlugin,\n \"id\" | \"$InferServerPlugin\" | \"getActions\"\n> & {\n id: \"solanaPayments\";\n $InferServerPlugin: ReturnType<typeof solanaPaymentsServer>;\n getActions: (\n $fetch: BetterFetch,\n $store: unknown,\n options: unknown,\n ) => SolanaPaymentsClientActions;\n};\n\nexport const solanaPaymentsClient = (): SolanaPaymentsClientPluginInstance => ({\n id: \"solanaPayments\",\n version: PACKAGE_VERSION,\n $InferServerPlugin: {} as ReturnType<typeof solanaPaymentsServer>,\n pathMethods: {\n \"/solana-payments/create-payment\": \"POST\",\n \"/solana-payments/verify-payment\": \"POST\",\n \"/solana-payments/payment\": \"GET\",\n },\n getActions: ($fetch): SolanaPaymentsClientActions => ({\n payment: {\n create: (data, options) =>\n $fetch(\"/solana-payments/create-payment\", {\n ...options,\n method: \"POST\",\n body: data,\n }),\n verify: (data, options) =>\n $fetch(\"/solana-payments/verify-payment\", {\n ...options,\n method: \"POST\",\n body: data,\n }),\n get: (data, options) =>\n $fetch(\"/solana-payments/payment\", { ...options, method: \"GET\", query: data }),\n },\n }),\n});\n"],"mappings":";;AAyEA,MAAa,8BAAkE;CAC7E,IAAI;CACJ,SAAS;CACT,oBAAoB,CAAC;CACrB,aAAa;EACX,mCAAmC;EACnC,mCAAmC;EACnC,4BAA4B;CAC9B;CACA,aAAa,YAAyC,EACpD,SAAS;EACP,SAAS,MAAM,YACb,OAAO,mCAAmC;GACxC,GAAG;GACH,QAAQ;GACR,MAAM;EACR,CAAC;EACH,SAAS,MAAM,YACb,OAAO,mCAAmC;GACxC,GAAG;GACH,QAAQ;GACR,MAAM;EACR,CAAC;EACH,MAAM,MAAM,YACV,OAAO,4BAA4B;GAAE,GAAG;GAAS,QAAQ;GAAO,OAAO;EAAK,CAAC;CACjF,EACF;AACF"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { GenericEndpointContext, InferOptionSchema } from "better-auth";
|
|
2
|
+
import { AddressInput, SolanaUsdtReadOnlyClient } from "solana-payments";
|
|
3
|
+
import { BetterAuthPluginDBSchema, DBFieldAttribute } from "better-auth/db";
|
|
4
|
+
//#region src/schema.d.ts
|
|
5
|
+
type SolanaPaymentSchema = Record<"solanaPayment", {
|
|
6
|
+
fields: Record<"reference" | "referenceType" | "referenceId" | "amount" | "mint" | "decimals" | "recipient" | "status" | "expiresAt" | "signature" | "slot" | "metadata" | "createdAt" | "updatedAt", DBFieldAttribute>;
|
|
7
|
+
}>;
|
|
8
|
+
type SolanaPaymentsPluginSchema = SolanaPaymentSchema;
|
|
9
|
+
declare const solanaPaymentsPluginSchema: SolanaPaymentSchema;
|
|
10
|
+
declare function getSchema(options: Pick<SolanaPaymentsOptions, "schema">): BetterAuthPluginDBSchema;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/types.d.ts
|
|
13
|
+
type SolanaPaymentStatus = "pending" | "paid" | "expired" | "failed";
|
|
14
|
+
interface SolanaPayment {
|
|
15
|
+
id: string;
|
|
16
|
+
reference: string;
|
|
17
|
+
referenceType: "user" | "organization";
|
|
18
|
+
referenceId: string;
|
|
19
|
+
/** Base-unit token amount, retained as a string to avoid JavaScript number rounding. */
|
|
20
|
+
amount: string;
|
|
21
|
+
mint: string;
|
|
22
|
+
decimals: number;
|
|
23
|
+
recipient: string;
|
|
24
|
+
status: SolanaPaymentStatus;
|
|
25
|
+
expiresAt: Date;
|
|
26
|
+
signature?: string | null;
|
|
27
|
+
/** Ledger slot, retained as a string to avoid JavaScript number rounding. */
|
|
28
|
+
slot?: string | null;
|
|
29
|
+
metadata?: string | null;
|
|
30
|
+
createdAt: Date;
|
|
31
|
+
updatedAt: Date;
|
|
32
|
+
}
|
|
33
|
+
interface SolanaPaymentsOptions {
|
|
34
|
+
client: SolanaUsdtReadOnlyClient;
|
|
35
|
+
recipient: AddressInput;
|
|
36
|
+
paymentExpirationMs?: number;
|
|
37
|
+
onPaymentComplete?: (payment: SolanaPayment, context: GenericEndpointContext) => Promise<void> | void;
|
|
38
|
+
organization?: {
|
|
39
|
+
enabled?: boolean;
|
|
40
|
+
};
|
|
41
|
+
schema?: InferOptionSchema<SolanaPaymentsPluginSchema>;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/version.d.ts
|
|
45
|
+
declare const PACKAGE_VERSION = "0.1.0";
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/store.d.ts
|
|
48
|
+
type Adapter = {
|
|
49
|
+
create<T>(input: {
|
|
50
|
+
model: string;
|
|
51
|
+
data: Omit<T, "id">;
|
|
52
|
+
}): Promise<T>;
|
|
53
|
+
findOne<T>(input: {
|
|
54
|
+
model: string;
|
|
55
|
+
where: WhereClause;
|
|
56
|
+
}): Promise<T | null>;
|
|
57
|
+
update<T>(input: {
|
|
58
|
+
model: string;
|
|
59
|
+
update: Partial<T>;
|
|
60
|
+
where: WhereClause;
|
|
61
|
+
}): Promise<T | null>;
|
|
62
|
+
};
|
|
63
|
+
type WhereClause = {
|
|
64
|
+
field: string;
|
|
65
|
+
value: string;
|
|
66
|
+
}[];
|
|
67
|
+
interface SolanaPaymentStoreContext {
|
|
68
|
+
adapter: Adapter;
|
|
69
|
+
session?: {
|
|
70
|
+
user?: {
|
|
71
|
+
id: string;
|
|
72
|
+
} | null;
|
|
73
|
+
} | null;
|
|
74
|
+
organizationId?: string;
|
|
75
|
+
hasOrganizationPlugin?: boolean;
|
|
76
|
+
}
|
|
77
|
+
type CreateSolanaPaymentInput = Omit<SolanaPayment, "id" | "referenceType" | "referenceId" | "status" | "createdAt" | "updatedAt">;
|
|
78
|
+
interface MarkPaidInput {
|
|
79
|
+
signature?: string;
|
|
80
|
+
slot?: string;
|
|
81
|
+
}
|
|
82
|
+
interface MarkPaidResult {
|
|
83
|
+
payment: SolanaPayment | null;
|
|
84
|
+
transitioned: boolean;
|
|
85
|
+
}
|
|
86
|
+
interface SolanaPaymentStore {
|
|
87
|
+
assertOwner(): Promise<void>;
|
|
88
|
+
create(input: CreateSolanaPaymentInput): Promise<SolanaPayment>;
|
|
89
|
+
findById(id: string): Promise<SolanaPayment | null>;
|
|
90
|
+
findByReference(reference: string): Promise<SolanaPayment | null>;
|
|
91
|
+
markPaid(reference: string, input?: MarkPaidInput): Promise<SolanaPayment | null>;
|
|
92
|
+
markPaidWithTransition(reference: string, input?: MarkPaidInput): Promise<MarkPaidResult>;
|
|
93
|
+
markExpired(reference: string): Promise<SolanaPayment | null>;
|
|
94
|
+
}
|
|
95
|
+
declare function createSolanaPaymentStore(context: SolanaPaymentStoreContext): SolanaPaymentStore;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/index.d.ts
|
|
98
|
+
declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
99
|
+
id: "solanaPayments";
|
|
100
|
+
endpoints: {
|
|
101
|
+
createPayment: import("better-call").StrictEndpoint<"/solana-payments/create-payment", {
|
|
102
|
+
method: "POST";
|
|
103
|
+
body: import("zod").ZodObject<{
|
|
104
|
+
amount: import("zod").ZodString;
|
|
105
|
+
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
|
|
106
|
+
organizationId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
107
|
+
}, import("zod/v4/core").$strip>;
|
|
108
|
+
use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
109
|
+
session: {
|
|
110
|
+
session: Record<string, any> & {
|
|
111
|
+
id: string;
|
|
112
|
+
createdAt: Date;
|
|
113
|
+
updatedAt: Date;
|
|
114
|
+
userId: string;
|
|
115
|
+
expiresAt: Date;
|
|
116
|
+
token: string;
|
|
117
|
+
ipAddress?: string | null | undefined;
|
|
118
|
+
userAgent?: string | null | undefined;
|
|
119
|
+
};
|
|
120
|
+
user: Record<string, any> & {
|
|
121
|
+
id: string;
|
|
122
|
+
createdAt: Date;
|
|
123
|
+
updatedAt: Date;
|
|
124
|
+
email: string;
|
|
125
|
+
emailVerified: boolean;
|
|
126
|
+
name: string;
|
|
127
|
+
image?: string | null | undefined;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
}>) | ((getValue: (ctx: import("better-auth").GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
|
|
131
|
+
}, {
|
|
132
|
+
paymentUrl?: string | undefined;
|
|
133
|
+
id: string;
|
|
134
|
+
reference: string;
|
|
135
|
+
amount: string;
|
|
136
|
+
mint: string;
|
|
137
|
+
decimals: number;
|
|
138
|
+
recipient: string;
|
|
139
|
+
status: SolanaPaymentStatus;
|
|
140
|
+
expiresAt: Date;
|
|
141
|
+
signature: string | undefined;
|
|
142
|
+
slot: string | undefined;
|
|
143
|
+
metadata: Record<string, unknown> | undefined;
|
|
144
|
+
}>;
|
|
145
|
+
verifyPayment: import("better-call").StrictEndpoint<"/solana-payments/verify-payment", {
|
|
146
|
+
method: "POST";
|
|
147
|
+
body: import("zod").ZodObject<{
|
|
148
|
+
reference: import("zod").ZodString;
|
|
149
|
+
organizationId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
150
|
+
}, import("zod/v4/core").$strip>;
|
|
151
|
+
use: (((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
152
|
+
session: {
|
|
153
|
+
session: Record<string, any> & {
|
|
154
|
+
id: string;
|
|
155
|
+
createdAt: Date;
|
|
156
|
+
updatedAt: Date;
|
|
157
|
+
userId: string;
|
|
158
|
+
expiresAt: Date;
|
|
159
|
+
token: string;
|
|
160
|
+
ipAddress?: string | null | undefined;
|
|
161
|
+
userAgent?: string | null | undefined;
|
|
162
|
+
};
|
|
163
|
+
user: Record<string, any> & {
|
|
164
|
+
id: string;
|
|
165
|
+
createdAt: Date;
|
|
166
|
+
updatedAt: Date;
|
|
167
|
+
email: string;
|
|
168
|
+
emailVerified: boolean;
|
|
169
|
+
name: string;
|
|
170
|
+
image?: string | null | undefined;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
}>) | ((getValue: (ctx: import("better-auth").GenericEndpointContext) => string | string[]) => (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<void>))[];
|
|
174
|
+
}, {
|
|
175
|
+
paymentUrl?: string | undefined;
|
|
176
|
+
id: string;
|
|
177
|
+
reference: string;
|
|
178
|
+
amount: string;
|
|
179
|
+
mint: string;
|
|
180
|
+
decimals: number;
|
|
181
|
+
recipient: string;
|
|
182
|
+
status: SolanaPaymentStatus;
|
|
183
|
+
expiresAt: Date;
|
|
184
|
+
signature: string | undefined;
|
|
185
|
+
slot: string | undefined;
|
|
186
|
+
metadata: Record<string, unknown> | undefined;
|
|
187
|
+
}>;
|
|
188
|
+
getPayment: import("better-call").StrictEndpoint<"/solana-payments/payment", {
|
|
189
|
+
method: "GET";
|
|
190
|
+
query: import("zod").ZodObject<{
|
|
191
|
+
reference: import("zod").ZodString;
|
|
192
|
+
organizationId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
193
|
+
}, import("zod/v4/core").$strip>;
|
|
194
|
+
use: ((inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
|
|
195
|
+
session: {
|
|
196
|
+
session: Record<string, any> & {
|
|
197
|
+
id: string;
|
|
198
|
+
createdAt: Date;
|
|
199
|
+
updatedAt: Date;
|
|
200
|
+
userId: string;
|
|
201
|
+
expiresAt: Date;
|
|
202
|
+
token: string;
|
|
203
|
+
ipAddress?: string | null | undefined;
|
|
204
|
+
userAgent?: string | null | undefined;
|
|
205
|
+
};
|
|
206
|
+
user: Record<string, any> & {
|
|
207
|
+
id: string;
|
|
208
|
+
createdAt: Date;
|
|
209
|
+
updatedAt: Date;
|
|
210
|
+
email: string;
|
|
211
|
+
emailVerified: boolean;
|
|
212
|
+
name: string;
|
|
213
|
+
image?: string | null | undefined;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
}>)[];
|
|
217
|
+
}, {
|
|
218
|
+
paymentUrl?: string | undefined;
|
|
219
|
+
id: string;
|
|
220
|
+
reference: string;
|
|
221
|
+
amount: string;
|
|
222
|
+
mint: string;
|
|
223
|
+
decimals: number;
|
|
224
|
+
recipient: string;
|
|
225
|
+
status: SolanaPaymentStatus;
|
|
226
|
+
expiresAt: Date;
|
|
227
|
+
signature: string | undefined;
|
|
228
|
+
slot: string | undefined;
|
|
229
|
+
metadata: Record<string, unknown> | undefined;
|
|
230
|
+
}>;
|
|
231
|
+
};
|
|
232
|
+
schema: import("better-auth").BetterAuthPluginDBSchema;
|
|
233
|
+
$ERROR_CODES: {
|
|
234
|
+
MISSING_SESSION: import("better-auth").RawError<"MISSING_SESSION">;
|
|
235
|
+
UNAUTHORIZED_PAYMENT: import("better-auth").RawError<"UNAUTHORIZED_PAYMENT">;
|
|
236
|
+
PAYMENT_EXPIRED: import("better-auth").RawError<"PAYMENT_EXPIRED">;
|
|
237
|
+
INVALID_PAYMENT: import("better-auth").RawError<"INVALID_PAYMENT">;
|
|
238
|
+
PAYMENT_MISMATCH: import("better-auth").RawError<"PAYMENT_MISMATCH">;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
//#endregion
|
|
242
|
+
export { SolanaPaymentStore as a, PACKAGE_VERSION as c, SolanaPaymentsOptions as d, getSchema as f, MarkPaidResult as i, SolanaPayment as l, CreateSolanaPaymentInput as n, SolanaPaymentStoreContext as o, solanaPaymentsPluginSchema as p, MarkPaidInput as r, createSolanaPaymentStore as s, solanaPayments as t, SolanaPaymentStatus as u };
|
|
243
|
+
//# sourceMappingURL=index-BAy-bbzL.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BAy-bbzL.d.mts","names":[],"sources":["../src/schema.ts","../src/types.d.ts","../src/version.ts","../src/store.ts","../src/index.ts"],"mappings":";;;;KAIK,sBAAsB;EAGvB,QAAQ,8LAeN;;KA0BM,6BAA6B;cAC5B,4BAA4B;iBAEzB,UACd,SAAS,KAAK,mCACb;;;KClDS;UACK;EACb;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA,QAAQ;EACR,WAAW;EACX;;EAEA;EACA;EACA,WAAW;EACX,WAAW;;UAEE;EACb,QAAQ;EACR,WAAW;EACX;EACA,qBAAqB,SAAS,eAAe,SAAS,2BAA2B;EACjF;IACI;;EAEJ,SAAS,kBAAkB;;;;cC/BlB;;;KCIR;EACH,OAAO,GAAG;IAAS;IAAe,MAAM,KAAK;MAAa,QAAQ;EAClE,QAAQ,GAAG;IAAS;IAAe,OAAO;MAAgB,QAAQ;EAClE,OAAO,GAAG;IAAS;IAAe,QAAQ,QAAQ;IAAI,OAAO;MAAgB,QAAQ;;KAElF;EAAgB;EAAe;;UAEnB;EACf,SAAS;EACT;IAAY;MAAS;;;EACrB;EACA;;KAGU,2BAA2B,KACrC;UAIe;EACf;EACA;;UAGe;EACf,SAAS;EACT;;UAGe;EACf,eAAe;EACf,OAAO,OAAO,2BAA2B,QAAQ;EACjD,SAAS,aAAa,QAAQ;EAC9B,gBAAgB,oBAAoB,QAAQ;EAC5C,SAAS,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC5D,uBAAuB,mBAAmB,QAAQ,gBAAgB,QAAQ;EAC1E,YAAY,oBAAoB,QAAQ;;iBAG1B,yBAAyB,SAAS,4BAA4B;;;iBCjB9D,eAAe,OAAO;;;;;;;;;;;;;;;;;;;YAwB0pD;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SolanaPaymentStore, c as PACKAGE_VERSION, d as SolanaPaymentsOptions, f as getSchema, i as MarkPaidResult, l as SolanaPayment, n as CreateSolanaPaymentInput, o as SolanaPaymentStoreContext, p as solanaPaymentsPluginSchema, r as MarkPaidInput, s as createSolanaPaymentStore, t as solanaPayments, u as SolanaPaymentStatus } from "./index-BAy-bbzL.mjs";
|
|
2
|
+
export { type CreateSolanaPaymentInput, type MarkPaidInput, type MarkPaidResult, PACKAGE_VERSION, type SolanaPayment, type SolanaPaymentStatus, type SolanaPaymentStore, type SolanaPaymentStoreContext, type SolanaPaymentsOptions, createSolanaPaymentStore, getSchema, solanaPayments, solanaPaymentsPluginSchema };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-Ctrvqbjd.mjs";
|
|
2
|
+
import { defineErrorCodes } from "better-auth";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { APIError, createAuthEndpoint, getSessionFromCtx, originCheck, sessionMiddleware } from "better-auth/api";
|
|
5
|
+
import { formatTokenAmount } from "solana-payments";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { mergeSchema } from "better-auth/db";
|
|
8
|
+
//#region src/store.ts
|
|
9
|
+
const SOLANA_PAYMENT_MODEL = "solanaPayment";
|
|
10
|
+
function createSolanaPaymentStore(context) {
|
|
11
|
+
const getOwner = async () => {
|
|
12
|
+
const userId = context.session?.user?.id;
|
|
13
|
+
if (!userId) throw new Error("A session user is required to access Solana payments");
|
|
14
|
+
if (!context.organizationId) return {
|
|
15
|
+
type: "user",
|
|
16
|
+
id: userId
|
|
17
|
+
};
|
|
18
|
+
if (!context.hasOrganizationPlugin) throw new Error("The Better Auth organization plugin is required for organization payments");
|
|
19
|
+
if (!await context.adapter.findOne({
|
|
20
|
+
model: "member",
|
|
21
|
+
where: [{
|
|
22
|
+
field: "organizationId",
|
|
23
|
+
value: context.organizationId
|
|
24
|
+
}, {
|
|
25
|
+
field: "userId",
|
|
26
|
+
value: userId
|
|
27
|
+
}]
|
|
28
|
+
})) throw new Error("The session user must be an organization member");
|
|
29
|
+
return {
|
|
30
|
+
type: "organization",
|
|
31
|
+
id: context.organizationId
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const paymentWhere = async (where) => {
|
|
35
|
+
const owner = await getOwner();
|
|
36
|
+
return [
|
|
37
|
+
...where,
|
|
38
|
+
{
|
|
39
|
+
field: "referenceType",
|
|
40
|
+
value: owner.type
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
field: "referenceId",
|
|
44
|
+
value: owner.id
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
};
|
|
48
|
+
const findByReference = async (reference) => context.adapter.findOne({
|
|
49
|
+
model: SOLANA_PAYMENT_MODEL,
|
|
50
|
+
where: await paymentWhere([{
|
|
51
|
+
field: "reference",
|
|
52
|
+
value: reference
|
|
53
|
+
}])
|
|
54
|
+
});
|
|
55
|
+
const markPaidWithTransition = async (reference, input = {}) => {
|
|
56
|
+
const payment = await findByReference(reference);
|
|
57
|
+
if (!payment) return {
|
|
58
|
+
payment: null,
|
|
59
|
+
transitioned: false
|
|
60
|
+
};
|
|
61
|
+
if (payment.status === "paid") return {
|
|
62
|
+
payment,
|
|
63
|
+
transitioned: false
|
|
64
|
+
};
|
|
65
|
+
if (payment.status !== "pending") return {
|
|
66
|
+
payment: null,
|
|
67
|
+
transitioned: false
|
|
68
|
+
};
|
|
69
|
+
const updated = await context.adapter.update({
|
|
70
|
+
model: SOLANA_PAYMENT_MODEL,
|
|
71
|
+
update: {
|
|
72
|
+
status: "paid",
|
|
73
|
+
...input,
|
|
74
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
75
|
+
},
|
|
76
|
+
where: await paymentWhere([{
|
|
77
|
+
field: "id",
|
|
78
|
+
value: payment.id
|
|
79
|
+
}, {
|
|
80
|
+
field: "status",
|
|
81
|
+
value: "pending"
|
|
82
|
+
}])
|
|
83
|
+
});
|
|
84
|
+
if (updated) return {
|
|
85
|
+
payment: updated,
|
|
86
|
+
transitioned: true
|
|
87
|
+
};
|
|
88
|
+
const current = await findByReference(reference);
|
|
89
|
+
return {
|
|
90
|
+
payment: current?.status === "paid" ? current : null,
|
|
91
|
+
transitioned: false
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
async assertOwner() {
|
|
96
|
+
await getOwner();
|
|
97
|
+
},
|
|
98
|
+
async create(input) {
|
|
99
|
+
const owner = await getOwner();
|
|
100
|
+
const now = /* @__PURE__ */ new Date();
|
|
101
|
+
return context.adapter.create({
|
|
102
|
+
model: SOLANA_PAYMENT_MODEL,
|
|
103
|
+
data: {
|
|
104
|
+
...input,
|
|
105
|
+
referenceType: owner.type,
|
|
106
|
+
referenceId: owner.id,
|
|
107
|
+
status: "pending",
|
|
108
|
+
createdAt: now,
|
|
109
|
+
updatedAt: now
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
findById: async (id) => context.adapter.findOne({
|
|
114
|
+
model: SOLANA_PAYMENT_MODEL,
|
|
115
|
+
where: await paymentWhere([{
|
|
116
|
+
field: "id",
|
|
117
|
+
value: id
|
|
118
|
+
}])
|
|
119
|
+
}),
|
|
120
|
+
findByReference,
|
|
121
|
+
async markPaid(reference, input = {}) {
|
|
122
|
+
return (await markPaidWithTransition(reference, input)).payment;
|
|
123
|
+
},
|
|
124
|
+
markPaidWithTransition,
|
|
125
|
+
async markExpired(reference) {
|
|
126
|
+
const payment = await findByReference(reference);
|
|
127
|
+
if (!payment || payment.status !== "pending") return payment?.status === "expired" ? payment : null;
|
|
128
|
+
return context.adapter.update({
|
|
129
|
+
model: SOLANA_PAYMENT_MODEL,
|
|
130
|
+
update: {
|
|
131
|
+
status: "expired",
|
|
132
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
133
|
+
},
|
|
134
|
+
where: await paymentWhere([{
|
|
135
|
+
field: "id",
|
|
136
|
+
value: payment.id
|
|
137
|
+
}, {
|
|
138
|
+
field: "status",
|
|
139
|
+
value: "pending"
|
|
140
|
+
}])
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/routes.ts
|
|
147
|
+
const createPaymentBody = z.object({
|
|
148
|
+
amount: z.string().min(1),
|
|
149
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
150
|
+
organizationId: z.string().min(1).optional()
|
|
151
|
+
});
|
|
152
|
+
const verifyPaymentBody = z.object({
|
|
153
|
+
reference: z.string().min(1),
|
|
154
|
+
organizationId: z.string().min(1).optional()
|
|
155
|
+
});
|
|
156
|
+
const getPaymentQuery = z.object({
|
|
157
|
+
reference: z.string().min(1),
|
|
158
|
+
organizationId: z.string().min(1).optional()
|
|
159
|
+
});
|
|
160
|
+
function routeError(code, message) {
|
|
161
|
+
throw new APIError(code === "MISSING_SESSION" ? "UNAUTHORIZED" : "BAD_REQUEST", {
|
|
162
|
+
code,
|
|
163
|
+
message
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
async function paymentStore(ctx, organizationId) {
|
|
167
|
+
const session = await getSessionFromCtx(ctx);
|
|
168
|
+
if (!session) routeError("MISSING_SESSION", "An authenticated session is required.");
|
|
169
|
+
try {
|
|
170
|
+
const store = createSolanaPaymentStore({
|
|
171
|
+
adapter: ctx.context.adapter,
|
|
172
|
+
session,
|
|
173
|
+
organizationId,
|
|
174
|
+
hasOrganizationPlugin: ctx.context.hasPlugin?.("organization") === true
|
|
175
|
+
});
|
|
176
|
+
await store.assertOwner();
|
|
177
|
+
return store;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
routeError("UNAUTHORIZED_PAYMENT", error instanceof Error ? error.message : "Unauthorized payment.");
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async function loadPayment(ctx, reference, organizationId) {
|
|
183
|
+
const store = await paymentStore(ctx, organizationId);
|
|
184
|
+
try {
|
|
185
|
+
const payment = await store.findByReference(reference);
|
|
186
|
+
if (!payment) routeError("UNAUTHORIZED_PAYMENT", "Payment was not found for this owner.");
|
|
187
|
+
return {
|
|
188
|
+
store,
|
|
189
|
+
payment
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (error instanceof APIError) throw error;
|
|
193
|
+
routeError("UNAUTHORIZED_PAYMENT", error instanceof Error ? error.message : "Unauthorized payment.");
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function asResponse(payment, paymentUrl) {
|
|
197
|
+
return {
|
|
198
|
+
id: payment.id,
|
|
199
|
+
reference: payment.reference,
|
|
200
|
+
amount: payment.amount,
|
|
201
|
+
mint: payment.mint,
|
|
202
|
+
decimals: payment.decimals,
|
|
203
|
+
recipient: payment.recipient,
|
|
204
|
+
status: payment.status,
|
|
205
|
+
expiresAt: payment.expiresAt,
|
|
206
|
+
signature: payment.signature ?? void 0,
|
|
207
|
+
slot: payment.slot ?? void 0,
|
|
208
|
+
metadata: payment.metadata ? JSON.parse(payment.metadata) : void 0,
|
|
209
|
+
...paymentUrl ? { paymentUrl } : {}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const createPayment = (options, path = "/create-payment") => createAuthEndpoint(path, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
body: createPaymentBody,
|
|
215
|
+
use: [sessionMiddleware, originCheck]
|
|
216
|
+
}, async (ctx) => {
|
|
217
|
+
const store = await paymentStore(ctx, ctx.body.organizationId);
|
|
218
|
+
const reference = randomUUID();
|
|
219
|
+
const request = options.client.payments.createRequest({
|
|
220
|
+
amount: ctx.body.amount,
|
|
221
|
+
recipient: options.recipient,
|
|
222
|
+
reference,
|
|
223
|
+
metadata: ctx.body.metadata
|
|
224
|
+
});
|
|
225
|
+
const payment = await store.create({
|
|
226
|
+
reference: request.reference,
|
|
227
|
+
amount: request.amount.toString(),
|
|
228
|
+
mint: request.mint,
|
|
229
|
+
decimals: request.decimals,
|
|
230
|
+
recipient: request.recipient ?? options.recipient,
|
|
231
|
+
expiresAt: new Date(Date.now() + (options.paymentExpirationMs ?? 1800 * 1e3)),
|
|
232
|
+
metadata: ctx.body.metadata ? JSON.stringify(ctx.body.metadata) : null,
|
|
233
|
+
signature: null,
|
|
234
|
+
slot: null
|
|
235
|
+
});
|
|
236
|
+
const paymentUrl = options.client.payments.toSolanaPayUrl(request).toString();
|
|
237
|
+
return ctx.json(asResponse(payment, paymentUrl));
|
|
238
|
+
});
|
|
239
|
+
const verifyPayment = (options, path = "/verify-payment", callbacksInFlight = /* @__PURE__ */ new Set()) => createAuthEndpoint(path, {
|
|
240
|
+
method: "POST",
|
|
241
|
+
body: verifyPaymentBody,
|
|
242
|
+
use: [sessionMiddleware, originCheck]
|
|
243
|
+
}, async (ctx) => {
|
|
244
|
+
const { store, payment } = await loadPayment(ctx, ctx.body.reference, ctx.body.organizationId);
|
|
245
|
+
if (payment.status === "paid") return ctx.json(asResponse(payment));
|
|
246
|
+
if (payment.status === "expired" || payment.expiresAt <= /* @__PURE__ */ new Date()) {
|
|
247
|
+
if (payment.status === "pending") await store.markExpired(payment.reference);
|
|
248
|
+
routeError("PAYMENT_EXPIRED", "Payment intent has expired.");
|
|
249
|
+
}
|
|
250
|
+
if (payment.status !== "pending") routeError("INVALID_PAYMENT", "Payment is not pending.");
|
|
251
|
+
const wasPending = payment.status === "pending";
|
|
252
|
+
let verified;
|
|
253
|
+
try {
|
|
254
|
+
verified = await options.client.payments.verify({
|
|
255
|
+
reference: payment.reference,
|
|
256
|
+
recipient: payment.recipient,
|
|
257
|
+
amount: formatTokenAmount(payment.amount, payment.decimals)
|
|
258
|
+
});
|
|
259
|
+
} catch (error) {
|
|
260
|
+
routeError("PAYMENT_MISMATCH", error instanceof Error ? error.message : "Payment did not match intent.");
|
|
261
|
+
}
|
|
262
|
+
if (!verified.found || verified.reference !== payment.reference || verified.recipient !== payment.recipient || verified.amount?.toString() !== payment.amount) routeError("PAYMENT_MISMATCH", "Payment did not exactly match the stored intent.");
|
|
263
|
+
const { payment: paid, transitioned } = await store.markPaidWithTransition(payment.reference, {
|
|
264
|
+
signature: verified.signature,
|
|
265
|
+
slot: verified.slot?.toString()
|
|
266
|
+
});
|
|
267
|
+
if (!paid) routeError("INVALID_PAYMENT", "Payment state could not be updated.");
|
|
268
|
+
if (wasPending && transitioned && !callbacksInFlight.has(paid.reference)) {
|
|
269
|
+
callbacksInFlight.add(paid.reference);
|
|
270
|
+
try {
|
|
271
|
+
await options.onPaymentComplete?.(paid, ctx);
|
|
272
|
+
} finally {
|
|
273
|
+
callbacksInFlight.delete(paid.reference);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return ctx.json(asResponse(paid));
|
|
277
|
+
});
|
|
278
|
+
const getPayment = (options, path = "/payment") => createAuthEndpoint(path, {
|
|
279
|
+
method: "GET",
|
|
280
|
+
query: getPaymentQuery,
|
|
281
|
+
use: [sessionMiddleware]
|
|
282
|
+
}, async (ctx) => {
|
|
283
|
+
const { store, payment } = await loadPayment(ctx, ctx.query.reference, ctx.query.organizationId);
|
|
284
|
+
const current = payment.status === "pending" && payment.expiresAt <= /* @__PURE__ */ new Date() ? await store.markExpired(payment.reference) : payment;
|
|
285
|
+
return ctx.json(asResponse(current ?? payment));
|
|
286
|
+
});
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/schema.ts
|
|
289
|
+
const solanaPaymentSchema = { solanaPayment: { fields: {
|
|
290
|
+
reference: {
|
|
291
|
+
type: "string",
|
|
292
|
+
required: true,
|
|
293
|
+
unique: true
|
|
294
|
+
},
|
|
295
|
+
referenceType: {
|
|
296
|
+
type: "string",
|
|
297
|
+
required: true
|
|
298
|
+
},
|
|
299
|
+
referenceId: {
|
|
300
|
+
type: "string",
|
|
301
|
+
required: true,
|
|
302
|
+
index: true
|
|
303
|
+
},
|
|
304
|
+
amount: {
|
|
305
|
+
type: "string",
|
|
306
|
+
required: true
|
|
307
|
+
},
|
|
308
|
+
mint: {
|
|
309
|
+
type: "string",
|
|
310
|
+
required: true
|
|
311
|
+
},
|
|
312
|
+
decimals: {
|
|
313
|
+
type: "number",
|
|
314
|
+
required: true
|
|
315
|
+
},
|
|
316
|
+
recipient: {
|
|
317
|
+
type: "string",
|
|
318
|
+
required: true
|
|
319
|
+
},
|
|
320
|
+
status: {
|
|
321
|
+
type: "string",
|
|
322
|
+
required: true,
|
|
323
|
+
defaultValue: "pending",
|
|
324
|
+
index: true
|
|
325
|
+
},
|
|
326
|
+
expiresAt: {
|
|
327
|
+
type: "date",
|
|
328
|
+
required: true
|
|
329
|
+
},
|
|
330
|
+
signature: {
|
|
331
|
+
type: "string",
|
|
332
|
+
required: false,
|
|
333
|
+
unique: true
|
|
334
|
+
},
|
|
335
|
+
slot: {
|
|
336
|
+
type: "string",
|
|
337
|
+
required: false
|
|
338
|
+
},
|
|
339
|
+
metadata: {
|
|
340
|
+
type: "string",
|
|
341
|
+
required: false
|
|
342
|
+
},
|
|
343
|
+
createdAt: {
|
|
344
|
+
type: "date",
|
|
345
|
+
required: true
|
|
346
|
+
},
|
|
347
|
+
updatedAt: {
|
|
348
|
+
type: "date",
|
|
349
|
+
required: true
|
|
350
|
+
}
|
|
351
|
+
} } };
|
|
352
|
+
const solanaPaymentsPluginSchema = solanaPaymentSchema;
|
|
353
|
+
function getSchema(options) {
|
|
354
|
+
return mergeSchema(solanaPaymentSchema, options.schema);
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/index.ts
|
|
358
|
+
const ERROR_CODES = defineErrorCodes({
|
|
359
|
+
MISSING_SESSION: "An authenticated session is required.",
|
|
360
|
+
UNAUTHORIZED_PAYMENT: "Payment was not found for this owner.",
|
|
361
|
+
PAYMENT_EXPIRED: "Payment intent has expired.",
|
|
362
|
+
INVALID_PAYMENT: "Payment is invalid.",
|
|
363
|
+
PAYMENT_MISMATCH: "Payment did not exactly match the stored intent."
|
|
364
|
+
});
|
|
365
|
+
function solanaPayments(input) {
|
|
366
|
+
const normalized = input.client.payments.createRequest({
|
|
367
|
+
amount: "0",
|
|
368
|
+
recipient: input.recipient,
|
|
369
|
+
reference: "solana-payments-recipient-normalization"
|
|
370
|
+
}).recipient;
|
|
371
|
+
if (!normalized) throw new Error("A Solana payment recipient is required.");
|
|
372
|
+
const options = {
|
|
373
|
+
...input,
|
|
374
|
+
recipient: normalized,
|
|
375
|
+
paymentExpirationMs: input.paymentExpirationMs ?? 1800 * 1e3
|
|
376
|
+
};
|
|
377
|
+
const callbacksInFlight = /* @__PURE__ */ new Set();
|
|
378
|
+
return {
|
|
379
|
+
id: "solanaPayments",
|
|
380
|
+
endpoints: {
|
|
381
|
+
createPayment: createPayment(options, "/solana-payments/create-payment"),
|
|
382
|
+
verifyPayment: verifyPayment(options, "/solana-payments/verify-payment", callbacksInFlight),
|
|
383
|
+
getPayment: getPayment(options, "/solana-payments/payment")
|
|
384
|
+
},
|
|
385
|
+
schema: getSchema(options),
|
|
386
|
+
$ERROR_CODES: ERROR_CODES
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
//#endregion
|
|
390
|
+
export { PACKAGE_VERSION, createSolanaPaymentStore, getSchema, solanaPayments, solanaPaymentsPluginSchema };
|
|
391
|
+
|
|
392
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/store.ts","../src/routes.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["import type { SolanaPayment } from \"./types.ts\";\n\nconst SOLANA_PAYMENT_MODEL = \"solanaPayment\";\n\ntype Adapter = {\n create<T>(input: { model: string; data: Omit<T, \"id\"> }): Promise<T>;\n findOne<T>(input: { model: string; where: WhereClause }): Promise<T | null>;\n update<T>(input: { model: string; update: Partial<T>; where: WhereClause }): Promise<T | null>;\n};\ntype WhereClause = { field: string; value: string }[];\n\nexport interface SolanaPaymentStoreContext {\n adapter: Adapter;\n session?: { user?: { id: string } | null } | null;\n organizationId?: string;\n hasOrganizationPlugin?: boolean;\n}\n\nexport type CreateSolanaPaymentInput = Omit<\n SolanaPayment,\n \"id\" | \"referenceType\" | \"referenceId\" | \"status\" | \"createdAt\" | \"updatedAt\"\n>;\n\nexport interface MarkPaidInput {\n signature?: string;\n slot?: string;\n}\n\nexport interface MarkPaidResult {\n payment: SolanaPayment | null;\n transitioned: boolean;\n}\n\nexport interface SolanaPaymentStore {\n assertOwner(): Promise<void>;\n create(input: CreateSolanaPaymentInput): Promise<SolanaPayment>;\n findById(id: string): Promise<SolanaPayment | null>;\n findByReference(reference: string): Promise<SolanaPayment | null>;\n markPaid(reference: string, input?: MarkPaidInput): Promise<SolanaPayment | null>;\n markPaidWithTransition(reference: string, input?: MarkPaidInput): Promise<MarkPaidResult>;\n markExpired(reference: string): Promise<SolanaPayment | null>;\n}\n\nexport function createSolanaPaymentStore(context: SolanaPaymentStoreContext): SolanaPaymentStore {\n const getOwner = async (): Promise<{ type: \"user\" | \"organization\"; id: string }> => {\n const userId = context.session?.user?.id;\n if (!userId) throw new Error(\"A session user is required to access Solana payments\");\n\n if (!context.organizationId) return { type: \"user\", id: userId };\n if (!context.hasOrganizationPlugin) {\n throw new Error(\"The Better Auth organization plugin is required for organization payments\");\n }\n\n const member = await context.adapter.findOne<{ id: string }>({\n model: \"member\",\n where: [\n { field: \"organizationId\", value: context.organizationId },\n { field: \"userId\", value: userId },\n ],\n });\n if (!member) throw new Error(\"The session user must be an organization member\");\n return { type: \"organization\", id: context.organizationId };\n };\n\n const paymentWhere = async (where: WhereClause): Promise<WhereClause> => {\n const owner = await getOwner();\n return [\n ...where,\n { field: \"referenceType\", value: owner.type },\n { field: \"referenceId\", value: owner.id },\n ];\n };\n\n const findByReference = async (reference: string): Promise<SolanaPayment | null> =>\n context.adapter.findOne<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([{ field: \"reference\", value: reference }]),\n });\n\n const markPaidWithTransition = async (\n reference: string,\n input: MarkPaidInput = {},\n ): Promise<MarkPaidResult> => {\n const payment = await findByReference(reference);\n if (!payment) return { payment: null, transitioned: false };\n if (payment.status === \"paid\") return { payment, transitioned: false };\n if (payment.status !== \"pending\") return { payment: null, transitioned: false };\n const updated = await context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n update: { status: \"paid\", ...input, updatedAt: new Date() },\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"status\", value: \"pending\" },\n ]),\n });\n if (updated) return { payment: updated, transitioned: true };\n const current = await findByReference(reference);\n return { payment: current?.status === \"paid\" ? current : null, transitioned: false };\n };\n\n return {\n async assertOwner() {\n await getOwner();\n },\n async create(input) {\n const owner = await getOwner();\n const now = new Date();\n return context.adapter.create<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n data: {\n ...input,\n referenceType: owner.type,\n referenceId: owner.id,\n status: \"pending\",\n createdAt: now,\n updatedAt: now,\n },\n });\n },\n findById: async (id) =>\n context.adapter.findOne<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([{ field: \"id\", value: id }]),\n }),\n findByReference,\n async markPaid(reference, input = {}) {\n return (await markPaidWithTransition(reference, input)).payment;\n },\n markPaidWithTransition,\n async markExpired(reference) {\n const payment = await findByReference(reference);\n if (!payment || payment.status !== \"pending\")\n return payment?.status === \"expired\" ? payment : null;\n\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n update: { status: \"expired\", updatedAt: new Date() },\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"status\", value: \"pending\" },\n ]),\n });\n },\n };\n}\n","import { randomUUID } from \"node:crypto\";\n\nimport {\n APIError,\n createAuthEndpoint,\n getSessionFromCtx,\n originCheck,\n sessionMiddleware,\n} from \"better-auth/api\";\nimport type { GenericEndpointContext } from \"better-auth\";\nimport { formatTokenAmount } from \"solana-payments\";\nimport { z } from \"zod\";\n\nimport { createSolanaPaymentStore } from \"./store.ts\";\nimport type { SolanaPayment, SolanaPaymentsOptions } from \"./types.ts\";\n\nconst createPaymentBody = z.object({\n amount: z.string().min(1),\n metadata: z.record(z.string(), z.unknown()).optional(),\n organizationId: z.string().min(1).optional(),\n});\nconst verifyPaymentBody = z.object({\n reference: z.string().min(1),\n organizationId: z.string().min(1).optional(),\n});\nconst getPaymentQuery = z.object({\n reference: z.string().min(1),\n organizationId: z.string().min(1).optional(),\n});\n\nfunction routeError(\n code:\n | \"MISSING_SESSION\"\n | \"UNAUTHORIZED_PAYMENT\"\n | \"PAYMENT_EXPIRED\"\n | \"INVALID_PAYMENT\"\n | \"PAYMENT_MISMATCH\",\n message: string,\n): never {\n throw new APIError(code === \"MISSING_SESSION\" ? \"UNAUTHORIZED\" : \"BAD_REQUEST\", {\n code,\n message,\n });\n}\n\nasync function paymentStore(ctx: GenericEndpointContext, organizationId?: string) {\n const session = await getSessionFromCtx(ctx);\n if (!session) routeError(\"MISSING_SESSION\", \"An authenticated session is required.\");\n try {\n const store = createSolanaPaymentStore({\n adapter: ctx.context.adapter,\n session,\n organizationId,\n hasOrganizationPlugin: ctx.context.hasPlugin?.(\"organization\") === true,\n });\n await store.assertOwner();\n return store;\n } catch (error) {\n routeError(\n \"UNAUTHORIZED_PAYMENT\",\n error instanceof Error ? error.message : \"Unauthorized payment.\",\n );\n }\n}\n\nasync function loadPayment(\n ctx: GenericEndpointContext,\n reference: string,\n organizationId?: string,\n) {\n const store = await paymentStore(ctx, organizationId);\n try {\n const payment = await store.findByReference(reference);\n if (!payment) routeError(\"UNAUTHORIZED_PAYMENT\", \"Payment was not found for this owner.\");\n return { store, payment };\n } catch (error) {\n if (error instanceof APIError) throw error;\n routeError(\n \"UNAUTHORIZED_PAYMENT\",\n error instanceof Error ? error.message : \"Unauthorized payment.\",\n );\n }\n}\n\nfunction asResponse(payment: SolanaPayment, paymentUrl?: string) {\n return {\n id: payment.id,\n reference: payment.reference,\n amount: payment.amount,\n mint: payment.mint,\n decimals: payment.decimals,\n recipient: payment.recipient,\n status: payment.status,\n expiresAt: payment.expiresAt,\n signature: payment.signature ?? undefined,\n slot: payment.slot ?? undefined,\n metadata: payment.metadata\n ? (JSON.parse(payment.metadata) as Record<string, unknown>)\n : undefined,\n ...(paymentUrl ? { paymentUrl } : {}),\n };\n}\n\nexport const createPayment = <P extends string = \"/create-payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/create-payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"POST\", body: createPaymentBody, use: [sessionMiddleware, originCheck] },\n async (ctx) => {\n const store = await paymentStore(ctx, ctx.body.organizationId);\n const reference = randomUUID();\n const request = options.client.payments.createRequest({\n amount: ctx.body.amount,\n recipient: options.recipient,\n reference,\n metadata: ctx.body.metadata,\n });\n const payment = await store.create({\n reference: request.reference,\n amount: request.amount.toString(),\n mint: request.mint,\n decimals: request.decimals,\n recipient: request.recipient ?? options.recipient,\n expiresAt: new Date(Date.now() + (options.paymentExpirationMs ?? 30 * 60 * 1000)),\n metadata: ctx.body.metadata ? JSON.stringify(ctx.body.metadata) : null,\n signature: null,\n slot: null,\n });\n const paymentUrl = options.client.payments.toSolanaPayUrl(request).toString();\n return ctx.json(asResponse(payment, paymentUrl));\n },\n );\n\nexport const verifyPayment = <P extends string = \"/verify-payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/verify-payment\" as P,\n callbacksInFlight = new Set<string>(),\n) =>\n createAuthEndpoint(\n path,\n { method: \"POST\", body: verifyPaymentBody, use: [sessionMiddleware, originCheck] },\n async (ctx) => {\n const { store, payment } = await loadPayment(\n ctx,\n ctx.body.reference,\n ctx.body.organizationId,\n );\n if (payment.status === \"paid\") return ctx.json(asResponse(payment));\n if (payment.status === \"expired\" || payment.expiresAt <= new Date()) {\n if (payment.status === \"pending\") await store.markExpired(payment.reference);\n routeError(\"PAYMENT_EXPIRED\", \"Payment intent has expired.\");\n }\n if (payment.status !== \"pending\") routeError(\"INVALID_PAYMENT\", \"Payment is not pending.\");\n const wasPending = payment.status === \"pending\";\n\n let verified;\n try {\n verified = await options.client.payments.verify({\n reference: payment.reference,\n recipient: payment.recipient,\n amount: formatTokenAmount(payment.amount, payment.decimals),\n });\n } catch (error) {\n routeError(\n \"PAYMENT_MISMATCH\",\n error instanceof Error ? error.message : \"Payment did not match intent.\",\n );\n }\n if (\n !verified.found ||\n verified.reference !== payment.reference ||\n verified.recipient !== payment.recipient ||\n verified.amount?.toString() !== payment.amount\n ) {\n routeError(\"PAYMENT_MISMATCH\", \"Payment did not exactly match the stored intent.\");\n }\n const { payment: paid, transitioned } = await store.markPaidWithTransition(\n payment.reference,\n {\n signature: verified.signature,\n slot: verified.slot?.toString(),\n },\n );\n if (!paid) routeError(\"INVALID_PAYMENT\", \"Payment state could not be updated.\");\n if (wasPending && transitioned && !callbacksInFlight.has(paid.reference)) {\n callbacksInFlight.add(paid.reference);\n try {\n await options.onPaymentComplete?.(paid, ctx);\n } finally {\n callbacksInFlight.delete(paid.reference);\n }\n }\n return ctx.json(asResponse(paid));\n },\n );\n\nexport const getPayment = <P extends string = \"/payment\">(\n options: SolanaPaymentsOptions,\n path: P = \"/payment\" as P,\n) =>\n createAuthEndpoint(\n path,\n { method: \"GET\", query: getPaymentQuery, use: [sessionMiddleware] },\n async (ctx) => {\n const { store, payment } = await loadPayment(\n ctx,\n ctx.query.reference,\n ctx.query.organizationId,\n );\n const current =\n payment.status === \"pending\" && payment.expiresAt <= new Date()\n ? await store.markExpired(payment.reference)\n : payment;\n return ctx.json(asResponse(current ?? payment));\n },\n );\n","import { mergeSchema, type BetterAuthPluginDBSchema, type DBFieldAttribute } from \"better-auth/db\";\n\nimport type { SolanaPaymentsOptions } from \"./types.ts\";\n\ntype SolanaPaymentSchema = Record<\n \"solanaPayment\",\n {\n fields: Record<\n | \"reference\"\n | \"referenceType\"\n | \"referenceId\"\n | \"amount\"\n | \"mint\"\n | \"decimals\"\n | \"recipient\"\n | \"status\"\n | \"expiresAt\"\n | \"signature\"\n | \"slot\"\n | \"metadata\"\n | \"createdAt\"\n | \"updatedAt\",\n DBFieldAttribute\n >;\n }\n>;\n\nconst solanaPaymentSchema: SolanaPaymentSchema = {\n solanaPayment: {\n fields: {\n reference: { type: \"string\", required: true, unique: true },\n referenceType: { type: \"string\", required: true },\n referenceId: { type: \"string\", required: true, index: true },\n amount: { type: \"string\", required: true },\n mint: { type: \"string\", required: true },\n decimals: { type: \"number\", required: true },\n recipient: { type: \"string\", required: true },\n status: { type: \"string\", required: true, defaultValue: \"pending\", index: true },\n expiresAt: { type: \"date\", required: true },\n signature: { type: \"string\", required: false, unique: true },\n slot: { type: \"string\", required: false },\n metadata: { type: \"string\", required: false },\n createdAt: { type: \"date\", required: true },\n updatedAt: { type: \"date\", required: true },\n },\n },\n} satisfies BetterAuthPluginDBSchema;\n\nexport type SolanaPaymentsPluginSchema = SolanaPaymentSchema;\nexport const solanaPaymentsPluginSchema: SolanaPaymentSchema = solanaPaymentSchema;\n\nexport function getSchema(\n options: Pick<SolanaPaymentsOptions, \"schema\">,\n): BetterAuthPluginDBSchema {\n return mergeSchema(solanaPaymentSchema, options.schema as Parameters<typeof mergeSchema>[1]);\n}\n","import { defineErrorCodes, type BetterAuthPlugin } from \"better-auth\";\n\nimport { createPayment, getPayment, verifyPayment } from \"./routes.ts\";\nimport { getSchema } from \"./schema.ts\";\nimport type { SolanaPaymentsOptions } from \"./types.ts\";\n\nexport { PACKAGE_VERSION } from \"./version.ts\";\nexport { getSchema, solanaPaymentsPluginSchema } from \"./schema.ts\";\nexport { createSolanaPaymentStore } from \"./store.ts\";\nexport type {\n CreateSolanaPaymentInput,\n MarkPaidInput,\n MarkPaidResult,\n SolanaPaymentStore,\n SolanaPaymentStoreContext,\n} from \"./store.ts\";\nexport type { SolanaPayment, SolanaPaymentsOptions, SolanaPaymentStatus } from \"./types.ts\";\n\nconst ERROR_CODES = defineErrorCodes({\n MISSING_SESSION: \"An authenticated session is required.\",\n UNAUTHORIZED_PAYMENT: \"Payment was not found for this owner.\",\n PAYMENT_EXPIRED: \"Payment intent has expired.\",\n INVALID_PAYMENT: \"Payment is invalid.\",\n PAYMENT_MISMATCH: \"Payment did not exactly match the stored intent.\",\n});\n\nexport function solanaPayments(input: SolanaPaymentsOptions) {\n const normalized = input.client.payments.createRequest({\n amount: \"0\",\n recipient: input.recipient,\n reference: \"solana-payments-recipient-normalization\",\n }).recipient;\n if (!normalized) throw new Error(\"A Solana payment recipient is required.\");\n const options = {\n ...input,\n recipient: normalized,\n paymentExpirationMs: input.paymentExpirationMs ?? 30 * 60 * 1000,\n } satisfies SolanaPaymentsOptions;\n const callbacksInFlight = new Set<string>();\n return {\n id: \"solanaPayments\",\n endpoints: {\n createPayment: createPayment(options, \"/solana-payments/create-payment\"),\n verifyPayment: verifyPayment(options, \"/solana-payments/verify-payment\", callbacksInFlight),\n getPayment: getPayment(options, \"/solana-payments/payment\"),\n },\n schema: getSchema(options),\n $ERROR_CODES: ERROR_CODES,\n } satisfies BetterAuthPlugin;\n}\n"],"mappings":";;;;;;;;AAEA,MAAM,uBAAuB;AAyC7B,SAAgB,yBAAyB,SAAwD;CAC/F,MAAM,WAAW,YAAoE;EACnF,MAAM,SAAS,QAAQ,SAAS,MAAM;EACtC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,sDAAsD;EAEnF,IAAI,CAAC,QAAQ,gBAAgB,OAAO;GAAE,MAAM;GAAQ,IAAI;EAAO;EAC/D,IAAI,CAAC,QAAQ,uBACX,MAAM,IAAI,MAAM,2EAA2E;EAU7F,IAAI,CAAC,MAPgB,QAAQ,QAAQ,QAAwB;GAC3D,OAAO;GACP,OAAO,CACL;IAAE,OAAO;IAAkB,OAAO,QAAQ;GAAe,GACzD;IAAE,OAAO;IAAU,OAAO;GAAO,CACnC;EACF,CAAC,GACY,MAAM,IAAI,MAAM,iDAAiD;EAC9E,OAAO;GAAE,MAAM;GAAgB,IAAI,QAAQ;EAAe;CAC5D;CAEA,MAAM,eAAe,OAAO,UAA6C;EACvE,MAAM,QAAQ,MAAM,SAAS;EAC7B,OAAO;GACL,GAAG;GACH;IAAE,OAAO;IAAiB,OAAO,MAAM;GAAK;GAC5C;IAAE,OAAO;IAAe,OAAO,MAAM;GAAG;EAC1C;CACF;CAEA,MAAM,kBAAkB,OAAO,cAC7B,QAAQ,QAAQ,QAAuB;EACrC,OAAO;EACP,OAAO,MAAM,aAAa,CAAC;GAAE,OAAO;GAAa,OAAO;EAAU,CAAC,CA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|
|
|
1
|
+
{"version":3,"file":"version-Ctrvqbjd.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const PACKAGE_VERSION = \"0.1.0\";\n"],"mappings":";AAAA,MAAa,kBAAkB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "better-auth-solana-payments",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "One-time Solana payment integration for Better Auth",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"better-auth",
|
|
7
|
+
"payments",
|
|
8
|
+
"solana",
|
|
9
|
+
"solana-pay"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/alexasomba/better-auth-solana-payments#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/alexasomba/better-auth-solana-payments/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "alexasomba",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/alexasomba/better-auth-solana-payments.git"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.mts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"default": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./client": {
|
|
34
|
+
"types": "./dist/client.d.mts",
|
|
35
|
+
"import": "./dist/client.mjs",
|
|
36
|
+
"default": "./dist/client.mjs"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "vp pack",
|
|
44
|
+
"dev": "vp pack --watch",
|
|
45
|
+
"test": "vp test run",
|
|
46
|
+
"lint": "vp lint src test",
|
|
47
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
48
|
+
"check": "vp check",
|
|
49
|
+
"lint:package": "publint run --strict",
|
|
50
|
+
"lint:types": "attw --profile esm-only --pack ."
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"better-call": "catalog:",
|
|
54
|
+
"defu": "catalog:",
|
|
55
|
+
"zod": "catalog:"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
59
|
+
"@better-fetch/fetch": "^1.3.1",
|
|
60
|
+
"@types/node": "catalog:",
|
|
61
|
+
"publint": "^0.3.24",
|
|
62
|
+
"typescript": "catalog:",
|
|
63
|
+
"vite-plus": "catalog:",
|
|
64
|
+
"vitest": "catalog:"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@better-fetch/fetch": "^1.3.1",
|
|
68
|
+
"better-auth": "catalog:",
|
|
69
|
+
"solana-payments": "catalog:"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=22.0.0"
|
|
73
|
+
},
|
|
74
|
+
"packageManager": "pnpm@11.8.0"
|
|
75
|
+
}
|