better-auth-solana-payments 0.1.2 → 0.2.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 +9 -1
- package/dist/client.d.mts +6 -7
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +1 -1
- package/dist/{index-CH-34bt8.d.mts → index-6unaaVQL.d.mts} +21 -13
- package/dist/index-6unaaVQL.d.mts.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +112 -23
- package/dist/index.mjs.map +1 -1
- package/dist/version-Cmtbh3PR.mjs +6 -0
- package/dist/version-Cmtbh3PR.mjs.map +1 -0
- package/migrations/0.2.0-sqlite.sql +9 -0
- package/package.json +11 -9
- package/dist/index-CH-34bt8.d.mts.map +0 -1
- package/dist/version-DgYRNhTs.mjs +0 -6
- package/dist/version-DgYRNhTs.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,9 @@ One-time Solana payment integration for [Better Auth](https://www.better-auth.co
|
|
|
8
8
|
pnpm add better-auth better-auth-solana-payments solana-payments
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Requires Node.js 22 or later.
|
|
11
|
+
Requires Node.js 22 or later and solana-payments 1.x.
|
|
12
|
+
|
|
13
|
+
Existing installations must add the fulfillment fields before upgrading. For the default SQLite table and column names, see `migrations/0.2.0-sqlite.sql`; custom schemas must generate the equivalent Better Auth migration. Back up the database, verify paid-row fulfillment state, then deploy.
|
|
12
14
|
|
|
13
15
|
## Server setup
|
|
14
16
|
|
|
@@ -111,3 +113,9 @@ smoke test (`pnpm test:devnet`) and the full wallet verification flow.
|
|
|
111
113
|
For devnet, configure a devnet SPL-token mint; the built-in `SOLANA_USDT` preset is the mainnet
|
|
112
114
|
USDT mint and must not be used for devnet testing. In production, use a persistent Better Auth
|
|
113
115
|
adapter, a generated `BETTER_AUTH_SECRET`, and a dedicated RPC provider.
|
|
116
|
+
|
|
117
|
+
### Fulfillment migration and retries
|
|
118
|
+
|
|
119
|
+
Generate/apply your Better Auth schema migration before upgrading. Add `fulfillmentStatus` (default `pending`), nullable `fulfillmentToken`, and nullable `fulfillmentClaimedAt` to `solanaPayment`. Backfill previously paid rows to `completed` before accepting requests, so historical payments are not fulfilled again.
|
|
120
|
+
|
|
121
|
+
Payment settlement and fulfillment are separate: verification persists `paid`, then claims a database lease before invoking `onPaymentComplete`. Failed callbacks return an error and leave fulfillment pending; retry verification to recover, including after a restart. A crashed worker's claim becomes recoverable after five minutes. Callbacks must be idempotent by payment reference, since a crash after an external side effect can cause a retry. Responses expose `fulfillmentStatus`; grant access only when it is `completed`.
|
package/dist/client.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as solanaPayments } from "./index-
|
|
1
|
+
import { t as solanaPayments } from "./index-6unaaVQL.mjs";
|
|
2
2
|
import { BetterFetch, BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
|
|
3
3
|
import { BetterAuthClientPlugin } from "better-auth/client";
|
|
4
4
|
//#region src/client.d.ts
|
|
5
|
-
type FetchResult<T, O extends BetterFetchOption | undefined> = O extends {
|
|
5
|
+
export type FetchResult<T, O extends BetterFetchOption | undefined> = O extends {
|
|
6
6
|
throw: true;
|
|
7
7
|
} ? T : BetterFetchResponse<T>;
|
|
8
|
-
interface SolanaPaymentResponse {
|
|
8
|
+
export interface SolanaPaymentResponse {
|
|
9
9
|
id: string;
|
|
10
10
|
reference: string;
|
|
11
11
|
amount: string;
|
|
@@ -19,7 +19,7 @@ interface SolanaPaymentResponse {
|
|
|
19
19
|
metadata?: Record<string, unknown>;
|
|
20
20
|
paymentUrl?: string;
|
|
21
21
|
}
|
|
22
|
-
interface SolanaPaymentActions {
|
|
22
|
+
export interface SolanaPaymentActions {
|
|
23
23
|
create: <O extends BetterFetchOption | undefined = undefined>(data: {
|
|
24
24
|
amount: string;
|
|
25
25
|
metadata?: Record<string, unknown>;
|
|
@@ -34,7 +34,7 @@ interface SolanaPaymentActions {
|
|
|
34
34
|
organizationId?: string;
|
|
35
35
|
}, options?: O) => Promise<FetchResult<SolanaPaymentResponse, O>>;
|
|
36
36
|
}
|
|
37
|
-
interface SolanaPaymentsClientActions {
|
|
37
|
+
export interface SolanaPaymentsClientActions {
|
|
38
38
|
payment: SolanaPaymentActions;
|
|
39
39
|
}
|
|
40
40
|
declare module "better-auth/client" {
|
|
@@ -52,7 +52,6 @@ type SolanaPaymentsClientPluginInstance = Omit<BetterAuthClientPlugin, "id" | "$
|
|
|
52
52
|
$InferServerPlugin: ReturnType<typeof solanaPayments>;
|
|
53
53
|
getActions: ($fetch: BetterFetch, $store: unknown, options: unknown) => SolanaPaymentsClientActions;
|
|
54
54
|
};
|
|
55
|
-
declare const solanaPaymentsClient: () => SolanaPaymentsClientPluginInstance;
|
|
55
|
+
export declare const solanaPaymentsClient: () => SolanaPaymentsClientPluginInstance;
|
|
56
56
|
//#endregion
|
|
57
|
-
export { FetchResult, SolanaPaymentActions, SolanaPaymentResponse, SolanaPaymentsClientActions, solanaPaymentsClient };
|
|
58
57
|
//# sourceMappingURL=client.d.mts.map
|
package/dist/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"mappings":";;;;YAMY,YAAY,GAAG,UAAU,iCAAiC;EAAY;IAC9E,IACA,oBAAoB;iBAEP;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,WAAW;EACX;;iBAGe;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;;iBAGjC;EACf,SAAS;;;YAIC;IACR,SAAS;;;;YAKD;IACR,gBAAgB,kBAAkB;;;KAIjC,qCAAqC,KACxC;EAGA;EACA,oBAAoB,kBAAkB;EACtC,aACE,QAAQ,aACR,iBACA,qBACG;;qBAGM,4BAA2B"}
|
package/dist/client.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { AddressInput, SolanaUsdtReadOnlyClient } from "solana-payments";
|
|
|
3
3
|
import { BetterAuthPluginDBSchema, DBFieldAttribute } from "better-auth/db";
|
|
4
4
|
//#region src/schema.d.ts
|
|
5
5
|
type SolanaPaymentSchema = Record<"solanaPayment", {
|
|
6
|
-
fields: Record<"reference" | "referenceType" | "referenceId" | "amount" | "mint" | "decimals" | "recipient" | "status" | "expiresAt" | "signature" | "slot" | "metadata" | "createdAt" | "updatedAt", DBFieldAttribute>;
|
|
6
|
+
fields: Record<"reference" | "referenceType" | "referenceId" | "amount" | "mint" | "decimals" | "recipient" | "status" | "fulfillmentStatus" | "fulfillmentToken" | "fulfillmentClaimedAt" | "expiresAt" | "signature" | "slot" | "metadata" | "createdAt" | "updatedAt", DBFieldAttribute>;
|
|
7
7
|
}>;
|
|
8
8
|
type SolanaPaymentsPluginSchema = SolanaPaymentSchema;
|
|
9
9
|
declare const solanaPaymentsPluginSchema: SolanaPaymentSchema;
|
|
@@ -22,6 +22,9 @@ interface SolanaPayment {
|
|
|
22
22
|
decimals: number;
|
|
23
23
|
recipient: string;
|
|
24
24
|
status: SolanaPaymentStatus;
|
|
25
|
+
fulfillmentStatus?: "pending" | "processing" | "completed";
|
|
26
|
+
fulfillmentToken?: string | null;
|
|
27
|
+
fulfillmentClaimedAt?: Date | null;
|
|
25
28
|
expiresAt: Date;
|
|
26
29
|
signature?: string | null;
|
|
27
30
|
/** Ledger slot, retained as a string to avoid JavaScript number rounding. */
|
|
@@ -42,7 +45,7 @@ interface SolanaPaymentsOptions {
|
|
|
42
45
|
}
|
|
43
46
|
//#endregion
|
|
44
47
|
//#region src/version.d.ts
|
|
45
|
-
declare const PACKAGE_VERSION = "0.
|
|
48
|
+
declare const PACKAGE_VERSION = "0.2.0";
|
|
46
49
|
//#endregion
|
|
47
50
|
//#region src/store.d.ts
|
|
48
51
|
type Adapter = {
|
|
@@ -62,7 +65,7 @@ type Adapter = {
|
|
|
62
65
|
};
|
|
63
66
|
type WhereClause = {
|
|
64
67
|
field: string;
|
|
65
|
-
value: string;
|
|
68
|
+
value: string | null;
|
|
66
69
|
}[];
|
|
67
70
|
interface SolanaPaymentStoreContext {
|
|
68
71
|
adapter: Adapter;
|
|
@@ -90,6 +93,8 @@ interface SolanaPaymentStore {
|
|
|
90
93
|
findByReference(reference: string): Promise<SolanaPayment | null>;
|
|
91
94
|
markPaid(reference: string, input?: MarkPaidInput): Promise<SolanaPayment | null>;
|
|
92
95
|
markPaidWithTransition(reference: string, input?: MarkPaidInput): Promise<MarkPaidResult>;
|
|
96
|
+
claimFulfillment(reference: string): Promise<SolanaPayment | null>;
|
|
97
|
+
finishFulfillment(reference: string, token: string, completed: boolean): Promise<SolanaPayment | null>;
|
|
93
98
|
markExpired(reference: string): Promise<SolanaPayment | null>;
|
|
94
99
|
}
|
|
95
100
|
declare function createSolanaPaymentStore(context: SolanaPaymentStoreContext): SolanaPaymentStore;
|
|
@@ -98,14 +103,14 @@ declare function createSolanaPaymentStore(context: SolanaPaymentStoreContext): S
|
|
|
98
103
|
declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
99
104
|
id: "solanaPayments";
|
|
100
105
|
endpoints: {
|
|
101
|
-
createPayment: import("better-
|
|
106
|
+
createPayment: import("better-auth").StrictEndpoint<"/solana-payments/create-payment", {
|
|
102
107
|
method: "POST";
|
|
103
108
|
body: import("zod").ZodObject<{
|
|
104
109
|
amount: import("zod").ZodString;
|
|
105
110
|
metadata: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>;
|
|
106
111
|
organizationId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
107
112
|
}, import("zod/v4/core").$strip>;
|
|
108
|
-
use: (((inputContext: import("better-
|
|
113
|
+
use: (import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
109
114
|
session: {
|
|
110
115
|
session: Record<string, any> & {
|
|
111
116
|
id: string;
|
|
@@ -127,7 +132,7 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
127
132
|
image?: string | null | undefined;
|
|
128
133
|
};
|
|
129
134
|
};
|
|
130
|
-
}
|
|
135
|
+
}>> | import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>)[];
|
|
131
136
|
}, {
|
|
132
137
|
paymentUrl?: string | undefined;
|
|
133
138
|
id: string;
|
|
@@ -137,18 +142,19 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
137
142
|
decimals: number;
|
|
138
143
|
recipient: string;
|
|
139
144
|
status: SolanaPaymentStatus;
|
|
145
|
+
fulfillmentStatus: "pending" | "processing" | "completed";
|
|
140
146
|
expiresAt: Date;
|
|
141
147
|
signature: string | undefined;
|
|
142
148
|
slot: string | undefined;
|
|
143
149
|
metadata: Record<string, unknown> | undefined;
|
|
144
150
|
}>;
|
|
145
|
-
verifyPayment: import("better-
|
|
151
|
+
verifyPayment: import("better-auth").StrictEndpoint<"/solana-payments/verify-payment", {
|
|
146
152
|
method: "POST";
|
|
147
153
|
body: import("zod").ZodObject<{
|
|
148
154
|
reference: import("zod").ZodString;
|
|
149
155
|
organizationId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
150
156
|
}, import("zod/v4/core").$strip>;
|
|
151
|
-
use: (((inputContext: import("better-
|
|
157
|
+
use: (import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
152
158
|
session: {
|
|
153
159
|
session: Record<string, any> & {
|
|
154
160
|
id: string;
|
|
@@ -170,7 +176,7 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
170
176
|
image?: string | null | undefined;
|
|
171
177
|
};
|
|
172
178
|
};
|
|
173
|
-
}
|
|
179
|
+
}>> | import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>)[];
|
|
174
180
|
}, {
|
|
175
181
|
paymentUrl?: string | undefined;
|
|
176
182
|
id: string;
|
|
@@ -180,18 +186,19 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
180
186
|
decimals: number;
|
|
181
187
|
recipient: string;
|
|
182
188
|
status: SolanaPaymentStatus;
|
|
189
|
+
fulfillmentStatus: "pending" | "processing" | "completed";
|
|
183
190
|
expiresAt: Date;
|
|
184
191
|
signature: string | undefined;
|
|
185
192
|
slot: string | undefined;
|
|
186
193
|
metadata: Record<string, unknown> | undefined;
|
|
187
194
|
}>;
|
|
188
|
-
getPayment: import("better-
|
|
195
|
+
getPayment: import("better-auth").StrictEndpoint<"/solana-payments/payment", {
|
|
189
196
|
method: "GET";
|
|
190
197
|
query: import("zod").ZodObject<{
|
|
191
198
|
reference: import("zod").ZodString;
|
|
192
199
|
organizationId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
193
200
|
}, import("zod/v4/core").$strip>;
|
|
194
|
-
use: ((inputContext: import("better-
|
|
201
|
+
use: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
|
|
195
202
|
session: {
|
|
196
203
|
session: Record<string, any> & {
|
|
197
204
|
id: string;
|
|
@@ -213,7 +220,7 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
213
220
|
image?: string | null | undefined;
|
|
214
221
|
};
|
|
215
222
|
};
|
|
216
|
-
}
|
|
223
|
+
}>>[];
|
|
217
224
|
}, {
|
|
218
225
|
paymentUrl?: string | undefined;
|
|
219
226
|
id: string;
|
|
@@ -223,6 +230,7 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
223
230
|
decimals: number;
|
|
224
231
|
recipient: string;
|
|
225
232
|
status: SolanaPaymentStatus;
|
|
233
|
+
fulfillmentStatus: "pending" | "processing" | "completed";
|
|
226
234
|
expiresAt: Date;
|
|
227
235
|
signature: string | undefined;
|
|
228
236
|
slot: string | undefined;
|
|
@@ -240,4 +248,4 @@ declare function solanaPayments(input: SolanaPaymentsOptions): {
|
|
|
240
248
|
};
|
|
241
249
|
//#endregion
|
|
242
250
|
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-
|
|
251
|
+
//# sourceMappingURL=index-6unaaVQL.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-6unaaVQL.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,kQAkBN;;KA6BM,6BAA6B;cAC5B,4BAA4B;iBAEzB,UACd,SAAS,KAAK,mCACb;;;KCxDS;UACK;EACb;EACA;EACA;EACA;;EAEA;EACA;EACA;EACA;EACA,QAAQ;EACR;EACA;EACA,uBAAuB;EACvB,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;;;;cClClB;;;KCMR;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,iBAAiB,oBAAoB,QAAQ;EAC7C,kBACE,mBACA,eACA,qBACC,QAAQ;EACX,YAAY,oBAAoB,QAAQ;;iBAG1B,yBAAyB,SAAS,4BAA4B;;;iBCzB9D,eAAe,OAAO;;;;;;;;;;;;;;;;;;;YAuBi4D;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAAtQ;YAA6C;;;;;;;;;YAAyN"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +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-
|
|
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-6unaaVQL.mjs";
|
|
2
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as PACKAGE_VERSION } from "./version-
|
|
1
|
+
import { t as PACKAGE_VERSION } from "./version-Cmtbh3PR.mjs";
|
|
2
2
|
import { defineErrorCodes } from "better-auth";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
import { APIError, createAuthEndpoint, getSessionFromCtx,
|
|
3
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
4
|
+
import { APIError, createAuthEndpoint, getSessionFromCtx, originCheckMiddleware, sessionMiddleware } from "better-auth/api";
|
|
5
5
|
import { formatTokenAmount } from "solana-payments";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { mergeSchema } from "better-auth/db";
|
|
@@ -105,6 +105,9 @@ function createSolanaPaymentStore(context) {
|
|
|
105
105
|
referenceType: owner.type,
|
|
106
106
|
referenceId: owner.id,
|
|
107
107
|
status: "pending",
|
|
108
|
+
fulfillmentStatus: "pending",
|
|
109
|
+
fulfillmentToken: null,
|
|
110
|
+
fulfillmentClaimedAt: null,
|
|
108
111
|
createdAt: now,
|
|
109
112
|
updatedAt: now
|
|
110
113
|
}
|
|
@@ -122,6 +125,59 @@ function createSolanaPaymentStore(context) {
|
|
|
122
125
|
return (await markPaidWithTransition(reference, input)).payment;
|
|
123
126
|
},
|
|
124
127
|
markPaidWithTransition,
|
|
128
|
+
async claimFulfillment(reference) {
|
|
129
|
+
const payment = await findByReference(reference);
|
|
130
|
+
if (!payment || payment.status !== "paid" || !payment.fulfillmentStatus || payment.fulfillmentStatus === "completed") return null;
|
|
131
|
+
if (payment.fulfillmentStatus === "processing" && payment.fulfillmentClaimedAt && new Date(payment.fulfillmentClaimedAt).getTime() > Date.now() - 3e5) return null;
|
|
132
|
+
return context.adapter.update({
|
|
133
|
+
model: SOLANA_PAYMENT_MODEL,
|
|
134
|
+
where: await paymentWhere([
|
|
135
|
+
{
|
|
136
|
+
field: "id",
|
|
137
|
+
value: payment.id
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
field: "fulfillmentStatus",
|
|
141
|
+
value: payment.fulfillmentStatus
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
field: "fulfillmentToken",
|
|
145
|
+
value: payment.fulfillmentToken ?? null
|
|
146
|
+
}
|
|
147
|
+
]),
|
|
148
|
+
update: {
|
|
149
|
+
fulfillmentStatus: "processing",
|
|
150
|
+
fulfillmentToken: randomUUID(),
|
|
151
|
+
fulfillmentClaimedAt: /* @__PURE__ */ new Date(),
|
|
152
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
async finishFulfillment(reference, token, completed) {
|
|
157
|
+
return context.adapter.update({
|
|
158
|
+
model: SOLANA_PAYMENT_MODEL,
|
|
159
|
+
where: await paymentWhere([
|
|
160
|
+
{
|
|
161
|
+
field: "reference",
|
|
162
|
+
value: reference
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
field: "fulfillmentToken",
|
|
166
|
+
value: token
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
field: "fulfillmentStatus",
|
|
170
|
+
value: "processing"
|
|
171
|
+
}
|
|
172
|
+
]),
|
|
173
|
+
update: {
|
|
174
|
+
fulfillmentStatus: completed ? "completed" : "pending",
|
|
175
|
+
fulfillmentToken: null,
|
|
176
|
+
fulfillmentClaimedAt: null,
|
|
177
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
},
|
|
125
181
|
async markExpired(reference) {
|
|
126
182
|
const payment = await findByReference(reference);
|
|
127
183
|
if (!payment || payment.status !== "pending") return payment?.status === "expired" ? payment : null;
|
|
@@ -202,6 +258,7 @@ function asResponse(payment, paymentUrl) {
|
|
|
202
258
|
decimals: payment.decimals,
|
|
203
259
|
recipient: payment.recipient,
|
|
204
260
|
status: payment.status,
|
|
261
|
+
fulfillmentStatus: payment.fulfillmentStatus ?? (payment.status === "paid" ? "completed" : "pending"),
|
|
205
262
|
expiresAt: payment.expiresAt,
|
|
206
263
|
signature: payment.signature ?? void 0,
|
|
207
264
|
slot: payment.slot ?? void 0,
|
|
@@ -209,13 +266,42 @@ function asResponse(payment, paymentUrl) {
|
|
|
209
266
|
...paymentUrl ? { paymentUrl } : {}
|
|
210
267
|
};
|
|
211
268
|
}
|
|
269
|
+
function createReference() {
|
|
270
|
+
const bytes = randomBytes(32);
|
|
271
|
+
const alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
272
|
+
let number = BigInt(`0x${bytes.toString("hex")}`);
|
|
273
|
+
let encoded = "";
|
|
274
|
+
while (number > 0n) {
|
|
275
|
+
encoded = alphabet[Number(number % 58n)] + encoded;
|
|
276
|
+
number /= 58n;
|
|
277
|
+
}
|
|
278
|
+
for (const byte of bytes) {
|
|
279
|
+
if (byte !== 0) break;
|
|
280
|
+
encoded = "1" + encoded;
|
|
281
|
+
}
|
|
282
|
+
return encoded;
|
|
283
|
+
}
|
|
284
|
+
async function fulfillPayment(ctx, options, store, payment) {
|
|
285
|
+
const claimed = await store.claimFulfillment(payment.reference);
|
|
286
|
+
if (!claimed) return await store.findByReference(payment.reference) ?? payment;
|
|
287
|
+
const token = claimed.fulfillmentToken;
|
|
288
|
+
try {
|
|
289
|
+
await options.onPaymentComplete?.(claimed, ctx);
|
|
290
|
+
const completed = await store.finishFulfillment(claimed.reference, token, true);
|
|
291
|
+
if (!completed) throw new Error("Fulfillment lease was lost; retry verification.");
|
|
292
|
+
return completed;
|
|
293
|
+
} catch (error) {
|
|
294
|
+
await store.finishFulfillment(claimed.reference, token, false);
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
212
298
|
const createPayment = (options, path = "/create-payment") => createAuthEndpoint(path, {
|
|
213
299
|
method: "POST",
|
|
214
300
|
body: createPaymentBody,
|
|
215
|
-
use: [sessionMiddleware,
|
|
301
|
+
use: [sessionMiddleware, originCheckMiddleware]
|
|
216
302
|
}, async (ctx) => {
|
|
217
303
|
const store = await paymentStore(ctx, ctx.body.organizationId);
|
|
218
|
-
const reference =
|
|
304
|
+
const reference = createReference();
|
|
219
305
|
const request = options.client.payments.createRequest({
|
|
220
306
|
amount: ctx.body.amount,
|
|
221
307
|
recipient: options.recipient,
|
|
@@ -228,7 +314,7 @@ const createPayment = (options, path = "/create-payment") => createAuthEndpoint(
|
|
|
228
314
|
mint: request.mint,
|
|
229
315
|
decimals: request.decimals,
|
|
230
316
|
recipient: request.recipient ?? options.recipient,
|
|
231
|
-
expiresAt: new Date(Date.now() + (options.paymentExpirationMs ??
|
|
317
|
+
expiresAt: new Date(Date.now() + (options.paymentExpirationMs ?? 18e5)),
|
|
232
318
|
metadata: ctx.body.metadata ? JSON.stringify(ctx.body.metadata) : null,
|
|
233
319
|
signature: null,
|
|
234
320
|
slot: null
|
|
@@ -236,19 +322,18 @@ const createPayment = (options, path = "/create-payment") => createAuthEndpoint(
|
|
|
236
322
|
const paymentUrl = options.client.payments.toSolanaPayUrl(request).toString();
|
|
237
323
|
return ctx.json(asResponse(payment, paymentUrl));
|
|
238
324
|
});
|
|
239
|
-
const verifyPayment = (options, path = "/verify-payment"
|
|
325
|
+
const verifyPayment = (options, path = "/verify-payment") => createAuthEndpoint(path, {
|
|
240
326
|
method: "POST",
|
|
241
327
|
body: verifyPaymentBody,
|
|
242
|
-
use: [sessionMiddleware,
|
|
328
|
+
use: [sessionMiddleware, originCheckMiddleware]
|
|
243
329
|
}, async (ctx) => {
|
|
244
330
|
const { store, payment } = await loadPayment(ctx, ctx.body.reference, ctx.body.organizationId);
|
|
245
|
-
if (payment.status === "paid") return ctx.json(asResponse(payment));
|
|
331
|
+
if (payment.status === "paid") return ctx.json(asResponse(await fulfillPayment(ctx, options, store, payment)));
|
|
246
332
|
if (payment.status === "expired" || payment.expiresAt <= /* @__PURE__ */ new Date()) {
|
|
247
333
|
if (payment.status === "pending") await store.markExpired(payment.reference);
|
|
248
334
|
routeError("PAYMENT_EXPIRED", "Payment intent has expired.");
|
|
249
335
|
}
|
|
250
336
|
if (payment.status !== "pending") routeError("INVALID_PAYMENT", "Payment is not pending.");
|
|
251
|
-
const wasPending = payment.status === "pending";
|
|
252
337
|
let verified;
|
|
253
338
|
try {
|
|
254
339
|
verified = await options.client.payments.verify({
|
|
@@ -260,20 +345,12 @@ const verifyPayment = (options, path = "/verify-payment", callbacksInFlight = /*
|
|
|
260
345
|
routeError("PAYMENT_MISMATCH", error instanceof Error ? error.message : "Payment did not match intent.");
|
|
261
346
|
}
|
|
262
347
|
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
|
|
348
|
+
const { payment: paid } = await store.markPaidWithTransition(payment.reference, {
|
|
264
349
|
signature: verified.signature,
|
|
265
350
|
slot: verified.slot?.toString()
|
|
266
351
|
});
|
|
267
352
|
if (!paid) routeError("INVALID_PAYMENT", "Payment state could not be updated.");
|
|
268
|
-
|
|
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));
|
|
353
|
+
return ctx.json(asResponse(await fulfillPayment(ctx, options, store, paid)));
|
|
277
354
|
});
|
|
278
355
|
const getPayment = (options, path = "/payment") => createAuthEndpoint(path, {
|
|
279
356
|
method: "GET",
|
|
@@ -323,6 +400,19 @@ const solanaPaymentSchema = { solanaPayment: { fields: {
|
|
|
323
400
|
defaultValue: "pending",
|
|
324
401
|
index: true
|
|
325
402
|
},
|
|
403
|
+
fulfillmentStatus: {
|
|
404
|
+
type: "string",
|
|
405
|
+
required: true,
|
|
406
|
+
defaultValue: "pending"
|
|
407
|
+
},
|
|
408
|
+
fulfillmentToken: {
|
|
409
|
+
type: "string",
|
|
410
|
+
required: false
|
|
411
|
+
},
|
|
412
|
+
fulfillmentClaimedAt: {
|
|
413
|
+
type: "date",
|
|
414
|
+
required: false
|
|
415
|
+
},
|
|
326
416
|
expiresAt: {
|
|
327
417
|
type: "date",
|
|
328
418
|
required: true
|
|
@@ -372,14 +462,13 @@ function solanaPayments(input) {
|
|
|
372
462
|
const options = {
|
|
373
463
|
...input,
|
|
374
464
|
recipient: normalized,
|
|
375
|
-
paymentExpirationMs: input.paymentExpirationMs ??
|
|
465
|
+
paymentExpirationMs: input.paymentExpirationMs ?? 18e5
|
|
376
466
|
};
|
|
377
|
-
const callbacksInFlight = /* @__PURE__ */ new Set();
|
|
378
467
|
return {
|
|
379
468
|
id: "solanaPayments",
|
|
380
469
|
endpoints: {
|
|
381
470
|
createPayment: createPayment(options, "/solana-payments/create-payment"),
|
|
382
|
-
verifyPayment: verifyPayment(options, "/solana-payments/verify-payment"
|
|
471
|
+
verifyPayment: verifyPayment(options, "/solana-payments/verify-payment"),
|
|
383
472
|
getPayment: getPayment(options, "/solana-payments/payment")
|
|
384
473
|
},
|
|
385
474
|
schema: getSchema(options),
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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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BAAsB;CACtB,iBAAiB;CACjB,iBAAiB;CACjB,kBAAkB;AACpB,CAAC;AAED,SAAgB,eAAe,OAA8B;CAC3D,MAAM,aAAa,MAAM,OAAO,SAAS,cAAc;EACrD,QAAQ;EACR,WAAW,MAAM;EACjB,WAAW;CACb,CAAC,CAAC,CAAC;CACH,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,yCAAyC;CAC1E,MAAM,UAAU;EACd,GAAG;EACH,WAAW;EACX,qBAAqB,MAAM,uBAAuB,OAAU;CAC9D;CACA,MAAM,oCAAoB,IAAI,IAAY;CAC1C,OAAO;EACL,IAAI;EACJ,WAAW;GACT,eAAe,cAAc,SAAS,iCAAiC;GACvE,eAAe,cAAc,SAAS,mCAAmC,iBAAiB;GAC1F,YAAY,WAAW,SAAS,0BAA0B;EAC5D;EACA,QAAQ,UAAU,OAAO;EACzB,cAAc;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/store.ts","../src/routes.ts","../src/schema.ts","../src/index.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\n\nimport 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 | null }[];\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 claimFulfillment(reference: string): Promise<SolanaPayment | null>;\n finishFulfillment(\n reference: string,\n token: string,\n completed: boolean,\n ): Promise<SolanaPayment | null>;\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 fulfillmentStatus: \"pending\",\n fulfillmentToken: null,\n fulfillmentClaimedAt: null,\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 claimFulfillment(reference) {\n const payment = await findByReference(reference);\n if (\n !payment ||\n payment.status !== \"paid\" ||\n !payment.fulfillmentStatus ||\n payment.fulfillmentStatus === \"completed\"\n )\n return null;\n if (\n payment.fulfillmentStatus === \"processing\" &&\n payment.fulfillmentClaimedAt &&\n new Date(payment.fulfillmentClaimedAt).getTime() > Date.now() - 5 * 60_000\n )\n return null;\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([\n { field: \"id\", value: payment.id },\n { field: \"fulfillmentStatus\", value: payment.fulfillmentStatus },\n { field: \"fulfillmentToken\", value: payment.fulfillmentToken ?? null },\n ]),\n update: {\n fulfillmentStatus: \"processing\",\n fulfillmentToken: randomUUID(),\n fulfillmentClaimedAt: new Date(),\n updatedAt: new Date(),\n },\n });\n },\n async finishFulfillment(reference, token, completed) {\n return context.adapter.update<SolanaPayment>({\n model: SOLANA_PAYMENT_MODEL,\n where: await paymentWhere([\n { field: \"reference\", value: reference },\n { field: \"fulfillmentToken\", value: token },\n { field: \"fulfillmentStatus\", value: \"processing\" },\n ]),\n update: {\n fulfillmentStatus: completed ? \"completed\" : \"pending\",\n fulfillmentToken: null,\n fulfillmentClaimedAt: null,\n updatedAt: new Date(),\n },\n });\n },\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 { randomBytes } from \"node:crypto\";\n\nimport {\n APIError,\n createAuthEndpoint,\n getSessionFromCtx,\n originCheckMiddleware,\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 fulfillmentStatus:\n payment.fulfillmentStatus ?? (payment.status === \"paid\" ? \"completed\" : \"pending\"),\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\n// Solana Pay references are public keys (base58-encoded 32-byte values).\nfunction createReference() {\n const bytes = randomBytes(32);\n const alphabet = \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\n let number = BigInt(`0x${bytes.toString(\"hex\")}`);\n let encoded = \"\";\n while (number > 0n) {\n encoded = alphabet[Number(number % 58n)] + encoded;\n number /= 58n;\n }\n for (const byte of bytes) {\n if (byte !== 0) break;\n encoded = \"1\" + encoded;\n }\n return encoded;\n}\n\nasync function fulfillPayment(\n ctx: GenericEndpointContext,\n options: SolanaPaymentsOptions,\n store: Awaited<ReturnType<typeof paymentStore>>,\n payment: SolanaPayment,\n) {\n const claimed = await store.claimFulfillment(payment.reference);\n if (!claimed) return (await store.findByReference(payment.reference)) ?? payment;\n const token = claimed.fulfillmentToken!;\n try {\n await options.onPaymentComplete?.(claimed, ctx);\n const completed = await store.finishFulfillment(claimed.reference, token, true);\n if (!completed) throw new Error(\"Fulfillment lease was lost; retry verification.\");\n return completed;\n } catch (error) {\n await store.finishFulfillment(claimed.reference, token, false);\n throw error;\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, originCheckMiddleware] },\n async (ctx) => {\n const store = await paymentStore(ctx, ctx.body.organizationId);\n const reference = createReference();\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) =>\n createAuthEndpoint(\n path,\n { method: \"POST\", body: verifyPaymentBody, use: [sessionMiddleware, originCheckMiddleware] },\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\")\n return ctx.json(asResponse(await fulfillPayment(ctx, options, store, 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\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 } = await store.markPaidWithTransition(payment.reference, {\n signature: verified.signature,\n slot: verified.slot?.toString(),\n });\n if (!paid) routeError(\"INVALID_PAYMENT\", \"Payment state could not be updated.\");\n return ctx.json(asResponse(await fulfillPayment(ctx, options, store, 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 | \"fulfillmentStatus\"\n | \"fulfillmentToken\"\n | \"fulfillmentClaimedAt\"\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 fulfillmentStatus: { type: \"string\", required: true, defaultValue: \"pending\" },\n fulfillmentToken: { type: \"string\", required: false },\n fulfillmentClaimedAt: { type: \"date\", required: false },\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 return {\n id: \"solanaPayments\",\n endpoints: {\n createPayment: createPayment(options, \"/solana-payments/create-payment\"),\n verifyPayment: verifyPayment(options, \"/solana-payments/verify-payment\"),\n getPayment: getPayment(options, \"/solana-payments/payment\"),\n },\n schema: getSchema(options),\n $ERROR_CODES: ERROR_CODES,\n } satisfies BetterAuthPlugin;\n}\n"],"mappings":";;;;;;;;AAIA,MAAM,uBAAuB;AA+C7B,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;IAAk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ACpD,sBAAsB;EAAE,MAAM;EAAQ,UAAU;CAAM;CACtD,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAK;CAC1C,WAAW;EAAE,MAAM;EAAU,UAAU;EAAO,QAAQ;CAAK;CAC3D,MAAM;EAAE,MAAM;EAAU,UAAU;CAAM;CACxC,UAAU;EAAE,MAAM;EAAU,UAAU;CAAM;CAC5C,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAK;CAC1C,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAK;AAC5C,EACF,EACF;AAGA,MAAa,6BAAkD;AAE/D,SAAgB,UACd,SAC0B;CAC1B,OAAO,YAAY,qBAAqB,QAAQ,MAA2C;AAC7F;;;AC3CA,MAAM,cAAc,iBAAiB;CACnC,iBAAiB;CACjB,sBAAsB;CACtB,iBAAiB;CACjB,iBAAiB;CACjB,kBAAkB;AACpB,CAAC;AAED,SAAgB,eAAe,OAA8B;CAC3D,MAAM,aAAa,MAAM,OAAO,SAAS,cAAc;EACrD,QAAQ;EACR,WAAW,MAAM;EACjB,WAAW;CACb,CAAC,CAAC,CAAC;CACH,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,yCAAyC;CAC1E,MAAM,UAAU;EACd,GAAG;EACH,WAAW;EACX,qBAAqB,MAAM,uBAAuB;CACpD;CACA,OAAO;EACL,IAAI;EACJ,WAAW;GACT,eAAe,cAAc,SAAS,iCAAiC;GACvE,eAAe,cAAc,SAAS,iCAAiC;GACvE,YAAY,WAAW,SAAS,0BAA0B;EAC5D;EACA,QAAQ,UAAU,OAAO;EACzB,cAAc;CAChB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-Cmtbh3PR.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["export const PACKAGE_VERSION = \"0.2.0\"; // x-release-please-version\n"],"mappings":";AAAA,MAAa,kBAAkB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Run once before upgrading, for the default Better Auth SQLite names only.
|
|
2
|
+
-- Back up first. Use schema generation for other adapters or custom names.
|
|
3
|
+
BEGIN;
|
|
4
|
+
ALTER TABLE "solanaPayment" ADD COLUMN "fulfillmentStatus" TEXT NOT NULL DEFAULT 'pending';
|
|
5
|
+
ALTER TABLE "solanaPayment" ADD COLUMN "fulfillmentToken" TEXT;
|
|
6
|
+
ALTER TABLE "solanaPayment" ADD COLUMN "fulfillmentClaimedAt" INTEGER;
|
|
7
|
+
-- Legacy paid rows already completed their old fulfillment path.
|
|
8
|
+
UPDATE "solanaPayment" SET "fulfillmentStatus" = 'completed' WHERE "status" = 'paid';
|
|
9
|
+
COMMIT;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-auth-solana-payments",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "One-time Solana payment integration for Better Auth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"better-auth",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"url": "git+https://github.com/alexasomba/better-auth-solana-payments.git"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"dist"
|
|
22
|
+
"dist",
|
|
23
|
+
"migrations"
|
|
23
24
|
],
|
|
24
25
|
"type": "module",
|
|
25
26
|
"sideEffects": false,
|
|
@@ -40,23 +41,24 @@
|
|
|
40
41
|
"access": "public"
|
|
41
42
|
},
|
|
42
43
|
"dependencies": {
|
|
43
|
-
"better-call": "1.3.
|
|
44
|
+
"better-call": "1.3.8",
|
|
44
45
|
"defu": "^6.1.7",
|
|
45
|
-
"zod": "^4.
|
|
46
|
+
"zod": "^4.6.2"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
49
|
-
"@better-fetch/fetch": "
|
|
50
|
-
"@types/node": "^24.13.
|
|
50
|
+
"@better-fetch/fetch": "1.3.1",
|
|
51
|
+
"@types/node": "^24.13.4",
|
|
52
|
+
"better-auth": "1.6.31",
|
|
51
53
|
"publint": "^0.3.24",
|
|
52
54
|
"typescript": "^6.0.3",
|
|
53
|
-
"vite
|
|
54
|
-
"
|
|
55
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.1",
|
|
56
|
+
"vite-plus": "0.3.1"
|
|
55
57
|
},
|
|
56
58
|
"peerDependencies": {
|
|
57
59
|
"@better-fetch/fetch": "^1.3.1",
|
|
58
60
|
"better-auth": "^1.6.25",
|
|
59
|
-
"solana-payments": "^0.
|
|
61
|
+
"solana-payments": "^1.0.0"
|
|
60
62
|
},
|
|
61
63
|
"engines": {
|
|
62
64
|
"node": ">=22.0.0"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-CH-34bt8.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;;U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