Skip to content

Add runtime support for V2 int64 string-encoded fields#2600

Merged
mbroshi-stripe merged 4 commits intomasterfrom
mbroshi/v2-int64-as-string
Mar 18, 2026
Merged

Add runtime support for V2 int64 string-encoded fields#2600
mbroshi-stripe merged 4 commits intomasterfrom
mbroshi/v2-int64-as-string

Conversation

@mbroshi-stripe
Copy link
Contributor

@mbroshi-stripe mbroshi-stripe commented Mar 12, 2026

Why?

V2 APIs represent int64 fields as JSON strings on the wire (e.g. "12345" instead of 12345) to avoid precision loss. The SDK should transparently convert between native JS numbers/bigints and this wire format so users don't need to handle string encoding themselves.

What?

  • Added V2RuntimeSchema type to Types.d.ts and optional requestSchema/responseSchema fields on MethodSpec
  • Added V2Int64.ts with coerceV2RequestData (number/bigint → string) and coerceV2ResponseData (string → bigint) coercion functions
  • Wired coercion into StripeResource._request(): request body is coerced before JSON serialization, response is coerced before returning to callers
  • Added unit tests (V2Int64.spec.ts) and integration tests (V2Int64Integration.spec.ts)

@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner March 12, 2026 16:45
@mbroshi-stripe mbroshi-stripe requested review from jar-stripe and removed request for a team March 12, 2026 16:45
@mbroshi-stripe mbroshi-stripe marked this pull request as draft March 12, 2026 16:45
@mbroshi-stripe mbroshi-stripe removed the request for review from jar-stripe March 12, 2026 16:45
@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from 7adfdda to 04d43a7 Compare March 15, 2026 19:39
@mbroshi-stripe mbroshi-stripe changed the title WIP Mbroshi/v2 int64 as string Mar 15, 2026
@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from 04d43a7 to f22bd2b Compare March 15, 2026 22:07
@mbroshi-stripe mbroshi-stripe changed the title Mbroshi/v2 int64 as string Add runtime support for V2 int64 string-encoded fields Mar 15, 2026
@mbroshi-stripe mbroshi-stripe changed the base branch from private-preview to master March 15, 2026 22:32
@mbroshi-stripe mbroshi-stripe marked this pull request as ready for review March 16, 2026 00:51
@mbroshi-stripe mbroshi-stripe requested review from a team and prathmesh-stripe and removed request for a team March 16, 2026 01:25
Copy link
Member

@xavdid-stripe xavdid-stripe left a comment

Choose a reason for hiding this comment

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

Looks generally good, but had a few questions

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds runtime schema-driven coercion for V2 “int64-as-JSON-string” fields so SDK users can pass native bigint/number inputs while V2 requests are encoded as strings, and V2 responses are decoded back to bigint.

Changes:

  • Introduces a runtime schema type (V2RuntimeSchema) and adds optional requestSchema / responseSchema fields to MethodSpec.
  • Adds coerceV2RequestData / coerceV2ResponseData and wires them into StripeResource._makeRequest() for request/response coercion.
  • Adds unit + integration tests, plus a mocha setup tweak to allow BigInt values to traverse mocha’s parallel IPC.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tsconfig.cjs.json Enables es2020.bigint lib types for the CJS TypeScript build.
test/setup.js Adds a global BigInt JSON serialization shim for mocha parallel worker IPC.
test/V2Int64Integration.spec.ts Integration coverage for request/response coercion and JSON-on-the-wire expectations.
test/V2Int64.spec.ts Unit tests for schema-walking coercion functions across objects/arrays/nullables.
src/V2Int64.ts Implements schema-driven coercion for int64_string fields.
src/Types.d.ts Declares V2RuntimeSchema and extends MethodSpec with schema hooks.
src/StripeResource.ts Applies request coercion before serialization and response coercion before returning to callers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/v2-int64-as-string branch from 4cbb3a2 to cfbe23b Compare March 18, 2026 13:30
@mbroshi-stripe mbroshi-stripe enabled auto-merge (squash) March 18, 2026 13:39
@mbroshi-stripe mbroshi-stripe merged commit c2387c1 into master Mar 18, 2026
11 checks passed
@mbroshi-stripe mbroshi-stripe deleted the mbroshi/v2-int64-as-string branch March 18, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants