@fantastic.dev/better-stripe 0.4.0 → 0.5.0

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.
Files changed (162) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/MIGRATION.md +135 -0
  3. package/README.md +23 -2
  4. package/dist/client/billing/checkout.d.ts.map +1 -1
  5. package/dist/client/billing/checkout.js +22 -8
  6. package/dist/client/billing/checkout.js.map +1 -1
  7. package/dist/client/billing/subscriptionRouting.d.ts +24 -0
  8. package/dist/client/billing/subscriptionRouting.d.ts.map +1 -0
  9. package/dist/client/billing/subscriptionRouting.js +19 -0
  10. package/dist/client/billing/subscriptionRouting.js.map +1 -0
  11. package/dist/client/billing/subscriptions.d.ts +6 -6
  12. package/dist/client/billing/subscriptions.d.ts.map +1 -1
  13. package/dist/client/billing/subscriptions.js +31 -12
  14. package/dist/client/billing/subscriptions.js.map +1 -1
  15. package/dist/client/connect/disputes.js.map +1 -1
  16. package/dist/client/constants.js +1 -1
  17. package/dist/client/core/accountLinks.d.ts +1 -0
  18. package/dist/client/core/accountLinks.d.ts.map +1 -1
  19. package/dist/client/core/accountLinks.js +0 -6
  20. package/dist/client/core/accountLinks.js.map +1 -1
  21. package/dist/client/core/accountStatus.d.ts.map +1 -1
  22. package/dist/client/core/accountStatus.js +23 -8
  23. package/dist/client/core/accountStatus.js.map +1 -1
  24. package/dist/client/index.d.ts +5 -2
  25. package/dist/client/index.d.ts.map +1 -1
  26. package/dist/client/index.js.map +1 -1
  27. package/dist/client/types/documents.d.ts +1 -0
  28. package/dist/client/types/documents.d.ts.map +1 -1
  29. package/dist/client/types/events.d.ts +2 -1
  30. package/dist/client/types/events.d.ts.map +1 -1
  31. package/dist/client/types/options.d.ts +7 -0
  32. package/dist/client/types/options.d.ts.map +1 -1
  33. package/dist/client/utils/stripeDashboardUrl.d.ts.map +1 -1
  34. package/dist/client/utils/webhookEndpoints.d.ts.map +1 -1
  35. package/dist/client/webhooks/handler.d.ts.map +1 -1
  36. package/dist/client/webhooks/handler.js +35 -1
  37. package/dist/client/webhooks/handler.js.map +1 -1
  38. package/dist/client/webhooks/hooks.d.ts +1 -1
  39. package/dist/client/webhooks/hooks.d.ts.map +1 -1
  40. package/dist/client/webhooks/hooks.js +5 -1
  41. package/dist/client/webhooks/hooks.js.map +1 -1
  42. package/dist/client/webhooks/processors.d.ts.map +1 -1
  43. package/dist/client/webhooks/processors.js +12 -2
  44. package/dist/client/webhooks/processors.js.map +1 -1
  45. package/dist/client/webhooks/v2.d.ts.map +1 -1
  46. package/dist/client/webhooks/v2.js +11 -3
  47. package/dist/client/webhooks/v2.js.map +1 -1
  48. package/dist/component/_generated/component.d.ts +8 -0
  49. package/dist/component/_generated/component.d.ts.map +1 -1
  50. package/dist/component/_generated/server.d.ts +7 -1
  51. package/dist/component/_generated/server.d.ts.map +1 -1
  52. package/dist/component/_generated/server.js +2 -1
  53. package/dist/component/_generated/server.js.map +1 -1
  54. package/dist/component/billing/mutations.d.ts +29 -28
  55. package/dist/component/billing/mutations.d.ts.map +1 -1
  56. package/dist/component/billing/mutations.js +1 -0
  57. package/dist/component/billing/mutations.js.map +1 -1
  58. package/dist/component/billing/queries.d.ts +138 -131
  59. package/dist/component/billing/queries.d.ts.map +1 -1
  60. package/dist/component/billing/schema.d.ts +67 -65
  61. package/dist/component/billing/schema.d.ts.map +1 -1
  62. package/dist/component/billing/validators.d.ts +94 -91
  63. package/dist/component/billing/validators.d.ts.map +1 -1
  64. package/dist/component/billing/validators.js +1 -0
  65. package/dist/component/billing/validators.js.map +1 -1
  66. package/dist/component/connect/mutations.d.ts +37 -37
  67. package/dist/component/connect/queries.d.ts +115 -115
  68. package/dist/component/connect/queries.d.ts.map +1 -1
  69. package/dist/component/connect/queries.js +34 -71
  70. package/dist/component/connect/queries.js.map +1 -1
  71. package/dist/component/connect/schema.d.ts +73 -73
  72. package/dist/component/connect/validators.d.ts +119 -119
  73. package/dist/component/connect/validators.d.ts.map +1 -1
  74. package/dist/component/convex.config.d.ts +1 -0
  75. package/dist/component/convex.config.d.ts.map +1 -1
  76. package/dist/component/convex.config.js +2 -1
  77. package/dist/component/convex.config.js.map +1 -1
  78. package/dist/component/core/mutations.d.ts +12 -12
  79. package/dist/component/core/queries.d.ts +34 -34
  80. package/dist/component/core/schema.d.ts +11 -11
  81. package/dist/component/core/validators.d.ts +14 -14
  82. package/dist/component/core/validators.d.ts.map +1 -1
  83. package/dist/component/lib/fees.d.ts +12 -12
  84. package/dist/component/lib/fees.d.ts.map +1 -1
  85. package/dist/component/lib/fees.js +1 -1
  86. package/dist/component/lib/reversals.js.map +1 -1
  87. package/dist/component/products/mutations.d.ts +7 -7
  88. package/dist/component/products/queries.d.ts +33 -33
  89. package/dist/component/products/schema.d.ts +15 -15
  90. package/dist/component/products/validators.d.ts +16 -16
  91. package/dist/component/products/validators.d.ts.map +1 -1
  92. package/dist/component/schema.d.ts +173 -171
  93. package/dist/component/schema.d.ts.map +1 -1
  94. package/dist/component/webhooks/mutations.d.ts +3 -3
  95. package/dist/component/webhooks/queries.d.ts +12 -12
  96. package/dist/component/webhooks/schema.d.ts +7 -7
  97. package/dist/component/webhooks/validators.d.ts +10 -10
  98. package/dist/component/webhooks/validators.d.ts.map +1 -1
  99. package/dist/react/components/AccountCreateCard.js.map +1 -1
  100. package/dist/react/components/BuyerBillingView.js +1 -1
  101. package/dist/react/components/CheckoutSessionProviderWithKey.d.ts +1 -1
  102. package/dist/react/components/DisputeDetail.js +1 -1
  103. package/dist/react/components/DisputesList.js +1 -1
  104. package/dist/react/components/EarningsSummary.js +1 -1
  105. package/dist/react/components/EmbeddedCheckout.d.ts.map +1 -1
  106. package/dist/react/components/EmbeddedCheckout.js +1 -1
  107. package/dist/react/components/EmbeddedCheckout.js.map +1 -1
  108. package/dist/react/components/PayoutSchedule.js +1 -1
  109. package/dist/react/components/SplitBreakdown.js +1 -1
  110. package/dist/react/components/StripeProvider.d.ts +1 -1
  111. package/dist/react/components/StripeProviderWithKey.d.ts +1 -1
  112. package/dist/react/hooks/useAccount.d.ts.map +1 -1
  113. package/dist/react/hooks/useAccountOnboarding.d.ts.map +1 -1
  114. package/dist/react/hooks/useCheckout.d.ts.map +1 -1
  115. package/dist/react/hooks/useDisputeWithCountdown.d.ts.map +1 -1
  116. package/dist/react/hooks/useDisputes.d.ts.map +1 -1
  117. package/dist/react/hooks/useEarnings.d.ts.map +1 -1
  118. package/dist/react/hooks/useInvoices.d.ts.map +1 -1
  119. package/dist/react/hooks/usePaymentMethodActions.js.map +1 -1
  120. package/dist/react/hooks/usePaymentMethods.d.ts.map +1 -1
  121. package/dist/react/hooks/usePrices.d.ts.map +1 -1
  122. package/dist/react/hooks/useProducts.d.ts.map +1 -1
  123. package/dist/react/hooks/useSplitBreakdown.d.ts.map +1 -1
  124. package/dist/react/hooks/useSubscription.d.ts.map +1 -1
  125. package/dist/react/hooks/useSubscriptions.d.ts.map +1 -1
  126. package/dist/react/lib/stripe-element-styles.d.ts.map +1 -1
  127. package/dist/react/lib/stripe-element-styles.js.map +1 -1
  128. package/package.json +25 -23
  129. package/src/client/billing/checkout.test.ts +62 -14
  130. package/src/client/billing/checkout.ts +26 -10
  131. package/src/client/billing/subscriptionRouting.ts +25 -0
  132. package/src/client/billing/subscriptions.test.ts +90 -28
  133. package/src/client/billing/subscriptions.ts +53 -18
  134. package/src/client/constants.ts +1 -1
  135. package/src/client/core/accountLinks.test.ts +20 -13
  136. package/src/client/core/accountLinks.ts +2 -10
  137. package/src/client/core/accountStatus.test.ts +67 -0
  138. package/src/client/core/accountStatus.ts +30 -13
  139. package/src/client/helpers.test.ts +2 -2
  140. package/src/client/index.ts +49 -44
  141. package/src/client/stripe-version.test.ts +47 -0
  142. package/src/client/types/documents.ts +1 -0
  143. package/src/client/types/events.ts +2 -1
  144. package/src/client/types/options.ts +7 -0
  145. package/src/client/webhooks/handler.ts +38 -1
  146. package/src/client/webhooks/hooks.ts +3 -0
  147. package/src/client/webhooks/processors.test.ts +201 -40
  148. package/src/client/webhooks/processors.ts +21 -17
  149. package/src/client/webhooks/retry.integration.test.ts +196 -0
  150. package/src/client/webhooks/v2.test.ts +36 -0
  151. package/src/client/webhooks/v2.ts +14 -4
  152. package/src/component/_generated/component.ts +15 -28
  153. package/src/component/_generated/server.ts +9 -2
  154. package/src/component/billing/mutations.ts +1 -0
  155. package/src/component/billing/validators.ts +1 -0
  156. package/src/component/config-queries.test.ts +8 -4
  157. package/src/component/connect/queries.ts +31 -66
  158. package/src/component/convex.config.ts +2 -1
  159. package/src/component/earnings-totals.test.ts +27 -1
  160. package/src/component/lib/fees.ts +1 -1
  161. package/src/react/components/EmbeddedCheckout.render.test.tsx +57 -0
  162. package/src/react/components/EmbeddedCheckout.tsx +1 -0
@@ -3,7 +3,7 @@
3
3
  * Tests for the earnings AGGREGATE queries (BTS-64). The row-list queries
4
4
  * (`listTransfersByAccount`, `listPayouts`) `.take(50)`, so a busy account's
5
5
  * earnings totals were silently truncated when summed client-side. These
6
- * aggregate queries paginate the account's ledger to completion and return
6
+ * aggregate queries iterate the account's ledger to completion and return
7
7
  * EXACT gross/reversed/paidOut regardless of row count, plus a bounded preview
8
8
  * of rows for drill-down UIs.
9
9
  */
@@ -12,6 +12,7 @@ import { describe, expect, it } from "vitest";
12
12
 
13
13
  import { api } from "./_generated/api.js";
14
14
  import schema from "./schema.js";
15
+ import { getAccountEarnings, getAccountPayouts } from "./connect/queries.js";
15
16
 
16
17
  const modules = import.meta.glob("./**/*.*s");
17
18
 
@@ -194,3 +195,28 @@ describe("getAccountPayouts — exact paidOut past the 50-row cap (BTS-64)", ()
194
195
  expect(result.paidOut).toBe(210 * 100);
195
196
  });
196
197
  });
198
+
199
+ // convex-test does not enforce production document/byte read limits. Simulate
200
+ // a database iterator reaching that boundary after a row has been accumulated.
201
+ // The aggregate must reject rather than exposing the partial financial total.
202
+ describe("aggregate read-limit failures (BTS-116)", () => {
203
+ it.each([
204
+ ["earnings", getAccountEarnings, { destinationAccountId: "acct_limit" }],
205
+ ["payouts", getAccountPayouts, { accountId: "acct_limit" }],
206
+ ])("rejects incomplete %s totals", async (_name, query, args) => {
207
+ const readLimit = new Error(
208
+ "Too many documents read in a single function execution",
209
+ );
210
+ const rows = {
211
+ async *[Symbol.asyncIterator]() {
212
+ yield { amount: 100, reversedAmount: 10, status: "paid" };
213
+ throw readLimit;
214
+ },
215
+ };
216
+ const ctx = { db: { query: () => ({ withIndex: () => rows }) } };
217
+ const registered = query as unknown as {
218
+ _handler: (ctx: unknown, args: unknown) => Promise<unknown>;
219
+ };
220
+ await expect(registered._handler(ctx, args)).rejects.toBe(readLimit);
221
+ });
222
+ });
@@ -28,7 +28,7 @@ export type SplitRecipientRole = Infer<typeof splitRecipientRoleValidator>;
28
28
 
29
29
  /**
30
30
  * One destination in a multi-recipient split. The cut is expressed as either a
31
- * fixed `amount` (minor units) or a `percent` of the net; the resolver (BTS-14)
31
+ * fixed `amount` (minor units) or a `percent` of the gross charge; the resolver (BTS-14)
32
32
  * decides precedence. App-owned attribution (who the affiliate is) lives in app
33
33
  * tables — the component just records and executes the split.
34
34
  */
@@ -0,0 +1,57 @@
1
+ // @vitest-environment jsdom
2
+ import { cleanup, render, waitFor } from "@testing-library/react";
3
+ import { afterEach, expect, it, vi } from "vitest";
4
+
5
+ import { EmbeddedCheckout } from "./EmbeddedCheckout.js";
6
+
7
+ const { createEmbeddedCheckoutPage, mount, destroy } = vi.hoisted(() => ({
8
+ createEmbeddedCheckoutPage: vi.fn(),
9
+ mount: vi.fn(),
10
+ destroy: vi.fn(),
11
+ }));
12
+ vi.mock("@stripe/stripe-js", () => ({
13
+ loadStripe: () =>
14
+ Promise.resolve({
15
+ createEmbeddedCheckoutPage,
16
+ // React Stripe.js validates a Stripe instance with these methods.
17
+ elements: vi.fn(),
18
+ createToken: vi.fn(),
19
+ createPaymentMethod: vi.fn(),
20
+ confirmCardPayment: vi.fn(),
21
+ }),
22
+ }));
23
+ afterEach(() => {
24
+ cleanup();
25
+ vi.clearAllMocks();
26
+ });
27
+
28
+ it("mounts through the current Stripe.js API, forwards completion, and remounts a new session", async () => {
29
+ createEmbeddedCheckoutPage.mockResolvedValue({ mount, destroy });
30
+ const onComplete = vi.fn();
31
+ const view = render(
32
+ <EmbeddedCheckout
33
+ publishableKey="pk_test_local"
34
+ clientSecret="cs_first_secret"
35
+ onComplete={onComplete}
36
+ />,
37
+ );
38
+ await waitFor(() => expect(mount).toHaveBeenCalledTimes(1));
39
+ const firstOptions = createEmbeddedCheckoutPage.mock.calls[0][0];
40
+ expect(await firstOptions.fetchClientSecret()).toBe("cs_first_secret");
41
+ firstOptions.onComplete();
42
+ expect(onComplete).toHaveBeenCalledTimes(1);
43
+ view.rerender(
44
+ <EmbeddedCheckout
45
+ publishableKey="pk_test_local"
46
+ clientSecret="cs_second_secret"
47
+ onComplete={onComplete}
48
+ />,
49
+ );
50
+ await waitFor(() => expect(mount).toHaveBeenCalledTimes(2));
51
+ expect(destroy).toHaveBeenCalledTimes(1);
52
+ expect(
53
+ await createEmbeddedCheckoutPage.mock.calls[1][0].fetchClientSecret(),
54
+ ).toBe("cs_second_secret");
55
+ view.unmount();
56
+ expect(destroy).toHaveBeenCalledTimes(2);
57
+ });
@@ -44,6 +44,7 @@ export function EmbeddedCheckout({
44
44
  return (
45
45
  <div className={className}>
46
46
  <EmbeddedCheckoutProvider
47
+ key={`${publishableKey}:${clientSecret}`}
47
48
  stripe={stripePromise}
48
49
  options={{ fetchClientSecret, onComplete }}
49
50
  >