Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/typescript/clients/batch-settlement/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { toClientEvmSigner } from "@x402/evm";
import {
BatchSettlementEvmScheme,
FileClientChannelStorage,
} from "@x402/evm/batch-settlement/client";
import { BatchSettlementEvmScheme } from "@x402/evm/batch-settlement/client";
import { FileClientChannelStorage } from "@x402/evm/batch-settlement/client/file-storage";
import { x402Client, wrapFetchWithPayment, x402HTTPClient } from "@x402/fetch";
import { config } from "dotenv";
import { createPublicClient, http } from "viem";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Next.js batch-settlement (Redis storage)

Next.js demo that exposes **`GET /api/weather`** behind `withX402` with the **batch-settlement** scheme. Channel state uses **`RedisChannelStorage`** (`@x402/evm/batch-settlement/server`), backed by the **`redis`** npm client via `lib/redisChannelClient.ts`.
Next.js demo that exposes **`GET /api/weather`** behind `withX402` with the **batch-settlement** scheme. Channel state uses **`RedisChannelStorage`** (`@x402/evm/batch-settlement/server/redis-storage`), backed by the **`redis`** npm client via `lib/redisChannelClient.ts`.

Parallels:

Expand Down Expand Up @@ -68,7 +68,7 @@ With a daily cron, `DEFERRED_WITHDRAW_DELAY_SECONDS` must exceed the daily caden

## Files

- `lib/server.ts` — facilitator client, `BatchSettlementEvmScheme` + `RedisChannelStorage`
- `lib/server.ts` — facilitator client, `BatchSettlementEvmScheme` (`/server`) + `RedisChannelStorage` (`/server/redis-storage`)
- `lib/cron.ts` — shared claim, settle, and claim-and-settle cron implementations
- `lib/cronAuth.ts` — optional bearer-token check for cron routes
- `lib/redisChannelClient.ts` — lazy `redis` adapter implementing `RedisChannelStorageClient`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
RedisEvalOptions,
RedisScanOptions,
RedisSetOptions,
} from "@x402/evm/batch-settlement/server";
} from "@x402/evm/batch-settlement/server/redis-storage";
import { createClient } from "redis";

export type LazyRedisChannelStorageClient = RedisChannelStorageClient & {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HTTPFacilitatorClient, x402ResourceServer } from "@x402/core/server";
import { BatchSettlementEvmScheme, RedisChannelStorage } from "@x402/evm/batch-settlement/server";
import { BatchSettlementEvmScheme } from "@x402/evm/batch-settlement/server";
import { RedisChannelStorage } from "@x402/evm/batch-settlement/server/redis-storage";
import { privateKeyToAccount } from "viem/accounts";

import { createLazyRedisChannelStorageClient } from "./redisChannelClient";
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript/fullstack/next/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/dev/types/routes.d.ts";
import "./.next/types/routes.d.ts";

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
3 changes: 2 additions & 1 deletion examples/typescript/servers/batch-settlement/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HTTPFacilitatorClient } from "@x402/core/server";
import { BatchSettlementEvmScheme, FileChannelStorage } from "@x402/evm/batch-settlement/server";
import { BatchSettlementEvmScheme } from "@x402/evm/batch-settlement/server";
import { FileChannelStorage } from "@x402/evm/batch-settlement/server/file-storage";
import { paymentMiddleware, setSettlementOverrides, x402ResourceServer } from "@x402/express";
import { config } from "dotenv";
import express from "express";
Expand Down
5 changes: 5 additions & 0 deletions typescript/.changeset/gold-forks-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@x402/evm': minor
---

add optional batch-settlement client/file-storage and server/file-storage (and server/redis-storage) exports to avoid pulling Node-fs/Redis helpers into default bundles
30 changes: 30 additions & 0 deletions typescript/packages/mechanisms/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
"default": "./dist/cjs/batch-settlement/client/index.js"
}
},
"./batch-settlement/client/file-storage": {
"import": {
"types": "./dist/esm/batch-settlement/client/file-storage.d.mts",
"default": "./dist/esm/batch-settlement/client/file-storage.mjs"
},
"require": {
"types": "./dist/cjs/batch-settlement/client/file-storage.d.ts",
"default": "./dist/cjs/batch-settlement/client/file-storage.js"
}
},
"./batch-settlement/server": {
"import": {
"types": "./dist/esm/batch-settlement/server/index.d.mts",
Expand All @@ -170,6 +180,26 @@
"default": "./dist/cjs/batch-settlement/server/index.js"
}
},
"./batch-settlement/server/file-storage": {
"import": {
"types": "./dist/esm/batch-settlement/server/file-storage.d.mts",
"default": "./dist/esm/batch-settlement/server/file-storage.mjs"
},
"require": {
"types": "./dist/cjs/batch-settlement/server/file-storage.d.ts",
"default": "./dist/cjs/batch-settlement/server/file-storage.js"
}
},
"./batch-settlement/server/redis-storage": {
"import": {
"types": "./dist/esm/batch-settlement/server/redis-storage.d.mts",
"default": "./dist/esm/batch-settlement/server/redis-storage.mjs"
},
"require": {
"types": "./dist/cjs/batch-settlement/server/redis-storage.d.ts",
"default": "./dist/cjs/batch-settlement/server/redis-storage.js"
}
},
"./batch-settlement/facilitator": {
"import": {
"types": "./dist/esm/batch-settlement/facilitator/index.d.mts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ The server claims any outstanding vouchers and then executes `refundWithSignatur
By default, channel state is stored in memory. For long-lived clients, use `FileClientChannelStorage`:

```typescript
import { FileClientChannelStorage } from "@x402/evm/batch-settlement/client";
import { FileClientChannelStorage } from "@x402/evm/batch-settlement/client/file-storage";

const scheme = new BatchSettlementEvmScheme(signer, {
storage: new FileClientChannelStorage({ directory: "./channels" }),
Expand All @@ -107,11 +107,9 @@ Register the scheme with an `x402ResourceServer` and pair it with a `ChannelMana

```typescript
import { x402ResourceServer } from "@x402/core/server";
import {
BatchSettlementEvmScheme,
FileChannelStorage,
RedisChannelStorage,
} from "@x402/evm/batch-settlement/server";
import { BatchSettlementEvmScheme } from "@x402/evm/batch-settlement/server";
import { FileChannelStorage } from "@x402/evm/batch-settlement/server/file-storage";
import { RedisChannelStorage } from "@x402/evm/batch-settlement/server/redis-storage";

const scheme = new BatchSettlementEvmScheme(receiverAddress, {
receiverAuthorizerSigner, // optional: self-managed authorizer (recommended)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { isNodeEnoent, readJsonFile, writeJsonAtomic } from "../storage-utils";
import type { FileChannelStorageOptions } from "../types";
import type { ClientChannelStorage, BatchSettlementClientContext } from "./storage";

export type { FileChannelStorageOptions };

/**
* Node.js file-backed {@link ClientChannelStorage} for the batched client scheme.
* Each channel's context is persisted as `{root}/client/{channelId}.json` so that channel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type {
} from "./scheme";
export type { ClientChannelStorage } from "./storage";
export { InMemoryClientChannelStorage } from "./storage";
export { FileClientChannelStorage } from "./fileStorage";
export { createBatchSettlementEIP3009DepositPayload } from "./eip3009";
export { signVoucher } from "./voucher";
export { refundChannel } from "./refund";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ export type { BatchSettlementEvmSchemeServerConfig, BatchSettlementRequestContex
export type { AuthorizerSigner } from "../types";
export { InMemoryChannelStorage } from "./storage";
export type { Channel, ChannelStorage, ChannelUpdateResult, PendingRequest } from "./storage";
export type { FileChannelStorageOptions } from "./fileStorage";
export { FileChannelStorage } from "./fileStorage";
export { RedisChannelStorage } from "./redisStorage";
export type {
RedisChannelStorageClient,
RedisChannelStorageOptions,
RedisEvalOptions,
RedisScanOptions,
RedisSetOptions,
} from "./redisStorage";
export { BatchSettlementChannelManager } from "./channelManager";
export type {
ChannelManagerConfig,
Expand Down
3 changes: 3 additions & 0 deletions typescript/packages/mechanisms/evm/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const baseConfig = {
"upto/server/index": "src/upto/server/index.ts",
"upto/facilitator/index": "src/upto/facilitator/index.ts",
"batch-settlement/client/index": "src/batch-settlement/client/index.ts",
"batch-settlement/client/file-storage": "src/batch-settlement/client/fileStorage.ts",
"batch-settlement/server/index": "src/batch-settlement/server/index.ts",
"batch-settlement/server/file-storage": "src/batch-settlement/server/fileStorage.ts",
"batch-settlement/server/redis-storage": "src/batch-settlement/server/redisStorage.ts",
"batch-settlement/facilitator/index": "src/batch-settlement/facilitator/index.ts",
},
dts: {
Expand Down
Loading