-
Notifications
You must be signed in to change notification settings - Fork 604
[SDK] Expose waitUntil parameter in settlePayment() #8153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDK] Expose waitUntil parameter in settlePayment() #8153
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: fbecb94 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds an optional waitUntil field to the x402 payment settlement API and threads it through types and runtime: new SettlePaymentArgs includes waitUntil, settlePayment forwards waitUntil to the facilitator, facilitator accepts an optional waitUtil config/arg, and request body includes waitUtil only when resolved. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Caller
participant SP as settlePayment
participant F as Facilitator.settle
participant API as X402 Service
C->>SP: settlePayment({ ..., waitUntil? })
SP->>F: settle(..., waitUtil=waitUntil)
Note over F: waitUtilParam = arg.waitUtil ?? config.waitUtil
alt waitUtilParam present
F->>API: POST /settle { ..., waitUtil: waitUtilParam }
else no waitUtilParam
F->>API: POST /settle { ... }
end
API-->>F: 200 Success / 402 Payment Required
F-->>SP: SettlePaymentResult | PaymentRequiredResult
SP-->>C: Result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used📓 Path-based instructions (4)**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
packages/thirdweb/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/thirdweb/src/exports/**📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧬 Code graph analysis (1)packages/thirdweb/src/x402/facilitator.ts (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🔇 Additional comments (2)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Comment |
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
size-limit report 📦
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8153 +/- ##
=======================================
Coverage 56.28% 56.28%
=======================================
Files 906 906
Lines 59208 59208
Branches 4176 4180 +4
=======================================
Hits 33324 33324
Misses 25779 25779
Partials 105 105
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/thirdweb/src/x402/facilitator.ts (1)
163-170
: JSDoc: include the new wait param.Add
@param
for the wait parameter to keep docs complete./** * Settles a payment with the facilitator service * * @param payload - The payment payload to settle * @param paymentRequirements - The payment requirements for the settlement + * @param waitUntil - Optional stage ("simulated" | "submitted" | "confirmed") to wait for before responding * @returns A promise that resolves to the settlement response */
🧹 Nitpick comments (7)
packages/thirdweb/src/x402/types.ts (1)
6-6
: Type ownership: define Wait type in types.ts to avoid cross-module coupling.To keep types centralized and avoid types.ts → facilitator.ts dependency, move the wait type here and have facilitator import it from types.ts. Also align naming with the public arg name (“waitUntil”).
-import type { ThirdwebX402Facilitator, WaitUtil } from "./facilitator.js"; +import type { ThirdwebX402Facilitator } from "./facilitator.js"; + +/** @public @beta */ +export type WaitUntil = "simulated" | "submitted" | "confirmed"; +/** @public @beta @deprecated Use WaitUntil */ +export type WaitUtil = WaitUntil;Follow-up: update facilitator.ts to import
WaitUntil
from./types.js
and use it (see facilitator comments). Based on coding guidelines.packages/thirdweb/src/x402/settle-payment.ts (1)
143-146
: Naming consistency across API: waitUntil vs waitUtil.You pass
args.waitUntil
to a parameter namedwaitUtil
. Recommend standardizing on “waitUntil” everywhere (types, config, and method param) for clarity. Backward-compat alias can be maintained.packages/thirdweb/src/x402/facilitator.ts (5)
17-17
: Config property: standardize on waitUntil and preserve compat.Align with
SettlePaymentArgs.waitUntil
and keepwaitUtil
as deprecated.- waitUtil?: WaitUtil; + /** @beta Preferred. Stage to wait for. */ + waitUntil?: WaitUntil; + /** @deprecated Use waitUntil */ + waitUtil?: WaitUntil;
42-43
: Method param: standardize and document the param.Align to
waitUntil?: WaitUntil
and add param docs on the type.- waitUtil?: WaitUtil, + /** Optional stage to wait for before responding. */ + waitUntil?: WaitUntil,
170-175
: Implementation param rename + docs.Rename local param and document in the JSDoc block above.
- async settle( + async settle( payload: RequestedPaymentPayload, paymentRequirements: RequestedPaymentRequirements, - waitUtil?: WaitUtil, + waitUntil?: WaitUntil, ): Promise<FacilitatorSettleResponse> {
180-181
: Prefer nullish coalescing and support both config keys.Handle both
waitUntil
and deprecatedwaitUtil
.- const waitUtilParam = waitUtil || config.waitUtil; + const waitUntilParam = + waitUntil ?? config.waitUntil ?? config.waitUtil;
185-190
: Body field name + stringify helper.
- If adopting the rename, send
waitUntil
.- Use the shared
stringify
helper for consistency withverify
.- const res = await fetch(`${url}/settle`, { + const res = await fetch(`${url}/settle`, { method: "POST", headers, - body: JSON.stringify({ + body: stringify({ x402Version: payload.x402Version, paymentPayload: payload, paymentRequirements: paymentRequirements, - ...(waitUtilParam ? { waitUtil: waitUtilParam } : {}), + ...(waitUntilParam ? { waitUntil: waitUntilParam } : {}), }), });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (5)
.changeset/yellow-cameras-tease.md
(1 hunks)packages/thirdweb/src/exports/x402.ts
(1 hunks)packages/thirdweb/src/x402/facilitator.ts
(4 hunks)packages/thirdweb/src/x402/settle-payment.ts
(3 hunks)packages/thirdweb/src/x402/types.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
.changeset/*.md
📄 CodeRabbit inference engine (AGENTS.md)
.changeset/*.md
: Each change inpackages/*
must include a changeset for the appropriate package
Version bump rules: patch for non‑API changes; minor for new/modified public API
Files:
.changeset/yellow-cameras-tease.md
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}
: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from@/types
or localtypes.ts
barrels
Prefer type aliases over interface except for nominal shapes
Avoidany
andunknown
unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial
,Pick
, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
**/*.{ts,tsx}
: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from@/types
where applicable
Prefertype
aliases overinterface
except for nominal shapes
Avoidany
andunknown
unless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size
Files:
packages/thirdweb/src/x402/types.ts
packages/thirdweb/src/exports/x402.ts
packages/thirdweb/src/x402/facilitator.ts
packages/thirdweb/src/x402/settle-payment.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)
Files:
packages/thirdweb/src/x402/types.ts
packages/thirdweb/src/exports/x402.ts
packages/thirdweb/src/x402/facilitator.ts
packages/thirdweb/src/x402/settle-payment.ts
**/types.ts
📄 CodeRabbit inference engine (AGENTS.md)
Provide and re‑use local type barrels in a
types.ts
file
Files:
packages/thirdweb/src/x402/types.ts
packages/thirdweb/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
packages/thirdweb/**/*.{ts,tsx}
: Every public symbol must have comprehensive TSDoc with at least one compiling@example
and a custom tag (@beta
,@internal
,@experimental
, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Lazy‑load heavy dependencies inside async paths (e.g.,const { jsPDF } = await import("jspdf")
)
Files:
packages/thirdweb/src/x402/types.ts
packages/thirdweb/src/exports/x402.ts
packages/thirdweb/src/x402/facilitator.ts
packages/thirdweb/src/x402/settle-payment.ts
packages/thirdweb/src/exports/**
📄 CodeRabbit inference engine (CLAUDE.md)
packages/thirdweb/src/exports/**
: Export everything viaexports/
directory, grouped by feature in the SDK public API
Every public symbol must have comprehensive TSDoc with at least one@example
block that compiles and custom annotation tags (@beta
,@internal
,@experimental
)
Files:
packages/thirdweb/src/exports/x402.ts
🧬 Code graph analysis (3)
packages/thirdweb/src/x402/types.ts (2)
packages/thirdweb/src/exports/x402.ts (2)
SettlePaymentArgs
(13-13)PaymentArgs
(11-11)packages/thirdweb/src/x402/facilitator.ts (1)
WaitUtil
(12-12)
packages/thirdweb/src/x402/facilitator.ts (3)
packages/thirdweb/src/exports/thirdweb.ts (1)
ThirdwebClient
(25-25)packages/thirdweb/src/x402/schemas.ts (1)
FacilitatorSettleResponse
(56-58)packages/ai-sdk-provider/src/types.ts (1)
DEFAULT_BASE_URL
(10-10)
packages/thirdweb/src/x402/settle-payment.ts (1)
packages/thirdweb/src/x402/types.ts (1)
SettlePaymentArgs
(42-44)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: Size
- GitHub Check: Unit Tests
- GitHub Check: Lint Packages
- GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/thirdweb/src/x402/facilitator.ts (1)
50-50
: Nit: Confirm API expectswaitUtil
in the/settle
payload (notwaitUntil
). No changes needed toDEFAULT_BASE_URL
.
635ae32
to
fbecb94
Compare
PR-Codex overview
This PR introduces a new
waitUntil
parameter in thesettlePayment()
function, enhancing its flexibility by allowing users to specify when to wait for a payment settlement. It also updates type definitions and relevant function signatures to accommodate this change.Detailed summary
WaitUntil
type to represent payment wait states.SettlePaymentArgs
to includewaitUntil
parameter.settlePayment
function to acceptSettlePaymentArgs
.settle
method inThirdwebX402Facilitator
to usewaitUtil
parameter.waitUntil
usage.Summary by CodeRabbit
New Features
Chores