subos-frontend 1.0.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.
- package/LIBRARY_USAGE.md +162 -0
- package/README.md +396 -0
- package/dist/index.js +2289 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2220 -0
- package/dist/index.mjs.map +1 -0
- package/dist/style.css +1684 -0
- package/dist/types/App.d.ts +2 -0
- package/dist/types/App.d.ts.map +1 -0
- package/dist/types/api/client.d.ts +49 -0
- package/dist/types/api/client.d.ts.map +1 -0
- package/dist/types/api/config.d.ts +16 -0
- package/dist/types/api/config.d.ts.map +1 -0
- package/dist/types/components/LogoInline.d.ts +8 -0
- package/dist/types/components/LogoInline.d.ts.map +1 -0
- package/dist/types/components/common/Layout.d.ts +7 -0
- package/dist/types/components/common/Layout.d.ts.map +1 -0
- package/dist/types/components/email/EmailEntry.d.ts +10 -0
- package/dist/types/components/email/EmailEntry.d.ts.map +1 -0
- package/dist/types/components/email/index.d.ts +3 -0
- package/dist/types/components/email/index.d.ts.map +1 -0
- package/dist/types/components/icons/CheckIcon.d.ts +6 -0
- package/dist/types/components/icons/CheckIcon.d.ts.map +1 -0
- package/dist/types/components/icons/CommonIcons.d.ts +21 -0
- package/dist/types/components/icons/CommonIcons.d.ts.map +1 -0
- package/dist/types/components/pagination/Pagination.d.ts +12 -0
- package/dist/types/components/pagination/Pagination.d.ts.map +1 -0
- package/dist/types/components/pagination/index.d.ts +3 -0
- package/dist/types/components/pagination/index.d.ts.map +1 -0
- package/dist/types/components/payments/ChangeCardButton.d.ts +10 -0
- package/dist/types/components/payments/ChangeCardButton.d.ts.map +1 -0
- package/dist/types/components/payments/PaymentCancelView.d.ts +8 -0
- package/dist/types/components/payments/PaymentCancelView.d.ts.map +1 -0
- package/dist/types/components/payments/PaymentSuccessView.d.ts +8 -0
- package/dist/types/components/payments/PaymentSuccessView.d.ts.map +1 -0
- package/dist/types/components/payments/index.d.ts +5 -0
- package/dist/types/components/payments/index.d.ts.map +1 -0
- package/dist/types/components/plans/BillingCycleToggle.d.ts +7 -0
- package/dist/types/components/plans/BillingCycleToggle.d.ts.map +1 -0
- package/dist/types/components/plans/PlanCard.d.ts +11 -0
- package/dist/types/components/plans/PlanCard.d.ts.map +1 -0
- package/dist/types/components/plans/PlanSelector.d.ts +19 -0
- package/dist/types/components/plans/PlanSelector.d.ts.map +1 -0
- package/dist/types/components/plans/PlansGrid.d.ts +13 -0
- package/dist/types/components/plans/PlansGrid.d.ts.map +1 -0
- package/dist/types/components/plans/TierFilterDropdown.d.ts +12 -0
- package/dist/types/components/plans/TierFilterDropdown.d.ts.map +1 -0
- package/dist/types/components/plans/index.d.ts +11 -0
- package/dist/types/components/plans/index.d.ts.map +1 -0
- package/dist/types/components/subscription/SubscriptionDetails.d.ts +11 -0
- package/dist/types/components/subscription/SubscriptionDetails.d.ts.map +1 -0
- package/dist/types/components/subscription/index.d.ts +3 -0
- package/dist/types/components/subscription/index.d.ts.map +1 -0
- package/dist/types/components/transaction/TransactionList.d.ts +11 -0
- package/dist/types/components/transaction/TransactionList.d.ts.map +1 -0
- package/dist/types/components/transaction/TransactionModal.d.ts +9 -0
- package/dist/types/components/transaction/TransactionModal.d.ts.map +1 -0
- package/dist/types/components/transaction/index.d.ts +5 -0
- package/dist/types/components/transaction/index.d.ts.map +1 -0
- package/dist/types/components/upgrade/UpgradeSummary.d.ts +8 -0
- package/dist/types/components/upgrade/UpgradeSummary.d.ts.map +1 -0
- package/dist/types/components/upgrade/index.d.ts +3 -0
- package/dist/types/components/upgrade/index.d.ts.map +1 -0
- package/dist/types/config/envConfig.d.ts +36 -0
- package/dist/types/config/envConfig.d.ts.map +1 -0
- package/dist/types/hooks/index.d.ts +15 -0
- package/dist/types/hooks/index.d.ts.map +1 -0
- package/dist/types/hooks/payments/usePaymentParams.d.ts +8 -0
- package/dist/types/hooks/payments/usePaymentParams.d.ts.map +1 -0
- package/dist/types/hooks/payments/useProcessPaymentCancel.d.ts +8 -0
- package/dist/types/hooks/payments/useProcessPaymentCancel.d.ts.map +1 -0
- package/dist/types/hooks/payments/useProcessPaymentSuccess.d.ts +8 -0
- package/dist/types/hooks/payments/useProcessPaymentSuccess.d.ts.map +1 -0
- package/dist/types/hooks/useCancelSubscription.d.ts +16 -0
- package/dist/types/hooks/useCancelSubscription.d.ts.map +1 -0
- package/dist/types/hooks/useCustomerPortal.d.ts +12 -0
- package/dist/types/hooks/useCustomerPortal.d.ts.map +1 -0
- package/dist/types/hooks/useEmailManagement.d.ts +13 -0
- package/dist/types/hooks/useEmailManagement.d.ts.map +1 -0
- package/dist/types/hooks/usePagination.d.ts +20 -0
- package/dist/types/hooks/usePagination.d.ts.map +1 -0
- package/dist/types/hooks/usePlans.d.ts +22 -0
- package/dist/types/hooks/usePlans.d.ts.map +1 -0
- package/dist/types/hooks/useSubscription.d.ts +10 -0
- package/dist/types/hooks/useSubscription.d.ts.map +1 -0
- package/dist/types/hooks/useTransactions.d.ts +26 -0
- package/dist/types/hooks/useTransactions.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/pages/DashboardPage.d.ts +3 -0
- package/dist/types/pages/DashboardPage.d.ts.map +1 -0
- package/dist/types/pages/PaymentCancelPage.d.ts +4 -0
- package/dist/types/pages/PaymentCancelPage.d.ts.map +1 -0
- package/dist/types/pages/PaymentSuccessPage.d.ts +4 -0
- package/dist/types/pages/PaymentSuccessPage.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +117 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/planUtils.d.ts +47 -0
- package/dist/types/utils/planUtils.d.ts.map +1 -0
- package/package.json +74 -0
package/LIBRARY_USAGE.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# SubOS Frontend Library Usage
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install subos-frontend
|
|
7
|
+
# or
|
|
8
|
+
yarn add subos-frontend
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Required Peer Dependencies
|
|
12
|
+
|
|
13
|
+
Make sure your project has these dependencies installed:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install react react-dom react-router-dom @stripe/react-stripe-js @stripe/stripe-js
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Configuration (REQUIRED)
|
|
20
|
+
|
|
21
|
+
**⚠️ Important:** You MUST configure SubOS before using any components, otherwise you'll get runtime errors.
|
|
22
|
+
|
|
23
|
+
### Method 1: Runtime Configuration (Recommended)
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import { configureSubOS } from 'subos-frontend';
|
|
27
|
+
|
|
28
|
+
// Configure SubOS at the root of your app (e.g., in main.jsx, _app.js, or App.jsx)
|
|
29
|
+
configureSubOS({
|
|
30
|
+
apiEndpoint: 'https://your-api.com/api/v1',
|
|
31
|
+
projectId: 'your-project-id',
|
|
32
|
+
stripePublishableKey: 'pk_test_your_stripe_key',
|
|
33
|
+
appName: 'Your App Name',
|
|
34
|
+
appEnvironment: 'production' // or 'development'
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Method 2: Environment Variables
|
|
39
|
+
|
|
40
|
+
Set these environment variables in your project:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# .env or .env.local
|
|
44
|
+
VITE_API_ENDPOINT=https://your-api.com/api/v1
|
|
45
|
+
VITE_PROJECT_ID=your-project-id
|
|
46
|
+
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_key
|
|
47
|
+
VITE_APP_NAME=Your App Name
|
|
48
|
+
VITE_APP_ENVIRONMENT=production
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Usage Examples
|
|
52
|
+
|
|
53
|
+
### Basic Component Usage
|
|
54
|
+
|
|
55
|
+
```jsx
|
|
56
|
+
import React from 'react';
|
|
57
|
+
import { PlansList, configureSubOS } from 'subos-frontend';
|
|
58
|
+
import 'subos-frontend/style.css';
|
|
59
|
+
|
|
60
|
+
// Configure first (do this once at app startup)
|
|
61
|
+
configureSubOS({
|
|
62
|
+
apiEndpoint: 'https://your-api.com/api/v1',
|
|
63
|
+
projectId: 'your-project-id',
|
|
64
|
+
stripePublishableKey: 'pk_test_your_stripe_key'
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function MyPlansPage() {
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<h1>Choose Your Plan</h1>
|
|
71
|
+
<PlansList />
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Validation
|
|
78
|
+
|
|
79
|
+
```jsx
|
|
80
|
+
import { validateSubOSConfig, ensureSubOSConfig } from 'subos-frontend';
|
|
81
|
+
|
|
82
|
+
// Check if configuration is valid
|
|
83
|
+
const validation = validateSubOSConfig();
|
|
84
|
+
if (!validation.isValid) {
|
|
85
|
+
console.error('Missing config:', validation.missingFields);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Or throw an error if config is invalid
|
|
89
|
+
try {
|
|
90
|
+
ensureSubOSConfig();
|
|
91
|
+
// Safe to use SubOS components here
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('SubOS not configured:', error.message);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Next.js Setup
|
|
98
|
+
|
|
99
|
+
```jsx
|
|
100
|
+
// pages/_app.js or app/layout.js
|
|
101
|
+
import { configureSubOS } from 'subos-frontend';
|
|
102
|
+
import 'subos-frontend/style.css';
|
|
103
|
+
|
|
104
|
+
// Configure SubOS once at app startup
|
|
105
|
+
configureSubOS({
|
|
106
|
+
apiEndpoint: process.env.NEXT_PUBLIC_API_ENDPOINT,
|
|
107
|
+
projectId: process.env.NEXT_PUBLIC_PROJECT_ID,
|
|
108
|
+
stripePublishableKey: process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
export default function MyApp({ Component, pageProps }) {
|
|
112
|
+
return <Component {...pageProps} />;
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Vite/React Setup
|
|
117
|
+
|
|
118
|
+
```jsx
|
|
119
|
+
// main.jsx or App.jsx
|
|
120
|
+
import { configureSubOS } from 'subos-frontend';
|
|
121
|
+
import 'subos-frontend/style.css';
|
|
122
|
+
|
|
123
|
+
configureSubOS({
|
|
124
|
+
apiEndpoint: import.meta.env.VITE_API_ENDPOINT,
|
|
125
|
+
projectId: import.meta.env.VITE_PROJECT_ID,
|
|
126
|
+
stripePublishableKey: import.meta.env.VITE_STRIPE_PUBLISHABLE_KEY,
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Available Components
|
|
131
|
+
|
|
132
|
+
- `PlansList` - Display available subscription plans
|
|
133
|
+
- `CheckoutForm` - Handle subscription checkout
|
|
134
|
+
- `SubscriptionManager` - Manage existing subscriptions
|
|
135
|
+
- `TransactionHistory` - Display transaction history
|
|
136
|
+
- `PaymentMethods` - Manage payment methods
|
|
137
|
+
|
|
138
|
+
## Troubleshooting
|
|
139
|
+
|
|
140
|
+
### "Cannot read properties of undefined (reading 'VITE_API_ENDPOINT')"
|
|
141
|
+
|
|
142
|
+
This error occurs when SubOS is not properly configured. Make sure to:
|
|
143
|
+
|
|
144
|
+
1. Call `configureSubOS()` before using any SubOS components
|
|
145
|
+
2. Provide all required configuration values
|
|
146
|
+
3. Import and configure SubOS at the root of your application
|
|
147
|
+
|
|
148
|
+
### Missing Peer Dependencies
|
|
149
|
+
|
|
150
|
+
If you get errors about missing React or Stripe dependencies, install them:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
npm install react react-dom react-router-dom @stripe/react-stripe-js @stripe/stripe-js
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## TypeScript Support
|
|
157
|
+
|
|
158
|
+
The library includes full TypeScript support. Import types as needed:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import type { ConfigureSubOSInput, EnvConfig } from 'subos-frontend';
|
|
162
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
# SubOS Frontend - React Component Library
|
|
2
|
+
|
|
3
|
+
A comprehensive React component library for subscription management, billing, and payment processing. SubOS Frontend provides a collection of reusable UI components designed to be integrated into React applications for managing subscriptions, pricing, billing, and account logic.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **Plan Management Components** - Browse, select, and display subscription plans
|
|
8
|
+
- **Payment Processing** - Stripe-integrated payment components and flows
|
|
9
|
+
- **Subscription Management** - View, manage, and cancel subscriptions
|
|
10
|
+
- **Transaction History** - Display payment history and invoices
|
|
11
|
+
- **Billing Components** - Handle billing cycles, pricing tiers, and coupons
|
|
12
|
+
- **TypeScript Support** - Full TypeScript definitions included
|
|
13
|
+
- **Modern UI** - Clean, responsive components built with Tailwind CSS
|
|
14
|
+
- **Tree Shaking** - Optimized bundle size with ESM support
|
|
15
|
+
|
|
16
|
+
## 📦 Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install subos-frontend
|
|
20
|
+
# or
|
|
21
|
+
yarn add subos-frontend
|
|
22
|
+
# or
|
|
23
|
+
pnpm add subos-frontend
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 🎯 Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Import Styles
|
|
29
|
+
|
|
30
|
+
Import the CSS file in your app's entry point:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import 'subos-frontend/style.css';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Configure SubOS
|
|
37
|
+
|
|
38
|
+
You have two options to configure the library:
|
|
39
|
+
|
|
40
|
+
#### Option A: Runtime Configuration (Recommended)
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { configureSubOS } from 'subos-frontend';
|
|
44
|
+
|
|
45
|
+
configureSubOS({
|
|
46
|
+
apiEndpoint: 'https://your-api.com/api/v1',
|
|
47
|
+
projectId: 'your-project-id',
|
|
48
|
+
stripePublishableKey: 'pk_live_xxx', // Optional, for payment features
|
|
49
|
+
appName: 'Your App Name',
|
|
50
|
+
appEnvironment: 'production'
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
#### Option B: Environment Variables
|
|
55
|
+
|
|
56
|
+
Create a `.env` file in your project root (copy from `.env.example` included in the package):
|
|
57
|
+
|
|
58
|
+
```env
|
|
59
|
+
VITE_API_ENDPOINT=https://your-api.com/api/v1
|
|
60
|
+
VITE_PROJECT_ID=your-project-id
|
|
61
|
+
VITE_STRIPE_PUBLISHABLE_KEY=pk_live_xxx
|
|
62
|
+
VITE_APP_NAME=Your App Name
|
|
63
|
+
VITE_APP_ENVIRONMENT=production
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Use Components
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { PlanCard, PlansGrid, SubscriptionDetails } from 'subos-frontend';
|
|
70
|
+
|
|
71
|
+
function MyApp() {
|
|
72
|
+
return (
|
|
73
|
+
<div>
|
|
74
|
+
<PlansGrid
|
|
75
|
+
plans={plans}
|
|
76
|
+
onPlanSelect={handlePlanSelect}
|
|
77
|
+
billingCycle="monthly"
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## 🧩 Available Components
|
|
85
|
+
|
|
86
|
+
### Plan Components
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import {
|
|
90
|
+
PlanCard,
|
|
91
|
+
PlansGrid,
|
|
92
|
+
PlanSelector,
|
|
93
|
+
BillingCycleToggle,
|
|
94
|
+
TierFilterDropdown
|
|
95
|
+
} from 'subos-frontend';
|
|
96
|
+
|
|
97
|
+
// Display individual plan
|
|
98
|
+
<PlanCard
|
|
99
|
+
plan={plan}
|
|
100
|
+
isSelected={false}
|
|
101
|
+
billingCycle="monthly"
|
|
102
|
+
onSelect={handleSelect}
|
|
103
|
+
/>
|
|
104
|
+
|
|
105
|
+
// Display grid of plans
|
|
106
|
+
<PlansGrid
|
|
107
|
+
plans={plans}
|
|
108
|
+
selectedPlan={selectedPlan}
|
|
109
|
+
billingCycle="monthly"
|
|
110
|
+
onPlanSelect={handlePlanSelect}
|
|
111
|
+
/>
|
|
112
|
+
|
|
113
|
+
// Billing cycle toggle
|
|
114
|
+
<BillingCycleToggle
|
|
115
|
+
value="monthly"
|
|
116
|
+
onChange={handleCycleChange}
|
|
117
|
+
/>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Payment Components
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
import {
|
|
124
|
+
PaymentSuccessView,
|
|
125
|
+
PaymentCancelView,
|
|
126
|
+
ChangeCardButton
|
|
127
|
+
} from 'subos-frontend';
|
|
128
|
+
|
|
129
|
+
// Payment result pages
|
|
130
|
+
<PaymentSuccessView />
|
|
131
|
+
<PaymentCancelView />
|
|
132
|
+
|
|
133
|
+
// Change payment method
|
|
134
|
+
<ChangeCardButton onCardChange={handleCardChange} />
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Subscription Components
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { SubscriptionDetails } from 'subos-frontend';
|
|
141
|
+
|
|
142
|
+
<SubscriptionDetails
|
|
143
|
+
subscription={subscription}
|
|
144
|
+
onCancel={handleCancel}
|
|
145
|
+
onUpgrade={handleUpgrade}
|
|
146
|
+
/>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Transaction Components
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { TransactionList, TransactionModal } from 'subos-frontend';
|
|
153
|
+
|
|
154
|
+
<TransactionList
|
|
155
|
+
transactions={transactions}
|
|
156
|
+
onViewInvoice={handleViewInvoice}
|
|
157
|
+
/>
|
|
158
|
+
|
|
159
|
+
<TransactionModal
|
|
160
|
+
transaction={transaction}
|
|
161
|
+
isOpen={isModalOpen}
|
|
162
|
+
onClose={handleClose}
|
|
163
|
+
/>
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Utility Components
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { Layout, LogoInline, CheckIcon, Pagination } from 'subos-frontend';
|
|
170
|
+
|
|
171
|
+
// Layout wrapper
|
|
172
|
+
<Layout>
|
|
173
|
+
<YourContent />
|
|
174
|
+
</Layout>
|
|
175
|
+
|
|
176
|
+
// Pagination
|
|
177
|
+
<Pagination
|
|
178
|
+
currentPage={1}
|
|
179
|
+
totalPages={10}
|
|
180
|
+
onPageChange={handlePageChange}
|
|
181
|
+
/>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## ⚙️ Environment Configuration
|
|
185
|
+
|
|
186
|
+
### Configuration Options
|
|
187
|
+
|
|
188
|
+
| Variable | Description | Required | Default |
|
|
189
|
+
|----------|-------------|----------|---------|
|
|
190
|
+
| `VITE_API_ENDPOINT` | Your SubOS backend API URL | ✅ | `http://localhost:3002/api/v1` |
|
|
191
|
+
| `VITE_PROJECT_ID` | Your project ID from SubOS backend | ✅ | - |
|
|
192
|
+
| `VITE_STRIPE_PUBLISHABLE_KEY` | Stripe publishable key for payments | ⚠️ | - |
|
|
193
|
+
| `VITE_APP_NAME` | Your application name | ❌ | `SubOS Frontend` |
|
|
194
|
+
| `VITE_APP_VERSION` | Your application version | ❌ | `1.0.0` |
|
|
195
|
+
| `VITE_APP_ENVIRONMENT` | Environment (development/production) | ❌ | `development` |
|
|
196
|
+
| `VITE_DEBUG` | Enable debug mode | ❌ | `false` |
|
|
197
|
+
|
|
198
|
+
### Runtime Configuration API
|
|
199
|
+
|
|
200
|
+
```tsx
|
|
201
|
+
import { configureSubOS, getApiBaseUrl, getProjectId } from 'subos-frontend';
|
|
202
|
+
|
|
203
|
+
// Configure at app startup
|
|
204
|
+
configureSubOS({
|
|
205
|
+
apiEndpoint: 'https://api.mycompany.com/api/v1',
|
|
206
|
+
projectId: 'my-project-id',
|
|
207
|
+
stripePublishableKey: 'pk_live_xxx',
|
|
208
|
+
appName: 'My Company App',
|
|
209
|
+
appEnvironment: 'production',
|
|
210
|
+
debug: false
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Access configured values
|
|
214
|
+
const apiUrl = getApiBaseUrl();
|
|
215
|
+
const projectId = getProjectId();
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Environment Template
|
|
219
|
+
|
|
220
|
+
Copy the included `.env.example` file to your project and customize:
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
cp node_modules/subos-frontend/.env.example .env
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## 🔧 API Integration
|
|
227
|
+
|
|
228
|
+
The library includes a complete API client for backend integration:
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
import {
|
|
232
|
+
plansApi,
|
|
233
|
+
subscriptionApi,
|
|
234
|
+
customerApi,
|
|
235
|
+
transactionApi,
|
|
236
|
+
checkoutApi
|
|
237
|
+
} from 'subos-frontend';
|
|
238
|
+
|
|
239
|
+
// Fetch plans
|
|
240
|
+
const { data: plans } = await plansApi.getPlans();
|
|
241
|
+
|
|
242
|
+
// Get subscription
|
|
243
|
+
const { data: subscription } = await subscriptionApi.getActiveSubscription(userId);
|
|
244
|
+
|
|
245
|
+
// Create checkout session
|
|
246
|
+
const { data: session } = await plansApi.createPaymentSession(planCode, {
|
|
247
|
+
customerEmail: 'user@example.com',
|
|
248
|
+
couponCode: 'DISCOUNT10'
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## 🎨 Styling
|
|
253
|
+
|
|
254
|
+
Components are styled with Tailwind CSS. You can:
|
|
255
|
+
|
|
256
|
+
1. **Use default styles** - Import the included CSS file
|
|
257
|
+
2. **Customize with Tailwind** - Override classes using Tailwind utilities
|
|
258
|
+
3. **Custom CSS** - Override component styles with custom CSS
|
|
259
|
+
|
|
260
|
+
## 📋 TypeScript Support
|
|
261
|
+
|
|
262
|
+
Full TypeScript definitions are included:
|
|
263
|
+
|
|
264
|
+
```tsx
|
|
265
|
+
import type {
|
|
266
|
+
Plan,
|
|
267
|
+
Subscription,
|
|
268
|
+
Transaction,
|
|
269
|
+
PlanCardProps,
|
|
270
|
+
ApiResponse
|
|
271
|
+
} from 'subos-frontend';
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## 🔄 Development Setup
|
|
275
|
+
|
|
276
|
+
For contributing or local development:
|
|
277
|
+
|
|
278
|
+
### Prerequisites
|
|
279
|
+
|
|
280
|
+
- Node.js (v20.19.0 or higher)
|
|
281
|
+
- pnpm (recommended)
|
|
282
|
+
|
|
283
|
+
### Setup
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
git clone <repository-url>
|
|
287
|
+
cd subos-frontend
|
|
288
|
+
pnpm install
|
|
289
|
+
pnpm dev
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Build Library
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
pnpm build
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
This generates:
|
|
299
|
+
- `/dist/index.js` - ESM bundle
|
|
300
|
+
- `/dist/index.cjs` - CommonJS bundle
|
|
301
|
+
- `/dist/index.d.ts` - TypeScript declarations
|
|
302
|
+
- `/dist/style.css` - Compiled styles
|
|
303
|
+
|
|
304
|
+
## Project Structure
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
subos-frontend/
|
|
308
|
+
├── src/
|
|
309
|
+
│ ├── api/ # API utilities and endpoints
|
|
310
|
+
│ ├── assets/ # Static assets
|
|
311
|
+
│ ├── components/ # React components
|
|
312
|
+
│ ├── config/ # Configuration files
|
|
313
|
+
│ ├── hooks/ # Custom React hooks
|
|
314
|
+
│ ├── pages/ # Page components
|
|
315
|
+
│ ├── styles/ # Global styles
|
|
316
|
+
│ ├── types/ # TypeScript type definitions
|
|
317
|
+
│ ├── utils/ # Utility functions
|
|
318
|
+
│ ├── App.tsx # Main App component with routing
|
|
319
|
+
│ └── main.tsx # Application entry point
|
|
320
|
+
├── public/ # Public assets
|
|
321
|
+
└── .env # Environment variables
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Backend Integration
|
|
325
|
+
|
|
326
|
+
This frontend is designed to work with the SubOS backend API (NestJS, TypeScript, PostgreSQL, TypeORM).
|
|
327
|
+
|
|
328
|
+
### Configuration
|
|
329
|
+
|
|
330
|
+
1. Configure the API endpoint in your environment variables (`.env` file):
|
|
331
|
+
```env
|
|
332
|
+
VITE_API_URL=http://localhost:3000
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
2. The API configuration is handled in `src/config/` directory.
|
|
336
|
+
|
|
337
|
+
### Backend Requirements
|
|
338
|
+
|
|
339
|
+
- NestJS backend with TypeScript
|
|
340
|
+
- PostgreSQL database with TypeORM
|
|
341
|
+
- CORS enabled for frontend domain
|
|
342
|
+
- API endpoints for subscription management
|
|
343
|
+
|
|
344
|
+
## 📚 Available Scripts
|
|
345
|
+
|
|
346
|
+
- `pnpm build` - Build the library (ESM + CommonJS + types)
|
|
347
|
+
- `pnpm build:watch` - Build in watch mode
|
|
348
|
+
- `pnpm dev` - Start development server
|
|
349
|
+
- `pnpm lint` - Run ESLint
|
|
350
|
+
|
|
351
|
+
## 🔗 Peer Dependencies
|
|
352
|
+
|
|
353
|
+
Ensure your project includes these peer dependencies:
|
|
354
|
+
|
|
355
|
+
```json
|
|
356
|
+
{
|
|
357
|
+
"peerDependencies": {
|
|
358
|
+
"react": ">=18",
|
|
359
|
+
"react-dom": ">=18",
|
|
360
|
+
"react-router-dom": ">=6",
|
|
361
|
+
"@stripe/react-stripe-js": ">=2",
|
|
362
|
+
"@stripe/stripe-js": ">=1"
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## 🏗️ Tech Stack
|
|
368
|
+
|
|
369
|
+
- **Frontend**: React 19, TypeScript
|
|
370
|
+
- **Build Tool**: tsup (ESM + CommonJS)
|
|
371
|
+
- **Styling**: Tailwind CSS
|
|
372
|
+
- **Payment**: Stripe integration
|
|
373
|
+
- **Routing**: React Router DOM
|
|
374
|
+
- **Package Manager**: pnpm
|
|
375
|
+
|
|
376
|
+
## 🤝 Contributing
|
|
377
|
+
|
|
378
|
+
1. Fork the repository
|
|
379
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
380
|
+
3. Commit changes: `git commit -m 'Add amazing feature'`
|
|
381
|
+
4. Push to branch: `git push origin feature/amazing-feature`
|
|
382
|
+
5. Open a Pull Request
|
|
383
|
+
|
|
384
|
+
## 📄 License
|
|
385
|
+
|
|
386
|
+
This project is licensed under the MIT License.
|
|
387
|
+
|
|
388
|
+
## 🆘 Support
|
|
389
|
+
|
|
390
|
+
For support and questions:
|
|
391
|
+
- Create an issue in the repository
|
|
392
|
+
- Contact the development team
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
Built with ❤️ by the Knovator team
|