@solvapay/react 1.0.8-preview.6 → 1.0.8-preview.7

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 (106) hide show
  1. package/README.md +12 -95
  2. package/dist/CancelPlanButton-Bb7cvym9.d.cts +1105 -0
  3. package/dist/CancelPlanButton-CieT9swn.d.cts +1102 -0
  4. package/dist/CancelPlanButton-Cq117t7h.d.ts +1105 -0
  5. package/dist/CancelPlanButton-f56UlQN-.d.ts +1102 -0
  6. package/dist/PaymentForm-B5dw0i1X.d.ts +934 -0
  7. package/dist/PaymentForm-CesoRQWu.d.cts +934 -0
  8. package/dist/chunk-C7SKOENW.js +1889 -0
  9. package/dist/chunk-ISYAH4ZL.js +1889 -0
  10. package/dist/chunk-MOP3ZBGC.js +4749 -0
  11. package/dist/chunk-Q7GPX6X4.js +4748 -0
  12. package/dist/chunk-TP4JPKE2.js +3126 -0
  13. package/dist/chunk-VTGIXJQU.js +4755 -0
  14. package/dist/chunk-XMQ4GBWQ.js +4752 -0
  15. package/dist/index-DLl3UwO3.d.ts +798 -0
  16. package/dist/index-Sj2lHLl8.d.cts +798 -0
  17. package/dist/index.cjs +11 -25
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +1 -1
  21. package/dist/primitives/index.cjs +4 -21
  22. package/dist/primitives/index.d.cts +2 -2
  23. package/dist/primitives/index.d.ts +2 -2
  24. package/dist/primitives/index.js +1 -1
  25. package/dist/src/PaymentForm.d.ts +56 -0
  26. package/dist/src/PaymentForm.d.ts.map +1 -0
  27. package/dist/src/PaymentForm.js +212 -0
  28. package/dist/src/PaymentForm.js.map +1 -0
  29. package/dist/src/SolvaPayProvider.d.ts +84 -0
  30. package/dist/src/SolvaPayProvider.d.ts.map +1 -0
  31. package/dist/src/SolvaPayProvider.js +537 -0
  32. package/dist/src/SolvaPayProvider.js.map +1 -0
  33. package/dist/src/adapters/auth.d.ts +43 -0
  34. package/dist/src/adapters/auth.d.ts.map +1 -0
  35. package/dist/src/adapters/auth.js +38 -0
  36. package/dist/src/adapters/auth.js.map +1 -0
  37. package/dist/src/components/PlanBadge.d.ts +31 -0
  38. package/dist/src/components/PlanBadge.d.ts.map +1 -0
  39. package/dist/src/components/PlanBadge.js +119 -0
  40. package/dist/src/components/PlanBadge.js.map +1 -0
  41. package/dist/src/components/PlanSelector.d.ts +49 -0
  42. package/dist/src/components/PlanSelector.d.ts.map +1 -0
  43. package/dist/src/components/PlanSelector.js +82 -0
  44. package/dist/src/components/PlanSelector.js.map +1 -0
  45. package/dist/src/components/Spinner.d.ts +10 -0
  46. package/dist/src/components/Spinner.d.ts.map +1 -0
  47. package/dist/src/components/Spinner.js +14 -0
  48. package/dist/src/components/Spinner.js.map +1 -0
  49. package/dist/src/components/StripePaymentFormWrapper.d.ts +17 -0
  50. package/dist/src/components/StripePaymentFormWrapper.d.ts.map +1 -0
  51. package/dist/src/components/StripePaymentFormWrapper.js +158 -0
  52. package/dist/src/components/StripePaymentFormWrapper.js.map +1 -0
  53. package/dist/src/components/SubscriptionGate.d.ts +21 -0
  54. package/dist/src/components/SubscriptionGate.d.ts.map +1 -0
  55. package/dist/src/components/SubscriptionGate.js +32 -0
  56. package/dist/src/components/SubscriptionGate.js.map +1 -0
  57. package/dist/src/hooks/__tests__/useSubscription.test.d.ts +2 -0
  58. package/dist/src/hooks/__tests__/useSubscription.test.d.ts.map +1 -0
  59. package/dist/src/hooks/__tests__/useSubscription.test.js +554 -0
  60. package/dist/src/hooks/__tests__/useSubscription.test.js.map +1 -0
  61. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts +2 -0
  62. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.d.ts.map +1 -0
  63. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js +719 -0
  64. package/dist/src/hooks/__tests__/useSubscriptionStatus.test.js.map +1 -0
  65. package/dist/src/hooks/useCheckout.d.ts +59 -0
  66. package/dist/src/hooks/useCheckout.d.ts.map +1 -0
  67. package/dist/src/hooks/useCheckout.js +138 -0
  68. package/dist/src/hooks/useCheckout.js.map +1 -0
  69. package/dist/src/hooks/useCustomer.d.ts +43 -0
  70. package/dist/src/hooks/useCustomer.d.ts.map +1 -0
  71. package/dist/src/hooks/useCustomer.js +31 -0
  72. package/dist/src/hooks/useCustomer.js.map +1 -0
  73. package/dist/src/hooks/usePlans.d.ts +28 -0
  74. package/dist/src/hooks/usePlans.d.ts.map +1 -0
  75. package/dist/src/hooks/usePlans.js +181 -0
  76. package/dist/src/hooks/usePlans.js.map +1 -0
  77. package/dist/src/hooks/useSolvaPay.d.ts +44 -0
  78. package/dist/src/hooks/useSolvaPay.d.ts.map +1 -0
  79. package/dist/src/hooks/useSolvaPay.js +52 -0
  80. package/dist/src/hooks/useSolvaPay.js.map +1 -0
  81. package/dist/src/hooks/useSubscription.d.ts +46 -0
  82. package/dist/src/hooks/useSubscription.d.ts.map +1 -0
  83. package/dist/src/hooks/useSubscription.js +50 -0
  84. package/dist/src/hooks/useSubscription.js.map +1 -0
  85. package/dist/src/hooks/useSubscriptionStatus.d.ts +19 -0
  86. package/dist/src/hooks/useSubscriptionStatus.d.ts.map +1 -0
  87. package/dist/src/hooks/useSubscriptionStatus.js +68 -0
  88. package/dist/src/hooks/useSubscriptionStatus.js.map +1 -0
  89. package/dist/src/index.d.ts +24 -0
  90. package/dist/src/index.d.ts.map +1 -0
  91. package/dist/src/index.js +26 -0
  92. package/dist/src/index.js.map +1 -0
  93. package/dist/src/types/index.d.ts +339 -0
  94. package/dist/src/types/index.d.ts.map +1 -0
  95. package/dist/src/types/index.js +5 -0
  96. package/dist/src/types/index.js.map +1 -0
  97. package/dist/src/utils/__tests__/subscriptions.test.d.ts +2 -0
  98. package/dist/src/utils/__tests__/subscriptions.test.d.ts.map +1 -0
  99. package/dist/src/utils/__tests__/subscriptions.test.js +121 -0
  100. package/dist/src/utils/__tests__/subscriptions.test.js.map +1 -0
  101. package/dist/src/utils/subscriptions.d.ts +57 -0
  102. package/dist/src/utils/subscriptions.d.ts.map +1 -0
  103. package/dist/src/utils/subscriptions.js +85 -0
  104. package/dist/src/utils/subscriptions.js.map +1 -0
  105. package/dist/tsconfig.tsbuildinfo +1 -0
  106. package/package.json +2 -2
package/README.md CHANGED
@@ -13,57 +13,6 @@ pnpm add @solvapay/react
13
13
  - `react` ^18.2.0 || ^19.0.0
14
14
  - `react-dom` ^18.2.0 || ^19.0.0
15
15
 
16
- ## Tailwind setup
17
-
18
- SolvaPay primitives ship plain CSS. They work with Tailwind v3 and v4
19
- identically. Import `@solvapay/react/styles.css` **after** your Tailwind
20
- entry so the SolvaPay rules resolve above preflight.
21
-
22
- ### Tailwind v4 (recommended for new projects)
23
-
24
- `src/index.css`:
25
-
26
- ```css
27
- @import "tailwindcss";
28
- @import "@solvapay/react/styles.css";
29
- ```
30
-
31
- No `tailwind.config.ts` needed. Theme via `@theme` block if desired.
32
-
33
- ### Tailwind v3 (Lovable, older projects)
34
-
35
- `tailwind.config.ts`:
36
-
37
- ```ts
38
- import type { Config } from 'tailwindcss'
39
-
40
- export default {
41
- content: ['./src/**/*.{ts,tsx}'],
42
- theme: { extend: {} },
43
- plugins: [],
44
- } satisfies Config
45
- ```
46
-
47
- `src/index.css`:
48
-
49
- ```css
50
- @tailwind base;
51
- @tailwind components;
52
- @tailwind utilities;
53
- @import "@solvapay/react/styles.css";
54
- ```
55
-
56
- No `content[]` entry for `@solvapay/react` is needed — primitives don't ship
57
- utility classes. `data-[state=*]:` variants work natively in v3.3+.
58
-
59
- ### CSS loading order
60
-
61
- Always import `@solvapay/react/styles.css` **after** `@tailwind utilities`
62
- (v3) or `@import "tailwindcss"` (v4). SolvaPay rules are unlayered; they beat
63
- Tailwind's preflight when loaded last. See
64
- [`examples/spa-checkout/src/index.css`](../../examples/spa-checkout/src/index.css)
65
- for the canonical demonstration.
66
-
67
16
  ## Quick Start
68
17
 
69
18
  ### Zero-Config Usage (Recommended)
@@ -395,48 +344,23 @@ Displays current product subscription with render props or className pattern.
395
344
 
396
345
  ### PurchaseGate
397
346
 
398
- Controls access to content based on purchase status. Uses a compound
399
- primitive API (`PurchaseGate.Root`, `.Allowed`, `.Blocked`, `.Loading`,
400
- `.Error`). Matching is by stable reference — `productRef` (`prd_*`) and/or
401
- `planRef` (`pln_*`) — never by product or plan name.
402
-
403
- **Root props:**
404
-
405
- - `productRef?: string` - Require an active purchase for this product
406
- - `planRef?: string` - Require an active purchase for this specific plan
407
- - `asChild?: boolean` - Merge onto the consumer element via `Slot`
408
-
409
- Matching precedence:
347
+ Controls access to content based on purchase status.
410
348
 
411
- - If neither is set, any `status === 'active'` purchase allows access
412
- - If only one is set, that field must match on an active purchase
413
- - If both are set, both must match on the **same** active purchase (AND)
414
-
415
- **Example — product-level gating:**
349
+ **Props:**
416
350
 
417
- ```tsx
418
- <PurchaseGate.Root productRef="prd_widget">
419
- <PurchaseGate.Loading>Loading…</PurchaseGate.Loading>
420
- <PurchaseGate.Allowed>
421
- <PremiumContent />
422
- </PurchaseGate.Allowed>
423
- <PurchaseGate.Blocked>
424
- <Paywall />
425
- </PurchaseGate.Blocked>
426
- </PurchaseGate.Root>
427
- ```
351
+ - `requireProduct?: string` - Optional product name to check for an active purchase
352
+ - `children: (props) => React.ReactNode` - Render prop function
428
353
 
429
- **Example — plan-level gating:**
354
+ **Example:**
430
355
 
431
356
  ```tsx
432
- <PurchaseGate.Root planRef="pln_premium">
433
- <PurchaseGate.Allowed>
434
- <PremiumOnlyFeature />
435
- </PurchaseGate.Allowed>
436
- <PurchaseGate.Blocked>
437
- <UpgradePrompt />
438
- </PurchaseGate.Blocked>
439
- </PurchaseGate.Root>
357
+ <PurchaseGate requireProduct="Pro Plan">
358
+ {({ hasAccess, loading, purchases }) => {
359
+ if (loading) return <Loading />
360
+ if (!hasAccess) return <Paywall />
361
+ return <PremiumContent />
362
+ }}
363
+ </PurchaseGate>
440
364
  ```
441
365
 
442
366
  ## Hooks
@@ -451,15 +375,8 @@ const {
451
375
  loading, // Loading state
452
376
  hasPaidPurchase, // Boolean: has any paid purchase
453
377
  activePurchase, // Most recent active purchase
454
- hasPurchase, // (criteria?: { productRef?, planRef? }) => boolean — predicate matching the PurchaseGate.Root shape
455
378
  refetch, // Function to refetch purchases
456
379
  } = usePurchase()
457
-
458
- // Examples — criteria-based checks:
459
- hasPurchase() // any active purchase
460
- hasPurchase({ productRef: 'prd_widget' }) // any active purchase for this product
461
- hasPurchase({ planRef: 'pln_premium' }) // any active purchase for this specific plan
462
- hasPurchase({ productRef: 'prd_widget', planRef: 'pln_premium' }) // both must match the same active purchase
463
380
  ```
464
381
 
465
382
  ### usePlans