@fantastic.dev/better-stripe 0.83.0 → 0.83.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/couponJoins.d.ts +1 -1
- package/dist/client/billing/renewalAttach/couponJoins.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/couponJoins.js +3 -3
- package/dist/client/billing/renewalAttach/couponJoins.js.map +1 -1
- package/dist/client/billing/renewalAttach/reader.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/reader.js +5 -8
- package/dist/client/billing/renewalAttach/reader.js.map +1 -1
- package/dist/client/billing/renewalAttach/wireJson.d.ts +24 -0
- package/dist/client/billing/renewalAttach/wireJson.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/wireJson.js +51 -0
- package/dist/client/billing/renewalAttach/wireJson.js.map +1 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/client/helpers.d.ts.map +1 -1
- package/dist/client/helpers.js +2 -2
- package/dist/client/helpers.js.map +1 -1
- package/dist/client/singleAttemptHttpClient.d.ts +1 -1
- package/dist/client/singleAttemptHttpClient.d.ts.map +1 -1
- package/dist/client/singleAttemptHttpClient.js +1 -1
- package/dist/client/singleAttemptHttpClient.js.map +1 -1
- package/dist/client/strictStripeTransport.d.ts +4 -0
- package/dist/client/strictStripeTransport.d.ts.map +1 -0
- package/dist/client/strictStripeTransport.js +7 -0
- package/dist/client/strictStripeTransport.js.map +1 -0
- package/dist/client/usage/observationClient.d.ts +2 -2
- package/dist/client/usage/observationClient.d.ts.map +1 -1
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +16 -16
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +33 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/couponEvidence.test.ts +1 -2
- package/src/client/billing/renewalAttach/couponJoins.ts +2 -5
- package/src/client/billing/renewalAttach/reader.test.ts +1 -1
- package/src/client/billing/renewalAttach/reader.ts +6 -12
- package/src/client/billing/renewalAttach/wireJson.test.ts +265 -0
- package/src/client/billing/renewalAttach/wireJson.ts +75 -0
- package/src/client/helpers.ts +2 -4
- package/src/client/singleAttemptHttpClient.ts +1 -1
- package/src/client/strictStripeTransport.test.ts +73 -0
- package/src/client/strictStripeTransport.ts +11 -0
|
@@ -12,7 +12,7 @@ class SingleAttemptConnectionClosed extends Error {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/** Guard for Stripe's closed-connection retry exception. */
|
|
16
16
|
export class SingleAttemptHttpClient implements Stripe.HttpClient {
|
|
17
17
|
constructor(private readonly delegate: Stripe.HttpClient) {}
|
|
18
18
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { afterEach, it, expect, vi } from "vitest";
|
|
2
|
+
import Stripe from "stripe";
|
|
3
|
+
import { createServer } from "node:http";
|
|
4
|
+
import { getStripeClient } from "./helpers.js";
|
|
5
|
+
afterEach(() => vi.restoreAllMocks());
|
|
6
|
+
it.each([307, 308])(
|
|
7
|
+
"shared singleAttempt factory sends onlyone POST on%s redirect",
|
|
8
|
+
async (status) => {
|
|
9
|
+
const requests: { path: string; method: string }[] = [];
|
|
10
|
+
const server = createServer((req, res) => {
|
|
11
|
+
requests.push({ path: req.url!, method: req.method! });
|
|
12
|
+
req.resume();
|
|
13
|
+
if (req.url?.startsWith("/v1/")) {
|
|
14
|
+
res.writeHead(status, { Location: "/redirected" });
|
|
15
|
+
res.end();
|
|
16
|
+
} else {
|
|
17
|
+
res.writeHead(200, { "content-type": "application/json" });
|
|
18
|
+
res.end(
|
|
19
|
+
JSON.stringify({
|
|
20
|
+
id: "sub_sched_controlled",
|
|
21
|
+
object: "subscription_schedule",
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
await new Promise<void>((r) => server.listen(0, "127.0.0.1", r));
|
|
27
|
+
const addr = server.address();
|
|
28
|
+
if (!addr || typeof addr === "string") throw Error("missingephemeralport");
|
|
29
|
+
const original = Stripe.createFetchHttpClient.bind(Stripe);
|
|
30
|
+
// Public Fetchfactory seam rewrites ONLY ownedloopback destination. The tested
|
|
31
|
+
// factory owns redirectmode; this fixture deliberately does not set it.
|
|
32
|
+
vi.spyOn(Stripe, "createFetchHttpClient").mockImplementation((fetchFn) =>
|
|
33
|
+
original((url, init) => {
|
|
34
|
+
const local = new URL(String(url));
|
|
35
|
+
local.protocol = "http:";
|
|
36
|
+
local.hostname = "127.0.0.1";
|
|
37
|
+
local.port = String(addr.port);
|
|
38
|
+
return (fetchFn ?? fetch)(local.toString(), init);
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
try {
|
|
42
|
+
const stripe = getStripeClient(
|
|
43
|
+
"sk_test_CONTROLLED_SHARED_" + status,
|
|
44
|
+
"2026-09-30.endive",
|
|
45
|
+
{ singleAttempt: true },
|
|
46
|
+
);
|
|
47
|
+
await expect(
|
|
48
|
+
stripe.subscriptionSchedules.update(
|
|
49
|
+
"sub_sched_controlled",
|
|
50
|
+
{ end_behavior: "release" },
|
|
51
|
+
{ maxNetworkRetries: 0, idempotencyKey: "retained-controlled-key" },
|
|
52
|
+
),
|
|
53
|
+
).rejects.toMatchObject({ type: "StripeConnectionError" });
|
|
54
|
+
expect(requests).toEqual([
|
|
55
|
+
{
|
|
56
|
+
path: "/v1/subscription_schedules/sub_sched_controlled",
|
|
57
|
+
method: "POST",
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
} finally {
|
|
61
|
+
server.closeAllConnections();
|
|
62
|
+
await new Promise<void>((resolve, reject) =>
|
|
63
|
+
server.close((error) => (error ? reject(error) : resolve())),
|
|
64
|
+
);
|
|
65
|
+
expect(server.listening).toBe(false);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
it("ordinary cached client remains on its normal transport factory path", () => {
|
|
70
|
+
const factory = vi.spyOn(Stripe, "createFetchHttpClient");
|
|
71
|
+
getStripeClient("sk_test_CONTROLLED_ORDINARY_UNCHANGED", "2026-09-30.endive");
|
|
72
|
+
expect(factory).not.toHaveBeenCalled();
|
|
73
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Stripe from "stripe";
|
|
2
|
+
import { SingleAttemptHttpClient } from "./singleAttemptHttpClient.js";
|
|
3
|
+
|
|
4
|
+
/** No fetch redirect replay, plus the Stripe closed-connection retry guard. */
|
|
5
|
+
export function createSingleAttemptHttpClient(): Stripe.HttpClient {
|
|
6
|
+
return new SingleAttemptHttpClient(
|
|
7
|
+
Stripe.createFetchHttpClient((input, init) =>
|
|
8
|
+
fetch(input, { ...init, redirect: "error" }),
|
|
9
|
+
),
|
|
10
|
+
);
|
|
11
|
+
}
|