Skip to content

Commit 26f9840

Browse files
authored
perf: remove viem from Stripe runtime (#876)
* perf: remove viem from Stripe runtime * fix: keep viem as required peer * docs: link Stripe amount parser source * docs: link original viem parser change * fix: resolve dependency audit failures * chore: remove extra audit changeset
1 parent f494ffd commit 26f9840

14 files changed

Lines changed: 1108 additions & 671 deletions

File tree

.changeset/stripe-without-viem.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mppx': patch
3+
---
4+
5+
Removed the Stripe SPT runtime dependency on viem.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"@types/node": "^26.2.0",
4242
"@types/ws": "^8.18.1",
4343
"@typescript/native-preview": "7.0.0-dev.20260707.2",
44-
"@vitest/coverage-v8": "4.1.8",
44+
"@vitest/browser-playwright": "4.1.11",
45+
"@vitest/coverage-v8": "4.1.11",
4546
"@x402/core": "2.22.0",
4647
"@x402/evm": "2.22.0",
4748
"@x402/express": "2.22.0",
@@ -55,10 +56,10 @@
5556
"fast-check": "^4.9.0",
5657
"file-type": "catalog:",
5758
"frog": "^1.1.0",
58-
"hono": "4.13.1",
59+
"hono": "4.13.7",
5960
"incur": "^0.5.1",
6061
"isows": "^1.0.7",
61-
"next": "16.3.2",
62+
"next": "16.3.4",
6263
"pkg-pr-new": "0.0.88",
6364
"playwright": "^1.62.1",
6465
"prool": "^0.2.14",
@@ -69,7 +70,7 @@
6970
"typescript": "catalog:",
7071
"viem": "2.55.13",
7172
"vite": "^8.2.1",
72-
"vp": "npm:vite-plus@~0.1.24",
73+
"vp": "npm:vite-plus@0.3.0",
7374
"ws": "^8.21.3",
7475
"zile": "^0.0.30"
7576
},

pnpm-lock.yaml

Lines changed: 933 additions & 613 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ catalog:
1616

1717
overrides:
1818
mppx: 'workspace:*'
19-
vitest: 'npm:@voidzero-dev/vite-plus-test@~0.1.24'
19+
vitest@<4.1.11: '4.1.11'
2020
typescript: 'catalog:'
2121
ox: 'catalog:'
2222
viem: '2.55.13'
@@ -38,7 +38,7 @@ overrides:
3838
flatted@<=3.4.1: '>=3.4.2'
3939
follow-redirects@<=1.15.11: '1.16.0'
4040
fast-uri@<3.1.6: '3.1.6'
41-
hono@<4.12.34: '4.12.34'
41+
hono@<4.13.7: '4.13.7'
4242
'@hono/node-server@<2.0.10': '2.0.10'
4343
undici@>=7.0.0 <7.28.0: '7.28.0'
4444
undici@>=8.0.0 <8.9.0: '8.9.0'
@@ -51,8 +51,7 @@ overrides:
5151
uuid@<14.0.0: '14.0.0'
5252
tmp@>=0.2.6 <0.2.7: '0.2.7'
5353
vite@>=8.0.0 <=8.0.15: '8.0.16'
54-
vite-plus@<=0.1.23: '0.1.24'
55-
'@voidzero-dev/vite-plus-test@<=0.1.23': '0.1.24'
54+
vite-plus@<0.3.0: '0.3.0'
5655
esbuild@>=0.17.0 <0.28.1: '0.28.1'
5756
read-yaml-file@^1.1.0: '2.1.0'
5857
js-yaml@>=4.0.0 <4.3.1: '4.3.1'
@@ -74,7 +73,7 @@ minimumReleaseAgeExclude:
7473
- body-parser@2.3.0
7574
- brace-expansion@5.0.9
7675
- fast-uri@3.1.6
77-
- hono@4.12.34
76+
- hono@4.13.7
7877
- ip-address@10.3.1
7978
- js-yaml@4.3.1
8079
- nanoid@3.3.18
@@ -88,5 +87,5 @@ minimumReleaseAgeExclude:
8887
- undici@8.9.0
8988
- viem@2.55.13
9089
- vite@8.0.16
91-
- vite-plus@0.1.24
90+
- vite-plus@0.3.0
9291
- ws@8.21.0

scripts/check:package.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ try {
8484
if (JSON.stringify(manifest.exports).includes('"src"'))
8585
throw new Error('Published exports include a src condition')
8686

87+
const stripeViemImports = paths.filter(
88+
(file) =>
89+
file.startsWith('dist/stripe/') &&
90+
file.endsWith('.js') &&
91+
/["']viem(?:\/[^"']*)?["']/.test(fs.readFileSync(path.join(root, file), 'utf8')),
92+
)
93+
if (stripeViemImports.length > 0)
94+
throw new Error(
95+
`Stripe package files import viem:\n${stripeViemImports.map((file) => `- ${file}`).join('\n')}`,
96+
)
97+
8798
const packageRoot = path.join(extractDirectory, 'package')
8899
const missingTargets = packageTargets({
89100
bin: manifest.bin,

src/internal/AcceptPayment.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ export type Key<methods extends readonly MethodLike[]> = methods[number] extends
3737
/** Method keys grouped by method name for ergonomic config callbacks. */
3838
export type KeyTree<methods extends readonly MethodLike[]> = {
3939
[name in methods[number]['name']]: {
40-
[mi in Extract<
41-
methods[number],
42-
{ name: name }
43-
> as mi['intent']]: `${mi['name']}/${mi['intent']}`
40+
[
41+
mi in Extract<methods[number], { name: name }> as mi['intent']
42+
]: `${mi['name']}/${mi['intent']}`
4443
}
4544
}
4645

src/server/Mppx.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,11 +1973,14 @@ describe('server events', () => {
19731973
inputOnly: z.optional(z.string()),
19741974
recipient: z.string(),
19751975
}),
1976-
z.transform(({ amount, currency, decimals, inputOnly: _, recipient }) => ({
1977-
amount: String(Number(amount) * 10 ** decimals),
1978-
currency,
1979-
recipient,
1980-
})),
1976+
z.transform(({ amount, currency, decimals, inputOnly, recipient }) => {
1977+
void inputOnly
1978+
return {
1979+
amount: String(Number(amount) * 10 ** decimals),
1980+
currency,
1981+
recipient,
1982+
}
1983+
}),
19811984
),
19821985
},
19831986
})

src/server/Mppx.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,9 @@ type IntentHandlers<
384384
methods extends readonly Method.AnyServer[],
385385
transport extends Transport.AnyTransport,
386386
> = {
387-
[intent in methods[number]['intent'] as intent extends ReservedKey
388-
? never
389-
: intent]: IsUniqueIntent<methods, intent> extends true
387+
[
388+
intent in methods[number]['intent'] as intent extends ReservedKey ? never : intent
389+
]: IsUniqueIntent<methods, intent> extends true
390390
? MethodFn<
391391
Extract<methods[number], { intent: intent }>,
392392
EffectiveTransportOf<Extract<methods[number], { intent: intent }>, transport>,
@@ -455,9 +455,11 @@ type Handlers<
455455
MethodExtensions<mi>
456456
} & IntentHandlers<methods, transport> &
457457
NestedHandlers<methods, transport> & {
458-
[mi in methods[number] as PublicAlias<mi> extends string
459-
? `${mi['name']}/${PublicAlias<mi>}`
460-
: never]: MethodFn<mi, EffectiveTransportOf<mi, transport>, NonNullable<mi['defaults']>> &
458+
[
459+
mi in methods[number] as PublicAlias<mi> extends string
460+
? `${mi['name']}/${PublicAlias<mi>}`
461+
: never
462+
]: MethodFn<mi, EffectiveTransportOf<mi, transport>, NonNullable<mi['defaults']>> &
461463
MethodExtensions<mi>
462464
}
463465

src/server/internal/html/config.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,14 @@ export function render(options: {
222222
aria-controls="mppx-panel-${i}"
223223
${i !== 0 ? 'tabindex="-1"' : ''}
224224
data-amount="${sanitize(data.formattedAmount)}"
225-
${data.challenge.description
226-
? `data-description="${sanitize(data.challenge.description)}"`
227-
: ''}
228-
${data.challenge.expires
229-
? `data-expires="${sanitize(data.challenge.expires)}"`
230-
: ''}
225+
${
226+
data.challenge.description
227+
? `data-description="${sanitize(data.challenge.description)}"`
228+
: ''
229+
}
230+
${
231+
data.challenge.expires ? `data-expires="${sanitize(data.challenge.expires)}"` : ''
232+
}
231233
${data.challenge.expires ? `data-expires-label="${sanitize(text.expires)}"` : ''}
232234
>
233235
${sanitize(data.label)}
@@ -282,12 +284,16 @@ export function render(options: {
282284
</header>
283285
<section class="${classNames.summary}" aria-label="Payment summary">
284286
<h1 class="${classNames.summaryAmount}">${sanitize(formattedAmount)}</h1>
285-
${firstChallenge.description
286-
? `<p class="${classNames.summaryDescription}">${sanitize(firstChallenge.description)}</p>`
287-
: ''}
288-
${firstChallenge.expires
289-
? `<p class="${classNames.summaryExpires}">${text.expires} <time datetime="${new Date(firstChallenge.expires).toISOString()}">${new Date(firstChallenge.expires).toLocaleString()}</time></p>`
290-
: ''}
287+
${
288+
firstChallenge.description
289+
? `<p class="${classNames.summaryDescription}">${sanitize(firstChallenge.description)}</p>`
290+
: ''
291+
}
292+
${
293+
firstChallenge.expires
294+
? `<p class="${classNames.summaryExpires}">${text.expires} <time datetime="${new Date(firstChallenge.expires).toISOString()}">${new Date(firstChallenge.expires).toLocaleString()}</time></p>`
295+
: ''
296+
}
291297
</section>
292298
${tabListHtml} ${panelsHtml}
293299
<script

src/stripe/Methods.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ describe('charge', () => {
3232
},
3333
})
3434
expect(result.success).toBe(true)
35-
if (result.success) expect(result.data).not.toHaveProperty('paymentIntentOptions')
35+
if (result.success) {
36+
expect(result.data.amount).toBe('100')
37+
expect(result.data).not.toHaveProperty('paymentIntentOptions')
38+
}
3639
})
3740

3841
test('schema: accepts a PaymentIntent options resolver without invoking it', () => {

0 commit comments

Comments
 (0)