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
5 changes: 5 additions & 0 deletions .changeset/five-plums-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Loosen network schema
15 changes: 1 addition & 14 deletions packages/thirdweb/src/x402/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@ import {
import { z } from "zod";
import type { Chain } from "../chains/types.js";

const FacilitatorNetworkSchema = z.union([
z.literal("base-sepolia"),
z.literal("base"),
z.literal("avalanche-fuji"),
z.literal("avalanche"),
z.literal("iotex"),
z.literal("solana-devnet"),
z.literal("solana"),
z.literal("sei"),
z.literal("sei-testnet"),
z.string().refine((value) => value.startsWith("eip155:"), {
message: "Invalid network",
}),
]);
const FacilitatorNetworkSchema = z.string();

export type FacilitatorNetwork = z.infer<typeof FacilitatorNetworkSchema>;
Comment on lines +14 to 16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Add required TSDoc and verify runtime validation coverage.

The FacilitatorNetworkSchema is a public symbol (exported via the FacilitatorNetwork type) but lacks TSDoc documentation. According to the coding guidelines, every public symbol in packages/thirdweb/** must have comprehensive TSDoc with at least one compiling @example and a custom tag.

Additionally, this change shifts validation from schema-time to runtime (via the networkToChainId function at lines 95-116). Ensure that all code paths consuming FacilitatorNetwork values properly call networkToChainId or otherwise validate the network string before use.

As per coding guidelines.

Consider adding TSDoc like:

+/**
+ * Schema for facilitator network identifiers.
+ * Accepts any string value; runtime validation via `networkToChainId` is required.
+ *
+ * @example
+ * ```ts
+ * const network = FacilitatorNetworkSchema.parse("eip155:1");
+ * const chainId = networkToChainId(network);
+ * ```
+ *
+ * @public
+ */
 const FacilitatorNetworkSchema = z.string();

Run the following script to verify that network values are validated before use:


🏁 Script executed:

#!/bin/bash
# Description: Find usages of FacilitatorNetwork or properties named 'network' from these schemas
# to verify runtime validation is applied

echo "=== Searching for FacilitatorNetwork type usage ==="
rg -n "FacilitatorNetwork" --type ts -C 3

echo -e "\n=== Searching for networkToChainId calls ==="
rg -n "networkToChainId" --type ts -C 2

echo -e "\n=== Searching for .network property access on x402 types ==="
rg -nP --type ts "\.network\b" -g '**/x402/**' -C 2

Length of output: 11966


Add required TSDoc—runtime validation coverage is properly handled.

The FacilitatorNetworkSchema and FacilitatorNetwork type lack TSDoc documentation, violating the coding guidelines requiring comprehensive TSDoc with @example and a custom tag for all public symbols in packages/thirdweb/**.

Runtime validation via networkToChainId() is properly applied across all critical code paths (sign.ts, fetchWithPayment.ts, common.ts).

Add TSDoc:

+/**
+ * Schema for facilitator network identifiers.
+ * Accepts any string value; runtime validation via `networkToChainId` is required.
+ *
+ * @example
+ * ```ts
+ * const network = FacilitatorNetworkSchema.parse("eip155:1");
+ * const chainId = networkToChainId(network);
+ * ```
+ *
+ * @public
+ */
 const FacilitatorNetworkSchema = z.string();

+/** @public */
 export type FacilitatorNetwork = z.infer<typeof FacilitatorNetworkSchema>;
🤖 Prompt for AI Agents
In packages/thirdweb/src/x402/schemas.ts around lines 14 to 16, the public
symbols FacilitatorNetworkSchema and FacilitatorNetwork are missing required
TSDoc; add a TSDoc block above FacilitatorNetworkSchema showing an example usage
(e.g., parsing "eip155:1" and passing to networkToChainId) and include the
@public tag, and add a short TSDoc with @public above the exported
FacilitatorNetwork type; ensure the comments follow existing project style and
include the example snippet shown in the review comment.


Expand Down
Loading