diff --git a/examples/typescript/clients/batch-settlement/index.ts b/examples/typescript/clients/batch-settlement/index.ts index dc535ef2ab..b234e8a6b3 100644 --- a/examples/typescript/clients/batch-settlement/index.ts +++ b/examples/typescript/clients/batch-settlement/index.ts @@ -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"; diff --git a/examples/typescript/fullstack/next-batch-settlement-redis/README.md b/examples/typescript/fullstack/next-batch-settlement-redis/README.md index 32ca906ba4..959e3255ed 100644 --- a/examples/typescript/fullstack/next-batch-settlement-redis/README.md +++ b/examples/typescript/fullstack/next-batch-settlement-redis/README.md @@ -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: @@ -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` diff --git a/examples/typescript/fullstack/next-batch-settlement-redis/lib/redisChannelClient.ts b/examples/typescript/fullstack/next-batch-settlement-redis/lib/redisChannelClient.ts index fc5047be46..443463947b 100644 --- a/examples/typescript/fullstack/next-batch-settlement-redis/lib/redisChannelClient.ts +++ b/examples/typescript/fullstack/next-batch-settlement-redis/lib/redisChannelClient.ts @@ -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 & { diff --git a/examples/typescript/fullstack/next-batch-settlement-redis/lib/server.ts b/examples/typescript/fullstack/next-batch-settlement-redis/lib/server.ts index 2e8ce234cc..bce916617a 100644 --- a/examples/typescript/fullstack/next-batch-settlement-redis/lib/server.ts +++ b/examples/typescript/fullstack/next-batch-settlement-redis/lib/server.ts @@ -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"; diff --git a/examples/typescript/fullstack/next/next-env.d.ts b/examples/typescript/fullstack/next/next-env.d.ts index c4b7818fbb..9edff1c7ca 100644 --- a/examples/typescript/fullstack/next/next-env.d.ts +++ b/examples/typescript/fullstack/next/next-env.d.ts @@ -1,6 +1,6 @@ /// /// -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. diff --git a/examples/typescript/servers/batch-settlement/index.ts b/examples/typescript/servers/batch-settlement/index.ts index 5669b60083..1b0ae58e31 100644 --- a/examples/typescript/servers/batch-settlement/index.ts +++ b/examples/typescript/servers/batch-settlement/index.ts @@ -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"; diff --git a/typescript/.changeset/gold-forks-smoke.md b/typescript/.changeset/gold-forks-smoke.md new file mode 100644 index 0000000000..36c2f7bde3 --- /dev/null +++ b/typescript/.changeset/gold-forks-smoke.md @@ -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 diff --git a/typescript/packages/mechanisms/evm/package.json b/typescript/packages/mechanisms/evm/package.json index d4e4624beb..a1060c47fa 100644 --- a/typescript/packages/mechanisms/evm/package.json +++ b/typescript/packages/mechanisms/evm/package.json @@ -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", @@ -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", diff --git a/typescript/packages/mechanisms/evm/src/batch-settlement/README.md b/typescript/packages/mechanisms/evm/src/batch-settlement/README.md index 1ae4de5949..f7a5ddca6c 100644 --- a/typescript/packages/mechanisms/evm/src/batch-settlement/README.md +++ b/typescript/packages/mechanisms/evm/src/batch-settlement/README.md @@ -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" }), @@ -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) diff --git a/typescript/packages/mechanisms/evm/src/batch-settlement/client/fileStorage.ts b/typescript/packages/mechanisms/evm/src/batch-settlement/client/fileStorage.ts index 16e6921c5c..915bac8984 100644 --- a/typescript/packages/mechanisms/evm/src/batch-settlement/client/fileStorage.ts +++ b/typescript/packages/mechanisms/evm/src/batch-settlement/client/fileStorage.ts @@ -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 diff --git a/typescript/packages/mechanisms/evm/src/batch-settlement/client/index.ts b/typescript/packages/mechanisms/evm/src/batch-settlement/client/index.ts index 8f2e3abce4..3d3288ef54 100644 --- a/typescript/packages/mechanisms/evm/src/batch-settlement/client/index.ts +++ b/typescript/packages/mechanisms/evm/src/batch-settlement/client/index.ts @@ -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"; diff --git a/typescript/packages/mechanisms/evm/src/batch-settlement/server/index.ts b/typescript/packages/mechanisms/evm/src/batch-settlement/server/index.ts index eb4f408fbe..0fe429712f 100644 --- a/typescript/packages/mechanisms/evm/src/batch-settlement/server/index.ts +++ b/typescript/packages/mechanisms/evm/src/batch-settlement/server/index.ts @@ -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, diff --git a/typescript/packages/mechanisms/evm/tsup.config.ts b/typescript/packages/mechanisms/evm/tsup.config.ts index 2fcd5c4c25..d8d066d877 100644 --- a/typescript/packages/mechanisms/evm/tsup.config.ts +++ b/typescript/packages/mechanisms/evm/tsup.config.ts @@ -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: {