@t402/next 2.0.0 → 2.3.1
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 +7 -7
- package/package.json +23 -23
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ import { paymentProxy, t402ResourceServer } from "@t402/next";
|
|
|
19
19
|
import { HTTPFacilitatorClient } from "@t402/core/server";
|
|
20
20
|
import { ExactEvmScheme } from "@t402/evm/exact/server";
|
|
21
21
|
|
|
22
|
-
const facilitatorClient = new HTTPFacilitatorClient({ url: "https://facilitator.t402.
|
|
22
|
+
const facilitatorClient = new HTTPFacilitatorClient({ url: "https://facilitator.t402.io" });
|
|
23
23
|
const resourceServer = new t402ResourceServer(facilitatorClient)
|
|
24
24
|
.register("eip155:84532", new ExactEvmScheme());
|
|
25
25
|
|
|
@@ -46,18 +46,18 @@ export const config = {
|
|
|
46
46
|
|
|
47
47
|
### Protecting API Routes
|
|
48
48
|
|
|
49
|
-
API routes are protected using the `
|
|
49
|
+
API routes are protected using the `withT402` route wrapper. This is the recommended approach to protect API routes as it guarantees payment settlement only AFTER successful API responses (status < 400). API routes can also be protected by `paymentProxy`, however this will charge clients for failed API responses:
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
52
|
// app/api/your-endpoint/route.ts
|
|
53
53
|
import { NextRequest, NextResponse } from "next/server";
|
|
54
|
-
import {
|
|
54
|
+
import { withT402 } from "@t402/next";
|
|
55
55
|
|
|
56
56
|
const handler = async (_: NextRequest) => {
|
|
57
57
|
return NextResponse.json({ data: "your response" });
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
export const GET =
|
|
60
|
+
export const GET = withT402(
|
|
61
61
|
handler,
|
|
62
62
|
{
|
|
63
63
|
accepts: {
|
|
@@ -96,12 +96,12 @@ paymentProxy(
|
|
|
96
96
|
4. **`paywall`** (optional): Custom paywall provider
|
|
97
97
|
5. **`syncFacilitatorOnStart`** (optional): Whether to sync with facilitator on startup (defaults to true)
|
|
98
98
|
|
|
99
|
-
###
|
|
99
|
+
### withT402
|
|
100
100
|
|
|
101
|
-
The `
|
|
101
|
+
The `withT402` function wraps API route handlers. This is the recommended approach to protect API routes as it guarantees payment settlement only AFTER successful API responses (status < 400).
|
|
102
102
|
|
|
103
103
|
```typescript
|
|
104
|
-
|
|
104
|
+
withT402(
|
|
105
105
|
routeHandler: (request: NextRequest) => Promise<NextResponse>,
|
|
106
106
|
routeConfig: RouteConfig,
|
|
107
107
|
server: t402ResourceServer,
|
package/package.json
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t402/next",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"start": "tsx --env-file=.env index.ts",
|
|
9
|
-
"test": "vitest run",
|
|
10
|
-
"test:watch": "vitest",
|
|
11
|
-
"build": "tsup",
|
|
12
|
-
"watch": "tsc --watch",
|
|
13
|
-
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
|
|
14
|
-
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
|
|
15
|
-
"lint": "eslint . --ext .ts --fix",
|
|
16
|
-
"lint:check": "eslint . --ext .ts"
|
|
17
|
-
},
|
|
18
7
|
"keywords": [],
|
|
19
8
|
"license": "Apache-2.0",
|
|
20
9
|
"author": "T402 Team",
|
|
@@ -29,23 +18,23 @@
|
|
|
29
18
|
"eslint-plugin-import": "^2.31.0",
|
|
30
19
|
"eslint-plugin-jsdoc": "^50.6.9",
|
|
31
20
|
"eslint-plugin-prettier": "^5.2.6",
|
|
21
|
+
"glob": "^13.0.0",
|
|
32
22
|
"prettier": "3.5.2",
|
|
33
23
|
"tsup": "^8.4.0",
|
|
34
|
-
"tsx": "^4.
|
|
24
|
+
"tsx": "^4.21.0",
|
|
35
25
|
"typescript": "^5.7.3",
|
|
36
|
-
"vite": "^
|
|
26
|
+
"vite": "^7.3.1",
|
|
37
27
|
"vite-tsconfig-paths": "^5.1.4",
|
|
38
|
-
"vitest": "^3.
|
|
28
|
+
"vitest": "^3.2.4"
|
|
39
29
|
},
|
|
40
30
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
-
"@t402/
|
|
43
|
-
"@t402/
|
|
44
|
-
"zod": "^3.24.2"
|
|
31
|
+
"zod": "^3.24.2",
|
|
32
|
+
"@t402/extensions": "2.3.1",
|
|
33
|
+
"@t402/core": "2.3.1"
|
|
45
34
|
},
|
|
46
35
|
"peerDependencies": {
|
|
47
|
-
"next": "^16.0.
|
|
48
|
-
"@t402/paywall": "
|
|
36
|
+
"next": "^15.0.0 || ^16.0.0",
|
|
37
|
+
"@t402/paywall": "2.3.1"
|
|
49
38
|
},
|
|
50
39
|
"peerDependenciesMeta": {
|
|
51
40
|
"@t402/paywall": {
|
|
@@ -67,5 +56,16 @@
|
|
|
67
56
|
},
|
|
68
57
|
"files": [
|
|
69
58
|
"dist"
|
|
70
|
-
]
|
|
71
|
-
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"start": "tsx --env-file=.env index.ts",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"test:watch": "vitest",
|
|
64
|
+
"build": "tsup",
|
|
65
|
+
"watch": "tsc --watch",
|
|
66
|
+
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
|
|
67
|
+
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
|
|
68
|
+
"lint": "eslint . --ext .ts --fix",
|
|
69
|
+
"lint:check": "eslint . --ext .ts"
|
|
70
|
+
}
|
|
71
|
+
}
|